Context
stringlengths
295
65.3k
file_name
stringlengths
21
74
start
int64
14
1.41k
end
int64
20
1.41k
theorem
stringlengths
27
1.42k
proof
stringlengths
0
4.57k
/- Copyright (c) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov, Winston Yin -/ import Mathlib.Algebra.Group.End import Mathlib.Topology.EMetricSpace.Diam /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we provide various ways to prove that various combinations of Lipschitz continuous functions are Lipschitz continuous. We also prove that Lipschitz continuous functions are uniformly continuous, and that locally Lipschitz functions are continuous. ## Main definitions and lemmas * `LipschitzWith K f`: states that `f` is Lipschitz with constant `K : ℝ≥0` * `LipschitzOnWith K f s`: states that `f` is Lipschitz with constant `K : ℝ≥0` on a set `s` * `LipschitzWith.uniformContinuous`: a Lipschitz function is uniformly continuous * `LipschitzOnWith.uniformContinuousOn`: a function which is Lipschitz on a set `s` is uniformly continuous on `s`. * `LocallyLipschitz f`: states that `f` is locally Lipschitz * `LocallyLipschitzOn f s`: states that `f` is locally Lipschitz on `s`. * `LocallyLipschitz.continuous`: a locally Lipschitz function is continuous. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {K : ℝ≥0} {s t : Set α} {f : α → β} /-- A function `f` is **Lipschitz continuous** with constant `K ≥ 0` if for all `x, y` we have `dist (f x) (f y) ≤ K * dist x y`. -/ def LipschitzWith (K : ℝ≥0) (f : α → β) := ∀ x y, edist (f x) (f y) ≤ K * edist x y /-- A function `f` is **Lipschitz continuous** with constant `K ≥ 0` **on `s`** if for all `x, y` in `s` we have `dist (f x) (f y) ≤ K * dist x y`. -/ def LipschitzOnWith (K : ℝ≥0) (f : α → β) (s : Set α) := ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → edist (f x) (f y) ≤ K * edist x y /-- `f : α → β` is called **locally Lipschitz continuous** iff every point `x` has a neighbourhood on which `f` is Lipschitz. -/ def LocallyLipschitz (f : α → β) : Prop := ∀ x, ∃ K, ∃ t ∈ 𝓝 x, LipschitzOnWith K f t /-- `f : α → β` is called **locally Lipschitz continuous** on `s` iff every point `x` of `s` has a neighbourhood within `s` on which `f` is Lipschitz. -/ def LocallyLipschitzOn (s : Set α) (f : α → β) : Prop := ∀ ⦃x⦄, x ∈ s → ∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t /-- Every function is Lipschitz on the empty set (with any Lipschitz constant). -/ @[simp] theorem lipschitzOnWith_empty (K : ℝ≥0) (f : α → β) : LipschitzOnWith K f ∅ := fun _ => False.elim @[simp] lemma locallyLipschitzOn_empty (f : α → β) : LocallyLipschitzOn ∅ f := fun _ ↦ False.elim /-- Being Lipschitz on a set is monotone w.r.t. that set. -/ theorem LipschitzOnWith.mono (hf : LipschitzOnWith K f t) (h : s ⊆ t) : LipschitzOnWith K f s := fun _x x_in _y y_in => hf (h x_in) (h y_in) lemma LocallyLipschitzOn.mono (hf : LocallyLipschitzOn t f) (h : s ⊆ t) : LocallyLipschitzOn s f := fun x hx ↦ by obtain ⟨K, u, hu, hfu⟩ := hf (h hx); exact ⟨K, u, nhdsWithin_mono _ h hu, hfu⟩ /-- `f` is Lipschitz iff it is Lipschitz on the entire space. -/ @[simp] lemma lipschitzOnWith_univ : LipschitzOnWith K f univ ↔ LipschitzWith K f := by simp [LipschitzOnWith, LipschitzWith] @[simp] lemma locallyLipschitzOn_univ : LocallyLipschitzOn univ f ↔ LocallyLipschitz f := by simp [LocallyLipschitzOn, LocallyLipschitz] protected lemma LocallyLipschitz.locallyLipschitzOn (h : LocallyLipschitz f) : LocallyLipschitzOn s f := (locallyLipschitzOn_univ.2 h).mono s.subset_univ theorem lipschitzOnWith_iff_restrict : LipschitzOnWith K f s ↔ LipschitzWith K (s.restrict f) := by simp [LipschitzOnWith, LipschitzWith] lemma lipschitzOnWith_restrict {t : Set s} : LipschitzOnWith K (s.restrict f) t ↔ LipschitzOnWith K f (s ∩ Subtype.val '' t) := by simp [LipschitzOnWith, LipschitzWith] lemma locallyLipschitzOn_iff_restrict : LocallyLipschitzOn s f ↔ LocallyLipschitz (s.restrict f) := by simp only [LocallyLipschitzOn, LocallyLipschitz, SetCoe.forall', restrict_apply, Subtype.edist_mk_mk, ← lipschitzOnWith_iff_restrict, lipschitzOnWith_restrict, nhds_subtype_eq_comap_nhdsWithin, mem_comap] congr! with x K constructor · rintro ⟨t, ht, hft⟩ exact ⟨_, ⟨t, ht, Subset.rfl⟩, hft.mono <| inter_subset_right.trans <| image_preimage_subset ..⟩ · rintro ⟨t, ⟨u, hu, hut⟩, hft⟩ exact ⟨s ∩ u, Filter.inter_mem self_mem_nhdsWithin hu, hft.mono fun x hx ↦ ⟨hx.1, ⟨x, hx.1⟩, hut hx.2, rfl⟩⟩ alias ⟨LipschitzOnWith.to_restrict, _⟩ := lipschitzOnWith_iff_restrict alias ⟨LocallyLipschitzOn.restrict, _⟩ := locallyLipschitzOn_iff_restrict lemma Set.MapsTo.lipschitzOnWith_iff_restrict {t : Set β} (h : MapsTo f s t) : LipschitzOnWith K f s ↔ LipschitzWith K (h.restrict f s t) := _root_.lipschitzOnWith_iff_restrict alias ⟨LipschitzOnWith.to_restrict_mapsTo, _⟩ := Set.MapsTo.lipschitzOnWith_iff_restrict end PseudoEMetricSpace namespace LipschitzWith open EMetric variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ≥0∞} {s : Set α} protected theorem lipschitzOnWith (h : LipschitzWith K f) : LipschitzOnWith K f s := fun x _ y _ => h x y theorem edist_le_mul (h : LipschitzWith K f) (x y : α) : edist (f x) (f y) ≤ K * edist x y := h x y theorem edist_le_mul_of_le (h : LipschitzWith K f) (hr : edist x y ≤ r) : edist (f x) (f y) ≤ K * r := (h x y).trans <| mul_left_mono hr theorem edist_lt_mul_of_lt (h : LipschitzWith K f) (hK : K ≠ 0) (hr : edist x y < r) : edist (f x) (f y) < K * r := (h x y).trans_lt <| (ENNReal.mul_lt_mul_left (ENNReal.coe_ne_zero.2 hK) ENNReal.coe_ne_top).2 hr theorem mapsTo_emetric_closedBall (h : LipschitzWith K f) (x : α) (r : ℝ≥0∞) : MapsTo f (closedBall x r) (closedBall (f x) (K * r)) := fun _y hy => h.edist_le_mul_of_le hy theorem mapsTo_emetric_ball (h : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ≥0∞) : MapsTo f (ball x r) (ball (f x) (K * r)) := fun _y hy => h.edist_lt_mul_of_lt hK hy theorem edist_lt_top (hf : LipschitzWith K f) {x y : α} (h : edist x y ≠ ⊤) : edist (f x) (f y) < ⊤ := (hf x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_lt_top h.lt_top theorem mul_edist_le (h : LipschitzWith K f) (x y : α) : (K⁻¹ : ℝ≥0∞) * edist (f x) (f y) ≤ edist x y := by rw [mul_comm, ← div_eq_mul_inv] exact ENNReal.div_le_of_le_mul' (h x y) protected theorem of_edist_le (h : ∀ x y, edist (f x) (f y) ≤ edist x y) : LipschitzWith 1 f := fun x y => by simp only [ENNReal.coe_one, one_mul, h] protected theorem weaken (hf : LipschitzWith K f) {K' : ℝ≥0} (h : K ≤ K') : LipschitzWith K' f := fun x y => le_trans (hf x y) <| mul_right_mono (ENNReal.coe_le_coe.2 h) theorem ediam_image_le (hf : LipschitzWith K f) (s : Set α) : EMetric.diam (f '' s) ≤ K * EMetric.diam s := by apply EMetric.diam_le rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ exact hf.edist_le_mul_of_le (EMetric.edist_le_diam_of_mem hx hy) theorem edist_lt_of_edist_lt_div (hf : LipschitzWith K f) {x y : α} {d : ℝ≥0∞} (h : edist x y < d / K) : edist (f x) (f y) < d := calc edist (f x) (f y) ≤ K * edist x y := hf x y _ < d := ENNReal.mul_lt_of_lt_div' h /-- A Lipschitz function is uniformly continuous. -/ protected theorem uniformContinuous (hf : LipschitzWith K f) : UniformContinuous f := EMetric.uniformContinuous_iff.2 fun ε εpos => ⟨ε / K, ENNReal.div_pos_iff.2 ⟨ne_of_gt εpos, ENNReal.coe_ne_top⟩, hf.edist_lt_of_edist_lt_div⟩ /-- A Lipschitz function is continuous. -/ protected theorem continuous (hf : LipschitzWith K f) : Continuous f := hf.uniformContinuous.continuous /-- Constant functions are Lipschitz (with any constant). -/ protected theorem const (b : β) : LipschitzWith 0 fun _ : α => b := fun x y => by simp only [edist_self, zero_le] protected theorem const' (b : β) {K : ℝ≥0} : LipschitzWith K fun _ : α => b := fun x y => by simp only [edist_self, zero_le] /-- The identity is 1-Lipschitz. -/ protected theorem id : LipschitzWith 1 (@id α) := LipschitzWith.of_edist_le fun _ _ => le_rfl /-- The inclusion of a subset is 1-Lipschitz. -/ protected theorem subtype_val (s : Set α) : LipschitzWith 1 (Subtype.val : s → α) := LipschitzWith.of_edist_le fun _ _ => le_rfl theorem subtype_mk (hf : LipschitzWith K f) {p : β → Prop} (hp : ∀ x, p (f x)) : LipschitzWith K (fun x => ⟨f x, hp x⟩ : α → { y // p y }) := hf protected theorem eval {α : ι → Type u} [∀ i, PseudoEMetricSpace (α i)] [Fintype ι] (i : ι) : LipschitzWith 1 (Function.eval i : (∀ i, α i) → α i) := LipschitzWith.of_edist_le fun f g => by convert edist_le_pi_edist f g i /-- The restriction of a `K`-Lipschitz function is `K`-Lipschitz. -/ protected theorem restrict (hf : LipschitzWith K f) (s : Set α) : LipschitzWith K (s.restrict f) := fun x y => hf x y /-- The composition of Lipschitz functions is Lipschitz. -/ protected theorem comp {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f ∘ g) := fun x y => calc edist (f (g x)) (f (g y)) ≤ Kf * edist (g x) (g y) := hf _ _ _ ≤ Kf * (Kg * edist x y) := mul_left_mono (hg _ _) _ = (Kf * Kg : ℝ≥0) * edist x y := by rw [← mul_assoc, ENNReal.coe_mul] theorem comp_lipschitzOnWith {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} {s : Set α} (hf : LipschitzWith Kf f) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (Kf * Kg) (f ∘ g) s := lipschitzOnWith_iff_restrict.mpr <| hf.comp hg.to_restrict protected theorem prod_fst : LipschitzWith 1 (@Prod.fst α β) := LipschitzWith.of_edist_le fun _ _ => le_max_left _ _ protected theorem prod_snd : LipschitzWith 1 (@Prod.snd α β) := LipschitzWith.of_edist_le fun _ _ => le_max_right _ _ /-- If `f` and `g` are Lipschitz functions, so is the induced map `f × g` to the product type. -/ protected theorem prodMk {f : α → β} {Kf : ℝ≥0} (hf : LipschitzWith Kf f) {g : α → γ} {Kg : ℝ≥0} (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => (f x, g x) := by intro x y rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul] exact max_le_max (hf x y) (hg x y) @[deprecated (since := "2025-03-10")] protected alias prod := LipschitzWith.prodMk protected theorem prodMk_left (a : α) : LipschitzWith 1 (Prod.mk a : β → α × β) := by simpa only [max_eq_right zero_le_one] using (LipschitzWith.const a).prodMk LipschitzWith.id @[deprecated (since := "2025-03-10")] protected alias prod_mk_left := LipschitzWith.prodMk_left protected theorem prodMk_right (b : β) : LipschitzWith 1 fun a : α => (a, b) := by simpa only [max_eq_left zero_le_one] using LipschitzWith.id.prodMk (LipschitzWith.const b) @[deprecated (since := "2025-03-10")] protected alias prod_mk_right := LipschitzWith.prodMk_right protected theorem uncurry {f : α → β → γ} {Kα Kβ : ℝ≥0} (hα : ∀ b, LipschitzWith Kα fun a => f a b) (hβ : ∀ a, LipschitzWith Kβ (f a)) : LipschitzWith (Kα + Kβ) (Function.uncurry f) := by rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ simp only [Function.uncurry, ENNReal.coe_add, add_mul] apply le_trans (edist_triangle _ (f a₂ b₁) _) exact add_le_add (le_trans (hα _ _ _) <| mul_left_mono <| le_max_left _ _) (le_trans (hβ _ _ _) <| mul_left_mono <| le_max_right _ _) /-- Iterates of a Lipschitz function are Lipschitz. -/ protected theorem iterate {f : α → α} (hf : LipschitzWith K f) : ∀ n, LipschitzWith (K ^ n) f^[n] | 0 => by simpa only [pow_zero] using LipschitzWith.id | n + 1 => by rw [pow_succ]; exact (LipschitzWith.iterate hf n).comp hf theorem edist_iterate_succ_le_geometric {f : α → α} (hf : LipschitzWith K f) (x n) : edist (f^[n] x) (f^[n + 1] x) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n := by rw [iterate_succ, mul_comm] simpa only [ENNReal.coe_pow] using (hf.iterate n) x (f x) protected theorem mul_end {f g : Function.End α} {Kf Kg} (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f * g : Function.End α) := hf.comp hg /-- The product of a list of Lipschitz continuous endomorphisms is a Lipschitz continuous endomorphism. -/ protected theorem list_prod (f : ι → Function.End α) (K : ι → ℝ≥0) (h : ∀ i, LipschitzWith (K i) (f i)) : ∀ l : List ι, LipschitzWith (l.map K).prod (l.map f).prod | [] => by simpa using LipschitzWith.id | i::l => by simp only [List.map_cons, List.prod_cons] exact (h i).mul_end (LipschitzWith.list_prod f K h l) protected theorem pow_end {f : Function.End α} {K} (h : LipschitzWith K f) : ∀ n : ℕ, LipschitzWith (K ^ n) (f ^ n : Function.End α) | 0 => by simpa only [pow_zero] using LipschitzWith.id | n + 1 => by rw [pow_succ, pow_succ] exact (LipschitzWith.pow_end h n).mul_end h end LipschitzWith namespace LipschitzOnWith variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {K : ℝ≥0} {s : Set α} {f : α → β} protected theorem uniformContinuousOn (hf : LipschitzOnWith K f s) : UniformContinuousOn f s := uniformContinuousOn_iff_restrict.mpr hf.to_restrict.uniformContinuous protected theorem continuousOn (hf : LipschitzOnWith K f s) : ContinuousOn f s := hf.uniformContinuousOn.continuousOn theorem edist_le_mul_of_le (h : LipschitzOnWith K f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) {r : ℝ≥0∞} (hr : edist x y ≤ r) : edist (f x) (f y) ≤ K * r := (h hx hy).trans <| mul_left_mono hr theorem edist_lt_of_edist_lt_div (hf : LipschitzOnWith K f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) {d : ℝ≥0∞} (hd : edist x y < d / K) : edist (f x) (f y) < d := hf.to_restrict.edist_lt_of_edist_lt_div <| show edist (⟨x, hx⟩ : s) ⟨y, hy⟩ < d / K from hd protected theorem comp {g : β → γ} {t : Set β} {Kg : ℝ≥0} (hg : LipschitzOnWith Kg g t) (hf : LipschitzOnWith K f s) (hmaps : MapsTo f s t) : LipschitzOnWith (Kg * K) (g ∘ f) s := lipschitzOnWith_iff_restrict.mpr <| hg.to_restrict.comp (hf.to_restrict_mapsTo hmaps) /-- If `f` and `g` are Lipschitz on `s`, so is the induced map `f × g` to the product type. -/ protected theorem prodMk {g : α → γ} {Kf Kg : ℝ≥0} (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (max Kf Kg) (fun x => (f x, g x)) s := by intro _ hx _ hy rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul] exact max_le_max (hf hx hy) (hg hx hy) @[deprecated (since := "2025-03-10")] protected alias prod := LipschitzOnWith.prodMk
Mathlib/Topology/EMetricSpace/Lipschitz.lean
329
333
theorem ediam_image2_le (f : α → β → γ) {K₁ K₂ : ℝ≥0} (s : Set α) (t : Set β) (hf₁ : ∀ b ∈ t, LipschitzOnWith K₁ (f · b) s) (hf₂ : ∀ a ∈ s, LipschitzOnWith K₂ (f a) t) : EMetric.diam (Set.image2 f s t) ≤ ↑K₁ * EMetric.diam s + ↑K₂ * EMetric.diam t := by
simp only [EMetric.diam_le_iff, forall_mem_image2] intro a₁ ha₁ b₁ hb₁ a₂ ha₂ b₂ hb₂
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
109
118
theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by
apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one]
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
134
146
theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by
by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound]
/- Copyright (c) 2014 Microsoft Corporation. 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.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Nat.PSub import Mathlib.Data.Nat.Size import Mathlib.Data.Num.Bitwise /-! # Properties of the binary representation of integers -/ open Int attribute [local simp] add_assoc namespace PosNum variable {α : Type*} @[simp, norm_cast] theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 := rfl @[simp] theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 := rfl @[simp, norm_cast] theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = (n : α) + n := rfl @[simp, norm_cast] theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = ((n : α) + n) + 1 := rfl @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n | 1 => Nat.cast_one | bit0 p => by dsimp; rw [Nat.cast_add, p.cast_to_nat] | bit1 p => by dsimp; rw [Nat.cast_add, Nat.cast_add, Nat.cast_one, p.cast_to_nat] @[norm_cast] theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n := cast_to_nat _ @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1 | 1 => rfl | bit0 _ => rfl | bit1 p => (congr_arg (fun n ↦ n + n) (succ_to_nat p)).trans <| show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm] theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n | 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one] | a, 1 => by rw [add_one a, succ_to_nat, cast_one] | bit0 a, bit0 b => (congr_arg (fun n ↦ n + n) (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _ | bit0 a, bit1 b => (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm] | bit1 a, bit0 b => (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm] | bit1 a, bit1 b => show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm] theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n) | 1, b => by simp [one_add] | bit0 a, 1 => congr_arg bit0 (add_one a) | bit1 a, 1 => congr_arg bit1 (add_one a) | bit0 _, bit0 _ => rfl | bit0 a, bit1 b => congr_arg bit0 (add_succ a b) | bit1 _, bit0 _ => rfl | bit1 a, bit1 b => congr_arg bit1 (add_succ a b) theorem bit0_of_bit0 : ∀ n, n + n = bit0 n | 1 => rfl | bit0 p => congr_arg bit0 (bit0_of_bit0 p) | bit1 p => show bit0 (succ (p + p)) = _ by rw [bit0_of_bit0 p, succ] theorem bit1_of_bit1 (n : PosNum) : (n + n) + 1 = bit1 n := show (n + n) + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ] @[norm_cast] theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n | 1 => (mul_one _).symm | bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib] | bit1 p => (add_to_nat (bit0 (m * p)) m).trans <| show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib] theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ) | 1 => Nat.zero_lt_one | bit0 p => let h := to_nat_pos p add_pos h h | bit1 _p => Nat.succ_pos _ theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n := show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by induction' m with m IH m IH <;> intro n <;> obtain - | n | n := n <;> unfold cmp <;> try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 1, 1 => rfl | bit0 a, 1 => let h : (1 : ℕ) ≤ a := to_nat_pos a Nat.add_le_add h h | bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a | 1, bit0 b => let h : (1 : ℕ) ≤ b := to_nat_pos b Nat.add_le_add h h | 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b | bit0 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.add_lt_add this this · rw [this] · exact Nat.add_lt_add this this | bit0 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.le_succ_of_le (Nat.add_lt_add this this) · rw [this] apply Nat.lt_succ_self · exact cmp_to_nat_lemma this | bit1 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact cmp_to_nat_lemma this · rw [this] apply Nat.lt_succ_self · exact Nat.le_succ_of_le (Nat.add_lt_add this this) | bit1 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.succ_lt_succ (Nat.add_lt_add this this) · rw [this] · exact Nat.succ_lt_succ (Nat.add_lt_add this this) @[norm_cast] theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] @[norm_cast] theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat end PosNum namespace Num variable {α : Type*} open PosNum theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl theorem add_one : ∀ n : Num, n + 1 = succ n | 0 => rfl | pos p => by cases p <;> rfl theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n) | 0, n => by simp [zero_add] | pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ'] | pos _, pos _ => congr_arg pos (PosNum.add_succ _ _) theorem bit0_of_bit0 : ∀ n : Num, n + n = n.bit0 | 0 => rfl | pos p => congr_arg pos p.bit0_of_bit0 theorem bit1_of_bit1 : ∀ n : Num, (n + n) + 1 = n.bit1 | 0 => rfl | pos p => congr_arg pos p.bit1_of_bit1 @[simp] theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat'] theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) := Nat.binaryRec_eq _ _ (.inl rfl) @[simp] theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0 | 0 => rfl | pos _n => rfl theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 := @(Nat.binaryRec (by simp [zero_add]) fun b n ih => by cases b · erw [ofNat'_bit true n, ofNat'_bit] simp only [← bit1_of_bit1, ← bit0_of_bit0, cond] · rw [show n.bit true + 1 = (n + 1).bit false by simp [Nat.bit, mul_add], ofNat'_bit, ofNat'_bit, ih] simp only [cond, add_one, bit1_succ]) @[simp] theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by induction n · simp only [Nat.add_zero, ofNat'_zero, add_zero] · simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *] @[simp, norm_cast] theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 := rfl @[simp] theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 := rfl @[simp, norm_cast] theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 := rfl @[simp] theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n := rfl theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1 | 0 => (Nat.zero_add _).symm | pos _p => PosNum.succ_to_nat _ theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n | 0 => Nat.cast_zero | pos p => p.cast_to_nat @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n | 0, 0 => rfl | 0, pos _q => (Nat.zero_add _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.add_to_nat _ _ @[norm_cast] theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n | 0, 0 => rfl | 0, pos _q => (zero_mul _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.mul_to_nat _ _ theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 0, 0 => rfl | 0, pos _ => to_nat_pos _ | pos _, 0 => to_nat_pos _ | pos a, pos b => by have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b exacts [id, congr_arg pos, id] @[norm_cast] theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] @[norm_cast] theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat end Num namespace PosNum @[simp] theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n | 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl | bit0 p => by simpa only [Nat.bit_false, cond_false, two_mul, of_to_nat' p] using Num.ofNat'_bit false p | bit1 p => by simpa only [Nat.bit_true, cond_true, two_mul, of_to_nat' p] using Num.ofNat'_bit true p end PosNum namespace Num @[simp, norm_cast] theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n | 0 => ofNat'_zero | pos p => p.of_to_nat' lemma toNat_injective : Function.Injective (castNum : Num → ℕ) := Function.LeftInverse.injective of_to_nat' @[norm_cast] theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff /-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp)) instance addMonoid : AddMonoid Num where add := (· + ·) zero := 0 zero_add := zero_add add_zero := add_zero add_assoc := by transfer nsmul := nsmulRec instance addMonoidWithOne : AddMonoidWithOne Num := { Num.addMonoid with natCast := Num.ofNat' one := 1 natCast_zero := ofNat'_zero natCast_succ := fun _ => ofNat'_succ } instance commSemiring : CommSemiring Num where __ := Num.addMonoid __ := Num.addMonoidWithOne mul := (· * ·) npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩ mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero] zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul] mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one] one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul] add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm] mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm] mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc] left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add] right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul] instance partialOrder : PartialOrder Num where lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le] le_refl := by transfer le_trans a b c := by transfer_rw; apply le_trans le_antisymm a b := by transfer_rw; apply le_antisymm instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid Num where add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c le_of_add_le_add_left a b c := show a + b ≤ a + c → b ≤ c by transfer_rw; apply le_of_add_le_add_left instance linearOrder : LinearOrder Num := { le_total := by intro a b transfer_rw apply le_total toDecidableLT := Num.decidableLT toDecidableLE := Num.decidableLE -- This is relying on an automatically generated instance name, -- generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 toDecidableEq := instDecidableEqNum } instance isStrictOrderedRing : IsStrictOrderedRing Num := { zero_le_one := by decide mul_lt_mul_of_pos_left := by intro a b c transfer_rw apply mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right := by intro a b c transfer_rw apply mul_lt_mul_of_pos_right exists_pair_ne := ⟨0, 1, by decide⟩ } @[norm_cast] theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n := add_ofNat' _ _ @[norm_cast] theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n := cast_to_nat _ @[simp, norm_cast] theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n | 0 => by rw [Nat.cast_zero, cast_zero] | n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n] @[simp, norm_cast] theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by rw [← cast_to_nat, to_of_nat] @[norm_cast] theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n := ⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩ -- The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n := of_to_nat' @[norm_cast] theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n := ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩ end Num namespace PosNum variable {α : Type*} open Num -- The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n := of_to_nat' @[norm_cast] theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n := ⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩ theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n | 1 => rfl | bit0 n => have : Nat.succ ↑(pred' n) = ↑n := by rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)] match (motive := ∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (n + n)) pred' n, this with | 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl | Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm | bit1 _ => rfl @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ] @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 <| by rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)] instance dvd : Dvd PosNum := ⟨fun m n => pos m ∣ pos n⟩ @[norm_cast] theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n := Num.dvd_to_nat (pos m) (pos n) theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 1 => Nat.size_one.symm | bit0 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit0, ← two_mul] erw [@Nat.size_bit false n] have := to_nat_pos n dsimp [Nat.bit]; omega | bit1 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit1, ← two_mul] erw [@Nat.size_bit true n] dsimp [Nat.bit]; omega theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 1 => rfl | bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] | bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos /-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm])) instance addCommSemigroup : AddCommSemigroup PosNum where add := (· + ·) add_assoc := by transfer add_comm := by transfer instance commMonoid : CommMonoid PosNum where mul := (· * ·) one := (1 : PosNum) npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩ mul_assoc := by transfer one_mul := by transfer mul_one := by transfer mul_comm := by transfer instance distrib : Distrib PosNum where add := (· + ·) mul := (· * ·) left_distrib := by transfer; simp [mul_add] right_distrib := by transfer; simp [mul_add, mul_comm] instance linearOrder : LinearOrder PosNum where lt := (· < ·) lt_iff_le_not_le := by intro a b transfer_rw apply lt_iff_le_not_le le := (· ≤ ·) le_refl := by transfer le_trans := by intro a b c transfer_rw apply le_trans le_antisymm := by intro a b transfer_rw apply le_antisymm le_total := by intro a b transfer_rw apply le_total toDecidableLT := by infer_instance toDecidableLE := by infer_instance toDecidableEq := by infer_instance @[simp] theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n] @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> simp [bit, two_mul] @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] @[simp 500, norm_cast] theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by rw [← add_one, cast_add, cast_one] @[simp, norm_cast] theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] @[simp] theorem one_le_cast [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) : (1 : α) ≤ n := by rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (α := α)]; apply to_nat_pos @[simp] theorem cast_pos [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) : 0 < (n : α) := lt_of_lt_of_le zero_lt_one (one_le_cast n) @[simp, norm_cast] theorem cast_mul [NonAssocSemiring α] (m n) : ((m * n : PosNum) : α) = m * n := by rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat] @[simp] theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;> simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this] @[simp, norm_cast] theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : PosNum} : (m : α) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat] @[simp, norm_cast] theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : PosNum} : (m : α) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr cast_lt end PosNum namespace Num variable {α : Type*} open PosNum theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> cases n <;> simp [bit, two_mul] <;> rfl theorem cast_succ' [AddMonoidWithOne α] (n) : (succ' n : α) = n + 1 := by rw [← PosNum.cast_to_nat, succ'_to_nat, Nat.cast_add_one, cast_to_nat] theorem cast_succ [AddMonoidWithOne α] (n) : (succ n : α) = n + 1 := cast_succ' n @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : Num) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] @[simp, norm_cast] theorem cast_bit0 [NonAssocSemiring α] (n : Num) : (n.bit0 : α) = 2 * (n : α) := by rw [← bit0_of_bit0, two_mul, cast_add] @[simp, norm_cast] theorem cast_bit1 [NonAssocSemiring α] (n : Num) : (n.bit1 : α) = 2 * (n : α) + 1 := by rw [← bit1_of_bit1, bit0_of_bit0, cast_add, cast_bit0]; rfl @[simp, norm_cast] theorem cast_mul [NonAssocSemiring α] : ∀ m n, ((m * n : Num) : α) = m * n | 0, 0 => (zero_mul _).symm | 0, pos _q => (zero_mul _).symm | pos _p, 0 => (mul_zero _).symm | pos _p, pos _q => PosNum.cast_mul _ _ theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 0 => Nat.size_zero.symm | pos p => p.size_to_nat theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 0 => rfl | pos p => p.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] @[simp 999] theorem ofNat'_eq : ∀ n, Num.ofNat' n = n := Nat.binaryRec (by simp) fun b n IH => by tauto theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl theorem zneg_toZNumNeg (n : Num) : -n.toZNumNeg = n.toZNum := by cases n <;> rfl theorem toZNum_inj {m n : Num} : m.toZNum = n.toZNum ↔ m = n := ⟨fun h => by cases m <;> cases n <;> cases h <;> rfl, congr_arg _⟩ @[simp] theorem cast_toZNum [Zero α] [One α] [Add α] [Neg α] : ∀ n : Num, (n.toZNum : α) = n | 0 => rfl | Num.pos _p => rfl @[simp] theorem cast_toZNumNeg [SubtractionMonoid α] [One α] : ∀ n : Num, (n.toZNumNeg : α) = -n | 0 => neg_zero.symm | Num.pos _p => rfl @[simp] theorem add_toZNum (m n : Num) : Num.toZNum (m + n) = m.toZNum + n.toZNum := by cases m <;> cases n <;> rfl end Num namespace PosNum open Num theorem pred_to_nat {n : PosNum} (h : 1 < n) : (pred n : ℕ) = Nat.pred n := by unfold pred cases e : pred' n · have : (1 : ℕ) ≤ Nat.pred n := Nat.pred_le_pred ((@cast_lt ℕ _ _ _).2 h) rw [← pred'_to_nat, e] at this exact absurd this (by decide) · rw [← pred'_to_nat, e] rfl theorem sub'_one (a : PosNum) : sub' a 1 = (pred' a).toZNum := by cases a <;> rfl theorem one_sub' (a : PosNum) : sub' 1 a = (pred' a).toZNumNeg := by cases a <;> rfl theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt := Iff.rfl theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt := not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide end PosNum namespace Num variable {α : Type*} open PosNum theorem pred_to_nat : ∀ n : Num, (pred n : ℕ) = Nat.pred n | 0 => rfl | pos p => by rw [pred, PosNum.pred'_to_nat]; rfl theorem ppred_to_nat : ∀ n : Num, (↑) <$> ppred n = Nat.ppred n | 0 => rfl | pos p => by rw [ppred, Option.map_some, Nat.ppred_eq_some.2] rw [PosNum.pred'_to_nat, Nat.succ_pred_eq_of_pos (PosNum.to_nat_pos _)] rfl theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by cases m <;> cases n <;> try { rfl }; apply PosNum.cmp_swap
Mathlib/Data/Num/Lemmas.lean
733
734
theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by
have := cmp_to_nat m n
/- 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, Kim Morrison -/ import Mathlib.Data.List.Basic /-! # Lattice structure of lists This files prove basic properties about `List.disjoint`, `List.union`, `List.inter` and `List.bagInter`, which are defined in core Lean and `Data.List.Defs`. `l₁ ∪ l₂` is the list where all elements of `l₁` have been inserted in `l₂` in order. For example, `[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0]` `l₁ ∩ l₂` is the list of elements of `l₁` in order which are in `l₂`. For example, `[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [0, 0, 3]` `List.bagInter l₁ l₂` is the list of elements that are in both `l₁` and `l₂`, counted with multiplicity and in the order they appear in `l₁`. As opposed to `List.inter`, `List.bagInter` copes well with multiplicity. For example, `bagInter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]` -/ open Nat namespace List variable {α : Type*} {l₁ l₂ : List α} {p : α → Prop} {a : α} /-! ### `Disjoint` -/ section Disjoint @[symm] theorem Disjoint.symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ end Disjoint variable [DecidableEq α] /-! ### `union` -/ section Union theorem mem_union_left (h : a ∈ l₁) (l₂ : List α) : a ∈ l₁ ∪ l₂ := mem_union_iff.2 (Or.inl h) theorem mem_union_right (l₁ : List α) (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ := mem_union_iff.2 (Or.inr h) theorem sublist_suffix_of_union : ∀ l₁ l₂ : List α, ∃ t, t <+ l₁ ∧ t ++ l₂ = l₁ ∪ l₂ | [], _ => ⟨[], by rfl, rfl⟩ | a :: l₁, l₂ => let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ if h : a ∈ l₁ ∪ l₂ then ⟨t, sublist_cons_of_sublist _ s, by simp only [e, cons_union, insert_of_mem h]⟩ else ⟨a :: t, s.cons_cons _, by simp only [cons_append, cons_union, e, insert_of_not_mem h]⟩ theorem suffix_union_right (l₁ l₂ : List α) : l₂ <:+ l₁ ∪ l₂ := (sublist_suffix_of_union l₁ l₂).imp fun _ => And.right theorem union_sublist_append (l₁ l₂ : List α) : l₁ ∪ l₂ <+ l₁ ++ l₂ := let ⟨_, s, e⟩ := sublist_suffix_of_union l₁ l₂ e ▸ (append_sublist_append_right _).2 s theorem forall_mem_union : (∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ ∀ x ∈ l₂, p x := by simp only [mem_union_iff, or_imp, forall_and] theorem forall_mem_of_forall_mem_union_left (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x := (forall_mem_union.1 h).1 theorem forall_mem_of_forall_mem_union_right (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x := (forall_mem_union.1 h).2 theorem Subset.union_eq_right {xs ys : List α} (h : xs ⊆ ys) : xs ∪ ys = ys := by induction xs with | nil => simp | cons x xs ih => rw [cons_union, insert_of_mem <| mem_union_right _ <| h mem_cons_self, ih <| subset_of_cons_subset h] end Union /-! ### `inter` -/ section Inter @[simp] theorem inter_nil (l : List α) : [] ∩ l = [] := rfl @[simp] theorem inter_cons_of_mem (l₁ : List α) (h : a ∈ l₂) : (a :: l₁) ∩ l₂ = a :: l₁ ∩ l₂ := by simp [Inter.inter, List.inter, h] @[simp] theorem inter_cons_of_not_mem (l₁ : List α) (h : a ∉ l₂) : (a :: l₁) ∩ l₂ = l₁ ∩ l₂ := by simp [Inter.inter, List.inter, h] @[simp] theorem inter_nil' (l : List α) : l ∩ [] = [] := by induction l with | nil => rfl | cons x xs ih => by_cases x ∈ xs <;> simp [ih] theorem mem_of_mem_inter_left : a ∈ l₁ ∩ l₂ → a ∈ l₁ := mem_of_mem_filter theorem mem_of_mem_inter_right (h : a ∈ l₁ ∩ l₂) : a ∈ l₂ := by simpa using of_mem_filter h theorem mem_inter_of_mem_of_mem (h₁ : a ∈ l₁) (h₂ : a ∈ l₂) : a ∈ l₁ ∩ l₂ := mem_filter_of_mem h₁ <| by simpa using h₂ theorem inter_subset_left {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₁ := filter_subset' _ theorem inter_subset_right {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₂ := fun _ => mem_of_mem_inter_right theorem subset_inter {l l₁ l₂ : List α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ := fun _ h => mem_inter_iff.2 ⟨h₁ h, h₂ h⟩ theorem inter_eq_nil_iff_disjoint : l₁ ∩ l₂ = [] ↔ Disjoint l₁ l₂ := by simp only [eq_nil_iff_forall_not_mem, mem_inter_iff, not_and] rfl alias ⟨_, Disjoint.inter_eq_nil⟩ := inter_eq_nil_iff_disjoint theorem forall_mem_inter_of_forall_left (h : ∀ x ∈ l₁, p x) (l₂ : List α) : ∀ x, x ∈ l₁ ∩ l₂ → p x := BAll.imp_left (fun _ => mem_of_mem_inter_left) h theorem forall_mem_inter_of_forall_right (l₁ : List α) (h : ∀ x ∈ l₂, p x) : ∀ x, x ∈ l₁ ∩ l₂ → p x := BAll.imp_left (fun _ => mem_of_mem_inter_right) h @[simp]
Mathlib/Data/List/Lattice.lean
147
147
theorem inter_reverse {xs ys : List α} : xs.inter ys.reverse = xs.inter ys := by
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.PropInstances import Mathlib.Order.GaloisConnection.Defs /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean algebras model classical logic. Heyting algebras are the order theoretic equivalent of cartesian-closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ assert_not_exists RelIso open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `aᶜ` is defined as `a ⇨ ⊥` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp] theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b := le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp /-- `(p → q) ∧ p ↔ q ∧ p` -/ @[simp] theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm] /-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic: an implication holds iff the conclusion follows from the hypothesis. -/ @[simp] theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq] /-- `p → true`, `true → p ↔ p` -/ @[simp] theorem himp_top : a ⇨ ⊤ = ⊤ := himp_eq_top_iff.2 le_top @[simp] theorem top_himp : ⊤ ⇨ a = a := eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq] /-- `p → q → r ↔ p ∧ q → r` -/ theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc] /-- `(q → r) → (p → q) → q → r` -/ theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc] exact inf_le_left @[simp] theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by simpa using @himp_le_himp_himp_himp /-- `p → q → r ↔ q → p → r` -/ theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm] @[simp] theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem] theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff] theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) := eq_of_forall_le_iff fun d => by rw [le_inf_iff, le_himp_comm, sup_le_iff] simp_rw [le_himp_comm] theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b := le_himp_iff.2 <| himp_inf_le.trans h theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c := le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d := (himp_le_himp_right hab).trans <| himp_le_himp_left hcd @[simp] theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by rw [sup_himp_distrib, himp_self, top_inf_eq] @[simp] theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by rw [sup_himp_distrib, himp_self, inf_top_eq] theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by conv_rhs => rw [← @top_himp _ _ a] rw [← h.eq_top, sup_himp_self_left] theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b := h.symm.himp_eq_right theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left] theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right] /-- See `himp_le` for a stronger version in Boolean algebras. -/ theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a := (himp_le_himp_left hba).trans_eq hac.himp_eq_right theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b := le_himp_iff.2 inf_himp_le @[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff] lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by rw [le_himp_iff, inf_right_comm, ← le_himp_iff] exact himp_inf_le.trans le_himp_himp theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c := (himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba) theorem gc_inf_himp : GaloisConnection (a ⊓ ·) (a ⇨ ·) := fun _ _ ↦ Iff.symm le_himp_iff' -- See note [lower instance priority] instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α := DistribLattice.ofInfSupLe fun a b c => by simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] : GeneralizedHeytingAlgebra (α × β) where le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] : GeneralizedHeytingAlgebra (∀ i, α i) where le_himp_iff i := by simp [le_def] end GeneralizedHeytingAlgebra section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] {a b c d : α} @[simp] theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c := GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _ theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm]
Mathlib/Order/Heyting/Basic.lean
388
389
theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by
rw [sdiff_le_iff, sdiff_le_iff']
/- 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 -/ import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv import Mathlib.Analysis.Calculus.FDeriv.Extend import Mathlib.Analysis.Calculus.Deriv.Prod import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # Derivatives of power function on `ℂ`, `ℝ`, `ℝ≥0`, and `ℝ≥0∞` We also prove differentiability and provide derivatives for the power functions `x ^ y`. -/ noncomputable section open scoped Real Topology NNReal ENNReal open Filter namespace Complex theorem hasStrictFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) : HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := by have A : p.1 ≠ 0 := slitPlane_ne_zero hp have : (fun x : ℂ × ℂ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) := ((isOpen_ne.preimage continuous_fst).eventually_mem A).mono fun p hp => cpow_def_of_ne_zero hp _ rw [cpow_sub _ _ A, cpow_one, mul_div_left_comm, mul_smul, mul_smul] refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, mul_smul, add_comm, smul_add] using ((hasStrictFDerivAt_fst.clog hp).mul hasStrictFDerivAt_snd).cexp theorem hasStrictFDerivAt_cpow' {x y : ℂ} (hp : x ∈ slitPlane) : HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((y * x ^ (y - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (x ^ y * log x) • ContinuousLinearMap.snd ℂ ℂ ℂ) (x, y) := @hasStrictFDerivAt_cpow (x, y) hp theorem hasStrictDerivAt_const_cpow {x y : ℂ} (h : x ≠ 0 ∨ y ≠ 0) : HasStrictDerivAt (fun y => x ^ y) (x ^ y * log x) y := by rcases em (x = 0) with (rfl | hx) · replace h := h.neg_resolve_left rfl rw [log_zero, mul_zero] refine (hasStrictDerivAt_const y 0).congr_of_eventuallyEq ?_ exact (isOpen_ne.eventually_mem h).mono fun y hy => (zero_cpow hy).symm · simpa only [cpow_def_of_ne_zero hx, mul_one] using ((hasStrictDerivAt_id y).const_mul (log x)).cexp theorem hasFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) : HasFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := (hasStrictFDerivAt_cpow hp).hasFDerivAt end Complex section fderiv open Complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : E → ℂ} {f' g' : E →L[ℂ] ℂ} {x : E} {s : Set E} {c : ℂ} theorem HasStrictFDerivAt.cpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := (hasStrictFDerivAt_cpow (p := (f x, g x)) h0).comp x (hf.prodMk hg) theorem HasStrictFDerivAt.const_cpow (hf : HasStrictFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x := (hasStrictDerivAt_const_cpow h0).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.cpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prodMk hg) theorem HasFDerivAt.const_cpow (hf : HasFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivAt x hf theorem HasFDerivWithinAt.cpow (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasFDerivWithinAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') s x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasFDerivWithinAt.const_cpow (hf : HasFDerivWithinAt f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasFDerivWithinAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivWithinAt x hf theorem DifferentiableAt.cpow (hf : DifferentiableAt ℂ f x) (hg : DifferentiableAt ℂ g x) (h0 : f x ∈ slitPlane) : DifferentiableAt ℂ (fun x => f x ^ g x) x := (hf.hasFDerivAt.cpow hg.hasFDerivAt h0).differentiableAt theorem DifferentiableAt.const_cpow (hf : DifferentiableAt ℂ f x) (h0 : c ≠ 0 ∨ f x ≠ 0) : DifferentiableAt ℂ (fun x => c ^ f x) x := (hf.hasFDerivAt.const_cpow h0).differentiableAt theorem DifferentiableAt.cpow_const (hf : DifferentiableAt ℂ f x) (h0 : f x ∈ slitPlane) : DifferentiableAt ℂ (fun x => f x ^ c) x := hf.cpow (differentiableAt_const c) h0 theorem DifferentiableWithinAt.cpow (hf : DifferentiableWithinAt ℂ f s x) (hg : DifferentiableWithinAt ℂ g s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt ℂ (fun x => f x ^ g x) s x := (hf.hasFDerivWithinAt.cpow hg.hasFDerivWithinAt h0).differentiableWithinAt theorem DifferentiableWithinAt.const_cpow (hf : DifferentiableWithinAt ℂ f s x) (h0 : c ≠ 0 ∨ f x ≠ 0) : DifferentiableWithinAt ℂ (fun x => c ^ f x) s x := (hf.hasFDerivWithinAt.const_cpow h0).differentiableWithinAt theorem DifferentiableWithinAt.cpow_const (hf : DifferentiableWithinAt ℂ f s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt ℂ (fun x => f x ^ c) s x := hf.cpow (differentiableWithinAt_const c) h0 theorem DifferentiableOn.cpow (hf : DifferentiableOn ℂ f s) (hg : DifferentiableOn ℂ g s) (h0 : Set.MapsTo f s slitPlane) : DifferentiableOn ℂ (fun x ↦ f x ^ g x) s := fun x hx ↦ (hf x hx).cpow (hg x hx) (h0 hx) theorem DifferentiableOn.const_cpow (hf : DifferentiableOn ℂ f s) (h0 : c ≠ 0 ∨ ∀ x ∈ s, f x ≠ 0) : DifferentiableOn ℂ (fun x ↦ c ^ f x) s := fun x hx ↦ (hf x hx).const_cpow (h0.imp_right fun h ↦ h x hx) theorem DifferentiableOn.cpow_const (hf : DifferentiableOn ℂ f s) (h0 : ∀ x ∈ s, f x ∈ slitPlane) : DifferentiableOn ℂ (fun x => f x ^ c) s := hf.cpow (differentiableOn_const c) h0 theorem Differentiable.cpow (hf : Differentiable ℂ f) (hg : Differentiable ℂ g) (h0 : ∀ x, f x ∈ slitPlane) : Differentiable ℂ (fun x ↦ f x ^ g x) := fun x ↦ (hf x).cpow (hg x) (h0 x) theorem Differentiable.const_cpow (hf : Differentiable ℂ f) (h0 : c ≠ 0 ∨ ∀ x, f x ≠ 0) : Differentiable ℂ (fun x ↦ c ^ f x) := fun x ↦ (hf x).const_cpow (h0.imp_right fun h ↦ h x) @[fun_prop] lemma differentiable_const_cpow_of_neZero (z : ℂ) [NeZero z] : Differentiable ℂ fun s : ℂ ↦ z ^ s := differentiable_id.const_cpow (.inl <| NeZero.ne z) @[fun_prop] lemma differentiableAt_const_cpow_of_neZero (z : ℂ) [NeZero z] (t : ℂ) : DifferentiableAt ℂ (fun s : ℂ ↦ z ^ s) t := differentiableAt_id.const_cpow (.inl <| NeZero.ne z) end fderiv section deriv open Complex variable {f g : ℂ → ℂ} {s : Set ℂ} {f' g' x c : ℂ} /-- A private lemma that rewrites the output of lemmas like `HasFDerivAt.cpow` to the form expected by lemmas like `HasDerivAt.cpow`. -/ private theorem aux : ((g x * f x ^ (g x - 1)) • (1 : ℂ →L[ℂ] ℂ).smulRight f' + (f x ^ g x * log (f x)) • (1 : ℂ →L[ℂ] ℂ).smulRight g') 1 = g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' := by simp only [Algebra.id.smul_eq_mul, one_mul, ContinuousLinearMap.one_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul'] nonrec theorem HasStrictDerivAt.cpow (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa using (hf.cpow hg h0).hasStrictDerivAt theorem HasStrictDerivAt.const_cpow (hf : HasStrictDerivAt f f' x) (h : c ≠ 0 ∨ f x ≠ 0) : HasStrictDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h).comp x hf theorem Complex.hasStrictDerivAt_cpow_const (h : x ∈ slitPlane) : HasStrictDerivAt (fun z : ℂ => z ^ c) (c * x ^ (c - 1)) x := by simpa only [mul_zero, add_zero, mul_one] using (hasStrictDerivAt_id x).cpow (hasStrictDerivAt_const x c) h theorem HasStrictDerivAt.cpow_const (hf : HasStrictDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).comp x hf theorem HasDerivAt.cpow (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa only [aux] using (hf.hasFDerivAt.cpow hg h0).hasDerivAt theorem HasDerivAt.const_cpow (hf : HasDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp x hf theorem HasDerivAt.cpow_const (hf : HasDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp x hf theorem HasDerivWithinAt.cpow (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') s x := by simpa only [aux] using (hf.hasFDerivWithinAt.cpow hg h0).hasDerivWithinAt theorem HasDerivWithinAt.const_cpow (hf : HasDerivWithinAt f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasDerivWithinAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasDerivWithinAt x hf theorem HasDerivWithinAt.cpow_const (hf : HasDerivWithinAt f f' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') s x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp_hasDerivWithinAt x hf /-- Although `fun x => x ^ r` for fixed `r` is *not* complex-differentiable along the negative real line, it is still real-differentiable, and the derivative is what one would formally expect. See `hasDerivAt_ofReal_cpow_const` for an alternate formulation. -/ theorem hasDerivAt_ofReal_cpow_const' {x : ℝ} (hx : x ≠ 0) {r : ℂ} (hr : r ≠ -1) : HasDerivAt (fun y : ℝ => (y : ℂ) ^ (r + 1) / (r + 1)) (x ^ r) x := by rw [Ne, ← add_eq_zero_iff_eq_neg, ← Ne] at hr rcases lt_or_gt_of_ne hx.symm with (hx | hx) · -- easy case : `0 < x` apply HasDerivAt.comp_ofReal (e := fun y => (y : ℂ) ^ (r + 1) / (r + 1)) convert HasDerivAt.div_const (𝕜 := ℂ) ?_ (r + 1) using 1 · exact (mul_div_cancel_right₀ _ hr).symm · convert HasDerivAt.cpow_const ?_ ?_ using 1 · rw [add_sub_cancel_right, mul_comm]; exact (mul_one _).symm · exact hasDerivAt_id (x : ℂ) · simp [hx] · -- harder case : `x < 0` have : ∀ᶠ y : ℝ in 𝓝 x, (y : ℂ) ^ (r + 1) / (r + 1) = (-y : ℂ) ^ (r + 1) * exp (π * I * (r + 1)) / (r + 1) := by refine Filter.eventually_of_mem (Iio_mem_nhds hx) fun y hy => ?_ rw [ofReal_cpow_of_nonpos (le_of_lt hy)] refine HasDerivAt.congr_of_eventuallyEq ?_ this rw [ofReal_cpow_of_nonpos (le_of_lt hx)] suffices HasDerivAt (fun y : ℝ => (-↑y) ^ (r + 1) * exp (↑π * I * (r + 1))) ((r + 1) * (-↑x) ^ r * exp (↑π * I * r)) x by convert this.div_const (r + 1) using 1 conv_rhs => rw [mul_assoc, mul_comm, mul_div_cancel_right₀ _ hr] rw [mul_add ((π : ℂ) * _), mul_one, exp_add, exp_pi_mul_I, mul_comm (_ : ℂ) (-1 : ℂ), neg_one_mul] simp_rw [mul_neg, ← neg_mul, ← ofReal_neg] suffices HasDerivAt (fun y : ℝ => (↑(-y) : ℂ) ^ (r + 1)) (-(r + 1) * ↑(-x) ^ r) x by convert this.neg.mul_const _ using 1; ring suffices HasDerivAt (fun y : ℝ => (y : ℂ) ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) (-x) by convert @HasDerivAt.scomp ℝ _ ℂ _ _ x ℝ _ _ _ _ _ _ _ _ this (hasDerivAt_neg x) using 1 rw [real_smul, ofReal_neg 1, ofReal_one]; ring suffices HasDerivAt (fun y : ℂ => y ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) ↑(-x) by exact this.comp_ofReal conv in ↑_ ^ _ => rw [(by ring : r = r + 1 - 1)] convert HasDerivAt.cpow_const ?_ ?_ using 1 · rw [add_sub_cancel_right, add_sub_cancel_right]; exact (mul_one _).symm · exact hasDerivAt_id ((-x : ℝ) : ℂ) · simp [hx] @[deprecated (since := "2024-12-15")] alias hasDerivAt_ofReal_cpow := hasDerivAt_ofReal_cpow_const' /-- An alternate formulation of `hasDerivAt_ofReal_cpow_const'`. -/ theorem hasDerivAt_ofReal_cpow_const {x : ℝ} (hx : x ≠ 0) {r : ℂ} (hr : r ≠ 0) : HasDerivAt (fun y : ℝ => (y : ℂ) ^ r) (r * x ^ (r - 1)) x := by have := HasDerivAt.const_mul r <| hasDerivAt_ofReal_cpow_const' hx (by rwa [ne_eq, sub_eq_neg_self]) simpa [sub_add_cancel, mul_div_cancel₀ _ hr] using this /-- A version of `DifferentiableAt.cpow_const` for a real function. -/ theorem DifferentiableAt.ofReal_cpow_const {f : ℝ → ℝ} {x : ℝ} (hf : DifferentiableAt ℝ f x) (h0 : f x ≠ 0) (h1 : c ≠ 0) : DifferentiableAt ℝ (fun (y : ℝ) => (f y : ℂ) ^ c) x := (hasDerivAt_ofReal_cpow_const h0 h1).differentiableAt.comp x hf theorem Complex.deriv_cpow_const (hx : x ∈ Complex.slitPlane) : deriv (fun (x : ℂ) ↦ x ^ c) x = c * x ^ (c - 1) := (hasStrictDerivAt_cpow_const hx).hasDerivAt.deriv /-- A version of `Complex.deriv_cpow_const` for a real variable. -/ theorem Complex.deriv_ofReal_cpow_const {x : ℝ} (hx : x ≠ 0) (hc : c ≠ 0) : deriv (fun x : ℝ ↦ (x : ℂ) ^ c) x = c * x ^ (c - 1) := (hasDerivAt_ofReal_cpow_const hx hc).deriv theorem deriv_cpow_const (hf : DifferentiableAt ℂ f x) (hx : f x ∈ Complex.slitPlane) : deriv (fun (x : ℂ) ↦ f x ^ c) x = c * f x ^ (c - 1) * deriv f x := (hf.hasDerivAt.cpow_const hx).deriv theorem isTheta_deriv_ofReal_cpow_const_atTop {c : ℂ} (hc : c ≠ 0) : deriv (fun (x : ℝ) => (x : ℂ) ^ c) =Θ[atTop] fun x => x ^ (c.re - 1) := by calc _ =ᶠ[atTop] fun x : ℝ ↦ c * x ^ (c - 1) := by filter_upwards [eventually_ne_atTop 0] with x hx using by rw [deriv_ofReal_cpow_const hx hc] _ =Θ[atTop] fun x : ℝ ↦ ‖(x : ℂ) ^ (c - 1)‖ := (Asymptotics.IsTheta.of_norm_eventuallyEq EventuallyEq.rfl).const_mul_left hc _ =ᶠ[atTop] fun x ↦ x ^ (c.re - 1) := by filter_upwards [eventually_gt_atTop 0] with x hx rw [norm_cpow_eq_rpow_re_of_pos hx, sub_re, one_re] theorem isBigO_deriv_ofReal_cpow_const_atTop (c : ℂ) : deriv (fun (x : ℝ) => (x : ℂ) ^ c) =O[atTop] fun x => x ^ (c.re - 1) := by obtain rfl | hc := eq_or_ne c 0 · simp_rw [cpow_zero, deriv_const', Asymptotics.isBigO_zero] · exact (isTheta_deriv_ofReal_cpow_const_atTop hc).1 end deriv namespace Real variable {x y z : ℝ} /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ × ℝ` such that `0 < p.fst`. -/ theorem hasStrictFDerivAt_rpow_of_pos (p : ℝ × ℝ) (hp : 0 < p.1) : HasStrictFDerivAt (fun x : ℝ × ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ × ℝ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) := (continuousAt_fst.eventually (lt_mem_nhds hp)).mono fun p hp => rpow_def_of_pos hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne').mul hasStrictFDerivAt_snd).exp using 1 rw [rpow_sub_one hp.ne', ← rpow_def_of_pos hp, smul_add, smul_smul, mul_div_left_comm, div_eq_mul_inv, smul_smul, smul_smul, mul_assoc, add_comm] /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ × ℝ` such that `p.fst < 0`. -/ theorem hasStrictFDerivAt_rpow_of_neg (p : ℝ × ℝ) (hp : p.1 < 0) : HasStrictFDerivAt (fun x : ℝ × ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1 - exp (log p.1 * p.2) * sin (p.2 * π) * π) • ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ × ℝ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) * cos (x.2 * π) := (continuousAt_fst.eventually (gt_mem_nhds hp)).mono fun p hp => rpow_def_of_neg hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne).mul hasStrictFDerivAt_snd).exp.mul (hasStrictFDerivAt_snd.mul_const π).cos using 1 simp_rw [rpow_sub_one hp.ne, smul_add, ← add_assoc, smul_smul, ← add_smul, ← mul_assoc, mul_comm (cos _), ← rpow_def_of_neg hp] rw [div_eq_mul_inv, add_comm]; congr 2 <;> ring /-- The function `fun (x, y) => x ^ y` is infinitely smooth at `(x, y)` unless `x = 0`. -/ theorem contDiffAt_rpow_of_ne (p : ℝ × ℝ) (hp : p.1 ≠ 0) {n : WithTop ℕ∞} : ContDiffAt ℝ n (fun p : ℝ × ℝ => p.1 ^ p.2) p := by rcases hp.lt_or_lt with hneg | hpos exacts [(((contDiffAt_fst.log hneg.ne).mul contDiffAt_snd).exp.mul (contDiffAt_snd.mul contDiffAt_const).cos).congr_of_eventuallyEq ((continuousAt_fst.eventually (gt_mem_nhds hneg)).mono fun p hp => rpow_def_of_neg hp _), ((contDiffAt_fst.log hpos.ne').mul contDiffAt_snd).exp.congr_of_eventuallyEq ((continuousAt_fst.eventually (lt_mem_nhds hpos)).mono fun p hp => rpow_def_of_pos hp _)] theorem differentiableAt_rpow_of_ne (p : ℝ × ℝ) (hp : p.1 ≠ 0) : DifferentiableAt ℝ (fun p : ℝ × ℝ => p.1 ^ p.2) p := (contDiffAt_rpow_of_ne p hp).differentiableAt le_rfl theorem _root_.HasStrictDerivAt.rpow {f g : ℝ → ℝ} {f' g' : ℝ} (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h : 0 < f x) : HasStrictDerivAt (fun x => f x ^ g x) (f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) x := by convert (hasStrictFDerivAt_rpow_of_pos ((fun x => (f x, g x)) x) h).comp_hasStrictDerivAt x (hf.prodMk hg) using 1 simp [mul_assoc, mul_comm, mul_left_comm] theorem hasStrictDerivAt_rpow_const_of_ne {x : ℝ} (hx : x ≠ 0) (p : ℝ) : HasStrictDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by rcases hx.lt_or_lt with hx | hx · have := (hasStrictFDerivAt_rpow_of_neg (x, p) hx).comp_hasStrictDerivAt x ((hasStrictDerivAt_id x).prodMk (hasStrictDerivAt_const x p)) convert this using 1; simp · simpa using (hasStrictDerivAt_id x).rpow (hasStrictDerivAt_const x p) hx theorem hasStrictDerivAt_const_rpow {a : ℝ} (ha : 0 < a) (x : ℝ) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a) x := by simpa using (hasStrictDerivAt_const _ _).rpow (hasStrictDerivAt_id x) ha lemma differentiableAt_rpow_const_of_ne (p : ℝ) {x : ℝ} (hx : x ≠ 0) : DifferentiableAt ℝ (fun x => x ^ p) x := (hasStrictDerivAt_rpow_const_of_ne hx p).differentiableAt lemma differentiableOn_rpow_const (p : ℝ) : DifferentiableOn ℝ (fun x => (x : ℝ) ^ p) {0}ᶜ := fun _ hx => (Real.differentiableAt_rpow_const_of_ne p hx).differentiableWithinAt /-- This lemma says that `fun x => a ^ x` is strictly differentiable for `a < 0`. Note that these values of `a` are outside of the "official" domain of `a ^ x`, and we may redefine `a ^ x` for negative `a` if some other definition will be more convenient. -/ theorem hasStrictDerivAt_const_rpow_of_neg {a x : ℝ} (ha : a < 0) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a - exp (log a * x) * sin (x * π) * π) x := by simpa using (hasStrictFDerivAt_rpow_of_neg (a, x) ha).comp_hasStrictDerivAt x ((hasStrictDerivAt_const _ _).prodMk (hasStrictDerivAt_id _)) end Real namespace Real variable {z x y : ℝ}
Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean
396
403
theorem hasDerivAt_rpow_const {x p : ℝ} (h : x ≠ 0 ∨ 1 ≤ p) : HasDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by
rcases ne_or_eq x 0 with (hx | rfl) · exact (hasStrictDerivAt_rpow_const_of_ne hx _).hasDerivAt replace h : 1 ≤ p := h.neg_resolve_left rfl apply hasDerivAt_of_hasDerivAt_of_ne fun x hx => (hasStrictDerivAt_rpow_const_of_ne hx p).hasDerivAt exacts [continuousAt_id.rpow_const (Or.inr (zero_le_one.trans h)),
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, 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}
Mathlib/Data/ENNReal/Real.lean
37
40
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
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.List.FinRange import Mathlib.Data.List.Perm.Basic import Mathlib.Data.List.Lex import Mathlib.Data.List.Induction /-! # sublists `List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list. This file contains basic results on this function. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Nat namespace List /-! ### sublists -/ @[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl @[simp] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl /-- Auxiliary helper definition for `sublists'` -/ def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) := r₁.foldl (init := r₂) fun r l => r ++ [a :: l] theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)), sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray) (fun r l => r.push (a :: l))).toList := by intro r₁ r₂ rw [sublists'Aux, Array.foldl_toList] have := List.foldl_hom Array.toList (g₁ := fun r l => r.push (a :: l)) (g₂ := fun r l => r ++ [a :: l]) (l := r₁) (init := r₂.toArray) (by simp) simpa using this theorem sublists'_eq_sublists'Aux (l : List α) : sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by simp only [sublists', sublists'Aux_eq_array_foldl] rw [← List.foldr_hom Array.toList] · intros _ _; congr theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)), sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ := List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl] simp [sublists'Aux] @[simp 900] theorem sublists'_cons (a : α) (l : List α) : sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map] @[simp]
Mathlib/Data/List/Sublists.lean
68
72
theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by
induction' t with a t IH generalizing s · simp only [sublists'_nil, mem_singleton] exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩ simp only [sublists'_cons, mem_append, IH, mem_map]
/- 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.Hull import Mathlib.LinearAlgebra.AffineSpace.Independent /-! # Simplicial complexes In this file, we define simplicial complexes in `𝕜`-modules. A simplicial complex is a collection of simplices closed by inclusion (of vertices) and intersection (of underlying sets). We model them by a downward-closed set of affine independent finite sets whose convex hulls "glue nicely", each finite set and its convex hull corresponding respectively to the vertices and the underlying set of a simplex. ## Main declarations * `SimplicialComplex 𝕜 E`: A simplicial complex in the `𝕜`-module `E`. * `SimplicialComplex.vertices`: The zero dimensional faces of a simplicial complex. * `SimplicialComplex.facets`: The maximal faces of a simplicial complex. ## Notation `s ∈ K` means that `s` is a face of `K`. `K ≤ L` means that the faces of `K` are faces of `L`. ## Implementation notes "glue nicely" usually means that the intersection of two faces (as sets in the ambient space) is a face. Given that we store the vertices, not the faces, this would be a bit awkward to spell. Instead, `SimplicialComplex.inter_subset_convexHull` is an equivalent condition which works on the vertices. ## TODO Simplicial complexes can be generalized to affine spaces once `ConvexHull` has been ported. -/ open Finset Set variable (𝕜 E : Type*) [Ring 𝕜] [PartialOrder 𝕜] [AddCommGroup E] [Module 𝕜 E] namespace Geometry -- TODO: update to new binder order? not sure what binder order is correct for `down_closed`. /-- A simplicial complex in a `𝕜`-module is a collection of simplices which glue nicely together. Note that the textbook meaning of "glue nicely" is given in `Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull`. It is mostly useless, as `Geometry.SimplicialComplex.convexHull_inter_convexHull` is enough for all purposes. -/ @[ext] structure SimplicialComplex where /-- the faces of this simplicial complex: currently, given by their spanning vertices -/ faces : Set (Finset E) /-- the empty set is not a face: hence, all faces are non-empty -/ not_empty_mem : ∅ ∉ faces /-- the vertices in each face are affine independent: this is an implementation detail -/ indep : ∀ {s}, s ∈ faces → AffineIndependent 𝕜 ((↑) : s → E) /-- faces are downward closed: a non-empty subset of its spanning vertices spans another face -/ down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ≠ ∅ → t ∈ faces inter_subset_convexHull : ∀ {s t}, s ∈ faces → t ∈ faces → convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E) namespace SimplicialComplex variable {𝕜 E} variable {K : SimplicialComplex 𝕜 E} {s t : Finset E} {x : E} /-- A `Finset` belongs to a `SimplicialComplex` if it's a face of it. -/ instance : Membership (Finset E) (SimplicialComplex 𝕜 E) := ⟨fun K s => s ∈ K.faces⟩ /-- The underlying space of a simplicial complex is the union of its faces. -/ def space (K : SimplicialComplex 𝕜 E) : Set E := ⋃ s ∈ K.faces, convexHull 𝕜 (s : Set E) -- Porting note: Expanded `∃ s ∈ K.faces` to get the type to match more closely with Lean 3 theorem mem_space_iff : x ∈ K.space ↔ ∃ s ∈ K.faces, x ∈ convexHull 𝕜 (s : Set E) := by simp [space] -- Porting note: Original proof was `:= subset_biUnion_of_mem hs`
Mathlib/Analysis/Convex/SimplicialComplex/Basic.lean
86
87
theorem convexHull_subset_space (hs : s ∈ K.faces) : convexHull 𝕜 ↑s ⊆ K.space := by
convert subset_biUnion_of_mem hs
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Basic import Mathlib.Algebra.GroupWithZero.Basic /-! # Basic Translation Lemmas Between Functions Defined for Continued Fractions ## Summary Some simple translation lemmas between the different definitions of functions defined in `Algebra.ContinuedFractions.Basic`. -/ namespace GenContFract section General /-! ### Translations Between General Access Functions Here we give some basic translations that hold by definition between the various methods that allow us to access the numerators and denominators of a continued fraction. -/ variable {α : Type*} {g : GenContFract α} {n : ℕ} theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq] theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by rw [terminatedAt_iff_s_none, partNum_none_iff_s_none] theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq] theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by rw [terminatedAt_iff_s_none, partDen_none_iff_s_none]
Mathlib/Algebra/ContinuedFractions/Translations.lean
49
50
theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partNums.get? n = some gp.a := by
simp [partNums, s_nth_eq]
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Measure.Trim import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated /-! # Almost everywhere measurable functions A function is almost everywhere measurable if it coincides almost everywhere with a measurable function. This property, called `AEMeasurable f μ`, is defined in the file `MeasureSpaceDef`. We discuss several of its properties that are analogous to properties of measurable functions. -/ open MeasureTheory MeasureTheory.Measure Filter Set Function ENNReal variable {ι α β γ δ R : Type*} {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] {f g : α → β} {μ ν : Measure α} section @[nontriviality, measurability] theorem Subsingleton.aemeasurable [Subsingleton α] : AEMeasurable f μ := Subsingleton.measurable.aemeasurable @[nontriviality, measurability] theorem aemeasurable_of_subsingleton_codomain [Subsingleton β] : AEMeasurable f μ := (measurable_of_subsingleton_codomain f).aemeasurable @[simp, measurability] theorem aemeasurable_zero_measure : AEMeasurable f (0 : Measure α) := by nontriviality α; inhabit α exact ⟨fun _ => f default, measurable_const, rfl⟩ @[fun_prop] theorem aemeasurable_id'' (μ : Measure α) {m : MeasurableSpace α} (hm : m ≤ m0) : @AEMeasurable α α m m0 id μ := @Measurable.aemeasurable α α m0 m id μ (measurable_id'' hm) lemma aemeasurable_of_map_neZero {μ : Measure α} {f : α → β} (h : NeZero (μ.map f)) : AEMeasurable f μ := by by_contra h' simp [h'] at h namespace AEMeasurable lemma mono_ac (hf : AEMeasurable f ν) (hμν : μ ≪ ν) : AEMeasurable f μ := ⟨hf.mk f, hf.measurable_mk, hμν.ae_le hf.ae_eq_mk⟩ theorem mono_measure (h : AEMeasurable f μ) (h' : ν ≤ μ) : AEMeasurable f ν := mono_ac h h'.absolutelyContinuous theorem mono_set {s t} (h : s ⊆ t) (ht : AEMeasurable f (μ.restrict t)) : AEMeasurable f (μ.restrict s) := ht.mono_measure (restrict_mono h le_rfl) @[fun_prop] protected theorem mono' (h : AEMeasurable f μ) (h' : ν ≪ μ) : AEMeasurable f ν := ⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩ theorem ae_mem_imp_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) : ∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x := ae_imp_of_ae_restrict h.ae_eq_mk theorem ae_inf_principal_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) : f =ᶠ[ae μ ⊓ 𝓟 s] h.mk f := le_ae_restrict h.ae_eq_mk @[measurability] theorem sum_measure [Countable ι] {μ : ι → Measure α} (h : ∀ i, AEMeasurable f (μ i)) : AEMeasurable f (sum μ) := by classical nontriviality β inhabit β set s : ι → Set α := fun i => toMeasurable (μ i) { x | f x ≠ (h i).mk f x } have hsμ : ∀ i, μ i (s i) = 0 := by intro i rw [measure_toMeasurable] exact (h i).ae_eq_mk have hsm : MeasurableSet (⋂ i, s i) := MeasurableSet.iInter fun i => measurableSet_toMeasurable _ _ have hs : ∀ i x, x ∉ s i → f x = (h i).mk f x := by intro i x hx contrapose! hx exact subset_toMeasurable _ _ hx set g : α → β := (⋂ i, s i).piecewise (const α default) f refine ⟨g, measurable_of_restrict_of_restrict_compl hsm ?_ ?_, ae_sum_iff.mpr fun i => ?_⟩ · rw [restrict_piecewise] simp only [s, Set.restrict, const] exact measurable_const · rw [restrict_piecewise_compl, compl_iInter] intro t ht refine ⟨⋃ i, (h i).mk f ⁻¹' t ∩ (s i)ᶜ, MeasurableSet.iUnion fun i ↦ (measurable_mk _ ht).inter (measurableSet_toMeasurable _ _).compl, ?_⟩ ext ⟨x, hx⟩ simp only [mem_preimage, mem_iUnion, Subtype.coe_mk, Set.restrict, mem_inter_iff, mem_compl_iff] at hx ⊢ constructor · rintro ⟨i, hxt, hxs⟩ rwa [hs _ _ hxs] · rcases hx with ⟨i, hi⟩ rw [hs _ _ hi] exact fun h => ⟨i, h, hi⟩ · refine measure_mono_null (fun x (hx : f x ≠ g x) => ?_) (hsμ i) contrapose! hx refine (piecewise_eq_of_not_mem _ _ _ ?_).symm exact fun h => hx (mem_iInter.1 h i) @[simp] theorem _root_.aemeasurable_sum_measure_iff [Countable ι] {μ : ι → Measure α} : AEMeasurable f (sum μ) ↔ ∀ i, AEMeasurable f (μ i) := ⟨fun h _ => h.mono_measure (le_sum _ _), sum_measure⟩ @[simp] theorem _root_.aemeasurable_add_measure_iff : AEMeasurable f (μ + ν) ↔ AEMeasurable f μ ∧ AEMeasurable f ν := by rw [← sum_cond, aemeasurable_sum_measure_iff, Bool.forall_bool, and_comm] rfl @[measurability] theorem add_measure {f : α → β} (hμ : AEMeasurable f μ) (hν : AEMeasurable f ν) : AEMeasurable f (μ + ν) := aemeasurable_add_measure_iff.2 ⟨hμ, hν⟩ @[measurability] protected theorem iUnion [Countable ι] {s : ι → Set α} (h : ∀ i, AEMeasurable f (μ.restrict (s i))) : AEMeasurable f (μ.restrict (⋃ i, s i)) := (sum_measure h).mono_measure <| restrict_iUnion_le @[simp] theorem _root_.aemeasurable_iUnion_iff [Countable ι] {s : ι → Set α} : AEMeasurable f (μ.restrict (⋃ i, s i)) ↔ ∀ i, AEMeasurable f (μ.restrict (s i)) := ⟨fun h _ => h.mono_measure <| restrict_mono (subset_iUnion _ _) le_rfl, AEMeasurable.iUnion⟩ @[simp] theorem _root_.aemeasurable_union_iff {s t : Set α} : AEMeasurable f (μ.restrict (s ∪ t)) ↔ AEMeasurable f (μ.restrict s) ∧ AEMeasurable f (μ.restrict t) := by simp only [union_eq_iUnion, aemeasurable_iUnion_iff, Bool.forall_bool, cond, and_comm] @[measurability] theorem smul_measure [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : AEMeasurable f μ) (c : R) : AEMeasurable f (c • μ) := ⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩ theorem comp_aemeasurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f)) (hf : AEMeasurable f μ) : AEMeasurable (g ∘ f) μ := ⟨hg.mk g ∘ hf.mk f, hg.measurable_mk.comp hf.measurable_mk, (ae_eq_comp hf hg.ae_eq_mk).trans (hf.ae_eq_mk.fun_comp (mk g hg))⟩ @[fun_prop] theorem comp_aemeasurable' {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f)) (hf : AEMeasurable f μ) : AEMeasurable (fun x ↦ g (f x)) μ := comp_aemeasurable hg hf theorem comp_measurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f)) (hf : Measurable f) : AEMeasurable (g ∘ f) μ := hg.comp_aemeasurable hf.aemeasurable theorem comp_quasiMeasurePreserving {ν : Measure δ} {f : α → δ} {g : δ → β} (hg : AEMeasurable g ν) (hf : QuasiMeasurePreserving f μ ν) : AEMeasurable (g ∘ f) μ := (hg.mono' hf.absolutelyContinuous).comp_measurable hf.measurable theorem map_map_of_aemeasurable {g : β → γ} {f : α → β} (hg : AEMeasurable g (Measure.map f μ)) (hf : AEMeasurable f μ) : (μ.map f).map g = μ.map (g ∘ f) := by ext1 s hs rw [map_apply_of_aemeasurable hg hs, map_apply₀ hf (hg.nullMeasurable hs), map_apply_of_aemeasurable (hg.comp_aemeasurable hf) hs, preimage_comp] @[fun_prop, measurability] theorem prodMk {f : α → β} {g : α → γ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun x => (f x, g x)) μ := ⟨fun a => (hf.mk f a, hg.mk g a), hf.measurable_mk.prodMk hg.measurable_mk, hf.ae_eq_mk.prodMk hg.ae_eq_mk⟩ @[deprecated (since := "2025-03-05")] alias prod_mk := prodMk theorem exists_ae_eq_range_subset (H : AEMeasurable f μ) {t : Set β} (ht : ∀ᵐ x ∂μ, f x ∈ t) (h₀ : t.Nonempty) : ∃ g, Measurable g ∧ range g ⊆ t ∧ f =ᵐ[μ] g := by classical let s : Set α := toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ let g : α → β := piecewise s (fun _ => h₀.some) (H.mk f) refine ⟨g, ?_, ?_, ?_⟩ · exact Measurable.piecewise (measurableSet_toMeasurable _ _) measurable_const H.measurable_mk · rintro _ ⟨x, rfl⟩ by_cases hx : x ∈ s · simpa [g, hx] using h₀.some_mem · simp only [g, hx, piecewise_eq_of_not_mem, not_false_iff] contrapose! hx apply subset_toMeasurable simp +contextual only [hx, mem_compl_iff, mem_setOf_eq, not_and, not_false_iff, imp_true_iff] · have A : μ (toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ) = 0 := by rw [measure_toMeasurable, ← compl_mem_ae_iff, compl_compl] exact H.ae_eq_mk.and ht filter_upwards [compl_mem_ae_iff.2 A] with x hx rw [mem_compl_iff] at hx simp only [s, g, hx, piecewise_eq_of_not_mem, not_false_iff] contrapose! hx apply subset_toMeasurable simp only [hx, mem_compl_iff, mem_setOf_eq, false_and, not_false_iff] theorem exists_measurable_nonneg {β} [Preorder β] [Zero β] {mβ : MeasurableSpace β} {f : α → β} (hf : AEMeasurable f μ) (f_nn : ∀ᵐ t ∂μ, 0 ≤ f t) : ∃ g, Measurable g ∧ 0 ≤ g ∧ f =ᵐ[μ] g := by obtain ⟨G, hG_meas, hG_mem, hG_ae_eq⟩ := hf.exists_ae_eq_range_subset f_nn ⟨0, le_rfl⟩ exact ⟨G, hG_meas, fun x => hG_mem (mem_range_self x), hG_ae_eq⟩ theorem subtype_mk (h : AEMeasurable f μ) {s : Set β} {hfs : ∀ x, f x ∈ s} : AEMeasurable (codRestrict f s hfs) μ := by nontriviality α; inhabit α obtain ⟨g, g_meas, hg, fg⟩ : ∃ g : α → β, Measurable g ∧ range g ⊆ s ∧ f =ᵐ[μ] g := h.exists_ae_eq_range_subset (Eventually.of_forall hfs) ⟨_, hfs default⟩ refine ⟨codRestrict g s fun x => hg (mem_range_self _), Measurable.subtype_mk g_meas, ?_⟩ filter_upwards [fg] with x hx simpa [Subtype.ext_iff] end AEMeasurable theorem aemeasurable_const' (h : ∀ᵐ (x) (y) ∂μ, f x = f y) : AEMeasurable f μ := by rcases eq_or_ne μ 0 with (rfl | hμ) · exact aemeasurable_zero_measure · haveI := ae_neBot.2 hμ rcases h.exists with ⟨x, hx⟩ exact ⟨const α (f x), measurable_const, EventuallyEq.symm hx⟩ open scoped Interval in theorem aemeasurable_uIoc_iff [LinearOrder α] {f : α → β} {a b : α} : (AEMeasurable f <| μ.restrict <| Ι a b) ↔ (AEMeasurable f <| μ.restrict <| Ioc a b) ∧ (AEMeasurable f <| μ.restrict <| Ioc b a) := by rw [uIoc_eq_union, aemeasurable_union_iff] theorem aemeasurable_iff_measurable [μ.IsComplete] : AEMeasurable f μ ↔ Measurable f := ⟨fun h => h.nullMeasurable.measurable_of_complete, fun h => h.aemeasurable⟩ theorem MeasurableEmbedding.aemeasurable_map_iff {g : β → γ} (hf : MeasurableEmbedding f) : AEMeasurable g (μ.map f) ↔ AEMeasurable (g ∘ f) μ := by refine ⟨fun H => H.comp_measurable hf.measurable, ?_⟩ rintro ⟨g₁, hgm₁, heq⟩ rcases hf.exists_measurable_extend hgm₁ fun x => ⟨g x⟩ with ⟨g₂, hgm₂, rfl⟩ exact ⟨g₂, hgm₂, hf.ae_map_iff.2 heq⟩
Mathlib/MeasureTheory/Measure/AEMeasurable.lean
244
249
theorem MeasurableEmbedding.aemeasurable_comp_iff {g : β → γ} (hg : MeasurableEmbedding g) {μ : Measure α} : AEMeasurable (g ∘ f) μ ↔ AEMeasurable f μ := by
refine ⟨fun H => ?_, hg.measurable.comp_aemeasurable⟩ suffices AEMeasurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) μ by rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this exact hg.measurable_rangeSplitting.comp_aemeasurable H.subtype_mk
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Cover import Mathlib.Order.Iterate /-! # Successor and predecessor This file defines successor and predecessor orders. `succ a`, the successor of an element `a : α` is the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples include `ℕ`, `ℤ`, `ℕ+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor order... ## Typeclasses * `SuccOrder`: Order equipped with a sensible successor function. * `PredOrder`: Order equipped with a sensible predecessor function. ## Implementation notes Maximal elements don't have a sensible successor. Thus the naïve typeclass ```lean class NaiveSuccOrder (α : Type*) [Preorder α] where (succ : α → α) (succ_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) (lt_succ_iff : ∀ {a b}, a < succ b ↔ a ≤ b) ``` can't apply to an `OrderTop` because plugging in `a = b = ⊤` into either of `succ_le_iff` and `lt_succ_iff` yields `⊤ < ⊤` (or more generally `m < m` for a maximal element `m`). The solution taken here is to remove the implications `≤ → <` and instead require that `a < succ a` for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of `max_of_succ_le`). The stricter condition of every element having a sensible successor can be obtained through the combination of `SuccOrder α` and `NoMaxOrder α`. -/ open Function OrderDual Set variable {α β : Type*} /-- Order equipped with a sensible successor function. -/ @[ext] class SuccOrder (α : Type*) [Preorder α] where /-- Successor function -/ succ : α → α /-- Proof of basic ordering with respect to `succ` -/ le_succ : ∀ a, a ≤ succ a /-- Proof of interaction between `succ` and maximal element -/ max_of_succ_le {a} : succ a ≤ a → IsMax a /-- Proof that `succ a` is the least element greater than `a` -/ succ_le_of_lt {a b} : a < b → succ a ≤ b /-- Order equipped with a sensible predecessor function. -/ @[ext] class PredOrder (α : Type*) [Preorder α] where /-- Predecessor function -/ pred : α → α /-- Proof of basic ordering with respect to `pred` -/ pred_le : ∀ a, pred a ≤ a /-- Proof of interaction between `pred` and minimal element -/ min_of_le_pred {a} : a ≤ pred a → IsMin a /-- Proof that `pred b` is the greatest element less than `b` -/ le_pred_of_lt {a b} : a < b → a ≤ pred b instance [Preorder α] [SuccOrder α] : PredOrder αᵒᵈ where pred := toDual ∘ SuccOrder.succ ∘ ofDual pred_le := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, SuccOrder.le_succ, implies_true] min_of_le_pred h := by apply SuccOrder.max_of_succ_le h le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h instance [Preorder α] [PredOrder α] : SuccOrder αᵒᵈ where succ := toDual ∘ PredOrder.pred ∘ ofDual le_succ := by simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual, PredOrder.pred_le, implies_true] max_of_succ_le h := by apply PredOrder.min_of_le_pred h succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h section Preorder variable [Preorder α] /-- A constructor for `SuccOrder α` usable when `α` has no maximal element. -/ def SuccOrder.ofSuccLeIff (succ : α → α) (hsucc_le_iff : ∀ {a b}, succ a ≤ b ↔ a < b) : SuccOrder α := { succ le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim succ_le_of_lt := fun h => hsucc_le_iff.2 h } /-- A constructor for `PredOrder α` usable when `α` has no minimal element. -/ def PredOrder.ofLePredIff (pred : α → α) (hle_pred_iff : ∀ {a b}, a ≤ pred b ↔ a < b) : PredOrder α := { pred pred_le := fun _ => (hle_pred_iff.1 le_rfl).le min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim le_pred_of_lt := fun h => hle_pred_iff.2 h } end Preorder section LinearOrder variable [LinearOrder α] /-- A constructor for `SuccOrder α` for `α` a linear order. -/ @[simps] def SuccOrder.ofCore (succ : α → α) (hn : ∀ {a}, ¬IsMax a → ∀ b, a < b ↔ succ a ≤ b) (hm : ∀ a, IsMax a → succ a = a) : SuccOrder α := { succ succ_le_of_lt := fun {a b} => by_cases (fun h hab => (hm a h).symm ▸ hab.le) fun h => (hn h b).mp le_succ := fun a => by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } /-- A constructor for `PredOrder α` for `α` a linear order. -/ @[simps] def PredOrder.ofCore (pred : α → α) (hn : ∀ {a}, ¬IsMin a → ∀ b, b ≤ pred a ↔ b < a) (hm : ∀ a, IsMin a → pred a = a) : PredOrder α := { pred le_pred_of_lt := fun {a b} => by_cases (fun h hab => (hm b h).symm ▸ hab.le) fun h => (hn h a).mpr pred_le := fun a => by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not } variable (α) open Classical in /-- A well-order is a `SuccOrder`. -/ noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT α] : SuccOrder α := ofCore (fun a ↦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a) (fun ha _ ↦ by rw [not_isMax_iff] at ha simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha] exact ⟨(wellFounded_lt.min_le · ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)⟩) fun _ ha ↦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr ·) /-- A linear order with well-founded greater-than relation is a `PredOrder`. -/ noncomputable def PredOrder.ofLinearWellFoundedGT (α) [LinearOrder α] [WellFoundedGT α] : PredOrder α := letI := SuccOrder.ofLinearWellFoundedLT αᵒᵈ; inferInstanceAs (PredOrder αᵒᵈᵒᵈ) end LinearOrder /-! ### Successor order -/ namespace Order section Preorder variable [Preorder α] [SuccOrder α] {a b : α} /-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater than `a`. If `a` is maximal, then `succ a = a`. -/ def succ : α → α := SuccOrder.succ theorem le_succ : ∀ a : α, a ≤ succ a := SuccOrder.le_succ theorem max_of_succ_le {a : α} : succ a ≤ a → IsMax a := SuccOrder.max_of_succ_le theorem succ_le_of_lt {a b : α} : a < b → succ a ≤ b := SuccOrder.succ_le_of_lt alias _root_.LT.lt.succ_le := succ_le_of_lt @[simp] theorem succ_le_iff_isMax : succ a ≤ a ↔ IsMax a := ⟨max_of_succ_le, fun h => h <| le_succ _⟩ alias ⟨_root_.IsMax.of_succ_le, _root_.IsMax.succ_le⟩ := succ_le_iff_isMax @[simp] theorem lt_succ_iff_not_isMax : a < succ a ↔ ¬IsMax a := ⟨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_le fun h => ha <| max_of_succ_le h⟩ alias ⟨_, lt_succ_of_not_isMax⟩ := lt_succ_iff_not_isMax theorem wcovBy_succ (a : α) : a ⩿ succ a := ⟨le_succ a, fun _ hb => (succ_le_of_lt hb).not_lt⟩ theorem covBy_succ_of_not_isMax (h : ¬IsMax a) : a ⋖ succ a := (wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h theorem lt_succ_of_le_of_not_isMax (hab : b ≤ a) (ha : ¬IsMax a) : b < succ a := hab.trans_lt <| lt_succ_of_not_isMax ha theorem succ_le_iff_of_not_isMax (ha : ¬IsMax a) : succ a ≤ b ↔ a < b := ⟨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_lt⟩ lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : ¬ IsMax b) : succ a < succ b := lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb @[simp, mono, gcongr] theorem succ_le_succ (h : a ≤ b) : succ a ≤ succ b := by by_cases hb : IsMax b · by_cases hba : b ≤ a · exact (hb <| hba.trans <| le_succ _).trans (le_succ _) · exact succ_le_of_lt ((h.lt_of_not_le hba).trans_le <| le_succ b) · rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h] apply lt_succ_of_le_of_not_isMax h hb theorem succ_mono : Monotone (succ : α → α) := fun _ _ => succ_le_succ /-- See also `Order.succ_eq_of_covBy`. -/ lemma le_succ_of_wcovBy (h : a ⩿ b) : b ≤ succ a := by obtain hab | ⟨-, hba⟩ := h.covBy_or_le_and_le · by_contra hba exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_le hba · exact hba.trans (le_succ _) alias _root_.WCovBy.le_succ := le_succ_of_wcovBy theorem le_succ_iterate (k : ℕ) (x : α) : x ≤ succ^[k] x := id_le_iterate_of_id_le le_succ _ _ theorem isMax_iterate_succ_of_eq_of_lt {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_lt : n < m) : IsMax (succ^[n] a) := by refine max_of_succ_le (le_trans ?_ h_eq.symm.le) rw [← iterate_succ_apply' succ] have h_le : n + 1 ≤ m := Nat.succ_le_of_lt h_lt exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le theorem isMax_iterate_succ_of_eq_of_ne {n m : ℕ} (h_eq : succ^[n] a = succ^[m] a) (h_ne : n ≠ m) : IsMax (succ^[n] a) := by rcases le_total n m with h | h · exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne) · rw [h_eq] exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm) theorem Iic_subset_Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iic a ⊆ Iio (succ a) := fun _ => (lt_succ_of_le_of_not_isMax · ha) theorem Ici_succ_of_not_isMax (ha : ¬IsMax a) : Ici (succ a) = Ioi a := Set.ext fun _ => succ_le_iff_of_not_isMax ha theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Icc a b ⊆ Ico a (succ b) := by rw [← Ici_inter_Iio, ← Ici_inter_Iic] gcongr intro _ h apply lt_succ_of_le_of_not_isMax h hb theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioc a b ⊆ Ioo a (succ b) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iic] gcongr intro _ h apply Iic_subset_Iio_succ_of_not_isMax hb h theorem Icc_succ_left_of_not_isMax (ha : ¬IsMax a) : Icc (succ a) b = Ioc a b := by rw [← Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic] theorem Ico_succ_left_of_not_isMax (ha : ¬IsMax a) : Ico (succ a) b = Ioo a b := by rw [← Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio] section NoMaxOrder variable [NoMaxOrder α] theorem lt_succ (a : α) : a < succ a := lt_succ_of_not_isMax <| not_isMax a @[simp] theorem lt_succ_of_le : a ≤ b → a < succ b := (lt_succ_of_le_of_not_isMax · <| not_isMax b) @[simp] theorem succ_le_iff : succ a ≤ b ↔ a < b := succ_le_iff_of_not_isMax <| not_isMax a @[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab] theorem succ_strictMono : StrictMono (succ : α → α) := fun _ _ => succ_lt_succ theorem covBy_succ (a : α) : a ⋖ succ a := covBy_succ_of_not_isMax <| not_isMax a theorem Iic_subset_Iio_succ (a : α) : Iic a ⊆ Iio (succ a) := by simp @[simp] theorem Ici_succ (a : α) : Ici (succ a) = Ioi a := Ici_succ_of_not_isMax <| not_isMax _ @[simp] theorem Icc_subset_Ico_succ_right (a b : α) : Icc a b ⊆ Ico a (succ b) := Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Ioc_subset_Ioo_succ_right (a b : α) : Ioc a b ⊆ Ioo a (succ b) := Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _ @[simp] theorem Icc_succ_left (a b : α) : Icc (succ a) b = Ioc a b := Icc_succ_left_of_not_isMax <| not_isMax _ @[simp] theorem Ico_succ_left (a b : α) : Ico (succ a) b = Ioo a b := Ico_succ_left_of_not_isMax <| not_isMax _ end NoMaxOrder end Preorder section PartialOrder variable [PartialOrder α] [SuccOrder α] {a b : α} @[simp] theorem succ_eq_iff_isMax : succ a = a ↔ IsMax a := ⟨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _⟩ alias ⟨_, _root_.IsMax.succ_eq⟩ := succ_eq_iff_isMax lemma le_iff_eq_or_succ_le : a ≤ b ↔ a = b ∨ succ a ≤ b := by by_cases ha : IsMax a · simpa [ha.succ_eq] using le_of_eq · rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt] theorem le_le_succ_iff : a ≤ b ∧ b ≤ succ a ↔ b = a ∨ b = succ a := by refine ⟨fun h => or_iff_not_imp_left.2 fun hba : b ≠ a => h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm), ?_⟩ rintro (rfl | rfl) · exact ⟨le_rfl, le_succ b⟩ · exact ⟨le_succ a, le_rfl⟩ /-- See also `Order.le_succ_of_wcovBy`. -/ lemma succ_eq_of_covBy (h : a ⋖ b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ alias _root_.CovBy.succ_eq := succ_eq_of_covBy theorem _root_.OrderIso.map_succ [PartialOrder β] [SuccOrder β] (f : α ≃o β) (a : α) : f (succ a) = succ (f a) := by by_cases h : IsMax a · rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq] · exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm section NoMaxOrder variable [NoMaxOrder α] theorem succ_eq_iff_covBy : succ a = b ↔ a ⋖ b := ⟨by rintro rfl; exact covBy_succ _, CovBy.succ_eq⟩ end NoMaxOrder section OrderTop variable [OrderTop α] @[simp] theorem succ_top : succ (⊤ : α) = ⊤ := by rw [succ_eq_iff_isMax, isMax_iff_eq_top] theorem succ_le_iff_eq_top : succ a ≤ a ↔ a = ⊤ := succ_le_iff_isMax.trans isMax_iff_eq_top theorem lt_succ_iff_ne_top : a < succ a ↔ a ≠ ⊤ := lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top end OrderTop section OrderBot variable [OrderBot α] [Nontrivial α] theorem bot_lt_succ (a : α) : ⊥ < succ a := (lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le theorem succ_ne_bot (a : α) : succ a ≠ ⊥ := (bot_lt_succ a).ne' end OrderBot end PartialOrder section LinearOrder variable [LinearOrder α] [SuccOrder α] {a b : α} theorem le_of_lt_succ {a b : α} : a < succ b → a ≤ b := fun h ↦ by by_contra! nh exact (h.trans_le (succ_le_of_lt nh)).false theorem lt_succ_iff_of_not_isMax (ha : ¬IsMax a) : b < succ a ↔ b ≤ a := ⟨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax ha⟩ theorem succ_lt_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a < succ b ↔ a < b := by rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha] theorem succ_le_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a ≤ succ b ↔ a ≤ b := by rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb] theorem Iio_succ_of_not_isMax (ha : ¬IsMax a) : Iio (succ a) = Iic a := Set.ext fun _ => lt_succ_iff_of_not_isMax ha theorem Ico_succ_right_of_not_isMax (hb : ¬IsMax b) : Ico a (succ b) = Icc a b := by rw [← Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic] theorem Ioo_succ_right_of_not_isMax (hb : ¬IsMax b) : Ioo a (succ b) = Ioc a b := by rw [← Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic] theorem succ_eq_succ_iff_of_not_isMax (ha : ¬IsMax a) (hb : ¬IsMax b) : succ a = succ b ↔ a = b := by rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb, succ_lt_succ_iff_of_not_isMax ha hb] theorem le_succ_iff_eq_or_le : a ≤ succ b ↔ a = succ b ∨ a ≤ b := by by_cases hb : IsMax b · rw [hb.succ_eq, or_iff_right_of_imp le_of_eq] · rw [← lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt] theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : ¬IsMax b) : a < succ b ↔ a = b ∨ a < b := (lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt
Mathlib/Order/SuccPred/Basic.lean
431
434
theorem not_isMin_succ [Nontrivial α] (a : α) : ¬ IsMin (succ a) := by
obtain ha | ha := (le_succ a).eq_or_lt · exact (ha ▸ succ_eq_iff_isMax.1 ha.symm).not_isMin · exact not_isMin_of_lt ha
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Patrick Massot -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.MeasureTheory.Measure.Real import Mathlib.Order.Filter.IndicatorFunction /-! # The dominated convergence theorem This file collects various results related to the Lebesgue dominated convergence theorem for the Bochner integral. ## Main results - `MeasureTheory.tendsto_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for the Bochner integral - `MeasureTheory.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for series - `MeasureTheory.integral_tsum`, `MeasureTheory.integral_tsum_of_summable_integral_norm`: the integral and `tsum`s commute, if the norms of the functions form a summable series - `intervalIntegral.hasSum_integral_of_dominated_convergence`: the Lebesgue dominated convergence theorem for parametric interval integrals - `intervalIntegral.continuous_of_dominated_interval`: continuity of the interval integral w.r.t. a parameter - `intervalIntegral.continuous_primitive` and friends: primitives of interval integrable measurable functions are continuous -/ open MeasureTheory Metric /-! ## The Lebesgue dominated convergence theorem for the Bochner integral -/ section DominatedConvergenceTheorem open Set Filter TopologicalSpace ENNReal open scoped Topology Interval namespace MeasureTheory variable {α E G : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup G] [NormedSpace ℝ G] {m : MeasurableSpace α} {μ : Measure α} /-- **Lebesgue dominated convergence theorem** provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their integrals. We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound μ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_integral_of_dominated_convergence {F : ℕ → α → G} {f : α → G} (bound : α → ℝ) (F_measurable : ∀ n, AEStronglyMeasurable (F n) μ) (bound_integrable : Integrable bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) atTop (𝓝 (f a))) : Tendsto (fun n => ∫ a, F n a ∂μ) atTop (𝓝 <| ∫ a, f a ∂μ) := by by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact tendsto_setToFun_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul μ) bound F_measurable bound_integrable h_bound h_lim · simp [integral, hG] /-- Lebesgue dominated convergence theorem for filters with a countable basis -/
Mathlib/MeasureTheory/Integral/DominatedConvergence.lean
66
75
theorem tendsto_integral_filter_of_dominated_convergence {ι} {l : Filter ι} [l.IsCountablyGenerated] {F : ι → α → G} {f : α → G} (bound : α → ℝ) (hF_meas : ∀ᶠ n in l, AEStronglyMeasurable (F n) μ) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (bound_integrable : Integrable bound μ) (h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => F n a) l (𝓝 (f a))) : Tendsto (fun n => ∫ a, F n a ∂μ) l (𝓝 <| ∫ a, f a ∂μ) := by
by_cases hG : CompleteSpace G · simp only [integral, hG, L1.integral] exact tendsto_setToFun_filter_of_dominated_convergence (dominatedFinMeasAdditive_weightedSMul μ) bound hF_meas h_bound bound_integrable h_lim · simp [integral, hG, tendsto_const_nhds]
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Computation.Basic import Mathlib.Algebra.ContinuedFractions.Translations import Mathlib.Algebra.Order.Floor.Ring /-! # Basic Translation Lemmas Between Structures Defined for Computing Continued Fractions ## Summary This is a collection of simple lemmas between the different structures used for the computation of continued fractions defined in `Mathlib.Algebra.ContinuedFractions.Computation.Basic`. The file consists of three sections: 1. Recurrences and inversion lemmas for `IntFractPair.stream`: these lemmas give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. 2. Translation lemmas for the head term: these lemmas show us that the head term of the computed continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation process. 3. Translation lemmas for the sequence: these lemmas show how the sequences of the involved structures (`IntFractPair.stream`, `IntFractPair.seq1`, and `GenContFract.of`) are connected, i.e. how the values are moved along the structures and the termination of one sequence implies the termination of another sequence. ## Main Theorems - `succ_nth_stream_eq_some_iff` gives as a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. - `succ_nth_stream_eq_none_iff` gives as a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. - `get?_of_eq_some_of_succ_get?_intFractPair_stream` and `get?_of_eq_some_of_get?_intFractPair_stream_fr_ne_zero` show how the entries of the sequence of the computed continued fraction can be obtained from the stream of integer and fractional parts. -/ assert_not_exists Finset namespace GenContFract open GenContFract (of) -- Fix a discrete linear ordered division ring with `floor` function and a value `v`. variable {K : Type*} [DivisionRing K] [LinearOrder K] [FloorRing K] {v : K} namespace IntFractPair /-! ### Recurrences and Inversion Lemmas for `IntFractPair.stream` Here we state some lemmas that give us inversion rules and recurrences for the computation of the stream of integer and fractional parts of a value. -/ theorem stream_zero (v : K) : IntFractPair.stream v 0 = some (IntFractPair.of v) := rfl variable {n : ℕ} theorem stream_eq_none_of_fr_eq_zero {ifp_n : IntFractPair K} (stream_nth_eq : IntFractPair.stream v n = some ifp_n) (nth_fr_eq_zero : ifp_n.fr = 0) : IntFractPair.stream v (n + 1) = none := by obtain ⟨_, fr⟩ := ifp_n change fr = 0 at nth_fr_eq_zero simp [IntFractPair.stream, stream_nth_eq, nth_fr_eq_zero] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of termination. -/ theorem succ_nth_stream_eq_none_iff : IntFractPair.stream v (n + 1) = none ↔ IntFractPair.stream v n = none ∨ ∃ ifp, IntFractPair.stream v n = some ifp ∧ ifp.fr = 0 := by rw [IntFractPair.stream] cases IntFractPair.stream v n <;> simp [imp_false] /-- Gives a recurrence to compute the `n + 1`th value of the sequence of integer and fractional parts of a value in case of non-termination. -/ theorem succ_nth_stream_eq_some_iff {ifp_succ_n : IntFractPair K} : IntFractPair.stream v (n + 1) = some ifp_succ_n ↔ ∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr ≠ 0 ∧ IntFractPair.of ifp_n.fr⁻¹ = ifp_succ_n := by simp [IntFractPair.stream, ite_eq_iff, Option.bind_eq_some_iff] /-- An easier to use version of one direction of `GenContFract.IntFractPair.succ_nth_stream_eq_some_iff`. -/ theorem stream_succ_of_some {p : IntFractPair K} (h : IntFractPair.stream v n = some p) (h' : p.fr ≠ 0) : IntFractPair.stream v (n + 1) = some (IntFractPair.of p.fr⁻¹) := succ_nth_stream_eq_some_iff.mpr ⟨p, h, h', rfl⟩ /-- The stream of `IntFractPair`s of an integer stops after the first term. -/ theorem stream_succ_of_int [IsStrictOrderedRing K] (a : ℤ) (n : ℕ) : IntFractPair.stream (a : K) (n + 1) = none := by induction n with | zero => refine IntFractPair.stream_eq_none_of_fr_eq_zero (IntFractPair.stream_zero (a : K)) ?_ simp only [IntFractPair.of, Int.fract_intCast] | succ n ih => exact IntFractPair.succ_nth_stream_eq_none_iff.mpr (Or.inl ih) theorem exists_succ_nth_stream_of_fr_zero {ifp_succ_n : IntFractPair K} (stream_succ_nth_eq : IntFractPair.stream v (n + 1) = some ifp_succ_n) (succ_nth_fr_eq_zero : ifp_succ_n.fr = 0) : ∃ ifp_n : IntFractPair K, IntFractPair.stream v n = some ifp_n ∧ ifp_n.fr⁻¹ = ⌊ifp_n.fr⁻¹⌋ := by -- get the witness from `succ_nth_stream_eq_some_iff` and prove that it has the additional -- properties rcases succ_nth_stream_eq_some_iff.mp stream_succ_nth_eq with ⟨ifp_n, seq_nth_eq, _, rfl⟩ refine ⟨ifp_n, seq_nth_eq, ?_⟩ simpa only [IntFractPair.of, Int.fract, sub_eq_zero] using succ_nth_fr_eq_zero /-- A recurrence relation that expresses the `(n+1)`th term of the stream of `IntFractPair`s of `v` for non-integer `v` in terms of the `n`th term of the stream associated to the inverse of the fractional part of `v`. -/ theorem stream_succ (h : Int.fract v ≠ 0) (n : ℕ) : IntFractPair.stream v (n + 1) = IntFractPair.stream (Int.fract v)⁻¹ n := by induction n with | zero => have H : (IntFractPair.of v).fr = Int.fract v := by simp [IntFractPair.of] rw [stream_zero, stream_succ_of_some (stream_zero v) (ne_of_eq_of_ne H h), H] | succ n ih => rcases eq_or_ne (IntFractPair.stream (Int.fract v)⁻¹ n) none with hnone | hsome · rw [hnone] at ih rw [succ_nth_stream_eq_none_iff.mpr (Or.inl hnone), succ_nth_stream_eq_none_iff.mpr (Or.inl ih)] · obtain ⟨p, hp⟩ := Option.ne_none_iff_exists'.mp hsome rw [hp] at ih rcases eq_or_ne p.fr 0 with hz | hnz · rw [stream_eq_none_of_fr_eq_zero hp hz, stream_eq_none_of_fr_eq_zero ih hz] · rw [stream_succ_of_some hp hnz, stream_succ_of_some ih hnz] end IntFractPair section Head /-! ### Translation of the Head Term Here we state some lemmas that show us that the head term of the computed continued fraction of a value `v` is `⌊v⌋` and how this head term is moved along the structures used in the computation process. -/ /-- The head term of the sequence with head of `v` is just the integer part of `v`. -/ @[simp] theorem IntFractPair.seq1_fst_eq_of : (IntFractPair.seq1 v).fst = IntFractPair.of v := rfl theorem of_h_eq_intFractPair_seq1_fst_b : (of v).h = (IntFractPair.seq1 v).fst.b := by cases aux_seq_eq : IntFractPair.seq1 v simp [of, aux_seq_eq] /-- The head term of the gcf of `v` is `⌊v⌋`. -/ @[simp]
Mathlib/Algebra/ContinuedFractions/Computation/Translations.lean
163
165
theorem of_h_eq_floor : (of v).h = ⌊v⌋ := by
simp [of_h_eq_intFractPair_seq1_fst_b, IntFractPair.of]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by rcases le_or_lt 0 x with hx | hx · rw [abs_rpow_of_nonneg hx] · rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 · by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] · rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hx₀, mul_inv_cancel₀] exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by calc _ ≤ |x ^ (log x)⁻¹| := le_abs_self _ _ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt · simp [hx] · rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) · rw [zero_rpow h, zero_eq_mul] have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0 exact this.imp zero_rpow zero_rpow · exact rpow_add pos _ _ /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) · rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) /-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) · by_cases h : y + z = 0 · simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp · simp [rpow_add', ← H, h] · simp [rpow_add pos] theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ} (h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs · rw [sum_empty, Finset.prod_empty, rpow_zero] · rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊢ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] protected theorem _root_.HasCompactSupport.rpow_const {α : Type*} [TopologicalSpace α] {f : α → ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r ≠ 0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (· ^ r)) (Real.zero_rpow hr) end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) : (x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) · rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : ℂ) (y : ℝ) : x ^ (y : ℂ) = ↑(‖x‖ ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx · simp [ofReal_cpow le_rfl] · rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [norm_pos_iff] lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = ‖x‖ ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = ‖x‖ ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]] rcases eq_or_ne w.re 0 with hw | hw · simp [hw, h rfl hw] · rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : ℂ) : ‖z ^ w‖ ≤ ‖z‖ ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 → w.re = 0 → w = 0 · exact (norm_cpow_of_imp h).le · push_neg at h simp [h] @[simp] theorem norm_cpow_real (x : ℂ) (y : ℝ) : ‖x ^ (y : ℂ)‖ = ‖x‖ ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : ℂ) (n : ℕ) : ‖x ^ (n⁻¹ : ℂ)‖ = ‖x‖ ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : ‖(x : ℂ) ^ y‖ = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) : ‖(x : ℂ) ^ y‖ = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] @[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero @[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp @[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le @[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real @[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos := norm_cpow_eq_rpow_re_of_pos @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg := norm_cpow_eq_rpow_re_of_nonneg open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : ℂ) : (fun t : ℝ ↦ ‖(t : ℂ) ^ c‖) =ᶠ[atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ := (norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) : (x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by rw [cpow_mul, ofReal_cpow hx] · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : ℕ} theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] lemma rpow_pow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y] lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y] lemma rpow_add_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] lemma rpow_add_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_intCast hx y n lemma rpow_sub_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_intCast hx y (-n) lemma rpow_sub_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_intCast hx y n lemma rpow_add_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_natCast' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_natCast' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] @[simp] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by rw [← rpow_natCast] simp only [Nat.cast_ofNat] theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H simp only [rpow_intCast, zpow_one, zpow_neg] theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all · rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)] all_goals positivity theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancel₀ hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancel₀ hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel₀ hn0, rpow_one] theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel₀ hn0, rpow_one] lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr, bound] theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx · rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ · rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr, bound] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp exact le_of_lt (rpow_lt_rpow h h₁' h₂') theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_inv₀, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by have := hx.trans_le hxy rw [← inv_le_inv₀, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_inv₀ (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) : x ^ z ≤ y ^ z := by rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) : AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1)
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
636
641
theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by
repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) :
/- Copyright (c) 2023 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Prod import Mathlib.Tactic.Common /-! # Lemmas about the divisibility relation in product (semi)groups -/ variable {ι G₁ G₂ : Type*} {G : ι → Type*} [Semigroup G₁] [Semigroup G₂] [∀ i, Semigroup (G i)]
Mathlib/Algebra/Divisibility/Prod.lean
16
20
theorem prod_dvd_iff {x y : G₁ × G₂} : x ∣ y ↔ x.1 ∣ y.1 ∧ x.2 ∣ y.2 := by
cases x; cases y simp only [dvd_def, Prod.exists, Prod.mk_mul_mk, Prod.mk.injEq, exists_and_left, exists_and_right, and_self, true_and]
/- Copyright (c) 2024 Ira Fesefeldt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ira Fesefeldt -/ import Mathlib.SetTheory.Ordinal.Arithmetic /-! # Ordinal Approximants for the Fixed points on complete lattices This file sets up the ordinal-indexed approximation theory of fixed points of a monotone function in a complete lattice [Cousot1979]. The proof follows loosely the one from [Echenique2005]. However, the proof given here is not constructive as we use the non-constructive axiomatization of ordinals from mathlib. It still allows an approximation scheme indexed over the ordinals. ## Main definitions * `OrdinalApprox.lfpApprox`: The ordinal-indexed approximation of the least fixed point greater or equal than an initial value of a bundled monotone function. * `OrdinalApprox.gfpApprox`: The ordinal-indexed approximation of the greatest fixed point less or equal than an initial value of a bundled monotone function. ## Main theorems * `OrdinalApprox.lfp_mem_range_lfpApprox`: The ordinal-indexed approximation of the least fixed point eventually reaches the least fixed point * `OrdinalApprox.gfp_mem_range_gfpApprox`: The ordinal-indexed approximation of the greatest fixed point eventually reaches the greatest fixed point ## References * [F. Echenique, *A short and constructive proof of Tarski’s fixed-point theorem*][Echenique2005] * [P. Cousot & R. Cousot, *Constructive Versions of Tarski's Fixed Point Theorems*][Cousot1979] ## Tags fixed point, complete lattice, monotone function, ordinals, approximation -/ namespace Cardinal universe u variable {α : Type u} variable (g : Ordinal → α) open Cardinal Ordinal SuccOrder Function Set theorem not_injective_limitation_set : ¬ InjOn g (Iio (ord <| succ #α)) := by intro h_inj have h := lift_mk_le_lift_mk_of_injective <| injOn_iff_injective.1 h_inj have mk_initialSeg_subtype : #(Iio (ord <| succ #α)) = lift.{u + 1} (succ #α) := by simpa only [coe_setOf, card_typein, card_ord] using mk_Iio_ordinal (ord <| succ #α) rw [mk_initialSeg_subtype, lift_lift, lift_le] at h exact not_le_of_lt (Order.lt_succ #α) h end Cardinal namespace OrdinalApprox universe u variable {α : Type u} variable [CompleteLattice α] (f : α →o α) (x : α) open Function fixedPoints Cardinal Order OrderHom set_option linter.unusedVariables false in /-- The ordinal-indexed sequence approximating the least fixed point greater than an initial value `x`. It is defined in such a way that we have `lfpApprox 0 x = x` and `lfpApprox a x = ⨆ b < a, f (lfpApprox b x)`. -/ def lfpApprox (a : Ordinal.{u}) : α := sSup ({ f (lfpApprox b) | (b : Ordinal) (h : b < a) } ∪ {x}) termination_by a decreasing_by exact h theorem lfpApprox_monotone : Monotone (lfpApprox f x) := by intros a b h rw [lfpApprox, lfpApprox] refine sSup_le_sSup ?h apply sup_le_sup_right simp only [exists_prop, Set.le_eq_subset, Set.setOf_subset_setOf, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intros a' h' use a' exact ⟨lt_of_lt_of_le h' h, rfl⟩ theorem le_lfpApprox {a : Ordinal} : x ≤ lfpApprox f x a := by rw [lfpApprox] apply le_sSup simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, true_or] theorem lfpApprox_add_one (h : x ≤ f x) (a : Ordinal) : lfpApprox f x (a+1) = f (lfpApprox f x a) := by apply le_antisymm · conv => left; rw [lfpApprox] apply sSup_le simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] apply And.intro · apply le_trans h apply Monotone.imp f.monotone exact le_lfpApprox f x · intros a' h apply f.2; apply lfpApprox_monotone; exact h · conv => right; rw [lfpApprox] apply le_sSup simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop] rw [Set.mem_union] apply Or.inl simp only [Set.mem_setOf_eq] use a theorem lfpApprox_mono_left : Monotone (lfpApprox : (α →o α) → _) := by intro f g h x a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, le_sup_left, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, true_and] intro i' h_lt apply le_sup_of_le_right apply le_sSup_of_le · use i' · apply le_trans (h _) simp only [OrderHom.toFun_eq_coe] exact g.monotone (ih i' h_lt) theorem lfpApprox_mono_mid : Monotone (lfpApprox f) := by intro x₁ x₂ h a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] constructor · exact le_sup_of_le_left h · intro i' h_i' apply le_sup_of_le_right apply le_sSup_of_le · use i' · exact f.monotone (ih i' h_i') /-- The approximations of the least fixed point stabilize at a fixed point of `f` -/ theorem lfpApprox_eq_of_mem_fixedPoints {a b : Ordinal} (h_init : x ≤ f x) (h_ab : a ≤ b) (h : lfpApprox f x a ∈ fixedPoints f) : lfpApprox f x b = lfpApprox f x a := by rw [mem_fixedPoints_iff] at h induction b using Ordinal.induction with | h b IH => apply le_antisymm · conv => left; rw [lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] apply And.intro (le_lfpApprox f x) intro a' ha'b by_cases haa : a' < a · rw [← lfpApprox_add_one f x h_init] apply lfpApprox_monotone simp only [Ordinal.add_one_eq_succ, succ_le_iff] exact haa · rw [IH a' ha'b (le_of_not_lt haa), h] · exact lfpApprox_monotone f x h_ab /-- There are distinct indices smaller than the successor of the domain's cardinality yielding the same value -/ theorem exists_lfpApprox_eq_lfpApprox : ∃ a < ord <| succ #α, ∃ b < ord <| succ #α, a ≠ b ∧ lfpApprox f x a = lfpApprox f x b := by have h_ninj := not_injective_limitation_set <| lfpApprox f x rw [Set.injOn_iff_injective, Function.not_injective_iff] at h_ninj let ⟨a, b, h_fab, h_nab⟩ := h_ninj use a.val; apply And.intro a.prop use b.val; apply And.intro b.prop apply And.intro · intro h_eq; rw [Subtype.coe_inj] at h_eq; exact h_nab h_eq · exact h_fab /-- If the sequence of ordinal-indexed approximations takes a value twice, then it actually stabilised at that value. -/ lemma lfpApprox_mem_fixedPoints_of_eq {a b c : Ordinal} (h_init : x ≤ f x) (h_ab : a < b) (h_ac : a ≤ c) (h_fab : lfpApprox f x a = lfpApprox f x b) : lfpApprox f x c ∈ fixedPoints f := by have lfpApprox_mem_fixedPoint : lfpApprox f x a ∈ fixedPoints f := by rw [mem_fixedPoints_iff, ← lfpApprox_add_one f x h_init] exact Monotone.eq_of_le_of_le (lfpApprox_monotone f x) h_fab (SuccOrder.le_succ a) (SuccOrder.succ_le_of_lt h_ab) rw [lfpApprox_eq_of_mem_fixedPoints f x h_init] · exact lfpApprox_mem_fixedPoint · exact h_ac · exact lfpApprox_mem_fixedPoint /-- The approximation at the index of the successor of the domain's cardinality is a fixed point -/ theorem lfpApprox_ord_mem_fixedPoint (h_init : x ≤ f x) : lfpApprox f x (ord <| succ #α) ∈ fixedPoints f := by let ⟨a, h_a, b, h_b, h_nab, h_fab⟩ := exists_lfpApprox_eq_lfpApprox f x cases le_total a b with | inl h_ab => exact lfpApprox_mem_fixedPoints_of_eq f x h_init (h_nab.lt_of_le h_ab) (le_of_lt h_a) h_fab | inr h_ba => exact lfpApprox_mem_fixedPoints_of_eq f x h_init (h_nab.symm.lt_of_le h_ba) (le_of_lt h_b) (h_fab.symm) /-- Every value of the approximation is less or equal than every fixed point of `f` greater or equal than the initial value -/
Mathlib/SetTheory/Ordinal/FixedPointApproximants.lean
209
211
theorem lfpApprox_le_of_mem_fixedPoints {a : α} (h_a : a ∈ fixedPoints f) (h_le_init : x ≤ a) (i : Ordinal) : lfpApprox f x i ≤ a := by
induction i using Ordinal.induction with
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Star.Basic import Mathlib.Data.Real.Basic import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Tactic.Ring /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field of characteristic zero. The result that the complex numbers are algebraically closed, see `FieldTheory.AlgebraicClosure`. -/ assert_not_exists Multiset Algebra open Set Function /-! ### Definition and basic arithmetic -/ /-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/ structure Complex : Type where /-- The real part of a complex number. -/ re : ℝ /-- The imaginary part of a complex number. -/ im : ℝ @[inherit_doc] notation "ℂ" => Complex namespace Complex open ComplexConjugate noncomputable instance : DecidableEq ℂ := Classical.decEq _ /-- The equivalence between the complex numbers and `ℝ × ℝ`. -/ @[simps apply] def equivRealProd : ℂ ≃ ℝ × ℝ where toFun z := ⟨z.re, z.im⟩ invFun p := ⟨p.1, p.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl @[simp] theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z | ⟨_, _⟩ => rfl -- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear. theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w | ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl attribute [local ext] Complex.ext lemma «forall» {p : ℂ → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ := by aesop lemma «exists» {p : ℂ → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ := by aesop theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩ theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩ @[simp] theorem range_re : range re = univ := re_surjective.range_eq @[simp] theorem range_im : range im = univ := im_surjective.range_eq /-- The natural inclusion of the real numbers into the complex numbers. -/ @[coe] def ofReal (r : ℝ) : ℂ := ⟨r, 0⟩ instance : Coe ℝ ℂ := ⟨ofReal⟩ @[simp, norm_cast] theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r := rfl @[simp, norm_cast] theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 := rfl theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl @[simp, norm_cast] theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w := ⟨congrArg re, by apply congrArg⟩ theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where prf z hz := ⟨z.re, ext rfl hz.symm⟩ /-- The product of a set on the real axis and a set on the imaginary axis of the complex plane, denoted by `s ×ℂ t`. -/ def reProdIm (s t : Set ℝ) : Set ℂ := re ⁻¹' s ∩ im ⁻¹' t @[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm @[inherit_doc] infixl:72 " ×ℂ " => reProdIm theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t := Iff.rfl instance : Zero ℂ := ⟨(0 : ℝ)⟩ instance : Inhabited ℂ := ⟨0⟩ @[simp] theorem zero_re : (0 : ℂ).re = 0 := rfl @[simp] theorem zero_im : (0 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 := rfl @[simp] theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := ofReal_inj theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr ofReal_eq_zero instance : One ℂ := ⟨(1 : ℝ)⟩ @[simp] theorem one_re : (1 : ℂ).re = 1 := rfl @[simp] theorem one_im : (1 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 := rfl @[simp] theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 := ofReal_inj theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 := not_congr ofReal_eq_one instance : Add ℂ := ⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl -- replaced by `re_ofNat` -- replaced by `im_ofNat` @[simp, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := Complex.ext_iff.2 <| by simp [ofReal] -- replaced by `Complex.ofReal_ofNat` instance : Neg ℂ := ⟨fun z => ⟨-z.re, -z.im⟩⟩ @[simp] theorem neg_re (z : ℂ) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℂ) : (-z).im = -z.im := rfl @[simp, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := Complex.ext_iff.2 <| by simp [ofReal] instance : Sub ℂ := ⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩ instance : Mul ℂ := ⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl @[simp] theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl @[simp, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := Complex.ext_iff.2 <| by simp [ofReal] theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal] theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by simp [ofReal] lemma re_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal] lemma im_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal] theorem ofReal_mul' (r : ℝ) (z : ℂ) : ↑r * z = ⟨r * z.re, r * z.im⟩ := ext (re_ofReal_mul _ _) (im_ofReal_mul _ _) /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ def I : ℂ := ⟨0, 1⟩ @[simp] theorem I_re : I.re = 0 := rfl @[simp] theorem I_im : I.im = 1 := rfl @[simp] theorem I_mul_I : I * I = -1 := Complex.ext_iff.2 <| by simp theorem I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ := Complex.ext_iff.2 <| by simp @[simp] lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I := Complex.ext_iff.2 <| by simp [ofReal] @[simp] theorem re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z := Complex.ext_iff.2 <| by simp [ofReal] theorem mul_I_re (z : ℂ) : (z * I).re = -z.im := by simp theorem mul_I_im (z : ℂ) : (z * I).im = z.re := by simp
Mathlib/Data/Complex/Basic.lean
261
261
theorem I_mul_re (z : ℂ) : (I * z).re = -z.im := by
simp
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prodMk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/
Mathlib/Topology/UniformSpace/Equicontinuity.lean
519
523
theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by
rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl
/- Copyright (c) 2021 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.NatIso /-! # Bicategories In this file we define typeclass for bicategories. A bicategory `B` consists of * objects `a : B`, * 1-morphisms `f : a ⟶ b` between objects `a b : B`, and * 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`. We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms, respectively. A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that we have * a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and * an identity `𝟙 a : a ⟶ a` for each object `a : B`. For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The 2-morphisms in the bicategory are implemented as the morphisms in this family of categories. The composition of 1-morphisms is in fact an object part of a functor `(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism `f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a 2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism `whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law `whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`, which is required as an axiom in the definition here. -/ namespace CategoryTheory universe w v u open Category Iso -- intended to be used with explicit universe parameters /-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative, but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`. There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`. These associators and unitors satisfy the pentagon and triangle equations. See https://ncatlab.org/nlab/show/bicategory. -/ @[nolint checkUnivs] class Bicategory (B : Type u) extends CategoryStruct.{v} B where /-- The category structure on the collection of 1-morphisms -/ homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance /-- Left whiskering for morphisms -/ whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h /-- Right whiskering for morphisms -/ whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h /-- The associator isomorphism: `(f ≫ g) ≫ h ≅ f ≫ g ≫ h` -/ associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h /-- The left unitor: `𝟙 a ≫ f ≅ f` -/ leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f /-- The right unitor: `f ≫ 𝟙 b ≅ f` -/ rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f -- axioms for left whiskering: whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by aesop_cat whiskerLeft_comp : ∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i), whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by aesop_cat id_whiskerLeft : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by aesop_cat comp_whiskerLeft : ∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'), whiskerLeft (f ≫ g) η = (associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by aesop_cat -- axioms for right whiskering: id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by aesop_cat comp_whiskerRight : ∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c), whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by aesop_cat whiskerRight_id : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by aesop_cat whiskerRight_comp : ∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d), whiskerRight η (g ≫ h) = (associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by aesop_cat -- associativity of whiskerings: whisker_assoc : ∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d), whiskerRight (whiskerLeft f η) h = (associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by aesop_cat -- exchange law of left and right whiskerings: whisker_exchange : ∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i), whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by aesop_cat -- pentagon identity: pentagon : ∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e), whiskerRight (associator f g h).hom i ≫ (associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom = (associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by aesop_cat -- triangle identity: triangle : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), (associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom = whiskerRight (rightUnitor f).hom g := by aesop_cat namespace Bicategory @[inherit_doc] scoped infixr:81 " ◁ " => Bicategory.whiskerLeft @[inherit_doc] scoped infixl:81 " ▷ " => Bicategory.whiskerRight @[inherit_doc] scoped notation "α_" => Bicategory.associator @[inherit_doc] scoped notation "λ_" => Bicategory.leftUnitor @[inherit_doc] scoped notation "ρ_" => Bicategory.rightUnitor /-! ### Simp-normal form for 2-morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming) `coherence` tactic. The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors) or non-structural 2-morphisms, and 2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`, where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a non-structural 2-morphisms that is also not the identity or a composite. Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`. -/ attribute [instance] homCategory attribute [reassoc] whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc whisker_exchange attribute [reassoc (attr := simp)] pentagon triangle /- The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`), which at first glance look more complicated than the LHS, but they will be eventually reduced by the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic. -/ attribute [simp] whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] /-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps] def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where hom := f ◁ η.hom inv := f ◁ η.inv instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) := (whiskerLeftIso f (asIso η)).isIso_hom @[simp] theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : inv (f ◁ η) = f ◁ inv η := by apply IsIso.inv_eq_of_hom_inv_id simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id] /-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps!] def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where hom := η.hom ▷ h inv := η.inv ▷ h instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) := (whiskerRightIso (asIso η) h).isIso_hom @[simp] theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : inv (η ▷ h) = inv η ▷ h := by apply IsIso.inv_eq_of_hom_inv_id simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id] @[reassoc (attr := simp)] theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i = (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom = f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom = (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv = (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by simp [← cancel_epi (f ◁ (α_ g h i).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv = (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv = (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv = (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom = (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by simp [← cancel_epi ((α_ f g h).hom ▷ i)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i = f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv := eq_of_inv_eq_inv (by simp) theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g := triangle f g @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by simp [← cancel_mono (f ◁ (λ_ g).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by simp [← cancel_mono ((ρ_ f).hom ▷ g)] @[reassoc] theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by simp @[reassoc] theorem associator_inv_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ (g ≫ h) ≫ (α_ f' g h).inv = (α_ f g h).inv ≫ η ▷ g ▷ h := by simp @[reassoc] theorem whiskerRight_comp_symm {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h = (α_ f g h).hom ≫ η ▷ (g ≫ h) ≫ (α_ f' g h).inv := by simp @[reassoc] theorem associator_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : (f ◁ η) ▷ h ≫ (α_ f g' h).hom = (α_ f g h).hom ≫ f ◁ η ▷ h := by simp @[reassoc] theorem associator_inv_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h ≫ (α_ f g' h).inv = (α_ f g h).inv ≫ (f ◁ η) ▷ h := by simp @[reassoc] theorem whisker_assoc_symm (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h = (α_ f g h).inv ≫ (f ◁ η) ▷ h ≫ (α_ f g' h).hom := by simp @[reassoc] theorem associator_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : (f ≫ g) ◁ η ≫ (α_ f g h').hom = (α_ f g h).hom ≫ f ◁ g ◁ η := by simp @[reassoc] theorem associator_inv_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η ≫ (α_ f g h').inv = (α_ f g h).inv ≫ (f ≫ g) ◁ η := by simp @[reassoc] theorem comp_whiskerLeft_symm (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η = (α_ f g h).inv ≫ (f ≫ g) ◁ η ≫ (α_ f g h').hom := by simp @[reassoc] theorem leftUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : 𝟙 a ◁ η ≫ (λ_ g).hom = (λ_ f).hom ≫ η := by simp @[reassoc] theorem leftUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (λ_ g).inv = (λ_ f).inv ≫ 𝟙 a ◁ η := by simp theorem id_whiskerLeft_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (λ_ f).inv ≫ 𝟙 a ◁ η ≫ (λ_ g).hom := by simp @[reassoc] theorem rightUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ▷ 𝟙 b ≫ (ρ_ g).hom = (ρ_ f).hom ≫ η := by simp @[reassoc] theorem rightUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (ρ_ g).inv = (ρ_ f).inv ≫ η ▷ 𝟙 b := by simp theorem whiskerRight_id_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (ρ_ f).inv ≫ η ▷ 𝟙 b ≫ (ρ_ g).hom := by simp theorem whiskerLeft_iff {f g : a ⟶ b} (η θ : f ⟶ g) : 𝟙 a ◁ η = 𝟙 a ◁ θ ↔ η = θ := by simp theorem whiskerRight_iff {f g : a ⟶ b} (η θ : f ⟶ g) : η ▷ 𝟙 b = θ ▷ 𝟙 b ↔ η = θ := by simp /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight f g : 𝟙 f ▷ g = 𝟙 (f ≫ g)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (f : a ⟶ b) (g : b ⟶ c) : (λ_ f).hom ▷ g = (α_ (𝟙 a) f g).hom ≫ (λ_ (f ≫ g)).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ← cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ← comp_whiskerRight_assoc, triangle, associator_naturality_left] @[reassoc, simp] theorem leftUnitor_inv_whiskerRight (f : a ⟶ b) (g : b ⟶ c) : (λ_ f).inv ▷ g = (λ_ (f ≫ g)).inv ≫ (α_ (𝟙 a) f g).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (f : a ⟶ b) (g : b ⟶ c) : f ◁ (ρ_ g).hom = (α_ f g (𝟙 c)).inv ≫ (ρ_ (f ≫ g)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (f ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ← associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right, associator_inv_naturality_right] @[reassoc, simp] theorem whiskerLeft_rightUnitor_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (ρ_ g).inv = (ρ_ (f ≫ g)).inv ≫ (α_ f g (𝟙 c)).hom := eq_of_inv_eq_inv (by simp) /- It is not so obvious whether `leftUnitor_whiskerRight` or `leftUnitor_comp` should be a simp lemma. Our choice is the former. One reason is that the latter yields the following loop: [id_whiskerLeft] : 𝟙 a ◁ (ρ_ f).hom ==> (λ_ (f ≫ 𝟙 b)).hom ≫ (ρ_ f).hom ≫ (λ_ f).inv [leftUnitor_comp] : (λ_ (f ≫ 𝟙 b)).hom ==> (α_ (𝟙 a) f (𝟙 b)).inv ≫ (λ_ f).hom ▷ 𝟙 b [whiskerRight_id] : (λ_ f).hom ▷ 𝟙 b ==> (ρ_ (𝟙 a ≫ f)).hom ≫ (λ_ f).hom ≫ (ρ_ f).inv [rightUnitor_comp] : (ρ_ (𝟙 a ≫ f)).hom ==> (α_ (𝟙 a) f (𝟙 b)).hom ≫ 𝟙 a ◁ (ρ_ f).hom -/ @[reassoc] theorem leftUnitor_comp (f : a ⟶ b) (g : b ⟶ c) : (λ_ (f ≫ g)).hom = (α_ (𝟙 a) f g).inv ≫ (λ_ f).hom ▷ g := by simp @[reassoc]
Mathlib/CategoryTheory/Bicategory/Basic.lean
399
400
theorem leftUnitor_comp_inv (f : a ⟶ b) (g : b ⟶ c) : (λ_ (f ≫ g)).inv = (λ_ f).inv ▷ g ≫ (α_ (𝟙 a) f g).hom := by
simp
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.ToSquareZero import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.IsTensorProduct import Mathlib.RingTheory.EssentialFiniteness import Mathlib.Algebra.Exact import Mathlib.LinearAlgebra.TensorProduct.RightExactness /-! # The module of kaehler differentials ## Main results - `KaehlerDifferential`: The module of kaehler differentials. For an `R`-algebra `S`, we provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. - `KaehlerDifferential.D`: The derivation into the module of kaehler differentials. - `KaehlerDifferential.span_range_derivation`: The image of `D` spans `Ω[S⁄R]` as an `S`-module. - `KaehlerDifferential.linearMapEquivDerivation`: The isomorphism `Hom_R(Ω[S⁄R], M) ≃ₗ[S] Der_R(S, M)`. - `KaehlerDifferential.quotKerTotalEquiv`: An alternative description of `Ω[S⁄R]` as `S` copies of `S` with kernel (`KaehlerDifferential.kerTotal`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` - `KaehlerDifferential.map`: Given a map between the arrows `R →+* A` and `S →+* B`, we have an `A`-linear map `Ω[A⁄R] → Ω[B⁄S]`. - `KaehlerDifferential.map_surjective`: The sequence `Ω[B⁄R] → Ω[B⁄A] → 0` is exact. - `KaehlerDifferential.exact_mapBaseChange_map`: The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A]` is exact. - `KaehlerDifferential.exact_kerCotangentToTensor_mapBaseChange`: If `A → B` is surjective with kernel `I`, then the sequence `I/I² → B ⊗[A] Ω[A⁄R] → Ω[B⁄R]` is exact. - `KaehlerDifferential.mapBaseChange_surjective`: If `A → B` is surjective, then the sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → 0` is exact. ## Future project - Define the `IsKaehlerDifferential` predicate. -/ suppress_compilation section KaehlerDifferential open scoped TensorProduct open Algebra Finsupp universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- The kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ abbrev KaehlerDifferential.ideal : Ideal (S ⊗[R] S) := RingHom.ker (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) variable {S} theorem KaehlerDifferential.one_smul_sub_smul_one_mem_ideal (a : S) : (1 : S) ⊗ₜ[R] a - a ⊗ₜ[R] (1 : S) ∈ KaehlerDifferential.ideal R S := by simp [RingHom.mem_ker] variable {R} variable {M : Type*} [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] /-- For a `R`-derivation `S → M`, this is the map `S ⊗[R] S →ₗ[S] M` sending `s ⊗ₜ t ↦ s • D t`. -/ def Derivation.tensorProductTo (D : Derivation R S M) : S ⊗[R] S →ₗ[S] M := TensorProduct.AlgebraTensorModule.lift ((LinearMap.lsmul S (S →ₗ[R] M)).flip D.toLinearMap) theorem Derivation.tensorProductTo_tmul (D : Derivation R S M) (s t : S) : D.tensorProductTo (s ⊗ₜ t) = s • D t := rfl theorem Derivation.tensorProductTo_mul (D : Derivation R S M) (x y : S ⊗[R] S) : D.tensorProductTo (x * y) = TensorProduct.lmul' (S := S) R x • D.tensorProductTo y + TensorProduct.lmul' (S := S) R y • D.tensorProductTo x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [zero_mul, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [add_mul, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x₁ x₂ refine TensorProduct.induction_on y ?_ ?_ ?_ · rw [mul_zero, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [mul_add, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x y simp only [TensorProduct.tmul_mul_tmul, Derivation.tensorProductTo, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul', TensorProduct.lmul'_apply_tmul] dsimp rw [D.leibniz] simp only [smul_smul, smul_add, mul_comm (x * y) x₁, mul_right_comm x₁ x₂, ← mul_assoc] variable (R S) /-- The kernel of `S ⊗[R] S →ₐ[R] S` is generated by `1 ⊗ s - s ⊗ 1` as a `S`-module. -/ theorem KaehlerDifferential.submodule_span_range_eq_ideal : Submodule.span S (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = (KaehlerDifferential.ideal R S).restrictScalars S := by apply le_antisymm · rw [Submodule.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · rintro x (hx : _ = _) have : x - TensorProduct.lmul' (S := S) R x ⊗ₜ[R] (1 : S) = x := by rw [hx, TensorProduct.zero_tmul, sub_zero] rw [← this] clear this hx refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [map_zero, TensorProduct.zero_tmul, sub_zero]; exact zero_mem _ · intro x y have : x ⊗ₜ[R] y - (x * y) ⊗ₜ[R] (1 : S) = x • ((1 : S) ⊗ₜ y - y ⊗ₜ (1 : S)) := by simp_rw [smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] rw [TensorProduct.lmul'_apply_tmul, this] refine Submodule.smul_mem _ x ?_ apply Submodule.subset_span exact Set.mem_range_self y · intro x y hx hy rw [map_add, TensorProduct.add_tmul, ← sub_add_sub_comm] exact add_mem hx hy theorem KaehlerDifferential.span_range_eq_ideal : Ideal.span (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = KaehlerDifferential.ideal R S := by apply le_antisymm · rw [Ideal.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · change (KaehlerDifferential.ideal R S).restrictScalars S ≤ (Ideal.span _).restrictScalars S rw [← KaehlerDifferential.submodule_span_range_eq_ideal, Ideal.span] conv_rhs => rw [← Submodule.span_span_of_tower S] exact Submodule.subset_span /-- The module of Kähler differentials (Kahler differentials, Kaehler differentials). This is implemented as `I / I ^ 2` with `I` the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. To view elements as a linear combination of the form `s • D s'`, use `KaehlerDifferential.tensorProductTo_surjective` and `Derivation.tensorProductTo_tmul`. We also provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. -/ def KaehlerDifferential : Type v := (KaehlerDifferential.ideal R S).Cotangent instance : AddCommGroup (KaehlerDifferential R S) := inferInstanceAs <| AddCommGroup (KaehlerDifferential.ideal R S).Cotangent instance KaehlerDifferential.module : Module (S ⊗[R] S) (KaehlerDifferential R S) := Ideal.Cotangent.moduleOfTower _ @[inherit_doc KaehlerDifferential] notation:100 "Ω[" S "⁄" R "]" => KaehlerDifferential R S instance : Nonempty (Ω[S⁄R]) := ⟨0⟩ instance KaehlerDifferential.module' {R' : Type*} [CommRing R'] [Algebra R' S] [SMulCommClass R R' S] : Module R' (Ω[S⁄R]) := Submodule.Quotient.module' _ instance : IsScalarTower S (S ⊗[R] S) (Ω[S⁄R]) := Ideal.Cotangent.isScalarTower _ instance KaehlerDifferential.isScalarTower_of_tower {R₁ R₂ : Type*} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [SMul R₁ R₂] [SMulCommClass R R₁ S] [SMulCommClass R R₂ S] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ instance KaehlerDifferential.isScalarTower' : IsScalarTower R (S ⊗[R] S) (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ /-- The quotient map `I → Ω[S⁄R]` with `I` being the kernel of `S ⊗[R] S → S`. -/ def KaehlerDifferential.fromIdeal : KaehlerDifferential.ideal R S →ₗ[S ⊗[R] S] Ω[S⁄R] := (KaehlerDifferential.ideal R S).toCotangent /-- (Implementation) The underlying linear map of the derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.DLinearMap : S →ₗ[R] Ω[S⁄R] := ((KaehlerDifferential.fromIdeal R S).restrictScalars R).comp ((TensorProduct.includeRight.toLinearMap - TensorProduct.includeLeft.toLinearMap : S →ₗ[R] S ⊗[R] S).codRestrict ((KaehlerDifferential.ideal R S).restrictScalars R) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R) : _ →ₗ[R] _) theorem KaehlerDifferential.DLinearMap_apply (s : S) : KaehlerDifferential.DLinearMap R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl /-- The universal derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.D : Derivation R S (Ω[S⁄R]) := { toLinearMap := KaehlerDifferential.DLinearMap R S map_one_eq_zero' := by dsimp [KaehlerDifferential.DLinearMap_apply, Ideal.toCotangent_apply] congr rw [sub_self] leibniz' := fun a b => by have : LinearMap.CompatibleSMul { x // x ∈ ideal R S } (Ω[S⁄R]) S (S ⊗[R] S) := inferInstance dsimp [KaehlerDifferential.DLinearMap_apply] rw [← LinearMap.map_smul_of_tower (ideal R S).toCotangent, ← LinearMap.map_smul_of_tower (ideal R S).toCotangent, ← map_add (ideal R S).toCotangent, Ideal.toCotangent_eq, pow_two] convert Submodule.mul_mem_mul (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R a :) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R b :) using 1 simp only [AddSubgroupClass.coe_sub, Submodule.coe_add, Submodule.coe_mk, TensorProduct.tmul_mul_tmul, mul_sub, sub_mul, mul_comm b, Submodule.coe_smul_of_tower, smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] ring_nf } theorem KaehlerDifferential.D_apply (s : S) : KaehlerDifferential.D R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl theorem KaehlerDifferential.span_range_derivation : Submodule.span S (Set.range <| KaehlerDifferential.D R S) = ⊤ := by rw [_root_.eq_top_iff] rintro x - obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x have : x ∈ (KaehlerDifferential.ideal R S).restrictScalars S := hx rw [← KaehlerDifferential.submodule_span_range_eq_ideal] at this suffices ∃ hx, (KaehlerDifferential.ideal R S).toCotangent ⟨x, hx⟩ ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) by exact this.choose_spec refine Submodule.span_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨x, rfl⟩ refine ⟨KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x, ?_⟩ apply Submodule.subset_span exact ⟨x, KaehlerDifferential.DLinearMap_apply R S x⟩ · exact ⟨zero_mem _, Submodule.zero_mem _⟩ · rintro x y - - ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩; exact ⟨add_mem hx₁ hy₁, Submodule.add_mem _ hx₂ hy₂⟩ · rintro r x - ⟨hx₁, hx₂⟩ exact ⟨((KaehlerDifferential.ideal R S).restrictScalars S).smul_mem r hx₁, Submodule.smul_mem _ r hx₂⟩ /-- `Ω[S⁄R]` is trivial if `R → S` is surjective. Also see `Algebra.FormallyUnramified.iff_subsingleton_kaehlerDifferential`. -/ lemma KaehlerDifferential.subsingleton_of_surjective (h : Function.Surjective (algebraMap R S)) : Subsingleton (Ω[S⁄R]) := by suffices (⊤ : Submodule S (Ω[S⁄R])) ≤ ⊥ from (subsingleton_iff_forall_eq 0).mpr fun y ↦ this trivial rw [← KaehlerDifferential.span_range_derivation, Submodule.span_le] rintro _ ⟨x, rfl⟩; obtain ⟨x, rfl⟩ := h x; simp variable {R S} /-- The linear map from `Ω[S⁄R]`, associated with a derivation. -/ def Derivation.liftKaehlerDifferential (D : Derivation R S M) : Ω[S⁄R] →ₗ[S] M := by refine LinearMap.comp ((((KaehlerDifferential.ideal R S) • (⊤ : Submodule (S ⊗[R] S) (KaehlerDifferential.ideal R S))).restrictScalars S).liftQ ?_ ?_) (Submodule.Quotient.restrictScalarsEquiv S _).symm.toLinearMap · exact D.tensorProductTo.comp ((KaehlerDifferential.ideal R S).subtype.restrictScalars S) · intro x hx rw [LinearMap.mem_ker] refine Submodule.smul_induction_on ((Submodule.restrictScalars_mem _ _ _).mp hx) ?_ ?_ · rintro x hx y - rw [RingHom.mem_ker] at hx dsimp rw [Derivation.tensorProductTo_mul, hx, y.prop, zero_smul, zero_smul, zero_add] · intro x y ex ey; rw [map_add, ex, ey, zero_add] theorem Derivation.liftKaehlerDifferential_apply (D : Derivation R S M) (x) : D.liftKaehlerDifferential ((KaehlerDifferential.ideal R S).toCotangent x) = D.tensorProductTo x := rfl theorem Derivation.liftKaehlerDifferential_comp (D : Derivation R S M) : D.liftKaehlerDifferential.compDer (KaehlerDifferential.D R S) = D := by ext a dsimp [KaehlerDifferential.D_apply] refine (D.liftKaehlerDifferential_apply _).trans ?_ rw [Subtype.coe_mk, map_sub, Derivation.tensorProductTo_tmul, Derivation.tensorProductTo_tmul, one_smul, D.map_one_eq_zero, smul_zero, sub_zero] @[simp] theorem Derivation.liftKaehlerDifferential_comp_D (D' : Derivation R S M) (x : S) : D'.liftKaehlerDifferential (KaehlerDifferential.D R S x) = D' x := Derivation.congr_fun D'.liftKaehlerDifferential_comp x @[ext] theorem Derivation.liftKaehlerDifferential_unique (f f' : Ω[S⁄R] →ₗ[S] M) (hf : f.compDer (KaehlerDifferential.D R S) = f'.compDer (KaehlerDifferential.D R S)) : f = f' := by apply LinearMap.ext intro x have : x ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) := by rw [KaehlerDifferential.span_range_derivation]; trivial refine Submodule.span_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨x, rfl⟩; exact congr_arg (fun D : Derivation R S M => D x) hf · rw [map_zero, map_zero] · intro x y _ _ hx hy; rw [map_add, map_add, hx, hy] · intro a x _ e; simp [e] variable (R S) theorem Derivation.liftKaehlerDifferential_D : (KaehlerDifferential.D R S).liftKaehlerDifferential = LinearMap.id := Derivation.liftKaehlerDifferential_unique _ _ (KaehlerDifferential.D R S).liftKaehlerDifferential_comp variable {R S} theorem KaehlerDifferential.D_tensorProductTo (x : KaehlerDifferential.ideal R S) : (KaehlerDifferential.D R S).tensorProductTo x = (KaehlerDifferential.ideal R S).toCotangent x := by rw [← Derivation.liftKaehlerDifferential_apply, Derivation.liftKaehlerDifferential_D] rfl variable (R S) theorem KaehlerDifferential.tensorProductTo_surjective : Function.Surjective (KaehlerDifferential.D R S).tensorProductTo := by intro x; obtain ⟨x, rfl⟩ := (KaehlerDifferential.ideal R S).toCotangent_surjective x exact ⟨x, KaehlerDifferential.D_tensorProductTo x⟩ /-- The `S`-linear maps from `Ω[S⁄R]` to `M` are (`S`-linearly) equivalent to `R`-derivations from `S` to `M`. -/ @[simps! symm_apply apply_apply] def KaehlerDifferential.linearMapEquivDerivation : (Ω[S⁄R] →ₗ[S] M) ≃ₗ[S] Derivation R S M := { Derivation.llcomp.flip <| KaehlerDifferential.D R S with invFun := Derivation.liftKaehlerDifferential left_inv := fun _ => Derivation.liftKaehlerDifferential_unique _ _ (Derivation.liftKaehlerDifferential_comp _) right_inv := Derivation.liftKaehlerDifferential_comp } /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S`. -/ def KaehlerDifferential.quotientCotangentIdealRingEquiv : (S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal ≃+* S := by have : Function.RightInverse (TensorProduct.includeLeft (R := R) (S := R) (A := S) (B := S)) (↑(TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) : S ⊗[R] S →+* S) := by intro x; rw [AlgHom.coe_toRingHom, ← AlgHom.comp_apply, TensorProduct.lmul'_comp_includeLeft] rfl refine (Ideal.quotCotangent _).trans ?_ refine (Ideal.quotEquivOfEq ?_).trans (RingHom.quotientKerEquivOfRightInverse this) ext; rfl /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S` as an `S`-algebra. -/ def KaehlerDifferential.quotientCotangentIdeal : ((S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal) ≃ₐ[S] S := { KaehlerDifferential.quotientCotangentIdealRingEquiv R S with commutes' := (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).apply_symm_apply }
Mathlib/RingTheory/Kaehler/Basic.lean
351
354
theorem KaehlerDifferential.End_equiv_aux (f : S →ₐ[R] S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) : (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ ↔ (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S := by
/- Copyright (c) 2022 Praneeth Kolichala. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Praneeth Kolichala -/ import Mathlib.Topology.Homotopy.Path import Mathlib.Topology.Homotopy.Equiv /-! # Contractible spaces In this file, we define `ContractibleSpace`, a space that is homotopy equivalent to `Unit`. -/ noncomputable section namespace ContinuousMap variable {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] /-- A map is nullhomotopic if it is homotopic to a constant map. -/ def Nullhomotopic (f : C(X, Y)) : Prop := ∃ y : Y, Homotopic f (ContinuousMap.const _ y) theorem nullhomotopic_of_constant (y : Y) : Nullhomotopic (ContinuousMap.const X y) := ⟨y, by rfl⟩
Mathlib/Topology/Homotopy/Contractible.lean
28
29
theorem Nullhomotopic.comp_right {f : C(X, Y)} (hf : f.Nullhomotopic) (g : C(Y, Z)) : (g.comp f).Nullhomotopic := by
/- 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
Mathlib/Data/Set/Card.lean
164
167
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
/- Copyright (c) 2018 Sean Leather. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sean Leather, Mario Carneiro -/ import Mathlib.Data.List.AList import Mathlib.Data.Finset.Sigma import Mathlib.Data.Part /-! # Finite maps over `Multiset` -/ universe u v w open List variable {α : Type u} {β : α → Type v} /-! ### Multisets of sigma types -/ namespace Multiset /-- Multiset of keys of an association multiset. -/ def keys (s : Multiset (Sigma β)) : Multiset α := s.map Sigma.fst @[simp] theorem coe_keys {l : List (Sigma β)} : keys (l : Multiset (Sigma β)) = (l.keys : Multiset α) := rfl @[simp] theorem keys_zero : keys (0 : Multiset (Sigma β)) = 0 := rfl @[simp] theorem keys_cons {a : α} {b : β a} {s : Multiset (Sigma β)} : keys (⟨a, b⟩ ::ₘ s) = a ::ₘ keys s := by simp [keys] @[simp] theorem keys_singleton {a : α} {b : β a} : keys ({⟨a, b⟩} : Multiset (Sigma β)) = {a} := rfl /-- `NodupKeys s` means that `s` has no duplicate keys. -/ def NodupKeys (s : Multiset (Sigma β)) : Prop := Quot.liftOn s List.NodupKeys fun _ _ p => propext <| perm_nodupKeys p @[simp] theorem coe_nodupKeys {l : List (Sigma β)} : @NodupKeys α β l ↔ l.NodupKeys := Iff.rfl lemma nodup_keys {m : Multiset (Σ a, β a)} : m.keys.Nodup ↔ m.NodupKeys := by rcases m with ⟨l⟩; rfl alias ⟨_, NodupKeys.nodup_keys⟩ := nodup_keys protected lemma NodupKeys.nodup {m : Multiset (Σ a, β a)} (h : m.NodupKeys) : m.Nodup := h.nodup_keys.of_map _ end Multiset /-! ### Finmap -/ /-- `Finmap β` is the type of finite maps over a multiset. It is effectively a quotient of `AList β` by permutation of the underlying list. -/ structure Finmap (β : α → Type v) : Type max u v where /-- The underlying `Multiset` of a `Finmap` -/ entries : Multiset (Sigma β) /-- There are no duplicate keys in `entries` -/ nodupKeys : entries.NodupKeys /-- The quotient map from `AList` to `Finmap`. -/ def AList.toFinmap (s : AList β) : Finmap β := ⟨s.entries, s.nodupKeys⟩ local notation:arg "⟦" a "⟧" => AList.toFinmap a theorem AList.toFinmap_eq {s₁ s₂ : AList β} : toFinmap s₁ = toFinmap s₂ ↔ s₁.entries ~ s₂.entries := by cases s₁ cases s₂ simp [AList.toFinmap] @[simp] theorem AList.toFinmap_entries (s : AList β) : ⟦s⟧.entries = s.entries := rfl /-- Given `l : List (Sigma β)`, create a term of type `Finmap β` by removing entries with duplicate keys. -/ def List.toFinmap [DecidableEq α] (s : List (Sigma β)) : Finmap β := s.toAList.toFinmap namespace Finmap open AList lemma nodup_entries (f : Finmap β) : f.entries.Nodup := f.nodupKeys.nodup /-! ### Lifting from AList -/ /-- Lift a permutation-respecting function on `AList` to `Finmap`. -/ def liftOn {γ} (s : Finmap β) (f : AList β → γ) (H : ∀ a b : AList β, a.entries ~ b.entries → f a = f b) : γ := by refine (Quotient.liftOn s.entries (fun (l : List (Sigma β)) => (⟨_, fun nd => f ⟨l, nd⟩⟩ : Part γ)) (fun l₁ l₂ p => Part.ext' (perm_nodupKeys p) ?_) : Part γ).get ?_ · exact fun h1 h2 => H _ _ p · have := s.nodupKeys revert this rcases s.entries with ⟨l⟩ exact id @[simp] theorem liftOn_toFinmap {γ} (s : AList β) (f : AList β → γ) (H) : liftOn ⟦s⟧ f H = f s := by cases s rfl /-- Lift a permutation-respecting function on 2 `AList`s to 2 `Finmap`s. -/ def liftOn₂ {γ} (s₁ s₂ : Finmap β) (f : AList β → AList β → γ) (H : ∀ a₁ b₁ a₂ b₂ : AList β, a₁.entries ~ a₂.entries → b₁.entries ~ b₂.entries → f a₁ b₁ = f a₂ b₂) : γ := liftOn s₁ (fun l₁ => liftOn s₂ (f l₁) fun _ _ p => H _ _ _ _ (Perm.refl _) p) fun a₁ a₂ p => by have H' : f a₁ = f a₂ := funext fun _ => H _ _ _ _ p (Perm.refl _) simp only [H'] @[simp] theorem liftOn₂_toFinmap {γ} (s₁ s₂ : AList β) (f : AList β → AList β → γ) (H) : liftOn₂ ⟦s₁⟧ ⟦s₂⟧ f H = f s₁ s₂ := by cases s₁; cases s₂; rfl /-! ### Induction -/ @[elab_as_elim] theorem induction_on {C : Finmap β → Prop} (s : Finmap β) (H : ∀ a : AList β, C ⟦a⟧) : C s := by rcases s with ⟨⟨a⟩, h⟩; exact H ⟨a, h⟩ @[elab_as_elim] theorem induction_on₂ {C : Finmap β → Finmap β → Prop} (s₁ s₂ : Finmap β) (H : ∀ a₁ a₂ : AList β, C ⟦a₁⟧ ⟦a₂⟧) : C s₁ s₂ := induction_on s₁ fun l₁ => induction_on s₂ fun l₂ => H l₁ l₂ @[elab_as_elim] theorem induction_on₃ {C : Finmap β → Finmap β → Finmap β → Prop} (s₁ s₂ s₃ : Finmap β) (H : ∀ a₁ a₂ a₃ : AList β, C ⟦a₁⟧ ⟦a₂⟧ ⟦a₃⟧) : C s₁ s₂ s₃ := induction_on₂ s₁ s₂ fun l₁ l₂ => induction_on s₃ fun l₃ => H l₁ l₂ l₃ /-! ### extensionality -/ @[ext] theorem ext : ∀ {s t : Finmap β}, s.entries = t.entries → s = t | ⟨l₁, h₁⟩, ⟨l₂, _⟩, H => by congr @[simp] theorem ext_iff' {s t : Finmap β} : s.entries = t.entries ↔ s = t := Finmap.ext_iff.symm /-! ### mem -/ /-- The predicate `a ∈ s` means that `s` has a value associated to the key `a`. -/ instance : Membership α (Finmap β) := ⟨fun s a => a ∈ s.entries.keys⟩ theorem mem_def {a : α} {s : Finmap β} : a ∈ s ↔ a ∈ s.entries.keys := Iff.rfl @[simp] theorem mem_toFinmap {a : α} {s : AList β} : a ∈ toFinmap s ↔ a ∈ s := Iff.rfl /-! ### keys -/ /-- The set of keys of a finite map. -/ def keys (s : Finmap β) : Finset α := ⟨s.entries.keys, s.nodupKeys.nodup_keys⟩ @[simp] theorem keys_val (s : AList β) : (keys ⟦s⟧).val = s.keys := rfl @[simp] theorem keys_ext {s₁ s₂ : AList β} : keys ⟦s₁⟧ = keys ⟦s₂⟧ ↔ s₁.keys ~ s₂.keys := by simp [keys, AList.keys] theorem mem_keys {a : α} {s : Finmap β} : a ∈ s.keys ↔ a ∈ s := induction_on s fun _ => AList.mem_keys /-! ### empty -/ /-- The empty map. -/ instance : EmptyCollection (Finmap β) := ⟨⟨0, nodupKeys_nil⟩⟩ instance : Inhabited (Finmap β) := ⟨∅⟩ @[simp] theorem empty_toFinmap : (⟦∅⟧ : Finmap β) = ∅ := rfl @[simp] theorem toFinmap_nil [DecidableEq α] : ([].toFinmap : Finmap β) = ∅ := rfl theorem not_mem_empty {a : α} : a ∉ (∅ : Finmap β) := Multiset.not_mem_zero a @[simp] theorem keys_empty : (∅ : Finmap β).keys = ∅ := rfl /-! ### singleton -/ /-- The singleton map. -/ def singleton (a : α) (b : β a) : Finmap β := ⟦AList.singleton a b⟧ @[simp] theorem keys_singleton (a : α) (b : β a) : (singleton a b).keys = {a} := rfl @[simp] theorem mem_singleton (x y : α) (b : β y) : x ∈ singleton y b ↔ x = y := by simp [singleton, mem_def] section variable [DecidableEq α] instance decidableEq [∀ a, DecidableEq (β a)] : DecidableEq (Finmap β) | _, _ => decidable_of_iff _ Finmap.ext_iff.symm /-! ### lookup -/ /-- Look up the value associated to a key in a map. -/ def lookup (a : α) (s : Finmap β) : Option (β a) := liftOn s (AList.lookup a) fun _ _ => perm_lookup @[simp] theorem lookup_toFinmap (a : α) (s : AList β) : lookup a ⟦s⟧ = s.lookup a := rfl @[simp] theorem dlookup_list_toFinmap (a : α) (s : List (Sigma β)) : lookup a s.toFinmap = s.dlookup a := by rw [List.toFinmap, lookup_toFinmap, lookup_to_alist] @[simp] theorem lookup_empty (a) : lookup a (∅ : Finmap β) = none := rfl theorem lookup_isSome {a : α} {s : Finmap β} : (s.lookup a).isSome ↔ a ∈ s := induction_on s fun _ => AList.lookup_isSome theorem lookup_eq_none {a} {s : Finmap β} : lookup a s = none ↔ a ∉ s := induction_on s fun _ => AList.lookup_eq_none lemma mem_lookup_iff {s : Finmap β} {a : α} {b : β a} : b ∈ s.lookup a ↔ Sigma.mk a b ∈ s.entries := by rcases s with ⟨⟨l⟩, hl⟩; exact List.mem_dlookup_iff hl lemma lookup_eq_some_iff {s : Finmap β} {a : α} {b : β a} : s.lookup a = b ↔ Sigma.mk a b ∈ s.entries := mem_lookup_iff @[simp] lemma sigma_keys_lookup (s : Finmap β) : s.keys.sigma (fun i => (s.lookup i).toFinset) = ⟨s.entries, s.nodup_entries⟩ := by ext x have : x ∈ s.entries → x.1 ∈ s.keys := Multiset.mem_map_of_mem _ simpa [lookup_eq_some_iff] @[simp] theorem lookup_singleton_eq {a : α} {b : β a} : (singleton a b).lookup a = some b := by rw [singleton, lookup_toFinmap, AList.singleton, AList.lookup, dlookup_cons_eq] instance (a : α) (s : Finmap β) : Decidable (a ∈ s) := decidable_of_iff _ lookup_isSome theorem mem_iff {a : α} {s : Finmap β} : a ∈ s ↔ ∃ b, s.lookup a = some b := induction_on s fun s => Iff.trans List.mem_keys <| exists_congr fun _ => (mem_dlookup_iff s.nodupKeys).symm theorem mem_of_lookup_eq_some {a : α} {b : β a} {s : Finmap β} (h : s.lookup a = some b) : a ∈ s := mem_iff.mpr ⟨_, h⟩ theorem ext_lookup {s₁ s₂ : Finmap β} : (∀ x, s₁.lookup x = s₂.lookup x) → s₁ = s₂ := induction_on₂ s₁ s₂ fun s₁ s₂ h => by simp only [AList.lookup, lookup_toFinmap] at h rw [AList.toFinmap_eq] apply lookup_ext s₁.nodupKeys s₂.nodupKeys intro x y rw [h] /-- An equivalence between `Finmap β` and pairs `(keys : Finset α, lookup : ∀ a, Option (β a))` such that `(lookup a).isSome ↔ a ∈ keys`. -/ @[simps apply_coe_fst apply_coe_snd] def keysLookupEquiv : Finmap β ≃ { f : Finset α × (∀ a, Option (β a)) // ∀ i, (f.2 i).isSome ↔ i ∈ f.1 } where toFun s := ⟨(s.keys, fun i => s.lookup i), fun _ => lookup_isSome⟩ invFun f := mk (f.1.1.sigma fun i => (f.1.2 i).toFinset).val <| by refine Multiset.nodup_keys.1 ((Finset.nodup _).map_on ?_) simp only [Finset.mem_val, Finset.mem_sigma, Option.mem_toFinset, Option.mem_def] rintro ⟨i, x⟩ ⟨_, hx⟩ ⟨j, y⟩ ⟨_, hy⟩ (rfl : i = j) simpa using hx.symm.trans hy left_inv f := ext <| by simp right_inv := fun ⟨(s, f), hf⟩ => by dsimp only at hf ext · simp [keys, Multiset.keys, ← hf, Option.isSome_iff_exists] · simp +contextual [lookup_eq_some_iff, ← hf] @[simp] lemma keysLookupEquiv_symm_apply_keys : ∀ f : {f : Finset α × (∀ a, Option (β a)) // ∀ i, (f.2 i).isSome ↔ i ∈ f.1}, (keysLookupEquiv.symm f).keys = f.1.1 := keysLookupEquiv.surjective.forall.2 fun _ => by simp only [Equiv.symm_apply_apply, keysLookupEquiv_apply_coe_fst] @[simp] lemma keysLookupEquiv_symm_apply_lookup : ∀ (f : {f : Finset α × (∀ a, Option (β a)) // ∀ i, (f.2 i).isSome ↔ i ∈ f.1}) a, (keysLookupEquiv.symm f).lookup a = f.1.2 a := keysLookupEquiv.surjective.forall.2 fun _ _ => by simp only [Equiv.symm_apply_apply, keysLookupEquiv_apply_coe_snd] /-! ### replace -/ /-- Replace a key with a given value in a finite map. If the key is not present it does nothing. -/ def replace (a : α) (b : β a) (s : Finmap β) : Finmap β := (liftOn s fun t => AList.toFinmap (AList.replace a b t)) fun _ _ p => toFinmap_eq.2 <| perm_replace p @[simp] theorem replace_toFinmap (a : α) (b : β a) (s : AList β) : replace a b ⟦s⟧ = (⟦s.replace a b⟧ : Finmap β) := by simp [replace] @[simp] theorem keys_replace (a : α) (b : β a) (s : Finmap β) : (replace a b s).keys = s.keys := induction_on s fun s => by simp @[simp] theorem mem_replace {a a' : α} {b : β a} {s : Finmap β} : a' ∈ replace a b s ↔ a' ∈ s := induction_on s fun s => by simp end /-! ### foldl -/ /-- Fold a commutative function over the key-value pairs in the map -/ def foldl {δ : Type w} (f : δ → ∀ a, β a → δ) (H : ∀ d a₁ b₁ a₂ b₂, f (f d a₁ b₁) a₂ b₂ = f (f d a₂ b₂) a₁ b₁) (d : δ) (m : Finmap β) : δ := letI : RightCommutative fun d (s : Sigma β) ↦ f d s.1 s.2 := ⟨fun _ _ _ ↦ H _ _ _ _ _⟩ m.entries.foldl (fun d s => f d s.1 s.2) d /-- `any f s` returns `true` iff there exists a value `v` in `s` such that `f v = true`. -/ def any (f : ∀ x, β x → Bool) (s : Finmap β) : Bool := s.foldl (fun x y z => x || f y z) (fun _ _ _ _ => by simp_rw [Bool.or_assoc, Bool.or_comm, imp_true_iff]) false /-- `all f s` returns `true` iff `f v = true` for all values `v` in `s`. -/ def all (f : ∀ x, β x → Bool) (s : Finmap β) : Bool := s.foldl (fun x y z => x && f y z) (fun _ _ _ _ => by simp_rw [Bool.and_assoc, Bool.and_comm, imp_true_iff]) true /-! ### erase -/ section variable [DecidableEq α] /-- Erase a key from the map. If the key is not present it does nothing. -/ def erase (a : α) (s : Finmap β) : Finmap β := (liftOn s fun t => AList.toFinmap (AList.erase a t)) fun _ _ p => toFinmap_eq.2 <| perm_erase p @[simp] theorem erase_toFinmap (a : α) (s : AList β) : erase a ⟦s⟧ = AList.toFinmap (s.erase a) := by simp [erase] @[simp] theorem keys_erase_toFinset (a : α) (s : AList β) : keys ⟦s.erase a⟧ = (keys ⟦s⟧).erase a := by simp [Finset.erase, keys, AList.erase, keys_kerase] @[simp] theorem keys_erase (a : α) (s : Finmap β) : (erase a s).keys = s.keys.erase a := induction_on s fun s => by simp @[simp] theorem mem_erase {a a' : α} {s : Finmap β} : a' ∈ erase a s ↔ a' ≠ a ∧ a' ∈ s := induction_on s fun s => by simp theorem not_mem_erase_self {a : α} {s : Finmap β} : ¬a ∈ erase a s := by rw [mem_erase, not_and_or, not_not] left rfl @[simp] theorem lookup_erase (a) (s : Finmap β) : lookup a (erase a s) = none := induction_on s <| AList.lookup_erase a @[simp] theorem lookup_erase_ne {a a'} {s : Finmap β} (h : a ≠ a') : lookup a (erase a' s) = lookup a s := induction_on s fun _ => AList.lookup_erase_ne h theorem erase_erase {a a' : α} {s : Finmap β} : erase a (erase a' s) = erase a' (erase a s) := induction_on s fun s => ext (by simp only [AList.erase_erase, erase_toFinmap]) /-! ### sdiff -/ /-- `sdiff s s'` consists of all key-value pairs from `s` and `s'` where the keys are in `s` or `s'` but not both. -/ def sdiff (s s' : Finmap β) : Finmap β := s'.foldl (fun s x _ => s.erase x) (fun _ _ _ _ _ => erase_erase) s instance : SDiff (Finmap β) := ⟨sdiff⟩ /-! ### insert -/ /-- Insert a key-value pair into a finite map, replacing any existing pair with the same key. -/ def insert (a : α) (b : β a) (s : Finmap β) : Finmap β := (liftOn s fun t => AList.toFinmap (AList.insert a b t)) fun _ _ p => toFinmap_eq.2 <| perm_insert p @[simp] theorem insert_toFinmap (a : α) (b : β a) (s : AList β) : insert a b (AList.toFinmap s) = AList.toFinmap (s.insert a b) := by simp [insert] theorem entries_insert_of_not_mem {a : α} {b : β a} {s : Finmap β} : a ∉ s → (insert a b s).entries = ⟨a, b⟩ ::ₘ s.entries := induction_on s fun s h => by simp [AList.entries_insert_of_not_mem (mt mem_toFinmap.1 h), -entries_insert] @[deprecated (since := "2024-12-14")] alias insert_entries_of_neg := entries_insert_of_not_mem @[simp] theorem mem_insert {a a' : α} {b' : β a'} {s : Finmap β} : a ∈ insert a' b' s ↔ a = a' ∨ a ∈ s := induction_on s AList.mem_insert @[simp] theorem lookup_insert {a} {b : β a} (s : Finmap β) : lookup a (insert a b s) = some b := induction_on s fun s => by simp only [insert_toFinmap, lookup_toFinmap, AList.lookup_insert] @[simp] theorem lookup_insert_of_ne {a a'} {b : β a} (s : Finmap β) (h : a' ≠ a) : lookup a' (insert a b s) = lookup a' s := induction_on s fun s => by simp only [insert_toFinmap, lookup_toFinmap, lookup_insert_ne h] @[simp] theorem insert_insert {a} {b b' : β a} (s : Finmap β) : (s.insert a b).insert a b' = s.insert a b' := induction_on s fun s => by simp only [insert_toFinmap, AList.insert_insert] theorem insert_insert_of_ne {a a'} {b : β a} {b' : β a'} (s : Finmap β) (h : a ≠ a') : (s.insert a b).insert a' b' = (s.insert a' b').insert a b := induction_on s fun s => by simp only [insert_toFinmap, AList.toFinmap_eq, AList.insert_insert_of_ne _ h] theorem toFinmap_cons (a : α) (b : β a) (xs : List (Sigma β)) : List.toFinmap (⟨a, b⟩ :: xs) = insert a b xs.toFinmap := rfl theorem mem_list_toFinmap (a : α) (xs : List (Sigma β)) : a ∈ xs.toFinmap ↔ ∃ b : β a, Sigma.mk a b ∈ xs := by induction' xs with x xs · simp only [toFinmap_nil, not_mem_empty, find?, not_mem_nil, exists_false] obtain ⟨fst_i, snd_i⟩ := x simp only [toFinmap_cons, *, exists_or, mem_cons, mem_insert, exists_and_left, Sigma.mk.inj_iff] refine (or_congr_left <| and_iff_left_of_imp ?_).symm rintro rfl simp only [exists_eq, heq_iff_eq] @[simp] theorem insert_singleton_eq {a : α} {b b' : β a} : insert a b (singleton a b') = singleton a b := by simp only [singleton, Finmap.insert_toFinmap, AList.insert_singleton_eq] /-! ### extract -/ /-- Erase a key from the map, and return the corresponding value, if found. -/ def extract (a : α) (s : Finmap β) : Option (β a) × Finmap β := (liftOn s fun t => Prod.map id AList.toFinmap (AList.extract a t)) fun s₁ s₂ p => by simp [perm_lookup p, toFinmap_eq, perm_erase p] @[simp] theorem extract_eq_lookup_erase (a : α) (s : Finmap β) : extract a s = (lookup a s, erase a s) := induction_on s fun s => by simp [extract] /-! ### union -/ /-- `s₁ ∪ s₂` is the key-based union of two finite maps. It is left-biased: if there exists an `a ∈ s₁`, `lookup a (s₁ ∪ s₂) = lookup a s₁`. -/ def union (s₁ s₂ : Finmap β) : Finmap β := (liftOn₂ s₁ s₂ fun s₁ s₂ => (AList.toFinmap (s₁ ∪ s₂))) fun _ _ _ _ p₁₃ p₂₄ => toFinmap_eq.mpr <| perm_union p₁₃ p₂₄ instance : Union (Finmap β) := ⟨union⟩ @[simp] theorem mem_union {a} {s₁ s₂ : Finmap β} : a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ := induction_on₂ s₁ s₂ fun _ _ => AList.mem_union @[simp]
Mathlib/Data/Finmap.lean
502
504
theorem union_toFinmap (s₁ s₂ : AList β) : (toFinmap s₁) ∪ (toFinmap s₂) = toFinmap (s₁ ∪ s₂) := by
simp [(· ∪ ·), union]
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ universe v v₁ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun | left => right | right => left invFun | left => right | right => left left_inv j := by cases j <;> rfl right_inv j := by cases j <;> rfl @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun | left => true | right => false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j <;> rfl right_inv b := by cases b <;> rfl @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app | ⟨left⟩ => f | ⟨right⟩ => g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j ↦ match j with | ⟨left⟩ => f | ⟨right⟩ => g) (fun ⟨⟨u⟩⟩ => by aesop_cat) end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) section variable {D : Type u₁} [Category.{v₁} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ @[simp] theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl @[simp] theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl /-- Constructs an isomorphism of `BinaryFan`s out of an isomorphism of the tips that commutes with the projections. -/ def BinaryFan.ext {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt) (h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : c ≅ c' := Cones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption) @[simp] lemma BinaryFan.ext_hom_hom {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt) (h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : (ext e h₁ h₂).hom.hom = e.hom := rfl /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ /-- Constructs an isomorphism of `BinaryCofan`s out of an isomorphism of the tips that commutes with the injections. -/ def BinaryCofan.ext {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt) (h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : c ≅ c' := Cocones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption) @[simp] lemma BinaryCofan.ext_hom_hom {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt) (h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : (ext e h₁ h₂).hom.hom = e.hom := rfl @[simp] theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl @[simp] theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ variable {X Y : C} section attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ } /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ } end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · intro s -- Porting note: simp timed out here simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id, BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc] · intro s -- Porting note: simp timed out here simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac] · intro s m e₁ e₂ -- Porting note: simpa timed out here also apply BinaryFan.IsLimit.hom_ext h · simpa only [BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv] · simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac] /-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/ noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y') [IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) := BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h) /-- Binary coproducts are symmetric. -/ def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) : IsColimit (BinaryCofan.mk c.inr c.inl) := BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryCofan.IsColimit.hom_ext hc (e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm) theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inl := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X) refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩ rw [Category.comp_id] have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl rwa [Category.assoc,Category.id_comp] at e · intro exact ⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f) (fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => (IsIso.eq_inv_comp _).mpr e⟩ theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) : Nonempty (IsColimit c) ↔ IsIso c.inr := by refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl)) exact ⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h => ⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/ noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by fapply BinaryCofan.isColimitMk · exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr) · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] · intro s -- Porting note: simp timed out here too simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] · intro s m e₁ e₂ apply BinaryCofan.IsColimit.hom_ext h · rw [← cancel_epi f] -- Porting note: simp timed out here too simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true, Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁ -- Porting note: simp timed out here too · simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr] /-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/ noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y) [IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) := BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h) /-- An abbreviation for `HasLimit (pair X Y)`. -/ abbrev HasBinaryProduct (X Y : C) := HasLimit (pair X Y) /-- An abbreviation for `HasColimit (pair X Y)`. -/ abbrev HasBinaryCoproduct (X Y : C) := HasColimit (pair X Y) /-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or `X ⨯ Y`. -/ noncomputable abbrev prod (X Y : C) [HasBinaryProduct X Y] := limit (pair X Y) /-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or `X ⨿ Y`. -/ noncomputable abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] := colimit (pair X Y) /-- Notation for the product -/ notation:20 X " ⨯ " Y:20 => prod X Y /-- Notation for the coproduct -/ notation:20 X " ⨿ " Y:20 => coprod X Y /-- The projection map to the first component of the product. -/ noncomputable abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X := limit.π (pair X Y) ⟨WalkingPair.left⟩ /-- The projection map to the second component of the product. -/ noncomputable abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y := limit.π (pair X Y) ⟨WalkingPair.right⟩ /-- The inclusion map from the first component of the coproduct. -/ noncomputable abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.left⟩ /-- The inclusion map from the second component of the coproduct. -/ noncomputable abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y := colimit.ι (pair X Y) ⟨WalkingPair.right⟩ /-- The binary fan constructed from the projection maps is a limit. -/ noncomputable def prodIsProd (X Y : C) [HasBinaryProduct X Y] : IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) := (limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.id_comp]; rfl · dsimp; simp only [Category.id_comp]; rfl )) /-- The binary cofan constructed from the coprojection maps is a colimit. -/ noncomputable def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] : IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) := (colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by cases u · dsimp; simp only [Category.comp_id] · dsimp; simp only [Category.comp_id] )) @[ext 1100] theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y} (h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g := BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂ @[ext 1100] theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W} (h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g := BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂ /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/ noncomputable abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y := limit.lift _ (BinaryFan.mk f g) /-- diagonal arrow of the binary product in the category `fam I` -/ noncomputable abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X := prod.lift (𝟙 _) (𝟙 _) /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/ noncomputable abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W := colimit.desc _ (BinaryCofan.mk f g) /-- codiagonal arrow of the binary coproduct -/ noncomputable abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X := coprod.desc (𝟙 _) (𝟙 _) @[reassoc] theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.fst = f := limit.lift_π _ _ @[reassoc] theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : prod.lift f g ≫ prod.snd = g := limit.lift_π _ _ @[reassoc] theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inl ≫ coprod.desc f g = f := colimit.ι_desc _ _ @[reassoc] theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : coprod.inr ≫ coprod.desc f g = g := colimit.ι_desc _ _ instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono f] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_fst _ _ instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) [Mono g] : Mono (prod.lift f g) := mono_of_mono_fac <| prod.lift_snd _ _ instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi f] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inl_desc _ _ instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) [Epi g] : Epi (coprod.desc f g) := epi_of_epi_fac <| coprod.inr_desc _ _ /-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/ noncomputable def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } := ⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩ /-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and `coprod.inr ≫ l = g`. -/ noncomputable def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : { l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } := ⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩ /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/ noncomputable def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z := limMap (mapPair f g) /-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and `g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/ noncomputable def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z := colimMap (mapPair f g) noncomputable section ProdLemmas -- Making the reassoc version of this a simp lemma seems to be more harmful than helpful. @[reassoc, simp] theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) : f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) : f ≫ diag Y = prod.lift f f := by simp @[reassoc (attr := simp)] theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f := limMap_π _ _ @[reassoc (attr := simp)] theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g := limMap_π _ _ @[simp] theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp @[simp] theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] : prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp @[reassoc (attr := simp)] theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W) (g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) : prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp @[simp] theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by rw [← prod.lift_map] simp -- We take the right hand side here to be simp normal form, as this way composition lemmas for -- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just -- as well. @[reassoc (attr := simp)] theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂] [HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) : prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp -- TODO: is it necessary to weaken the assumption here? @[reassoc] theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y) [HasLimitsOfShape (Discrete WalkingPair) C] : prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp @[reassoc] theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W] [HasBinaryProduct Z W] [HasBinaryProduct Y W] : prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp @[reassoc] theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X] [HasBinaryProduct W Y] [HasBinaryProduct W Z] : prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp /-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and `g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/ @[simps] def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y) (g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where hom := prod.map f.hom g.hom inv := prod.map f.inv g.inv instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) := (prod.mapIso (asIso f) (asIso g)).isIso_hom instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f] [Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) := ⟨fun i₁ i₂ h => by ext · rw [← cancel_mono f] simpa using congr_arg (fun f => f ≫ prod.fst) h · rw [← cancel_mono g] simpa using congr_arg (fun f => f ≫ prod.snd) h⟩ @[reassoc] theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] : diag X ≫ prod.map f f = f ≫ diag Y := by simp @[reassoc] theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] : diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp @[reassoc] theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C} (g : X ⟶ Y) (g' : X' ⟶ Y') : diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) := IsSplitMono.mk' { retraction := prod.fst } end ProdLemmas noncomputable section CoprodLemmas @[reassoc, simp] theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V) (h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by ext <;> simp theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) : codiag X ≫ f = coprod.desc f f := by simp @[reassoc (attr := simp)] theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl := ι_colimMap _ _ @[reassoc (attr := simp)] theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y) (g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr := ι_colimMap _ _ @[simp] theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by ext <;> simp @[simp] theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] : coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp -- The simp linter says simp can prove the reassoc version of this lemma. @[reassoc, simp]
Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean
765
767
theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V] (f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) : coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.Data.Finite.Sum import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Fin import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Basis.SMul import Mathlib.LinearAlgebra.Matrix.StdBasis import Mathlib.RingTheory.AlgebraTower import Mathlib.RingTheory.Ideal.Span /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`, the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R` * `Matrix.toLin`: the inverse of `LinearMap.toMatrix` * `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)` to `Matrix m n R` (with the standard basis on `m → R` and `n → R`) * `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'` * `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between `R`-endomorphisms of `M` and `Matrix n n R` ## Issues This file was originally written without attention to non-commutative rings, and so mostly only works in the commutative setting. This should be fixed. In particular, `Matrix.mulVec` gives us a linear equivalence `Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)` while `Matrix.vecMul` gives us a linear equivalence `Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`. At present, the first equivalence is developed in detail but only for commutative rings (and we omit the distinction between `Rᵐᵒᵖ` and `R`), while the second equivalence is developed only in brief, but for not-necessarily-commutative rings. Naming is slightly inconsistent between the two developments. In the original (commutative) development `linear` is abbreviated to `lin`, although this is not consistent with the rest of mathlib. In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right` to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`). When the two developments are made uniform, the names should be made uniform, too, by choosing between `linear` and `lin` consistently, and (presumably) adding `_left` where necessary. ## Tags linear_map, matrix, linear_equiv, diagonal, det, trace -/ noncomputable section open LinearMap Matrix Set Submodule section ToMatrixRight variable {R : Type*} [Semiring R] variable {l m n : Type*} /-- `Matrix.vecMul M` is a linear map. -/ def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where toFun x := x ᵥ* M map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _ map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _ @[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) : M.vecMulLinear x = x ᵥ* M := rfl theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) : (M.vecMulLinear : _ → _) = M.vecMul := rfl variable [Fintype m] theorem range_vecMulLinear (M : Matrix m n R) : LinearMap.range M.vecMulLinear = span R (range M.row) := by letI := Classical.decEq m simp_rw [range_eq_map, ← iSup_range_single, Submodule.map_iSup, range_eq_map, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton, Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range, LinearMap.single, LinearMap.coe_mk, AddHom.coe_mk, row_def] unfold vecMul simp_rw [single_dotProduct, one_mul] theorem Matrix.vecMul_injective_iff {R : Type*} [Ring R] {M : Matrix m n R} : Function.Injective M.vecMul ↔ LinearIndependent R M.row := by rw [← coe_vecMulLinear] simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff, LinearMap.mem_ker, vecMulLinear_apply, row_def] refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩ · rw [← h0] ext i simp [vecMul, dotProduct] · rw [← h0] ext j simp [vecMul, dotProduct] lemma Matrix.linearIndependent_rows_of_isUnit {R : Type*} [Ring R] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.row := by rw [← Matrix.vecMul_injective_iff] exact Matrix.vecMul_injective_of_isUnit ha section variable [DecidableEq m] /-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`, by having matrices act by right multiplication. -/ def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where toFun f i j := f (single R (fun _ ↦ R) i 1) j invFun := Matrix.vecMulLinear right_inv M := by ext i j simp left_inv f := by apply (Pi.basisFun R m).ext intro j; ext i simp map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`, by having matrices act by right multiplication. -/ abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R := LinearEquiv.symm LinearMap.toMatrixRight' @[simp] theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) : (Matrix.toLinearMapRight') M v = v ᵥ* M := rfl @[simp] theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLinearMapRight' (M * N) = (Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) := LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLinearMapRight' (M * N) x = Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) := (vecMul_vecMul _ M N).symm @[simp] theorem Matrix.toLinearMapRight'_one : Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by ext simp [Module.End.one_apply] /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A` and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/ @[simps] def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R := { LinearMap.toMatrixRight'.symm M' with toFun := Matrix.toLinearMapRight' M' invFun := Matrix.toLinearMapRight' M left_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] } end end ToMatrixRight /-! From this point on, we only work with commutative rings, and fail to distinguish between `Rᵐᵒᵖ` and `R`. This should eventually be remedied. -/ section mulVec variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} /-- `Matrix.mulVec M` is a linear map. -/ def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where toFun := M.mulVec map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _ map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _ theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) : (M.mulVecLin : _ → _) = M.mulVec := rfl @[simp] theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) : M.mulVecLin v = M *ᵥ v := rfl @[simp] theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 := LinearMap.ext zero_mulVec @[simp] theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) : (M + N).mulVecLin = M.mulVecLin + N.mulVecLin := LinearMap.ext fun _ ↦ add_mulVec _ _ _ @[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) : Mᵀ.mulVecLin = M.vecMulLinear := by ext; simp [mulVec_transpose] @[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) : Mᵀ.vecMulLinear = M.mulVecLin := by ext; simp [vecMul_transpose] theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : (M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm := LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _ /-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : (reindex e₁ e₂ M).mulVecLin = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_submatrix _ _ _ variable [Fintype n] @[simp] theorem Matrix.mulVecLin_one [DecidableEq n] : Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by ext; simp [Matrix.one_apply, Pi.single_apply, eq_comm] @[simp] theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) := LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} : (LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply] theorem Matrix.range_mulVecLin (M : Matrix m n R) : LinearMap.range M.mulVecLin = span R (range M.col) := by rw [← vecMulLinear_transpose, range_vecMulLinear, row_transpose] theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.mulVec ↔ LinearIndependent R M.col := by change Function.Injective (fun x ↦ _) ↔ _ simp_rw [← M.vecMul_transpose, vecMul_injective_iff, row_transpose] lemma Matrix.linearIndependent_cols_of_isUnit {R : Type*} [CommRing R] [Fintype m] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.col := by rw [← Matrix.mulVec_injective_iff] exact Matrix.mulVec_injective_of_isUnit ha end mulVec section ToMatrix' variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} [DecidableEq n] [Fintype n] /-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/ def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where toFun f := of fun i j ↦ f (Pi.single j 1) i invFun := Matrix.mulVecLin right_inv M := by ext i j simp only [Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply] left_inv f := by apply (Pi.basisFun R n).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`. Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/ def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R := LinearMap.toMatrix'.symm theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin := rfl @[simp] theorem LinearMap.toMatrix'_symm : (LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' := rfl @[simp] theorem Matrix.toLin'_symm : (Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' := rfl @[simp] theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M := LinearMap.toMatrix'.apply_symm_apply M @[simp] theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) : Matrix.toLin' (LinearMap.toMatrix' f) = f := Matrix.toLin'.apply_symm_apply f @[simp] theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) : LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply] congr! with i split_ifs with h · rw [h, Pi.single_eq_same] apply Pi.single_eq_of_ne h @[simp] theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v := rfl @[simp] theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id := Matrix.mulVecLin_one @[simp] theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by ext rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply] @[simp] theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id @[simp] theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) := Matrix.mulVecLin_mul _ _ @[simp] theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : Matrix.toLin' (M.submatrix f₁ e₂) = funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm := Matrix.mulVecLin_submatrix _ _ _ /-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : Matrix.toLin' (reindex e₁ e₂ M) = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_reindex _ _ _ /-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/ theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by rw [Matrix.toLin'_mul, LinearMap.comp_apply] theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R) (g : (l → R) →ₗ[R] n → R) : LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by rw [this, LinearMap.toMatrix'_toLin'] rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix'] theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) : LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := LinearMap.toMatrix'_comp f g @[simp] theorem LinearMap.toMatrix'_algebraMap (x : R) : LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul] theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} : LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := Matrix.ker_mulVecLin_eq_bot_iff theorem Matrix.range_toLin' (M : Matrix m n R) : LinearMap.range (Matrix.toLin' M) = span R (range M.col) := Matrix.range_mulVecLin _ /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A` and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/ @[simps] def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R := { Matrix.toLin' M' with toFun := Matrix.toLin' M' invFun := Matrix.toLin' M left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] } /-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/ def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul /-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/ def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R := LinearMap.toMatrixAlgEquiv'.symm @[simp] theorem LinearMap.toMatrixAlgEquiv'_symm : (LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' := rfl @[simp] theorem Matrix.toLinAlgEquiv'_symm : (Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' := rfl @[simp] theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M := LinearMap.toMatrixAlgEquiv'.apply_symm_apply M @[simp] theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) : Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f := Matrix.toLinAlgEquiv'.apply_symm_apply f @[simp] theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) : LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp [LinearMap.toMatrixAlgEquiv'] @[simp] theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) : Matrix.toLinAlgEquiv' M v = M *ᵥ v := rfl theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id := Matrix.toLin'_one @[simp] theorem LinearMap.toMatrixAlgEquiv'_id : LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := LinearMap.toMatrix'_id theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f.comp g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrix'_comp _ _ theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) : LinearMap.toMatrixAlgEquiv' (f * g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrixAlgEquiv'_comp f g end ToMatrix' section ToMatrix section Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/ def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R := LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix' /-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis `Pi.basisFun R n`. -/ theorem LinearMap.toMatrix_eq_toMatrix' : LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' := rfl /-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/ def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ := (LinearMap.toMatrix v₁ v₂).symm /-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis `Pi.basisFun R n`. -/ theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' := rfl @[simp] theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ := rfl @[simp] theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ := rfl @[simp] theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) : Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply] @[simp] theorem LinearMap.toMatrix_toLin (M : Matrix m n R) : LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply] theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl, one_smul, Basis.equivFun_apply] · intro j' _ hj' rw [if_neg hj', zero_smul] · intro hj have := Finset.mem_univ j contradiction theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) : LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := LinearMap.toMatrix_apply v₁ v₂ f i j theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) : (LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) := LinearMap.toMatrix_transpose_apply v₁ v₂ f j /-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/ theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] @[simp] theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 := LinearMap.toMatrix_id v₁ @[simp] lemma LinearMap.toMatrix_singleton {ι : Type*} [Unique ι] (f : R →ₗ[R] R) (i j : ι) : f.toMatrix (.singleton ι R) (.singleton ι R) i j = f 1 := by simp [toMatrix, Subsingleton.elim j default] @[simp] theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix] theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) : LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrix v₁ v₂ f k i := by simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr] @[simp] theorem LinearMap.toMatrix_algebraMap (x : R) : LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul] theorem LinearMap.toMatrix_mulVec_repr (f : M₁ →ₗ[R] M₂) (x : M₁) : LinearMap.toMatrix v₁ v₂ f *ᵥ v₁.repr x = v₂.repr (f x) := by ext i rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix', LinearEquiv.arrowCongr_apply, v₂.equivFun_apply] congr exact v₁.equivFun.symm_apply_apply x @[simp] theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁) (b' : Basis l R M₂) : LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : M₂ →ₗ[R] M₁) = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] theorem LinearMap.toMatrix_smulBasis_left {G} [Group G] [DistribMulAction G M₁] [SMulCommClass G R M₁] (g : G) (f : M₁ →ₗ[R] M₂) : LinearMap.toMatrix (g • v₁) v₂ f = LinearMap.toMatrix v₁ v₂ (f ∘ₗ DistribMulAction.toLinearMap _ _ g) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp theorem LinearMap.toMatrix_smulBasis_right {G} [Group G] [DistribMulAction G M₂] [SMulCommClass G R M₂] (g : G) (f : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ (g • v₂) f = LinearMap.toMatrix v₁ v₂ (DistribMulAction.toLinearMap _ _ g⁻¹ ∘ₗ f) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp end Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Fintype m] [DecidableEq n] variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂] variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂) theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) : Matrix.toLin v₁ v₂ M v = ∑ j, (M *ᵥ v₁.repr v) j • v₂ j := show v₂.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by rw [Matrix.toLin'_apply, v₂.equivFun_symm_apply] @[simp] theorem Matrix.toLin_self (M : Matrix m n R) (i : n) : Matrix.toLin v₁ v₂ M (v₁ i) = ∑ j, M j i • v₂ j := by rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↦ ?_] rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same, mul_one] · intro i' _ i'_ne rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero] · intros have := Finset.mem_univ i contradiction variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃) theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ v₃ (f.comp g) = LinearMap.toMatrix v₂ v₃ f * LinearMap.toMatrix v₁ v₂ g := by simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ v₂.equivFun, LinearMap.toMatrix'_comp] theorem LinearMap.toMatrix_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by rw [Module.End.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] lemma LinearMap.toMatrix_pow (f : M₁ →ₗ[R] M₁) (k : ℕ) : (toMatrix v₁ v₁ f) ^ k = toMatrix v₁ v₁ (f ^ k) := by induction k with | zero => simp | succ k ih => rw [pow_succ, pow_succ, ih, ← toMatrix_mul] theorem Matrix.toLin_mul [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) : Matrix.toLin v₁ v₃ (A * B) = (Matrix.toLin v₂ v₃ A).comp (Matrix.toLin v₁ v₂ B) := by apply (LinearMap.toMatrix v₁ v₃).injective haveI : DecidableEq l := fun _ _ ↦ Classical.propDecidable _ rw [LinearMap.toMatrix_comp v₁ v₂ v₃] repeat' rw [LinearMap.toMatrix_toLin] /-- Shortcut lemma for `Matrix.toLin_mul` and `LinearMap.comp_apply`. -/ theorem Matrix.toLin_mul_apply [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) (x) : Matrix.toLin v₁ v₃ (A * B) x = (Matrix.toLin v₂ v₃ A) (Matrix.toLin v₁ v₂ B x) := by rw [Matrix.toLin_mul v₁ v₂, LinearMap.comp_apply] /-- If `M` and `M` are each other's inverse matrices, `Matrix.toLin M` and `Matrix.toLin M'` form a linear equivalence. -/ @[simps] def Matrix.toLinOfInv [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : M₁ ≃ₗ[R] M₂ := { Matrix.toLin v₁ v₂ M with toFun := Matrix.toLin v₁ v₂ M invFun := Matrix.toLin v₂ v₁ M' left_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hM'M, Matrix.toLin_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLin_mul_apply, hMM', Matrix.toLin_one, id_apply] } /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between linear maps `M₁ →ₗ M₁` and square matrices over `R` indexed by the basis. -/ def LinearMap.toMatrixAlgEquiv : (M₁ →ₗ[R] M₁) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv (LinearMap.toMatrix v₁ v₁) (LinearMap.toMatrix_one v₁) (LinearMap.toMatrix_mul v₁) /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between square matrices over `R` indexed by the basis and linear maps `M₁ →ₗ M₁`. -/ def Matrix.toLinAlgEquiv : Matrix n n R ≃ₐ[R] M₁ →ₗ[R] M₁ := (LinearMap.toMatrixAlgEquiv v₁).symm @[simp] theorem LinearMap.toMatrixAlgEquiv_symm : (LinearMap.toMatrixAlgEquiv v₁).symm = Matrix.toLinAlgEquiv v₁ := rfl @[simp] theorem Matrix.toLinAlgEquiv_symm : (Matrix.toLinAlgEquiv v₁).symm = LinearMap.toMatrixAlgEquiv v₁ := rfl @[simp] theorem Matrix.toLinAlgEquiv_toMatrixAlgEquiv (f : M₁ →ₗ[R] M₁) : Matrix.toLinAlgEquiv v₁ (LinearMap.toMatrixAlgEquiv v₁ f) = f := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.apply_symm_apply] @[simp] theorem LinearMap.toMatrixAlgEquiv_toLinAlgEquiv (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv v₁ (Matrix.toLinAlgEquiv v₁ M) = M := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.symm_apply_apply]
Mathlib/LinearAlgebra/Matrix/ToLin.lean
701
703
theorem LinearMap.toMatrixAlgEquiv_apply (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := by
simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_apply]
/- 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.Card import Mathlib.Data.Fintype.Basic /-! # Cardinalities of finite types This file defines the cardinality `Fintype.card α` as the number of elements in `(univ : Finset α)`. We also include some elementary results on the values of `Fintype.card` on specific types. ## Main declarations * `Fintype.card α`: Cardinality of a fintype. Equal to `Finset.univ.card`. * `Finite.surjective_of_injective`: an injective function from a finite type to itself is also surjective. -/ assert_not_exists Monoid open Function universe u v variable {α β γ : Type*} open Finset Function namespace Fintype /-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/ def card (α) [Fintype α] : ℕ := (@univ α _).card theorem subtype_card {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) : @card { x // p x } (Fintype.subtype s H) = #s := Multiset.card_pmap _ _ _ theorem card_of_subtype {p : α → Prop} (s : Finset α) (H : ∀ x : α, x ∈ s ↔ p x) [Fintype { x // p x }] : card { x // p x } = #s := by rw [← subtype_card s H] congr! @[simp] theorem card_ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : @Fintype.card p (ofFinset s H) = #s := Fintype.subtype_card s H theorem card_of_finset' {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) [Fintype p] : Fintype.card p = #s := by rw [← card_ofFinset s H]; congr! end Fintype namespace Fintype theorem ofEquiv_card [Fintype α] (f : α ≃ β) : @card β (ofEquiv α f) = card α := Multiset.card_map _ _ theorem card_congr {α β} [Fintype α] [Fintype β] (f : α ≃ β) : card α = card β := by rw [← ofEquiv_card f]; congr! @[congr] theorem card_congr' {α β} [Fintype α] [Fintype β] (h : α = β) : card α = card β := card_congr (by rw [h]) /-- Note: this lemma is specifically about `Fintype.ofSubsingleton`. For a statement about arbitrary `Fintype` instances, use either `Fintype.card_le_one_iff_subsingleton` or `Fintype.card_unique`. -/ theorem card_ofSubsingleton (a : α) [Subsingleton α] : @Fintype.card _ (ofSubsingleton a) = 1 := rfl @[simp] theorem card_unique [Unique α] [h : Fintype α] : Fintype.card α = 1 := Subsingleton.elim (ofSubsingleton default) h ▸ card_ofSubsingleton _ /-- Note: this lemma is specifically about `Fintype.ofIsEmpty`. For a statement about arbitrary `Fintype` instances, use `Fintype.card_eq_zero`. -/ theorem card_ofIsEmpty [IsEmpty α] : @Fintype.card α Fintype.ofIsEmpty = 0 := rfl end Fintype namespace Set variable {s t : Set α} -- We use an arbitrary `[Fintype s]` instance here, -- not necessarily coming from a `[Fintype α]`. @[simp] theorem toFinset_card {α : Type*} (s : Set α) [Fintype s] : s.toFinset.card = Fintype.card s := Multiset.card_map Subtype.val Finset.univ.val end Set @[simp] theorem Finset.card_univ [Fintype α] : #(univ : Finset α) = Fintype.card α := rfl theorem Finset.eq_univ_of_card [Fintype α] (s : Finset α) (hs : #s = Fintype.card α) : s = univ := eq_of_subset_of_card_le (subset_univ _) <| by rw [hs, Finset.card_univ] theorem Finset.card_eq_iff_eq_univ [Fintype α] (s : Finset α) : #s = Fintype.card α ↔ s = univ := ⟨s.eq_univ_of_card, by rintro rfl exact Finset.card_univ⟩ theorem Finset.card_le_univ [Fintype α] (s : Finset α) : #s ≤ Fintype.card α := card_le_card (subset_univ s) theorem Finset.card_lt_univ_of_not_mem [Fintype α] {s : Finset α} {x : α} (hx : x ∉ s) : #s < Fintype.card α := card_lt_card ⟨subset_univ s, not_forall.2 ⟨x, fun hx' => hx (hx' <| mem_univ x)⟩⟩ theorem Finset.card_lt_iff_ne_univ [Fintype α] (s : Finset α) : #s < Fintype.card α ↔ s ≠ Finset.univ := s.card_le_univ.lt_iff_ne.trans (not_congr s.card_eq_iff_eq_univ) theorem Finset.card_compl_lt_iff_nonempty [Fintype α] [DecidableEq α] (s : Finset α) : #sᶜ < Fintype.card α ↔ s.Nonempty := sᶜ.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty theorem Finset.card_univ_diff [DecidableEq α] [Fintype α] (s : Finset α) : #(univ \ s) = Fintype.card α - #s := Finset.card_sdiff (subset_univ s) theorem Finset.card_compl [DecidableEq α] [Fintype α] (s : Finset α) : #sᶜ = Fintype.card α - #s := Finset.card_univ_diff s @[simp] theorem Finset.card_add_card_compl [DecidableEq α] [Fintype α] (s : Finset α) : #s + #sᶜ = Fintype.card α := by rw [Finset.card_compl, ← Nat.add_sub_assoc (card_le_univ s), Nat.add_sub_cancel_left] @[simp]
Mathlib/Data/Fintype/Card.lean
139
140
theorem Finset.card_compl_add_card [DecidableEq α] [Fintype α] (s : Finset α) : #sᶜ + #s = Fintype.card α := by
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Algebra.Polynomial.Basic import Mathlib.Data.Nat.Choose.Sum import Mathlib.Algebra.CharP.Defs /-! # Theory of univariate polynomials The theorems include formulas for computing coefficients, such as `coeff_add`, `coeff_sum`, `coeff_mul` -/ noncomputable section open Finsupp Finset AddMonoidAlgebra open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ} variable [Semiring R] {p q r : R[X]} section Coeff @[simp] theorem coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := by rcases p with ⟨⟩ rcases q with ⟨⟩ simp_rw [← ofFinsupp_add, coeff] exact Finsupp.add_apply _ _ _ @[simp] theorem coeff_smul [SMulZeroClass S R] (r : S) (p : R[X]) (n : ℕ) : coeff (r • p) n = r • coeff p n := by rcases p with ⟨⟩ simp_rw [← ofFinsupp_smul, coeff] exact Finsupp.smul_apply _ _ _
Mathlib/Algebra/Polynomial/Coeff.lean
50
54
theorem support_smul [SMulZeroClass S R] (r : S) (p : R[X]) : support (r • p) ⊆ support p := by
intro i hi simp? [mem_support_iff] at hi ⊢ says simp only [mem_support_iff, coeff_smul, ne_eq] at hi ⊢ contrapose! hi
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.MeasureTheory.Measure.Prod /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun _ hs hd => lintegral_iUnion hs hd _ @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp
Mathlib/MeasureTheory/Measure/WithDensity.lean
83
87
theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by
refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h)
/- 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.Topology.Order.IsLUB /-! # Order topology on a densely ordered set -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β : Type*} section DenselyOrdered variable [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [DenselyOrdered α] {a b : α} {s : Set α} /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top element. -/ theorem closure_Ioi' {a : α} (h : (Ioi a).Nonempty) : closure (Ioi a) = Ici a := by apply Subset.antisymm · exact closure_minimal Ioi_subset_Ici_self isClosed_Ici · rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff] exact isGLB_Ioi.mem_closure h /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/ @[simp] theorem closure_Ioi (a : α) [NoMaxOrder α] : closure (Ioi a) = Ici a := closure_Ioi' nonempty_Ioi /-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom element. -/ theorem closure_Iio' (h : (Iio a).Nonempty) : closure (Iio a) = Iic a := closure_Ioi' (α := αᵒᵈ) h /-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/ @[simp] theorem closure_Iio (a : α) [NoMinOrder α] : closure (Iio a) = Iic a := closure_Iio' nonempty_Iio /-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ioo {a b : α} (hab : a ≠ b) : closure (Ioo a b) = Icc a b := by apply Subset.antisymm · exact closure_minimal Ioo_subset_Icc_self isClosed_Icc · rcases hab.lt_or_lt with hab | hab · rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le] have hab' : (Ioo a b).Nonempty := nonempty_Ioo.2 hab simp only [insert_subset_iff, singleton_subset_iff] exact ⟨(isGLB_Ioo hab).mem_closure hab', (isLUB_Ioo hab).mem_closure hab'⟩ · rw [Icc_eq_empty_of_lt hab] exact empty_subset _ /-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ioc {a b : α} (hab : a ≠ b) : closure (Ioc a b) = Icc a b := by apply Subset.antisymm · exact closure_minimal Ioc_subset_Icc_self isClosed_Icc · apply Subset.trans _ (closure_mono Ioo_subset_Ioc_self) rw [closure_Ioo hab] /-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ico {a b : α} (hab : a ≠ b) : closure (Ico a b) = Icc a b := by apply Subset.antisymm · exact closure_minimal Ico_subset_Icc_self isClosed_Icc · apply Subset.trans _ (closure_mono Ioo_subset_Ico_self) rw [closure_Ioo hab] @[simp] theorem interior_Ici' {a : α} (ha : (Iio a).Nonempty) : interior (Ici a) = Ioi a := by rw [← compl_Iio, interior_compl, closure_Iio' ha, compl_Iic] theorem interior_Ici [NoMinOrder α] {a : α} : interior (Ici a) = Ioi a := interior_Ici' nonempty_Iio @[simp] theorem interior_Iic' {a : α} (ha : (Ioi a).Nonempty) : interior (Iic a) = Iio a := interior_Ici' (α := αᵒᵈ) ha theorem interior_Iic [NoMaxOrder α] {a : α} : interior (Iic a) = Iio a := interior_Iic' nonempty_Ioi @[simp] theorem interior_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} : interior (Icc a b) = Ioo a b := by rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio] @[simp] theorem Icc_mem_nhds_iff [NoMinOrder α] [NoMaxOrder α] {a b x : α} : Icc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by rw [← interior_Icc, mem_interior_iff_mem_nhds] @[simp] theorem interior_Ico [NoMinOrder α] {a b : α} : interior (Ico a b) = Ioo a b := by rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio] @[simp] theorem Ico_mem_nhds_iff [NoMinOrder α] {a b x : α} : Ico a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by rw [← interior_Ico, mem_interior_iff_mem_nhds] @[simp] theorem interior_Ioc [NoMaxOrder α] {a b : α} : interior (Ioc a b) = Ioo a b := by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio] @[simp] theorem Ioc_mem_nhds_iff [NoMaxOrder α] {a b x : α} : Ioc a b ∈ 𝓝 x ↔ x ∈ Ioo a b := by rw [← interior_Ioc, mem_interior_iff_mem_nhds] theorem closure_interior_Icc {a b : α} (h : a ≠ b) : closure (interior (Icc a b)) = Icc a b := (closure_minimal interior_subset isClosed_Icc).antisymm <| calc Icc a b = closure (Ioo a b) := (closure_Ioo h).symm _ ⊆ closure (interior (Icc a b)) := closure_mono (interior_maximal Ioo_subset_Icc_self isOpen_Ioo) theorem Ioc_subset_closure_interior (a b : α) : Ioc a b ⊆ closure (interior (Ioc a b)) := by rcases eq_or_ne a b with (rfl | h) · simp · calc Ioc a b ⊆ Icc a b := Ioc_subset_Icc_self _ = closure (Ioo a b) := (closure_Ioo h).symm _ ⊆ closure (interior (Ioc a b)) := closure_mono (interior_maximal Ioo_subset_Ioc_self isOpen_Ioo) theorem Ico_subset_closure_interior (a b : α) : Ico a b ⊆ closure (interior (Ico a b)) := by simpa only [Ioc_toDual] using Ioc_subset_closure_interior (OrderDual.toDual b) (OrderDual.toDual a) @[simp] theorem frontier_Ici' {a : α} (ha : (Iio a).Nonempty) : frontier (Ici a) = {a} := by simp [frontier, ha] theorem frontier_Ici [NoMinOrder α] {a : α} : frontier (Ici a) = {a} := frontier_Ici' nonempty_Iio @[simp] theorem frontier_Iic' {a : α} (ha : (Ioi a).Nonempty) : frontier (Iic a) = {a} := by simp [frontier, ha] theorem frontier_Iic [NoMaxOrder α] {a : α} : frontier (Iic a) = {a} := frontier_Iic' nonempty_Ioi @[simp] theorem frontier_Ioi' {a : α} (ha : (Ioi a).Nonempty) : frontier (Ioi a) = {a} := by simp [frontier, closure_Ioi' ha, Iic_diff_Iio, Icc_self] theorem frontier_Ioi [NoMaxOrder α] {a : α} : frontier (Ioi a) = {a} := frontier_Ioi' nonempty_Ioi @[simp] theorem frontier_Iio' {a : α} (ha : (Iio a).Nonempty) : frontier (Iio a) = {a} := by simp [frontier, closure_Iio' ha, Iic_diff_Iio, Icc_self] theorem frontier_Iio [NoMinOrder α] {a : α} : frontier (Iio a) = {a} := frontier_Iio' nonempty_Iio @[simp] theorem frontier_Icc [NoMinOrder α] [NoMaxOrder α] {a b : α} (h : a ≤ b) : frontier (Icc a b) = {a, b} := by simp [frontier, h, Icc_diff_Ioo_same] @[simp] theorem frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by rw [frontier, closure_Ioo h.ne, interior_Ioo, Icc_diff_Ioo_same h.le] @[simp] theorem frontier_Ico [NoMinOrder α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by rw [frontier, closure_Ico h.ne, interior_Ico, Icc_diff_Ioo_same h.le] @[simp] theorem frontier_Ioc [NoMaxOrder α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by rw [frontier, closure_Ioc h.ne, interior_Ioc, Icc_diff_Ioo_same h.le] theorem nhdsWithin_Ioi_neBot' {a b : α} (H₁ : (Ioi a).Nonempty) (H₂ : a ≤ b) : NeBot (𝓝[Ioi a] b) := mem_closure_iff_nhdsWithin_neBot.1 <| by rwa [closure_Ioi' H₁] theorem nhdsWithin_Ioi_neBot [NoMaxOrder α] {a b : α} (H : a ≤ b) : NeBot (𝓝[Ioi a] b) := nhdsWithin_Ioi_neBot' nonempty_Ioi H theorem nhdsGT_neBot_of_exists_gt {a : α} (H : ∃ b, a < b) : NeBot (𝓝[>] a) := nhdsWithin_Ioi_neBot' H (le_refl a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioi_self_neBot' := nhdsGT_neBot_of_exists_gt instance nhdsGT_neBot [NoMaxOrder α] (a : α) : NeBot (𝓝[>] a) := nhdsWithin_Ioi_neBot le_rfl @[deprecated nhdsGT_neBot (since := "2024-12-22")] theorem nhdsWithin_Ioi_self_neBot [NoMaxOrder α] (a : α) : NeBot (𝓝[>] a) := nhdsGT_neBot a theorem nhdsWithin_Iio_neBot' {b c : α} (H₁ : (Iio c).Nonempty) (H₂ : b ≤ c) : NeBot (𝓝[Iio c] b) := mem_closure_iff_nhdsWithin_neBot.1 <| by rwa [closure_Iio' H₁] theorem nhdsWithin_Iio_neBot [NoMinOrder α] {a b : α} (H : a ≤ b) : NeBot (𝓝[Iio b] a) := nhdsWithin_Iio_neBot' nonempty_Iio H theorem nhdsWithin_Iio_self_neBot' {b : α} (H : (Iio b).Nonempty) : NeBot (𝓝[<] b) := nhdsWithin_Iio_neBot' H (le_refl b) instance nhdsLT_neBot [NoMinOrder α] (a : α) : NeBot (𝓝[<] a) := nhdsWithin_Iio_neBot (le_refl a) @[deprecated nhdsLT_neBot (since := "2024-12-22")] theorem nhdsWithin_Iio_self_neBot [NoMinOrder α] (a : α) : NeBot (𝓝[<] a) := nhdsLT_neBot a theorem right_nhdsWithin_Ico_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ico a b] b) := (isLUB_Ico H).nhdsWithin_neBot (nonempty_Ico.2 H) theorem left_nhdsWithin_Ioc_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioc a b] a) := (isGLB_Ioc H).nhdsWithin_neBot (nonempty_Ioc.2 H) theorem left_nhdsWithin_Ioo_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioo a b] a) := (isGLB_Ioo H).nhdsWithin_neBot (nonempty_Ioo.2 H) theorem right_nhdsWithin_Ioo_neBot {a b : α} (H : a < b) : NeBot (𝓝[Ioo a b] b) := (isLUB_Ioo H).nhdsWithin_neBot (nonempty_Ioo.2 H)
Mathlib/Topology/Order/DenselyOrdered.lean
223
225
theorem comap_coe_nhdsLT_of_Ioo_subset (hb : s ⊆ Iio b) (hs : s.Nonempty → ∃ a < b, Ioo a b ⊆ s) : comap ((↑) : s → α) (𝓝[<] b) = atTop := by
nontriviality
/- Copyright (c) 2023 Richard M. Hill. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Richard M. Hill -/ import Mathlib.RingTheory.PowerSeries.Trunc import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.Derivation.Basic /-! # Definitions In this file we define an operation `derivative` (formal differentiation) on the ring of formal power series in one variable (over an arbitrary commutative semiring). Under suitable assumptions, we prove that two power series are equal if their derivatives are equal and their constant terms are equal. This will give us a simple tool for proving power series identities. For example, one can easily prove the power series identity $\exp ( \log (1+X)) = 1+X$ by differentiating twice. ## Main Definition - `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation. This is abbreviated `d⁄dX R`. -/ namespace PowerSeries open Polynomial Derivation Nat section CommutativeSemiring variable {R} [CommSemiring R] /-- The formal derivative of a power series in one variable. This is defined here as a function, but will be packaged as a derivation `derivative` on `R⟦X⟧`. -/ noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff R (n + 1) f * (n + 1) theorem coeff_derivativeFun (f : R⟦X⟧) (n : ℕ) : coeff R n f.derivativeFun = coeff R (n + 1) f * (n + 1) := by rw [derivativeFun, coeff_mk] theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by ext rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative] theorem derivativeFun_add (f g : R⟦X⟧) : derivativeFun (f + g) = derivativeFun f + derivativeFun g := by ext rw [coeff_derivativeFun, map_add, map_add, coeff_derivativeFun, coeff_derivativeFun, add_mul] theorem derivativeFun_C (r : R) : derivativeFun (C R r) = 0 := by ext n -- Note that `map_zero` didn't get picked up, apparently due to a missing `FunLike.coe` rw [coeff_derivativeFun, coeff_succ_C, zero_mul, (coeff R n).map_zero]
Mathlib/RingTheory/PowerSeries/Derivative.lean
60
68
theorem trunc_derivativeFun (f : R⟦X⟧) (n : ℕ) : trunc n f.derivativeFun = derivative (trunc (n + 1) f) := by
ext d rw [coeff_trunc] split_ifs with h · have : d + 1 < n + 1 := succ_lt_succ_iff.2 h rw [coeff_derivativeFun, coeff_derivative, coeff_trunc, if_pos this] · have : ¬d + 1 < n + 1 := by rwa [succ_lt_succ_iff] rw [coeff_derivative, coeff_trunc, if_neg this, zero_mul]
/- Copyright (c) 2018 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Kim Morrison -/ import Mathlib.CategoryTheory.Opposites /-! # Morphisms from equations between objects. When working categorically, sometimes one encounters an equation `h : X = Y` between objects. Your initial aversion to this is natural and appropriate: you're in for some trouble, and if there is another way to approach the problem that won't rely on this equality, it may be worth pursuing. You have two options: 1. Use the equality `h` as one normally would in Lean (e.g. using `rw` and `subst`). This may immediately cause difficulties, because in category theory everything is dependently typed, and equations between objects quickly lead to nasty goals with `eq.rec`. 2. Promote `h` to a morphism using `eqToHom h : X ⟶ Y`, or `eqToIso h : X ≅ Y`. This file introduces various `simp` lemmas which in favourable circumstances result in the various `eqToHom` morphisms to drop out at the appropriate moment! -/ universe v₁ v₂ v₃ u₁ u₂ u₃ -- morphism levels before object levels. See note [CategoryTheory universes]. namespace CategoryTheory open Opposite variable {C : Type u₁} [Category.{v₁} C] /-- An equality `X = Y` gives us a morphism `X ⟶ Y`. It is typically better to use this, rather than rewriting by the equality then using `𝟙 _` which usually leads to dependent type theory hell. -/ def eqToHom {X Y : C} (p : X = Y) : X ⟶ Y := by rw [p]; exact 𝟙 _ @[simp] theorem eqToHom_refl (X : C) (p : X = X) : eqToHom p = 𝟙 X := rfl @[reassoc (attr := simp)] theorem eqToHom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) : eqToHom p ≫ eqToHom q = eqToHom (p.trans q) := by cases p cases q simp /-- `eqToHom h` is heterogeneously equal to the identity of its domain. -/ lemma eqToHom_heq_id_dom (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 X) := by subst h; rfl /-- `eqToHom h` is heterogeneously equal to the identity of its codomain. -/ lemma eqToHom_heq_id_cod (X Y : C) (h : X = Y) : HEq (eqToHom h) (𝟙 Y) := by subst h; rfl /-- Two morphisms are conjugate via eqToHom if and only if they are heterogeneously equal. Note this used to be in the Functor namespace, where it doesn't belong. -/ theorem conj_eqToHom_iff_heq {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : X = Z) : f = eqToHom h ≫ g ≫ eqToHom h'.symm ↔ HEq f g := by cases h cases h' simp theorem conj_eqToHom_iff_heq' {C} [Category C] {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : Z = X) : f = eqToHom h ≫ g ≫ eqToHom h' ↔ HEq f g := conj_eqToHom_iff_heq _ _ _ h'.symm theorem comp_eqToHom_iff {X Y Y' : C} (p : Y = Y') (f : X ⟶ Y) (g : X ⟶ Y') : f ≫ eqToHom p = g ↔ f = g ≫ eqToHom p.symm := { mp := fun h => h ▸ by simp mpr := fun h => by simp [eq_whisker h (eqToHom p)] } theorem eqToHom_comp_iff {X X' Y : C} (p : X = X') (f : X ⟶ Y) (g : X' ⟶ Y) : eqToHom p ≫ g = f ↔ g = eqToHom p.symm ≫ f := { mp := fun h => h ▸ by simp mpr := fun h => h ▸ by simp [whisker_eq _ h] } theorem eqToHom_comp_heq {C} [Category C] {W X Y : C} (f : Y ⟶ X) (h : W = Y) : HEq (eqToHom h ≫ f) f := by rw [← conj_eqToHom_iff_heq _ _ h rfl, eqToHom_refl, Category.comp_id] @[simp] theorem eqToHom_comp_heq_iff {C} [Category C] {W X Y Z Z' : C} (f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) : HEq (eqToHom h ≫ f) g ↔ HEq f g := ⟨(eqToHom_comp_heq ..).symm.trans, (eqToHom_comp_heq ..).trans⟩ @[simp] theorem heq_eqToHom_comp_iff {C} [Category C] {W X Y Z Z' : C} (f : Y ⟶ X) (g : Z ⟶ Z') (h : W = Y) : HEq g (eqToHom h ≫ f) ↔ HEq g f := ⟨(·.trans (eqToHom_comp_heq ..)), (·.trans (eqToHom_comp_heq ..).symm)⟩ theorem comp_eqToHom_heq {C} [Category C] {X Y Z : C} (f : X ⟶ Y) (h : Y = Z) : HEq (f ≫ eqToHom h) f := by rw [← conj_eqToHom_iff_heq' _ _ rfl h, eqToHom_refl, Category.id_comp] @[simp] theorem comp_eqToHom_heq_iff {C} [Category C] {W X Y Z Z' : C} (f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) : HEq (f ≫ eqToHom h) g ↔ HEq f g := ⟨(comp_eqToHom_heq ..).symm.trans, (comp_eqToHom_heq ..).trans⟩ @[simp] theorem heq_comp_eqToHom_iff {C} [Category C] {W X Y Z Z' : C} (f : X ⟶ Y) (g : Z ⟶ Z') (h : Y = W) : HEq g (f ≫ eqToHom h) ↔ HEq g f := ⟨(·.trans (comp_eqToHom_heq ..)), (·.trans (comp_eqToHom_heq ..).symm)⟩ theorem heq_comp {C} [Category C] {X Y Z X' Y' Z' : C} {f : X ⟶ Y} {g : Y ⟶ Z} {f' : X' ⟶ Y'} {g' : Y' ⟶ Z'} (eq1 : X = X') (eq2 : Y = Y') (eq3 : Z = Z') (H1 : HEq f f') (H2 : HEq g g') : HEq (f ≫ g) (f' ≫ g') := by cases eq1; cases eq2; cases eq3; cases H1; cases H2; rfl variable {β : Sort*} /-- We can push `eqToHom` to the left through families of morphisms. -/ -- The simpNF linter incorrectly claims that this will never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 @[reassoc (attr := simp, nolint simpNF)] theorem eqToHom_naturality {f g : β → C} (z : ∀ b, f b ⟶ g b) {j j' : β} (w : j = j') : z j ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ z j' := by cases w simp /-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/ -- The simpNF linter incorrectly claims that this will never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 @[reassoc (attr := simp, nolint simpNF)] theorem eqToHom_iso_hom_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') : (z j).hom ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').hom := by cases w simp /-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/ -- The simpNF linter incorrectly claims that this will never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 @[reassoc (attr := simp, nolint simpNF)] theorem eqToHom_iso_inv_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') : (z j).inv ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').inv := by cases w simp /-- Reducible form of congrArg_mpr_hom_left -/ @[simp] theorem congrArg_cast_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) : cast (congrArg (fun W : C => W ⟶ Z) p.symm) q = eqToHom p ≫ q := by cases p simp /-- If we (perhaps unintentionally) perform equational rewriting on the source object of a morphism, we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`. It may be advisable to introduce any necessary `eqToHom` morphisms manually, rather than relying on this lemma firing. -/ theorem congrArg_mpr_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) : (congrArg (fun W : C => W ⟶ Z) p).mpr q = eqToHom p ≫ q := by cases p simp /-- Reducible form of `congrArg_mpr_hom_right` -/ @[simp] theorem congrArg_cast_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) : cast (congrArg (fun W : C => X ⟶ W) q.symm) p = p ≫ eqToHom q.symm := by cases q simp /-- If we (perhaps unintentionally) perform equational rewriting on the target object of a morphism, we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`. It may be advisable to introduce any necessary `eqToHom` morphisms manually, rather than relying on this lemma firing. -/ theorem congrArg_mpr_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) : (congrArg (fun W : C => X ⟶ W) q).mpr p = p ≫ eqToHom q.symm := by cases q simp /-- An equality `X = Y` gives us an isomorphism `X ≅ Y`. It is typically better to use this, rather than rewriting by the equality then using `Iso.refl _` which usually leads to dependent type theory hell. -/ def eqToIso {X Y : C} (p : X = Y) : X ≅ Y := ⟨eqToHom p, eqToHom p.symm, by simp, by simp⟩ @[simp] theorem eqToIso.hom {X Y : C} (p : X = Y) : (eqToIso p).hom = eqToHom p := rfl @[simp] theorem eqToIso.inv {X Y : C} (p : X = Y) : (eqToIso p).inv = eqToHom p.symm := rfl @[simp] theorem eqToIso_refl {X : C} (p : X = X) : eqToIso p = Iso.refl X := rfl @[simp] theorem eqToIso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) : eqToIso p ≪≫ eqToIso q = eqToIso (p.trans q) := by ext; simp @[simp] theorem eqToHom_op {X Y : C} (h : X = Y) : (eqToHom h).op = eqToHom (congr_arg op h.symm) := by cases h rfl @[simp] theorem eqToHom_unop {X Y : Cᵒᵖ} (h : X = Y) : (eqToHom h).unop = eqToHom (congr_arg unop h.symm) := by cases h rfl instance {X Y : C} (h : X = Y) : IsIso (eqToHom h) := (eqToIso h).isIso_hom @[simp] theorem inv_eqToHom {X Y : C} (h : X = Y) : inv (eqToHom h) = eqToHom h.symm := by aesop_cat variable {D : Type u₂} [Category.{v₂} D] namespace Functor /-- Proving equality between functors. This isn't an extensionality lemma, because usually you don't really want to do this. -/ theorem ext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X) (h_map : ∀ X Y f, F.map f = eqToHom (h_obj X) ≫ G.map f ≫ eqToHom (h_obj Y).symm := by aesop_cat) : F = G := by match F, G with | mk F_pre _ _ , mk G_pre _ _ => match F_pre, G_pre with | Prefunctor.mk F_obj _ , Prefunctor.mk G_obj _ => obtain rfl : F_obj = G_obj := by ext X apply h_obj congr funext X Y f simpa using h_map X Y f lemma ext_of_iso {F G : C ⥤ D} (e : F ≅ G) (hobj : ∀ X, F.obj X = G.obj X) (happ : ∀ X, e.hom.app X = eqToHom (hobj X)) : F = G := Functor.ext hobj (fun X Y f => by rw [← cancel_mono (e.hom.app Y), e.hom.naturality f, happ, happ, Category.assoc, Category.assoc, eqToHom_trans, eqToHom_refl, Category.comp_id]) /-- Proving equality between functors using heterogeneous equality. -/ theorem hext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X) (h_map : ∀ (X Y) (f : X ⟶ Y), HEq (F.map f) (G.map f)) : F = G := Functor.ext h_obj fun _ _ f => (conj_eqToHom_iff_heq _ _ (h_obj _) (h_obj _)).2 <| h_map _ _ f -- Using equalities between functors. theorem congr_obj {F G : C ⥤ D} (h : F = G) (X) : F.obj X = G.obj X := by rw [h] @[reassoc] theorem congr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) : F.map f = eqToHom (congr_obj h X) ≫ G.map f ≫ eqToHom (congr_obj h Y).symm := by subst h; simp theorem congr_inv_of_congr_hom (F G : C ⥤ D) {X Y : C} (e : X ≅ Y) (hX : F.obj X = G.obj X) (hY : F.obj Y = G.obj Y) (h₂ : F.map e.hom = eqToHom (by rw [hX]) ≫ G.map e.hom ≫ eqToHom (by rw [hY])) : F.map e.inv = eqToHom (by rw [hY]) ≫ G.map e.inv ≫ eqToHom (by rw [hX]) := by simp only [← IsIso.Iso.inv_hom e, Functor.map_inv, h₂, IsIso.inv_comp, inv_eqToHom, Category.assoc] section HEq -- Composition of functors and maps w.r.t. heq variable {E : Type u₃} [Category.{v₃} E] {F G : C ⥤ D} {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} theorem map_comp_heq (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y) (hz : F.obj Z = G.obj Z) (hf : HEq (F.map f) (G.map f)) (hg : HEq (F.map g) (G.map g)) : HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by rw [F.map_comp, G.map_comp] congr theorem map_comp_heq' (hobj : ∀ X : C, F.obj X = G.obj X) (hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) : HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by rw [Functor.hext hobj fun _ _ => hmap] theorem precomp_map_heq (H : E ⥤ C) (hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) {X Y : E} (f : X ⟶ Y) : HEq ((H ⋙ F).map f) ((H ⋙ G).map f) := hmap _ theorem postcomp_map_heq (H : D ⥤ E) (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y) (hmap : HEq (F.map f) (G.map f)) : HEq ((F ⋙ H).map f) ((G ⋙ H).map f) := by dsimp congr theorem postcomp_map_heq' (H : D ⥤ E) (hobj : ∀ X : C, F.obj X = G.obj X) (hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) : HEq ((F ⋙ H).map f) ((G ⋙ H).map f) := by rw [Functor.hext hobj fun _ _ => hmap] theorem hcongr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) : HEq (F.map f) (G.map f) := by rw [h] end HEq end Functor /-- This is not always a good idea as a `@[simp]` lemma, as we lose the ability to use results that interact with `F`, e.g. the naturality of a natural transformation. In some files it may be appropriate to use `attribute [local simp] eqToHom_map`, however. -/ theorem eqToHom_map (F : C ⥤ D) {X Y : C} (p : X = Y) : F.map (eqToHom p) = eqToHom (congr_arg F.obj p) := by cases p; simp @[reassoc (attr := simp)]
Mathlib/CategoryTheory/EqToHom.lean
324
327
theorem eqToHom_map_comp (F : C ⥤ D) {X Y Z : C} (p : X = Y) (q : Y = Z) : F.map (eqToHom p) ≫ F.map (eqToHom q) = F.map (eqToHom <| p.trans q) := by
aesop_cat /-- See the note on `eqToHom_map` regarding using this as a `simp` lemma.
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann, Kyle Miller, Mario Carneiro -/ import Mathlib.Data.Finset.NatAntidiagonal import Mathlib.Data.Nat.GCD.Basic import Mathlib.Data.Nat.BinaryRec import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify import Mathlib.Data.Nat.Choose.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Fibonacci Numbers This file defines the fibonacci series, proves results about it and introduces methods to compute it quickly. -/ /-! # The Fibonacci Sequence ## Summary Definition of the Fibonacci sequence `F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`. ## Main Definitions - `Nat.fib` returns the stream of Fibonacci numbers. ## Main Statements - `Nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.`. - `Nat.fib_gcd`: `fib n` is a strong divisibility sequence. - `Nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `Nat.choose` along an antidiagonal. - `Nat.fib_succ_eq_succ_sum`: shows that `F₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1`. - `Nat.fib_two_mul` and `Nat.fib_two_mul_add_one` are the basis for an efficient algorithm to compute `fib` (see `Nat.fastFib`). ## Implementation Notes For efficiency purposes, the sequence is defined using `Stream.iterate`. ## Tags fib, fibonacci -/ namespace Nat /-- Implementation of the fibonacci sequence satisfying `fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`. *Note:* We use a stream iterator for better performance when compared to the naive recursive implementation. -/ @[pp_nodot] def fib (n : ℕ) : ℕ := ((fun p : ℕ × ℕ => (p.snd, p.fst + p.snd))^[n] (0, 1)).fst @[simp] theorem fib_zero : fib 0 = 0 := rfl @[simp] theorem fib_one : fib 1 = 1 := rfl @[simp] theorem fib_two : fib 2 = 1 := rfl /-- Shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.` -/ theorem fib_add_two {n : ℕ} : fib (n + 2) = fib n + fib (n + 1) := by simp [fib, Function.iterate_succ_apply'] lemma fib_add_one : ∀ {n}, n ≠ 0 → fib (n + 1) = fib (n - 1) + fib n | _n + 1, _ => fib_add_two theorem fib_le_fib_succ {n : ℕ} : fib n ≤ fib (n + 1) := by cases n <;> simp [fib_add_two] @[mono] theorem fib_mono : Monotone fib := monotone_nat_of_le_succ fun _ => fib_le_fib_succ @[simp] lemma fib_eq_zero : ∀ {n}, fib n = 0 ↔ n = 0 | 0 => Iff.rfl | 1 => Iff.rfl | n + 2 => by simp [fib_add_two, fib_eq_zero] @[simp] lemma fib_pos {n : ℕ} : 0 < fib n ↔ 0 < n := by simp [pos_iff_ne_zero] theorem fib_add_two_sub_fib_add_one {n : ℕ} : fib (n + 2) - fib (n + 1) = fib n := by rw [fib_add_two, add_tsub_cancel_right] theorem fib_lt_fib_succ {n : ℕ} (hn : 2 ≤ n) : fib n < fib (n + 1) := by rcases exists_add_of_le hn with ⟨n, rfl⟩ rw [← tsub_pos_iff_lt, add_comm 2, add_right_comm, fib_add_two, add_tsub_cancel_right, fib_pos] exact succ_pos n /-- `fib (n + 2)` is strictly monotone. -/ theorem fib_add_two_strictMono : StrictMono fun n => fib (n + 2) := by refine strictMono_nat_of_lt_succ fun n => ?_ rw [add_right_comm] exact fib_lt_fib_succ (self_le_add_left _ _) lemma fib_strictMonoOn : StrictMonoOn fib (Set.Ici 2) | _m + 2, _, _n + 2, _, hmn => fib_add_two_strictMono <| lt_of_add_lt_add_right hmn lemma fib_lt_fib {m : ℕ} (hm : 2 ≤ m) : ∀ {n}, fib m < fib n ↔ m < n | 0 => by simp [hm] | 1 => by simp [hm] | n + 2 => fib_strictMonoOn.lt_iff_lt hm <| by simp theorem le_fib_self {n : ℕ} (five_le_n : 5 ≤ n) : n ≤ fib n := by induction' five_le_n with n five_le_n IH · -- 5 ≤ fib 5 rfl · -- n + 1 ≤ fib (n + 1) for 5 ≤ n rw [succ_le_iff] calc n ≤ fib n := IH _ < fib (n + 1) := fib_lt_fib_succ (le_trans (by decide) five_le_n) lemma le_fib_add_one : ∀ n, n ≤ fib n + 1 | 0 => zero_le_one | 1 => one_le_two | 2 => le_rfl | 3 => le_rfl | 4 => le_rfl | _n + 5 => (le_fib_self le_add_self).trans <| le_succ _ /-- Subsequent Fibonacci numbers are coprime, see https://proofwiki.org/wiki/Consecutive_Fibonacci_Numbers_are_Coprime -/ theorem fib_coprime_fib_succ (n : ℕ) : Nat.Coprime (fib n) (fib (n + 1)) := by induction' n with n ih · simp · simp only [fib_add_two, coprime_add_self_right, Coprime, ih.symm] /-- See https://proofwiki.org/wiki/Fibonacci_Number_in_terms_of_Smaller_Fibonacci_Numbers -/ theorem fib_add (m n : ℕ) : fib (m + n + 1) = fib m * fib n + fib (m + 1) * fib (n + 1) := by induction' n with n ih generalizing m · simp · specialize ih (m + 1) rw [add_assoc m 1 n, add_comm 1 n] at ih simp only [fib_add_two, succ_eq_add_one, ih] ring theorem fib_two_mul (n : ℕ) : fib (2 * n) = fib n * (2 * fib (n + 1) - fib n) := by cases n · simp · rw [two_mul, ← add_assoc, fib_add, fib_add_two, two_mul] simp only [← add_assoc, add_tsub_cancel_right] ring theorem fib_two_mul_add_one (n : ℕ) : fib (2 * n + 1) = fib (n + 1) ^ 2 + fib n ^ 2 := by rw [two_mul, fib_add] ring theorem fib_two_mul_add_two (n : ℕ) : fib (2 * n + 2) = fib (n + 1) * (2 * fib n + fib (n + 1)) := by rw [fib_add_two, fib_two_mul, fib_two_mul_add_one] have : fib n ≤ 2 * fib (n + 1) := le_trans fib_le_fib_succ (mul_comm 2 _ ▸ Nat.le_mul_of_pos_right _ two_pos) zify [this] ring /-- Computes `(Nat.fib n, Nat.fib (n + 1))` using the binary representation of `n`. Supports `Nat.fastFib`. -/ def fastFibAux : ℕ → ℕ × ℕ := Nat.binaryRec (fib 0, fib 1) fun b _ p => if b then (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2)) else (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2) /-- Computes `Nat.fib n` using the binary representation of `n`. Proved to be equal to `Nat.fib` in `Nat.fast_fib_eq`. -/ def fastFib (n : ℕ) : ℕ := (fastFibAux n).1 theorem fast_fib_aux_bit_ff (n : ℕ) : fastFibAux (bit false n) = let p := fastFibAux n (p.1 * (2 * p.2 - p.1), p.2 ^ 2 + p.1 ^ 2) := by rw [fastFibAux, binaryRec_eq] · rfl · simp theorem fast_fib_aux_bit_tt (n : ℕ) : fastFibAux (bit true n) = let p := fastFibAux n (p.2 ^ 2 + p.1 ^ 2, p.2 * (2 * p.1 + p.2)) := by rw [fastFibAux, binaryRec_eq] · rfl · simp theorem fast_fib_aux_eq (n : ℕ) : fastFibAux n = (fib n, fib (n + 1)) := by refine Nat.binaryRec ?_ ?_ n · simp [fastFibAux] · rintro (_|_) n' ih <;> simp only [fast_fib_aux_bit_ff, fast_fib_aux_bit_tt, congr_arg Prod.fst ih, congr_arg Prod.snd ih, Prod.mk_inj] <;> simp [bit, fib_two_mul, fib_two_mul_add_one, fib_two_mul_add_two] theorem fast_fib_eq (n : ℕ) : fastFib n = fib n := by rw [fastFib, fast_fib_aux_eq]
Mathlib/Data/Nat/Fib/Basic.lean
211
212
theorem gcd_fib_add_self (m n : ℕ) : gcd (fib m) (fib (n + m)) = gcd (fib m) (fib n) := by
rcases Nat.eq_zero_or_pos n with rfl | h
/- 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.Data.Finset.Option import Mathlib.Data.PFun import Mathlib.Data.Part /-! # Image of a `Finset α` under a partially defined function In this file we define `Part.toFinset` and `Finset.pimage`. We also prove some trivial lemmas about these definitions. ## Tags finite set, image, partial function -/ variable {α β : Type*} namespace Part /-- Convert an `o : Part α` with decidable `Part.Dom o` to `Finset α`. -/ def toFinset (o : Part α) [Decidable o.Dom] : Finset α := o.toOption.toFinset @[simp] theorem mem_toFinset {o : Part α} [Decidable o.Dom] {x : α} : x ∈ o.toFinset ↔ x ∈ o := by simp [toFinset] @[simp] theorem toFinset_none [Decidable (none : Part α).Dom] : none.toFinset = (∅ : Finset α) := by simp [toFinset] @[simp] theorem toFinset_some {a : α} [Decidable (some a).Dom] : (some a).toFinset = {a} := by simp [toFinset] @[simp] theorem coe_toFinset (o : Part α) [Decidable o.Dom] : (o.toFinset : Set α) = { x | x ∈ o } := Set.ext fun _ => mem_toFinset end Part namespace Finset variable [DecidableEq β] {f g : α →. β} [∀ x, Decidable (f x).Dom] [∀ x, Decidable (g x).Dom] {s t : Finset α} {b : β} /-- Image of `s : Finset α` under a partially defined function `f : α →. β`. -/ def pimage (f : α →. β) [∀ x, Decidable (f x).Dom] (s : Finset α) : Finset β := s.biUnion fun x => (f x).toFinset @[simp] theorem mem_pimage : b ∈ s.pimage f ↔ ∃ a ∈ s, b ∈ f a := by simp [pimage] @[simp, norm_cast] theorem coe_pimage : (s.pimage f : Set β) = f.image s := Set.ext fun _ => mem_pimage @[simp]
Mathlib/Data/Finset/PImage.lean
66
67
theorem pimage_some (s : Finset α) (f : α → β) [∀ x, Decidable (Part.some <| f x).Dom] : (s.pimage fun x => Part.some (f x)) = s.image f := by
/- 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]
Mathlib/FieldTheory/RatFunc/Basic.lean
421
429
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⟩
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C → C → C` * `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`, * `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`, where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`. Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C → C → C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂ /-- right whiskering for morphisms -/ whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) := whiskerRight f X₂ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `𝟙_ C` -/ tensorUnit (C) : C /-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z) /-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/ leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X /-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/ rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/ scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C /-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/ scoped notation "α_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/ scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor /-- The property that the pentagon relation is satisfied by four objects in a category equipped with a `MonoidalCategoryStruct`. -/ def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C] (Y₁ Y₂ Y₃ Y₄ : C) : Prop := (α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom = (α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. -/ @[stacks 0FFK] -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/ tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat /-- Tensor product of compositions is composition of tensor products: `(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)` -/ tensor_comp : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by aesop_cat whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by aesop_cat id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/ associator_naturality : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y` -/ leftUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y` -/ rightUnitor_naturality : ∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W` -/ pentagon : ∀ W X Y Z : C, (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y` -/ triangle : ∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by aesop_cat attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : f ⊗ 𝟙 Y = f ▷ Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) : 𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) : (f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) : f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) : W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ := whisker_exchange f g ▸ tensorHom_def f g @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) : X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) : f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) : inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) : whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where hom := f.hom ▷ Z inv := f.inv ▷ Z instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : inv (f ▷ Z) = inv f ▷ Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) : whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where hom := f.hom ⊗ g.hom inv := f.inv ⊗ g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ scoped infixr:70 " ⊗ " => tensorIso theorem tensorIso_def {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : f ⊗ g = whiskerRightIso f X' ≪≫ whiskerLeftIso Y g := Iso.ext (tensorHom_def f.hom g.hom) theorem tensorIso_def' {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') : f ⊗ g = whiskerLeftIso X g ≪≫ whiskerRightIso f Y' := Iso.ext (tensorHom_def' f.hom g.hom) instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) := (asIso f ⊗ asIso g).isIso_hom @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : inv (f ⊗ g) = inv f ⊗ inv g := by simp [tensorHom_def ,whisker_exchange] variable {W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C) : (if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) : f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom = W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv := by rw [← cancel_epi (W ◁ (α_ X Y Z).inv), ← cancel_mono (α_ (W ⊗ X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom = (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv : W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv = (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z := by simp [← cancel_epi (W ◁ (α_ X Y Z).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom : (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv = (α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom : (α_ W X (Y ⊗ Z)).hom ≫ W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv = (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z := by rw [← cancel_epi (α_ W X (Y ⊗ Z)).inv, ← cancel_mono ((α_ W X Y).inv ▷ Z)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom : (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom ≫ (α_ W X (Y ⊗ Z)).inv = (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom : (α_ W X Y).inv ▷ Z ≫ (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom = (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom := by simp [← cancel_epi ((α_ W X Y).hom ▷ Z)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv : (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv ≫ (α_ W X Y).hom ▷ Z = W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (X Y : C) : (α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ▷ Y) = X ◁ (λ_ Y).hom := by rw [← triangle, Iso.inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (X Y : C) : (ρ_ X).inv ▷ Y ≫ (α_ X (𝟙_ C) Y).hom = X ◁ (λ_ Y).inv := by simp [← cancel_mono (X ◁ (λ_ Y).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (X Y : C) : (X ◁ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = (ρ_ X).inv ▷ Y := by simp [← cancel_mono ((ρ_ X).hom ▷ Y)] /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight X Y : 𝟙 X ▷ Y = 𝟙 (X ⊗ Y)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (X Y : C) : (λ_ X).hom ▷ Y = (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ← cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ← comp_whiskerRight_assoc, triangle, associator_naturality_left] @[reassoc, simp] theorem leftUnitor_inv_whiskerRight (X Y : C) : (λ_ X).inv ▷ Y = (λ_ (X ⊗ Y)).inv ≫ (α_ (𝟙_ C) X Y).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (X Y : C) : X ◁ (ρ_ Y).hom = (α_ X Y (𝟙_ C)).inv ≫ (ρ_ (X ⊗ Y)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (X ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ← associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right, associator_inv_naturality_right] @[reassoc, simp] theorem whiskerLeft_rightUnitor_inv (X Y : C) : X ◁ (ρ_ Y).inv = (ρ_ (X ⊗ Y)).inv ≫ (α_ X Y (𝟙_ C)).hom := eq_of_inv_eq_inv (by simp) @[reassoc] theorem leftUnitor_tensor (X Y : C) : (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ (λ_ X).hom ▷ Y := by simp @[reassoc] theorem leftUnitor_tensor_inv (X Y : C) : (λ_ (X ⊗ Y)).inv = (λ_ X).inv ▷ Y ≫ (α_ (𝟙_ C) X Y).hom := by simp @[reassoc] theorem rightUnitor_tensor (X Y : C) : (ρ_ (X ⊗ Y)).hom = (α_ X Y (𝟙_ C)).hom ≫ X ◁ (ρ_ Y).hom := by simp @[reassoc] theorem rightUnitor_tensor_inv (X Y : C) : (ρ_ (X ⊗ Y)).inv = X ◁ (ρ_ Y).inv ≫ (α_ X Y (𝟙_ C)).inv := by simp end @[reassoc] theorem associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) := by simp [tensorHom_def] @[reassoc, simp]
Mathlib/CategoryTheory/Monoidal/Category.lean
621
623
theorem associator_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g) ⊗ h = (α_ X Y Z).hom ≫ (f ⊗ g ⊗ h) ≫ (α_ X' Y' Z').inv := by
rw [associator_inv_naturality, hom_inv_id_assoc]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.Morphisms.ClosedImmersion import Mathlib.AlgebraicGeometry.PullbackCarrier import Mathlib.Topology.LocalAtTarget /-! # Universally closed morphism A morphism of schemes `f : X ⟶ Y` is universally closed if `X ×[Y] Y' ⟶ Y'` is a closed map for all base change `Y' ⟶ Y`. This implies that `f` is topologically proper (`AlgebraicGeometry.Scheme.Hom.isProperMap`). We show that being universally closed is local at the target, and is stable under compositions and base changes. -/ noncomputable section open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace universe v u namespace AlgebraicGeometry variable {X Y : Scheme.{u}} (f : X ⟶ Y) open CategoryTheory.MorphismProperty /-- A morphism of schemes `f : X ⟶ Y` is universally closed if the base change `X ×[Y] Y' ⟶ Y'` along any morphism `Y' ⟶ Y` is (topologically) a closed map. -/ @[mk_iff] class UniversallyClosed (f : X ⟶ Y) : Prop where out : universally (topologically @IsClosedMap) f lemma Scheme.Hom.isClosedMap {X Y : Scheme} (f : X.Hom Y) [UniversallyClosed f] : IsClosedMap f.base := UniversallyClosed.out _ _ _ IsPullback.of_id_snd
Mathlib/AlgebraicGeometry/Morphisms/UniversallyClosed.lean
45
46
theorem universallyClosed_eq : @UniversallyClosed = universally (topologically @IsClosedMap) := by
ext X Y f; rw [universallyClosed_iff]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.MeasureTheory.Measure.Prod /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun _ hs hd => lintegral_iUnion hs hd _ @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h) lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) : μ.withDensity f ≤ μ.withDensity g := by refine le_iff.2 fun s hs ↦ ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] refine setLIntegral_mono_ae' hs ?_ filter_upwards [hfg] with x h_le using fun _ ↦ h_le theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs, ← lintegral_add_left hf] simp only [Pi.add_apply] theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by simpa only [add_comm] using withDensity_add_left hg f theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) : (μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by ext1 s hs simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply] theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) : (sum μ).withDensity f = sum fun n => (μ n).withDensity f := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure] theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul r hf] simp only [Pi.smul_apply, smul_eq_mul] theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul' r f hr] simp only [Pi.smul_apply, smul_eq_mul] theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (r • μ).withDensity f = r • μ.withDensity f := by ext s hs simp [withDensity_apply, hs] theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) : IsFiniteMeasure (μ.withDensity f) := { measure_univ_lt_top := by rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] } theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : μ.withDensity f ≪ μ := by refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_ rw [withDensity_apply _ hs₁] exact setLIntegral_measure_zero _ _ hs₂ @[simp] theorem withDensity_zero : μ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_one : μ.withDensity 1 = μ := by ext1 s hs simp [withDensity_apply _ hs] @[simp]
Mathlib/MeasureTheory/Measure/WithDensity.lean
158
160
theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by
ext1 s hs simp [withDensity_apply _ hs]
/- Copyright (c) 2024 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Topology.ContinuousMap.ZeroAtInfty /-! # ZeroAtInftyContinuousMapClass in normed additive groups In this file we give a characterization of the predicate `zero_at_infty` from `ZeroAtInftyContinuousMapClass`. A continuous map `f` is zero at infinity if and only if for every `ε > 0` there exists a `r : ℝ` such that for all `x : E` with `r < ‖x‖` it holds that `‖f x‖ < ε`. -/ open Topology Filter variable {E F 𝓕 : Type*} variable [SeminormedAddGroup E] [SeminormedAddCommGroup F] variable [FunLike 𝓕 E F] [ZeroAtInftyContinuousMapClass 𝓕 E F]
Mathlib/Analysis/Normed/Group/ZeroAtInfty.lean
24
34
theorem ZeroAtInftyContinuousMapClass.norm_le (f : 𝓕) (ε : ℝ) (hε : 0 < ε) : ∃ (r : ℝ), ∀ (x : E) (_hx : r < ‖x‖), ‖f x‖ < ε := by
have h := zero_at_infty f rw [tendsto_zero_iff_norm_tendsto_zero, tendsto_def] at h specialize h (Metric.ball 0 ε) (Metric.ball_mem_nhds 0 hε) rcases Metric.closedBall_compl_subset_of_mem_cocompact h 0 with ⟨r, hr⟩ use r intro x hr' suffices x ∈ (fun x ↦ ‖f x‖) ⁻¹' Metric.ball 0 ε by aesop apply hr aesop
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.Tactic.CategoryTheory.Monoidal.PureCoherence /-! # Lemmas which are consequences of monoidal coherence These lemmas are all proved `by coherence`. ## Future work Investigate whether these lemmas are really needed, or if they can be replaced by use of the `coherence` tactic. -/ open CategoryTheory Category Iso namespace CategoryTheory.MonoidalCategory variable {C : Type*} [Category C] [MonoidalCategory C] -- See Proposition 2.2.4 of <http://www-math.mit.edu/~etingof/egnobookfinal.pdf> @[reassoc] theorem leftUnitor_tensor'' (X Y : C) : (α_ (𝟙_ C) X Y).hom ≫ (λ_ (X ⊗ Y)).hom = (λ_ X).hom ⊗ 𝟙 Y := by monoidal_coherence @[reassoc] theorem leftUnitor_tensor' (X Y : C) : (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ ((λ_ X).hom ⊗ 𝟙 Y) := by monoidal_coherence @[reassoc] theorem leftUnitor_tensor_inv' (X Y : C) : (λ_ (X ⊗ Y)).inv = ((λ_ X).inv ⊗ 𝟙 Y) ≫ (α_ (𝟙_ C) X Y).hom := by monoidal_coherence @[reassoc] theorem id_tensor_rightUnitor_inv (X Y : C) : 𝟙 X ⊗ (ρ_ Y).inv = (ρ_ _).inv ≫ (α_ _ _ _).hom := by monoidal_coherence @[reassoc] theorem leftUnitor_inv_tensor_id (X Y : C) : (λ_ X).inv ⊗ 𝟙 Y = (λ_ _).inv ≫ (α_ _ _ _).inv := by monoidal_coherence @[reassoc] theorem pentagon_inv_inv_hom (W X Y Z : C) : (α_ W (X ⊗ Y) Z).inv ≫ ((α_ W X Y).inv ⊗ 𝟙 Z) ≫ (α_ (W ⊗ X) Y Z).hom = (𝟙 W ⊗ (α_ X Y Z).hom) ≫ (α_ W X (Y ⊗ Z)).inv := by monoidal_coherence theorem unitors_equal : (λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom := by monoidal_coherence
Mathlib/CategoryTheory/Monoidal/CoherenceLemmas.lean
57
60
theorem unitors_inv_equal : (λ_ (𝟙_ C)).inv = (ρ_ (𝟙_ C)).inv := by
monoidal_coherence @[reassoc]
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Gabin Kolly -/ import Mathlib.Data.Fintype.Order import Mathlib.Order.Closure import Mathlib.ModelTheory.Semantics import Mathlib.ModelTheory.Encoding /-! # First-Order Substructures This file defines substructures of first-order structures in a similar manner to the various substructures appearing in the algebra library. ## Main Definitions - A `FirstOrder.Language.Substructure` is defined so that `L.Substructure M` is the type of all substructures of the `L`-structure `M`. - `FirstOrder.Language.Substructure.closure` is defined so that if `s : Set M`, `closure L s` is the least substructure of `M` containing `s`. - `FirstOrder.Language.Substructure.comap` is defined so that `s.comap f` is the preimage of the substructure `s` under the homomorphism `f`, as a substructure. - `FirstOrder.Language.Substructure.map` is defined so that `s.map f` is the image of the substructure `s` under the homomorphism `f`, as a substructure. - `FirstOrder.Language.Hom.range` is defined so that `f.range` is the range of the homomorphism `f`, as a substructure. - `FirstOrder.Language.Hom.domRestrict` and `FirstOrder.Language.Hom.codRestrict` restrict the domain and codomain respectively of first-order homomorphisms to substructures. - `FirstOrder.Language.Embedding.domRestrict` and `FirstOrder.Language.Embedding.codRestrict` restrict the domain and codomain respectively of first-order embeddings to substructures. - `FirstOrder.Language.Substructure.inclusion` is the inclusion embedding between substructures. - `FirstOrder.Language.Substructure.PartialEquiv` is defined so that `PartialEquiv L M N` is the type of equivalences between substructures of `M` and `N`. ## Main Results - `L.Substructure M` forms a `CompleteLattice`. -/ universe u v w namespace FirstOrder namespace Language variable {L : Language.{u, v}} {M : Type w} {N P : Type*} variable [L.Structure M] [L.Structure N] [L.Structure P] open FirstOrder Cardinal open Structure Cardinal section ClosedUnder open Set variable {n : ℕ} (f : L.Functions n) (s : Set M) /-- Indicates that a set in a given structure is a closed under a function symbol. -/ def ClosedUnder : Prop := ∀ x : Fin n → M, (∀ i : Fin n, x i ∈ s) → funMap f x ∈ s variable (L) @[simp] theorem closedUnder_univ : ClosedUnder f (univ : Set M) := fun _ _ => mem_univ _ variable {L f s} {t : Set M} namespace ClosedUnder theorem inter (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ∩ t) := fun x h => mem_inter (hs x fun i => mem_of_mem_inter_left (h i)) (ht x fun i => mem_of_mem_inter_right (h i)) theorem inf (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ⊓ t) := hs.inter ht variable {S : Set (Set M)} theorem sInf (hS : ∀ s, s ∈ S → ClosedUnder f s) : ClosedUnder f (sInf S) := fun x h s hs => hS s hs x fun i => h i s hs end ClosedUnder end ClosedUnder variable (L) (M) /-- A substructure of a structure `M` is a set closed under application of function symbols. -/ structure Substructure where /-- The underlying set of this substructure -/ carrier : Set M fun_mem : ∀ {n}, ∀ f : L.Functions n, ClosedUnder f carrier variable {L} {M} namespace Substructure attribute [coe] Substructure.carrier instance instSetLike : SetLike (L.Substructure M) M := ⟨Substructure.carrier, fun p q h => by cases p; cases q; congr⟩ /-- See Note [custom simps projection] -/ def Simps.coe (S : L.Substructure M) : Set M := S initialize_simps_projections Substructure (carrier → coe, as_prefix coe) @[simp] theorem mem_carrier {s : L.Substructure M} {x : M} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl /-- Two substructures are equal if they have the same elements. -/ @[ext] theorem ext {S T : L.Substructure M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h /-- Copy a substructure replacing `carrier` with a set that is equal to it. -/ protected def copy (S : L.Substructure M) (s : Set M) (hs : s = S) : L.Substructure M where carrier := s fun_mem _ f := hs.symm ▸ S.fun_mem _ f end Substructure variable {S : L.Substructure M} theorem Term.realize_mem {α : Type*} (t : L.Term α) (xs : α → M) (h : ∀ a, xs a ∈ S) : t.realize xs ∈ S := by induction t with | var a => exact h a | func f ts ih => exact Substructure.fun_mem _ _ _ ih namespace Substructure @[simp] theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s := rfl theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S := SetLike.coe_injective hs theorem constants_mem (c : L.Constants) : (c : M) ∈ S := mem_carrier.2 (S.fun_mem c _ finZeroElim) /-- The substructure `M` of the structure `M`. -/ instance instTop : Top (L.Substructure M) := ⟨{ carrier := Set.univ fun_mem := fun {_} _ _ _ => Set.mem_univ _ }⟩ instance instInhabited : Inhabited (L.Substructure M) := ⟨⊤⟩ @[simp] theorem mem_top (x : M) : x ∈ (⊤ : L.Substructure M) := Set.mem_univ x @[simp] theorem coe_top : ((⊤ : L.Substructure M) : Set M) = Set.univ := rfl /-- The inf of two substructures is their intersection. -/ instance instInf : Min (L.Substructure M) := ⟨fun S₁ S₂ => { carrier := (S₁ : Set M) ∩ (S₂ : Set M) fun_mem := fun {_} f => (S₁.fun_mem f).inf (S₂.fun_mem f) }⟩ @[simp] theorem coe_inf (p p' : L.Substructure M) : ((p ⊓ p' : L.Substructure M) : Set M) = (p : Set M) ∩ (p' : Set M) := rfl @[simp] theorem mem_inf {p p' : L.Substructure M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance instInfSet : InfSet (L.Substructure M) := ⟨fun s => { carrier := ⋂ t ∈ s, (t : Set M) fun_mem := fun {n} f => ClosedUnder.sInf (by rintro _ ⟨t, rfl⟩ by_cases h : t ∈ s · simpa [h] using t.fun_mem f · simp [h]) }⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (L.Substructure M)) : ((sInf S : L.Substructure M) : Set M) = ⋂ s ∈ S, (s : Set M) := rfl theorem mem_sInf {S : Set (L.Substructure M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := Set.mem_iInter₂ theorem mem_iInf {ι : Sort*} {S : ι → L.Substructure M} {x : M} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp, norm_cast] theorem coe_iInf {ι : Sort*} {S : ι → L.Substructure M} : ((⨅ i, S i : L.Substructure M) : Set M) = ⋂ i, (S i : Set M) := by simp only [iInf, coe_sInf, Set.biInter_range] /-- Substructures of a structure form a complete lattice. -/ instance instCompleteLattice : CompleteLattice (L.Substructure M) := { completeLatticeOfInf (L.Substructure M) fun _ => IsGLB.of_image (fun {S T : L.Substructure M} => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe) isGLB_biInf with le := (· ≤ ·) lt := (· < ·) top := ⊤ le_top := fun _ x _ => mem_top x inf := (· ⊓ ·) sInf := InfSet.sInf le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right } variable (L) /-- The `L.Substructure` generated by a set. -/ def closure : LowerAdjoint ((↑) : L.Substructure M → Set M) := ⟨fun s => sInf { S | s ⊆ S }, fun _ _ => ⟨Set.Subset.trans fun _x hx => mem_sInf.2 fun _S hS => hS hx, fun h => sInf_le h⟩⟩ variable {L} {s : Set M} theorem mem_closure {x : M} : x ∈ closure L s ↔ ∀ S : L.Substructure M, s ⊆ S → x ∈ S := mem_sInf /-- The substructure generated by a set includes the set. -/ @[simp] theorem subset_closure : s ⊆ closure L s := (closure L).le_closure s theorem not_mem_of_not_mem_closure {P : M} (hP : P ∉ closure L s) : P ∉ s := fun h => hP (subset_closure h) @[simp] theorem closed (S : L.Substructure M) : (closure L).closed (S : Set M) := congr rfl ((closure L).eq_of_le Set.Subset.rfl fun _x xS => mem_closure.2 fun _T hT => hT xS) open Set /-- A substructure `S` includes `closure L s` if and only if it includes `s`. -/ @[simp] theorem closure_le : closure L s ≤ S ↔ s ⊆ S := (closure L).closure_le_closed_iff_le s S.closed /-- Substructure closure of a set is monotone in its argument: if `s ⊆ t`, then `closure L s ≤ closure L t`. -/ @[gcongr] theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure L s ≤ closure L t := (closure L).monotone h theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure L s) : closure L s = S := (closure L).eq_of_le h₁ h₂ theorem coe_closure_eq_range_term_realize : (closure L s : Set M) = range (@Term.realize L _ _ _ ((↑) : s → M)) := by let S : L.Substructure M := ⟨range (Term.realize (L := L) ((↑) : s → M)), fun {n} f x hx => by simp only [mem_range] at * refine ⟨func f fun i => Classical.choose (hx i), ?_⟩ simp only [Term.realize, fun i => Classical.choose_spec (hx i)]⟩ change _ = (S : Set M) rw [← SetLike.ext'_iff] refine closure_eq_of_le (fun x hx => ⟨var ⟨x, hx⟩, rfl⟩) (le_sInf fun S' hS' => ?_) rintro _ ⟨t, rfl⟩ exact t.realize_mem _ fun i => hS' i.2 instance small_closure [Small.{u} s] : Small.{u} (closure L s) := by rw [← SetLike.coe_sort_coe, Substructure.coe_closure_eq_range_term_realize] exact small_range _ theorem mem_closure_iff_exists_term {x : M} : x ∈ closure L s ↔ ∃ t : L.Term s, t.realize ((↑) : s → M) = x := by rw [← SetLike.mem_coe, coe_closure_eq_range_term_realize, mem_range] theorem lift_card_closure_le_card_term : Cardinal.lift.{max u w} #(closure L s) ≤ #(L.Term s) := by rw [← SetLike.coe_sort_coe, coe_closure_eq_range_term_realize] rw [← Cardinal.lift_id'.{w, max u w} #(L.Term s)] exact Cardinal.mk_range_le_lift theorem lift_card_closure_le : Cardinal.lift.{u, w} #(closure L s) ≤ max ℵ₀ (Cardinal.lift.{u, w} #s + Cardinal.lift.{w, u} #(Σi, L.Functions i)) := by rw [← lift_umax] refine lift_card_closure_le_card_term.trans (Term.card_le.trans ?_) rw [mk_sum, lift_umax.{w, u}] lemma mem_closed_iff (s : Set M) : s ∈ (closure L).closed ↔ ∀ {n}, ∀ f : L.Functions n, ClosedUnder f s := by refine ⟨fun h n f => ?_, fun h => ?_⟩ · rw [← h] exact Substructure.fun_mem _ _ · have h' : closure L s = ⟨s, h⟩ := closure_eq_of_le (refl _) subset_closure exact congr_arg _ h' variable (L) lemma mem_closed_of_isRelational [L.IsRelational] (s : Set M) : s ∈ (closure L).closed := (mem_closed_iff s).2 isEmptyElim @[simp] lemma closure_eq_of_isRelational [L.IsRelational] (s : Set M) : closure L s = s := LowerAdjoint.closure_eq_self_of_mem_closed _ (mem_closed_of_isRelational L s) @[simp] lemma mem_closure_iff_of_isRelational [L.IsRelational] (s : Set M) (m : M) : m ∈ closure L s ↔ m ∈ s := by rw [← SetLike.mem_coe, closure_eq_of_isRelational] theorem _root_.Set.Countable.substructure_closure [Countable (Σ l, L.Functions l)] (h : s.Countable) : Countable.{w + 1} (closure L s) := by haveI : Countable s := h.to_subtype rw [← mk_le_aleph0_iff, ← lift_le_aleph0] exact lift_card_closure_le_card_term.trans mk_le_aleph0 variable {L} (S) /-- An induction principle for closure membership. If `p` holds for all elements of `s`, and is preserved under function symbols, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure L s) (Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := (@closure_le L M _ ⟨setOf p, fun {_} => Hfun⟩ _).2 Hs h /-- If `s` is a dense set in a structure `M`, `Substructure.closure L s = ⊤`, then in order to prove that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify that `p` is preserved under function symbols. -/ @[elab_as_elim]
Mathlib/ModelTheory/Substructures.lean
335
339
theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure L s = ⊤) (Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := by
have : ∀ x ∈ closure L s, p x := fun x hx => closure_induction hx Hs fun {n} => Hfun simpa [hs] using this x
/- Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.GroupWithZero.Finset import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Group.FiniteSupport import Mathlib.Algebra.NoZeroSMulDivisors.Basic import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Set.Finite.Lattice import Mathlib.Data.Set.Subsingleton /-! # Finite products and sums over types and sets We define products and sums over types and subsets of types, with no finiteness hypotheses. All infinite products and sums are defined to be junk values (i.e. one or zero). This approach is sometimes easier to use than `Finset.sum`, when issues arise with `Finset` and `Fintype` being data. ## Main definitions We use the following variables: * `α`, `β` - types with no structure; * `s`, `t` - sets * `M`, `N` - additive or multiplicative commutative monoids * `f`, `g` - functions Definitions in this file: * `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite. Zero otherwise. * `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if it's finite. One otherwise. ## Notation * `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f` * `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f` This notation works for functions `f : p → M`, where `p : Prop`, so the following works: * `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : Set α` : sum over the set `s`; * `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`; * `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`. ## Implementation notes `finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings where the user is not interested in computability and wants to do reasoning without running into typeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and `Fintype`. By sticking solely to `Set.Finite` we avoid these problems. We are aware that there are other solutions but for beginner mathematicians this approach is easier in practice. Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly. The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. We did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`. ## Tags finsum, finprod, finite sum, finite product -/ open Function Set /-! ### Definition and relation to `Finset.sum` and `Finset.prod` -/ -- Porting note: Used to be section Sort section sort variable {G M N : Type*} {α β ι : Sort*} [CommMonoid M] [CommMonoid N] section /- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas with `Classical.dec` in their statement. -/ open Classical in /-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero otherwise. -/ noncomputable irreducible_def finsum (lemma := finsum_def') [AddCommMonoid M] (f : α → M) : M := if h : (support (f ∘ PLift.down)).Finite then ∑ i ∈ h.toFinset, f i.down else 0 open Classical in /-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's finite. One otherwise. -/ @[to_additive existing] noncomputable irreducible_def finprod (lemma := finprod_def') (f : α → M) : M := if h : (mulSupport (f ∘ PLift.down)).Finite then ∏ i ∈ h.toFinset, f i.down else 1 attribute [to_additive existing] finprod_def' end open Batteries.ExtendedBinder /-- `∑ᶠ x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the support of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/ notation3"∑ᶠ "(...)", "r:67:(scoped f => finsum f) => r /-- `∏ᶠ x, f x` is notation for `finprod f`. It is the product of `f x`, where `x` ranges over the multiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/ notation3"∏ᶠ "(...)", "r:67:(scoped f => finprod f) => r -- Porting note: The following ports the lean3 notation for this file, but is currently very fickle. -- syntax (name := bigfinsum) "∑ᶠ" extBinders ", " term:67 : term -- macro_rules (kind := bigfinsum) -- | `(∑ᶠ $x:ident, $p) => `(finsum (fun $x:ident ↦ $p)) -- | `(∑ᶠ $x:ident : $t, $p) => `(finsum (fun $x:ident : $t ↦ $p)) -- | `(∑ᶠ $x:ident $b:binderPred, $p) => -- `(finsum fun $x => (finsum (α := satisfies_binder_pred% $x $b) (fun _ => $p))) -- | `(∑ᶠ ($x:ident) ($h:ident : $t), $p) => -- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p)) -- | `(∑ᶠ ($x:ident : $_) ($h:ident : $t), $p) => -- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p)) -- | `(∑ᶠ ($x:ident) ($y:ident), $p) => -- `(finsum fun $x => (finsum fun $y => $p)) -- | `(∑ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum (α := $t) fun $h => $p))) -- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p))) -- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (α := $t) fun $h => $p)))) -- -- -- syntax (name := bigfinprod) "∏ᶠ " extBinders ", " term:67 : term -- macro_rules (kind := bigfinprod) -- | `(∏ᶠ $x:ident, $p) => `(finprod (fun $x:ident ↦ $p)) -- | `(∏ᶠ $x:ident : $t, $p) => `(finprod (fun $x:ident : $t ↦ $p)) -- | `(∏ᶠ $x:ident $b:binderPred, $p) => -- `(finprod fun $x => (finprod (α := satisfies_binder_pred% $x $b) (fun _ => $p))) -- | `(∏ᶠ ($x:ident) ($h:ident : $t), $p) => -- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p)) -- | `(∏ᶠ ($x:ident : $_) ($h:ident : $t), $p) => -- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p)) -- | `(∏ᶠ ($x:ident) ($y:ident), $p) => -- `(finprod fun $x => (finprod fun $y => $p)) -- | `(∏ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod (α := $t) fun $h => $p))) -- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p))) -- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod fun $z => -- (finprod (α := $t) fun $h => $p)))) @[to_additive] theorem finprod_eq_prod_plift_of_mulSupport_toFinset_subset {f : α → M} (hf : (mulSupport (f ∘ PLift.down)).Finite) {s : Finset (PLift α)} (hs : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down := by rw [finprod, dif_pos] refine Finset.prod_subset hs fun x _ hxf => ?_ rwa [hf.mem_toFinset, nmem_mulSupport] at hxf @[to_additive] theorem finprod_eq_prod_plift_of_mulSupport_subset {f : α → M} {s : Finset (PLift α)} (hs : mulSupport (f ∘ PLift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down := finprod_eq_prod_plift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx => by rw [Finite.mem_toFinset] at hx exact hs hx @[to_additive (attr := simp)] theorem finprod_one : (∏ᶠ _ : α, (1 : M)) = 1 := by have : (mulSupport fun x : PLift α => (fun _ => 1 : α → M) x.down) ⊆ (∅ : Finset (PLift α)) := fun x h => by simp at h rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_empty] @[to_additive] theorem finprod_of_isEmpty [IsEmpty α] (f : α → M) : ∏ᶠ i, f i = 1 := by rw [← finprod_one] congr simp [eq_iff_true_of_subsingleton] @[to_additive (attr := simp)] theorem finprod_false (f : False → M) : ∏ᶠ i, f i = 1 := finprod_of_isEmpty _ @[to_additive] theorem finprod_eq_single (f : α → M) (a : α) (ha : ∀ x, x ≠ a → f x = 1) : ∏ᶠ x, f x = f a := by have : mulSupport (f ∘ PLift.down) ⊆ ({PLift.up a} : Finset (PLift α)) := by intro x contrapose simpa [PLift.eq_up_iff_down_eq] using ha x.down rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_singleton] @[to_additive] theorem finprod_unique [Unique α] (f : α → M) : ∏ᶠ i, f i = f default := finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim @[to_additive (attr := simp)] theorem finprod_true (f : True → M) : ∏ᶠ i, f i = f trivial := @finprod_unique M True _ ⟨⟨trivial⟩, fun _ => rfl⟩ f @[to_additive] theorem finprod_eq_dif {p : Prop} [Decidable p] (f : p → M) : ∏ᶠ i, f i = if h : p then f h else 1 := by split_ifs with h · haveI : Unique p := ⟨⟨h⟩, fun _ => rfl⟩ exact finprod_unique f · haveI : IsEmpty p := ⟨h⟩ exact finprod_of_isEmpty f @[to_additive] theorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : ∏ᶠ _ : p, x = if p then x else 1 := finprod_eq_dif fun _ => x @[to_additive] theorem finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g := congr_arg _ <| funext h @[to_additive (attr := congr)] theorem finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q) (hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by subst q exact finprod_congr hfg /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on the factors. -/ @[to_additive "To prove a property of a finite sum, it suffices to prove that the property is additive and holds on the summands."] theorem finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := by rw [finprod] split_ifs exacts [Finset.prod_induction _ _ hp₁ hp₀ fun i _ => hp₂ _, hp₀] theorem finprod_nonneg {R : Type*} [CommSemiring R] [PartialOrder R] [IsOrderedRing R] {f : α → R} (hf : ∀ x, 0 ≤ f x) : 0 ≤ ∏ᶠ x, f x := finprod_induction (fun x => 0 ≤ x) zero_le_one (fun _ _ => mul_nonneg) hf @[to_additive finsum_nonneg] theorem one_le_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) : 1 ≤ ∏ᶠ i, f i := finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf @[to_additive] theorem MonoidHom.map_finprod_plift (f : M →* N) (g : α → M) (h : (mulSupport <| g ∘ PLift.down).Finite) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := by rw [finprod_eq_prod_plift_of_mulSupport_subset h.coe_toFinset.ge, finprod_eq_prod_plift_of_mulSupport_subset, map_prod] rw [h.coe_toFinset] exact mulSupport_comp_subset f.map_one (g ∘ PLift.down) @[to_additive] theorem MonoidHom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := f.map_finprod_plift g (Set.toFinite _) @[to_additive] theorem MonoidHom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) : f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := by by_cases hg : (mulSupport <| g ∘ PLift.down).Finite; · exact f.map_finprod_plift g hg rw [finprod, dif_neg, f.map_one, finprod, dif_neg] exacts [Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg] @[to_additive] theorem MonoidHom.map_finprod_of_injective (g : M →* N) (hg : Injective g) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f @[to_additive] theorem MulEquiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f @[to_additive] theorem MulEquivClass.map_finprod {F : Type*} [EquivLike F M N] [MulEquivClass F M N] (g : F) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := MulEquiv.map_finprod (MulEquivClass.toMulEquiv g) f /-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is infinite. For a more usual version assuming `(support f).Finite` instead, see `finsum_smul'`. -/ theorem finsum_smul {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (f : ι → R) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _ /-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is infinite. For a more usual version assuming `(support f).Finite` instead, see `smul_finsum'`. -/ theorem smul_finsum {R M : Type*} [Semiring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (c : R) (f : ι → M) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := by rcases eq_or_ne c 0 with (rfl | hc) · simp · exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _ @[to_additive] theorem finprod_inv_distrib [DivisionCommMonoid G] (f : α → G) : (∏ᶠ x, (f x)⁻¹) = (∏ᶠ x, f x)⁻¹ := ((MulEquiv.inv G).map_finprod f).symm end sort -- Porting note: Used to be section Type section type variable {α β ι G M N : Type*} [CommMonoid M] [CommMonoid N] @[to_additive] theorem finprod_eq_mulIndicator_apply (s : Set α) (f : α → M) (a : α) : ∏ᶠ _ : a ∈ s, f a = mulIndicator s f a := by classical convert finprod_eq_if (M := M) (p := a ∈ s) (x := f a) @[to_additive (attr := simp)] theorem finprod_apply_ne_one (f : α → M) (a : α) : ∏ᶠ _ : f a ≠ 1, f a = f a := by rw [← mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport] @[to_additive] theorem finprod_mem_def (s : Set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mulIndicator s f a := finprod_congr <| finprod_eq_mulIndicator_apply s f @[to_additive] lemma finprod_mem_mulSupport (f : α → M) : ∏ᶠ a ∈ mulSupport f, f a = ∏ᶠ a, f a := by rw [finprod_mem_def, mulIndicator_mulSupport] @[to_additive] theorem finprod_eq_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i := by have A : mulSupport (f ∘ PLift.down) = Equiv.plift.symm '' mulSupport f := by rw [mulSupport_comp_eq_preimage] exact (Equiv.plift.symm.image_eq_preimage _).symm have : mulSupport (f ∘ PLift.down) ⊆ s.map Equiv.plift.symm.toEmbedding := by rw [A, Finset.coe_map] exact image_subset _ h rw [finprod_eq_prod_plift_of_mulSupport_subset this] simp only [Finset.prod_map, Equiv.coe_toEmbedding] congr @[to_additive] theorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : α → M) (hf : (mulSupport f).Finite) {s : Finset α} (h : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i := finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx @[to_additive] theorem finprod_eq_finset_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ (s : Set α)) : ∏ᶠ i, f i = ∏ i ∈ s, f i := haveI h' : (s.finite_toSet.subset h).toFinset ⊆ s := by simpa [← Finset.coe_subset, Set.coe_toFinset] finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h' @[to_additive] theorem finprod_def (f : α → M) [Decidable (mulSupport f).Finite] : ∏ᶠ i : α, f i = if h : (mulSupport f).Finite then ∏ i ∈ h.toFinset, f i else 1 := by split_ifs with h · exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _) · rw [finprod, dif_neg] rw [mulSupport_comp_eq_preimage] exact mt (fun hf => hf.of_preimage Equiv.plift.surjective) h @[to_additive] theorem finprod_of_infinite_mulSupport {f : α → M} (hf : (mulSupport f).Infinite) : ∏ᶠ i, f i = 1 := by classical rw [finprod_def, dif_neg hf] @[to_additive] theorem finprod_eq_prod (f : α → M) (hf : (mulSupport f).Finite) : ∏ᶠ i : α, f i = ∏ i ∈ hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf] @[to_additive] theorem finprod_eq_prod_of_fintype [Fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i := finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _ @[to_additive] theorem map_finset_prod {α F : Type*} [Fintype α] [EquivLike F M N] [MulEquivClass F M N] (f : F) (g : α → M) : f (∏ i : α, g i) = ∏ i : α, f (g i) := by simp [← finprod_eq_prod_of_fintype, MulEquivClass.map_finprod] @[to_additive] theorem finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : Finset α} (h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : (∏ᶠ (i) (_ : p i), f i) = ∏ i ∈ t, f i := by set s := { x | p x } change ∏ᶠ (i : α) (_ : i ∈ s), f i = ∏ i ∈ t, f i have : mulSupport (s.mulIndicator f) ⊆ t := by rw [Set.mulSupport_mulIndicator] intro x hx exact (h hx.2).1 hx.1 rw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this] refine Finset.prod_congr rfl fun x hx => mulIndicator_apply_eq_self.2 fun hxs => ?_ contrapose! hxs exact (h hxs).2 hx @[to_additive] theorem finprod_cond_ne (f : α → M) (a : α) [DecidableEq α] (hf : (mulSupport f).Finite) : (∏ᶠ (i) (_ : i ≠ a), f i) = ∏ i ∈ hf.toFinset.erase a, f i := by apply finprod_cond_eq_prod_of_cond_iff intro x hx rw [Finset.mem_erase, Finite.mem_toFinset, mem_mulSupport] exact ⟨fun h => And.intro h hx, fun h => h.1⟩ @[to_additive] theorem finprod_mem_eq_prod_of_inter_mulSupport_eq (f : α → M) {s : Set α} {t : Finset α} (h : s ∩ mulSupport f = t.toSet ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i := finprod_cond_eq_prod_of_cond_iff _ <| by intro x hxf rw [← mem_mulSupport] at hxf refine ⟨fun hx => ?_, fun hx => ?_⟩ · refine ((mem_inter_iff x t (mulSupport f)).mp ?_).1 rw [← Set.ext_iff.mp h x, mem_inter_iff] exact ⟨hx, hxf⟩ · refine ((mem_inter_iff x s (mulSupport f)).mp ?_).1 rw [Set.ext_iff.mp h x, mem_inter_iff] exact ⟨hx, hxf⟩ @[to_additive] theorem finprod_mem_eq_prod_of_subset (f : α → M) {s : Set α} {t : Finset α} (h₁ : s ∩ mulSupport f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i := finprod_cond_eq_prod_of_cond_iff _ fun hx => ⟨fun h => h₁ ⟨h, hx⟩, fun h => h₂ h⟩ @[to_additive] theorem finprod_mem_eq_prod (f : α → M) {s : Set α} (hf : (s ∩ mulSupport f).Finite) : ∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_assoc] @[to_additive] theorem finprod_mem_eq_prod_filter (f : α → M) (s : Set α) [DecidablePred (· ∈ s)] (hf : (mulSupport f).Finite) : ∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset with i ∈ s, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by ext x simp [and_comm] @[to_additive] theorem finprod_mem_eq_toFinset_prod (f : α → M) (s : Set α) [Fintype s] : ∏ᶠ i ∈ s, f i = ∏ i ∈ s.toFinset, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp_rw [coe_toFinset s] @[to_additive] theorem finprod_mem_eq_finite_toFinset_prod (f : α → M) {s : Set α} (hs : s.Finite) : ∏ᶠ i ∈ s, f i = ∏ i ∈ hs.toFinset, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [hs.coe_toFinset] @[to_additive] theorem finprod_mem_finset_eq_prod (f : α → M) (s : Finset α) : ∏ᶠ i ∈ s, f i = ∏ i ∈ s, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl @[to_additive] theorem finprod_mem_coe_finset (f : α → M) (s : Finset α) : (∏ᶠ i ∈ (s : Set α), f i) = ∏ i ∈ s, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl @[to_additive] theorem finprod_mem_eq_one_of_infinite {f : α → M} {s : Set α} (hs : (s ∩ mulSupport f).Infinite) : ∏ᶠ i ∈ s, f i = 1 := by rw [finprod_mem_def] apply finprod_of_infinite_mulSupport rwa [← mulSupport_mulIndicator] at hs @[to_additive] theorem finprod_mem_eq_one_of_forall_eq_one {f : α → M} {s : Set α} (h : ∀ x ∈ s, f x = 1) : ∏ᶠ i ∈ s, f i = 1 := by simp +contextual [h] @[to_additive] theorem finprod_mem_inter_mulSupport (f : α → M) (s : Set α) : ∏ᶠ i ∈ s ∩ mulSupport f, f i = ∏ᶠ i ∈ s, f i := by rw [finprod_mem_def, finprod_mem_def, mulIndicator_inter_mulSupport] @[to_additive] theorem finprod_mem_inter_mulSupport_eq (f : α → M) (s t : Set α) (h : s ∩ mulSupport f = t ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mulSupport, h, finprod_mem_inter_mulSupport] @[to_additive] theorem finprod_mem_inter_mulSupport_eq' (f : α → M) (s t : Set α) (h : ∀ x ∈ mulSupport f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by apply finprod_mem_inter_mulSupport_eq ext x exact and_congr_left (h x) @[to_additive] theorem finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @Set.univ α, f i = ∏ᶠ i : α, f i := finprod_congr fun _ => finprod_true _ variable {f g : α → M} {a b : α} {s t : Set α} @[to_additive] theorem finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i := h₀.symm ▸ finprod_congr fun i => finprod_congr_Prop rfl (h₁ i) @[to_additive] theorem finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) : ∏ᶠ i, f i = 1 := by simp +contextual [h] @[to_additive finsum_pos'] theorem one_lt_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M] {f : ι → M} (h : ∀ i, 1 ≤ f i) (h' : ∃ i, 1 < f i) (hf : (mulSupport f).Finite) : 1 < ∏ᶠ i, f i := by rcases h' with ⟨i, hi⟩ rw [finprod_eq_prod _ hf] refine Finset.one_lt_prod' (fun i _ ↦ h i) ⟨i, ?_, hi⟩ simpa only [Finite.mem_toFinset, mem_mulSupport] using ne_of_gt hi /-! ### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication -/ /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals the product of `f i` multiplied by the product of `g i`. -/ @[to_additive "If the additive supports of `f` and `g` are finite, then the sum of `f i + g i` equals the sum of `f i` plus the sum of `g i`."] theorem finprod_mul_distrib (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) : ∏ᶠ i, f i * g i = (∏ᶠ i, f i) * ∏ᶠ i, g i := by classical rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf Finset.subset_union_left, finprod_eq_prod_of_mulSupport_toFinset_subset g hg Finset.subset_union_right, ← Finset.prod_mul_distrib] refine finprod_eq_prod_of_mulSupport_subset _ ?_ simp only [Finset.coe_union, Finite.coe_toFinset, mulSupport_subset_iff, mem_union, mem_mulSupport] intro x contrapose! rintro ⟨hf, hg⟩ simp [hf, hg] /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i` equals the product of `f i` divided by the product of `g i`. -/ @[to_additive "If the additive supports of `f` and `g` are finite, then the sum of `f i - g i` equals the sum of `f i` minus the sum of `g i`."] theorem finprod_div_distrib [DivisionCommMonoid G] {f g : α → G} (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) : ∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i := by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mulSupport_inv g).symm.rec hg), finprod_inv_distrib] /-- A more general version of `finprod_mem_mul_distrib` that only requires `s ∩ mulSupport f` and `s ∩ mulSupport g` rather than `s` to be finite. -/ @[to_additive "A more general version of `finsum_mem_add_distrib` that only requires `s ∩ support f` and `s ∩ support g` rather than `s` to be finite."] theorem finprod_mem_mul_distrib' (hf : (s ∩ mulSupport f).Finite) (hg : (s ∩ mulSupport g).Finite) : ∏ᶠ i ∈ s, f i * g i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := by rw [← mulSupport_mulIndicator] at hf hg simp only [finprod_mem_def, mulIndicator_mul, finprod_mul_distrib hf hg] /-- The product of the constant function `1` over any set equals `1`. -/ @[to_additive "The sum of the constant function `0` over any set equals `0`."] theorem finprod_mem_one (s : Set α) : (∏ᶠ i ∈ s, (1 : M)) = 1 := by simp /-- If a function `f` equals `1` on a set `s`, then the product of `f i` over `i ∈ s` equals `1`. -/ @[to_additive "If a function `f` equals `0` on a set `s`, then the product of `f i` over `i ∈ s` equals `0`."] theorem finprod_mem_of_eqOn_one (hf : s.EqOn f 1) : ∏ᶠ i ∈ s, f i = 1 := by rw [← finprod_mem_one s] exact finprod_mem_congr rfl hf /-- If the product of `f i` over `i ∈ s` is not equal to `1`, then there is some `x ∈ s` such that `f x ≠ 1`. -/ @[to_additive "If the product of `f i` over `i ∈ s` is not equal to `0`, then there is some `x ∈ s` such that `f x ≠ 0`."] theorem exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : ∃ x ∈ s, f x ≠ 1 := by by_contra! h' exact h (finprod_mem_of_eqOn_one h') /-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` times the product of `g i` over `i ∈ s`. -/ @[to_additive "Given a finite set `s`, the sum of `f i + g i` over `i ∈ s` equals the sum of `f i` over `i ∈ s` plus the sum of `g i` over `i ∈ s`."] theorem finprod_mem_mul_distrib (hs : s.Finite) : ∏ᶠ i ∈ s, f i * g i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _) @[to_additive] theorem MonoidHom.map_finprod {f : α → M} (g : M →* N) (hf : (mulSupport f).Finite) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_plift f <| hf.preimage Equiv.plift.injective.injOn @[to_additive] theorem finprod_pow (hf : (mulSupport f).Finite) (n : ℕ) : (∏ᶠ i, f i) ^ n = ∏ᶠ i, f i ^ n := (powMonoidHom n).map_finprod hf /-- See also `finsum_smul` for a version that works even when the support of `f` is not finite, but with slightly stronger typeclass requirements. -/ theorem finsum_smul' {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] {f : ι → R} (hf : (support f).Finite) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := ((smulAddHom R M).flip x).map_finsum hf /-- See also `smul_finsum` for a version that works even when the support of `f` is not finite, but with slightly stronger typeclass requirements. -/ theorem smul_finsum' {R M : Type*} [Monoid R] [AddCommMonoid M] [DistribMulAction R M] (c : R) {f : ι → M} (hf : (support f).Finite) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := (DistribMulAction.toAddMonoidHom M c).map_finsum hf /-- A more general version of `MonoidHom.map_finprod_mem` that requires `s ∩ mulSupport f` rather than `s` to be finite. -/ @[to_additive "A more general version of `AddMonoidHom.map_finsum_mem` that requires `s ∩ support f` rather than `s` to be finite."] theorem MonoidHom.map_finprod_mem' {f : α → M} (g : M →* N) (h₀ : (s ∩ mulSupport f).Finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := by rw [g.map_finprod] · simp only [g.map_finprod_Prop] · simpa only [finprod_eq_mulIndicator_apply, mulSupport_mulIndicator] /-- Given a monoid homomorphism `g : M →* N` and a function `f : α → M`, the value of `g` at the product of `f i` over `i ∈ s` equals the product of `g (f i)` over `s`. -/ @[to_additive "Given an additive monoid homomorphism `g : M →* N` and a function `f : α → M`, the value of `g` at the sum of `f i` over `i ∈ s` equals the sum of `g (f i)` over `s`."] theorem MonoidHom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.Finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := g.map_finprod_mem' (hs.inter_of_left _) @[to_additive] theorem MulEquiv.map_finprod_mem (g : M ≃* N) (f : α → M) {s : Set α} (hs : s.Finite) : g (∏ᶠ i ∈ s, f i) = ∏ᶠ i ∈ s, g (f i) := g.toMonoidHom.map_finprod_mem f hs @[to_additive] theorem finprod_mem_inv_distrib [DivisionCommMonoid G] (f : α → G) (hs : s.Finite) : (∏ᶠ x ∈ s, (f x)⁻¹) = (∏ᶠ x ∈ s, f x)⁻¹ := ((MulEquiv.inv G).map_finprod_mem f hs).symm /-- Given a finite set `s`, the product of `f i / g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` divided by the product of `g i` over `i ∈ s`. -/ @[to_additive "Given a finite set `s`, the sum of `f i / g i` over `i ∈ s` equals the sum of `f i` over `i ∈ s` minus the sum of `g i` over `i ∈ s`."] theorem finprod_mem_div_distrib [DivisionCommMonoid G] (f g : α → G) (hs : s.Finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i := by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs] /-! ### `∏ᶠ x ∈ s, f x` and set operations -/ /-- The product of any function over an empty set is `1`. -/ @[to_additive "The sum of any function over an empty set is `0`."] theorem finprod_mem_empty : (∏ᶠ i ∈ (∅ : Set α), f i) = 1 := by simp /-- A set `s` is nonempty if the product of some function over `s` is not equal to `1`. -/ @[to_additive "A set `s` is nonempty if the sum of some function over `s` is not equal to `0`."] theorem nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.Nonempty := nonempty_iff_ne_empty.2 fun h' => h <| h'.symm ▸ finprod_mem_empty /-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of `f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive "Given finite sets `s` and `t`, the sum of `f i` over `i ∈ s ∪ t` plus the sum of `f i` over `i ∈ s ∩ t` equals the sum of `f i` over `i ∈ s` plus the sum of `f i` over `i ∈ t`."] theorem finprod_mem_union_inter (hs : s.Finite) (ht : t.Finite) : ((∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by lift s to Finset α using hs; lift t to Finset α using ht classical rw [← Finset.coe_union, ← Finset.coe_inter] simp only [finprod_mem_coe_finset, Finset.prod_union_inter] /-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mulSupport f` and `t ∩ mulSupport f` rather than `s` and `t` to be finite. -/ @[to_additive "A more general version of `finsum_mem_union_inter` that requires `s ∩ support f` and `t ∩ support f` rather than `s` and `t` to be finite."] theorem finprod_mem_union_inter' (hs : (s ∩ mulSupport f).Finite) (ht : (t ∩ mulSupport f).Finite) : ((∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mulSupport f s, ← finprod_mem_inter_mulSupport f t, ← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mulSupport, ← finprod_mem_inter_mulSupport f (s ∩ t)] congr 2 rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm] /-- A more general version of `finprod_mem_union` that requires `s ∩ mulSupport f` and `t ∩ mulSupport f` rather than `s` and `t` to be finite. -/ @[to_additive "A more general version of `finsum_mem_union` that requires `s ∩ support f` and `t ∩ support f` rather than `s` and `t` to be finite."] theorem finprod_mem_union' (hst : Disjoint s t) (hs : (s ∩ mulSupport f).Finite) (ht : (t ∩ mulSupport f).Finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty, mul_one] /-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive "Given two finite disjoint sets `s` and `t`, the sum of `f i` over `i ∈ s ∪ t` equals the sum of `f i` over `i ∈ s` plus the sum of `f i` over `i ∈ t`."] theorem finprod_mem_union (hst : Disjoint s t) (hs : s.Finite) (ht : t.Finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _) /-- A more general version of `finprod_mem_union'` that requires `s ∩ mulSupport f` and `t ∩ mulSupport f` rather than `s` and `t` to be disjoint -/ @[to_additive "A more general version of `finsum_mem_union'` that requires `s ∩ support f` and `t ∩ support f` rather than `s` and `t` to be disjoint"] theorem finprod_mem_union'' (hst : Disjoint (s ∩ mulSupport f) (t ∩ mulSupport f)) (hs : (s ∩ mulSupport f).Finite) (ht : (t ∩ mulSupport f).Finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mulSupport f s, ← finprod_mem_inter_mulSupport f t, ← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mulSupport] /-- The product of `f i` over `i ∈ {a}` equals `f a`. -/ @[to_additive "The sum of `f i` over `i ∈ {a}` equals `f a`."] theorem finprod_mem_singleton : (∏ᶠ i ∈ ({a} : Set α), f i) = f a := by rw [← Finset.coe_singleton, finprod_mem_coe_finset, Finset.prod_singleton] @[to_additive (attr := simp)] theorem finprod_cond_eq_left : (∏ᶠ (i) (_ : i = a), f i) = f a := finprod_mem_singleton @[to_additive (attr := simp)] theorem finprod_cond_eq_right : (∏ᶠ (i) (_ : a = i), f i) = f a := by simp [@eq_comm _ a] /-- A more general version of `finprod_mem_insert` that requires `s ∩ mulSupport f` rather than `s` to be finite. -/ @[to_additive "A more general version of `finsum_mem_insert` that requires `s ∩ support f` rather than `s` to be finite."] theorem finprod_mem_insert' (f : α → M) (h : a ∉ s) (hs : (s ∩ mulSupport f).Finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := by rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton] · rwa [disjoint_singleton_left] · exact (finite_singleton a).inter_of_left _ /-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals `f a` times the product of `f i` over `i ∈ s`. -/ @[to_additive "Given a finite set `s` and an element `a ∉ s`, the sum of `f i` over `i ∈ insert a s` equals `f a` plus the sum of `f i` over `i ∈ s`."] theorem finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.Finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := finprod_mem_insert' f h <| hs.inter_of_left _ /-- If `f a = 1` when `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive "If `f a = 0` when `a ∉ s`, then the sum of `f i` over `i ∈ insert a s` equals the sum of `f i` over `i ∈ s`."] theorem finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) : ∏ᶠ i ∈ insert a s, f i = ∏ᶠ i ∈ s, f i := by refine finprod_mem_inter_mulSupport_eq' _ _ _ fun x hx => ⟨?_, Or.inr⟩ rintro (rfl | hxs) exacts [not_imp_comm.1 h hx, hxs] /-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive "If `f a = 0`, then the sum of `f i` over `i ∈ insert a s` equals the sum of `f i` over `i ∈ s`."] theorem finprod_mem_insert_one (h : f a = 1) : ∏ᶠ i ∈ insert a s, f i = ∏ᶠ i ∈ s, f i := finprod_mem_insert_of_eq_one_if_not_mem fun _ => h /-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`, `f x` divides `finprod f`. -/ theorem finprod_mem_dvd {f : α → N} (a : α) (hf : (mulSupport f).Finite) : f a ∣ finprod f := by by_cases ha : a ∈ mulSupport f · rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf (Set.Subset.refl _)] exact Finset.dvd_prod_of_mem f ((Finite.mem_toFinset hf).mpr ha) · rw [nmem_mulSupport.mp ha] exact one_dvd (finprod f) /-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/ @[to_additive "The sum of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a + f b`."] theorem finprod_mem_pair (h : a ≠ b) : (∏ᶠ i ∈ ({a, b} : Set α), f i) = f a * f b := by rw [finprod_mem_insert, finprod_mem_singleton] exacts [h, finite_singleton b] /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s ∩ mulSupport (f ∘ g)`. -/ @[to_additive "The sum of `f y` over `y ∈ g '' s` equals the sum of `f (g i)` over `s` provided that `g` is injective on `s ∩ support (f ∘ g)`."] theorem finprod_mem_image' {s : Set β} {g : β → α} (hg : (s ∩ mulSupport (f ∘ g)).InjOn g) : ∏ᶠ i ∈ g '' s, f i = ∏ᶠ j ∈ s, f (g j) := by classical by_cases hs : (s ∩ mulSupport (f ∘ g)).Finite · have hg : ∀ x ∈ hs.toFinset, ∀ y ∈ hs.toFinset, g x = g y → x = y := by simpa only [hs.mem_toFinset] have := finprod_mem_eq_prod (comp f g) hs unfold Function.comp at this rw [this, ← Finset.prod_image hg] refine finprod_mem_eq_prod_of_inter_mulSupport_eq f ?_ rw [Finset.coe_image, hs.coe_toFinset, ← image_inter_mulSupport_eq, inter_assoc, inter_self] · unfold Function.comp at hs rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite] rwa [image_inter_mulSupport_eq, infinite_image_iff hg] /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s`. -/ @[to_additive "The sum of `f y` over `y ∈ g '' s` equals the sum of `f (g i)` over `s` provided that `g` is injective on `s`."] theorem finprod_mem_image {s : Set β} {g : β → α} (hg : s.InjOn g) : ∏ᶠ i ∈ g '' s, f i = ∏ᶠ j ∈ s, f (g j) := finprod_mem_image' <| hg.mono inter_subset_left /-- The product of `f y` over `y ∈ Set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective on `mulSupport (f ∘ g)`. -/ @[to_additive "The sum of `f y` over `y ∈ Set.range g` equals the sum of `f (g i)` over all `i` provided that `g` is injective on `support (f ∘ g)`."] theorem finprod_mem_range' {g : β → α} (hg : (mulSupport (f ∘ g)).InjOn g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := by rw [← image_univ, finprod_mem_image', finprod_mem_univ] rwa [univ_inter] /-- The product of `f y` over `y ∈ Set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective. -/ @[to_additive "The sum of `f y` over `y ∈ Set.range g` equals the sum of `f (g i)` over all `i` provided that `g` is injective."] theorem finprod_mem_range {g : β → α} (hg : Injective g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := finprod_mem_range' hg.injOn /-- See also `Finset.prod_bij`. -/ @[to_additive "See also `Finset.sum_bij`."] theorem finprod_mem_eq_of_bijOn {s : Set α} {t : Set β} {f : α → M} {g : β → M} (e : α → β) (he₀ : s.BijOn e t) (he₁ : ∀ x ∈ s, f x = g (e x)) : ∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j := by rw [← Set.BijOn.image_eq he₀, finprod_mem_image he₀.2.1] exact finprod_mem_congr rfl he₁ /-- See `finprod_comp`, `Fintype.prod_bijective` and `Finset.prod_bij`. -/ @[to_additive "See `finsum_comp`, `Fintype.sum_bijective` and `Finset.sum_bij`."] theorem finprod_eq_of_bijective {f : α → M} {g : β → M} (e : α → β) (he₀ : Bijective e) (he₁ : ∀ x, f x = g (e x)) : ∏ᶠ i, f i = ∏ᶠ j, g j := by rw [← finprod_mem_univ f, ← finprod_mem_univ g] exact finprod_mem_eq_of_bijOn _ (bijective_iff_bijOn_univ.mp he₀) fun x _ => he₁ x /-- See also `finprod_eq_of_bijective`, `Fintype.prod_bijective` and `Finset.prod_bij`. -/ @[to_additive "See also `finsum_eq_of_bijective`, `Fintype.sum_bijective` and `Finset.sum_bij`."] theorem finprod_comp {g : β → M} (e : α → β) (he₀ : Function.Bijective e) : (∏ᶠ i, g (e i)) = ∏ᶠ j, g j := finprod_eq_of_bijective e he₀ fun _ => rfl @[to_additive] theorem finprod_comp_equiv (e : α ≃ β) {f : β → M} : (∏ᶠ i, f (e i)) = ∏ᶠ i', f i' := finprod_comp e e.bijective @[to_additive] theorem finprod_set_coe_eq_finprod_mem (s : Set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i := by rw [← finprod_mem_range, Subtype.range_coe] exact Subtype.coe_injective @[to_additive] theorem finprod_subtype_eq_finprod_cond (p : α → Prop) : ∏ᶠ j : Subtype p, f j = ∏ᶠ (i) (_ : p i), f i := finprod_set_coe_eq_finprod_mem { i | p i } @[to_additive] theorem finprod_mem_inter_mul_diff' (t : Set α) (h : (s ∩ mulSupport f).Finite) : ((∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i) = ∏ᶠ i ∈ s, f i := by rw [← finprod_mem_union', inter_union_diff] · rw [disjoint_iff_inf_le] exact fun x hx => hx.2.2 hx.1.2 exacts [h.subset fun x hx => ⟨hx.1.1, hx.2⟩, h.subset fun x hx => ⟨hx.1.1, hx.2⟩] @[to_additive] theorem finprod_mem_inter_mul_diff (t : Set α) (h : s.Finite) : ((∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i) = ∏ᶠ i ∈ s, f i := finprod_mem_inter_mul_diff' _ <| h.inter_of_left _ /-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mulSupport f` rather than `t` to be finite. -/ @[to_additive "A more general version of `finsum_mem_add_diff` that requires `t ∩ support f` rather than `t` to be finite."] theorem finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mulSupport f).Finite) : ((∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i) = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst] /-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s` times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/ @[to_additive "Given a finite set `t` and a subset `s` of `t`, the sum of `f i` over `i ∈ s` plus the sum of `f i` over `t \\ s` equals the sum of `f i` over `i ∈ t`."] theorem finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.Finite) : ((∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i) = ∏ᶠ i ∈ t, f i := finprod_mem_mul_diff' hst (ht.inter_of_left _) /-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i` of the products of `f a` over `a ∈ t i`. -/ @[to_additive "Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the sum of `f a` over the union `⋃ i, t i` is equal to the sum over all indexes `i` of the sums of `f a` over `a ∈ t i`."] theorem finprod_mem_iUnion [Finite ι] {t : ι → Set α} (h : Pairwise (Disjoint on t)) (ht : ∀ i, (t i).Finite) : ∏ᶠ a ∈ ⋃ i : ι, t i, f a = ∏ᶠ i, ∏ᶠ a ∈ t i, f a := by cases nonempty_fintype ι lift t to ι → Finset α using ht classical rw [← biUnion_univ, ← Finset.coe_univ, ← Finset.coe_biUnion, finprod_mem_coe_finset, Finset.prod_biUnion] · simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] · exact fun x _ y _ hxy => Finset.disjoint_coe.1 (h hxy) /-- Given a family of sets `t : ι → Set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I` of the products of `f a` over `a ∈ t i`. -/ @[to_additive "Given a family of sets `t : ι → Set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the sum of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the sum over `i ∈ I` of the sums of `f a` over `a ∈ t i`."] theorem finprod_mem_biUnion {I : Set ι} {t : ι → Set α} (h : I.PairwiseDisjoint t) (hI : I.Finite) (ht : ∀ i ∈ I, (t i).Finite) : ∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j := by haveI := hI.fintype rw [biUnion_eq_iUnion, finprod_mem_iUnion, ← finprod_set_coe_eq_finprod_mem] exacts [fun x y hxy => h x.2 y.2 (Subtype.coe_injective.ne hxy), fun b => ht b b.2] /-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a` over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/ @[to_additive "If `t` is a finite set of pairwise disjoint finite sets, then the sum of `f a` over `a ∈ ⋃₀ t` is the sum over `s ∈ t` of the sums of `f a` over `a ∈ s`."] theorem finprod_mem_sUnion {t : Set (Set α)} (h : t.PairwiseDisjoint id) (ht₀ : t.Finite) (ht₁ : ∀ x ∈ t, Set.Finite x) : ∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a := by rw [Set.sUnion_eq_biUnion] exact finprod_mem_biUnion h ht₀ ht₁ @[to_additive] lemma finprod_option {f : Option α → M} (hf : (mulSupport (f ∘ some)).Finite) : ∏ᶠ o, f o = f none * ∏ᶠ a, f (some a) := by replace hf : (mulSupport f).Finite := by simpa [finite_option] convert finprod_mem_insert' f (show none ∉ Set.range Option.some by aesop) (hf.subset inter_subset_right) · aesop · rw [finprod_mem_range] exact Option.some_injective _ @[to_additive] theorem mul_finprod_cond_ne (a : α) (hf : (mulSupport f).Finite) : (f a * ∏ᶠ (i) (_ : i ≠ a), f i) = ∏ᶠ i, f i := by classical rw [finprod_eq_prod _ hf] have h : ∀ x : α, f x ≠ 1 → (x ≠ a ↔ x ∈ hf.toFinset \ {a}) := by intro x hx rw [Finset.mem_sdiff, Finset.mem_singleton, Finite.mem_toFinset, mem_mulSupport] exact ⟨fun h => And.intro hx h, fun h => h.2⟩ rw [finprod_cond_eq_prod_of_cond_iff f (fun hx => h _ hx), Finset.sdiff_singleton_eq_erase] by_cases ha : a ∈ mulSupport f · apply Finset.mul_prod_erase _ _ ((Finite.mem_toFinset _).mpr ha) · rw [mem_mulSupport, not_not] at ha rw [ha, one_mul] apply Finset.prod_erase _ ha /-- If `s : Set α` and `t : Set β` are finite sets, then taking the product over `s` commutes with taking the product over `t`. -/ @[to_additive "If `s : Set α` and `t : Set β` are finite sets, then summing over `s` commutes with summing over `t`."] theorem finprod_mem_comm {s : Set α} {t : Set β} (f : α → β → M) (hs : s.Finite) (ht : t.Finite) : (∏ᶠ i ∈ s, ∏ᶠ j ∈ t, f i j) = ∏ᶠ j ∈ t, ∏ᶠ i ∈ s, f i j := by lift s to Finset α using hs; lift t to Finset β using ht simp only [finprod_mem_coe_finset] exact Finset.prod_comm /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on factors. -/ @[to_additive "To prove a property of a finite sum, it suffices to prove that the property is additive and holds on summands."] theorem finprod_mem_induction (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ x ∈ s, p <| f x) : p (∏ᶠ i ∈ s, f i) := finprod_induction _ hp₀ hp₁ fun x => finprod_induction _ hp₀ hp₁ <| hp₂ x theorem finprod_cond_nonneg {R : Type*} [CommSemiring R] [PartialOrder R] [IsOrderedRing R] {p : α → Prop} {f : α → R} (hf : ∀ x, p x → 0 ≤ f x) : 0 ≤ ∏ᶠ (x) (_ : p x), f x := finprod_nonneg fun x => finprod_nonneg <| hf x @[to_additive]
Mathlib/Algebra/BigOperators/Finprod.lean
994
997
theorem single_le_finprod {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M] (i : α) {f : α → M} (hf : (mulSupport f).Finite) (h : ∀ j, 1 ≤ f j) : f i ≤ ∏ᶠ j, f j := by
classical calc
/- 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₁₂) exact Nat.sInf_upward_closed_eq_succ_iff hs k @[simp] theorem nilpotencyLength_eq_one_iff [Nontrivial M] : nilpotencyLength L M = 1 ↔ IsTrivial L M := by rw [nilpotencyLength_eq_succ_iff ℤ, ← trivial_iff_lower_central_eq_bot] simp theorem isTrivial_of_nilpotencyLength_le_one [IsNilpotent L M] (h : nilpotencyLength L M ≤ 1) : IsTrivial L M := by nontriviality M rcases Nat.le_one_iff_eq_zero_or_eq_one.mp h with h | h · rw [nilpotencyLength_eq_zero_iff] at h; infer_instance · rwa [nilpotencyLength_eq_one_iff] at h end /-- Given a non-trivial nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the `k-1`th term in the lower central series (the last non-trivial term). For a trivial or non-nilpotent module, this is the bottom submodule, `⊥`. -/ noncomputable def lowerCentralSeriesLast : LieSubmodule R L M := match nilpotencyLength L M with | 0 => ⊥ | k + 1 => lowerCentralSeries R L M k theorem lowerCentralSeriesLast_le_max_triv [LieModule R L M] : lowerCentralSeriesLast R L M ≤ maxTrivSubmodule R L M := by rw [lowerCentralSeriesLast] rcases h : nilpotencyLength L M with - | k · exact bot_le · rw [le_max_triv_iff_bracket_eq_bot] rw [nilpotencyLength_eq_succ_iff R, lowerCentralSeries_succ] at h exact h.1 theorem nontrivial_lowerCentralSeriesLast [LieModule R L M] [Nontrivial M] [IsNilpotent L M] : Nontrivial (lowerCentralSeriesLast R L M) := by rw [LieSubmodule.nontrivial_iff_ne_bot, lowerCentralSeriesLast] cases h : nilpotencyLength L M · rw [nilpotencyLength_eq_zero_iff, ← not_nontrivial_iff_subsingleton] at h contradiction · rw [nilpotencyLength_eq_succ_iff R] at h exact h.2 theorem lowerCentralSeriesLast_le_of_not_isTrivial [IsNilpotent L M] (h : ¬ IsTrivial L M) : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 := by rw [lowerCentralSeriesLast] replace h : 1 < nilpotencyLength L M := by by_contra contra have := isTrivial_of_nilpotencyLength_le_one L M (not_lt.mp contra) contradiction rcases hk : nilpotencyLength L M with - | k <;> rw [hk] at h · contradiction · exact antitone_lowerCentralSeries _ _ _ (Nat.lt_succ.mp h) variable [LieModule R L M] /-- For a nilpotent Lie module `M` of a Lie algebra `L`, the first term in the lower central series of `M` contains a non-zero element on which `L` acts trivially unless the entire action is trivial. Taking `M = L`, this provides a useful characterisation of Abelian-ness for nilpotent Lie algebras. -/ lemma disjoint_lowerCentralSeries_maxTrivSubmodule_iff [IsNilpotent L M] : Disjoint (lowerCentralSeries R L M 1) (maxTrivSubmodule R L M) ↔ IsTrivial L M := by refine ⟨fun h ↦ ?_, fun h ↦ by simp⟩ nontriviality M by_contra contra have : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 ⊓ maxTrivSubmodule R L M := le_inf_iff.mpr ⟨lowerCentralSeriesLast_le_of_not_isTrivial R L M contra, lowerCentralSeriesLast_le_max_triv R L M⟩ suffices ¬ Nontrivial (lowerCentralSeriesLast R L M) by exact this (nontrivial_lowerCentralSeriesLast R L M) rw [h.eq_bot, le_bot_iff] at this exact this ▸ not_nontrivial _ theorem nontrivial_max_triv_of_isNilpotent [Nontrivial M] [IsNilpotent L M] : Nontrivial (maxTrivSubmodule R L M) := Set.nontrivial_mono (lowerCentralSeriesLast_le_max_triv R L M) (nontrivial_lowerCentralSeriesLast R L M) @[simp] theorem coe_lcs_range_toEnd_eq (k : ℕ) : (lowerCentralSeries R (toEnd R L M).range M k : Submodule R M) = lowerCentralSeries R L M k := by induction k with | zero => simp | succ k ih => simp only [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (lowerCentralSeries R (toEnd R L M).range M k).mem_toSubmodule, ih] congr ext m constructor · rintro ⟨⟨-, ⟨y, rfl⟩⟩, -, n, hn, rfl⟩ exact ⟨y, LieSubmodule.mem_top _, n, hn, rfl⟩ · rintro ⟨x, -, n, hn, rfl⟩ exact ⟨⟨toEnd R L M x, LieHom.mem_range_self _ x⟩, LieSubmodule.mem_top _, n, hn, rfl⟩ @[simp] theorem isNilpotent_range_toEnd_iff : IsNilpotent (toEnd R L M).range M ↔ IsNilpotent L M := by simp only [isNilpotent_iff R _ M] constructor <;> rintro ⟨k, hk⟩ <;> use k <;> rw [← LieSubmodule.toSubmodule_inj] at hk ⊢ <;> simpa using hk end LieModule namespace LieSubmodule variable {N₁ N₂ : LieSubmodule R L M} variable [LieModule R L M] /-- The upper (aka ascending) central series. See also `LieSubmodule.lcs`. -/ def ucs (k : ℕ) : LieSubmodule R L M → LieSubmodule R L M := normalizer^[k] @[simp] theorem ucs_zero : N.ucs 0 = N := rfl @[simp] theorem ucs_succ (k : ℕ) : N.ucs (k + 1) = (N.ucs k).normalizer := Function.iterate_succ_apply' normalizer k N theorem ucs_add (k l : ℕ) : N.ucs (k + l) = (N.ucs l).ucs k := Function.iterate_add_apply normalizer k l N @[gcongr, mono] theorem ucs_mono (k : ℕ) (h : N₁ ≤ N₂) : N₁.ucs k ≤ N₂.ucs k := by induction k with | zero => simpa | succ k ih => simp only [ucs_succ] gcongr theorem ucs_eq_self_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : N₁.ucs k = N₁ := by induction k with | zero => simp | succ k ih => rwa [ucs_succ, ih] /-- If a Lie module `M` contains a self-normalizing Lie submodule `N`, then all terms of the upper central series of `M` are contained in `N`. An important instance of this situation arises from a Cartan subalgebra `H ⊆ L` with the roles of `L`, `M`, `N` played by `H`, `L`, `H`, respectively. -/ theorem ucs_le_of_normalizer_eq_self (h : N₁.normalizer = N₁) (k : ℕ) : (⊥ : LieSubmodule R L M).ucs k ≤ N₁ := by rw [← ucs_eq_self_of_normalizer_eq_self h k] gcongr simp theorem lcs_add_le_iff (l k : ℕ) : N₁.lcs (l + k) ≤ N₂ ↔ N₁.lcs l ≤ N₂.ucs k := by induction k generalizing l with | zero => simp | succ k ih => rw [(by abel : l + (k + 1) = l + 1 + k), ih, ucs_succ, lcs_succ, top_lie_le_iff_le_normalizer] theorem lcs_le_iff (k : ℕ) : N₁.lcs k ≤ N₂ ↔ N₁ ≤ N₂.ucs k := by convert lcs_add_le_iff (R := R) (L := L) (M := M) 0 k rw [zero_add] theorem gc_lcs_ucs (k : ℕ) : GaloisConnection (fun N : LieSubmodule R L M => N.lcs k) fun N : LieSubmodule R L M => N.ucs k := fun _ _ => lcs_le_iff k
Mathlib/Algebra/Lie/Nilpotent.lean
593
601
theorem ucs_eq_top_iff (k : ℕ) : N.ucs k = ⊤ ↔ LieModule.lowerCentralSeries R L M k ≤ N := by
rw [eq_top_iff, ← lcs_le_iff]; rfl variable (R) in theorem _root_.LieModule.isNilpotent_iff_exists_ucs_eq_top : LieModule.IsNilpotent L M ↔ ∃ k, (⊥ : LieSubmodule R L M).ucs k = ⊤ := by rw [LieModule.isNilpotent_iff R]; exact exists_congr fun k => by simp [ucs_eq_top_iff] theorem ucs_comap_incl (k : ℕ) :
/- 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.Algebra.BigOperators.NatAntidiagonal import Mathlib.Topology.Algebra.InfiniteSum.Constructions import Mathlib.Topology.Algebra.Ring.Basic /-! # Infinite sum in a ring This file provides lemmas about the interaction between infinite sums and multiplication. ## Main results * `tsum_mul_tsum_eq_tsum_sum_antidiagonal`: Cauchy product formula -/ open Filter Finset Function variable {ι κ α : Type*} section NonUnitalNonAssocSemiring variable [NonUnitalNonAssocSemiring α] [TopologicalSpace α] [IsTopologicalSemiring α] {f : ι → α} {a₁ : α} theorem HasSum.mul_left (a₂) (h : HasSum f a₁) : HasSum (fun i ↦ a₂ * f i) (a₂ * a₁) := by simpa only using h.map (AddMonoidHom.mulLeft a₂) (continuous_const.mul continuous_id) theorem HasSum.mul_right (a₂) (hf : HasSum f a₁) : HasSum (fun i ↦ f i * a₂) (a₁ * a₂) := by simpa only using hf.map (AddMonoidHom.mulRight a₂) (continuous_id.mul continuous_const) theorem Summable.mul_left (a) (hf : Summable f) : Summable fun i ↦ a * f i := (hf.hasSum.mul_left _).summable theorem Summable.mul_right (a) (hf : Summable f) : Summable fun i ↦ f i * a := (hf.hasSum.mul_right _).summable section tsum variable [T2Space α] protected theorem Summable.tsum_mul_left (a) (hf : Summable f) : ∑' i, a * f i = a * ∑' i, f i := (hf.hasSum.mul_left _).tsum_eq protected theorem Summable.tsum_mul_right (a) (hf : Summable f) : ∑' i, f i * a = (∑' i, f i) * a := (hf.hasSum.mul_right _).tsum_eq theorem Commute.tsum_right (a) (h : ∀ i, Commute a (f i)) : Commute a (∑' i, f i) := by classical by_cases hf : Summable f · exact (hf.tsum_mul_left a).symm.trans ((congr_arg _ <| funext h).trans (hf.tsum_mul_right a)) · exact (tsum_eq_zero_of_not_summable hf).symm ▸ Commute.zero_right _ theorem Commute.tsum_left (a) (h : ∀ i, Commute (f i) a) : Commute (∑' i, f i) a := (Commute.tsum_right _ fun i ↦ (h i).symm).symm end tsum end NonUnitalNonAssocSemiring section DivisionSemiring variable [DivisionSemiring α] [TopologicalSpace α] [IsTopologicalSemiring α] {f : ι → α} {a a₁ a₂ : α} theorem HasSum.div_const (h : HasSum f a) (b : α) : HasSum (fun i ↦ f i / b) (a / b) := by simp only [div_eq_mul_inv, h.mul_right b⁻¹] theorem Summable.div_const (h : Summable f) (b : α) : Summable fun i ↦ f i / b := (h.hasSum.div_const _).summable theorem hasSum_mul_left_iff (h : a₂ ≠ 0) : HasSum (fun i ↦ a₂ * f i) (a₂ * a₁) ↔ HasSum f a₁ := ⟨fun H ↦ by simpa only [inv_mul_cancel_left₀ h] using H.mul_left a₂⁻¹, HasSum.mul_left _⟩ theorem hasSum_mul_right_iff (h : a₂ ≠ 0) : HasSum (fun i ↦ f i * a₂) (a₁ * a₂) ↔ HasSum f a₁ := ⟨fun H ↦ by simpa only [mul_inv_cancel_right₀ h] using H.mul_right a₂⁻¹, HasSum.mul_right _⟩ theorem hasSum_div_const_iff (h : a₂ ≠ 0) : HasSum (fun i ↦ f i / a₂) (a₁ / a₂) ↔ HasSum f a₁ := by simpa only [div_eq_mul_inv] using hasSum_mul_right_iff (inv_ne_zero h) theorem summable_mul_left_iff (h : a ≠ 0) : (Summable fun i ↦ a * f i) ↔ Summable f := ⟨fun H ↦ by simpa only [inv_mul_cancel_left₀ h] using H.mul_left a⁻¹, fun H ↦ H.mul_left _⟩ theorem summable_mul_right_iff (h : a ≠ 0) : (Summable fun i ↦ f i * a) ↔ Summable f := ⟨fun H ↦ by simpa only [mul_inv_cancel_right₀ h] using H.mul_right a⁻¹, fun H ↦ H.mul_right _⟩ theorem summable_div_const_iff (h : a ≠ 0) : (Summable fun i ↦ f i / a) ↔ Summable f := by simpa only [div_eq_mul_inv] using summable_mul_right_iff (inv_ne_zero h)
Mathlib/Topology/Algebra/InfiniteSum/Ring.lean
93
94
theorem tsum_mul_left [T2Space α] : ∑' x, a * f x = a * ∑' x, f x := by
classical
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Analysis.Normed.Module.FiniteDimension /-! # Higher differentiability in finite dimensions. -/ noncomputable section universe uD uE uF variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {D : Type uD} [NormedAddCommGroup D] [NormedSpace 𝕜 D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {n : WithTop ℕ∞} {f : D → E} {s : Set D} /-! ### Finite dimensional results -/ section FiniteDimensional open Function Module open scoped ContDiff variable [CompleteSpace 𝕜] /-- A family of continuous linear maps is `C^n` on `s` if all its applications are. -/ theorem contDiffOn_clm_apply {f : D → E →L[𝕜] F} {s : Set D} [FiniteDimensional 𝕜 E] : ContDiffOn 𝕜 n f s ↔ ∀ y, ContDiffOn 𝕜 n (fun x => f x y) s := by refine ⟨fun h y => h.clm_apply contDiffOn_const, fun h => ?_⟩ let d := finrank 𝕜 E have hd : d = finrank 𝕜 (Fin d → 𝕜) := (finrank_fin_fun 𝕜).symm let e₁ := ContinuousLinearEquiv.ofFinrankEq hd let e₂ := (e₁.arrowCongr (1 : F ≃L[𝕜] F)).trans (ContinuousLinearEquiv.piRing (Fin d)) rw [← id_comp f, ← e₂.symm_comp_self] exact e₂.symm.contDiff.comp_contDiffOn (contDiffOn_pi.mpr fun i => h _) theorem contDiff_clm_apply_iff {f : D → E →L[𝕜] F} [FiniteDimensional 𝕜 E] : ContDiff 𝕜 n f ↔ ∀ y, ContDiff 𝕜 n fun x => f x y := by simp_rw [← contDiffOn_univ, contDiffOn_clm_apply] /-- This is a useful lemma to prove that a certain operation preserves functions being `C^n`. When you do induction on `n`, this gives a useful characterization of a function being `C^(n+1)`, assuming you have already computed the derivative. The advantage of this version over `contDiff_succ_iff_fderiv` is that both occurrences of `ContDiff` are for functions with the same domain and codomain (`D` and `E`). This is not the case for `contDiff_succ_iff_fderiv`, which often requires an inconvenient need to generalize `F`, which results in universe issues (see the discussion in the section of `ContDiff.comp`). This lemma avoids these universe issues, but only applies for finite dimensional `D`. -/ theorem contDiff_succ_iff_fderiv_apply [FiniteDimensional 𝕜 D] : ContDiff 𝕜 (n + 1) f ↔ Differentiable 𝕜 f ∧ (n = ω → AnalyticOnNhd 𝕜 f Set.univ) ∧ ∀ y, ContDiff 𝕜 n fun x => fderiv 𝕜 f x y := by rw [contDiff_succ_iff_fderiv, contDiff_clm_apply_iff] theorem contDiffOn_succ_of_fderiv_apply [FiniteDimensional 𝕜 D] (hf : DifferentiableOn 𝕜 f s) (h'f : n = ω → AnalyticOn 𝕜 f s) (h : ∀ y, ContDiffOn 𝕜 n (fun x => fderivWithin 𝕜 f s x y) s) : ContDiffOn 𝕜 (n + 1) f s := contDiffOn_succ_of_fderivWithin hf h'f <| contDiffOn_clm_apply.mpr h
Mathlib/Analysis/Calculus/ContDiff/FiniteDimension.lean
71
75
theorem contDiffOn_succ_iff_fderiv_apply [FiniteDimensional 𝕜 D] (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1) f s ↔ DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧ ∀ y, ContDiffOn 𝕜 n (fun x => fderivWithin 𝕜 f s x y) s := by
rw [contDiffOn_succ_iff_fderivWithin hs, contDiffOn_clm_apply]
/- Copyright (c) 2023 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.CategoryTheory.Sites.Canonical import Mathlib.CategoryTheory.Sites.Coherent.Basic import Mathlib.CategoryTheory.Sites.EffectiveEpimorphic /-! # Sheaves for the coherent topology This file characterises sheaves for the coherent topology ## Main result * `isSheaf_coherent`: a presheaf of types for the is a sheaf for the coherent topology if and only if it satisfies the sheaf condition with respect to every presieve consisting of a finite effective epimorphic family. -/ namespace CategoryTheory variable {C : Type*} [Category C] [Precoherent C] universe w in lemma isSheaf_coherent (P : Cᵒᵖ ⥤ Type w) : Presieve.IsSheaf (coherentTopology C) P ↔ (∀ (B : C) (α : Type) [Finite α] (X : α → C) (π : (a : α) → (X a ⟶ B)), EffectiveEpiFamily X π → (Presieve.ofArrows X π).IsSheafFor P) := by constructor · intro hP B α _ X π h simp only [coherentTopology, Presieve.isSheaf_coverage] at hP apply hP exact ⟨α, inferInstance, X, π, rfl, h⟩ · intro h simp only [coherentTopology, Presieve.isSheaf_coverage] rintro B S ⟨α, _, X, π, rfl, hS⟩ exact h _ _ _ _ hS namespace coherentTopology /-- Every Yoneda-presheaf is a sheaf for the coherent topology. -/
Mathlib/CategoryTheory/Sites/Coherent/CoherentSheaves.lean
44
58
theorem isSheaf_yoneda_obj (W : C) : Presieve.IsSheaf (coherentTopology C) (yoneda.obj W) := by
rw [isSheaf_coherent] intro X α _ Y π H have h_colim := isColimitOfEffectiveEpiFamilyStruct Y π H.effectiveEpiFamily.some rw [← Sieve.generateFamily_eq] at h_colim intro x hx let x_ext := Presieve.FamilyOfElements.sieveExtend x have hx_ext := Presieve.FamilyOfElements.Compatible.sieveExtend hx let S := Sieve.generate (Presieve.ofArrows Y π) obtain ⟨t, t_amalg, t_uniq⟩ : ∃! t, x_ext.IsAmalgamation t := (Sieve.forallYonedaIsSheaf_iff_colimit S).mpr ⟨h_colim⟩ W x_ext hx_ext refine ⟨t, ?_, ?_⟩ · convert Presieve.isAmalgamation_restrict (Sieve.le_generate (Presieve.ofArrows Y π)) _ _ t_amalg exact (Presieve.restrict_extend hx).symm · exact fun y hy ↦ t_uniq y <| Presieve.isAmalgamation_sieveExtend x y hy
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Jeremy Avigad, Simon Hudon -/ import Mathlib.Algebra.Notation.Defs import Mathlib.Data.Set.Subsingleton import Mathlib.Logic.Equiv.Defs /-! # Partial values of a type This file defines `Part α`, the partial values of a type. `o : Part α` carries a proposition `o.Dom`, its domain, along with a function `get : o.Dom → α`, its value. The rule is then that every partial value has a value but, to access it, you need to provide a proof of the domain. `Part α` behaves the same as `Option α` except that `o : Option α` is decidably `none` or `some a` for some `a : α`, while the domain of `o : Part α` doesn't have to be decidable. That means you can translate back and forth between a partial value with a decidable domain and an option, and `Option α` and `Part α` are classically equivalent. In general, `Part α` is bigger than `Option α`. In current mathlib, `Part ℕ`, aka `PartENat`, is used to move decidability of the order to decidability of `PartENat.find` (which is the smallest natural satisfying a predicate, or `∞` if there's none). ## Main declarations `Option`-like declarations: * `Part.none`: The partial value whose domain is `False`. * `Part.some a`: The partial value whose domain is `True` and whose value is `a`. * `Part.ofOption`: Converts an `Option α` to a `Part α` by sending `none` to `none` and `some a` to `some a`. * `Part.toOption`: Converts a `Part α` with a decidable domain to an `Option α`. * `Part.equivOption`: Classical equivalence between `Part α` and `Option α`. Monadic structure: * `Part.bind`: `o.bind f` has value `(f (o.get _)).get _` (`f o` morally) and is defined when `o` and `f (o.get _)` are defined. * `Part.map`: Maps the value and keeps the same domain. Other: * `Part.restrict`: `Part.restrict p o` replaces the domain of `o : Part α` by `p : Prop` so long as `p → o.Dom`. * `Part.assert`: `assert p f` appends `p` to the domains of the values of a partial function. * `Part.unwrap`: Gets the value of a partial value regardless of its domain. Unsound. ## Notation For `a : α`, `o : Part α`, `a ∈ o` means that `o` is defined and equal to `a`. Formally, it means `o.Dom` and `o.get _ = a`. -/ assert_not_exists RelIso open Function /-- `Part α` is the type of "partial values" of type `α`. It is similar to `Option α` except the domain condition can be an arbitrary proposition, not necessarily decidable. -/ structure Part.{u} (α : Type u) : Type u where /-- The domain of a partial value -/ Dom : Prop /-- Extract a value from a partial value given a proof of `Dom` -/ get : Dom → α namespace Part variable {α : Type*} {β : Type*} {γ : Type*} /-- Convert a `Part α` with a decidable domain to an option -/ def toOption (o : Part α) [Decidable o.Dom] : Option α := if h : Dom o then some (o.get h) else none @[simp] lemma toOption_isSome (o : Part α) [Decidable o.Dom] : o.toOption.isSome ↔ o.Dom := by by_cases h : o.Dom <;> simp [h, toOption] @[simp] lemma toOption_eq_none (o : Part α) [Decidable o.Dom] : o.toOption = none ↔ ¬o.Dom := by by_cases h : o.Dom <;> simp [h, toOption] /-- `Part` extensionality -/ theorem ext' : ∀ {o p : Part α}, (o.Dom ↔ p.Dom) → (∀ h₁ h₂, o.get h₁ = p.get h₂) → o = p | ⟨od, o⟩, ⟨pd, p⟩, H1, H2 => by have t : od = pd := propext H1 cases t; rw [show o = p from funext fun p => H2 p p] /-- `Part` eta expansion -/ @[simp] theorem eta : ∀ o : Part α, (⟨o.Dom, fun h => o.get h⟩ : Part α) = o | ⟨_, _⟩ => rfl /-- `a ∈ o` means that `o` is defined and equal to `a` -/ protected def Mem (o : Part α) (a : α) : Prop := ∃ h, o.get h = a instance : Membership α (Part α) := ⟨Part.Mem⟩ theorem mem_eq (a : α) (o : Part α) : (a ∈ o) = ∃ h, o.get h = a := rfl theorem dom_iff_mem : ∀ {o : Part α}, o.Dom ↔ ∃ y, y ∈ o | ⟨_, f⟩ => ⟨fun h => ⟨f h, h, rfl⟩, fun ⟨_, h, rfl⟩ => h⟩ theorem get_mem {o : Part α} (h) : get o h ∈ o := ⟨_, rfl⟩ @[simp] theorem mem_mk_iff {p : Prop} {o : p → α} {a : α} : a ∈ Part.mk p o ↔ ∃ h, o h = a := Iff.rfl /-- `Part` extensionality -/ @[ext] theorem ext {o p : Part α} (H : ∀ a, a ∈ o ↔ a ∈ p) : o = p := (ext' ⟨fun h => ((H _).1 ⟨h, rfl⟩).fst, fun h => ((H _).2 ⟨h, rfl⟩).fst⟩) fun _ _ => ((H _).2 ⟨_, rfl⟩).snd /-- The `none` value in `Part` has a `False` domain and an empty function. -/ def none : Part α := ⟨False, False.rec⟩ instance : Inhabited (Part α) := ⟨none⟩ @[simp] theorem not_mem_none (a : α) : a ∉ @none α := fun h => h.fst /-- The `some a` value in `Part` has a `True` domain and the function returns `a`. -/ def some (a : α) : Part α := ⟨True, fun _ => a⟩ @[simp] theorem some_dom (a : α) : (some a).Dom := trivial theorem mem_unique : ∀ {a b : α} {o : Part α}, a ∈ o → b ∈ o → a = b | _, _, ⟨_, _⟩, ⟨_, rfl⟩, ⟨_, rfl⟩ => rfl theorem mem_right_unique : ∀ {a : α} {o p : Part α}, a ∈ o → a ∈ p → o = p | _, _, _, ⟨ho, _⟩, ⟨hp, _⟩ => ext' (iff_of_true ho hp) (by simp [*]) theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Part α → Prop) := fun _ _ _ => mem_unique theorem Mem.right_unique : Relator.RightUnique ((· ∈ ·) : α → Part α → Prop) := fun _ _ _ => mem_right_unique theorem get_eq_of_mem {o : Part α} {a} (h : a ∈ o) (h') : get o h' = a := mem_unique ⟨_, rfl⟩ h protected theorem subsingleton (o : Part α) : Set.Subsingleton { a | a ∈ o } := fun _ ha _ hb => mem_unique ha hb @[simp] theorem get_some {a : α} (ha : (some a).Dom) : get (some a) ha = a := rfl theorem mem_some (a : α) : a ∈ some a := ⟨trivial, rfl⟩ @[simp] theorem mem_some_iff {a b} : b ∈ (some a : Part α) ↔ b = a := ⟨fun ⟨_, e⟩ => e.symm, fun e => ⟨trivial, e.symm⟩⟩ theorem eq_some_iff {a : α} {o : Part α} : o = some a ↔ a ∈ o := ⟨fun e => e.symm ▸ mem_some _, fun ⟨h, e⟩ => e ▸ ext' (iff_true_intro h) fun _ _ => rfl⟩ theorem eq_none_iff {o : Part α} : o = none ↔ ∀ a, a ∉ o := ⟨fun e => e.symm ▸ not_mem_none, fun h => ext (by simpa)⟩ theorem eq_none_iff' {o : Part α} : o = none ↔ ¬o.Dom := ⟨fun e => e.symm ▸ id, fun h => eq_none_iff.2 fun _ h' => h h'.fst⟩ @[simp] theorem not_none_dom : ¬(none : Part α).Dom := id @[simp] theorem some_ne_none (x : α) : some x ≠ none := by intro h exact true_ne_false (congr_arg Dom h) @[simp] theorem none_ne_some (x : α) : none ≠ some x := (some_ne_none x).symm theorem ne_none_iff {o : Part α} : o ≠ none ↔ ∃ x, o = some x := by constructor · rw [Ne, eq_none_iff', not_not] exact fun h => ⟨o.get h, eq_some_iff.2 (get_mem h)⟩ · rintro ⟨x, rfl⟩ apply some_ne_none theorem eq_none_or_eq_some (o : Part α) : o = none ∨ ∃ x, o = some x := or_iff_not_imp_left.2 ne_none_iff.1 theorem some_injective : Injective (@Part.some α) := fun _ _ h => congr_fun (eq_of_heq (Part.mk.inj h).2) trivial @[simp] theorem some_inj {a b : α} : Part.some a = some b ↔ a = b := some_injective.eq_iff @[simp] theorem some_get {a : Part α} (ha : a.Dom) : Part.some (Part.get a ha) = a := Eq.symm (eq_some_iff.2 ⟨ha, rfl⟩) theorem get_eq_iff_eq_some {a : Part α} {ha : a.Dom} {b : α} : a.get ha = b ↔ a = some b := ⟨fun h => by simp [h.symm], fun h => by simp [h]⟩ theorem get_eq_get_of_eq (a : Part α) (ha : a.Dom) {b : Part α} (h : a = b) : a.get ha = b.get (h ▸ ha) := by congr theorem get_eq_iff_mem {o : Part α} {a : α} (h : o.Dom) : o.get h = a ↔ a ∈ o := ⟨fun H => ⟨h, H⟩, fun ⟨_, H⟩ => H⟩ theorem eq_get_iff_mem {o : Part α} {a : α} (h : o.Dom) : a = o.get h ↔ a ∈ o := eq_comm.trans (get_eq_iff_mem h) @[simp] theorem none_toOption [Decidable (@none α).Dom] : (none : Part α).toOption = Option.none := dif_neg id @[simp] theorem some_toOption (a : α) [Decidable (some a).Dom] : (some a).toOption = Option.some a := dif_pos trivial instance noneDecidable : Decidable (@none α).Dom := instDecidableFalse instance someDecidable (a : α) : Decidable (some a).Dom := instDecidableTrue /-- Retrieves the value of `a : Part α` if it exists, and return the provided default value otherwise. -/ def getOrElse (a : Part α) [Decidable a.Dom] (d : α) := if ha : a.Dom then a.get ha else d theorem getOrElse_of_dom (a : Part α) (h : a.Dom) [Decidable a.Dom] (d : α) : getOrElse a d = a.get h := dif_pos h theorem getOrElse_of_not_dom (a : Part α) (h : ¬a.Dom) [Decidable a.Dom] (d : α) : getOrElse a d = d := dif_neg h @[simp] theorem getOrElse_none (d : α) [Decidable (none : Part α).Dom] : getOrElse none d = d := none.getOrElse_of_not_dom not_none_dom d @[simp] theorem getOrElse_some (a : α) (d : α) [Decidable (some a).Dom] : getOrElse (some a) d = a := (some a).getOrElse_of_dom (some_dom a) d -- `simp`-normal form is `toOption_eq_some_iff`. theorem mem_toOption {o : Part α} [Decidable o.Dom] {a : α} : a ∈ toOption o ↔ a ∈ o := by unfold toOption by_cases h : o.Dom <;> simp [h] · exact ⟨fun h => ⟨_, h⟩, fun ⟨_, h⟩ => h⟩ · exact mt Exists.fst h @[simp] theorem toOption_eq_some_iff {o : Part α} [Decidable o.Dom] {a : α} : toOption o = Option.some a ↔ a ∈ o := by rw [← Option.mem_def, mem_toOption] protected theorem Dom.toOption {o : Part α} [Decidable o.Dom] (h : o.Dom) : o.toOption = o.get h := dif_pos h theorem toOption_eq_none_iff {a : Part α} [Decidable a.Dom] : a.toOption = Option.none ↔ ¬a.Dom := Ne.dite_eq_right_iff fun _ => Option.some_ne_none _ @[simp] theorem elim_toOption {α β : Type*} (a : Part α) [Decidable a.Dom] (b : β) (f : α → β) : a.toOption.elim b f = if h : a.Dom then f (a.get h) else b := by split_ifs with h · rw [h.toOption] rfl · rw [Part.toOption_eq_none_iff.2 h] rfl /-- Converts an `Option α` into a `Part α`. -/ @[coe] def ofOption : Option α → Part α | Option.none => none | Option.some a => some a @[simp] theorem mem_ofOption {a : α} : ∀ {o : Option α}, a ∈ ofOption o ↔ a ∈ o | Option.none => ⟨fun h => h.fst.elim, fun h => Option.noConfusion h⟩ | Option.some _ => ⟨fun h => congr_arg Option.some h.snd, fun h => ⟨trivial, Option.some.inj h⟩⟩ @[simp] theorem ofOption_dom {α} : ∀ o : Option α, (ofOption o).Dom ↔ o.isSome | Option.none => by simp [ofOption, none] | Option.some a => by simp [ofOption] theorem ofOption_eq_get {α} (o : Option α) : ofOption o = ⟨_, @Option.get _ o⟩ := Part.ext' (ofOption_dom o) fun h₁ h₂ => by cases o · simp at h₂ · rfl instance : Coe (Option α) (Part α) := ⟨ofOption⟩ theorem mem_coe {a : α} {o : Option α} : a ∈ (o : Part α) ↔ a ∈ o := mem_ofOption @[simp] theorem coe_none : (@Option.none α : Part α) = none := rfl @[simp] theorem coe_some (a : α) : (Option.some a : Part α) = some a := rfl @[elab_as_elim] protected theorem induction_on {P : Part α → Prop} (a : Part α) (hnone : P none) (hsome : ∀ a : α, P (some a)) : P a := (Classical.em a.Dom).elim (fun h => Part.some_get h ▸ hsome _) fun h => (eq_none_iff'.2 h).symm ▸ hnone instance ofOptionDecidable : ∀ o : Option α, Decidable (ofOption o).Dom | Option.none => Part.noneDecidable | Option.some a => Part.someDecidable a @[simp] theorem to_ofOption (o : Option α) : toOption (ofOption o) = o := by cases o <;> rfl @[simp] theorem of_toOption (o : Part α) [Decidable o.Dom] : ofOption (toOption o) = o := ext fun _ => mem_ofOption.trans mem_toOption /-- `Part α` is (classically) equivalent to `Option α`. -/ noncomputable def equivOption : Part α ≃ Option α := haveI := Classical.dec ⟨fun o => toOption o, ofOption, fun o => of_toOption o, fun o => Eq.trans (by dsimp; congr) (to_ofOption o)⟩ /-- We give `Part α` the order where everything is greater than `none`. -/ instance : PartialOrder (Part α) where le x y := ∀ i, i ∈ x → i ∈ y le_refl _ _ := id le_trans _ _ _ f g _ := g _ ∘ f _ le_antisymm _ _ f g := Part.ext fun _ => ⟨f _, g _⟩ instance : OrderBot (Part α) where bot := none bot_le := by rintro x _ ⟨⟨_⟩, _⟩ theorem le_total_of_le_of_le {x y : Part α} (z : Part α) (hx : x ≤ z) (hy : y ≤ z) : x ≤ y ∨ y ≤ x := by rcases Part.eq_none_or_eq_some x with (h | ⟨b, h₀⟩) · rw [h] left apply OrderBot.bot_le _ right; intro b' h₁ rw [Part.eq_some_iff] at h₀ have hx := hx _ h₀; have hy := hy _ h₁ have hx := Part.mem_unique hx hy; subst hx exact h₀ /-- `assert p f` is a bind-like operation which appends an additional condition `p` to the domain and uses `f` to produce the value. -/ def assert (p : Prop) (f : p → Part α) : Part α := ⟨∃ h : p, (f h).Dom, fun ha => (f ha.fst).get ha.snd⟩ /-- The bind operation has value `g (f.get)`, and is defined when all the parts are defined. -/ protected def bind (f : Part α) (g : α → Part β) : Part β := assert (Dom f) fun b => g (f.get b) /-- The map operation for `Part` just maps the value and maintains the same domain. -/ @[simps] def map (f : α → β) (o : Part α) : Part β := ⟨o.Dom, f ∘ o.get⟩ theorem mem_map (f : α → β) {o : Part α} : ∀ {a}, a ∈ o → f a ∈ map f o | _, ⟨_, rfl⟩ => ⟨_, rfl⟩ @[simp] theorem mem_map_iff (f : α → β) {o : Part α} {b} : b ∈ map f o ↔ ∃ a ∈ o, f a = b := ⟨fun hb => match b, hb with | _, ⟨_, rfl⟩ => ⟨_, ⟨_, rfl⟩, rfl⟩, fun ⟨_, h₁, h₂⟩ => h₂ ▸ mem_map f h₁⟩ @[simp] theorem map_none (f : α → β) : map f none = none := eq_none_iff.2 fun a => by simp @[simp] theorem map_some (f : α → β) (a : α) : map f (some a) = some (f a) := eq_some_iff.2 <| mem_map f <| mem_some _ theorem mem_assert {p : Prop} {f : p → Part α} : ∀ {a} (h : p), a ∈ f h → a ∈ assert p f | _, x, ⟨h, rfl⟩ => ⟨⟨x, h⟩, rfl⟩ @[simp] theorem mem_assert_iff {p : Prop} {f : p → Part α} {a} : a ∈ assert p f ↔ ∃ h : p, a ∈ f h := ⟨fun ha => match a, ha with | _, ⟨_, rfl⟩ => ⟨_, ⟨_, rfl⟩⟩, fun ⟨_, h⟩ => mem_assert _ h⟩ theorem assert_pos {p : Prop} {f : p → Part α} (h : p) : assert p f = f h := by dsimp [assert] cases h' : f h simp only [h', mk.injEq, h, exists_prop_of_true, true_and] apply Function.hfunext · simp only [h, h', exists_prop_of_true] · simp theorem assert_neg {p : Prop} {f : p → Part α} (h : ¬p) : assert p f = none := by dsimp [assert, none]; congr · simp only [h, not_false_iff, exists_prop_of_false] · apply Function.hfunext · simp only [h, not_false_iff, exists_prop_of_false] simp at * theorem mem_bind {f : Part α} {g : α → Part β} : ∀ {a b}, a ∈ f → b ∈ g a → b ∈ f.bind g | _, _, ⟨h, rfl⟩, ⟨h₂, rfl⟩ => ⟨⟨h, h₂⟩, rfl⟩ @[simp] theorem mem_bind_iff {f : Part α} {g : α → Part β} {b} : b ∈ f.bind g ↔ ∃ a ∈ f, b ∈ g a := ⟨fun hb => match b, hb with | _, ⟨⟨_, _⟩, rfl⟩ => ⟨_, ⟨_, rfl⟩, ⟨_, rfl⟩⟩, fun ⟨_, h₁, h₂⟩ => mem_bind h₁ h₂⟩ protected theorem Dom.bind {o : Part α} (h : o.Dom) (f : α → Part β) : o.bind f = f (o.get h) := by ext b simp only [Part.mem_bind_iff, exists_prop] refine ⟨?_, fun hb => ⟨o.get h, Part.get_mem _, hb⟩⟩ rintro ⟨a, ha, hb⟩ rwa [Part.get_eq_of_mem ha] theorem Dom.of_bind {f : α → Part β} {a : Part α} (h : (a.bind f).Dom) : a.Dom := h.1 @[simp] theorem bind_none (f : α → Part β) : none.bind f = none := eq_none_iff.2 fun a => by simp @[simp] theorem bind_some (a : α) (f : α → Part β) : (some a).bind f = f a := ext <| by simp theorem bind_of_mem {o : Part α} {a : α} (h : a ∈ o) (f : α → Part β) : o.bind f = f a := by rw [eq_some_iff.2 h, bind_some] theorem bind_some_eq_map (f : α → β) (x : Part α) : x.bind (fun y => some (f y)) = map f x := ext <| by simp [eq_comm] theorem bind_toOption (f : α → Part β) (o : Part α) [Decidable o.Dom] [∀ a, Decidable (f a).Dom] [Decidable (o.bind f).Dom] : (o.bind f).toOption = o.toOption.elim Option.none fun a => (f a).toOption := by by_cases h : o.Dom · simp_rw [h.toOption, h.bind] rfl · rw [Part.toOption_eq_none_iff.2 h] exact Part.toOption_eq_none_iff.2 fun ho => h ho.of_bind theorem bind_assoc {γ} (f : Part α) (g : α → Part β) (k : β → Part γ) : (f.bind g).bind k = f.bind fun x => (g x).bind k := ext fun a => by simp only [mem_bind_iff] exact ⟨fun ⟨_, ⟨_, h₁, h₂⟩, h₃⟩ => ⟨_, h₁, _, h₂, h₃⟩, fun ⟨_, h₁, _, h₂, h₃⟩ => ⟨_, ⟨_, h₁, h₂⟩, h₃⟩⟩ @[simp] theorem bind_map {γ} (f : α → β) (x) (g : β → Part γ) : (map f x).bind g = x.bind fun y => g (f y) := by rw [← bind_some_eq_map, bind_assoc]; simp @[simp] theorem map_bind {γ} (f : α → Part β) (x : Part α) (g : β → γ) : map g (x.bind f) = x.bind fun y => map g (f y) := by rw [← bind_some_eq_map, bind_assoc]; simp [bind_some_eq_map] theorem map_map (g : β → γ) (f : α → β) (o : Part α) : map g (map f o) = map (g ∘ f) o := by simp [map, Function.comp_assoc] instance : Monad Part where pure := @some map := @map bind := @Part.bind instance : LawfulMonad Part where bind_pure_comp := @bind_some_eq_map id_map f := by cases f; rfl pure_bind := @bind_some bind_assoc := @bind_assoc map_const := by simp [Functor.mapConst, Functor.map] --Porting TODO : In Lean3 these were automatic by a tactic seqLeft_eq x y := ext' (by simp [SeqLeft.seqLeft, Part.bind, assert, Seq.seq, const, (· <$> ·), and_comm]) (fun _ _ => rfl) seqRight_eq x y := ext' (by simp [SeqRight.seqRight, Part.bind, assert, Seq.seq, const, (· <$> ·), and_comm]) (fun _ _ => rfl) pure_seq x y := ext' (by simp [Seq.seq, Part.bind, assert, (· <$> ·), pure]) (fun _ _ => rfl) bind_map x y := ext' (by simp [(· >>= ·), Part.bind, assert, Seq.seq, get, (· <$> ·)] ) (fun _ _ => rfl) theorem map_id' {f : α → α} (H : ∀ x : α, f x = x) (o) : map f o = o := by rw [show f = id from funext H]; exact id_map o @[simp] theorem bind_some_right (x : Part α) : x.bind some = x := by rw [bind_some_eq_map] simp [map_id'] @[simp] theorem pure_eq_some (a : α) : pure a = some a := rfl @[simp] theorem ret_eq_some (a : α) : (return a : Part α) = some a := rfl @[simp] theorem map_eq_map {α β} (f : α → β) (o : Part α) : f <$> o = map f o := rfl @[simp] theorem bind_eq_bind {α β} (f : Part α) (g : α → Part β) : f >>= g = f.bind g := rfl
Mathlib/Data/Part.lean
525
526
theorem bind_le {α} (x : Part α) (f : α → Part β) (y : Part β) : x >>= f ≤ y ↔ ∀ a, a ∈ x → f a ≤ y := by
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, 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)
Mathlib/SetTheory/Cardinal/Basic.lean
304
307
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
/- 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, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Integration import Mathlib.MeasureTheory.Function.L2Space /-! # Variance of random variables We define the variance of a real-valued random variable as `Var[X] = 𝔼[(X - 𝔼[X])^2]` (in the `ProbabilityTheory` locale). ## Main definitions * `ProbabilityTheory.evariance`: the variance of a real-valued random variable as an extended non-negative real. * `ProbabilityTheory.variance`: the variance of a real-valued random variable as a real number. ## Main results * `ProbabilityTheory.variance_le_expectation_sq`: the inequality `Var[X] ≤ 𝔼[X^2]`. * `ProbabilityTheory.meas_ge_le_variance_div_sq`: Chebyshev's inequality, i.e., `ℙ {ω | c ≤ |X ω - 𝔼[X]|} ≤ ENNReal.ofReal (Var[X] / c ^ 2)`. * `ProbabilityTheory.meas_ge_le_evariance_div_sq`: Chebyshev's inequality formulated with `evariance` without requiring the random variables to be L². * `ProbabilityTheory.IndepFun.variance_add`: the variance of the sum of two independent random variables is the sum of the variances. * `ProbabilityTheory.IndepFun.variance_sum`: the variance of a finite sum of pairwise independent random variables is the sum of the variances. * `ProbabilityTheory.variance_le_sub_mul_sub`: the variance of a random variable `X` satisfying `a ≤ X ≤ b` almost everywhere is at most `(b - 𝔼 X) * (𝔼 X - a)`. * `ProbabilityTheory.variance_le_sq_of_bounded`: the variance of a random variable `X` satisfying `a ≤ X ≤ b` almost everywhere is at most`((b - a) / 2) ^ 2`. -/ open MeasureTheory Filter Finset noncomputable section open scoped MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} variable (X μ) in -- Porting note: Consider if `evariance` or `eVariance` is better. Also, -- consider `eVariationOn` in `Mathlib.Analysis.BoundedVariation`. /-- The `ℝ≥0∞`-valued variance of a real-valued random variable defined as the Lebesgue integral of `‖X - 𝔼[X]‖^2`. -/ def evariance : ℝ≥0∞ := ∫⁻ ω, ‖X ω - μ[X]‖ₑ ^ 2 ∂μ variable (X μ) in /-- The `ℝ`-valued variance of a real-valued random variable defined by applying `ENNReal.toReal` to `evariance`. -/ def variance : ℝ := (evariance X μ).toReal /-- The `ℝ≥0∞`-valued variance of the real-valued random variable `X` according to the measure `μ`. This is defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/ scoped notation "eVar[" X "; " μ "]" => ProbabilityTheory.evariance X μ /-- The `ℝ≥0∞`-valued variance of the real-valued random variable `X` according to the volume measure. This is defined as the Lebesgue integral of `(X - 𝔼[X])^2`. -/ scoped notation "eVar[" X "]" => eVar[X; MeasureTheory.MeasureSpace.volume] /-- The `ℝ`-valued variance of the real-valued random variable `X` according to the measure `μ`. It is set to `0` if `X` has infinite variance. -/ scoped notation "Var[" X "; " μ "]" => ProbabilityTheory.variance X μ /-- The `ℝ`-valued variance of the real-valued random variable `X` according to the volume measure. It is set to `0` if `X` has infinite variance. -/ scoped notation "Var[" X "]" => Var[X; MeasureTheory.MeasureSpace.volume] theorem evariance_lt_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ < ∞ := by have := ENNReal.pow_lt_top (hX.sub <| memLp_const <| μ[X]).2 (n := 2) rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top, ← ENNReal.rpow_two] at this simp only [ENNReal.toReal_ofNat, Pi.sub_apply, ENNReal.toReal_one, one_div] at this rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this simp_rw [ENNReal.rpow_two] at this exact this lemma evariance_ne_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ ≠ ∞ := (evariance_lt_top hX).ne theorem evariance_eq_top [IsFiniteMeasure μ] (hXm : AEStronglyMeasurable X μ) (hX : ¬MemLp X 2 μ) : evariance X μ = ∞ := by by_contra h rw [← Ne, ← lt_top_iff_ne_top] at h have : MemLp (fun ω => X ω - μ[X]) 2 μ := by refine ⟨hXm.sub aestronglyMeasurable_const, ?_⟩ rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top] simp only [ENNReal.toReal_ofNat, ENNReal.toReal_one, ENNReal.rpow_two, Ne] exact ENNReal.rpow_lt_top_of_nonneg (by linarith) h.ne refine hX ?_ convert this.add (memLp_const μ[X]) ext ω rw [Pi.add_apply, sub_add_cancel] theorem evariance_lt_top_iff_memLp [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) : evariance X μ < ∞ ↔ MemLp X 2 μ where mp := by contrapose!; rw [top_le_iff]; exact evariance_eq_top hX mpr := evariance_lt_top @[deprecated (since := "2025-02-21")] alias evariance_lt_top_iff_memℒp := evariance_lt_top_iff_memLp lemma evariance_eq_top_iff [IsFiniteMeasure μ] (hX : AEStronglyMeasurable X μ) : evariance X μ = ∞ ↔ ¬ MemLp X 2 μ := by simp [← evariance_lt_top_iff_memLp hX] theorem ofReal_variance [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : .ofReal (variance X μ) = evariance X μ := by rw [variance, ENNReal.ofReal_toReal] exact evariance_ne_top hX protected alias _root_.MeasureTheory.MemLp.evariance_lt_top := evariance_lt_top protected alias _root_.MeasureTheory.MemLp.evariance_ne_top := evariance_ne_top protected alias _root_.MeasureTheory.MemLp.ofReal_variance_eq := ofReal_variance @[deprecated (since := "2025-02-21")] protected alias _root_.MeasureTheory.Memℒp.evariance_lt_top := evariance_lt_top @[deprecated (since := "2025-02-21")] protected alias _root_.MeasureTheory.Memℒp.evariance_ne_top := evariance_ne_top @[deprecated (since := "2025-02-21")] protected alias _root_.MeasureTheory.Memℒp.ofReal_variance_eq := ofReal_variance variable (X μ) in theorem evariance_eq_lintegral_ofReal : evariance X μ = ∫⁻ ω, ENNReal.ofReal ((X ω - μ[X]) ^ 2) ∂μ := by simp [evariance, ← enorm_pow, Real.enorm_of_nonneg (sq_nonneg _)] lemma variance_eq_integral (hX : AEMeasurable X μ) : Var[X; μ] = ∫ ω, (X ω - μ[X]) ^ 2 ∂μ := by simp [variance, evariance, toReal_enorm, ← integral_toReal ((hX.sub_const _).enorm.pow_const _) <| .of_forall fun _ ↦ ENNReal.pow_lt_top enorm_lt_top] lemma variance_of_integral_eq_zero (hX : AEMeasurable X μ) (hXint : μ[X] = 0) : variance X μ = ∫ ω, X ω ^ 2 ∂μ := by simp [variance_eq_integral hX, hXint] @[deprecated (since := "2025-01-23")] alias _root_.MeasureTheory.Memℒp.variance_eq := variance_eq_integral @[deprecated (since := "2025-01-23")] alias _root_.MeasureTheory.Memℒp.variance_eq_of_integral_eq_zero := variance_of_integral_eq_zero @[simp] theorem evariance_zero : evariance 0 μ = 0 := by simp [evariance] theorem evariance_eq_zero_iff (hX : AEMeasurable X μ) : evariance X μ = 0 ↔ X =ᵐ[μ] fun _ => μ[X] := by simp [evariance, lintegral_eq_zero_iff' ((hX.sub_const _).enorm.pow_const _), EventuallyEq, sub_eq_zero] theorem evariance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : evariance (fun ω => c * X ω) μ = ENNReal.ofReal (c ^ 2) * evariance X μ := by rw [evariance, evariance, ← lintegral_const_mul' _ _ ENNReal.ofReal_lt_top.ne] congr with ω rw [integral_const_mul, ← mul_sub, enorm_mul, mul_pow, ← enorm_pow, Real.enorm_of_nonneg (sq_nonneg _)] @[simp] theorem variance_zero (μ : Measure Ω) : variance 0 μ = 0 := by simp only [variance, evariance_zero, ENNReal.toReal_zero] theorem variance_nonneg (X : Ω → ℝ) (μ : Measure Ω) : 0 ≤ variance X μ := ENNReal.toReal_nonneg theorem variance_mul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : variance (fun ω => c * X ω) μ = c ^ 2 * variance X μ := by rw [variance, evariance_mul, ENNReal.toReal_mul, ENNReal.toReal_ofReal (sq_nonneg _)] rfl theorem variance_smul (c : ℝ) (X : Ω → ℝ) (μ : Measure Ω) : variance (c • X) μ = c ^ 2 * variance X μ := variance_mul c X μ theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ) (μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by convert variance_smul (algebraMap A ℝ c) X μ using 1 · congr; simp only [algebraMap_smul] · simp only [Algebra.smul_def, map_pow] theorem variance_def' [IsProbabilityMeasure μ] {X : Ω → ℝ} (hX : MemLp X 2 μ) : variance X μ = μ[X ^ 2] - μ[X] ^ 2 := by simp only [variance_eq_integral hX.aestronglyMeasurable.aemeasurable, sub_sq'] rw [integral_sub, integral_add]; rotate_left · exact hX.integrable_sq · apply integrable_const · apply hX.integrable_sq.add apply integrable_const · exact ((hX.integrable one_le_two).const_mul 2).mul_const' _ simp only [integral_const, measureReal_univ_eq_one, smul_eq_mul, one_mul, integral_mul_const, integral_const_mul, Pi.pow_apply] ring
Mathlib/Probability/Variance.lean
202
212
theorem variance_le_expectation_sq [IsProbabilityMeasure μ] {X : Ω → ℝ} (hm : AEStronglyMeasurable X μ) : variance X μ ≤ μ[X ^ 2] := by
by_cases hX : MemLp X 2 μ · rw [variance_def' hX] simp only [sq_nonneg, sub_le_self_iff] rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae] · by_cases hint : Integrable X μ; swap · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero] exact le_rfl · rw [integral_undef] · exact integral_nonneg fun a => sq_nonneg _
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Polynomial.Inductions import Mathlib.RingTheory.Localization.Away.Basic /-! # Laurent polynomials We introduce Laurent polynomials over a semiring `R`. Mathematically, they are expressions of the form $$ \sum_{i \in \mathbb{Z}} a_i T ^ i $$ where the sum extends over a finite subset of `ℤ`. Thus, negative exponents are allowed. The coefficients come from the semiring `R` and the variable `T` commutes with everything. Since we are going to convert back and forth between polynomials and Laurent polynomials, we decided to maintain some distinction by using the symbol `T`, rather than `X`, as the variable for Laurent polynomials. ## Notation The symbol `R[T;T⁻¹]` stands for `LaurentPolynomial R`. We also define * `C : R →+* R[T;T⁻¹]` the inclusion of constant polynomials, analogous to the one for `R[X]`; * `T : ℤ → R[T;T⁻¹]` the sequence of powers of the variable `T`. ## Implementation notes We define Laurent polynomials as `AddMonoidAlgebra R ℤ`. Thus, they are essentially `Finsupp`s `ℤ →₀ R`. This choice differs from the current irreducible design of `Polynomial`, that instead shields away the implementation via `Finsupp`s. It is closer to the original definition of polynomials. As a consequence, `LaurentPolynomial` plays well with polynomials, but there is a little roughness in establishing the API, since the `Finsupp` implementation of `R[X]` is well-shielded. Unlike the case of polynomials, I felt that the exponent notation was not too easy to use, as only natural exponents would be allowed. Moreover, in the end, it seems likely that we should aim to perform computations on exponents in `ℤ` anyway and separating this via the symbol `T` seems convenient. I made a *heavy* use of `simp` lemmas, aiming to bring Laurent polynomials to the form `C a * T n`. Any comments or suggestions for improvements is greatly appreciated! ## Future work Lots is missing! -- (Riccardo) add inclusion into Laurent series. -- A "better" definition of `trunc` would be as an `R`-linear map. This works: -- ``` -- def trunc : R[T;T⁻¹] →[R] R[X] := -- refine (?_ : R[ℕ] →[R] R[X]).comp ?_ -- · exact ⟨(toFinsuppIso R).symm, by simp⟩ -- · refine ⟨fun r ↦ comapDomain _ r -- (Set.injOn_of_injective (fun _ _ ↦ Int.ofNat.inj) _), ?_⟩ -- exact fun r f ↦ comapDomain_smul .. -- ``` -- but it would make sense to bundle the maps better, for a smoother user experience. -- I (DT) did not have the strength to embark on this (possibly short!) journey, after getting to -- this stage of the Laurent process! -- This would likely involve adding a `comapDomain` analogue of -- `AddMonoidAlgebra.mapDomainAlgHom` and an `R`-linear version of -- `Polynomial.toFinsuppIso`. -- Add `degree, intDegree, intTrailingDegree, leadingCoeff, trailingCoeff,...`. -/ open Polynomial Function AddMonoidAlgebra Finsupp noncomputable section variable {R S : Type*} /-- The semiring of Laurent polynomials with coefficients in the semiring `R`. We denote it by `R[T;T⁻¹]`. The ring homomorphism `C : R →+* R[T;T⁻¹]` includes `R` as the constant polynomials. -/ abbrev LaurentPolynomial (R : Type*) [Semiring R] := AddMonoidAlgebra R ℤ @[nolint docBlame] scoped[LaurentPolynomial] notation:9000 R "[T;T⁻¹]" => LaurentPolynomial R open LaurentPolynomial @[ext] theorem LaurentPolynomial.ext [Semiring R] {p q : R[T;T⁻¹]} (h : ∀ a, p a = q a) : p = q := Finsupp.ext h /-- The ring homomorphism, taking a polynomial with coefficients in `R` to a Laurent polynomial with coefficients in `R`. -/ def Polynomial.toLaurent [Semiring R] : R[X] →+* R[T;T⁻¹] := (mapDomainRingHom R Int.ofNatHom).comp (toFinsuppIso R) /-- This is not a simp lemma, as it is usually preferable to use the lemmas about `C` and `X` instead. -/ theorem Polynomial.toLaurent_apply [Semiring R] (p : R[X]) : toLaurent p = p.toFinsupp.mapDomain (↑) := rfl /-- The `R`-algebra map, taking a polynomial with coefficients in `R` to a Laurent polynomial with coefficients in `R`. -/ def Polynomial.toLaurentAlg [CommSemiring R] : R[X] →ₐ[R] R[T;T⁻¹] := (mapDomainAlgHom R R Int.ofNatHom).comp (toFinsuppIsoAlg R).toAlgHom @[simp] lemma Polynomial.coe_toLaurentAlg [CommSemiring R] : (toLaurentAlg : R[X] → R[T;T⁻¹]) = toLaurent := rfl theorem Polynomial.toLaurentAlg_apply [CommSemiring R] (f : R[X]) : toLaurentAlg f = toLaurent f := rfl namespace LaurentPolynomial section Semiring variable [Semiring R] theorem single_zero_one_eq_one : (Finsupp.single 0 1 : R[T;T⁻¹]) = (1 : R[T;T⁻¹]) := rfl /-! ### The functions `C` and `T`. -/ /-- The ring homomorphism `C`, including `R` into the ring of Laurent polynomials over `R` as the constant Laurent polynomials. -/ def C : R →+* R[T;T⁻¹] := singleZeroRingHom theorem algebraMap_apply {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (r : R) : algebraMap R (LaurentPolynomial A) r = C (algebraMap R A r) := rfl /-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[T;T⁻¹]`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebraMap` is not available.) -/ theorem C_eq_algebraMap {R : Type*} [CommSemiring R] (r : R) : C r = algebraMap R R[T;T⁻¹] r := rfl theorem single_eq_C (r : R) : Finsupp.single 0 r = C r := rfl @[simp] lemma C_apply (t : R) (n : ℤ) : C t n = if n = 0 then t else 0 := by rw [← single_eq_C, Finsupp.single_apply]; aesop /-- The function `n ↦ T ^ n`, implemented as a sequence `ℤ → R[T;T⁻¹]`. Using directly `T ^ n` does not work, since we want the exponents to be of Type `ℤ` and there is no `ℤ`-power defined on `R[T;T⁻¹]`. Using that `T` is a unit introduces extra coercions. For these reasons, the definition of `T` is as a sequence. -/ def T (n : ℤ) : R[T;T⁻¹] := Finsupp.single n 1 @[simp] lemma T_apply (m n : ℤ) : (T n : R[T;T⁻¹]) m = if n = m then 1 else 0 := Finsupp.single_apply @[simp] theorem T_zero : (T 0 : R[T;T⁻¹]) = 1 := rfl theorem T_add (m n : ℤ) : (T (m + n) : R[T;T⁻¹]) = T m * T n := by simp [T, single_mul_single] theorem T_sub (m n : ℤ) : (T (m - n) : R[T;T⁻¹]) = T m * T (-n) := by rw [← T_add, sub_eq_add_neg] @[simp] theorem T_pow (m : ℤ) (n : ℕ) : (T m ^ n : R[T;T⁻¹]) = T (n * m) := by rw [T, T, single_pow n, one_pow, nsmul_eq_mul] /-- The `simp` version of `mul_assoc`, in the presence of `T`'s. -/ @[simp] theorem mul_T_assoc (f : R[T;T⁻¹]) (m n : ℤ) : f * T m * T n = f * T (m + n) := by simp [← T_add, mul_assoc] @[simp] theorem single_eq_C_mul_T (r : R) (n : ℤ) : (Finsupp.single n r : R[T;T⁻¹]) = (C r * T n : R[T;T⁻¹]) := by simp [C, T, single_mul_single] -- This lemma locks in the right changes and is what Lean proved directly. -- The actual `simp`-normal form of a Laurent monomial is `C a * T n`, whenever it can be reached. @[simp] theorem _root_.Polynomial.toLaurent_C_mul_T (n : ℕ) (r : R) : (toLaurent (Polynomial.monomial n r) : R[T;T⁻¹]) = C r * T n := show Finsupp.mapDomain (↑) (monomial n r).toFinsupp = (C r * T n : R[T;T⁻¹]) by rw [toFinsupp_monomial, Finsupp.mapDomain_single, single_eq_C_mul_T] @[simp] theorem _root_.Polynomial.toLaurent_C (r : R) : toLaurent (Polynomial.C r) = C r := by convert Polynomial.toLaurent_C_mul_T 0 r simp only [Int.ofNat_zero, T_zero, mul_one] @[simp] theorem _root_.Polynomial.toLaurent_comp_C : toLaurent (R := R) ∘ Polynomial.C = C := funext Polynomial.toLaurent_C @[simp] theorem _root_.Polynomial.toLaurent_X : (toLaurent Polynomial.X : R[T;T⁻¹]) = T 1 := by have : (Polynomial.X : R[X]) = monomial 1 1 := by simp [← C_mul_X_pow_eq_monomial] simp [this, Polynomial.toLaurent_C_mul_T] @[simp] theorem _root_.Polynomial.toLaurent_one : (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) 1 = 1 := map_one Polynomial.toLaurent @[simp] theorem _root_.Polynomial.toLaurent_C_mul_eq (r : R) (f : R[X]) : toLaurent (Polynomial.C r * f) = C r * toLaurent f := by simp only [map_mul, Polynomial.toLaurent_C] @[simp] theorem _root_.Polynomial.toLaurent_X_pow (n : ℕ) : toLaurent (X ^ n : R[X]) = T n := by simp only [map_pow, Polynomial.toLaurent_X, T_pow, mul_one] theorem _root_.Polynomial.toLaurent_C_mul_X_pow (n : ℕ) (r : R) : toLaurent (Polynomial.C r * X ^ n) = C r * T n := by simp only [map_mul, Polynomial.toLaurent_C, Polynomial.toLaurent_X_pow] instance invertibleT (n : ℤ) : Invertible (T n : R[T;T⁻¹]) where invOf := T (-n) invOf_mul_self := by rw [← T_add, neg_add_cancel, T_zero] mul_invOf_self := by rw [← T_add, add_neg_cancel, T_zero] @[simp] theorem invOf_T (n : ℤ) : ⅟ (T n : R[T;T⁻¹]) = T (-n) := rfl theorem isUnit_T (n : ℤ) : IsUnit (T n : R[T;T⁻¹]) := isUnit_of_invertible _ @[elab_as_elim] protected theorem induction_on {M : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (h_C : ∀ a, M (C a)) (h_add : ∀ {p q}, M p → M q → M (p + q)) (h_C_mul_T : ∀ (n : ℕ) (a : R), M (C a * T n) → M (C a * T (n + 1))) (h_C_mul_T_Z : ∀ (n : ℕ) (a : R), M (C a * T (-n)) → M (C a * T (-n - 1))) : M p := by have A : ∀ {n : ℤ} {a : R}, M (C a * T n) := by intro n a refine Int.induction_on n ?_ ?_ ?_ · simpa only [T_zero, mul_one] using h_C a · exact fun m => h_C_mul_T m a · exact fun m => h_C_mul_T_Z m a have B : ∀ s : Finset ℤ, M (s.sum fun n : ℤ => C (p.toFun n) * T n) := by apply Finset.induction · convert h_C 0 simp only [Finset.sum_empty, map_zero] · intro n s ns ih rw [Finset.sum_insert ns] exact h_add A ih convert B p.support ext a simp_rw [← single_eq_C_mul_T] -- Porting note: did not make progress in `simp_rw` rw [Finset.sum_apply'] simp_rw [Finsupp.single_apply, Finset.sum_ite_eq'] split_ifs with h · rfl · exact Finsupp.not_mem_support_iff.mp h /-- To prove something about Laurent polynomials, it suffices to show that * the condition is closed under taking sums, and * it holds for monomials. -/ @[elab_as_elim] protected theorem induction_on' {motive : R[T;T⁻¹] → Prop} (p : R[T;T⁻¹]) (add : ∀ p q, motive p → motive q → motive (p + q)) (C_mul_T : ∀ (n : ℤ) (a : R), motive (C a * T n)) : motive p := by refine p.induction_on (fun a => ?_) (fun {p q} => add p q) ?_ ?_ <;> try exact fun n f _ => C_mul_T _ f convert C_mul_T 0 a exact (mul_one _).symm theorem commute_T (n : ℤ) (f : R[T;T⁻¹]) : Commute (T n) f := f.induction_on' (fun _ _ Tp Tq => Commute.add_right Tp Tq) fun m a => show T n * _ = _ by rw [T, T, ← single_eq_C, single_mul_single, single_mul_single, single_mul_single] simp [add_comm] @[simp] theorem T_mul (n : ℤ) (f : R[T;T⁻¹]) : T n * f = f * T n := (commute_T n f).eq theorem smul_eq_C_mul (r : R) (f : R[T;T⁻¹]) : r • f = C r * f := by induction f using LaurentPolynomial.induction_on' with | add _ _ hp hq => rw [smul_add, mul_add, hp, hq] | C_mul_T n s => rw [← mul_assoc, ← smul_mul_assoc, mul_left_inj_of_invertible, ← map_mul, ← single_eq_C, Finsupp.smul_single', single_eq_C] /-- `trunc : R[T;T⁻¹] →+ R[X]` maps a Laurent polynomial `f` to the polynomial whose terms of nonnegative degree coincide with the ones of `f`. The terms of negative degree of `f` "vanish". `trunc` is a left-inverse to `Polynomial.toLaurent`. -/ def trunc : R[T;T⁻¹] →+ R[X] := (toFinsuppIso R).symm.toAddMonoidHom.comp <| comapDomain.addMonoidHom fun _ _ => Int.ofNat.inj @[simp] theorem trunc_C_mul_T (n : ℤ) (r : R) : trunc (C r * T n) = ite (0 ≤ n) (monomial n.toNat r) 0 := by apply (toFinsuppIso R).injective rw [← single_eq_C_mul_T, trunc, AddMonoidHom.coe_comp, Function.comp_apply] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): was `rw` erw [comapDomain.addMonoidHom_apply Int.ofNat_injective] rw [toFinsuppIso_apply] split_ifs with n0 · rw [toFinsupp_monomial] lift n to ℕ using n0 apply comapDomain_single · rw [toFinsupp_inj] ext a have : n ≠ a := by omega simp only [coeff_ofFinsupp, comapDomain_apply, Int.ofNat_eq_coe, coeff_zero, single_eq_of_ne this] @[simp] theorem leftInverse_trunc_toLaurent : Function.LeftInverse (trunc : R[T;T⁻¹] → R[X]) Polynomial.toLaurent := by refine fun f => f.induction_on' ?_ ?_ · intro f g hf hg simp only [hf, hg, map_add] · intro n r simp only [Polynomial.toLaurent_C_mul_T, trunc_C_mul_T, Int.natCast_nonneg, Int.toNat_natCast, if_true] @[simp] theorem _root_.Polynomial.trunc_toLaurent (f : R[X]) : trunc (toLaurent f) = f := leftInverse_trunc_toLaurent _ theorem _root_.Polynomial.toLaurent_injective : Function.Injective (Polynomial.toLaurent : R[X] → R[T;T⁻¹]) := leftInverse_trunc_toLaurent.injective @[simp] theorem _root_.Polynomial.toLaurent_inj (f g : R[X]) : toLaurent f = toLaurent g ↔ f = g := ⟨fun h => Polynomial.toLaurent_injective h, congr_arg _⟩ theorem _root_.Polynomial.toLaurent_ne_zero {f : R[X]} : toLaurent f ≠ 0 ↔ f ≠ 0 := map_ne_zero_iff _ Polynomial.toLaurent_injective @[simp] theorem _root_.Polynomial.toLaurent_eq_zero {f : R[X]} : toLaurent f = 0 ↔ f = 0 := map_eq_zero_iff _ Polynomial.toLaurent_injective theorem exists_T_pow (f : R[T;T⁻¹]) : ∃ (n : ℕ) (f' : R[X]), toLaurent f' = f * T n := by refine f.induction_on' ?_ fun n a => ?_ <;> clear f · rintro f g ⟨m, fn, hf⟩ ⟨n, gn, hg⟩ refine ⟨m + n, fn * X ^ n + gn * X ^ m, ?_⟩ simp only [hf, hg, add_mul, add_comm (n : ℤ), map_add, map_mul, Polynomial.toLaurent_X_pow, mul_T_assoc, Int.natCast_add] · rcases n with n | n · exact ⟨0, Polynomial.C a * X ^ n, by simp⟩ · refine ⟨n + 1, Polynomial.C a, ?_⟩ simp only [Int.negSucc_eq, Polynomial.toLaurent_C, Int.natCast_succ, mul_T_assoc, neg_add_cancel, T_zero, mul_one] /-- This is a version of `exists_T_pow` stated as an induction principle. -/ @[elab_as_elim] theorem induction_on_mul_T {Q : R[T;T⁻¹] → Prop} (f : R[T;T⁻¹]) (Qf : ∀ {f : R[X]} {n : ℕ}, Q (toLaurent f * T (-n))) : Q f := by rcases f.exists_T_pow with ⟨n, f', hf⟩ rw [← mul_one f, ← T_zero, ← Nat.cast_zero, ← Nat.sub_self n, Nat.cast_sub rfl.le, T_sub, ← mul_assoc, ← hf] exact Qf /-- Suppose that `Q` is a statement about Laurent polynomials such that * `Q` is true on *ordinary* polynomials; * `Q (f * T)` implies `Q f`; it follow that `Q` is true on all Laurent polynomials. -/ theorem reduce_to_polynomial_of_mul_T (f : R[T;T⁻¹]) {Q : R[T;T⁻¹] → Prop} (Qf : ∀ f : R[X], Q (toLaurent f)) (QT : ∀ f, Q (f * T 1) → Q f) : Q f := by induction' f using LaurentPolynomial.induction_on_mul_T with f n induction n with | zero => simpa only [Nat.cast_zero, neg_zero, T_zero, mul_one] using Qf _ | succ n hn => convert QT _ _; simpa using hn section Support theorem support_C_mul_T (a : R) (n : ℤ) : Finsupp.support (C a * T n) ⊆ {n} := by rw [← single_eq_C_mul_T] exact support_single_subset theorem support_C_mul_T_of_ne_zero {a : R} (a0 : a ≠ 0) (n : ℤ) : Finsupp.support (C a * T n) = {n} := by rw [← single_eq_C_mul_T] exact support_single_ne_zero _ a0 /-- The support of a polynomial `f` is a finset in `ℕ`. The lemma `toLaurent_support f` shows that the support of `f.toLaurent` is the same finset, but viewed in `ℤ` under the natural inclusion `ℕ ↪ ℤ`. -/ theorem toLaurent_support (f : R[X]) : f.toLaurent.support = f.support.map Nat.castEmbedding := by generalize hd : f.support = s revert f refine Finset.induction_on s ?_ ?_ <;> clear s · intro f hf rw [Finset.map_empty, Finsupp.support_eq_empty, toLaurent_eq_zero] exact Polynomial.support_eq_empty.mp hf · intro a s as hf f fs have : (erase a f).toLaurent.support = s.map Nat.castEmbedding := by refine hf (f.erase a) ?_ simp only [fs, Finset.erase_eq_of_not_mem as, Polynomial.support_erase, Finset.erase_insert_eq_erase] rw [← monomial_add_erase f a, Finset.map_insert, ← this, map_add, Polynomial.toLaurent_C_mul_T, support_add_eq, Finset.insert_eq] · congr exact support_C_mul_T_of_ne_zero (Polynomial.mem_support_iff.mp (by simp [fs])) _ · rw [this] exact Disjoint.mono_left (support_C_mul_T _ _) (by simpa) end Support section Degrees /-- The degree of a Laurent polynomial takes values in `WithBot ℤ`. If `f : R[T;T⁻¹]` is a Laurent polynomial, then `f.degree` is the maximum of its support of `f`, or `⊥`, if `f = 0`. -/ def degree (f : R[T;T⁻¹]) : WithBot ℤ := f.support.max @[simp] theorem degree_zero : degree (0 : R[T;T⁻¹]) = ⊥ := rfl @[simp] theorem degree_eq_bot_iff {f : R[T;T⁻¹]} : f.degree = ⊥ ↔ f = 0 := by refine ⟨fun h => ?_, fun h => by rw [h, degree_zero]⟩ ext n simp only [coe_zero, Pi.zero_apply] simp_rw [degree, Finset.max_eq_sup_withBot, Finset.sup_eq_bot_iff, Finsupp.mem_support_iff, Ne, WithBot.coe_ne_bot, imp_false, not_not] at h exact h n section ExactDegrees @[simp] theorem degree_C_mul_T (n : ℤ) (a : R) (a0 : a ≠ 0) : degree (C a * T n) = n := by rw [degree, support_C_mul_T_of_ne_zero a0 n] exact Finset.max_singleton theorem degree_C_mul_T_ite [DecidableEq R] (n : ℤ) (a : R) : degree (C a * T n) = if a = 0 then ⊥ else ↑n := by split_ifs with h <;> simp only [h, map_zero, zero_mul, degree_zero, degree_C_mul_T, Ne, not_false_iff] @[simp] theorem degree_T [Nontrivial R] (n : ℤ) : (T n : R[T;T⁻¹]).degree = n := by rw [← one_mul (T n), ← map_one C] exact degree_C_mul_T n 1 (one_ne_zero : (1 : R) ≠ 0) theorem degree_C {a : R} (a0 : a ≠ 0) : (C a).degree = 0 := by rw [← mul_one (C a), ← T_zero] exact degree_C_mul_T 0 a a0 theorem degree_C_ite [DecidableEq R] (a : R) : (C a).degree = if a = 0 then ⊥ else 0 := by split_ifs with h <;> simp only [h, map_zero, degree_zero, degree_C, Ne, not_false_iff] end ExactDegrees section DegreeBounds theorem degree_C_mul_T_le (n : ℤ) (a : R) : degree (C a * T n) ≤ n := by by_cases a0 : a = 0 · simp only [a0, map_zero, zero_mul, degree_zero, bot_le] · exact (degree_C_mul_T n a a0).le theorem degree_T_le (n : ℤ) : (T n : R[T;T⁻¹]).degree ≤ n := (le_of_eq (by rw [map_one, one_mul])).trans (degree_C_mul_T_le n (1 : R)) theorem degree_C_le (a : R) : (C a).degree ≤ 0 := (le_of_eq (by rw [T_zero, mul_one])).trans (degree_C_mul_T_le 0 a) end DegreeBounds end Degrees instance : Module R[X] R[T;T⁻¹] := Module.compHom _ Polynomial.toLaurent instance (R : Type*) [Semiring R] : IsScalarTower R[X] R[X] R[T;T⁻¹] where smul_assoc x y z := by dsimp; simp_rw [MulAction.mul_smul] end Semiring section CommSemiring variable [CommSemiring R] {S : Type*} [CommSemiring S] (f : R →+* S) (x : Sˣ) instance algebraPolynomial (R : Type*) [CommSemiring R] : Algebra R[X] R[T;T⁻¹] where algebraMap := Polynomial.toLaurent commutes' := fun f l => by simp [mul_comm] smul_def' := fun _ _ => rfl theorem algebraMap_X_pow (n : ℕ) : algebraMap R[X] R[T;T⁻¹] (X ^ n) = T n := Polynomial.toLaurent_X_pow n @[simp] theorem algebraMap_eq_toLaurent (f : R[X]) : algebraMap R[X] R[T;T⁻¹] f = toLaurent f := rfl instance isLocalization : IsLocalization.Away (X : R[X]) R[T;T⁻¹] := { map_units' := fun ⟨t, ht⟩ => by obtain ⟨n, rfl⟩ := ht rw [algebraMap_eq_toLaurent, toLaurent_X_pow] exact isUnit_T ↑n surj' := fun f => by induction' f using LaurentPolynomial.induction_on_mul_T with f n have : X ^ n ∈ Submonoid.powers (X : R[X]) := ⟨n, rfl⟩ refine ⟨(f, ⟨_, this⟩), ?_⟩ simp only [algebraMap_eq_toLaurent, toLaurent_X_pow, mul_T_assoc, neg_add_cancel, T_zero, mul_one] exists_of_eq := fun {f g} => by rw [algebraMap_eq_toLaurent, algebraMap_eq_toLaurent, Polynomial.toLaurent_inj] rintro rfl exact ⟨1, rfl⟩ } theorem mk'_mul_T (p : R[X]) (n : ℕ) : IsLocalization.mk' R[T;T⁻¹] p (⟨X^n, n, rfl⟩ : Submonoid.powers (X : R[X])) * T n = toLaurent p := by rw [←toLaurent_X_pow, ←algebraMap_eq_toLaurent, IsLocalization.mk'_spec, algebraMap_eq_toLaurent] @[simp] theorem mk'_eq (p : R[X]) (n : ℕ) : IsLocalization.mk' R[T;T⁻¹] p (⟨X^n, n, rfl⟩ : Submonoid.powers (X : R[X])) = toLaurent p * T (-n) := by rw [←IsUnit.mul_left_inj (isUnit_T n), mul_T_assoc, neg_add_cancel, T_zero, mul_one] exact mk'_mul_T p n theorem mk'_one_X_pow (n : ℕ) : IsLocalization.mk' R[T;T⁻¹] 1 (⟨X^n, n, rfl⟩ : Submonoid.powers (X : R[X])) = T (-n) := by rw [mk'_eq 1 n, toLaurent_one, one_mul] @[simp] theorem mk'_one_X : IsLocalization.mk' R[T;T⁻¹] 1 (⟨X, 1, pow_one X⟩ : Submonoid.powers (X : R[X])) = T (-1) := by convert mk'_one_X_pow 1 exact (pow_one X).symm /-- Given a ring homomorphism `f : R →+* S` and a unit `x` in `S`, the induced homomorphism `R[T;T⁻¹] →+* S` sending `T` to `x` and `T⁻¹` to `x⁻¹`. -/ def eval₂ : R[T;T⁻¹] →+* S := IsLocalization.lift (M := Submonoid.powers (X : R[X])) (g := Polynomial.eval₂RingHom f x) <| by rintro ⟨y, n, rfl⟩ simpa only [coe_eval₂RingHom, eval₂_X_pow] using x.isUnit.pow n @[simp] theorem eval₂_toLaurent (p : R[X]) : eval₂ f x (toLaurent p) = Polynomial.eval₂ f x p := by unfold eval₂ rw [←algebraMap_eq_toLaurent, IsLocalization.lift_eq, coe_eval₂RingHom] theorem eval₂_T_n (n : ℕ) : eval₂ f x (T n) = x ^ n := by rw [←Polynomial.toLaurent_X_pow, eval₂_toLaurent, eval₂_X_pow] theorem eval₂_T_neg_n (n : ℕ) : eval₂ f x (T (-n)) = x⁻¹ ^ n := by rw [←mk'_one_X_pow] unfold eval₂ rw [IsLocalization.lift_mk'_spec, map_one, coe_eval₂RingHom, eval₂_X_pow, ←mul_pow, Units.mul_inv, one_pow] @[simp]
Mathlib/Algebra/Polynomial/Laurent.lean
559
560
theorem eval₂_T (n : ℤ) : eval₂ f x (T n) = (x ^ n).val := by
by_cases hn : 0 ≤ n
/- 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, Kim Morrison -/ import Mathlib.Data.List.Basic /-! # Lattice structure of lists This files prove basic properties about `List.disjoint`, `List.union`, `List.inter` and `List.bagInter`, which are defined in core Lean and `Data.List.Defs`. `l₁ ∪ l₂` is the list where all elements of `l₁` have been inserted in `l₂` in order. For example, `[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [1, 2, 4, 3, 3, 0]` `l₁ ∩ l₂` is the list of elements of `l₁` in order which are in `l₂`. For example, `[0, 0, 1, 2, 2, 3] ∪ [4, 3, 3, 0] = [0, 0, 3]` `List.bagInter l₁ l₂` is the list of elements that are in both `l₁` and `l₂`, counted with multiplicity and in the order they appear in `l₁`. As opposed to `List.inter`, `List.bagInter` copes well with multiplicity. For example, `bagInter [0, 1, 2, 3, 2, 1, 0] [1, 0, 1, 4, 3] = [0, 1, 3, 1]` -/ open Nat namespace List variable {α : Type*} {l₁ l₂ : List α} {p : α → Prop} {a : α} /-! ### `Disjoint` -/ section Disjoint @[symm] theorem Disjoint.symm (d : Disjoint l₁ l₂) : Disjoint l₂ l₁ := fun _ i₂ i₁ => d i₁ i₂ end Disjoint variable [DecidableEq α] /-! ### `union` -/ section Union theorem mem_union_left (h : a ∈ l₁) (l₂ : List α) : a ∈ l₁ ∪ l₂ := mem_union_iff.2 (Or.inl h) theorem mem_union_right (l₁ : List α) (h : a ∈ l₂) : a ∈ l₁ ∪ l₂ := mem_union_iff.2 (Or.inr h) theorem sublist_suffix_of_union : ∀ l₁ l₂ : List α, ∃ t, t <+ l₁ ∧ t ++ l₂ = l₁ ∪ l₂ | [], _ => ⟨[], by rfl, rfl⟩ | a :: l₁, l₂ => let ⟨t, s, e⟩ := sublist_suffix_of_union l₁ l₂ if h : a ∈ l₁ ∪ l₂ then ⟨t, sublist_cons_of_sublist _ s, by simp only [e, cons_union, insert_of_mem h]⟩ else ⟨a :: t, s.cons_cons _, by simp only [cons_append, cons_union, e, insert_of_not_mem h]⟩ theorem suffix_union_right (l₁ l₂ : List α) : l₂ <:+ l₁ ∪ l₂ := (sublist_suffix_of_union l₁ l₂).imp fun _ => And.right theorem union_sublist_append (l₁ l₂ : List α) : l₁ ∪ l₂ <+ l₁ ++ l₂ := let ⟨_, s, e⟩ := sublist_suffix_of_union l₁ l₂ e ▸ (append_sublist_append_right _).2 s theorem forall_mem_union : (∀ x ∈ l₁ ∪ l₂, p x) ↔ (∀ x ∈ l₁, p x) ∧ ∀ x ∈ l₂, p x := by simp only [mem_union_iff, or_imp, forall_and] theorem forall_mem_of_forall_mem_union_left (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₁, p x := (forall_mem_union.1 h).1 theorem forall_mem_of_forall_mem_union_right (h : ∀ x ∈ l₁ ∪ l₂, p x) : ∀ x ∈ l₂, p x := (forall_mem_union.1 h).2 theorem Subset.union_eq_right {xs ys : List α} (h : xs ⊆ ys) : xs ∪ ys = ys := by induction xs with | nil => simp | cons x xs ih => rw [cons_union, insert_of_mem <| mem_union_right _ <| h mem_cons_self, ih <| subset_of_cons_subset h] end Union /-! ### `inter` -/ section Inter @[simp] theorem inter_nil (l : List α) : [] ∩ l = [] := rfl @[simp] theorem inter_cons_of_mem (l₁ : List α) (h : a ∈ l₂) : (a :: l₁) ∩ l₂ = a :: l₁ ∩ l₂ := by simp [Inter.inter, List.inter, h] @[simp] theorem inter_cons_of_not_mem (l₁ : List α) (h : a ∉ l₂) : (a :: l₁) ∩ l₂ = l₁ ∩ l₂ := by simp [Inter.inter, List.inter, h] @[simp] theorem inter_nil' (l : List α) : l ∩ [] = [] := by induction l with | nil => rfl | cons x xs ih => by_cases x ∈ xs <;> simp [ih] theorem mem_of_mem_inter_left : a ∈ l₁ ∩ l₂ → a ∈ l₁ := mem_of_mem_filter theorem mem_of_mem_inter_right (h : a ∈ l₁ ∩ l₂) : a ∈ l₂ := by simpa using of_mem_filter h theorem mem_inter_of_mem_of_mem (h₁ : a ∈ l₁) (h₂ : a ∈ l₂) : a ∈ l₁ ∩ l₂ := mem_filter_of_mem h₁ <| by simpa using h₂ theorem inter_subset_left {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₁ := filter_subset' _ theorem inter_subset_right {l₁ l₂ : List α} : l₁ ∩ l₂ ⊆ l₂ := fun _ => mem_of_mem_inter_right theorem subset_inter {l l₁ l₂ : List α} (h₁ : l ⊆ l₁) (h₂ : l ⊆ l₂) : l ⊆ l₁ ∩ l₂ := fun _ h => mem_inter_iff.2 ⟨h₁ h, h₂ h⟩ theorem inter_eq_nil_iff_disjoint : l₁ ∩ l₂ = [] ↔ Disjoint l₁ l₂ := by simp only [eq_nil_iff_forall_not_mem, mem_inter_iff, not_and] rfl alias ⟨_, Disjoint.inter_eq_nil⟩ := inter_eq_nil_iff_disjoint theorem forall_mem_inter_of_forall_left (h : ∀ x ∈ l₁, p x) (l₂ : List α) : ∀ x, x ∈ l₁ ∩ l₂ → p x := BAll.imp_left (fun _ => mem_of_mem_inter_left) h theorem forall_mem_inter_of_forall_right (l₁ : List α) (h : ∀ x ∈ l₂, p x) : ∀ x, x ∈ l₁ ∩ l₂ → p x := BAll.imp_left (fun _ => mem_of_mem_inter_right) h @[simp] theorem inter_reverse {xs ys : List α} : xs.inter ys.reverse = xs.inter ys := by simp only [List.inter, elem_eq_mem, mem_reverse] theorem Subset.inter_eq_left {xs ys : List α} (h : xs ⊆ ys) : xs ∩ ys = xs := List.filter_eq_self.mpr fun _ ha => elem_eq_true_of_mem (h ha) end Inter /-! ### `bagInter` -/ section BagInter @[simp] theorem nil_bagInter (l : List α) : [].bagInter l = [] := by cases l <;> rfl @[simp] theorem bagInter_nil (l : List α) : l.bagInter [] = [] := by cases l <;> rfl @[simp]
Mathlib/Data/List/Lattice.lean
167
169
theorem cons_bagInter_of_pos (l₁ : List α) (h : a ∈ l₂) : (a :: l₁).bagInter l₂ = a :: l₁.bagInter (l₂.erase a) := by
cases l₂
/- 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.Algebra.Pi import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Algebra.Polynomial.Eval.Algebra import Mathlib.Algebra.Polynomial.Eval.Degree import Mathlib.Algebra.Polynomial.Monomial /-! # Theory of univariate polynomials We show that `A[X]` is an R-algebra when `A` is an R-algebra. We promote `eval₂` to an algebra hom in `aeval`. -/ assert_not_exists Ideal noncomputable section open Finset open Polynomial namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B : Type*} {a b : R} {n : ℕ} section CommSemiring variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable {p q r : R[X]} /-- Note that this instance also provides `Algebra R R[X]`. -/ instance algebraOfAlgebra : Algebra R A[X] where smul_def' r p := toFinsupp_injective <| by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply] rw [toFinsupp_smul, toFinsupp_mul, toFinsupp_C] exact Algebra.smul_def' _ _ commutes' r p := toFinsupp_injective <| by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply] simp_rw [toFinsupp_mul, toFinsupp_C] convert Algebra.commutes' r p.toFinsupp algebraMap := C.comp (algebraMap R A) @[simp] theorem algebraMap_apply (r : R) : algebraMap R A[X] r = C (algebraMap R A r) := rfl @[simp] theorem toFinsupp_algebraMap (r : R) : (algebraMap R A[X] r).toFinsupp = algebraMap R _ r := show toFinsupp (C (algebraMap _ _ r)) = _ by rw [toFinsupp_C] rfl theorem ofFinsupp_algebraMap (r : R) : (⟨algebraMap R _ r⟩ : A[X]) = algebraMap R A[X] r := toFinsupp_injective (toFinsupp_algebraMap _).symm /-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[X]`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebraMap` is not available.) -/ theorem C_eq_algebraMap (r : R) : C r = algebraMap R R[X] r := rfl @[simp] theorem algebraMap_eq : algebraMap R R[X] = C := rfl /-- `Polynomial.C` as an `AlgHom`. -/ @[simps! apply] def CAlgHom : A →ₐ[R] A[X] where toRingHom := C commutes' _ := rfl /-- Extensionality lemma for algebra maps out of `A'[X]` over a smaller base ring than `A'` -/ @[ext 1100] theorem algHom_ext' {f g : A[X] →ₐ[R] B} (hC : f.comp CAlgHom = g.comp CAlgHom) (hX : f X = g X) : f = g := AlgHom.coe_ringHom_injective (ringHom_ext' (congr_arg AlgHom.toRingHom hC) hX) variable (R) in open AddMonoidAlgebra in /-- Algebra isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps!] def toFinsuppIsoAlg : R[X] ≃ₐ[R] R[ℕ] := { toFinsuppIso R with commutes' := fun r => by dsimp } instance subalgebraNontrivial [Nontrivial A] : Nontrivial (Subalgebra R A[X]) := ⟨⟨⊥, ⊤, by rw [Ne, SetLike.ext_iff, not_forall] refine ⟨X, ?_⟩ simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true, Algebra.mem_top, algebraMap_apply, not_forall] intro x rw [ext_iff, not_forall] refine ⟨1, ?_⟩ simp [coeff_C]⟩⟩ @[simp] theorem algHom_eval₂_algebraMap {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] (p : R[X]) (f : A →ₐ[R] B) (a : A) : f (eval₂ (algebraMap R A) a p) = eval₂ (algebraMap R B) (f a) p := by simp only [eval₂_eq_sum, sum_def] simp only [map_sum, map_mul, map_pow, eq_intCast, map_intCast, AlgHom.commutes] @[simp]
Mathlib/Algebra/Polynomial/AlgebraMap.lean
123
127
theorem eval₂_algebraMap_X {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (p : R[X]) (f : R[X] →ₐ[R] A) : eval₂ (algebraMap R A) (f X) p = f p := by
conv_rhs => rw [← Polynomial.sum_C_mul_X_pow_eq p] simp only [eval₂_eq_sum, sum_def] simp only [map_sum, map_mul, map_pow, eq_intCast, map_intCast]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Domain import Mathlib.Algebra.Polynomial.Degree.Support import Mathlib.Algebra.Polynomial.Eval.Coeff import Mathlib.GroupTheory.GroupAction.Ring /-! # The derivative map on polynomials ## Main definitions * `Polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map. * `Polynomial.derivativeFinsupp`: Iterated derivatives as a finite support function. -/ noncomputable section open Finset open Polynomial open scoped Nat namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ} section Derivative section Semiring variable [Semiring R] /-- `derivative p` is the formal derivative of the polynomial `p` -/ def derivative : R[X] →ₗ[R] R[X] where toFun p := p.sum fun n a => C (a * n) * X ^ (n - 1) map_add' p q := by rw [sum_add_index] <;> simp only [add_mul, forall_const, RingHom.map_add, eq_self_iff_true, zero_mul, RingHom.map_zero] map_smul' a p := by dsimp; rw [sum_smul_index] <;> simp only [mul_sum, ← C_mul', mul_assoc, coeff_C_mul, RingHom.map_mul, forall_const, zero_mul, RingHom.map_zero, sum] theorem derivative_apply (p : R[X]) : derivative p = p.sum fun n a => C (a * n) * X ^ (n - 1) := rfl theorem coeff_derivative (p : R[X]) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := by rw [derivative_apply] simp only [coeff_X_pow, coeff_sum, coeff_C_mul] rw [sum, Finset.sum_eq_single (n + 1)] · simp only [Nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true]; norm_cast · intro b cases b · intros rw [Nat.cast_zero, mul_zero, zero_mul] · intro _ H rw [Nat.add_one_sub_one, if_neg (mt (congr_arg Nat.succ) H.symm), mul_zero] · rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, Nat.cast_add, Nat.cast_one, mem_support_iff] intro h push_neg at h simp [h] @[simp] theorem derivative_zero : derivative (0 : R[X]) = 0 := derivative.map_zero theorem iterate_derivative_zero {k : ℕ} : derivative^[k] (0 : R[X]) = 0 := iterate_map_zero derivative k theorem derivative_monomial (a : R) (n : ℕ) : derivative (monomial n a) = monomial (n - 1) (a * n) := by rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial] simp @[simp] theorem derivative_monomial_succ (a : R) (n : ℕ) : derivative (monomial (n + 1) a) = monomial n (a * (n + 1)) := by rw [derivative_monomial, add_tsub_cancel_right, Nat.cast_add, Nat.cast_one] theorem derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by simp [C_mul_X_eq_monomial, derivative_monomial, Nat.cast_one, mul_one] theorem derivative_C_mul_X_pow (a : R) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial] theorem derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one] theorem derivative_X_pow (n : ℕ) : derivative (X ^ n : R[X]) = C (n : R) * X ^ (n - 1) := by convert derivative_C_mul_X_pow (1 : R) n <;> simp @[simp] theorem derivative_X_pow_succ (n : ℕ) : derivative (X ^ (n + 1) : R[X]) = C (n + 1 : R) * X ^ n := by simp [derivative_X_pow] theorem derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by rw [derivative_X_pow, Nat.cast_two, pow_one] @[simp] theorem derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply] theorem derivative_of_natDegree_zero {p : R[X]} (hp : p.natDegree = 0) : derivative p = 0 := by rw [eq_C_of_natDegree_eq_zero hp, derivative_C] @[simp] theorem derivative_X : derivative (X : R[X]) = 1 := (derivative_monomial _ _).trans <| by simp @[simp] theorem derivative_one : derivative (1 : R[X]) = 0 := derivative_C @[simp] theorem derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g := derivative.map_add f g theorem derivative_X_add_C (c : R) : derivative (X + C c) = 1 := by rw [derivative_add, derivative_X, derivative_C, add_zero] theorem derivative_sum {s : Finset ι} {f : ι → R[X]} : derivative (∑ b ∈ s, f b) = ∑ b ∈ s, derivative (f b) := map_sum .. theorem iterate_derivative_sum (k : ℕ) (s : Finset ι) (f : ι → R[X]) : derivative^[k] (∑ b ∈ s, f b) = ∑ b ∈ s, derivative^[k] (f b) := by simp_rw [← Module.End.pow_apply, map_sum] theorem derivative_smul {S : Type*} [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p : R[X]) : derivative (s • p) = s • derivative p := derivative.map_smul_of_tower s p @[simp] theorem iterate_derivative_smul {S : Type*} [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p : R[X]) (k : ℕ) : derivative^[k] (s • p) = s • derivative^[k] p := by induction k generalizing p with | zero => simp | succ k ih => simp [ih] @[simp] theorem iterate_derivative_C_mul (a : R) (p : R[X]) (k : ℕ) : derivative^[k] (C a * p) = C a * derivative^[k] p := by simp_rw [← smul_eq_C_mul, iterate_derivative_smul] theorem derivative_C_mul (a : R) (p : R[X]) : derivative (C a * p) = C a * derivative p := iterate_derivative_C_mul _ _ 1 theorem of_mem_support_derivative {p : R[X]} {n : ℕ} (h : n ∈ p.derivative.support) : n + 1 ∈ p.support := mem_support_iff.2 fun h1 : p.coeff (n + 1) = 0 => mem_support_iff.1 h <| show p.derivative.coeff n = 0 by rw [coeff_derivative, h1, zero_mul] theorem degree_derivative_lt {p : R[X]} (hp : p ≠ 0) : p.derivative.degree < p.degree := (Finset.sup_lt_iff <| bot_lt_iff_ne_bot.2 <| mt degree_eq_bot.1 hp).2 fun n hp => lt_of_lt_of_le (WithBot.coe_lt_coe.2 n.lt_succ_self) <| Finset.le_sup <| of_mem_support_derivative hp theorem degree_derivative_le {p : R[X]} : p.derivative.degree ≤ p.degree := letI := Classical.decEq R if H : p = 0 then le_of_eq <| by rw [H, derivative_zero] else (degree_derivative_lt H).le theorem natDegree_derivative_lt {p : R[X]} (hp : p.natDegree ≠ 0) : p.derivative.natDegree < p.natDegree := by rcases eq_or_ne (derivative p) 0 with hp' | hp' · rw [hp', Polynomial.natDegree_zero] exact hp.bot_lt · rw [natDegree_lt_natDegree_iff hp'] exact degree_derivative_lt fun h => hp (h.symm ▸ natDegree_zero) theorem natDegree_derivative_le (p : R[X]) : p.derivative.natDegree ≤ p.natDegree - 1 := by by_cases p0 : p.natDegree = 0 · simp [p0, derivative_of_natDegree_zero] · exact Nat.le_sub_one_of_lt (natDegree_derivative_lt p0) theorem natDegree_iterate_derivative (p : R[X]) (k : ℕ) : (derivative^[k] p).natDegree ≤ p.natDegree - k := by induction k with | zero => rw [Function.iterate_zero_apply, Nat.sub_zero] | succ d hd => rw [Function.iterate_succ_apply', Nat.sub_succ'] exact (natDegree_derivative_le _).trans <| Nat.sub_le_sub_right hd 1 @[simp] theorem derivative_natCast {n : ℕ} : derivative (n : R[X]) = 0 := by rw [← map_natCast C n] exact derivative_C @[simp] theorem derivative_ofNat (n : ℕ) [n.AtLeastTwo] : derivative (ofNat(n) : R[X]) = 0 := derivative_natCast theorem iterate_derivative_eq_zero {p : R[X]} {x : ℕ} (hx : p.natDegree < x) : Polynomial.derivative^[x] p = 0 := by induction' h : p.natDegree using Nat.strong_induction_on with _ ih generalizing p x subst h obtain ⟨t, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (pos_of_gt hx).ne' rw [Function.iterate_succ_apply] by_cases hp : p.natDegree = 0 · rw [derivative_of_natDegree_zero hp, iterate_derivative_zero] have := natDegree_derivative_lt hp exact ih _ this (this.trans_le <| Nat.le_of_lt_succ hx) rfl @[simp] theorem iterate_derivative_C {k} (h : 0 < k) : derivative^[k] (C a : R[X]) = 0 := iterate_derivative_eq_zero <| (natDegree_C _).trans_lt h @[simp] theorem iterate_derivative_one {k} (h : 0 < k) : derivative^[k] (1 : R[X]) = 0 := iterate_derivative_C h @[simp] theorem iterate_derivative_X {k} (h : 1 < k) : derivative^[k] (X : R[X]) = 0 := iterate_derivative_eq_zero <| natDegree_X_le.trans_lt h theorem natDegree_eq_zero_of_derivative_eq_zero [NoZeroSMulDivisors ℕ R] {f : R[X]} (h : derivative f = 0) : f.natDegree = 0 := by rcases eq_or_ne f 0 with (rfl | hf) · exact natDegree_zero rw [natDegree_eq_zero_iff_degree_le_zero] by_contra! f_nat_degree_pos rw [← natDegree_pos_iff_degree_pos] at f_nat_degree_pos let m := f.natDegree - 1 have hm : m + 1 = f.natDegree := tsub_add_cancel_of_le f_nat_degree_pos have h2 := coeff_derivative f m rw [Polynomial.ext_iff] at h rw [h m, coeff_zero, ← Nat.cast_add_one, ← nsmul_eq_mul', eq_comm, smul_eq_zero] at h2 replace h2 := h2.resolve_left m.succ_ne_zero rw [hm, ← leadingCoeff, leadingCoeff_eq_zero] at h2 exact hf h2 theorem eq_C_of_derivative_eq_zero [NoZeroSMulDivisors ℕ R] {f : R[X]} (h : derivative f = 0) : f = C (f.coeff 0) := eq_C_of_natDegree_eq_zero <| natDegree_eq_zero_of_derivative_eq_zero h @[simp] theorem derivative_mul {f g : R[X]} : derivative (f * g) = derivative f * g + f * derivative g := by induction f using Polynomial.induction_on' with | add => simp only [add_mul, map_add, add_assoc, add_left_comm, *] | monomial m a => ?_ induction g using Polynomial.induction_on' with | add => simp only [mul_add, map_add, add_assoc, add_left_comm, *] | monomial n b => ?_ simp only [monomial_mul_monomial, derivative_monomial] simp only [mul_assoc, (Nat.cast_commute _ _).eq, Nat.cast_add, mul_add, map_add] cases m with | zero => simp only [zero_add, Nat.cast_zero, mul_zero, map_zero] | succ m => cases n with | zero => simp only [add_zero, Nat.cast_zero, mul_zero, map_zero] | succ n => simp only [Nat.add_succ_sub_one, add_tsub_cancel_right] rw [add_assoc, add_comm n 1] theorem derivative_eval (p : R[X]) (x : R) : p.derivative.eval x = p.sum fun n a => a * n * x ^ (n - 1) := by simp_rw [derivative_apply, eval_sum, eval_mul_X_pow, eval_C] @[simp] theorem derivative_map [Semiring S] (p : R[X]) (f : R →+* S) : derivative (p.map f) = p.derivative.map f := by let n := max p.natDegree (map f p).natDegree rw [derivative_apply, derivative_apply] rw [sum_over_range' _ _ (n + 1) ((le_max_left _ _).trans_lt (lt_add_one _))] on_goal 1 => rw [sum_over_range' _ _ (n + 1) ((le_max_right _ _).trans_lt (lt_add_one _))] · simp only [Polynomial.map_sum, Polynomial.map_mul, Polynomial.map_C, map_mul, coeff_map, map_natCast, Polynomial.map_natCast, Polynomial.map_pow, map_X] all_goals intro n; rw [zero_mul, C_0, zero_mul] @[simp] theorem iterate_derivative_map [Semiring S] (p : R[X]) (f : R →+* S) (k : ℕ) : Polynomial.derivative^[k] (p.map f) = (Polynomial.derivative^[k] p).map f := by induction' k with k ih generalizing p · simp · simp only [ih, Function.iterate_succ, Polynomial.derivative_map, Function.comp_apply] theorem derivative_natCast_mul {n : ℕ} {f : R[X]} : derivative ((n : R[X]) * f) = n * derivative f := by simp @[simp] theorem iterate_derivative_natCast_mul {n k : ℕ} {f : R[X]} : derivative^[k] ((n : R[X]) * f) = n * derivative^[k] f := by induction' k with k ih generalizing f <;> simp [*] theorem mem_support_derivative [NoZeroSMulDivisors ℕ R] (p : R[X]) (n : ℕ) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := by suffices ¬p.coeff (n + 1) * (n + 1 : ℕ) = 0 ↔ coeff p (n + 1) ≠ 0 by simpa only [mem_support_iff, coeff_derivative, Ne, Nat.cast_succ] rw [← nsmul_eq_mul', smul_eq_zero] simp only [Nat.succ_ne_zero, false_or] @[simp] theorem degree_derivative_eq [NoZeroSMulDivisors ℕ R] (p : R[X]) (hp : 0 < natDegree p) : degree (derivative p) = (natDegree p - 1 : ℕ) := by apply le_antisymm · rw [derivative_apply] apply le_trans (degree_sum_le _ _) (Finset.sup_le _) intro n hn apply le_trans (degree_C_mul_X_pow_le _ _) (WithBot.coe_le_coe.2 (tsub_le_tsub_right _ _)) apply le_natDegree_of_mem_supp _ hn · refine le_sup ?_ rw [mem_support_derivative, tsub_add_cancel_of_le, mem_support_iff] · rw [coeff_natDegree, Ne, leadingCoeff_eq_zero] intro h rw [h, natDegree_zero] at hp exact hp.false exact hp theorem coeff_iterate_derivative {k} (p : R[X]) (m : ℕ) : (derivative^[k] p).coeff m = (m + k).descFactorial k • p.coeff (m + k) := by induction k generalizing m with | zero => simp | succ k ih => calc (derivative^[k + 1] p).coeff m _ = Nat.descFactorial (Nat.succ (m + k)) k • p.coeff (m + k.succ) * (m + 1) := by rw [Function.iterate_succ_apply', coeff_derivative, ih m.succ, Nat.succ_add, Nat.add_succ] _ = ((m + 1) * Nat.descFactorial (Nat.succ (m + k)) k) • p.coeff (m + k.succ) := by rw [← Nat.cast_add_one, ← nsmul_eq_mul', smul_smul] _ = Nat.descFactorial (m.succ + k) k.succ • p.coeff (m + k.succ) := by rw [← Nat.succ_add, Nat.descFactorial_succ, add_tsub_cancel_right] _ = Nat.descFactorial (m + k.succ) k.succ • p.coeff (m + k.succ) := by rw [Nat.succ_add_eq_add_succ] theorem iterate_derivative_eq_sum (p : R[X]) (k : ℕ) : derivative^[k] p = ∑ x ∈ (derivative^[k] p).support, C ((x + k).descFactorial k • p.coeff (x + k)) * X ^ x := by conv_lhs => rw [(derivative^[k] p).as_sum_support_C_mul_X_pow] refine sum_congr rfl fun i _ ↦ ?_ rw [coeff_iterate_derivative, Nat.descFactorial_eq_factorial_mul_choose] theorem iterate_derivative_eq_factorial_smul_sum (p : R[X]) (k : ℕ) : derivative^[k] p = k ! • ∑ x ∈ (derivative^[k] p).support, C ((x + k).choose k • p.coeff (x + k)) * X ^ x := by conv_lhs => rw [iterate_derivative_eq_sum] rw [smul_sum] refine sum_congr rfl fun i _ ↦ ?_ rw [← smul_mul_assoc, smul_C, smul_smul, Nat.descFactorial_eq_factorial_mul_choose] theorem iterate_derivative_mul {n} (p q : R[X]) : derivative^[n] (p * q) = ∑ k ∈ range n.succ, (n.choose k • (derivative^[n - k] p * derivative^[k] q)) := by induction n with | zero => simp [Finset.range] | succ n IH => calc derivative^[n + 1] (p * q) = derivative (∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k] q)) := by rw [Function.iterate_succ_apply', IH] _ = (∑ k ∈ range n.succ, n.choose k • (derivative^[n - k + 1] p * derivative^[k] q)) + ∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k + 1] q) := by simp_rw [derivative_sum, derivative_smul, derivative_mul, Function.iterate_succ_apply', smul_add, sum_add_distrib] _ = (∑ k ∈ range n.succ, n.choose k.succ • (derivative^[n - k] p * derivative^[k + 1] q)) + 1 • (derivative^[n + 1] p * derivative^[0] q) + ∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k + 1] q) := ?_ _ = ((∑ k ∈ range n.succ, n.choose k • (derivative^[n - k] p * derivative^[k + 1] q)) + ∑ k ∈ range n.succ, n.choose k.succ • (derivative^[n - k] p * derivative^[k + 1] q)) + 1 • (derivative^[n + 1] p * derivative^[0] q) := by rw [add_comm, add_assoc] _ = (∑ i ∈ range n.succ, (n + 1).choose (i + 1) • (derivative^[n + 1 - (i + 1)] p * derivative^[i + 1] q)) + 1 • (derivative^[n + 1] p * derivative^[0] q) := by simp_rw [Nat.choose_succ_succ, Nat.succ_sub_succ, add_smul, sum_add_distrib] _ = ∑ k ∈ range n.succ.succ, n.succ.choose k • (derivative^[n.succ - k] p * derivative^[k] q) := by rw [sum_range_succ' _ n.succ, Nat.choose_zero_right, tsub_zero] congr refine (sum_range_succ' _ _).trans (congr_arg₂ (· + ·) ?_ ?_) · rw [sum_range_succ, Nat.choose_succ_self, zero_smul, add_zero] refine sum_congr rfl fun k hk => ?_ rw [mem_range] at hk congr omega · rw [Nat.choose_zero_right, tsub_zero] /-- Iterated derivatives as a finite support function. -/ @[simps! apply_toFun] noncomputable def derivativeFinsupp : R[X] →ₗ[R] ℕ →₀ R[X] where toFun p := .onFinset (range (p.natDegree + 1)) (derivative^[·] p) fun i ↦ by contrapose; simp_all [iterate_derivative_eq_zero, Nat.succ_le] map_add' _ _ := by ext; simp map_smul' _ _ := by ext; simp @[simp] theorem support_derivativeFinsupp_subset_range {p : R[X]} {n : ℕ} (h : p.natDegree < n) : (derivativeFinsupp p).support ⊆ range n := by dsimp [derivativeFinsupp] exact Finsupp.support_onFinset_subset.trans (Finset.range_subset.mpr h) @[simp] theorem derivativeFinsupp_C (r : R) : derivativeFinsupp (C r : R[X]) = .single 0 (C r) := by ext i : 1 match i with | 0 => simp | i + 1 => simp @[simp] theorem derivativeFinsupp_one : derivativeFinsupp (1 : R[X]) = .single 0 1 := by simpa using derivativeFinsupp_C (1 : R) @[simp] theorem derivativeFinsupp_X : derivativeFinsupp (X : R[X]) = .single 0 X + .single 1 1 := by ext i : 1 match i with | 0 => simp | 1 => simp | (n + 2) => simp theorem derivativeFinsupp_map [Semiring S] (p : R[X]) (f : R →+* S) : derivativeFinsupp (p.map f) = (derivativeFinsupp p).mapRange (·.map f) (by simp) := by ext i : 1 simp theorem derivativeFinsupp_derivative (p : R[X]) : derivativeFinsupp (derivative p) = (derivativeFinsupp p).comapDomain Nat.succ Nat.succ_injective.injOn := by ext i : 1 simp end Semiring section CommSemiring variable [CommSemiring R] theorem derivative_pow_succ (p : R[X]) (n : ℕ) : derivative (p ^ (n + 1)) = C (n + 1 : R) * p ^ n * derivative p := Nat.recOn n (by simp) fun n ih => by rw [pow_succ, derivative_mul, ih, Nat.add_one, mul_right_comm, C_add, add_mul, add_mul, pow_succ, ← mul_assoc, C_1, one_mul]; simp [add_mul] theorem derivative_pow (p : R[X]) (n : ℕ) : derivative (p ^ n) = C (n : R) * p ^ (n - 1) * derivative p := Nat.casesOn n (by rw [pow_zero, derivative_one, Nat.cast_zero, C_0, zero_mul, zero_mul]) fun n => by rw [p.derivative_pow_succ n, Nat.add_one_sub_one, n.cast_succ] theorem derivative_sq (p : R[X]) : derivative (p ^ 2) = C 2 * p * derivative p := by rw [derivative_pow_succ, Nat.cast_one, one_add_one_eq_two, pow_one] theorem pow_sub_one_dvd_derivative_of_pow_dvd {p q : R[X]} {n : ℕ} (dvd : q ^ n ∣ p) : q ^ (n - 1) ∣ derivative p := by obtain ⟨r, rfl⟩ := dvd rw [derivative_mul, derivative_pow] exact (((dvd_mul_left _ _).mul_right _).mul_right _).add ((pow_dvd_pow q n.pred_le).mul_right _) theorem pow_sub_dvd_iterate_derivative_of_pow_dvd {p q : R[X]} {n : ℕ} (m : ℕ) (dvd : q ^ n ∣ p) : q ^ (n - m) ∣ derivative^[m] p := by induction m generalizing p with | zero => simpa | succ m ih => rw [Nat.sub_succ, Function.iterate_succ'] exact pow_sub_one_dvd_derivative_of_pow_dvd (ih dvd) theorem pow_sub_dvd_iterate_derivative_pow (p : R[X]) (n m : ℕ) : p ^ (n - m) ∣ derivative^[m] (p ^ n) := pow_sub_dvd_iterate_derivative_of_pow_dvd m dvd_rfl theorem dvd_iterate_derivative_pow (f : R[X]) (n : ℕ) {m : ℕ} (c : R) (hm : m ≠ 0) : (n : R) ∣ eval c (derivative^[m] (f ^ n)) := by obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hm rw [Function.iterate_succ_apply, derivative_pow, mul_assoc, C_eq_natCast, iterate_derivative_natCast_mul, eval_mul, eval_natCast] exact dvd_mul_right _ _ theorem iterate_derivative_X_pow_eq_natCast_mul (n k : ℕ) : derivative^[k] (X ^ n : R[X]) = ↑(Nat.descFactorial n k : R[X]) * X ^ (n - k) := by induction k with | zero => rw [Function.iterate_zero_apply, tsub_zero, Nat.descFactorial_zero, Nat.cast_one, one_mul] | succ k ih => rw [Function.iterate_succ_apply', ih, derivative_natCast_mul, derivative_X_pow, C_eq_natCast, Nat.descFactorial_succ, Nat.sub_sub, Nat.cast_mul] simp [mul_comm, mul_assoc, mul_left_comm] theorem iterate_derivative_X_pow_eq_C_mul (n k : ℕ) : derivative^[k] (X ^ n : R[X]) = C (Nat.descFactorial n k : R) * X ^ (n - k) := by rw [iterate_derivative_X_pow_eq_natCast_mul n k, C_eq_natCast] theorem iterate_derivative_X_pow_eq_smul (n : ℕ) (k : ℕ) : derivative^[k] (X ^ n : R[X]) = (Nat.descFactorial n k : R) • X ^ (n - k) := by rw [iterate_derivative_X_pow_eq_C_mul n k, smul_eq_C_mul] theorem derivative_X_add_C_pow (c : R) (m : ℕ) : derivative ((X + C c) ^ m) = C (m : R) * (X + C c) ^ (m - 1) := by rw [derivative_pow, derivative_X_add_C, mul_one] theorem derivative_X_add_C_sq (c : R) : derivative ((X + C c) ^ 2) = C 2 * (X + C c) := by rw [derivative_sq, derivative_X_add_C, mul_one] theorem iterate_derivative_X_add_pow (n k : ℕ) (c : R) : derivative^[k] ((X + C c) ^ n) = Nat.descFactorial n k • (X + C c) ^ (n - k) := by induction k with | zero => simp | succ k IH => rw [Nat.sub_succ', Function.iterate_succ_apply', IH, derivative_smul, derivative_X_add_C_pow, map_natCast, Nat.descFactorial_succ, nsmul_eq_mul, nsmul_eq_mul, Nat.cast_mul] ring theorem derivative_comp (p q : R[X]) : derivative (p.comp q) = derivative q * p.derivative.comp q := by induction p using Polynomial.induction_on' · simp [*, mul_add] · simp only [derivative_pow, derivative_mul, monomial_comp, derivative_monomial, derivative_C, zero_mul, C_eq_natCast, zero_add, RingHom.map_mul] ring /-- Chain rule for formal derivative of polynomials. -/ theorem derivative_eval₂_C (p q : R[X]) : derivative (p.eval₂ C q) = p.derivative.eval₂ C q * derivative q := Polynomial.induction_on p (fun r => by rw [eval₂_C, derivative_C, eval₂_zero, zero_mul]) (fun p₁ p₂ ih₁ ih₂ => by rw [eval₂_add, derivative_add, ih₁, ih₂, derivative_add, eval₂_add, add_mul]) fun n r ih => by rw [pow_succ, ← mul_assoc, eval₂_mul, eval₂_X, derivative_mul, ih, @derivative_mul _ _ _ X, derivative_X, mul_one, eval₂_add, @eval₂_mul _ _ _ _ X, eval₂_X, add_mul, mul_right_comm] theorem derivative_prod [DecidableEq ι] {s : Multiset ι} {f : ι → R[X]} : derivative (Multiset.map f s).prod = (Multiset.map (fun i => (Multiset.map f (s.erase i)).prod * derivative (f i)) s).sum := by refine Multiset.induction_on s (by simp) fun i s h => ?_ rw [Multiset.map_cons, Multiset.prod_cons, derivative_mul, Multiset.map_cons _ i s, Multiset.sum_cons, Multiset.erase_cons_head, mul_comm (derivative (f i))] congr rw [h, ← AddMonoidHom.coe_mulLeft, (AddMonoidHom.mulLeft (f i)).map_multiset_sum _, AddMonoidHom.coe_mulLeft] simp only [Function.comp_apply, Multiset.map_map] refine congr_arg _ (Multiset.map_congr rfl fun j hj => ?_) rw [← mul_assoc, ← Multiset.prod_cons, ← Multiset.map_cons] by_cases hij : i = j · simp [hij, ← Multiset.prod_cons, ← Multiset.map_cons, Multiset.cons_erase hj] · simp [hij] end CommSemiring section Ring variable [Ring R] @[simp] theorem derivative_neg (f : R[X]) : derivative (-f) = -derivative f := LinearMap.map_neg derivative f theorem iterate_derivative_neg {f : R[X]} {k : ℕ} : derivative^[k] (-f) = -derivative^[k] f := iterate_map_neg derivative k f @[simp] theorem derivative_sub {f g : R[X]} : derivative (f - g) = derivative f - derivative g := LinearMap.map_sub derivative f g theorem derivative_X_sub_C (c : R) : derivative (X - C c) = 1 := by rw [derivative_sub, derivative_X, derivative_C, sub_zero] theorem iterate_derivative_sub {k : ℕ} {f g : R[X]} : derivative^[k] (f - g) = derivative^[k] f - derivative^[k] g := iterate_map_sub derivative k f g @[simp] theorem derivative_intCast {n : ℤ} : derivative (n : R[X]) = 0 := by rw [← C_eq_intCast n] exact derivative_C theorem derivative_intCast_mul {n : ℤ} {f : R[X]} : derivative ((n : R[X]) * f) = n * derivative f := by simp @[simp] theorem iterate_derivative_intCast_mul {n : ℤ} {k : ℕ} {f : R[X]} : derivative^[k] ((n : R[X]) * f) = n * derivative^[k] f := by induction' k with k ih generalizing f <;> simp [*] end Ring section CommRing variable [CommRing R] theorem derivative_comp_one_sub_X (p : R[X]) : derivative (p.comp (1 - X)) = -p.derivative.comp (1 - X) := by simp [derivative_comp] @[simp] theorem iterate_derivative_comp_one_sub_X (p : R[X]) (k : ℕ) : derivative^[k] (p.comp (1 - X)) = (-1) ^ k * (derivative^[k] p).comp (1 - X) := by induction' k with k ih generalizing p · simp · simp [ih (derivative p), iterate_derivative_neg, derivative_comp, pow_succ] theorem eval_multiset_prod_X_sub_C_derivative [DecidableEq R] {S : Multiset R} {r : R} (hr : r ∈ S) : eval r (derivative (Multiset.map (fun a => X - C a) S).prod) = (Multiset.map (fun a => r - a) (S.erase r)).prod := by nth_rw 1 [← Multiset.cons_erase hr] have := (evalRingHom r).map_multiset_prod (Multiset.map (fun a => X - C a) (S.erase r)) simpa using this theorem derivative_X_sub_C_pow (c : R) (m : ℕ) : derivative ((X - C c) ^ m) = C (m : R) * (X - C c) ^ (m - 1) := by rw [derivative_pow, derivative_X_sub_C, mul_one] theorem derivative_X_sub_C_sq (c : R) : derivative ((X - C c) ^ 2) = C 2 * (X - C c) := by rw [derivative_sq, derivative_X_sub_C, mul_one] theorem iterate_derivative_X_sub_pow (n k : ℕ) (c : R) : derivative^[k] ((X - C c) ^ n) = n.descFactorial k • (X - C c) ^ (n - k) := by rw [sub_eq_add_neg, ← C_neg, iterate_derivative_X_add_pow] theorem iterate_derivative_X_sub_pow_self (n : ℕ) (c : R) : derivative^[n] ((X - C c) ^ n) = n.factorial := by rw [iterate_derivative_X_sub_pow, n.sub_self, pow_zero, nsmul_one, n.descFactorial_self] end CommRing section NoZeroDivisors variable [Semiring R] [NoZeroDivisors R] @[simp]
Mathlib/Algebra/Polynomial/Derivative.lean
640
644
theorem dvd_derivative_iff {P : R[X]} : P ∣ derivative P ↔ derivative P = 0 where mp h := by
by_cases hP : P = 0 · simp only [hP, derivative_zero] exact eq_zero_of_dvd_of_degree_lt h (degree_derivative_lt hP)
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Yaël Dillies -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap /-! # Integral average of a function In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For average w.r.t. the volume, one can omit `∂volume`. Both have a version for the Lebesgue integral rather than Bochner. We prove several version of the first moment method: An integrable function is below/above its average on a set of positive measure: * `measure_le_setLAverage_pos` for the Lebesgue integral * `measure_le_setAverage_pos` for the Bochner integral ## Implementation notes The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner integrals work for the average without modifications. For theorems that require integrability of a function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`. ## Tags integral, center mass, average value -/ open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function open scoped Topology ENNReal Convex variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α} {s t : Set α} /-! ### Average value of a function w.r.t. a measure The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation: `⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if `f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to its integral. -/ namespace MeasureTheory section ENNReal variable (μ) {f g : α → ℝ≥0∞} /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure. It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`. It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 (prettyPrint := false) "⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r @[simp] theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero] @[simp] theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage] theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul] theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul] @[simp] theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) : μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rcases eq_or_ne μ 0 with hμ | hμ · rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero] · rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)] theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq
Mathlib/MeasureTheory/Integral/Average.lean
127
131
theorem setLAverage_eq' (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [laverage_eq', restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq'
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Data.Set.Prod /-! # N-ary images of sets This file defines `Set.image2`, the binary image of sets. This is mostly useful to define pointwise operations and `Set.seq`. ## Notes This file is very similar to `Data.Finset.NAry`, to `Order.Filter.NAry`, and to `Data.Option.NAry`. Please keep them in sync. -/ open Function namespace Set variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} {f f' : α → β → γ} variable {s s' : Set α} {t t' : Set β} {u : Set γ} {v : Set δ} {a : α} {b : β} theorem mem_image2_iff (hf : Injective2 f) : f a b ∈ image2 f s t ↔ a ∈ s ∧ b ∈ t := ⟨by rintro ⟨a', ha', b', hb', h⟩ rcases hf h with ⟨rfl, rfl⟩ exact ⟨ha', hb'⟩, fun ⟨ha, hb⟩ => mem_image2_of_mem ha hb⟩ /-- image2 is monotone with respect to `⊆`. -/ @[gcongr] theorem image2_subset (hs : s ⊆ s') (ht : t ⊆ t') : image2 f s t ⊆ image2 f s' t' := by rintro _ ⟨a, ha, b, hb, rfl⟩ exact mem_image2_of_mem (hs ha) (ht hb) @[gcongr] theorem image2_subset_left (ht : t ⊆ t') : image2 f s t ⊆ image2 f s t' := image2_subset Subset.rfl ht @[gcongr] theorem image2_subset_right (hs : s ⊆ s') : image2 f s t ⊆ image2 f s' t := image2_subset hs Subset.rfl theorem image_subset_image2_left (hb : b ∈ t) : (fun a => f a b) '' s ⊆ image2 f s t := forall_mem_image.2 fun _ ha => mem_image2_of_mem ha hb theorem image_subset_image2_right (ha : a ∈ s) : f a '' t ⊆ image2 f s t := forall_mem_image.2 fun _ => mem_image2_of_mem ha lemma forall_mem_image2 {p : γ → Prop} : (∀ z ∈ image2 f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by aesop lemma exists_mem_image2 {p : γ → Prop} : (∃ z ∈ image2 f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by aesop @[deprecated (since := "2024-11-23")] alias forall_image2_iff := forall_mem_image2 @[simp] theorem image2_subset_iff {u : Set γ} : image2 f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u := forall_mem_image2 theorem image2_subset_iff_left : image2 f s t ⊆ u ↔ ∀ a ∈ s, (fun b => f a b) '' t ⊆ u := by simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage] theorem image2_subset_iff_right : image2 f s t ⊆ u ↔ ∀ b ∈ t, (fun a => f a b) '' s ⊆ u := by simp_rw [image2_subset_iff, image_subset_iff, subset_def, mem_preimage, @forall₂_swap α] variable (f) @[simp] lemma image_prod : (fun x : α × β ↦ f x.1 x.2) '' s ×ˢ t = image2 f s t := ext fun _ ↦ by simp [and_assoc] @[simp] lemma image_uncurry_prod (s : Set α) (t : Set β) : uncurry f '' s ×ˢ t = image2 f s t := image_prod _ @[simp] lemma image2_mk_eq_prod : image2 Prod.mk s t = s ×ˢ t := ext <| by simp @[simp] lemma image2_curry (f : α × β → γ) (s : Set α) (t : Set β) : image2 (fun a b ↦ f (a, b)) s t = f '' s ×ˢ t := by simp [← image_uncurry_prod, uncurry] theorem image2_swap (s : Set α) (t : Set β) : image2 f s t = image2 (fun a b => f b a) t s := by ext constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨b, hb, a, ha, rfl⟩ variable {f} theorem image2_union_left : image2 f (s ∪ s') t = image2 f s t ∪ image2 f s' t := by simp_rw [← image_prod, union_prod, image_union] theorem image2_union_right : image2 f s (t ∪ t') = image2 f s t ∪ image2 f s t' := by rw [← image2_swap, image2_union_left, image2_swap f, image2_swap f] lemma image2_inter_left (hf : Injective2 f) : image2 f (s ∩ s') t = image2 f s t ∩ image2 f s' t := by simp_rw [← image_uncurry_prod, inter_prod, image_inter hf.uncurry] lemma image2_inter_right (hf : Injective2 f) : image2 f s (t ∩ t') = image2 f s t ∩ image2 f s t' := by simp_rw [← image_uncurry_prod, prod_inter, image_inter hf.uncurry] @[simp] theorem image2_empty_left : image2 f ∅ t = ∅ := ext <| by simp @[simp] theorem image2_empty_right : image2 f s ∅ = ∅ := ext <| by simp theorem Nonempty.image2 : s.Nonempty → t.Nonempty → (image2 f s t).Nonempty := fun ⟨_, ha⟩ ⟨_, hb⟩ => ⟨_, mem_image2_of_mem ha hb⟩ @[simp] theorem image2_nonempty_iff : (image2 f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun ⟨_, a, ha, b, hb, _⟩ => ⟨⟨a, ha⟩, b, hb⟩, fun h => h.1.image2 h.2⟩ theorem Nonempty.of_image2_left (h : (Set.image2 f s t).Nonempty) : s.Nonempty := (image2_nonempty_iff.1 h).1 theorem Nonempty.of_image2_right (h : (Set.image2 f s t).Nonempty) : t.Nonempty := (image2_nonempty_iff.1 h).2 @[simp] theorem image2_eq_empty_iff : image2 f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by rw [← not_nonempty_iff_eq_empty, image2_nonempty_iff, not_and_or] simp [not_nonempty_iff_eq_empty] theorem Subsingleton.image2 (hs : s.Subsingleton) (ht : t.Subsingleton) (f : α → β → γ) : (image2 f s t).Subsingleton := by rw [← image_prod] apply (hs.prod ht).image theorem image2_inter_subset_left : image2 f (s ∩ s') t ⊆ image2 f s t ∩ image2 f s' t := Monotone.map_inf_le (fun _ _ ↦ image2_subset_right) s s' theorem image2_inter_subset_right : image2 f s (t ∩ t') ⊆ image2 f s t ∩ image2 f s t' := Monotone.map_inf_le (fun _ _ ↦ image2_subset_left) t t' @[simp] theorem image2_singleton_left : image2 f {a} t = f a '' t := ext fun x => by simp @[simp] theorem image2_singleton_right : image2 f s {b} = (fun a => f a b) '' s := ext fun x => by simp theorem image2_singleton : image2 f {a} {b} = {f a b} := by simp @[simp] theorem image2_insert_left : image2 f (insert a s) t = (fun b => f a b) '' t ∪ image2 f s t := by rw [insert_eq, image2_union_left, image2_singleton_left] @[simp] theorem image2_insert_right : image2 f s (insert b t) = (fun a => f a b) '' s ∪ image2 f s t := by rw [insert_eq, image2_union_right, image2_singleton_right] @[congr] theorem image2_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image2 f s t = image2 f' s t := by ext constructor <;> rintro ⟨a, ha, b, hb, rfl⟩ <;> exact ⟨a, ha, b, hb, by rw [h a ha b hb]⟩ /-- A common special case of `image2_congr` -/ theorem image2_congr' (h : ∀ a b, f a b = f' a b) : image2 f s t = image2 f' s t := image2_congr fun a _ b _ => h a b theorem image_image2 (f : α → β → γ) (g : γ → δ) : g '' image2 f s t = image2 (fun a b => g (f a b)) s t := by simp only [← image_prod, image_image] theorem image2_image_left (f : γ → β → δ) (g : α → γ) : image2 f (g '' s) t = image2 (fun a b => f (g a) b) s t := by ext; simp theorem image2_image_right (f : α → γ → δ) (g : β → γ) : image2 f s (g '' t) = image2 (fun a b => f a (g b)) s t := by ext; simp @[simp] theorem image2_left (h : t.Nonempty) : image2 (fun x _ => x) s t = s := by simp [nonempty_def.mp h, Set.ext_iff] @[simp] theorem image2_right (h : s.Nonempty) : image2 (fun _ y => y) s t = t := by simp [nonempty_def.mp h, Set.ext_iff] lemma image2_range (f : α' → β' → γ) (g : α → α') (h : β → β') : image2 f (range g) (range h) = range fun x : α × β ↦ f (g x.1) (h x.2) := by simp_rw [← image_univ, image2_image_left, image2_image_right, ← image_prod, univ_prod_univ] theorem image2_assoc {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) : image2 f (image2 g s t) u = image2 f' s (image2 g' t u) := eq_of_forall_subset_iff fun _ ↦ by simp only [image2_subset_iff, forall_mem_image2, h_assoc] theorem image2_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image2 f s t = image2 g t s := (image2_swap _ _ _).trans <| by simp_rw [h_comm] theorem image2_left_comm {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) : image2 f s (image2 g t u) = image2 g' t (image2 f' s u) := by rw [image2_swap f', image2_swap f] exact image2_assoc fun _ _ _ => h_left_comm _ _ _ theorem image2_right_comm {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) : image2 f (image2 g s t) u = image2 g' (image2 f' s u) t := by rw [image2_swap g, image2_swap g'] exact image2_assoc fun _ _ _ => h_right_comm _ _ _ theorem image2_image2_image2_comm {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ} {f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'} (h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) : image2 f (image2 g s t) (image2 h u v) = image2 f' (image2 g' s u) (image2 h' t v) := by ext; constructor · rintro ⟨_, ⟨a, ha, b, hb, rfl⟩, _, ⟨c, hc, d, hd, rfl⟩, rfl⟩ exact ⟨_, ⟨a, ha, c, hc, rfl⟩, _, ⟨b, hb, d, hd, rfl⟩, (h_comm _ _ _ _).symm⟩ · rintro ⟨_, ⟨a, ha, c, hc, rfl⟩, _, ⟨b, hb, d, hd, rfl⟩, rfl⟩ exact ⟨_, ⟨a, ha, b, hb, rfl⟩, _, ⟨c, hc, d, hd, rfl⟩, h_comm _ _ _ _⟩ theorem image_image2_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'} (h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) : (image2 f s t).image g = image2 f' (s.image g₁) (t.image g₂) := by simp_rw [image_image2, image2_image_left, image2_image_right, h_distrib] /-- Symmetric statement to `Set.image2_image_left_comm`. -/ theorem image_image2_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'} (h_distrib : ∀ a b, g (f a b) = f' (g' a) b) : (image2 f s t).image g = image2 f' (s.image g') t := (image_image2_distrib h_distrib).trans <| by rw [image_id'] /-- Symmetric statement to `Set.image_image2_right_comm`. -/ theorem image_image2_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'} (h_distrib : ∀ a b, g (f a b) = f' a (g' b)) : (image2 f s t).image g = image2 f' s (t.image g') := (image_image2_distrib h_distrib).trans <| by rw [image_id'] /-- Symmetric statement to `Set.image_image2_distrib_left`. -/ theorem image2_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ} (h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) : image2 f (s.image g) t = (image2 f' s t).image g' := (image_image2_distrib_left fun a b => (h_left_comm a b).symm).symm /-- Symmetric statement to `Set.image_image2_distrib_right`. -/ theorem image_image2_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ} (h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) : image2 f s (t.image g) = (image2 f' s t).image g' := (image_image2_distrib_right fun a b => (h_right_comm a b).symm).symm /-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/ theorem image2_distrib_subset_left {f : α → δ → ε} {g : β → γ → δ} {f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε} (h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) : image2 f s (image2 g t u) ⊆ image2 g' (image2 f₁ s t) (image2 f₂ s u) := by rintro _ ⟨a, ha, _, ⟨b, hb, c, hc, rfl⟩, rfl⟩ rw [h_distrib] exact mem_image2_of_mem (mem_image2_of_mem ha hb) (mem_image2_of_mem ha hc) /-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
Mathlib/Data/Set/NAry.lean
262
270
theorem image2_distrib_subset_right {f : δ → γ → ε} {g : α → β → δ} {f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε} (h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) : image2 f (image2 g s t) u ⊆ image2 g' (image2 f₁ s u) (image2 f₂ t u) := by
rintro _ ⟨_, ⟨a, ha, b, hb, rfl⟩, c, hc, rfl⟩ rw [h_distrib] exact mem_image2_of_mem (mem_image2_of_mem ha hc) (mem_image2_of_mem hb hc) theorem image_image2_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'} (h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) :
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Set.Piecewise import Mathlib.Logic.Equiv.Defs import Mathlib.Tactic.Core import Mathlib.Tactic.Attr.Core /-! # Partial equivalences This files defines equivalences between subsets of given types. An element `e` of `PartialEquiv α β` is made of two maps `e.toFun` and `e.invFun` respectively from α to β and from β to α (just like equivs), which are inverse to each other on the subsets `e.source` and `e.target` of respectively α and β. They are designed in particular to define charts on manifolds. The main functionality is `e.trans f`, which composes the two partial equivalences by restricting the source and target to the maximal set where the composition makes sense. As for equivs, we register a coercion to functions and use it in our simp normal form: we write `e x` and `e.symm y` instead of `e.toFun x` and `e.invFun y`. ## Main definitions * `Equiv.toPartialEquiv`: associating a partial equiv to an equiv, with source = target = univ * `PartialEquiv.symm`: the inverse of a partial equivalence * `PartialEquiv.trans`: the composition of two partial equivalences * `PartialEquiv.refl`: the identity partial equivalence * `PartialEquiv.ofSet`: the identity on a set `s` * `EqOnSource`: equivalence relation describing the "right" notion of equality for partial equivalences (see below in implementation notes) ## Implementation notes There are at least three possible implementations of partial equivalences: * equivs on subtypes * pairs of functions taking values in `Option α` and `Option β`, equal to none where the partial equivalence is not defined * pairs of functions defined everywhere, keeping the source and target as additional data Each of these implementations has pros and cons. * When dealing with subtypes, one still need to define additional API for composition and restriction of domains. Checking that one always belongs to the right subtype makes things very tedious, and leads quickly to DTT hell (as the subtype `u ∩ v` is not the "same" as `v ∩ u`, for instance). * With option-valued functions, the composition is very neat (it is just the usual composition, and the domain is restricted automatically). These are implemented in `PEquiv.lean`. For manifolds, where one wants to discuss thoroughly the smoothness of the maps, this creates however a lot of overhead as one would need to extend all classes of smoothness to option-valued maps. * The `PartialEquiv` version as explained above is easier to use for manifolds. The drawback is that there is extra useless data (the values of `toFun` and `invFun` outside of `source` and `target`). In particular, the equality notion between partial equivs is not "the right one", i.e., coinciding source and target and equality there. Moreover, there are no partial equivs in this sense between an empty type and a nonempty type. Since empty types are not that useful, and since one almost never needs to talk about equal partial equivs, this is not an issue in practice. Still, we introduce an equivalence relation `EqOnSource` that captures this right notion of equality, and show that many properties are invariant under this equivalence relation. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Lean Meta Elab Tactic /-! Implementation of the `mfld_set_tac` tactic for working with the domains of partially-defined functions (`PartialEquiv`, `PartialHomeomorph`, etc). This is in a separate file from `Mathlib.Logic.Equiv.MfldSimpsAttr` because attributes need a new file to become functional. -/ /-- Common `@[simps]` configuration options used for manifold-related declarations. -/ def mfld_cfg : Simps.Config where attrs := [`mfld_simps] fullyApplied := false namespace Tactic.MfldSetTac /-- A very basic tactic to show that sets showing up in manifolds coincide or are included in one another. -/ elab (name := mfldSetTac) "mfld_set_tac" : tactic => withMainContext do let g ← getMainGoal let goalTy := (← instantiateMVars (← g.getDecl).type).getAppFnArgs match goalTy with | (``Eq, #[_ty, _e₁, _e₂]) => evalTactic (← `(tactic| ( apply Set.ext; intro my_y constructor <;> · intro h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | (``Subset, #[_ty, _inst, _e₁, _e₂]) => evalTactic (← `(tactic| ( intro my_y h_my_y try simp only [*, mfld_simps] at h_my_y try simp only [*, mfld_simps]))) | _ => throwError "goal should be an equality or an inclusion" attribute [mfld_simps] and_true eq_self_iff_true Function.comp_apply end Tactic.MfldSetTac open Function Set variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} /-- Local equivalence between subsets `source` and `target` of `α` and `β` respectively. The (global) maps `toFun : α → β` and `invFun : β → α` map `source` to `target` and conversely, and are inverse to each other there. The values of `toFun` outside of `source` and of `invFun` outside of `target` are irrelevant. -/ structure PartialEquiv (α : Type*) (β : Type*) where /-- The global function which has a partial inverse. Its value outside of the `source` subset is irrelevant. -/ toFun : α → β /-- The partial inverse to `toFun`. Its value outside of the `target` subset is irrelevant. -/ invFun : β → α /-- The domain of the partial equivalence. -/ source : Set α /-- The codomain of the partial equivalence. -/ target : Set β /-- The proposition that elements of `source` are mapped to elements of `target`. -/ map_source' : ∀ ⦃x⦄, x ∈ source → toFun x ∈ target /-- The proposition that elements of `target` are mapped to elements of `source`. -/ map_target' : ∀ ⦃x⦄, x ∈ target → invFun x ∈ source /-- The proposition that `invFun` is a left-inverse of `toFun` on `source`. -/ left_inv' : ∀ ⦃x⦄, x ∈ source → invFun (toFun x) = x /-- The proposition that `invFun` is a right-inverse of `toFun` on `target`. -/ right_inv' : ∀ ⦃x⦄, x ∈ target → toFun (invFun x) = x attribute [coe] PartialEquiv.toFun namespace PartialEquiv variable (e : PartialEquiv α β) (e' : PartialEquiv β γ) instance [Inhabited α] [Inhabited β] : Inhabited (PartialEquiv α β) := ⟨⟨const α default, const β default, ∅, ∅, mapsTo_empty _ _, mapsTo_empty _ _, eqOn_empty _ _, eqOn_empty _ _⟩⟩ /-- The inverse of a partial equivalence -/ @[symm] protected def symm : PartialEquiv β α where toFun := e.invFun invFun := e.toFun source := e.target target := e.source map_source' := e.map_target' map_target' := e.map_source' left_inv' := e.right_inv' right_inv' := e.left_inv' instance : CoeFun (PartialEquiv α β) fun _ => α → β := ⟨PartialEquiv.toFun⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialEquiv α β) : β → α := e.symm initialize_simps_projections PartialEquiv (toFun → apply, invFun → symm_apply) theorem coe_mk (f : α → β) (g s t ml mr il ir) : (PartialEquiv.mk f g s t ml mr il ir : α → β) = f := rfl @[simp, mfld_simps] theorem coe_symm_mk (f : α → β) (g s t ml mr il ir) : ((PartialEquiv.mk f g s t ml mr il ir).symm : β → α) = g := rfl @[simp, mfld_simps] theorem invFun_as_coe : e.invFun = e.symm := rfl @[simp, mfld_simps] theorem map_source {x : α} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h /-- Variant of `e.map_source` and `map_source'`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : β} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h @[simp, mfld_simps] theorem left_inv {x : α} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h @[simp, mfld_simps] theorem right_inv {x : β} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h theorem eq_symm_apply {x : α} {y : β} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := ⟨fun h => by rw [← e.right_inv hy, h], fun h => by rw [← e.left_inv hx, h]⟩ protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn /-- Interpret an `Equiv` as a `PartialEquiv` by restricting it to `s` in the domain and to `t` in the codomain. -/ @[simps -fullyApplied] def _root_.Equiv.toPartialEquivOfImageEq (e : α ≃ β) (s : Set α) (t : Set β) (h : e '' s = t) : PartialEquiv α β where toFun := e invFun := e.symm source := s target := t map_source' _ hx := h ▸ mem_image_of_mem _ hx map_target' x hx := by subst t rcases hx with ⟨x, hx, rfl⟩ rwa [e.symm_apply_apply] left_inv' x _ := e.symm_apply_apply x right_inv' x _ := e.apply_symm_apply x /-- Associate a `PartialEquiv` to an `Equiv`. -/ @[simps! (config := mfld_cfg)] def _root_.Equiv.toPartialEquiv (e : α ≃ β) : PartialEquiv α β := e.toPartialEquivOfImageEq univ univ <| by rw [image_univ, e.surjective.range_eq] instance inhabitedOfEmpty [IsEmpty α] [IsEmpty β] : Inhabited (PartialEquiv α β) := ⟨((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).toPartialEquiv⟩ /-- Create a copy of a `PartialEquiv` providing better definitional equalities. -/ @[simps -fullyApplied] def copy (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : PartialEquiv α β where toFun := f invFun := g source := s target := t map_source' _ := ht ▸ hs ▸ hf ▸ e.map_source map_target' _ := hs ▸ ht ▸ hg ▸ e.map_target left_inv' _ := hs ▸ hf ▸ hg ▸ e.left_inv right_inv' _ := ht ▸ hf ▸ hg ▸ e.right_inv theorem copy_eq (e : PartialEquiv α β) (f : α → β) (hf : ⇑e = f) (g : β → α) (hg : ⇑e.symm = g) (s : Set α) (hs : e.source = s) (t : Set β) (ht : e.target = t) : e.copy f hf g hg s hs t ht = e := by substs f g s t cases e rfl /-- Associate to a `PartialEquiv` an `Equiv` between the source and the target. -/ protected def toEquiv : e.source ≃ e.target where toFun x := ⟨e x, e.map_source x.mem⟩ invFun y := ⟨e.symm y, e.map_target y.mem⟩ left_inv := fun ⟨_, hx⟩ => Subtype.eq <| e.left_inv hx right_inv := fun ⟨_, hy⟩ => Subtype.eq <| e.right_inv hy @[simp, mfld_simps] theorem symm_source : e.symm.source = e.target := rfl @[simp, mfld_simps] theorem symm_target : e.symm.target = e.source := rfl @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (PartialEquiv.symm : PartialEquiv α β → PartialEquiv β α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem image_source_eq_target : e '' e.source = e.target := e.bijOn.image_eq theorem forall_mem_target {p : β → Prop} : (∀ y ∈ e.target, p y) ↔ ∀ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, forall_mem_image] theorem exists_mem_target {p : β → Prop} : (∃ y ∈ e.target, p y) ↔ ∃ x ∈ e.source, p (e x) := by rw [← image_source_eq_target, exists_mem_image] /-- We say that `t : Set β` is an image of `s : Set α` under a partial equivalence if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set α) (t : Set β) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s) namespace IsImage variable {e} {s : Set α} {t : Set β} {x : α} theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx theorem symm_apply_mem_iff (h : e.IsImage s t) : ∀ ⦃y⦄, y ∈ e.target → (e.symm y ∈ s ↔ y ∈ t) := e.forall_mem_target.mpr fun x hx => by rw [e.left_inv hx, h hx] protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.symm_apply_mem_iff @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩ protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) := fun _ hx => ⟨e.mapsTo hx.1, (h hx.1).2 hx.2⟩ theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) := h.symm.mapsTo /-- Restrict a `PartialEquiv` to a pair of corresponding sets. -/ @[simps -fullyApplied] def restr (h : e.IsImage s t) : PartialEquiv α β where toFun := e invFun := e.symm source := e.source ∩ s target := e.target ∩ t map_source' := h.mapsTo map_target' := h.symm_mapsTo left_inv' := e.leftInvOn.mono inter_subset_left right_inv' := e.rightInvOn.mono inter_subset_left theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t := h.restr.image_source_eq_target theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s := h.symm.image_eq theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := by simp only [IsImage, Set.ext_iff, mem_inter_iff, mem_preimage, and_congr_right_iff] alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t := symm_iff.symm.trans iff_preimage_eq alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t := of_symm_preimage_eq <| Eq.trans (of_symm_preimage_eq rfl).image_eq.symm h theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t := of_preimage_eq <| Eq.trans (iff_preimage_eq.2 rfl).symm_image_eq.symm h protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => not_congr (h hx) protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => and_congr (h hx) (h' hx) protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => or_congr (h hx) (h' hx) protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') : e.IsImage (s \ s') (t \ t') := h.inter h'.compl theorem leftInvOn_piecewise {e' : PartialEquiv α β} [∀ i, Decidable (i ∈ s)] [∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) : LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) := by rintro x (⟨he, hs⟩ | ⟨he, hs : x ∉ s⟩) · rw [piecewise_eq_of_mem _ _ _ hs, piecewise_eq_of_mem _ _ _ ((h he).2 hs), e.left_inv he] · rw [piecewise_eq_of_not_mem _ _ _ hs, piecewise_eq_of_not_mem _ _ _ ((h'.compl he).2 hs), e'.left_inv he] theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : e.target ∩ t = e'.target ∩ t := by rw [← h.image_eq, ← h'.image_eq, ← hs, heq.image_eq] theorem symm_eq_on_of_inter_eq_of_eqOn {e' : PartialEquiv α β} (h : e.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (heq : EqOn e e' (e.source ∩ s)) : EqOn e.symm e'.symm (e.target ∩ t) := by rw [← h.image_eq] rintro y ⟨x, hx, rfl⟩ have hx' := hx; rw [hs] at hx' rw [e.left_inv hx.1, heq hx, e'.left_inv hx'.1] end IsImage theorem isImage_source_target : e.IsImage e.source e.target := fun x hx => by simp [hx] theorem isImage_source_target_of_disjoint (e' : PartialEquiv α β) (hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) : e.IsImage e'.source e'.target := IsImage.of_image_eq <| by rw [hs.inter_eq, ht.inter_eq, image_empty] theorem image_source_inter_eq' (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := by rw [inter_comm, e.leftInvOn.image_inter', image_source_eq_target, inter_comm] theorem image_source_inter_eq (s : Set α) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := by rw [inter_comm, e.leftInvOn.image_inter, image_source_eq_target, inter_comm] theorem image_eq_target_inter_inv_preimage {s : Set α} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := by rw [← e.image_source_inter_eq', inter_eq_self_of_subset_right h] theorem symm_image_eq_source_inter_preimage {s : Set β} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h theorem symm_image_target_inter_eq (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ theorem symm_image_target_inter_eq' (s : Set β) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.symm.image_source_inter_eq' _ theorem source_inter_preimage_inv_preimage (s : Set α) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := Set.ext fun x => and_congr_right_iff.2 fun hx => by simp only [mem_preimage, e.left_inv hx] theorem source_inter_preimage_target_inter (s : Set β) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := ext fun _ => ⟨fun hx => ⟨hx.1, hx.2.2⟩, fun hx => ⟨hx.1, e.map_source hx.1, hx.2⟩⟩ theorem target_inter_inv_preimage_preimage (s : Set β) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ theorem symm_image_image_of_subset_source {s : Set α} (h : s ⊆ e.source) : e.symm '' (e '' s) = s := (e.leftInvOn.mono h).image_image theorem image_symm_image_of_subset_target {s : Set β} (h : s ⊆ e.target) : e '' (e.symm '' s) = s := e.symm.symm_image_image_of_subset_source h theorem source_subset_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target theorem target_subset_preimage_source : e.target ⊆ e.symm ⁻¹' e.source := e.symm_mapsTo /-- Two partial equivs that have the same `source`, same `toFun` and same `invFun`, coincide. -/ @[ext] protected theorem ext {e e' : PartialEquiv α β} (h : ∀ x, e x = e' x) (hsymm : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := by have A : (e : α → β) = e' := by ext x exact h x have B : (e.symm : β → α) = e'.symm := by ext x exact hsymm x have I : e '' e.source = e.target := e.image_source_eq_target have I' : e' '' e'.source = e'.target := e'.image_source_eq_target rw [A, hs, I'] at I cases e; cases e' simp_all /-- Restricting a partial equivalence to `e.source ∩ s` -/ protected def restr (s : Set α) : PartialEquiv α β := (@IsImage.of_symm_preimage_eq α β e s (e.symm ⁻¹' s) rfl).restr @[simp, mfld_simps] theorem restr_coe (s : Set α) : (e.restr s : α → β) = e := rfl @[simp, mfld_simps] theorem restr_coe_symm (s : Set α) : ((e.restr s).symm : β → α) = e.symm := rfl @[simp, mfld_simps] theorem restr_source (s : Set α) : (e.restr s).source = e.source ∩ s := rfl theorem source_restr_subset_source (s : Set α) : (e.restr s).source ⊆ e.source := inter_subset_left @[simp, mfld_simps] theorem restr_target (s : Set α) : (e.restr s).target = e.target ∩ e.symm ⁻¹' s := rfl theorem restr_eq_of_source_subset {e : PartialEquiv α β} {s : Set α} (h : e.source ⊆ s) : e.restr s = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [inter_eq_self_of_subset_left h]) @[simp, mfld_simps] theorem restr_univ {e : PartialEquiv α β} : e.restr univ = e := restr_eq_of_source_subset (subset_univ _) /-- The identity partial equiv -/ protected def refl (α : Type*) : PartialEquiv α α := (Equiv.refl α).toPartialEquiv @[simp, mfld_simps] theorem refl_source : (PartialEquiv.refl α).source = univ := rfl @[simp, mfld_simps] theorem refl_target : (PartialEquiv.refl α).target = univ := rfl @[simp, mfld_simps] theorem refl_coe : (PartialEquiv.refl α : α → α) = id := rfl @[simp, mfld_simps] theorem refl_symm : (PartialEquiv.refl α).symm = PartialEquiv.refl α := rfl @[mfld_simps] theorem refl_restr_source (s : Set α) : ((PartialEquiv.refl α).restr s).source = s := by simp @[mfld_simps] theorem refl_restr_target (s : Set α) : ((PartialEquiv.refl α).restr s).target = s := by simp /-- The identity partial equivalence on a set `s` -/ def ofSet (s : Set α) : PartialEquiv α α where toFun := id invFun := id source := s target := s map_source' _ hx := hx map_target' _ hx := hx left_inv' _ _ := rfl right_inv' _ _ := rfl @[simp, mfld_simps] theorem ofSet_source (s : Set α) : (PartialEquiv.ofSet s).source = s := rfl @[simp, mfld_simps] theorem ofSet_target (s : Set α) : (PartialEquiv.ofSet s).target = s := rfl @[simp, mfld_simps] theorem ofSet_coe (s : Set α) : (PartialEquiv.ofSet s : α → α) = id := rfl @[simp, mfld_simps] theorem ofSet_symm (s : Set α) : (PartialEquiv.ofSet s).symm = PartialEquiv.ofSet s := rfl /-- `Function.const` as a `PartialEquiv`. It consists of two constant maps in opposite directions. -/ @[simps] def single (a : α) (b : β) : PartialEquiv α β where toFun := Function.const α b invFun := Function.const β a source := {a} target := {b} map_source' _ _ := rfl map_target' _ _ := rfl left_inv' a' ha' := by rw [eq_of_mem_singleton ha', const_apply] right_inv' b' hb' := by rw [eq_of_mem_singleton hb', const_apply] /-- Composing two partial equivs if the target of the first coincides with the source of the second. -/ @[simps] protected def trans' (e' : PartialEquiv β γ) (h : e.target = e'.source) : PartialEquiv α γ where toFun := e' ∘ e invFun := e.symm ∘ e'.symm source := e.source target := e'.target map_source' x hx := by simp [← h, hx] map_target' y hy := by simp [h, hy] left_inv' x hx := by simp [hx, ← h] right_inv' y hy := by simp [hy, h] /-- Composing two partial equivs, by restricting to the maximal domain where their composition is well defined. Within the `Manifold` namespace, there is the notation `e ≫ f` for this. -/ @[trans] protected def trans : PartialEquiv α γ := PartialEquiv.trans' (e.symm.restr e'.source).symm (e'.restr e.target) (inter_comm _ _) @[simp, mfld_simps] theorem coe_trans : (e.trans e' : α → γ) = e' ∘ e := rfl @[simp, mfld_simps] theorem coe_trans_symm : ((e.trans e').symm : γ → α) = e.symm ∘ e'.symm := rfl theorem trans_apply {x : α} : (e.trans e') x = e' (e x) := rfl theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := by cases e; cases e'; rfl @[simp, mfld_simps] theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source := rfl theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) := by mfld_set_tac theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) := by rw [e.trans_source', e.symm_image_target_inter_eq] theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source := (e.symm.restr e'.source).symm.image_source_eq_target @[simp, mfld_simps] theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target := rfl theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) := trans_source' e'.symm e.symm theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) := trans_source'' e'.symm e.symm theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target := image_trans_source e'.symm e.symm theorem trans_assoc (e'' : PartialEquiv γ δ) : (e.trans e').trans e'' = e.trans (e'.trans e'') := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source, @preimage_comp α β γ, inter_assoc]) @[simp, mfld_simps] theorem trans_refl : e.trans (PartialEquiv.refl β) = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source]) @[simp, mfld_simps] theorem refl_trans : (PartialEquiv.refl α).trans e = e := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source, preimage_id]) theorem trans_ofSet (s : Set β) : e.trans (ofSet s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) rfl theorem trans_refl_restr (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) (by simp [trans_source]) theorem trans_refl_restr' (s : Set β) : e.trans ((PartialEquiv.refl β).restr s) = e.restr (e.source ∩ e ⁻¹' s) := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) <| by simp only [trans_source, restr_source, refl_source, univ_inter] rw [← inter_assoc, inter_self] theorem restr_trans (s : Set α) : (e.restr s).trans e' = (e.trans e').restr s := PartialEquiv.ext (fun _ => rfl) (fun _ => rfl) <| by simp [trans_source, inter_comm, inter_assoc] /-- A lemma commonly useful when `e` and `e'` are charts of a manifold. -/ theorem mem_symm_trans_source {e' : PartialEquiv α γ} {x : α} (he : x ∈ e.source) (he' : x ∈ e'.source) : e x ∈ (e.symm.trans e').source := ⟨e.mapsTo he, by rwa [mem_preimage, PartialEquiv.symm_symm, e.left_inv he]⟩ /-- `EqOnSource e e'` means that `e` and `e'` have the same source, and coincide there. Then `e` and `e'` should really be considered the same partial equiv. -/ def EqOnSource (e e' : PartialEquiv α β) : Prop := e.source = e'.source ∧ e.source.EqOn e e' /-- `EqOnSource` is an equivalence relation. This instance provides the `≈` notation between two `PartialEquiv`s. -/ instance eqOnSourceSetoid : Setoid (PartialEquiv α β) where r := EqOnSource iseqv := by constructor <;> simp only [Equivalence, EqOnSource, EqOn] <;> aesop theorem eqOnSource_refl : e ≈ e := Setoid.refl _ /-- Two equivalent partial equivs have the same source. -/ theorem EqOnSource.source_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.source = e'.source := h.1 /-- Two equivalent partial equivs coincide on the source. -/ theorem EqOnSource.eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : e.source.EqOn e e' := h.2 /-- Two equivalent partial equivs have the same target. -/ theorem EqOnSource.target_eq {e e' : PartialEquiv α β} (h : e ≈ e') : e.target = e'.target := by simp only [← image_source_eq_target, ← source_eq h, h.2.image_eq] /-- If two partial equivs are equivalent, so are their inverses. -/ theorem EqOnSource.symm' {e e' : PartialEquiv α β} (h : e ≈ e') : e.symm ≈ e'.symm := by refine ⟨target_eq h, eqOn_of_leftInvOn_of_rightInvOn e.leftInvOn ?_ ?_⟩ <;> simp only [symm_source, target_eq h, source_eq h, e'.symm_mapsTo] exact e'.rightInvOn.congr_right e'.symm_mapsTo (source_eq h ▸ h.eqOn.symm) /-- Two equivalent partial equivs have coinciding inverses on the target. -/ theorem EqOnSource.symm_eqOn {e e' : PartialEquiv α β} (h : e ≈ e') : EqOn e.symm e'.symm e.target := -- Porting note: `h.symm'` dot notation doesn't work anymore because `h` is not recognised as -- `PartialEquiv.EqOnSource` for some reason. eqOn (symm' h) /-- Composition of partial equivs respects equivalence. -/ theorem EqOnSource.trans' {e e' : PartialEquiv α β} {f f' : PartialEquiv β γ} (he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' := by constructor · rw [trans_source'', trans_source'', ← target_eq he, ← hf.1] exact (he.symm'.eqOn.mono inter_subset_left).image_eq · intro x hx rw [trans_source] at hx simp [Function.comp_apply, PartialEquiv.coe_trans, (he.2 hx.1).symm, hf.2 hx.2] /-- Restriction of partial equivs respects equivalence. -/ theorem EqOnSource.restr {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set α) : e.restr s ≈ e'.restr s := by constructor · simp [he.1] · intro x hx simp only [mem_inter_iff, restr_source] at hx exact he.2 hx.1 /-- Preimages are respected by equivalence. -/
Mathlib/Logic/Equiv/PartialEquiv.lean
724
725
theorem EqOnSource.source_inter_preimage_eq {e e' : PartialEquiv α β} (he : e ≈ e') (s : Set β) : e.source ∩ e ⁻¹' s = e'.source ∩ e' ⁻¹' s := by
rw [he.eqOn.inter_preimage_eq, source_eq he]
/- 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.Multiset.FinsetOps import Mathlib.Data.Multiset.Fold /-! # Lattice operations on multisets -/ namespace Multiset variable {α : Type*} /-! ### sup -/ section Sup -- can be defined with just `[Bot α]` where some lemmas hold without requiring `[OrderBot α]` variable [SemilatticeSup α] [OrderBot α] /-- Supremum of a multiset: `sup {a, b, c} = a ⊔ b ⊔ c` -/ def sup (s : Multiset α) : α := s.fold (· ⊔ ·) ⊥ @[simp] theorem sup_coe (l : List α) : sup (l : Multiset α) = l.foldr (· ⊔ ·) ⊥ := rfl @[simp] theorem sup_zero : (0 : Multiset α).sup = ⊥ := fold_zero _ _ @[simp] theorem sup_cons (a : α) (s : Multiset α) : (a ::ₘ s).sup = a ⊔ s.sup := fold_cons_left _ _ _ _ @[simp] theorem sup_singleton {a : α} : ({a} : Multiset α).sup = a := sup_bot_eq _ @[simp] theorem sup_add (s₁ s₂ : Multiset α) : (s₁ + s₂).sup = s₁.sup ⊔ s₂.sup := Eq.trans (by simp [sup]) (fold_add _ _ _ _ _) @[simp] theorem sup_le {s : Multiset α} {a : α} : s.sup ≤ a ↔ ∀ b ∈ s, b ≤ a := Multiset.induction_on s (by simp) (by simp +contextual [or_imp, forall_and]) theorem le_sup {s : Multiset α} {a : α} (h : a ∈ s) : a ≤ s.sup := sup_le.1 le_rfl _ h @[gcongr] theorem sup_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₁.sup ≤ s₂.sup := sup_le.2 fun _ hb => le_sup (h hb) variable [DecidableEq α] @[simp] theorem sup_dedup (s : Multiset α) : (dedup s).sup = s.sup := fold_dedup_idem _ _ _ @[simp] theorem sup_ndunion (s₁ s₂ : Multiset α) : (ndunion s₁ s₂).sup = s₁.sup ⊔ s₂.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp @[simp] theorem sup_union (s₁ s₂ : Multiset α) : (s₁ ∪ s₂).sup = s₁.sup ⊔ s₂.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_add]; simp @[simp] theorem sup_ndinsert (a : α) (s : Multiset α) : (ndinsert a s).sup = a ⊔ s.sup := by rw [← sup_dedup, dedup_ext.2, sup_dedup, sup_cons]; simp
Mathlib/Data/Multiset/Lattice.lean
79
80
theorem nodup_sup_iff {α : Type*} [DecidableEq α] {m : Multiset (Multiset α)} : m.sup.Nodup ↔ ∀ a : Multiset α, a ∈ m → a.Nodup := by
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x := AddCircle.coe_eq_zero_iff (2 * π) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
169
169
theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Basic import Mathlib.Algebra.GroupWithZero.Basic /-! # Basic Translation Lemmas Between Functions Defined for Continued Fractions ## Summary Some simple translation lemmas between the different definitions of functions defined in `Algebra.ContinuedFractions.Basic`. -/ namespace GenContFract section General /-! ### Translations Between General Access Functions Here we give some basic translations that hold by definition between the various methods that allow us to access the numerators and denominators of a continued fraction. -/ variable {α : Type*} {g : GenContFract α} {n : ℕ} theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq] theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by rw [terminatedAt_iff_s_none, partNum_none_iff_s_none] theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq] theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by rw [terminatedAt_iff_s_none, partDen_none_iff_s_none] theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq] theorem partDen_eq_s_b {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq] theorem exists_s_a_of_partNum {a : α} (nth_partNum_eq : g.partNums.get? n = some a) : ∃ gp, g.s.get? n = some gp ∧ gp.a = a := by simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq theorem exists_s_b_of_partDen {b : α} (nth_partDen_eq : g.partDens.get? n = some b) : ∃ gp, g.s.get? n = some gp ∧ gp.b = b := by simpa [partDens, Stream'.Seq.map_get?] using nth_partDen_eq end General section WithDivisionRing /-! ### Translations Between Computational Functions Here we give some basic translations that hold by definition for the computational methods of a continued fraction. -/ variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K] theorem nth_cont_eq_succ_nth_contAux : g.conts n = g.contsAux (n + 1) := rfl theorem num_eq_conts_a : g.nums n = (g.conts n).a := rfl theorem den_eq_conts_b : g.dens n = (g.conts n).b := rfl theorem conv_eq_num_div_den : g.convs n = g.nums n / g.dens n := rfl theorem conv_eq_conts_a_div_conts_b : g.convs n = (g.conts n).a / (g.conts n).b := rfl theorem exists_conts_a_of_num {A : K} (nth_num_eq : g.nums n = A) : ∃ conts, g.conts n = conts ∧ conts.a = A := by simpa theorem exists_conts_b_of_den {B : K} (nth_denom_eq : g.dens n = B) : ∃ conts, g.conts n = conts ∧ conts.b = B := by simpa @[simp] theorem zeroth_contAux_eq_one_zero : g.contsAux 0 = ⟨1, 0⟩ := rfl @[simp] theorem first_contAux_eq_h_one : g.contsAux 1 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_cont_eq_h_one : g.conts 0 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_num_eq_h : g.nums 0 = g.h := rfl @[simp] theorem zeroth_den_eq_one : g.dens 0 = 1 := rfl @[simp] theorem zeroth_conv_eq_h : g.convs 0 = g.h := by simp [conv_eq_num_div_den, num_eq_conts_a, den_eq_conts_b, div_one] theorem second_contAux_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.contsAux 2 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [zeroth_s_eq, contsAux, nextConts, nextDen, nextNum] theorem first_cont_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.conts 1 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [nth_cont_eq_succ_nth_contAux, second_contAux_eq zeroth_s_eq] theorem first_num_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.nums 1 = gp.b * g.h + gp.a := by simp [num_eq_conts_a, first_cont_eq zeroth_s_eq] theorem first_den_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.dens 1 = gp.b := by simp [den_eq_conts_b, first_cont_eq zeroth_s_eq] @[simp] theorem zeroth_conv'Aux_eq_zero {s : Stream'.Seq <| Pair K} : convs'Aux s 0 = (0 : K) := rfl @[simp] theorem zeroth_conv'_eq_h : g.convs' 0 = g.h := by simp [convs']
Mathlib/Algebra/ContinuedFractions/Translations.lean
146
147
theorem convs'Aux_succ_none {s : Stream'.Seq (Pair K)} (h : s.head = none) (n : ℕ) : convs'Aux s (n + 1) = 0 := by
simp [convs'Aux, h]
/- Copyright (c) 2023 Alex Keizer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Keizer -/ import Mathlib.Data.Vector.Basic import Mathlib.Data.Vector.Snoc /-! This file establishes a set of normalization lemmas for `map`/`mapAccumr` operations on vectors -/ variable {α β γ ζ σ σ₁ σ₂ φ : Type*} {n : ℕ} {s : σ} {s₁ : σ₁} {s₂ : σ₂} namespace List namespace Vector /-! ## Fold nested `mapAccumr`s into one -/ section Fold section Unary variable (xs : Vector α n) (f₁ : β → σ₁ → σ₁ × γ) (f₂ : α → σ₂ → σ₂ × β) @[simp] theorem mapAccumr_mapAccumr : mapAccumr f₁ (mapAccumr f₂ xs s₂).snd s₁ = let m := (mapAccumr (fun x s => let r₂ := f₂ x s.snd let r₁ := f₁ r₂.snd s.fst ((r₁.fst, r₂.fst), r₁.snd) ) xs (s₁, s₂)) (m.fst.fst, m.snd) := by induction xs using Vector.revInductionOn generalizing s₁ s₂ <;> simp_all @[simp]
Mathlib/Data/Vector/MapLemmas.lean
38
40
theorem mapAccumr_map {s : σ₁} (f₂ : α → β) : (mapAccumr f₁ (map f₂ xs) s) = (mapAccumr (fun x s => f₁ (f₂ x) s) xs s) := by
induction xs using Vector.revInductionOn generalizing s <;> simp_all
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Order.Interval.Multiset /-! # Finite intervals of naturals This file proves that `ℕ` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. ## TODO Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedMul` or `SuccOrder` and subsequently be moved upstream to `Order.Interval.Finset`. -/ assert_not_exists Ring open Finset Nat variable (a b c : ℕ) namespace Nat instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ where finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ finsetIco a b := ⟨List.range' a (b - a), List.nodup_range'⟩ finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ := rfl theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range'⟩ := rfl theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ := rfl theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ := rfl theorem uIcc_eq_range' : uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range'⟩ := rfl theorem Iio_eq_range : Iio = range := by ext b x rw [mem_Iio, mem_range] @[simp] theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range] lemma range_eq_Icc_zero_sub_one (n : ℕ) (hn : n ≠ 0) : range n = Icc 0 (n - 1) := by ext b simp_all only [mem_Icc, zero_le, true_and, mem_range] exact lt_iff_le_pred (zero_lt_of_ne_zero hn) theorem _root_.Finset.range_eq_Ico : range = Ico 0 := Ico_zero_eq_range.symm theorem range_succ_eq_Icc_zero (n : ℕ) : range (n + 1) = Icc 0 n := by rw [range_eq_Icc_zero_sub_one _ (Nat.add_one_ne_zero _), Nat.add_sub_cancel_right] @[simp] lemma card_Icc : #(Icc a b) = b + 1 - a := List.length_range' .. @[simp] lemma card_Ico : #(Ico a b) = b - a := List.length_range' .. @[simp] lemma card_Ioc : #(Ioc a b) = b - a := List.length_range' .. @[simp] lemma card_Ioo : #(Ioo a b) = b - a - 1 := List.length_range' .. @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := (card_Icc _ _).trans <| by rw [← Int.natCast_inj, Int.ofNat_sub] <;> omega @[simp] lemma card_Iic : #(Iic b) = b + 1 := by rw [Iic_eq_Icc, card_Icc, Nat.bot_eq_zero, Nat.sub_zero] @[simp] theorem card_Iio : #(Iio b) = b := by rw [Iio_eq_Ico, card_Ico, Nat.bot_eq_zero, Nat.sub_zero] @[deprecated Fintype.card_Icc (since := "2025-03-28")] theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by simp @[deprecated Fintype.card_Ico (since := "2025-03-28")] theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by simp @[deprecated Fintype.card_Ioc (since := "2025-03-28")] theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by simp @[deprecated Fintype.card_Ioo (since := "2025-03-28")] theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by simp @[deprecated Fintype.card_Iic (since := "2025-03-28")]
Mathlib/Order/Interval/Finset/Nat.lean
100
101
theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by
simp
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.MvPolynomial.Counit import Mathlib.Algebra.MvPolynomial.Invertible import Mathlib.RingTheory.WittVector.Defs /-! # Witt vectors This file verifies that the ring operations on `WittVector p R` satisfy the axioms of a commutative ring. ## Main definitions * `WittVector.map`: lifts a ring homomorphism `R →+* S` to a ring homomorphism `𝕎 R →+* 𝕎 S`. * `WittVector.ghostComponent n x`: evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`, producing a value in `R`. This is a ring homomorphism. * `WittVector.ghostMap`: a ring homomorphism `𝕎 R →+* (ℕ → R)`, obtained by packaging all the ghost components together. If `p` is invertible in `R`, then the ghost map is an equivalence, which we use to define the ring operations on `𝕎 R`. * `WittVector.CommRing`: the ring structure induced by the ghost components. ## Notation We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`. ## Implementation details As we prove that the ghost components respect the ring operations, we face a number of repetitive proofs. To avoid duplicating code we factor these proofs into a custom tactic, only slightly more powerful than a tactic macro. This tactic is not particularly useful outside of its applications in this file. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable section open MvPolynomial Function variable {p : ℕ} {R S : Type*} [CommRing R] [CommRing S] variable {α : Type*} {β : Type*} local notation "𝕎" => WittVector p local notation "W_" => wittPolynomial p -- type as `\bbW` open scoped Witt namespace WittVector /-- `f : α → β` induces a map from `𝕎 α` to `𝕎 β` by applying `f` componentwise. If `f` is a ring homomorphism, then so is `f`, see `WittVector.map f`. -/ def mapFun (f : α → β) : 𝕎 α → 𝕎 β := fun x => mk _ (f ∘ x.coeff) namespace mapFun -- Porting note: switched the proof to tactic mode. I think that `ext` was the issue. theorem injective (f : α → β) (hf : Injective f) : Injective (mapFun f : 𝕎 α → 𝕎 β) := by intros _ _ h ext p exact hf (congr_arg (fun x => coeff x p) h :) theorem surjective (f : α → β) (hf : Surjective f) : Surjective (mapFun f : 𝕎 α → 𝕎 β) := fun x => ⟨mk _ fun n => Classical.choose <| hf <| x.coeff n, by ext n; simp only [mapFun, coeff_mk, comp_apply, Classical.choose_spec (hf (x.coeff n))]⟩ /-- Auxiliary tactic for showing that `mapFun` respects the ring operations. -/ -- porting note: a very crude port. macro "map_fun_tac" : tactic => `(tactic| ( ext n simp only [mapFun, mk, comp_apply, zero_coeff, map_zero, -- Porting note: the lemmas on the next line do not have the `simp` tag in mathlib4 add_coeff, sub_coeff, mul_coeff, neg_coeff, nsmul_coeff, zsmul_coeff, pow_coeff, peval, map_aeval, algebraMap_int_eq, coe_eval₂Hom] <;> try { cases n <;> simp <;> done } <;> -- Porting note: this line solves `one` apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl <;> ext ⟨i, k⟩ <;> fin_cases i <;> rfl)) variable [Fact p.Prime] -- Porting note: using `(x y : 𝕎 R)` instead of `(x y : WittVector p R)` produced sorries. variable (f : R →+* S) (x y : WittVector p R) -- and until `pow`. -- We do not tag these lemmas as `@[simp]` because they will be bundled in `map` later on. theorem zero : mapFun f (0 : 𝕎 R) = 0 := by map_fun_tac theorem one : mapFun f (1 : 𝕎 R) = 1 := by map_fun_tac
Mathlib/RingTheory/WittVector/Basic.lean
102
102
theorem add : mapFun f (x + y) = mapFun f x + mapFun f y := by
map_fun_tac
/- 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]
Mathlib/MeasureTheory/Measure/Hausdorff.lean
336
351
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ε => ?_
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.FiniteDimensional import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`). Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `ω`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `ℂ` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `ℂ` ## Implementation notes Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `ω[o]`). Write ``` local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open Module lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ := LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm local notation "ω" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm] @[simp] theorem areaForm_apply_self (x : E) : ω x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1) · simp · norm_num theorem areaForm_swap (x y : E) : ω x y = -ω y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1) · ext i fin_cases i <;> rfl · norm_num @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E →L[ℝ] E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm) @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] · simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j · simp_all · simpa using h · simpa [real_inner_comm] using h · simp_all theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y = o.areaForm (φ.symm x) (φ.symm y) := by have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by ext i fin_cases i <;> rfl simp [areaForm_to_volumeForm, volumeForm_map, this] /-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.areaForm (φ x) (φ y) = o.areaForm x y := by convert o.areaForm_map φ (φ x) (φ y) · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] · simp · simp /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E := let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ := (InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm ↑to_dual.symm ∘ₗ ω @[simp] theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, LinearIsometryEquiv.coe_toLinearEquiv] rw [InnerProductSpace.toDual_symm_apply] norm_cast @[simp] theorem inner_rightAngleRotationAux₁_right (x y : E) : ⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by rw [real_inner_comm] simp [o.areaForm_swap y x] /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E := { o.rightAngleRotationAux₁ with norm_map' := fun x => by refine le_antisymm ?_ ?_ · rcases eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h | h · rw [← h] positivity refine le_of_mul_le_mul_right ?_ h rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left] exact o.areaForm_le x (o.rightAngleRotationAux₁ x) · let K : Submodule ℝ E := ℝ ∙ x have : Nontrivial Kᗮ := by apply nontrivial_of_finrank_pos (R := ℝ) have : finrank ℝ K ≤ Finset.card {x} := by rw [← Set.toFinset_singleton] exact finrank_span_le_card ({x} : Set E) have : Finset.card {x} = 1 := Finset.card_singleton x have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal have : finrank ℝ E = 2 := Fact.out omega obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0 have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2 have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h) refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖) rw [← o.abs_areaForm_of_orthogonal hw'] rw [← o.inner_rightAngleRotationAux₁_left x w] exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w } @[simp] theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) : o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by apply ext_inner_left ℝ intro y have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ := LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this, inner_neg_right] /-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation `J`). This automorphism squares to -1. We will define rotations in such a way that this automorphism is equal to rotation by 90 degrees. -/ irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E := LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁) (by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂]) local notation "J" => o.rightAngleRotation @[simp] theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_left x y @[simp] theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_right x y @[simp] theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by rw [rightAngleRotation] exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x @[simp] theorem rightAngleRotation_symm : LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by rw [rightAngleRotation] exact LinearIsometryEquiv.toLinearIsometry_injective rfl theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by simp [o.inner_rightAngleRotation_swap x y] theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ := LinearIsometryEquiv.inner_map_map J x y @[simp] theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg] @[simp] theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation] theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp @[simp] theorem rightAngleRotation_trans_rightAngleRotation : LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
281
284
theorem rightAngleRotation_neg_orientation (x : E) : (-o).rightAngleRotation x = -o.rightAngleRotation x := by
apply ext_inner_right ℝ intro y
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.Data.Complex.FiniteDimensional import Mathlib.MeasureTheory.Constructions.HaarToSphere import Mathlib.MeasureTheory.Integral.Gamma import Mathlib.MeasureTheory.Integral.Pi import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral /-! # Volume of balls Let `E` be a finite dimensional normed `ℝ`-vector space equipped with a Haar measure `μ`. We prove that `μ (Metric.ball 0 1) = (∫ (x : E), Real.exp (- ‖x‖ ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)` for any real number `p` with `0 < p`, see `MeasureTheorymeasure_unitBall_eq_integral_div_gamma`. We also prove the corresponding result to compute `μ {x : E | g x < 1}` where `g : E → ℝ` is a function defining a norm on `E`, see `MeasureTheory.measure_lt_one_eq_integral_div_gamma`. Using these formulas, we compute the volume of the unit balls in several cases. * `MeasureTheory.volume_sum_rpow_lt` / `MeasureTheory.volume_sum_rpow_le`: volume of the open and closed balls for the norm `Lp` over a real finite dimensional vector space with `1 ≤ p`. These are computed as `volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r}` and `volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) ≤ r}` since the spaces `PiLp` do not have a `MeasureSpace` instance. * `Complex.volume_sum_rpow_lt_one` / `Complex.volume_sum_rpow_lt`: same as above but for complex finite dimensional vector space. * `EuclideanSpace.volume_ball` / `EuclideanSpace.volume_closedBall` : volume of open and closed balls in a finite dimensional Euclidean space. * `InnerProductSpace.volume_ball` / `InnerProductSpace.volume_closedBall`: volume of open and closed balls in a finite dimensional real inner product space. * `Complex.volume_ball` / `Complex.volume_closedBall`: volume of open and closed balls in `ℂ`. -/ section general_case open MeasureTheory MeasureTheory.Measure Module ENNReal theorem MeasureTheory.measure_unitBall_eq_integral_div_gamma {E : Type*} {p : ℝ} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (hp : 0 < p) : μ (Metric.ball 0 1) = .ofReal ((∫ (x : E), Real.exp (- ‖x‖ ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)) := by obtain hE | hE := subsingleton_or_nontrivial E · rw [(Metric.nonempty_ball.mpr zero_lt_one).eq_zero, ← setIntegral_univ, Set.univ_nonempty.eq_zero, integral_singleton, finrank_zero_of_subsingleton, Nat.cast_zero, zero_div, zero_add, Real.Gamma_one, div_one, norm_zero, Real.zero_rpow hp.ne', neg_zero, Real.exp_zero, smul_eq_mul, mul_one, measureReal_def, ofReal_toReal (measure_ne_top μ {0})] · have : (0 : ℝ) < finrank ℝ E := Nat.cast_pos.mpr finrank_pos have : ((∫ y in Set.Ioi (0 : ℝ), y ^ (finrank ℝ E - 1) • Real.exp (-y ^ p)) / Real.Gamma ((finrank ℝ E) / p + 1)) * (finrank ℝ E) = 1 := by simp_rw [← Real.rpow_natCast _ (finrank ℝ E - 1), smul_eq_mul, Nat.cast_sub finrank_pos, Nat.cast_one] rw [integral_rpow_mul_exp_neg_rpow hp (by linarith), sub_add_cancel, Real.Gamma_add_one (ne_of_gt (by positivity))] field_simp; ring rw [integral_fun_norm_addHaar μ (fun x => Real.exp (- x ^ p)), nsmul_eq_mul, smul_eq_mul, mul_div_assoc, mul_div_assoc, mul_comm, mul_assoc, this, mul_one, ofReal_measureReal _] exact ne_of_lt measure_ball_lt_top variable {E : Type*} [AddCommGroup E] [Module ℝ E] [FiniteDimensional ℝ E] [mE : MeasurableSpace E] [tE : TopologicalSpace E] [IsTopologicalAddGroup E] [BorelSpace E] [T2Space E] [ContinuousSMul ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {g : E → ℝ} (h1 : g 0 = 0) (h2 : ∀ x, g (-x) = g x) (h3 : ∀ x y, g (x + y) ≤ g x + g y) (h4 : ∀ {x}, g x = 0 → x = 0) (h5 : ∀ r x, g (r • x) ≤ |r| * (g x)) include h1 h2 h3 h4 h5 theorem MeasureTheory.measure_lt_one_eq_integral_div_gamma {p : ℝ} (hp : 0 < p) : μ {x : E | g x < 1} = .ofReal ((∫ (x : E), Real.exp (- (g x) ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)) := by -- We copy `E` to a new type `F` on which we will put the norm defined by `g` letI F : Type _ := E letI : NormedAddCommGroup F := { norm := g dist := fun x y => g (x - y) dist_self := by simp only [_root_.sub_self, h1, forall_const] dist_comm := fun _ _ => by rw [← h2, neg_sub] dist_triangle := fun x y z => by convert h3 (x - y) (y - z) using 1; simp [F] edist := fun x y => .ofReal (g (x - y)) edist_dist := fun _ _ => rfl eq_of_dist_eq_zero := by convert fun _ _ h => eq_of_sub_eq_zero (h4 h) } letI : NormedSpace ℝ F := { norm_smul_le := fun _ _ ↦ h5 _ _ } -- We put the new topology on F letI : TopologicalSpace F := UniformSpace.toTopologicalSpace letI : MeasurableSpace F := borel F have : BorelSpace F := { measurable_eq := rfl } -- The map between `E` and `F` as a continuous linear equivalence let φ := @LinearEquiv.toContinuousLinearEquiv ℝ _ E _ _ tE _ _ F _ _ _ _ _ _ _ _ _ (LinearEquiv.refl ℝ E : E ≃ₗ[ℝ] F) -- The measure `ν` is the measure on `F` defined by `μ` -- Since we have two different topologies, it is necessary to specify the topology of E let ν : Measure F := @Measure.map E F mE _ φ μ have : IsAddHaarMeasure ν := @ContinuousLinearEquiv.isAddHaarMeasure_map E F ℝ ℝ _ _ _ _ _ _ tE _ _ _ _ _ _ _ mE _ _ _ φ μ _ convert (measure_unitBall_eq_integral_div_gamma ν hp) using 1 · rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_ball] · congr! simp_rw [Metric.ball, dist_zero_right] rfl · refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_ exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ · -- The map between `E` and `F` as a measurable equivalence let ψ := @Homeomorph.toMeasurableEquiv E F tE mE _ _ _ _ (@ContinuousLinearEquiv.toHomeomorph ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ) -- The map `ψ` is measure preserving by construction have : @MeasurePreserving E F mE _ ψ μ ν := @Measurable.measurePreserving E F mE _ ψ (@MeasurableEquiv.measurable E F mE _ ψ) _ rw [← this.integral_comp'] rfl theorem MeasureTheory.measure_le_eq_lt [Nontrivial E] (r : ℝ) : μ {x : E | g x ≤ r} = μ {x : E | g x < r} := by -- We copy `E` to a new type `F` on which we will put the norm defined by `g` letI F : Type _ := E letI : NormedAddCommGroup F := { norm := g dist := fun x y => g (x - y) dist_self := by simp only [_root_.sub_self, h1, forall_const] dist_comm := fun _ _ => by rw [← h2, neg_sub] dist_triangle := fun x y z => by convert h3 (x - y) (y - z) using 1; simp [F] edist := fun x y => .ofReal (g (x - y)) edist_dist := fun _ _ => rfl eq_of_dist_eq_zero := by convert fun _ _ h => eq_of_sub_eq_zero (h4 h) } letI : NormedSpace ℝ F := { norm_smul_le := fun _ _ ↦ h5 _ _ } -- We put the new topology on F letI : TopologicalSpace F := UniformSpace.toTopologicalSpace letI : MeasurableSpace F := borel F have : BorelSpace F := { measurable_eq := rfl } -- The map between `E` and `F` as a continuous linear equivalence let φ := @LinearEquiv.toContinuousLinearEquiv ℝ _ E _ _ tE _ _ F _ _ _ _ _ _ _ _ _ (LinearEquiv.refl ℝ E : E ≃ₗ[ℝ] F) -- The measure `ν` is the measure on `F` defined by `μ` -- Since we have two different topologies, it is necessary to specify the topology of E let ν : Measure F := @Measure.map E F mE _ φ μ have : IsAddHaarMeasure ν := @ContinuousLinearEquiv.isAddHaarMeasure_map E F ℝ ℝ _ _ _ _ _ _ tE _ _ _ _ _ _ _ mE _ _ _ φ μ _ convert addHaar_closedBall_eq_addHaar_ball ν 0 r using 1 · rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_closedBall] · congr! simp_rw [Metric.closedBall, dist_zero_right] rfl · refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_ exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ · rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_ball] · congr! simp_rw [Metric.ball, dist_zero_right] rfl · refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_ exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ end general_case section LpSpace open Real Fintype ENNReal Module MeasureTheory MeasureTheory.Measure variable (ι : Type*) [Fintype ι] {p : ℝ} theorem MeasureTheory.volume_sum_rpow_lt_one (hp : 1 ≤ p) : volume {x : ι → ℝ | ∑ i, |x i| ^ p < 1} = .ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by have h₁ : 0 < p := by linarith have h₂ : ∀ x : ι → ℝ, 0 ≤ ∑ i, |x i| ^ p := by refine fun _ => Finset.sum_nonneg' ?_ exact fun i => (fun _ => rpow_nonneg (abs_nonneg _) _) _ -- We collect facts about `Lp` norms that will be used in `measure_lt_one_eq_integral_div_gamma` have eq_norm := fun x : ι → ℝ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x) ((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁)) simp_rw [toReal_ofReal (le_of_lt h₁), Real.norm_eq_abs] at eq_norm have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ofReal_one ▸ (ofReal_le_ofReal hp)) have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) have eq_zero := fun x : ι → ℝ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) (a := x) have nm_neg := fun x : ι → ℝ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x have nm_add := fun x y : ι → ℝ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x y simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add have nm_smul := fun (r : ℝ) (x : ι → ℝ) => norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℝ)) r x simp_rw [eq_norm, norm_eq_abs] at nm_smul -- We use `measure_lt_one_eq_integral_div_gamma` with `g` equals to the norm `L_p` convert (measure_lt_one_eq_integral_div_gamma (volume : Measure (ι → ℝ)) (g := fun x => (∑ i, |x i| ^ p) ^ (1 / p)) nm_zero nm_neg nm_add (eq_zero _).mp (fun r x => nm_smul r x) (by linarith : 0 < p)) using 4 · rw [rpow_lt_one_iff' _ (one_div_pos.mpr h₁)] exact Finset.sum_nonneg' (fun _ => rpow_nonneg (abs_nonneg _) _) · simp_rw [← rpow_mul (h₂ _), div_mul_cancel₀ _ (ne_of_gt h₁), Real.rpow_one, ← Finset.sum_neg_distrib, exp_sum] rw [integral_fintype_prod_eq_pow ι fun x : ℝ => exp (- |x| ^ p), integral_comp_abs (f := fun x => exp (- x ^ p)), integral_exp_neg_rpow h₁] · rw [finrank_fintype_fun_eq_card] theorem MeasureTheory.volume_sum_rpow_lt [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) : volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r} = (.ofReal r) ^ card ι * .ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by have h₁ (x : ι → ℝ) : 0 ≤ ∑ i, |x i| ^ p := by positivity have h₂ : ∀ x : ι → ℝ, 0 ≤ (∑ i, |x i| ^ p) ^ (1 / p) := fun x => rpow_nonneg (h₁ x) _ obtain hr | hr := le_or_lt r 0 · have : {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r} = ∅ := by ext x refine ⟨fun hx => ?_, fun hx => hx.elim⟩ exact not_le.mpr (lt_of_lt_of_le (Set.mem_setOf.mp hx) hr) (h₂ x) rw [this, measure_empty, ← zero_eq_ofReal.mpr hr, zero_pow Fin.pos'.ne', zero_mul] · rw [← volume_sum_rpow_lt_one _ hp, ← ofReal_pow (le_of_lt hr), ← finrank_pi ℝ] convert addHaar_smul_of_nonneg volume (le_of_lt hr) {x : ι → ℝ | ∑ i, |x i| ^ p < 1} using 2 simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hr), Set.preimage_setOf_eq, Pi.smul_apply, smul_eq_mul, abs_mul, mul_rpow (abs_nonneg _) (abs_nonneg _), abs_inv, inv_rpow (abs_nonneg _), ← Finset.mul_sum, abs_eq_self.mpr (le_of_lt hr), inv_mul_lt_iff₀ (rpow_pos_of_pos hr _), mul_one, ← rpow_lt_rpow_iff (rpow_nonneg (h₁ _) _) (le_of_lt hr) (by linarith : 0 < p), ← rpow_mul (h₁ _), div_mul_cancel₀ _ (ne_of_gt (by linarith) : p ≠ 0), Real.rpow_one] theorem MeasureTheory.volume_sum_rpow_le [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) : volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) ≤ r} = (.ofReal r) ^ card ι * .ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by have h₁ : 0 < p := by linarith -- We collect facts about `Lp` norms that will be used in `measure_le_one_eq_lt_one` have eq_norm := fun x : ι → ℝ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x) ((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁)) simp_rw [toReal_ofReal (le_of_lt h₁), Real.norm_eq_abs] at eq_norm have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ofReal_one ▸ (ofReal_le_ofReal hp)) have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) have eq_zero := fun x : ι → ℝ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) (a := x) have nm_neg := fun x : ι → ℝ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x have nm_add := fun x y : ι → ℝ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x y simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add have nm_smul := fun (r : ℝ) (x : ι → ℝ) => norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℝ)) r x simp_rw [eq_norm, norm_eq_abs] at nm_smul rw [measure_le_eq_lt _ nm_zero (fun x ↦ nm_neg x) (fun x y ↦ nm_add x y) (eq_zero _).mp (fun r x => nm_smul r x), volume_sum_rpow_lt _ hp] theorem Complex.volume_sum_rpow_lt_one {p : ℝ} (hp : 1 ≤ p) : volume {x : ι → ℂ | ∑ i, ‖x i‖ ^ p < 1} = .ofReal ((π * Real.Gamma (2 / p + 1)) ^ card ι / Real.Gamma (2 * card ι / p + 1)) := by have h₁ : 0 < p := by linarith have h₂ : ∀ x : ι → ℂ, 0 ≤ ∑ i, ‖x i‖ ^ p := by refine fun _ => Finset.sum_nonneg' ?_ exact fun i => (fun _ => rpow_nonneg (norm_nonneg _) _) _ -- We collect facts about `Lp` norms that will be used in `measure_lt_one_eq_integral_div_gamma` have eq_norm := fun x : ι → ℂ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x) ((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁)) simp_rw [toReal_ofReal (le_of_lt h₁)] at eq_norm have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ENNReal.ofReal_one ▸ (ofReal_le_ofReal hp)) have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) have eq_zero := fun x : ι → ℂ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) (a := x) have nm_neg := fun x : ι → ℂ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) x have nm_add := fun x y : ι → ℂ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℂ)) x y simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add have nm_smul := fun (r : ℝ) (x : ι → ℂ) => norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℂ)) r x simp_rw [eq_norm] at nm_smul -- We use `measure_lt_one_eq_integral_div_gamma` with `g` equals to the norm `L_p` convert measure_lt_one_eq_integral_div_gamma (volume : Measure (ι → ℂ)) (g := fun x => (∑ i, ‖x i‖ ^ p) ^ (1 / p)) nm_zero nm_neg nm_add (eq_zero _).mp (fun r x => nm_smul r x) (by linarith : 0 < p) using 4 · rw [rpow_lt_one_iff' _ (one_div_pos.mpr h₁)] exact Finset.sum_nonneg' (fun _ => rpow_nonneg (norm_nonneg _) _) · simp_rw [← rpow_mul (h₂ _), div_mul_cancel₀ _ (ne_of_gt h₁), Real.rpow_one, ← Finset.sum_neg_distrib, Real.exp_sum] rw [integral_fintype_prod_eq_pow ι fun x : ℂ => Real.exp (- ‖x‖ ^ p), Complex.integral_exp_neg_rpow hp] · rw [finrank_pi_fintype, Complex.finrank_real_complex, Finset.sum_const, smul_eq_mul, Nat.cast_mul, Nat.cast_ofNat, Fintype.card, mul_comm]
Mathlib/MeasureTheory/Measure/Lebesgue/VolumeOfBalls.lean
273
295
theorem Complex.volume_sum_rpow_lt [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) : volume {x : ι → ℂ | (∑ i, ‖x i‖ ^ p) ^ (1 / p) < r} = (.ofReal r) ^ (2 * card ι) * .ofReal ((π * Real.Gamma (2 / p + 1)) ^ card ι / Real.Gamma (2 * card ι / p + 1)) := by
have h₁ (x : ι → ℂ) : 0 ≤ ∑ i, ‖x i‖ ^ p := by positivity have h₂ : ∀ x : ι → ℂ, 0 ≤ (∑ i, ‖x i‖ ^ p) ^ (1 / p) := fun x => rpow_nonneg (h₁ x) _ obtain hr | hr := le_or_lt r 0 · have : {x : ι → ℂ | (∑ i, ‖x i‖ ^ p) ^ (1 / p) < r} = ∅ := by ext x refine ⟨fun hx => ?_, fun hx => hx.elim⟩ exact not_le.mpr (lt_of_lt_of_le (Set.mem_setOf.mp hx) hr) (h₂ x) rw [this, measure_empty, ← zero_eq_ofReal.mpr hr, zero_pow Fin.pos'.ne', zero_mul] · rw [← Complex.volume_sum_rpow_lt_one _ hp, ← ENNReal.ofReal_pow (le_of_lt hr)] convert addHaar_smul_of_nonneg volume (le_of_lt hr) {x : ι → ℂ | ∑ i, ‖x i‖ ^ p < 1} using 2 · simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hr), Set.preimage_setOf_eq, Pi.smul_apply, norm_smul, mul_rpow (norm_nonneg _) (norm_nonneg _), Real.norm_eq_abs, abs_inv, inv_rpow (abs_nonneg _), ← Finset.mul_sum, abs_eq_self.mpr (le_of_lt hr), inv_mul_lt_iff₀ (rpow_pos_of_pos hr _), mul_one, ← rpow_lt_rpow_iff (rpow_nonneg (h₁ _) _) (le_of_lt hr) (by linarith : 0 < p), ← rpow_mul (h₁ _), div_mul_cancel₀ _ (ne_of_gt (by linarith) : p ≠ 0), Real.rpow_one] · simp_rw [finrank_pi_fintype ℝ, Complex.finrank_real_complex, Finset.sum_const, smul_eq_mul, mul_comm, Fintype.card] theorem Complex.volume_sum_rpow_le [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) :
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Int.DivMod import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common import Mathlib.Tactic.Attr.Register /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas` ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; -/ assert_not_exists Monoid Finset open Fin Nat Function attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 namespace Fin @[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} : (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 := mk.inj_iff @[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} : 1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by simp [eq_comm] instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl section coe /-! ### coercions and constructions -/ theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := Fin.ext_iff.symm theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := Fin.ext_iff.not theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := Fin.ext_iff -- syntactic tautologies now /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [funext_iff] /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [funext_iff] /-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires `k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/ protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] end coe section Order /-! ### order -/ theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps -fullyApplied apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) @[deprecated (since := "2025-02-24")] alias val_zero' := val_zero /-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val @[simp, norm_cast]
Mathlib/Data/Fin/Basic.lean
212
215
theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by
rw [Fin.ext_iff, val_zero] theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 :=
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero] @[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply] theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero] @[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply] @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div]
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
76
77
theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by
simp_rw [logb, log_div hx hy, sub_div]
/- 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, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Adjoint of operators on Hilbert spaces Given an operator `A : E →L[𝕜] F`, where `E` and `F` are Hilbert spaces, its adjoint `adjoint A : F →L[𝕜] E` is the unique operator such that `⟪x, A y⟫ = ⟪adjoint A x, y⟫` for all `x` and `y`. We then use this to put a C⋆-algebra structure on `E →L[𝕜] E` with the adjoint as the star operation. This construction is used to define an adjoint for linear maps (i.e. not continuous) between finite dimensional spaces. ## Main definitions * `ContinuousLinearMap.adjoint : (E →L[𝕜] F) ≃ₗᵢ⋆[𝕜] (F →L[𝕜] E)`: the adjoint of a continuous linear map, bundled as a conjugate-linear isometric equivalence. * `LinearMap.adjoint : (E →ₗ[𝕜] F) ≃ₗ⋆[𝕜] (F →ₗ[𝕜] E)`: the adjoint of a linear map between finite-dimensional spaces, this time only as a conjugate-linear equivalence, since there is no norm defined on these maps. ## Implementation notes * The continuous conjugate-linear version `adjointAux` is only an intermediate definition and is not meant to be used outside this file. ## Tags adjoint -/ noncomputable section open RCLike open scoped ComplexConjugate variable {𝕜 E F G : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] variable [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 F] [InnerProductSpace 𝕜 G] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-! ### Adjoint operator -/ open InnerProductSpace namespace ContinuousLinearMap variable [CompleteSpace E] [CompleteSpace G] -- Note: made noncomputable to stop excess compilation -- https://github.com/leanprover-community/mathlib4/issues/7103 /-- The adjoint, as a continuous conjugate-linear map. This is only meant as an auxiliary definition for the main definition `adjoint`, where this is bundled as a conjugate-linear isometric equivalence. -/ noncomputable def adjointAux : (E →L[𝕜] F) →L⋆[𝕜] F →L[𝕜] E := (ContinuousLinearMap.compSL _ _ _ _ _ ((toDual 𝕜 E).symm : NormedSpace.Dual 𝕜 E →L⋆[𝕜] E)).comp (toSesqForm : (E →L[𝕜] F) →L[𝕜] F →L⋆[𝕜] NormedSpace.Dual 𝕜 E) @[simp] theorem adjointAux_apply (A : E →L[𝕜] F) (x : F) : adjointAux A x = ((toDual 𝕜 E).symm : NormedSpace.Dual 𝕜 E → E) ((toSesqForm A) x) := rfl theorem adjointAux_inner_left (A : E →L[𝕜] F) (x : E) (y : F) : ⟪adjointAux A y, x⟫ = ⟪y, A x⟫ := by rw [adjointAux_apply, toDual_symm_apply, toSesqForm_apply_coe, coe_comp', innerSL_apply_coe, Function.comp_apply] theorem adjointAux_inner_right (A : E →L[𝕜] F) (x : E) (y : F) : ⟪x, adjointAux A y⟫ = ⟪A x, y⟫ := by rw [← inner_conj_symm, adjointAux_inner_left, inner_conj_symm] variable [CompleteSpace F] theorem adjointAux_adjointAux (A : E →L[𝕜] F) : adjointAux (adjointAux A) = A := by ext v refine ext_inner_left 𝕜 fun w => ?_ rw [adjointAux_inner_right, adjointAux_inner_left] @[simp]
Mathlib/Analysis/InnerProductSpace/Adjoint.lean
92
95
theorem adjointAux_norm (A : E →L[𝕜] F) : ‖adjointAux A‖ = ‖A‖ := by
refine le_antisymm ?_ ?_ · refine ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) fun x => ?_ rw [adjointAux_apply, LinearIsometryEquiv.norm_map]
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Peter Pfaffelhuber, Yaël Dillies, Kin Yau James Wong -/ import Mathlib.MeasureTheory.MeasurableSpace.Constructions import Mathlib.MeasureTheory.PiSystem import Mathlib.Topology.Constructions /-! # π-systems of cylinders and square cylinders The instance `MeasurableSpace.pi` on `∀ i, α i`, where each `α i` has a `MeasurableSpace` `m i`, is defined as `⨆ i, (m i).comap (fun a => a i)`. That is, a function `g : β → ∀ i, α i` is measurable iff for all `i`, the function `b ↦ g b i` is measurable. We define two π-systems generating `MeasurableSpace.pi`, cylinders and square cylinders. ## Main definitions Given a finite set `s` of indices, a cylinder is the product of a set of `∀ i : s, α i` and of `univ` on the other indices. A square cylinder is a cylinder for which the set on `∀ i : s, α i` is a product set. * `cylinder s S`: cylinder with base set `S : Set (∀ i : s, α i)` where `s` is a `Finset` * `squareCylinders C` with `C : ∀ i, Set (Set (α i))`: set of all square cylinders such that for all `i` in the finset defining the box, the projection to `α i` belongs to `C i`. The main application of this is with `C i = {s : Set (α i) | MeasurableSet s}`. * `measurableCylinders`: set of all cylinders with measurable base sets. * `cylinderEvents Δ`: The σ-algebra of cylinder events on `Δ`. It is the smallest σ-algebra making the projections on the `i`-th coordinate continuous for all `i ∈ Δ`. ## Main statements * `generateFrom_squareCylinders`: square cylinders formed from measurable sets generate the product σ-algebra * `generateFrom_measurableCylinders`: cylinders formed from measurable sets generate the product σ-algebra -/ open Function Set namespace MeasureTheory variable {ι : Type _} {α : ι → Type _} section squareCylinders /-- Given a finite set `s` of indices, a square cylinder is the product of a set `S` of `∀ i : s, α i` and of `univ` on the other indices. The set `S` is a product of sets `t i` such that for all `i : s`, `t i ∈ C i`. `squareCylinders` is the set of all such squareCylinders. -/ def squareCylinders (C : ∀ i, Set (Set (α i))) : Set (Set (∀ i, α i)) := {S | ∃ s : Finset ι, ∃ t ∈ univ.pi C, S = (s : Set ι).pi t} theorem squareCylinders_eq_iUnion_image (C : ∀ i, Set (Set (α i))) : squareCylinders C = ⋃ s : Finset ι, (fun t ↦ (s : Set ι).pi t) '' univ.pi C := by ext1 f simp only [squareCylinders, mem_iUnion, mem_image, mem_univ_pi, exists_prop, mem_setOf_eq, eq_comm (a := f)] theorem isPiSystem_squareCylinders {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i)) (hC_univ : ∀ i, univ ∈ C i) : IsPiSystem (squareCylinders C) := by rintro S₁ ⟨s₁, t₁, h₁, rfl⟩ S₂ ⟨s₂, t₂, h₂, rfl⟩ hst_nonempty classical let t₁' := s₁.piecewise t₁ (fun i ↦ univ) let t₂' := s₂.piecewise t₂ (fun i ↦ univ) have h1 : ∀ i ∈ (s₁ : Set ι), t₁ i = t₁' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h1' : ∀ i ∉ (s₁ : Set ι), t₁' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi have h2 : ∀ i ∈ (s₂ : Set ι), t₂ i = t₂' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h2' : ∀ i ∉ (s₂ : Set ι), t₂' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, ← union_pi_inter h1' h2'] refine ⟨s₁ ∪ s₂, fun i ↦ t₁' i ∩ t₂' i, ?_, ?_⟩ · rw [mem_univ_pi] intro i have : (t₁' i ∩ t₂' i).Nonempty := by obtain ⟨f, hf⟩ := hst_nonempty rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, mem_inter_iff, mem_pi, mem_pi] at hf refine ⟨f i, ⟨?_, ?_⟩⟩ · by_cases hi₁ : i ∈ s₁ · exact hf.1 i hi₁ · rw [h1' i hi₁] exact mem_univ _ · by_cases hi₂ : i ∈ s₂ · exact hf.2 i hi₂ · rw [h2' i hi₂] exact mem_univ _ refine hC i _ ?_ _ ?_ this · by_cases hi₁ : i ∈ s₁ · rw [← h1 i hi₁] exact h₁ i (mem_univ _) · rw [h1' i hi₁] exact hC_univ i · by_cases hi₂ : i ∈ s₂ · rw [← h2 i hi₂] exact h₂ i (mem_univ _) · rw [h2' i hi₂] exact hC_univ i · rw [Finset.coe_union] theorem comap_eval_le_generateFrom_squareCylinders_singleton (α : ι → Type*) [m : ∀ i, MeasurableSpace (α i)] (i : ι) : MeasurableSpace.comap (Function.eval i) (m i) ≤ MeasurableSpace.generateFrom ((fun t ↦ ({i} : Set ι).pi t) '' univ.pi fun i ↦ {s : Set (α i) | MeasurableSet s}) := by simp only [Function.eval, singleton_pi] rw [MeasurableSpace.comap_eq_generateFrom] refine MeasurableSpace.generateFrom_mono fun S ↦ ?_ simp only [mem_setOf_eq, mem_image, mem_univ_pi, forall_exists_index, and_imp] intro t ht h classical refine ⟨fun j ↦ if hji : j = i then by convert t else univ, fun j ↦ ?_, ?_⟩ · by_cases hji : j = i · simp only [hji, eq_self_iff_true, eq_mpr_eq_cast, dif_pos] convert ht simp only [id_eq, cast_heq] · simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ] · simp only [id_eq, eq_mpr_eq_cast, ← h] ext1 x simp only [singleton_pi, Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage] /-- The square cylinders formed from measurable sets generate the product σ-algebra. -/ theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] : MeasurableSpace.generateFrom (squareCylinders fun i ↦ {s : Set (α i) | MeasurableSet s}) = MeasurableSpace.pi := by apply le_antisymm · rw [MeasurableSpace.generateFrom_le_iff] rintro S ⟨s, t, h, rfl⟩ simp only [mem_univ_pi, mem_setOf_eq] at h exact MeasurableSet.pi (Finset.countable_toSet _) (fun i _ ↦ h i) · refine iSup_le fun i ↦ ?_ refine (comap_eval_le_generateFrom_squareCylinders_singleton α i).trans ?_ refine MeasurableSpace.generateFrom_mono ?_ rw [← Finset.coe_singleton, squareCylinders_eq_iUnion_image] exact subset_iUnion (fun (s : Finset ι) ↦ (fun t : ∀ i, Set (α i) ↦ (s : Set ι).pi t) '' univ.pi (fun i ↦ setOf MeasurableSet)) ({i} : Finset ι) end squareCylinders section cylinder /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. -/ def cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : Set (∀ i, α i) := s.restrict ⁻¹' S @[simp] theorem mem_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) (f : ∀ i, α i) : f ∈ cylinder s S ↔ s.restrict f ∈ S := mem_preimage @[simp] theorem cylinder_empty (s : Finset ι) : cylinder s (∅ : Set (∀ i : s, α i)) = ∅ := by rw [cylinder, preimage_empty] @[simp] theorem cylinder_univ (s : Finset ι) : cylinder s (univ : Set (∀ i : s, α i)) = univ := by rw [cylinder, preimage_univ] @[simp] theorem cylinder_eq_empty_iff [h_nonempty : Nonempty (∀ i, α i)] (s : Finset ι) (S : Set (∀ i : s, α i)) : cylinder s S = ∅ ↔ S = ∅ := by refine ⟨fun h ↦ ?_, fun h ↦ by (rw [h]; exact cylinder_empty _)⟩ by_contra hS rw [← Ne, ← nonempty_iff_ne_empty] at hS let f := hS.some have hf : f ∈ S := hS.choose_spec classical let f' : ∀ i, α i := fun i ↦ if hi : i ∈ s then f ⟨i, hi⟩ else h_nonempty.some i have hf' : f' ∈ cylinder s S := by rw [mem_cylinder] simpa only [Finset.restrict_def, Finset.coe_mem, dif_pos, f'] rw [h] at hf' exact not_mem_empty _ hf' theorem inter_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∩ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∩ Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by ext1 f; simp only [mem_inter_iff, mem_cylinder, mem_setOf_eq]; rfl theorem inter_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∩ cylinder s S₂ = cylinder s (S₁ ∩ S₂) := by classical rw [inter_cylinder]; rfl theorem union_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∪ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∪ Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by ext1 f; simp only [mem_union, mem_cylinder, mem_setOf_eq]; rfl theorem union_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∪ cylinder s S₂ = cylinder s (S₁ ∪ S₂) := by classical rw [union_cylinder]; rfl theorem compl_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : (cylinder s S)ᶜ = cylinder s (Sᶜ) := by ext1 f; simp only [mem_compl_iff, mem_cylinder] theorem diff_cylinder_same (s : Finset ι) (S T : Set (∀ i : s, α i)) : cylinder s S \ cylinder s T = cylinder s (S \ T) := by ext1 f; simp only [mem_diff, mem_cylinder] theorem eq_of_cylinder_eq_of_subset [h_nonempty : Nonempty (∀ i, α i)] {I J : Finset ι} {S : Set (∀ i : I, α i)} {T : Set (∀ i : J, α i)} (h_eq : cylinder I S = cylinder J T) (hJI : J ⊆ I) : S = Finset.restrict₂ hJI ⁻¹' T := by rw [Set.ext_iff] at h_eq simp only [mem_cylinder] at h_eq ext1 f simp only [mem_preimage] classical specialize h_eq fun i ↦ if hi : i ∈ I then f ⟨i, hi⟩ else h_nonempty.some i have h_mem : ∀ j : J, ↑j ∈ I := fun j ↦ hJI j.prop simpa only [Finset.restrict_def, Finset.coe_mem, dite_true, h_mem] using h_eq theorem cylinder_eq_cylinder_union [DecidableEq ι] (I : Finset ι) (S : Set (∀ i : I, α i)) (J : Finset ι) : cylinder I S = cylinder (I ∪ J) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S) := by ext1 f; simp only [mem_cylinder, Finset.restrict_def, Finset.restrict₂_def, mem_preimage] theorem disjoint_cylinder_iff [Nonempty (∀ i, α i)] {s t : Finset ι} {S : Set (∀ i : s, α i)} {T : Set (∀ i : t, α i)} [DecidableEq ι] : Disjoint (cylinder s S) (cylinder t T) ↔ Disjoint (Finset.restrict₂ Finset.subset_union_left ⁻¹' S) (Finset.restrict₂ Finset.subset_union_right ⁻¹' T) := by simp_rw [Set.disjoint_iff, subset_empty_iff, inter_cylinder, cylinder_eq_empty_iff] theorem IsClosed.cylinder [∀ i, TopologicalSpace (α i)] (s : Finset ι) {S : Set (∀ i : s, α i)} (hs : IsClosed S) : IsClosed (cylinder s S) := hs.preimage (continuous_pi fun _ ↦ continuous_apply _) theorem _root_.MeasurableSet.cylinder [∀ i, MeasurableSpace (α i)] (s : Finset ι) {S : Set (∀ i : s, α i)} (hS : MeasurableSet S) : MeasurableSet (cylinder s S) := measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS /-- The indicator of a cylinder only depends on the variables whose the cylinder depends on. -/ theorem dependsOn_cylinder_indicator_const {M : Type*} [Zero M] {I : Finset ι} (S : Set (Π i : I, α i)) (c : M) : DependsOn ((cylinder I S).indicator (fun _ ↦ c)) I := fun x y hxy ↦ Set.indicator_const_eq_indicator_const (by simp [Finset.restrict_def, hxy]) end cylinder section cylinders /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. `measurableCylinders` is the set of all cylinders with measurable base `S`. -/ def measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : Set (Set (∀ i, α i)) := ⋃ (s) (S) (_ : MeasurableSet S), {cylinder s S} theorem empty_mem_measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : ∅ ∈ measurableCylinders α := by simp_rw [measurableCylinders, mem_iUnion, mem_singleton_iff] exact ⟨∅, ∅, MeasurableSet.empty, (cylinder_empty _).symm⟩ variable [∀ i, MeasurableSpace (α i)] {s t : Set (∀ i, α i)} @[simp] theorem mem_measurableCylinders (t : Set (∀ i, α i)) : t ∈ measurableCylinders α ↔ ∃ s S, MeasurableSet S ∧ t = cylinder s S := by simp_rw [measurableCylinders, mem_iUnion, exists_prop, mem_singleton_iff] @[measurability] theorem _root_.MeasurableSet.of_mem_measurableCylinders {s : Set (Π i, α i)} (hs : s ∈ measurableCylinders α) : MeasurableSet s := by obtain ⟨I, t, mt, rfl⟩ := (mem_measurableCylinders s).1 hs exact mt.cylinder /-- A finset `s` such that `t = cylinder s S`. `S` is given by `measurableCylinders.set`. -/ noncomputable def measurableCylinders.finset (ht : t ∈ measurableCylinders α) : Finset ι := ((mem_measurableCylinders t).mp ht).choose /-- A set `S` such that `t = cylinder s S`. `s` is given by `measurableCylinders.finset`. -/ def measurableCylinders.set (ht : t ∈ measurableCylinders α) : Set (∀ i : measurableCylinders.finset ht, α i) := ((mem_measurableCylinders t).mp ht).choose_spec.choose theorem measurableCylinders.measurableSet (ht : t ∈ measurableCylinders α) : MeasurableSet (measurableCylinders.set ht) := ((mem_measurableCylinders t).mp ht).choose_spec.choose_spec.left theorem measurableCylinders.eq_cylinder (ht : t ∈ measurableCylinders α) : t = cylinder (measurableCylinders.finset ht) (measurableCylinders.set ht) := ((mem_measurableCylinders t).mp ht).choose_spec.choose_spec.right theorem cylinder_mem_measurableCylinders (s : Finset ι) (S : Set (∀ i : s, α i)) (hS : MeasurableSet S) : cylinder s S ∈ measurableCylinders α := by rw [mem_measurableCylinders]; exact ⟨s, S, hS, rfl⟩ theorem inter_mem_measurableCylinders (hs : s ∈ measurableCylinders α) (ht : t ∈ measurableCylinders α) : s ∩ t ∈ measurableCylinders α := by rw [mem_measurableCylinders] at * obtain ⟨s₁, S₁, hS₁, rfl⟩ := hs obtain ⟨s₂, S₂, hS₂, rfl⟩ := ht classical refine ⟨s₁ ∪ s₂, Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∩ {f | Finset.restrict₂ Finset.subset_union_right f ∈ S₂}, ?_, ?_⟩ · refine MeasurableSet.inter ?_ ?_ · exact measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS₁ · exact measurable_pi_lambda _ (fun _ ↦ measurable_pi_apply _) hS₂ · exact inter_cylinder _ _ _ _ theorem isPiSystem_measurableCylinders : IsPiSystem (measurableCylinders α) := fun _ hS _ hT _ ↦ inter_mem_measurableCylinders hS hT theorem compl_mem_measurableCylinders (hs : s ∈ measurableCylinders α) : sᶜ ∈ measurableCylinders α := by rw [mem_measurableCylinders] at hs ⊢ obtain ⟨s, S, hS, rfl⟩ := hs refine ⟨s, Sᶜ, hS.compl, ?_⟩ rw [compl_cylinder]
Mathlib/MeasureTheory/Constructions/Cylinders.lean
335
339
theorem univ_mem_measurableCylinders (α : ι → Type*) [∀ i, MeasurableSpace (α i)] : Set.univ ∈ measurableCylinders α := by
rw [← compl_empty]; exact compl_mem_measurableCylinders (empty_mem_measurableCylinders α) theorem union_mem_measurableCylinders (hs : s ∈ measurableCylinders α)
/- 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.Algebra.Algebra.Rat import Mathlib.Data.Nat.Cast.Field import Mathlib.RingTheory.PowerSeries.Basic /-! # Definition of well-known power series In this file we define the following power series: * `PowerSeries.invUnitsSub`: given `u : Rˣ`, this is the series for `1 / (u - x)`. It is given by `∑ n, x ^ n /ₚ u ^ (n + 1)`. * `PowerSeries.invOneSubPow`: given a commutative ring `S` and a number `d : ℕ`, `PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`. When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive, `PowerSeries.invOneSubPow S d` will be `∑ n, Nat.choose (d - 1 + n) (d - 1)`. * `PowerSeries.sin`, `PowerSeries.cos`, `PowerSeries.exp` : power series for sin, cosine, and exponential functions. -/ namespace PowerSeries section Ring variable {R S : Type*} [Ring R] [Ring S] /-- The power series for `1 / (u - x)`. -/ def invUnitsSub (u : Rˣ) : PowerSeries R := mk fun n => 1 /ₚ u ^ (n + 1) @[simp] theorem coeff_invUnitsSub (u : Rˣ) (n : ℕ) : coeff R n (invUnitsSub u) = 1 /ₚ u ^ (n + 1) := coeff_mk _ _ @[simp] theorem constantCoeff_invUnitsSub (u : Rˣ) : constantCoeff R (invUnitsSub u) = 1 /ₚ u := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_invUnitsSub, zero_add, pow_one] @[simp] theorem invUnitsSub_mul_X (u : Rˣ) : invUnitsSub u * X = invUnitsSub u * C R u - 1 := by ext (_ | n) · simp · simp [n.succ_ne_zero, pow_succ'] @[simp] theorem invUnitsSub_mul_sub (u : Rˣ) : invUnitsSub u * (C R u - X) = 1 := by simp [mul_sub, sub_sub_cancel] theorem map_invUnitsSub (f : R →+* S) (u : Rˣ) : map f (invUnitsSub u) = invUnitsSub (Units.map (f : R →* S) u) := by ext simp only [← map_pow, coeff_map, coeff_invUnitsSub, one_divp] rfl end Ring section invOneSubPow variable (S : Type*) [CommRing S] (d : ℕ) /-- (1 + X + X^2 + ...) * (1 - X) = 1. Note that the power series `1 + X + X^2 + ...` is written as `mk 1` where `1` is the constant function so that `mk 1` is the power series with all coefficients equal to one. -/ theorem mk_one_mul_one_sub_eq_one : (mk 1 : S⟦X⟧) * (1 - X) = 1 := by rw [mul_comm, PowerSeries.ext_iff] intro n cases n with | zero => simp | succ n => simp [sub_mul] /-- Note that `mk 1` is the constant function `1` so the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `(1 + X + X^2 + ... : S⟦X⟧) ^ (d + 1)` is equal to the power series `mk fun n => Nat.choose (d + n) d : S⟦X⟧`. -/ theorem mk_one_pow_eq_mk_choose_add : (mk 1 : S⟦X⟧) ^ (d + 1) = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := by induction d with | zero => ext; simp | succ d hd => ext n rw [pow_add, hd, pow_one, mul_comm, coeff_mul] simp_rw [coeff_mk, Pi.one_apply, one_mul] norm_cast rw [Finset.sum_antidiagonal_choose_add, add_right_comm] /-- Given a natural number `d : ℕ` and a commutative ring `S`, `PowerSeries.invOneSubPow S d` is the multiplicative inverse of `(1 - X) ^ d` in `S⟦X⟧ˣ`. When `d` is `0`, `PowerSeries.invOneSubPow S d` will just be `1`. When `d` is positive, `PowerSeries.invOneSubPow S d` will be the power series `mk fun n => Nat.choose (d - 1 + n) (d - 1)`. -/ noncomputable def invOneSubPow : ℕ → S⟦X⟧ˣ | 0 => 1 | d + 1 => { val := mk fun n => Nat.choose (d + n) d inv := (1 - X) ^ (d + 1) val_inv := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mk_one_mul_one_sub_eq_one, one_pow] inv_val := by rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mul_comm, mk_one_mul_one_sub_eq_one, one_pow] } theorem invOneSubPow_zero : invOneSubPow S 0 = 1 := by delta invOneSubPow simp only [Units.val_one] theorem invOneSubPow_val_eq_mk_sub_one_add_choose_of_pos (h : 0 < d) : (invOneSubPow S d).val = (mk fun n => Nat.choose (d - 1 + n) (d - 1) : S⟦X⟧) := by rw [← Nat.sub_one_add_one_eq_of_pos h, invOneSubPow, add_tsub_cancel_right] theorem invOneSubPow_val_succ_eq_mk_add_choose : (invOneSubPow S (d + 1)).val = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := rfl theorem invOneSubPow_val_one_eq_invUnitSub_one : (invOneSubPow S 1).val = invUnitsSub (1 : Sˣ) := by simp [invOneSubPow, invUnitsSub] /-- The theorem `PowerSeries.mk_one_mul_one_sub_eq_one` implies that `1 - X` is a unit in `S⟦X⟧` whose inverse is the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`, `PowerSeries.invOneSubPow S d` is equal to `(1 - X)⁻¹ ^ d`. -/ theorem invOneSubPow_eq_inv_one_sub_pow : invOneSubPow S d = (Units.mkOfMulEqOne (1 - X) (mk 1 : S⟦X⟧) <| Eq.trans (mul_comm _ _) (mk_one_mul_one_sub_eq_one S))⁻¹ ^ d := by induction d with | zero => exact Eq.symm <| pow_zero _ | succ d _ => rw [inv_pow] exact (DivisionMonoid.inv_eq_of_mul _ (invOneSubPow S (d + 1)) <| by rw [← Units.val_eq_one, Units.val_mul, Units.val_pow_eq_pow_val] exact (invOneSubPow S (d + 1)).inv_val).symm theorem invOneSubPow_inv_eq_one_sub_pow : (invOneSubPow S d).inv = (1 - X : S⟦X⟧) ^ d := by induction d with | zero => exact Eq.symm <| pow_zero _ | succ d => rfl theorem invOneSubPow_inv_zero_eq_one : (invOneSubPow S 0).inv = 1 := by delta invOneSubPow simp only [Units.inv_eq_val_inv, inv_one, Units.val_one] theorem mk_add_choose_mul_one_sub_pow_eq_one : (mk fun n ↦ Nat.choose (d + n) d : S⟦X⟧) * ((1 - X) ^ (d + 1)) = 1 := (invOneSubPow S (d + 1)).val_inv theorem invOneSubPow_add (e : ℕ) : invOneSubPow S (d + e) = invOneSubPow S d * invOneSubPow S e := by simp_rw [invOneSubPow_eq_inv_one_sub_pow, pow_add] theorem one_sub_pow_mul_invOneSubPow_val_add_eq_invOneSubPow_val (e : ℕ) : (1 - X) ^ e * (invOneSubPow S (d + e)).val = (invOneSubPow S d).val := by simp [invOneSubPow_add, Units.val_mul, mul_comm, mul_assoc, ← invOneSubPow_inv_eq_one_sub_pow] theorem one_sub_pow_add_mul_invOneSubPow_val_eq_one_sub_pow (e : ℕ) : (1 - X) ^ (d + e) * (invOneSubPow S e).val = (1 - X) ^ d := by simp [pow_add, mul_assoc, ← invOneSubPow_inv_eq_one_sub_pow S e] end invOneSubPow section Field variable (A A' : Type*) [Ring A] [Ring A'] [Algebra ℚ A] [Algebra ℚ A'] open Nat /-- Power series for the exponential function at zero. -/ def exp : PowerSeries A := mk fun n => algebraMap ℚ A (1 / n !) /-- Power series for the sine function at zero. -/ def sin : PowerSeries A := mk fun n => if Even n then 0 else algebraMap ℚ A ((-1) ^ (n / 2) / n !) /-- Power series for the cosine function at zero. -/ def cos : PowerSeries A := mk fun n => if Even n then algebraMap ℚ A ((-1) ^ (n / 2) / n !) else 0 variable {A A'} (n : ℕ) @[simp] theorem coeff_exp : coeff A n (exp A) = algebraMap ℚ A (1 / n !) := coeff_mk _ _ @[simp] theorem constantCoeff_exp : constantCoeff A (exp A) = 1 := by rw [← coeff_zero_eq_constantCoeff_apply, coeff_exp] simp variable (f : A →+* A') @[simp] theorem map_exp : map (f : A →+* A') (exp A) = exp A' := by ext simp @[simp] theorem map_sin : map f (sin A) = sin A' := by ext simp [sin, apply_ite f] @[simp] theorem map_cos : map f (cos A) = cos A' := by ext simp [cos, apply_ite f] end Field open RingHom open Finset Nat variable {A : Type*} [CommRing A] /-- Shows that $e^{aX} * e^{bX} = e^{(a + b)X}$ -/ theorem exp_mul_exp_eq_exp_add [Algebra ℚ A] (a b : A) : rescale a (exp A) * rescale b (exp A) = rescale (a + b) (exp A) := by ext n simp only [coeff_mul, exp, rescale, coeff_mk, MonoidHom.coe_mk, OneHom.coe_mk, coe_mk, factorial, Nat.sum_antidiagonal_eq_sum_range_succ_mk, add_pow, sum_mul] apply sum_congr rfl rintro x hx suffices a ^ x * b ^ (n - x) * (algebraMap ℚ A (1 / ↑x.factorial) * algebraMap ℚ A (1 / ↑(n - x).factorial)) = a ^ x * b ^ (n - x) * (↑(n.choose x) * (algebraMap ℚ A) (1 / ↑n.factorial)) by convert this using 1 <;> ring congr 1 rw [← map_natCast (algebraMap ℚ A) (n.choose x), ← map_mul, ← map_mul] refine RingHom.congr_arg _ ?_ rw [mul_one_div (↑(n.choose x) : ℚ), one_div_mul_one_div] symm rw [div_eq_iff, div_mul_eq_mul_div, one_mul, choose_eq_factorial_div_factorial] · norm_cast rw [cast_div_charZero] apply factorial_mul_factorial_dvd_factorial (mem_range_succ_iff.1 hx) · apply mem_range_succ_iff.1 hx · rintro h apply factorial_ne_zero n rw [cast_eq_zero.1 h] /-- Shows that $e^{x} * e^{-x} = 1$ -/ theorem exp_mul_exp_neg_eq_one [Algebra ℚ A] : exp A * evalNegHom (exp A) = 1 := by convert exp_mul_exp_eq_exp_add (1 : A) (-1) <;> simp /-- Shows that $(e^{X})^k = e^{kX}$. -/
Mathlib/RingTheory/PowerSeries/WellKnown.lean
260
261
theorem exp_pow_eq_rescale_exp [Algebra ℚ A] (k : ℕ) : exp A ^ k = rescale (k : A) (exp A) := by
induction' k with k h
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions /-! # Neighborhoods and continuity relative to a subset This file develops API on the relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` related to continuity, which are defined in previous definition files. Their basic properties studied in this file include the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α β γ δ : Type*} variable [TopologicalSpace α] /-! ## Properties of the neighborhood-within filter -/ @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] @[simp] theorem eventually_eventually_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs @[simp] theorem eventually_mem_nhdsWithin_iff {x : α} {s t : Set α} : (∀ᶠ x' in 𝓝[s] x, t ∈ 𝓝[s] x') ↔ t ∈ 𝓝[s] x := eventually_eventually_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf @[simp] lemma nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] theorem nhdsWithin_hasBasis {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] theorem nhds_eq_nhdsWithin_sup_nhdsWithin (b : α) {I₁ I₂ : Set α} (hI : Set.univ = I₁ ∪ I₂) : nhds b = nhdsWithin b I₁ ⊔ nhdsWithin b I₂ := by rw [← nhdsWithin_univ b, hI, nhdsWithin_union] /-- If `L` and `R` are neighborhoods of `b` within sets whose union is `Set.univ`, then `L ∪ R` is a neighborhood of `b`. -/ theorem union_mem_nhds_of_mem_nhdsWithin {b : α} {I₁ I₂ : Set α} (h : Set.univ = I₁ ∪ I₂) {L : Set α} (hL : L ∈ nhdsWithin b I₁) {R : Set α} (hR : R ∈ nhdsWithin b I₂) : L ∪ R ∈ nhds b := by rw [← nhdsWithin_univ b, h, nhdsWithin_union] exact ⟨mem_of_superset hL (by simp), mem_of_superset hR (by simp)⟩ /-- Writing a punctured neighborhood filter as a sup of left and right filters. -/ lemma punctured_nhds_eq_nhdsWithin_sup_nhdsWithin [LinearOrder α] {x : α} : 𝓝[≠] x = 𝓝[<] x ⊔ 𝓝[>] x := by rw [← Iio_union_Ioi, nhdsWithin_union] /-- Obtain a "predictably-sided" neighborhood of `b` from two one-sided neighborhoods. -/ theorem nhds_of_Ici_Iic [LinearOrder α] {b : α} {L : Set α} (hL : L ∈ 𝓝[≤] b) {R : Set α} (hR : R ∈ 𝓝[≥] b) : L ∩ Iic b ∪ R ∩ Ici b ∈ 𝓝 b := union_mem_nhds_of_mem_nhdsWithin Iic_union_Ici.symm (inter_mem hL self_mem_nhdsWithin) (inter_mem hR self_mem_nhdsWithin) theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := by induction I, hI using Set.Finite.induction_on with | empty => simp | insert _ _ hT => simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] @[simp] theorem nhdsNE_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] @[deprecated (since := "2025-03-02")] alias nhdsWithin_compl_singleton_sup_pure := nhdsNE_sup_pure @[simp] theorem pure_sup_nhdsNE (a : α) : pure a ⊔ 𝓝[≠] a = 𝓝 a := by rw [← sup_comm, nhdsNE_sup_pure] theorem nhdsWithin_prod [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv lemma Filter.EventuallyEq.mem_interior {x : α} {s t : Set α} (hst : s =ᶠ[𝓝 x] t) (h : x ∈ interior s) : x ∈ interior t := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst simpa [mem_interior_iff_mem_nhds, ← nhdsWithin_eq_nhds, hst] using h lemma Filter.EventuallyEq.mem_interior_iff {x : α} {s t : Set α} (hst : s =ᶠ[𝓝 x] t) : x ∈ interior s ↔ x ∈ interior t := ⟨fun h ↦ hst.mem_interior h, fun h ↦ hst.symm.mem_interior h⟩ @[deprecated (since := "2024-11-11")] alias EventuallyEq.mem_interior_iff := Filter.EventuallyEq.mem_interior_iff section Pi variable {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] theorem nhdsWithin_pi_eq' {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (π i)) (x : ∀ i, π i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] theorem nhdsWithin_pi_eq {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (π i)) (x : ∀ i, π i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal, eval] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] theorem nhdsWithin_pi_univ_eq [Finite ι] (s : ∀ i, Set (π i)) (x : ∀ i, π i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x theorem nhdsWithin_pi_eq_bot {I : Set ι} {s : ∀ i, Set (π i)} {x : ∀ i, π i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] theorem nhdsWithin_pi_neBot {I : Set ι} {s : ∀ i, Set (π i)} {x : ∀ i, π i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] instance instNeBotNhdsWithinUnivPi {s : ∀ i, Set (π i)} {x : ∀ i, π i} [∀ i, (𝓝[s i] x i).NeBot] : (𝓝[pi univ s] x).NeBot := by simpa [nhdsWithin_pi_neBot] instance Pi.instNeBotNhdsWithinIio [Nonempty ι] [∀ i, Preorder (π i)] {x : ∀ i, π i} [∀ i, (𝓝[<] x i).NeBot] : (𝓝[<] x).NeBot := have : (𝓝[pi univ fun i ↦ Iio (x i)] x).NeBot := inferInstance this.mono <| nhdsWithin_mono _ fun _y hy ↦ lt_of_strongLT fun i ↦ hy i trivial instance Pi.instNeBotNhdsWithinIoi [Nonempty ι] [∀ i, Preorder (π i)] {x : ∀ i, π i} [∀ i, (𝓝[>] x i).NeBot] : (𝓝[>] x).NeBot := Pi.instNeBotNhdsWithinIio (π := fun i ↦ (π i)ᵒᵈ) (x := fun i ↦ OrderDual.toDual (x i)) end Pi theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] theorem DenseRange.piMap {ι : Type*} {X Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : (i : ι) → (X i) → (Y i)} (hf : ∀ i, DenseRange (f i)): DenseRange (Pi.map f) := by rw [DenseRange, Set.range_piMap] exact dense_pi Set.univ (fun i _ => hf i) theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal /-- Two functions agree on a neighborhood of `x` if they agree at `x` and in a punctured neighborhood. -/
Mathlib/Topology/ContinuousOn.lean
423
426
theorem eventuallyEq_nhds_of_eventuallyEq_nhdsNE {f g : α → β} {a : α} (h₁ : f =ᶠ[𝓝[≠] a] g) (h₂ : f a = g a) : f =ᶠ[𝓝 a] g := by
filter_upwards [eventually_nhdsWithin_iff.1 h₁]
/- 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, Violeta Hernández Palacios -/ import Mathlib.MeasureTheory.MeasurableSpace.Defs import Mathlib.SetTheory.Cardinal.Regular import Mathlib.SetTheory.Cardinal.Continuum import Mathlib.SetTheory.Cardinal.Ordinal /-! # Cardinal of sigma-algebras If a sigma-algebra is generated by a set of sets `s`, then the cardinality of the sigma-algebra is bounded by `(max #s 2) ^ ℵ₀`. This is stated in `MeasurableSpace.cardinal_generate_measurable_le` and `MeasurableSpace.cardinalMeasurableSet_le`. In particular, if `#s ≤ 𝔠`, then the generated sigma-algebra has cardinality at most `𝔠`, see `MeasurableSpace.cardinal_measurableSet_le_continuum`. For the proof, we rely on an explicit inductive construction of the sigma-algebra generated by `s` (instead of the inductive predicate `GenerateMeasurable`). This transfinite inductive construction is parameterized by an ordinal `< ω₁`, and the cardinality bound is preserved along each step of the construction. We show in `MeasurableSpace.generateMeasurable_eq_rec` that this indeed generates this sigma-algebra. -/ universe u v variable {α : Type u} open Cardinal Ordinal Set MeasureTheory namespace MeasurableSpace /-- Transfinite induction construction of the sigma-algebra generated by a set of sets `s`. At each step, we add all elements of `s`, the empty set, the complements of already constructed sets, and countable unions of already constructed sets. We index this construction by an arbitrary ordinal for simplicity, but by `ω₁` we will have generated all the sets in the sigma-algebra. This construction is very similar to that of the Borel hierarchy. -/ def generateMeasurableRec (s : Set (Set α)) (i : Ordinal) : Set (Set α) := let S := ⋃ j < i, generateMeasurableRec s j s ∪ {∅} ∪ compl '' S ∪ Set.range fun f : ℕ → S => ⋃ n, (f n).1 termination_by i theorem self_subset_generateMeasurableRec (s : Set (Set α)) (i : Ordinal) : s ⊆ generateMeasurableRec s i := by unfold generateMeasurableRec apply_rules [subset_union_of_subset_left] exact subset_rfl theorem empty_mem_generateMeasurableRec (s : Set (Set α)) (i : Ordinal) : ∅ ∈ generateMeasurableRec s i := by unfold generateMeasurableRec exact mem_union_left _ (mem_union_left _ (mem_union_right _ (mem_singleton ∅))) theorem compl_mem_generateMeasurableRec {s : Set (Set α)} {i j : Ordinal} (h : j < i) {t : Set α} (ht : t ∈ generateMeasurableRec s j) : tᶜ ∈ generateMeasurableRec s i := by unfold generateMeasurableRec exact mem_union_left _ (mem_union_right _ ⟨t, mem_iUnion₂.2 ⟨j, h, ht⟩, rfl⟩) theorem iUnion_mem_generateMeasurableRec {s : Set (Set α)} {i : Ordinal} {f : ℕ → Set α} (hf : ∀ n, ∃ j < i, f n ∈ generateMeasurableRec s j) : ⋃ n, f n ∈ generateMeasurableRec s i := by unfold generateMeasurableRec exact mem_union_right _ ⟨fun n => ⟨f n, let ⟨j, hj, hf⟩ := hf n; mem_iUnion₂.2 ⟨j, hj, hf⟩⟩, rfl⟩ theorem generateMeasurableRec_mono (s : Set (Set α)) : Monotone (generateMeasurableRec s) := by intro i j h x hx rcases h.eq_or_lt with (rfl | h) · exact hx · convert iUnion_mem_generateMeasurableRec fun _ => ⟨i, h, hx⟩ exact (iUnion_const x).symm /-- An inductive principle for the elements of `generateMeasurableRec`. -/ @[elab_as_elim] theorem generateMeasurableRec_induction {s : Set (Set α)} {i : Ordinal} {t : Set α} {p : Set α → Prop} (hs : ∀ t ∈ s, p t) (h0 : p ∅) (hc : ∀ u, p u → (∃ j < i, u ∈ generateMeasurableRec s j) → p uᶜ) (hn : ∀ f : ℕ → Set α, (∀ n, p (f n) ∧ ∃ j < i, f n ∈ generateMeasurableRec s j) → p (⋃ n, f n)) : t ∈ generateMeasurableRec s i → p t := by suffices H : ∀ k ≤ i, ∀ t ∈ generateMeasurableRec s k, p t from H i le_rfl t intro k apply WellFoundedLT.induction k intro k IH hk t replace IH := fun j hj => IH j hj (hj.le.trans hk) unfold generateMeasurableRec rintro (((ht | rfl) | ht) | ⟨f, rfl⟩) · exact hs t ht · exact h0 · simp_rw [mem_image, mem_iUnion₂] at ht obtain ⟨u, ⟨⟨j, hj, hj'⟩, rfl⟩⟩ := ht exact hc u (IH j hj u hj') ⟨j, hj.trans_le hk, hj'⟩ · apply hn intro n obtain ⟨j, hj, hj'⟩ := mem_iUnion₂.1 (f n).2 use IH j hj _ hj', j, hj.trans_le hk theorem generateMeasurableRec_omega1 (s : Set (Set α)) : generateMeasurableRec s (ω₁ : Ordinal.{v}) = ⋃ i < (ω₁ : Ordinal.{v}), generateMeasurableRec s i := by apply (iUnion₂_subset fun i h => generateMeasurableRec_mono s h.le).antisymm' intro t ht rw [mem_iUnion₂] refine generateMeasurableRec_induction ?_ ?_ ?_ ?_ ht · intro t ht exact ⟨0, omega_pos 1, self_subset_generateMeasurableRec s 0 ht⟩ · exact ⟨0, omega_pos 1, empty_mem_generateMeasurableRec s 0⟩ · rintro u - ⟨j, hj, hj'⟩ exact ⟨_, (isLimit_omega 1).succ_lt hj, compl_mem_generateMeasurableRec (Order.lt_succ j) hj'⟩ · intro f H choose I hI using fun n => (H n).1 simp_rw [exists_prop] at hI refine ⟨_, Ordinal.lsub_lt_ord_lift ?_ fun n => (hI n).1, iUnion_mem_generateMeasurableRec fun n => ⟨_, Ordinal.lt_lsub I n, (hI n).2⟩⟩ rw [mk_nat, lift_aleph0, isRegular_aleph_one.cof_omega_eq] exact aleph0_lt_aleph_one theorem generateMeasurableRec_subset (s : Set (Set α)) (i : Ordinal) : generateMeasurableRec s i ⊆ { t | GenerateMeasurable s t } := by apply WellFoundedLT.induction i exact fun i IH t ht => generateMeasurableRec_induction .basic .empty (fun u _ ⟨j, hj, hj'⟩ => .compl _ (IH j hj hj')) (fun f H => .iUnion _ fun n => (H n).1) ht /-- `generateMeasurableRec s ω₁` generates precisely the smallest sigma-algebra containing `s`. -/ theorem generateMeasurable_eq_rec (s : Set (Set α)) : { t | GenerateMeasurable s t } = generateMeasurableRec s ω₁ := by apply (generateMeasurableRec_subset s _).antisymm' intro t ht induction ht with | basic u hu => exact self_subset_generateMeasurableRec s _ hu | empty => exact empty_mem_generateMeasurableRec s _ | compl u _ IH => rw [generateMeasurableRec_omega1, mem_iUnion₂] at IH obtain ⟨i, hi, hi'⟩ := IH exact generateMeasurableRec_mono _ ((isLimit_omega 1).succ_lt hi).le (compl_mem_generateMeasurableRec (Order.lt_succ i) hi') | iUnion f _ IH => simp_rw [generateMeasurableRec_omega1, mem_iUnion₂, exists_prop] at IH exact iUnion_mem_generateMeasurableRec IH /-- `generateMeasurableRec` is constant for ordinals `≥ ω₁`. -/ theorem generateMeasurableRec_of_omega1_le (s : Set (Set α)) {i : Ordinal.{v}} (hi : ω₁ ≤ i) : generateMeasurableRec s i = generateMeasurableRec s (ω₁ : Ordinal.{v}) := by apply (generateMeasurableRec_mono s hi).antisymm' rw [← generateMeasurable_eq_rec] exact generateMeasurableRec_subset s i /-- At each step of the inductive construction, the cardinality bound `≤ #s ^ ℵ₀` holds. -/
Mathlib/MeasureTheory/MeasurableSpace/Card.lean
156
164
theorem cardinal_generateMeasurableRec_le (s : Set (Set α)) (i : Ordinal.{v}) : #(generateMeasurableRec s i) ≤ max #s 2 ^ ℵ₀ := by
suffices ∀ i ≤ ω₁, #(generateMeasurableRec s i) ≤ max #s 2 ^ ℵ₀ by obtain hi | hi := le_or_lt i ω₁ · exact this i hi · rw [generateMeasurableRec_of_omega1_le s hi.le] exact this _ le_rfl intro i apply WellFoundedLT.induction i
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Data.PFunctor.Multivariate.W import Mathlib.Data.QPF.Multivariate.Basic /-! # The initial algebra of a multivariate qpf is again a qpf. For an `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with regards to its last argument `αₙ`. The result is an `n`-ary functor: `Fix F (α₀,..,αₙ₋₁)`. Making `Fix F` into a functor allows us to take the fixed point, compose with other functors and take a fixed point again. ## Main definitions * `Fix.mk` - constructor * `Fix.dest` - destructor * `Fix.rec` - recursor: basis for defining functions by structural recursion on `Fix F α` * `Fix.drec` - dependent recursor: generalization of `Fix.rec` where the result type of the function is allowed to depend on the `Fix F α` value * `Fix.rec_eq` - defining equation for `recursor` * `Fix.ind` - induction principle for `Fix F α` ## Implementation notes For `F` a `QPF`, we define `Fix F α` in terms of the W-type of the polynomial functor `P` of `F`. We define the relation `WEquiv` and take its quotient as the definition of `Fix F α`. See [avigad-carneiro-hudon2019] for more details. ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u v namespace MvQPF open TypeVec open MvFunctor (LiftP LiftR) open MvFunctor variable {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] /-- `recF` is used as a basis for defining the recursor on `Fix F α`. `recF` traverses recursively the W-type generated by `q.P` using a function on `F` as a recursive step -/ def recF {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) : q.P.W α → β := q.P.wRec fun a f' _f rec => g (abs ⟨a, splitFun f' rec⟩) theorem recF_eq {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f : q.P.last.B a → q.P.W α) : recF g (q.P.wMk a f' f) = g (abs ⟨a, splitFun f' (recF g ∘ f)⟩) := by rw [recF, MvPFunctor.wRec_eq]; rfl theorem recF_eq' {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) (x : q.P.W α) : recF g x = g (abs (appendFun id (recF g) <$$> q.P.wDest' x)) := by apply q.P.w_cases _ x intro a f' f rw [recF_eq, q.P.wDest'_wMk, MvPFunctor.map_eq, appendFun_comp_splitFun, TypeVec.id_comp] /-- Equivalence relation on W-types that represent the same `Fix F` value -/ inductive WEquiv {α : TypeVec n} : q.P.W α → q.P.W α → Prop | ind (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f₀ f₁ : q.P.last.B a → q.P.W α) : (∀ x, WEquiv (f₀ x) (f₁ x)) → WEquiv (q.P.wMk a f' f₀) (q.P.wMk a f' f₁) | abs (a₀ : q.P.A) (f'₀ : q.P.drop.B a₀ ⟹ α) (f₀ : q.P.last.B a₀ → q.P.W α) (a₁ : q.P.A) (f'₁ : q.P.drop.B a₁ ⟹ α) (f₁ : q.P.last.B a₁ → q.P.W α) : abs ⟨a₀, q.P.appendContents f'₀ f₀⟩ = abs ⟨a₁, q.P.appendContents f'₁ f₁⟩ → WEquiv (q.P.wMk a₀ f'₀ f₀) (q.P.wMk a₁ f'₁ f₁) | trans (u v w : q.P.W α) : WEquiv u v → WEquiv v w → WEquiv u w theorem recF_eq_of_wEquiv (α : TypeVec n) {β : Type u} (u : F (α.append1 β) → β) (x y : q.P.W α) : WEquiv x y → recF u x = recF u y := by apply q.P.w_cases _ x intro a₀ f'₀ f₀ apply q.P.w_cases _ y intro a₁ f'₁ f₁ intro h -- Porting note: induction on h doesn't work. refine @WEquiv.recOn _ _ _ _ (fun a a' _ ↦ recF u a = recF u a') _ _ h ?_ ?_ ?_ · intros a f' f₀ f₁ _h ih; simp only [recF_eq, Function.comp] congr; funext; congr; funext; apply ih · intros a₀ f'₀ f₀ a₁ f'₁ f₁ h; simp only [recF_eq', abs_map, MvPFunctor.wDest'_wMk, h] · intros x y z _e₁ _e₂ ih₁ ih₂; exact Eq.trans ih₁ ih₂ theorem wEquiv.abs' {α : TypeVec n} (x y : q.P.W α) (h : MvQPF.abs (q.P.wDest' x) = MvQPF.abs (q.P.wDest' y)) : WEquiv x y := by revert h apply q.P.w_cases _ x intro a₀ f'₀ f₀ apply q.P.w_cases _ y intro a₁ f'₁ f₁ apply WEquiv.abs theorem wEquiv.refl {α : TypeVec n} (x : q.P.W α) : WEquiv x x := by apply q.P.w_cases _ x; intro a f' f; exact WEquiv.abs a f' f a f' f rfl theorem wEquiv.symm {α : TypeVec n} (x y : q.P.W α) : WEquiv x y → WEquiv y x := by intro h; induction h with | ind a f' f₀ f₁ _h ih => exact WEquiv.ind _ _ _ _ ih | abs a₀ f'₀ f₀ a₁ f'₁ f₁ h => exact WEquiv.abs _ _ _ _ _ _ h.symm | trans x y z _e₁ _e₂ ih₁ ih₂ => exact MvQPF.WEquiv.trans _ _ _ ih₂ ih₁ /-- maps every element of the W type to a canonical representative -/ def wrepr {α : TypeVec n} : q.P.W α → q.P.W α := recF (q.P.wMk' ∘ repr) theorem wrepr_wMk {α : TypeVec n} (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f : q.P.last.B a → q.P.W α) : wrepr (q.P.wMk a f' f) = q.P.wMk' (repr (abs (appendFun id wrepr <$$> ⟨a, q.P.appendContents f' f⟩))) := by rw [wrepr, recF_eq', q.P.wDest'_wMk]; rfl
Mathlib/Data/QPF/Multivariate/Constructions/Fix.lean
125
129
theorem wrepr_equiv {α : TypeVec n} (x : q.P.W α) : WEquiv (wrepr x) x := by
apply q.P.w_ind _ x; intro a f' f ih apply WEquiv.trans _ (q.P.wMk' (appendFun id wrepr <$$> ⟨a, q.P.appendContents f' f⟩)) · apply wEquiv.abs' rw [wrepr_wMk, q.P.wDest'_wMk', q.P.wDest'_wMk', abs_repr]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Data.ENat.Lattice import Mathlib.Order.OrderIsoNat import Mathlib.Tactic.TFAE /-! # Maximal length of chains This file contains lemmas to work with the maximal length of strictly descending finite sequences (chains) in a partial order. ## Main definition - `Set.subchain`: The set of strictly ascending lists of `α` contained in a `Set α`. - `Set.chainHeight`: The maximal length of a strictly ascending sequence in a partial order. This is defined as the maximum of the lengths of `Set.subchain`s, valued in `ℕ∞`. ## Main results - `Set.exists_chain_of_le_chainHeight`: For each `n : ℕ` such that `n ≤ s.chainHeight`, there exists `s.subchain` of length `n`. - `Set.chainHeight_mono`: If `s ⊆ t` then `s.chainHeight ≤ t.chainHeight`. - `Set.chainHeight_image`: If `f` is an order embedding, then `(f '' s).chainHeight = s.chainHeight`. - `Set.chainHeight_insert_of_forall_lt`: If `∀ y ∈ s, y < x`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_insert_of_forall_gt`: If `∀ y ∈ s, x < y`, then `(insert x s).chainHeight = s.chainHeight + 1`. - `Set.chainHeight_union_eq`: If `∀ x ∈ s, ∀ y ∈ t, s ≤ t`, then `(s ∪ t).chainHeight = s.chainHeight + t.chainHeight`. - `Set.wellFoundedGT_of_chainHeight_ne_top`: If `s` has finite height, then `>` is well-founded on `s`. - `Set.wellFoundedLT_of_chainHeight_ne_top`: If `s` has finite height, then `<` is well-founded on `s`. -/ assert_not_exists Field open List hiding le_antisymm open OrderDual universe u v variable {α β : Type*} namespace Set section LT variable [LT α] [LT β] (s t : Set α) /-- The set of strictly ascending lists of `α` contained in a `Set α`. -/ def subchain : Set (List α) := { l | l.Chain' (· < ·) ∧ ∀ i ∈ l, i ∈ s } @[simp] theorem nil_mem_subchain : [] ∈ s.subchain := ⟨trivial, fun _ ↦ nofun⟩ variable {s} {l : List α} {a : α} theorem cons_mem_subchain_iff : (a::l) ∈ s.subchain ↔ a ∈ s ∧ l ∈ s.subchain ∧ ∀ b ∈ l.head?, a < b := by simp only [subchain, mem_setOf_eq, forall_mem_cons, chain'_cons', and_left_comm, and_comm, and_assoc] @[simp] theorem singleton_mem_subchain_iff : [a] ∈ s.subchain ↔ a ∈ s := by simp [cons_mem_subchain_iff] instance : Nonempty s.subchain := ⟨⟨[], s.nil_mem_subchain⟩⟩ variable (s) /-- The maximal length of a strictly ascending sequence in a partial order. -/ noncomputable def chainHeight : ℕ∞ := ⨆ l ∈ s.subchain, length l theorem chainHeight_eq_iSup_subtype : s.chainHeight = ⨆ l : s.subchain, ↑l.1.length := iSup_subtype' theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) : ∃ l ∈ s.subchain, length l = n := by rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;> rw [chainHeight_eq_iSup_subtype] at ha · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ := not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| le_of_not_ge h₃⟩ · rw [ENat.iSup_coe_lt_top] at ha obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha refine ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩, (l.length_take).trans <| min_eq_left <| ?_⟩ rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype] theorem le_chainHeight_TFAE (n : ℕ) : TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by tfae_have 1 → 2 := s.exists_chain_of_le_chainHeight tfae_have 2 → 3 := fun ⟨l, hls, he⟩ ↦ ⟨l, hls, he.ge⟩ tfae_have 3 → 1 := fun ⟨l, hs, hn⟩ ↦ le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn) tfae_finish variable {s t} theorem le_chainHeight_iff {n : ℕ} : ↑n ≤ s.chainHeight ↔ ∃ l ∈ s.subchain, length l = n := (le_chainHeight_TFAE s n).out 0 1 theorem length_le_chainHeight_of_mem_subchain (hl : l ∈ s.subchain) : ↑l.length ≤ s.chainHeight := le_chainHeight_iff.mpr ⟨l, hl, rfl⟩ theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by refine ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ ?_⟩ contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <| (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩ @[simp] theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by rw [← Nat.cast_one, Set.le_chainHeight_iff] simp only [length_eq_one_iff, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and, singleton_mem_subchain_iff, Set.Nonempty] @[simp] theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by rw [← not_iff_not, ← Ne, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff, nonempty_iff_ne_empty] @[simp] theorem chainHeight_empty : (∅ : Set α).chainHeight = 0 := chainHeight_eq_zero_iff.2 rfl @[simp] theorem chainHeight_of_isEmpty [IsEmpty α] : s.chainHeight = 0 := chainHeight_eq_zero_iff.mpr (Subsingleton.elim _ _)
Mathlib/Order/Height.lean
142
144
theorem le_chainHeight_add_nat_iff {n m : ℕ} : ↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by
simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Order.Interval.Multiset /-! # Finite intervals of naturals This file proves that `ℕ` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. ## TODO Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedMul` or `SuccOrder` and subsequently be moved upstream to `Order.Interval.Finset`. -/ assert_not_exists Ring open Finset Nat variable (a b c : ℕ) namespace Nat instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ where finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ finsetIco a b := ⟨List.range' a (b - a), List.nodup_range'⟩ finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ := rfl theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range'⟩ := rfl theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ := rfl theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ := rfl theorem uIcc_eq_range' : uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range'⟩ := rfl theorem Iio_eq_range : Iio = range := by ext b x rw [mem_Iio, mem_range] @[simp] theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range] lemma range_eq_Icc_zero_sub_one (n : ℕ) (hn : n ≠ 0) : range n = Icc 0 (n - 1) := by ext b simp_all only [mem_Icc, zero_le, true_and, mem_range] exact lt_iff_le_pred (zero_lt_of_ne_zero hn) theorem _root_.Finset.range_eq_Ico : range = Ico 0 := Ico_zero_eq_range.symm theorem range_succ_eq_Icc_zero (n : ℕ) : range (n + 1) = Icc 0 n := by rw [range_eq_Icc_zero_sub_one _ (Nat.add_one_ne_zero _), Nat.add_sub_cancel_right] @[simp] lemma card_Icc : #(Icc a b) = b + 1 - a := List.length_range' .. @[simp] lemma card_Ico : #(Ico a b) = b - a := List.length_range' .. @[simp] lemma card_Ioc : #(Ioc a b) = b - a := List.length_range' .. @[simp] lemma card_Ioo : #(Ioo a b) = b - a - 1 := List.length_range' .. @[simp] theorem card_uIcc : #(uIcc a b) = (b - a : ℤ).natAbs + 1 := (card_Icc _ _).trans <| by rw [← Int.natCast_inj, Int.ofNat_sub] <;> omega @[simp] lemma card_Iic : #(Iic b) = b + 1 := by rw [Iic_eq_Icc, card_Icc, Nat.bot_eq_zero, Nat.sub_zero] @[simp] theorem card_Iio : #(Iio b) = b := by rw [Iio_eq_Ico, card_Ico, Nat.bot_eq_zero, Nat.sub_zero] @[deprecated Fintype.card_Icc (since := "2025-03-28")] theorem card_fintypeIcc : Fintype.card (Set.Icc a b) = b + 1 - a := by simp @[deprecated Fintype.card_Ico (since := "2025-03-28")] theorem card_fintypeIco : Fintype.card (Set.Ico a b) = b - a := by simp @[deprecated Fintype.card_Ioc (since := "2025-03-28")] theorem card_fintypeIoc : Fintype.card (Set.Ioc a b) = b - a := by simp @[deprecated Fintype.card_Ioo (since := "2025-03-28")] theorem card_fintypeIoo : Fintype.card (Set.Ioo a b) = b - a - 1 := by simp @[deprecated Fintype.card_Iic (since := "2025-03-28")] theorem card_fintypeIic : Fintype.card (Set.Iic b) = b + 1 := by simp @[deprecated Fintype.card_Iio (since := "2025-03-28")] theorem card_fintypeIio : Fintype.card (Set.Iio b) = b := by simp -- TODO@Yaël: Generalize all the following lemmas to `SuccOrder` theorem Icc_succ_left : Icc a.succ b = Ioc a b := by ext x rw [mem_Icc, mem_Ioc, succ_le_iff] theorem Ico_succ_right : Ico a b.succ = Icc a b := by ext x rw [mem_Ico, mem_Icc, Nat.lt_succ_iff]
Mathlib/Order/Interval/Finset/Nat.lean
114
115
theorem Ico_succ_left : Ico a.succ b = Ioo a b := by
ext x
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions /-! # Neighborhoods and continuity relative to a subset This file develops API on the relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` related to continuity, which are defined in previous definition files. Their basic properties studied in this file include the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α β γ δ : Type*} variable [TopologicalSpace α] /-! ## Properties of the neighborhood-within filter -/ @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] @[simp] theorem eventually_eventually_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs @[simp] theorem eventually_mem_nhdsWithin_iff {x : α} {s t : Set α} : (∀ᶠ x' in 𝓝[s] x, t ∈ 𝓝[s] x') ↔ t ∈ 𝓝[s] x := eventually_eventually_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf @[simp] lemma nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] theorem nhdsWithin_hasBasis {ι : Sort*} {p : ι → Prop} {s : ι → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] theorem nhds_eq_nhdsWithin_sup_nhdsWithin (b : α) {I₁ I₂ : Set α} (hI : Set.univ = I₁ ∪ I₂) : nhds b = nhdsWithin b I₁ ⊔ nhdsWithin b I₂ := by rw [← nhdsWithin_univ b, hI, nhdsWithin_union] /-- If `L` and `R` are neighborhoods of `b` within sets whose union is `Set.univ`, then `L ∪ R` is a neighborhood of `b`. -/ theorem union_mem_nhds_of_mem_nhdsWithin {b : α} {I₁ I₂ : Set α} (h : Set.univ = I₁ ∪ I₂) {L : Set α} (hL : L ∈ nhdsWithin b I₁) {R : Set α} (hR : R ∈ nhdsWithin b I₂) : L ∪ R ∈ nhds b := by rw [← nhdsWithin_univ b, h, nhdsWithin_union] exact ⟨mem_of_superset hL (by simp), mem_of_superset hR (by simp)⟩ /-- Writing a punctured neighborhood filter as a sup of left and right filters. -/ lemma punctured_nhds_eq_nhdsWithin_sup_nhdsWithin [LinearOrder α] {x : α} : 𝓝[≠] x = 𝓝[<] x ⊔ 𝓝[>] x := by rw [← Iio_union_Ioi, nhdsWithin_union] /-- Obtain a "predictably-sided" neighborhood of `b` from two one-sided neighborhoods. -/ theorem nhds_of_Ici_Iic [LinearOrder α] {b : α} {L : Set α} (hL : L ∈ 𝓝[≤] b) {R : Set α} (hR : R ∈ 𝓝[≥] b) : L ∩ Iic b ∪ R ∩ Ici b ∈ 𝓝 b := union_mem_nhds_of_mem_nhdsWithin Iic_union_Ici.symm (inter_mem hL self_mem_nhdsWithin) (inter_mem hR self_mem_nhdsWithin) theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := by induction I, hI using Set.Finite.induction_on with | empty => simp | insert _ _ hT => simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] @[simp] theorem nhdsNE_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] @[deprecated (since := "2025-03-02")] alias nhdsWithin_compl_singleton_sup_pure := nhdsNE_sup_pure @[simp] theorem pure_sup_nhdsNE (a : α) : pure a ⊔ 𝓝[≠] a = 𝓝 a := by rw [← sup_comm, nhdsNE_sup_pure] theorem nhdsWithin_prod [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv lemma Filter.EventuallyEq.mem_interior {x : α} {s t : Set α} (hst : s =ᶠ[𝓝 x] t) (h : x ∈ interior s) : x ∈ interior t := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst simpa [mem_interior_iff_mem_nhds, ← nhdsWithin_eq_nhds, hst] using h lemma Filter.EventuallyEq.mem_interior_iff {x : α} {s t : Set α} (hst : s =ᶠ[𝓝 x] t) : x ∈ interior s ↔ x ∈ interior t := ⟨fun h ↦ hst.mem_interior h, fun h ↦ hst.symm.mem_interior h⟩ @[deprecated (since := "2024-11-11")] alias EventuallyEq.mem_interior_iff := Filter.EventuallyEq.mem_interior_iff section Pi variable {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] theorem nhdsWithin_pi_eq' {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (π i)) (x : ∀ i, π i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] theorem nhdsWithin_pi_eq {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (π i)) (x : ∀ i, π i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal, eval] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] theorem nhdsWithin_pi_univ_eq [Finite ι] (s : ∀ i, Set (π i)) (x : ∀ i, π i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x theorem nhdsWithin_pi_eq_bot {I : Set ι} {s : ∀ i, Set (π i)} {x : ∀ i, π i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] theorem nhdsWithin_pi_neBot {I : Set ι} {s : ∀ i, Set (π i)} {x : ∀ i, π i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] instance instNeBotNhdsWithinUnivPi {s : ∀ i, Set (π i)} {x : ∀ i, π i} [∀ i, (𝓝[s i] x i).NeBot] : (𝓝[pi univ s] x).NeBot := by simpa [nhdsWithin_pi_neBot] instance Pi.instNeBotNhdsWithinIio [Nonempty ι] [∀ i, Preorder (π i)] {x : ∀ i, π i} [∀ i, (𝓝[<] x i).NeBot] : (𝓝[<] x).NeBot := have : (𝓝[pi univ fun i ↦ Iio (x i)] x).NeBot := inferInstance this.mono <| nhdsWithin_mono _ fun _y hy ↦ lt_of_strongLT fun i ↦ hy i trivial instance Pi.instNeBotNhdsWithinIoi [Nonempty ι] [∀ i, Preorder (π i)] {x : ∀ i, π i} [∀ i, (𝓝[>] x i).NeBot] : (𝓝[>] x).NeBot := Pi.instNeBotNhdsWithinIio (π := fun i ↦ (π i)ᵒᵈ) (x := fun i ↦ OrderDual.toDual (x i)) end Pi theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] theorem DenseRange.piMap {ι : Type*} {X Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : (i : ι) → (X i) → (Y i)} (hf : ∀ i, DenseRange (f i)): DenseRange (Pi.map f) := by rw [DenseRange, Set.range_piMap] exact dense_pi Set.univ (fun i _ => hf i) theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal /-- Two functions agree on a neighborhood of `x` if they agree at `x` and in a punctured neighborhood. -/ theorem eventuallyEq_nhds_of_eventuallyEq_nhdsNE {f g : α → β} {a : α} (h₁ : f =ᶠ[𝓝[≠] a] g) (h₂ : f a = g a) : f =ᶠ[𝓝 a] g := by filter_upwards [eventually_nhdsWithin_iff.1 h₁] intro x hx by_cases h₂x : x = a · simp [h₂x, h₂] · tauto theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_of_right h theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := eventuallyEq_nhdsWithin_of_eqOn h theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l := (tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_of_right h theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α} (f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} : Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s := ⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h => tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩ @[simp] theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} : Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => h.mono_right inf_le_left, fun h => tendsto_inf.2 ⟨h, tendsto_principal.2 <| Eventually.of_forall mem_range_self⟩⟩ theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhdsWithin hmem theorem eventually_nhdsWithin_of_eventually_nhds {s : Set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhdsWithin_of_mem_nhds h lemma Set.MapsTo.preimage_mem_nhdsWithin {f : α → β} {s : Set α} {t : Set β} {x : α} (hst : MapsTo f s t) : f ⁻¹' t ∈ 𝓝[s] x := Filter.mem_of_superset self_mem_nhdsWithin hst /-! ### `nhdsWithin` and subtypes -/ theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} : t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin] theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) : 𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) := Filter.ext fun _ => mem_nhdsWithin_subtype theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) := (map_nhds_subtype_val ⟨a, h⟩).symm theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} : t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective] theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by rw [← map_nhds_subtype_val, mem_map] theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x := preimage_coe_mem_nhds_subtype theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x := eventually_nhds_subtype_iff s a (¬ P ·) |>.not theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) : Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl /-! ## Local continuity properties of functions -/ variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] {f g : α → β} {s s' s₁ t : Set α} {x : α} /-! ### `ContinuousWithinAt` -/ /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as `ContinuousWithinAt.comp` will have a different meaning. -/ theorem ContinuousWithinAt.tendsto (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝 (f x)) := h theorem continuousWithinAt_univ (f : α → β) (x : α) : ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ := tendsto_nhdsWithin_iff_subtype h f _ theorem ContinuousWithinAt.tendsto_nhdsWithin {t : Set β} (h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) := tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩ theorem ContinuousWithinAt.tendsto_nhdsWithin_image (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) := h.tendsto_nhdsWithin (mapsTo_image _ _) theorem nhdsWithin_le_comap (ctsf : ContinuousWithinAt f s x) : 𝓝[s] x ≤ comap f (𝓝[f '' s] f x) := ctsf.tendsto_nhdsWithin_image.le_comap theorem ContinuousWithinAt.preimage_mem_nhdsWithin {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h ht theorem ContinuousWithinAt.preimage_mem_nhdsWithin' {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝[f '' s] f x) : f ⁻¹' t ∈ 𝓝[s] x := h.tendsto_nhdsWithin (mapsTo_image _ _) ht theorem ContinuousWithinAt.preimage_mem_nhdsWithin'' {y : β} {s t : Set β} (h : ContinuousWithinAt f (f ⁻¹' s) x) (ht : t ∈ 𝓝[s] y) (hxy : y = f x) : f ⁻¹' t ∈ 𝓝[f ⁻¹' s] x := by rw [hxy] at ht exact h.preimage_mem_nhdsWithin' (nhdsWithin_mono _ (image_preimage_subset f s) ht) theorem continuousWithinAt_of_not_mem_closure (hx : x ∉ closure s) : ContinuousWithinAt f s x := by rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] at hx rw [ContinuousWithinAt, hx] exact tendsto_bot /-! ### `ContinuousOn` -/ theorem continuousOn_iff : ContinuousOn f s ↔ ∀ x ∈ s, ∀ t : Set β, IsOpen t → f x ∈ t → ∃ u, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [ContinuousOn, ContinuousWithinAt, tendsto_nhds, mem_nhdsWithin] theorem ContinuousOn.continuousWithinAt (hf : ContinuousOn f s) (hx : x ∈ s) : ContinuousWithinAt f s x := hf x hx theorem continuousOn_iff_continuous_restrict : ContinuousOn f s ↔ Continuous (s.restrict f) := by rw [ContinuousOn, continuous_iff_continuousAt]; constructor · rintro h ⟨x, xs⟩ exact (continuousWithinAt_iff_continuousAt_restrict f xs).mp (h x xs) intro h x xs exact (continuousWithinAt_iff_continuousAt_restrict f xs).mpr (h ⟨x, xs⟩) alias ⟨ContinuousOn.restrict, _⟩ := continuousOn_iff_continuous_restrict theorem ContinuousOn.restrict_mapsTo {t : Set β} (hf : ContinuousOn f s) (ht : MapsTo f s t) : Continuous (ht.restrict f s t) := hf.restrict.codRestrict _ theorem continuousOn_iff' : ContinuousOn f s ↔ ∀ t : Set β, IsOpen t → ∃ u, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsOpen (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isOpen_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff] constructor <;> · rintro ⟨u, ou, useq⟩ exact ⟨u, ou, by simpa only [Set.inter_comm, eq_comm] using useq⟩ rw [continuousOn_iff_continuous_restrict, continuous_def]; simp only [this] /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any finer topology on the source space. -/ theorem ContinuousOn.mono_dom {α β : Type*} {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₃ f s) : @ContinuousOn α β t₂ t₃ f s := fun x hx _u hu => map_mono (inf_le_inf_right _ <| nhds_mono h₁) (h₂ x hx hu) /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any coarser topology on the target space. -/ theorem ContinuousOn.mono_rng {α β : Type*} {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₂ f s) : @ContinuousOn α β t₁ t₃ f s := fun x hx _u hu => h₂ x hx <| nhds_mono h₁ hu theorem continuousOn_iff_isClosed : ContinuousOn f s ↔ ∀ t : Set β, IsClosed t → ∃ u, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsClosed (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isClosed_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm, Set.inter_comm s] rw [continuousOn_iff_continuous_restrict, continuous_iff_isClosed]; simp only [this] theorem continuous_of_cover_nhds {ι : Sort*} {s : ι → Set α} (hs : ∀ x : α, ∃ i, s i ∈ 𝓝 x) (hf : ∀ i, ContinuousOn f (s i)) : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ let ⟨i, hi⟩ := hs x; by rw [ContinuousAt, ← nhdsWithin_eq_nhds.2 hi] exact hf _ _ (mem_of_mem_nhds hi) @[simp] theorem continuousOn_empty (f : α → β) : ContinuousOn f ∅ := fun _ => False.elim @[simp] theorem continuousOn_singleton (f : α → β) (a : α) : ContinuousOn f {a} := forall_eq.2 <| by simpa only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_left] using fun s => mem_of_mem_nhds theorem Set.Subsingleton.continuousOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : ContinuousOn f s := hs.induction_on (continuousOn_empty f) (continuousOn_singleton f) theorem continuousOn_open_iff (hs : IsOpen s) : ContinuousOn f s ↔ ∀ t, IsOpen t → IsOpen (s ∩ f ⁻¹' t) := by rw [continuousOn_iff'] constructor · intro h t ht rcases h t ht with ⟨u, u_open, hu⟩ rw [inter_comm, hu] apply IsOpen.inter u_open hs · intro h t ht refine ⟨s ∩ f ⁻¹' t, h t ht, ?_⟩ rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] theorem ContinuousOn.isOpen_inter_preimage {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ∩ f ⁻¹' t) := (continuousOn_open_iff hs).1 hf t ht theorem ContinuousOn.isOpen_preimage {t : Set β} (h : ContinuousOn f s) (hs : IsOpen s) (hp : f ⁻¹' t ⊆ s) (ht : IsOpen t) : IsOpen (f ⁻¹' t) := by convert (continuousOn_open_iff hs).mp h t ht rw [inter_comm, inter_eq_self_of_subset_left hp] theorem ContinuousOn.preimage_isClosed_of_isClosed {t : Set β} (hf : ContinuousOn f s) (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s ∩ f ⁻¹' t) := by rcases continuousOn_iff_isClosed.1 hf t ht with ⟨u, hu⟩ rw [inter_comm, hu.2] apply IsClosed.inter hu.1 hs theorem ContinuousOn.preimage_interior_subset_interior_preimage {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) : s ∩ f ⁻¹' interior t ⊆ s ∩ interior (f ⁻¹' t) := calc s ∩ f ⁻¹' interior t ⊆ interior (s ∩ f ⁻¹' t) := interior_maximal (inter_subset_inter (Subset.refl _) (preimage_mono interior_subset)) (hf.isOpen_inter_preimage hs isOpen_interior) _ = s ∩ interior (f ⁻¹' t) := by rw [interior_inter, hs.interior_eq] theorem continuousOn_of_locally_continuousOn (h : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ContinuousOn f (s ∩ t)) : ContinuousOn f s := by intro x xs rcases h x xs with ⟨t, open_t, xt, ct⟩ have := ct x ⟨xs, xt⟩ rwa [ContinuousWithinAt, ← nhdsWithin_restrict _ xt open_t] at this theorem continuousOn_to_generateFrom_iff {β : Type*} {T : Set (Set β)} {f : α → β} : @ContinuousOn α β _ (.generateFrom T) f s ↔ ∀ x ∈ s, ∀ t ∈ T, f x ∈ t → f ⁻¹' t ∈ 𝓝[s] x := forall₂_congr fun x _ => by delta ContinuousWithinAt simp only [TopologicalSpace.nhds_generateFrom, tendsto_iInf, tendsto_principal, mem_setOf_eq, and_imp] exact forall_congr' fun t => forall_swap theorem continuousOn_isOpen_of_generateFrom {β : Type*} {s : Set α} {T : Set (Set β)} {f : α → β} (h : ∀ t ∈ T, IsOpen (s ∩ f ⁻¹' t)) : @ContinuousOn α β _ (.generateFrom T) f s := continuousOn_to_generateFrom_iff.2 fun _x hx t ht hxt => mem_nhdsWithin.2 ⟨_, h t ht, ⟨hx, hxt⟩, fun _y hy => hy.1.2⟩ /-! ### Congruence and monotonicity properties with respect to sets -/ theorem ContinuousWithinAt.mono (h : ContinuousWithinAt f t x) (hs : s ⊆ t) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_mono x hs) theorem ContinuousWithinAt.mono_of_mem_nhdsWithin (h : ContinuousWithinAt f t x) (hs : t ∈ 𝓝[s] x) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_le_of_mem hs) /-- If two sets coincide around `x`, then being continuous within one or the other at `x` is equivalent. See also `continuousWithinAt_congr_set'` which requires that the sets coincide locally away from a point `y`, in a T1 space. -/ theorem continuousWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : ContinuousWithinAt f s x ↔ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_eq_iff_eventuallyEq.mpr h] theorem ContinuousWithinAt.congr_set (hf : ContinuousWithinAt f s x) (h : s =ᶠ[𝓝 x] t) : ContinuousWithinAt f t x := (continuousWithinAt_congr_set h).1 hf theorem continuousWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict'' s h] theorem continuousWithinAt_inter (h : t ∈ 𝓝 x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict' s h] theorem continuousWithinAt_union : ContinuousWithinAt f (s ∪ t) x ↔ ContinuousWithinAt f s x ∧ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_union, tendsto_sup] theorem ContinuousWithinAt.union (hs : ContinuousWithinAt f s x) (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s ∪ t) x := continuousWithinAt_union.2 ⟨hs, ht⟩ @[simp] theorem continuousWithinAt_singleton : ContinuousWithinAt f {x} x := by simp only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_nhds] @[simp] theorem continuousWithinAt_insert_self : ContinuousWithinAt f (insert x s) x ↔ ContinuousWithinAt f s x := by simp only [← singleton_union, continuousWithinAt_union, continuousWithinAt_singleton, true_and] protected alias ⟨_, ContinuousWithinAt.insert⟩ := continuousWithinAt_insert_self /- `continuousWithinAt_insert` gives the same equivalence but at a point `y` possibly different from `x`. As this requires the space to be T1, and this property is not available in this file, this is found in another file although it is part of the basic API for `continuousWithinAt`. -/ theorem ContinuousWithinAt.diff_iff (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s \ t) x ↔ ContinuousWithinAt f s x := ⟨fun h => (h.union ht).mono <| by simp only [diff_union_self, subset_union_left], fun h => h.mono diff_subset⟩ /-- See also `continuousWithinAt_diff_singleton` for the case of `s \ {y}`, but requiring `T1Space α. -/ @[simp] theorem continuousWithinAt_diff_self : ContinuousWithinAt f (s \ {x}) x ↔ ContinuousWithinAt f s x := continuousWithinAt_singleton.diff_iff @[simp] theorem continuousWithinAt_compl_self : ContinuousWithinAt f {x}ᶜ x ↔ ContinuousAt f x := by rw [compl_eq_univ_diff, continuousWithinAt_diff_self, continuousWithinAt_univ] theorem ContinuousOn.mono (hf : ContinuousOn f s) (h : t ⊆ s) : ContinuousOn f t := fun x hx => (hf x (h hx)).mono_left (nhdsWithin_mono _ h) theorem antitone_continuousOn {f : α → β} : Antitone (ContinuousOn f) := fun _s _t hst hf => hf.mono hst /-! ### Relation between `ContinuousAt` and `ContinuousWithinAt` -/ theorem ContinuousAt.continuousWithinAt (h : ContinuousAt f x) : ContinuousWithinAt f s x := ContinuousWithinAt.mono ((continuousWithinAt_univ f x).2 h) (subset_univ _) theorem continuousWithinAt_iff_continuousAt (h : s ∈ 𝓝 x) : ContinuousWithinAt f s x ↔ ContinuousAt f x := by rw [← univ_inter s, continuousWithinAt_inter h, continuousWithinAt_univ] theorem ContinuousWithinAt.continuousAt (h : ContinuousWithinAt f s x) (hs : s ∈ 𝓝 x) : ContinuousAt f x := (continuousWithinAt_iff_continuousAt hs).mp h theorem IsOpen.continuousOn_iff (hs : IsOpen s) : ContinuousOn f s ↔ ∀ ⦃a⦄, a ∈ s → ContinuousAt f a := forall₂_congr fun _ => continuousWithinAt_iff_continuousAt ∘ hs.mem_nhds theorem ContinuousOn.continuousAt (h : ContinuousOn f s) (hx : s ∈ 𝓝 x) : ContinuousAt f x := (h x (mem_of_mem_nhds hx)).continuousAt hx theorem continuousOn_of_forall_continuousAt (hcont : ∀ x ∈ s, ContinuousAt f x) : ContinuousOn f s := fun x hx => (hcont x hx).continuousWithinAt @[deprecated (since := "2024-10-30")] alias ContinuousAt.continuousOn := continuousOn_of_forall_continuousAt @[fun_prop] theorem Continuous.continuousOn (h : Continuous f) : ContinuousOn f s := by rw [continuous_iff_continuousOn_univ] at h exact h.mono (subset_univ _) theorem Continuous.continuousWithinAt (h : Continuous f) : ContinuousWithinAt f s x := h.continuousAt.continuousWithinAt /-! ### Congruence properties with respect to functions -/ theorem ContinuousOn.congr_mono (h : ContinuousOn f s) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) : ContinuousOn g s₁ := by intro x hx unfold ContinuousWithinAt have A := (h x (h₁ hx)).mono h₁ unfold ContinuousWithinAt at A rw [← h' hx] at A exact A.congr' h'.eventuallyEq_nhdsWithin.symm theorem ContinuousOn.congr (h : ContinuousOn f s) (h' : EqOn g f s) : ContinuousOn g s := h.congr_mono h' (Subset.refl _) theorem continuousOn_congr (h' : EqOn g f s) : ContinuousOn g s ↔ ContinuousOn f s := ⟨fun h => ContinuousOn.congr h h'.symm, fun h => h.congr h'⟩ theorem Filter.EventuallyEq.congr_continuousWithinAt (h : f =ᶠ[𝓝[s] x] g) (hx : f x = g x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := by rw [ContinuousWithinAt, hx, tendsto_congr' h, ContinuousWithinAt] theorem ContinuousWithinAt.congr_of_eventuallyEq (h : ContinuousWithinAt f s x) (h₁ : g =ᶠ[𝓝[s] x] f) (hx : g x = f x) : ContinuousWithinAt g s x := (h₁.congr_continuousWithinAt hx).2 h theorem ContinuousWithinAt.congr_of_eventuallyEq_of_mem (h : ContinuousWithinAt f s x) (h₁ : g =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContinuousWithinAt g s x := h.congr_of_eventuallyEq h₁ (mem_of_mem_nhdsWithin hx h₁ :) theorem Filter.EventuallyEq.congr_continuousWithinAt_of_mem (h : f =ᶠ[𝓝[s] x] g) (hx : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := ⟨fun h' ↦ h'.congr_of_eventuallyEq_of_mem h.symm hx, fun h' ↦ h'.congr_of_eventuallyEq_of_mem h hx⟩ theorem ContinuousWithinAt.congr_of_eventuallyEq_insert (h : ContinuousWithinAt f s x) (h₁ : g =ᶠ[𝓝[insert x s] x] f) : ContinuousWithinAt g s x := h.congr_of_eventuallyEq (nhdsWithin_mono _ (subset_insert _ _) h₁) (mem_of_mem_nhdsWithin (mem_insert _ _) h₁ :) theorem Filter.EventuallyEq.congr_continuousWithinAt_of_insert (h : f =ᶠ[𝓝[insert x s] x] g) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := ⟨fun h' ↦ h'.congr_of_eventuallyEq_insert h.symm, fun h' ↦ h'.congr_of_eventuallyEq_insert h⟩ theorem ContinuousWithinAt.congr (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, g y = f y) (hx : g x = f x) : ContinuousWithinAt g s x := h.congr_of_eventuallyEq (mem_of_superset self_mem_nhdsWithin h₁) hx theorem continuousWithinAt_congr (h₁ : ∀ y ∈ s, g y = f y) (hx : g x = f x) : ContinuousWithinAt g s x ↔ ContinuousWithinAt f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContinuousWithinAt.congr_of_mem (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, g y = f y) (hx : x ∈ s) : ContinuousWithinAt g s x := h.congr h₁ (h₁ x hx) theorem continuousWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, g y = f y) (hx : x ∈ s) : ContinuousWithinAt g s x ↔ ContinuousWithinAt f s x := continuousWithinAt_congr h₁ (h₁ x hx) theorem ContinuousWithinAt.congr_of_insert (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ insert x s, g y = f y) : ContinuousWithinAt g s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem continuousWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, g y = f y) : ContinuousWithinAt g s x ↔ ContinuousWithinAt f s x := continuousWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContinuousWithinAt.congr_mono (h : ContinuousWithinAt f s x) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x) : ContinuousWithinAt g s₁ x := (h.mono h₁).congr h' hx theorem ContinuousAt.congr_of_eventuallyEq (h : ContinuousAt f x) (hg : g =ᶠ[𝓝 x] f) : ContinuousAt g x := by simp only [← continuousWithinAt_univ] at h ⊢ exact h.congr_of_eventuallyEq_of_mem (by rwa [nhdsWithin_univ]) (mem_univ x) /-! ### Composition -/ theorem ContinuousWithinAt.comp {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (hf.tendsto_nhdsWithin h) theorem ContinuousWithinAt.comp_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp hf h theorem ContinuousWithinAt.comp_inter {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp (hf.mono inter_subset_left) inter_subset_right theorem ContinuousWithinAt.comp_inter_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (hy : f x = y) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := by subst hy; exact hg.comp_inter hf theorem ContinuousWithinAt.comp_of_preimage_mem_nhdsWithin {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : f ⁻¹' t ∈ 𝓝[s] x) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within f hf h) theorem ContinuousWithinAt.comp_of_preimage_mem_nhdsWithin_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (h : f ⁻¹' t ∈ 𝓝[s] x) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp_of_preimage_mem_nhdsWithin hf h theorem ContinuousWithinAt.comp_of_mem_nhdsWithin_image {g : β → γ} {t : Set β} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (hs : t ∈ 𝓝[f '' s] f x) : ContinuousWithinAt (g ∘ f) s x := (hg.mono_of_mem_nhdsWithin hs).comp hf (mapsTo_image f s) theorem ContinuousWithinAt.comp_of_mem_nhdsWithin_image_of_eq {g : β → γ} {t : Set β} {y : β} (hg : ContinuousWithinAt g t y) (hf : ContinuousWithinAt f s x) (hs : t ∈ 𝓝[f '' s] y) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp_of_mem_nhdsWithin_image hf hs theorem ContinuousAt.comp_continuousWithinAt {g : β → γ} (hg : ContinuousAt g (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) s x := hg.continuousWithinAt.comp hf (mapsTo_univ _ _) theorem ContinuousAt.comp_continuousWithinAt_of_eq {g : β → γ} {y : β} (hg : ContinuousAt g y) (hf : ContinuousWithinAt f s x) (hy : f x = y) : ContinuousWithinAt (g ∘ f) s x := by subst hy; exact hg.comp_continuousWithinAt hf /-- See also `ContinuousOn.comp'` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ theorem ContinuousOn.comp {g : β → γ} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : MapsTo f s t) : ContinuousOn (g ∘ f) s := fun x hx => ContinuousWithinAt.comp (hg _ (h hx)) (hf x hx) h /-- Variant of `ContinuousOn.comp` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ @[fun_prop] theorem ContinuousOn.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : Set.MapsTo f s t) : ContinuousOn (fun x => g (f x)) s := ContinuousOn.comp hg hf h @[fun_prop] theorem ContinuousOn.comp_inter {g : β → γ} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right /-- See also `Continuous.comp_continuousOn'` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ theorem Continuous.comp_continuousOn {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) s := hg.continuousOn.comp hf (mapsTo_univ _ _) /-- Variant of `Continuous.comp_continuousOn` using the form `fun y ↦ g (f y)` instead of `g ∘ f`. -/ @[fun_prop] theorem Continuous.comp_continuousOn' {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ g (f x)) s := hg.comp_continuousOn hf theorem ContinuousOn.comp_continuous {g : β → γ} {f : α → β} {s : Set β} (hg : ContinuousOn g s) (hf : Continuous f) (hs : ∀ x, f x ∈ s) : Continuous (g ∘ f) := by rw [continuous_iff_continuousOn_univ] at * exact hg.comp hf fun x _ => hs x theorem ContinuousOn.image_comp_continuous {g : β → γ} {f : α → β} {s : Set α} (hg : ContinuousOn g (f '' s)) (hf : Continuous f) : ContinuousOn (g ∘ f) s := hg.comp hf.continuousOn (s.mapsTo_image f) theorem ContinuousAt.comp₂_continuousWithinAt {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := ContinuousAt.comp_continuousWithinAt hf (hg.prodMk_nhds hh) theorem ContinuousAt.comp₂_continuousWithinAt_of_eq {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} {y : β × γ} (hf : ContinuousAt f y) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) (e : (g x, h x) = y) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := by rw [← e] at hf exact hf.comp₂_continuousWithinAt hg hh /-! ### Image -/ theorem ContinuousWithinAt.mem_closure_image (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := haveI := mem_closure_iff_nhdsWithin_neBot.1 hx mem_closure_of_tendsto h <| mem_of_superset self_mem_nhdsWithin (subset_preimage_image f s) theorem ContinuousWithinAt.mem_closure {t : Set β} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) (ht : MapsTo f s t) : f x ∈ closure t := closure_mono (image_subset_iff.2 ht) (h.mem_closure_image hx) theorem Set.MapsTo.closure_of_continuousWithinAt {t : Set β} (h : MapsTo f s t) (hc : ∀ x ∈ closure s, ContinuousWithinAt f s x) : MapsTo f (closure s) (closure t) := fun x hx => (hc x hx).mem_closure hx h theorem Set.MapsTo.closure_of_continuousOn {t : Set β} (h : MapsTo f s t) (hc : ContinuousOn f (closure s)) : MapsTo f (closure s) (closure t) := h.closure_of_continuousWithinAt fun x hx => (hc x hx).mono subset_closure theorem ContinuousWithinAt.image_closure (hf : ∀ x ∈ closure s, ContinuousWithinAt f s x) : f '' closure s ⊆ closure (f '' s) := ((mapsTo_image f s).closure_of_continuousWithinAt hf).image_subset theorem ContinuousOn.image_closure (hf : ContinuousOn f (closure s)) : f '' closure s ⊆ closure (f '' s) := ContinuousWithinAt.image_closure fun x hx => (hf x hx).mono subset_closure /-! ### Product -/ theorem ContinuousWithinAt.prodMk {f : α → β} {g : α → γ} {s : Set α} {x : α} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) : ContinuousWithinAt (fun x => (f x, g x)) s x := hf.prodMk_nhds hg @[deprecated (since := "2025-03-10")] alias ContinuousWithinAt.prod := ContinuousWithinAt.prodMk @[fun_prop] theorem ContinuousOn.prodMk {f : α → β} {g : α → γ} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk (hg x hx) @[deprecated (since := "2025-03-10")] alias ContinuousOn.prod := ContinuousOn.prodMk theorem continuousOn_fst {s : Set (α × β)} : ContinuousOn Prod.fst s := continuous_fst.continuousOn theorem continuousWithinAt_fst {s : Set (α × β)} {p : α × β} : ContinuousWithinAt Prod.fst s p := continuous_fst.continuousWithinAt @[fun_prop] theorem ContinuousOn.fst {f : α → β × γ} {s : Set α} (hf : ContinuousOn f s) : ContinuousOn (fun x => (f x).1) s := continuous_fst.comp_continuousOn hf theorem ContinuousWithinAt.fst {f : α → β × γ} {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => (f x).fst) s a := continuousAt_fst.comp_continuousWithinAt h theorem continuousOn_snd {s : Set (α × β)} : ContinuousOn Prod.snd s := continuous_snd.continuousOn theorem continuousWithinAt_snd {s : Set (α × β)} {p : α × β} : ContinuousWithinAt Prod.snd s p := continuous_snd.continuousWithinAt @[fun_prop] theorem ContinuousOn.snd {f : α → β × γ} {s : Set α} (hf : ContinuousOn f s) : ContinuousOn (fun x => (f x).2) s := continuous_snd.comp_continuousOn hf theorem ContinuousWithinAt.snd {f : α → β × γ} {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => (f x).snd) s a := continuousAt_snd.comp_continuousWithinAt h theorem continuousWithinAt_prod_iff {f : α → β × γ} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (Prod.fst ∘ f) s x ∧ ContinuousWithinAt (Prod.snd ∘ f) s x := ⟨fun h => ⟨h.fst, h.snd⟩, fun ⟨h1, h2⟩ => h1.prodMk h2⟩ theorem ContinuousWithinAt.prodMap {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) : ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := .prodMk (hf.comp continuousWithinAt_fst mapsTo_fst_prod) (hg.comp continuousWithinAt_snd mapsTo_snd_prod) @[deprecated (since := "2025-03-10")] alias ContinuousWithinAt.prod_map := ContinuousWithinAt.prodMap theorem ContinuousOn.prodMap {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hg : ContinuousOn g t) : ContinuousOn (Prod.map f g) (s ×ˢ t) := fun ⟨x, y⟩ ⟨hx, hy⟩ => (hf x hx).prodMap (hg y hy) @[deprecated (since := "2025-03-10")] alias ContinuousOn.prod_map := ContinuousOn.prodMap theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod, ← map_inf_principal_preimage]; rfl theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure, ← map_inf_principal_preimage]; rfl theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl theorem continuousOn_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ b, ContinuousOn (f ⟨·, b⟩) {a | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_right]; apply forall_swap /-- If a function `f a b` is such that `y ↦ f a b` is continuous for all `a`, and `a` lives in a discrete space, then `f` is continuous, and vice versa. -/ theorem continuous_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : Continuous f ↔ ∀ a, Continuous (f ⟨a, ·⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_left theorem continuous_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : Continuous f ↔ ∀ b, Continuous (f ⟨·, b⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_right theorem isOpenMap_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : IsOpenMap f ↔ ∀ a, IsOpenMap (f ⟨a, ·⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, nhds_prod_eq, nhds_discrete, pure_prod, map_map] rfl theorem isOpenMap_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : IsOpenMap f ↔ ∀ b, IsOpenMap (f ⟨·, b⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, forall_swap (α := α) (β := β), nhds_prod_eq, nhds_discrete, prod_pure, map_map]; rfl /-! ### Pi -/ theorem continuousWithinAt_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ∀ i, ContinuousWithinAt (fun y => f y i) s x := tendsto_pi_nhds theorem continuousOn_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} : ContinuousOn f s ↔ ∀ i, ContinuousOn (fun y => f y i) s := ⟨fun h i x hx => tendsto_pi_nhds.1 (h x hx) i, fun h x hx => tendsto_pi_nhds.2 fun i => h i x hx⟩ @[fun_prop] theorem continuousOn_pi' {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} (hf : ∀ i, ContinuousOn (fun y => f y i) s) : ContinuousOn f s := continuousOn_pi.2 hf @[fun_prop] theorem continuousOn_apply {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] (i : ι) (s) : ContinuousOn (fun p : ∀ i, π i => p i) s := Continuous.continuousOn (continuous_apply i) /-! ### Specific functions -/ @[fun_prop] theorem continuousOn_const {s : Set α} {c : β} : ContinuousOn (fun _ => c) s := continuous_const.continuousOn theorem continuousWithinAt_const {b : β} {s : Set α} {x : α} : ContinuousWithinAt (fun _ : α => b) s x := continuous_const.continuousWithinAt theorem continuousOn_id {s : Set α} : ContinuousOn id s := continuous_id.continuousOn @[fun_prop] theorem continuousOn_id' (s : Set α) : ContinuousOn (fun x : α => x) s := continuousOn_id theorem continuousWithinAt_id {s : Set α} {x : α} : ContinuousWithinAt id s x := continuous_id.continuousWithinAt protected theorem ContinuousOn.iterate {f : α → α} {s : Set α} (hcont : ContinuousOn f s) (hmaps : MapsTo f s s) : ∀ n, ContinuousOn (f^[n]) s | 0 => continuousOn_id | (n + 1) => (hcont.iterate hmaps n).comp hcont hmaps section Fin variable {n : ℕ} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] theorem ContinuousWithinAt.finCons {f : α → π 0} {g : α → ∀ j : Fin n, π (Fin.succ j)} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => Fin.cons (f a) (g a)) s a := hf.tendsto.finCons hg theorem ContinuousOn.finCons {f : α → π 0} {s : Set α} {g : α → ∀ j : Fin n, π (Fin.succ j)} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => Fin.cons (f a) (g a)) s := fun a ha => (hf a ha).finCons (hg a ha) theorem ContinuousWithinAt.matrixVecCons {f : α → β} {g : α → Fin n → β} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => Matrix.vecCons (f a) (g a)) s a := hf.tendsto.matrixVecCons hg theorem ContinuousOn.matrixVecCons {f : α → β} {g : α → Fin n → β} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => Matrix.vecCons (f a) (g a)) s := fun a ha => (hf a ha).matrixVecCons (hg a ha) theorem ContinuousWithinAt.finSnoc {f : α → ∀ j : Fin n, π (Fin.castSucc j)} {g : α → π (Fin.last _)} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => Fin.snoc (f a) (g a)) s a := hf.tendsto.finSnoc hg theorem ContinuousOn.finSnoc {f : α → ∀ j : Fin n, π (Fin.castSucc j)} {g : α → π (Fin.last _)} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => Fin.snoc (f a) (g a)) s := fun a ha => (hf a ha).finSnoc (hg a ha) theorem ContinuousWithinAt.finInsertNth (i : Fin (n + 1)) {f : α → π i} {g : α → ∀ j : Fin n, π (i.succAbove j)} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => i.insertNth (f a) (g a)) s a := hf.tendsto.finInsertNth i hg @[deprecated (since := "2025-01-02")] alias ContinuousWithinAt.fin_insertNth := ContinuousWithinAt.finInsertNth theorem ContinuousOn.finInsertNth (i : Fin (n + 1)) {f : α → π i} {g : α → ∀ j : Fin n, π (i.succAbove j)} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun a => i.insertNth (f a) (g a)) s := fun a ha => (hf a ha).finInsertNth i (hg a ha) @[deprecated (since := "2025-01-02")] alias ContinuousOn.fin_insertNth := ContinuousOn.finInsertNth end Fin theorem Set.LeftInvOn.map_nhdsWithin_eq {f : α → β} {g : β → α} {x : β} {s : Set β} (h : LeftInvOn f g s) (hx : f (g x) = x) (hf : ContinuousWithinAt f (g '' s) (g x)) (hg : ContinuousWithinAt g s x) : map g (𝓝[s] x) = 𝓝[g '' s] g x := by apply le_antisymm · exact hg.tendsto_nhdsWithin (mapsTo_image _ _) · have A : g ∘ f =ᶠ[𝓝[g '' s] g x] id := h.rightInvOn_image.eqOn.eventuallyEq_of_mem self_mem_nhdsWithin refine le_map_of_right_inverse A ?_ simpa only [hx] using hf.tendsto_nhdsWithin (h.mapsTo (surjOn_image _ _)) theorem Function.LeftInverse.map_nhds_eq {f : α → β} {g : β → α} {x : β} (h : Function.LeftInverse f g) (hf : ContinuousWithinAt f (range g) (g x)) (hg : ContinuousAt g x) : map g (𝓝 x) = 𝓝[range g] g x := by simpa only [nhdsWithin_univ, image_univ] using (h.leftInvOn univ).map_nhdsWithin_eq (h x) (by rwa [image_univ]) hg.continuousWithinAt lemma Topology.IsInducing.continuousWithinAt_iff {f : α → β} {g : β → γ} (hg : IsInducing g) {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (g ∘ f) s x := by simp_rw [ContinuousWithinAt, hg.tendsto_nhds_iff]; rfl @[deprecated (since := "2024-10-28")] alias Inducing.continuousWithinAt_iff := IsInducing.continuousWithinAt_iff lemma Topology.IsInducing.continuousOn_iff {f : α → β} {g : β → γ} (hg : IsInducing g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := by simp_rw [ContinuousOn, hg.continuousWithinAt_iff] @[deprecated (since := "2024-10-28")] alias Inducing.continuousOn_iff := IsInducing.continuousOn_iff lemma Topology.IsEmbedding.continuousOn_iff {f : α → β} {g : β → γ} (hg : IsEmbedding g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := hg.isInducing.continuousOn_iff @[deprecated (since := "2024-10-26")] alias Embedding.continuousOn_iff := IsEmbedding.continuousOn_iff lemma Topology.IsEmbedding.map_nhdsWithin_eq {f : α → β} (hf : IsEmbedding f) (s : Set α) (x : α) : map f (𝓝[s] x) = 𝓝[f '' s] f x := by rw [nhdsWithin, Filter.map_inf hf.injective, hf.map_nhds_eq, map_principal, ← nhdsWithin_inter', inter_eq_self_of_subset_right (image_subset_range _ _)] @[deprecated (since := "2024-10-26")] alias Embedding.map_nhdsWithin_eq := IsEmbedding.map_nhdsWithin_eq
Mathlib/Topology/ContinuousOn.lean
1,315
1,318
theorem Topology.IsOpenEmbedding.map_nhdsWithin_preimage_eq {f : α → β} (hf : IsOpenEmbedding f) (s : Set β) (x : α) : map f (𝓝[f ⁻¹' s] x) = 𝓝[s] f x := by
rw [hf.isEmbedding.map_nhdsWithin_eq, image_preimage_eq_inter_range] apply nhdsWithin_eq_nhdsWithin (mem_range_self _) hf.isOpen_range
/- 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]
Mathlib/Data/ENNReal/Real.lean
332
335
theorem toReal_top_mul (a : ℝ≥0∞) : ENNReal.toReal (∞ * a) = 0 := by
rw [mul_comm] exact toReal_mul_top _
/- 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, Sébastien Gouëzel, Patrick Massot -/ import Mathlib.Topology.UniformSpace.Cauchy import Mathlib.Topology.UniformSpace.Separation import Mathlib.Topology.DenseEmbedding /-! # Uniform embeddings of uniform spaces. Extension of uniform continuous functions. -/ open Filter Function Set Uniformity Topology section universe u v w variable {α : Type u} {β : Type v} {γ : Type w} [UniformSpace α] [UniformSpace β] [UniformSpace γ] {f : α → β} /-! ### Uniform inducing maps -/ /-- A map `f : α → β` between uniform spaces is called *uniform inducing* if the uniformity filter on `α` is the pullback of the uniformity filter on `β` under `Prod.map f f`. If `α` is a separated space, then this implies that `f` is injective, hence it is a `IsUniformEmbedding`. -/ @[mk_iff] structure IsUniformInducing (f : α → β) : Prop where /-- The uniformity filter on the domain is the pullback of the uniformity filter on the codomain under `Prod.map f f`. -/ comap_uniformity : comap (fun x : α × α => (f x.1, f x.2)) (𝓤 β) = 𝓤 α lemma isUniformInducing_iff_uniformSpace {f : α → β} : IsUniformInducing f ↔ ‹UniformSpace β›.comap f = ‹UniformSpace α› := by rw [isUniformInducing_iff, UniformSpace.ext_iff, Filter.ext_iff] rfl protected alias ⟨IsUniformInducing.comap_uniformSpace, _⟩ := isUniformInducing_iff_uniformSpace lemma isUniformInducing_iff' {f : α → β} : IsUniformInducing f ↔ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by rw [isUniformInducing_iff, UniformContinuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; rfl protected lemma Filter.HasBasis.isUniformInducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : IsUniformInducing f ↔ (∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by simp [isUniformInducing_iff', h.uniformContinuous_iff h', (h'.comap _).le_basis_iff h, subset_def] theorem IsUniformInducing.mk' {f : α → β} (h : ∀ s, s ∈ 𝓤 α ↔ ∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : IsUniformInducing f := ⟨by simp [eq_comm, Filter.ext_iff, subset_def, h]⟩ theorem IsUniformInducing.id : IsUniformInducing (@id α) := ⟨by rw [← Prod.map_def, Prod.map_id, comap_id]⟩ theorem IsUniformInducing.comp {g : β → γ} (hg : IsUniformInducing g) {f : α → β} (hf : IsUniformInducing f) : IsUniformInducing (g ∘ f) := ⟨by rw [← hf.1, ← hg.1, comap_comap]; rfl⟩ theorem IsUniformInducing.of_comp_iff {g : β → γ} (hg : IsUniformInducing g) {f : α → β} : IsUniformInducing (g ∘ f) ↔ IsUniformInducing f := by refine ⟨fun h ↦ ?_, hg.comp⟩ rw [isUniformInducing_iff, ← hg.comap_uniformity, comap_comap, ← h.comap_uniformity, Function.comp_def, Function.comp_def] theorem IsUniformInducing.basis_uniformity {f : α → β} (hf : IsUniformInducing f) {ι : Sort*} {p : ι → Prop} {s : ι → Set (β × β)} (H : (𝓤 β).HasBasis p s) : (𝓤 α).HasBasis p fun i => Prod.map f f ⁻¹' s i := hf.1 ▸ H.comap _ theorem IsUniformInducing.cauchy_map_iff {f : α → β} (hf : IsUniformInducing f) {F : Filter α} : Cauchy (map f F) ↔ Cauchy F := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap, ← hf.comap_uniformity] theorem IsUniformInducing.of_comp {f : α → β} {g : β → γ} (hf : UniformContinuous f) (hg : UniformContinuous g) (hgf : IsUniformInducing (g ∘ f)) : IsUniformInducing f := by refine ⟨le_antisymm ?_ hf.le_comap⟩ rw [← hgf.1, ← Prod.map_def, ← Prod.map_def, ← Prod.map_comp_map f f g g, ← comap_comap] exact comap_mono hg.le_comap theorem IsUniformInducing.uniformContinuous {f : α → β} (hf : IsUniformInducing f) : UniformContinuous f := (isUniformInducing_iff'.1 hf).1 theorem IsUniformInducing.uniformContinuous_iff {f : α → β} {g : β → γ} (hg : IsUniformInducing g) : UniformContinuous f ↔ UniformContinuous (g ∘ f) := by dsimp only [UniformContinuous, Tendsto] simp only [← hg.comap_uniformity, ← map_le_iff_le_comap, Filter.map_map, Function.comp_def] protected theorem IsUniformInducing.isUniformInducing_comp_iff {f : α → β} {g : β → γ} (hg : IsUniformInducing g) : IsUniformInducing (g ∘ f) ↔ IsUniformInducing f := by simp only [isUniformInducing_iff, ← hg.comap_uniformity, comap_comap, Function.comp_def] theorem IsUniformInducing.uniformContinuousOn_iff {f : α → β} {g : β → γ} {S : Set α} (hg : IsUniformInducing g) : UniformContinuousOn f S ↔ UniformContinuousOn (g ∘ f) S := by dsimp only [UniformContinuousOn, Tendsto] rw [← hg.comap_uniformity, ← map_le_iff_le_comap, Filter.map_map, comp_def, comp_def] theorem IsUniformInducing.isInducing {f : α → β} (h : IsUniformInducing f) : IsInducing f := by obtain rfl := h.comap_uniformSpace exact .induced f @[deprecated (since := "2024-10-28")] alias IsUniformInducing.inducing := IsUniformInducing.isInducing @[deprecated (since := "2024-10-28")] alias UniformInducing.inducing := IsUniformInducing.isInducing theorem IsUniformInducing.prod {α' : Type*} {β' : Type*} [UniformSpace α'] [UniformSpace β'] {e₁ : α → α'} {e₂ : β → β'} (h₁ : IsUniformInducing e₁) (h₂ : IsUniformInducing e₂) : IsUniformInducing fun p : α × β => (e₁ p.1, e₂ p.2) := ⟨by simp [Function.comp_def, uniformity_prod, ← h₁.1, ← h₂.1, comap_inf, comap_comap]⟩ lemma IsUniformInducing.isDenseInducing (h : IsUniformInducing f) (hd : DenseRange f) : IsDenseInducing f where toIsInducing := h.isInducing dense := hd lemma SeparationQuotient.isUniformInducing_mk : IsUniformInducing (mk : α → SeparationQuotient α) := ⟨comap_mk_uniformity⟩ protected theorem IsUniformInducing.injective [T0Space α] {f : α → β} (h : IsUniformInducing f) : Injective f := h.isInducing.injective /-! ### Uniform embeddings -/ /-- A map `f : α → β` between uniform spaces is a *uniform embedding* if it is uniform inducing and injective. If `α` is a separated space, then the latter assumption follows from the former. -/ @[mk_iff] structure IsUniformEmbedding (f : α → β) : Prop extends IsUniformInducing f where /-- A uniform embedding is injective. -/ injective : Function.Injective f lemma IsUniformEmbedding.isUniformInducing (hf : IsUniformEmbedding f) : IsUniformInducing f := hf.toIsUniformInducing theorem isUniformEmbedding_iff' {f : α → β} : IsUniformEmbedding f ↔ Injective f ∧ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by rw [isUniformEmbedding_iff, and_comm, isUniformInducing_iff'] theorem Filter.HasBasis.isUniformEmbedding_iff' {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : IsUniformEmbedding f ↔ Injective f ∧ (∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by rw [isUniformEmbedding_iff, and_comm, h.isUniformInducing_iff h'] theorem Filter.HasBasis.isUniformEmbedding_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'} (h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} : IsUniformEmbedding f ↔ Injective f ∧ UniformContinuous f ∧ (∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by simp only [h.isUniformEmbedding_iff' h', h.uniformContinuous_iff h'] theorem isUniformEmbedding_subtype_val {p : α → Prop} : IsUniformEmbedding (Subtype.val : Subtype p → α) := { comap_uniformity := rfl injective := Subtype.val_injective } theorem isUniformEmbedding_set_inclusion {s t : Set α} (hst : s ⊆ t) : IsUniformEmbedding (inclusion hst) where comap_uniformity := by rw [uniformity_subtype, uniformity_subtype, comap_comap]; rfl injective := inclusion_injective hst theorem IsUniformEmbedding.comp {g : β → γ} (hg : IsUniformEmbedding g) {f : α → β} (hf : IsUniformEmbedding f) : IsUniformEmbedding (g ∘ f) where toIsUniformInducing := hg.isUniformInducing.comp hf.isUniformInducing injective := hg.injective.comp hf.injective
Mathlib/Topology/UniformSpace/UniformEmbedding.lean
180
183
theorem IsUniformEmbedding.of_comp_iff {g : β → γ} (hg : IsUniformEmbedding g) {f : α → β} : IsUniformEmbedding (g ∘ f) ↔ IsUniformEmbedding f := by
simp_rw [isUniformEmbedding_iff, hg.isUniformInducing.of_comp_iff, hg.injective.of_comp_iff f]
/- Copyright (c) 2020 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Algebra.Group.Action.Pi import Mathlib.Data.Finset.Prod import Mathlib.Data.SetLike.Basic import Mathlib.Data.Sym.Basic import Mathlib.Data.Sym.Sym2.Init /-! # The symmetric square This file defines the symmetric square, which is `α × α` modulo swapping. This is also known as the type of unordered pairs. More generally, the symmetric square is the second symmetric power (see `Data.Sym.Basic`). The equivalence is `Sym2.equivSym`. From the point of view that an unordered pair is equivalent to a multiset of cardinality two (see `Sym2.equivMultiset`), there is a `Mem` instance `Sym2.Mem`, which is a `Prop`-valued membership test. Given `h : a ∈ z` for `z : Sym2 α`, then `Mem.other h` is the other element of the pair, defined using `Classical.choice`. If `α` has decidable equality, then `h.other'` computably gives the other element. The universal property of `Sym2` is provided as `Sym2.lift`, which states that functions from `Sym2 α` are equivalent to symmetric two-argument functions from `α`. Recall that an undirected graph (allowing self loops, but no multiple edges) is equivalent to a symmetric relation on the vertex type `α`. Given a symmetric relation on `α`, the corresponding edge set is constructed by `Sym2.fromRel` which is a special case of `Sym2.lift`. ## Notation The element `Sym2.mk (a, b)` can be written as `s(a, b)` for short. ## Tags symmetric square, unordered pairs, symmetric powers -/ assert_not_exists MonoidWithZero open List (Vector) open Finset Function Sym universe u variable {α β γ : Type*} namespace Sym2 /-- This is the relation capturing the notion of pairs equivalent up to permutations. -/ @[aesop (rule_sets := [Sym2]) [safe [constructors, cases], norm]] inductive Rel (α : Type u) : α × α → α × α → Prop | refl (x y : α) : Rel _ (x, y) (x, y) | swap (x y : α) : Rel _ (x, y) (y, x) attribute [refl] Rel.refl @[symm] theorem Rel.symm {x y : α × α} : Rel α x y → Rel α y x := by aesop (rule_sets := [Sym2]) @[trans] theorem Rel.trans {x y z : α × α} (a : Rel α x y) (b : Rel α y z) : Rel α x z := by aesop (rule_sets := [Sym2]) theorem Rel.is_equivalence : Equivalence (Rel α) := { refl := fun (x, y) ↦ Rel.refl x y, symm := Rel.symm, trans := Rel.trans } /-- One can use `attribute [local instance] Sym2.Rel.setoid` to temporarily make `Quotient` functionality work for `α × α`. -/ def Rel.setoid (α : Type u) : Setoid (α × α) := ⟨Rel α, Rel.is_equivalence⟩ @[simp] theorem rel_iff' {p q : α × α} : Rel α p q ↔ p = q ∨ p = q.swap := by aesop (rule_sets := [Sym2]) theorem rel_iff {x y z w : α} : Rel α (x, y) (z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp end Sym2 /-- `Sym2 α` is the symmetric square of `α`, which, in other words, is the type of unordered pairs. It is equivalent in a natural way to multisets of cardinality 2 (see `Sym2.equivMultiset`). -/ abbrev Sym2 (α : Type u) := Quot (Sym2.Rel α) /-- Constructor for `Sym2`. This is the quotient map `α × α → Sym2 α`. -/ protected abbrev Sym2.mk {α : Type*} (p : α × α) : Sym2 α := Quot.mk (Sym2.Rel α) p /-- `s(x, y)` is an unordered pair, which is to say a pair modulo the action of the symmetric group. It is equal to `Sym2.mk (x, y)`. -/ notation3 "s(" x ", " y ")" => Sym2.mk (x, y) namespace Sym2 protected theorem sound {p p' : α × α} (h : Sym2.Rel α p p') : Sym2.mk p = Sym2.mk p' := Quot.sound h protected theorem exact {p p' : α × α} (h : Sym2.mk p = Sym2.mk p') : Sym2.Rel α p p' := Quotient.exact (s := Sym2.Rel.setoid α) h @[simp] protected theorem eq {p p' : α × α} : Sym2.mk p = Sym2.mk p' ↔ Sym2.Rel α p p' := Quotient.eq' (s₁ := Sym2.Rel.setoid α) @[elab_as_elim, cases_eliminator, induction_eliminator] protected theorem ind {f : Sym2 α → Prop} (h : ∀ x y, f s(x, y)) : ∀ i, f i := Quot.ind <| Prod.rec <| h @[elab_as_elim] protected theorem inductionOn {f : Sym2 α → Prop} (i : Sym2 α) (hf : ∀ x y, f s(x, y)) : f i := i.ind hf @[elab_as_elim] protected theorem inductionOn₂ {f : Sym2 α → Sym2 β → Prop} (i : Sym2 α) (j : Sym2 β) (hf : ∀ a₁ a₂ b₁ b₂, f s(a₁, a₂) s(b₁, b₂)) : f i j := Quot.induction_on₂ i j <| by intro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩ exact hf _ _ _ _ /-- Dependent recursion principal for `Sym2`. See `Quot.rec`. -/ @[elab_as_elim] protected def rec {motive : Sym2 α → Sort*} (f : (p : α × α) → motive (Sym2.mk p)) (h : (p q : α × α) → (h : Sym2.Rel α p q) → Eq.ndrec (f p) (Sym2.sound h) = f q) (z : Sym2 α) : motive z := Quot.rec f h z /-- Dependent recursion principal for `Sym2` when the target is a `Subsingleton` type. See `Quot.recOnSubsingleton`. -/ @[elab_as_elim] protected abbrev recOnSubsingleton {motive : Sym2 α → Sort*} [(p : α × α) → Subsingleton (motive (Sym2.mk p))] (z : Sym2 α) (f : (p : α × α) → motive (Sym2.mk p)) : motive z := Quot.recOnSubsingleton z f protected theorem «exists» {α : Sort _} {f : Sym2 α → Prop} : (∃ x : Sym2 α, f x) ↔ ∃ x y, f s(x, y) := Quot.mk_surjective.exists.trans Prod.exists protected theorem «forall» {α : Sort _} {f : Sym2 α → Prop} : (∀ x : Sym2 α, f x) ↔ ∀ x y, f s(x, y) := Quot.mk_surjective.forall.trans Prod.forall theorem eq_swap {a b : α} : s(a, b) = s(b, a) := Quot.sound (Rel.swap _ _) @[simp] theorem mk_prod_swap_eq {p : α × α} : Sym2.mk p.swap = Sym2.mk p := by cases p exact eq_swap theorem congr_right {a b c : α} : s(a, b) = s(a, c) ↔ b = c := by simp +contextual theorem congr_left {a b c : α} : s(b, a) = s(c, a) ↔ b = c := by simp +contextual theorem eq_iff {x y z w : α} : s(x, y) = s(z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp theorem mk_eq_mk_iff {p q : α × α} : Sym2.mk p = Sym2.mk q ↔ p = q ∨ p = q.swap := by cases p cases q simp only [eq_iff, Prod.mk_inj, Prod.swap_prod_mk] /-- The universal property of `Sym2`; symmetric functions of two arguments are equivalent to functions from `Sym2`. Note that when `β` is `Prop`, it can sometimes be more convenient to use `Sym2.fromRel` instead. -/ def lift : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ } ≃ (Sym2 α → β) where toFun f := Quot.lift (uncurry ↑f) <| by rintro _ _ ⟨⟩ exacts [rfl, f.prop _ _] invFun F := ⟨curry (F ∘ Sym2.mk), fun _ _ => congr_arg F eq_swap⟩ left_inv _ := Subtype.ext rfl right_inv _ := funext <| Sym2.ind fun _ _ => rfl @[simp] theorem lift_mk (f : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ }) (a₁ a₂ : α) : lift f s(a₁, a₂) = (f : α → α → β) a₁ a₂ := rfl @[simp] theorem coe_lift_symm_apply (F : Sym2 α → β) (a₁ a₂ : α) : (lift.symm F : α → α → β) a₁ a₂ = F s(a₁, a₂) := rfl /-- A two-argument version of `Sym2.lift`. -/ def lift₂ : { f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ } ≃ (Sym2 α → Sym2 β → γ) where toFun f := Quotient.lift₂ (s₁ := Sym2.Rel.setoid α) (s₂ := Sym2.Rel.setoid β) (fun (a : α × α) (b : β × β) => f.1 a.1 a.2 b.1 b.2) (by rintro _ _ _ _ ⟨⟩ ⟨⟩ exacts [rfl, (f.2 _ _ _ _).2, (f.2 _ _ _ _).1, (f.2 _ _ _ _).1.trans (f.2 _ _ _ _).2]) invFun F := ⟨fun a₁ a₂ b₁ b₂ => F s(a₁, a₂) s(b₁, b₂), fun a₁ a₂ b₁ b₂ => by constructor exacts [congr_arg₂ F eq_swap rfl, congr_arg₂ F rfl eq_swap]⟩ left_inv _ := Subtype.ext rfl right_inv _ := funext₂ fun a b => Sym2.inductionOn₂ a b fun _ _ _ _ => rfl @[simp] theorem lift₂_mk (f : { f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ }) (a₁ a₂ : α) (b₁ b₂ : β) : lift₂ f s(a₁, a₂) s(b₁, b₂) = (f : α → α → β → β → γ) a₁ a₂ b₁ b₂ := rfl @[simp] theorem coe_lift₂_symm_apply (F : Sym2 α → Sym2 β → γ) (a₁ a₂ : α) (b₁ b₂ : β) : (lift₂.symm F : α → α → β → β → γ) a₁ a₂ b₁ b₂ = F s(a₁, a₂) s(b₁, b₂) := rfl /-- The functor `Sym2` is functorial, and this function constructs the induced maps. -/ def map (f : α → β) : Sym2 α → Sym2 β := Quot.map (Prod.map f f) (by intro _ _ h; cases h <;> constructor) @[simp] theorem map_id : map (@id α) = id := by ext ⟨⟨x, y⟩⟩ rfl theorem map_comp {g : β → γ} {f : α → β} : Sym2.map (g ∘ f) = Sym2.map g ∘ Sym2.map f := by ext ⟨⟨x, y⟩⟩ rfl theorem map_map {g : β → γ} {f : α → β} (x : Sym2 α) : map g (map f x) = map (g ∘ f) x := by induction x; aesop @[simp] theorem map_pair_eq (f : α → β) (x y : α) : map f s(x, y) = s(f x, f y) := rfl theorem map.injective {f : α → β} (hinj : Injective f) : Injective (map f) := by intro z z' refine Sym2.inductionOn₂ z z' (fun x y x' y' => ?_) simp [hinj.eq_iff] /-- `mk a` as an embedding. This is the symmetric version of `Function.Embedding.sectL`. -/ @[simps] def mkEmbedding (a : α) : α ↪ Sym2 α where toFun b := s(a, b) inj' b₁ b₁ h := by simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, true_and, Prod.swap_prod_mk] at h obtain rfl | ⟨rfl, rfl⟩ := h <;> rfl /-- `Sym2.map` as an embedding. -/ @[simps] def _root_.Function.Embedding.sym2Map (f : α ↪ β) : Sym2 α ↪ Sym2 β where toFun := map f inj' := map.injective f.injective lemma lift_comp_map {g : γ → α} (f : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁}) : lift f ∘ map g = lift ⟨fun (c₁ c₂ : γ) => f.val (g c₁) (g c₂), fun _ _ => f.prop _ _⟩ := lift.symm_apply_eq.mp rfl lemma lift_map_apply {g : γ → α} (f : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁}) (p : Sym2 γ) : lift f (map g p) = lift ⟨fun (c₁ c₂ : γ) => f.val (g c₁) (g c₂), fun _ _ => f.prop _ _⟩ p := by conv_rhs => rw [← lift_comp_map, comp_apply] section Membership /-! ### Membership and set coercion -/ /-- This is a predicate that determines whether a given term is a member of a term of the symmetric square. From this point of view, the symmetric square is the subtype of cardinality-two multisets on `α`. -/ protected def Mem (x : α) (z : Sym2 α) : Prop := ∃ y : α, z = s(x, y) @[aesop norm (rule_sets := [Sym2])] theorem mem_iff' {a b c : α} : Sym2.Mem a s(b, c) ↔ a = b ∨ a = c := { mp := by rintro ⟨_, h⟩ rw [eq_iff] at h aesop mpr := by rintro (rfl | rfl) · exact ⟨_, rfl⟩ rw [eq_swap] exact ⟨_, rfl⟩ } instance : SetLike (Sym2 α) α where coe z := { x | z.Mem x } coe_injective' z z' h := by simp only [Set.ext_iff, Set.mem_setOf_eq] at h obtain ⟨x, y⟩ := z obtain ⟨x', y'⟩ := z' have hx := h x; have hy := h y; have hx' := h x'; have hy' := h y' simp only [mem_iff', eq_self_iff_true] at hx hy hx' hy' aesop @[simp] theorem mem_iff_mem {x : α} {z : Sym2 α} : Sym2.Mem x z ↔ x ∈ z := Iff.rfl theorem mem_iff_exists {x : α} {z : Sym2 α} : x ∈ z ↔ ∃ y : α, z = s(x, y) := Iff.rfl @[ext] theorem ext {p q : Sym2 α} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h theorem mem_mk_left (x y : α) : x ∈ s(x, y) := ⟨y, rfl⟩ theorem mem_mk_right (x y : α) : y ∈ s(x, y) := eq_swap ▸ mem_mk_left y x @[simp, aesop norm (rule_sets := [Sym2])] theorem mem_iff {a b c : α} : a ∈ s(b, c) ↔ a = b ∨ a = c := mem_iff' theorem out_fst_mem (e : Sym2 α) : e.out.1 ∈ e := ⟨e.out.2, by rw [Sym2.mk, e.out_eq]⟩ theorem out_snd_mem (e : Sym2 α) : e.out.2 ∈ e := ⟨e.out.1, by rw [eq_swap, Sym2.mk, e.out_eq]⟩ theorem ball {p : α → Prop} {a b : α} : (∀ c ∈ s(a, b), p c) ↔ p a ∧ p b := by refine ⟨fun h => ⟨h _ <| mem_mk_left _ _, h _ <| mem_mk_right _ _⟩, fun h c hc => ?_⟩ obtain rfl | rfl := Sym2.mem_iff.1 hc · exact h.1 · exact h.2 /-- Given an element of the unordered pair, give the other element using `Classical.choose`. See also `Mem.other'` for the computable version. -/ noncomputable def Mem.other {a : α} {z : Sym2 α} (h : a ∈ z) : α := Classical.choose h @[simp]
Mathlib/Data/Sym/Sym2.lean
354
355
theorem other_spec {a : α} {z : Sym2 α} (h : a ∈ z) : s(a, Mem.other h) = z := by
erw [← Classical.choose_spec h]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Ring.Associated import Mathlib.Algebra.Ring.Regular /-! # Monoids with normalization functions, `gcd`, and `lcm` This file defines extra structures on `CancelCommMonoidWithZero`s, including `IsDomain`s. ## Main Definitions * `NormalizationMonoid` * `GCDMonoid` * `NormalizedGCDMonoid` * `gcdMonoidOfGCD`, `gcdMonoidOfExistsGCD`, `normalizedGCDMonoidOfGCD`, `normalizedGCDMonoidOfExistsGCD` * `gcdMonoidOfLCM`, `gcdMonoidOfExistsLCM`, `normalizedGCDMonoidOfLCM`, `normalizedGCDMonoidOfExistsLCM` For the `NormalizedGCDMonoid` instances on `ℕ` and `ℤ`, see `Mathlib.Algebra.GCDMonoid.Nat`. ## Implementation Notes * `NormalizationMonoid` is defined by assigning to each element a `normUnit` such that multiplying by that unit normalizes the monoid, and `normalize` is an idempotent monoid homomorphism. This definition as currently implemented does casework on `0`. * `GCDMonoid` contains the definitions of `gcd` and `lcm` with the usual properties. They are both determined up to a unit. * `NormalizedGCDMonoid` extends `NormalizationMonoid`, so the `gcd` and `lcm` are always normalized. This makes `gcd`s of polynomials easier to work with, but excludes Euclidean domains, and monoids without zero. * `gcdMonoidOfGCD` and `normalizedGCDMonoidOfGCD` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `gcd` and its properties. * `gcdMonoidOfExistsGCD` and `normalizedGCDMonoidOfExistsGCD` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `gcd`. * `gcdMonoidOfLCM` and `normalizedGCDMonoidOfLCM` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from the `lcm` and its properties. * `gcdMonoidOfExistsLCM` and `normalizedGCDMonoidOfExistsLCM` noncomputably construct a `GCDMonoid` (resp. `NormalizedGCDMonoid`) structure just from a proof that any two elements have a (not necessarily normalized) `lcm`. ## TODO * Port GCD facts about nats, definition of coprime * Generalize normalization monoids to commutative (cancellative) monoids with or without zero ## Tags divisibility, gcd, lcm, normalize -/ variable {α : Type*} /-- Normalization monoid: multiplying with `normUnit` gives a normal form for associated elements. -/ class NormalizationMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- `normUnit` assigns to each element of the monoid a unit of the monoid. -/ normUnit : α → αˣ /-- The proposition that `normUnit` maps `0` to the identity. -/ normUnit_zero : normUnit 0 = 1 /-- The proposition that `normUnit` respects multiplication of non-zero elements. -/ normUnit_mul : ∀ {a b}, a ≠ 0 → b ≠ 0 → normUnit (a * b) = normUnit a * normUnit b /-- The proposition that `normUnit` maps units to their inverses. -/ normUnit_coe_units : ∀ u : αˣ, normUnit u = u⁻¹ export NormalizationMonoid (normUnit normUnit_zero normUnit_mul normUnit_coe_units) attribute [simp] normUnit_coe_units normUnit_zero normUnit_mul section NormalizationMonoid variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] @[simp] theorem normUnit_one : normUnit (1 : α) = 1 := normUnit_coe_units 1 /-- Chooses an element of each associate class, by multiplying by `normUnit` -/ def normalize : α →*₀ α where toFun x := x * normUnit x map_zero' := by simp only [normUnit_zero] exact mul_one (0 : α) map_one' := by rw [normUnit_one, one_mul]; rfl map_mul' x y := (by_cases fun hx : x = 0 => by rw [hx, zero_mul, zero_mul, zero_mul]) fun hx => (by_cases fun hy : y = 0 => by rw [hy, mul_zero, zero_mul, mul_zero]) fun hy => by simp only [normUnit_mul hx hy, Units.val_mul]; simp only [mul_assoc, mul_left_comm y] theorem associated_normalize (x : α) : Associated x (normalize x) := ⟨_, rfl⟩ theorem normalize_associated (x : α) : Associated (normalize x) x := (associated_normalize _).symm theorem associated_normalize_iff {x y : α} : Associated x (normalize y) ↔ Associated x y := ⟨fun h => h.trans (normalize_associated y), fun h => h.trans (associated_normalize y)⟩ theorem normalize_associated_iff {x y : α} : Associated (normalize x) y ↔ Associated x y := ⟨fun h => (associated_normalize _).trans h, fun h => (normalize_associated _).trans h⟩ theorem Associates.mk_normalize (x : α) : Associates.mk (normalize x) = Associates.mk x := Associates.mk_eq_mk_iff_associated.2 (normalize_associated _) theorem normalize_apply (x : α) : normalize x = x * normUnit x := rfl theorem normalize_zero : normalize (0 : α) = 0 := normalize.map_zero theorem normalize_one : normalize (1 : α) = 1 := normalize.map_one theorem normalize_coe_units (u : αˣ) : normalize (u : α) = 1 := by simp [normalize_apply] theorem normalize_eq_zero {x : α} : normalize x = 0 ↔ x = 0 := ⟨fun hx => (associated_zero_iff_eq_zero x).1 <| hx ▸ associated_normalize _, by rintro rfl; exact normalize_zero⟩ theorem normalize_eq_one {x : α} : normalize x = 1 ↔ IsUnit x := ⟨fun hx => isUnit_iff_exists_inv.2 ⟨_, hx⟩, fun ⟨u, hu⟩ => hu ▸ normalize_coe_units u⟩ @[simp] theorem normUnit_mul_normUnit (a : α) : normUnit (a * normUnit a) = 1 := by nontriviality α using Subsingleton.elim a 0 obtain rfl | h := eq_or_ne a 0 · rw [normUnit_zero, zero_mul, normUnit_zero] · rw [normUnit_mul h (Units.ne_zero _), normUnit_coe_units, mul_inv_eq_one] @[simp] theorem normalize_idem (x : α) : normalize (normalize x) = normalize x := by simp [normalize_apply] theorem normalize_eq_normalize {a b : α} (hab : a ∣ b) (hba : b ∣ a) : normalize a = normalize b := by nontriviality α rcases associated_of_dvd_dvd hab hba with ⟨u, rfl⟩ refine by_cases (by rintro rfl; simp only [zero_mul]) fun ha : a ≠ 0 => ?_ suffices a * ↑(normUnit a) = a * ↑u * ↑(normUnit a) * ↑u⁻¹ by simpa only [normalize_apply, mul_assoc, normUnit_mul ha u.ne_zero, normUnit_coe_units] calc a * ↑(normUnit a) = a * ↑(normUnit a) * ↑u * ↑u⁻¹ := (Units.mul_inv_cancel_right _ _).symm _ = a * ↑u * ↑(normUnit a) * ↑u⁻¹ := by rw [mul_right_comm a] theorem normalize_eq_normalize_iff {x y : α} : normalize x = normalize y ↔ x ∣ y ∧ y ∣ x := ⟨fun h => ⟨Units.dvd_mul_right.1 ⟨_, h.symm⟩, Units.dvd_mul_right.1 ⟨_, h⟩⟩, fun ⟨hxy, hyx⟩ => normalize_eq_normalize hxy hyx⟩ theorem dvd_antisymm_of_normalize_eq {a b : α} (ha : normalize a = a) (hb : normalize b = b) (hab : a ∣ b) (hba : b ∣ a) : a = b := ha ▸ hb ▸ normalize_eq_normalize hab hba theorem Associated.eq_of_normalized {a b : α} (h : Associated a b) (ha : normalize a = a) (hb : normalize b = b) : a = b := dvd_antisymm_of_normalize_eq ha hb h.dvd h.dvd' @[simp] theorem dvd_normalize_iff {a b : α} : a ∣ normalize b ↔ a ∣ b := Units.dvd_mul_right @[simp] theorem normalize_dvd_iff {a b : α} : normalize a ∣ b ↔ a ∣ b := Units.mul_right_dvd end NormalizationMonoid namespace Associates variable [CancelCommMonoidWithZero α] [NormalizationMonoid α] /-- Maps an element of `Associates` back to the normalized element of its associate class -/ protected def out : Associates α → α := (Quotient.lift (normalize : α → α)) fun a _ ⟨_, hu⟩ => hu ▸ normalize_eq_normalize ⟨_, rfl⟩ (Units.mul_right_dvd.2 <| dvd_refl a) @[simp] theorem out_mk (a : α) : (Associates.mk a).out = normalize a := rfl @[simp] theorem out_one : (1 : Associates α).out = 1 := normalize_one theorem out_mul (a b : Associates α) : (a * b).out = a.out * b.out := Quotient.inductionOn₂ a b fun _ _ => by simp only [Associates.quotient_mk_eq_mk, out_mk, mk_mul_mk, normalize.map_mul] theorem dvd_out_iff (a : α) (b : Associates α) : a ∣ b.out ↔ Associates.mk a ≤ b := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] theorem out_dvd_iff (a : α) (b : Associates α) : b.out ∣ a ↔ b ≤ Associates.mk a := Quotient.inductionOn b <| by simp [Associates.out_mk, Associates.quotient_mk_eq_mk, mk_le_mk_iff_dvd] @[simp] theorem out_top : (⊤ : Associates α).out = 0 := normalize_zero @[simp] theorem normalize_out (a : Associates α) : normalize a.out = a.out := Quotient.inductionOn a normalize_idem @[simp] theorem mk_out (a : Associates α) : Associates.mk a.out = a := Quotient.inductionOn a mk_normalize theorem out_injective : Function.Injective (Associates.out : _ → α) := Function.LeftInverse.injective mk_out end Associates /-- GCD monoid: a `CancelCommMonoidWithZero` with `gcd` (greatest common divisor) and `lcm` (least common multiple) operations, determined up to a unit. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class GCDMonoid (α : Type*) [CancelCommMonoidWithZero α] where /-- The greatest common divisor between two elements. -/ gcd : α → α → α /-- The least common multiple between two elements. -/ lcm : α → α → α /-- The GCD is a divisor of the first element. -/ gcd_dvd_left : ∀ a b, gcd a b ∣ a /-- The GCD is a divisor of the second element. -/ gcd_dvd_right : ∀ a b, gcd a b ∣ b /-- Any common divisor of both elements is a divisor of the GCD. -/ dvd_gcd : ∀ {a b c}, a ∣ c → a ∣ b → a ∣ gcd c b /-- The product of two elements is `Associated` with the product of their GCD and LCM. -/ gcd_mul_lcm : ∀ a b, Associated (gcd a b * lcm a b) (a * b) /-- `0` is left-absorbing. -/ lcm_zero_left : ∀ a, lcm 0 a = 0 /-- `0` is right-absorbing. -/ lcm_zero_right : ∀ a, lcm a 0 = 0 /-- Normalized GCD monoid: a `CancelCommMonoidWithZero` with normalization and `gcd` (greatest common divisor) and `lcm` (least common multiple) operations. In this setting `gcd` and `lcm` form a bounded lattice on the associated elements where `gcd` is the infimum, `lcm` is the supremum, `1` is bottom, and `0` is top. The type class focuses on `gcd` and we derive the corresponding `lcm` facts from `gcd`. -/ class NormalizedGCDMonoid (α : Type*) [CancelCommMonoidWithZero α] extends NormalizationMonoid α, GCDMonoid α where /-- The GCD is normalized to itself. -/ normalize_gcd : ∀ a b, normalize (gcd a b) = gcd a b /-- The LCM is normalized to itself. -/ normalize_lcm : ∀ a b, normalize (lcm a b) = lcm a b export GCDMonoid (gcd lcm gcd_dvd_left gcd_dvd_right dvd_gcd lcm_zero_left lcm_zero_right) attribute [simp] lcm_zero_left lcm_zero_right section GCDMonoid variable [CancelCommMonoidWithZero α] instance [NormalizationMonoid α] : Nonempty (NormalizationMonoid α) := ⟨‹_›⟩ instance [GCDMonoid α] : Nonempty (GCDMonoid α) := ⟨‹_›⟩ instance [NormalizedGCDMonoid α] : Nonempty (NormalizedGCDMonoid α) := ⟨‹_›⟩ instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (NormalizationMonoid α) := h.elim fun _ ↦ inferInstance instance [h : Nonempty (NormalizedGCDMonoid α)] : Nonempty (GCDMonoid α) := h.elim fun _ ↦ inferInstance theorem gcd_isUnit_iff_isRelPrime [GCDMonoid α] {a b : α} : IsUnit (gcd a b) ↔ IsRelPrime a b := ⟨fun h _ ha hb ↦ isUnit_of_dvd_unit (dvd_gcd ha hb) h, (· (gcd_dvd_left a b) (gcd_dvd_right a b))⟩ @[simp] theorem normalize_gcd [NormalizedGCDMonoid α] : ∀ a b : α, normalize (gcd a b) = gcd a b := NormalizedGCDMonoid.normalize_gcd theorem gcd_mul_lcm [GCDMonoid α] : ∀ a b : α, Associated (gcd a b * lcm a b) (a * b) := GCDMonoid.gcd_mul_lcm section GCD theorem dvd_gcd_iff [GCDMonoid α] (a b c : α) : a ∣ gcd b c ↔ a ∣ b ∧ a ∣ c := Iff.intro (fun h => ⟨h.trans (gcd_dvd_left _ _), h.trans (gcd_dvd_right _ _)⟩) fun ⟨hab, hac⟩ => dvd_gcd hab hac theorem gcd_comm [NormalizedGCDMonoid α] (a b : α) : gcd a b = gcd b a := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) theorem gcd_comm' [GCDMonoid α] (a b : α) : Associated (gcd a b) (gcd b a) := associated_of_dvd_dvd (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) (dvd_gcd (gcd_dvd_right _ _) (gcd_dvd_left _ _)) theorem gcd_assoc [NormalizedGCDMonoid α] (m n k : α) : gcd (gcd m n) k = gcd m (gcd n k) := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) theorem gcd_assoc' [GCDMonoid α] (m n k : α) : Associated (gcd (gcd m n) k) (gcd m (gcd n k)) := associated_of_dvd_dvd (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_left m n)) (dvd_gcd ((gcd_dvd_left (gcd m n) k).trans (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_left n k))) ((gcd_dvd_right m (gcd n k)).trans (gcd_dvd_right n k))) instance [NormalizedGCDMonoid α] : Std.Commutative (α := α) gcd where comm := gcd_comm instance [NormalizedGCDMonoid α] : Std.Associative (α := α) gcd where assoc := gcd_assoc theorem gcd_eq_normalize [NormalizedGCDMonoid α] {a b c : α} (habc : gcd a b ∣ c) (hcab : c ∣ gcd a b) : gcd a b = normalize c := normalize_gcd a b ▸ normalize_eq_normalize habc hcab @[simp] theorem gcd_zero_left [NormalizedGCDMonoid α] (a : α) : gcd 0 a = normalize a := gcd_eq_normalize (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) theorem gcd_zero_left' [GCDMonoid α] (a : α) : Associated (gcd 0 a) a := associated_of_dvd_dvd (gcd_dvd_right 0 a) (dvd_gcd (dvd_zero _) (dvd_refl a)) @[simp] theorem gcd_zero_right [NormalizedGCDMonoid α] (a : α) : gcd a 0 = normalize a := gcd_eq_normalize (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) theorem gcd_zero_right' [GCDMonoid α] (a : α) : Associated (gcd a 0) a := associated_of_dvd_dvd (gcd_dvd_left a 0) (dvd_gcd (dvd_refl a) (dvd_zero _)) @[simp] theorem gcd_eq_zero_iff [GCDMonoid α] (a b : α) : gcd a b = 0 ↔ a = 0 ∧ b = 0 := Iff.intro (fun h => by let ⟨ca, ha⟩ := gcd_dvd_left a b let ⟨cb, hb⟩ := gcd_dvd_right a b rw [h, zero_mul] at ha hb exact ⟨ha, hb⟩) fun ⟨ha, hb⟩ => by rw [ha, hb, ← zero_dvd_iff] apply dvd_gcd <;> rfl theorem gcd_ne_zero_of_left [GCDMonoid α] {a b : α} (ha : a ≠ 0) : gcd a b ≠ 0 := by simp_all theorem gcd_ne_zero_of_right [GCDMonoid α] {a b : α} (hb : b ≠ 0) : gcd a b ≠ 0 := by simp_all @[simp] theorem gcd_one_left [NormalizedGCDMonoid α] (a : α) : gcd 1 a = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_left _ _) (one_dvd _) @[simp] theorem isUnit_gcd_one_left [GCDMonoid α] (a : α) : IsUnit (gcd 1 a) := isUnit_of_dvd_one (gcd_dvd_left _ _) theorem gcd_one_left' [GCDMonoid α] (a : α) : Associated (gcd 1 a) 1 := by simp @[simp] theorem gcd_one_right [NormalizedGCDMonoid α] (a : α) : gcd a 1 = 1 := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) normalize_one (gcd_dvd_right _ _) (one_dvd _) @[simp] theorem isUnit_gcd_one_right [GCDMonoid α] (a : α) : IsUnit (gcd a 1) := isUnit_of_dvd_one (gcd_dvd_right _ _) theorem gcd_one_right' [GCDMonoid α] (a : α) : Associated (gcd a 1) 1 := by simp theorem gcd_dvd_gcd [GCDMonoid α] {a b c d : α} (hab : a ∣ b) (hcd : c ∣ d) : gcd a c ∣ gcd b d := dvd_gcd ((gcd_dvd_left _ _).trans hab) ((gcd_dvd_right _ _).trans hcd) protected theorem Associated.gcd [GCDMonoid α] {a₁ a₂ b₁ b₂ : α} (ha : Associated a₁ a₂) (hb : Associated b₁ b₂) : Associated (gcd a₁ b₁) (gcd a₂ b₂) := associated_of_dvd_dvd (gcd_dvd_gcd ha.dvd hb.dvd) (gcd_dvd_gcd ha.dvd' hb.dvd') @[simp] theorem gcd_same [NormalizedGCDMonoid α] (a : α) : gcd a a = normalize a := gcd_eq_normalize (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) (dvd_refl a)) @[simp] theorem gcd_mul_left [NormalizedGCDMonoid α] (a b c : α) : gcd (a * b) (a * c) = normalize a * gcd b c := (by_cases (by rintro rfl; simp only [zero_mul, gcd_zero_left, normalize_zero])) fun ha : a ≠ 0 => suffices gcd (a * b) (a * c) = normalize (a * gcd b c) by simpa let ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) gcd_eq_normalize (eq.symm ▸ mul_dvd_mul_left a (show d ∣ gcd b c from dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _))) (dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _)) theorem gcd_mul_left' [GCDMonoid α] (a b c : α) : Associated (gcd (a * b) (a * c)) (a * gcd b c) := by obtain rfl | ha := eq_or_ne a 0 · simp only [zero_mul, gcd_zero_left'] obtain ⟨d, eq⟩ := dvd_gcd (dvd_mul_right a b) (dvd_mul_right a c) apply associated_of_dvd_dvd · rw [eq] apply mul_dvd_mul_left exact dvd_gcd ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_left _ _) ((mul_dvd_mul_iff_left ha).1 <| eq ▸ gcd_dvd_right _ _) · exact dvd_gcd (mul_dvd_mul_left a <| gcd_dvd_left _ _) (mul_dvd_mul_left a <| gcd_dvd_right _ _) @[simp] theorem gcd_mul_right [NormalizedGCDMonoid α] (a b c : α) : gcd (b * a) (c * a) = gcd b c * normalize a := by simp only [mul_comm, gcd_mul_left] @[simp] theorem gcd_mul_right' [GCDMonoid α] (a b c : α) : Associated (gcd (b * a) (c * a)) (gcd b c * a) := by simp only [mul_comm, gcd_mul_left'] theorem gcd_eq_left_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize a = a) : gcd a b = a ↔ a ∣ b := (Iff.intro fun eq => eq ▸ gcd_dvd_right _ _) fun hab => dvd_antisymm_of_normalize_eq (normalize_gcd _ _) h (gcd_dvd_left _ _) (dvd_gcd (dvd_refl a) hab) theorem gcd_eq_right_iff [NormalizedGCDMonoid α] (a b : α) (h : normalize b = b) : gcd a b = b ↔ b ∣ a := by simpa only [gcd_comm a b] using gcd_eq_left_iff b a h theorem gcd_dvd_gcd_mul_left [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (k * m) n := gcd_dvd_gcd (dvd_mul_left _ _) dvd_rfl theorem gcd_dvd_gcd_mul_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd (m * k) n := gcd_dvd_gcd (dvd_mul_right _ _) dvd_rfl theorem gcd_dvd_gcd_mul_left_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (k * n) := gcd_dvd_gcd dvd_rfl (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right_right [GCDMonoid α] (m n k : α) : gcd m n ∣ gcd m (n * k) := gcd_dvd_gcd dvd_rfl (dvd_mul_right _ _) theorem Associated.gcd_eq_left [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : gcd m k = gcd n k := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd h.dvd dvd_rfl) (gcd_dvd_gcd h.symm.dvd dvd_rfl) theorem Associated.gcd_eq_right [NormalizedGCDMonoid α] {m n : α} (h : Associated m n) (k : α) : gcd k m = gcd k n := dvd_antisymm_of_normalize_eq (normalize_gcd _ _) (normalize_gcd _ _) (gcd_dvd_gcd dvd_rfl h.dvd) (gcd_dvd_gcd dvd_rfl h.symm.dvd) theorem dvd_gcd_mul_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ gcd k m * n := (dvd_gcd (dvd_mul_right _ n) H).trans (gcd_mul_right' n k m).dvd theorem dvd_gcd_mul_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ gcd k m * n ↔ k ∣ m * n := ⟨fun h => h.trans (mul_dvd_mul (gcd_dvd_right k m) dvd_rfl), dvd_gcd_mul_of_dvd_mul⟩ theorem dvd_mul_gcd_of_dvd_mul [GCDMonoid α] {m n k : α} (H : k ∣ m * n) : k ∣ m * gcd k n := by rw [mul_comm] at H ⊢ exact dvd_gcd_mul_of_dvd_mul H theorem dvd_mul_gcd_iff_dvd_mul [GCDMonoid α] {m n k : α} : k ∣ m * gcd k n ↔ k ∣ m * n := ⟨fun h => h.trans (mul_dvd_mul dvd_rfl (gcd_dvd_right k n)), dvd_mul_gcd_of_dvd_mul⟩ /-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. Note: In general, this representation is highly non-unique. See `Nat.dvdProdDvdOfDvdProd` for a constructive version on `ℕ`. -/ instance [h : Nonempty (GCDMonoid α)] : DecompositionMonoid α where primal k m n H := by cases h by_cases h0 : gcd k m = 0 · rw [gcd_eq_zero_iff] at h0 rcases h0 with ⟨rfl, rfl⟩ exact ⟨0, n, dvd_refl 0, dvd_refl n, by simp⟩ · obtain ⟨a, ha⟩ := gcd_dvd_left k m refine ⟨gcd k m, a, gcd_dvd_right _ _, ?_, ha⟩ rw [← mul_dvd_mul_iff_left h0, ← ha] exact dvd_gcd_mul_of_dvd_mul H theorem gcd_mul_dvd_mul_gcd [GCDMonoid α] (k m n : α) : gcd k (m * n) ∣ gcd k m * gcd k n := by obtain ⟨m', n', hm', hn', h⟩ := exists_dvd_and_dvd_of_dvd_mul (gcd_dvd_right k (m * n)) replace h : gcd k (m * n) = m' * n' := h rw [h] have hm'n' : m' * n' ∣ k := h ▸ gcd_dvd_left _ _ apply mul_dvd_mul · have hm'k : m' ∣ k := (dvd_mul_right m' n').trans hm'n' exact dvd_gcd hm'k hm' · have hn'k : n' ∣ k := (dvd_mul_left n' m').trans hm'n' exact dvd_gcd hn'k hn'
Mathlib/Algebra/GCDMonoid/Basic.lean
499
500
theorem gcd_pow_right_dvd_pow_gcd [GCDMonoid α] {a b : α} {k : ℕ} : gcd a (b ^ k) ∣ gcd a b ^ k := by
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Group.Action import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Int.ModEq import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Index import Mathlib.NumberTheory.Divisors import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ assert_not_exists Field open Function Fintype Nat Pointwise Subgroup Submonoid open scoped Finset variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos /-- 1 is of finite order in any monoid. -/ @[to_additive (attr := simp) "0 is of finite order in any additive monoid."] theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ @[to_additive] lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ @[to_additive] lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by rw [isOfFinOrder_iff_pow_eq_one] at * rcases h with ⟨m, hm, ha⟩ exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩ @[to_additive (attr := simp)] lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by rcases Decidable.eq_or_ne n 0 with rfl | hn · simp · exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨n, n_gt_0, eq'⟩ exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩ /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 · rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 · exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ /-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] · exact Nat.minFac_dvd a · rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e.toMonoidHom e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y @[to_additive] theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive unit with inverse `(addOrderOf x - 1) • x`. "] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ @[to_additive] lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≤ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x ≠ 1 := by rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one] /-- The backward direction of `orderOf_eq_prime_iff`. -/ @[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := orderOf_eq_prime_iff.mpr ⟨hg, hg1⟩ @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ end PPrime /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`"] noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivPowers hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : ℕ) : (finEquivPowers hx).symm ⟨x ^ n, _, rfl⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] variable {x n} (hx : IsOfFinOrder x) include hx @[to_additive] theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq] exact ⟨fun h ↦ Nat.ModEq.add_left _ h, fun h ↦ Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive] lemma IsOfFinOrder.pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := hx.pow_eq_pow_iff_modEq end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive]
Mathlib/GroupTheory/OrderOfElement.lean
536
538
theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by
rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Data.Set.Subsingleton import Mathlib.Order.Interval.Set.Defs /-! # Intervals In any preorder, we define intervals (which on each side can be either infinite, open or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. The definitions can be found in `Mathlib.Order.Interval.Set.Defs`. This file contains basic facts on inclusion of and set operations on intervals (where the precise statements depend on the order's properties; statements requiring `LinearOrder` are in `Mathlib.Order.Interval.Set.LinearOrder`). TODO: This is just the beginning; a lot of rules are missing -/ assert_not_exists RelIso open Function open OrderDual (toDual ofDual) variable {α : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] theorem left_mem_Ici : a ∈ Ici a := by simp theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] theorem right_mem_Iic : a ∈ Iic a := by simp @[simp] theorem Ici_toDual : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl @[deprecated (since := "2025-03-20")] alias dual_Ici := Ici_toDual @[simp] theorem Iic_toDual : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl @[deprecated (since := "2025-03-20")] alias dual_Iic := Iic_toDual @[simp] theorem Ioi_toDual : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl @[deprecated (since := "2025-03-20")] alias dual_Ioi := Ioi_toDual @[simp] theorem Iio_toDual : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl @[deprecated (since := "2025-03-20")] alias dual_Iio := Iio_toDual @[simp] theorem Icc_toDual : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Icc := Icc_toDual @[simp] theorem Ioc_toDual : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ioc := Ioc_toDual @[simp] theorem Ico_toDual : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ico := Ico_toDual @[simp] theorem Ioo_toDual : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ioo := Ioo_toDual @[simp] theorem Ici_ofDual {x : αᵒᵈ} : Ici (ofDual x) = toDual ⁻¹' Iic x := rfl @[simp] theorem Iic_ofDual {x : αᵒᵈ} : Iic (ofDual x) = toDual ⁻¹' Ici x := rfl @[simp] theorem Ioi_ofDual {x : αᵒᵈ} : Ioi (ofDual x) = toDual ⁻¹' Iio x := rfl @[simp] theorem Iio_ofDual {x : αᵒᵈ} : Iio (ofDual x) = toDual ⁻¹' Ioi x := rfl @[simp] theorem Icc_ofDual {x y : αᵒᵈ} : Icc (ofDual y) (ofDual x) = toDual ⁻¹' Icc x y := Set.ext fun _ => and_comm @[simp] theorem Ico_ofDual {x y : αᵒᵈ} : Ico (ofDual y) (ofDual x) = toDual ⁻¹' Ioc x y := Set.ext fun _ => and_comm @[simp] theorem Ioc_ofDual {x y : αᵒᵈ} : Ioc (ofDual y) (ofDual x) = toDual ⁻¹' Ico x y := Set.ext fun _ => and_comm @[simp] theorem Ioo_ofDual {x y : αᵒᵈ} : Ioo (ofDual y) (ofDual x) = toDual ⁻¹' Ioo x y := Set.ext fun _ => and_comm @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a where mp h := by obtain ⟨ab, c, cb, ac⟩ := ssubset_iff_exists.mp h exact lt_of_le_not_le (Ici_subset_Ici.mp ab) (fun h' ↦ ac (h'.trans cb)) mpr h := (ssubset_iff_of_subset (Ici_subset_Ici.mpr h.le)).mpr ⟨b, right_mem_Iic, fun h' => h.not_le h'⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_ssubset_Ici_of_le⟩ := Ici_ssubset_Ici @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := @Ici_ssubset_Ici αᵒᵈ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_ssubset_Iic_of_le⟩ := Iic_ssubset_Iic @[simp] theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ @[simp] theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx /-- If `a < b`, then `(b, +∞) ⊂ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_ssubset_Ioi_iff`. -/ @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := (ssubset_iff_of_subset (Ioi_subset_Ioi h.le)).mpr ⟨b, h, lt_irrefl b⟩ /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h /-- If `a < b`, then `(-∞, a) ⊂ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_ssubset_Iio_iff`. -/ @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := (ssubset_iff_of_subset (Iio_subset_Iio h.le)).mpr ⟨a, h, lt_irrefl a⟩ /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h @[simp] theorem Ioi_eq_empty_iff : Ioi a = ∅ ↔ IsMax a := by simp only [isMax_iff_forall_not_lt, eq_empty_iff_forall_not_mem, mem_Ioi] @[simp] theorem Iio_eq_empty_iff : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty_iff (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMax.Ioi_eq⟩ := Ioi_eq_empty_iff @[simp] alias ⟨_, _root_.IsMin.Iio_eq⟩ := Iio_eq_empty_iff @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb section matched_intervals @[simp] theorem Icc_eq_Ioc_same_iff : Icc a b = Ioc a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Icc_eq_empty h, Ioc_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ico_same_iff : Icc a b = Ico a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ico_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ioo_same_iff : Icc a b = Ioo a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ioo_eq_empty (mt le_of_lt h)] @[simp] theorem Ioc_eq_Ico_same_iff : Ioc a b = Ico a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioc_eq_empty h, Ico_eq_empty h] @[simp] theorem Ioo_eq_Ioc_same_iff : Ioo a b = Ioc a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Ioo_eq_empty h, Ioc_eq_empty h] @[simp] theorem Ioo_eq_Ico_same_iff : Ioo a b = Ico a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioo_eq_empty h, Ico_eq_empty h] -- Mirrored versions of the above for `simp`. @[simp] theorem Ioc_eq_Icc_same_iff : Ioc a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ioc_same_iff @[simp] theorem Ico_eq_Icc_same_iff : Ico a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ico_same_iff @[simp] theorem Ioo_eq_Icc_same_iff : Ioo a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ioo_same_iff @[simp] theorem Ico_eq_Ioc_same_iff : Ico a b = Ioc a b ↔ ¬a < b := eq_comm.trans Ioc_eq_Ico_same_iff @[simp] theorem Ioc_eq_Ioo_same_iff : Ioc a b = Ioo a b ↔ ¬a < b := eq_comm.trans Ioo_eq_Ioc_same_iff @[simp] theorem Ico_eq_Ioo_same_iff : Ico a b = Ioo a b ↔ ¬a < b := eq_comm.trans Ioo_eq_Ico_same_iff end matched_intervals end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h ▸ left_mem_Icc.2 hab, eq_of_mem_singleton <| h ▸ right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] @[simp] theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)] @[simp] theorem Icc_diff_Ico_same (h : a ≤ b) : Icc a b \ Ico a b = {b} := by rw [← Icc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Icc.2 h)] @[simp] theorem Icc_diff_Ioc_same (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by rw [← Icc_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Icc.2 h)] @[simp] theorem Icc_diff_Ioo_same (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by rw [← Icc_diff_both, diff_diff_cancel_left] simp [insert_subset_iff, h] @[simp] theorem Ici_diff_Ioi_same : Ici a \ Ioi a = {a} := by rw [← Ici_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 left_mem_Ici)] @[simp] theorem Iic_diff_Iio_same : Iic a \ Iio a = {a} := by rw [← Iic_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 right_mem_Iic)] theorem Ioi_union_left : Ioi a ∪ {a} = Ici a := ext fun x => by simp [eq_comm, le_iff_eq_or_lt] theorem Iio_union_right : Iio a ∪ {a} = Iic a := ext fun _ => le_iff_lt_or_eq.symm theorem Ioo_union_left (hab : a < b) : Ioo a b ∪ {a} = Ico a b := by rw [← Ico_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Ico.2 hab)] theorem Ioo_union_right (hab : a < b) : Ioo a b ∪ {b} = Ioc a b := by simpa only [Ioo_toDual, Ico_toDual] using Ioo_union_left hab.dual theorem Ioo_union_both (h : a ≤ b) : Ioo a b ∪ {a, b} = Icc a b := by have : (Icc a b \ {a, b}) ∪ {a, b} = Icc a b := diff_union_of_subset fun | x, .inl rfl => left_mem_Icc.mpr h | x, .inr rfl => right_mem_Icc.mpr h rw [← this, Icc_diff_both] theorem Ioc_union_left (hab : a ≤ b) : Ioc a b ∪ {a} = Icc a b := by rw [← Icc_diff_left, diff_union_self, union_eq_self_of_subset_right (singleton_subset_iff.2 <| left_mem_Icc.2 hab)] theorem Ico_union_right (hab : a ≤ b) : Ico a b ∪ {b} = Icc a b := by simpa only [Ioc_toDual, Icc_toDual] using Ioc_union_left hab.dual @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [insert_eq, union_comm, Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [insert_eq, union_comm, Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [insert_eq, union_comm, Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [insert_eq, union_comm, Ioo_union_right h] @[simp] theorem Iio_insert : insert a (Iio a) = Iic a := ext fun _ => le_iff_eq_or_lt.symm @[simp] theorem Ioi_insert : insert a (Ioi a) = Ici a := ext fun _ => (or_congr_left eq_comm).trans le_iff_eq_or_lt.symm theorem mem_Ici_Ioi_of_subset_of_subset {s : Set α} (ho : Ioi a ⊆ s) (hc : s ⊆ Ici a) : s ∈ ({Ici a, Ioi a} : Set (Set α)) := by_cases (fun h : a ∈ s => Or.inl <| Subset.antisymm hc <| by rw [← Ioi_union_left, union_subset_iff]; simp [*]) fun h => Or.inr <| Subset.antisymm (fun _ hx => lt_of_le_of_ne (hc hx) fun heq => h <| heq.symm ▸ hx) ho theorem mem_Iic_Iio_of_subset_of_subset {s : Set α} (ho : Iio a ⊆ s) (hc : s ⊆ Iic a) : s ∈ ({Iic a, Iio a} : Set (Set α)) := @mem_Ici_Ioi_of_subset_of_subset αᵒᵈ _ a s ho hc theorem mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset {s : Set α} (ho : Ioo a b ⊆ s) (hc : s ⊆ Icc a b) : s ∈ ({Icc a b, Ico a b, Ioc a b, Ioo a b} : Set (Set α)) := by classical by_cases ha : a ∈ s <;> by_cases hb : b ∈ s · refine Or.inl (Subset.antisymm hc ?_) rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha, ← Icc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_right] exact subset_diff_singleton hc hb · rwa [← Ico_diff_left, diff_singleton_subset_iff, insert_eq_of_mem ha] at ho · refine Or.inr <| Or.inr <| Or.inl <| Subset.antisymm ?_ ?_ · rw [← Icc_diff_left] exact subset_diff_singleton hc ha · rwa [← Ioc_diff_right, diff_singleton_subset_iff, insert_eq_of_mem hb] at ho · refine Or.inr <| Or.inr <| Or.inr <| Subset.antisymm ?_ ho rw [← Ico_diff_left, ← Icc_diff_right] apply_rules [subset_diff_singleton] theorem eq_left_or_mem_Ioo_of_mem_Ico {x : α} (hmem : x ∈ Ico a b) : x = a ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => ⟨h, hmem.2⟩ theorem eq_right_or_mem_Ioo_of_mem_Ioc {x : α} (hmem : x ∈ Ioc a b) : x = b ∨ x ∈ Ioo a b := hmem.2.eq_or_lt.imp_right <| And.intro hmem.1 theorem eq_endpoints_or_mem_Ioo_of_mem_Icc {x : α} (hmem : x ∈ Icc a b) : x = a ∨ x = b ∨ x ∈ Ioo a b := hmem.1.eq_or_gt.imp_right fun h => eq_right_or_mem_Ioo_of_mem_Ioc ⟨h, hmem.2⟩ theorem _root_.IsMax.Ici_eq (h : IsMax a) : Ici a = {a} := eq_singleton_iff_unique_mem.2 ⟨left_mem_Ici, fun _ => h.eq_of_ge⟩ theorem _root_.IsMin.Iic_eq (h : IsMin a) : Iic a = {a} := h.toDual.Ici_eq theorem Ici_injective : Injective (Ici : α → Set α) := fun _ _ => eq_of_forall_ge_iff ∘ Set.ext_iff.1 theorem Iic_injective : Injective (Iic : α → Set α) := fun _ _ => eq_of_forall_le_iff ∘ Set.ext_iff.1 theorem Ici_inj : Ici a = Ici b ↔ a = b := Ici_injective.eq_iff theorem Iic_inj : Iic a = Iic b ↔ a = b := Iic_injective.eq_iff @[simp] theorem Icc_inter_Icc_eq_singleton (hab : a ≤ b) (hbc : b ≤ c) : Icc a b ∩ Icc b c = {b} := by rw [← Ici_inter_Iic, ← Iic_inter_Ici, inter_inter_inter_comm, Iic_inter_Ici] simp [hab, hbc] lemma Icc_eq_Icc_iff {d : α} (h : a ≤ b) : Icc a b = Icc c d ↔ a = c ∧ b = d := by refine ⟨fun heq ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ have h' : c ≤ d := by by_contra contra; rw [Icc_eq_empty_iff.mpr contra, Icc_eq_empty_iff] at heq; contradiction simp only [Set.ext_iff, mem_Icc] at heq obtain ⟨-, h₁⟩ := (heq b).mp ⟨h, le_refl _⟩ obtain ⟨h₂, -⟩ := (heq a).mp ⟨le_refl _, h⟩ obtain ⟨h₃, -⟩ := (heq c).mpr ⟨le_refl _, h'⟩ obtain ⟨-, h₄⟩ := (heq d).mpr ⟨h', le_refl _⟩ exact ⟨le_antisymm h₃ h₂, le_antisymm h₁ h₄⟩ end PartialOrder section OrderTop @[simp] theorem Ici_top [PartialOrder α] [OrderTop α] : Ici (⊤ : α) = {⊤} := isMax_top.Ici_eq variable [Preorder α] [OrderTop α] {a : α} theorem Ioi_top : Ioi (⊤ : α) = ∅ := isMax_top.Ioi_eq @[simp] theorem Iic_top : Iic (⊤ : α) = univ := isTop_top.Iic_eq @[simp] theorem Icc_top : Icc a ⊤ = Ici a := by simp [← Ici_inter_Iic] @[simp] theorem Ioc_top : Ioc a ⊤ = Ioi a := by simp [← Ioi_inter_Iic] end OrderTop section OrderBot @[simp] theorem Iic_bot [PartialOrder α] [OrderBot α] : Iic (⊥ : α) = {⊥} := isMin_bot.Iic_eq variable [Preorder α] [OrderBot α] {a : α} theorem Iio_bot : Iio (⊥ : α) = ∅ := isMin_bot.Iio_eq @[simp] theorem Ici_bot : Ici (⊥ : α) = univ := isBot_bot.Ici_eq @[simp] theorem Icc_bot : Icc ⊥ a = Iic a := by simp [← Ici_inter_Iic] @[simp] theorem Ico_bot : Ico ⊥ a = Iio a := by simp [← Ici_inter_Iio] end OrderBot theorem Icc_bot_top [Preorder α] [BoundedOrder α] : Icc (⊥ : α) ⊤ = univ := by simp section Lattice section Inf variable [SemilatticeInf α] @[simp]
Mathlib/Order/Interval/Set/Basic.lean
907
908
theorem Iic_inter_Iic {a b : α} : Iic a ∩ Iic b = Iic (a ⊓ b) := by
ext x
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Infix import Mathlib.Data.Quot /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by simp @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | _ :: _, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero_iff] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))] simp [rotate] @[simp] theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate_iff.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _) @[simp] theorem nodup_rotate {l : List α} {n : ℕ} : Nodup (l.rotate n) ↔ Nodup l := (rotate_perm l n).nodup_iff @[simp] theorem rotate_eq_nil_iff {l : List α} {n : ℕ} : l.rotate n = [] ↔ l = [] := by induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · simp [rotate_cons_succ, hn] theorem nil_eq_rotate_iff {l : List α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by rw [eq_comm, rotate_eq_nil_iff, eq_comm] @[simp] theorem rotate_singleton (x : α) (n : ℕ) : [x].rotate n = [x] := rotate_replicate x 1 n theorem zipWith_rotate_distrib {β γ : Type*} (f : α → β → γ) (l : List α) (l' : List β) (n : ℕ) (h : l.length = l'.length) : (zipWith f l l').rotate n = zipWith f (l.rotate n) (l'.rotate n) := by rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, h, zipWith_append, ← drop_zipWith, ← take_zipWith, List.length_zipWith, h, min_self] rw [length_drop, length_drop, h] theorem zipWith_rotate_one {β : Type*} (f : α → α → β) (x y : α) (l : List α) : zipWith f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: zipWith f (y :: l) (l ++ [x]) := by simp theorem getElem?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n)[m]? = l[(m + n) % l.length]? := by rw [rotate_eq_drop_append_take_mod] rcases lt_or_le m (l.drop (n % l.length)).length with hm | hm · rw [getElem?_append_left hm, getElem?_drop, ← add_mod_mod] rw [length_drop, Nat.lt_sub_iff_add_lt] at hm rw [mod_eq_of_lt hm, Nat.add_comm] · have hlt : n % length l < length l := mod_lt _ (m.zero_le.trans_lt hml) rw [getElem?_append_right hm, getElem?_take_of_lt, length_drop] · congr 1 rw [length_drop] at hm have hm' := Nat.sub_le_iff_le_add'.1 hm have : n % length l + m - length l < length l := by rw [Nat.sub_lt_iff_lt_add hm'] exact Nat.add_lt_add hlt hml conv_rhs => rw [Nat.add_comm m, ← mod_add_mod, mod_eq_sub_mod hm', mod_eq_of_lt this] omega · rwa [Nat.sub_lt_iff_lt_add' hm, length_drop, Nat.sub_add_cancel hlt.le] theorem getElem_rotate (l : List α) (n : ℕ) (k : Nat) (h : k < (l.rotate n).length) : (l.rotate n)[k] = l[(k + n) % l.length]'(mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt h)) := by rw [← Option.some_inj, ← getElem?_eq_getElem, ← getElem?_eq_getElem, getElem?_rotate] exact h.trans_eq (length_rotate _ _) set_option linter.deprecated false in @[deprecated getElem?_rotate (since := "2025-02-14")] theorem get?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n).get? m = l.get? ((m + n) % l.length) := by simp only [get?_eq_getElem?, length_rotate, hml, getElem?_eq_getElem, getElem_rotate] rw [← getElem?_eq_getElem] theorem get_rotate (l : List α) (n : ℕ) (k : Fin (l.rotate n).length) : (l.rotate n).get k = l.get ⟨(k + n) % l.length, mod_lt _ (length_rotate l n ▸ k.pos)⟩ := by simp [getElem_rotate] theorem head?_rotate {l : List α} {n : ℕ} (h : n < l.length) : head? (l.rotate n) = l[n]? := by rw [head?_eq_getElem?, getElem?_rotate (n.zero_le.trans_lt h), Nat.zero_add, Nat.mod_eq_of_lt h] theorem get_rotate_one (l : List α) (k : Fin (l.rotate 1).length) : (l.rotate 1).get k = l.get ⟨(k + 1) % l.length, mod_lt _ (length_rotate l 1 ▸ k.pos)⟩ := get_rotate l 1 k /-- A version of `List.getElem_rotate` that represents `l[k]` in terms of `(List.rotate l n)[⋯]`, not vice versa. Can be used instead of rewriting `List.getElem_rotate` from right to left. -/ theorem getElem_eq_getElem_rotate (l : List α) (n : ℕ) (k : Nat) (hk : k < l.length) : l[k] = ((l.rotate n)[(l.length - n % l.length + k) % l.length]' ((Nat.mod_lt _ (k.zero_le.trans_lt hk)).trans_eq (length_rotate _ _).symm)) := by rw [getElem_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [hk, (mod_lt _ (k.zero_le.trans_lt hk)).le] /-- A version of `List.get_rotate` that represents `List.get l` in terms of `List.get (List.rotate l n)`, not vice versa. Can be used instead of rewriting `List.get_rotate` from right to left. -/ theorem get_eq_get_rotate (l : List α) (n : ℕ) (k : Fin l.length) : l.get k = (l.rotate n).get ⟨(l.length - n % l.length + k) % l.length, (Nat.mod_lt _ (k.1.zero_le.trans_lt k.2)).trans_eq (length_rotate _ _).symm⟩ := by rw [get_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [k.2, (mod_lt _ (k.1.zero_le.trans_lt k.2)).le] theorem rotate_eq_self_iff_eq_replicate [hα : Nonempty α] : ∀ {l : List α}, (∀ n, l.rotate n = l) ↔ ∃ a, l = replicate l.length a | [] => by simp | a :: l => ⟨fun h => ⟨a, ext_getElem length_replicate.symm fun n h₁ h₂ => by rw [getElem_replicate, ← Option.some_inj, ← getElem?_eq_getElem, ← head?_rotate h₁, h, head?_cons]⟩, fun ⟨b, hb⟩ n => by rw [hb, rotate_replicate]⟩ theorem rotate_one_eq_self_iff_eq_replicate [Nonempty α] {l : List α} : l.rotate 1 = l ↔ ∃ a : α, l = List.replicate l.length a := ⟨fun h => rotate_eq_self_iff_eq_replicate.mp fun n => Nat.rec l.rotate_zero (fun n hn => by rwa [Nat.succ_eq_add_one, ← l.rotate_rotate, hn]) n, fun h => rotate_eq_self_iff_eq_replicate.mpr h 1⟩ theorem rotate_injective (n : ℕ) : Function.Injective fun l : List α => l.rotate n := by rintro l l' (h : l.rotate n = l'.rotate n) have hle : l.length = l'.length := (l.length_rotate n).symm.trans (h.symm ▸ l'.length_rotate n) rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod] at h obtain ⟨hd, ht⟩ := append_inj h (by simp_all) rw [← take_append_drop _ l, ht, hd, take_append_drop] @[simp] theorem rotate_eq_rotate {l l' : List α} {n : ℕ} : l.rotate n = l'.rotate n ↔ l = l' := (rotate_injective n).eq_iff theorem rotate_eq_iff {l l' : List α} {n : ℕ} : l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length) := by rw [← @rotate_eq_rotate _ l _ n, rotate_rotate, ← rotate_mod l', add_mod] rcases l'.length.zero_le.eq_or_lt with hl | hl · rw [eq_nil_of_length_eq_zero hl.symm, rotate_nil] · rcases (Nat.zero_le (n % l'.length)).eq_or_lt with hn | hn · simp [← hn] · rw [mod_eq_of_lt (Nat.sub_lt hl hn), Nat.sub_add_cancel, mod_self, rotate_zero] exact (Nat.mod_lt _ hl).le @[simp] theorem rotate_eq_singleton_iff {l : List α} {n : ℕ} {x : α} : l.rotate n = [x] ↔ l = [x] := by rw [rotate_eq_iff, rotate_singleton] @[simp] theorem singleton_eq_rotate_iff {l : List α} {n : ℕ} {x : α} : [x] = l.rotate n ↔ [x] = l := by rw [eq_comm, rotate_eq_singleton_iff, eq_comm] theorem reverse_rotate (l : List α) (n : ℕ) : (l.rotate n).reverse = l.reverse.rotate (l.length - n % l.length) := by rw [← length_reverse, ← rotate_eq_iff] induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · rw [rotate_cons_succ, ← rotate_rotate, hn] simp theorem rotate_reverse (l : List α) (n : ℕ) : l.reverse.rotate n = (l.rotate (l.length - n % l.length)).reverse := by rw [← reverse_reverse l] simp_rw [reverse_rotate, reverse_reverse, rotate_eq_iff, rotate_rotate, length_rotate, length_reverse] rw [← length_reverse] let k := n % l.reverse.length rcases hk' : k with - | k' · simp_all! [k, length_reverse, ← rotate_rotate] · rcases l with - | ⟨x, l⟩ · simp · rw [Nat.mod_eq_of_lt, Nat.sub_add_cancel, rotate_length] · exact Nat.sub_le _ _ · exact Nat.sub_lt (by simp) (by simp_all! [k]) theorem map_rotate {β : Type*} (f : α → β) (l : List α) (n : ℕ) : map f (l.rotate n) = (map f l).rotate n := by induction' n with n hn IH generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · simp [hn] theorem Nodup.rotate_congr {l : List α} (hl : l.Nodup) (hn : l ≠ []) (i j : ℕ) (h : l.rotate i = l.rotate j) : i % l.length = j % l.length := by rw [← rotate_mod l i, ← rotate_mod l j] at h simpa only [head?_rotate, mod_lt, length_pos_of_ne_nil hn, getElem?_eq_getElem, Option.some_inj, hl.getElem_inj_iff, Fin.ext_iff] using congr_arg head? h theorem Nodup.rotate_congr_iff {l : List α} (hl : l.Nodup) {i j : ℕ} : l.rotate i = l.rotate j ↔ i % l.length = j % l.length ∨ l = [] := by rcases eq_or_ne l [] with rfl | hn · simp · simp only [hn, or_false] refine ⟨hl.rotate_congr hn _ _, fun h ↦ ?_⟩ rw [← rotate_mod, h, rotate_mod] theorem Nodup.rotate_eq_self_iff {l : List α} (hl : l.Nodup) {n : ℕ} : l.rotate n = l ↔ n % l.length = 0 ∨ l = [] := by rw [← zero_mod, ← hl.rotate_congr_iff, rotate_zero] section IsRotated variable (l l' : List α) /-- `IsRotated l₁ l₂` or `l₁ ~r l₂` asserts that `l₁` and `l₂` are cyclic permutations of each other. This is defined by claiming that `∃ n, l.rotate n = l'`. -/ def IsRotated : Prop := ∃ n, l.rotate n = l' @[inherit_doc List.IsRotated] -- This matches the precedence of the infix `~` for `List.Perm`, and of other relation infixes infixr:50 " ~r " => IsRotated variable {l l'} @[refl] theorem IsRotated.refl (l : List α) : l ~r l := ⟨0, by simp⟩ @[symm] theorem IsRotated.symm (h : l ~r l') : l' ~r l := by obtain ⟨n, rfl⟩ := h rcases l with - | ⟨hd, tl⟩ · exists 0 · use (hd :: tl).length * n - n rw [rotate_rotate, Nat.add_sub_cancel', rotate_length_mul] exact Nat.le_mul_of_pos_left _ (by simp) theorem isRotated_comm : l ~r l' ↔ l' ~r l := ⟨IsRotated.symm, IsRotated.symm⟩ @[simp] protected theorem IsRotated.forall (l : List α) (n : ℕ) : l.rotate n ~r l := IsRotated.symm ⟨n, rfl⟩ @[trans] theorem IsRotated.trans : ∀ {l l' l'' : List α}, l ~r l' → l' ~r l'' → l ~r l'' | _, _, _, ⟨n, rfl⟩, ⟨m, rfl⟩ => ⟨n + m, by rw [rotate_rotate]⟩ theorem IsRotated.eqv : Equivalence (@IsRotated α) := Equivalence.mk IsRotated.refl IsRotated.symm IsRotated.trans /-- The relation `List.IsRotated l l'` forms a `Setoid` of cycles. -/ def IsRotated.setoid (α : Type*) : Setoid (List α) where r := IsRotated iseqv := IsRotated.eqv theorem IsRotated.perm (h : l ~r l') : l ~ l' := Exists.elim h fun _ hl => hl ▸ (rotate_perm _ _).symm theorem IsRotated.nodup_iff (h : l ~r l') : Nodup l ↔ Nodup l' := h.perm.nodup_iff theorem IsRotated.mem_iff (h : l ~r l') {a : α} : a ∈ l ↔ a ∈ l' := h.perm.mem_iff @[simp] theorem isRotated_nil_iff : l ~r [] ↔ l = [] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ @[simp] theorem isRotated_nil_iff' : [] ~r l ↔ [] = l := by rw [isRotated_comm, isRotated_nil_iff, eq_comm] @[simp] theorem isRotated_singleton_iff {x : α} : l ~r [x] ↔ l = [x] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ @[simp] theorem isRotated_singleton_iff' {x : α} : [x] ~r l ↔ [x] = l := by rw [isRotated_comm, isRotated_singleton_iff, eq_comm] theorem isRotated_concat (hd : α) (tl : List α) : (tl ++ [hd]) ~r (hd :: tl) := IsRotated.symm ⟨1, by simp⟩ theorem isRotated_append : (l ++ l') ~r (l' ++ l) := ⟨l.length, by simp⟩ theorem IsRotated.reverse (h : l ~r l') : l.reverse ~r l'.reverse := by obtain ⟨n, rfl⟩ := h exact ⟨_, (reverse_rotate _ _).symm⟩
Mathlib/Data/List/Rotate.lean
433
434
theorem isRotated_reverse_comm_iff : l.reverse ~r l' ↔ l ~r l'.reverse := by
constructor <;>
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Eric Wieser -/ import Mathlib.Data.Finset.Sym import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Quadratic maps This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`. An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such that: * `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x` * `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`, `QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`: the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear. This notion generalizes to commutative semirings using the approach in [izhakian2016][] which requires that there be a (possibly non-unique) companion bilinear map `B` such that `∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`. To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`. Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`, and composition with linear maps `f`, `Q.comp f x = Q (f x)`. ## Main definitions * `QuadraticMap.ofPolar`: a more familiar constructor that works on rings * `QuadraticMap.associated`: associated bilinear map * `QuadraticMap.PosDef`: positive definite quadratic maps * `QuadraticMap.Anisotropic`: anisotropic quadratic maps * `QuadraticMap.discr`: discriminant of a quadratic map * `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map. ## Main statements * `QuadraticMap.associated_left_inverse`, * `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has an inverse, there is a correspondence between quadratic maps and symmetric bilinear forms * `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with respect to any nondegenerate, symmetric bilinear map `B`. ## Notation In this file, the variable `R` is used when a `CommSemiring` structure is available. The variable `S` is used when `R` itself has a `•` action. ## Implementation notes While the definition and many results make sense if we drop commutativity assumptions, the correct definition of a quadratic maps in the noncommutative setting would require substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some suitable conjugation $r^*$. The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867) has some further discussion. ## References * https://en.wikipedia.org/wiki/Quadratic_form * https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms ## Tags quadratic map, homogeneous polynomial, quadratic polynomial -/ universe u v w variable {S T : Type*} variable {R : Type*} {M N P A : Type*} open LinearMap (BilinMap BilinForm) section Polar variable [CommRing R] [AddCommGroup M] [AddCommGroup N] namespace QuadraticMap /-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`. Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization -/ def polar (f : M → N) (x y : M) := f (x + y) - f x - f y protected theorem map_add (f : M → N) (x y : M) : f (x + y) = f x + f y + polar f x y := by rw [polar] abel
Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
103
104
theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
/- 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 -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Analysis.NormedSpace.Real import Mathlib.Data.Rat.Cast.CharZero /-! # Real logarithm In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and `log (-x) = log x`. We prove some basic properties of this function and show that it is continuous. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {x y : ℝ} /-- The real logarithm function, equal to the inverse of the exponential for `x > 0`, to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to `(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and the derivative of `log` is `1/x` away from `0`. -/ @[pp_nodot] noncomputable def log (x : ℝ) : ℝ := if hx : x = 0 then 0 else expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ theorem log_of_ne_zero (hx : x ≠ 0) : log x = expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ := dif_neg hx theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟨x, hx⟩ := by rw [log_of_ne_zero hx.ne'] congr exact abs_of_pos hx theorem exp_log_eq_abs (hx : x ≠ 0) : exp (log x) = |x| := by rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk] theorem exp_log (hx : 0 < x) : exp (log x) = x := by rw [exp_log_eq_abs hx.ne'] exact abs_of_pos hx theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by rw [exp_log_eq_abs (ne_of_lt hx)] exact abs_of_neg hx theorem le_exp_log (x : ℝ) : x ≤ exp (log x) := by by_cases h_zero : x = 0 · rw [h_zero, log, dif_pos rfl, exp_zero] exact zero_le_one · rw [exp_log_eq_abs h_zero] exact le_abs_self _ @[simp] theorem log_exp (x : ℝ) : log (exp x) = x := exp_injective <| exp_log (exp_pos x) theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≤ exp x := by by_cases hx0 : x ≤ 0 · apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x) · have h := add_one_le_exp (log x) rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h theorem two_mul_le_exp {x : ℝ} : 2 * x ≤ exp x := by by_cases hx0 : x < 0 · exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le) (exp_nonneg x) · apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp have := Real.add_one_le_exp 1 rwa [one_add_one_eq_two] at this theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟨exp x, exp_pos x, log_exp x⟩ theorem log_surjective : Surjective log := fun x => ⟨exp x, log_exp x⟩ @[simp] theorem range_log : range log = univ := log_surjective.range_eq @[simp] theorem log_zero : log 0 = 0 := dif_pos rfl @[simp] theorem log_one : log 1 = 0 := exp_injective <| by rw [exp_log zero_lt_one, exp_zero] /-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/ @[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem log_abs (x : ℝ) : log |x| = log x := by by_cases h : x = 0 · simp [h] · rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] @[simp] theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg] theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by rw [sinh_eq, exp_neg, exp_log hx] theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by rw [cosh_eq, exp_neg, exp_log hx] theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ => ⟨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩ theorem log_mul (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y := exp_injective <| by rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul] theorem log_div (hx : x ≠ 0) (hy : y ≠ 0) : log (x / y) = log x - log y := exp_injective <| by rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div] @[simp] theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by by_cases hx : x = 0; · simp [hx] rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv] theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≤ log y ↔ x ≤ y := by rw [← exp_le_exp, exp_log h, exp_log h₁] @[gcongr, bound] lemma log_le_log (hx : 0 < x) (hxy : x ≤ y) : log x ≤ log y := (log_le_log_iff hx (hx.trans_le hxy)).2 hxy @[gcongr, bound] theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by rw [← exp_lt_exp, exp_log hx, exp_log hy] theorem log_le_iff_le_exp (hx : 0 < x) : log x ≤ y ↔ x ≤ exp y := by rw [← exp_le_exp, exp_log hx] theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx] theorem le_log_iff_exp_le (hy : 0 < y) : x ≤ log y ↔ exp x ≤ y := by rw [← exp_le_exp, exp_log hy] theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy] theorem log_pos_iff (hx : 0 ≤ x) : 0 < log x ↔ 1 < x := by rcases hx.eq_or_lt with (rfl | hx) · simp [le_refl, zero_le_one] rw [← log_one] exact log_lt_log_iff zero_lt_one hx @[bound] theorem log_pos (hx : 1 < x) : 0 < log x := (log_pos_iff (lt_trans zero_lt_one hx).le).2 hx theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by rw [← neg_neg x, log_neg_eq_log] have : 1 < -x := by linarith exact log_pos this theorem log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 := by rw [← log_one] exact log_lt_log_iff h zero_lt_one @[bound]
Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
180
183
theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1 theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Sébastien Gouëzel -/ import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic /-! # Relationship between the Haar and Lebesgue measures We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in `MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`. We deduce basic properties of any Haar measure on a finite dimensional real vector space: * `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the absolute value of its determinant. * `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the determinant of `f`. * `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the measure of `s` multiplied by the absolute value of the determinant of `f`. * `addHaar_submodule` : a strict submodule has measure `0`. * `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`. * `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`. * `addHaar_sphere`: spheres have zero measure. This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`. This measure is called `AlternatingMap.measure`. Its main property is `ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned by vectors `v₁, ..., vₙ` is given by `|ω v|`. We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in `tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for small `r`, see `eventually_nonempty_inter_smul_of_density_one`. Statements on integrals of functions with respect to an additive Haar measure can be found in `MeasureTheory.Measure.Haar.NormedSpace`. -/ assert_not_exists MeasureTheory.integral open TopologicalSpace Set Filter Metric Bornology open scoped ENNReal Pointwise Topology NNReal /-- The interval `[0,1]` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where carrier := Icc 0 1 isCompact' := isCompact_Icc interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one] universe u /-- The set `[0,1]^ι` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] : PositiveCompacts (ι → ℝ) where carrier := pi univ fun _ => Icc 0 1 isCompact' := isCompact_univ_pi fun _ => isCompact_Icc interior_nonempty' := by simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo, imp_true_iff, zero_lt_one] /-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/ theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] : (Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι := SetLike.coe_injective <| by refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm) · classical convert parallelepiped_single (ι := ι) 1 · exact zero_le_one /-- A parallelepiped can be expressed on the standard basis. -/ theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ι ℝ E) : b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by classical rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map] congr with x simp [Pi.single_apply] open MeasureTheory MeasureTheory.Measure theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E] [BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F] (b : Basis ι ℝ E) (f : E ≃L[ℝ] F) : map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by have : IsAddHaarMeasure (map f b.addHaar) := AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable (PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map] erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self] namespace MeasureTheory open Measure TopologicalSpace.PositiveCompacts Module /-! ### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`. -/ /-- The Haar measure equals the Lebesgue measure on `ℝ`. -/ theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01] /-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/ theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] : addHaarMeasure (piIcc01 ι) = volume := by convert (addHaarMeasure_unique volume (piIcc01 ι)).symm simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk, Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero] theorem isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] : IsAddHaarMeasure (volume : Measure (ι → ℝ)) := inferInstance namespace Measure /-! ### Strict subspaces have zero measure -/ open scoped Function -- required for scoped `on` notation /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/ theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by by_contra h apply lt_irrefl ∞ calc ∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm _ = ∑' n : ℕ, μ ({u n} + s) := by congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add] _ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's _ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range] _ < ∞ := (hu.add sb).measure_lt_top /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. -/ theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by apply le_antisymm _ (zero_le _) calc μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by conv_lhs => rw [← iUnion_inter_closedBall_nat s 0] exact measure_iUnion_le _ _ = 0 := by simp only [H, tsum_zero] intro R apply addHaar_eq_zero_of_disjoint_translates_aux μ u (isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall) refine pairwise_disjoint_mono hs fun n => ?_ exact add_subset_add Subset.rfl inter_subset_left /-- A strict vector subspace has measure zero. -/ theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩ have A : IsBounded (range fun n : ℕ => c ^ n • x) := have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) := (tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x isBounded_range_of_tendsto _ this apply addHaar_eq_zero_of_disjoint_translates μ _ A _ (Submodule.closed_of_finiteDimensional s).measurableSet intro m n hmn simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage, SetLike.mem_coe] intro y hym hyn have A : (c ^ n - c ^ m) • x ∈ s := by convert s.sub_mem hym hyn using 1 simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub] have H : c ^ n - c ^ m ≠ 0 := by simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti₀ cpos cone).injective.ne hmn.symm have : x ∈ s := by convert s.smul_mem (c ^ n - c ^ m)⁻¹ A rw [smul_smul, inv_mul_cancel₀ H, one_smul] exact hx this /-- A strict affine subspace has measure zero. -/ theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by rcases s.eq_bot_or_nonempty with (rfl | hne) · rw [AffineSubspace.bot_coe, measure_empty] rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs rcases hne with ⟨x, hx : x ∈ s⟩ simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg, image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs /-! ### Applying a linear map rescales Haar measure by the determinant We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a linear equiv maps Haar measure to Haar measure. -/ theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ} (hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] : Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by cases nonempty_fintype ι /- We have already proved the result for the Lebesgue product measure, using matrices. We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/ have := addHaarMeasure_unique μ (piIcc01 ι) rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul, Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) : Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by -- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using -- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`. let ι := Fin (finrank ℝ E) haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι] have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this -- next line is to avoid `g` getting reduced by `simp`. obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩ have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e rw [← gdet] at hf ⊢ have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by ext x simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp, LinearEquiv.symm_apply_apply, hg] simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp] have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable] haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm have ecomp : e.symm ∘ e = id := by ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply] rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul, map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id] /-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := calc μ (f ⁻¹' s) = Measure.map f μ s := ((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl /-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E} (hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s := addHaar_preimage_linearMap μ hf s /-- The preimage of a set `s` under a linear equiv `f` has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero convert addHaar_preimage_linearMap μ A s simp only [LinearEquiv.det_coe_symm] /-- The preimage of a set `s` under a continuous linear equiv `f` has measure equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := addHaar_preimage_linearEquiv μ _ s /-- The image of a set `s` under a linear map `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf) · let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv change μ (g '' s) = _ rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv] congr · simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero] have : μ (LinearMap.range f) = 0 := addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _) /-- The image of a set `s` under a continuous linear map `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s := addHaar_image_linearMap μ _ s /-- The image of a set `s` under a continuous linear equiv `f` has measure equal to `μ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s := μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) : QuasiMeasurePreserving f μ μ := by refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩ rw [map_linearMap_addHaar_eq_smul_addHaar μ hf] exact smul_absolutelyContinuous theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) : QuasiMeasurePreserving f μ μ := LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf /-! ### Basic properties of Haar measures on real vector spaces -/ theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) : Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E) change Measure.map f μ = _ have hf : LinearMap.det f ≠ 0 := by simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one] intro h exact hr (pow_eq_zero h) simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one] theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) : QuasiMeasurePreserving (r • ·) μ μ := by refine ⟨measurable_const_smul r, ?_⟩ rw [map_addHaar_smul μ hr] exact smul_absolutelyContinuous @[simp] theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) : μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := calc μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s := ((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul] /-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/ @[simp] theorem addHaar_smul (r : ℝ) (s : Set E) : μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by rcases ne_or_eq r 0 with (h | rfl) · rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv] rcases eq_empty_or_nonempty s with (rfl | hs) · simp only [measure_empty, mul_zero, smul_set_empty] rw [zero_smul_set hs, ← singleton_zero] by_cases h : finrank ℝ E = 0 · haveI : Subsingleton E := finrank_zero_iff.1 h simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs, pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))] · haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h) simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff, zero_pow, measure_singleton] theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) : μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by rw [addHaar_smul, abs_pow, abs_of_nonneg hr] variable {μ} {s : Set E} -- Note: We might want to rename this once we acquire the lemma corresponding to -- `MeasurableSet.const_smul` theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) : NullMeasurableSet (r • s) μ := by obtain rfl | hs' := s.eq_empty_or_nonempty · simp obtain rfl | hr := eq_or_ne r 0 · simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _ obtain ⟨t, ht, hst⟩ := hs refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩ rw [← measure_symmDiff_eq_zero_iff] at hst ⊢ rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero] variable (μ) @[simp] theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) : μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := calc μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by simp only [image_add_right, measure_preimage_add_right, addHaar_smul] /-! We don't need to state `map_addHaar_neg` here, because it has already been proved for general Haar measures on general commutative groups. -/ /-! ### Measure of balls -/ theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball] rw [this, measure_preimage_add] theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ.real (ball x r) = μ.real (ball (0 : E) r) := by simp [measureReal_def, addHaar_ball_center] theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (closedBall x r) = μ (closedBall (0 : E) r) := by have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall] rw [this, measure_preimage_add] theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ.real (closedBall x r) = μ.real (closedBall (0 : E) r) := by simp [measureReal_def, addHaar_closedBall_center] theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by have : ball (0 : E) (r * s) = r • ball (0 : E) s := by simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow] theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) : μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [← addHaar_ball_mul_of_pos μ x hr, mul_one] theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) : μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by rcases hr.eq_or_lt with (rfl | h) · simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul, ENNReal.ofReal_zero, ball_zero] · exact addHaar_ball_mul_of_pos μ x h s theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [← addHaar_ball_mul μ x hr, mul_one] theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow] theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) : μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr] simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow] /-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball. Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard form. -/ theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one]
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
474
476
theorem addHaar_real_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) : μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (closedBall 0 1) := by
simp only [measureReal_def, addHaar_closedBall' μ x hr, ENNReal.toReal_mul, mul_eq_mul_right_iff,
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope /-! # Line derivatives We define the line derivative of a function `f : E → F`, at a point `x : E` along a vector `v : E`, as the element `f' : F` such that `f (x + t • v) = f x + t • f' + o (t)` as `t` tends to `0` in the scalar field `𝕜`, if it exists. It is denoted by `lineDeriv 𝕜 f x v`. This notion is generally less well behaved than the full Fréchet derivative (for instance, the composition of functions which are line-differentiable is not line-differentiable in general). The Fréchet derivative should therefore be favored over this one in general, although the line derivative may sometimes prove handy. The line derivative in direction `v` is also called the Gateaux derivative in direction `v`, although the term "Gateaux derivative" is sometimes reserved for the situation where there is such a derivative in all directions, for the map `v ↦ lineDeriv 𝕜 f x v` (which doesn't have to be linear in general). ## Main definition and results We mimic the definitions and statements for the Fréchet derivative and the one-dimensional derivative. We define in particular the following objects: * `LineDifferentiableWithinAt 𝕜 f s x v` * `LineDifferentiableAt 𝕜 f x v` * `HasLineDerivWithinAt 𝕜 f f' s x v` * `HasLineDerivAt 𝕜 f s x v` * `lineDerivWithin 𝕜 f s x v` * `lineDeriv 𝕜 f x v` and develop about them a basic API inspired by the one for the Fréchet derivative. We depart from the Fréchet derivative in two places, as the dependence of the following predicates on the direction would make them barely usable: * We do not define an analogue of the predicate `UniqueDiffOn`; * We do not define `LineDifferentiableOn` nor `LineDifferentiable`. -/ noncomputable section open scoped Topology Filter ENNReal NNReal open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section Module /-! Results that do not rely on a topological structure on `E` -/ variable (𝕜) variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] /-- `f` has the derivative `f'` at the point `x` along the direction `v` in the set `s`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivWithinAt (f : E → F) (f' : F) (s : Set E) (x : E) (v : E) := HasDerivWithinAt (fun t ↦ f (x + t • v)) f' ((fun t ↦ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` has the derivative `f'` at the point `x` along the direction `v`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivAt (f : E → F) (f' : F) (x : E) (v : E) := HasDerivAt (fun t ↦ f (x + t • v)) f' (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` in the set `s` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def LineDifferentiableWithinAt (f : E → F) (s : Set E) (x : E) (v : E) : Prop := DifferentiableWithinAt 𝕜 (fun t ↦ f (x + t • v)) ((fun t ↦ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. -/ def LineDifferentiableAt (f : E → F) (x : E) (v : E) : Prop := DifferentiableAt 𝕜 (fun t ↦ f (x + t • v)) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v` within the set `s`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivWithinAt 𝕜 f f' s x v`), then `f (x + t v) = f x + t lineDerivWithin 𝕜 f s x v + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def lineDerivWithin (f : E → F) (s : Set E) (x : E) (v : E) : F := derivWithin (fun t ↦ f (x + t • v)) ((fun t ↦ x + t • v) ⁻¹' s) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivAt 𝕜 f f' x v`), then `f (x + t v) = f x + t lineDeriv 𝕜 f x v + o (t)` when `t` tends to `0`. -/ def lineDeriv (f : E → F) (x : E) (v : E) : F := deriv (fun t ↦ f (x + t • v)) (0 : 𝕜) variable {𝕜} variable {f f₁ : E → F} {f' f₀' f₁' : F} {s t : Set E} {x v : E} lemma HasLineDerivWithinAt.mono (hf : HasLineDerivWithinAt 𝕜 f f' s x v) (hst : t ⊆ s) : HasLineDerivWithinAt 𝕜 f f' t x v := HasDerivWithinAt.mono hf (preimage_mono hst) lemma HasLineDerivAt.hasLineDerivWithinAt (hf : HasLineDerivAt 𝕜 f f' x v) (s : Set E) : HasLineDerivWithinAt 𝕜 f f' s x v := HasDerivAt.hasDerivWithinAt hf lemma HasLineDerivWithinAt.lineDifferentiableWithinAt (hf : HasLineDerivWithinAt 𝕜 f f' s x v) : LineDifferentiableWithinAt 𝕜 f s x v := HasDerivWithinAt.differentiableWithinAt hf theorem HasLineDerivAt.lineDifferentiableAt (hf : HasLineDerivAt 𝕜 f f' x v) : LineDifferentiableAt 𝕜 f x v := HasDerivAt.differentiableAt hf theorem LineDifferentiableWithinAt.hasLineDerivWithinAt (h : LineDifferentiableWithinAt 𝕜 f s x v) : HasLineDerivWithinAt 𝕜 f (lineDerivWithin 𝕜 f s x v) s x v := DifferentiableWithinAt.hasDerivWithinAt h theorem LineDifferentiableAt.hasLineDerivAt (h : LineDifferentiableAt 𝕜 f x v) : HasLineDerivAt 𝕜 f (lineDeriv 𝕜 f x v) x v := DifferentiableAt.hasDerivAt h @[simp] lemma hasLineDerivWithinAt_univ : HasLineDerivWithinAt 𝕜 f f' univ x v ↔ HasLineDerivAt 𝕜 f f' x v := by simp only [HasLineDerivWithinAt, HasLineDerivAt, preimage_univ, hasDerivWithinAt_univ] theorem lineDerivWithin_zero_of_not_lineDifferentiableWithinAt (h : ¬LineDifferentiableWithinAt 𝕜 f s x v) : lineDerivWithin 𝕜 f s x v = 0 := derivWithin_zero_of_not_differentiableWithinAt h theorem lineDeriv_zero_of_not_lineDifferentiableAt (h : ¬LineDifferentiableAt 𝕜 f x v) : lineDeriv 𝕜 f x v = 0 := deriv_zero_of_not_differentiableAt h theorem hasLineDerivAt_iff_isLittleO_nhds_zero : HasLineDerivAt 𝕜 f f' x v ↔ (fun t : 𝕜 => f (x + t • v) - f x - t • f') =o[𝓝 0] fun t => t := by simp only [HasLineDerivAt, hasDerivAt_iff_isLittleO_nhds_zero, zero_add, zero_smul, add_zero] theorem HasLineDerivAt.unique (h₀ : HasLineDerivAt 𝕜 f f₀' x v) (h₁ : HasLineDerivAt 𝕜 f f₁' x v) : f₀' = f₁' := HasDerivAt.unique h₀ h₁ protected theorem HasLineDerivAt.lineDeriv (h : HasLineDerivAt 𝕜 f f' x v) : lineDeriv 𝕜 f x v = f' := by rw [h.unique h.lineDifferentiableAt.hasLineDerivAt]
Mathlib/Analysis/Calculus/LineDeriv/Basic.lean
160
163
theorem lineDifferentiableWithinAt_univ : LineDifferentiableWithinAt 𝕜 f univ x v ↔ LineDifferentiableAt 𝕜 f x v := by
simp only [LineDifferentiableWithinAt, LineDifferentiableAt, preimage_univ, differentiableWithinAt_univ]
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Interval.Finset.Basic /-! # Intervals as multisets This file defines intervals as multisets. ## Main declarations In a `LocallyFiniteOrder`, * `Multiset.Icc`: Closed-closed interval as a multiset. * `Multiset.Ico`: Closed-open interval as a multiset. * `Multiset.Ioc`: Open-closed interval as a multiset. * `Multiset.Ioo`: Open-open interval as a multiset. In a `LocallyFiniteOrderTop`, * `Multiset.Ici`: Closed-infinite interval as a multiset. * `Multiset.Ioi`: Open-infinite interval as a multiset. In a `LocallyFiniteOrderBot`, * `Multiset.Iic`: Infinite-open interval as a multiset. * `Multiset.Iio`: Infinite-closed interval as a multiset. ## TODO Do we really need this file at all? (March 2024) -/ variable {α : Type*} namespace Multiset section LocallyFiniteOrder variable [Preorder α] [LocallyFiniteOrder α] {a b x : α} /-- The multiset of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a multiset. -/ def Icc (a b : α) : Multiset α := (Finset.Icc a b).val /-- The multiset of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a multiset. -/ def Ico (a b : α) : Multiset α := (Finset.Ico a b).val /-- The multiset of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a multiset. -/ def Ioc (a b : α) : Multiset α := (Finset.Ioc a b).val /-- The multiset of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a multiset. -/ def Ioo (a b : α) : Multiset α := (Finset.Ioo a b).val @[simp] lemma mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := by rw [Icc, ← Finset.mem_def, Finset.mem_Icc] @[simp] lemma mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := by rw [Ico, ← Finset.mem_def, Finset.mem_Ico] @[simp] lemma mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := by rw [Ioc, ← Finset.mem_def, Finset.mem_Ioc] @[simp] lemma mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := by rw [Ioo, ← Finset.mem_def, Finset.mem_Ioo] end LocallyFiniteOrder section LocallyFiniteOrderTop variable [Preorder α] [LocallyFiniteOrderTop α] {a x : α} /-- The multiset of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a multiset. -/ def Ici (a : α) : Multiset α := (Finset.Ici a).val /-- The multiset of elements `x` such that `a < x`. Basically `Set.Ioi a` as a multiset. -/ def Ioi (a : α) : Multiset α := (Finset.Ioi a).val @[simp] lemma mem_Ici : x ∈ Ici a ↔ a ≤ x := by rw [Ici, ← Finset.mem_def, Finset.mem_Ici] @[simp] lemma mem_Ioi : x ∈ Ioi a ↔ a < x := by rw [Ioi, ← Finset.mem_def, Finset.mem_Ioi] end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [Preorder α] [LocallyFiniteOrderBot α] {b x : α} /-- The multiset of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a multiset. -/ def Iic (b : α) : Multiset α := (Finset.Iic b).val /-- The multiset of elements `x` such that `x < b`. Basically `Set.Iio b` as a multiset. -/ def Iio (b : α) : Multiset α := (Finset.Iio b).val @[simp] lemma mem_Iic : x ∈ Iic b ↔ x ≤ b := by rw [Iic, ← Finset.mem_def, Finset.mem_Iic] @[simp] lemma mem_Iio : x ∈ Iio b ↔ x < b := by rw [Iio, ← Finset.mem_def, Finset.mem_Iio] end LocallyFiniteOrderBot section Preorder variable [Preorder α] [LocallyFiniteOrder α] {a b c : α} theorem nodup_Icc : (Icc a b).Nodup := Finset.nodup _ theorem nodup_Ico : (Ico a b).Nodup := Finset.nodup _ theorem nodup_Ioc : (Ioc a b).Nodup := Finset.nodup _ theorem nodup_Ioo : (Ioo a b).Nodup := Finset.nodup _ @[simp] theorem Icc_eq_zero_iff : Icc a b = 0 ↔ ¬a ≤ b := by rw [Icc, Finset.val_eq_zero, Finset.Icc_eq_empty_iff] @[simp] theorem Ico_eq_zero_iff : Ico a b = 0 ↔ ¬a < b := by rw [Ico, Finset.val_eq_zero, Finset.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_zero_iff : Ioc a b = 0 ↔ ¬a < b := by rw [Ioc, Finset.val_eq_zero, Finset.Ioc_eq_empty_iff] @[simp] theorem Ioo_eq_zero_iff [DenselyOrdered α] : Ioo a b = 0 ↔ ¬a < b := by rw [Ioo, Finset.val_eq_zero, Finset.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_zero⟩ := Icc_eq_zero_iff alias ⟨_, Ico_eq_zero⟩ := Ico_eq_zero_iff alias ⟨_, Ioc_eq_zero⟩ := Ioc_eq_zero_iff @[simp] theorem Ioo_eq_zero (h : ¬a < b) : Ioo a b = 0 := eq_zero_iff_forall_not_mem.2 fun _x hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_zero_of_lt (h : b < a) : Icc a b = 0 := Icc_eq_zero h.not_le @[simp] theorem Ico_eq_zero_of_le (h : b ≤ a) : Ico a b = 0 := Ico_eq_zero h.not_lt @[simp] theorem Ioc_eq_zero_of_le (h : b ≤ a) : Ioc a b = 0 := Ioc_eq_zero h.not_lt @[simp] theorem Ioo_eq_zero_of_le (h : b ≤ a) : Ioo a b = 0 := Ioo_eq_zero h.not_lt variable (a) theorem Ico_self : Ico a a = 0 := by rw [Ico, Finset.Ico_self, Finset.empty_val] theorem Ioc_self : Ioc a a = 0 := by rw [Ioc, Finset.Ioc_self, Finset.empty_val] theorem Ioo_self : Ioo a a = 0 := by rw [Ioo, Finset.Ioo_self, Finset.empty_val] variable {a} theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := Finset.left_mem_Icc theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := Finset.left_mem_Ico theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := Finset.right_mem_Icc theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := Finset.right_mem_Ioc theorem left_not_mem_Ioc : a ∉ Ioc a b := Finset.left_not_mem_Ioc theorem left_not_mem_Ioo : a ∉ Ioo a b := Finset.left_not_mem_Ioo theorem right_not_mem_Ico : b ∉ Ico a b := Finset.right_not_mem_Ico theorem right_not_mem_Ioo : b ∉ Ioo a b := Finset.right_not_mem_Ioo theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : ((Ico a b).filter fun x => x < c) = ∅ := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_left hca] rfl theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : ((Ico a b).filter fun x => x < c) = Ico a b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_right_le hbc] theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : ((Ico a b).filter fun x => x < c) = Ico a c := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_lt_of_le_right hcb] rfl theorem Ico_filter_le_of_le_left [DecidablePred (c ≤ ·)] (hca : c ≤ a) : ((Ico a b).filter fun x => c ≤ x) = Ico a b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_le_left hca] theorem Ico_filter_le_of_right_le [DecidablePred (b ≤ ·)] : ((Ico a b).filter fun x => b ≤ x) = ∅ := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_right_le] rfl theorem Ico_filter_le_of_left_le [DecidablePred (c ≤ ·)] (hac : a ≤ c) : ((Ico a b).filter fun x => c ≤ x) = Ico c b := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_of_left_le hac] rfl end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [Icc, Finset.Icc_self, Finset.singleton_val] theorem Ico_cons_right (h : a ≤ b) : b ::ₘ Ico a b = Icc a b := by classical rw [Ico, ← Finset.insert_val_of_not_mem right_not_mem_Ico, Finset.Ico_insert_right h] rfl theorem Ioo_cons_left (h : a < b) : a ::ₘ Ioo a b = Ico a b := by classical rw [Ioo, ← Finset.insert_val_of_not_mem left_not_mem_Ioo, Finset.Ioo_insert_left h] rfl theorem Ico_disjoint_Ico {a b c d : α} (h : b ≤ c) : Disjoint (Ico a b) (Ico c d) := disjoint_left.mpr fun hab hbc => by rw [mem_Ico] at hab hbc exact hab.2.not_le (h.trans hbc.1) @[simp] theorem Ico_inter_Ico_of_le [DecidableEq α] {a b c d : α} (h : b ≤ c) : Ico a b ∩ Ico c d = 0 := Multiset.inter_eq_zero_iff_disjoint.2 <| Ico_disjoint_Ico h theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : ((Ico a b).filter fun x => x ≤ a) = {a} := by rw [Ico, ← Finset.filter_val, Finset.Ico_filter_le_left hab] rfl theorem card_Ico_eq_card_Icc_sub_one (a b : α) : card (Ico a b) = card (Icc a b) - 1 := Finset.card_Ico_eq_card_Icc_sub_one _ _ theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : card (Ioc a b) = card (Icc a b) - 1 := Finset.card_Ioc_eq_card_Icc_sub_one _ _ theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : card (Ioo a b) = card (Ico a b) - 1 := Finset.card_Ioo_eq_card_Ico_sub_one _ _ theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : card (Ioo a b) = card (Icc a b) - 2 := Finset.card_Ioo_eq_card_Icc_sub_two _ _ end PartialOrder section LinearOrder variable [LinearOrder α] [LocallyFiniteOrder α] {a b c d : α} theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := Finset.Ico_subset_Ico_iff h theorem Ico_add_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b + Ico b c = Ico a c := by rw [add_eq_union_iff_disjoint.2 (Ico_disjoint_Ico le_rfl), Ico, Ico, Ico, ← Finset.union_val, Finset.Ico_union_Ico_eq_Ico hab hbc] theorem Ico_inter_Ico : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [Ico, Ico, Ico, ← Finset.inter_val, Finset.Ico_inter_Ico] @[simp] theorem Ico_filter_lt (a b c : α) : ((Ico a b).filter fun x => x < c) = Ico a (min b c) := by rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_lt] @[simp]
Mathlib/Order/Interval/Multiset.lean
287
290
theorem Ico_filter_le (a b c : α) : ((Ico a b).filter fun x => c ≤ x) = Ico (max a c) b := by
rw [Ico, Ico, ← Finset.filter_val, Finset.Ico_filter_le] @[simp]
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.RepresentationTheory.FDRep import Mathlib.LinearAlgebra.Trace import Mathlib.RepresentationTheory.Invariants /-! # Characters of representations This file introduces characters of representation and proves basic lemmas about how characters behave under various operations on representations. A key result is the orthogonality of characters for irreducible representations of finite group over an algebraically closed field whose characteristic doesn't divide the order of the group. It is the theorem `char_orthonormal` ## Implementation notes Irreducible representations are implemented categorically, using the `CategoryTheory.Simple` class defined in `Mathlib.CategoryTheory.Simple` ## TODO * Once we have the monoidal closed structure on `FdRep k G` and a better API for the rigid structure, `char_dual` and `char_linHom` should probably be stated in terms of `Vᘁ` and `ihom V W`. -/ noncomputable section universe u open CategoryTheory LinearMap CategoryTheory.MonoidalCategory Representation Module variable {k : Type u} [Field k] namespace FDRep section Monoid variable {G : Type u} [Monoid G] /-- The character of a representation `V : FDRep k G` is the function associating to `g : G` the trace of the linear map `V.ρ g`. -/ def character (V : FDRep k G) (g : G) := LinearMap.trace k V (V.ρ g) theorem char_mul_comm (V : FDRep k G) (g : G) (h : G) : V.character (h * g) = V.character (g * h) := by simp only [trace_mul_comm, character, map_mul] @[simp] theorem char_one (V : FDRep k G) : V.character 1 = Module.finrank k V := by simp only [character, map_one, trace_one] /-- The character is multiplicative under the tensor product. -/ @[simp]
Mathlib/RepresentationTheory/Character.lean
59
60
theorem char_tensor (V W : FDRep k G) : (V ⊗ W).character = V.character * W.character := by
ext g; convert trace_tensorProduct' (V.ρ g) (W.ρ g)
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Module.Defs import Mathlib.Data.DFinsupp.Module /-! # Pointwise order on finitely supported dependent functions This file lifts order structures on the `α i` to `Π₀ i, α i`. ## Main declarations * `DFinsupp.orderEmbeddingToFun`: The order embedding from finitely supported dependent functions to functions. -/ open Finset variable {ι : Type*} {α : ι → Type*} namespace DFinsupp /-! ### Order structures -/ section Zero variable [∀ i, Zero (α i)] section LE variable [∀ i, LE (α i)] {f g : Π₀ i, α i} instance : LE (Π₀ i, α i) := ⟨fun f g ↦ ∀ i, f i ≤ g i⟩ lemma le_def : f ≤ g ↔ ∀ i, f i ≤ g i := Iff.rfl @[simp, norm_cast] lemma coe_le_coe : ⇑f ≤ g ↔ f ≤ g := Iff.rfl /-- The order on `DFinsupp`s over a partial order embeds into the order on functions -/ def orderEmbeddingToFun : (Π₀ i, α i) ↪o ∀ i, α i where toFun := DFunLike.coe inj' := DFunLike.coe_injective map_rel_iff' := Iff.rfl @[simp, norm_cast] lemma coe_orderEmbeddingToFun : ⇑(orderEmbeddingToFun (α := α)) = DFunLike.coe := rfl theorem orderEmbeddingToFun_apply {f : Π₀ i, α i} {i : ι} : orderEmbeddingToFun f i = f i := rfl end LE section Preorder variable [∀ i, Preorder (α i)] {f g : Π₀ i, α i} instance : Preorder (Π₀ i, α i) := { (inferInstance : LE (DFinsupp α)) with le_refl := fun _ _ ↦ le_rfl le_trans := fun _ _ _ hfg hgh i ↦ (hfg i).trans (hgh i) } lemma lt_def : f < g ↔ f ≤ g ∧ ∃ i, f i < g i := Pi.lt_def @[simp, norm_cast] lemma coe_lt_coe : ⇑f < g ↔ f < g := Iff.rfl lemma coe_mono : Monotone ((⇑) : (Π₀ i, α i) → ∀ i, α i) := fun _ _ ↦ id lemma coe_strictMono : Monotone ((⇑) : (Π₀ i, α i) → ∀ i, α i) := fun _ _ ↦ id end Preorder instance [∀ i, PartialOrder (α i)] : PartialOrder (Π₀ i, α i) := { (inferInstance : Preorder (DFinsupp α)) with le_antisymm := fun _ _ hfg hgf ↦ ext fun i ↦ (hfg i).antisymm (hgf i) } instance [∀ i, SemilatticeInf (α i)] : SemilatticeInf (Π₀ i, α i) := { (inferInstance : PartialOrder (DFinsupp α)) with inf := zipWith (fun _ ↦ (· ⊓ ·)) fun _ ↦ inf_idem _ inf_le_left := fun _ _ _ ↦ inf_le_left inf_le_right := fun _ _ _ ↦ inf_le_right le_inf := fun _ _ _ hf hg i ↦ le_inf (hf i) (hg i) } @[simp, norm_cast] lemma coe_inf [∀ i, SemilatticeInf (α i)] (f g : Π₀ i, α i) : f ⊓ g = ⇑f ⊓ g := rfl theorem inf_apply [∀ i, SemilatticeInf (α i)] (f g : Π₀ i, α i) (i : ι) : (f ⊓ g) i = f i ⊓ g i := zipWith_apply _ _ _ _ _ instance [∀ i, SemilatticeSup (α i)] : SemilatticeSup (Π₀ i, α i) := { (inferInstance : PartialOrder (DFinsupp α)) with sup := zipWith (fun _ ↦ (· ⊔ ·)) fun _ ↦ sup_idem _ le_sup_left := fun _ _ _ ↦ le_sup_left le_sup_right := fun _ _ _ ↦ le_sup_right sup_le := fun _ _ _ hf hg i ↦ sup_le (hf i) (hg i) } @[simp, norm_cast] lemma coe_sup [∀ i, SemilatticeSup (α i)] (f g : Π₀ i, α i) : f ⊔ g = ⇑f ⊔ g := rfl theorem sup_apply [∀ i, SemilatticeSup (α i)] (f g : Π₀ i, α i) (i : ι) : (f ⊔ g) i = f i ⊔ g i := zipWith_apply _ _ _ _ _ section Lattice variable [∀ i, Lattice (α i)] (f g : Π₀ i, α i) instance lattice : Lattice (Π₀ i, α i) := { (inferInstance : SemilatticeInf (DFinsupp α)), (inferInstance : SemilatticeSup (DFinsupp α)) with } variable [DecidableEq ι] [∀ (i) (x : α i), Decidable (x ≠ 0)] theorem support_inf_union_support_sup : (f ⊓ g).support ∪ (f ⊔ g).support = f.support ∪ g.support := coe_injective <| compl_injective <| by ext; simp [inf_eq_and_sup_eq_iff] theorem support_sup_union_support_inf : (f ⊔ g).support ∪ (f ⊓ g).support = f.support ∪ g.support := (union_comm _ _).trans <| support_inf_union_support_sup _ _ end Lattice end Zero /-! ### Algebraic order structures -/ instance (α : ι → Type*) [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, IsOrderedAddMonoid (α i)] : IsOrderedAddMonoid (Π₀ i, α i) := { add_le_add_left := fun _ _ h c i ↦ add_le_add_left (h i) (c i) } instance (α : ι → Type*) [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, IsOrderedCancelAddMonoid (α i)] : IsOrderedCancelAddMonoid (Π₀ i, α i) := { le_of_add_le_add_left := fun _ _ _ H i ↦ le_of_add_le_add_left (H i) } instance [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, AddLeftReflectLE (α i)] : AddLeftReflectLE (Π₀ i, α i) := ⟨fun _ _ _ H i ↦ le_of_add_le_add_left (H i)⟩ section Module variable {α : Type*} {β : ι → Type*} [Semiring α] [Preorder α] [∀ i, AddCommMonoid (β i)] [∀ i, Preorder (β i)] [∀ i, Module α (β i)] instance instPosSMulMono [∀ i, PosSMulMono α (β i)] : PosSMulMono α (Π₀ i, β i) := PosSMulMono.lift _ coe_le_coe coe_smul instance instSMulPosMono [∀ i, SMulPosMono α (β i)] : SMulPosMono α (Π₀ i, β i) := SMulPosMono.lift _ coe_le_coe coe_smul coe_zero instance instPosSMulReflectLE [∀ i, PosSMulReflectLE α (β i)] : PosSMulReflectLE α (Π₀ i, β i) := PosSMulReflectLE.lift _ coe_le_coe coe_smul instance instSMulPosReflectLE [∀ i, SMulPosReflectLE α (β i)] : SMulPosReflectLE α (Π₀ i, β i) := SMulPosReflectLE.lift _ coe_le_coe coe_smul coe_zero end Module section Module variable {α : Type*} {β : ι → Type*} [Semiring α] [PartialOrder α] [∀ i, AddCommMonoid (β i)] [∀ i, PartialOrder (β i)] [∀ i, Module α (β i)] instance instPosSMulStrictMono [∀ i, PosSMulStrictMono α (β i)] : PosSMulStrictMono α (Π₀ i, β i) := PosSMulStrictMono.lift _ coe_le_coe coe_smul instance instSMulPosStrictMono [∀ i, SMulPosStrictMono α (β i)] : SMulPosStrictMono α (Π₀ i, β i) := SMulPosStrictMono.lift _ coe_le_coe coe_smul coe_zero -- Note: There is no interesting instance for `PosSMulReflectLT α (Π₀ i, β i)` that's not already -- implied by the other instances instance instSMulPosReflectLT [∀ i, SMulPosReflectLT α (β i)] : SMulPosReflectLT α (Π₀ i, β i) := SMulPosReflectLT.lift _ coe_le_coe coe_smul coe_zero end Module section PartialOrder variable (α) [∀ i, AddCommMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, CanonicallyOrderedAdd (α i)] instance : OrderBot (Π₀ i, α i) where bot := 0 bot_le := by simp only [le_def, coe_zero, Pi.zero_apply, imp_true_iff, zero_le] variable {α} protected theorem bot_eq_zero : (⊥ : Π₀ i, α i) = 0 := rfl @[simp] theorem add_eq_zero_iff (f g : Π₀ i, α i) : f + g = 0 ↔ f = 0 ∧ g = 0 := by simp [DFunLike.ext_iff, forall_and] section LE variable [DecidableEq ι] section variable [∀ (i) (x : α i), Decidable (x ≠ 0)] {f g : Π₀ i, α i} {s : Finset ι} theorem le_iff' (hf : f.support ⊆ s) : f ≤ g ↔ ∀ i ∈ s, f i ≤ g i := ⟨fun h s _ ↦ h s, fun h s ↦ if H : s ∈ f.support then h s (hf H) else (not_mem_support_iff.1 H).symm ▸ zero_le (g s)⟩ theorem le_iff : f ≤ g ↔ ∀ i ∈ f.support, f i ≤ g i := le_iff' <| Subset.refl _ lemma support_monotone : Monotone (support (ι := ι) (β := α)) := fun f g h a ha ↦ by rw [mem_support_iff, ← pos_iff_ne_zero] at ha ⊢; exact ha.trans_le (h _) lemma support_mono (hfg : f ≤ g) : f.support ⊆ g.support := support_monotone hfg variable (α) in instance decidableLE [∀ i, DecidableLE (α i)] : DecidableLE (Π₀ i, α i) := fun _ _ ↦ decidable_of_iff _ le_iff.symm end @[simp] theorem single_le_iff {f : Π₀ i, α i} {i : ι} {a : α i} : single i a ≤ f ↔ a ≤ f i := by classical exact (le_iff' support_single_subset).trans <| by simp end LE variable (α) [∀ i, Sub (α i)] [∀ i, OrderedSub (α i)] {f g : Π₀ i, α i} {i : ι} {a b : α i} /-- This is called `tsub` for truncated subtraction, to distinguish it with subtraction in an additive group. -/ instance tsub : Sub (Π₀ i, α i) := ⟨zipWith (fun _ m n ↦ m - n) fun _ ↦ tsub_self 0⟩ variable {α} theorem tsub_apply (f g : Π₀ i, α i) (i : ι) : (f - g) i = f i - g i := zipWith_apply _ _ _ _ _ @[simp, norm_cast] theorem coe_tsub (f g : Π₀ i, α i) : ⇑(f - g) = f - g := by ext i exact tsub_apply f g i variable (α) instance : OrderedSub (Π₀ i, α i) := ⟨fun _ _ _ ↦ forall_congr' fun _ ↦ tsub_le_iff_right⟩ instance [∀ i, CovariantClass (α i) (α i) (· + ·) (· ≤ ·)] : CanonicallyOrderedAdd (Π₀ i, α i) where exists_add_of_le := by intro f g h exists g - f ext i exact (add_tsub_cancel_of_le <| h i).symm le_self_add := fun _ _ _ ↦ le_self_add variable {α} [DecidableEq ι] @[simp] theorem single_tsub : single i (a - b) = single i a - single i b := by ext j obtain rfl | h := eq_or_ne i j · rw [tsub_apply, single_eq_same, single_eq_same, single_eq_same] · rw [tsub_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, tsub_self] variable [∀ (i) (x : α i), Decidable (x ≠ 0)]
Mathlib/Data/DFinsupp/Order.lean
265
267
theorem support_tsub : (f - g).support ⊆ f.support := by
simp +contextual only [subset_iff, tsub_eq_zero_iff_le, mem_support_iff, Ne, coe_tsub, Pi.sub_apply, not_imp_not, zero_le, imp_true_iff]
/- Copyright (c) 2024 Emilie Burgun. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emilie Burgun -/ import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Exponent import Mathlib.GroupTheory.GroupAction.Basic /-! # Period of a group action This module defines some helpful lemmas around [`MulAction.period`] and [`AddAction.period`]. The period of a point `a` by a group element `g` is the smallest `m` such that `g ^ m • a = a` (resp. `(m • g) +ᵥ a = a`) for a given `g : G` and `a : α`. If such an `m` does not exist, then by convention `MulAction.period` and `AddAction.period` return 0. -/ namespace MulAction universe u v variable {α : Type v} variable {G : Type u} [Group G] [MulAction G α] variable {M : Type u} [Monoid M] [MulAction M α] /-- If the action is periodic, then a lower bound for its period can be computed. -/ @[to_additive "If the action is periodic, then a lower bound for its period can be computed."] theorem le_period {m : M} {a : α} {n : ℕ} (period_pos : 0 < period m a) (moved : ∀ k, 0 < k → k < n → m ^ k • a ≠ a) : n ≤ period m a := le_of_not_gt fun period_lt_n => moved _ period_pos period_lt_n <| pow_period_smul m a /-- If for some `n`, `m ^ n • a = a`, then `period m a ≤ n`. -/ @[to_additive "If for some `n`, `(n • m) +ᵥ a = a`, then `period m a ≤ n`."] theorem period_le_of_fixed {m : M} {a : α} {n : ℕ} (n_pos : 0 < n) (fixed : m ^ n • a = a) : period m a ≤ n := (isPeriodicPt_smul_iff.mpr fixed).minimalPeriod_le n_pos /-- If for some `n`, `m ^ n • a = a`, then `0 < period m a`. -/ @[to_additive "If for some `n`, `(n • m) +ᵥ a = a`, then `0 < period m a`."] theorem period_pos_of_fixed {m : M} {a : α} {n : ℕ} (n_pos : 0 < n) (fixed : m ^ n • a = a) : 0 < period m a := (isPeriodicPt_smul_iff.mpr fixed).minimalPeriod_pos n_pos @[to_additive] theorem period_eq_one_iff {m : M} {a : α} : period m a = 1 ↔ m • a = a := ⟨fun eq_one => pow_one m ▸ eq_one ▸ pow_period_smul m a, fun fixed => le_antisymm (period_le_of_fixed one_pos (by simpa)) (period_pos_of_fixed one_pos (by simpa))⟩ /-- For any non-zero `n` less than the period of `m` on `a`, `a` is moved by `m ^ n`. -/ @[to_additive "For any non-zero `n` less than the period of `m` on `a`, `a` is moved by `n • m`."] theorem pow_smul_ne_of_lt_period {m : M} {a : α} {n : ℕ} (n_pos : 0 < n) (n_lt_period : n < period m a) : m ^ n • a ≠ a := fun a_fixed => not_le_of_gt n_lt_period <| period_le_of_fixed n_pos a_fixed section Identities /-! ### `MulAction.period` for common group elements -/ variable (M) in @[to_additive (attr := simp)] theorem period_one (a : α) : period (1 : M) a = 1 := period_eq_one_iff.mpr (one_smul M a) @[to_additive (attr := simp)] theorem period_inv (g : G) (a : α) : period g⁻¹ a = period g a := by simp only [period_eq_minimalPeriod, Function.minimalPeriod_eq_minimalPeriod_iff, isPeriodicPt_smul_iff] intro n rw [smul_eq_iff_eq_inv_smul, eq_comm, ← zpow_natCast, inv_zpow, inv_inv, zpow_natCast] end Identities section MonoidExponent /-! ### `MulAction.period` and group exponents The period of a given element `m : M` can be bounded by the `Monoid.exponent M` or `orderOf m`. -/ @[to_additive]
Mathlib/GroupTheory/GroupAction/Period.lean
87
88
theorem period_dvd_orderOf (m : M) (a : α) : period m a ∣ orderOf m := by
rw [← pow_smul_eq_iff_period_dvd, pow_orderOf_eq_one, one_smul]
/- 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]
Mathlib/Data/Set/Lattice.lean
991
992
theorem iUnion_singleton_eq_range (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.Discriminant import Mathlib.RingTheory.Polynomial.Eisenstein.IsIntegral import Mathlib.RingTheory.Ideal.Norm.AbsNorm import Mathlib.RingTheory.Prime /-! # Ring of integers of `p ^ n`-th cyclotomic fields We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of integers of a `p ^ n`-th cyclotomic extension of `ℚ`. ## Main results * `IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow`: if `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. * `IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow`: the integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. * `IsCyclotomicExtension.Rat.absdiscr_prime_pow` and related results: the absolute discriminant of cyclotomic fields. -/ universe u open Algebra IsCyclotomicExtension Polynomial NumberField open scoped Cyclotomic Nat variable {p : ℕ+} {k : ℕ} {K : Type u} [Field K] {ζ : K} [hp : Fact (p : ℕ).Prime] namespace IsCyclotomicExtension.Rat variable [CharZero K] /-- The discriminant of the power basis given by `ζ - 1`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm
Mathlib/NumberTheory/Cyclotomic/Rat.lean
46
49
theorem discr_odd_prime' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (hodd : p ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by
rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm
/- 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.Data.Multiset.Bind /-! # The cartesian product of multisets ## Main definitions * `Multiset.pi`: Cartesian product of multisets indexed by a multiset. -/ namespace Multiset section Pi open Function namespace Pi variable {α : Type*} [DecidableEq α] {δ : α → Sort*} /-- Given `δ : α → Sort*`, `Pi.empty δ` is the trivial dependent function out of the empty multiset. -/ def empty (δ : α → Sort*) : ∀ a ∈ (0 : Multiset α), δ a := nofun variable (m : Multiset α) (a : α) /-- Given `δ : α → Sort*`, a multiset `m` and a term `a`, as well as a term `b : δ a` and a function `f` such that `f a' : δ a'` for all `a'` in `m`, `Pi.cons m a b f` is a function `g` such that `g a'' : δ a''` for all `a''` in `a ::ₘ m`. -/ def cons (b : δ a) (f : ∀ a ∈ m, δ a) : ∀ a' ∈ a ::ₘ m, δ a' := fun a' ha' => if h : a' = a then Eq.ndrec b h.symm else f a' <| (mem_cons.1 ha').resolve_left h variable {m a} theorem cons_same {b : δ a} {f : ∀ a ∈ m, δ a} (h : a ∈ a ::ₘ m) : cons m a b f a h = b := dif_pos rfl theorem cons_ne {a a' : α} {b : δ a} {f : ∀ a ∈ m, δ a} (h' : a' ∈ a ::ₘ m) (h : a' ≠ a) : Pi.cons m a b f a' h' = f a' ((mem_cons.1 h').resolve_left h) := dif_neg h
Mathlib/Data/Multiset/Pi.lean
49
58
theorem cons_swap {a a' : α} {b : δ a} {b' : δ a'} {m : Multiset α} {f : ∀ a ∈ m, δ a} (h : a ≠ a') : HEq (Pi.cons (a' ::ₘ m) a b (Pi.cons m a' b' f)) (Pi.cons (a ::ₘ m) a' b' (Pi.cons m a b f)) := by
apply hfunext rfl simp only [heq_iff_eq] rintro a'' _ rfl refine hfunext (by rw [Multiset.cons_swap]) fun ha₁ ha₂ _ => ?_ rcases Decidable.ne_or_eq a'' a with (h₁ | rfl) on_goal 1 => rcases Decidable.eq_or_ne a'' a' with (rfl | h₂) all_goals simp [*, Pi.cons_same, Pi.cons_ne]
/- Copyright (c) 2024 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, Oliver Nash -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Identities import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.RingTheory.Polynomial.Nilpotent import Mathlib.RingTheory.Polynomial.Tower /-! # Newton-Raphson method Given a single-variable polynomial `P` with derivative `P'`, Newton's method concerns iteration of the rational map: `x ↦ x - P(x) / P'(x)`. Over a field it can serve as a root-finding algorithm. It is also useful tool in certain proofs such as Hensel's lemma and Jordan-Chevalley decomposition. ## Main definitions / results: * `Polynomial.newtonMap`: the map `x ↦ x - P(x) / P'(x)`, where `P'` is the derivative of the polynomial `P`. * `Polynomial.isFixedPt_newtonMap_of_isUnit_iff`: `x` is a fixed point for Newton iteration iff it is a root of `P` (provided `P'(x)` is a unit). * `Polynomial.existsUnique_nilpotent_sub_and_aeval_eq_zero`: if `x` is almost a root of `P` in the sense that `P(x)` is nilpotent (and `P'(x)` is a unit) then we may write `x` as a sum `x = n + r` where `n` is nilpotent and `r` is a root of `P`. This can be used to prove the Jordan-Chevalley decomposition of linear endomorphims. -/ open Set Function noncomputable section namespace Polynomial variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] (P : R[X]) {x : S} /-- Given a single-variable polynomial `P` with derivative `P'`, this is the map: `x ↦ x - P(x) / P'(x)`. When `P'(x)` is not a unit we use a junk-value pattern and send `x ↦ x`. -/ def newtonMap (x : S) : S := x - (Ring.inverse <| aeval x (derivative P)) * aeval x P theorem newtonMap_apply : P.newtonMap x = x - (Ring.inverse <| aeval x (derivative P)) * (aeval x P) := rfl variable {P} theorem newtonMap_apply_of_isUnit (h : IsUnit <| aeval x (derivative P)) : P.newtonMap x = x - h.unit⁻¹ * aeval x P := by simp [newtonMap_apply, Ring.inverse, h] theorem newtonMap_apply_of_not_isUnit (h : ¬ (IsUnit <| aeval x (derivative P))) : P.newtonMap x = x := by simp [newtonMap_apply, Ring.inverse, h] theorem isNilpotent_iterate_newtonMap_sub_of_isNilpotent (h : IsNilpotent <| aeval x P) (n : ℕ) : IsNilpotent <| P.newtonMap^[n] x - x := by induction n with | zero => simp | succ n ih => rw [iterate_succ', comp_apply, newtonMap_apply, sub_right_comm] refine (Commute.all _ _).isNilpotent_sub ih <| (Commute.all _ _).isNilpotent_mul_right ?_ simpa using Commute.isNilpotent_add (Commute.all _ _) (isNilpotent_aeval_sub_of_isNilpotent_sub P ih) h theorem isFixedPt_newtonMap_of_aeval_eq_zero (h : aeval x P = 0) : IsFixedPt P.newtonMap x := by rw [IsFixedPt, newtonMap_apply, h, mul_zero, sub_zero] theorem isFixedPt_newtonMap_of_isUnit_iff (h : IsUnit <| aeval x (derivative P)) : IsFixedPt P.newtonMap x ↔ aeval x P = 0 := by rw [IsFixedPt, newtonMap_apply, sub_eq_self, Ring.inverse_mul_eq_iff_eq_mul _ _ _ h, mul_zero] /-- This is really an auxiliary result, en route to `Polynomial.existsUnique_nilpotent_sub_and_aeval_eq_zero`. -/ theorem aeval_pow_two_pow_dvd_aeval_iterate_newtonMap (h : IsNilpotent (aeval x P)) (h' : IsUnit (aeval x <| derivative P)) (n : ℕ) : (aeval x P) ^ (2 ^ n) ∣ aeval (P.newtonMap^[n] x) P := by induction n with | zero => simp | succ n ih => have ⟨d, hd⟩ := binomExpansion (P.map (algebraMap R S)) (P.newtonMap^[n] x) (-Ring.inverse (aeval (P.newtonMap^[n] x) <| derivative P) * aeval (P.newtonMap^[n] x) P) rw [eval_map_algebraMap, eval_map_algebraMap] at hd rw [iterate_succ', comp_apply, newtonMap_apply, sub_eq_add_neg, neg_mul_eq_neg_mul, hd] refine dvd_add ?_ (dvd_mul_of_dvd_right ?_ _) · convert dvd_zero _ have : IsUnit (aeval (P.newtonMap^[n] x) <| derivative P) := isUnit_aeval_of_isUnit_aeval_of_isNilpotent_sub h' <| isNilpotent_iterate_newtonMap_sub_of_isNilpotent h n rw [derivative_map, eval_map_algebraMap, ← mul_assoc, mul_neg, Ring.mul_inverse_cancel _ this, neg_mul, one_mul, add_neg_cancel] · rw [neg_mul, even_two.neg_pow, mul_pow, pow_succ, pow_mul] exact dvd_mul_of_dvd_right (pow_dvd_pow_of_dvd ih 2) _ /-- If `x` is almost a root of `P` in the sense that `P(x)` is nilpotent (and `P'(x)` is a unit) then we may write `x` as a sum `x = n + r` where `n` is nilpotent and `r` is a root of `P`. Moreover, `n` and `r` are unique. This can be used to prove the Jordan-Chevalley decomposition of linear endomorphims. -/
Mathlib/Dynamics/Newton.lean
106
126
theorem existsUnique_nilpotent_sub_and_aeval_eq_zero (h : IsNilpotent (aeval x P)) (h' : IsUnit (aeval x <| derivative P)) : ∃! r, IsNilpotent (x - r) ∧ aeval r P = 0 := by
simp_rw [(neg_sub _ x).symm, isNilpotent_neg_iff] refine existsUnique_of_exists_of_unique ?_ fun r₁ r₂ ⟨hr₁, hr₁'⟩ ⟨hr₂, hr₂'⟩ ↦ ?_ · -- Existence obtain ⟨n, hn⟩ := id h refine ⟨P.newtonMap^[n] x, isNilpotent_iterate_newtonMap_sub_of_isNilpotent h n, ?_⟩ rw [← zero_dvd_iff, ← pow_eq_zero_of_le (n.lt_two_pow_self).le hn] exact aeval_pow_two_pow_dvd_aeval_iterate_newtonMap h h' n · -- Uniqueness have ⟨u, hu⟩ := binomExpansion (P.map (algebraMap R S)) r₁ (r₂ - r₁) suffices IsUnit (aeval r₁ (derivative P) + u * (r₂ - r₁)) by rwa [derivative_map, eval_map_algebraMap, eval_map_algebraMap, eval_map_algebraMap, add_sub_cancel, hr₂', hr₁', zero_add, pow_two, ← mul_assoc, ← add_mul, eq_comm, this.mul_right_eq_zero, sub_eq_zero, eq_comm] at hu have : IsUnit (aeval r₁ (derivative P)) := isUnit_aeval_of_isUnit_aeval_of_isNilpotent_sub h' hr₁ rw [← sub_sub_sub_cancel_right r₂ r₁ x] refine IsNilpotent.isUnit_add_left_of_commute ?_ this (Commute.all _ _) exact (Commute.all _ _).isNilpotent_mul_right <| (Commute.all _ _).isNilpotent_sub hr₂ hr₁
/- Copyright (c) 2024 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.CategoryTheory.Sites.Coherent.Comparison import Mathlib.CategoryTheory.Sites.Coherent.ExtensiveSheaves import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPrecoherent import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPreregular import Mathlib.CategoryTheory.Sites.DenseSubsite.InducedTopology import Mathlib.CategoryTheory.Sites.Whiskering /-! # Categories of coherent sheaves Given a fully faithful functor `F : C ⥤ D` into a precoherent category, which preserves and reflects finite effective epi families, and satisfies the property `F.EffectivelyEnough` (meaning that to every object in `C` there is an effective epi from an object in the image of `F`), the categories of coherent sheaves on `C` and `D` are equivalent (see `CategoryTheory.coherentTopology.equivalence`). The main application of this equivalence is the characterisation of condensed sets as coherent sheaves on either `CompHaus`, `Profinite` or `Stonean`. See the file `Condensed/Equivalence.lean` We give the corresponding result for the regular topology as well (see `CategoryTheory.regularTopology.equivalence`). -/ universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ namespace CategoryTheory open Limits Functor regularTopology variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D) namespace coherentTopology variable [F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies] [F.Full] [F.Faithful] [F.EffectivelyEnough] [Precoherent D] instance : F.IsCoverDense (coherentTopology _) := by refine F.isCoverDense_of_generate_singleton_functor_π_mem _ fun B ↦ ⟨_, F.effectiveEpiOver B, ?_⟩ apply Coverage.Saturate.of refine ⟨Unit, inferInstance, fun _ => F.effectiveEpiOverObj B, fun _ => F.effectiveEpiOver B, ?_ , ?_⟩ · funext; ext -- Do we want `Presieve.ext`? refine ⟨fun ⟨⟩ ↦ ⟨()⟩, ?_⟩ rintro ⟨⟩ simp · rw [← effectiveEpi_iff_effectiveEpiFamily] infer_instance
Mathlib/CategoryTheory/Sites/Coherent/SheafComparison.lean
55
76
theorem exists_effectiveEpiFamily_iff_mem_induced (X : C) (S : Sieve X) : (∃ (α : Type) (_ : Finite α) (Y : α → C) (π : (a : α) → (Y a ⟶ X)), EffectiveEpiFamily Y π ∧ (∀ a : α, (S.arrows) (π a)) ) ↔ (S ∈ F.inducedTopology (coherentTopology _) X) := by
refine ⟨fun ⟨α, _, Y, π, ⟨H₁, H₂⟩⟩ ↦ ?_, fun hS ↦ ?_⟩ · apply (mem_sieves_iff_hasEffectiveEpiFamily (Sieve.functorPushforward _ S)).mpr refine ⟨α, inferInstance, fun i => F.obj (Y i), fun i => F.map (π i), ⟨?_, fun a => Sieve.image_mem_functorPushforward F S (H₂ a)⟩⟩ exact F.map_finite_effectiveEpiFamily _ _ · obtain ⟨α, _, Y, π, ⟨H₁, H₂⟩⟩ := (mem_sieves_iff_hasEffectiveEpiFamily _).mp hS refine ⟨α, inferInstance, ?_⟩ let Z : α → C := fun a ↦ (Functor.EffectivelyEnough.presentation (F := F) (Y a)).some.p let g₀ : (a : α) → F.obj (Z a) ⟶ Y a := fun a ↦ F.effectiveEpiOver (Y a) have : EffectiveEpiFamily _ (fun a ↦ g₀ a ≫ π a) := inferInstance refine ⟨Z , fun a ↦ F.preimage (g₀ a ≫ π a), ?_, fun a ↦ (?_ : S.arrows (F.preimage _))⟩ · refine F.finite_effectiveEpiFamily_of_map _ _ ?_ simpa using this · obtain ⟨W, g₁, g₂, h₁, h₂⟩ := H₂ a rw [h₂] convert S.downward_closed h₁ (F.preimage (g₀ a ≫ g₂)) exact F.map_injective (by simp)
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Sean Leather -/ import Batteries.Data.List.Perm import Mathlib.Data.List.Pairwise import Mathlib.Data.List.Nodup import Mathlib.Data.List.Lookmap import Mathlib.Data.Sigma.Basic /-! # Utilities for lists of sigmas This file includes several ways of interacting with `List (Sigma β)`, treated as a key-value store. If `α : Type*` and `β : α → Type*`, then we regard `s : Sigma β` as having key `s.1 : α` and value `s.2 : β s.1`. Hence, `List (Sigma β)` behaves like a key-value store. ## Main Definitions - `List.keys` extracts the list of keys. - `List.NodupKeys` determines if the store has duplicate keys. - `List.lookup`/`lookup_all` accesses the value(s) of a particular key. - `List.kreplace` replaces the first value with a given key by a given value. - `List.kerase` removes a value. - `List.kinsert` inserts a value. - `List.kunion` computes the union of two stores. - `List.kextract` returns a value with a given key and the rest of the values. -/ universe u u' v v' namespace List variable {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} {l l₁ l₂ : List (Sigma β)} /-! ### `keys` -/ /-- List of keys from a list of key-value pairs -/ def keys : List (Sigma β) → List α := map Sigma.fst @[simp] theorem keys_nil : @keys α β [] = [] := rfl @[simp] theorem keys_cons {s} {l : List (Sigma β)} : (s :: l).keys = s.1 :: l.keys := rfl theorem mem_keys_of_mem {s : Sigma β} {l : List (Sigma β)} : s ∈ l → s.1 ∈ l.keys := mem_map_of_mem theorem exists_of_mem_keys {a} {l : List (Sigma β)} (h : a ∈ l.keys) : ∃ b : β a, Sigma.mk a b ∈ l := let ⟨⟨_, b'⟩, m, e⟩ := exists_of_mem_map h Eq.recOn e (Exists.intro b' m) theorem mem_keys {a} {l : List (Sigma β)} : a ∈ l.keys ↔ ∃ b : β a, Sigma.mk a b ∈ l := ⟨exists_of_mem_keys, fun ⟨_, h⟩ => mem_keys_of_mem h⟩ theorem not_mem_keys {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ b : β a, Sigma.mk a b ∉ l := (not_congr mem_keys).trans not_exists theorem ne_key {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ s : Sigma β, s ∈ l → a ≠ s.1 := Iff.intro (fun h₁ s h₂ e => absurd (mem_keys_of_mem h₂) (by rwa [e] at h₁)) fun f h₁ => let ⟨_, h₂⟩ := exists_of_mem_keys h₁ f _ h₂ rfl @[deprecated (since := "2025-04-27")] alias not_eq_key := ne_key /-! ### `NodupKeys` -/ /-- Determines whether the store uses a key several times. -/ def NodupKeys (l : List (Sigma β)) : Prop := l.keys.Nodup theorem nodupKeys_iff_pairwise {l} : NodupKeys l ↔ Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l := pairwise_map theorem NodupKeys.pairwise_ne {l} (h : NodupKeys l) : Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l := nodupKeys_iff_pairwise.1 h @[simp] theorem nodupKeys_nil : @NodupKeys α β [] := Pairwise.nil @[simp] theorem nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} : NodupKeys (s :: l) ↔ s.1 ∉ l.keys ∧ NodupKeys l := by simp [keys, NodupKeys] theorem not_mem_keys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) : s.1 ∉ l.keys := (nodupKeys_cons.1 h).1 theorem nodupKeys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) : NodupKeys l := (nodupKeys_cons.1 h).2 theorem NodupKeys.eq_of_fst_eq {l : List (Sigma β)} (nd : NodupKeys l) {s s' : Sigma β} (h : s ∈ l) (h' : s' ∈ l) : s.1 = s'.1 → s = s' := @Pairwise.forall_of_forall _ (fun s s' : Sigma β => s.1 = s'.1 → s = s') _ (fun _ _ H h => (H h.symm).symm) (fun _ _ _ => rfl) ((nodupKeys_iff_pairwise.1 nd).imp fun h h' => (h h').elim) _ h _ h' theorem NodupKeys.eq_of_mk_mem {a : α} {b b' : β a} {l : List (Sigma β)} (nd : NodupKeys l) (h : Sigma.mk a b ∈ l) (h' : Sigma.mk a b' ∈ l) : b = b' := by cases nd.eq_of_fst_eq h h' rfl; rfl theorem nodupKeys_singleton (s : Sigma β) : NodupKeys [s] := nodup_singleton _ theorem NodupKeys.sublist {l₁ l₂ : List (Sigma β)} (h : l₁ <+ l₂) : NodupKeys l₂ → NodupKeys l₁ := Nodup.sublist <| h.map _ protected theorem NodupKeys.nodup {l : List (Sigma β)} : NodupKeys l → Nodup l := Nodup.of_map _ theorem perm_nodupKeys {l₁ l₂ : List (Sigma β)} (h : l₁ ~ l₂) : NodupKeys l₁ ↔ NodupKeys l₂ := (h.map _).nodup_iff theorem nodupKeys_flatten {L : List (List (Sigma β))} : NodupKeys (flatten L) ↔ (∀ l ∈ L, NodupKeys l) ∧ Pairwise Disjoint (L.map keys) := by rw [nodupKeys_iff_pairwise, pairwise_flatten, pairwise_map] refine and_congr (forall₂_congr fun l _ => by simp [nodupKeys_iff_pairwise]) ?_ apply iff_of_eq; congr! with (l₁ l₂) simp [keys, disjoint_iff_ne, Sigma.forall] theorem nodup_zipIdx_map_snd (l : List α) : (l.zipIdx.map Prod.snd).Nodup := by simp [List.nodup_range'] @[deprecated (since := "2025-01-28")] alias nodup_enum_map_fst := nodup_zipIdx_map_snd theorem mem_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.Nodup) (nd₁ : l₁.Nodup) (h : ∀ x, x ∈ l₀ ↔ x ∈ l₁) : l₀ ~ l₁ := (perm_ext_iff_of_nodup nd₀ nd₁).2 h variable [DecidableEq α] [DecidableEq α'] /-! ### `dlookup` -/ /-- `dlookup a l` is the first value in `l` corresponding to the key `a`, or `none` if no such element exists. -/ def dlookup (a : α) : List (Sigma β) → Option (β a) | [] => none | ⟨a', b⟩ :: l => if h : a' = a then some (Eq.recOn h b) else dlookup a l @[simp] theorem dlookup_nil (a : α) : dlookup a [] = @none (β a) := rfl @[simp] theorem dlookup_cons_eq (l) (a : α) (b : β a) : dlookup a (⟨a, b⟩ :: l) = some b := dif_pos rfl @[simp] theorem dlookup_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → dlookup a (s :: l) = dlookup a l | ⟨_, _⟩, h => dif_neg h.symm theorem dlookup_isSome {a : α} : ∀ {l : List (Sigma β)}, (dlookup a l).isSome ↔ a ∈ l.keys | [] => by simp | ⟨a', b⟩ :: l => by by_cases h : a = a' · subst a' simp · simp [h, dlookup_isSome] theorem dlookup_eq_none {a : α} {l : List (Sigma β)} : dlookup a l = none ↔ a ∉ l.keys := by simp [← dlookup_isSome, Option.isNone_iff_eq_none] theorem of_mem_dlookup {a : α} {b : β a} : ∀ {l : List (Sigma β)}, b ∈ dlookup a l → Sigma.mk a b ∈ l | ⟨a', b'⟩ :: l, H => by by_cases h : a = a' · subst a' simp? at H says simp only [dlookup_cons_eq, Option.mem_def, Option.some.injEq] at H simp [H] · simp only [ne_eq, h, not_false_iff, dlookup_cons_ne] at H simp [of_mem_dlookup H] theorem mem_dlookup {a} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) (h : Sigma.mk a b ∈ l) : b ∈ dlookup a l := by obtain ⟨b', h'⟩ := Option.isSome_iff_exists.mp (dlookup_isSome.mpr (mem_keys_of_mem h)) cases nd.eq_of_mk_mem h (of_mem_dlookup h') exact h' theorem map_dlookup_eq_find (a : α) : ∀ l : List (Sigma β), (dlookup a l).map (Sigma.mk a) = find? (fun s => a = s.1) l | [] => rfl | ⟨a', b'⟩ :: l => by by_cases h : a = a' · subst a' simp · simpa [h] using map_dlookup_eq_find a l
Mathlib/Data/List/Sigma.lean
201
209
theorem mem_dlookup_iff {a : α} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) : b ∈ dlookup a l ↔ Sigma.mk a b ∈ l := ⟨of_mem_dlookup, mem_dlookup nd⟩ theorem perm_dlookup (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys) (p : l₁ ~ l₂) : dlookup a l₁ = dlookup a l₂ := by
ext b; simp only [mem_dlookup_iff nd₁, mem_dlookup_iff nd₂]; exact p.mem_iff theorem lookup_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.NodupKeys) (nd₁ : l₁.NodupKeys)
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Kim Morrison -/ import Mathlib.CategoryTheory.Subobject.MonoOver import Mathlib.CategoryTheory.Skeletal import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.Tactic.ApplyFun import Mathlib.Tactic.CategoryTheory.Elementwise /-! # Subobjects We define `Subobject X` as the quotient (by isomorphisms) of `MonoOver X := {f : Over X // Mono f.hom}`. Here `MonoOver X` is a thin category (a pair of objects has at most one morphism between them), so we can think of it as a preorder. However as it is not skeletal, it is not a partial order. There is a coercion from `Subobject X` back to the ambient category `C` (using choice to pick a representative), and for `P : Subobject X`, `P.arrow : (P : C) ⟶ X` is the inclusion morphism. We provide * `def pullback [HasPullbacks C] (f : X ⟶ Y) : Subobject Y ⥤ Subobject X` * `def map (f : X ⟶ Y) [Mono f] : Subobject X ⥤ Subobject Y` * `def «exists_» [HasImages C] (f : X ⟶ Y) : Subobject X ⥤ Subobject Y` and prove their basic properties and relationships. These are all easy consequences of the earlier development of the corresponding functors for `MonoOver`. The subobjects of `X` form a preorder making them into a category. We have `X ≤ Y` if and only if `X.arrow` factors through `Y.arrow`: see `ofLE`/`ofLEMk`/`ofMkLE`/`ofMkLEMk` and `le_of_comm`. Similarly, to show that two subobjects are equal, we can supply an isomorphism between the underlying objects that commutes with the arrows (`eq_of_comm`). See also * `CategoryTheory.Subobject.factorThru` : an API describing factorization of morphisms through subobjects. * `CategoryTheory.Subobject.lattice` : the lattice structures on subobjects. ## Notes This development originally appeared in Bhavik Mehta's "Topos theory for Lean" repository, and was ported to mathlib by Kim Morrison. ### Implementation note Currently we describe `pullback`, `map`, etc., as functors. It may be better to just say that they are monotone functions, and even avoid using categorical language entirely when describing `Subobject X`. (It's worth keeping this in mind in future use; it should be a relatively easy change here if it looks preferable.) ### Relation to pseudoelements There is a separate development of pseudoelements in `CategoryTheory.Abelian.Pseudoelements`, as a quotient (but not by isomorphism) of `Over X`. When a morphism `f` has an image, the image represents the same pseudoelement. In a category with images `Pseudoelements X` could be constructed as a quotient of `MonoOver X`. In fact, in an abelian category (I'm not sure in what generality beyond that), `Pseudoelements X` agrees with `Subobject X`, but we haven't developed this in mathlib yet. -/ universe v₁ v₂ u₁ u₂ noncomputable section namespace CategoryTheory open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] {X Y Z : C} variable {D : Type u₂} [Category.{v₂} D] /-! We now construct the subobject lattice for `X : C`, as the quotient by isomorphisms of `MonoOver X`. Since `MonoOver X` is a thin category, we use `ThinSkeleton` to take the quotient. Essentially all the structure defined above on `MonoOver X` descends to `Subobject X`, with morphisms becoming inequalities, and isomorphisms becoming equations. -/ /-- The category of subobjects of `X : C`, defined as isomorphism classes of monomorphisms into `X`. -/ def Subobject (X : C) := ThinSkeleton (MonoOver X) instance (X : C) : PartialOrder (Subobject X) := inferInstanceAs <| PartialOrder (ThinSkeleton (MonoOver X)) namespace Subobject -- Porting note: made it a def rather than an abbreviation -- because Lean would make it too transparent /-- Convenience constructor for a subobject. -/ def mk {X A : C} (f : A ⟶ X) [Mono f] : Subobject X := (toThinSkeleton _).obj (MonoOver.mk' f) section attribute [local ext] CategoryTheory.Comma protected theorem ind {X : C} (p : Subobject X → Prop) (h : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], p (Subobject.mk f)) (P : Subobject X) : p P := by apply Quotient.inductionOn' intro a exact h a.arrow protected theorem ind₂ {X : C} (p : Subobject X → Subobject X → Prop) (h : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [Mono f] [Mono g], p (Subobject.mk f) (Subobject.mk g)) (P Q : Subobject X) : p P Q := by apply Quotient.inductionOn₂' intro a b exact h a.arrow b.arrow end /-- Declare a function on subobjects of `X` by specifying a function on monomorphisms with codomain `X`. -/ protected def lift {α : Sort*} {X : C} (F : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], α) (h : ∀ ⦃A B : C⦄ (f : A ⟶ X) (g : B ⟶ X) [Mono f] [Mono g] (i : A ≅ B), i.hom ≫ g = f → F f = F g) : Subobject X → α := fun P => Quotient.liftOn' P (fun m => F m.arrow) fun m n ⟨i⟩ => h m.arrow n.arrow ((MonoOver.forget X ⋙ Over.forget X).mapIso i) (Over.w i.hom) @[simp] protected theorem lift_mk {α : Sort*} {X : C} (F : ∀ ⦃A : C⦄ (f : A ⟶ X) [Mono f], α) {h A} (f : A ⟶ X) [Mono f] : Subobject.lift F h (Subobject.mk f) = F f := rfl /-- The category of subobjects is equivalent to the `MonoOver` category. It is more convenient to use the former due to the partial order instance, but oftentimes it is easier to define structures on the latter. -/ noncomputable def equivMonoOver (X : C) : Subobject X ≌ MonoOver X := ThinSkeleton.equivalence _ /-- Use choice to pick a representative `MonoOver X` for each `Subobject X`. -/ noncomputable def representative {X : C} : Subobject X ⥤ MonoOver X := (equivMonoOver X).functor instance : (representative (X := X)).IsEquivalence := (equivMonoOver X).isEquivalence_functor /-- Starting with `A : MonoOver X`, we can take its equivalence class in `Subobject X` then pick an arbitrary representative using `representative.obj`. This is isomorphic (in `MonoOver X`) to the original `A`. -/ noncomputable def representativeIso {X : C} (A : MonoOver X) : representative.obj ((toThinSkeleton _).obj A) ≅ A := (equivMonoOver X).counitIso.app A /-- Use choice to pick a representative underlying object in `C` for any `Subobject X`. Prefer to use the coercion `P : C` rather than explicitly writing `underlying.obj P`. -/ noncomputable def underlying {X : C} : Subobject X ⥤ C := representative ⋙ MonoOver.forget _ ⋙ Over.forget _ instance : CoeOut (Subobject X) C where coe Y := underlying.obj Y -- Porting note: removed as it has become a syntactic tautology -- @[simp] -- theorem underlying_as_coe {X : C} (P : Subobject X) : underlying.obj P = P := -- rfl /-- If we construct a `Subobject Y` from an explicit `f : X ⟶ Y` with `[Mono f]`, then pick an arbitrary choice of underlying object `(Subobject.mk f : C)` back in `C`, it is isomorphic (in `C`) to the original `X`. -/ noncomputable def underlyingIso {X Y : C} (f : X ⟶ Y) [Mono f] : (Subobject.mk f : C) ≅ X := (MonoOver.forget _ ⋙ Over.forget _).mapIso (representativeIso (MonoOver.mk' f)) /-- The morphism in `C` from the arbitrarily chosen underlying object to the ambient object. -/ noncomputable def arrow {X : C} (Y : Subobject X) : (Y : C) ⟶ X := (representative.obj Y).obj.hom instance arrow_mono {X : C} (Y : Subobject X) : Mono Y.arrow := (representative.obj Y).property @[simp] theorem arrow_congr {A : C} (X Y : Subobject A) (h : X = Y) : eqToHom (congr_arg (fun X : Subobject A => (X : C)) h) ≫ Y.arrow = X.arrow := by induction h simp @[simp] theorem representative_coe (Y : Subobject X) : (representative.obj Y : C) = (Y : C) := rfl @[simp] theorem representative_arrow (Y : Subobject X) : (representative.obj Y).arrow = Y.arrow := rfl @[reassoc (attr := simp)] theorem underlying_arrow {X : C} {Y Z : Subobject X} (f : Y ⟶ Z) : underlying.map f ≫ arrow Z = arrow Y := Over.w (representative.map f) @[reassoc (attr := simp), elementwise (attr := simp)] theorem underlyingIso_arrow {X Y : C} (f : X ⟶ Y) [Mono f] : (underlyingIso f).inv ≫ (Subobject.mk f).arrow = f := Over.w _ @[reassoc (attr := simp)] theorem underlyingIso_hom_comp_eq_mk {X Y : C} (f : X ⟶ Y) [Mono f] : (underlyingIso f).hom ≫ f = (mk f).arrow := (Iso.eq_inv_comp _).1 (underlyingIso_arrow f).symm /-- Two morphisms into a subobject are equal exactly if the morphisms into the ambient object are equal -/ @[ext] theorem eq_of_comp_arrow_eq {X Y : C} {P : Subobject Y} {f g : X ⟶ P} (h : f ≫ P.arrow = g ≫ P.arrow) : f = g := (cancel_mono P.arrow).mp h theorem mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [Mono f₁] [Mono f₂] (g : A₁ ⟶ A₂) (w : g ≫ f₂ = f₁) : mk f₁ ≤ mk f₂ := ⟨MonoOver.homMk _ w⟩ @[simp] theorem mk_arrow (P : Subobject X) : mk P.arrow = P := Quotient.inductionOn' P fun Q => by obtain ⟨e⟩ := @Quotient.mk_out' _ (isIsomorphicSetoid _) Q exact Quotient.sound' ⟨MonoOver.isoMk (Iso.refl _) ≪≫ e⟩ theorem le_of_comm {B : C} {X Y : Subobject B} (f : (X : C) ⟶ (Y : C)) (w : f ≫ Y.arrow = X.arrow) : X ≤ Y := by convert mk_le_mk_of_comm _ w <;> simp theorem le_mk_of_comm {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (g : (X : C) ⟶ A) (w : g ≫ f = X.arrow) : X ≤ mk f := le_of_comm (g ≫ (underlyingIso f).inv) <| by simp [w] theorem mk_le_of_comm {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (g : A ⟶ (X : C)) (w : g ≫ X.arrow = f) : mk f ≤ X := le_of_comm ((underlyingIso f).hom ≫ g) <| by simp [w] /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ @[ext (iff := false)] theorem eq_of_comm {B : C} {X Y : Subobject B} (f : (X : C) ≅ (Y : C)) (w : f.hom ≫ Y.arrow = X.arrow) : X = Y := le_antisymm (le_of_comm f.hom w) <| le_of_comm f.inv <| f.inv_comp_eq.2 w.symm /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ theorem eq_mk_of_comm {B A : C} {X : Subobject B} (f : A ⟶ B) [Mono f] (i : (X : C) ≅ A) (w : i.hom ≫ f = X.arrow) : X = mk f := eq_of_comm (i.trans (underlyingIso f).symm) <| by simp [w] /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ theorem mk_eq_of_comm {B A : C} {X : Subobject B} (f : A ⟶ B) [Mono f] (i : A ≅ (X : C)) (w : i.hom ≫ X.arrow = f) : mk f = X := Eq.symm <| eq_mk_of_comm _ i.symm <| by rw [Iso.symm_hom, Iso.inv_comp_eq, w] /-- To show that two subobjects are equal, it suffices to exhibit an isomorphism commuting with the arrows. -/ theorem mk_eq_mk_of_comm {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (i : A₁ ≅ A₂) (w : i.hom ≫ g = f) : mk f = mk g := eq_mk_of_comm _ ((underlyingIso f).trans i) <| by simp [w] lemma mk_surjective {X : C} (S : Subobject X) : ∃ (A : C) (i : A ⟶ X) (_ : Mono i), S = Subobject.mk i := ⟨_, S.arrow, inferInstance, by simp⟩ -- We make `X` and `Y` explicit arguments here so that when `ofLE` appears in goal statements -- it is possible to see its source and target -- (`h` will just display as `_`, because it is in `Prop`). /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofLE {B : C} (X Y : Subobject B) (h : X ≤ Y) : (X : C) ⟶ (Y : C) := underlying.map <| h.hom @[reassoc (attr := simp)] theorem ofLE_arrow {B : C} {X Y : Subobject B} (h : X ≤ Y) : ofLE X Y h ≫ Y.arrow = X.arrow := underlying_arrow _ instance {B : C} (X Y : Subobject B) (h : X ≤ Y) : Mono (ofLE X Y h) := by fconstructor intro Z f g w replace w := w =≫ Y.arrow ext simpa using w theorem ofLE_mk_le_mk_of_comm {B A₁ A₂ : C} {f₁ : A₁ ⟶ B} {f₂ : A₂ ⟶ B} [Mono f₁] [Mono f₂] (g : A₁ ⟶ A₂) (w : g ≫ f₂ = f₁) : ofLE _ _ (mk_le_mk_of_comm g w) = (underlyingIso _).hom ≫ g ≫ (underlyingIso _).inv := by ext simp [w] /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofLEMk {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X ≤ mk f) : (X : C) ⟶ A := ofLE X (mk f) h ≫ (underlyingIso f).hom instance {B A : C} (X : Subobject B) (f : A ⟶ B) [Mono f] (h : X ≤ mk f) : Mono (ofLEMk X f h) := by dsimp only [ofLEMk] infer_instance @[simp] theorem ofLEMk_comp {B A : C} {X : Subobject B} {f : A ⟶ B} [Mono f] (h : X ≤ mk f) : ofLEMk X f h ≫ f = X.arrow := by simp [ofLEMk] /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofMkLE {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f ≤ X) : A ⟶ (X : C) := (underlyingIso f).inv ≫ ofLE (mk f) X h instance {B A : C} (f : A ⟶ B) [Mono f] (X : Subobject B) (h : mk f ≤ X) : Mono (ofMkLE f X h) := by dsimp only [ofMkLE] infer_instance @[simp] theorem ofMkLE_arrow {B A : C} {f : A ⟶ B} [Mono f] {X : Subobject B} (h : mk f ≤ X) : ofMkLE f X h ≫ X.arrow = f := by simp [ofMkLE] /-- An inequality of subobjects is witnessed by some morphism between the corresponding objects. -/ def ofMkLEMk {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f ≤ mk g) : A₁ ⟶ A₂ := (underlyingIso f).inv ≫ ofLE (mk f) (mk g) h ≫ (underlyingIso g).hom instance {B A₁ A₂ : C} (f : A₁ ⟶ B) (g : A₂ ⟶ B) [Mono f] [Mono g] (h : mk f ≤ mk g) : Mono (ofMkLEMk f g h) := by dsimp only [ofMkLEMk] infer_instance @[simp] theorem ofMkLEMk_comp {B A₁ A₂ : C} {f : A₁ ⟶ B} {g : A₂ ⟶ B} [Mono f] [Mono g] (h : mk f ≤ mk g) : ofMkLEMk f g h ≫ g = f := by simp [ofMkLEMk] @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Subobject/Basic.lean
349
350
theorem ofLE_comp_ofLE {B : C} (X Y Z : Subobject B) (h₁ : X ≤ Y) (h₂ : Y ≤ Z) : ofLE X Y h₁ ≫ ofLE Y Z h₂ = ofLE X Z (h₁.trans h₂) := by
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Finite.Prod import Mathlib.Data.Matroid.Init import Mathlib.Data.Set.Card import Mathlib.Data.Set.Finite.Powerset import Mathlib.Order.UpperLower.Closure /-! # Matroids A `Matroid` is a structure that combinatorially abstracts the notion of linear independence and dependence; matroids have connections with graph theory, discrete optimization, additive combinatorics and algebraic geometry. Mathematically, a matroid `M` is a structure on a set `E` comprising a collection of subsets of `E` called the bases of `M`, where the bases are required to obey certain axioms. This file gives a definition of a matroid `M` in terms of its bases, and some API relating independent sets (subsets of bases) and the notion of a basis of a set `X` (a maximal independent subset of `X`). ## Main definitions * a `Matroid α` on a type `α` is a structure comprising a 'ground set' and a suitably behaved 'base' predicate. Given `M : Matroid α` ... * `M.E` denotes the ground set of `M`, which has type `Set α` * For `B : Set α`, `M.IsBase B` means that `B` is a base of `M`. * For `I : Set α`, `M.Indep I` means that `I` is independent in `M` (that is, `I` is contained in a base of `M`). * For `D : Set α`, `M.Dep D` means that `D` is contained in the ground set of `M` but isn't independent. * For `I : Set α` and `X : Set α`, `M.IsBasis I X` means that `I` is a maximal independent subset of `X`. * `M.Finite` means that `M` has finite ground set. * `M.Nonempty` means that the ground set of `M` is nonempty. * `RankFinite M` means that the bases of `M` are finite. * `RankInfinite M` means that the bases of `M` are infinite. * `RankPos M` means that the bases of `M` are nonempty. * `Finitary M` means that a set is independent if and only if all its finite subsets are independent. * `aesop_mat` : a tactic designed to prove `X ⊆ M.E` for some set `X` and matroid `M`. ## Implementation details There are a few design decisions worth discussing. ### Finiteness The first is that our matroids are allowed to be infinite. Unlike with many mathematical structures, this isn't such an obvious choice. Finite matroids have been studied since the 1930's, and there was never controversy as to what is and isn't an example of a finite matroid - in fact, surprisingly many apparently different definitions of a matroid give rise to the same class of objects. However, generalizing different definitions of a finite matroid to the infinite in the obvious way (i.e. by simply allowing the ground set to be infinite) gives a number of different notions of 'infinite matroid' that disagree with each other, and that all lack nice properties. Many different competing notions of infinite matroid were studied through the years; in fact, the problem of which definition is the best was only really solved in 2013, when Bruhn et al. [2] showed that there is a unique 'reasonable' notion of an infinite matroid (these objects had previously defined by Higgs under the name 'B-matroid'). These are defined by adding one carefully chosen axiom to the standard set, and adapting existing axioms to not mention set cardinalities; they enjoy nearly all the nice properties of standard finite matroids. Even though at least 90% of the literature is on finite matroids, B-matroids are the definition we use, because they allow for additional generality, nearly all theorems are still true and just as easy to state, and (hopefully) the more general definition will prevent the need for a costly future refactor. The disadvantage is that developing API for the finite case is harder work (for instance, it is harder to prove that something is a matroid in the first place, and one must deal with `ℕ∞` rather than `ℕ`). For serious work on finite matroids, we provide the typeclasses `[M.Finite]` and `[RankFinite M]` and associated API. ### Cardinality Just as with bases of a vector space, all bases of a finite matroid `M` are finite and have the same cardinality; this cardinality is an important invariant known as the 'rank' of `M`. For infinite matroids, bases are not in general equicardinal; in fact the equicardinality of bases of infinite matroids is independent of ZFC [3]. What is still true is that either all bases are finite and equicardinal, or all bases are infinite. This means that the natural notion of 'size' for a set in matroid theory is given by the function `Set.encard`, which is the cardinality as a term in `ℕ∞`. We use this function extensively in building the API; it is preferable to both `Set.ncard` and `Finset.card` because it allows infinite sets to be handled without splitting into cases. ### The ground `Set` A last place where we make a consequential choice is making the ground set of a matroid a structure field of type `Set α` (where `α` is the type of 'possible matroid elements') rather than just having a type `α` of all the matroid elements. This is because of how common it is to simultaneously consider a number of matroids on different but related ground sets. For example, a matroid `M` on ground set `E` can have its structure 'restricted' to some subset `R ⊆ E` to give a smaller matroid `M ↾ R` with ground set `R`. A statement like `(M ↾ R₁) ↾ R₂ = M ↾ R₂` is mathematically obvious. But if the ground set of a matroid is a type, this doesn't typecheck, and is only true up to canonical isomorphism. Restriction is just the tip of the iceberg here; one can also 'contract' and 'delete' elements and sets of elements in a matroid to give a smaller matroid, and in practice it is common to make statements like `M₁.E = M₂.E ∩ M₃.E` and `((M ⟋ e) ↾ R) ⟋ C = M ⟋ (C ∪ {e}) ↾ R`. Such things are a nightmare to work with unless `=` is actually propositional equality (especially because the relevant coercions are usually between sets and not just elements). So the solution is that the ground set `M.E` has type `Set α`, and there are elements of type `α` that aren't in the matroid. The tradeoff is that for many statements, one now has to add hypotheses of the form `X ⊆ M.E` to make sure than `X` is actually 'in the matroid', rather than letting a 'type of matroid elements' take care of this invisibly. It still seems that this is worth it. The tactic `aesop_mat` exists specifically to discharge such goals with minimal fuss (using default values). The tactic works fairly well, but has room for improvement. A related decision is to not have matroids themselves be a typeclass. This would make things be notationally simpler (having `Base` in the presence of `[Matroid α]` rather than `M.Base` for a term `M : Matroid α`) but is again just too awkward when one has multiple matroids on the same type. In fact, in regular written mathematics, it is normal to explicitly indicate which matroid something is happening in, so our notation mirrors common practice. ### Notation We use a few nonstandard conventions in theorem names that are related to the above. First, we mirror common informal practice by referring explicitly to the `ground` set rather than the notation `E`. (Writing `ground` everywhere in a proof term would be unwieldy, and writing `E` in theorem names would be unnatural to read.) Second, because we are typically interested in subsets of the ground set `M.E`, using `Set.compl` is inconvenient, since `Xᶜ ⊆ M.E` is typically false for `X ⊆ M.E`. On the other hand (especially when duals arise), it is common to complement a set `X ⊆ M.E` *within* the ground set, giving `M.E \ X`. For this reason, we use the term `compl` in theorem names to refer to taking a set difference with respect to the ground set, rather than a complement within a type. The lemma `compl_isBase_dual` is one of the many examples of this. Finally, in theorem names, matroid predicates that apply to sets (such as `Base`, `Indep`, `IsBasis`) are typically used as suffixes rather than prefixes. For instance, we have `ground_indep_iff_isBase` rather than `indep_ground_iff_isBase`. ## References * [J. Oxley, Matroid Theory][oxley2011] * [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids, Adv. Math 239 (2013), 18-46][bruhnDiestelKriesselPendavinghWollan2013] * [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets, Proc. Amer. Math. Soc. 144 (2016), 459-471][bowlerGeschke2015] -/ assert_not_exists Field open Set /-- A predicate `P` on sets satisfies the **exchange property** if, for all `X` and `Y` satisfying `P` and all `a ∈ X \ Y`, there exists `b ∈ Y \ X` so that swapping `a` for `b` in `X` maintains `P`. -/ def Matroid.ExchangeProperty {α : Type*} (P : Set α → Prop) : Prop := ∀ X Y, P X → P Y → ∀ a ∈ X \ Y, ∃ b ∈ Y \ X, P (insert b (X \ {a})) /-- A set `X` has the maximal subset property for a predicate `P` if every subset of `X` satisfying `P` is contained in a maximal subset of `X` satisfying `P`. -/ def Matroid.ExistsMaximalSubsetProperty {α : Type*} (P : Set α → Prop) (X : Set α) : Prop := ∀ I, P I → I ⊆ X → ∃ J, I ⊆ J ∧ Maximal (fun K ↦ P K ∧ K ⊆ X) J /-- A `Matroid α` is a ground set `E` of type `Set α`, and a nonempty collection of its subsets satisfying the exchange property and the maximal subset property. Each such set is called a `Base` of `M`. An `Indep`endent set is just a set contained in a base, but we include this predicate as a structure field for better definitional properties. In most cases, using this definition directly is not the best way to construct a matroid, since it requires specifying both the bases and independent sets. If the bases are known, use `Matroid.ofBase` or a variant. If just the independent sets are known, define an `IndepMatroid`, and then use `IndepMatroid.matroid`. -/ structure Matroid (α : Type*) where /-- `M` has a ground set `E`. -/ (E : Set α) /-- `M` has a predicate `Base` defining its bases. -/ (IsBase : Set α → Prop) /-- `M` has a predicate `Indep` defining its independent sets. -/ (Indep : Set α → Prop) /-- The `Indep`endent sets are those contained in `Base`s. -/ (indep_iff' : ∀ ⦃I⦄, Indep I ↔ ∃ B, IsBase B ∧ I ⊆ B) /-- There is at least one `Base`. -/ (exists_isBase : ∃ B, IsBase B) /-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f` is a base. -/ (isBase_exchange : Matroid.ExchangeProperty IsBase) /-- Every independent subset `I` of a set `X` for is contained in a maximal independent subset of `X`. -/ (maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty Indep X) /-- Every base is contained in the ground set. -/ (subset_ground : ∀ B, IsBase B → B ⊆ E) attribute [local ext] Matroid namespace Matroid variable {α : Type*} {M : Matroid α} @[deprecated (since := "2025-02-14")] alias Base := IsBase instance (M : Matroid α) : Nonempty {B // M.IsBase B} := nonempty_subtype.2 M.exists_isBase /-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`. -/ @[mk_iff] protected class Finite (M : Matroid α) : Prop where /-- The ground set is finite -/ (ground_finite : M.E.Finite) /-- Typeclass for a matroid having nonempty ground set. Just a wrapper for `M.E.Nonempty`. -/ protected class Nonempty (M : Matroid α) : Prop where /-- The ground set is nonempty -/ (ground_nonempty : M.E.Nonempty) theorem ground_nonempty (M : Matroid α) [M.Nonempty] : M.E.Nonempty := Nonempty.ground_nonempty theorem ground_nonempty_iff (M : Matroid α) : M.E.Nonempty ↔ M.Nonempty := ⟨fun h ↦ ⟨h⟩, fun ⟨h⟩ ↦ h⟩ lemma nonempty_type (M : Matroid α) [h : M.Nonempty] : Nonempty α := ⟨M.ground_nonempty.some⟩ theorem ground_finite (M : Matroid α) [M.Finite] : M.E.Finite := Finite.ground_finite theorem set_finite (M : Matroid α) [M.Finite] (X : Set α) (hX : X ⊆ M.E := by aesop) : X.Finite := M.ground_finite.subset hX instance finite_of_finite [Finite α] {M : Matroid α} : M.Finite := ⟨Set.toFinite _⟩ /-- A `RankFinite` matroid is one whose bases are finite -/ @[mk_iff] class RankFinite (M : Matroid α) : Prop where /-- There is a finite base -/ exists_finite_isBase : ∃ B, M.IsBase B ∧ B.Finite @[deprecated (since := "2025-02-09")] alias FiniteRk := RankFinite instance rankFinite_of_finite (M : Matroid α) [M.Finite] : RankFinite M := ⟨M.exists_isBase.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩ /-- An `RankInfinite` matroid is one whose bases are infinite. -/ @[mk_iff] class RankInfinite (M : Matroid α) : Prop where /-- There is an infinite base -/ exists_infinite_isBase : ∃ B, M.IsBase B ∧ B.Infinite @[deprecated (since := "2025-02-09")] alias InfiniteRk := RankInfinite /-- A `RankPos` matroid is one whose bases are nonempty. -/ @[mk_iff] class RankPos (M : Matroid α) : Prop where /-- The empty set isn't a base -/ empty_not_isBase : ¬M.IsBase ∅ @[deprecated (since := "2025-02-09")] alias RkPos := RankPos instance rankPos_nonempty {M : Matroid α} [M.RankPos] : M.Nonempty := by obtain ⟨B, hB⟩ := M.exists_isBase obtain rfl | ⟨e, heB⟩ := B.eq_empty_or_nonempty · exact False.elim <| RankPos.empty_not_isBase hB exact ⟨e, M.subset_ground B hB heB ⟩ @[deprecated (since := "2025-01-20")] alias rkPos_iff_empty_not_base := rankPos_iff section exchange namespace ExchangeProperty variable {IsBase : Set α → Prop} {B B' : Set α} /-- A family of sets with the exchange property is an antichain. -/ theorem antichain (exch : ExchangeProperty IsBase) (hB : IsBase B) (hB' : IsBase B') (h : B ⊆ B') : B = B' := h.antisymm (fun x hx ↦ by_contra (fun hxB ↦ let ⟨_, hy, _⟩ := exch B' B hB' hB x ⟨hx, hxB⟩; hy.2 <| h hy.1)) theorem encard_diff_le_aux {B₁ B₂ : Set α} (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase B₂) : (B₁ \ B₂).encard ≤ (B₂ \ B₁).encard := by obtain (he | hinf | ⟨e, he, hcard⟩) := (B₂ \ B₁).eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · rw [exch.antichain hB₂ hB₁ (diff_eq_empty.mp he)] · exact le_top.trans_eq hinf.symm obtain ⟨f, hf, hB'⟩ := exch B₂ B₁ hB₂ hB₁ e he have : encard (insert f (B₂ \ {e}) \ B₁) < encard (B₂ \ B₁) := by rw [insert_diff_of_mem _ hf.1, diff_diff_comm]; exact hcard have hencard := encard_diff_le_aux exch hB₁ hB' rw [insert_diff_of_mem _ hf.1, diff_diff_comm, ← union_singleton, ← diff_diff, diff_diff_right, inter_singleton_eq_empty.mpr he.2, union_empty] at hencard rw [← encard_diff_singleton_add_one he, ← encard_diff_singleton_add_one hf] exact add_le_add_right hencard 1 termination_by (B₂ \ B₁).encard variable {B₁ B₂ : Set α} /-- For any two sets `B₁`, `B₂` in a family with the exchange property, the differences `B₁ \ B₂` and `B₂ \ B₁` have the same `ℕ∞`-cardinality. -/ theorem encard_diff_eq (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := (encard_diff_le_aux exch hB₁ hB₂).antisymm (encard_diff_le_aux exch hB₂ hB₁) /-- Any two sets `B₁`, `B₂` in a family with the exchange property have the same `ℕ∞`-cardinality. -/ theorem encard_isBase_eq (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase B₂) : B₁.encard = B₂.encard := by rw [← encard_diff_add_encard_inter B₁ B₂, exch.encard_diff_eq hB₁ hB₂, inter_comm, encard_diff_add_encard_inter] end ExchangeProperty end exchange section aesop /-- The `aesop_mat` tactic attempts to prove a set is contained in the ground set of a matroid. It uses a `[Matroid]` ruleset, and is allowed to fail. -/ macro (name := aesop_mat) "aesop_mat" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { terminal := true }) (rule_sets := [$(Lean.mkIdent `Matroid):ident])) /- We add a number of trivial lemmas (deliberately specialized to statements in terms of the ground set of a matroid) to the ruleset `Matroid` for `aesop`. -/ variable {X Y : Set α} {e : α} @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_right_subset_ground (hX : X ⊆ M.E) : X ∩ Y ⊆ M.E := inter_subset_left.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_left_subset_ground (hX : X ⊆ M.E) : Y ∩ X ⊆ M.E := inter_subset_right.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem diff_subset_ground (hX : X ⊆ M.E) : X \ Y ⊆ M.E := diff_subset.trans hX @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem ground_diff_subset_ground : M.E \ X ⊆ M.E := diff_subset_ground rfl.subset @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem singleton_subset_ground (he : e ∈ M.E) : {e} ⊆ M.E := singleton_subset_iff.mpr he @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem subset_ground_of_subset (hXY : X ⊆ Y) (hY : Y ⊆ M.E) : X ⊆ M.E := hXY.trans hY @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem mem_ground_of_mem_of_subset (hX : X ⊆ M.E) (heX : e ∈ X) : e ∈ M.E := hX heX @[aesop safe (rule_sets := [Matroid])] private theorem insert_subset_ground {e : α} {X : Set α} {M : Matroid α} (he : e ∈ M.E) (hX : X ⊆ M.E) : insert e X ⊆ M.E := insert_subset he hX @[aesop safe (rule_sets := [Matroid])] private theorem ground_subset_ground {M : Matroid α} : M.E ⊆ M.E := rfl.subset attribute [aesop safe (rule_sets := [Matroid])] empty_subset union_subset iUnion_subset end aesop section IsBase variable {B B₁ B₂ : Set α} @[aesop unsafe 10% (rule_sets := [Matroid])] theorem IsBase.subset_ground (hB : M.IsBase B) : B ⊆ M.E := M.subset_ground B hB theorem IsBase.exchange {e : α} (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hx : e ∈ B₁ \ B₂) : ∃ y ∈ B₂ \ B₁, M.IsBase (insert y (B₁ \ {e})) := M.isBase_exchange B₁ B₂ hB₁ hB₂ _ hx theorem IsBase.exchange_mem {e : α} (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) : ∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.IsBase (insert y (B₁ \ {e})) := by simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩ theorem IsBase.eq_of_subset_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hB₁B₂ : B₁ ⊆ B₂) : B₁ = B₂ := M.isBase_exchange.antichain hB₁ hB₂ hB₁B₂ theorem IsBase.not_isBase_of_ssubset {X : Set α} (hB : M.IsBase B) (hX : X ⊂ B) : ¬ M.IsBase X := fun h ↦ hX.ne (h.eq_of_subset_isBase hB hX.subset) theorem IsBase.insert_not_isBase {e : α} (hB : M.IsBase B) (heB : e ∉ B) : ¬ M.IsBase (insert e B) := fun h ↦ h.not_isBase_of_ssubset (ssubset_insert heB) hB theorem IsBase.encard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := M.isBase_exchange.encard_diff_eq hB₁ hB₂ theorem IsBase.ncard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def] theorem IsBase.encard_eq_encard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : B₁.encard = B₂.encard := by rw [M.isBase_exchange.encard_isBase_eq hB₁ hB₂] theorem IsBase.ncard_eq_ncard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : B₁.ncard = B₂.ncard := by rw [ncard_def B₁, hB₁.encard_eq_encard_of_isBase hB₂, ← ncard_def] theorem IsBase.finite_of_finite {B' : Set α} (hB : M.IsBase B) (h : B.Finite) (hB' : M.IsBase B') : B'.Finite := (finite_iff_finite_of_encard_eq_encard (hB.encard_eq_encard_of_isBase hB')).mp h theorem IsBase.infinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) (hB₁ : M.IsBase B₁) : B₁.Infinite := by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h) theorem IsBase.finite [RankFinite M] (hB : M.IsBase B) : B.Finite := let ⟨_,hB₀⟩ := ‹RankFinite M›.exists_finite_isBase hB₀.1.finite_of_finite hB₀.2 hB theorem IsBase.infinite [RankInfinite M] (hB : M.IsBase B) : B.Infinite := let ⟨_,hB₀⟩ := ‹RankInfinite M›.exists_infinite_isBase hB₀.1.infinite_of_infinite hB₀.2 hB theorem empty_not_isBase [h : RankPos M] : ¬M.IsBase ∅ := h.empty_not_isBase theorem IsBase.nonempty [RankPos M] (hB : M.IsBase B) : B.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_isBase hB theorem IsBase.rankPos_of_nonempty (hB : M.IsBase B) (h : B.Nonempty) : M.RankPos := by rw [rankPos_iff] intro he obtain rfl := he.eq_of_subset_isBase hB (empty_subset B) simp at h theorem IsBase.rankFinite_of_finite (hB : M.IsBase B) (hfin : B.Finite) : RankFinite M := ⟨⟨B, hB, hfin⟩⟩ theorem IsBase.rankInfinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) : RankInfinite M := ⟨⟨B, hB, h⟩⟩ theorem not_rankFinite (M : Matroid α) [RankInfinite M] : ¬ RankFinite M := by intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite theorem not_rankInfinite (M : Matroid α) [RankFinite M] : ¬ RankInfinite M := by intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite theorem rankFinite_or_rankInfinite (M : Matroid α) : RankFinite M ∨ RankInfinite M := let ⟨B, hB⟩ := M.exists_isBase B.finite_or_infinite.imp hB.rankFinite_of_finite hB.rankInfinite_of_infinite @[deprecated (since := "2025-03-27")] alias finite_or_rankInfinite := rankFinite_or_rankInfinite @[simp] theorem not_rankFinite_iff (M : Matroid α) : ¬ RankFinite M ↔ RankInfinite M := M.rankFinite_or_rankInfinite.elim (fun h ↦ iff_of_false (by simpa) M.not_rankInfinite) fun h ↦ iff_of_true M.not_rankFinite h @[simp] theorem not_rankInfinite_iff (M : Matroid α) : ¬ RankInfinite M ↔ RankFinite M := by rw [← not_rankFinite_iff, not_not] theorem IsBase.diff_finite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite := finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem IsBase.diff_infinite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite := infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem ext_isBase {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B)) : M₁ = M₂ := by have h' : ∀ B, M₁.IsBase B ↔ M₂.IsBase B := fun B ↦ ⟨fun hB ↦ (h hB.subset_ground).1 hB, fun hB ↦ (h <| hB.subset_ground.trans_eq hE.symm).2 hB⟩ ext <;> simp [hE, M₁.indep_iff', M₂.indep_iff', h'] @[deprecated (since := "2024-12-25")] alias eq_of_isBase_iff_isBase_forall := ext_isBase theorem ext_iff_isBase {M₁ M₂ : Matroid α} : M₁ = M₂ ↔ M₁.E = M₂.E ∧ ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B) := ⟨fun h ↦ by simp [h], fun ⟨hE, h⟩ ↦ ext_isBase hE h⟩ theorem isBase_compl_iff_maximal_disjoint_isBase (hB : B ⊆ M.E := by aesop_mat) : M.IsBase (M.E \ B) ↔ Maximal (fun I ↦ I ⊆ M.E ∧ ∃ B, M.IsBase B ∧ Disjoint I B) B := by simp_rw [maximal_iff, and_iff_right hB, and_imp, forall_exists_index] refine ⟨fun h ↦ ⟨⟨_, h, disjoint_sdiff_right⟩, fun I hI B' ⟨hB', hIB'⟩ hBI ↦ hBI.antisymm ?_⟩, fun ⟨⟨B', hB', hBB'⟩,h⟩ ↦ ?_⟩ · rw [hB'.eq_of_subset_isBase h, ← subset_compl_iff_disjoint_right, diff_eq, compl_inter, compl_compl] at hIB' · exact fun e he ↦ (hIB' he).elim (fun h' ↦ (h' (hI he)).elim) id rw [subset_diff, and_iff_right hB'.subset_ground, disjoint_comm] exact disjoint_of_subset_left hBI hIB' rw [h diff_subset B' ⟨hB', disjoint_sdiff_left⟩] · simpa [hB'.subset_ground] simp [subset_diff, hB, hBB'] end IsBase section dep_indep /-- A subset of `M.E` is `Dep`endent if it is not `Indep`endent . -/ def Dep (M : Matroid α) (D : Set α) : Prop := ¬M.Indep D ∧ D ⊆ M.E variable {B B' I J D X : Set α} {e f : α} theorem indep_iff : M.Indep I ↔ ∃ B, M.IsBase B ∧ I ⊆ B := M.indep_iff' (I := I) theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.IsBase B}) := by simp_rw [indep_iff, lowerClosure, LowerSet.coe_mk, mem_setOf, le_eq_subset] theorem Indep.exists_isBase_superset (hI : M.Indep I) : ∃ B, M.IsBase B ∧ I ⊆ B := indep_iff.1 hI theorem dep_iff : M.Dep D ↔ ¬M.Indep D ∧ D ⊆ M.E := Iff.rfl theorem setOf_dep_eq (M : Matroid α) : {D | M.Dep D} = {I | M.Indep I}ᶜ ∩ Iic M.E := rfl @[aesop unsafe 30% (rule_sets := [Matroid])] theorem Indep.subset_ground (hI : M.Indep I) : I ⊆ M.E := by obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact hIB.trans hB.subset_ground @[aesop unsafe 20% (rule_sets := [Matroid])] theorem Dep.subset_ground (hD : M.Dep D) : D ⊆ M.E := hD.2 theorem indep_or_dep (hX : X ⊆ M.E := by aesop_mat) : M.Indep X ∨ M.Dep X := by rw [Dep, and_iff_left hX] apply em theorem Indep.not_dep (hI : M.Indep I) : ¬ M.Dep I := fun h ↦ h.1 hI theorem Dep.not_indep (hD : M.Dep D) : ¬ M.Indep D := hD.1 theorem dep_of_not_indep (hD : ¬ M.Indep D) (hDE : D ⊆ M.E := by aesop_mat) : M.Dep D := ⟨hD, hDE⟩ theorem indep_of_not_dep (hI : ¬ M.Dep I) (hIE : I ⊆ M.E := by aesop_mat) : M.Indep I := by_contra (fun h ↦ hI ⟨h, hIE⟩) @[simp] theorem not_dep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Dep X ↔ M.Indep X := by rw [Dep, and_iff_left hX, not_not] @[simp] theorem not_indep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Indep X ↔ M.Dep X := by rw [Dep, and_iff_left hX] theorem indep_iff_not_dep : M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E := by rw [dep_iff, not_and, not_imp_not] exact ⟨fun h ↦ ⟨fun _ ↦ h, h.subset_ground⟩, fun h ↦ h.1 h.2⟩ theorem Indep.subset (hJ : M.Indep J) (hIJ : I ⊆ J) : M.Indep I := by obtain ⟨B, hB, hJB⟩ := hJ.exists_isBase_superset exact indep_iff.2 ⟨B, hB, hIJ.trans hJB⟩ theorem Dep.superset (hD : M.Dep D) (hDX : D ⊆ X) (hXE : X ⊆ M.E := by aesop_mat) : M.Dep X := dep_of_not_indep (fun hI ↦ (hI.subset hDX).not_dep hD) theorem IsBase.indep (hB : M.IsBase B) : M.Indep B := indep_iff.2 ⟨B, hB, subset_rfl⟩ @[simp] theorem empty_indep (M : Matroid α) : M.Indep ∅ := Exists.elim M.exists_isBase (fun _ hB ↦ hB.indep.subset (empty_subset _)) theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact hD.not_indep M.empty_indep theorem Indep.finite [RankFinite M] (hI : M.Indep I) : I.Finite := let ⟨_, hB, hIB⟩ := hI.exists_isBase_superset hB.finite.subset hIB theorem Indep.rankPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RankPos := by obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact hB.rankPos_of_nonempty (hne.mono hIB) theorem Indep.inter_right (hI : M.Indep I) (X : Set α) : M.Indep (I ∩ X) := hI.subset inter_subset_left theorem Indep.inter_left (hI : M.Indep I) (X : Set α) : M.Indep (X ∩ I) := hI.subset inter_subset_right theorem Indep.diff (hI : M.Indep I) (X : Set α) : M.Indep (I \ X) := hI.subset diff_subset theorem IsBase.eq_of_subset_indep (hB : M.IsBase B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I := let ⟨B', hB', hB'I⟩ := hI.exists_isBase_superset hBI.antisymm (by rwa [hB.eq_of_subset_isBase hB' (hBI.trans hB'I)]) theorem isBase_iff_maximal_indep : M.IsBase B ↔ Maximal M.Indep B := by rw [maximal_subset_iff] refine ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep⟩, fun ⟨h, h'⟩ ↦ ?_⟩ obtain ⟨B', hB', hBB'⟩ := h.exists_isBase_superset rwa [h' hB'.indep hBB'] theorem Indep.isBase_of_maximal (hI : M.Indep I) (h : ∀ ⦃J⦄, M.Indep J → I ⊆ J → I = J) : M.IsBase I := by rwa [isBase_iff_maximal_indep, maximal_subset_iff, and_iff_right hI] theorem IsBase.dep_of_ssubset (hB : M.IsBase B) (h : B ⊂ X) (hX : X ⊆ M.E := by aesop_mat) : M.Dep X := ⟨fun hX ↦ h.ne (hB.eq_of_subset_indep hX h.subset), hX⟩ theorem IsBase.dep_of_insert (hB : M.IsBase B) (heB : e ∉ B) (he : e ∈ M.E := by aesop_mat) : M.Dep (insert e B) := hB.dep_of_ssubset (ssubset_insert heB) (insert_subset he hB.subset_ground) theorem IsBase.mem_of_insert_indep (hB : M.IsBase B) (heB : M.Indep (insert e B)) : e ∈ B := by_contra fun he ↦ (hB.dep_of_insert he (heB.subset_ground (mem_insert _ _))).not_indep heB /-- If the difference of two IsBases is a singleton, then they differ by an insertion/removal -/ theorem IsBase.eq_exchange_of_diff_eq_singleton (hB : M.IsBase B) (hB' : M.IsBase B') (h : B \ B' = {e}) : ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e)) have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1 rw [insert_diff_singleton_comm hne] at hb refine ⟨f, hf, (hb.eq_of_subset_isBase hB' ?_).symm⟩ rw [diff_subset_iff, insert_subset_iff, union_comm, ← diff_subset_iff, h, and_iff_left rfl.subset] exact Or.inl hf.1 theorem IsBase.exchange_isBase_of_indep (hB : M.IsBase B) (hf : f ∉ B) (hI : M.Indep (insert f (B \ {e}))) : M.IsBase (insert f (B \ {e})) := by obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_superset have hcard := hB'.encard_diff_comm hB rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq] at hIB' obtain ⟨hfB, (h | h)⟩ := hIB' · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_not_mem] at hcard exact (hcard f ⟨hfB, hf⟩).elim rw [h, encard_singleton, encard_eq_one] at hcard obtain ⟨x, hx⟩ := hcard obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩ simp_rw [← h, ← singleton_union, ← hx, sdiff_sdiff_right_self, inf_eq_inter, inter_comm B, diff_union_inter] exact hB' theorem IsBase.exchange_isBase_of_indep' (hB : M.IsBase B) (he : e ∈ B) (hf : f ∉ B) (hI : M.Indep (insert f B \ {e})) : M.IsBase (insert f B \ {e}) := by have hfe : f ≠ e := ne_of_mem_of_not_mem he hf |>.symm rw [← insert_diff_singleton_comm hfe] at * exact hB.exchange_isBase_of_indep hf hI lemma insert_isBase_of_insert_indep {M : Matroid α} {I : Set α} {e f : α} (he : e ∉ I) (hf : f ∉ I) (heI : M.IsBase (insert e I)) (hfI : M.Indep (insert f I)) : M.IsBase (insert f I) := by obtain rfl | hef := eq_or_ne e f · assumption simpa [diff_singleton_eq_self he, hfI] using heI.exchange_isBase_of_indep (e := e) (f := f) (by simp [hef.symm, hf]) theorem IsBase.insert_dep (hB : M.IsBase B) (h : e ∈ M.E \ B) : M.Dep (insert e B) := by rw [← not_indep_iff (insert_subset h.1 hB.subset_ground)] exact h.2 ∘ (fun hi ↦ insert_eq_self.mp (hB.eq_of_subset_indep hi (subset_insert e B)).symm) theorem Indep.exists_insert_of_not_isBase (hI : M.Indep I) (hI' : ¬M.IsBase I) (hB : M.IsBase B) : ∃ e ∈ B \ I, M.Indep (insert e I) := by obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_superset obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB'))) by_cases hxB : x ∈ B · exact ⟨x, ⟨hxB, hx⟩, hB'.indep.subset (insert_subset hxB' hIB')⟩ obtain ⟨e,he, hBase⟩ := hB'.exchange hB ⟨hxB',hxB⟩ exact ⟨e, ⟨he.1, not_mem_subset hIB' he.2⟩, indep_iff.2 ⟨_, hBase, insert_subset_insert (subset_diff_singleton hIB' hx)⟩⟩ /-- This is the same as `Indep.exists_insert_of_not_isBase`, but phrased so that it is defeq to the augmentation axiom for independent sets. -/ theorem Indep.exists_insert_of_not_maximal (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I) (hInotmax : ¬ Maximal M.Indep I) (hB : Maximal M.Indep B) : ∃ x ∈ B \ I, M.Indep (insert x I) := by simp only [maximal_subset_iff, hI, not_and, not_forall, exists_prop, true_imp_iff] at hB hInotmax refine hI.exists_insert_of_not_isBase (fun hIb ↦ ?_) ?_ · obtain ⟨I', hII', hI', hne⟩ := hInotmax exact hne <| hIb.eq_of_subset_indep hII' hI' exact hB.1.isBase_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ theorem Indep.isBase_of_forall_insert (hB : M.Indep B) (hBmax : ∀ e ∈ M.E \ B, ¬ M.Indep (insert e B)) : M.IsBase B := by refine by_contra fun hnb ↦ ?_ obtain ⟨B', hB'⟩ := M.exists_isBase obtain ⟨e, he, h⟩ := hB.exists_insert_of_not_isBase hnb hB' exact hBmax e ⟨hB'.subset_ground he.1, he.2⟩ h theorem ground_indep_iff_isBase : M.Indep M.E ↔ M.IsBase M.E := ⟨fun h ↦ h.isBase_of_maximal (fun _ hJ hEJ ↦ hEJ.antisymm hJ.subset_ground), IsBase.indep⟩ theorem IsBase.exists_insert_of_ssubset (hB : M.IsBase B) (hIB : I ⊂ B) (hB' : M.IsBase B') : ∃ e ∈ B' \ I, M.Indep (insert e I) := (hB.indep.subset hIB.subset).exists_insert_of_not_isBase (fun hI ↦ hIB.ne (hI.eq_of_subset_isBase hB hIB.subset)) hB' @[ext] theorem ext_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ := have h' : M₁.Indep = M₂.Indep := by ext I by_cases hI : I ⊆ M₁.E · rwa [h] exact iff_of_false (fun hi ↦ hI hi.subset_ground) (fun hi ↦ hI (hi.subset_ground.trans_eq hE.symm)) ext_isBase hE (fun B _ ↦ by simp_rw [isBase_iff_maximal_indep, h']) @[deprecated (since := "2024-12-25")] alias eq_of_indep_iff_indep_forall := ext_indep theorem ext_iff_indep {M₁ M₂ : Matroid α} : M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) := ⟨fun h ↦ by (subst h; simp), fun h ↦ ext_indep h.1 h.2⟩ @[deprecated (since := "2024-12-25")] alias eq_iff_indep_iff_indep_forall := ext_iff_indep /-- If every base of `M₁` is independent in `M₂` and vice versa, then `M₁ = M₂`. -/ lemma ext_isBase_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (hM₁ : ∀ ⦃B⦄, M₁.IsBase B → M₂.Indep B) (hM₂ : ∀ ⦃B⦄, M₂.IsBase B → M₁.Indep B) : M₁ = M₂ := by refine ext_indep hE fun I hIE ↦ ⟨fun hI ↦ ?_, fun hI ↦ ?_⟩ · obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact (hM₁ hB).subset hIB obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact (hM₂ hB).subset hIB /-- A `Finitary` matroid is one where a set is independent if and only if it all its finite subsets are independent, or equivalently a matroid whose circuits are finite. -/ @[mk_iff] class Finitary (M : Matroid α) : Prop where /-- `I` is independent if all its finite subsets are independent. -/ indep_of_forall_finite : ∀ I, (∀ J, J ⊆ I → J.Finite → M.Indep J) → M.Indep I theorem indep_of_forall_finite_subset_indep {M : Matroid α} [Finitary M] (I : Set α) (h : ∀ J, J ⊆ I → J.Finite → M.Indep J) : M.Indep I := Finitary.indep_of_forall_finite I h theorem indep_iff_forall_finite_subset_indep {M : Matroid α} [Finitary M] : M.Indep I ↔ ∀ J, J ⊆ I → J.Finite → M.Indep J := ⟨fun h _ hJI _ ↦ h.subset hJI, Finitary.indep_of_forall_finite I⟩ instance finitary_of_rankFinite {M : Matroid α} [RankFinite M] : Finitary M where indep_of_forall_finite I hI := by refine I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_) obtain ⟨B, hB⟩ := M.exists_isBase obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1) obtain ⟨B', hB', hI₀B'⟩ := (hI _ hI₀I hI₀fin).exists_isBase_superset have hle := ncard_le_ncard hI₀B' hB'.finite rw [hI₀card, hB'.ncard_eq_ncard_of_isBase hB, Nat.add_one_le_iff] at hle exact hle.ne rfl /-- Matroids obey the maximality axiom -/ theorem existsMaximalSubsetProperty_indep (M : Matroid α) : ∀ X, X ⊆ M.E → ExistsMaximalSubsetProperty M.Indep X := M.maximality end dep_indep section copy /-- create a copy of `M : Matroid α` with independence and base predicates and ground set defeq to supplied arguments that are provably equal to those of `M`. -/ @[simps] def copy (M : Matroid α) (E : Set α) (IsBase Indep : Set α → Prop) (hE : E = M.E) (hB : ∀ B, IsBase B ↔ M.IsBase B) (hI : ∀ I, Indep I ↔ M.Indep I) : Matroid α where E := E IsBase := IsBase Indep := Indep indep_iff' _ := by simp_rw [hI, hB, M.indep_iff] exists_isBase := by simp_rw [hB] exact M.exists_isBase isBase_exchange := by simp_rw [show IsBase = M.IsBase from funext (by simp [hB])] exact M.isBase_exchange maximality := by simp_rw [hE, show Indep = M.Indep from funext (by simp [hI])] exact M.maximality subset_ground := by simp_rw [hE, hB] exact M.subset_ground /-- create a copy of `M : Matroid α` with an independence predicate and ground set defeq to supplied arguments that are provably equal to those of `M`. -/ @[simps!] def copyIndep (M : Matroid α) (E : Set α) (Indep : Set α → Prop) (hE : E = M.E) (h : ∀ I, Indep I ↔ M.Indep I) : Matroid α := M.copy E M.IsBase Indep hE (fun _ ↦ Iff.rfl) h /-- create a copy of `M : Matroid α` with a base predicate and ground set defeq to supplied arguments that are provably equal to those of `M`. -/ @[simps!] def copyBase (M : Matroid α) (E : Set α) (IsBase : Set α → Prop) (hE : E = M.E) (h : ∀ B, IsBase B ↔ M.IsBase B) : Matroid α := M.copy E IsBase M.Indep hE h (fun _ ↦ Iff.rfl) end copy section IsBasis /-- A Basis for a set `X ⊆ M.E` is a maximal independent subset of `X` (Often in the literature, the word 'Basis' is used to refer to what we call a 'Base'). -/ def IsBasis (M : Matroid α) (I X : Set α) : Prop := Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I ∧ X ⊆ M.E @[deprecated (since := "2025-02-14")] alias Basis := IsBasis /-- `Matroid.IsBasis' I X` is the same as `Matroid.IsBasis I X`, without the requirement that `X ⊆ M.E`. This is convenient for some API building, especially when working with rank and closure. -/ def IsBasis' (M : Matroid α) (I X : Set α) : Prop := Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I @[deprecated (since := "2025-02-14")] alias Basis' := IsBasis' variable {B I J X Y : Set α} {e : α} theorem IsBasis'.indep (hI : M.IsBasis' I X) : M.Indep I := hI.1.1 theorem IsBasis.indep (hI : M.IsBasis I X) : M.Indep I := hI.1.1.1 theorem IsBasis.subset (hI : M.IsBasis I X) : I ⊆ X := hI.1.1.2 theorem IsBasis.isBasis' (hI : M.IsBasis I X) : M.IsBasis' I X := hI.1 theorem IsBasis'.isBasis (hI : M.IsBasis' I X) (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X := ⟨hI, hX⟩ theorem IsBasis'.subset (hI : M.IsBasis' I X) : I ⊆ X := hI.1.2 @[aesop unsafe 15% (rule_sets := [Matroid])] theorem IsBasis.subset_ground (hI : M.IsBasis I X) : X ⊆ M.E := hI.2 theorem IsBasis.isBasis_inter_ground (hI : M.IsBasis I X) : M.IsBasis I (X ∩ M.E) := by convert hI rw [inter_eq_self_of_subset_left hI.subset_ground] @[aesop unsafe 15% (rule_sets := [Matroid])] theorem IsBasis.left_subset_ground (hI : M.IsBasis I X) : I ⊆ M.E := hI.indep.subset_ground theorem IsBasis.eq_of_subset_indep (hI : M.IsBasis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) : I = J := hIJ.antisymm (hI.1.2 ⟨hJ, hJX⟩ hIJ) theorem IsBasis.Finite (hI : M.IsBasis I X) [RankFinite M] : I.Finite := hI.indep.finite theorem isBasis_iff' : M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by rw [IsBasis, maximal_subset_iff] tauto theorem isBasis_iff (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) := by rw [isBasis_iff', and_iff_left hX] theorem isBasis'_iff_isBasis_inter_ground : M.IsBasis' I X ↔ M.IsBasis I (X ∩ M.E) := by rw [IsBasis', IsBasis, and_iff_left inter_subset_right, maximal_iff_maximal_of_imp_of_forall] · exact fun I hI ↦ ⟨hI.1, hI.2.trans inter_subset_left⟩ exact fun I hI ↦ ⟨I, rfl.le, hI.1, subset_inter hI.2 hI.1.subset_ground⟩ theorem isBasis'_iff_isBasis (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis' I X ↔ M.IsBasis I X := by rw [isBasis'_iff_isBasis_inter_ground, inter_eq_self_of_subset_left hX] theorem isBasis_iff_isBasis'_subset_ground : M.IsBasis I X ↔ M.IsBasis' I X ∧ X ⊆ M.E := ⟨fun h ↦ ⟨h.isBasis', h.subset_ground⟩, fun h ↦ (isBasis'_iff_isBasis h.2).mp h.1⟩ theorem IsBasis'.isBasis_inter_ground (hIX : M.IsBasis' I X) : M.IsBasis I (X ∩ M.E) := isBasis'_iff_isBasis_inter_ground.mp hIX theorem IsBasis'.eq_of_subset_indep (hI : M.IsBasis' I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) : I = J := hIJ.antisymm (hI.2 ⟨hJ, hJX⟩ hIJ) theorem IsBasis'.insert_not_indep (hI : M.IsBasis' I X) (he : e ∈ X \ I) : ¬ M.Indep (insert e I) := fun hi ↦ he.2 <| insert_eq_self.1 <| Eq.symm <| hI.eq_of_subset_indep hi (subset_insert _ _) (insert_subset he.1 hI.subset) theorem isBasis_iff_maximal (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X ↔ Maximal (fun I ↦ M.Indep I ∧ I ⊆ X) I := by rw [IsBasis, and_iff_left hX] theorem Indep.isBasis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X) (hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X := by rw [isBasis_iff (by aesop_mat : X ⊆ M.E), and_iff_right hI, and_iff_right hIX] exact fun J hJ hIJ hJX ↦ hIJ.antisymm (hmax hJ hIJ hJX) theorem IsBasis.isBasis_subset (hI : M.IsBasis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) : M.IsBasis I Y := by rw [isBasis_iff (hYX.trans hI.subset_ground), and_iff_right hI.indep, and_iff_right hIY] exact fun J hJ hIJ hJY ↦ hI.eq_of_subset_indep hJ hIJ (hJY.trans hYX) @[simp] theorem isBasis_self_iff_indep : M.IsBasis I I ↔ M.Indep I := by rw [isBasis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp] exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩ theorem Indep.isBasis_self (h : M.Indep I) : M.IsBasis I I := isBasis_self_iff_indep.mpr h @[simp] theorem isBasis_empty_iff (M : Matroid α) : M.IsBasis I ∅ ↔ I = ∅ := ⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; exact M.empty_indep.isBasis_self)⟩ theorem IsBasis.dep_of_ssubset (hI : M.IsBasis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by have : X ⊆ M.E := hI.subset_ground rw [← not_indep_iff] exact fun hY ↦ hIY.ne (hI.eq_of_subset_indep hY hIY.subset hYX) theorem IsBasis.insert_dep (hI : M.IsBasis I X) (he : e ∈ X \ I) : M.Dep (insert e I) := hI.dep_of_ssubset (ssubset_insert he.2) (insert_subset he.1 hI.subset) theorem IsBasis.mem_of_insert_indep (hI : M.IsBasis I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) : e ∈ I := by_contra (fun heI ↦ (hI.insert_dep ⟨he, heI⟩).not_indep hIe) theorem IsBasis'.mem_of_insert_indep (hI : M.IsBasis' I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) : e ∈ I := hI.isBasis_inter_ground.mem_of_insert_indep ⟨he, hIe.subset_ground (mem_insert _ _)⟩ hIe theorem IsBasis.not_isBasis_of_ssubset (hI : M.IsBasis I X) (hJI : J ⊂ I) : ¬ M.IsBasis J X := fun h ↦ hJI.ne (h.eq_of_subset_indep hI.indep hJI.subset hI.subset) theorem Indep.subset_isBasis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J X ∧ I ⊆ J := by obtain ⟨J, hJ, hJmax⟩ := M.maximality X hX I hI hIX exact ⟨J, ⟨hJmax, hX⟩, hJ⟩ theorem Indep.subset_isBasis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) : ∃ J, M.IsBasis' J X ∧ I ⊆ J := by simp_rw [isBasis'_iff_isBasis_inter_ground] exact hI.subset_isBasis_of_subset (subset_inter hIX hI.subset_ground)
Mathlib/Data/Matroid/Basic.lean
948
951
theorem exists_isBasis (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by
aesop_mat) : ∃ I, M.IsBasis I X := let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis_of_subset (empty_subset X) ⟨_, hI⟩