Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Limits and asymptotics of power functions at `+∞` This file contains results about the limiting behaviour of power functions at `+∞`. For convenience some results on asymptotics as `x → 0` (those which are not just continuity statements) are also located here. -/ noncomputable section open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set /-! ## Limits at `+∞` -/ section Limits open Real Filter /-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by rw [(atTop_basis' 0).tendsto_right_iff] intro b hb filter_upwards [eventually_ge_atTop 0, eventually_ge_atTop (b ^ (1 / y))] with x hx₀ hx simpa (disch := positivity) [Real.rpow_inv_le_iff_of_pos] using hx /-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_neg_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ (-y)) atTop (𝓝 0) := Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop 0) fun _ hx => (rpow_neg (le_of_lt hx) y).symm) (tendsto_rpow_atTop hy).inv_tendsto_atTop open Asymptotics in lemma tendsto_rpow_atTop_of_base_lt_one (b : ℝ) (hb₀ : -1 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atTop (𝓝 (0 : ℝ)) := by rcases lt_trichotomy b 0 with hb|rfl|hb case inl => -- b < 0 simp_rw [Real.rpow_def_of_nonpos hb.le, hb.ne, ite_false] rw [← isLittleO_const_iff (c := (1 : ℝ)) one_ne_zero, (one_mul (1 : ℝ)).symm] refine IsLittleO.mul_isBigO ?exp ?cos case exp => rw [isLittleO_const_iff one_ne_zero] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id rw [← log_neg_eq_log, log_neg_iff (by linarith)] linarith case cos => rw [isBigO_iff] exact ⟨1, Eventually.of_forall fun x => by simp [Real.abs_cos_le_one]⟩ case inr.inl => -- b = 0 refine Tendsto.mono_right ?_ (Iff.mpr pure_le_nhds_iff rfl) rw [tendsto_pure] filter_upwards [eventually_ne_atTop 0] with _ hx simp [hx] case inr.inr => -- b > 0 simp_rw [Real.rpow_def_of_pos hb] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id exact (log_neg_iff hb).mpr hb₁ lemma tendsto_rpow_atTop_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 (0 : ℝ)) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_pos ?_).mpr tendsto_id exact (log_pos_iff (by positivity)).mpr <| by aesop lemma tendsto_rpow_atBot_of_base_lt_one (b : ℝ) (hb₀ : 0 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atBot atTop := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atTop.comp <| (tendsto_const_mul_atTop_iff_neg <| tendsto_id (α := ℝ)).mpr ?_ exact (log_neg_iff hb₀).mpr hb₁ lemma tendsto_rpow_atBot_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 0) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_iff_pos <| tendsto_id (α := ℝ)).mpr ?_ exact (log_pos_iff (by positivity)).mpr <| by aesop /-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and `c` such that `b` is nonzero. -/ theorem tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 ≠ b) : Tendsto (fun x => x ^ (a / (b * x + c))) atTop (𝓝 1) := by refine Tendsto.congr' ?_ ((tendsto_exp_nhds_zero_nhds_one.comp (by simpa only [mul_zero, pow_one] using (tendsto_const_nhds (x := a)).mul (tendsto_div_pow_mul_exp_add_atTop b c 1 hb))).comp tendsto_log_atTop) apply eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) intro x hx simp only [Set.mem_Ioi, Function.comp_apply] at hx ⊢ rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))] field_simp /-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_div : Tendsto (fun x => x ^ ((1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (1 : ℝ) _ (0 : ℝ) zero_ne_one ring /-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_neg_div : Tendsto (fun x => x ^ (-(1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (-(1 : ℝ)) _ (0 : ℝ) zero_ne_one ring /-- The function `exp(x) / x ^ s` tends to `+∞` at `+∞`, for any real number `s`. -/ theorem tendsto_exp_div_rpow_atTop (s : ℝ) : Tendsto (fun x : ℝ => exp x / x ^ s) atTop atTop := by obtain ⟨n, hn⟩ := archimedean_iff_nat_lt.1 Real.instArchimedean s refine tendsto_atTop_mono' _ ?_ (tendsto_exp_div_pow_atTop n) filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_ge_atTop (1 : ℝ)] with x hx₀ hx₁ gcongr simpa using rpow_le_rpow_of_exponent_le hx₁ hn.le /-- The function `exp (b * x) / x ^ s` tends to `+∞` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_exp_mul_div_rpow_atTop (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => exp (b * x) / x ^ s) atTop atTop := by refine ((tendsto_rpow_atTop hb).comp (tendsto_exp_div_rpow_atTop (s / b))).congr' ?_ filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx₀ simp [Real.div_rpow, (exp_pos x).le, rpow_nonneg, ← Real.rpow_mul, ← exp_mul, mul_comm x, hb.ne', *] /-- The function `x ^ s * exp (-b * x)` tends to `0` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => x ^ s * exp (-b * x)) atTop (𝓝 0) := by refine (tendsto_exp_mul_div_rpow_atTop s b hb).inv_tendsto_atTop.congr' ?_ filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)] nonrec theorem NNReal.tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0 => x ^ y) atTop atTop := by rw [Filter.tendsto_atTop_atTop] intro b obtain ⟨c, hc⟩ := tendsto_atTop_atTop.mp (tendsto_rpow_atTop hy) b use c.toNNReal intro a ha exact mod_cast hc a (Real.toNNReal_le_iff_le_coe.mp ha) theorem ENNReal.tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0∞ => x ^ y) (𝓝 ⊤) (𝓝 ⊤) := by rw [ENNReal.tendsto_nhds_top_iff_nnreal] intro x obtain ⟨c, _, hc⟩ := (atTop_basis_Ioi.tendsto_iff atTop_basis_Ioi).mp (NNReal.tendsto_rpow_atTop hy) x trivial have hc' : Set.Ioi ↑c ∈ 𝓝 (⊤ : ℝ≥0∞) := Ioi_mem_nhds ENNReal.coe_lt_top filter_upwards [hc'] with a ha by_cases ha' : a = ⊤ · simp [ha', hy] lift a to ℝ≥0 using ha' simp only [Set.mem_Ioi, coe_lt_coe] at ha hc rw [← ENNReal.coe_rpow_of_nonneg _ hy.le] exact mod_cast hc a ha end Limits /-! ## Asymptotic results: `IsBigO`, `IsLittleO` and `IsTheta` -/ namespace Complex section variable {α : Type*} {l : Filter α} {f g : α → ℂ} open Asymptotics theorem isTheta_exp_arg_mul_im (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) : (fun x => Real.exp (arg (f x) * im (g x))) =Θ[l] fun _ => (1 : ℝ) := by rcases hl with ⟨b, hb⟩ refine Real.isTheta_exp_comp_one.2 ⟨π * b, ?_⟩ rw [eventually_map] at hb ⊢ refine hb.mono fun x hx => ?_ rw [abs_mul] exact mul_le_mul (abs_arg_le_pi _) hx (abs_nonneg _) Real.pi_pos.le theorem isBigO_cpow_rpow (hl : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) : (fun x => f x ^ g x) =O[l] fun x => ‖f x‖ ^ (g x).re := calc (fun x => f x ^ g x) =O[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re / Real.exp (arg (f x) * im (g x))) := isBigO_of_le _ fun _ => (norm_cpow_le _ _).trans (le_abs_self _) _ =Θ[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re / (1 : ℝ)) := ((isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl)) _ =ᶠ[l] (show α → ℝ from fun x => ‖f x‖ ^ (g x).re) := by simp only [ofReal_one, div_one, EventuallyEq.rfl] theorem isTheta_cpow_rpow (hl_im : IsBoundedUnder (· ≤ ·) l fun x => |(g x).im|) (hl : ∀ᶠ x in l, f x = 0 → re (g x) = 0 → g x = 0) : (fun x => f x ^ g x) =Θ[l] fun x => ‖f x‖ ^ (g x).re := calc (fun x => f x ^ g x) =Θ[l] (fun x => ‖f x‖ ^ (g x).re / Real.exp (arg (f x) * im (g x))) := .of_norm_eventuallyEq <| hl.mono fun _ => norm_cpow_of_imp _ =Θ[l] fun x => ‖f x‖ ^ (g x).re / (1 : ℝ) := (isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl_im) _ =ᶠ[l] (fun x => ‖f x‖ ^ (g x).re) := by simp only [ofReal_one, div_one, EventuallyEq.rfl] theorem isTheta_cpow_const_rpow {b : ℂ} (hl : b.re = 0 → b ≠ 0 → ∀ᶠ x in l, f x ≠ 0) : (fun x => f x ^ b) =Θ[l] fun x => ‖f x‖ ^ b.re := isTheta_cpow_rpow isBoundedUnder_const <| by simpa only [eventually_imp_distrib_right, not_imp_not, Imp.swap (a := b.re = 0)] using hl end end Complex open Real namespace Asymptotics variable {α : Type*} {r c : ℝ} {l : Filter α} {f g : α → ℝ} theorem IsBigOWith.rpow (h : IsBigOWith c l f g) (hc : 0 ≤ c) (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) : IsBigOWith (c ^ r) l (fun x => f x ^ r) fun x => g x ^ r := by apply IsBigOWith.of_bound filter_upwards [hg, h.bound] with x hgx hx calc |f x ^ r| ≤ |f x| ^ r := abs_rpow_le_abs_rpow _ _ _ ≤ (c * |g x|) ^ r := rpow_le_rpow (abs_nonneg _) hx hr _ = c ^ r * |g x ^ r| := by rw [mul_rpow hc (abs_nonneg _), abs_rpow_of_nonneg hgx] theorem IsBigO.rpow (hr : 0 ≤ r) (hg : 0 ≤ᶠ[l] g) (h : f =O[l] g) : (fun x => f x ^ r) =O[l] fun x => g x ^ r := let ⟨_, hc, h'⟩ := h.exists_nonneg (h'.rpow hc hr hg).isBigO theorem IsTheta.rpow (hr : 0 ≤ r) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) (h : f =Θ[l] g) : (fun x => f x ^ r) =Θ[l] fun x => g x ^ r := ⟨h.1.rpow hr hg, h.2.rpow hr hf⟩ theorem IsLittleO.rpow (hr : 0 < r) (hg : 0 ≤ᶠ[l] g) (h : f =o[l] g) : (fun x => f x ^ r) =o[l] fun x => g x ^ r := by refine .of_isBigOWith fun c hc ↦ ?_ rw [← rpow_inv_rpow hc.le hr.ne'] refine (h.forall_isBigOWith ?_).rpow ?_ ?_ hg <;> positivity protected lemma IsBigO.sqrt (hfg : f =O[l] g) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =O[l] (Real.sqrt <| g ·) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos.le hg protected lemma IsLittleO.sqrt (hfg : f =o[l] g) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =o[l] (Real.sqrt <| g ·) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos hg protected lemma IsTheta.sqrt (hfg : f =Θ[l] g) (hf : 0 ≤ᶠ[l] f) (hg : 0 ≤ᶠ[l] g) : (Real.sqrt <| f ·) =Θ[l] (Real.sqrt <| g ·) := ⟨hfg.1.sqrt hg, hfg.2.sqrt hf⟩ theorem isBigO_atTop_natCast_rpow_of_tendsto_div_rpow {𝕜 : Type*} [RCLike 𝕜] {g : ℕ → 𝕜} {a : 𝕜} {r : ℝ} (hlim : Tendsto (fun n ↦ g n / (n ^ r : ℝ)) atTop (𝓝 a)) : g =O[atTop] fun n ↦ (n : ℝ) ^ r := by refine (isBigO_of_div_tendsto_nhds ?_ ‖a‖ ?_).of_norm_left · filter_upwards [eventually_ne_atTop 0] with _ h simp [Real.rpow_eq_zero_iff_of_nonneg, h] · exact hlim.norm.congr fun n ↦ by simp [abs_of_nonneg, show 0 ≤ (n : ℝ) ^ r by positivity] variable {E : Type*} [SeminormedRing E] (a b c : ℝ) theorem IsBigO.mul_atTop_rpow_of_isBigO_rpow {f g : ℝ → E} (hf : f =O[atTop] fun t ↦ (t : ℝ) ^ a) (hg : g =O[atTop] fun t ↦ (t : ℝ) ^ b) (h : a + b ≤ c) : (f * g) =O[atTop] fun t ↦ (t : ℝ) ^ c := by refine (hf.mul hg).trans (Eventually.isBigO ?_) filter_upwards [eventually_ge_atTop 1] with t ht rw [← Real.rpow_add (zero_lt_one.trans_le ht), Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans ht) (a + b))] exact Real.rpow_le_rpow_of_exponent_le ht h theorem IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow {f g : ℕ → E} (hf : f =O[atTop] fun n ↦ (n : ℝ) ^ a) (hg : g =O[atTop] fun n ↦ (n : ℝ) ^ b) (h : a + b ≤ c) : (f * g) =O[atTop] fun n ↦ (n : ℝ) ^ c := by refine (hf.mul hg).trans (Eventually.isBigO ?_) filter_upwards [eventually_ge_atTop 1] with t ht replace ht : 1 ≤ (t : ℝ) := Nat.one_le_cast.mpr ht rw [← Real.rpow_add (zero_lt_one.trans_le ht), Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans ht) (a + b))] exact Real.rpow_le_rpow_of_exponent_le ht h
end Asymptotics
Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
290
292
/- 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.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg fun _ hx => hx.1.le theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff₀ hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · convert convex_empty (𝕜 := ℝ) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun _ hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le₀ hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] section LinearOrderedField variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ] theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) : gauge (a • s) = a⁻¹ • gauge s := by obtain rfl | ha' := ha.eq_or_lt · rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] ext x rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, y, hy, h⟩ simp_rw [mem_Ioi] at hr ⊢ refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩ rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne'] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩ rw [smul_inv₀, smul_assoc, inv_inv] theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) : gauge (a • s) = |a|⁻¹ • gauge s := by rw [← gauge_smul_left_of_nonneg (abs_nonneg a)] obtain h | h := abs_choice a · rw [h] · rw [h, Set.neg_smul_set, ← Set.smul_set_neg] -- Porting note: was congr apply congr_arg apply congr_arg ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy end LinearOrderedField section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (‖r‖ • x) = gauge s (r • x) := by unfold gauge congr with θ rw [@RCLike.real_smul_eq_coe_smul 𝕜] refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] /-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/ theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩ have hrc := (lt_inv_comm₀ hr₀ hc₀).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smul₀ hc₀.ne'] variable [T1Space E] theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩ have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩ exact hr (by simpa [h₀]) rfl theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : 0 < gauge s x ↔ x ≠ 0 := by simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb] end TopologicalSpace section ContinuousSMul variable [TopologicalSpace E] [ContinuousSMul ℝ E] open Filter in theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by intro x hx have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) := ((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left rw [inv_one, one_smul] at H₁ have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsLT one_pos] with r h₁ h₂ exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩ rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩ exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁ theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) : { x | gauge s x < 1 } = s := by refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_ convert interior_subset_gauge_lt_one s exact hs₂.interior_eq.symm theorem gauge_lt_one_of_mem_of_isOpen (hs₂ : IsOpen s) {x : E} (hx : x ∈ s) : gauge s x < 1 := interior_subset_gauge_lt_one s <| by rwa [hs₂.interior_eq] theorem gauge_lt_of_mem_smul (x : E) (ε : ℝ) (hε : 0 < ε) (hs₂ : IsOpen s) (hx : x ∈ ε • s) : gauge s x < ε := by have : ε⁻¹ • x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_mem₀ hε.ne'] have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hs₂ this rwa [gauge_smul_of_nonneg (inv_nonneg.2 hε.le), smul_eq_mul, inv_mul_lt_iff₀ hε, mul_one] at h_gauge_lt theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x ≤ 1) : x ∈ closure s := by have : ∀ᶠ r : ℝ in 𝓝[<] 1, r • x ∈ s := by filter_upwards [Ico_mem_nhdsLT one_pos] with r ⟨hr₀, hr₁⟩ apply gauge_lt_one_subset_self hc hs₀ ha rw [mem_setOf_eq, gauge_smul_of_nonneg hr₀] exact mul_lt_one_of_nonneg_of_lt_one_left hr₀ hr₁ h refine mem_closure_of_tendsto ?_ this exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _)) inf_le_left theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x = 1) : x ∈ frontier s := ⟨mem_closure_of_gauge_le_one hc hs₀ ha h.le, fun h' ↦ (interior_subset_gauge_lt_one s h').out.ne h⟩ theorem tendsto_gauge_nhds_zero_nhdsGE (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[≥] 0) := by refine nhdsGE_basis_Icc.tendsto_right_iff.2 fun ε hε ↦ ?_ rw [← set_smul_mem_nhds_zero_iff hε.ne'] at hs filter_upwards [hs] with x hx exact ⟨gauge_nonneg _, gauge_le_of_mem hε.le hx⟩ @[deprecated (since := "2025-03-02")] alias tendsto_gauge_nhds_zero' := tendsto_gauge_nhds_zero_nhdsGE theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) := (tendsto_gauge_nhds_zero_nhdsGE hs).mono_right inf_le_left /-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin. See also `continuousAt_gauge`. -/ theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by rw [ContinuousAt, gauge_zero] exact tendsto_gauge_nhds_zero hs theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (h₀ : s ∈ 𝓝 0) : comap (gauge s) (𝓝 0) = 𝓝 0 := (comap_gauge_nhds_zero_le (absorbent_nhds_zero h₀) hb).antisymm (tendsto_gauge_nhds_zero h₀).le_comap end ContinuousSMul section TopologicalVectorSpace open Filter variable [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ theorem continuousAt_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by have ha : Absorbent ℝ s := absorbent_nhds_zero hs₀ refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun ε hε₀ ↦ ?_ rw [← map_add_left_nhds_zero, eventually_map] have : ε • s ∩ -(ε • s) ∈ 𝓝 0 := inter_mem ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀) (neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀)) filter_upwards [this] with y hy constructor · rw [sub_le_iff_le_add] calc gauge s x = gauge s (x + y + (-y)) := by simp _ ≤ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _ _ ≤ gauge s (x + y) + ε := add_le_add_left (gauge_le_of_mem hε₀.le (mem_neg.1 hy.2)) _ · calc gauge s (x + y) ≤ gauge s x + gauge s y := gauge_add_le hc ha _ _ _ ≤ gauge s x + ε := add_le_add_left (gauge_le_of_mem hε₀.le hy.1) _ /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ @[continuity] theorem continuous_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : Continuous (gauge s) := continuous_iff_continuousAt.2 fun _ ↦ continuousAt_gauge hc hs₀ theorem gauge_lt_one_eq_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : { x | gauge s x < 1 } = interior s := by refine Subset.antisymm (fun x hx ↦ ?_) (interior_subset_gauge_lt_one s) rcases mem_openSegment_of_gauge_lt_one (absorbent_nhds_zero hs₀) hx with ⟨y, hys, hxy⟩ exact hc.openSegment_interior_self_subset_interior (mem_interior_iff_mem_nhds.2 hs₀) hys hxy theorem gauge_lt_one_iff_mem_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x < 1 ↔ x ∈ interior s := Set.ext_iff.1 (gauge_lt_one_eq_interior hc hs₀) _ theorem gauge_le_one_iff_mem_closure (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x ≤ 1 ↔ x ∈ closure s := ⟨mem_closure_of_gauge_le_one hc (mem_of_mem_nhds hs₀) (absorbent_nhds_zero hs₀), fun h ↦ le_on_closure (fun _ ↦ gauge_le_one_of_mem) (continuous_gauge hc hs₀).continuousOn continuousOn_const h⟩ theorem gauge_eq_one_iff_mem_frontier (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x = 1 ↔ x ∈ frontier s := by rw [eq_iff_le_not_lt, gauge_le_one_iff_mem_closure hc hs₀, gauge_lt_one_iff_mem_interior hc hs₀] rfl end TopologicalVectorSpace section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] /-- `gauge s` as a seminorm when `s` is balanced, convex and absorbent. -/ @[simps!] def gaugeSeminorm (hs₀ : Balanced 𝕜 s) (hs₁ : Convex ℝ s) (hs₂ : Absorbent ℝ s) : Seminorm 𝕜 E := Seminorm.of (gauge s) (gauge_add_le hs₁ hs₂) (gauge_smul hs₀) variable {hs₀ : Balanced 𝕜 s} {hs₁ : Convex ℝ s} {hs₂ : Absorbent ℝ s} [TopologicalSpace E] [ContinuousSMul ℝ E] theorem gaugeSeminorm_lt_one_of_isOpen (hs : IsOpen s) {x : E} (hx : x ∈ s) : gaugeSeminorm hs₀ hs₁ hs₂ x < 1 := gauge_lt_one_of_mem_of_isOpen hs hx theorem gaugeSeminorm_ball_one (hs : IsOpen s) : (gaugeSeminorm hs₀ hs₁ hs₂).ball 0 1 = s := by rw [Seminorm.ball_zero_eq] exact gauge_lt_one_eq_self_of_isOpen hs₁ hs₂.zero_mem hs end RCLike /-- Any seminorm arises as the gauge of its unit ball. -/ @[simp] protected theorem Seminorm.gauge_ball (p : Seminorm ℝ E) : gauge (p.ball 0 1) = p := by ext x obtain hp | hp := { r : ℝ | 0 < r ∧ x ∈ r • p.ball 0 1 }.eq_empty_or_nonempty · rw [gauge, hp, Real.sInf_empty] by_contra h have hpx : 0 < p x := (apply_nonneg _ _).lt_of_ne h have hpx₂ : 0 < 2 * p x := mul_pos zero_lt_two hpx refine hp.subset ⟨hpx₂, (2 * p x)⁻¹ • x, ?_, smul_inv_smul₀ hpx₂.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx₂), inv_mul_lt_iff₀ hpx₂, mul_one] exact lt_mul_of_one_lt_left hpx one_lt_two refine IsGLB.csInf_eq ⟨fun r => ?_, fun r hr => le_of_forall_pos_le_add fun ε hε => ?_⟩ hp · rintro ⟨hr, y, hy, rfl⟩ rw [p.mem_ball_zero] at hy rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos hr] exact mul_le_of_le_one_right hr.le hy.le · have hpε : 0 < p x + ε := by positivity refine hr ⟨hpε, (p x + ε)⁻¹ • x, ?_, smul_inv_smul₀ hpε.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpε), inv_mul_lt_iff₀ hpε, mul_one] exact lt_add_of_pos_right _ hε theorem Seminorm.gaugeSeminorm_ball (p : Seminorm ℝ E) : gaugeSeminorm (p.balanced_ball_zero 1) (p.convex_ball 0 1) (p.absorbent_ball_zero zero_lt_one) = p := DFunLike.coe_injective p.gauge_ball end AddCommGroup section Seminormed variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E} open Metric theorem gauge_unit_ball (x : E) : gauge (ball (0 : E) 1) x = ‖x‖ := by rw [← ball_normSeminorm ℝ, Seminorm.gauge_ball, coe_normSeminorm] theorem gauge_ball (hr : 0 ≤ r) (x : E) : gauge (ball (0 : E) r) x = ‖x‖ / r := by rcases hr.eq_or_lt with rfl | hr · simp · rw [← smul_unitBall_of_pos hr, gauge_smul_left, Pi.smul_apply, gauge_unit_ball, smul_eq_mul, abs_of_nonneg hr.le, div_eq_inv_mul] simp_rw [mem_ball_zero_iff, norm_neg] exact fun _ => id @[simp] theorem gauge_closure_zero : gauge (closure (0 : Set E)) = 0 := funext fun x ↦ by simp only [← singleton_zero, gauge_def', mem_closure_zero_iff_norm, norm_smul, mul_eq_zero, norm_eq_zero, inv_eq_zero] rcases (norm_nonneg x).eq_or_gt with hx | hx · convert csInf_Ioi (a := (0 : ℝ)) exact Set.ext fun r ↦ and_iff_left (.inr hx) · convert Real.sInf_empty exact eq_empty_of_forall_not_mem fun r ⟨hr₀, hr⟩ ↦ hx.ne' <| hr.resolve_left hr₀.out.ne' @[simp] theorem gauge_closedBall (hr : 0 ≤ r) (x : E) : gauge (closedBall (0 : E) r) x = ‖x‖ / r := by rcases hr.eq_or_lt with rfl | hr' · rw [div_zero, closedBall_zero', singleton_zero, gauge_closure_zero]; rfl · apply le_antisymm · rw [← gauge_ball hr] exact gauge_mono (absorbent_ball_zero hr') ball_subset_closedBall x · suffices ∀ᶠ R in 𝓝[>] r, ‖x‖ / R ≤ gauge (closedBall 0 r) x by refine le_of_tendsto ?_ this exact tendsto_const_nhds.div inf_le_left hr'.ne' filter_upwards [self_mem_nhdsWithin] with R hR rw [← gauge_ball (hr.trans hR.out.le)] refine gauge_mono ?_ (closedBall_subset_ball hR) _ exact (absorbent_ball_zero hr').mono ball_subset_closedBall theorem mul_gauge_le_norm (hs : Metric.ball (0 : E) r ⊆ s) : r * gauge s x ≤ ‖x‖ := by obtain hr | hr := le_or_lt r 0 · exact (mul_nonpos_of_nonpos_of_nonneg hr <| gauge_nonneg _).trans (norm_nonneg _) rw [mul_comm, ← le_div_iff₀ hr, ← gauge_ball hr.le] exact gauge_mono (absorbent_ball_zero hr) hs x theorem Convex.lipschitzWith_gauge {r : ℝ≥0} (hc : Convex ℝ s) (hr : 0 < r) (hs : Metric.ball (0 : E) r ⊆ s) : LipschitzWith r⁻¹ (gauge s) := have : Absorbent ℝ (Metric.ball (0 : E) r) := absorbent_ball_zero hr LipschitzWith.of_le_add_mul _ fun x y => calc gauge s x = gauge s (y + (x - y)) := by simp _ ≤ gauge s y + gauge s (x - y) := gauge_add_le hc (this.mono hs) _ _ _ ≤ gauge s y + ‖x - y‖ / r := add_le_add_left ((gauge_mono this hs (x - y)).trans_eq (gauge_ball hr.le _)) _ _ = gauge s y + r⁻¹ * dist x y := by rw [dist_eq_norm, div_eq_inv_mul, NNReal.coe_inv] theorem Convex.lipschitz_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) : ∃ K, LipschitzWith K (gauge s) := let ⟨r, hr₀, hr⟩ := Metric.mem_nhds_iff.1 h₀ ⟨(⟨r, hr₀.le⟩ : ℝ≥0)⁻¹, hc.lipschitzWith_gauge hr₀ hr⟩ theorem Convex.uniformContinuous_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) : UniformContinuous (gauge s) := let ⟨_K, hK⟩ := hc.lipschitz_gauge h₀; hK.uniformContinuous end Seminormed section Normed variable [NormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E} open Metric theorem le_gauge_of_subset_closedBall (hs : Absorbent ℝ s) (hr : 0 ≤ r) (hsr : s ⊆ closedBall 0 r) : ‖x‖ / r ≤ gauge s x := by rw [← gauge_closedBall hr] exact gauge_mono hs hsr _ end Normed
Mathlib/Analysis/Convex/Gauge.lean
621
630
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Joël Riou -/ import Mathlib.CategoryTheory.ConcreteCategory.Basic import Mathlib.CategoryTheory.Shift.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Algebra.Group.Int.Defs /-! # The category of graded objects For any type `β`, a `β`-graded object over some category `C` is just a function `β → C` into the objects of `C`. We put the "pointwise" category structure on these, as the non-dependent specialization of `CategoryTheory.Pi`. We describe the `comap` functors obtained by precomposing with functions `β → γ`. As a consequence a fixed element (e.g. `1`) in an additive group `β` provides a shift functor on `β`-graded objects When `C` has coproducts we construct the `total` functor `GradedObject β C ⥤ C`, show that it is faithful, and deduce that when `C` is concrete so is `GradedObject β C`. A covariant functoriality of `GradedObject β C` with respect to the index set `β` is also introduced: if `p : I → J` is a map such that `C` has coproducts indexed by `p ⁻¹' {j}`, we have a functor `map : GradedObject I C ⥤ GradedObject J C`. -/ namespace CategoryTheory open Category Limits universe w v u /-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`. -/ def GradedObject (β : Type w) (C : Type u) : Type max w u := β → C -- Satisfying the inhabited linter... instance inhabitedGradedObject (β : Type w) (C : Type u) [Inhabited C] : Inhabited (GradedObject β C) := ⟨fun _ => Inhabited.default⟩ -- `s` is here to distinguish type synonyms asking for different shifts /-- A type synonym for `β → C`, used for `β`-graded objects in a category `C` with a shift functor given by translation by `s`. -/ @[nolint unusedArguments] abbrev GradedObjectWithShift {β : Type w} [AddCommGroup β] (_ : β) (C : Type u) : Type max w u := GradedObject β C namespace GradedObject variable {C : Type u} [Category.{v} C] @[simps!] instance categoryOfGradedObjects (β : Type w) : Category.{max w v} (GradedObject β C) := CategoryTheory.pi fun _ => C @[ext] lemma hom_ext {β : Type*} {X Y : GradedObject β C} (f g : X ⟶ Y) (h : ∀ x, f x = g x) : f = g := by funext apply h /-- The projection of a graded object to its `i`-th component. -/ @[simps] def eval {β : Type w} (b : β) : GradedObject β C ⥤ C where obj X := X b map f := f b section variable {β : Type*} (X Y : GradedObject β C) /-- Constructor for isomorphisms in `GradedObject` -/ @[simps] def isoMk (e : ∀ i, X i ≅ Y i) : X ≅ Y where hom i := (e i).hom inv i := (e i).inv variable {X Y} -- this lemma is not an instance as it may create a loop with `isIso_apply_of_isIso` lemma isIso_of_isIso_apply (f : X ⟶ Y) [hf : ∀ i, IsIso (f i)] : IsIso f := by change IsIso (isoMk X Y (fun i => asIso (f i))).hom infer_instance instance isIso_apply_of_isIso (f : X ⟶ Y) [IsIso f] (i : β) : IsIso (f i) := by change IsIso ((eval i).map f) infer_instance end end GradedObject namespace Iso variable {C D E J : Type*} [Category C] [Category D] [Category E] {X Y : GradedObject J C} @[reassoc (attr := simp)] lemma hom_inv_id_eval (e : X ≅ Y) (j : J) : e.hom j ≫ e.inv j = 𝟙 _ := by rw [← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id, GradedObject.categoryOfGradedObjects_id] @[reassoc (attr := simp)] lemma inv_hom_id_eval (e : X ≅ Y) (j : J) : e.inv j ≫ e.hom j = 𝟙 _ := by rw [← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id, GradedObject.categoryOfGradedObjects_id] @[reassoc (attr := simp)] lemma map_hom_inv_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.hom j) ≫ F.map (e.inv j) = 𝟙 _ := by rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id, GradedObject.categoryOfGradedObjects_id, Functor.map_id] @[reassoc (attr := simp)]
Mathlib/CategoryTheory/GradedObject.lean
120
124
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Integer powers of square matrices In this file, we define integer power of matrices, relying on the nonsingular inverse definition for negative powers. ## Implementation details The main definition is a direct recursive call on the integer inductive type, as provided by the `DivInvMonoid.Pow` default implementation. The lemma names are taken from `Algebra.GroupWithZero.Power`. ## Tags matrix inverse, matrix powers -/ open Matrix namespace Matrix variable {n' : Type*} [DecidableEq n'] [Fintype n'] {R : Type*} [CommRing R] local notation "M" => Matrix n' n' R noncomputable instance : DivInvMonoid M := { show Monoid M by infer_instance, show Inv M by infer_instance with } section NatPow @[simp] theorem inv_pow' (A : M) (n : ℕ) : A⁻¹ ^ n = (A ^ n)⁻¹ := by induction n with | zero => simp | succ n ih => rw [pow_succ A, mul_inv_rev, ← ih, ← pow_succ'] theorem pow_sub' (A : M) {m n : ℕ} (ha : IsUnit A.det) (h : n ≤ m) : A ^ (m - n) = A ^ m * (A ^ n)⁻¹ := by rw [← tsub_add_cancel_of_le h, pow_add, Matrix.mul_assoc, mul_nonsing_inv, tsub_add_cancel_of_le h, Matrix.mul_one] simpa using ha.pow n theorem pow_inv_comm' (A : M) (m n : ℕ) : A⁻¹ ^ m * A ^ n = A ^ n * A⁻¹ ^ m := by induction n generalizing m with | zero => simp | succ n IH => rcases m with m | m · simp rcases nonsing_inv_cancel_or_zero A with ⟨h, h'⟩ | h · calc A⁻¹ ^ (m + 1) * A ^ (n + 1) = A⁻¹ ^ m * (A⁻¹ * A) * A ^ n := by simp only [pow_succ A⁻¹, pow_succ' A, Matrix.mul_assoc] _ = A ^ n * A⁻¹ ^ m := by simp only [h, Matrix.mul_one, Matrix.one_mul, IH m] _ = A ^ n * (A * A⁻¹) * A⁻¹ ^ m := by simp only [h', Matrix.mul_one, Matrix.one_mul] _ = A ^ (n + 1) * A⁻¹ ^ (m + 1) := by simp only [pow_succ A, pow_succ' A⁻¹, Matrix.mul_assoc] · simp [h] end NatPow section ZPow open Int @[simp] theorem one_zpow : ∀ n : ℤ, (1 : M) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | -[n+1] => by rw [zpow_negSucc, one_pow, inv_one] theorem zero_zpow : ∀ z : ℤ, z ≠ 0 → (0 : M) ^ z = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow] exact mod_cast h | -[n+1], _ => by simp [zero_pow n.succ_ne_zero] theorem zero_zpow_eq (n : ℤ) : (0 : M) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h] theorem inv_zpow (A : M) : ∀ n : ℤ, A⁻¹ ^ n = (A ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow'] | -[n+1] => by rw [zpow_negSucc, zpow_negSucc, inv_pow'] @[simp] theorem zpow_neg_one (A : M) : A ^ (-1 : ℤ) = A⁻¹ := by convert DivInvMonoid.zpow_neg' 0 A simp only [zpow_one, Int.ofNat_zero, Int.natCast_succ, zpow_eq_pow, zero_add] @[simp] theorem zpow_neg_natCast (A : M) (n : ℕ) : A ^ (-n : ℤ) = (A ^ n)⁻¹ := by cases n · simp · exact DivInvMonoid.zpow_neg' _ _ theorem _root_.IsUnit.det_zpow {A : M} (h : IsUnit A.det) (n : ℤ) : IsUnit (A ^ n).det := by rcases n with n | n · simpa using h.pow n · simpa using h.pow n.succ theorem isUnit_det_zpow_iff {A : M} {z : ℤ} : IsUnit (A ^ z).det ↔ IsUnit A.det ∨ z = 0 := by induction z with | hz => simp | hp z => rw [← Int.natCast_succ, zpow_natCast, det_pow, isUnit_pow_succ_iff, ← Int.ofNat_zero, Int.ofNat_inj] simp | hn z => rw [← neg_add', ← Int.natCast_succ, zpow_neg_natCast, isUnit_nonsing_inv_det_iff, det_pow, isUnit_pow_succ_iff, neg_eq_zero, ← Int.ofNat_zero, Int.ofNat_inj] simp theorem zpow_neg {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (-n) = (A ^ n)⁻¹ | (n : ℕ) => zpow_neg_natCast _ _ | -[n+1] => by rw [zpow_negSucc, neg_negSucc, zpow_natCast, nonsing_inv_nonsing_inv] rw [det_pow] exact h.pow _ theorem inv_zpow' {A : M} (h : IsUnit A.det) (n : ℤ) : A⁻¹ ^ n = A ^ (-n) := by rw [zpow_neg h, inv_zpow] theorem zpow_add_one {A : M} (h : IsUnit A.det) : ∀ n : ℤ, A ^ (n + 1) = A ^ n * A | (n : ℕ) => by simp only [← Nat.cast_succ, pow_succ, zpow_natCast] | -[n+1] => calc A ^ (-(n + 1) + 1 : ℤ) = (A ^ n)⁻¹ := by rw [neg_add, neg_add_cancel_right, zpow_neg h, zpow_natCast] _ = (A * A ^ n)⁻¹ * A := by rw [mul_inv_rev, Matrix.mul_assoc, nonsing_inv_mul _ h, Matrix.mul_one] _ = A ^ (-(n + 1 : ℤ)) * A := by rw [zpow_neg h, ← Int.natCast_succ, zpow_natCast, pow_succ'] theorem zpow_sub_one {A : M} (h : IsUnit A.det) (n : ℤ) : A ^ (n - 1) = A ^ n * A⁻¹ := calc A ^ (n - 1) = A ^ (n - 1) * A * A⁻¹ := by rw [mul_assoc, mul_nonsing_inv _ h, mul_one] _ = A ^ n * A⁻¹ := by rw [← zpow_add_one h, sub_add_cancel] theorem zpow_add {A : M} (ha : IsUnit A.det) (m n : ℤ) : A ^ (m + n) = A ^ m * A ^ n := by induction n with | hz => simp | hp n ihn => simp only [← add_assoc, zpow_add_one ha, ihn, mul_assoc] | hn n ihn => rw [zpow_sub_one ha, ← mul_assoc, ← ihn, ← zpow_sub_one ha, add_sub_assoc] theorem zpow_add_of_nonpos {A : M} {m n : ℤ} (hm : m ≤ 0) (hn : n ≤ 0) : A ^ (m + n) = A ^ m * A ^ n := by rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h) · exact zpow_add (isUnit_det_of_left_inverse h) m n · obtain ⟨k, rfl⟩ := exists_eq_neg_ofNat hm obtain ⟨l, rfl⟩ := exists_eq_neg_ofNat hn simp_rw [← neg_add, ← Int.natCast_add, zpow_neg_natCast, ← inv_pow', h, pow_add] theorem zpow_add_of_nonneg {A : M} {m n : ℤ} (hm : 0 ≤ m) (hn : 0 ≤ n) : A ^ (m + n) = A ^ m * A ^ n := by obtain ⟨k, rfl⟩ := eq_ofNat_of_zero_le hm obtain ⟨l, rfl⟩ := eq_ofNat_of_zero_le hn rw [← Int.natCast_add, zpow_natCast, zpow_natCast, zpow_natCast, pow_add] theorem zpow_one_add {A : M} (h : IsUnit A.det) (i : ℤ) : A ^ (1 + i) = A * A ^ i := by rw [zpow_add h, zpow_one] theorem SemiconjBy.zpow_right {A X Y : M} (hx : IsUnit X.det) (hy : IsUnit Y.det) (h : SemiconjBy A X Y) : ∀ m : ℤ, SemiconjBy A (X ^ m) (Y ^ m) | (n : ℕ) => by simp [h.pow_right n] | -[n+1] => by have hx' : IsUnit (X ^ n.succ).det := by rw [det_pow] exact hx.pow n.succ have hy' : IsUnit (Y ^ n.succ).det := by rw [det_pow] exact hy.pow n.succ rw [zpow_negSucc, zpow_negSucc, nonsing_inv_apply _ hx', nonsing_inv_apply _ hy', SemiconjBy] refine (isRegular_of_isLeftRegular_det hy'.isRegular.left).left ?_ dsimp only rw [← mul_assoc, ← (h.pow_right n.succ).eq, mul_assoc, mul_smul, mul_adjugate, ← Matrix.mul_assoc, mul_smul (Y ^ _) (↑hy'.unit⁻¹ : R), mul_adjugate, smul_smul, smul_smul, hx'.val_inv_mul, hy'.val_inv_mul, one_smul, Matrix.mul_one, Matrix.one_mul] theorem Commute.zpow_right {A B : M} (h : Commute A B) (m : ℤ) : Commute A (B ^ m) := by rcases nonsing_inv_cancel_or_zero B with (⟨hB, _⟩ | hB) · refine SemiconjBy.zpow_right ?_ ?_ h _ <;> exact isUnit_det_of_left_inverse hB · cases m · simpa using h.pow_right _ · simp [← inv_pow', hB] theorem Commute.zpow_left {A B : M} (h : Commute A B) (m : ℤ) : Commute (A ^ m) B := (Commute.zpow_right h.symm m).symm theorem Commute.zpow_zpow {A B : M} (h : Commute A B) (m n : ℤ) : Commute (A ^ m) (B ^ n) := Commute.zpow_right (Commute.zpow_left h _) _ theorem Commute.zpow_self (A : M) (n : ℤ) : Commute (A ^ n) A := Commute.zpow_left (Commute.refl A) _ theorem Commute.self_zpow (A : M) (n : ℤ) : Commute A (A ^ n) := Commute.zpow_right (Commute.refl A) _ theorem Commute.zpow_zpow_self (A : M) (m n : ℤ) : Commute (A ^ m) (A ^ n) := Commute.zpow_zpow (Commute.refl A) _ _ theorem zpow_add_one_of_ne_neg_one {A : M} : ∀ n : ℤ, n ≠ -1 → A ^ (n + 1) = A ^ n * A | (n : ℕ), _ => by simp only [pow_succ, ← Nat.cast_succ, zpow_natCast]
| -1, h => absurd rfl h | -((n : ℕ) + 2), _ => by rcases nonsing_inv_cancel_or_zero A with (⟨h, _⟩ | h) · apply zpow_add_one (isUnit_det_of_left_inverse h) · show A ^ (-((n + 1 : ℕ) : ℤ)) = A ^ (-((n + 2 : ℕ) : ℤ)) * A simp_rw [zpow_neg_natCast, ← inv_pow', h, zero_pow <| Nat.succ_ne_zero _, zero_mul]
Mathlib/LinearAlgebra/Matrix/ZPow.lean
214
219
/- Copyright (c) 2022 Sebastian Monnet. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Monnet -/ import Mathlib.FieldTheory.Galois.Basic import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.OpenSubgroup import Mathlib.Tactic.ByContra /-! # Krull topology We define the Krull topology on `L ≃ₐ[K] L` for an arbitrary field extension `L/K`. In order to do this, we first define a `GroupFilterBasis` on `L ≃ₐ[K] L`, whose sets are `E.fixingSubgroup` for all intermediate fields `E` with `E/K` finite dimensional. ## Main Definitions - `finiteExts K L`. Given a field extension `L/K`, this is the set of intermediate fields that are finite-dimensional over `K`. - `fixedByFinite K L`. Given a field extension `L/K`, `fixedByFinite K L` is the set of subsets `Gal(L/E)` of `Gal(L/K)`, where `E/K` is finite - `galBasis K L`. Given a field extension `L/K`, this is the filter basis on `L ≃ₐ[K] L` whose sets are `Gal(L/E)` for intermediate fields `E` with `E/K` finite. - `galGroupBasis K L`. This is the same as `galBasis K L`, but with the added structure that it is a group filter basis on `L ≃ₐ[K] L`, rather than just a filter basis. - `krullTopology K L`. Given a field extension `L/K`, this is the topology on `L ≃ₐ[K] L`, induced by the group filter basis `galGroupBasis K L`. ## Main Results - `krullTopology_t2 K L`. For an integral field extension `L/K`, the topology `krullTopology K L` is Hausdorff. - `krullTopology_totallyDisconnected K L`. For an integral field extension `L/K`, the topology `krullTopology K L` is totally disconnected. - `IntermediateField.finrank_eq_fixingSubgroup_index`: given a Galois extension `K/k` and an intermediate field `L`, the `[L : k]` as a natural number is equal to the index of the fixing subgroup of `L`. ## Notations - In docstrings, we will write `Gal(L/E)` to denote the fixing subgroup of an intermediate field `E`. That is, `Gal(L/E)` is the subgroup of `L ≃ₐ[K] L` consisting of automorphisms that fix every element of `E`. In particular, we distinguish between `L ≃ₐ[E] L` and `Gal(L/E)`, since the former is defined to be a subgroup of `L ≃ₐ[K] L`, while the latter is a group in its own right. ## Implementation Notes - `krullTopology K L` is defined as an instance for type class inference. -/ open scoped Pointwise /-- Mapping intermediate fields along the identity does not change them -/ theorem IntermediateField.map_id {K L : Type*} [Field K] [Field L] [Algebra K L] (E : IntermediateField K L) : E.map (AlgHom.id K L) = E := SetLike.coe_injective <| Set.image_id _ /-- Mapping a finite dimensional intermediate field along an algebra equivalence gives a finite-dimensional intermediate field. -/ instance im_finiteDimensional {K L : Type*} [Field K] [Field L] [Algebra K L] {E : IntermediateField K L} (σ : L ≃ₐ[K] L) [FiniteDimensional K E] : FiniteDimensional K (E.map σ.toAlgHom) := LinearEquiv.finiteDimensional (IntermediateField.intermediateFieldMap σ E).toLinearEquiv /-- Given a field extension `L/K`, `finiteExts K L` is the set of intermediate field extensions `L/E/K` such that `E/K` is finite -/ def finiteExts (K : Type*) [Field K] (L : Type*) [Field L] [Algebra K L] : Set (IntermediateField K L) := {E | FiniteDimensional K E} /-- Given a field extension `L/K`, `fixedByFinite K L` is the set of subsets `Gal(L/E)` of `L ≃ₐ[K] L`, where `E/K` is finite -/ def fixedByFinite (K L : Type*) [Field K] [Field L] [Algebra K L] : Set (Subgroup (L ≃ₐ[K] L)) := IntermediateField.fixingSubgroup '' finiteExts K L /-- For a field extension `L/K`, the intermediate field `K` is finite-dimensional over `K` -/ theorem IntermediateField.finiteDimensional_bot (K L : Type*) [Field K] [Field L] [Algebra K L] : FiniteDimensional K (⊥ : IntermediateField K L) := .of_rank_eq_one IntermediateField.rank_bot /-- This lemma says that `Gal(L/K) = L ≃ₐ[K] L` -/ theorem IntermediateField.fixingSubgroup.bot {K L : Type*} [Field K] [Field L] [Algebra K L] : IntermediateField.fixingSubgroup (⊥ : IntermediateField K L) = ⊤ := by ext f refine ⟨fun _ => Subgroup.mem_top _, fun _ => ?_⟩ rintro ⟨x, hx : x ∈ (⊥ : IntermediateField K L)⟩ rw [IntermediateField.mem_bot] at hx rcases hx with ⟨y, rfl⟩ exact f.commutes y /-- If `L/K` is a field extension, then we have `Gal(L/K) ∈ fixedByFinite K L` -/ theorem top_fixedByFinite {K L : Type*} [Field K] [Field L] [Algebra K L] : ⊤ ∈ fixedByFinite K L := ⟨⊥, IntermediateField.finiteDimensional_bot K L, IntermediateField.fixingSubgroup.bot⟩ /-- If `E1` and `E2` are finite-dimensional intermediate fields, then so is their compositum. This rephrases a result already in mathlib so that it is compatible with our type classes -/ theorem finiteDimensional_sup {K L : Type*} [Field K] [Field L] [Algebra K L] (E1 E2 : IntermediateField K L) (_ : FiniteDimensional K E1) (_ : FiniteDimensional K E2) : FiniteDimensional K (↥(E1 ⊔ E2)) := IntermediateField.finiteDimensional_sup E1 E2 /-- An element of `L ≃ₐ[K] L` is in `Gal(L/E)` if and only if it fixes every element of `E`. -/ theorem IntermediateField.mem_fixingSubgroup_iff {K L : Type*} [Field K] [Field L] [Algebra K L] (E : IntermediateField K L) (σ : L ≃ₐ[K] L) : σ ∈ E.fixingSubgroup ↔ ∀ x : L, x ∈ E → σ x = x := ⟨fun hσ x hx => hσ ⟨x, hx⟩, fun h ⟨x, hx⟩ => h x hx⟩ /-- The map `E ↦ Gal(L/E)` is inclusion-reversing -/ theorem IntermediateField.fixingSubgroup.antimono {K L : Type*} [Field K] [Field L] [Algebra K L] {E1 E2 : IntermediateField K L} (h12 : E1 ≤ E2) : E2.fixingSubgroup ≤ E1.fixingSubgroup := by rintro σ hσ ⟨x, hx⟩ exact hσ ⟨x, h12 hx⟩ /-- Given a field extension `L/K`, `galBasis K L` is the filter basis on `L ≃ₐ[K] L` whose sets are `Gal(L/E)` for intermediate fields `E` with `E/K` finite dimensional -/ def galBasis (K L : Type*) [Field K] [Field L] [Algebra K L] : FilterBasis (L ≃ₐ[K] L) where sets := (fun g => g.carrier) '' fixedByFinite K L nonempty := ⟨⊤, ⊤, top_fixedByFinite, rfl⟩ inter_sets := by rintro X Y ⟨H1, ⟨E1, h_E1, rfl⟩, rfl⟩ ⟨H2, ⟨E2, h_E2, rfl⟩, rfl⟩ use (IntermediateField.fixingSubgroup (E1 ⊔ E2)).carrier refine ⟨⟨_, ⟨_, finiteDimensional_sup E1 E2 h_E1 h_E2, rfl⟩, rfl⟩, ?_⟩ rw [Set.subset_inter_iff] exact ⟨IntermediateField.fixingSubgroup.antimono le_sup_left, IntermediateField.fixingSubgroup.antimono le_sup_right⟩ /-- A subset of `L ≃ₐ[K] L` is a member of `galBasis K L` if and only if it is the underlying set of `Gal(L/E)` for some finite subextension `E/K`. -/ theorem mem_galBasis_iff (K L : Type*) [Field K] [Field L] [Algebra K L] (U : Set (L ≃ₐ[K] L)) : U ∈ galBasis K L ↔ U ∈ (fun g => g.carrier) '' fixedByFinite K L := Iff.rfl /-- For a field extension `L/K`, `galGroupBasis K L` is the group filter basis on `L ≃ₐ[K] L` whose sets are `Gal(L/E)` for finite subextensions `E/K` -/ def galGroupBasis (K L : Type*) [Field K] [Field L] [Algebra K L] : GroupFilterBasis (L ≃ₐ[K] L) where toFilterBasis := galBasis K L one' := fun ⟨H, _, h2⟩ => h2 ▸ H.one_mem mul' {U} hU := ⟨U, hU, by rcases hU with ⟨H, _, rfl⟩ rintro x ⟨a, haH, b, hbH, rfl⟩ exact H.mul_mem haH hbH⟩ inv' {U} hU := ⟨U, hU, by rcases hU with ⟨H, _, rfl⟩ exact fun _ => H.inv_mem'⟩ conj' := by rintro σ U ⟨H, ⟨E, hE, rfl⟩, rfl⟩ let F : IntermediateField K L := E.map σ.symm.toAlgHom refine ⟨F.fixingSubgroup.carrier, ⟨⟨F.fixingSubgroup, ⟨F, ?_, rfl⟩, rfl⟩, fun g hg => ?_⟩⟩ · have : FiniteDimensional K E := hE apply im_finiteDimensional σ.symm change σ * g * σ⁻¹ ∈ E.fixingSubgroup rw [IntermediateField.mem_fixingSubgroup_iff] intro x hx change σ (g (σ⁻¹ x)) = x have h_in_F : σ⁻¹ x ∈ F := ⟨x, hx, by dsimp; rw [← AlgEquiv.invFun_eq_symm]; rfl⟩ have h_g_fix : g (σ⁻¹ x) = σ⁻¹ x := by rw [Subgroup.mem_carrier, IntermediateField.mem_fixingSubgroup_iff F g] at hg exact hg (σ⁻¹ x) h_in_F rw [h_g_fix] change σ (σ⁻¹ x) = x exact AlgEquiv.apply_symm_apply σ x /-- For a field extension `L/K`, `krullTopology K L` is the topological space structure on `L ≃ₐ[K] L` induced by the group filter basis `galGroupBasis K L` -/ instance krullTopology (K L : Type*) [Field K] [Field L] [Algebra K L] : TopologicalSpace (L ≃ₐ[K] L) := GroupFilterBasis.topology (galGroupBasis K L) /-- For a field extension `L/K`, the Krull topology on `L ≃ₐ[K] L` makes it a topological group. -/ @[stacks 0BMJ "We define Krull topology directly without proving the universal property"] instance (K L : Type*) [Field K] [Field L] [Algebra K L] : IsTopologicalGroup (L ≃ₐ[K] L) := GroupFilterBasis.isTopologicalGroup (galGroupBasis K L) open scoped Topology in lemma krullTopology_mem_nhds_one_iff (K L : Type*) [Field K] [Field L] [Algebra K L] (s : Set (L ≃ₐ[K] L)) : s ∈ 𝓝 1 ↔ ∃ E : IntermediateField K L, FiniteDimensional K E ∧ (E.fixingSubgroup : Set (L ≃ₐ[K] L)) ⊆ s := by rw [GroupFilterBasis.nhds_one_eq] constructor · rintro ⟨-, ⟨-, ⟨E, fin, rfl⟩, rfl⟩, hE⟩ exact ⟨E, fin, hE⟩ · rintro ⟨E, fin, hE⟩ exact ⟨E.fixingSubgroup, ⟨E.fixingSubgroup, ⟨E, fin, rfl⟩, rfl⟩, hE⟩ open scoped Topology in lemma krullTopology_mem_nhds_one_iff_of_normal (K L : Type*) [Field K] [Field L] [Algebra K L] [Normal K L] (s : Set (L ≃ₐ[K] L)) : s ∈ 𝓝 1 ↔ ∃ E : IntermediateField K L, FiniteDimensional K E ∧ Normal K E ∧ (E.fixingSubgroup : Set (L ≃ₐ[K] L)) ⊆ s := by rw [krullTopology_mem_nhds_one_iff] refine ⟨fun ⟨E, _, hE⟩ ↦ ?_, fun ⟨E, hE⟩ ↦ ⟨E, hE.1, hE.2.2⟩⟩ use (IntermediateField.normalClosure K E L) simp only [normalClosure.is_finiteDimensional K E L, normalClosure.normal K E L, true_and] exact le_trans (E.fixingSubgroup_anti E.le_normalClosure) hE section KrullT2 open scoped Topology Filter /-- Let `L/E/K` be a tower of fields with `E/K` finite. Then `Gal(L/E)` is an open subgroup of `L ≃ₐ[K] L`. -/ theorem IntermediateField.fixingSubgroup_isOpen {K L : Type*} [Field K] [Field L] [Algebra K L] (E : IntermediateField K L) [FiniteDimensional K E] : IsOpen (E.fixingSubgroup : Set (L ≃ₐ[K] L)) := by have h_basis : E.fixingSubgroup.carrier ∈ galGroupBasis K L := ⟨E.fixingSubgroup, ⟨E, ‹_›, rfl⟩, rfl⟩ have h_nhd := GroupFilterBasis.mem_nhds_one (galGroupBasis K L) h_basis exact Subgroup.isOpen_of_mem_nhds _ h_nhd /-- Given a tower of fields `L/E/K`, with `E/K` finite, the subgroup `Gal(L/E) ≤ L ≃ₐ[K] L` is closed. -/ theorem IntermediateField.fixingSubgroup_isClosed {K L : Type*} [Field K] [Field L] [Algebra K L] (E : IntermediateField K L) [FiniteDimensional K E] : IsClosed (E.fixingSubgroup : Set (L ≃ₐ[K] L)) := OpenSubgroup.isClosed ⟨E.fixingSubgroup, E.fixingSubgroup_isOpen⟩ /-- If `L/K` is an algebraic extension, then the Krull topology on `L ≃ₐ[K] L` is Hausdorff. -/ theorem krullTopology_t2 {K L : Type*} [Field K] [Field L] [Algebra K L] [Algebra.IsIntegral K L] : T2Space (L ≃ₐ[K] L) := { t2 := fun f g hfg => by let φ := f⁻¹ * g obtain ⟨x, hx⟩ := DFunLike.exists_ne hfg have hφx : φ x ≠ x := by apply ne_of_apply_ne f change f (f.symm (g x)) ≠ f x rw [AlgEquiv.apply_symm_apply f (g x), ne_comm] exact hx let E : IntermediateField K L := IntermediateField.adjoin K {x} let h_findim : FiniteDimensional K E := IntermediateField.adjoin.finiteDimensional (Algebra.IsIntegral.isIntegral x) let H := E.fixingSubgroup have h_basis : (H : Set (L ≃ₐ[K] L)) ∈ galGroupBasis K L := ⟨H, ⟨E, ⟨h_findim, rfl⟩⟩, rfl⟩ have h_nhd := GroupFilterBasis.mem_nhds_one (galGroupBasis K L) h_basis rw [mem_nhds_iff] at h_nhd rcases h_nhd with ⟨W, hWH, hW_open, hW_1⟩ refine ⟨f • W, g • W, ⟨hW_open.leftCoset f, hW_open.leftCoset g, ⟨1, hW_1, mul_one _⟩, ⟨1, hW_1, mul_one _⟩, ?_⟩⟩ rw [Set.disjoint_left] rintro σ ⟨w1, hw1, h⟩ ⟨w2, hw2, rfl⟩ dsimp at h rw [eq_inv_mul_iff_mul_eq.symm, ← mul_assoc, mul_inv_eq_iff_eq_mul.symm] at h have h_in_H : w1 * w2⁻¹ ∈ H := H.mul_mem (hWH hw1) (H.inv_mem (hWH hw2)) rw [h] at h_in_H change φ ∈ E.fixingSubgroup at h_in_H rw [IntermediateField.mem_fixingSubgroup_iff] at h_in_H specialize h_in_H x have hxE : x ∈ E := by apply IntermediateField.subset_adjoin apply Set.mem_singleton exact hφx (h_in_H hxE) } end KrullT2 section TotallySeparated instance {K L : Type*} [Field K] [Field L] [Algebra K L] [Algebra.IsIntegral K L] : TotallySeparatedSpace (L ≃ₐ[K] L) := by rw [totallySeparatedSpace_iff_exists_isClopen] intro σ τ h_diff have hστ : σ⁻¹ * τ ≠ 1 := by rwa [Ne, inv_mul_eq_one] rcases DFunLike.exists_ne hστ with ⟨x, hx : (σ⁻¹ * τ) x ≠ x⟩ let E := IntermediateField.adjoin K ({x} : Set L) haveI := IntermediateField.adjoin.finiteDimensional (Algebra.IsIntegral.isIntegral (R := K) x) refine ⟨σ • E.fixingSubgroup, ⟨E.fixingSubgroup_isClosed.leftCoset σ, E.fixingSubgroup_isOpen.leftCoset σ⟩, ⟨1, E.fixingSubgroup.one_mem', mul_one σ⟩, ?_⟩ simp only [Set.mem_compl_iff, mem_leftCoset_iff, SetLike.mem_coe, IntermediateField.mem_fixingSubgroup_iff, not_forall] exact ⟨x, IntermediateField.mem_adjoin_simple_self K x, hx⟩ /-- If `L/K` is an algebraic field extension, then the Krull topology on `L ≃ₐ[K] L` is totally disconnected. -/ theorem krullTopology_isTotallySeparated {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsIntegral K L] : IsTotallySeparated (Set.univ : Set (L ≃ₐ[K] L)) := (totallySeparatedSpace_iff _).mp inferInstance @[deprecated (since := "2025-04-03")]
Mathlib/FieldTheory/KrullTopology.lean
286
289
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.Tactic.IntervalCases /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where /-- The degree-3 coefficient -/ a : R /-- The degree-2 coefficient -/ b : R /-- The degree-1 coefficient -/ c : R /-- The degree-0 coefficient -/ d : R namespace Cubic open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] /-! ### Coefficients -/ section Coeff private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] norm_num intro n hn repeat' rw [if_neg] any_goals omega repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by rw [toPoly, ha, C_0, zero_mul, zero_add]
Mathlib/Algebra/CubicDiscriminant.lean
127
127
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Devon Tuma -/ import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.RingTheory.Coprime.Basic import Mathlib.Tactic.AdaptationNote /-! # Scaling the roots of a polynomial This file defines `scaleRoots p s` for a polynomial `p` in one variable and a ring element `s` to be the polynomial with root `r * s` for each root `r` of `p` and proves some basic results about it. -/ variable {R S A K : Type*} namespace Polynomial section Semiring variable [Semiring R] [Semiring S] /-- `scaleRoots p s` is a polynomial with root `r * s` for each root `r` of `p`. -/ noncomputable def scaleRoots (p : R[X]) (s : R) : R[X] := ∑ i ∈ p.support, monomial i (p.coeff i * s ^ (p.natDegree - i)) @[simp] theorem coeff_scaleRoots (p : R[X]) (s : R) (i : ℕ) : (scaleRoots p s).coeff i = coeff p i * s ^ (p.natDegree - i) := by simp +contextual [scaleRoots, coeff_monomial] theorem coeff_scaleRoots_natDegree (p : R[X]) (s : R) : (scaleRoots p s).coeff p.natDegree = p.leadingCoeff := by rw [leadingCoeff, coeff_scaleRoots, tsub_self, pow_zero, mul_one] @[simp] theorem zero_scaleRoots (s : R) : scaleRoots 0 s = 0 := by ext simp theorem scaleRoots_ne_zero {p : R[X]} (hp : p ≠ 0) (s : R) : scaleRoots p s ≠ 0 := by intro h have : p.coeff p.natDegree ≠ 0 := mt leadingCoeff_eq_zero.mp hp have : (scaleRoots p s).coeff p.natDegree = 0 := congr_fun (congr_arg (coeff : R[X] → ℕ → R) h) p.natDegree rw [coeff_scaleRoots_natDegree] at this contradiction theorem support_scaleRoots_le (p : R[X]) (s : R) : (scaleRoots p s).support ≤ p.support := by intro simpa using left_ne_zero_of_mul theorem support_scaleRoots_eq (p : R[X]) {s : R} (hs : s ∈ nonZeroDivisors R) : (scaleRoots p s).support = p.support := le_antisymm (support_scaleRoots_le p s) (by intro i simp only [coeff_scaleRoots, Polynomial.mem_support_iff] intro p_ne_zero ps_zero have := pow_mem hs (p.natDegree - i) _ ps_zero contradiction) @[simp] theorem degree_scaleRoots (p : R[X]) {s : R} : degree (scaleRoots p s) = degree p := by haveI := Classical.propDecidable by_cases hp : p = 0 · rw [hp, zero_scaleRoots] refine le_antisymm (Finset.sup_mono (support_scaleRoots_le p s)) (degree_le_degree ?_) rw [coeff_scaleRoots_natDegree] intro h have := leadingCoeff_eq_zero.mp h contradiction @[simp] theorem natDegree_scaleRoots (p : R[X]) (s : R) : natDegree (scaleRoots p s) = natDegree p := by simp only [natDegree, degree_scaleRoots] theorem monic_scaleRoots_iff {p : R[X]} (s : R) : Monic (scaleRoots p s) ↔ Monic p := by simp only [Monic, leadingCoeff, natDegree_scaleRoots, coeff_scaleRoots_natDegree] theorem map_scaleRoots (p : R[X]) (x : R) (f : R →+* S) (h : f p.leadingCoeff ≠ 0) : (p.scaleRoots x).map f = (p.map f).scaleRoots (f x) := by ext simp [Polynomial.natDegree_map_of_leadingCoeff_ne_zero _ h] @[simp] lemma scaleRoots_C (r c : R) : (C c).scaleRoots r = C c := by ext; simp @[simp] lemma scaleRoots_one (p : R[X]) : p.scaleRoots 1 = p := by ext; simp @[simp] lemma scaleRoots_zero (p : R[X]) : p.scaleRoots 0 = p.leadingCoeff • X ^ p.natDegree := by ext n simp only [coeff_scaleRoots, ne_eq, tsub_eq_zero_iff_le, not_le, zero_pow_eq, mul_ite, mul_one, mul_zero, coeff_smul, coeff_X_pow, smul_eq_mul] split_ifs with h₁ h₂ h₂ · subst h₂; rfl · exact coeff_eq_zero_of_natDegree_lt (lt_of_le_of_ne h₁ (Ne.symm h₂)) · exact (h₁ h₂.ge).elim · rfl @[simp] lemma one_scaleRoots (r : R) : (1 : R[X]).scaleRoots r = 1 := by ext; simp end Semiring section CommSemiring variable [Semiring S] [CommSemiring R] [Semiring A] [Field K] theorem scaleRoots_eval₂_mul_of_commute {p : S[X]} (f : S →+* A) (a : A) (s : S) (hsa : Commute (f s) a) (hf : ∀ s₁ s₂, Commute (f s₁) (f s₂)) : eval₂ f (f s * a) (scaleRoots p s) = f s ^ p.natDegree * eval₂ f a p := by calc _ = (scaleRoots p s).support.sum fun i => f (coeff p i * s ^ (p.natDegree - i)) * (f s * a) ^ i := by simp [eval₂_eq_sum, sum_def] _ = p.support.sum fun i => f (coeff p i * s ^ (p.natDegree - i)) * (f s * a) ^ i := (Finset.sum_subset (support_scaleRoots_le p s) fun i _hi hi' => by let this : coeff p i * s ^ (p.natDegree - i) = 0 := by simpa using hi' simp [this]) _ = p.support.sum fun i : ℕ => f (p.coeff i) * f s ^ (p.natDegree - i + i) * a ^ i := (Finset.sum_congr rfl fun i _hi => by simp_rw [f.map_mul, f.map_pow, pow_add, hsa.mul_pow, mul_assoc]) _ = p.support.sum fun i : ℕ => f s ^ p.natDegree * (f (p.coeff i) * a ^ i) := Finset.sum_congr rfl fun i hi => by rw [mul_assoc, ← map_pow, (hf _ _).left_comm, map_pow, tsub_add_cancel_of_le] exact le_natDegree_of_ne_zero (Polynomial.mem_support_iff.mp hi) _ = f s ^ p.natDegree * eval₂ f a p := by simp [← Finset.mul_sum, eval₂_eq_sum, sum_def] theorem scaleRoots_eval₂_mul {p : S[X]} (f : S →+* R) (r : R) (s : S) : eval₂ f (f s * r) (scaleRoots p s) = f s ^ p.natDegree * eval₂ f r p := scaleRoots_eval₂_mul_of_commute f r s (mul_comm _ _) fun _ _ ↦ mul_comm _ _ theorem scaleRoots_eval₂_eq_zero {p : S[X]} (f : S →+* R) {r : R} {s : S} (hr : eval₂ f r p = 0) : eval₂ f (f s * r) (scaleRoots p s) = 0 := by rw [scaleRoots_eval₂_mul, hr, mul_zero] theorem scaleRoots_aeval_eq_zero [Algebra R A] {p : R[X]} {a : A} {r : R} (ha : aeval a p = 0) : aeval (algebraMap R A r * a) (scaleRoots p r) = 0 := by rw [aeval_def, scaleRoots_eval₂_mul_of_commute, ← aeval_def, ha, mul_zero] · apply Algebra.commutes · intros; rw [Commute, SemiconjBy, ← map_mul, ← map_mul, mul_comm] theorem scaleRoots_eval₂_eq_zero_of_eval₂_div_eq_zero {p : S[X]} {f : S →+* K} (hf : Function.Injective f) {r s : S} (hr : eval₂ f (f r / f s) p = 0) (hs : s ∈ nonZeroDivisors S) : eval₂ f (f r) (scaleRoots p s) = 0 := by -- if we don't specify the type with `(_ : S)`, the proof is much slower nontriviality S using Subsingleton.eq_zero (_ : S) convert @scaleRoots_eval₂_eq_zero _ _ _ _ p f _ s hr rw [← mul_div_assoc, mul_comm, mul_div_cancel_right₀] exact map_ne_zero_of_mem_nonZeroDivisors _ hf hs theorem scaleRoots_aeval_eq_zero_of_aeval_div_eq_zero [Algebra R K] (inj : Function.Injective (algebraMap R K)) {p : R[X]} {r s : R} (hr : aeval (algebraMap R K r / algebraMap R K s) p = 0) (hs : s ∈ nonZeroDivisors R) : aeval (algebraMap R K r) (scaleRoots p s) = 0 := scaleRoots_eval₂_eq_zero_of_eval₂_div_eq_zero inj hr hs @[simp] lemma scaleRoots_mul (p : R[X]) (r s) : p.scaleRoots (r * s) = (p.scaleRoots r).scaleRoots s := by ext; simp [mul_pow, mul_assoc] /-- Multiplication and `scaleRoots` commute up to a power of `r`. The factor disappears if we assume that the product of the leading coeffs does not vanish. See `Polynomial.mul_scaleRoots'`. -/ lemma mul_scaleRoots (p q : R[X]) (r : R) : r ^ (natDegree p + natDegree q - natDegree (p * q)) • (p * q).scaleRoots r = p.scaleRoots r * q.scaleRoots r := by ext n; simp only [coeff_scaleRoots, coeff_smul, smul_eq_mul] trans (∑ x ∈ Finset.antidiagonal n, coeff p x.1 * coeff q x.2) * r ^ (natDegree p + natDegree q - n) · rw [← coeff_mul] cases lt_or_le (natDegree (p * q)) n with | inl h => simp only [coeff_eq_zero_of_natDegree_lt h, zero_mul, mul_zero] | inr h => rw [mul_comm, mul_assoc, ← pow_add, add_comm, tsub_add_tsub_cancel natDegree_mul_le h] · rw [coeff_mul, Finset.sum_mul] apply Finset.sum_congr rfl simp only [Finset.mem_antidiagonal, coeff_scaleRoots, Prod.forall] intros a b e cases lt_or_le (natDegree p) a with | inl h => simp only [coeff_eq_zero_of_natDegree_lt h, zero_mul, mul_zero] | inr ha => cases lt_or_le (natDegree q) b with | inl h => simp only [coeff_eq_zero_of_natDegree_lt h, zero_mul, mul_zero] | inr hb => simp only [← e, mul_assoc, mul_comm (r ^ (_ - a)), ← pow_add] rw [add_comm (_ - _), tsub_add_tsub_comm ha hb] lemma mul_scaleRoots' (p q : R[X]) (r : R) (h : leadingCoeff p * leadingCoeff q ≠ 0) : (p * q).scaleRoots r = p.scaleRoots r * q.scaleRoots r := by rw [← mul_scaleRoots, natDegree_mul' h, tsub_self, pow_zero, one_smul] lemma mul_scaleRoots_of_noZeroDivisors (p q : R[X]) (r : R) [NoZeroDivisors R] : (p * q).scaleRoots r = p.scaleRoots r * q.scaleRoots r := by by_cases hp : p = 0; · simp [hp] by_cases hq : q = 0; · simp [hq] apply mul_scaleRoots' simp only [ne_eq, mul_eq_zero, leadingCoeff_eq_zero, hp, hq, or_self, not_false_eq_true] lemma add_scaleRoots_of_natDegree_eq (p q : R[X]) (r : R) (h : natDegree p = natDegree q) : r ^ (natDegree p - natDegree (p + q)) • (p + q).scaleRoots r = p.scaleRoots r + q.scaleRoots r := by ext n; simp only [coeff_smul, coeff_scaleRoots, coeff_add, smul_eq_mul, mul_comm (r ^ _), ← pow_add, ← h, ← add_mul, add_comm (_ - n)] #adaptation_note /-- v4.7.0-rc1 Previously `mul_assoc` was part of the `simp only` above, and this `rw` was not needed. but this now causes a max rec depth error. -/ rw [mul_assoc, ← pow_add] cases lt_or_le (natDegree (p + q)) n with | inl hn => simp only [← coeff_add, coeff_eq_zero_of_natDegree_lt hn, zero_mul] | inr hn => rw [add_comm (_ - n), tsub_add_tsub_cancel (natDegree_add_le_of_degree_le le_rfl h.ge) hn] lemma scaleRoots_dvd' (p q : R[X]) {r : R} (hr : IsUnit r) (hpq : p ∣ q) : p.scaleRoots r ∣ q.scaleRoots r := by obtain ⟨a, rfl⟩ := hpq rw [← ((hr.pow (natDegree p + natDegree a - natDegree (p * a))).map (algebraMap R R[X])).dvd_mul_left, ← Algebra.smul_def, mul_scaleRoots] exact dvd_mul_right (scaleRoots p r) (scaleRoots a r)
lemma scaleRoots_dvd (p q : R[X]) {r : R} [NoZeroDivisors R] (hpq : p ∣ q) : p.scaleRoots r ∣ q.scaleRoots r := by obtain ⟨a, rfl⟩ := hpq rw [mul_scaleRoots_of_noZeroDivisors] exact dvd_mul_right (scaleRoots p r) (scaleRoots a r) alias _root_.Dvd.dvd.scaleRoots := scaleRoots_dvd lemma scaleRoots_dvd_iff (p q : R[X]) {r : R} (hr : IsUnit r) : p.scaleRoots r ∣ q.scaleRoots r ↔ p ∣ q := by refine ⟨?_ ∘ scaleRoots_dvd' _ _ (hr.unit⁻¹).isUnit, scaleRoots_dvd' p q hr⟩ simp [← scaleRoots_mul, scaleRoots_one] alias _root_.IsUnit.scaleRoots_dvd_iff := scaleRoots_dvd_iff
Mathlib/RingTheory/Polynomial/ScaleRoots.lean
230
242
/- 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 -/ import Mathlib.Order.Filter.Prod import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.Bases.Basic /-! # Lift filters along filter and set functions -/ open Set Filter Function namespace Filter variable {α β γ : Type*} {ι : Sort*} section lift variable {f f₁ f₂ : Filter α} {g g₁ g₂ : Set α → Filter β} @[simp] theorem lift_top (g : Set α → Filter β) : (⊤ : Filter α).lift g = g univ := by simp [Filter.lift] /-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function `Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis of the filter `g (s i)`, then `(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis of the filter `f.lift g`. This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using `Filter.HasBasis` one has to use `Σ i, β i` as the index type, see `Filter.HasBasis.lift`. This lemma states the corresponding `mem_iff` statement without using a sigma type. -/ theorem HasBasis.mem_lift_iff {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ} (hg : ∀ i, (g <| s i).HasBasis (pg i) (sg i)) (gm : Monotone g) {s : Set γ} : s ∈ f.lift g ↔ ∃ i, p i ∧ ∃ x, pg i x ∧ sg i x ⊆ s := by refine (mem_biInf_of_directed ?_ ⟨univ, univ_sets _⟩).trans ?_ · intro t₁ ht₁ t₂ ht₂ exact ⟨t₁ ∩ t₂, inter_mem ht₁ ht₂, gm inter_subset_left, gm inter_subset_right⟩ · simp only [← (hg _).mem_iff] exact hf.exists_iff fun t₁ t₂ ht H => gm ht H /-- If `(p : ι → Prop, s : ι → Set α)` is a basis of a filter `f`, `g` is a monotone function `Set α → Filter γ`, and for each `i`, `(pg : β i → Prop, sg : β i → Set α)` is a basis of the filter `g (s i)`, then `(fun (i : ι) (x : β i) ↦ p i ∧ pg i x, fun (i : ι) (x : β i) ↦ sg i x)` is a basis of the filter `f.lift g`. This basis is parametrized by `i : ι` and `x : β i`, so in order to formulate this fact using `has_basis` one has to use `Σ i, β i` as the index type. See also `Filter.HasBasis.mem_lift_iff` for the corresponding `mem_iff` statement formulated without using a sigma type. -/ theorem HasBasis.lift {ι} {p : ι → Prop} {s : ι → Set α} {f : Filter α} (hf : f.HasBasis p s) {β : ι → Type*} {pg : ∀ i, β i → Prop} {sg : ∀ i, β i → Set γ} {g : Set α → Filter γ} (hg : ∀ i, (g (s i)).HasBasis (pg i) (sg i)) (gm : Monotone g) : (f.lift g).HasBasis (fun i : Σi, β i => p i.1 ∧ pg i.1 i.2) fun i : Σi, β i => sg i.1 i.2 := by refine ⟨fun t => (hf.mem_lift_iff hg gm).trans ?_⟩ simp [Sigma.exists, and_assoc, exists_and_left] theorem mem_lift_sets (hg : Monotone g) {s : Set β} : s ∈ f.lift g ↔ ∃ t ∈ f, s ∈ g t := (f.basis_sets.mem_lift_iff (fun s => (g s).basis_sets) hg).trans <| by simp only [id, exists_mem_subset_iff] theorem sInter_lift_sets (hg : Monotone g) : ⋂₀ { s | s ∈ f.lift g } = ⋂ s ∈ f, ⋂₀ { t | t ∈ g s } := by simp only [sInter_eq_biInter, mem_setOf_eq, Filter.mem_sets, mem_lift_sets hg, iInter_exists, iInter_and, @iInter_comm _ (Set β)] theorem mem_lift {s : Set β} {t : Set α} (ht : t ∈ f) (hs : s ∈ g t) : s ∈ f.lift g := le_principal_iff.mp <| show f.lift g ≤ 𝓟 s from iInf_le_of_le t <| iInf_le_of_le ht <| le_principal_iff.mpr hs theorem lift_le {f : Filter α} {g : Set α → Filter β} {h : Filter β} {s : Set α} (hs : s ∈ f) (hg : g s ≤ h) : f.lift g ≤ h := iInf₂_le_of_le s hs hg theorem le_lift {f : Filter α} {g : Set α → Filter β} {h : Filter β} : h ≤ f.lift g ↔ ∀ s ∈ f, h ≤ g s := le_iInf₂_iff theorem lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ := iInf_mono fun s => iInf_mono' fun hs => ⟨hf hs, hg s⟩ theorem lift_mono' (hg : ∀ s ∈ f, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ := iInf₂_mono hg theorem tendsto_lift {m : γ → β} {l : Filter γ} : Tendsto m l (f.lift g) ↔ ∀ s ∈ f, Tendsto m l (g s) := by simp only [Filter.lift, tendsto_iInf] theorem map_lift_eq {m : β → γ} (hg : Monotone g) : map m (f.lift g) = f.lift (map m ∘ g) := have : Monotone (map m ∘ g) := map_mono.comp hg Filter.ext fun s => by simp only [mem_lift_sets hg, mem_lift_sets this, exists_prop, mem_map, Function.comp_apply] theorem comap_lift_eq {m : γ → β} : comap m (f.lift g) = f.lift (comap m ∘ g) := by simp only [Filter.lift, comap_iInf]; rfl theorem comap_lift_eq2 {m : β → α} {g : Set β → Filter γ} (hg : Monotone g) : (comap m f).lift g = f.lift (g ∘ preimage m) := le_antisymm (le_iInf₂ fun s hs => iInf₂_le (m ⁻¹' s) ⟨s, hs, Subset.rfl⟩) (le_iInf₂ fun _s ⟨s', hs', h_sub⟩ => iInf₂_le_of_le s' hs' <| hg h_sub) theorem lift_map_le {g : Set β → Filter γ} {m : α → β} : (map m f).lift g ≤ f.lift (g ∘ image m) := le_lift.2 fun _s hs => lift_le (image_mem_map hs) le_rfl theorem map_lift_eq2 {g : Set β → Filter γ} {m : α → β} (hg : Monotone g) : (map m f).lift g = f.lift (g ∘ image m) := lift_map_le.antisymm <| le_lift.2 fun _s hs => lift_le hs <| hg <| image_preimage_subset _ _ theorem lift_comm {g : Filter β} {h : Set α → Set β → Filter γ} : (f.lift fun s => g.lift (h s)) = g.lift fun t => f.lift fun s => h s t := le_antisymm (le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj => iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi) (le_iInf fun i => le_iInf fun hi => le_iInf fun j => le_iInf fun hj => iInf_le_of_le j <| iInf_le_of_le hj <| iInf_le_of_le i <| iInf_le _ hi) theorem lift_assoc {h : Set β → Filter γ} (hg : Monotone g) : (f.lift g).lift h = f.lift fun s => (g s).lift h := le_antisymm (le_iInf₂ fun _s hs => le_iInf₂ fun t ht => iInf_le_of_le t <| iInf_le _ <| (mem_lift_sets hg).mpr ⟨_, hs, ht⟩) (le_iInf₂ fun t ht => let ⟨s, hs, h'⟩ := (mem_lift_sets hg).mp ht iInf_le_of_le s <| iInf_le_of_le hs <| iInf_le_of_le t <| iInf_le _ h') theorem lift_lift_same_le_lift {g : Set α → Set α → Filter β} : (f.lift fun s => f.lift (g s)) ≤ f.lift fun s => g s s := le_lift.2 fun _s hs => lift_le hs <| lift_le hs le_rfl theorem lift_lift_same_eq_lift {g : Set α → Set α → Filter β} (hg₁ : ∀ s, Monotone fun t => g s t) (hg₂ : ∀ t, Monotone fun s => g s t) : (f.lift fun s => f.lift (g s)) = f.lift fun s => g s s := lift_lift_same_le_lift.antisymm <| le_lift.2 fun s hs => le_lift.2 fun t ht => lift_le (inter_mem hs ht) <| calc g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) := hg₂ (s ∩ t) inter_subset_left _ ≤ g s t := hg₁ s inter_subset_right theorem lift_principal {s : Set α} (hg : Monotone g) : (𝓟 s).lift g = g s := (lift_le (mem_principal_self _) le_rfl).antisymm (le_lift.2 fun _t ht => hg ht) theorem monotone_lift [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Filter β} (hf : Monotone f) (hg : Monotone g) : Monotone fun c => (f c).lift (g c) := fun _ _ h => lift_mono (hf h) (hg h) theorem lift_neBot_iff (hm : Monotone g) : (NeBot (f.lift g)) ↔ ∀ s ∈ f, NeBot (g s) := by simp only [neBot_iff, Ne, ← empty_mem_iff_bot, mem_lift_sets hm, not_exists, not_and] @[simp] theorem lift_const {f : Filter α} {g : Filter β} : (f.lift fun _ => g) = g := iInf_subtype'.trans iInf_const @[simp] theorem lift_inf {f : Filter α} {g h : Set α → Filter β} : (f.lift fun x => g x ⊓ h x) = f.lift g ⊓ f.lift h := by simp only [Filter.lift, iInf_inf_eq] @[simp] theorem lift_principal2 {f : Filter α} : f.lift 𝓟 = f := le_antisymm (fun s hs => mem_lift hs (mem_principal_self s)) (le_iInf fun s => le_iInf fun hs => by simp only [hs, le_principal_iff]) theorem lift_iInf_le {f : ι → Filter α} {g : Set α → Filter β} : (iInf f).lift g ≤ ⨅ i, (f i).lift g := le_iInf fun _ => lift_mono (iInf_le _ _) le_rfl theorem lift_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β} (hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) : (iInf f).lift g = ⨅ i, (f i).lift g := by refine lift_iInf_le.antisymm fun s => ?_ have H : ∀ t ∈ iInf f, ⨅ i, (f i).lift g ≤ g t := by intro t ht refine iInf_sets_induct ht ?_ fun hs ht => ?_ · inhabit ι exact iInf₂_le_of_le default univ (iInf_le _ univ_mem) · rw [hg] exact le_inf (iInf₂_le_of_le _ _ <| iInf_le _ hs) ht simp only [mem_lift_sets (Monotone.of_map_inf hg), exists_imp, and_imp] exact fun t ht hs => H t ht hs theorem lift_iInf_of_directed [Nonempty ι] {f : ι → Filter α} {g : Set α → Filter β} (hf : Directed (· ≥ ·) f) (hg : Monotone g) : (iInf f).lift g = ⨅ i, (f i).lift g := lift_iInf_le.antisymm fun s => by simp only [mem_lift_sets hg, exists_imp, and_imp, mem_iInf_of_directed hf] exact fun t i ht hs => mem_iInf_of_mem i <| mem_lift ht hs theorem lift_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Filter β} (hg : ∀ s t, g (s ∩ t) = g s ⊓ g t) (hg' : g univ = ⊤) : (iInf f).lift g = ⨅ i, (f i).lift g := by cases isEmpty_or_nonempty ι · simp [iInf_of_empty, hg'] · exact lift_iInf hg end lift section Lift' variable {f f₁ f₂ : Filter α} {h h₁ h₂ : Set α → Set β} @[simp] theorem lift'_top (h : Set α → Set β) : (⊤ : Filter α).lift' h = 𝓟 (h univ) := lift_top _ theorem mem_lift' {t : Set α} (ht : t ∈ f) : h t ∈ f.lift' h := le_principal_iff.mp <| show f.lift' h ≤ 𝓟 (h t) from iInf_le_of_le t <| iInf_le_of_le ht <| le_rfl theorem tendsto_lift' {m : γ → β} {l : Filter γ} : Tendsto m l (f.lift' h) ↔ ∀ s ∈ f, ∀ᶠ a in l, m a ∈ h s := by simp only [Filter.lift', tendsto_lift, tendsto_principal, comp] theorem HasBasis.lift' {ι} {p : ι → Prop} {s} (hf : f.HasBasis p s) (hh : Monotone h) : (f.lift' h).HasBasis p (h ∘ s) := ⟨fun t => (hf.mem_lift_iff (fun i => hasBasis_principal (h (s i))) (monotone_principal.comp hh)).trans <| by simp only [exists_const, true_and, comp]⟩ theorem mem_lift'_sets (hh : Monotone h) {s : Set β} : s ∈ f.lift' h ↔ ∃ t ∈ f, h t ⊆ s := mem_lift_sets <| monotone_principal.comp hh theorem eventually_lift'_iff (hh : Monotone h) {p : β → Prop} : (∀ᶠ y in f.lift' h, p y) ↔ ∃ t ∈ f, ∀ y ∈ h t, p y := mem_lift'_sets hh theorem sInter_lift'_sets (hh : Monotone h) : ⋂₀ { s | s ∈ f.lift' h } = ⋂ s ∈ f, h s := (sInter_lift_sets (monotone_principal.comp hh)).trans <| iInter₂_congr fun _ _ => csInf_Ici theorem lift'_le {f : Filter α} {g : Set α → Set β} {h : Filter β} {s : Set α} (hs : s ∈ f) (hg : 𝓟 (g s) ≤ h) : f.lift' g ≤ h := lift_le hs hg theorem lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁.lift' h₁ ≤ f₂.lift' h₂ := lift_mono hf fun s => principal_mono.mpr <| hh s theorem lift'_mono' (hh : ∀ s ∈ f, h₁ s ⊆ h₂ s) : f.lift' h₁ ≤ f.lift' h₂ := iInf₂_mono fun s hs => principal_mono.mpr <| hh s hs theorem lift'_cong (hh : ∀ s ∈ f, h₁ s = h₂ s) : f.lift' h₁ = f.lift' h₂ := le_antisymm (lift'_mono' fun s hs => le_of_eq <| hh s hs) (lift'_mono' fun s hs => le_of_eq <| (hh s hs).symm) theorem map_lift'_eq {m : β → γ} (hh : Monotone h) : map m (f.lift' h) = f.lift' (image m ∘ h) := calc map m (f.lift' h) = f.lift (map m ∘ 𝓟 ∘ h) := map_lift_eq <| monotone_principal.comp hh _ = f.lift' (image m ∘ h) := by simp only [comp_def, Filter.lift', map_principal] theorem lift'_map_le {g : Set β → Set γ} {m : α → β} : (map m f).lift' g ≤ f.lift' (g ∘ image m) := lift_map_le theorem map_lift'_eq2 {g : Set β → Set γ} {m : α → β} (hg : Monotone g) : (map m f).lift' g = f.lift' (g ∘ image m) := map_lift_eq2 <| monotone_principal.comp hg theorem comap_lift'_eq {m : γ → β} : comap m (f.lift' h) = f.lift' (preimage m ∘ h) := by simp only [Filter.lift', comap_lift_eq, comp_def, comap_principal] theorem comap_lift'_eq2 {m : β → α} {g : Set β → Set γ} (hg : Monotone g) : (comap m f).lift' g = f.lift' (g ∘ preimage m) := comap_lift_eq2 <| monotone_principal.comp hg theorem lift'_principal {s : Set α} (hh : Monotone h) : (𝓟 s).lift' h = 𝓟 (h s) := lift_principal <| monotone_principal.comp hh theorem lift'_pure {a : α} (hh : Monotone h) : (pure a : Filter α).lift' h = 𝓟 (h {a}) := by rw [← principal_singleton, lift'_principal hh] theorem lift'_bot (hh : Monotone h) : (⊥ : Filter α).lift' h = 𝓟 (h ∅) := by rw [← principal_empty, lift'_principal hh] theorem le_lift' {f : Filter α} {h : Set α → Set β} {g : Filter β} : g ≤ f.lift' h ↔ ∀ s ∈ f, h s ∈ g := le_lift.trans <| forall₂_congr fun _ _ => le_principal_iff theorem principal_le_lift' {t : Set β} : 𝓟 t ≤ f.lift' h ↔ ∀ s ∈ f, t ⊆ h s := le_lift' theorem monotone_lift' [Preorder γ] {f : γ → Filter α} {g : γ → Set α → Set β} (hf : Monotone f) (hg : Monotone g) : Monotone fun c => (f c).lift' (g c) := fun _ _ h => lift'_mono (hf h) (hg h) theorem lift_lift'_assoc {g : Set α → Set β} {h : Set β → Filter γ} (hg : Monotone g) (hh : Monotone h) : (f.lift' g).lift h = f.lift fun s => h (g s) := calc (f.lift' g).lift h = f.lift fun s => (𝓟 (g s)).lift h := lift_assoc (monotone_principal.comp hg) _ = f.lift fun s => h (g s) := by simp only [lift_principal, hh, eq_self_iff_true] theorem lift'_lift'_assoc {g : Set α → Set β} {h : Set β → Set γ} (hg : Monotone g) (hh : Monotone h) : (f.lift' g).lift' h = f.lift' fun s => h (g s) := lift_lift'_assoc hg (monotone_principal.comp hh) theorem lift'_lift_assoc {g : Set α → Filter β} {h : Set β → Set γ} (hg : Monotone g) : (f.lift g).lift' h = f.lift fun s => (g s).lift' h := lift_assoc hg theorem lift_lift'_same_le_lift' {g : Set α → Set α → Set β} : (f.lift fun s => f.lift' (g s)) ≤ f.lift' fun s => g s s := lift_lift_same_le_lift theorem lift_lift'_same_eq_lift' {g : Set α → Set α → Set β} (hg₁ : ∀ s, Monotone fun t => g s t) (hg₂ : ∀ t, Monotone fun s => g s t) : (f.lift fun s => f.lift' (g s)) = f.lift' fun s => g s s := lift_lift_same_eq_lift (fun s => monotone_principal.comp (hg₁ s)) fun t => monotone_principal.comp (hg₂ t) theorem lift'_inf_principal_eq {h : Set α → Set β} {s : Set β} : f.lift' h ⊓ 𝓟 s = f.lift' fun t => h t ∩ s := by simp only [Filter.lift', Filter.lift, (· ∘ ·), ← inf_principal, iInf_subtype', ← iInf_inf] theorem lift'_neBot_iff (hh : Monotone h) : NeBot (f.lift' h) ↔ ∀ s ∈ f, (h s).Nonempty := calc NeBot (f.lift' h) ↔ ∀ s ∈ f, NeBot (𝓟 (h s)) := lift_neBot_iff (monotone_principal.comp hh) _ ↔ ∀ s ∈ f, (h s).Nonempty := by simp only [principal_neBot_iff] @[simp] theorem lift'_id {f : Filter α} : f.lift' id = f := lift_principal2 theorem lift'_iInf [Nonempty ι] {f : ι → Filter α} {g : Set α → Set β} (hg : ∀ s t, g (s ∩ t) = g s ∩ g t) : (iInf f).lift' g = ⨅ i, (f i).lift' g := lift_iInf fun s t => by simp only [inf_principal, comp, hg] theorem lift'_iInf_of_map_univ {f : ι → Filter α} {g : Set α → Set β} (hg : ∀ {s t}, g (s ∩ t) = g s ∩ g t) (hg' : g univ = univ) : (iInf f).lift' g = ⨅ i, (f i).lift' g := lift_iInf_of_map_univ (fun s t => by simp only [inf_principal, comp, hg]) (by rw [Function.comp_apply, hg', principal_univ]) theorem lift'_inf (f g : Filter α) {s : Set α → Set β} (hs : ∀ t₁ t₂, s (t₁ ∩ t₂) = s t₁ ∩ s t₂) : (f ⊓ g).lift' s = f.lift' s ⊓ g.lift' s := by rw [inf_eq_iInf, inf_eq_iInf, lift'_iInf hs] refine iInf_congr ?_ rintro (_|_) <;> rfl theorem lift'_inf_le (f g : Filter α) (s : Set α → Set β) : (f ⊓ g).lift' s ≤ f.lift' s ⊓ g.lift' s := le_inf (lift'_mono inf_le_left le_rfl) (lift'_mono inf_le_right le_rfl) theorem comap_eq_lift' {f : Filter β} {m : α → β} : comap m f = f.lift' (preimage m) := Filter.ext fun _ => (mem_lift'_sets monotone_preimage).symm end Lift' section Prod variable {f : Filter α} theorem prod_def {f : Filter α} {g : Filter β} : f ×ˢ g = f.lift fun s => g.lift' fun t => s ×ˢ t := by simpa only [Filter.lift', Filter.lift, (f.basis_sets.prod g.basis_sets).eq_biInf, iInf_prod, iInf_and] using iInf_congr fun i => iInf_comm alias mem_prod_same_iff := mem_prod_self_iff theorem prod_same_eq : f ×ˢ f = f.lift' fun t : Set α => t ×ˢ t := f.basis_sets.prod_self.eq_biInf theorem tendsto_prod_self_iff {f : α × α → β} {x : Filter α} {y : Filter β} : Filter.Tendsto f (x ×ˢ x) y ↔ ∀ W ∈ y, ∃ U ∈ x, ∀ x x' : α, x ∈ U → x' ∈ U → f (x, x') ∈ W := by simp only [tendsto_def, mem_prod_same_iff, prod_sub_preimage_iff, exists_prop] variable {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} theorem prod_lift_lift {f₁ : Filter α₁} {f₂ : Filter α₂} {g₁ : Set α₁ → Filter β₁} {g₂ : Set α₂ → Filter β₂} (hg₁ : Monotone g₁) (hg₂ : Monotone g₂) : f₁.lift g₁ ×ˢ f₂.lift g₂ = f₁.lift fun s => f₂.lift fun t => g₁ s ×ˢ g₂ t := by simp only [prod_def, lift_assoc hg₁] apply congr_arg; funext x rw [lift_comm] apply congr_arg; funext y apply lift'_lift_assoc hg₂ theorem prod_lift'_lift' {f₁ : Filter α₁} {f₂ : Filter α₂} {g₁ : Set α₁ → Set β₁} {g₂ : Set α₂ → Set β₂} (hg₁ : Monotone g₁) (hg₂ : Monotone g₂) : f₁.lift' g₁ ×ˢ f₂.lift' g₂ = f₁.lift fun s => f₂.lift' fun t => g₁ s ×ˢ g₂ t := calc f₁.lift' g₁ ×ˢ f₂.lift' g₂ = f₁.lift fun s => f₂.lift fun t => 𝓟 (g₁ s) ×ˢ 𝓟 (g₂ t) := prod_lift_lift (monotone_principal.comp hg₁) (monotone_principal.comp hg₂) _ = f₁.lift fun s => f₂.lift fun t => 𝓟 (g₁ s ×ˢ g₂ t) := by { simp only [prod_principal_principal] } end Prod end Filter
Mathlib/Order/Filter/Lift.lean
388
390
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Data.Set.Countable import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Tactic.FunProp.Attr import Mathlib.Tactic.Measurability /-! # Measurable spaces and measurable functions This file defines measurable spaces and measurable functions. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function -/ assert_not_exists Covariant MonoidWithZero open Set Encodable Function Equiv variable {α β γ δ δ' : Type*} {ι : Sort*} {s t u : Set α} /-- A measurable space is a space equipped with a σ-algebra. -/ @[class] structure MeasurableSpace (α : Type*) where /-- Predicate saying that a given set is measurable. Use `MeasurableSet` in the root namespace instead. -/ MeasurableSet' : Set α → Prop /-- The empty set is a measurable set. Use `MeasurableSet.empty` instead. -/ measurableSet_empty : MeasurableSet' ∅ /-- The complement of a measurable set is a measurable set. Use `MeasurableSet.compl` instead. -/ measurableSet_compl : ∀ s, MeasurableSet' s → MeasurableSet' sᶜ /-- The union of a sequence of measurable sets is a measurable set. Use a more general `MeasurableSet.iUnion` instead. -/ measurableSet_iUnion : ∀ f : ℕ → Set α, (∀ i, MeasurableSet' (f i)) → MeasurableSet' (⋃ i, f i) instance [h : MeasurableSpace α] : MeasurableSpace αᵒᵈ := h /-- `MeasurableSet s` means that `s` is measurable (in the ambient measure space on `α`) -/ def MeasurableSet [MeasurableSpace α] (s : Set α) : Prop := ‹MeasurableSpace α›.MeasurableSet' s /-- Notation for `MeasurableSet` with respect to a non-standard σ-algebra. -/ scoped[MeasureTheory] notation "MeasurableSet[" m "]" => @MeasurableSet _ m open MeasureTheory section open scoped symmDiff @[simp, measurability] theorem MeasurableSet.empty [MeasurableSpace α] : MeasurableSet (∅ : Set α) := MeasurableSpace.measurableSet_empty _ variable {m : MeasurableSpace α} @[measurability] protected theorem MeasurableSet.compl : MeasurableSet s → MeasurableSet sᶜ := MeasurableSpace.measurableSet_compl _ s protected theorem MeasurableSet.of_compl (h : MeasurableSet sᶜ) : MeasurableSet s := compl_compl s ▸ h.compl @[simp] theorem MeasurableSet.compl_iff : MeasurableSet sᶜ ↔ MeasurableSet s := ⟨.of_compl, .compl⟩ @[simp, measurability] protected theorem MeasurableSet.univ : MeasurableSet (univ : Set α) := .of_compl <| by simp @[nontriviality, measurability] theorem Subsingleton.measurableSet [Subsingleton α] {s : Set α} : MeasurableSet s := Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s theorem MeasurableSet.congr {s t : Set α} (hs : MeasurableSet s) (h : s = t) : MeasurableSet t := by rwa [← h] @[measurability] protected theorem MeasurableSet.iUnion [Countable ι] ⦃f : ι → Set α⦄ (h : ∀ b, MeasurableSet (f b)) : MeasurableSet (⋃ b, f b) := by cases isEmpty_or_nonempty ι · simp · rcases exists_surjective_nat ι with ⟨e, he⟩ rw [← iUnion_congr_of_surjective _ he (fun _ => rfl)] exact m.measurableSet_iUnion _ fun _ => h _ protected theorem MeasurableSet.biUnion {f : β → Set α} {s : Set β} (hs : s.Countable) (h : ∀ b ∈ s, MeasurableSet (f b)) : MeasurableSet (⋃ b ∈ s, f b) := by rw [biUnion_eq_iUnion]
have := hs.to_subtype exact MeasurableSet.iUnion (by simpa using h)
Mathlib/MeasureTheory/MeasurableSpace/Defs.lean
112
113
/- 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 /-! # Extreme sets This file defines extreme sets and extreme points for sets in a module. An extreme set of `A` is a subset of `A` that is as far as it can get in any outward direction: If point `x` is in it and point `y ∈ A`, then the line passing through `x` and `y` leaves `A` at `x`. This is an analytic notion of "being on the side of". It is weaker than being exposed (see `IsExposed.isExtreme`). ## Main declarations * `IsExtreme 𝕜 A B`: States that `B` is an extreme set of `A` (in the literature, `A` is often implicit). * `Set.extremePoints 𝕜 A`: Set of extreme points of `A` (corresponding to extreme singletons). * `Convex.mem_extremePoints_iff_convex_diff`: A useful equivalent condition to being an extreme point: `x` is an extreme point iff `A \ {x}` is convex. ## Implementation notes The exact definition of extremeness has been carefully chosen so as to make as many lemmas unconditional (in particular, the Krein-Milman theorem doesn't need the set to be convex!). In practice, `A` is often assumed to be a convex set. ## References See chapter 8 of [Barry Simon, *Convexity*][simon2011] ## TODO Prove lemmas relating extreme sets and points to the intrinsic frontier. -/ open Function Set Affine variable {𝕜 E F ι : Type*} {M : ι → Type*} section SMul variable (𝕜) [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [SMul 𝕜 E] /-- A set `B` is an extreme subset of `A` if `B ⊆ A` and all points of `B` only belong to open segments whose ends are in `B`. -/ def IsExtreme (A B : Set E) : Prop := B ⊆ A ∧ ∀ ⦃x₁⦄, x₁ ∈ A → ∀ ⦃x₂⦄, x₂ ∈ A → ∀ ⦃x⦄, x ∈ B → x ∈ openSegment 𝕜 x₁ x₂ → x₁ ∈ B ∧ x₂ ∈ B /-- A point `x` is an extreme point of a set `A` if `x` belongs to no open segment with ends in `A`, except for the obvious `openSegment x x`. In order to prove that `x` is an extreme point of `A`, it is convenient to use `mem_extremePoints_iff_left` to avoid repeating arguments twice. -/ def Set.extremePoints (A : Set E) : Set E := { x ∈ A | ∀ ⦃x₁⦄, x₁ ∈ A → ∀ ⦃x₂⦄, x₂ ∈ A → x ∈ openSegment 𝕜 x₁ x₂ → x₁ = x ∧ x₂ = x } @[refl] protected theorem IsExtreme.refl (A : Set E) : IsExtreme 𝕜 A A := ⟨Subset.rfl, fun _ hx₁A _ hx₂A _ _ _ ↦ ⟨hx₁A, hx₂A⟩⟩ variable {𝕜} {A B C : Set E} {x : E} protected theorem IsExtreme.rfl : IsExtreme 𝕜 A A := IsExtreme.refl 𝕜 A @[trans] protected theorem IsExtreme.trans (hAB : IsExtreme 𝕜 A B) (hBC : IsExtreme 𝕜 B C) : IsExtreme 𝕜 A C := by refine ⟨Subset.trans hBC.1 hAB.1, fun x₁ hx₁A x₂ hx₂A x hxC hx ↦ ?_⟩ obtain ⟨hx₁B, hx₂B⟩ := hAB.2 hx₁A hx₂A (hBC.1 hxC) hx exact hBC.2 hx₁B hx₂B hxC hx protected theorem IsExtreme.antisymm : AntiSymmetric (IsExtreme 𝕜 : Set E → Set E → Prop) := fun _ _ hAB hBA ↦ Subset.antisymm hBA.1 hAB.1
instance : IsPartialOrder (Set E) (IsExtreme 𝕜) where refl := IsExtreme.refl 𝕜 trans _ _ _ := IsExtreme.trans antisymm := IsExtreme.antisymm
Mathlib/Analysis/Convex/Extreme.lean
81
85
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Complex.Log /-! # Power function on `ℂ` We construct the power functions `x ^ y`, where `x` and `y` are complex numbers. -/ open Real Topology Filter ComplexConjugate Finset Set namespace Complex /-- The complex power function `x ^ y`, given by `x ^ y = exp(y log x)` (where `log` is the principal determination of the logarithm), unless `x = 0` where one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def cpow (x y : ℂ) : ℂ := if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) noncomputable instance : Pow ℂ ℂ := ⟨cpow⟩ @[simp] theorem cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y := rfl theorem cpow_def (x y : ℂ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := rfl theorem cpow_def_of_ne_zero {x : ℂ} (hx : x ≠ 0) (y : ℂ) : x ^ y = exp (log x * y) := if_neg hx @[simp] theorem cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def] @[simp] theorem cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [cpow_def] split_ifs <;> simp [*, exp_ne_zero] theorem cpow_ne_zero_iff {x y : ℂ} : x ^ y ≠ 0 ↔ x ≠ 0 ∨ y = 0 := by rw [ne_eq, cpow_eq_zero_iff, not_and_or, ne_eq, not_not] theorem cpow_ne_zero_iff_of_exponent_ne_zero {x y : ℂ} (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := by simp [hy] @[simp] theorem zero_cpow {x : ℂ} (h : x ≠ 0) : (0 : ℂ) ^ x = 0 := by simp [cpow_def, *] theorem zero_cpow_eq_iff {x : ℂ} {a : ℂ} : (0 : ℂ) ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [cpow_def, eq_self_iff_true, if_true] at hyp by_cases h : x = 0 · subst h simp only [if_true, eq_self_iff_true] at hyp right exact ⟨rfl, hyp.symm⟩ · rw [if_neg h] at hyp left exact ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_cpow h · exact cpow_zero _ theorem eq_zero_cpow_iff {x : ℂ} {a : ℂ} : a = (0 : ℂ) ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_cpow_eq_iff, eq_comm] @[simp] theorem cpow_one (x : ℂ) : x ^ (1 : ℂ) = x := if hx : x = 0 then by simp [hx, cpow_def] else by rw [cpow_def, if_neg (one_ne_zero : (1 : ℂ) ≠ 0), if_neg hx, mul_one, exp_log hx] @[simp] theorem one_cpow (x : ℂ) : (1 : ℂ) ^ x = 1 := by rw [cpow_def] split_ifs <;> simp_all [one_ne_zero] theorem cpow_add {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by simp only [cpow_def, ite_mul, boole_mul, mul_ite, mul_boole] simp_all [exp_add, mul_add] theorem cpow_mul {x y : ℂ} (z : ℂ) (h₁ : -π < (log x * y).im) (h₂ : (log x * y).im ≤ π) : x ^ (y * z) = (x ^ y) ^ z := by simp only [cpow_def] split_ifs <;> simp_all [exp_ne_zero, log_exp h₁ h₂, mul_assoc] theorem cpow_neg (x y : ℂ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [cpow_def, neg_eq_zero, mul_neg] split_ifs <;> simp [exp_neg] theorem cpow_sub {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, cpow_add _ _ hx, cpow_neg, div_eq_mul_inv] theorem cpow_neg_one (x : ℂ) : x ^ (-1 : ℂ) = x⁻¹ := by simpa using cpow_neg x 1 /-- See also `Complex.cpow_int_mul'`. -/ lemma cpow_int_mul (x : ℂ) (n : ℤ) (y : ℂ) : x ^ (n * y) = (x ^ y) ^ n := by rcases eq_or_ne x 0 with rfl | hx · rcases eq_or_ne n 0 with rfl | hn · simp · rcases eq_or_ne y 0 with rfl | hy <;> simp [*, zero_zpow] · rw [cpow_def_of_ne_zero hx, cpow_def_of_ne_zero hx, mul_left_comm, exp_int_mul] lemma cpow_mul_int (x y : ℂ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [mul_comm, cpow_int_mul] lemma cpow_nat_mul (x : ℂ) (n : ℕ) (y : ℂ) : x ^ (n * y) = (x ^ y) ^ n := mod_cast cpow_int_mul x n y lemma cpow_ofNat_mul (x : ℂ) (n : ℕ) [n.AtLeastTwo] (y : ℂ) : x ^ (ofNat(n) * y) = (x ^ y) ^ ofNat(n) := cpow_nat_mul x n y lemma cpow_mul_nat (x y : ℂ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [mul_comm, cpow_nat_mul] lemma cpow_mul_ofNat (x y : ℂ) (n : ℕ) [n.AtLeastTwo] : x ^ (y * ofNat(n)) = (x ^ y) ^ ofNat(n) := cpow_mul_nat x y n @[simp, norm_cast] theorem cpow_natCast (x : ℂ) (n : ℕ) : x ^ (n : ℂ) = x ^ n := by simpa using cpow_nat_mul x n 1 @[simp] lemma cpow_ofNat (x : ℂ) (n : ℕ) [n.AtLeastTwo] : x ^ (ofNat(n) : ℂ) = x ^ ofNat(n) := cpow_natCast x n theorem cpow_two (x : ℂ) : x ^ (2 : ℂ) = x ^ (2 : ℕ) := cpow_ofNat x 2 @[simp, norm_cast] theorem cpow_intCast (x : ℂ) (n : ℤ) : x ^ (n : ℂ) = x ^ n := by simpa using cpow_int_mul x n 1 @[simp] theorem cpow_nat_inv_pow (x : ℂ) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℂ)) ^ n = x := by rw [← cpow_nat_mul, mul_inv_cancel₀, cpow_one] assumption_mod_cast @[simp] lemma cpow_ofNat_inv_pow (x : ℂ) (n : ℕ) [n.AtLeastTwo] : (x ^ ((ofNat(n) : ℂ)⁻¹)) ^ (ofNat(n) : ℕ) = x := cpow_nat_inv_pow _ (NeZero.ne n) /-- A version of `Complex.cpow_int_mul` with RHS that matches `Complex.cpow_mul`. The assumptions on the arguments are needed because the equality fails, e.g., for `x = -I`, `n = 2`, `y = 1/2`. -/ lemma cpow_int_mul' {x : ℂ} {n : ℤ} (hlt : -π < n * x.arg) (hle : n * x.arg ≤ π) (y : ℂ) : x ^ (n * y) = (x ^ n) ^ y := by rw [mul_comm] at hlt hle rw [cpow_mul, cpow_intCast] <;> simpa [log_im] /-- A version of `Complex.cpow_nat_mul` with RHS that matches `Complex.cpow_mul`. The assumptions on the arguments are needed because the equality fails, e.g., for `x = -I`, `n = 2`, `y = 1/2`. -/ lemma cpow_nat_mul' {x : ℂ} {n : ℕ} (hlt : -π < n * x.arg) (hle : n * x.arg ≤ π) (y : ℂ) : x ^ (n * y) = (x ^ n) ^ y := cpow_int_mul' hlt hle y lemma cpow_ofNat_mul' {x : ℂ} {n : ℕ} [n.AtLeastTwo] (hlt : -π < OfNat.ofNat n * x.arg) (hle : OfNat.ofNat n * x.arg ≤ π) (y : ℂ) : x ^ (OfNat.ofNat n * y) = (x ^ ofNat(n)) ^ y := cpow_nat_mul' hlt hle y lemma pow_cpow_nat_inv {x : ℂ} {n : ℕ} (h₀ : n ≠ 0) (hlt : -(π / n) < x.arg) (hle : x.arg ≤ π / n) : (x ^ n) ^ (n⁻¹ : ℂ) = x := by rw [← cpow_nat_mul', mul_inv_cancel₀ (Nat.cast_ne_zero.2 h₀), cpow_one] · rwa [← div_lt_iff₀' (Nat.cast_pos.2 h₀.bot_lt), neg_div] · rwa [← le_div_iff₀' (Nat.cast_pos.2 h₀.bot_lt)] lemma pow_cpow_ofNat_inv {x : ℂ} {n : ℕ} [n.AtLeastTwo] (hlt : -(π / OfNat.ofNat n) < x.arg) (hle : x.arg ≤ π / OfNat.ofNat n) : (x ^ ofNat(n)) ^ ((OfNat.ofNat n : ℂ)⁻¹) = x := pow_cpow_nat_inv (NeZero.ne n) hlt hle /-- See also `Complex.pow_cpow_ofNat_inv` for a version that also works for `x * I`, `0 ≤ x`. -/ lemma sq_cpow_two_inv {x : ℂ} (hx : 0 < x.re) : (x ^ (2 : ℕ)) ^ (2⁻¹ : ℂ) = x := pow_cpow_ofNat_inv (neg_pi_div_two_lt_arg_iff.2 <| .inl hx) (arg_le_pi_div_two_iff.2 <| .inl hx.le) theorem mul_cpow_ofReal_nonneg {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (r : ℂ) : ((a : ℂ) * (b : ℂ)) ^ r = (a : ℂ) ^ r * (b : ℂ) ^ r := by rcases eq_or_ne r 0 with (rfl | hr) · simp only [cpow_zero, mul_one] rcases eq_or_lt_of_le ha with (rfl | ha') · rw [ofReal_zero, zero_mul, zero_cpow hr, zero_mul] rcases eq_or_lt_of_le hb with (rfl | hb') · rw [ofReal_zero, mul_zero, zero_cpow hr, mul_zero] have ha'' : (a : ℂ) ≠ 0 := ofReal_ne_zero.mpr ha'.ne' have hb'' : (b : ℂ) ≠ 0 := ofReal_ne_zero.mpr hb'.ne' rw [cpow_def_of_ne_zero (mul_ne_zero ha'' hb''), log_ofReal_mul ha' hb'', ofReal_log ha, add_mul, exp_add, ← cpow_def_of_ne_zero ha'', ← cpow_def_of_ne_zero hb''] lemma natCast_mul_natCast_cpow (m n : ℕ) (s : ℂ) : (m * n : ℂ) ^ s = m ^ s * n ^ s := ofReal_natCast m ▸ ofReal_natCast n ▸ mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg s lemma natCast_cpow_natCast_mul (n m : ℕ) (z : ℂ) : (n : ℂ) ^ (m * z) = ((n : ℂ) ^ m) ^ z := by refine cpow_nat_mul' (x := n) (n := m) ?_ ?_ z · simp only [natCast_arg, mul_zero, Left.neg_neg_iff, pi_pos] · simp only [natCast_arg, mul_zero, pi_pos.le] theorem inv_cpow_eq_ite (x : ℂ) (n : ℂ) : x⁻¹ ^ n = if x.arg = π then conj (x ^ conj n)⁻¹ else (x ^ n)⁻¹ := by simp_rw [Complex.cpow_def, log_inv_eq_ite, inv_eq_zero, map_eq_zero, ite_mul, neg_mul, RCLike.conj_inv, apply_ite conj, apply_ite exp, apply_ite Inv.inv, map_zero, map_one, exp_neg, inv_one, inv_zero, ← exp_conj, map_mul, conj_conj] split_ifs with hx hn ha ha <;> rfl theorem inv_cpow (x : ℂ) (n : ℂ) (hx : x.arg ≠ π) : x⁻¹ ^ n = (x ^ n)⁻¹ := by rw [inv_cpow_eq_ite, if_neg hx] /-- `Complex.inv_cpow_eq_ite` with the `ite` on the other side. -/ theorem inv_cpow_eq_ite' (x : ℂ) (n : ℂ) : (x ^ n)⁻¹ = if x.arg = π then conj (x⁻¹ ^ conj n) else x⁻¹ ^ n := by rw [inv_cpow_eq_ite, apply_ite conj, conj_conj, conj_conj] split_ifs with h · rfl · rw [inv_cpow _ _ h] theorem conj_cpow_eq_ite (x : ℂ) (n : ℂ) : conj x ^ n = if x.arg = π then x ^ n else conj (x ^ conj n) := by simp_rw [cpow_def, map_eq_zero, apply_ite conj, map_one, map_zero, ← exp_conj, map_mul, conj_conj, log_conj_eq_ite] split_ifs with hcx hn hx <;> rfl theorem conj_cpow (x : ℂ) (n : ℂ) (hx : x.arg ≠ π) : conj x ^ n = conj (x ^ conj n) := by rw [conj_cpow_eq_ite, if_neg hx] theorem cpow_conj (x : ℂ) (n : ℂ) (hx : x.arg ≠ π) : x ^ conj n = conj (conj x ^ n) := by rw [conj_cpow _ _ hx, conj_conj] lemma natCast_add_one_cpow_ne_zero (n : ℕ) (z : ℂ) : (n + 1 : ℂ) ^ z ≠ 0 := mt (cpow_eq_zero_iff ..).mp fun H ↦ by norm_cast at H; exact H.1 end Complex -- section Tactics -- /-! -- ## Tactic extensions for complex powers -- -/
-- namespace NormNum -- theorem cpow_pos (a b : ℂ) (b' : ℕ) (c : ℂ) (hb : b = b') (h : a ^ b' = c) : a ^ b = c := by -- rw [← h, hb, Complex.cpow_natCast]
Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean
248
253
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.CharP.Reduced import Mathlib.RingTheory.IntegralDomain -- TODO: remove Mathlib.Algebra.CharP.Reduced and move the last two lemmas to Lemmas /-! # Roots of unity We define roots of unity in the context of an arbitrary commutative monoid, as a subgroup of the group of units. ## Main definitions * `rootsOfUnity n M`, for `n : ℕ` is the subgroup of the units of a commutative monoid `M` consisting of elements `x` that satisfy `x ^ n = 1`. ## Main results * `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group. ## Implementation details It is desirable that `rootsOfUnity` is a subgroup, and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields. We therefore implement it as a subgroup of the units of a commutative monoid. We have chosen to define `rootsOfUnity n` for `n : ℕ` and add a `[NeZero n]` typeclass assumption when we need `n` to be non-zero (which is the case for most interesting statements). Note that `rootsOfUnity 0 M` is the top subgroup of `Mˣ` (as the condition `ζ^0 = 1` is satisfied for all units). -/ noncomputable section open Polynomial open Finset variable {M N G R S F : Type*} variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G] section rootsOfUnity variable {k l : ℕ} /-- `rootsOfUnity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1`. -/ def rootsOfUnity (k : ℕ) (M : Type*) [CommMonoid M] : Subgroup Mˣ where carrier := {ζ | ζ ^ k = 1} one_mem' := one_pow _ mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul] inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one] @[simp] theorem mem_rootsOfUnity (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ ζ ^ k = 1 := Iff.rfl /-- A variant of `mem_rootsOfUnity` using `ζ : Mˣ`. -/ theorem mem_rootsOfUnity' (k : ℕ) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ (ζ : M) ^ k = 1 := by rw [mem_rootsOfUnity]; norm_cast @[simp] theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = ⊥ := by ext1 simp only [mem_rootsOfUnity, pow_one, Subgroup.mem_bot] @[simp] lemma rootsOfUnity_zero (M : Type*) [CommMonoid M] : rootsOfUnity 0 M = ⊤ := by ext1 simp only [mem_rootsOfUnity, pow_zero, Subgroup.mem_top] theorem rootsOfUnity.coe_injective {n : ℕ} : Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) := Units.ext.comp fun _ _ ↦ Subtype.eq /-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has a positive power equal to one. -/ @[simps! coe_val] def rootsOfUnity.mkOfPowEq (ζ : M) {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : rootsOfUnity n M := ⟨Units.ofPowEqOne ζ n h <| NeZero.ne n, Units.pow_ofPowEqOne _ _⟩ @[simp] theorem rootsOfUnity.coe_mkOfPowEq {ζ : M} {n : ℕ} [NeZero n] (h : ζ ^ n = 1) : ((rootsOfUnity.mkOfPowEq _ h : Mˣ) : M) = ζ := rfl theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≤ rootsOfUnity l M := by obtain ⟨d, rfl⟩ := h intro ζ h simp_all only [mem_rootsOfUnity, pow_mul, one_pow] theorem map_rootsOfUnity (f : Mˣ →* Nˣ) (k : ℕ) : (rootsOfUnity k M).map f ≤ rootsOfUnity k N := by rintro _ ⟨ζ, h, rfl⟩ simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one] @[norm_cast] theorem rootsOfUnity.coe_pow [CommMonoid R] (ζ : rootsOfUnity k R) (m : ℕ) : (((ζ ^ m :) : Rˣ) : R) = ((ζ : Rˣ) : R) ^ m := by rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val] /-- The canonical isomorphism from the `n`th roots of unity in `Mˣ` to the `n`th roots of unity in `M`. -/ def rootsOfUnityUnitsMulEquiv (M : Type*) [CommMonoid M] (n : ℕ) : rootsOfUnity n Mˣ ≃* rootsOfUnity n M where toFun ζ := ⟨ζ.val, (mem_rootsOfUnity ..).mpr <| (mem_rootsOfUnity' ..).mp ζ.prop⟩ invFun ζ := ⟨toUnits ζ.val, by simp only [mem_rootsOfUnity, ← map_pow, EmbeddingLike.map_eq_one_iff] exact (mem_rootsOfUnity ..).mp ζ.prop⟩ left_inv ζ := by simp only [toUnits_val_apply, Subtype.coe_eta] right_inv ζ := by simp only [val_toUnits_apply, Subtype.coe_eta] map_mul' ζ ζ' := by simp only [Subgroup.coe_mul, Units.val_mul, MulMemClass.mk_mul_mk] section CommMonoid variable [CommMonoid R] [CommMonoid S] [FunLike F R S] /-- Restrict a ring homomorphism to the nth roots of unity. -/ def restrictRootsOfUnity [MonoidHomClass F R S] (σ : F) (n : ℕ) : rootsOfUnity n R →* rootsOfUnity n S := { toFun := fun ξ ↦ ⟨Units.map σ (ξ : Rˣ), by rw [mem_rootsOfUnity, ← map_pow, Units.ext_iff, Units.coe_map, ξ.prop] exact map_one σ⟩ map_one' := by ext1; simp only [OneMemClass.coe_one, map_one] map_mul' := fun ξ₁ ξ₂ ↦ by ext1; simp only [Subgroup.coe_mul, map_mul, MulMemClass.mk_mul_mk] } @[simp] theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (σ : F) (ζ : rootsOfUnity k R) : (restrictRootsOfUnity σ k ζ : Sˣ) = σ (ζ : Rˣ) := rfl /-- Restrict a monoid isomorphism to the nth roots of unity. -/ nonrec def MulEquiv.restrictRootsOfUnity (σ : R ≃* S) (n : ℕ) : rootsOfUnity n R ≃* rootsOfUnity n S where toFun := restrictRootsOfUnity σ n invFun := restrictRootsOfUnity σ.symm n left_inv ξ := by ext; exact σ.symm_apply_apply _ right_inv ξ := by ext; exact σ.apply_symm_apply _ map_mul' := (restrictRootsOfUnity _ n).map_mul @[simp] theorem MulEquiv.restrictRootsOfUnity_coe_apply (σ : R ≃* S) (ζ : rootsOfUnity k R) : (σ.restrictRootsOfUnity k ζ : Sˣ) = σ (ζ : Rˣ) := rfl @[simp] theorem MulEquiv.restrictRootsOfUnity_symm (σ : R ≃* S) : (σ.restrictRootsOfUnity k).symm = σ.symm.restrictRootsOfUnity k := rfl end CommMonoid section IsDomain -- The following results need `k` to be nonzero. variable [NeZero k] [CommRing R] [IsDomain R] theorem mem_rootsOfUnity_iff_mem_nthRoots {ζ : Rˣ} : ζ ∈ rootsOfUnity k R ↔ (ζ : R) ∈ nthRoots k (1 : R) := by simp only [mem_rootsOfUnity, mem_nthRoots (NeZero.pos k), Units.ext_iff, Units.val_one, Units.val_pow_eq_pow_val] variable (k R) /-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`. This is implemented as equivalence of subtypes, because `rootsOfUnity` is a subgroup of the group of units, whereas `nthRoots` is a multiset. -/ def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where toFun x := ⟨(x : Rˣ), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩ invFun x := by refine ⟨⟨x, ↑x ^ (k - 1 : ℕ), ?_, ?_⟩, ?_⟩ all_goals rcases x with ⟨x, hx⟩; rw [mem_nthRoots <| NeZero.pos k] at hx simp only [← pow_succ, ← pow_succ', hx, tsub_add_cancel_of_le NeZero.one_le] simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hx, Units.val_one] left_inv := by rintro ⟨x, hx⟩; ext; rfl right_inv := by rintro ⟨x, hx⟩; ext; rfl variable {k R} @[simp] theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) : (rootsOfUnityEquivNthRoots R k x : R) = ((x : Rˣ) : R) := rfl @[simp] theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) : (((rootsOfUnityEquivNthRoots R k).symm x : Rˣ) : R) = (x : R) := rfl variable (k R) instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) := by classical exact Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } (rootsOfUnityEquivNthRoots R k).symm instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) := isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype) coe_injective theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≤ k := by classical calc Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } := Fintype.card_congr (rootsOfUnityEquivNthRoots R k) _ ≤ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _) _ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach _ ≤ k := card_nthRoots k 1 variable {k R} theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [MonoidHomClass F R R] (σ : F) (ζ : rootsOfUnity k R) : ∃ m : ℕ, σ (ζ : Rˣ) = ((ζ : Rˣ) : R) ^ m := by obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity σ k) rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg (m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ζ)))), zpow_natCast, rootsOfUnity.coe_pow] exact ⟨(m % orderOf ζ).toNat, rfl⟩ end IsDomain section Reduced variable (R) [CommRing R] [IsReduced R] -- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'` theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} : ζ ∈ rootsOfUnity (p ^ k * m) R ↔ ζ ∈ rootsOfUnity m R := by simp only [mem_rootsOfUnity', ExpChar.pow_prime_pow_mul_eq_one_iff] /-- A variant of `mem_rootsOfUnity_prime_pow_mul_iff` in terms of `ζ ^ _` -/ @[simp] theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : ℕ) (m : ℕ) [ExpChar R p] {ζ : Rˣ} : ζ ^ (p ^ k * m) = 1 ↔ ζ ∈ rootsOfUnity m R := by rw [← mem_rootsOfUnity, mem_rootsOfUnity_prime_pow_mul_iff] end Reduced end rootsOfUnity section cyclic namespace IsCyclic /-- The isomorphism from the group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` to the group of `n`th roots of unity in `G'` determined by a generator `g` of `G`. It sends `φ : G →* G'` to `φ g`. -/ noncomputable def monoidHomMulEquivRootsOfUnityOfGenerator {G : Type*} [CommGroup G] {g : G} (hg : ∀ (x : G), x ∈ Subgroup.zpowers g) (G' : Type*) [CommGroup G'] : (G →* G') ≃* rootsOfUnity (Nat.card G) G' where toFun φ := ⟨(IsUnit.map φ <| Group.isUnit g).unit, by simp only [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, IsUnit.unit_spec, ← map_pow, pow_card_eq_one', map_one, Units.val_one]⟩ invFun ζ := monoidHomOfForallMemZpowers hg (g' := (ζ.val : G')) <| by simpa only [orderOf_eq_card_of_forall_mem_zpowers hg, orderOf_dvd_iff_pow_eq_one, ← Units.val_pow_eq_pow_val, Units.val_eq_one] using ζ.prop left_inv φ := (MonoidHom.eq_iff_eq_on_generator hg _ φ).mpr <| by simp only [IsUnit.unit_spec, monoidHomOfForallMemZpowers_apply_gen] right_inv φ := Subtype.ext <| by simp only [monoidHomOfForallMemZpowers_apply_gen, IsUnit.unit_of_val_units] map_mul' x y := by simp only [MonoidHom.mul_apply, MulMemClass.mk_mul_mk, Subtype.mk.injEq, Units.ext_iff, IsUnit.unit_spec, Units.val_mul] /-- The group of group homomorphisms from a finite cyclic group `G` of order `n` into another group `G'` is (noncanonically) isomorphic to the group of `n`th roots of unity in `G'`. -/ lemma monoidHom_mulEquiv_rootsOfUnity (G : Type*) [CommGroup G] [IsCyclic G] (G' : Type*) [CommGroup G'] : Nonempty <| (G →* G') ≃* rootsOfUnity (Nat.card G) G' := by obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := G) exact ⟨monoidHomMulEquivRootsOfUnityOfGenerator hg G'⟩ end IsCyclic end cyclic
Mathlib/RingTheory/RootsOfUnity/Basic.lean
866
873
/- 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 -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ := let ⟨n, hn⟩ := exists_nat_gt ‖z‖ have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : ℂ) : CauSeq ℂ (‖·‖) := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε rcases j with - | j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel₀ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_one₀ (norm_nonneg _) hx _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc ‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤ ∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ := calc ‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ] _ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 := calc ‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = ‖x‖ ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ _ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _ rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi · rw [Complex.norm_pow] · simp _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm · intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] · intro a ha b hb hab simpa using hab · intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ · rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 · rw [tsub_add_cancel_of_le hb.2] · simp _ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← sq_abs] have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three _ ≤ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.) rw [show 3 = 1 + 1 + 1 from rfl] repeat rw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) : Real.exp x ≤ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) · simp · exact (exp_bound_div_one_sub_of_interval' h1 h2).le theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt · exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) · linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 · simp · exact (add_one_lt_exp hx).le lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) · simp rwa [Nat.cast_zero] at ht' calc (1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by gcongr · exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg · exact one_sub_le_exp_neg _ _ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by rw [le_inv_mul_iff₀ hc] calc c * x _ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one _ ≤ _ := Real.add_one_le_exp (c * x) end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.exp $a) => assertInstancesCommute pure (.positive q(Real.exp_pos $a)) | _, _, _ => throwError "not Real.exp" end Mathlib.Meta.Positivity namespace Complex @[simp] theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by rw [← ofReal_exp] exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _)) @[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal end Complex
Mathlib/Data/Complex/Exponential.lean
1,024
1,026
/- Copyright (c) 2021 Henry Swanson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Henry Swanson -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Combinatorics.Derangements.Basic import Mathlib.Data.Fintype.BigOperators import Mathlib.Tactic.Ring /-! # Derangements on fintypes This file contains lemmas that describe the cardinality of `derangements α` when `α` is a fintype. # Main definitions * `card_derangements_invariant`: A lemma stating that the number of derangements on a type `α` depends only on the cardinality of `α`. * `numDerangements n`: The number of derangements on an n-element set, defined in a computation- friendly way. * `card_derangements_eq_numDerangements`: Proof that `numDerangements` really does compute the number of derangements. * `numDerangements_sum`: A lemma giving an expression for `numDerangements n` in terms of factorials. -/ open derangements Equiv Fintype variable {α : Type*} [DecidableEq α] [Fintype α] instance : DecidablePred (derangements α) := fun _ => Fintype.decidableForallFintype -- Porting note: used to use the tactic delta_instance instance : Fintype (derangements α) := Subtype.fintype (fun (_ : Perm α) => ∀ (x_1 : α), ¬_ = x_1) theorem card_derangements_invariant {α β : Type*} [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β] (h : card α = card β) : card (derangements α) = card (derangements β) := Fintype.card_congr (Equiv.derangementsCongr <| equivOfCardEq h) theorem card_derangements_fin_add_two (n : ℕ) : card (derangements (Fin (n + 2))) = (n + 1) * card (derangements (Fin n)) + (n + 1) * card (derangements (Fin (n + 1))) := by -- get some basic results about the size of Fin (n+1) plus or minus an element have h1 : ∀ a : Fin (n + 1), card ({a}ᶜ : Set (Fin (n + 1))) = card (Fin n) := by intro a simp only [card_ofFinset (s := Finset.filter (fun x => x ∈ ({a}ᶜ : Set (Fin (n + 1)))) Finset.univ), Set.mem_compl_singleton_iff, Finset.filter_ne' _ a, Finset.card_erase_of_mem (Finset.mem_univ a), Finset.card_fin, add_tsub_cancel_right, card_fin] have h2 : card (Fin (n + 2)) = card (Option (Fin (n + 1))) := by simp only [card_fin, card_option] -- rewrite the LHS and substitute in our fintype-level equivalence simp only [card_derangements_invariant h2, card_congr (@derangementsRecursionEquiv (Fin (n + 1)) _),-- push the cardinality through the Σ and ⊕ so that we can use `card_n` card_sigma, card_sum, card_derangements_invariant (h1 _), Finset.sum_const, nsmul_eq_mul, Finset.card_fin, mul_add, Nat.cast_id] /-- The number of derangements of an `n`-element set. -/ def numDerangements : ℕ → ℕ | 0 => 1 | 1 => 0 | n + 2 => (n + 1) * (numDerangements n + numDerangements (n + 1)) @[simp] theorem numDerangements_zero : numDerangements 0 = 1 := rfl @[simp] theorem numDerangements_one : numDerangements 1 = 0 := rfl theorem numDerangements_add_two (n : ℕ) : numDerangements (n + 2) = (n + 1) * (numDerangements n + numDerangements (n + 1)) := rfl theorem numDerangements_succ (n : ℕ) : (numDerangements (n + 1) : ℤ) = (n + 1) * (numDerangements n : ℤ) - (-1) ^ n := by induction n with | zero => rfl | succ n hn => simp only [numDerangements_add_two, hn, pow_succ, Int.natCast_mul, Int.natCast_add] ring theorem card_derangements_fin_eq_numDerangements {n : ℕ} : card (derangements (Fin n)) = numDerangements n := by induction n using Nat.strongRecOn with | ind n hyp => _ rcases n with _ | _ | n -- knock out cases 0 and 1 · rfl · rfl -- now we have n ≥ 2. rewrite everything in terms of card_derangements, so that we can use -- `card_derangements_fin_add_two` rw [numDerangements_add_two, card_derangements_fin_add_two, mul_add, hyp, hyp] <;> omega theorem card_derangements_eq_numDerangements (α : Type*) [Fintype α] [DecidableEq α] : card (derangements α) = numDerangements (card α) := by rw [← card_derangements_invariant (card_fin _)] exact card_derangements_fin_eq_numDerangements theorem numDerangements_sum (n : ℕ) : (numDerangements n : ℤ) = ∑ k ∈ Finset.range (n + 1), (-1 : ℤ) ^ k * Nat.ascFactorial (k + 1) (n - k) := by induction n with | zero => rfl | succ n hn => rw [Finset.sum_range_succ, numDerangements_succ, hn, Finset.mul_sum, tsub_self, Nat.ascFactorial_zero, Int.ofNat_one, mul_one, pow_succ', neg_one_mul, sub_eq_add_neg,
add_left_inj, Finset.sum_congr rfl] -- show that (n + 1) * (-1)^x * asc_fac x (n - x) = (-1)^x * asc_fac x (n.succ - x) intro x hx have h_le : x ≤ n := Finset.mem_range_succ_iff.mp hx rw [Nat.succ_sub h_le, Nat.ascFactorial_succ, add_right_comm, add_tsub_cancel_of_le h_le, Int.natCast_mul, Int.natCast_add, mul_left_comm, Nat.cast_one]
Mathlib/Combinatorics/Derangements/Finite.lean
113
124
/- 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.Order.Group.Pointwise.Interval import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Prod import Mathlib.Tactic.Abel import Mathlib.Algebra.AddTorsor.Basic import Mathlib.LinearAlgebra.AffineSpace.Defs /-! # Affine maps This file defines affine maps. ## Main definitions * `AffineMap` is the type of affine maps between two affine spaces with the same ring `k`. Various basic examples of affine maps are defined, including `const`, `id`, `lineMap` and `homothety`. ## Notations * `P1 →ᵃ[k] P2` is a notation for `AffineMap k P1 P2`; * `AffineSpace V P`: a localized notation for `AddTorsor V P` defined in `LinearAlgebra.AffineSpace.Basic`. ## Implementation notes `outParam` is used in the definition of `[AddTorsor V P]` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.Normed.Affine.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ open Affine /-- An `AffineMap k P1 P2` (notation: `P1 →ᵃ[k] P2`) is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ structure AffineMap (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] where toFun : P1 → P2 linear : V1 →ₗ[k] V2 map_vadd' : ∀ (p : P1) (v : V1), toFun (v +ᵥ p) = linear v +ᵥ toFun p /-- An `AffineMap k P1 P2` (notation: `P1 →ᵃ[k] P2`) is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ notation:25 P1 " →ᵃ[" k:25 "] " P2:0 => AffineMap k P1 P2 instance AffineMap.instFunLike (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] : FunLike (P1 →ᵃ[k] P2) P1 P2 where coe := AffineMap.toFun coe_injective' := fun ⟨f, f_linear, f_add⟩ ⟨g, g_linear, g_add⟩ => fun (h : f = g) => by obtain ⟨p⟩ := (AddTorsor.nonempty : Nonempty P1) congr with v apply vadd_right_cancel (f p) rw [← f_add, h, ← g_add] namespace LinearMap variable {k : Type*} {V₁ : Type*} {V₂ : Type*} [Ring k] [AddCommGroup V₁] [Module k V₁] [AddCommGroup V₂] [Module k V₂] (f : V₁ →ₗ[k] V₂) /-- Reinterpret a linear map as an affine map. -/ def toAffineMap : V₁ →ᵃ[k] V₂ where toFun := f linear := f map_vadd' p v := f.map_add v p @[simp] theorem coe_toAffineMap : ⇑f.toAffineMap = f := rfl @[simp] theorem toAffineMap_linear : f.toAffineMap.linear = f := rfl end LinearMap namespace AffineMap variable {k : Type*} {V1 : Type*} {P1 : Type*} {V2 : Type*} {P2 : Type*} {V3 : Type*} {P3 : Type*} {V4 : Type*} {P4 : Type*} [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] [AddCommGroup V3] [Module k V3] [AffineSpace V3 P3] [AddCommGroup V4] [Module k V4] [AffineSpace V4 P4] /-- Constructing an affine map and coercing back to a function produces the same map. -/ @[simp] theorem coe_mk (f : P1 → P2) (linear add) : ((mk f linear add : P1 →ᵃ[k] P2) : P1 → P2) = f := rfl /-- `toFun` is the same as the result of coercing to a function. -/ @[simp] theorem toFun_eq_coe (f : P1 →ᵃ[k] P2) : f.toFun = ⇑f := rfl /-- An affine map on the result of adding a vector to a point produces the same result as the linear map applied to that vector, added to the affine map applied to that point. -/ @[simp] theorem map_vadd (f : P1 →ᵃ[k] P2) (p : P1) (v : V1) : f (v +ᵥ p) = f.linear v +ᵥ f p := f.map_vadd' p v /-- The linear map on the result of subtracting two points is the result of subtracting the result of the affine map on those two points. -/ @[simp] theorem linearMap_vsub (f : P1 →ᵃ[k] P2) (p1 p2 : P1) : f.linear (p1 -ᵥ p2) = f p1 -ᵥ f p2 := by conv_rhs => rw [← vsub_vadd p1 p2, map_vadd, vadd_vsub] /-- Two affine maps are equal if they coerce to the same function. -/ @[ext] theorem ext {f g : P1 →ᵃ[k] P2} (h : ∀ p, f p = g p) : f = g := DFunLike.ext _ _ h theorem coeFn_injective : @Function.Injective (P1 →ᵃ[k] P2) (P1 → P2) (⇑) := DFunLike.coe_injective protected theorem congr_arg (f : P1 →ᵃ[k] P2) {x y : P1} (h : x = y) : f x = f y := congr_arg _ h protected theorem congr_fun {f g : P1 →ᵃ[k] P2} (h : f = g) (x : P1) : f x = g x := h ▸ rfl /-- Two affine maps are equal if they have equal linear maps and are equal at some point. -/ theorem ext_linear {f g : P1 →ᵃ[k] P2} (h₁ : f.linear = g.linear) {p : P1} (h₂ : f p = g p) : f = g := by ext q have hgl : g.linear (q -ᵥ p) = toFun g ((q -ᵥ p) +ᵥ q) -ᵥ toFun g q := by simp have := f.map_vadd' q (q -ᵥ p) rw [h₁, hgl, toFun_eq_coe, map_vadd, linearMap_vsub, h₂] at this simpa /-- Two affine maps are equal if they have equal linear maps and are equal at some point. -/ theorem ext_linear_iff {f g : P1 →ᵃ[k] P2} : f = g ↔ (f.linear = g.linear) ∧ (∃ p, f p = g p) := ⟨fun h ↦ ⟨congrArg _ h, by inhabit P1; exact default, by rw [h]⟩, fun h ↦ Exists.casesOn h.2 fun _ hp ↦ ext_linear h.1 hp⟩ variable (k P1) /-- The constant function as an `AffineMap`. -/ def const (p : P2) : P1 →ᵃ[k] P2 where toFun := Function.const P1 p linear := 0 map_vadd' _ _ := letI : AddAction V2 P2 := inferInstance by simp @[simp] theorem coe_const (p : P2) : ⇑(const k P1 p) = Function.const P1 p := rfl @[simp] theorem const_apply (p : P2) (q : P1) : (const k P1 p) q = p := rfl @[simp] theorem const_linear (p : P2) : (const k P1 p).linear = 0 := rfl variable {k P1} theorem linear_eq_zero_iff_exists_const (f : P1 →ᵃ[k] P2) : f.linear = 0 ↔ ∃ q, f = const k P1 q := by refine ⟨fun h => ?_, fun h => ?_⟩ · use f (Classical.arbitrary P1) ext rw [coe_const, Function.const_apply, ← @vsub_eq_zero_iff_eq V2, ← f.linearMap_vsub, h, LinearMap.zero_apply] · rcases h with ⟨q, rfl⟩ exact const_linear k P1 q instance nonempty : Nonempty (P1 →ᵃ[k] P2) := (AddTorsor.nonempty : Nonempty P2).map <| const k P1 /-- Construct an affine map by verifying the relation between the map and its linear part at one base point. Namely, this function takes a map `f : P₁ → P₂`, a linear map `f' : V₁ →ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have `f p' = f' (p' -ᵥ p) +ᵥ f p`. -/ def mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p : P1) (h : ∀ p' : P1, f p' = f' (p' -ᵥ p) +ᵥ f p) : P1 →ᵃ[k] P2 where toFun := f linear := f' map_vadd' p' v := by rw [h, h p', vadd_vsub_assoc, f'.map_add, vadd_vadd] @[simp] theorem coe_mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : ⇑(mk' f f' p h) = f := rfl @[simp] theorem mk'_linear (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : (mk' f f' p h).linear = f' := rfl section SMul variable {R : Type*} [Monoid R] [DistribMulAction R V2] [SMulCommClass k R V2] /-- The space of affine maps to a module inherits an `R`-action from the action on its codomain. -/ instance mulAction : MulAction R (P1 →ᵃ[k] V2) where smul c f := ⟨c • ⇑f, c • f.linear, fun p v => by simp [smul_add]⟩ one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ @[simp, norm_cast] theorem coe_smul (c : R) (f : P1 →ᵃ[k] V2) : ⇑(c • f) = c • ⇑f := rfl @[simp] theorem smul_linear (t : R) (f : P1 →ᵃ[k] V2) : (t • f).linear = t • f.linear := rfl instance isCentralScalar [DistribMulAction Rᵐᵒᵖ V2] [IsCentralScalar R V2] : IsCentralScalar R (P1 →ᵃ[k] V2) where op_smul_eq_smul _r _x := ext fun _ => op_smul_eq_smul _ _ end SMul instance : Zero (P1 →ᵃ[k] V2) where zero := ⟨0, 0, fun _ _ => (zero_vadd _ _).symm⟩ instance : Add (P1 →ᵃ[k] V2) where add f g := ⟨f + g, f.linear + g.linear, fun p v => by simp [add_add_add_comm]⟩ instance : Sub (P1 →ᵃ[k] V2) where sub f g := ⟨f - g, f.linear - g.linear, fun p v => by simp [sub_add_sub_comm]⟩ instance : Neg (P1 →ᵃ[k] V2) where neg f := ⟨-f, -f.linear, fun p v => by simp [add_comm, map_vadd f]⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : P1 →ᵃ[k] V2) = 0 := rfl @[simp, norm_cast] theorem coe_add (f g : P1 →ᵃ[k] V2) : ⇑(f + g) = f + g := rfl @[simp, norm_cast] theorem coe_neg (f : P1 →ᵃ[k] V2) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem coe_sub (f g : P1 →ᵃ[k] V2) : ⇑(f - g) = f - g := rfl @[simp] theorem zero_linear : (0 : P1 →ᵃ[k] V2).linear = 0 := rfl @[simp] theorem add_linear (f g : P1 →ᵃ[k] V2) : (f + g).linear = f.linear + g.linear := rfl @[simp] theorem sub_linear (f g : P1 →ᵃ[k] V2) : (f - g).linear = f.linear - g.linear := rfl @[simp] theorem neg_linear (f : P1 →ᵃ[k] V2) : (-f).linear = -f.linear := rfl /-- The set of affine maps to a vector space is an additive commutative group. -/ instance : AddCommGroup (P1 →ᵃ[k] V2) := coeFn_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ /-- The space of affine maps from `P1` to `P2` is an affine space over the space of affine maps from `P1` to the vector space `V2` corresponding to `P2`. -/ instance : AffineSpace (P1 →ᵃ[k] V2) (P1 →ᵃ[k] P2) where vadd f g := ⟨fun p => f p +ᵥ g p, f.linear + g.linear, fun p v => by simp [vadd_vadd, add_right_comm]⟩ zero_vadd f := ext fun p => zero_vadd _ (f p) add_vadd f₁ f₂ f₃ := ext fun p => add_vadd (f₁ p) (f₂ p) (f₃ p) vsub f g := ⟨fun p => f p -ᵥ g p, f.linear - g.linear, fun p v => by simp [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub, sub_add_eq_add_sub]⟩ vsub_vadd' f g := ext fun p => vsub_vadd (f p) (g p) vadd_vsub' f g := ext fun p => vadd_vsub (f p) (g p) @[simp] theorem vadd_apply (f : P1 →ᵃ[k] V2) (g : P1 →ᵃ[k] P2) (p : P1) : (f +ᵥ g) p = f p +ᵥ g p := rfl @[simp] theorem vsub_apply (f g : P1 →ᵃ[k] P2) (p : P1) : (f -ᵥ g : P1 →ᵃ[k] V2) p = f p -ᵥ g p := rfl /-- `Prod.fst` as an `AffineMap`. -/ def fst : P1 × P2 →ᵃ[k] P1 where toFun := Prod.fst linear := LinearMap.fst k V1 V2 map_vadd' _ _ := rfl @[simp] theorem coe_fst : ⇑(fst : P1 × P2 →ᵃ[k] P1) = Prod.fst := rfl @[simp] theorem fst_linear : (fst : P1 × P2 →ᵃ[k] P1).linear = LinearMap.fst k V1 V2 := rfl /-- `Prod.snd` as an `AffineMap`. -/ def snd : P1 × P2 →ᵃ[k] P2 where toFun := Prod.snd linear := LinearMap.snd k V1 V2 map_vadd' _ _ := rfl @[simp] theorem coe_snd : ⇑(snd : P1 × P2 →ᵃ[k] P2) = Prod.snd := rfl @[simp] theorem snd_linear : (snd : P1 × P2 →ᵃ[k] P2).linear = LinearMap.snd k V1 V2 := rfl variable (k P1) /-- Identity map as an affine map. -/ nonrec def id : P1 →ᵃ[k] P1 where toFun := id linear := LinearMap.id map_vadd' _ _ := rfl /-- The identity affine map acts as the identity. -/ @[simp, norm_cast] theorem coe_id : ⇑(id k P1) = _root_.id := rfl @[simp] theorem id_linear : (id k P1).linear = LinearMap.id := rfl variable {P1} /-- The identity affine map acts as the identity. -/ theorem id_apply (p : P1) : id k P1 p = p := rfl variable {k} instance : Inhabited (P1 →ᵃ[k] P1) := ⟨id k P1⟩ /-- Composition of affine maps. -/ def comp (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) : P1 →ᵃ[k] P3 where toFun := f ∘ g linear := f.linear.comp g.linear map_vadd' := by intro p v rw [Function.comp_apply, g.map_vadd, f.map_vadd] rfl /-- Composition of affine maps acts as applying the two functions. -/ @[simp] theorem coe_comp (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) : ⇑(f.comp g) = f ∘ g := rfl /-- Composition of affine maps acts as applying the two functions. -/ theorem comp_apply (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) (p : P1) : f.comp g p = f (g p) := rfl @[simp] theorem comp_id (f : P1 →ᵃ[k] P2) : f.comp (id k P1) = f := ext fun _ => rfl @[simp] theorem id_comp (f : P1 →ᵃ[k] P2) : (id k P2).comp f = f := ext fun _ => rfl theorem comp_assoc (f₃₄ : P3 →ᵃ[k] P4) (f₂₃ : P2 →ᵃ[k] P3) (f₁₂ : P1 →ᵃ[k] P2) : (f₃₄.comp f₂₃).comp f₁₂ = f₃₄.comp (f₂₃.comp f₁₂) := rfl instance : Monoid (P1 →ᵃ[k] P1) where one := id k P1 mul := comp one_mul := id_comp mul_one := comp_id mul_assoc := comp_assoc @[simp] theorem coe_mul (f g : P1 →ᵃ[k] P1) : ⇑(f * g) = f ∘ g := rfl @[simp] theorem coe_one : ⇑(1 : P1 →ᵃ[k] P1) = _root_.id := rfl /-- `AffineMap.linear` on endomorphisms is a `MonoidHom`. -/ @[simps] def linearHom : (P1 →ᵃ[k] P1) →* V1 →ₗ[k] V1 where toFun := linear map_one' := rfl map_mul' _ _ := rfl @[simp] theorem linear_injective_iff (f : P1 →ᵃ[k] P2) : Function.Injective f.linear ↔ Function.Injective f := by obtain ⟨p⟩ := (inferInstance : Nonempty P1) have h : ⇑f.linear = (Equiv.vaddConst (f p)).symm ∘ f ∘ Equiv.vaddConst p := by ext v simp [f.map_vadd, vadd_vsub_assoc] rw [h, Equiv.comp_injective, Equiv.injective_comp] @[simp] theorem linear_surjective_iff (f : P1 →ᵃ[k] P2) : Function.Surjective f.linear ↔ Function.Surjective f := by obtain ⟨p⟩ := (inferInstance : Nonempty P1) have h : ⇑f.linear = (Equiv.vaddConst (f p)).symm ∘ f ∘ Equiv.vaddConst p := by ext v simp [f.map_vadd, vadd_vsub_assoc] rw [h, Equiv.comp_surjective, Equiv.surjective_comp] @[simp] theorem linear_bijective_iff (f : P1 →ᵃ[k] P2) : Function.Bijective f.linear ↔ Function.Bijective f := and_congr f.linear_injective_iff f.linear_surjective_iff theorem image_vsub_image {s t : Set P1} (f : P1 →ᵃ[k] P2) : f '' s -ᵥ f '' t = f.linear '' (s -ᵥ t) := by ext v simp only [Set.mem_vsub, Set.mem_image, exists_exists_and_eq_and, exists_and_left, ← f.linearMap_vsub] constructor · rintro ⟨x, hx, y, hy, hv⟩ exact ⟨x -ᵥ y, ⟨x, hx, y, hy, rfl⟩, hv⟩ · rintro ⟨-, ⟨x, hx, y, hy, rfl⟩, rfl⟩ exact ⟨x, hx, y, hy, rfl⟩ /-! ### Definition of `AffineMap.lineMap` and lemmas about it -/ /-- The affine map from `k` to `P1` sending `0` to `p₀` and `1` to `p₁`. -/ def lineMap (p₀ p₁ : P1) : k →ᵃ[k] P1 := ((LinearMap.id : k →ₗ[k] k).smulRight (p₁ -ᵥ p₀)).toAffineMap +ᵥ const k k p₀ theorem coe_lineMap (p₀ p₁ : P1) : (lineMap p₀ p₁ : k → P1) = fun c => c • (p₁ -ᵥ p₀) +ᵥ p₀ := rfl theorem lineMap_apply (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c = c • (p₁ -ᵥ p₀) +ᵥ p₀ := rfl theorem lineMap_apply_module' (p₀ p₁ : V1) (c : k) : lineMap p₀ p₁ c = c • (p₁ - p₀) + p₀ := rfl theorem lineMap_apply_module (p₀ p₁ : V1) (c : k) : lineMap p₀ p₁ c = (1 - c) • p₀ + c • p₁ := by simp [lineMap_apply_module', smul_sub, sub_smul]; abel theorem lineMap_apply_ring' (a b c : k) : lineMap a b c = c * (b - a) + a := rfl theorem lineMap_apply_ring (a b c : k) : lineMap a b c = (1 - c) * a + c * b := lineMap_apply_module a b c theorem lineMap_vadd_apply (p : P1) (v : V1) (c : k) : lineMap p (v +ᵥ p) c = c • v +ᵥ p := by rw [lineMap_apply, vadd_vsub] @[simp] theorem lineMap_linear (p₀ p₁ : P1) : (lineMap p₀ p₁ : k →ᵃ[k] P1).linear = LinearMap.id.smulRight (p₁ -ᵥ p₀) := add_zero _ theorem lineMap_same_apply (p : P1) (c : k) : lineMap p p c = p := by simp [lineMap_apply] @[simp] theorem lineMap_same (p : P1) : lineMap p p = const k k p := ext <| lineMap_same_apply p @[simp] theorem lineMap_apply_zero (p₀ p₁ : P1) : lineMap p₀ p₁ (0 : k) = p₀ := by simp [lineMap_apply] @[simp] theorem lineMap_apply_one (p₀ p₁ : P1) : lineMap p₀ p₁ (1 : k) = p₁ := by simp [lineMap_apply] @[simp] theorem lineMap_eq_lineMap_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c₁ c₂ : k} : lineMap p₀ p₁ c₁ = lineMap p₀ p₁ c₂ ↔ p₀ = p₁ ∨ c₁ = c₂ := by rw [lineMap_apply, lineMap_apply, ← @vsub_eq_zero_iff_eq V1, vadd_vsub_vadd_cancel_right, ← sub_smul, smul_eq_zero, sub_eq_zero, vsub_eq_zero_iff_eq, or_comm, eq_comm] @[simp] theorem lineMap_eq_left_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c : k} : lineMap p₀ p₁ c = p₀ ↔ p₀ = p₁ ∨ c = 0 := by rw [← @lineMap_eq_lineMap_iff k V1, lineMap_apply_zero] @[simp] theorem lineMap_eq_right_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c : k} : lineMap p₀ p₁ c = p₁ ↔ p₀ = p₁ ∨ c = 1 := by rw [← @lineMap_eq_lineMap_iff k V1, lineMap_apply_one] variable (k) in theorem lineMap_injective [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} (h : p₀ ≠ p₁) : Function.Injective (lineMap p₀ p₁ : k → P1) := fun _c₁ _c₂ hc => (lineMap_eq_lineMap_iff.mp hc).resolve_left h @[simp] theorem apply_lineMap (f : P1 →ᵃ[k] P2) (p₀ p₁ : P1) (c : k) : f (lineMap p₀ p₁ c) = lineMap (f p₀) (f p₁) c := by simp [lineMap_apply] @[simp] theorem comp_lineMap (f : P1 →ᵃ[k] P2) (p₀ p₁ : P1) : f.comp (lineMap p₀ p₁) = lineMap (f p₀) (f p₁) := ext <| f.apply_lineMap p₀ p₁ @[simp] theorem fst_lineMap (p₀ p₁ : P1 × P2) (c : k) : (lineMap p₀ p₁ c).1 = lineMap p₀.1 p₁.1 c := fst.apply_lineMap p₀ p₁ c @[simp] theorem snd_lineMap (p₀ p₁ : P1 × P2) (c : k) : (lineMap p₀ p₁ c).2 = lineMap p₀.2 p₁.2 c := snd.apply_lineMap p₀ p₁ c theorem lineMap_symm (p₀ p₁ : P1) : lineMap p₀ p₁ = (lineMap p₁ p₀).comp (lineMap (1 : k) (0 : k)) := by rw [comp_lineMap] simp theorem lineMap_apply_one_sub (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ (1 - c) = lineMap p₁ p₀ c := by rw [lineMap_symm p₀, comp_apply] congr simp [lineMap_apply] @[simp] theorem lineMap_vsub_left (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c -ᵥ p₀ = c • (p₁ -ᵥ p₀) := vadd_vsub _ _ @[simp] theorem left_vsub_lineMap (p₀ p₁ : P1) (c : k) : p₀ -ᵥ lineMap p₀ p₁ c = c • (p₀ -ᵥ p₁) := by rw [← neg_vsub_eq_vsub_rev, lineMap_vsub_left, ← smul_neg, neg_vsub_eq_vsub_rev] @[simp] theorem lineMap_vsub_right (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c -ᵥ p₁ = (1 - c) • (p₀ -ᵥ p₁) := by rw [← lineMap_apply_one_sub, lineMap_vsub_left] @[simp] theorem right_vsub_lineMap (p₀ p₁ : P1) (c : k) : p₁ -ᵥ lineMap p₀ p₁ c = (1 - c) • (p₁ -ᵥ p₀) := by rw [← lineMap_apply_one_sub, left_vsub_lineMap] theorem lineMap_vadd_lineMap (v₁ v₂ : V1) (p₁ p₂ : P1) (c : k) : lineMap v₁ v₂ c +ᵥ lineMap p₁ p₂ c = lineMap (v₁ +ᵥ p₁) (v₂ +ᵥ p₂) c := ((fst : V1 × P1 →ᵃ[k] V1) +ᵥ (snd : V1 × P1 →ᵃ[k] P1)).apply_lineMap (v₁, p₁) (v₂, p₂) c theorem lineMap_vsub_lineMap (p₁ p₂ p₃ p₄ : P1) (c : k) : lineMap p₁ p₂ c -ᵥ lineMap p₃ p₄ c = lineMap (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) c := ((fst : P1 × P1 →ᵃ[k] P1) -ᵥ (snd : P1 × P1 →ᵃ[k] P1)).apply_lineMap (_, _) (_, _) c @[simp] lemma lineMap_lineMap_right (p₀ p₁ : P1) (c d : k) : lineMap p₀ (lineMap p₀ p₁ c) d = lineMap p₀ p₁ (d * c) := by simp [lineMap_apply, mul_smul] @[simp] lemma lineMap_lineMap_left (p₀ p₁ : P1) (c d : k) : lineMap (lineMap p₀ p₁ c) p₁ d = lineMap p₀ p₁ (1 - (1 - d) * (1 - c)) := by simp_rw [lineMap_apply_one_sub, ← lineMap_apply_one_sub p₁, lineMap_lineMap_right] /-- Decomposition of an affine map in the special case when the point space and vector space are the same. -/ theorem decomp (f : V1 →ᵃ[k] V2) : (f : V1 → V2) = ⇑f.linear + fun _ => f 0 := by ext x calc f x = f.linear x +ᵥ f 0 := by rw [← f.map_vadd, vadd_eq_add, add_zero] _ = (f.linear + fun _ : V1 => f 0) x := rfl /-- Decomposition of an affine map in the special case when the point space and vector space are the same. -/ theorem decomp' (f : V1 →ᵃ[k] V2) : (f.linear : V1 → V2) = ⇑f - fun _ => f 0 := by rw [decomp] simp only [LinearMap.map_zero, Pi.add_apply, add_sub_cancel_right, zero_add] theorem image_uIcc {k : Type*} [Field k] [LinearOrder k] [IsStrictOrderedRing k] (f : k →ᵃ[k] k) (a b : k) : f '' Set.uIcc a b = Set.uIcc (f a) (f b) := by have : ⇑f = (fun x => x + f 0) ∘ fun x => x * (f 1 - f 0) := by ext x change f x = x • (f 1 -ᵥ f 0) +ᵥ f 0 rw [← f.linearMap_vsub, ← f.linear.map_smul, ← f.map_vadd] simp only [vsub_eq_sub, add_zero, mul_one, vadd_eq_add, sub_zero, smul_eq_mul] rw [this, Set.image_comp] simp only [Set.image_add_const_uIcc, Set.image_mul_const_uIcc, Function.comp_apply] section variable {ι : Type*} {V : ι → Type*} {P : ι → Type*} [∀ i, AddCommGroup (V i)] [∀ i, Module k (V i)] [∀ i, AddTorsor (V i) (P i)] /-- Evaluation at a point as an affine map. -/ def proj (i : ι) : (∀ i : ι, P i) →ᵃ[k] P i where toFun f := f i linear := @LinearMap.proj k ι _ V _ _ i map_vadd' _ _ := rfl @[simp] theorem proj_apply (i : ι) (f : ∀ i, P i) : @proj k _ ι V P _ _ _ i f = f i := rfl @[simp] theorem proj_linear (i : ι) : (@proj k _ ι V P _ _ _ i).linear = @LinearMap.proj k ι _ V _ _ i := rfl theorem pi_lineMap_apply (f g : ∀ i, P i) (c : k) (i : ι) : lineMap f g c i = lineMap (f i) (g i) c := (proj i : (∀ i, P i) →ᵃ[k] P i).apply_lineMap f g c end end AffineMap namespace AffineMap variable {R k V1 P1 V2 P2 V3 P3 : Type*} section Ring variable [Ring k] [AddCommGroup V1] [AffineSpace V1 P1] [AddCommGroup V2] [AffineSpace V2 P2] variable [AddCommGroup V3] [AffineSpace V3 P3] [Module k V1] [Module k V2] [Module k V3] section DistribMulAction variable [Monoid R] [DistribMulAction R V2] [SMulCommClass k R V2] /-- The space of affine maps to a module inherits an `R`-action from the action on its codomain. -/ instance distribMulAction : DistribMulAction R (P1 →ᵃ[k] V2) where smul_add _ _ _ := ext fun _ => smul_add _ _ _ smul_zero _ := ext fun _ => smul_zero _ end DistribMulAction section Module variable [Semiring R] [Module R V2] [SMulCommClass k R V2] /-- The space of affine maps taking values in an `R`-module is an `R`-module. -/ instance : Module R (P1 →ᵃ[k] V2) := { AffineMap.distribMulAction with add_smul := fun _ _ _ => ext fun _ => add_smul _ _ _ zero_smul := fun _ => ext fun _ => zero_smul _ _ } variable (R) /-- The space of affine maps between two modules is linearly equivalent to the product of the domain with the space of linear maps, by taking the value of the affine map at `(0 : V1)` and the linear part. See note [bundled maps over different rings] -/ @[simps] def toConstProdLinearMap : (V1 →ᵃ[k] V2) ≃ₗ[R] V2 × (V1 →ₗ[k] V2) where toFun f := ⟨f 0, f.linear⟩ invFun p := p.2.toAffineMap + const k V1 p.1 left_inv f := by ext rw [f.decomp] simp [const_apply] right_inv := by rintro ⟨v, f⟩ ext <;> simp [const_apply, const_linear] map_add' := by simp map_smul' := by simp end Module section Pi
variable {ι : Type*} {φv φp : ι → Type*} [(i : ι) → AddCommGroup (φv i)] [(i : ι) → Module k (φv i)] [(i : ι) → AffineSpace (φv i) (φp i)]
Mathlib/LinearAlgebra/AffineSpace/AffineMap.lean
671
673
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Data.Countable.Basic import Mathlib.Data.Fin.VecNotation import Mathlib.Order.Disjointed import Mathlib.MeasureTheory.OuterMeasure.Defs import Mathlib.Topology.Instances.ENNReal.Lemmas /-! # Outer Measures An outer measure is a function `μ : Set α → ℝ≥0∞`, from the powerset of a type to the extended nonnegative real numbers that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is monotone; 3. `μ` is countably subadditive. This means that the outer measure of a countable union is at most the sum of the outer measure on the individual sets. Note that we do not need `α` to be measurable to define an outer measure. ## References <https://en.wikipedia.org/wiki/Outer_measure> ## Tags outer measure -/ noncomputable section open Set Function Filter open scoped NNReal Topology ENNReal namespace MeasureTheory section OuterMeasureClass variable {α ι F : Type*} [FunLike F (Set α) ℝ≥0∞] [OuterMeasureClass F α] {μ : F} {s t : Set α} @[simp] theorem measure_empty : μ ∅ = 0 := OuterMeasureClass.measure_empty μ @[mono, gcongr] theorem measure_mono (h : s ⊆ t) : μ s ≤ μ t := OuterMeasureClass.measure_mono μ h theorem measure_mono_null (h : s ⊆ t) (ht : μ t = 0) : μ s = 0 := eq_bot_mono (measure_mono h) ht lemma measure_eq_top_mono (h : s ⊆ t) (hs : μ s = ∞) : μ t = ∞ := eq_top_mono (measure_mono h) hs lemma measure_lt_top_mono (h : s ⊆ t) (ht : μ t < ∞) : μ s < ∞ := (measure_mono h).trans_lt ht theorem measure_pos_of_superset (h : s ⊆ t) (hs : μ s ≠ 0) : 0 < μ t := hs.bot_lt.trans_le (measure_mono h) theorem measure_iUnion_le [Countable ι] (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) := by refine rel_iSup_tsum μ measure_empty (· ≤ ·) (fun t ↦ ?_) _ calc μ (⋃ i, t i) = μ (⋃ i, disjointed t i) := by rw [iUnion_disjointed] _ ≤ ∑' i, μ (disjointed t i) := OuterMeasureClass.measure_iUnion_nat_le _ _ (disjoint_disjointed _) _ ≤ ∑' i, μ (t i) := by gcongr; exact disjointed_subset .. theorem measure_biUnion_le {I : Set ι} (μ : F) (hI : I.Countable) (s : ι → Set α) : μ (⋃ i ∈ I, s i) ≤ ∑' i : I, μ (s i) := by have := hI.to_subtype rw [biUnion_eq_iUnion] apply measure_iUnion_le theorem measure_biUnion_finset_le (I : Finset ι) (s : ι → Set α) : μ (⋃ i ∈ I, s i) ≤ ∑ i ∈ I, μ (s i) := (measure_biUnion_le μ I.countable_toSet s).trans_eq <| I.tsum_subtype (μ <| s ·) theorem measure_iUnion_fintype_le [Fintype ι] (μ : F) (s : ι → Set α) : μ (⋃ i, s i) ≤ ∑ i, μ (s i) := by simpa using measure_biUnion_finset_le Finset.univ s theorem measure_union_le (s t : Set α) : μ (s ∪ t) ≤ μ s + μ t := by simpa [union_eq_iUnion] using measure_iUnion_fintype_le μ (cond · s t) lemma measure_univ_le_add_compl (s : Set α) : μ univ ≤ μ s + μ sᶜ := s.union_compl_self ▸ measure_union_le s sᶜ theorem measure_le_inter_add_diff (μ : F) (s t : Set α) : μ s ≤ μ (s ∩ t) + μ (s \ t) := by simpa using measure_union_le (s ∩ t) (s \ t) theorem measure_diff_null (ht : μ t = 0) : μ (s \ t) = μ s := (measure_mono diff_subset).antisymm <| calc μ s ≤ μ (s ∩ t) + μ (s \ t) := measure_le_inter_add_diff _ _ _ _ ≤ μ t + μ (s \ t) := by gcongr; apply inter_subset_right _ = μ (s \ t) := by simp [ht] theorem measure_biUnion_null_iff {I : Set ι} (hI : I.Countable) {s : ι → Set α} : μ (⋃ i ∈ I, s i) = 0 ↔ ∀ i ∈ I, μ (s i) = 0 := by refine ⟨fun h i hi ↦ measure_mono_null (subset_biUnion_of_mem hi) h, fun h ↦ ?_⟩ have _ := hI.to_subtype
simpa [h] using measure_iUnion_le (μ := μ) fun x : I ↦ s x theorem measure_sUnion_null_iff {S : Set (Set α)} (hS : S.Countable) : μ (⋃₀ S) = 0 ↔ ∀ s ∈ S, μ s = 0 := by rw [sUnion_eq_biUnion, measure_biUnion_null_iff hS]
Mathlib/MeasureTheory/OuterMeasure/Basic.lean
103
107
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Family /-! # Ordinal exponential In this file we define the power function and the logarithm function on ordinals. The two are related by the lemma `Ordinal.opow_le_iff_le_log : b ^ c ≤ x ↔ c ≤ log b x` for nontrivial inputs `b`, `c`. -/ noncomputable section open Function Set Equiv Order open scoped Cardinal Ordinal universe u v w namespace Ordinal /-- The ordinal exponential, defined by transfinite recursion. We call this `opow` in theorems in order to disambiguate from other exponentials. -/ instance instPow : Pow Ordinal Ordinal := ⟨fun a b ↦ if a = 0 then 1 - b else limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2⟩ private theorem opow_of_ne_zero {a b : Ordinal} (h : a ≠ 0) : a ^ b = limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2 := if_neg h /-- `0 ^ a = 1` if `a = 0` and `0 ^ a = 0` otherwise. -/ theorem zero_opow' (a : Ordinal) : 0 ^ a = 1 - a := if_pos rfl theorem zero_opow_le (a : Ordinal) : (0 : Ordinal) ^ a ≤ 1 := by rw [zero_opow'] exact sub_le_self 1 a @[simp] theorem zero_opow {a : Ordinal} (a0 : a ≠ 0) : (0 : Ordinal) ^ a = 0 := by rwa [zero_opow', Ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero] @[simp] theorem opow_zero (a : Ordinal) : a ^ (0 : Ordinal) = 1 := by obtain rfl | h := eq_or_ne a 0 · rw [zero_opow', Ordinal.sub_zero] · rw [opow_of_ne_zero h, limitRecOn_zero] @[simp] theorem opow_succ (a b : Ordinal) : a ^ succ b = a ^ b * a := by obtain rfl | h := eq_or_ne a 0 · rw [zero_opow (succ_ne_zero b), mul_zero] · rw [opow_of_ne_zero h, opow_of_ne_zero h, limitRecOn_succ] theorem opow_limit {a b : Ordinal} (ha : a ≠ 0) (hb : IsLimit b) : a ^ b = ⨆ x : Iio b, a ^ x.1 := by simp_rw [opow_of_ne_zero ha, limitRecOn_limit _ _ _ _ hb] theorem opow_le_of_limit {a b c : Ordinal} (a0 : a ≠ 0) (h : IsLimit b) : a ^ b ≤ c ↔ ∀ b' < b, a ^ b' ≤ c := by rw [opow_limit a0 h, Ordinal.iSup_le_iff, Subtype.forall] rfl theorem lt_opow_of_limit {a b c : Ordinal} (b0 : b ≠ 0) (h : IsLimit c) : a < b ^ c ↔ ∃ c' < c, a < b ^ c' := by rw [← not_iff_not, not_exists] simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and] @[simp] theorem opow_one (a : Ordinal) : a ^ (1 : Ordinal) = a := by rw [← succ_zero, opow_succ] simp only [opow_zero, one_mul] @[simp] theorem one_opow (a : Ordinal) : (1 : Ordinal) ^ a = 1 := by induction a using limitRecOn with | zero => simp only [opow_zero] | succ _ ih => simp only [opow_succ, ih, mul_one] | isLimit b l IH => refine eq_of_forall_ge_iff fun c => ?_ rw [opow_le_of_limit Ordinal.one_ne_zero l] exact ⟨fun H => by simpa only [opow_zero] using H 0 l.pos, fun H b' h => by rwa [IH _ h]⟩ theorem opow_pos {a : Ordinal} (b : Ordinal) (a0 : 0 < a) : 0 < a ^ b := by have h0 : 0 < a ^ (0 : Ordinal) := by simp only [opow_zero, zero_lt_one] induction b using limitRecOn with | zero => exact h0 | succ b IH => rw [opow_succ] exact mul_pos IH a0 | isLimit b l _ => exact (lt_opow_of_limit (Ordinal.pos_iff_ne_zero.1 a0) l).2 ⟨0, l.pos, h0⟩ theorem opow_ne_zero {a : Ordinal} (b : Ordinal) (a0 : a ≠ 0) : a ^ b ≠ 0 := Ordinal.pos_iff_ne_zero.1 <| opow_pos b <| Ordinal.pos_iff_ne_zero.2 a0 @[simp] theorem opow_eq_zero {a b : Ordinal} : a ^ b = 0 ↔ a = 0 ∧ b ≠ 0 := by obtain rfl | ha := eq_or_ne a 0 · obtain rfl | hb := eq_or_ne b 0 · simp · simp [hb] · simp [opow_ne_zero b ha, ha] @[simp, norm_cast] theorem opow_natCast (a : Ordinal) (n : ℕ) : a ^ (n : Ordinal) = a ^ n := by induction n with | zero => rw [Nat.cast_zero, opow_zero, pow_zero] | succ n IH => rw [Nat.cast_succ, add_one_eq_succ, opow_succ, pow_succ, IH] theorem isNormal_opow {a : Ordinal} (h : 1 < a) : IsNormal (a ^ ·) := have a0 : 0 < a := zero_lt_one.trans h ⟨fun b => by simpa only [mul_one, opow_succ] using (mul_lt_mul_iff_left (opow_pos b a0)).2 h, fun _ l _ => opow_le_of_limit (ne_of_gt a0) l⟩ theorem opow_lt_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b < a ^ c ↔ b < c := (isNormal_opow a1).lt_iff theorem opow_le_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b ≤ a ^ c ↔ b ≤ c := (isNormal_opow a1).le_iff theorem opow_right_inj {a b c : Ordinal} (a1 : 1 < a) : a ^ b = a ^ c ↔ b = c := (isNormal_opow a1).inj theorem isLimit_opow {a b : Ordinal} (a1 : 1 < a) : IsLimit b → IsLimit (a ^ b) := (isNormal_opow a1).isLimit theorem isLimit_opow_left {a b : Ordinal} (l : IsLimit a) (hb : b ≠ 0) : IsLimit (a ^ b) := by rcases zero_or_succ_or_limit b with (e | ⟨b, rfl⟩ | l') · exact absurd e hb · rw [opow_succ] exact isLimit_mul (opow_pos _ l.pos) l · exact isLimit_opow l.one_lt l' theorem opow_le_opow_right {a b c : Ordinal} (h₁ : 0 < a) (h₂ : b ≤ c) : a ^ b ≤ a ^ c := by rcases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ | h₁ · exact (opow_le_opow_iff_right h₁).2 h₂ · subst a -- Porting note: `le_refl` is required. simp only [one_opow, le_refl] theorem opow_le_opow_left {a b : Ordinal} (c : Ordinal) (ab : a ≤ b) : a ^ c ≤ b ^ c := by by_cases a0 : a = 0 -- Porting note: `le_refl` is required. · subst a by_cases c0 : c = 0 · subst c simp only [opow_zero, le_refl] · simp only [zero_opow c0, Ordinal.zero_le] · induction c using limitRecOn with | zero => simp only [opow_zero, le_refl] | succ c IH => simpa only [opow_succ] using mul_le_mul' IH ab | isLimit c l IH => exact (opow_le_of_limit a0 l).2 fun b' h => (IH _ h).trans (opow_le_opow_right ((Ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le) theorem opow_le_opow {a b c d : Ordinal} (hac : a ≤ c) (hbd : b ≤ d) (hc : 0 < c) : a ^ b ≤ c ^ d := (opow_le_opow_left b hac).trans (opow_le_opow_right hc hbd) theorem left_le_opow (a : Ordinal) {b : Ordinal} (b1 : 0 < b) : a ≤ a ^ b := by nth_rw 1 [← opow_one a] rcases le_or_gt a 1 with a1 | a1 · rcases lt_or_eq_of_le a1 with a0 | a1 · rw [lt_one_iff_zero] at a0 rw [a0, zero_opow Ordinal.one_ne_zero] exact Ordinal.zero_le _ rw [a1, one_opow, one_opow] rwa [opow_le_opow_iff_right a1, one_le_iff_pos] theorem left_lt_opow {a b : Ordinal} (ha : 1 < a) (hb : 1 < b) : a < a ^ b := by conv_lhs => rw [← opow_one a] rwa [opow_lt_opow_iff_right ha]
theorem right_le_opow {a : Ordinal} (b : Ordinal) (a1 : 1 < a) : b ≤ a ^ b := (isNormal_opow a1).le_apply theorem opow_lt_opow_left_of_succ {a b c : Ordinal} (ab : a < b) : a ^ succ c < b ^ succ c := by
Mathlib/SetTheory/Ordinal/Exponential.lean
180
184
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Init import Mathlib.Data.Int.Init import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero DenselyOrdered open Function variable {α β G M : Type*} section ite variable [Pow α β] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section Semigroup variable [Semigroup α] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩ /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by ext z simp [mul_assoc] /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by ext z simp [mul_assoc] end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩ section MulOneClass variable [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h : P <;> simp [h] @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h : P <;> simp [h] @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) @[to_additive] theorem one_mul_eq_id : ((1 : M) * ·) = id := funext one_mul @[to_additive] theorem mul_one_eq_id : (· * (1 : M)) = id := funext mul_one end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by rw [← mul_assoc, mul_comm a, mul_assoc] @[to_additive] theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by rw [mul_assoc, mul_comm b, mul_assoc] @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] end CommSemigroup attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b : M} {m n : ℕ} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"] lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] @[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] @[to_additive (attr := simp)] lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ, mul_left_iterate] @[to_additive (attr := simp)] lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ', mul_right_iterate] @[to_additive] lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive] lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul] end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz @[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] end CommMonoid section LeftCancelMonoid variable [Monoid M] [IsLeftCancelMul M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_left : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left @[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_eq_self @[to_additive (attr := simp)] theorem left_eq_mul : a = a * b ↔ b = 1 := eq_comm.trans mul_eq_left @[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_right @[to_additive] theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not @[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left @[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_ne_self @[to_additive] theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_right end LeftCancelMonoid section RightCancelMonoid variable [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_right : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right @[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_eq_self @[to_additive (attr := simp)] theorem right_eq_mul : b = a * b ↔ a = 1 := eq_comm.trans mul_eq_right @[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_left @[to_additive] theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not @[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right @[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_ne_self @[to_additive] theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_left end RightCancelMonoid section CancelCommMonoid variable [CancelCommMonoid α] {a b c d : α} @[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop @[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop end CancelCommMonoid section InvolutiveInv variable [InvolutiveInv G] {a b : G} @[to_additive (attr := simp)] theorem inv_involutive : Function.Involutive (Inv.inv : G → G) := inv_inv @[to_additive (attr := simp)] theorem inv_surjective : Function.Surjective (Inv.inv : G → G) := inv_involutive.surjective @[to_additive] theorem inv_injective : Function.Injective (Inv.inv : G → G) := inv_involutive.injective @[to_additive (attr := simp)] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff @[to_additive] theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ := ⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩ variable (G) @[to_additive] theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G := inv_involutive.comp_self @[to_additive] theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv @[to_additive] theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv end InvolutiveInv section DivInvMonoid variable [DivInvMonoid G] @[to_additive] theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by rw [div_eq_mul_inv, one_mul, div_eq_mul_inv] @[to_additive, field_simps] -- The attributes are out of order on purpose theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c := (mul_div_assoc _ _ _).symm @[to_additive] theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv] @[to_additive] theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div] end DivInvMonoid section DivInvOneMonoid variable [DivInvOneMonoid G] @[to_additive (attr := simp)] theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv] @[to_additive] theorem one_div_one : (1 : G) / 1 = 1 := div_one _ end DivInvOneMonoid section DivisionMonoid variable [DivisionMonoid α] {a b c d : α} attribute [local simp] mul_assoc div_eq_mul_inv @[to_additive] theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ := (inv_eq_of_mul_eq_one_right h).symm @[to_additive] theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_left h, one_div] @[to_additive] theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_right h, one_div] @[to_additive] theorem eq_of_div_eq_one (h : a / b = 1) : a = b := inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv] @[to_additive] lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 := mt eq_of_div_eq_one variable (a b c) @[to_additive] theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp @[to_additive] theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp @[to_additive (attr := simp)] theorem inv_div : (a / b)⁻¹ = b / a := by simp @[to_additive] theorem one_div_div : 1 / (a / b) = b / a := by simp @[to_additive] theorem one_div_one_div : 1 / (1 / a) = a := by simp @[to_additive] theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c := inv_inj.symm.trans <| by simp only [inv_div] @[to_additive] instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α := { DivisionMonoid.toDivInvMonoid with inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm } @[to_additive (attr := simp)] lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹ | 0 => by rw [pow_zero, pow_zero, inv_one] | n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev] -- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`. @[to_additive zsmul_zero, simp] lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | .negSucc n => by rw [zpow_negSucc, one_pow, inv_one] @[to_additive (attr := simp) neg_zsmul] lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹ | (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _ | 0 => by simp | Int.negSucc n => by rw [zpow_negSucc, inv_inv, ← zpow_natCast] rfl @[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by simp only [zpow_neg, zpow_one, mul_inv_rev] @[to_additive zsmul_neg] lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow] | .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow] @[to_additive (attr := simp) zsmul_neg'] lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg] @[to_additive nsmul_zero_sub] lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow] @[to_additive zsmul_zero_sub] lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow] variable {a b c} @[to_additive (attr := simp)] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := inv_injective.eq_iff' inv_one @[to_additive (attr := simp)] theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 := eq_comm.trans inv_eq_one @[to_additive] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := inv_eq_one.not @[to_additive] theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by rw [← one_div_one_div a, h, one_div_one_div] -- Note that `mul_zsmul` and `zpow_mul` have the primes swapped -- when additivised since their argument order, -- and therefore the more "natural" choice of lemma, is reversed. @[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n | (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast] rfl | (m : ℕ), .negSucc n => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj, ← zpow_natCast] | .negSucc m, (n : ℕ) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow, inv_inj, ← zpow_natCast] | .negSucc m, .negSucc n => by rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ← zpow_natCast] rfl @[to_additive mul_zsmul] lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul] @[to_additive] theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul'] variable (a b c) @[to_additive, field_simps] -- The attributes are out of order on purpose theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp @[to_additive (attr := simp)] theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp @[to_additive] theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv] end DivisionMonoid section DivisionCommMonoid variable [DivisionCommMonoid α] (a b c d : α) attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive neg_add] theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp @[to_additive] theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp @[to_additive] theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp @[to_additive] theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp @[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp @[to_additive] theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp @[to_additive] theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp @[to_additive] theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp @[to_additive] theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp @[to_additive] theorem div_right_comm : a / b / c = a / c / b := by simp @[to_additive, field_simps] theorem div_div : a / b / c = a / (b * c) := by simp @[to_additive] theorem div_mul : a / b * c = a / (b / c) := by simp @[to_additive] theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp @[to_additive] theorem mul_div_right_comm : a * b / c = a / c * b := by simp @[to_additive] theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp @[to_additive, field_simps] theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp @[to_additive] theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp @[to_additive] theorem mul_comm_div : a / b * c = a * (c / b) := by simp @[to_additive] theorem div_mul_comm : a / b * c = c / b * a := by simp @[to_additive] theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp @[to_additive] theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp @[to_additive] theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp @[to_additive] theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp @[to_additive] theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp @[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) => by simp_rw [zpow_natCast, mul_pow] | .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow] @[to_additive nsmul_sub] lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_pow, inv_pow] @[to_additive zsmul_sub] lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_zpow, inv_zpow] attribute [field_simps] div_pow div_zpow end DivisionCommMonoid section Group variable [Group G] {a b c d : G} {n : ℤ} @[to_additive (attr := simp)] theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right] @[to_additive] theorem mul_left_surjective (a : G) : Surjective (a * ·) := fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩ @[to_additive] theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦ ⟨x * a⁻¹, inv_mul_cancel_right x a⟩ @[to_additive] theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm] @[to_additive] theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm] @[to_additive] theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h] @[to_additive] theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h] @[to_additive] theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm] @[to_additive] theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h] @[to_additive] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := ⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩ @[to_additive] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv] /-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by rw [mul_eq_one_iff_inv_eq, eq_comm] /-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by rw [mul_eq_one_iff_eq_inv, eq_comm] @[to_additive] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm @[to_additive] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm @[to_additive] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩ @[to_additive] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩ @[to_additive] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩ @[to_additive] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩ @[to_additive] theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] @[to_additive] theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj] @[to_additive (attr := simp)] theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by rw [mul_inv_eq_one, mul_eq_left] @[to_additive] theorem div_left_injective : Function.Injective fun a ↦ a / b := by -- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`. simp only [div_eq_mul_inv] exact fun a a' h ↦ mul_left_injective b⁻¹ h @[to_additive] theorem div_right_injective : Function.Injective fun a ↦ b / a := by -- FIXME see above simp only [div_eq_mul_inv] exact fun a a' h ↦ inv_injective (mul_right_injective b h) @[to_additive (attr := simp)] lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right] @[to_additive (attr := simp)] theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right] @[to_additive eq_sub_of_add_eq] theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h] @[to_additive sub_eq_of_eq_add] theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h] @[to_additive] theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h] @[to_additive] theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h] @[to_additive (attr := simp)] theorem div_right_inj : a / b = a / c ↔ b = c := div_right_injective.eq_iff @[to_additive (attr := simp)] theorem div_left_inj : b / a = c / a ↔ b = c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_left_inj _ @[to_additive (attr := simp)] theorem div_mul_div_cancel (a b c : G) : a / b * (b / c) = a / c := by rw [← mul_div_assoc, div_mul_cancel] @[to_additive (attr := simp)] theorem div_div_div_cancel_right (a b c : G) : a / c / (b / c) = a / b := by rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel] @[to_additive] theorem div_eq_one : a / b = 1 ↔ a = b := ⟨eq_of_div_eq_one, fun h ↦ by rw [h, div_self']⟩ alias ⟨_, div_eq_one_of_eq⟩ := div_eq_one alias ⟨_, sub_eq_zero_of_eq⟩ := sub_eq_zero @[to_additive] theorem div_ne_one : a / b ≠ 1 ↔ a ≠ b := not_congr div_eq_one @[to_additive (attr := simp)] theorem div_eq_self : a / b = a ↔ b = 1 := by rw [div_eq_mul_inv, mul_eq_left, inv_eq_one] @[to_additive eq_sub_iff_add_eq] theorem eq_div_iff_mul_eq' : a = b / c ↔ a * c = b := by rw [div_eq_mul_inv, eq_mul_inv_iff_mul_eq] @[to_additive] theorem div_eq_iff_eq_mul : a / b = c ↔ a = c * b := by rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul] @[to_additive] theorem eq_iff_eq_of_div_eq_div (H : a / b = c / d) : a = b ↔ c = d := by rw [← div_eq_one, H, div_eq_one] @[to_additive] theorem leftInverse_div_mul_left (c : G) : Function.LeftInverse (fun x ↦ x / c) fun x ↦ x * c := fun x ↦ mul_div_cancel_right x c @[to_additive] theorem leftInverse_mul_left_div (c : G) : Function.LeftInverse (fun x ↦ x * c) fun x ↦ x / c := fun x ↦ div_mul_cancel x c @[to_additive] theorem leftInverse_mul_right_inv_mul (c : G) : Function.LeftInverse (fun x ↦ c * x) fun x ↦ c⁻¹ * x := fun x ↦ mul_inv_cancel_left c x @[to_additive] theorem leftInverse_inv_mul_mul_right (c : G) : Function.LeftInverse (fun x ↦ c⁻¹ * x) fun x ↦ c * x := fun x ↦ inv_mul_cancel_left c x @[to_additive (attr := simp) natAbs_nsmul_eq_zero] lemma pow_natAbs_eq_one : a ^ n.natAbs = 1 ↔ a ^ n = 1 := by cases n <;> simp @[to_additive sub_nsmul] lemma pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := eq_mul_inv_of_mul_eq <| by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_nsmul_neg] theorem inv_pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub a⁻¹ h, inv_pow, inv_pow, inv_inv] @[to_additive add_one_zsmul] lemma zpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a | (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ] | -1 => by simp [Int.add_left_neg] | .negSucc (n + 1) => by rw [zpow_negSucc, pow_succ', mul_inv_rev, inv_mul_cancel_right] rw [Int.negSucc_eq, Int.neg_add, Int.neg_add_cancel_right] exact zpow_negSucc _ _ @[to_additive sub_one_zsmul] lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ := calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := (mul_inv_cancel_right _ _).symm _ = a ^ n * a⁻¹ := by rw [← zpow_add_one, Int.sub_add_cancel] @[to_additive add_zsmul] lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by induction n with | hz => simp | hp n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc] | hn n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc] @[to_additive one_add_zsmul] lemma zpow_one_add (a : G) (n : ℤ) : a ^ (1 + n) = a * a ^ n := by rw [zpow_add, zpow_one] @[to_additive add_zsmul_self] lemma mul_self_zpow (a : G) (n : ℤ) : a * a ^ n = a ^ (n + 1) := by rw [Int.add_comm, zpow_add, zpow_one] @[to_additive add_self_zsmul] lemma mul_zpow_self (a : G) (n : ℤ) : a ^ n * a = a ^ (n + 1) := (zpow_add_one ..).symm @[to_additive sub_zsmul] lemma zpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by rw [Int.sub_eq_add_neg, zpow_add, zpow_neg] @[to_additive natCast_sub_natCast_zsmul] lemma zpow_natCast_sub_natCast (a : G) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by simpa [div_eq_mul_inv] using zpow_sub a m n @[to_additive natCast_sub_one_zsmul] lemma zpow_natCast_sub_one (a : G) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by simpa [div_eq_mul_inv] using zpow_sub a n 1 @[to_additive one_sub_natCast_zsmul] lemma zpow_one_sub_natCast (a : G) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by simpa [div_eq_mul_inv] using zpow_sub a 1 n @[to_additive] lemma zpow_mul_comm (a : G) (m n : ℤ) : a ^ m * a ^ n = a ^ n * a ^ m := by rw [← zpow_add, Int.add_comm, zpow_add] theorem zpow_eq_zpow_emod {x : G} (m : ℤ) {n : ℤ} (h : x ^ n = 1) : x ^ m = x ^ (m % n) := calc x ^ m = x ^ (m % n + n * (m / n)) := by rw [Int.emod_add_ediv] _ = x ^ (m % n) := by simp [zpow_add, zpow_mul, h] theorem zpow_eq_zpow_emod' {x : G} (m : ℤ) {n : ℕ} (h : x ^ n = 1) : x ^ m = x ^ (m % (n : ℤ)) := zpow_eq_zpow_emod m (by simpa) @[to_additive (attr := simp)] lemma zpow_iterate (k : ℤ) : ∀ n : ℕ, (fun x : G ↦ x ^ k)^[n] = (· ^ k ^ n) | 0 => by ext; simp [Int.pow_zero] | n + 1 => by ext; simp [zpow_iterate, Int.pow_succ', zpow_mul] /-- To show a property of all powers of `g` it suffices to show it is closed under multiplication by `g` and `g⁻¹` on the left. For subgroups generated by more than one element, see `Subgroup.closure_induction_left`. -/ @[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under addition by `g` and `-g` on the left. For additive subgroups generated by more than one element, see `AddSubgroup.closure_induction_left`."] lemma zpow_induction_left {g : G} {P : G → Prop} (h_one : P (1 : G)) (h_mul : ∀ a, P a → P (g * a)) (h_inv : ∀ a, P a → P (g⁻¹ * a)) (n : ℤ) : P (g ^ n) := by induction n with | hz => rwa [zpow_zero] | hp n ih => rw [Int.add_comm, zpow_add, zpow_one] exact h_mul _ ih | hn n ih => rw [Int.sub_eq_add_neg, Int.add_comm, zpow_add, zpow_neg_one] exact h_inv _ ih /-- To show a property of all powers of `g` it suffices to show it is closed under multiplication by `g` and `g⁻¹` on the right. For subgroups generated by more than one element, see `Subgroup.closure_induction_right`. -/ @[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under addition by `g` and `-g` on the right. For additive subgroups generated by more than one element, see `AddSubgroup.closure_induction_right`."] lemma zpow_induction_right {g : G} {P : G → Prop} (h_one : P (1 : G)) (h_mul : ∀ a, P a → P (a * g)) (h_inv : ∀ a, P a → P (a * g⁻¹)) (n : ℤ) : P (g ^ n) := by induction n with | hz => rwa [zpow_zero] | hp n ih => rw [zpow_add_one] exact h_mul _ ih | hn n ih => rw [zpow_sub_one] exact h_inv _ ih end Group section CommGroup variable [CommGroup G] {a b c d : G} attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive] theorem div_eq_of_eq_mul' {a b c : G} (h : a = b * c) : a / b = c := by rw [h, div_eq_mul_inv, mul_comm, inv_mul_cancel_left] @[to_additive (attr := simp)] theorem mul_div_mul_left_eq_div (a b c : G) : c * a / (c * b) = a / b := by rw [div_eq_mul_inv, mul_inv_rev, mul_comm b⁻¹ c⁻¹, mul_comm c a, mul_assoc, ← mul_assoc c, mul_inv_cancel, one_mul, div_eq_mul_inv] @[to_additive eq_sub_of_add_eq'] theorem eq_div_of_mul_eq'' (h : c * a = b) : a = b / c := by simp [h.symm] @[to_additive] theorem eq_mul_of_div_eq' (h : a / b = c) : a = b * c := by simp [h.symm] @[to_additive] theorem mul_eq_of_eq_div' (h : b = c / a) : a * b = c := by rw [h, div_eq_mul_inv, mul_comm c, mul_inv_cancel_left] @[to_additive sub_sub_self] theorem div_div_self' (a b : G) : a / (a / b) = b := by simp @[to_additive] theorem div_eq_div_mul_div (a b c : G) : a / b = c / b * (a / c) := by simp [mul_left_comm c] @[to_additive (attr := simp)] theorem div_div_cancel (a b : G) : a / (a / b) = b := div_div_self' a b @[to_additive (attr := simp)] theorem div_div_cancel_left (a b : G) : a / b / a = b⁻¹ := by simp @[to_additive eq_sub_iff_add_eq'] theorem eq_div_iff_mul_eq'' : a = b / c ↔ c * a = b := by rw [eq_div_iff_mul_eq', mul_comm] @[to_additive] theorem div_eq_iff_eq_mul' : a / b = c ↔ a = b * c := by rw [div_eq_iff_eq_mul, mul_comm] @[to_additive (attr := simp)] theorem mul_div_cancel_left (a b : G) : a * b / a = b := by rw [div_eq_inv_mul, inv_mul_cancel_left] @[to_additive (attr := simp)] theorem mul_div_cancel (a b : G) : a * (b / a) = b := by rw [← mul_div_assoc, mul_div_cancel_left] @[to_additive (attr := simp)] theorem div_mul_cancel_left (a b : G) : a / (a * b) = b⁻¹ := by rw [← inv_div, mul_div_cancel_left] -- This lemma is in the `simp` set under the name `mul_inv_cancel_comm_assoc`, -- along with the additive version `add_neg_cancel_comm_assoc`, -- defined in `Algebra.Group.Commute` @[to_additive] theorem mul_mul_inv_cancel'_right (a b : G) : a * (b * a⁻¹) = b := by rw [← div_eq_mul_inv, mul_div_cancel a b] @[to_additive (attr := simp)] theorem mul_mul_div_cancel (a b c : G) : a * c * (b / c) = a * b := by rw [mul_assoc, mul_div_cancel] @[to_additive (attr := simp)] theorem div_mul_mul_cancel (a b c : G) : a / c * (b * c) = a * b := by rw [mul_left_comm, div_mul_cancel, mul_comm] @[to_additive (attr := simp)] theorem div_mul_div_cancel' (a b c : G) : a / b * (c / a) = c / b := by rw [mul_comm]; apply div_mul_div_cancel @[to_additive (attr := simp)] theorem mul_div_div_cancel (a b c : G) : a * b / (a / c) = b * c := by rw [← div_mul, mul_div_cancel_left] @[to_additive (attr := simp)] theorem div_div_div_cancel_left (a b c : G) : c / a / (c / b) = b / a := by rw [← inv_div b c, div_inv_eq_mul, mul_comm, div_mul_div_cancel] @[to_additive] theorem div_eq_div_iff_mul_eq_mul : a / b = c / d ↔ a * d = c * b := by rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, eq_comm, div_eq_iff_eq_mul'] simp only [mul_comm, eq_comm] @[to_additive] theorem div_eq_div_iff_div_eq_div : a / b = c / d ↔ a / c = b / d := by rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, div_eq_iff_eq_mul', mul_div_assoc] end CommGroup section multiplicative variable [Monoid β] (p r : α → α → Prop) [IsTotal α r] (f : α → α → β) @[to_additive additive_of_symmetric_of_isTotal] lemma multiplicative_of_symmetric_of_isTotal (hsymm : Symmetric p) (hf_swap : ∀ {a b}, p a b → f a b * f b a = 1) (hmul : ∀ {a b c}, r a b → r b c → p a b → p b c → p a c → f a c = f a b * f b c) {a b c : α} (pab : p a b) (pbc : p b c) (pac : p a c) : f a c = f a b * f b c := by have hmul' : ∀ {b c}, r b c → p a b → p b c → p a c → f a c = f a b * f b c := by intros b c rbc pab pbc pac obtain rab | rba := total_of r a b · exact hmul rab rbc pab pbc pac rw [← one_mul (f a c), ← hf_swap pab, mul_assoc] obtain rac | rca := total_of r a c · rw [hmul rba rac (hsymm pab) pac pbc] · rw [hmul rbc rca pbc (hsymm pac) (hsymm pab), mul_assoc, hf_swap (hsymm pac), mul_one] obtain rbc | rcb := total_of r b c · exact hmul' rbc pab pbc pac · rw [hmul' rcb pac (hsymm pbc) pab, mul_assoc, hf_swap (hsymm pbc), mul_one] /-- If a binary function from a type equipped with a total relation `r` to a monoid is anti-symmetric (i.e. satisfies `f a b * f b a = 1`), in order to show it is multiplicative (i.e. satisfies `f a c = f a b * f b c`), we may assume `r a b` and `r b c` are satisfied. We allow restricting to a subset specified by a predicate `p`. -/ @[to_additive additive_of_isTotal "If a binary function from a type equipped with a total relation `r` to an additive monoid is anti-symmetric (i.e. satisfies `f a b + f b a = 0`), in order to show it is additive (i.e. satisfies `f a c = f a b + f b c`), we may assume `r a b` and `r b c` are satisfied. We allow restricting to a subset specified by a predicate `p`."] theorem multiplicative_of_isTotal (p : α → Prop) (hswap : ∀ {a b}, p a → p b → f a b * f b a = 1) (hmul : ∀ {a b c}, r a b → r b c → p a → p b → p c → f a c = f a b * f b c) {a b c : α} (pa : p a) (pb : p b) (pc : p c) : f a c = f a b * f b c := by apply multiplicative_of_symmetric_of_isTotal (fun a b => p a ∧ p b) r f fun _ _ => And.symm · simp_rw [and_imp]; exact @hswap · exact fun rab rbc pab _pbc pac => hmul rab rbc pab.1 pab.2 pac.2 exacts [⟨pa, pb⟩, ⟨pb, pc⟩, ⟨pa, pc⟩] end multiplicative /-- An auxiliary lemma that can be used to prove `⇑(f ^ n) = ⇑f^[n]`. -/ @[to_additive] lemma hom_coe_pow {F : Type*} [Monoid F] (c : F → M → M) (h1 : c 1 = id) (hmul : ∀ f g, c (f * g) = c f ∘ c g) (f : F) : ∀ n, c (f ^ n) = (c f)^[n] | 0 => by rw [pow_zero, h1] rfl | n + 1 => by rw [pow_succ, iterate_succ, hmul, hom_coe_pow c h1 hmul f n]
Mathlib/Algebra/Group/Basic.lean
1,266
1,267
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Topology.Constructions import Mathlib.Order.Filter.ListTraverse import Mathlib.Tactic.AdaptationNote import Mathlib.Topology.Algebra.Monoid.Defs /-! # Topology on lists and vectors -/ open TopologicalSpace Set Filter open Topology Filter variable {α : Type*} {β : Type*} [TopologicalSpace α] [TopologicalSpace β] instance : TopologicalSpace (List α) := TopologicalSpace.mkOfNhds (traverse nhds) theorem nhds_list (as : List α) : 𝓝 as = traverse 𝓝 as := by refine nhds_mkOfNhds _ _ ?_ ?_ · intro l induction l with | nil => exact le_rfl | cons a l ih => suffices List.cons <$> pure a <*> pure l ≤ List.cons <$> 𝓝 a <*> traverse 𝓝 l by simpa only [functor_norm] using this exact Filter.seq_mono (Filter.map_mono <| pure_le_nhds a) ih · intro l s hs rcases (mem_traverse_iff _ _).1 hs with ⟨u, hu, hus⟩ clear as hs have : ∃ v : List (Set α), l.Forall₂ (fun a s => IsOpen s ∧ a ∈ s) v ∧ sequence v ⊆ s := by induction hu generalizing s with | nil => exists [] simp only [List.forall₂_nil_left_iff, exists_eq_left] exact ⟨trivial, hus⟩ | cons ht _ ih => rcases mem_nhds_iff.1 ht with ⟨u, hut, hu⟩ rcases ih _ Subset.rfl with ⟨v, hv, hvss⟩ exact ⟨u::v, List.Forall₂.cons hu hv, Subset.trans (Set.seq_mono (Set.image_subset _ hut) hvss) hus⟩ rcases this with ⟨v, hv, hvs⟩ have : sequence v ∈ traverse 𝓝 l := mem_traverse _ _ <| hv.imp fun a s ⟨hs, ha⟩ => IsOpen.mem_nhds hs ha refine mem_of_superset this fun u hu ↦ ?_ have hu := (List.mem_traverse _ _).1 hu have : List.Forall₂ (fun a s => IsOpen s ∧ a ∈ s) u v := by refine List.Forall₂.flip ?_ replace hv := hv.flip simp only [List.forall₂_and_left, Function.flip_def] at hv ⊢ exact ⟨hv.1, hu.flip⟩ refine mem_of_superset ?_ hvs exact mem_traverse _ _ (this.imp fun a s ⟨hs, ha⟩ => IsOpen.mem_nhds hs ha) @[simp] theorem nhds_nil : 𝓝 ([] : List α) = pure [] := by rw [nhds_list, List.traverse_nil _] theorem nhds_cons (a : α) (l : List α) : 𝓝 (a::l) = List.cons <$> 𝓝 a <*> 𝓝 l := by rw [nhds_list, List.traverse_cons _, ← nhds_list] theorem List.tendsto_cons {a : α} {l : List α} : Tendsto (fun p : α × List α => List.cons p.1 p.2) (𝓝 a ×ˢ 𝓝 l) (𝓝 (a::l)) := by rw [nhds_cons, Tendsto, Filter.map_prod]; exact le_rfl theorem Filter.Tendsto.cons {α : Type*} {f : α → β} {g : α → List β} {a : Filter α} {b : β} {l : List β} (hf : Tendsto f a (𝓝 b)) (hg : Tendsto g a (𝓝 l)) : Tendsto (fun a => List.cons (f a) (g a)) a (𝓝 (b::l)) := List.tendsto_cons.comp (Tendsto.prodMk hf hg) namespace List theorem tendsto_cons_iff {β : Type*} {f : List α → β} {b : Filter β} {a : α} {l : List α} : Tendsto f (𝓝 (a::l)) b ↔ Tendsto (fun p : α × List α => f (p.1::p.2)) (𝓝 a ×ˢ 𝓝 l) b := by have : 𝓝 (a::l) = (𝓝 a ×ˢ 𝓝 l).map fun p : α × List α => p.1::p.2 := by simp only [nhds_cons, Filter.prod_eq, (Filter.map_def _ _).symm, (Filter.seq_eq_filter_seq _ _).symm] simp [-Filter.map_def, Function.comp_def, functor_norm] rw [this, Filter.tendsto_map'_iff]; rfl theorem continuous_cons : Continuous fun x : α × List α => (x.1::x.2 : List α) := continuous_iff_continuousAt.mpr fun ⟨_x, _y⟩ => continuousAt_fst.cons continuousAt_snd theorem tendsto_nhds {β : Type*} {f : List α → β} {r : List α → Filter β} (h_nil : Tendsto f (pure []) (r [])) (h_cons : ∀ l a, Tendsto f (𝓝 l) (r l) → Tendsto (fun p : α × List α => f (p.1::p.2)) (𝓝 a ×ˢ 𝓝 l) (r (a::l))) : ∀ l, Tendsto f (𝓝 l) (r l) | [] => by rwa [nhds_nil] | a::l => by rw [tendsto_cons_iff]; exact h_cons l a (@tendsto_nhds _ _ _ h_nil h_cons l) instance [DiscreteTopology α] : DiscreteTopology (List α) := by rw [discreteTopology_iff_nhds]; intro l; induction l <;> simp [*, nhds_cons] theorem continuousAt_length : ∀ l : List α, ContinuousAt List.length l := by simp only [ContinuousAt, nhds_discrete] refine tendsto_nhds ?_ ?_ · exact tendsto_pure_pure _ _ · intro l a ih dsimp only [List.length] refine Tendsto.comp (tendsto_pure_pure (fun x => x + 1) _) ?_ exact Tendsto.comp ih tendsto_snd /-- Continuity of `insertIdx` in terms of `Tendsto`. -/ theorem tendsto_insertIdx' {a : α} : ∀ {n : ℕ} {l : List α}, Tendsto (fun p : α × List α => p.2.insertIdx n p.1) (𝓝 a ×ˢ 𝓝 l) (𝓝 (l.insertIdx n a)) | 0, _ => tendsto_cons | n + 1, [] => by simp | n + 1, a'::l => by have : 𝓝 a ×ˢ 𝓝 (a'::l) = (𝓝 a ×ˢ (𝓝 a' ×ˢ 𝓝 l)).map fun p : α × α × List α => (p.1, p.2.1::p.2.2) := by simp only [nhds_cons, Filter.prod_eq, ← Filter.map_def, ← Filter.seq_eq_filter_seq] simp [-Filter.map_def, Function.comp_def, functor_norm] rw [this, tendsto_map'_iff] exact (tendsto_fst.comp tendsto_snd).cons
((@tendsto_insertIdx' _ n l).comp <| tendsto_fst.prodMk <| tendsto_snd.comp tendsto_snd) theorem tendsto_insertIdx {β} {n : ℕ} {a : α} {l : List α} {f : β → α} {g : β → List α} {b : Filter β} (hf : Tendsto f b (𝓝 a)) (hg : Tendsto g b (𝓝 l)) : Tendsto (fun b : β => (g b).insertIdx n (f b)) b (𝓝 (l.insertIdx n a)) := tendsto_insertIdx'.comp (hf.prodMk hg) theorem continuous_insertIdx {n : ℕ} : Continuous fun p : α × List α => p.2.insertIdx n p.1 := continuous_iff_continuousAt.mpr fun ⟨a, l⟩ => by rw [ContinuousAt, nhds_prod_eq]; exact tendsto_insertIdx' theorem tendsto_eraseIdx : ∀ {n : ℕ} {l : List α}, Tendsto (eraseIdx · n) (𝓝 l) (𝓝 (eraseIdx l n)) | _, [] => by rw [nhds_nil]; exact tendsto_pure_nhds _ _
Mathlib/Topology/List.lean
129
142
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Edward Ayers -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback import Mathlib.Data.Set.BooleanAlgebra /-! # Theory of sieves - For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. - The complete lattice structure on sieves is given, as well as the Galois insertion given by downward-closing. - A `Sieve X` (functorially) induces a presheaf on `C` together with a monomorphism to the yoneda embedding of `X`. ## Tags sieve, pullback -/ universe v₁ v₂ v₃ u₁ u₂ u₃ namespace CategoryTheory open Category Limits variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D) variable {X Y Z : C} (f : Y ⟶ X) /-- A set of arrows all with codomain `X`. -/ def Presieve (X : C) := ∀ ⦃Y⦄, Set (Y ⟶ X)-- deriving CompleteLattice instance : CompleteLattice (Presieve X) := by dsimp [Presieve] infer_instance namespace Presieve noncomputable instance : Inhabited (Presieve X) := ⟨⊤⟩ /-- The full subcategory of the over category `C/X` consisting of arrows which belong to a presieve on `X`. -/ abbrev category {X : C} (P : Presieve X) := ObjectProperty.FullSubcategory fun f : Over X => P f.hom /-- Construct an object of `P.category`. -/ abbrev categoryMk {X : C} (P : Presieve X) {Y : C} (f : Y ⟶ X) (hf : P f) : P.category := ⟨Over.mk f, hf⟩ /-- Given a sieve `S` on `X : C`, its associated diagram `S.diagram` is defined to be the natural functor from the full subcategory of the over category `C/X` consisting of arrows in `S` to `C`. -/ abbrev diagram (S : Presieve X) : S.category ⥤ C := ObjectProperty.ι _ ⋙ Over.forget X /-- Given a sieve `S` on `X : C`, its associated cocone `S.cocone` is defined to be the natural cocone over the diagram defined above with cocone point `X`. -/ abbrev cocone (S : Presieve X) : Cocone S.diagram := (Over.forgetCocone X).whisker (ObjectProperty.ι _) /-- Given a set of arrows `S` all with codomain `X`, and a set of arrows with codomain `Y` for each `f : Y ⟶ X` in `S`, produce a set of arrows with codomain `X`: `{ g ≫ f | (f : Y ⟶ X) ∈ S, (g : Z ⟶ Y) ∈ R f }`. -/ def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) : Presieve X := fun Z h => ∃ (Y : C) (g : Z ⟶ Y) (f : Y ⟶ X) (H : S f), R H g ∧ g ≫ f = h /-- Structure which contains the data and properties for a morphism `h` satisfying `Presieve.bind S R h`. -/ structure BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) {Z : C} (h : Z ⟶ X) where /-- the intermediate object -/ Y : C /-- a morphism in the family of presieves `R` -/ g : Z ⟶ Y /-- a morphism in the presieve `S` -/ f : Y ⟶ X hf : S f hg : R hf g fac : g ≫ f = h attribute [reassoc (attr := simp)] BindStruct.fac /-- If a morphism `h` satisfies `Presieve.bind S R h`, this is a choice of a structure in `BindStruct S R h`. -/ noncomputable def bind.bindStruct {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (H : bind S R h) : BindStruct S R h := Nonempty.some (by obtain ⟨Y, g, f, hf, hg, fac⟩ := H exact ⟨{ hf := hf, hg := hg, fac := fac, .. }⟩) lemma BindStruct.bind {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {Z : C} {h : Z ⟶ X} (b : BindStruct S R h) : bind S R h := ⟨b.Y, b.g, b.f, b.hf, b.hg, b.fac⟩ @[simp] theorem bind_comp {S : Presieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {g : Z ⟶ Y} (h₁ : S f) (h₂ : R h₁ g) : bind S R (g ≫ f) := ⟨_, _, _, h₁, h₂, rfl⟩ -- Porting note: it seems the definition of `Presieve` must be unfolded in order to define -- this inductive type, it was thus renamed `singleton'` -- Note we can't make this into `HasSingleton` because of the out-param. /-- The singleton presieve. -/ inductive singleton' : ⦃Y : C⦄ → (Y ⟶ X) → Prop | mk : singleton' f /-- The singleton presieve. -/ def singleton : Presieve X := singleton' f lemma singleton.mk {f : Y ⟶ X} : singleton f f := singleton'.mk @[simp] theorem singleton_eq_iff_domain (f g : Y ⟶ X) : singleton f g ↔ f = g := by constructor · rintro ⟨a, rfl⟩ rfl · rintro rfl apply singleton.mk theorem singleton_self : singleton f f := singleton.mk /-- Pullback a set of arrows with given codomain along a fixed map, by taking the pullback in the category. This is not the same as the arrow set of `Sieve.pullback`, but there is a relation between them in `pullbackArrows_comm`. -/ inductive pullbackArrows [HasPullbacks C] (R : Presieve X) : Presieve Y | mk (Z : C) (h : Z ⟶ X) : R h → pullbackArrows _ (pullback.snd h f) theorem pullback_singleton [HasPullbacks C] (g : Z ⟶ X) : pullbackArrows f (singleton g) = singleton (pullback.snd g f) := by funext W ext h constructor · rintro ⟨W, _, _, _⟩ exact singleton.mk · rintro ⟨_⟩ exact pullbackArrows.mk Z g singleton.mk /-- Construct the presieve given by the family of arrows indexed by `ι`. -/ inductive ofArrows {ι : Type*} (Y : ι → C) (f : ∀ i, Y i ⟶ X) : Presieve X | mk (i : ι) : ofArrows _ _ (f i) theorem ofArrows_pUnit : (ofArrows _ fun _ : PUnit => f) = singleton f := by funext Y ext g constructor · rintro ⟨_⟩ apply singleton.mk · rintro ⟨_⟩ exact ofArrows.mk PUnit.unit theorem ofArrows_pullback [HasPullbacks C] {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) : (ofArrows (fun i => pullback (g i) f) fun _ => pullback.snd _ _) = pullbackArrows f (ofArrows Z g) := by funext T ext h constructor · rintro ⟨hk⟩ exact pullbackArrows.mk _ _ (ofArrows.mk hk) · rintro ⟨W, k, ⟨_⟩⟩ apply ofArrows.mk theorem ofArrows_bind {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) (j : ∀ ⦃Y⦄ (f : Y ⟶ X), ofArrows Z g f → Type*) (W : ∀ ⦃Y⦄ (f : Y ⟶ X) (H), j f H → C) (k : ∀ ⦃Y⦄ (f : Y ⟶ X) (H i), W f H i ⟶ Y) : ((ofArrows Z g).bind fun _ f H => ofArrows (W f H) (k f H)) = ofArrows (fun i : Σi, j _ (ofArrows.mk i) => W (g i.1) _ i.2) fun ij => k (g ij.1) _ ij.2 ≫ g ij.1 := by funext Y ext f constructor · rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩ exact ofArrows.mk (Sigma.mk _ _) · rintro ⟨i⟩ exact bind_comp _ (ofArrows.mk _) (ofArrows.mk _) theorem ofArrows_surj {ι : Type*} {Y : ι → C} (f : ∀ i, Y i ⟶ X) {Z : C} (g : Z ⟶ X) (hg : ofArrows Y f g) : ∃ (i : ι) (h : Y i = Z), g = eqToHom h.symm ≫ f i := by obtain ⟨i⟩ := hg exact ⟨i, rfl, by simp only [eqToHom_refl, id_comp]⟩ /-- Given a presieve on `F(X)`, we can define a presieve on `X` by taking the preimage via `F`. -/ def functorPullback (R : Presieve (F.obj X)) : Presieve X := fun _ f => R (F.map f) @[simp] theorem functorPullback_mem (R : Presieve (F.obj X)) {Y} (f : Y ⟶ X) : R.functorPullback F f ↔ R (F.map f) := Iff.rfl @[simp] theorem functorPullback_id (R : Presieve X) : R.functorPullback (𝟭 _) = R := rfl /-- Given a presieve `R` on `X`, the predicate `R.hasPullbacks` means that for all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ class hasPullbacks (R : Presieve X) : Prop where /-- For all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/ has_pullbacks : ∀ {Y Z} {f : Y ⟶ X} (_ : R f) {g : Z ⟶ X} (_ : R g), HasPullback f g instance (R : Presieve X) [HasPullbacks C] : R.hasPullbacks := ⟨fun _ _ ↦ inferInstance⟩ instance {α : Type v₂} {X : α → C} {B : C} (π : (a : α) → X a ⟶ B) [(Presieve.ofArrows X π).hasPullbacks] (a b : α) : HasPullback (π a) (π b) := Presieve.hasPullbacks.has_pullbacks (Presieve.ofArrows.mk _) (Presieve.ofArrows.mk _) section FunctorPushforward variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- Given a presieve on `X`, we can define a presieve on `F(X)` (which is actually a sieve) by taking the sieve generated by the image via `F`. -/ def functorPushforward (S : Presieve X) : Presieve (F.obj X) := fun Y f => ∃ (Z : C) (g : Z ⟶ X) (h : Y ⟶ F.obj Z), S g ∧ f = h ≫ F.map g /-- An auxiliary definition in order to fix the choice of the preimages between various definitions. -/ structure FunctorPushforwardStructure (S : Presieve X) {Y} (f : Y ⟶ F.obj X) where /-- an object in the source category -/ preobj : C /-- a map in the source category which has to be in the presieve -/ premap : preobj ⟶ X /-- the morphism which appear in the factorisation -/ lift : Y ⟶ F.obj preobj /-- the condition that `premap` is in the presieve -/ cover : S premap /-- the factorisation of the morphism -/ fac : f = lift ≫ F.map premap /-- The fixed choice of a preimage. -/ noncomputable def getFunctorPushforwardStructure {F : C ⥤ D} {S : Presieve X} {Y : D} {f : Y ⟶ F.obj X} (h : S.functorPushforward F f) : FunctorPushforwardStructure F S f := by choose Z f' g h₁ h using h exact ⟨Z, f', g, h₁, h⟩ theorem functorPushforward_comp (R : Presieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by funext x ext f constructor · rintro ⟨X, f₁, g₁, h₁, rfl⟩ exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩ · rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩ exact ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩ theorem image_mem_functorPushforward (R : Presieve X) {f : Y ⟶ X} (h : R f) : R.functorPushforward F (F.map f) := ⟨Y, f, 𝟙 _, h, by simp⟩ end FunctorPushforward end Presieve /-- For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under left-composition. -/ structure Sieve {C : Type u₁} [Category.{v₁} C] (X : C) where /-- the underlying presieve -/ arrows : Presieve X /-- stability by precomposition -/ downward_closed : ∀ {Y Z f} (_ : arrows f) (g : Z ⟶ Y), arrows (g ≫ f) namespace Sieve instance : CoeFun (Sieve X) fun _ => Presieve X := ⟨Sieve.arrows⟩ initialize_simps_projections Sieve (arrows → apply) variable {S R : Sieve X} attribute [simp] downward_closed theorem arrows_ext : ∀ {R S : Sieve X}, R.arrows = S.arrows → R = S := by rintro ⟨_, _⟩ ⟨_, _⟩ rfl rfl @[ext] protected theorem ext {R S : Sieve X} (h : ∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f) : R = S := arrows_ext <| funext fun _ => funext fun f => propext <| h f open Lattice /-- The supremum of a collection of sieves: the union of them all. -/ protected def sup (𝒮 : Set (Sieve X)) : Sieve X where arrows _ := { f | ∃ S ∈ 𝒮, Sieve.arrows S f } downward_closed {_ _ f} hf _ := by obtain ⟨S, hS, hf⟩ := hf exact ⟨S, hS, S.downward_closed hf _⟩ /-- The infimum of a collection of sieves: the intersection of them all. -/ protected def inf (𝒮 : Set (Sieve X)) : Sieve X where arrows _ := { f | ∀ S ∈ 𝒮, Sieve.arrows S f } downward_closed {_ _ _} hf g S H := S.downward_closed (hf S H) g /-- The union of two sieves is a sieve. -/ protected def union (S R : Sieve X) : Sieve X where arrows _ f := S f ∨ R f downward_closed := by rintro _ _ _ (h | h) g <;> simp [h] /-- The intersection of two sieves is a sieve. -/ protected def inter (S R : Sieve X) : Sieve X where arrows _ f := S f ∧ R f downward_closed := by rintro _ _ _ ⟨h₁, h₂⟩ g simp [h₁, h₂] /-- Sieves on an object `X` form a complete lattice. We generate this directly rather than using the galois insertion for nicer definitional properties. -/ instance : CompleteLattice (Sieve X) where le S R := ∀ ⦃Y⦄ (f : Y ⟶ X), S f → R f le_refl _ _ _ := id le_trans _ _ _ S₁₂ S₂₃ _ _ h := S₂₃ _ (S₁₂ _ h) le_antisymm _ _ p q := Sieve.ext fun _ _ => ⟨p _, q _⟩ top := { arrows := fun _ => Set.univ downward_closed := fun _ _ => ⟨⟩ } bot := { arrows := fun _ => ∅ downward_closed := False.elim } sup := Sieve.union inf := Sieve.inter sSup := Sieve.sup sInf := Sieve.inf le_sSup _ S hS _ _ hf := ⟨S, hS, hf⟩ sSup_le := fun _ _ ha _ _ ⟨b, hb, hf⟩ => (ha b hb) _ hf sInf_le _ _ hS _ _ h := h _ hS le_sInf _ _ hS _ _ hf _ hR := hS _ hR _ hf le_sup_left _ _ _ _ := Or.inl le_sup_right _ _ _ _ := Or.inr sup_le _ _ _ h₁ h₂ _ f := by--ℰ S hS Y f := by rintro (hf | hf) · exact h₁ _ hf · exact h₂ _ hf inf_le_left _ _ _ _ := And.left inf_le_right _ _ _ _ := And.right le_inf _ _ _ p q _ _ z := ⟨p _ z, q _ z⟩ le_top _ _ _ _ := trivial bot_le _ _ _ := False.elim /-- The maximal sieve always exists. -/ instance sieveInhabited : Inhabited (Sieve X) := ⟨⊤⟩ @[simp] theorem sInf_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) : sInf Ss f ↔ ∀ (S : Sieve X) (_ : S ∈ Ss), S f := Iff.rfl @[simp] theorem sSup_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) : sSup Ss f ↔ ∃ (S : Sieve X) (_ : S ∈ Ss), S f := by simp [sSup, Sieve.sup, setOf] @[simp] theorem inter_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊓ S) f ↔ R f ∧ S f := Iff.rfl @[simp] theorem union_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊔ S) f ↔ R f ∨ S f := Iff.rfl @[simp] theorem top_apply (f : Y ⟶ X) : (⊤ : Sieve X) f := trivial /-- Generate the smallest sieve containing the given set of arrows. -/ @[simps] def generate (R : Presieve X) : Sieve X where arrows Z f := ∃ (Y : _) (h : Z ⟶ Y) (g : Y ⟶ X), R g ∧ h ≫ g = f downward_closed := by rintro Y Z _ ⟨W, g, f, hf, rfl⟩ h exact ⟨_, h ≫ g, _, hf, by simp⟩ /-- Given a presieve on `X`, and a sieve on each domain of an arrow in the presieve, we can bind to produce a sieve on `X`. -/ @[simps] def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) : Sieve X where arrows := S.bind fun _ _ h => R h downward_closed := by rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩ /-- Structure which contains the data and properties for a morphism `h` satisfying `Sieve.bind S R h`. -/ abbrev BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) {Z : C} (h : Z ⟶ X) := Presieve.BindStruct S (fun _ _ hf ↦ R hf) h open Order Lattice theorem generate_le_iff (R : Presieve X) (S : Sieve X) : generate R ≤ S ↔ R ≤ S := ⟨fun H _ _ hg => H _ ⟨_, 𝟙 _, _, hg, id_comp _⟩, fun ss Y f => by rintro ⟨Z, f, g, hg, rfl⟩ exact S.downward_closed (ss Z hg) f⟩ /-- Show that there is a galois insertion (generate, set_over). -/ def giGenerate : GaloisInsertion (generate : Presieve X → Sieve X) arrows where gc := generate_le_iff choice 𝒢 _ := generate 𝒢 choice_eq _ _ := rfl le_l_u _ _ _ hf := ⟨_, 𝟙 _, _, hf, id_comp _⟩ theorem le_generate (R : Presieve X) : R ≤ generate R := giGenerate.gc.le_u_l R @[simp] theorem generate_sieve (S : Sieve X) : generate S = S := giGenerate.l_u_eq S /-- If the identity arrow is in a sieve, the sieve is maximal. -/ theorem id_mem_iff_eq_top : S (𝟙 X) ↔ S = ⊤ := ⟨fun h => top_unique fun Y f _ => by simpa using downward_closed _ h f, fun h => h.symm ▸ trivial⟩ /-- If an arrow set contains a split epi, it generates the maximal sieve. -/ theorem generate_of_contains_isSplitEpi {R : Presieve X} (f : Y ⟶ X) [IsSplitEpi f] (hf : R f) : generate R = ⊤ := by rw [← id_mem_iff_eq_top] exact ⟨_, section_ f, f, hf, by simp⟩ @[simp] theorem generate_of_singleton_isSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : generate (Presieve.singleton f) = ⊤ := generate_of_contains_isSplitEpi f (Presieve.singleton_self _) @[simp] theorem generate_top : generate (⊤ : Presieve X) = ⊤ := generate_of_contains_isSplitEpi (𝟙 _) ⟨⟩ @[simp] lemma comp_mem_iff (i : X ⟶ Y) (f : Y ⟶ Z) [IsIso i] (S : Sieve Z) : S (i ≫ f) ↔ S f := by refine ⟨fun H ↦ ?_, fun H ↦ S.downward_closed H _⟩ convert S.downward_closed H (inv i) simp section variable {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X) /-- The sieve of `X` generated by family of morphisms `Y i ⟶ X`. -/ abbrev ofArrows : Sieve X := generate (Presieve.ofArrows Y f) lemma ofArrows_mk (i : I) : ofArrows Y f (f i) := ⟨_, 𝟙 _, _, ⟨i⟩, by simp⟩ lemma mem_ofArrows_iff {W : C} (g : W ⟶ X) : ofArrows Y f g ↔ ∃ (i : I) (a : W ⟶ Y i), g = a ≫ f i := by constructor · rintro ⟨T, a, b, ⟨i⟩, rfl⟩ exact ⟨i, a, rfl⟩ · rintro ⟨i, a, rfl⟩ apply downward_closed _ (ofArrows_mk Y f i) variable {Y f} {W : C} {g : W ⟶ X} (hg : ofArrows Y f g) include hg in lemma ofArrows.exists : ∃ (i : I) (h : W ⟶ Y i), g = h ≫ f i := by obtain ⟨_, h, _, ⟨i⟩, rfl⟩ := hg exact ⟨i, h, rfl⟩ /-- When `hg : Sieve.ofArrows Y f g`, this is a choice of `i` such that `g` factors through `f i`. -/ noncomputable def ofArrows.i : I := (ofArrows.exists hg).choose /-- When `hg : Sieve.ofArrows Y f g`, this is a morphism `h : W ⟶ Y (i hg)` such that `h ≫ f (i hg) = g`. -/ noncomputable def ofArrows.h : W ⟶ Y (i hg) := (ofArrows.exists hg).choose_spec.choose @[reassoc (attr := simp)] lemma ofArrows.fac : h hg ≫ f (i hg) = g := (ofArrows.exists hg).choose_spec.choose_spec.symm end /-- The sieve generated by two morphisms. -/ abbrev ofTwoArrows {U V X : C} (i : U ⟶ X) (j : V ⟶ X) : Sieve X := Sieve.ofArrows (Y := pairFunction U V) (fun k ↦ WalkingPair.casesOn k i j) /-- The sieve of `X : C` that is generated by a family of objects `Y : I → C`: it consists of morphisms to `X` which factor through at least one of the `Y i`. -/ def ofObjects {I : Type*} (Y : I → C) (X : C) : Sieve X where arrows Z _ := ∃ (i : I), Nonempty (Z ⟶ Y i) downward_closed := by rintro Z₁ Z₂ p ⟨i, ⟨f⟩⟩ g exact ⟨i, ⟨g ≫ f⟩⟩ lemma mem_ofObjects_iff {I : Type*} (Y : I → C) {Z X : C} (g : Z ⟶ X) : ofObjects Y X g ↔ ∃ (i : I), Nonempty (Z ⟶ Y i) := by rfl lemma ofArrows_le_ofObjects {I : Type*} (Y : I → C) {X : C} (f : ∀ i, Y i ⟶ X) : Sieve.ofArrows Y f ≤ Sieve.ofObjects Y X := by intro W g hg rw [mem_ofArrows_iff] at hg obtain ⟨i, a, rfl⟩ := hg exact ⟨i, ⟨a⟩⟩ lemma ofArrows_eq_ofObjects {X : C} (hX : IsTerminal X) {I : Type*} (Y : I → C) (f : ∀ i, Y i ⟶ X) : ofArrows Y f = ofObjects Y X := by refine le_antisymm (ofArrows_le_ofObjects Y f) (fun W g => ?_) rw [mem_ofArrows_iff, mem_ofObjects_iff] rintro ⟨i, ⟨h⟩⟩ exact ⟨i, h, hX.hom_ext _ _⟩ /-- Given a morphism `h : Y ⟶ X`, send a sieve S on X to a sieve on Y as the inverse image of S with `_ ≫ h`. That is, `Sieve.pullback S h := (≫ h) '⁻¹ S`. -/ @[simps] def pullback (h : Y ⟶ X) (S : Sieve X) : Sieve Y where arrows _ sl := S (sl ≫ h) downward_closed g := by simp [g] @[simp] theorem pullback_id : S.pullback (𝟙 _) = S := by simp [Sieve.ext_iff] @[simp] theorem pullback_top {f : Y ⟶ X} : (⊤ : Sieve X).pullback f = ⊤ := top_unique fun _ _ => id theorem pullback_comp {f : Y ⟶ X} {g : Z ⟶ Y} (S : Sieve X) : S.pullback (g ≫ f) = (S.pullback f).pullback g := by simp [Sieve.ext_iff] @[simp] theorem pullback_inter {f : Y ⟶ X} (S R : Sieve X) : (S ⊓ R).pullback f = S.pullback f ⊓ R.pullback f := by simp [Sieve.ext_iff] theorem mem_iff_pullback_eq_top (f : Y ⟶ X) : S f ↔ S.pullback f = ⊤ := by rw [← id_mem_iff_eq_top, pullback_apply, id_comp] @[deprecated (since := "2025-02-28")] alias pullback_eq_top_iff_mem := mem_iff_pullback_eq_top theorem pullback_eq_top_of_mem (S : Sieve X) {f : Y ⟶ X} : S f → S.pullback f = ⊤ := (mem_iff_pullback_eq_top f).1 lemma pullback_ofObjects_eq_top {I : Type*} (Y : I → C) {X : C} {i : I} (g : X ⟶ Y i) : ofObjects Y X = ⊤ := by ext Z h simp only [top_apply, iff_true] rw [mem_ofObjects_iff ] exact ⟨i, ⟨h ≫ g⟩⟩ /-- Push a sieve `R` on `Y` forward along an arrow `f : Y ⟶ X`: `gf : Z ⟶ X` is in the sieve if `gf` factors through some `g : Z ⟶ Y` which is in `R`. -/ @[simps] def pushforward (f : Y ⟶ X) (R : Sieve Y) : Sieve X where arrows _ gf := ∃ g, g ≫ f = gf ∧ R g downward_closed := fun ⟨j, k, z⟩ h => ⟨h ≫ j, by simp [k], by simp [z]⟩ theorem pushforward_apply_comp {R : Sieve Y} {Z : C} {g : Z ⟶ Y} (hg : R g) (f : Y ⟶ X) : R.pushforward f (g ≫ f) := ⟨g, rfl, hg⟩ theorem pushforward_comp {f : Y ⟶ X} {g : Z ⟶ Y} (R : Sieve Z) : R.pushforward (g ≫ f) = (R.pushforward g).pushforward f := Sieve.ext fun W h => ⟨fun ⟨f₁, hq, hf₁⟩ => ⟨f₁ ≫ g, by simpa, f₁, rfl, hf₁⟩, fun ⟨y, hy, z, hR, hz⟩ => ⟨z, by rw [← Category.assoc, hR]; tauto⟩⟩ theorem galoisConnection (f : Y ⟶ X) : GaloisConnection (Sieve.pushforward f) (Sieve.pullback f) := fun _ _ => ⟨fun hR _ g hg => hR _ ⟨g, rfl, hg⟩, fun hS _ _ ⟨h, hg, hh⟩ => hg ▸ hS h hh⟩ theorem pullback_monotone (f : Y ⟶ X) : Monotone (Sieve.pullback f) := (galoisConnection f).monotone_u theorem pushforward_monotone (f : Y ⟶ X) : Monotone (Sieve.pushforward f) := (galoisConnection f).monotone_l theorem le_pushforward_pullback (f : Y ⟶ X) (R : Sieve Y) : R ≤ (R.pushforward f).pullback f := (galoisConnection f).le_u_l _ theorem pullback_pushforward_le (f : Y ⟶ X) (R : Sieve X) : (R.pullback f).pushforward f ≤ R := (galoisConnection f).l_u_le _ theorem pushforward_union {f : Y ⟶ X} (S R : Sieve Y) : (S ⊔ R).pushforward f = S.pushforward f ⊔ R.pushforward f := (galoisConnection f).l_sup theorem pushforward_le_bind_of_mem (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X) (h : S f) : (R h).pushforward f ≤ bind S R := by rintro Z _ ⟨g, rfl, hg⟩ exact ⟨_, g, f, h, hg, rfl⟩ theorem le_pullback_bind (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X) (h : S f) : R h ≤ (bind S R).pullback f := by rw [← galoisConnection f] apply pushforward_le_bind_of_mem /-- If `f` is a monomorphism, the pushforward-pullback adjunction on sieves is coreflective. -/ def galoisCoinsertionOfMono (f : Y ⟶ X) [Mono f] : GaloisCoinsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisCoinsertion rintro S Z g ⟨g₁, hf, hg₁⟩ rw [cancel_mono f] at hf rwa [← hf] /-- If `f` is a split epi, the pushforward-pullback adjunction on sieves is reflective. -/ def galoisInsertionOfIsSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : GaloisInsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisInsertion intro S Z g hg exact ⟨g ≫ section_ f, by simpa⟩ theorem pullbackArrows_comm [HasPullbacks C] {X Y : C} (f : Y ⟶ X) (R : Presieve X) : Sieve.generate (R.pullbackArrows f) = (Sieve.generate R).pullback f := by ext W g constructor · rintro ⟨_, h, k, ⟨W, g, hg⟩, rfl⟩ rw [Sieve.pullback_apply, assoc, ← pullback.condition, ← assoc] exact Sieve.downward_closed _ (by exact Sieve.le_generate R W hg) (h ≫ pullback.fst g f) · rintro ⟨W, h, k, hk, comm⟩ exact ⟨_, _, _, Presieve.pullbackArrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩ section Functor variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E) /-- If `R` is a sieve, then the `CategoryTheory.Presieve.functorPullback` of `R` is actually a sieve. -/ @[simps] def functorPullback (R : Sieve (F.obj X)) : Sieve X where arrows := Presieve.functorPullback F R downward_closed := by intro _ _ f hf g unfold Presieve.functorPullback rw [F.map_comp] exact R.downward_closed hf (F.map g) @[simp] theorem functorPullback_arrows (R : Sieve (F.obj X)) : (R.functorPullback F).arrows = R.arrows.functorPullback F := rfl @[simp] theorem functorPullback_id (R : Sieve X) : R.functorPullback (𝟭 _) = R := by ext rfl theorem functorPullback_comp (R : Sieve ((F ⋙ G).obj X)) : R.functorPullback (F ⋙ G) = (R.functorPullback G).functorPullback F := by ext rfl theorem functorPushforward_extend_eq {R : Presieve X} : (generate R).arrows.functorPushforward F = R.functorPushforward F := by funext Y ext f constructor · rintro ⟨X', g, f', ⟨X'', g', f'', h₁, rfl⟩, rfl⟩ exact ⟨X'', f'', f' ≫ F.map g', h₁, by simp⟩ · rintro ⟨X', g, f', h₁, h₂⟩ exact ⟨X', g, f', le_generate R _ h₁, h₂⟩ /-- The sieve generated by the image of `R` under `F`. -/ @[simps] def functorPushforward (R : Sieve X) : Sieve (F.obj X) where arrows := R.arrows.functorPushforward F downward_closed := by intro _ _ f h g obtain ⟨X, α, β, hα, rfl⟩ := h exact ⟨X, α, g ≫ β, hα, by simp⟩ @[simp] theorem functorPushforward_id (R : Sieve X) : R.functorPushforward (𝟭 _) = R := by ext X f constructor · intro hf obtain ⟨X, g, h, hg, rfl⟩ := hf exact R.downward_closed hg h · intro hf exact ⟨X, f, 𝟙 _, hf, by simp⟩ theorem functorPushforward_comp (R : Sieve X) : R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by ext simp [R.arrows.functorPushforward_comp F G] theorem functor_galoisConnection (X : C) : GaloisConnection (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) (Sieve.functorPullback F) := by intro R S constructor · intro hle X f hf apply hle refine ⟨X, f, 𝟙 _, hf, ?_⟩ rw [id_comp] · rintro hle Y f ⟨X, g, h, hg, rfl⟩ apply Sieve.downward_closed S exact hle g hg theorem functorPullback_monotone (X : C) : Monotone (Sieve.functorPullback F : Sieve (F.obj X) → Sieve X) := (functor_galoisConnection F X).monotone_u theorem functorPushforward_monotone (X : C) : Monotone (Sieve.functorPushforward F : Sieve X → Sieve (F.obj X)) := (functor_galoisConnection F X).monotone_l
theorem le_functorPushforward_pullback (R : Sieve X) : R ≤ (R.functorPushforward F).functorPullback F := (functor_galoisConnection F X).le_u_l _ theorem functorPullback_pushforward_le (R : Sieve (F.obj X)) : (R.functorPullback F).functorPushforward F ≤ R := (functor_galoisConnection F X).l_u_le _ theorem functorPushforward_union (S R : Sieve X) : (S ⊔ R).functorPushforward F = S.functorPushforward F ⊔ R.functorPushforward F := (functor_galoisConnection F X).l_sup
Mathlib/CategoryTheory/Sites/Sieves.lean
716
727
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.Squarefree.Basic import Mathlib.Data.Nat.Factorization.PrimePow import Mathlib.RingTheory.UniqueFactorizationDomain.Nat /-! # Lemmas about squarefreeness of natural numbers A number is squarefree when it is not divisible by any squares except the squares of units. ## Main Results - `Nat.squarefree_iff_nodup_primeFactorsList`: A positive natural number `x` is squarefree iff the list `factors x` has no duplicate factors. ## Tags squarefree, multiplicity -/ open Finset namespace Nat theorem squarefree_iff_nodup_primeFactorsList {n : ℕ} (h0 : n ≠ 0) : Squarefree n ↔ n.primeFactorsList.Nodup := by rw [UniqueFactorizationMonoid.squarefree_iff_nodup_normalizedFactors h0, Nat.factors_eq] simp end Nat theorem Squarefree.nodup_primeFactorsList {n : ℕ} (hn : Squarefree n) : n.primeFactorsList.Nodup := (Nat.squarefree_iff_nodup_primeFactorsList hn.ne_zero).mp hn namespace Nat variable {s : Finset ℕ} {m n p : ℕ} theorem squarefree_iff_prime_squarefree {n : ℕ} : Squarefree n ↔ ∀ x, Prime x → ¬x * x ∣ n := squarefree_iff_irreducible_sq_not_dvd_of_exists_irreducible ⟨_, prime_two⟩ theorem _root_.Squarefree.natFactorization_le_one {n : ℕ} (p : ℕ) (hn : Squarefree n) : n.factorization p ≤ 1 := by rcases eq_or_ne n 0 with (rfl | hn') · simp rw [squarefree_iff_emultiplicity_le_one] at hn by_cases hp : p.Prime · have := hn p rw [← multiplicity_eq_factorization hp hn'] simp only [Nat.isUnit_iff, hp.ne_one, or_false] at this exact multiplicity_le_of_emultiplicity_le this · rw [factorization_eq_zero_of_non_prime _ hp] exact zero_le_one lemma factorization_eq_one_of_squarefree (hn : Squarefree n) (hp : p.Prime) (hpn : p ∣ n) : factorization n p = 1 := (hn.natFactorization_le_one _).antisymm <| (hp.dvd_iff_one_le_factorization hn.ne_zero).1 hpn theorem squarefree_of_factorization_le_one {n : ℕ} (hn : n ≠ 0) (hn' : ∀ p, n.factorization p ≤ 1) : Squarefree n := by rw [squarefree_iff_nodup_primeFactorsList hn, List.nodup_iff_count_le_one] intro a rw [primeFactorsList_count_eq] apply hn' theorem squarefree_iff_factorization_le_one {n : ℕ} (hn : n ≠ 0) : Squarefree n ↔ ∀ p, n.factorization p ≤ 1 := ⟨fun hn => hn.natFactorization_le_one, squarefree_of_factorization_le_one hn⟩ theorem Squarefree.ext_iff {n m : ℕ} (hn : Squarefree n) (hm : Squarefree m) : n = m ↔ ∀ p, Prime p → (p ∣ n ↔ p ∣ m) := by refine ⟨by rintro rfl; simp, fun h => eq_of_factorization_eq hn.ne_zero hm.ne_zero fun p => ?_⟩ by_cases hp : p.Prime · have h₁ := h _ hp rw [← not_iff_not, hp.dvd_iff_one_le_factorization hn.ne_zero, not_le, lt_one_iff, hp.dvd_iff_one_le_factorization hm.ne_zero, not_le, lt_one_iff] at h₁ have h₂ := hn.natFactorization_le_one p have h₃ := hm.natFactorization_le_one p omega rw [factorization_eq_zero_of_non_prime _ hp, factorization_eq_zero_of_non_prime _ hp] theorem squarefree_pow_iff {n k : ℕ} (hn : n ≠ 1) (hk : k ≠ 0) : Squarefree (n ^ k) ↔ Squarefree n ∧ k = 1 := by refine ⟨fun h => ?_, by rintro ⟨hn, rfl⟩; simpa⟩ rcases eq_or_ne n 0 with (rfl | -) · simp [zero_pow hk] at h refine ⟨h.squarefree_of_dvd (dvd_pow_self _ hk), by_contradiction fun h₁ => ?_⟩ have : 2 ≤ k := k.two_le_iff.mpr ⟨hk, h₁⟩ apply hn (Nat.isUnit_iff.1 (h _ _)) rw [← sq] exact pow_dvd_pow _ this theorem squarefree_and_prime_pow_iff_prime {n : ℕ} : Squarefree n ∧ IsPrimePow n ↔ Prime n := by refine ⟨?_, fun hn => ⟨hn.squarefree, hn.isPrimePow⟩⟩ rw [isPrimePow_nat_iff] rintro ⟨h, p, k, hp, hk, rfl⟩ rw [squarefree_pow_iff hp.ne_one hk.ne'] at h rwa [h.2, pow_one] /-- Assuming that `n` has no factors less than `k`, returns the smallest prime `p` such that `p^2 ∣ n`. -/ def minSqFacAux : ℕ → ℕ → Option ℕ | n, k => if h : n < k * k then none else have : Nat.sqrt n - k < Nat.sqrt n + 2 - k := by exact Nat.minFac_lemma n k h if k ∣ n then let n' := n / k have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k := lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt <| Nat.div_le_self _ _) k) this if k ∣ n' then some k else minSqFacAux n' (k + 2) else minSqFacAux n (k + 2) termination_by n k => sqrt n + 2 - k /-- Returns the smallest prime factor `p` of `n` such that `p^2 ∣ n`, or `none` if there is no such `p` (that is, `n` is squarefree). See also `Nat.squarefree_iff_minSqFac`. -/ def minSqFac (n : ℕ) : Option ℕ := if 2 ∣ n then let n' := n / 2 if 2 ∣ n' then some 2 else minSqFacAux n' 3 else minSqFacAux n 3 /-- The correctness property of the return value of `minSqFac`. * If `none`, then `n` is squarefree; * If `some d`, then `d` is a minimal square factor of `n` -/ def MinSqFacProp (n : ℕ) : Option ℕ → Prop | none => Squarefree n | some d => Prime d ∧ d * d ∣ n ∧ ∀ p, Prime p → p * p ∣ n → d ≤ p theorem minSqFacProp_div (n) {k} (pk : Prime k) (dk : k ∣ n) (dkk : ¬k * k ∣ n) {o} (H : MinSqFacProp (n / k) o) : MinSqFacProp n o := by have : ∀ p, Prime p → p * p ∣ n → k * (p * p) ∣ n := fun p pp dp => have := (coprime_primes pk pp).2 fun e => by subst e contradiction (coprime_mul_iff_right.2 ⟨this, this⟩).mul_dvd_of_dvd_of_dvd dk dp rcases o with - | d · rw [MinSqFacProp, squarefree_iff_prime_squarefree] at H ⊢ exact fun p pp dp => H p pp ((dvd_div_iff_mul_dvd dk).2 (this _ pp dp)) · obtain ⟨H1, H2, H3⟩ := H simp only [dvd_div_iff_mul_dvd dk] at H2 H3 exact ⟨H1, dvd_trans (dvd_mul_left _ _) H2, fun p pp dp => H3 _ pp (this _ pp dp)⟩ theorem minSqFacAux_has_prop {n : ℕ} (k) (n0 : 0 < n) (i) (e : k = 2 * i + 3) (ih : ∀ m, Prime m → m ∣ n → k ≤ m) : MinSqFacProp n (minSqFacAux n k) := by rw [minSqFacAux] by_cases h : n < k * k <;> simp only [h, ↓reduceDIte] · refine squarefree_iff_prime_squarefree.2 fun p pp d => ?_ have := ih p pp (dvd_trans ⟨_, rfl⟩ d) have := Nat.mul_le_mul this this exact not_le_of_lt h (le_trans this (le_of_dvd n0 d)) have k2 : 2 ≤ k := by omega have k0 : 0 < k := lt_of_lt_of_le (by decide) k2 have IH : ∀ n', n' ∣ n → ¬k ∣ n' → MinSqFacProp n' (n'.minSqFacAux (k + 2)) := by intro n' nd' nk have hn' := le_of_dvd n0 nd' refine have : Nat.sqrt n' - k < Nat.sqrt n + 2 - k := lt_of_le_of_lt (Nat.sub_le_sub_right (Nat.sqrt_le_sqrt hn') _) (Nat.minFac_lemma n k h) @minSqFacAux_has_prop n' (k + 2) (pos_of_dvd_of_pos nd' n0) (i + 1) (by simp [e, left_distrib]) fun m m2 d => ?_ rcases Nat.eq_or_lt_of_le (ih m m2 (dvd_trans d nd')) with me | ml · subst me contradiction apply (Nat.eq_or_lt_of_le ml).resolve_left intro me rw [← me, e] at d change 2 * (i + 2) ∣ n' at d have := ih _ prime_two (dvd_trans (dvd_of_mul_right_dvd d) nd') rw [e] at this exact absurd this (by omega) have pk : k ∣ n → Prime k := by refine fun dk => prime_def_minFac.2 ⟨k2, le_antisymm (minFac_le k0) ?_⟩ exact ih _ (minFac_prime (ne_of_gt k2)) (dvd_trans (minFac_dvd _) dk) split_ifs with dk dkk · exact ⟨pk dk, (Nat.dvd_div_iff_mul_dvd dk).1 dkk, fun p pp d => ih p pp (dvd_trans ⟨_, rfl⟩ d)⟩ · specialize IH (n / k) (div_dvd_of_dvd dk) dkk exact minSqFacProp_div _ (pk dk) dk (mt (Nat.dvd_div_iff_mul_dvd dk).2 dkk) IH · exact IH n (dvd_refl _) dk termination_by n.sqrt + 2 - k theorem minSqFac_has_prop (n : ℕ) : MinSqFacProp n (minSqFac n) := by dsimp only [minSqFac]; split_ifs with d2 d4 · exact ⟨prime_two, (dvd_div_iff_mul_dvd d2).1 d4, fun p pp _ => pp.two_le⟩ · rcases Nat.eq_zero_or_pos n with n0 | n0 · subst n0 cases d4 (by decide) refine minSqFacProp_div _ prime_two d2 (mt (dvd_div_iff_mul_dvd d2).2 d4) ?_ refine minSqFacAux_has_prop 3 (Nat.div_pos (le_of_dvd n0 d2) (by decide)) 0 rfl ?_ refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_) rintro rfl contradiction · rcases Nat.eq_zero_or_pos n with n0 | n0 · subst n0 cases d2 (by decide) refine minSqFacAux_has_prop _ n0 0 rfl ?_ refine fun p pp dp => succ_le_of_lt (lt_of_le_of_ne pp.two_le ?_) rintro rfl contradiction theorem minSqFac_prime {n d : ℕ} (h : n.minSqFac = some d) : Prime d := by have := minSqFac_has_prop n rw [h] at this exact this.1 theorem minSqFac_dvd {n d : ℕ} (h : n.minSqFac = some d) : d * d ∣ n := by have := minSqFac_has_prop n rw [h] at this exact this.2.1 theorem minSqFac_le_of_dvd {n d : ℕ} (h : n.minSqFac = some d) {m} (m2 : 2 ≤ m) (md : m * m ∣ n) : d ≤ m := by have := minSqFac_has_prop n; rw [h] at this have fd := minFac_dvd m exact le_trans (this.2.2 _ (minFac_prime <| ne_of_gt m2) (dvd_trans (mul_dvd_mul fd fd) md)) (minFac_le <| lt_of_lt_of_le (by decide) m2) theorem squarefree_iff_minSqFac {n : ℕ} : Squarefree n ↔ n.minSqFac = none := by have := minSqFac_has_prop n constructor <;> intro H · rcases e : n.minSqFac with - | d · rfl rw [e] at this cases squarefree_iff_prime_squarefree.1 H _ this.1 this.2.1 · rwa [H] at this instance : DecidablePred (Squarefree : ℕ → Prop) := fun _ => decidable_of_iff' _ squarefree_iff_minSqFac theorem squarefree_two : Squarefree 2 := by rw [squarefree_iff_nodup_primeFactorsList] <;> simp theorem divisors_filter_squarefree_of_squarefree {n : ℕ} (hn : Squarefree n) : {d ∈ n.divisors | Squarefree d} = n.divisors := Finset.ext fun d => ⟨@Finset.filter_subset _ _ _ _ d, fun hd => Finset.mem_filter.mpr ⟨hd, hn.squarefree_of_dvd (Nat.dvd_of_mem_divisors hd) ⟩⟩ open UniqueFactorizationMonoid
theorem divisors_filter_squarefree {n : ℕ} (h0 : n ≠ 0) : {d ∈ n.divisors | Squarefree d}.val = (UniqueFactorizationMonoid.normalizedFactors n).toFinset.powerset.val.map fun x => x.val.prod := by rw [(Finset.nodup _).ext ((Finset.nodup _).map_on _)] · intro a simp only [Multiset.mem_filter, id, Multiset.mem_map, Finset.filter_val, ← Finset.mem_def, mem_divisors]
Mathlib/Data/Nat/Squarefree.lean
244
251
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Control.Basic import Mathlib.Data.Nat.Basic import Mathlib.Data.Option.Basic import Mathlib.Data.List.Defs import Mathlib.Data.List.Monad import Mathlib.Logic.OpClass import Mathlib.Logic.Unique import Mathlib.Order.Basic import Mathlib.Tactic.Common /-! # Basic properties of lists -/ assert_not_exists GroupWithZero assert_not_exists Lattice assert_not_exists Prod.swap_eq_iff_eq_swap assert_not_exists Ring assert_not_exists Set.range open Function open Nat hiding one_pos namespace List universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α} /-- There is only one list of an empty type -/ instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) := { instInhabitedList with uniq := fun l => match l with | [] => rfl | a :: _ => isEmptyElim a } instance : Std.LawfulIdentity (α := List α) Append.append [] where left_id := nil_append right_id := append_nil instance : Std.Associative (α := List α) Append.append where assoc := append_assoc @[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1 theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } := Set.ext fun _ => mem_cons /-! ### mem -/ theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α] {a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by by_cases hab : a = b · exact Or.inl hab · exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩)) lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by rw [mem_cons, mem_singleton] -- The simpNF linter says that the LHS can be simplified via `List.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} : f a ∈ map f l ↔ a ∈ l := ⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩ @[simp] theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α} (hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l := ⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩ theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} : a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff] /-! ### length -/ alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t | [], H => absurd H.symm <| succ_ne_zero n | h :: t, _ => ⟨h, t, rfl⟩ @[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by constructor · intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl · intros hα l1 l2 hl induction l1 generalizing l2 <;> cases l2 · rfl · cases hl · cases hl · next ih _ _ => congr · subsingleton · apply ih; simpa using hl @[simp default+1] -- Raise priority above `length_injective_iff`. lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) := length_injective_iff.mpr inferInstance theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] := ⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩ theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] := ⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩ /-! ### set-theoretic notation of lists -/ instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩ instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩ instance [DecidableEq α] : LawfulSingleton α (List α) := { insert_empty_eq := fun x => show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil } theorem singleton_eq (x : α) : ({x} : List α) = [x] := rfl theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) : Insert.insert x l = x :: l := insert_of_not_mem h theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l := insert_of_mem h theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by rw [insert_neg, singleton_eq] rwa [singleton_eq, mem_singleton] /-! ### bounded quantifiers over lists -/ theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) : ∀ x ∈ l, p x := (forall_mem_cons.1 h).2 theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x := ⟨a, mem_cons_self, h⟩ theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) → ∃ x ∈ a :: l, p x := fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩ theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) → p a ∨ ∃ x ∈ l, p x := fun ⟨x, xal, px⟩ => Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px) fun h : x ∈ l => Or.inr ⟨x, h, px⟩ theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x := Iff.intro or_exists_of_exists_mem_cons fun h => Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists /-! ### list subset -/ theorem cons_subset_of_subset_of_mem {a : α} {l m : List α} (ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m := cons_subset.2 ⟨ainm, lsubm⟩ theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) : l₁ ++ l₂ ⊆ l := fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _) theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) : map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by refine ⟨?_, map_subset f⟩; intro h2 x hx rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩ cases h hxx'; exact hx' /-! ### append -/ theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ := rfl theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t := fun _ _ ↦ append_cancel_left theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t := fun _ _ ↦ append_cancel_right /-! ### replicate -/ theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a | [] => by simp | (b :: l) => by simp [eq_replicate_length, replicate_succ] theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by rw [replicate_append_replicate] theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h => mem_singleton.2 (eq_of_mem_replicate h) theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left'] theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective hn).eq_iff theorem replicate_right_inj' {a b : α} : ∀ {n}, replicate n a = replicate n b ↔ n = 0 ∨ a = b | 0 => by simp | n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or] theorem replicate_left_injective (a : α) : Injective (replicate · a) := LeftInverse.injective (length_replicate (n := ·)) theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m := (replicate_left_injective a).eq_iff @[simp] theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.head? = l.head? := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h induction l <;> simp [replicate] @[simp] theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.getLast? = l.getLast? := by rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate, List.reverse_replicate, head?_flatten_replicate h] /-! ### pure -/ theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp /-! ### bind -/ @[simp] theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f := rfl /-! ### concat -/ /-! ### reverse -/ theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by rw [reverse_append]; rfl @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl @[simp] theorem reverse_involutive : Involutive (@reverse α) := reverse_reverse @[simp] theorem reverse_injective : Injective (@reverse α) := reverse_involutive.injective theorem reverse_surjective : Surjective (@reverse α) := reverse_involutive.surjective theorem reverse_bijective : Bijective (@reverse α) := reverse_involutive.bijective theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by simp only [concat_eq_append, reverse_cons, reverse_reverse] theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) : map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by simp only [reverseAux_eq, map_append, map_reverse] -- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self` @[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where mp := l₁.reverse_perm.symm.trans mpr := l₁.reverse_perm.trans @[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where mp hl := hl.trans l₂.reverse_perm mpr hl := hl.trans l₂.reverse_perm.symm /-! ### getLast -/ attribute [simp] getLast_cons theorem getLast_append_singleton {a : α} (l : List α) : getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by simp [getLast_append] theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) : getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by induction l₁ with | nil => simp | cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih @[deprecated (since := "2025-02-06")] alias getLast_append' := getLast_append_of_right_ne_nil theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by simp @[simp] theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl @[simp] theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) : getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) := rfl theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l | [], h => absurd rfl h | [_], _ => rfl | a :: b :: l, h => by rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)] congr exact dropLast_append_getLast (cons_ne_nil b l) theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl theorem getLast_replicate_succ (m : ℕ) (a : α) : (replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by simp only [replicate_succ'] exact getLast_append_singleton _ @[deprecated (since := "2025-02-07")] alias getLast_filter' := getLast_filter_of_pos /-! ### getLast? -/ theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h | [], x, hx => False.elim <| by simp at hx | [a], x, hx => have : a = x := by simpa using hx this ▸ ⟨cons_ne_nil a [], rfl⟩ | a :: b :: l, x, hx => by rw [getLast?_cons_cons] at hx rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩ use cons_ne_nil _ _ assumption theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h) | [], h => (h rfl).elim | [_], _ => rfl | _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _) theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast? | [], _ => by contradiction | _ :: _, h => h theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l | [], a, ha => (Option.not_mem_none a ha).elim | [a], _, rfl => rfl | a :: b :: l, c, hc => by rw [getLast?_cons_cons] at hc rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc] theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget | [] => by simp [getLastI, Inhabited.default] | [_] => rfl | [_, _] => rfl | [_, _, _] => rfl | _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)] theorem getLast?_append_cons : ∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂) | [], _, _ => rfl | [_], _, _ => rfl | b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons, ← cons_append, getLast?_append_cons (c :: l₁)] theorem getLast?_append_of_ne_nil (l₁ : List α) : ∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂ | [], hl₂ => by contradiction | b :: l₂, _ => getLast?_append_cons l₁ b l₂ theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) : x ∈ (l₁ ++ l₂).getLast? := by cases l₂ · contradiction · rw [List.getLast?_append_cons] exact h /-! ### head(!?) and tail -/ @[simp] theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl @[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by cases x <;> simp at h ⊢ theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) : l.head hl = l[0]'(length_pos_iff.2 hl) := (getElem_zero _).symm theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩ theorem surjective_head? : Surjective (@head? α) := Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩ theorem surjective_tail : Surjective (@tail α) | [] => ⟨[], rfl⟩ | a :: l => ⟨a :: a :: l, rfl⟩ theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l | [], h => (Option.not_mem_none _ h).elim | a :: l, h => by simp only [head?, Option.mem_def, Option.some_inj] at h exact h ▸ rfl @[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl @[simp] theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) : head! (s ++ t) = head! s := by induction s · contradiction · rfl theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by cases s · contradiction · exact h theorem head?_append_of_ne_nil : ∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁ | _ :: _, _, _ => rfl theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) : tail (l ++ [a]) = tail l ++ [a] := by induction l · contradiction · rw [tail, cons_append, tail] theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l | [], a, h => by contradiction | b :: l, a, h => by simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h simp [h] theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l | [], h => by contradiction | _ :: _, _ => rfl theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l := cons_head?_tail (head!_mem_head? h) theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self rwa [cons_head!_tail h] at h' theorem get_eq_getElem? (l : List α) (i : Fin l.length) : l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by simp @[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem? theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} : (∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by simp only [mem_iff_getElem] exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩ theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} : (∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by simp [mem_iff_getElem, @forall_swap α] theorem get_tail (l : List α) (i) (h : i < l.tail.length) (h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) : l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by cases l <;> [cases h; rfl] /-! ### sublists -/ attribute [refl] List.Sublist.refl theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ := Sublist.cons₂ _ s lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by constructor · rintro (_ | _) · exact Or.inl ‹_› · exact Or.inr ⟨rfl, ‹_›⟩ · rintro (h | ⟨rfl, h⟩) · exact h.cons _ · rwa [cons_sublist_cons] theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _ @[deprecated (since := "2025-02-07")] alias sublist_nil_iff_eq_nil := sublist_nil @[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by constructor <;> rintro (_ | _) <;> aesop theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := s₁.eq_of_length_le s₂.length_le /-- If the first element of two lists are different, then a sublist relation can be reduced. -/ theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ := match h₁, h₂ with | _, .cons _ h => h /-! ### indexOf -/ section IndexOf variable [DecidableEq α] theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0 | e => by rw [← e]; exact idxOf_cons_self @[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq @[simp] theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l) | h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h] @[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by induction l with | nil => exact iff_of_true rfl not_mem_nil | cons b l ih => simp only [length, mem_cons, idxOf_cons, eq_comm] rw [cond_eq_if] split_ifs with h <;> simp at h · exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm · simp only [Ne.symm h, false_or] rw [← ih] exact succ_inj @[simp] theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l := idxOf_eq_length_iff.2 @[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by induction l with | nil => rfl | cons b l ih => ?_ simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq] by_cases h : b = a · rw [if_pos h]; exact Nat.zero_le _ · rw [if_neg h]; exact succ_le_succ ih @[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l := ⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al, fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩ @[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by induction l₁ with | nil => exfalso exact not_mem_nil h | cons d₁ t₁ ih => rw [List.cons_append] by_cases hh : d₁ = a · iterate 2 rw [idxOf_cons_eq _ hh] rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) : idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by induction l₁ with | nil => rw [List.nil_append, List.length, Nat.zero_add] | cons d₁ t₁ ih => rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length, ih (not_mem_of_not_mem_cons h), Nat.succ_add] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem end IndexOf /-! ### nth element -/ section deprecated @[simp] theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl /-- A version of `getElem_map` that can be used for rewriting. -/ theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} : f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _) theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) : l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) := (getLast_eq_getElem _).symm theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) : (l.drop n).take 1 = [l.get ⟨n, h⟩] := by rw [drop_eq_getElem_cons h, take, take] simp theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) : l₁ = l₂ := by apply ext_getElem? intro n rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn · exact h' n hn · simp_all [Nat.max_le, getElem?_eq_none] @[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?' @[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff theorem ext_get_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by constructor · rintro rfl exact ⟨rfl, fun _ _ _ ↦ rfl⟩ · intro ⟨h₁, h₂⟩ exact ext_get h₁ h₂ theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? := ⟨by rintro rfl _ _; rfl, ext_getElem?'⟩ @[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff' /-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`, then the lists are equal. -/ theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) : l₁ = l₂ := ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n @[simp] theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length), l[idxOf a l] = a | b :: l, h => by by_cases h' : b = a <;> simp [h', if_pos, if_false, getElem_idxOf] @[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf -- This is incorrectly named and should be `get_idxOf`; -- this already exists, so will require a deprecation dance. theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by simp @[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get @[simp] theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l[idxOf a l]? = some a := by rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)] @[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf @[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf @[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : idxOf x l = idxOf y l ↔ x = y := ⟨fun h => by have x_eq_y : get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ = get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by simp only [h] simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩ @[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj theorem get_reverse' (l : List α) (n) (hn') : l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by simp theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by refine ext_get (by convert h) fun n h₁ h₂ => ?_ simp congr omega end deprecated @[simp] theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.set i a).length) : (l.set i a)[j] = l[j]'(by simpa using hj) := by rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h, List.getElem?_eq_getElem] /-! ### map -/ -- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged -- `simp` in Core -- TODO: Upstream the tagging to Core? attribute [simp] map_const' theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l := .symm <| map_eq_flatMap .. theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) : l.flatMap f = l.flatMap g := (congr_arg List.flatten <| map_congr_left h :) theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) : f a <:+: as.flatMap f := infix_of_mem_flatten (mem_map_of_mem h) @[simp] theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l := rfl /-- A single `List.map` of a composition of functions is equal to composing a `List.map` with another `List.map`, fully applied. This is the reverse direction of `List.map_map`. -/ theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) := map_map.symm /-- Composing a `List.map` with another `List.map` is equal to a single `List.map` of composed functions. -/ @[simp] theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by ext l; rw [comp_map, Function.comp_apply] section map_bijectivity theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) : LeftInverse (map f) (map g) | [] => by simp_rw [map_nil] | x :: xs => by simp_rw [map_cons, h x, h.list_map xs] nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α} (h : RightInverse f g) : RightInverse (map f) (map g) := h.list_map nonrec theorem _root_.Function.Involutive.list_map {f : α → α} (h : Involutive f) : Involutive (map f) := Function.LeftInverse.list_map h @[simp] theorem map_leftInverse_iff {f : α → β} {g : β → α} : LeftInverse (map f) (map g) ↔ LeftInverse f g := ⟨fun h x => by injection h [x], (·.list_map)⟩ @[simp] theorem map_rightInverse_iff {f : α → β} {g : β → α} : RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff @[simp] theorem map_involutive_iff {f : α → α} : Involutive (map f) ↔ Involutive f := map_leftInverse_iff theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) : Injective (map f) | [], [], _ => rfl | x :: xs, y :: ys, hxy => by injection hxy with hxy hxys rw [h hxy, h.list_map hxys] @[simp] theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by refine ⟨fun h x y hxy => ?_, (·.list_map)⟩ suffices [x] = [y] by simpa using this apply h simp [hxy] theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) : Surjective (map f) := let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective @[simp] theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by refine ⟨fun h x => ?_, (·.list_map)⟩ let ⟨[y], hxy⟩ := h [x] exact ⟨_, List.singleton_injective hxy⟩ theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) := ⟨h.1.list_map, h.2.list_map⟩ @[simp] theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff] end map_bijectivity theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) : b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h /-- `eq_nil_or_concat` in simp normal form -/ lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by simpa using l.eq_nil_or_concat /-! ### foldl, foldr -/ theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) : foldl f a l = foldl g a l := by induction l generalizing a with | nil => rfl | cons hd tl ih => unfold foldl rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self] theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) : foldr f b l = foldr g b l := by induction l with | nil => rfl | cons hd tl ih => ?_ simp only [mem_cons, or_imp, forall_and, forall_eq] at H simp only [foldr, ih H.2, H.1] theorem foldl_concat (f : β → α → β) (b : β) (x : α) (xs : List α) : List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by simp only [List.foldl_append, List.foldl] theorem foldr_concat (f : α → β → β) (b : β) (x : α) (xs : List α) : List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by simp only [List.foldr_append, List.foldr] theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a | [] => rfl | b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l] theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b | [] => rfl | a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a] @[simp] theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a := foldl_fixed' fun _ => rfl @[simp] theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b := foldr_fixed' fun _ => rfl @[deprecated foldr_cons_nil (since := "2025-02-10")] theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by simp theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β) (op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) : foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) := Eq.symm <| by revert a b induction l <;> intros <;> [rfl; simp only [*, foldl]] theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β) (op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) : foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by revert a induction l <;> intros <;> [rfl; simp only [*, foldr]] theorem injective_foldl_comp {l : List (α → α)} {f : α → α} (hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) : Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by induction l generalizing f with | nil => exact hf | cons lh lt l_ih => apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h) apply Function.Injective.comp hf apply hl _ mem_cons_self /-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them: `l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`. Assume the designated element `a₂` is present in neither `x₁` nor `z₁`. We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal (`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/ lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α} (notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) : x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by constructor · simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons] rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ | ⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all · rintro ⟨rfl, rfl, rfl⟩ rfl section FoldlEqFoldr -- foldl and foldr coincide when f is commutative and associative variable {f : α → α → α} theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l) | _, _, nil => rfl | a, b, c :: l => by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l] rw [hassoc.assoc] theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l) | a, b, nil => hcomm.comm a b | a, b, c :: l => by simp only [foldl_cons] have : RightCommutative f := inferInstance rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons] theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] : ∀ a l, foldl f a l = foldr f a l | _, nil => rfl | a, b :: l => by simp only [foldr_cons, foldl_eq_of_comm_of_assoc] rw [foldl_eq_foldr a l] end FoldlEqFoldr section FoldlEqFoldlr' variable {f : α → β → α} variable (hf : ∀ a b c, f (f a b) c = f (f a c) b) include hf theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b | _, _, [] => rfl | a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf] theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | _, [] => rfl | a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl end FoldlEqFoldlr' section FoldlEqFoldlr' variable {f : α → β → β} theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l | _, _, [] => rfl | a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl end FoldlEqFoldlr' section variable {op : α → α → α} [ha : Std.Associative op] /-- Notation for `op a b`. -/ local notation a " ⋆ " b => op a b /-- Notation for `foldl op a l`. -/ local notation l " <*> " a => foldl op a l theorem foldl_op_eq_op_foldr_assoc : ∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂ | [], _, _ => rfl | a :: l, a₁, a₂ => by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] variable [hc : Std.Commutative op] theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by rw [foldl_cons, hc.comm, foldl_assoc] end /-! ### foldlM, foldrM, mapM -/ section FoldlMFoldrM variable {m : Type v → Type w} [Monad m] variable [LawfulMonad m] theorem foldrM_eq_foldr (f : α → β → m β) (b l) : foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*] theorem foldlM_eq_foldl (f : β → α → m β) (b l) : List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by suffices h : ∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l by simp [← h (pure b)] induction l with | nil => intro; simp | cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm] end FoldlMFoldrM /-! ### intersperse -/ @[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single @[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂ /-! ### map for partial functions -/ @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) : SizeOf.sizeOf x < SizeOf.sizeOf l := by induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec] · omega · specialize ih ‹_› omega /-! ### filter -/ theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) : l.length = (l.filter f).length + (l.filter (! f ·)).length := by simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true, Bool.decide_eq_false] /-! ### filterMap -/ theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) : l.filterMap f = l.flatMap fun a ↦ (f a).toList := by induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons] rcases f a <;> simp [ih] theorem filterMap_congr {f g : α → Option β} {l : List α} (h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by induction l <;> simp_all [filterMap_cons] theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} : l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where mp := by induction l with | nil => simp | cons a l ih => ?_ rcases ha : f a with - | b <;> simp [ha, filterMap_cons] · intro h simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff] using List.length_filterMap_le f l · rintro rfl h exact ⟨rfl, ih h⟩ mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _) /-! ### filter -/ section Filter variable {p : α → Bool} theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] := rfl theorem filter_eq_foldr (p : α → Bool) (l : List α) : filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by induction l <;> simp [*, filter]; rfl #adaptation_note /-- nightly-2024-07-27 This has to be temporarily renamed to avoid an unintentional collision. The prime should be removed at nightly-2024-07-27. -/ @[simp] theorem filter_subset' (l : List α) : filter p l ⊆ l := filter_sublist.subset theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2 theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset' l h theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l := mem_filter.2 ⟨h₁, h₂⟩ @[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset variable (p) theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄ (h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by induction l with | nil => rfl | cons hd tl IH => by_cases hp : p hd · rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)] exact IH.cons_cons hd · rw [filter_cons_of_neg hp] by_cases hq : q hd · rw [filter_cons_of_pos hq] exact sublist_cons_of_sublist hd IH · rw [filter_cons_of_neg hq] exact IH lemma map_filter {f : α → β} (hf : Injective f) (l : List α) [DecidablePred fun b => ∃ a, p a ∧ f a = b] : (l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [comp_def, filter_map, hf.eq_iff] @[deprecated (since := "2025-02-07")] alias map_filter' := map_filter lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] : l.attach.filter p = (l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by classical refine map_injective_iff.2 Subtype.coe_injective ?_ simp [comp_def, map_filter _ Subtype.coe_injective] lemma filter_attach (l : List α) (p : α → Bool) : (l.attach.filter fun x => p x : List {x // x ∈ l}) = (l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := map_injective_iff.2 Subtype.coe_injective <| by simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val), ← filter_map, attach_map_subtype_val] lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by simp [Bool.and_comm] @[simp] theorem filter_true (l : List α) : filter (fun _ => true) l = l := by induction l <;> simp [*, filter] @[simp] theorem filter_false (l : List α) : filter (fun _ => false) l = [] := by induction l <;> simp [*, filter] end Filter /-! ### eraseP -/ section eraseP variable {p : α → Bool} @[simp] theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) : (l.eraseP p).length + 1 = l.length := by let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa rw [h₂, h₁, length_append, length_append] rfl end eraseP /-! ### erase -/ section Erase variable [DecidableEq α] @[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) : (l.erase a).length + 1 = l.length := by rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)] theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) : map f (l.erase a) = (map f l).erase (f a) := by have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff] rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]] theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) : Perm (l.erase l[i]) (l.eraseIdx i) := by induction l generalizing i with | nil => simp | cons a l IH => cases i with | zero => simp | succ i => have hi' : i < l.length := by simpa using hi if ha : a = l[i] then simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi')) else simpa [ha] using IH hi' theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) : (l.eraseIdx i).length + 1 = l.length := by rw [length_eraseIdx] split <;> omega end Erase /-! ### diff -/ section Diff variable [DecidableEq α] @[simp] theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj] @[deprecated (since := "2025-04-10")] alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist end Diff section Choose variable (p : α → Prop) [DecidablePred p] (l : List α) theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose /-! ### Forall -/ section Forall variable {p q : α → Prop} {l : List α} @[simp] theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l | [] => (and_iff_left_of_imp fun _ ↦ trivial).symm | _ :: _ => Iff.rfl @[simp] theorem forall_append {p : α → Prop} : ∀ {xs ys : List α}, Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys | [] => by simp | _ :: _ => by simp [forall_append, and_assoc] theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x | [] => (iff_true_intro <| forall_mem_nil _).symm | x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem] theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l | [] => id | x :: l => by simp only [forall_cons, and_imp] rw [← and_imp] exact And.imp (h x) (Forall.imp h) @[simp] theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by induction l <;> simp [*] instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ => decidable_of_iff' _ forall_iff_forall_mem end Forall /-! ### Miscellaneous lemmas -/ theorem get_attach (l : List α) (i) : (l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp section Disjoint /-- The images of disjoint lists under a partially defined map are disjoint -/ theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α} (hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a) (hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a') (h : Disjoint s t) : Disjoint (s.pmap f hs) (t.pmap f ht) := by simp only [Disjoint, mem_pmap] rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩ apply h ha rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm] /-- The images of disjoint lists under an injective map are disjoint -/ theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f) (h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)] exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h alias Disjoint.map := disjoint_map theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) : Disjoint s t := fun _a has hat ↦ h (mem_map_of_mem has) (mem_map_of_mem hat) theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := ⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩ theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l₁ l ↔ Disjoint l₂ l := by simp_rw [List.disjoint_left, p.mem_iff] theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l l₁ ↔ Disjoint l l₂ := by simp_rw [List.disjoint_right, p.mem_iff] @[simp] theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_left @[simp] theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_right end Disjoint section lookup variable [BEq α] [LawfulBEq α] lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) : lookup a (as.map fun x => (x, f x)) = some (f a) := by induction as with | nil => exact (not_mem_nil h).elim | cons a' as ih => by_cases ha : a = a' · simp [ha, lookup_cons] · simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h) end lookup section range' @[simp] lemma range'_0 (a b : ℕ) : range' a b 0 = replicate b a := by induction b with | zero => simp | succ b ih => simp [range'_succ, ih, replicate_succ] lemma left_le_of_mem_range' {a b s x : ℕ} (hx : x ∈ List.range' a b s) : a ≤ x := by obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx exact le_add_right a (s * i) end range' end List
Mathlib/Data/List/Basic.lean
2,969
2,973
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Shift.Induced import Mathlib.CategoryTheory.Localization.HasLocalization import Mathlib.CategoryTheory.Localization.LocalizerMorphism /-! # The shift induced on a localized category Let `C` be a category equipped with a shift by a monoid `A`. A morphism property `W` on `C` satisfies `W.IsCompatibleWithShift A` when for all `a : A`, a morphism `f` is in `W` iff `f⟦a⟧'` is. When this compatibility is satisfied, then the corresponding localized category can be equipped with a shift by `A`, and the localization functor is compatible with the shift. -/ universe v₁ v₂ v₃ u₁ u₂ u₃ w namespace CategoryTheory variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] {E : Type u₃} [Category.{v₃} E] (L : C ⥤ D) (W : MorphismProperty C) [L.IsLocalization W] (A : Type w) [AddMonoid A] [HasShift C A] namespace MorphismProperty /-- A morphism property `W` on a category `C` is compatible with the shift by a monoid `A` when for all `a : A`, a morphism `f` belongs to `W` if and only if `f⟦a⟧'` does. -/ class IsCompatibleWithShift : Prop where /-- the condition that for all `a : A`, the morphism property `W` is not changed when we take its inverse image by the shift functor by `a` -/ condition : ∀ (a : A), W.inverseImage (shiftFunctor C a) = W variable [W.IsCompatibleWithShift A] namespace IsCompatibleWithShift
variable {A} lemma iff {X Y : C} (f : X ⟶ Y) (a : A) : W (f⟦a⟧') ↔ W f := by
Mathlib/CategoryTheory/Shift/Localization.lean
44
46
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot, Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/IntervalIntegral.lean
1,064
1,070
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.FixedPoint /-! # Principal ordinals We define principal or indecomposable ordinals, and we prove the standard properties about them. ## Main definitions and results * `Principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and any other typically excluded edge cases for simplicity. * `not_bddAbove_principal`: Principal ordinals (under any operation) are unbounded. * `principal_add_iff_zero_or_omega0_opow`: The main characterization theorem for additive principal ordinals. * `principal_mul_iff_le_two_or_omega0_opow_opow`: The main characterization theorem for multiplicative principal ordinals. ## TODO * Prove that exponential principal ordinals are 0, 1, 2, ω, or epsilon numbers, i.e. fixed points of `fun x ↦ ω ^ x`. -/ universe u open Order namespace Ordinal variable {a b c o : Ordinal.{u}} section Arbitrary variable {op : Ordinal → Ordinal → Ordinal} /-! ### Principal ordinals -/ /-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of ordinals less than it is closed under that operation. In standard mathematical usage, this term is almost exclusively used for additive and multiplicative principal ordinals. For simplicity, we break usual convention and regard `0` as principal. -/ def Principal (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Prop := ∀ ⦃a b⦄, a < o → b < o → op a b < o theorem principal_swap_iff : Principal (Function.swap op) o ↔ Principal op o := by constructor <;> exact fun h a b ha hb => h hb ha theorem not_principal_iff : ¬ Principal op o ↔ ∃ a < o, ∃ b < o, o ≤ op a b := by simp [Principal] theorem principal_iff_of_monotone (h₁ : ∀ a, Monotone (op a)) (h₂ : ∀ a, Monotone (Function.swap op a)) : Principal op o ↔ ∀ a < o, op a a < o := by use fun h a ha => h ha ha intro H a b ha hb obtain hab | hba := le_or_lt a b · exact (h₂ b hab).trans_lt <| H b hb · exact (h₁ a hba.le).trans_lt <| H a ha theorem not_principal_iff_of_monotone (h₁ : ∀ a, Monotone (op a)) (h₂ : ∀ a, Monotone (Function.swap op a)) : ¬ Principal op o ↔ ∃ a < o, o ≤ op a a := by simp [principal_iff_of_monotone h₁ h₂] theorem principal_zero : Principal op 0 := fun a _ h => (Ordinal.not_lt_zero a h).elim @[simp] theorem principal_one_iff : Principal op 1 ↔ op 0 0 = 0 := by refine ⟨fun h => ?_, fun h a b ha hb => ?_⟩ · rw [← lt_one_iff_zero] exact h zero_lt_one zero_lt_one · rwa [lt_one_iff_zero, ha, hb] at * theorem Principal.iterate_lt (hao : a < o) (ho : Principal op o) (n : ℕ) : (op a)^[n] a < o := by induction' n with n hn · rwa [Function.iterate_zero] · rw [Function.iterate_succ'] exact ho hao hn theorem op_eq_self_of_principal (hao : a < o) (H : IsNormal (op a)) (ho : Principal op o) (ho' : IsLimit o) : op a o = o := by apply H.le_apply.antisymm' rw [← IsNormal.bsup_eq.{u, u} H ho', bsup_le_iff] exact fun b hbo => (ho hao hbo).le theorem nfp_le_of_principal (hao : a < o) (ho : Principal op o) : nfp (op a) a ≤ o := nfp_le fun n => (ho.iterate_lt hao n).le end Arbitrary /-! ### Principal ordinals are unbounded -/ /-- We give an explicit construction for a principal ordinal larger or equal than `o`. -/ private theorem principal_nfp_iSup (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Principal op (nfp (fun x ↦ ⨆ y : Set.Iio x ×ˢ Set.Iio x, succ (op y.1.1 y.1.2)) o) := by intro a b ha hb rw [lt_nfp_iff] at * obtain ⟨m, ha⟩ := ha obtain ⟨n, hb⟩ := hb obtain h | h := le_total ((fun x ↦ ⨆ y : Set.Iio x ×ˢ Set.Iio x, succ (op y.1.1 y.1.2))^[m] o) ((fun x ↦ ⨆ y : Set.Iio x ×ˢ Set.Iio x, succ (op y.1.1 y.1.2))^[n] o) · use n + 1 rw [Function.iterate_succ'] apply (lt_succ _).trans_le exact Ordinal.le_iSup (fun y : Set.Iio _ ×ˢ Set.Iio _ ↦ succ (op y.1.1 y.1.2)) ⟨_, Set.mk_mem_prod (ha.trans_le h) hb⟩ · use m + 1 rw [Function.iterate_succ'] apply (lt_succ _).trans_le exact Ordinal.le_iSup (fun y : Set.Iio _ ×ˢ Set.Iio _ ↦ succ (op y.1.1 y.1.2)) ⟨_, Set.mk_mem_prod ha (hb.trans_le h)⟩ /-- Principal ordinals under any operation are unbounded. -/ theorem not_bddAbove_principal (op : Ordinal → Ordinal → Ordinal) : ¬ BddAbove { o | Principal op o } := by rintro ⟨a, ha⟩ exact ((le_nfp _ _).trans (ha (principal_nfp_iSup op (succ a)))).not_lt (lt_succ a) /-! #### Additive principal ordinals -/ theorem principal_add_one : Principal (· + ·) 1 := principal_one_iff.2 <| zero_add 0
theorem principal_add_of_le_one (ho : o ≤ 1) : Principal (· + ·) o := by rcases le_one_iff.1 ho with (rfl | rfl) · exact principal_zero · exact principal_add_one theorem isLimit_of_principal_add (ho₁ : 1 < o) (ho : Principal (· + ·) o) : o.IsLimit := by rw [isLimit_iff, isSuccPrelimit_iff_succ_lt] exact ⟨ho₁.ne_bot, fun _ ha ↦ ho ha ho₁⟩
Mathlib/SetTheory/Ordinal/Principal.lean
131
140
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Oleksandr Manzyuk -/ import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Monoidal.Mon_ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers /-! # The category of bimodule objects over a pair of monoid objects. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory open CategoryTheory.MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] section open CategoryTheory.Limits variable [HasCoequalizers C] section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] theorem id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W) (wh : (Z ◁ f) ≫ h = (Z ◁ g) ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorLeft Z) f g h wh theorem id_tensor_π_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (Z ◁ f) ≫ q = p ≫ f') (wg : (Z ◁ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ colimMap (parallelPairHom (Z ◁ f) (Z ◁ g) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorLeft Z) f g f' g' p q wf wg h wh end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W) (wh : (f ▷ Z) ≫ h = (g ▷ Z) ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorRight Z) f g h wh theorem π_tensor_id_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ▷ Z) ≫ q = p ≫ f') (wg : (g ▷ Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ colimMap (parallelPairHom (f ▷ Z) (g ▷ Z) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorRight Z) f g f' g' p q wf wg h wh end end /-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/ structure Bimod (A B : Mon_ C) where /-- The underlying monoidal category -/ X : C /-- The left action of this bimodule object -/ actLeft : A.X ⊗ X ⟶ X one_actLeft : (A.one ▷ X) ≫ actLeft = (λ_ X).hom := by aesop_cat left_assoc : (A.mul ▷ X) ≫ actLeft = (α_ A.X A.X X).hom ≫ (A.X ◁ actLeft) ≫ actLeft := by aesop_cat /-- The right action of this bimodule object -/ actRight : X ⊗ B.X ⟶ X actRight_one : (X ◁ B.one) ≫ actRight = (ρ_ X).hom := by aesop_cat right_assoc : (X ◁ B.mul) ≫ actRight = (α_ X B.X B.X).inv ≫ (actRight ▷ B.X) ≫ actRight := by aesop_cat middle_assoc : (actLeft ▷ B.X) ≫ actRight = (α_ A.X X B.X).hom ≫ (A.X ◁ actRight) ≫ actLeft := by aesop_cat attribute [reassoc (attr := simp)] Bimod.one_actLeft Bimod.actRight_one Bimod.left_assoc Bimod.right_assoc Bimod.middle_assoc namespace Bimod variable {A B : Mon_ C} (M : Bimod A B) /-- A morphism of bimodule objects. -/ @[ext] structure Hom (M N : Bimod A B) where /-- The morphism between `M`'s monoidal category and `N`'s monoidal category -/ hom : M.X ⟶ N.X left_act_hom : M.actLeft ≫ hom = (A.X ◁ hom) ≫ N.actLeft := by aesop_cat right_act_hom : M.actRight ≫ hom = (hom ▷ B.X) ≫ N.actRight := by aesop_cat attribute [reassoc (attr := simp)] Hom.left_act_hom Hom.right_act_hom /-- The identity morphism on a bimodule object. -/ @[simps] def id' (M : Bimod A B) : Hom M M where hom := 𝟙 M.X instance homInhabited (M : Bimod A B) : Inhabited (Hom M M) := ⟨id' M⟩ /-- Composition of bimodule object morphisms. -/ @[simps] def comp {M N O : Bimod A B} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom instance : Category (Bimod A B) where Hom M N := Hom M N id := id' comp f g := comp f g @[ext] lemma hom_ext {M N : Bimod A B} (f g : M ⟶ N) (h : f.hom = g.hom) : f = g := Hom.ext h @[simp] theorem id_hom' (M : Bimod A B) : (𝟙 M : Hom M M).hom = 𝟙 M.X := rfl @[simp] theorem comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl /-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects and checking compatibility with left and right actions only in the forward direction. -/ @[simps] def isoOfIso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X) (f_left_act_hom : P.actLeft ≫ f.hom = (X.X ◁ f.hom) ≫ Q.actLeft) (f_right_act_hom : P.actRight ≫ f.hom = (f.hom ▷ Y.X) ≫ Q.actRight) : P ≅ Q where hom := { hom := f.hom } inv := { hom := f.inv left_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_left_act_hom, ← Category.assoc, ← MonoidalCategory.whiskerLeft_comp, Iso.inv_hom_id, MonoidalCategory.whiskerLeft_id, Category.id_comp] right_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_right_act_hom, ← Category.assoc, ← comp_whiskerRight, Iso.inv_hom_id, MonoidalCategory.id_whiskerRight, Category.id_comp] } hom_inv_id := by ext; dsimp; rw [Iso.hom_inv_id] inv_hom_id := by ext; dsimp; rw [Iso.inv_hom_id] variable (A) /-- A monoid object as a bimodule over itself. -/ @[simps] def regular : Bimod A A where X := A.X actLeft := A.mul actRight := A.mul instance : Inhabited (Bimod A A) := ⟨regular A⟩ /-- The forgetful functor from bimodule objects to the ambient category. -/ def forget : Bimod A B ⥤ C where obj A := A.X map f := f.hom open CategoryTheory.Limits variable [HasCoequalizers C] namespace TensorBimod variable {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T) /-- The underlying object of the tensor product of two bimodules. -/ noncomputable def X : C := coequalizer (P.actRight ▷ Q.X) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actLeft)) section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] /-- Left action for the tensor product of two bimodules. -/ noncomputable def actLeft : R.X ⊗ X P Q ⟶ X P Q := (PreservesCoequalizer.iso (tensorLeft R.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).inv ≫ ((α_ _ _ _).inv ▷ _) ≫ (P.actLeft ▷ S.X ▷ Q.X)) ((α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X)) (by dsimp simp only [Category.assoc] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_rhs 3 4 => rw [← comp_whiskerRight, middle_assoc, comp_whiskerRight] monoidal) (by dsimp slice_lhs 1 1 => rw [MonoidalCategory.whiskerLeft_comp] slice_lhs 2 3 => rw [associator_inv_naturality_right] slice_lhs 3 4 => rw [whisker_exchange] monoidal)) theorem whiskerLeft_π_actLeft : (R.X ◁ coequalizer.π _ _) ≫ actLeft P Q = (α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorLeft _)] simp only [Category.assoc] theorem one_act_left' : (R.one ▷ _) ≫ actLeft P Q = (λ_ _).hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 => erw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, one_actLeft] slice_rhs 1 2 => rw [leftUnitor_naturality] monoidal theorem left_assoc' : (R.mul ▷ _) ≫ actLeft P Q = (α_ R.X R.X _).hom ≫ (R.X ◁ actLeft P Q) ≫ actLeft P Q := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] slice_lhs 1 2 => rw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, left_assoc, comp_whiskerRight, comp_whiskerRight] slice_rhs 1 2 => rw [associator_naturality_right] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 5 => rw [whiskerLeft_π_actLeft] slice_rhs 3 4 => rw [associator_inv_naturality_middle] monoidal end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- Right action for the tensor product of two bimodules. -/ noncomputable def actRight : X P Q ⊗ T.X ⟶ X P Q := (PreservesCoequalizer.iso (tensorRight T.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).hom ≫ (α_ _ _ _).hom ≫ (P.X ◁ S.X ◁ Q.actRight) ≫ (α_ _ _ _).inv) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actRight)) (by dsimp slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] simp) (by dsimp simp only [comp_whiskerRight, whisker_assoc, Category.assoc, Iso.inv_hom_id_assoc] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, middle_assoc, MonoidalCategory.whiskerLeft_comp] simp)) theorem π_tensor_id_actRight : (coequalizer.π _ _ ▷ T.X) ≫ actRight P Q = (α_ _ _ _).hom ≫ (P.X ◁ Q.actRight) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorRight _)] simp only [Category.assoc] theorem actRight_one' : (_ ◁ T.one) ≫ actRight P Q = (ρ_ _).hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 =>erw [← whisker_exchange] slice_lhs 2 3 => rw [π_tensor_id_actRight] slice_lhs 1 2 => rw [associator_naturality_right] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, actRight_one] simp theorem right_assoc' : (_ ◁ T.mul) ≫ actRight P Q = (α_ _ T.X T.X).inv ≫ (actRight P Q ▷ T.X) ≫ actRight P Q := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace some `rw` by `erw` slice_lhs 1 2 => rw [← whisker_exchange] slice_lhs 2 3 => rw [π_tensor_id_actRight] slice_lhs 1 2 => rw [associator_naturality_right] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, right_assoc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_inv_naturality_left] slice_rhs 2 3 => rw [← comp_whiskerRight, π_tensor_id_actRight, comp_whiskerRight, comp_whiskerRight] slice_rhs 4 5 => rw [π_tensor_id_actRight] simp end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem middle_assoc' : (actLeft P Q ▷ T.X) ≫ actRight P Q = (α_ R.X _ T.X).hom ≫ (R.X ◁ actRight P Q) ≫ actLeft P Q := by refine (cancel_epi ((tensorLeft _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] slice_lhs 1 2 => rw [← comp_whiskerRight, whiskerLeft_π_actLeft, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 4 => rw [π_tensor_id_actRight] slice_lhs 2 3 => rw [associator_naturality_left] -- Porting note: had to replace `rw` by `erw` slice_rhs 1 2 => rw [associator_naturality_middle] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, π_tensor_id_actRight, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 5 => rw [whiskerLeft_π_actLeft] slice_rhs 3 4 => rw [associator_inv_naturality_right] slice_rhs 4 5 => rw [whisker_exchange] simp end end TensorBimod section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- Tensor product of two bimodule objects as a bimodule object. -/ @[simps] noncomputable def tensorBimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : Bimod X Z where X := TensorBimod.X M N actLeft := TensorBimod.actLeft M N actRight := TensorBimod.actRight M N one_actLeft := TensorBimod.one_act_left' M N actRight_one := TensorBimod.actRight_one' M N left_assoc := TensorBimod.left_assoc' M N right_assoc := TensorBimod.right_assoc' M N middle_assoc := TensorBimod.middle_assoc' M N /-- Left whiskering for morphisms of bimodule objects. -/ @[simps] noncomputable def whiskerLeft {X Y Z : Mon_ C} (M : Bimod X Y) {N₁ N₂ : Bimod Y Z} (f : N₁ ⟶ N₂) : M.tensorBimod N₁ ⟶ M.tensorBimod N₂ where hom := colimMap (parallelPairHom _ _ _ _ (_ ◁ f.hom) (_ ◁ f.hom) (by rw [whisker_exchange]) (by simp only [Category.assoc, tensor_whiskerLeft, Iso.inv_hom_id_assoc, Iso.cancel_iso_hom_left] slice_lhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.left_act_hom] simp)) left_act_hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one, MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_rhs 1 2 => rw [associator_inv_naturality_right] slice_rhs 2 3 => rw [whisker_exchange] simp right_act_hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.right_act_hom] slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight] slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight] simp /-- Right whiskering for morphisms of bimodule objects. -/ @[simps] noncomputable def whiskerRight {X Y Z : Mon_ C} {M₁ M₂ : Bimod X Y} (f : M₁ ⟶ M₂) (N : Bimod Y Z) : M₁.tensorBimod N ⟶ M₂.tensorBimod N where hom := colimMap (parallelPairHom _ _ _ _ (f.hom ▷ _ ▷ _) (f.hom ▷ _) (by rw [← comp_whiskerRight, Hom.right_act_hom, comp_whiskerRight]) (by slice_lhs 2 3 => rw [whisker_exchange] simp)) left_act_hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [← comp_whiskerRight, Hom.left_act_hom] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one, MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_rhs 1 2 => rw [associator_inv_naturality_middle] simp right_act_hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [whisker_exchange] slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight] slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight] simp end namespace AssociatorBimod variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] variable {R S T U : Mon_ C} (P : Bimod R S) (Q : Bimod S T) (L : Bimod T U) /-- An auxiliary morphism for the definition of the underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def homAux : (P.tensorBimod Q).X ⊗ L.X ⟶ (P.tensorBimod (Q.tensorBimod L)).X := (PreservesCoequalizer.iso (tensorRight L.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).hom ≫ (P.X ◁ coequalizer.π _ _) ≫ coequalizer.π _ _) (by dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 4 => rw [coequalizer.condition] slice_lhs 2 3 => rw [associator_naturality_right] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp] simp) /-- The underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def hom : ((P.tensorBimod Q).tensorBimod L).X ⟶ (P.tensorBimod (Q.tensorBimod L)).X := coequalizer.desc (homAux P Q L) (by dsimp [homAux] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [TensorBimod.X] slice_lhs 1 2 => rw [← comp_whiskerRight, TensorBimod.π_tensor_id_actRight, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 2 3 => rw [associator_naturality_middle] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.condition, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_naturality_left] slice_rhs 2 3 => rw [← whisker_exchange] slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] simp) theorem hom_left_act_hom' : ((P.tensorBimod Q).tensorBimod L).actLeft ≫ hom P Q L = (R.X ◁ hom P Q L) ≫ (P.tensorBimod (Q.tensorBimod L)).actLeft := by dsimp; dsimp [hom, homAux] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc, MonoidalCategory.whiskerLeft_comp] refine (cancel_epi ((tensorRight _ ⋙ tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_lhs 2 3 => rw [← comp_whiskerRight, TensorBimod.whiskerLeft_π_actLeft, comp_whiskerRight, comp_whiskerRight] slice_lhs 4 6 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [associator_naturality_left] slice_rhs 1 3 => rw [← MonoidalCategory.whiskerLeft_comp, ← MonoidalCategory.whiskerLeft_comp, π_tensor_id_preserves_coequalizer_inv_desc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 3 4 => erw [TensorBimod.whiskerLeft_π_actLeft P (Q.tensorBimod L)] slice_rhs 2 3 => erw [associator_inv_naturality_right] slice_rhs 3 4 => erw [whisker_exchange] monoidal theorem hom_right_act_hom' : ((P.tensorBimod Q).tensorBimod L).actRight ≫ hom P Q L = (hom P Q L ▷ U.X) ≫ (P.tensorBimod (Q.tensorBimod L)).actRight := by dsimp; dsimp [hom, homAux] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc, comp_whiskerRight] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 2 3 => rw [associator_naturality_right] slice_rhs 1 3 => rw [← comp_whiskerRight, ← comp_whiskerRight, π_tensor_id_preserves_coequalizer_inv_desc, comp_whiskerRight, comp_whiskerRight] slice_rhs 3 4 => erw [TensorBimod.π_tensor_id_actRight P (Q.tensorBimod L)] slice_rhs 2 3 => erw [associator_naturality_middle] dsimp slice_rhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.π_tensor_id_actRight, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] monoidal /-- An auxiliary morphism for the definition of the underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def invAux : P.X ⊗ (Q.tensorBimod L).X ⟶ ((P.tensorBimod Q).tensorBimod L).X := (PreservesCoequalizer.iso (tensorLeft P.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).inv ≫ (coequalizer.π _ _ ▷ L.X) ≫ coequalizer.π _ _) (by dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_inv_naturality_middle] rw [← Iso.inv_hom_id_assoc (α_ _ _ _) (P.X ◁ Q.actRight), comp_whiskerRight] slice_lhs 3 4 => rw [← comp_whiskerRight, Category.assoc, ← TensorBimod.π_tensor_id_actRight, comp_whiskerRight] slice_lhs 4 5 => rw [coequalizer.condition] slice_lhs 3 4 => rw [associator_naturality_left] slice_rhs 1 2 => rw [MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [associator_inv_naturality_right] slice_rhs 3 4 => rw [whisker_exchange] monoidal) /-- The underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def inv : (P.tensorBimod (Q.tensorBimod L)).X ⟶ ((P.tensorBimod Q).tensorBimod L).X := coequalizer.desc (invAux P Q L) (by dsimp [invAux] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [TensorBimod.X] slice_lhs 1 2 => rw [whisker_exchange] slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, coequalizer.condition, comp_whiskerRight, comp_whiskerRight] slice_rhs 1 2 => rw [associator_naturality_right] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 6 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [associator_inv_naturality_middle] monoidal) theorem hom_inv_id : hom P Q L ≫ inv P Q L = 𝟙 _ := by dsimp [hom, homAux, inv, invAux] apply coequalizer.hom_ext slice_lhs 1 2 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 1 3 => rw [Iso.hom_inv_id_assoc] dsimp only [TensorBimod.X] slice_rhs 2 3 => rw [Category.comp_id] rfl theorem inv_hom_id : inv P Q L ≫ hom P Q L = 𝟙 _ := by dsimp [hom, homAux, inv, invAux] apply coequalizer.hom_ext slice_lhs 1 2 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_lhs 1 3 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_lhs 2 4 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 1 3 => rw [Iso.inv_hom_id_assoc] dsimp only [TensorBimod.X] slice_rhs 2 3 => rw [Category.comp_id] rfl end AssociatorBimod namespace LeftUnitorBimod variable {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the left unitor isomorphism. -/ noncomputable def hom : TensorBimod.X (regular R) P ⟶ P.X := coequalizer.desc P.actLeft (by dsimp; rw [Category.assoc, left_assoc]) /-- The underlying morphism of the inverse component of the left unitor isomorphism. -/ noncomputable def inv : P.X ⟶ TensorBimod.X (regular R) P := (λ_ P.X).inv ≫ (R.one ▷ _) ≫ coequalizer.π _ _ theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by dsimp only [hom, inv, TensorBimod.X] ext; dsimp slice_lhs 1 2 => rw [coequalizer.π_desc] slice_lhs 1 2 => rw [leftUnitor_inv_naturality] slice_lhs 2 3 => rw [whisker_exchange] slice_lhs 3 3 => rw [← Iso.inv_hom_id_assoc (α_ R.X R.X P.X) (R.X ◁ P.actLeft)] slice_lhs 4 6 => rw [← Category.assoc, ← coequalizer.condition] slice_lhs 2 3 => rw [associator_inv_naturality_left] slice_lhs 3 4 => rw [← comp_whiskerRight, Mon_.one_mul] slice_rhs 1 2 => rw [Category.comp_id] monoidal theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by dsimp [hom, inv] slice_lhs 3 4 => rw [coequalizer.π_desc] rw [one_actLeft, Iso.inv_hom_id] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem hom_left_act_hom' : ((regular R).tensorBimod P).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by dsimp; dsimp [hom, TensorBimod.actLeft, regular] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [left_assoc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] rw [Iso.inv_hom_id_assoc] theorem hom_right_act_hom' : ((regular R).tensorBimod P).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by dsimp; dsimp [hom, TensorBimod.actRight, regular] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] slice_rhs 1 2 => rw [middle_assoc] simp only [Category.assoc] end LeftUnitorBimod namespace RightUnitorBimod variable {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the right unitor isomorphism. -/ noncomputable def hom : TensorBimod.X P (regular S) ⟶ P.X := coequalizer.desc P.actRight (by dsimp; rw [Category.assoc, right_assoc, Iso.hom_inv_id_assoc]) /-- The underlying morphism of the inverse component of the right unitor isomorphism. -/ noncomputable def inv : P.X ⟶ TensorBimod.X P (regular S) := (ρ_ P.X).inv ≫ (_ ◁ S.one) ≫ coequalizer.π _ _ theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by dsimp only [hom, inv, TensorBimod.X] ext; dsimp slice_lhs 1 2 => rw [coequalizer.π_desc] slice_lhs 1 2 => rw [rightUnitor_inv_naturality] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 4 => rw [coequalizer.condition] slice_lhs 2 3 => rw [associator_naturality_right] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, Mon_.mul_one] slice_rhs 1 2 => rw [Category.comp_id] monoidal theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by dsimp [hom, inv] slice_lhs 3 4 => rw [coequalizer.π_desc] rw [actRight_one, Iso.inv_hom_id] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem hom_left_act_hom' : (P.tensorBimod (regular S)).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by dsimp; dsimp [hom, TensorBimod.actLeft, regular] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [middle_assoc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] rw [Iso.inv_hom_id_assoc] theorem hom_right_act_hom' : (P.tensorBimod (regular S)).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by dsimp; dsimp [hom, TensorBimod.actRight, regular] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp
slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [right_assoc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] rw [Iso.hom_inv_id_assoc] end RightUnitorBimod variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
Mathlib/CategoryTheory/Monoidal/Bimod.lean
690
698
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Eric Wieser -/ import Mathlib.Analysis.Normed.Algebra.Exponential import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Data.Complex.Exponential import Mathlib.Topology.MetricSpace.CauSeqFilter /-! # Calculus results on exponential in a Banach algebra In this file, we prove basic properties about the derivative of the exponential map `exp 𝕂` in a Banach algebra `𝔸` over a field `𝕂`. We keep them separate from the main file `Analysis.Normed.Algebra.Exponential` in order to minimize dependencies. ## Main results We prove most results for an arbitrary field `𝕂`, and then specialize to `𝕂 = ℝ` or `𝕂 = ℂ`. ### General case - `hasStrictFDerivAt_exp_zero_of_radius_pos` : `NormedSpace.exp 𝕂` has strict Fréchet derivative `1 : 𝔸 →L[𝕂] 𝔸` at zero, as long as it converges on a neighborhood of zero (see also `hasStrictDerivAt_exp_zero_of_radius_pos` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp_of_lt_radius` : if `𝕂` has characteristic zero and `𝔸` is commutative, then given a point `x` in the disk of convergence, `NormedSpace.exp 𝕂` has strict Fréchet derivative `NormedSpace.exp 𝕂 x • 1 : 𝔸 →L[𝕂] 𝔸` at x (see also `hasStrictDerivAt_exp_of_lt_radius` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp_smul_const_of_mem_ball`: even when `𝔸` is non-commutative, if we have an intermediate algebra `𝕊` which is commutative, the function `(u : 𝕊) ↦ NormedSpace.exp 𝕂 (u • x)`, still has strict Fréchet derivative `NormedSpace.exp 𝕂 (t • x) • (1 : 𝕊 →L[𝕂] 𝕊).smulRight x` at `t` if `t • x` is in the radius of convergence. ### `𝕂 = ℝ` or `𝕂 = ℂ` - `hasStrictFDerivAt_exp_zero` : `NormedSpace.exp 𝕂` has strict Fréchet derivative `1 : 𝔸 →L[𝕂] 𝔸` at zero (see also `hasStrictDerivAt_exp_zero` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp` : if `𝔸` is commutative, then given any point `x`, `NormedSpace.exp 𝕂` has strict Fréchet derivative `NormedSpace.exp 𝕂 x • 1 : 𝔸 →L[𝕂] 𝔸` at x (see also `hasStrictDerivAt_exp` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp_smul_const`: even when `𝔸` is non-commutative, if we have an intermediate algebra `𝕊` which is commutative, the function `(u : 𝕊) ↦ NormedSpace.exp 𝕂 (u • x)` still has strict Fréchet derivative `NormedSpace.exp 𝕂 (t • x) • (1 : 𝔸 →L[𝕂] 𝔸).smulRight x` at `t`. ### Compatibility with `Real.exp` and `Complex.exp` - `Complex.exp_eq_exp_ℂ` : `Complex.exp = NormedSpace.exp ℂ ℂ` - `Real.exp_eq_exp_ℝ` : `Real.exp = NormedSpace.exp ℝ ℝ` -/ open Filter RCLike ContinuousMultilinearMap NormedField NormedSpace Asymptotics open scoped Nat Topology ENNReal section AnyFieldAnyAlgebra variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential in a Banach algebra `𝔸` over a normed field `𝕂` has strict Fréchet derivative `1 : 𝔸 →L[𝕂] 𝔸` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasStrictFDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) : HasStrictFDerivAt (exp 𝕂) (1 : 𝔸 →L[𝕂] 𝔸) 0 := by convert (hasFPowerSeriesAt_exp_zero_of_radius_pos h).hasStrictFDerivAt ext x change x = expSeries 𝕂 𝔸 1 fun _ => x simp [expSeries_apply_eq, Nat.factorial] /-- The exponential in a Banach algebra `𝔸` over a normed field `𝕂` has Fréchet derivative `1 : 𝔸 →L[𝕂] 𝔸` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasFDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) : HasFDerivAt (exp 𝕂) (1 : 𝔸 →L[𝕂] 𝔸) 0 := (hasStrictFDerivAt_exp_zero_of_radius_pos h).hasFDerivAt end AnyFieldAnyAlgebra section AnyFieldCommAlgebra variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential map in a commutative Banach algebra `𝔸` over a normed field `𝕂` of characteristic zero has Fréchet derivative `NormedSpace.exp 𝕂 x • 1 : 𝔸 →L[𝕂] 𝔸` at any point `x`in the disk of convergence. -/ theorem hasFDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasFDerivAt (exp 𝕂) (exp 𝕂 x • (1 : 𝔸 →L[𝕂] 𝔸)) x := by have hpos : 0 < (expSeries 𝕂 𝔸).radius := (zero_le _).trans_lt hx rw [hasFDerivAt_iff_isLittleO_nhds_zero] suffices (fun h => exp 𝕂 x * (exp 𝕂 (0 + h) - exp 𝕂 0 - ContinuousLinearMap.id 𝕂 𝔸 h)) =ᶠ[𝓝 0] fun h => exp 𝕂 (x + h) - exp 𝕂 x - exp 𝕂 x • ContinuousLinearMap.id 𝕂 𝔸 h by refine (IsLittleO.const_mul_left ?_ _).congr' this (EventuallyEq.refl _ _) rw [← hasFDerivAt_iff_isLittleO_nhds_zero] exact hasFDerivAt_exp_zero_of_radius_pos hpos have : ∀ᶠ h in 𝓝 (0 : 𝔸), h ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := EMetric.ball_mem_nhds _ hpos filter_upwards [this] with _ hh rw [exp_add_of_mem_ball hx hh, exp_zero, zero_add, ContinuousLinearMap.id_apply, smul_eq_mul] ring /-- The exponential map in a commutative Banach algebra `𝔸` over a normed field `𝕂` of characteristic zero has strict Fréchet derivative `NormedSpace.exp 𝕂 x • 1 : 𝔸 →L[𝕂] 𝔸` at any point `x` in the disk of convergence. -/ theorem hasStrictFDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasStrictFDerivAt (exp 𝕂) (exp 𝕂 x • (1 : 𝔸 →L[𝕂] 𝔸)) x := let ⟨_, hp⟩ := analyticAt_exp_of_mem_ball x hx hp.hasFDerivAt.unique (hasFDerivAt_exp_of_mem_ball hx) ▸ hp.hasStrictFDerivAt end AnyFieldCommAlgebra section deriv variable {𝕂 : Type*} [NontriviallyNormedField 𝕂] [CompleteSpace 𝕂] /-- The exponential map in a complete normed field `𝕂` of characteristic zero has strict derivative `NormedSpace.exp 𝕂 x` at any point `x` in the disk of convergence. -/ theorem hasStrictDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝕂} (hx : x ∈ EMetric.ball (0 : 𝕂) (expSeries 𝕂 𝕂).radius) : HasStrictDerivAt (exp 𝕂) (exp 𝕂 x) x := by simpa using (hasStrictFDerivAt_exp_of_mem_ball hx).hasStrictDerivAt /-- The exponential map in a complete normed field `𝕂` of characteristic zero has derivative `NormedSpace.exp 𝕂 x` at any point `x` in the disk of convergence. -/ theorem hasDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝕂} (hx : x ∈ EMetric.ball (0 : 𝕂) (expSeries 𝕂 𝕂).radius) : HasDerivAt (exp 𝕂) (exp 𝕂 x) x := (hasStrictDerivAt_exp_of_mem_ball hx).hasDerivAt /-- The exponential map in a complete normed field `𝕂` of characteristic zero has strict derivative `1` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasStrictDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝕂).radius) : HasStrictDerivAt (exp 𝕂) (1 : 𝕂) 0 := (hasStrictFDerivAt_exp_zero_of_radius_pos h).hasStrictDerivAt /-- The exponential map in a complete normed field `𝕂` of characteristic zero has derivative `1` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝕂).radius) : HasDerivAt (exp 𝕂) (1 : 𝕂) 0 := (hasStrictDerivAt_exp_zero_of_radius_pos h).hasDerivAt end deriv section RCLikeAnyAlgebra variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential in a Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ` has strict Fréchet derivative `1 : 𝔸 →L[𝕂] 𝔸` at zero. -/ theorem hasStrictFDerivAt_exp_zero : HasStrictFDerivAt (exp 𝕂) (1 : 𝔸 →L[𝕂] 𝔸) 0 := hasStrictFDerivAt_exp_zero_of_radius_pos (expSeries_radius_pos 𝕂 𝔸) /-- The exponential in a Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ` has Fréchet derivative `1 : 𝔸 →L[𝕂] 𝔸` at zero. -/ theorem hasFDerivAt_exp_zero : HasFDerivAt (exp 𝕂) (1 : 𝔸 →L[𝕂] 𝔸) 0 := hasStrictFDerivAt_exp_zero.hasFDerivAt end RCLikeAnyAlgebra section RCLikeCommAlgebra variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential map in a commutative Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ` has strict Fréchet derivative `NormedSpace.exp 𝕂 x • 1 : 𝔸 →L[𝕂] 𝔸` at any point `x`. -/ theorem hasStrictFDerivAt_exp {x : 𝔸} : HasStrictFDerivAt (exp 𝕂) (exp 𝕂 x • (1 : 𝔸 →L[𝕂] 𝔸)) x := hasStrictFDerivAt_exp_of_mem_ball ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _) /-- The exponential map in a commutative Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ` has Fréchet derivative `NormedSpace.exp 𝕂 x • 1 : 𝔸 →L[𝕂] 𝔸` at any point `x`. -/ theorem hasFDerivAt_exp {x : 𝔸} : HasFDerivAt (exp 𝕂) (exp 𝕂 x • (1 : 𝔸 →L[𝕂] 𝔸)) x := hasStrictFDerivAt_exp.hasFDerivAt end RCLikeCommAlgebra section DerivRCLike variable {𝕂 : Type*} [RCLike 𝕂] /-- The exponential map in `𝕂 = ℝ` or `𝕂 = ℂ` has strict derivative `NormedSpace.exp 𝕂 x` at any point `x`. -/ theorem hasStrictDerivAt_exp {x : 𝕂} : HasStrictDerivAt (exp 𝕂) (exp 𝕂 x) x := hasStrictDerivAt_exp_of_mem_ball ((expSeries_radius_eq_top 𝕂 𝕂).symm ▸ edist_lt_top _ _) /-- The exponential map in `𝕂 = ℝ` or `𝕂 = ℂ` has derivative `NormedSpace.exp 𝕂 x` at any point `x`. -/ theorem hasDerivAt_exp {x : 𝕂} : HasDerivAt (exp 𝕂) (exp 𝕂 x) x := hasStrictDerivAt_exp.hasDerivAt /-- The exponential map in `𝕂 = ℝ` or `𝕂 = ℂ` has strict derivative `1` at zero. -/ theorem hasStrictDerivAt_exp_zero : HasStrictDerivAt (exp 𝕂) (1 : 𝕂) 0 := hasStrictDerivAt_exp_zero_of_radius_pos (expSeries_radius_pos 𝕂 𝕂) /-- The exponential map in `𝕂 = ℝ` or `𝕂 = ℂ` has derivative `1` at zero. -/ theorem hasDerivAt_exp_zero : HasDerivAt (exp 𝕂) (1 : 𝕂) 0 := hasStrictDerivAt_exp_zero.hasDerivAt end DerivRCLike theorem Complex.exp_eq_exp_ℂ : Complex.exp = NormedSpace.exp ℂ := by refine funext fun x => ?_ rw [Complex.exp, exp_eq_tsum_div] have : CauSeq.IsComplete ℂ norm := Complex.instIsComplete exact tendsto_nhds_unique x.exp'.tendsto_limit (expSeries_div_summable ℝ x).hasSum.tendsto_sum_nat theorem Real.exp_eq_exp_ℝ : Real.exp = NormedSpace.exp ℝ := by ext x; exact mod_cast congr_fun Complex.exp_eq_exp_ℂ x /-! ### Derivative of $\exp (ux)$ by $u$ Note that since for `x : 𝔸` we have `NormedRing 𝔸` not `NormedCommRing 𝔸`, we cannot deduce these results from `hasFDerivAt_exp_of_mem_ball` applied to the algebra `𝔸`. One possible solution for that would be to apply `hasFDerivAt_exp_of_mem_ball` to the commutative algebra `Algebra.elementalAlgebra 𝕊 x`. Unfortunately we don't have all the required API, so we leave that to a future refactor (see https://github.com/leanprover-community/mathlib3/pull/19062 for discussion). We could also go the other way around and deduce `hasFDerivAt_exp_of_mem_ball` from `hasFDerivAt_exp_smul_const_of_mem_ball` applied to `𝕊 := 𝔸`, `x := (1 : 𝔸)`, and `t := x`. However, doing so would make the aforementioned `elementalAlgebra` refactor harder, so for now we
just prove these two lemmas independently.
Mathlib/Analysis/SpecialFunctions/Exponential.lean
227
228
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ import Mathlib.NumberTheory.LegendreSymbol.Basic import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.GaussSum /-! # Quadratic reciprocity. ## Main results We prove the law of quadratic reciprocity, see `legendreSym.quadratic_reciprocity` and `legendreSym.quadratic_reciprocity'`, as well as the interpretations in terms of existence of square roots depending on the congruence mod 4, `ZMod.exists_sq_eq_prime_iff_of_mod_four_eq_one` and `ZMod.exists_sq_eq_prime_iff_of_mod_four_eq_three`. We also prove the supplementary laws that give conditions for when `2` or `-2` is a square modulo a prime `p`: `legendreSym.at_two` and `ZMod.exists_sq_eq_two_iff` for `2` and `legendreSym.at_neg_two` and `ZMod.exists_sq_eq_neg_two_iff` for `-2`. ## Implementation notes The proofs use results for quadratic characters on arbitrary finite fields from `NumberTheory.LegendreSymbol.QuadraticChar.GaussSum`, which in turn are based on properties of quadratic Gauss sums as provided by `NumberTheory.LegendreSymbol.GaussSum`. ## Tags quadratic residue, quadratic nonresidue, Legendre symbol, quadratic reciprocity -/ open Nat section Values variable {p : ℕ} [Fact p.Prime] open ZMod /-! ### The value of the Legendre symbol at `2` and `-2` See `jacobiSym.at_two` and `jacobiSym.at_neg_two` for the corresponding statements for the Jacobi symbol. -/ namespace legendreSym /-- `legendreSym p 2` is given by `χ₈ p`. -/ theorem at_two (hp : p ≠ 2) : legendreSym p 2 = χ₈ p := by have : (2 : ZMod p) = (2 : ℤ) := by norm_cast rw [legendreSym, ← this, quadraticChar_two ((ringChar_zmod_n p).substr hp), card p] /-- `legendreSym p (-2)` is given by `χ₈' p`. -/ theorem at_neg_two (hp : p ≠ 2) : legendreSym p (-2) = χ₈' p := by have : (-2 : ZMod p) = (-2 : ℤ) := by norm_cast rw [legendreSym, ← this, quadraticChar_neg_two ((ringChar_zmod_n p).substr hp), card p] end legendreSym namespace ZMod /-- `2` is a square modulo an odd prime `p` iff `p` is congruent to `1` or `7` mod `8`. -/ theorem exists_sq_eq_two_iff (hp : p ≠ 2) : IsSquare (2 : ZMod p) ↔ p % 8 = 1 ∨ p % 8 = 7 := by rw [FiniteField.isSquare_two_iff, card p] have h₁ := Prime.mod_two_eq_one_iff_ne_two.mpr hp omega /-- `-2` is a square modulo an odd prime `p` iff `p` is congruent to `1` or `3` mod `8`. -/ theorem exists_sq_eq_neg_two_iff (hp : p ≠ 2) : IsSquare (-2 : ZMod p) ↔ p % 8 = 1 ∨ p % 8 = 3 := by rw [FiniteField.isSquare_neg_two_iff, card p] have h₁ := Prime.mod_two_eq_one_iff_ne_two.mpr hp omega end ZMod end Values section Reciprocity /-! ### The Law of Quadratic Reciprocity See `jacobiSym.quadratic_reciprocity` and variants for a version of Quadratic Reciprocity for the Jacobi symbol. -/ variable {p q : ℕ} [Fact p.Prime] [Fact q.Prime] namespace legendreSym open ZMod /-- **The Law of Quadratic Reciprocity**: if `p` and `q` are distinct odd primes, then `(q / p) * (p / q) = (-1)^((p-1)(q-1)/4)`. -/ theorem quadratic_reciprocity (hp : p ≠ 2) (hq : q ≠ 2) (hpq : p ≠ q) : legendreSym q p * legendreSym p q = (-1) ^ (p / 2 * (q / 2)) := by have hp₁ := (Prime.eq_two_or_odd <| @Fact.out p.Prime _).resolve_left hp have hq₁ := (Prime.eq_two_or_odd <| @Fact.out q.Prime _).resolve_left hq have hq₂ : ringChar (ZMod q) ≠ 2 := (ringChar_zmod_n q).substr hq have h := quadraticChar_odd_prime ((ringChar_zmod_n p).substr hp) hq ((ringChar_zmod_n p).substr hpq) rw [card p] at h have nc : ∀ n r : ℕ, ((n : ℤ) : ZMod r) = n := fun n r => by norm_cast have nc' : (((-1) ^ (p / 2) : ℤ) : ZMod q) = (-1) ^ (p / 2) := by norm_cast rw [legendreSym, legendreSym, nc, nc, h, map_mul, mul_rotate', mul_comm (p / 2), ← pow_two, quadraticChar_sq_one (prime_ne_zero q p hpq.symm), mul_one, pow_mul, χ₄_eq_neg_one_pow hp₁, nc', map_pow, quadraticChar_neg_one hq₂, card q, χ₄_eq_neg_one_pow hq₁] /-- The Law of Quadratic Reciprocity: if `p` and `q` are odd primes, then `(q / p) = (-1)^((p-1)(q-1)/4) * (p / q)`. -/ theorem quadratic_reciprocity' (hp : p ≠ 2) (hq : q ≠ 2) : legendreSym q p = (-1) ^ (p / 2 * (q / 2)) * legendreSym p q := by rcases eq_or_ne p q with h | h · subst p rw [(eq_zero_iff q q).mpr (mod_cast natCast_self q), mul_zero] · have qr := congr_arg (· * legendreSym p q) (quadratic_reciprocity hp hq h) have : ((q : ℤ) : ZMod p) ≠ 0 := mod_cast prime_ne_zero p q h simpa only [mul_assoc, ← pow_two, sq_one p this, mul_one] using qr /-- The Law of Quadratic Reciprocity: if `p` and `q` are odd primes and `p % 4 = 1`, then `(q / p) = (p / q)`. -/ theorem quadratic_reciprocity_one_mod_four (hp : p % 4 = 1) (hq : q ≠ 2) : legendreSym q p = legendreSym p q := by rw [quadratic_reciprocity' (Prime.mod_two_eq_one_iff_ne_two.mp (odd_of_mod_four_eq_one hp)) hq, pow_mul, neg_one_pow_div_two_of_one_mod_four hp, one_pow, one_mul] /-- The Law of Quadratic Reciprocity: if `p` and `q` are primes that are both congruent to `3` mod `4`, then `(q / p) = -(p / q)`. -/ theorem quadratic_reciprocity_three_mod_four (hp : p % 4 = 3) (hq : q % 4 = 3) : legendreSym q p = -legendreSym p q := by let nop := @neg_one_pow_div_two_of_three_mod_four rw [quadratic_reciprocity', pow_mul, nop hp, nop hq, neg_one_mul] <;> rwa [← Prime.mod_two_eq_one_iff_ne_two, odd_of_mod_four_eq_three] end legendreSym namespace ZMod open legendreSym /-- If `p` and `q` are odd primes and `p % 4 = 1`, then `q` is a square mod `p` iff `p` is a square mod `q`. -/ theorem exists_sq_eq_prime_iff_of_mod_four_eq_one (hp1 : p % 4 = 1) (hq1 : q ≠ 2) : IsSquare (q : ZMod p) ↔ IsSquare (p : ZMod q) := by rcases eq_or_ne p q with h | h · subst p; rfl · rw [← eq_one_iff' p (prime_ne_zero p q h), ← eq_one_iff' q (prime_ne_zero q p h.symm), quadratic_reciprocity_one_mod_four hp1 hq1]
/-- If `p` and `q` are distinct primes that are both congruent to `3` mod `4`, then `q` is a square mod `p` iff `p` is a nonsquare mod `q`. -/ theorem exists_sq_eq_prime_iff_of_mod_four_eq_three (hp3 : p % 4 = 3) (hq3 : q % 4 = 3) (hpq : p ≠ q) : IsSquare (q : ZMod p) ↔ ¬IsSquare (p : ZMod q) := by rw [← eq_one_iff' p (prime_ne_zero p q hpq), ← eq_neg_one_iff' q,
Mathlib/NumberTheory/LegendreSymbol/QuadraticReciprocity.lean
158
162
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.Kernel.Basic import Mathlib.Probability.Kernel.Composition.MeasureComp import Mathlib.Tactic.Peel import Mathlib.MeasureTheory.MeasurableSpace.Pi /-! # Independence with respect to a kernel and a measure A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ : Kernel α Ω` and a measure `μ` on `α` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then for `μ`-almost every `a : α`, `κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. This notion of independence is a generalization of both independence and conditional independence. For conditional independence, `κ` is the conditional kernel `ProbabilityTheory.condExpKernel` and `μ` is the ambient measure. For (non-conditional) independence, `κ = Kernel.const Unit μ` and the measure is the Dirac measure on `Unit`. The main purpose of this file is to prove only once the properties that hold for both conditional and non-conditional independence. ## Main definitions * `ProbabilityTheory.Kernel.iIndepSets`: independence of a family of sets of sets. Variant for two sets of sets: `ProbabilityTheory.Kernel.IndepSets`. * `ProbabilityTheory.Kernel.iIndep`: independence of a family of σ-algebras. Variant for two σ-algebras: `Indep`. * `ProbabilityTheory.Kernel.iIndepSet`: independence of a family of sets. Variant for two sets: `ProbabilityTheory.Kernel.IndepSet`. * `ProbabilityTheory.Kernel.iIndepFun`: independence of a family of functions (random variables). Variant for two functions: `ProbabilityTheory.Kernel.IndepFun`. See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these definitions in the particular case of the usual independence notion. ## Main statements * `ProbabilityTheory.Kernel.iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `ProbabilityTheory.Kernel.IndepSets.Indep`: variant with two π-systems. -/ open Set MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory.Kernel variable {α Ω ι : Type*} section Definitions variable {_mα : MeasurableSpace α} /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a kernel `κ` and a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `∀ᵐ a ∂μ, κ a (⋂ i in s, f i) = ∏ i ∈ s, κ a (f i)`. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) /-- Two sets of sets `s₁, s₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (∀ᵐ a ∂μ, κ a (t1 ∩ t2) = κ a t1 * κ a t2) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a kernel `κ` and a measure `μ` if the family of sets of measurable sets they define is independent. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a kernel `κ` and a measure `μ` if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `∀ᵐ a ∂μ, κ a (t₁ ∩ t₂) = κ a (t₁) * κ a (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} κ μ /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (m := fun i ↦ generateFrom {s i}) κ μ /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (generateFrom {s}) (generateFrom {t}) κ μ /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)] (f : ∀ x : ι, Ω → β x) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := iIndep (m := fun x ↦ MeasurableSpace.comap (f x) (m x)) κ μ /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (κ : Kernel α Ω) (μ : Measure α := by volume_tac) : Prop := Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) κ μ end Definitions section ByDefinition variable {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {_mα : MeasurableSpace α} {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ η : Kernel α Ω} {μ : Measure α} {π : ι → Set (Set Ω)} {s : ι → Set Ω} {S : Finset ι} {f : ∀ x : ι, Ω → β x} {s1 s2 : Set (Set Ω)} @[simp] lemma iIndepSets_zero_right : iIndepSets π κ 0 := by simp [iIndepSets] @[simp] lemma indepSets_zero_right : IndepSets s1 s2 κ 0 := by simp [IndepSets] @[simp] lemma indepSets_zero_left : IndepSets s1 s2 (0 : Kernel α Ω) μ := by simp [IndepSets] @[simp] lemma iIndep_zero_right : iIndep m κ 0 := by simp [iIndep] @[simp] lemma indep_zero_right {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} : Indep m₁ m₂ κ 0 := by simp [Indep] @[simp] lemma indep_zero_left {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} : Indep m₁ m₂ (0 : Kernel α Ω) μ := by simp [Indep] @[simp] lemma iIndepSet_zero_right : iIndepSet s κ 0 := by simp [iIndepSet] @[simp] lemma indepSet_zero_right {s t : Set Ω} : IndepSet s t κ 0 := by simp [IndepSet] @[simp] lemma indepSet_zero_left {s t : Set Ω} : IndepSet s t (0 : Kernel α Ω) μ := by simp [IndepSet] @[simp] lemma iIndepFun_zero_right {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)} {f : ∀ x : ι, Ω → β x} : iIndepFun f κ 0 := by simp [iIndepFun] @[simp] lemma indepFun_zero_right {β γ} [MeasurableSpace β] [MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} : IndepFun f g κ 0 := by simp [IndepFun] @[simp] lemma indepFun_zero_left {β γ} [MeasurableSpace β] [MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} : IndepFun f g (0 : Kernel α Ω) μ := by simp [IndepFun] lemma iIndepSets_congr (h : κ =ᵐ[μ] η) : iIndepSets π κ μ ↔ iIndepSets π η μ := by peel 3 refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;> · filter_upwards [h, h'] with a ha h'a simpa [ha] using h'a alias ⟨iIndepSets.congr, _⟩ := iIndepSets_congr lemma indepSets_congr (h : κ =ᵐ[μ] η) : IndepSets s1 s2 κ μ ↔ IndepSets s1 s2 η μ := by peel 4 refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;> · filter_upwards [h, h'] with a ha h'a simpa [ha] using h'a alias ⟨IndepSets.congr, _⟩ := indepSets_congr lemma iIndep_congr (h : κ =ᵐ[μ] η) : iIndep m κ μ ↔ iIndep m η μ := iIndepSets_congr h alias ⟨iIndep.congr, _⟩ := iIndep_congr lemma indep_congr {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ η : Kernel α Ω} (h : κ =ᵐ[μ] η) : Indep m₁ m₂ κ μ ↔ Indep m₁ m₂ η μ := indepSets_congr h alias ⟨Indep.congr, _⟩ := indep_congr lemma iIndepSet_congr (h : κ =ᵐ[μ] η) : iIndepSet s κ μ ↔ iIndepSet s η μ := iIndep_congr h alias ⟨iIndepSet.congr, _⟩ := iIndepSet_congr lemma indepSet_congr {s t : Set Ω} (h : κ =ᵐ[μ] η) : IndepSet s t κ μ ↔ IndepSet s t η μ := indep_congr h alias ⟨indepSet.congr, _⟩ := indepSet_congr lemma iIndepFun_congr {β : ι → Type*} {m : ∀ x : ι, MeasurableSpace (β x)} {f : ∀ x : ι, Ω → β x} (h : κ =ᵐ[μ] η) : iIndepFun f κ μ ↔ iIndepFun f η μ := iIndep_congr h alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr lemma indepFun_congr {β γ} [MeasurableSpace β] [MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (h : κ =ᵐ[μ] η) : IndepFun f g κ μ ↔ IndepFun f g η μ := indep_congr h alias ⟨IndepFun.congr, _⟩ := indepFun_congr lemma iIndepSets.meas_biInter (h : iIndepSets π κ μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ s, f i) = ∏ i ∈ s, κ a (f i) := h s hf lemma iIndepSets.ae_isProbabilityMeasure (h : iIndepSets π κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := by filter_upwards [h.meas_biInter ∅ (f := fun _ ↦ Set.univ) (by simp)] with a ha exact ⟨by simpa using ha⟩ lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π κ μ) (hs : ∀ i, s i ∈ π i) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha] lemma iIndep.iIndepSets' (hμ : iIndep m κ μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) κ μ := hμ lemma iIndep.ae_isProbabilityMeasure (h : iIndep m κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := h.iIndepSets'.ae_isProbabilityMeasure lemma iIndep.meas_biInter (hμ : iIndep m κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (h : iIndep m κ μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := by filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha simp [← ha] @[nontriviality, simp] lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} {κ : Kernel α Ω} [IsMarkovKernel κ] : iIndepSets m κ μ := by rintro s f hf obtain rfl | ⟨i, rfl⟩ : s = ∅ ∨ ∃ i, s = {i} := by simpa using (subsingleton_of_subsingleton (s := s.toSet)).eq_empty_or_singleton all_goals simp @[nontriviality, simp] lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} {κ : Kernel α Ω} [IsMarkovKernel κ] : iIndep m κ μ := by simp [iIndep] @[nontriviality, simp] lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} [IsMarkovKernel κ] : iIndepFun f κ μ := by simp [iIndepFun] protected lemma iIndepFun.iIndep (hf : iIndepFun f κ μ) : iIndep (fun x ↦ (mβ x).comap (f x)) κ μ := hf lemma iIndepFun.ae_isProbabilityMeasure (h : iIndepFun f κ μ) : ∀ᵐ a ∂μ, IsProbabilityMeasure (κ a) := h.iIndep.ae_isProbabilityMeasure lemma iIndepFun.meas_biInter (hf : iIndepFun f κ μ) (hs : ∀ i, i ∈ S → MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] (hf : iIndepFun f κ μ) (hs : ∀ i, MeasurableSet[(mβ i).comap (f i)] (s i)) : ∀ᵐ a ∂μ, κ a (⋂ i, s i) = ∏ i, κ a (s i) := hf.iIndep.meas_iInter hs lemma IndepFun.meas_inter {β γ : Type*} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g κ μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := hfg _ _ hs ht end ByDefinition section Indep variable {_mα : MeasurableSpace α} @[symm] theorem IndepSets.symm {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ κ μ) : IndepSets s₂ s₁ κ μ := by intros t1 t2 ht1 ht2 filter_upwards [h t2 t1 ht2 ht1] with a ha rwa [Set.inter_comm, mul_comm] @[symm] theorem Indep.symm {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h : Indep m₁ m₂ κ μ) : Indep m₂ m₁ κ μ := IndepSets.symm h theorem indep_bot_right (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] : Indep m' ⊥ κ μ := by intros s t _ ht rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht rcases eq_zero_or_isMarkovKernel κ with rfl| h · simp refine Filter.Eventually.of_forall (fun a ↦ ?_) rcases ht with ht | ht · rw [ht, Set.inter_empty, measure_empty, mul_zero] · rw [ht, Set.inter_univ, measure_univ, mul_one] theorem indep_bot_left (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] : Indep ⊥ m' κ μ := (indep_bot_right m').symm theorem indepSet_empty_right {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) : IndepSet s ∅ κ μ := by simp only [IndepSet, generateFrom_singleton_empty] exact indep_bot_right _ theorem indepSet_empty_left {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} [IsZeroOrMarkovKernel κ] (s : Set Ω) : IndepSet ∅ s κ μ := (indepSet_empty_right s).symm theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : IndepSets s₁ s₂ κ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2) theorem indep_of_indep_of_le_left {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (h31 _ ht1) ht2 theorem indep_of_indep_of_le_right {m₁ m₂ m₃ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h_indep : Indep m₁ m₂ κ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ κ μ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (h32 _ ht2) theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) (h₂ : IndepSets s₂ s' κ μ) : IndepSets (s₁ ∪ s₂) s' κ μ := by intro t1 t2 ht1 ht2 rcases (Set.mem_union _ _ _).mp ht1 with ht1₁ | ht1₂ · exact h₁ t1 t2 ht1₁ ht2 · exact h₂ t1 t2 ht1₂ ht2 @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : IndepSets (s₁ ∪ s₂) s' κ μ ↔ IndepSets s₁ s' κ μ ∧ IndepSets s₂ s' κ μ := ⟨fun h => ⟨indepSets_of_indepSets_of_le_left h Set.subset_union_left, indepSets_of_indepSets_of_le_left h Set.subset_union_right⟩, fun h => IndepSets.union h.left h.right⟩ theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (hyp : ∀ n, IndepSets (s n) s' κ μ) : IndepSets (⋃ n, s n) s' κ μ := by intro t1 t2 ht1 ht2 rw [Set.mem_iUnion] at ht1 obtain ⟨n, ht1⟩ := ht1 exact hyp n t1 t2 ht1 ht2 theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋃ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 simp_rw [Set.mem_iUnion] at ht1 rcases ht1 with ⟨n, hpn, ht1⟩ exact hyp n hpn t1 t2 ht1 ht2 theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h₁ : IndepSets s₁ s' κ μ) : IndepSets (s₁ ∩ s₂) s' κ μ := fun t1 t2 ht1 ht2 => h₁ t1 t2 ((Set.mem_inter_iff _ _ _).mp ht1).left ht2
theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} (h : ∃ n, IndepSets (s n) s' κ μ) : IndepSets (⋂ n, s n) s' κ μ := by intro t1 t2 ht1 ht2; obtain ⟨n, h⟩ := h; exact h t1 t2 (Set.mem_iInter.mp ht1 n) ht2 theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' κ μ) : IndepSets (⋂ n ∈ u, s n) s' κ μ := by intro t1 t2 ht1 ht2 rcases h with ⟨n, hn, h⟩ exact h t1 t2 (Set.biInter_subset_of_mem hn ht1) ht2 theorem iIndep_comap_mem_iff {f : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) κ μ ↔ iIndepSet f κ μ := by simp_rw [← generateFrom_singleton, iIndepSet] theorem iIndepSets_singleton_iff {s : ι → Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : iIndepSets (fun i ↦ {s i}) κ μ ↔ ∀ S : Finset ι, ∀ᵐ a ∂μ, κ a (⋂ i ∈ S, s i) = ∏ i ∈ S, κ a (s i) := by refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩ filter_upwards [h S] with a ha have : ∀ i ∈ S, κ a (f i) = κ a (s i) := fun i hi ↦ by rw [hf i hi] rwa [Finset.prod_congr rfl this, Set.iInter₂_congr hf] theorem indepSets_singleton_iff {s t : Set Ω} {_mΩ : MeasurableSpace Ω} {κ : Kernel α Ω} {μ : Measure α} : IndepSets {s} {t} κ μ ↔ ∀ᵐ a ∂μ, κ a (s ∩ t) = κ a s * κ a t := ⟨fun h ↦ h s t rfl rfl,
Mathlib/Probability/Independence/Kernel.lean
378
407
/- Copyright (c) 2024 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Order.CompactlyGenerated.Basic /-! # Generators for boolean algebras In this file, we provide an alternative constructor for boolean algebras. A set of *boolean generators* in a compactly generated complete lattice is a subset `S` such that * the elements of `S` are all atoms, and * the set `S` satisfies an atomicity condition: any compact element below the supremum of a subset `s` of generators is equal to the supremum of a subset of `s`. ## Main declarations * `IsCompactlyGenerated.BooleanGenerators`: the predicate described above. * `IsCompactlyGenerated.BooleanGenerators.complementedLattice_of_sSup_eq_top`: if `S` generates the entire lattice, then it is complemented. * `IsCompactlyGenerated.BooleanGenerators.distribLattice_of_sSup_eq_top`: if `S` generates the entire lattice, then it is distributive. * `IsCompactlyGenerated.BooleanGenerators.booleanAlgebra_of_sSup_eq_top`: if `S` generates the entire lattice, then it is a boolean algebra. -/ namespace IsCompactlyGenerated open CompleteLattice variable {α : Type*} [CompleteLattice α] /-- An alternative constructor for boolean algebras. A set of *boolean generators* in a compactly generated complete lattice is a subset `S` such that * the elements of `S` are all atoms, and * the set `S` satisfies an atomicity condition: any compact element below the supremum of a finite subset `s` of generators is equal to the supremum of a subset of `s`. If the supremum of `S` is the whole lattice, then the lattice is a boolean algebra (see `IsCompactlyGenerated.BooleanGenerators.booleanAlgebra_of_sSup_eq_top`). -/ structure BooleanGenerators (S : Set α) : Prop where /-- The elements in a collection of boolean generators are all atoms. -/ isAtom : ∀ I ∈ S, IsAtom I /-- The elements in a collection of boolean generators satisfy an atomicity condition: any compact element below the supremum of a finite subset `s` of generators is equal to the supremum of a subset of `s`. -/ finitelyAtomistic : ∀ (s : Finset α) (a : α), ↑s ⊆ S → IsCompactElement a → a ≤ s.sup id → ∃ t ⊆ s, a = t.sup id namespace BooleanGenerators variable {S : Set α} lemma mono (hS : BooleanGenerators S) {T : Set α} (hTS : T ⊆ S) : BooleanGenerators T where isAtom I hI := hS.isAtom I (hTS hI) finitelyAtomistic := fun s a hs ↦ hS.finitelyAtomistic s a (le_trans hs hTS) variable [IsCompactlyGenerated α] lemma atomistic (hS : BooleanGenerators S) (a : α) (ha : a ≤ sSup S) : ∃ T ⊆ S, a = sSup T := by obtain ⟨C, hC, rfl⟩ := IsCompactlyGenerated.exists_sSup_eq a have aux : ∀ b : α, IsCompactElement b → b ≤ sSup S → ∃ T ⊆ S, b = sSup T := by intro b hb hbS obtain ⟨s, hs₁, hs₂⟩ := hb S hbS obtain ⟨t, ht, rfl⟩ := hS.finitelyAtomistic s b hs₁ hb hs₂ refine ⟨t, ?_, Finset.sup_id_eq_sSup t⟩ refine Set.Subset.trans ?_ hs₁ simpa only [Finset.coe_subset] using ht choose T hT₁ hT₂ using aux use sSup {T c h₁ h₂ | (c ∈ C) (h₁ : IsCompactElement c) (h₂ : c ≤ sSup S)} constructor · apply _root_.sSup_le rintro _ ⟨c, -, h₁, h₂, rfl⟩ apply hT₁ · apply le_antisymm · apply _root_.sSup_le intro c hc rw [hT₂ c (hC _ hc) ((le_sSup hc).trans ha)] apply sSup_le_sSup apply _root_.le_sSup use c, hc, hC _ hc, (le_sSup hc).trans ha · simp only [Set.sSup_eq_sUnion, sSup_le_iff, Set.mem_sUnion, Set.mem_setOf_eq, forall_exists_index, and_imp] rintro a T b hbC hb hbS rfl haT apply (le_sSup haT).trans rw [← hT₂] exact le_sSup hbC lemma isAtomistic_of_sSup_eq_top (hS : BooleanGenerators S) (h : sSup S = ⊤) : IsAtomistic α := by refine CompleteLattice.isAtomistic_iff.2 fun a ↦ ?_ obtain ⟨s, hs, hs'⟩ := hS.atomistic a (h ▸ le_top) exact ⟨s, hs', fun I hI ↦ hS.isAtom I (hs hI)⟩ lemma mem_of_isAtom_of_le_sSup_atoms (hS : BooleanGenerators S) (a : α) (ha : IsAtom a) (haS : a ≤ sSup S) : a ∈ S := by obtain ⟨T, hT, rfl⟩ := hS.atomistic a haS obtain rfl | ⟨a, haT⟩ := T.eq_empty_or_nonempty · simp only [sSup_empty] at ha exact (ha.1 rfl).elim suffices sSup T = a from this ▸ hT haT have : a ≤ sSup T := le_sSup haT rwa [ha.le_iff_eq, eq_comm] at this
exact (hS.isAtom a (hT haT)).1 lemma sSup_inter (hS : BooleanGenerators S) {T₁ T₂ : Set α} (hT₁ : T₁ ⊆ S) (hT₂ : T₂ ⊆ S) : sSup (T₁ ∩ T₂) = (sSup T₁) ⊓ (sSup T₂) := by apply le_antisymm · apply le_inf · apply sSup_le_sSup Set.inter_subset_left · apply sSup_le_sSup Set.inter_subset_right obtain ⟨X, hX, hX'⟩ := hS.atomistic (sSup T₁ ⊓ sSup T₂) (inf_le_left.trans (sSup_le_sSup hT₁)) rw [hX'] apply _root_.sSup_le intro I hI apply _root_.le_sSup constructor · apply (hS.mono hT₁).mem_of_isAtom_of_le_sSup_atoms _ _ _ · exact (hS.mono hX).isAtom I hI · exact (_root_.le_sSup hI).trans (hX'.ge.trans inf_le_left) · apply (hS.mono hT₂).mem_of_isAtom_of_le_sSup_atoms _ _ _
Mathlib/Order/BooleanGenerators.lean
116
133
/- 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, Kim Morrison -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Preimage import Mathlib.Algebra.Module.Defs import Mathlib.Data.Rat.BigOperators /-! # Miscellaneous definitions, lemmas, and constructions using finsupp ## Main declarations * `Finsupp.graph`: the finset of input and output pairs with non-zero outputs. * `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv. * `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing. * `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage of its support. * `Finsupp.some`: restrict a finitely supported function on `Option α` to a finitely supported function on `α`. * `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true and 0 otherwise. * `Finsupp.frange`: the image of a finitely supported function on its support. * `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * This file is currently ~1600 lines long and is quite a miscellany of definitions and lemmas, so it should be divided into smaller pieces. * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {α β γ ι M M' N P G H R S : Type*} namespace Finsupp /-! ### Declarations about `graph` -/ section Graph variable [Zero M] /-- The graph of a finitely supported function over its support, i.e. the finset of input and output pairs with non-zero outputs. -/ def graph (f : α →₀ M) : Finset (α × M) := f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩ theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by simp_rw [graph, mem_map, mem_support_iff] constructor · rintro ⟨b, ha, rfl, -⟩ exact ⟨rfl, ha⟩ · rintro ⟨rfl, ha⟩ exact ⟨a, ha, rfl⟩ @[simp] theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by cases c exact mk_mem_graph_iff theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph := mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m := (mem_graph_iff.1 h).1
Mathlib/Data/Finsupp/Basic.lean
78
80
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Algebra.CharP.Reduced import Mathlib.Algebra.Field.ZMod import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.ValMinAbs import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix import Mathlib.FieldTheory.Finiteness import Mathlib.FieldTheory.Perfect import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * #(univ.image fun x => eval x p) := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = #(p - C a).roots.toFinset := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_cancel]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g))) <| calc 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * #(univ.image fun x : R => eval x f) + natDegree (-g) * #(univ.image fun x : R => eval x (-g)) := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) := by rw [card_union_of_disjoint hd] simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp +contextual [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) : ∑ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G ↪ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x simp only [h_unchanged, mulLeftEmbedding_apply, Subgroup.coe_mul, Units.val_mul, ← mul_sum, a_mul_emb] at h_sum_map -- thus one of (a - 1) or ∑ G, x is zero have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] : ∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by by_cases G_bot : G = ⊥ · subst G_bot simp only [univ_unique, sum_singleton, ↓reduceIte, Units.val_eq_one, OneMemClass.coe_eq_one] rw [Set.default_coe_singleton] rfl · simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by rw [← Nat.card_eq_fintype_card] at k_lt_card_G nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k) = (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by funext x simp only [Function.comp_apply, Subgroup.coe_mul, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : Kˣ) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K] theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one] rfl theorem pow_card (a : K) : a ^ q = a := by by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one, pow_card_sub_one_eq_one a h, one_mul] theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by induction n with | zero => simp | succ n ih => simp [pow_succ, pow_mul, ih, pow_card] end variable (K) [Field K] [Fintype K] /-- The cardinality `q` is a power of the characteristic of `K`. -/ @[stacks 09HY "first part"] theorem card (p : ℕ) [CharP K p] : ∃ n : ℕ+, Nat.Prime p ∧ q = p ^ (n : ℕ) := by haveI hp : Fact p.Prime := ⟨CharP.char_is_prime K p⟩ letI : Module (ZMod p) K := { (ZMod.castHom dvd_rfl K : ZMod p →+* _).toModule with } obtain ⟨n, h⟩ := VectorSpace.card_fintype (ZMod p) K rw [ZMod.card] at h refine ⟨⟨n, ?_⟩, hp.1, h⟩ apply Or.resolve_left (Nat.eq_zero_or_pos n) rintro rfl rw [pow_zero] at h have : (0 : K) = 1 := by apply Fintype.card_le_one_iff.mp (le_of_eq h) exact absurd this zero_ne_one -- this statement doesn't use `q` because we want `K` to be an explicit parameter theorem card' : ∃ (p : ℕ), CharP K p ∧ ∃ (n : ℕ+), Nat.Prime p ∧ Fintype.card K = p ^ (n : ℕ) := let ⟨p, hc⟩ := CharP.exists K ⟨p, hc, @FiniteField.card K _ _ p hc⟩ lemma isPrimePow_card : IsPrimePow (Fintype.card K) := by obtain ⟨p, _, n, hp, hn⟩ := card' K exact ⟨p, n, Nat.prime_iff.mp hp, n.prop, hn.symm⟩ theorem cast_card_eq_zero : (q : K) = 0 := by simp theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣ i := by classical obtain ⟨x, hx⟩ := IsCyclic.exists_generator (α := Kˣ) rw [← Nat.card_eq_fintype_card, ← Nat.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hx, orderOf_dvd_iff_pow_eq_one] constructor · intro h; apply h · intro h y simp_rw [← mem_powers_iff_mem_zpowers] at hx rcases hx y with ⟨j, rfl⟩ rw [← pow_mul, mul_comm, pow_mul, h, one_pow] /-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q` is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/ theorem sum_pow_units [DecidableEq K] (i : ℕ) : (∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by let φ : Kˣ →* K := { toFun := fun x => x ^ i map_one' := by simp map_mul' := by intros; simp [mul_pow] } have : Decidable (φ = 1) := by classical infer_instance calc (∑ x : Kˣ, φ x) = if φ = 1 then Fintype.card Kˣ else 0 := sum_hom_units φ _ = if q - 1 ∣ i then -1 else 0 := by suffices q - 1 ∣ i ↔ φ = 1 by simp only [this] split_ifs; swap · exact Nat.cast_zero · rw [Fintype.card_units, Nat.cast_sub, cast_card_eq_zero, Nat.cast_one, zero_sub] show 1 ≤ q; exact Fintype.card_pos_iff.mpr ⟨0⟩ rw [← forall_pow_eq_one_iff, DFunLike.ext_iff] apply forall_congr'; intro x; simp [φ, Units.ext_iff] /-- The sum of `x ^ i` as `x` ranges over a finite field of cardinality `q` is equal to `0` if `i < q - 1`. -/ theorem sum_pow_lt_card_sub_one (i : ℕ) (h : i < q - 1) : ∑ x : K, x ^ i = 0 := by by_cases hi : i = 0 · simp only [hi, nsmul_one, sum_const, pow_zero, card_univ, cast_card_eq_zero] classical have hiq : ¬q - 1 ∣ i := by contrapose! h; exact Nat.le_of_dvd (Nat.pos_of_ne_zero hi) h let φ : Kˣ ↪ K := ⟨fun x ↦ x, Units.ext⟩ have : univ.map φ = univ \ {0} := by ext x simpa only [mem_map, mem_univ, Function.Embedding.coeFn_mk, true_and, mem_sdiff, mem_singleton, φ] using isUnit_iff_ne_zero calc ∑ x : K, x ^ i = ∑ x ∈ univ \ {(0 : K)}, x ^ i := by rw [← sum_sdiff ({0} : Finset K).subset_univ, sum_singleton, zero_pow hi, add_zero] _ = ∑ x : Kˣ, (x ^ i : K) := by simp [φ, ← this, univ.sum_map φ] _ = 0 := by rw [sum_pow_units K i, if_neg]; exact hiq section frobenius variable (R) [CommRing R] [Algebra K R] /-- If `R` is an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is given by raising every element of `R` to its `#K`-th power. -/ @[simps!] def frobeniusAlgHom : R →ₐ[K] R where __ := powMonoidHom q map_zero' := zero_pow Fintype.card_pos.ne' map_add' _ _ := by obtain ⟨p, _, _, hp, card_eq⟩ := card' K nontriviality R have : CharP R p := charP_of_injective_algebraMap' K R p have : ExpChar R p := .prime hp simp only [OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, powMonoidHom_apply, card_eq] exact add_pow_expChar_pow .. commutes' _ := by simp [← RingHom.map_pow, pow_card] theorem coe_frobeniusAlgHom : ⇑(frobeniusAlgHom K R) = (· ^ q) := rfl /-- If `R` is a perfect ring and an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquiv (p : ℕ) [ExpChar R p] [PerfectRing R p] : R ≃ₐ[K] R := .ofBijective (frobeniusAlgHom K R) <| by obtain ⟨p', _, n, hp, card_eq⟩ := card' K rw [coe_frobeniusAlgHom, card_eq] have : ExpChar K p' := ExpChar.prime hp nontriviality R have := ExpChar.eq ‹_› (expChar_of_injective_algebraMap (algebraMap K R).injective p') subst this apply bijective_iterateFrobenius variable (L : Type*) [Field L] [Algebra K L] /-- If `L/K` is an algebraic extension of a finite field, the Frobenius `K`-algebra endomorphism of `L` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : L ≃ₐ[K] L := (Algebra.IsAlgebraic.algEquivEquivAlgHom K L).symm (frobeniusAlgHom K L) theorem coe_frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : ⇑(frobeniusAlgEquivOfAlgebraic K L) = (· ^ q) := rfl variable [Finite L] open Polynomial in theorem orderOf_frobeniusAlgHom : orderOf (frobeniusAlgHom K L) = Module.finrank K L := (orderOf_eq_iff Module.finrank_pos).mpr <| by have := Fintype.ofFinite L refine ⟨DFunLike.ext _ _ fun x ↦ ?_, fun m lt pos eq ↦ ?_⟩ · simp_rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← Module.card_eq_pow_finrank, pow_card] have := card_le_degree_of_subset_roots (R := L) (p := X ^ q ^ m - X) (Z := univ) fun x _ ↦ by simp_rw [mem_roots', IsRoot, eval_sub, eval_pow, eval_X] have := DFunLike.congr_fun eq x rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← sub_eq_zero] at this refine ⟨fun h ↦ ?_, this⟩ simpa [if_neg (Nat.one_lt_pow pos.ne' Fintype.one_lt_card).ne] using congr_arg (coeff · 1) h refine this.not_lt (((natDegree_sub_le ..).trans_eq ?_).trans_lt <| (Nat.pow_lt_pow_right Fintype.one_lt_card lt).trans_eq Module.card_eq_pow_finrank.symm) simp [Nat.one_le_pow _ _ Fintype.card_pos] theorem orderOf_frobeniusAlgEquivOfAlgebraic : orderOf (frobeniusAlgEquivOfAlgebraic K L) = Module.finrank K L := by simpa [orderOf_eq_iff Module.finrank_pos, DFunLike.ext_iff] using orderOf_frobeniusAlgHom K L theorem bijective_frobeniusAlgHom_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgHom K L ^ n.1 := let e := (finCongr <| orderOf_frobeniusAlgHom K L).symm.trans <| finEquivPowers (orderOf_pos_iff.mp <| orderOf_frobeniusAlgHom K L ▸ Module.finrank_pos) (Subtype.val_injective.comp e.injective).bijective_of_nat_card_le
((card_algHom_le_finrank K L L).trans_eq <| by simp) theorem bijective_frobeniusAlgEquivOfAlgebraic_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgEquivOfAlgebraic K L ^ n.1 := ((Algebra.IsAlgebraic.algEquivEquivAlgHom K L).bijective.of_comp_iff' _).mp <| by simpa only [Function.comp_def, map_pow] using bijective_frobeniusAlgHom_pow K L
Mathlib/FieldTheory/Finite/Basic.lean
386
392
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Units.Equiv import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.HomCongr /-! # Conjugate morphisms by isomorphisms An isomorphism `α : X ≅ Y` defines - a monoid isomorphism `CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`; - a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by `α.conjAut f = α.symm ≪≫ f ≪≫ α` using `CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)` and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)` which are defined in `CategoryTheory.HomCongr`. -/ universe v u namespace CategoryTheory namespace Iso variable {C : Type u} [Category.{v} C] variable {X Y : C} (α : X ≅ Y) /-- An isomorphism between two objects defines a monoid isomorphism between their monoid of endomorphisms. -/ def conj : End X ≃* End Y := { homCongr α α with map_mul' := fun f g => homCongr_comp α α α g f } theorem conj_apply (f : End X) : α.conj f = α.inv ≫ f ≫ α.hom := rfl @[simp] theorem conj_comp (f g : End X) : α.conj (f ≫ g) = α.conj f ≫ α.conj g := map_mul α.conj g f @[simp] theorem conj_id : α.conj (𝟙 X) = 𝟙 Y := map_one α.conj @[simp] theorem refl_conj (f : End X) : (Iso.refl X).conj f = f := by rw [conj_apply, Iso.refl_inv, Iso.refl_hom, Category.id_comp, Category.comp_id] @[simp] theorem trans_conj {Z : C} (β : Y ≅ Z) (f : End X) : (α ≪≫ β).conj f = β.conj (α.conj f) := homCongr_trans α α β β f @[simp] theorem symm_self_conj (f : End X) : α.symm.conj (α.conj f) = f := by rw [← trans_conj, α.self_symm_id, refl_conj] @[simp] theorem self_symm_conj (f : End Y) : α.conj (α.symm.conj f) = f := α.symm.symm_self_conj f @[simp] theorem conj_pow (f : End X) (n : ℕ) : α.conj (f ^ n) = α.conj f ^ n := α.conj.toMonoidHom.map_pow f n -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: change definition so that `conjAut_apply` becomes a `rfl`? /-- `conj` defines a group isomorphisms between groups of automorphisms -/ def conjAut : Aut X ≃* Aut Y := (Aut.unitsEndEquivAut X).symm.trans <| (Units.mapEquiv α.conj).trans <| Aut.unitsEndEquivAut Y theorem conjAut_apply (f : Aut X) : α.conjAut f = α.symm ≪≫ f ≪≫ α := by aesop_cat @[simp] theorem conjAut_hom (f : Aut X) : (α.conjAut f).hom = α.conj f.hom := rfl @[simp] theorem trans_conjAut {Z : C} (β : Y ≅ Z) (f : Aut X) : (α ≪≫ β).conjAut f = β.conjAut (α.conjAut f) := by simp only [conjAut_apply, Iso.trans_symm, Iso.trans_assoc] @[simp] theorem conjAut_mul (f g : Aut X) : α.conjAut (f * g) = α.conjAut f * α.conjAut g := map_mul α.conjAut f g @[simp] theorem conjAut_trans (f g : Aut X) : α.conjAut (f ≪≫ g) = α.conjAut f ≪≫ α.conjAut g := conjAut_mul α g f @[simp] theorem conjAut_pow (f : Aut X) (n : ℕ) : α.conjAut (f ^ n) = α.conjAut f ^ n := map_pow α.conjAut f n @[simp] theorem conjAut_zpow (f : Aut X) (n : ℤ) : α.conjAut (f ^ n) = α.conjAut f ^ n := map_zpow α.conjAut f n end Iso namespace Functor universe v₁ u₁ variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] (F : C ⥤ D) theorem map_conj {X Y : C} (α : X ≅ Y) (f : End X) : F.map (α.conj f) = (F.mapIso α).conj (F.map f) := map_homCongr F α α f theorem map_conjAut (F : C ⥤ D) {X Y : C} (α : X ≅ Y) (f : Aut X) : F.mapIso (α.conjAut f) = (F.mapIso α).conjAut (F.mapIso f) := by ext; simp only [mapIso_hom, Iso.conjAut_hom, F.map_conj] -- alternative proof: by simp only [Iso.conjAut_apply, F.mapIso_trans, F.mapIso_symm] end Functor end CategoryTheory
Mathlib/CategoryTheory/Conj.lean
203
205
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth -/ import Mathlib.MeasureTheory.Group.Action import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Integral.Lebesgue.Map import Mathlib.MeasureTheory.Integral.Bochner.Set /-! # Fundamental domain of a group action A set `s` is said to be a *fundamental domain* of an action of a group `G` on a measurable space `α` with respect to a measure `μ` if * `s` is a measurable set; * the sets `g • s` over all `g : G` cover almost all points of the whole space; * the sets `g • s`, are pairwise a.e. disjoint, i.e., `μ (g₁ • s ∩ g₂ • s) = 0` whenever `g₁ ≠ g₂`; we require this for `g₂ = 1` in the definition, then deduce it for any two `g₁ ≠ g₂`. In this file we prove that in case of a countable group `G` and a measure preserving action, any two fundamental domains have the same measure, and for a `G`-invariant function, its integrals over any two fundamental domains are equal to each other. We also generate additive versions of all theorems in this file using the `to_additive` attribute. * We define the `HasFundamentalDomain` typeclass, in particular to be able to define the `covolume` of a quotient of `α` by a group `G`, which under reasonable conditions does not depend on the choice of fundamental domain. * We define the `QuotientMeasureEqMeasurePreimage` typeclass to describe a situation in which a measure `μ` on `α ⧸ G` can be computed by taking a measure `ν` on `α` of the intersection of the pullback with a fundamental domain. ## Main declarations * `MeasureTheory.IsFundamentalDomain`: Predicate for a set to be a fundamental domain of the action of a group * `MeasureTheory.fundamentalFrontier`: Fundamental frontier of a set under the action of a group. Elements of `s` that belong to some other translate of `s`. * `MeasureTheory.fundamentalInterior`: Fundamental interior of a set under the action of a group. Elements of `s` that do not belong to any other translate of `s`. -/ open scoped ENNReal Pointwise Topology NNReal ENNReal MeasureTheory open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Filter namespace MeasureTheory /-- A measurable set `s` is a *fundamental domain* for an additive action of an additive group `G` on a measurable space `α` with respect to a measure `α` if the sets `g +ᵥ s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ structure IsAddFundamentalDomain (G : Type*) {α : Type*} [Zero G] [VAdd G α] [MeasurableSpace α] (s : Set α) (μ : Measure α := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s μ protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g +ᵥ x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g +ᵥ s) /-- A measurable set `s` is a *fundamental domain* for an action of a group `G` on a measurable space `α` with respect to a measure `α` if the sets `g • s`, `g : G`, are pairwise a.e. disjoint and cover the whole space. -/ @[to_additive IsAddFundamentalDomain] structure IsFundamentalDomain (G : Type*) {α : Type*} [One G] [SMul G α] [MeasurableSpace α] (s : Set α) (μ : Measure α := by volume_tac) : Prop where protected nullMeasurableSet : NullMeasurableSet s μ protected ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s protected aedisjoint : Pairwise <| (AEDisjoint μ on fun g : G => g • s) variable {G H α β E : Type*} namespace IsFundamentalDomain variable [Group G] [Group H] [MulAction G α] [MeasurableSpace α] [MulAction H β] [MeasurableSpace β] [NormedAddCommGroup E] {s t : Set α} {μ : Measure α} /-- If for each `x : α`, exactly one of `g • x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the action of `G` on `α`. -/ @[to_additive "If for each `x : α`, exactly one of `g +ᵥ x`, `g : G`, belongs to a measurable set `s`, then `s` is a fundamental domain for the additive action of `G` on `α`."] theorem mk' (h_meas : NullMeasurableSet s μ) (h_exists : ∀ x : α, ∃! g : G, g • x ∈ s) : IsFundamentalDomain G s μ where nullMeasurableSet := h_meas ae_covers := Eventually.of_forall fun x => (h_exists x).exists aedisjoint a b hab := Disjoint.aedisjoint <| disjoint_left.2 fun x hxa hxb => by rw [mem_smul_set_iff_inv_smul_mem] at hxa hxb exact hab (inv_injective <| (h_exists x).unique hxa hxb) /-- For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g • s) s` for `g ≠ 1`. -/ @[to_additive "For `s` to be a fundamental domain, it's enough to check `MeasureTheory.AEDisjoint (g +ᵥ s) s` for `g ≠ 0`."] theorem mk'' (h_meas : NullMeasurableSet s μ) (h_ae_covers : ∀ᵐ x ∂μ, ∃ g : G, g • x ∈ s) (h_ae_disjoint : ∀ g, g ≠ (1 : G) → AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving ((g • ·) : α → α) μ μ) : IsFundamentalDomain G s μ where nullMeasurableSet := h_meas ae_covers := h_ae_covers aedisjoint := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp /-- If a measurable space has a finite measure `μ` and a countable group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g • s` are (almost) disjoint and that the sum `∑' g, μ (g • s)` is sufficiently large. -/ @[to_additive "If a measurable space has a finite measure `μ` and a countable additive group `G` acts quasi-measure-preservingly, then to show that a set `s` is a fundamental domain, it is sufficient to check that its translates `g +ᵥ s` are (almost) disjoint and that the sum `∑' g, μ (g +ᵥ s)` is sufficiently large."] theorem mk_of_measure_univ_le [IsFiniteMeasure μ] [Countable G] (h_meas : NullMeasurableSet s μ) (h_ae_disjoint : ∀ g ≠ (1 : G), AEDisjoint μ (g • s) s) (h_qmp : ∀ g : G, QuasiMeasurePreserving (g • · : α → α) μ μ) (h_measure_univ_le : μ (univ : Set α) ≤ ∑' g : G, μ (g • s)) : IsFundamentalDomain G s μ := have aedisjoint : Pairwise (AEDisjoint μ on fun g : G => g • s) := pairwise_aedisjoint_of_aedisjoint_forall_ne_one h_ae_disjoint h_qmp { nullMeasurableSet := h_meas aedisjoint ae_covers := by replace h_meas : ∀ g : G, NullMeasurableSet (g • s) μ := fun g => by rw [← inv_inv g, ← preimage_smul]; exact h_meas.preimage (h_qmp g⁻¹) have h_meas' : NullMeasurableSet {a | ∃ g : G, g • a ∈ s} μ := by rw [← iUnion_smul_eq_setOf_exists]; exact .iUnion h_meas rw [ae_iff_measure_eq h_meas', ← iUnion_smul_eq_setOf_exists] refine le_antisymm (measure_mono <| subset_univ _) ?_ rw [measure_iUnion₀ aedisjoint h_meas] exact h_measure_univ_le } @[to_additive] theorem iUnion_smul_ae_eq (h : IsFundamentalDomain G s μ) : ⋃ g : G, g • s =ᵐ[μ] univ := eventuallyEq_univ.2 <| h.ae_covers.mono fun _ ⟨g, hg⟩ => mem_iUnion.2 ⟨g⁻¹, _, hg, inv_smul_smul _ _⟩ @[to_additive] theorem measure_ne_zero [Countable G] [SMulInvariantMeasure G α μ] (hμ : μ ≠ 0) (h : IsFundamentalDomain G s μ) : μ s ≠ 0 := by have hc := measure_univ_pos.mpr hμ contrapose! hc rw [← measure_congr h.iUnion_smul_ae_eq] refine le_trans (measure_iUnion_le _) ?_ simp_rw [measure_smul, hc, tsum_zero, le_refl] @[to_additive] theorem mono (h : IsFundamentalDomain G s μ) {ν : Measure α} (hle : ν ≪ μ) : IsFundamentalDomain G s ν := ⟨h.1.mono_ac hle, hle h.2, h.aedisjoint.mono fun _ _ h => hle h⟩ @[to_additive] theorem preimage_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) {f : β → α} (hf : QuasiMeasurePreserving f ν μ) {e : G → H} (he : Bijective e) (hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f ⁻¹' s) ν where nullMeasurableSet := h.nullMeasurableSet.preimage hf ae_covers := (hf.ae h.ae_covers).mono fun x ⟨g, hg⟩ => ⟨e g, by rwa [mem_preimage, hef g x]⟩ aedisjoint a b hab := by lift e to G ≃ H using he have : (e.symm a⁻¹)⁻¹ ≠ (e.symm b⁻¹)⁻¹ := by simp [hab] have := (h.aedisjoint this).preimage hf simp only [Semiconj] at hef simpa only [onFun, ← preimage_smul_inv, preimage_preimage, ← hef, e.apply_symm_apply, inv_inv] using this @[to_additive] theorem image_of_equiv {ν : Measure β} (h : IsFundamentalDomain G s μ) (f : α ≃ β) (hf : QuasiMeasurePreserving f.symm ν μ) (e : H ≃ G) (hef : ∀ g, Semiconj f (e g • ·) (g • ·)) : IsFundamentalDomain H (f '' s) ν := by rw [f.image_eq_preimage] refine h.preimage_of_equiv hf e.symm.bijective fun g x => ?_ rcases f.surjective x with ⟨x, rfl⟩ rw [← hef _ _, f.symm_apply_apply, f.symm_apply_apply, e.apply_symm_apply] @[to_additive] theorem pairwise_aedisjoint_of_ac {ν} (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) : Pairwise fun g₁ g₂ : G => AEDisjoint ν (g₁ • s) (g₂ • s) := h.aedisjoint.mono fun _ _ H => hν H @[to_additive] theorem smul_of_comm {G' : Type*} [Group G'] [MulAction G' α] [MeasurableSpace G'] [MeasurableSMul G' α] [SMulInvariantMeasure G' α μ] [SMulCommClass G' G α] (h : IsFundamentalDomain G s μ) (g : G') : IsFundamentalDomain G (g • s) μ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving (Equiv.refl _) <| smul_comm g variable [MeasurableSpace G] [MeasurableSMul G α] [SMulInvariantMeasure G α μ] @[to_additive] theorem nullMeasurableSet_smul (h : IsFundamentalDomain G s μ) (g : G) : NullMeasurableSet (g • s) μ := h.nullMeasurableSet.smul g @[to_additive] theorem restrict_restrict (h : IsFundamentalDomain G s μ) (g : G) (t : Set α) : (μ.restrict t).restrict (g • s) = μ.restrict (g • s ∩ t) := restrict_restrict₀ ((h.nullMeasurableSet_smul g).mono restrict_le_self) @[to_additive] theorem smul (h : IsFundamentalDomain G s μ) (g : G) : IsFundamentalDomain G (g • s) μ := h.image_of_equiv (MulAction.toPerm g) (measurePreserving_smul _ _).quasiMeasurePreserving ⟨fun g' => g⁻¹ * g' * g, fun g' => g * g' * g⁻¹, fun g' => by simp [mul_assoc], fun g' => by simp [mul_assoc]⟩ fun g' x => by simp [smul_smul, mul_assoc] variable [Countable G] {ν : Measure α} @[to_additive] theorem sum_restrict_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) : (sum fun g : G => ν.restrict (g • s)) = ν := by rw [← restrict_iUnion_ae (h.aedisjoint.mono fun i j h => hν h) fun g => (h.nullMeasurableSet_smul g).mono_ac hν, restrict_congr_set (hν h.iUnion_smul_ae_eq), restrict_univ] @[to_additive] theorem lintegral_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂ν = ∑' g : G, ∫⁻ x in g • s, f x ∂ν := by rw [← lintegral_sum_measure, h.sum_restrict_of_ac hν] @[to_additive] theorem sum_restrict (h : IsFundamentalDomain G s μ) : (sum fun g : G => μ.restrict (g • s)) = μ := h.sum_restrict_of_ac (refl _) @[to_additive] theorem lintegral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ := h.lintegral_eq_tsum_of_ac (refl _) f @[to_additive] theorem lintegral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in s, f (g⁻¹ • x) ∂μ := calc ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ := h.lintegral_eq_tsum f _ = ∑' g : G, ∫⁻ x in g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫⁻ x in s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ μ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] lemma lintegral_eq_tsum'' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) : ∫⁻ x, f x ∂μ = ∑' g : G, ∫⁻ x in s, f (g • x) ∂μ := (lintegral_eq_tsum' h f).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫⁻ (x : α) in s, f (g • x) ∂μ)) @[to_additive] theorem setLIntegral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) (t : Set α) : ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := calc ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in g • s, f x ∂μ.restrict t := h.lintegral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous _ _ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := by simp only [h.restrict_restrict, inter_comm] @[to_additive] theorem setLIntegral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → ℝ≥0∞) (t : Set α) : ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := calc ∫⁻ x in t, f x ∂μ = ∑' g : G, ∫⁻ x in t ∩ g • s, f x ∂μ := h.setLIntegral_eq_tsum f t _ = ∑' g : G, ∫⁻ x in t ∩ g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫⁻ x in g⁻¹ • (g • t ∩ s), f x ∂μ := by simp only [smul_set_inter, inv_smul_smul] _ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => Eq.symm <| (measurePreserving_smul g⁻¹ μ).setLIntegral_comp_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] theorem measure_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (t : Set α) : ν t = ∑' g : G, ν (t ∩ g • s) := by have H : ν.restrict t ≪ μ := Measure.restrict_le_self.absolutelyContinuous.trans hν simpa only [setLIntegral_one, Pi.one_def, Measure.restrict_apply₀ ((h.nullMeasurableSet_smul _).mono_ac H), inter_comm] using h.lintegral_eq_tsum_of_ac H 1 @[to_additive] theorem measure_eq_tsum' (h : IsFundamentalDomain G s μ) (t : Set α) : μ t = ∑' g : G, μ (t ∩ g • s) := h.measure_eq_tsum_of_ac AbsolutelyContinuous.rfl t @[to_additive] theorem measure_eq_tsum (h : IsFundamentalDomain G s μ) (t : Set α) : μ t = ∑' g : G, μ (g • t ∩ s) := by simpa only [setLIntegral_one] using h.setLIntegral_eq_tsum' (fun _ => 1) t @[to_additive] theorem measure_zero_of_invariant (h : IsFundamentalDomain G s μ) (t : Set α) (ht : ∀ g : G, g • t = t) (hts : μ (t ∩ s) = 0) : μ t = 0 := by rw [measure_eq_tsum h]; simp [ht, hts] /-- Given a measure space with an action of a finite group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`. -/ @[to_additive measure_eq_card_smul_of_vadd_ae_eq_self "Given a measure space with an action of a finite additive group `G`, the measure of any `G`-invariant set is determined by the measure of its intersection with a fundamental domain for the action of `G`."] theorem measure_eq_card_smul_of_smul_ae_eq_self [Finite G] (h : IsFundamentalDomain G s μ) (t : Set α) (ht : ∀ g : G, (g • t : Set α) =ᵐ[μ] t) : μ t = Nat.card G • μ (t ∩ s) := by haveI : Fintype G := Fintype.ofFinite G rw [h.measure_eq_tsum] replace ht : ∀ g : G, (g • t ∩ s : Set α) =ᵐ[μ] (t ∩ s : Set α) := fun g => ae_eq_set_inter (ht g) (ae_eq_refl s) simp_rw [measure_congr (ht _), tsum_fintype, Finset.sum_const, Nat.card_eq_fintype_card, Finset.card_univ] @[to_additive] protected theorem setLIntegral_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) (f : α → ℝ≥0∞) (hf : ∀ (g : G) (x), f (g • x) = f x) : ∫⁻ x in s, f x ∂μ = ∫⁻ x in t, f x ∂μ := calc ∫⁻ x in s, f x ∂μ = ∑' g : G, ∫⁻ x in s ∩ g • t, f x ∂μ := ht.setLIntegral_eq_tsum _ _ _ = ∑' g : G, ∫⁻ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := by simp only [hf, inter_comm] _ = ∫⁻ x in t, f x ∂μ := (hs.setLIntegral_eq_tsum' _ _).symm @[to_additive] theorem measure_set_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {A : Set α} (hA₀ : MeasurableSet A) (hA : ∀ g : G, (fun x => g • x) ⁻¹' A = A) : μ (A ∩ s) = μ (A ∩ t) := by have : ∫⁻ x in s, A.indicator 1 x ∂μ = ∫⁻ x in t, A.indicator 1 x ∂μ := by refine hs.setLIntegral_eq ht (Set.indicator A fun _ => 1) fun g x ↦ ?_ convert (Set.indicator_comp_right (g • · : α → α) (g := fun _ ↦ (1 : ℝ≥0∞))).symm rw [hA g] simpa [Measure.restrict_apply hA₀, lintegral_indicator hA₀] using this /-- If `s` and `t` are two fundamental domains of the same action, then their measures are equal. -/ @[to_additive "If `s` and `t` are two fundamental domains of the same action, then their measures are equal."] protected theorem measure_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) : μ s = μ t := by simpa only [setLIntegral_one] using hs.setLIntegral_eq ht (fun _ => 1) fun _ _ => rfl @[to_additive] protected theorem aestronglyMeasurable_on_iff {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → β} (hf : ∀ (g : G) (x), f (g • x) = f x) : AEStronglyMeasurable f (μ.restrict s) ↔ AEStronglyMeasurable f (μ.restrict t) := calc AEStronglyMeasurable f (μ.restrict s) ↔ AEStronglyMeasurable f (Measure.sum fun g : G => μ.restrict (g • t ∩ s)) := by simp only [← ht.restrict_restrict, ht.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g • (g⁻¹ • s ∩ t))) := by simp only [smul_set_inter, inter_comm, smul_inv_smul, aestronglyMeasurable_sum_measure_iff] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g⁻¹ • (g⁻¹⁻¹ • s ∩ t))) := inv_surjective.forall _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g⁻¹ • (g • s ∩ t))) := by simp only [inv_inv] _ ↔ ∀ g : G, AEStronglyMeasurable f (μ.restrict (g • s ∩ t)) := by refine forall_congr' fun g => ?_ have he : MeasurableEmbedding (g⁻¹ • · : α → α) := measurableEmbedding_const_smul _ rw [← image_smul, ← ((measurePreserving_smul g⁻¹ μ).restrict_image_emb he _).aestronglyMeasurable_comp_iff he] simp only [Function.comp_def, hf] _ ↔ AEStronglyMeasurable f (μ.restrict t) := by simp only [← aestronglyMeasurable_sum_measure_iff, ← hs.restrict_restrict, hs.sum_restrict_of_ac restrict_le_self.absolutelyContinuous] @[deprecated (since := "2025-04-09")] alias aEStronglyMeasurable_on_iff := MeasureTheory.IsFundamentalDomain.aestronglyMeasurable_on_iff @[deprecated (since := "2025-04-09")] alias _root_.MeasureTheory.IsAddFundamentalDomain.aEStronglyMeasurable_on_iff := MeasureTheory.IsAddFundamentalDomain.aestronglyMeasurable_on_iff @[to_additive] protected theorem hasFiniteIntegral_on_iff (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : HasFiniteIntegral f (μ.restrict s) ↔ HasFiniteIntegral f (μ.restrict t) := by dsimp only [HasFiniteIntegral] rw [hs.setLIntegral_eq ht] intro g x; rw [hf] @[to_additive] protected theorem integrableOn_iff (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : IntegrableOn f s μ ↔ IntegrableOn f t μ := and_congr (hs.aestronglyMeasurable_on_iff ht hf) (hs.hasFiniteIntegral_on_iff ht hf) variable [NormedSpace ℝ E] @[to_additive] theorem integral_eq_tsum_of_ac (h : IsFundamentalDomain G s μ) (hν : ν ≪ μ) (f : α → E) (hf : Integrable f ν) : ∫ x, f x ∂ν = ∑' g : G, ∫ x in g • s, f x ∂ν := by rw [← MeasureTheory.integral_sum_measure, h.sum_restrict_of_ac hν] rw [h.sum_restrict_of_ac hν] exact hf @[to_additive] theorem integral_eq_tsum (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ := integral_eq_tsum_of_ac h (by rfl) f hf @[to_additive] theorem integral_eq_tsum' (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in s, f (g⁻¹ • x) ∂μ := calc ∫ x, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ := h.integral_eq_tsum f hf _ = ∑' g : G, ∫ x in g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫ x in s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => (measurePreserving_smul g⁻¹ μ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] lemma integral_eq_tsum'' (h : IsFundamentalDomain G s μ) (f : α → E) (hf : Integrable f μ) : ∫ x, f x ∂μ = ∑' g : G, ∫ x in s, f (g • x) ∂μ := (integral_eq_tsum' h f hf).trans ((Equiv.inv G).tsum_eq (fun g ↦ ∫ (x : α) in s, f (g • x) ∂μ)) @[to_additive] theorem setIntegral_eq_tsum (h : IsFundamentalDomain G s μ) {f : α → E} {t : Set α} (hf : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := calc ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in g • s, f x ∂μ.restrict t := h.integral_eq_tsum_of_ac restrict_le_self.absolutelyContinuous f hf _ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := by simp only [h.restrict_restrict, measure_smul, inter_comm] @[to_additive] theorem setIntegral_eq_tsum' (h : IsFundamentalDomain G s μ) {f : α → E} {t : Set α} (hf : IntegrableOn f t μ) : ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := calc ∫ x in t, f x ∂μ = ∑' g : G, ∫ x in t ∩ g • s, f x ∂μ := h.setIntegral_eq_tsum hf _ = ∑' g : G, ∫ x in t ∩ g⁻¹ • s, f x ∂μ := ((Equiv.inv G).tsum_eq _).symm _ = ∑' g : G, ∫ x in g⁻¹ • (g • t ∩ s), f x ∂μ := by simp only [smul_set_inter, inv_smul_smul] _ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := tsum_congr fun g => (measurePreserving_smul g⁻¹ μ).setIntegral_image_emb (measurableEmbedding_const_smul _) _ _ @[to_additive] protected theorem setIntegral_eq (hs : IsFundamentalDomain G s μ) (ht : IsFundamentalDomain G t μ) {f : α → E} (hf : ∀ (g : G) (x), f (g • x) = f x) : ∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ := by by_cases hfs : IntegrableOn f s μ · have hft : IntegrableOn f t μ := by rwa [ht.integrableOn_iff hs hf] calc ∫ x in s, f x ∂μ = ∑' g : G, ∫ x in s ∩ g • t, f x ∂μ := ht.setIntegral_eq_tsum hfs _ = ∑' g : G, ∫ x in g • t ∩ s, f (g⁻¹ • x) ∂μ := by simp only [hf, inter_comm] _ = ∫ x in t, f x ∂μ := (hs.setIntegral_eq_tsum' hft).symm · rw [integral_undef hfs, integral_undef] rwa [hs.integrableOn_iff ht hf] at hfs /-- If the action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g • t ∩ s` are pairwise a.e.-disjoint has measure at most `μ s`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` such that the sets `g +ᵥ t ∩ s` are pairwise a.e.-disjoint has measure at most `μ s`."] theorem measure_le_of_pairwise_disjoint (hs : IsFundamentalDomain G s μ) (ht : NullMeasurableSet t μ) (hd : Pairwise (AEDisjoint μ on fun g : G => g • t ∩ s)) : μ t ≤ μ s := calc μ t = ∑' g : G, μ (g • t ∩ s) := hs.measure_eq_tsum t _ = μ (⋃ g : G, g • t ∩ s) := Eq.symm <| measure_iUnion₀ hd fun _ => (ht.smul _).inter hs.nullMeasurableSet _ ≤ μ s := measure_mono (iUnion_subset fun _ => inter_subset_right) /-- If the action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `μ s` contains two points `x y` such that `g • x = y` for some `g ≠ 1`. -/ @[to_additive "If the additive action of a countable group `G` admits an invariant measure `μ` with a fundamental domain `s`, then every null-measurable set `t` of measure strictly greater than `μ s` contains two points `x y` such that `g +ᵥ x = y` for some `g ≠ 0`."] theorem exists_ne_one_smul_eq (hs : IsFundamentalDomain G s μ) (htm : NullMeasurableSet t μ) (ht : μ s < μ t) : ∃ x ∈ t, ∃ y ∈ t, ∃ g, g ≠ (1 : G) ∧ g • x = y := by contrapose! ht refine hs.measure_le_of_pairwise_disjoint htm (Pairwise.aedisjoint fun g₁ g₂ hne => ?_) dsimp [Function.onFun] refine (Disjoint.inf_left _ ?_).inf_right _ rw [Set.disjoint_left] rintro _ ⟨x, hx, rfl⟩ ⟨y, hy, hxy : g₂ • y = g₁ • x⟩ refine ht x hx y hy (g₂⁻¹ * g₁) (mt inv_mul_eq_one.1 hne.symm) ?_ rw [mul_smul, ← hxy, inv_smul_smul] /-- If `f` is invariant under the action of a countable group `G`, and `μ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain. -/ @[to_additive "If `f` is invariant under the action of a countable additive group `G`, and `μ` is a `G`-invariant measure with a fundamental domain `s`, then the `essSup` of `f` restricted to `s` is the same as that of `f` on all of its domain."] theorem essSup_measure_restrict (hs : IsFundamentalDomain G s μ) {f : α → ℝ≥0∞} (hf : ∀ γ : G, ∀ x : α, f (γ • x) = f x) : essSup f (μ.restrict s) = essSup f μ := by refine le_antisymm (essSup_mono_measure' Measure.restrict_le_self) ?_ rw [essSup_eq_sInf (μ.restrict s) f, essSup_eq_sInf μ f] refine sInf_le_sInf ?_ rintro a (ha : (μ.restrict s) {x : α | a < f x} = 0) rw [Measure.restrict_apply₀' hs.nullMeasurableSet] at ha refine measure_zero_of_invariant hs _ ?_ ha intro γ ext x rw [mem_smul_set_iff_inv_smul_mem] simp only [mem_setOf_eq, hf γ⁻¹ x] end IsFundamentalDomain /-! ### Interior/frontier of a fundamental domain -/ section MeasurableSpace variable (G) [Group G] [MulAction G α] (s : Set α) {x : α} /-- The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial translate. -/ @[to_additive MeasureTheory.addFundamentalFrontier "The boundary of a fundamental domain, those points of the domain that also lie in a nontrivial translate."] def fundamentalFrontier : Set α := s ∩ ⋃ (g : G) (_ : g ≠ 1), g • s /-- The interior of a fundamental domain, those points of the domain not lying in any translate. -/ @[to_additive MeasureTheory.addFundamentalInterior "The interior of a fundamental domain, those points of the domain not lying in any translate."] def fundamentalInterior : Set α := s \ ⋃ (g : G) (_ : g ≠ 1), g • s variable {G s} @[to_additive (attr := simp) MeasureTheory.mem_addFundamentalFrontier] theorem mem_fundamentalFrontier : x ∈ fundamentalFrontier G s ↔ x ∈ s ∧ ∃ g : G, g ≠ 1 ∧ x ∈ g • s := by simp [fundamentalFrontier] @[to_additive (attr := simp) MeasureTheory.mem_addFundamentalInterior] theorem mem_fundamentalInterior : x ∈ fundamentalInterior G s ↔ x ∈ s ∧ ∀ g : G, g ≠ 1 → x ∉ g • s := by simp [fundamentalInterior] @[to_additive MeasureTheory.addFundamentalFrontier_subset] theorem fundamentalFrontier_subset : fundamentalFrontier G s ⊆ s := inter_subset_left @[to_additive MeasureTheory.addFundamentalInterior_subset] theorem fundamentalInterior_subset : fundamentalInterior G s ⊆ s := diff_subset variable (G s) @[to_additive MeasureTheory.disjoint_addFundamentalInterior_addFundamentalFrontier] theorem disjoint_fundamentalInterior_fundamentalFrontier : Disjoint (fundamentalInterior G s) (fundamentalFrontier G s) := disjoint_sdiff_self_left.mono_right inf_le_right @[to_additive (attr := simp) MeasureTheory.addFundamentalInterior_union_addFundamentalFrontier] theorem fundamentalInterior_union_fundamentalFrontier : fundamentalInterior G s ∪ fundamentalFrontier G s = s := diff_union_inter _ _ @[to_additive (attr := simp) MeasureTheory.addFundamentalFrontier_union_addFundamentalInterior] theorem fundamentalFrontier_union_fundamentalInterior : fundamentalFrontier G s ∪ fundamentalInterior G s = s := inter_union_diff _ _ @[to_additive (attr := simp) MeasureTheory.sdiff_addFundamentalInterior] theorem sdiff_fundamentalInterior : s \ fundamentalInterior G s = fundamentalFrontier G s := sdiff_sdiff_right_self @[to_additive (attr := simp) MeasureTheory.sdiff_addFundamentalFrontier] theorem sdiff_fundamentalFrontier : s \ fundamentalFrontier G s = fundamentalInterior G s := diff_self_inter @[to_additive (attr := simp) MeasureTheory.addFundamentalFrontier_vadd] theorem fundamentalFrontier_smul [Group H] [MulAction H α] [SMulCommClass H G α] (g : H) : fundamentalFrontier G (g • s) = g • fundamentalFrontier G s := by simp_rw [fundamentalFrontier, smul_set_inter, smul_set_iUnion, smul_comm g (_ : G) (_ : Set α)] @[to_additive (attr := simp) MeasureTheory.addFundamentalInterior_vadd] theorem fundamentalInterior_smul [Group H] [MulAction H α] [SMulCommClass H G α] (g : H) : fundamentalInterior G (g • s) = g • fundamentalInterior G s := by simp_rw [fundamentalInterior, smul_set_sdiff, smul_set_iUnion, smul_comm g (_ : G) (_ : Set α)] @[to_additive MeasureTheory.pairwise_disjoint_addFundamentalInterior] theorem pairwise_disjoint_fundamentalInterior : Pairwise (Disjoint on fun g : G => g • fundamentalInterior G s) := by refine fun a b hab => disjoint_left.2 ?_ rintro _ ⟨x, hx, rfl⟩ ⟨y, hy, hxy⟩ rw [mem_fundamentalInterior] at hx hy refine hx.2 (a⁻¹ * b) ?_ ?_ · rwa [Ne, inv_mul_eq_iff_eq_mul, mul_one, eq_comm] · simpa [mul_smul, ← hxy, mem_inv_smul_set_iff] using hy.1 variable [Countable G] [MeasurableSpace G] [MeasurableSpace α] [MeasurableSMul G α] {μ : Measure α} [SMulInvariantMeasure G α μ] @[to_additive MeasureTheory.NullMeasurableSet.addFundamentalFrontier] protected theorem NullMeasurableSet.fundamentalFrontier (hs : NullMeasurableSet s μ) : NullMeasurableSet (fundamentalFrontier G s) μ := hs.inter <| .iUnion fun _ => .iUnion fun _ => hs.smul _ @[to_additive MeasureTheory.NullMeasurableSet.addFundamentalInterior] protected theorem NullMeasurableSet.fundamentalInterior (hs : NullMeasurableSet s μ) : NullMeasurableSet (fundamentalInterior G s) μ := hs.diff <| .iUnion fun _ => .iUnion fun _ => hs.smul _ end MeasurableSpace namespace IsFundamentalDomain variable [Countable G] [Group G] [MulAction G α] [MeasurableSpace α] {μ : Measure α} {s : Set α} (hs : IsFundamentalDomain G s μ) include hs section Group @[to_additive MeasureTheory.IsAddFundamentalDomain.measure_addFundamentalFrontier] theorem measure_fundamentalFrontier : μ (fundamentalFrontier G s) = 0 := by simpa only [fundamentalFrontier, iUnion₂_inter, one_smul, measure_iUnion_null_iff, inter_comm s, Function.onFun] using fun g (hg : g ≠ 1) => hs.aedisjoint hg @[to_additive MeasureTheory.IsAddFundamentalDomain.measure_addFundamentalInterior] theorem measure_fundamentalInterior : μ (fundamentalInterior G s) = μ s := measure_diff_null' hs.measure_fundamentalFrontier end Group variable [MeasurableSpace G] [MeasurableSMul G α] [SMulInvariantMeasure G α μ] protected theorem fundamentalInterior : IsFundamentalDomain G (fundamentalInterior G s) μ where nullMeasurableSet := hs.nullMeasurableSet.fundamentalInterior _ _ ae_covers := by simp_rw [ae_iff, not_exists, ← mem_inv_smul_set_iff, setOf_forall, ← compl_setOf, setOf_mem_eq, ← compl_iUnion] have : ((⋃ g : G, g⁻¹ • s) \ ⋃ g : G, g⁻¹ • fundamentalFrontier G s) ⊆ ⋃ g : G, g⁻¹ • fundamentalInterior G s := by simp_rw [diff_subset_iff, ← iUnion_union_distrib, ← smul_set_union (α := G) (β := α), fundamentalFrontier_union_fundamentalInterior]; rfl refine eq_bot_mono (μ.mono <| compl_subset_compl.2 this) ?_ simp only [iUnion_inv_smul, compl_sdiff, ENNReal.bot_eq_zero, himp_eq, sup_eq_union, @iUnion_smul_eq_setOf_exists _ _ _ _ s] exact measure_union_null (measure_iUnion_null fun _ => measure_smul_null hs.measure_fundamentalFrontier _) hs.ae_covers aedisjoint := (pairwise_disjoint_fundamentalInterior _ _).mono fun _ _ => Disjoint.aedisjoint end IsFundamentalDomain section FundamentalDomainMeasure variable (G) [Group G] [MulAction G α] [MeasurableSpace α] (μ : Measure α) local notation "α_mod_G" => MulAction.orbitRel G α local notation "π" => @Quotient.mk _ α_mod_G variable {G} @[to_additive addMeasure_map_restrict_apply] lemma measure_map_restrict_apply (s : Set α) {U : Set (Quotient α_mod_G)} (meas_U : MeasurableSet U) : (μ.restrict s).map π U = μ ((π ⁻¹' U) ∩ s) := by rw [map_apply (f := π) (fun V hV ↦ measurableSet_quotient.mp hV) meas_U, Measure.restrict_apply (t := (Quotient.mk α_mod_G ⁻¹' U)) (measurableSet_quotient.mp meas_U)] @[to_additive] lemma IsFundamentalDomain.quotientMeasure_eq [Countable G] [MeasurableSpace G] {s t : Set α} [SMulInvariantMeasure G α μ] [MeasurableSMul G α] (fund_dom_s : IsFundamentalDomain G s μ) (fund_dom_t : IsFundamentalDomain G t μ) : (μ.restrict s).map π = (μ.restrict t).map π := by ext U meas_U rw [measure_map_restrict_apply (meas_U := meas_U), measure_map_restrict_apply (meas_U := meas_U)] apply MeasureTheory.IsFundamentalDomain.measure_set_eq fund_dom_s fund_dom_t · exact measurableSet_quotient.mp meas_U · intro g ext x have : Quotient.mk α_mod_G (g • x) = Quotient.mk α_mod_G x := by apply Quotient.sound use g simp only [mem_preimage, this] end FundamentalDomainMeasure /-! ## `HasFundamentalDomain` typeclass We define `HasFundamentalDomain` in order to be able to define the `covolume` of a quotient of `α` by a group `G`, which under reasonable conditions does not depend on the choice of fundamental domain. Even though any "sensible" action should have a fundamental domain, this is a rather delicate question which was recently addressed by Misha Kapovich: https://arxiv.org/abs/2301.05325 TODO: Formalize the existence of a Dirichlet domain as in Kapovich's paper. -/ section HasFundamentalDomain /-- We say a quotient of `α` by `G` `HasAddFundamentalDomain` if there is a measurable set `s` for which `IsAddFundamentalDomain G s` holds. -/ class HasAddFundamentalDomain (G α : Type*) [Zero G] [VAdd G α] [MeasurableSpace α] (ν : Measure α := by volume_tac) : Prop where ExistsIsAddFundamentalDomain : ∃ s : Set α, IsAddFundamentalDomain G s ν /-- We say a quotient of `α` by `G` `HasFundamentalDomain` if there is a measurable set `s` for which `IsFundamentalDomain G s` holds. -/ class HasFundamentalDomain (G : Type*) (α : Type*) [One G] [SMul G α] [MeasurableSpace α] (ν : Measure α := by volume_tac) : Prop where ExistsIsFundamentalDomain : ∃ (s : Set α), IsFundamentalDomain G s ν attribute [to_additive existing] MeasureTheory.HasFundamentalDomain open Classical in /-- The `covolume` of an action of `G` on `α` the volume of some fundamental domain, or `0` if none exists. -/ @[to_additive addCovolume "The `addCovolume` of an action of `G` on `α` is the volume of some fundamental domain, or `0` if none exists."] noncomputable def covolume (G α : Type*) [One G] [SMul G α] [MeasurableSpace α] (ν : Measure α := by volume_tac) : ℝ≥0∞ := if funDom : HasFundamentalDomain G α ν then ν funDom.ExistsIsFundamentalDomain.choose else 0 variable [Group G] [MulAction G α] [MeasurableSpace α] /-- If there is a fundamental domain `s`, then `HasFundamentalDomain` holds. -/ @[to_additive] lemma IsFundamentalDomain.hasFundamentalDomain (ν : Measure α) {s : Set α} (fund_dom_s : IsFundamentalDomain G s ν) : HasFundamentalDomain G α ν := ⟨⟨s, fund_dom_s⟩⟩ /-- The `covolume` can be computed by taking the `volume` of any given fundamental domain `s`. -/ @[to_additive] lemma IsFundamentalDomain.covolume_eq_volume (ν : Measure α) [Countable G] [MeasurableSpace G] [MeasurableSMul G α] [SMulInvariantMeasure G α ν] {s : Set α} (fund_dom_s : IsFundamentalDomain G s ν) : covolume G α ν = ν s := by dsimp [covolume] simp only [(fund_dom_s.hasFundamentalDomain ν), ↓reduceDIte] rw [fund_dom_s.measure_eq] exact (fund_dom_s.hasFundamentalDomain ν).ExistsIsFundamentalDomain.choose_spec end HasFundamentalDomain /-! ## `QuotientMeasureEqMeasurePreimage` typeclass This typeclass describes a situation in which a measure `μ` on `α ⧸ G` can be computed by taking a measure `ν` on `α` of the intersection of the pullback with a fundamental domain. It's curious that in measure theory, measures can be pushed forward, while in geometry, volumes can be pulled back. And yet here, we are describing a situation involving measures in a geometric way. Another viewpoint is that if a set is small enough to fit in a single fundamental domain, then its `ν` measure in `α` is the same as the `μ` measure of its pushforward in `α ⧸ G`. -/ section QuotientMeasureEqMeasurePreimage section additive variable [AddGroup G] [AddAction G α] [MeasurableSpace α]
local notation "α_mod_G" => AddAction.orbitRel G α local notation "π" => @Quotient.mk _ α_mod_G /-- A measure `μ` on the `AddQuotient` of `α` mod `G` satisfies `AddQuotientMeasureEqMeasurePreimage` if: for any fundamental domain `t`, and any measurable subset `U` of the quotient, `μ U = volume ((π ⁻¹' U) ∩ t)`. -/ class AddQuotientMeasureEqMeasurePreimage (ν : Measure α := by volume_tac) (μ : Measure (Quotient α_mod_G)) : Prop where addProjection_respects_measure' : ∀ (t : Set α) (_ : IsAddFundamentalDomain G t ν), μ = (ν.restrict t).map π end additive variable [Group G] [MulAction G α] [MeasurableSpace α]
Mathlib/MeasureTheory/Group/FundamentalDomain.lean
728
743
/- Copyright (c) 2021 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Ring.Regular import Mathlib.GroupTheory.MonoidLocalization.Away import Mathlib.RingTheory.Localization.Defs import Mathlib.SetTheory.Game.Birthday import Mathlib.SetTheory.Surreal.Multiplication import Mathlib.Tactic.Linarith /-! # Dyadic numbers Dyadic numbers are obtained by localizing ℤ away from 2. They are the initial object in the category of rings with no 2-torsion. ## Dyadic surreal numbers We construct dyadic surreal numbers using the canonical map from ℤ[2 ^ {-1}] to surreals. As we currently do not have a ring structure on `Surreal` we construct this map explicitly. Once we have the ring structure, this map can be constructed directly by sending `2 ^ {-1}` to `half`. ## Embeddings The above construction gives us an abelian group embedding of ℤ into `Surreal`. The goal is to extend this to an embedding of dyadic rationals into `Surreal` and use Cauchy sequences of dyadic rational numbers to construct an ordered field embedding of ℝ into `Surreal`. -/ universe u namespace SetTheory namespace PGame /-- For a natural number `n`, the pre-game `powHalf (n + 1)` is recursively defined as `{0 | powHalf n}`. These are the explicit expressions of powers of `1 / 2`. By definition, we have `powHalf 0 = 1` and `powHalf 1 ≈ 1 / 2` and we prove later on that `powHalf (n + 1) + powHalf (n + 1) ≈ powHalf n`. -/ def powHalf : ℕ → PGame | 0 => 1 | n + 1 => ⟨PUnit, PUnit, 0, fun _ => powHalf n⟩ @[simp] theorem powHalf_zero : powHalf 0 = 1 := rfl theorem powHalf_leftMoves (n) : (powHalf n).LeftMoves = PUnit := by cases n <;> rfl theorem powHalf_zero_rightMoves : (powHalf 0).RightMoves = PEmpty := rfl theorem powHalf_succ_rightMoves (n) : (powHalf (n + 1)).RightMoves = PUnit := rfl @[simp] theorem powHalf_moveLeft (n i) : (powHalf n).moveLeft i = 0 := by cases n <;> cases i <;> rfl @[simp] theorem powHalf_succ_moveRight (n i) : (powHalf (n + 1)).moveRight i = powHalf n := rfl instance uniquePowHalfLeftMoves (n) : Unique (powHalf n).LeftMoves := by cases n <;> exact PUnit.instUnique instance isEmpty_powHalf_zero_rightMoves : IsEmpty (powHalf 0).RightMoves := inferInstanceAs (IsEmpty PEmpty) instance uniquePowHalfSuccRightMoves (n) : Unique (powHalf (n + 1)).RightMoves := PUnit.instUnique @[simp] theorem birthday_half : birthday (powHalf 1) = 2 := by rw [birthday_def]; simp /-- For all natural numbers `n`, the pre-games `powHalf n` are numeric. -/ theorem numeric_powHalf (n) : (powHalf n).Numeric := by induction n with | zero => exact numeric_one | succ n hn => constructor · simpa using hn.moveLeft_lt default · exact ⟨fun _ => numeric_zero, fun _ => hn⟩ theorem powHalf_succ_lt_powHalf (n : ℕ) : powHalf (n + 1) < powHalf n := (numeric_powHalf (n + 1)).lt_moveRight default theorem powHalf_succ_le_powHalf (n : ℕ) : powHalf (n + 1) ≤ powHalf n := (powHalf_succ_lt_powHalf n).le theorem powHalf_le_one (n : ℕ) : powHalf n ≤ 1 := by induction n with | zero => exact le_rfl | succ n hn => exact (powHalf_succ_le_powHalf n).trans hn theorem powHalf_succ_lt_one (n : ℕ) : powHalf (n + 1) < 1 := (powHalf_succ_lt_powHalf n).trans_le <| powHalf_le_one n theorem powHalf_pos (n : ℕ) : 0 < powHalf n := by rw [← lf_iff_lt numeric_zero (numeric_powHalf n), zero_lf_le]; simp theorem zero_le_powHalf (n : ℕ) : 0 ≤ powHalf n := (powHalf_pos n).le
theorem add_powHalf_succ_self_eq_powHalf (n) : powHalf (n + 1) + powHalf (n + 1) ≈ powHalf n := by induction' n using Nat.strong_induction_on with n hn constructor <;> rw [le_iff_forall_lf] <;> constructor
Mathlib/SetTheory/Surreal/Dyadic.lean
106
109
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Kexing Ying -/ import Mathlib.Probability.Notation import Mathlib.Probability.Process.Stopping /-! # Martingales A family of functions `f : ι → Ω → E` is a martingale with respect to a filtration `ℱ` if every `f i` is integrable, `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] =ᵐ[μ] f i`. On the other hand, `f : ι → Ω → E` is said to be a supermartingale with respect to the filtration `ℱ` if `f i` is integrable, `f` is adapted with resepct to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] ≤ᵐ[μ] f i`. Finally, `f : ι → Ω → E` is said to be a submartingale with respect to the filtration `ℱ` if `f i` is integrable, `f` is adapted with resepct to `ℱ` and for all `i ≤ j`, `f i ≤ᵐ[μ] μ[f j | ℱ i]`. The definitions of filtration and adapted can be found in `Probability.Process.Stopping`. ### Definitions * `MeasureTheory.Martingale f ℱ μ`: `f` is a martingale with respect to filtration `ℱ` and measure `μ`. * `MeasureTheory.Supermartingale f ℱ μ`: `f` is a supermartingale with respect to filtration `ℱ` and measure `μ`. * `MeasureTheory.Submartingale f ℱ μ`: `f` is a submartingale with respect to filtration `ℱ` and measure `μ`. ### Results * `MeasureTheory.martingale_condExp f ℱ μ`: the sequence `fun i => μ[f | ℱ i, ℱ.le i])` is a martingale with respect to `ℱ` and `μ`. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory variable {Ω E ι : Type*} [Preorder ι] {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f g : ι → Ω → E} {ℱ : Filtration ι m0} /-- A family of functions `f : ι → Ω → E` is a martingale with respect to a filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ i] =ᵐ[μ] f i`. -/ def Martingale (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop := Adapted ℱ f ∧ ∀ i j, i ≤ j → μ[f j|ℱ i] =ᵐ[μ] f i /-- A family of integrable functions `f : ι → Ω → E` is a supermartingale with respect to a filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `μ[f j | ℱ.le i] ≤ᵐ[μ] f i`. -/ def Supermartingale [LE E] (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop := Adapted ℱ f ∧ (∀ i j, i ≤ j → μ[f j|ℱ i] ≤ᵐ[μ] f i) ∧ ∀ i, Integrable (f i) μ /-- A family of integrable functions `f : ι → Ω → E` is a submartingale with respect to a filtration `ℱ` if `f` is adapted with respect to `ℱ` and for all `i ≤ j`, `f i ≤ᵐ[μ] μ[f j | ℱ.le i]`. -/ def Submartingale [LE E] (f : ι → Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) : Prop := Adapted ℱ f ∧ (∀ i j, i ≤ j → f i ≤ᵐ[μ] μ[f j|ℱ i]) ∧ ∀ i, Integrable (f i) μ theorem martingale_const (ℱ : Filtration ι m0) (μ : Measure Ω) [IsFiniteMeasure μ] (x : E) : Martingale (fun _ _ => x) ℱ μ := ⟨adapted_const ℱ _, fun i j _ => by rw [condExp_const (ℱ.le _)]⟩ theorem martingale_const_fun [OrderBot ι] (ℱ : Filtration ι m0) (μ : Measure Ω) [IsFiniteMeasure μ] {f : Ω → E} (hf : StronglyMeasurable[ℱ ⊥] f) (hfint : Integrable f μ) : Martingale (fun _ => f) ℱ μ := by refine ⟨fun i => hf.mono <| ℱ.mono bot_le, fun i j _ => ?_⟩ rw [condExp_of_stronglyMeasurable (ℱ.le _) (hf.mono <| ℱ.mono bot_le) hfint] variable (E) in theorem martingale_zero (ℱ : Filtration ι m0) (μ : Measure Ω) : Martingale (0 : ι → Ω → E) ℱ μ := ⟨adapted_zero E ℱ, fun i j _ => by rw [Pi.zero_apply, condExp_zero]; simp⟩ namespace Martingale protected theorem adapted (hf : Martingale f ℱ μ) : Adapted ℱ f := hf.1 protected theorem stronglyMeasurable (hf : Martingale f ℱ μ) (i : ι) : StronglyMeasurable[ℱ i] (f i) := hf.adapted i theorem condExp_ae_eq (hf : Martingale f ℱ μ) {i j : ι} (hij : i ≤ j) : μ[f j|ℱ i] =ᵐ[μ] f i := hf.2 i j hij @[deprecated (since := "2025-01-21")] alias condexp_ae_eq := condExp_ae_eq protected theorem integrable (hf : Martingale f ℱ μ) (i : ι) : Integrable (f i) μ := integrable_condExp.congr (hf.condExp_ae_eq (le_refl i)) theorem setIntegral_eq [SigmaFiniteFiltration μ ℱ] (hf : Martingale f ℱ μ) {i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f i ω ∂μ = ∫ ω in s, f j ω ∂μ := by rw [← setIntegral_condExp (ℱ.le i) (hf.integrable j) hs] refine setIntegral_congr_ae (ℱ.le i s hs) ?_ filter_upwards [hf.2 i j hij] with _ heq _ using heq.symm theorem add (hf : Martingale f ℱ μ) (hg : Martingale g ℱ μ) : Martingale (f + g) ℱ μ := by refine ⟨hf.adapted.add hg.adapted, fun i j hij => ?_⟩ exact (condExp_add (hf.integrable j) (hg.integrable j) _).trans ((hf.2 i j hij).add (hg.2 i j hij)) theorem neg (hf : Martingale f ℱ μ) : Martingale (-f) ℱ μ := ⟨hf.adapted.neg, fun i j hij => (condExp_neg ..).trans (hf.2 i j hij).neg⟩ theorem sub (hf : Martingale f ℱ μ) (hg : Martingale g ℱ μ) : Martingale (f - g) ℱ μ := by rw [sub_eq_add_neg]; exact hf.add hg.neg theorem smul (c : ℝ) (hf : Martingale f ℱ μ) : Martingale (c • f) ℱ μ := by refine ⟨hf.adapted.smul c, fun i j hij => ?_⟩ refine (condExp_smul ..).trans ((hf.2 i j hij).mono fun x hx => ?_) simp only [Pi.smul_apply, hx] theorem supermartingale [Preorder E] (hf : Martingale f ℱ μ) : Supermartingale f ℱ μ := ⟨hf.1, fun i j hij => (hf.2 i j hij).le, fun i => hf.integrable i⟩ theorem submartingale [Preorder E] (hf : Martingale f ℱ μ) : Submartingale f ℱ μ := ⟨hf.1, fun i j hij => (hf.2 i j hij).symm.le, fun i => hf.integrable i⟩ end Martingale theorem martingale_iff [PartialOrder E] : Martingale f ℱ μ ↔ Supermartingale f ℱ μ ∧ Submartingale f ℱ μ := ⟨fun hf => ⟨hf.supermartingale, hf.submartingale⟩, fun ⟨hf₁, hf₂⟩ => ⟨hf₁.1, fun i j hij => (hf₁.2.1 i j hij).antisymm (hf₂.2.1 i j hij)⟩⟩ theorem martingale_condExp (f : Ω → E) (ℱ : Filtration ι m0) (μ : Measure Ω) [SigmaFiniteFiltration μ ℱ] : Martingale (fun i => μ[f|ℱ i]) ℱ μ := ⟨fun _ => stronglyMeasurable_condExp, fun _ j hij => condExp_condExp_of_le (ℱ.mono hij) (ℱ.le j)⟩ @[deprecated (since := "2025-01-21")] alias martingale_condexp := martingale_condExp namespace Supermartingale protected theorem adapted [LE E] (hf : Supermartingale f ℱ μ) : Adapted ℱ f := hf.1 protected theorem stronglyMeasurable [LE E] (hf : Supermartingale f ℱ μ) (i : ι) : StronglyMeasurable[ℱ i] (f i) := hf.adapted i protected theorem integrable [LE E] (hf : Supermartingale f ℱ μ) (i : ι) : Integrable (f i) μ := hf.2.2 i theorem condExp_ae_le [LE E] (hf : Supermartingale f ℱ μ) {i j : ι} (hij : i ≤ j) : μ[f j|ℱ i] ≤ᵐ[μ] f i := hf.2.1 i j hij @[deprecated (since := "2025-01-21")] alias condexp_ae_le := condExp_ae_le theorem setIntegral_le [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} (hf : Supermartingale f ℱ μ) {i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f j ω ∂μ ≤ ∫ ω in s, f i ω ∂μ := by rw [← setIntegral_condExp (ℱ.le i) (hf.integrable j) hs] refine setIntegral_mono_ae integrable_condExp.integrableOn (hf.integrable i).integrableOn ?_ filter_upwards [hf.2.1 i j hij] with _ heq using heq theorem add [Preorder E] [AddLeftMono E] (hf : Supermartingale f ℱ μ) (hg : Supermartingale g ℱ μ) : Supermartingale (f + g) ℱ μ := by refine ⟨hf.1.add hg.1, fun i j hij => ?_, fun i => (hf.2.2 i).add (hg.2.2 i)⟩ refine (condExp_add (hf.integrable j) (hg.integrable j) _).le.trans ?_ filter_upwards [hf.2.1 i j hij, hg.2.1 i j hij] intros refine add_le_add ?_ ?_ <;> assumption theorem add_martingale [Preorder E] [AddLeftMono E] (hf : Supermartingale f ℱ μ) (hg : Martingale g ℱ μ) : Supermartingale (f + g) ℱ μ := hf.add hg.supermartingale theorem neg [Preorder E] [AddLeftMono E] (hf : Supermartingale f ℱ μ) : Submartingale (-f) ℱ μ := by refine ⟨hf.1.neg, fun i j hij => ?_, fun i => (hf.2.2 i).neg⟩ refine EventuallyLE.trans ?_ (condExp_neg ..).symm.le filter_upwards [hf.2.1 i j hij] with _ _ simpa end Supermartingale namespace Submartingale protected theorem adapted [LE E] (hf : Submartingale f ℱ μ) : Adapted ℱ f := hf.1 protected theorem stronglyMeasurable [LE E] (hf : Submartingale f ℱ μ) (i : ι) : StronglyMeasurable[ℱ i] (f i) := hf.adapted i protected theorem integrable [LE E] (hf : Submartingale f ℱ μ) (i : ι) : Integrable (f i) μ := hf.2.2 i theorem ae_le_condExp [LE E] (hf : Submartingale f ℱ μ) {i j : ι} (hij : i ≤ j) : f i ≤ᵐ[μ] μ[f j|ℱ i] := hf.2.1 i j hij @[deprecated (since := "2025-01-21")] alias ae_le_condexp := ae_le_condExp theorem add [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ) (hg : Submartingale g ℱ μ) : Submartingale (f + g) ℱ μ := by refine ⟨hf.1.add hg.1, fun i j hij => ?_, fun i => (hf.2.2 i).add (hg.2.2 i)⟩ refine EventuallyLE.trans ?_ (condExp_add (hf.integrable j) (hg.integrable j) _).symm.le filter_upwards [hf.2.1 i j hij, hg.2.1 i j hij] intros refine add_le_add ?_ ?_ <;> assumption theorem add_martingale [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ) (hg : Martingale g ℱ μ) : Submartingale (f + g) ℱ μ := hf.add hg.submartingale theorem neg [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ) : Supermartingale (-f) ℱ μ := by refine ⟨hf.1.neg, fun i j hij => (condExp_neg ..).le.trans ?_, fun i => (hf.2.2 i).neg⟩ filter_upwards [hf.2.1 i j hij] with _ _ simpa /-- The converse of this lemma is `MeasureTheory.submartingale_of_setIntegral_le`. -/ theorem setIntegral_le [SigmaFiniteFiltration μ ℱ] {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) {i j : ι} (hij : i ≤ j) {s : Set Ω} (hs : MeasurableSet[ℱ i] s) : ∫ ω in s, f i ω ∂μ ≤ ∫ ω in s, f j ω ∂μ := by rw [← neg_le_neg_iff, ← integral_neg, ← integral_neg] exact Supermartingale.setIntegral_le hf.neg hij hs theorem sub_supermartingale [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ) (hg : Supermartingale g ℱ μ) : Submartingale (f - g) ℱ μ := by rw [sub_eq_add_neg]; exact hf.add hg.neg theorem sub_martingale [Preorder E] [AddLeftMono E] (hf : Submartingale f ℱ μ) (hg : Martingale g ℱ μ) : Submartingale (f - g) ℱ μ := hf.sub_supermartingale hg.supermartingale protected theorem sup {f g : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) (hg : Submartingale g ℱ μ) : Submartingale (f ⊔ g) ℱ μ := by refine ⟨fun i => @StronglyMeasurable.sup _ _ _ _ (ℱ i) _ _ _ (hf.adapted i) (hg.adapted i), fun i j hij => ?_, fun i => Integrable.sup (hf.integrable _) (hg.integrable _)⟩ refine EventuallyLE.sup_le ?_ ?_ · exact EventuallyLE.trans (hf.2.1 i j hij) (condExp_mono (hf.integrable _) (Integrable.sup (hf.integrable j) (hg.integrable j)) (Eventually.of_forall fun x => le_max_left _ _)) · exact EventuallyLE.trans (hg.2.1 i j hij) (condExp_mono (hg.integrable _) (Integrable.sup (hf.integrable j) (hg.integrable j)) (Eventually.of_forall fun x => le_max_right _ _)) protected theorem pos {f : ι → Ω → ℝ} (hf : Submartingale f ℱ μ) : Submartingale (f⁺) ℱ μ := hf.sup (martingale_zero _ _ _).submartingale
end Submartingale section Submartingale
Mathlib/Probability/Martingale/Basic.lean
248
252
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # Lindelöf sets and Lindelöf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is Lindelöf if it is Lindelöf as a set. * `NonLindelofSpace`: a space that is not a Lindëlof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is Lindelöf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is Lindelöf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := ∀ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≤ 𝓟 s → ∃ x ∈ s, ClusterPt x f /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact hs inf_le_right /-- The complement to a Lindelöf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a Lindelöf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X → Prop} (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, p s) → p (⋃₀ S)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a Lindelöf set and a closed set is a Lindelöf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a Lindelöf set and an open set is a Lindelöf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t ⊆ s) : IsLindelof t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht /-- A continuous image of a Lindelöf set is a Lindelöf set. -/ theorem IsLindelof.image_of_continuousOn {f : X → Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a Lindelöf set is a Lindelöf set within the codomain. -/ theorem IsLindelof.image {f : X → Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a Lindelöf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f ⊓ 𝓟 tᶜ) _ _ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ι : Type v} (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i) := by have hmono : ∀ ⦃s t : Set X⦄, s ⊆ t → (∃ r : Set ι, r.Countable ∧ t ⊆ ⋃ i ∈ r, U i) → (∃ r : Set ι, r.Countable ∧ s ⊆ ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : ∀ (S : Set (Set X)), S.Countable → (∀ s ∈ S, ∃ r : Set ι, r.Countable ∧ (s ⊆ ⋃ i ∈ r, U i)) → ∃ r : Set ι, r.Countable ∧ (⋃₀ S ⊆ ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine ⟨⋃ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∃ r : Set ι, r.Countable ∧ (t ⊆ ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Set s, t.Countable ∧ s ⊆ ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnion₂_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Set X, t.Countable ∧ (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine ⟨↑t, Countable.image htc Subtype.val, ?_⟩ constructor · intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto · have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- For every nonempty open cover of a Lindelöf set, there exists a subcover indexed by ℕ. -/ theorem IsLindelof.indexed_countable_subcover {ι : Type v} [Nonempty ι] (hs : IsLindelof s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ f : ℕ → ι, s ⊆ ⋃ n, U (f n) := by obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU rcases c.eq_empty_or_nonempty with rfl | c_nonempty · simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const] obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count refine ⟨fun x ↦ f x, c_cov.trans <| iUnion₂_subset_iff.mpr (?_ : ∀ i ∈ c, U i ⊆ ⋃ n, U (f n))⟩ intro x hx obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩ exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn]) /-- The neighborhood filter of a Lindelöf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi)) /-- A filter `l` with the countable intersection property is disjoint with the neighborhood filter of a Lindelöf set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left /-- For every family of closed sets whose intersection avoids a Lindelö set, there exists a countable subfamily whose intersection avoids this Lindelöf set. -/ theorem IsLindelof.elim_countable_subfamily_closed {ι : Type v} (hs : IsLindelof s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := by let U := tᶜ have hUo : ∀ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc have hsU : s ⊆ ⋃ i, U i := by simp only [U, Pi.compl_apply] rw [← compl_iInter] apply disjoint_compl_left_iff_subset.mp simp only [compl_iInter, compl_iUnion, compl_compl] apply Disjoint.symm exact disjoint_iff_inter_eq_empty.mpr hst rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩ use u, hucount rw [← disjoint_compl_left_iff_subset] at husub simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub) /-- To show that a Lindelöf set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every countable subfamily. -/ theorem IsLindelof.inter_iInter_nonempty {ι : Type v} (hs : IsLindelof s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩ exact ⟨u, fun _ ↦ husub⟩ /-- For every open cover of a Lindelöf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsLindelof s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Countable b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_countable_subcover (fun i ↦ c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d, by simp, Countable.image hd.1 Subtype.val, ?_⟩ rw [biUnion_image] exact hd.2 /-- A set `s` is Lindelöf if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_of_countable_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i) : IsLindelof s := fun f hf hfs ↦ by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose fsub U hU hUf using h refine ⟨s, U, fun x ↦ (hU x).2, fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1 ⟩, ?_⟩ intro t ht h have uinf := f.sets_of_superset (le_principal_iff.1 fsub) h have uninf : ⋂ i ∈ t, (U i)ᶜ ∈ f := (countable_bInter_mem ht).mpr (fun _ _ ↦ hUf _) rw [← compl_iUnion₂] at uninf have uninf := compl_not_mem uninf simp only [compl_compl] at uninf contradiction /-- A set `s` is Lindelöf if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_of_countable_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅) : IsLindelof s := isLindelof_of_countable_subcover fun U hUo hsU ↦ by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i ↦ (U i)ᶜ) (fun i ↦ (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] /-- A set `s` is Lindelöf if and only if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_iff_countable_subcover : IsLindelof s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Set ι, t.Countable ∧ s ⊆ ⋃ i ∈ t, U i := ⟨fun hs ↦ hs.elim_countable_subcover, isLindelof_of_countable_subcover⟩ /-- A set `s` is Lindelöf if and only if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_iff_countable_subfamily_closed : IsLindelof s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Set ι, u.Countable ∧ (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs ↦ hs.elim_countable_subfamily_closed, isLindelof_of_countable_subfamily_closed⟩ /-- The empty set is a Lindelof set. -/ @[simp] theorem isLindelof_empty : IsLindelof (∅ : Set X) := fun _f hnf _ hsf ↦ Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf /-- A singleton set is a Lindelof set. -/ @[simp] theorem isLindelof_singleton {x : X} : IsLindelof ({x} : Set X) := fun _ hf _ hfa ↦ ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ theorem Set.Subsingleton.isLindelof (hs : s.Subsingleton) : IsLindelof s := Subsingleton.induction_on hs isLindelof_empty fun _ ↦ isLindelof_singleton theorem Set.Countable.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Countable) (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := by apply isLindelof_of_countable_subcover intro i U hU hUcover have hiU : ∀ i ∈ s, f i ⊆ ⋃ i, U i := fun _ is ↦ _root_.subset_trans (subset_biUnion_of_mem is) hUcover have iSets := fun i is ↦ (hf i is).elim_countable_subcover U hU (hiU i is) choose! r hr using iSets use ⋃ i ∈ s, r i constructor · refine (Countable.biUnion_iff hs).mpr ?h.left.a exact fun s hs ↦ (hr s hs).1 · refine iUnion₂_subset ?h.right.h intro i is simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] intro x hx exact mem_biUnion is ((hr i is).2 hx) theorem Set.Finite.isLindelof_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := Set.Countable.isLindelof_biUnion (countable hs) hf theorem Finset.isLindelof_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := s.finite_toSet.isLindelof_biUnion hf theorem isLindelof_accumulate {K : ℕ → Set X} (hK : ∀ n, IsLindelof (K n)) (n : ℕ) : IsLindelof (Accumulate K n) := (finite_le_nat n).isLindelof_biUnion fun k _ => hK k theorem Set.Countable.isLindelof_sUnion {S : Set (Set X)} (hf : S.Countable) (hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem Set.Finite.isLindelof_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem isLindelof_iUnion {ι : Sort*} {f : ι → Set X} [Countable ι] (h : ∀ i, IsLindelof (f i)) : IsLindelof (⋃ i, f i) := (countable_range f).isLindelof_sUnion <| forall_mem_range.2 h theorem Set.Countable.isLindelof (hs : s.Countable) : IsLindelof s := biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem Set.Finite.isLindelof (hs : s.Finite) : IsLindelof s := biUnion_of_singleton s ▸ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem IsLindelof.countable_of_discrete [DiscreteTopology X] (hs : IsLindelof s) : s.Countable := by have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, ht, _, hssubt⟩ rw [biUnion_of_singleton] at hssubt exact ht.mono hssubt theorem isLindelof_iff_countable [DiscreteTopology X] : IsLindelof s ↔ s.Countable := ⟨fun h => h.countable_of_discrete, fun h => h.isLindelof⟩ theorem IsLindelof.union (hs : IsLindelof s) (ht : IsLindelof t) : IsLindelof (s ∪ t) := by rw [union_eq_iUnion]; exact isLindelof_iUnion fun b => by cases b <;> assumption protected theorem IsLindelof.insert (hs : IsLindelof s) (a) : IsLindelof (insert a s) := isLindelof_singleton.union hs /-- If `X` has a basis consisting of compact opens, then an open set in `X` is compact open iff it is a finite union of some elements in the basis -/ theorem isLindelof_open_iff_eq_countable_iUnion_of_isTopologicalBasis (b : ι → Set X) (hb : IsTopologicalBasis (Set.range b)) (hb' : ∀ i, IsLindelof (b i)) (U : Set X) : IsLindelof U ∧ IsOpen U ↔ ∃ s : Set ι, s.Countable ∧ U = ⋃ i ∈ s, b i := by constructor · rintro ⟨h₁, h₂⟩ obtain ⟨Y, f, rfl, hf⟩ := hb.open_eq_iUnion h₂ choose f' hf' using hf have : b ∘ f' = f := funext hf' subst this obtain ⟨t, ht⟩ := h₁.elim_countable_subcover (b ∘ f') (fun i => hb.isOpen (Set.mem_range_self _)) Subset.rfl refine ⟨t.image f', Countable.image (ht.1) f', le_antisymm ?_ ?_⟩ · refine Set.Subset.trans ht.2 ?_ simp only [Set.iUnion_subset_iff] intro i hi rw [← Set.iUnion_subtype (fun x : ι => x ∈ t.image f') fun i => b i.1] exact Set.subset_iUnion (fun i : t.image f' => b i) ⟨_, mem_image_of_mem _ hi⟩ · apply Set.iUnion₂_subset rintro i hi obtain ⟨j, -, rfl⟩ := (mem_image ..).mp hi exact Set.subset_iUnion (b ∘ f') j · rintro ⟨s, hs, rfl⟩ constructor · exact hs.isLindelof_biUnion fun i _ => hb' i · exact isOpen_biUnion fun i _ => hb.isOpen (Set.mem_range_self _) /-- `Filter.coLindelof` is the filter generated by complements to Lindelöf sets. -/ def Filter.coLindelof (X : Type*) [TopologicalSpace X] : Filter X := --`Filter.coLindelof` is the filter generated by complements to Lindelöf sets. ⨅ (s : Set X) (_ : IsLindelof s), 𝓟 sᶜ theorem hasBasis_coLindelof : (coLindelof X).HasBasis IsLindelof compl := hasBasis_biInf_principal' (fun s hs t ht => ⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩) ⟨∅, isLindelof_empty⟩ theorem mem_coLindelof : s ∈ coLindelof X ↔ ∃ t, IsLindelof t ∧ tᶜ ⊆ s := hasBasis_coLindelof.mem_iff theorem mem_coLindelof' : s ∈ coLindelof X ↔ ∃ t, IsLindelof t ∧ sᶜ ⊆ t := mem_coLindelof.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm theorem _root_.IsLindelof.compl_mem_coLindelof (hs : IsLindelof s) : sᶜ ∈ coLindelof X := hasBasis_coLindelof.mem_of_mem hs theorem coLindelof_le_cofinite : coLindelof X ≤ cofinite := fun s hs => compl_compl s ▸ hs.isLindelof.compl_mem_coLindelof theorem Tendsto.isLindelof_insert_range_of_coLindelof {f : X → Y} {y} (hf : Tendsto f (coLindelof X) (𝓝 y)) (hfc : Continuous f) : IsLindelof (insert y (range f)) := by intro l hne _ hle by_cases hy : ClusterPt y l · exact ⟨y, Or.inl rfl, hy⟩ simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy rcases hy with ⟨s, hsy, t, htl, hd⟩ rcases mem_coLindelof.1 (hf hsy) with ⟨K, hKc, hKs⟩ have : f '' K ∈ l := by filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf rcases hyf with (rfl | ⟨x, rfl⟩) exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim, mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)] rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩ exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩ /-- `Filter.coclosedLindelof` is the filter generated by complements to closed Lindelof sets. -/ def Filter.coclosedLindelof (X : Type*) [TopologicalSpace X] : Filter X := -- `Filter.coclosedLindelof` is the filter generated by complements to closed Lindelof sets. ⨅ (s : Set X) (_ : IsClosed s) (_ : IsLindelof s), 𝓟 sᶜ theorem hasBasis_coclosedLindelof : (Filter.coclosedLindelof X).HasBasis (fun s => IsClosed s ∧ IsLindelof s) compl := by simp only [Filter.coclosedLindelof, iInf_and'] refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isLindelof_empty⟩ rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩ exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩⟩ theorem mem_coclosedLindelof : s ∈ coclosedLindelof X ↔ ∃ t, IsClosed t ∧ IsLindelof t ∧ tᶜ ⊆ s := by simp only [hasBasis_coclosedLindelof.mem_iff, and_assoc] theorem mem_coclosed_Lindelof' : s ∈ coclosedLindelof X ↔ ∃ t, IsClosed t ∧ IsLindelof t ∧ sᶜ ⊆ t := by simp only [mem_coclosedLindelof, compl_subset_comm] theorem coLindelof_le_coclosedLindelof : coLindelof X ≤ coclosedLindelof X := iInf_mono fun _ => le_iInf fun _ => le_rfl theorem IsLindeof.compl_mem_coclosedLindelof_of_isClosed (hs : IsLindelof s) (hs' : IsClosed s) : sᶜ ∈ Filter.coclosedLindelof X := hasBasis_coclosedLindelof.mem_of_mem ⟨hs', hs⟩ /-- X is a Lindelöf space iff every open cover has a countable subcover. -/ class LindelofSpace (X : Type*) [TopologicalSpace X] : Prop where /-- In a Lindelöf space, `Set.univ` is a Lindelöf set. -/ isLindelof_univ : IsLindelof (univ : Set X) instance (priority := 10) Subsingleton.lindelofSpace [Subsingleton X] : LindelofSpace X := ⟨subsingleton_univ.isLindelof⟩ theorem isLindelof_univ_iff : IsLindelof (univ : Set X) ↔ LindelofSpace X := ⟨fun h => ⟨h⟩, fun h => h.1⟩ theorem isLindelof_univ [h : LindelofSpace X] : IsLindelof (univ : Set X) := h.isLindelof_univ theorem cluster_point_of_Lindelof [LindelofSpace X] (f : Filter X) [NeBot f] [CountableInterFilter f] : ∃ x, ClusterPt x f := by simpa using isLindelof_univ (show f ≤ 𝓟 univ by simp) theorem LindelofSpace.elim_nhds_subcover [LindelofSpace X] (U : X → Set X) (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Set X, t.Countable ∧ ⋃ x ∈ t, U x = univ := by obtain ⟨t, tc, -, s⟩ := IsLindelof.elim_nhds_subcover isLindelof_univ U fun x _ => hU x use t, tc apply top_unique s theorem lindelofSpace_of_countable_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → ⋂ i, t i = ∅ → ∃ u : Set ι, u.Countable ∧ ⋂ i ∈ u, t i = ∅) : LindelofSpace X where isLindelof_univ := isLindelof_of_countable_subfamily_closed fun t => by simpa using h t theorem IsClosed.isLindelof [LindelofSpace X] (h : IsClosed s) : IsLindelof s := isLindelof_univ.of_isClosed_subset h (subset_univ _) /-- A compact set `s` is Lindelöf. -/ theorem IsCompact.isLindelof (hs : IsCompact s) : IsLindelof s := by tauto /-- A σ-compact set `s` is Lindelöf -/
theorem IsSigmaCompact.isLindelof (hs : IsSigmaCompact s) : IsLindelof s := by rw [IsSigmaCompact] at hs rcases hs with ⟨K, ⟨hc, huniv⟩⟩ rw [← huniv] have hl : ∀ n, IsLindelof (K n) := fun n ↦ IsCompact.isLindelof (hc n) exact isLindelof_iUnion hl
Mathlib/Topology/Compactness/Lindelof.lean
515
521
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.MorphismProperty.Concrete import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Epi and mono in concrete categories In this file, we relate epimorphisms and monomorphisms in a concrete category `C` to surjective and injective morphisms, and we show that if `C` has strong epi mono factorizations and is such that `forget C` preserves both epi and mono, then any morphism in `C` can be factored in a functorial manner as a composition of a surjective morphism followed by an injective morphism. -/ universe w v v' u u' namespace CategoryTheory variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] open Limits MorphismProperty namespace ConcreteCategory section /-- In any concrete category, injective morphisms are monomorphisms. -/ theorem mono_of_injective {X Y : C} (f : X ⟶ Y) (i : Function.Injective f) : Mono f := (forget C).mono_of_mono_map ((mono_iff_injective ((forget C).map f)).2 i) instance forget₂_preservesMonomorphisms (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] [(forget C).PreservesMonomorphisms] : (forget₂ C D).PreservesMonomorphisms := have : (forget₂ C D ⋙ forget D).PreservesMonomorphisms := by simp only [HasForget₂.forget_comp] infer_instance Functor.preservesMonomorphisms_of_preserves_of_reflects _ (forget D) instance forget₂_preservesEpimorphisms (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] [(forget C).PreservesEpimorphisms] : (forget₂ C D).PreservesEpimorphisms := have : (forget₂ C D ⋙ forget D).PreservesEpimorphisms := by simp only [HasForget₂.forget_comp] infer_instance Functor.preservesEpimorphisms_of_preserves_of_reflects _ (forget D) variable (C) lemma surjective_le_epimorphisms : MorphismProperty.surjective C ≤ epimorphisms C := fun _ _ _ hf => (forget C).epi_of_epi_map ((epi_iff_surjective _).2 hf) lemma injective_le_monomorphisms : MorphismProperty.injective C ≤ monomorphisms C := fun _ _ _ hf => (forget C).mono_of_mono_map ((mono_iff_injective _).2 hf) lemma surjective_eq_epimorphisms_iff : MorphismProperty.surjective C = epimorphisms C ↔ (forget C).PreservesEpimorphisms := by constructor · intro h constructor rintro _ _ f (hf : epimorphisms C f) rw [epi_iff_surjective] rw [← h] at hf exact hf · intro apply le_antisymm (surjective_le_epimorphisms C) intro _ _ f hf have : Epi f := hf change Function.Surjective ((forget C).map f) rw [← epi_iff_surjective] infer_instance lemma injective_eq_monomorphisms_iff : MorphismProperty.injective C = monomorphisms C ↔ (forget C).PreservesMonomorphisms := by constructor · intro h constructor rintro _ _ f (hf : monomorphisms C f) rw [mono_iff_injective] rw [← h] at hf exact hf · intro apply le_antisymm (injective_le_monomorphisms C) intro _ _ f hf have : Mono f := hf change Function.Injective ((forget C).map f) rw [← mono_iff_injective] infer_instance lemma injective_eq_monomorphisms [(forget C).PreservesMonomorphisms] : MorphismProperty.injective C = monomorphisms C := by rw [injective_eq_monomorphisms_iff]
infer_instance lemma surjective_eq_epimorphisms [(forget C).PreservesEpimorphisms] : MorphismProperty.surjective C = epimorphisms C := by
Mathlib/CategoryTheory/ConcreteCategory/EpiMono.lean
107
110
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Abelian.Basic import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Limits.FunctorCategory.Finite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels /-! # If `D` is abelian, then the functor category `C ⥤ D` is also abelian. -/ noncomputable section namespace CategoryTheory open CategoryTheory.Limits namespace Abelian section universe z w v u variable {C : Type u} [Category.{v} C] variable {D : Type w} [Category.{z} D] [Abelian D] namespace FunctorCategory variable {F G : C ⥤ D} (α : F ⟶ G) (X : C) /-- The abelian coimage in a functor category can be calculated componentwise. -/ @[simps!] def coimageObjIso : (Abelian.coimage α).obj X ≅ Abelian.coimage (α.app X) := PreservesCokernel.iso ((evaluation C D).obj X) _ ≪≫ cokernel.mapIso _ _ (PreservesKernel.iso ((evaluation C D).obj X) _) (Iso.refl _) (by dsimp simp only [Category.comp_id, PreservesKernel.iso_hom] exact (kernelComparison_comp_ι _ ((evaluation C D).obj X)).symm) /-- The abelian image in a functor category can be calculated componentwise. -/ @[simps!] def imageObjIso : (Abelian.image α).obj X ≅ Abelian.image (α.app X) := PreservesKernel.iso ((evaluation C D).obj X) _ ≪≫ kernel.mapIso _ _ (Iso.refl _) (PreservesCokernel.iso ((evaluation C D).obj X) _) (by apply (cancel_mono (PreservesCokernel.iso ((evaluation C D).obj X) α).inv).1 simp only [Category.assoc, Iso.hom_inv_id] dsimp simp only [PreservesCokernel.iso_inv, Category.id_comp, Category.comp_id] exact (π_comp_cokernelComparison _ ((evaluation C D).obj X)).symm) theorem coimageImageComparison_app : coimageImageComparison (α.app X) = (coimageObjIso α X).inv ≫ (coimageImageComparison α).app X ≫ (imageObjIso α X).hom := by ext dsimp dsimp [imageObjIso, coimageObjIso, cokernel.map] simp only [coimage_image_factorisation, PreservesKernel.iso_hom, Category.assoc, kernel.lift_ι, Category.comp_id, PreservesCokernel.iso_inv, cokernel.π_desc_assoc, Category.id_comp] erw [kernelComparison_comp_ι _ ((evaluation C D).obj X)] erw [π_comp_cokernelComparison_assoc _ ((evaluation C D).obj X)] conv_lhs => rw [← coimage_image_factorisation α] rfl theorem coimageImageComparison_app' : (coimageImageComparison α).app X = (coimageObjIso α X).hom ≫ coimageImageComparison (α.app X) ≫ (imageObjIso α X).inv := by simp only [coimageImageComparison_app, Iso.hom_inv_id_assoc, Iso.hom_inv_id, Category.assoc, Category.comp_id] instance functor_category_isIso_coimageImageComparison :
IsIso (Abelian.coimageImageComparison α) := by have : ∀ X : C, IsIso ((Abelian.coimageImageComparison α).app X) := by intros rw [coimageImageComparison_app'] infer_instance
Mathlib/CategoryTheory/Abelian/FunctorCategory.lean
79
83
/- 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 =>
Mathlib/Algebra/Lie/Nilpotent.lean
165
171
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Data.Set.SymmDiff import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Irreducible /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : IsInducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (by fun_prop)).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (Continuous.prodMk_left _).continuousOn) theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ classical rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction I using Finset.induction_on with | empty => refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI | insert i I _ ihI => rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn /-- The connected component of a point is the maximal connected set that contains this point. -/ def connectedComponent (x : α) : Set α := ⋃₀ { s : Set α | IsPreconnected s ∧ x ∈ s } open Classical in /-- Given a set `F` in a topological space `α` and a point `x : α`, the connected component of `x` in `F` is the connected component of `x` in the subtype `F` seen as a set in `α`. This definition does not make sense if `x` is not in `F` so we return the empty set in this case. -/ def connectedComponentIn (F : Set α) (x : α) : Set α := if h : x ∈ F then (↑) '' connectedComponent (⟨x, h⟩ : F) else ∅ theorem connectedComponentIn_eq_image {F : Set α} {x : α} (h : x ∈ F) : connectedComponentIn F x = (↑) '' connectedComponent (⟨x, h⟩ : F) := dif_pos h theorem connectedComponentIn_eq_empty {F : Set α} {x : α} (h : x ∉ F) : connectedComponentIn F x = ∅ := dif_neg h theorem mem_connectedComponent {x : α} : x ∈ connectedComponent x := mem_sUnion_of_mem (mem_singleton x) ⟨isPreconnected_singleton, mem_singleton x⟩ theorem mem_connectedComponentIn {x : α} {F : Set α} (hx : x ∈ F) : x ∈ connectedComponentIn F x := by simp [connectedComponentIn_eq_image hx, mem_connectedComponent, hx] theorem connectedComponent_nonempty {x : α} : (connectedComponent x).Nonempty := ⟨x, mem_connectedComponent⟩ theorem connectedComponentIn_nonempty_iff {x : α} {F : Set α} : (connectedComponentIn F x).Nonempty ↔ x ∈ F := by rw [connectedComponentIn] split_ifs <;> simp [connectedComponent_nonempty, *] theorem connectedComponentIn_subset (F : Set α) (x : α) : connectedComponentIn F x ⊆ F := by rw [connectedComponentIn] split_ifs <;> simp theorem isPreconnected_connectedComponent {x : α} : IsPreconnected (connectedComponent x) := isPreconnected_sUnion x _ (fun _ => And.right) fun _ => And.left theorem isPreconnected_connectedComponentIn {x : α} {F : Set α} : IsPreconnected (connectedComponentIn F x) := by rw [connectedComponentIn]; split_ifs · exact IsInducing.subtypeVal.isPreconnected_image.mpr isPreconnected_connectedComponent · exact isPreconnected_empty theorem isConnected_connectedComponent {x : α} : IsConnected (connectedComponent x) := ⟨⟨x, mem_connectedComponent⟩, isPreconnected_connectedComponent⟩ theorem isConnected_connectedComponentIn_iff {x : α} {F : Set α} : IsConnected (connectedComponentIn F x) ↔ x ∈ F := by simp_rw [← connectedComponentIn_nonempty_iff, IsConnected, isPreconnected_connectedComponentIn, and_true] theorem IsPreconnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsPreconnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := fun _z hz => mem_sUnion_of_mem hz ⟨H1, H2⟩ theorem IsPreconnected.subset_connectedComponentIn {x : α} {F : Set α} (hs : IsPreconnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connectedComponentIn F x := by have : IsPreconnected (((↑) : F → α) ⁻¹' s) := by refine IsInducing.subtypeVal.isPreconnected_image.mp ?_ rwa [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] have h2xs : (⟨x, hsF hxs⟩ : F) ∈ (↑) ⁻¹' s := by rw [mem_preimage] exact hxs have := this.subset_connectedComponent h2xs rw [connectedComponentIn_eq_image (hsF hxs)] refine Subset.trans ?_ (image_subset _ this) rw [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] theorem IsConnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsConnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := H1.2.subset_connectedComponent H2 theorem IsPreconnected.connectedComponentIn {x : α} {F : Set α} (h : IsPreconnected F) (hx : x ∈ F) : connectedComponentIn F x = F := (connectedComponentIn_subset F x).antisymm (h.subset_connectedComponentIn hx subset_rfl) theorem connectedComponent_eq {x y : α} (h : y ∈ connectedComponent x) : connectedComponent x = connectedComponent y := eq_of_subset_of_subset (isConnected_connectedComponent.subset_connectedComponent h) (isConnected_connectedComponent.subset_connectedComponent (Set.mem_of_mem_of_subset mem_connectedComponent (isConnected_connectedComponent.subset_connectedComponent h))) theorem connectedComponent_eq_iff_mem {x y : α} : connectedComponent x = connectedComponent y ↔ x ∈ connectedComponent y := ⟨fun h => h ▸ mem_connectedComponent, fun h => (connectedComponent_eq h).symm⟩ theorem connectedComponentIn_eq {x y : α} {F : Set α} (h : y ∈ connectedComponentIn F x) : connectedComponentIn F x = connectedComponentIn F y := by have hx : x ∈ F := connectedComponentIn_nonempty_iff.mp ⟨y, h⟩ simp_rw [connectedComponentIn_eq_image hx] at h ⊢ obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h simp_rw [connectedComponentIn_eq_image hy, connectedComponent_eq h2y] theorem connectedComponentIn_univ (x : α) : connectedComponentIn univ x = connectedComponent x := subset_antisymm (isPreconnected_connectedComponentIn.subset_connectedComponent <| mem_connectedComponentIn trivial) (isPreconnected_connectedComponent.subset_connectedComponentIn mem_connectedComponent <| subset_univ _) theorem connectedComponent_disjoint {x y : α} (h : connectedComponent x ≠ connectedComponent y) : Disjoint (connectedComponent x) (connectedComponent y) := Set.disjoint_left.2 fun _ h1 h2 => h ((connectedComponent_eq h1).trans (connectedComponent_eq h2).symm) theorem isClosed_connectedComponent {x : α} : IsClosed (connectedComponent x) := closure_subset_iff_isClosed.1 <| isConnected_connectedComponent.closure.subset_connectedComponent <| subset_closure mem_connectedComponent theorem Continuous.image_connectedComponent_subset [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : f '' connectedComponent a ⊆ connectedComponent (f a) := (isConnected_connectedComponent.image f h.continuousOn).subset_connectedComponent ((mem_image f (connectedComponent a) (f a)).2 ⟨a, mem_connectedComponent, rfl⟩) theorem Continuous.image_connectedComponentIn_subset [TopologicalSpace β] {f : α → β} {s : Set α} {a : α} (hf : Continuous f) (hx : a ∈ s) : f '' connectedComponentIn s a ⊆ connectedComponentIn (f '' s) (f a) := (isPreconnected_connectedComponentIn.image _ hf.continuousOn).subset_connectedComponentIn (mem_image_of_mem _ <| mem_connectedComponentIn hx) (image_subset _ <| connectedComponentIn_subset _ _) theorem Continuous.mapsTo_connectedComponent [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : MapsTo f (connectedComponent a) (connectedComponent (f a)) := mapsTo'.2 <| h.image_connectedComponent_subset a theorem Continuous.mapsTo_connectedComponentIn [TopologicalSpace β] {f : α → β} {s : Set α} (h : Continuous f) {a : α} (hx : a ∈ s) : MapsTo f (connectedComponentIn s a) (connectedComponentIn (f '' s) (f a)) := mapsTo'.2 <| image_connectedComponentIn_subset h hx theorem irreducibleComponent_subset_connectedComponent {x : α} : irreducibleComponent x ⊆ connectedComponent x := isIrreducible_irreducibleComponent.isConnected.subset_connectedComponent mem_irreducibleComponent @[mono] theorem connectedComponentIn_mono (x : α) {F G : Set α} (h : F ⊆ G) : connectedComponentIn F x ⊆ connectedComponentIn G x := by by_cases hx : x ∈ F · rw [connectedComponentIn_eq_image hx, connectedComponentIn_eq_image (h hx), ← show ((↑) : G → α) ∘ inclusion h = (↑) from rfl, image_comp] exact image_subset _ ((continuous_inclusion h).image_connectedComponent_subset ⟨x, hx⟩) · rw [connectedComponentIn_eq_empty hx] exact Set.empty_subset _ /-- A preconnected space is one where there is no non-trivial open partition. -/ class PreconnectedSpace (α : Type u) [TopologicalSpace α] : Prop where /-- The universal set `Set.univ` in a preconnected space is a preconnected set. -/ isPreconnected_univ : IsPreconnected (univ : Set α) export PreconnectedSpace (isPreconnected_univ) /-- A connected space is a nonempty one where there is no non-trivial open partition. -/ class ConnectedSpace (α : Type u) [TopologicalSpace α] : Prop extends PreconnectedSpace α where /-- A connected space is nonempty. -/ toNonempty : Nonempty α attribute [instance 50] ConnectedSpace.toNonempty -- see Note [lower instance priority] -- see Note [lower instance priority] theorem isConnected_univ [ConnectedSpace α] : IsConnected (univ : Set α) := ⟨univ_nonempty, isPreconnected_univ⟩ lemma preconnectedSpace_iff_univ : PreconnectedSpace α ↔ IsPreconnected (univ : Set α) := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩ lemma connectedSpace_iff_univ : ConnectedSpace α ↔ IsConnected (univ : Set α) := ⟨fun h ↦ ⟨univ_nonempty, h.1.1⟩, fun h ↦ ConnectedSpace.mk (toPreconnectedSpace := ⟨h.2⟩) ⟨h.1.some⟩⟩ theorem isPreconnected_range [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (h : Continuous f) : IsPreconnected (range f) := @image_univ _ _ f ▸ isPreconnected_univ.image _ h.continuousOn theorem isConnected_range [TopologicalSpace β] [ConnectedSpace α] {f : α → β} (h : Continuous f) : IsConnected (range f) := ⟨range_nonempty f, isPreconnected_range h⟩ theorem Function.Surjective.connectedSpace [ConnectedSpace α] [TopologicalSpace β] {f : α → β} (hf : Surjective f) (hf' : Continuous f) : ConnectedSpace β := by rw [connectedSpace_iff_univ, ← hf.range_eq] exact isConnected_range hf' instance Quotient.instConnectedSpace {s : Setoid α} [ConnectedSpace α] : ConnectedSpace (Quotient s) := Quotient.mk'_surjective.connectedSpace continuous_coinduced_rng theorem DenseRange.preconnectedSpace [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (hf : DenseRange f) (hc : Continuous f) : PreconnectedSpace β := ⟨hf.closure_eq ▸ (isPreconnected_range hc).closure⟩ theorem connectedSpace_iff_connectedComponent : ConnectedSpace α ↔ ∃ x : α, connectedComponent x = univ := by constructor · rintro ⟨⟨x⟩⟩ exact ⟨x, eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x)⟩ · rintro ⟨x, h⟩ haveI : PreconnectedSpace α := ⟨by rw [← h]; exact isPreconnected_connectedComponent⟩ exact ⟨⟨x⟩⟩ theorem preconnectedSpace_iff_connectedComponent : PreconnectedSpace α ↔ ∀ x : α, connectedComponent x = univ := by constructor · intro h x exact eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x) · intro h rcases isEmpty_or_nonempty α with hα | hα · exact ⟨by rw [univ_eq_empty_iff.mpr hα]; exact isPreconnected_empty⟩ · exact ⟨by rw [← h (Classical.choice hα)]; exact isPreconnected_connectedComponent⟩ @[simp] theorem PreconnectedSpace.connectedComponent_eq_univ {X : Type*} [TopologicalSpace X] [h : PreconnectedSpace X] (x : X) : connectedComponent x = univ := preconnectedSpace_iff_connectedComponent.mp h x instance [TopologicalSpace β] [PreconnectedSpace α] [PreconnectedSpace β] : PreconnectedSpace (α × β) := ⟨by rw [← univ_prod_univ] exact isPreconnected_univ.prod isPreconnected_univ⟩ instance [TopologicalSpace β] [ConnectedSpace α] [ConnectedSpace β] : ConnectedSpace (α × β) := ⟨inferInstance⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, PreconnectedSpace (π i)] : PreconnectedSpace (∀ i, π i) := ⟨by rw [← pi_univ univ]; exact isPreconnected_univ_pi fun i => isPreconnected_univ⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, ConnectedSpace (π i)] : ConnectedSpace (∀ i, π i) := ⟨inferInstance⟩ -- see Note [lower instance priority] instance (priority := 100) PreirreducibleSpace.preconnectedSpace (α : Type u) [TopologicalSpace α] [PreirreducibleSpace α] : PreconnectedSpace α := ⟨isPreirreducible_univ.isPreconnected⟩ -- see Note [lower instance priority] instance (priority := 100) IrreducibleSpace.connectedSpace (α : Type u) [TopologicalSpace α] [IrreducibleSpace α] : ConnectedSpace α where toNonempty := IrreducibleSpace.toNonempty theorem Subtype.preconnectedSpace {s : Set α} (h : IsPreconnected s) : PreconnectedSpace s where isPreconnected_univ := by rwa [← IsInducing.subtypeVal.isPreconnected_image, image_univ, Subtype.range_val] theorem Subtype.connectedSpace {s : Set α} (h : IsConnected s) : ConnectedSpace s where toPreconnectedSpace := Subtype.preconnectedSpace h.isPreconnected toNonempty := h.nonempty.to_subtype theorem isPreconnected_iff_preconnectedSpace {s : Set α} : IsPreconnected s ↔ PreconnectedSpace s := ⟨Subtype.preconnectedSpace, fun h => by simpa using isPreconnected_univ.image ((↑) : s → α) continuous_subtype_val.continuousOn⟩ theorem isConnected_iff_connectedSpace {s : Set α} : IsConnected s ↔ ConnectedSpace s := ⟨Subtype.connectedSpace, fun h => ⟨nonempty_subtype.mp h.2, isPreconnected_iff_preconnectedSpace.mpr h.1⟩⟩ end Preconnected
Mathlib/Topology/Connected/Basic.lean
1,053
1,071
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Support import Mathlib.Data.Set.SymmDiff /-! # Indicator function - `Set.indicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `0` otherwise. - `Set.mulIndicator (s : Set α) (f : α → β) (a : α)` is `f a` if `a ∈ s` and is `1` otherwise. ## Implementation note In mathematics, an indicator function or a characteristic function is a function used to indicate membership of an element in a set `s`, having the value `1` for all elements of `s` and the value `0` otherwise. But since it is usually used to restrict a function to a certain set `s`, we let the indicator function take the value `f x` for some function `f`, instead of `1`. If the usual indicator function is needed, just set `f` to be the constant function `fun _ ↦ 1`. The indicator function is implemented non-computably, to avoid having to pass around `Decidable` arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`. ## Tags indicator, characteristic -/ assert_not_exists MonoidWithZero open Function variable {α β M N : Type*} namespace Set section One variable [One M] [One N] {s t : Set α} {f g : α → M} {a : α} /-- `Set.mulIndicator s f a` is `f a` if `a ∈ s`, `1` otherwise. -/ @[to_additive "`Set.indicator s f a` is `f a` if `a ∈ s`, `0` otherwise."] noncomputable def mulIndicator (s : Set α) (f : α → M) (x : α) : M := haveI := Classical.decPred (· ∈ s) if x ∈ s then f x else 1 @[to_additive (attr := simp)] theorem piecewise_eq_mulIndicator [DecidablePred (· ∈ s)] : s.piecewise f 1 = s.mulIndicator f := funext fun _ => @if_congr _ _ _ _ (id _) _ _ _ _ Iff.rfl rfl rfl @[to_additive] theorem mulIndicator_apply (s : Set α) (f : α → M) (a : α) [Decidable (a ∈ s)] : mulIndicator s f a = if a ∈ s then f a else 1 := by unfold mulIndicator congr @[to_additive (attr := simp)] theorem mulIndicator_of_mem (h : a ∈ s) (f : α → M) : mulIndicator s f a = f a := if_pos h @[to_additive (attr := simp)] theorem mulIndicator_of_not_mem (h : a ∉ s) (f : α → M) : mulIndicator s f a = 1 := if_neg h @[to_additive] theorem mulIndicator_eq_one_or_self (s : Set α) (f : α → M) (a : α) : mulIndicator s f a = 1 ∨ mulIndicator s f a = f a := by by_cases h : a ∈ s · exact Or.inr (mulIndicator_of_mem h f) · exact Or.inl (mulIndicator_of_not_mem h f) @[to_additive (attr := simp)] theorem mulIndicator_apply_eq_self : s.mulIndicator f a = f a ↔ a ∉ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)]) @[to_additive (attr := simp)] theorem mulIndicator_eq_self : s.mulIndicator f = f ↔ mulSupport f ⊆ s := by simp only [funext_iff, subset_def, mem_mulSupport, mulIndicator_apply_eq_self, not_imp_comm] @[to_additive] theorem mulIndicator_eq_self_of_superset (h1 : s.mulIndicator f = f) (h2 : s ⊆ t) : t.mulIndicator f = f := by rw [mulIndicator_eq_self] at h1 ⊢ exact Subset.trans h1 h2 @[to_additive (attr := simp)] theorem mulIndicator_apply_eq_one : mulIndicator s f a = 1 ↔ a ∈ s → f a = 1 := letI := Classical.dec (a ∈ s) ite_eq_right_iff @[to_additive (attr := simp)] theorem mulIndicator_eq_one : (mulIndicator s f = fun _ => 1) ↔ Disjoint (mulSupport f) s := by simp only [funext_iff, mulIndicator_apply_eq_one, Set.disjoint_left, mem_mulSupport, not_imp_not] @[to_additive (attr := simp)] theorem mulIndicator_eq_one' : mulIndicator s f = 1 ↔ Disjoint (mulSupport f) s := mulIndicator_eq_one @[to_additive] theorem mulIndicator_apply_ne_one {a : α} : s.mulIndicator f a ≠ 1 ↔ a ∈ s ∩ mulSupport f := by simp only [Ne, mulIndicator_apply_eq_one, Classical.not_imp, mem_inter_iff, mem_mulSupport] @[to_additive (attr := simp)] theorem mulSupport_mulIndicator : Function.mulSupport (s.mulIndicator f) = s ∩ Function.mulSupport f := ext fun x => by simp [Function.mem_mulSupport, mulIndicator_apply_eq_one] /-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the set. -/ @[to_additive "If an additive indicator function is not equal to `0` at a point, then that point is in the set."] theorem mem_of_mulIndicator_ne_one (h : mulIndicator s f a ≠ 1) : a ∈ s := not_imp_comm.1 (fun hn => mulIndicator_of_not_mem hn f) h /-- See `Set.eqOn_mulIndicator'` for the version with `sᶜ`. -/ @[to_additive "See `Set.eqOn_indicator'` for the version with `sᶜ`"] theorem eqOn_mulIndicator : EqOn (mulIndicator s f) f s := fun _ hx => mulIndicator_of_mem hx f /-- See `Set.eqOn_mulIndicator` for the version with `s`. -/ @[to_additive "See `Set.eqOn_indicator` for the version with `s`."] theorem eqOn_mulIndicator' : EqOn (mulIndicator s f) 1 sᶜ := fun _ hx => mulIndicator_of_not_mem hx f @[to_additive] theorem mulSupport_mulIndicator_subset : mulSupport (s.mulIndicator f) ⊆ s := fun _ hx => hx.imp_symm fun h => mulIndicator_of_not_mem h f @[to_additive (attr := simp)] theorem mulIndicator_mulSupport : mulIndicator (mulSupport f) f = f := mulIndicator_eq_self.2 Subset.rfl @[to_additive (attr := simp)] theorem mulIndicator_range_comp {ι : Sort*} (f : ι → α) (g : α → M) : mulIndicator (range f) g ∘ f = g ∘ f := letI := Classical.decPred (· ∈ range f) piecewise_range_comp _ _ _ @[to_additive] theorem mulIndicator_congr (h : EqOn f g s) : mulIndicator s f = mulIndicator s g := funext fun x => by simp only [mulIndicator] split_ifs with h_1 · exact h h_1 rfl @[to_additive] theorem mulIndicator_eq_mulIndicator {t : Set β} {g : β → M} {b : β} (h1 : a ∈ s ↔ b ∈ t) (h2 : f a = g b) : s.mulIndicator f a = t.mulIndicator g b := by by_cases a ∈ s <;> simp_all @[to_additive] theorem mulIndicator_const_eq_mulIndicator_const {t : Set β} {b : β} {c : M} (h : a ∈ s ↔ b ∈ t) : s.mulIndicator (fun _ ↦ c) a = t.mulIndicator (fun _ ↦ c) b := mulIndicator_eq_mulIndicator h rfl @[to_additive (attr := simp)] theorem mulIndicator_univ (f : α → M) : mulIndicator (univ : Set α) f = f := mulIndicator_eq_self.2 <| subset_univ _ @[to_additive (attr := simp)] theorem mulIndicator_empty (f : α → M) : mulIndicator (∅ : Set α) f = fun _ => 1 := mulIndicator_eq_one.2 <| disjoint_empty _ @[to_additive] theorem mulIndicator_empty' (f : α → M) : mulIndicator (∅ : Set α) f = 1 := mulIndicator_empty f variable (M)
@[to_additive (attr := simp)] theorem mulIndicator_one (s : Set α) : (mulIndicator s fun _ => (1 : M)) = fun _ => (1 : M) := mulIndicator_eq_one.2 <| by simp only [mulSupport_one, empty_disjoint] @[to_additive (attr := simp)]
Mathlib/Algebra/Group/Indicator.lean
179
184
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Kim Morrison, Chris Hughes, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Dimension.Free import Mathlib.LinearAlgebra.TensorProduct.Basis /-! # Rank of various constructions ## Main statements - `rank_quotient_add_rank_le` : `rank M/N + rank N ≤ rank M`. - `lift_rank_add_lift_rank_le_rank_prod`: `rank M × N ≤ rank M + rank N`. - `rank_span_le_of_finite`: `rank (span s) ≤ #s` for finite `s`. For free modules, we have - `rank_prod` : `rank M × N = rank M + rank N`. - `rank_finsupp` : `rank (ι →₀ M) = #ι * rank M` - `rank_directSum`: `rank (⨁ Mᵢ) = ∑ rank Mᵢ` - `rank_tensorProduct`: `rank (M ⊗ N) = rank M * rank N`. Lemmas for ranks of submodules and subalgebras are also provided. We have finrank variants for most lemmas as well. -/ noncomputable section universe u u' v v' u₁' w w' variable {R : Type u} {S : Type u'} {M : Type v} {M' : Type v'} {M₁ : Type v} variable {ι : Type w} {ι' : Type w'} {η : Type u₁'} {φ : η → Type*} open Basis Cardinal DirectSum Function Module Set Submodule section Quotient variable [Ring R] [CommRing S] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] theorem LinearIndependent.sumElim_of_quotient {M' : Submodule R M} {ι₁ ι₂} {f : ι₁ → M'} (hf : LinearIndependent R f) (g : ι₂ → M) (hg : LinearIndependent R (Submodule.Quotient.mk (p := M') ∘ g)) : LinearIndependent R (Sum.elim (f · : ι₁ → M) g) := by refine .sum_type (hf.map' M'.subtype M'.ker_subtype) (.of_comp M'.mkQ hg) ?_ refine disjoint_def.mpr fun x h₁ h₂ ↦ ?_ have : x ∈ M' := span_le.mpr (Set.range_subset_iff.mpr fun i ↦ (f i).prop) h₁ obtain ⟨c, rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp h₂ simp_rw [← Quotient.mk_eq_zero, ← mkQ_apply, map_finsuppSum, map_smul, mkQ_apply] at this rw [linearIndependent_iff.mp hg _ this, Finsupp.sum_zero_index] @[deprecated (since := "2025-02-21")] alias LinearIndependent.sum_elim_of_quotient := LinearIndependent.sumElim_of_quotient theorem LinearIndepOn.union_of_quotient {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s) (ht : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t) : LinearIndepOn R f (s ∪ t) := by apply hs.union ht.of_comp convert (Submodule.range_ker_disjoint ht).symm · simp aesop theorem LinearIndepOn.union_id_of_quotient {M' : Submodule R M} {s : Set M} (hs : s ⊆ M') (hs' : LinearIndepOn R id s) {t : Set M} (ht : LinearIndepOn R (mkQ M') t) : LinearIndepOn R id (s ∪ t) := hs'.union_of_quotient <| by rw [image_id] exact ht.of_comp ((span R s).mapQ M' (LinearMap.id) (span_le.2 hs)) @[deprecated (since := "2025-02-16")] alias LinearIndependent.union_of_quotient := LinearIndepOn.union_id_of_quotient theorem linearIndepOn_union_iff_quotient {s t : Set ι} {f : ι → M} (hst : Disjoint s t) : LinearIndepOn R f (s ∪ t) ↔ LinearIndepOn R f s ∧ LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ h.1.union_of_quotient h.2⟩ · exact h.mono subset_union_left apply (h.mono subset_union_right).map simpa [← image_eq_range] using ((linearIndepOn_union_iff hst).1 h).2.2.symm theorem LinearIndepOn.quotient_iff_union {s t : Set ι} {f : ι → M} (hs : LinearIndepOn R f s) (hst : Disjoint s t) : LinearIndepOn R (mkQ (span R (f '' s)) ∘ f) t ↔ LinearIndepOn R f (s ∪ t) := by rw [linearIndepOn_union_iff_quotient hst, and_iff_right hs] theorem rank_quotient_add_rank_le [Nontrivial R] (M' : Submodule R M) : Module.rank R (M ⧸ M') + Module.rank R M' ≤ Module.rank R M := by conv_lhs => simp only [Module.rank_def] have := nonempty_linearIndependent_set R (M ⧸ M') have := nonempty_linearIndependent_set R M' rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)] refine ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ ?_ choose f hf using Submodule.Quotient.mk_surjective M' simpa [add_comm] using (LinearIndependent.sumElim_of_quotient ht (fun (i : s) ↦ f i) (by simpa [Function.comp_def, hf] using hs)).cardinal_le_rank theorem rank_quotient_le (p : Submodule R M) : Module.rank R (M ⧸ p) ≤ Module.rank R M := (mkQ p).rank_le_of_surjective Quot.mk_surjective /-- The dimension of a quotient is bounded by the dimension of the ambient space. -/ theorem Submodule.finrank_quotient_le [StrongRankCondition R] [Module.Finite R M] (s : Submodule R M) : finrank R (M ⧸ s) ≤ finrank R M := toNat_le_toNat ((Submodule.mkQ s).rank_le_of_surjective Quot.mk_surjective) (rank_lt_aleph0 _ _) end Quotient variable [Semiring R] [CommSemiring S] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M₁] variable [Module R M] section ULift @[simp] theorem rank_ulift : Module.rank R (ULift.{w} M) = Cardinal.lift.{w} (Module.rank R M) := Cardinal.lift_injective.{v} <| Eq.symm <| (lift_lift _).trans ULift.moduleEquiv.symm.lift_rank_eq @[simp] theorem finrank_ulift : finrank R (ULift M) = finrank R M := by simp_rw [finrank, rank_ulift, toNat_lift] end ULift section Prod variable (R M M') variable [Module R M₁] [Module R M'] theorem rank_add_rank_le_rank_prod [Nontrivial R] : Module.rank R M + Module.rank R M₁ ≤ Module.rank R (M × M₁) := by conv_lhs => simp only [Module.rank_def] have := nonempty_linearIndependent_set R M have := nonempty_linearIndependent_set R M₁ rw [Cardinal.ciSup_add_ciSup _ (bddAbove_range _) _ (bddAbove_range _)] exact ciSup_le fun ⟨s, hs⟩ ↦ ciSup_le fun ⟨t, ht⟩ ↦ (linearIndependent_inl_union_inr' hs ht).cardinal_le_rank theorem lift_rank_add_lift_rank_le_rank_prod [Nontrivial R] : lift.{v'} (Module.rank R M) + lift.{v} (Module.rank R M') ≤ Module.rank R (M × M') := by rw [← rank_ulift, ← rank_ulift] exact (rank_add_rank_le_rank_prod R _).trans_eq (ULift.moduleEquiv.prodCongr ULift.moduleEquiv).rank_eq variable {R M M'} variable [StrongRankCondition R] [Module.Free R M] [Module.Free R M'] [Module.Free R M₁] open Module.Free /-- If `M` and `M'` are free, then the rank of `M × M'` is `(Module.rank R M).lift + (Module.rank R M').lift`. -/ @[simp] theorem rank_prod : Module.rank R (M × M') = Cardinal.lift.{v'} (Module.rank R M) + Cardinal.lift.{v, v'} (Module.rank R M') := by simpa [rank_eq_card_chooseBasisIndex R M, rank_eq_card_chooseBasisIndex R M', lift_umax] using ((chooseBasis R M).prod (chooseBasis R M')).mk_eq_rank.symm /-- If `M` and `M'` are free (and lie in the same universe), the rank of `M × M'` is `(Module.rank R M) + (Module.rank R M')`. -/ theorem rank_prod' : Module.rank R (M × M₁) = Module.rank R M + Module.rank R M₁ := by simp
/-- The finrank of `M × M'` is `(finrank R M) + (finrank R M')`. -/ @[simp] theorem Module.finrank_prod [Module.Finite R M] [Module.Finite R M'] : finrank R (M × M') = finrank R M + finrank R M' := by
Mathlib/LinearAlgebra/Dimension/Constructions.lean
164
168
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Order.Filter.Bases.Finite import Mathlib.Topology.Algebra.Group.Defs import Mathlib.Topology.Algebra.Monoid import Mathlib.Topology.Homeomorph.Lemmas /-! # Topological groups This file defines the following typeclasses: * `IsTopologicalGroup`, `IsTopologicalAddGroup`: multiplicative and additive topological groups, i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`; * `ContinuousSub G` means that `G` has a continuous subtraction operation. There is an instance deducing `ContinuousSub` from `IsTopologicalGroup` but we use a separate typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups. We also define `Homeomorph` versions of several `Equiv`s: `Homeomorph.mulLeft`, `Homeomorph.mulRight`, `Homeomorph.inv`, and prove a few facts about neighbourhood filters in groups. ## Tags topological space, group, topological group -/ open Set Filter TopologicalSpace Function Topology MulOpposite Pointwise universe u v w x variable {G : Type w} {H : Type x} {α : Type u} {β : Type v} section ContinuousMulGroup /-! ### Groups with continuous multiplication In this section we prove a few statements about groups with continuous `(*)`. -/ variable [TopologicalSpace G] [Group G] [ContinuousMul G] /-- Multiplication from the left in a topological group as a homeomorphism. -/ @[to_additive "Addition from the left in a topological additive group as a homeomorphism."] protected def Homeomorph.mulLeft (a : G) : G ≃ₜ G := { Equiv.mulLeft a with continuous_toFun := continuous_const.mul continuous_id continuous_invFun := continuous_const.mul continuous_id } @[to_additive (attr := simp)] theorem Homeomorph.coe_mulLeft (a : G) : ⇑(Homeomorph.mulLeft a) = (a * ·) := rfl @[to_additive] theorem Homeomorph.mulLeft_symm (a : G) : (Homeomorph.mulLeft a).symm = Homeomorph.mulLeft a⁻¹ := by ext rfl @[to_additive] lemma isOpenMap_mul_left (a : G) : IsOpenMap (a * ·) := (Homeomorph.mulLeft a).isOpenMap @[to_additive IsOpen.left_addCoset] theorem IsOpen.leftCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (x • U) := isOpenMap_mul_left x _ h @[to_additive] lemma isClosedMap_mul_left (a : G) : IsClosedMap (a * ·) := (Homeomorph.mulLeft a).isClosedMap @[to_additive IsClosed.left_addCoset] theorem IsClosed.leftCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (x • U) := isClosedMap_mul_left x _ h /-- Multiplication from the right in a topological group as a homeomorphism. -/ @[to_additive "Addition from the right in a topological additive group as a homeomorphism."] protected def Homeomorph.mulRight (a : G) : G ≃ₜ G := { Equiv.mulRight a with continuous_toFun := continuous_id.mul continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive (attr := simp)] lemma Homeomorph.coe_mulRight (a : G) : ⇑(Homeomorph.mulRight a) = (· * a) := rfl @[to_additive] theorem Homeomorph.mulRight_symm (a : G) : (Homeomorph.mulRight a).symm = Homeomorph.mulRight a⁻¹ := by ext rfl @[to_additive] theorem isOpenMap_mul_right (a : G) : IsOpenMap (· * a) := (Homeomorph.mulRight a).isOpenMap @[to_additive IsOpen.right_addCoset] theorem IsOpen.rightCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (op x • U) := isOpenMap_mul_right x _ h @[to_additive] theorem isClosedMap_mul_right (a : G) : IsClosedMap (· * a) := (Homeomorph.mulRight a).isClosedMap @[to_additive IsClosed.right_addCoset] theorem IsClosed.rightCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (op x • U) := isClosedMap_mul_right x _ h @[to_additive] theorem discreteTopology_of_isOpen_singleton_one (h : IsOpen ({1} : Set G)) : DiscreteTopology G := by rw [← singletons_open_iff_discrete] intro g suffices {g} = (g⁻¹ * ·) ⁻¹' {1} by rw [this] exact (continuous_mul_left g⁻¹).isOpen_preimage _ h simp only [mul_one, Set.preimage_mul_left_singleton, eq_self_iff_true, inv_inv, Set.singleton_eq_singleton_iff] @[to_additive] theorem discreteTopology_iff_isOpen_singleton_one : DiscreteTopology G ↔ IsOpen ({1} : Set G) := ⟨fun h => forall_open_iff_discrete.mpr h {1}, discreteTopology_of_isOpen_singleton_one⟩ end ContinuousMulGroup /-! ### `ContinuousInv` and `ContinuousNeg` -/ section ContinuousInv variable [TopologicalSpace G] [Inv G] [ContinuousInv G] @[to_additive] theorem ContinuousInv.induced {α : Type*} {β : Type*} {F : Type*} [FunLike F α β] [Group α] [DivisionMonoid β] [MonoidHomClass F α β] [tβ : TopologicalSpace β] [ContinuousInv β] (f : F) : @ContinuousInv α (tβ.induced f) _ := by let _tα := tβ.induced f refine ⟨continuous_induced_rng.2 ?_⟩ simp only [Function.comp_def, map_inv] fun_prop @[to_additive] protected theorem Specializes.inv {x y : G} (h : x ⤳ y) : (x⁻¹) ⤳ (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Inseparable.inv {x y : G} (h : Inseparable x y) : Inseparable (x⁻¹) (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Specializes.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : x ⤳ y) : ∀ m : ℤ, (x ^ m) ⤳ (y ^ m) | .ofNat n => by simpa using h.pow n | .negSucc n => by simpa using (h.pow (n + 1)).inv @[to_additive] protected theorem Inseparable.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : Inseparable x y) (m : ℤ) : Inseparable (x ^ m) (y ^ m) := (h.specializes.zpow m).antisymm (h.specializes'.zpow m) @[to_additive] instance : ContinuousInv (ULift G) := ⟨continuous_uliftUp.comp (continuous_inv.comp continuous_uliftDown)⟩ @[to_additive] theorem continuousOn_inv {s : Set G} : ContinuousOn Inv.inv s := continuous_inv.continuousOn @[to_additive] theorem continuousWithinAt_inv {s : Set G} {x : G} : ContinuousWithinAt Inv.inv s x := continuous_inv.continuousWithinAt @[to_additive] theorem continuousAt_inv {x : G} : ContinuousAt Inv.inv x := continuous_inv.continuousAt @[to_additive] theorem tendsto_inv (a : G) : Tendsto Inv.inv (𝓝 a) (𝓝 a⁻¹) := continuousAt_inv variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive] instance OrderDual.instContinuousInv : ContinuousInv Gᵒᵈ := ‹ContinuousInv G› @[to_additive] instance Prod.continuousInv [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousInv (G × H) := ⟨continuous_inv.fst'.prodMk continuous_inv.snd'⟩ variable {ι : Type*} @[to_additive] instance Pi.continuousInv {C : ι → Type*} [∀ i, TopologicalSpace (C i)] [∀ i, Inv (C i)] [∀ i, ContinuousInv (C i)] : ContinuousInv (∀ i, C i) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv /-- A version of `Pi.continuousInv` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousInv` for non-dependent functions. -/ @[to_additive "A version of `Pi.continuousNeg` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousNeg` for non-dependent functions."] instance Pi.has_continuous_inv' : ContinuousInv (ι → G) := Pi.continuousInv @[to_additive] instance (priority := 100) continuousInv_of_discreteTopology [TopologicalSpace H] [Inv H] [DiscreteTopology H] : ContinuousInv H := ⟨continuous_of_discreteTopology⟩ section PointwiseLimits variable (G₁ G₂ : Type*) [TopologicalSpace G₂] [T2Space G₂] @[to_additive] theorem isClosed_setOf_map_inv [Inv G₁] [Inv G₂] [ContinuousInv G₂] : IsClosed { f : G₁ → G₂ | ∀ x, f x⁻¹ = (f x)⁻¹ } := by simp only [setOf_forall] exact isClosed_iInter fun i => isClosed_eq (continuous_apply _) (continuous_apply _).inv end PointwiseLimits instance [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousNeg (Additive H) where continuous_neg := @continuous_inv H _ _ _ instance [TopologicalSpace H] [Neg H] [ContinuousNeg H] : ContinuousInv (Multiplicative H) where continuous_inv := @continuous_neg H _ _ _ end ContinuousInv section ContinuousInvolutiveInv variable [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] {s : Set G} @[to_additive] theorem IsCompact.inv (hs : IsCompact s) : IsCompact s⁻¹ := by rw [← image_inv_eq_inv] exact hs.image continuous_inv variable (G) /-- Inversion in a topological group as a homeomorphism. -/ @[to_additive "Negation in a topological group as a homeomorphism."] protected def Homeomorph.inv (G : Type*) [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : G ≃ₜ G := { Equiv.inv G with continuous_toFun := continuous_inv continuous_invFun := continuous_inv } @[to_additive (attr := simp)] lemma Homeomorph.coe_inv {G : Type*} [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : ⇑(Homeomorph.inv G) = Inv.inv := rfl @[to_additive] theorem nhds_inv (a : G) : 𝓝 a⁻¹ = (𝓝 a)⁻¹ := ((Homeomorph.inv G).map_nhds_eq a).symm @[to_additive] theorem isOpenMap_inv : IsOpenMap (Inv.inv : G → G) := (Homeomorph.inv _).isOpenMap @[to_additive] theorem isClosedMap_inv : IsClosedMap (Inv.inv : G → G) := (Homeomorph.inv _).isClosedMap variable {G} @[to_additive] theorem IsOpen.inv (hs : IsOpen s) : IsOpen s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem IsClosed.inv (hs : IsClosed s) : IsClosed s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem inv_closure : ∀ s : Set G, (closure s)⁻¹ = closure s⁻¹ := (Homeomorph.inv G).preimage_closure variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive (attr := simp)] lemma continuous_inv_iff : Continuous f⁻¹ ↔ Continuous f := (Homeomorph.inv G).comp_continuous_iff @[to_additive (attr := simp)] lemma continuousAt_inv_iff : ContinuousAt f⁻¹ x ↔ ContinuousAt f x := (Homeomorph.inv G).comp_continuousAt_iff _ _ @[to_additive (attr := simp)] lemma continuousOn_inv_iff : ContinuousOn f⁻¹ s ↔ ContinuousOn f s := (Homeomorph.inv G).comp_continuousOn_iff _ _ @[to_additive] alias ⟨Continuous.of_inv, _⟩ := continuous_inv_iff @[to_additive] alias ⟨ContinuousAt.of_inv, _⟩ := continuousAt_inv_iff @[to_additive] alias ⟨ContinuousOn.of_inv, _⟩ := continuousOn_inv_iff end ContinuousInvolutiveInv section LatticeOps variable {ι' : Sort*} [Inv G] @[to_additive] theorem continuousInv_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @ContinuousInv G t _) : @ContinuousInv G (sInf ts) _ := letI := sInf ts { continuous_inv := continuous_sInf_rng.2 fun t ht => continuous_sInf_dom ht (@ContinuousInv.continuous_inv G t _ (h t ht)) } @[to_additive] theorem continuousInv_iInf {ts' : ι' → TopologicalSpace G} (h' : ∀ i, @ContinuousInv G (ts' i) _) : @ContinuousInv G (⨅ i, ts' i) _ := by rw [← sInf_range] exact continuousInv_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem continuousInv_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @ContinuousInv G t₁ _) (h₂ : @ContinuousInv G t₂ _) : @ContinuousInv G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine continuousInv_iInf fun b => ?_ cases b <;> assumption end LatticeOps @[to_additive] theorem Topology.IsInducing.continuousInv {G H : Type*} [Inv G] [Inv H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv H] {f : G → H} (hf : IsInducing f) (hf_inv : ∀ x, f x⁻¹ = (f x)⁻¹) : ContinuousInv G := ⟨hf.continuous_iff.2 <| by simpa only [Function.comp_def, hf_inv] using hf.continuous.inv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.continuousInv := IsInducing.continuousInv section IsTopologicalGroup /-! ### Topological groups A topological group is a group in which the multiplication and inversion operations are continuous. Topological additive groups are defined in the same way. Equivalently, we can require that the division operation `x y ↦ x * y⁻¹` (resp., subtraction) is continuous. -/ section Conj instance ConjAct.units_continuousConstSMul {M} [Monoid M] [TopologicalSpace M] [ContinuousMul M] : ContinuousConstSMul (ConjAct Mˣ) M := ⟨fun _ => (continuous_const.mul continuous_id).mul continuous_const⟩ variable [TopologicalSpace G] [Inv G] [Mul G] [ContinuousMul G] /-- Conjugation is jointly continuous on `G × G` when both `mul` and `inv` are continuous. -/ @[to_additive continuous_addConj_prod "Conjugation is jointly continuous on `G × G` when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj_prod [ContinuousInv G] : Continuous fun g : G × G => g.fst * g.snd * g.fst⁻¹ := continuous_mul.mul (continuous_inv.comp continuous_fst) @[deprecated (since := "2025-03-11")] alias IsTopologicalAddGroup.continuous_conj_sum := IsTopologicalAddGroup.continuous_addConj_prod /-- Conjugation by a fixed element is continuous when `mul` is continuous. -/ @[to_additive (attr := continuity) "Conjugation by a fixed element is continuous when `add` is continuous."] theorem IsTopologicalGroup.continuous_conj (g : G) : Continuous fun h : G => g * h * g⁻¹ := (continuous_mul_right g⁻¹).comp (continuous_mul_left g) /-- Conjugation acting on fixed element of the group is continuous when both `mul` and `inv` are continuous. -/ @[to_additive (attr := continuity) "Conjugation acting on fixed element of the additive group is continuous when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj' [ContinuousInv G] (h : G) : Continuous fun g : G => g * h * g⁻¹ := (continuous_mul_right h).mul continuous_inv end Conj variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} instance : IsTopologicalGroup (ULift G) where section ZPow @[to_additive (attr := continuity, fun_prop)] theorem continuous_zpow : ∀ z : ℤ, Continuous fun a : G => a ^ z | Int.ofNat n => by simpa using continuous_pow n | Int.negSucc n => by simpa using (continuous_pow (n + 1)).inv instance AddGroup.continuousConstSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousConstSMul ℤ A := ⟨continuous_zsmul⟩ instance AddGroup.continuousSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousSMul ℤ A := ⟨continuous_prod_of_discrete_left.mpr continuous_zsmul⟩ @[to_additive (attr := continuity, fun_prop)] theorem Continuous.zpow {f : α → G} (h : Continuous f) (z : ℤ) : Continuous fun b => f b ^ z := (continuous_zpow z).comp h @[to_additive] theorem continuousOn_zpow {s : Set G} (z : ℤ) : ContinuousOn (fun x => x ^ z) s := (continuous_zpow z).continuousOn @[to_additive] theorem continuousAt_zpow (x : G) (z : ℤ) : ContinuousAt (fun x => x ^ z) x := (continuous_zpow z).continuousAt @[to_additive] theorem Filter.Tendsto.zpow {α} {l : Filter α} {f : α → G} {x : G} (hf : Tendsto f l (𝓝 x)) (z : ℤ) : Tendsto (fun x => f x ^ z) l (𝓝 (x ^ z)) := (continuousAt_zpow _ _).tendsto.comp hf @[to_additive] theorem ContinuousWithinAt.zpow {f : α → G} {x : α} {s : Set α} (hf : ContinuousWithinAt f s x) (z : ℤ) : ContinuousWithinAt (fun x => f x ^ z) s x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousAt.zpow {f : α → G} {x : α} (hf : ContinuousAt f x) (z : ℤ) : ContinuousAt (fun x => f x ^ z) x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousOn.zpow {f : α → G} {s : Set α} (hf : ContinuousOn f s) (z : ℤ) : ContinuousOn (fun x => f x ^ z) s := fun x hx => (hf x hx).zpow z end ZPow section OrderedCommGroup variable [TopologicalSpace H] [CommGroup H] [PartialOrder H] [IsOrderedMonoid H] [ContinuousInv H] @[to_additive] theorem tendsto_inv_nhdsGT {a : H} : Tendsto Inv.inv (𝓝[>] a) (𝓝[<] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi := tendsto_neg_nhdsGT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi := tendsto_inv_nhdsGT @[to_additive] theorem tendsto_inv_nhdsLT {a : H} : Tendsto Inv.inv (𝓝[<] a) (𝓝[>] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio := tendsto_neg_nhdsLT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio := tendsto_inv_nhdsLT @[to_additive] theorem tendsto_inv_nhdsGT_inv {a : H} : Tendsto Inv.inv (𝓝[>] a⁻¹) (𝓝[<] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi_neg := tendsto_neg_nhdsGT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi_inv := tendsto_inv_nhdsGT_inv @[to_additive] theorem tendsto_inv_nhdsLT_inv {a : H} : Tendsto Inv.inv (𝓝[<] a⁻¹) (𝓝[>] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio_neg := tendsto_neg_nhdsLT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio_inv := tendsto_inv_nhdsLT_inv @[to_additive] theorem tendsto_inv_nhdsGE {a : H} : Tendsto Inv.inv (𝓝[≥] a) (𝓝[≤] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici := tendsto_neg_nhdsGE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici := tendsto_inv_nhdsGE @[to_additive] theorem tendsto_inv_nhdsLE {a : H} : Tendsto Inv.inv (𝓝[≤] a) (𝓝[≥] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic := tendsto_neg_nhdsLE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic := tendsto_inv_nhdsLE @[to_additive] theorem tendsto_inv_nhdsGE_inv {a : H} : Tendsto Inv.inv (𝓝[≥] a⁻¹) (𝓝[≤] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici_neg := tendsto_neg_nhdsGE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici_inv := tendsto_inv_nhdsGE_inv @[to_additive] theorem tendsto_inv_nhdsLE_inv {a : H} : Tendsto Inv.inv (𝓝[≤] a⁻¹) (𝓝[≥] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic_neg := tendsto_neg_nhdsLE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic_inv := tendsto_inv_nhdsLE_inv end OrderedCommGroup @[to_additive] instance Prod.instIsTopologicalGroup [TopologicalSpace H] [Group H] [IsTopologicalGroup H] : IsTopologicalGroup (G × H) where continuous_inv := continuous_inv.prodMap continuous_inv @[to_additive] instance OrderDual.instIsTopologicalGroup : IsTopologicalGroup Gᵒᵈ where @[to_additive] instance Pi.topologicalGroup {C : β → Type*} [∀ b, TopologicalSpace (C b)] [∀ b, Group (C b)] [∀ b, IsTopologicalGroup (C b)] : IsTopologicalGroup (∀ b, C b) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv open MulOpposite @[to_additive] instance [Inv α] [ContinuousInv α] : ContinuousInv αᵐᵒᵖ := opHomeomorph.symm.isInducing.continuousInv unop_inv /-- If multiplication is continuous in `α`, then it also is in `αᵐᵒᵖ`. -/ @[to_additive "If addition is continuous in `α`, then it also is in `αᵃᵒᵖ`."] instance [Group α] [IsTopologicalGroup α] : IsTopologicalGroup αᵐᵒᵖ where variable (G) @[to_additive] theorem nhds_one_symm : comap Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem nhds_one_symm' : map Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).map_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem inv_mem_nhds_one {S : Set G} (hS : S ∈ (𝓝 1 : Filter G)) : S⁻¹ ∈ 𝓝 (1 : G) := by rwa [← nhds_one_symm'] at hS /-- The map `(x, y) ↦ (x, x * y)` as a homeomorphism. This is a shear mapping. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism. This is a shear mapping."] protected def Homeomorph.shearMulRight : G × G ≃ₜ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with continuous_toFun := by dsimp; fun_prop continuous_invFun := by dsimp; fun_prop } @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_coe : ⇑(Homeomorph.shearMulRight G) = fun z : G × G => (z.1, z.1 * z.2) := rfl @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_symm_coe : ⇑(Homeomorph.shearMulRight G).symm = fun z : G × G => (z.1, z.1⁻¹ * z.2) := rfl variable {G} @[to_additive] protected theorem Topology.IsInducing.topologicalGroup {F : Type*} [Group H] [TopologicalSpace H] [FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : IsInducing f) : IsTopologicalGroup H := { toContinuousMul := hf.continuousMul _ toContinuousInv := hf.continuousInv (map_inv f) } @[deprecated (since := "2024-10-28")] alias Inducing.topologicalGroup := IsInducing.topologicalGroup @[to_additive] theorem topologicalGroup_induced {F : Type*} [Group H] [FunLike F H G] [MonoidHomClass F H G] (f : F) : @IsTopologicalGroup H (induced f ‹_›) _ := letI := induced f ‹_› IsInducing.topologicalGroup f ⟨rfl⟩ namespace Subgroup @[to_additive] instance (S : Subgroup G) : IsTopologicalGroup S := IsInducing.subtypeVal.topologicalGroup S.subtype end Subgroup /-- The (topological-space) closure of a subgroup of a topological group is itself a subgroup. -/ @[to_additive "The (topological-space) closure of an additive subgroup of an additive topological group is itself an additive subgroup."] def Subgroup.topologicalClosure (s : Subgroup G) : Subgroup G := { s.toSubmonoid.topologicalClosure with carrier := _root_.closure (s : Set G) inv_mem' := fun {g} hg => by simpa only [← Set.mem_inv, inv_closure, inv_coe_set] using hg } @[to_additive (attr := simp)] theorem Subgroup.topologicalClosure_coe {s : Subgroup G} : (s.topologicalClosure : Set G) = _root_.closure s := rfl @[to_additive] theorem Subgroup.le_topologicalClosure (s : Subgroup G) : s ≤ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Subgroup.isClosed_topologicalClosure (s : Subgroup G) : IsClosed (s.topologicalClosure : Set G) := isClosed_closure @[to_additive] theorem Subgroup.topologicalClosure_minimal (s : Subgroup G) {t : Subgroup G} (h : s ≤ t) (ht : IsClosed (t : Set G)) : s.topologicalClosure ≤ t := closure_minimal h ht @[to_additive] theorem DenseRange.topologicalClosure_map_subgroup [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {f : G →* H} (hf : Continuous f) (hf' : DenseRange f) {s : Subgroup G} (hs : s.topologicalClosure = ⊤) : (s.map f).topologicalClosure = ⊤ := by rw [SetLike.ext'_iff] at hs ⊢ simp only [Subgroup.topologicalClosure_coe, Subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊢ exact hf'.dense_image hf hs /-- The topological closure of a normal subgroup is normal. -/ @[to_additive "The topological closure of a normal additive subgroup is normal."] theorem Subgroup.is_normal_topologicalClosure {G : Type*} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] (N : Subgroup G) [N.Normal] : (Subgroup.topologicalClosure N).Normal where conj_mem n hn g := by apply map_mem_closure (IsTopologicalGroup.continuous_conj g) hn exact fun m hm => Subgroup.Normal.conj_mem inferInstance m hm g @[to_additive] theorem mul_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] {g h : G} (hg : g ∈ connectedComponent (1 : G)) (hh : h ∈ connectedComponent (1 : G)) : g * h ∈ connectedComponent (1 : G) := by rw [connectedComponent_eq hg] have hmul : g ∈ connectedComponent (g * h) := by apply Continuous.image_connectedComponent_subset (continuous_mul_left g) rw [← connectedComponent_eq hh] exact ⟨(1 : G), mem_connectedComponent, by simp only [mul_one]⟩ simpa [← connectedComponent_eq hmul] using mem_connectedComponent @[to_additive] theorem inv_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [DivisionMonoid G] [ContinuousInv G] {g : G} (hg : g ∈ connectedComponent (1 : G)) : g⁻¹ ∈ connectedComponent (1 : G) := by rw [← inv_one] exact Continuous.image_connectedComponent_subset continuous_inv _ ((Set.mem_image _ _ _).mp ⟨g, hg, rfl⟩) /-- The connected component of 1 is a subgroup of `G`. -/ @[to_additive "The connected component of 0 is a subgroup of `G`."] def Subgroup.connectedComponentOfOne (G : Type*) [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : Subgroup G where carrier := connectedComponent (1 : G) one_mem' := mem_connectedComponent mul_mem' hg hh := mul_mem_connectedComponent_one hg hh inv_mem' hg := inv_mem_connectedComponent_one hg /-- If a subgroup of a topological group is commutative, then so is its topological closure. See note [reducible non-instances]. -/ @[to_additive "If a subgroup of an additive topological group is commutative, then so is its topological closure. See note [reducible non-instances]."] abbrev Subgroup.commGroupTopologicalClosure [T2Space G] (s : Subgroup G) (hs : ∀ x y : s, x * y = y * x) : CommGroup s.topologicalClosure := { s.topologicalClosure.toGroup, s.toSubmonoid.commMonoidTopologicalClosure hs with } variable (G) in @[to_additive] lemma Subgroup.coe_topologicalClosure_bot : ((⊥ : Subgroup G).topologicalClosure : Set G) = _root_.closure ({1} : Set G) := by simp @[to_additive exists_nhds_half_neg] theorem exists_nhds_split_inv {s : Set G} (hs : s ∈ 𝓝 (1 : G)) : ∃ V ∈ 𝓝 (1 : G), ∀ v ∈ V, ∀ w ∈ V, v / w ∈ s := by have : (fun p : G × G => p.1 * p.2⁻¹) ⁻¹' s ∈ 𝓝 ((1, 1) : G × G) := continuousAt_fst.mul continuousAt_snd.inv (by simpa) simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage] using this @[to_additive] theorem nhds_translation_mul_inv (x : G) : comap (· * x⁻¹) (𝓝 1) = 𝓝 x := ((Homeomorph.mulRight x⁻¹).comap_nhds_eq 1).trans <| show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x by simp @[to_additive (attr := simp)] theorem map_mul_left_nhds (x y : G) : map (x * ·) (𝓝 y) = 𝓝 (x * y) := (Homeomorph.mulLeft x).map_nhds_eq y @[to_additive] theorem map_mul_left_nhds_one (x : G) : map (x * ·) (𝓝 1) = 𝓝 x := by simp @[to_additive (attr := simp)] theorem map_mul_right_nhds (x y : G) : map (· * x) (𝓝 y) = 𝓝 (y * x) := (Homeomorph.mulRight x).map_nhds_eq y @[to_additive] theorem map_mul_right_nhds_one (x : G) : map (· * x) (𝓝 1) = 𝓝 x := by simp @[to_additive] theorem Filter.HasBasis.nhds_of_one {ι : Sort*} {p : ι → Prop} {s : ι → Set G} (hb : HasBasis (𝓝 1 : Filter G) p s) (x : G) : HasBasis (𝓝 x) p fun i => { y | y / x ∈ s i } := by rw [← nhds_translation_mul_inv] simp_rw [div_eq_mul_inv] exact hb.comap _ @[to_additive] theorem mem_closure_iff_nhds_one {x : G} {s : Set G} : x ∈ closure s ↔ ∀ U ∈ (𝓝 1 : Filter G), ∃ y ∈ s, y / x ∈ U := by rw [mem_closure_iff_nhds_basis ((𝓝 1 : Filter G).basis_sets.nhds_of_one x)] simp_rw [Set.mem_setOf, id] /-- A monoid homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) from a topological group to a topological monoid is continuous provided that it is continuous at one. See also `uniformContinuous_of_continuousAt_one`. -/ @[to_additive "An additive monoid homomorphism (a bundled morphism of a type that implements `AddMonoidHomClass`) from an additive topological group to an additive topological monoid is continuous provided that it is continuous at zero. See also `uniformContinuous_of_continuousAt_zero`."] theorem continuous_of_continuousAt_one {M hom : Type*} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] [FunLike hom G M] [MonoidHomClass hom G M] (f : hom) (hf : ContinuousAt f 1) : Continuous f := continuous_iff_continuousAt.2 fun x => by simpa only [ContinuousAt, ← map_mul_left_nhds_one x, tendsto_map'_iff, Function.comp_def, map_mul, map_one, mul_one] using hf.tendsto.const_mul (f x) @[to_additive continuous_of_continuousAt_zero₂] theorem continuous_of_continuousAt_one₂ {H M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] [Group H] [TopologicalSpace H] [IsTopologicalGroup H] (f : G →* H →* M) (hf : ContinuousAt (fun x : G × H ↦ f x.1 x.2) (1, 1)) (hl : ∀ x, ContinuousAt (f x) 1) (hr : ∀ y, ContinuousAt (f · y) 1) : Continuous (fun x : G × H ↦ f x.1 x.2) := continuous_iff_continuousAt.2 fun (x, y) => by simp only [ContinuousAt, nhds_prod_eq, ← map_mul_left_nhds_one x, ← map_mul_left_nhds_one y, prod_map_map_eq, tendsto_map'_iff, Function.comp_def, map_mul, MonoidHom.mul_apply] at * refine ((tendsto_const_nhds.mul ((hr y).comp tendsto_fst)).mul (((hl x).comp tendsto_snd).mul hf)).mono_right (le_of_eq ?_) simp only [map_one, mul_one, MonoidHom.one_apply] @[to_additive] lemma IsTopologicalGroup.isInducing_iff_nhds_one {H : Type*} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : Topology.IsInducing f ↔ 𝓝 (1 : G) = (𝓝 (1 : H)).comap f := by rw [Topology.isInducing_iff_nhds] refine ⟨(map_one f ▸ · 1), fun hf x ↦ ?_⟩ rw [← nhds_translation_mul_inv, ← nhds_translation_mul_inv (f x), Filter.comap_comap, hf, Filter.comap_comap] congr 1 ext; simp @[to_additive] lemma TopologicalGroup.isOpenMap_iff_nhds_one {H : Type*} [Monoid H] [TopologicalSpace H] [ContinuousConstSMul H H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : IsOpenMap f ↔ 𝓝 1 ≤ .map f (𝓝 1) := by refine ⟨fun H ↦ map_one f ▸ H.nhds_le 1, fun h ↦ IsOpenMap.of_nhds_le fun x ↦ ?_⟩ have : Filter.map (f x * ·) (𝓝 1) = 𝓝 (f x) := by simpa [-Homeomorph.map_nhds_eq, Units.smul_def] using (Homeomorph.smul ((toUnits x).map (MonoidHomClass.toMonoidHom f))).map_nhds_eq (1 : H) rw [← map_mul_left_nhds_one x, Filter.map_map, Function.comp_def, ← this] refine (Filter.map_mono h).trans ?_ simp [Function.comp_def] -- TODO: unify with `QuotientGroup.isOpenQuotientMap_mk` /-- Let `A` and `B` be topological groups, and let `φ : A → B` be a continuous surjective group homomorphism. Assume furthermore that `φ` is a quotient map (i.e., `V ⊆ B` is open iff `φ⁻¹ V` is open). Then `φ` is an open quotient map, and in particular an open map. -/ @[to_additive "Let `A` and `B` be topological additive groups, and let `φ : A → B` be a continuous surjective additive group homomorphism. Assume furthermore that `φ` is a quotient map (i.e., `V ⊆ B` is open iff `φ⁻¹ V` is open). Then `φ` is an open quotient map, and in particular an open map."] lemma MonoidHom.isOpenQuotientMap_of_isQuotientMap {A : Type*} [Group A] [TopologicalSpace A] [ContinuousMul A] {B : Type*} [Group B] [TopologicalSpace B] {F : Type*} [FunLike F A B] [MonoidHomClass F A B] {φ : F} (hφ : IsQuotientMap φ) : IsOpenQuotientMap φ where surjective := hφ.surjective continuous := hφ.continuous isOpenMap := by -- We need to check that if `U ⊆ A` is open then `φ⁻¹ (φ U)` is open. intro U hU rw [← hφ.isOpen_preimage] -- It suffices to show that `φ⁻¹ (φ U) = ⋃ (U * k⁻¹)` as `k` runs through the kernel of `φ`, -- as `U * k⁻¹` is open because `x ↦ x * k` is continuous. -- Remark: here is where we use that we have groups not monoids (you cannot avoid -- using both `k` and `k⁻¹` at this point). suffices ⇑φ ⁻¹' (⇑φ '' U) = ⋃ k ∈ ker (φ : A →* B), (fun x ↦ x * k) ⁻¹' U by exact this ▸ isOpen_biUnion (fun k _ ↦ Continuous.isOpen_preimage (by fun_prop) _ hU) ext x -- But this is an elementary calculation. constructor · rintro ⟨y, hyU, hyx⟩ apply Set.mem_iUnion_of_mem (x⁻¹ * y) simp_all · rintro ⟨_, ⟨k, rfl⟩, _, ⟨(hk : φ k = 1), rfl⟩, hx⟩ use x * k, hx rw [map_mul, hk, mul_one] @[to_additive] theorem IsTopologicalGroup.ext {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := TopologicalSpace.ext_nhds fun x ↦ by rw [← @nhds_translation_mul_inv G t _ _ x, ← @nhds_translation_mul_inv G t' _ _ x, ← h] @[to_additive] theorem IsTopologicalGroup.ext_iff {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) : t = t' ↔ @nhds G t 1 = @nhds G t' 1 := ⟨fun h => h ▸ rfl, tg.ext tg'⟩ @[to_additive] theorem ContinuousInv.of_nhds_one {G : Type*} [Group G] [TopologicalSpace G] (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x : G => x₀ * x) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (fun x : G => x₀ * x * x₀⁻¹) (𝓝 1) (𝓝 1)) : ContinuousInv G := by refine ⟨continuous_iff_continuousAt.2 fun x₀ => ?_⟩ have : Tendsto (fun x => x₀⁻¹ * (x₀ * x⁻¹ * x₀⁻¹)) (𝓝 1) (map (x₀⁻¹ * ·) (𝓝 1)) := (tendsto_map.comp <| hconj x₀).comp hinv simpa only [ContinuousAt, hleft x₀, hleft x₀⁻¹, tendsto_map'_iff, Function.comp_def, mul_assoc, mul_inv_rev, inv_mul_cancel_left] using this @[to_additive] theorem IsTopologicalGroup.of_nhds_one' {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1)) (hright : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x * x₀) (𝓝 1)) : IsTopologicalGroup G := { toContinuousMul := ContinuousMul.of_nhds_one hmul hleft hright toContinuousInv := ContinuousInv.of_nhds_one hinv hleft fun x₀ => le_of_eq (by rw [show (fun x => x₀ * x * x₀⁻¹) = (fun x => x * x₀⁻¹) ∘ fun x => x₀ * x from rfl, ← map_map, ← hleft, hright, map_map] simp [(· ∘ ·)]) } @[to_additive] theorem IsTopologicalGroup.of_nhds_one {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (x₀ * · * x₀⁻¹) (𝓝 1) (𝓝 1)) : IsTopologicalGroup G := by refine IsTopologicalGroup.of_nhds_one' hmul hinv hleft fun x₀ => ?_ replace hconj : ∀ x₀ : G, map (x₀ * · * x₀⁻¹) (𝓝 1) = 𝓝 1 := fun x₀ => map_eq_of_inverse (x₀⁻¹ * · * x₀⁻¹⁻¹) (by ext; simp [mul_assoc]) (hconj _) (hconj _) rw [← hconj x₀] simpa [Function.comp_def] using hleft _ @[to_additive] theorem IsTopologicalGroup.of_comm_of_nhds_one {G : Type u} [CommGroup G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) : IsTopologicalGroup G := IsTopologicalGroup.of_nhds_one hmul hinv hleft (by simpa using tendsto_id) variable (G) in /-- Any first countable topological group has an antitone neighborhood basis `u : ℕ → Set G` for which `(u (n + 1)) ^ 2 ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientGroup.completeSpace` -/ @[to_additive "Any first countable topological additive group has an antitone neighborhood basis `u : ℕ → set G` for which `u (n + 1) + u (n + 1) ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientAddGroup.completeSpace`"] theorem IsTopologicalGroup.exists_antitone_basis_nhds_one [FirstCountableTopology G] : ∃ u : ℕ → Set G, (𝓝 1).HasAntitoneBasis u ∧ ∀ n, u (n + 1) * u (n + 1) ⊆ u n := by rcases (𝓝 (1 : G)).exists_antitone_basis with ⟨u, hu, u_anti⟩ have := ((hu.prod_nhds hu).tendsto_iff hu).mp (by simpa only [mul_one] using continuous_mul.tendsto ((1, 1) : G × G)) simp only [and_self_iff, mem_prod, and_imp, Prod.forall, exists_true_left, Prod.exists, forall_true_left] at this have event_mul : ∀ n : ℕ, ∀ᶠ m in atTop, u m * u m ⊆ u n := by intro n rcases this n with ⟨j, k, -, h⟩ refine atTop_basis.eventually_iff.mpr ⟨max j k, True.intro, fun m hm => ?_⟩ rintro - ⟨a, ha, b, hb, rfl⟩ exact h a b (u_anti ((le_max_left _ _).trans hm) ha) (u_anti ((le_max_right _ _).trans hm) hb) obtain ⟨φ, -, hφ, φ_anti_basis⟩ := HasAntitoneBasis.subbasis_with_rel ⟨hu, u_anti⟩ event_mul exact ⟨u ∘ φ, φ_anti_basis, fun n => hφ n.lt_succ_self⟩ end IsTopologicalGroup section ContinuousDiv variable [TopologicalSpace G] [Div G] [ContinuousDiv G] @[to_additive const_sub] theorem Filter.Tendsto.const_div' (b : G) {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) : Tendsto (fun k : α => b / f k) l (𝓝 (b / c)) := tendsto_const_nhds.div' h @[to_additive] lemma Filter.tendsto_const_div_iff {G : Type*} [CommGroup G] [TopologicalSpace G] [ContinuousDiv G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (fun k : α ↦ b / f k) l (𝓝 (b / c)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, Filter.Tendsto.const_div' b⟩ convert h.const_div' b with k <;> rw [div_div_cancel] @[to_additive sub_const] theorem Filter.Tendsto.div_const' {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) (b : G) : Tendsto (f · / b) l (𝓝 (c / b)) := h.div' tendsto_const_nhds lemma Filter.tendsto_div_const_iff {G : Type*} [CommGroupWithZero G] [TopologicalSpace G] [ContinuousDiv G] {b : G} (hb : b ≠ 0) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · / b) l (𝓝 (c / b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.div_const' h b⟩ convert h.div_const' b⁻¹ with k <;> rw [div_div, mul_inv_cancel₀ hb, div_one] lemma Filter.tendsto_sub_const_iff {G : Type*} [AddCommGroup G] [TopologicalSpace G] [ContinuousSub G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · - b) l (𝓝 (c - b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.sub_const h b⟩ convert h.sub_const (-b) with k <;> rw [sub_sub, ← sub_eq_add_neg, sub_self, sub_zero] variable [TopologicalSpace α] {f g : α → G} {s : Set α} {x : α} @[to_additive (attr := continuity) continuous_sub_left] lemma continuous_div_left' (a : G) : Continuous (a / ·) := continuous_const.div' continuous_id @[to_additive (attr := continuity) continuous_sub_right] lemma continuous_div_right' (a : G) : Continuous (· / a) := continuous_id.div' continuous_const end ContinuousDiv section DivInvTopologicalGroup variable [Group G] [TopologicalSpace G] [IsTopologicalGroup G] /-- A version of `Homeomorph.mulLeft a b⁻¹` that is defeq to `a / b`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addLeft a (-b)` that is defeq to `a - b`."] def Homeomorph.divLeft (x : G) : G ≃ₜ G := { Equiv.divLeft x with continuous_toFun := continuous_const.div' continuous_id continuous_invFun := continuous_inv.mul continuous_const } @[to_additive] theorem isOpenMap_div_left (a : G) : IsOpenMap (a / ·) := (Homeomorph.divLeft _).isOpenMap @[to_additive] theorem isClosedMap_div_left (a : G) : IsClosedMap (a / ·) := (Homeomorph.divLeft _).isClosedMap /-- A version of `Homeomorph.mulRight a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addRight (-a) b` that is defeq to `b - a`. "] def Homeomorph.divRight (x : G) : G ≃ₜ G := { Equiv.divRight x with continuous_toFun := continuous_id.div' continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive] lemma isOpenMap_div_right (a : G) : IsOpenMap (· / a) := (Homeomorph.divRight a).isOpenMap @[to_additive] lemma isClosedMap_div_right (a : G) : IsClosedMap (· / a) := (Homeomorph.divRight a).isClosedMap @[to_additive] theorem tendsto_div_nhds_one_iff {α : Type*} {l : Filter α} {x : G} {u : α → G} : Tendsto (u · / x) l (𝓝 1) ↔ Tendsto u l (𝓝 x) := haveI A : Tendsto (fun _ : α => x) l (𝓝 x) := tendsto_const_nhds ⟨fun h => by simpa using h.mul A, fun h => by simpa using h.div' A⟩ @[to_additive] theorem nhds_translation_div (x : G) : comap (· / x) (𝓝 1) = 𝓝 x := by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x end DivInvTopologicalGroup section FilterMul section variable (G) [TopologicalSpace G] [Group G] [ContinuousMul G] @[to_additive] theorem IsTopologicalGroup.t1Space (h : @IsClosed G _ {1}) : T1Space G := ⟨fun x => by simpa using isClosedMap_mul_right x _ h⟩ end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] variable (S : Subgroup G) [Subgroup.Normal S] [IsClosed (S : Set G)] /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`."] theorem Subgroup.properlyDiscontinuousSMul_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S G := { finite_disjoint_inter_image := by intro K L hK hL have H : Set.Finite _ := hS ((hL.prod hK).image continuous_div').compl_mem_cocompact rw [preimage_compl, compl_compl] at H convert H ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.smul_inter_ne_empty_iff' } /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousSMul_of_t2Space` to show that the quotient group `G ⧸ S` is Hausdorff. -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousVAdd_of_t2Space` to show that the quotient group `G ⧸ S` is Hausdorff."] theorem Subgroup.properlyDiscontinuousSMul_opposite_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S.op G := { finite_disjoint_inter_image := by intro K L hK hL have : Continuous fun p : G × G => (p.1⁻¹, p.2) := continuous_inv.prodMap continuous_id have H : Set.Finite _ := hS ((hK.prod hL).image (continuous_mul.comp this)).compl_mem_cocompact simp only [preimage_compl, compl_compl, coe_subtype, comp_apply] at H apply Finite.of_preimage _ (equivOp S).surjective convert H using 1 ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.op_smul_inter_ne_empty_iff } end section /-! Some results about an open set containing the product of two sets in a topological group. -/ variable [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `K * V ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `K + V ⊆ U`."] theorem compact_open_separated_mul_right {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), K * V ⊆ U := by refine hK.induction_on ?_ ?_ ?_ ?_ · exact ⟨univ, by simp⟩ · rintro s t hst ⟨V, hV, hV'⟩ exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ · rintro s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩ use V ∩ W, inter_mem V_in W_in rw [union_mul] exact union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV') ((mul_subset_mul_left V.inter_subset_right).trans hW') · intro x hx have := tendsto_mul (show U ∈ 𝓝 (x * 1) by simpa using hU.mem_nhds (hKU hx)) rw [nhds_prod_eq, mem_map, mem_prod_iff] at this rcases this with ⟨t, ht, s, hs, h⟩ rw [← image_subset_iff, image_mul_prod] at h exact ⟨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, h⟩ open MulOpposite /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `V * K ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `V + K ⊆ U`."] theorem compact_open_separated_mul_left {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), V * K ⊆ U := by rcases compact_open_separated_mul_right (hK.image continuous_op) (opHomeomorph.isOpenMap U hU) (image_subset op hKU) with ⟨V, hV : V ∈ 𝓝 (op (1 : G)), hV' : op '' K * V ⊆ op '' U⟩ refine ⟨op ⁻¹' V, continuous_op.continuousAt hV, ?_⟩ rwa [← image_preimage_eq V op_surjective, ← image_op_mul, image_subset_iff, preimage_image_eq _ op_injective] at hV' end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] /-- A compact set is covered by finitely many left multiplicative translates of a set with non-empty interior. -/ @[to_additive "A compact set is covered by finitely many left additive translates of a set with non-empty interior."] theorem compact_covered_by_mul_left_translates {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ t : Finset G, K ⊆ ⋃ g ∈ t, (g * ·) ⁻¹' V := by obtain ⟨t, ht⟩ : ∃ t : Finset G, K ⊆ ⋃ x ∈ t, interior ((x * ·) ⁻¹' V) := by refine hK.elim_finite_subcover (fun x => interior <| (x * ·) ⁻¹' V) (fun x => isOpen_interior) ?_ obtain ⟨g₀, hg₀⟩ := hV refine fun g _ => mem_iUnion.2 ⟨g₀ * g⁻¹, ?_⟩ refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) ?_ rwa [mem_preimage, Function.id_def, inv_mul_cancel_right] exact ⟨t, Subset.trans ht <| iUnion₂_mono fun g _ => interior_subset⟩ /-- Every weakly locally compact separable topological group is σ-compact. Note: this is not true if we drop the topological group hypothesis. -/ @[to_additive SeparableWeaklyLocallyCompactAddGroup.sigmaCompactSpace "Every weakly locally compact separable topological additive group is σ-compact. Note: this is not true if we drop the topological group hypothesis."] instance (priority := 100) SeparableWeaklyLocallyCompactGroup.sigmaCompactSpace [SeparableSpace G] [WeaklyLocallyCompactSpace G] : SigmaCompactSpace G := by obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G) refine ⟨⟨fun n => (fun x => x * denseSeq G n) ⁻¹' L, ?_, ?_⟩⟩ · intro n exact (Homeomorph.mulRight _).isCompact_preimage.mpr hLc · refine iUnion_eq_univ_iff.2 fun x => ?_ obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (denseSeq G) ∩ (fun y => x * y) ⁻¹' L).Nonempty := by rw [← (Homeomorph.mulLeft x).apply_symm_apply 1] at hL1 exact (denseRange_denseSeq G).inter_nhds_nonempty ((Homeomorph.mulLeft x).continuous.continuousAt <| hL1) exact ⟨n, hn⟩ /-- Given two compact sets in a noncompact topological group, there is a translate of the second one that is disjoint from the first one. -/ @[to_additive "Given two compact sets in a noncompact additive topological group, there is a translate of the second one that is disjoint from the first one."] theorem exists_disjoint_smul_of_isCompact [NoncompactSpace G] {K L : Set G} (hK : IsCompact K) (hL : IsCompact L) : ∃ g : G, Disjoint K (g • L) := by have A : ¬K * L⁻¹ = univ := (hK.mul hL.inv).ne_univ obtain ⟨g, hg⟩ : ∃ g, g ∉ K * L⁻¹ := by contrapose! A exact eq_univ_iff_forall.2 A refine ⟨g, ?_⟩ refine disjoint_left.2 fun a ha h'a => hg ?_ rcases h'a with ⟨b, bL, rfl⟩ refine ⟨g * b, ha, b⁻¹, by simpa only [Set.mem_inv, inv_inv] using bL, ?_⟩ simp only [smul_eq_mul, mul_inv_cancel_right] end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] @[to_additive] theorem nhds_mul (x y : G) : 𝓝 (x * y) = 𝓝 x * 𝓝 y := calc 𝓝 (x * y) = map (x * ·) (map (· * y) (𝓝 1 * 𝓝 1)) := by simp _ = map₂ (fun a b => x * (a * b * y)) (𝓝 1) (𝓝 1) := by rw [← map₂_mul, map_map₂, map_map₂] _ = map₂ (fun a b => x * a * (b * y)) (𝓝 1) (𝓝 1) := by simp only [mul_assoc] _ = 𝓝 x * 𝓝 y := by rw [← map_mul_left_nhds_one x, ← map_mul_right_nhds_one y, ← map₂_mul, map₂_map_left, map₂_map_right] /-- On a topological group, `𝓝 : G → Filter G` can be promoted to a `MulHom`. -/ @[to_additive (attr := simps) "On an additive topological group, `𝓝 : G → Filter G` can be promoted to an `AddHom`."] def nhdsMulHom : G →ₙ* Filter G where toFun := 𝓝 map_mul' _ _ := nhds_mul _ _ end end FilterMul instance {G} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : IsTopologicalAddGroup (Additive G) where continuous_neg := @continuous_inv G _ _ _ instance {G} [TopologicalSpace G] [AddGroup G] [IsTopologicalAddGroup G] : IsTopologicalGroup (Multiplicative G) where continuous_inv := @continuous_neg G _ _ _ /-- If `G` is a group with topological `⁻¹`, then it is homeomorphic to its units. -/ @[to_additive "If `G` is an additive group with topological negation, then it is homeomorphic to its additive units."] def toUnits_homeomorph [Group G] [TopologicalSpace G] [ContinuousInv G] : G ≃ₜ Gˣ where toEquiv := toUnits.toEquiv continuous_toFun := Units.continuous_iff.2 ⟨continuous_id, continuous_inv⟩ continuous_invFun := Units.continuous_val @[to_additive] theorem Units.isEmbedding_val [Group G] [TopologicalSpace G] [ContinuousInv G] : IsEmbedding (val : Gˣ → G) := toUnits_homeomorph.symm.isEmbedding @[deprecated (since := "2024-10-26")] alias Units.embedding_val := Units.isEmbedding_val lemma Continuous.of_coeHom_comp [Group G] [Monoid H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv G] {f : G →* Hˣ} (hf : Continuous ((Units.coeHom H).comp f)) : Continuous f := by apply continuous_induced_rng.mpr ?_ refine continuous_prodMk.mpr ⟨hf, ?_⟩ simp_rw [← map_inv] exact MulOpposite.continuous_op.comp (hf.comp continuous_inv) namespace Units open MulOpposite (continuous_op continuous_unop) variable [Monoid α] [TopologicalSpace α] [Monoid β] [TopologicalSpace β] @[to_additive] instance [ContinuousMul α] : IsTopologicalGroup αˣ where continuous_inv := Units.continuous_iff.2 <| ⟨continuous_coe_inv, continuous_val⟩ /-- The topological group isomorphism between the units of a product of two monoids, and the product of the units of each monoid. -/ @[to_additive prodAddUnits "The topological group isomorphism between the additive units of a product of two additive monoids, and the product of the additive units of each additive monoid."] def _root_.Homeomorph.prodUnits : (α × β)ˣ ≃ₜ αˣ × βˣ where continuous_toFun := (continuous_fst.units_map (MonoidHom.fst α β)).prodMk (continuous_snd.units_map (MonoidHom.snd α β)) continuous_invFun := Units.continuous_iff.2 ⟨continuous_val.fst'.prodMk continuous_val.snd', continuous_coe_inv.fst'.prodMk continuous_coe_inv.snd'⟩ toEquiv := MulEquiv.prodUnits.toEquiv @[deprecated (since := "2025-02-21")] alias Homeomorph.sumAddUnits := Homeomorph.prodAddUnits @[deprecated (since := "2025-02-21")] protected alias Homeomorph.prodUnits := Homeomorph.prodUnits end Units section LatticeOps variable {ι : Sort*} [Group G] @[to_additive] theorem topologicalGroup_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @IsTopologicalGroup G t _) : @IsTopologicalGroup G (sInf ts) _ := letI := sInf ts { toContinuousInv := @continuousInv_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousInv G t _ <| h t ht toContinuousMul := @continuousMul_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousMul G t _ <| h t ht } @[to_additive] theorem topologicalGroup_iInf {ts' : ι → TopologicalSpace G} (h' : ∀ i, @IsTopologicalGroup G (ts' i) _) : @IsTopologicalGroup G (⨅ i, ts' i) _ := by rw [← sInf_range] exact topologicalGroup_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem topologicalGroup_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @IsTopologicalGroup G t₁ _) (h₂ : @IsTopologicalGroup G t₂ _) : @IsTopologicalGroup G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine topologicalGroup_iInf fun b => ?_ cases b <;> assumption end LatticeOps
Mathlib/Topology/Algebra/Group/Basic.lean
1,860
1,866
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.Kaehler.Basic import Mathlib.Algebra.MvPolynomial.PDeriv import Mathlib.Algebra.Polynomial.Derivation /-! # The Kaehler differential module of polynomial algebras -/ open scoped TensorProduct open Algebra universe u v variable (R : Type u) [CommRing R] suppress_compilation section MvPolynomial /-- The relative differential module of a polynomial algebra `R[σ]` is the free module generated by `{ dx | x ∈ σ }`. Also see `KaehlerDifferential.mvPolynomialBasis`. -/ def KaehlerDifferential.mvPolynomialEquiv (σ : Type*) : Ω[MvPolynomial σ R⁄R] ≃ₗ[MvPolynomial σ R] σ →₀ MvPolynomial σ R where __ := (MvPolynomial.mkDerivation _ (Finsupp.single · 1)).liftKaehlerDifferential invFun := Finsupp.linearCombination (α := σ) _ (fun x ↦ D _ _ (MvPolynomial.X x)) right_inv := by intro x induction x using Finsupp.induction_linear with | zero => simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom]; rw [map_zero, map_zero] | add => simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, map_add] at *; simp only [*] | single a b => simp [LinearMap.map_smul, -map_smul] left_inv := by intro x obtain ⟨x, rfl⟩ := linearCombination_surjective _ _ x induction x using Finsupp.induction_linear with | zero => simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom] rw [map_zero, map_zero, map_zero] | add => simp only [map_add, AddHom.toFun_eq_coe, LinearMap.coe_toAddHom] at *; simp only [*] | single a b => simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Finsupp.linearCombination_single, LinearMap.map_smul, Derivation.liftKaehlerDifferential_comp_D] congr 1 induction a using MvPolynomial.induction_on · simp only [MvPolynomial.derivation_C, map_zero] · simp only [map_add, *] · simp [*] /-- `{ dx | x ∈ σ }` forms a basis of the relative differential module of a polynomial algebra `R[σ]`. -/ def KaehlerDifferential.mvPolynomialBasis (σ) : Basis σ (MvPolynomial σ R) (Ω[MvPolynomial σ R⁄R]) := ⟨mvPolynomialEquiv R σ⟩ lemma KaehlerDifferential.mvPolynomialBasis_repr_comp_D (σ) : (mvPolynomialBasis R σ).repr.toLinearMap.compDer (D _ _) = MvPolynomial.mkDerivation _ (Finsupp.single · 1) := Derivation.liftKaehlerDifferential_comp _ lemma KaehlerDifferential.mvPolynomialBasis_repr_D (σ) (x) : (mvPolynomialBasis R σ).repr (D _ _ x) = MvPolynomial.mkDerivation R (Finsupp.single · (1 : MvPolynomial σ R)) x := Derivation.congr_fun (mvPolynomialBasis_repr_comp_D R σ) x @[simp] lemma KaehlerDifferential.mvPolynomialBasis_repr_D_X (σ) (i) : (mvPolynomialBasis R σ).repr (D _ _ (.X i)) = Finsupp.single i 1 := by simp [mvPolynomialBasis_repr_D] @[simp] lemma KaehlerDifferential.mvPolynomialBasis_repr_apply (σ) (x) (i) : (mvPolynomialBasis R σ).repr (D _ _ x) i = MvPolynomial.pderiv i x := by classical suffices ((Finsupp.lapply i).comp (mvPolynomialBasis R σ).repr.toLinearMap).compDer (D _ _) = MvPolynomial.pderiv i by rw [← this]; rfl apply MvPolynomial.derivation_ext intro j simp [Finsupp.single_apply, Pi.single_apply] lemma KaehlerDifferential.mvPolynomialBasis_repr_symm_single (σ) (i) (x) : (mvPolynomialBasis R σ).repr.symm (Finsupp.single i x) = x • D R (MvPolynomial σ R) (.X i) := by apply (mvPolynomialBasis R σ).repr.injective; simp [LinearEquiv.map_smul, -map_smul] @[simp] lemma KaehlerDifferential.mvPolynomialBasis_apply (σ) (i) : mvPolynomialBasis R σ i = D R (MvPolynomial σ R) (.X i) := (mvPolynomialBasis_repr_symm_single R σ i 1).trans (one_smul _ _) instance (σ) : Module.Free (MvPolynomial σ R) (Ω[MvPolynomial σ R⁄R]) := .of_basis (KaehlerDifferential.mvPolynomialBasis R σ) end MvPolynomial section Polynomial
open Polynomial
Mathlib/RingTheory/Kaehler/Polynomial.lean
101
103
/- 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.RingTheory.WittVector.Truncated import Mathlib.RingTheory.WittVector.Identities import Mathlib.NumberTheory.Padics.RingHoms /-! # Comparison isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]` We construct a ring isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`. This isomorphism follows from the fact that both satisfy the universal property of the inverse limit of `ZMod (p^n)`. ## Main declarations * `WittVector.toZModPow`: a family of compatible ring homs `𝕎 (ZMod p) → ZMod (p^k)` * `WittVector.equiv`: the isomorphism ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable section variable {p : ℕ} [hp : Fact p.Prime] local notation "𝕎" => WittVector p namespace TruncatedWittVector variable (p) (n : ℕ) (R : Type*) [CommRing R] theorem eq_of_le_of_cast_pow_eq_zero [CharP R p] (i : ℕ) (hin : i ≤ n) (hpi : (p : TruncatedWittVector p n R) ^ i = 0) : i = n := by contrapose! hpi replace hin := lt_of_le_of_ne hin hpi; clear hpi have : (p : TruncatedWittVector p n R) ^ i = WittVector.truncate n ((p : 𝕎 R) ^ i) := by rw [RingHom.map_pow, map_natCast] rw [this, ne_eq, TruncatedWittVector.ext_iff, not_forall]; clear this use ⟨i, hin⟩ rw [WittVector.coeff_truncate, coeff_zero, Fin.val_mk, WittVector.coeff_p_pow] haveI : Nontrivial R := CharP.nontrivial_of_char_ne_one hp.1.ne_one exact one_ne_zero section Iso variable {R} theorem card_zmod : Fintype.card (TruncatedWittVector p n (ZMod p)) = p ^ n := by rw [card, ZMod.card] theorem charP_zmod : CharP (TruncatedWittVector p n (ZMod p)) (p ^ n) := charP_of_prime_pow_injective _ _ _ (card_zmod _ _) (eq_of_le_of_cast_pow_eq_zero p n (ZMod p)) attribute [local instance] charP_zmod /-- The unique isomorphism between `ZMod p^n` and `TruncatedWittVector p n (ZMod p)`. This isomorphism exists, because `TruncatedWittVector p n (ZMod p)` is a finite ring with characteristic and cardinality `p^n`. -/ def zmodEquivTrunc : ZMod (p ^ n) ≃+* TruncatedWittVector p n (ZMod p) := ZMod.ringEquiv (TruncatedWittVector p n (ZMod p)) (card_zmod _ _) theorem zmodEquivTrunc_apply {x : ZMod (p ^ n)} : zmodEquivTrunc p n x = ZMod.castHom (m := p ^ n) (by rfl) (TruncatedWittVector p n (ZMod p)) x := rfl /-- The following diagram commutes: ```text ZMod (p^n) ----------------------------> ZMod (p^m) | | | | v v TruncatedWittVector p n (ZMod p) ----> TruncatedWittVector p m (ZMod p) ``` Here the vertical arrows are `TruncatedWittVector.zmodEquivTrunc`, the horizontal arrow at the top is `ZMod.castHom`, and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`. -/ theorem commutes {m : ℕ} (hm : n ≤ m) : (truncate hm).comp (zmodEquivTrunc p m).toRingHom = (zmodEquivTrunc p n).toRingHom.comp (ZMod.castHom (pow_dvd_pow p hm) _) := RingHom.ext_zmod _ _ theorem commutes' {m : ℕ} (hm : n ≤ m) (x : ZMod (p ^ m)) : truncate hm (zmodEquivTrunc p m x) = zmodEquivTrunc p n (ZMod.castHom (pow_dvd_pow p hm) _ x) := show (truncate hm).comp (zmodEquivTrunc p m).toRingHom x = _ by rw [commutes _ _ hm]; rfl theorem commutes_symm' {m : ℕ} (hm : n ≤ m) (x : TruncatedWittVector p m (ZMod p)) : (zmodEquivTrunc p n).symm (truncate hm x) = ZMod.castHom (pow_dvd_pow p hm) _ ((zmodEquivTrunc p m).symm x) := by apply (zmodEquivTrunc p n).injective rw [← commutes' _ _ hm] simp /-- The following diagram commutes: ```text TruncatedWittVector p n (ZMod p) ----> TruncatedWittVector p m (ZMod p) | | | | v v ZMod (p^n) ----------------------------> ZMod (p^m) ``` Here the vertical arrows are `(TruncatedWittVector.zmodEquivTrunc p _).symm`, the horizontal arrow at the top is `ZMod.castHom`, and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`. -/ theorem commutes_symm {m : ℕ} (hm : n ≤ m) : (zmodEquivTrunc p n).symm.toRingHom.comp (truncate hm) = (ZMod.castHom (pow_dvd_pow p hm) _).comp (zmodEquivTrunc p m).symm.toRingHom := by ext; apply commutes_symm' end Iso end TruncatedWittVector namespace WittVector open TruncatedWittVector variable (p) /-- `toZModPow` is a family of compatible ring homs. We get this family by composing `TruncatedWittVector.zmodEquivTrunc` (in right-to-left direction) with `WittVector.truncate`. -/ def toZModPow (k : ℕ) : 𝕎 (ZMod p) →+* ZMod (p ^ k) := (zmodEquivTrunc p k).symm.toRingHom.comp (truncate k) theorem toZModPow_compat (m n : ℕ) (h : m ≤ n) : (ZMod.castHom (pow_dvd_pow p h) (ZMod (p ^ m))).comp (toZModPow p n) = toZModPow p m := calc (ZMod.castHom _ (ZMod (p ^ m))).comp ((zmodEquivTrunc p n).symm.toRingHom.comp (truncate n)) _ = ((zmodEquivTrunc p m).symm.toRingHom.comp (TruncatedWittVector.truncate h)).comp (truncate n) := by rw [commutes_symm, RingHom.comp_assoc] _ = (zmodEquivTrunc p m).symm.toRingHom.comp (truncate m) := by rw [RingHom.comp_assoc, truncate_comp_wittVector_truncate] /-- `toPadicInt` lifts `toZModPow : 𝕎 (ZMod p) →+* ZMod (p ^ k)` to a ring hom to `ℤ_[p]` using `PadicInt.lift`, the universal property of `ℤ_[p]`. -/ def toPadicInt : 𝕎 (ZMod p) →+* ℤ_[p] := PadicInt.lift <| toZModPow_compat p theorem zmodEquivTrunc_compat (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂) : (TruncatedWittVector.truncate hk).comp ((zmodEquivTrunc p k₂).toRingHom.comp (PadicInt.toZModPow k₂)) = (zmodEquivTrunc p k₁).toRingHom.comp (PadicInt.toZModPow k₁) := by rw [← RingHom.comp_assoc, commutes, RingHom.comp_assoc, PadicInt.zmod_cast_comp_toZModPow _ _ hk] /-- `fromPadicInt` uses `WittVector.lift` to lift `TruncatedWittVector.zmodEquivTrunc` composed with `PadicInt.toZModPow` to a ring hom `ℤ_[p] →+* 𝕎 (ZMod p)`. -/ def fromPadicInt : ℤ_[p] →+* 𝕎 (ZMod p) := (WittVector.lift fun k => (zmodEquivTrunc p k).toRingHom.comp (PadicInt.toZModPow k)) <| zmodEquivTrunc_compat _ theorem toPadicInt_comp_fromPadicInt : (toPadicInt p).comp (fromPadicInt p) = RingHom.id ℤ_[p] := by rw [← PadicInt.toZModPow_eq_iff_ext] intro n rw [← RingHom.comp_assoc, toPadicInt, PadicInt.lift_spec] simp only [fromPadicInt, toZModPow, RingHom.comp_id] rw [RingHom.comp_assoc, truncate_comp_lift, ← RingHom.comp_assoc] simp only [RingEquiv.symm_toRingHom_comp_toRingHom, RingHom.id_comp] theorem toPadicInt_comp_fromPadicInt_ext (x) : (toPadicInt p).comp (fromPadicInt p) x = RingHom.id ℤ_[p] x := by rw [toPadicInt_comp_fromPadicInt] theorem fromPadicInt_comp_toPadicInt : (fromPadicInt p).comp (toPadicInt p) = RingHom.id (𝕎 (ZMod p)) := by apply WittVector.hom_ext intro n rw [fromPadicInt, ← RingHom.comp_assoc, truncate_comp_lift, RingHom.comp_assoc] simp only [toPadicInt, toZModPow, RingHom.comp_id, PadicInt.lift_spec, RingHom.id_comp, ← RingHom.comp_assoc, RingEquiv.toRingHom_comp_symm_toRingHom] theorem fromPadicInt_comp_toPadicInt_ext (x) : (fromPadicInt p).comp (toPadicInt p) x = RingHom.id (𝕎 (ZMod p)) x := by rw [fromPadicInt_comp_toPadicInt] /-- The ring of Witt vectors over `ZMod p` is isomorphic to the ring of `p`-adic integers. This equivalence is witnessed by `WittVector.toPadicInt` with inverse `WittVector.fromPadicInt`. -/ def equiv : 𝕎 (ZMod p) ≃+* ℤ_[p] where toFun := toPadicInt p
invFun := fromPadicInt p left_inv := fromPadicInt_comp_toPadicInt_ext _ right_inv := toPadicInt_comp_fromPadicInt_ext _ map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ end WittVector
Mathlib/RingTheory/WittVector/Compare.lean
197
203
/- Copyright (c) 2017 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Tactic.Attr.Register import Mathlib.Data.Set.Defs import Mathlib.Tactic.TypeStar import Batteries.Tactic.Lint /-! # Functors This module provides additional lemmas, definitions, and instances for `Functor`s. ## Main definitions * `Functor.Const α` is the functor that sends all types to `α`. * `Functor.AddConst α` is `Functor.Const α` but for when `α` has an additive structure. * `Functor.Comp F G` for functors `F` and `G` is the functor composition of `F` and `G`. * `Liftp` and `Liftr` respectively lift predicates and relations on a type `α` to `F α`. Terms of `F α` are considered to, in some sense, contain values of type `α`. ## Tags functor, applicative -/ universe u v w section Functor variable {F : Type u → Type v} variable {α β γ : Type u} variable [Functor F] [LawfulFunctor F] theorem Functor.map_id : (id <$> ·) = (id : F α → F α) := funext id_map theorem Functor.map_comp_map (f : α → β) (g : β → γ) : ((g <$> ·) ∘ (f <$> ·) : F α → F γ) = ((g ∘ f) <$> ·) := funext fun _ => (comp_map _ _ _).symm -- Porting note: was `apply funext <;> intro <;> rw [comp_map]` but `rw` failed? theorem Functor.ext {F} : ∀ {F1 : Functor F} {F2 : Functor F} [@LawfulFunctor F F1] [@LawfulFunctor F F2], (∀ (α β) (f : α → β) (x : F α), @Functor.map _ F1 _ _ f x = @Functor.map _ F2 _ _ f x) → F1 = F2
| ⟨m, mc⟩, ⟨m', mc'⟩, H1, H2, H => by cases show @m = @m' by funext α β f x; apply H congr funext α β have E1 := @map_const _ ⟨@m, @mc⟩ H1 have E2 := @map_const _ ⟨@m, @mc'⟩ H2 exact E1.trans E2.symm end Functor /-- Introduce `id` as a quasi-functor. (Note that where a lawful `Monad` or
Mathlib/Control/Functor.lean
48
58
/- 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 -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ := let ⟨n, hn⟩ := exists_nat_gt ‖z‖ have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : ℂ) : CauSeq ℂ (‖·‖) := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε rcases j with - | j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel₀ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_one₀ (norm_nonneg _) hx _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc ‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤ ∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ := calc ‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ] _ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 := calc ‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = ‖x‖ ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ _ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _ rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi · rw [Complex.norm_pow] · simp _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm · intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] · intro a ha b hb hab simpa using hab · intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ · rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 · rw [tsub_add_cancel_of_le hb.2] · simp _ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← sq_abs] have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
Mathlib/Data/Complex/Exponential.lean
580
581
/- 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.Order.Interval.Set.OrderEmbedding import Mathlib.Order.Antichain import Mathlib.Order.SetNotation /-! # Order-connected sets We say that a set `s : Set α` is `OrdConnected` if for all `x y ∈ s` it includes the interval `[[x, y]]`. If `α` is a `DenselyOrdered` `ConditionallyCompleteLinearOrder` with the `OrderTopology`, then this condition is equivalent to `IsPreconnected s`. If `α` is a `LinearOrderedField`, then this condition is also equivalent to `Convex α s`. In this file we prove that intersection of a family of `OrdConnected` sets is `OrdConnected` and that all standard intervals are `OrdConnected`. -/ open scoped Interval open Set open OrderDual (toDual ofDual) namespace Set section Preorder variable {α β : Type*} [Preorder α] [Preorder β] {s : Set α} theorem OrdConnected.out (h : OrdConnected s) : ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y ⊆ s := h.1 theorem ordConnected_def : OrdConnected s ↔ ∀ ⦃x⦄ (_ : x ∈ s) ⦃y⦄ (_ : y ∈ s), Icc x y ⊆ s := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- It suffices to prove `[[x, y]] ⊆ s` for `x y ∈ s`, `x ≤ y`. -/ theorem ordConnected_iff : OrdConnected s ↔ ∀ x ∈ s, ∀ y ∈ s, x ≤ y → Icc x y ⊆ s := ordConnected_def.trans ⟨fun hs _ hx _ hy _ => hs hx hy, fun H x hx y hy _ hz => H x hx y hy (le_trans hz.1 hz.2) hz⟩ theorem ordConnected_of_Ioo {α : Type*} [PartialOrder α] {s : Set α} (hs : ∀ x ∈ s, ∀ y ∈ s, x < y → Ioo x y ⊆ s) : OrdConnected s := by rw [ordConnected_iff] intro x hx y hy hxy rcases eq_or_lt_of_le hxy with (rfl | hxy'); · simpa rw [← Ioc_insert_left hxy, ← Ioo_insert_right hxy'] exact insert_subset_iff.2 ⟨hx, insert_subset_iff.2 ⟨hy, hs x hx y hy hxy'⟩⟩ theorem OrdConnected.preimage_mono {f : β → α} (hs : OrdConnected s) (hf : Monotone f) : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hx hy ⟨hf hz.1, hf hz.2⟩⟩ theorem OrdConnected.preimage_anti {f : β → α} (hs : OrdConnected s) (hf : Antitone f) : OrdConnected (f ⁻¹' s) := ⟨fun _ hx _ hy _ hz => hs.out hy hx ⟨hf hz.2, hf hz.1⟩⟩ protected theorem Icc_subset (s : Set α) [hs : OrdConnected s] {x y} (hx : x ∈ s) (hy : y ∈ s) : Icc x y ⊆ s := hs.out hx hy end Preorder end Set namespace OrderEmbedding variable {α β : Type*} [Preorder α] [Preorder β] theorem image_Icc (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Icc x y = Icc (e x) (e y) := by rw [← e.preimage_Icc, image_preimage_eq_inter_range, inter_eq_left.2 (he.out ⟨_, rfl⟩ ⟨_, rfl⟩)] theorem image_Ico (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Ico x y = Ico (e x) (e y) := by rw [← e.preimage_Ico, image_preimage_eq_inter_range, inter_eq_left.2 <| Ico_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] theorem image_Ioc (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Ioc x y = Ioc (e x) (e y) := by rw [← e.preimage_Ioc, image_preimage_eq_inter_range, inter_eq_left.2 <| Ioc_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩] theorem image_Ioo (e : α ↪o β) (he : OrdConnected (range e)) (x y : α) : e '' Ioo x y = Ioo (e x) (e y) := by rw [← e.preimage_Ioo, image_preimage_eq_inter_range, inter_eq_left.2 <| Ioo_subset_Icc_self.trans <| he.out ⟨_, rfl⟩ ⟨_, rfl⟩]
end OrderEmbedding
Mathlib/Order/Interval/Set/OrdConnected.lean
89
91
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Init import Mathlib.Data.Int.Init import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero DenselyOrdered open Function variable {α β G M : Type*} section ite variable [Pow α β] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section Semigroup variable [Semigroup α] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩ /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by ext z simp [mul_assoc] /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by ext z simp [mul_assoc] end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩ section MulOneClass variable [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h : P <;> simp [h] @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h : P <;> simp [h] @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) @[to_additive] theorem one_mul_eq_id : ((1 : M) * ·) = id := funext one_mul @[to_additive] theorem mul_one_eq_id : (· * (1 : M)) = id := funext mul_one end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by rw [← mul_assoc, mul_comm a, mul_assoc] @[to_additive] theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by rw [mul_assoc, mul_comm b, mul_assoc] @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] end CommSemigroup attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b : M} {m n : ℕ} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"] lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] @[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] @[to_additive (attr := simp)] lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ, mul_left_iterate] @[to_additive (attr := simp)] lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ', mul_right_iterate] @[to_additive] lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive] lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul] end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz @[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] end CommMonoid section LeftCancelMonoid variable [Monoid M] [IsLeftCancelMul M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_left : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left @[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_eq_self @[to_additive (attr := simp)] theorem left_eq_mul : a = a * b ↔ b = 1 := eq_comm.trans mul_eq_left @[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_right @[to_additive] theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not @[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left @[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_ne_self
@[to_additive]
Mathlib/Algebra/Group/Basic.lean
245
245
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂) /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x ∉ s ∧ y ∉ s /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x ∉ s ∧ y ∉ s theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by
refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
Mathlib/Analysis/Convex/Side.lean
101
106
/- 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 =
Mathlib/CategoryTheory/Bicategory/Basic.lean
245
248
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Comma.Arrow import Mathlib.Order.CompleteBooleanAlgebra /-! # Properties of morphisms We provide the basic framework for talking about properties of morphisms. The following meta-property is defined * `RespectsLeft P Q`: `P` respects the property `Q` on the left if `P f → P (i ≫ f)` where `i` satisfies `Q`. * `RespectsRight P Q`: `P` respects the property `Q` on the right if `P f → P (f ≫ i)` where `i` satisfies `Q`. * `Respects`: `P` respects `Q` if `P` respects `Q` both on the left and on the right. -/ universe w v v' u u' open CategoryTheory Opposite noncomputable section namespace CategoryTheory variable (C : Type u) [Category.{v} C] {D : Type*} [Category D] /-- A `MorphismProperty C` is a class of morphisms between objects in `C`. -/ def MorphismProperty := ∀ ⦃X Y : C⦄ (_ : X ⟶ Y), Prop instance : CompleteBooleanAlgebra (MorphismProperty C) where le P₁ P₂ := ∀ ⦃X Y : C⦄ (f : X ⟶ Y), P₁ f → P₂ f __ := inferInstanceAs (CompleteBooleanAlgebra (∀ ⦃X Y : C⦄ (_ : X ⟶ Y), Prop)) lemma MorphismProperty.le_def {P Q : MorphismProperty C} : P ≤ Q ↔ ∀ {X Y : C} (f : X ⟶ Y), P f → Q f := Iff.rfl instance : Inhabited (MorphismProperty C) := ⟨⊤⟩ lemma MorphismProperty.top_eq : (⊤ : MorphismProperty C) = fun _ _ _ => True := rfl variable {C} namespace MorphismProperty @[ext] lemma ext (W W' : MorphismProperty C) (h : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), W f ↔ W' f) : W = W' := by funext X Y f rw [h] @[simp] lemma top_apply {X Y : C} (f : X ⟶ Y) : (⊤ : MorphismProperty C) f := by simp only [top_eq] lemma of_eq_top {P : MorphismProperty C} (h : P = ⊤) {X Y : C} (f : X ⟶ Y) : P f := by simp [h] @[simp] lemma sSup_iff (S : Set (MorphismProperty C)) {X Y : C} (f : X ⟶ Y) : sSup S f ↔ ∃ (W : S), W.1 f := by dsimp [sSup, iSup] constructor · rintro ⟨_, ⟨⟨_, ⟨⟨_, ⟨_, h⟩, rfl⟩, rfl⟩⟩, rfl⟩, hf⟩ exact ⟨⟨_, h⟩, hf⟩ · rintro ⟨⟨W, hW⟩, hf⟩ exact ⟨_, ⟨⟨_, ⟨_, ⟨⟨W, hW⟩, rfl⟩⟩, rfl⟩, rfl⟩, hf⟩ @[simp] lemma iSup_iff {ι : Sort*} (W : ι → MorphismProperty C) {X Y : C} (f : X ⟶ Y) : iSup W f ↔ ∃ i, W i f := by apply (sSup_iff (Set.range W) f).trans constructor · rintro ⟨⟨_, i, rfl⟩, hf⟩ exact ⟨i, hf⟩ · rintro ⟨i, hf⟩ exact ⟨⟨_, i, rfl⟩, hf⟩ /-- The morphism property in `Cᵒᵖ` associated to a morphism property in `C` -/ @[simp] def op (P : MorphismProperty C) : MorphismProperty Cᵒᵖ := fun _ _ f => P f.unop /-- The morphism property in `C` associated to a morphism property in `Cᵒᵖ` -/ @[simp] def unop (P : MorphismProperty Cᵒᵖ) : MorphismProperty C := fun _ _ f => P f.op theorem unop_op (P : MorphismProperty C) : P.op.unop = P := rfl theorem op_unop (P : MorphismProperty Cᵒᵖ) : P.unop.op = P := rfl /-- The inverse image of a `MorphismProperty D` by a functor `C ⥤ D` -/ def inverseImage (P : MorphismProperty D) (F : C ⥤ D) : MorphismProperty C := fun _ _ f => P (F.map f) @[simp] lemma inverseImage_iff (P : MorphismProperty D) (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) : P.inverseImage F f ↔ P (F.map f) := by rfl /-- The image (up to isomorphisms) of a `MorphismProperty C` by a functor `C ⥤ D` -/ def map (P : MorphismProperty C) (F : C ⥤ D) : MorphismProperty D := fun _ _ f => ∃ (X' Y' : C) (f' : X' ⟶ Y') (_ : P f'), Nonempty (Arrow.mk (F.map f') ≅ Arrow.mk f) lemma map_mem_map (P : MorphismProperty C) (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) (hf : P f) : (P.map F) (F.map f) := ⟨X, Y, f, hf, ⟨Iso.refl _⟩⟩ lemma monotone_map (F : C ⥤ D) : Monotone (map · F) := by intro P Q h X Y f ⟨X', Y', f', hf', ⟨e⟩⟩ exact ⟨X', Y', f', h _ hf', ⟨e⟩⟩ section variable (P : MorphismProperty C) /-- The set in `Set (Arrow C)` which corresponds to `P : MorphismProperty C`. -/ def toSet : Set (Arrow C) := setOf (fun f ↦ P f.hom) /-- The family of morphisms indexed by `P.toSet` which corresponds to `P : MorphismProperty C`, see `MorphismProperty.ofHoms_homFamily`. -/ def homFamily (f : P.toSet) : f.1.left ⟶ f.1.right := f.1.hom lemma homFamily_apply (f : P.toSet) : P.homFamily f = f.1.hom := rfl @[simp] lemma homFamily_arrow_mk {X Y : C} (f : X ⟶ Y) (hf : P f) : P.homFamily ⟨Arrow.mk f, hf⟩ = f := rfl @[simp] lemma arrow_mk_mem_toSet_iff {X Y : C} (f : X ⟶ Y) : Arrow.mk f ∈ P.toSet ↔ P f := Iff.rfl lemma of_eq {X Y : C} {f : X ⟶ Y} (hf : P f) {X' Y' : C} {f' : X' ⟶ Y'} (hX : X = X') (hY : Y = Y') (h : f' = eqToHom hX.symm ≫ f ≫ eqToHom hY) : P f' := by rw [← P.arrow_mk_mem_toSet_iff] at hf ⊢ rwa [(Arrow.mk_eq_mk_iff f' f).2 ⟨hX.symm, hY.symm, h⟩] end /-- The class of morphisms given by a family of morphisms `f i : X i ⟶ Y i`. -/ inductive ofHoms {ι : Type*} {X Y : ι → C} (f : ∀ i, X i ⟶ Y i) : MorphismProperty C | mk (i : ι) : ofHoms f (f i) lemma ofHoms_iff {ι : Type*} {X Y : ι → C} (f : ∀ i, X i ⟶ Y i) {A B : C} (g : A ⟶ B) : ofHoms f g ↔ ∃ i, Arrow.mk g = Arrow.mk (f i) := by constructor · rintro ⟨i⟩ exact ⟨i, rfl⟩ · rintro ⟨i, h⟩ rw [← (ofHoms f).arrow_mk_mem_toSet_iff, h, arrow_mk_mem_toSet_iff] constructor @[simp] lemma ofHoms_homFamily (P : MorphismProperty C) : ofHoms P.homFamily = P := by ext _ _ f constructor · intro hf rw [ofHoms_iff] at hf obtain ⟨⟨f, hf⟩, ⟨_, _⟩⟩ := hf exact hf · intro hf exact ⟨(⟨f, hf⟩ : P.toSet)⟩ /-- A morphism property `P` satisfies `P.RespectsRight Q` if it is stable under post-composition with morphisms satisfying `Q`, i.e. whenever `P` holds for `f` and `Q` holds for `i` then `P` holds for `f ≫ i`. -/ class RespectsRight (P Q : MorphismProperty C) : Prop where postcomp {X Y Z : C} (i : Y ⟶ Z) (hi : Q i) (f : X ⟶ Y) (hf : P f) : P (f ≫ i) /-- A morphism property `P` satisfies `P.RespectsLeft Q` if it is stable under pre-composition with morphisms satisfying `Q`, i.e. whenever `P` holds for `f` and `Q` holds for `i` then `P` holds for `i ≫ f`. -/ class RespectsLeft (P Q : MorphismProperty C) : Prop where precomp {X Y Z : C} (i : X ⟶ Y) (hi : Q i) (f : Y ⟶ Z) (hf : P f) : P (i ≫ f) /-- A morphism property `P` satisfies `P.Respects Q` if it is stable under composition on the left and right by morphisms satisfying `Q`. -/ class Respects (P Q : MorphismProperty C) : Prop extends P.RespectsLeft Q, P.RespectsRight Q where instance (P Q : MorphismProperty C) [P.RespectsLeft Q] [P.RespectsRight Q] : P.Respects Q where instance (P Q : MorphismProperty C) [P.RespectsLeft Q] : P.op.RespectsRight Q.op where postcomp i hi f hf := RespectsLeft.precomp (Q := Q) i.unop hi f.unop hf instance (P Q : MorphismProperty C) [P.RespectsRight Q] : P.op.RespectsLeft Q.op where precomp i hi f hf := RespectsRight.postcomp (Q := Q) i.unop hi f.unop hf instance RespectsLeft.inf (P₁ P₂ Q : MorphismProperty C) [P₁.RespectsLeft Q] [P₂.RespectsLeft Q] : (P₁ ⊓ P₂).RespectsLeft Q where precomp i hi f hf := ⟨precomp i hi f hf.left, precomp i hi f hf.right⟩ instance RespectsRight.inf (P₁ P₂ Q : MorphismProperty C) [P₁.RespectsRight Q] [P₂.RespectsRight Q] : (P₁ ⊓ P₂).RespectsRight Q where postcomp i hi f hf := ⟨postcomp i hi f hf.left, postcomp i hi f hf.right⟩ variable (C) /-- The `MorphismProperty C` satisfied by isomorphisms in `C`. -/ def isomorphisms : MorphismProperty C := fun _ _ f => IsIso f /-- The `MorphismProperty C` satisfied by monomorphisms in `C`. -/ def monomorphisms : MorphismProperty C := fun _ _ f => Mono f /-- The `MorphismProperty C` satisfied by epimorphisms in `C`. -/ def epimorphisms : MorphismProperty C := fun _ _ f => Epi f
section variable {C} /-- `P` respects isomorphisms, if it respects the morphism property `isomorphisms C`, i.e. it is stable under pre- and postcomposition with isomorphisms. -/ abbrev RespectsIso (P : MorphismProperty C) : Prop := P.Respects (isomorphisms C)
Mathlib/CategoryTheory/MorphismProperty/Basic.lean
216
223
/- Copyright (c) 2022 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth -/ import Mathlib.MeasureTheory.Function.L1Space.AEEqFun import Mathlib.MeasureTheory.Function.LpSpace.Complete import Mathlib.MeasureTheory.Function.LpSpace.Indicator /-! # Density of simple functions Show that each `Lᵖ` Borel measurable function can be approximated in `Lᵖ` norm by a sequence of simple functions. ## Main definitions * `MeasureTheory.Lp.simpleFunc`, the type of `Lp` simple functions * `coeToLp`, the embedding of `Lp.simpleFunc E p μ` into `Lp E p μ` ## Main results * `tendsto_approxOn_Lp_eLpNorm` (Lᵖ convergence): If `E` is a `NormedAddCommGroup` and `f` is measurable and `MemLp` (for `p < ∞`), then the simple functions `SimpleFunc.approxOn f hf s 0 h₀ n` may be considered as elements of `Lp E p μ`, and they tend in Lᵖ to `f`. * `Lp.simpleFunc.isDenseEmbedding`: the embedding `coeToLp` of the `Lp` simple functions into `Lp` is dense. * `Lp.simpleFunc.induction`, `Lp.induction`, `MemLp.induction`, `Integrable.induction`: to prove a predicate for all elements of one of these classes of functions, it suffices to check that it behaves correctly on simple functions. ## TODO For `E` finite-dimensional, simple functions `α →ₛ E` are dense in L^∞ -- prove this. ## Notations * `α →ₛ β` (local notation): the type of simple functions `α → β`. * `α →₁ₛ[μ] E`: the type of `L1` simple functions `α → β`. -/ noncomputable section open Set Function Filter TopologicalSpace ENNReal EMetric Finset open scoped Topology ENNReal MeasureTheory variable {α β ι E F 𝕜 : Type*} namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc namespace SimpleFunc /-! ### Lp approximation by simple functions -/ section Lp variable [MeasurableSpace β] [MeasurableSpace E] [NormedAddCommGroup E] [NormedAddCommGroup F] {q : ℝ} {p : ℝ≥0∞} theorem nnnorm_approxOn_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (x : β) (n : ℕ) : ‖approxOn f hf s y₀ h₀ n x - f x‖₊ ≤ ‖f x - y₀‖₊ := by have := edist_approxOn_le hf h₀ x n rw [edist_comm y₀] at this simp only [edist_nndist, nndist_eq_nnnorm] at this exact mod_cast this theorem norm_approxOn_y₀_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (x : β) (n : ℕ) : ‖approxOn f hf s y₀ h₀ n x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ := by simpa [enorm, edist_eq_enorm_sub, ← ENNReal.coe_add, norm_sub_rev] using edist_approxOn_y0_le hf h₀ x n theorem norm_approxOn_zero_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E} (h₀ : (0 : E) ∈ s) [SeparableSpace s] (x : β) (n : ℕ) : ‖approxOn f hf s 0 h₀ n x‖ ≤ ‖f x‖ + ‖f x‖ := by simpa [enorm, edist_eq_enorm_sub, ← ENNReal.coe_add, norm_sub_rev] using edist_approxOn_y0_le hf h₀ x n theorem tendsto_approxOn_Lp_eLpNorm [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (hp_ne_top : p ≠ ∞) {μ : Measure β} (hμ : ∀ᵐ x ∂μ, f x ∈ closure s) (hi : eLpNorm (fun x => f x - y₀) p μ < ∞) : Tendsto (fun n => eLpNorm (⇑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) := by by_cases hp_zero : p = 0 · simpa only [hp_zero, eLpNorm_exponent_zero] using tendsto_const_nhds have hp : 0 < p.toReal := toReal_pos hp_zero hp_ne_top suffices Tendsto (fun n => ∫⁻ x, ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal ∂μ) atTop (𝓝 0) by simp only [eLpNorm_eq_lintegral_rpow_enorm hp_zero hp_ne_top] convert continuous_rpow_const.continuousAt.tendsto.comp this simp [zero_rpow_of_pos (_root_.inv_pos.mpr hp)] -- We simply check the conditions of the Dominated Convergence Theorem: -- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable have hF_meas n : Measurable fun x => ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal := by simpa only [← edist_eq_enorm_sub] using (approxOn f hf s y₀ h₀ n).measurable_bind (fun y x => edist y (f x) ^ p.toReal) fun y => (measurable_edist_right.comp hf).pow_const p.toReal -- (2) The functions "`p`-th power of distance between `f` and the approximation" are uniformly -- bounded, at any given point, by `fun x => ‖f x - y₀‖ ^ p.toReal` have h_bound n : (fun x ↦ ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal) ≤ᵐ[μ] (‖f · - y₀‖ₑ ^ p.toReal) := .of_forall fun x => rpow_le_rpow (coe_mono (nnnorm_approxOn_le hf h₀ x n)) toReal_nonneg -- (3) The bounding function `fun x => ‖f x - y₀‖ ^ p.toReal` has finite integral have h_fin : (∫⁻ a : β, ‖f a - y₀‖ₑ ^ p.toReal ∂μ) ≠ ⊤ := (lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_zero hp_ne_top hi).ne -- (4) The functions "`p`-th power of distance between `f` and the approximation" tend pointwise -- to zero have h_lim : ∀ᵐ a : β ∂μ, Tendsto (‖approxOn f hf s y₀ h₀ · a - f a‖ₑ ^ p.toReal) atTop (𝓝 0) := by filter_upwards [hμ] with a ha have : Tendsto (fun n => (approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) := (tendsto_approxOn hf h₀ ha).sub tendsto_const_nhds convert continuous_rpow_const.continuousAt.tendsto.comp (tendsto_coe.mpr this.nnnorm) simp [zero_rpow_of_pos hp] -- Then we apply the Dominated Convergence Theorem simpa using tendsto_lintegral_of_dominated_convergence _ hF_meas h_bound h_fin h_lim theorem memLp_approxOn [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f) (hf : MemLp f p μ) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (hi₀ : MemLp (fun _ => y₀) p μ) (n : ℕ) : MemLp (approxOn f fmeas s y₀ h₀ n) p μ := by refine ⟨(approxOn f fmeas s y₀ h₀ n).aestronglyMeasurable, ?_⟩ suffices eLpNorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ < ⊤ by have : MemLp (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ := ⟨(approxOn f fmeas s y₀ h₀ n - const β y₀).aestronglyMeasurable, this⟩ convert eLpNorm_add_lt_top this hi₀ ext x simp have hf' : MemLp (fun x => ‖f x - y₀‖) p μ := by have h_meas : Measurable fun x => ‖f x - y₀‖ := by simp only [← dist_eq_norm] exact (continuous_id.dist continuous_const).measurable.comp fmeas refine ⟨h_meas.aemeasurable.aestronglyMeasurable, ?_⟩ rw [eLpNorm_norm] convert eLpNorm_add_lt_top hf hi₀.neg with x simp [sub_eq_add_neg] have : ∀ᵐ x ∂μ, ‖approxOn f fmeas s y₀ h₀ n x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ := by filter_upwards with x convert norm_approxOn_y₀_le fmeas h₀ x n using 1 rw [Real.norm_eq_abs, abs_of_nonneg] positivity calc eLpNorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ ≤ eLpNorm (fun x => ‖f x - y₀‖ + ‖f x - y₀‖) p μ := eLpNorm_mono_ae this _ < ⊤ := eLpNorm_add_lt_top hf' hf' theorem tendsto_approxOn_range_Lp_eLpNorm [BorelSpace E] {f : β → E} (hp_ne_top : p ≠ ∞) {μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)] (hf : eLpNorm f p μ < ∞) : Tendsto (fun n => eLpNorm (⇑(approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) - f) p μ) atTop (𝓝 0) := by refine tendsto_approxOn_Lp_eLpNorm fmeas _ hp_ne_top ?_ ?_ · filter_upwards with x using subset_closure (by simp) · simpa using hf theorem memLp_approxOn_range [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)] (hf : MemLp f p μ) (n : ℕ) : MemLp (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) p μ := memLp_approxOn fmeas hf (y₀ := 0) (by simp) MemLp.zero n theorem tendsto_approxOn_range_Lp [BorelSpace E] {f : β → E} [hp : Fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) {μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)] (hf : MemLp f p μ) : Tendsto (fun n => (memLp_approxOn_range fmeas hf n).toLp (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n)) atTop (𝓝 (hf.toLp f)) := by simpa only [Lp.tendsto_Lp_iff_tendsto_eLpNorm''] using tendsto_approxOn_range_Lp_eLpNorm hp_ne_top fmeas hf.2 /-- Any function in `ℒp` can be approximated by a simple function if `p < ∞`. -/ theorem _root_.MeasureTheory.MemLp.exists_simpleFunc_eLpNorm_sub_lt {E : Type*}
[NormedAddCommGroup E] {f : β → E} {μ : Measure β} (hf : MemLp f p μ) (hp_ne_top : p ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ g : β →ₛ E, eLpNorm (f - ⇑g) p μ < ε ∧ MemLp g p μ := by borelize E let f' := hf.1.mk f
Mathlib/MeasureTheory/Function/SimpleFuncDenseLp.lean
178
181
/- Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.MvPolynomial.Rename import Mathlib.Algebra.MvPolynomial.Variables /-! # Monad operations on `MvPolynomial` This file defines two monadic operations on `MvPolynomial`. Given `p : MvPolynomial σ R`, * `MvPolynomial.bind₁` and `MvPolynomial.join₁` operate on the variable type `σ`. * `MvPolynomial.bind₂` and `MvPolynomial.join₂` operate on the coefficient type `R`. - `MvPolynomial.bind₁ f φ` with `f : σ → MvPolynomial τ R` and `φ : MvPolynomial σ R`, is the polynomial `φ(f 1, ..., f i, ...) : MvPolynomial τ R`. - `MvPolynomial.join₁ φ` with `φ : MvPolynomial (MvPolynomial σ R) R` collapses `φ` to a `MvPolynomial σ R`, by evaluating `φ` under the map `X f ↦ f` for `f : MvPolynomial σ R`. In other words, if you have a polynomial `φ` in a set of variables indexed by a polynomial ring, you evaluate the polynomial in these indexing polynomials. - `MvPolynomial.bind₂ f φ` with `f : R →+* MvPolynomial σ S` and `φ : MvPolynomial σ R` is the `MvPolynomial σ S` obtained from `φ` by mapping the coefficients of `φ` through `f` and considering the resulting polynomial as polynomial expression in `MvPolynomial σ R`. - `MvPolynomial.join₂ φ` with `φ : MvPolynomial σ (MvPolynomial σ R)` collapses `φ` to a `MvPolynomial σ R`, by considering `φ` as polynomial expression in `MvPolynomial σ R`. These operations themselves have algebraic structure: `MvPolynomial.bind₁` and `MvPolynomial.join₁` are algebra homs and `MvPolynomial.bind₂` and `MvPolynomial.join₂` are ring homs. They interact in convenient ways with `MvPolynomial.rename`, `MvPolynomial.map`, `MvPolynomial.vars`, and other polynomial operations. Indeed, `MvPolynomial.rename` is the "map" operation for the (`bind₁`, `join₁`) pair, whereas `MvPolynomial.map` is the "map" operation for the other pair. ## Implementation notes We add a `LawfulMonad` instance for the (`bind₁`, `join₁`) pair. The second pair cannot be instantiated as a `Monad`, since it is not a monad in `Type` but in `CommRingCat` (or rather `CommSemiRingCat`). -/ noncomputable section namespace MvPolynomial open Finsupp variable {σ : Type*} {τ : Type*} variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T] /-- `bind₁` is the "left hand side" bind operation on `MvPolynomial`, operating on the variable type. Given a polynomial `p : MvPolynomial σ R` and a map `f : σ → MvPolynomial τ R` taking variables in `p` to polynomials in the variable type `τ`, `bind₁ f p` replaces each variable in `p` with its value under `f`, producing a new polynomial in `τ`. The coefficient type remains the same. This operation is an algebra hom. -/ def bind₁ (f : σ → MvPolynomial τ R) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R := aeval f /-- `bind₂` is the "right hand side" bind operation on `MvPolynomial`, operating on the coefficient type. Given a polynomial `p : MvPolynomial σ R` and a map `f : R → MvPolynomial σ S` taking coefficients in `p` to polynomials over a new ring `S`, `bind₂ f p` replaces each coefficient in `p` with its value under `f`, producing a new polynomial over `S`. The variable type remains the same. This operation is a ring hom. -/ def bind₂ (f : R →+* MvPolynomial σ S) : MvPolynomial σ R →+* MvPolynomial σ S := eval₂Hom f X /-- `join₁` is the monadic join operation corresponding to `MvPolynomial.bind₁`. Given a polynomial `p` with coefficients in `R` whose variables are polynomials in `σ` with coefficients in `R`, `join₁ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`. This operation is an algebra hom. -/ def join₁ : MvPolynomial (MvPolynomial σ R) R →ₐ[R] MvPolynomial σ R := aeval id /-- `join₂` is the monadic join operation corresponding to `MvPolynomial.bind₂`. Given a polynomial `p` with variables in `σ` whose coefficients are polynomials in `σ` with coefficients in `R`, `join₂ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`. This operation is a ring hom. -/ def join₂ : MvPolynomial σ (MvPolynomial σ R) →+* MvPolynomial σ R := eval₂Hom (RingHom.id _) X @[simp] theorem aeval_eq_bind₁ (f : σ → MvPolynomial τ R) : aeval f = bind₁ f := rfl @[simp] theorem eval₂Hom_C_eq_bind₁ (f : σ → MvPolynomial τ R) : eval₂Hom C f = bind₁ f := rfl @[simp] theorem eval₂Hom_eq_bind₂ (f : R →+* MvPolynomial σ S) : eval₂Hom f X = bind₂ f := rfl section variable (σ R) @[simp] theorem aeval_id_eq_join₁ : aeval id = @join₁ σ R _ := rfl theorem eval₂Hom_C_id_eq_join₁ (φ : MvPolynomial (MvPolynomial σ R) R) : eval₂Hom C id φ = join₁ φ := rfl @[simp] theorem eval₂Hom_id_X_eq_join₂ : eval₂Hom (RingHom.id _) X = @join₂ σ R _ := rfl end -- In this file, we don't want to use these simp lemmas, -- because we first need to show how these new definitions interact -- and the proofs fall back on unfolding the definitions and call simp afterwards attribute [-simp] aeval_eq_bind₁ eval₂Hom_C_eq_bind₁ eval₂Hom_eq_bind₂ aeval_id_eq_join₁ eval₂Hom_id_X_eq_join₂ @[simp] theorem bind₁_X_right (f : σ → MvPolynomial τ R) (i : σ) : bind₁ f (X i) = f i := aeval_X f i @[simp] theorem bind₂_X_right (f : R →+* MvPolynomial σ S) (i : σ) : bind₂ f (X i) = X i := eval₂Hom_X' f X i @[simp] theorem bind₁_X_left : bind₁ (X : σ → MvPolynomial σ R) = AlgHom.id R _ := by ext1 i simp variable (f : σ → MvPolynomial τ R) theorem bind₁_C_right (f : σ → MvPolynomial τ R) (x) : bind₁ f (C x) = C x := algHom_C _ _ @[simp] theorem bind₂_C_right (f : R →+* MvPolynomial σ S) (r : R) : bind₂ f (C r) = f r := eval₂Hom_C f X r @[simp] theorem bind₂_C_left : bind₂ (C : R →+* MvPolynomial σ R) = RingHom.id _ := by ext : 2 <;> simp @[simp] theorem bind₂_comp_C (f : R →+* MvPolynomial σ S) : (bind₂ f).comp C = f := RingHom.ext <| bind₂_C_right _ @[simp] theorem join₂_map (f : R →+* MvPolynomial σ S) (φ : MvPolynomial σ R) : join₂ (map f φ) = bind₂ f φ := by simp only [join₂, bind₂, eval₂Hom_map_hom, RingHom.id_comp] @[simp] theorem join₂_comp_map (f : R →+* MvPolynomial σ S) : join₂.comp (map f) = bind₂ f := RingHom.ext <| join₂_map _ theorem aeval_id_rename (f : σ → MvPolynomial τ R) (p : MvPolynomial σ R) : aeval id (rename f p) = aeval f p := by rw [aeval_rename, Function.id_comp] @[simp] theorem join₁_rename (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) : join₁ (rename f φ) = bind₁ f φ := aeval_id_rename _ _ @[simp] theorem bind₁_id : bind₁ (@id (MvPolynomial σ R)) = join₁ := rfl @[simp] theorem bind₂_id : bind₂ (RingHom.id (MvPolynomial σ R)) = join₂ := rfl theorem bind₁_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → MvPolynomial υ R) (φ : MvPolynomial σ R) : (bind₁ g) (bind₁ f φ) = bind₁ (fun i => bind₁ g (f i)) φ := by simp [bind₁, ← comp_aeval] theorem bind₁_comp_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → MvPolynomial υ R) : (bind₁ g).comp (bind₁ f) = bind₁ fun i => bind₁ g (f i) := by ext1 apply bind₁_bind₁ theorem bind₂_comp_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* MvPolynomial σ T) : (bind₂ g).comp (bind₂ f) = bind₂ ((bind₂ g).comp f) := by ext : 2 <;> simp theorem bind₂_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* MvPolynomial σ T) (φ : MvPolynomial σ R) : (bind₂ g) (bind₂ f φ) = bind₂ ((bind₂ g).comp f) φ := RingHom.congr_fun (bind₂_comp_bind₂ f g) φ theorem rename_comp_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → υ) : (rename g).comp (bind₁ f) = bind₁ fun i => rename g <| f i := by ext1 i simp theorem rename_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → υ) (φ : MvPolynomial σ R) : rename g (bind₁ f φ) = bind₁ (fun i => rename g <| f i) φ := AlgHom.congr_fun (rename_comp_bind₁ f g) φ theorem map_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* T) (φ : MvPolynomial σ R) : map g (bind₂ f φ) = bind₂ ((map g).comp f) φ := by simp only [bind₂, eval₂_comp_right, coe_eval₂Hom, eval₂_map] congr 1 with : 1 simp only [Function.comp_apply, map_X] theorem bind₁_comp_rename {υ : Type*} (f : τ → MvPolynomial υ R) (g : σ → τ) : (bind₁ f).comp (rename g) = bind₁ (f ∘ g) := by ext1 i simp theorem bind₁_rename {υ : Type*} (f : τ → MvPolynomial υ R) (g : σ → τ) (φ : MvPolynomial σ R) : bind₁ f (rename g φ) = bind₁ (f ∘ g) φ := AlgHom.congr_fun (bind₁_comp_rename f g) φ
theorem bind₂_map (f : S →+* MvPolynomial σ T) (g : R →+* S) (φ : MvPolynomial σ R) : bind₂ f (map g φ) = bind₂ (f.comp g) φ := by simp [bind₂] @[simp]
Mathlib/Algebra/MvPolynomial/Monad.lean
224
227
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Algebra.CharP.Basic import Mathlib.Algebra.CharP.Lemmas import Mathlib.Data.Fintype.Units import Mathlib.GroupTheory.OrderOfElement /-! # Multiplicative characters of finite rings and fields Let `R` and `R'` be a commutative rings. A *multiplicative character* of `R` with values in `R'` is a morphism of monoids from the multiplicative monoid of `R` into that of `R'` that sends non-units to zero. We use the namespace `MulChar` for the definitions and results. ## Main results We show that the multiplicative characters form a group (if `R'` is commutative); see `MulChar.commGroup`. We also provide an equivalence with the homomorphisms `Rˣ →* R'ˣ`; see `MulChar.equivToUnitHom`. We define a multiplicative character to be *quadratic* if its values are among `0`, `1` and `-1`, and we prove some properties of quadratic characters. Finally, we show that the sum of all values of a nontrivial multiplicative character vanishes; see `MulChar.IsNontrivial.sum_eq_zero`. ## Tags multiplicative character -/ /-! ### Definitions related to multiplicative characters Even though the intended use is when domain and target of the characters are commutative rings, we define them in the more general setting when the domain is a commutative monoid and the target is a commutative monoid with zero. (We need a zero in the target, since non-units are supposed to map to zero.) In this setting, there is an equivalence between multiplicative characters `R → R'` and group homomorphisms `Rˣ → R'ˣ`, and the multiplicative characters have a natural structure as a commutative group. -/ section Defi -- The domain of our multiplicative characters variable (R : Type*) [CommMonoid R] -- The target variable (R' : Type*) [CommMonoidWithZero R'] /-- Define a structure for multiplicative characters. A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'` is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/ structure MulChar extends MonoidHom R R' where map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0 instance MulChar.instFunLike : FunLike (MulChar R R') R R' := ⟨fun χ => χ.toFun, fun χ₀ χ₁ h => by cases χ₀; cases χ₁; congr; apply MonoidHom.ext (fun _ => congr_fun h _)⟩ /-- This is the corresponding extension of `MonoidHomClass`. -/ class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R] [CommMonoidWithZero R'] [FunLike F R R'] : Prop extends MonoidHomClass F R R' where map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0 initialize_simps_projections MulChar (toFun → apply, -toMonoidHom) end Defi namespace MulChar attribute [scoped simp] MulCharClass.map_nonunit section Group -- The domain of our multiplicative characters variable {R : Type*} [CommMonoid R] -- The target variable {R' : Type*} [CommMonoidWithZero R'] variable (R R') in /-- The trivial multiplicative character. It takes the value `0` on non-units and the value `1` on units. -/ @[simps] noncomputable def trivial : MulChar R R' where toFun := by classical exact fun x => if IsUnit x then 1 else 0 map_nonunit' := by intro a ha simp only [ha, if_false] map_one' := by simp only [isUnit_one, if_true] map_mul' := by intro x y classical simp only [IsUnit.mul_iff, boole_mul] split_ifs <;> tauto @[simp] theorem coe_mk (f : R →* R') (hf) : (MulChar.mk f hf : R → R') = f := rfl /-- Extensionality. See `ext` below for the version that will actually be used. -/ theorem ext' {χ χ' : MulChar R R'} (h : ∀ a, χ a = χ' a) : χ = χ' := by cases χ cases χ' congr exact MonoidHom.ext h instance : MulCharClass (MulChar R R') R R' where map_mul χ := χ.map_mul' map_one χ := χ.map_one' map_nonunit χ := χ.map_nonunit' _ theorem map_nonunit (χ : MulChar R R') {a : R} (ha : ¬IsUnit a) : χ a = 0 := χ.map_nonunit' a ha /-- Extensionality. Since `MulChar`s always take the value zero on non-units, it is sufficient to compare the values on units. -/ @[ext] theorem ext {χ χ' : MulChar R R'} (h : ∀ a : Rˣ, χ a = χ' a) : χ = χ' := by apply ext' intro a by_cases ha : IsUnit a · exact h ha.unit · rw [map_nonunit χ ha, map_nonunit χ' ha] /-! ### Equivalence of multiplicative characters with homomorphisms on units We show that restriction / extension by zero gives an equivalence between `MulChar R R'` and `Rˣ →* R'ˣ`. -/ /-- Turn a `MulChar` into a homomorphism between the unit groups. -/ def toUnitHom (χ : MulChar R R') : Rˣ →* R'ˣ := Units.map χ theorem coe_toUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(χ.toUnitHom a) = χ a := rfl /-- Turn a homomorphism between unit groups into a `MulChar`. -/ noncomputable def ofUnitHom (f : Rˣ →* R'ˣ) : MulChar R R' where toFun := by classical exact fun x => if hx : IsUnit x then f hx.unit else 0 map_one' := by have h1 : (isUnit_one.unit : Rˣ) = 1 := Units.eq_iff.mp rfl simp only [h1, dif_pos, Units.val_eq_one, map_one, isUnit_one] map_mul' := by classical intro x y by_cases hx : IsUnit x · simp only [hx, IsUnit.mul_iff, true_and, dif_pos] by_cases hy : IsUnit y · simp only [hy, dif_pos] have hm : (IsUnit.mul_iff.mpr ⟨hx, hy⟩).unit = hx.unit * hy.unit := Units.eq_iff.mp rfl rw [hm, map_mul] norm_cast · simp only [hy, not_false_iff, dif_neg, mul_zero] · simp only [hx, IsUnit.mul_iff, false_and, not_false_iff, dif_neg, zero_mul] map_nonunit' := by intro a ha simp only [ha, not_false_iff, dif_neg] theorem ofUnitHom_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : ofUnitHom f ↑a = f a := by simp [ofUnitHom] /-- The equivalence between multiplicative characters and homomorphisms of unit groups. -/ noncomputable def equivToUnitHom : MulChar R R' ≃ (Rˣ →* R'ˣ) where toFun := toUnitHom invFun := ofUnitHom left_inv := by intro χ ext x rw [ofUnitHom_coe, coe_toUnitHom] right_inv := by intro f ext x simp only [coe_toUnitHom, ofUnitHom_coe] @[simp] theorem toUnitHom_eq (χ : MulChar R R') : toUnitHom χ = equivToUnitHom χ := rfl @[simp] theorem ofUnitHom_eq (χ : Rˣ →* R'ˣ) : ofUnitHom χ = equivToUnitHom.symm χ := rfl @[simp] theorem coe_equivToUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(equivToUnitHom χ a) = χ a := coe_toUnitHom χ a @[simp] theorem equivToUnitHom_symm_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : equivToUnitHom.symm f ↑a = f a := ofUnitHom_coe f a @[simp] lemma coe_toMonoidHom (χ : MulChar R R') (x : R) : χ.toMonoidHom x = χ x := rfl /-! ### Commutative group structure on multiplicative characters The multiplicative characters `R → R'` form a commutative group. -/ protected theorem map_one (χ : MulChar R R') : χ (1 : R) = 1 := χ.map_one' /-- If the domain has a zero (and is nontrivial), then `χ 0 = 0`. -/ protected theorem map_zero {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') : χ (0 : R) = 0 := by rw [map_nonunit χ not_isUnit_zero] /-- We can convert a multiplicative character into a homomorphism of monoids with zero when the source has a zero and another element. -/ @[coe, simps] def toMonoidWithZeroHom {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') : R →*₀ R' where toFun := χ.toFun map_zero' := χ.map_zero map_one' := χ.map_one' map_mul' := χ.map_mul' /-- If the domain is a ring `R`, then `χ (ringChar R) = 0`. -/ theorem map_ringChar {R : Type*} [CommSemiring R] [Nontrivial R] (χ : MulChar R R') : χ (ringChar R) = 0 := by rw [ringChar.Nat.cast_ringChar, χ.map_zero] noncomputable instance hasOne : One (MulChar R R') := ⟨trivial R R'⟩ noncomputable instance inhabited : Inhabited (MulChar R R') := ⟨1⟩ /-- Evaluation of the trivial character -/ @[simp] theorem one_apply_coe (a : Rˣ) : (1 : MulChar R R') a = 1 := by classical exact dif_pos a.isUnit /-- Evaluation of the trivial character -/ lemma one_apply {x : R} (hx : IsUnit x) : (1 : MulChar R R') x = 1 := one_apply_coe hx.unit /-- Multiplication of multiplicative characters. (This needs the target to be commutative.) -/ def mul (χ χ' : MulChar R R') : MulChar R R' := { χ.toMonoidHom * χ'.toMonoidHom with toFun := χ * χ' map_nonunit' := fun a ha => by simp only [map_nonunit χ ha, zero_mul, Pi.mul_apply] } instance hasMul : Mul (MulChar R R') := ⟨mul⟩ theorem mul_apply (χ χ' : MulChar R R') (a : R) : (χ * χ') a = χ a * χ' a := rfl @[simp] theorem coeToFun_mul (χ χ' : MulChar R R') : ⇑(χ * χ') = χ * χ' := rfl protected theorem one_mul (χ : MulChar R R') : (1 : MulChar R R') * χ = χ := by ext simp only [one_mul, Pi.mul_apply, MulChar.coeToFun_mul, MulChar.one_apply_coe] protected theorem mul_one (χ : MulChar R R') : χ * 1 = χ := by ext simp only [mul_one, Pi.mul_apply, MulChar.coeToFun_mul, MulChar.one_apply_coe] /-- The inverse of a multiplicative character. We define it as `inverse ∘ χ`. -/ noncomputable def inv (χ : MulChar R R') : MulChar R R' := { MonoidWithZero.inverse.toMonoidHom.comp χ.toMonoidHom with toFun := fun a => MonoidWithZero.inverse (χ a) map_nonunit' := fun a ha => by simp [map_nonunit _ ha] } noncomputable instance hasInv : Inv (MulChar R R') := ⟨inv⟩ /-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`. -/ theorem inv_apply_eq_inv (χ : MulChar R R') (a : R) : χ⁻¹ a = Ring.inverse (χ a) := Eq.refl <| inv χ a /-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`. Variant when the target is a field -/ theorem inv_apply_eq_inv' {R' : Type*} [CommGroupWithZero R'] (χ : MulChar R R') (a : R) : χ⁻¹ a = (χ a)⁻¹ := (inv_apply_eq_inv χ a).trans <| Ring.inverse_eq_inv (χ a) /-- When the domain has a zero, then the inverse of a multiplicative character `χ`, applied to `a`, is `χ` applied to the inverse of `a`. -/ theorem inv_apply {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (a : R) : χ⁻¹ a = χ (Ring.inverse a) := by by_cases ha : IsUnit a · rw [inv_apply_eq_inv] have h := IsUnit.map χ ha apply_fun (χ a * ·) using IsUnit.mul_right_injective h dsimp only rw [Ring.mul_inverse_cancel _ h, ← map_mul, Ring.mul_inverse_cancel _ ha, map_one] · revert ha nontriviality R intro ha -- `nontriviality R` by itself doesn't do it rw [map_nonunit _ ha, Ring.inverse_non_unit a ha, MulChar.map_zero χ] /-- When the domain has a zero, then the inverse of a multiplicative character `χ`, applied to `a`, is `χ` applied to the inverse of `a`. -/ theorem inv_apply' {R : Type*} [CommGroupWithZero R] (χ : MulChar R R') (a : R) : χ⁻¹ a = χ a⁻¹ := (inv_apply χ a).trans <| congr_arg _ (Ring.inverse_eq_inv a) /-- The product of a character with its inverse is the trivial character. -/ theorem inv_mul (χ : MulChar R R') : χ⁻¹ * χ = 1 := by ext x rw [coeToFun_mul, Pi.mul_apply, inv_apply_eq_inv] simp only [Ring.inverse_mul_cancel _ (IsUnit.map χ x.isUnit)] rw [one_apply_coe] /-- The commutative group structure on `MulChar R R'`. -/ noncomputable instance commGroup : CommGroup (MulChar R R') := { one := 1 mul := (· * ·) inv := Inv.inv inv_mul_cancel := inv_mul mul_assoc := by intro χ₁ χ₂ χ₃ ext a simp only [mul_assoc, Pi.mul_apply, MulChar.coeToFun_mul] mul_comm := by intro χ₁ χ₂ ext a simp only [mul_comm, Pi.mul_apply, MulChar.coeToFun_mul] one_mul := MulChar.one_mul mul_one := MulChar.mul_one } /-- If `a` is a unit and `n : ℕ`, then `(χ ^ n) a = (χ a) ^ n`. -/ theorem pow_apply_coe (χ : MulChar R R') (n : ℕ) (a : Rˣ) : (χ ^ n) a = χ a ^ n := by induction n with | zero => rw [pow_zero, pow_zero, one_apply_coe] | succ n ih => rw [pow_succ, pow_succ, mul_apply, ih] /-- If `n` is positive, then `(χ ^ n) a = (χ a) ^ n`. -/ theorem pow_apply' (χ : MulChar R R') {n : ℕ} (hn : n ≠ 0) (a : R) : (χ ^ n) a = χ a ^ n := by by_cases ha : IsUnit a · exact pow_apply_coe χ n ha.unit · rw [map_nonunit (χ ^ n) ha, map_nonunit χ ha, zero_pow hn] lemma equivToUnitHom_mul_apply (χ₁ χ₂ : MulChar R R') (a : Rˣ) : equivToUnitHom (χ₁ * χ₂) a = equivToUnitHom χ₁ a * equivToUnitHom χ₂ a := by apply_fun ((↑) : R'ˣ → R') using Units.ext push_cast simp_rw [coe_equivToUnitHom, coeToFun_mul, Pi.mul_apply] /-- The equivalence between multiplicative characters and homomorphisms of unit groups as a multiplicative equivalence. -/ noncomputable def mulEquivToUnitHom : MulChar R R' ≃* (Rˣ →* R'ˣ) := { equivToUnitHom with map_mul' := by intro χ ψ ext simp only [Equiv.toFun_as_coe, coe_equivToUnitHom, coeToFun_mul, Pi.mul_apply, MonoidHom.mul_apply, Units.val_mul] } end Group /-! ### Properties of multiplicative characters We introduce the properties of being nontrivial or quadratic and prove some basic facts about them. We now (mostly) assume that the target is a commutative ring. -/ section Properties section nontrivial variable {R : Type*} [CommMonoid R] {R' : Type*} [CommMonoidWithZero R'] lemma eq_one_iff {χ : MulChar R R'} : χ = 1 ↔ ∀ a : Rˣ, χ a = 1 := by simp only [MulChar.ext_iff, one_apply_coe] lemma ne_one_iff {χ : MulChar R R'} : χ ≠ 1 ↔ ∃ a : Rˣ, χ a ≠ 1 := by simp only [Ne, eq_one_iff, not_forall] end nontrivial section quadratic_and_comp variable {R : Type*} [CommMonoid R] {R' : Type*} [CommRing R'] {R'' : Type*} [CommRing R''] /-- A multiplicative character is *quadratic* if it takes only the values `0`, `1`, `-1`. -/ def IsQuadratic (χ : MulChar R R') : Prop := ∀ a, χ a = 0 ∨ χ a = 1 ∨ χ a = -1 /-- If two values of quadratic characters with target `ℤ` agree after coercion into a ring of characteristic not `2`, then they agree in `ℤ`. -/ theorem IsQuadratic.eq_of_eq_coe {χ : MulChar R ℤ} (hχ : IsQuadratic χ) {χ' : MulChar R' ℤ} (hχ' : IsQuadratic χ') [Nontrivial R''] (hR'' : ringChar R'' ≠ 2) {a : R} {a' : R'} (h : (χ a : R'') = χ' a') : χ a = χ' a' := Int.cast_injOn_of_ringChar_ne_two hR'' (hχ a) (hχ' a') h /-- We can post-compose a multiplicative character with a ring homomorphism. -/ @[simps] def ringHomComp (χ : MulChar R R') (f : R' →+* R'') : MulChar R R'' := { f.toMonoidHom.comp χ.toMonoidHom with toFun := fun a => f (χ a) map_nonunit' := fun a ha => by simp only [map_nonunit χ ha, map_zero] } @[simp] lemma ringHomComp_one (f : R' →+* R'') : (1 : MulChar R R').ringHomComp f = 1 := by ext1 simp only [MulChar.ringHomComp_apply, MulChar.one_apply_coe, map_one] lemma ringHomComp_inv {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (f : R' →+* R'') : (χ.ringHomComp f)⁻¹ = χ⁻¹.ringHomComp f := by ext1 simp only [inv_apply, Ring.inverse_unit, ringHomComp_apply] lemma ringHomComp_mul (χ φ : MulChar R R') (f : R' →+* R'') : (χ * φ).ringHomComp f = χ.ringHomComp f * φ.ringHomComp f := by ext1 simp only [ringHomComp_apply, coeToFun_mul, Pi.mul_apply, map_mul] lemma ringHomComp_pow (χ : MulChar R R') (f : R' →+* R'') (n : ℕ) : χ.ringHomComp f ^ n = (χ ^ n).ringHomComp f := by induction n with | zero => simp only [pow_zero, ringHomComp_one] | succ n ih => simp only [pow_succ, ih, ringHomComp_mul] lemma injective_ringHomComp {f : R' →+* R''} (hf : Function.Injective f) : Function.Injective (ringHomComp (R := R) · f) := by simpa only [Function.Injective, MulChar.ext_iff, ringHomComp, coe_mk, MonoidHom.coe_mk, OneHom.coe_mk] using fun χ χ' h a ↦ hf (h a) lemma ringHomComp_eq_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} : χ.ringHomComp f = 1 ↔ χ = 1 := by conv_lhs => rw [← (show (1 : MulChar R R').ringHomComp f = 1 by ext; simp)] exact (injective_ringHomComp hf).eq_iff lemma ringHomComp_ne_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} : χ.ringHomComp f ≠ 1 ↔ χ ≠ 1 := (ringHomComp_eq_one_iff hf).not /-- Composition with a ring homomorphism preserves the property of being a quadratic character. -/ theorem IsQuadratic.comp {χ : MulChar R R'} (hχ : χ.IsQuadratic) (f : R' →+* R'') : (χ.ringHomComp f).IsQuadratic := by intro a rcases hχ a with (ha | ha | ha) <;> simp [ha] /-- The inverse of a quadratic character is itself. → -/ theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by ext x rw [inv_apply_eq_inv] rcases hχ x with (h₀ | h₁ | h₂) · rw [h₀, Ring.inverse_zero] · rw [h₁, Ring.inverse_one] · -- Porting note: was `by norm_cast` have : (-1 : R') = (-1 : R'ˣ) := by rw [Units.val_neg, Units.val_one] rw [h₂, this, Ring.inverse_unit (-1 : R'ˣ)] rfl /-- The square of a quadratic character is the trivial character. -/ theorem IsQuadratic.sq_eq_one {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ ^ 2 = 1 := by rw [← inv_mul_cancel χ, pow_two, hχ.inv] /-- The `p`th power of a quadratic character is itself, when `p` is the (prime) characteristic of the target ring. -/ theorem IsQuadratic.pow_char {χ : MulChar R R'} (hχ : χ.IsQuadratic) (p : ℕ) [hp : Fact p.Prime] [CharP R' p] : χ ^ p = χ := by ext x rw [pow_apply_coe] rcases hχ x with (hx | hx | hx) <;> rw [hx] · rw [zero_pow (@Fact.out p.Prime).ne_zero] · rw [one_pow] · exact neg_one_pow_char R' p /-- The `n`th power of a quadratic character is the trivial character, when `n` is even. -/ theorem IsQuadratic.pow_even {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Even n) : χ ^ n = 1 := by obtain ⟨n, rfl⟩ := even_iff_two_dvd.mp hn rw [pow_mul, hχ.sq_eq_one, one_pow] /-- The `n`th power of a quadratic character is itself, when `n` is odd. -/ theorem IsQuadratic.pow_odd {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Odd n) : χ ^ n = χ := by obtain ⟨n, rfl⟩ := hn rw [pow_add, pow_one, hχ.pow_even (even_two_mul _), one_mul] /-- A multiplicative character `χ` into an integral domain is quadratic if and only if `χ^2 = 1`. -/ lemma isQuadratic_iff_sq_eq_one {M R : Type*} [CommMonoid M] [CommRing R] [NoZeroDivisors R] [Nontrivial R] {χ : MulChar M R} : IsQuadratic χ ↔ χ ^ 2 = 1:= by refine ⟨fun h ↦ ext (fun x ↦ ?_), fun h x ↦ ?_⟩ · rw [one_apply_coe, χ.pow_apply_coe] rcases h x with H | H | H · exact (not_isUnit_zero <| H ▸ IsUnit.map χ <| x.isUnit).elim · simp only [H, one_pow] · simp only [H, even_two, Even.neg_pow, one_pow] · by_cases hx : IsUnit x · refine .inr <| sq_eq_one_iff.mp ?_ rw [← χ.pow_apply' two_ne_zero, h, MulChar.one_apply hx] · exact .inl <| map_nonunit χ hx end quadratic_and_comp end Properties /-! ### Multiplicative characters with finite domain -/ section Finite variable {M : Type*} [CommMonoid M] variable {R : Type*} [CommMonoidWithZero R] /-- If `χ` is a multiplicative character on a commutative monoid `M` with finitely many units, then `χ ^ #Mˣ = 1`. -/ protected lemma pow_card_eq_one [Fintype Mˣ] (χ : MulChar M R) : χ ^ (Fintype.card Mˣ) = 1 := by ext1 rw [pow_apply_coe, ← map_pow, one_apply_coe, ← Units.val_pow_eq_pow_val, pow_card_eq_one, Units.val_eq_one.mpr rfl, map_one] /-- A multiplicative character on a commutative monoid with finitely many units has finite (= positive) order. -/ lemma orderOf_pos [Finite Mˣ] (χ : MulChar M R) : 0 < orderOf χ := by cases nonempty_fintype Mˣ apply IsOfFinOrder.orderOf_pos exact isOfFinOrder_iff_pow_eq_one.2 ⟨_, Fintype.card_pos, χ.pow_card_eq_one⟩ end Finite section sum variable {R : Type*} [CommMonoid R] [Fintype R] {R' : Type*} [CommRing R'] /-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero (when the target is a domain). -/ theorem sum_eq_zero_of_ne_one [IsDomain R'] {χ : MulChar R R'} (hχ : χ ≠ 1) : ∑ a, χ a = 0 := by rcases ne_one_iff.mp hχ with ⟨b, hb⟩ refine eq_zero_of_mul_eq_self_left hb ?_ simpa only [Finset.mul_sum, ← map_mul] using b.mulLeft_bijective.sum_comp _ /-- The sum over all values of the trivial multiplicative character on a finite ring is the cardinality of its unit group. -/ theorem sum_one_eq_card_units [DecidableEq R] : (∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by calc (∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 := Finset.sum_congr rfl fun a _ => ?_ _ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole _ _ _ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.ext⟩).card := ?_ _ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _) · split_ifs with h · exact one_apply_coe h.unit · exact map_nonunit _ h
· congr ext a simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Function.Embedding.coeFn_mk, exists_true_left, IsUnit] end sum
Mathlib/NumberTheory/MulChar/Basic.lean
568
573
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Thomas Browning -/ import Mathlib.Algebra.Group.Subgroup.Actions import Mathlib.Algebra.Group.Subgroup.ZPowers.Lemmas import Mathlib.Data.Fintype.BigOperators import Mathlib.Dynamics.PeriodicPts.Defs import Mathlib.GroupTheory.Commutator.Basic import Mathlib.GroupTheory.Coset.Basic import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.ConjAct import Mathlib.GroupTheory.GroupAction.Hom /-! # Properties of group actions involving quotient groups This file proves properties of group actions which use the quotient group construction, notably * the orbit-stabilizer theorem `MulAction.card_orbit_mul_card_stabilizer_eq_card_group` * the class formula `MulAction.card_eq_sum_card_group_div_card_stabilizer'` * Burnside's lemma `MulAction.sum_card_fixedBy_eq_card_orbits_mul_card_group`, as well as their analogues for additive groups. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Function namespace MulAction variable [Group α] section QuotientAction open Subgroup MulOpposite QuotientGroup variable (β) [Monoid β] [MulAction β α] (H : Subgroup α) /-- A typeclass for when a `MulAction β α` descends to the quotient `α ⧸ H`. -/ class QuotientAction : Prop where /-- The action fulfils a normality condition on products that lie in `H`. This ensures that the action descends to an action on the quotient `α ⧸ H`. -/ inv_mul_mem : ∀ (b : β) {a a' : α}, a⁻¹ * a' ∈ H → (b • a)⁻¹ * b • a' ∈ H /-- A typeclass for when an `AddAction β α` descends to the quotient `α ⧸ H`. -/ class _root_.AddAction.QuotientAction {α : Type u} (β : Type v) [AddGroup α] [AddMonoid β] [AddAction β α] (H : AddSubgroup α) : Prop where /-- The action fulfils a normality condition on summands that lie in `H`. This ensures that the action descends to an action on the quotient `α ⧸ H`. -/ inv_mul_mem : ∀ (b : β) {a a' : α}, -a + a' ∈ H → -(b +ᵥ a) + (b +ᵥ a') ∈ H attribute [to_additive] MulAction.QuotientAction @[to_additive] instance left_quotientAction : QuotientAction α H := ⟨fun _ _ _ _ => by rwa [smul_eq_mul, smul_eq_mul, mul_inv_rev, mul_assoc, inv_mul_cancel_left]⟩ @[to_additive] instance right_quotientAction : QuotientAction (normalizer H).op H := ⟨fun b c _ _ => by rwa [smul_def, smul_def, smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, ← mul_assoc, mem_normalizer_iff'.mp b.prop, mul_assoc, mul_inv_cancel_left]⟩ @[to_additive] instance right_quotientAction' [hH : H.Normal] : QuotientAction αᵐᵒᵖ H := ⟨fun _ _ _ _ => by rwa [smul_eq_mul_unop, smul_eq_mul_unop, mul_inv_rev, mul_assoc, hH.mem_comm_iff, mul_assoc, mul_inv_cancel_right]⟩ @[to_additive] instance quotient [QuotientAction β H] : MulAction β (α ⧸ H) where smul b := Quotient.map' (b • ·) fun _ _ h => leftRel_apply.mpr <| QuotientAction.inv_mul_mem b <| leftRel_apply.mp h one_smul q := Quotient.inductionOn' q fun a => congr_arg Quotient.mk'' (one_smul β a) mul_smul b b' q := Quotient.inductionOn' q fun a => congr_arg Quotient.mk'' (mul_smul b b' a) variable {β} @[to_additive (attr := simp)] theorem Quotient.smul_mk [QuotientAction β H] (b : β) (a : α) : (b • QuotientGroup.mk a : α ⧸ H) = QuotientGroup.mk (b • a) := rfl @[to_additive (attr := simp)] theorem Quotient.smul_coe [QuotientAction β H] (b : β) (a : α) : b • (a : α ⧸ H) = (↑(b • a) : α ⧸ H) := rfl @[to_additive (attr := simp)] theorem Quotient.mk_smul_out [QuotientAction β H] (b : β) (q : α ⧸ H) : QuotientGroup.mk (b • q.out) = b • q := by rw [← Quotient.smul_mk, QuotientGroup.out_eq'] @[to_additive] theorem Quotient.coe_smul_out [QuotientAction β H] (b : β) (q : α ⧸ H) : ↑(b • q.out) = b • q := by simp theorem _root_.QuotientGroup.out_conj_pow_minimalPeriod_mem (a : α) (q : α ⧸ H) : q.out⁻¹ * a ^ Function.minimalPeriod (a • ·) q * q.out ∈ H := by rw [mul_assoc, ← QuotientGroup.eq, QuotientGroup.out_eq', ← smul_eq_mul, Quotient.mk_smul_out, eq_comm, pow_smul_eq_iff_minimalPeriod_dvd] end QuotientAction open QuotientGroup /-- The canonical map to the left cosets. -/ def _root_.MulActionHom.toQuotient (H : Subgroup α) : α →[α] α ⧸ H where toFun := (↑); map_smul' := Quotient.smul_coe H @[simp] theorem _root_.MulActionHom.toQuotient_apply (H : Subgroup α) (g : α) : MulActionHom.toQuotient H g = g := rfl @[to_additive] instance mulLeftCosetsCompSubtypeVal (H I : Subgroup α) : MulAction I (α ⧸ H) := MulAction.compHom (α ⧸ H) (Subgroup.subtype I) variable (α) variable [MulAction α β] (x : β) /-- The canonical map from the quotient of the stabilizer to the set. -/ @[to_additive "The canonical map from the quotient of the stabilizer to the set. "] def ofQuotientStabilizer (g : α ⧸ MulAction.stabilizer α x) : β := Quotient.liftOn' g (· • x) fun g1 g2 H => calc g1 • x = g1 • (g1⁻¹ * g2) • x := congr_arg _ (leftRel_apply.mp H).symm _ = g2 • x := by rw [smul_smul, mul_inv_cancel_left] @[to_additive (attr := simp)] theorem ofQuotientStabilizer_mk (g : α) : ofQuotientStabilizer α x (QuotientGroup.mk g) = g • x := rfl @[to_additive] theorem ofQuotientStabilizer_mem_orbit (g) : ofQuotientStabilizer α x g ∈ orbit α x := Quotient.inductionOn' g fun g => ⟨g, rfl⟩ @[to_additive] theorem ofQuotientStabilizer_smul (g : α) (g' : α ⧸ MulAction.stabilizer α x) : ofQuotientStabilizer α x (g • g') = g • ofQuotientStabilizer α x g' := Quotient.inductionOn' g' fun _ => mul_smul _ _ _ @[to_additive] theorem injective_ofQuotientStabilizer : Function.Injective (ofQuotientStabilizer α x) := fun y₁ y₂ => Quotient.inductionOn₂' y₁ y₂ fun g₁ g₂ (H : g₁ • x = g₂ • x) => Quotient.sound' <| by rw [leftRel_apply] show (g₁⁻¹ * g₂) • x = x rw [mul_smul, ← H, inv_smul_smul] /-- **Orbit-stabilizer theorem**. -/ @[to_additive "Orbit-stabilizer theorem."] noncomputable def orbitEquivQuotientStabilizer (b : β) : orbit α b ≃ α ⧸ stabilizer α b := Equiv.symm <| Equiv.ofBijective (fun g => ⟨ofQuotientStabilizer α b g, ofQuotientStabilizer_mem_orbit α b g⟩) ⟨fun x y hxy => injective_ofQuotientStabilizer α b (by convert congr_arg Subtype.val hxy), fun ⟨_, ⟨g, hgb⟩⟩ => ⟨g, Subtype.eq hgb⟩⟩ /-- Orbit-stabilizer theorem. -/ @[to_additive AddAction.orbitProdStabilizerEquivAddGroup "Orbit-stabilizer theorem."] noncomputable def orbitProdStabilizerEquivGroup (b : β) : orbit α b × stabilizer α b ≃ α := (Equiv.prodCongr (orbitEquivQuotientStabilizer α _) (Equiv.refl _)).trans Subgroup.groupEquivQuotientProdSubgroup.symm /-- Orbit-stabilizer theorem. -/ @[to_additive AddAction.card_orbit_mul_card_stabilizer_eq_card_addGroup "Orbit-stabilizer theorem."] theorem card_orbit_mul_card_stabilizer_eq_card_group (b : β) [Fintype α] [Fintype <| orbit α b] [Fintype <| stabilizer α b] : Fintype.card (orbit α b) * Fintype.card (stabilizer α b) = Fintype.card α := by rw [← Fintype.card_prod, Fintype.card_congr (orbitProdStabilizerEquivGroup α b)] @[to_additive (attr := simp)] theorem orbitEquivQuotientStabilizer_symm_apply (b : β) (a : α) : ((orbitEquivQuotientStabilizer α b).symm a : β) = a • b := rfl @[to_additive (attr := simp)] theorem stabilizer_quotient {G} [Group G] (H : Subgroup G) : MulAction.stabilizer G ((1 : G) : G ⧸ H) = H := by ext simp [QuotientGroup.eq] variable (β) local notation "Ω" => Quotient <| orbitRel α β /-- **Class formula** : given `G` a group acting on `X` and `φ` a function mapping each orbit of `X` under this action (that is, each element of the quotient of `X` by the relation `orbitRel G X`) to an element in this orbit, this gives a (noncomputable) bijection between `X` and the disjoint union of `G/Stab(φ(ω))` over all orbits `ω`. In most cases you'll want `φ` to be `Quotient.out`, so we provide `MulAction.selfEquivSigmaOrbitsQuotientStabilizer'` as a special case. -/ @[to_additive "**Class formula** : given `G` an additive group acting on `X` and `φ` a function mapping each orbit of `X` under this action (that is, each element of the quotient of `X` by the relation `orbit_rel G X`) to an element in this orbit, this gives a (noncomputable) bijection between `X` and the disjoint union of `G/Stab(φ(ω))` over all orbits `ω`. In most cases you'll want `φ` to be `Quotient.out`, so we provide `AddAction.selfEquivSigmaOrbitsQuotientStabilizer'` as a special case. "] noncomputable def selfEquivSigmaOrbitsQuotientStabilizer' {φ : Ω → β} (hφ : LeftInverse Quotient.mk'' φ) : β ≃ Σω : Ω, α ⧸ stabilizer α (φ ω) := calc β ≃ Σω : Ω, orbitRel.Quotient.orbit ω := selfEquivSigmaOrbits' α β _ ≃ Σω : Ω, α ⧸ stabilizer α (φ ω) := Equiv.sigmaCongrRight fun ω => (Equiv.setCongr <| orbitRel.Quotient.orbit_eq_orbit_out _ hφ).trans <| orbitEquivQuotientStabilizer α (φ ω) /-- **Class formula** for a finite group acting on a finite type. See `MulAction.card_eq_sum_card_group_div_card_stabilizer` for a specialized version using `Quotient.out`. -/ @[to_additive "**Class formula** for a finite group acting on a finite type. See `AddAction.card_eq_sum_card_addGroup_div_card_stabilizer` for a specialized version using `Quotient.out`."] theorem card_eq_sum_card_group_div_card_stabilizer' [Fintype α] [Fintype β] [Fintype Ω] [∀ b : β, Fintype <| stabilizer α b] {φ : Ω → β} (hφ : LeftInverse Quotient.mk'' φ) : Fintype.card β = ∑ ω : Ω, Fintype.card α / Fintype.card (stabilizer α (φ ω)) := by classical have : ∀ ω : Ω, Fintype.card α / Fintype.card (stabilizer α (φ ω)) = Fintype.card (α ⧸ stabilizer α (φ ω)) := by intro ω rw [Fintype.card_congr (@Subgroup.groupEquivQuotientProdSubgroup α _ (stabilizer α <| φ ω)), Fintype.card_prod, Nat.mul_div_cancel] exact Fintype.card_pos_iff.mpr (by infer_instance) simp_rw [this, ← Fintype.card_sigma, Fintype.card_congr (selfEquivSigmaOrbitsQuotientStabilizer' α β hφ)] /-- **Class formula**. This is a special case of `MulAction.self_equiv_sigma_orbits_quotient_stabilizer'` with `φ = Quotient.out`. -/ @[to_additive "**Class formula**. This is a special case of `AddAction.self_equiv_sigma_orbits_quotient_stabilizer'` with `φ = Quotient.out`. "] noncomputable def selfEquivSigmaOrbitsQuotientStabilizer : β ≃ Σω : Ω, α ⧸ stabilizer α ω.out := selfEquivSigmaOrbitsQuotientStabilizer' α β Quotient.out_eq' /-- **Class formula** for a finite group acting on a finite type. -/ @[to_additive "**Class formula** for a finite group acting on a finite type."] theorem card_eq_sum_card_group_div_card_stabilizer [Fintype α] [Fintype β] [Fintype Ω] [∀ b : β, Fintype <| stabilizer α b] : Fintype.card β = ∑ ω : Ω, Fintype.card α / Fintype.card (stabilizer α ω.out) := card_eq_sum_card_group_div_card_stabilizer' α β Quotient.out_eq' /-- **Burnside's lemma** : a (noncomputable) bijection between the disjoint union of all `{x ∈ X | g • x = x}` for `g ∈ G` and the product `G × X/G`, where `G` is a group acting on `X` and `X/G` denotes the quotient of `X` by the relation `orbitRel G X`. -/ @[to_additive AddAction.sigmaFixedByEquivOrbitsProdAddGroup "**Burnside's lemma** : a (noncomputable) bijection between the disjoint union of all `{x ∈ X | g • x = x}` for `g ∈ G` and the product `G × X/G`, where `G` is an additive group acting on `X` and `X/G`denotes the quotient of `X` by the relation `orbitRel G X`. "] noncomputable def sigmaFixedByEquivOrbitsProdGroup : (Σa : α, fixedBy β a) ≃ Ω × α := calc (Σa : α, fixedBy β a) ≃ { ab : α × β // ab.1 • ab.2 = ab.2 } := (Equiv.subtypeProdEquivSigmaSubtype _).symm _ ≃ { ba : β × α // ba.2 • ba.1 = ba.1 } := (Equiv.prodComm α β).subtypeEquiv fun _ => Iff.rfl _ ≃ Σb : β, stabilizer α b := Equiv.subtypeProdEquivSigmaSubtype fun (b : β) a => a ∈ stabilizer α b _ ≃ Σωb : Σω : Ω, orbit α ω.out, stabilizer α (ωb.2 : β) := (selfEquivSigmaOrbits α β).sigmaCongrLeft' _ ≃ Σω : Ω, Σb : orbit α ω.out, stabilizer α (b : β) := Equiv.sigmaAssoc fun (ω : Ω) (b : orbit α ω.out) => stabilizer α (b : β) _ ≃ Σω : Ω, Σ _ : orbit α ω.out, stabilizer α ω.out := Equiv.sigmaCongrRight fun _ => Equiv.sigmaCongrRight fun ⟨_, hb⟩ => (stabilizerEquivStabilizerOfOrbitRel hb).toEquiv _ ≃ Σω : Ω, orbit α ω.out × stabilizer α ω.out := Equiv.sigmaCongrRight fun _ => Equiv.sigmaEquivProd _ _ _ ≃ Σ _ : Ω, α := Equiv.sigmaCongrRight fun ω => orbitProdStabilizerEquivGroup α ω.out _ ≃ Ω × α := Equiv.sigmaEquivProd Ω α /-- **Burnside's lemma** : given a finite group `G` acting on a set `X`, the average number of elements fixed by each `g ∈ G` is the number of orbits. -/ @[to_additive AddAction.sum_card_fixedBy_eq_card_orbits_mul_card_addGroup "**Burnside's lemma** : given a finite additive group `G` acting on a set `X`, the average number of elements fixed by each `g ∈ G` is the number of orbits. "] theorem sum_card_fixedBy_eq_card_orbits_mul_card_group [Fintype α] [∀ a : α, Fintype <| fixedBy β a] [Fintype Ω] : (∑ a : α, Fintype.card (fixedBy β a)) = Fintype.card Ω * Fintype.card α := by rw [← Fintype.card_prod, ← Fintype.card_sigma, Fintype.card_congr (sigmaFixedByEquivOrbitsProdGroup α β)] @[to_additive] instance isPretransitive_quotient (G) [Group G] (H : Subgroup G) : IsPretransitive G (G ⧸ H) where exists_smul_eq := by { rintro ⟨x⟩ ⟨y⟩ refine ⟨y * x⁻¹, QuotientGroup.eq.mpr ?_⟩ simp only [smul_eq_mul, H.one_mem, inv_mul_cancel, inv_mul_cancel_right]} variable {α} @[to_additive] instance finite_quotient_of_pretransitive_of_finite_quotient [IsPretransitive α β] {H : Subgroup α} [Finite (α ⧸ H)] : Finite <| orbitRel.Quotient H β := by rcases isEmpty_or_nonempty β with he | ⟨⟨b⟩⟩ · exact Quotient.finite _ · have h' : Finite (Quotient (rightRel H)) := Finite.of_equiv _ (quotientRightRelEquivQuotientLeftRel _).symm let f : Quotient (rightRel H) → orbitRel.Quotient H β := fun a ↦ Quotient.liftOn' a (fun g ↦ ⟦g • b⟧) fun g₁ g₂ r ↦ by replace r := Setoid.symm' _ r rw [rightRel_eq] at r simp only [Quotient.eq, orbitRel_apply, mem_orbit_iff] exact ⟨⟨g₁ * g₂⁻¹, r⟩, by simp [mul_smul]⟩ exact Finite.of_surjective f ((Quotient.surjective_liftOn' _).2 (Quotient.mk''_surjective.comp (MulAction.surjective_smul _ _))) variable {β} in /-- A bijection between the quotient of the action of a subgroup `H` on an orbit, and a corresponding quotient expressed in terms of `Setoid.comap Subtype.val`. -/ @[to_additive "A bijection between the quotient of the action of an additive subgroup `H` on an orbit, and a corresponding quotient expressed in terms of `Setoid.comap Subtype.val`."] noncomputable def equivSubgroupOrbitsSetoidComap (H : Subgroup α) (ω : Ω) : orbitRel.Quotient H (orbitRel.Quotient.orbit ω) ≃ Quotient ((orbitRel H β).comap (Subtype.val : Quotient.mk (orbitRel α β) ⁻¹' {ω} → β)) where toFun := fun q ↦ q.liftOn' (fun x ↦ ⟦⟨↑x, by simp only [Set.mem_preimage, Set.mem_singleton_iff] have hx := x.property rwa [orbitRel.Quotient.mem_orbit] at hx⟩⟧) fun a b h ↦ by simp only [← Quotient.eq, orbitRel.Quotient.subgroup_quotient_eq_iff] at h simp only [Quotient.eq] at h ⊢ exact h invFun := fun q ↦ q.liftOn' (fun x ↦ ⟦⟨↑x, by have hx := x.property simp only [Set.mem_preimage, Set.mem_singleton_iff] at hx rwa [orbitRel.Quotient.mem_orbit, @Quotient.mk''_eq_mk]⟩⟧) fun a b h ↦ by rw [Setoid.comap_rel, ← Quotient.eq'', @Quotient.mk''_eq_mk] at h simp only [orbitRel.Quotient.subgroup_quotient_eq_iff] exact h left_inv := by
simp only [LeftInverse] intro q induction q using Quotient.inductionOn' rfl
Mathlib/GroupTheory/GroupAction/Quotient.lean
333
336
/- 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 :=
Mathlib/Data/Set/Card.lean
82
83
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Batteries.Tactic.Congr import Mathlib.Data.Option.Basic import Mathlib.Data.Prod.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Data.Set.SymmDiff import Mathlib.Data.Set.Inclusion /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β. * `range f : Set β` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p → α)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ assert_not_exists WithTop OrderIso universe u v open Function Set namespace Set variable {α β γ : Type*} {ι : Sort*} /-! ### Inverse image -/ section Preimage variable {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] @[gcongr] theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ := subset_univ _ @[simp, mfld_simps] theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl @[simp] theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl @[simp] theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl @[simp] theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) := rfl @[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) : f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) := rfl @[simp] theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl @[simp] theorem preimage_id_eq : preimage (id : α → α) = id := rfl @[mfld_simps] theorem preimage_id {s : Set α} : id ⁻¹' s = s := rfl @[simp, mfld_simps] theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s := rfl @[simp] theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h @[simp] theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ := eq_empty_of_subset_empty fun _ hx => h hx theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] : (fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] /-- If preimage of each singleton under `f : α → β` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β} (hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' · exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ · have : ∀ x b, f x ≠ b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} : s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ @[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp @[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v) (H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by ext ⟨x, x_in_s⟩ constructor · intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ · intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' lemma preimage_subset {s t} (hs : s ⊆ f '' t) (hf : Set.InjOn f (f ⁻¹' s)) : f ⁻¹' s ⊆ t := by rintro a ha obtain ⟨b, hb, hba⟩ := hs ha rwa [hf ha _ hba.symm] simpa [hba] end Preimage /-! ### Image of a set under a function -/ section Image variable {f : α → β} {s t : Set α} theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s := rfl theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩ lemma preimage_subset_of_surjOn {t : Set β} (hf : Injective f) (h : SurjOn f s t) : f ⁻¹' t ⊆ s := fun _ hx ↦ hf.mem_set_image.1 <| h hx theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp @[congr] theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by aesop /-- A common special case of `image_congr` -/ theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x @[gcongr] lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h /-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in terms of `≤`. -/ @[gcongr] theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/ lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _ theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ · exact mem_union_left t h · exact mem_union_right s h⟩ @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by ext simp theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦ have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩ theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by ext simp [image, eq_comm] @[simp] theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h => (eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ @[simp, mfld_simps] theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) : t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by simp [← preimage_compl_eq_image_compl] @[simp] theorem image_id_eq : image (id : α → α) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set α) : (fun x => x) '' s = s := by ext simp theorem image_id (s : Set α) : id '' s = s := by simp lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq] theorem compl_compl_image [BooleanAlgebra α] (S : Set α) : HasCompl.compl '' (HasCompl.compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] theorem image_insert_eq {f : α → β} {a : α} {s : Set α} : f '' insert a s = insert (f a) (f '' s) := by ext simp [and_or_left, exists_or, eq_comm, or_comm, and_comm] theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by simp only [image_insert_eq, image_singleton] theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) : f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s) theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) : f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩ theorem range_inter_ssubset_iff_preimage_ssubset {f : α → β} {S S' : Set β} : range f ∩ S ⊂ range f ∩ S' ↔ f ⁻¹' S ⊂ f ⁻¹' S' := by simp only [Set.ssubset_iff_exists] apply and_congr ?_ (by aesop) constructor all_goals intro r x hx simp_all only [subset_inter_iff, inter_subset_left, true_and, mem_preimage, mem_inter_iff, mem_range, true_and] aesop theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : image f = preimage g := funext fun s => Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw [image_eq_preimage_of_inverse h₁ h₂]; rfl theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ := Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H] theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ := compl_subset_iff_union.2 <| by rw [← image_union] simp [image_univ_of_surjective H] theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ := Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by rw [diff_subset_iff, ← image_union, union_diff_self] exact image_subset f subset_union_right open scoped symmDiff in theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t := (union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans (superset_of_eq (image_union _ _ _)) theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t := Subset.antisymm (Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf) (subset_image_diff f s t) open scoped symmDiff in theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by simp_rw [Set.symmDiff_def, image_union, image_diff hf]
theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty | ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩
Mathlib/Data/Set/Image.lean
384
386
/- Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Group import Mathlib.NumberTheory.EllipticDivisibilitySequence /-! # Division polynomials of Weierstrass curves This file defines certain polynomials associated to division polynomials of Weierstrass curves. These are defined in terms of the auxiliary sequences for normalised elliptic divisibility sequences (EDS) as defined in `Mathlib.NumberTheory.EllipticDivisibilitySequence`. ## Mathematical background Let `W` be a Weierstrass curve over a commutative ring `R`. The sequence of `n`-division polynomials `ψₙ ∈ R[X, Y]` of `W` is the normalised EDS with initial values * `ψ₀ := 0`, * `ψ₁ := 1`, * `ψ₂ := 2Y + a₁X + a₃`, * `ψ₃ := 3X⁴ + b₂X³ + 3b₄X² + 3b₆X + b₈`, and * `ψ₄ := ψ₂ ⬝ (2X⁶ + b₂X⁵ + 5b₄X⁴ + 10b₆X³ + 10b₈X² + (b₂b₈ - b₄b₆)X + (b₄b₈ - b₆²))`. Furthermore, define the associated sequences `φₙ, ωₙ ∈ R[X, Y]` by * `φₙ := Xψₙ² - ψₙ₊₁ ⬝ ψₙ₋₁`, and * `ωₙ := (ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)) / 2`. Note that `ωₙ` is always well-defined as a polynomial in `R[X, Y]`. As a start, it can be shown by induction that `ψₙ` always divides `ψ₂ₙ` in `R[X, Y]`, so that `ψ₂ₙ / ψₙ` is always well-defined as a polynomial, while division by `2` is well-defined when `R` has characteristic different from `2`. In general, it can be shown that `2` always divides the polynomial `ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)` in the characteristic `0` universal ring `𝓡[X, Y] := ℤ[A₁, A₂, A₃, A₄, A₆][X, Y]` of `W`, where the `Aᵢ` are indeterminates. Then `ωₙ` can be equivalently defined as the image of this division under the associated universal morphism `𝓡[X, Y] → R[X, Y]` mapping `Aᵢ` to `aᵢ`. Now, in the coordinate ring `R[W]`, note that `ψ₂²` is congruent to the polynomial `Ψ₂Sq := 4X³ + b₂X² + 2b₄X + b₆ ∈ R[X]`. As such, the recurrences of a normalised EDS show that `ψₙ / ψ₂` are congruent to certain polynomials in `R[W]`. In particular, define `preΨₙ ∈ R[X]` as the auxiliary sequence for a normalised EDS with extra parameter `Ψ₂Sq²` and initial values * `preΨ₀ := 0`, * `preΨ₁ := 1`, * `preΨ₂ := 1`, * `preΨ₃ := ψ₃`, and * `preΨ₄ := ψ₄ / ψ₂`. The corresponding normalised EDS `Ψₙ ∈ R[X, Y]` is then given by * `Ψₙ := preΨₙ ⬝ ψ₂` if `n` is even, and * `Ψₙ := preΨₙ` if `n` is odd. Furthermore, define the associated sequences `ΨSqₙ, Φₙ ∈ R[X]` by * `ΨSqₙ := preΨₙ² ⬝ Ψ₂Sq` if `n` is even, * `ΨSqₙ := preΨₙ²` if `n` is odd, * `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁` if `n` is even, and * `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁ ⬝ Ψ₂Sq` if `n` is odd. With these definitions, `ψₙ ∈ R[X, Y]` and `φₙ ∈ R[X, Y]` are congruent in `R[W]` to `Ψₙ ∈ R[X, Y]` and `Φₙ ∈ R[X]` respectively, which are defined in terms of `Ψ₂Sq ∈ R[X]` and `preΨₙ ∈ R[X]`. ## Main definitions * `WeierstrassCurve.preΨ`: the univariate polynomials `preΨₙ`. * `WeierstrassCurve.ΨSq`: the univariate polynomials `ΨSqₙ`. * `WeierstrassCurve.Ψ`: the bivariate polynomials `Ψₙ`. * `WeierstrassCurve.Φ`: the univariate polynomials `Φₙ`. * `WeierstrassCurve.ψ`: the bivariate `n`-division polynomials `ψₙ`. * `WeierstrassCurve.φ`: the bivariate polynomials `φₙ`. * TODO: the bivariate polynomials `ωₙ`. ## Implementation notes Analogously to `Mathlib.NumberTheory.EllipticDivisibilitySequence`, the bivariate polynomials `Ψₙ` are defined in terms of the univariate polynomials `preΨₙ`. This is done partially to avoid ring division, but more crucially to allow the definition of `ΨSqₙ` and `Φₙ` as univariate polynomials without needing to work under the coordinate ring, and to allow the computation of their leading terms without ambiguity. Furthermore, evaluating these polynomials at a rational point on `W` recovers their original definition up to linear combinations of the Weierstrass equation of `W`, hence also avoiding the need to work in the coordinate ring. TODO: implementation notes for the definition of `ωₙ`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, division polynomial, torsion point -/ open Polynomial open scoped Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, Polynomial.map_ofNat, Polynomial.map_one, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom, apply_ite <| mapRingHom _, WeierstrassCurve.map]) universe r s u v namespace WeierstrassCurve variable {R : Type r} {S : Type s} [CommRing R] [CommRing S] (W : WeierstrassCurve R) section Ψ₂Sq /-! ### The univariate polynomial `Ψ₂Sq` -/ /-- The `2`-division polynomial `ψ₂ = Ψ₂`. -/ noncomputable def ψ₂ : R[X][Y] := W.toAffine.polynomialY /-- The univariate polynomial `Ψ₂Sq` congruent to `ψ₂²`. -/ noncomputable def Ψ₂Sq : R[X] := C 4 * X ^ 3 + C W.b₂ * X ^ 2 + C (2 * W.b₄) * X + C W.b₆ lemma C_Ψ₂Sq : C W.Ψ₂Sq = W.ψ₂ ^ 2 - 4 * W.toAffine.polynomial := by rw [Ψ₂Sq, ψ₂, b₂, b₄, b₆, Affine.polynomialY, Affine.polynomial] C_simp ring1 lemma ψ₂_sq : W.ψ₂ ^ 2 = C W.Ψ₂Sq + 4 * W.toAffine.polynomial := by rw [C_Ψ₂Sq, sub_add_cancel] lemma Affine.CoordinateRing.mk_ψ₂_sq : mk W W.ψ₂ ^ 2 = mk W (C W.Ψ₂Sq) := by rw [C_Ψ₂Sq, map_sub, map_mul, AdjoinRoot.mk_self, mul_zero, sub_zero, map_pow] -- TODO: remove `twoTorsionPolynomial` in favour of `Ψ₂Sq` lemma Ψ₂Sq_eq : W.Ψ₂Sq = W.twoTorsionPolynomial.toPoly := rfl end Ψ₂Sq section preΨ' /-! ### The univariate polynomials `preΨₙ` for `n ∈ ℕ` -/ /-- The `3`-division polynomial `ψ₃ = Ψ₃`. -/ noncomputable def Ψ₃ : R[X] := 3 * X ^ 4 + C W.b₂ * X ^ 3 + 3 * C W.b₄ * X ^ 2 + 3 * C W.b₆ * X + C W.b₈ /-- The univariate polynomial `preΨ₄`, which is auxiliary to the 4-division polynomial `ψ₄ = Ψ₄ = preΨ₄ψ₂`. -/ noncomputable def preΨ₄ : R[X] := 2 * X ^ 6 + C W.b₂ * X ^ 5 + 5 * C W.b₄ * X ^ 4 + 10 * C W.b₆ * X ^ 3 + 10 * C W.b₈ * X ^ 2 + C (W.b₂ * W.b₈ - W.b₄ * W.b₆) * X + C (W.b₄ * W.b₈ - W.b₆ ^ 2) /-- The univariate polynomials `preΨₙ` for `n ∈ ℕ`, which are auxiliary to the bivariate polynomials `Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/ noncomputable def preΨ' (n : ℕ) : R[X] := preNormEDS' (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n @[simp] lemma preΨ'_zero : W.preΨ' 0 = 0 := preNormEDS'_zero .. @[simp] lemma preΨ'_one : W.preΨ' 1 = 1 := preNormEDS'_one .. @[simp] lemma preΨ'_two : W.preΨ' 2 = 1 := preNormEDS'_two .. @[simp] lemma preΨ'_three : W.preΨ' 3 = W.Ψ₃ := preNormEDS'_three .. @[simp] lemma preΨ'_four : W.preΨ' 4 = W.preΨ₄ := preNormEDS'_four .. lemma preΨ'_even (m : ℕ) : W.preΨ' (2 * (m + 3)) = W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) - W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2 := preNormEDS'_even .. lemma preΨ'_odd (m : ℕ) : W.preΨ' (2 * (m + 2) + 1) = W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS'_odd .. end preΨ' section preΨ /-! ### The univariate polynomials `preΨₙ` for `n ∈ ℤ` -/ /-- The univariate polynomials `preΨₙ` for `n ∈ ℤ`, which are auxiliary to the bivariate polynomials `Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/ noncomputable def preΨ (n : ℤ) : R[X] := preNormEDS (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n @[simp] lemma preΨ_ofNat (n : ℕ) : W.preΨ n = W.preΨ' n := preNormEDS_ofNat .. @[simp] lemma preΨ_zero : W.preΨ 0 = 0 := preNormEDS_zero .. @[simp] lemma preΨ_one : W.preΨ 1 = 1 := preNormEDS_one .. @[simp] lemma preΨ_two : W.preΨ 2 = 1 := preNormEDS_two .. @[simp] lemma preΨ_three : W.preΨ 3 = W.Ψ₃ := preNormEDS_three .. @[simp] lemma preΨ_four : W.preΨ 4 = W.preΨ₄ := preNormEDS_four .. lemma preΨ_even_ofNat (m : ℕ) : W.preΨ (2 * (m + 3)) = W.preΨ (m + 2) ^ 2 * W.preΨ (m + 3) * W.preΨ (m + 5) - W.preΨ (m + 1) * W.preΨ (m + 3) * W.preΨ (m + 4) ^ 2 := preNormEDS_even_ofNat .. lemma preΨ_odd_ofNat (m : ℕ) : W.preΨ (2 * (m + 2) + 1) = W.preΨ (m + 4) * W.preΨ (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m + 1) * W.preΨ (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS_odd_ofNat .. @[simp] lemma preΨ_neg (n : ℤ) : W.preΨ (-n) = -W.preΨ n := preNormEDS_neg .. lemma preΨ_even (m : ℤ) : W.preΨ (2 * m) = W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) - W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2 := preNormEDS_even .. lemma preΨ_odd (m : ℤ) : W.preΨ (2 * m + 1) = W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS_odd .. end preΨ section ΨSq /-! ### The univariate polynomials `ΨSqₙ` -/ /-- The univariate polynomials `ΨSqₙ` congruent to `ψₙ²`. -/ noncomputable def ΨSq (n : ℤ) : R[X] := W.preΨ n ^ 2 * if Even n then W.Ψ₂Sq else 1 @[simp] lemma ΨSq_ofNat (n : ℕ) : W.ΨSq n = W.preΨ' n ^ 2 * if Even n then W.Ψ₂Sq else 1 := by simp only [ΨSq, preΨ_ofNat, Int.even_coe_nat] @[simp] lemma ΨSq_zero : W.ΨSq 0 = 0 := by rw [← Nat.cast_zero, ΨSq_ofNat, preΨ'_zero, zero_pow two_ne_zero, zero_mul] @[simp] lemma ΨSq_one : W.ΨSq 1 = 1 := by rw [← Nat.cast_one, ΨSq_ofNat, preΨ'_one, one_pow, one_mul, if_neg Nat.not_even_one] @[simp] lemma ΨSq_two : W.ΨSq 2 = W.Ψ₂Sq := by rw [← Nat.cast_two, ΨSq_ofNat, preΨ'_two, one_pow, one_mul, if_pos even_two] @[simp] lemma ΨSq_three : W.ΨSq 3 = W.Ψ₃ ^ 2 := by rw [← Nat.cast_three, ΨSq_ofNat, preΨ'_three, if_neg <| by decide, mul_one] @[simp] lemma ΨSq_four : W.ΨSq 4 = W.preΨ₄ ^ 2 * W.Ψ₂Sq := by rw [← Nat.cast_four, ΨSq_ofNat, preΨ'_four, if_pos <| by decide] lemma ΨSq_even_ofNat (m : ℕ) : W.ΨSq (2 * (m + 3)) = (W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) - W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2) ^ 2 * W.Ψ₂Sq := by rw_mod_cast [ΨSq_ofNat, preΨ'_even, if_pos <| even_two_mul _] lemma ΨSq_odd_ofNat (m : ℕ) : W.ΨSq (2 * (m + 2) + 1) = (W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by rw_mod_cast [ΨSq_ofNat, preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, mul_one] @[simp] lemma ΨSq_neg (n : ℤ) : W.ΨSq (-n) = W.ΨSq n := by simp only [ΨSq, preΨ_neg, neg_sq, even_neg] lemma ΨSq_even (m : ℤ) : W.ΨSq (2 * m) = (W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) - W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2) ^ 2 * W.Ψ₂Sq := by rw [ΨSq, preΨ_even, if_pos <| even_two_mul _] lemma ΨSq_odd (m : ℤ) : W.ΨSq (2 * m + 1) = (W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by rw [ΨSq, preΨ_odd, if_neg m.not_even_two_mul_add_one, mul_one] end ΨSq section Ψ /-! ### The bivariate polynomials `Ψₙ` -/ /-- The bivariate polynomials `Ψₙ` congruent to the `n`-division polynomials `ψₙ`. -/ protected noncomputable def Ψ (n : ℤ) : R[X][Y] := C (W.preΨ n) * if Even n then W.ψ₂ else 1 open WeierstrassCurve (Ψ) @[simp] lemma Ψ_ofNat (n : ℕ) : W.Ψ n = C (W.preΨ' n) * if Even n then W.ψ₂ else 1 := by simp only [Ψ, preΨ_ofNat, Int.even_coe_nat] @[simp] lemma Ψ_zero : W.Ψ 0 = 0 := by rw [← Nat.cast_zero, Ψ_ofNat, preΨ'_zero, C_0, zero_mul] @[simp] lemma Ψ_one : W.Ψ 1 = 1 := by rw [← Nat.cast_one, Ψ_ofNat, preΨ'_one, C_1, if_neg Nat.not_even_one, mul_one] @[simp] lemma Ψ_two : W.Ψ 2 = W.ψ₂ := by rw [← Nat.cast_two, Ψ_ofNat, preΨ'_two, C_1, one_mul, if_pos even_two] @[simp] lemma Ψ_three : W.Ψ 3 = C W.Ψ₃ := by rw [← Nat.cast_three, Ψ_ofNat, preΨ'_three, if_neg <| by decide, mul_one] @[simp] lemma Ψ_four : W.Ψ 4 = C W.preΨ₄ * W.ψ₂ := by rw [← Nat.cast_four, Ψ_ofNat, preΨ'_four, if_pos <| by decide] lemma Ψ_even_ofNat (m : ℕ) : W.Ψ (2 * (m + 3)) * W.ψ₂ = W.Ψ (m + 2) ^ 2 * W.Ψ (m + 3) * W.Ψ (m + 5) - W.Ψ (m + 1) * W.Ψ (m + 3) * W.Ψ (m + 4) ^ 2 := by repeat rw_mod_cast [Ψ_ofNat] simp_rw [preΨ'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not] split_ifs <;> C_simp <;> ring1 lemma Ψ_odd_ofNat (m : ℕ) : W.Ψ (2 * (m + 2) + 1) = W.Ψ (m + 4) * W.Ψ (m + 2) ^ 3 - W.Ψ (m + 1) * W.Ψ (m + 3) ^ 3 + W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) * C (if Even m then W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 else -W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3) := by repeat rw_mod_cast [Ψ_ofNat] simp_rw [preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not] split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1 @[simp] lemma Ψ_neg (n : ℤ) : W.Ψ (-n) = -W.Ψ n := by simp only [Ψ, preΨ_neg, C_neg, neg_mul (α := R[X][Y]), even_neg] lemma Ψ_even (m : ℤ) : W.Ψ (2 * m) * W.ψ₂ = W.Ψ (m - 1) ^ 2 * W.Ψ m * W.Ψ (m + 2) - W.Ψ (m - 2) * W.Ψ m * W.Ψ (m + 1) ^ 2 := by repeat rw [Ψ] simp_rw [preΨ_even, if_pos <| even_two_mul _, Int.even_add_one, show m + 2 = m + 1 + 1 by ring1, Int.even_add_one, show m - 2 = m - 1 - 1 by ring1, Int.even_sub_one, ite_not] split_ifs <;> C_simp <;> ring1 lemma Ψ_odd (m : ℤ) : W.Ψ (2 * m + 1) = W.Ψ (m + 2) * W.Ψ m ^ 3 - W.Ψ (m - 1) * W.Ψ (m + 1) ^ 3 + W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) * C (if Even m then W.preΨ (m + 2) * W.preΨ m ^ 3 else -W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3) := by repeat rw [Ψ] simp_rw [preΨ_odd, if_neg m.not_even_two_mul_add_one, show m + 2 = m + 1 + 1 by ring1, Int.even_add_one, Int.even_sub_one, ite_not] split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1 lemma Affine.CoordinateRing.mk_Ψ_sq (n : ℤ) : mk W (W.Ψ n) ^ 2 = mk W (C <| W.ΨSq n) := by simp only [Ψ, ΨSq, map_one, map_mul, map_pow, one_pow, mul_pow, ite_pow, apply_ite C, apply_ite <| mk W, mk_ψ₂_sq] end Ψ section Φ /-! ### The univariate polynomials `Φₙ` -/ /-- The univariate polynomials `Φₙ` congruent to `φₙ`. -/ protected noncomputable def Φ (n : ℤ) : R[X] := X * W.ΨSq n - W.preΨ (n + 1) * W.preΨ (n - 1) * if Even n then 1 else W.Ψ₂Sq open WeierstrassCurve (Φ) @[simp] lemma Φ_ofNat (n : ℕ) : W.Φ (n + 1) = X * W.preΨ' (n + 1) ^ 2 * (if Even n then 1 else W.Ψ₂Sq) - W.preΨ' (n + 2) * W.preΨ' n * (if Even n then W.Ψ₂Sq else 1) := by rw [Φ, ← Nat.cast_one, ← Nat.cast_add, ΨSq_ofNat, ← mul_assoc, ← Nat.cast_add, preΨ_ofNat, Nat.cast_add, add_sub_cancel_right, preΨ_ofNat, ← Nat.cast_add] simp only [Nat.even_add_one, Int.even_add_one, Int.even_coe_nat, ite_not] @[simp] lemma Φ_zero : W.Φ 0 = 1 := by rw [Φ, ΨSq_zero, mul_zero, zero_sub, zero_add, preΨ_one, one_mul, zero_sub, preΨ_neg, preΨ_one, neg_one_mul, neg_neg, if_pos Even.zero] @[simp] lemma Φ_one : W.Φ 1 = X := by rw [show 1 = ((0 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_one, one_pow, mul_one, if_pos Even.zero, mul_one, preΨ'_zero, mul_zero, zero_mul, sub_zero] @[simp] lemma Φ_two : W.Φ 2 = X ^ 4 - C W.b₄ * X ^ 2 - C (2 * W.b₆) * X - C W.b₈ := by rw [show 2 = ((1 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_two, if_neg Nat.not_even_one, Ψ₂Sq, preΨ'_three, preΨ'_one, if_neg Nat.not_even_one, Ψ₃] C_simp ring1 @[simp] lemma Φ_three : W.Φ 3 = X * W.Ψ₃ ^ 2 - W.preΨ₄ * W.Ψ₂Sq := by rw [show 3 = ((2 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_three, if_pos <| by decide, mul_one, preΨ'_four, preΨ'_two, mul_one, if_pos even_two] @[simp] lemma Φ_four : W.Φ 4 = X * W.preΨ₄ ^ 2 * W.Ψ₂Sq - W.Ψ₃ * (W.preΨ₄ * W.Ψ₂Sq ^ 2 - W.Ψ₃ ^ 3) := by rw [show 4 = ((3 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_four, if_neg <| by decide, show 3 + 2 = 2 * 2 + 1 by rfl, preΨ'_odd, preΨ'_four, preΨ'_two, if_pos Even.zero, preΨ'_one, preΨ'_three, if_pos Even.zero, if_neg <| by decide] ring1 @[simp] lemma Φ_neg (n : ℤ) : W.Φ (-n) = W.Φ n := by simp only [Φ, ΨSq_neg, neg_add_eq_sub, ← neg_sub n, preΨ_neg, ← neg_add', preΨ_neg, neg_mul_neg, mul_comm <| W.preΨ <| n - 1, even_neg] end Φ section ψ /-! ### The bivariate polynomials `ψₙ` -/ /-- The bivariate `n`-division polynomials `ψₙ`. -/ protected noncomputable def ψ (n : ℤ) : R[X][Y] := normEDS W.ψ₂ (C W.Ψ₃) (C W.preΨ₄) n open WeierstrassCurve (Ψ ψ) @[simp] lemma ψ_zero : W.ψ 0 = 0 := normEDS_zero .. @[simp] lemma ψ_one : W.ψ 1 = 1 := normEDS_one .. @[simp] lemma ψ_two : W.ψ 2 = W.ψ₂ := normEDS_two .. @[simp] lemma ψ_three : W.ψ 3 = C W.Ψ₃ := normEDS_three .. @[simp] lemma ψ_four : W.ψ 4 = C W.preΨ₄ * W.ψ₂ := normEDS_four .. lemma ψ_even_ofNat (m : ℕ) : W.ψ (2 * (m + 3)) * W.ψ₂ = W.ψ (m + 2) ^ 2 * W.ψ (m + 3) * W.ψ (m + 5) - W.ψ (m + 1) * W.ψ (m + 3) * W.ψ (m + 4) ^ 2 := normEDS_even_ofNat .. lemma ψ_odd_ofNat (m : ℕ) : W.ψ (2 * (m + 2) + 1) = W.ψ (m + 4) * W.ψ (m + 2) ^ 3 - W.ψ (m + 1) * W.ψ (m + 3) ^ 3 := normEDS_odd_ofNat .. @[simp] lemma ψ_neg (n : ℤ) : W.ψ (-n) = -W.ψ n := normEDS_neg .. lemma ψ_even (m : ℤ) : W.ψ (2 * m) * W.ψ₂ = W.ψ (m - 1) ^ 2 * W.ψ m * W.ψ (m + 2) - W.ψ (m - 2) * W.ψ m * W.ψ (m + 1) ^ 2 := normEDS_even .. lemma ψ_odd (m : ℤ) : W.ψ (2 * m + 1) = W.ψ (m + 2) * W.ψ m ^ 3 - W.ψ (m - 1) * W.ψ (m + 1) ^ 3 := normEDS_odd .. lemma Affine.CoordinateRing.mk_ψ (n : ℤ) : mk W (W.ψ n) = mk W (W.Ψ n) := by simp only [ψ, normEDS, Ψ, preΨ, map_mul, map_pow, map_preNormEDS, ← mk_ψ₂_sq, ← pow_mul] end ψ section φ /-! ### The bivariate polynomials `φₙ` -/ /-- The bivariate polynomials `φₙ`. -/ protected noncomputable def φ (n : ℤ) : R[X][Y] := C X * W.ψ n ^ 2 - W.ψ (n + 1) * W.ψ (n - 1) open WeierstrassCurve (Ψ Φ φ) @[simp] lemma φ_zero : W.φ 0 = 1 := by rw [φ, ψ_zero, zero_pow two_ne_zero, mul_zero, zero_sub, zero_add, ψ_one, one_mul, zero_sub, ψ_neg, neg_neg, ψ_one] @[simp] lemma φ_one : W.φ 1 = C X := by rw [φ, ψ_one, one_pow, mul_one, sub_self, ψ_zero, mul_zero, sub_zero] @[simp] lemma φ_two : W.φ 2 = C X * W.ψ₂ ^ 2 - C W.Ψ₃ := by rw [φ, ψ_two, two_add_one_eq_three, ψ_three, show (2 - 1 : ℤ) = 1 by rfl, ψ_one, mul_one] @[simp] lemma φ_three : W.φ 3 = C X * C W.Ψ₃ ^ 2 - C W.preΨ₄ * W.ψ₂ ^ 2 := by rw [φ, ψ_three, three_add_one_eq_four, ψ_four, mul_assoc, show (3 - 1 : ℤ) = 2 by rfl, ψ_two, ← sq] @[simp] lemma φ_four : W.φ 4 = C X * C W.preΨ₄ ^ 2 * W.ψ₂ ^ 2 - C W.preΨ₄ * W.ψ₂ ^ 4 * C W.Ψ₃ + C W.Ψ₃ ^ 4 := by rw [φ, ψ_four, show (4 + 1 : ℤ) = 2 * 2 + 1 by rfl, ψ_odd, two_add_two_eq_four, ψ_four, show (2 - 1 : ℤ) = 1 by rfl, ψ_two, ψ_one, two_add_one_eq_three, show (4 - 1 : ℤ) = 3 by rfl, ψ_three] ring1 @[simp] lemma φ_neg (n : ℤ) : W.φ (-n) = W.φ n := by rw [φ, ψ_neg, neg_sq (R := R[X][Y]), neg_add_eq_sub, ← neg_sub n, ψ_neg, ← neg_add', ψ_neg, neg_mul_neg (α := R[X][Y]), mul_comm <| W.ψ _, φ] lemma Affine.CoordinateRing.mk_φ (n : ℤ) : mk W (W.φ n) = mk W (C <| W.Φ n) := by simp_rw [φ, Φ, map_sub, map_mul, map_pow, mk_ψ, mk_Ψ_sq, Ψ, map_mul, mul_mul_mul_comm _ <| mk W <| ite .., Int.even_add_one, Int.even_sub_one, ← sq, ite_not, apply_ite C, apply_ite <| mk W, ite_pow, map_one, one_pow, mk_ψ₂_sq] end φ section Map /-! ### Maps across ring homomorphisms -/ open WeierstrassCurve (Ψ Φ ψ φ) variable (f : R →+* S) lemma map_ψ₂ : (W.map f).ψ₂ = W.ψ₂.map (mapRingHom f) := by simp only [ψ₂, Affine.map_polynomialY] lemma map_Ψ₂Sq : (W.map f).Ψ₂Sq = W.Ψ₂Sq.map f := by simp only [Ψ₂Sq, map_b₂, map_b₄, map_b₆] map_simp lemma map_Ψ₃ : (W.map f).Ψ₃ = W.Ψ₃.map f := by simp only [Ψ₃, map_b₂, map_b₄, map_b₆, map_b₈] map_simp lemma map_preΨ₄ : (W.map f).preΨ₄ = W.preΨ₄.map f := by simp only [preΨ₄, map_b₂, map_b₄, map_b₆, map_b₈] map_simp lemma map_preΨ' (n : ℕ) : (W.map f).preΨ' n = (W.preΨ' n).map f := by simp only [preΨ', map_Ψ₂Sq, map_Ψ₃, map_preΨ₄, ← coe_mapRingHom, map_preNormEDS'] map_simp lemma map_preΨ (n : ℤ) : (W.map f).preΨ n = (W.preΨ n).map f := by simp only [preΨ, map_Ψ₂Sq, map_Ψ₃, map_preΨ₄, ← coe_mapRingHom, map_preNormEDS] map_simp lemma map_ΨSq (n : ℤ) : (W.map f).ΨSq n = (W.ΨSq n).map f := by simp only [ΨSq, map_preΨ, map_Ψ₂Sq, ← coe_mapRingHom] map_simp lemma map_Ψ (n : ℤ) : (W.map f).Ψ n = (W.Ψ n).map (mapRingHom f) := by simp only [Ψ, map_preΨ, map_ψ₂, ← coe_mapRingHom] map_simp lemma map_Φ (n : ℤ) : (W.map f).Φ n = (W.Φ n).map f := by simp only [Φ, map_ΨSq, map_preΨ, map_Ψ₂Sq, ← coe_mapRingHom]
map_simp
Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean
581
582
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) : (⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ · exact mk_toType o · exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) : (a ^ b).card ≤ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ · simpa using one_lt_omega0.le.trans ha · intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add · rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha · rwa [aleph0_le_card] · intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) · simpa using hb.pos.ne' · refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ · exact Cardinal.bddAbove_of_small _ · simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) : (a ^ b).card ≤ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] · exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b · rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le · exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) · exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a hb · exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a (omega0_pos.trans_le hb) · exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o · rw [omega_zero] exact principal_opow_omega0 · intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊢ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· ^ ·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· + ·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· * ·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
854
857
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Data.Set.SymmDiff import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Irreducible /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : IsInducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (by fun_prop)).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (Continuous.prodMk_left _).continuousOn) theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ classical rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction I using Finset.induction_on with | empty => refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI | insert i I _ ihI => rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn /-- The connected component of a point is the maximal connected set that contains this point. -/ def connectedComponent (x : α) : Set α := ⋃₀ { s : Set α | IsPreconnected s ∧ x ∈ s } open Classical in /-- Given a set `F` in a topological space `α` and a point `x : α`, the connected component of `x` in `F` is the connected component of `x` in the subtype `F` seen as a set in `α`. This definition does not make sense if `x` is not in `F` so we return the empty set in this case. -/ def connectedComponentIn (F : Set α) (x : α) : Set α := if h : x ∈ F then (↑) '' connectedComponent (⟨x, h⟩ : F) else ∅ theorem connectedComponentIn_eq_image {F : Set α} {x : α} (h : x ∈ F) : connectedComponentIn F x = (↑) '' connectedComponent (⟨x, h⟩ : F) := dif_pos h theorem connectedComponentIn_eq_empty {F : Set α} {x : α} (h : x ∉ F) : connectedComponentIn F x = ∅ := dif_neg h theorem mem_connectedComponent {x : α} : x ∈ connectedComponent x := mem_sUnion_of_mem (mem_singleton x) ⟨isPreconnected_singleton, mem_singleton x⟩ theorem mem_connectedComponentIn {x : α} {F : Set α} (hx : x ∈ F) : x ∈ connectedComponentIn F x := by simp [connectedComponentIn_eq_image hx, mem_connectedComponent, hx] theorem connectedComponent_nonempty {x : α} : (connectedComponent x).Nonempty := ⟨x, mem_connectedComponent⟩ theorem connectedComponentIn_nonempty_iff {x : α} {F : Set α} : (connectedComponentIn F x).Nonempty ↔ x ∈ F := by rw [connectedComponentIn] split_ifs <;> simp [connectedComponent_nonempty, *] theorem connectedComponentIn_subset (F : Set α) (x : α) : connectedComponentIn F x ⊆ F := by rw [connectedComponentIn] split_ifs <;> simp theorem isPreconnected_connectedComponent {x : α} : IsPreconnected (connectedComponent x) := isPreconnected_sUnion x _ (fun _ => And.right) fun _ => And.left theorem isPreconnected_connectedComponentIn {x : α} {F : Set α} : IsPreconnected (connectedComponentIn F x) := by rw [connectedComponentIn]; split_ifs · exact IsInducing.subtypeVal.isPreconnected_image.mpr isPreconnected_connectedComponent · exact isPreconnected_empty theorem isConnected_connectedComponent {x : α} : IsConnected (connectedComponent x) := ⟨⟨x, mem_connectedComponent⟩, isPreconnected_connectedComponent⟩ theorem isConnected_connectedComponentIn_iff {x : α} {F : Set α} : IsConnected (connectedComponentIn F x) ↔ x ∈ F := by simp_rw [← connectedComponentIn_nonempty_iff, IsConnected, isPreconnected_connectedComponentIn, and_true] theorem IsPreconnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsPreconnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := fun _z hz => mem_sUnion_of_mem hz ⟨H1, H2⟩ theorem IsPreconnected.subset_connectedComponentIn {x : α} {F : Set α} (hs : IsPreconnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connectedComponentIn F x := by have : IsPreconnected (((↑) : F → α) ⁻¹' s) := by refine IsInducing.subtypeVal.isPreconnected_image.mp ?_ rwa [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] have h2xs : (⟨x, hsF hxs⟩ : F) ∈ (↑) ⁻¹' s := by rw [mem_preimage] exact hxs have := this.subset_connectedComponent h2xs rw [connectedComponentIn_eq_image (hsF hxs)] refine Subset.trans ?_ (image_subset _ this) rw [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] theorem IsConnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsConnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := H1.2.subset_connectedComponent H2 theorem IsPreconnected.connectedComponentIn {x : α} {F : Set α} (h : IsPreconnected F) (hx : x ∈ F) : connectedComponentIn F x = F := (connectedComponentIn_subset F x).antisymm (h.subset_connectedComponentIn hx subset_rfl) theorem connectedComponent_eq {x y : α} (h : y ∈ connectedComponent x) : connectedComponent x = connectedComponent y := eq_of_subset_of_subset (isConnected_connectedComponent.subset_connectedComponent h) (isConnected_connectedComponent.subset_connectedComponent (Set.mem_of_mem_of_subset mem_connectedComponent (isConnected_connectedComponent.subset_connectedComponent h))) theorem connectedComponent_eq_iff_mem {x y : α} : connectedComponent x = connectedComponent y ↔ x ∈ connectedComponent y := ⟨fun h => h ▸ mem_connectedComponent, fun h => (connectedComponent_eq h).symm⟩ theorem connectedComponentIn_eq {x y : α} {F : Set α} (h : y ∈ connectedComponentIn F x) : connectedComponentIn F x = connectedComponentIn F y := by have hx : x ∈ F := connectedComponentIn_nonempty_iff.mp ⟨y, h⟩
simp_rw [connectedComponentIn_eq_image hx] at h ⊢ obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h simp_rw [connectedComponentIn_eq_image hy, connectedComponent_eq h2y] theorem connectedComponentIn_univ (x : α) : connectedComponentIn univ x = connectedComponent x := subset_antisymm (isPreconnected_connectedComponentIn.subset_connectedComponent <| mem_connectedComponentIn trivial) (isPreconnected_connectedComponent.subset_connectedComponentIn mem_connectedComponent <| subset_univ _) theorem connectedComponent_disjoint {x y : α} (h : connectedComponent x ≠ connectedComponent y) :
Mathlib/Topology/Connected/Basic.lean
554
565
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Opposite /-! # Calculus of fractions Following the definitions by [Gabriel and Zisman][gabriel-zisman-1967], given a morphism property `W : MorphismProperty C` on a category `C`, we introduce the class `W.HasLeftCalculusOfFractions`. The main result `Localization.exists_leftFraction` is that if `L : C ⥤ D` is a localization functor for `W`, then for any morphism `L.obj X ⟶ L.obj Y` in `D`, there exists an auxiliary object `Y' : C` and morphisms `g : X ⟶ Y'` and `s : Y ⟶ Y'`, with `W s`, such that the given morphism is a sort of fraction `g / s`, or more precisely of the form `L.map g ≫ (Localization.isoOfHom L W s hs).inv`. We also show that the functor `L.mapArrow : Arrow C ⥤ Arrow D` is essentially surjective. Similar results are obtained when `W` has a right calculus of fractions. ## References * [P. Gabriel, M. Zisman, *Calculus of fractions and homotopy theory*][gabriel-zisman-1967] -/ namespace CategoryTheory variable {C D : Type*} [Category C] [Category D] open Category namespace MorphismProperty /-- A left fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the datum of an object `Y' : C` and maps `f : X ⟶ Y'` and `s : Y ⟶ Y'` such that `W s`. -/ structure LeftFraction (W : MorphismProperty C) (X Y : C) where /-- the auxiliary object of a left fraction -/ {Y' : C} /-- the numerator of a left fraction -/ f : X ⟶ Y' /-- the denominator of a left fraction -/ s : Y ⟶ Y' /-- the condition that the denominator belongs to the given morphism property -/ hs : W s namespace LeftFraction variable (W : MorphismProperty C) {X Y : C} /-- The left fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/ @[simps] def ofHom (f : X ⟶ Y) [W.ContainsIdentities] : W.LeftFraction X Y := mk f (𝟙 Y) (W.id_mem Y) variable {W} /-- The left fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/ @[simps] def ofInv (s : Y ⟶ X) (hs : W s) : W.LeftFraction X Y := mk (𝟙 X) s hs /-- If `φ : W.LeftFraction X Y` and `L` is a functor which inverts `W`, this is the induced morphism `L.obj X ⟶ L.obj Y` -/ noncomputable def map (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.obj X ⟶ L.obj Y := have := hL _ φ.hs L.map φ.f ≫ inv (L.map φ.s) @[reassoc (attr := simp)] lemma map_comp_map_s (φ : W.LeftFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : φ.map L hL ≫ L.map φ.s = L.map φ.f := by letI := hL _ φ.hs simp [map] variable (W) lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] : (ofHom W f).map L hL = L.map f := by simp [map] @[reassoc (attr := simp)] lemma map_ofInv_hom_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) : (ofInv s hs).map L hL ≫ L.map s = 𝟙 _ := by letI := hL _ hs simp [map] @[reassoc (attr := simp)] lemma map_hom_ofInv_id (s : Y ⟶ X) (hs : W s) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.map s ≫ (ofInv s hs).map L hL = 𝟙 _ := by letI := hL _ hs simp [map] variable {W} lemma cases (α : W.LeftFraction X Y) : ∃ (Y' : C) (f : X ⟶ Y') (s : Y ⟶ Y') (hs : W s), α = LeftFraction.mk f s hs := ⟨_, _, _, _, rfl⟩ end LeftFraction /-- A right fraction from `X : C` to `Y : C` for `W : MorphismProperty C` consists of the datum of an object `X' : C` and maps `s : X' ⟶ X` and `f : X' ⟶ Y` such that `W s`. -/ structure RightFraction (W : MorphismProperty C) (X Y : C) where /-- the auxiliary object of a right fraction -/ {X' : C} /-- the denominator of a right fraction -/ s : X' ⟶ X /-- the condition that the denominator belongs to the given morphism property -/ hs : W s /-- the numerator of a right fraction -/ f : X' ⟶ Y namespace RightFraction variable (W : MorphismProperty C) variable {X Y : C} /-- The right fraction from `X` to `Y` given by a morphism `f : X ⟶ Y`. -/ @[simps] def ofHom (f : X ⟶ Y) [W.ContainsIdentities] : W.RightFraction X Y := mk (𝟙 X) (W.id_mem X) f variable {W} /-- The right fraction from `X` to `Y` given by a morphism `s : Y ⟶ X` such that `W s`. -/ @[simps] def ofInv (s : Y ⟶ X) (hs : W s) : W.RightFraction X Y := mk s hs (𝟙 Y) /-- If `φ : W.RightFraction X Y` and `L` is a functor which inverts `W`, this is the induced morphism `L.obj X ⟶ L.obj Y` -/ noncomputable def map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.obj X ⟶ L.obj Y := have := hL _ φ.hs inv (L.map φ.s) ≫ L.map φ.f @[reassoc (attr := simp)] lemma map_s_comp_map (φ : W.RightFraction X Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) : L.map φ.s ≫ φ.map L hL = L.map φ.f := by letI := hL _ φ.hs simp [map] variable (W)
@[simp] lemma map_ofHom (f : X ⟶ Y) (L : C ⥤ D) (hL : W.IsInvertedBy L) [W.ContainsIdentities] : (ofHom W f).map L hL = L.map f := by simp [map]
Mathlib/CategoryTheory/Localization/CalculusOfFractions.lean
148
151
/- 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 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 : Num} : (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 : Num} : (m : α) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr cast_lt @[simp, norm_cast] theorem cast_inj [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] 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 theorem castNum_eq_bitwise {f : Num → Num → Num} {g : Bool → Bool → Bool} (p : PosNum → PosNum → Num) (gff : g false false = false) (f00 : f 0 0 = 0) (f0n : ∀ n, f 0 (pos n) = cond (g false true) (pos n) 0) (fn0 : ∀ n, f (pos n) 0 = cond (g true false) (pos n) 0) (fnn : ∀ m n, f (pos m) (pos n) = p m n) (p11 : p 1 1 = cond (g true true) 1 0) (p1b : ∀ b n, p 1 (PosNum.bit b n) = bit (g true b) (cond (g false true) (pos n) 0)) (pb1 : ∀ a m, p (PosNum.bit a m) 1 = bit (g a true) (cond (g true false) (pos m) 0)) (pbb : ∀ a b m n, p (PosNum.bit a m) (PosNum.bit b n) = bit (g a b) (p m n)) : ∀ m n : Num, (f m n : ℕ) = Nat.bitwise g m n := by intros m n obtain - | m := m <;> obtain - | n := n <;> try simp only [show zero = 0 from rfl, show ((0 : Num) : ℕ) = 0 from rfl] · rw [f00, Nat.bitwise_zero]; rfl · rw [f0n, Nat.bitwise_zero_left] cases g false true <;> rfl · rw [fn0, Nat.bitwise_zero_right] cases g true false <;> rfl · rw [fnn] have this b (n : PosNum) : (cond b (↑n) 0 : ℕ) = ↑(cond b (pos n) 0 : Num) := by cases b <;> rfl have this' b (n : PosNum) : ↑ (pos (PosNum.bit b n)) = Nat.bit b ↑n := by cases b <;> simp induction' m with m IH m IH generalizing n <;> obtain - | n | n := n any_goals simp only [show one = 1 from rfl, show pos 1 = 1 from rfl, show PosNum.bit0 = PosNum.bit false from rfl, show PosNum.bit1 = PosNum.bit true from rfl, show ((1 : Num) : ℕ) = Nat.bit true 0 from rfl] all_goals repeat rw [this'] rw [Nat.bitwise_bit gff] any_goals rw [Nat.bitwise_zero, p11]; cases g true true <;> rfl any_goals rw [Nat.bitwise_zero_left, ← Bool.cond_eq_ite, this, ← bit_to_nat, p1b] any_goals rw [Nat.bitwise_zero_right, ← Bool.cond_eq_ite, this, ← bit_to_nat, pb1] all_goals rw [← show ∀ n : PosNum, ↑(p m n) = Nat.bitwise g ↑m ↑n from IH] rw [← bit_to_nat, pbb] @[simp, norm_cast] theorem castNum_or : ∀ m n : Num, ↑(m ||| n) = (↑m ||| ↑n : ℕ) := by apply castNum_eq_bitwise fun x y => pos (PosNum.lor x y) <;> (try rintro (_ | _)) <;> (try rintro (_ | _)) <;> intros <;> rfl @[simp, norm_cast] theorem castNum_and : ∀ m n : Num, ↑(m &&& n) = (↑m &&& ↑n : ℕ) := by apply castNum_eq_bitwise PosNum.land <;> intros <;> (try cases_type* Bool) <;> rfl @[simp, norm_cast] theorem castNum_ldiff : ∀ m n : Num, (ldiff m n : ℕ) = Nat.ldiff m n := by apply castNum_eq_bitwise PosNum.ldiff <;> intros <;> (try cases_type* Bool) <;> rfl @[simp, norm_cast] theorem castNum_xor : ∀ m n : Num, ↑(m ^^^ n) = (↑m ^^^ ↑n : ℕ) := by apply castNum_eq_bitwise PosNum.lxor <;> intros <;> (try cases_type* Bool) <;> rfl @[simp, norm_cast] theorem castNum_shiftLeft (m : Num) (n : Nat) : ↑(m <<< n) = (m : ℕ) <<< (n : ℕ) := by cases m <;> dsimp only [← shiftl_eq_shiftLeft, shiftl] · symm apply Nat.zero_shiftLeft simp only [cast_pos] induction' n with n IH · rfl simp [PosNum.shiftl_succ_eq_bit0_shiftl, Nat.shiftLeft_succ, IH, pow_succ, ← mul_assoc, mul_comm, -shiftl_eq_shiftLeft, -PosNum.shiftl_eq_shiftLeft, shiftl, mul_two] @[simp, norm_cast] theorem castNum_shiftRight (m : Num) (n : Nat) : ↑(m >>> n) = (m : ℕ) >>> (n : ℕ) := by obtain - | m := m <;> dsimp only [← shiftr_eq_shiftRight, shiftr] · symm apply Nat.zero_shiftRight induction' n with n IH generalizing m · cases m <;> rfl have hdiv2 : ∀ m, Nat.div2 (m + m) = m := by intro; rw [Nat.div2_val]; omega obtain - | m | m := m <;> dsimp only [PosNum.shiftr, ← PosNum.shiftr_eq_shiftRight] · rw [Nat.shiftRight_eq_div_pow] symm apply Nat.div_eq_of_lt simp · trans · apply IH change Nat.shiftRight m n = Nat.shiftRight (m + m + 1) (n + 1) rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add] apply congr_arg fun x => Nat.shiftRight x n simp [-add_assoc, Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val, hdiv2] · trans · apply IH change Nat.shiftRight m n = Nat.shiftRight (m + m) (n + 1) rw [add_comm n 1, @Nat.shiftRight_eq _ (1 + n), Nat.shiftRight_add] apply congr_arg fun x => Nat.shiftRight x n simp [-add_assoc, Nat.shiftRight_succ, Nat.shiftRight_zero, ← Nat.div2_val, hdiv2] @[simp] theorem castNum_testBit (m n) : testBit m n = Nat.testBit m n := by cases m with dsimp only [testBit] | zero => rw [show (Num.zero : Nat) = 0 from rfl, Nat.zero_testBit] | pos m => rw [cast_pos] induction' n with n IH generalizing m <;> obtain - | m | m := m <;> simp only [PosNum.testBit] · rfl · rw [PosNum.cast_bit1, ← two_mul, ← congr_fun Nat.bit_true, Nat.testBit_bit_zero] · rw [PosNum.cast_bit0, ← two_mul, ← congr_fun Nat.bit_false, Nat.testBit_bit_zero] · simp [Nat.testBit_add_one] · rw [PosNum.cast_bit1, ← two_mul, ← congr_fun Nat.bit_true, Nat.testBit_bit_succ, IH] · rw [PosNum.cast_bit0, ← two_mul, ← congr_fun Nat.bit_false, Nat.testBit_bit_succ, IH] end Num namespace Int /-- Cast a `SNum` to the corresponding integer. -/ def ofSnum : SNum → ℤ := SNum.rec' (fun a => cond a (-1) 0) fun a _p IH => cond a (2 * IH + 1) (2 * IH) instance snumCoe : Coe SNum ℤ := ⟨ofSnum⟩ end Int instance SNum.lt : LT SNum := ⟨fun a b => (a : ℤ) < b⟩ instance SNum.le : LE SNum := ⟨fun a b => (a : ℤ) ≤ b⟩
Mathlib/Data/Num/Lemmas.lean
1,331
1,334
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Group.Measure import Mathlib.MeasureTheory.Measure.Prod /-! # Measure theory in the product of groups In this file we show properties about measure theory in products of measurable groups and properties of iterated integrals in measurable groups. These lemmas show the uniqueness of left invariant measures on measurable groups, up to scaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos. The idea of the proof is to use the translation invariance of measures to prove `μ(t) = c * μ(s)` for two sets `s` and `t`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be the characteristic functions of `s` and `t`. Assume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)` preserves the measure `μ × ν`, which means that ``` ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ ``` If we apply this to `h x y := e x * f y⁻¹ / ν ((fun h ↦ h * y⁻¹) ⁻¹' s)`, we can rewrite the RHS to `μ(t)`, and the LHS to `c * μ(s)`, where `c = c(ν)` does not depend on `μ`. Applying this to `μ` and to `ν` gives `μ (t) / μ (s) = ν (t) / ν (s)`, which is the uniqueness up to scalar multiplication. The proof in [Halmos] seems to contain an omission in §60 Th. A, see `MeasureTheory.measure_lintegral_div_measure`. Note that this theory only applies in measurable groups, i.e., when multiplication and inversion are measurable. This is not the case in general in locally compact groups, or even in compact groups, when the topology is not second-countable. For arguments along the same line, but using continuous functions instead of measurable sets and working in the general locally compact setting, see the file `Mathlib/MeasureTheory/Measure/Haar/Unique.lean`. -/ noncomputable section open Set hiding prod_eq open Function MeasureTheory open Filter hiding map open scoped ENNReal Pointwise MeasureTheory variable (G : Type*) [MeasurableSpace G] variable [Group G] [MeasurableMul₂ G] variable (μ ν : Measure G) [SFinite ν] [SFinite μ] {s : Set G} /-- The map `(x, y) ↦ (x, xy)` as a `MeasurableEquiv`. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a `MeasurableEquiv`."] protected def MeasurableEquiv.shearMulRight [MeasurableInv G] : G × G ≃ᵐ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with measurable_toFun := measurable_fst.prodMk measurable_mul measurable_invFun := measurable_fst.prodMk <| measurable_fst.inv.mul measurable_snd } /-- The map `(x, y) ↦ (x, y / x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, yx)` -/ @[to_additive "The map `(x, y) ↦ (x, y - x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, y + x)`."] protected def MeasurableEquiv.shearDivRight [MeasurableInv G] : G × G ≃ᵐ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.divRight with measurable_toFun := measurable_fst.prodMk <| measurable_snd.div measurable_fst measurable_invFun := measurable_fst.prodMk <| measurable_snd.mul measurable_fst } variable {G} namespace MeasureTheory open Measure section LeftInvariant /-- The multiplicative shear mapping `(x, y) ↦ (x, xy)` preserves the measure `μ × ν`. This condition is part of the definition of a measurable group in [Halmos, §59]. There, the map in this lemma is called `S`. -/ @[to_additive measurePreserving_prod_add " The shear mapping `(x, y) ↦ (x, x + y)` preserves the measure `μ × ν`. "] theorem measurePreserving_prod_mul [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.1, z.1 * z.2)) (μ.prod ν) (μ.prod ν) := (MeasurePreserving.id μ).skew_product measurable_mul <| Filter.Eventually.of_forall <| map_mul_left_eq_self ν /-- The map `(x, y) ↦ (y, yx)` sends the measure `μ × ν` to `ν × μ`. This is the map `SR` in [Halmos, §59]. `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_prod_add_swap " The map `(x, y) ↦ (y, y + x)` sends the measure `μ × ν` to `ν × μ`. "] theorem measurePreserving_prod_mul_swap [IsMulLeftInvariant μ] : MeasurePreserving (fun z : G × G => (z.2, z.2 * z.1)) (μ.prod ν) (ν.prod μ) := (measurePreserving_prod_mul ν μ).comp measurePreserving_swap @[to_additive] theorem measurable_measure_mul_right (hs : MeasurableSet s) : Measurable fun x => μ ((fun y => y * x) ⁻¹' s) := by suffices Measurable fun y => μ ((fun x => (x, y)) ⁻¹' ((fun z : G × G => ((1 : G), z.1 * z.2)) ⁻¹' univ ×ˢ s)) by convert this using 1; ext1 x; congr 1 with y : 1; simp apply measurable_measure_prodMk_right apply measurable_const.prodMk measurable_mul (MeasurableSet.univ.prod hs) infer_instance
variable [MeasurableInv G] /-- The map `(x, y) ↦ (x, x⁻¹y)` is measure-preserving. This is the function `S⁻¹` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)`. -/ @[to_additive measurePreserving_prod_neg_add "The map `(x, y) ↦ (x, - x + y)` is measure-preserving."] theorem measurePreserving_prod_inv_mul [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.1, z.1⁻¹ * z.2)) (μ.prod ν) (μ.prod ν) :=
Mathlib/MeasureTheory/Group/Prod.lean
108
116
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap import Mathlib.MeasureTheory.Integral.Bochner.FundThmCalculus import Mathlib.MeasureTheory.Integral.Bochner.Set deprecated_module (since := "2025-04-15")
Mathlib/MeasureTheory/Integral/SetIntegral.lean
865
869
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Eval.Subring import Mathlib.Algebra.Polynomial.Monic /-! # Polynomials that lift Given semirings `R` and `S` with a morphism `f : R →+* S`, we define a subsemiring `lifts` of `S[X]` by the image of `RingHom.of (map f)`. Then, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree and that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree). ## Main definition * `lifts (f : R →+* S)` : the subsemiring of polynomials that lift. ## Main results * `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. * `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a monic polynomial of the same degree. * `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of `mapAlg`, where `mapAlg : R[X] →ₐ[R] S[X]` is the only `R`-algebra map that sends `X` to `X`. ## Implementation details In general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see `lifts_iff_lifts_ring`. Since we do not assume `R` to be commutative, we cannot say in general that the set of polynomials that lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.) -/ open Polynomial noncomputable section namespace Polynomial universe u v w section Semiring variable {R : Type u} [Semiring R] {S : Type v} [Semiring S] {f : R →+* S} /-- We define the subsemiring of polynomials that lifts as the image of `RingHom.of (map f)`. -/ def lifts (f : R →+* S) : Subsemiring S[X] := RingHom.rangeS (mapRingHom f) theorem mem_lifts (p : S[X]) : p ∈ lifts f ↔ ∃ q : R[X], map f q = p := by simp only [coe_mapRingHom, lifts, RingHom.mem_rangeS] theorem lifts_iff_set_range (p : S[X]) : p ∈ lifts f ↔ p ∈ Set.range (map f) := by simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS] theorem lifts_iff_ringHom_rangeS (p : S[X]) : p ∈ lifts f ↔ p ∈ (mapRingHom f).rangeS := by simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS] theorem lifts_iff_coeff_lifts (p : S[X]) : p ∈ lifts f ↔ ∀ n : ℕ, p.coeff n ∈ Set.range f := by rw [lifts_iff_ringHom_rangeS, mem_map_rangeS f] rfl theorem lifts_iff_coeffs_subset_range (p : S[X]) : p ∈ lifts f ↔ (p.coeffs : Set S) ⊆ Set.range f := by rw [lifts_iff_coeff_lifts] constructor · intro h _ hc obtain ⟨n, ⟨-, hn⟩⟩ := mem_coeffs_iff.mp hc exact hn ▸ h n · intro h n by_cases hn : p.coeff n = 0 · exact ⟨0, by simp [hn]⟩ · exact h <| coeff_mem_coeffs _ _ hn /-- If `(r : R)`, then `C (f r)` lifts. -/ theorem C_mem_lifts (f : R →+* S) (r : R) : C (f r) ∈ lifts f := ⟨C r, by simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, and_self_iff]⟩ /-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/ theorem C'_mem_lifts {f : R →+* S} {s : S} (h : s ∈ Set.range f) : C s ∈ lifts f := by obtain ⟨r, rfl⟩ := Set.mem_range.1 h use C r simp only [coe_mapRingHom, map_C, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, and_self_iff] /-- The polynomial `X` lifts. -/ theorem X_mem_lifts (f : R →+* S) : (X : S[X]) ∈ lifts f := ⟨X, by simp only [coe_mapRingHom, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, map_X, and_self_iff]⟩ /-- The polynomial `X ^ n` lifts. -/ theorem X_pow_mem_lifts (f : R →+* S) (n : ℕ) : (X ^ n : S[X]) ∈ lifts f := ⟨X ^ n, by simp only [coe_mapRingHom, map_pow, Set.mem_univ, Subsemiring.coe_top, eq_self_iff_true, map_X, and_self_iff]⟩ /-- If `p` lifts and `(r : R)` then `r * p` lifts. -/ theorem base_mul_mem_lifts {p : S[X]} (r : R) (hp : p ∈ lifts f) : C (f r) * p ∈ lifts f := by simp only [lifts, RingHom.mem_rangeS] at hp ⊢ obtain ⟨p₁, rfl⟩ := hp use C r * p₁ simp only [coe_mapRingHom, map_C, map_mul] /-- If `(s : S)` is in the image of `f`, then `monomial n s` lifts. -/ theorem monomial_mem_lifts {s : S} (n : ℕ) (h : s ∈ Set.range f) : monomial n s ∈ lifts f := by obtain ⟨r, rfl⟩ := Set.mem_range.1 h use monomial n r simp only [coe_mapRingHom, Set.mem_univ, map_monomial, Subsemiring.coe_top, eq_self_iff_true, and_self_iff] /-- If `p` lifts then `p.erase n` lifts. -/ theorem erase_mem_lifts {p : S[X]} (n : ℕ) (h : p ∈ lifts f) : p.erase n ∈ lifts f := by rw [lifts_iff_ringHom_rangeS, mem_map_rangeS] at h ⊢ intro k by_cases hk : k = n · use 0 simp only [hk, RingHom.map_zero, erase_same] obtain ⟨i, hi⟩ := h k use i simp only [hi, hk, erase_ne, Ne, not_false_iff] section LiftDeg theorem monomial_mem_lifts_and_degree_eq {s : S} {n : ℕ} (hl : monomial n s ∈ lifts f) : ∃ q : R[X], map f q = monomial n s ∧ q.degree = (monomial n s).degree := by rcases eq_or_ne s 0 with rfl | h · exact ⟨0, by simp⟩ obtain ⟨a, rfl⟩ := coeff_monomial_same n s ▸ (monomial n s).lifts_iff_coeff_lifts.mp hl n refine ⟨monomial n a, map_monomial f, ?_⟩ rw [degree_monomial, degree_monomial n h] exact mt (fun ha ↦ ha ▸ map_zero f) h /-- A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. -/ theorem mem_lifts_and_degree_eq {p : S[X]} (hlifts : p ∈ lifts f) : ∃ q : R[X], map f q = p ∧ q.degree = p.degree := by rw [lifts_iff_coeff_lifts] at hlifts let g : ℕ → R := fun k ↦ (hlifts k).choose have hg : ∀ k, f (g k) = p.coeff k := fun k ↦ (hlifts k).choose_spec let q : R[X] := ∑ k ∈ p.support, monomial k (g k) have hq : map f q = p := by simp_rw [q, Polynomial.map_sum, map_monomial, hg, ← as_sum_support] have hq' : q.support = p.support := by simp_rw [Finset.ext_iff, mem_support_iff, q, finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', ite_ne_right_iff, mem_support_iff, and_iff_left_iff_imp, not_imp_not] exact fun k h ↦ by rw [← hg, h, map_zero] exact ⟨q, hq, congrArg Finset.max hq'⟩ end LiftDeg section Monic /-- A monic polynomial lifts if and only if it can be lifted to a monic polynomial of the same degree. -/ theorem lifts_and_degree_eq_and_monic [Nontrivial S] {p : S[X]} (hlifts : p ∈ lifts f) (hp : p.Monic) : ∃ q : R[X], map f q = p ∧ q.degree = p.degree ∧ q.Monic := by rw [lifts_iff_coeff_lifts] at hlifts let g : ℕ → R := fun k ↦ (hlifts k).choose have hg k : f (g k) = p.coeff k := (hlifts k).choose_spec let q : R[X] := X ^ p.natDegree + ∑ k ∈ Finset.range p.natDegree, C (g k) * X ^ k have hq : map f q = p := by simp_rw [q, Polynomial.map_add, Polynomial.map_sum, Polynomial.map_mul, Polynomial.map_pow, map_X, map_C, hg, ← hp.as_sum] have h : q.Monic := monic_X_pow_add (by simp_rw [← Fin.sum_univ_eq_sum_range, degree_sum_fin_lt]) exact ⟨q, hq, hq ▸ (h.degree_map f).symm, h⟩ theorem lifts_and_natDegree_eq_and_monic {p : S[X]} (hlifts : p ∈ lifts f) (hp : p.Monic) : ∃ q : R[X], map f q = p ∧ q.natDegree = p.natDegree ∧ q.Monic := by rcases subsingleton_or_nontrivial S with hR | hR · obtain rfl : p = 1 := Subsingleton.elim _ _ exact ⟨1, Subsingleton.elim _ _, by simp, by simp⟩ obtain ⟨p', h₁, h₂, h₃⟩ := lifts_and_degree_eq_and_monic hlifts hp exact ⟨p', h₁, natDegree_eq_of_degree_eq h₂, h₃⟩ end Monic end Semiring section Ring variable {R : Type u} [Ring R] {S : Type v} [Ring S] (f : R →+* S) /-- The subring of polynomials that lift. -/ def liftsRing (f : R →+* S) : Subring S[X] := RingHom.range (mapRingHom f) /-- If `R` and `S` are rings, `p` is in the subring of polynomials that lift if and only if it is in the subsemiring of polynomials that lift. -/ theorem lifts_iff_liftsRing (p : S[X]) : p ∈ lifts f ↔ p ∈ liftsRing f := by simp only [lifts, liftsRing, RingHom.mem_range, RingHom.mem_rangeS] end Ring section Algebra variable {R : Type u} [CommSemiring R] {S : Type v} [Semiring S] [Algebra R S] /-- The map `R[X] → S[X]` as an algebra homomorphism. -/ def mapAlg (R : Type u) [CommSemiring R] (S : Type v) [Semiring S] [Algebra R S] : R[X] →ₐ[R] S[X] := @aeval _ S[X] _ _ _ (X : S[X]) /-- `mapAlg` is the morphism induced by `R → S`. -/ theorem mapAlg_eq_map (p : R[X]) : mapAlg R S p = map (algebraMap R S) p := by simp only [mapAlg, aeval_def, eval₂_eq_sum, map, algebraMap_apply, RingHom.coe_comp] ext; congr /-- A polynomial `p` lifts if and only if it is in the image of `mapAlg`. -/ theorem mem_lifts_iff_mem_alg (R : Type u) [CommSemiring R] {S : Type v} [Semiring S] [Algebra R S] (p : S[X]) : p ∈ lifts (algebraMap R S) ↔ p ∈ AlgHom.range (@mapAlg R _ S _ _) := by simp only [coe_mapRingHom, lifts, mapAlg_eq_map, AlgHom.mem_range, RingHom.mem_rangeS] /-- If `p` lifts and `(r : R)` then `r • p` lifts. -/ theorem smul_mem_lifts {p : S[X]} (r : R) (hp : p ∈ lifts (algebraMap R S)) : r • p ∈ lifts (algebraMap R S) := by rw [mem_lifts_iff_mem_alg] at hp ⊢ exact Subalgebra.smul_mem (mapAlg R S).range hp r theorem monic_of_monic_mapAlg [FaithfulSMul R S] {p : Polynomial R} (hp : (mapAlg R S p).Monic) : p.Monic := monic_of_injective (FaithfulSMul.algebraMap_injective R S) hp
end Algebra end Polynomial
Mathlib/Algebra/Polynomial/Lifts.lean
233
239
/- Copyright (c) 2022 Abby J. Goldberg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Abby J. Goldberg, Mario Carneiro, Heather Macbeth -/ import Mathlib.Tactic.LinearCombination.Lemmas import Mathlib.Tactic.Positivity.Core import Mathlib.Tactic.Ring import Mathlib.Tactic.Ring.Compare /-! # linear_combination Tactic In this file, the `linear_combination` tactic is created. This tactic, which works over `CommRing`s, attempts to simplify the target by creating a linear combination of a list of equalities and subtracting it from the target. A `Syntax.Tactic` object can also be passed into the tactic, allowing the user to specify a normalization tactic. Over ordered algebraic objects (such as `LinearOrderedCommRing`), taking linear combinations of inequalities is also supported. ## Implementation Notes This tactic works by creating a weighted sum of the given equations with the given coefficients. Then, it subtracts the right side of the weighted sum from the left side so that the right side equals 0, and it does the same with the target. Afterwards, it sets the goal to be the equality between the lefthand side of the new goal and the lefthand side of the new weighted sum. Lastly, calls a normalization tactic on this target. ## References * <https://leanprover.zulipchat.com/#narrow/stream/239415-metaprogramming-.2F.20tactics/topic/Linear.20algebra.20tactic/near/213928196> -/ namespace Mathlib.Tactic.LinearCombination open Lean open Elab Meta Term Mathlib Ineq /-- Result of `expandLinearCombo`, either an equality/inequality proof or a value. -/ inductive Expanded /-- A proof of `a = b`, `a ≤ b`, or `a < b` (according to the value of `Ineq`). -/ | proof (rel : Ineq) (pf : Syntax.Term) /-- A value, equivalently a proof of `c = c`. -/ | const (c : Syntax.Term) /-- The handling in `linear_combination` of left- and right-multiplication and scalar-multiplication and of division all five proceed according to the same logic, specified here: given a proof `p` of an (in)equality and a constant `c`, * if `p` is a proof of an equation, multiply/divide through by `c`; * if `p` is a proof of a non-strict inequality, run `positivity` to find a proof that `c` is nonnegative, then multiply/divide through by `c`, invoking the nonnegativity of `c` where needed; * if `p` is a proof of a strict inequality, run `positivity` to find a proof that `c` is positive (if possible) or nonnegative (if not), then multiply/divide through by `c`, invoking the positivity or nonnegativity of `c` where needed. This generic logic takes as a parameter the object `lems`: the four lemmas corresponding to the four cases. -/ def rescale (lems : Ineq.WithStrictness → Name) (ty : Option Expr) (p c : Term) : Ineq → TermElabM Expanded | eq => do let i := mkIdent <| lems .eq .proof eq <$> ``($i $p $c) | le => do let i := mkIdent <| lems .le let e₂ ← withSynthesizeLight <| Term.elabTerm c ty let hc₂ ← Meta.Positivity.proveNonneg e₂ .proof le <$> ``($i $p $(← hc₂.toSyntax)) | lt => do let e₂ ← withSynthesizeLight <| Term.elabTerm c ty let (strict, hc₂) ← Meta.Positivity.bestResult e₂ let i := mkIdent <| lems (.lt strict) let p' : Term ← ``($i $p $(← hc₂.toSyntax)) if strict then pure (.proof lt p') else pure (.proof le p') /-- Performs macro expansion of a linear combination expression, using `+`/`-`/`*`/`/` on equations and values. * `.proof eq p` means that `p` is a syntax corresponding to a proof of an equation. For example, if `h : a = b` then `expandLinearCombo (2 * h)` returns `.proof (c_add_pf 2 h)` which is a proof of `2 * a = 2 * b`. Similarly, `.proof le p` means that `p` is a syntax corresponding to a proof of a non-strict inequality, and `.proof lt p` means that `p` is a syntax corresponding to a proof of a strict inequality. * `.const c` means that the input expression is not an equation but a value. -/ partial def expandLinearCombo (ty : Option Expr) (stx : Syntax.Term) : TermElabM Expanded := withRef stx do match stx with | `(($e)) => expandLinearCombo ty e | `($e₁ + $e₂) => do match ← expandLinearCombo ty e₁, ← expandLinearCombo ty e₂ with | .const c₁, .const c₂ => .const <$> ``($c₁ + $c₂) | .proof rel₁ p₁, .proof rel₂ p₂ => let i := mkIdent <| Ineq.addRelRelData rel₁ rel₂ .proof (max rel₁ rel₂) <$> ``($i $p₁ $p₂) | .proof rel p, .const c | .const c, .proof rel p => logWarningAt c "this constant has no effect on the linear combination; it can be dropped \ from the term" pure (.proof rel p) | `($e₁ - $e₂) => do match ← expandLinearCombo ty e₁, ← expandLinearCombo ty e₂ with | .const c₁, .const c₂ => .const <$> ``($c₁ - $c₂) | .proof rel p, .const c => logWarningAt c "this constant has no effect on the linear combination; it can be dropped \ from the term" pure (.proof rel p) | .const c, .proof eq p =>
logWarningAt c "this constant has no effect on the linear combination; it can be dropped \ from the term"
Mathlib/Tactic/LinearCombination.lean
111
112
/- Copyright (c) 2024 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.DirectSum.LinearMap import Mathlib.Algebra.Lie.Weights.Cartan import Mathlib.Data.Int.Interval import Mathlib.LinearAlgebra.Trace import Mathlib.RingTheory.Finiteness.Nilpotent /-! # Chains of roots and weights Given roots `α` and `β` of a Lie algebra, together with elements `x` in the `α`-root space and `y` in the `β`-root space, it follows from the Leibniz identity that `⁅x, y⁆` is either zero or belongs to the `α + β`-root space. Iterating this operation leads to the study of families of roots of the form `k • α + β`. Such a family is known as the `α`-chain through `β` (or sometimes, the `α`-string through `β`) and the study of the sum of the corresponding root spaces is an important technique. More generally if `α` is a root and `χ` is a weight of a representation, it is useful to study the `α`-chain through `χ`. We provide basic definitions and results to support `α`-chain techniques in this file. ## Main definitions / results * `LieModule.exists₂_genWeightSpace_smul_add_eq_bot`: given weights `χ₁`, `χ₂` if `χ₁ ≠ 0`, we can find `p < 0` and `q > 0` such that the weight spaces `p • χ₁ + χ₂` and `q • χ₁ + χ₂` are both trivial. * `LieModule.genWeightSpaceChain`: given weights `χ₁`, `χ₂` together with integers `p` and `q`, this is the sum of the weight spaces `k • χ₁ + χ₂` for `p < k < q`. * `LieModule.trace_toEnd_genWeightSpaceChain_eq_zero`: given a root `α` relative to a Cartan subalgebra `H`, there is a natural ideal `corootSpace α` in `H`. This lemma states that this ideal acts by trace-zero endomorphisms on the sum of root spaces of any `α`-chain, provided the weight spaces at the endpoints are both trivial. * `LieModule.exists_forall_mem_corootSpace_smul_add_eq_zero`: given a (potential) root `α` relative to a Cartan subalgebra `H`, if we restrict to the ideal `corootSpace α` of `H`, we may find an integral linear combination between `α` and any weight `χ` of a representation. ## TODO It should be possible to unify some of the definitions here such as `LieModule.chainBotCoeff`, `LieModule.chainTopCoeff` with corresponding definitions such as `RootPairing.chainBotCoeff`, `RootPairing.chainTopCoeff`. This is not quite trivial since: * The definitions here allow for chains in representations of Lie algebras. * The proof that the roots of a Lie algebra are a root system currently depends on these results. (This can be resolved by proving the root reflection formula using the approach outlined in Bourbaki Ch. VIII §2.2 Lemma 1 (page 80 of English translation, 88 of English PDF).) -/ open Module Function Set variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieModule section IsNilpotent variable [LieRing.IsNilpotent L] (χ₁ χ₂ : L → R) (p q : ℤ) section variable [NoZeroSMulDivisors ℤ R] [NoZeroSMulDivisors R M] [IsNoetherian R M] (hχ₁ : χ₁ ≠ 0) include hχ₁ lemma eventually_genWeightSpace_smul_add_eq_bot : ∀ᶠ (k : ℕ) in Filter.atTop, genWeightSpace M (k • χ₁ + χ₂) = ⊥ := by let f : ℕ → L → R := fun k ↦ k • χ₁ + χ₂ suffices Injective f by rw [← Nat.cofinite_eq_atTop, Filter.eventually_cofinite, ← finite_image_iff this.injOn] apply (finite_genWeightSpace_ne_bot R L M).subset simp [f] intro k l hkl replace hkl : (k : ℤ) • χ₁ = (l : ℤ) • χ₁ := by simpa only [f, add_left_inj, natCast_zsmul] using hkl exact Nat.cast_inj.mp <| smul_left_injective ℤ hχ₁ hkl lemma exists_genWeightSpace_smul_add_eq_bot : ∃ k > 0, genWeightSpace M (k • χ₁ + χ₂) = ⊥ := (Nat.eventually_pos.and <| eventually_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁).exists lemma exists₂_genWeightSpace_smul_add_eq_bot : ∃ᵉ (p < (0 : ℤ)) (q > (0 : ℤ)), genWeightSpace M (p • χ₁ + χ₂) = ⊥ ∧ genWeightSpace M (q • χ₁ + χ₂) = ⊥ := by obtain ⟨q, hq₀, hq⟩ := exists_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁ obtain ⟨p, hp₀, hp⟩ := exists_genWeightSpace_smul_add_eq_bot M (-χ₁) χ₂ (neg_ne_zero.mpr hχ₁) refine ⟨-(p : ℤ), by simpa, q, by simpa, ?_, ?_⟩ · rw [neg_smul, ← smul_neg, natCast_zsmul] exact hp · rw [natCast_zsmul] exact hq end /-- Given two (potential) weights `χ₁` and `χ₂` together with integers `p` and `q`, it is often useful to study the sum of weight spaces associated to the family of weights `k • χ₁ + χ₂` for `p < k < q`. -/ def genWeightSpaceChain : LieSubmodule R L M := ⨆ k ∈ Ioo p q, genWeightSpace M (k • χ₁ + χ₂) lemma genWeightSpaceChain_def : genWeightSpaceChain M χ₁ χ₂ p q = ⨆ k ∈ Ioo p q, genWeightSpace M (k • χ₁ + χ₂) := rfl lemma genWeightSpaceChain_def' : genWeightSpaceChain M χ₁ χ₂ p q = ⨆ k ∈ Finset.Ioo p q, genWeightSpace M (k • χ₁ + χ₂) := by have : ∀ (k : ℤ), k ∈ Ioo p q ↔ k ∈ Finset.Ioo p q := by simp simp_rw [genWeightSpaceChain_def, this] @[simp] lemma genWeightSpaceChain_neg : genWeightSpaceChain M (-χ₁) χ₂ (-q) (-p) = genWeightSpaceChain M χ₁ χ₂ p q := by let e : ℤ ≃ ℤ := neg_involutive.toPerm simp_rw [genWeightSpaceChain, ← e.biSup_comp (Ioo p q)] simp [e, -mem_Ioo, neg_mem_Ioo_iff] lemma genWeightSpace_le_genWeightSpaceChain {k : ℤ} (hk : k ∈ Ioo p q) : genWeightSpace M (k • χ₁ + χ₂) ≤ genWeightSpaceChain M χ₁ χ₂ p q := le_biSup (fun i ↦ genWeightSpace M (i • χ₁ + χ₂)) hk end IsNilpotent section LieSubalgebra open LieAlgebra variable {H : LieSubalgebra R L} (α χ : H → R) (p q : ℤ) lemma lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right [LieRing.IsNilpotent H] (hq : genWeightSpace M (q • α + χ) = ⊥) {x : L} (hx : x ∈ rootSpace H α) {y : M} (hy : y ∈ genWeightSpaceChain M α χ p q) : ⁅x, y⁆ ∈ genWeightSpaceChain M α χ p q := by rw [genWeightSpaceChain, iSup_subtype'] at hy induction hy using LieSubmodule.iSup_induction' with | mem k z hz => obtain ⟨k, hk⟩ := k suffices genWeightSpace M ((k + 1) • α + χ) ≤ genWeightSpaceChain M α χ p q by apply this -- was `simpa using [...]` and very slow -- (https://github.com/leanprover-community/mathlib4/issues/19751) simpa only [zsmul_eq_mul, Int.cast_add, Pi.intCast_def, Int.cast_one] using (rootSpaceWeightSpaceProduct R L H M α (k • α + χ) ((k + 1) • α + χ) (by rw [add_smul]; abel) (⟨x, hx⟩ ⊗ₜ ⟨z, hz⟩)).property rw [genWeightSpaceChain] rcases eq_or_ne (k + 1) q with rfl | hk'; · simp only [hq, bot_le] replace hk' : k + 1 ∈ Ioo p q := ⟨by linarith [hk.1], lt_of_le_of_ne hk.2 hk'⟩ exact le_biSup (fun k ↦ genWeightSpace M (k • α + χ)) hk' | zero => simp | add _ _ _ _ hz₁ hz₂ => rw [lie_add]; exact add_mem hz₁ hz₂ lemma lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_left [LieRing.IsNilpotent H] (hp : genWeightSpace M (p • α + χ) = ⊥) {x : L} (hx : x ∈ rootSpace H (-α)) {y : M} (hy : y ∈ genWeightSpaceChain M α χ p q) : ⁅x, y⁆ ∈ genWeightSpaceChain M α χ p q := by replace hp : genWeightSpace M ((-p) • (-α) + χ) = ⊥ := by rwa [smul_neg, neg_smul, neg_neg] rw [← genWeightSpaceChain_neg] at hy ⊢ exact lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right M (-α) χ (-q) (-p) hp hx hy section IsCartanSubalgebra variable [H.IsCartanSubalgebra] [IsNoetherian R L] lemma trace_toEnd_genWeightSpaceChain_eq_zero (hp : genWeightSpace M (p • α + χ) = ⊥) (hq : genWeightSpace M (q • α + χ) = ⊥) {x : H} (hx : x ∈ corootSpace α) : LinearMap.trace R _ (toEnd R H (genWeightSpaceChain M α χ p q) x) = 0 := by rw [LieAlgebra.mem_corootSpace'] at hx induction hx using Submodule.span_induction · next u hu => obtain ⟨y, hy, z, hz, hyz⟩ := hu let f : Module.End R (genWeightSpaceChain M α χ p q) := { toFun := fun ⟨m, hm⟩ ↦ ⟨⁅(y : L), m⁆, lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_right M α χ p q hq hy hm⟩ map_add' := fun _ _ ↦ by simp map_smul' := fun t m ↦ by simp } let g : Module.End R (genWeightSpaceChain M α χ p q) := { toFun := fun ⟨m, hm⟩ ↦ ⟨⁅(z : L), m⁆, lie_mem_genWeightSpaceChain_of_genWeightSpace_eq_bot_left M α χ p q hp hz hm⟩ map_add' := fun _ _ ↦ by simp map_smul' := fun t m ↦ by simp } have hfg : toEnd R H _ u = ⁅f, g⁆ := by ext rw [toEnd_apply_apply, LieSubmodule.coe_bracket, LieSubalgebra.coe_bracket_of_module, ← hyz] simp only [lie_lie, LieHom.lie_apply, LinearMap.coe_mk, AddHom.coe_mk, Module.End.lie_apply, AddSubgroupClass.coe_sub, f, g] simp [hfg] · simp · simp_all · simp_all /-- Given a (potential) root `α` relative to a Cartan subalgebra `H`, if we restrict to the ideal `I = corootSpace α` of `H` (informally, `I = ⁅H(α), H(-α)⁆`), we may find an integral linear combination between `α` and any weight `χ` of a representation. This is Proposition 4.4 from [carter2005] and is a key step in the proof that the roots of a semisimple Lie algebra form a root system. It shows that the restriction of `α` to `I` vanishes iff the restriction of every root to `I` vanishes (which cannot happen in a semisimple Lie algebra). -/ lemma exists_forall_mem_corootSpace_smul_add_eq_zero [IsDomain R] [IsPrincipalIdealRing R] [CharZero R] [NoZeroSMulDivisors R M] [IsNoetherian R M] (hα : α ≠ 0) (hχ : genWeightSpace M χ ≠ ⊥) : ∃ a b : ℤ, 0 < b ∧ ∀ x ∈ corootSpace α, (a • α + b • χ) x = 0 := by obtain ⟨p, hp₀, q, hq₀, hp, hq⟩ := exists₂_genWeightSpace_smul_add_eq_bot M α χ hα let a := ∑ i ∈ Finset.Ioo p q, finrank R (genWeightSpace M (i • α + χ)) • i let b := ∑ i ∈ Finset.Ioo p q, finrank R (genWeightSpace M (i • α + χ)) have hb : 0 < b := by replace hχ : Nontrivial (genWeightSpace M χ) := by rwa [LieSubmodule.nontrivial_iff_ne_bot] refine Finset.sum_pos' (fun _ _ ↦ zero_le _) ⟨0, Finset.mem_Ioo.mpr ⟨hp₀, hq₀⟩, ?_⟩ rw [zero_smul, zero_add] exact finrank_pos refine ⟨a, b, Int.ofNat_pos.mpr hb, fun x hx ↦ ?_⟩ let N : ℤ → Submodule R M := fun k ↦ genWeightSpace M (k • α + χ) have h₁ : iSupIndep fun (i : Finset.Ioo p q) ↦ N i := by rw [LieSubmodule.iSupIndep_toSubmodule] refine (iSupIndep_genWeightSpace R H M).comp fun i j hij ↦ ?_ exact SetCoe.ext <| smul_left_injective ℤ hα <| by rwa [add_left_inj] at hij have h₂ : ∀ i, MapsTo (toEnd R H M x) ↑(N i) ↑(N i) := fun _ _ ↦ LieSubmodule.lie_mem _ have h₃ : genWeightSpaceChain M α χ p q = ⨆ i ∈ Finset.Ioo p q, N i := by simp_rw [N, genWeightSpaceChain_def', LieSubmodule.iSup_toSubmodule] rw [← trace_toEnd_genWeightSpaceChain_eq_zero M α χ p q hp hq hx, ← LieSubmodule.toEnd_restrict_eq_toEnd] -- The lines below illustrate the cost of treating `LieSubmodule` as both a -- `Submodule` and a `LieSubmodule` simultaneously. erw [LinearMap.trace_eq_sum_trace_restrict_of_eq_biSup _ h₁ h₂ (genWeightSpaceChain M α χ p q) h₃] simp_rw [N, LieSubmodule.toEnd_restrict_eq_toEnd] dsimp [N] convert_to _ = ∑ k ∈ Finset.Ioo p q, (LinearMap.trace R { x // x ∈ (genWeightSpace M (k • α + χ)) }) ((toEnd R { x // x ∈ H } { x // x ∈ genWeightSpace M (k • α + χ) }) x) simp_rw [a, b, trace_toEnd_genWeightSpace, Pi.add_apply, Pi.smul_apply, smul_add, ← smul_assoc, Finset.sum_add_distrib, ← Finset.sum_smul, natCast_zsmul] end IsCartanSubalgebra end LieSubalgebra section variable {M} variable [LieRing.IsNilpotent L] variable [NoZeroSMulDivisors ℤ R] [NoZeroSMulDivisors R M] [IsNoetherian R M] variable (α : L → R) (β : Weight R L M) /-- This is the largest `n : ℕ` such that `i • α + β` is a weight for all `0 ≤ i ≤ n`. -/ noncomputable def chainTopCoeff : ℕ := letI := Classical.propDecidable if hα : α = 0 then 0 else Nat.pred <| Nat.find (show ∃ n, genWeightSpace M (n • α + β : L → R) = ⊥ from (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists) /-- This is the largest `n : ℕ` such that `-i • α + β` is a weight for all `0 ≤ i ≤ n`. -/ noncomputable def chainBotCoeff : ℕ := chainTopCoeff (-α) β @[simp] lemma chainTopCoeff_neg : chainTopCoeff (-α) β = chainBotCoeff α β := rfl @[simp] lemma chainBotCoeff_neg : chainBotCoeff (-α) β = chainTopCoeff α β := by rw [← chainTopCoeff_neg, neg_neg] @[simp] lemma chainTopCoeff_zero : chainTopCoeff 0 β = 0 := dif_pos rfl @[simp] lemma chainBotCoeff_zero : chainBotCoeff 0 β = 0 := dif_pos neg_zero section variable (hα : α ≠ 0) include hα lemma chainTopCoeff_add_one : letI := Classical.propDecidable chainTopCoeff α β + 1 = Nat.find (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists := by classical rw [chainTopCoeff, dif_neg hα] apply Nat.succ_pred_eq_of_pos rw [zero_lt_iff] intro e have : genWeightSpace M (0 • α + β : L → R) = ⊥ := by rw [← e] exact Nat.find_spec (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists exact β.genWeightSpace_ne_bot _ (by simpa only [zero_smul, zero_add] using this) lemma genWeightSpace_chainTopCoeff_add_one_nsmul_add : genWeightSpace M ((chainTopCoeff α β + 1) • α + β : L → R) = ⊥ := by classical rw [chainTopCoeff_add_one _ _ hα] exact Nat.find_spec (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists lemma genWeightSpace_chainTopCoeff_add_one_zsmul_add : genWeightSpace M ((chainTopCoeff α β + 1 : ℤ) • α + β : L → R) = ⊥ := by rw [← genWeightSpace_chainTopCoeff_add_one_nsmul_add α β hα, ← Nat.cast_smul_eq_nsmul ℤ, Nat.cast_add, Nat.cast_one] lemma genWeightSpace_chainBotCoeff_sub_one_zsmul_sub : genWeightSpace M ((-chainBotCoeff α β - 1 : ℤ) • α + β : L → R) = ⊥ := by rw [sub_eq_add_neg, ← neg_add, neg_smul, ← smul_neg, chainBotCoeff, genWeightSpace_chainTopCoeff_add_one_zsmul_add _ _ (by simpa using hα)] end lemma genWeightSpace_nsmul_add_ne_bot_of_le {n} (hn : n ≤ chainTopCoeff α β) : genWeightSpace M (n • α + β : L → R) ≠ ⊥ := by by_cases hα : α = 0 · rw [hα, smul_zero, zero_add]; exact β.genWeightSpace_ne_bot classical rw [← Nat.lt_succ, Nat.succ_eq_add_one, chainTopCoeff_add_one _ _ hα] at hn exact Nat.find_min (eventually_genWeightSpace_smul_add_eq_bot M α β hα).exists hn
lemma genWeightSpace_zsmul_add_ne_bot {n : ℤ}
Mathlib/Algebra/Lie/Weights/Chain.lean
315
315
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Algebra.Lie.Quotient /-! # The normalizer of Lie submodules and subalgebras. Given a Lie module `M` over a Lie subalgebra `L`, the normalizer of a Lie submodule `N ⊆ M` is the Lie submodule with underlying set `{ m | ∀ (x : L), ⁅x, m⁆ ∈ N }`. The lattice of Lie submodules thus has two natural operations, the normalizer: `N ↦ N.normalizer` and the ideal operation: `N ↦ ⁅⊤, N⁆`; these are adjoint, i.e., they form a Galois connection. This adjointness is the reason that we may define nilpotency in terms of either the upper or lower central series. Given a Lie subalgebra `H ⊆ L`, we may regard `H` as a Lie submodule of `L` over `H`, and thus consider the normalizer. This turns out to be a Lie subalgebra. ## Main definitions * `LieSubmodule.normalizer` * `LieSubalgebra.normalizer` * `LieSubmodule.gc_top_lie_normalizer` ## Tags lie algebra, normalizer -/ variable {R L M M' : Type*} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] [LieModule R L M'] namespace LieSubmodule variable (N : LieSubmodule R L M) {N₁ N₂ : LieSubmodule R L M} /-- The normalizer of a Lie submodule. See also `LieSubmodule.idealizer`. -/ def normalizer : LieSubmodule R L M where carrier := {m | ∀ x : L, ⁅x, m⁆ ∈ N} add_mem' hm₁ hm₂ x := by rw [lie_add]; exact N.add_mem' (hm₁ x) (hm₂ x) zero_mem' x := by simp smul_mem' t m hm x := by rw [lie_smul]; exact N.smul_mem' t (hm x) lie_mem {x m} hm y := by rw [leibniz_lie]; exact N.add_mem' (hm ⁅y, x⁆) (N.lie_mem (hm y)) @[simp] theorem mem_normalizer (m : M) : m ∈ N.normalizer ↔ ∀ x : L, ⁅x, m⁆ ∈ N := Iff.rfl @[simp] theorem le_normalizer : N ≤ N.normalizer := by intro m hm rw [mem_normalizer] exact fun x => N.lie_mem hm theorem normalizer_inf : (N₁ ⊓ N₂).normalizer = N₁.normalizer ⊓ N₂.normalizer := by ext; simp [← forall_and] @[gcongr, mono] theorem normalizer_mono (h : N₁ ≤ N₂) : normalizer N₁ ≤ normalizer N₂ := by intro m hm rw [mem_normalizer] at hm ⊢ exact fun x ↦ h (hm x) theorem monotone_normalizer : Monotone (normalizer : LieSubmodule R L M → LieSubmodule R L M) := fun _ _ ↦ normalizer_mono @[simp] theorem comap_normalizer (f : M' →ₗ⁅R,L⁆ M) : N.normalizer.comap f = (N.comap f).normalizer := by ext; simp theorem top_lie_le_iff_le_normalizer (N' : LieSubmodule R L M) : ⁅(⊤ : LieIdeal R L), N⁆ ≤ N' ↔ N ≤ N'.normalizer := by rw [lie_le_iff]; tauto theorem gc_top_lie_normalizer : GaloisConnection (fun N : LieSubmodule R L M => ⁅(⊤ : LieIdeal R L), N⁆) normalizer := top_lie_le_iff_le_normalizer variable (R L M) in
theorem normalizer_bot_eq_maxTrivSubmodule : (⊥ : LieSubmodule R L M).normalizer = LieModule.maxTrivSubmodule R L M :=
Mathlib/Algebra/Lie/Normalizer.lean
89
90
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Geometry.Manifold.VectorBundle.Basic /-! # Tangent bundles This file defines the tangent bundle as a `C^n` vector bundle. Let `M` be a manifold with model `I` on `(E, H)`. The tangent space `TangentSpace I (x : M)` has already been defined as a type synonym for `E`, and the tangent bundle `TangentBundle I M` as an abbrev of `Bundle.TotalSpace E (TangentSpace I : M → Type _)`. In this file, when `M` is `C^1`, we construct a vector bundle structure on `TangentBundle I M` using the `VectorBundleCore` construction indexed by the charts of `M` with fibers `E`. Given two charts `i, j : PartialHomeomorph M H`, the coordinate change between `i` and `j` at a point `x : M` is the derivative of the composite ``` I.symm i.symm j I E -----> H -----> M --> H --> E ``` within the set `range I ⊆ E` at `I (i x) : E`. This defines a vector bundle `TangentBundle` with fibers `TangentSpace`. ## Main definitions and results * `tangentBundleCore I M` is the vector bundle core for the tangent bundle over `M`. * When `M` is a `C^{n+1}` manifold, `TangentBundle I M` has a `C^n` vector bundle structure over `M`. In particular, it is a topological space, a vector bundle, a fiber bundle, and a `C^n` manifold. -/ open Bundle Set IsManifold PartialHomeomorph ContinuousLinearMap open scoped Manifold Topology Bundle ContDiff noncomputable section section General variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞} {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] /-- Auxiliary lemma for tangent spaces: the derivative of a coordinate change between two charts is `C^n` on its source. -/ theorem contDiffOn_fderiv_coord_change [IsManifold I (n + 1) M] (i j : atlas H M) : ContDiffOn 𝕜 n (fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I)) ((i.1.extend I).symm ≫ j.1.extend I).source := by have h : ((i.1.extend I).symm ≫ j.1.extend I).source ⊆ range I := by rw [i.1.extend_coord_change_source]; apply image_subset_range intro x hx refine (ContDiffWithinAt.fderivWithin_right ?_ I.uniqueDiffOn le_rfl <| h hx).mono h refine (PartialHomeomorph.contDiffOn_extend_coord_change (subset_maximalAtlas j.2) (subset_maximalAtlas i.2) x hx).mono_of_mem_nhdsWithin ?_ exact i.1.extend_coord_change_source_mem_nhdsWithin j.1 hx open IsManifold variable [IsManifold I 1 M] [IsManifold I' 1 M'] variable (I M) in /-- Let `M` be a `C^1` manifold with model `I` on `(E, H)`. Then `tangentBundleCore I M` is the vector bundle core for the tangent bundle over `M`. It is indexed by the atlas of `M`, with fiber `E` and its change of coordinates from the chart `i` to the chart `j` at point `x : M` is the derivative of the composite ``` I.symm i.symm j I E -----> H -----> M --> H --> E ``` within the set `range I ⊆ E` at `I (i x) : E`. -/ @[simps indexAt coordChange] def tangentBundleCore : VectorBundleCore 𝕜 M E (atlas H M) where baseSet i := i.1.source isOpen_baseSet i := i.1.open_source indexAt := achart H mem_baseSet_at := mem_chart_source H coordChange i j x := fderivWithin 𝕜 (j.1.extend I ∘ (i.1.extend I).symm) (range I) (i.1.extend I x) coordChange_self i x hx v := by rw [Filter.EventuallyEq.fderivWithin_eq, fderivWithin_id', ContinuousLinearMap.id_apply] · exact I.uniqueDiffWithinAt_image · filter_upwards [i.1.extend_target_mem_nhdsWithin hx] with y hy exact (i.1.extend I).right_inv hy · simp_rw [Function.comp_apply, i.1.extend_left_inv hx] continuousOn_coordChange i j := by have : IsManifold I (0 + 1) M := by simp; infer_instance refine (contDiffOn_fderiv_coord_change (n := 0) i j).continuousOn.comp (i.1.continuousOn_extend.mono ?_) ?_ · rw [i.1.extend_source]; exact inter_subset_left simp_rw [← i.1.extend_image_source_inter, mapsTo_image] coordChange_comp := by have : IsManifold I (0 + 1) M := by simp; infer_instance rintro i j k x ⟨⟨hxi, hxj⟩, hxk⟩ v rw [fderivWithin_fderivWithin, Filter.EventuallyEq.fderivWithin_eq] · have := i.1.extend_preimage_mem_nhds (I := I) hxi (j.1.extend_source_mem_nhds (I := I) hxj) filter_upwards [nhdsWithin_le_nhds this] with y hy simp_rw [Function.comp_apply, (j.1.extend I).left_inv hy] · simp_rw [Function.comp_apply, i.1.extend_left_inv hxi, j.1.extend_left_inv hxj] · exact (contDiffWithinAt_extend_coord_change' (subset_maximalAtlas k.2) (subset_maximalAtlas j.2) hxk hxj).differentiableWithinAt le_rfl · exact (contDiffWithinAt_extend_coord_change' (subset_maximalAtlas j.2) (subset_maximalAtlas i.2) hxj hxi).differentiableWithinAt le_rfl · intro x _; exact mem_range_self _ · exact I.uniqueDiffWithinAt_image · rw [Function.comp_apply, i.1.extend_left_inv hxi] -- Porting note: moved to a separate `simp high` lemma b/c `simp` can simplify the LHS @[simp high] theorem tangentBundleCore_baseSet (i) : (tangentBundleCore I M).baseSet i = i.1.source := rfl theorem tangentBundleCore_coordChange_achart (x x' z : M) : (tangentBundleCore I M).coordChange (achart H x) (achart H x') z = fderivWithin 𝕜 (extChartAt I x' ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl section tangentCoordChange variable (I) in /-- In a manifold `M`, given two preferred charts indexed by `x y : M`, `tangentCoordChange I x y` is the family of derivatives of the corresponding change-of-coordinates map. It takes junk values outside the intersection of the sources of the two charts. Note that this definition takes advantage of the fact that `tangentBundleCore` has the same base sets as the preferred charts of the base manifold. -/ abbrev tangentCoordChange (x y : M) : M → E →L[𝕜] E := (tangentBundleCore I M).coordChange (achart H x) (achart H y) lemma tangentCoordChange_def {x y z : M} : tangentCoordChange I x y z = fderivWithin 𝕜 (extChartAt I y ∘ (extChartAt I x).symm) (range I) (extChartAt I x z) := rfl lemma tangentCoordChange_self {x z : M} {v : E} (h : z ∈ (extChartAt I x).source) : tangentCoordChange I x x z v = v := by apply (tangentBundleCore I M).coordChange_self rw [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] exact h lemma tangentCoordChange_comp {w x y z : M} {v : E} (h : z ∈ (extChartAt I w).source ∩ (extChartAt I x).source ∩ (extChartAt I y).source) : tangentCoordChange I x y z (tangentCoordChange I w x z v) = tangentCoordChange I w y z v := by apply (tangentBundleCore I M).coordChange_comp simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] exact h lemma hasFDerivWithinAt_tangentCoordChange {x y z : M} (h : z ∈ (extChartAt I x).source ∩ (extChartAt I y).source) : HasFDerivWithinAt ((extChartAt I y) ∘ (extChartAt I x).symm) (tangentCoordChange I x y z) (range I) (extChartAt I x z) := have h' : extChartAt I x z ∈ ((extChartAt I x).symm ≫ (extChartAt I y)).source := by rw [PartialEquiv.trans_source'', PartialEquiv.symm_symm, PartialEquiv.symm_target] exact mem_image_of_mem _ h ((contDiffWithinAt_ext_coord_change y x h').differentiableWithinAt le_rfl).hasFDerivWithinAt lemma continuousOn_tangentCoordChange (x y : M) : ContinuousOn (tangentCoordChange I x y) ((extChartAt I x).source ∩ (extChartAt I y).source) := by convert (tangentBundleCore I M).continuousOn_coordChange (achart H x) (achart H y) <;> simp only [tangentBundleCore_baseSet, coe_achart, ← extChartAt_source I] end tangentCoordChange local notation "TM" => TangentBundle I M section TangentBundleInstances instance : TopologicalSpace TM := (tangentBundleCore I M).toTopologicalSpace instance TangentSpace.fiberBundle : FiberBundle E (TangentSpace I : M → Type _) := (tangentBundleCore I M).fiberBundle instance TangentSpace.vectorBundle : VectorBundle 𝕜 E (TangentSpace I : M → Type _) := (tangentBundleCore I M).vectorBundle namespace TangentBundle protected theorem chartAt (p : TM) : chartAt (ModelProd H E) p = ((tangentBundleCore I M).toFiberBundleCore.localTriv (achart H p.1)).toPartialHomeomorph ≫ₕ (chartAt H p.1).prod (PartialHomeomorph.refl E) := rfl theorem chartAt_toPartialEquiv (p : TM) : (chartAt (ModelProd H E) p).toPartialEquiv = (tangentBundleCore I M).toFiberBundleCore.localTrivAsPartialEquiv (achart H p.1) ≫ (chartAt H p.1).toPartialEquiv.prod (PartialEquiv.refl E) := rfl theorem trivializationAt_eq_localTriv (x : M) : trivializationAt E (TangentSpace I) x = (tangentBundleCore I M).toFiberBundleCore.localTriv (achart H x) := rfl @[simp, mfld_simps] theorem trivializationAt_source (x : M) : (trivializationAt E (TangentSpace I) x).source = π E (TangentSpace I) ⁻¹' (chartAt H x).source := rfl @[simp, mfld_simps] theorem trivializationAt_target (x : M) : (trivializationAt E (TangentSpace I) x).target = (chartAt H x).source ×ˢ univ := rfl @[simp, mfld_simps] theorem trivializationAt_baseSet (x : M) : (trivializationAt E (TangentSpace I) x).baseSet = (chartAt H x).source := rfl theorem trivializationAt_apply (x : M) (z : TM) : trivializationAt E (TangentSpace I) x z = (z.1, fderivWithin 𝕜 ((chartAt H x).extend I ∘ ((chartAt H z.1).extend I).symm) (range I) ((chartAt H z.1).extend I z.1) z.2) := rfl @[simp, mfld_simps] theorem trivializationAt_fst (x : M) (z : TM) : (trivializationAt E (TangentSpace I) x z).1 = z.1 := rfl @[simp, mfld_simps] theorem mem_chart_source_iff (p q : TM) : p ∈ (chartAt (ModelProd H E) q).source ↔ p.1 ∈ (chartAt H q.1).source := by simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] @[simp, mfld_simps] theorem mem_chart_target_iff (p : H × E) (q : TM) : p ∈ (chartAt (ModelProd H E) q).target ↔ p.1 ∈ (chartAt H q.1).target := by /- porting note: was simp +contextual only [FiberBundle.chartedSpace_chartAt, and_iff_left_iff_imp, mfld_simps] -/ simp only [FiberBundle.chartedSpace_chartAt, mfld_simps] rw [PartialEquiv.prod_symm] simp +contextual only [and_iff_left_iff_imp, mfld_simps] @[simp, mfld_simps] theorem coe_chartAt_fst (p q : TM) : ((chartAt (ModelProd H E) q) p).1 = chartAt H q.1 p.1 := rfl @[simp, mfld_simps] theorem coe_chartAt_symm_fst (p : H × E) (q : TM) : ((chartAt (ModelProd H E) q).symm p).1 = ((chartAt H q.1).symm : H → M) p.1 := rfl @[simp, mfld_simps] theorem trivializationAt_continuousLinearMapAt {b₀ b : M} (hb : b ∈ (trivializationAt E (TangentSpace I) b₀).baseSet) : (trivializationAt E (TangentSpace I) b₀).continuousLinearMapAt 𝕜 b = (tangentBundleCore I M).coordChange (achart H b) (achart H b₀) b := (tangentBundleCore I M).localTriv_continuousLinearMapAt hb @[simp, mfld_simps] theorem trivializationAt_symmL {b₀ b : M} (hb : b ∈ (trivializationAt E (TangentSpace I) b₀).baseSet) : (trivializationAt E (TangentSpace I) b₀).symmL 𝕜 b = (tangentBundleCore I M).coordChange (achart H b₀) (achart H b) b := (tangentBundleCore I M).localTriv_symmL hb -- Porting note: `simp` simplifies LHS to `.id _ _` @[simp high, mfld_simps] theorem coordChange_model_space (b b' x : F) : (tangentBundleCore 𝓘(𝕜, F) F).coordChange (achart F b) (achart F b') x = 1 := by simpa only [tangentBundleCore_coordChange, mfld_simps] using fderivWithin_id uniqueDiffWithinAt_univ -- Porting note: `simp` simplifies LHS to `.id _ _` @[simp high, mfld_simps] theorem symmL_model_space (b b' : F) : (trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).symmL 𝕜 b' = (1 : F →L[𝕜] F) := by rw [TangentBundle.trivializationAt_symmL, coordChange_model_space] apply mem_univ -- Porting note: `simp` simplifies LHS to `.id _ _` @[simp high, mfld_simps] theorem continuousLinearMapAt_model_space (b b' : F) : (trivializationAt F (TangentSpace 𝓘(𝕜, F)) b).continuousLinearMapAt 𝕜 b' = (1 : F →L[𝕜] F) := by rw [TangentBundle.trivializationAt_continuousLinearMapAt, coordChange_model_space] apply mem_univ end TangentBundle omit [IsManifold I 1 M] in lemma tangentBundleCore.isContMDiff [h : IsManifold I (n + 1) M] : haveI : IsManifold I 1 M := .of_le (n := n + 1) le_add_self (tangentBundleCore I M).IsContMDiff I n := by have : IsManifold I n M := .of_le (n := n + 1) (le_self_add) refine ⟨fun i j => ?_⟩ rw [contMDiffOn_iff_source_of_mem_maximalAtlas (subset_maximalAtlas i.2), contMDiffOn_iff_contDiffOn] · refine ((contDiffOn_fderiv_coord_change (I := I) i j).congr fun x hx => ?_).mono ?_ · rw [PartialEquiv.trans_source'] at hx simp_rw [Function.comp_apply, tangentBundleCore_coordChange, (i.1.extend I).right_inv hx.1] · exact (i.1.extend_image_source_inter j.1).subset · apply inter_subset_left @[deprecated (since := "2025-01-09")] alias tangentBundleCore.isSmooth := tangentBundleCore.isContMDiff omit [IsManifold I 1 M] in lemma TangentBundle.contMDiffVectorBundle [h : IsManifold I (n + 1) M] : haveI : IsManifold I 1 M := .of_le (n := n + 1) le_add_self ContMDiffVectorBundle n E (TangentSpace I : M → Type _) I := by have : IsManifold I 1 M := .of_le (n := n + 1) le_add_self have : (tangentBundleCore I M).IsContMDiff I n := tangentBundleCore.isContMDiff exact (tangentBundleCore I M).instContMDiffVectorBundle @[deprecated (since := "2025-01-09")] alias TangentBundle.smoothVectorBundle := TangentBundle.contMDiffVectorBundle omit [IsManifold I 1 M] in instance [h : IsManifold I ∞ M] : ContMDiffVectorBundle ∞ E (TangentSpace I : M → Type _) I := by have : IsManifold I (∞ + 1) M := h exact TangentBundle.contMDiffVectorBundle omit [IsManifold I 1 M] in instance [IsManifold I ω M] : ContMDiffVectorBundle ω E (TangentSpace I : M → Type _) I := TangentBundle.contMDiffVectorBundle omit [IsManifold I 1 M] in instance [h : IsManifold I 2 M] : ContMDiffVectorBundle 1 E (TangentSpace I : M → Type _) I := by have : IsManifold I (1 + 1) M := h exact TangentBundle.contMDiffVectorBundle end TangentBundleInstances /-! ## The tangent bundle to the model space -/ @[simp, mfld_simps] theorem trivializationAt_model_space_apply (p : TangentBundle I H) (x : H) : trivializationAt E (TangentSpace I) x p = (p.1, p.2) := by simp [TangentBundle.trivializationAt_apply] have : fderivWithin 𝕜 (↑I ∘ ↑I.symm) (range I) (I p.proj) = fderivWithin 𝕜 id (range I) (I p.proj) := fderivWithin_congr' (fun y hy ↦ by simp [hy]) (mem_range_self p.proj) simp [this, fderivWithin_id (ModelWithCorners.uniqueDiffWithinAt_image I)] /-- In the tangent bundle to the model space, the charts are just the canonical identification between a product type and a sigma type, a.k.a. `TotalSpace.toProd`. -/ @[simp, mfld_simps] theorem tangentBundle_model_space_chartAt (p : TangentBundle I H) : (chartAt (ModelProd H E) p).toPartialEquiv = (TotalSpace.toProd H E).toPartialEquiv := by ext x : 1 · ext; · rfl exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2 · ext; · rfl apply heq_of_eq exact (tangentBundleCore I H).coordChange_self (achart _ x.1) x.1 (mem_achart_source H x.1) x.2 simp_rw [TangentBundle.chartAt, FiberBundleCore.localTriv, FiberBundleCore.localTrivAsPartialEquiv, VectorBundleCore.toFiberBundleCore_baseSet, tangentBundleCore_baseSet] simp only [mfld_simps] @[simp, mfld_simps] theorem tangentBundle_model_space_coe_chartAt (p : TangentBundle I H) : ⇑(chartAt (ModelProd H E) p) = TotalSpace.toProd H E := by rw [← PartialHomeomorph.coe_coe, tangentBundle_model_space_chartAt]; rfl @[simp, mfld_simps] theorem tangentBundle_model_space_coe_chartAt_symm (p : TangentBundle I H) : ((chartAt (ModelProd H E) p).symm : ModelProd H E → TangentBundle I H) = (TotalSpace.toProd H E).symm := by rw [← PartialHomeomorph.coe_coe, PartialHomeomorph.symm_toPartialEquiv, tangentBundle_model_space_chartAt]; rfl theorem tangentBundleCore_coordChange_model_space (x x' z : H) : (tangentBundleCore I H).coordChange (achart H x) (achart H x') z = ContinuousLinearMap.id 𝕜 E := by ext v; exact (tangentBundleCore I H).coordChange_self (achart _ z) z (mem_univ _) v variable (I) in /-- The canonical identification between the tangent bundle to the model space and the product, as a homeomorphism. For the diffeomorphism version, see `tangentBundleModelSpaceDiffeomorph`. -/ def tangentBundleModelSpaceHomeomorph : TangentBundle I H ≃ₜ ModelProd H E := { TotalSpace.toProd H E with continuous_toFun := by let p : TangentBundle I H := ⟨I.symm (0 : E), (0 : E)⟩ have : Continuous (chartAt (ModelProd H E) p) := by rw [continuous_iff_continuousOn_univ] convert (chartAt (ModelProd H E) p).continuousOn simp only [TangentSpace.fiberBundle, mfld_simps] simpa only [mfld_simps] using this continuous_invFun := by let p : TangentBundle I H := ⟨I.symm (0 : E), (0 : E)⟩
have : Continuous (chartAt (ModelProd H E) p).symm := by rw [continuous_iff_continuousOn_univ] convert (chartAt (ModelProd H E) p).symm.continuousOn simp only [mfld_simps] simpa only [mfld_simps] using this }
Mathlib/Geometry/Manifold/VectorBundle/Tangent.lean
395
399
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.GroupWithZero.NeZero import Mathlib.Logic.Unique import Mathlib.Tactic.Conv /-! # Groups with an adjoined zero element This file describes structures that are not usually studied on their own right in mathematics, namely a special sort of monoid: apart from a distinguished “zero element” they form a group, or in other words, they are groups with an adjoined zero element. Examples are: * division rings; * the value monoid of a multiplicative valuation; * in particular, the non-negative real numbers. ## Main definitions Various lemmas about `GroupWithZero` and `CommGroupWithZero`. To reduce import dependencies, the type-classes themselves are in `Algebra.GroupWithZero.Defs`. ## Implementation details As is usual in mathlib, we extend the inverse function to the zero element, and require `0⁻¹ = 0`. -/ assert_not_exists DenselyOrdered open Function variable {M₀ G₀ : Type*} section section MulZeroClass variable [MulZeroClass M₀] {a b : M₀} theorem left_ne_zero_of_mul : a * b ≠ 0 → a ≠ 0 := mt fun h => mul_eq_zero_of_left h b theorem right_ne_zero_of_mul : a * b ≠ 0 → b ≠ 0 := mt (mul_eq_zero_of_right a) theorem ne_zero_and_ne_zero_of_mul (h : a * b ≠ 0) : a ≠ 0 ∧ b ≠ 0 := ⟨left_ne_zero_of_mul h, right_ne_zero_of_mul h⟩ theorem mul_eq_zero_of_ne_zero_imp_eq_zero {a b : M₀} (h : a ≠ 0 → b = 0) : a * b = 0 := by have : Decidable (a = 0) := Classical.propDecidable (a = 0) exact if ha : a = 0 then by rw [ha, zero_mul] else by rw [h ha, mul_zero] /-- To match `one_mul_eq_id`. -/ theorem zero_mul_eq_const : ((0 : M₀) * ·) = Function.const _ 0 := funext zero_mul /-- To match `mul_one_eq_id`. -/ theorem mul_zero_eq_const : (· * (0 : M₀)) = Function.const _ 0 := funext mul_zero end MulZeroClass section Mul variable [Mul M₀] [Zero M₀] [NoZeroDivisors M₀] {a b : M₀} theorem eq_zero_of_mul_self_eq_zero (h : a * a = 0) : a = 0 := (eq_zero_or_eq_zero_of_mul_eq_zero h).elim id id @[field_simps] theorem mul_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 := mt eq_zero_or_eq_zero_of_mul_eq_zero <| not_or.mpr ⟨ha, hb⟩ end Mul namespace NeZero instance mul [Zero M₀] [Mul M₀] [NoZeroDivisors M₀] {x y : M₀} [NeZero x] [NeZero y] : NeZero (x * y) := ⟨mul_ne_zero out out⟩ end NeZero end section variable [MulZeroOneClass M₀] /-- In a monoid with zero, if zero equals one, then zero is the only element. -/ theorem eq_zero_of_zero_eq_one (h : (0 : M₀) = 1) (a : M₀) : a = 0 := by rw [← mul_one a, ← h, mul_zero] /-- In a monoid with zero, if zero equals one, then zero is the unique element. Somewhat arbitrarily, we define the default element to be `0`. All other elements will be provably equal to it, but not necessarily definitionally equal. -/ def uniqueOfZeroEqOne (h : (0 : M₀) = 1) : Unique M₀ where default := 0 uniq := eq_zero_of_zero_eq_one h /-- In a monoid with zero, zero equals one if and only if all elements of that semiring are equal. -/ theorem subsingleton_iff_zero_eq_one : (0 : M₀) = 1 ↔ Subsingleton M₀ := ⟨fun h => haveI := uniqueOfZeroEqOne h; inferInstance, fun h => @Subsingleton.elim _ h _ _⟩ alias ⟨subsingleton_of_zero_eq_one, _⟩ := subsingleton_iff_zero_eq_one theorem eq_of_zero_eq_one (h : (0 : M₀) = 1) (a b : M₀) : a = b := @Subsingleton.elim _ (subsingleton_of_zero_eq_one h) a b /-- In a monoid with zero, either zero and one are nonequal, or zero is the only element. -/ theorem zero_ne_one_or_forall_eq_0 : (0 : M₀) ≠ 1 ∨ ∀ a : M₀, a = 0 := not_or_of_imp eq_zero_of_zero_eq_one end section variable [MulZeroOneClass M₀] [Nontrivial M₀] {a b : M₀} theorem left_ne_zero_of_mul_eq_one (h : a * b = 1) : a ≠ 0 := left_ne_zero_of_mul <| ne_zero_of_eq_one h theorem right_ne_zero_of_mul_eq_one (h : a * b = 1) : b ≠ 0 := right_ne_zero_of_mul <| ne_zero_of_eq_one h end section MonoidWithZero variable [MonoidWithZero M₀] {a : M₀} {n : ℕ} @[simp] lemma zero_pow : ∀ {n : ℕ}, n ≠ 0 → (0 : M₀) ^ n = 0 | n + 1, _ => by rw [pow_succ, mul_zero] lemma zero_pow_eq (n : ℕ) : (0 : M₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, pow_zero] · rw [zero_pow h] lemma zero_pow_eq_one₀ [Nontrivial M₀] : (0 : M₀) ^ n = 1 ↔ n = 0 := by rw [zero_pow_eq, one_ne_zero.ite_eq_left_iff] lemma pow_eq_zero_of_le : ∀ {m n}, m ≤ n → a ^ m = 0 → a ^ n = 0 | _, _, Nat.le.refl, ha => ha | _, _, Nat.le.step hmn, ha => by rw [pow_succ, pow_eq_zero_of_le hmn ha, zero_mul] lemma ne_zero_pow (hn : n ≠ 0) (ha : a ^ n ≠ 0) : a ≠ 0 := by rintro rfl; exact ha <| zero_pow hn @[simp] lemma zero_pow_eq_zero [Nontrivial M₀] : (0 : M₀) ^ n = 0 ↔ n ≠ 0 := ⟨by rintro h rfl; simp at h, zero_pow⟩ lemma pow_mul_eq_zero_of_le {a b : M₀} {m n : ℕ} (hmn : m ≤ n) (h : a ^ m * b = 0) : a ^ n * b = 0 := by rw [show n = n - m + m by omega, pow_add, mul_assoc, h] simp variable [NoZeroDivisors M₀] lemma pow_eq_zero : ∀ {n}, a ^ n = 0 → a = 0 | 0, ha => by simpa using congr_arg (a * ·) ha | n + 1, ha => by rw [pow_succ, mul_eq_zero] at ha; exact ha.elim pow_eq_zero id @[simp] lemma pow_eq_zero_iff (hn : n ≠ 0) : a ^ n = 0 ↔ a = 0 := ⟨pow_eq_zero, by rintro rfl; exact zero_pow hn⟩ lemma pow_ne_zero_iff (hn : n ≠ 0) : a ^ n ≠ 0 ↔ a ≠ 0 := (pow_eq_zero_iff hn).not @[field_simps] lemma pow_ne_zero (n : ℕ) (h : a ≠ 0) : a ^ n ≠ 0 := mt pow_eq_zero h instance NeZero.pow [NeZero a] : NeZero (a ^ n) := ⟨pow_ne_zero n NeZero.out⟩ lemma sq_eq_zero_iff : a ^ 2 = 0 ↔ a = 0 := pow_eq_zero_iff two_ne_zero @[simp] lemma pow_eq_zero_iff' [Nontrivial M₀] : a ^ n = 0 ↔ a = 0 ∧ n ≠ 0 := by obtain rfl | hn := eq_or_ne n 0 <;> simp [*] theorem exists_right_inv_of_exists_left_inv {α} [MonoidWithZero α] (h : ∀ a : α, a ≠ 0 → ∃ b : α, b * a = 1) {a : α} (ha : a ≠ 0) : ∃ b : α, a * b = 1 := by obtain _ | _ := subsingleton_or_nontrivial α · exact ⟨a, Subsingleton.elim _ _⟩ obtain ⟨b, hb⟩ := h a ha obtain ⟨c, hc⟩ := h b (left_ne_zero_of_mul <| hb.trans_ne one_ne_zero) refine ⟨b, ?_⟩ conv_lhs => rw [← one_mul (a * b), ← hc, mul_assoc, ← mul_assoc b, hb, one_mul, hc] end MonoidWithZero section CancelMonoidWithZero variable [CancelMonoidWithZero M₀] {a b c : M₀} -- see Note [lower instance priority] instance (priority := 10) CancelMonoidWithZero.to_noZeroDivisors : NoZeroDivisors M₀ := ⟨fun ab0 => or_iff_not_imp_left.mpr fun ha => mul_left_cancel₀ ha <| ab0.trans (mul_zero _).symm⟩ @[simp] theorem mul_eq_mul_right_iff : a * c = b * c ↔ a = b ∨ c = 0 := by by_cases hc : c = 0 <;> [simp only [hc, mul_zero, or_true]; simp [mul_left_inj', hc]] @[simp] theorem mul_eq_mul_left_iff : a * b = a * c ↔ b = c ∨ a = 0 := by by_cases ha : a = 0 <;> [simp only [ha, zero_mul, or_true]; simp [mul_right_inj', ha]] theorem mul_right_eq_self₀ : a * b = a ↔ b = 1 ∨ a = 0 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 ∨ a = 0 := mul_eq_mul_left_iff theorem mul_left_eq_self₀ : a * b = b ↔ a = 1 ∨ b = 0 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 ∨ b = 0 := mul_eq_mul_right_iff @[simp] theorem mul_eq_left₀ (ha : a ≠ 0) : a * b = a ↔ b = 1 := by rw [Iff.comm, ← mul_right_inj' ha, mul_one] @[simp] theorem mul_eq_right₀ (hb : b ≠ 0) : a * b = b ↔ a = 1 := by rw [Iff.comm, ← mul_left_inj' hb, one_mul] @[simp] theorem left_eq_mul₀ (ha : a ≠ 0) : a = a * b ↔ b = 1 := by rw [eq_comm, mul_eq_left₀ ha] @[simp] theorem right_eq_mul₀ (hb : b ≠ 0) : b = a * b ↔ a = 1 := by rw [eq_comm, mul_eq_right₀ hb] /-- An element of a `CancelMonoidWithZero` fixed by right multiplication by an element other than one must be zero. -/ theorem eq_zero_of_mul_eq_self_right (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 := Classical.byContradiction fun ha => h₁ <| mul_left_cancel₀ ha <| h₂.symm ▸ (mul_one a).symm /-- An element of a `CancelMonoidWithZero` fixed by left multiplication by an element other than one must be zero. -/ theorem eq_zero_of_mul_eq_self_left (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 := Classical.byContradiction fun ha => h₁ <| mul_right_cancel₀ ha <| h₂.symm ▸ (one_mul a).symm end CancelMonoidWithZero section GroupWithZero variable [GroupWithZero G₀] {a b x : G₀} theorem GroupWithZero.mul_right_injective (h : x ≠ 0) : Function.Injective fun y => x * y := fun y y' w => by simpa only [← mul_assoc, inv_mul_cancel₀ h, one_mul] using congr_arg (fun y => x⁻¹ * y) w theorem GroupWithZero.mul_left_injective (h : x ≠ 0) : Function.Injective fun y => y * x := fun y y' w => by simpa only [mul_assoc, mul_inv_cancel₀ h, mul_one] using congr_arg (fun y => y * x⁻¹) w @[simp] theorem inv_mul_cancel_right₀ (h : b ≠ 0) (a : G₀) : a * b⁻¹ * b = a := calc a * b⁻¹ * b = a * (b⁻¹ * b) := mul_assoc _ _ _ _ = a := by simp [h] @[simp] theorem inv_mul_cancel_left₀ (h : a ≠ 0) (b : G₀) : a⁻¹ * (a * b) = b := calc a⁻¹ * (a * b) = a⁻¹ * a * b := (mul_assoc _ _ _).symm _ = b := by simp [h] private theorem inv_eq_of_mul (h : a * b = 1) : a⁻¹ = b := by rw [← inv_mul_cancel_left₀ (left_ne_zero_of_mul_eq_one h) b, h, mul_one] -- See note [lower instance priority] instance (priority := 100) GroupWithZero.toDivisionMonoid : DivisionMonoid G₀ := { ‹GroupWithZero G₀› with inv := Inv.inv, inv_inv := fun a => by by_cases h : a = 0 · simp [h] · exact left_inv_eq_right_inv (inv_mul_cancel₀ <| inv_ne_zero h) (inv_mul_cancel₀ h) , mul_inv_rev := fun a b => by by_cases ha : a = 0 · simp [ha] by_cases hb : b = 0 · simp [hb] apply inv_eq_of_mul simp [mul_assoc, ha, hb], inv_eq_of_mul := fun _ _ => inv_eq_of_mul } -- see Note [lower instance priority] instance (priority := 10) GroupWithZero.toCancelMonoidWithZero : CancelMonoidWithZero G₀ := { (‹_› : GroupWithZero G₀) with mul_left_cancel_of_ne_zero := @fun x y z hx h => by rw [← inv_mul_cancel_left₀ hx y, h, inv_mul_cancel_left₀ hx z], mul_right_cancel_of_ne_zero := @fun x y z hy h => by rw [← mul_inv_cancel_right₀ hy x, h, mul_inv_cancel_right₀ hy z] } end GroupWithZero section GroupWithZero variable [GroupWithZero G₀] {a : G₀} @[simp] theorem zero_div (a : G₀) : 0 / a = 0 := by rw [div_eq_mul_inv, zero_mul] @[simp] theorem div_zero (a : G₀) : a / 0 = 0 := by rw [div_eq_mul_inv, inv_zero, mul_zero] /-- Multiplying `a` by itself and then by its inverse results in `a` (whether or not `a` is zero). -/ @[simp] theorem mul_self_mul_inv (a : G₀) : a * a * a⁻¹ = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [mul_assoc, mul_inv_cancel₀ h, mul_one] /-- Multiplying `a` by its inverse and then by itself results in `a` (whether or not `a` is zero). -/ @[simp] theorem mul_inv_mul_cancel (a : G₀) : a * a⁻¹ * a = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [mul_inv_cancel₀ h, one_mul] /-- Multiplying `a⁻¹` by `a` twice results in `a` (whether or not `a` is zero). -/ @[simp] theorem inv_mul_mul_self (a : G₀) : a⁻¹ * a * a = a := by by_cases h : a = 0 · rw [h, inv_zero, mul_zero] · rw [inv_mul_cancel₀ h, one_mul] /-- Multiplying `a` by itself and then dividing by itself results in `a`, whether or not `a` is zero. -/ @[simp] theorem mul_self_div_self (a : G₀) : a * a / a = a := by rw [div_eq_mul_inv, mul_self_mul_inv a] /-- Dividing `a` by itself and then multiplying by itself results in `a`, whether or not `a` is zero. -/ @[simp] theorem div_self_mul_self (a : G₀) : a / a * a = a := by rw [div_eq_mul_inv, mul_inv_mul_cancel a] attribute [local simp] div_eq_mul_inv mul_comm mul_assoc mul_left_comm @[simp] theorem div_self_mul_self' (a : G₀) : a / (a * a) = a⁻¹ := calc a / (a * a) = a⁻¹⁻¹ * a⁻¹ * a⁻¹ := by simp [mul_inv_rev] _ = a⁻¹ := inv_mul_mul_self _ theorem one_div_ne_zero {a : G₀} (h : a ≠ 0) : 1 / a ≠ 0 := by simpa only [one_div] using inv_ne_zero h @[simp] theorem inv_eq_zero {a : G₀} : a⁻¹ = 0 ↔ a = 0 := by rw [inv_eq_iff_eq_inv, inv_zero] @[simp] theorem zero_eq_inv {a : G₀} : 0 = a⁻¹ ↔ 0 = a := eq_comm.trans <| inv_eq_zero.trans eq_comm /-- Dividing `a` by the result of dividing `a` by itself results in `a` (whether or not `a` is zero). -/ @[simp] theorem div_div_self (a : G₀) : a / (a / a) = a := by rw [div_div_eq_mul_div] exact mul_self_div_self a theorem ne_zero_of_one_div_ne_zero {a : G₀} (h : 1 / a ≠ 0) : a ≠ 0 := fun ha : a = 0 => by rw [ha, div_zero] at h contradiction theorem eq_zero_of_one_div_eq_zero {a : G₀} (h : 1 / a = 0) : a = 0 := Classical.byCases (fun ha => ha) fun ha => ((one_div_ne_zero ha) h).elim theorem mul_left_surjective₀ {a : G₀} (h : a ≠ 0) : Surjective fun g => a * g := fun g => ⟨a⁻¹ * g, by simp [← mul_assoc, mul_inv_cancel₀ h]⟩ theorem mul_right_surjective₀ {a : G₀} (h : a ≠ 0) : Surjective fun g => g * a := fun g => ⟨g * a⁻¹, by simp [mul_assoc, inv_mul_cancel₀ h]⟩ lemma zero_zpow : ∀ n : ℤ, n ≠ 0 → (0 : G₀) ^ n = 0 | (n : ℕ), h => by rw [zpow_natCast, zero_pow]; simpa [Int.natCast_eq_zero] using h | .negSucc n, _ => by simp lemma zero_zpow_eq (n : ℤ) : (0 : G₀) ^ n = if n = 0 then 1 else 0 := by split_ifs with h · rw [h, zpow_zero] · rw [zero_zpow _ h] lemma zero_zpow_eq_one₀ {n : ℤ} : (0 : G₀) ^ n = 1 ↔ n = 0 := by rw [zero_zpow_eq, one_ne_zero.ite_eq_left_iff] lemma zpow_add_one₀ (ha : a ≠ 0) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a | (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ] | -1 => by simp [ha] | .negSucc (n + 1) => by rw [Int.negSucc_eq, zpow_neg, Int.neg_add, Int.neg_add_cancel_right, zpow_neg, ← Int.natCast_succ, zpow_natCast, zpow_natCast, pow_succ' _ (n + 1), mul_inv_rev, mul_assoc, inv_mul_cancel₀ ha, mul_one] lemma zpow_sub_one₀ (ha : a ≠ 0) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ := calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := by rw [mul_assoc, mul_inv_cancel₀ ha, mul_one] _ = a ^ n * a⁻¹ := by rw [← zpow_add_one₀ ha, Int.sub_add_cancel] lemma zpow_add₀ (ha : a ≠ 0) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by induction n with | hz => simp | hp n ihn => simp only [← Int.add_assoc, zpow_add_one₀ ha, ihn, mul_assoc] | hn n ihn => rw [zpow_sub_one₀ ha, ← mul_assoc, ← ihn, ← zpow_sub_one₀ ha, Int.add_sub_assoc] lemma zpow_add' {m n : ℤ} (h : a ≠ 0 ∨ m + n ≠ 0 ∨ m = 0 ∧ n = 0) : a ^ (m + n) = a ^ m * a ^ n := by by_cases hm : m = 0 · simp [hm] by_cases hn : n = 0 · simp [hn] by_cases ha : a = 0 · subst a simp only [false_or, eq_self_iff_true, not_true, Ne, hm, hn, false_and, or_false] at h rw [zero_zpow _ h, zero_zpow _ hm, zero_mul] · exact zpow_add₀ ha m n lemma zpow_one_add₀ (h : a ≠ 0) (i : ℤ) : a ^ (1 + i) = a * a ^ i := by rw [zpow_add₀ h, zpow_one] end GroupWithZero section CommGroupWithZero
variable [CommGroupWithZero G₀]
Mathlib/Algebra/GroupWithZero/Basic.lean
444
446
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.InnerProductSpace.Defs import Mathlib.GroupTheory.MonoidLocalization.Basic /-! # Properties of inner product spaces This file proves many basic properties of inner product spaces (real or complex). ## Main results - `inner_mul_inner_self_le`: the Cauchy-Schwartz inequality (one of many variants). - `norm_inner_eq_norm_iff`: the equality criteion in the Cauchy-Schwartz inequality (also in many variants). - `inner_eq_sum_norm_sq_div_four`: the polarization identity. ## Tags inner product space, Hilbert space, norm -/ noncomputable section open RCLike Real Filter Topology ComplexConjugate Finsupp open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] section BasicProperties_Seminormed open scoped InnerProductSpace variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local postfix:90 "†" => starRingEnd _ export InnerProductSpace (norm_sq_eq_re_inner) @[simp] theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ := InnerProductSpace.conj_inner_symm _ _ theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := @inner_conj_symm ℝ _ _ _ _ x y theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by rw [← inner_conj_symm] exact star_eq_zero @[simp] theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := InnerProductSpace.add_left _ _ _ theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add] simp only [inner_conj_symm] theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] section Algebra variable {𝕝 : Type*} [CommSemiring 𝕝] [StarRing 𝕝] [Algebra 𝕝 𝕜] [Module 𝕝 E] [IsScalarTower 𝕝 𝕜 E] [StarModule 𝕝 𝕜] /-- See `inner_smul_left` for the common special when `𝕜 = 𝕝`. -/ lemma inner_smul_left_eq_star_smul (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r† • ⟪x, y⟫ := by rw [← algebraMap_smul 𝕜 r, InnerProductSpace.smul_left, starRingEnd_apply, starRingEnd_apply, ← algebraMap_star_comm, ← smul_eq_mul, algebraMap_smul] /-- Special case of `inner_smul_left_eq_star_smul` when the acting ring has a trivial star (eg `ℕ`, `ℤ`, `ℚ≥0`, `ℚ`, `ℝ`). -/ lemma inner_smul_left_eq_smul [TrivialStar 𝕝] (x y : E) (r : 𝕝) : ⟪r • x, y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_left_eq_star_smul, starRingEnd_apply, star_trivial] /-- See `inner_smul_right` for the common special when `𝕜 = 𝕝`. -/ lemma inner_smul_right_eq_smul (x y : E) (r : 𝕝) : ⟪x, r • y⟫ = r • ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left_eq_star_smul, starRingEnd_apply, starRingEnd_apply, star_smul, star_star, ← starRingEnd_apply, inner_conj_symm] end Algebra /-- See `inner_smul_left_eq_star_smul` for the case of a general algebra action. -/ theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := inner_smul_left_eq_star_smul .. theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_left _ _ _ theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_left, conj_ofReal, Algebra.smul_def] /-- See `inner_smul_right_eq_smul` for the case of a general algebra action. -/ theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ := inner_smul_right_eq_smul .. theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_right _ _ _ theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_right, Algebra.smul_def] /-- The inner product as a sesquilinear form. Note that in the case `𝕜 = ℝ` this is a bilinear form. -/ @[simps!] def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 := LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫) (fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _) (fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _ /-- The real inner product as a bilinear form. Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/ @[simps!] def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip /-- An inner product with a sum on the left. -/ theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ := map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _ /-- An inner product with a sum on the right. -/ theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ := map_sum (LinearMap.flip sesqFormOfInner x) _ _ /-- An inner product with a sum on the left, `Finsupp` version. -/ protected theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by convert sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_left, Finsupp.sum, smul_eq_mul] /-- An inner product with a sum on the right, `Finsupp` version. -/ protected theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by convert inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_right, Finsupp.sum, smul_eq_mul] protected theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by simp +contextual only [DFinsupp.sum, sum_inner, smul_eq_mul] protected theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by simp +contextual only [DFinsupp.sum, inner_sum, smul_eq_mul] @[simp] theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul] theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by simp only [inner_zero_left, AddMonoidHom.map_zero] @[simp] theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero] theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by simp only [inner_zero_right, AddMonoidHom.map_zero] theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ := PreInnerProductSpace.toCore.re_inner_nonneg x theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ _ x @[simp] theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := ((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im (𝕜 := 𝕜) x) theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by rw [← inner_self_ofReal_re, ← norm_sq_eq_re_inner, ofReal_pow] theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by conv_rhs => rw [← inner_self_ofReal_re] symm exact norm_of_nonneg inner_self_nonneg theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by rw [← inner_self_re_eq_norm] exact inner_self_ofReal_re _ theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ := @inner_self_ofReal_norm ℝ F _ _ _ x theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] @[simp] theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp @[simp] theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _ theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left] theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right] theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) /-- Expand `⟪x + y, x + y⟫` -/ theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring /-- Expand `⟪x + y, x + y⟫_ℝ` -/ theorem real_inner_add_add_self (x y : F) : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_add_add_self, this, add_left_inj] ring -- Expand `⟪x - y, x - y⟫` theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring /-- Expand `⟪x - y, x - y⟫_ℝ` -/ theorem real_inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_sub_sub_self, this, add_left_inj] ring /-- Parallelogram law -/ theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by simp only [inner_add_add_self, inner_sub_sub_self] ring /-- **Cauchy–Schwarz inequality**. -/ theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := letI cd : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore InnerProductSpace.Core.inner_mul_inner_self_le x y /-- Cauchy–Schwarz inequality for real inner products. -/ theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := calc ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by rw [real_inner_comm y, ← norm_mul] exact le_abs_self _ _ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y end BasicProperties_Seminormed section BasicProperties variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y export InnerProductSpace (norm_sq_eq_re_inner) @[simp] theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero] theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not variable (𝕜) theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)] theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)] variable {𝕜} @[simp] theorem re_inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by rw [← norm_sq_eq_re_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero] @[simp] lemma re_inner_self_pos {x : E} : 0 < re ⟪x, x⟫ ↔ x ≠ 0 := by simpa [-re_inner_self_nonpos] using re_inner_self_nonpos (𝕜 := 𝕜) (x := x).not @[deprecated (since := "2025-04-22")] alias inner_self_nonpos := re_inner_self_nonpos @[deprecated (since := "2025-04-22")] alias inner_self_pos := re_inner_self_pos open scoped InnerProductSpace in theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := re_inner_self_nonpos (𝕜 := ℝ) open scoped InnerProductSpace in theorem real_inner_self_pos {x : F} : 0 < ⟪x, x⟫_ℝ ↔ x ≠ 0 := re_inner_self_pos (𝕜 := ℝ) /-- A family of vectors is linearly independent if they are nonzero and orthogonal. -/ theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0) (ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff'] intro s g hg i hi have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by rw [inner_sum] symm convert Finset.sum_eq_single (M := 𝕜) i ?_ ?_ · rw [inner_smul_right] · intro j _hj hji rw [inner_smul_right, ho hji.symm, mul_zero] · exact fun h => False.elim (h hi) simpa [hg, hz] using h' end BasicProperties section Norm_Seminormed open scoped InnerProductSpace variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [SeminormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "IK" => @RCLike.I 𝕜 _ theorem norm_eq_sqrt_re_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) := calc ‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm _ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_re_inner _) @[deprecated (since := "2025-04-22")] alias norm_eq_sqrt_inner := norm_eq_sqrt_re_inner theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ := @norm_eq_sqrt_re_inner ℝ _ _ _ _ x theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by rw [@norm_eq_sqrt_re_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by rw [pow_two, inner_self_eq_norm_mul_norm] theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x simpa using h theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by rw [pow_two, real_inner_self_eq_norm_mul_norm] /-- Expand the square -/ theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] rw [inner_add_add_self, two_mul] simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add] rw [← inner_conj_symm, conj_re] alias norm_add_pow_two := norm_add_sq /-- Expand the square -/ theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by have h := @norm_add_sq ℝ _ _ _ _ x y simpa using h alias norm_add_pow_two_real := norm_add_sq_real /-- Expand the square -/ theorem norm_add_mul_self (x y : E) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by repeat' rw [← sq (M := ℝ)] exact norm_add_sq _ _ /-- Expand the square -/ theorem norm_add_mul_self_real (x y : F) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by have h := @norm_add_mul_self ℝ _ _ _ _ x y simpa using h /-- Expand the square -/ theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg, sub_eq_add_neg] alias norm_sub_pow_two := norm_sub_sq /-- Expand the square -/ theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := @norm_sub_sq ℝ _ _ _ _ _ _ alias norm_sub_pow_two_real := norm_sub_sq_real /-- Expand the square -/ theorem norm_sub_mul_self (x y : E) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by repeat' rw [← sq (M := ℝ)] exact norm_sub_sq _ _ /-- Expand the square -/ theorem norm_sub_mul_self_real (x y : F) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by have h := @norm_sub_mul_self ℝ _ _ _ _ x y simpa using h /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by rw [norm_eq_sqrt_re_inner (𝕜 := 𝕜) x, norm_eq_sqrt_re_inner (𝕜 := 𝕜) y] letI : PreInnerProductSpace.Core 𝕜 E := PreInnerProductSpace.toCore exact InnerProductSpace.Core.norm_inner_le_norm x y theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ := norm_inner_le_norm x y theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y) /-- Cauchy–Schwarz inequality with norm -/ theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ := (Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y) /-- Cauchy–Schwarz inequality with norm -/ theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ := le_trans (le_abs_self _) (abs_real_inner_le_norm _ _) lemma inner_eq_zero_of_left {x : E} (y : E) (h : ‖x‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by rw [← norm_eq_zero] refine le_antisymm ?_ (by positivity) exact norm_inner_le_norm _ _ |>.trans <| by simp [h] lemma inner_eq_zero_of_right (x : E) {y : E} (h : ‖y‖ = 0) : ⟪x, y⟫_𝕜 = 0 := by rw [inner_eq_zero_symm, inner_eq_zero_of_left _ h] variable (𝕜) include 𝕜 in theorem parallelogram_law_with_norm (x y : E) : ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by simp only [← @inner_self_eq_norm_mul_norm 𝕜] rw [← re.map_add, parallelogram_law, two_mul, two_mul] simp only [re.map_add] include 𝕜 in theorem parallelogram_law_with_nnnorm (x y : E) : ‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) := Subtype.ext <| parallelogram_law_with_norm 𝕜 x y variable {𝕜} /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) : re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := by rw [@norm_add_mul_self 𝕜] ring /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) : re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := by rw [@norm_sub_mul_self 𝕜] ring /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) : re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 := by rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜] ring /-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/ theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) : im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 := by simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re] ring /-- Polarization identity: The inner product, in terms of the norm. -/ theorem inner_eq_sum_norm_sq_div_four (x y : E) : ⟪x, y⟫ = ((‖x + y‖ : 𝕜) ^ 2 - (‖x - y‖ : 𝕜) ^ 2 + ((‖x - IK • y‖ : 𝕜) ^ 2 - (‖x + IK • y‖ : 𝕜) ^ 2) * IK) / 4 := by rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four, im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four] push_cast simp only [sq, ← mul_div_right_comm, ← add_div] /-- Polarization identity: The real inner product, in terms of the norm. -/ theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) : ⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := re_to_real.symm.trans <| re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y /-- Polarization identity: The real inner product, in terms of the norm. -/ theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) : ⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := re_to_real.symm.trans <| re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y /-- Pythagorean theorem, if-and-only-if vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_eq_left, mul_eq_zero] norm_num /-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/ theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} : ‖x + y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq, eq_comm] <;> positivity /-- Pythagorean theorem, vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := by rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_eq_left, mul_eq_zero] apply Or.inr simp only [h, zero_re'] /-- Pythagorean theorem, vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector inner product form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_eq_left, neg_eq_zero, mul_eq_zero] norm_num /-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square roots. -/ theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} : ‖x - y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq, eq_comm] <;> positivity /-- Pythagorean theorem, subtracting vectors, vector inner product form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h /-- The sum and difference of two vectors are orthogonal if and only if they have the same norm. -/ theorem real_inner_add_sub_eq_zero_iff (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ := by conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x, sub_eq_zero, re_to_real] constructor · intro h rw [add_comm] at h linarith · intro h linarith /-- Given two orthogonal vectors, their sum and difference have equal norms. -/ theorem norm_sub_eq_norm_add {v w : E} (h : ⟪v, w⟫ = 0) : ‖w - v‖ = ‖w + v‖ := by rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] simp only [h, ← @inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re', zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm, zero_add] /-- The real inner product of two vectors, divided by the product of their norms, has absolute value at most 1. -/ theorem abs_real_inner_div_norm_mul_norm_le_one (x y : F) : |⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| ≤ 1 := by rw [abs_div, abs_mul, abs_norm, abs_norm] exact div_le_one_of_le₀ (abs_real_inner_le_norm x y) (by positivity) /-- The inner product of a vector with a multiple of itself. -/ theorem real_inner_smul_self_left (x : F) (r : ℝ) : ⟪r • x, x⟫_ℝ = r * (‖x‖ * ‖x‖) := by rw [real_inner_smul_left, ← real_inner_self_eq_norm_mul_norm] /-- The inner product of a vector with a multiple of itself. -/ theorem real_inner_smul_self_right (x : F) (r : ℝ) : ⟪x, r • x⟫_ℝ = r * (‖x‖ * ‖x‖) := by rw [inner_smul_right, ← real_inner_self_eq_norm_mul_norm] /-- The inner product of two weighted sums, where the weights in each sum add to 0, in terms of the norms of pairwise differences. -/ theorem inner_sum_smul_sum_smul_of_sum_eq_zero {ι₁ : Type*} {s₁ : Finset ι₁} {w₁ : ι₁ → ℝ} (v₁ : ι₁ → F) (h₁ : ∑ i ∈ s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : Finset ι₂} {w₂ : ι₂ → ℝ} (v₂ : ι₂ → F) (h₂ : ∑ i ∈ s₂, w₂ i = 0) : ⟪∑ i₁ ∈ s₁, w₁ i₁ • v₁ i₁, ∑ i₂ ∈ s₂, w₂ i₂ • v₂ i₂⟫_ℝ = (-∑ i₁ ∈ s₁, ∑ i₂ ∈ s₂, w₁ i₁ * w₂ i₂ * (‖v₁ i₁ - v₂ i₂‖ * ‖v₁ i₁ - v₂ i₂‖)) / 2 := by simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two, ← div_sub_div_same, ← div_add_div_same, mul_sub_left_distrib, left_distrib, Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.sum_mul, h₁, h₂, zero_mul, mul_zero, Finset.sum_const_zero, zero_add, zero_sub, Finset.mul_sum, neg_div, Finset.sum_div, mul_div_assoc, mul_assoc] end Norm_Seminormed section Norm open scoped InnerProductSpace variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {ι : Type*} local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- Formula for the distance between the images of two nonzero points under an inversion with center zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general point. -/ theorem dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) : dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := calc dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = √(‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) := by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)] _ = √((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) := congr_arg sqrt <| by field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right, Real.norm_of_nonneg (mul_self_nonneg _)] ring _ = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := by rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity /-- The inner product of a nonzero vector with a nonzero multiple of itself, divided by the product of their norms, has absolute value 1. -/ theorem norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : E} {r : 𝕜} (hx : x ≠ 0) (hr : r ≠ 0) : ‖⟪x, r • x⟫‖ / (‖x‖ * ‖r • x‖) = 1 := by have hx' : ‖x‖ ≠ 0 := by simp [hx] have hr' : ‖r‖ ≠ 0 := by simp [hr] rw [inner_smul_right, norm_mul, ← inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul] rw [← mul_assoc, ← div_div, mul_div_cancel_right₀ _ hx', ← div_div, mul_comm, mul_div_cancel_right₀ _ hr', div_self hx'] /-- The inner product of a nonzero vector with a nonzero multiple of itself, divided by the product of their norms, has absolute value 1. -/ theorem abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul {x : F} {r : ℝ} (hx : x ≠ 0) (hr : r ≠ 0) : |⟪x, r • x⟫_ℝ| / (‖x‖ * ‖r • x‖) = 1 := norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr /-- The inner product of a nonzero vector with a positive multiple of itself, divided by the product of their norms, has value 1. -/ theorem real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul {x : F} {r : ℝ} (hx : x ≠ 0) (hr : 0 < r) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = 1 := by rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|, mul_assoc, abs_of_nonneg hr.le, div_self] exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx)) /-- The inner product of a nonzero vector with a negative multiple of itself, divided by the product of their norms, has value -1. -/ theorem real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul {x : F} {r : ℝ} (hx : x ≠ 0) (hr : r < 0) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = -1 := by rw [real_inner_smul_self_right, norm_smul, Real.norm_eq_abs, ← mul_assoc ‖x‖, mul_comm _ |r|, mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self] exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx)) theorem norm_inner_eq_norm_tfae (x y : E) : List.TFAE [‖⟪x, y⟫‖ = ‖x‖ * ‖y‖, x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫) • x, x = 0 ∨ ∃ r : 𝕜, y = r • x, x = 0 ∨ y ∈ 𝕜 ∙ x] := by tfae_have 1 → 2 := by refine fun h => or_iff_not_imp_left.2 fun hx₀ => ?_ have : ‖x‖ ^ 2 ≠ 0 := pow_ne_zero _ (norm_ne_zero_iff.2 hx₀) rw [← sq_eq_sq₀, mul_pow, ← mul_right_inj' this, eq_comm, ← sub_eq_zero, ← mul_sub] at h <;> try positivity simp only [@norm_sq_eq_re_inner 𝕜] at h letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore erw [← InnerProductSpace.Core.cauchy_schwarz_aux (𝕜 := 𝕜) (F := E)] at h rw [InnerProductSpace.Core.normSq_eq_zero, sub_eq_zero] at h rw [div_eq_inv_mul, mul_smul, h, inv_smul_smul₀] rwa [inner_self_ne_zero] tfae_have 2 → 3 := fun h => h.imp_right fun h' => ⟨_, h'⟩ tfae_have 3 → 1 := by rintro (rfl | ⟨r, rfl⟩) <;> simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K, inner_self_eq_norm_mul_norm, sq, mul_left_comm] tfae_have 3 ↔ 4 := by simp only [Submodule.mem_span_singleton, eq_comm] tfae_finish /-- If the inner product of two vectors is equal to the product of their norms, then the two vectors are multiples of each other. One form of the equality case for Cauchy-Schwarz. Compare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `⟪x, y⟫ = ‖x‖ * ‖y‖`. -/ theorem norm_inner_eq_norm_iff {x y : E} (hx₀ : x ≠ 0) (hy₀ : y ≠ 0) : ‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x := calc ‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ x = 0 ∨ ∃ r : 𝕜, y = r • x := (@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 2 _ ↔ ∃ r : 𝕜, y = r • x := or_iff_right hx₀ _ ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x := ⟨fun ⟨r, h⟩ => ⟨r, fun hr₀ => hy₀ <| h.symm ▸ smul_eq_zero.2 <| Or.inl hr₀, h⟩, fun ⟨r, _hr₀, h⟩ => ⟨r, h⟩⟩ /-- The inner product of two vectors, divided by the product of their norms, has absolute value 1 if and only if they are nonzero and one is a multiple of the other. One form of equality case for Cauchy-Schwarz. -/ theorem norm_inner_div_norm_mul_norm_eq_one_iff (x y : E) : ‖⟪x, y⟫ / (‖x‖ * ‖y‖)‖ = 1 ↔ x ≠ 0 ∧ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x := by constructor · intro h have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h refine ⟨hx₀, (norm_inner_eq_norm_iff hx₀ hy₀).1 <| eq_of_div_eq_one ?_⟩ simpa using h · rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩ simp only [norm_div, norm_mul, norm_ofReal, abs_norm] exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr /-- The inner product of two vectors, divided by the product of their norms, has absolute value 1 if and only if they are nonzero and one is a multiple of the other. One form of equality case for Cauchy-Schwarz. -/ theorem abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) : |⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r ≠ 0 ∧ y = r • x := @norm_inner_div_norm_mul_norm_eq_one_iff ℝ F _ _ _ x y theorem inner_eq_norm_mul_iff_div {x y : E} (h₀ : x ≠ 0) : ⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ / ‖x‖ : 𝕜) • x = y := by have h₀' := h₀ rw [← norm_ne_zero_iff, Ne, ← @ofReal_eq_zero 𝕜] at h₀' constructor <;> intro h · have : x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫ : 𝕜) • x := ((@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 1).1 (by simp [h]) rw [this.resolve_left h₀, h] simp [norm_smul, inner_self_ofReal_norm, mul_div_cancel_right₀ _ h₀'] · conv_lhs => rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] field_simp [sq, mul_left_comm] /-- If the inner product of two vectors is equal to the product of their norms (i.e., `⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form of the equality case for Cauchy-Schwarz. Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/ theorem inner_eq_norm_mul_iff {x y : E} : ⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ : 𝕜) • x = (‖x‖ : 𝕜) • y := by rcases eq_or_ne x 0 with (rfl | h₀) · simp · rw [inner_eq_norm_mul_iff_div h₀, div_eq_inv_mul, mul_smul, inv_smul_eq_iff₀] rwa [Ne, ofReal_eq_zero, norm_eq_zero] /-- If the inner product of two vectors is equal to the product of their norms (i.e., `⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form of the equality case for Cauchy-Schwarz. Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/ theorem inner_eq_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ = ‖x‖ * ‖y‖ ↔ ‖y‖ • x = ‖x‖ • y := inner_eq_norm_mul_iff /-- The inner product of two vectors, divided by the product of their norms, has value 1 if and only if they are nonzero and one is a positive multiple of the other. -/ theorem real_inner_div_norm_mul_norm_eq_one_iff (x y : F) : ⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = 1 ↔ x ≠ 0 ∧ ∃ r : ℝ, 0 < r ∧ y = r • x := by constructor · intro h have hx₀ : x ≠ 0 := fun h₀ => by simp [h₀] at h have hy₀ : y ≠ 0 := fun h₀ => by simp [h₀] at h refine ⟨hx₀, ‖y‖ / ‖x‖, div_pos (norm_pos_iff.2 hy₀) (norm_pos_iff.2 hx₀), ?_⟩ exact ((inner_eq_norm_mul_iff_div hx₀).1 (eq_of_div_eq_one h)).symm · rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩ exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr /-- The inner product of two vectors, divided by the product of their norms, has value -1 if and only if they are nonzero and one is a negative multiple of the other. -/ theorem real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) : ⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = -1 ↔ x ≠ 0 ∧ ∃ r : ℝ, r < 0 ∧ y = r • x := by rw [← neg_eq_iff_eq_neg, ← neg_div, ← inner_neg_right, ← norm_neg y, real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective ℝ _).exists] refine Iff.rfl.and (exists_congr fun r => ?_) rw [neg_pos, neg_smul, neg_inj] /-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of the equality case for Cauchy-Schwarz. -/ theorem inner_eq_one_iff_of_norm_one {x y : E} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) : ⟪x, y⟫ = 1 ↔ x = y := by convert inner_eq_norm_mul_iff (𝕜 := 𝕜) (E := E) using 2 <;> simp [hx, hy] theorem inner_lt_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ‖y‖ • x ≠ ‖x‖ • y := calc ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ ≠ ‖x‖ * ‖y‖ := ⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩ _ ↔ ‖y‖ • x ≠ ‖x‖ • y := not_congr inner_eq_norm_mul_iff_real /-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are distinct. One form of the equality case for Cauchy-Schwarz. -/ theorem inner_lt_one_iff_real_of_norm_one {x y : F} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) : ⟪x, y⟫_ℝ < 1 ↔ x ≠ y := by convert inner_lt_norm_mul_iff_real (F := F) <;> simp [hx, hy] /-- The sphere of radius `r = ‖y‖` is tangent to the plane `⟪x, y⟫ = ‖y‖ ^ 2` at `x = y`. -/ theorem eq_of_norm_le_re_inner_eq_norm_sq {x y : E} (hle : ‖x‖ ≤ ‖y‖) (h : re ⟪x, y⟫ = ‖y‖ ^ 2) : x = y := by suffices H : re ⟪x - y, x - y⟫ ≤ 0 by rwa [re_inner_self_nonpos, sub_eq_zero] at H have H₁ : ‖x‖ ^ 2 ≤ ‖y‖ ^ 2 := by gcongr have H₂ : re ⟪y, x⟫ = ‖y‖ ^ 2 := by rwa [← inner_conj_symm, conj_re] simpa [inner_sub_left, inner_sub_right, ← norm_sq_eq_re_inner, h, H₂] using H₁ end Norm section RCLike local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- A field `𝕜` satisfying `RCLike` is itself a `𝕜`-inner product space. -/ instance RCLike.innerProductSpace : InnerProductSpace 𝕜 𝕜 where inner x y := y * conj x norm_sq_eq_re_inner x := by simp only [inner, mul_conj, ← ofReal_pow, ofReal_re] conj_inner_symm x y := by simp only [mul_comm, map_mul, starRingEnd_self_apply] add_left x y z := by simp only [mul_add, map_add] smul_left x y z := by simp only [mul_comm (conj z), mul_assoc, smul_eq_mul, map_mul] @[simp] theorem RCLike.inner_apply (x y : 𝕜) : ⟪x, y⟫ = y * conj x := rfl /-- A version of `RCLike.inner_apply` that swaps the order of multiplication. -/ theorem RCLike.inner_apply' (x y : 𝕜) : ⟪x, y⟫ = conj x * y := mul_comm _ _ end RCLike section RCLikeToReal open scoped InnerProductSpace variable {G : Type*} variable (𝕜 E) variable [SeminormedAddCommGroup E] [InnerProductSpace 𝕜 E] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- A general inner product implies a real inner product. This is not registered as an instance since `𝕜` does not appear in the return type `Inner ℝ E`. -/ def Inner.rclikeToReal : Inner ℝ E where inner x y := re ⟪x, y⟫ /-- A general inner product space structure implies a real inner product structure. This is not registered as an instance since * `𝕜` does not appear in the return type `InnerProductSpace ℝ E`, * It is likely to create instance diamonds, as it builds upon the diamond-prone `NormedSpace.restrictScalars`. However, it can be used in a proof to obtain a real inner product space structure from a given `𝕜`-inner product space structure. -/ -- See note [reducible non instances] abbrev InnerProductSpace.rclikeToReal : InnerProductSpace ℝ E := { Inner.rclikeToReal 𝕜 E, NormedSpace.restrictScalars ℝ 𝕜 E with norm_sq_eq_re_inner := norm_sq_eq_re_inner conj_inner_symm := fun _ _ => inner_re_symm _ _ add_left := fun x y z => by change re ⟪x + y, z⟫ = re ⟪x, z⟫ + re ⟪y, z⟫ simp only [inner_add_left, map_add] smul_left := fun x y r => by change re ⟪(r : 𝕜) • x, y⟫ = r * re ⟪x, y⟫ simp only [inner_smul_left, conj_ofReal, re_ofReal_mul] } variable {E} theorem real_inner_eq_re_inner (x y : E) : @Inner.inner ℝ E (Inner.rclikeToReal 𝕜 E) x y = re ⟪x, y⟫ := rfl theorem real_inner_I_smul_self (x : E) : @Inner.inner ℝ E (Inner.rclikeToReal 𝕜 E) x ((I : 𝕜) • x) = 0 := by simp [real_inner_eq_re_inner 𝕜, inner_smul_right] /-- A complex inner product implies a real inner product. This cannot be an instance since it creates a diamond with `PiLp.innerProductSpace` because `re (sum i, inner (x i) (y i))` and `sum i, re (inner (x i) (y i))` are not defeq. -/ def InnerProductSpace.complexToReal [SeminormedAddCommGroup G] [InnerProductSpace ℂ G] : InnerProductSpace ℝ G := InnerProductSpace.rclikeToReal ℂ G instance : InnerProductSpace ℝ ℂ := InnerProductSpace.complexToReal @[simp] protected theorem Complex.inner (w z : ℂ) : ⟪w, z⟫_ℝ = (z * conj w).re := rfl end RCLikeToReal /-- An `RCLike` field is a real inner product space. -/ noncomputable instance RCLike.toInnerProductSpaceReal : InnerProductSpace ℝ 𝕜 where __ := Inner.rclikeToReal 𝕜 𝕜 norm_sq_eq_re_inner := norm_sq_eq_re_inner conj_inner_symm x y := inner_re_symm .. add_left x y z := show re (_ * _) = re (_ * _) + re (_ * _) by simp only [map_add, mul_re, conj_re, conj_im]; ring smul_left x y r := show re (_ * _) = _ * re (_ * _) by simp only [mul_re, conj_re, conj_im, conj_trivial, smul_re, smul_im]; ring -- The instance above does not create diamonds for concrete `𝕜`: example : (innerProductSpace : InnerProductSpace ℝ ℝ) = RCLike.toInnerProductSpaceReal := rfl example : (instInnerProductSpaceRealComplex : InnerProductSpace ℝ ℂ) = RCLike.toInnerProductSpaceReal := rfl
Mathlib/Analysis/InnerProductSpace/Basic.lean
1,717
1,718
/- Copyright (c) 2023 Antoine Chambert-Loir and María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández, Eric Wieser, Bhavik Mehta, Yaël Dillies -/ import Mathlib.Algebra.Order.Antidiag.Pi import Mathlib.Data.Finsupp.Basic /-! # Antidiagonal of finitely supported functions as finsets This file defines the finset of finitely functions summing to a specific value on a finset. Such finsets should be thought of as the "antidiagonals" in the space of finitely supported functions. Precisely, for a commutative monoid `μ` with antidiagonals (see `Finset.HasAntidiagonal`), `Finset.finsuppAntidiag s n` is the finset of all finitely supported functions `f : ι →₀ μ` with support contained in `s` and such that the sum of its values equals `n : μ`. We define it using `Finset.piAntidiag s n`, the corresponding antidiagonal in `ι → μ`. ## Main declarations * `Finset.finsuppAntidiag s n`: Finset of all finitely supported functions `f : ι →₀ μ` with support contained in `s` and such that the sum of its values equals `n : μ`. -/ open Finsupp Function variable {ι μ μ' : Type*} namespace Finset section AddCommMonoid variable [DecidableEq ι] [AddCommMonoid μ] [HasAntidiagonal μ] [DecidableEq μ] {s : Finset ι} {n : μ} {f : ι →₀ μ} /-- The finset of functions `ι →₀ μ` with support contained in `s` and sum equal to `n`. -/ def finsuppAntidiag (s : Finset ι) (n : μ) : Finset (ι →₀ μ) := (piAntidiag s n).attach.map ⟨fun f ↦ ⟨s.filter (f.1 · ≠ 0), f.1, by simpa using (mem_piAntidiag.1 f.2).2⟩, fun _ _ hfg ↦ Subtype.ext (congr_arg (⇑) hfg)⟩ @[simp] lemma mem_finsuppAntidiag : f ∈ finsuppAntidiag s n ↔ s.sum f = n ∧ f.support ⊆ s := by simp [finsuppAntidiag, ← DFunLike.coe_fn_eq, subset_iff] lemma mem_finsuppAntidiag' : f ∈ finsuppAntidiag s n ↔ f.sum (fun _ x ↦ x) = n ∧ f.support ⊆ s := by simp only [mem_finsuppAntidiag, and_congr_left_iff] rintro hf rw [sum_of_support_subset (N := μ) f hf (fun _ x ↦ x) fun _ _ ↦ rfl] @[simp] lemma finsuppAntidiag_empty_zero : finsuppAntidiag (∅ : Finset ι) (0 : μ) = {0} := by ext f; simp [finsuppAntidiag, ← DFunLike.coe_fn_eq (g := f), eq_comm] @[simp] lemma finsuppAntidiag_empty_of_ne_zero (hn : n ≠ 0) : finsuppAntidiag (∅ : Finset ι) n = ∅ := eq_empty_of_forall_not_mem (by simp [@eq_comm _ 0, hn.symm]) lemma finsuppAntidiag_empty (n : μ) : finsuppAntidiag (∅ : Finset ι) n = if n = 0 then {0} else ∅ := by split_ifs with hn <;> simp [*] theorem mem_finsuppAntidiag_insert {a : ι} {s : Finset ι} (h : a ∉ s) (n : μ) {f : ι →₀ μ} : f ∈ finsuppAntidiag (insert a s) n ↔ ∃ m ∈ antidiagonal n, ∃ (g : ι →₀ μ), f = Finsupp.update g a m.1 ∧ g ∈ finsuppAntidiag s m.2 := by simp only [mem_finsuppAntidiag, mem_antidiagonal, Prod.exists, sum_insert h] constructor · rintro ⟨rfl, hsupp⟩ refine ⟨_, _, rfl, Finsupp.erase a f, ?_, ?_, ?_⟩ · rw [update_erase_eq_update, Finsupp.update_self] · apply sum_congr rfl intro x hx rw [Finsupp.erase_ne (ne_of_mem_of_not_mem hx h)] · rwa [support_erase, ← subset_insert_iff] · rintro ⟨n1, n2, rfl, g, rfl, rfl, hgsupp⟩ refine ⟨?_, (support_update_subset _ _).trans (insert_subset_insert a hgsupp)⟩
simp only [coe_update] apply congr_arg₂ · rw [Function.update_self] · apply sum_congr rfl intro x hx rw [update_of_ne (ne_of_mem_of_not_mem hx h) n1 ⇑g] theorem finsuppAntidiag_insert {a : ι} {s : Finset ι} (h : a ∉ s) (n : μ) : finsuppAntidiag (insert a s) n = (antidiagonal n).biUnion (fun p : μ × μ => (finsuppAntidiag s p.snd).attach.map ⟨fun f => Finsupp.update f.val a p.fst, (fun ⟨f, hf⟩ ⟨g, hg⟩ hfg => Subtype.ext <| by simp only [mem_val, mem_finsuppAntidiag] at hf hg simp only [DFunLike.ext_iff] at hfg ⊢ intro x obtain rfl | hx := eq_or_ne x a · replace hf := mt (hf.2 ·) h
Mathlib/Algebra/Order/Antidiag/Finsupp.lean
78
96
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Devon Tuma -/ import Mathlib.Probability.ProbabilityMassFunction.Basic /-! # Monad Operations for Probability Mass Functions This file constructs two operations on `PMF` that give it a monad structure. `pure a` is the distribution where a single value `a` has probability `1`. `bind pa pb : PMF β` is the distribution given by sampling `a : α` from `pa : PMF α`, and then sampling from `pb a : PMF β` to get a final result `b : β`. `bindOnSupport` generalizes `bind` to allow binding to a partial function, so that the second argument only needs to be defined on the support of the first argument. -/ noncomputable section variable {α β γ : Type*} open NNReal ENNReal open MeasureTheory namespace PMF section Pure open scoped Classical in /-- The pure `PMF` is the `PMF` where all the mass lies in one point. The value of `pure a` is `1` at `a` and `0` elsewhere. -/ def pure (a : α) : PMF α := ⟨fun a' => if a' = a then 1 else 0, hasSum_ite_eq _ _⟩ variable (a a' : α) open scoped Classical in @[simp] theorem pure_apply : pure a a' = if a' = a then 1 else 0 := rfl @[simp] theorem support_pure : (pure a).support = {a} := Set.ext fun a' => by simp [mem_support_iff]
theorem mem_support_pure_iff : a' ∈ (pure a).support ↔ a' = a := by simp
Mathlib/Probability/ProbabilityMassFunction/Monad.lean
50
51
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Kim Morrison -/ import Mathlib.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Constructions /-! # Conditions for rank to be finite Also contains characterization for when rank equals zero or rank equals one. -/ noncomputable section universe u v v' w variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] attribute [local instance] nontrivial_of_invariantBasisNumber open Basis Cardinal Function Module Set Submodule /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li theorem rank_le {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : Module.rank R M ≤ n := by rw [Module.rank_def] apply ciSup_le' rintro ⟨s, li⟩ exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li section RankZero /-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/ lemma rank_eq_zero_iff : Module.rank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by nontriviality R constructor · contrapose! rintro ⟨x, hx⟩ rw [← Cardinal.one_le_iff_ne_zero] have : LinearIndependent R (fun _ : Unit ↦ x) := linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦ hx _ H ((Finsupp.linearCombination_unique _ _ _).symm.trans hl)) simpa using this.cardinal_lift_le_rank · intro h rw [← le_zero_iff, Module.rank_def] apply ciSup_le' intro ⟨s, hs⟩ rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff] rintro ⟨i : s⟩ obtain ⟨a, ha, ha'⟩ := h i apply ha simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i theorem rank_pos_of_free [Module.Free R M] [Nontrivial M] : 0 < Module.rank R M := have := Module.nontrivial R M (pos_of_ne_zero <| Cardinal.mk_ne_zero _).trans_le (Free.chooseBasis R M).linearIndependent.cardinal_le_rank variable [Nontrivial R] section variable [NoZeroSMulDivisors R M] theorem rank_zero_iff_forall_zero : Module.rank R M = 0 ↔ ∀ x : M, x = 0 := by simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or, exists_and_right, and_iff_right (exists_ne (0 : R))] /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/ theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M := rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ ∃ x : M, x ≠ 0 := by rw [← not_iff_not] simpa using rank_zero_iff_forall_zero theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M := rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm theorem rank_pos [Nontrivial M] : 0 < Module.rank R M := rank_pos_iff_nontrivial.mpr ‹_› end variable (R M) /-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/ @[nontriviality] theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 := rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩ @[simp] theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _ @[simp] theorem rank_bot : Module.rank R (⊥ : Submodule R M) = 0 := rank_subsingleton' _ _ variable {R M} theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) : ∃ b : M, b ∈ s ∧ b ≠ 0 := exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h end RankZero section Finite theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : ℕ} (h : Module.rank R M = n) : Module.Finite R M := by nontriviality R obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have := mk_lt_aleph0_iff.mp <| b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n exact Module.Finite.of_basis b theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : Module.Finite R M := by nontriviality R rw [rank_zero_iff] at h infer_instance theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) : Module.Finite R M := Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm section variable [StrongRankCondition R] /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Nonempty (Fintype ι) := by rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0, Cardinal.lt_aleph0_iff_fintype] at h /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Fintype ι := Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h) /-- If a module has a finite dimension, all bases are indexed by a finite set. -/ theorem Basis.finite_index_of_rank_lt_aleph0 {ι : Type*} {s : Set ι} (b : Basis s R M) (h : Module.rank R M < ℵ₀) : s.Finite := finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h) end namespace LinearIndependent variable [StrongRankCondition R] theorem cardinalMk_le_finrank [Module.Finite R M] {ι : Type w} {b : ι → M} (h : LinearIndependent R b) : #ι ≤ finrank R M := by rw [← lift_le.{max v w}] simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank @[deprecated (since := "2024-11-10")] alias cardinal_mk_le_finrank := cardinalMk_le_finrank theorem fintype_card_le_finrank [Module.Finite R M] {ι : Type*} [Fintype ι] {b : ι → M} (h : LinearIndependent R b) : Fintype.card ι ≤ finrank R M := by simpa using h.cardinalMk_le_finrank theorem finset_card_le_finrank [Module.Finite R M] {b : Finset M} (h : LinearIndependent R (fun x => x : b → M)) : b.card ≤ finrank R M := by rw [← Fintype.card_coe] exact h.fintype_card_le_finrank theorem lt_aleph0_of_finite {ι : Type w} [Module.Finite R M] {v : ι → M} (h : LinearIndependent R v) : #ι < ℵ₀ := by apply Cardinal.lift_lt.1 apply lt_of_le_of_lt · apply h.cardinal_lift_le_rank · rw [← finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast] apply Cardinal.nat_lt_aleph0 theorem finite [Module.Finite R M] {ι : Type*} {f : ι → M} (h : LinearIndependent R f) : Finite ι := Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite theorem setFinite [Module.Finite R M] {b : Set M} (h : LinearIndependent R fun x : b => (x : M)) : b.Finite := Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite end LinearIndependent lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) : ∃ s : Set M, #s = n ∧ LinearIndepOn R id s := by obtain ⟨⟨s, hs⟩, hs'⟩ := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M)) obtain ⟨t, ht, ht'⟩ := le_mk_iff_exists_subset.mp hs'.le exact ⟨t, ht', hs.mono ht⟩ lemma exists_finset_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndepOn R id (s : Set M) := by have := nonempty_linearIndependent_set rcases hn.eq_or_lt with h | h · obtain ⟨⟨s, hs⟩, hs'⟩ := Cardinal.exists_eq_natCast_of_iSup_eq _ (Cardinal.bddAbove_range _) _ (h.trans (Module.rank_def R M)).symm have : Finite s := lt_aleph0_iff_finite.mp (hs' ▸ nat_lt_aleph0 n) cases nonempty_fintype s refine ⟨s.toFinset, by simpa using hs', by simpa⟩ · obtain ⟨s, hs, hs'⟩ := exists_set_linearIndependent_of_lt_rank h have : Finite s := lt_aleph0_iff_finite.mp (hs ▸ nat_lt_aleph0 n) cases nonempty_fintype s exact ⟨s.toFinset, by simpa using hs, by simpa⟩ lemma exists_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_rank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ lemma natCast_le_rank_iff [Nontrivial R] {n : ℕ} : n ≤ Module.rank R M ↔ ∃ f : Fin n → M, LinearIndependent R f := ⟨exists_linearIndependent_of_le_rank, fun H ↦ by simpa using H.choose_spec.cardinal_lift_le_rank⟩ lemma natCast_le_rank_iff_finset [Nontrivial R] {n : ℕ} : n ≤ Module.rank R M ↔ ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := ⟨exists_finset_linearIndependent_of_le_rank, fun ⟨s, h₁, h₂⟩ ↦ by simpa [h₁] using h₂.cardinal_le_rank⟩ lemma exists_finset_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by by_cases h : finrank R M = 0 · rw [le_zero_iff.mp (hn.trans_eq h)] exact ⟨∅, rfl, by convert linearIndependent_empty R M using 2 <;> aesop⟩ exact exists_finset_linearIndependent_of_le_rank ((Nat.cast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2)) lemma exists_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_finrank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ variable [Module.Finite R M] [StrongRankCondition R] in theorem Module.Finite.not_linearIndependent_of_infinite {ι : Type*} [Infinite ι] (v : ι → M) : ¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _ section variable [NoZeroSMulDivisors R M] theorem iSupIndep.subtype_ne_bot_le_rank [Nontrivial R] {V : ι → Submodule R M} (hV : iSupIndep V) : Cardinal.lift.{v} #{ i : ι // V i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := by set I := { i : ι // V i ≠ ⊥ } have hI : ∀ i : I, ∃ v ∈ V i, v ≠ (0 : M) := by intro i rw [← Submodule.ne_bot_iff] exact i.prop choose v hvV hv using hI have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv exact this.cardinal_lift_le_rank @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.subtype_ne_bot_le_rank := iSupIndep.subtype_ne_bot_le_rank variable [Module.Finite R M] [StrongRankCondition R] theorem iSupIndep.subtype_ne_bot_le_finrank_aux {p : ι → Submodule R M} (hp : iSupIndep p) : #{ i // p i ≠ ⊥ } ≤ (finrank R M : Cardinal.{w}) := by suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by rwa [Cardinal.lift_le] at this calc Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := hp.subtype_ne_bot_le_rank _ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank] _ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is finite. -/ noncomputable def iSupIndep.fintypeNeBotOfFiniteDimensional {p : ι → Submodule R M} (hp : iSupIndep p) : Fintype { i : ι // p i ≠ ⊥ } := by suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by rw [Cardinal.lt_aleph0_iff_fintype] at this exact this.some refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_ simp [Cardinal.nat_lt_aleph0] /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`. Note that the `Fintype` hypothesis required here can be provided by `iSupIndep.fintypeNeBotOfFiniteDimensional`. -/ theorem iSupIndep.subtype_ne_bot_le_finrank {p : ι → Submodule R M} (hp : iSupIndep p) [Fintype { i // p i ≠ ⊥ }] : Fintype.card { i // p i ≠ ⊥ } ≤ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux end variable [Module.Finite R M] [StrongRankCondition R] section open Finset /-- If a finset has cardinality larger than the rank of a module, then there is a nontrivial linear relation amongst its elements. -/ theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M} (h : finrank R M < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by obtain ⟨g, sum, z, nonzero⟩ := Fintype.not_linearIndependent_iff.mp (mt LinearIndependent.finset_card_le_finrank h.not_le) refine ⟨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]⟩ rw [← Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply /-- If a finset has cardinality larger than `finrank + 1`, then there is a nontrivial linear relation amongst its elements, such that the coefficients of the relation sum to zero. -/ theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card {t : Finset M} (h : finrank R M + 1 < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by -- Pick an element x₀ ∈ t, obtain ⟨x₀, x₀_mem⟩ := card_pos.1 ((Nat.succ_pos _).trans h) -- and apply the previous lemma to the {xᵢ - x₀} let shift : M ↪ M := ⟨(· - x₀), sub_left_injective⟩ classical let t' := (t.erase x₀).map shift have h' : finrank R M < t'.card := by rw [card_map, card_erase_of_mem x₀_mem] exact Nat.lt_pred_iff.mpr h -- to obtain a function `g`. obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h' -- Then obtain `f` by translating back by `x₀`, -- and setting the value of `f` at `x₀` to ensure `∑ e ∈ t, f e = 0`. let f : M → R := fun z ↦ if z = x₀ then -∑ z ∈ t.erase x₀, g (z - x₀) else g (z - x₀) refine ⟨f, ?_, ?_, ?_⟩ -- After this, it's a matter of verifying the properties, -- based on the corresponding properties for `g`. · rw [sum_map, Embedding.coeFn_mk] at gsum simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, neg_smul, sum_smul, ← sub_eq_add_neg, ← sum_sub_distrib, ← gsum, smul_sub] refine sum_congr rfl fun x x_mem ↦ ?_ rw [if_neg (mem_erase.mp x_mem).1] · simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, add_neg_eq_zero] exact sum_congr rfl fun x x_mem ↦ if_neg (mem_erase.mp x_mem).1 · obtain ⟨x₁, x₁_mem', rfl⟩ := Finset.mem_map.mp x₁_mem have := mem_erase.mp x₁_mem' exact ⟨x₁, by simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]⟩ end end Finite section FinrankZero section variable [Nontrivial R] /-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/ @[nontriviality] theorem Module.finrank_zero_of_subsingleton [Subsingleton M] : finrank R M = 0 := by rw [finrank, rank_subsingleton', map_zero] lemma LinearIndependent.finrank_eq_zero_of_infinite {ι} [Infinite ι] {v : ι → M} (hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank section variable [NoZeroSMulDivisors R M] /-- A finite dimensional space is nontrivial if it has positive `finrank`. -/ theorem Module.nontrivial_of_finrank_pos (h : 0 < finrank R M) : Nontrivial M := rank_pos_iff_nontrivial.mp (lt_rank_of_lt_finrank h) /-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a natural number. -/ theorem Module.nontrivial_of_finrank_eq_succ {n : ℕ} (hn : finrank R M = n.succ) : Nontrivial M := nontrivial_of_finrank_pos (R := R) (by rw [hn]; exact n.succ_pos) end variable (R M) @[simp] theorem finrank_bot : finrank R (⊥ : Submodule R M) = 0 := finrank_eq_of_rank_eq (rank_bot _ _) end section StrongRankCondition variable [StrongRankCondition R] [Module.Finite R M] /-- A finite rank torsion-free module has positive `finrank` iff it has a nonzero element. -/ theorem Module.finrank_pos_iff_exists_ne_zero [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ ∃ x : M, x ≠ 0 := by rw [← @rank_pos_iff_exists_ne_zero R M, ← finrank_eq_rank] norm_cast /-- An `R`-finite torsion-free module has positive `finrank` iff it is nontrivial. -/ theorem Module.finrank_pos_iff [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ Nontrivial M := by rw [← rank_pos_iff_nontrivial (R := R), ← finrank_eq_rank] norm_cast /-- A nontrivial finite dimensional space has positive `finrank`. -/ theorem Module.finrank_pos [NoZeroSMulDivisors R M] [h : Nontrivial M] : 0 < finrank R M := finrank_pos_iff.mpr h /-- See `Module.finrank_zero_iff` for the stronger version with `NoZeroSMulDivisors R M`. -/ theorem Module.finrank_eq_zero_iff : finrank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by rw [← rank_eq_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- A finite dimensional space has zero `finrank` iff it is a subsingleton. This is the `finrank` version of `rank_zero_iff`. -/ theorem Module.finrank_zero_iff [NoZeroSMulDivisors R M] : finrank R M = 0 ↔ Subsingleton M := by rw [← rank_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- Similar to `rank_quotient_add_rank_le` but for `finrank` and a finite `M`. -/ lemma Module.finrank_quotient_add_finrank_le (N : Submodule R M) : finrank R (M ⧸ N) + finrank R N ≤ finrank R M := by haveI := nontrivial_of_invariantBasisNumber R have := rank_quotient_add_rank_le N rw [← finrank_eq_rank R M, ← finrank_eq_rank R, ← N.finrank_eq_rank] at this exact mod_cast this end StrongRankCondition theorem Module.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R M = 0) : finrank R M = 0 := by delta finrank rw [h, zero_toNat] theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : (⊥ : Submodule R M) = ⊤ := by nontriviality R rw [rank_zero_iff] at h subsingleton /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. -/ @[simp] theorem Submodule.rank_eq_zero [Nontrivial R] [NoZeroSMulDivisors R M] {S : Submodule R M} : Module.rank R S = 0 ↔ S = ⊥ := ⟨fun h => (Submodule.eq_bot_iff _).2 fun x hx => congr_arg Subtype.val <| ((Submodule.eq_bot_iff _).1 <| Eq.symm <| Submodule.bot_eq_top_of_rank_eq_zero h) ⟨x, hx⟩ Submodule.mem_top, fun h => by rw [h, rank_bot]⟩ @[simp] theorem Submodule.finrank_eq_zero [StrongRankCondition R] [NoZeroSMulDivisors R M] {S : Submodule R M} [Module.Finite R S] : finrank R S = 0 ↔ S = ⊥ := by rw [← Submodule.rank_eq_zero, ← finrank_eq_rank, ← @Nat.cast_zero Cardinal, Nat.cast_inj] @[simp] lemma Submodule.one_le_finrank_iff [StrongRankCondition R] [NoZeroSMulDivisors R M] {S : Submodule R M} [Module.Finite R S] : 1 ≤ finrank R S ↔ S ≠ ⊥ := by simp [← not_iff_not] variable [Module.Free R M] theorem finrank_eq_zero_of_basis_imp_not_finite (h : ∀ s : Set M, Basis.{v} (s : Set M) R M → ¬s.Finite) : finrank R M = 0 := by cases subsingleton_or_nontrivial R · have := Module.subsingleton R M exact (h ∅ ⟨LinearEquiv.ofSubsingleton _ _⟩ Set.finite_empty).elim obtain ⟨_, ⟨b⟩⟩ := (Module.free_iff_set R M).mp ‹_› have := Set.Infinite.to_subtype (h _ b) exact b.linearIndependent.finrank_eq_zero_of_infinite theorem finrank_eq_zero_of_basis_imp_false (h : ∀ s : Finset M, Basis.{v} (s : Set M) R M → False) : finrank R M = 0 := finrank_eq_zero_of_basis_imp_not_finite fun s b hs => h hs.toFinset (by convert b simp) theorem finrank_eq_zero_of_not_exists_basis (h : ¬∃ s : Finset M, Nonempty (Basis (s : Set M) R M)) : finrank R M = 0 := finrank_eq_zero_of_basis_imp_false fun s b => h ⟨s, ⟨b⟩⟩ theorem finrank_eq_zero_of_not_exists_basis_finite (h : ¬∃ (s : Set M) (_ : Basis.{v} (s : Set M) R M), s.Finite) : finrank R M = 0 := finrank_eq_zero_of_basis_imp_not_finite fun s b hs => h ⟨s, b, hs⟩ theorem finrank_eq_zero_of_not_exists_basis_finset (h : ¬∃ s : Finset M, Nonempty (Basis s R M)) : finrank R M = 0 := finrank_eq_zero_of_basis_imp_false fun s b => h ⟨s, ⟨b⟩⟩ end FinrankZero section RankOne variable [NoZeroSMulDivisors R M] [StrongRankCondition R] /-- If there is a nonzero vector and every other vector is a multiple of it, then the module has dimension one. -/ theorem rank_eq_one (v : M) (n : v ≠ 0) (h : ∀ w : M, ∃ c : R, c • v = w) : Module.rank R M = 1 := by haveI := nontrivial_of_invariantBasisNumber R obtain ⟨b⟩ := (Basis.basis_singleton_iff.{_, _, u} PUnit).mpr ⟨v, n, h⟩ rw [rank_eq_card_basis b, Fintype.card_punit, Nat.cast_one] /-- If there is a nonzero vector and every other vector is a multiple of it, then the module has dimension one. -/ theorem finrank_eq_one (v : M) (n : v ≠ 0) (h : ∀ w : M, ∃ c : R, c • v = w) : finrank R M = 1 := finrank_eq_of_rank_eq (rank_eq_one v n h) /-- If every vector is a multiple of some `v : M`, then `M` has dimension at most one. -/ theorem finrank_le_one (v : M) (h : ∀ w : M, ∃ c : R, c • v = w) : finrank R M ≤ 1 := by haveI := nontrivial_of_invariantBasisNumber R rcases eq_or_ne v 0 with (rfl | hn) · haveI := _root_.subsingleton_of_forall_eq (0 : M) fun w => by obtain ⟨c, rfl⟩ := h w simp rw [finrank_zero_of_subsingleton] exact zero_le_one · exact (finrank_eq_one v hn h).le end RankOne
namespace Module variable {ι : Type*} @[simp] lemma finite_finsupp_iff : Module.Finite R (ι →₀ M) ↔ IsEmpty ι ∨ Subsingleton M ∨ Module.Finite R M ∧ Finite ι where mp := by simp only [or_iff_not_imp_left, not_subsingleton_iff_nontrivial, not_isEmpty_iff] rintro h ⟨i⟩ _ obtain ⟨s, hs⟩ := id h
Mathlib/LinearAlgebra/Dimension/Finite.lean
549
558
/- 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.Vector.Defs import Mathlib.Data.List.Nodup import Mathlib.Data.List.OfFn import Mathlib.Data.List.Scan import Mathlib.Control.Applicative import Mathlib.Control.Traversable.Basic import Mathlib.Algebra.BigOperators.Group.List.Basic /-! # Additional theorems and definitions about the `Vector` type This file introduces the infix notation `::ᵥ` for `Vector.cons`. -/ universe u variable {α β γ σ φ : Type*} {m n : ℕ} namespace List.Vector @[inherit_doc] infixr:67 " ::ᵥ " => Vector.cons attribute [simp] head_cons tail_cons instance [Inhabited α] : Inhabited (Vector α n) := ⟨ofFn default⟩ theorem toList_injective : Function.Injective (@toList α n) := Subtype.val_injective /-- Two `v w : Vector α n` are equal iff they are equal at every single index. -/ @[ext] theorem ext : ∀ {v w : Vector α n} (_ : ∀ m : Fin n, Vector.get v m = Vector.get w m), v = w | ⟨v, hv⟩, ⟨w, hw⟩, h => Subtype.eq (List.ext_get (by rw [hv, hw]) fun m hm _ => h ⟨m, hv ▸ hm⟩) /-- The empty `Vector` is a `Subsingleton`. -/ instance zero_subsingleton : Subsingleton (Vector α 0) := ⟨fun _ _ => Vector.ext fun m => Fin.elim0 m⟩ @[simp] theorem cons_val (a : α) : ∀ v : Vector α n, (a ::ᵥ v).val = a :: v.val | ⟨_, _⟩ => rfl theorem eq_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) : v = a ::ᵥ v' ↔ v.head = a ∧ v.tail = v' := ⟨fun h => h.symm ▸ ⟨head_cons a v', tail_cons a v'⟩, fun h => _root_.trans (cons_head_tail v).symm (by rw [h.1, h.2])⟩ theorem ne_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) : v ≠ a ::ᵥ v' ↔ v.head ≠ a ∨ v.tail ≠ v' := by rw [Ne, eq_cons_iff a v v', not_and_or] theorem exists_eq_cons (v : Vector α n.succ) : ∃ (a : α) (as : Vector α n), v = a ::ᵥ as := ⟨v.head, v.tail, (eq_cons_iff v.head v v.tail).2 ⟨rfl, rfl⟩⟩ @[simp] theorem toList_ofFn : ∀ {n} (f : Fin n → α), toList (ofFn f) = List.ofFn f | 0, f => by rw [ofFn, List.ofFn_zero, toList, nil] | n + 1, f => by rw [ofFn, List.ofFn_succ, toList_cons, toList_ofFn] @[simp] theorem mk_toList : ∀ (v : Vector α n) (h), (⟨toList v, h⟩ : Vector α n) = v | ⟨_, _⟩, _ => rfl @[simp] theorem length_val (v : Vector α n) : v.val.length = n := v.2 @[simp] theorem pmap_cons {p : α → Prop} (f : (a : α) → p a → β) (a : α) (v : Vector α n) (hp : ∀ x ∈ (cons a v).toList, p x) : (cons a v).pmap f hp = cons (f a (by simp only [Nat.succ_eq_add_one, toList_cons, List.mem_cons, forall_eq_or_imp] at hp exact hp.1)) (v.pmap f (by simp only [Nat.succ_eq_add_one, toList_cons, List.mem_cons, forall_eq_or_imp] at hp exact hp.2)) := rfl /-- Opposite direction of `Vector.pmap_cons` -/ theorem pmap_cons' {p : α → Prop} (f : (a : α) → p a → β) (a : α) (v : Vector α n) (ha : p a) (hp : ∀ x ∈ v.toList, p x) : cons (f a ha) (v.pmap f hp) = (cons a v).pmap f (by simpa [ha]) := rfl @[simp] theorem toList_map {β : Type*} (v : Vector α n) (f : α → β) : (v.map f).toList = v.toList.map f := by cases v; rfl @[simp] theorem head_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).head = f v.head := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v rw [h, map_cons, head_cons, head_cons] @[simp] theorem tail_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).tail = v.tail.map f := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v rw [h, map_cons, tail_cons, tail_cons] @[simp] theorem getElem_map {β : Type*} (v : Vector α n) (f : α → β) {i : ℕ} (hi : i < n) : (v.map f)[i] = f v[i] := by simp only [getElem_def, toList_map, List.getElem_map] @[simp] theorem toList_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α n) (hp : ∀ x ∈ v.toList, p x) : (v.pmap f hp).toList = v.toList.pmap f hp := by cases v; rfl @[simp] theorem head_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α (n + 1)) (hp : ∀ x ∈ v.toList, p x) : (v.pmap f hp).head = f v.head (hp _ <| by rw [← cons_head_tail v, toList_cons, head_cons, List.mem_cons]; exact .inl rfl) := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v simp_rw [h, pmap_cons, head_cons] @[simp] theorem tail_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α (n + 1)) (hp : ∀ x ∈ v.toList, p x) : (v.pmap f hp).tail = v.tail.pmap f (fun x hx ↦ hp _ <| by rw [← cons_head_tail v, toList_cons, List.mem_cons]; exact .inr hx) := by obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v simp_rw [h, pmap_cons, tail_cons] @[simp] theorem getElem_pmap {p : α → Prop} (f : (a : α) → p a → β) (v : Vector α n) (hp : ∀ x ∈ v.toList, p x) {i : ℕ} (hi : i < n) : (v.pmap f hp)[i] = f v[i] (hp _ (by simp [getElem_def, List.getElem_mem])) := by simp only [getElem_def, toList_pmap, List.getElem_pmap] theorem get_eq_get_toList (v : Vector α n) (i : Fin n) : v.get i = v.toList.get (Fin.cast v.toList_length.symm i) := rfl @[deprecated (since := "2024-12-20")] alias get_eq_get := get_eq_get_toList @[simp] theorem get_replicate (a : α) (i : Fin n) : (Vector.replicate n a).get i = a := by apply List.getElem_replicate @[simp] theorem get_map {β : Type*} (v : Vector α n) (f : α → β) (i : Fin n) : (v.map f).get i = f (v.get i) := by cases v; simp [Vector.map, get_eq_get_toList] @[simp] theorem map₂_nil (f : α → β → γ) : Vector.map₂ f nil nil = nil := rfl @[simp] theorem map₂_cons (hd₁ : α) (tl₁ : Vector α n) (hd₂ : β) (tl₂ : Vector β n) (f : α → β → γ) : Vector.map₂ f (hd₁ ::ᵥ tl₁) (hd₂ ::ᵥ tl₂) = f hd₁ hd₂ ::ᵥ (Vector.map₂ f tl₁ tl₂) := rfl @[simp] theorem get_ofFn {n} (f : Fin n → α) (i) : get (ofFn f) i = f i := by conv_rhs => erw [← List.get_ofFn f ⟨i, by simp⟩] simp only [get_eq_get_toList] congr <;> simp [Fin.heq_ext_iff] @[simp] theorem ofFn_get (v : Vector α n) : ofFn (get v) = v := by rcases v with ⟨l, rfl⟩ apply toList_injective dsimp simpa only [toList_ofFn] using List.ofFn_get _ /-- The natural equivalence between length-`n` vectors and functions from `Fin n`. -/ def _root_.Equiv.vectorEquivFin (α : Type*) (n : ℕ) : Vector α n ≃ (Fin n → α) := ⟨Vector.get, Vector.ofFn, Vector.ofFn_get, fun f => funext <| Vector.get_ofFn f⟩ theorem get_tail (x : Vector α n) (i) : x.tail.get i = x.get ⟨i.1 + 1, by omega⟩ := by obtain ⟨i, ih⟩ := i; dsimp rcases x with ⟨_ | _, h⟩ <;> try rfl rw [List.length] at h rw [← h] at ih contradiction @[simp] theorem get_tail_succ : ∀ (v : Vector α n.succ) (i : Fin n), get (tail v) i = get v i.succ | ⟨a :: l, e⟩, ⟨i, h⟩ => by simp [get_eq_get_toList]; rfl @[simp] theorem tail_val : ∀ v : Vector α n.succ, v.tail.val = v.val.tail | ⟨_ :: _, _⟩ => rfl /-- The `tail` of a `nil` vector is `nil`. -/ @[simp] theorem tail_nil : (@nil α).tail = nil := rfl /-- The `tail` of a vector made up of one element is `nil`. -/ @[simp] theorem singleton_tail : ∀ (v : Vector α 1), v.tail = Vector.nil | ⟨[_], _⟩ => rfl @[simp] theorem tail_ofFn {n : ℕ} (f : Fin n.succ → α) : tail (ofFn f) = ofFn fun i => f i.succ := (ofFn_get _).symm.trans <| by congr funext i rw [get_tail, get_ofFn] rfl @[simp] theorem toList_empty (v : Vector α 0) : v.toList = [] := List.length_eq_zero_iff.mp v.2 /-- The list that makes up a `Vector` made up of a single element, retrieved via `toList`, is equal to the list of that single element. -/ @[simp] theorem toList_singleton (v : Vector α 1) : v.toList = [v.head] := by rw [← v.cons_head_tail] simp only [toList_cons, toList_nil, head_cons, eq_self_iff_true, and_self_iff, singleton_tail] @[simp] theorem empty_toList_eq_ff (v : Vector α (n + 1)) : v.toList.isEmpty = false := match v with | ⟨_ :: _, _⟩ => rfl theorem not_empty_toList (v : Vector α (n + 1)) : ¬v.toList.isEmpty := by simp only [empty_toList_eq_ff, Bool.coe_sort_false, not_false_iff] /-- Mapping under `id` does not change a vector. -/ @[simp] theorem map_id {n : ℕ} (v : Vector α n) : Vector.map id v = v := Vector.eq _ _ (by simp only [List.map_id, Vector.toList_map]) theorem nodup_iff_injective_get {v : Vector α n} : v.toList.Nodup ↔ Function.Injective v.get := by obtain ⟨l, hl⟩ := v subst hl exact List.nodup_iff_injective_get theorem head?_toList : ∀ v : Vector α n.succ, (toList v).head? = some (head v) | ⟨_ :: _, _⟩ => rfl /-- Reverse a vector. -/ def reverse (v : Vector α n) : Vector α n := ⟨v.toList.reverse, by simp⟩ /-- The `List` of a vector after a `reverse`, retrieved by `toList` is equal to the `List.reverse` after retrieving a vector's `toList`. -/ theorem toList_reverse {v : Vector α n} : v.reverse.toList = v.toList.reverse := rfl @[simp] theorem reverse_reverse {v : Vector α n} : v.reverse.reverse = v := by cases v simp [Vector.reverse] @[simp] theorem get_zero : ∀ v : Vector α n.succ, get v 0 = head v | ⟨_ :: _, _⟩ => rfl @[simp] theorem head_ofFn {n : ℕ} (f : Fin n.succ → α) : head (ofFn f) = f 0 := by rw [← get_zero, get_ofFn] theorem get_cons_zero (a : α) (v : Vector α n) : get (a ::ᵥ v) 0 = a := by simp [get_zero] /-- Accessing the nth element of a vector made up of one element `x : α` is `x` itself. -/ @[simp] theorem get_cons_nil : ∀ {ix : Fin 1} (x : α), get (x ::ᵥ nil) ix = x | ⟨0, _⟩, _ => rfl @[simp] theorem get_cons_succ (a : α) (v : Vector α n) (i : Fin n) : get (a ::ᵥ v) i.succ = get v i := by rw [← get_tail_succ, tail_cons] /-- The last element of a `Vector`, given that the vector is at least one element. -/ def last (v : Vector α (n + 1)) : α := v.get (Fin.last n) /-- The last element of a `Vector`, given that the vector is at least one element. -/ theorem last_def {v : Vector α (n + 1)} : v.last = v.get (Fin.last n) := rfl /-- The `last` element of a vector is the `head` of the `reverse` vector. -/ theorem reverse_get_zero {v : Vector α (n + 1)} : v.reverse.head = v.last := by rw [← get_zero, last_def, get_eq_get_toList, get_eq_get_toList] simp_rw [toList_reverse] rw [List.get_eq_getElem, List.get_eq_getElem, ← Option.some_inj, Fin.cast, Fin.cast, ← List.getElem?_eq_getElem, ← List.getElem?_eq_getElem, List.getElem?_reverse] · congr simp · simp section Scan variable {β : Type*} variable (f : β → α → β) (b : β) variable (v : Vector α n) /-- Construct a `Vector β (n + 1)` from a `Vector α n` by scanning `f : β → α → β` from the "left", that is, from 0 to `Fin.last n`, using `b : β` as the starting value. -/ def scanl : Vector β (n + 1) := ⟨List.scanl f b v.toList, by rw [List.length_scanl, toList_length]⟩ /-- Providing an empty vector to `scanl` gives the starting value `b : β`. -/ @[simp] theorem scanl_nil : scanl f b nil = b ::ᵥ nil := rfl /-- The recursive step of `scanl` splits a vector `x ::ᵥ v : Vector α (n + 1)` into the provided starting value `b : β` and the recursed `scanl` `f b x : β` as the starting value. This lemma is the `cons` version of `scanl_get`. -/ @[simp] theorem scanl_cons (x : α) : scanl f b (x ::ᵥ v) = b ::ᵥ scanl f (f b x) v := by simp only [scanl, toList_cons, List.scanl]; dsimp simp only [cons] /-- The underlying `List` of a `Vector` after a `scanl` is the `List.scanl` of the underlying `List` of the original `Vector`. -/ @[simp] theorem scanl_val : ∀ {v : Vector α n}, (scanl f b v).val = List.scanl f b v.val | _ => rfl /-- The `toList` of a `Vector` after a `scanl` is the `List.scanl` of the `toList` of the original `Vector`. -/ @[simp] theorem toList_scanl : (scanl f b v).toList = List.scanl f b v.toList := rfl /-- The recursive step of `scanl` splits a vector made up of a single element `x ::ᵥ nil : Vector α 1` into a `Vector` of the provided starting value `b : β` and the mapped `f b x : β` as the last value. -/ @[simp] theorem scanl_singleton (v : Vector α 1) : scanl f b v = b ::ᵥ f b v.head ::ᵥ nil := by rw [← cons_head_tail v] simp only [scanl_cons, scanl_nil, head_cons, singleton_tail] /-- The first element of `scanl` of a vector `v : Vector α n`, retrieved via `head`, is the starting value `b : β`. -/ @[simp] theorem scanl_head : (scanl f b v).head = b := by cases n · have : v = nil := by simp only [eq_iff_true_of_subsingleton] simp only [this, scanl_nil, head_cons] · rw [← cons_head_tail v] simp [← get_zero, get_eq_get_toList] /-- For an index `i : Fin n`, the nth element of `scanl` of a vector `v : Vector α n` at `i.succ`, is equal to the application function `f : β → α → β` of the `castSucc i` element of `scanl f b v` and `get v i`. This lemma is the `get` version of `scanl_cons`. -/ @[simp] theorem scanl_get (i : Fin n) : (scanl f b v).get i.succ = f ((scanl f b v).get (Fin.castSucc i)) (v.get i) := by rcases n with - | n · exact i.elim0 induction' n with n hn generalizing b · have i0 : i = 0 := Fin.eq_zero _ simp [scanl_singleton, i0, get_zero]; simp [get_eq_get_toList, List.get] · rw [← cons_head_tail v, scanl_cons, get_cons_succ] refine Fin.cases ?_ ?_ i · simp only [get_zero, scanl_head, Fin.castSucc_zero, head_cons] · intro i' simp only [hn, Fin.castSucc_fin_succ, get_cons_succ] end Scan /-- Monadic analog of `Vector.ofFn`. Given a monadic function on `Fin n`, return a `Vector α n` inside the monad. -/ def mOfFn {m} [Monad m] {α : Type u} : ∀ {n}, (Fin n → m α) → m (Vector α n) | 0, _ => pure nil | _ + 1, f => do let a ← f 0 let v ← mOfFn fun i => f i.succ pure (a ::ᵥ v) theorem mOfFn_pure {m} [Monad m] [LawfulMonad m] {α} : ∀ {n} (f : Fin n → α), (@mOfFn m _ _ _ fun i => pure (f i)) = pure (ofFn f) | 0, _ => rfl | n + 1, f => by rw [mOfFn, @mOfFn_pure m _ _ _ n _, ofFn] simp /-- Apply a monadic function to each component of a vector, returning a vector inside the monad. -/ def mmap {m} [Monad m] {α} {β : Type u} (f : α → m β) : ∀ {n}, Vector α n → m (Vector β n) | 0, _ => pure nil | _ + 1, xs => do let h' ← f xs.head let t' ← mmap f xs.tail pure (h' ::ᵥ t') @[simp] theorem mmap_nil {m} [Monad m] {α β} (f : α → m β) : mmap f nil = pure nil := rfl @[simp] theorem mmap_cons {m} [Monad m] {α β} (f : α → m β) (a) : ∀ {n} (v : Vector α n), mmap f (a ::ᵥ v) = do let h' ← f a let t' ← mmap f v pure (h' ::ᵥ t') | _, ⟨_, rfl⟩ => rfl /-- Define `C v` by induction on `v : Vector α n`. This function has two arguments: `nil` handles the base case on `C nil`, and `cons` defines the inductive step using `∀ x : α, C w → C (x ::ᵥ w)`. It is used as the default induction principle for the `induction` tactic. -/ @[elab_as_elim, induction_eliminator] def inductionOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n) (nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : C v := by induction' n with n ih · rcases v with ⟨_ | ⟨-, -⟩, - | -⟩ exact nil · rcases v with ⟨_ | ⟨a, v⟩, v_property⟩ cases v_property exact cons (ih ⟨v, (add_left_inj 1).mp v_property⟩) @[simp] theorem inductionOn_nil {C : ∀ {n : ℕ}, Vector α n → Sort*} (nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : Vector.nil.inductionOn nil cons = nil := rfl @[simp] theorem inductionOn_cons {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (x : α) (v : Vector α n) (nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : (x ::ᵥ v).inductionOn nil cons = cons (v.inductionOn nil cons : C v) := rfl variable {β γ : Type*} /-- Define `C v w` by induction on a pair of vectors `v : Vector α n` and `w : Vector β n`. -/ @[elab_as_elim] def inductionOn₂ {C : ∀ {n}, Vector α n → Vector β n → Sort*} (v : Vector α n) (w : Vector β n) (nil : C nil nil) (cons : ∀ {n a b} {x : Vector α n} {y}, C x y → C (a ::ᵥ x) (b ::ᵥ y)) : C v w := by induction' n with n ih · rcases v with ⟨_ | ⟨-, -⟩, - | -⟩ rcases w with ⟨_ | ⟨-, -⟩, - | -⟩ exact nil · rcases v with ⟨_ | ⟨a, v⟩, v_property⟩ cases v_property rcases w with ⟨_ | ⟨b, w⟩, w_property⟩ cases w_property apply @cons n _ _ ⟨v, (add_left_inj 1).mp v_property⟩ ⟨w, (add_left_inj 1).mp w_property⟩ apply ih /-- Define `C u v w` by induction on a triplet of vectors `u : Vector α n`, `v : Vector β n`, and `w : Vector γ b`. -/ @[elab_as_elim] def inductionOn₃ {C : ∀ {n}, Vector α n → Vector β n → Vector γ n → Sort*} (u : Vector α n) (v : Vector β n) (w : Vector γ n) (nil : C nil nil nil) (cons : ∀ {n a b c} {x : Vector α n} {y z}, C x y z → C (a ::ᵥ x) (b ::ᵥ y) (c ::ᵥ z)) : C u v w := by induction' n with n ih · rcases u with ⟨_ | ⟨-, -⟩, - | -⟩ rcases v with ⟨_ | ⟨-, -⟩, - | -⟩ rcases w with ⟨_ | ⟨-, -⟩, - | -⟩ exact nil · rcases u with ⟨_ | ⟨a, u⟩, u_property⟩ cases u_property rcases v with ⟨_ | ⟨b, v⟩, v_property⟩ cases v_property rcases w with ⟨_ | ⟨c, w⟩, w_property⟩ cases w_property apply @cons n _ _ _ ⟨u, (add_left_inj 1).mp u_property⟩ ⟨v, (add_left_inj 1).mp v_property⟩ ⟨w, (add_left_inj 1).mp w_property⟩ apply ih /-- Define `motive v` by case-analysis on `v : Vector α n`. -/ def casesOn {motive : ∀ {n}, Vector α n → Sort*} (v : Vector α m) (nil : motive nil) (cons : ∀ {n}, (hd : α) → (tl : Vector α n) → motive (Vector.cons hd tl)) : motive v := inductionOn (C := motive) v nil @fun _ hd tl _ => cons hd tl /-- Define `motive v₁ v₂` by case-analysis on `v₁ : Vector α n` and `v₂ : Vector β n`. -/ def casesOn₂ {motive : ∀ {n}, Vector α n → Vector β n → Sort*} (v₁ : Vector α m) (v₂ : Vector β m) (nil : motive nil nil) (cons : ∀ {n}, (x : α) → (y : β) → (xs : Vector α n) → (ys : Vector β n) → motive (x ::ᵥ xs) (y ::ᵥ ys)) : motive v₁ v₂ := inductionOn₂ (C := motive) v₁ v₂ nil @fun _ x y xs ys _ => cons x y xs ys /-- Define `motive v₁ v₂ v₃` by case-analysis on `v₁ : Vector α n`, `v₂ : Vector β n`, and `v₃ : Vector γ n`. -/ def casesOn₃ {motive : ∀ {n}, Vector α n → Vector β n → Vector γ n → Sort*} (v₁ : Vector α m) (v₂ : Vector β m) (v₃ : Vector γ m) (nil : motive nil nil nil) (cons : ∀ {n}, (x : α) → (y : β) → (z : γ) → (xs : Vector α n) → (ys : Vector β n) → (zs : Vector γ n) → motive (x ::ᵥ xs) (y ::ᵥ ys) (z ::ᵥ zs)) : motive v₁ v₂ v₃ := inductionOn₃ (C := motive) v₁ v₂ v₃ nil @fun _ x y z xs ys zs _ => cons x y z xs ys zs /-- Cast a vector to an array. -/ def toArray : Vector α n → Array α | ⟨xs, _⟩ => cast (by rfl) xs.toArray section InsertIdx variable {a : α} /-- `v.insertIdx a i` inserts `a` into the vector `v` at position `i` (and shifting later components to the right). -/ def insertIdx (a : α) (i : Fin (n + 1)) (v : Vector α n) : Vector α (n + 1) := ⟨v.1.insertIdx i a, by rw [List.length_insertIdx, v.2] split <;> omega⟩ theorem insertIdx_val {i : Fin (n + 1)} {v : Vector α n} : (v.insertIdx a i).val = v.val.insertIdx i.1 a := rfl @[simp] theorem eraseIdx_val {i : Fin n} : ∀ {v : Vector α n}, (eraseIdx i v).val = v.val.eraseIdx i | _ => rfl theorem eraseIdx_insertIdx {v : Vector α n} {i : Fin (n + 1)} : eraseIdx i (insertIdx a i v) = v := Subtype.eq (List.eraseIdx_insertIdx ..) /-- Erasing an element after inserting an element, at different indices. -/ theorem eraseIdx_insertIdx' {v : Vector α (n + 1)} : ∀ {i : Fin (n + 1)} {j : Fin (n + 2)}, eraseIdx (j.succAbove i) (insertIdx a j v) = insertIdx a (i.predAbove j) (eraseIdx i v) | ⟨i, hi⟩, ⟨j, hj⟩ => by dsimp [insertIdx, eraseIdx, Fin.succAbove, Fin.predAbove] rw [Subtype.mk_eq_mk] simp only [Fin.lt_iff_val_lt_val] split_ifs with hij · rcases Nat.exists_eq_succ_of_ne_zero (Nat.pos_iff_ne_zero.1 (lt_of_le_of_lt (Nat.zero_le _) hij)) with ⟨j, rfl⟩ rw [← List.insertIdx_eraseIdx_of_ge] · simp; rfl · simpa · simpa [Nat.lt_succ_iff] using hij · dsimp rw [← List.insertIdx_eraseIdx_of_le] · rfl · simpa · simpa [not_lt] using hij theorem insertIdx_comm (a b : α) (i j : Fin (n + 1)) (h : i ≤ j) : ∀ v : Vector α n, (v.insertIdx a i).insertIdx b j.succ = (v.insertIdx b j).insertIdx a (Fin.castSucc i) | ⟨l, hl⟩ => by refine Subtype.eq ?_ simp only [insertIdx_val, Fin.val_succ, Fin.castSucc, Fin.coe_castAdd] apply List.insertIdx_comm · assumption · rw [hl] exact Nat.le_of_succ_le_succ j.2 end InsertIdx section Set /-- `set v n a` replaces the `n`th element of `v` with `a`. -/ def set (v : Vector α n) (i : Fin n) (a : α) : Vector α n := ⟨v.1.set i.1 a, by simp⟩ @[simp] theorem toList_set (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).toList = v.toList.set i a := rfl @[simp] theorem get_set_same (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).get i = a := by cases v; cases i; simp [Vector.set, get_eq_get_toList] theorem get_set_of_ne {v : Vector α n} {i j : Fin n} (h : i ≠ j) (a : α) : (v.set i a).get j = v.get j := by cases v; cases i; cases j simp only [get_eq_get_toList, toList_set, toList_mk, Fin.cast_mk, List.get_eq_getElem] rw [List.getElem_set_of_ne] · simpa using h theorem get_set_eq_if {v : Vector α n} {i j : Fin n} (a : α) : (v.set i a).get j = if i = j then a else v.get j := by split_ifs <;> (try simp [*]); rwa [get_set_of_ne] @[to_additive] theorem prod_set [Monoid α] (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).toList.prod = (v.take i).toList.prod * a * (v.drop (i + 1)).toList.prod := by
refine (List.prod_set v.toList i a).trans ?_ simp_all /-- Variant of `List.Vector.prod_set` that multiplies by the inverse of the replaced element -/ @[to_additive "Variant of `List.Vector.sum_set` that subtracts the inverse of the replaced element"] theorem prod_set' [CommGroup α] (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).toList.prod = v.toList.prod * (v.get i)⁻¹ * a := by refine (List.prod_set' v.toList i a).trans ?_ simp [get_eq_get_toList, mul_assoc]
Mathlib/Data/Vector/Basic.lean
604
613
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.NonUnitalSubsemiring.Basic /-! # More operations on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations` universe u v w x open Pointwise namespace Submodule lemma coe_span_smul {R' M' : Type*} [CommSemiring R'] [AddCommMonoid M'] [Module R' M'] (s : Set R') (N : Submodule R' M') : (Ideal.span s : Set R') • N = s • N := set_smul_eq_of_le _ _ _ (by rintro r n hr hn induction hr using Submodule.span_induction with | mem _ h => exact mem_set_smul_of_mem_mem h hn | zero => rw [zero_smul]; exact Submodule.zero_mem _ | add _ _ _ _ ihr ihs => rw [add_smul]; exact Submodule.add_mem _ ihr ihs | smul _ _ hr => rw [mem_span_set] at hr obtain ⟨c, hc, rfl⟩ := hr rw [Finsupp.sum, Finset.smul_sum, Finset.sum_smul] refine Submodule.sum_mem _ fun i hi => ?_ rw [← mul_smul, smul_eq_mul, mul_comm, mul_smul] exact mem_set_smul_of_mem_mem (hc hi) <| Submodule.smul_mem _ _ hn) <| set_smul_mono_left _ Submodule.subset_span lemma span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) : (span ℤ {a}).toAddSubgroup = AddSubgroup.zmultiples a := by ext i simp [Ideal.mem_span_singleton', AddSubgroup.mem_zmultiples_iff] @[simp] lemma _root_.Ideal.span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) : (Ideal.span {a}).toAddSubgroup = AddSubgroup.zmultiples a := Submodule.span_singleton_toAddSubgroup_eq_zmultiples _ variable {R : Type u} {M : Type v} {M' F G : Type*} section Semiring variable [Semiring R] [AddCommMonoid M] [Module R M] /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl variable {I J : Ideal R} {N : Submodule R M} theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ ↦ N.smul_mem r theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top variable (I J N) @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri protected theorem mul_smul : (I * J) • N = I • J • N := Submodule.smul_assoc _ _ _ theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices LinearMap.range (LinearMap.toSpanSingleton R M x) ≤ M' by rw [← LinearMap.toSpanSingleton_one R M x] exact this (LinearMap.mem_range_self _ 1) rw [LinearMap.range_eq_map, ← hs, map_le_iff_le_comap, Ideal.span, span_le] exact fun r hr ↦ H ⟨r, hr⟩ variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] simp [← this, -map_smul''] @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx end Semiring section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri _ hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨_, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ variable {I J : Ideal R} {N P : Submodule R M} variable (S : Set R) (T : Set M) theorem smul_eq_map₂ : I • N = Submodule.map₂ (LinearMap.lsmul R M) I N := le_antisymm (smul_le.mpr fun _m hm _n ↦ Submodule.apply_mem_map₂ _ hm) (map₂_le.mpr fun _m hm _n ↦ smul_mem_smul hm) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := by rw [smul_eq_map₂] exact (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by choose f hf using H apply M'.mem_of_span_top_of_smul_mem _ (Ideal.span_range_pow_eq_top s hs f) rintro ⟨_, r, hr, rfl⟩ exact hf r open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] simp variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction ?_ ?_ ?_ ?_ (mem_smul_span.mp hx) · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y - - ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x - ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl @[simp] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl end Add section Semiring variable {R : Type u} [Semiring R] {I J K L : Ideal R} @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by rw [Submodule.one_eq_span, ← Ideal.span, Ideal.span_singleton_one] theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le theorem mul_le_left : I * J ≤ J := mul_le.2 fun _ _ _ => J.mul_mem_left _ @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 mul_le_left @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 mul_le_left theorem mul_le_right [I.IsTwoSided] : I * J ≤ I := mul_le.2 fun _ hr _ _ ↦ I.mul_mem_right _ hr @[simp] theorem sup_mul_right_self [I.IsTwoSided] : I ⊔ I * J = I := sup_eq_left.2 mul_le_right @[simp] theorem mul_right_self_sup [I.IsTwoSided] : I * J ⊔ I = I := sup_eq_right.2 mul_le_right protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K variable (I) theorem mul_bot : I * ⊥ = ⊥ := by simp theorem bot_mul : ⊥ * I = ⊥ := by simp @[simp] theorem top_mul : ⊤ * I = I := Submodule.top_smul I variable {I} theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L := Submodule.smul_mono hik hjl theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K := Submodule.smul_mono_left h theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K := smul_mono_right I h variable (I J K) theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K := Submodule.smul_sup I J K theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K := Submodule.sup_smul I J K variable {I J K} theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by obtain _ | m := m · rw [Submodule.pow_zero, one_eq_top]; exact le_top obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h rw [add_comm, Submodule.pow_add _ m.add_one_ne_zero] exact mul_le_left theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I := calc I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn) _ = I := Submodule.pow_one _ theorem pow_right_mono (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by induction' n with _ hn · rw [Submodule.pow_zero, Submodule.pow_zero] · rw [Submodule.pow_succ, Submodule.pow_succ] exact Ideal.mul_mono hn e namespace IsTwoSided instance (priority := low) [J.IsTwoSided] : (I * J).IsTwoSided := ⟨fun b ha ↦ Submodule.mul_induction_on ha (fun i hi j hj ↦ by rw [mul_assoc]; exact mul_mem_mul hi (mul_mem_right _ _ hj)) fun x y hx hy ↦ by rw [right_distrib]; exact add_mem hx hy⟩ variable [I.IsTwoSided] (m n : ℕ) instance (priority := low) : (I ^ n).IsTwoSided := n.rec (by rw [Submodule.pow_zero, one_eq_top]; infer_instance) (fun _ _ ↦ by rw [Submodule.pow_succ]; infer_instance) protected theorem mul_one : I * 1 = I := mul_le_right.antisymm fun i hi ↦ mul_one i ▸ mul_mem_mul hi (one_eq_top (R := R) ▸ Submodule.mem_top) protected theorem pow_add : I ^ (m + n) = I ^ m * I ^ n := by obtain rfl | h := eq_or_ne n 0 · rw [add_zero, Submodule.pow_zero, IsTwoSided.mul_one] · exact Submodule.pow_add _ h protected theorem pow_succ : I ^ (n + 1) = I * I ^ n := by rw [add_comm, IsTwoSided.pow_add, Submodule.pow_one] end IsTwoSided @[simp] theorem mul_eq_bot [NoZeroDivisors R] : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ := ⟨fun hij => or_iff_not_imp_left.mpr fun I_ne_bot => J.eq_bot_iff.mpr fun j hj => let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0, fun h => by obtain rfl | rfl := h; exacts [bot_mul _, mul_bot _]⟩ instance [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1 instance {S A : Type*} [Semiring S] [SMul R S] [AddCommMonoid A] [Module R A] [Module S A] [IsScalarTower R S A] [NoZeroSMulDivisors R A] {I : Submodule S A} : NoZeroSMulDivisors R I := Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I) theorem pow_eq_zero_of_mem {I : Ideal R} {n m : ℕ} (hnI : I ^ n = 0) (hmn : n ≤ m) {x : R} (hx : x ∈ I) : x ^ m = 0 := by simpa [hnI] using pow_le_pow_right hmn <| pow_mem_pow hx m end Semiring section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) lemma sup_pow_add_le_pow_sup_pow {n m : ℕ} : (I ⊔ J) ^ (n + m) ≤ I ^ n ⊔ J ^ m := by rw [← Ideal.add_eq_sup, ← Ideal.add_eq_sup, add_pow, Ideal.sum_eq_sup] apply Finset.sup_le intros i hi by_cases hn : n ≤ i · exact (Ideal.mul_le_right.trans (Ideal.mul_le_right.trans ((Ideal.pow_le_pow_right hn).trans le_sup_left))) · refine (Ideal.mul_le_right.trans (Ideal.mul_le_left.trans ((Ideal.pow_le_pow_right ?_).trans le_sup_right))) omega variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_left_mono hx] theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ => (span_singleton_mul_right_inj hx).mp theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective fun I : Ideal R => I * span {x} := fun _ _ => (span_singleton_mul_left_inj hx).mp theorem eq_span_singleton_mul {x : R} (I J : Ideal R) : I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff] theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) : span {x} * I = span {y} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm] theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) : (∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) := Submodule.prod_span s I theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) : (∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := Submodule.prod_span_singleton s I @[simp] theorem multiset_prod_span_singleton (m : Multiset R) : (m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) := Multiset.induction_on m (by simp) fun a m ih => by simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton] open scoped Function in -- required for scoped `on` notation theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) (hI : Set.Pairwise (↑s) (IsCoprime on I)) : (s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by ext x simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton] exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩ theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R} (hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) : ⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton] rwa [Finset.coe_univ, Set.pairwise_univ] theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι] {I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) : ⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by rw [iInf_span_singleton, Nat.cast_prod] exact fun i j h ↦ (hI h).cast theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) : span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by rw [eq_top_iff_one, Submodule.mem_sup] constructor · rintro ⟨u, hu, v, hv, h1⟩ rw [mem_span_singleton'] at hu hv rw [← hu.choose_spec, ← hv.choose_spec] at h1 exact ⟨_, _, h1⟩ · exact fun ⟨u, v, h1⟩ => ⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩ theorem mul_le_inf : I * J ≤ I ⊓ J := mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩ theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by classical refine s.induction_on ?_ ?_ · rw [Multiset.inf_zero] exact le_top intro a s ih rw [Multiset.prod_cons, Multiset.inf_cons] exact le_trans mul_le_inf (inf_le_inf le_rfl ih) theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f := multiset_prod_le_inf theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J := le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ => let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj) theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K := le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢ obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩ rw [add_assoc, ← add_mul, h, one_mul, hi] theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by rw [mul_comm] exact sup_mul_eq_of_coprime_left h
theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by rw [sup_comm] at h
Mathlib/RingTheory/Ideal/Operations.lean
571
573
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Ralf Stephan, Neil Strickland, Ruben Van de Velde -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Positive.Ring import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Algebra.Order.Sub.Basic import Mathlib.Data.PNat.Equiv /-! # The positive natural numbers This file develops the type `ℕ+` or `PNat`, the subtype of natural numbers that are positive. It is defined in `Data.PNat.Defs`, but most of the development is deferred to here so that `Data.PNat.Defs` can have very few imports. -/ deriving instance AddLeftCancelSemigroup, AddRightCancelSemigroup, AddCommSemigroup, Add, Mul, Distrib for PNat namespace PNat instance instCommMonoid : CommMonoid ℕ+ := Positive.commMonoid instance instIsOrderedCancelMonoid : IsOrderedCancelMonoid ℕ+ := Positive.isOrderedCancelMonoid instance instCancelCommMonoid : CancelCommMonoid ℕ+ := ⟨fun _ _ _ ↦ mul_left_cancel⟩ instance instWellFoundedLT : WellFoundedLT ℕ+ := WellFoundedRelation.isWellFounded @[simp] theorem one_add_natPred (n : ℕ+) : 1 + n.natPred = n := by rw [natPred, add_tsub_cancel_iff_le.mpr <| show 1 ≤ (n : ℕ) from n.2] @[simp] theorem natPred_add_one (n : ℕ+) : n.natPred + 1 = n := (add_comm _ _).trans n.one_add_natPred @[mono] theorem natPred_strictMono : StrictMono natPred := fun m _ h => Nat.pred_lt_pred m.2.ne' h @[mono] theorem natPred_monotone : Monotone natPred := natPred_strictMono.monotone theorem natPred_injective : Function.Injective natPred := natPred_strictMono.injective @[simp] theorem natPred_lt_natPred {m n : ℕ+} : m.natPred < n.natPred ↔ m < n := natPred_strictMono.lt_iff_lt @[simp] theorem natPred_le_natPred {m n : ℕ+} : m.natPred ≤ n.natPred ↔ m ≤ n := natPred_strictMono.le_iff_le @[simp] theorem natPred_inj {m n : ℕ+} : m.natPred = n.natPred ↔ m = n := natPred_injective.eq_iff @[simp, norm_cast] lemma val_ofNat (n : ℕ) [NeZero n] : ((ofNat(n) : ℕ+) : ℕ) = OfNat.ofNat n := rfl @[simp] lemma mk_ofNat (n : ℕ) (h : 0 < n) : @Eq ℕ+ (⟨ofNat(n), h⟩ : ℕ+) (haveI : NeZero n := ⟨h.ne'⟩; OfNat.ofNat n) := rfl end PNat namespace Nat @[mono] theorem succPNat_strictMono : StrictMono succPNat := fun _ _ => Nat.succ_lt_succ @[mono] theorem succPNat_mono : Monotone succPNat := succPNat_strictMono.monotone @[simp] theorem succPNat_lt_succPNat {m n : ℕ} : m.succPNat < n.succPNat ↔ m < n := succPNat_strictMono.lt_iff_lt @[simp] theorem succPNat_le_succPNat {m n : ℕ} : m.succPNat ≤ n.succPNat ↔ m ≤ n := succPNat_strictMono.le_iff_le theorem succPNat_injective : Function.Injective succPNat := succPNat_strictMono.injective @[simp] theorem succPNat_inj {n m : ℕ} : succPNat n = succPNat m ↔ n = m := succPNat_injective.eq_iff end Nat namespace PNat open Nat /-- We now define a long list of structures on `ℕ+` induced by similar structures on `ℕ`. Most of these behave in a completely obvious way, but there are a few things to be said about subtraction, division and powers. -/ @[simp, norm_cast] theorem coe_inj {m n : ℕ+} : (m : ℕ) = n ↔ m = n := SetCoe.ext_iff @[simp, norm_cast] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl /-- `coe` promoted to an `AddHom`, that is, a morphism which preserves addition. -/ @[simps] def coeAddHom : AddHom ℕ+ ℕ where toFun := (↑) map_add' := add_coe instance addLeftMono : AddLeftMono ℕ+ := Positive.addLeftMono instance addLeftStrictMono : AddLeftStrictMono ℕ+ := Positive.addLeftStrictMono instance addLeftReflectLE : AddLeftReflectLE ℕ+ := Positive.addLeftReflectLE instance addLeftReflectLT : AddLeftReflectLT ℕ+ := Positive.addLeftReflectLT /-- The order isomorphism between ℕ and ℕ+ given by `succ`. -/ @[simps! -fullyApplied apply] def _root_.OrderIso.pnatIsoNat : ℕ+ ≃o ℕ where toEquiv := Equiv.pnatEquivNat map_rel_iff' := natPred_le_natPred @[simp] theorem _root_.OrderIso.pnatIsoNat_symm_apply : OrderIso.pnatIsoNat.symm = Nat.succPNat := rfl theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b := Nat.lt_add_one_iff theorem add_one_le_iff : ∀ {a b : ℕ+}, a + 1 ≤ b ↔ a < b := Nat.add_one_le_iff instance instOrderBot : OrderBot ℕ+ where bot := 1 bot_le a := a.property @[simp] theorem bot_eq_one : (⊥ : ℕ+) = 1 := rfl /-- Strong induction on `ℕ+`, with `n = 1` treated separately. -/ def caseStrongInductionOn {p : ℕ+ → Sort*} (a : ℕ+) (hz : p 1) (hi : ∀ n, (∀ m, m ≤ n → p m) → p (n + 1)) : p a := by apply strongInductionOn a rintro ⟨k, kprop⟩ hk rcases k with - | k · exact (lt_irrefl 0 kprop).elim rcases k with - | k · exact hz exact hi ⟨k.succ, Nat.succ_pos _⟩ fun m hm => hk _ (Nat.lt_succ_iff.2 hm) /-- An induction principle for `ℕ+`: it takes values in `Sort*`, so it applies also to Types, not only to `Prop`. -/ @[elab_as_elim, induction_eliminator] def recOn (n : ℕ+) {p : ℕ+ → Sort*} (one : p 1) (succ : ∀ n, p n → p (n + 1)) : p n := by rcases n with ⟨n, h⟩ induction n with | zero => exact absurd h (by decide) | succ n IH => rcases n with - | n · exact one · exact succ _ (IH n.succ_pos) @[simp] theorem recOn_one {p} (one succ) : @PNat.recOn 1 p one succ = one := rfl @[simp] theorem recOn_succ (n : ℕ+) {p : ℕ+ → Sort*} (one succ) : @PNat.recOn (n + 1) p one succ = succ n (@PNat.recOn n p one succ) := by obtain ⟨n, h⟩ := n cases n <;> [exact absurd h (by decide); rfl] @[simp] theorem ofNat_le_ofNat {m n : ℕ} [NeZero m] [NeZero n] : (ofNat(m) : ℕ+) ≤ ofNat(n) ↔ OfNat.ofNat m ≤ OfNat.ofNat n := .rfl @[simp] theorem ofNat_lt_ofNat {m n : ℕ} [NeZero m] [NeZero n] : (ofNat(m) : ℕ+) < ofNat(n) ↔ OfNat.ofNat m < OfNat.ofNat n := .rfl @[simp] theorem ofNat_inj {m n : ℕ} [NeZero m] [NeZero n] : (ofNat(m) : ℕ+) = ofNat(n) ↔ OfNat.ofNat m = OfNat.ofNat n := Subtype.mk_eq_mk @[simp, norm_cast] theorem mul_coe (m n : ℕ+) : ((m * n : ℕ+) : ℕ) = m * n := rfl /-- `PNat.coe` promoted to a `MonoidHom`. -/ def coeMonoidHom : ℕ+ →* ℕ where toFun := Coe.coe map_one' := one_coe map_mul' := mul_coe @[simp] theorem coe_coeMonoidHom : (coeMonoidHom : ℕ+ → ℕ) = Coe.coe := rfl @[simp] theorem le_one_iff {n : ℕ+} : n ≤ 1 ↔ n = 1 := le_bot_iff theorem lt_add_left (n m : ℕ+) : n < m + n := lt_add_of_pos_left _ m.2 theorem lt_add_right (n m : ℕ+) : n < n + m := (lt_add_left n m).trans_eq (add_comm _ _) @[simp, norm_cast] theorem pow_coe (m : ℕ+) (n : ℕ) : ↑(m ^ n) = (m : ℕ) ^ n := rfl /-- b is greater one if any a is less than b -/ theorem one_lt_of_lt {a b : ℕ+} (hab : a < b) : 1 < b := bot_le.trans_lt hab theorem add_one (a : ℕ+) : a + 1 = succPNat a := rfl theorem lt_succ_self (a : ℕ+) : a < succPNat a := lt.base a /-- Subtraction a - b is defined in the obvious way when a > b, and by a - b = 1 if a ≤ b. -/ instance instSub : Sub ℕ+ := ⟨fun a b => toPNat' (a - b : ℕ)⟩ theorem sub_coe (a b : ℕ+) : ((a - b : ℕ+) : ℕ) = ite (b < a) (a - b : ℕ) 1 := by change (toPNat' _ : ℕ) = ite _ _ _ split_ifs with h · exact toPNat'_coe (tsub_pos_of_lt h) · rw [tsub_eq_zero_iff_le.mpr (le_of_not_gt h : (a : ℕ) ≤ b)] rfl theorem sub_le (a b : ℕ+) : a - b ≤ a := by rw [← coe_le_coe, sub_coe] split_ifs with h · exact Nat.sub_le a b · exact a.2 theorem le_sub_one_of_lt {a b : ℕ+} (hab : a < b) : a ≤ b - (1 : ℕ+) := by rw [← coe_le_coe, sub_coe] split_ifs with h · exact Nat.le_pred_of_lt hab · exact hab.le.trans (le_of_not_lt h) theorem add_sub_of_lt {a b : ℕ+} : a < b → a + (b - a) = b := fun h => PNat.eq <| by rw [add_coe, sub_coe, if_pos h] exact add_tsub_cancel_of_le h.le theorem sub_add_of_lt {a b : ℕ+} (h : b < a) : a - b + b = a := by rw [add_comm, add_sub_of_lt h] @[simp] theorem add_sub {a b : ℕ+} : a + b - b = a := add_right_cancel (sub_add_of_lt (lt_add_left _ _)) /-- If `n : ℕ+` is different from `1`, then it is the successor of some `k : ℕ+`. -/ theorem exists_eq_succ_of_ne_one : ∀ {n : ℕ+} (_ : n ≠ 1), ∃ k : ℕ+, n = k + 1 | ⟨1, _⟩, h₁ => False.elim <| h₁ rfl | ⟨n + 2, _⟩, _ => ⟨⟨n + 1, by simp⟩, rfl⟩ /-- Lemmas with div, dvd and mod operations -/ theorem modDivAux_spec : ∀ (k : ℕ+) (r q : ℕ) (_ : ¬(r = 0 ∧ q = 0)), ((modDivAux k r q).1 : ℕ) + k * (modDivAux k r q).2 = r + k * q | _, 0, 0, h => (h ⟨rfl, rfl⟩).elim | k, 0, q + 1, _ => by change (k : ℕ) + (k : ℕ) * (q + 1).pred = 0 + (k : ℕ) * (q + 1) rw [Nat.pred_succ, Nat.mul_succ, zero_add, add_comm] | _, _ + 1, _, _ => rfl
theorem mod_add_div (m k : ℕ+) : (mod m k + k * div m k : ℕ) = m := by let h₀ := Nat.mod_add_div (m : ℕ) (k : ℕ) have : ¬((m : ℕ) % (k : ℕ) = 0 ∧ (m : ℕ) / (k : ℕ) = 0) := by rintro ⟨hr, hq⟩ rw [hr, hq, mul_zero, zero_add] at h₀
Mathlib/Data/PNat/Basic.lean
291
295
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Order.Filter.Interval import Mathlib.Order.Interval.Set.Pi import Mathlib.Tactic.TFAE import Mathlib.Tactic.NormNum import Mathlib.Topology.Order.LeftRight import Mathlib.Topology.Order.OrderClosed /-! # Theory of topology on ordered spaces ## Main definitions The order topology on an ordered space is the topology generated by all open intervals (or equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `Preorder.topology α`. However, we do *not* register it as an instance (as many existing ordered types already have topologies, which would be equal but not definitionally equal to `Preorder.topology α`). Instead, we introduce a class `OrderTopology α` (which is a `Prop`, also known as a mixin) saying that on the type `α` having already a topological space structure and a preorder structure, the topological structure is equal to the order topology. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`OrderClosedTopology` vs `OrderTopology`, `Preorder` vs `PartialOrder` vs `LinearOrder` etc) see their statements. * `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`. * `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem, sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h` both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`. ## Implementation notes We do _not_ register the order topology as an instance on a preorder (or even on a linear order). Indeed, on many such spaces, a topology has already been constructed in a different way (think of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`), and is in general not defeq to the one generated by the intervals. We make it available as a definition `Preorder.topology α` though, that can be registered as an instance when necessary, or for specific types. -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) universe u v w variable {α : Type u} {β : Type v} {γ : Type w} -- TODO: define `Preorder.topology` before `OrderTopology` and reuse the def /-- The order topology on an ordered type is the topology generated by open intervals. We register it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed. We define it as a mixin. If you want to introduce the order topology on a preorder, use `Preorder.topology`. -/ class OrderTopology (α : Type*) [t : TopologicalSpace α] [Preorder α] : Prop where /-- The topology is generated by open intervals `Set.Ioi _` and `Set.Iio _`. -/ topology_eq_generate_intervals : t = generateFrom { s | ∃ a, s = Ioi a ∨ s = Iio a } /-- (Order) topology on a partial order `α` generated by the subbase of open intervals `(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an instance as many ordered sets are already endowed with the same topology, most often in a non-defeq way though. Register as a local instance when necessary. -/ def Preorder.topology (α : Type*) [Preorder α] : TopologicalSpace α := generateFrom { s : Set α | ∃ a : α, s = { b : α | a < b } ∨ s = { b : α | b < a } } section OrderTopology section Preorder variable [TopologicalSpace α] [Preorder α] instance [t : OrderTopology α] : OrderTopology αᵒᵈ := ⟨by convert OrderTopology.topology_eq_generate_intervals (α := α) using 6 apply or_comm⟩ theorem isOpen_iff_generate_intervals [t : OrderTopology α] {s : Set α} : IsOpen s ↔ GenerateOpen { s | ∃ a, s = Ioi a ∨ s = Iio a } s := by rw [t.topology_eq_generate_intervals]; rfl theorem isOpen_lt' [OrderTopology α] (a : α) : IsOpen { b : α | a < b } := isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inl rfl⟩ theorem isOpen_gt' [OrderTopology α] (a : α) : IsOpen { b : α | b < a } := isOpen_iff_generate_intervals.2 <| .basic _ ⟨a, .inr rfl⟩ theorem lt_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x := (isOpen_lt' _).mem_nhds h theorem le_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x := (lt_mem_nhds h).mono fun _ => le_of_lt theorem gt_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b := (isOpen_gt' _).mem_nhds h theorem ge_mem_nhds [OrderTopology α] {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := (gt_mem_nhds h).mono fun _ => le_of_lt theorem nhds_eq_order [OrderTopology α] (a : α) : 𝓝 a = (⨅ b ∈ Iio a, 𝓟 (Ioi b)) ⊓ ⨅ b ∈ Ioi a, 𝓟 (Iio b) := by rw [OrderTopology.topology_eq_generate_intervals (α := α), nhds_generateFrom] simp_rw [mem_setOf_eq, @and_comm (a ∈ _), exists_or, or_and_right, iInf_or, iInf_and, iInf_exists, iInf_inf_eq, iInf_comm (ι := Set α), iInf_iInf_eq_left, mem_Ioi, mem_Iio] theorem tendsto_order [OrderTopology α] {f : β → α} {a : α} {x : Filter β} : Tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ ∀ a' > a, ∀ᶠ b in x, f b < a' := by simp only [nhds_eq_order a, tendsto_inf, tendsto_iInf, tendsto_principal]; rfl instance tendstoIccClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Icc (𝓝 a) (𝓝 a) := by simp only [nhds_eq_order, iInf_subtype'] refine ((hasBasis_iInf_principal_finite _).inf (hasBasis_iInf_principal_finite _)).tendstoIxxClass fun s _ => ?_ refine ((ordConnected_biInter ?_).inter (ordConnected_biInter ?_)).out <;> intro _ _ exacts [ordConnected_Ioi, ordConnected_Iio] instance tendstoIcoClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ico (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ico_subset_Icc_self instance tendstoIocClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ioc (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ioc_subset_Icc_self instance tendstoIooClassNhds [OrderTopology α] (a : α) : TendstoIxxClass Ioo (𝓝 a) (𝓝 a) := tendstoIxxClass_of_subset fun _ _ => Ioo_subset_Icc_self /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold eventually for the filter. -/ theorem tendsto_of_tendsto_of_tendsto_of_le_of_le' [OrderTopology α] {f g h : β → α} {b : Filter β} {a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) : Tendsto f b (𝓝 a) := (hg.Icc hh).of_smallSets <| hgf.and hfh alias Filter.Tendsto.squeeze' := tendsto_of_tendsto_of_tendsto_of_le_of_le' /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold everywhere. -/ theorem tendsto_of_tendsto_of_tendsto_of_le_of_le [OrderTopology α] {f g h : β → α} {b : Filter β} {a : α} (hg : Tendsto g b (𝓝 a)) (hh : Tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) : Tendsto f b (𝓝 a) := tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (Eventually.of_forall hgf) (Eventually.of_forall hfh) alias Filter.Tendsto.squeeze := tendsto_of_tendsto_of_tendsto_of_le_of_le theorem nhds_order_unbounded [OrderTopology α] {a : α} (hu : ∃ u, a < u) (hl : ∃ l, l < a) : 𝓝 a = ⨅ (l) (_ : l < a) (u) (_ : a < u), 𝓟 (Ioo l u) := by simp only [nhds_eq_order, ← inf_biInf, ← biInf_inf, *, ← inf_principal, ← Ioi_inter_Iio]; rfl theorem tendsto_order_unbounded [OrderTopology α] {f : β → α} {a : α} {x : Filter β} (hu : ∃ u, a < u) (hl : ∃ l, l < a) (h : ∀ l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) : Tendsto f x (𝓝 a) := by simp only [nhds_order_unbounded hu hl, tendsto_iInf, tendsto_principal] exact fun l hl u => h l u hl end Preorder instance tendstoIxxNhdsWithin {α : Type*} [TopologicalSpace α] (a : α) {s t : Set α} {Ixx} [TendstoIxxClass Ixx (𝓝 a) (𝓝 a)] [TendstoIxxClass Ixx (𝓟 s) (𝓟 t)] : TendstoIxxClass Ixx (𝓝[s] a) (𝓝[t] a) := Filter.tendstoIxxClass_inf instance tendstoIccClassNhdsPi {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] [∀ i, TopologicalSpace (α i)] [∀ i, OrderTopology (α i)] (f : ∀ i, α i) : TendstoIxxClass Icc (𝓝 f) (𝓝 f) := by constructor conv in (𝓝 f).smallSets => rw [nhds_pi, Filter.pi] simp only [smallSets_iInf, smallSets_comap_eq_comap_image, tendsto_iInf, tendsto_comap_iff] intro i have : Tendsto (fun g : ∀ i, α i => g i) (𝓝 f) (𝓝 (f i)) := (continuous_apply i).tendsto f refine (this.comp tendsto_fst).Icc (this.comp tendsto_snd) |>.smallSets_mono ?_ filter_upwards [] using fun ⟨f, g⟩ ↦ image_subset_iff.mpr fun p hp ↦ ⟨hp.1 i, hp.2 i⟩ theorem induced_topology_le_preorder [Preorder α] [Preorder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) : induced f ‹TopologicalSpace β› ≤ Preorder.topology α := by let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩ refine le_of_nhds_le_nhds fun x => ?_ simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal, Ioi, Iio, ← hf] refine inf_le_inf (le_iInf₂ fun a ha => ?_) (le_iInf₂ fun a ha => ?_) exacts [iInf₂_le (f a) ha, iInf₂_le (f a) ha] theorem induced_topology_eq_preorder [Preorder α] [Preorder β] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a b x}, b < f a → ¬(b < f x) → ∃ y, y < a ∧ b ≤ f y) (H₂ : ∀ {a b x}, f a < b → ¬(f x < b) → ∃ y, a < y ∧ f y ≤ b) : induced f ‹TopologicalSpace β› = Preorder.topology α := by let _ := Preorder.topology α; have : OrderTopology α := ⟨rfl⟩ refine le_antisymm (induced_topology_le_preorder hf) ?_ refine le_of_nhds_le_nhds fun a => ?_ simp only [nhds_eq_order, nhds_induced, comap_inf, comap_iInf, comap_principal] refine inf_le_inf (le_iInf₂ fun b hb => ?_) (le_iInf₂ fun b hb => ?_) · rcases em (∃ x, ¬(b < f x)) with (⟨x, hx⟩ | hb) · rcases H₁ hb hx with ⟨y, hya, hyb⟩ exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => hyb.trans_lt (hf.2 hz)) · push_neg at hb exact le_principal_iff.2 (univ_mem' hb) · rcases em (∃ x, ¬(f x < b)) with (⟨x, hx⟩ | hb) · rcases H₂ hb hx with ⟨y, hya, hyb⟩ exact iInf₂_le_of_le y hya (principal_mono.2 fun z hz => (hf.2 hz).trans_le hyb) · push_neg at hb exact le_principal_iff.2 (univ_mem' hb) theorem induced_orderTopology' {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β] [Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @OrderTopology _ (induced f ta) _ := let _ := induced f ta ⟨induced_topology_eq_preorder hf (fun h _ => H₁ h) (fun h _ => H₂ h)⟩ theorem induced_orderTopology {α : Type u} {β : Type v} [Preorder α] [ta : TopologicalSpace β] [Preorder β] [OrderTopology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @OrderTopology _ (induced f ta) _ := induced_orderTopology' f (hf) (fun xa => let ⟨b, xb, ba⟩ := H xa; ⟨b, hf.1 ba, le_of_lt xb⟩) fun ax => let ⟨b, ab, bx⟩ := H ax; ⟨b, hf.1 ab, le_of_lt bx⟩ /-- The topology induced by a strictly monotone function with order-connected range is the preorder topology. -/ nonrec theorem StrictMono.induced_topology_eq_preorder {α β : Type*} [LinearOrder α] [LinearOrder β] [t : TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : StrictMono f) (hc : OrdConnected (range f)) : t.induced f = Preorder.topology α := by refine induced_topology_eq_preorder hf.lt_iff_lt (fun h₁ h₂ => ?_) fun h₁ h₂ => ?_ · rcases hc.out (mem_range_self _) (mem_range_self _) ⟨not_lt.1 h₂, h₁.le⟩ with ⟨y, rfl⟩ exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩ · rcases hc.out (mem_range_self _) (mem_range_self _) ⟨h₁.le, not_lt.1 h₂⟩ with ⟨y, rfl⟩ exact ⟨y, hf.lt_iff_lt.1 h₁, le_rfl⟩ /-- A strictly monotone function between linear orders with order topology is a topological embedding provided that the range of `f` is order-connected. -/ theorem StrictMono.isEmbedding_of_ordConnected {α β : Type*} [LinearOrder α] [LinearOrder β] [TopologicalSpace α] [h : OrderTopology α] [TopologicalSpace β] [OrderTopology β] {f : α → β} (hf : StrictMono f) (hc : OrdConnected (range f)) : IsEmbedding f := ⟨⟨h.1.trans <| Eq.symm <| hf.induced_topology_eq_preorder hc⟩, hf.injective⟩ @[deprecated (since := "2024-10-26")] alias StrictMono.embedding_of_ordConnected := StrictMono.isEmbedding_of_ordConnected /-- On a `Set.OrdConnected` subset of a linear order, the order topology for the restriction of the order is the same as the restriction to the subset of the order topology. -/ instance orderTopology_of_ordConnected {α : Type u} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {t : Set α} [ht : OrdConnected t] : OrderTopology t := ⟨(Subtype.strictMono_coe t).induced_topology_eq_preorder <| by rwa [← @Subtype.range_val _ t] at ht⟩ theorem nhdsGE_eq_iInf_inf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) : 𝓝[≥] a = (⨅ (u) (_ : a < u), 𝓟 (Iio u)) ⊓ 𝓟 (Ici a) := by rw [nhdsWithin, nhds_eq_order] refine le_antisymm (inf_le_inf_right _ inf_le_right) (le_inf (le_inf ?_ inf_le_left) inf_le_right) exact inf_le_right.trans (le_iInf₂ fun l hl => principal_mono.2 <| Ici_subset_Ioi.2 hl) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_eq'' := nhdsGE_eq_iInf_inf_principal theorem nhdsLE_eq_iInf_inf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] (a : α) : 𝓝[≤] a = (⨅ l < a, 𝓟 (Ioi l)) ⊓ 𝓟 (Iic a) := nhdsGE_eq_iInf_inf_principal (toDual a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_eq'' := nhdsLE_eq_iInf_inf_principal theorem nhdsGE_eq_iInf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α} (ha : ∃ u, a < u) : 𝓝[≥] a = ⨅ (u) (_ : a < u), 𝓟 (Ico a u) := by simp only [nhdsGE_eq_iInf_inf_principal, biInf_inf ha, inf_principal, Iio_inter_Ici] @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_eq' := nhdsGE_eq_iInf_principal theorem nhdsLE_eq_iInf_principal [TopologicalSpace α] [Preorder α] [OrderTopology α] {a : α} (ha : ∃ l, l < a) : 𝓝[≤] a = ⨅ l < a, 𝓟 (Ioc l a) := by simp only [nhdsLE_eq_iInf_inf_principal, biInf_inf ha, inf_principal, Ioi_inter_Iic] @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_eq' := nhdsLE_eq_iInf_principal theorem nhdsGE_basis_of_exists_gt [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α} (ha : ∃ u, a < u) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u := (nhdsGE_eq_iInf_principal ha).symm ▸ hasBasis_biInf_principal (fun b hb c hc => ⟨min b c, lt_min hb hc, Ico_subset_Ico_right (min_le_left _ _), Ico_subset_Ico_right (min_le_right _ _)⟩) ha @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis' := nhdsGE_basis_of_exists_gt theorem nhdsLE_basis_of_exists_lt [TopologicalSpace α] [LinearOrder α] [OrderTopology α] {a : α} (ha : ∃ l, l < a) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := by convert nhdsGE_basis_of_exists_gt (α := αᵒᵈ) ha using 2 exact Ico_toDual.symm @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis' := nhdsLE_basis_of_exists_lt theorem nhdsGE_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMaxOrder α] (a : α) : (𝓝[≥] a).HasBasis (fun u => a < u) fun u => Ico a u := nhdsGE_basis_of_exists_gt (exists_gt a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis := nhdsGE_basis theorem nhdsLE_basis [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [NoMinOrder α] (a : α) : (𝓝[≤] a).HasBasis (fun l => l < a) fun l => Ioc l a := nhdsLE_basis_of_exists_lt (exists_lt a) @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis := nhdsLE_basis theorem nhds_top_order [TopologicalSpace α] [Preorder α] [OrderTop α] [OrderTopology α] : 𝓝 (⊤ : α) = ⨅ (l) (_ : l < ⊤), 𝓟 (Ioi l) := by simp [nhds_eq_order (⊤ : α)] theorem nhds_bot_order [TopologicalSpace α] [Preorder α] [OrderBot α] [OrderTopology α] : 𝓝 (⊥ : α) = ⨅ (l) (_ : ⊥ < l), 𝓟 (Iio l) := by simp [nhds_eq_order (⊥ : α)] theorem nhds_top_basis [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α] [Nontrivial α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) fun a : α => Ioi a := by have : ∃ x : α, x < ⊤ := (exists_ne ⊤).imp fun x hx => hx.lt_top simpa only [Iic_top, nhdsWithin_univ, Ioc_top] using nhdsLE_basis_of_exists_lt this theorem nhds_bot_basis [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α] [Nontrivial α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) fun a : α => Iio a := nhds_top_basis (α := αᵒᵈ) theorem nhds_top_basis_Ici [TopologicalSpace α] [LinearOrder α] [OrderTop α] [OrderTopology α] [Nontrivial α] [DenselyOrdered α] : (𝓝 ⊤).HasBasis (fun a : α => a < ⊤) Ici := nhds_top_basis.to_hasBasis (fun _a ha => let ⟨b, hab, hb⟩ := exists_between ha; ⟨b, hb, Ici_subset_Ioi.mpr hab⟩) fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩ theorem nhds_bot_basis_Iic [TopologicalSpace α] [LinearOrder α] [OrderBot α] [OrderTopology α] [Nontrivial α] [DenselyOrdered α] : (𝓝 ⊥).HasBasis (fun a : α => ⊥ < a) Iic := nhds_top_basis_Ici (α := αᵒᵈ) theorem tendsto_nhds_top_mono [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : Tendsto g l (𝓝 ⊤) := by simp only [nhds_top_order, tendsto_iInf, tendsto_principal] at hf ⊢ intro x hx filter_upwards [hf x hx, hg] with _ using lt_of_lt_of_le theorem tendsto_nhds_bot_mono [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : Tendsto g l (𝓝 ⊥) := tendsto_nhds_top_mono (β := βᵒᵈ) hf hg theorem tendsto_nhds_top_mono' [TopologicalSpace β] [Preorder β] [OrderTop β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : Tendsto g l (𝓝 ⊤) := tendsto_nhds_top_mono hf (Eventually.of_forall hg) theorem tendsto_nhds_bot_mono' [TopologicalSpace β] [Preorder β] [OrderBot β] [OrderTopology β] {l : Filter α} {f g : α → β} (hf : Tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : Tendsto g l (𝓝 ⊥) := tendsto_nhds_bot_mono hf (Eventually.of_forall hg) section LinearOrder variable [TopologicalSpace α] [LinearOrder α] section OrderTopology theorem order_separated [OrderTopology α] {a₁ a₂ : α} (h : a₁ < a₂) : ∃ u v : Set α, IsOpen u ∧ IsOpen v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ ∀ b₁ ∈ u, ∀ b₂ ∈ v, b₁ < b₂ := let ⟨x, hx, y, hy, h⟩ := h.exists_disjoint_Iio_Ioi ⟨Iio x, Ioi y, isOpen_gt' _, isOpen_lt' _, hx, hy, h⟩ -- see Note [lower instance priority] instance (priority := 100) OrderTopology.to_orderClosedTopology [OrderTopology α] : OrderClosedTopology α where isClosed_le' := isOpen_compl_iff.1 <| isOpen_prod_iff.mpr fun a₁ a₂ (h : ¬a₁ ≤ a₂) => have h : a₂ < a₁ := lt_of_not_ge h let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h ⟨v, u, hv, hu, ha₂, ha₁, fun ⟨b₁, b₂⟩ ⟨h₁, h₂⟩ => not_le_of_gt <| h b₂ h₂ b₁ h₁⟩ theorem exists_Ioc_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s := (nhdsLE_basis_of_exists_lt h).mem_iff.mp (nhdsWithin_le_nhds hs) theorem exists_Ioc_subset_of_mem_nhds' [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s := let ⟨l', hl'a, hl's⟩ := exists_Ioc_subset_of_mem_nhds hs ⟨l, hl⟩ ⟨max l l', ⟨le_max_left _ _, max_lt hl hl'a⟩, (Ioc_subset_Ioc_left <| le_max_right _ _).trans hl's⟩ theorem exists_Ico_subset_of_mem_nhds' [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := by simpa only [OrderDual.exists, exists_prop, Ico_toDual, Ioc_toDual] using exists_Ioc_subset_of_mem_nhds' (show ofDual ⁻¹' s ∈ 𝓝 (toDual a) from hs) hu.dual theorem exists_Ico_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) : ∃ u, a < u ∧ Ico a u ⊆ s := let ⟨_l', hl'⟩ := h let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' ⟨l, hl.1.1, hl.2⟩ theorem exists_Icc_mem_subset_of_mem_nhdsGE [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝[≥] a) : ∃ b, a ≤ b ∧ Icc a b ∈ 𝓝[≥] a ∧ Icc a b ⊆ s := by rcases (em (IsMax a)).imp_right not_isMax_iff.mp with (ha | ha) · use a simpa [ha.Ici_eq] using hs · rcases(nhdsGE_basis_of_exists_gt ha).mem_iff.mp hs with ⟨b, hab, hbs⟩ rcases eq_empty_or_nonempty (Ioo a b) with (H | ⟨c, hac, hcb⟩) · have : Ico a b = Icc a a := by rw [← Icc_union_Ioo_eq_Ico le_rfl hab, H, union_empty] exact ⟨a, le_rfl, this ▸ ⟨Ico_mem_nhdsGE hab, hbs⟩⟩ · refine ⟨c, hac.le, Icc_mem_nhdsGE hac, ?_⟩ exact (Icc_subset_Ico_right hcb).trans hbs @[deprecated (since := "2024-12-22")] alias exists_Icc_mem_subset_of_mem_nhdsWithin_Ici := exists_Icc_mem_subset_of_mem_nhdsGE theorem exists_Icc_mem_subset_of_mem_nhdsLE [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝[≤] a) : ∃ b ≤ a, Icc b a ∈ 𝓝[≤] a ∧ Icc b a ⊆ s := by simpa only [Icc_toDual, toDual.surjective.exists] using exists_Icc_mem_subset_of_mem_nhdsGE (α := αᵒᵈ) (a := toDual a) hs @[deprecated (since := "2024-12-22")] alias exists_Icc_mem_subset_of_mem_nhdsWithin_Iic := exists_Icc_mem_subset_of_mem_nhdsLE theorem exists_Icc_mem_subset_of_mem_nhds [OrderTopology α] {a : α} {s : Set α} (hs : s ∈ 𝓝 a) : ∃ b c, a ∈ Icc b c ∧ Icc b c ∈ 𝓝 a ∧ Icc b c ⊆ s := by rcases exists_Icc_mem_subset_of_mem_nhdsLE (nhdsWithin_le_nhds hs) with ⟨b, hba, hb_nhds, hbs⟩ rcases exists_Icc_mem_subset_of_mem_nhdsGE (nhdsWithin_le_nhds hs) with ⟨c, hac, hc_nhds, hcs⟩ refine ⟨b, c, ⟨hba, hac⟩, ?_⟩ rw [← Icc_union_Icc_eq_Icc hba hac, ← nhdsLE_sup_nhdsGE] exact ⟨union_mem_sup hb_nhds hc_nhds, union_subset hbs hcs⟩ theorem IsOpen.exists_Ioo_subset [OrderTopology α] [Nontrivial α] {s : Set α} (hs : IsOpen s) (h : s.Nonempty) : ∃ a b, a < b ∧ Ioo a b ⊆ s := by obtain ⟨x, hx⟩ : ∃ x, x ∈ s := h obtain ⟨y, hy⟩ : ∃ y, y ≠ x := exists_ne x rcases lt_trichotomy x y with (H | rfl | H) · obtain ⟨u, xu, hu⟩ : ∃ u, x < u ∧ Ico x u ⊆ s := exists_Ico_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩ exact ⟨x, u, xu, Ioo_subset_Ico_self.trans hu⟩ · exact (hy rfl).elim · obtain ⟨l, lx, hl⟩ : ∃ l, l < x ∧ Ioc l x ⊆ s := exists_Ioc_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩ exact ⟨l, x, lx, Ioo_subset_Ioc_self.trans hl⟩ theorem dense_of_exists_between [OrderTopology α] [Nontrivial α] {s : Set α} (h : ∀ ⦃a b⦄, a < b → ∃ c ∈ s, a < c ∧ c < b) : Dense s := by refine dense_iff_inter_open.2 fun U U_open U_nonempty => ?_ obtain ⟨a, b, hab, H⟩ : ∃ a b : α, a < b ∧ Ioo a b ⊆ U := U_open.exists_Ioo_subset U_nonempty obtain ⟨x, xs, hx⟩ : ∃ x ∈ s, a < x ∧ x < b := h hab exact ⟨x, ⟨H hx, xs⟩⟩ /-- A set in a nontrivial densely linear ordered type is dense in the sense of topology if and only if for any `a < b` there exists `c ∈ s`, `a < c < b`. Each implication requires less typeclass assumptions. -/ theorem dense_iff_exists_between [OrderTopology α] [DenselyOrdered α] [Nontrivial α] {s : Set α} : Dense s ↔ ∀ a b, a < b → ∃ c ∈ s, a < c ∧ c < b := ⟨fun h _ _ hab => h.exists_between hab, dense_of_exists_between⟩ /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`, provided `a` is neither a bottom element nor a top element. -/ theorem mem_nhds_iff_exists_Ioo_subset' [OrderTopology α] {a : α} {s : Set α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : s ∈ 𝓝 a ↔ ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := by constructor · intro h rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩ rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩ exact ⟨l, u, ⟨la, au⟩, Ioc_union_Ico_eq_Ioo la au ▸ union_subset hl hu⟩ · rintro ⟨l, u, ha, h⟩ apply mem_of_superset (Ioo_mem_nhds ha.1 ha.2) h /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`. -/ theorem mem_nhds_iff_exists_Ioo_subset [OrderTopology α] [NoMaxOrder α] [NoMinOrder α] {a : α} {s : Set α} : s ∈ 𝓝 a ↔ ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := mem_nhds_iff_exists_Ioo_subset' (exists_lt a) (exists_gt a) theorem nhds_basis_Ioo' [OrderTopology α] {a : α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : (𝓝 a).HasBasis (fun b : α × α => b.1 < a ∧ a < b.2) fun b => Ioo b.1 b.2 := ⟨fun s => (mem_nhds_iff_exists_Ioo_subset' hl hu).trans <| by simp⟩ theorem nhds_basis_Ioo [OrderTopology α] [NoMaxOrder α] [NoMinOrder α] (a : α) : (𝓝 a).HasBasis (fun b : α × α => b.1 < a ∧ a < b.2) fun b => Ioo b.1 b.2 := nhds_basis_Ioo' (exists_lt a) (exists_gt a) theorem Filter.Eventually.exists_Ioo_subset [OrderTopology α] [NoMaxOrder α] [NoMinOrder α] {a : α} {p : α → Prop} (hp : ∀ᶠ x in 𝓝 a, p x) : ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ { x | p x } := mem_nhds_iff_exists_Ioo_subset.1 hp theorem Dense.topology_eq_generateFrom [OrderTopology α] [DenselyOrdered α] {s : Set α} (hs : Dense s) : ‹TopologicalSpace α› = .generateFrom (Ioi '' s ∪ Iio '' s) := by refine (OrderTopology.topology_eq_generate_intervals (α := α)).trans ?_ refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_) · simp only [union_subset_iff, image_subset_iff] exact ⟨fun a _ ↦ ⟨a, .inl rfl⟩, fun a _ ↦ ⟨a, .inr rfl⟩⟩ · rintro _ ⟨a, rfl | rfl⟩ · rw [hs.Ioi_eq_biUnion] let _ := generateFrom (Ioi '' s ∪ Iio '' s) exact isOpen_iUnion fun x ↦ isOpen_iUnion fun h ↦ .basic _ <| .inl <| mem_image_of_mem _ h.1 · rw [hs.Iio_eq_biUnion] let _ := generateFrom (Ioi '' s ∪ Iio '' s) exact isOpen_iUnion fun x ↦ isOpen_iUnion fun h ↦ .basic _ <| .inr <| mem_image_of_mem _ h.1 theorem PredOrder.hasBasis_nhds_Ioc_of_exists_gt [OrderTopology α] [PredOrder α] {a : α} (ha : ∃ u, a < u) : (𝓝 a).HasBasis (a < ·) (Set.Ico a ·) := PredOrder.nhdsGE_eq_nhds a ▸ nhdsGE_basis_of_exists_gt ha theorem PredOrder.hasBasis_nhds_Ioc [OrderTopology α] [PredOrder α] [NoMaxOrder α] {a : α} : (𝓝 a).HasBasis (a < ·) (Set.Ico a ·) := PredOrder.hasBasis_nhds_Ioc_of_exists_gt (exists_gt a) theorem SuccOrder.hasBasis_nhds_Ioc_of_exists_lt [OrderTopology α] [SuccOrder α] {a : α} (ha : ∃ l, l < a) : (𝓝 a).HasBasis (· < a) (Set.Ioc · a) := SuccOrder.nhdsLE_eq_nhds a ▸ nhdsLE_basis_of_exists_lt ha theorem SuccOrder.hasBasis_nhds_Ioc [OrderTopology α] [SuccOrder α] {a : α} [NoMinOrder α] : (𝓝 a).HasBasis (· < a) (Set.Ioc · a) := SuccOrder.hasBasis_nhds_Ioc_of_exists_lt (exists_lt a) variable (α) in /-- Let `α` be a densely ordered linear order with order topology. If `α` is a separable space, then it has second countable topology. Note that the "densely ordered" assumption cannot be dropped, see [double arrow space](https://topology.pi-base.org/spaces/S000093) for a counterexample. -/ theorem SecondCountableTopology.of_separableSpace_orderTopology [OrderTopology α] [DenselyOrdered α] [SeparableSpace α] : SecondCountableTopology α := by rcases exists_countable_dense α with ⟨s, hc, hd⟩ refine ⟨⟨_, ?_, hd.topology_eq_generateFrom⟩⟩ exact (hc.image _).union (hc.image _) /-- The set of points which are isolated on the right is countable when the space is second-countable. -/ theorem countable_setOf_covBy_right [OrderTopology α] [SecondCountableTopology α] : Set.Countable { x : α | ∃ y, x ⋖ y } := by nontriviality α let s := { x : α | ∃ y, x ⋖ y } have : ∀ x ∈ s, ∃ y, x ⋖ y := fun x => id choose! y hy using this have Hy : ∀ x z, x ∈ s → z < y x → z ≤ x := fun x z hx => (hy x hx).le_of_lt suffices H : ∀ a : Set α, IsOpen a → Set.Countable { x | x ∈ s ∧ x ∈ a ∧ y x ∉ a } by have : s ⊆ ⋃ a ∈ countableBasis α, { x | x ∈ s ∧ x ∈ a ∧ y x ∉ a } := fun x hx => by rcases (isBasis_countableBasis α).exists_mem_of_ne (hy x hx).ne with ⟨a, ab, xa, ya⟩ exact mem_iUnion₂.2 ⟨a, ab, hx, xa, ya⟩ refine Set.Countable.mono this ?_ refine Countable.biUnion (countable_countableBasis α) fun a ha => H _ ?_ exact isOpen_of_mem_countableBasis ha intro a ha suffices H : Set.Countable { x | (x ∈ s ∧ x ∈ a ∧ y x ∉ a) ∧ ¬IsBot x } from H.of_diff (subsingleton_isBot α).countable simp only [and_assoc] let t := { x | x ∈ s ∧ x ∈ a ∧ y x ∉ a ∧ ¬IsBot x } have : ∀ x ∈ t, ∃ z < x, Ioc z x ⊆ a := by intro x hx apply exists_Ioc_subset_of_mem_nhds (ha.mem_nhds hx.2.1) simpa only [IsBot, not_forall, not_le] using hx.right.right.right choose! z hz h'z using this have : PairwiseDisjoint t fun x => Ioc (z x) x := fun x xt x' x't hxx' => by rcases hxx'.lt_or_lt with (h' | h') · refine disjoint_left.2 fun u ux ux' => xt.2.2.1 ?_ refine h'z x' x't ⟨ux'.1.trans_le (ux.2.trans (hy x xt.1).le), ?_⟩ by_contra! H exact lt_irrefl _ ((Hy _ _ xt.1 H).trans_lt h') · refine disjoint_left.2 fun u ux ux' => x't.2.2.1 ?_
refine h'z x xt ⟨ux.1.trans_le (ux'.2.trans (hy x' x't.1).le), ?_⟩ by_contra! H exact lt_irrefl _ ((Hy _ _ x't.1 H).trans_lt h') refine this.countable_of_isOpen (fun x hx => ?_) fun x hx => ⟨x, hz x hx, le_rfl⟩ suffices H : Ioc (z x) x = Ioo (z x) (y x) by rw [H] exact isOpen_Ioo exact Subset.antisymm (Ioc_subset_Ioo_right (hy x hx.1).lt) fun u hu => ⟨hu.1, Hy _ _ hx.1 hu.2⟩ /-- The set of points which are isolated on the left is countable when the space is second-countable. -/ theorem countable_setOf_covBy_left [OrderTopology α] [SecondCountableTopology α] : Set.Countable { x : α | ∃ y, y ⋖ x } := by convert countable_setOf_covBy_right (α := αᵒᵈ) using 5 exact toDual_covBy_toDual_iff.symm /-- The set of points which are isolated on the left is countable when the space is second-countable. -/ theorem countable_of_isolated_left' [OrderTopology α] [SecondCountableTopology α] : Set.Countable { x : α | ∃ y, y < x ∧ Ioo y x = ∅ } := by simpa only [← covBy_iff_Ioo_eq] using countable_setOf_covBy_left /-- Consider a disjoint family of intervals `(x, y)` with `x < y` in a second-countable space. Then the family is countable. This is not a straightforward consequence of second-countability as some of these intervals might be empty (but in fact this can happen only for countably many of them). -/ theorem Set.PairwiseDisjoint.countable_of_Ioo [OrderTopology α] [SecondCountableTopology α] {y : α → α} {s : Set α} (h : PairwiseDisjoint s fun x => Ioo x (y x)) (h' : ∀ x ∈ s, x < y x) : s.Countable := have : (s \ { x | ∃ y, x ⋖ y }).Countable := (h.subset diff_subset).countable_of_isOpen (fun _ _ => isOpen_Ioo) fun x hx => (h' _ hx.1).exists_lt_lt (mt (Exists.intro (y x)) hx.2) this.of_diff countable_setOf_covBy_right /-- For a function taking values in a second countable space, the set of points `x` for which the image under `f` of `(x, ∞)` is separated above from `f x` is countable. -/ theorem countable_image_lt_image_Ioi [OrderTopology α] [LinearOrder β] (f : β → α) [SecondCountableTopology α] : Set.Countable {x | ∃ z, f x < z ∧ ∀ y, x < y → z ≤ f y} := by /- If the values of `f` are separated above on the right of `x`, there is an interval `(f x, z x)`
Mathlib/Topology/Order/Basic.lean
555
593
/- 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.Algebra.Ring.Prod import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Canonical import Mathlib.Order.Interval.Basic import Mathlib.Tactic.Positivity.Core import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Interval arithmetic This file defines arithmetic operations on intervals and prove their correctness. Note that this is full precision operations. The essentials of float operations can be found in `Data.FP.Basic`. We have not yet integrated these with the rest of the library. -/ open Function Set open scoped Pointwise universe u variable {ι α : Type*} /-! ### One/zero -/ section One section Preorder variable [Preorder α] [One α] @[to_additive] instance : One (NonemptyInterval α) := ⟨NonemptyInterval.pure 1⟩ namespace NonemptyInterval @[to_additive (attr := simp) toProd_zero] theorem toProd_one : (1 : NonemptyInterval α).toProd = 1 := rfl @[to_additive] theorem fst_one : (1 : NonemptyInterval α).fst = 1 := rfl @[to_additive] theorem snd_one : (1 : NonemptyInterval α).snd = 1 := rfl @[to_additive (attr := push_cast, simp)] theorem coe_one_interval : ((1 : NonemptyInterval α) : Interval α) = 1 := rfl @[to_additive (attr := simp)] theorem pure_one : pure (1 : α) = 1 := rfl end NonemptyInterval namespace Interval @[to_additive (attr := simp)] theorem pure_one : pure (1 : α) = 1 := rfl @[to_additive] lemma one_ne_bot : (1 : Interval α) ≠ ⊥ := pure_ne_bot @[to_additive] lemma bot_ne_one : (⊥ : Interval α) ≠ 1 := bot_ne_pure end Interval end Preorder section PartialOrder variable [PartialOrder α] [One α] namespace NonemptyInterval @[to_additive (attr := simp)] theorem coe_one : ((1 : NonemptyInterval α) : Set α) = 1 := coe_pure _ @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : NonemptyInterval α) := ⟨le_rfl, le_rfl⟩ end NonemptyInterval namespace Interval @[to_additive (attr := simp)] theorem coe_one : ((1 : Interval α) : Set α) = 1 := Icc_self _ @[to_additive] theorem one_mem_one : (1 : α) ∈ (1 : Interval α) := ⟨le_rfl, le_rfl⟩ end Interval end PartialOrder end One /-! ### Addition/multiplication Note that this multiplication does not apply to `ℚ` or `ℝ`. -/ section Mul variable [Preorder α] [Mul α] [MulLeftMono α] [MulRightMono α] @[to_additive] instance : Mul (NonemptyInterval α) := ⟨fun s t => ⟨s.toProd * t.toProd, mul_le_mul' s.fst_le_snd t.fst_le_snd⟩⟩ @[to_additive] instance : Mul (Interval α) := ⟨Option.map₂ (· * ·)⟩ namespace NonemptyInterval variable (s t : NonemptyInterval α) (a b : α) @[to_additive (attr := simp) toProd_add] theorem toProd_mul : (s * t).toProd = s.toProd * t.toProd := rfl @[to_additive] theorem fst_mul : (s * t).fst = s.fst * t.fst := rfl @[to_additive] theorem snd_mul : (s * t).snd = s.snd * t.snd := rfl @[to_additive (attr := simp)] theorem coe_mul_interval : (↑(s * t) : Interval α) = s * t := rfl @[to_additive (attr := simp)] theorem pure_mul_pure : pure a * pure b = pure (a * b) := rfl end NonemptyInterval namespace Interval variable (s t : Interval α) @[to_additive (attr := simp)] theorem bot_mul : ⊥ * t = ⊥ := rfl @[to_additive] theorem mul_bot : s * ⊥ = ⊥ := Option.map₂_none_right _ _ -- simp can already prove `add_bot` attribute [simp] mul_bot end Interval end Mul /-! ### Powers -/ -- TODO: if `to_additive` gets improved sufficiently, derive this from `hasPow` instance NonemptyInterval.hasNSMul [AddMonoid α] [Preorder α] [AddLeftMono α] [AddRightMono α] : SMul ℕ (NonemptyInterval α) := ⟨fun n s => ⟨(n • s.fst, n • s.snd), nsmul_le_nsmul_right s.fst_le_snd _⟩⟩ section Pow variable [Monoid α] [Preorder α] @[to_additive existing] instance NonemptyInterval.hasPow [MulLeftMono α] [MulRightMono α] : Pow (NonemptyInterval α) ℕ := ⟨fun s n => ⟨s.toProd ^ n, pow_le_pow_left' s.fst_le_snd _⟩⟩ namespace NonemptyInterval variable [MulLeftMono α] [MulRightMono α] variable (s : NonemptyInterval α) (a : α) (n : ℕ) @[to_additive (attr := simp) toProd_nsmul] theorem toProd_pow : (s ^ n).toProd = s.toProd ^ n := rfl @[to_additive] theorem fst_pow : (s ^ n).fst = s.fst ^ n := rfl @[to_additive] theorem snd_pow : (s ^ n).snd = s.snd ^ n := rfl @[to_additive (attr := simp)] theorem pure_pow : pure a ^ n = pure (a ^ n) := rfl end NonemptyInterval end Pow namespace NonemptyInterval @[to_additive] instance commMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] : CommMonoid (NonemptyInterval α) := NonemptyInterval.toProd_injective.commMonoid _ toProd_one toProd_mul toProd_pow end NonemptyInterval @[to_additive] instance Interval.mulOneClass [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] : MulOneClass (Interval α) where mul := (· * ·) one := 1 one_mul s := (Option.map₂_coe_left _ _ _).trans <| by simp_rw [one_mul, ← Function.id_def, Option.map_id, id] mul_one s := (Option.map₂_coe_right _ _ _).trans <| by simp_rw [mul_one, ← Function.id_def, Option.map_id, id] @[to_additive] instance Interval.commMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] : CommMonoid (Interval α) := { Interval.mulOneClass with mul_comm := fun _ _ => Option.map₂_comm mul_comm mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc } namespace NonemptyInterval @[to_additive] theorem coe_pow_interval [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] (s : NonemptyInterval α) (n : ℕ) : ↑(s ^ n) = (s : Interval α) ^ n := map_pow (⟨⟨(↑), coe_one_interval⟩, coe_mul_interval⟩ : NonemptyInterval α →* Interval α) _ _ -- simp can already prove `coe_nsmul_interval` attribute [simp] coe_pow_interval end NonemptyInterval namespace Interval variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] (s : Interval α) {n : ℕ} @[to_additive] theorem bot_pow : ∀ {n : ℕ}, n ≠ 0 → (⊥ : Interval α) ^ n = ⊥ | 0, h => (h rfl).elim | Nat.succ n, _ => mul_bot (⊥ ^ n) end Interval /-! ### Semiring structure When `α` is a canonically `OrderedCommSemiring`, the previous `+` and `*` on `NonemptyInterval α` form a `CommSemiring`. -/ section NatCast variable [Preorder α] [NatCast α] namespace NonemptyInterval instance : NatCast (NonemptyInterval α) where natCast n := pure <| Nat.cast n theorem fst_natCast (n : ℕ) : (n : NonemptyInterval α).fst = n := rfl theorem snd_natCast (n : ℕ) : (n : NonemptyInterval α).snd = n := rfl @[simp] theorem pure_natCast (n : ℕ) : pure (n : α) = n := rfl end NonemptyInterval end NatCast namespace NonemptyInterval instance [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α] : CommSemiring (NonemptyInterval α) := NonemptyInterval.toProd_injective.commSemiring _ toProd_zero toProd_one toProd_add toProd_mul (swap toProd_nsmul) toProd_pow (fun _ => rfl) end NonemptyInterval /-! ### Subtraction Subtraction is defined more generally than division so that it applies to `ℕ` (and `OrderedDiv` is not a thing and probably should not become one). -/ section Sub variable [Preorder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] [AddLeftMono α] instance : Sub (NonemptyInterval α) := ⟨fun s t => ⟨(s.fst - t.snd, s.snd - t.fst), tsub_le_tsub s.fst_le_snd t.fst_le_snd⟩⟩ instance : Sub (Interval α) := ⟨Option.map₂ Sub.sub⟩ namespace NonemptyInterval variable (s t : NonemptyInterval α) {a b : α} @[simp] theorem fst_sub : (s - t).fst = s.fst - t.snd := rfl @[simp] theorem snd_sub : (s - t).snd = s.snd - t.fst := rfl @[simp] theorem coe_sub_interval : (↑(s - t) : Interval α) = s - t := rfl theorem sub_mem_sub (ha : a ∈ s) (hb : b ∈ t) : a - b ∈ s - t := ⟨tsub_le_tsub ha.1 hb.2, tsub_le_tsub ha.2 hb.1⟩ @[simp] theorem pure_sub_pure (a b : α) : pure a - pure b = pure (a - b) := rfl end NonemptyInterval namespace Interval variable (s t : Interval α) @[simp] theorem bot_sub : ⊥ - t = ⊥ := rfl @[simp] theorem sub_bot : s - ⊥ = ⊥ := Option.map₂_none_right _ _ end Interval end Sub /-! ### Division in ordered groups Note that this division does not apply to `ℚ` or `ℝ`. -/ section Div variable [Preorder α] [CommGroup α] [MulLeftMono α] @[to_additive existing] instance : Div (NonemptyInterval α) := ⟨fun s t => ⟨(s.fst / t.snd, s.snd / t.fst), div_le_div'' s.fst_le_snd t.fst_le_snd⟩⟩ @[to_additive existing] instance : Div (Interval α) := ⟨Option.map₂ (· / ·)⟩ namespace NonemptyInterval variable (s t : NonemptyInterval α) (a b : α) @[to_additive existing (attr := simp)] theorem fst_div : (s / t).fst = s.fst / t.snd := rfl @[to_additive existing (attr := simp)] theorem snd_div : (s / t).snd = s.snd / t.fst := rfl @[to_additive existing (attr := simp)] theorem coe_div_interval : (↑(s / t) : Interval α) = s / t := rfl @[to_additive existing] theorem div_mem_div (ha : a ∈ s) (hb : b ∈ t) : a / b ∈ s / t := ⟨div_le_div'' ha.1 hb.2, div_le_div'' ha.2 hb.1⟩ @[to_additive existing (attr := simp)] theorem pure_div_pure : pure a / pure b = pure (a / b) := rfl end NonemptyInterval namespace Interval variable (s t : Interval α) @[to_additive existing (attr := simp)] theorem bot_div : ⊥ / t = ⊥ := rfl @[to_additive existing (attr := simp)] theorem div_bot : s / ⊥ = ⊥ := Option.map₂_none_right _ _ end Interval end Div /-! ### Negation/inversion -/ section Inv variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] @[to_additive] instance : Inv (NonemptyInterval α) := ⟨fun s => ⟨(s.snd⁻¹, s.fst⁻¹), inv_le_inv' s.fst_le_snd⟩⟩ @[to_additive] instance : Inv (Interval α) := ⟨Option.map Inv.inv⟩ namespace NonemptyInterval variable (s t : NonemptyInterval α) (a : α) @[to_additive (attr := simp)] theorem fst_inv : s⁻¹.fst = s.snd⁻¹ := rfl @[to_additive (attr := simp)] theorem snd_inv : s⁻¹.snd = s.fst⁻¹ := rfl @[to_additive (attr := simp)] theorem coe_inv_interval : (↑(s⁻¹) : Interval α) = (↑s)⁻¹ := rfl @[to_additive] theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ := ⟨inv_le_inv' ha.2, inv_le_inv' ha.1⟩ @[to_additive (attr := simp)] theorem inv_pure : (pure a)⁻¹ = pure a⁻¹ := rfl end NonemptyInterval @[to_additive (attr := simp)] theorem Interval.inv_bot : (⊥ : Interval α)⁻¹ = ⊥ := rfl end Inv namespace NonemptyInterval variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : NonemptyInterval α} @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 := by refine ⟨fun h => ?_, ?_⟩ · rw [NonemptyInterval.ext_iff, Prod.ext_iff] at h have := (mul_le_mul_iff_of_ge s.fst_le_snd t.fst_le_snd).1 (h.2.trans h.1.symm).le refine ⟨s.fst, t.fst, ?_, ?_, h.1⟩ <;> apply NonemptyInterval.ext <;> dsimp [pure] · nth_rw 2 [this.1] · nth_rw 2 [this.2] · rintro ⟨b, c, rfl, rfl, h⟩ rw [pure_mul_pure, h, pure_one] instance subtractionCommMonoid {α : Type u} [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] : SubtractionCommMonoid (NonemptyInterval α) := { NonemptyInterval.addCommMonoid with neg := Neg.neg sub := Sub.sub sub_eq_add_neg := fun s t => by refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;> exact sub_eq_add_neg _ _ neg_neg := fun s => by apply NonemptyInterval.ext; exact neg_neg _ neg_add_rev := fun s t => by refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;> exact neg_add_rev _ _ neg_eq_of_add := fun s t h => by obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.add_eq_zero_iff.1 h rw [neg_pure, neg_eq_of_add_eq_zero_right hab] -- TODO: use a better defeq zsmul := zsmulRec } @[to_additive existing NonemptyInterval.subtractionCommMonoid] instance divisionCommMonoid : DivisionCommMonoid (NonemptyInterval α) := { NonemptyInterval.commMonoid with inv := Inv.inv div := (· / ·) div_eq_mul_inv := fun s t => by refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;> exact div_eq_mul_inv _ _ inv_inv := fun s => by apply NonemptyInterval.ext; exact inv_inv _ mul_inv_rev := fun s t => by refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;> exact mul_inv_rev _ _ inv_eq_of_mul := fun s t h => by obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.mul_eq_one_iff.1 h rw [inv_pure, inv_eq_of_mul_eq_one_right hab] } end NonemptyInterval namespace Interval variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : Interval α} @[to_additive] protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 := by cases s · simp cases t · simp · simp_rw [← NonemptyInterval.coe_mul_interval, ← NonemptyInterval.coe_one_interval, WithBot.coe_inj, NonemptyInterval.coe_eq_pure] exact NonemptyInterval.mul_eq_one_iff instance subtractionCommMonoid {α : Type u} [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] : SubtractionCommMonoid (Interval α) := { Interval.addCommMonoid with neg := Neg.neg sub := Sub.sub sub_eq_add_neg := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (sub_eq_add_neg _ _) neg_neg := by rintro (_ | s) <;> first |rfl|exact congr_arg some (neg_neg _) neg_add_rev := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (neg_add_rev _ _) neg_eq_of_add := by rintro (_ | s) (_ | t) h <;> first | cases h | exact congr_arg some (neg_eq_of_add_eq_zero_right <| Option.some_injective _ h) -- TODO: use a better defeq zsmul := zsmulRec } @[to_additive existing Interval.subtractionCommMonoid] instance divisionCommMonoid : DivisionCommMonoid (Interval α) := { Interval.commMonoid with inv := Inv.inv div := (· / ·) div_eq_mul_inv := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (div_eq_mul_inv _ _) inv_inv := by rintro (_ | s) <;> first |rfl|exact congr_arg some (inv_inv _) mul_inv_rev := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (mul_inv_rev _ _) inv_eq_of_mul := by rintro (_ | s) (_ | t) h <;> first | cases h | exact congr_arg some (inv_eq_of_mul_eq_one_right <| Option.some_injective _ h) } end Interval section Length variable [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] namespace NonemptyInterval variable (s t : NonemptyInterval α) (a : α) /-- The length of an interval is its first component minus its second component. This measures the accuracy of the approximation by an interval. -/ def length : α := s.snd - s.fst @[simp] theorem length_nonneg : 0 ≤ s.length := sub_nonneg_of_le s.fst_le_snd omit [IsOrderedAddMonoid α] in @[simp] theorem length_pure : (pure a).length = 0 := sub_self _ omit [IsOrderedAddMonoid α] in @[simp] theorem length_zero : (0 : NonemptyInterval α).length = 0 := length_pure _ @[simp] theorem length_neg : (-s).length = s.length := neg_sub_neg _ _ @[simp] theorem length_add : (s + t).length = s.length + t.length := add_sub_add_comm _ _ _ _ @[simp] theorem length_sub : (s - t).length = s.length + t.length := by simp [sub_eq_add_neg] @[simp] theorem length_sum (f : ι → NonemptyInterval α) (s : Finset ι) : (∑ i ∈ s, f i).length = ∑ i ∈ s, (f i).length := map_sum (⟨⟨length, length_zero⟩, length_add⟩ : NonemptyInterval α →+ α) _ _ end NonemptyInterval namespace Interval variable (s t : Interval α) (a : α) /-- The length of an interval is its first component minus its second component. This measures the accuracy of the approximation by an interval. -/ def length : Interval α → α | ⊥ => 0 | (s : NonemptyInterval α) => s.length @[simp] theorem length_nonneg : ∀ s : Interval α, 0 ≤ s.length | ⊥ => le_rfl | (s : NonemptyInterval α) => s.length_nonneg omit [IsOrderedAddMonoid α] in @[simp] theorem length_pure : (pure a).length = 0 := NonemptyInterval.length_pure _ omit [IsOrderedAddMonoid α] in @[simp] theorem length_zero : (0 : Interval α).length = 0 := length_pure _ @[simp] theorem length_neg : ∀ s : Interval α, (-s).length = s.length | ⊥ => rfl | (s : NonemptyInterval α) => s.length_neg theorem length_add_le : ∀ s t : Interval α, (s + t).length ≤ s.length + t.length | ⊥, _ => by simp | _, ⊥ => by simp | (s : NonemptyInterval α), (t : NonemptyInterval α) => (s.length_add t).le theorem length_sub_le : (s - t).length ≤ s.length + t.length := by simpa [sub_eq_add_neg] using length_add_le s (-t) theorem length_sum_le (f : ι → Interval α) (s : Finset ι) : (∑ i ∈ s, f i).length ≤ ∑ i ∈ s, (f i).length := Finset.le_sum_of_subadditive _ length_zero length_add_le _ _ end Interval end Length namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: The length of an interval is always nonnegative. -/ @[positivity NonemptyInterval.length _] def evalNonemptyIntervalLength : PositivityExt where eval {u α} _ _ e := do let ~q(@NonemptyInterval.length _ $ig $ipo $a) := e | throwError "not NonemptyInterval.length" let _i ← synthInstanceQ q(IsOrderedAddMonoid $α) assertInstancesCommute return .nonnegative q(NonemptyInterval.length_nonneg $a) /-- Extension for the `positivity` tactic: The length of an interval is always nonnegative. -/ @[positivity Interval.length _] def evalIntervalLength : PositivityExt where eval {u α} _ _ e := do let ~q(@Interval.length _ $ig $ipo $a) := e | throwError "not Interval.length" let _i ← synthInstanceQ q(IsOrderedAddMonoid $α) assumeInstancesCommute return .nonnegative q(Interval.length_nonneg $a) end Mathlib.Meta.Positivity
Mathlib/Algebra/Order/Interval/Basic.lean
700
703
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Mario Carneiro, Sean Leather -/ import Mathlib.Data.Finset.Card import Mathlib.Data.Finset.Union /-! # Finite sets in `Option α` In this file we define * `Option.toFinset`: construct an empty or singleton `Finset α` from an `Option α`; * `Finset.insertNone`: given `s : Finset α`, lift it to a finset on `Option α` using `Option.some` and then insert `Option.none`; * `Finset.eraseNone`: given `s : Finset (Option α)`, returns `t : Finset α` such that `x ∈ t ↔ some x ∈ s`. Then we prove some basic lemmas about these definitions. ## Tags finset, option -/ variable {α β : Type*} open Function namespace Option /-- Construct an empty or singleton finset from an `Option` -/ def toFinset (o : Option α) : Finset α := o.elim ∅ singleton @[simp] theorem toFinset_none : none.toFinset = (∅ : Finset α) := rfl @[simp] theorem toFinset_some {a : α} : (some a).toFinset = {a} := rfl @[simp] theorem mem_toFinset {a : α} {o : Option α} : a ∈ o.toFinset ↔ a ∈ o := by cases o <;> simp [eq_comm] theorem card_toFinset (o : Option α) : o.toFinset.card = o.elim 0 1 := by cases o <;> rfl end Option namespace Finset /-- Given a finset on `α`, lift it to being a finset on `Option α` using `Option.some` and then insert `Option.none`. -/ def insertNone : Finset α ↪o Finset (Option α) := (OrderEmbedding.ofMapLEIff fun s => cons none (s.map Embedding.some) <| by simp) fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset] @[simp] theorem mem_insertNone {s : Finset α} : ∀ {o : Option α}, o ∈ insertNone s ↔ ∀ a ∈ o, a ∈ s | none => iff_of_true (Multiset.mem_cons_self _ _) fun a h => by cases h | some a => Multiset.mem_cons.trans <| by simp lemma forall_mem_insertNone {s : Finset α} {p : Option α → Prop} : (∀ a ∈ insertNone s, p a) ↔ p none ∧ ∀ a ∈ s, p a := by simp [Option.forall] theorem some_mem_insertNone {s : Finset α} {a : α} : some a ∈ insertNone s ↔ a ∈ s := by simp lemma none_mem_insertNone {s : Finset α} : none ∈ insertNone s := by simp @[aesop safe apply (rule_sets := [finsetNonempty])] lemma insertNone_nonempty {s : Finset α} : insertNone s |>.Nonempty := ⟨none, none_mem_insertNone⟩ @[simp] theorem card_insertNone (s : Finset α) : s.insertNone.card = s.card + 1 := by simp [insertNone] /-- Given `s : Finset (Option α)`, `eraseNone s : Finset α` is the set of `x : α` such that `some x ∈ s`. -/ def eraseNone : Finset (Option α) →o Finset α := (Finset.mapEmbedding (Equiv.optionIsSomeEquiv α).toEmbedding).toOrderHom.comp ⟨Finset.subtype _, subtype_mono⟩ @[simp] theorem mem_eraseNone {s : Finset (Option α)} {x : α} : x ∈ eraseNone s ↔ some x ∈ s := by simp [eraseNone] lemma forall_mem_eraseNone {s : Finset (Option α)} {p : Option α → Prop} : (∀ a ∈ eraseNone s, p a) ↔ ∀ a : α, (a : Option α) ∈ s → p a := by simp [Option.forall] theorem eraseNone_eq_biUnion [DecidableEq α] (s : Finset (Option α)) : eraseNone s = s.biUnion Option.toFinset := by ext simp @[simp] theorem eraseNone_map_some (s : Finset α) : eraseNone (s.map Embedding.some) = s := by ext simp @[simp] theorem eraseNone_image_some [DecidableEq (Option α)] (s : Finset α) : eraseNone (s.image some) = s := by simpa only [map_eq_image] using eraseNone_map_some s @[simp] theorem coe_eraseNone (s : Finset (Option α)) : (eraseNone s : Set α) = some ⁻¹' s := Set.ext fun _ => mem_eraseNone @[simp] theorem eraseNone_union [DecidableEq (Option α)] [DecidableEq α] (s t : Finset (Option α)) : eraseNone (s ∪ t) = eraseNone s ∪ eraseNone t := by ext simp @[simp] theorem eraseNone_inter [DecidableEq (Option α)] [DecidableEq α] (s t : Finset (Option α)) : eraseNone (s ∩ t) = eraseNone s ∩ eraseNone t := by ext simp @[simp] theorem eraseNone_empty : eraseNone (∅ : Finset (Option α)) = ∅ := by ext simp @[simp] theorem eraseNone_none : eraseNone ({none} : Finset (Option α)) = ∅ := by ext simp @[simp] theorem image_some_eraseNone [DecidableEq (Option α)] (s : Finset (Option α)) : (eraseNone s).image some = s.erase none := by ext (_ | x) <;> simp @[simp] theorem map_some_eraseNone [DecidableEq (Option α)] (s : Finset (Option α)) : (eraseNone s).map Embedding.some = s.erase none := by rw [map_eq_image, Embedding.some_apply, image_some_eraseNone] @[simp] theorem insertNone_eraseNone [DecidableEq (Option α)] (s : Finset (Option α)) : insertNone (eraseNone s) = insert none s := by ext (_ | x) <;> simp @[simp] theorem eraseNone_insertNone (s : Finset α) : eraseNone (insertNone s) = s := by ext simp end Finset
Mathlib/Data/Finset/Option.lean
159
161
/- 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 -/ import Mathlib.Data.Nat.Lattice import Mathlib.Data.Set.Accumulate import Mathlib.Data.Set.Pairwise.Lattice import Mathlib.MeasureTheory.PiSystem /-! # Semirings and rings of sets A semi-ring of sets `C` (in the sense of measure theory) is a family of sets containing `∅`, stable by intersection and such that for all `s, t ∈ C`, `t \ s` is equal to a disjoint union of finitely many sets in `C`. Note that a semi-ring of sets may not contain unions. An important example of a semi-ring of sets is intervals in `ℝ`. The intersection of two intervals is an interval (possibly empty). The union of two intervals may not be an interval. The set difference of two intervals may not be an interval, but it will be a disjoint union of two intervals. A ring of sets is a set of sets containing `∅`, stable by union, set difference and intersection. ## Main definitions * `MeasureTheory.IsSetSemiring C`: property of being a semi-ring of sets. * `MeasureTheory.IsSetSemiring.disjointOfDiff hs ht`: for `s, t` in a semi-ring `C` (with `hC : IsSetSemiring C`) with `hs : s ∈ C`, `ht : t ∈ C`, this is a `Finset` of pairwise disjoint sets such that `s \ t = ⋃₀ hC.disjointOfDiff hs ht`. * `MeasureTheory.IsSetSemiring.disjointOfDiffUnion hs hI`: for `hs : s ∈ C` and a finset `I` of sets in `C` (with `hI : ↑I ⊆ C`), this is a `Finset` of pairwise disjoint sets such that `s \ ⋃₀ I = ⋃₀ hC.disjointOfDiffUnion hs hI`. * `MeasureTheory.IsSetSemiring.disjointOfUnion hJ`: for `hJ ⊆ C`, this is a `Finset` of pairwise disjoint sets such that `⋃₀ J = ⋃₀ hC.disjointOfUnion hJ`. * `MeasureTheory.IsSetRing`: property of being a ring of sets. ## Main statements * `MeasureTheory.IsSetSemiring.exists_disjoint_finset_diff_eq`: the existence of the `Finset` given by the definition `IsSetSemiring.disjointOfDiffUnion` (see above). * `MeasureTheory.IsSetSemiring.disjointOfUnion_props`: In a `hC : IsSetSemiring C`, for a `J : Finset (Set α)` with `J ⊆ C`, there is for every `x in J` some `K x ⊆ C` finite, such that * `⋃ x ∈ J, K x` are pairwise disjoint and do not contain ∅, * `⋃ s ∈ K x, s ⊆ x`, * `⋃ x ∈ J, x = ⋃ x ∈ J, ⋃ s ∈ K x, s`. -/ open Finset Set namespace MeasureTheory variable {α : Type*} {C : Set (Set α)} {s t : Set α} /-- A semi-ring of sets `C` is a family of sets containing `∅`, stable by intersection and such that for all `s, t ∈ C`, `s \ t` is equal to a disjoint union of finitely many sets in `C`. -/ structure IsSetSemiring (C : Set (Set α)) : Prop where empty_mem : ∅ ∈ C inter_mem : ∀ s ∈ C, ∀ t ∈ C, s ∩ t ∈ C diff_eq_sUnion' : ∀ s ∈ C, ∀ t ∈ C, ∃ I : Finset (Set α), ↑I ⊆ C ∧ PairwiseDisjoint (I : Set (Set α)) id ∧ s \ t = ⋃₀ I namespace IsSetSemiring lemma isPiSystem (hC : IsSetSemiring C) : IsPiSystem C := fun s hs t ht _ ↦ hC.inter_mem s hs t ht section disjointOfDiff open scoped Classical in /-- In a semi-ring of sets `C`, for all sets `s, t ∈ C`, `s \ t` is equal to a disjoint union of finitely many sets in `C`. The finite set of sets in the union is not unique, but this definition gives an arbitrary `Finset (Set α)` that satisfies the equality. We remove the empty set to ensure that `t ∉ hC.disjointOfDiff hs ht` even if `t = ∅`. -/ noncomputable def disjointOfDiff (hC : IsSetSemiring C) (hs : s ∈ C) (ht : t ∈ C) : Finset (Set α) := (hC.diff_eq_sUnion' s hs t ht).choose \ {∅} lemma empty_nmem_disjointOfDiff (hC : IsSetSemiring C) (hs : s ∈ C) (ht : t ∈ C) : ∅ ∉ hC.disjointOfDiff hs ht := by
classical simp only [disjointOfDiff, mem_sdiff, Finset.mem_singleton, eq_self_iff_true, not_true, and_false, not_false_iff] lemma subset_disjointOfDiff (hC : IsSetSemiring C) (hs : s ∈ C) (ht : t ∈ C) : ↑(hC.disjointOfDiff hs ht) ⊆ C := by
Mathlib/MeasureTheory/SetSemiring.lean
83
88
/- 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] 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] exact toSesqForm_apply_norm_le · nth_rw 1 [← adjointAux_adjointAux A] refine ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) fun x => ?_ rw [adjointAux_apply, LinearIsometryEquiv.norm_map] exact toSesqForm_apply_norm_le /-- The adjoint of a bounded operator `A` from a Hilbert space `E` to another Hilbert space `F`, denoted as `A†`. -/ def adjoint : (E →L[𝕜] F) ≃ₗᵢ⋆[𝕜] F →L[𝕜] E := LinearIsometryEquiv.ofSurjective { adjointAux with norm_map' := adjointAux_norm } fun A => ⟨adjointAux A, adjointAux_adjointAux A⟩ @[inherit_doc] scoped[InnerProduct] postfix:1000 "†" => ContinuousLinearMap.adjoint open InnerProduct /-- The fundamental property of the adjoint. -/ theorem adjoint_inner_left (A : E →L[𝕜] F) (x : E) (y : F) : ⟪(A†) y, x⟫ = ⟪y, A x⟫ := adjointAux_inner_left A x y /-- The fundamental property of the adjoint. -/ theorem adjoint_inner_right (A : E →L[𝕜] F) (x : E) (y : F) : ⟪x, (A†) y⟫ = ⟪A x, y⟫ := adjointAux_inner_right A x y /-- The adjoint is involutive. -/ @[simp] theorem adjoint_adjoint (A : E →L[𝕜] F) : A†† = A := adjointAux_adjointAux A /-- The adjoint of the composition of two operators is the composition of the two adjoints in reverse order. -/ @[simp] theorem adjoint_comp (A : F →L[𝕜] G) (B : E →L[𝕜] F) : (A ∘L B)† = B† ∘L A† := by ext v refine ext_inner_left 𝕜 fun w => ?_ simp only [adjoint_inner_right, ContinuousLinearMap.coe_comp', Function.comp_apply] theorem apply_norm_sq_eq_inner_adjoint_left (A : E →L[𝕜] F) (x : E) : ‖A x‖ ^ 2 = re ⟪(A† ∘L A) x, x⟫ := by have h : ⟪(A† ∘L A) x, x⟫ = ⟪A x, A x⟫ := by rw [← adjoint_inner_left]; rfl rw [h, ← inner_self_eq_norm_sq (𝕜 := 𝕜) _] theorem apply_norm_eq_sqrt_inner_adjoint_left (A : E →L[𝕜] F) (x : E) : ‖A x‖ = √(re ⟪(A† ∘L A) x, x⟫) := by rw [← apply_norm_sq_eq_inner_adjoint_left, Real.sqrt_sq (norm_nonneg _)] theorem apply_norm_sq_eq_inner_adjoint_right (A : E →L[𝕜] F) (x : E) : ‖A x‖ ^ 2 = re ⟪x, (A† ∘L A) x⟫ := by have h : ⟪x, (A† ∘L A) x⟫ = ⟪A x, A x⟫ := by rw [← adjoint_inner_right]; rfl rw [h, ← inner_self_eq_norm_sq (𝕜 := 𝕜) _] theorem apply_norm_eq_sqrt_inner_adjoint_right (A : E →L[𝕜] F) (x : E) : ‖A x‖ = √(re ⟪x, (A† ∘L A) x⟫) := by rw [← apply_norm_sq_eq_inner_adjoint_right, Real.sqrt_sq (norm_nonneg _)] /-- The adjoint is unique: a map `A` is the adjoint of `B` iff it satisfies `⟪A x, y⟫ = ⟪x, B y⟫` for all `x` and `y`. -/ theorem eq_adjoint_iff (A : E →L[𝕜] F) (B : F →L[𝕜] E) : A = B† ↔ ∀ x y, ⟪A x, y⟫ = ⟪x, B y⟫ := by refine ⟨fun h x y => by rw [h, adjoint_inner_left], fun h => ?_⟩ ext x exact ext_inner_right 𝕜 fun y => by simp only [adjoint_inner_left, h x y] @[simp] theorem adjoint_id : ContinuousLinearMap.adjoint (ContinuousLinearMap.id 𝕜 E) = ContinuousLinearMap.id 𝕜 E := by
refine Eq.symm ?_ rw [eq_adjoint_iff] simp
Mathlib/Analysis/InnerProductSpace/Adjoint.lean
161
163
/- 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) _
Mathlib/Dynamics/Newton.lean
81
99
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Riccardo Brasca -/ import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Analysis.Normed.Group.Hom import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Quotients of seminormed groups For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M`, we provide a `SeminormedAddCommGroup`, the group quotient `M ⧸ S`. If `S` is closed, we provide `NormedAddCommGroup (M ⧸ S)` (regardless of whether `M` itself is separated). The two main properties of these structures are the underlying topology is the quotient topology and the projection is a normed group homomorphism which is norm non-increasing (better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding universal property is that every normed group hom defined on `M` which vanishes on `S` descends to a normed group hom defined on `M ⧸ S`. This file also introduces a predicate `IsQuotient` characterizing normed group homs that are isomorphic to the canonical projection onto a normed group quotient. In addition, this file also provides normed structures for quotients of modules by submodules, and of (commutative) rings by ideals. The `SeminormedAddCommGroup` and `NormedAddCommGroup` instances described above are transferred directly, but we also define instances of `NormedSpace`, `SeminormedCommRing`, `NormedCommRing` and `NormedAlgebra` under appropriate type class assumptions on the original space. Moreover, while `QuotientAddGroup.completeSpace` works out-of-the-box for quotients of `NormedAddCommGroup`s by `AddSubgroup`s, we need to transfer this instance in `Submodule.Quotient.completeSpace` so that it applies to these other quotients. ## Main definitions We use `M` and `N` to denote seminormed groups and `S : AddSubgroup M`. All the following definitions are in the `AddSubgroup` namespace. Hence we can access `AddSubgroup.normedMk S` as `S.normedMk`. * `seminormedAddCommGroupQuotient` : The seminormed group structure on the quotient by an additive subgroup. This is an instance so there is no need to explicitly use it. * `normedAddCommGroupQuotient` : The normed group structure on the quotient by a closed additive subgroup. This is an instance so there is no need to explicitly use it. * `normedMk S` : the normed group hom from `M` to `M ⧸ S`. * `lift S f hf`: implements the universal property of `M ⧸ S`. Here `(f : NormedAddGroupHom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and `lift S f hf : NormedAddGroupHom (M ⧸ S) N`. * `IsQuotient`: given `f : NormedAddGroupHom M N`, `IsQuotient f` means `N` is isomorphic to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`. ## Main results * `norm_normedMk` : the operator norm of the projection is `1` if the subspace is not dense. * `IsQuotient.norm_lift`: Provided `f : normed_hom M N` satisfies `IsQuotient f`, for every `n : N` and positive `ε`, there exists `m` such that `f m = n ∧ ‖m‖ < ‖n‖ + ε`. ## Implementation details For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M` we define a norm on `M ⧸ S` by `‖x‖ = sInf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it shouldn't be needed outside of this file setting up the theory. Since `M ⧸ S` is automatically a topological space (as any quotient of a topological space), one needs to be careful while defining the `SeminormedAddCommGroup` instance to avoid having two different topologies on this quotient. This is not purely a technological issue. Mathematically there is something to prove. The main point is proved in the auxiliary lemma `quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient admits as basis of neighborhoods in the quotient topology the sets `{x | ‖x‖ < ε}` for positive `ε`. Once this mathematical point is settled, we have two topologies that are propositionally equal. This is not good enough for the type class system. As usual we ensure *definitional* equality using forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure includes a uniform space structure which includes a topological space structure, together with propositional fields asserting compatibility conditions. The usual way to define a `SeminormedAddCommGroup` is to let Lean build a uniform space structure using the provided norm, and then trivially build a proof that the norm and uniform structure are compatible. Here the uniform structure is provided using `IsTopologicalAddGroup.toUniformSpace` which uses the topological structure and the group structure to build the uniform structure. This uniform structure induces the correct topological structure by construction, but the fact that it is compatible with the norm is not obvious; this is where the mathematical content explained in the previous paragraph kicks in. -/ noncomputable section open Metric Set Topology NNReal namespace QuotientGroup variable {M : Type*} [SeminormedCommGroup M] {S : Subgroup M} {x : M ⧸ S} {m : M} {r ε : ℝ} @[to_additive add_norm_aux] private lemma norm_aux (x : M ⧸ S) : {m : M | (m : M ⧸ S) = x}.Nonempty := Quot.exists_rep x /-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x * M`. -/ @[to_additive "The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x + S`."] noncomputable def groupSeminorm : GroupSeminorm (M ⧸ S) where toFun x := infDist 1 {m : M | (m : M ⧸ S) = x} map_one' := infDist_zero_of_mem (by simpa using S.one_mem) mul_le' x y := by simp only [infDist_eq_iInf] have := (norm_aux x).to_subtype have := (norm_aux y).to_subtype refine le_ciInf_add_ciInf ?_ rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ciInf_le_of_le ⟨0, forall_mem_range.2 fun _ ↦ dist_nonneg⟩ ⟨a * b, rfl⟩ ?_ simpa using norm_mul_le' _ _ inv' x := eq_of_forall_le_iff fun r ↦ by simp only [le_infDist (norm_aux _)] exact (Equiv.inv _).forall_congr (by simp [← inv_eq_iff_eq_inv]) /-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x * S`. -/ @[to_additive "The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x + S`."] noncomputable instance instNorm : Norm (M ⧸ S) where norm := groupSeminorm @[to_additive] lemma norm_eq_groupSeminorm (x : M ⧸ S) : ‖x‖ = groupSeminorm x := rfl @[to_additive] lemma norm_eq_infDist (x : M ⧸ S) : ‖x‖ = infDist 1 {m : M | (m : M ⧸ S) = x} := rfl @[to_additive] lemma le_norm_iff : r ≤ ‖x‖ ↔ ∀ m : M, ↑m = x → r ≤ ‖m‖ := by simp [norm_eq_infDist, le_infDist (norm_aux _)] @[to_additive] lemma norm_lt_iff : ‖x‖ < r ↔ ∃ m : M, ↑m = x ∧ ‖m‖ < r := by simp [norm_eq_infDist, infDist_lt_iff (norm_aux _)] @[to_additive] lemma nhds_one_hasBasis : (𝓝 (1 : M ⧸ S)).HasBasis (fun ε ↦ 0 < ε) fun ε ↦ {x | ‖x‖ < ε} := by have : ∀ ε : ℝ, mk '' ball (1 : M) ε = {x : M ⧸ S | ‖x‖ < ε} := by refine fun ε ↦ Set.ext <| forall_mk.2 fun x ↦ ?_ rw [ball_one_eq, mem_setOf_eq, norm_lt_iff, mem_image] exact exists_congr fun _ ↦ and_comm rw [← mk_one, nhds_eq, ← funext this] exact .map _ Metric.nhds_basis_ball /-- An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is equal to the distance from `x` to `S`. -/ @[to_additive "An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is equal to the distance from `x` to `S`."] lemma norm_mk (x : M) : ‖(x : M ⧸ S)‖ = infDist x S := by rw [norm_eq_infDist, ← infDist_image (IsometryEquiv.divLeft x).isometry, ← IsometryEquiv.preimage_symm] simp /-- The norm of the projection is smaller or equal to the norm of the original element. -/ @[to_additive "The norm of the projection is smaller or equal to the norm of the original element."] lemma norm_mk_le_norm : ‖(m : M ⧸ S)‖ ≤ ‖m‖ := (infDist_le_dist_of_mem (by simp)).trans_eq (dist_one_left _) /-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs to the closure of `S`. -/ @[to_additive "The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs to the closure of `S`."] lemma norm_mk_eq_zero_iff_mem_closure : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ closure (S : Set M) := by rw [norm_mk, ← mem_closure_iff_infDist_zero] exact ⟨1, S.one_mem⟩ /-- The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if and only if `m ∈ S`. -/ @[to_additive "The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if and only if `m ∈ S`."] lemma norm_mk_eq_zero [hS : IsClosed (S : Set M)] : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ S := by rw [norm_mk_eq_zero_iff_mem_closure, hS.closure_eq, SetLike.mem_coe] /-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x` and `‖m‖ < ‖x‖ + ε`. -/ @[to_additive "For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x` and `‖m‖ < ‖x‖ + ε`."] lemma exists_norm_mk_lt (x : M ⧸ S) (hε : 0 < ε) : ∃ m : M, m = x ∧ ‖m‖ < ‖x‖ + ε := norm_lt_iff.1 <| lt_add_of_pos_right _ hε /-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m * s‖ < ‖mk' S m‖ + ε`. -/ @[to_additive "For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m + s‖ < ‖mk' S m‖ + ε`."] lemma exists_norm_mul_lt (S : Subgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) : ∃ s ∈ S, ‖m * s‖ < ‖mk' S m‖ + ε := by obtain ⟨n : M, hn, hn'⟩ := exists_norm_mk_lt (QuotientGroup.mk' S m) hε exact ⟨m⁻¹ * n, by simpa [eq_comm, QuotientGroup.eq] using hn, by simpa⟩ variable (S) in /-- The seminormed group structure on the quotient by a subgroup. -/ @[to_additive "The seminormed group structure on the quotient by an additive subgroup."] noncomputable instance instSeminormedCommGroup : SeminormedCommGroup (M ⧸ S) where toUniformSpace := IsTopologicalGroup.toUniformSpace (M ⧸ S) __ := groupSeminorm.toSeminormedCommGroup uniformity_dist := by rw [uniformity_eq_comap_nhds_one', (nhds_one_hasBasis.comap _).eq_biInf] simp only [dist, preimage_setOf_eq, norm_eq_groupSeminorm, map_div_rev] variable (S) in /-- The quotient in the category of normed groups. -/ @[to_additive "The quotient in the category of normed groups."] noncomputable instance instNormedCommGroup [hS : IsClosed (S : Set M)] : NormedCommGroup (M ⧸ S) where __ := MetricSpace.ofT0PseudoMetricSpace _ -- This is a sanity check left here on purpose to ensure that potential refactors won't destroy -- this important property. example : (instTopologicalSpaceQuotient : TopologicalSpace <| M ⧸ S) = (instSeminormedCommGroup S).toUniformSpace.toTopologicalSpace := rfl example [IsClosed (S : Set M)] : (instSeminormedCommGroup S) = NormedCommGroup.toSeminormedCommGroup := rfl end QuotientGroup open QuotientAddGroup Metric Set Topology NNReal variable {M N : Type*} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] /-- The definition of the norm on the quotient by an additive subgroup. -/ @[deprecated QuotientAddGroup.instNorm (since := "2025-02-02")] noncomputable def normOnQuotient (S : AddSubgroup M) : Norm (M ⧸ S) := inferInstance @[deprecated QuotientAddGroup.norm_eq_infDist (since := "2025-02-02")] theorem AddSubgroup.quotient_norm_eq {S : AddSubgroup M} (x : M ⧸ S) : ‖x‖ = sInf (norm '' { m : M | (m : M ⧸ S) = x }) := by simp only [norm_eq_infDist, infDist_eq_iInf, sInf_image', dist_zero_left] @[deprecated "Replaced by a private lemma" (since := "2025-02-02")] theorem image_norm_nonempty {S : AddSubgroup M} (x : M ⧸ S) : (norm '' { m | mk' S m = x }).Nonempty := .image _ <| Quot.exists_rep x @[deprecated norm_nonneg (since := "2025-02-02")] theorem bddBelow_image_norm (s : Set M) : BddBelow (norm '' s) := ⟨0, forall_mem_image.2 fun _ _ ↦ norm_nonneg _⟩ @[deprecated isGLB_infDist (since := "2025-02-02")] theorem isGLB_quotient_norm {S : AddSubgroup M} (x : M ⧸ S) : IsGLB (norm '' { m | mk' S m = x }) (‖x‖) := by simpa using isGLB_infDist (QuotientGroup.add_norm_aux x) (x := 0) /-- The norm on the quotient satisfies `‖-x‖ = ‖x‖`. -/ @[deprecated norm_neg (since := "2025-02-02")] theorem quotient_norm_neg {S : AddSubgroup M} (x : M ⧸ S) : ‖-x‖ = ‖x‖ := norm_neg _ @[deprecated norm_sub_rev (since := "2025-02-02")] theorem quotient_norm_sub_rev {S : AddSubgroup M} (x y : M ⧸ S) : ‖x - y‖ = ‖y - x‖ := norm_sub_rev .. /-- The norm of the projection is smaller or equal to the norm of the original element. -/ @[deprecated QuotientAddGroup.norm_mk_le_norm (since := "2025-02-02")] theorem quotient_norm_mk_le (S : AddSubgroup M) (m : M) : ‖mk' S m‖ ≤ ‖m‖ := norm_mk_le_norm /-- The norm of the projection is smaller or equal to the norm of the original element. -/ @[deprecated QuotientAddGroup.norm_mk_le_norm (since := "2025-02-02")] theorem quotient_norm_mk_le' (S : AddSubgroup M) (m : M) : ‖(m : M ⧸ S)‖ ≤ ‖m‖ := norm_mk_le_norm /-- The norm of the image under the natural morphism to the quotient. -/ theorem quotient_norm_mk_eq (S : AddSubgroup M) (m : M) : ‖mk' S m‖ = sInf ((‖m + ·‖) '' S) := by rw [mk'_apply, norm_mk, sInf_image', ← infDist_image isometry_neg, image_neg_eq_neg, neg_coe_set (H := S), infDist_eq_iInf] simp only [dist_eq_norm', sub_neg_eq_add, add_comm] /-- The quotient norm is nonnegative. -/ @[deprecated norm_nonneg (since := "2025-02-02")] theorem quotient_norm_nonneg (S : AddSubgroup M) (x : M ⧸ S) : 0 ≤ ‖x‖ := norm_nonneg _ /-- The quotient norm is nonnegative. -/ @[deprecated norm_nonneg (since := "2025-02-02")] theorem norm_mk_nonneg (S : AddSubgroup M) (m : M) : 0 ≤ ‖mk' S m‖ := norm_nonneg _ /-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs to the closure of `S`. -/ @[deprecated QuotientAddGroup.norm_mk_eq_zero_iff_mem_closure (since := "2025-02-02")] theorem quotient_norm_eq_zero_iff (S : AddSubgroup M) (m : M) : ‖mk' S m‖ = 0 ↔ m ∈ closure (S : Set M) := norm_mk_eq_zero_iff_mem_closure /-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x` and `‖m‖ < ‖x‖ + ε`. -/ @[deprecated QuotientAddGroup.exists_norm_mk_lt (since := "2025-02-02")] theorem norm_mk_lt {S : AddSubgroup M} (x : M ⧸ S) {ε : ℝ} (hε : 0 < ε) : ∃ m : M, mk' S m = x ∧ ‖m‖ < ‖x‖ + ε := exists_norm_mk_lt _ hε /-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m + s‖ < ‖mk' S m‖ + ε`. -/ @[deprecated QuotientAddGroup.exists_norm_add_lt (since := "2025-02-02")] theorem norm_mk_lt' (S : AddSubgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) : ∃ s ∈ S, ‖m + s‖ < ‖mk' S m‖ + ε := exists_norm_add_lt _ _ hε /-- The quotient norm satisfies the triangle inequality. -/ theorem quotient_norm_add_le (S : AddSubgroup M) (x y : M ⧸ S) : ‖x + y‖ ≤ ‖x‖ + ‖y‖ := by rcases And.intro (mk_surjective x) (mk_surjective y) with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ simp only [← mk'_apply, ← map_add, quotient_norm_mk_eq, sInf_image'] refine le_ciInf_add_ciInf fun a b ↦ ?_ refine ciInf_le_of_le ⟨0, forall_mem_range.2 fun _ ↦ norm_nonneg _⟩ (a + b) ?_ exact (congr_arg norm (add_add_add_comm _ _ _ _)).trans_le (norm_add_le _ _) /-- The quotient norm of `0` is `0`. -/ @[deprecated norm_zero (since := "2025-02-02")] theorem norm_mk_zero (S : AddSubgroup M) : ‖(0 : M ⧸ S)‖ = 0 := norm_zero /-- If `(m : M)` has norm equal to `0` in `M ⧸ S` for a closed subgroup `S` of `M`, then `m ∈ S`. -/ @[deprecated QuotientAddGroup.norm_mk_eq_zero (since := "2025-02-02")] theorem norm_mk_eq_zero (S : AddSubgroup M) (hS : IsClosed (S : Set M)) (m : M) (h : ‖mk' S m‖ = 0) : m ∈ S := QuotientAddGroup.norm_mk_eq_zero.1 h @[deprecated QuotientAddGroup.nhds_zero_hasBasis (since := "2025-02-02")] theorem quotient_nhd_basis (S : AddSubgroup M) : (𝓝 (0 : M ⧸ S)).HasBasis (fun ε ↦ 0 < ε) fun ε ↦ { x | ‖x‖ < ε } := nhds_zero_hasBasis /-- The seminormed group structure on the quotient by an additive subgroup. -/ @[deprecated QuotientAddGroup.instSeminormedAddCommGroup (since := "2025-02-02")] noncomputable def AddSubgroup.seminormedAddCommGroupQuotient (S : AddSubgroup M) : SeminormedAddCommGroup (M ⧸ S) := inferInstance /-- The quotient in the category of normed groups. -/ @[deprecated QuotientAddGroup.instNormedAddCommGroup (since := "2025-02-02")] noncomputable instance AddSubgroup.normedAddCommGroupQuotient (S : AddSubgroup M) [IsClosed (S : Set M)] : NormedAddCommGroup (M ⧸ S) := inferInstance namespace AddSubgroup open NormedAddGroupHom /-- The morphism from a seminormed group to the quotient by a subgroup. -/ noncomputable def normedMk (S : AddSubgroup M) : NormedAddGroupHom M (M ⧸ S) where __ := QuotientAddGroup.mk' S bound' := ⟨1, fun m => by simpa [one_mul] using norm_mk_le_norm⟩ /-- `S.normedMk` agrees with `QuotientAddGroup.mk' S`. -/ @[simp] theorem normedMk.apply (S : AddSubgroup M) (m : M) : normedMk S m = QuotientAddGroup.mk' S m := rfl /-- `S.normedMk` is surjective. -/ theorem surjective_normedMk (S : AddSubgroup M) : Function.Surjective (normedMk S) := Quot.mk_surjective /-- The kernel of `S.normedMk` is `S`. -/ theorem ker_normedMk (S : AddSubgroup M) : S.normedMk.ker = S := QuotientAddGroup.ker_mk' _ /-- The operator norm of the projection is at most `1`. -/ theorem norm_normedMk_le (S : AddSubgroup M) : ‖S.normedMk‖ ≤ 1 := NormedAddGroupHom.opNorm_le_bound _ zero_le_one fun m => by simp [norm_mk_le_norm] theorem _root_.QuotientAddGroup.norm_lift_apply_le {S : AddSubgroup M} (f : NormedAddGroupHom M N) (hf : ∀ x ∈ S, f x = 0) (x : M ⧸ S) : ‖lift S f.toAddMonoidHom hf x‖ ≤ ‖f‖ * ‖x‖ := by cases (norm_nonneg f).eq_or_gt with | inl h => rcases mk_surjective x with ⟨x, rfl⟩ simpa [h] using le_opNorm f x | inr h => rw [← not_lt, ← lt_div_iff₀' h, norm_lt_iff] rintro ⟨x, rfl, hx⟩ exact ((lt_div_iff₀' h).1 hx).not_le (le_opNorm f x) /-- The operator norm of the projection is `1` if the subspace is not dense. -/ theorem norm_normedMk (S : AddSubgroup M) (h : (S.topologicalClosure : Set M) ≠ univ) : ‖S.normedMk‖ = 1 := by refine le_antisymm (norm_normedMk_le S) ?_ obtain ⟨x, hx⟩ : ∃ x : M, 0 < ‖(x : M ⧸ S)‖ := by refine (Set.nonempty_compl.2 h).imp fun x hx ↦ ?_ exact (norm_nonneg _).lt_of_ne' <| mt norm_mk_eq_zero_iff_mem_closure.1 hx
refine (le_mul_iff_one_le_left hx).1 ?_ exact norm_lift_apply_le S.normedMk (fun x ↦ (eq_zero_iff x).2) x /-- The operator norm of the projection is `0` if the subspace is dense. -/ theorem norm_trivial_quotient_mk (S : AddSubgroup M) (h : (S.topologicalClosure : Set M) = Set.univ) : ‖S.normedMk‖ = 0 := by refine le_antisymm (opNorm_le_bound _ le_rfl fun x => ?_) (norm_nonneg _) have hker : x ∈ S.normedMk.ker.topologicalClosure := by rw [S.ker_normedMk, ← SetLike.mem_coe, h] trivial
Mathlib/Analysis/Normed/Group/Quotient.lean
378
387
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Data.Int.Cast.Pi import Mathlib.Data.Nat.Cast.Basic import Mathlib.MeasureTheory.MeasurableSpace.Defs /-! # Measurable spaces and measurable functions This file provides properties of measurable spaces and the functions and isomorphisms between them. The definition of a measurable space is in `Mathlib/MeasureTheory/MeasurableSpace/Defs.lean`. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. A function `f : α → β` induces a Galois connection between the lattices of σ-algebras on `α` and `β`. ## Implementation notes Measurability of a function `f : α → β` between measurable spaces is defined in terms of the Galois connection induced by `f`. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function, dynkin system, π-λ theorem, π-system -/ open Set MeasureTheory universe uι variable {α β γ : Type*} {ι : Sort uι} {s : Set α} namespace MeasurableSpace section Functors variable {m m₁ m₂ : MeasurableSpace α} {m' : MeasurableSpace β} {f : α → β} {g : β → α} /-- The forward image of a measurable space under a function. `map f m` contains the sets `s : Set β` whose preimage under `f` is measurable. -/ protected def map (f : α → β) (m : MeasurableSpace α) : MeasurableSpace β where MeasurableSet' s := MeasurableSet[m] <| f ⁻¹' s measurableSet_empty := m.measurableSet_empty measurableSet_compl _ hs := m.measurableSet_compl _ hs measurableSet_iUnion f hf := by simpa only [preimage_iUnion] using m.measurableSet_iUnion _ hf lemma map_def {s : Set β} : MeasurableSet[m.map f] s ↔ MeasurableSet[m] (f ⁻¹' s) := Iff.rfl @[simp] theorem map_id : m.map id = m := MeasurableSpace.ext fun _ => Iff.rfl @[simp] theorem map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) := MeasurableSpace.ext fun _ => Iff.rfl /-- The reverse image of a measurable space under a function. `comap f m` contains the sets `s : Set α` such that `s` is the `f`-preimage of a measurable set in `β`. -/ protected def comap (f : α → β) (m : MeasurableSpace β) : MeasurableSpace α where MeasurableSet' s := ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s measurableSet_empty := ⟨∅, m.measurableSet_empty, rfl⟩ measurableSet_compl := fun _ ⟨s', h₁, h₂⟩ => ⟨s'ᶜ, m.measurableSet_compl _ h₁, h₂ ▸ rfl⟩ measurableSet_iUnion s hs := let ⟨s', hs'⟩ := Classical.axiom_of_choice hs ⟨⋃ i, s' i, m.measurableSet_iUnion _ fun i => (hs' i).left, by simp [hs']⟩ lemma measurableSet_comap {m : MeasurableSpace β} : MeasurableSet[m.comap f] s ↔ ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s := .rfl theorem comap_eq_generateFrom (m : MeasurableSpace β) (f : α → β) : m.comap f = generateFrom { t | ∃ s, MeasurableSet s ∧ f ⁻¹' s = t } := (@generateFrom_measurableSet _ (.comap f m)).symm @[simp] theorem comap_id : m.comap id = m := MeasurableSpace.ext fun s => ⟨fun ⟨_, hs', h⟩ => h ▸ hs', fun h => ⟨s, h, rfl⟩⟩ @[simp] theorem comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) := MeasurableSpace.ext fun _ => ⟨fun ⟨_, ⟨u, h, hu⟩, ht⟩ => ⟨u, h, ht ▸ hu ▸ rfl⟩, fun ⟨t, h, ht⟩ => ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩ theorem comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f := ⟨fun h _s hs => h _ ⟨_, hs, rfl⟩, fun h _s ⟨_t, ht, heq⟩ => heq ▸ h _ ht⟩ theorem gc_comap_map (f : α → β) : GaloisConnection (MeasurableSpace.comap f) (MeasurableSpace.map f) := fun _ _ => comap_le_iff_le_map theorem map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f := (gc_comap_map f).monotone_u h theorem monotone_map : Monotone (MeasurableSpace.map f) := fun _ _ => map_mono theorem comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g := (gc_comap_map g).monotone_l h theorem monotone_comap : Monotone (MeasurableSpace.comap g) := fun _ _ h => comap_mono h @[simp] theorem comap_bot : (⊥ : MeasurableSpace α).comap g = ⊥ := (gc_comap_map g).l_bot @[simp] theorem comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g := (gc_comap_map g).l_sup @[simp] theorem comap_iSup {m : ι → MeasurableSpace α} : (⨆ i, m i).comap g = ⨆ i, (m i).comap g := (gc_comap_map g).l_iSup @[simp] theorem map_top : (⊤ : MeasurableSpace α).map f = ⊤ := (gc_comap_map f).u_top @[simp] theorem map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f := (gc_comap_map f).u_inf @[simp] theorem map_iInf {m : ι → MeasurableSpace α} : (⨅ i, m i).map f = ⨅ i, (m i).map f := (gc_comap_map f).u_iInf theorem comap_map_le : (m.map f).comap f ≤ m := (gc_comap_map f).l_u_le _ theorem le_map_comap : m ≤ (m.comap g).map g := (gc_comap_map g).le_u_l _ end Functors @[simp] theorem map_const {m} (b : β) : MeasurableSpace.map (fun _a : α ↦ b) m = ⊤ := eq_top_iff.2 <| fun s _ ↦ by rw [map_def]; by_cases h : b ∈ s <;> simp [h] @[simp] theorem comap_const {m} (b : β) : MeasurableSpace.comap (fun _a : α => b) m = ⊥ := eq_bot_iff.2 <| by rintro _ ⟨s, -, rfl⟩; by_cases b ∈ s <;> simp [*] theorem comap_generateFrom {f : α → β} {s : Set (Set β)} : (generateFrom s).comap f = generateFrom (preimage f '' s) := le_antisymm (comap_le_iff_le_map.2 <| generateFrom_le fun _t hts => GenerateMeasurable.basic _ <| mem_image_of_mem _ <| hts) (generateFrom_le fun _t ⟨u, hu, Eq⟩ => Eq ▸ ⟨u, GenerateMeasurable.basic _ hu, rfl⟩) end MeasurableSpace section MeasurableFunctions open MeasurableSpace theorem measurable_iff_le_map {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂ ≤ m₁.map f := Iff.rfl alias ⟨Measurable.le_map, Measurable.of_le_map⟩ := measurable_iff_le_map theorem measurable_iff_comap_le {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂.comap f ≤ m₁ := comap_le_iff_le_map.symm alias ⟨Measurable.comap_le, Measurable.of_comap_le⟩ := measurable_iff_comap_le theorem comap_measurable {m : MeasurableSpace β} (f : α → β) : Measurable[m.comap f] f := fun s hs => ⟨s, hs, rfl⟩ theorem Measurable.mono {ma ma' : MeasurableSpace α} {mb mb' : MeasurableSpace β} {f : α → β} (hf : @Measurable α β ma mb f) (ha : ma ≤ ma') (hb : mb' ≤ mb) : @Measurable α β ma' mb' f := fun _t ht => ha _ <| hf <| hb _ ht lemma Measurable.iSup' {mα : ι → MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (i₀ : ι) (h : Measurable[mα i₀] f) : Measurable[⨆ i, mα i] f := h.mono (le_iSup mα i₀) le_rfl lemma Measurable.sup_of_left {mα mα' : MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (h : Measurable[mα] f) : Measurable[mα ⊔ mα'] f := h.mono le_sup_left le_rfl lemma Measurable.sup_of_right {mα mα' : MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (h : Measurable[mα'] f) : Measurable[mα ⊔ mα'] f := h.mono le_sup_right le_rfl theorem measurable_id'' {m mα : MeasurableSpace α} (hm : m ≤ mα) : @Measurable α α mα m id := measurable_id.mono le_rfl hm @[measurability] theorem measurable_from_top [MeasurableSpace β] {f : α → β} : Measurable[⊤] f := fun _ _ => trivial theorem measurable_generateFrom [MeasurableSpace α] {s : Set (Set β)} {f : α → β} (h : ∀ t ∈ s, MeasurableSet (f ⁻¹' t)) : @Measurable _ _ _ (generateFrom s) f := Measurable.of_le_map <| generateFrom_le h variable {f g : α → β} section TypeclassMeasurableSpace variable [MeasurableSpace α] [MeasurableSpace β] @[nontriviality, measurability] theorem Subsingleton.measurable [Subsingleton α] : Measurable f := fun _ _ => @Subsingleton.measurableSet α _ _ _ @[nontriviality, measurability] theorem measurable_of_subsingleton_codomain [Subsingleton β] (f : α → β) : Measurable f := fun s _ => Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s @[to_additive (attr := measurability, fun_prop)] theorem measurable_one [One α] : Measurable (1 : β → α) := @measurable_const _ _ _ _ 1 theorem measurable_of_empty [IsEmpty α] (f : α → β) : Measurable f := Subsingleton.measurable theorem measurable_of_empty_codomain [IsEmpty β] (f : α → β) : Measurable f := measurable_of_subsingleton_codomain f /-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem measurable_const' {f : β → α} (hf : ∀ x y, f x = f y) : Measurable f := by nontriviality β inhabit β convert @measurable_const α β _ _ (f default) using 2 apply hf @[measurability] theorem measurable_natCast [NatCast α] (n : ℕ) : Measurable (n : β → α) := @measurable_const α _ _ _ n @[measurability] theorem measurable_intCast [IntCast α] (n : ℤ) : Measurable (n : β → α) := @measurable_const α _ _ _ n theorem measurable_of_countable [Countable α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := fun s _ => (f ⁻¹' s).to_countable.measurableSet theorem measurable_of_finite [Finite α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := measurable_of_countable f end TypeclassMeasurableSpace variable {m : MeasurableSpace α} @[measurability] theorem Measurable.iterate {f : α → α} (hf : Measurable f) : ∀ n, Measurable f^[n] | 0 => measurable_id | n + 1 => (Measurable.iterate hf n).comp hf variable {mβ : MeasurableSpace β} @[measurability] theorem measurableSet_preimage {t : Set β} (hf : Measurable f) (ht : MeasurableSet t) : MeasurableSet (f ⁻¹' t) := hf ht protected theorem MeasurableSet.preimage {t : Set β} (ht : MeasurableSet t) (hf : Measurable f) : MeasurableSet (f ⁻¹' t) := hf ht @[measurability, fun_prop] protected theorem Measurable.piecewise {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : Measurable (piecewise s f g) := by intro t ht rw [piecewise_preimage] exact hs.ite (hf ht) (hg ht) /-- This is slightly different from `Measurable.piecewise`. It can be used to show `Measurable (ite (x=0) 0 1)` by `exact Measurable.ite (measurableSet_singleton 0) measurable_const measurable_const`, but replacing `Measurable.ite` by `Measurable.piecewise` in that example proof does not work. -/ theorem Measurable.ite {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : Measurable f) (hg : Measurable g) : Measurable fun x => ite (p x) (f x) (g x) := Measurable.piecewise hp hf hg @[measurability, fun_prop] theorem Measurable.indicator [Zero β] (hf : Measurable f) (hs : MeasurableSet s) : Measurable (s.indicator f) := hf.piecewise hs measurable_const /-- The measurability of a set `A` is equivalent to the measurability of the indicator function which takes a constant value `b ≠ 0` on a set `A` and `0` elsewhere. -/ lemma measurable_indicator_const_iff [Zero β] [MeasurableSingletonClass β] (b : β) [NeZero b] : Measurable (s.indicator (fun (_ : α) ↦ b)) ↔ MeasurableSet s := by constructor <;> intro h · convert h (MeasurableSet.singleton (0 : β)).compl ext a simp [NeZero.ne b] · exact measurable_const.indicator h @[to_additive (attr := measurability)] theorem measurableSet_mulSupport [One β] [MeasurableSingletonClass β] (hf : Measurable f) : MeasurableSet (Function.mulSupport f) := hf (measurableSet_singleton 1).compl /-- If a function coincides with a measurable function outside of a countable set, it is measurable. -/ theorem Measurable.measurable_of_countable_ne [MeasurableSingletonClass α] (hf : Measurable f) (h : Set.Countable { x | f x ≠ g x }) : Measurable g := by intro t ht have : g ⁻¹' t = g ⁻¹' t ∩ { x | f x = g x }ᶜ ∪ g ⁻¹' t ∩ { x | f x = g x } := by simp [← inter_union_distrib_left] rw [this] refine (h.mono inter_subset_right).measurableSet.union ?_ have : g ⁻¹' t ∩ { x : α | f x = g x } = f ⁻¹' t ∩ { x : α | f x = g x } := by ext x simp +contextual rw [this] exact (hf ht).inter h.measurableSet.of_compl end MeasurableFunctions /-- We say that a collection of sets is countably spanning if a countable subset spans the whole type. This is a useful condition in various parts of measure theory. For example, it is a needed condition to show that the product of two collections generate the product sigma algebra, see `generateFrom_prod_eq`. -/ def IsCountablySpanning (C : Set (Set α)) : Prop := ∃ s : ℕ → Set α, (∀ n, s n ∈ C) ∧ ⋃ n, s n = univ theorem isCountablySpanning_measurableSet [MeasurableSpace α] : IsCountablySpanning { s : Set α | MeasurableSet s } := ⟨fun _ => univ, fun _ => MeasurableSet.univ, iUnion_const _⟩ /-- Rectangles of countably spanning sets are countably spanning. -/ lemma IsCountablySpanning.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C) (hD : IsCountablySpanning D) : IsCountablySpanning (image2 (· ×ˢ ·) C D) := by rcases hC, hD with ⟨⟨s, h1s, h2s⟩, t, h1t, h2t⟩ refine ⟨fun n => s n.unpair.1 ×ˢ t n.unpair.2, fun n => mem_image2_of_mem (h1s _) (h1t _), ?_⟩ rw [iUnion_unpair_prod, h2s, h2t, univ_prod_univ]
Mathlib/MeasureTheory/MeasurableSpace/Basic.lean
1,138
1,141
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Action.End import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.Group.Subgroup.Map import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Data.Finite.Sigma import Mathlib.Data.Set.Finite.Range import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Defs /-! # Basic properties of group actions This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation of `•` belong elsewhere. ## Main definitions * `MulAction.orbit` * `MulAction.fixedPoints` * `MulAction.fixedBy` * `MulAction.stabilizer` -/ universe u v open Pointwise open Function namespace MulAction variable (M : Type u) [Monoid M] (α : Type v) [MulAction M α] {β : Type*} [MulAction M β] section Orbit variable {α M} @[to_additive] lemma fst_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) : x.1 ∈ MulAction.orbit M y.1 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma snd_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) : x.2 ∈ MulAction.orbit M y.2 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma _root_.Finite.finite_mulAction_orbit [Finite M] (a : α) : Set.Finite (orbit M a) := Set.finite_range _ variable (M) @[to_additive] theorem orbit_eq_univ [IsPretransitive M α] (a : α) : orbit M a = Set.univ := (surjective_smul M a).range_eq end Orbit section FixedPoints variable {M α} @[to_additive (attr := simp)] theorem subsingleton_orbit_iff_mem_fixedPoints {a : α} : (orbit M a).Subsingleton ↔ a ∈ fixedPoints M α := by rw [mem_fixedPoints] constructor · exact fun h m ↦ h (mem_orbit a m) (mem_orbit_self a) · rintro h _ ⟨m, rfl⟩ y ⟨p, rfl⟩ simp only [h] @[to_additive mem_fixedPoints_iff_card_orbit_eq_one] theorem mem_fixedPoints_iff_card_orbit_eq_one {a : α} [Fintype (orbit M a)] : a ∈ fixedPoints M α ↔ Fintype.card (orbit M a) = 1 := by simp only [← subsingleton_orbit_iff_mem_fixedPoints, le_antisymm_iff, Fintype.card_le_one_iff_subsingleton, Nat.add_one_le_iff, Fintype.card_pos_iff, Set.subsingleton_coe, iff_self_and, Set.nonempty_coe_sort, orbit_nonempty, implies_true] @[to_additive instDecidablePredMemSetFixedByAddOfDecidableEq] instance (m : M) [DecidableEq β] : DecidablePred fun b : β => b ∈ MulAction.fixedBy β m := fun b ↦ by simp only [MulAction.mem_fixedBy, Equiv.Perm.smul_def] infer_instance end FixedPoints end MulAction /-- `smul` by a `k : M` over a group is injective, if `k` is not a zero divisor. The general theory of such `k` is elaborated by `IsSMulRegular`. The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/ theorem smul_cancel_of_non_zero_divisor {M G : Type*} [Monoid M] [AddGroup G] [DistribMulAction M G] (k : M) (h : ∀ x : G, k • x = 0 → x = 0) {a b : G} (h' : k • a = k • b) : a = b := by rw [← sub_eq_zero] refine h _ ?_ rw [smul_sub, h', sub_self] namespace MulAction variable {G α β : Type*} [Group G] [MulAction G α] [MulAction G β] @[to_additive] theorem fixedPoints_of_subsingleton [Subsingleton α] : fixedPoints G α = .univ := by apply Set.eq_univ_of_forall simp only [mem_fixedPoints] intro x hx apply Subsingleton.elim .. /-- If a group acts nontrivially, then the type is nontrivial -/ @[to_additive "If a subgroup acts nontrivially, then the type is nontrivial."] theorem nontrivial_of_fixedPoints_ne_univ (h : fixedPoints G α ≠ .univ) : Nontrivial α := (subsingleton_or_nontrivial α).resolve_left fun _ ↦ h fixedPoints_of_subsingleton section Orbit -- TODO: This proof is redoing a special case of `MulAction.IsInvariantBlock.isBlock`. Can we move -- this lemma earlier to golf? @[to_additive (attr := simp)] theorem smul_orbit (g : G) (a : α) : g • orbit G a = orbit G a := (smul_orbit_subset g a).antisymm <| calc orbit G a = g • g⁻¹ • orbit G a := (smul_inv_smul _ _).symm _ ⊆ g • orbit G a := Set.image_subset _ (smul_orbit_subset _ _) /-- The action of a group on an orbit is transitive. -/ @[to_additive "The action of an additive group on an orbit is transitive."] instance (a : α) : IsPretransitive G (orbit G a) := ⟨by rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩ use h * g⁻¹ ext1 simp [mul_smul]⟩ @[to_additive] lemma orbitRel_subgroup_le (H : Subgroup G) : orbitRel H α ≤ orbitRel G α := Setoid.le_def.2 mem_orbit_of_mem_orbit_subgroup @[to_additive] lemma orbitRel_subgroupOf (H K : Subgroup G) : orbitRel (H.subgroupOf K) α = orbitRel (H ⊓ K : Subgroup G) α := by rw [← Subgroup.subgroupOf_map_subtype] ext x simp_rw [orbitRel_apply] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h with ⟨⟨gv, gp⟩, rfl⟩ simp only [Submonoid.mk_smul] refine mem_orbit _ (⟨gv, ?_⟩ : Subgroup.map K.subtype (H.subgroupOf K)) simpa using gp · rcases h with ⟨⟨gv, gp⟩, rfl⟩ simp only [Submonoid.mk_smul] simp only [Subgroup.subgroupOf_map_subtype, Subgroup.mem_inf] at gp refine mem_orbit _ (⟨⟨gv, ?_⟩, ?_⟩ : H.subgroupOf K) · exact gp.2 · simp only [Subgroup.mem_subgroupOf] exact gp.1 variable (G α) /-- An action is pretransitive if and only if the quotient by `MulAction.orbitRel` is a subsingleton. -/ @[to_additive "An additive action is pretransitive if and only if the quotient by `AddAction.orbitRel` is a subsingleton."] theorem pretransitive_iff_subsingleton_quotient : IsPretransitive G α ↔ Subsingleton (orbitRel.Quotient G α) := by refine ⟨fun _ ↦ ⟨fun a b ↦ ?_⟩, fun _ ↦ ⟨fun a b ↦ ?_⟩⟩ · refine Quot.inductionOn a (fun x ↦ ?_) exact Quot.inductionOn b (fun y ↦ Quot.sound <| exists_smul_eq G y x) · have h : Quotient.mk (orbitRel G α) b = ⟦a⟧ := Subsingleton.elim _ _ exact Quotient.eq''.mp h /-- If `α` is non-empty, an action is pretransitive if and only if the quotient has exactly one element. -/ @[to_additive "If `α` is non-empty, an additive action is pretransitive if and only if the quotient has exactly one element."] theorem pretransitive_iff_unique_quotient_of_nonempty [Nonempty α] : IsPretransitive G α ↔ Nonempty (Unique <| orbitRel.Quotient G α) := by rw [unique_iff_subsingleton_and_nonempty, pretransitive_iff_subsingleton_quotient, iff_self_and] exact fun _ ↦ (nonempty_quotient_iff _).mpr inferInstance variable {G α} @[to_additive] instance (x : orbitRel.Quotient G α) : IsPretransitive G x.orbit where exists_smul_eq := by induction x using Quotient.inductionOn' rintro ⟨y, yh⟩ ⟨z, zh⟩ rw [orbitRel.Quotient.mem_orbit, Quotient.eq''] at yh zh rcases yh with ⟨g, rfl⟩ rcases zh with ⟨h, rfl⟩ refine ⟨h * g⁻¹, ?_⟩ ext simp [mul_smul] variable (G) (α) local notation "Ω" => orbitRel.Quotient G α @[to_additive] lemma _root_.Finite.of_finite_mulAction_orbitRel_quotient [Finite G] [Finite Ω] : Finite α := by rw [(selfEquivSigmaOrbits' G _).finite_iff] have : ∀ g : Ω, Finite g.orbit := by intro g induction g using Quotient.inductionOn' simpa [Set.finite_coe_iff] using Finite.finite_mulAction_orbit _ exact Finite.instSigma variable (β) @[to_additive] lemma orbitRel_le_fst : orbitRel G (α × β) ≤ (orbitRel G α).comap Prod.fst := Setoid.le_def.2 fst_mem_orbit_of_mem_orbit @[to_additive] lemma orbitRel_le_snd : orbitRel G (α × β) ≤ (orbitRel G β).comap Prod.snd := Setoid.le_def.2 snd_mem_orbit_of_mem_orbit end Orbit section Stabilizer variable (G) variable {G} /-- If the stabilizer of `a` is `S`, then the stabilizer of `g • a` is `gSg⁻¹`. -/ theorem stabilizer_smul_eq_stabilizer_map_conj (g : G) (a : α) : stabilizer G (g • a) = (stabilizer G a).map (MulAut.conj g).toMonoidHom := by ext h rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul, inv_mul_cancel, one_smul, ← mem_stabilizer_iff, Subgroup.mem_map_equiv, MulAut.conj_symm_apply] /-- A bijection between the stabilizers of two elements in the same orbit. -/ noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) : stabilizer G a ≃* stabilizer G b := let g : G := Classical.choose h have hg : g • b = a := Classical.choose_spec h have this : stabilizer G a = (stabilizer G b).map (MulAut.conj g).toMonoidHom := by rw [← hg, stabilizer_smul_eq_stabilizer_map_conj] (MulEquiv.subgroupCongr this).trans ((MulAut.conj g).subgroupMap <| stabilizer G b).symm end Stabilizer end MulAction namespace AddAction variable {G α : Type*} [AddGroup G] [AddAction G α] /-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/ theorem stabilizer_vadd_eq_stabilizer_map_conj (g : G) (a : α) : stabilizer G (g +ᵥ a) = (stabilizer G a).map (AddAut.conj g).toMul.toAddMonoidHom := by ext h rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g), vadd_vadd, vadd_vadd, vadd_vadd, neg_add_cancel, zero_vadd, ← mem_stabilizer_iff, AddSubgroup.mem_map_equiv, AddAut.conj_symm_apply] /-- A bijection between the stabilizers of two elements in the same orbit. -/ noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) : stabilizer G a ≃+ stabilizer G b := let g : G := Classical.choose h have hg : g +ᵥ b = a := Classical.choose_spec h have this : stabilizer G a = (stabilizer G b).map (AddAut.conj g).toMul.toAddMonoidHom := by rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj] (AddEquiv.addSubgroupCongr this).trans ((AddAut.conj g).addSubgroupMap <| stabilizer G b).symm end AddAction attribute [to_additive existing] MulAction.stabilizer_smul_eq_stabilizer_map_conj attribute [to_additive existing] MulAction.stabilizerEquivStabilizerOfOrbitRel theorem Equiv.swap_mem_stabilizer {α : Type*} [DecidableEq α] {S : Set α} {a b : α} : Equiv.swap a b ∈ MulAction.stabilizer (Equiv.Perm α) S ↔ (a ∈ S ↔ b ∈ S) := by rw [MulAction.mem_stabilizer_iff, Set.ext_iff, ← swap_inv] simp_rw [Set.mem_inv_smul_set_iff, Perm.smul_def, swap_apply_def] exact ⟨fun h ↦ by simpa [Iff.comm] using h a, by intros; split_ifs <;> simp [*]⟩ namespace MulAction variable {G : Type*} [Group G] {α : Type*} [MulAction G α] /-- To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions. -/ @[to_additive "To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions."] theorem le_stabilizer_iff_smul_le (s : Set α) (H : Subgroup G) : H ≤ stabilizer G s ↔ ∀ g ∈ H, g • s ⊆ s := by constructor · intro hyp g hg apply Eq.subset rw [← mem_stabilizer_iff] exact hyp hg · intro hyp g hg rw [mem_stabilizer_iff] apply subset_antisymm (hyp g hg) intro x hx use g⁻¹ • x constructor · apply hyp g⁻¹ (inv_mem hg) simp only [Set.smul_mem_smul_set_iff, hx] · simp only [smul_inv_smul] end MulAction section variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] variable {M} in lemma Module.stabilizer_units_eq_bot_of_ne_zero {x : M} (hx : x ≠ 0) : MulAction.stabilizer Rˣ x = ⊥ := by rw [eq_bot_iff] intro g (hg : g.val • x = x) ext rw [← sub_eq_zero, ← smul_eq_zero_iff_left hx, Units.val_one, sub_smul, hg, one_smul, sub_self] end
Mathlib/GroupTheory/GroupAction/Basic.lean
814
829
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Logic.Encodable.Pi import Mathlib.Logic.Function.Iterate /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `ℕ → ℕ` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := ℕ`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (Gödel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) In the above, the pairing function is primitive recursive by definition. This deviates from the textbook definition of primitive recursive functions, which instead work with *`n`-ary* functions. We formalize the textbook definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is equivalent to our chosen formulation. For more discussionn of this and other design choices in this formalization, see [carneiro2019]. ## Main definitions - `Nat.Primrec f`: `f` is primitive recursive, for functions `f : ℕ → ℕ` - `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types - `Primcodable α`: well-behaved encoding of `α` into `ℕ`, i.e. one such that roundtripping through the encoding functions adds no computational power ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open List (Vector) open Denumerable Encodable Function namespace Nat /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α := f n.unpair.1 n.unpair.2 /-- The primitive recursive functions `ℕ → ℕ`. -/ protected inductive Primrec : (ℕ → ℕ) → Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) namespace Primrec theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g := (funext H : f = g) ▸ hf theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) := (prec1 m (hf.comp left)).of_eq <| by simp -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] theorem add : Nat.Primrec (unpaired (· + ·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] theorem sub : Nat.Primrec (unpaired (· - ·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] theorem mul : Nat.Primrec (unpaired (· * ·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst] theorem pow : Nat.Primrec (unpaired (· ^ ·)) := (prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ] end Primrec end Nat /-- A `Primcodable` type is, essentially, an `Encodable` type for which the encode/decode functions are primitive recursive. However, such a definition is circular. Instead, we ask that the composition of `decode : ℕ → Option α` with `encode : Option α → ℕ` is primitive recursive. Said composition is the identity function, restricted to the image of `encode`. Thus, in a way, the added requirement ensures that no predicates can be smuggled in through a cunning choice of the subset of `ℕ` into which the type is encoded. -/ class Primcodable (α : Type*) extends Encodable α where -- Porting note: was `prim [] `. -- This means that `prim` does not take the type explicitly in Lean 4 prim : Nat.Primrec fun n => Encodable.encode (decode n) namespace Primcodable open Nat.Primrec instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α := ⟨Nat.Primrec.succ.of_eq <| by simp⟩ /-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/ def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β := { __ := Encodable.ofEquiv α e prim := (@Primcodable.prim α _).of_eq fun n => by rw [decode_ofEquiv] cases (@decode α _ n) <;> simp [encode_ofEquiv] } instance empty : Primcodable Empty := ⟨zero⟩ instance unit : Primcodable PUnit := ⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩ instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) := ⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by cases n with | zero => rfl | succ n => rw [decode_option_succ] cases H : @decode α _ n <;> simp [H]⟩ instance bool : Primcodable Bool := ⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with | 0 => rfl | 1 => rfl | (n + 2) => by rw [decode_ge_two] <;> simp⟩ end Primcodable /-- `Primrec f` means `f` is primitive recursive (after encoding its input and output as natural numbers). -/ def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop := Nat.Primrec fun n => encode ((@decode α _ n).map f) namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec protected theorem encode : Primrec (@encode α _) := (@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl protected theorem decode : Primrec (@decode α _) := Nat.Primrec.succ.comp (@Primcodable.prim α _) theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) := ⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h => (Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩ theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f := dom_denumerable theorem encdec : Primrec fun n => encode (@decode α _ n) := nat_iff.2 Primcodable.prim theorem option_some : Primrec (@some α) := ((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g := (funext H : f = g) ▸ hf theorem const (x : σ) : Primrec fun _ : α => x := ((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> rfl protected theorem id : Primrec (@id α) := (@Primcodable.prim α).of_eq <| by simp theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) := ((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] theorem succ : Primrec Nat.succ := nat_iff.2 Nat.Primrec.succ theorem pred : Primrec Nat.pred := nat_iff.2 Nat.Primrec.pred theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f := ⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩ theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Primrec fun n => f (ofNat α n) := dom_denumerable.trans <| nat_iff.symm.trans encode_iff protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) := ofNat_iff.1 Primrec.id theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f := ⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩ theorem of_equiv {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e := letI : Primcodable β := Primcodable.ofEquiv α e encode_iff.1 Primrec.encode theorem of_equiv_symm {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e.symm := letI := Primcodable.ofEquiv α e encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode]) theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩ theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e.symm (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩ end Primrec namespace Primcodable open Nat.Primrec instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) := ⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1; · simp cases @decode β _ n.unpair.2 <;> simp⟩ end Primcodable namespace Primrec variable {α : Type*} [Primcodable α] open Nat.Primrec theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp left)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp right)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) := ((casesOn1 0 (Nat.Primrec.succ.comp <| .pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] theorem unpair : Primrec Nat.unpair := (pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp theorem list_getElem?₁ : ∀ l : List α, Primrec (l[·]? : ℕ → Option α) | [] => dom_denumerable.2 zero | a :: l => dom_denumerable.2 <| (casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?₁ l).of_eq fun n => by cases n <;> simp @[deprecated (since := "2025-02-14")] alias list_get?₁ := list_getElem?₁ end Primrec /-- `Primrec₂ f` means `f` is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly. -/ def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) := Primrec fun p : α × β => f p.1 p.2 /-- `PrimrecPred p` means `p : α → Prop` is a (decidable) primitive recursive predicate, which is to say that `decide ∘ p : α → Bool` is primitive recursive. -/ def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] := Primrec fun a => decide (p a) /-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable) primitive recursive relation, which is to say that `decide ∘ p : α → β → Bool` is primitive recursive. -/ def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop) [∀ a b, Decidable (s a b)] := Primrec₂ fun a b => decide (s a b) namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g := (by funext a b; apply H : f = g) ▸ hg theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x := Primrec.const _ protected theorem pair : Primrec₂ (@Prod.mk α β) := Primrec.pair .fst .snd theorem left : Primrec₂ fun (a : α) (_ : β) => a := .fst theorem right : Primrec₂ fun (_ : α) (b : β) => b := .snd theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f := ⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩ theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f := Primrec.nat_iff.symm.trans unpaired theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f := Primrec.encode_iff theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f := Primrec.option_some_iff theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) := (Primrec.ofNat_iff.trans <| by simp).trans unpaired theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by rw [← uncurry, Function.uncurry_curry] end Primrec₂ section Comp variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a b => f (g a b) := hf.comp hg theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g) (hh : Primrec h) : Primrec fun a => f (g a) (h a) := Primrec.comp hf (hg.pair hh) theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f) (hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) := hf.comp hg hh theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} : PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) := Primrec.comp theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} : PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) := Primrec₂.comp theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ} {g : α → β → δ} : PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) := PrimrecRel.comp end Comp theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q := Primrec.of_eq hp fun a => Bool.decide_congr (H a) theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop} [∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r) (H : ∀ a b, r a b ↔ s a b) : PrimrecRel s := Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b) namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) := h.comp₂ Primrec₂.right Primrec₂.left theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec (.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by have : ∀ (a : Option α) (b : Option β), Option.map (fun p : α × β => f p.1 p.2) (Option.bind a fun a : α => Option.map (Prod.mk a) b) = Option.bind a fun a => Option.map (f a) b := fun a b => by cases a <;> cases b <;> rfl simp [Primrec₂, Primrec, this] theorem nat_iff' {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) := nat_iff.trans <| unpaired'.trans encode_iff end Primrec₂ namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) := hf.of_eq fun _ => rfl theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) := Primrec₂.nat_iff.2 <| ((Nat.Primrec.casesOn' .zero <| (Nat.Primrec.prec hf <| .comp hg <| Nat.Primrec.left.pair <| (Nat.Primrec.left.comp .right).pair <| Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <| Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <| Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq fun n => by simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat, Option.some_bind, Option.map_map, Option.map_some'] rcases @decode α _ n.unpair.1 with - | a; · rfl simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some', Option.some_bind, Option.map_map] induction' n.unpair.2 with m <;> simp [encodek] simp [*, encodek] theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) := (nat_rec hg hh).comp .id hf theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) := nat_rec' .id (const a) <| comp₂ hf Primrec₂.right theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) := nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) := (nat_casesOn' hg hh).comp .id hf theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) : Primrec (fun (n : ℕ) => (n.casesOn a f : α)) := nat_casesOn .id (const a) (comp₂ hf .right) theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) := (nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ'] theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o) (hf : Primrec f) (hg : Primrec₂ g) : @Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) := encode_iff.1 <| (nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <| pred.comp₂ <| Primrec₂.encode_iff.2 <| (Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂ Primrec₂.right).of_eq fun a => by rcases o a with - | b <;> simp [encodek] theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).bind (g a) := (option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f := option_bind .id (hf.comp snd).to₂ theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) := option_map .id (hf.comp snd).to₂ theorem option_iget [Inhabited α] : Primrec (@Option.iget α _) := (option_casesOn .id (const <| @default α _) .right).of_eq fun o => by cases o <;> rfl theorem option_isSome : Primrec (@Option.isSome α) := (option_casesOn .id (const false) (const true).to₂).of_eq fun o => by cases o <;> rfl theorem option_getD : Primrec₂ (@Option.getD α) := Primrec.of_eq (option_casesOn Primrec₂.left Primrec₂.right .right) fun ⟨o, a⟩ => by cases o <;> rfl theorem bind_decode_iff {f : α → β → Option σ} : (Primrec₂ fun a n => (@decode β _ n).bind (f a)) ↔ Primrec₂ f := ⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode β _).comp snd), fun h => option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩ theorem map_decode_iff {f : α → β → σ} : (Primrec₂ fun a n => (@decode β _ n).map (f a)) ↔ Primrec₂ f := by simp only [Option.map_eq_bind] exact bind_decode_iff.trans Primrec₂.option_some_iff theorem nat_add : Primrec₂ ((· + ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.add theorem nat_sub : Primrec₂ ((· - ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.sub theorem nat_mul : Primrec₂ ((· * ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.mul theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) := (nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq fun a => by cases c a <;> rfl theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by simpa [Bool.cond_decide] using cond hc hf hg theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) := (nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by dsimp [swap] rcases e : p.1 - p.2 with - | n · simp [Nat.sub_eq_zero_iff_le.1 e] · simp [not_le.2 (Nat.lt_of_sub_eq_succ e)] theorem nat_min : Primrec₂ (@min ℕ _) := ite nat_le fst snd theorem nat_max : Primrec₂ (@max ℕ _) := ite (nat_le.comp fst snd) snd fst theorem dom_bool (f : Bool → α) : Primrec f := (cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl theorem dom_bool₂ (f : Bool → Bool → α) : Primrec₂ f := (cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by cases a <;> rfl protected theorem not : Primrec not := dom_bool _ protected theorem and : Primrec₂ and := dom_bool₂ _ protected theorem or : Primrec₂ or := dom_bool₂ _ theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : PrimrecPred fun a => ¬p a := (Primrec.not.comp hp).of_eq fun n => by simp theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a := (Primrec.and.comp hp hq).of_eq fun n => by simp theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a := (Primrec.or.comp hp hq).of_eq fun n => by simp protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) := have : PrimrecRel fun a b : ℕ => a = b := (PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff] (this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq fun _ _ => encode_injective.eq_iff protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) := (nat_le.comp snd fst).not.of_eq fun p => by simp theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β} (hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) := ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none) theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Option α) := (option_casesOn fst snd (fst.comp fst).to₂).of_eq fun ⟨o₁, o₂⟩ => by cases o₁ <;> cases o₂ <;> rfl protected theorem decode₂ : Primrec (decode₂ α) := option_bind .decode <| option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) : ∀ l : List β, Primrec fun a => l.findIdx (p a) | [] => const 0 | a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n => by simp [List.findIdx_cons] theorem list_idxOf₁ [DecidableEq α] (l : List α) : Primrec fun a => l.idxOf a := list_findIdx₁ (.swap .beq) l @[deprecated (since := "2025-01-30")] alias list_indexOf₁ := list_idxOf₁ theorem dom_fintype [Finite α] (f : α → σ) : Primrec f := let ⟨l, _, m⟩ := Finite.exists_univ_list α option_some_iff.1 <| by haveI := decidableEqOfEncodable α refine ((list_getElem?₁ (l.map f)).comp (list_idxOf₁ l)).of_eq fun a => ?_ rw [List.getElem?_map, List.getElem?_idxOf (m a), Option.map_some'] -- Porting note: These are new lemmas -- I added it because it actually simplified the proofs -- and because I couldn't understand the original proof /-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/ def PrimrecBounded (f : α → β) : Prop := ∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)] (hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) := (nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2) hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp)) (snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by induction f x <;> simp [Nat.findGreatest, *] /-- To show a function `f : α → ℕ` is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive -/ theorem of_graph {f : α → ℕ} (h₁ : PrimrecBounded f) (h₂ : PrimrecRel fun a b => f a = b) : Primrec f := by rcases h₁ with ⟨g, pg, hg : ∀ x, f x ≤ g x⟩ refine (nat_findGreatest pg h₂).of_eq fun n => ?_ exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm -- We show that division is primitive recursive by showing that the graph is theorem nat_div : Primrec₂ ((· / ·) : ℕ → ℕ → ℕ) := by refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_ have : PrimrecRel fun (a : ℕ × ℕ) (b : ℕ) => (a.2 = 0 ∧ b = 0) ∨ (0 < a.2 ∧ b * a.2 ≤ a.1 ∧ a.1 < (b + 1) * a.2) := PrimrecPred.or (.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd)) (.and (nat_lt.comp (const 0) (fst |> snd.comp)) <| .and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp)) (nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst)))) refine this.of_eq ?_ rintro ⟨a, k⟩ q if H : k = 0 then simp [H, eq_comm] else have : q * k ≤ a ∧ a < (q + 1) * k ↔ q = a / k := by rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le (Nat.pos_of_ne_zero H), Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero H)] simpa [H, zero_lt_iff, eq_comm (b := q)] theorem nat_mod : Primrec₂ ((· % ·) : ℕ → ℕ → ℕ) := (nat_sub.comp fst (nat_mul.comp snd nat_div)).to₂.of_eq fun m n => by apply Nat.sub_eq_of_eq_add simp [add_comm (m % n), Nat.div_add_mod] theorem nat_bodd : Primrec Nat.bodd := (Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H] theorem nat_div2 : Primrec Nat.div2 := (nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm theorem nat_double : Primrec (fun n : ℕ => 2 * n) := nat_mul.comp (const _) Primrec.id theorem nat_double_succ : Primrec (fun n : ℕ => 2 * n + 1) := nat_double |> Primrec.succ.comp end Primrec section variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List β) _ n)) open Primrec private def prim : Primcodable (List β) := ⟨H⟩ private theorem list_casesOn' {f : α → List β} {g : α → σ} {h : α → β × List β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := letI := prim H have : @Primrec _ (Option σ) _ _ fun a => (@decode (Option (β × List β)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) := ((@map_decode_iff _ (Option (β × List β)) _ _ _ _ _).2 <| to₂ <| option_casesOn snd (hg.comp fst) (hh.comp₂ (fst.comp₂ Primrec₂.left) Primrec₂.right)).comp .id (encode_iff.2 hf) option_some_iff.1 <| this.of_eq fun a => by rcases f a with - | ⟨b, l⟩ <;> simp [encodek] private theorem list_foldl' {f : α → List β} {g : α → σ} {h : α → σ × β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by letI := prim H let G (a : α) (IH : σ × List β) : σ × List β := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l) have hG : Primrec₂ G := list_casesOn' H (snd.comp snd) snd <| to₂ <| pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd)) (snd.comp snd) let F := fun (a : α) (n : ℕ) => (G a)^[n] (g a, f a) have hF : Primrec fun a => (F a (encode (f a))).1 := (fst.comp <| nat_iterate (encode_iff.2 hf) (pair hg hf) <| hG) suffices ∀ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by refine hF.of_eq fun a => ?_ rw [this, List.take_of_length_le (length_le_encode _)] introv dsimp only [F] generalize f a = l generalize g a = x induction n generalizing l x with | zero => rfl | succ n IH => simp only [iterate_succ, comp_apply] rcases l with - | ⟨b, l⟩ <;> simp [G, IH] private theorem list_cons' : (haveI := prim H; Primrec₂ (@List.cons β)) := letI := prim H encode_iff.1 (succ.comp <| Primrec₂.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd)) private theorem list_reverse' : haveI := prim H Primrec (@List.reverse β) := letI := prim H (list_foldl' H .id (const []) <| to₂ <| ((list_cons' H).comp snd fst).comp snd).of_eq (suffices ∀ l r, List.foldl (fun (s : List β) (b : β) => b :: s) r l = List.reverseAux l r from fun l => this l [] fun l => by induction l <;> simp [*, List.reverseAux]) end namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec instance sum : Primcodable (α ⊕ β) := ⟨Primrec.nat_iff.1 <| (encode_iff.2 (cond nat_bodd (((@Primrec.decode β _).comp nat_div2).option_map <| to₂ <| nat_double_succ.comp (Primrec.encode.comp snd)) (((@Primrec.decode α _).comp nat_div2).option_map <| to₂ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq fun n => show _ = encode (decodeSum n) by simp only [decodeSum, Nat.boddDiv2_eq] cases Nat.bodd n <;> simp [decodeSum] · cases @decode α _ n.div2 <;> rfl · cases @decode β _ n.div2 <;> rfl⟩ instance list : Primcodable (List α) := ⟨letI H := @Primcodable.prim (List ℕ) _ have : Primrec₂ fun (a : α) (o : Option (List ℕ)) => o.map (List.cons (encode a)) := option_map snd <| (list_cons' H).comp ((@Primrec.encode α _).comp (fst.comp fst)) snd have : Primrec fun n => (ofNat (List ℕ) n).reverse.foldl (fun o m => (@decode α _ m).bind fun a => o.map (List.cons (encode a))) (some []) := list_foldl' H ((list_reverse' H).comp (.ofNat (List ℕ))) (const (some [])) (Primrec.comp₂ (bind_decode_iff.2 <| .swap this) Primrec₂.right) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => by rw [List.foldl_reverse] apply Nat.case_strong_induction_on n; · simp intro n IH; simp rcases @decode α _ n.unpair.1 with - | a; · rfl simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some'] suffices ∀ (o : Option (List ℕ)) (p), encode o = encode p → encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from this _ _ (IH _ (Nat.unpair_right_le n)) intro o p IH cases o <;> cases p · rfl · injection IH · injection IH · exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)⟩ end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem sumInl : Primrec (@Sum.inl α β) := encode_iff.1 <| nat_double.comp Primrec.encode theorem sumInr : Primrec (@Sum.inr α β) := encode_iff.1 <| nat_double_succ.comp Primrec.encode @[deprecated (since := "2025-02-21")] alias sum_inl := Primrec.sumInl @[deprecated (since := "2025-02-21")] alias sum_inr := Primrec.sumInr theorem sumCasesOn {f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ → σ} (hf : Primrec f) (hg : Primrec₂ g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) := option_some_iff.1 <| (cond (nat_bodd.comp <| encode_iff.2 hf) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq fun a => by rcases f a with b | c <;> simp [Nat.div2_val, encodek] @[deprecated (since := "2025-02-21")] alias sum_casesOn := Primrec.sumCasesOn theorem list_cons : Primrec₂ (@List.cons α) := list_cons' Primcodable.prim theorem list_casesOn {f : α → List β} {g : α → σ} {h : α → β × List β → σ} : Primrec f → Primrec g → Primrec₂ h → @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := list_casesOn' Primcodable.prim theorem list_foldl {f : α → List β} {g : α → σ} {h : α → σ × β → σ} : Primrec f → Primrec g → Primrec₂ h → Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := list_foldl' Primcodable.prim theorem list_reverse : Primrec (@List.reverse α) := list_reverse' Primcodable.prim theorem list_foldr {f : α → List β} {g : α → σ} {h : α → β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) := (list_foldl (list_reverse.comp hf) hg <| to₂ <| hh.comp fst <| (pair snd fst).comp snd).of_eq fun a => by simp [List.foldl_reverse] theorem list_head? : Primrec (@List.head? α) := (list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).to₂).of_eq fun l => by cases l <;> rfl theorem list_headI [Inhabited α] : Primrec (@List.headI α _) := (option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm theorem list_tail : Primrec (@List.tail α) := (list_casesOn .id (const []) (snd.comp snd).to₂).of_eq fun l => by cases l <;> rfl theorem list_rec {f : α → List β} {g : α → σ} {h : α → β × List β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) := let F (a : α) := (f a).foldr (fun (b : β) (s : List β × σ) => (b :: s.1, h a (b, s))) ([], g a) have : Primrec F := list_foldr hf (pair (const []) hg) <| to₂ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh (snd.comp this).of_eq fun a => by suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this] dsimp [F] induction' f a with b l IH <;> simp [*] theorem list_getElem? : Primrec₂ ((·[·]? : List α → ℕ → Option α)) := let F (l : List α) (n : ℕ) := l.foldl (fun (s : ℕ ⊕ α) (a : α) => Sum.casesOn s (@Nat.casesOn (fun _ => ℕ ⊕ α) · (Sum.inr a) Sum.inl) Sum.inr) (Sum.inl n) have hF : Primrec₂ F := (list_foldl fst (sumInl.comp snd) ((sumCasesOn fst (nat_casesOn snd (sumInr.comp <| snd.comp fst) (sumInl.comp snd).to₂).to₂ (sumInr.comp snd).to₂).comp snd).to₂).to₂ have : @Primrec _ (Option α) _ _ fun p : List α × ℕ => Sum.casesOn (F p.1 p.2) (fun _ => none) some := sumCasesOn hF (const none).to₂ (option_some.comp snd).to₂ this.to₂.of_eq fun l n => by dsimp; symm induction' l with a l IH generalizing n; · rfl rcases n with - | n · dsimp [F] clear IH induction' l with _ l IH <;> simp_all · simpa using IH .. @[deprecated (since := "2025-02-14")] alias list_get? := list_getElem? theorem list_getD (d : α) : Primrec₂ fun l n => List.getD l n d := by simp only [List.getD_eq_getElem?_getD] exact option_getD.comp₂ list_getElem? (const _) theorem list_getI [Inhabited α] : Primrec₂ (@List.getI α _) := list_getD _ theorem list_append : Primrec₂ ((· ++ ·) : List α → List α → List α) := (list_foldr fst snd <| to₂ <| comp (@list_cons α _) snd).to₂.of_eq fun l₁ l₂ => by induction l₁ <;> simp [*] theorem list_concat : Primrec₂ fun l (a : α) => l ++ [a] := list_append.comp fst (list_cons.comp snd (const [])) theorem list_map {f : α → List β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (list_foldr hf (const []) <| to₂ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq fun a => by induction f a <;> simp [*] theorem list_range : Primrec List.range := (nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).to₂).of_eq fun n => by simp; induction n <;> simp [*, List.range_succ] theorem list_flatten : Primrec (@List.flatten α) := (list_foldr .id (const []) <| to₂ <| comp (@list_append α _) snd).of_eq fun l => by dsimp; induction l <;> simp [*] theorem list_flatMap {f : α → List β} {g : α → β → List σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec (fun a => (f a).flatMap (g a)) := list_flatten.comp (list_map hf hg) theorem optionToList : Primrec (Option.toList : Option α → List α) := (option_casesOn Primrec.id (const []) ((list_cons.comp Primrec.id (const [])).comp₂ Primrec₂.right)).of_eq (fun o => by rcases o <;> simp) theorem listFilterMap {f : α → List β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).filterMap (g a) := (list_flatMap hf (comp₂ optionToList hg)).of_eq fun _ ↦ Eq.symm <| List.filterMap_eq_flatMap_toList _ _ theorem list_length : Primrec (@List.length α) := (list_foldr (@Primrec.id (List α) _) (const 0) <| to₂ <| (succ.comp <| snd.comp snd).to₂).of_eq fun l => by dsimp; induction l <;> simp [*] theorem list_findIdx {f : α → List β} {p : α → β → Bool} (hf : Primrec f) (hp : Primrec₂ p) : Primrec fun a => (f a).findIdx (p a) := (list_foldr hf (const 0) <| to₂ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *] theorem list_idxOf [DecidableEq α] : Primrec₂ (@List.idxOf α _) := to₂ <| list_findIdx snd <| Primrec.beq.comp₂ snd.to₂ (fst.comp fst).to₂ @[deprecated (since := "2025-01-30")] alias list_indexOf := list_idxOf theorem nat_strong_rec (f : α → ℕ → σ) {g : α → List σ → Option σ} (hg : Primrec₂ g) (H : ∀ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrec₂ f := suffices Primrec₂ fun a n => (List.range n).map (f a) from Primrec₂.option_some_iff.1 <| (list_getElem?.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq fun a n => by simp [List.getElem?_range (Nat.lt_succ_self n)] Primrec₂.option_some_iff.1 <| (nat_rec (const (some [])) (to₂ <| option_bind (snd.comp snd) <| to₂ <| option_map (hg.comp (fst.comp fst) snd) (to₂ <| list_concat.comp (snd.comp fst) snd))).of_eq fun a n => by induction n with | zero => rfl | succ n IH => simp [IH, H, List.range_succ] theorem listLookup [DecidableEq α] : Primrec₂ (List.lookup : α → List (α × β) → Option β) := (to₂ <| list_rec snd (const none) <| to₂ <| cond (Primrec.beq.comp (fst.comp fst) (fst.comp <| fst.comp snd)) (option_some.comp <| snd.comp <| fst.comp snd) (snd.comp <| snd.comp snd)).of_eq fun a ps => by induction' ps with p ps ih <;> simp [List.lookup, *] cases ha : a == p.1 <;> simp [ha] theorem nat_omega_rec' (f : β → σ) {m : β → ℕ} {l : β → List β} {g : β → List σ → Option σ} (hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g) (Ord : ∀ b, ∀ b' ∈ l b, m b' < m b) (H : ∀ b, g b ((l b).map f) = some (f b)) : Primrec f := by haveI : DecidableEq β := Encodable.decidableEqOfEncodable β let mapGraph (M : List (β × σ)) (bs : List β) : List σ := bs.flatMap (Option.toList <| M.lookup ·) let bindList (b : β) : ℕ → List β := fun n ↦ n.rec [b] fun _ bs ↦ bs.flatMap l let graph (b : β) : ℕ → List (β × σ) := fun i ↦ i.rec [] fun i ih ↦ (bindList b (m b - i)).filterMap fun b' ↦ (g b' <| mapGraph ih (l b')).map (b', ·) have mapGraph_primrec : Primrec₂ mapGraph := to₂ <| list_flatMap snd <| optionToList.comp₂ <| listLookup.comp₂ .right (fst.comp₂ .left) have bindList_primrec : Primrec₂ (bindList) := nat_rec' snd (list_cons.comp fst (const [])) (to₂ <| list_flatMap (snd.comp snd) (hl.comp₂ .right)) have graph_primrec : Primrec₂ (graph) := to₂ <| nat_rec' snd (const []) <| to₂ <| listFilterMap (bindList_primrec.comp (fst.comp fst) (nat_sub.comp (hm.comp <| fst.comp fst) (fst.comp snd))) <| to₂ <| option_map (hg.comp snd (mapGraph_primrec.comp (snd.comp <| snd.comp fst) (hl.comp snd))) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right) have : Primrec (fun b => (graph b (m b + 1))[0]?.map Prod.snd) := option_map (list_getElem?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0)) (snd.comp₂ Primrec₂.right) exact option_some_iff.mp <| this.of_eq <| fun b ↦ by have graph_eq_map_bindList (i : ℕ) (hi : i ≤ m b + 1) : graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by have bindList_eq_nil : bindList b (m b + 1) = [] := have bindList_m_lt (k : ℕ) : ∀ b' ∈ bindList b k, m b' < m b + 1 - k := by induction' k with k ih <;> simp [bindList] intro a₂ a₁ ha₁ ha₂ have : k ≤ m b := Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub <| Nat.zero_lt_of_lt (ih a₁ ha₁)) have : m a₁ ≤ m b - k := Nat.lt_succ.mp (by rw [← Nat.succ_sub this]; simpa using ih a₁ ha₁) exact lt_of_lt_of_le (Ord a₁ a₂ ha₂) this List.eq_nil_iff_forall_not_mem.mpr (by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha') have mapGraph_graph {bs bs' : List β} (has : bs' ⊆ bs) : mapGraph (bs.map <| fun x => (x, f x)) bs' = bs'.map f := by induction' bs' with b bs' ih <;> simp [mapGraph] · have : b ∈ bs ∧ bs' ⊆ bs := by simpa using has rcases this with ⟨ha, has'⟩ simpa [List.lookup_graph f ha] using ih has' have graph_succ : ∀ i, graph b (i + 1) = (bindList b (m b - i)).filterMap fun b' => (g b' <| mapGraph (graph b i) (l b')).map (b', ·) := fun _ => rfl have bindList_succ : ∀ i, bindList b (i + 1) = (bindList b i).flatMap l := fun _ => rfl induction' i with i ih · symm; simpa [graph] using bindList_eq_nil · simp only [graph_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi), Nat.succ_eq_add_one, bindList_succ, Nat.reduceSubDiff] apply List.filterMap_eq_map_iff_forall_eq_some.mpr intro b' ha'; simp; rw [mapGraph_graph] · exact H b' · exact (List.infix_flatMap_of_mem ha' l).subset simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList] theorem nat_omega_rec (f : α → β → σ) {m : α → β → ℕ} {l : α → β → List β} {g : α → β × List σ → Option σ} (hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g) (Ord : ∀ a b, ∀ b' ∈ l a b, m a b' < m a b) (H : ∀ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrec₂ f := Primrec₂.uncurry.mp <| nat_omega_rec' (Function.uncurry f) (Primrec₂.uncurry.mpr hm) (list_map (hl.comp fst snd) (Primrec₂.pair.comp₂ (fst.comp₂ .left) .right)) (hg.comp₂ (fst.comp₂ .left) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right)) (by simpa using Ord) (by simpa [Function.comp] using H) end Primrec namespace Primcodable variable {α : Type*} [Primcodable α] open Primrec /-- A subtype of a primitive recursive predicate is `Primcodable`. -/ def subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) := ⟨have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a := option_bind .decode (option_guard (hp.comp snd).to₂ snd) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => show _ = encode ((@decode α _ n).bind fun _ => _) by rcases @decode α _ n with - | a; · rfl dsimp [Option.guard] by_cases h : p a <;> simp [h]; rfl⟩ instance fin {n} : Primcodable (Fin n) := @ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype instance vector {n} : Primcodable (List.Vector α n) := subtype ((@Primrec.eq ℕ _ _).comp list_length (const _)) instance finArrow {n} : Primcodable (Fin n → α) := ofEquiv _ (Equiv.vectorEquivFin _ _).symm section ULower attribute [local instance] Encodable.decidableRangeEncode Encodable.decidableEqOfEncodable theorem mem_range_encode : PrimrecPred (fun n => n ∈ Set.range (encode : α → ℕ)) := have : PrimrecPred fun n => Encodable.decode₂ α n ≠ none := .not (Primrec.eq.comp (.option_bind .decode (.ite (Primrec.eq.comp (Primrec.encode.comp .snd) .fst) (Primrec.option_some.comp .snd) (.const _))) (.const _)) this.of_eq fun _ => decode₂_ne_none_iff instance ulower : Primcodable (ULower α) := Primcodable.subtype mem_range_encode end ULower end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem subtype_val {p : α → Prop} [DecidablePred p] {hp : PrimrecPred p} : haveI := Primcodable.subtype hp Primrec (@Subtype.val α p) := by letI := Primcodable.subtype hp refine (@Primcodable.prim (Subtype p)).of_eq fun n => ?_ rcases @decode (Subtype p) _ n with (_ | ⟨a, h⟩) <;> rfl theorem subtype_val_iff {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p} : haveI := Primcodable.subtype hp (Primrec fun a => (f a).1) ↔ Primrec f := by letI := Primcodable.subtype hp refine ⟨fun h => ?_, fun hf => subtype_val.comp hf⟩ refine Nat.Primrec.of_eq h fun n => ?_ rcases @decode α _ n with - | a; · rfl simp; rfl theorem subtype_mk {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → β} {h : ∀ a, p (f a)} (hf : Primrec f) : haveI := Primcodable.subtype hp Primrec fun a => @Subtype.mk β p (f a) (h a) := subtype_val_iff.1 hf theorem option_get {f : α → Option β} {h : ∀ a, (f a).isSome} : Primrec f → Primrec fun a => (f a).get (h a) := by intro hf refine (Nat.Primrec.pred.comp hf).of_eq fun n => ?_ generalize hx : @decode α _ n = x cases x <;> simp theorem ulower_down : Primrec (ULower.down : α → ULower α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ subtype_mk .encode theorem ulower_up : Primrec (ULower.up : ULower α → α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ option_get (Primrec.decode₂.comp subtype_val) theorem fin_val_iff {n} {f : α → Fin n} : (Primrec fun a => (f a).1) ↔ Primrec f := by
letI : Primcodable { a // id a < n } := Primcodable.subtype (nat_lt.comp .id (const _)) exact (Iff.trans (by rfl) subtype_val_iff).trans (of_equiv_iff _) theorem fin_val {n} : Primrec (fun (i : Fin n) => (i : ℕ)) := fin_val_iff.2 .id theorem fin_succ {n} : Primrec (@Fin.succ n) := fin_val_iff.1 <| by simp [succ.comp fin_val] theorem vector_toList {n} : Primrec (@List.Vector.toList α n) := subtype_val theorem vector_toList_iff {n} {f : α → List.Vector β n} : (Primrec fun a => (f a).toList) ↔ Primrec f := subtype_val_iff theorem vector_cons {n} : Primrec₂ (@List.Vector.cons α n) := vector_toList_iff.1 <| by simpa using list_cons.comp fst (vector_toList_iff.2 snd) theorem vector_length {n} : Primrec (@List.Vector.length α n) := const _ theorem vector_head {n} : Primrec (@List.Vector.head α n) := option_some_iff.1 <| (list_head?.comp vector_toList).of_eq fun ⟨_ :: _, _⟩ => rfl theorem vector_tail {n} : Primrec (@List.Vector.tail α n) := vector_toList_iff.1 <| (list_tail.comp vector_toList).of_eq fun ⟨l, h⟩ => by cases l <;> rfl theorem vector_get {n} : Primrec₂ (@List.Vector.get α n) := option_some_iff.1 <| (list_getElem?.comp (vector_toList.comp fst) (fin_val.comp snd)).of_eq fun a => by simp [Vector.get_eq_get_toList] theorem list_ofFn : ∀ {n} {f : Fin n → α → σ}, (∀ i, Primrec (f i)) → Primrec fun a => List.ofFn fun i => f i a | 0, _, _ => by simp only [List.ofFn_zero]; exact const [] | n + 1, f, hf => by simpa [List.ofFn_succ] using list_cons.comp (hf 0) (list_ofFn fun i => hf i.succ) theorem vector_ofFn {n} {f : Fin n → α → σ} (hf : ∀ i, Primrec (f i)) : Primrec fun a => List.Vector.ofFn fun i => f i a := vector_toList_iff.1 <| by simp [list_ofFn hf] theorem vector_get' {n} : Primrec (@List.Vector.get α n) := of_equiv_symm theorem vector_ofFn' {n} : Primrec (@List.Vector.ofFn α n) := of_equiv theorem fin_app {n} : Primrec₂ (@id (Fin n → σ)) := (vector_get.comp (vector_ofFn'.comp fst) snd).of_eq fun ⟨v, i⟩ => by simp theorem fin_curry₁ {n} {f : Fin n → α → σ} : Primrec₂ f ↔ ∀ i, Primrec (f i) := ⟨fun h i => h.comp (const i) .id, fun h => (vector_get.comp ((vector_ofFn h).comp snd) fst).of_eq fun a => by simp⟩ theorem fin_curry {n} {f : α → Fin n → σ} : Primrec f ↔ Primrec₂ f := ⟨fun h => fin_app.comp (h.comp fst) snd, fun h => (vector_get'.comp (vector_ofFn fun i => show Primrec fun a => f a i from h.comp .id (const i))).of_eq
Mathlib/Computability/Primrec.lean
1,176
1,235
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Fin.consEquiv _).symm.trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, isTrivial_apply, sub_self, LinearMap.zero_apply, Pi.zero_apply] lemma dZero_comp_subtype : dZero A ∘ₗ A.ρ.invariants.subtype = 0 := by ext ⟨x, hx⟩ g replace hx := hx g rw [← sub_eq_zero] at hx exact hx /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 0 1).hom := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.val_eq_zero, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 1 2).hom := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 2 3).hom := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, Module.End.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by show (ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A)).hom = _ have h1 := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [ModuleCat.ofHom_comp, ModuleCat.ofHom_comp, ← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, ModuleCat.ofHom_hom, ModuleCat.hom_ofHom, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero, ModuleCat.hom_zero] open ShortComplex /-- The (exact) short complex `A.ρ.invariants ⟶ A ⟶ (G → A)`. -/ def shortComplexH0 : ShortComplex (ModuleCat k) := moduleCatMk _ _ (dZero_comp_subtype A) /-- The short complex `A --dZero--> Fun(G, A) --dOne--> Fun(G × G, A)`. -/ def shortComplexH1 : ShortComplex (ModuleCat k) := moduleCatMk (dZero A) (dOne A) (dOne_comp_dZero A) /-- The short complex `Fun(G, A) --dOne--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)`. -/ def shortComplexH2 : ShortComplex (ModuleCat k) := moduleCatMk (dOne A) (dTwo A) (dTwo_comp_dOne A) end Differentials section Cocycles /-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A) /-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G × G, A) → Fun(G × G × G, A)` sending `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A) variable {A} instance : FunLike (oneCocycles A) G A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem oneCocycles.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : oneCocycles A) : G → A) = f := rfl @[simp] theorem oneCocycles.val_eq_coe (f : oneCocycles A) : f.1 = f := rfl @[ext] theorem oneCocycles_ext {f₁ f₂ : oneCocycles A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ := DFunLike.ext f₁ f₂ h theorem mem_oneCocycles_def (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 := LinearMap.mem_ker.trans <| by rw [funext_iff] simp only [dOne_apply, Pi.zero_apply, Prod.forall] theorem mem_oneCocycles_iff (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm] @[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f 1 = 0 := by have := (mem_oneCocycles_def f).1 f.2 1 1 simpa only [map_one, Module.End.one_apply, mul_one, sub_self, zero_add] using this @[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) : A.ρ g (f g⁻¹) = - f g := by rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_cancel g, (mem_oneCocycles_iff f).1 f.2 g g⁻¹] theorem dZero_apply_mem_oneCocycles (x : A) : dZero A x ∈ oneCocycles A := congr($(dOne_comp_dZero A) x) theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) : f (g * h) = f g + f h := by rw [(mem_oneCocycles_iff f).1 f.2, isTrivial_apply A.ρ g (f h), add_comm] theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) : f ∘ Additive.ofMul ∈ oneCocycles A := (mem_oneCocycles_iff _).2 fun g h => by simp only [Function.comp_apply, ofMul_mul, map_add, oneCocycles_map_mul_of_isTrivial, isTrivial_apply A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))] variable (A) in /-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the group homs `G → A`. -/ @[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] : oneCocycles A ≃ₗ[k] Additive G →+ A where toFun f := { toFun := f ∘ Additive.toMul map_zero' := oneCocycles_map_one f map_add' := oneCocycles_map_mul_of_isTrivial f } map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := { val := f property := mem_oneCocycles_of_addMonoidHom f } left_inv f := by ext; rfl right_inv f := by ext; rfl instance : FunLike (twoCocycles A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem twoCocycles.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : twoCocycles A) : G × G → A) = f := rfl @[simp] theorem twoCocycles.val_eq_coe (f : twoCocycles A) : f.1 = f := rfl @[ext] theorem twoCocycles_ext {f₁ f₂ : twoCocycles A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ := DFunLike.ext f₁ f₂ (Prod.forall.mpr h) theorem mem_twoCocycles_def (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 := LinearMap.mem_ker.trans <| by rw [funext_iff] simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall] theorem mem_twoCocycles_iff (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, f (g * h, j) + f (g, h) = A.ρ g (f (h, j)) + f (g, h * j) := by simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm, add_comm (f (_ * _, _))] theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) : f (1, g) = f (1, 1) := by have := ((mem_twoCocycles_iff f).1 f.2 1 1 g).symm simpa only [map_one, Module.End.one_apply, one_mul, add_right_inj, this] theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) : f (g, 1) = A.ρ g (f (1, 1)) := by have := (mem_twoCocycles_iff f).1 f.2 g 1 1 simpa only [mul_one, add_left_inj, this] lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) : A.ρ g (f (g⁻¹, g)) - f (g, g⁻¹)
= f (1, 1) - f (g, 1) := by have := (mem_twoCocycles_iff f).1 f.2 g g⁻¹ g simp only [mul_inv_cancel, inv_mul_cancel, twoCocycles_map_one_fst _ g] at this
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
349
352
/- 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.Topology.PartialHomeomorph import Mathlib.Topology.Connected.LocPathConnected /-! # Charted spaces A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean half-space for manifolds with boundaries, or an infinite dimensional vector space for more general notions of manifolds), i.e., the manifold is covered by open subsets on which there are local homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth maps. In this file, we introduce a general framework describing these notions, where the model space is an arbitrary topological space. We avoid the word *manifold*, which should be reserved for the situation where the model space is a (subset of a) vector space, and use the terminology *charted space* instead. If the changes of charts satisfy some additional property (for instance if they are smooth), then `M` inherits additional structure (it makes sense to talk about smooth manifolds). There are therefore two different ingredients in a charted space: * the set of charts, which is data * the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop. We separate these two parts in the definition: the charted space structure is just the set of charts, and then the different smoothness requirements (smooth manifold, orientable manifold, contact manifold, and so on) are additional properties of these charts. These properties are formalized through the notion of structure groupoid, i.e., a set of partial homeomorphisms stable under composition and inverse, to which the change of coordinates should belong. ## Main definitions * `StructureGroupoid H` : a subset of partial homeomorphisms of `H` stable under composition, inverse and restriction (ex: partial diffeomorphisms). * `continuousGroupoid H` : the groupoid of all partial homeomorphisms of `H`. * `ChartedSpace H M` : charted space structure on `M` modelled on `H`, given by an atlas of partial homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class. * `HasGroupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space modelled on `H`, require that all coordinate changes belong to `G`. This is a type class. * `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted space structure, i.e., the set of charts. * `G.maximalAtlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a structure groupoid, one can consider all the partial homeomorphisms from `M` to `H` such that changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the maximal atlas (for the groupoid `G`). * `Structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category. As a basic example, we give the instance `instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H` saying that a topological space is a charted space over itself, with the identity as unique chart. This charted space structure is compatible with any groupoid. Additional useful definitions: * `Pregroupoid H` : a subset of partial maps of `H` stable under composition and restriction, but not inverse (ex: smooth maps) * `Pregroupoid.groupoid` : construct a groupoid from a pregroupoid, by requiring that a map and its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps) * `chartAt H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on `H`. * `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid. * `G.compatible_of_mem_maximalAtlas he he'` states that, for any two charts `e` and `e'` in the maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the `G` if `M` admits `G` as a structure groupoid. * `ChartedSpaceCore.toChartedSpace`: consider a space without a topology, but endowed with a set of charts (which are partial equivs) for which the change of coordinates are partial homeos. Then one can construct a topology on the space for which the charts become partial homeos, defining a genuine charted space structure. ## Implementation notes The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the definition is only that, read in charts, the structomorphism locally belongs to the groupoid under consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas). A consequence is that the invariance under structomorphisms of properties defined in terms of the atlas is not obvious in general, and could require some work in theory (amounting to the fact that these properties only depend on the maximal atlas, for instance). In practice, this does not create any real difficulty. We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the model space is a half space. Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and sometimes as spaces with an atlas from which a topology is deduced. We use the former approach: otherwise, there would be an instance from manifolds to topological spaces, which means that any instance search for topological spaces would try to find manifold structures involving a yet unknown model space, leading to problems. However, we also introduce the latter approach, through a structure `ChartedSpaceCore` making it possible to construct a topology out of a set of partial equivs with compatibility conditions (but we do not register it as an instance). In the definition of a charted space, the model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`. ## Notations In the locale `Manifold`, we denote the composition of partial homeomorphisms with `≫ₕ`, and the composition of partial equivs with `≫`. -/ noncomputable section open TopologicalSpace Topology universe u variable {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*} /- Notational shortcut for the composition of partial homeomorphisms and partial equivs, i.e., `PartialHomeomorph.trans` and `PartialEquiv.trans`. Note that, as is usual for equivs, the composition is from left to right, hence the direction of the arrow. -/ @[inherit_doc] scoped[Manifold] infixr:100 " ≫ₕ " => PartialHomeomorph.trans @[inherit_doc] scoped[Manifold] infixr:100 " ≫ " => PartialEquiv.trans open Set PartialHomeomorph Manifold -- Porting note: Added `Manifold` /-! ### Structure groupoids -/ section Groupoid /-! One could add to the definition of a structure groupoid the fact that the restriction of an element of the groupoid to any open set still belongs to the groupoid. (This is in Kobayashi-Nomizu.) I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is made of functions respecting the fibers and linear in the fibers (so that a charted space over this groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always defined on sets of the form `s × E`. There is a typeclass `ClosedUnderRestriction` for groupoids which have the restriction property. The only nontrivial requirement is locality: if a partial homeomorphism belongs to the groupoid around each point in its domain of definition, then it belongs to the groupoid. Without this requirement, the composition of structomorphisms does not have to be a structomorphism. Note that this implies that a partial homeomorphism with empty source belongs to any structure groupoid, as it trivially satisfies this condition. There is also a technical point, related to the fact that a partial homeomorphism is by definition a global map which is a homeomorphism when restricted to its source subset (and its values outside of the source are not relevant). Therefore, we also require that being a member of the groupoid only depends on the values on the source. We use primes in the structure names as we will reformulate them below (without primes) using a `Membership` instance, writing `e ∈ G` instead of `e ∈ G.members`. -/ /-- A structure groupoid is a set of partial homeomorphisms of a topological space stable under composition and inverse. They appear in the definition of the smoothness class of a manifold. -/ structure StructureGroupoid (H : Type u) [TopologicalSpace H] where /-- Members of the structure groupoid are partial homeomorphisms. -/ members : Set (PartialHomeomorph H H) /-- Structure groupoids are stable under composition. -/ trans' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members /-- Structure groupoids are stable under inverse. -/ symm' : ∀ e : PartialHomeomorph H H, e ∈ members → e.symm ∈ members /-- The identity morphism lies in the structure groupoid. -/ id_mem' : PartialHomeomorph.refl H ∈ members /-- Let `e` be a partial homeomorphism. If for every `x ∈ e.source`, the restriction of e to some open set around `x` lies in the groupoid, then `e` lies in the groupoid. -/ locality' : ∀ e : PartialHomeomorph H H, (∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ members) → e ∈ members /-- Membership in a structure groupoid respects the equivalence of partial homeomorphisms. -/ mem_of_eqOnSource' : ∀ e e' : PartialHomeomorph H H, e ∈ members → e' ≈ e → e' ∈ members variable [TopologicalSpace H] instance : Membership (PartialHomeomorph H H) (StructureGroupoid H) := ⟨fun (G : StructureGroupoid H) (e : PartialHomeomorph H H) ↦ e ∈ G.members⟩ instance (H : Type u) [TopologicalSpace H] : SetLike (StructureGroupoid H) (PartialHomeomorph H H) where coe s := s.members coe_injective' N O h := by cases N; cases O; congr instance : Min (StructureGroupoid H) := ⟨fun G G' => StructureGroupoid.mk (members := G.members ∩ G'.members) (trans' := fun e e' he he' => ⟨G.trans' e e' he.left he'.left, G'.trans' e e' he.right he'.right⟩) (symm' := fun e he => ⟨G.symm' e he.left, G'.symm' e he.right⟩) (id_mem' := ⟨G.id_mem', G'.id_mem'⟩) (locality' := by intro e hx apply (mem_inter_iff e G.members G'.members).mpr refine And.intro (G.locality' e ?_) (G'.locality' e ?_) all_goals intro x hex rcases hx x hex with ⟨s, hs⟩ use s refine And.intro hs.left (And.intro hs.right.left ?_) · exact hs.right.right.left · exact hs.right.right.right) (mem_of_eqOnSource' := fun e e' he hee' => ⟨G.mem_of_eqOnSource' e e' he.left hee', G'.mem_of_eqOnSource' e e' he.right hee'⟩)⟩ instance : InfSet (StructureGroupoid H) := ⟨fun S => StructureGroupoid.mk (members := ⋂ s ∈ S, s.members) (trans' := by simp only [mem_iInter] intro e e' he he' i hi exact i.trans' e e' (he i hi) (he' i hi)) (symm' := by simp only [mem_iInter] intro e he i hi exact i.symm' e (he i hi)) (id_mem' := by simp only [mem_iInter] intro i _ exact i.id_mem') (locality' := by simp only [mem_iInter] intro e he i hi refine i.locality' e ?_ intro x hex rcases he x hex with ⟨s, hs⟩ exact ⟨s, ⟨hs.left, ⟨hs.right.left, hs.right.right i hi⟩⟩⟩) (mem_of_eqOnSource' := by simp only [mem_iInter] intro e e' he he'e exact fun i hi => i.mem_of_eqOnSource' e e' (he i hi) he'e)⟩ theorem StructureGroupoid.trans (G : StructureGroupoid H) {e e' : PartialHomeomorph H H} (he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G := G.trans' e e' he he' theorem StructureGroupoid.symm (G : StructureGroupoid H) {e : PartialHomeomorph H H} (he : e ∈ G) : e.symm ∈ G := G.symm' e he theorem StructureGroupoid.id_mem (G : StructureGroupoid H) : PartialHomeomorph.refl H ∈ G := G.id_mem' theorem StructureGroupoid.locality (G : StructureGroupoid H) {e : PartialHomeomorph H H} (h : ∀ x ∈ e.source, ∃ s, IsOpen s ∧ x ∈ s ∧ e.restr s ∈ G) : e ∈ G := G.locality' e h theorem StructureGroupoid.mem_of_eqOnSource (G : StructureGroupoid H) {e e' : PartialHomeomorph H H} (he : e ∈ G) (h : e' ≈ e) : e' ∈ G := G.mem_of_eqOnSource' e e' he h theorem StructureGroupoid.mem_iff_of_eqOnSource {G : StructureGroupoid H} {e e' : PartialHomeomorph H H} (h : e ≈ e') : e ∈ G ↔ e' ∈ G := ⟨fun he ↦ G.mem_of_eqOnSource he (Setoid.symm h), fun he' ↦ G.mem_of_eqOnSource he' h⟩ /-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid. -/ instance StructureGroupoid.partialOrder : PartialOrder (StructureGroupoid H) := PartialOrder.lift StructureGroupoid.members fun a b h ↦ by cases a cases b dsimp at h induction h rfl theorem StructureGroupoid.le_iff {G₁ G₂ : StructureGroupoid H} : G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ := Iff.rfl /-- The trivial groupoid, containing only the identity (and maps with empty source, as this is necessary from the definition). -/ def idGroupoid (H : Type u) [TopologicalSpace H] : StructureGroupoid H where members := {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ } trans' e e' he he' := by rcases he with he | he · simpa only [mem_singleton_iff.1 he, refl_trans] · have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _ rw [he] at this have : e ≫ₕ e' ∈ { e : PartialHomeomorph H H | e.source = ∅ } := eq_bot_iff.2 this exact (mem_union _ _ _).2 (Or.inr this) symm' e he := by rcases (mem_union _ _ _).1 he with E | E · simp [mem_singleton_iff.mp E] · right simpa only [e.toPartialEquiv.image_source_eq_target.symm, mfld_simps] using E id_mem' := mem_union_left _ rfl locality' e he := by rcases e.source.eq_empty_or_nonempty with h | h · right exact h · left rcases h with ⟨x, hx⟩ rcases he x hx with ⟨s, open_s, xs, hs⟩ have x's : x ∈ (e.restr s).source := by rw [restr_source, open_s.interior_eq] exact ⟨hx, xs⟩ rcases hs with hs | hs · replace hs : PartialHomeomorph.restr e s = PartialHomeomorph.refl H := by simpa only using hs have : (e.restr s).source = univ := by rw [hs] simp have : e.toPartialEquiv.source ∩ interior s = univ := this have : univ ⊆ interior s := by rw [← this] exact inter_subset_right have : s = univ := by rwa [open_s.interior_eq, univ_subset_iff] at this simpa only [this, restr_univ] using hs · exfalso rw [mem_setOf_eq] at hs rwa [hs] at x's mem_of_eqOnSource' e e' he he'e := by rcases he with he | he · left have : e = e' := by refine eq_of_eqOnSource_univ (Setoid.symm he'e) ?_ ?_ <;> rw [Set.mem_singleton_iff.1 he] <;> rfl rwa [← this] · right have he : e.toPartialEquiv.source = ∅ := he rwa [Set.mem_setOf_eq, EqOnSource.source_eq he'e] /-- Every structure groupoid contains the identity groupoid. -/ instance instStructureGroupoidOrderBot : OrderBot (StructureGroupoid H) where bot := idGroupoid H bot_le := by intro u f hf have hf : f ∈ {PartialHomeomorph.refl H} ∪ { e : PartialHomeomorph H H | e.source = ∅ } := hf simp only [singleton_union, mem_setOf_eq, mem_insert_iff] at hf rcases hf with hf | hf · rw [hf] apply u.id_mem · apply u.locality intro x hx rw [hf, mem_empty_iff_false] at hx exact hx.elim instance : Inhabited (StructureGroupoid H) := ⟨idGroupoid H⟩ /-- To construct a groupoid, one may consider classes of partial homeomorphisms such that both the function and its inverse have some property. If this property is stable under composition, one gets a groupoid. `Pregroupoid` bundles the properties needed for this construction, with the groupoid of smooth functions with smooth inverses as an application. -/ structure Pregroupoid (H : Type*) [TopologicalSpace H] where /-- Property describing membership in this groupoid: the pregroupoid "contains" all functions `H → H` having the pregroupoid property on some `s : Set H` -/ property : (H → H) → Set H → Prop /-- The pregroupoid property is stable under composition -/ comp : ∀ {f g u v}, property f u → property g v → IsOpen u → IsOpen v → IsOpen (u ∩ f ⁻¹' v) → property (g ∘ f) (u ∩ f ⁻¹' v) /-- Pregroupoids contain the identity map (on `univ`) -/ id_mem : property id univ /-- The pregroupoid property is "local", in the sense that `f` has the pregroupoid property on `u` iff its restriction to each open subset of `u` has it -/ locality : ∀ {f u}, IsOpen u → (∀ x ∈ u, ∃ v, IsOpen v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u /-- If `f = g` on `u` and `property f u`, then `property g u` -/ congr : ∀ {f g : H → H} {u}, IsOpen u → (∀ x ∈ u, g x = f x) → property f u → property g u /-- Construct a groupoid of partial homeos for which the map and its inverse have some property, from a pregroupoid asserting that this property is stable under composition. -/ def Pregroupoid.groupoid (PG : Pregroupoid H) : StructureGroupoid H where members := { e : PartialHomeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target } trans' e e' he he' := by constructor · apply PG.comp he.1 he'.1 e.open_source e'.open_source apply e.continuousOn_toFun.isOpen_inter_preimage e.open_source e'.open_source · apply PG.comp he'.2 he.2 e'.open_target e.open_target apply e'.continuousOn_invFun.isOpen_inter_preimage e'.open_target e.open_target symm' _ he := ⟨he.2, he.1⟩ id_mem' := ⟨PG.id_mem, PG.id_mem⟩ locality' e he := by constructor · refine PG.locality e.open_source fun x xu ↦ ?_ rcases he x xu with ⟨s, s_open, xs, hs⟩ refine ⟨s, s_open, xs, ?_⟩ convert hs.1 using 1 dsimp [PartialHomeomorph.restr] rw [s_open.interior_eq] · refine PG.locality e.open_target fun x xu ↦ ?_ rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩ refine ⟨e.target ∩ e.symm ⁻¹' s, ?_, ⟨xu, xs⟩, ?_⟩ · exact ContinuousOn.isOpen_inter_preimage e.continuousOn_invFun e.open_target s_open · rw [← inter_assoc, inter_self] convert hs.2 using 1 dsimp [PartialHomeomorph.restr] rw [s_open.interior_eq] mem_of_eqOnSource' e e' he ee' := by constructor · apply PG.congr e'.open_source ee'.2 simp only [ee'.1, he.1] · have A := EqOnSource.symm' ee' apply PG.congr e'.symm.open_source A.2 -- Porting note: was -- convert he.2 -- rw [A.1] -- rfl rw [A.1, symm_toPartialEquiv, PartialEquiv.symm_source] exact he.2 theorem mem_groupoid_of_pregroupoid {PG : Pregroupoid H} {e : PartialHomeomorph H H} : e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target := Iff.rfl theorem groupoid_of_pregroupoid_le (PG₁ PG₂ : Pregroupoid H) (h : ∀ f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid := by refine StructureGroupoid.le_iff.2 fun e he ↦ ?_ rw [mem_groupoid_of_pregroupoid] at he ⊢ exact ⟨h _ _ he.1, h _ _ he.2⟩ theorem mem_pregroupoid_of_eqOnSource (PG : Pregroupoid H) {e e' : PartialHomeomorph H H} (he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source := by rw [← he'.1] exact PG.congr e.open_source he'.eqOn.symm he /-- The pregroupoid of all partial maps on a topological space `H`. -/ abbrev continuousPregroupoid (H : Type*) [TopologicalSpace H] : Pregroupoid H where property _ _ := True comp _ _ _ _ _ := trivial id_mem := trivial locality _ _ := trivial congr _ _ _ := trivial instance (H : Type*) [TopologicalSpace H] : Inhabited (Pregroupoid H) := ⟨continuousPregroupoid H⟩ /-- The groupoid of all partial homeomorphisms on a topological space `H`. -/ def continuousGroupoid (H : Type*) [TopologicalSpace H] : StructureGroupoid H := Pregroupoid.groupoid (continuousPregroupoid H) /-- Every structure groupoid is contained in the groupoid of all partial homeomorphisms. -/ instance instStructureGroupoidOrderTop : OrderTop (StructureGroupoid H) where top := continuousGroupoid H le_top _ _ _ := ⟨trivial, trivial⟩ instance : CompleteLattice (StructureGroupoid H) := { SetLike.instPartialOrder, completeLatticeOfInf _ (by exact fun s => ⟨fun S Ss F hF => mem_iInter₂.mp hF S Ss, fun T Tl F fT => mem_iInter₂.mpr (fun i his => Tl his fT)⟩) with le := (· ≤ ·) lt := (· < ·) bot := instStructureGroupoidOrderBot.bot bot_le := instStructureGroupoidOrderBot.bot_le top := instStructureGroupoidOrderTop.top le_top := instStructureGroupoidOrderTop.le_top inf := (· ⊓ ·) le_inf := fun _ _ _ h₁₂ h₁₃ _ hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } /-- A groupoid is closed under restriction if it contains all restrictions of its element local homeomorphisms to open subsets of the source. -/ class ClosedUnderRestriction (G : StructureGroupoid H) : Prop where closedUnderRestriction : ∀ {e : PartialHomeomorph H H}, e ∈ G → ∀ s : Set H, IsOpen s → e.restr s ∈ G theorem closedUnderRestriction' {G : StructureGroupoid H} [ClosedUnderRestriction G] {e : PartialHomeomorph H H} (he : e ∈ G) {s : Set H} (hs : IsOpen s) : e.restr s ∈ G := ClosedUnderRestriction.closedUnderRestriction he s hs /-- The trivial restriction-closed groupoid, containing only partial homeomorphisms equivalent to the restriction of the identity to the various open subsets. -/ def idRestrGroupoid : StructureGroupoid H where members := { e | ∃ (s : Set H) (h : IsOpen s), e ≈ PartialHomeomorph.ofSet s h } trans' := by rintro e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩ refine ⟨s ∩ s', hs.inter hs', ?_⟩ have := PartialHomeomorph.EqOnSource.trans' hse hse' rwa [PartialHomeomorph.ofSet_trans_ofSet] at this symm' := by rintro e ⟨s, hs, hse⟩ refine ⟨s, hs, ?_⟩ rw [← ofSet_symm] exact PartialHomeomorph.EqOnSource.symm' hse id_mem' := ⟨univ, isOpen_univ, by simp only [mfld_simps, refl]⟩ locality' := by intro e h refine ⟨e.source, e.open_source, by simp only [mfld_simps], ?_⟩ intro x hx rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩ have hes : x ∈ (e.restr s).source := by rw [e.restr_source] refine ⟨hx, ?_⟩ rw [hs.interior_eq] exact hxs simpa only [mfld_simps] using PartialHomeomorph.EqOnSource.eqOn hes' hes mem_of_eqOnSource' := by rintro e e' ⟨s, hs, hse⟩ hee' exact ⟨s, hs, Setoid.trans hee' hse⟩ theorem idRestrGroupoid_mem {s : Set H} (hs : IsOpen s) : ofSet s hs ∈ @idRestrGroupoid H _ := ⟨s, hs, refl _⟩ /-- The trivial restriction-closed groupoid is indeed `ClosedUnderRestriction`. -/ instance closedUnderRestriction_idRestrGroupoid : ClosedUnderRestriction (@idRestrGroupoid H _) := ⟨by rintro e ⟨s', hs', he⟩ s hs use s' ∩ s, hs'.inter hs refine Setoid.trans (PartialHomeomorph.EqOnSource.restr he s) ?_ exact ⟨by simp only [hs.interior_eq, mfld_simps], by simp only [mfld_simps, eqOn_refl]⟩⟩ /-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed groupoid. -/ theorem closedUnderRestriction_iff_id_le (G : StructureGroupoid H) : ClosedUnderRestriction G ↔ idRestrGroupoid ≤ G := by constructor · intro _i rw [StructureGroupoid.le_iff] rintro e ⟨s, hs, hes⟩ refine G.mem_of_eqOnSource ?_ hes convert closedUnderRestriction' G.id_mem hs -- Porting note: was -- change s = _ ∩ _ -- rw [hs.interior_eq] -- simp only [mfld_simps] ext · rw [PartialHomeomorph.restr_apply, PartialHomeomorph.refl_apply, id, ofSet_apply, id_eq] · simp [hs] · simp [hs.interior_eq] · intro h constructor intro e he s hs rw [← ofSet_trans (e : PartialHomeomorph H H) hs] refine G.trans ?_ he apply StructureGroupoid.le_iff.mp h exact idRestrGroupoid_mem hs /-- The groupoid of all partial homeomorphisms on a topological space `H` is closed under restriction. -/ instance : ClosedUnderRestriction (continuousGroupoid H) := (closedUnderRestriction_iff_id_le _).mpr le_top end Groupoid /-! ### Charted spaces -/ /-- A charted space is a topological space endowed with an atlas, i.e., a set of local homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts cover the whole space. We express the covering property by choosing for each `x` a member `chartAt x` of the atlas containing `x` in its source: in the smooth case, this is convenient to construct the tangent bundle in an efficient way. The model space is written as an explicit parameter as there can be several model spaces for a given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen sometimes as a real manifold over `ℝ^(2n)`. -/ @[ext] class ChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] where /-- The atlas of charts in the `ChartedSpace`. -/ protected atlas : Set (PartialHomeomorph M H) /-- The preferred chart at each point in the charted space. -/ protected chartAt : M → PartialHomeomorph M H protected mem_chart_source : ∀ x, x ∈ (chartAt x).source protected chart_mem_atlas : ∀ x, chartAt x ∈ atlas /-- The atlas of charts in a `ChartedSpace`. -/ abbrev atlas (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] : Set (PartialHomeomorph M H) := ChartedSpace.atlas /-- The preferred chart at a point `x` in a charted space `M`. -/ abbrev chartAt (H : Type*) [TopologicalSpace H] {M : Type*} [TopologicalSpace M] [ChartedSpace H M] (x : M) : PartialHomeomorph M H := ChartedSpace.chartAt x @[simp, mfld_simps] lemma mem_chart_source (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : x ∈ (chartAt H x).source := ChartedSpace.mem_chart_source x @[simp, mfld_simps] lemma chart_mem_atlas (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : chartAt H x ∈ atlas H M := ChartedSpace.chart_mem_atlas x lemma nonempty_of_chartedSpace {H : Type*} {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] (x : M) : Nonempty H := ⟨chartAt H x x⟩ lemma isEmpty_of_chartedSpace (H : Type*) {M : Type*} [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] [IsEmpty H] : IsEmpty M := by rcases isEmpty_or_nonempty M with hM | ⟨⟨x⟩⟩ · exact hM · exact (IsEmpty.false (chartAt H x x)).elim section ChartedSpace section variable (H) [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] -- Porting note: Added `(H := H)` to avoid typeclass instance problem. theorem mem_chart_target (x : M) : chartAt H x x ∈ (chartAt H x).target := (chartAt H x).map_source (mem_chart_source _ _) theorem chart_source_mem_nhds (x : M) : (chartAt H x).source ∈ 𝓝 x := (chartAt H x).open_source.mem_nhds <| mem_chart_source H x theorem chart_target_mem_nhds (x : M) : (chartAt H x).target ∈ 𝓝 (chartAt H x x) := (chartAt H x).open_target.mem_nhds <| mem_chart_target H x variable (M) in @[simp] theorem iUnion_source_chartAt : (⋃ x : M, (chartAt H x).source) = (univ : Set M) := eq_univ_iff_forall.mpr fun x ↦ mem_iUnion.mpr ⟨x, mem_chart_source H x⟩ theorem ChartedSpace.isOpen_iff (s : Set M) : IsOpen s ↔ ∀ x : M, IsOpen <| chartAt H x '' ((chartAt H x).source ∩ s) := by rw [isOpen_iff_of_cover (fun i ↦ (chartAt H i).open_source) (iUnion_source_chartAt H M)] simp only [(chartAt H _).isOpen_image_iff_of_subset_source inter_subset_left] /-- `achart H x` is the chart at `x`, considered as an element of the atlas. Especially useful for working with `BasicContMDiffVectorBundleCore`. -/ def achart (x : M) : atlas H M := ⟨chartAt H x, chart_mem_atlas H x⟩ theorem achart_def (x : M) : achart H x = ⟨chartAt H x, chart_mem_atlas H x⟩ := rfl @[simp, mfld_simps] theorem coe_achart (x : M) : (achart H x : PartialHomeomorph M H) = chartAt H x := rfl @[simp, mfld_simps] theorem achart_val (x : M) : (achart H x).1 = chartAt H x := rfl theorem mem_achart_source (x : M) : x ∈ (achart H x).1.source := mem_chart_source H x open TopologicalSpace theorem ChartedSpace.secondCountable_of_countable_cover [SecondCountableTopology H] {s : Set M} (hs : ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ) (hsc : s.Countable) : SecondCountableTopology M := by haveI : ∀ x : M, SecondCountableTopology (chartAt H x).source := fun x ↦ (chartAt (H := H) x).secondCountableTopology_source haveI := hsc.toEncodable rw [biUnion_eq_iUnion] at hs exact secondCountableTopology_of_countable_cover (fun x : s ↦ (chartAt H (x : M)).open_source) hs variable (M) theorem ChartedSpace.secondCountable_of_sigmaCompact [SecondCountableTopology H] [SigmaCompactSpace M] : SecondCountableTopology M := by obtain ⟨s, hsc, hsU⟩ : ∃ s, Set.Countable s ∧ ⋃ (x) (_ : x ∈ s), (chartAt H x).source = univ := countable_cover_nhds_of_sigmaCompact fun x : M ↦ chart_source_mem_nhds H x exact ChartedSpace.secondCountable_of_countable_cover H hsU hsc @[deprecated (since := "2024-11-13")] alias ChartedSpace.secondCountable_of_sigma_compact := ChartedSpace.secondCountable_of_sigmaCompact /-- If a topological space admits an atlas with locally compact charts, then the space itself is locally compact. -/ theorem ChartedSpace.locallyCompactSpace [LocallyCompactSpace H] : LocallyCompactSpace M := by have : ∀ x : M, (𝓝 x).HasBasis (fun s ↦ s ∈ 𝓝 (chartAt H x x) ∧ IsCompact s ∧ s ⊆ (chartAt H x).target) fun s ↦ (chartAt H x).symm '' s := fun x ↦ by rw [← (chartAt H x).symm_map_nhds_eq (mem_chart_source H x)] exact ((compact_basis_nhds (chartAt H x x)).hasBasis_self_subset (chart_target_mem_nhds H x)).map _ refine .of_hasBasis this ?_ rintro x s ⟨_, h₂, h₃⟩ exact h₂.image_of_continuousOn ((chartAt H x).continuousOn_symm.mono h₃) /-- If a topological space admits an atlas with locally connected charts, then the space itself is locally connected. -/ theorem ChartedSpace.locallyConnectedSpace [LocallyConnectedSpace H] : LocallyConnectedSpace M := by let e : M → PartialHomeomorph M H := chartAt H refine locallyConnectedSpace_of_connected_bases (fun x s ↦ (e x).symm '' s) (fun x s ↦ (IsOpen s ∧ e x x ∈ s ∧ IsConnected s) ∧ s ⊆ (e x).target) ?_ ?_ · intro x simpa only [e, PartialHomeomorph.symm_map_nhds_eq, mem_chart_source] using ((LocallyConnectedSpace.open_connected_basis (e x x)).restrict_subset ((e x).open_target.mem_nhds (mem_chart_target H x))).map (e x).symm · rintro x s ⟨⟨-, -, hsconn⟩, hssubset⟩ exact hsconn.isPreconnected.image _ ((e x).continuousOn_symm.mono hssubset) /-- If a topological space `M` admits an atlas with locally path-connected charts, then `M` itself is locally path-connected. -/ theorem ChartedSpace.locPathConnectedSpace [LocPathConnectedSpace H] : LocPathConnectedSpace M := by refine ⟨fun x ↦ ⟨fun s ↦ ⟨fun hs ↦ ?_, fun ⟨u, hu⟩ ↦ Filter.mem_of_superset hu.1.1 hu.2⟩⟩⟩ let e := chartAt H x let t := s ∩ e.source have ht : t ∈ 𝓝 x := Filter.inter_mem hs (chart_source_mem_nhds _ _) refine ⟨e.symm '' pathComponentIn (e x) (e '' t), ⟨?_, ?_⟩, (?_ : _ ⊆ t).trans inter_subset_left⟩ · nth_rewrite 1 [← e.left_inv (mem_chart_source _ _)] apply e.symm.image_mem_nhds (by simp [e]) exact pathComponentIn_mem_nhds <| e.image_mem_nhds (mem_chart_source _ _) ht · refine (isPathConnected_pathComponentIn <| mem_image_of_mem e (mem_of_mem_nhds ht)).image' ?_ refine e.continuousOn_symm.mono <| subset_trans ?_ e.map_source'' exact (pathComponentIn_mono <| image_mono inter_subset_right).trans pathComponentIn_subset · exact (image_mono pathComponentIn_subset).trans (PartialEquiv.symm_image_image_of_subset_source _ inter_subset_right).subset /-- If `M` is modelled on `H'` and `H'` is itself modelled on `H`, then we can consider `M` as being modelled on `H`. -/ def ChartedSpace.comp (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] (M : Type*) [TopologicalSpace M] [ChartedSpace H H'] [ChartedSpace H' M] : ChartedSpace H M where atlas := image2 PartialHomeomorph.trans (atlas H' M) (atlas H H') chartAt p := (chartAt H' p).trans (chartAt H (chartAt H' p p)) mem_chart_source p := by simp only [mfld_simps] chart_mem_atlas p := ⟨chartAt _ p, chart_mem_atlas _ p, chartAt _ _, chart_mem_atlas _ _, rfl⟩ theorem chartAt_comp (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] {M : Type*} [TopologicalSpace M] [ChartedSpace H H'] [ChartedSpace H' M] (x : M) : (letI := ChartedSpace.comp H H' M; chartAt H x) = chartAt H' x ≫ₕ chartAt H (chartAt H' x x) := rfl /-- A charted space over a T1 space is T1. Note that this is *not* true for T2 (for instance for the real line with a double origin). -/ theorem ChartedSpace.t1Space [T1Space H] : T1Space M := by apply t1Space_iff_exists_open.2 (fun x y hxy ↦ ?_) by_cases hy : y ∈ (chartAt H x).source · refine ⟨(chartAt H x).source ∩ (chartAt H x)⁻¹' ({chartAt H x y}ᶜ), ?_, ?_, by simp⟩ · exact PartialHomeomorph.isOpen_inter_preimage _ isOpen_compl_singleton · simp only [preimage_compl, mem_inter_iff, mem_chart_source, mem_compl_iff, mem_preimage, mem_singleton_iff, true_and] exact (chartAt H x).injOn.ne (ChartedSpace.mem_chart_source x) hy hxy · exact ⟨(chartAt H x).source, (chartAt H x).open_source, ChartedSpace.mem_chart_source x, hy⟩ /-- A charted space over a discrete space is discrete. -/ theorem ChartedSpace.discreteTopology [DiscreteTopology H] : DiscreteTopology M := by apply singletons_open_iff_discrete.1 (fun x ↦ ?_) have : IsOpen ((chartAt H x).source ∩ (chartAt H x) ⁻¹' {chartAt H x x}) := isOpen_inter_preimage _ (isOpen_discrete _) convert this refine Subset.antisymm (by simp) ?_ simp only [subset_singleton_iff, mem_inter_iff, mem_preimage, mem_singleton_iff, and_imp] intro y hy h'y exact (chartAt H x).injOn hy (mem_chart_source _ x) h'y end section Constructions /-- An empty type is a charted space over any topological space. -/ def ChartedSpace.empty (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [IsEmpty M] : ChartedSpace H M where atlas := ∅ chartAt x := (IsEmpty.false x).elim mem_chart_source x := (IsEmpty.false x).elim chart_mem_atlas x := (IsEmpty.false x).elim /-- Any space is a `ChartedSpace` modelled over itself, by just using the identity chart. -/ instance chartedSpaceSelf (H : Type*) [TopologicalSpace H] : ChartedSpace H H where atlas := {PartialHomeomorph.refl H} chartAt _ := PartialHomeomorph.refl H mem_chart_source x := mem_univ x chart_mem_atlas _ := mem_singleton _ /-- In the trivial `ChartedSpace` structure of a space modelled over itself through the identity, the atlas members are just the identity. -/ @[simp, mfld_simps] theorem chartedSpaceSelf_atlas {H : Type*} [TopologicalSpace H] {e : PartialHomeomorph H H} : e ∈ atlas H H ↔ e = PartialHomeomorph.refl H := Iff.rfl /-- In the model space, `chartAt` is always the identity. -/ theorem chartAt_self_eq {H : Type*} [TopologicalSpace H] {x : H} : chartAt H x = PartialHomeomorph.refl H := rfl /-- Any discrete space is a charted space over a singleton set. We keep this as a definition (not an instance) to avoid instance search trying to search for `DiscreteTopology` or `Unique` instances. -/ def ChartedSpace.of_discreteTopology [TopologicalSpace M] [TopologicalSpace H] [DiscreteTopology M] [h : Unique H] : ChartedSpace H M where atlas := letI f := fun x : M ↦ PartialHomeomorph.const (isOpen_discrete {x}) (isOpen_discrete {h.default}) Set.image f univ chartAt x := PartialHomeomorph.const (isOpen_discrete {x}) (isOpen_discrete {h.default}) mem_chart_source x := by simp chart_mem_atlas x := by simp /-- A chart on the discrete space is the constant chart. -/ @[simp, mfld_simps] lemma chartedSpace_of_discreteTopology_chartAt [TopologicalSpace M] [TopologicalSpace H] [DiscreteTopology M] [h : Unique H] {x : M} : haveI := ChartedSpace.of_discreteTopology (M := M) (H := H) chartAt H x = PartialHomeomorph.const (isOpen_discrete {x}) (isOpen_discrete {h.default}) := rfl section Products library_note "Manifold type tags" /-- For technical reasons we introduce two type tags: * `ModelProd H H'` is the same as `H × H'`; * `ModelPi H` is the same as `∀ i, H i`, where `H : ι → Type*` and `ι` is a finite type. In both cases the reason is the same, so we explain it only in the case of the product. A charted space `M` with model `H` is a set of charts from `M` to `H` covering the space. Every space is registered as a charted space over itself, using the only chart `id`, in `chartedSpaceSelf`. You can also define a product of charted space `M` and `M'` (with model space `H × H'`) by taking the products of the charts. Now, on `H × H'`, there are two charted space structures with model space `H × H'` itself, the one coming from `chartedSpaceSelf`, and the one coming from the product of the two `chartedSpaceSelf` on each component. They are equal, but not defeq (because the product of `id` and `id` is not defeq to `id`), which is bad as we know. This expedient of renaming `H × H'` solves this problem. -/ /-- Same thing as `H × H'`. We introduce it for technical reasons, see note [Manifold type tags]. -/ def ModelProd (H : Type*) (H' : Type*) := H × H' /-- Same thing as `∀ i, H i`. We introduce it for technical reasons, see note [Manifold type tags]. -/ def ModelPi {ι : Type*} (H : ι → Type*) := ∀ i, H i section -- attribute [local reducible] ModelProd -- Porting note: not available in Lean4 instance modelProdInhabited [Inhabited H] [Inhabited H'] : Inhabited (ModelProd H H') := instInhabitedProd instance (H : Type*) [TopologicalSpace H] (H' : Type*) [TopologicalSpace H'] : TopologicalSpace (ModelProd H H') := instTopologicalSpaceProd -- Next lemma shows up often when dealing with derivatives, so we register it as simp lemma. @[simp, mfld_simps] theorem modelProd_range_prod_id {H : Type*} {H' : Type*} {α : Type*} (f : H → α) : (range fun p : ModelProd H H' ↦ (f p.1, p.2)) = range f ×ˢ (univ : Set H') := by rw [prod_range_univ_eq] rfl end section variable {ι : Type*} {Hi : ι → Type*} instance modelPiInhabited [∀ i, Inhabited (Hi i)] : Inhabited (ModelPi Hi) := Pi.instInhabited instance [∀ i, TopologicalSpace (Hi i)] : TopologicalSpace (ModelPi Hi) := Pi.topologicalSpace end /-- The product of two charted spaces is naturally a charted space, with the canonical construction of the atlas of product maps. -/ instance prodChartedSpace (H : Type*) [TopologicalSpace H] (M : Type*) [TopologicalSpace M] [ChartedSpace H M] (H' : Type*) [TopologicalSpace H'] (M' : Type*) [TopologicalSpace M'] [ChartedSpace H' M'] : ChartedSpace (ModelProd H H') (M × M') where atlas := image2 PartialHomeomorph.prod (atlas H M) (atlas H' M') chartAt x := (chartAt H x.1).prod (chartAt H' x.2) mem_chart_source x := ⟨mem_chart_source H x.1, mem_chart_source H' x.2⟩ chart_mem_atlas x := mem_image2_of_mem (chart_mem_atlas H x.1) (chart_mem_atlas H' x.2) section prodChartedSpace @[ext] theorem ModelProd.ext {x y : ModelProd H H'} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := Prod.ext h₁ h₂ variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M'] {x : M × M'} @[simp, mfld_simps] theorem prodChartedSpace_chartAt : chartAt (ModelProd H H') x = (chartAt H x.fst).prod (chartAt H' x.snd) := rfl theorem chartedSpaceSelf_prod : prodChartedSpace H H H' H' = chartedSpaceSelf (H × H') := by ext1 · simp [prodChartedSpace, atlas, ChartedSpace.atlas] · ext1 simp only [prodChartedSpace_chartAt, chartAt_self_eq, refl_prod_refl] rfl end prodChartedSpace /-- The product of a finite family of charted spaces is naturally a charted space, with the canonical construction of the atlas of finite product maps. -/ instance piChartedSpace {ι : Type*} [Finite ι] (H : ι → Type*) [∀ i, TopologicalSpace (H i)] (M : ι → Type*) [∀ i, TopologicalSpace (M i)] [∀ i, ChartedSpace (H i) (M i)] : ChartedSpace (ModelPi H) (∀ i, M i) where atlas := PartialHomeomorph.pi '' Set.pi univ fun _ ↦ atlas (H _) (M _) chartAt f := PartialHomeomorph.pi fun i ↦ chartAt (H i) (f i) mem_chart_source f i _ := mem_chart_source (H i) (f i) chart_mem_atlas f := mem_image_of_mem _ fun i _ ↦ chart_mem_atlas (H i) (f i) @[simp, mfld_simps] theorem piChartedSpace_chartAt {ι : Type*} [Finite ι] (H : ι → Type*) [∀ i, TopologicalSpace (H i)] (M : ι → Type*) [∀ i, TopologicalSpace (M i)] [∀ i, ChartedSpace (H i) (M i)] (f : ∀ i, M i) : chartAt (H := ModelPi H) f = PartialHomeomorph.pi fun i ↦ chartAt (H i) (f i) := rfl end Products
section sum variable [TopologicalSpace H] [TopologicalSpace M] [TopologicalSpace M'] [cm : ChartedSpace H M] [cm' : ChartedSpace H M']
Mathlib/Geometry/Manifold/ChartedSpace.lean
898
902
/- Copyright (c) 2022 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.Bicategory.Functor.Prelax import Mathlib.Tactic.CategoryTheory.ToApp /-! # Oplax functors An oplax functor `F` between bicategories `B` and `C` consists of * a function between objects `F.obj : B ⟶ C`, * a family of functions between 1-morphisms `F.map : (a ⟶ b) → (F.obj a ⟶ F.obj b)`, * a family of functions between 2-morphisms `F.map₂ : (f ⟶ g) → (F.map f ⟶ F.map g)`, * a family of 2-morphisms `F.mapId a : F.map (𝟙 a) ⟶ 𝟙 (F.obj a)`, * a family of 2-morphisms `F.mapComp f g : F.map (f ≫ g) ⟶ F.map f ≫ F.map g`, and * certain consistency conditions on them. ## Main definitions * `CategoryTheory.OplaxFunctor B C` : an oplax functor between bicategories `B` and `C` * `CategoryTheory.OplaxFunctor.comp F G` : the composition of oplax functors -/ namespace CategoryTheory open Category Bicategory open Bicategory universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃ section variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C] variable {D : Type u₃} [Bicategory.{w₃, v₃} D] /-- An oplax functor `F` between bicategories `B` and `C` consists of a function between objects `F.obj`, a function between 1-morphisms `F.map`, and a function between 2-morphisms `F.map₂`. Unlike functors between categories, `F.map` do not need to strictly commute with the composition, and do not need to strictly preserve the identity. Instead, there are specified 2-morphisms `F.map (𝟙 a) ⟶ 𝟙 (F.obj a)` and `F.map (f ≫ g) ⟶ F.map f ≫ F.map g`. `F.map₂` strictly commute with compositions and preserve the identity. They also preserve the associator, the left unitor, and the right unitor modulo some adjustments of domains and codomains of 2-morphisms. -/ structure OplaxFunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂) [Bicategory.{w₂, v₂} C] extends PrelaxFunctor B C where /-- The 2-morphism underlying the oplax unity constraint. -/ mapId (a : B) : map (𝟙 a) ⟶ 𝟙 (obj a) /-- The 2-morphism underlying the oplax functoriality constraint. -/ mapComp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : map (f ≫ g) ⟶ map f ≫ map g /-- Naturality of the oplax functoriality constraint, on the left. -/ mapComp_naturality_left : ∀ {a b c : B} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c), map₂ (η ▷ g) ≫ mapComp f' g = mapComp f g ≫ map₂ η ▷ map g := by aesop_cat /-- Naturality of the lax functoriality constraight, on the right. -/ mapComp_naturality_right : ∀ {a b c : B} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g'), map₂ (f ◁ η) ≫ mapComp f g' = mapComp f g ≫ map f ◁ map₂ η := by aesop_cat /-- Oplax associativity. -/ map₂_associator : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d), map₂ (α_ f g h).hom ≫ mapComp f (g ≫ h) ≫ map f ◁ mapComp g h = mapComp (f ≫ g) h ≫ mapComp f g ▷ map h ≫ (α_ (map f) (map g) (map h)).hom := by aesop_cat /-- Oplax left unity. -/ map₂_leftUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (λ_ f).hom = mapComp (𝟙 a) f ≫ mapId a ▷ map f ≫ (λ_ (map f)).hom := by aesop_cat /-- Oplax right unity. -/ map₂_rightUnitor : ∀ {a b : B} (f : a ⟶ b), map₂ (ρ_ f).hom = mapComp f (𝟙 b) ≫ map f ◁ mapId b ≫ (ρ_ (map f)).hom := by aesop_cat initialize_simps_projections OplaxFunctor (+toPrelaxFunctor, -obj, -map, -map₂) namespace OplaxFunctor attribute [reassoc (attr := simp), to_app (attr := simp)] mapComp_naturality_left mapComp_naturality_right map₂_associator attribute [simp, reassoc, to_app] map₂_leftUnitor map₂_rightUnitor section /-- The underlying prelax functor. -/ add_decl_doc OplaxFunctor.toPrelaxFunctor variable (F : OplaxFunctor B C) @[reassoc, to_app] lemma mapComp_assoc_right {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.mapComp f (g ≫ h) ≫ F.map f ◁ F.mapComp g h = F.map₂ (α_ f g h).inv ≫ F.mapComp (f ≫ g) h ≫ F.mapComp f g ▷ F.map h ≫ (α_ (F.map f) (F.map g) (F.map h)).hom := by rw [← F.map₂_associator, ← F.map₂_comp_assoc] simp @[reassoc, to_app] lemma mapComp_assoc_left {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : F.mapComp (f ≫ g) h ≫ F.mapComp f g ▷ F.map h = F.map₂ (α_ f g h).hom ≫ F.mapComp f (g ≫ h) ≫ F.map f ◁ F.mapComp g h ≫ (α_ (F.map f) (F.map g) (F.map h)).inv := by simp /-- The identity oplax functor. -/ @[simps] def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : OplaxFunctor B B where toPrelaxFunctor := PrelaxFunctor.id B mapId := fun a => 𝟙 (𝟙 a) mapComp := fun f g => 𝟙 (f ≫ g) instance : Inhabited (OplaxFunctor B B) := ⟨id B⟩ /-- Composition of oplax functors. -/ --@[simps] def comp (F : OplaxFunctor B C) (G : OplaxFunctor C D) : OplaxFunctor B D where toPrelaxFunctor := F.toPrelaxFunctor.comp G.toPrelaxFunctor mapId := fun a => (G.mapFunctor _ _).map (F.mapId a) ≫ G.mapId (F.obj a) mapComp := fun f g => (G.mapFunctor _ _).map (F.mapComp f g) ≫ G.mapComp (F.map f) (F.map g) mapComp_naturality_left := fun η g => by dsimp rw [← G.map₂_comp_assoc, mapComp_naturality_left, G.map₂_comp_assoc, mapComp_naturality_left, assoc] mapComp_naturality_right := fun η => by dsimp intros rw [← G.map₂_comp_assoc, mapComp_naturality_right, G.map₂_comp_assoc, mapComp_naturality_right, assoc] map₂_associator := fun f g h => by dsimp simp only [map₂_associator, ← PrelaxFunctor.map₂_comp_assoc, ← mapComp_naturality_right_assoc, Bicategory.whiskerLeft_comp, assoc] simp only [map₂_associator, PrelaxFunctor.map₂_comp, mapComp_naturality_left_assoc, comp_whiskerRight, assoc] map₂_leftUnitor := fun f => by dsimp simp only [map₂_leftUnitor, PrelaxFunctor.map₂_comp, mapComp_naturality_left_assoc, comp_whiskerRight, assoc] map₂_rightUnitor := fun f => by dsimp simp only [map₂_rightUnitor, PrelaxFunctor.map₂_comp, mapComp_naturality_right_assoc, Bicategory.whiskerLeft_comp, assoc] /-- A structure on an oplax functor that promotes an oplax functor to a pseudofunctor. See `Pseudofunctor.mkOfOplax`. -/ structure PseudoCore (F : OplaxFunctor B C) where /-- The isomorphism giving rise to the oplax unity constraint -/ mapIdIso (a : B) : F.map (𝟙 a) ≅ 𝟙 (F.obj a) /-- The isomorphism giving rise to the oplax functoriality constraint -/ mapCompIso {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : F.map (f ≫ g) ≅ F.map f ≫ F.map g /-- `mapIdIso` gives rise to the oplax unity constraint -/ mapIdIso_hom : ∀ {a : B}, (mapIdIso a).hom = F.mapId a := by aesop_cat /-- `mapCompIso` gives rise to the oplax functoriality constraint -/ mapCompIso_hom : ∀ {a b c : B} (f : a ⟶ b) (g : b ⟶ c), (mapCompIso f g).hom = F.mapComp f g := by aesop_cat attribute [simp] PseudoCore.mapIdIso_hom PseudoCore.mapCompIso_hom end end OplaxFunctor end end CategoryTheory
Mathlib/CategoryTheory/Bicategory/Functor/Oplax.lean
245
248
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Calculus.SmoothSeries import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation import Mathlib.Data.Complex.FiniteDimensional /-! # The two-variable Jacobi theta function This file defines the two-variable Jacobi theta function $$\theta(z, \tau) = \sum_{n \in \mathbb{Z}} \exp (2 i \pi n z + i \pi n ^ 2 \tau),$$ and proves the functional equation relating the values at `(z, τ)` and `(z / τ, -1 / τ)`, using Poisson's summation formula. We also show holomorphy (jointly in both variables). Additionally, we show some analogous results about the derivative (in the `z`-variable) $$\theta'(z, τ) = \sum_{n \in \mathbb{Z}} 2 \pi i n \exp (2 i \pi n z + i \pi n ^ 2 \tau).$$ (Note that the Mellin transform of `θ` will give us functional equations for `L`-functions of even Dirichlet characters, and that of `θ'` will do the same for odd Dirichlet characters.) -/ open Complex Real Asymptotics Filter Topology open scoped ComplexConjugate noncomputable section section term_defs /-! ## Definitions of the summands -/ /-- Summand in the series for the Jacobi theta function. -/ def jacobiTheta₂_term (n : ℤ) (z τ : ℂ) : ℂ := cexp (2 * π * I * n * z + π * I * n ^ 2 * τ) /-- Summand in the series for the Fréchet derivative of the Jacobi theta function. -/ def jacobiTheta₂_term_fderiv (n : ℤ) (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ := cexp (2 * π * I * n * z + π * I * n ^ 2 * τ) • ((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ) + (π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ)) lemma hasFDerivAt_jacobiTheta₂_term (n : ℤ) (z τ : ℂ) : HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂_term n p.1 p.2) (jacobiTheta₂_term_fderiv n z τ) (z, τ) := by let f : ℂ × ℂ → ℂ := fun p ↦ 2 * π * I * n * p.1 + π * I * n ^ 2 * p.2 suffices HasFDerivAt f ((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ) + (π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ)) (z, τ) from this.cexp exact (hasFDerivAt_fst.const_mul _).add (hasFDerivAt_snd.const_mul _) /-- Summand in the series for the `z`-derivative of the Jacobi theta function. -/ def jacobiTheta₂'_term (n : ℤ) (z τ : ℂ) := 2 * π * I * n * jacobiTheta₂_term n z τ end term_defs section term_bounds /-! ## Bounds for the summands We show that the sums of the three functions `jacobiTheta₂_term`, `jacobiTheta₂'_term` and `jacobiTheta₂_term_fderiv` are locally uniformly convergent in the domain `0 < im τ`, and diverge everywhere else. -/ lemma norm_jacobiTheta₂_term (n : ℤ) (z τ : ℂ) : ‖jacobiTheta₂_term n z τ‖ = rexp (-π * n ^ 2 * τ.im - 2 * π * n * z.im) := by rw [jacobiTheta₂_term, Complex.norm_exp, (by push_cast; ring : (2 * π : ℂ) * I * n * z + π * I * n ^ 2 * τ = (π * (2 * n):) * z * I + (π * n ^ 2 :) * τ * I), add_re, mul_I_re, im_ofReal_mul, mul_I_re, im_ofReal_mul] ring_nf /-- A uniform upper bound for `jacobiTheta₂_term` on compact subsets. -/ lemma norm_jacobiTheta₂_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ} (hz : |im z| ≤ S) (hτ : T ≤ im τ) (n : ℤ) : ‖jacobiTheta₂_term n z τ‖ ≤ rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by simp_rw [norm_jacobiTheta₂_term, Real.exp_le_exp, sub_eq_add_neg, neg_mul, ← neg_add, neg_le_neg_iff, mul_comm (2 : ℝ), mul_assoc π, ← mul_add, mul_le_mul_left pi_pos, mul_comm T, mul_comm S] refine add_le_add (mul_le_mul le_rfl hτ hT.le (sq_nonneg _)) ?_ rw [← mul_neg, mul_assoc, mul_assoc, mul_le_mul_left two_pos, mul_comm, neg_mul, ← mul_neg] refine le_trans ?_ (neg_abs_le _) rw [mul_neg, neg_le_neg_iff, abs_mul, Int.cast_abs] exact mul_le_mul_of_nonneg_left hz (abs_nonneg _) /-- A uniform upper bound for `jacobiTheta₂'_term` on compact subsets. -/ lemma norm_jacobiTheta₂'_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ} (hz : |im z| ≤ S) (hτ : T ≤ im τ) (n : ℤ) : ‖jacobiTheta₂'_term n z τ‖ ≤ 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by rw [jacobiTheta₂'_term, norm_mul] refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hT hz hτ n) (norm_nonneg _) (by positivity) simp only [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le, norm_intCast, mul_one, Int.cast_abs] /-- The uniform bound we have given is summable, and remains so after multiplying by any fixed power of `|n|` (we shall need this for `k = 0, 1, 2`). -/ lemma summable_pow_mul_jacobiTheta₂_term_bound (S : ℝ) {T : ℝ} (hT : 0 < T) (k : ℕ) : Summable (fun n : ℤ ↦ (|n| ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|))) := by suffices Summable (fun n : ℕ ↦ (n ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * n))) by apply Summable.of_nat_of_neg <;> simpa only [Int.cast_neg, neg_sq, abs_neg, Int.cast_natCast, Nat.abs_cast] apply summable_of_isBigO_nat (summable_pow_mul_exp_neg_nat_mul k zero_lt_one) apply IsBigO.mul (isBigO_refl _ _) refine Real.isBigO_exp_comp_exp_comp.mpr (Tendsto.isBoundedUnder_le_atBot ?_) simp_rw [← tendsto_neg_atTop_iff, Pi.sub_apply] conv => enter [1, n] rw [show -(-π * (T * n ^ 2 - 2 * S * n) - -1 * n) = n * (π * T * n - (2 * π * S + 1)) by ring] refine tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ (tendsto_atTop_add_const_right _ _ ?_) exact tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos pi_pos hT) /-- The series defining the theta function is summable if and only if `0 < im τ`. -/ lemma summable_jacobiTheta₂_term_iff (z τ : ℂ) : Summable (jacobiTheta₂_term · z τ) ↔ 0 < im τ := by -- NB. This is a statement of no great mathematical interest; it is included largely to avoid -- having to impose `0 < im τ` as a hypothesis on many later lemmas. refine Iff.symm ⟨fun hτ ↦ ?_, fun h ↦ ?_⟩ -- do quicker implication first! · refine (summable_pow_mul_jacobiTheta₂_term_bound |im z| hτ 0).of_norm_bounded _ ?_ simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hτ le_rfl le_rfl · by_contra! hτ rcases lt_or_eq_of_le hτ with hτ | hτ · -- easy case `im τ < 0` suffices Tendsto (fun n : ℕ ↦ ‖jacobiTheta₂_term ↑n z τ‖) atTop atTop by replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero.norm exact atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop _) this) simp only [norm_zero, Function.comp_def, norm_jacobiTheta₂_term, Int.cast_natCast] conv => enter [1, n] rw [show -π * n ^ 2 * τ.im - 2 * π * n * z.im = n * (n * (-π * τ.im) - 2 * π * z.im) by ring] refine tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ ?_) exact tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.atTop_mul_const (mul_pos_of_neg_of_neg (neg_lt_zero.mpr pi_pos) hτ)) · -- case im τ = 0: 3-way split according to `im z` simp_rw [← summable_norm_iff (E := ℂ), norm_jacobiTheta₂_term, hτ, mul_zero, zero_sub] at h rcases lt_trichotomy (im z) 0 with hz | hz | hz · replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero simp_rw [Function.comp_def, Int.cast_natCast] at h refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_) refine tendsto_exp_atTop.comp ?_ simp only [tendsto_neg_atTop_iff, mul_assoc] apply Filter.Tendsto.const_mul_atBot two_pos exact (tendsto_natCast_atTop_atTop.atTop_mul_const_of_neg hz).const_mul_atBot pi_pos · revert h simpa only [hz, mul_zero, neg_zero, Real.exp_zero, summable_const_iff] using one_ne_zero · have : ((-↑·) : ℕ → ℤ).Injective := fun _ _ ↦ by simp only [neg_inj, Nat.cast_inj, imp_self] replace h := (h.comp_injective this).tendsto_atTop_zero simp_rw [Function.comp_def, Int.cast_neg, Int.cast_natCast, mul_neg, neg_mul, neg_neg] at h refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_) exact tendsto_exp_atTop.comp ((tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos two_pos pi_pos)).atTop_mul_const hz) lemma norm_jacobiTheta₂_term_fderiv_le (n : ℤ) (z τ : ℂ) : ‖jacobiTheta₂_term_fderiv n z τ‖ ≤ 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ := by -- this is slow to elaborate so do it once and reuse: have hns (a : ℂ) (f : (ℂ × ℂ) →L[ℂ] ℂ) : ‖a • f‖ = ‖a‖ * ‖f‖ := norm_smul a f rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, hns, mul_comm _ ‖cexp _‖, (by norm_num : (3 : ℝ) = 2 + 1), add_mul, add_mul] refine mul_le_mul_of_nonneg_left ((norm_add_le _ _).trans (add_le_add ?_ ?_)) (norm_nonneg _) · simp_rw [hns, norm_mul, ← ofReal_ofNat, ← ofReal_intCast, norm_real, norm_of_nonneg zero_le_two, Real.norm_of_nonneg pi_pos.le, norm_I, mul_one, Real.norm_eq_abs, Int.cast_abs, mul_assoc] refine mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left ?_ pi_pos.le) two_pos.le refine le_trans ?_ (?_ : |(n : ℝ)| ≤ |(n : ℝ)| ^ 2) · exact mul_le_of_le_one_right (abs_nonneg _) (ContinuousLinearMap.norm_fst_le ..) · exact_mod_cast Int.le_self_sq |n| · simp_rw [hns, norm_mul, one_mul, norm_I, mul_one, norm_real, norm_of_nonneg pi_pos.le, ← ofReal_intCast, ← ofReal_pow, norm_real, Real.norm_eq_abs, Int.cast_abs, abs_pow] apply mul_le_of_le_one_right (mul_nonneg pi_pos.le (pow_nonneg (abs_nonneg _) _)) exact ContinuousLinearMap.norm_snd_le .. lemma norm_jacobiTheta₂_term_fderiv_ge (n : ℤ) (z τ : ℂ) : π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by have : ‖(jacobiTheta₂_term_fderiv n z τ) (0, 1)‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by refine (ContinuousLinearMap.le_opNorm _ _).trans ?_ simp_rw [Prod.norm_def, norm_one, norm_zero, max_eq_right zero_le_one, mul_one, le_refl] refine le_trans ?_ this simp_rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, ContinuousLinearMap.coe_smul', Pi.smul_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Pi.smul_apply, smul_zero, zero_add, smul_eq_mul, mul_one, mul_comm _ ‖cexp _‖, norm_mul] refine mul_le_mul_of_nonneg_left (le_of_eq ?_) (norm_nonneg _) simp_rw [norm_real, norm_of_nonneg pi_pos.le, norm_I, mul_one, Int.cast_abs, ← norm_intCast, norm_pow] lemma summable_jacobiTheta₂_term_fderiv_iff (z τ : ℂ) : Summable (jacobiTheta₂_term_fderiv · z τ) ↔ 0 < im τ := by constructor · rw [← summable_jacobiTheta₂_term_iff (z := z)] intro h have := h.norm refine this.of_norm_bounded_eventually _ ?_ have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 := Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩) filter_upwards [this] with n hn refine le_trans ?_ (norm_jacobiTheta₂_term_fderiv_ge n z τ) apply le_mul_of_one_le_left (norm_nonneg _) refine one_le_pi_div_two.trans (mul_le_mul_of_nonneg_left ?_ pi_pos.le) refine (by norm_num : 2⁻¹ ≤ (1 : ℝ)).trans ?_ rw [one_le_sq_iff_one_le_abs, ← Int.cast_abs, abs_abs, ← Int.cast_one, Int.cast_le] exact Int.one_le_abs hn · intro hτ refine ((summable_pow_mul_jacobiTheta₂_term_bound |z.im| hτ 2).mul_left (3 * π)).of_norm_bounded _ (fun n ↦ ?_) refine (norm_jacobiTheta₂_term_fderiv_le n z τ).trans (?_ : 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ _) simp_rw [mul_assoc (3 * π)] refine mul_le_mul_of_nonneg_left ?_ (mul_pos (by norm_num : 0 < (3 : ℝ)) pi_pos).le refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg.mpr (abs_nonneg _)) _) exact norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n lemma summable_jacobiTheta₂'_term_iff (z τ : ℂ) : Summable (jacobiTheta₂'_term · z τ) ↔ 0 < im τ := by constructor · rw [← summable_jacobiTheta₂_term_iff (z := z)] refine fun h ↦ (h.norm.mul_left (2 * π)⁻¹).of_norm_bounded_eventually _ ?_ have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 := Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩) filter_upwards [this] with n hn rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc] refine le_mul_of_one_le_left (norm_nonneg _) ?_ simp_rw [norm_mul, norm_I, norm_real, mul_one, norm_of_nonneg pi_pos.le, ← ofReal_ofNat, norm_real, norm_of_nonneg two_pos.le, ← ofReal_intCast, norm_real, Real.norm_eq_abs, ← Int.cast_abs, ← mul_assoc _ (2 * π), inv_mul_cancel₀ (mul_pos two_pos pi_pos).ne', one_mul] rw [← Int.cast_one, Int.cast_le] exact Int.one_le_abs hn · refine fun hτ ↦ ((summable_pow_mul_jacobiTheta₂_term_bound |z.im| hτ 1).mul_left (2 * π)).of_norm_bounded _ (fun n ↦ ?_) rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc, pow_one] refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n) (norm_nonneg _) (by positivity) simp_rw [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le, norm_intCast, mul_one, Int.cast_abs] end term_bounds /-! ## Definitions of the functions -/ /-- The two-variable Jacobi theta function, `θ z τ = ∑' (n : ℤ), cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`. -/ def jacobiTheta₂ (z τ : ℂ) : ℂ := ∑' n : ℤ, jacobiTheta₂_term n z τ /-- Fréchet derivative of the two-variable Jacobi theta function. -/ def jacobiTheta₂_fderiv (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ := ∑' n : ℤ, jacobiTheta₂_term_fderiv n z τ /-- The `z`-derivative of the Jacobi theta function, `θ' z τ = ∑' (n : ℤ), 2 * π * I * n * cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`. -/ def jacobiTheta₂' (z τ : ℂ) := ∑' n : ℤ, jacobiTheta₂'_term n z τ lemma hasSum_jacobiTheta₂_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasSum (fun n ↦ jacobiTheta₂_term n z τ) (jacobiTheta₂ z τ) := ((summable_jacobiTheta₂_term_iff z τ).mpr hτ).hasSum lemma hasSum_jacobiTheta₂_term_fderiv (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasSum (fun n ↦ jacobiTheta₂_term_fderiv n z τ) (jacobiTheta₂_fderiv z τ) := ((summable_jacobiTheta₂_term_fderiv_iff z τ).mpr hτ).hasSum lemma hasSum_jacobiTheta₂'_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasSum (fun n ↦ jacobiTheta₂'_term n z τ) (jacobiTheta₂' z τ) := ((summable_jacobiTheta₂'_term_iff z τ).mpr hτ).hasSum lemma jacobiTheta₂_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂ z τ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiTheta₂_term_iff] exact not_lt.mpr hτ lemma jacobiTheta₂_fderiv_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂_fderiv z τ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiTheta₂_term_fderiv_iff] exact not_lt.mpr hτ lemma jacobiTheta₂'_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂' z τ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiTheta₂'_term_iff] exact not_lt.mpr hτ /-! ## Derivatives and continuity -/ lemma hasFDerivAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (jacobiTheta₂_fderiv z τ) (z, τ) := by obtain ⟨T, hT, hτ'⟩ := exists_between hτ obtain ⟨S, hz⟩ := exists_gt |im z| let V := {u | |im u| < S} ×ˢ {v | T < im v} have hVo : IsOpen V := by refine ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod ?_ exact continuous_im.isOpen_preimage _ isOpen_Ioi have hVmem : (z, τ) ∈ V := ⟨hz, hτ'⟩ have hVp : IsPreconnected V := by refine (Convex.isPreconnected ?_).prod (convex_halfSpace_im_gt T).isPreconnected simpa only [abs_lt] using (convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _) let f : ℤ → ℂ × ℂ → ℂ := fun n p ↦ jacobiTheta₂_term n p.1 p.2 let f' : ℤ → ℂ × ℂ → ℂ × ℂ →L[ℂ] ℂ := fun n p ↦ jacobiTheta₂_term_fderiv n p.1 p.2 have hf (n : ℤ) : ∀ p ∈ V, HasFDerivAt (f n) (f' n p) p := fun p _ ↦ hasFDerivAt_jacobiTheta₂_term n p.1 p.2 let u : ℤ → ℝ := fun n ↦ 3 * π * |n| ^ 2 * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|)) have hu : ∀ (n : ℤ), ∀ x ∈ V, ‖f' n x‖ ≤ u n := by refine fun n p hp ↦ (norm_jacobiTheta₂_term_fderiv_le n p.1 p.2).trans ?_ refine mul_le_mul_of_nonneg_left ?_ (by positivity) exact norm_jacobiTheta₂_term_le hT (le_of_lt hp.1) (le_of_lt hp.2) n have hu_sum : Summable u := by simp_rw [u, mul_assoc (3 * π)] exact (summable_pow_mul_jacobiTheta₂_term_bound S hT 2).mul_left _ have hf_sum : Summable fun n : ℤ ↦ f n (z, τ) := by refine (summable_pow_mul_jacobiTheta₂_term_bound S hT 0).of_norm_bounded _ ?_ simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hT hz.le hτ'.le simpa only [jacobiTheta₂, jacobiTheta₂_fderiv, f, f'] using hasFDerivAt_tsum_of_isPreconnected hu_sum hVo hVp hf hu hVmem hf_sum hVmem lemma continuousAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (z, τ) := (hasFDerivAt_jacobiTheta₂ z hτ).continuousAt /-- Differentiability of `Θ z τ` in `z`, for fixed `τ`. -/ lemma differentiableAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : DifferentiableAt ℂ (jacobiTheta₂ · τ) z := ((hasFDerivAt_jacobiTheta₂ z hτ).comp (𝕜 := ℂ) z (hasFDerivAt_prodMk_left z τ) :).differentiableAt /-- Differentiability of `Θ z τ` in `τ`, for fixed `z`. -/ lemma differentiableAt_jacobiTheta₂_snd (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : DifferentiableAt ℂ (jacobiTheta₂ z) τ := ((hasFDerivAt_jacobiTheta₂ z hτ).comp τ (hasFDerivAt_prodMk_right z τ)).differentiableAt lemma hasDerivAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasDerivAt (jacobiTheta₂ · τ) (jacobiTheta₂' z τ) z := by -- This proof is annoyingly fiddly, because of the need to commute "evaluation at a point" -- through infinite sums of continuous linear maps. let eval_fst_CLM : (ℂ × ℂ →L[ℂ] ℂ) →L[ℂ] ℂ := { toFun := fun f ↦ f (1, 0) cont := continuous_id'.clm_apply continuous_const map_add' := by simp only [ContinuousLinearMap.add_apply, forall_const] map_smul' := by simp only [ContinuousLinearMap.coe_smul', Pi.smul_apply, smul_eq_mul, RingHom.id_apply, forall_const] } have step1 : HasSum (fun n ↦ (jacobiTheta₂_term_fderiv n z τ) (1, 0)) ((jacobiTheta₂_fderiv z τ) (1, 0)) := by apply eval_fst_CLM.hasSum (hasSum_jacobiTheta₂_term_fderiv z hτ) have step2 (n : ℤ) : (jacobiTheta₂_term_fderiv n z τ) (1, 0) = jacobiTheta₂'_term n z τ := by simp only [jacobiTheta₂_term_fderiv, smul_add, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', Pi.smul_apply, smul_eq_mul, mul_one, ContinuousLinearMap.coe_snd', mul_zero, add_zero, jacobiTheta₂'_term, jacobiTheta₂_term, mul_comm _ (cexp _)] rw [funext step2] at step1 #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 need `by exact` to bypass unification failure -/ have step3 : HasDerivAt (fun x ↦ jacobiTheta₂ x τ) ((jacobiTheta₂_fderiv z τ) (1, 0)) z := by exact ((hasFDerivAt_jacobiTheta₂ z hτ).comp z (hasFDerivAt_prodMk_left z τ)).hasDerivAt rwa [← step1.tsum_eq] at step3 lemma continuousAt_jacobiTheta₂' (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂' p.1 p.2) (z, τ) := by obtain ⟨T, hT, hτ'⟩ := exists_between hτ obtain ⟨S, hz⟩ := exists_gt |im z| let V := {u | |im u| < S} ×ˢ {v | T < im v} have hVo : IsOpen V := ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod (continuous_im.isOpen_preimage _ isOpen_Ioi) refine ContinuousOn.continuousAt ?_ (hVo.mem_nhds ⟨hz, hτ'⟩) let u (n : ℤ) : ℝ := 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|)) have hu : Summable u := by simpa only [u, mul_assoc, pow_one] using (summable_pow_mul_jacobiTheta₂_term_bound S hT 1).mul_left (2 * π) refine continuousOn_tsum (fun n ↦ ?_) hu (fun n ⟨z', τ'⟩ ⟨hz', hτ'⟩ ↦ ?_) · apply Continuous.continuousOn unfold jacobiTheta₂'_term jacobiTheta₂_term fun_prop · exact norm_jacobiTheta₂'_term_le hT (le_of_lt hz') (le_of_lt hτ') n /-! ## Periodicity and conjugation -/ /-- The two-variable Jacobi theta function is periodic in `τ` with period 2. -/ lemma jacobiTheta₂_add_right (z τ : ℂ) : jacobiTheta₂ z (τ + 2) = jacobiTheta₂ z τ := by refine tsum_congr (fun n ↦ ?_) simp_rw [jacobiTheta₂_term, Complex.exp_add] suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one]
rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul, exp_two_pi_mul_I, one_zpow] /-- The two-variable Jacobi theta function is periodic in `z` with period 1. -/ lemma jacobiTheta₂_add_left (z τ : ℂ) : jacobiTheta₂ (z + 1) τ = jacobiTheta₂ z τ := by
Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean
387
391
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.ProbabilityMeasure import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Layercake import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction /-! # Characterizations of weak convergence of finite measures and probability measures This file will provide portmanteau characterizations of the weak convergence of finite measures and of probability measures, i.e., the standard characterizations of convergence in distribution. ## Main definitions The topologies of weak convergence on the types of finite measures and probability measures are already defined in their corresponding files; no substantial new definitions are introduced here. ## Main results The main result will be the portmanteau theorem providing various characterizations of the weak convergence of measures (probability measures or finite measures). Given measures μs and μ on a topological space Ω, the conditions that will be proven equivalent (under quite general hypotheses) are: (T) The measures μs tend to the measure μ weakly. (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). The separate implications are: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` is the implication (T) → (C). * `MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge` is the equivalence (C) ↔ (O). * `MeasureTheory.tendsto_measure_of_null_frontier` is the implication (O) → (B). * `MeasureTheory.limsup_measure_closed_le_of_forall_tendsto_measure` is the implication (B) → (C). * `MeasureTheory.tendsto_of_forall_isOpen_le_liminf` gives the implication (O) → (T) for any sequence of Borel probability measures. ## Implementation notes Many of the characterizations of weak convergence hold for finite measures and are proven in that generality and then specialized to probability measures. Some implications hold with slightly more general assumptions than in the usual statement of portmanteau theorem. The full portmanteau theorem, however, is most convenient for probability measures on pseudo-emetrizable spaces with their Borel sigma algebras. Some specific considerations on the assumptions in the different implications: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto`, i.e., implication (T) → (C), assumes that in the underlying topological space, indicator functions of closed sets have decreasing bounded continuous pointwise approximating sequences. The assumption is in the form of the type class `HasOuterApproxClosed`. Type class inference knows that for example the more common assumptions of metrizability or pseudo-emetrizability suffice. * Where formulations are currently only provided for probability measures, one can obtain the finite measure formulations using the characterization of convergence of finite measures by their total masses and their probability-normalized versions, i.e., by `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, convergence in distribution, convergence in law, finite measure, probability measure -/ noncomputable section open MeasureTheory Set Filter BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section LimsupClosedLEAndLELiminfOpen /-! ### Portmanteau: limsup condition for closed sets iff liminf condition for open sets In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, the following two conditions are equivalent: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). Either of these will later be shown to be equivalent to the weak convergence of the sequence of measures. -/ variable {Ω : Type*} [MeasurableSpace Ω] theorem le_measure_compl_liminf_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i ↦ μs i E) ≤ μ E) : μ Eᶜ ≤ L.liminf fun i ↦ μs i Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [liminf_bot, le_top] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] rw [show (L.liminf fun i : ι ↦ 1 - μs i E) = L.liminf ((fun x ↦ 1 - x) ∘ fun i : ι ↦ μs i E) from rfl] have key := antitone_const_tsub.map_limsup_of_continuousAt (F := L) (fun i ↦ μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simpa [← key] using antitone_const_tsub h theorem le_measure_liminf_of_limsup_measure_compl_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i ↦ μs i Eᶜ) ≤ μ Eᶜ) : μ E ≤ L.liminf fun i ↦ μs i E := compl_compl E ▸ le_measure_compl_liminf_of_limsup_measure_le (MeasurableSet.compl E_mble) h theorem limsup_measure_compl_le_of_le_liminf_measure {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ E ≤ L.liminf fun i ↦ μs i E) : (L.limsup fun i ↦ μs i Eᶜ) ≤ μ Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] rw [show (L.limsup fun i : ι ↦ 1 - μs i E) = L.limsup ((fun x ↦ 1 - x) ∘ fun i : ι ↦ μs i E) from rfl] have key := antitone_const_tsub.map_liminf_of_continuousAt (F := L) (fun i ↦ μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simpa [← key] using antitone_const_tsub h theorem limsup_measure_le_of_le_liminf_measure_compl {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ Eᶜ ≤ L.liminf fun i ↦ μs i Eᶜ) : (L.limsup fun i ↦ μs i E) ≤ μ E := compl_compl E ▸ limsup_measure_compl_le_of_le_liminf_measure (MeasurableSet.compl E_mble) h variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One pair of implications of the portmanteau theorem: For a sequence of Borel probability measures, the following two are equivalent: (C) The limsup of the measures of any closed set is at most the measure of the closed set under a candidate limit measure. (O) The liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure. -/ theorem limsup_measure_closed_le_iff_liminf_measure_open_ge {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] : (∀ F, IsClosed F → (L.limsup fun i ↦ μs i F) ≤ μ F) ↔ ∀ G, IsOpen G → μ G ≤ L.liminf fun i ↦ μs i G := by constructor · intro h G G_open exact le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h Gᶜ (isClosed_compl_iff.mpr G_open)) · intro h F F_closed exact limsup_measure_le_of_le_liminf_measure_compl F_closed.measurableSet (h Fᶜ (isOpen_compl_iff.mpr F_closed)) end LimsupClosedLEAndLELiminfOpen -- section section TendstoOfNullFrontier /-! ### Portmanteau: limit of measures of Borel sets whose boundary carries no mass in the limit In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, either of the following equivalent conditions: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). implies that (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ variable {Ω : Type*} [MeasurableSpace Ω] theorem tendsto_measure_of_le_liminf_measure_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} {E₀ E E₁ : Set Ω} (E₀_subset : E₀ ⊆ E) (subset_E₁ : E ⊆ E₁) (nulldiff : μ (E₁ \ E₀) = 0) (h_E₀ : μ E₀ ≤ L.liminf fun i ↦ μs i E₀) (h_E₁ : (L.limsup fun i ↦ μs i E₁) ≤ μ E₁) : L.Tendsto (fun i ↦ μs i E) (𝓝 (μ E)) := by apply tendsto_of_le_liminf_of_limsup_le · have E₀_ae_eq_E : E₀ =ᵐ[μ] E := EventuallyLE.antisymm E₀_subset.eventuallyLE (subset_E₁.eventuallyLE.trans (ae_le_set.mpr nulldiff)) calc μ E = μ E₀ := measure_congr E₀_ae_eq_E.symm _ ≤ L.liminf fun i ↦ μs i E₀ := h_E₀ _ ≤ L.liminf fun i ↦ μs i E := liminf_le_liminf (.of_forall fun _ ↦ measure_mono E₀_subset) · have E_ae_eq_E₁ : E =ᵐ[μ] E₁ := EventuallyLE.antisymm subset_E₁.eventuallyLE ((ae_le_set.mpr nulldiff).trans E₀_subset.eventuallyLE) calc (L.limsup fun i ↦ μs i E) ≤ L.limsup fun i ↦ μs i E₁ := limsup_le_limsup (.of_forall fun _ ↦ measure_mono subset_E₁) _ ≤ μ E₁ := h_E₁ _ = μ E := measure_congr E_ae_eq_E₁.symm · infer_param · infer_param variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One implication of the portmanteau theorem: For a sequence of Borel probability measures, if the liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure, then for any set whose boundary carries no probability mass under the candidate limit measure, then its measures under the sequence converge to its measure under the candidate limit measure. -/ theorem tendsto_measure_of_null_frontier {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] (h_opens : ∀ G, IsOpen G → μ G ≤ L.liminf fun i ↦ μs i G) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : L.Tendsto (fun i ↦ μs i E) (𝓝 (μ E)) := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ μs i F) ≤ μ F := limsup_measure_closed_le_iff_liminf_measure_open_ge.mpr h_opens tendsto_measure_of_le_liminf_measure_of_limsup_measure_le interior_subset subset_closure E_nullbdry (h_opens _ isOpen_interior) (h_closeds _ isClosed_closure) end TendstoOfNullFrontier --section section ConvergenceImpliesLimsupClosedLE /-! ### Portmanteau implication: weak convergence implies a limsup condition for closed sets In this section we prove, under the assumption that the underlying topological space `Ω` is pseudo-emetrizable, that (T) The measures μs tend to the measure μ weakly implies (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). Combining with a earlier proven implications, we get that (T) implies also both (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G); (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ /-- One implication of the portmanteau theorem: Weak convergence of finite measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit measure. -/ theorem FiniteMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [OpensMeasurableSpace Ω] {μ : FiniteMeasure Ω} {μs : ι → FiniteMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] apply ENNReal.le_of_forall_pos_le_add intro ε ε_pos _ have ε_pos' := (ENNReal.half_pos (ENNReal.coe_ne_zero.mpr ε_pos.ne.symm)).ne.symm let fs := F_closed.apprSeq have key₁ : Tendsto (fun n ↦ ∫⁻ ω, (fs n ω : ℝ≥0∞) ∂μ) atTop (𝓝 ((μ : Measure Ω) F)) := HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed (μ : Measure Ω) have room₁ : (μ : Measure Ω) F < (μ : Measure Ω) F + ε / 2 := ENNReal.lt_add_right (measure_lt_top (μ : Measure Ω) F).ne ε_pos' obtain ⟨M, hM⟩ := eventually_atTop.mp <| key₁.eventually_lt_const room₁ have key₂ := FiniteMeasure.tendsto_iff_forall_lintegral_tendsto.mp μs_lim (fs M) have room₂ : (lintegral (μ : Measure Ω) fun a ↦ fs M a) < (lintegral (μ : Measure Ω) fun a ↦ fs M a) + ε / 2 := ENNReal.lt_add_right (ne_of_lt ((fs M).lintegral_lt_top_of_nnreal _)) ε_pos' have ev_near := key₂.eventually_le_const room₂ have ev_near' := ev_near.mono (fun n ↦ le_trans (HasOuterApproxClosed.measure_le_lintegral F_closed (μs n) M)) apply (Filter.limsup_le_limsup ev_near').trans rw [limsup_const] apply le_trans (add_le_add (hM M rfl.le).le (le_refl (ε / 2 : ℝ≥0∞))) simp only [add_assoc, ENNReal.add_halves, le_refl] /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit probability measure. -/ theorem ProbabilityMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by apply FiniteMeasure.limsup_measure_closed_le_of_tendsto ((tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds L).mp μs_lim) F_closed /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the liminf of the measures of any open set is at least the measure of the open set under the limit probability measure. -/ theorem ProbabilityMeasure.le_liminf_measure_open_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {G : Set Ω} (G_open : IsOpen G) : (μ : Measure Ω) G ≤ L.liminf fun i ↦ (μs i : Measure Ω) G := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := fun _ F_closed ↦ limsup_measure_closed_le_of_tendsto μs_lim F_closed
le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h_closeds _ (isClosed_compl_iff.mpr G_open)) theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : (μ : Measure Ω) (frontier E) = 0) :
Mathlib/MeasureTheory/Measure/Portmanteau.lean
318
324
/- 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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Data.Set.Finite.Range /-! # Range of linear maps The range `LinearMap.range` of a (semi)linear map `f : M → M₂` is a submodule of `M₂`. More specifically, `LinearMap.range` applies to any `SemilinearMapClass` over a `RingHomSurjective` ring homomorphism. Note that this also means that dot notation (i.e. `f.range` for a linear map `f`) does not work. ## Notations * We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear (resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`). ## Tags linear algebra, vector space, module, range -/ open Function variable {R : Type*} {R₂ : Type*} {R₃ : Type*} variable {K : Type*} variable {M : Type*} {M₂ : Type*} {M₃ : Type*} variable {V : Type*} {V₂ : Type*} namespace LinearMap section AddCommMonoid variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] open Submodule variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] section variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. See Note [range copy pattern]. -/ def range [RingHomSurjective τ₁₂] (f : F) : Submodule R₂ M₂ := (map f ⊤).copy (Set.range f) Set.image_univ.symm theorem range_coe [RingHomSurjective τ₁₂] (f : F) : (range f : Set M₂) = Set.range f := rfl theorem range_toAddSubmonoid [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubmonoid = AddMonoidHom.mrange f := rfl @[simp] theorem mem_range [RingHomSurjective τ₁₂] {f : F} {x} : x ∈ range f ↔ ∃ y, f y = x := Iff.rfl theorem range_eq_map [RingHomSurjective τ₁₂] (f : F) : range f = map f ⊤ := by ext simp theorem mem_range_self [RingHomSurjective τ₁₂] (f : F) (x : M) : f x ∈ range f := ⟨x, rfl⟩ @[simp] theorem range_id : range (LinearMap.id : M →ₗ[R] M) = ⊤ := SetLike.coe_injective Set.range_id theorem range_comp [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = map g (range f) := SetLike.coe_injective (Set.range_comp g f) theorem range_comp_le_range [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) ≤ range g := SetLike.coe_mono (Set.range_comp_subset_range f g) theorem range_eq_top [RingHomSurjective τ₁₂] {f : F} : range f = ⊤ ↔ Surjective f := by rw [SetLike.ext'_iff, range_coe, top_coe, Set.range_eq_univ] theorem range_eq_top_of_surjective [RingHomSurjective τ₁₂] (f : F) (hf : Surjective f) : range f = ⊤ := range_eq_top.2 hf theorem range_le_iff_comap [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range_eq_map, map_le_iff_le_comap, eq_top_iff] theorem map_le_range [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} : map f p ≤ range f := SetLike.coe_mono (Set.image_subset_range f p) @[simp] theorem range_neg {R : Type*} {R₂ : Type*} {M : Type*} {M₂ : Type*} [Semiring R] [Ring R₂] [AddCommMonoid M] [AddCommGroup M₂] [Module R M] [Module R₂ M₂] {τ₁₂ : R →+* R₂} [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : LinearMap.range (-f) = LinearMap.range f := by change range ((-LinearMap.id : M₂ →ₗ[R₂] M₂).comp f) = _ rw [range_comp, Submodule.map_neg, Submodule.map_id] @[simp] lemma range_domRestrict [Module R M₂] (K : Submodule R M) (f : M →ₗ[R] M₂) : range (domRestrict f K) = K.map f := by ext; simp lemma range_domRestrict_le_range [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) (S : Submodule R M) : LinearMap.range (f.domRestrict S) ≤ LinearMap.range f := by rintro x ⟨⟨y, hy⟩, rfl⟩ exact LinearMap.mem_range_self f y @[simp] theorem _root_.AddMonoidHom.coe_toIntLinearMap_range {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂] (f : M →+ M₂) : LinearMap.range f.toIntLinearMap = AddSubgroup.toIntSubmodule f.range := rfl lemma _root_.Submodule.map_comap_eq_of_le [RingHomSurjective τ₁₂] {f : F} {p : Submodule R₂ M₂} (h : p ≤ LinearMap.range f) : (p.comap f).map f = p := SetLike.coe_injective <| Set.image_preimage_eq_of_subset h lemma range_restrictScalars [SMul R R₂] [Module R₂ M] [Module R M₂] [CompatibleSMul M M₂ R R₂] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) : LinearMap.range (f.restrictScalars R) = (LinearMap.range f).restrictScalars R := rfl end /-- The decreasing sequence of submodules consisting of the ranges of the iterates of a linear map. -/ @[simps] def iterateRange (f : M →ₗ[R] M) : ℕ →o (Submodule R M)ᵒᵈ where toFun n := LinearMap.range (f ^ n) monotone' n m w x h := by obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w rw [LinearMap.mem_range] at h obtain ⟨m, rfl⟩ := h rw [LinearMap.mem_range] use (f ^ c) m rw [pow_add, Module.End.mul_apply] /-- Restrict the codomain of a linear map `f` to `f.range`. This is the bundled version of `Set.rangeFactorization`. -/ abbrev rangeRestrict [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : M →ₛₗ[τ₁₂] LinearMap.range f := f.codRestrict (LinearMap.range f) (LinearMap.mem_range_self f) /-- The range of a linear map is finite if the domain is finite. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype M₂`. -/ instance fintypeRange [Fintype M] [DecidableEq M₂] [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : Fintype (range f) := Set.fintypeRange f variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] theorem range_codRestrict {τ₂₁ : R₂ →+* R} [RingHomSurjective τ₂₁] (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) : range (codRestrict p f hf) = comap p.subtype (LinearMap.range f) := by simpa only [range_eq_map] using map_codRestrict _ _ _ _ theorem _root_.Submodule.map_comap_eq [RingHomSurjective τ₁₂] (f : F) (q : Submodule R₂ M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf map_le_range (map_comap_le _ _)) <| by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ theorem _root_.Submodule.map_comap_eq_self [RingHomSurjective τ₁₂] {f : F} {q : Submodule R₂ M₂} (h : q ≤ range f) : map f (comap f q) = q := by rwa [Submodule.map_comap_eq, inf_eq_right] @[simp] theorem range_zero [RingHomSurjective τ₁₂] : range (0 : M →ₛₗ[τ₁₂] M₂) = ⊥ := by simpa only [range_eq_map] using Submodule.map_zero _ section variable [RingHomSurjective τ₁₂] theorem range_le_bot_iff (f : M →ₛₗ[τ₁₂] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem range_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : range f = ⊥ ↔ f = 0 := by rw [← range_le_bot_iff, le_bot_iff] theorem range_le_ker_iff {f : M →ₛₗ[τ₁₂] M₂} {g : M₂ →ₛₗ[τ₂₃] M₃} : range f ≤ ker g ↔ (g.comp f : M →ₛₗ[τ₁₃] M₃) = 0 := ⟨fun h => ker_eq_top.1 <| eq_top_iff'.2 fun _ => h <| ⟨_, rfl⟩, fun h x hx => mem_ker.2 <| Exists.elim hx fun y hy => by rw [← hy, ← comp_apply, h, zero_apply]⟩ theorem comap_le_comap_iff {f : F} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨fun H ↦ by rwa [SetLike.le_def, (range_eq_top.1 hf).forall], comap_mono⟩ theorem comap_injective {f : F} (hf : range f = ⊤) : Injective (comap f) := fun _ _ h => le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) -- TODO (?): generalize to semilinear maps with `f ∘ₗ g` bijective. theorem ker_eq_range_of_comp_eq_id {M P} [AddCommGroup M] [Module R M] [AddCommGroup P] [Module R P] {f : M →ₗ[R] P} {g : P →ₗ[R] M} (h : f ∘ₗ g = .id) : ker f = range (LinearMap.id - g ∘ₗ f) := le_antisymm (fun x hx ↦ ⟨x, show x - g (f x) = x by rw [hx, map_zero, sub_zero]⟩) <| range_le_ker_iff.mpr <| by rw [comp_sub, comp_id, ← comp_assoc, h, id_comp, sub_self] end end AddCommMonoid section Ring variable [Ring R] [Ring R₂] variable [AddCommGroup M] [AddCommGroup M₂] variable [Module R M] [Module R₂ M₂] variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] variable {f : F} open Submodule theorem range_toAddSubgroup [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂) : (range f).toAddSubgroup = f.toAddMonoidHom.range := rfl theorem ker_le_iff [RingHomSurjective τ₁₂] {p : Submodule R M} : ker f ≤ p ↔ ∃ y ∈ range f, f ⁻¹' {y} ⊆ p := by constructor · intro h use 0 rw [← SetLike.mem_coe, range_coe] exact ⟨⟨0, map_zero f⟩, h⟩ · rintro ⟨y, h₁, h₂⟩ rw [SetLike.le_def] intro z hz simp only [mem_ker, SetLike.mem_coe] at hz rw [← SetLike.mem_coe, range_coe, Set.mem_range] at h₁ obtain ⟨x, hx⟩ := h₁ have hx' : x ∈ p := h₂ hx have hxz : z + x ∈ p := by apply h₂ simp [hx, hz] suffices z + x - x ∈ p by simpa only [this, add_sub_cancel_right] exact p.sub_mem hxz hx' end Ring section Semifield variable [Semifield K] variable [AddCommMonoid V] [Module K V] variable [AddCommMonoid V₂] [Module K V₂] theorem range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := by simpa only [range_eq_map] using Submodule.map_smul f _ a h theorem range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆ _ : a ≠ 0, range f := by simpa only [range_eq_map] using Submodule.map_smul' f _ a end Semifield end LinearMap namespace Submodule section AddCommMonoid variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂] variable [Module R M] [Module R₂ M₂] variable (p : Submodule R M) variable {τ₁₂ : R →+* R₂} variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂] open LinearMap @[simp] theorem map_top [RingHomSurjective τ₁₂] (f : F) : map f ⊤ = range f := (range_eq_map f).symm @[simp] theorem range_subtype : range p.subtype = p := by simpa using map_comap_subtype p ⊤ theorem map_subtype_le (p' : Submodule R p) : map p.subtype p' ≤ p := by simpa using (map_le_range : map p.subtype p' ≤ range p.subtype) /-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the maximal submodule of `p` is just `p`. -/ theorem map_subtype_top : map p.subtype (⊤ : Submodule R p) = p := by simp @[simp] theorem comap_subtype_eq_top {p p' : Submodule R M} : comap p.subtype p' = ⊤ ↔ p ≤ p' := eq_top_iff.trans <| map_le_iff_le_comap.symm.trans <| by rw [map_subtype_top] @[simp] theorem comap_subtype_self : comap p.subtype p = ⊤ := comap_subtype_eq_top.2 le_rfl @[simp] lemma comap_subtype_le_iff {p q r : Submodule R M} : q.comap p.subtype ≤ r.comap p.subtype ↔ p ⊓ q ≤ p ⊓ r := ⟨fun h ↦ by simpa using map_mono (f := p.subtype) h, fun h ↦ by simpa using comap_mono (f := p.subtype) h⟩ theorem range_inclusion (p q : Submodule R M) (h : p ≤ q) : range (inclusion h) = comap q.subtype p := by rw [← map_top, inclusion, LinearMap.map_codRestrict, map_top, range_subtype] @[simp] theorem map_subtype_range_inclusion {p p' : Submodule R M} (h : p ≤ p') : map p'.subtype (range <| inclusion h) = p := by simp [range_inclusion, map_comap_eq, h] lemma restrictScalars_map [SMul R R₂] [Module R₂ M] [Module R M₂] [IsScalarTower R R₂ M] [IsScalarTower R R₂ M₂] (f : M →ₗ[R₂] M₂) (M' : Submodule R₂ M) : (M'.map f).restrictScalars R = (M'.restrictScalars R).map (f.restrictScalars R) := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. See also `Submodule.mapIic`. -/ def MapSubtype.relIso : Submodule R p ≃o { p' : Submodule R M // p' ≤ p } where toFun p' := ⟨map p.subtype p', map_subtype_le p _⟩ invFun q := comap p.subtype q left_inv p' := comap_map_eq_of_injective (by exact Subtype.val_injective) p' right_inv := fun ⟨q, hq⟩ => Subtype.ext_val <| by simp [map_comap_subtype p, inf_of_le_right hq] map_rel_iff' {p₁ p₂} := Subtype.coe_le_coe.symm.trans <| by dsimp rw [map_le_iff_le_comap, comap_map_eq_of_injective (show Injective p.subtype from Subtype.coe_injective) p₂] /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of `M`. -/ def MapSubtype.orderEmbedding : Submodule R p ↪o Submodule R M := (RelIso.toRelEmbedding <| MapSubtype.relIso p).trans <| Subtype.relEmbedding (X := Submodule R M) (fun p p' ↦ p ≤ p') _ @[simp] theorem map_subtype_embedding_eq (p' : Submodule R p) : MapSubtype.orderEmbedding p p' = map p.subtype p' := rfl /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N`. -/ def mapIic (p : Submodule R M) : Submodule R p ≃o Set.Iic p := Submodule.MapSubtype.relIso p @[simp] lemma coe_mapIic_apply (p : Submodule R M) (q : Submodule R p) : (p.mapIic q : Submodule R M) = q.map p.subtype := rfl end AddCommMonoid end Submodule namespace LinearMap section Semiring variable [Semiring R] [Semiring R₂] [Semiring R₃] variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃] variable [Module R M] [Module R₂ M₂] [Module R₃ M₃] variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃} variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃] /-- A monomorphism is injective. -/ theorem ker_eq_bot_of_cancel {f : M →ₛₗ[τ₁₂] M₂} (h : ∀ u v : ker f →ₗ[R] M, f.comp u = f.comp v → u = v) : ker f = ⊥ := by have h₁ : f.comp (0 : ker f →ₗ[R] M) = 0 := comp_zero _ rw [← Submodule.range_subtype (ker f), ← h 0 (ker f).subtype (Eq.trans h₁ (comp_ker_subtype f).symm)] exact range_zero theorem range_comp_of_range_eq_top [RingHomSurjective τ₁₂] [RingHomSurjective τ₂₃] [RingHomSurjective τ₁₃] {f : M →ₛₗ[τ₁₂] M₂} (g : M₂ →ₛₗ[τ₂₃] M₃) (hf : range f = ⊤) : range (g.comp f : M →ₛₗ[τ₁₃] M₃) = range g := by rw [range_comp, hf, Submodule.map_top] section Image /-- If `O` is a submodule of `M`, and `Φ : O →ₗ M'` is a linear map, then `(ϕ : O →ₗ M').submoduleImage N` is `ϕ(N)` as a submodule of `M'` -/ def submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) : Submodule R M' := (N.comap O.subtype).map ϕ @[simp] theorem mem_submoduleImage {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} {x : M'} : x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yO : y ∈ O), y ∈ N ∧ ϕ ⟨y, yO⟩ = x := by refine Submodule.mem_map.trans ⟨?_, ?_⟩ <;> simp_rw [Submodule.mem_comap] · rintro ⟨⟨y, yO⟩, yN : y ∈ N, h⟩ exact ⟨y, yO, yN, h⟩ · rintro ⟨y, yO, yN, h⟩ exact ⟨⟨y, yO⟩, yN, h⟩ theorem mem_submoduleImage_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} {ϕ : O →ₗ[R] M'} {N : Submodule R M} (hNO : N ≤ O) {x : M'} : x ∈ ϕ.submoduleImage N ↔ ∃ (y : _) (yN : y ∈ N), ϕ ⟨y, hNO yN⟩ = x := by refine mem_submoduleImage.trans ⟨?_, ?_⟩ · rintro ⟨y, yO, yN, h⟩ exact ⟨y, yN, h⟩ · rintro ⟨y, yN, h⟩ exact ⟨y, hNO yN, yN, h⟩ theorem submoduleImage_apply_of_le {M' : Type*} [AddCommMonoid M'] [Module R M'] {O : Submodule R M} (ϕ : O →ₗ[R] M') (N : Submodule R M) (hNO : N ≤ O) : ϕ.submoduleImage N = range (ϕ.comp (Submodule.inclusion hNO)) := by rw [submoduleImage, range_comp, Submodule.range_inclusion] end Image section rangeRestrict variable [RingHomSurjective τ₁₂] (f : M →ₛₗ[τ₁₂] M₂)
@[simp] theorem range_rangeRestrict : range f.rangeRestrict = ⊤ := by simp [f.range_codRestrict _] theorem surjective_rangeRestrict : Surjective f.rangeRestrict := by rw [← range_eq_top, range_rangeRestrict] @[simp] theorem ker_rangeRestrict : ker f.rangeRestrict = ker f := LinearMap.ker_codRestrict _ _ _ @[simp] theorem injective_rangeRestrict_iff : Injective f.rangeRestrict ↔ Injective f :=
Mathlib/Algebra/Module/Submodule/Range.lean
412
419
/- Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Bivariate import Mathlib.AlgebraicGeometry.EllipticCurve.Weierstrass import Mathlib.AlgebraicGeometry.EllipticCurve.VariableChange /-! # Affine coordinates for Weierstrass curves This file defines the type of points on a Weierstrass curve as an inductive, consisting of the point at infinity and affine points satisfying a Weierstrass equation with a nonsingular condition. This file also defines the negation and addition operations of the group law for this type, and proves that they respect the Weierstrass equation and the nonsingular condition. The fact that they form an abelian group is proven in `Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean`. ## Mathematical background Let `W` be a Weierstrass curve over a field `F` with coefficients `aᵢ`. An *affine point* on `W` is a tuple `(x, y)` of elements in `R` satisfying the *Weierstrass equation* `W(X, Y) = 0` in *affine coordinates*, where `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)`. It is *nonsingular* if its partial derivatives `W_X(x, y)` and `W_Y(x, y)` do not vanish simultaneously. The nonsingular affine points on `W` can be given negation and addition operations defined by a secant-and-tangent process. * Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third nonsingular point of intersection between `W` and the vertical line through `P`. Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - a₁x - a₃)`. * Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the negation of the unique third nonsingular point of intersection between `W` and the line `L` through `P` and `Q`. Explicitly, let `P` be `(x₁, y₁)` and let `Q` be `(x₂, y₂)`. * If `x₁ = x₂` and `y₁ = -y₂ - a₁x₂ - a₃`, then `L` is vertical. * If `x₁ = x₂` and `y₁ ≠ -y₂ - a₁x₂ - a₃`, then `L` is the tangent of `W` at `P = Q`, and has slope `ℓ := (3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. * Otherwise `x₁ ≠ x₂`, then `L` is the secant of `W` through `P` and `Q`, and has slope `ℓ := (y₁ - y₂) / (x₁ - x₂)`. In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the equation obtained by substituting the line `Y = ℓ(X - x₁) + y₁` into the Weierstrass equation, and can be written down explicitly as `x := ℓ² + a₁ℓ - a₂ - x₁ - x₂` by inspecting the coefficients of `X²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps `Y` to `-Y - a₁X - a₃`, is precisely `y := -(ℓ(x - x₁) + y₁) - a₁x - a₃`. The type of nonsingular points `W⟮F⟯` in affine coordinates is an inductive, consisting of the unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. Then `W⟮F⟯` can be endowed with a group law, with `𝓞` as the identity nonsingular point, which is uniquely determined by these formulae. ## Main definitions * `WeierstrassCurve.Affine.Equation`: the Weierstrass equation of an affine Weierstrass curve. * `WeierstrassCurve.Affine.Nonsingular`: the nonsingular condition on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point`: a nonsingular rational point on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point.neg`: the negation operation on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point.add`: the addition operation on an affine Weierstrass curve. ## Main statements * `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation. * `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation. * `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition. * `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition. * `WeierstrassCurve.Affine.nonsingular_of_Δ_ne_zero`: an affine Weierstrass curve is nonsingular at every point if its discriminant is non-zero. * `WeierstrassCurve.Affine.nonsingular`: an affine elliptic curve is nonsingular at every point. ## Notations * `W⟮K⟯`: the group of nonsingular rational points on `W` base changed to `K`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, rational point, affine coordinates -/ open Polynomial open scoped Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "derivative_simp" : tactic => `(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add, derivative_sub, derivative_mul, derivative_sq]) local macro "eval_simp" : tactic => `(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval]) local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, Polynomial.map_ofNat, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom, WeierstrassCurve.map]) universe r s u v w /-! ## Weierstrass curves -/ namespace WeierstrassCurve variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} {L : Type w} variable (R) in /-- An abbreviation for a Weierstrass curve in affine coordinates. -/ abbrev Affine : Type r := WeierstrassCurve R /-- The conversion from a Weierstrass curve to affine coordinates. -/ abbrev toAffine (W : WeierstrassCurve R) : Affine R := W namespace Affine variable [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] [Field L] {W' : Affine R} {W : Affine F} section Equation /-! ### Weierstrass equations -/ variable (W') in /-- The polynomial `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)` associated to a Weierstrass curve `W` over a ring `R` in affine coordinates. For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the inner variable represents `X` and the outer variable represents `Y`. For clarity, the alternative notations `Y` and `R[X][Y]` are provided in the `Polynomial.Bivariate` scope to represent the outer variable and the bivariate polynomial ring `R[X][X]` respectively. -/ noncomputable def polynomial : R[X][Y] := Y ^ 2 + C (C W'.a₁ * X + C W'.a₃) * Y - C (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆) lemma polynomial_eq : W'.polynomial = Cubic.toPoly ⟨0, 1, Cubic.toPoly ⟨0, 0, W'.a₁, W'.a₃⟩, Cubic.toPoly ⟨-1, -W'.a₂, -W'.a₄, -W'.a₆⟩⟩ := by simp only [polynomial, Cubic.toPoly] C_simp ring1 lemma polynomial_ne_zero [Nontrivial R] : W'.polynomial ≠ 0 := by rw [polynomial_eq] exact Cubic.ne_zero_of_b_ne_zero one_ne_zero @[simp] lemma degree_polynomial [Nontrivial R] : W'.polynomial.degree = 2 := by rw [polynomial_eq] exact Cubic.degree_of_b_ne_zero' one_ne_zero @[simp] lemma natDegree_polynomial [Nontrivial R] : W'.polynomial.natDegree = 2 := by rw [polynomial_eq] exact Cubic.natDegree_of_b_ne_zero' one_ne_zero lemma monic_polynomial : W'.polynomial.Monic := by nontriviality R simpa only [polynomial_eq] using Cubic.monic_of_b_eq_one' lemma irreducible_polynomial [IsDomain R] : Irreducible W'.polynomial := by by_contra h rcases (monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff natDegree_polynomial).mp h with ⟨f, g, h0, h1⟩ simp only [polynomial_eq, Cubic.coeff_eq_c, Cubic.coeff_eq_d] at h0 h1 apply_fun degree at h0 h1 rw [Cubic.degree_of_a_ne_zero' <| neg_ne_zero.mpr <| one_ne_zero' R, degree_mul] at h0 apply (h1.symm.le.trans Cubic.degree_of_b_eq_zero').not_lt rcases Nat.WithBot.add_eq_three_iff.mp h0.symm with h | h | h | h iterate 2 rw [degree_add_eq_right_of_degree_lt] <;> simp only [h] <;> decide iterate 2 rw [degree_add_eq_left_of_degree_lt] <;> simp only [h] <;> decide lemma evalEval_polynomial (x y : R) : W'.polynomial.evalEval x y = y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) := by simp only [polynomial] eval_simp rw [add_mul, ← add_assoc] @[simp] lemma evalEval_polynomial_zero : W'.polynomial.evalEval 0 0 = -W'.a₆ := by simp only [evalEval_polynomial, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _] variable (W') in /-- The proposition that an affine point `(x, y)` lies in a Weierstrass curve `W`. In other words, it satisfies the Weierstrass equation `W(X, Y) = 0`. -/ def Equation (x y : R) : Prop := W'.polynomial.evalEval x y = 0 lemma equation_iff' (x y : R) : W'.Equation x y ↔ y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) = 0 := by rw [Equation, evalEval_polynomial] lemma equation_iff (x y : R) : W'.Equation x y ↔ y ^ 2 + W'.a₁ * x * y + W'.a₃ * y = x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆ := by rw [equation_iff', sub_eq_zero] @[simp] lemma equation_zero : W'.Equation 0 0 ↔ W'.a₆ = 0 := by rw [Equation, evalEval_polynomial_zero, neg_eq_zero] lemma equation_iff_variableChange (x y : R) : W'.Equation x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Equation 0 0 := by rw [equation_iff', ← neg_eq_zero, equation_zero, variableChange_a₆, inv_one, Units.val_one] congr! 1 ring1 end Equation section Nonsingular /-! ### Nonsingular Weierstrass equations -/ variable (W') in /-- The partial derivative `W_X(X, Y)` with respect to `X` of the polynomial `W(X, Y)` associated to a Weierstrass curve `W` in affine coordinates. -/ -- TODO: define this in terms of `Polynomial.derivative`. noncomputable def polynomialX : R[X][Y] := C (C W'.a₁) * Y - C (C 3 * X ^ 2 + C (2 * W'.a₂) * X + C W'.a₄) lemma evalEval_polynomialX (x y : R) : W'.polynomialX.evalEval x y = W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) := by simp only [polynomialX] eval_simp @[simp] lemma evalEval_polynomialX_zero : W'.polynomialX.evalEval 0 0 = -W'.a₄ := by simp only [evalEval_polynomialX, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _] variable (W') in /-- The partial derivative `W_Y(X, Y)` with respect to `Y` of the polynomial `W(X, Y)` associated to a Weierstrass curve `W` in affine coordinates. -/ -- TODO: define this in terms of `Polynomial.derivative`. noncomputable def polynomialY : R[X][Y] := C (C 2) * Y + C (C W'.a₁ * X + C W'.a₃) lemma evalEval_polynomialY (x y : R) : W'.polynomialY.evalEval x y = 2 * y + W'.a₁ * x + W'.a₃ := by simp only [polynomialY] eval_simp rw [← add_assoc] @[simp] lemma evalEval_polynomialY_zero : W'.polynomialY.evalEval 0 0 = W'.a₃ := by simp only [evalEval_polynomialY, zero_add, mul_zero] variable (W') in /-- The proposition that an affine point `(x, y)` on a Weierstrass curve `W` is nonsingular. In other words, either `W_X(x, y) ≠ 0` or `W_Y(x, y) ≠ 0`. Note that this definition is only mathematically accurate for fields. -/ -- TODO: generalise this definition to be mathematically accurate for a larger class of rings. def Nonsingular (x y : R) : Prop := W'.Equation x y ∧ (W'.polynomialX.evalEval x y ≠ 0 ∨ W'.polynomialY.evalEval x y ≠ 0) lemma nonsingular_iff' (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧ (W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) ≠ 0 ∨ 2 * y + W'.a₁ * x + W'.a₃ ≠ 0) := by rw [Nonsingular, equation_iff', evalEval_polynomialX, evalEval_polynomialY] lemma nonsingular_iff (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧ (W'.a₁ * y ≠ 3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄ ∨ y ≠ -y - W'.a₁ * x - W'.a₃) := by rw [nonsingular_iff', sub_ne_zero, ← sub_ne_zero (a := y)] congr! 3 ring1 @[simp] lemma nonsingular_zero : W'.Nonsingular 0 0 ↔ W'.a₆ = 0 ∧ (W'.a₃ ≠ 0 ∨ W'.a₄ ≠ 0) := by rw [Nonsingular, equation_zero, evalEval_polynomialX_zero, neg_ne_zero, evalEval_polynomialY_zero, or_comm] lemma nonsingular_iff_variableChange (x y : R) : W'.Nonsingular x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Nonsingular 0 0 := by rw [nonsingular_iff', equation_iff_variableChange, equation_zero, ← neg_ne_zero, or_comm, nonsingular_zero, variableChange_a₃, variableChange_a₄, inv_one, Units.val_one] simp only [variableChange_def] congr! 3 <;> ring1 private lemma equation_zero_iff_nonsingular_zero_of_Δ_ne_zero (hΔ : W'.Δ ≠ 0) : W'.Equation 0 0 ↔ W'.Nonsingular 0 0 := by simp only [equation_zero, nonsingular_zero, iff_self_and] contrapose! hΔ simp only [b₂, b₄, b₆, b₈, Δ, hΔ] ring1 /-- A Weierstrass curve is nonsingular at every point if its discriminant is non-zero. -/ lemma equation_iff_nonsingular_of_Δ_ne_zero {x y : R} (hΔ : W'.Δ ≠ 0) : W'.Equation x y ↔ W'.Nonsingular x y := by rw [equation_iff_variableChange, nonsingular_iff_variableChange, equation_zero_iff_nonsingular_zero_of_Δ_ne_zero <| by rwa [variableChange_Δ, inv_one, Units.val_one, one_pow, one_mul]] /-- An elliptic curve is nonsingular at every point. -/ lemma equation_iff_nonsingular [Nontrivial R] [W'.IsElliptic] {x y : R} : W'.toAffine.Equation x y ↔ W'.toAffine.Nonsingular x y := W'.toAffine.equation_iff_nonsingular_of_Δ_ne_zero <| W'.coe_Δ' ▸ W'.Δ'.ne_zero @[deprecated (since := "2025-03-01")] alias nonsingular_zero_of_Δ_ne_zero := equation_iff_nonsingular_of_Δ_ne_zero @[deprecated (since := "2025-03-01")] alias nonsingular_of_Δ_ne_zero := equation_iff_nonsingular_of_Δ_ne_zero @[deprecated (since := "2025-03-01")] alias nonsingular := equation_iff_nonsingular end Nonsingular section Ring /-! ### Group operation polynomials over a ring -/ variable (W') in /-- The negation polynomial `-Y - a₁X - a₃` associated to the negation of a nonsingular affine point on a Weierstrass curve. -/ noncomputable def negPolynomial : R[X][Y] := -(Y : R[X][Y]) - C (C W'.a₁ * X + C W'.a₃) lemma Y_sub_polynomialY : Y - W'.polynomialY = W'.negPolynomial := by rw [polynomialY, negPolynomial] C_simp ring1 lemma Y_sub_negPolynomial : Y - W'.negPolynomial = W'.polynomialY := by rw [← Y_sub_polynomialY, sub_sub_cancel] variable (W') in /-- The `Y`-coordinate of `-(x, y)` for a nonsingular affine point `(x, y)` on a Weierstrass curve `W`. This depends on `W`, and has argument order: `x`, `y`. -/ @[simp] def negY (x y : R) : R := -y - W'.a₁ * x - W'.a₃ lemma negY_negY (x y : R) : W'.negY x (W'.negY x y) = y := by simp only [negY] ring1 lemma evalEval_negPolynomial (x y : R) : W'.negPolynomial.evalEval x y = W'.negY x y := by rw [negY, sub_sub, negPolynomial] eval_simp @[deprecated (since := "2025-03-05")] alias eval_negPolynomial := evalEval_negPolynomial /-- The line polynomial `ℓ(X - x) + y` associated to the line `Y = ℓ(X - x) + y` that passes through a nonsingular affine point `(x, y)` on a Weierstrass curve `W` with a slope of `ℓ`. This does not depend on `W`, and has argument order: `x`, `y`, `ℓ`. -/ noncomputable def linePolynomial (x y ℓ : R) : R[X] := C ℓ * (X - C x) + C y variable (W') in /-- The addition polynomial obtained by substituting the line `Y = ℓ(X - x) + y` into the polynomial `W(X, Y)` associated to a Weierstrass curve `W`. If such a line intersects `W` at another nonsingular affine point `(x', y')` on `W`, then the roots of this polynomial are precisely `x`, `x'`, and the `X`-coordinate of the addition of `(x, y)` and `(x', y')`. This depends on `W`, and has argument order: `x`, `y`, `ℓ`. -/ noncomputable def addPolynomial (x y ℓ : R) : R[X] := W'.polynomial.eval <| linePolynomial x y ℓ lemma C_addPolynomial (x y ℓ : R) : C (W'.addPolynomial x y ℓ) = (Y - C (linePolynomial x y ℓ)) * (W'.negPolynomial - C (linePolynomial x y ℓ)) + W'.polynomial := by rw [addPolynomial, linePolynomial, polynomial, negPolynomial] eval_simp C_simp ring1 lemma addPolynomial_eq (x y ℓ : R) : W'.addPolynomial x y ℓ = -Cubic.toPoly ⟨1, -ℓ ^ 2 - W'.a₁ * ℓ + W'.a₂, 2 * x * ℓ ^ 2 + (W'.a₁ * x - 2 * y - W'.a₃) * ℓ + (-W'.a₁ * y + W'.a₄), -x ^ 2 * ℓ ^ 2 + (2 * x * y + W'.a₃ * x) * ℓ - (y ^ 2 + W'.a₃ * y - W'.a₆)⟩ := by rw [addPolynomial, linePolynomial, polynomial, Cubic.toPoly] eval_simp C_simp ring1 variable (W') in /-- The `X`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`. This depends on `W`, and has argument order: `x₁`, `x₂`, `ℓ`. -/ @[simp] def addX (x₁ x₂ ℓ : R) : R := ℓ ^ 2 + W'.a₁ * ℓ - W'.a₂ - x₁ - x₂ variable (W') in /-- The `Y`-coordinate of `-((x₁, y₁) + (x₂, y₂))` for two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`. This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/ @[simp] def negAddY (x₁ x₂ y₁ ℓ : R) : R := ℓ * (W'.addX x₁ x₂ ℓ - x₁) + y₁ variable (W') in /-- The `Y`-coordinate of `(x₁, y₁) + (x₂, y₂)` for two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`, where the line through them has a slope of `ℓ`. This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `ℓ`. -/ @[simp] def addY (x₁ x₂ y₁ ℓ : R) : R := W'.negY (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) lemma equation_neg (x y : R) : W'.Equation x (W'.negY x y) ↔ W'.Equation x y := by rw [equation_iff, equation_iff, negY] congr! 1 ring1 @[deprecated (since := "2025-02-01")] alias equation_neg_of := equation_neg @[deprecated (since := "2025-02-01")] alias equation_neg_iff := equation_neg lemma nonsingular_neg (x y : R) : W'.Nonsingular x (W'.negY x y) ↔ W'.Nonsingular x y := by rw [nonsingular_iff, equation_neg, ← negY, negY_negY, ← @ne_comm _ y, nonsingular_iff] exact and_congr_right' <| (iff_congr not_and_or.symm not_and_or.symm).mpr <| not_congr <| and_congr_left fun h => by rw [← h] @[deprecated (since := "2025-02-01")] alias nonsingular_neg_of := nonsingular_neg @[deprecated (since := "2025-02-01")] alias nonsingular_neg_iff := nonsingular_neg lemma equation_add_iff (x₁ x₂ y₁ ℓ : R) : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) ↔ (W'.addPolynomial x₁ y₁ ℓ).eval (W'.addX x₁ x₂ ℓ) = 0 := by rw [Equation, negAddY, addPolynomial, linePolynomial, polynomial] eval_simp lemma nonsingular_negAdd_of_eval_derivative_ne_zero {x₁ x₂ y₁ ℓ : R} (hx' : W'.Equation (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ)) (hx : (W'.addPolynomial x₁ y₁ ℓ).derivative.eval (W'.addX x₁ x₂ ℓ) ≠ 0) : W'.Nonsingular (W'.addX x₁ x₂ ℓ) (W'.negAddY x₁ x₂ y₁ ℓ) := by rw [Nonsingular, and_iff_right hx', negAddY, polynomialX, polynomialY] eval_simp contrapose! hx rw [addPolynomial, linePolynomial, polynomial] eval_simp derivative_simp simp only [zero_add, add_zero, sub_zero, zero_mul, mul_one] eval_simp linear_combination (norm := (norm_num1; ring1)) hx.left + ℓ * hx.right end Ring section Field /-! ### Group operation polynomials over a field -/ open Classical in variable (W) in /-- The slope of the line through two nonsingular affine points `(x₁, y₁)` and `(x₂, y₂)` on a Weierstrass curve `W`. If `x₁ ≠ x₂`, then this line is the secant of `W` through `(x₁, y₁)` and `(x₂, y₂)`, and has slope `(y₁ - y₂) / (x₁ - x₂)`. Otherwise, if `y₁ ≠ -y₁ - a₁x₁ - a₃`, then this line is the tangent of `W` at `(x₁, y₁) = (x₂, y₂)`, and has slope `(3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. Otherwise, this line is vertical, in which case this returns the value `0`. This depends on `W`, and has argument order: `x₁`, `x₂`, `y₁`, `y₂`. -/ noncomputable def slope (x₁ x₂ y₁ y₂ : F) : F := if x₁ = x₂ then if y₁ = W.negY x₂ y₂ then 0 else (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) else (y₁ - y₂) / (x₁ - x₂) @[simp] lemma slope_of_Y_eq {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ = W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = 0 := by rw [slope, if_pos hx, if_pos hy] @[simp] lemma slope_of_Y_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = (3 * x₁ ^ 2 + 2 * W.a₂ * x₁ + W.a₄ - W.a₁ * y₁) / (y₁ - W.negY x₁ y₁) := by rw [slope, if_pos hx, if_neg hy] @[simp] lemma slope_of_X_ne {x₁ x₂ y₁ y₂ : F} (hx : x₁ ≠ x₂) : W.slope x₁ x₂ y₁ y₂ = (y₁ - y₂) / (x₁ - x₂) := by rw [slope, if_neg hx] lemma slope_of_Y_ne_eq_evalEval {x₁ x₂ y₁ y₂ : F} (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : W.slope x₁ x₂ y₁ y₂ = -W.polynomialX.evalEval x₁ y₁ / W.polynomialY.evalEval x₁ y₁ := by rw [slope_of_Y_ne hx hy, evalEval_polynomialX, neg_sub] congr 1 rw [negY, evalEval_polynomialY] ring1 @[deprecated (since := "2025-03-05")] alias slope_of_Y_ne_eq_eval := slope_of_Y_ne_eq_evalEval lemma Y_eq_of_X_eq {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂) : y₁ = y₂ ∨ y₁ = W.negY x₂ y₂ := by rw [equation_iff] at h₁ h₂ rw [← sub_eq_zero, ← sub_eq_zero (a := y₁), ← mul_eq_zero, negY] linear_combination (norm := (rw [hx]; ring1)) h₁ - h₂ lemma Y_eq_of_Y_ne {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hx : x₁ = x₂) (hy : y₁ ≠ W.negY x₂ y₂) : y₁ = y₂ := (Y_eq_of_X_eq h₁ h₂ hx).resolve_right hy lemma addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.addPolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂) = -((X - C x₁) * (X - C x₂) * (X - C (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂))) := by rw [addPolynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective] by_cases hx : x₁ = x₂ · have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩ rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩ rw [equation_iff] at h₁ h₂ rw [slope_of_Y_ne rfl hy] rw [negY, ← sub_ne_zero] at hy ext · rfl · simp only [addX] ring1 · field_simp [hy] ring1 · linear_combination (norm := (field_simp [hy]; ring1)) -h₁ · rw [equation_iff] at h₁ h₂ rw [slope_of_X_ne hx] rw [← sub_eq_zero] at hx ext · rfl · simp only [addX] ring1 · apply mul_right_injective₀ hx linear_combination (norm := (field_simp [hx]; ring1)) h₂ - h₁ · apply mul_right_injective₀ hx linear_combination (norm := (field_simp [hx]; ring1)) x₂ * h₁ - x₁ * h₂ /-- The negated addition of two affine points in `W` on a sloped line lies in `W`. -/ lemma equation_negAdd {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : W.Equation (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (W.negAddY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by
rw [equation_add_iff, addPolynomial_slope h₁ h₂ hxy] eval_simp rw [neg_eq_zero, sub_self, mul_zero] /-- The addition of two affine points in `W` on a sloped line lies in `W`. -/ lemma equation_add {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂)
Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean
530
535
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn -/ import Mathlib.Geometry.Manifold.ChartedSpace /-! # Local properties invariant under a groupoid We study properties of a triple `(g, s, x)` where `g` is a function between two spaces `H` and `H'`, `s` is a subset of `H` and `x` is a point of `H`. Our goal is to register how such a property should behave to make sense in charted spaces modelled on `H` and `H'`. The main examples we have in mind are the properties "`g` is differentiable at `x` within `s`", or "`g` is smooth at `x` within `s`". We want to develop general results that, when applied in these specific situations, say that the notion of smooth function in a manifold behaves well under restriction, intersection, is local, and so on. ## Main definitions * `LocalInvariantProp G G' P` says that a property `P` of a triple `(g, s, x)` is local, and invariant under composition by elements of the groupoids `G` and `G'` of `H` and `H'` respectively. * `ChartedSpace.LiftPropWithinAt` (resp. `LiftPropAt`, `LiftPropOn` and `LiftProp`): given a property `P` of `(g, s, x)` where `g : H → H'`, define the corresponding property for functions `M → M'` where `M` and `M'` are charted spaces modelled respectively on `H` and `H'`. We define these properties within a set at a point, or at a point, or on a set, or in the whole space. This lifting process (obtained by restricting to suitable chart domains) can always be done, but it only behaves well under locality and invariance assumptions. Given `hG : LocalInvariantProp G G' P`, we deduce many properties of the lifted property on the charted spaces. For instance, `hG.liftPropWithinAt_inter` says that `P g s x` is equivalent to `P g (s ∩ t) x` whenever `t` is a neighborhood of `x`. ## Implementation notes We do not use dot notation for properties of the lifted property. For instance, we have `hG.liftPropWithinAt_congr` saying that if `LiftPropWithinAt P g s x` holds, and `g` and `g'` coincide on `s`, then `LiftPropWithinAt P g' s x` holds. We can't call it `LiftPropWithinAt.congr` as it is in the namespace associated to `LocalInvariantProp`, not in the one for `LiftPropWithinAt`. -/ noncomputable section open Set Filter TopologicalSpace open scoped Manifold Topology variable {H M H' M' X : Type*} variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M] variable [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M'] variable [TopologicalSpace X] namespace StructureGroupoid variable (G : StructureGroupoid H) (G' : StructureGroupoid H') /-- Structure recording good behavior of a property of a triple `(f, s, x)` where `f` is a function, `s` a set and `x` a point. Good behavior here means locality and invariance under given groupoids (both in the source and in the target). Given such a good behavior, the lift of this property to charted spaces admitting these groupoids will inherit the good behavior. -/ structure LocalInvariantProp (P : (H → H') → Set H → H → Prop) : Prop where is_local : ∀ {s x u} {f : H → H'}, IsOpen u → x ∈ u → (P f s x ↔ P f (s ∩ u) x) right_invariance' : ∀ {s x f} {e : PartialHomeomorph H H}, e ∈ G → x ∈ e.source → P f s x → P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) congr_of_forall : ∀ {s x} {f g : H → H'}, (∀ y ∈ s, f y = g y) → f x = g x → P f s x → P g s x left_invariance' : ∀ {s x f} {e' : PartialHomeomorph H' H'}, e' ∈ G' → s ⊆ f ⁻¹' e'.source → f x ∈ e'.source → P f s x → P (e' ∘ f) s x variable {G G'} {P : (H → H') → Set H → H → Prop} variable (hG : G.LocalInvariantProp G' P) include hG namespace LocalInvariantProp theorem congr_set {s t : Set H} {x : H} {f : H → H'} (hu : s =ᶠ[𝓝 x] t) : P f s x ↔ P f t x := by obtain ⟨o, host, ho, hxo⟩ := mem_nhds_iff.mp hu.mem_iff simp_rw [subset_def, mem_setOf, ← and_congr_left_iff, ← mem_inter_iff, ← Set.ext_iff] at host rw [hG.is_local ho hxo, host, ← hG.is_local ho hxo] theorem is_local_nhds {s u : Set H} {x : H} {f : H → H'} (hu : u ∈ 𝓝[s] x) : P f s x ↔ P f (s ∩ u) x := hG.congr_set <| mem_nhdsWithin_iff_eventuallyEq.mp hu theorem congr_iff_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) : P f s x ↔ P g s x := by simp_rw [hG.is_local_nhds h1] exact ⟨hG.congr_of_forall (fun y hy ↦ hy.2) h2, hG.congr_of_forall (fun y hy ↦ hy.2.symm) h2.symm⟩ theorem congr_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) (hP : P f s x) : P g s x := (hG.congr_iff_nhdsWithin h1 h2).mp hP theorem congr_nhdsWithin' {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x) (hP : P g s x) : P f s x := (hG.congr_iff_nhdsWithin h1 h2).mpr hP theorem congr_iff {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) : P f s x ↔ P g s x := hG.congr_iff_nhdsWithin (mem_nhdsWithin_of_mem_nhds h) (mem_of_mem_nhds h :) theorem congr {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P f s x) : P g s x := (hG.congr_iff h).mp hP theorem congr' {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P g s x) : P f s x := hG.congr h.symm hP theorem left_invariance {s : Set H} {x : H} {f : H → H'} {e' : PartialHomeomorph H' H'} (he' : e' ∈ G') (hfs : ContinuousWithinAt f s x) (hxe' : f x ∈ e'.source) : P (e' ∘ f) s x ↔ P f s x := by have h2f := hfs.preimage_mem_nhdsWithin (e'.open_source.mem_nhds hxe') have h3f := ((e'.continuousAt hxe').comp_continuousWithinAt hfs).preimage_mem_nhdsWithin <| e'.symm.open_source.mem_nhds <| e'.mapsTo hxe' constructor · intro h rw [hG.is_local_nhds h3f] at h have h2 := hG.left_invariance' (G'.symm he') inter_subset_right (e'.mapsTo hxe') h rw [← hG.is_local_nhds h3f] at h2 refine hG.congr_nhdsWithin ?_ (e'.left_inv hxe') h2 exact eventually_of_mem h2f fun x' ↦ e'.left_inv · simp_rw [hG.is_local_nhds h2f] exact hG.left_invariance' he' inter_subset_right hxe' theorem right_invariance {s : Set H} {x : H} {f : H → H'} {e : PartialHomeomorph H H} (he : e ∈ G) (hxe : x ∈ e.source) : P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P f s x := by refine ⟨fun h ↦ ?_, hG.right_invariance' he hxe⟩ have := hG.right_invariance' (G.symm he) (e.mapsTo hxe) h rw [e.symm_symm, e.left_inv hxe] at this refine hG.congr ?_ ((hG.congr_set ?_).mp this) · refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_ simp_rw [Function.comp_apply, e.left_inv hx'] · rw [eventuallyEq_set] refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_ simp_rw [mem_preimage, e.left_inv hx'] end LocalInvariantProp
end StructureGroupoid namespace ChartedSpace /-- Given a property of germs of functions and sets in the model space, then one defines a corresponding property in a charted space, by requiring that it holds at the preferred chart at this point. (When the property is local and invariant, it will in fact hold using any chart, see `liftPropWithinAt_indep_chart`). We require continuity in the lifted property, as otherwise one single chart might fail to capture the behavior of the function. -/ @[mk_iff liftPropWithinAt_iff']
Mathlib/Geometry/Manifold/LocalInvariantProperties.lean
139
149
/- Copyright (c) 2020 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Path /-! # Path connectedness Continuing from `Mathlib.Topology.Path`, this file defines path components and path-connected spaces. ## Main definitions In the file the unit interval `[0, 1]` in `ℝ` is denoted by `I`, and `X` is a topological space. * `Joined (x y : X)` means there is a path between `x` and `y`. * `Joined.somePath (h : Joined x y)` selects some path between two points `x` and `y`. * `pathComponent (x : X)` is the set of points joined to `x`. * `PathConnectedSpace X` is a predicate class asserting that `X` is non-empty and every two points of `X` are joined. Then there are corresponding relative notions for `F : Set X`. * `JoinedIn F (x y : X)` means there is a path `γ` joining `x` to `y` with values in `F`. * `JoinedIn.somePath (h : JoinedIn F x y)` selects a path from `x` to `y` inside `F`. * `pathComponentIn F (x : X)` is the set of points joined to `x` in `F`. * `IsPathConnected F` asserts that `F` is non-empty and every two points of `F` are joined in `F`. ## Main theorems * `Joined` is an equivalence relation, while `JoinedIn F` is at least symmetric and transitive. One can link the absolute and relative version in two directions, using `(univ : Set X)` or the subtype `↥F`. * `pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X)` * `isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace ↥F` Furthermore, it is shown that continuous images and quotients of path-connected sets/spaces are path-connected, and that every path-connected set/space is also connected. -/ noncomputable section open Topology Filter unitInterval Set Function variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {x y z : X} {ι : Type*} /-! ### Being joined by a path -/ /-- The relation "being joined by a path". This is an equivalence relation. -/ def Joined (x y : X) : Prop := Nonempty (Path x y) @[refl] theorem Joined.refl (x : X) : Joined x x := ⟨Path.refl x⟩ /-- When two points are joined, choose some path from `x` to `y`. -/ def Joined.somePath (h : Joined x y) : Path x y := Nonempty.some h @[symm] theorem Joined.symm {x y : X} (h : Joined x y) : Joined y x := ⟨h.somePath.symm⟩ @[trans] theorem Joined.trans {x y z : X} (hxy : Joined x y) (hyz : Joined y z) : Joined x z := ⟨hxy.somePath.trans hyz.somePath⟩ variable (X) /-- The setoid corresponding the equivalence relation of being joined by a continuous path. -/ def pathSetoid : Setoid X where r := Joined iseqv := Equivalence.mk Joined.refl Joined.symm Joined.trans /-- The quotient type of points of a topological space modulo being joined by a continuous path. -/ def ZerothHomotopy := Quotient (pathSetoid X) instance ZerothHomotopy.inhabited : Inhabited (ZerothHomotopy ℝ) := ⟨@Quotient.mk' ℝ (pathSetoid ℝ) 0⟩ variable {X} /-! ### Being joined by a path inside a set -/ /-- The relation "being joined by a path in `F`". Not quite an equivalence relation since it's not reflexive for points that do not belong to `F`. -/ def JoinedIn (F : Set X) (x y : X) : Prop := ∃ γ : Path x y, ∀ t, γ t ∈ F variable {F : Set X} theorem JoinedIn.mem (h : JoinedIn F x y) : x ∈ F ∧ y ∈ F := by rcases h with ⟨γ, γ_in⟩ have : γ 0 ∈ F ∧ γ 1 ∈ F := by constructor <;> apply γ_in simpa using this theorem JoinedIn.source_mem (h : JoinedIn F x y) : x ∈ F := h.mem.1 theorem JoinedIn.target_mem (h : JoinedIn F x y) : y ∈ F := h.mem.2 /-- When `x` and `y` are joined in `F`, choose a path from `x` to `y` inside `F` -/ def JoinedIn.somePath (h : JoinedIn F x y) : Path x y := Classical.choose h theorem JoinedIn.somePath_mem (h : JoinedIn F x y) (t : I) : h.somePath t ∈ F := Classical.choose_spec h t /-- If `x` and `y` are joined in the set `F`, then they are joined in the subtype `F`. -/ theorem JoinedIn.joined_subtype (h : JoinedIn F x y) : Joined (⟨x, h.source_mem⟩ : F) (⟨y, h.target_mem⟩ : F) := ⟨{ toFun := fun t => ⟨h.somePath t, h.somePath_mem t⟩ continuous_toFun := by fun_prop source' := by simp target' := by simp }⟩ theorem JoinedIn.ofLine {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) (hF : f '' I ⊆ F) : JoinedIn F x y := ⟨Path.ofLine hf h₀ h₁, fun t => hF <| Path.ofLine_mem hf h₀ h₁ t⟩ theorem JoinedIn.joined (h : JoinedIn F x y) : Joined x y := ⟨h.somePath⟩ theorem joinedIn_iff_joined (x_in : x ∈ F) (y_in : y ∈ F) : JoinedIn F x y ↔ Joined (⟨x, x_in⟩ : F) (⟨y, y_in⟩ : F) := ⟨fun h => h.joined_subtype, fun h => ⟨h.somePath.map continuous_subtype_val, by simp⟩⟩ @[simp] theorem joinedIn_univ : JoinedIn univ x y ↔ Joined x y := by simp [JoinedIn, Joined, exists_true_iff_nonempty] theorem JoinedIn.mono {U V : Set X} (h : JoinedIn U x y) (hUV : U ⊆ V) : JoinedIn V x y := ⟨h.somePath, fun t => hUV (h.somePath_mem t)⟩ theorem JoinedIn.refl (h : x ∈ F) : JoinedIn F x x := ⟨Path.refl x, fun _t => h⟩ @[symm] theorem JoinedIn.symm (h : JoinedIn F x y) : JoinedIn F y x := by obtain ⟨hx, hy⟩ := h.mem simp_all only [joinedIn_iff_joined] exact h.symm theorem JoinedIn.trans (hxy : JoinedIn F x y) (hyz : JoinedIn F y z) : JoinedIn F x z := by obtain ⟨hx, hy⟩ := hxy.mem obtain ⟨hx, hy⟩ := hyz.mem simp_all only [joinedIn_iff_joined] exact hxy.trans hyz theorem Specializes.joinedIn (h : x ⤳ y) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn F x y := by refine ⟨⟨⟨Set.piecewise {1} (const I y) (const I x), ?_⟩, by simp, by simp⟩, fun t ↦ ?_⟩ · exact isClosed_singleton.continuous_piecewise_of_specializes continuous_const continuous_const fun _ ↦ h · simp only [Path.coe_mk_mk, piecewise] split_ifs <;> assumption theorem Inseparable.joinedIn (h : Inseparable x y) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn F x y := h.specializes.joinedIn hx hy theorem JoinedIn.map_continuousOn (h : JoinedIn F x y) {f : X → Y} (hf : ContinuousOn f F) : JoinedIn (f '' F) (f x) (f y) := let ⟨γ, hγ⟩ := h ⟨γ.map' <| hf.mono (range_subset_iff.mpr hγ), fun t ↦ mem_image_of_mem _ (hγ t)⟩ theorem JoinedIn.map (h : JoinedIn F x y) {f : X → Y} (hf : Continuous f) : JoinedIn (f '' F) (f x) (f y) := h.map_continuousOn hf.continuousOn theorem Topology.IsInducing.joinedIn_image {f : X → Y} (hf : IsInducing f) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn (f '' F) (f x) (f y) ↔ JoinedIn F x y := by refine ⟨?_, (.map · hf.continuous)⟩ rintro ⟨γ, hγ⟩ choose γ' hγ'F hγ' using hγ have h₀ : x ⤳ γ' 0 := by rw [← hf.specializes_iff, hγ', γ.source] have h₁ : γ' 1 ⤳ y := by rw [← hf.specializes_iff, hγ', γ.target] have h : JoinedIn F (γ' 0) (γ' 1) := by refine ⟨⟨⟨γ', ?_⟩, rfl, rfl⟩, hγ'F⟩ simpa only [hf.continuous_iff, comp_def, hγ'] using map_continuous γ exact (h₀.joinedIn hx (hγ'F _)).trans <| h.trans <| h₁.joinedIn (hγ'F _) hy @[deprecated (since := "2024-10-28")] alias Inducing.joinedIn_image := IsInducing.joinedIn_image /-! ### Path component -/ /-- The path component of `x` is the set of points that can be joined to `x`. -/ def pathComponent (x : X) := { y | Joined x y } theorem mem_pathComponent_iff : x ∈ pathComponent y ↔ Joined y x := .rfl @[simp] theorem mem_pathComponent_self (x : X) : x ∈ pathComponent x := Joined.refl x @[simp] theorem pathComponent.nonempty (x : X) : (pathComponent x).Nonempty := ⟨x, mem_pathComponent_self x⟩ theorem mem_pathComponent_of_mem (h : x ∈ pathComponent y) : y ∈ pathComponent x := Joined.symm h theorem pathComponent_symm : x ∈ pathComponent y ↔ y ∈ pathComponent x := ⟨fun h => mem_pathComponent_of_mem h, fun h => mem_pathComponent_of_mem h⟩ theorem pathComponent_congr (h : x ∈ pathComponent y) : pathComponent x = pathComponent y := by ext z constructor · intro h' rw [pathComponent_symm] exact (h.trans h').symm · intro h' rw [pathComponent_symm] at h' ⊢ exact h'.trans h theorem pathComponent_subset_component (x : X) : pathComponent x ⊆ connectedComponent x := fun y h => (isConnected_range h.somePath.continuous).subset_connectedComponent ⟨0, by simp⟩ ⟨1, by simp⟩ /-- The path component of `x` in `F` is the set of points that can be joined to `x` in `F`. -/ def pathComponentIn (x : X) (F : Set X) := { y | JoinedIn F x y } @[simp] theorem pathComponentIn_univ (x : X) : pathComponentIn x univ = pathComponent x := by simp [pathComponentIn, pathComponent, JoinedIn, Joined, exists_true_iff_nonempty] theorem Joined.mem_pathComponent (hyz : Joined y z) (hxy : y ∈ pathComponent x) : z ∈ pathComponent x := hxy.trans hyz theorem mem_pathComponentIn_self (h : x ∈ F) : x ∈ pathComponentIn x F := JoinedIn.refl h theorem pathComponentIn_subset : pathComponentIn x F ⊆ F := fun _ hy ↦ hy.target_mem theorem pathComponentIn_nonempty_iff : (pathComponentIn x F).Nonempty ↔ x ∈ F := ⟨fun ⟨_, ⟨γ, hγ⟩⟩ ↦ γ.source ▸ hγ 0, fun hx ↦ ⟨x, mem_pathComponentIn_self hx⟩⟩ theorem pathComponentIn_congr (h : x ∈ pathComponentIn y F) : pathComponentIn x F = pathComponentIn y F := by ext; exact ⟨h.trans, h.symm.trans⟩ @[gcongr] theorem pathComponentIn_mono {G : Set X} (h : F ⊆ G) : pathComponentIn x F ⊆ pathComponentIn x G := fun _ ⟨γ, hγ⟩ ↦ ⟨γ, fun t ↦ h (hγ t)⟩ /-! ### Path connected sets -/ /-- A set `F` is path connected if it contains a point that can be joined to all other in `F`. -/ def IsPathConnected (F : Set X) : Prop := ∃ x ∈ F, ∀ {y}, y ∈ F → JoinedIn F x y theorem isPathConnected_iff_eq : IsPathConnected F ↔ ∃ x ∈ F, pathComponentIn x F = F := by constructor <;> rintro ⟨x, x_in, h⟩ <;> use x, x_in · ext y exact ⟨fun hy => hy.mem.2, h⟩ · intro y y_in rwa [← h] at y_in theorem IsPathConnected.joinedIn (h : IsPathConnected F) : ∀ᵉ (x ∈ F) (y ∈ F), JoinedIn F x y := fun _x x_in _y y_in => let ⟨_b, _b_in, hb⟩ := h (hb x_in).symm.trans (hb y_in) theorem isPathConnected_iff : IsPathConnected F ↔ F.Nonempty ∧ ∀ᵉ (x ∈ F) (y ∈ F), JoinedIn F x y := ⟨fun h => ⟨let ⟨b, b_in, _hb⟩ := h; ⟨b, b_in⟩, h.joinedIn⟩, fun ⟨⟨b, b_in⟩, h⟩ => ⟨b, b_in, fun x_in => h _ b_in _ x_in⟩⟩ /-- If `f` is continuous on `F` and `F` is path-connected, so is `f(F)`. -/ theorem IsPathConnected.image' (hF : IsPathConnected F) {f : X → Y} (hf : ContinuousOn f F) : IsPathConnected (f '' F) := by rcases hF with ⟨x, x_in, hx⟩ use f x, mem_image_of_mem f x_in rintro _ ⟨y, y_in, rfl⟩ refine ⟨(hx y_in).somePath.map' ?_, fun t ↦ ⟨_, (hx y_in).somePath_mem t, rfl⟩⟩ exact hf.mono (range_subset_iff.2 (hx y_in).somePath_mem) /-- If `f` is continuous and `F` is path-connected, so is `f(F)`. -/ theorem IsPathConnected.image (hF : IsPathConnected F) {f : X → Y} (hf : Continuous f) : IsPathConnected (f '' F) := hF.image' hf.continuousOn /-- If `f : X → Y` is an inducing map, `f(F)` is path-connected iff `F` is. -/ nonrec theorem Topology.IsInducing.isPathConnected_iff {f : X → Y} (hf : IsInducing f) : IsPathConnected F ↔ IsPathConnected (f '' F) := by simp only [IsPathConnected, forall_mem_image, exists_mem_image] refine exists_congr fun x ↦ and_congr_right fun hx ↦ forall₂_congr fun y hy ↦ ?_ rw [hf.joinedIn_image hx hy] @[deprecated (since := "2024-10-28")] alias Inducing.isPathConnected_iff := IsInducing.isPathConnected_iff /-- If `h : X → Y` is a homeomorphism, `h(s)` is path-connected iff `s` is. -/ @[simp] theorem Homeomorph.isPathConnected_image {s : Set X} (h : X ≃ₜ Y) : IsPathConnected (h '' s) ↔ IsPathConnected s := h.isInducing.isPathConnected_iff.symm /-- If `h : X → Y` is a homeomorphism, `h⁻¹(s)` is path-connected iff `s` is. -/ @[simp] theorem Homeomorph.isPathConnected_preimage {s : Set Y} (h : X ≃ₜ Y) : IsPathConnected (h ⁻¹' s) ↔ IsPathConnected s := by rw [← Homeomorph.image_symm]; exact h.symm.isPathConnected_image theorem IsPathConnected.mem_pathComponent (h : IsPathConnected F) (x_in : x ∈ F) (y_in : y ∈ F) : y ∈ pathComponent x := (h.joinedIn x x_in y y_in).joined theorem IsPathConnected.subset_pathComponent (h : IsPathConnected F) (x_in : x ∈ F) : F ⊆ pathComponent x := fun _y y_in => h.mem_pathComponent x_in y_in theorem IsPathConnected.subset_pathComponentIn {s : Set X} (hs : IsPathConnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ pathComponentIn x F := fun y hys ↦ (hs.joinedIn x hxs y hys).mono hsF theorem isPathConnected_singleton (x : X) : IsPathConnected ({x} : Set X) := by refine ⟨x, rfl, ?_⟩ rintro y rfl exact JoinedIn.refl rfl theorem isPathConnected_pathComponentIn (h : x ∈ F) : IsPathConnected (pathComponentIn x F) := ⟨x, mem_pathComponentIn_self h, fun ⟨γ, hγ⟩ ↦ by refine ⟨γ, fun t ↦ ⟨(γ.truncateOfLE t.2.1).cast (γ.extend_zero.symm) (γ.extend_extends' t).symm, fun t' ↦ ?_⟩⟩ dsimp [Path.truncateOfLE, Path.truncate] exact γ.extend_extends' ⟨min (max t'.1 0) t.1, by simp [t.2.1, t.2.2]⟩ ▸ hγ _⟩ theorem isPathConnected_pathComponent : IsPathConnected (pathComponent x) := by rw [← pathComponentIn_univ] exact isPathConnected_pathComponentIn (mem_univ x) theorem IsPathConnected.union {U V : Set X} (hU : IsPathConnected U) (hV : IsPathConnected V) (hUV : (U ∩ V).Nonempty) : IsPathConnected (U ∪ V) := by rcases hUV with ⟨x, xU, xV⟩ use x, Or.inl xU rintro y (yU | yV) · exact (hU.joinedIn x xU y yU).mono subset_union_left · exact (hV.joinedIn x xV y yV).mono subset_union_right /-- If a set `W` is path-connected, then it is also path-connected when seen as a set in a smaller ambient type `U` (when `U` contains `W`). -/ theorem IsPathConnected.preimage_coe {U W : Set X} (hW : IsPathConnected W) (hWU : W ⊆ U) : IsPathConnected (((↑) : U → X) ⁻¹' W) := by rwa [IsInducing.subtypeVal.isPathConnected_iff, Subtype.image_preimage_val, inter_eq_right.2 hWU] theorem IsPathConnected.exists_path_through_family {n : ℕ} {s : Set X} (h : IsPathConnected s) (p : Fin (n + 1) → X) (hp : ∀ i, p i ∈ s) : ∃ γ : Path (p 0) (p n), range γ ⊆ s ∧ ∀ i, p i ∈ range γ := by let p' : ℕ → X := fun k => if h : k < n + 1 then p ⟨k, h⟩ else p ⟨0, n.zero_lt_succ⟩ obtain ⟨γ, hγ⟩ : ∃ γ : Path (p' 0) (p' n), (∀ i ≤ n, p' i ∈ range γ) ∧ range γ ⊆ s := by have hp' : ∀ i ≤ n, p' i ∈ s := by intro i hi simp [p', Nat.lt_succ_of_le hi, hp] clear_value p' clear hp p induction n with | zero => use Path.refl (p' 0) constructor · rintro i hi rw [Nat.le_zero.mp hi] exact ⟨0, rfl⟩ · rw [range_subset_iff] rintro _x exact hp' 0 le_rfl | succ n hn => rcases hn fun i hi => hp' i <| Nat.le_succ_of_le hi with ⟨γ₀, hγ₀⟩ rcases h.joinedIn (p' n) (hp' n n.le_succ) (p' <| n + 1) (hp' (n + 1) <| le_rfl) with ⟨γ₁, hγ₁⟩ let γ : Path (p' 0) (p' <| n + 1) := γ₀.trans γ₁ use γ have range_eq : range γ = range γ₀ ∪ range γ₁ := γ₀.trans_range γ₁ constructor · rintro i hi by_cases hi' : i ≤ n · rw [range_eq] left exact hγ₀.1 i hi' · rw [not_le, ← Nat.succ_le_iff] at hi' have : i = n.succ := le_antisymm hi hi' rw [this] use 1 exact γ.target · rw [range_eq] apply union_subset hγ₀.2 rw [range_subset_iff] exact hγ₁ have hpp' : ∀ k < n + 1, p k = p' k := by intro k hk simp only [p', hk, dif_pos] congr ext rw [Fin.val_cast_of_lt hk] use γ.cast (hpp' 0 n.zero_lt_succ) (hpp' n n.lt_succ_self) simp only [γ.cast_coe] refine And.intro hγ.2 ?_ rintro ⟨i, hi⟩ suffices p ⟨i, hi⟩ = p' i by convert hγ.1 i (Nat.le_of_lt_succ hi) rw [← hpp' i hi] suffices i = i % n.succ by congr rw [Nat.mod_eq_of_lt hi] theorem IsPathConnected.exists_path_through_family' {n : ℕ} {s : Set X} (h : IsPathConnected s) (p : Fin (n + 1) → X) (hp : ∀ i, p i ∈ s) : ∃ (γ : Path (p 0) (p n)) (t : Fin (n + 1) → I), (∀ t, γ t ∈ s) ∧ ∀ i, γ (t i) = p i := by rcases h.exists_path_through_family p hp with ⟨γ, hγ⟩ rcases hγ with ⟨h₁, h₂⟩ simp only [range, mem_setOf_eq] at h₂ rw [range_subset_iff] at h₁ choose! t ht using h₂ exact ⟨γ, t, h₁, ht⟩ /-! ### Path connected spaces -/ /-- A topological space is path-connected if it is non-empty and every two points can be joined by a continuous path. -/ @[mk_iff] class PathConnectedSpace (X : Type*) [TopologicalSpace X] : Prop where /-- A path-connected space must be nonempty. -/ nonempty : Nonempty X /-- Any two points in a path-connected space must be joined by a continuous path. -/ joined : ∀ x y : X, Joined x y theorem pathConnectedSpace_iff_zerothHomotopy : PathConnectedSpace X ↔ Nonempty (ZerothHomotopy X) ∧ Subsingleton (ZerothHomotopy X) := by letI := pathSetoid X constructor · intro h refine ⟨(nonempty_quotient_iff _).mpr h.1, ⟨?_⟩⟩ rintro ⟨x⟩ ⟨y⟩ exact Quotient.sound (PathConnectedSpace.joined x y) · unfold ZerothHomotopy rintro ⟨h, h'⟩ exact ⟨(nonempty_quotient_iff _).mp h, fun x y => Quotient.exact <| Subsingleton.elim ⟦x⟧ ⟦y⟧⟩ namespace PathConnectedSpace variable [PathConnectedSpace X] /-- Use path-connectedness to build a path between two points. -/ def somePath (x y : X) : Path x y := Nonempty.some (joined x y) end PathConnectedSpace theorem pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X) := by simp [pathConnectedSpace_iff, isPathConnected_iff, nonempty_iff_univ_nonempty] theorem isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace F := by rw [pathConnectedSpace_iff_univ, IsInducing.subtypeVal.isPathConnected_iff, image_univ, Subtype.range_val_subtype, setOf_mem_eq] theorem isPathConnected_univ [PathConnectedSpace X] : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp inferInstance theorem isPathConnected_range [PathConnectedSpace X] {f : X → Y} (hf : Continuous f) : IsPathConnected (range f) := by rw [← image_univ] exact isPathConnected_univ.image hf theorem Function.Surjective.pathConnectedSpace [PathConnectedSpace X] {f : X → Y} (hf : Surjective f) (hf' : Continuous f) : PathConnectedSpace Y := by rw [pathConnectedSpace_iff_univ, ← hf.range_eq] exact isPathConnected_range hf' instance Quotient.instPathConnectedSpace {s : Setoid X} [PathConnectedSpace X] : PathConnectedSpace (Quotient s) := Quotient.mk'_surjective.pathConnectedSpace continuous_coinduced_rng /-- This is a special case of `NormedSpace.instPathConnectedSpace` (and `IsTopologicalAddGroup.pathConnectedSpace`). It exists only to simplify dependencies. -/ instance Real.instPathConnectedSpace : PathConnectedSpace ℝ where joined x y := ⟨⟨⟨fun (t : I) ↦ (1 - t) * x + t * y, by fun_prop⟩, by simp, by simp⟩⟩ nonempty := inferInstance theorem pathConnectedSpace_iff_eq : PathConnectedSpace X ↔ ∃ x : X, pathComponent x = univ := by simp [pathConnectedSpace_iff_univ, isPathConnected_iff_eq] -- see Note [lower instance priority] instance (priority := 100) PathConnectedSpace.connectedSpace [PathConnectedSpace X] : ConnectedSpace X := by rw [connectedSpace_iff_connectedComponent] rcases isPathConnected_iff_eq.mp (pathConnectedSpace_iff_univ.mp ‹_›) with ⟨x, _x_in, hx⟩ use x rw [← univ_subset_iff] exact (by simpa using hx : pathComponent x = univ) ▸ pathComponent_subset_component x theorem IsPathConnected.isConnected (hF : IsPathConnected F) : IsConnected F := by rw [isConnected_iff_connectedSpace] rw [isPathConnected_iff_pathConnectedSpace] at hF exact @PathConnectedSpace.connectedSpace _ _ hF namespace PathConnectedSpace variable [PathConnectedSpace X] theorem exists_path_through_family {n : ℕ} (p : Fin (n + 1) → X) : ∃ γ : Path (p 0) (p n), ∀ i, p i ∈ range γ := by have : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp (by infer_instance) rcases this.exists_path_through_family p fun _i => True.intro with ⟨γ, -, h⟩ exact ⟨γ, h⟩ theorem exists_path_through_family' {n : ℕ} (p : Fin (n + 1) → X) : ∃ (γ : Path (p 0) (p n)) (t : Fin (n + 1) → I), ∀ i, γ (t i) = p i := by have : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp (by infer_instance) rcases this.exists_path_through_family' p fun _i => True.intro with ⟨γ, t, -, h⟩ exact ⟨γ, t, h⟩ end PathConnectedSpace
Mathlib/Topology/Connected/PathConnected.lean
581
586
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri -/ import Mathlib.Geometry.Manifold.ContMDiffMap import Mathlib.Geometry.Manifold.MFDeriv.Basic /-! # `C^n` monoid A `C^n` monoid is a monoid that is also a `C^n` manifold, in which multiplication is a `C^n` map of the product manifold `G` × `G` into `G`. In this file we define the basic structures to talk about `C^n` monoids: `ContMDiffMul` and its additive counterpart `ContMDiffAdd`. These structures are general enough to also talk about `C^n` semigroups. -/ open scoped Manifold ContDiff library_note "Design choices about smooth algebraic structures"/-- 1. All `C^n` algebraic structures on `G` are `Prop`-valued classes that extend `IsManifold I n G`. This way we save users from adding both `[IsManifold I n G]` and `[ContMDiffMul I n G]` to the assumptions. While many API lemmas hold true without the `IsManifold I n G` assumption, we're not aware of a mathematically interesting monoid on a topological manifold such that (a) the space is not a `IsManifold`; (b) the multiplication is `C^n` at `(a, b)` in the charts `extChartAt I a`, `extChartAt I b`, `extChartAt I (a * b)`. 2. Because of `ModelProd` we can't assume, e.g., that a `LieGroup` is modelled on `𝓘(𝕜, E)`. So, we formulate the definitions and lemmas for any model. 3. While smoothness of an operation implies its continuity, lemmas like `continuousMul_of_contMDiffMul` can't be instances because otherwise Lean would have to search for `ContMDiffMul I n G` with unknown `𝕜`, `E`, `H`, and `I : ModelWithCorners 𝕜 E H`. If users needs `[ContinuousMul G]` in a proof about a `C^n` monoid, then they need to either add `[ContinuousMul G]` as an assumption (worse) or use `haveI` in the proof (better). -/ -- See note [Design choices about smooth algebraic structures] /-- Basic hypothesis to talk about a `C^n` (Lie) additive monoid or a `C^n` additive semigroup. A `C^n` additive monoid over `G`, for example, is obtained by requiring both the instances `AddMonoid G` and `ContMDiffAdd I n G`. -/ class ContMDiffAdd {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] (I : ModelWithCorners 𝕜 E H) (n : WithTop ℕ∞) (G : Type*) [Add G] [TopologicalSpace G] [ChartedSpace H G] : Prop extends IsManifold I n G where contMDiff_add : ContMDiff (I.prod I) I n fun p : G × G => p.1 + p.2 @[deprecated (since := "2025-01-09")] alias SmoothAdd := ContMDiffAdd -- See note [Design choices about smooth algebraic structures] /-- Basic hypothesis to talk about a `C^n` (Lie) monoid or a `C^n` semigroup. A `C^n` monoid over `G`, for example, is obtained by requiring both the instances `Monoid G` and `ContMDiffMul I n G`. -/ @[to_additive] class ContMDiffMul {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] (I : ModelWithCorners 𝕜 E H) (n : WithTop ℕ∞) (G : Type*) [Mul G] [TopologicalSpace G] [ChartedSpace H G] : Prop extends IsManifold I n G where contMDiff_mul : ContMDiff (I.prod I) I n fun p : G × G => p.1 * p.2 @[deprecated (since := "2025-01-09")] alias SmoothMul := ContMDiffMul section ContMDiffMul variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {H : Type*} [TopologicalSpace H] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {I : ModelWithCorners 𝕜 E H} {n : WithTop ℕ∞} {G : Type*} [Mul G] [TopologicalSpace G] [ChartedSpace H G] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M : Type*} [TopologicalSpace M] [ChartedSpace H' M] @[to_additive] protected theorem ContMDiffMul.of_le {m n : WithTop ℕ∞} (hmn : m ≤ n) [h : ContMDiffMul I n G] : ContMDiffMul I m G := by have : IsManifold I m G := IsManifold.of_le hmn exact ⟨h.contMDiff_mul.of_le hmn⟩ @[to_additive] instance {a : WithTop ℕ∞} [ContMDiffMul I ∞ G] [h : ENat.LEInfty a] : ContMDiffMul I a G := ContMDiffMul.of_le h.out @[to_additive] instance {a : WithTop ℕ∞} [ContMDiffMul I ω G] : ContMDiffMul I a G := ContMDiffMul.of_le le_top @[to_additive] instance [ContinuousMul G] : ContMDiffMul I 0 G := by constructor rw [contMDiff_zero_iff] exact continuous_mul @[to_additive] instance [ContMDiffMul I 2 G] : ContMDiffMul I 1 G := ContMDiffMul.of_le one_le_two section variable (I n) @[to_additive] theorem contMDiff_mul [ContMDiffMul I n G] : ContMDiff (I.prod I) I n fun p : G × G => p.1 * p.2 := ContMDiffMul.contMDiff_mul @[deprecated (since := "2024-11-20")] alias smooth_mul := contMDiff_mul @[deprecated (since := "2024-11-20")] alias smooth_add := contMDiff_add include I n in /-- If the multiplication is `C^n`, then it is continuous. This is not an instance for technical reasons, see note [Design choices about smooth algebraic structures]. -/ @[to_additive "If the addition is `C^n`, then it is continuous. This is not an instance for technical reasons, see note [Design choices about smooth algebraic structures]."] theorem continuousMul_of_contMDiffMul [ContMDiffMul I n G] : ContinuousMul G := ⟨(contMDiff_mul I n).continuous⟩ @[deprecated (since := "2025-01-09")] alias continuousMul_of_smooth := continuousMul_of_contMDiffMul end section variable [ContMDiffMul I n G] {f g : M → G} {s : Set M} {x : M} @[to_additive] theorem ContMDiffWithinAt.mul (hf : ContMDiffWithinAt I' I n f s x) (hg : ContMDiffWithinAt I' I n g s x) : ContMDiffWithinAt I' I n (f * g) s x := (contMDiff_mul I n).contMDiffAt.comp_contMDiffWithinAt x (hf.prodMk hg) @[to_additive] nonrec theorem ContMDiffAt.mul (hf : ContMDiffAt I' I n f x) (hg : ContMDiffAt I' I n g x) : ContMDiffAt I' I n (f * g) x := hf.mul hg @[to_additive] theorem ContMDiffOn.mul (hf : ContMDiffOn I' I n f s) (hg : ContMDiffOn I' I n g s) : ContMDiffOn I' I n (f * g) s := fun x hx => (hf x hx).mul (hg x hx) @[to_additive] theorem ContMDiff.mul (hf : ContMDiff I' I n f) (hg : ContMDiff I' I n g) : ContMDiff I' I n (f * g) := fun x => (hf x).mul (hg x) @[deprecated (since := "2024-11-21")] alias SmoothWithinAt.mul := ContMDiffWithinAt.mul @[deprecated (since := "2024-11-21")] alias SmoothAt.mul := ContMDiffAt.mul @[deprecated (since := "2024-11-21")] alias SmoothOn.mul := ContMDiffOn.mul @[deprecated (since := "2024-11-21")] alias Smooth.mul := ContMDiff.mul @[deprecated (since := "2024-11-21")] alias SmoothWithinAt.add := ContMDiffWithinAt.add @[deprecated (since := "2024-11-21")] alias SmoothAt.add := ContMDiffAt.add @[deprecated (since := "2024-11-21")] alias SmoothOn.add := ContMDiffOn.add @[deprecated (since := "2024-11-21")] alias Smooth.add := ContMDiff.add @[to_additive] theorem contMDiff_mul_left {a : G} : ContMDiff I I n (a * ·) := contMDiff_const.mul contMDiff_id @[deprecated (since := "2024-11-21")] alias smooth_mul_left := contMDiff_mul_left @[deprecated (since := "2024-11-21")] alias smooth_add_left := contMDiff_add_left @[to_additive] theorem contMDiffAt_mul_left {a b : G} : ContMDiffAt I I n (a * ·) b := contMDiff_mul_left.contMDiffAt @[to_additive] theorem contMDiff_mul_right {a : G} : ContMDiff I I n (· * a) := contMDiff_id.mul contMDiff_const @[deprecated (since := "2024-11-21")] alias smooth_mul_right := contMDiff_mul_right @[deprecated (since := "2024-11-21")] alias smooth_add_right := contMDiff_add_right @[to_additive] theorem contMDiffAt_mul_right {a b : G} : ContMDiffAt I I n (· * a) b := contMDiff_mul_right.contMDiffAt end section variable [ContMDiffMul I 1 G] @[to_additive] theorem mdifferentiable_mul_left {a : G} : MDifferentiable I I (a * ·) := contMDiff_mul_left.mdifferentiable le_rfl @[to_additive] theorem mdifferentiableAt_mul_left {a b : G} : MDifferentiableAt I I (a * ·) b := contMDiffAt_mul_left.mdifferentiableAt le_rfl @[to_additive] theorem mdifferentiable_mul_right {a : G} : MDifferentiable I I (· * a) := contMDiff_mul_right.mdifferentiable le_rfl @[to_additive] theorem mdifferentiableAt_mul_right {a b : G} : MDifferentiableAt I I (· * a) b := contMDiffAt_mul_right.mdifferentiableAt le_rfl end variable (I) (g h : G) variable [ContMDiffMul I ∞ G] /-- Left multiplication by `g`. It is meant to mimic the usual notation in Lie groups. Used mostly through the notation `𝑳`. Lemmas involving `smoothLeftMul` with the notation `𝑳` usually use `L` instead of `𝑳` in the names. -/ def smoothLeftMul : C^∞⟮I, G; I, G⟯ := ⟨(g * ·), contMDiff_mul_left⟩ /-- Right multiplication by `g`. It is meant to mimic the usual notation in Lie groups. Used mostly through the notation `𝑹`. Lemmas involving `smoothRightMul` with the notation `𝑹` usually use `R` instead of `𝑹` in the names. -/ def smoothRightMul : C^∞⟮I, G; I, G⟯ := ⟨(· * g), contMDiff_mul_right⟩ -- Left multiplication. The abbreviation is `MIL`. @[inherit_doc] scoped[LieGroup] notation "𝑳" => smoothLeftMul -- Right multiplication. The abbreviation is `MIR`. @[inherit_doc] scoped[LieGroup] notation "𝑹" => smoothRightMul open scoped LieGroup @[simp] theorem L_apply : (𝑳 I g) h = g * h := rfl @[simp] theorem R_apply : (𝑹 I g) h = h * g := rfl @[simp] theorem L_mul {G : Type*} [Semigroup G] [TopologicalSpace G] [ChartedSpace H G] [ContMDiffMul I ∞ G] (g h : G) : 𝑳 I (g * h) = (𝑳 I g).comp (𝑳 I h) := by ext simp only [ContMDiffMap.comp_apply, L_apply, mul_assoc] @[simp] theorem R_mul {G : Type*} [Semigroup G] [TopologicalSpace G] [ChartedSpace H G] [ContMDiffMul I ∞ G] (g h : G) : 𝑹 I (g * h) = (𝑹 I h).comp (𝑹 I g) := by ext simp only [ContMDiffMap.comp_apply, R_apply, mul_assoc] section variable {G' : Type*} [Monoid G'] [TopologicalSpace G'] [ChartedSpace H G'] [ContMDiffMul I ∞ G'] (g' : G') theorem smoothLeftMul_one : (𝑳 I g') 1 = g' := mul_one g' theorem smoothRightMul_one : (𝑹 I g') 1 = g' := one_mul g'
end -- Instance of product
Mathlib/Geometry/Manifold/Algebra/Monoid.lean
257
259
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kim Morrison -/ import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.Algebra.Category.Ring.Instances import Mathlib.Algebra.Category.Ring.Limits import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.RingTheory.Localization.AtPrime import Mathlib.RingTheory.Spectrum.Prime.Topology import Mathlib.Topology.Sheaves.LocalPredicate /-! # The structure sheaf on `PrimeSpectrum R`. We define the structure sheaf on `TopCat.of (PrimeSpectrum R)`, for a commutative ring `R` and prove basic properties about it. We define this as a subsheaf of the sheaf of dependent functions into the localizations, cut out by the condition that the function must be locally equal to a ratio of elements of `R`. Because the condition "is equal to a fraction" passes to smaller open subsets, the subset of functions satisfying this condition is automatically a subpresheaf. Because the condition "is locally equal to a fraction" is local, it is also a subsheaf. (It may be helpful to refer back to `Mathlib/Topology/Sheaves/SheafOfFunctions.lean`, where we show that dependent functions into any type family form a sheaf, and also `Mathlib/Topology/Sheaves/LocalPredicate.lean`, where we characterise the predicates which pick out sub-presheaves and sub-sheaves of these sheaves.) We also set up the ring structure, obtaining `structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R)`. We then construct two basic isomorphisms, relating the structure sheaf to the underlying ring `R`. First, `StructureSheaf.stalkIso` gives an isomorphism between the stalk of the structure sheaf at a point `p` and the localization of `R` at the prime ideal `p`. Second, `StructureSheaf.basicOpenIso` gives an isomorphism between the structure sheaf on `basicOpen f` and the localization of `R` at the submonoid of powers of `f`. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ universe u noncomputable section variable (R : Type u) [CommRing R] open TopCat open TopologicalSpace open CategoryTheory open Opposite namespace AlgebraicGeometry /-- The prime spectrum, just as a topological space. -/ def PrimeSpectrum.Top : TopCat := TopCat.of (PrimeSpectrum R) namespace StructureSheaf /-- The type family over `PrimeSpectrum R` consisting of the localization over each point. -/ def Localizations (P : PrimeSpectrum.Top R) : Type u := Localization.AtPrime P.asIdeal instance commRingLocalizations (P : PrimeSpectrum.Top R) : CommRing <| Localizations R P := inferInstanceAs <| CommRing <| Localization.AtPrime P.asIdeal instance localRingLocalizations (P : PrimeSpectrum.Top R) : IsLocalRing <| Localizations R P := inferInstanceAs <| IsLocalRing <| Localization.AtPrime P.asIdeal instance (P : PrimeSpectrum.Top R) : Inhabited (Localizations R P) := ⟨1⟩ instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : Algebra R (Localizations R x) := inferInstanceAs <| Algebra R (Localization.AtPrime x.1.asIdeal) instance (U : Opens (PrimeSpectrum.Top R)) (x : U) : IsLocalization.AtPrime (Localizations R x) (x : PrimeSpectrum.Top R).asIdeal := Localization.isLocalization variable {R} /-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction `r / s` in each of the stalks (which are localizations at various prime ideals). -/ def IsFraction {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : Prop := ∃ r s : R, ∀ x : U, ¬s ∈ x.1.asIdeal ∧ f x * algebraMap _ _ s = algebraMap _ _ r theorem IsFraction.eq_mk' {U : Opens (PrimeSpectrum.Top R)} {f : ∀ x : U, Localizations R x} (hf : IsFraction f) : ∃ r s : R, ∀ x : U, ∃ hs : s ∉ x.1.asIdeal, f x = IsLocalization.mk' (Localization.AtPrime _) r (⟨s, hs⟩ : (x : PrimeSpectrum.Top R).asIdeal.primeCompl) := by rcases hf with ⟨r, s, h⟩ refine ⟨r, s, fun x => ⟨(h x).1, (IsLocalization.mk'_eq_iff_eq_mul.mpr ?_).symm⟩⟩ exact (h x).2.symm variable (R) /-- The predicate `IsFraction` is "prelocal", in the sense that if it holds on `U` it holds on any open subset `V` of `U`. -/ def isFractionPrelocal : PrelocalPredicate (Localizations R) where pred {_} f := IsFraction f res := by rintro V U i f ⟨r, s, w⟩; exact ⟨r, s, fun x => w (i x)⟩ /-- We will define the structure sheaf as the subsheaf of all dependent functions in `Π x : U, Localizations R x` consisting of those functions which can locally be expressed as a ratio of (the images in the localization of) elements of `R`. Quoting Hartshorne: For an open set $U ⊆ Spec A$, we define $𝒪(U)$ to be the set of functions $s : U → ⨆_{𝔭 ∈ U} A_𝔭$, such that $s(𝔭) ∈ A_𝔭$ for each $𝔭$, and such that $s$ is locally a quotient of elements of $A$: to be precise, we require that for each $𝔭 ∈ U$, there is a neighborhood $V$ of $𝔭$, contained in $U$, and elements $a, f ∈ A$, such that for each $𝔮 ∈ V, f ∉ 𝔮$, and $s(𝔮) = a/f$ in $A_𝔮$. Now Hartshorne had the disadvantage of not knowing about dependent functions, so we replace his circumlocution about functions into a disjoint union with `Π x : U, Localizations x`. -/ def isLocallyFraction : LocalPredicate (Localizations R) := (isFractionPrelocal R).sheafify @[simp] theorem isLocallyFraction_pred {U : Opens (PrimeSpectrum.Top R)} (f : ∀ x : U, Localizations R x) : (isLocallyFraction R).pred f = ∀ x : U, ∃ (V : _) (_ : x.1 ∈ V) (i : V ⟶ U), ∃ r s : R, ∀ y : V, ¬s ∈ y.1.asIdeal ∧ f (i y : U) * algebraMap _ _ s = algebraMap _ _ r := rfl /-- The functions satisfying `isLocallyFraction` form a subring. -/ def sectionsSubring (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) : Subring (∀ x : U.unop, Localizations R x) where carrier := { f | (isLocallyFraction R).pred f } zero_mem' := by refine fun x => ⟨unop U, x.2, 𝟙 _, 0, 1, fun y => ⟨?_, ?_⟩⟩ · rw [← Ideal.ne_top_iff_one]; exact y.1.isPrime.1 · simp one_mem' := by refine fun x => ⟨unop U, x.2, 𝟙 _, 1, 1, fun y => ⟨?_, ?_⟩⟩ · rw [← Ideal.ne_top_iff_one]; exact y.1.isPrime.1 · simp add_mem' := by intro a b ha hb x rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩ rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * sb + rb * sa, sa * sb, ?_⟩ intro ⟨y, hy⟩ rcases wa (Opens.infLELeft _ _ ⟨y, hy⟩) with ⟨nma, wa⟩ rcases wb (Opens.infLERight _ _ ⟨y, hy⟩) with ⟨nmb, wb⟩ fconstructor · intro H; cases y.isPrime.mem_or_mem H <;> contradiction · simp only [Opens.apply_mk, Pi.add_apply, RingHom.map_mul, add_mul, RingHom.map_add] at wa wb ⊢ rw [← wa, ← wb] simp only [mul_assoc] congr 2 rw [mul_comm] neg_mem' := by intro a ha x rcases ha x with ⟨V, m, i, r, s, w⟩ refine ⟨V, m, i, -r, s, ?_⟩ intro y rcases w y with ⟨nm, w⟩ fconstructor · exact nm · simp only [RingHom.map_neg, Pi.neg_apply] rw [← w] simp only [neg_mul] mul_mem' := by intro a b ha hb x rcases ha x with ⟨Va, ma, ia, ra, sa, wa⟩ rcases hb x with ⟨Vb, mb, ib, rb, sb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ra * rb, sa * sb, ?_⟩ intro ⟨y, hy⟩ rcases wa (Opens.infLELeft _ _ ⟨y, hy⟩) with ⟨nma, wa⟩ rcases wb (Opens.infLERight _ _ ⟨y, hy⟩) with ⟨nmb, wb⟩ fconstructor · intro H; cases y.isPrime.mem_or_mem H <;> contradiction · simp only [Opens.apply_mk, Pi.mul_apply, RingHom.map_mul] at wa wb ⊢ rw [← wa, ← wb] simp only [mul_left_comm, mul_assoc, mul_comm] end StructureSheaf open StructureSheaf /-- The structure sheaf (valued in `Type`, not yet `CommRingCat`) is the subsheaf consisting of functions satisfying `isLocallyFraction`. -/ def structureSheafInType : Sheaf (Type u) (PrimeSpectrum.Top R) := subsheafToTypes (isLocallyFraction R) instance commRingStructureSheafInTypeObj (U : (Opens (PrimeSpectrum.Top R))ᵒᵖ) : CommRing ((structureSheafInType R).1.obj U) := (sectionsSubring R U).toCommRing open PrimeSpectrum /-- The structure presheaf, valued in `CommRingCat`, constructed by dressing up the `Type` valued structure presheaf. -/ @[simps obj_carrier] def structurePresheafInCommRing : Presheaf CommRingCat (PrimeSpectrum.Top R) where obj U := CommRingCat.of ((structureSheafInType R).1.obj U) map {_ _} i := CommRingCat.ofHom { toFun := (structureSheafInType R).1.map i map_zero' := rfl map_add' := fun _ _ => rfl map_one' := rfl map_mul' := fun _ _ => rfl } /-- Some glue, verifying that the structure presheaf valued in `CommRingCat` agrees with the `Type` valued structure presheaf. -/ def structurePresheafCompForget : structurePresheafInCommRing R ⋙ forget CommRingCat ≅ (structureSheafInType R).1 := NatIso.ofComponents fun _ => Iso.refl _ open TopCat.Presheaf /-- The structure sheaf on $Spec R$, valued in `CommRingCat`. This is provided as a bundled `SheafedSpace` as `Spec.SheafedSpace R` later. -/ def Spec.structureSheaf : Sheaf CommRingCat (PrimeSpectrum.Top R) := ⟨structurePresheafInCommRing R, (-- We check the sheaf condition under `forget CommRingCat`. isSheaf_iff_isSheaf_comp _ _).mpr (isSheaf_of_iso (structurePresheafCompForget R).symm (structureSheafInType R).cond)⟩ open Spec (structureSheaf) namespace StructureSheaf @[simp] theorem res_apply (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) (s : (structureSheaf R).1.obj (op U)) (x : V) : ((structureSheaf R).1.map i.op s).1 x = (s.1 (i x) :) := rfl /- Notation in this comment X = Spec R OX = structure sheaf In the following we construct an isomorphism between OX_p and R_p given any point p corresponding to a prime ideal in R. We do this via 8 steps: 1. def const (f g : R) (V) (hv : V ≤ D_g) : OX(V) [for api] 2. def toOpen (U) : R ⟶ OX(U) 3. [2] def toStalk (p : Spec R) : R ⟶ OX_p 4. [2] def toBasicOpen (f : R) : R_f ⟶ OX(D_f) 5. [3] def localizationToStalk (p : Spec R) : R_p ⟶ OX_p 6. def openToLocalization (U) (p) (hp : p ∈ U) : OX(U) ⟶ R_p 7. [6] def stalkToFiberRingHom (p : Spec R) : OX_p ⟶ R_p 8. [5,7] def stalkIso (p : Spec R) : OX_p ≅ R_p In the square brackets we list the dependencies of a construction on the previous steps. -/ /-- The section of `structureSheaf R` on an open `U` sending each `x ∈ U` to the element `f/g` in the localization of `R` at `x`. -/ def const (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) : (structureSheaf R).1.obj (op U) := ⟨fun x => IsLocalization.mk' _ f ⟨g, hu x x.2⟩, fun x => ⟨U, x.2, 𝟙 _, f, g, fun y => ⟨hu y y.2, IsLocalization.mk'_spec _ _ _⟩⟩⟩ @[simp] theorem const_apply (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) : (const R f g U hu).1 x = IsLocalization.mk' (Localization.AtPrime x.1.asIdeal) f ⟨g, hu x x.2⟩ := rfl theorem const_apply' (f g : R) (U : Opens (PrimeSpectrum.Top R)) (hu : ∀ x ∈ U, g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) (x : U) (hx : g ∈ (x : PrimeSpectrum.Top R).asIdeal.primeCompl) : (const R f g U hu).1 x = IsLocalization.mk' _ f ⟨g, hx⟩ := rfl theorem exists_const (U) (s : (structureSheaf R).1.obj (op U)) (x : PrimeSpectrum.Top R) (hx : x ∈ U) : ∃ (V : Opens (PrimeSpectrum.Top R)) (_ : x ∈ V) (i : V ⟶ U) (f g : R) (hg : _), const R f g V hg = (structureSheaf R).1.map i.op s := let ⟨V, hxV, iVU, f, g, hfg⟩ := s.2 ⟨x, hx⟩ ⟨V, hxV, iVU, f, g, fun y hyV => (hfg ⟨y, hyV⟩).1, Subtype.eq <| funext fun y => IsLocalization.mk'_eq_iff_eq_mul.2 <| Eq.symm <| (hfg y).2⟩ @[simp] theorem res_const (f g : R) (U hu V hv i) : (structureSheaf R).1.map i (const R f g U hu) = const R f g V hv := rfl theorem res_const' (f g : R) (V hv) : (structureSheaf R).1.map (homOfLE hv).op (const R f g (PrimeSpectrum.basicOpen g) fun _ => id) = const R f g V hv := rfl theorem const_zero (f : R) (U hu) : const R 0 f U hu = 0 := Subtype.eq <| funext fun x => IsLocalization.mk'_eq_iff_eq_mul.2 <| by rw [RingHom.map_zero] exact (mul_eq_zero_of_left rfl ((algebraMap R (Localizations R x)) _)).symm theorem const_self (f : R) (U hu) : const R f f U hu = 1 := Subtype.eq <| funext fun _ => IsLocalization.mk'_self _ _ theorem const_one (U) : (const R 1 1 U fun _ _ => Submonoid.one_mem _) = 1 := const_self R 1 U _ theorem const_add (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ + const R f₂ g₂ U hu₂ = const R (f₁ * g₂ + f₂ * g₁) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) := Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_add _ _ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ theorem const_mul (f₁ f₂ g₁ g₂ : R) (U hu₁ hu₂) : const R f₁ g₁ U hu₁ * const R f₂ g₂ U hu₂ = const R (f₁ * f₂) (g₁ * g₂) U fun x hx => Submonoid.mul_mem _ (hu₁ x hx) (hu₂ x hx) := Subtype.eq <| funext fun x => Eq.symm <| IsLocalization.mk'_mul _ f₁ f₂ ⟨g₁, hu₁ x x.2⟩ ⟨g₂, hu₂ x x.2⟩ theorem const_ext {f₁ f₂ g₁ g₂ : R} {U hu₁ hu₂} (h : f₁ * g₂ = f₂ * g₁) : const R f₁ g₁ U hu₁ = const R f₂ g₂ U hu₂ := Subtype.eq <| funext fun x => IsLocalization.mk'_eq_of_eq (by rw [mul_comm, Subtype.coe_mk, ← h, mul_comm, Subtype.coe_mk]) theorem const_congr {f₁ f₂ g₁ g₂ : R} {U hu} (hf : f₁ = f₂) (hg : g₁ = g₂) : const R f₁ g₁ U hu = const R f₂ g₂ U (hg ▸ hu) := by substs hf hg; rfl theorem const_mul_rev (f g : R) (U hu₁ hu₂) : const R f g U hu₁ * const R g f U hu₂ = 1 := by rw [const_mul, const_congr R rfl (mul_comm g f), const_self] theorem const_mul_cancel (f g₁ g₂ : R) (U hu₁ hu₂) : const R f g₁ U hu₁ * const R g₁ g₂ U hu₂ = const R f g₂ U hu₂ := by rw [const_mul, const_ext]; rw [mul_assoc] theorem const_mul_cancel' (f g₁ g₂ : R) (U hu₁ hu₂) : const R g₁ g₂ U hu₂ * const R f g₁ U hu₁ = const R f g₂ U hu₂ := by rw [mul_comm, const_mul_cancel] /-- The canonical ring homomorphism interpreting an element of `R` as a section of the structure sheaf. -/ def toOpen (U : Opens (PrimeSpectrum.Top R)) : CommRingCat.of R ⟶ (structureSheaf R).1.obj (op U) := CommRingCat.ofHom { toFun f := ⟨fun _ => algebraMap R _ f, fun x => ⟨U, x.2, 𝟙 _, f, 1, fun y => ⟨(Ideal.ne_top_iff_one _).1 y.1.2.1, by simp [RingHom.map_one, mul_one]⟩⟩⟩ map_one' := Subtype.eq <| funext fun _ => RingHom.map_one _ map_mul' _ _ := Subtype.eq <| funext fun _ => RingHom.map_mul _ _ _ map_zero' := Subtype.eq <| funext fun _ => RingHom.map_zero _ map_add' _ _ := Subtype.eq <| funext fun _ => RingHom.map_add _ _ _ } @[simp] theorem toOpen_res (U V : Opens (PrimeSpectrum.Top R)) (i : V ⟶ U) : toOpen R U ≫ (structureSheaf R).1.map i.op = toOpen R V := rfl @[simp] theorem toOpen_apply (U : Opens (PrimeSpectrum.Top R)) (f : R) (x : U) : (toOpen R U f).1 x = algebraMap _ _ f :=
rfl
Mathlib/AlgebraicGeometry/StructureSheaf.lean
393
394