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) 2020 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.IndicatorFunction import Mathlib.Data.Fintype.Order import Mathlib.MeasureTheory.Function.AEEqFun import Mathlib.MeasureTheory.Function.LpSeminorm.Defs import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.Sub /-! # Basic theorems about ℒp space -/ noncomputable section open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology ComplexConjugate variable {α ε ε' E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm ε] [ENorm ε'] namespace MeasureTheory section Lp section Top theorem MemLp.eLpNorm_lt_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) : eLpNorm f p μ < ∞ := hfp.2 @[deprecated (since := "2025-02-21")] alias Memℒp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top theorem MemLp.eLpNorm_ne_top [TopologicalSpace ε] {f : α → ε} (hfp : MemLp f p μ) : eLpNorm f p μ ≠ ∞ := ne_of_lt hfp.2 @[deprecated (since := "2025-02-21")] alias Memℒp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : α → ε} (hq0_lt : 0 < q) (hfq : eLpNorm' f q μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ q ∂μ < ∞ := by rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt] exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq) @[deprecated (since := "2025-01-17")] alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' := lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hfp : eLpNorm f p μ < ∞) : ∫⁻ a, ‖f a‖ₑ ^ p.toReal ∂μ < ∞ := by apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top · exact ENNReal.toReal_pos hp_ne_zero hp_ne_top · simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp @[deprecated (since := "2025-01-17")] alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top := lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : α → ε} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : eLpNorm f p μ < ∞ ↔ ∫⁻ a, (‖f a‖ₑ) ^ p.toReal ∂μ < ∞ := ⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by intro h have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top have : 0 < 1 / p.toReal := div_pos zero_lt_one hp' simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩ @[deprecated (since := "2025-02-04")] alias eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top end Top section Zero @[simp] theorem eLpNorm'_exponent_zero {f : α → ε} : eLpNorm' f 0 μ = 1 := by rw [eLpNorm', div_zero, ENNReal.rpow_zero] @[simp] theorem eLpNorm_exponent_zero {f : α → ε} : eLpNorm f 0 μ = 0 := by simp [eLpNorm] @[simp] theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace ε] {f : α → ε} : MemLp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [MemLp, eLpNorm_exponent_zero] @[deprecated (since := "2025-02-21")] alias memℒp_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable section ENormedAddMonoid variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε] @[simp] theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : α → ε) q μ = 0 := by simp [eLpNorm'_eq_lintegral_enorm, hp0_lt] @[simp] theorem eLpNorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : eLpNorm' (0 : α → ε) q μ = 0 := by rcases le_or_lt 0 q with hq0 | hq_neg · exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm) · simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hμ, hq_neg] @[simp] theorem eLpNormEssSup_zero : eLpNormEssSup (0 : α → ε) μ = 0 := by simp [eLpNormEssSup, ← bot_eq_zero', essSup_const_bot] @[simp] theorem eLpNorm_zero : eLpNorm (0 : α → ε) p μ = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero] rw [← Ne] at h0 simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top] @[simp] theorem eLpNorm_zero' : eLpNorm (fun _ : α => (0 : ε)) p μ = 0 := eLpNorm_zero @[simp] lemma MemLp.zero : MemLp (0 : α → ε) p μ := ⟨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_top⟩ @[simp] lemma MemLp.zero' : MemLp (fun _ : α => (0 : ε)) p μ := MemLp.zero @[deprecated (since := "2025-02-21")] alias Memℒp.zero' := MemLp.zero' @[deprecated (since := "2025-01-21")] alias zero_memℒp := MemLp.zero @[deprecated (since := "2025-01-21")] alias zero_mem_ℒp := MemLp.zero' variable [MeasurableSpace α] theorem eLpNorm'_measure_zero_of_pos {f : α → ε} (hq_pos : 0 < q) : eLpNorm' f q (0 : Measure α) = 0 := by simp [eLpNorm', hq_pos] theorem eLpNorm'_measure_zero_of_exponent_zero {f : α → ε} : eLpNorm' f 0 (0 : Measure α) = 1 := by simp [eLpNorm'] theorem eLpNorm'_measure_zero_of_neg {f : α → ε} (hq_neg : q < 0) : eLpNorm' f q (0 : Measure α) = ∞ := by simp [eLpNorm', hq_neg] end ENormedAddMonoid @[simp] theorem eLpNormEssSup_measure_zero {f : α → ε} : eLpNormEssSup f (0 : Measure α) = 0 := by simp [eLpNormEssSup] @[simp] theorem eLpNorm_measure_zero {f : α → ε} : eLpNorm f p (0 : Measure α) = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top] rw [← Ne] at h0 simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top] section ContinuousENorm variable {ε : Type*} [TopologicalSpace ε] [ContinuousENorm ε] @[simp] lemma memLp_measure_zero {f : α → ε} : MemLp f p (0 : Measure α) := by simp [MemLp] @[deprecated (since := "2025-02-21")] alias memℒp_measure_zero := memLp_measure_zero end ContinuousENorm end Zero section Neg @[simp] theorem eLpNorm'_neg (f : α → F) (q : ℝ) (μ : Measure α) : eLpNorm' (-f) q μ = eLpNorm' f q μ := by simp [eLpNorm'_eq_lintegral_enorm] @[simp] theorem eLpNorm_neg (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : eLpNorm (-f) p μ = eLpNorm f p μ := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top, eLpNormEssSup_eq_essSup_enorm] simp [eLpNorm_eq_eLpNorm' h0 h_top] lemma eLpNorm_sub_comm (f g : α → E) (p : ℝ≥0∞) (μ : Measure α) : eLpNorm (f - g) p μ = eLpNorm (g - f) p μ := by simp [← eLpNorm_neg (f := f - g)] theorem MemLp.neg {f : α → E} (hf : MemLp f p μ) : MemLp (-f) p μ := ⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩ @[deprecated (since := "2025-02-21")] alias Memℒp.neg := MemLp.neg theorem memLp_neg_iff {f : α → E} : MemLp (-f) p μ ↔ MemLp f p μ := ⟨fun h => neg_neg f ▸ h.neg, MemLp.neg⟩ @[deprecated (since := "2025-02-21")] alias memℒp_neg_iff := memLp_neg_iff end Neg section Const variable {ε' ε'' : Type*} [TopologicalSpace ε'] [ContinuousENorm ε'] [TopologicalSpace ε''] [ENormedAddMonoid ε''] theorem eLpNorm'_const (c : ε) (hq_pos : 0 < q) : eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by rw [eLpNorm'_eq_lintegral_enorm, lintegral_const, ENNReal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)] congr rw [← ENNReal.rpow_mul] suffices hq_cancel : q * (1 / q) = 1 by rw [hq_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel₀ (ne_of_lt hq_pos).symm] -- Generalising this to ENormedAddMonoid requires a case analysis whether ‖c‖ₑ = ⊤, -- and will happen in a future PR. theorem eLpNorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) : eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ * μ Set.univ ^ (1 / q) := by rw [eLpNorm'_eq_lintegral_enorm, lintegral_const, ENNReal.mul_rpow_of_ne_top _ (measure_ne_top μ Set.univ)] · congr rw [← ENNReal.rpow_mul] suffices hp_cancel : q * (1 / q) = 1 by rw [hp_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel₀ hq_ne_zero] · rw [Ne, ENNReal.rpow_eq_top_iff, not_or, not_and_or, not_and_or] simp [hc_ne_zero] theorem eLpNormEssSup_const (c : ε) (hμ : μ ≠ 0) : eLpNormEssSup (fun _ : α => c) μ = ‖c‖ₑ := by rw [eLpNormEssSup_eq_essSup_enorm, essSup_const _ hμ] theorem eLpNorm'_const_of_isProbabilityMeasure (c : ε) (hq_pos : 0 < q) [IsProbabilityMeasure μ] : eLpNorm' (fun _ : α => c) q μ = ‖c‖ₑ := by simp [eLpNorm'_const c hq_pos, measure_univ] theorem eLpNorm_const (c : ε) (h0 : p ≠ 0) (hμ : μ ≠ 0) : eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by by_cases h_top : p = ∞ · simp [h_top, eLpNormEssSup_const c hμ] simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top] theorem eLpNorm_const' (c : ε) (h0 : p ≠ 0) (h_top : p ≠ ∞) : eLpNorm (fun _ : α => c) p μ = ‖c‖ₑ * μ Set.univ ^ (1 / ENNReal.toReal p) := by simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm'_const, ENNReal.toReal_pos h0 h_top] -- NB. If ‖c‖ₑ = ∞ and μ is finite, this claim is false: the right has side is true, -- but the left hand side is false (as the norm is infinite). theorem eLpNorm_const_lt_top_iff_enorm {c : ε''} (hc' : ‖c‖ₑ ≠ ∞) {p : ℝ≥0∞} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : eLpNorm (fun _ : α ↦ c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := by have hp : 0 < p.toReal := ENNReal.toReal_pos hp_ne_zero hp_ne_top by_cases hμ : μ = 0 · simp only [hμ, Measure.coe_zero, Pi.zero_apply, or_true, ENNReal.zero_lt_top, eLpNorm_measure_zero] by_cases hc : c = 0 · simp only [hc, true_or, eq_self_iff_true, ENNReal.zero_lt_top, eLpNorm_zero'] rw [eLpNorm_const' c hp_ne_zero hp_ne_top] obtain hμ_top | hμ_ne_top := eq_or_ne (μ .univ) ∞ · simp [hc, hμ_top, hp] rw [ENNReal.mul_lt_top_iff] simpa [hμ, hc, hμ_ne_top, hμ_ne_top.lt_top, hc, hc'.lt_top] using ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_ne_top theorem eLpNorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : eLpNorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := eLpNorm_const_lt_top_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top theorem memLp_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) [IsFiniteMeasure μ] : MemLp (fun _ : α ↦ c) p μ := by refine ⟨aestronglyMeasurable_const, ?_⟩ by_cases h0 : p = 0 · simp [h0] by_cases hμ : μ = 0 · simp [hμ] rw [eLpNorm_const c h0 hμ] exact ENNReal.mul_lt_top hc.lt_top (ENNReal.rpow_lt_top_of_nonneg (by simp) (measure_ne_top μ Set.univ)) theorem memLp_const (c : E) [IsFiniteMeasure μ] : MemLp (fun _ : α => c) p μ := memLp_const_enorm enorm_ne_top @[deprecated (since := "2025-02-21")] alias memℒp_const := memLp_const theorem memLp_top_const_enorm {c : ε'} (hc : ‖c‖ₑ ≠ ⊤) : MemLp (fun _ : α ↦ c) ∞ μ := ⟨aestronglyMeasurable_const, by by_cases h : μ = 0 <;> simp [eLpNorm_const _, h, hc.lt_top]⟩ theorem memLp_top_const (c : E) : MemLp (fun _ : α => c) ∞ μ := memLp_top_const_enorm enorm_ne_top @[deprecated (since := "2025-02-21")] alias memℒp_top_const := memLp_top_const theorem memLp_const_iff_enorm {p : ℝ≥0∞} {c : ε''} (hc : ‖c‖ₑ ≠ ⊤) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : MemLp (fun _ : α ↦ c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by simp_all [MemLp, aestronglyMeasurable_const, eLpNorm_const_lt_top_iff_enorm hc hp_ne_zero hp_ne_top] theorem memLp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : MemLp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := memLp_const_iff_enorm enorm_ne_top hp_ne_zero hp_ne_top @[deprecated (since := "2025-02-21")] alias memℒp_const_iff := memLp_const_iff end Const variable {f : α → F} lemma eLpNorm'_mono_enorm_ae {f : α → ε} {g : α → ε'} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) : eLpNorm' f q μ ≤ eLpNorm' g q μ := by simp only [eLpNorm'_eq_lintegral_enorm] gcongr ?_ ^ (1/q) refine lintegral_mono_ae (h.mono fun x hx => ?_) gcongr lemma eLpNorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : eLpNorm' f q μ ≤ eLpNorm' g q μ := by simp only [eLpNorm'_eq_lintegral_enorm] gcongr ?_ ^ (1/q) refine lintegral_mono_ae (h.mono fun x hx => ?_) dsimp [enorm] gcongr theorem eLpNorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : eLpNorm' f q μ ≤ eLpNorm' g q μ := eLpNorm'_mono_enorm_ae hq (by simpa only [enorm_le_iff_norm_le] using h) theorem eLpNorm'_congr_enorm_ae {f g : α → ε} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ = ‖g x‖ₑ) : eLpNorm' f q μ = eLpNorm' g q μ := by have : (‖f ·‖ₑ ^ q) =ᵐ[μ] (‖g ·‖ₑ ^ q) := hfg.mono fun x hx ↦ by simp [hx] simp only [eLpNorm'_eq_lintegral_enorm, lintegral_congr_ae this] theorem eLpNorm'_congr_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) : eLpNorm' f q μ = eLpNorm' g q μ := by have : (‖f ·‖ₑ ^ q) =ᵐ[μ] (‖g ·‖ₑ ^ q) := hfg.mono fun x hx ↦ by simp [enorm, hx] simp only [eLpNorm'_eq_lintegral_enorm, lintegral_congr_ae this] theorem eLpNorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) : eLpNorm' f q μ = eLpNorm' g q μ := eLpNorm'_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx theorem eLpNorm'_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) : eLpNorm' f q μ = eLpNorm' g q μ := eLpNorm'_congr_enorm_ae (hfg.fun_comp _) theorem eLpNormEssSup_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) : eLpNormEssSup f μ = eLpNormEssSup g μ := essSup_congr_ae (hfg.fun_comp enorm) theorem eLpNormEssSup_mono_enorm_ae {f g : α → ε} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) : eLpNormEssSup f μ ≤ eLpNormEssSup g μ := essSup_mono_ae <| hfg theorem eLpNormEssSup_mono_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : eLpNormEssSup f μ ≤ eLpNormEssSup g μ := essSup_mono_ae <| hfg.mono fun _x hx => ENNReal.coe_le_coe.mpr hx theorem eLpNorm_mono_enorm_ae {f : α → ε} {g : α → ε'} (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) : eLpNorm f p μ ≤ eLpNorm g p μ := by simp only [eLpNorm] split_ifs · exact le_rfl · exact essSup_mono_ae h · exact eLpNorm'_mono_enorm_ae ENNReal.toReal_nonneg h theorem eLpNorm_mono_nnnorm_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : eLpNorm f p μ ≤ eLpNorm g p μ := by simp only [eLpNorm] split_ifs · exact le_rfl · exact essSup_mono_ae (h.mono fun x hx => ENNReal.coe_le_coe.mpr hx) · exact eLpNorm'_mono_nnnorm_ae ENNReal.toReal_nonneg h theorem eLpNorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_enorm_ae (by simpa only [enorm_le_iff_norm_le] using h) theorem eLpNorm_mono_ae' {ε' : Type*} [ENorm ε'] {f : α → ε} {g : α → ε'} (h : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖g x‖ₑ) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_enorm_ae (by simpa only [enorm_le_iff_norm_le] using h) theorem eLpNorm_mono_ae_real {f : α → F} {g : α → ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_ae <| h.mono fun _x hx => hx.trans ((le_abs_self _).trans (Real.norm_eq_abs _).symm.le) theorem eLpNorm_mono_enorm {f : α → ε} {g : α → ε'} (h : ∀ x, ‖f x‖ₑ ≤ ‖g x‖ₑ) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_enorm_ae (Eventually.of_forall h) theorem eLpNorm_mono_nnnorm {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖₊ ≤ ‖g x‖₊) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_nnnorm_ae (Eventually.of_forall h) theorem eLpNorm_mono {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖ ≤ ‖g x‖) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_ae (Eventually.of_forall h) theorem eLpNorm_mono_real {f : α → F} {g : α → ℝ} (h : ∀ x, ‖f x‖ ≤ g x) : eLpNorm f p μ ≤ eLpNorm g p μ := eLpNorm_mono_ae_real (Eventually.of_forall h) theorem eLpNormEssSup_le_of_ae_enorm_bound {f : α → ε} {C : ℝ≥0∞} (hfC : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ C) : eLpNormEssSup f μ ≤ C := essSup_le_of_ae_le C hfC theorem eLpNormEssSup_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : eLpNormEssSup f μ ≤ C := essSup_le_of_ae_le (C : ℝ≥0∞) <| hfC.mono fun _x hx => ENNReal.coe_le_coe.mpr hx theorem eLpNormEssSup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : eLpNormEssSup f μ ≤ ENNReal.ofReal C := eLpNormEssSup_le_of_ae_nnnorm_bound <| hfC.mono fun _x hx => hx.trans C.le_coe_toNNReal theorem eLpNormEssSup_lt_top_of_ae_enorm_bound {f : α → ε} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ C) : eLpNormEssSup f μ < ∞ := (eLpNormEssSup_le_of_ae_enorm_bound hfC).trans_lt ENNReal.coe_lt_top theorem eLpNormEssSup_lt_top_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : eLpNormEssSup f μ < ∞ := (eLpNormEssSup_le_of_ae_nnnorm_bound hfC).trans_lt ENNReal.coe_lt_top theorem eLpNormEssSup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : eLpNormEssSup f μ < ∞ := (eLpNormEssSup_le_of_ae_bound hfC).trans_lt ENNReal.ofReal_lt_top theorem eLpNorm_le_of_ae_enorm_bound {ε} [TopologicalSpace ε] [ENormedAddMonoid ε] {f : α → ε} {C : ℝ≥0∞} (hfC : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ C) : eLpNorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by rcases eq_zero_or_neZero μ with rfl | hμ · simp by_cases hp : p = 0 · simp [hp] have : ∀ᵐ x ∂μ, ‖f x‖ₑ ≤ ‖C‖ₑ := hfC.mono fun x hx ↦ hx.trans (Preorder.le_refl C) refine (eLpNorm_mono_enorm_ae this).trans_eq ?_ rw [eLpNorm_const _ hp (NeZero.ne μ), one_div, enorm_eq_self, smul_eq_mul] theorem eLpNorm_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : eLpNorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by rcases eq_zero_or_neZero μ with rfl | hμ · simp by_cases hp : p = 0 · simp [hp] have : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖(C : ℝ)‖₊ := hfC.mono fun x hx => hx.trans_eq C.nnnorm_eq.symm refine (eLpNorm_mono_ae this).trans_eq ?_ rw [eLpNorm_const _ hp (NeZero.ne μ), C.enorm_eq, one_div, ENNReal.smul_def, smul_eq_mul] theorem eLpNorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : eLpNorm f p μ ≤ μ Set.univ ^ p.toReal⁻¹ * ENNReal.ofReal C := by rw [← mul_comm] exact eLpNorm_le_of_ae_nnnorm_bound (hfC.mono fun x hx => hx.trans C.le_coe_toNNReal) theorem eLpNorm_congr_enorm_ae {f : α → ε} {g : α → ε'} (hfg : ∀ᵐ x ∂μ, ‖f x‖ₑ = ‖g x‖ₑ) : eLpNorm f p μ = eLpNorm g p μ := le_antisymm (eLpNorm_mono_enorm_ae <| EventuallyEq.le hfg) (eLpNorm_mono_enorm_ae <| (EventuallyEq.symm hfg).le) theorem eLpNorm_congr_nnnorm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) : eLpNorm f p μ = eLpNorm g p μ := le_antisymm (eLpNorm_mono_nnnorm_ae <| EventuallyEq.le hfg) (eLpNorm_mono_nnnorm_ae <| (EventuallyEq.symm hfg).le) theorem eLpNorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) : eLpNorm f p μ = eLpNorm g p μ := eLpNorm_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx open scoped symmDiff in theorem eLpNorm_indicator_sub_indicator (s t : Set α) (f : α → E) : eLpNorm (s.indicator f - t.indicator f) p μ = eLpNorm ((s ∆ t).indicator f) p μ := eLpNorm_congr_norm_ae <| ae_of_all _ fun x ↦ by simp [Set.apply_indicator_symmDiff norm_neg] @[simp] theorem eLpNorm'_norm {f : α → F} : eLpNorm' (fun a => ‖f a‖) q μ = eLpNorm' f q μ := by simp [eLpNorm'_eq_lintegral_enorm] @[simp] theorem eLpNorm'_enorm {f : α → ε} : eLpNorm' (fun a => ‖f a‖ₑ) q μ = eLpNorm' f q μ := by simp [eLpNorm'_eq_lintegral_enorm] @[simp] theorem eLpNorm_norm (f : α → F) : eLpNorm (fun x => ‖f x‖) p μ = eLpNorm f p μ := eLpNorm_congr_norm_ae <| Eventually.of_forall fun _ => norm_norm _ @[simp] theorem eLpNorm_enorm (f : α → ε) : eLpNorm (fun x ↦ ‖f x‖ₑ) p μ = eLpNorm f p μ := eLpNorm_congr_enorm_ae <| Eventually.of_forall fun _ => enorm_enorm _ theorem eLpNorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) : eLpNorm' (fun x => ‖f x‖ ^ q) p μ = eLpNorm' f (p * q) μ ^ q := by simp_rw [eLpNorm', ← ENNReal.rpow_mul, ← one_div_mul_one_div, one_div, mul_assoc, inv_mul_cancel₀ hq_pos.ne.symm, mul_one, ← ofReal_norm_eq_enorm, Real.norm_eq_abs, abs_eq_self.mpr (Real.rpow_nonneg (norm_nonneg _) _), mul_comm p, ← ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ENNReal.rpow_mul] theorem eLpNorm_norm_rpow (f : α → F) (hq_pos : 0 < q) : eLpNorm (fun x => ‖f x‖ ^ q) p μ = eLpNorm f (p * ENNReal.ofReal q) μ ^ q := by by_cases h0 : p = 0 · simp [h0, ENNReal.zero_rpow_of_pos hq_pos] by_cases hp_top : p = ∞ · simp only [hp_top, eLpNorm_exponent_top, ENNReal.top_mul', hq_pos.not_le, ENNReal.ofReal_eq_zero, if_false, eLpNorm_exponent_top, eLpNormEssSup_eq_essSup_enorm] have h_rpow : essSup (‖‖f ·‖ ^ q‖ₑ) μ = essSup (‖f ·‖ₑ ^ q) μ := by congr ext1 x conv_rhs => rw [← enorm_norm] rw [← Real.enorm_rpow_of_nonneg (norm_nonneg _) hq_pos.le] rw [h_rpow] have h_rpow_mono := ENNReal.strictMono_rpow_of_pos hq_pos have h_rpow_surj := (ENNReal.rpow_left_bijective hq_pos.ne.symm).2 let iso := h_rpow_mono.orderIsoOfSurjective _ h_rpow_surj exact (iso.essSup_apply (fun x => ‖f x‖ₑ) μ).symm rw [eLpNorm_eq_eLpNorm' h0 hp_top, eLpNorm_eq_eLpNorm' _ _] swap · refine mul_ne_zero h0 ?_ rwa [Ne, ENNReal.ofReal_eq_zero, not_le] swap; · exact ENNReal.mul_ne_top hp_top ENNReal.ofReal_ne_top rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal hq_pos.le] exact eLpNorm'_norm_rpow f p.toReal q hq_pos theorem eLpNorm_congr_ae {f g : α → ε} (hfg : f =ᵐ[μ] g) : eLpNorm f p μ = eLpNorm g p μ := eLpNorm_congr_enorm_ae <| hfg.mono fun _x hx => hx ▸ rfl theorem memLp_congr_ae [TopologicalSpace ε] {f g : α → ε} (hfg : f =ᵐ[μ] g) : MemLp f p μ ↔ MemLp g p μ := by simp only [MemLp, eLpNorm_congr_ae hfg, aestronglyMeasurable_congr hfg] @[deprecated (since := "2025-02-21")] alias memℒp_congr_ae := memLp_congr_ae theorem MemLp.ae_eq [TopologicalSpace ε] {f g : α → ε} (hfg : f =ᵐ[μ] g) (hf_Lp : MemLp f p μ) : MemLp g p μ := (memLp_congr_ae hfg).1 hf_Lp @[deprecated (since := "2025-02-21")] alias Memℒp.ae_eq := MemLp.ae_eq theorem MemLp.of_le {f : α → E} {g : α → F} (hg : MemLp g p μ) (hf : AEStronglyMeasurable f μ) (hfg : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : MemLp f p μ := ⟨hf, (eLpNorm_mono_ae hfg).trans_lt hg.eLpNorm_lt_top⟩ @[deprecated (since := "2025-02-21")] alias Memℒp.of_le := MemLp.of_le alias MemLp.mono := MemLp.of_le @[deprecated (since := "2025-02-21")] alias Memℒp.mono := MemLp.mono theorem MemLp.mono' {f : α → E} {g : α → ℝ} (hg : MemLp g p μ) (hf : AEStronglyMeasurable f μ) (h : ∀ᵐ a ∂μ, ‖f a‖ ≤ g a) : MemLp f p μ := hg.mono hf <| h.mono fun _x hx => le_trans hx (le_abs_self _) @[deprecated (since := "2025-02-21")] alias Memℒp.mono' := MemLp.mono' theorem MemLp.congr_norm {f : α → E} {g : α → F} (hf : MemLp f p μ) (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : MemLp g p μ := hf.mono hg <| EventuallyEq.le <| EventuallyEq.symm h @[deprecated (since := "2025-02-21")] alias Memℒp.congr_norm := MemLp.congr_norm theorem memLp_congr_norm {f : α → E} {g : α → F} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : MemLp f p μ ↔ MemLp g p μ := ⟨fun h2f => h2f.congr_norm hg h, fun h2g => h2g.congr_norm hf <| EventuallyEq.symm h⟩ @[deprecated (since := "2025-02-21")] alias memℒp_congr_norm := memLp_congr_norm theorem memLp_top_of_bound {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : MemLp f ∞ μ := ⟨hf, by rw [eLpNorm_exponent_top] exact eLpNormEssSup_lt_top_of_ae_bound hfC⟩ @[deprecated (since := "2025-02-21")] alias memℒp_top_of_bound := memLp_top_of_bound theorem MemLp.of_bound [IsFiniteMeasure μ] {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : MemLp f p μ := (memLp_const C).of_le hf (hfC.mono fun _x hx => le_trans hx (le_abs_self _)) @[deprecated (since := "2025-02-21")] alias Memℒp.of_bound := MemLp.of_bound theorem memLp_of_bounded [IsFiniteMeasure μ] {a b : ℝ} {f : α → ℝ} (h : ∀ᵐ x ∂μ, f x ∈ Set.Icc a b) (hX : AEStronglyMeasurable f μ) (p : ENNReal) : MemLp f p μ := have ha : ∀ᵐ x ∂μ, a ≤ f x := h.mono fun ω h => h.1 have hb : ∀ᵐ x ∂μ, f x ≤ b := h.mono fun ω h => h.2 (memLp_const (max |a| |b|)).mono' hX (by filter_upwards [ha, hb] with x using abs_le_max_abs_abs) @[deprecated (since := "2025-02-21")] alias memℒp_of_bounded := memLp_of_bounded @[gcongr, mono] theorem eLpNorm'_mono_measure (f : α → ε) (hμν : ν ≤ μ) (hq : 0 ≤ q) : eLpNorm' f q ν ≤ eLpNorm' f q μ := by simp_rw [eLpNorm'] gcongr exact lintegral_mono' hμν le_rfl @[gcongr, mono] theorem eLpNormEssSup_mono_measure (f : α → ε) (hμν : ν ≪ μ) : eLpNormEssSup f ν ≤ eLpNormEssSup f μ := by simp_rw [eLpNormEssSup] exact essSup_mono_measure hμν @[gcongr, mono] theorem eLpNorm_mono_measure (f : α → ε) (hμν : ν ≤ μ) : eLpNorm f p ν ≤ eLpNorm f p μ := by by_cases hp0 : p = 0 · simp [hp0] by_cases hp_top : p = ∞ · simp [hp_top, eLpNormEssSup_mono_measure f (Measure.absolutelyContinuous_of_le hμν)] simp_rw [eLpNorm_eq_eLpNorm' hp0 hp_top] exact eLpNorm'_mono_measure f hμν ENNReal.toReal_nonneg theorem MemLp.mono_measure [TopologicalSpace ε] {f : α → ε} (hμν : ν ≤ μ) (hf : MemLp f p μ) : MemLp f p ν := ⟨hf.1.mono_measure hμν, (eLpNorm_mono_measure f hμν).trans_lt hf.2⟩ @[deprecated (since := "2025-02-21")] alias Memℒp.mono_measure := MemLp.mono_measure section Indicator variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε] {c : ε} {hf : AEStronglyMeasurable f μ} {s : Set α} lemma eLpNorm_indicator_eq_eLpNorm_restrict {f : α → ε} {s : Set α} (hs : MeasurableSet s) : eLpNorm (s.indicator f) p μ = eLpNorm f p (μ.restrict s) := by by_cases hp_zero : p = 0 · simp only [hp_zero, eLpNorm_exponent_zero] by_cases hp_top : p = ∞ · simp_rw [hp_top, eLpNorm_exponent_top, eLpNormEssSup_eq_essSup_enorm, enorm_indicator_eq_indicator_enorm, ENNReal.essSup_indicator_eq_essSup_restrict hs] simp_rw [eLpNorm_eq_lintegral_rpow_enorm hp_zero hp_top] suffices (∫⁻ x, (‖s.indicator f x‖ₑ) ^ p.toReal ∂μ) = ∫⁻ x in s, ‖f x‖ₑ ^ p.toReal ∂μ by rw [this] rw [← lintegral_indicator hs] congr simp_rw [enorm_indicator_eq_indicator_enorm] rw [eq_comm, ← Function.comp_def (fun x : ℝ≥0∞ => x ^ p.toReal), Set.indicator_comp_of_zero, Function.comp_def] simp [ENNReal.toReal_pos hp_zero hp_top] @[deprecated (since := "2025-01-07")] alias eLpNorm_indicator_eq_restrict := eLpNorm_indicator_eq_eLpNorm_restrict lemma eLpNormEssSup_indicator_eq_eLpNormEssSup_restrict (hs : MeasurableSet s) : eLpNormEssSup (s.indicator f) μ = eLpNormEssSup f (μ.restrict s) := by simp_rw [← eLpNorm_exponent_top, eLpNorm_indicator_eq_eLpNorm_restrict hs] lemma eLpNorm_restrict_le (f : α → ε') (p : ℝ≥0∞) (μ : Measure α) (s : Set α) : eLpNorm f p (μ.restrict s) ≤ eLpNorm f p μ := eLpNorm_mono_measure f Measure.restrict_le_self lemma eLpNorm_indicator_le (f : α → ε) : eLpNorm (s.indicator f) p μ ≤ eLpNorm f p μ := by refine eLpNorm_mono_ae' <| .of_forall fun x ↦ ?_ rw [enorm_indicator_eq_indicator_enorm] exact s.indicator_le_self _ x lemma eLpNormEssSup_indicator_le (s : Set α) (f : α → ε) : eLpNormEssSup (s.indicator f) μ ≤ eLpNormEssSup f μ := by refine essSup_mono_ae (Eventually.of_forall fun x => ?_) simp_rw [enorm_indicator_eq_indicator_enorm] exact Set.indicator_le_self s _ x lemma eLpNormEssSup_indicator_const_le (s : Set α) (c : ε) : eLpNormEssSup (s.indicator fun _ : α => c) μ ≤ ‖c‖ₑ := by by_cases hμ0 : μ = 0 · rw [hμ0, eLpNormEssSup_measure_zero] exact zero_le _ · exact (eLpNormEssSup_indicator_le s fun _ => c).trans (eLpNormEssSup_const c hμ0).le lemma eLpNormEssSup_indicator_const_eq (s : Set α) (c : ε) (hμs : μ s ≠ 0) : eLpNormEssSup (s.indicator fun _ : α => c) μ = ‖c‖ₑ := by refine le_antisymm (eLpNormEssSup_indicator_const_le s c) ?_ by_contra! h have h' := ae_iff.mp (ae_lt_of_essSup_lt h) push_neg at h' refine hμs (measure_mono_null (fun x hx_mem => ?_) h') rw [Set.mem_setOf_eq, Set.indicator_of_mem hx_mem] lemma eLpNorm_indicator_const₀ (hs : NullMeasurableSet s μ) (hp : p ≠ 0) (hp_top : p ≠ ∞) : eLpNorm (s.indicator fun _ => c) p μ = ‖c‖ₑ * μ s ^ (1 / p.toReal) := have hp_pos : 0 < p.toReal := ENNReal.toReal_pos hp hp_top calc eLpNorm (s.indicator fun _ => c) p μ = (∫⁻ x, (‖(s.indicator fun _ ↦ c) x‖ₑ ^ p.toReal) ∂μ) ^ (1 / p.toReal) := eLpNorm_eq_lintegral_rpow_enorm hp hp_top _ = (∫⁻ x, (s.indicator fun _ ↦ ‖c‖ₑ ^ p.toReal) x ∂μ) ^ (1 / p.toReal) := by congr 2 refine (Set.comp_indicator_const c (fun x ↦ (‖x‖ₑ) ^ p.toReal) ?_) simp [hp_pos] _ = ‖c‖ₑ * μ s ^ (1 / p.toReal) := by rw [lintegral_indicator_const₀ hs, ENNReal.mul_rpow_of_nonneg, ← ENNReal.rpow_mul, mul_one_div_cancel hp_pos.ne', ENNReal.rpow_one] positivity lemma eLpNorm_indicator_const (hs : MeasurableSet s) (hp : p ≠ 0) (hp_top : p ≠ ∞) : eLpNorm (s.indicator fun _ => c) p μ = ‖c‖ₑ * μ s ^ (1 / p.toReal) := eLpNorm_indicator_const₀ hs.nullMeasurableSet hp hp_top lemma eLpNorm_indicator_const' (hs : MeasurableSet s) (hμs : μ s ≠ 0) (hp : p ≠ 0) : eLpNorm (s.indicator fun _ => c) p μ = ‖c‖ₑ * μ s ^ (1 / p.toReal) := by by_cases hp_top : p = ∞ · simp [hp_top, eLpNormEssSup_indicator_const_eq s c hμs] · exact eLpNorm_indicator_const hs hp hp_top variable (c) in lemma eLpNorm_indicator_const_le (p : ℝ≥0∞) : eLpNorm (s.indicator fun _ => c) p μ ≤ ‖c‖ₑ * μ s ^ (1 / p.toReal) := by obtain rfl | hp := eq_or_ne p 0 · simp only [eLpNorm_exponent_zero, zero_le'] obtain rfl | h'p := eq_or_ne p ∞ · simp only [eLpNorm_exponent_top, ENNReal.toReal_top, _root_.div_zero, ENNReal.rpow_zero, mul_one] exact eLpNormEssSup_indicator_const_le _ _ let t := toMeasurable μ s calc eLpNorm (s.indicator fun _ => c) p μ ≤ eLpNorm (t.indicator fun _ ↦ c) p μ := eLpNorm_mono_enorm (enorm_indicator_le_of_subset (subset_toMeasurable _ _) _) _ = ‖c‖ₑ * μ t ^ (1 / p.toReal) := eLpNorm_indicator_const (measurableSet_toMeasurable ..) hp h'p _ = ‖c‖ₑ * μ s ^ (1 / p.toReal) := by rw [measure_toMeasurable] lemma MemLp.indicator {f : α → ε} (hs : MeasurableSet s) (hf : MemLp f p μ) : MemLp (s.indicator f) p μ := ⟨hf.aestronglyMeasurable.indicator hs, lt_of_le_of_lt (eLpNorm_indicator_le f) hf.eLpNorm_lt_top⟩ @[deprecated (since := "2025-02-21")] alias Memℒp.indicator := MemLp.indicator lemma memLp_indicator_iff_restrict {f : α → ε} (hs : MeasurableSet s) : MemLp (s.indicator f) p μ ↔ MemLp f p (μ.restrict s) := by simp [MemLp, aestronglyMeasurable_indicator_iff hs, eLpNorm_indicator_eq_eLpNorm_restrict hs] @[deprecated (since := "2025-02-21")] alias memℒp_indicator_iff_restrict := memLp_indicator_iff_restrict lemma memLp_indicator_const (p : ℝ≥0∞) (hs : MeasurableSet s) (c : E) (hμsc : c = 0 ∨ μ s ≠ ∞) : MemLp (s.indicator fun _ => c) p μ := by rw [memLp_indicator_iff_restrict hs] obtain rfl | hμ := hμsc · exact MemLp.zero · have := Fact.mk hμ.lt_top apply memLp_const @[deprecated (since := "2025-02-21")] alias memℒp_indicator_const := memLp_indicator_const lemma eLpNormEssSup_piecewise (f g : α → ε) [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : eLpNormEssSup (Set.piecewise s f g) μ = max (eLpNormEssSup f (μ.restrict s)) (eLpNormEssSup g (μ.restrict sᶜ)) := by simp only [eLpNormEssSup, ← ENNReal.essSup_piecewise hs] congr with x by_cases hx : x ∈ s <;> simp [hx] lemma eLpNorm_top_piecewise (f g : α → ε) [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : eLpNorm (Set.piecewise s f g) ∞ μ = max (eLpNorm f ∞ (μ.restrict s)) (eLpNorm g ∞ (μ.restrict sᶜ)) := eLpNormEssSup_piecewise f g hs protected lemma MemLp.piecewise {f : α → ε} [DecidablePred (· ∈ s)] {g} (hs : MeasurableSet s) (hf : MemLp f p (μ.restrict s)) (hg : MemLp g p (μ.restrict sᶜ)) : MemLp (s.piecewise f g) p μ := by by_cases hp_zero : p = 0 · simp only [hp_zero, memLp_zero_iff_aestronglyMeasurable] exact AEStronglyMeasurable.piecewise hs hf.1 hg.1 refine ⟨AEStronglyMeasurable.piecewise hs hf.1 hg.1, ?_⟩ obtain rfl | hp_top := eq_or_ne p ∞ · rw [eLpNorm_top_piecewise f g hs] exact max_lt hf.2 hg.2 rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top hp_zero hp_top, ← lintegral_add_compl _ hs, ENNReal.add_lt_top] constructor · have h : ∀ᵐ x ∂μ, x ∈ s → ‖Set.piecewise s f g x‖ₑ ^ p.toReal = ‖f x‖ₑ ^ p.toReal := by filter_upwards with a ha using by simp [ha] rw [setLIntegral_congr_fun hs h] exact lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_zero hp_top hf.2 · have h : ∀ᵐ x ∂μ, x ∈ sᶜ → ‖Set.piecewise s f g x‖ₑ ^ p.toReal = ‖g x‖ₑ ^ p.toReal := by filter_upwards with a ha have ha' : a ∉ s := ha simp [ha'] rw [setLIntegral_congr_fun hs.compl h] exact lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_zero hp_top hg.2 @[deprecated (since := "2025-02-21")] alias Memℒp.piecewise := MemLp.piecewise end Indicator section ENormedAddMonoid variable {ε : Type*} [TopologicalSpace ε] [ENormedAddMonoid ε] /-- For a function `f` with support in `s`, the Lᵖ norms of `f` with respect to `μ` and `μ.restrict s` are the same. -/ theorem eLpNorm_restrict_eq_of_support_subset {s : Set α} {f : α → ε} (hsf : f.support ⊆ s) : eLpNorm f p (μ.restrict s) = eLpNorm f p μ := by by_cases hp0 : p = 0 · simp [hp0] by_cases hp_top : p = ∞ · simp only [hp_top, eLpNorm_exponent_top, eLpNormEssSup_eq_essSup_enorm] exact ENNReal.essSup_restrict_eq_of_support_subset fun x hx ↦ hsf <| enorm_ne_zero.1 hx · simp_rw [eLpNorm_eq_eLpNorm' hp0 hp_top, eLpNorm'_eq_lintegral_enorm] congr 1 apply setLIntegral_eq_of_support_subset have : ¬(p.toReal ≤ 0) := by simpa only [not_le] using ENNReal.toReal_pos hp0 hp_top simpa [this] using hsf end ENormedAddMonoid theorem MemLp.restrict [TopologicalSpace ε] (s : Set α) {f : α → ε} (hf : MemLp f p μ) : MemLp f p (μ.restrict s) := hf.mono_measure Measure.restrict_le_self @[deprecated (since := "2025-02-21")] alias Memℒp.restrict := MemLp.restrict theorem eLpNorm'_smul_measure {p : ℝ} (hp : 0 ≤ p) {f : α → ε} (c : ℝ≥0∞) : eLpNorm' f p (c • μ) = c ^ (1 / p) * eLpNorm' f p μ := by simp [eLpNorm', ENNReal.mul_rpow_of_nonneg, hp] section SMul variable {R : Type*} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} @[simp] lemma eLpNormEssSup_smul_measure (hc : c ≠ 0) (f : α → ε) : eLpNormEssSup f (c • μ) = eLpNormEssSup f μ := by simp_rw [eLpNormEssSup]
exact essSup_smul_measure hc _ end SMul
Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean
840
842
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Analysis.InnerProductSpace.Convex import Mathlib.Analysis.SpecialFunctions.Complex.Arg /-! # Rays in the complex numbers This file links the definition `SameRay ℝ x y` with the equality of arguments of complex numbers, the usual way this is considered. ## Main statements * `Complex.sameRay_iff` : Two complex numbers are on the same ray iff one of them is zero, or they have the same argument. * `Complex.abs_add_eq/Complex.abs_sub_eq`: If two non zero complex numbers have the same argument, then the triangle inequality is an equality. -/ variable {x y : ℂ} namespace Complex theorem sameRay_iff : SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := by rcases eq_or_ne x 0 with (rfl | hx)
· simp rcases eq_or_ne y 0 with (rfl | hy) · simp simp only [hx, hy, sameRay_iff_norm_smul_eq, arg_eq_arg_iff hx hy] field_simp [hx, hy] rw [mul_comm, eq_comm] theorem sameRay_iff_arg_div_eq_zero : SameRay ℝ x y ↔ arg (x / y) = 0 := by
Mathlib/Analysis/Complex/Arg.lean
31
38
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Reid Barton, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq /-! # Products in the over category Shows that products in the over category can be derived from wide pullbacks in the base category. The main result is `over_product_of_widePullback`, which says that if `C` has `J`-indexed wide pullbacks, then `Over B` has `J`-indexed products. Note that the binary case is done separately to ensure defeqs with the pullback in the base category. ## TODO * Generalise from arbitrary products to arbitrary limits. This is done in Toric. * Dualise to get the `Under X` results. -/ universe w v u -- morphism levels before object levels. See note [category_theory universes]. open CategoryTheory CategoryTheory.Limits variable {J : Type w} variable {C : Type u} [Category.{v} C] variable {X Y Z : C} /-! ### Binary products In this section we construct binary products in `Over X` and binary coproducts in `Under X` explicitly as the pullbacks and pushouts of binary (co)fans in the base category. For `Over X`, one could construct these binary products from the general theory of arbitrary products from the next section, ie ``` (Cones.postcomposeEquivalence (diagramIsoCospan _).symm).trans (Over.ConstructProducts.conesEquiv _ (pair (Over.mk f) (Over.mk g))) ``` but this gives worse defeqs. For `Under X`, there is currently no general theory of arbitrary coproducts. -/ namespace CategoryTheory.Limits section Over variable {f : Y ⟶ X} {g : Z ⟶ X} /-- Pullback cones to `X` are the same thing as binary fans in `Over X`. -/ @[simps] def pullbackConeEquivBinaryFan : PullbackCone f g ≌ BinaryFan (Over.mk f) (.mk g) where functor.obj c := .mk (Over.homMk (U := .mk (c.fst ≫ f)) (V := .mk f) c.fst rfl) (Over.homMk (U := .mk (c.fst ≫ f)) (V := .mk g) c.snd c.condition.symm) functor.map {c₁ c₂} a := { hom := Over.homMk a.hom, w := by rintro (_|_) <;> aesop_cat } inverse.obj c := PullbackCone.mk c.fst.left c.snd.left (c.fst.w.trans c.snd.w.symm) inverse.map {c₁ c₂} a := { hom := a.hom.left w := by rintro (_|_|_) <;> simp [← Over.comp_left_assoc, ← Over.comp_left] } unitIso := NatIso.ofComponents (fun c ↦ c.eta) (by intros; ext; dsimp; simp) counitIso := NatIso.ofComponents (fun X ↦ BinaryFan.ext (Over.isoMk (Iso.refl _) (by simpa using X.fst.w.symm)) (by ext; dsimp; simp) (by ext; dsimp; simp)) (by intros; ext; dsimp; simp [BinaryFan.ext]) functor_unitIso_comp c := by ext; dsimp; simp [BinaryFan.ext] /-- A binary fan in `Over X` is a limit if its corresponding pullback cone to `X` is a limit. -/ -- `IsLimit.ofConeEquiv` isn't used here because the lift it defines is `𝟙 _ ≫ pullback.lift`. -- TODO: Define `IsLimit.copy`? @[simps!] def IsLimit.pullbackConeEquivBinaryFanFunctor {c : PullbackCone f g} (hc : IsLimit c) : IsLimit <| pullbackConeEquivBinaryFan.functor.obj c := BinaryFan.isLimitMk -- TODO: Drop `BinaryFan.IsLimit.lift'`. Instead provide the lemmas it bundles separately. -- TODO: Define `abbrev BinaryFan.IsLimit (c : BinaryFan X Y) := IsLimit c` for dot notation? (fun s ↦ Over.homMk (hc.lift <| pullbackConeEquivBinaryFan.inverse.obj s) <| by simpa using s.fst.w) (fun s ↦ Over.OverMorphism.ext (hc.fac _ _)) (fun s ↦ Over.OverMorphism.ext (hc.fac _ _)) fun s m e₁ e₂ ↦ by ext1 apply PullbackCone.IsLimit.hom_ext hc · simpa using congr(($e₁).left) · simpa using congr(($e₂).left) /-- A pullback cone to `X` is a limit if its corresponding binary fan in `Over X` is a limit. -/ -- This could also be `(IsLimit.ofConeEquiv pullbackConeEquivBinaryFan.symm).symm hc`, but possibly -- bad defeqs? def IsLimit.pullbackConeEquivBinaryFanInverse {c : BinaryFan (Over.mk f) (.mk g)} (hc : IsLimit c) : IsLimit <| pullbackConeEquivBinaryFan.inverse.obj c := PullbackCone.IsLimit.mk (c.fst.w.trans c.snd.w.symm) (fun s ↦ (hc.lift <| pullbackConeEquivBinaryFan.functor.obj s).left) (fun s ↦ by simpa only using congr($(hc.fac _ _).left)) (fun s ↦ by simpa only using congr($(hc.fac _ _).left)) <| fun s m hm₁ hm₂ ↦ by change PullbackCone f g at s have := hc.uniq (pullbackConeEquivBinaryFan.functor.obj s) (Over.homMk m <| by have := c.fst.w simp only [pair_obj_left, Over.mk_left, Functor.id_obj, pair_obj_right, Functor.const_obj_obj, Over.mk_hom, Functor.id_map, CostructuredArrow.right_eq_id, Discrete.functor_map_id, Category.comp_id] at hm₁ this simp [← hm₁, this]) (by rintro (_ | _) <;> ext <;> simpa) exact congr(($this).left) end Over section Under variable {f : X ⟶ Y} {g : X ⟶ Z} /-- Pushout cocones from `X` are the same thing as binary cofans in `Under X`. -/ @[simps] def pushoutCoconeEquivBinaryCofan : PushoutCocone f g ≌ BinaryCofan (Under.mk f) (.mk g) where functor.obj c := .mk (Under.homMk (U := .mk f) (V := .mk (f ≫ c.inl)) c.inl rfl) (Under.homMk (U := .mk g) (V := .mk (f ≫ c.inl)) c.inr c.condition.symm) functor.map {c₁ c₂} a := { hom := Under.homMk a.hom, w := by rintro (_|_) <;> aesop_cat } inverse.obj c := .mk c.inl.right c.inr.right (c.inl.w.symm.trans c.inr.w) inverse.map {c₁ c₂} a := { hom := a.hom.right w := by rintro (_|_|_) <;> dsimp <;> simp [← Under.comp_right] } unitIso := NatIso.ofComponents (fun c ↦ c.eta) (fun f ↦ by ext; dsimp; simp) counitIso := NatIso.ofComponents (fun X ↦ BinaryCofan.ext (Under.isoMk (.refl _) (by dsimp; simpa using X.inl.w.symm)) (by ext; dsimp; simp) (by ext; dsimp; simp)) (by intros; ext; dsimp; simp) functor_unitIso_comp c := by ext; dsimp; simp /-- A binary cofan in `Under X` is a colimit if its corresponding pushout cocone from `X` is a colimit. -/ -- `IsColimit.ofCoconeEquiv` isn't used here because the lift it defines is `pushout.desc ≫ 𝟙 _`. -- TODO: Define `IsColimit.copy`? @[simps!] def IsColimit.pushoutCoconeEquivBinaryCofanFunctor {c : PushoutCocone f g} (hc : IsColimit c) : IsColimit <| pushoutCoconeEquivBinaryCofan.functor.obj c := BinaryCofan.isColimitMk (fun s ↦ Under.homMk (hc.desc (PushoutCocone.mk s.inl.right s.inr.right (s.inl.w.symm.trans s.inr.w))) <| by simpa using s.inl.w.symm) (fun s ↦ Under.UnderMorphism.ext (hc.fac _ _)) (fun s ↦ Under.UnderMorphism.ext (hc.fac _ _)) fun s m e₁ e₂ ↦ by ext1 refine PushoutCocone.IsColimit.hom_ext hc ?_ ?_ · simpa using congr(($e₁).right) · simpa using congr(($e₂).right) /-- A pushout cocone from `X` is a colimit if its corresponding binary cofan in `Under X` is a colimit. -/ -- This could also be `(IsColimit.ofCoconeEquiv pushoutCoconeEquivBinaryCofan.symm).symm hc`, -- but possibly bad defeqs? def IsColimit.pushoutCoconeEquivBinaryCofanInverse {c : BinaryCofan (Under.mk f) (.mk g)} (hc : IsColimit c) : IsColimit <| pushoutCoconeEquivBinaryCofan.inverse.obj c := PushoutCocone.IsColimit.mk (c.inl.w.symm.trans c.inr.w) (fun s ↦ (hc.desc <| pushoutCoconeEquivBinaryCofan.functor.obj s).right) (fun s ↦ by simpa only using congr($(hc.fac _ _).right)) (fun s ↦ by simpa only using congr($(hc.fac _ _).right)) <| fun s m hm₁ hm₂ ↦ by change PushoutCocone f g at s have := hc.uniq (pushoutCoconeEquivBinaryCofan.functor.obj s) (Under.homMk m <| by have := c.inl.w simp only [pair_obj_left, Functor.const_obj_obj, Functor.id_obj, StructuredArrow.left_eq_id, Discrete.functor_map_id, Category.id_comp, Under.mk_right, Under.mk_hom, Functor.id_map,
pair_obj_right] at this hm₁ simp [← hm₁, ← Category.assoc, ← this]) (by rintro (_ | _) <;> ext <;> simpa) exact congr(($this).right) end Under end Limits namespace Over section BinaryProduct variable {X : C} {Y Z : Over X} open Limits lemma isPullback_of_binaryFan_isLimit (c : BinaryFan Y Z) (hc : IsLimit c) : IsPullback c.fst.left c.snd.left Y.hom Z.hom :=
Mathlib/CategoryTheory/Limits/Constructions/Over/Products.lean
167
182
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.MellinTransform /-! # Abstract functional equations for Mellin transforms This file formalises a general version of an argument used to prove functional equations for zeta and L functions. ### FE-pairs We define a *weak FE-pair* to be a pair of functions `f, g` on the reals which are locally integrable on `(0, ∞)`, have the form "constant" + "rapidly decaying term" at `∞`, and satisfy a functional equation of the form `f (1 / x) = ε * x ^ k * g x` for some constants `k ∈ ℝ` and `ε ∈ ℂ`. (Modular forms give rise to natural examples with `k` being the weight and `ε` the global root number; hence the notation.) We could arrange `ε = 1` by scaling `g`; but this is inconvenient in applications so we set things up more generally. A *strong FE-pair* is a weak FE-pair where the constant terms of `f` and `g` at `∞` are both 0. The main property of these pairs is the following: if `f`, `g` are a weak FE-pair, with constant terms `f₀` and `g₀` at `∞`, then the Mellin transforms `Λ` and `Λ'` of `f - f₀` and `g - g₀` respectively both have meromorphic continuation and satisfy a functional equation of the form `Λ (k - s) = ε * Λ' s`. The poles (and their residues) are explicitly given in terms of `f₀` and `g₀`; in particular, if `(f, g)` are a strong FE-pair, then the Mellin transforms of `f` and `g` are entire functions. ### Main definitions and results See the sections *Main theorems on weak FE-pairs* and *Main theorems on strong FE-pairs* below. * Strong FE pairs: - `StrongFEPair.Λ` : function of `s : ℂ` - `StrongFEPair.differentiable_Λ`: `Λ` is entire - `StrongFEPair.hasMellin`: `Λ` is everywhere equal to the Mellin transform of `f` - `StrongFEPair.functional_equation`: the functional equation for `Λ` * Weak FE pairs: - `WeakFEPair.Λ₀`: and `WeakFEPair.Λ`: functions of `s : ℂ` - `WeakFEPair.differentiable_Λ₀`: `Λ₀` is entire - `WeakFEPair.differentiableAt_Λ`: `Λ` is differentiable away from `s = 0` and `s = k` - `WeakFEPair.hasMellin`: for `k < re s`, `Λ s` equals the Mellin transform of `f - f₀` - `WeakFEPair.functional_equation₀`: the functional equation for `Λ₀` - `WeakFEPair.functional_equation`: the functional equation for `Λ` - `WeakFEPair.Λ_residue_k`: computation of the residue at `k` - `WeakFEPair.Λ_residue_zero`: computation of the residue at `0`. -/ /- TODO : Consider extending the results to allow functional equations of the form `f (N / x) = (const) • x ^ k • g x` for a real parameter `0 < N`. This could be done either by generalising the existing proofs in situ, or by a separate wrapper `FEPairWithLevel` which just applies a scaling factor to `f` and `g` to reduce to the `N = 1` case. -/ noncomputable section open Real Complex Filter Topology Asymptotics Set MeasureTheory variable (E : Type*) [NormedAddCommGroup E] [NormedSpace ℂ E] /-! ## Definitions and symmetry -/ /-- A structure designed to hold the hypotheses for the Mellin-functional-equation argument (most general version: rapid decay at `∞` up to constant terms) -/ structure WeakFEPair where /-- The functions whose Mellin transform we study -/ (f g : ℝ → E) /-- Weight (exponent in the functional equation) -/ (k : ℝ) /-- Root number -/ (ε : ℂ) /-- Constant terms at `∞` -/ (f₀ g₀ : E) (hf_int : LocallyIntegrableOn f (Ioi 0)) (hg_int : LocallyIntegrableOn g (Ioi 0)) (hk : 0 < k) (hε : ε ≠ 0) (h_feq : ∀ x ∈ Ioi 0, f (1 / x) = (ε * ↑(x ^ k)) • g x) (hf_top (r : ℝ) : (f · - f₀) =O[atTop] (· ^ r)) (hg_top (r : ℝ) : (g · - g₀) =O[atTop] (· ^ r)) /-- A structure designed to hold the hypotheses for the Mellin-functional-equation argument (version without constant terms) -/ structure StrongFEPair extends WeakFEPair E where (hf₀ : f₀ = 0) (hg₀ : g₀ = 0) variable {E} section symmetry /-- Reformulated functional equation with `f` and `g` interchanged. -/ lemma WeakFEPair.h_feq' (P : WeakFEPair E) (x : ℝ) (hx : 0 < x) : P.g (1 / x) = (P.ε⁻¹ * ↑(x ^ P.k)) • P.f x := by rw [(div_div_cancel₀ (one_ne_zero' ℝ) ▸ P.h_feq (1 / x) (one_div_pos.mpr hx):), ← mul_smul] convert (one_smul ℂ (P.g (1 / x))).symm using 2 rw [one_div, inv_rpow hx.le, ofReal_inv] field_simp [P.hε, (rpow_pos_of_pos hx _).ne'] /-- The hypotheses are symmetric in `f` and `g`, with the constant `ε` replaced by `ε⁻¹`. -/ def WeakFEPair.symm (P : WeakFEPair E) : WeakFEPair E where f := P.g g := P.f k := P.k ε := P.ε⁻¹ f₀ := P.g₀ g₀ := P.f₀ hf_int := P.hg_int hg_int := P.hf_int hf_top := P.hg_top hg_top := P.hf_top hε := inv_ne_zero P.hε hk := P.hk h_feq := P.h_feq' /-- The hypotheses are symmetric in `f` and `g`, with the constant `ε` replaced by `ε⁻¹`. -/ def StrongFEPair.symm (P : StrongFEPair E) : StrongFEPair E where toWeakFEPair := P.toWeakFEPair.symm hf₀ := P.hg₀ hg₀ := P.hf₀ end symmetry namespace WeakFEPair /-! ## Auxiliary results I: lemmas on asymptotics -/ /-- As `x → 0`, we have `f x = x ^ (-P.k) • constant` up to a rapidly decaying error. -/ lemma hf_zero (P : WeakFEPair E) (r : ℝ) : (fun x ↦ P.f x - (P.ε * ↑(x ^ (-P.k))) • P.g₀) =O[𝓝[>] 0] (· ^ r) := by have := (P.hg_top (-(r + P.k))).comp_tendsto tendsto_inv_nhdsGT_zero simp_rw [IsBigO, IsBigOWith, eventually_nhdsWithin_iff] at this ⊢ obtain ⟨C, hC⟩ := this use ‖P.ε‖ * C filter_upwards [hC] with x hC' (hx : 0 < x) have h_nv2 : ↑(x ^ P.k) ≠ (0 : ℂ) := ofReal_ne_zero.mpr (rpow_pos_of_pos hx _).ne' have h_nv : P.ε⁻¹ * ↑(x ^ P.k) ≠ 0 := mul_ne_zero P.symm.hε h_nv2 specialize hC' hx simp_rw [Function.comp_apply, ← one_div, P.h_feq' _ hx] at hC' rw [← ((mul_inv_cancel₀ h_nv).symm ▸ one_smul ℂ P.g₀ :), mul_smul _ _ P.g₀, ← smul_sub, norm_smul, ← le_div_iff₀' (lt_of_le_of_ne (norm_nonneg _) (norm_ne_zero_iff.mpr h_nv).symm)] at hC' convert hC' using 1 · congr 3 rw [rpow_neg hx.le] field_simp · simp_rw [norm_mul, norm_real, one_div, inv_rpow hx.le, rpow_neg hx.le, inv_inv, norm_inv, norm_of_nonneg (rpow_pos_of_pos hx _).le, rpow_add hx] field_simp ring /-- Power asymptotic for `f - f₀` as `x → 0`. -/ lemma hf_zero' (P : WeakFEPair E) : (fun x : ℝ ↦ P.f x - P.f₀) =O[𝓝[>] 0] (· ^ (-P.k)) := by simp_rw [← fun x ↦ sub_add_sub_cancel (P.f x) ((P.ε * ↑(x ^ (-P.k))) • P.g₀) P.f₀] refine (P.hf_zero _).add (IsBigO.sub ?_ ?_) · rw [← isBigO_norm_norm] simp_rw [mul_smul, norm_smul, mul_comm _ ‖P.g₀‖, ← mul_assoc, norm_real] apply (isBigO_refl _ _).const_mul_left · refine IsBigO.of_bound ‖P.f₀‖ (eventually_nhdsWithin_iff.mpr ?_) filter_upwards [eventually_le_nhds zero_lt_one] with x hx' (hx : 0 < x) apply le_mul_of_one_le_right (norm_nonneg _) rw [norm_of_nonneg (rpow_pos_of_pos hx _).le, rpow_neg hx.le] exact (one_le_inv₀ (rpow_pos_of_pos hx _)).2 (rpow_le_one hx.le hx' P.hk.le) end WeakFEPair namespace StrongFEPair variable (P : StrongFEPair E) /-- As `x → ∞`, `f x` decays faster than any power of `x`. -/ lemma hf_top' (r : ℝ) : P.f =O[atTop] (· ^ r) := by simpa [P.hf₀] using P.hf_top r /-- As `x → 0`, `f x` decays faster than any power of `x`. -/ lemma hf_zero' (r : ℝ) : P.f =O[𝓝[>] 0] (· ^ r) := by simpa using (P.hg₀ ▸ P.hf_zero r :) /-! ## Main theorems on strong FE-pairs -/ /-- The completed L-function. -/ def Λ : ℂ → E := mellin P.f /-- The Mellin transform of `f` is well-defined and equal to `P.Λ s`, for all `s`. -/ theorem hasMellin (s : ℂ) : HasMellin P.f s (P.Λ s) := let ⟨_, ht⟩ := exists_gt s.re let ⟨_, hu⟩ := exists_lt s.re ⟨mellinConvergent_of_isBigO_rpow P.hf_int (P.hf_top' _) ht (P.hf_zero' _) hu, rfl⟩ lemma Λ_eq : P.Λ = mellin P.f := rfl lemma symm_Λ_eq : P.symm.Λ = mellin P.g := rfl /-- If `(f, g)` are a strong FE pair, then the Mellin transform of `f` is entire. -/ theorem differentiable_Λ : Differentiable ℂ P.Λ := fun s ↦ let ⟨_, ht⟩ := exists_gt s.re let ⟨_, hu⟩ := exists_lt s.re mellin_differentiableAt_of_isBigO_rpow P.hf_int (P.hf_top' _) ht (P.hf_zero' _) hu /-- Main theorem about strong FE pairs: if `(f, g)` are a strong FE pair, then the Mellin transforms of `f` and `g` are related by `s ↦ k - s`. This is proved by making a substitution `t ↦ t⁻¹` in the Mellin transform integral. -/ theorem functional_equation (s : ℂ) : P.Λ (P.k - s) = P.ε • P.symm.Λ s := by -- unfold definition: rw [P.Λ_eq, P.symm_Λ_eq] -- substitute `t ↦ t⁻¹` in `mellin P.g s` have step1 := mellin_comp_rpow P.g (-s) (-1) simp_rw [abs_neg, abs_one, inv_one, one_smul, ofReal_neg, ofReal_one, div_neg, div_one, neg_neg, rpow_neg_one, ← one_div] at step1 -- introduce a power of `t` to match the hypothesis `P.h_feq` have step2 := mellin_cpow_smul (fun t ↦ P.g (1 / t)) (P.k - s) (-P.k) rw [← sub_eq_add_neg, sub_right_comm, sub_self, zero_sub, step1] at step2 -- put in the constant `P.ε` have step3 := mellin_const_smul (fun t ↦ (t : ℂ) ^ (-P.k : ℂ) • P.g (1 / t)) (P.k - s) P.ε rw [step2] at step3 rw [← step3] -- now the integrand matches `P.h_feq'` on `Ioi 0`, so we can apply `setIntegral_congr_fun` refine setIntegral_congr_fun measurableSet_Ioi (fun t ht ↦ ?_) simp_rw [P.h_feq' t ht, ← mul_smul] -- some simple `cpow` arithmetic to finish rw [cpow_neg, ofReal_cpow (le_of_lt ht)] have : (t : ℂ) ^ (P.k : ℂ) ≠ 0 := by simpa [← ofReal_cpow ht.le] using (rpow_pos_of_pos ht _).ne' field_simp [P.hε] end StrongFEPair namespace WeakFEPair variable (P : WeakFEPair E) /-! ## Auxiliary results II: building a strong FE-pair from a weak FE-pair -/ /-- Piecewise modified version of `f` with optimal asymptotics. We deliberately choose intervals which don't quite join up, so the function is `0` at `x = 1`, in order to maintain symmetry; there is no "good" choice of value at `1`. -/ def f_modif : ℝ → E := (Ioi 1).indicator (fun x ↦ P.f x - P.f₀) + (Ioo 0 1).indicator (fun x ↦ P.f x - (P.ε * ↑(x ^ (-P.k))) • P.g₀) /-- Piecewise modified version of `g` with optimal asymptotics. -/ def g_modif : ℝ → E := (Ioi 1).indicator (fun x ↦ P.g x - P.g₀) + (Ioo 0 1).indicator (fun x ↦ P.g x - (P.ε⁻¹ * ↑(x ^ (-P.k))) • P.f₀) lemma hf_modif_int : LocallyIntegrableOn P.f_modif (Ioi 0) := by have : LocallyIntegrableOn (fun x : ℝ ↦ (P.ε * ↑(x ^ (-P.k))) • P.g₀) (Ioi 0) := by refine ContinuousOn.locallyIntegrableOn ?_ measurableSet_Ioi refine continuousOn_of_forall_continuousAt (fun x (hx : 0 < x) ↦ ?_) refine (continuousAt_const.mul ?_).smul continuousAt_const exact continuous_ofReal.continuousAt.comp (continuousAt_rpow_const _ _ (Or.inl hx.ne')) refine LocallyIntegrableOn.add (fun x hx ↦ ?_) (fun x hx ↦ ?_) · obtain ⟨s, hs, hs'⟩ := P.hf_int.sub (locallyIntegrableOn_const _) x hx refine ⟨s, hs, ?_⟩ rw [IntegrableOn, integrable_indicator_iff measurableSet_Ioi, IntegrableOn, Measure.restrict_restrict measurableSet_Ioi, ← IntegrableOn] exact hs'.mono_set Set.inter_subset_right · obtain ⟨s, hs, hs'⟩ := P.hf_int.sub this x hx refine ⟨s, hs, ?_⟩ rw [IntegrableOn, integrable_indicator_iff measurableSet_Ioo, IntegrableOn, Measure.restrict_restrict measurableSet_Ioo, ← IntegrableOn] exact hs'.mono_set Set.inter_subset_right lemma hf_modif_FE (x : ℝ) (hx : 0 < x) : P.f_modif (1 / x) = (P.ε * ↑(x ^ P.k)) • P.g_modif x := by rcases lt_trichotomy 1 x with hx' | rfl | hx' · have : 1 / x < 1 := by rwa [one_div_lt hx one_pos, div_one] rw [f_modif, Pi.add_apply, indicator_of_not_mem (not_mem_Ioi.mpr this.le), zero_add, indicator_of_mem (mem_Ioo.mpr ⟨div_pos one_pos hx, this⟩), g_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr hx'), indicator_of_not_mem (not_mem_Ioo_of_ge hx'.le), add_zero, P.h_feq _ hx, smul_sub] simp_rw [rpow_neg (one_div_pos.mpr hx).le, one_div, inv_rpow hx.le, inv_inv] · simp [f_modif, g_modif] · have : 1 < 1 / x := by rwa [lt_one_div one_pos hx, div_one] rw [f_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr this), indicator_of_not_mem (not_mem_Ioo_of_ge this.le), add_zero, g_modif, Pi.add_apply, indicator_of_not_mem (not_mem_Ioi.mpr hx'.le), indicator_of_mem (mem_Ioo.mpr ⟨hx, hx'⟩), zero_add, P.h_feq _ hx, smul_sub] simp_rw [rpow_neg hx.le, ← mul_smul] field_simp [(rpow_pos_of_pos hx P.k).ne', P.hε] /-- Given a weak FE-pair `(f, g)`, modify it into a strong FE-pair by subtracting suitable correction terms from `f` and `g`. -/ def toStrongFEPair : StrongFEPair E where f := P.f_modif g := P.symm.f_modif k := P.k ε := P.ε f₀ := 0 g₀ := 0 hf_int := P.hf_modif_int hg_int := P.symm.hf_modif_int h_feq := P.hf_modif_FE hε := P.hε hk := P.hk hf₀ := rfl hg₀ := rfl hf_top r := by refine (P.hf_top r).congr' ?_ (by rfl) filter_upwards [eventually_gt_atTop 1] with x hx
rw [f_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr hx), indicator_of_not_mem (not_mem_Ioo_of_ge hx.le), add_zero, sub_zero] hg_top r := by refine (P.hg_top r).congr' ?_ (by rfl) filter_upwards [eventually_gt_atTop 1] with x hx rw [f_modif, Pi.add_apply, indicator_of_mem (mem_Ioi.mpr hx), indicator_of_not_mem (not_mem_Ioo_of_ge hx.le), add_zero, sub_zero] rfl /- Alternative form for the difference between `f - f₀` and its modified term. -/ lemma f_modif_aux1 : EqOn (fun x ↦ P.f_modif x - P.f x + P.f₀) ((Ioo 0 1).indicator (fun x : ℝ ↦ P.f₀ - (P.ε * ↑(x ^ (-P.k))) • P.g₀) + ({1} : Set ℝ).indicator (fun _ ↦ P.f₀ - P.f 1)) (Ioi 0) := by intro x (hx : 0 < x) simp_rw [f_modif, Pi.add_apply]
Mathlib/NumberTheory/LSeries/AbstractFuncEq.lean
320
334
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl, Damiano Testa, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Defs import Mathlib.Data.Ordering.Basic import Mathlib.Order.MinMax import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Use /-! # Ordered monoids This file develops the basics of ordered monoids. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. ## Remark Almost no monoid is actually present in this file: most assumptions have been generalized to `Mul` or `MulOneClass`. -/ -- TODO: If possible, uniformize lemma names, taking special care of `'`, -- after the `ordered`-refactor is done. open Function section Nat instance Nat.instMulLeftMono : MulLeftMono ℕ where elim := fun _ _ _ h => mul_le_mul_left _ h end Nat section Int instance Int.instAddLeftMono : AddLeftMono ℤ where elim := fun _ _ _ h => Int.add_le_add_left h _ end Int variable {α β : Type*} section Mul variable [Mul α] section LE variable [LE α] /- The prime on this lemma is present only on the multiplicative version. The unprimed version is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/ @[to_additive (attr := gcongr) add_le_add_left] theorem mul_le_mul_left' [MulLeftMono α] {b c : α} (bc : b ≤ c) (a : α) : a * b ≤ a * c := CovariantClass.elim _ bc @[to_additive le_of_add_le_add_left] theorem le_of_mul_le_mul_left' [MulLeftReflectLE α] {a b c : α} (bc : a * b ≤ a * c) : b ≤ c := ContravariantClass.elim _ bc /- The prime on this lemma is present only on the multiplicative version. The unprimed version is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/ @[to_additive (attr := gcongr) add_le_add_right] theorem mul_le_mul_right' [i : MulRightMono α] {b c : α} (bc : b ≤ c) (a : α) : b * a ≤ c * a := i.elim a bc @[to_additive le_of_add_le_add_right] theorem le_of_mul_le_mul_right' [i : MulRightReflectLE α] {a b c : α} (bc : b * a ≤ c * a) : b ≤ c := i.elim a bc @[to_additive (attr := simp)] theorem mul_le_mul_iff_left [MulLeftMono α] [MulLeftReflectLE α] (a : α) {b c : α} : a * b ≤ a * c ↔ b ≤ c := rel_iff_cov α α (· * ·) (· ≤ ·) a @[to_additive (attr := simp)] theorem mul_le_mul_iff_right [MulRightMono α] [MulRightReflectLE α] (a : α) {b c : α} : b * a ≤ c * a ↔ b ≤ c := rel_iff_cov α α (swap (· * ·)) (· ≤ ·) a end LE section LT variable [LT α] @[to_additive (attr := simp)] theorem mul_lt_mul_iff_left [MulLeftStrictMono α] [MulLeftReflectLT α] (a : α) {b c : α} : a * b < a * c ↔ b < c := rel_iff_cov α α (· * ·) (· < ·) a @[to_additive (attr := simp)] theorem mul_lt_mul_iff_right [MulRightStrictMono α] [MulRightReflectLT α] (a : α) {b c : α} : b * a < c * a ↔ b < c := rel_iff_cov α α (swap (· * ·)) (· < ·) a @[to_additive (attr := gcongr) add_lt_add_left] theorem mul_lt_mul_left' [MulLeftStrictMono α] {b c : α} (bc : b < c) (a : α) : a * b < a * c := CovariantClass.elim _ bc @[to_additive lt_of_add_lt_add_left] theorem lt_of_mul_lt_mul_left' [MulLeftReflectLT α] {a b c : α} (bc : a * b < a * c) : b < c := ContravariantClass.elim _ bc @[to_additive (attr := gcongr) add_lt_add_right] theorem mul_lt_mul_right' [i : MulRightStrictMono α] {b c : α} (bc : b < c) (a : α) : b * a < c * a := i.elim a bc @[to_additive lt_of_add_lt_add_right] theorem lt_of_mul_lt_mul_right' [i : MulRightReflectLT α] {a b c : α} (bc : b * a < c * a) : b < c := i.elim a bc end LT section Preorder variable [Preorder α] @[to_additive] lemma mul_left_mono [MulLeftMono α] {a : α} : Monotone (a * ·) := fun _ _ h ↦ mul_le_mul_left' h _ @[to_additive] lemma mul_right_mono [MulRightMono α] {a : α} : Monotone (· * a) := fun _ _ h ↦ mul_le_mul_right' h _ @[to_additive] lemma mul_left_strictMono [MulLeftStrictMono α] {a : α} : StrictMono (a * ·) := fun _ _ h ↦ mul_lt_mul_left' h _ @[to_additive] lemma mul_right_strictMono [MulRightStrictMono α] {a : α} : StrictMono (· * a) := fun _ _ h ↦ mul_lt_mul_right' h _ @[to_additive (attr := gcongr)] theorem mul_lt_mul_of_lt_of_lt [MulLeftStrictMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := calc a * c < a * d := mul_lt_mul_left' h₂ a _ < b * d := mul_lt_mul_right' h₁ d alias add_lt_add := add_lt_add_of_lt_of_lt @[to_additive] theorem mul_lt_mul_of_le_of_lt [MulLeftStrictMono α] [MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c < d) : a * c < b * d := (mul_le_mul_right' h₁ _).trans_lt (mul_lt_mul_left' h₂ b) @[to_additive] theorem mul_lt_mul_of_lt_of_le [MulLeftMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c ≤ d) : a * c < b * d := (mul_le_mul_left' h₂ _).trans_lt (mul_lt_mul_right' h₁ d) /-- Only assumes left strict covariance. -/ @[to_additive "Only assumes left strict covariance"] theorem Left.mul_lt_mul [MulLeftStrictMono α] [MulRightMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := mul_lt_mul_of_le_of_lt h₁.le h₂ /-- Only assumes right strict covariance. -/ @[to_additive "Only assumes right strict covariance"] theorem Right.mul_lt_mul [MulLeftMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := mul_lt_mul_of_lt_of_le h₁ h₂.le @[to_additive (attr := gcongr) add_le_add] theorem mul_le_mul' [MulLeftMono α] [MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := (mul_le_mul_left' h₂ _).trans (mul_le_mul_right' h₁ d) @[to_additive] theorem mul_le_mul_three [MulLeftMono α] [MulRightMono α] {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a * b * c ≤ d * e * f := mul_le_mul' (mul_le_mul' h₁ h₂) h₃ @[to_additive] theorem mul_lt_of_mul_lt_left [MulLeftMono α] {a b c d : α} (h : a * b < c) (hle : d ≤ b) : a * d < c := (mul_le_mul_left' hle a).trans_lt h @[to_additive] theorem mul_le_of_mul_le_left [MulLeftMono α] {a b c d : α} (h : a * b ≤ c) (hle : d ≤ b) : a * d ≤ c := @act_rel_of_rel_of_act_rel _ _ _ (· ≤ ·) _ _ a _ _ _ hle h @[to_additive] theorem mul_lt_of_mul_lt_right [MulRightMono α] {a b c d : α} (h : a * b < c) (hle : d ≤ a) : d * b < c := (mul_le_mul_right' hle b).trans_lt h @[to_additive] theorem mul_le_of_mul_le_right [MulRightMono α] {a b c d : α} (h : a * b ≤ c) (hle : d ≤ a) : d * b ≤ c := (mul_le_mul_right' hle b).trans h @[to_additive] theorem lt_mul_of_lt_mul_left [MulLeftMono α] {a b c d : α} (h : a < b * c) (hle : c ≤ d) : a < b * d := h.trans_le (mul_le_mul_left' hle b) @[to_additive] theorem le_mul_of_le_mul_left [MulLeftMono α] {a b c d : α} (h : a ≤ b * c) (hle : c ≤ d) : a ≤ b * d := @rel_act_of_rel_of_rel_act _ _ _ (· ≤ ·) _ _ b _ _ _ hle h @[to_additive] theorem lt_mul_of_lt_mul_right [MulRightMono α] {a b c d : α} (h : a < b * c) (hle : b ≤ d) : a < d * c := h.trans_le (mul_le_mul_right' hle c) @[to_additive] theorem le_mul_of_le_mul_right [MulRightMono α] {a b c d : α} (h : a ≤ b * c) (hle : b ≤ d) : a ≤ d * c := h.trans (mul_le_mul_right' hle c) end Preorder section PartialOrder variable [PartialOrder α] @[to_additive] theorem mul_left_cancel'' [MulLeftReflectLE α] {a b c : α} (h : a * b = a * c) : b = c := (le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge) @[to_additive] theorem mul_right_cancel'' [MulRightReflectLE α] {a b c : α} (h : a * b = c * b) : a = c := (le_of_mul_le_mul_right' h.le).antisymm (le_of_mul_le_mul_right' h.ge) @[to_additive] lemma mul_le_mul_iff_of_ge [MulLeftStrictMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) : a₂ * b₂ ≤ a₁ * b₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by haveI := mulLeftMono_of_mulLeftStrictMono α haveI := mulRightMono_of_mulRightStrictMono α refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ simp only [eq_iff_le_not_lt, ha, hb, true_and] refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩ exacts [mul_lt_mul_of_lt_of_le ha hb, mul_lt_mul_of_le_of_lt ha hb] @[to_additive] theorem mul_eq_mul_iff_eq_and_eq [MulLeftStrictMono α] [MulRightStrictMono α] {a b c d : α} (hac : a ≤ c) (hbd : b ≤ d) : a * b = c * d ↔ a = c ∧ b = d := by haveI := mulLeftMono_of_mulLeftStrictMono α haveI := mulRightMono_of_mulRightStrictMono α rw [le_antisymm_iff, eq_true (mul_le_mul' hac hbd), true_and, mul_le_mul_iff_of_ge hac hbd] @[to_additive] lemma mul_left_inj_of_comparable [MulRightStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) : c * a = b * a ↔ c = b := by refine ⟨fun h' => ?_, (· ▸ rfl)⟩ contrapose h' obtain h | h := h · exact mul_lt_mul_right' (h.lt_of_ne' h') a |>.ne' · exact mul_lt_mul_right' (h.lt_of_ne h') a |>.ne @[to_additive] lemma mul_right_inj_of_comparable [MulLeftStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) : a * c = a * b ↔ c = b := by refine ⟨fun h' => ?_, (· ▸ rfl)⟩ contrapose h' obtain h | h := h · exact mul_lt_mul_left' (h.lt_of_ne' h') a |>.ne' · exact mul_lt_mul_left' (h.lt_of_ne h') a |>.ne end PartialOrder section LinearOrder variable [LinearOrder α] {a b c d : α} @[to_additive] theorem trichotomy_of_mul_eq_mul [MulLeftStrictMono α] [MulRightStrictMono α] (h : a * b = c * d) : (a = c ∧ b = d) ∨ a < c ∨ b < d := by obtain hac | rfl | hca := lt_trichotomy a c · right; left; exact hac · left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b)|>.1 h · obtain hbd | rfl | hdb := lt_trichotomy b d · right; right; exact hbd · exact False.elim <| ne_of_lt (mul_lt_mul_right' hca b) h.symm · exact False.elim <| ne_of_lt (mul_lt_mul_of_lt_of_lt hca hdb) h.symm @[to_additive] lemma mul_max [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : a * max b c = max (a * b) (a * c) := mul_left_mono.map_max @[to_additive] lemma max_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) : max a b * c = max (a * c) (b * c) := mul_right_mono.map_max @[to_additive] lemma mul_min [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : a * min b c = min (a * b) (a * c) := mul_left_mono.map_min @[to_additive] lemma min_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) : min a b * c = min (a * c) (b * c) := mul_right_mono.map_min @[to_additive] lemma min_lt_max_of_mul_lt_mul [MulLeftMono α] [MulRightMono α] (h : a * b < c * d) : min a b < max c d := by simp_rw [min_lt_iff, lt_max_iff]; contrapose! h; exact mul_le_mul' h.1.1 h.2.2 @[to_additive] lemma Left.min_le_max_of_mul_le_mul [MulLeftStrictMono α] [MulRightMono α] (h : a * b ≤ c * d) : min a b ≤ max c d := by simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_le_of_lt h.1.1.le h.2.2 @[to_additive] lemma Right.min_le_max_of_mul_le_mul [MulLeftMono α] [MulRightStrictMono α] (h : a * b ≤ c * d) : min a b ≤ max c d := by simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_lt_of_le h.1.1 h.2.2.le @[to_additive] lemma min_le_max_of_mul_le_mul [MulLeftStrictMono α] [MulRightStrictMono α] (h : a * b ≤ c * d) : min a b ≤ max c d := haveI := mulRightMono_of_mulRightStrictMono α Left.min_le_max_of_mul_le_mul h /-- Not an instance, to avoid loops with `IsLeftCancelMul.mulLeftStrictMono_of_mulLeftMono`. -/ @[to_additive] theorem MulLeftStrictMono.toIsLeftCancelMul [MulLeftStrictMono α] : IsLeftCancelMul α where mul_left_cancel _ _ _ h := mul_left_strictMono.injective h /-- Not an instance, to avoid loops with `IsRightCancelMul.mulRightStrictMono_of_mulRightMono`. -/ @[to_additive] theorem MulRightStrictMono.toIsRightCancelMul [MulRightStrictMono α] : IsRightCancelMul α where mul_right_cancel _ _ _ h := mul_right_strictMono.injective h end LinearOrder section LinearOrder variable [LinearOrder α] [MulLeftMono α] [MulRightMono α] {a b c d : α} @[to_additive max_add_add_le_max_add_max] theorem max_mul_mul_le_max_mul_max' : max (a * b) (c * d) ≤ max a c * max b d := max_le (mul_le_mul' (le_max_left _ _) <| le_max_left _ _) <| mul_le_mul' (le_max_right _ _) <| le_max_right _ _ @[to_additive min_add_min_le_min_add_add] theorem min_mul_min_le_min_mul_mul' : min a c * min b d ≤ min (a * b) (c * d) := le_min (mul_le_mul' (min_le_left _ _) <| min_le_left _ _) <| mul_le_mul' (min_le_right _ _) <| min_le_right _ _ end LinearOrder end Mul -- using one section MulOneClass variable [MulOneClass α] section LE variable [LE α] @[to_additive le_add_of_nonneg_right] theorem le_mul_of_one_le_right' [MulLeftMono α] {a b : α} (h : 1 ≤ b) : a ≤ a * b := calc a = a * 1 := (mul_one a).symm _ ≤ a * b := mul_le_mul_left' h a @[to_additive add_le_of_nonpos_right] theorem mul_le_of_le_one_right' [MulLeftMono α] {a b : α} (h : b ≤ 1) : a * b ≤ a := calc a * b ≤ a * 1 := mul_le_mul_left' h a _ = a := mul_one a @[to_additive le_add_of_nonneg_left] theorem le_mul_of_one_le_left' [MulRightMono α] {a b : α} (h : 1 ≤ b) : a ≤ b * a := calc a = 1 * a := (one_mul a).symm _ ≤ b * a := mul_le_mul_right' h a @[to_additive add_le_of_nonpos_left] theorem mul_le_of_le_one_left' [MulRightMono α] {a b : α} (h : b ≤ 1) : b * a ≤ a := calc b * a ≤ 1 * a := mul_le_mul_right' h a _ = a := one_mul a @[to_additive] theorem one_le_of_le_mul_right [MulLeftReflectLE α] {a b : α} (h : a ≤ a * b) : 1 ≤ b := le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one] @[to_additive] theorem le_one_of_mul_le_right [MulLeftReflectLE α] {a b : α} (h : a * b ≤ a) : b ≤ 1 := le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one] @[to_additive] theorem one_le_of_le_mul_left [MulRightReflectLE α] {a b : α} (h : b ≤ a * b) : 1 ≤ a := le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul] @[to_additive] theorem le_one_of_mul_le_left [MulRightReflectLE α] {a b : α} (h : a * b ≤ b) : a ≤ 1 := le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul] @[to_additive (attr := simp) le_add_iff_nonneg_right] theorem le_mul_iff_one_le_right' [MulLeftMono α] [MulLeftReflectLE α] (a : α) {b : α} : a ≤ a * b ↔ 1 ≤ b := Iff.trans (by rw [mul_one]) (mul_le_mul_iff_left a) @[to_additive (attr := simp) le_add_iff_nonneg_left] theorem le_mul_iff_one_le_left' [MulRightMono α] [MulRightReflectLE α] (a : α) {b : α} : a ≤ b * a ↔ 1 ≤ b := Iff.trans (by rw [one_mul]) (mul_le_mul_iff_right a) @[to_additive (attr := simp) add_le_iff_nonpos_right] theorem mul_le_iff_le_one_right' [MulLeftMono α] [MulLeftReflectLE α] (a : α) {b : α} : a * b ≤ a ↔ b ≤ 1 := Iff.trans (by rw [mul_one]) (mul_le_mul_iff_left a) @[to_additive (attr := simp) add_le_iff_nonpos_left] theorem mul_le_iff_le_one_left' [MulRightMono α] [MulRightReflectLE α] {a b : α} : a * b ≤ b ↔ a ≤ 1 := Iff.trans (by rw [one_mul]) (mul_le_mul_iff_right b) end LE section LT variable [LT α] @[to_additive lt_add_of_pos_right] theorem lt_mul_of_one_lt_right' [MulLeftStrictMono α] (a : α) {b : α} (h : 1 < b) : a < a * b := calc a = a * 1 := (mul_one a).symm _ < a * b := mul_lt_mul_left' h a @[to_additive add_lt_of_neg_right] theorem mul_lt_of_lt_one_right' [MulLeftStrictMono α] (a : α) {b : α} (h : b < 1) : a * b < a := calc a * b < a * 1 := mul_lt_mul_left' h a _ = a := mul_one a @[to_additive lt_add_of_pos_left] theorem lt_mul_of_one_lt_left' [MulRightStrictMono α] (a : α) {b : α} (h : 1 < b) : a < b * a := calc a = 1 * a := (one_mul a).symm _ < b * a := mul_lt_mul_right' h a @[to_additive add_lt_of_neg_left] theorem mul_lt_of_lt_one_left' [MulRightStrictMono α] (a : α) {b : α} (h : b < 1) : b * a < a := calc b * a < 1 * a := mul_lt_mul_right' h a _ = a := one_mul a @[to_additive] theorem one_lt_of_lt_mul_right [MulLeftReflectLT α] {a b : α} (h : a < a * b) : 1 < b := lt_of_mul_lt_mul_left' (a := a) <| by simpa only [mul_one] @[to_additive] theorem lt_one_of_mul_lt_right [MulLeftReflectLT α] {a b : α} (h : a * b < a) : b < 1 := lt_of_mul_lt_mul_left' (a := a) <| by simpa only [mul_one] @[to_additive] theorem one_lt_of_lt_mul_left [MulRightReflectLT α] {a b : α} (h : b < a * b) : 1 < a := lt_of_mul_lt_mul_right' (a := b) <| by simpa only [one_mul] @[to_additive] theorem lt_one_of_mul_lt_left [MulRightReflectLT α] {a b : α} (h : a * b < b) : a < 1 := lt_of_mul_lt_mul_right' (a := b) <| by simpa only [one_mul] @[to_additive (attr := simp) lt_add_iff_pos_right] theorem lt_mul_iff_one_lt_right' [MulLeftStrictMono α] [MulLeftReflectLT α] (a : α) {b : α} : a < a * b ↔ 1 < b := Iff.trans (by rw [mul_one]) (mul_lt_mul_iff_left a) @[to_additive (attr := simp) lt_add_iff_pos_left] theorem lt_mul_iff_one_lt_left' [MulRightStrictMono α] [MulRightReflectLT α] (a : α) {b : α} : a < b * a ↔ 1 < b := Iff.trans (by rw [one_mul]) (mul_lt_mul_iff_right a) @[to_additive (attr := simp) add_lt_iff_neg_left] theorem mul_lt_iff_lt_one_left' [MulLeftStrictMono α] [MulLeftReflectLT α] {a b : α} : a * b < a ↔ b < 1 := Iff.trans (by rw [mul_one]) (mul_lt_mul_iff_left a) @[to_additive (attr := simp) add_lt_iff_neg_right] theorem mul_lt_iff_lt_one_right' [MulRightStrictMono α] [MulRightReflectLT α] {a : α} (b : α) : a * b < b ↔ a < 1 := Iff.trans (by rw [one_mul]) (mul_lt_mul_iff_right b) end LT section Preorder variable [Preorder α] /-! Lemmas of the form `b ≤ c → a ≤ 1 → b * a ≤ c`, which assume left covariance. -/ @[to_additive] theorem mul_le_of_le_of_le_one [MulLeftMono α] {a b c : α} (hbc : b ≤ c) (ha : a ≤ 1) : b * a ≤ c := calc b * a ≤ b * 1 := mul_le_mul_left' ha b _ = b := mul_one b _ ≤ c := hbc @[to_additive] theorem mul_lt_of_le_of_lt_one [MulLeftStrictMono α] {a b c : α} (hbc : b ≤ c) (ha : a < 1) : b * a < c := calc b * a < b * 1 := mul_lt_mul_left' ha b _ = b := mul_one b _ ≤ c := hbc @[to_additive] theorem mul_lt_of_lt_of_le_one [MulLeftMono α] {a b c : α} (hbc : b < c) (ha : a ≤ 1) : b * a < c := calc b * a ≤ b * 1 := mul_le_mul_left' ha b _ = b := mul_one b _ < c := hbc @[to_additive] theorem mul_lt_of_lt_of_lt_one [MulLeftStrictMono α] {a b c : α} (hbc : b < c) (ha : a < 1) : b * a < c := calc b * a < b * 1 := mul_lt_mul_left' ha b _ = b := mul_one b _ < c := hbc @[to_additive] theorem mul_lt_of_lt_of_lt_one' [MulLeftMono α] {a b c : α} (hbc : b < c) (ha : a < 1) : b * a < c := mul_lt_of_lt_of_le_one hbc ha.le /-- Assumes left covariance. The lemma assuming right covariance is `Right.mul_le_one`. -/ @[to_additive "Assumes left covariance. The lemma assuming right covariance is `Right.add_nonpos`."] theorem Left.mul_le_one [MulLeftMono α] {a b : α} (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := mul_le_of_le_of_le_one ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.mul_lt_one_of_le_of_lt`. -/ @[to_additive Left.add_neg_of_nonpos_of_neg "Assumes left covariance. The lemma assuming right covariance is `Right.add_neg_of_nonpos_of_neg`."] theorem Left.mul_lt_one_of_le_of_lt [MulLeftStrictMono α] {a b : α} (ha : a ≤ 1) (hb : b < 1) : a * b < 1 := mul_lt_of_le_of_lt_one ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.mul_lt_one_of_lt_of_le`. -/ @[to_additive Left.add_neg_of_neg_of_nonpos "Assumes left covariance. The lemma assuming right covariance is `Right.add_neg_of_neg_of_nonpos`."] theorem Left.mul_lt_one_of_lt_of_le [MulLeftMono α] {a b : α} (ha : a < 1) (hb : b ≤ 1) : a * b < 1 := mul_lt_of_lt_of_le_one ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.mul_lt_one`. -/ @[to_additive "Assumes left covariance. The lemma assuming right covariance is `Right.add_neg`."] theorem Left.mul_lt_one [MulLeftStrictMono α] {a b : α} (ha : a < 1) (hb : b < 1) : a * b < 1 := mul_lt_of_lt_of_lt_one ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.mul_lt_one'`. -/ @[to_additive "Assumes left covariance. The lemma assuming right covariance is `Right.add_neg'`."] theorem Left.mul_lt_one' [MulLeftMono α] {a b : α} (ha : a < 1) (hb : b < 1) : a * b < 1 := mul_lt_of_lt_of_lt_one' ha hb /-! Lemmas of the form `b ≤ c → 1 ≤ a → b ≤ c * a`, which assume left covariance. -/ @[to_additive] theorem le_mul_of_le_of_one_le [MulLeftMono α] {a b c : α} (hbc : b ≤ c) (ha : 1 ≤ a) : b ≤ c * a := calc b ≤ c := hbc _ = c * 1 := (mul_one c).symm _ ≤ c * a := mul_le_mul_left' ha c @[to_additive] theorem lt_mul_of_le_of_one_lt [MulLeftStrictMono α] {a b c : α} (hbc : b ≤ c) (ha : 1 < a) : b < c * a := calc b ≤ c := hbc _ = c * 1 := (mul_one c).symm _ < c * a := mul_lt_mul_left' ha c @[to_additive] theorem lt_mul_of_lt_of_one_le [MulLeftMono α] {a b c : α} (hbc : b < c) (ha : 1 ≤ a) : b < c * a := calc b < c := hbc _ = c * 1 := (mul_one c).symm _ ≤ c * a := mul_le_mul_left' ha c @[to_additive] theorem lt_mul_of_lt_of_one_lt [MulLeftStrictMono α] {a b c : α} (hbc : b < c) (ha : 1 < a) : b < c * a := calc b < c := hbc _ = c * 1 := (mul_one c).symm _ < c * a := mul_lt_mul_left' ha c @[to_additive] theorem lt_mul_of_lt_of_one_lt' [MulLeftMono α] {a b c : α} (hbc : b < c) (ha : 1 < a) : b < c * a := lt_mul_of_lt_of_one_le hbc ha.le /-- Assumes left covariance. The lemma assuming right covariance is `Right.one_le_mul`. -/ @[to_additive Left.add_nonneg "Assumes left covariance. The lemma assuming right covariance is `Right.add_nonneg`."] theorem Left.one_le_mul [MulLeftMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := le_mul_of_le_of_one_le ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.one_lt_mul_of_le_of_lt`. -/ @[to_additive Left.add_pos_of_nonneg_of_pos "Assumes left covariance. The lemma assuming right covariance is `Right.add_pos_of_nonneg_of_pos`."] theorem Left.one_lt_mul_of_le_of_lt [MulLeftStrictMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b := lt_mul_of_le_of_one_lt ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.one_lt_mul_of_lt_of_le`. -/ @[to_additive Left.add_pos_of_pos_of_nonneg "Assumes left covariance. The lemma assuming right covariance is `Right.add_pos_of_pos_of_nonneg`."] theorem Left.one_lt_mul_of_lt_of_le [MulLeftMono α] {a b : α} (ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b := lt_mul_of_lt_of_one_le ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.one_lt_mul`. -/ @[to_additive Left.add_pos "Assumes left covariance. The lemma assuming right covariance is `Right.add_pos`."] theorem Left.one_lt_mul [MulLeftStrictMono α] {a b : α} (ha : 1 < a) (hb : 1 < b) : 1 < a * b := lt_mul_of_lt_of_one_lt ha hb /-- Assumes left covariance. The lemma assuming right covariance is `Right.one_lt_mul'`. -/ @[to_additive Left.add_pos' "Assumes left covariance. The lemma assuming right covariance is `Right.add_pos'`."] theorem Left.one_lt_mul' [MulLeftMono α] {a b : α} (ha : 1 < a) (hb : 1 < b) : 1 < a * b := lt_mul_of_lt_of_one_lt' ha hb /-! Lemmas of the form `a ≤ 1 → b ≤ c → a * b ≤ c`, which assume right covariance. -/ @[to_additive] theorem mul_le_of_le_one_of_le [MulRightMono α] {a b c : α} (ha : a ≤ 1) (hbc : b ≤ c) : a * b ≤ c := calc a * b ≤ 1 * b := mul_le_mul_right' ha b _ = b := one_mul b _ ≤ c := hbc @[to_additive] theorem mul_lt_of_lt_one_of_le [MulRightStrictMono α] {a b c : α} (ha : a < 1) (hbc : b ≤ c) : a * b < c := calc a * b < 1 * b := mul_lt_mul_right' ha b _ = b := one_mul b _ ≤ c := hbc @[to_additive] theorem mul_lt_of_le_one_of_lt [MulRightMono α] {a b c : α} (ha : a ≤ 1) (hb : b < c) : a * b < c := calc a * b ≤ 1 * b := mul_le_mul_right' ha b _ = b := one_mul b _ < c := hb @[to_additive] theorem mul_lt_of_lt_one_of_lt [MulRightStrictMono α] {a b c : α} (ha : a < 1) (hb : b < c) : a * b < c := calc a * b < 1 * b := mul_lt_mul_right' ha b _ = b := one_mul b _ < c := hb @[to_additive] theorem mul_lt_of_lt_one_of_lt' [MulRightMono α] {a b c : α} (ha : a < 1) (hbc : b < c) : a * b < c := mul_lt_of_le_one_of_lt ha.le hbc /-- Assumes right covariance. The lemma assuming left covariance is `Left.mul_le_one`. -/ @[to_additive "Assumes right covariance. The lemma assuming left covariance is `Left.add_nonpos`."] theorem Right.mul_le_one [MulRightMono α] {a b : α} (ha : a ≤ 1) (hb : b ≤ 1) : a * b ≤ 1 := mul_le_of_le_one_of_le ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.mul_lt_one_of_lt_of_le`. -/ @[to_additive Right.add_neg_of_neg_of_nonpos "Assumes right covariance. The lemma assuming left covariance is `Left.add_neg_of_neg_of_nonpos`."] theorem Right.mul_lt_one_of_lt_of_le [MulRightStrictMono α] {a b : α} (ha : a < 1) (hb : b ≤ 1) : a * b < 1 := mul_lt_of_lt_one_of_le ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.mul_lt_one_of_le_of_lt`. -/ @[to_additive Right.add_neg_of_nonpos_of_neg "Assumes right covariance. The lemma assuming left covariance is `Left.add_neg_of_nonpos_of_neg`."] theorem Right.mul_lt_one_of_le_of_lt [MulRightMono α] {a b : α} (ha : a ≤ 1) (hb : b < 1) : a * b < 1 := mul_lt_of_le_one_of_lt ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.mul_lt_one`. -/ @[to_additive "Assumes right covariance. The lemma assuming left covariance is `Left.add_neg`."] theorem Right.mul_lt_one [MulRightStrictMono α] {a b : α} (ha : a < 1) (hb : b < 1) : a * b < 1 := mul_lt_of_lt_one_of_lt ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.mul_lt_one'`. -/ @[to_additive "Assumes right covariance. The lemma assuming left covariance is `Left.add_neg'`."] theorem Right.mul_lt_one' [MulRightMono α] {a b : α} (ha : a < 1) (hb : b < 1) : a * b < 1 := mul_lt_of_lt_one_of_lt' ha hb /-! Lemmas of the form `1 ≤ a → b ≤ c → b ≤ a * c`, which assume right covariance. -/ @[to_additive] theorem le_mul_of_one_le_of_le [MulRightMono α] {a b c : α} (ha : 1 ≤ a) (hbc : b ≤ c) : b ≤ a * c := calc b ≤ c := hbc _ = 1 * c := (one_mul c).symm _ ≤ a * c := mul_le_mul_right' ha c @[to_additive] theorem lt_mul_of_one_lt_of_le [MulRightStrictMono α] {a b c : α} (ha : 1 < a) (hbc : b ≤ c) : b < a * c := calc b ≤ c := hbc _ = 1 * c := (one_mul c).symm _ < a * c := mul_lt_mul_right' ha c @[to_additive] theorem lt_mul_of_one_le_of_lt [MulRightMono α] {a b c : α} (ha : 1 ≤ a) (hbc : b < c) : b < a * c := calc b < c := hbc _ = 1 * c := (one_mul c).symm _ ≤ a * c := mul_le_mul_right' ha c @[to_additive] theorem lt_mul_of_one_lt_of_lt [MulRightStrictMono α] {a b c : α} (ha : 1 < a) (hbc : b < c) : b < a * c := calc b < c := hbc _ = 1 * c := (one_mul c).symm _ < a * c := mul_lt_mul_right' ha c @[to_additive] theorem lt_mul_of_one_lt_of_lt' [MulRightMono α] {a b c : α} (ha : 1 < a) (hbc : b < c) : b < a * c := lt_mul_of_one_le_of_lt ha.le hbc /-- Assumes right covariance. The lemma assuming left covariance is `Left.one_le_mul`. -/ @[to_additive Right.add_nonneg "Assumes right covariance. The lemma assuming left covariance is `Left.add_nonneg`."] theorem Right.one_le_mul [MulRightMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) : 1 ≤ a * b := le_mul_of_one_le_of_le ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.one_lt_mul_of_lt_of_le`. -/ @[to_additive Right.add_pos_of_pos_of_nonneg "Assumes right covariance. The lemma assuming left covariance is `Left.add_pos_of_pos_of_nonneg`."] theorem Right.one_lt_mul_of_lt_of_le [MulRightStrictMono α] {a b : α} (ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b := lt_mul_of_one_lt_of_le ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.one_lt_mul_of_le_of_lt`. -/ @[to_additive Right.add_pos_of_nonneg_of_pos "Assumes right covariance. The lemma assuming left covariance is `Left.add_pos_of_nonneg_of_pos`."] theorem Right.one_lt_mul_of_le_of_lt [MulRightMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b := lt_mul_of_one_le_of_lt ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.one_lt_mul`. -/ @[to_additive Right.add_pos "Assumes right covariance. The lemma assuming left covariance is `Left.add_pos`."] theorem Right.one_lt_mul [MulRightStrictMono α] {a b : α} (ha : 1 < a) (hb : 1 < b) : 1 < a * b := lt_mul_of_one_lt_of_lt ha hb /-- Assumes right covariance. The lemma assuming left covariance is `Left.one_lt_mul'`. -/ @[to_additive Right.add_pos' "Assumes right covariance. The lemma assuming left covariance is `Left.add_pos'`."] theorem Right.one_lt_mul' [MulRightMono α] {a b : α} (ha : 1 < a) (hb : 1 < b) : 1 < a * b := lt_mul_of_one_lt_of_lt' ha hb alias mul_le_one' := Left.mul_le_one alias mul_lt_one_of_le_of_lt := Left.mul_lt_one_of_le_of_lt alias mul_lt_one_of_lt_of_le := Left.mul_lt_one_of_lt_of_le alias mul_lt_one := Left.mul_lt_one alias mul_lt_one' := Left.mul_lt_one' attribute [to_additive add_nonpos "**Alias** of `Left.add_nonpos`."] mul_le_one' attribute [to_additive add_neg_of_nonpos_of_neg "**Alias** of `Left.add_neg_of_nonpos_of_neg`."] mul_lt_one_of_le_of_lt attribute [to_additive add_neg_of_neg_of_nonpos "**Alias** of `Left.add_neg_of_neg_of_nonpos`."] mul_lt_one_of_lt_of_le attribute [to_additive "**Alias** of `Left.add_neg`."] mul_lt_one attribute [to_additive "**Alias** of `Left.add_neg'`."] mul_lt_one' alias one_le_mul := Left.one_le_mul alias one_lt_mul_of_le_of_lt' := Left.one_lt_mul_of_le_of_lt alias one_lt_mul_of_lt_of_le' := Left.one_lt_mul_of_lt_of_le alias one_lt_mul' := Left.one_lt_mul alias one_lt_mul'' := Left.one_lt_mul' attribute [to_additive add_nonneg "**Alias** of `Left.add_nonneg`."] one_le_mul attribute [to_additive add_pos_of_nonneg_of_pos "**Alias** of `Left.add_pos_of_nonneg_of_pos`."] one_lt_mul_of_le_of_lt' attribute [to_additive add_pos_of_pos_of_nonneg "**Alias** of `Left.add_pos_of_pos_of_nonneg`."] one_lt_mul_of_lt_of_le' attribute [to_additive add_pos "**Alias** of `Left.add_pos`."] one_lt_mul' attribute [to_additive add_pos' "**Alias** of `Left.add_pos'`."] one_lt_mul'' @[to_additive] theorem lt_of_mul_lt_of_one_le_left [MulLeftMono α] {a b c : α} (h : a * b < c) (hle : 1 ≤ b) : a < c := (le_mul_of_one_le_right' hle).trans_lt h @[to_additive] theorem le_of_mul_le_of_one_le_left [MulLeftMono α] {a b c : α} (h : a * b ≤ c) (hle : 1 ≤ b) : a ≤ c := (le_mul_of_one_le_right' hle).trans h @[to_additive] theorem lt_of_lt_mul_of_le_one_left [MulLeftMono α] {a b c : α} (h : a < b * c) (hle : c ≤ 1) : a < b := h.trans_le (mul_le_of_le_one_right' hle) @[to_additive] theorem le_of_le_mul_of_le_one_left [MulLeftMono α] {a b c : α} (h : a ≤ b * c) (hle : c ≤ 1) : a ≤ b := h.trans (mul_le_of_le_one_right' hle) @[to_additive] theorem lt_of_mul_lt_of_one_le_right [MulRightMono α] {a b c : α} (h : a * b < c) (hle : 1 ≤ a) : b < c := (le_mul_of_one_le_left' hle).trans_lt h @[to_additive] theorem le_of_mul_le_of_one_le_right [MulRightMono α] {a b c : α} (h : a * b ≤ c) (hle : 1 ≤ a) : b ≤ c := (le_mul_of_one_le_left' hle).trans h @[to_additive] theorem lt_of_lt_mul_of_le_one_right [MulRightMono α] {a b c : α} (h : a < b * c) (hle : b ≤ 1) : a < c := h.trans_le (mul_le_of_le_one_left' hle) @[to_additive] theorem le_of_le_mul_of_le_one_right [MulRightMono α] {a b c : α} (h : a ≤ b * c) (hle : b ≤ 1) : a ≤ c := h.trans (mul_le_of_le_one_left' hle) end Preorder section PartialOrder variable [PartialOrder α] @[to_additive] theorem mul_eq_one_iff_of_one_le [MulLeftMono α] [MulRightMono α] {a b : α} (ha : 1 ≤ a) (hb : 1 ≤ b) : a * b = 1 ↔ a = 1 ∧ b = 1 := Iff.intro (fun hab : a * b = 1 => have : a ≤ 1 := hab ▸ le_mul_of_le_of_one_le le_rfl hb have : a = 1 := le_antisymm this ha have : b ≤ 1 := hab ▸ le_mul_of_one_le_of_le ha le_rfl have : b = 1 := le_antisymm this hb And.intro ‹a = 1› ‹b = 1›) (by rintro ⟨rfl, rfl⟩; rw [mul_one]) section Left variable [MulLeftMono α] {a b : α} @[to_additive eq_zero_of_add_nonneg_left] theorem eq_one_of_one_le_mul_left (ha : a ≤ 1) (hb : b ≤ 1) (hab : 1 ≤ a * b) : a = 1 := ha.eq_of_not_lt fun h => hab.not_lt <| mul_lt_one_of_lt_of_le h hb @[to_additive] theorem eq_one_of_mul_le_one_left (ha : 1 ≤ a) (hb : 1 ≤ b) (hab : a * b ≤ 1) : a = 1 := ha.eq_of_not_gt fun h => hab.not_lt <| one_lt_mul_of_lt_of_le' h hb end Left section Right variable [MulRightMono α] {a b : α} @[to_additive eq_zero_of_add_nonneg_right] theorem eq_one_of_one_le_mul_right (ha : a ≤ 1) (hb : b ≤ 1) (hab : 1 ≤ a * b) : b = 1 := hb.eq_of_not_lt fun h => hab.not_lt <| Right.mul_lt_one_of_le_of_lt ha h @[to_additive] theorem eq_one_of_mul_le_one_right (ha : 1 ≤ a) (hb : 1 ≤ b) (hab : a * b ≤ 1) : b = 1 := hb.eq_of_not_gt fun h => hab.not_lt <| Right.one_lt_mul_of_le_of_lt ha h end Right end PartialOrder section LinearOrder variable [LinearOrder α] theorem exists_square_le [MulLeftStrictMono α] (a : α) : ∃ b : α, b * b ≤ a := by by_cases h : a < 1 · use a have : a * a < a * 1 := mul_lt_mul_left' h a rw [mul_one] at this exact le_of_lt this · use 1 push_neg at h rwa [mul_one] end LinearOrder end MulOneClass section Semigroup variable [Semigroup α] section PartialOrder variable [PartialOrder α] /- This is not instance, since we want to have an instance from `LeftCancelSemigroup`s to the appropriate covariant class. -/ /-- A semigroup with a partial order and satisfying `LeftCancelSemigroup` (i.e. `a * c < b * c → a < b`) is a `LeftCancelSemigroup`. -/ @[to_additive "An additive semigroup with a partial order and satisfying `AddLeftCancelSemigroup` (i.e. `c + a < c + b → a < b`) is a `AddLeftCancelSemigroup`."] def Contravariant.toLeftCancelSemigroup [MulLeftReflectLE α] : LeftCancelSemigroup α := { ‹Semigroup α› with mul_left_cancel := fun _ _ _ => mul_left_cancel'' } /- This is not instance, since we want to have an instance from `RightCancelSemigroup`s to the appropriate covariant class. -/ /-- A semigroup with a partial order and satisfying `RightCancelSemigroup` (i.e. `a * c < b * c → a < b`) is a `RightCancelSemigroup`. -/ @[to_additive "An additive semigroup with a partial order and satisfying `AddRightCancelSemigroup` (`a + c < b + c → a < b`) is a `AddRightCancelSemigroup`."] def Contravariant.toRightCancelSemigroup [MulRightReflectLE α] : RightCancelSemigroup α := { ‹Semigroup α› with mul_right_cancel := fun _ _ _ => mul_right_cancel'' } end PartialOrder end Semigroup section Mono variable [Mul α] [Preorder α] [Preorder β] {f g : β → α} {s : Set β} @[to_additive const_add] theorem Monotone.const_mul' [MulLeftMono α] (hf : Monotone f) (a : α) : Monotone fun x ↦ a * f x := mul_left_mono.comp hf @[to_additive const_add] theorem MonotoneOn.const_mul' [MulLeftMono α] (hf : MonotoneOn f s) (a : α) : MonotoneOn (fun x => a * f x) s := mul_left_mono.comp_monotoneOn hf @[to_additive const_add] theorem Antitone.const_mul' [MulLeftMono α] (hf : Antitone f) (a : α) : Antitone fun x ↦ a * f x := mul_left_mono.comp_antitone hf @[to_additive const_add] theorem AntitoneOn.const_mul' [MulLeftMono α] (hf : AntitoneOn f s) (a : α) : AntitoneOn (fun x => a * f x) s := mul_left_mono.comp_antitoneOn hf @[to_additive add_const] theorem Monotone.mul_const' [MulRightMono α] (hf : Monotone f) (a : α) : Monotone fun x => f x * a := mul_right_mono.comp hf @[to_additive add_const] theorem MonotoneOn.mul_const' [MulRightMono α] (hf : MonotoneOn f s) (a : α) : MonotoneOn (fun x => f x * a) s := mul_right_mono.comp_monotoneOn hf @[to_additive add_const] theorem Antitone.mul_const' [MulRightMono α] (hf : Antitone f) (a : α) : Antitone fun x ↦ f x * a := mul_right_mono.comp_antitone hf @[to_additive add_const] theorem AntitoneOn.mul_const' [MulRightMono α] (hf : AntitoneOn f s) (a : α) : AntitoneOn (fun x => f x * a) s := mul_right_mono.comp_antitoneOn hf /-- The product of two monotone functions is monotone. -/ @[to_additive add "The sum of two monotone functions is monotone."] theorem Monotone.mul' [MulLeftMono α] [MulRightMono α] (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x * g x := fun _ _ h => mul_le_mul' (hf h) (hg h) /-- The product of two monotone functions is monotone. -/ @[to_additive add "The sum of two monotone functions is monotone."] theorem MonotoneOn.mul' [MulLeftMono α] [MulRightMono α] (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x * g x) s := fun _ hx _ hy h => mul_le_mul' (hf hx hy h) (hg hx hy h) /-- The product of two antitone functions is antitone. -/ @[to_additive add "The sum of two antitone functions is antitone."] theorem Antitone.mul' [MulLeftMono α] [MulRightMono α] (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x * g x := fun _ _ h => mul_le_mul' (hf h) (hg h) /-- The product of two antitone functions is antitone. -/ @[to_additive add "The sum of two antitone functions is antitone."] theorem AntitoneOn.mul' [MulLeftMono α] [MulRightMono α] (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x * g x) s := fun _ hx _ hy h => mul_le_mul' (hf hx hy h) (hg hx hy h) section Left variable [MulLeftStrictMono α] @[to_additive const_add] theorem StrictMono.const_mul' (hf : StrictMono f) (c : α) : StrictMono fun x => c * f x := fun _ _ ab => mul_lt_mul_left' (hf ab) c @[to_additive const_add] theorem StrictMonoOn.const_mul' (hf : StrictMonoOn f s) (c : α) : StrictMonoOn (fun x => c * f x) s := fun _ ha _ hb ab => mul_lt_mul_left' (hf ha hb ab) c @[to_additive const_add] theorem StrictAnti.const_mul' (hf : StrictAnti f) (c : α) : StrictAnti fun x => c * f x := fun _ _ ab => mul_lt_mul_left' (hf ab) c @[to_additive const_add] theorem StrictAntiOn.const_mul' (hf : StrictAntiOn f s) (c : α) : StrictAntiOn (fun x => c * f x) s := fun _ ha _ hb ab => mul_lt_mul_left' (hf ha hb ab) c end Left section Right variable [MulRightStrictMono α] @[to_additive add_const] theorem StrictMono.mul_const' (hf : StrictMono f) (c : α) : StrictMono fun x => f x * c := fun _ _ ab => mul_lt_mul_right' (hf ab) c @[to_additive add_const] theorem StrictMonoOn.mul_const' (hf : StrictMonoOn f s) (c : α) : StrictMonoOn (fun x => f x * c) s := fun _ ha _ hb ab => mul_lt_mul_right' (hf ha hb ab) c @[to_additive add_const] theorem StrictAnti.mul_const' (hf : StrictAnti f) (c : α) : StrictAnti fun x => f x * c := fun _ _ ab => mul_lt_mul_right' (hf ab) c @[to_additive add_const] theorem StrictAntiOn.mul_const' (hf : StrictAntiOn f s) (c : α) : StrictAntiOn (fun x => f x * c) s := fun _ ha _ hb ab => mul_lt_mul_right' (hf ha hb ab) c end Right /-- The product of two strictly monotone functions is strictly monotone. -/ @[to_additive add "The sum of two strictly monotone functions is strictly monotone."] theorem StrictMono.mul' [MulLeftStrictMono α] [MulRightStrictMono α] (hf : StrictMono f) (hg : StrictMono g) : StrictMono fun x => f x * g x := fun _ _ ab => mul_lt_mul_of_lt_of_lt (hf ab) (hg ab) /-- The product of two strictly monotone functions is strictly monotone. -/ @[to_additive add "The sum of two strictly monotone functions is strictly monotone."] theorem StrictMonoOn.mul' [MulLeftStrictMono α] [MulRightStrictMono α] (hf : StrictMonoOn f s) (hg : StrictMonoOn g s) : StrictMonoOn (fun x => f x * g x) s := fun _ ha _ hb ab => mul_lt_mul_of_lt_of_lt (hf ha hb ab) (hg ha hb ab) /-- The product of two strictly antitone functions is strictly antitone. -/ @[to_additive add "The sum of two strictly antitone functions is strictly antitone."] theorem StrictAnti.mul' [MulLeftStrictMono α] [MulRightStrictMono α] (hf : StrictAnti f) (hg : StrictAnti g) : StrictAnti fun x => f x * g x := fun _ _ ab => mul_lt_mul_of_lt_of_lt (hf ab) (hg ab) /-- The product of two strictly antitone functions is strictly antitone. -/ @[to_additive add "The sum of two strictly antitone functions is strictly antitone."] theorem StrictAntiOn.mul' [MulLeftStrictMono α] [MulRightStrictMono α] (hf : StrictAntiOn f s) (hg : StrictAntiOn g s) : StrictAntiOn (fun x => f x * g x) s := fun _ ha _ hb ab => mul_lt_mul_of_lt_of_lt (hf ha hb ab) (hg ha hb ab) /-- The product of a monotone function and a strictly monotone function is strictly monotone. -/ @[to_additive add_strictMono "The sum of a monotone function and a strictly monotone function is strictly monotone."] theorem Monotone.mul_strictMono' [MulLeftStrictMono α] [MulRightMono α] {f g : β → α} (hf : Monotone f) (hg : StrictMono g) : StrictMono fun x => f x * g x := fun _ _ h => mul_lt_mul_of_le_of_lt (hf h.le) (hg h) /-- The product of a monotone function and a strictly monotone function is strictly monotone. -/ @[to_additive add_strictMono "The sum of a monotone function and a strictly monotone function is strictly monotone."] theorem MonotoneOn.mul_strictMono' [MulLeftStrictMono α] [MulRightMono α] {f g : β → α} (hf : MonotoneOn f s) (hg : StrictMonoOn g s) : StrictMonoOn (fun x => f x * g x) s := fun _ hx _ hy h => mul_lt_mul_of_le_of_lt (hf hx hy h.le) (hg hx hy h) /-- The product of an antitone function and a strictly antitone function is strictly antitone. -/ @[to_additive add_strictAnti "The sum of an antitone function and a strictly antitone function is strictly antitone."] theorem Antitone.mul_strictAnti' [MulLeftStrictMono α] [MulRightMono α] {f g : β → α} (hf : Antitone f) (hg : StrictAnti g) : StrictAnti fun x => f x * g x := fun _ _ h => mul_lt_mul_of_le_of_lt (hf h.le) (hg h) /-- The product of an antitone function and a strictly antitone function is strictly antitone. -/ @[to_additive add_strictAnti "The sum of an antitone function and a strictly antitone function is strictly antitone."] theorem AntitoneOn.mul_strictAnti' [MulLeftStrictMono α] [MulRightMono α] {f g : β → α} (hf : AntitoneOn f s) (hg : StrictAntiOn g s) : StrictAntiOn (fun x => f x * g x) s := fun _ hx _ hy h => mul_lt_mul_of_le_of_lt (hf hx hy h.le) (hg hx hy h) variable [MulLeftMono α] [MulRightStrictMono α] /-- The product of a strictly monotone function and a monotone function is strictly monotone. -/ @[to_additive add_monotone "The sum of a strictly monotone function and a monotone function is strictly monotone."] theorem StrictMono.mul_monotone' (hf : StrictMono f) (hg : Monotone g) : StrictMono fun x => f x * g x := fun _ _ h => mul_lt_mul_of_lt_of_le (hf h) (hg h.le) /-- The product of a strictly monotone function and a monotone function is strictly monotone. -/ @[to_additive add_monotone "The sum of a strictly monotone function and a monotone function is strictly monotone."] theorem StrictMonoOn.mul_monotone' (hf : StrictMonoOn f s) (hg : MonotoneOn g s) : StrictMonoOn (fun x => f x * g x) s := fun _ hx _ hy h => mul_lt_mul_of_lt_of_le (hf hx hy h) (hg hx hy h.le) /-- The product of a strictly antitone function and an antitone function is strictly antitone. -/ @[to_additive add_antitone "The sum of a strictly antitone function and an antitone function is strictly antitone."] theorem StrictAnti.mul_antitone' (hf : StrictAnti f) (hg : Antitone g) : StrictAnti fun x => f x * g x := fun _ _ h => mul_lt_mul_of_lt_of_le (hf h) (hg h.le) /-- The product of a strictly antitone function and an antitone function is strictly antitone. -/ @[to_additive add_antitone "The sum of a strictly antitone function and an antitone function is strictly antitone."] theorem StrictAntiOn.mul_antitone' (hf : StrictAntiOn f s) (hg : AntitoneOn g s) : StrictAntiOn (fun x => f x * g x) s := fun _ hx _ hy h => mul_lt_mul_of_lt_of_le (hf hx hy h) (hg hx hy h.le) @[to_additive (attr := simp) cmp_add_left] theorem cmp_mul_left' {α : Type*} [Mul α] [LinearOrder α] [MulLeftStrictMono α] (a b c : α) : cmp (a * b) (a * c) = cmp b c := (strictMono_id.const_mul' a).cmp_map_eq b c @[to_additive (attr := simp) cmp_add_right] theorem cmp_mul_right' {α : Type*} [Mul α] [LinearOrder α] [MulRightStrictMono α] (a b c : α) : cmp (a * c) (b * c) = cmp a b := (strictMono_id.mul_const' c).cmp_map_eq a b end Mono /-- An element `a : α` is `MulLECancellable` if `x ↦ a * x` is order-reflecting. We will make a separate version of many lemmas that require `[MulLeftReflectLE α]` with `MulLECancellable` assumptions instead. These lemmas can then be instantiated to specific types, like `ENNReal`, where we can replace the assumption `AddLECancellable x` by `x ≠ ∞`. -/ @[to_additive "An element `a : α` is `AddLECancellable` if `x ↦ a + x` is order-reflecting. We will make a separate version of many lemmas that require `[MulLeftReflectLE α]` with `AddLECancellable` assumptions instead. These lemmas can then be instantiated to specific types, like `ENNReal`, where we can replace the assumption `AddLECancellable x` by `x ≠ ∞`. "] def MulLECancellable [Mul α] [LE α] (a : α) : Prop := ∀ ⦃b c⦄, a * b ≤ a * c → b ≤ c @[to_additive] theorem Contravariant.MulLECancellable [Mul α] [LE α] [MulLeftReflectLE α] {a : α} : MulLECancellable a := fun _ _ => le_of_mul_le_mul_left' @[to_additive (attr := simp)] theorem mulLECancellable_one [MulOneClass α] [LE α] : MulLECancellable (1 : α) := fun a b => by simpa only [one_mul] using id namespace MulLECancellable @[to_additive] protected theorem Injective [Mul α] [PartialOrder α] {a : α} (ha : MulLECancellable a) : Injective (a * ·) := fun _ _ h => le_antisymm (ha h.le) (ha h.ge) @[to_additive] protected theorem inj [Mul α] [PartialOrder α] {a b c : α} (ha : MulLECancellable a) : a * b = a * c ↔ b = c := ha.Injective.eq_iff @[to_additive] protected theorem injective_left [Mul α] [i : @Std.Commutative α (· * ·)] [PartialOrder α] {a : α} (ha : MulLECancellable a) : Injective (· * a) := fun b c h => ha.Injective <| by dsimp; rwa [i.comm a, i.comm a] @[to_additive] protected theorem inj_left [Mul α] [@Std.Commutative α (· * ·)] [PartialOrder α] {a b c : α} (hc : MulLECancellable c) : a * c = b * c ↔ a = b := hc.injective_left.eq_iff variable [LE α] @[to_additive] protected theorem mul_le_mul_iff_left [Mul α] [MulLeftMono α] {a b c : α} (ha : MulLECancellable a) : a * b ≤ a * c ↔ b ≤ c := ⟨fun h => ha h, fun h => mul_le_mul_left' h a⟩ @[to_additive] protected theorem mul_le_mul_iff_right [Mul α] [i : @Std.Commutative α (· * ·)] [MulLeftMono α] {a b c : α} (ha : MulLECancellable a) : b * a ≤ c * a ↔ b ≤ c := by rw [i.comm b, i.comm c, ha.mul_le_mul_iff_left] @[to_additive] protected theorem le_mul_iff_one_le_right [MulOneClass α] [MulLeftMono α] {a b : α} (ha : MulLECancellable a) : a ≤ a * b ↔ 1 ≤ b := Iff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left @[to_additive] protected theorem mul_le_iff_le_one_right [MulOneClass α] [MulLeftMono α] {a b : α} (ha : MulLECancellable a) : a * b ≤ a ↔ b ≤ 1 := Iff.trans (by rw [mul_one]) ha.mul_le_mul_iff_left @[to_additive] protected theorem le_mul_iff_one_le_left [MulOneClass α] [i : @Std.Commutative α (· * ·)] [MulLeftMono α] {a b : α} (ha : MulLECancellable a) : a ≤ b * a ↔ 1 ≤ b := by rw [i.comm, ha.le_mul_iff_one_le_right] @[to_additive] protected theorem mul_le_iff_le_one_left [MulOneClass α] [i : @Std.Commutative α (· * ·)] [MulLeftMono α] {a b : α} (ha : MulLECancellable a) : b * a ≤ a ↔ b ≤ 1 := by rw [i.comm, ha.mul_le_iff_le_one_right] @[to_additive] lemma mul [Semigroup α] {a b : α} (ha : MulLECancellable a) (hb : MulLECancellable b) : MulLECancellable (a * b) := fun c d hcd ↦ hb <| ha <| by rwa [← mul_assoc, ← mul_assoc] @[to_additive] lemma of_mul_right [Semigroup α] [MulLeftMono α] {a b : α} (h : MulLECancellable (a * b)) : MulLECancellable b := fun c d hcd ↦ h <| by rw [mul_assoc, mul_assoc]; exact mul_le_mul_left' hcd _ @[to_additive] lemma of_mul_left [CommSemigroup α] [MulLeftMono α] {a b : α} (h : MulLECancellable (a * b)) : MulLECancellable a := (mul_comm a b ▸ h).of_mul_right end MulLECancellable @[to_additive (attr := simp)] lemma mulLECancellable_mul [LE α] [CommSemigroup α] [MulLeftMono α] {a b : α} : MulLECancellable (a * b) ↔ MulLECancellable a ∧ MulLECancellable b := ⟨fun h ↦ ⟨h.of_mul_left, h.of_mul_right⟩, fun h ↦ h.1.mul h.2⟩
Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean
1,632
1,634
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Mario Carneiro -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds /-! # Pi This file contains lemmas which establish bounds on `Real.pi`. Notably, these include `pi_gt_sqrtTwoAddSeries` and `pi_lt_sqrtTwoAddSeries`, which bound `π` using series; numerical bounds on `π` such as `pi_gt_d2` and `pi_lt_d2` (more precise versions are given, too). See also `Mathlib/Data/Real/Pi/Leibniz.lean` and `Mathlib/Data/Real/Pi/Wallis.lean` for infinite formulas for `π`. -/ open scoped Real namespace Real theorem pi_gt_sqrtTwoAddSeries (n : ℕ) : 2 ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) < π := by have : √(2 - sqrtTwoAddSeries 0 n) / 2 * 2 ^ (n + 2) < π := by rw [← lt_div_iff₀, ← sin_pi_over_two_pow_succ] focus apply sin_lt apply div_pos pi_pos all_goals apply pow_pos; norm_num refine lt_of_le_of_lt (le_of_eq ?_) this rw [pow_succ' _ (n + 1), ← mul_assoc, div_mul_cancel₀, mul_comm]; norm_num theorem pi_lt_sqrtTwoAddSeries (n : ℕ) : π < 2 ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) + 1 / 4 ^ n := by have : π < (√(2 - sqrtTwoAddSeries 0 n) / 2 + 1 / (2 ^ n) ^ 3 / 4) * (2 : ℝ) ^ (n + 2) := by rw [← div_lt_iff₀ (by norm_num), ← sin_pi_over_two_pow_succ, ← sub_lt_iff_lt_add'] calc π / 2 ^ (n + 2) - sin (π / 2 ^ (n + 2)) < (π / 2 ^ (n + 2)) ^ 3 / 4 := sub_lt_comm.1 <| sin_gt_sub_cube (by positivity) <| div_le_one_of_le₀ ?_ (by positivity) _ ≤ (4 / 2 ^ (n + 2)) ^ 3 / 4 := by gcongr; exact pi_le_four _ = 1 / (2 ^ n) ^ 3 / 4 := by simp [add_comm n, pow_add, div_mul_eq_div_div]; norm_num calc π ≤ 4 := pi_le_four _ = 2 ^ (0 + 2) := by norm_num _ ≤ 2 ^ (n + 2) := by gcongr <;> norm_num refine lt_of_lt_of_le this (le_of_eq ?_); rw [add_mul]; congr 1 · ring simp only [show (4 : ℝ) = 2 ^ 2 by norm_num, ← pow_mul, div_div, ← pow_add] rw [one_div, one_div, inv_mul_eq_iff_eq_mul₀, eq_comm, mul_inv_eq_iff_eq_mul₀, ← pow_add] · rw [add_assoc, Nat.mul_succ, add_comm, add_comm n, add_assoc, mul_comm n] all_goals norm_num /-- From an upper bound on `sqrtTwoAddSeries 0 n = 2 cos (π / 2 ^ (n+1))` of the form `sqrtTwoAddSeries 0 n ≤ 2 - (a / 2 ^ (n + 1)) ^ 2)`, one can deduce the lower bound `a < π` thanks to basic trigonometric inequalities as expressed in `pi_gt_sqrtTwoAddSeries`. -/ theorem pi_lower_bound_start (n : ℕ) {a} (h : sqrtTwoAddSeries ((0 : ℕ) / (1 : ℕ)) n ≤ (2 : ℝ) - (a / (2 : ℝ) ^ (n + 1)) ^ 2) : a < π := by refine lt_of_le_of_lt ?_ (pi_gt_sqrtTwoAddSeries n); rw [mul_comm] refine (div_le_iff₀ (pow_pos (by norm_num) _)).mp (le_sqrt_of_sq_le ?_) rwa [le_sub_comm, show (0 : ℝ) = (0 : ℕ) / (1 : ℕ) by rw [Nat.cast_zero, zero_div]] theorem sqrtTwoAddSeries_step_up (c d : ℕ) {a b n : ℕ} {z : ℝ} (hz : sqrtTwoAddSeries (c / d) n ≤ z) (hb : 0 < b) (hd : 0 < d) (h : (2 * b + a) * d ^ 2 ≤ c ^ 2 * b) : sqrtTwoAddSeries (a / b) (n + 1) ≤ z := by refine le_trans ?_ hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [sqrt_le_left (div_nonneg c.cast_nonneg d.cast_nonneg), div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hb'), div_le_div_iff₀ hb' (pow_pos hd' _)] exact mod_cast h /-- From a lower bound on `sqrtTwoAddSeries 0 n = 2 cos (π / 2 ^ (n+1))` of the form `2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 ≤ sqrtTwoAddSeries 0 n`, one can deduce the upper bound `π < a` thanks to basic trigonometric formulas as expressed in `pi_lt_sqrtTwoAddSeries`. -/ theorem pi_upper_bound_start (n : ℕ) {a} (h : (2 : ℝ) - ((a - 1 / (4 : ℝ) ^ n) / (2 : ℝ) ^ (n + 1)) ^ 2 ≤ sqrtTwoAddSeries ((0 : ℕ) / (1 : ℕ)) n) (h₂ : (1 : ℝ) / (4 : ℝ) ^ n ≤ a) : π < a := by refine lt_of_lt_of_le (pi_lt_sqrtTwoAddSeries n) ?_ rw [← le_sub_iff_add_le, ← le_div_iff₀', sqrt_le_left, sub_le_comm] · rwa [Nat.cast_zero, zero_div] at h · exact div_nonneg (sub_nonneg.2 h₂) (pow_nonneg (le_of_lt zero_lt_two) _) · exact pow_pos zero_lt_two _ theorem sqrtTwoAddSeries_step_down (a b : ℕ) {c d n : ℕ} {z : ℝ} (hz : z ≤ sqrtTwoAddSeries (a / b) n) (hb : 0 < b) (hd : 0 < d) (h : a ^ 2 * d ≤ (2 * d + c) * b ^ 2) : z ≤ sqrtTwoAddSeries (c / d) (n + 1) := by apply le_trans hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left apply le_sqrt_of_sq_le have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hd'), div_le_div_iff₀ (pow_pos hb' _) hd'] exact mod_cast h section Tactic open Lean Elab Tactic Qq /-- Create a proof of `a < π` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) ≤ r(i+1)`, where `r 0 = 0` and `√(2 - r n) ≥ a/2^(n+1)`. -/ elab "pi_lower_bound " "[" l:term,* "]" : tactic => do have els := l.getElems let n := quote els.size evalTactic (← `(tactic| apply pi_lower_bound_start $n)) for l in els do let {num, den, ..} ← unsafe Meta.evalExpr ℚ q(ℚ) (← Term.elabTermAndSynthesize l (some q(ℚ))) evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_up $(quote num.toNat) $(quote den))) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals <| evalTactic (← `(tactic| norm_num1)) /-- Create a proof of `π < a` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) ≥ r(i+1)`, where `r 0 = 0` and `√(2 - r n) ≤ (a - 1/4^n) / 2^(n+1)`. -/ elab "pi_upper_bound " "[" l:term,* "]" : tactic => do have els := l.getElems let n := quote els.size evalTactic (← `(tactic| apply pi_upper_bound_start $n)) for l in els do let {num, den, ..} ← unsafe Meta.evalExpr ℚ q(ℚ) (← Term.elabTermAndSynthesize l (some q(ℚ))) evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_down $(quote num.toNat) $(quote den))) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals <| evalTactic (← `(tactic| norm_num1)) end Tactic /-! The below witnesses were generated using the following Mathematica script: ```mathematica bound[a_, Iters -> n_, Rounding -> extra_, Precision -> prec_] := Module[{r0, r, r2, diff, sign}, On[Assert]; sign = If[a >= \[Pi], Print["upper"]; 1, Print["lower"]; -1]; r0 = 2 - ((a - (sign + 1)/2/4^n)/2^(n + 1))^2; r = Log[2 - NestList[#^2 - 2 &, N[r0, prec], n - 1]]; diff = (r[[-1]] - Log[2 - Sqrt[2]])/(Length[r] + 1); If[sign diff <= 0, Return["insufficient iterations"]]; r2 = Log[Rationalize[Exp[#], extra (Exp[#] - Exp[# - sign diff])] & /@ (r - diff Range[1, Length[r]])]; Assert[sign (2 - Exp@r2[[1]] - r0) >= 0]; Assert[And @@ Table[ sign (Sqrt@(4 - Exp@r2[[i + 1]]) - (2 - Exp@r2[[i]])) >= 0, {i, 1, Length[r2] - 1}]]; Assert[sign (Exp@r2[[-1]] - (2 - Sqrt[2])) >= 0]; With[{s1 = ToString@InputForm[2 - #], s2 = ToString@InputForm[#]}, If[StringLength[s1] <= StringLength[s2] + 2, s1, "2-" <> s2]] & /@ Exp@Reverse@r2 ]; ``` -/ theorem pi_gt_three : 3 < π := by -- bound[3, Iters -> 1, Rounding -> 2, Precision -> 3] pi_lower_bound [23 / 16] theorem pi_lt_four : π < 4 := by -- bound[4, Iters -> 1, Rounding -> 1, Precision -> 1] pi_upper_bound [4 / 3] theorem pi_gt_d2 : 3.14 < π := by -- bound[314*^-2, Iters -> 4, Rounding -> 1.5, Precision -> 8] pi_lower_bound [338 / 239, 704 / 381, 1940 / 989, 1447 / 727] theorem pi_lt_d2 : π < 3.15 := by -- bound[315*^-2, Iters -> 4, Rounding -> 1.4, Precision -> 7] pi_upper_bound [41 / 29, 109 / 59, 865 / 441, 412 / 207] theorem pi_gt_d4 : 3.1415 < π := by -- bound[31415*^-4, Iters -> 6, Rounding -> 1.1, Precision -> 10] pi_lower_bound [ 1970 / 1393, 3010 / 1629, 11689 / 5959, 10127 / 5088, 33997 / 17019, 23235 / 11621] theorem pi_lt_d4 : π < 3.1416 := by -- bound[31416*^-4, Iters -> 9, Rounding -> .9, Precision -> 16] pi_upper_bound [ 4756/3363, 14965/8099, 21183/10799, 49188/24713, 2-53/22000, 2-71/117869, 2-47/312092, 2-17/451533, 2-4/424971] theorem pi_gt_d6 : 3.141592 < π := by -- bound[3141592*^-6, Iters -> 10, Rounding -> .8, Precision -> 16] pi_lower_bound [ 11482/8119, 7792/4217, 54055/27557, 2-623/64690, 2-337/139887, 2-208/345307, 2-167/1108925, 2-64/1699893, 2-31/3293535, 2-48/20398657] theorem pi_lt_d6 : π < 3.141593 := by -- bound[3141593*^-6, Iters -> 11, Rounding -> .5, Precision -> 17] pi_upper_bound [ 35839/25342, 49143/26596, 145729/74292, 294095/147759, 2-137/56868, 2-471/781921, 2-153/1015961,
2-157/4170049, 2-28/2974805, 2-9/3824747, 2-7/11899211] theorem pi_gt_d20 : 3.14159265358979323846 < π := by -- bound[314159265358979323846*^-20, Iters -> 34, Rounding -> .6, Precision -> 46]
Mathlib/Data/Real/Pi/Bounds.lean
188
191
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FormalMultilinearSeries import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Tactic.Bound.Attribute import Mathlib.Topology.Algebra.InfiniteSum.Module /-! # Analytic functions A function is analytic in one dimension around `0` if it can be written as a converging power series `Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not always possible in nonzero characteristic (in characteristic 2, the previous example has no symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition, and we only require the existence of a converging series. The general framework is important to say that the exponential map on bounded operators on a Banach space is analytic, as well as the inverse on invertible operators. ## Main definitions Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n` for `n : ℕ`. * `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially. * `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `‖p n‖ * r ^ n` is bounded above, then `r ≤ p.radius`; * `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.isLittleO_one_of_lt_radius`, `p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then `‖p n‖ * r ^ n` tends to zero exponentially; * `p.lt_radius_of_isBigO`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then `r < p.radius`; * `p.partialSum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`. * `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`. Additionally, let `f` be a function from `E` to `F`. * `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`, `f (x + y) = ∑'_n pₙ yⁿ`. * `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds `HasFPowerSeriesOnBall f p x r`. * `AnalyticAt 𝕜 f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`. * `AnalyticOnNhd 𝕜 f s`: the function `f` is analytic at every point of `s`. We also define versions of `HasFPowerSeriesOnBall`, `AnalyticAt`, and `AnalyticOnNhd` restricted to a set, similar to `ContinuousWithinAt`. See `Mathlib.Analysis.Analytic.Within` for basic properties. * `AnalyticWithinAt 𝕜 f s x` means a power series at `x` converges to `f` on `𝓝[s ∪ {x}] x`. * `AnalyticOn 𝕜 f s t` means `∀ x ∈ t, AnalyticWithinAt 𝕜 f s x`. We develop the basic properties of these notions, notably: * If a function admits a power series, it is continuous (see `HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and `AnalyticAt.continuousAt`). * In a complete space, the sum of a formal power series with positive radius is well defined on the disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`. ## Implementation details We only introduce the radius of convergence of a power series, as `p.radius`. For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent) notion, describing the polydisk of convergence. This notion is more specific, and not necessary to build the general theory. We do not define it here. -/ noncomputable section variable {𝕜 E F G : Type*} open Topology NNReal Filter ENNReal Set Asymptotics namespace FormalMultilinearSeries variable [Semiring 𝕜] [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] variable [TopologicalSpace E] [TopologicalSpace F] variable [ContinuousAdd E] [ContinuousAdd F] variable [ContinuousConstSMul 𝕜 E] [ContinuousConstSMul 𝕜 F] /-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A priori, it only behaves well when `‖x‖ < p.radius`. -/ protected def sum (p : FormalMultilinearSeries 𝕜 E F) (x : E) : F := ∑' n : ℕ, p n fun _ => x /-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum `Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/ def partialSum (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (x : E) : F := ∑ k ∈ Finset.range n, p k fun _ : Fin k => x /-- The partial sums of a formal multilinear series are continuous. -/ theorem partialSum_continuous (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) : Continuous (p.partialSum n) := by unfold partialSum fun_prop end FormalMultilinearSeries /-! ### The radius of a formal multilinear series -/ variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] namespace FormalMultilinearSeries variable (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} /-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ` converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these definitions are *not* equivalent in general. -/ def radius (p : FormalMultilinearSeries 𝕜 E F) : ℝ≥0∞ := ⨆ (r : ℝ≥0) (C : ℝ) (_ : ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C), (r : ℝ≥0∞) /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖ * (r : ℝ) ^ n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝ≥0∞)) h /-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖₊ * r ^ n ≤ C) : (r : ℝ≥0∞) ≤ p.radius := p.le_radius_of_bound C fun n => mod_cast h n /-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_isBigO (h : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : ↑r ≤ p.radius := Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC => p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n) theorem le_radius_of_eventually_le (C) (h : ∀ᶠ n in atTop, ‖p n‖ * (r : ℝ) ^ n ≤ C) : ↑r ≤ p.radius := p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa theorem le_radius_of_summable_nnnorm (h : Summable fun n => ‖p n‖₊ * r ^ n) : ↑r ≤ p.radius := p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) fun _ => h.le_tsum' _ theorem le_radius_of_summable (h : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius := p.le_radius_of_summable_nnnorm <| by simp only [← coe_nnnorm] at h exact mod_cast h theorem radius_eq_top_of_forall_nnreal_isBigO (h : ∀ r : ℝ≥0, (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_isBigO (h r) theorem radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in atTop, p n = 0) : p.radius = ∞ := p.radius_eq_top_of_forall_nnreal_isBigO fun r => (isBigO_zero _ _).congr' (h.mono fun n hn => by simp [hn]) EventuallyEq.rfl theorem radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ := p.radius_eq_top_of_eventually_eq_zero <| mem_atTop_sets.2 ⟨n, fun _ hk => tsub_add_cancel_of_le hk ▸ hn _⟩ @[simp] theorem constFormalMultilinearSeries_radius {v : F} : (constFormalMultilinearSeries 𝕜 E v).radius = ⊤ := (constFormalMultilinearSeries 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1 (by simp [constFormalMultilinearSeries]) /-- `0` has infinite radius of convergence -/ @[simp] lemma zero_radius : (0 : FormalMultilinearSeries 𝕜 E F).radius = ∞ := by rw [← constFormalMultilinearSeries_zero] exact constFormalMultilinearSeries_radius /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/ theorem isLittleO_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (a ^ ·) := by have := (TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4 rw [this] -- Porting note: was -- rw [(TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4] simp only [radius, lt_iSup_iff] at h rcases h with ⟨t, C, hC, rt⟩ rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at rt have : 0 < (t : ℝ) := r.coe_nonneg.trans_lt rt rw [← div_lt_one this] at rt refine ⟨_, rt, C, Or.inr zero_lt_one, fun n => ?_⟩ calc |‖p n‖ * (r : ℝ) ^ n| = ‖p n‖ * (t : ℝ) ^ n * (r / t : ℝ) ^ n := by field_simp [mul_right_comm, abs_mul] _ ≤ C * (r / t : ℝ) ^ n := by gcongr; apply hC /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/ theorem isLittleO_one_of_lt_radius (h : ↑r < p.radius) : (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (fun _ => 1 : ℕ → ℝ) := let ⟨_, ha, hp⟩ := p.isLittleO_of_lt_radius h hp.trans <| (isLittleO_pow_pow_of_lt_left ha.1.le ha.2).congr (fun _ => rfl) one_pow /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially: for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/ theorem norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C * a ^ n := by have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 5).mp (p.isLittleO_of_lt_radius h) rcases this with ⟨a, ha, C, hC, H⟩ exact ⟨a, ha, C, hC, fun n => (le_abs_self _).trans (H n)⟩ /-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/ theorem lt_radius_of_isBigO (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1) (hp : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] (a ^ ·)) : ↑r < p.radius := by have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 2 5) rcases this.mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩ rw [← pos_iff_ne_zero, ← NNReal.coe_pos] at h₀ lift a to ℝ≥0 using ha.1.le have : (r : ℝ) < r / a := by simpa only [div_one] using (div_lt_div_iff_of_pos_left h₀ zero_lt_one ha.1).2 ha.2 norm_cast at this rw [← ENNReal.coe_lt_coe] at this refine this.trans_le (p.le_radius_of_bound C fun n => ?_) rw [NNReal.coe_div, div_pow, ← mul_div_assoc, div_le_iff₀ (pow_pos ha.1 n)] exact (le_abs_self _).trans (hp n) /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem norm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C := let ⟨_, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h ⟨C, hC, fun n => (h n).trans <| mul_le_of_le_one_right hC.lt.le (pow_le_one₀ ha.1.le ha.2.le)⟩ /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem norm_le_div_pow_of_pos_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / (r : ℝ) ^ n := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h ⟨C, hC, fun n => Iff.mpr (le_div_iff₀ (pow_pos h0 _)) (hp n)⟩ /-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/ theorem nnnorm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r ^ n ≤ C := let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h ⟨⟨C, hC.lt.le⟩, hC, mod_cast hp⟩ theorem le_radius_of_tendsto (p : FormalMultilinearSeries 𝕜 E F) {l : ℝ} (h : Tendsto (fun n => ‖p n‖ * (r : ℝ) ^ n) atTop (𝓝 l)) : ↑r ≤ p.radius := p.le_radius_of_isBigO (h.isBigO_one _) theorem le_radius_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F) (hs : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius := p.le_radius_of_tendsto hs.tendsto_atTop_zero theorem not_summable_norm_of_radius_lt_nnnorm (p : FormalMultilinearSeries 𝕜 E F) {x : E} (h : p.radius < ‖x‖₊) : ¬Summable fun n => ‖p n‖ * ‖x‖ ^ n := fun hs => not_le_of_lt h (p.le_radius_of_summable_norm hs) theorem summable_norm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : Summable fun n : ℕ => ‖p n‖ * (r : ℝ) ^ n := by obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h exact .of_nonneg_of_le (fun n => mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) theorem summable_norm_apply (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => ‖p n fun _ => x‖ := by rw [mem_emetric_ball_zero_iff] at hx refine .of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun n ↦ ((p n).le_opNorm _).trans_eq ?_) (p.summable_norm_mul_pow hx) simp theorem summable_nnnorm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) : Summable fun n : ℕ => ‖p n‖₊ * r ^ n := by rw [← NNReal.summable_coe] push_cast exact p.summable_norm_mul_pow h protected theorem summable [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E} (hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => p n fun _ => x := (p.summable_norm_apply hx).of_norm theorem radius_eq_top_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F) (hs : ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : p.radius = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_summable_norm (hs r) theorem radius_eq_top_iff_summable_norm (p : FormalMultilinearSeries 𝕜 E F) : p.radius = ∞ ↔ ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n := by constructor · intro h r obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius (show (r : ℝ≥0∞) < p.radius from h.symm ▸ ENNReal.coe_lt_top) refine .of_norm_bounded (fun n ↦ (C : ℝ) * a ^ n) ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) fun n ↦ ?_ specialize hp n rwa [Real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n))] · exact p.radius_eq_top_of_summable_norm /-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/ theorem le_mul_pow_of_radius_pos (p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) : ∃ (C r : _) (_ : 0 < C) (_ : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n := by rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩ have rpos : 0 < (r : ℝ) := by simp [ENNReal.coe_pos.1 r0] rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩ refine ⟨C, r⁻¹, Cpos, by simp only [inv_pos, rpos], fun n => ?_⟩ rw [inv_pow, ← div_eq_mul_inv] exact hCp n lemma radius_le_of_le {𝕜' E' F' : Type*} [NontriviallyNormedField 𝕜'] [NormedAddCommGroup E'] [NormedSpace 𝕜' E'] [NormedAddCommGroup F'] [NormedSpace 𝕜' F'] {p : FormalMultilinearSeries 𝕜 E F} {q : FormalMultilinearSeries 𝕜' E' F'} (h : ∀ n, ‖p n‖ ≤ ‖q n‖) : q.radius ≤ p.radius := by apply le_of_forall_nnreal_lt (fun r hr ↦ ?_) rcases norm_mul_pow_le_of_lt_radius _ hr with ⟨C, -, hC⟩ apply le_radius_of_bound _ C (fun n ↦ ?_) apply le_trans _ (hC n) gcongr exact h n /-- The radius of the sum of two formal series is at least the minimum of their two radii. -/ theorem min_radius_le_radius_add (p q : FormalMultilinearSeries 𝕜 E F) : min p.radius q.radius ≤ (p + q).radius := by
refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_ rw [lt_min_iff] at hr have := ((p.isLittleO_one_of_lt_radius hr.1).add (q.isLittleO_one_of_lt_radius hr.2)).isBigO refine (p + q).le_radius_of_isBigO ((isBigO_of_le _ fun n => ?_).trans this) rw [← add_mul, norm_mul, norm_mul, norm_norm] exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _) @[simp] theorem radius_neg (p : FormalMultilinearSeries 𝕜 E F) : (-p).radius = p.radius := by simp only [radius, neg_apply, norm_neg]
Mathlib/Analysis/Analytic/Basic.lean
315
325
/- Copyright (c) 2023 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Dagur Asgeirsson -/ import Mathlib.Topology.Category.Profinite.Basic import Mathlib.Topology.Category.CompHausLike.Limits /-! # Explicit limits and colimits This file applies the general API for explicit limits and colimits in `CompHausLike P` (see the file `Mathlib.Topology.Category.CompHausLike.Limits`) to the special case of `Profinite`. -/ namespace Profinite universe u w open CategoryTheory Limits CompHausLike instance : HasExplicitPullbacks (fun Y ↦ TotallyDisconnectedSpace Y) where hasProp _ _ := { hasProp := show TotallyDisconnectedSpace {_xy : _ | _} from inferInstance} instance : HasExplicitFiniteCoproducts.{w, u} (fun Y ↦ TotallyDisconnectedSpace Y) where hasProp _ := { hasProp := show TotallyDisconnectedSpace (Σ (_a : _), _) from inferInstance} /-- A one-element space is terminal in `Profinite` -/ abbrev isTerminalPUnit : IsTerminal (Profinite.of PUnit.{u + 1}) := CompHausLike.isTerminalPUnit example : FinitaryExtensive Profinite.{u} := inferInstance noncomputable example : PreservesFiniteCoproducts profiniteToCompHaus := inferInstance end Profinite
Mathlib/Topology/Category/Profinite/Limits.lean
169
174
/- 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]
Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean
534
536
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.Ring.Commute import Mathlib.Algebra.Ring.Invertible import Mathlib.Order.Synonym /-! # Lemmas about division (semi)rings and (semi)fields -/ open Function OrderDual Set universe u variable {K L : Type*} section DivisionSemiring variable [DivisionSemiring K] {a b c d : K} theorem add_div (a b c : K) : (a + b) / c = a / c + b / c := by simp_rw [div_eq_mul_inv, add_mul] @[field_simps] theorem div_add_div_same (a b c : K) : a / c + b / c = (a + b) / c := (add_div _ _ _).symm theorem same_add_div (h : b ≠ 0) : (b + a) / b = 1 + a / b := by rw [← div_self h, add_div] theorem div_add_same (h : b ≠ 0) : (a + b) / b = a / b + 1 := by rw [← div_self h, add_div] theorem one_add_div (h : b ≠ 0) : 1 + a / b = (b + a) / b := (same_add_div h).symm theorem div_add_one (h : b ≠ 0) : a / b + 1 = (a + b) / b := (div_add_same h).symm /-- See `inv_add_inv` for the more convenient version when `K` is commutative. -/ theorem inv_add_inv' (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = a⁻¹ * (a + b) * b⁻¹ := let _ := invertibleOfNonzero ha; let _ := invertibleOfNonzero hb; invOf_add_invOf a b theorem one_div_mul_add_mul_one_div_eq_one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a * (a + b) * (1 / b) = 1 / a + 1 / b := by simpa only [one_div] using (inv_add_inv' ha hb).symm theorem add_div_eq_mul_add_div (a b : K) (hc : c ≠ 0) : a + b / c = (a * c + b) / c := (eq_div_iff_mul_eq hc).2 <| by rw [right_distrib, div_mul_cancel₀ _ hc] @[field_simps] theorem add_div' (a b c : K) (hc : c ≠ 0) : b + a / c = (b * c + a) / c := by rw [add_div, mul_div_cancel_right₀ _ hc] @[field_simps] theorem div_add' (a b c : K) (hc : c ≠ 0) : a / c + b = (a + b * c) / c := by rwa [add_comm, add_div', add_comm] protected theorem Commute.div_add_div (hbc : Commute b c) (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b + c / d = (a * d + b * c) / (b * d) := by rw [add_div, mul_div_mul_right _ b hd, hbc.eq, hbd.eq, mul_div_mul_right c d hb] protected theorem Commute.one_div_add_one_div (hab : Commute a b) (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) := by rw [(Commute.one_right a).div_add_div hab ha hb, one_mul, mul_one, add_comm] protected theorem Commute.inv_add_inv (hab : Commute a b) (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = (a + b) / (a * b) := by rw [inv_eq_one_div, inv_eq_one_div, hab.one_div_add_one_div ha hb] variable [NeZero (2 : K)] @[simp] lemma add_self_div_two (a : K) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel_right₀ a two_ne_zero] @[simp] lemma add_halves (a : K) : a / 2 + a / 2 = a := by rw [← add_div, add_self_div_two] end DivisionSemiring section DivisionRing variable [DivisionRing K] {a b c d : K} @[simp] theorem div_neg_self {a : K} (h : a ≠ 0) : a / -a = -1 := by rw [div_neg_eq_neg_div, div_self h] @[simp] theorem neg_div_self {a : K} (h : a ≠ 0) : -a / a = -1 := by rw [neg_div, div_self h] theorem div_sub_div_same (a b c : K) : a / c - b / c = (a - b) / c := by rw [sub_eq_add_neg, ← neg_div, div_add_div_same, sub_eq_add_neg] theorem same_sub_div {a b : K} (h : b ≠ 0) : (b - a) / b = 1 - a / b := by simpa only [← @div_self _ _ b h] using (div_sub_div_same b a b).symm theorem one_sub_div {a b : K} (h : b ≠ 0) : 1 - a / b = (b - a) / b := (same_sub_div h).symm theorem div_sub_same {a b : K} (h : b ≠ 0) : (a - b) / b = a / b - 1 := by simpa only [← @div_self _ _ b h] using (div_sub_div_same a b b).symm theorem div_sub_one {a b : K} (h : b ≠ 0) : a / b - 1 = (a - b) / b := (div_sub_same h).symm theorem sub_div (a b c : K) : (a - b) / c = a / c - b / c := (div_sub_div_same _ _ _).symm /-- See `inv_sub_inv` for the more convenient version when `K` is commutative. -/ theorem inv_sub_inv' {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = a⁻¹ * (b - a) * b⁻¹ := let _ := invertibleOfNonzero ha; let _ := invertibleOfNonzero hb; invOf_sub_invOf a b theorem one_div_mul_sub_mul_one_div_eq_one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a * (b - a) * (1 / b) = 1 / a - 1 / b := by simpa only [one_div] using (inv_sub_inv' ha hb).symm -- see Note [lower instance priority] instance (priority := 100) DivisionRing.isDomain : IsDomain K := NoZeroDivisors.to_isDomain _ protected theorem Commute.div_sub_div (hbc : Commute b c) (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b - c / d = (a * d - b * c) / (b * d) := by simpa only [mul_neg, neg_div, ← sub_eq_add_neg] using hbc.neg_right.div_add_div hbd hb hd protected theorem Commute.inv_sub_inv (hab : Commute a b) (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = (b - a) / (a * b) := by simp only [inv_eq_one_div, (Commute.one_right a).div_sub_div hab ha hb, one_mul, mul_one] variable [NeZero (2 : K)] lemma sub_half (a : K) : a - a / 2 = a / 2 := by rw [sub_eq_iff_eq_add, add_halves] lemma half_sub (a : K) : a / 2 - a = -(a / 2) := by rw [← neg_sub, sub_half] end DivisionRing
section Semifield
Mathlib/Algebra/Field/Basic.lean
138
138
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Yaël Dillies -/ import Mathlib.Analysis.Convex.Cone.Extension import Mathlib.Analysis.Convex.Gauge import Mathlib.Topology.Algebra.Module.FiniteDimension import Mathlib.Topology.Algebra.Module.LocallyConvex import Mathlib.Topology.Algebra.MulAction import Mathlib.Analysis.RCLike.Basic import Mathlib.Analysis.NormedSpace.Extend /-! # Separation Hahn-Banach theorem In this file we prove the geometric Hahn-Banach theorem. For any two disjoint convex sets, there exists a continuous linear functional separating them, geometrically meaning that we can intercalate a plane between them. We provide many variations to stricten the result under more assumptions on the convex sets: * `geometric_hahn_banach_open`: One set is open. Weak separation. * `geometric_hahn_banach_open_point`, `geometric_hahn_banach_point_open`: One set is open, the other is a singleton. Weak separation. * `geometric_hahn_banach_open_open`: Both sets are open. Semistrict separation. * `geometric_hahn_banach_compact_closed`, `geometric_hahn_banach_closed_compact`: One set is closed, the other one is compact. Strict separation. * `geometric_hahn_banach_point_closed`, `geometric_hahn_banach_closed_point`: One set is closed, the other one is a singleton. Strict separation. * `geometric_hahn_banach_point_point`: Both sets are singletons. Strict separation. ## TODO * Eidelheit's theorem * `Convex ℝ s → interior (closure s) ⊆ s` -/ open Set open Pointwise variable {𝕜 E : Type*} /-- Given a set `s` which is a convex neighbourhood of `0` and a point `x₀` outside of it, there is a continuous linear functional `f` separating `x₀` and `s`, in the sense that it sends `x₀` to 1 and all of `s` to values strictly below `1`. -/ theorem separate_convex_open_set [TopologicalSpace E] [AddCommGroup E] [IsTopologicalAddGroup E] [Module ℝ E] [ContinuousSMul ℝ E] {s : Set E} (hs₀ : (0 : E) ∈ s) (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) {x₀ : E} (hx₀ : x₀ ∉ s) : ∃ f : E →L[ℝ] ℝ, f x₀ = 1 ∧ ∀ x ∈ s, f x < 1 := by let f : E →ₗ.[ℝ] ℝ := LinearPMap.mkSpanSingleton x₀ 1 (ne_of_mem_of_not_mem hs₀ hx₀).symm have := exists_extension_of_le_sublinear f (gauge s) (fun c hc => gauge_smul_of_nonneg hc.le) (gauge_add_le hs₁ <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀) ?_ · obtain ⟨φ, hφ₁, hφ₂⟩ := this have hφ₃ : φ x₀ = 1 := by rw [← f.domain.coe_mk x₀ (Submodule.mem_span_singleton_self _), hφ₁, LinearPMap.mkSpanSingleton'_apply_self] have hφ₄ : ∀ x ∈ s, φ x < 1 := fun x hx => (hφ₂ x).trans_lt (gauge_lt_one_of_mem_of_isOpen hs₂ hx) refine ⟨⟨φ, ?_⟩, hφ₃, hφ₄⟩ refine φ.continuous_of_nonzero_on_open _ (hs₂.vadd (-x₀)) (Nonempty.vadd_set ⟨0, hs₀⟩) (vadd_set_subset_iff.mpr fun x hx => ?_) change φ (-x₀ + x) ≠ 0 rw [map_add, map_neg] specialize hφ₄ x hx linarith rintro ⟨x, hx⟩ obtain ⟨y, rfl⟩ := Submodule.mem_span_singleton.1 hx rw [LinearPMap.mkSpanSingleton'_apply] simp only [mul_one, Algebra.id.smul_eq_mul, Submodule.coe_mk] obtain h | h := le_or_lt y 0 · exact h.trans (gauge_nonneg _) · rw [gauge_smul_of_nonneg h.le, smul_eq_mul, le_mul_iff_one_le_right h] exact one_le_gauge_of_not_mem (hs₁.starConvex hs₀) (absorbent_nhds_zero <| hs₂.mem_nhds hs₀).absorbs hx₀ variable [TopologicalSpace E] [AddCommGroup E] [Module ℝ E] {s t : Set E} {x y : E} section variable [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] /-- A version of the **Hahn-Banach theorem**: given disjoint convex sets `s`, `t` where `s` is open, there is a continuous linear functional which separates them. -/ theorem geometric_hahn_banach_open (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) (ht : Convex ℝ t) (disj : Disjoint s t) : ∃ (f : E →L[ℝ] ℝ) (u : ℝ), (∀ a ∈ s, f a < u) ∧ ∀ b ∈ t, u ≤ f b := by obtain rfl | ⟨a₀, ha₀⟩ := s.eq_empty_or_nonempty · exact ⟨0, 0, by simp, fun b _hb => le_rfl⟩ obtain rfl | ⟨b₀, hb₀⟩ := t.eq_empty_or_nonempty · exact ⟨0, 1, fun a _ha => zero_lt_one, by simp⟩ let x₀ := b₀ - a₀ let C := x₀ +ᵥ (s - t) have : (0 : E) ∈ C := ⟨a₀ - b₀, sub_mem_sub ha₀ hb₀, by simp_rw [x₀, vadd_eq_add, sub_add_sub_cancel', sub_self]⟩ have : Convex ℝ C := (hs₁.sub ht).vadd _ have : x₀ ∉ C := by intro hx₀ rw [← add_zero x₀] at hx₀ exact disj.zero_not_mem_sub_set (vadd_mem_vadd_set_iff.1 hx₀) obtain ⟨f, hf₁, hf₂⟩ := separate_convex_open_set ‹0 ∈ C› ‹_› (hs₂.sub_right.vadd _) ‹x₀ ∉ C› have : f b₀ = f a₀ + 1 := by simp [x₀, ← hf₁] have forall_le : ∀ a ∈ s, ∀ b ∈ t, f a ≤ f b := by intro a ha b hb have := hf₂ (x₀ + (a - b)) (vadd_mem_vadd_set <| sub_mem_sub ha hb) simp only [f.map_add, f.map_sub, hf₁] at this linarith refine ⟨f, sInf (f '' t), image_subset_iff.1 (?_ : f '' s ⊆ Iio (sInf (f '' t))), fun b hb => ?_⟩ · rw [← interior_Iic] refine interior_maximal (image_subset_iff.2 fun a ha => ?_) (f.isOpenMap_of_ne_zero ?_ _ hs₂) · exact le_csInf (Nonempty.image _ ⟨_, hb₀⟩) (forall_mem_image.2 <| forall_le _ ha) · rintro rfl simp at hf₁ · exact csInf_le ⟨f a₀, forall_mem_image.2 <| forall_le _ ha₀⟩ (mem_image_of_mem _ hb) theorem geometric_hahn_banach_open_point (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) (disj : x ∉ s) : ∃ f : E →L[ℝ] ℝ, ∀ a ∈ s, f a < f x := let ⟨f, _s, hs, hx⟩ := geometric_hahn_banach_open hs₁ hs₂ (convex_singleton x) (disjoint_singleton_right.2 disj) ⟨f, fun a ha => lt_of_lt_of_le (hs a ha) (hx x (mem_singleton _))⟩ theorem geometric_hahn_banach_point_open (ht₁ : Convex ℝ t) (ht₂ : IsOpen t) (disj : x ∉ t) : ∃ f : E →L[ℝ] ℝ, ∀ b ∈ t, f x < f b := let ⟨f, hf⟩ := geometric_hahn_banach_open_point ht₁ ht₂ disj ⟨-f, by simpa⟩ theorem geometric_hahn_banach_open_open (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) (ht₁ : Convex ℝ t) (ht₃ : IsOpen t) (disj : Disjoint s t) : ∃ (f : E →L[ℝ] ℝ) (u : ℝ), (∀ a ∈ s, f a < u) ∧ ∀ b ∈ t, u < f b := by obtain rfl | ⟨a₀, ha₀⟩ := s.eq_empty_or_nonempty · exact ⟨0, -1, by simp, fun b _hb => by norm_num⟩ obtain rfl | ⟨b₀, hb₀⟩ := t.eq_empty_or_nonempty · exact ⟨0, 1, fun a _ha => by norm_num, by simp⟩ obtain ⟨f, s, hf₁, hf₂⟩ := geometric_hahn_banach_open hs₁ hs₂ ht₁ disj have hf : IsOpenMap f := by refine f.isOpenMap_of_ne_zero ?_ rintro rfl simp_rw [ContinuousLinearMap.zero_apply] at hf₁ hf₂ exact (hf₁ _ ha₀).not_le (hf₂ _ hb₀) refine ⟨f, s, hf₁, image_subset_iff.1 (?_ : f '' t ⊆ Ioi s)⟩ rw [← interior_Ici] refine interior_maximal (image_subset_iff.2 hf₂) (f.isOpenMap_of_ne_zero ?_ _ ht₃) rintro rfl simp_rw [ContinuousLinearMap.zero_apply] at hf₁ hf₂ exact (hf₁ _ ha₀).not_le (hf₂ _ hb₀) variable [LocallyConvexSpace ℝ E] /-- A version of the **Hahn-Banach theorem**: given disjoint convex sets `s`, `t` where `s` is compact and `t` is closed, there is a continuous linear functional which strongly separates them. -/ theorem geometric_hahn_banach_compact_closed (hs₁ : Convex ℝ s) (hs₂ : IsCompact s) (ht₁ : Convex ℝ t) (ht₂ : IsClosed t) (disj : Disjoint s t) : ∃ (f : E →L[ℝ] ℝ) (u v : ℝ), (∀ a ∈ s, f a < u) ∧ u < v ∧ ∀ b ∈ t, v < f b := by obtain rfl | hs := s.eq_empty_or_nonempty · exact ⟨0, -2, -1, by simp, by norm_num, fun b _hb => by norm_num⟩ obtain rfl | _ht := t.eq_empty_or_nonempty · exact ⟨0, 1, 2, fun a _ha => by norm_num, by norm_num, by simp⟩ obtain ⟨U, V, hU, hV, hU₁, hV₁, sU, tV, disj'⟩ := disj.exists_open_convexes hs₁ hs₂ ht₁ ht₂ obtain ⟨f, u, hf₁, hf₂⟩ := geometric_hahn_banach_open_open hU₁ hU hV₁ hV disj' obtain ⟨x, hx₁, hx₂⟩ := hs₂.exists_isMaxOn hs f.continuous.continuousOn have : f x < u := hf₁ x (sU hx₁) exact ⟨f, (f x + u) / 2, u, fun a ha => by have := hx₂ ha; dsimp at this; linarith, by linarith, fun b hb => hf₂ b (tV hb)⟩ /-- A version of the **Hahn-Banach theorem**: given disjoint convex sets `s`, `t` where `s` is closed, and `t` is compact, there is a continuous linear functional which strongly separates them. -/ theorem geometric_hahn_banach_closed_compact (hs₁ : Convex ℝ s) (hs₂ : IsClosed s) (ht₁ : Convex ℝ t) (ht₂ : IsCompact t) (disj : Disjoint s t) : ∃ (f : E →L[ℝ] ℝ) (u v : ℝ), (∀ a ∈ s, f a < u) ∧ u < v ∧ ∀ b ∈ t, v < f b := let ⟨f, s, t, hs, st, ht⟩ := geometric_hahn_banach_compact_closed ht₁ ht₂ hs₁ hs₂ disj.symm ⟨-f, -t, -s, by simpa using ht, by simpa using st, by simpa using hs⟩ theorem geometric_hahn_banach_point_closed (ht₁ : Convex ℝ t) (ht₂ : IsClosed t) (disj : x ∉ t) : ∃ (f : E →L[ℝ] ℝ) (u : ℝ), f x < u ∧ ∀ b ∈ t, u < f b := let ⟨f, _u, v, ha, hst, hb⟩ := geometric_hahn_banach_compact_closed (convex_singleton x) isCompact_singleton ht₁ ht₂ (disjoint_singleton_left.2 disj) ⟨f, v, hst.trans' <| ha x <| mem_singleton _, hb⟩ theorem geometric_hahn_banach_closed_point (hs₁ : Convex ℝ s) (hs₂ : IsClosed s) (disj : x ∉ s) : ∃ (f : E →L[ℝ] ℝ) (u : ℝ), (∀ a ∈ s, f a < u) ∧ u < f x := let ⟨f, s, _t, ha, hst, hb⟩ := geometric_hahn_banach_closed_compact hs₁ hs₂ (convex_singleton x) isCompact_singleton (disjoint_singleton_right.2 disj) ⟨f, s, ha, hst.trans <| hb x <| mem_singleton _⟩ /-- See also `NormedSpace.eq_iff_forall_dual_eq`. -/ theorem geometric_hahn_banach_point_point [T1Space E] (hxy : x ≠ y) : ∃ f : E →L[ℝ] ℝ, f x < f y := by obtain ⟨f, s, t, hs, st, ht⟩ := geometric_hahn_banach_compact_closed (convex_singleton x) isCompact_singleton (convex_singleton y) isClosed_singleton (disjoint_singleton.2 hxy)
exact ⟨f, by linarith [hs x rfl, ht y rfl]⟩ /-- A closed convex set is the intersection of the half-spaces containing it. -/ theorem iInter_halfSpaces_eq (hs₁ : Convex ℝ s) (hs₂ : IsClosed s) : ⋂ l : E →L[ℝ] ℝ, { x | ∃ y ∈ s, l x ≤ l y } = s := by rw [Set.iInter_setOf]
Mathlib/Analysis/NormedSpace/HahnBanach/Separation.lean
198
203
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Regular.Basic import Mathlib.GroupTheory.GroupAction.Hom /-! # Action of regular elements on a module We introduce `M`-regular elements, in the context of an `R`-module `M`. The corresponding predicate is called `IsSMulRegular`. There are very limited typeclass assumptions on `R` and `M`, but the "mathematical" case of interest is a commutative ring `R` acting on a module `M`. Since the properties are "multiplicative", there is no actual requirement of having an addition, but there is a zero in both `R` and `M`. SMultiplications involving `0` are, of course, all trivial. The defining property is that an element `a ∈ R` is `M`-regular if the smultiplication map `M → M`, defined by `m ↦ a • m`, is injective. This property is the direct generalization to modules of the property `IsLeftRegular` defined in `Algebra/Regular`. Lemma `isLeftRegular_iff` shows that indeed the two notions coincide. -/ variable {R S : Type*} (M : Type*) {a b : R} {s : S} /-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an injective map `M → M`. -/ def IsSMulRegular [SMul R M] (c : R) := Function.Injective ((c • ·) : M → M) theorem IsLeftRegular.isSMulRegular [Mul R] {c : R} (h : IsLeftRegular c) : IsSMulRegular R c := h /-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/ theorem isLeftRegular_iff [Mul R] {a : R} : IsLeftRegular a ↔ IsSMulRegular R a := Iff.rfl theorem IsRightRegular.isSMulRegular [Mul R] {c : R} (h : IsRightRegular c) : IsSMulRegular R (MulOpposite.op c) := h /-- Right-regular multiplication on `R` is equivalent to `Rᵐᵒᵖ`-regularity of `R` itself. -/ theorem isRightRegular_iff [Mul R] {a : R} : IsRightRegular a ↔ IsSMulRegular R (MulOpposite.op a) := Iff.rfl namespace IsSMulRegular variable {M} section SMul variable [SMul R M] [SMul R S] [SMul S M] [IsScalarTower R S M] /-- The product of `M`-regular elements is `M`-regular. -/ theorem smul (ra : IsSMulRegular M a) (rs : IsSMulRegular M s) : IsSMulRegular M (a • s) := fun _ _ ab => rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _)))) /-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular element, then `b` is `M`-regular. -/ theorem of_smul (a : R) (ab : IsSMulRegular M (a • s)) : IsSMulRegular M s := @Function.Injective.of_comp _ _ _ (fun m : M => a • m) _ fun c d cd => by dsimp only [Function.comp_def] at cd rw [← smul_assoc, ← smul_assoc] at cd exact ab cd /-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element is `M`-regular. -/ @[simp] theorem smul_iff (b : S) (ha : IsSMulRegular M a) : IsSMulRegular M (a • b) ↔ IsSMulRegular M b := ⟨of_smul _, ha.smul⟩ theorem isLeftRegular [Mul R] {a : R} (h : IsSMulRegular R a) : IsLeftRegular a := h theorem isRightRegular [Mul R] {a : R} (h : IsSMulRegular R (MulOpposite.op a)) : IsRightRegular a := h theorem mul [Mul R] [IsScalarTower R R M] (ra : IsSMulRegular M a) (rb : IsSMulRegular M b) : IsSMulRegular M (a * b) := ra.smul rb theorem of_mul [Mul R] [IsScalarTower R R M] (ab : IsSMulRegular M (a * b)) : IsSMulRegular M b := by rw [← smul_eq_mul] at ab exact ab.of_smul _ @[simp] theorem mul_iff_right [Mul R] [IsScalarTower R R M] (ha : IsSMulRegular M a) : IsSMulRegular M (a * b) ↔ IsSMulRegular M b := ⟨of_mul, ha.mul⟩ /-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a` are `M`-regular. -/ theorem mul_and_mul_iff [Mul R] [IsScalarTower R R M] : IsSMulRegular M (a * b) ∧ IsSMulRegular M (b * a) ↔ IsSMulRegular M a ∧ IsSMulRegular M b := by refine ⟨?_, ?_⟩ · rintro ⟨ab, ba⟩ exact ⟨ba.of_mul, ab.of_mul⟩ · rintro ⟨ha, hb⟩ exact ⟨ha.mul hb, hb.mul ha⟩ lemma of_injective {N F} [SMul R N] [FunLike F M N] [MulActionHomClass F R M N] (f : F) {r : R} (h1 : Function.Injective f) (h2 : IsSMulRegular N r) : IsSMulRegular M r := fun x y h3 => h1 <| h2 <| (map_smulₛₗ f r x).symm.trans ((congrArg f h3).trans (map_smulₛₗ f r y)) end SMul section Monoid variable [Monoid R] [MulAction R M] variable (M) /-- One is always `M`-regular. -/ @[simp] theorem one : IsSMulRegular M (1 : R) := fun a b ab => by dsimp only [Function.comp_def] at ab rw [one_smul, one_smul] at ab assumption variable {M} /-- An element of `R` admitting a left inverse is `M`-regular. -/ theorem of_mul_eq_one (h : a * b = 1) : IsSMulRegular M b := of_mul (a := a) (by rw [h]; exact one M) /-- Any power of an `M`-regular element is `M`-regular. -/ theorem pow (n : ℕ) (ra : IsSMulRegular M a) : IsSMulRegular M (a ^ n) := by induction n with | zero => rw [pow_zero]; simp only [one] | succ n hn => rw [pow_succ'] exact (ra.smul_iff (a ^ n)).mpr hn /-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/ theorem pow_iff {n : ℕ} (n0 : 0 < n) : IsSMulRegular M (a ^ n) ↔ IsSMulRegular M a := by refine ⟨?_, pow n⟩ rw [← Nat.succ_pred_eq_of_pos n0, pow_succ, ← smul_eq_mul] exact of_smul _ end Monoid section MonoidSMul variable [Monoid S] [SMul R M] [SMul R S] [MulAction S M] [IsScalarTower R S M] /-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/ theorem of_smul_eq_one (h : a • s = 1) : IsSMulRegular M s :=
of_smul a (by rw [h] exact one M)
Mathlib/Algebra/Regular/SMul.lean
156
160
/- 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)] lemma map_inv_hom_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) : F.map (e.inv j) ≫ F.map (e.hom j) = 𝟙 _ := by rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id, GradedObject.categoryOfGradedObjects_id, Functor.map_id] @[reassoc (attr := simp)] lemma map_hom_inv_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) : (F.map (e.hom j)).app Y ≫ (F.map (e.inv j)).app Y = 𝟙 _ := by rw [← NatTrans.comp_app, ← F.map_comp, hom_inv_id_eval, Functor.map_id, NatTrans.id_app] @[reassoc (attr := simp)] lemma map_inv_hom_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) : (F.map (e.inv j)).app Y ≫ (F.map (e.hom j)).app Y = 𝟙 _ := by rw [← NatTrans.comp_app, ← F.map_comp, inv_hom_id_eval, Functor.map_id, NatTrans.id_app] end Iso namespace GradedObject variable {C : Type u} [Category.{v} C] section variable (C) /-- Pull back an `I`-graded object in `C` to a `J`-graded object along a function `J → I`. -/ abbrev comap {I J : Type*} (h : J → I) : GradedObject I C ⥤ GradedObject J C := Pi.comap (fun _ => C) h @[simp] theorem eqToHom_proj {I : Type*} {x x' : GradedObject I C} (h : x = x') (i : I) : (eqToHom h : x ⟶ x') i = eqToHom (funext_iff.mp h i) := by subst h rfl /-- The natural isomorphism comparing between pulling back along two propositionally equal functions. -/ @[simps] def comapEq {β γ : Type w} {f g : β → γ} (h : f = g) : comap C f ≅ comap C g where hom := { app := fun X b => eqToHom (by dsimp; simp only [h]) } inv := { app := fun X b => eqToHom (by dsimp; simp only [h]) } theorem comapEq_symm {β γ : Type w} {f g : β → γ} (h : f = g) : comapEq C h.symm = (comapEq C h).symm := by aesop_cat theorem comapEq_trans {β γ : Type w} {f g h : β → γ} (k : f = g) (l : g = h) : comapEq C (k.trans l) = comapEq C k ≪≫ comapEq C l := by aesop_cat theorem eqToHom_apply {β : Type w} {X Y : β → C} (h : X = Y) (b : β) : (eqToHom h : X ⟶ Y) b = eqToHom (by rw [h]) := by subst h rfl /-- The equivalence between β-graded objects and γ-graded objects, given an equivalence between β and γ. -/ @[simps] def comapEquiv {β γ : Type w} (e : β ≃ γ) : GradedObject β C ≌ GradedObject γ C where functor := comap C (e.symm : γ → β) inverse := comap C (e : β → γ) counitIso := (Pi.comapComp (fun _ => C) _ _).trans (comapEq C (by ext; simp)) unitIso := (comapEq C (by ext; simp)).trans (Pi.comapComp _ _ _).symm end instance hasShift {β : Type*} [AddCommGroup β] (s : β) : HasShift (GradedObjectWithShift s C) ℤ := hasShiftMk _ _ { F := fun n => comap C fun b : β => b + n • s zero := comapEq C (by aesop_cat) ≪≫ Pi.comapId β fun _ => C add := fun m n => comapEq C (by ext; dsimp; rw [add_comm m n, add_zsmul, add_assoc]) ≪≫ (Pi.comapComp _ _ _).symm } @[simp] theorem shiftFunctor_obj_apply {β : Type*} [AddCommGroup β] (s : β) (X : β → C) (t : β) (n : ℤ) : (shiftFunctor (GradedObjectWithShift s C) n).obj X t = X (t + n • s) := rfl @[simp] theorem shiftFunctor_map_apply {β : Type*} [AddCommGroup β] (s : β) {X Y : GradedObjectWithShift s C} (f : X ⟶ Y) (t : β) (n : ℤ) : (shiftFunctor (GradedObjectWithShift s C) n).map f t = f (t + n • s) := rfl instance [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) : Zero (X ⟶ Y) := ⟨fun _ => 0⟩ @[simp] theorem zero_apply [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) (b : β) : (0 : X ⟶ Y) b = 0 := rfl instance hasZeroMorphisms [HasZeroMorphisms C] (β : Type w) : HasZeroMorphisms.{max w v} (GradedObject β C) where section open ZeroObject instance hasZeroObject [HasZeroObject C] [HasZeroMorphisms C] (β : Type w) : HasZeroObject.{max w v} (GradedObject β C) := by refine ⟨⟨fun _ => 0, fun X => ⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩⟩⟩ <;> aesop_cat end end GradedObject namespace GradedObject -- The universes get a little hairy here, so we restrict the universe level for the grading to 0. -- Since we're typically interested in grading by ℤ or a finite group, this should be okay. -- If you're grading by things in higher universes, have fun! variable (β : Type) variable (C : Type u) [Category.{v} C] variable [HasCoproducts.{0} C] section /-- The total object of a graded object is the coproduct of the graded components. -/ noncomputable def total : GradedObject β C ⥤ C where obj X := ∐ fun i : β => X i map f := Limits.Sigma.map fun i => f i end variable [HasZeroMorphisms C] /-- The `total` functor taking a graded object to the coproduct of its graded components is faithful. To prove this, we need to know that the coprojections into the coproduct are monomorphisms, which follows from the fact we have zero morphisms and decidable equality for the grading. -/ instance : (total β C).Faithful where map_injective {X Y} f g w := by ext i replace w := Sigma.ι (fun i : β => X i) i ≫= w erw [colimit.ι_map, colimit.ι_map] at w simp? at * says simp only [Discrete.functor_obj_eq_as, Discrete.natTrans_app] at * exact Mono.right_cancellation _ _ w end GradedObject namespace GradedObject noncomputable section variable (β : Type) variable (C : Type (u + 1)) [LargeCategory C] [HasForget C] [HasCoproducts.{0} C] [HasZeroMorphisms C] instance : HasForget (GradedObject β C) where forget := total β C ⋙ forget C instance : HasForget₂ (GradedObject β C) C where forget₂ := total β C end end GradedObject namespace GradedObject variable {I J K : Type*} {C : Type*} [Category C] (X Y Z : GradedObject I C) (φ : X ⟶ Y) (e : X ≅ Y) (ψ : Y ⟶ Z) (p : I → J) /-- If `X : GradedObject I C` and `p : I → J`, `X.mapObjFun p j` is the family of objects `X i` for `i : I` such that `p i = j`. -/ abbrev mapObjFun (j : J) (i : p ⁻¹' {j}) : C := X i variable (j : J) /-- Given `X : GradedObject I C` and `p : I → J`, `X.HasMap p` is the condition that for all `j : J`, the coproduct of all `X i` such `p i = j` exists. -/ abbrev HasMap : Prop := ∀ (j : J), HasCoproduct (X.mapObjFun p j) variable {X Y} in lemma hasMap_of_iso (e : X ≅ Y) (p: I → J) [HasMap X p] : HasMap Y p := fun j => by have α : Discrete.functor (X.mapObjFun p j) ≅ Discrete.functor (Y.mapObjFun p j) := Discrete.natIso (fun ⟨i, _⟩ => (GradedObject.eval i).mapIso e) exact hasColimit_of_iso α.symm section variable [X.HasMap p] [Y.HasMap p] /-- Given `X : GradedObject I C` and `p : I → J`, `X.mapObj p` is the graded object by `J` which in degree `j` consists of the coproduct of the `X i` such that `p i = j`. -/ noncomputable def mapObj : GradedObject J C := fun j => ∐ (X.mapObjFun p j) /-- The canonical inclusion `X i ⟶ X.mapObj p j` when `i : I` and `j : J` are such that `p i = j`. -/ noncomputable def ιMapObj (i : I) (j : J) (hij : p i = j) : X i ⟶ X.mapObj p j := Sigma.ι (X.mapObjFun p j) ⟨i, hij⟩ /-- Given `X : GradedObject I C`, `p : I → J` and `j : J`, `CofanMapObjFun X p j` is the type `Cofan (X.mapObjFun p j)`. The point object of such colimits cofans are isomorphic to `X.mapObj p j`, see `CofanMapObjFun.iso`. -/ abbrev CofanMapObjFun (j : J) : Type _ := Cofan (X.mapObjFun p j) -- in order to use the cofan API, some definitions below -- have a `simp` attribute rather than `simps` /-- Constructor for `CofanMapObjFun X p j`. -/ @[simp] def CofanMapObjFun.mk (j : J) (pt : C) (ι' : ∀ (i : I) (_ : p i = j), X i ⟶ pt) : CofanMapObjFun X p j := Cofan.mk pt (fun ⟨i, hi⟩ => ι' i hi) /-- The tautological cofan corresponding to the coproduct decomposition of `X.mapObj p j`. -/ @[simp] noncomputable def cofanMapObj (j : J) : CofanMapObjFun X p j := CofanMapObjFun.mk X p j (X.mapObj p j) (fun i hi => X.ιMapObj p i j hi) /-- Given `X : GradedObject I C`, `p : I → J` and `j : J`, `X.mapObj p j` satisfies the universal property of the coproduct of those `X i` such that `p i = j`. -/ noncomputable def isColimitCofanMapObj (j : J) : IsColimit (X.cofanMapObj p j) := colimit.isColimit _ @[ext] lemma mapObj_ext {A : C} {j : J} (f g : X.mapObj p j ⟶ A) (hfg : ∀ (i : I) (hij : p i = j), X.ιMapObj p i j hij ≫ f = X.ιMapObj p i j hij ≫ g) : f = g := Cofan.IsColimit.hom_ext (X.isColimitCofanMapObj p j) _ _ (fun ⟨i, hij⟩ => hfg i hij) /-- This is the morphism `X.mapObj p j ⟶ A` constructed from a family of morphisms `X i ⟶ A` for all `i : I` such that `p i = j`. -/ noncomputable def descMapObj {A : C} {j : J} (φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) : X.mapObj p j ⟶ A := Cofan.IsColimit.desc (X.isColimitCofanMapObj p j) (fun ⟨i, hi⟩ => φ i hi) @[reassoc (attr := simp)] lemma ι_descMapObj {A : C} {j : J} (φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) (i : I) (hi : p i = j) : X.ιMapObj p i j hi ≫ X.descMapObj p φ = φ i hi := by apply Cofan.IsColimit.fac end namespace CofanMapObjFun lemma hasMap (c : ∀ j, CofanMapObjFun X p j) (hc : ∀ j, IsColimit (c j)) : X.HasMap p := fun j => ⟨_, hc j⟩ variable {j X p} variable [X.HasMap p] variable {c : CofanMapObjFun X p j} (hc : IsColimit c) /-- If `c : CofanMapObjFun X p j` is a colimit cofan, this is the induced isomorphism `c.pt ≅ X.mapObj p j`. -/ noncomputable def iso : c.pt ≅ X.mapObj p j := IsColimit.coconePointUniqueUpToIso hc (X.isColimitCofanMapObj p j) @[reassoc (attr := simp)] lemma inj_iso_hom (i : I) (hi : p i = j) : c.inj ⟨i, hi⟩ ≫ (c.iso hc).hom = X.ιMapObj p i j hi := by apply IsColimit.comp_coconePointUniqueUpToIso_hom @[reassoc (attr := simp)] lemma ιMapObj_iso_inv (i : I) (hi : p i = j) : X.ιMapObj p i j hi ≫ (c.iso hc).inv = c.inj ⟨i, hi⟩ := by apply IsColimit.comp_coconePointUniqueUpToIso_inv end CofanMapObjFun variable {X Y} variable [X.HasMap p] [Y.HasMap p] /-- The canonical morphism of `J`-graded objects `X.mapObj p ⟶ Y.mapObj p` induced by a morphism `X ⟶ Y` of `I`-graded objects and a map `p : I → J`. -/ noncomputable def mapMap : X.mapObj p ⟶ Y.mapObj p := fun j => X.descMapObj p (fun i hi => φ i ≫ Y.ιMapObj p i j hi) @[reassoc (attr := simp)] lemma ι_mapMap (i : I) (j : J) (hij : p i = j) : X.ιMapObj p i j hij ≫ mapMap φ p j = φ i ≫ Y.ιMapObj p i j hij := by simp only [mapMap, ι_descMapObj]
lemma congr_mapMap (φ₁ φ₂ : X ⟶ Y) (h : φ₁ = φ₂) : mapMap φ₁ p = mapMap φ₂ p := by subst h rfl
Mathlib/CategoryTheory/GradedObject.lean
402
405
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.DirectSum.LinearMap import Mathlib.Algebra.Lie.InvariantForm import Mathlib.Algebra.Lie.Weights.Cartan import Mathlib.Algebra.Lie.Weights.Linear import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.LinearAlgebra.PID /-! # The trace and Killing forms of a Lie algebra. Let `L` be a Lie algebra with coefficients in a commutative ring `R`. Suppose `M` is a finite, free `R`-module and we have a representation `φ : L → End M`. This data induces a natural bilinear form `B` on `L`, called the trace form associated to `M`; it is defined as `B(x, y) = Tr (φ x) (φ y)`. In the special case that `M` is `L` itself and `φ` is the adjoint representation, the trace form is known as the Killing form. We define the trace / Killing form in this file and prove some basic properties. ## Main definitions * `LieModule.traceForm`: a finite, free representation of a Lie algebra `L` induces a bilinear form on `L` called the trace Form. * `LieModule.traceForm_eq_zero_of_isNilpotent`: the trace form induced by a nilpotent representation of a Lie algebra vanishes. * `killingForm`: the adjoint representation of a (finite, free) Lie algebra `L` induces a bilinear form on `L` via the trace form construction. -/ variable (R K L M : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] local notation "φ" => LieModule.toEnd R L M open LinearMap (trace) open Set Module namespace LieModule /-- A finite, free representation of a Lie algebra `L` induces a bilinear form on `L` called the trace Form. See also `killingForm`. -/ noncomputable def traceForm : LinearMap.BilinForm R L := ((LinearMap.mul _ _).compl₁₂ (φ).toLinearMap (φ).toLinearMap).compr₂ (trace R M) lemma traceForm_apply_apply (x y : L) : traceForm R L M x y = trace R _ (φ x ∘ₗ φ y) := rfl lemma traceForm_comm (x y : L) : traceForm R L M x y = traceForm R L M y x := LinearMap.trace_mul_comm R (φ x) (φ y) lemma traceForm_isSymm : LinearMap.IsSymm (traceForm R L M) := LieModule.traceForm_comm R L M @[simp] lemma traceForm_flip : LinearMap.flip (traceForm R L M) = traceForm R L M := Eq.symm <| LinearMap.ext₂ <| traceForm_comm R L M /-- The trace form of a Lie module is compatible with the action of the Lie algebra. See also `LieModule.traceForm_apply_lie_apply'`. -/ lemma traceForm_apply_lie_apply (x y z : L) : traceForm R L M ⁅x, y⁆ z = traceForm R L M x ⁅y, z⁆ := by calc traceForm R L M ⁅x, y⁆ z = trace R _ (φ ⁅x, y⁆ ∘ₗ φ z) := by simp only [traceForm_apply_apply] _ = trace R _ ((φ x * φ y - φ y * φ x) * φ z) := ?_ _ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ y * (φ x * φ z)) := ?_ _ = trace R _ (φ x * (φ y * φ z)) - trace R _ (φ x * (φ z * φ y)) := ?_ _ = traceForm R L M x ⁅y, z⁆ := ?_ · simp only [LieHom.map_lie, Ring.lie_def, ← Module.End.mul_eq_comp] · simp only [sub_mul, mul_sub, map_sub, mul_assoc] · simp only [LinearMap.trace_mul_cycle' R (φ x) (φ z) (φ y)] · simp only [traceForm_apply_apply, LieHom.map_lie, Ring.lie_def, mul_sub, map_sub, ← Module.End.mul_eq_comp] /-- Given a representation `M` of a Lie algebra `L`, the action of any `x : L` is skew-adjoint wrt the trace form. -/ lemma traceForm_apply_lie_apply' (x y z : L) : traceForm R L M ⁅x, y⁆ z = - traceForm R L M y ⁅x, z⁆ := calc traceForm R L M ⁅x, y⁆ z = - traceForm R L M ⁅y, x⁆ z := by rw [← lie_skew x y, map_neg, LinearMap.neg_apply] _ = - traceForm R L M y ⁅x, z⁆ := by rw [traceForm_apply_lie_apply] lemma traceForm_lieInvariant : (traceForm R L M).lieInvariant L := by intro x y z rw [← lie_skew, map_neg, LinearMap.neg_apply, LieModule.traceForm_apply_lie_apply R L M] /-- This lemma justifies the terminology "invariant" for trace forms. -/
@[simp] lemma lie_traceForm_eq_zero (x : L) : ⁅x, traceForm R L M⁆ = 0 := by ext y z rw [LieHom.lie_apply, LinearMap.sub_apply, Module.Dual.lie_apply, LinearMap.zero_apply, LinearMap.zero_apply, traceForm_apply_lie_apply', sub_self]
Mathlib/Algebra/Lie/TraceForm.lean
92
96
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann, Kyle Miller, Mario Carneiro -/ import Mathlib.Data.Finset.NatAntidiagonal import Mathlib.Data.Nat.GCD.Basic import Mathlib.Data.Nat.BinaryRec import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify import Mathlib.Data.Nat.Choose.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Fibonacci Numbers This file defines the fibonacci series, proves results about it and introduces methods to compute it quickly. -/ /-! # The Fibonacci Sequence ## Summary Definition of the Fibonacci sequence `F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`. ## Main Definitions - `Nat.fib` returns the stream of Fibonacci numbers. ## Main Statements - `Nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.`. - `Nat.fib_gcd`: `fib n` is a strong divisibility sequence. - `Nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `Nat.choose` along an antidiagonal. - `Nat.fib_succ_eq_succ_sum`: shows that `F₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1`. - `Nat.fib_two_mul` and `Nat.fib_two_mul_add_one` are the basis for an efficient algorithm to compute `fib` (see `Nat.fastFib`). ## Implementation Notes For efficiency purposes, the sequence is defined using `Stream.iterate`. ## Tags fib, fibonacci -/ namespace Nat /-- Implementation of the fibonacci sequence satisfying `fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`. *Note:* We use a stream iterator for better performance when compared to the naive recursive implementation. -/ @[pp_nodot] def fib (n : ℕ) : ℕ := ((fun p : ℕ × ℕ => (p.snd, p.fst + p.snd))^[n] (0, 1)).fst @[simp] theorem fib_zero : fib 0 = 0 := rfl @[simp] theorem fib_one : fib 1 = 1 := rfl @[simp] theorem fib_two : fib 2 = 1 := rfl /-- Shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.` -/ theorem fib_add_two {n : ℕ} : fib (n + 2) = fib n + fib (n + 1) := by simp [fib, Function.iterate_succ_apply'] lemma fib_add_one : ∀ {n}, n ≠ 0 → fib (n + 1) = fib (n - 1) + fib n | _n + 1, _ => fib_add_two theorem fib_le_fib_succ {n : ℕ} : fib n ≤ fib (n + 1) := by cases n <;> simp [fib_add_two] @[mono] theorem fib_mono : Monotone fib := monotone_nat_of_le_succ fun _ => fib_le_fib_succ @[simp] lemma fib_eq_zero : ∀ {n}, fib n = 0 ↔ n = 0 | 0 => Iff.rfl | 1 => Iff.rfl | n + 2 => by simp [fib_add_two, fib_eq_zero] @[simp] lemma fib_pos {n : ℕ} : 0 < fib n ↔ 0 < n := by simp [pos_iff_ne_zero] theorem fib_add_two_sub_fib_add_one {n : ℕ} : fib (n + 2) - fib (n + 1) = fib n := by rw [fib_add_two, add_tsub_cancel_right] theorem fib_lt_fib_succ {n : ℕ} (hn : 2 ≤ n) : fib n < fib (n + 1) := by rcases exists_add_of_le hn with ⟨n, rfl⟩ rw [← tsub_pos_iff_lt, add_comm 2, add_right_comm, fib_add_two, add_tsub_cancel_right, fib_pos] exact succ_pos n /-- `fib (n + 2)` is strictly monotone. -/ theorem fib_add_two_strictMono : StrictMono fun n => fib (n + 2) := by refine strictMono_nat_of_lt_succ fun n => ?_
rw [add_right_comm] exact fib_lt_fib_succ (self_le_add_left _ _)
Mathlib/Data/Nat/Fib/Basic.lean
109
110
/- 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.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Defs /-! # Equitable functions This file defines equitable functions. A function `f` is equitable on a set `s` if `f a₁ ≤ f a₂ + 1` for all `a₁, a₂ ∈ s`. This is mostly useful when the codomain of `f` is `ℕ` or `ℤ` (or more generally a successor order). ## TODO `ℕ` can be replaced by any `SuccOrder` + `ConditionallyCompleteMonoid`, but we don't have the latter yet. -/ variable {α β : Type*} namespace Set /-- A set is equitable if no element value is more than one bigger than another. -/ def EquitableOn [LE β] [Add β] [One β] (s : Set α) (f : α → β) : Prop := ∀ ⦃a₁ a₂⦄, a₁ ∈ s → a₂ ∈ s → f a₁ ≤ f a₂ + 1 @[simp] theorem equitableOn_empty [LE β] [Add β] [One β] (f : α → β) : EquitableOn ∅ f := fun a _ ha => (Set.not_mem_empty a ha).elim theorem equitableOn_iff_exists_le_le_add_one {s : Set α} {f : α → ℕ} : s.EquitableOn f ↔ ∃ b, ∀ a ∈ s, b ≤ f a ∧ f a ≤ b + 1 := by refine ⟨?_, fun ⟨b, hb⟩ x y hx hy => (hb x hx).2.trans (add_le_add_right (hb y hy).1 _)⟩ obtain rfl | ⟨x, hx⟩ := s.eq_empty_or_nonempty · simp intro hs by_cases h : ∀ y ∈ s, f x ≤ f y · exact ⟨f x, fun y hy => ⟨h _ hy, hs hy hx⟩⟩ push_neg at h obtain ⟨w, hw, hwx⟩ := h refine ⟨f w, fun y hy => ⟨Nat.le_of_succ_le_succ ?_, hs hy hw⟩⟩ rw [(Nat.succ_le_of_lt hwx).antisymm (hs hx hw)] exact hs hx hy theorem equitableOn_iff_exists_image_subset_icc {s : Set α} {f : α → ℕ} : s.EquitableOn f ↔ ∃ b, f '' s ⊆ Icc b (b + 1) := by simpa only [image_subset_iff] using equitableOn_iff_exists_le_le_add_one theorem equitableOn_iff_exists_eq_eq_add_one {s : Set α} {f : α → ℕ} : s.EquitableOn f ↔ ∃ b, ∀ a ∈ s, f a = b ∨ f a = b + 1 := by simp_rw [equitableOn_iff_exists_le_le_add_one, Nat.le_and_le_add_one_iff] section LinearOrder variable [LinearOrder β] [Add β] [One β] {s : Set α} {f : α → β} @[simp] lemma not_equitableOn : ¬s.EquitableOn f ↔ ∃ a ∈ s, ∃ b ∈ s, f b + 1 < f a := by simp [EquitableOn] end LinearOrder section OrderedSemiring variable [Semiring β] [PartialOrder β] [IsOrderedRing β]
theorem Subsingleton.equitableOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : s.EquitableOn f := fun i j hi hj => by
Mathlib/Data/Set/Equitable.lean
70
72
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Complex.Basic import Mathlib.Data.Nat.Prime.Basic import Mathlib.Data.Real.Archimedean import Mathlib.NumberTheory.Zsqrtd.Basic /-! # Gaussian integers The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both integers. ## Main definitions The Euclidean domain structure on `ℤ[i]` is defined in this file. The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file. ## See also See `NumberTheory.Zsqrtd.QuadraticReciprocity` for: * `prime_iff_mod_four_eq_three_of_nat_prime`: A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` ## Notations This file uses the local notation `ℤ[i]` for `GaussianInt` ## Implementation notes Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties and definitions about `Zsqrtd` can easily be used. -/ open Zsqrtd Complex open scoped ComplexConjugate /-- The Gaussian integers, defined as `ℤ√(-1)`. -/ abbrev GaussianInt : Type := Zsqrtd (-1) local notation "ℤ[i]" => GaussianInt namespace GaussianInt instance : Repr ℤ[i] := ⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩ instance instCommRing : CommRing ℤ[i] := Zsqrtd.commRing section attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily. /-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/ def toComplex : ℤ[i] →+* ℂ := Zsqrtd.lift ⟨I, by simp⟩ end instance : Coe ℤ[i] ℂ := ⟨toComplex⟩ theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I := rfl theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def] theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by apply Complex.ext <;> simp [toComplex_def] @[simp] theorem to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [toComplex_def] @[simp] theorem to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by simp [toComplex_def] @[simp] theorem toComplex_re (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).re = x := by simp [toComplex_def] @[simp] theorem toComplex_im (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ).im = y := by simp [toComplex_def] theorem toComplex_add (x y : ℤ[i]) : ((x + y : ℤ[i]) : ℂ) = x + y := toComplex.map_add _ _ theorem toComplex_mul (x y : ℤ[i]) : ((x * y : ℤ[i]) : ℂ) = x * y := toComplex.map_mul _ _ theorem toComplex_one : ((1 : ℤ[i]) : ℂ) = 1 := toComplex.map_one theorem toComplex_zero : ((0 : ℤ[i]) : ℂ) = 0 := toComplex.map_zero theorem toComplex_neg (x : ℤ[i]) : ((-x : ℤ[i]) : ℂ) = -x := toComplex.map_neg _ theorem toComplex_sub (x y : ℤ[i]) : ((x - y : ℤ[i]) : ℂ) = x - y := toComplex.map_sub _ _ @[simp] theorem toComplex_star (x : ℤ[i]) : ((star x : ℤ[i]) : ℂ) = conj (x : ℂ) := by rw [toComplex_def₂, toComplex_def₂] exact congr_arg₂ _ rfl (Int.cast_neg _) @[simp] theorem toComplex_inj {x y : ℤ[i]} : (x : ℂ) = y ↔ x = y := by cases x; cases y; simp [toComplex_def₂] lemma toComplex_injective : Function.Injective GaussianInt.toComplex := fun ⦃_ _⦄ ↦ toComplex_inj.mp @[simp] theorem toComplex_eq_zero {x : ℤ[i]} : (x : ℂ) = 0 ↔ x = 0 := by rw [← toComplex_zero, toComplex_inj] @[simp] theorem intCast_real_norm (x : ℤ[i]) : (x.norm : ℝ) = Complex.normSq (x : ℂ) := by rw [Zsqrtd.norm, normSq]; simp @[simp] theorem intCast_complex_norm (x : ℤ[i]) : (x.norm : ℂ) = Complex.normSq (x : ℂ) := by cases x; rw [Zsqrtd.norm, normSq]; simp theorem norm_nonneg (x : ℤ[i]) : 0 ≤ norm x :=
Zsqrtd.norm_nonneg (by norm_num) _ @[simp]
Mathlib/NumberTheory/Zsqrtd/GaussianInt.lean
135
137
/- 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,033
1,034
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Sites.EqualizerSheafCondition /-! # Sheaves preserve products We prove that a presheaf which satisfies the sheaf condition with respect to certain presieves preserve "the corresponding products". ## Main results More precisely, given a presheaf `F : Cᵒᵖ ⥤ Type*`, we have: * If `F` satisfies the sheaf condition with respect to the empty sieve on the initial object of `C`, then `F` preserves terminal objects. See `preservesTerminalOfIsSheafForEmpty`. * If `F` furthermore satisfies the sheaf condition with respect to the presieve consisting of the inclusion arrows in a coproduct in `C`, then `F` preserves the corresponding product. See `preservesProductOfIsSheafFor`. * If `F` preserves a product, then it satisfies the sheaf condition with respect to the corresponding presieve of arrows. See `isSheafFor_of_preservesProduct`. -/ universe v u w namespace CategoryTheory.Presieve variable {C : Type u} [Category.{v} C] {I : C} (F : Cᵒᵖ ⥤ Type w) open Limits Opposite variable (hF : (ofArrows (X := I) Empty.elim Empty.instIsEmpty.elim).IsSheafFor F) section Terminal variable (I) in /-- If `F` is a presheaf which satisfies the sheaf condition with respect to the empty presieve on any object, then `F` takes that object to the terminal object. -/ noncomputable def isTerminal_of_isSheafFor_empty_presieve : IsTerminal (F.obj (op I)) := by refine @IsTerminal.ofUnique _ _ _ fun Y ↦ ?_ choose t h using hF (by tauto) (by tauto) exact ⟨⟨fun _ ↦ t⟩, fun a ↦ by ext; exact h.2 _ (by tauto)⟩ include hF in /-- If `F` is a presheaf which satisfies the sheaf condition with respect to the empty presieve on the initial object, then `F` preserves terminal objects. -/ lemma preservesTerminal_of_isSheaf_for_empty (hI : IsInitial I) : PreservesLimit (Functor.empty.{0} Cᵒᵖ) F := have := hI.hasInitial (preservesTerminal_of_iso F ((F.mapIso (terminalIsoIsTerminal (terminalOpOfInitial initialIsInitial)) ≪≫ (F.mapIso (initialIsoIsInitial hI).symm.op) ≪≫ (terminalIsoIsTerminal (isTerminal_of_isSheafFor_empty_presieve I F hF)).symm))) end Terminal section Product variable (hI : IsInitial I) -- This is the data of a particular disjoint coproduct in `C`. variable {α : Type} {X : α → C} (c : Cofan X) (hc : IsColimit c) theorem piComparison_fac : have : HasCoproduct X := ⟨⟨c, hc⟩⟩ piComparison F (fun x ↦ op (X x)) = F.map (opCoproductIsoProduct' hc (productIsProduct _)).inv ≫ Equalizer.Presieve.Arrows.forkMap F X c.inj := by have : HasCoproduct X := ⟨⟨c, hc⟩⟩
dsimp only [Equalizer.Presieve.Arrows.forkMap] have h : Pi.lift (fun i ↦ F.map (c.inj i).op) = F.map (Pi.lift (fun i ↦ (c.inj i).op)) ≫ piComparison F _ := by simp rw [h, ← Category.assoc, ← Functor.map_comp] have hh : Pi.lift (fun i ↦ (c.inj i).op) = (productIsProduct (op <| X ·)).lift c.op := by simp [Pi.lift, productIsProduct] rw [hh, ← desc_op_comp_opCoproductIsoProduct'_hom hc] simp variable [(ofArrows X c.inj).hasPullbacks] include hc in /--
Mathlib/CategoryTheory/Sites/Preserves.lean
83
95
/- Copyright (c) 2022 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.Polynomial.Taylor import Mathlib.FieldTheory.RatFunc.AsPolynomial /-! # Laurent expansions of rational functions ## Main declarations * `RatFunc.laurent`: the Laurent expansion of the rational function `f` at `r`, as an `AlgHom`. * `RatFunc.laurent_injective`: the Laurent expansion at `r` is unique ## Implementation details Implemented as the quotient of two Taylor expansions, over domains. An auxiliary definition is provided first to make the construction of the `AlgHom` easier, which works on `CommRing` which are not necessarily domains. -/ universe u namespace RatFunc noncomputable section open Polynomial open scoped nonZeroDivisors variable {R : Type u} [CommRing R] (r s : R) (p q : R[X]) (f : RatFunc R) theorem taylor_mem_nonZeroDivisors (hp : p ∈ R[X]⁰) : taylor r p ∈ R[X]⁰ := by rw [mem_nonZeroDivisors_iff] intro x hx have : x = taylor (r - r) x := by simp rwa [this, sub_eq_add_neg, ← taylor_taylor, ← taylor_mul, LinearMap.map_eq_zero_iff _ (taylor_injective _), mul_right_mem_nonZeroDivisors_eq_zero_iff hp, LinearMap.map_eq_zero_iff _ (taylor_injective _)] at hx /-- The Laurent expansion of rational functions about a value. Auxiliary definition, usage when over integral domains should prefer `RatFunc.laurent`. -/ def laurentAux : RatFunc R →+* RatFunc R := RatFunc.mapRingHom ( { toFun := taylor r map_add' := map_add (taylor r) map_mul' := taylor_mul _ map_zero' := map_zero (taylor r) map_one' := taylor_one r } : R[X] →+* R[X]) (taylor_mem_nonZeroDivisors _) theorem laurentAux_ofFractionRing_mk (q : R[X]⁰) : laurentAux r (ofFractionRing (Localization.mk p q)) = ofFractionRing (.mk (taylor r p) ⟨taylor r q, taylor_mem_nonZeroDivisors r q q.prop⟩) := map_apply_ofFractionRing_mk _ _ _ _ variable [IsDomain R] theorem laurentAux_div : laurentAux r (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (taylor r p) / algebraMap _ _ (taylor r q) := -- Porting note: added `by exact taylor_mem_nonZeroDivisors r` map_apply_div _ (by exact taylor_mem_nonZeroDivisors r) _ _ @[simp] theorem laurentAux_algebraMap : laurentAux r (algebraMap _ _ p) = algebraMap _ _ (taylor r p) := by rw [← mk_one, ← mk_one, mk_eq_div, laurentAux_div, mk_eq_div, taylor_one, map_one, map_one] /-- The Laurent expansion of rational functions about a value. -/ def laurent : RatFunc R →ₐ[R] RatFunc R := RatFunc.mapAlgHom (.ofLinearMap (taylor r) (taylor_one _) (taylor_mul _)) (taylor_mem_nonZeroDivisors _) theorem laurent_div : laurent r (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (taylor r p) / algebraMap _ _ (taylor r q) := laurentAux_div r p q @[simp] theorem laurent_algebraMap : laurent r (algebraMap _ _ p) = algebraMap _ _ (taylor r p) := laurentAux_algebraMap _ _ @[simp] theorem laurent_X : laurent r X = X + C r := by rw [← algebraMap_X, laurent_algebraMap, taylor_X, map_add, algebraMap_C] @[simp] theorem laurent_C (x : R) : laurent r (C x) = C x := by rw [← algebraMap_C, laurent_algebraMap, taylor_C] @[simp] theorem laurent_at_zero : laurent 0 f = f := by induction f using RatFunc.induction_on; simp theorem laurent_laurent : laurent r (laurent s f) = laurent (r + s) f := by induction f using RatFunc.induction_on simp_rw [laurent_div, taylor_taylor] theorem laurent_injective : Function.Injective (laurent r) := fun _ _ h => by simpa [laurent_laurent] using congr_arg (laurent (-r)) h end end RatFunc
Mathlib/FieldTheory/Laurent.lean
111
113
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, 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 τ₁₂]
Mathlib/Algebra/Module/Submodule/Range.lean
179
180
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.PreservesHomology import Mathlib.Algebra.Homology.ShortComplex.Abelian import Mathlib.Algebra.Homology.ShortComplex.QuasiIso import Mathlib.CategoryTheory.Abelian.Opposite import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Preadditive.Injective.Basic /-! # Exact short complexes When `S : ShortComplex C`, this file defines a structure `S.Exact` which expresses the exactness of `S`, i.e. there exists a homology data `h : S.HomologyData` such that `h.left.H` is zero. When `[S.HasHomology]`, it is equivalent to the assertion `IsZero S.homology`. Almost by construction, this notion of exactness is self dual, see `Exact.op` and `Exact.unop`. -/ namespace CategoryTheory open Category Limits ZeroObject Preadditive variable {C D : Type*} [Category C] [Category D] namespace ShortComplex section variable [HasZeroMorphisms C] [HasZeroMorphisms D] (S : ShortComplex C) {S₁ S₂ : ShortComplex C} /-- The assertion that the short complex `S : ShortComplex C` is exact. -/ structure Exact : Prop where /-- the condition that there exists an homology data whose `left.H` field is zero -/ condition : ∃ (h : S.HomologyData), IsZero h.left.H variable {S} lemma Exact.hasHomology (h : S.Exact) : S.HasHomology := HasHomology.mk' h.condition.choose lemma Exact.hasZeroObject (h : S.Exact) : HasZeroObject C := ⟨h.condition.choose.left.H, h.condition.choose_spec⟩ variable (S) lemma exact_iff_isZero_homology [S.HasHomology] : S.Exact ↔ IsZero S.homology := by constructor · rintro ⟨⟨h', z⟩⟩ exact IsZero.of_iso z h'.left.homologyIso · intro h exact ⟨⟨_, h⟩⟩ variable {S} lemma LeftHomologyData.exact_iff [S.HasHomology] (h : S.LeftHomologyData) : S.Exact ↔ IsZero h.H := by rw [S.exact_iff_isZero_homology] exact Iso.isZero_iff h.homologyIso lemma RightHomologyData.exact_iff [S.HasHomology] (h : S.RightHomologyData) : S.Exact ↔ IsZero h.H := by rw [S.exact_iff_isZero_homology] exact Iso.isZero_iff h.homologyIso variable (S) lemma exact_iff_isZero_leftHomology [S.HasHomology] : S.Exact ↔ IsZero S.leftHomology := LeftHomologyData.exact_iff _ lemma exact_iff_isZero_rightHomology [S.HasHomology] : S.Exact ↔ IsZero S.rightHomology := RightHomologyData.exact_iff _ variable {S} lemma HomologyData.exact_iff (h : S.HomologyData) : S.Exact ↔ IsZero h.left.H := by haveI := HasHomology.mk' h exact LeftHomologyData.exact_iff h.left lemma HomologyData.exact_iff' (h : S.HomologyData) : S.Exact ↔ IsZero h.right.H := by haveI := HasHomology.mk' h exact RightHomologyData.exact_iff h.right variable (S) lemma exact_iff_homology_iso_zero [S.HasHomology] [HasZeroObject C] : S.Exact ↔ Nonempty (S.homology ≅ 0) := by rw [exact_iff_isZero_homology] constructor · intro h exact ⟨h.isoZero⟩ · rintro ⟨e⟩ exact IsZero.of_iso (isZero_zero C) e lemma exact_of_iso (e : S₁ ≅ S₂) (h : S₁.Exact) : S₂.Exact := by obtain ⟨⟨h, z⟩⟩ := h exact ⟨⟨HomologyData.ofIso e h, z⟩⟩ lemma exact_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ↔ S₂.Exact := ⟨exact_of_iso e, exact_of_iso e.symm⟩ lemma exact_and_mono_f_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ∧ Mono S₁.f ↔ S₂.Exact ∧ Mono S₂.f := by have : Mono S₁.f ↔ Mono S₂.f := (MorphismProperty.monomorphisms C).arrow_mk_iso_iff (Arrow.isoMk (ShortComplex.π₁.mapIso e) (ShortComplex.π₂.mapIso e) e.hom.comm₁₂) rw [exact_iff_of_iso e, this] lemma exact_and_epi_g_iff_of_iso (e : S₁ ≅ S₂) : S₁.Exact ∧ Epi S₁.g ↔ S₂.Exact ∧ Epi S₂.g := by have : Epi S₁.g ↔ Epi S₂.g := (MorphismProperty.epimorphisms C).arrow_mk_iso_iff (Arrow.isoMk (ShortComplex.π₂.mapIso e) (ShortComplex.π₃.mapIso e) e.hom.comm₂₃) rw [exact_iff_of_iso e, this] lemma exact_of_isZero_X₂ (h : IsZero S.X₂) : S.Exact := by rw [(HomologyData.ofZeros S (IsZero.eq_of_tgt h _ _) (IsZero.eq_of_src h _ _)).exact_iff] exact h lemma exact_iff_of_epi_of_isIso_of_mono (φ : S₁ ⟶ S₂) [Epi φ.τ₁] [IsIso φ.τ₂] [Mono φ.τ₃] : S₁.Exact ↔ S₂.Exact := by constructor · rintro ⟨h₁, z₁⟩ exact ⟨HomologyData.ofEpiOfIsIsoOfMono φ h₁, z₁⟩ · rintro ⟨h₂, z₂⟩ exact ⟨HomologyData.ofEpiOfIsIsoOfMono' φ h₂, z₂⟩ variable {S} lemma HomologyData.exact_iff_i_p_zero (h : S.HomologyData) : S.Exact ↔ h.left.i ≫ h.right.p = 0 := by haveI := HasHomology.mk' h rw [h.left.exact_iff, ← h.comm] constructor · intro z rw [IsZero.eq_of_src z h.iso.hom 0, zero_comp, comp_zero] · intro eq simp only [IsZero.iff_id_eq_zero, ← cancel_mono h.iso.hom, id_comp, ← cancel_mono h.right.ι, ← cancel_epi h.left.π, eq, zero_comp, comp_zero] variable (S) lemma exact_iff_i_p_zero [S.HasHomology] (h₁ : S.LeftHomologyData) (h₂ : S.RightHomologyData) : S.Exact ↔ h₁.i ≫ h₂.p = 0 := (HomologyData.ofIsIsoLeftRightHomologyComparison' h₁ h₂).exact_iff_i_p_zero lemma exact_iff_iCycles_pOpcycles_zero [S.HasHomology] : S.Exact ↔ S.iCycles ≫ S.pOpcycles = 0 := S.exact_iff_i_p_zero _ _ lemma exact_iff_kernel_ι_comp_cokernel_π_zero [S.HasHomology] [HasKernel S.g] [HasCokernel S.f] : S.Exact ↔ kernel.ι S.g ≫ cokernel.π S.f = 0 := by haveI := HasLeftHomology.hasCokernel S haveI := HasRightHomology.hasKernel S exact S.exact_iff_i_p_zero (LeftHomologyData.ofHasKernelOfHasCokernel S) (RightHomologyData.ofHasCokernelOfHasKernel S) variable {S} lemma Exact.op (h : S.Exact) : S.op.Exact := by obtain ⟨h, z⟩ := h exact ⟨⟨h.op, (IsZero.of_iso z h.iso.symm).op⟩⟩ lemma Exact.unop {S : ShortComplex Cᵒᵖ} (h : S.Exact) : S.unop.Exact := by obtain ⟨h, z⟩ := h exact ⟨⟨h.unop, (IsZero.of_iso z h.iso.symm).unop⟩⟩ variable (S) @[simp] lemma exact_op_iff : S.op.Exact ↔ S.Exact := ⟨Exact.unop, Exact.op⟩ @[simp] lemma exact_unop_iff (S : ShortComplex Cᵒᵖ) : S.unop.Exact ↔ S.Exact := S.unop.exact_op_iff.symm variable {S} lemma LeftHomologyData.exact_map_iff (h : S.LeftHomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h.IsPreservedBy F] [(S.map F).HasHomology] : (S.map F).Exact ↔ IsZero (F.obj h.H) := (h.map F).exact_iff lemma RightHomologyData.exact_map_iff (h : S.RightHomologyData) (F : C ⥤ D) [F.PreservesZeroMorphisms] [h.IsPreservedBy F] [(S.map F).HasHomology] : (S.map F).Exact ↔ IsZero (F.obj h.H) := (h.map F).exact_iff lemma Exact.map_of_preservesLeftHomologyOf (h : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [(S.map F).HasHomology] : (S.map F).Exact := by have := h.hasHomology rw [S.leftHomologyData.exact_iff, IsZero.iff_id_eq_zero] at h rw [S.leftHomologyData.exact_map_iff F, IsZero.iff_id_eq_zero, ← F.map_id, h, F.map_zero] lemma Exact.map_of_preservesRightHomologyOf (h : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesRightHomologyOf S] [(S.map F).HasHomology] : (S.map F).Exact := by have : S.HasHomology := h.hasHomology rw [S.rightHomologyData.exact_iff, IsZero.iff_id_eq_zero] at h rw [S.rightHomologyData.exact_map_iff F, IsZero.iff_id_eq_zero, ← F.map_id, h, F.map_zero] lemma Exact.map (h : S.Exact) (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] : (S.map F).Exact := by have := h.hasHomology exact h.map_of_preservesLeftHomologyOf F variable (S) lemma exact_map_iff_of_faithful [S.HasHomology] (F : C ⥤ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S] [F.PreservesRightHomologyOf S] [F.Faithful] : (S.map F).Exact ↔ S.Exact := by constructor · intro h rw [S.leftHomologyData.exact_iff, IsZero.iff_id_eq_zero] rw [(S.leftHomologyData.map F).exact_iff, IsZero.iff_id_eq_zero, LeftHomologyData.map_H] at h apply F.map_injective rw [F.map_id, F.map_zero, h] · intro h exact h.map F variable {S} @[reassoc] lemma Exact.comp_eq_zero (h : S.Exact) {X Y : C} {a : X ⟶ S.X₂} (ha : a ≫ S.g = 0) {b : S.X₂ ⟶ Y} (hb : S.f ≫ b = 0) : a ≫ b = 0 := by have := h.hasHomology have eq := h rw [exact_iff_iCycles_pOpcycles_zero] at eq rw [← S.liftCycles_i a ha, ← S.p_descOpcycles b hb, assoc, reassoc_of% eq, zero_comp, comp_zero] lemma Exact.isZero_of_both_zeros (ex : S.Exact) (hf : S.f = 0) (hg : S.g = 0) : IsZero S.X₂ := (ShortComplex.HomologyData.ofZeros S hf hg).exact_iff.1 ex end section Preadditive variable [Preadditive C] [Preadditive D] (S : ShortComplex C) lemma exact_iff_mono [HasZeroObject C] (hf : S.f = 0) : S.Exact ↔ Mono S.g := by constructor · intro h have := h.hasHomology simp only [exact_iff_isZero_homology] at h have := S.isIso_pOpcycles hf have := mono_of_isZero_kernel' _ S.homologyIsKernel h rw [← S.p_fromOpcycles] apply mono_comp · intro rw [(HomologyData.ofIsLimitKernelFork S hf _ (KernelFork.IsLimit.ofMonoOfIsZero (KernelFork.ofι (0 : 0 ⟶ S.X₂) zero_comp) inferInstance (isZero_zero C))).exact_iff] exact isZero_zero C lemma exact_iff_epi [HasZeroObject C] (hg : S.g = 0) : S.Exact ↔ Epi S.f := by constructor · intro h have := h.hasHomology simp only [exact_iff_isZero_homology] at h haveI := S.isIso_iCycles hg haveI : Epi S.toCycles := epi_of_isZero_cokernel' _ S.homologyIsCokernel h rw [← S.toCycles_i] apply epi_comp · intro rw [(HomologyData.ofIsColimitCokernelCofork S hg _ (CokernelCofork.IsColimit.ofEpiOfIsZero (CokernelCofork.ofπ (0 : S.X₂ ⟶ 0) comp_zero) inferInstance (isZero_zero C))).exact_iff] exact isZero_zero C variable {S} lemma Exact.epi_f' (hS : S.Exact) (h : LeftHomologyData S) : Epi h.f' := epi_of_isZero_cokernel' _ h.hπ (by haveI := hS.hasHomology dsimp simpa only [← h.exact_iff] using hS) lemma Exact.mono_g' (hS : S.Exact) (h : RightHomologyData S) : Mono h.g' := mono_of_isZero_kernel' _ h.hι (by haveI := hS.hasHomology dsimp simpa only [← h.exact_iff] using hS) lemma Exact.epi_toCycles (hS : S.Exact) [S.HasLeftHomology] : Epi S.toCycles := hS.epi_f' _ lemma Exact.mono_fromOpcycles (hS : S.Exact) [S.HasRightHomology] : Mono S.fromOpcycles := hS.mono_g' _ lemma LeftHomologyData.exact_iff_epi_f' [S.HasHomology] (h : LeftHomologyData S) : S.Exact ↔ Epi h.f' := by constructor · intro hS exact hS.epi_f' h · intro simp only [h.exact_iff, IsZero.iff_id_eq_zero, ← cancel_epi h.π, ← cancel_epi h.f', comp_id, h.f'_π, comp_zero] lemma RightHomologyData.exact_iff_mono_g' [S.HasHomology] (h : RightHomologyData S) : S.Exact ↔ Mono h.g' := by constructor · intro hS exact hS.mono_g' h · intro simp only [h.exact_iff, IsZero.iff_id_eq_zero, ← cancel_mono h.ι, ← cancel_mono h.g', id_comp, h.ι_g', zero_comp] /-- Given an exact short complex `S` and a limit kernel fork `kf` for `S.g`, this is the left homology data for `S` with `K := kf.pt` and `H := 0`. -/ @[simps] noncomputable def Exact.leftHomologyDataOfIsLimitKernelFork (hS : S.Exact) [HasZeroObject C] (kf : KernelFork S.g) (hkf : IsLimit kf) : S.LeftHomologyData where K := kf.pt H := 0 i := kf.ι π := 0 wi := kf.condition hi := IsLimit.ofIsoLimit hkf (Fork.ext (Iso.refl _) (by simp)) wπ := comp_zero hπ := CokernelCofork.IsColimit.ofEpiOfIsZero _ (by have := hS.hasHomology refine ((MorphismProperty.epimorphisms C).arrow_mk_iso_iff ?_).1 hS.epi_toCycles refine Arrow.isoMk (Iso.refl _) (IsLimit.conePointUniqueUpToIso S.cyclesIsKernel hkf) ?_ apply Fork.IsLimit.hom_ext hkf simp [IsLimit.conePointUniqueUpToIso]) (isZero_zero C) /-- Given an exact short complex `S` and a colimit cokernel cofork `cc` for `S.f`, this is the right homology data for `S` with `Q := cc.pt` and `H := 0`. -/ @[simps] noncomputable def Exact.rightHomologyDataOfIsColimitCokernelCofork (hS : S.Exact) [HasZeroObject C] (cc : CokernelCofork S.f) (hcc : IsColimit cc) : S.RightHomologyData where Q := cc.pt H := 0 p := cc.π ι := 0 wp := cc.condition hp := IsColimit.ofIsoColimit hcc (Cofork.ext (Iso.refl _) (by simp)) wι := zero_comp hι := KernelFork.IsLimit.ofMonoOfIsZero _ (by have := hS.hasHomology refine ((MorphismProperty.monomorphisms C).arrow_mk_iso_iff ?_).2 hS.mono_fromOpcycles refine Arrow.isoMk (IsColimit.coconePointUniqueUpToIso hcc S.opcyclesIsCokernel) (Iso.refl _) ?_ apply Cofork.IsColimit.hom_ext hcc simp [IsColimit.coconePointUniqueUpToIso]) (isZero_zero C) variable (S) lemma exact_iff_epi_toCycles [S.HasHomology] : S.Exact ↔ Epi S.toCycles := S.leftHomologyData.exact_iff_epi_f' lemma exact_iff_mono_fromOpcycles [S.HasHomology] : S.Exact ↔ Mono S.fromOpcycles := S.rightHomologyData.exact_iff_mono_g' lemma exact_iff_epi_kernel_lift [S.HasHomology] [HasKernel S.g] : S.Exact ↔ Epi (kernel.lift S.g S.f S.zero) := by rw [exact_iff_epi_toCycles] apply (MorphismProperty.epimorphisms C).arrow_mk_iso_iff exact Arrow.isoMk (Iso.refl _) S.cyclesIsoKernel (by aesop_cat) lemma exact_iff_mono_cokernel_desc [S.HasHomology] [HasCokernel S.f] : S.Exact ↔ Mono (cokernel.desc S.f S.g S.zero) := by rw [exact_iff_mono_fromOpcycles] refine (MorphismProperty.monomorphisms C).arrow_mk_iso_iff (Iso.symm ?_) exact Arrow.isoMk S.opcyclesIsoCokernel.symm (Iso.refl _) (by aesop_cat) lemma QuasiIso.exact_iff {S₁ S₂ : ShortComplex C} (φ : S₁ ⟶ S₂) [S₁.HasHomology] [S₂.HasHomology] [QuasiIso φ] : S₁.Exact ↔ S₂.Exact := by simp only [exact_iff_isZero_homology] exact Iso.isZero_iff (asIso (homologyMap φ)) lemma exact_of_f_is_kernel (hS : IsLimit (KernelFork.ofι S.f S.zero)) [S.HasHomology] : S.Exact := by rw [exact_iff_epi_toCycles] have : IsSplitEpi S.toCycles := ⟨⟨{ section_ := hS.lift (KernelFork.ofι S.iCycles S.iCycles_g) id := by rw [← cancel_mono S.iCycles, assoc, toCycles_i, id_comp] exact Fork.IsLimit.lift_ι hS }⟩⟩ infer_instance lemma exact_of_g_is_cokernel (hS : IsColimit (CokernelCofork.ofπ S.g S.zero)) [S.HasHomology] : S.Exact := by rw [exact_iff_mono_fromOpcycles] have : IsSplitMono S.fromOpcycles := ⟨⟨{ retraction := hS.desc (CokernelCofork.ofπ S.pOpcycles S.f_pOpcycles) id := by rw [← cancel_epi S.pOpcycles, p_fromOpcycles_assoc, comp_id] exact Cofork.IsColimit.π_desc hS }⟩⟩ infer_instance variable {S} lemma Exact.mono_g (hS : S.Exact) (hf : S.f = 0) : Mono S.g := by have := hS.hasHomology have := hS.epi_toCycles have : S.iCycles = 0 := by rw [← cancel_epi S.toCycles, comp_zero, toCycles_i, hf] apply Preadditive.mono_of_cancel_zero intro A x₂ hx₂ rw [← S.liftCycles_i x₂ hx₂, this, comp_zero] lemma Exact.epi_f (hS : S.Exact) (hg : S.g = 0) : Epi S.f := by have := hS.hasHomology have := hS.mono_fromOpcycles have : S.pOpcycles = 0 := by rw [← cancel_mono S.fromOpcycles, zero_comp, p_fromOpcycles, hg] apply Preadditive.epi_of_cancel_zero intro A x₂ hx₂ rw [← S.p_descOpcycles x₂ hx₂, this, zero_comp] lemma Exact.mono_g_iff (hS : S.Exact) : Mono S.g ↔ S.f = 0 := by constructor · intro rw [← cancel_mono S.g, zero, zero_comp] · exact hS.mono_g lemma Exact.epi_f_iff (hS : S.Exact) : Epi S.f ↔ S.g = 0 := by constructor · intro rw [← cancel_epi S.f, zero, comp_zero] · exact hS.epi_f lemma Exact.isZero_X₂ (hS : S.Exact) (hf : S.f = 0) (hg : S.g = 0) : IsZero S.X₂ := by have := hS.mono_g hf rw [IsZero.iff_id_eq_zero, ← cancel_mono S.g, hg, comp_zero, comp_zero] lemma Exact.isZero_X₂_iff (hS : S.Exact) : IsZero S.X₂ ↔ S.f = 0 ∧ S.g = 0 := by constructor · intro h exact ⟨h.eq_of_tgt _ _, h.eq_of_src _ _⟩ · rintro ⟨hf, hg⟩ exact hS.isZero_X₂ hf hg variable (S) /-- A splitting for a short complex `S` consists of the data of a retraction `r : X₂ ⟶ X₁` of `S.f` and section `s : X₃ ⟶ X₂` of `S.g` which satisfy `r ≫ S.f + S.g ≫ s = 𝟙 _` -/ structure Splitting (S : ShortComplex C) where /-- a retraction of `S.f` -/ r : S.X₂ ⟶ S.X₁ /-- a section of `S.g` -/ s : S.X₃ ⟶ S.X₂ /-- the condition that `r` is a retraction of `S.f` -/ f_r : S.f ≫ r = 𝟙 _ := by aesop_cat /-- the condition that `s` is a section of `S.g` -/ s_g : s ≫ S.g = 𝟙 _ := by aesop_cat /-- the compatibility between the given section and retraction -/ id : r ≫ S.f + S.g ≫ s = 𝟙 _ := by aesop_cat namespace Splitting attribute [reassoc (attr := simp)] f_r s_g variable {S} @[reassoc] lemma r_f (s : S.Splitting) : s.r ≫ S.f = 𝟙 _ - S.g ≫ s.s := by rw [← s.id, add_sub_cancel_right] @[reassoc] lemma g_s (s : S.Splitting) : S.g ≫ s.s = 𝟙 _ - s.r ≫ S.f := by rw [← s.id, add_sub_cancel_left] /-- Given a splitting of a short complex `S`, this shows that `S.f` is a split monomorphism. -/ @[simps] def splitMono_f (s : S.Splitting) : SplitMono S.f := ⟨s.r, s.f_r⟩ lemma isSplitMono_f (s : S.Splitting) : IsSplitMono S.f := ⟨⟨s.splitMono_f⟩⟩ lemma mono_f (s : S.Splitting) : Mono S.f := by have := s.isSplitMono_f infer_instance /-- Given a splitting of a short complex `S`, this shows that `S.g` is a split epimorphism. -/ @[simps] def splitEpi_g (s : S.Splitting) : SplitEpi S.g := ⟨s.s, s.s_g⟩ lemma isSplitEpi_g (s : S.Splitting) : IsSplitEpi S.g := ⟨⟨s.splitEpi_g⟩⟩ lemma epi_g (s : S.Splitting) : Epi S.g := by have := s.isSplitEpi_g infer_instance @[reassoc (attr := simp)] lemma s_r (s : S.Splitting) : s.s ≫ s.r = 0 := by have := s.epi_g simp only [← cancel_epi S.g, comp_zero, g_s_assoc, sub_comp, id_comp, assoc, f_r, comp_id, sub_self] lemma ext_r (s s' : S.Splitting) (h : s.r = s'.r) : s = s' := by have := s.epi_g have eq := s.id rw [← s'.id, h, add_right_inj, cancel_epi S.g] at eq cases s cases s' obtain rfl := eq obtain rfl := h rfl lemma ext_s (s s' : S.Splitting) (h : s.s = s'.s) : s = s' := by have := s.mono_f have eq := s.id rw [← s'.id, h, add_left_inj, cancel_mono S.f] at eq cases s cases s' obtain rfl := eq obtain rfl := h rfl /-- The left homology data on a short complex equipped with a splitting. -/ @[simps] noncomputable def leftHomologyData [HasZeroObject C] (s : S.Splitting) : LeftHomologyData S := by have hi := KernelFork.IsLimit.ofι S.f S.zero (fun x _ => x ≫ s.r) (fun x hx => by simp only [assoc, s.r_f, comp_sub, comp_id, sub_eq_self, reassoc_of% hx, zero_comp]) (fun x _ b hb => by simp only [← hb, assoc, f_r, comp_id]) let f' := hi.lift (KernelFork.ofι S.f S.zero) have hf' : f' = 𝟙 _ := by apply Fork.IsLimit.hom_ext hi dsimp erw [Fork.IsLimit.lift_ι hi] simp only [Fork.ι_ofι, id_comp] have wπ : f' ≫ (0 : S.X₁ ⟶ 0) = 0 := comp_zero have hπ : IsColimit (CokernelCofork.ofπ 0 wπ) := CokernelCofork.IsColimit.ofEpiOfIsZero _ (by rw [hf']; infer_instance) (isZero_zero _) exact { K := S.X₁ H := 0 i := S.f wi := S.zero hi := hi π := 0 wπ := wπ hπ := hπ } /-- The right homology data on a short complex equipped with a splitting. -/ @[simps] noncomputable def rightHomologyData [HasZeroObject C] (s : S.Splitting) : RightHomologyData S := by have hp := CokernelCofork.IsColimit.ofπ S.g S.zero (fun x _ => s.s ≫ x) (fun x hx => by simp only [s.g_s_assoc, sub_comp, id_comp, sub_eq_self, assoc, hx, comp_zero]) (fun x _ b hb => by simp only [← hb, s.s_g_assoc]) let g' := hp.desc (CokernelCofork.ofπ S.g S.zero) have hg' : g' = 𝟙 _ := by apply Cofork.IsColimit.hom_ext hp dsimp erw [Cofork.IsColimit.π_desc hp] simp only [Cofork.π_ofπ, comp_id] have wι : (0 : 0 ⟶ S.X₃) ≫ g' = 0 := zero_comp have hι : IsLimit (KernelFork.ofι 0 wι) := KernelFork.IsLimit.ofMonoOfIsZero _ (by rw [hg']; dsimp; infer_instance) (isZero_zero _) exact { Q := S.X₃ H := 0 p := S.g wp := S.zero hp := hp ι := 0 wι := wι hι := hι } /-- The homology data on a short complex equipped with a splitting. -/ @[simps] noncomputable def homologyData [HasZeroObject C] (s : S.Splitting) : S.HomologyData where left := s.leftHomologyData right := s.rightHomologyData iso := Iso.refl 0 /-- A short complex equipped with a splitting is exact. -/ lemma exact [HasZeroObject C] (s : S.Splitting) : S.Exact := ⟨s.homologyData, isZero_zero _⟩ /-- If a short complex `S` is equipped with a splitting, then `S.X₁` is the kernel of `S.g`. -/ noncomputable def fIsKernel [HasZeroObject C] (s : S.Splitting) : IsLimit (KernelFork.ofι S.f S.zero) := s.homologyData.left.hi /-- If a short complex `S` is equipped with a splitting, then `S.X₃` is the cokernel of `S.f`. -/ noncomputable def gIsCokernel [HasZeroObject C] (s : S.Splitting) : IsColimit (CokernelCofork.ofπ S.g S.zero) := s.homologyData.right.hp /-- If a short complex `S` has a splitting and `F` is an additive functor, then `S.map F` also has a splitting. -/ @[simps] def map (s : S.Splitting) (F : C ⥤ D) [F.Additive] : (S.map F).Splitting where r := F.map s.r s := F.map s.s f_r := by dsimp [ShortComplex.map] rw [← F.map_comp, f_r, F.map_id] s_g := by dsimp [ShortComplex.map] simp only [← F.map_comp, s_g, F.map_id] id := by dsimp [ShortComplex.map] simp only [← F.map_id, ← s.id, Functor.map_comp, Functor.map_add] /-- A splitting on a short complex induces splittings on isomorphic short complexes. -/ @[simps] def ofIso {S₁ S₂ : ShortComplex C} (s : S₁.Splitting) (e : S₁ ≅ S₂) : S₂.Splitting where r := e.inv.τ₂ ≫ s.r ≫ e.hom.τ₁ s := e.inv.τ₃ ≫ s.s ≫ e.hom.τ₂ f_r := by rw [← e.inv.comm₁₂_assoc, s.f_r_assoc, ← comp_τ₁, e.inv_hom_id, id_τ₁] s_g := by rw [assoc, assoc, e.hom.comm₂₃, s.s_g_assoc, ← comp_τ₃, e.inv_hom_id, id_τ₃] id := by have eq := e.inv.τ₂ ≫= s.id =≫ e.hom.τ₂ rw [id_comp, ← comp_τ₂, e.inv_hom_id, id_τ₂] at eq rw [← eq, assoc, assoc, add_comp, assoc, assoc, comp_add, e.hom.comm₁₂, e.inv.comm₂₃_assoc] /-- The obvious splitting of the short complex `X₁ ⟶ X₁ ⊞ X₂ ⟶ X₂`. -/ noncomputable def ofHasBinaryBiproduct (X₁ X₂ : C) [HasBinaryBiproduct X₁ X₂] : Splitting (ShortComplex.mk (biprod.inl : X₁ ⟶ _) (biprod.snd : _ ⟶ X₂) (by simp)) where r := biprod.fst s := biprod.inr variable (S) /-- The obvious splitting of a short complex when `S.X₁` is zero and `S.g` is an isomorphism. -/ noncomputable def ofIsZeroOfIsIso (hf : IsZero S.X₁) (hg : IsIso S.g) : Splitting S where r := 0 s := inv S.g f_r := hf.eq_of_src _ _ /-- The obvious splitting of a short complex when `S.f` is an isomorphism and `S.X₃` is zero. -/ noncomputable def ofIsIsoOfIsZero (hf : IsIso S.f) (hg : IsZero S.X₃) : Splitting S where r := inv S.f s := 0 s_g := hg.eq_of_src _ _ variable {S} /-- The splitting of the short complex `S.op` deduced from a splitting of `S`. -/ @[simps] def op (h : Splitting S) : Splitting S.op where r := h.s.op s := h.r.op f_r := Quiver.Hom.unop_inj (by simp) s_g := Quiver.Hom.unop_inj (by simp) id := Quiver.Hom.unop_inj (by simp only [op_X₂, Opposite.unop_op, op_X₁, op_f, op_X₃, op_g, unop_add, unop_comp, Quiver.Hom.unop_op, unop_id, ← h.id] abel) /-- The splitting of the short complex `S.unop` deduced from a splitting of `S`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : Splitting S) : Splitting S.unop where r := h.s.unop s := h.r.unop f_r := Quiver.Hom.op_inj (by simp) s_g := Quiver.Hom.op_inj (by simp) id := Quiver.Hom.op_inj (by simp only [unop_X₂, Opposite.op_unop, unop_X₁, unop_f, unop_X₃, unop_g, op_add, op_comp, Quiver.Hom.op_unop, op_id, ← h.id] abel) /-- The isomorphism `S.X₂ ≅ S.X₁ ⊞ S.X₃` induced by a splitting of the short complex `S`. -/ @[simps] noncomputable def isoBinaryBiproduct (h : Splitting S) [HasBinaryBiproduct S.X₁ S.X₃] : S.X₂ ≅ S.X₁ ⊞ S.X₃ where hom := biprod.lift h.r S.g inv := biprod.desc S.f h.s hom_inv_id := by simp [h.id] end Splitting section Balanced variable {S} variable [Balanced C] namespace Exact lemma isIso_f' (hS : S.Exact) (h : S.LeftHomologyData) [Mono S.f] : IsIso h.f' := by have := hS.epi_f' h have := mono_of_mono_fac h.f'_i exact isIso_of_mono_of_epi h.f' lemma isIso_toCycles (hS : S.Exact) [Mono S.f] [S.HasLeftHomology]: IsIso S.toCycles := hS.isIso_f' _ lemma isIso_g' (hS : S.Exact) (h : S.RightHomologyData) [Epi S.g] : IsIso h.g' := by have := hS.mono_g' h have := epi_of_epi_fac h.p_g' exact isIso_of_mono_of_epi h.g' lemma isIso_fromOpcycles (hS : S.Exact) [Epi S.g] [S.HasRightHomology] : IsIso S.fromOpcycles := hS.isIso_g' _ /-- In a balanced category, if a short complex `S` is exact and `S.f` is a mono, then `S.X₁` is the kernel of `S.g`. -/
noncomputable def fIsKernel (hS : S.Exact) [Mono S.f] : IsLimit (KernelFork.ofι S.f S.zero) := by have := hS.hasHomology have := hS.isIso_toCycles exact IsLimit.ofIsoLimit S.cyclesIsKernel (Fork.ext (asIso S.toCycles).symm (by simp))
Mathlib/Algebra/Homology/ShortComplex/Exact.lean
728
732
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.Order.Antidiag.Finsupp import Mathlib.Data.Finsupp.Weight import Mathlib.Tactic.Linarith import Mathlib.LinearAlgebra.Pi import Mathlib.Algebra.MvPolynomial.Eval /-! # Formal (multivariate) power series This file defines multivariate formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. We provide the natural inclusion from multivariate polynomials to multivariate formal power series. ## Main definitions - `MvPowerSeries.C`: constant power series - `MvPowerSeries.X`: the indeterminates - `MvPowerSeries.coeff`, `MvPowerSeries.constantCoeff`: the coefficients of a `MvPowerSeries`, its constant coefficient - `MvPowerSeries.monomial`: the monomials - `MvPowerSeries.coeff_mul`: computes the coefficients of the product of two `MvPowerSeries` - `MvPowerSeries.coeff_prod` : computes the coefficients of products of `MvPowerSeries` - `MvPowerSeries.coeff_pow` : computes the coefficients of powers of a `MvPowerSeries` - `MvPowerSeries.coeff_eq_zero_of_constantCoeff_nilpotent`: if the constant coefficient of a `MvPowerSeries` is nilpotent, then some coefficients of its powers are automatically zero - `MvPowerSeries.map`: apply a `RingHom` to the coefficients of a `MvPowerSeries` (as a `RingHom) - `MvPowerSeries.X_pow_dvd_iff`, `MvPowerSeries.X_dvd_iff`: equivalent conditions for (a power of) an indeterminate to divide a `MvPowerSeries` - `MvPolynomial.toMvPowerSeries`: the canonical coercion from `MvPolynomial` to `MvPowerSeries` ## Note This file sets up the (semi)ring structure on multivariate power series: additional results are in: * `Mathlib.RingTheory.MvPowerSeries.Inverse` : invertibility, formal power series over a local ring form a local ring; * `Mathlib.RingTheory.MvPowerSeries.Trunc`: truncation of power series. In `Mathlib.RingTheory.PowerSeries.Basic`, formal power series in one variable will be obtained as a particular case, defined by `PowerSeries R := MvPowerSeries Unit R`. See that file for a specific description. ## Implementation notes In this file we define multivariate formal power series with variables indexed by `σ` and coefficients in `R` as `MvPowerSeries σ R := (σ →₀ ℕ) → R`. Unfortunately there is not yet enough API to show that they are the completion of the ring of multivariate polynomials. However, we provide most of the infrastructure that is needed to do this. Once I-adic completion (topological or algebraic) is available it should not be hard to fill in the details. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Multivariate formal power series, where `σ` is the index set of the variables and `R` is the coefficient ring. -/ def MvPowerSeries (σ : Type*) (R : Type*) := (σ →₀ ℕ) → R namespace MvPowerSeries open Finsupp variable {σ R : Type*} instance [Inhabited R] : Inhabited (MvPowerSeries σ R) := ⟨fun _ => default⟩ instance [Zero R] : Zero (MvPowerSeries σ R) := Pi.instZero instance [AddMonoid R] : AddMonoid (MvPowerSeries σ R) := Pi.addMonoid instance [AddGroup R] : AddGroup (MvPowerSeries σ R) := Pi.addGroup instance [AddCommMonoid R] : AddCommMonoid (MvPowerSeries σ R) := Pi.addCommMonoid instance [AddCommGroup R] : AddCommGroup (MvPowerSeries σ R) := Pi.addCommGroup instance [Nontrivial R] : Nontrivial (MvPowerSeries σ R) := Function.nontrivial instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R (MvPowerSeries σ A) := Pi.module _ _ _ instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S (MvPowerSeries σ A) := Pi.isScalarTower section Semiring variable (R) [Semiring R] /-- The `n`th monomial as multivariate formal power series: it is defined as the `R`-linear map from `R` to the semi-ring of multivariate formal power series associating to each `a` the map sending `n : σ →₀ ℕ` to the value `a` and sending all other `x : σ →₀ ℕ` different from `n` to `0`. -/ def monomial (n : σ →₀ ℕ) : R →ₗ[R] MvPowerSeries σ R := letI := Classical.decEq σ LinearMap.single R (fun _ ↦ R) n /-- The `n`th coefficient of a multivariate formal power series. -/ def coeff (n : σ →₀ ℕ) : MvPowerSeries σ R →ₗ[R] R := LinearMap.proj n theorem coeff_apply (f : MvPowerSeries σ R) (d : σ →₀ ℕ) : coeff R d f = f d := rfl variable {R} /-- Two multivariate formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ} (h : ∀ n : σ →₀ ℕ, coeff R n φ = coeff R n ψ) : φ = ψ := funext h /-- Two multivariate formal power series are equal if and only if all their coefficients are equal. -/ add_decl_doc MvPowerSeries.ext_iff theorem monomial_def [DecidableEq σ] (n : σ →₀ ℕ) : (monomial R n) = LinearMap.single R (fun _ ↦ R) n := by rw [monomial] -- unify the `Decidable` arguments convert rfl theorem coeff_monomial [DecidableEq σ] (m n : σ →₀ ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := by dsimp only [coeff, MvPowerSeries] rw [monomial_def, LinearMap.proj_apply (i := m), LinearMap.single_apply, Pi.single_apply] @[simp] theorem coeff_monomial_same (n : σ →₀ ℕ) (a : R) : coeff R n (monomial R n a) = a := by classical rw [monomial_def] exact Pi.single_eq_same _ _ theorem coeff_monomial_ne {m n : σ →₀ ℕ} (h : m ≠ n) (a : R) : coeff R m (monomial R n a) = 0 := by classical rw [monomial_def] exact Pi.single_eq_of_ne h _ theorem eq_of_coeff_monomial_ne_zero {m n : σ →₀ ℕ} {a : R} (h : coeff R m (monomial R n a) ≠ 0) : m = n := by_contra fun h' => h <| coeff_monomial_ne h' a @[simp] theorem coeff_comp_monomial (n : σ →₀ ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n @[simp] theorem coeff_zero (n : σ →₀ ℕ) : coeff R n (0 : MvPowerSeries σ R) = 0 := rfl theorem eq_zero_iff_forall_coeff_zero {f : MvPowerSeries σ R} : f = 0 ↔ (∀ d : σ →₀ ℕ, coeff R d f = 0) := MvPowerSeries.ext_iff theorem ne_zero_iff_exists_coeff_ne_zero (f : MvPowerSeries σ R) : f ≠ 0 ↔ (∃ d : σ →₀ ℕ, coeff R d f ≠ 0) := by simp only [MvPowerSeries.ext_iff, ne_eq, coeff_zero, not_forall] variable (m n : σ →₀ ℕ) (φ ψ : MvPowerSeries σ R) instance : One (MvPowerSeries σ R) := ⟨monomial R (0 : σ →₀ ℕ) 1⟩ theorem coeff_one [DecidableEq σ] : coeff R n (1 : MvPowerSeries σ R) = if n = 0 then 1 else 0 := coeff_monomial _ _ _ theorem coeff_zero_one : coeff R (0 : σ →₀ ℕ) 1 = 1 := coeff_monomial_same 0 1 theorem monomial_zero_one : monomial R (0 : σ →₀ ℕ) 1 = 1 := rfl instance : AddMonoidWithOne (MvPowerSeries σ R) := { show AddMonoid (MvPowerSeries σ R) by infer_instance with natCast := fun n => monomial R 0 n natCast_zero := by simp [Nat.cast] natCast_succ := by simp [Nat.cast, monomial_zero_one] one := 1 } instance : Mul (MvPowerSeries σ R) := letI := Classical.decEq σ ⟨fun φ ψ n => ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ⟩ theorem coeff_mul [DecidableEq σ] : coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by refine Finset.sum_congr ?_ fun _ _ => rfl rw [Subsingleton.elim (Classical.decEq σ) ‹DecidableEq σ›] protected theorem zero_mul : (0 : MvPowerSeries σ R) * φ = 0 := ext fun n => by classical simp [coeff_mul] protected theorem mul_zero : φ * 0 = 0 := ext fun n => by classical simp [coeff_mul] theorem coeff_monomial_mul (a : R) : coeff R m (monomial R n a * φ) = if n ≤ m then a * coeff R (m - n) φ else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 (monomial R n a) * coeff R p.2 φ ≠ 0 → p.1 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (left_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_fst_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] theorem coeff_mul_monomial (a : R) : coeff R m (φ * monomial R n a) = if n ≤ m then coeff R (m - n) φ * a else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 φ * coeff R p.2 (monomial R n a) ≠ 0 → p.2 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (right_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_snd_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] theorem coeff_add_monomial_mul (a : R) : coeff R (m + n) (monomial R m a * φ) = a * coeff R n φ := by rw [coeff_monomial_mul, if_pos, add_tsub_cancel_left] exact le_add_right le_rfl theorem coeff_add_mul_monomial (a : R) : coeff R (m + n) (φ * monomial R n a) = coeff R m φ * a := by rw [coeff_mul_monomial, if_pos, add_tsub_cancel_right] exact le_add_left le_rfl @[simp] theorem commute_monomial {a : R} {n} : Commute φ (monomial R n a) ↔ ∀ m, Commute (coeff R m φ) a := by rw [commute_iff_eq, MvPowerSeries.ext_iff] refine ⟨fun h m => ?_, fun h m => ?_⟩ · have := h (m + n) rwa [coeff_add_mul_monomial, add_comm, coeff_add_monomial_mul] at this · rw [coeff_mul_monomial, coeff_monomial_mul] split_ifs <;> [apply h; rfl] protected theorem one_mul : (1 : MvPowerSeries σ R) * φ = φ := ext fun n => by simpa using coeff_add_monomial_mul 0 n φ 1 protected theorem mul_one : φ * 1 = φ := ext fun n => by simpa using coeff_add_mul_monomial n 0 φ 1 protected theorem mul_add (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ := ext fun n => by classical simp only [coeff_mul, mul_add, Finset.sum_add_distrib, LinearMap.map_add] protected theorem add_mul (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : (φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ := ext fun n => by classical simp only [coeff_mul, add_mul, Finset.sum_add_distrib, LinearMap.map_add] protected theorem mul_assoc (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * φ₂ * φ₃ = φ₁ * (φ₂ * φ₃) := by ext1 n classical simp only [coeff_mul, Finset.sum_mul, Finset.mul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l + j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add simp [add_assoc, mul_assoc]) instance : Semiring (MvPowerSeries σ R) := { inferInstanceAs (AddMonoidWithOne (MvPowerSeries σ R)), inferInstanceAs (Mul (MvPowerSeries σ R)), inferInstanceAs (AddCommMonoid (MvPowerSeries σ R)) with mul_one := MvPowerSeries.mul_one one_mul := MvPowerSeries.one_mul mul_assoc := MvPowerSeries.mul_assoc mul_zero := MvPowerSeries.mul_zero zero_mul := MvPowerSeries.zero_mul left_distrib := MvPowerSeries.mul_add right_distrib := MvPowerSeries.add_mul } end Semiring instance [CommSemiring R] : CommSemiring (MvPowerSeries σ R) := { show Semiring (MvPowerSeries σ R) by infer_instance with mul_comm := fun φ ψ => ext fun n => by classical simpa only [coeff_mul, mul_comm] using sum_antidiagonal_swap n fun a b => coeff R a φ * coeff R b ψ } instance [Ring R] : Ring (MvPowerSeries σ R) := { inferInstanceAs (Semiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } instance [CommRing R] : CommRing (MvPowerSeries σ R) := { inferInstanceAs (CommSemiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } section Semiring variable [Semiring R] theorem monomial_mul_monomial (m n : σ →₀ ℕ) (a b : R) : monomial R m a * monomial R n b = monomial R (m + n) (a * b) := by classical ext k simp only [coeff_mul_monomial, coeff_monomial] split_ifs with h₁ h₂ h₃ h₃ h₂ <;> try rfl · rw [← h₂, tsub_add_cancel_of_le h₁] at h₃ exact (h₃ rfl).elim · rw [h₃, add_tsub_cancel_right] at h₂ exact (h₂ rfl).elim · exact zero_mul b · rw [h₂] at h₁ exact (h₁ <| le_add_left le_rfl).elim variable (σ) (R) /-- The constant multivariate formal power series. -/ def C : R →+* MvPowerSeries σ R := { monomial R (0 : σ →₀ ℕ) with map_one' := rfl map_mul' := fun a b => (monomial_mul_monomial 0 0 a b).symm map_zero' := (monomial R 0).map_zero } variable {σ} {R} @[simp] theorem monomial_zero_eq_C : ⇑(monomial R (0 : σ →₀ ℕ)) = C σ R := rfl theorem monomial_zero_eq_C_apply (a : R) : monomial R (0 : σ →₀ ℕ) a = C σ R a := rfl theorem coeff_C [DecidableEq σ] (n : σ →₀ ℕ) (a : R) : coeff R n (C σ R a) = if n = 0 then a else 0 := coeff_monomial _ _ _ theorem coeff_zero_C (a : R) : coeff R (0 : σ →₀ ℕ) (C σ R a) = a := coeff_monomial_same 0 a /-- The variables of the multivariate formal power series ring. -/ def X (s : σ) : MvPowerSeries σ R := monomial R (single s 1) 1 theorem coeff_X [DecidableEq σ] (n : σ →₀ ℕ) (s : σ) : coeff R n (X s : MvPowerSeries σ R) = if n = single s 1 then 1 else 0 := coeff_monomial _ _ _ theorem coeff_index_single_X [DecidableEq σ] (s t : σ) : coeff R (single t 1) (X s : MvPowerSeries σ R) = if t = s then 1 else 0 := by simp only [coeff_X, single_left_inj (one_ne_zero : (1 : ℕ) ≠ 0)] @[simp] theorem coeff_index_single_self_X (s : σ) : coeff R (single s 1) (X s : MvPowerSeries σ R) = 1 := coeff_monomial_same _ _ theorem coeff_zero_X (s : σ) : coeff R (0 : σ →₀ ℕ) (X s : MvPowerSeries σ R) = 0 := by classical rw [coeff_X, if_neg] intro h exact one_ne_zero (single_eq_zero.mp h.symm) theorem commute_X (φ : MvPowerSeries σ R) (s : σ) : Commute φ (X s) := φ.commute_monomial.mpr fun _m => Commute.one_right _ theorem X_mul {φ : MvPowerSeries σ R} {s : σ} : X s * φ = φ * X s := φ.commute_X s |>.symm.eq theorem commute_X_pow (φ : MvPowerSeries σ R) (s : σ) (n : ℕ) : Commute φ (X s ^ n) := φ.commute_X s |>.pow_right _ theorem X_pow_mul {φ : MvPowerSeries σ R} {s : σ} {n : ℕ} : X s ^ n * φ = φ * X s ^ n := φ.commute_X_pow s n |>.symm.eq theorem X_def (s : σ) : X s = monomial R (single s 1) 1 := rfl theorem X_pow_eq (s : σ) (n : ℕ) : (X s : MvPowerSeries σ R) ^ n = monomial R (single s n) 1 := by induction n with | zero => simp | succ n ih => rw [pow_succ, ih, Finsupp.single_add, X, monomial_mul_monomial, one_mul] theorem coeff_X_pow [DecidableEq σ] (m : σ →₀ ℕ) (s : σ) (n : ℕ) : coeff R m ((X s : MvPowerSeries σ R) ^ n) = if m = single s n then 1 else 0 := by rw [X_pow_eq s n, coeff_monomial] @[simp] theorem coeff_mul_C (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (φ * C σ R a) = coeff R n φ * a := by simpa using coeff_add_mul_monomial n 0 φ a @[simp] theorem coeff_C_mul (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (C σ R a * φ) = a * coeff R n φ := by simpa using coeff_add_monomial_mul 0 n φ a theorem coeff_zero_mul_X (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (φ * X s) = 0 := by have : ¬single s 1 ≤ 0 := fun h => by simpa using h s simp only [X, coeff_mul_monomial, if_neg this] theorem coeff_zero_X_mul (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (X s * φ) = 0 := by rw [← (φ.commute_X s).eq, coeff_zero_mul_X] variable (σ) (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : MvPowerSeries σ R →+* R := { coeff R (0 : σ →₀ ℕ) with toFun := coeff R (0 : σ →₀ ℕ) map_one' := coeff_zero_one map_mul' := fun φ ψ => by classical simp [coeff_mul, support_single_ne_zero] map_zero' := LinearMap.map_zero _ } variable {σ} {R} @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R (0 : σ →₀ ℕ)) = constantCoeff σ R := rfl theorem coeff_zero_eq_constantCoeff_apply (φ : MvPowerSeries σ R) : coeff R (0 : σ →₀ ℕ) φ = constantCoeff σ R φ := rfl @[simp] theorem constantCoeff_C (a : R) : constantCoeff σ R (C σ R a) = a := rfl @[simp] theorem constantCoeff_comp_C : (constantCoeff σ R).comp (C σ R) = RingHom.id R := rfl @[simp] theorem constantCoeff_zero : constantCoeff σ R 0 = 0 := rfl @[simp] theorem constantCoeff_one : constantCoeff σ R 1 = 1 := rfl @[simp] theorem constantCoeff_X (s : σ) : constantCoeff σ R (X s) = 0 := coeff_zero_X s @[simp] theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : MvPowerSeries σ S) (a : R) : constantCoeff σ S (a • φ) = a • constantCoeff σ S φ := rfl /-- If a multivariate formal power series is invertible, then so is its constant coefficient. -/ theorem isUnit_constantCoeff (φ : MvPowerSeries σ R) (h : IsUnit φ) : IsUnit (constantCoeff σ R φ) := h.map _ @[simp] theorem coeff_smul (f : MvPowerSeries σ R) (n) (a : R) : coeff _ n (a • f) = a * coeff _ n f := rfl theorem smul_eq_C_mul (f : MvPowerSeries σ R) (a : R) : a • f = C σ R a * f := by ext simp theorem X_inj [Nontrivial R] {s t : σ} : (X s : MvPowerSeries σ R) = X t ↔ s = t := ⟨by classical intro h replace h := congr_arg (coeff R (single s 1)) h rw [coeff_X, if_pos rfl, coeff_X] at h split_ifs at h with H · rw [Finsupp.single_eq_single_iff] at H rcases H with H | H · exact H.1 · exfalso exact one_ne_zero H.1 · exfalso exact one_ne_zero h, congr_arg X⟩ end Semiring section Map variable {S T : Type*} [Semiring R] [Semiring S] [Semiring T] variable (f : R →+* S) (g : S →+* T) variable (σ) in /-- The map between multivariate formal power series induced by a map on the coefficients. -/ def map : MvPowerSeries σ R →+* MvPowerSeries σ S where toFun φ n := f <| coeff R n φ map_zero' := ext fun _n => f.map_zero map_one' := ext fun n => show f ((coeff R n) 1) = (coeff S n) 1 by classical rw [coeff_one, coeff_one] split_ifs with h · simp only [ite_true, map_one, h] · simp only [ite_false, map_zero, h] map_add' φ ψ := ext fun n => show f ((coeff R n) (φ + ψ)) = f ((coeff R n) φ) + f ((coeff R n) ψ) by simp map_mul' φ ψ := ext fun n => show f _ = _ by classical rw [coeff_mul, map_sum, coeff_mul] apply Finset.sum_congr rfl rintro ⟨i, j⟩ _; rw [f.map_mul]; rfl @[simp] theorem map_id : map σ (RingHom.id R) = RingHom.id _ := rfl theorem map_comp : map σ (g.comp f) = (map σ g).comp (map σ f) := rfl @[simp] theorem coeff_map (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) : coeff S n (map σ f φ) = f (coeff R n φ) := rfl @[simp] theorem constantCoeff_map (φ : MvPowerSeries σ R) : constantCoeff σ S (map σ f φ) = f (constantCoeff σ R φ) := rfl @[simp] theorem map_monomial (n : σ →₀ ℕ) (a : R) : map σ f (monomial R n a) = monomial S n (f a) := by classical ext m simp [coeff_monomial, apply_ite f] @[simp] theorem map_C (a : R) : map σ f (C σ R a) = C σ S (f a) := map_monomial _ _ _ @[simp] theorem map_X (s : σ) : map σ f (X s) = X s := by simp [MvPowerSeries.X] end Map @[simp] theorem map_eq_zero {S : Type*} [DivisionSemiring R] [Semiring S] [Nontrivial S] (φ : MvPowerSeries σ R) (f : R →+* S) : φ.map σ f = 0 ↔ φ = 0 := by simp only [MvPowerSeries.ext_iff] congr! with n simp section Semiring variable [Semiring R] theorem X_pow_dvd_iff {s : σ} {n : ℕ} {φ : MvPowerSeries σ R} : (X s : MvPowerSeries σ R) ^ n ∣ φ ↔ ∀ m : σ →₀ ℕ, m s < n → coeff R m φ = 0 := by classical constructor · rintro ⟨φ, rfl⟩ m h rw [coeff_mul, Finset.sum_eq_zero] rintro ⟨i, j⟩ hij rw [coeff_X_pow, if_neg, zero_mul] contrapose! h dsimp at h subst i rw [mem_antidiagonal] at hij rw [← hij, Finsupp.add_apply, Finsupp.single_eq_same] exact Nat.le_add_right n _ · intro h refine ⟨fun m => coeff R (m + single s n) φ, ?_⟩ ext m by_cases H : m - single s n + single s n = m · rw [coeff_mul, Finset.sum_eq_single (single s n, m - single s n)] · rw [coeff_X_pow, if_pos rfl, one_mul] simpa using congr_arg (fun m : σ →₀ ℕ => coeff R m φ) H.symm · rintro ⟨i, j⟩ hij hne rw [mem_antidiagonal] at hij rw [coeff_X_pow] split_ifs with hi · exfalso apply hne rw [← hij, ← hi, Prod.mk_inj] refine ⟨rfl, ?_⟩ ext t simp only [add_tsub_cancel_left, Finsupp.add_apply, Finsupp.tsub_apply] · exact zero_mul _ · intro hni exfalso apply hni rwa [mem_antidiagonal, add_comm] · rw [h, coeff_mul, Finset.sum_eq_zero] · rintro ⟨i, j⟩ hij rw [mem_antidiagonal] at hij rw [coeff_X_pow] split_ifs with hi · exfalso apply H rw [← hij, hi] ext rw [coe_add, coe_add, Pi.add_apply, Pi.add_apply, add_tsub_cancel_left, add_comm] · exact zero_mul _ · contrapose! H ext t by_cases hst : s = t · subst t simpa using tsub_add_cancel_of_le H · simp [Finsupp.single_apply, hst] theorem X_dvd_iff {s : σ} {φ : MvPowerSeries σ R} : (X s : MvPowerSeries σ R) ∣ φ ↔ ∀ m : σ →₀ ℕ, m s = 0 → coeff R m φ = 0 := by rw [← pow_one (X s : MvPowerSeries σ R), X_pow_dvd_iff] constructor <;> intro h m hm · exact h m (hm.symm ▸ zero_lt_one) · exact h m (Nat.eq_zero_of_le_zero <| Nat.le_of_succ_le_succ hm) end Semiring section CommSemiring open Finset.HasAntidiagonal Finset variable {R : Type*} [CommSemiring R] {ι : Type*} [DecidableEq ι] /-- Coefficients of a product of power series -/ theorem coeff_prod [DecidableEq σ] (f : ι → MvPowerSeries σ R) (d : σ →₀ ℕ) (s : Finset ι) : coeff R d (∏ j ∈ s, f j) = ∑ l ∈ finsuppAntidiag s d, ∏ i ∈ s, coeff R (l i) (f i) := by induction s using Finset.induction_on generalizing d with | empty => simp only [prod_empty, sum_const, nsmul_eq_mul, mul_one, coeff_one, finsuppAntidiag_empty] split_ifs · simp only [card_singleton, Nat.cast_one] · simp only [card_empty, Nat.cast_zero] | insert a s ha ih => rw [finsuppAntidiag_insert ha, prod_insert ha, coeff_mul, sum_biUnion] · apply Finset.sum_congr rfl simp only [mem_antidiagonal, sum_map, Function.Embedding.coeFn_mk, coe_update, Prod.forall] rintro u v rfl rw [ih, Finset.mul_sum, ← Finset.sum_attach] apply Finset.sum_congr rfl simp only [mem_attach, Finset.prod_insert ha, Function.update_self, forall_true_left, Subtype.forall] rintro x - rw [Finset.prod_congr rfl] intro i hi rw [Function.update_of_ne] exact ne_of_mem_of_not_mem hi ha · simp only [Set.PairwiseDisjoint, Set.Pairwise, mem_coe, mem_antidiagonal, ne_eq, disjoint_left, mem_map, mem_attach, Function.Embedding.coeFn_mk, true_and, Subtype.exists, exists_prop, not_exists, not_and, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Prod.forall, Prod.mk.injEq] rintro u v rfl u' v' huv h k - l - hkl obtain rfl : u' = u := by simpa only [Finsupp.coe_update, Function.update_self] using DFunLike.congr_fun hkl a simp only [add_right_inj] at huv exact h rfl huv.symm /-- The `d`th coefficient of a power of a multivariate power series is the sum, indexed by `finsuppAntidiag (Finset.range n) d`, of products of coefficients -/ theorem coeff_pow [DecidableEq σ] (f : MvPowerSeries σ R) {n : ℕ} (d : σ →₀ ℕ) : coeff R d (f ^ n) = ∑ l ∈ finsuppAntidiag (Finset.range n) d, ∏ i ∈ Finset.range n, coeff R (l i) f := by suffices f ^ n = (Finset.range n).prod fun _ ↦ f by rw [this, coeff_prod] rw [Finset.prod_const, card_range]
/-- Vanishing of coefficients of powers of multivariate power series when the constant coefficient is nilpotent [N. Bourbaki, *Algebra {II}*, Chapter 4, §4, n°2, proposition 3][bourbaki1981] -/ theorem coeff_eq_zero_of_constantCoeff_nilpotent {f : MvPowerSeries σ R} {m : ℕ} (hf : constantCoeff σ R f ^ m = 0) {d : σ →₀ ℕ} {n : ℕ} (hn : m + degree d ≤ n) : coeff R d (f ^ n) = 0 := by classical rw [coeff_pow] apply sum_eq_zero intro k hk rw [mem_finsuppAntidiag] at hk set s := {i ∈ range n | k i = 0} with hs_def have hs : s ⊆ range n := filter_subset _ _ have hs' (i : ℕ) (hi : i ∈ s) : coeff R (k i) f = constantCoeff σ R f := by simp only [hs_def, mem_filter] at hi rw [hi.2, coeff_zero_eq_constantCoeff] have hs'' (i : ℕ) (hi : i ∈ s) : k i = 0 := by simp only [hs_def, mem_filter] at hi rw [hi.2] rw [← prod_sdiff (s₁ := s) (filter_subset _ _)] apply mul_eq_zero_of_right rw [prod_congr rfl hs', prod_const] suffices m ≤ #s by obtain ⟨m', hm'⟩ := Nat.exists_eq_add_of_le this rw [hm', pow_add, hf, MulZeroClass.zero_mul] rw [← Nat.add_le_add_iff_right, add_comm #s, Finset.card_sdiff_add_card_eq_card (filter_subset _ _), card_range] apply le_trans _ hn simp only [add_comm m, Nat.add_le_add_iff_right, ← hk.1, ← sum_sdiff (hs), sum_eq_zero (s := s) hs'', add_zero] rw [← hs_def] convert Finset.card_nsmul_le_sum (range n \ s) (fun x ↦ degree (k x)) 1 _ · simp only [Algebra.id.smul_eq_mul, mul_one] · simp only [degree_eq_weight_one, map_sum]
Mathlib/RingTheory/MvPowerSeries/Basic.lean
687
720
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Combinatorics.SimpleGraph.Clique import Mathlib.Order.Partition.Equipartition /-! # Turán's theorem In this file we prove Turán's theorem, the first important result of extremal graph theory, which states that the `r + 1`-cliquefree graph on `n` vertices with the most edges is the complete `r`-partite graph with part sizes as equal as possible (`turanGraph n r`). The forward direction of the proof performs "Zykov symmetrisation", which first shows constructively that non-adjacency is an equivalence relation in a maximal graph, so it must be complete multipartite with the parts being the equivalence classes. Then basic manipulations show that the graph is isomorphic to the Turán graph for the given parameters. For the reverse direction we first show that a Turán-maximal graph exists, then transfer the property through `turanGraph n r` using the isomorphism provided by the forward direction. ## Main declarations * `SimpleGraph.IsTuranMaximal`: `G.IsTuranMaximal r` means that `G` has the most number of edges for its number of vertices while still being `r + 1`-cliquefree. * `SimpleGraph.turanGraph n r`: The canonical `r + 1`-cliquefree Turán graph on `n` vertices. * `SimpleGraph.IsTuranMaximal.finpartition`: The result of Zykov symmetrisation, a finpartition of the vertices such that two vertices are in the same part iff they are non-adjacent. * `SimpleGraph.IsTuranMaximal.nonempty_iso_turanGraph`: The forward direction, an isomorphism between `G` satisfying `G.IsTuranMaximal r` and `turanGraph n r`. * `isTuranMaximal_of_iso`: the reverse direction, `G.IsTuranMaximal r` given the isomorphism. * `isTuranMaximal_iff_nonempty_iso_turanGraph`: Turán's theorem in full. ## References * https://en.wikipedia.org/wiki/Turán%27s_theorem -/ open Finset namespace SimpleGraph variable {V : Type*} [Fintype V] {G : SimpleGraph V} [DecidableRel G.Adj] {n r : ℕ} variable (G) in /-- An `r + 1`-cliquefree graph is `r`-Turán-maximal if any other `r + 1`-cliquefree graph on the same vertex set has the same or fewer number of edges. -/ def IsTuranMaximal (r : ℕ) : Prop := G.CliqueFree (r + 1) ∧ ∀ (H : SimpleGraph V) [DecidableRel H.Adj], H.CliqueFree (r + 1) → #H.edgeFinset ≤ #G.edgeFinset section Defs variable {H : SimpleGraph V} lemma IsTuranMaximal.le_iff_eq (hG : G.IsTuranMaximal r) (hH : H.CliqueFree (r + 1)) : G ≤ H ↔ G = H := by classical exact ⟨fun hGH ↦ edgeFinset_inj.1 <| eq_of_subset_of_card_le (edgeFinset_subset_edgeFinset.2 hGH) (hG.2 _ hH), le_of_eq⟩ /-- The canonical `r + 1`-cliquefree Turán graph on `n` vertices. -/ def turanGraph (n r : ℕ) : SimpleGraph (Fin n) where Adj v w := v % r ≠ w % r instance turanGraph.instDecidableRelAdj : DecidableRel (turanGraph n r).Adj := by dsimp only [turanGraph]; infer_instance @[simp] lemma turanGraph_zero : turanGraph n 0 = ⊤ := by ext a b; simp_rw [turanGraph, top_adj, Nat.mod_zero, not_iff_not, Fin.val_inj] @[simp] theorem turanGraph_eq_top : turanGraph n r = ⊤ ↔ r = 0 ∨ n ≤ r := by simp_rw [SimpleGraph.ext_iff, funext_iff, turanGraph, top_adj, eq_iff_iff, not_iff_not] refine ⟨fun h ↦ ?_, ?_⟩ · contrapose! h use ⟨0, (Nat.pos_of_ne_zero h.1).trans h.2⟩, ⟨r, h.2⟩ simp [h.1.symm] · rintro (rfl | h) a b · simp [Fin.val_inj] · rw [Nat.mod_eq_of_lt (a.2.trans_le h), Nat.mod_eq_of_lt (b.2.trans_le h), Fin.val_inj] theorem turanGraph_cliqueFree (hr : 0 < r) : (turanGraph n r).CliqueFree (r + 1) := by rw [cliqueFree_iff] by_contra h rw [not_isEmpty_iff] at h obtain ⟨f, ha⟩ := h simp only [turanGraph, top_adj] at ha obtain ⟨x, y, d, c⟩ := Fintype.exists_ne_map_eq_of_card_lt (fun x ↦ (⟨(f x).1 % r, Nat.mod_lt _ hr⟩ : Fin r)) (by simp) simp only [Fin.mk.injEq] at c exact absurd c ((@ha x y).mpr d) /-- An `r + 1`-cliquefree Turán-maximal graph is _not_ `r`-cliquefree if it can accommodate such a clique. -/ theorem not_cliqueFree_of_isTuranMaximal (hn : r ≤ Fintype.card V) (hG : G.IsTuranMaximal r) : ¬G.CliqueFree r := by rintro h obtain ⟨K, _, rfl⟩ := exists_subset_card_eq hn obtain ⟨a, -, b, -, hab, hGab⟩ : ∃ a ∈ K, ∃ b ∈ K, a ≠ b ∧ ¬ G.Adj a b := by simpa only [isNClique_iff, IsClique, Set.Pairwise, mem_coe, ne_eq, and_true, not_forall, exists_prop, exists_and_right] using h K exact hGab <| le_sup_right.trans_eq ((hG.le_iff_eq <| h.sup_edge _ _).1 le_sup_left).symm <| (edge_adj ..).2 ⟨Or.inl ⟨rfl, rfl⟩, hab⟩ lemma exists_isTuranMaximal (hr : 0 < r): ∃ H : SimpleGraph V, ∃ _ : DecidableRel H.Adj, H.IsTuranMaximal r := by classical let c := {H : SimpleGraph V | H.CliqueFree (r + 1)} have cn : c.toFinset.Nonempty := ⟨⊥, by simp only [Set.toFinset_setOf, mem_filter, mem_univ, true_and, c] exact cliqueFree_bot (by omega)⟩ obtain ⟨S, Sm, Sl⟩ := exists_max_image c.toFinset (#·.edgeFinset) cn use S, inferInstance rw [Set.mem_toFinset] at Sm refine ⟨Sm, fun I _ cf ↦ ?_⟩ by_cases Im : I ∈ c.toFinset · convert Sl I Im · rw [Set.mem_toFinset] at Im contradiction end Defs namespace IsTuranMaximal variable {s t u : V} /-- In a Turán-maximal graph, non-adjacent vertices have the same degree. -/ lemma degree_eq_of_not_adj (h : G.IsTuranMaximal r) (hn : ¬G.Adj s t) : G.degree s = G.degree t := by rw [IsTuranMaximal] at h; contrapose! h; intro cf wlog hd : G.degree t < G.degree s generalizing G t s · replace hd : G.degree s < G.degree t := lt_of_le_of_ne (le_of_not_lt hd) h exact this (by rwa [adj_comm] at hn) hd.ne' cf hd classical use G.replaceVertex s t, inferInstance, cf.replaceVertex s t have := G.card_edgeFinset_replaceVertex_of_not_adj hn omega /-- In a Turán-maximal graph, non-adjacency is transitive. -/ lemma not_adj_trans (h : G.IsTuranMaximal r) (hts : ¬G.Adj t s) (hsu : ¬G.Adj s u) : ¬G.Adj t u := by have hst : ¬G.Adj s t := fun a ↦ hts a.symm have dst := h.degree_eq_of_not_adj hst have dsu := h.degree_eq_of_not_adj hsu rw [IsTuranMaximal] at h; contrapose! h; intro cf classical use (G.replaceVertex s t).replaceVertex s u, inferInstance, (cf.replaceVertex s t).replaceVertex s u have nst : s ≠ t := fun a ↦ hsu (a ▸ h) have ntu : t ≠ u := G.ne_of_adj h have := (G.adj_replaceVertex_iff_of_ne s nst ntu.symm).not.mpr hsu rw [card_edgeFinset_replaceVertex_of_not_adj _ this, card_edgeFinset_replaceVertex_of_not_adj _ hst, dst, Nat.add_sub_cancel] have l1 : (G.replaceVertex s t).degree s = G.degree s := by unfold degree; congr 1; ext v simp only [mem_neighborFinset, SimpleGraph.irrefl, ite_self] by_cases eq : v = t · simpa only [eq, not_adj_replaceVertex_same, false_iff] · rw [G.adj_replaceVertex_iff_of_ne s nst eq] have l2 : (G.replaceVertex s t).degree u = G.degree u - 1 := by rw [degree, degree, ← card_singleton t, ← card_sdiff (by simp [h.symm])] congr 1; ext v simp only [mem_neighborFinset, mem_sdiff, mem_singleton, replaceVertex] split_ifs <;> simp_all [adj_comm] have l3 : 0 < G.degree u := by rw [G.degree_pos_iff_exists_adj u]; use t, h.symm omega variable (h : G.IsTuranMaximal r) include h /-- In a Turán-maximal graph, non-adjacency is an equivalence relation. -/ theorem equivalence_not_adj : Equivalence (¬G.Adj · ·) where refl := by simp symm := by simp [adj_comm] trans := h.not_adj_trans /-- The non-adjacency setoid over the vertices of a Turán-maximal graph induced by `equivalence_not_adj`. -/ def setoid : Setoid V := ⟨_, h.equivalence_not_adj⟩ instance : DecidableRel h.setoid.r :=
inferInstanceAs <| DecidableRel (¬G.Adj · ·) /-- The finpartition derived from `h.setoid`. -/ def finpartition [DecidableEq V] : Finpartition (univ : Finset V) := Finpartition.ofSetoid h.setoid lemma not_adj_iff_part_eq [DecidableEq V] :
Mathlib/Combinatorics/SimpleGraph/Turan.lean
184
189
/- Copyright (c) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov, Winston Yin -/ import Mathlib.Algebra.Group.End import Mathlib.Topology.EMetricSpace.Diam /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we provide various ways to prove that various combinations of Lipschitz continuous functions are Lipschitz continuous. We also prove that Lipschitz continuous functions are uniformly continuous, and that locally Lipschitz functions are continuous. ## Main definitions and lemmas * `LipschitzWith K f`: states that `f` is Lipschitz with constant `K : ℝ≥0` * `LipschitzOnWith K f s`: states that `f` is Lipschitz with constant `K : ℝ≥0` on a set `s` * `LipschitzWith.uniformContinuous`: a Lipschitz function is uniformly continuous * `LipschitzOnWith.uniformContinuousOn`: a function which is Lipschitz on a set `s` is uniformly continuous on `s`. * `LocallyLipschitz f`: states that `f` is locally Lipschitz * `LocallyLipschitzOn f s`: states that `f` is locally Lipschitz on `s`. * `LocallyLipschitz.continuous`: a locally Lipschitz function is continuous. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {K : ℝ≥0} {s t : Set α} {f : α → β} /-- A function `f` is **Lipschitz continuous** with constant `K ≥ 0` if for all `x, y` we have `dist (f x) (f y) ≤ K * dist x y`. -/ def LipschitzWith (K : ℝ≥0) (f : α → β) := ∀ x y, edist (f x) (f y) ≤ K * edist x y /-- A function `f` is **Lipschitz continuous** with constant `K ≥ 0` **on `s`** if for all `x, y` in `s` we have `dist (f x) (f y) ≤ K * dist x y`. -/ def LipschitzOnWith (K : ℝ≥0) (f : α → β) (s : Set α) := ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → edist (f x) (f y) ≤ K * edist x y /-- `f : α → β` is called **locally Lipschitz continuous** iff every point `x` has a neighbourhood on which `f` is Lipschitz. -/ def LocallyLipschitz (f : α → β) : Prop := ∀ x, ∃ K, ∃ t ∈ 𝓝 x, LipschitzOnWith K f t /-- `f : α → β` is called **locally Lipschitz continuous** on `s` iff every point `x` of `s` has a neighbourhood within `s` on which `f` is Lipschitz. -/ def LocallyLipschitzOn (s : Set α) (f : α → β) : Prop := ∀ ⦃x⦄, x ∈ s → ∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t /-- Every function is Lipschitz on the empty set (with any Lipschitz constant). -/ @[simp] theorem lipschitzOnWith_empty (K : ℝ≥0) (f : α → β) : LipschitzOnWith K f ∅ := fun _ => False.elim @[simp] lemma locallyLipschitzOn_empty (f : α → β) : LocallyLipschitzOn ∅ f := fun _ ↦ False.elim /-- Being Lipschitz on a set is monotone w.r.t. that set. -/ theorem LipschitzOnWith.mono (hf : LipschitzOnWith K f t) (h : s ⊆ t) : LipschitzOnWith K f s := fun _x x_in _y y_in => hf (h x_in) (h y_in) lemma LocallyLipschitzOn.mono (hf : LocallyLipschitzOn t f) (h : s ⊆ t) : LocallyLipschitzOn s f := fun x hx ↦ by obtain ⟨K, u, hu, hfu⟩ := hf (h hx); exact ⟨K, u, nhdsWithin_mono _ h hu, hfu⟩ /-- `f` is Lipschitz iff it is Lipschitz on the entire space. -/ @[simp] lemma lipschitzOnWith_univ : LipschitzOnWith K f univ ↔ LipschitzWith K f := by simp [LipschitzOnWith, LipschitzWith] @[simp] lemma locallyLipschitzOn_univ : LocallyLipschitzOn univ f ↔ LocallyLipschitz f := by simp [LocallyLipschitzOn, LocallyLipschitz] protected lemma LocallyLipschitz.locallyLipschitzOn (h : LocallyLipschitz f) : LocallyLipschitzOn s f := (locallyLipschitzOn_univ.2 h).mono s.subset_univ theorem lipschitzOnWith_iff_restrict : LipschitzOnWith K f s ↔ LipschitzWith K (s.restrict f) := by simp [LipschitzOnWith, LipschitzWith] lemma lipschitzOnWith_restrict {t : Set s} : LipschitzOnWith K (s.restrict f) t ↔ LipschitzOnWith K f (s ∩ Subtype.val '' t) := by simp [LipschitzOnWith, LipschitzWith] lemma locallyLipschitzOn_iff_restrict : LocallyLipschitzOn s f ↔ LocallyLipschitz (s.restrict f) := by simp only [LocallyLipschitzOn, LocallyLipschitz, SetCoe.forall', restrict_apply, Subtype.edist_mk_mk, ← lipschitzOnWith_iff_restrict, lipschitzOnWith_restrict, nhds_subtype_eq_comap_nhdsWithin, mem_comap] congr! with x K constructor · rintro ⟨t, ht, hft⟩ exact ⟨_, ⟨t, ht, Subset.rfl⟩, hft.mono <| inter_subset_right.trans <| image_preimage_subset ..⟩ · rintro ⟨t, ⟨u, hu, hut⟩, hft⟩ exact ⟨s ∩ u, Filter.inter_mem self_mem_nhdsWithin hu, hft.mono fun x hx ↦ ⟨hx.1, ⟨x, hx.1⟩, hut hx.2, rfl⟩⟩ alias ⟨LipschitzOnWith.to_restrict, _⟩ := lipschitzOnWith_iff_restrict alias ⟨LocallyLipschitzOn.restrict, _⟩ := locallyLipschitzOn_iff_restrict lemma Set.MapsTo.lipschitzOnWith_iff_restrict {t : Set β} (h : MapsTo f s t) : LipschitzOnWith K f s ↔ LipschitzWith K (h.restrict f s t) := _root_.lipschitzOnWith_iff_restrict alias ⟨LipschitzOnWith.to_restrict_mapsTo, _⟩ := Set.MapsTo.lipschitzOnWith_iff_restrict end PseudoEMetricSpace namespace LipschitzWith open EMetric variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ≥0∞} {s : Set α} protected theorem lipschitzOnWith (h : LipschitzWith K f) : LipschitzOnWith K f s := fun x _ y _ => h x y theorem edist_le_mul (h : LipschitzWith K f) (x y : α) : edist (f x) (f y) ≤ K * edist x y := h x y theorem edist_le_mul_of_le (h : LipschitzWith K f) (hr : edist x y ≤ r) : edist (f x) (f y) ≤ K * r := (h x y).trans <| mul_left_mono hr theorem edist_lt_mul_of_lt (h : LipschitzWith K f) (hK : K ≠ 0) (hr : edist x y < r) : edist (f x) (f y) < K * r := (h x y).trans_lt <| (ENNReal.mul_lt_mul_left (ENNReal.coe_ne_zero.2 hK) ENNReal.coe_ne_top).2 hr theorem mapsTo_emetric_closedBall (h : LipschitzWith K f) (x : α) (r : ℝ≥0∞) : MapsTo f (closedBall x r) (closedBall (f x) (K * r)) := fun _y hy => h.edist_le_mul_of_le hy theorem mapsTo_emetric_ball (h : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ≥0∞) : MapsTo f (ball x r) (ball (f x) (K * r)) := fun _y hy => h.edist_lt_mul_of_lt hK hy theorem edist_lt_top (hf : LipschitzWith K f) {x y : α} (h : edist x y ≠ ⊤) : edist (f x) (f y) < ⊤ := (hf x y).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_lt_top h.lt_top theorem mul_edist_le (h : LipschitzWith K f) (x y : α) : (K⁻¹ : ℝ≥0∞) * edist (f x) (f y) ≤ edist x y := by rw [mul_comm, ← div_eq_mul_inv] exact ENNReal.div_le_of_le_mul' (h x y) protected theorem of_edist_le (h : ∀ x y, edist (f x) (f y) ≤ edist x y) : LipschitzWith 1 f := fun x y => by simp only [ENNReal.coe_one, one_mul, h] protected theorem weaken (hf : LipschitzWith K f) {K' : ℝ≥0} (h : K ≤ K') : LipschitzWith K' f := fun x y => le_trans (hf x y) <| mul_right_mono (ENNReal.coe_le_coe.2 h) theorem ediam_image_le (hf : LipschitzWith K f) (s : Set α) : EMetric.diam (f '' s) ≤ K * EMetric.diam s := by apply EMetric.diam_le rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ exact hf.edist_le_mul_of_le (EMetric.edist_le_diam_of_mem hx hy) theorem edist_lt_of_edist_lt_div (hf : LipschitzWith K f) {x y : α} {d : ℝ≥0∞} (h : edist x y < d / K) : edist (f x) (f y) < d := calc edist (f x) (f y) ≤ K * edist x y := hf x y _ < d := ENNReal.mul_lt_of_lt_div' h /-- A Lipschitz function is uniformly continuous. -/ protected theorem uniformContinuous (hf : LipschitzWith K f) : UniformContinuous f := EMetric.uniformContinuous_iff.2 fun ε εpos => ⟨ε / K, ENNReal.div_pos_iff.2 ⟨ne_of_gt εpos, ENNReal.coe_ne_top⟩, hf.edist_lt_of_edist_lt_div⟩ /-- A Lipschitz function is continuous. -/ protected theorem continuous (hf : LipschitzWith K f) : Continuous f := hf.uniformContinuous.continuous /-- Constant functions are Lipschitz (with any constant). -/ protected theorem const (b : β) : LipschitzWith 0 fun _ : α => b := fun x y => by simp only [edist_self, zero_le] protected theorem const' (b : β) {K : ℝ≥0} : LipschitzWith K fun _ : α => b := fun x y => by simp only [edist_self, zero_le] /-- The identity is 1-Lipschitz. -/ protected theorem id : LipschitzWith 1 (@id α) := LipschitzWith.of_edist_le fun _ _ => le_rfl /-- The inclusion of a subset is 1-Lipschitz. -/ protected theorem subtype_val (s : Set α) : LipschitzWith 1 (Subtype.val : s → α) := LipschitzWith.of_edist_le fun _ _ => le_rfl theorem subtype_mk (hf : LipschitzWith K f) {p : β → Prop} (hp : ∀ x, p (f x)) : LipschitzWith K (fun x => ⟨f x, hp x⟩ : α → { y // p y }) := hf protected theorem eval {α : ι → Type u} [∀ i, PseudoEMetricSpace (α i)] [Fintype ι] (i : ι) : LipschitzWith 1 (Function.eval i : (∀ i, α i) → α i) := LipschitzWith.of_edist_le fun f g => by convert edist_le_pi_edist f g i /-- The restriction of a `K`-Lipschitz function is `K`-Lipschitz. -/ protected theorem restrict (hf : LipschitzWith K f) (s : Set α) : LipschitzWith K (s.restrict f) := fun x y => hf x y /-- The composition of Lipschitz functions is Lipschitz. -/ protected theorem comp {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f ∘ g) := fun x y => calc edist (f (g x)) (f (g y)) ≤ Kf * edist (g x) (g y) := hf _ _ _ ≤ Kf * (Kg * edist x y) := mul_left_mono (hg _ _) _ = (Kf * Kg : ℝ≥0) * edist x y := by rw [← mul_assoc, ENNReal.coe_mul] theorem comp_lipschitzOnWith {Kf Kg : ℝ≥0} {f : β → γ} {g : α → β} {s : Set α} (hf : LipschitzWith Kf f) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (Kf * Kg) (f ∘ g) s := lipschitzOnWith_iff_restrict.mpr <| hf.comp hg.to_restrict protected theorem prod_fst : LipschitzWith 1 (@Prod.fst α β) := LipschitzWith.of_edist_le fun _ _ => le_max_left _ _ protected theorem prod_snd : LipschitzWith 1 (@Prod.snd α β) := LipschitzWith.of_edist_le fun _ _ => le_max_right _ _ /-- If `f` and `g` are Lipschitz functions, so is the induced map `f × g` to the product type. -/ protected theorem prodMk {f : α → β} {Kf : ℝ≥0} (hf : LipschitzWith Kf f) {g : α → γ} {Kg : ℝ≥0} (hg : LipschitzWith Kg g) : LipschitzWith (max Kf Kg) fun x => (f x, g x) := by intro x y rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul] exact max_le_max (hf x y) (hg x y) @[deprecated (since := "2025-03-10")] protected alias prod := LipschitzWith.prodMk protected theorem prodMk_left (a : α) : LipschitzWith 1 (Prod.mk a : β → α × β) := by simpa only [max_eq_right zero_le_one] using (LipschitzWith.const a).prodMk LipschitzWith.id @[deprecated (since := "2025-03-10")] protected alias prod_mk_left := LipschitzWith.prodMk_left protected theorem prodMk_right (b : β) : LipschitzWith 1 fun a : α => (a, b) := by simpa only [max_eq_left zero_le_one] using LipschitzWith.id.prodMk (LipschitzWith.const b) @[deprecated (since := "2025-03-10")] protected alias prod_mk_right := LipschitzWith.prodMk_right protected theorem uncurry {f : α → β → γ} {Kα Kβ : ℝ≥0} (hα : ∀ b, LipschitzWith Kα fun a => f a b) (hβ : ∀ a, LipschitzWith Kβ (f a)) : LipschitzWith (Kα + Kβ) (Function.uncurry f) := by rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ simp only [Function.uncurry, ENNReal.coe_add, add_mul] apply le_trans (edist_triangle _ (f a₂ b₁) _) exact add_le_add (le_trans (hα _ _ _) <| mul_left_mono <| le_max_left _ _) (le_trans (hβ _ _ _) <| mul_left_mono <| le_max_right _ _) /-- Iterates of a Lipschitz function are Lipschitz. -/ protected theorem iterate {f : α → α} (hf : LipschitzWith K f) : ∀ n, LipschitzWith (K ^ n) f^[n] | 0 => by simpa only [pow_zero] using LipschitzWith.id | n + 1 => by rw [pow_succ]; exact (LipschitzWith.iterate hf n).comp hf theorem edist_iterate_succ_le_geometric {f : α → α} (hf : LipschitzWith K f) (x n) : edist (f^[n] x) (f^[n + 1] x) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n := by rw [iterate_succ, mul_comm] simpa only [ENNReal.coe_pow] using (hf.iterate n) x (f x) protected theorem mul_end {f g : Function.End α} {Kf Kg} (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) : LipschitzWith (Kf * Kg) (f * g : Function.End α) := hf.comp hg /-- The product of a list of Lipschitz continuous endomorphisms is a Lipschitz continuous endomorphism. -/ protected theorem list_prod (f : ι → Function.End α) (K : ι → ℝ≥0) (h : ∀ i, LipschitzWith (K i) (f i)) : ∀ l : List ι, LipschitzWith (l.map K).prod (l.map f).prod | [] => by simpa using LipschitzWith.id | i::l => by simp only [List.map_cons, List.prod_cons] exact (h i).mul_end (LipschitzWith.list_prod f K h l) protected theorem pow_end {f : Function.End α} {K} (h : LipschitzWith K f) : ∀ n : ℕ, LipschitzWith (K ^ n) (f ^ n : Function.End α) | 0 => by simpa only [pow_zero] using LipschitzWith.id | n + 1 => by rw [pow_succ, pow_succ] exact (LipschitzWith.pow_end h n).mul_end h end LipschitzWith namespace LipschitzOnWith variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {K : ℝ≥0} {s : Set α} {f : α → β} protected theorem uniformContinuousOn (hf : LipschitzOnWith K f s) : UniformContinuousOn f s := uniformContinuousOn_iff_restrict.mpr hf.to_restrict.uniformContinuous protected theorem continuousOn (hf : LipschitzOnWith K f s) : ContinuousOn f s := hf.uniformContinuousOn.continuousOn theorem edist_le_mul_of_le (h : LipschitzOnWith K f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) {r : ℝ≥0∞} (hr : edist x y ≤ r) : edist (f x) (f y) ≤ K * r := (h hx hy).trans <| mul_left_mono hr theorem edist_lt_of_edist_lt_div (hf : LipschitzOnWith K f s) {x y : α} (hx : x ∈ s) (hy : y ∈ s) {d : ℝ≥0∞} (hd : edist x y < d / K) : edist (f x) (f y) < d := hf.to_restrict.edist_lt_of_edist_lt_div <| show edist (⟨x, hx⟩ : s) ⟨y, hy⟩ < d / K from hd protected theorem comp {g : β → γ} {t : Set β} {Kg : ℝ≥0} (hg : LipschitzOnWith Kg g t) (hf : LipschitzOnWith K f s) (hmaps : MapsTo f s t) : LipschitzOnWith (Kg * K) (g ∘ f) s := lipschitzOnWith_iff_restrict.mpr <| hg.to_restrict.comp (hf.to_restrict_mapsTo hmaps) /-- If `f` and `g` are Lipschitz on `s`, so is the induced map `f × g` to the product type. -/ protected theorem prodMk {g : α → γ} {Kf Kg : ℝ≥0} (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) : LipschitzOnWith (max Kf Kg) (fun x => (f x, g x)) s := by intro _ hx _ hy rw [ENNReal.coe_mono.map_max, Prod.edist_eq, max_mul] exact max_le_max (hf hx hy) (hg hx hy) @[deprecated (since := "2025-03-10")] protected alias prod := LipschitzOnWith.prodMk
theorem ediam_image2_le (f : α → β → γ) {K₁ K₂ : ℝ≥0} (s : Set α) (t : Set β) (hf₁ : ∀ b ∈ t, LipschitzOnWith K₁ (f · b) s) (hf₂ : ∀ a ∈ s, LipschitzOnWith K₂ (f a) t) : EMetric.diam (Set.image2 f s t) ≤ ↑K₁ * EMetric.diam s + ↑K₂ * EMetric.diam t := by simp only [EMetric.diam_le_iff, forall_mem_image2] intro a₁ ha₁ b₁ hb₁ a₂ ha₂ b₂ hb₂
Mathlib/Topology/EMetricSpace/Lipschitz.lean
329
333
/- Copyright (c) 2024 Miyahara Kō. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Miyahara Kō -/ import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.List.Defs import Mathlib.Data.Set.Function /-! # iterate Proves various lemmas about `List.iterate`. -/ variable {α : Type*} namespace List @[simp] theorem length_iterate (f : α → α) (a : α) (n : ℕ) : length (iterate f a n) = n := by induction n generalizing a <;> simp [*] @[simp] theorem iterate_eq_nil {f : α → α} {a : α} {n : ℕ} : iterate f a n = [] ↔ n = 0 := by rw [← length_eq_zero_iff, length_iterate] theorem getElem?_iterate (f : α → α) (a : α) : ∀ (n i : ℕ), i < n → (iterate f a n)[i]? = f^[i] a | n + 1, 0 , _ => by simp | n + 1, i + 1, h => by simp [getElem?_iterate f (f a) n i (by simpa using h)] @[simp] theorem getElem_iterate (f : α → α) (a : α) (n : ℕ) (i : Nat) (h : i < (iterate f a n).length) : (iterate f a n)[i] = f^[i] a := (getElem_eq_iff _).2 <| getElem?_iterate _ _ _ _ <| by rwa [length_iterate] at h @[simp] theorem mem_iterate {f : α → α} {a : α} {n : ℕ} {b : α} : b ∈ iterate f a n ↔ ∃ m < n, b = f^[m] a := by simp [List.mem_iff_get, Fin.exists_iff, eq_comm (b := b)] @[simp] theorem range_map_iterate (n : ℕ) (f : α → α) (a : α) : (List.range n).map (f^[·] a) = List.iterate f a n := by apply List.ext_getElem <;> simp theorem iterate_add (f : α → α) (a : α) (m n : ℕ) : iterate f a (m + n) = iterate f a m ++ iterate f (f^[m] a) n := by induction m generalizing a with | zero => simp | succ n ih => rw [iterate, add_right_comm, iterate, ih, Nat.iterate, cons_append] theorem take_iterate (f : α → α) (a : α) (m n : ℕ) : take m (iterate f a n) = iterate f a (min m n) := by
rw [← range_map_iterate, ← range_map_iterate, ← map_take, take_range] end List
Mathlib/Data/List/Iterate.lean
56
60
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.Order.Antidiag.Finsupp import Mathlib.Data.Finsupp.Weight import Mathlib.Tactic.Linarith import Mathlib.LinearAlgebra.Pi import Mathlib.Algebra.MvPolynomial.Eval /-! # Formal (multivariate) power series This file defines multivariate formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. We provide the natural inclusion from multivariate polynomials to multivariate formal power series. ## Main definitions - `MvPowerSeries.C`: constant power series - `MvPowerSeries.X`: the indeterminates - `MvPowerSeries.coeff`, `MvPowerSeries.constantCoeff`: the coefficients of a `MvPowerSeries`, its constant coefficient - `MvPowerSeries.monomial`: the monomials - `MvPowerSeries.coeff_mul`: computes the coefficients of the product of two `MvPowerSeries` - `MvPowerSeries.coeff_prod` : computes the coefficients of products of `MvPowerSeries` - `MvPowerSeries.coeff_pow` : computes the coefficients of powers of a `MvPowerSeries` - `MvPowerSeries.coeff_eq_zero_of_constantCoeff_nilpotent`: if the constant coefficient of a `MvPowerSeries` is nilpotent, then some coefficients of its powers are automatically zero - `MvPowerSeries.map`: apply a `RingHom` to the coefficients of a `MvPowerSeries` (as a `RingHom) - `MvPowerSeries.X_pow_dvd_iff`, `MvPowerSeries.X_dvd_iff`: equivalent conditions for (a power of) an indeterminate to divide a `MvPowerSeries` - `MvPolynomial.toMvPowerSeries`: the canonical coercion from `MvPolynomial` to `MvPowerSeries` ## Note This file sets up the (semi)ring structure on multivariate power series: additional results are in: * `Mathlib.RingTheory.MvPowerSeries.Inverse` : invertibility, formal power series over a local ring form a local ring; * `Mathlib.RingTheory.MvPowerSeries.Trunc`: truncation of power series. In `Mathlib.RingTheory.PowerSeries.Basic`, formal power series in one variable will be obtained as a particular case, defined by `PowerSeries R := MvPowerSeries Unit R`. See that file for a specific description. ## Implementation notes In this file we define multivariate formal power series with variables indexed by `σ` and coefficients in `R` as `MvPowerSeries σ R := (σ →₀ ℕ) → R`. Unfortunately there is not yet enough API to show that they are the completion of the ring of multivariate polynomials. However, we provide most of the infrastructure that is needed to do this. Once I-adic completion (topological or algebraic) is available it should not be hard to fill in the details. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Multivariate formal power series, where `σ` is the index set of the variables and `R` is the coefficient ring. -/ def MvPowerSeries (σ : Type*) (R : Type*) := (σ →₀ ℕ) → R namespace MvPowerSeries open Finsupp variable {σ R : Type*} instance [Inhabited R] : Inhabited (MvPowerSeries σ R) := ⟨fun _ => default⟩ instance [Zero R] : Zero (MvPowerSeries σ R) := Pi.instZero instance [AddMonoid R] : AddMonoid (MvPowerSeries σ R) := Pi.addMonoid instance [AddGroup R] : AddGroup (MvPowerSeries σ R) := Pi.addGroup instance [AddCommMonoid R] : AddCommMonoid (MvPowerSeries σ R) := Pi.addCommMonoid instance [AddCommGroup R] : AddCommGroup (MvPowerSeries σ R) := Pi.addCommGroup instance [Nontrivial R] : Nontrivial (MvPowerSeries σ R) := Function.nontrivial instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R (MvPowerSeries σ A) := Pi.module _ _ _ instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S (MvPowerSeries σ A) := Pi.isScalarTower section Semiring variable (R) [Semiring R] /-- The `n`th monomial as multivariate formal power series: it is defined as the `R`-linear map from `R` to the semi-ring of multivariate formal power series associating to each `a` the map sending `n : σ →₀ ℕ` to the value `a` and sending all other `x : σ →₀ ℕ` different from `n` to `0`. -/ def monomial (n : σ →₀ ℕ) : R →ₗ[R] MvPowerSeries σ R := letI := Classical.decEq σ LinearMap.single R (fun _ ↦ R) n /-- The `n`th coefficient of a multivariate formal power series. -/
def coeff (n : σ →₀ ℕ) : MvPowerSeries σ R →ₗ[R] R := LinearMap.proj n theorem coeff_apply (f : MvPowerSeries σ R) (d : σ →₀ ℕ) : coeff R d f = f d := rfl
Mathlib/RingTheory/MvPowerSeries/Basic.lean
134
139
/- Copyright (c) 2020 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import Mathlib.RingTheory.AdicCompletion.Basic import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.LocalRing.RingHom.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.Basic import Mathlib.RingTheory.Valuation.PrimeMultiplicity import Mathlib.RingTheory.Valuation.ValuationRing /-! # Discrete valuation rings This file defines discrete valuation rings (DVRs) and develops a basic interface for them. ## Important definitions There are various definitions of a DVR in the literature; we define a DVR to be a local PID which is not a field (the first definition in Wikipedia) and prove that this is equivalent to being a PID with a unique non-zero prime ideal (the definition in Serre's book "Local Fields"). Let R be an integral domain, assumed to be a principal ideal ring and a local ring. * `IsDiscreteValuationRing R` : a predicate expressing that R is a DVR. ### Definitions * `addVal R : AddValuation R PartENat` : the additive valuation on a DVR. ## Implementation notes It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible. We do not hence define `Uniformizer` at all, because we can use `Irreducible` instead. ## Tags discrete valuation ring -/ universe u open Ideal IsLocalRing /-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which is not a field. -/ class IsDiscreteValuationRing (R : Type u) [CommRing R] [IsDomain R] : Prop extends IsPrincipalIdealRing R, IsLocalRing R where not_a_field' : maximalIdeal R ≠ ⊥ namespace IsDiscreteValuationRing variable (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] theorem not_a_field : maximalIdeal R ≠ ⊥ := not_a_field' /-- A discrete valuation ring `R` is not a field. -/ theorem not_isField : ¬IsField R := IsLocalRing.isField_iff_maximalIdeal_eq.not.mpr (not_a_field R) variable {R} open PrincipalIdealRing theorem irreducible_of_span_eq_maximalIdeal {R : Type*} [CommSemiring R] [IsLocalRing R] [IsDomain R] (ϖ : R) (hϖ : ϖ ≠ 0) (h : maximalIdeal R = Ideal.span {ϖ}) : Irreducible ϖ := by have h2 : ¬IsUnit ϖ := show ϖ ∈ maximalIdeal R from h.symm ▸ Submodule.mem_span_singleton_self ϖ refine ⟨h2, ?_⟩ intro a b hab by_contra! h obtain ⟨ha : a ∈ maximalIdeal R, hb : b ∈ maximalIdeal R⟩ := h rw [h, mem_span_singleton'] at ha hb rcases ha with ⟨a, rfl⟩ rcases hb with ⟨b, rfl⟩ rw [show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)) by ring] at hab apply hϖ apply eq_zero_of_mul_eq_self_right _ hab.symm exact fun hh => h2 (isUnit_of_dvd_one ⟨_, hh.symm⟩) /-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the maximal ideal of `R`. -/ theorem irreducible_iff_uniformizer (ϖ : R) : Irreducible ϖ ↔ maximalIdeal R = Ideal.span {ϖ} := ⟨fun hϖ => (eq_maximalIdeal (isMaximal_of_irreducible hϖ)).symm, fun h => irreducible_of_span_eq_maximalIdeal ϖ (fun e => not_a_field R <| by rwa [h, span_singleton_eq_bot]) h⟩ theorem _root_.Irreducible.maximalIdeal_eq {ϖ : R} (h : Irreducible ϖ) : maximalIdeal R = Ideal.span {ϖ} := (irreducible_iff_uniformizer _).mp h variable (R) /-- Uniformizers exist in a DVR. -/ theorem exists_irreducible : ∃ ϖ : R, Irreducible ϖ := by simp_rw [irreducible_iff_uniformizer] exact (IsPrincipalIdealRing.principal <| maximalIdeal R).principal /-- Uniformizers exist in a DVR. -/ theorem exists_prime : ∃ ϖ : R, Prime ϖ := (exists_irreducible R).imp fun _ => irreducible_iff_prime.1 /-- An integral domain is a DVR iff it's a PID with a unique non-zero prime ideal. -/ theorem iff_pid_with_one_nonzero_prime (R : Type u) [CommRing R] [IsDomain R] : IsDiscreteValuationRing R ↔ IsPrincipalIdealRing R ∧ ∃! P : Ideal R, P ≠ ⊥ ∧ IsPrime P := by constructor · intro RDVR rcases id RDVR with ⟨Rlocal⟩ constructor · assumption use IsLocalRing.maximalIdeal R constructor · exact ⟨Rlocal, inferInstance⟩ · rintro Q ⟨hQ1, hQ2⟩ obtain ⟨q, rfl⟩ := (IsPrincipalIdealRing.principal Q).1 have hq : q ≠ 0 := by rintro rfl apply hQ1 simp rw [submodule_span_eq, span_singleton_prime hq] at hQ2 replace hQ2 := hQ2.irreducible rw [irreducible_iff_uniformizer] at hQ2 exact hQ2.symm · rintro ⟨RPID, Punique⟩ haveI : IsLocalRing R := IsLocalRing.of_unique_nonzero_prime Punique refine { not_a_field' := ?_ } rcases Punique with ⟨P, ⟨hP1, hP2⟩, _⟩ have hPM : P ≤ maximalIdeal R := le_maximalIdeal hP2.1 intro h rw [h, le_bot_iff] at hPM exact hP1 hPM theorem associated_of_irreducible {a b : R} (ha : Irreducible a) (hb : Irreducible b) : Associated a b := by rw [irreducible_iff_uniformizer] at ha hb rw [← span_singleton_eq_span_singleton, ← ha, hb] variable (R : Type*) /-- Alternative characterisation of discrete valuation rings. -/ def HasUnitMulPowIrreducibleFactorization [CommRing R] : Prop := ∃ p : R, Irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ n : ℕ, Associated (p ^ n) x namespace HasUnitMulPowIrreducibleFactorization variable {R} [CommRing R] theorem unique_irreducible (hR : HasUnitMulPowIrreducibleFactorization R) ⦃p q : R⦄ (hp : Irreducible p) (hq : Irreducible q) : Associated p q := by rcases hR with ⟨ϖ, hϖ, hR⟩ suffices ∀ {p : R} (_ : Irreducible p), Associated p ϖ by apply Associated.trans (this hp) (this hq).symm clear hp hq p q intro p hp obtain ⟨n, hn⟩ := hR hp.ne_zero have : Irreducible (ϖ ^ n) := hn.symm.irreducible hp rcases lt_trichotomy n 1 with (H | rfl | H) · obtain rfl : n = 0 := by clear hn this revert H n decide simp [not_irreducible_one, pow_zero] at this · simpa only [pow_one] using hn.symm · obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := Nat.exists_eq_add_of_lt H rw [pow_succ'] at this rcases this.isUnit_or_isUnit rfl with (H0 | H0) · exact (hϖ.not_isUnit H0).elim · rw [add_comm, pow_succ'] at H0 exact (hϖ.not_isUnit (isUnit_of_mul_isUnit_left H0)).elim variable [IsDomain R] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a unique factorization domain. See `IsDiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization`. -/ theorem toUniqueFactorizationMonoid (hR : HasUnitMulPowIrreducibleFactorization R) : UniqueFactorizationMonoid R := let p := Classical.choose hR let spec := Classical.choose_spec hR UniqueFactorizationMonoid.of_exists_prime_factors fun x hx => by use Multiset.replicate (Classical.choose (spec.2 hx)) p constructor · intro q hq have hpq := Multiset.eq_of_mem_replicate hq rw [hpq] refine ⟨spec.1.ne_zero, spec.1.not_isUnit, ?_⟩ intro a b h by_cases ha : a = 0 · rw [ha] simp only [true_or, dvd_zero] obtain ⟨m, u, rfl⟩ := spec.2 ha rw [mul_assoc, mul_left_comm, Units.dvd_mul_left] at h rw [Units.dvd_mul_right] by_cases hm : m = 0 · simp only [hm, one_mul, pow_zero] at h ⊢ right exact h left obtain ⟨m, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hm rw [pow_succ'] apply dvd_mul_of_dvd_left dvd_rfl _ · rw [Multiset.prod_replicate] exact Classical.choose_spec (spec.2 hx) theorem of_ufd_of_unique_irreducible [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : HasUnitMulPowIrreducibleFactorization R := by obtain ⟨p, hp⟩ := h₁ refine ⟨p, hp, ?_⟩ intro x hx obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx refine ⟨Multiset.card fx, ?_⟩ have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 symm rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, eq_self_iff_true, Multiset.mem_map, exists_imp] rintro _ q hq rfl rw [Associates.mk_eq_mk_iff_associated] apply h₂ (hfx.1 _ hq) hp end HasUnitMulPowIrreducibleFactorization theorem aux_pid_of_ufd_of_unique_irreducible (R : Type u) [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsPrincipalIdealRing R := by classical constructor intro I by_cases I0 : I = ⊥ · rw [I0] use 0 simp only [Set.singleton_zero, Submodule.span_zero] obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0 : R) := I.ne_bot_iff.mp I0 obtain ⟨p, _, H⟩ := HasUnitMulPowIrreducibleFactorization.of_ufd_of_unique_irreducible h₁ h₂ have ex : ∃ n : ℕ, p ^ n ∈ I := by obtain ⟨n, u, rfl⟩ := H hx0 refine ⟨n, ?_⟩ simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hxI constructor use p ^ Nat.find ex show I = Ideal.span _ apply le_antisymm · intro r hr by_cases hr0 : r = 0 · simp only [hr0, Submodule.zero_mem] obtain ⟨n, u, rfl⟩ := H hr0 simp only [mem_span_singleton, Units.isUnit, IsUnit.dvd_mul_right] apply pow_dvd_pow apply Nat.find_min' simpa only [Units.mul_inv_cancel_right] using I.mul_mem_right (↑u⁻¹) hr · rw [span_singleton_le_iff_mem] exact Nat.find_spec ex /-- A unique factorization domain with at least one irreducible element in which all irreducible elements are associated is a discrete valuation ring. -/ theorem of_ufd_of_unique_irreducible {R : Type u} [CommRing R] [IsDomain R] [UniqueFactorizationMonoid R] (h₁ : ∃ p : R, Irreducible p) (h₂ : ∀ ⦃p q : R⦄, Irreducible p → Irreducible q → Associated p q) : IsDiscreteValuationRing R := by rw [iff_pid_with_one_nonzero_prime] haveI PID : IsPrincipalIdealRing R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂ obtain ⟨p, hp⟩ := h₁ refine ⟨PID, ⟨Ideal.span {p}, ⟨?_, ?_⟩, ?_⟩⟩ · rw [Submodule.ne_bot_iff] exact ⟨p, Ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩ · rwa [Ideal.span_singleton_prime hp.ne_zero, ← UniqueFactorizationMonoid.irreducible_iff_prime] · intro I rw [← Submodule.IsPrincipal.span_singleton_generator I] rintro ⟨I0, hI⟩ apply span_singleton_eq_span_singleton.mpr apply h₂ _ hp rw [Ne, Submodule.span_singleton_eq_bot] at I0 rwa [UniqueFactorizationMonoid.irreducible_iff_prime, ← Ideal.span_singleton_prime I0] /-- An integral domain in which there is an irreducible element `p` such that every nonzero element is associated to a power of `p` is a discrete valuation ring. -/ theorem ofHasUnitMulPowIrreducibleFactorization {R : Type u} [CommRing R] [IsDomain R] (hR : HasUnitMulPowIrreducibleFactorization R) : IsDiscreteValuationRing R := by letI : UniqueFactorizationMonoid R := hR.toUniqueFactorizationMonoid apply of_ufd_of_unique_irreducible _ hR.unique_irreducible obtain ⟨p, hp, H⟩ := hR exact ⟨p, hp⟩ /- If a ring is equivalent to a DVR, it is itself a DVR. -/ theorem RingEquivClass.isDiscreteValuationRing {A B E : Type*} [CommRing A] [IsDomain A] [CommRing B] [IsDomain B] [IsDiscreteValuationRing A] [EquivLike E A B] [RingEquivClass E A B] (e : E) : IsDiscreteValuationRing B where principal := (isPrincipalIdealRing_iff _).1 <| IsPrincipalIdealRing.of_surjective _ (e : A ≃+* B).surjective __ : IsLocalRing B := (e : A ≃+* B).isLocalRing not_a_field' := by obtain ⟨a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr <| IsDiscreteValuationRing.not_a_field A) rw [Submodule.ne_bot_iff] refine ⟨e a, ⟨?_, by simp only [ne_eq, EmbeddingLike.map_eq_zero_iff, ZeroMemClass.coe_eq_zero, ha, not_false_eq_true]⟩⟩ rw [IsLocalRing.mem_maximalIdeal, map_mem_nonunits_iff e, ← IsLocalRing.mem_maximalIdeal] exact a.2 section variable [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] variable {R} theorem associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, Associated x (ϖ ^ n) := by have : WfDvdMonoid R := IsNoetherianRing.wfDvdMonoid obtain ⟨fx, hfx⟩ := WfDvdMonoid.exists_factors x hx use Multiset.card fx have H := hfx.2 rw [← Associates.mk_eq_mk_iff_associated] at H ⊢ rw [← H, ← Associates.prod_mk, Associates.mk_pow, ← Multiset.prod_replicate] congr 1 rw [Multiset.eq_replicate] simp only [true_and, and_imp, Multiset.card_map, eq_self_iff_true, Multiset.mem_map, exists_imp] rintro _ _ _ rfl rw [Associates.mk_eq_mk_iff_associated] refine associated_of_irreducible _ ?_ hirr apply hfx.1 assumption theorem eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : Irreducible ϖ) : ∃ (n : ℕ) (u : Rˣ), x = u * ϖ ^ n := by obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr obtain ⟨u, rfl⟩ := hn.symm use n, u apply mul_comm open Submodule.IsPrincipal theorem ideal_eq_span_pow_irreducible {s : Ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : Irreducible ϖ) : ∃ n : ℕ, s = Ideal.span {ϖ ^ n} := by have gen_ne_zero : generator s ≠ 0 := by rw [Ne, ← eq_bot_iff_generator_eq_zero] assumption rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩ use n have : span _ = _ := Ideal.span_singleton_generator s rw [← this, ← hnu, span_singleton_eq_span_singleton] use u theorem unit_mul_pow_congr_pow {p q : R} (hp : Irreducible p) (hq : Irreducible q) (u v : Rˣ) (m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) : m = n := by have key : Associated (Multiset.replicate m p).prod (Multiset.replicate n q).prod := by rw [Multiset.prod_replicate, Multiset.prod_replicate, Associated] refine ⟨u * v⁻¹, ?_⟩ simp only [Units.val_mul] rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, Units.mul_inv, one_mul] have := by refine Multiset.card_eq_card_of_rel (UniqueFactorizationMonoid.factors_unique ?_ ?_ key) all_goals intro x hx obtain rfl := Multiset.eq_of_mem_replicate hx assumption simpa only [Multiset.card_replicate] theorem unit_mul_pow_congr_unit {ϖ : R} (hirr : Irreducible ϖ) (u v : Rˣ) (m n : ℕ) (h : ↑u * ϖ ^ m = v * ϖ ^ n) : u = v := by obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h rw [← sub_eq_zero] at h rw [← sub_mul, mul_eq_zero] at h rcases h with h | h · rw [sub_eq_zero] at h exact mod_cast h · apply (hirr.ne_zero (pow_eq_zero h)).elim /-! ## The additive valuation on a DVR -/ open Classical in /-- The `ℕ∞`-valued additive valuation on a DVR. -/ noncomputable def addVal (R : Type u) [CommRing R] [IsDomain R] [IsDiscreteValuationRing R] : AddValuation R ℕ∞ := multiplicity_addValuation (Classical.choose_spec (exists_prime R)) theorem addVal_def (r : R) (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) (hr : r = u * ϖ ^ n) : addVal R r = n := by classical rw [addVal, multiplicity_addValuation_apply, hr, emultiplicity_eq_of_associated_left (associated_of_irreducible R hϖ (Classical.choose_spec (exists_prime R)).irreducible), emultiplicity_eq_of_associated_right (Associated.symm ⟨u, mul_comm _ _⟩), emultiplicity_pow_self_of_prime (irreducible_iff_prime.1 hϖ)] /-- An alternative definition of the additive valuation, taking units into account -/ theorem addVal_def' (u : Rˣ) {ϖ : R} (hϖ : Irreducible ϖ) (n : ℕ) : addVal R ((u : R) * ϖ ^ n) = n := addVal_def _ u hϖ n rfl
theorem addVal_zero : addVal R 0 = ⊤ := (addVal R).map_zero theorem addVal_one : addVal R 1 = 0 := (addVal R).map_one
Mathlib/RingTheory/DiscreteValuationRing/Basic.lean
402
407
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Andrew Yang -/ import Mathlib.AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf import Mathlib.AlgebraicGeometry.GammaSpecAdjunction import Mathlib.RingTheory.GradedAlgebra.Radical /-! # Proj as a scheme This file is to prove that `Proj` is a scheme. ## Notation * `Proj` : `Proj` as a locally ringed space * `Proj.T` : the underlying topological space of `Proj` * `Proj| U` : `Proj` restricted to some open set `U` * `Proj.T| U` : the underlying topological space of `Proj` restricted to open set `U` * `pbo f` : basic open set at `f` in `Proj` * `Spec` : `Spec` as a locally ringed space * `Spec.T` : the underlying topological space of `Spec` * `sbo g` : basic open set at `g` in `Spec` * `A⁰_x` : the degree zero part of localized ring `Aₓ` ## Implementation In `AlgebraicGeometry/ProjectiveSpectrum/StructureSheaf.lean`, we have given `Proj` a structure sheaf so that `Proj` is a locally ringed space. In this file we will prove that `Proj` equipped with this structure sheaf is a scheme. We achieve this by using an affine cover by basic open sets in `Proj`, more specifically: 1. We prove that `Proj` can be covered by basic open sets at homogeneous element of positive degree. 2. We prove that for any homogeneous element `f : A` of positive degree `m`, `Proj.T | (pbo f)` is homeomorphic to `Spec.T A⁰_f`: - forward direction `toSpec`: for any `x : pbo f`, i.e. a relevant homogeneous prime ideal `x`, send it to `A⁰_f ∩ span {g / 1 | g ∈ x}` (see `ProjIsoSpecTopComponent.IoSpec.carrier`). This ideal is prime, the proof is in `ProjIsoSpecTopComponent.ToSpec.toFun`. The fact that this function is continuous is found in `ProjIsoSpecTopComponent.toSpec` - backward direction `fromSpec`: for any `q : Spec A⁰_f`, we send it to `{a | ∀ i, aᵢᵐ/fⁱ ∈ q}`; we need this to be a homogeneous prime ideal that is relevant. * This is in fact an ideal, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal`; * This ideal is also homogeneous, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal.homogeneous`; * This ideal is relevant, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.relevant`; * This ideal is prime, the proof can be found in `ProjIsoSpecTopComponent.FromSpec.carrier.asIdeal.prime`. Hence we have a well defined function `Spec.T A⁰_f → Proj.T | (pbo f)`, this function is called `ProjIsoSpecTopComponent.FromSpec.toFun`. But to prove the continuity of this function, we need to prove `fromSpec ∘ toSpec` and `toSpec ∘ fromSpec` are both identities; these are achieved in `ProjIsoSpecTopComponent.fromSpec_toSpec` and `ProjIsoSpecTopComponent.toSpec_fromSpec`. 3. Then we construct a morphism of locally ringed spaces `α : Proj| (pbo f) ⟶ Spec.T A⁰_f` as the following: by the Gamma-Spec adjunction, it is sufficient to construct a ring map `A⁰_f → Γ(Proj, pbo f)` from the ring of homogeneous localization of `A` away from `f` to the local sections of structure sheaf of projective spectrum on the basic open set around `f`. The map `A⁰_f → Γ(Proj, pbo f)` is constructed in `awayToΓ` and is defined by sending `s ∈ A⁰_f` to the section `x ↦ s` on `pbo f`. ## Main Definitions and Statements For a homogeneous element `f` of degree `m` * `ProjIsoSpecTopComponent.toSpec`: the continuous map between `Proj.T| pbo f` and `Spec.T A⁰_f` defined by sending `x : Proj| (pbo f)` to `A⁰_f ∩ span {g / 1 | g ∈ x}`. We also denote this map as `ψ`. * `ProjIsoSpecTopComponent.ToSpec.preimage_eq`: for any `a: A`, if `a/f^m` has degree zero, then the preimage of `sbo a/f^m` under `toSpec f` is `pbo f ∩ pbo a`. If we further assume `m` is positive * `ProjIsoSpecTopComponent.fromSpec`: the continuous map between `Spec.T A⁰_f` and `Proj.T| pbo f` defined by sending `q` to `{a | aᵢᵐ/fⁱ ∈ q}` where `aᵢ` is the `i`-th coordinate of `a`. We also denote this map as `φ` * `projIsoSpecTopComponent`: the homeomorphism `Proj.T| pbo f ≅ Spec.T A⁰_f` obtained by `φ` and `ψ`. * `ProjectiveSpectrum.Proj.toSpec`: the morphism of locally ringed spaces between `Proj| pbo f` and `Spec A⁰_f` corresponding to the ring map `A⁰_f → Γ(Proj, pbo f)` under the Gamma-Spec adjunction defined by sending `s` to the section `x ↦ s` on `pbo f`. Finally, * `AlgebraicGeometry.Proj`: for any `ℕ`-graded ring `A`, `Proj A` is locally affine, hence is a scheme. ## Reference * [Robin Hartshorne, *Algebraic Geometry*][Har77]: Chapter II.2 Proposition 2.5 -/ noncomputable section namespace AlgebraicGeometry open scoped DirectSum Pointwise open DirectSum SetLike.GradedMonoid Localization open Finset hiding mk_zero variable {R A : Type*} variable [CommRing R] [CommRing A] [Algebra R A] variable (𝒜 : ℕ → Submodule R A) variable [GradedAlgebra 𝒜] open TopCat TopologicalSpace open CategoryTheory Opposite open ProjectiveSpectrum.StructureSheaf -- Porting note: currently require lack of hygiene to use in variable declarations -- maybe all make into notation3? set_option hygiene false /-- `Proj` as a locally ringed space -/ local notation3 "Proj" => Proj.toLocallyRingedSpace 𝒜 /-- The underlying topological space of `Proj` -/ local notation3 "Proj.T" => PresheafedSpace.carrier <| SheafedSpace.toPresheafedSpace <| LocallyRingedSpace.toSheafedSpace <| Proj.toLocallyRingedSpace 𝒜 /-- `Proj` restrict to some open set -/ macro "Proj| " U:term : term => `((Proj.toLocallyRingedSpace 𝒜).restrict (Opens.isOpenEmbedding (X := Proj.T) ($U : Opens Proj.T))) /-- the underlying topological space of `Proj` restricted to some open set -/ local notation "Proj.T| " U => PresheafedSpace.carrier <| SheafedSpace.toPresheafedSpace <| LocallyRingedSpace.toSheafedSpace <| (LocallyRingedSpace.restrict Proj (Opens.isOpenEmbedding (X := Proj.T) (U : Opens Proj.T))) /-- basic open sets in `Proj` -/ local notation "pbo " x => ProjectiveSpectrum.basicOpen 𝒜 x /-- basic open sets in `Spec` -/ local notation "sbo " f => PrimeSpectrum.basicOpen f /-- `Spec` as a locally ringed space -/ local notation3 "Spec " ring => Spec.locallyRingedSpaceObj (CommRingCat.of ring) /-- the underlying topological space of `Spec` -/ local notation "Spec.T " ring => (Spec.locallyRingedSpaceObj (CommRingCat.of ring)).toSheafedSpace.toPresheafedSpace.1 local notation3 "A⁰_ " f => HomogeneousLocalization.Away 𝒜 f namespace ProjIsoSpecTopComponent /- This section is to construct the homeomorphism between `Proj` restricted at basic open set at a homogeneous element `x` and `Spec A⁰ₓ` where `A⁰ₓ` is the degree zero part of the localized ring `Aₓ`. -/ namespace ToSpec open Ideal -- This section is to construct the forward direction : -- So for any `x` in `Proj| (pbo f)`, we need some point in `Spec A⁰_f`, i.e. a prime ideal, -- and we need this correspondence to be continuous in their Zariski topology. variable {𝒜} variable {f : A} {m : ℕ} (x : Proj| (pbo f)) /-- For any `x` in `Proj| (pbo f)`, the corresponding ideal in `Spec A⁰_f`. This fact that this ideal is prime is proven in `TopComponent.Forward.toFun`. -/ def carrier : Ideal (A⁰_ f) := Ideal.comap (algebraMap (A⁰_ f) (Away f)) (x.val.asHomogeneousIdeal.toIdeal.map (algebraMap A (Away f))) @[simp] theorem mk_mem_carrier (z : HomogeneousLocalization.NumDenSameDeg 𝒜 (.powers f)) : HomogeneousLocalization.mk z ∈ carrier x ↔ z.num.1 ∈ x.1.asHomogeneousIdeal := by rw [carrier, Ideal.mem_comap, HomogeneousLocalization.algebraMap_apply, HomogeneousLocalization.val_mk, Localization.mk_eq_mk', IsLocalization.mk'_eq_mul_mk'_one, mul_comm, Ideal.unit_mul_mem_iff_mem, ← Ideal.mem_comap, IsLocalization.comap_map_of_isPrime_disjoint (.powers f)] · rfl · infer_instance · exact (disjoint_powers_iff_not_mem _ (Ideal.IsPrime.isRadical inferInstance)).mpr x.2 · exact isUnit_of_invertible _ theorem isPrime_carrier : Ideal.IsPrime (carrier x) := by refine Ideal.IsPrime.comap _ (hK := ?_) exact IsLocalization.isPrime_of_isPrime_disjoint (Submonoid.powers f) _ _ inferInstance ((disjoint_powers_iff_not_mem _ (Ideal.IsPrime.isRadical inferInstance)).mpr x.2) variable (f) /-- The function between the basic open set `D(f)` in `Proj` to the corresponding basic open set in `Spec A⁰_f`. This is bundled into a continuous map in `TopComponent.forward`. -/ @[simps -isSimp] def toFun (x : Proj.T| pbo f) : Spec.T A⁰_ f := ⟨carrier x, isPrime_carrier x⟩ /- The preimage of basic open set `D(a/f^n)` in `Spec A⁰_f` under the forward map from `Proj A` to `Spec A⁰_f` is the basic open set `D(a) ∩ D(f)` in `Proj A`. This lemma is used to prove that the forward map is continuous. -/ theorem preimage_basicOpen (z : HomogeneousLocalization.NumDenSameDeg 𝒜 (.powers f)) : toFun f ⁻¹' (sbo (HomogeneousLocalization.mk z) : Set (PrimeSpectrum (A⁰_ f))) = Subtype.val ⁻¹' (pbo z.num.1 : Set (ProjectiveSpectrum 𝒜)) := Set.ext fun y ↦ (mk_mem_carrier y z).not end ToSpec section /-- The continuous function from the basic open set `D(f)` in `Proj` to the corresponding basic open set in `Spec A⁰_f`. -/ @[simps! -isSimp hom_apply_asIdeal] def toSpec (f : A) : (Proj.T| pbo f) ⟶ Spec.T A⁰_ f := TopCat.ofHom { toFun := ToSpec.toFun f continuous_toFun := by rw [PrimeSpectrum.isTopologicalBasis_basic_opens.continuous_iff] rintro _ ⟨x, rfl⟩ obtain ⟨x, rfl⟩ := Quotient.mk''_surjective x rw [ToSpec.preimage_basicOpen] exact (pbo x.num).2.preimage continuous_subtype_val } variable {𝒜} in lemma toSpec_preimage_basicOpen {f} (z : HomogeneousLocalization.NumDenSameDeg 𝒜 (.powers f)) : toSpec 𝒜 f ⁻¹' (sbo (HomogeneousLocalization.mk z) : Set (PrimeSpectrum (A⁰_ f))) = Subtype.val ⁻¹' (pbo z.num.1 : Set (ProjectiveSpectrum 𝒜)) := ToSpec.preimage_basicOpen f z end namespace FromSpec open GradedAlgebra SetLike open Finset hiding mk_zero open HomogeneousLocalization variable {𝒜} variable {f : A} {m : ℕ} (f_deg : f ∈ 𝒜 m) open Lean Meta Elab Tactic macro "mem_tac_aux" : tactic => `(tactic| first | exact pow_mem_graded _ (Submodule.coe_mem _) | exact natCast_mem_graded _ _ | exact pow_mem_graded _ f_deg) macro "mem_tac" : tactic => `(tactic| first | mem_tac_aux | repeat (all_goals (apply SetLike.GradedMonoid.toGradedMul.mul_mem)); mem_tac_aux) /-- The function from `Spec A⁰_f` to `Proj|D(f)` is defined by `q ↦ {a | aᵢᵐ/fⁱ ∈ q}`, i.e. sending `q` a prime ideal in `A⁰_f` to the homogeneous prime relevant ideal containing only and all the elements `a : A` such that for every `i`, the degree 0 element formed by dividing the `m`-th power of the `i`-th projection of `a` by the `i`-th power of the degree-`m` homogeneous element `f`, lies in `q`. The set `{a | aᵢᵐ/fⁱ ∈ q}` * is an ideal, as proved in `carrier.asIdeal`; * is homogeneous, as proved in `carrier.asHomogeneousIdeal`; * is prime, as proved in `carrier.asIdeal.prime`; * is relevant, as proved in `carrier.relevant`. -/ def carrier (f_deg : f ∈ 𝒜 m) (q : Spec.T A⁰_ f) : Set A := {a | ∀ i, (HomogeneousLocalization.mk ⟨m * i, ⟨proj 𝒜 i a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨f ^ i, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.1} theorem mem_carrier_iff (q : Spec.T A⁰_ f) (a : A) : a ∈ carrier f_deg q ↔ ∀ i, (HomogeneousLocalization.mk ⟨m * i, ⟨proj 𝒜 i a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨f ^ i, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.1 := Iff.rfl theorem mem_carrier_iff' (q : Spec.T A⁰_ f) (a : A) : a ∈ carrier f_deg q ↔ ∀ i, (Localization.mk (proj 𝒜 i a ^ m) ⟨f ^ i, ⟨i, rfl⟩⟩ : Localization.Away f) ∈ algebraMap (HomogeneousLocalization.Away 𝒜 f) (Localization.Away f) '' { s | s ∈ q.1 } := (mem_carrier_iff f_deg q a).trans (by constructor <;> intro h i <;> specialize h i · rw [Set.mem_image]; refine ⟨_, h, rfl⟩ · rw [Set.mem_image] at h; rcases h with ⟨x, h, hx⟩ change x ∈ q.asIdeal at h convert h rw [HomogeneousLocalization.ext_iff_val, HomogeneousLocalization.val_mk] dsimp only [Subtype.coe_mk]; rw [← hx]; rfl) theorem mem_carrier_iff_of_mem (hm : 0 < m) (q : Spec.T A⁰_ f) (a : A) {n} (hn : a ∈ 𝒜 n) : a ∈ carrier f_deg q ↔ (HomogeneousLocalization.mk ⟨m * n, ⟨a ^ m, pow_mem_graded m hn⟩, ⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal := by trans (HomogeneousLocalization.mk ⟨m * n, ⟨proj 𝒜 n a ^ m, by rw [← smul_eq_mul]; mem_tac⟩, ⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal · refine ⟨fun h ↦ h n, fun h i ↦ if hi : i = n then hi ▸ h else ?_⟩ convert zero_mem q.asIdeal apply HomogeneousLocalization.val_injective
simp only [proj_apply, decompose_of_mem_ne _ hn (Ne.symm hi), zero_pow hm.ne', HomogeneousLocalization.val_mk, Localization.mk_zero, HomogeneousLocalization.val_zero] · simp only [proj_apply, decompose_of_mem_same _ hn] theorem mem_carrier_iff_of_mem_mul (hm : 0 < m) (q : Spec.T A⁰_ f) (a : A) {n} (hn : a ∈ 𝒜 (n * m)) : a ∈ carrier f_deg q ↔ (HomogeneousLocalization.mk ⟨m * n, ⟨a, mul_comm n m ▸ hn⟩, ⟨f ^ n, by rw [mul_comm]; mem_tac⟩, ⟨_, rfl⟩⟩ : A⁰_ f) ∈ q.asIdeal := by rw [mem_carrier_iff_of_mem f_deg hm q a hn, iff_iff_eq, eq_comm, ← Ideal.IsPrime.pow_mem_iff_mem (α := A⁰_ f) inferInstance m hm] congr 1 apply HomogeneousLocalization.val_injective
Mathlib/AlgebraicGeometry/ProjectiveSpectrum/Scheme.lean
300
311
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Anne Baanen -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.Data.Matrix.RowCol import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.GroupTheory.Perm.Fin import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Matrix.SemiringInverse /-! # Determinant of a matrix This file defines the determinant of a matrix, `Matrix.det`, and its essential properties. ## Main definitions - `Matrix.det`: the determinant of a square matrix, as a sum over permutations - `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A * B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `MathlibTest/matrix.lean` for some examples. -/ universe u v w z open Equiv Equiv.Perm Finset Function namespace Matrix variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] variable {R : Type v} [CommRing R] local notation "ε " σ:arg => ((sign σ : ℤ) : R) /-- `det` is an `AlternatingMap` in the rows of the matrix. -/ def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R := MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj) /-- The determinant of a matrix given by the Leibniz formula. -/ abbrev det (M : Matrix n n R) : R := detRowAlternating M theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i := MultilinearMap.alternatization_apply _ M -- This is what the old definition was. We use it to avoid having to change the old proofs below theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by simp [det_apply, Units.smul_def] theorem det_eq_detp_sub_detp (M : Matrix n n R) : M.det = M.detp 1 - M.detp (-1) := by rw [det_apply, ← Equiv.sum_comp (Equiv.inv (Perm n)), ← ofSign_disjUnion, sum_disjUnion] simp_rw [inv_apply, sign_inv, sub_eq_add_neg, detp, ← sum_neg_distrib] refine congr_arg₂ (· + ·) (sum_congr rfl fun σ hσ ↦ ?_) (sum_congr rfl fun σ hσ ↦ ?_) <;> rw [mem_ofSign.mp hσ, ← Equiv.prod_comp σ] <;> simp @[simp] theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by rw [det_apply'] refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_ · rintro σ - h2 obtain ⟨x, h3⟩ := not_forall.1 (mt Equiv.ext h2) convert mul_zero (ε σ) apply Finset.prod_eq_zero (mem_univ x) exact if_neg h3 · simp · simp theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero @[simp] theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply] @[simp] theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by ext exact det_isEmpty theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 := haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h det_isEmpty /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `Unique` implies `DecidableEq` and `Fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) : det A = A default default := by simp [det_apply, univ_unique] theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k := by have := uniqueOfSubsingleton k convert det_unique A theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) : det A = A k k := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le det_eq_elem_of_subsingleton _ _ theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) : (∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ @[simp] theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N := calc det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] rw [Finset.sum_comm] _ = ∑ p : n → n with Bijective p, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by refine (sum_subset (filter_subset _ _) fun f _ hbij ↦ det_mul_aux ?_).symm simpa only [true_and, mem_filter, mem_univ] using hbij _ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i := sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _) (fun _ _ _ _ h ↦ by injection h) (fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i := (sum_congr rfl fun σ _ => Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] simp_rw [Equiv.coe_mulRight, h] simp only [this]) _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] /-- The determinant of a matrix, as a monoid homomorphism. -/ def detMonoidHom : Matrix n n R →* R where toFun := det map_one' := det_one map_mul' := det_mul @[simp] theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det := rfl /-- On square matrices, `mul_comm` applies under `det`. -/ theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- On square matrices, `mul_left_comm` applies under `det`. -/ theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul] /-- On square matrices, `mul_right_comm` applies under `det`. -/ theorem det_mul_right_comm (M N P : Matrix m m R) : det (M * N * P) = det (M * P * N) := by rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M.val * N * M⁻¹.val) = det N := by rw [det_mul_right_comm, Units.mul_inv, one_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj' (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M⁻¹.val * N * ↑M.val) = det N := det_units_conj M⁻¹ N /-- Transposing a matrix preserves the determinant. -/ @[simp] theorem det_transpose (M : Matrix n n R) : Mᵀ.det = M.det := by rw [det_apply', det_apply'] refine Fintype.sum_bijective _ inv_involutive.bijective _ _ ?_ intro σ rw [sign_inv] congr 1 apply Fintype.prod_equiv σ simp /-- Permuting the columns changes the sign of the determinant. -/ theorem det_permute (σ : Perm n) (M : Matrix n n R) : (M.submatrix σ id).det = Perm.sign σ * M.det := ((detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_perm M σ).trans (by simp [Units.smul_def]) /-- Permuting the rows changes the sign of the determinant. -/ theorem det_permute' (σ : Perm n) (M : Matrix n n R) : (M.submatrix id σ).det = Perm.sign σ * M.det := by rw [← det_transpose, transpose_submatrix, det_permute, det_transpose] /-- Permuting rows and columns with the same equivalence does not change the determinant. -/ @[simp] theorem det_submatrix_equiv_self (e : n ≃ m) (A : Matrix m m R) : det (A.submatrix e e) = det A := by rw [det_apply', det_apply'] apply Fintype.sum_equiv (Equiv.permCongr e) intro σ rw [Equiv.Perm.sign_permCongr e σ] congr 1 apply Fintype.prod_equiv e intro i rw [Equiv.permCongr_apply, Equiv.symm_apply_apply, submatrix_apply] /-- Permuting rows and columns with two equivalences does not change the absolute value of the determinant. -/ @[simp] theorem abs_det_submatrix_equiv_equiv {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (e₁ e₂ : n ≃ m) (A : Matrix m m R) : |(A.submatrix e₁ e₂).det| = |A.det| := by have hee : e₂ = e₁.trans (e₁.symm.trans e₂) := by ext; simp rw [hee] show |((A.submatrix id (e₁.symm.trans e₂)).submatrix e₁ e₁).det| = |A.det| rw [Matrix.det_submatrix_equiv_self, Matrix.det_permute', abs_mul, abs_unit_intCast, one_mul] /-- Reindexing both indices along the same equivalence preserves the determinant. For the `simp` version of this lemma, see `det_submatrix_equiv_self`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem det_reindex_self (e : m ≃ n) (A : Matrix m m R) : det (reindex e e A) = det A := det_submatrix_equiv_self e.symm A /-- Reindexing both indices along equivalences preserves the absolute of the determinant. For the `simp` version of this lemma, see `abs_det_submatrix_equiv_equiv`; this one is unsuitable because `Matrix.reindex_apply` unfolds `reindex` first. -/ theorem abs_det_reindex {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (e₁ e₂ : m ≃ n) (A : Matrix m m R) : |det (reindex e₁ e₂ A)| = |det A| := abs_det_submatrix_equiv_equiv e₁.symm e₂.symm A theorem det_smul (A : Matrix n n R) (c : R) : det (c • A) = c ^ Fintype.card n * det A := calc det (c • A) = det ((diagonal fun _ => c) * A) := by rw [smul_eq_diagonal_mul] _ = det (diagonal fun _ => c) * det A := det_mul _ _ _ = c ^ Fintype.card n * det A := by simp @[simp] theorem det_smul_of_tower {α} [Monoid α] [MulAction α R] [IsScalarTower α R R] [SMulCommClass α R R] (c : α) (A : Matrix n n R) : det (c • A) = c ^ Fintype.card n • det A := by rw [← smul_one_smul R c A, det_smul, smul_pow, one_pow, smul_mul_assoc, one_mul] theorem det_neg (A : Matrix n n R) : det (-A) = (-1) ^ Fintype.card n * det A := by rw [← det_smul, neg_one_smul] /-- A variant of `Matrix.det_neg` with scalar multiplication by `Units ℤ` instead of multiplication by `R`. -/ theorem det_neg_eq_smul (A : Matrix n n R) : det (-A) = (-1 : Units ℤ) ^ Fintype.card n • det A := by rw [← det_smul_of_tower, Units.neg_smul, one_smul] /-- Multiplying each row by a fixed `v i` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_row (v : n → R) (A : Matrix n n R) : det (of fun i j => v j * A i j) = (∏ i, v i) * det A := calc det (of fun i j => v j * A i j) = det (A * diagonal v) := congr_arg det <| by ext simp [mul_comm] _ = (∏ i, v i) * det A := by rw [det_mul, det_diagonal, mul_comm] /-- Multiplying each column by a fixed `v j` multiplies the determinant by the product of the `v`s. -/ theorem det_mul_column (v : n → R) (A : Matrix n n R) : det (of fun i j => v i * A i j) = (∏ i, v i) * det A := MultilinearMap.map_smul_univ _ v A @[simp] theorem det_pow (M : Matrix m m R) (n : ℕ) : det (M ^ n) = det M ^ n := (detMonoidHom : Matrix m m R →* R).map_pow M n section HomMap variable {S : Type w} [CommRing S] theorem _root_.RingHom.map_det (f : R →+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := by simp [Matrix.det_apply', map_sum f, map_prod f] theorem _root_.RingEquiv.map_det (f : R ≃+* S) (M : Matrix n n R) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ theorem _root_.AlgHom.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S →ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toRingHom.map_det _ theorem _root_.AlgEquiv.map_det [Algebra R S] {T : Type z} [CommRing T] [Algebra R T] (f : S ≃ₐ[R] T) (M : Matrix n n S) : f M.det = Matrix.det (f.mapMatrix M) := f.toAlgHom.map_det _ @[norm_cast] theorem _root_.Int.cast_det (M : Matrix n n ℤ) : (M.det : R) = (M.map fun x ↦ (x : R)).det := Int.castRingHom R |>.map_det M @[norm_cast] theorem _root_.Rat.cast_det {F : Type*} [Field F] [CharZero F] (M : Matrix n n ℚ) : (M.det : F) = (M.map fun x ↦ (x : F)).det := Rat.castHom F |>.map_det M end HomMap @[simp] theorem det_conjTranspose [StarRing R] (M : Matrix m m R) : det Mᴴ = star (det M) := ((starRingEnd R).map_det _).symm.trans <| congr_arg star M.det_transpose section DetZero /-! ### `det_zero` section Prove that a matrix with a repeated column has determinant equal to zero. -/ theorem det_eq_zero_of_row_eq_zero {A : Matrix n n R} (i : n) (h : ∀ j, A i j = 0) : det A = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_coord_zero i (funext h) theorem det_eq_zero_of_column_eq_zero {A : Matrix n n R} (j : n) (h : ∀ i, A i j = 0) : det A = 0 := by rw [← det_transpose] exact det_eq_zero_of_row_eq_zero j h variable {M : Matrix n n R} {i j : n} /-- If a matrix has a repeated row, the determinant will be zero. -/ theorem det_zero_of_row_eq (i_ne_j : i ≠ j) (hij : M i = M j) : M.det = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_eq_zero_of_eq M hij i_ne_j /-- If a matrix has a repeated column, the determinant will be zero. -/ theorem det_zero_of_column_eq (i_ne_j : i ≠ j) (hij : ∀ k, M k i = M k j) : M.det = 0 := by rw [← det_transpose, det_zero_of_row_eq i_ne_j] exact funext hij /-- If we repeat a row of a matrix, we get a matrix of determinant zero. -/ theorem det_updateRow_eq_zero (h : i ≠ j) : (M.updateRow j (M i)).det = 0 := det_zero_of_row_eq h (by simp [h]) /-- If we repeat a column of a matrix, we get a matrix of determinant zero. -/ theorem det_updateCol_eq_zero (h : i ≠ j) : (M.updateCol j (fun k ↦ M k i)).det = 0 := det_zero_of_column_eq h (by simp [h]) @[deprecated (since := "2024-12-11")] alias det_updateColumn_eq_zero := det_updateCol_eq_zero end DetZero theorem det_updateRow_add (M : Matrix n n R) (j : n) (u v : n → R) : det (updateRow M j <| u + v) = det (updateRow M j u) + det (updateRow M j v) := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_update_add M j u v theorem det_updateCol_add (M : Matrix n n R) (j : n) (u v : n → R) : det (updateCol M j <| u + v) = det (updateCol M j u) + det (updateCol M j v) := by rw [← det_transpose, ← updateRow_transpose, det_updateRow_add] simp [updateRow_transpose, det_transpose] @[deprecated (since := "2024-12-11")] alias det_updateColumn_add := det_updateCol_add theorem det_updateRow_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateRow M j <| s • u) = s * det (updateRow M j u) := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_update_smul M j s u theorem det_updateCol_smul (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateCol M j <| s • u) = s * det (updateCol M j u) := by rw [← det_transpose, ← updateRow_transpose, det_updateRow_smul] simp [updateRow_transpose, det_transpose] @[deprecated (since := "2024-12-11")] alias det_updateColumn_smul := det_updateCol_smul theorem det_updateRow_smul_left (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateRow (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateRow M j u) := MultilinearMap.map_update_smul_left _ M j s u @[deprecated (since := "2024-11-03")] alias det_updateRow_smul' := det_updateRow_smul_left theorem det_updateCol_smul_left (M : Matrix n n R) (j : n) (s : R) (u : n → R) : det (updateCol (s • M) j u) = s ^ (Fintype.card n - 1) * det (updateCol M j u) := by rw [← det_transpose, ← updateRow_transpose, transpose_smul, det_updateRow_smul_left] simp [updateRow_transpose, det_transpose] @[deprecated (since := "2024-12-11")] alias det_updateColumn_smul' := det_updateCol_smul_left @[deprecated (since := "2024-12-11")] alias det_updateColumn_smul_left := det_updateCol_smul_left theorem det_updateRow_sum_aux (M : Matrix n n R) {j : n} (s : Finset n) (hj : j ∉ s) (c : n → R) (a : R) : (M.updateRow j (a • M j + ∑ k ∈ s, (c k) • M k)).det = a • M.det := by induction s using Finset.induction_on with | empty => rw [Finset.sum_empty, add_zero, smul_eq_mul, det_updateRow_smul, updateRow_eq_self] | insert k _ hk h_ind => have h : k ≠ j := fun h ↦ (h ▸ hj) (Finset.mem_insert_self _ _) rw [Finset.sum_insert hk, add_comm ((c k) • M k), ← add_assoc, det_updateRow_add, det_updateRow_smul, det_updateRow_eq_zero h, mul_zero, add_zero, h_ind] exact fun h ↦ hj (Finset.mem_insert_of_mem h) /-- If we replace a row of a matrix by a linear combination of its rows, then the determinant is multiplied by the coefficient of that row. -/ theorem det_updateRow_sum (A : Matrix n n R) (j : n) (c : n → R) : (A.updateRow j (∑ k, (c k) • A k)).det = (c j) • A.det := by convert det_updateRow_sum_aux A (Finset.univ.erase j) (Finset.univ.not_mem_erase j) c (c j) rw [← Finset.univ.add_sum_erase _ (Finset.mem_univ j)] /-- If we replace a column of a matrix by a linear combination of its columns, then the determinant is multiplied by the coefficient of that column. -/ theorem det_updateCol_sum (A : Matrix n n R) (j : n) (c : n → R) : (A.updateCol j (fun k ↦ ∑ i, (c i) • A k i)).det = (c j) • A.det := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] convert det_updateRow_sum A.transpose j c simp only [smul_eq_mul, Finset.sum_apply, Pi.smul_apply, transpose_apply] @[deprecated (since := "2024-12-11")] alias det_updateColumn_sum := det_updateCol_sum section DetEq /-! ### `det_eq` section Lemmas showing the determinant is invariant under a variety of operations. -/ theorem det_eq_of_eq_mul_det_one {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1) (hA : A = B * C) : det A = det B := calc det A = det (B * C) := congr_arg _ hA _ = det B * det C := det_mul _ _ _ = det B := by rw [hC, mul_one] theorem det_eq_of_eq_det_one_mul {A B : Matrix n n R} (C : Matrix n n R) (hC : det C = 1) (hA : A = C * B) : det A = det B := calc det A = det (C * B) := congr_arg _ hA _ = det C * det B := det_mul _ _ _ = det B := by rw [hC, one_mul] theorem det_updateRow_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) : det (updateRow A i (A i + A j)) = det A := by simp [det_updateRow_add, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] theorem det_updateCol_add_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) : det (updateCol A i fun k => A k i + A k j) = det A := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] exact det_updateRow_add_self Aᵀ hij @[deprecated (since := "2024-12-11")] alias det_updateColumn_add_self := det_updateCol_add_self theorem det_updateRow_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) : det (updateRow A i (A i + c • A j)) = det A := by simp [det_updateRow_add, det_updateRow_smul, det_zero_of_row_eq hij (updateRow_self.trans (updateRow_ne hij.symm).symm)] theorem det_updateCol_add_smul_self (A : Matrix n n R) {i j : n} (hij : i ≠ j) (c : R) : det (updateCol A i fun k => A k i + c • A k j) = det A := by rw [← det_transpose, ← updateRow_transpose, ← det_transpose A] exact det_updateRow_add_smul_self Aᵀ hij c @[deprecated (since := "2024-12-11")] alias det_updateColumn_add_smul_self := det_updateCol_add_smul_self theorem linearIndependent_rows_of_det_ne_zero [IsDomain R] {A : Matrix m m R} (hA : A.det ≠ 0) : LinearIndependent R A.row := by rw [row_def] contrapose! hA obtain ⟨c, hc0, i, hci⟩ := Fintype.not_linearIndependent_iff.1 hA have h0 := A.det_updateRow_sum i c rwa [det_eq_zero_of_row_eq_zero (i := i) (fun j ↦ by simp [hc0]), smul_eq_mul, eq_comm, mul_eq_zero_iff_left hci] at h0 theorem linearIndependent_cols_of_det_ne_zero [IsDomain R] {A : Matrix m m R} (hA : A.det ≠ 0) : LinearIndependent R A.col := Matrix.linearIndependent_rows_of_det_ne_zero (by simpa) theorem det_eq_of_forall_row_eq_smul_add_const_aux {A B : Matrix n n R} {s : Finset n} : ∀ (c : n → R) (_ : ∀ i, i ∉ s → c i = 0) (k : n) (_ : k ∉ s) (_ : ∀ i j, A i j = B i j + c i * B k j), det A = det B := by induction s using Finset.induction_on generalizing B with | empty => rintro c hs k - A_eq have : ∀ i, c i = 0 := by intro i specialize hs i contrapose! hs simp [hs] congr ext i j rw [A_eq, this, zero_mul, add_zero] | insert i s _hi ih => intro c hs k hk A_eq have hAi : A i = B i + c i • B k := funext (A_eq i) rw [@ih (updateRow B i (A i)) (Function.update c i 0), hAi, det_updateRow_add_smul_self] · exact mt (fun h => show k ∈ insert i s from h ▸ Finset.mem_insert_self _ _) hk · intro i' hi' rw [Function.update_apply] split_ifs with hi'i · rfl · exact hs i' fun h => hi' ((Finset.mem_insert.mp h).resolve_left hi'i) · exact k · exact fun h => hk (Finset.mem_insert_of_mem h) · intro i' j' rw [updateRow_apply, Function.update_apply] split_ifs with hi'i · simp [hi'i] rw [A_eq, updateRow_ne fun h : k = i => hk <| h ▸ Finset.mem_insert_self k s] /-- If you add multiples of row `B k` to other rows, the determinant doesn't change. -/ theorem det_eq_of_forall_row_eq_smul_add_const {A B : Matrix n n R} (c : n → R) (k : n) (hk : c k = 0) (A_eq : ∀ i j, A i j = B i j + c i * B k j) : det A = det B := det_eq_of_forall_row_eq_smul_add_const_aux c (fun i => not_imp_comm.mp fun hi => Finset.mem_erase.mpr ⟨mt (fun h : i = k => show c i = 0 from h.symm ▸ hk) hi, Finset.mem_univ i⟩) k (Finset.not_mem_erase k Finset.univ) A_eq theorem det_eq_of_forall_row_eq_smul_add_pred_aux {n : ℕ} (k : Fin (n + 1)) : ∀ (c : Fin n → R) (_hc : ∀ i : Fin n, k < i.succ → c i = 0) {M N : Matrix (Fin n.succ) (Fin n.succ) R} (_h0 : ∀ j, M 0 j = N 0 j) (_hsucc : ∀ (i : Fin n) (j), M i.succ j = N i.succ j + c i * M (Fin.castSucc i) j), det M = det N := by refine Fin.induction ?_ (fun k ih => ?_) k <;> intro c hc M N h0 hsucc · congr ext i j refine Fin.cases (h0 j) (fun i => ?_) i rw [hsucc, hc i (Fin.succ_pos _), zero_mul, add_zero] set M' := updateRow M k.succ (N k.succ) with hM' have hM : M = updateRow M' k.succ (M' k.succ + c k • M (Fin.castSucc k)) := by ext i j by_cases hi : i = k.succ · simp [hi, hM', hsucc, updateRow_self] rw [updateRow_ne hi, hM', updateRow_ne hi] have k_ne_succ : (Fin.castSucc k) ≠ k.succ := (Fin.castSucc_lt_succ k).ne have M_k : M (Fin.castSucc k) = M' (Fin.castSucc k) := (updateRow_ne k_ne_succ).symm rw [hM, M_k, det_updateRow_add_smul_self M' k_ne_succ.symm, ih (Function.update c k 0)] · intro i hi rw [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff] at hi rw [Function.update_apply] split_ifs with hik · rfl exact hc _ (Fin.succ_lt_succ_iff.mpr (lt_of_le_of_ne hi (Ne.symm hik))) · rwa [hM', updateRow_ne (Fin.succ_ne_zero _).symm] intro i j rw [Function.update_apply] split_ifs with hik · rw [zero_mul, add_zero, hM', hik, updateRow_self] rw [hM', updateRow_ne ((Fin.succ_injective _).ne hik), hsucc] by_cases hik2 : k < i · simp [hc i (Fin.succ_lt_succ_iff.mpr hik2)] rw [updateRow_ne] apply ne_of_lt rwa [Fin.lt_iff_val_lt_val, Fin.coe_castSucc, Fin.val_succ, Nat.lt_succ_iff, ← not_lt] /-- If you add multiples of previous rows to the next row, the determinant doesn't change. -/ theorem det_eq_of_forall_row_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R} (c : Fin n → R) (A_zero : ∀ j, A 0 j = B 0 j) (A_succ : ∀ (i : Fin n) (j), A i.succ j = B i.succ j + c i * A (Fin.castSucc i) j) : det A = det B := det_eq_of_forall_row_eq_smul_add_pred_aux (Fin.last _) c (fun _ hi => absurd hi (not_lt_of_ge (Fin.le_last _))) A_zero A_succ /-- If you add multiples of previous columns to the next columns, the determinant doesn't change. -/ theorem det_eq_of_forall_col_eq_smul_add_pred {n : ℕ} {A B : Matrix (Fin (n + 1)) (Fin (n + 1)) R} (c : Fin n → R) (A_zero : ∀ i, A i 0 = B i 0) (A_succ : ∀ (i) (j : Fin n), A i j.succ = B i j.succ + c j * A i (Fin.castSucc j)) : det A = det B := by rw [← det_transpose A, ← det_transpose B] exact det_eq_of_forall_row_eq_smul_add_pred c A_zero fun i j => A_succ j i end DetEq @[simp] theorem det_blockDiagonal {o : Type*} [Fintype o] [DecidableEq o] (M : o → Matrix n n R) : (blockDiagonal M).det = ∏ k, (M k).det := by -- Rewrite the determinants as a sum over permutations. simp_rw [det_apply'] -- The right hand side is a product of sums, rewrite it as a sum of products. rw [Finset.prod_sum] simp_rw [Finset.prod_attach_univ, Finset.univ_pi_univ] -- We claim that the only permutations contributing to the sum are those that -- preserve their second component. let preserving_snd : Finset (Equiv.Perm (n × o)) := {σ | ∀ x, (σ x).snd = x.snd} have mem_preserving_snd : ∀ {σ : Equiv.Perm (n × o)}, σ ∈ preserving_snd ↔ ∀ x, (σ x).snd = x.snd := fun {σ} => Finset.mem_filter.trans ⟨fun h => h.2, fun h => ⟨Finset.mem_univ _, h⟩⟩ rw [← Finset.sum_subset (Finset.subset_univ preserving_snd) _] -- And that these are in bijection with `o → Equiv.Perm m`. · refine (Finset.sum_bij (fun σ _ => prodCongrLeft fun k ↦ σ k (mem_univ k)) ?_ ?_ ?_ ?_).symm · intro σ _ rw [mem_preserving_snd] rintro ⟨-, x⟩ simp only [prodCongrLeft_apply] · intro σ _ σ' _ eq ext x hx k simp only at eq have : ∀ k x, prodCongrLeft (fun k => σ k (Finset.mem_univ _)) (k, x) = prodCongrLeft (fun k => σ' k (Finset.mem_univ _)) (k, x) := fun k x => by rw [eq] simp only [prodCongrLeft_apply, Prod.mk_inj] at this exact (this k x).1 · intro σ hσ rw [mem_preserving_snd] at hσ have hσ' : ∀ x, (σ⁻¹ x).snd = x.snd := by intro x conv_rhs => rw [← Perm.apply_inv_self σ x, hσ] have mk_apply_eq : ∀ k x, ((σ (x, k)).fst, k) = σ (x, k) := by intro k x ext · simp only · simp only [hσ] have mk_inv_apply_eq : ∀ k x, ((σ⁻¹ (x, k)).fst, k) = σ⁻¹ (x, k) := by intro k x conv_lhs => rw [← Perm.apply_inv_self σ (x, k)] ext · simp only [apply_inv_self] · simp only [hσ'] refine ⟨fun k _ => ⟨fun x => (σ (x, k)).fst, fun x => (σ⁻¹ (x, k)).fst, ?_, ?_⟩, ?_, ?_⟩ · intro x simp only [mk_apply_eq, inv_apply_self] · intro x simp only [mk_inv_apply_eq, apply_inv_self] · apply Finset.mem_univ · ext ⟨k, x⟩ · simp only [coe_fn_mk, prodCongrLeft_apply] · simp only [prodCongrLeft_apply, hσ] · intro σ _ rw [Finset.prod_mul_distrib, ← Finset.univ_product_univ, Finset.prod_product_right] simp only [sign_prodCongrLeft, Units.coe_prod, Int.cast_prod, blockDiagonal_apply_eq, prodCongrLeft_apply] · intro σ _ hσ rw [mem_preserving_snd] at hσ obtain ⟨⟨k, x⟩, hkx⟩ := not_forall.mp hσ rw [Finset.prod_eq_zero (Finset.mem_univ (k, x)), mul_zero] rw [blockDiagonal_apply_ne] exact hkx /-- The determinant of a 2×2 block matrix with the lower-left block equal to zero is the product of the determinants of the diagonal blocks. For the generalization to any number of blocks, see `Matrix.det_of_upperTriangular`. -/
@[simp] theorem det_fromBlocks_zero₂₁ (A : Matrix m m R) (B : Matrix m n R) (D : Matrix n n R) : (Matrix.fromBlocks A B 0 D).det = A.det * D.det := by classical simp_rw [det_apply'] convert Eq.symm <| sum_subset (M := R) (subset_univ ((sumCongrHom m n).range : Set (Perm (m ⊕ n))).toFinset) ?_ · simp_rw [sum_mul_sum, ← sum_product', univ_product_univ] refine sum_nbij (fun σ ↦ σ.fst.sumCongr σ.snd) ?_ ?_ ?_ ?_ · intro σ₁₂ _ simp · intro σ₁ _ σ₂ _ dsimp only intro h have h2 : ∀ x, Perm.sumCongr σ₁.fst σ₁.snd x = Perm.sumCongr σ₂.fst σ₂.snd x := DFunLike.congr_fun h simp only [Sum.map_inr, Sum.map_inl, Perm.sumCongr_apply, Sum.forall, Sum.inl.injEq, Sum.inr.injEq] at h2 ext x · exact h2.left x · exact h2.right x · intro σ hσ rw [mem_coe, Set.mem_toFinset] at hσ obtain ⟨σ₁₂, hσ₁₂⟩ := hσ use σ₁₂ rw [← hσ₁₂] simp · simp only [forall_prop_of_true, Prod.forall, mem_univ] intro σ₁ σ₂ rw [Fintype.prod_sum_type] simp_rw [Equiv.sumCongr_apply, Sum.map_inr, Sum.map_inl, fromBlocks_apply₁₁, fromBlocks_apply₂₂] rw [mul_mul_mul_comm] congr rw [sign_sumCongr, Units.val_mul, Int.cast_mul] · rintro σ - hσn have h1 : ¬∀ x, ∃ y, Sum.inl y = σ (Sum.inl x) := by rw [Set.mem_toFinset] at hσn simpa only [Set.MapsTo, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] using mt mem_sumCongrHom_range_of_perm_mapsTo_inl hσn obtain ⟨a, ha⟩ := not_forall.mp h1 rcases hx : σ (Sum.inl a) with a2 | b · have hn := (not_exists.mp ha) a2 exact absurd hx.symm hn · rw [Finset.prod_eq_zero (Finset.mem_univ (Sum.inl a)), mul_zero] rw [hx, fromBlocks_apply₂₁, zero_apply] /-- The determinant of a 2×2 block matrix with the upper-right block equal to zero is the product of the determinants of the diagonal blocks. For the generalization to any number of blocks, see
Mathlib/LinearAlgebra/Matrix/Determinant/Basic.lean
671
719
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.CoprodI import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.Complement /-! ## Pushouts of Monoids and Groups This file defines wide pushouts of monoids and groups and proves some properties of the amalgamated product of groups (i.e. the special case where all the maps in the diagram are injective). ## Main definitions - `Monoid.PushoutI`: the pushout of a diagram of monoids indexed by a type `ι` - `Monoid.PushoutI.base`: the map from the amalgamating monoid to the pushout - `Monoid.PushoutI.of`: the map from each Monoid in the family to the pushout - `Monoid.PushoutI.lift`: the universal property used to define homomorphisms out of the pushout. - `Monoid.PushoutI.NormalWord`: a normal form for words in the pushout - `Monoid.PushoutI.of_injective`: if all the maps in the diagram are injective in a pushout of groups then so is `of` - `Monoid.PushoutI.Reduced.eq_empty_of_mem_range`: For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base monoid. ## References * The normal form theorem follows these [notes](https://webspace.maths.qmul.ac.uk/i.m.chiswell/ggt/lecture_notes/lecture2.pdf) from Queen Mary University ## Tags amalgamated product, pushout, group -/ namespace Monoid open CoprodI Subgroup Coprod Function List variable {ι : Type*} {G : ι → Type*} {H : Type*} {K : Type*} [Monoid K] /-- The relation we quotient by to form the pushout -/ def PushoutI.con [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Con (Coprod (CoprodI G) H) := conGen (fun x y : Coprod (CoprodI G) H => ∃ i x', x = inl (of (φ i x')) ∧ y = inr x') /-- The indexed pushout of monoids, which is the pushout in the category of monoids, or the category of groups. -/ def PushoutI [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Type _ := (PushoutI.con φ).Quotient namespace PushoutI section Monoid variable [∀ i, Monoid (G i)] [Monoid H] {φ : ∀ i, H →* G i} protected instance mul : Mul (PushoutI φ) := by delta PushoutI; infer_instance protected instance one : One (PushoutI φ) := by delta PushoutI; infer_instance instance monoid : Monoid (PushoutI φ) := { Con.monoid _ with toMul := PushoutI.mul toOne := PushoutI.one } /-- The map from each indexing group into the pushout -/ def of (i : ι) : G i →* PushoutI φ := (Con.mk' _).comp <| inl.comp CoprodI.of variable (φ) in /-- The map from the base monoid into the pushout -/ def base : H →* PushoutI φ := (Con.mk' _).comp inr theorem of_comp_eq_base (i : ι) : (of i).comp (φ i) = (base φ) := by ext x apply (Con.eq _).2 refine ConGen.Rel.of _ _ ?_ simp only [MonoidHom.comp_apply, Set.mem_iUnion, Set.mem_range] exact ⟨_, _, rfl, rfl⟩ variable (φ) in theorem of_apply_eq_base (i : ι) (x : H) : of i (φ i x) = base φ x := by rw [← MonoidHom.comp_apply, of_comp_eq_base] /-- Define a homomorphism out of the pushout of monoids be defining it on each object in the diagram -/ def lift (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) : PushoutI φ →* K := Con.lift _ (Coprod.lift (CoprodI.lift f) k) <| by apply Con.conGen_le fun x y => ?_ rintro ⟨i, x', rfl, rfl⟩ simp only [DFunLike.ext_iff, MonoidHom.coe_comp, comp_apply] at hf simp [hf] @[simp] theorem lift_of (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) {i : ι} (g : G i) : (lift f k hf) (of i g : PushoutI φ) = f i g := by delta PushoutI lift of simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inl, CoprodI.lift_of] @[simp] theorem lift_base (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) (g : H) : (lift f k hf) (base φ g : PushoutI φ) = k g := by delta PushoutI lift base simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inr] -- `ext` attribute should be lower priority then `hom_ext_nonempty` @[ext 1199] theorem hom_ext {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) (hbase : f.comp (base φ) = g.comp (base φ)) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext (CoprodI.ext_hom _ _ h) hbase @[ext high] theorem hom_ext_nonempty [hn : Nonempty ι] {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) : f = g := hom_ext h <| by cases hn with | intro i => ext rw [← of_comp_eq_base i, ← MonoidHom.comp_assoc, h, MonoidHom.comp_assoc] /-- The equivalence that is part of the universal property of the pushout. A hom out of the pushout is just a morphism out of all groups in the pushout that satisfies a commutativity condition. -/ @[simps] def homEquiv : (PushoutI φ →* K) ≃ { f : (Π i, G i →* K) × (H →* K) // ∀ i, (f.1 i).comp (φ i) = f.2 } := { toFun := fun f => ⟨(fun i => f.comp (of i), f.comp (base φ)), fun i => by rw [MonoidHom.comp_assoc, of_comp_eq_base]⟩ invFun := fun f => lift f.1.1 f.1.2 f.2, left_inv := fun _ => hom_ext (by simp [DFunLike.ext_iff]) (by simp [DFunLike.ext_iff]) right_inv := fun ⟨⟨_, _⟩, _⟩ => by simp [DFunLike.ext_iff, funext_iff] } /-- The map from the coproduct into the pushout -/ def ofCoprodI : CoprodI G →* PushoutI φ := CoprodI.lift of @[simp] theorem ofCoprodI_of (i : ι) (g : G i) : (ofCoprodI (CoprodI.of g) : PushoutI φ) = of i g := by simp [ofCoprodI] theorem induction_on {motive : PushoutI φ → Prop} (x : PushoutI φ) (of : ∀ (i : ι) (g : G i), motive (of i g)) (base : ∀ h, motive (base φ h)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by delta PushoutI PushoutI.of PushoutI.base at * induction x using Con.induction_on with | H x => induction x using Coprod.induction_on with | inl g => induction g using CoprodI.induction_on with | of i g => exact of i g | mul x y ihx ihy => rw [map_mul] exact mul _ _ ihx ihy | one => simpa using base 1 | inr h => exact base h | mul x y ihx ihy => exact mul _ _ ihx ihy end Monoid variable [∀ i, Group (G i)] [Group H] {φ : ∀ i, H →* G i} instance : Group (PushoutI φ) := { Con.group (PushoutI.con φ) with toMonoid := PushoutI.monoid } namespace NormalWord /- In this section we show that there is a normal form for words in the amalgamated product. To have a normal form, we need to pick canonical choice of element of each right coset of the base group. The choice of element in the base group itself is `1`. Given a choice of element of each right coset, given by the type `Transversal φ` we can find a normal form. The normal form for an element is an element of the base group, multiplied by a word in the coproduct, where each letter in the word is the canonical choice of element of its coset. We then show that all groups in the diagram act faithfully on the normal form. This implies that the maps into the coproduct are injective. We demonstrate the action is faithful using the equivalence `equivPair`. We show that `G i` acts faithfully on `Pair d i` and that `Pair d i` is isomorphic to `NormalWord d`. Here, `d` is a `Transversal`. A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. We then show that the equivalence between `NormalWord` and `PushoutI`, between the set of normal words and the elements of the amalgamated product. The key to this is the theorem `prod_smul_empty`, which says that going from `NormalWord` to `PushoutI` and back is the identity. This is proven by induction on the word using `consRecOn`. -/ variable (φ) /-- The data we need to pick a normal form for words in the pushout. We need to pick a canonical element of each coset. We also need all the maps in the diagram to be injective -/ structure Transversal : Type _ where /-- All maps in the diagram are injective -/ injective : ∀ i, Injective (φ i) /-- The underlying set, containing exactly one element of each coset of the base group -/ set : ∀ i, Set (G i) /-- The chosen element of the base group itself is the identity -/ one_mem : ∀ i, 1 ∈ set i /-- We have exactly one element of each coset of the base group -/ compl : ∀ i, IsComplement (φ i).range (set i) theorem transversal_nonempty (hφ : ∀ i, Injective (φ i)) : Nonempty (Transversal φ) := by choose t ht using fun i => (φ i).range.exists_isComplement_right 1 apply Nonempty.intro exact { injective := hφ set := t one_mem := fun i => (ht i).2 compl := fun i => (ht i).1 } variable {φ} /-- The normal form for words in the pushout. Every element of the pushout is the product of an element of the base group and a word made up of letters each of which is in the transversal. -/ structure _root_.Monoid.PushoutI.NormalWord (d : Transversal φ) extends CoprodI.Word G where /-- Every `NormalWord` is the product of an element of the base group and a word made up of letters each of which is in the transversal. `head` is that element of the base group. -/ head : H /-- All letter in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ toList → g ∈ d.set i /-- A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. Similar to `Monoid.CoprodI.Pair` except every letter must be in the transversal (not including the head letter). -/ structure Pair (d : Transversal φ) (i : ι) extends CoprodI.Word.Pair G i where /-- All letters in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ tail.toList → g ∈ d.set i variable {d : Transversal φ} /-- The empty normalized word, representing the identity element of the group. -/ @[simps!] def empty : NormalWord d := ⟨CoprodI.Word.empty, 1, fun i g => by simp [CoprodI.Word.empty]⟩ instance : Inhabited (NormalWord d) := ⟨NormalWord.empty⟩ instance (i : ι) : Inhabited (Pair d i) := ⟨{ (empty : NormalWord d) with head := 1, tail := _, fstIdx_ne := fun h => by cases h }⟩ @[ext] theorem ext {w₁ w₂ : NormalWord d} (hhead : w₁.head = w₂.head) (hlist : w₁.toList = w₂.toList) : w₁ = w₂ := by rcases w₁ with ⟨⟨_, _, _⟩, _, _⟩ rcases w₂ with ⟨⟨_, _, _⟩, _, _⟩ simp_all open Subgroup.IsComplement instance baseAction : MulAction H (NormalWord d) := { smul := fun h w => { w with head := h * w.head }, one_smul := by simp [instHSMul] mul_smul := by simp [instHSMul, mul_assoc] } theorem base_smul_def' (h : H) (w : NormalWord d) : h • w = { w with head := h * w.head } := rfl /-- Take the product of a normal word as an element of the `PushoutI`. We show that this is bijective, in `NormalWord.equiv`. -/ def prod (w : NormalWord d) : PushoutI φ := base φ w.head * ofCoprodI (w.toWord).prod @[simp] theorem prod_base_smul (h : H) (w : NormalWord d) : (h • w).prod = base φ h * w.prod := by simp only [base_smul_def', prod, map_mul, mul_assoc] @[simp] theorem prod_empty : (empty : NormalWord d).prod = 1 := by simp [prod, empty] /-- A constructor that multiplies a `NormalWord` by an element, with condition to make sure the underlying list does get longer. -/ @[simps!] noncomputable def cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : NormalWord d := letI n := (d.compl i).equiv (g * (φ i w.head)) letI w' := Word.cons (n.2 : G i) w.toWord hmw (mt (coe_equiv_snd_eq_one_iff_mem _ (d.one_mem _)).1 (mt (mul_mem_cancel_right (by simp)).1 hgr)) { toWord := w' head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by simp only [w', Word.cons, mem_cons, Sigma.mk.inj_iff] at hg rcases hg with ⟨rfl, hg | hg⟩ · simp · exact w.normalized _ _ (by assumption) } @[simp] theorem prod_cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : (cons g w hmw hgr).prod = of i g * w.prod := by simp [prod, cons, ← of_apply_eq_base φ i, equiv_fst_eq_mul_inv, mul_assoc] variable [DecidableEq ι] [∀ i, DecidableEq (G i)] /-- Given a word in `CoprodI`, if every letter is in the transversal and when we multiply by an element of the base group it still has this property, then the element of the base group we multiplied by was one. -/ theorem eq_one_of_smul_normalized (w : CoprodI.Word G) {i : ι} (h : H) (hw : ∀ i g, ⟨i, g⟩ ∈ w.toList → g ∈ d.set i) (hφw : ∀ j g, ⟨j, g⟩ ∈ (CoprodI.of (φ i h) • w).toList → g ∈ d.set j) : h = 1 := by simp only [← (d.compl _).equiv_snd_eq_self_iff_mem (one_mem _)] at hw hφw have hhead : ((d.compl i).equiv (Word.equivPair i w).head).2 = (Word.equivPair i w).head := by rw [Word.equivPair_head] split_ifs with h · rcases h with ⟨_, rfl⟩ exact hw _ _ (List.head_mem _) · rw [equiv_one (d.compl i) (one_mem _) (d.one_mem _)] by_contra hh1 have := hφw i (φ i h * (Word.equivPair i w).head) ?_ · apply hh1 rw [equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩, hhead] at this simpa [((injective_iff_map_eq_one' _).1 (d.injective i))] using this · simp only [Word.mem_smul_iff, not_true, false_and, ne_eq, Option.mem_def, mul_right_inj, exists_eq_right', mul_eq_left, exists_prop, true_and, false_or] constructor · intro h apply_fun (d.compl i).equiv at h simp only [Prod.ext_iff, equiv_one (d.compl i) (one_mem _) (d.one_mem _), equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩ , hhead, Subtype.ext_iff, Prod.ext_iff, Subgroup.coe_mul] at h rcases h with ⟨h₁, h₂⟩ rw [h₂, equiv_one (d.compl i) (one_mem _) (d.one_mem _)] at h₁ erw [mul_one] at h₁ simp only [((injective_iff_map_eq_one' _).1 (d.injective i))] at h₁ contradiction · rw [Word.equivPair_head] dsimp split_ifs with hep · rcases hep with ⟨hnil, rfl⟩ rw [head?_eq_head hnil] simp_all · push_neg at hep by_cases hw : w.toList = [] · simp [hw, Word.fstIdx] · simp [head?_eq_head hw, Word.fstIdx, hep hw] theorem ext_smul {w₁ w₂ : NormalWord d} (i : ι) (h : CoprodI.of (φ i w₁.head) • w₁.toWord = CoprodI.of (φ i w₂.head) • w₂.toWord) : w₁ = w₂ := by rcases w₁ with ⟨w₁, h₁, hw₁⟩ rcases w₂ with ⟨w₂, h₂, hw₂⟩ dsimp at * rw [smul_eq_iff_eq_inv_smul, ← mul_smul] at h subst h simp only [← map_inv, ← map_mul] at hw₁ have : h₁⁻¹ * h₂ = 1 := eq_one_of_smul_normalized w₂ (h₁⁻¹ * h₂) hw₂ hw₁ rw [inv_mul_eq_one] at this; subst this simp /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, but putting head into normal form first, by making sure it is expressed as an element of the base group multiplied by an element of the transversal. -/ noncomputable def rcons (i : ι) (p : Pair d i) : NormalWord d := letI n := (d.compl i).equiv p.head let w := (Word.equivPair i).symm { p.toPair with head := n.2 } { toWord := w head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by dsimp [w] at hg rw [Word.equivPair_symm, Word.mem_rcons_iff] at hg rcases hg with hg | ⟨_, rfl, rfl⟩ · exact p.normalized _ _ hg · simp } theorem rcons_injective {i : ι} : Function.Injective (rcons (d := d) i) := by rintro ⟨⟨head₁, tail₁⟩, _⟩ ⟨⟨head₂, tail₂⟩, _⟩ simp only [rcons, NormalWord.mk.injEq, EmbeddingLike.apply_eq_iff_eq, Word.Pair.mk.injEq, Pair.mk.injEq, and_imp] intro h₁ h₂ h₃ subst h₂ rw [← equiv_fst_mul_equiv_snd (d.compl i) head₁, ← equiv_fst_mul_equiv_snd (d.compl i) head₂, h₁, h₃] simp /-- The equivalence between `NormalWord`s and pairs. We can turn a `NormalWord` into a pair by taking the head of the `List` if it is in `G i` and multiplying it by the element of the base group. -/ noncomputable def equivPair (i) : NormalWord d ≃ Pair d i := letI toFun : NormalWord d → Pair d i := fun w => letI p := Word.equivPair i (CoprodI.of (φ i w.head) • w.toWord) { toPair := p normalized := fun j g hg => by dsimp only [p] at hg rw [Word.of_smul_def, ← Word.equivPair_symm, Equiv.apply_symm_apply] at hg dsimp at hg exact w.normalized _ _ (Word.mem_of_mem_equivPair_tail _ hg) } haveI leftInv : Function.LeftInverse (rcons i) toFun := fun w => ext_smul i <| by simp only [toFun, rcons, Word.equivPair_symm, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul] { toFun := toFun invFun := rcons i left_inv := leftInv right_inv := fun _ => rcons_injective (leftInv _) } noncomputable instance summandAction (i : ι) : MulAction (G i) (NormalWord d) := { smul := fun g w => (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } one_smul := fun _ => by dsimp [instHSMul] rw [one_mul] exact (equivPair i).symm_apply_apply _ mul_smul := fun _ _ _ => by dsimp [instHSMul] simp [mul_assoc, Equiv.apply_symm_apply, Function.End.mul_def] } theorem summand_smul_def' {i : ι} (g : G i) (w : NormalWord d) : g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := rfl noncomputable instance mulAction : MulAction (PushoutI φ) (NormalWord d) := MulAction.ofEndHom <| lift (fun _ => MulAction.toEndHom) MulAction.toEndHom <| by intro i simp only [MulAction.toEndHom, DFunLike.ext_iff, MonoidHom.coe_comp, MonoidHom.coe_mk,
OneHom.coe_mk, comp_apply] intro h funext w apply NormalWord.ext_smul i simp only [summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, equiv_fst_eq_mul_inv, map_mul, map_inv, mul_smul, inv_smul_smul,
Mathlib/GroupTheory/PushoutI.lean
459
465
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.Hom.Set /-! # Lemmas about images of intervals under order isomorphisms. -/ open Set namespace OrderIso section Preorder variable {α β : Type*} [Preorder α] [Preorder β] @[simp] theorem preimage_Iic (e : α ≃o β) (b : β) : e ⁻¹' Iic b = Iic (e.symm b) := by ext x simp [← e.le_iff_le] @[simp] theorem preimage_Ici (e : α ≃o β) (b : β) : e ⁻¹' Ici b = Ici (e.symm b) := by ext x simp [← e.le_iff_le] @[simp] theorem preimage_Iio (e : α ≃o β) (b : β) : e ⁻¹' Iio b = Iio (e.symm b) := by ext x simp [← e.lt_iff_lt] @[simp] theorem preimage_Ioi (e : α ≃o β) (b : β) : e ⁻¹' Ioi b = Ioi (e.symm b) := by ext x simp [← e.lt_iff_lt] @[simp] theorem preimage_Icc (e : α ≃o β) (a b : β) : e ⁻¹' Icc a b = Icc (e.symm a) (e.symm b) := by simp [← Ici_inter_Iic] @[simp] theorem preimage_Ico (e : α ≃o β) (a b : β) : e ⁻¹' Ico a b = Ico (e.symm a) (e.symm b) := by simp [← Ici_inter_Iio] @[simp] theorem preimage_Ioc (e : α ≃o β) (a b : β) : e ⁻¹' Ioc a b = Ioc (e.symm a) (e.symm b) := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_Ioo (e : α ≃o β) (a b : β) : e ⁻¹' Ioo a b = Ioo (e.symm a) (e.symm b) := by simp [← Ioi_inter_Iio] @[simp] theorem image_Iic (e : α ≃o β) (a : α) : e '' Iic a = Iic (e a) := by rw [e.image_eq_preimage, e.symm.preimage_Iic, e.symm_symm] @[simp] theorem image_Ici (e : α ≃o β) (a : α) : e '' Ici a = Ici (e a) := e.dual.image_Iic a @[simp] theorem image_Iio (e : α ≃o β) (a : α) : e '' Iio a = Iio (e a) := by rw [e.image_eq_preimage, e.symm.preimage_Iio, e.symm_symm] @[simp] theorem image_Ioi (e : α ≃o β) (a : α) : e '' Ioi a = Ioi (e a) := e.dual.image_Iio a @[simp] theorem image_Ioo (e : α ≃o β) (a b : α) : e '' Ioo a b = Ioo (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Ioo, e.symm_symm] @[simp] theorem image_Ioc (e : α ≃o β) (a b : α) : e '' Ioc a b = Ioc (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Ioc, e.symm_symm] @[simp] theorem image_Ico (e : α ≃o β) (a b : α) : e '' Ico a b = Ico (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Ico, e.symm_symm] @[simp] theorem image_Icc (e : α ≃o β) (a b : α) : e '' Icc a b = Icc (e a) (e b) := by rw [e.image_eq_preimage, e.symm.preimage_Icc, e.symm_symm]
end Preorder
Mathlib/Order/Interval/Set/OrderIso.lean
88
89
/- 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.Computability.Tape import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.PFun import Mathlib.Computability.PostTuringMachine /-! # Turing machines The files `PostTuringMachine.lean` and `TuringMachine.lean` define a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. `PostTuringMachine.lean` covers the TM0 model and TM1 model; `TuringMachine.lean` adds the TM2 model. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Γ` is the alphabet on the tape. * `Λ` is the set of labels, or internal machine states. * `σ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Λ`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Λ → Stmt`, although different models have different ways of halting and other actions. * `step : Cfg → Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input → Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Γ`. * `eval : Machine → Input → Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg → Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine → Finset Λ → Prop` asserts that a machine `M` starts in `S : Finset Λ`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Λ` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open List (Vector) open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-! ## The TM2 model The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks, each with elements of different types (the alphabet of stack `k : K` is `Γ k`). The statements are: * `push k (f : σ → Γ k) q` puts `f a` on the `k`-th stack, then does `q`. * `pop k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, and removes this element from the stack, then does `q`. * `peek k (f : σ → Option (Γ k) → σ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, then does `q`. * `load (f : σ → σ) q` reads nothing but applies `f` to the internal state, then does `q`. * `branch (f : σ → Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`. * `goto (f : σ → Λ)` jumps to label `f a`. * `halt` halts on the next step. The configuration is a tuple `(l, var, stk)` where `l : Option Λ` is the current label to run or `none` for the halting state, `var : σ` is the (finite) internal state, and `stk : ∀ k, List (Γ k)` is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not `ListBlank`s, they have definite ends that can be detected by the `pop` command.) Given a designated stack `k` and a value `L : List (Γ k)`, the initial configuration has all the stacks empty except the designated "input" stack; in `eval` this designated stack also functions as the output stack. -/ namespace TM2 variable {K : Type*} -- Index type of stacks variable (Γ : K → Type*) -- Type of stack elements variable (Λ : Type*) -- Type of function labels variable (σ : Type*) -- Type of variable settings /-- The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks. The operation `push` puts an element on one of the stacks, and `pop` removes an element from a stack (and modifying the internal state based on the result). `peek` modifies the internal state but does not remove an element. -/ inductive Stmt | push : ∀ k, (σ → Γ k) → Stmt → Stmt | peek : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt | pop : ∀ k, (σ → Option (Γ k) → σ) → Stmt → Stmt | load : (σ → σ) → Stmt → Stmt | branch : (σ → Bool) → Stmt → Stmt → Stmt | goto : (σ → Λ) → Stmt | halt : Stmt open Stmt instance Stmt.inhabited : Inhabited (Stmt Γ Λ σ) := ⟨halt⟩ /-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite size.) -/ structure Cfg where /-- The current label to run (or `none` for the halting state) -/ l : Option Λ /-- The internal state -/ var : σ /-- The (finite) collection of internal stacks -/ stk : ∀ k, List (Γ k) instance Cfg.inhabited [Inhabited σ] : Inhabited (Cfg Γ Λ σ) := ⟨⟨default, default, default⟩⟩ variable {Γ Λ σ} section variable [DecidableEq K] /-- The step function for the TM2 model. -/ def stepAux : Stmt Γ Λ σ → σ → (∀ k, List (Γ k)) → Cfg Γ Λ σ | push k f q, v, S => stepAux q v (update S k (f v :: S k)) | peek k f q, v, S => stepAux q (f v (S k).head?) S | pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail) | load a q, v, S => stepAux q (a v) S | branch f q₁ q₂, v, S => cond (f v) (stepAux q₁ v S) (stepAux q₂ v S) | goto f, v, S => ⟨some (f v), v, S⟩ | halt, v, S => ⟨none, v, S⟩ /-- The step function for the TM2 model. -/ def step (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Option (Cfg Γ Λ σ) | ⟨none, _, _⟩ => none | ⟨some l, v, S⟩ => some (stepAux (M l) v S) attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3 stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2 /-- The (reflexive) reachability relation for the TM2 model. -/ def Reaches (M : Λ → Stmt Γ Λ σ) : Cfg Γ Λ σ → Cfg Γ Λ σ → Prop := ReflTransGen fun a b ↦ b ∈ step M a end /-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/ def SupportsStmt (S : Finset Λ) : Stmt Γ Λ σ → Prop | push _ _ q => SupportsStmt S q | peek _ _ q => SupportsStmt S q | pop _ _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ q₂ => SupportsStmt S q₁ ∧ SupportsStmt S q₂ | goto l => ∀ v, l v ∈ S | halt => True section open scoped Classical in /-- The set of subtree statements in a statement. -/ noncomputable def stmts₁ : Stmt Γ Λ σ → Finset (Stmt Γ Λ σ) | Q@(push _ _ q) => insert Q (stmts₁ q) | Q@(peek _ _ q) => insert Q (stmts₁ q) | Q@(pop _ _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ q₂) => insert Q (stmts₁ q₁ ∪ stmts₁ q₂) | Q@(goto _) => {Q} | Q@halt => {Q} theorem stmts₁_self {q : Stmt Γ Λ σ} : q ∈ stmts₁ q := by cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁] theorem stmts₁_trans {q₁ q₂ : Stmt Γ Λ σ} : q₁ ∈ stmts₁ q₂ → stmts₁ q₁ ⊆ stmts₁ q₂ := by classical intro h₁₂ q₀ h₀₁ induction q₂ with ( simp only [stmts₁] at h₁₂ ⊢ simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂) | branch f q₁ q₂ IH₁ IH₂ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) · unfold stmts₁ at h₀₁ exact h₀₁ · exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂)) · exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IH₂ h₁₂)) | goto l => subst h₁₂; exact h₀₁ | halt => subst h₁₂; exact h₀₁ | load _ q IH | _ _ _ q IH => rcases h₁₂ with (rfl | h₁₂) · unfold stmts₁ at h₀₁ exact h₀₁ · exact Finset.mem_insert_of_mem (IH h₁₂) theorem stmts₁_supportsStmt_mono {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h : q₁ ∈ stmts₁ q₂) (hs : SupportsStmt S q₂) : SupportsStmt S q₁ := by induction q₂ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch f q₁ q₂ IH₁ IH₂ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IH₂ h hs.2] | goto l => subst h; exact hs | halt => subst h; trivial | load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs] open scoped Classical in /-- The set of statements accessible from initial set `S` of labels. -/ noncomputable def stmts (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) : Finset (Option (Stmt Γ Λ σ)) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q)) theorem stmts_trans {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q₁ q₂ : Stmt Γ Λ σ} (h₁ : q₁ ∈ stmts₁ q₂) : some q₂ ∈ stmts M S → some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h₂ ↦ ⟨_, ls, stmts₁_trans h₂ h₁⟩ end variable [Inhabited Λ] /-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in `S` jump only to other states in `S`. -/ def Supports (M : Λ → Stmt Γ Λ σ) (S : Finset Λ) := default ∈ S ∧ ∀ q ∈ S, SupportsStmt S (M q) theorem stmts_supportsStmt {M : Λ → Stmt Γ Λ σ} {S : Finset Λ} {q : Stmt Γ Λ σ} (ss : Supports M S) : some q ∈ stmts M S → SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls) variable [DecidableEq K] theorem step_supports (M : Λ → Stmt Γ Λ σ) {S : Finset Λ} (ss : Supports M S) : ∀ {c c' : Cfg Γ Λ σ}, c' ∈ step M c → c.l ∈ Finset.insertNone S → c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, h₂ => by replace h₂ := ss.2 _ (Finset.some_mem_insertNone.1 h₂) simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c' revert h₂; induction M l₁ generalizing v T with intro hs | branch p q₁' q₂' IH₁ IH₂ => unfold stepAux; cases p v · exact IH₂ _ _ hs.2 · exact IH₁ _ _ hs.1 | goto => exact Finset.some_mem_insertNone.2 (hs _) | halt => apply Multiset.mem_cons_self | load _ _ IH | _ _ _ _ IH => exact IH _ _ hs variable [Inhabited σ] /-- The initial state of the TM2 model. The input is provided on a designated stack. -/ def init (k : K) (L : List (Γ k)) : Cfg Γ Λ σ := ⟨some default, default, update (fun _ ↦ []) k L⟩ /-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/ def eval (M : Λ → Stmt Γ Λ σ) (k : K) (L : List (Γ k)) : Part (List (Γ k)) := (Turing.eval (step M) (init k L)).map fun c ↦ c.stk k end TM2 /-! ## TM2 emulator in TM1 To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack 1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this: ``` bottom: ... | _ | T | _ | _ | _ | _ | ... stack 1: ... | _ | b | a | _ | _ | _ | ... stack 2: ... | _ | f | e | d | c | _ | ... ``` where a tape element is a vertical slice through the diagram. Here the alphabet is `Γ' := Bool × ∀ k, Option (Γ k)`, where: * `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the tail of all stacks. It is never modified. * `stk k : Option (Γ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is the blank value). Note that the head of the stack is at the far end; this is so that push and pop don't have to do any shifting. In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions, it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the end of the appropriate stack, make its changes, and then return to the bottom. So the states are: * `normal (l : Λ)`: waiting at `bottom` to execute function `l` * `go k (s : StAct k) (q : Stmt₂)`: travelling to the right to get to the end of stack `k` in order to perform stack action `s`, and later continue with executing `q` * `ret (q : Stmt₂)`: travelling to the left after having performed a stack action, and executing `q` once we arrive Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)` steps to run when emulated in TM1, where `m` is the length of the input. -/ namespace TM2to1 -- A displaced lemma proved in unnecessary generality theorem stk_nth_val {K : Type*} {Γ : K → Type*} {L : ListBlank (∀ k, Option (Γ k))} {k S} (n) (hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) : L.nth n k = S.reverse[n]? := by rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.getElem?_map] cases S.reverse[n]? <;> rfl variable (K : Type*) variable (Γ : K → Type*) variable {Λ σ : Type*} /-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom, plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/ def Γ' := Bool × ∀ k, Option (Γ k) variable {K Γ} instance Γ'.inhabited : Inhabited (Γ' K Γ) := ⟨⟨false, fun _ ↦ none⟩⟩ instance Γ'.fintype [DecidableEq K] [Fintype K] [∀ k, Fintype (Γ k)] : Fintype (Γ' K Γ) := instFintypeProd _ _ /-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function to express the program state in terms of a tape with only the stacks themselves. -/ def addBottom (L : ListBlank (∀ k, Option (Γ k))) : ListBlank (Γ' K Γ) := ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩) theorem addBottom_map (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by simp only [addBottom, ListBlank.map_cons] convert ListBlank.cons_head_tail L generalize ListBlank.tail L = L' refine L'.induction_on fun l ↦ ?_; simp theorem addBottom_modifyNth (f : (∀ k, Option (Γ k)) → ∀ k, Option (Γ k)) (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) : (addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by cases n <;> simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons] congr; symm; apply ListBlank.map_modifyNth; intro; rfl theorem addBottom_nth_snd (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) : ((addBottom L).nth n).2 = L.nth n := by conv => rhs; rw [← addBottom_map L, ListBlank.nth_map] theorem addBottom_nth_succ_fst (L : ListBlank (∀ k, Option (Γ k))) (n : ℕ) : ((addBottom L).nth (n + 1)).1 = false := by rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map] theorem addBottom_head_fst (L : ListBlank (∀ k, Option (Γ k))) : (addBottom L).head.1 = true := by rw [addBottom, ListBlank.head_cons] variable (K Γ σ) in /-- A stack action is a command that interacts with the top of a stack. Our default position is at the bottom of all the stacks, so we have to hold on to this action while going to the end to modify the stack. -/ inductive StAct (k : K) | push : (σ → Γ k) → StAct k | peek : (σ → Option (Γ k) → σ) → StAct k | pop : (σ → Option (Γ k) → σ) → StAct k instance StAct.inhabited {k : K} : Inhabited (StAct K Γ σ k) := ⟨StAct.peek fun s _ ↦ s⟩ section open StAct /-- The TM2 statement corresponding to a stack action. -/ def stRun {k : K} : StAct K Γ σ k → TM2.Stmt Γ Λ σ → TM2.Stmt Γ Λ σ | push f => TM2.Stmt.push k f | peek f => TM2.Stmt.peek k f | pop f => TM2.Stmt.pop k f /-- The effect of a stack action on the local variables, given the value of the stack. -/ def stVar {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → σ | push _ => v | peek f => f v l.head? | pop f => f v l.head? /-- The effect of a stack action on the stack. -/ def stWrite {k : K} (v : σ) (l : List (Γ k)) : StAct K Γ σ k → List (Γ k) | push f => f v :: l | peek _ => l | pop _ => l.tail /-- We have partitioned the TM2 statements into "stack actions", which require going to the end of the stack, and all other actions, which do not. This is a modified recursor which lumps the stack actions into one. -/ @[elab_as_elim] def stmtStRec.{l} {motive : TM2.Stmt Γ Λ σ → Sort l} (run : ∀ (k) (s : StAct K Γ σ k) (q) (_ : motive q), motive (stRun s q)) (load : ∀ (a q) (_ : motive q), motive (TM2.Stmt.load a q)) (branch : ∀ (p q₁ q₂) (_ : motive q₁) (_ : motive q₂), motive (TM2.Stmt.branch p q₁ q₂)) (goto : ∀ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : ∀ n, motive n | TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q) | TM2.Stmt.branch _ q₁ q₂ => branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt q₂) | TM2.Stmt.goto _ => goto _ | TM2.Stmt.halt => halt theorem supports_run (S : Finset Λ) {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) : TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by cases s <;> rfl end variable (K Γ Λ σ) /-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and return to the bottom, respectively. -/ inductive Λ' | normal : Λ → Λ' | go (k : K) : StAct K Γ σ k → TM2.Stmt Γ Λ σ → Λ' | ret : TM2.Stmt Γ Λ σ → Λ' variable {K Γ Λ σ} open Λ' instance Λ'.inhabited [Inhabited Λ] : Inhabited (Λ' K Γ Λ σ) := ⟨normal default⟩ open TM1.Stmt section variable [DecidableEq K] /-- The program corresponding to state transitions at the end of a stack. Here we start out just after the top of the stack, and should end just after the new top of the stack. -/ def trStAct {k : K} (q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ) : StAct K Γ σ k → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ | StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q | StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q | StAct.pop f => branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q) (move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q) /-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty except for the input stack, and the stack bottom mark is set at the head. -/ def trInit (k : K) (L : List (Γ k)) : List (Γ' K Γ) := let L' : List (Γ' K Γ) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a)) (true, L'.headI.2) :: L'.tail theorem step_run {k : K} (q : TM2.Stmt Γ Λ σ) (v : σ) (S : ∀ k, List (Γ k)) : ∀ s : StAct K Γ σ k, TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s)) | StAct.push _ => rfl | StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl | StAct.pop _ => rfl end /-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents, but stack actions are deferred by going to the corresponding `go` state, so that we can find the appropriate stack top. -/ def trNormal : TM2.Stmt Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ | TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q | TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q | TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q | TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q) | TM2.Stmt.branch f q₁ q₂ => branch (fun _ ↦ f) (trNormal q₁) (trNormal q₂) | TM2.Stmt.goto l => goto fun _ s ↦ normal (l s) | TM2.Stmt.halt => halt theorem trNormal_run {k : K} (s : StAct K Γ σ k) (q : TM2.Stmt Γ Λ σ) : trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by cases s <;> rfl section open scoped Classical in /-- The set of machine states accessible from an initial TM2 statement. -/ noncomputable def trStmts₁ : TM2.Stmt Γ Λ σ → Finset (Λ' K Γ Λ σ) | TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} ∪ trStmts₁ q | TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} ∪ trStmts₁ q | TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} ∪ trStmts₁ q | TM2.Stmt.load _ q => trStmts₁ q | TM2.Stmt.branch _ q₁ q₂ => trStmts₁ q₁ ∪ trStmts₁ q₂ | _ => ∅ theorem trStmts₁_run {k : K} {s : StAct K Γ σ k} {q : TM2.Stmt Γ Λ σ} : open scoped Classical in trStmts₁ (stRun s q) = {go k s q, ret q} ∪ trStmts₁ q := by cases s <;> simp only [trStmts₁, stRun] theorem tr_respects_aux₂ [DecidableEq K] {k : K} {q : TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ} {v : σ} {S : ∀ k, List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))} (hL : ∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) : let v' := stVar v (S k) o let Sk' := stWrite v (S k) o let S' := update S k Sk' ∃ L' : ListBlank (∀ k, Option (Γ k)), (∀ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧ TM1.stepAux (trStAct q o) v ((Tape.move Dir.right)^[(S k).length] (Tape.mk' ∅ (addBottom L))) = TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' ∅ (addBottom L'))) := by simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux] | push f => have := Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k (some (f v))) refine ⟨_, fun k' ↦ ?_, by -- Porting note: `rw [...]` to `erw [...]; rfl`. -- https://github.com/leanprover-community/mathlib4/issues/5164 rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this] erw [addBottom_modifyNth fun a ↦ update a k (some (f v))] rw [Nat.add_one, iterate_succ'] rfl⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val] by_cases h' : k' = k · subst k' split_ifs with h <;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map] · rw [List.getI_eq_getElem _, List.getElem_append_right] <;> simp only [List.length_append, List.length_reverse, List.length_map, ← h, Nat.sub_self, List.length_singleton, List.getElem_singleton, le_refl, Nat.lt_succ_self] rw [← proj_map_nth, hL, ListBlank.nth_mk] rcases lt_or_gt_of_ne h with h | h · rw [List.getI_append] simpa only [List.length_map, List.length_reverse] using h · rw [gt_iff_lt] at h rw [List.getI_eq_default, List.getI_eq_default] <;> simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse, List.length_append, List.length_map] · split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL] rw [Function.update_of_ne h'] | peek f => rw [Function.update_eq_self] use L, hL; rw [Tape.move_left_right]; congr cases e : S k; · rfl rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e, List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length] rfl | pop f => rcases e : S k with - | ⟨hd, tl⟩ · simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length, Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil] rw [← e, Function.update_eq_self] exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩ · refine ⟨_, fun k' ↦ ?_, by erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst, cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head, Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Γ' K Γ ↦ (a.1, update a.2 k none), addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd, stk_nth_val _ (hL k), e, show (List.cons hd tl).reverse[tl.length]? = some hd by rw [List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length], List.head?, List.tail]⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val] by_cases h' : k' = k · subst k' split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail] · rw [List.getI_eq_default] · rfl rw [h, List.length_reverse, List.length_map] rw [← proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons] rcases lt_or_gt_of_ne h with h | h · rw [List.getI_append] simpa only [List.length_map, List.length_reverse] using h · rw [gt_iff_lt] at h rw [List.getI_eq_default, List.getI_eq_default] <;> simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse, List.length_append, List.length_map] · split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL] rw [Function.update_of_ne h'] end variable [DecidableEq K] variable (M : Λ → TM2.Stmt Γ Λ σ) /-- The TM2 emulator machine states written as a TM1 program. This handles the `go` and `ret` states, which shuttle to and from a stack top. -/ def tr : Λ' K Γ Λ σ → TM1.Stmt (Γ' K Γ) (Λ' K Γ Λ σ) σ | normal q => trNormal (M q) | go k s q => branch (fun a _ ↦ (a.2 k).isNone) (trStAct (goto fun _ _ ↦ ret q) s) (move Dir.right <| goto fun _ _ ↦ go k s q) | ret q => branch (fun a _ ↦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ ↦ ret q) /-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/ inductive TrCfg : TM2.Cfg Γ Λ σ → TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ → Prop | mk {q : Option Λ} {v : σ} {S : ∀ k, List (Γ k)} (L : ListBlank (∀ k, Option (Γ k))) : (∀ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) → TrCfg ⟨q, v, S⟩ ⟨q.map normal, v, Tape.mk' ∅ (addBottom L)⟩ theorem tr_respects_aux₁ {k} (o q v) {S : List (Γ k)} {L : ListBlank (∀ k, Option (Γ k))} (hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n ≤ S.length) : Reaches₀ (TM1.step (tr M)) ⟨some (go k o q), v, Tape.mk' ∅ (addBottom L)⟩ ⟨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ := by induction' n with n IH; · rfl apply (IH (le_of_lt H)).tail rw [iterate_succ_apply'] simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head, addBottom_nth_snd, Option.mem_def] rw [stk_nth_val _ hL, List.getElem?_eq_getElem] · rfl · rwa [List.length_reverse] theorem tr_respects_aux₃ {q v} {L : ListBlank (∀ k, Option (Γ k))} (n) : Reaches₀ (TM1.step (tr M)) ⟨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' ∅ (addBottom L))⟩ ⟨some (ret q), v, Tape.mk' ∅ (addBottom L)⟩ := by induction' n with n IH; · rfl refine Reaches₀.head ?_ IH simp only [Option.mem_def, TM1.step] rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left] rfl theorem tr_respects_aux {q v T k} {S : ∀ k, List (Γ k)} (hT : ∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) (o : StAct K Γ σ k) (IH : ∀ {v : σ} {S : ∀ k : K, List (Γ k)} {T : ListBlank (∀ k, Option (Γ k))}, (∀ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) → ∃ b, TrCfg (TM2.stepAux q v S) b ∧ Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' ∅ (addBottom T))) b) : ∃ b, TrCfg (TM2.stepAux (stRun o q) v S) b ∧ Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal (stRun o q)) v (Tape.mk' ∅ (addBottom T))) b := by simp only [trNormal_run, step_run] have hgo := tr_respects_aux₁ M o q v (hT k) _ le_rfl obtain ⟨T', hT', hrun⟩ := tr_respects_aux₂ (Λ := Λ) hT o have := hgo.tail' rfl rw [tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hT k), List.getElem?_eq_none (le_of_eq List.length_reverse), Option.isNone, cond, hrun, TM1.stepAux] at this obtain ⟨c, gc, rc⟩ := IH hT' refine ⟨c, gc, (this.to₀.trans (tr_respects_aux₃ M _) c (TransGen.head' rfl ?_)).to_reflTransGen⟩ rw [tr, TM1.stepAux, Tape.mk'_head, addBottom_head_fst] exact rc attribute [local simp] Respects TM2.step TM2.stepAux trNormal theorem tr_respects : Respects (TM2.step M) (TM1.step (tr M)) TrCfg := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed intro c₁ c₂ h obtain @⟨- | l, v, S, L, hT⟩ := h; · constructor rsuffices ⟨b, c, r⟩ : ∃ b, _ ∧ Reaches (TM1.step (tr M)) _ _ · exact ⟨b, c, TransGen.head' rfl r⟩ simp only [tr] generalize M l = N induction N using stmtStRec generalizing v S L hT with | run k s q IH => exact tr_respects_aux M hT s @IH | load a _ IH => exact IH _ hT | branch p q₁ q₂ IH₁ IH₂ => unfold TM2.stepAux trNormal TM1.stepAux beta_reduce cases p v <;> [exact IH₂ _ hT; exact IH₁ _ hT] | goto => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩ | halt => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩ section variable [Inhabited Λ] [Inhabited σ] theorem trCfg_init (k) (L : List (Γ k)) : TrCfg (TM2.init k L) (TM1.init (trInit k L) : TM1.Cfg (Γ' K Γ) (Λ' K Γ Λ σ) σ) := by rw [(_ : TM1.init _ = _)] · refine ⟨ListBlank.mk (L.reverse.map fun a ↦ update default k (some a)), fun k' ↦ ?_⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map_map] have : ((proj k').f ∘ fun a => update (β := fun k => Option (Γ k)) default k (some a)) = fun a => (proj k').f (update (β := fun k => Option (Γ k)) default k (some a)) := rfl rw [this, List.getElem?_map, proj, PointedMap.mk_val] simp only [] by_cases h : k' = k · subst k' simp only [Function.update_self] rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, ← List.map_reverse, List.getElem?_map] · simp only [Function.update_of_ne h] rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map, List.reverse_nil] cases L.reverse[i]? <;> rfl · rw [trInit, TM1.init] congr <;> cases L.reverse <;> try rfl simp only [List.map_map, List.tail_cons, List.map] rfl theorem tr_eval_dom (k) (L : List (Γ k)) : (TM1.eval (tr M) (trInit k L)).Dom ↔ (TM2.eval M k L).Dom := Turing.tr_eval_dom (tr_respects M) (trCfg_init k L) theorem tr_eval (k) (L : List (Γ k)) {L₁ L₂} (H₁ : L₁ ∈ TM1.eval (tr M) (trInit k L)) (H₂ : L₂ ∈ TM2.eval M k L) : ∃ (S : ∀ k, List (Γ k)) (L' : ListBlank (∀ k, Option (Γ k))), addBottom L' = L₁ ∧ (∀ k, L'.map (proj k) = ListBlank.mk ((S k).map some).reverse) ∧ S k = L₂ := by obtain ⟨c₁, h₁, rfl⟩ := (Part.mem_map_iff _).1 H₁ obtain ⟨c₂, h₂, rfl⟩ := (Part.mem_map_iff _).1 H₂ obtain ⟨_, ⟨L', hT⟩, h₃⟩ := Turing.tr_eval (tr_respects M) (trCfg_init k L) h₂ cases Part.mem_unique h₁ h₃ exact ⟨_, L', by simp only [Tape.mk'_right₀], hT, rfl⟩ end section variable [Inhabited Λ] open scoped Classical in /-- The support of a set of TM2 states in the TM2 emulator. -/ noncomputable def trSupp (S : Finset Λ) : Finset (Λ' K Γ Λ σ) := S.biUnion fun l ↦ insert (normal l) (trStmts₁ (M l)) open scoped Classical in theorem tr_supports {S} (ss : TM2.Supports M S) : TM1.Supports (tr M) (trSupp M S) := ⟨Finset.mem_biUnion.2 ⟨_, ss.1, Finset.mem_insert.2 <| Or.inl rfl⟩, fun l' h ↦ by suffices ∀ (q) (_ : TM2.SupportsStmt S q) (_ : ∀ x ∈ trStmts₁ q, x ∈ trSupp M S), TM1.SupportsStmt (trSupp M S) (trNormal q) ∧ ∀ l' ∈ trStmts₁ q, TM1.SupportsStmt (trSupp M S) (tr M l') by rcases Finset.mem_biUnion.1 h with ⟨l, lS, h⟩ have := this _ (ss.2 l lS) fun x hx ↦ Finset.mem_biUnion.2 ⟨_, lS, Finset.mem_insert_of_mem hx⟩ rcases Finset.mem_insert.1 h with (rfl | h) <;> [exact this.1; exact this.2 _ h] clear h l' refine stmtStRec ?_ ?_ ?_ ?_ ?_ · intro _ s _ IH ss' sub -- stack op rw [TM2to1.supports_run] at ss' simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] at sub have hgo := sub _ (Or.inl <| Or.inl rfl) have hret := sub _ (Or.inl <| Or.inr rfl) obtain ⟨IH₁, IH₂⟩ := IH ss' fun x hx ↦ sub x <| Or.inr hx refine ⟨by simp only [trNormal_run, TM1.SupportsStmt]; intros; exact hgo, fun l h ↦ ?_⟩ rw [trStmts₁_run] at h simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] at h rcases h with (⟨rfl | rfl⟩ | h) · cases s · exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩ · exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩ · exact ⟨⟨fun _ _ ↦ hret, fun _ _ ↦ hret⟩, fun _ _ ↦ hgo⟩ · unfold TM1.SupportsStmt TM2to1.tr exact ⟨IH₁, fun _ _ ↦ hret⟩ · exact IH₂ _ h · intro _ _ IH ss' sub -- load unfold TM2to1.trStmts₁ at sub ⊢ exact IH ss' sub · intro _ _ _ IH₁ IH₂ ss' sub -- branch unfold TM2to1.trStmts₁ at sub obtain ⟨IH₁₁, IH₁₂⟩ := IH₁ ss'.1 fun x hx ↦ sub x <| Finset.mem_union_left _ hx obtain ⟨IH₂₁, IH₂₂⟩ := IH₂ ss'.2 fun x hx ↦ sub x <| Finset.mem_union_right _ hx refine ⟨⟨IH₁₁, IH₂₁⟩, fun l h ↦ ?_⟩ rw [trStmts₁] at h rcases Finset.mem_union.1 h with (h | h) <;> [exact IH₁₂ _ h; exact IH₂₂ _ h] · intro _ ss' _ -- goto simp only [trStmts₁, Finset.not_mem_empty]; refine ⟨?_, fun _ ↦ False.elim⟩ exact fun _ v ↦ Finset.mem_biUnion.2 ⟨_, ss' v, Finset.mem_insert_self _ _⟩ · intro _ _ -- halt simp only [trStmts₁, Finset.not_mem_empty] exact ⟨trivial, fun _ ↦ False.elim⟩⟩ end end TM2to1 end Turing
Mathlib/Computability/TuringMachine.lean
1,546
1,588
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.ToSquareZero import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.IsTensorProduct import Mathlib.RingTheory.EssentialFiniteness import Mathlib.Algebra.Exact import Mathlib.LinearAlgebra.TensorProduct.RightExactness /-! # The module of kaehler differentials ## Main results - `KaehlerDifferential`: The module of kaehler differentials. For an `R`-algebra `S`, we provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. - `KaehlerDifferential.D`: The derivation into the module of kaehler differentials. - `KaehlerDifferential.span_range_derivation`: The image of `D` spans `Ω[S⁄R]` as an `S`-module. - `KaehlerDifferential.linearMapEquivDerivation`: The isomorphism `Hom_R(Ω[S⁄R], M) ≃ₗ[S] Der_R(S, M)`. - `KaehlerDifferential.quotKerTotalEquiv`: An alternative description of `Ω[S⁄R]` as `S` copies of `S` with kernel (`KaehlerDifferential.kerTotal`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` - `KaehlerDifferential.map`: Given a map between the arrows `R →+* A` and `S →+* B`, we have an `A`-linear map `Ω[A⁄R] → Ω[B⁄S]`. - `KaehlerDifferential.map_surjective`: The sequence `Ω[B⁄R] → Ω[B⁄A] → 0` is exact. - `KaehlerDifferential.exact_mapBaseChange_map`: The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A]` is exact. - `KaehlerDifferential.exact_kerCotangentToTensor_mapBaseChange`: If `A → B` is surjective with kernel `I`, then the sequence `I/I² → B ⊗[A] Ω[A⁄R] → Ω[B⁄R]` is exact. - `KaehlerDifferential.mapBaseChange_surjective`: If `A → B` is surjective, then the sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → 0` is exact. ## Future project - Define the `IsKaehlerDifferential` predicate. -/ suppress_compilation section KaehlerDifferential open scoped TensorProduct open Algebra Finsupp universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- The kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ abbrev KaehlerDifferential.ideal : Ideal (S ⊗[R] S) := RingHom.ker (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) variable {S} theorem KaehlerDifferential.one_smul_sub_smul_one_mem_ideal (a : S) : (1 : S) ⊗ₜ[R] a - a ⊗ₜ[R] (1 : S) ∈ KaehlerDifferential.ideal R S := by simp [RingHom.mem_ker] variable {R} variable {M : Type*} [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] /-- For a `R`-derivation `S → M`, this is the map `S ⊗[R] S →ₗ[S] M` sending `s ⊗ₜ t ↦ s • D t`. -/ def Derivation.tensorProductTo (D : Derivation R S M) : S ⊗[R] S →ₗ[S] M := TensorProduct.AlgebraTensorModule.lift ((LinearMap.lsmul S (S →ₗ[R] M)).flip D.toLinearMap) theorem Derivation.tensorProductTo_tmul (D : Derivation R S M) (s t : S) : D.tensorProductTo (s ⊗ₜ t) = s • D t := rfl theorem Derivation.tensorProductTo_mul (D : Derivation R S M) (x y : S ⊗[R] S) : D.tensorProductTo (x * y) = TensorProduct.lmul' (S := S) R x • D.tensorProductTo y + TensorProduct.lmul' (S := S) R y • D.tensorProductTo x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [zero_mul, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [add_mul, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x₁ x₂ refine TensorProduct.induction_on y ?_ ?_ ?_ · rw [mul_zero, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [mul_add, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x y simp only [TensorProduct.tmul_mul_tmul, Derivation.tensorProductTo, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul', TensorProduct.lmul'_apply_tmul] dsimp rw [D.leibniz] simp only [smul_smul, smul_add, mul_comm (x * y) x₁, mul_right_comm x₁ x₂, ← mul_assoc] variable (R S) /-- The kernel of `S ⊗[R] S →ₐ[R] S` is generated by `1 ⊗ s - s ⊗ 1` as a `S`-module. -/ theorem KaehlerDifferential.submodule_span_range_eq_ideal : Submodule.span S (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = (KaehlerDifferential.ideal R S).restrictScalars S := by apply le_antisymm · rw [Submodule.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · rintro x (hx : _ = _) have : x - TensorProduct.lmul' (S := S) R x ⊗ₜ[R] (1 : S) = x := by rw [hx, TensorProduct.zero_tmul, sub_zero] rw [← this] clear this hx refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [map_zero, TensorProduct.zero_tmul, sub_zero]; exact zero_mem _ · intro x y have : x ⊗ₜ[R] y - (x * y) ⊗ₜ[R] (1 : S) = x • ((1 : S) ⊗ₜ y - y ⊗ₜ (1 : S)) := by simp_rw [smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] rw [TensorProduct.lmul'_apply_tmul, this] refine Submodule.smul_mem _ x ?_ apply Submodule.subset_span exact Set.mem_range_self y · intro x y hx hy rw [map_add, TensorProduct.add_tmul, ← sub_add_sub_comm] exact add_mem hx hy theorem KaehlerDifferential.span_range_eq_ideal : Ideal.span (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = KaehlerDifferential.ideal R S := by apply le_antisymm · rw [Ideal.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · change (KaehlerDifferential.ideal R S).restrictScalars S ≤ (Ideal.span _).restrictScalars S rw [← KaehlerDifferential.submodule_span_range_eq_ideal, Ideal.span] conv_rhs => rw [← Submodule.span_span_of_tower S] exact Submodule.subset_span /-- The module of Kähler differentials (Kahler differentials, Kaehler differentials). This is implemented as `I / I ^ 2` with `I` the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. To view elements as a linear combination of the form `s • D s'`, use `KaehlerDifferential.tensorProductTo_surjective` and `Derivation.tensorProductTo_tmul`. We also provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. -/ def KaehlerDifferential : Type v := (KaehlerDifferential.ideal R S).Cotangent instance : AddCommGroup (KaehlerDifferential R S) := inferInstanceAs <| AddCommGroup (KaehlerDifferential.ideal R S).Cotangent instance KaehlerDifferential.module : Module (S ⊗[R] S) (KaehlerDifferential R S) := Ideal.Cotangent.moduleOfTower _ @[inherit_doc KaehlerDifferential] notation:100 "Ω[" S "⁄" R "]" => KaehlerDifferential R S instance : Nonempty (Ω[S⁄R]) := ⟨0⟩ instance KaehlerDifferential.module' {R' : Type*} [CommRing R'] [Algebra R' S] [SMulCommClass R R' S] : Module R' (Ω[S⁄R]) := Submodule.Quotient.module' _ instance : IsScalarTower S (S ⊗[R] S) (Ω[S⁄R]) := Ideal.Cotangent.isScalarTower _ instance KaehlerDifferential.isScalarTower_of_tower {R₁ R₂ : Type*} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [SMul R₁ R₂] [SMulCommClass R R₁ S] [SMulCommClass R R₂ S] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ instance KaehlerDifferential.isScalarTower' : IsScalarTower R (S ⊗[R] S) (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ /-- The quotient map `I → Ω[S⁄R]` with `I` being the kernel of `S ⊗[R] S → S`. -/ def KaehlerDifferential.fromIdeal : KaehlerDifferential.ideal R S →ₗ[S ⊗[R] S] Ω[S⁄R] := (KaehlerDifferential.ideal R S).toCotangent /-- (Implementation) The underlying linear map of the derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.DLinearMap : S →ₗ[R] Ω[S⁄R] := ((KaehlerDifferential.fromIdeal R S).restrictScalars R).comp ((TensorProduct.includeRight.toLinearMap - TensorProduct.includeLeft.toLinearMap : S →ₗ[R] S ⊗[R] S).codRestrict ((KaehlerDifferential.ideal R S).restrictScalars R) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R) : _ →ₗ[R] _) theorem KaehlerDifferential.DLinearMap_apply (s : S) : KaehlerDifferential.DLinearMap R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl /-- The universal derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.D : Derivation R S (Ω[S⁄R]) := { toLinearMap := KaehlerDifferential.DLinearMap R S map_one_eq_zero' := by dsimp [KaehlerDifferential.DLinearMap_apply, Ideal.toCotangent_apply] congr rw [sub_self] leibniz' := fun a b => by have : LinearMap.CompatibleSMul { x // x ∈ ideal R S } (Ω[S⁄R]) S (S ⊗[R] S) := inferInstance dsimp [KaehlerDifferential.DLinearMap_apply] rw [← LinearMap.map_smul_of_tower (ideal R S).toCotangent, ← LinearMap.map_smul_of_tower (ideal R S).toCotangent, ← map_add (ideal R S).toCotangent, Ideal.toCotangent_eq, pow_two] convert Submodule.mul_mem_mul (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R a :) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R b :) using 1 simp only [AddSubgroupClass.coe_sub, Submodule.coe_add, Submodule.coe_mk, TensorProduct.tmul_mul_tmul, mul_sub, sub_mul, mul_comm b, Submodule.coe_smul_of_tower, smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] ring_nf } theorem KaehlerDifferential.D_apply (s : S) : KaehlerDifferential.D R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl theorem KaehlerDifferential.span_range_derivation : Submodule.span S (Set.range <| KaehlerDifferential.D R S) = ⊤ := by rw [_root_.eq_top_iff] rintro x - obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x have : x ∈ (KaehlerDifferential.ideal R S).restrictScalars S := hx rw [← KaehlerDifferential.submodule_span_range_eq_ideal] at this suffices ∃ hx, (KaehlerDifferential.ideal R S).toCotangent ⟨x, hx⟩ ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) by exact this.choose_spec refine Submodule.span_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨x, rfl⟩ refine ⟨KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x, ?_⟩ apply Submodule.subset_span exact ⟨x, KaehlerDifferential.DLinearMap_apply R S x⟩ · exact ⟨zero_mem _, Submodule.zero_mem _⟩ · rintro x y - - ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩; exact ⟨add_mem hx₁ hy₁, Submodule.add_mem _ hx₂ hy₂⟩ · rintro r x - ⟨hx₁, hx₂⟩ exact ⟨((KaehlerDifferential.ideal R S).restrictScalars S).smul_mem r hx₁, Submodule.smul_mem _ r hx₂⟩ /-- `Ω[S⁄R]` is trivial if `R → S` is surjective. Also see `Algebra.FormallyUnramified.iff_subsingleton_kaehlerDifferential`. -/ lemma KaehlerDifferential.subsingleton_of_surjective (h : Function.Surjective (algebraMap R S)) : Subsingleton (Ω[S⁄R]) := by suffices (⊤ : Submodule S (Ω[S⁄R])) ≤ ⊥ from (subsingleton_iff_forall_eq 0).mpr fun y ↦ this trivial rw [← KaehlerDifferential.span_range_derivation, Submodule.span_le] rintro _ ⟨x, rfl⟩; obtain ⟨x, rfl⟩ := h x; simp variable {R S} /-- The linear map from `Ω[S⁄R]`, associated with a derivation. -/ def Derivation.liftKaehlerDifferential (D : Derivation R S M) : Ω[S⁄R] →ₗ[S] M := by refine LinearMap.comp ((((KaehlerDifferential.ideal R S) • (⊤ : Submodule (S ⊗[R] S) (KaehlerDifferential.ideal R S))).restrictScalars S).liftQ ?_ ?_) (Submodule.Quotient.restrictScalarsEquiv S _).symm.toLinearMap · exact D.tensorProductTo.comp ((KaehlerDifferential.ideal R S).subtype.restrictScalars S) · intro x hx rw [LinearMap.mem_ker] refine Submodule.smul_induction_on ((Submodule.restrictScalars_mem _ _ _).mp hx) ?_ ?_ · rintro x hx y - rw [RingHom.mem_ker] at hx dsimp rw [Derivation.tensorProductTo_mul, hx, y.prop, zero_smul, zero_smul, zero_add] · intro x y ex ey; rw [map_add, ex, ey, zero_add] theorem Derivation.liftKaehlerDifferential_apply (D : Derivation R S M) (x) : D.liftKaehlerDifferential ((KaehlerDifferential.ideal R S).toCotangent x) = D.tensorProductTo x := rfl theorem Derivation.liftKaehlerDifferential_comp (D : Derivation R S M) : D.liftKaehlerDifferential.compDer (KaehlerDifferential.D R S) = D := by ext a dsimp [KaehlerDifferential.D_apply] refine (D.liftKaehlerDifferential_apply _).trans ?_ rw [Subtype.coe_mk, map_sub, Derivation.tensorProductTo_tmul, Derivation.tensorProductTo_tmul, one_smul, D.map_one_eq_zero, smul_zero, sub_zero] @[simp] theorem Derivation.liftKaehlerDifferential_comp_D (D' : Derivation R S M) (x : S) : D'.liftKaehlerDifferential (KaehlerDifferential.D R S x) = D' x := Derivation.congr_fun D'.liftKaehlerDifferential_comp x @[ext] theorem Derivation.liftKaehlerDifferential_unique (f f' : Ω[S⁄R] →ₗ[S] M) (hf : f.compDer (KaehlerDifferential.D R S) = f'.compDer (KaehlerDifferential.D R S)) : f = f' := by apply LinearMap.ext intro x have : x ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) := by rw [KaehlerDifferential.span_range_derivation]; trivial refine Submodule.span_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨x, rfl⟩; exact congr_arg (fun D : Derivation R S M => D x) hf · rw [map_zero, map_zero] · intro x y _ _ hx hy; rw [map_add, map_add, hx, hy] · intro a x _ e; simp [e] variable (R S) theorem Derivation.liftKaehlerDifferential_D : (KaehlerDifferential.D R S).liftKaehlerDifferential = LinearMap.id := Derivation.liftKaehlerDifferential_unique _ _ (KaehlerDifferential.D R S).liftKaehlerDifferential_comp variable {R S} theorem KaehlerDifferential.D_tensorProductTo (x : KaehlerDifferential.ideal R S) : (KaehlerDifferential.D R S).tensorProductTo x = (KaehlerDifferential.ideal R S).toCotangent x := by rw [← Derivation.liftKaehlerDifferential_apply, Derivation.liftKaehlerDifferential_D] rfl variable (R S) theorem KaehlerDifferential.tensorProductTo_surjective : Function.Surjective (KaehlerDifferential.D R S).tensorProductTo := by intro x; obtain ⟨x, rfl⟩ := (KaehlerDifferential.ideal R S).toCotangent_surjective x exact ⟨x, KaehlerDifferential.D_tensorProductTo x⟩ /-- The `S`-linear maps from `Ω[S⁄R]` to `M` are (`S`-linearly) equivalent to `R`-derivations from `S` to `M`. -/ @[simps! symm_apply apply_apply] def KaehlerDifferential.linearMapEquivDerivation : (Ω[S⁄R] →ₗ[S] M) ≃ₗ[S] Derivation R S M := { Derivation.llcomp.flip <| KaehlerDifferential.D R S with invFun := Derivation.liftKaehlerDifferential left_inv := fun _ => Derivation.liftKaehlerDifferential_unique _ _ (Derivation.liftKaehlerDifferential_comp _) right_inv := Derivation.liftKaehlerDifferential_comp } /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S`. -/ def KaehlerDifferential.quotientCotangentIdealRingEquiv : (S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal ≃+* S := by have : Function.RightInverse (TensorProduct.includeLeft (R := R) (S := R) (A := S) (B := S)) (↑(TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) : S ⊗[R] S →+* S) := by intro x; rw [AlgHom.coe_toRingHom, ← AlgHom.comp_apply, TensorProduct.lmul'_comp_includeLeft] rfl refine (Ideal.quotCotangent _).trans ?_ refine (Ideal.quotEquivOfEq ?_).trans (RingHom.quotientKerEquivOfRightInverse this) ext; rfl /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S` as an `S`-algebra. -/ def KaehlerDifferential.quotientCotangentIdeal : ((S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal) ≃ₐ[S] S := { KaehlerDifferential.quotientCotangentIdealRingEquiv R S with commutes' := (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).apply_symm_apply } theorem KaehlerDifferential.End_equiv_aux (f : S →ₐ[R] S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) : (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ ↔ (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S := by rw [AlgHom.ext_iff, AlgHom.ext_iff] apply forall_congr' intro x have e₁ : (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift (f x) = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (Ideal.Quotient.mk (KaehlerDifferential.ideal R S).cotangentIdeal <| f x) := by generalize f x = y; obtain ⟨y, rfl⟩ := Ideal.Quotient.mk_surjective y; rfl have e₂ : x = KaehlerDifferential.quotientCotangentIdealRingEquiv R S (IsScalarTower.toAlgHom R S _ x) := (mul_one x).symm constructor · intro e exact (e₁.trans (@RingEquiv.congr_arg _ _ _ _ _ _ (KaehlerDifferential.quotientCotangentIdealRingEquiv R S) _ _ e)).trans e₂.symm · intro e; apply (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).injective exact e₁.symm.trans (e.trans e₂) /- Note: Lean is slow to synthesize these instances (times out). Without them the endEquivDerivation' and endEquivAuxEquiv both have significant timeouts. In Mathlib 3, it was slow but not this slow. -/ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance smul_SSmod_SSmod : SMul (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Mul.toSMul _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_S_right : IsScalarTower S (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_R_right : IsScalarTower R (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ @[nolint defLemma] local instance isScalarTower_SS_right : IsScalarTower (S ⊗[R] S) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) (S ⊗[R] S ⧸ KaehlerDifferential.ideal R S ^ 2) := Ideal.Quotient.isScalarTower_right /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instS : Module S (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instR : Module R (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- A shortcut instance to prevent timing out. Hopefully to be removed in the future. -/ local instance instSS : Module (S ⊗[R] S) (KaehlerDifferential.ideal R S).cotangentIdeal := Submodule.module' _ /-- Derivations into `Ω[S⁄R]` is equivalent to derivations into `(KaehlerDifferential.ideal R S).cotangentIdeal`. -/ noncomputable def KaehlerDifferential.endEquivDerivation' : Derivation R S (Ω[S⁄R]) ≃ₗ[R] Derivation R S (ideal R S).cotangentIdeal := LinearEquiv.compDer ((KaehlerDifferential.ideal R S).cotangentEquivIdeal.restrictScalars S) /-- (Implementation) An `Equiv` version of `KaehlerDifferential.End_equiv_aux`. Used in `KaehlerDifferential.endEquiv`. -/ def KaehlerDifferential.endEquivAuxEquiv : { f // (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ } ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (Equiv.refl _).subtypeEquiv (KaehlerDifferential.End_equiv_aux R S) /-- The endomorphisms of `Ω[S⁄R]` corresponds to sections of the surjection `S ⊗[R] S ⧸ J ^ 2 →ₐ[R] S`, with `J` being the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ noncomputable def KaehlerDifferential.endEquiv : Module.End S (Ω[S⁄R]) ≃ { f // (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S } := (KaehlerDifferential.linearMapEquivDerivation R S).toEquiv.trans <| (KaehlerDifferential.endEquivDerivation' R S).toEquiv.trans <| (derivationToSquareZeroEquivLift (KaehlerDifferential.ideal R S).cotangentIdeal (KaehlerDifferential.ideal R S).cotangentIdeal_square).trans <| KaehlerDifferential.endEquivAuxEquiv R S section Finiteness theorem KaehlerDifferential.ideal_fg [EssFiniteType R S] : (KaehlerDifferential.ideal R S).FG := by classical use (EssFiniteType.finset R S).image (fun s ↦ (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) apply le_antisymm · rw [Finset.coe_image, Ideal.span_le] rintro _ ⟨x, _, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x · rw [← KaehlerDifferential.span_range_eq_ideal, Ideal.span_le] rintro _ ⟨x, rfl⟩ let I : Ideal (S ⊗[R] S) := Ideal.span ((EssFiniteType.finset R S).image (fun s ↦ (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S))) show _ - _ ∈ I have : (IsScalarTower.toAlgHom R (S ⊗[R] S) (S ⊗[R] S ⧸ I)).comp TensorProduct.includeRight = (IsScalarTower.toAlgHom R (S ⊗[R] S) (S ⊗[R] S ⧸ I)).comp TensorProduct.includeLeft := by apply EssFiniteType.algHom_ext intro a ha simp only [AlgHom.coe_comp, IsScalarTower.coe_toAlgHom', Ideal.Quotient.algebraMap_eq, Function.comp_apply, TensorProduct.includeLeft_apply, TensorProduct.includeRight_apply, Ideal.Quotient.mk_eq_mk_iff_sub_mem] refine Ideal.subset_span ?_ simp only [Finset.coe_image, Set.mem_image, Finset.mem_coe] exact ⟨a, ha, rfl⟩ simpa [Ideal.Quotient.mk_eq_mk_iff_sub_mem] using AlgHom.congr_fun this x instance KaehlerDifferential.finite [EssFiniteType R S] : Module.Finite S (Ω[S⁄R]) := by classical let s := (EssFiniteType.finset R S).image (fun s ↦ D R S s) refine ⟨⟨s, top_le_iff.mp ?_⟩⟩ rw [← span_range_derivation, Submodule.span_le] rintro _ ⟨x, rfl⟩ have : ∀ x ∈ adjoin R (EssFiniteType.finset R S).toSet, .D _ _ x ∈ Submodule.span S s.toSet := by intro x hx refine adjoin_induction ?_ ?_ ?_ ?_ hx · exact fun x hx ↦ Submodule.subset_span (Finset.mem_image_of_mem _ hx) · simp · exact fun x y _ _ hx hy ↦ (D R S).map_add x y ▸ add_mem hx hy · intro x y _ _ hx hy simp only [Derivation.leibniz] exact add_mem (Submodule.smul_mem _ _ hy) (Submodule.smul_mem _ _ hx) obtain ⟨t, ht, ht', hxt⟩ := (essFiniteType_cond_iff R S (EssFiniteType.finset R S)).mp EssFiniteType.cond.choose_spec x rw [show D R S x = ht'.unit⁻¹ • (D R S (x * t) - x • D R S t) by simp [smul_smul, Units.smul_def]] exact Submodule.smul_mem _ _ (sub_mem (this _ hxt) (Submodule.smul_mem _ _ (this _ ht))) end Finiteness section Presentation open KaehlerDifferential (D) open Finsupp (single) /-- The `S`-submodule of `S →₀ S` (the direct sum of copies of `S` indexed by `S`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` where `db` is the unit in the copy of `S` with index `b`. This is the kernel of the surjection `Finsupp.linearCombination S Ω[S⁄R] S (KaehlerDifferential.D R S)`. See `KaehlerDifferential.kerTotal_eq` and `KaehlerDifferential.linearCombination_surjective`. -/ noncomputable def KaehlerDifferential.kerTotal : Submodule S (S →₀ S) := Submodule.span S (((Set.range fun x : S × S => single x.1 1 + single x.2 1 - single (x.1 + x.2) 1) ∪ Set.range fun x : S × S => single x.2 x.1 + single x.1 x.2 - single (x.1 * x.2) 1) ∪ Set.range fun x : R => single (algebraMap R S x) 1) unsuppress_compilation in -- Porting note: was `local notation x "𝖣" y => (KaehlerDifferential.kerTotal R S).mkQ (single y x)` -- but not having `DFunLike.coe` leads to `kerTotal_mkQ_single_smul` failing. local notation3 x "𝖣" y => DFunLike.coe (KaehlerDifferential.kerTotal R S).mkQ (single y x) theorem KaehlerDifferential.kerTotal_mkQ_single_add (x y z) : (z𝖣x + y) = (z𝖣x) + z𝖣y := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inl <| ⟨⟨_, _⟩, rfl⟩)) theorem KaehlerDifferential.kerTotal_mkQ_single_mul (x y z) : (z𝖣x * y) = ((z * x)𝖣y) + (z * y)𝖣x := by rw [← map_add, eq_comm, ← sub_eq_zero, ← map_sub (Submodule.mkQ (kerTotal R S)), Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero] simp_rw [← Finsupp.smul_single_one _ z, ← @smul_eq_mul _ _ z, ← Finsupp.smul_single, ← smul_add, ← smul_sub] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inl <| Or.inr <| ⟨⟨_, _⟩, rfl⟩)) theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap (x y) : (y𝖣algebraMap R S x) = 0 := by rw [Submodule.mkQ_apply, Submodule.Quotient.mk_eq_zero, ← Finsupp.smul_single_one _ y] exact Submodule.smul_mem _ _ (Submodule.subset_span (Or.inr <| ⟨_, rfl⟩)) theorem KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one (x) : (x𝖣1) = 0 := by rw [← (algebraMap R S).map_one, KaehlerDifferential.kerTotal_mkQ_single_algebraMap] theorem KaehlerDifferential.kerTotal_mkQ_single_smul (r : R) (x y) : (y𝖣r • x) = r • y𝖣x := by letI : SMulZeroClass R S := inferInstance rw [Algebra.smul_def, KaehlerDifferential.kerTotal_mkQ_single_mul, KaehlerDifferential.kerTotal_mkQ_single_algebraMap, add_zero, ← LinearMap.map_smul_of_tower, Finsupp.smul_single, mul_comm, Algebra.smul_def] /-- The (universal) derivation into `(S →₀ S) ⧸ KaehlerDifferential.kerTotal R S`. -/ noncomputable def KaehlerDifferential.derivationQuotKerTotal : Derivation R S ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) where toFun x := 1𝖣x map_add' _ _ := KaehlerDifferential.kerTotal_mkQ_single_add _ _ _ _ _ map_smul' _ _ := KaehlerDifferential.kerTotal_mkQ_single_smul _ _ _ _ _ map_one_eq_zero' := KaehlerDifferential.kerTotal_mkQ_single_algebraMap_one _ _ _ leibniz' a b := (KaehlerDifferential.kerTotal_mkQ_single_mul _ _ _ _ _).trans (by simp_rw [← Finsupp.smul_single_one _ (1 * _ : S)]; dsimp; simp) theorem KaehlerDifferential.derivationQuotKerTotal_apply (x) : KaehlerDifferential.derivationQuotKerTotal R S x = 1𝖣x := rfl theorem KaehlerDifferential.derivationQuotKerTotal_lift_comp_linearCombination : (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential.comp (Finsupp.linearCombination S (KaehlerDifferential.D R S)) = Submodule.mkQ _ := by apply Finsupp.lhom_ext intro a b conv_rhs => rw [← Finsupp.smul_single_one a b, LinearMap.map_smul] simp [KaehlerDifferential.derivationQuotKerTotal_apply] theorem KaehlerDifferential.kerTotal_eq : LinearMap.ker (Finsupp.linearCombination S (KaehlerDifferential.D R S)) = KaehlerDifferential.kerTotal R S := by apply le_antisymm · conv_rhs => rw [← (KaehlerDifferential.kerTotal R S).ker_mkQ] rw [← KaehlerDifferential.derivationQuotKerTotal_lift_comp_linearCombination] exact LinearMap.ker_le_ker_comp _ _ · rw [KaehlerDifferential.kerTotal, Submodule.span_le] rintro _ ((⟨⟨x, y⟩, rfl⟩ | ⟨⟨x, y⟩, rfl⟩) | ⟨x, rfl⟩) <;> dsimp <;> simp [LinearMap.mem_ker] theorem KaehlerDifferential.linearCombination_surjective : Function.Surjective (Finsupp.linearCombination S (KaehlerDifferential.D R S)) := by rw [← LinearMap.range_eq_top, range_linearCombination, span_range_derivation] /-- `Ω[S⁄R]` is isomorphic to `S` copies of `S` with kernel `KaehlerDifferential.kerTotal`. -/ @[simps!] noncomputable def KaehlerDifferential.quotKerTotalEquiv : ((S →₀ S) ⧸ KaehlerDifferential.kerTotal R S) ≃ₗ[S] Ω[S⁄R] := { (KaehlerDifferential.kerTotal R S).liftQ (Finsupp.linearCombination S (KaehlerDifferential.D R S)) (KaehlerDifferential.kerTotal_eq R S).ge with invFun := (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential left_inv := by intro x obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x exact LinearMap.congr_fun (KaehlerDifferential.derivationQuotKerTotal_lift_comp_linearCombination R S :) x right_inv := by intro x obtain ⟨x, rfl⟩ := KaehlerDifferential.linearCombination_surjective R S x have := LinearMap.congr_fun (KaehlerDifferential.derivationQuotKerTotal_lift_comp_linearCombination R S) x rw [LinearMap.comp_apply] at this rw [this] rfl } theorem KaehlerDifferential.quotKerTotalEquiv_symm_comp_D : (KaehlerDifferential.quotKerTotalEquiv R S).symm.toLinearMap.compDer (KaehlerDifferential.D R S) = KaehlerDifferential.derivationQuotKerTotal R S := by convert (KaehlerDifferential.derivationQuotKerTotal R S).liftKaehlerDifferential_comp end Presentation section ExactSequence /- We have the commutative diagram ``` A --→ B ↑ ↑ | | R --→ S ``` -/ variable (A B : Type*) [CommRing A] [CommRing B] [Algebra R A] variable [Algebra A B] [Algebra S B] unsuppress_compilation in -- The map `(A →₀ A) →ₗ[A] (B →₀ B)` local macro "finsupp_map" : term => `((Finsupp.mapRange.linearMap (Algebra.linearMap A B)).comp (Finsupp.lmapDomain A A (algebraMap A B))) /-- Given the commutative diagram ``` A --→ B ↑ ↑ | | R --→ S ``` The kernel of the presentation `⊕ₓ B dx ↠ Ω_{B/S}` is spanned by the image of the kernel of `⊕ₓ A dx ↠ Ω_{A/R}` and all `ds` with `s : S`. See `kerTotal_map'` for the special case where `R = S`. -/ theorem KaehlerDifferential.kerTotal_map [Algebra R B] [IsScalarTower R A B] [IsScalarTower R S B] (h : Function.Surjective (algebraMap A B)) : (KaehlerDifferential.kerTotal R A).map finsupp_map ⊔ Submodule.span A (Set.range fun x : S => .single (algebraMap S B x) (1 : B)) = (KaehlerDifferential.kerTotal S B).restrictScalars _ := by rw [KaehlerDifferential.kerTotal, Submodule.map_span, KaehlerDifferential.kerTotal, Submodule.restrictScalars_span _ _ h] simp_rw [Set.image_union, Submodule.span_union, ← Set.image_univ, Set.image_image, Set.image_univ, map_sub, map_add] simp only [LinearMap.comp_apply, Finsupp.lmapDomain_apply, Finsupp.mapDomain_single, Finsupp.mapRange.linearMap_apply, Finsupp.mapRange_single, Algebra.linearMap_apply, map_one, map_add, map_mul] simp_rw [sup_assoc, ← (h.prodMap h).range_comp] congr! -- Porting note: new simp_rw [← IsScalarTower.algebraMap_apply R A B] rw [sup_eq_right] apply Submodule.span_mono simp_rw [IsScalarTower.algebraMap_apply R S B] exact Set.range_comp_subset_range (algebraMap R S) fun x => Finsupp.single (algebraMap S B x) (1 : B) /-- This is a special case of `kerTotal_map` where `R = S`. The kernel of the presentation `⊕ₓ B dx ↠ Ω_{B/R}` is spanned by the image of the kernel of `⊕ₓ A dx ↠ Ω_{A/R}` and all `da` with `a : A`. -/ theorem KaehlerDifferential.kerTotal_map' [Algebra R B] [IsScalarTower R A B] (h : Function.Surjective (algebraMap A B)) : (KaehlerDifferential.kerTotal R A ⊔ Submodule.span A (Set.range fun x ↦ .single (algebraMap R A x) 1)).map finsupp_map = (KaehlerDifferential.kerTotal R B).restrictScalars _ := by rw [Submodule.map_sup, ← kerTotal_map R R A B h, Submodule.map_span, ← Set.range_comp] congr refine congr_arg Set.range ?_ ext; simp [IsScalarTower.algebraMap_eq R A B] section variable [Algebra R B] [IsScalarTower R A B] [IsScalarTower R S B] [SMulCommClass S A B] /-- The map `Ω[A⁄R] →ₗ[A] Ω[B⁄S]` given a square ``` A --→ B ↑ ↑ | | R --→ S ``` -/ def KaehlerDifferential.map : Ω[A⁄R] →ₗ[A] Ω[B⁄S] := Derivation.liftKaehlerDifferential (((KaehlerDifferential.D S B).restrictScalars R).compAlgebraMap A) theorem KaehlerDifferential.map_compDer : (KaehlerDifferential.map R S A B).compDer (KaehlerDifferential.D R A) = ((KaehlerDifferential.D S B).restrictScalars R).compAlgebraMap A := Derivation.liftKaehlerDifferential_comp _ @[simp] theorem KaehlerDifferential.map_D (x : A) : KaehlerDifferential.map R S A B (KaehlerDifferential.D R A x) = KaehlerDifferential.D S B (algebraMap A B x) := Derivation.congr_fun (KaehlerDifferential.map_compDer R S A B) x theorem KaehlerDifferential.ker_map : LinearMap.ker (KaehlerDifferential.map R S A B) = (((kerTotal S B).restrictScalars A).comap finsupp_map).map (Finsupp.linearCombination (M := Ω[A⁄R]) A (D R A)) := by rw [← Submodule.map_comap_eq_of_surjective (linearCombination_surjective R A) (LinearMap.ker _)] congr 1 ext x simp only [Submodule.mem_comap, LinearMap.mem_ker, Finsupp.apply_linearCombination, ← kerTotal_eq, Submodule.restrictScalars_mem] simp only [linearCombination_apply, Function.comp_apply, LinearMap.coe_comp, lmapDomain_apply, Finsupp.mapRange.linearMap_apply] rw [Finsupp.sum_mapRange_index, Finsupp.sum_mapDomain_index] · simp [ofId] · simp · simp [add_smul] · simp lemma KaehlerDifferential.ker_map_of_surjective (h : Function.Surjective (algebraMap A B)) : LinearMap.ker (map R R A B) = (LinearMap.ker finsupp_map).map (Finsupp.linearCombination A (D R A)) := by rw [ker_map, ← kerTotal_map' R A B h, Submodule.comap_map_eq, Submodule.map_sup, Submodule.map_sup, ← kerTotal_eq, ← Submodule.comap_bot, Submodule.map_comap_eq_of_surjective (linearCombination_surjective _ _), bot_sup_eq, Submodule.map_span, ← Set.range_comp] convert bot_sup_eq _ rw [Submodule.span_eq_bot]; simp open IsScalarTower (toAlgHom) theorem KaehlerDifferential.map_surjective_of_surjective (h : Function.Surjective (algebraMap A B)) : Function.Surjective (KaehlerDifferential.map R S A B) := by rw [← LinearMap.range_eq_top, _root_.eq_top_iff, ← @Submodule.restrictScalars_top A B, ← span_range_derivation, Submodule.restrictScalars_span _ _ h, Submodule.span_le] rintro _ ⟨x, rfl⟩ obtain ⟨y, rfl⟩ := h x rw [← KaehlerDifferential.map_D R S A B] exact ⟨_, rfl⟩ theorem KaehlerDifferential.map_surjective : Function.Surjective (KaehlerDifferential.map R S B B) := map_surjective_of_surjective R S B B Function.surjective_id /-- The lift of the map `Ω[A⁄R] →ₗ[A] Ω[B⁄R]` to the base change along `A → B`. This is the first map in the exact sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A] → 0`. -/ noncomputable def KaehlerDifferential.mapBaseChange : B ⊗[A] Ω[A⁄R] →ₗ[B] Ω[B⁄R] := (TensorProduct.isBaseChange A (Ω[A⁄R]) B).lift (KaehlerDifferential.map R R A B) @[simp] theorem KaehlerDifferential.mapBaseChange_tmul (x : B) (y : Ω[A⁄R]) : KaehlerDifferential.mapBaseChange R A B (x ⊗ₜ y) = x • KaehlerDifferential.map R R A B y := by conv_lhs => rw [← mul_one x, ← smul_eq_mul, ← TensorProduct.smul_tmul', LinearMap.map_smul]
congr 1 exact IsBaseChange.lift_eq _ _ _ lemma KaehlerDifferential.range_mapBaseChange : LinearMap.range (mapBaseChange R A B) = LinearMap.ker (map R A B B) := by apply le_antisymm · rintro _ ⟨x, rfl⟩ induction' x with r s · simp · obtain ⟨x, rfl⟩ := linearCombination_surjective _ _ s simp only [mapBaseChange_tmul, LinearMap.mem_ker, map_smul] induction x using Finsupp.induction_linear · simp · simp [smul_add, *] · simp · rw [map_add]; exact add_mem ‹_› ‹_› · convert_to (kerTotal A B).map (Finsupp.linearCombination B (D R B)) ≤ _ · rw [KaehlerDifferential.ker_map] congr 1 convert Submodule.comap_id _ · ext; simp rw [Submodule.map_le_iff_le_comap, kerTotal, Submodule.span_le] rintro f ((⟨⟨x, y⟩, rfl⟩|⟨⟨x, y⟩, rfl⟩)|⟨x, rfl⟩)
Mathlib/RingTheory/Kaehler/Basic.lean
760
782
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Set.Finite.Range import Mathlib.Data.Set.Lattice import Mathlib.Topology.Defs.Filter /-! # Openness and closedness of a set This file provides lemmas relating to the predicates `IsOpen` and `IsClosed` of a set endowed with a topology. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space -/ open Set Filter Topology universe u v /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy section TopologicalSpace variable {X : Type u} {ι : Sort v} {α : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl @[ext (iff := false)] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) (h : ∀ t ∈ s, IsOpen t) : IsOpen (⋂₀ s) := by induction s, hs using Set.Finite.induction_on with | empty => rw [sInter_empty]; exact isOpen_univ | insert _ _ ih => simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h @[simp] theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s :=
⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩
Mathlib/Topology/Basic.lean
115
116
/- 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
Mathlib/Analysis/InnerProductSpace/Basic.lean
893
897
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Module.BigOperators import Mathlib.NumberTheory.Divisors import Mathlib.Data.Nat.Squarefree import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.Factorization.Induction import Mathlib.Tactic.ArithMult /-! # Arithmetic Functions and Dirichlet Convolution This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition, to form the Dirichlet ring. ## Main Definitions * `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`. * An arithmetic function `f` `IsMultiplicative` when `x.Coprime y → f (x * y) = f x * f y`. * The pointwise operations `pmul` and `ppow` differ from the multiplication and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication. * `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`. * `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`. * `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`. * `id` is the identity arithmetic function on `ℕ`. * `ω n` is the number of distinct prime factors of `n`. * `Ω n` is the number of prime factors of `n` counted with multiplicity. * `μ` is the Möbius function (spelled `moebius` in code). ## Main Results * Several forms of Möbius inversion: * `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero` * And variants that apply when the equalities only hold on a set `S : Set ℕ` such that `m ∣ n → n ∈ S → m ∈ S`: * `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero` ## Notation All notation is localized in the namespace `ArithmeticFunction`. The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names. In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`, `ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`, `ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`, to allow for selective access to these notations. The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation `∏ᵖ p ∣ n, f p` when applied to `n`. ## Tags arithmetic functions, dirichlet convolution, divisors -/ open Finset open Nat variable (R : Type*) /-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by Dirichlet convolution. -/ def ArithmeticFunction [Zero R] := ZeroHom ℕ R instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) := inferInstanceAs (Zero (ZeroHom ℕ R)) instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R)) variable {R} namespace ArithmeticFunction section Zero variable [Zero R] instance : FunLike (ArithmeticFunction R) ℕ R := inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R) @[simp] theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl @[simp] theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _ (ZeroHom.mk f hf) = f := rfl @[simp] theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 := ZeroHom.map_zero' f theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g := DFunLike.coe_fn_eq @[simp] theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 := ZeroHom.zero_apply x @[ext] theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g := ZeroHom.ext h section One variable [One R] instance one : One (ArithmeticFunction R) := ⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩ theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 := rfl @[simp] theorem one_one : (1 : ArithmeticFunction R) 1 = 1 := rfl @[simp] theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 := if_neg h end One end Zero /-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline this in `natCoe` because it gets unfolded too much. -/ @[coe] def natToArithmeticFunction [AddMonoidWithOne R] : (ArithmeticFunction ℕ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) := ⟨natToArithmeticFunction⟩ @[simp] theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f := ext fun _ => cast_id _ @[simp] theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl /-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline this in `intCoe` because it gets unfolded too much. -/ @[coe] def ofInt [AddGroupWithOne R] : (ArithmeticFunction ℤ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) := ⟨ofInt⟩ @[simp] theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f := ext fun _ => Int.cast_id @[simp] theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl @[simp] theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} : ((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by ext simp @[simp] theorem natCoe_one [AddMonoidWithOne R] : ((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] @[simp] theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] section AddMonoid variable [AddMonoid R] instance add : Add (ArithmeticFunction R) := ⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩ @[simp] theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n := rfl instance instAddMonoid : AddMonoid (ArithmeticFunction R) := { ArithmeticFunction.zero R, ArithmeticFunction.add with add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _ zero_add := fun _ => ext fun _ => zero_add _ add_zero := fun _ => ext fun _ => add_zero _ nsmul := nsmulRec } end AddMonoid instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid, ArithmeticFunction.one with natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩ natCast_zero := by ext; simp natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] } instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ } instance [NegZeroClass R] : Neg (ArithmeticFunction R) where neg f := ⟨fun n => -f n, by simp⟩ instance [AddGroup R] : AddGroup (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with neg_add_cancel := fun _ => ext fun _ => neg_add_cancel _ zsmul := zsmulRec } instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) := { show AddGroup (ArithmeticFunction R) by infer_instance with add_comm := fun _ _ ↦ add_comm _ _ } section SMul variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M] /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) := ⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩ @[simp] theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} : (f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd := rfl end SMul /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance [Semiring R] : Mul (ArithmeticFunction R) := ⟨(· • ·)⟩ @[simp] theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} : (f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd := rfl theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp @[simp, norm_cast] theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} : (↑(f * g) : ArithmeticFunction R) = f * g := by ext n simp @[simp, norm_cast] theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} : (↑(f * g) : ArithmeticFunction R) = ↑f * g := by ext n simp section Module variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) : (f * g) • h = f • g • h := by ext n simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc) theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by ext x rw [smul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro y ymem ynmem have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff] simp [y1ne] end Module section Semiring variable [Semiring R] instance instMonoid : Monoid (ArithmeticFunction R) := { one := One.one mul := Mul.mul one_mul := one_smul' mul_one := fun f => by ext x rw [mul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro ⟨y₁, y₂⟩ ymem ynmem have y2ne : y₂ ≠ 1 := by intro con simp_all simp [y2ne] mul_assoc := mul_smul' } instance instSemiring : Semiring (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoidWithOne, ArithmeticFunction.instMonoid, ArithmeticFunction.instAddCommMonoid with zero_mul := fun f => by ext simp mul_zero := fun f => by ext simp left_distrib := fun a b c => by ext simp [← sum_add_distrib, mul_add] right_distrib := fun a b c => by ext simp [← sum_add_distrib, add_mul] } end Semiring instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with mul_comm := fun f g => by ext rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map] simp [mul_comm] } instance [CommRing R] : CommRing (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with neg_add_cancel := neg_add_cancel mul_comm := mul_comm zsmul := (· • ·) } instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] : Module (ArithmeticFunction R) (ArithmeticFunction M) where one_smul := one_smul' mul_smul := mul_smul' smul_add r x y := by ext simp only [sum_add_distrib, smul_add, smul_apply, add_apply] smul_zero r := by ext simp only [smul_apply, sum_const_zero, smul_zero, zero_apply] add_smul r s x := by ext simp only [add_smul, sum_add_distrib, smul_apply, add_apply] zero_smul r := by ext simp only [smul_apply, sum_const_zero, zero_smul, zero_apply] section Zeta /-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/ def zeta : ArithmeticFunction ℕ := ⟨fun x => ite (x = 0) 0 1, rfl⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta @[inherit_doc] scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta @[simp] theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 := rfl theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 := if_neg h -- Porting note: removed `@[simp]`, LHS not in normal form theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [MulAction R M] {f : ArithmeticFunction M} {x : ℕ} : ((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by rw [smul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.snd · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul] · rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk] theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (↑ζ * f) x = ∑ i ∈ divisors x, f i := coe_zeta_smul_apply theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by rw [mul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.1 · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one] · rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk] theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by rw [← natCoe_nat ζ, coe_zeta_mul_apply] theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by rw [← natCoe_nat ζ, coe_mul_zeta_apply] end Zeta open ArithmeticFunction section Pmul /-- This is the pointwise product of `ArithmeticFunction`s. -/ def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun x => f x * g x, by simp⟩ @[simp] theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x := rfl theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by ext simp [mul_comm] lemma pmul_assoc [SemigroupWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) : pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by ext simp only [pmul_apply, mul_assoc] section NonAssocSemiring variable [NonAssocSemiring R] @[simp] theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by ext x cases x <;> simp [Nat.succ_ne_zero] @[simp] theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by ext x cases x <;> simp [Nat.succ_ne_zero] end NonAssocSemiring variable [Semiring R] /-- This is the pointwise power of `ArithmeticFunction`s. -/ def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R := if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩ @[simp] theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl] @[simp] theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by rw [ppow, dif_neg (Nat.ne_of_gt kpos), coe_mk] theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ'] induction k <;> simp theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} : f.ppow (k + 1) = (f.ppow k).pmul f := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ] induction k <;> simp end Pmul section Pdiv /-- This is the pointwise division of `ArithmeticFunction`s. -/ def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩ @[simp] theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) : pdiv f g n = f n / g n := rfl /-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/ @[simp] theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) : pdiv f zeta = f := by ext n cases n <;> simp [succ_ne_zero] end Pdiv section ProdPrimeFactors /-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/ def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p map_zero' := if_pos rfl open Batteries.ExtendedBinder /-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/ scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term scoped macro_rules (kind := bigproddvd) | `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n) @[simp] theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) : ∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p := if_neg hn end ProdPrimeFactors /-- Multiplicative functions -/ def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop := f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n namespace IsMultiplicative section MonoidWithZero variable [MonoidWithZero R] @[simp, arith_mult] theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 := h.1 @[simp] theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ} (h : m.Coprime n) : f (m * n) = f m * f n := hf.2 h end MonoidWithZero open scoped Function in -- required for scoped `on` notation theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) : f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by classical induction s using Finset.induction_on with | empty => simp [hf] | insert _ _ has ih => rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1] exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm theorem map_prod_of_prime [CommMonoidWithZero R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy theorem map_prod_of_subset_primeFactors [CommMonoidWithZero R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ) (t : Finset ℕ) (ht : t ⊆ l.primeFactors) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a) theorem map_div_of_coprime [GroupWithZero R] {f : ArithmeticFunction R} (hf : IsMultiplicative f) {l d : ℕ} (hdl : d ∣ l) (hl : (l / d).Coprime d) (hd : f d ≠ 0) : f (l / d) = f l / f d := by apply (div_eq_of_eq_mul hd ..).symm rw [← hf.right hl, Nat.div_mul_cancel hdl] @[arith_mult] theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ @[arith_mult] theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ @[arith_mult] theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by refine ⟨by simp [hf.1, hg.1], ?_⟩ simp only [mul_apply] intro m n cop rw [sum_mul_sum, ← sum_product'] symm apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l) · rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne] constructor · ring rw [Nat.mul_eq_zero] at * apply not_or_intro ha hb · simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk_inj] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h simp only [Prod.mk_inj] at h ext <;> dsimp only · trans Nat.gcd (a1 * a2) (a1 * b1) · rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.1, Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · trans Nat.gcd (a1 * a2) (a2 * b2) · rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a1 * b1) · rw [mul_comm, Nat.gcd_mul_right, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a2 * b2) · rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.2, Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Set.mem_image, exists_prop, Prod.mk_inj] rintro ⟨b1, b2⟩ h dsimp at h use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)) rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _] · rw [Nat.mul_eq_zero, not_or] at h simp [h.2.1, h.2.2] rw [mul_comm n m, h.1] · simp only [mem_divisorsAntidiagonal, Ne, mem_product] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ dsimp only rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right, hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right] ring @[arith_mult] theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) := ⟨by simp [hf, hg], fun {m n} cop => by simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop] ring⟩ @[arith_mult] theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) := ⟨by simp [hf, hg], fun {m n} cop => by simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop, div_eq_mul_inv, mul_inv] apply mul_mul_mul_comm ⟩ /-- For any multiplicative function `f` and any `n > 0`, we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/ theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) : f n = n.factorization.prod fun p k => f (p ^ k) := Nat.multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn /-- A recapitulation of the definition of multiplicative that is simpler for proofs -/ theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} : IsMultiplicative f ↔ f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩) rcases eq_or_ne m 0 with (rfl | hm) · simp rcases eq_or_ne n 0 with (rfl | hn) · simp exact h hm hn hmn /-- Two multiplicative functions `f` and `g` are equal if and only if they agree on prime powers -/ theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) : f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by constructor · intro h p i _ rw [h] intro h ext n by_cases hn : n = 0 · rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero] rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn] exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp) @[arith_mult] theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : IsMultiplicative (prodPrimeFactors f) := by rw [iff_ne_zero] simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one, prod_empty, true_and] intro x y hx hy hxy have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy, Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors] theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) : ∏ᵖ p ∣ n, (f + g) p = (f * g) n := by rw [prodPrimeFactors_apply hn.ne_zero] simp_rw [add_apply (f := f) (g := g)] rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·), ← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero, factors_eq] apply Finset.sum_congr rfl intro t ht rw [t.prod_val, Function.id_def, ← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht), hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht), ← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset] theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} : f (x.lcm y) * f (x.gcd y) = f x * f y := by by_cases hx : x = 0 · simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left] by_cases hy : y = 0 · simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul] have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by intro i; rw [Nat.pow_zero, hf.1] iterate 4 rw [hf.multiplicative_factorization f (by assumption), Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero) (s := (x.primeFactors ∪ y.primeFactors))] · rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib] apply Finset.prod_congr rfl intro p _ rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;> simp only [factorization_lcm hx hy, Finsupp.sup_apply, h, sup_of_le_right, sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply, inf_of_le_left, mul_comm] · apply Finset.subset_union_right · apply Finset.subset_union_left · rw [factorization_gcd hx hy, Finsupp.support_inf] apply Finset.inter_subset_union · simp [factorization_lcm hx hy] theorem map_gcd [CommGroupWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} (hf_lcm : f (x.lcm y) ≠ 0) : f (x.gcd y) = f x * f y / f (x.lcm y) := by rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_left₀ _ hf_lcm] theorem map_lcm [CommGroupWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} (hf_gcd : f (x.gcd y) ≠ 0) : f (x.lcm y) = f x * f y / f (x.gcd y) := by rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_right₀ _ hf_gcd] theorem eq_zero_of_squarefree_of_dvd_eq_zero [MonoidWithZero R] {f : ArithmeticFunction R} (hf : IsMultiplicative f) {m n : ℕ} (hn : Squarefree n) (hmn : m ∣ n) (h_zero : f m = 0) : f n = 0 := by rcases hmn with ⟨k, rfl⟩ simp only [MulZeroClass.zero_mul, eq_self_iff_true, hf.map_mul_of_coprime (coprime_of_squarefree_mul hn), h_zero] end IsMultiplicative section SpecialFunctions /-- The identity on `ℕ` as an `ArithmeticFunction`. -/ def id : ArithmeticFunction ℕ := ⟨_root_.id, rfl⟩ @[simp] theorem id_apply {x : ℕ} : id x = x := rfl /-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/ def pow (k : ℕ) : ArithmeticFunction ℕ := id.ppow k @[simp] theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by cases k <;> simp [pow] theorem pow_zero_eq_zeta : pow 0 = ζ := by ext n simp /-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/ def sigma (k : ℕ) : ArithmeticFunction ℕ := ⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma @[inherit_doc] scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k := rfl theorem sigma_apply_prime_pow {k p i : ℕ} (hp : p.Prime) : σ k (p ^ i) = ∑ j ∈ .range (i + 1), p ^ (j * k) := by simp [sigma_apply, divisors_prime_pow hp, Nat.pow_mul] theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply] theorem sigma_one_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 1 (p ^ i) = ∑ k ∈ .range (i + 1), p ^ k := by simp [sigma_apply_prime_pow hp] theorem sigma_zero_apply (n : ℕ) : σ 0 n = #n.divisors := by simp [sigma_apply] theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by simp [sigma_apply_prime_pow hp] theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by ext rw [sigma, zeta_mul_apply] apply sum_congr rfl intro x hx rw [pow_apply, if_neg (not_and_of_not_right _ _)] contrapose! hx simp [hx] @[arith_mult] theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by intro m n hm _hn hmn rcases eq_or_ne m 1 with (rfl | hm') · simp rw [one_apply_ne, one_apply_ne hm', zero_mul] rw [Ne, mul_eq_one, not_and_or] exact Or.inl hm'⟩ @[arith_mult] theorem isMultiplicative_zeta : IsMultiplicative ζ := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp +contextual⟩ @[arith_mult] theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id := ⟨rfl, fun {_ _} _ => rfl⟩ @[arith_mult] theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {k : ℕ} : IsMultiplicative (f.ppow k) := by induction k with | zero => exact isMultiplicative_zeta.natCast | succ k hi => rw [ppow_succ']; apply hf.pmul hi @[arith_mult] theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) := isMultiplicative_id.ppow @[arith_mult] theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by rw [← zeta_mul_pow_eq_sigma] apply isMultiplicative_zeta.mul isMultiplicative_pow /-- `Ω n` is the number of prime factors of `n`. -/ def cardFactors : ArithmeticFunction ℕ := ⟨fun n => n.primeFactorsList.length, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors @[inherit_doc] scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors theorem cardFactors_apply {n : ℕ} : Ω n = n.primeFactorsList.length := rfl lemma cardFactors_zero : Ω 0 = 0 := by simp @[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply] @[simp] theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by refine ⟨fun h => ?_, fun h => List.length_eq_one_iff.2 ⟨n, primeFactorsList_prime h⟩⟩ cases n with | zero => simp at h | succ n => rcases List.length_eq_one_iff.1 h with ⟨x, hx⟩ rw [← prod_primeFactorsList n.add_one_ne_zero, hx, List.prod_singleton] apply prime_of_mem_primeFactorsList rw [hx, List.mem_singleton] theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq, UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq, Multiset.card_add, Multiset.coe_card, Multiset.coe_card] theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) : Ω s.prod = (Multiset.map Ω s).sum := by induction s using Multiset.induction_on with | empty => simp | cons ih => simp_all [cardFactors_mul, not_or] @[simp] theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 := cardFactors_eq_one_iff_prime.2 hp @[simp] theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by rw [cardFactors_apply, hp.primeFactorsList_pow, List.length_replicate] /-- `ω n` is the number of distinct prime factors of `n`. -/ def cardDistinctFactors : ArithmeticFunction ℕ := ⟨fun n => n.primeFactorsList.dedup.length, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors @[inherit_doc] scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors theorem cardDistinctFactors_zero : ω 0 = 0 := by simp @[simp] theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors] theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.primeFactorsList.dedup.length := rfl theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) : ω n = Ω n ↔ Squarefree n := by rw [squarefree_iff_nodup_primeFactorsList h0, cardDistinctFactors_apply] constructor <;> intro h · rw [← n.primeFactorsList.dedup_sublist.eq_of_length h] apply List.nodup_dedup · simp [h.dedup, cardFactors] @[simp] theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) : ω (p ^ k) = 1 := by rw [cardDistinctFactors_apply, hp.primeFactorsList_pow, List.replicate_dedup hk, List.length_singleton] @[simp] theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero] /-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors, `μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`. If `n` is not squarefree, `μ n = 0`. -/ def moebius : ArithmeticFunction ℤ := ⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius @[inherit_doc] scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius @[simp] theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n := if_pos h @[simp] theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 := if_neg h theorem moebius_apply_one : μ 1 = 1 := by simp theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by constructor <;> intro h · contrapose! h simp [h] · simp [h, pow_ne_zero] theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by simp only [moebius, coe_mk] split_ifs · right exact neg_one_pow_eq_or .. · left rfl theorem moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 := by have := moebius_eq_or n aesop theorem moebius_sq_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : μ l ^ 2 = 1 := by rw [moebius_apply_of_squarefree hl, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow] theorem abs_moebius_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : |μ l| = 1 := by simp only [moebius_apply_of_squarefree hl, abs_pow, abs_neg, abs_one, one_pow] theorem moebius_sq {n : ℕ} : μ n ^ 2 = if Squarefree n then 1 else 0 := by split_ifs with h · exact moebius_sq_eq_one_of_squarefree h · simp only [pow_eq_zero_iff, moebius_eq_zero_of_not_squarefree h, zero_pow (show 2 ≠ 0 by norm_num)] theorem abs_moebius {n : ℕ} : |μ n| = if Squarefree n then 1 else 0 := by split_ifs with h · exact abs_moebius_eq_one_of_squarefree h · simp only [moebius_eq_zero_of_not_squarefree h, abs_zero] theorem abs_moebius_le_one {n : ℕ} : |μ n| ≤ 1 := by rw [abs_moebius, apply_ite (· ≤ 1)] simp theorem moebius_apply_prime {p : ℕ} (hp : p.Prime) : μ p = -1 := by rw [moebius_apply_of_squarefree hp.squarefree, cardFactors_apply_prime hp, pow_one] theorem moebius_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) : μ (p ^ k) = if k = 1 then -1 else 0 := by split_ifs with h · rw [h, pow_one, moebius_apply_prime hp] rw [moebius_eq_zero_of_not_squarefree] rw [squarefree_pow_iff hp.ne_one hk, not_and_or] exact Or.inr h theorem moebius_apply_isPrimePow_not_prime {n : ℕ} (hn : IsPrimePow n) (hn' : ¬n.Prime) : μ n = 0 := by obtain ⟨p, k, hp, hk, rfl⟩ := (isPrimePow_nat_iff _).1 hn rw [moebius_apply_prime_pow hp hk.ne', if_neg] rintro rfl exact hn' (by simpa) @[arith_mult] theorem isMultiplicative_moebius : IsMultiplicative μ := by rw [IsMultiplicative.iff_ne_zero] refine ⟨by simp, fun {n m} hn hm hnm => ?_⟩ simp only [moebius, ZeroHom.coe_mk, coe_mk, ZeroHom.toFun_eq_coe, Eq.ndrec, ZeroHom.coe_mk, IsUnit.mul_iff, Nat.isUnit_iff, squarefree_mul hnm, ite_zero_mul_ite_zero, cardFactors_mul hn hm, pow_add] theorem IsMultiplicative.prodPrimeFactors_one_add_of_squarefree [CommSemiring R] {f : ArithmeticFunction R} (h_mult : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) : ∏ p ∈ n.primeFactors, (1 + f p) = ∑ d ∈ n.divisors, f d := by trans (∏ᵖ p ∣ n, ((ζ : ArithmeticFunction R) + f) p) · simp_rw [prodPrimeFactors_apply hn.ne_zero, add_apply, natCoe_apply] apply Finset.prod_congr rfl; intro p hp rw [zeta_apply_ne (prime_of_mem_primeFactorsList <| List.mem_toFinset.mp hp).ne_zero, cast_one] rw [isMultiplicative_zeta.natCast.prodPrimeFactors_add_of_squarefree h_mult hn, coe_zeta_mul_apply] theorem IsMultiplicative.prodPrimeFactors_one_sub_of_squarefree [CommRing R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) : ∏ p ∈ n.primeFactors, (1 - f p) = ∑ d ∈ n.divisors, μ d * f d := by trans (∏ p ∈ n.primeFactors, (1 + (ArithmeticFunction.pmul (μ : ArithmeticFunction R) f) p)) · apply Finset.prod_congr rfl; intro p hp rw [pmul_apply, intCoe_apply, ArithmeticFunction.moebius_apply_prime (prime_of_mem_primeFactorsList (List.mem_toFinset.mp hp))] ring · rw [(isMultiplicative_moebius.intCast.pmul hf).prodPrimeFactors_one_add_of_squarefree hn] simp_rw [pmul_apply, intCoe_apply] open UniqueFactorizationMonoid @[simp] theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by ext n refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n · intro p n hp hn rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ'] simp_rw [Nat.pow_zero, moebius_apply_one, moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj, sum_ite_eq', mem_range, if_pos hn, neg_add_cancel] rw [one_apply_ne] rw [Ne, pow_eq_one_iff] · exact hp.ne_one · exact hn.ne' · rw [ZeroHom.map_zero, ZeroHom.map_zero] · simp · intro a b _ha _hb hab ha' hb' rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb', IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab] exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast @[simp] theorem coe_zeta_mul_moebius : (ζ * μ : ArithmeticFunction ℤ) = 1 := by rw [mul_comm, moebius_mul_coe_zeta] @[simp] theorem coe_moebius_mul_coe_zeta [Ring R] : (μ * ζ : ArithmeticFunction R) = 1 := by rw [← coe_coe, ← intCoe_mul, moebius_mul_coe_zeta, intCoe_one] @[simp] theorem coe_zeta_mul_coe_moebius [Ring R] : (ζ * μ : ArithmeticFunction R) = 1 := by rw [← coe_coe, ← intCoe_mul, coe_zeta_mul_moebius, intCoe_one] section CommRing variable [CommRing R] instance : Invertible (ζ : ArithmeticFunction R) where invOf := μ invOf_mul_self := coe_moebius_mul_coe_zeta mul_invOf_self := coe_zeta_mul_coe_moebius /-- A unit in `ArithmeticFunction R` that evaluates to `ζ`, with inverse `μ`. -/ def zetaUnit : (ArithmeticFunction R)ˣ := ⟨ζ, μ, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta⟩ @[simp] theorem coe_zetaUnit : ((zetaUnit : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = ζ := rfl @[simp] theorem inv_zetaUnit : ((zetaUnit⁻¹ : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = μ := rfl end CommRing /-- Möbius inversion for functions to an `AddCommGroup`. -/ theorem sum_eq_iff_sum_smul_moebius_eq [AddCommGroup R] {f g : ℕ → R} : (∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔ ∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd = f n := by let f' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else f x, if_pos rfl⟩ let g' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else g x, if_pos rfl⟩ trans (ζ : ArithmeticFunction ℤ) • f' = g' · rw [ArithmeticFunction.ext_iff] apply forall_congr' intro n cases n with | zero => simp | succ n => rw [coe_zeta_smul_apply] simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, ZeroHom.coe_mk] simp only [f', g', coe_mk, succ_ne_zero, ite_false] rw [sum_congr rfl fun x hx => ?_] rw [if_neg (Nat.pos_of_mem_divisors hx).ne'] trans μ • g' = f' · constructor <;> intro h · rw [← h, ← mul_smul, moebius_mul_coe_zeta, one_smul] · rw [← h, ← mul_smul, coe_zeta_mul_moebius, one_smul] · rw [ArithmeticFunction.ext_iff] apply forall_congr' intro n cases n with | zero => simp | succ n => simp only [forall_prop_of_true, succ_pos', smul_apply, f', g', coe_mk, succ_ne_zero, ite_false] rw [sum_congr rfl fun x hx => ?_] simp [if_neg (Nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)).ne'] /-- Möbius inversion for functions to a `Ring`. -/ theorem sum_eq_iff_sum_mul_moebius_eq [NonAssocRing R] {f g : ℕ → R} : (∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔ ∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd = f n := by rw [sum_eq_iff_sum_smul_moebius_eq] apply forall_congr' refine fun a => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left rw [zsmul_eq_mul] /-- Möbius inversion for functions to a `CommGroup`. -/ theorem prod_eq_iff_prod_pow_moebius_eq [CommGroup R] {f g : ℕ → R} : (∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔ ∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n := @sum_eq_iff_sum_smul_moebius_eq (Additive R) _ _ _ /-- Möbius inversion for functions to a `CommGroupWithZero`. -/ theorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [CommGroupWithZero R] {f g : ℕ → R} (hf : ∀ n : ℕ, 0 < n → f n ≠ 0) (hg : ∀ n : ℕ, 0 < n → g n ≠ 0) : (∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔ ∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n := by refine Iff.trans (Iff.trans (forall_congr' fun n => ?_) (@prod_eq_iff_prod_pow_moebius_eq Rˣ _ (fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1) fun n => if h : 0 < n then Units.mk0 (g n) (hg n h) else 1)) (forall_congr' fun n => ?_) <;> refine imp_congr_right fun hn => ?_ · dsimp rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0, prod_congr rfl _] intro x hx rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0] · dsimp rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0, prod_congr rfl _] intro x hx rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)), Units.coeHom_apply, Units.val_zpow_eq_zpow_val, Units.val_mk0] /-- Möbius inversion for functions to an `AddCommGroup`, where the equalities only hold on a
well-behaved set. -/ theorem sum_eq_iff_sum_smul_moebius_eq_on [AddCommGroup R] {f g : ℕ → R}
Mathlib/NumberTheory/ArithmeticFunction.lean
1,191
1,192
/- Copyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Group.Action.Pi import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Fin import Mathlib.Logic.Equiv.Fin.Basic /-! # Big operators and `Fin` Some results about products and sums over the type `Fin`. The most important results are the induction formulas `Fin.prod_univ_castSucc` and `Fin.prod_univ_succ`, and the formula `Fin.prod_const` for the product of a constant function. These results have variants for sums instead of products. ## Main declarations * `finFunctionFinEquiv`: An explicit equivalence between `Fin n → Fin m` and `Fin (m ^ n)`. -/ assert_not_exists Field open Finset variable {α M : Type*} namespace Finset @[to_additive] theorem prod_range [CommMonoid M] {n : ℕ} (f : ℕ → M) : ∏ i ∈ Finset.range n, f i = ∏ i : Fin n, f i := (Fin.prod_univ_eq_prod_range _ _).symm end Finset namespace Fin section CommMonoid variable [CommMonoid M] {n : ℕ} @[to_additive] theorem prod_ofFn (f : Fin n → M) : (List.ofFn f).prod = ∏ i, f i := by simp [prod_eq_multiset_prod] @[to_additive] theorem prod_univ_def (f : Fin n → M) : ∏ i, f i = ((List.finRange n).map f).prod := by rw [← List.ofFn_eq_map, prod_ofFn] /-- A product of a function `f : Fin 0 → M` is `1` because `Fin 0` is empty -/ @[to_additive "A sum of a function `f : Fin 0 → M` is `0` because `Fin 0` is empty"] theorem prod_univ_zero (f : Fin 0 → M) : ∏ i, f i = 1 := rfl /-- A product of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the product of `f x`, for some `x : Fin (n + 1)` times the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the sum of `f x`, for some `x : Fin (n + 1)` plus the remaining sum"] theorem prod_univ_succAbove (f : Fin (n + 1) → M) (x : Fin (n + 1)) : ∏ i, f i = f x * ∏ i : Fin n, f (x.succAbove i) := by rw [univ_succAbove n x, prod_cons, Finset.prod_map, coe_succAboveEmb] /-- A product of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the product of `f 0` plus the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the sum of `f 0` plus the remaining sum"] theorem prod_univ_succ (f : Fin (n + 1) → M) : ∏ i, f i = f 0 * ∏ i : Fin n, f i.succ := prod_univ_succAbove f 0 /-- A product of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the product of `f (Fin.last n)` plus the remaining product -/ @[to_additive "A sum of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the sum of `f (Fin.last n)` plus the remaining sum"] theorem prod_univ_castSucc (f : Fin (n + 1) → M) : ∏ i, f i = (∏ i : Fin n, f (Fin.castSucc i)) * f (last n) := by simpa [mul_comm] using prod_univ_succAbove f (last n) @[to_additive (attr := simp)] theorem prod_univ_getElem (l : List M) : ∏ i : Fin l.length, l[i.1] = l.prod := by simp [Finset.prod_eq_multiset_prod] @[deprecated (since := "2025-04-19")] alias sum_univ_get := sum_univ_getElem @[to_additive existing, deprecated (since := "2025-04-19")] alias prod_univ_get := prod_univ_getElem @[to_additive (attr := simp)] theorem prod_univ_fun_getElem (l : List α) (f : α → M) : ∏ i : Fin l.length, f l[i.1] = (l.map f).prod := by simp [Finset.prod_eq_multiset_prod] @[deprecated (since := "2025-04-19")] alias sum_univ_get' := sum_univ_fun_getElem @[to_additive existing, deprecated (since := "2025-04-19")] alias prod_univ_get' := prod_univ_fun_getElem @[to_additive (attr := simp)] theorem prod_cons (x : M) (f : Fin n → M) : (∏ i : Fin n.succ, (cons x f : Fin n.succ → M) i) = x * ∏ i : Fin n, f i := by simp_rw [prod_univ_succ, cons_zero, cons_succ] @[to_additive (attr := simp)] theorem prod_snoc (x : M) (f : Fin n → M) : (∏ i : Fin n.succ, (snoc f x : Fin n.succ → M) i) = (∏ i : Fin n, f i) * x := by simp [prod_univ_castSucc] @[to_additive sum_univ_one] theorem prod_univ_one (f : Fin 1 → M) : ∏ i, f i = f 0 := by simp @[to_additive (attr := simp)] theorem prod_univ_two (f : Fin 2 → M) : ∏ i, f i = f 0 * f 1 := by simp [prod_univ_succ] @[to_additive] theorem prod_univ_two' (f : α → M) (a b : α) : ∏ i, f (![a, b] i) = f a * f b := prod_univ_two _ @[to_additive] theorem prod_univ_three (f : Fin 3 → M) : ∏ i, f i = f 0 * f 1 * f 2 := by rw [prod_univ_castSucc, prod_univ_two] rfl @[to_additive] theorem prod_univ_four (f : Fin 4 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 := by rw [prod_univ_castSucc, prod_univ_three] rfl @[to_additive] theorem prod_univ_five (f : Fin 5 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 := by rw [prod_univ_castSucc, prod_univ_four] rfl @[to_additive] theorem prod_univ_six (f : Fin 6 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 := by rw [prod_univ_castSucc, prod_univ_five] rfl @[to_additive] theorem prod_univ_seven (f : Fin 7 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 := by rw [prod_univ_castSucc, prod_univ_six] rfl @[to_additive] theorem prod_univ_eight (f : Fin 8 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 * f 7 := by rw [prod_univ_castSucc, prod_univ_seven] rfl @[to_additive] theorem prod_const (n : ℕ) (x : M) : ∏ _i : Fin n, x = x ^ n := by simp @[to_additive] theorem prod_Ioi_zero {v : Fin n.succ → M} : ∏ i ∈ Ioi 0, v i = ∏ j : Fin n, v j.succ := by rw [Ioi_zero_eq_map, Finset.prod_map, coe_succEmb] @[to_additive (attr := simp)] theorem prod_Ioi_succ (i : Fin n) (v : Fin n.succ → M) : ∏ j ∈ Ioi i.succ, v j = ∏ j ∈ Ioi i, v j.succ := by rw [← map_succEmb_Ioi, Finset.prod_map, coe_succEmb] @[to_additive] theorem prod_congr' {a b : ℕ} (f : Fin b → M) (h : a = b) : (∏ i : Fin a, f (i.cast h)) = ∏ i : Fin b, f i := by subst h congr @[to_additive] theorem prod_univ_add {a b : ℕ} (f : Fin (a + b) → M) : (∏ i : Fin (a + b), f i) = (∏ i : Fin a, f (castAdd b i)) * ∏ i : Fin b, f (natAdd a i) := by rw [Fintype.prod_equiv finSumFinEquiv.symm f fun i => f (finSumFinEquiv.toFun i)] · apply Fintype.prod_sum_type · intro x simp only [Equiv.toFun_as_coe, Equiv.apply_symm_apply] @[to_additive] theorem prod_trunc {a b : ℕ} (f : Fin (a + b) → M) (hf : ∀ j : Fin b, f (natAdd a j) = 1) : (∏ i : Fin (a + b), f i) = ∏ i : Fin a, f (castAdd b i) := by rw [prod_univ_add, Fintype.prod_eq_one _ hf, mul_one] end CommMonoid theorem sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [CommSemiring R] (a b : R) : (∑ s : Finset (Fin n), a ^ s.card * b ^ (n - s.card)) = (a + b) ^ n := by simpa using Fintype.sum_pow_mul_eq_add_pow (Fin n) a b lemma sum_neg_one_pow (R : Type*) [Ring R] (m : ℕ) : (∑ n : Fin m, (-1) ^ n.1 : R) = if Even m then 0 else 1 := by induction m with | zero => simp | succ n IH => simp only [Fin.sum_univ_castSucc, Fin.coe_castSucc, IH, Fin.val_last, Nat.even_add_one, ← Nat.not_even_iff_odd, ite_not] split_ifs with h · simp [*] · simp [(Nat.not_even_iff_odd.mp h).neg_pow] section PartialProd variable [Monoid α] {n : ℕ} /-- For `f = (a₁, ..., aₙ)` in `αⁿ`, `partialProd f` is `(1, a₁, a₁a₂, ..., a₁...aₙ)` in `αⁿ⁺¹`. -/ @[to_additive "For `f = (a₁, ..., aₙ)` in `αⁿ`, `partialSum f` is\n `(0, a₁, a₁ + a₂, ..., a₁ + ... + aₙ)` in `αⁿ⁺¹`."] def partialProd (f : Fin n → α) (i : Fin (n + 1)) : α := ((List.ofFn f).take i).prod @[to_additive (attr := simp)] theorem partialProd_zero (f : Fin n → α) : partialProd f 0 = 1 := by simp [partialProd] @[to_additive] theorem partialProd_succ (f : Fin n → α) (j : Fin n) : partialProd f j.succ = partialProd f (Fin.castSucc j) * f j := by simp [partialProd, List.take_succ, List.ofFnNthVal, dif_pos j.is_lt] @[to_additive] theorem partialProd_succ' (f : Fin (n + 1) → α) (j : Fin (n + 1)) : partialProd f j.succ = f 0 * partialProd (Fin.tail f) j := by simp [partialProd] rfl @[to_additive] theorem partialProd_left_inv {G : Type*} [Group G] (f : Fin (n + 1) → G) : (f 0 • partialProd fun i : Fin n => (f i)⁻¹ * f i.succ) = f := funext fun x => Fin.inductionOn x (by simp) fun x hx => by simp only [coe_eq_castSucc, Pi.smul_apply, smul_eq_mul] at hx ⊢ rw [partialProd_succ, ← mul_assoc, hx, mul_inv_cancel_left] @[to_additive] theorem partialProd_right_inv {G : Type*} [Group G] (f : Fin n → G) (i : Fin n) : (partialProd f (Fin.castSucc i))⁻¹ * partialProd f i.succ = f i := by rw [partialProd_succ, inv_mul_cancel_left] /-- Let `(g₀, g₁, ..., gₙ)` be a tuple of elements in `Gⁿ⁺¹`. Then if `k < j`, this says `(g₀g₁...gₖ₋₁)⁻¹ * g₀g₁...gₖ = gₖ`.
If `k = j`, it says `(g₀g₁...gₖ₋₁)⁻¹ * g₀g₁...gₖ₊₁ = gₖgₖ₊₁`. If `k > j`, it says `(g₀g₁...gₖ)⁻¹ * g₀g₁...gₖ₊₁ = gₖ₊₁.` Useful for defining group cohomology. -/
Mathlib/Algebra/BigOperators/Fin.lean
244
246
/- Copyright (c) 2020 Jalex Stark. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jalex Stark, Kim Morrison, Eric Wieser, Oliver Nash, Wen Yang -/ import Mathlib.Data.Matrix.Basic /-! # Matrices with a single non-zero element. This file provides `Matrix.stdBasisMatrix`. The matrix `Matrix.stdBasisMatrix i j c` has `c` at position `(i, j)`, and zeroes elsewhere. -/ assert_not_exists Matrix.trace variable {l m n o : Type*} variable {R α β : Type*} namespace Matrix variable [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq o] section Zero variable [Zero α] /-- `stdBasisMatrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column, and zeroes elsewhere. -/ def stdBasisMatrix (i : m) (j : n) (a : α) : Matrix m n α := of <| fun i' j' => if i = i' ∧ j = j' then a else 0 theorem stdBasisMatrix_eq_of_single_single (i : m) (j : n) (a : α) : stdBasisMatrix i j a = Matrix.of (Pi.single i (Pi.single j a)) := by ext a b unfold stdBasisMatrix by_cases hi : i = a <;> by_cases hj : j = b <;> simp [*] @[simp] theorem of_symm_stdBasisMatrix (i : m) (j : n) (a : α) : of.symm (stdBasisMatrix i j a) = Pi.single i (Pi.single j a) := congr_arg of.symm <| stdBasisMatrix_eq_of_single_single i j a @[simp] theorem smul_stdBasisMatrix [SMulZeroClass R α] (r : R) (i : m) (j : n) (a : α) : r • stdBasisMatrix i j a = stdBasisMatrix i j (r • a) := by unfold stdBasisMatrix ext simp [smul_ite] @[simp] theorem stdBasisMatrix_zero (i : m) (j : n) : stdBasisMatrix i j (0 : α) = 0 := by unfold stdBasisMatrix ext simp @[simp] lemma transpose_stdBasisMatrix (i : m) (j : n) (a : α) : (stdBasisMatrix i j a)ᵀ = stdBasisMatrix j i a := by aesop (add unsafe unfold stdBasisMatrix) @[simp] lemma map_stdBasisMatrix (i : m) (j : n) (a : α) {β : Type*} [Zero β] {F : Type*} [FunLike F α β] [ZeroHomClass F α β] (f : F) : (stdBasisMatrix i j a).map f = stdBasisMatrix i j (f a) := by aesop (add unsafe unfold stdBasisMatrix) end Zero theorem stdBasisMatrix_add [AddZeroClass α] (i : m) (j : n) (a b : α) : stdBasisMatrix i j (a + b) = stdBasisMatrix i j a + stdBasisMatrix i j b := by ext simp only [stdBasisMatrix, of_apply] split_ifs with h <;> simp [h] theorem mulVec_stdBasisMatrix [NonUnitalNonAssocSemiring α] [Fintype m] (i : n) (j : m) (c : α) (x : m → α) : mulVec (stdBasisMatrix i j c) x = Function.update (0 : n → α) i (c * x j) := by ext i' simp [stdBasisMatrix, mulVec, dotProduct] rcases eq_or_ne i i' with rfl|h · simp simp [h, h.symm] theorem matrix_eq_sum_stdBasisMatrix [AddCommMonoid α] [Fintype m] [Fintype n] (x : Matrix m n α) : x = ∑ i : m, ∑ j : n, stdBasisMatrix i j (x i j) := by ext i j rw [← Fintype.sum_prod_type'] simp [stdBasisMatrix, Matrix.sum_apply, Matrix.of_apply, ← Prod.mk_inj] theorem stdBasisMatrix_eq_single_vecMulVec_single [MulZeroOneClass α] (i : m) (j : n) : stdBasisMatrix i j (1 : α) = vecMulVec (Pi.single i 1) (Pi.single j 1) := by ext i' j' simp [-mul_ite, stdBasisMatrix, vecMulVec, ite_and, Pi.single_apply, eq_comm] -- todo: the old proof used fintypes, I don't know `Finsupp` but this feels generalizable @[elab_as_elim] protected theorem induction_on' [AddCommMonoid α] [Finite m] [Finite n] {P : Matrix m n α → Prop} (M : Matrix m n α) (h_zero : P 0) (h_add : ∀ p q, P p → P q → P (p + q)) (h_std_basis : ∀ (i : m) (j : n) (x : α), P (stdBasisMatrix i j x)) : P M := by cases nonempty_fintype m; cases nonempty_fintype n rw [matrix_eq_sum_stdBasisMatrix M, ← Finset.sum_product'] apply Finset.sum_induction _ _ h_add h_zero · intros apply h_std_basis @[elab_as_elim] protected theorem induction_on [AddCommMonoid α] [Finite m] [Finite n] [Nonempty m] [Nonempty n] {P : Matrix m n α → Prop} (M : Matrix m n α) (h_add : ∀ p q, P p → P q → P (p + q)) (h_std_basis : ∀ i j x, P (stdBasisMatrix i j x)) : P M := Matrix.induction_on' M (by inhabit m inhabit n simpa using h_std_basis default default 0) h_add h_std_basis /-- `Matrix.stdBasisMatrix` as a bundled additive map. -/ @[simps] def stdBasisMatrixAddMonoidHom [AddCommMonoid α] (i : m) (j : n) : α →+ Matrix m n α where toFun := stdBasisMatrix i j map_zero' := stdBasisMatrix_zero _ _ map_add' _ _ := stdBasisMatrix_add _ _ _ _ variable (R) /-- `Matrix.stdBasisMatrix` as a bundled linear map. -/ @[simps!] def stdBasisMatrixLinearMap [Semiring R] [AddCommMonoid α] [Module R α] (i : m) (j : n) : α →ₗ[R] Matrix m n α where __ := stdBasisMatrixAddMonoidHom i j map_smul' _ _:= smul_stdBasisMatrix _ _ _ _ |>.symm section ext /-- Additive maps from finite matrices are equal if they agree on the standard basis.
See note [partially-applied ext lemmas]. -/ @[local ext]
Mathlib/Data/Matrix/Basis.lean
139
140
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Data.NNReal.Basic import Mathlib.Topology.Algebra.Support import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.Order.Real /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 /-- Auxiliary class, endowing a type `α` with a function `enorm : α → ℝ≥0∞` with notation `‖x‖ₑ`. -/ @[notation_class] class ENorm (E : Type*) where /-- the `ℝ≥0∞`-valued norm function. -/ enorm : E → ℝ≥0∞ export Norm (norm) export NNNorm (nnnorm) export ENorm (enorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e @[inherit_doc] notation "‖" e "‖ₑ" => enorm e section ENorm variable {E : Type*} [NNNorm E] {x : E} {r : ℝ≥0} instance NNNorm.toENorm : ENorm E where enorm := (‖·‖₊ : E → ℝ≥0∞) lemma enorm_eq_nnnorm (x : E) : ‖x‖ₑ = ‖x‖₊ := rfl @[simp] lemma toNNReal_enorm (x : E) : ‖x‖ₑ.toNNReal = ‖x‖₊ := rfl @[simp, norm_cast] lemma coe_le_enorm : r ≤ ‖x‖ₑ ↔ r ≤ ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_le_coe : ‖x‖ₑ ≤ r ↔ ‖x‖₊ ≤ r := by simp [enorm] @[simp, norm_cast] lemma coe_lt_enorm : r < ‖x‖ₑ ↔ r < ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_lt_coe : ‖x‖ₑ < r ↔ ‖x‖₊ < r := by simp [enorm] @[simp] lemma enorm_ne_top : ‖x‖ₑ ≠ ∞ := by simp [enorm] @[simp] lemma enorm_lt_top : ‖x‖ₑ < ∞ := by simp [enorm] end ENorm /-- A type `E` equipped with a continuous map `‖·‖ₑ : E → ℝ≥0∞` NB. We do not demand that the topology is somehow defined by the enorm: for ℝ≥0∞ (the motivating example behind this definition), this is not true. -/ class ContinuousENorm (E : Type*) [TopologicalSpace E] extends ENorm E where continuous_enorm : Continuous enorm /-- An enormed monoid is an additive monoid endowed with a continuous enorm. -/ class ENormedAddMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, AddMonoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 0 protected enorm_add_le : ∀ x y : E, ‖x + y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ /-- An enormed monoid is a monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, Monoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 1 enorm_mul_le : ∀ x y : E, ‖x * y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ /-- An enormed commutative monoid is an additive commutative monoid endowed with a continuous enorm. We don't have `ENormedAddCommMonoid` extend `EMetricSpace`, since the canonical instance `ℝ≥0∞` is not an `EMetricSpace`. This is because `ℝ≥0∞` carries the order topology, which is distinct from the topology coming from `edist`. -/ class ENormedAddCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedAddMonoid E, AddCommMonoid E where /-- An enormed commutative monoid is a commutative monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedMonoid E, CommMonoid E where /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] abbrev NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] abbrev NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive "Construct a seminormed group from a translation-invariant distance."] abbrev SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive "Construct a normed group from a translation-invariant distance."] abbrev NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq _ _ := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b c : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] alias dist_eq_norm := dist_eq_norm_sub alias dist_eq_norm' := dist_eq_norm_sub' @[to_additive of_forall_le_norm] lemma DiscreteTopology.of_forall_le_norm' (hpos : 0 < r) (hr : ∀ x : E, x ≠ 1 → r ≤ ‖x‖) : DiscreteTopology E := .of_forall_le_dist hpos fun x y hne ↦ by simp only [dist_eq_norm_div] exact hr _ (div_ne_one.2 hne) @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive] lemma dist_one_left (a : E) : dist 1 a = ‖a‖ := by rw [dist_comm, dist_one_right] @[to_additive (attr := simp)] lemma dist_one : dist (1 : E) = norm := funext dist_one_left @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a @[to_additive (attr := simp) norm_abs_zsmul] theorem norm_zpow_abs (a : E) (n : ℤ) : ‖a ^ |n|‖ = ‖a ^ n‖ := by rcases le_total 0 n with hn | hn <;> simp [hn, abs_of_nonneg, abs_of_nonpos] @[to_additive (attr := simp) norm_natAbs_smul] theorem norm_pow_natAbs (a : E) (n : ℤ) : ‖a ^ n.natAbs‖ = ‖a ^ n‖ := by rw [← zpow_natCast, ← Int.abs_eq_natAbs, norm_zpow_abs] @[to_additive norm_isUnit_zsmul] theorem norm_zpow_isUnit (a : E) {n : ℤ} (hn : IsUnit n) : ‖a ^ n‖ = ‖a‖ := by rw [← norm_pow_natAbs, Int.isUnit_iff_natAbs_eq.mp hn, pow_one] @[simp] theorem norm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℤˣ) (a : E) : ‖n • a‖ = ‖a‖ := norm_isUnit_zsmul a n.isUnit open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le_of_le "**Triangle inequality** for the norm."] theorem norm_mul_le_of_le' (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add₃_le "**Triangle inequality** for the norm."] lemma norm_mul₃_le' : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le' (norm_mul_le' _ _) le_rfl @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg attribute [bound] norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b attribute [bound] norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) @[to_additive (attr := bound)] theorem norm_sub_le_norm_mul (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a * b‖ := by simpa using norm_mul_le' (a * b) (b⁻¹) @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u alias norm_le_insert' := norm_le_norm_add_norm_sub' alias norm_le_insert := norm_le_norm_add_norm_sub @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ /-- An analogue of `norm_le_mul_norm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `norm_le_add_norm_add` for the addition from the left."] theorem norm_le_mul_norm_add' (u v : E) : ‖v‖ ≤ ‖u * v‖ + ‖u‖ := calc ‖v‖ = ‖u⁻¹ * (u * v)‖ := by rw [← mul_assoc, inv_mul_cancel, one_mul] _ ≤ ‖u⁻¹‖ + ‖u * v‖ := norm_mul_le' u⁻¹ (u * v) _ = ‖u * v‖ + ‖u‖ := by rw [norm_inv', add_comm] @[to_additive] lemma norm_mul_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x * y‖ = ‖y‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_mul_le' x y · simpa [h] using norm_le_mul_norm_add' x y @[to_additive] lemma norm_mul_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x * y‖ = ‖x‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_mul_le' x y · simpa [h] using norm_le_mul_norm_add x y @[to_additive] lemma norm_div_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x / y‖ = ‖y‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_div_le x y · simpa [h, norm_div_rev x y] using norm_sub_norm_le' y x @[to_additive] lemma norm_div_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x / y‖ = ‖x‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_div_le x y · simpa [h] using norm_sub_norm_le' x y @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] @[to_additive] theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] @[to_additive] theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right] using norm_sub_norm_le' (u / w) (v / w) @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] open Finset variable [FunLike 𝓕 E F] section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl @[to_additive (attr := simp) norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ @[to_additive (attr := simp) toReal_enorm] lemma toReal_enorm' (x : E) : ‖x‖ₑ.toReal = ‖x‖ := by simp [enorm] @[to_additive (attr := simp) ofReal_norm] lemma ofReal_norm' (x : E) : .ofReal ‖x‖ = ‖x‖ₑ := by simp [enorm, ENNReal.ofReal, Real.toNNReal, nnnorm] @[to_additive enorm_eq_iff_norm_eq] theorem enorm'_eq_iff_norm_eq {x : E} {y : F} : ‖x‖ₑ = ‖y‖ₑ ↔ ‖x‖ = ‖y‖ := by simp only [← ofReal_norm'] refine ⟨fun h ↦ ?_, fun h ↦ by congr⟩ exact (Real.toNNReal_eq_toNNReal_iff (norm_nonneg' _) (norm_nonneg' _)).mp (ENNReal.coe_inj.mp h) @[to_additive enorm_le_iff_norm_le] theorem enorm'_le_iff_norm_le {x : E} {y : F} : ‖x‖ₑ ≤ ‖y‖ₑ ↔ ‖x‖ ≤ ‖y‖ := by simp only [← ofReal_norm'] refine ⟨fun h ↦ ?_, fun h ↦ by gcongr⟩ rw [ENNReal.ofReal_le_ofReal_iff (norm_nonneg' _)] at h exact h @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub @[to_additive (attr := simp)] theorem nndist_one_right (a : E) : nndist a 1 = ‖a‖₊ := by simp [nndist_eq_nnnorm_div] @[to_additive (attr := simp)] lemma edist_one_right (a : E) : edist a 1 = ‖a‖ₑ := by simp [edist_nndist, nndist_one_right, enorm] @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b @[to_additive norm_nsmul_le] lemma norm_pow_le_mul_norm : ∀ {n : ℕ}, ‖a ^ n‖ ≤ n * ‖a‖ | 0 => by simp | n + 1 => by simpa [pow_succ, add_mul] using norm_mul_le_of_le' norm_pow_le_mul_norm le_rfl @[to_additive nnnorm_nsmul_le] lemma nnnorm_pow_le_mul_norm {n : ℕ} : ‖a ^ n‖₊ ≤ n * ‖a‖₊ := by simpa only [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_natCast] using norm_pow_le_mul_norm @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a @[to_additive (attr := simp) nnnorm_abs_zsmul] theorem nnnorm_zpow_abs (a : E) (n : ℤ) : ‖a ^ |n|‖₊ = ‖a ^ n‖₊ := NNReal.eq <| norm_zpow_abs a n @[to_additive (attr := simp) nnnorm_natAbs_smul] theorem nnnorm_pow_natAbs (a : E) (n : ℤ) : ‖a ^ n.natAbs‖₊ = ‖a ^ n‖₊ := NNReal.eq <| norm_pow_natAbs a n @[to_additive nnnorm_isUnit_zsmul] theorem nnnorm_zpow_isUnit (a : E) {n : ℤ} (hn : IsUnit n) : ‖a ^ n‖₊ = ‖a‖₊ := NNReal.eq <| norm_zpow_isUnit a hn @[simp] theorem nnnorm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℤˣ) (a : E) : ‖n • a‖₊ = ‖a‖₊ := NNReal.eq <| norm_isUnit_zsmul a n.isUnit @[to_additive (attr := simp)] theorem nndist_one_left (a : E) : nndist 1 a = ‖a‖₊ := by simp [nndist_eq_nnnorm_div] @[to_additive (attr := simp)] theorem edist_one_left (a : E) : edist 1 a = ‖a‖₊ := by rw [edist_nndist, nndist_one_left] open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ @[to_additive] lemma enorm_div_le : ‖a / b‖ₑ ≤ ‖a‖ₑ + ‖b‖ₑ := by simpa [enorm, ← ENNReal.coe_add] using nnnorm_div_le a b @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ /-- An analogue of `nnnorm_le_mul_nnnorm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `nnnorm_le_add_nnnorm_add` for the addition from the left."] theorem nnnorm_le_mul_nnnorm_add' (a b : E) : ‖b‖₊ ≤ ‖a * b‖₊ + ‖a‖₊ := norm_le_mul_norm_add' _ _ @[to_additive] lemma nnnorm_mul_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x * y‖₊ = ‖y‖₊ := NNReal.eq <| norm_mul_eq_norm_right _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_mul_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x * y‖₊ = ‖x‖₊ := NNReal.eq <| norm_mul_eq_norm_left _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_div_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x / y‖₊ = ‖y‖₊ := NNReal.eq <| norm_div_eq_norm_right _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_div_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x / y‖₊ = ‖x‖₊ := NNReal.eq <| norm_div_eq_norm_left _ <| congr_arg NNReal.toReal h /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] end NNNorm section ENorm @[to_additive (attr := simp) enorm_zero] lemma enorm_one' {E : Type*} [TopologicalSpace E] [ENormedMonoid E] : ‖(1 : E)‖ₑ = 0 := by rw [ENormedMonoid.enorm_eq_zero] @[to_additive exists_enorm_lt] lemma exists_enorm_lt' (E : Type*) [TopologicalSpace E] [ENormedMonoid E] [hbot : NeBot (𝓝[≠] (1 : E))] {c : ℝ≥0∞} (hc : c ≠ 0) : ∃ x ≠ (1 : E), ‖x‖ₑ < c := frequently_iff_neBot.mpr hbot |>.and_eventually (ContinuousENorm.continuous_enorm.tendsto' 1 0 (by simp) |>.eventually_lt_const hc.bot_lt) |>.exists @[to_additive (attr := simp) enorm_neg] lemma enorm_inv' (a : E) : ‖a⁻¹‖ₑ = ‖a‖ₑ := by simp [enorm] @[to_additive ofReal_norm_eq_enorm] lemma ofReal_norm_eq_enorm' (a : E) : .ofReal ‖a‖ = ‖a‖ₑ := ENNReal.ofReal_eq_coe_nnreal _ @[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm := ofReal_norm_eq_enorm @[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm' := ofReal_norm_eq_enorm' instance : ENorm ℝ≥0∞ where enorm x := x @[simp] lemma enorm_eq_self (x : ℝ≥0∞) : ‖x‖ₑ = x := rfl @[to_additive] theorem edist_eq_enorm_div (a b : E) : edist a b = ‖a / b‖ₑ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_enorm'] @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm_sub := edist_eq_enorm_sub @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm_div := edist_eq_enorm_div @[to_additive] theorem edist_one_eq_enorm (x : E) : edist x 1 = ‖x‖ₑ := by rw [edist_eq_enorm_div, div_one] @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm := edist_zero_eq_enorm @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm' := edist_one_eq_enorm @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball 1 r ↔ ‖a‖ₑ < r := by rw [EMetric.mem_ball, edist_one_eq_enorm] end ENorm section ContinuousENorm variable {E : Type*} [TopologicalSpace E] [ContinuousENorm E] @[continuity, fun_prop] lemma continuous_enorm : Continuous fun a : E ↦ ‖a‖ₑ := ContinuousENorm.continuous_enorm variable {X : Type*} [TopologicalSpace X] {f : X → E} {s : Set X} {a : X} @[fun_prop] lemma Continuous.enorm : Continuous f → Continuous (‖f ·‖ₑ) := continuous_enorm.comp lemma ContinuousAt.enorm {a : X} (h : ContinuousAt f a) : ContinuousAt (‖f ·‖ₑ) a := by fun_prop @[fun_prop] lemma ContinuousWithinAt.enorm {s : Set X} {a : X} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (‖f ·‖ₑ) s a := (ContinuousENorm.continuous_enorm.continuousWithinAt).comp (t := Set.univ) h (fun _ _ ↦ by trivial) @[fun_prop] lemma ContinuousOn.enorm (h : ContinuousOn f s) : ContinuousOn (‖f ·‖ₑ) s := (ContinuousENorm.continuous_enorm.continuousOn).comp (t := Set.univ) h <| Set.mapsTo_univ _ _ end ContinuousENorm section ENormedMonoid variable {E : Type*} [TopologicalSpace E] [ENormedMonoid E] @[to_additive enorm_add_le] lemma enorm_mul_le' (a b : E) : ‖a * b‖ₑ ≤ ‖a‖ₑ + ‖b‖ₑ := ENormedMonoid.enorm_mul_le a b @[to_additive (attr := simp) enorm_eq_zero] lemma enorm_eq_zero' {a : E} : ‖a‖ₑ = 0 ↔ a = 1 := by simp [enorm, ENormedMonoid.enorm_eq_zero] @[to_additive enorm_ne_zero] lemma enorm_ne_zero' {a : E} : ‖a‖ₑ ≠ 0 ↔ a ≠ 1 := enorm_eq_zero'.ne @[to_additive (attr := simp) enorm_pos] lemma enorm_pos' {a : E} : 0 < ‖a‖ₑ ↔ a ≠ 1 := pos_iff_ne_zero.trans enorm_ne_zero' end ENormedMonoid instance : ENormedAddCommMonoid ℝ≥0∞ where continuous_enorm := continuous_id enorm_eq_zero := by simp enorm_add_le := by simp open Set in @[to_additive] lemma SeminormedGroup.disjoint_nhds (x : E) (f : Filter E) : Disjoint (𝓝 x) f ↔ ∃ δ > 0, ∀ᶠ y in f, δ ≤ ‖y / x‖ := by simp [NormedCommGroup.nhds_basis_norm_lt x |>.disjoint_iff_left, compl_setOf, eventually_iff] @[to_additive] lemma SeminormedGroup.disjoint_nhds_one (f : Filter E) : Disjoint (𝓝 1) f ↔ ∃ δ > 0, ∀ᶠ y in f, δ ≤ ‖y‖ := by simpa using disjoint_nhds 1 f end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] abbrev SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] abbrev SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] abbrev NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] abbrev NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } end Induced namespace Real variable {r : ℝ} instance norm : Norm ℝ where norm r := |r| @[simp] theorem norm_eq_abs (r : ℝ) : ‖r‖ = |r| := rfl instance normedAddCommGroup : NormedAddCommGroup ℝ := ⟨fun _r _y => rfl⟩ theorem norm_of_nonneg (hr : 0 ≤ r) : ‖r‖ = r := abs_of_nonneg hr theorem norm_of_nonpos (hr : r ≤ 0) : ‖r‖ = -r := abs_of_nonpos hr theorem le_norm_self (r : ℝ) : r ≤ ‖r‖ := le_abs_self r @[simp 1100] lemma norm_natCast (n : ℕ) : ‖(n : ℝ)‖ = n := abs_of_nonneg n.cast_nonneg @[simp 1100] lemma nnnorm_natCast (n : ℕ) : ‖(n : ℝ)‖₊ = n := NNReal.eq <| norm_natCast _ @[simp 1100] lemma enorm_natCast (n : ℕ) : ‖(n : ℝ)‖ₑ = n := by simp [enorm] @[simp 1100] lemma norm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : ℝ)‖ = ofNat(n) := norm_natCast n @[simp 1100] lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : ℝ)‖₊ = ofNat(n) := nnnorm_natCast n lemma norm_two : ‖(2 : ℝ)‖ = 2 := abs_of_pos zero_lt_two lemma nnnorm_two : ‖(2 : ℝ)‖₊ = 2 := NNReal.eq <| by simp @[simp 1100, norm_cast] lemma norm_nnratCast (q : ℚ≥0) : ‖(q : ℝ)‖ = q := norm_of_nonneg q.cast_nonneg @[simp 1100, norm_cast] lemma nnnorm_nnratCast (q : ℚ≥0) : ‖(q : ℝ)‖₊ = q := by simp [nnnorm, -norm_eq_abs] theorem nnnorm_of_nonneg (hr : 0 ≤ r) : ‖r‖₊ = ⟨r, hr⟩ := NNReal.eq <| norm_of_nonneg hr lemma enorm_of_nonneg (hr : 0 ≤ r) : ‖r‖ₑ = .ofReal r := by simp [enorm, nnnorm_of_nonneg hr, ENNReal.ofReal, toNNReal, hr] @[simp] lemma nnnorm_abs (r : ℝ) : ‖|r|‖₊ = ‖r‖₊ := by simp [nnnorm] @[simp] lemma enorm_abs (r : ℝ) : ‖|r|‖ₑ = ‖r‖ₑ := by simp [enorm] theorem enorm_eq_ofReal (hr : 0 ≤ r) : ‖r‖ₑ = .ofReal r := by rw [← ofReal_norm_eq_enorm, norm_of_nonneg hr] @[deprecated (since := "2025-01-17")] alias ennnorm_eq_ofReal := enorm_eq_ofReal theorem enorm_eq_ofReal_abs (r : ℝ) : ‖r‖ₑ = ENNReal.ofReal |r| := by rw [← enorm_eq_ofReal (abs_nonneg _), enorm_abs] @[deprecated (since := "2025-01-17")] alias ennnorm_eq_ofReal_abs := enorm_eq_ofReal_abs theorem toNNReal_eq_nnnorm_of_nonneg (hr : 0 ≤ r) : r.toNNReal = ‖r‖₊ := by rw [Real.toNNReal_of_nonneg hr] ext rw [coe_mk, coe_nnnorm r, Real.norm_eq_abs r, abs_of_nonneg hr] -- Porting note: this is due to the change from `Subtype.val` to `NNReal.toReal` for the coercion theorem ofReal_le_enorm (r : ℝ) : ENNReal.ofReal r ≤ ‖r‖ₑ := by rw [enorm_eq_ofReal_abs]; gcongr; exact le_abs_self _ @[deprecated (since := "2025-01-17")] alias ofReal_le_ennnorm := ofReal_le_enorm end Real namespace NNReal instance : NNNorm ℝ≥0 where nnnorm x := x @[simp] lemma nnnorm_eq_self (x : ℝ≥0) : ‖x‖₊ = x := rfl end NNReal section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a b : E} {r : ℝ} @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≤ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≤ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y @[bound] theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≤ n b) : ‖∏ b ∈ s, f b‖ ≤ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h @[to_additive] theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≤ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, d b := by simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h @[to_additive] theorem dist_prod_prod_le (s : Finset ι) (f a : ι → E) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, dist (f b) (a b) := dist_prod_prod_le_of_le s fun _ _ => le_rfl @[to_additive] theorem mul_mem_ball_iff_norm : a * b ∈ ball a r ↔ ‖b‖ < r := by rw [mem_ball_iff_norm'', mul_div_cancel_left] @[to_additive] theorem mul_mem_closedBall_iff_norm : a * b ∈ closedBall a r ↔ ‖b‖ ≤ r := by rw [mem_closedBall_iff_norm'', mul_div_cancel_left] @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_ball (a b : E) (r : ℝ) : (b * ·) ⁻¹' ball a r = ball (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_closedBall (a b : E) (r : ℝ) : (b * ·) ⁻¹' closedBall a r = closedBall (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_closedBall, div_div_eq_mul_div, mul_comm] @[to_additive (attr := simp)] theorem preimage_mul_sphere (a b : E) (r : ℝ) : (b * ·) ⁻¹' sphere a r = sphere (a / b) r := by ext c simp only [Set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] @[to_additive] theorem pow_mem_closedBall {n : ℕ} (h : a ∈ closedBall b r) : a ^ n ∈ closedBall (b ^ n) (n • r) := by simp only [mem_closedBall, dist_eq_norm_div, ← div_pow] at h ⊢ refine norm_pow_le_mul_norm.trans ?_ simpa only [nsmul_eq_mul] using mul_le_mul_of_nonneg_left h n.cast_nonneg @[to_additive] theorem pow_mem_ball {n : ℕ} (hn : 0 < n) (h : a ∈ ball b r) : a ^ n ∈ ball (b ^ n) (n • r) := by simp only [mem_ball, dist_eq_norm_div, ← div_pow] at h ⊢ refine lt_of_le_of_lt norm_pow_le_mul_norm ?_ replace hn : 0 < (n : ℝ) := by norm_cast rw [nsmul_eq_mul] nlinarith @[to_additive] theorem mul_mem_closedBall_mul_iff {c : E} : a * c ∈ closedBall (b * c) r ↔ a ∈ closedBall b r := by simp only [mem_closedBall, dist_eq_norm_div, mul_div_mul_right_eq_div] @[to_additive] theorem mul_mem_ball_mul_iff {c : E} : a * c ∈ ball (b * c) r ↔ a ∈ ball b r := by simp only [mem_ball, dist_eq_norm_div, mul_div_mul_right_eq_div] @[to_additive] theorem smul_closedBall'' : a • closedBall b r = closedBall (a • b) r := by ext simp [mem_closedBall, Set.mem_smul_set, dist_eq_norm_div, div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] @[to_additive] theorem smul_ball'' : a • ball b r = ball (a • b) r := by ext simp [mem_ball, Set.mem_smul_set, dist_eq_norm_div, _root_.div_eq_inv_mul,
← eq_inv_mul_iff_mul_eq, mul_assoc]
Mathlib/Analysis/Normed/Group/Basic.lean
1,201
1,202
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Pi.Basic import Mathlib.Algebra.Notation.Prod import Mathlib.Data.Set.Image /-! # Support of a function In this file we define `Function.support f = {x | f x ≠ 0}` and prove its basic properties. We also define `Function.mulSupport f = {x | f x ≠ 1}`. -/ assert_not_exists CompleteLattice MonoidWithZero open Set namespace Function variable {α β A B M M' N P G : Type*} section One variable [One M] [One N] [One P] /-- `mulSupport` of a function is the set of points `x` such that `f x ≠ 1`. -/ @[to_additive "`support` of a function is the set of points `x` such that `f x ≠ 0`."] def mulSupport (f : α → M) : Set α := {x | f x ≠ 1} @[to_additive] theorem mulSupport_eq_preimage (f : α → M) : mulSupport f = f ⁻¹' {1}ᶜ := rfl @[to_additive] theorem nmem_mulSupport {f : α → M} {x : α} : x ∉ mulSupport f ↔ f x = 1 := not_not @[to_additive] theorem compl_mulSupport {f : α → M} : (mulSupport f)ᶜ = { x | f x = 1 } := ext fun _ => nmem_mulSupport @[to_additive (attr := simp)] theorem mem_mulSupport {f : α → M} {x : α} : x ∈ mulSupport f ↔ f x ≠ 1 := Iff.rfl @[to_additive (attr := simp)] theorem mulSupport_subset_iff {f : α → M} {s : Set α} : mulSupport f ⊆ s ↔ ∀ x, f x ≠ 1 → x ∈ s := Iff.rfl @[to_additive] theorem mulSupport_subset_iff' {f : α → M} {s : Set α} : mulSupport f ⊆ s ↔ ∀ x ∉ s, f x = 1 := forall_congr' fun _ => not_imp_comm @[to_additive] theorem mulSupport_eq_iff {f : α → M} {s : Set α} : mulSupport f = s ↔ (∀ x, x ∈ s → f x ≠ 1) ∧ ∀ x, x ∉ s → f x = 1 := by simp +contextual only [Set.ext_iff, mem_mulSupport, ne_eq, iff_def, not_imp_comm, and_comm, forall_and] @[to_additive] theorem ext_iff_mulSupport {f g : α → M} : f = g ↔ f.mulSupport = g.mulSupport ∧ ∀ x ∈ f.mulSupport, f x = g x := ⟨fun h ↦ h ▸ ⟨rfl, fun _ _ ↦ rfl⟩, fun ⟨h₁, h₂⟩ ↦ funext fun x ↦ by if hx : x ∈ f.mulSupport then exact h₂ x hx else rw [nmem_mulSupport.1 hx, nmem_mulSupport.1 (mt (Set.ext_iff.1 h₁ x).2 hx)]⟩ @[to_additive] theorem mulSupport_update_of_ne_one [DecidableEq α] (f : α → M) (x : α) {y : M} (hy : y ≠ 1) : mulSupport (update f x y) = insert x (mulSupport f) := by ext a; rcases eq_or_ne a x with rfl | hne <;> simp [*] @[to_additive] theorem mulSupport_update_one [DecidableEq α] (f : α → M) (x : α) : mulSupport (update f x 1) = mulSupport f \ {x} := by ext a; rcases eq_or_ne a x with rfl | hne <;> simp [*] @[to_additive] theorem mulSupport_update_eq_ite [DecidableEq α] [DecidableEq M] (f : α → M) (x : α) (y : M) : mulSupport (update f x y) = if y = 1 then mulSupport f \ {x} else insert x (mulSupport f) := by rcases eq_or_ne y 1 with rfl | hy <;> simp [mulSupport_update_one, mulSupport_update_of_ne_one, *] @[to_additive] theorem mulSupport_extend_one_subset {f : α → M'} {g : α → N} : mulSupport (f.extend g 1) ⊆ f '' mulSupport g := mulSupport_subset_iff'.mpr fun x hfg ↦ by by_cases hf : ∃ a, f a = x · rw [extend, dif_pos hf, ← nmem_mulSupport] rw [← Classical.choose_spec hf] at hfg exact fun hg ↦ hfg ⟨_, hg, rfl⟩ · rw [extend_apply' _ _ _ hf]; rfl @[to_additive] theorem mulSupport_extend_one {f : α → M'} {g : α → N} (hf : f.Injective) : mulSupport (f.extend g 1) = f '' mulSupport g := mulSupport_extend_one_subset.antisymm <| by rintro _ ⟨x, hx, rfl⟩; rwa [mem_mulSupport, hf.extend_apply] @[to_additive] theorem mulSupport_disjoint_iff {f : α → M} {s : Set α} : Disjoint (mulSupport f) s ↔ EqOn f 1 s := by simp_rw [← subset_compl_iff_disjoint_right, mulSupport_subset_iff', not_mem_compl_iff, EqOn, Pi.one_apply] @[to_additive] theorem disjoint_mulSupport_iff {f : α → M} {s : Set α} : Disjoint s (mulSupport f) ↔ EqOn f 1 s := by rw [disjoint_comm, mulSupport_disjoint_iff] @[to_additive (attr := simp)] theorem mulSupport_eq_empty_iff {f : α → M} : mulSupport f = ∅ ↔ f = 1 := by rw [← subset_empty_iff, mulSupport_subset_iff', funext_iff] simp @[to_additive (attr := simp)] theorem mulSupport_nonempty_iff {f : α → M} : (mulSupport f).Nonempty ↔ f ≠ 1 := by rw [nonempty_iff_ne_empty, Ne, mulSupport_eq_empty_iff] @[to_additive] theorem range_subset_insert_image_mulSupport (f : α → M) : range f ⊆ insert 1 (f '' mulSupport f) := by simpa only [range_subset_iff, mem_insert_iff, or_iff_not_imp_left] using fun x (hx : x ∈ mulSupport f) => mem_image_of_mem f hx @[to_additive] lemma range_eq_image_or_of_mulSupport_subset {f : α → M} {k : Set α} (h : mulSupport f ⊆ k) : range f = f '' k ∨ range f = insert 1 (f '' k) := by have : range f ⊆ insert 1 (f '' k) := (range_subset_insert_image_mulSupport f).trans (insert_subset_insert (image_subset f h)) by_cases h1 : 1 ∈ range f · exact Or.inr (subset_antisymm this (insert_subset h1 (image_subset_range _ _))) refine Or.inl (subset_antisymm ?_ (image_subset_range _ _)) rwa [← diff_singleton_eq_self h1, diff_singleton_subset_iff] @[to_additive (attr := simp)] theorem mulSupport_one' : mulSupport (1 : α → M) = ∅ := mulSupport_eq_empty_iff.2 rfl @[to_additive (attr := simp)] theorem mulSupport_one : (mulSupport fun _ : α => (1 : M)) = ∅ := mulSupport_one' @[to_additive] theorem mulSupport_const {c : M} (hc : c ≠ 1) : (mulSupport fun _ : α => c) = Set.univ := by ext x simp [hc] @[to_additive] theorem mulSupport_binop_subset (op : M → N → P) (op1 : op 1 1 = 1) (f : α → M) (g : α → N) : (mulSupport fun x => op (f x) (g x)) ⊆ mulSupport f ∪ mulSupport g := fun x hx => not_or_of_imp fun hf hg => hx <| by simp only [hf, hg, op1] @[to_additive] theorem mulSupport_comp_subset {g : M → N} (hg : g 1 = 1) (f : α → M) : mulSupport (g ∘ f) ⊆ mulSupport f := fun x => mt fun h => by simp only [(· ∘ ·), *] @[to_additive] theorem mulSupport_subset_comp {g : M → N} (hg : ∀ {x}, g x = 1 → x = 1) (f : α → M) : mulSupport f ⊆ mulSupport (g ∘ f) := fun _ => mt hg @[to_additive] theorem mulSupport_comp_eq (g : M → N) (hg : ∀ {x}, g x = 1 ↔ x = 1) (f : α → M) : mulSupport (g ∘ f) = mulSupport f := Set.ext fun _ => not_congr hg @[to_additive] theorem mulSupport_comp_eq_of_range_subset {g : M → N} {f : α → M} (hg : ∀ {x}, x ∈ range f → (g x = 1 ↔ x = 1)) : mulSupport (g ∘ f) = mulSupport f := Set.ext fun x ↦ not_congr <| by rw [Function.comp, hg (mem_range_self x)] @[to_additive] theorem mulSupport_comp_eq_preimage (g : β → M) (f : α → β) : mulSupport (g ∘ f) = f ⁻¹' mulSupport g := rfl @[to_additive support_prod_mk] theorem mulSupport_prod_mk (f : α → M) (g : α → N) : (mulSupport fun x => (f x, g x)) = mulSupport f ∪ mulSupport g := Set.ext fun x => by simp only [mulSupport, not_and_or, mem_union, mem_setOf_eq, Prod.mk_eq_one, Ne] @[to_additive support_prod_mk'] theorem mulSupport_prod_mk' (f : α → M × N) : mulSupport f = (mulSupport fun x => (f x).1) ∪ mulSupport fun x => (f x).2 := by simp only [← mulSupport_prod_mk] @[to_additive] theorem mulSupport_along_fiber_subset (f : α × β → M) (a : α) : (mulSupport fun b => f (a, b)) ⊆ (mulSupport f).image Prod.snd := fun x hx => ⟨(a, x), by simpa using hx⟩ @[to_additive] theorem mulSupport_curry (f : α × β → M) : (mulSupport f.curry) = (mulSupport f).image Prod.fst := by simp [mulSupport, funext_iff, image] @[to_additive] theorem mulSupport_curry' (f : α × β → M) : (mulSupport fun a b ↦ f (a, b)) = (mulSupport f).image Prod.fst := mulSupport_curry f end One @[to_additive] theorem mulSupport_mul [MulOneClass M] (f g : α → M) : (mulSupport fun x => f x * g x) ⊆ mulSupport f ∪ mulSupport g := mulSupport_binop_subset (· * ·) (one_mul _) f g @[to_additive] theorem mulSupport_pow [Monoid M] (f : α → M) (n : ℕ) : (mulSupport fun x => f x ^ n) ⊆ mulSupport f := by induction n with | zero => simp [pow_zero, mulSupport_one] | succ n hfn => simpa only [pow_succ'] using (mulSupport_mul f _).trans (union_subset Subset.rfl hfn) section DivisionMonoid variable [DivisionMonoid G] (f g : α → G) @[to_additive (attr := simp)] theorem mulSupport_inv : (mulSupport fun x => (f x)⁻¹) = mulSupport f := ext fun _ => inv_ne_one @[to_additive (attr := simp)] theorem mulSupport_inv' : mulSupport f⁻¹ = mulSupport f := mulSupport_inv f @[to_additive] theorem mulSupport_mul_inv : (mulSupport fun x => f x * (g x)⁻¹) ⊆ mulSupport f ∪ mulSupport g := mulSupport_binop_subset (fun a b => a * b⁻¹) (by simp) f g @[to_additive] theorem mulSupport_div : (mulSupport fun x => f x / g x) ⊆ mulSupport f ∪ mulSupport g := mulSupport_binop_subset (· / ·) one_div_one f g end DivisionMonoid end Function namespace Set open Function variable {α β M : Type*} [One M] {f : α → M} @[to_additive] theorem image_inter_mulSupport_eq {s : Set β} {g : β → α} : g '' s ∩ mulSupport f = g '' (s ∩ mulSupport (f ∘ g)) := by rw [mulSupport_comp_eq_preimage f g, image_inter_preimage] end Set namespace Pi variable {A : Type*} {B : Type*} [DecidableEq A] [One B] {a : A} {b : B} open Function @[to_additive] theorem mulSupport_mulSingle_subset : mulSupport (mulSingle a b) ⊆ {a} := fun _ hx => by_contra fun hx' => hx <| mulSingle_eq_of_ne hx' _ @[to_additive] theorem mulSupport_mulSingle_one : mulSupport (mulSingle a (1 : B)) = ∅ := by simp @[to_additive (attr := simp)] theorem mulSupport_mulSingle_of_ne (h : b ≠ 1) : mulSupport (mulSingle a b) = {a} := mulSupport_mulSingle_subset.antisymm fun x (hx : x = a) => by rwa [mem_mulSupport, hx, mulSingle_eq_same] @[to_additive] theorem mulSupport_mulSingle [DecidableEq B] : mulSupport (mulSingle a b) = if b = 1 then ∅ else {a} := by split_ifs with h <;> simp [h] @[to_additive] theorem mulSupport_mulSingle_disjoint {b' : B} (hb : b ≠ 1) (hb' : b' ≠ 1) {i j : A} : Disjoint (mulSupport (mulSingle i b)) (mulSupport (mulSingle j b')) ↔ i ≠ j := by rw [mulSupport_mulSingle_of_ne hb, mulSupport_mulSingle_of_ne hb', disjoint_singleton] end Pi
Mathlib/Algebra/Group/Support.lean
309
311
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Rayleigh import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Algebra.DirectSum.Decomposition import Mathlib.LinearAlgebra.Eigenspace.Minpoly /-! # Spectral theory of self-adjoint operators This file covers the spectral theory of self-adjoint operators on an inner product space. The first part of the file covers general properties, true without any condition on boundedness or compactness of the operator or finite-dimensionality of the underlying space, notably: * `LinearMap.IsSymmetric.conj_eigenvalue_eq_self`: the eigenvalues are real * `LinearMap.IsSymmetric.orthogonalFamily_eigenspaces`: the eigenspaces are orthogonal * `LinearMap.IsSymmetric.orthogonalComplement_iSup_eigenspaces`: the restriction of the operator to the mutual orthogonal complement of the eigenspaces has, itself, no eigenvectors The second part of the file covers properties of self-adjoint operators in finite dimension. Letting `T` be a self-adjoint operator on a finite-dimensional inner product space `T`, * The definition `LinearMap.IsSymmetric.diagonalization` provides a linear isometry equivalence `E` to the direct sum of the eigenspaces of `T`. The theorem `LinearMap.IsSymmetric.diagonalization_apply_self_apply` states that, when `T` is transferred via this equivalence to an operator on the direct sum, it acts diagonally. * The definition `LinearMap.IsSymmetric.eigenvectorBasis` provides an orthonormal basis for `E` consisting of eigenvectors of `T`, with `LinearMap.IsSymmetric.eigenvalues` giving the corresponding list of eigenvalues, as real numbers. The definition `LinearMap.IsSymmetric.eigenvectorBasis` gives the associated linear isometry equivalence from `E` to Euclidean space, and the theorem `LinearMap.IsSymmetric.eigenvectorBasis_apply_self_apply` states that, when `T` is transferred via this equivalence to an operator on Euclidean space, it acts diagonally. These are forms of the *diagonalization theorem* for self-adjoint operators on finite-dimensional inner product spaces. ## TODO Spectral theory for compact self-adjoint operators, bounded self-adjoint operators. ## Tags self-adjoint operator, spectral theorem, diagonalization theorem -/ variable {𝕜 : Type*} [RCLike 𝕜] variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y open scoped ComplexConjugate open Module.End namespace LinearMap namespace IsSymmetric variable {T : E →ₗ[𝕜] E} /-- A self-adjoint operator preserves orthogonal complements of its eigenspaces. -/ theorem invariant_orthogonalComplement_eigenspace (hT : T.IsSymmetric) (μ : 𝕜) (v : E) (hv : v ∈ (eigenspace T μ)ᗮ) : T v ∈ (eigenspace T μ)ᗮ := by intro w hw have : T w = (μ : 𝕜) • w := by rwa [mem_eigenspace_iff] at hw simp [← hT w, this, inner_smul_left, hv w hw] /-- The eigenvalues of a self-adjoint operator are real. -/ theorem conj_eigenvalue_eq_self (hT : T.IsSymmetric) {μ : 𝕜} (hμ : HasEigenvalue T μ) : conj μ = μ := by obtain ⟨v, hv₁, hv₂⟩ := hμ.exists_hasEigenvector rw [mem_eigenspace_iff] at hv₁ simpa [hv₂, inner_smul_left, inner_smul_right, hv₁] using hT v v /-- The eigenspaces of a self-adjoint operator are mutually orthogonal. -/ theorem orthogonalFamily_eigenspaces (hT : T.IsSymmetric) : OrthogonalFamily 𝕜 (fun μ => eigenspace T μ) fun μ => (eigenspace T μ).subtypeₗᵢ := by rintro μ ν hμν ⟨v, hv⟩ ⟨w, hw⟩ by_cases hv' : v = 0 · simp [hv'] have H := hT.conj_eigenvalue_eq_self (hasEigenvalue_of_hasEigenvector ⟨hv, hv'⟩) rw [mem_eigenspace_iff] at hv hw refine Or.resolve_left ?_ hμν.symm simpa [inner_smul_left, inner_smul_right, hv, hw, H] using (hT v w).symm theorem orthogonalFamily_eigenspaces' (hT : T.IsSymmetric) : OrthogonalFamily 𝕜 (fun μ : Eigenvalues T => eigenspace T μ) fun μ => (eigenspace T μ).subtypeₗᵢ := hT.orthogonalFamily_eigenspaces.comp Subtype.coe_injective /-- The mutual orthogonal complement of the eigenspaces of a self-adjoint operator on an inner product space is an invariant subspace of the operator. -/ theorem orthogonalComplement_iSup_eigenspaces_invariant (hT : T.IsSymmetric) ⦃v : E⦄ (hv : v ∈ (⨆ μ, eigenspace T μ)ᗮ) : T v ∈ (⨆ μ, eigenspace T μ)ᗮ := by rw [← Submodule.iInf_orthogonal] at hv ⊢ exact T.iInf_invariant hT.invariant_orthogonalComplement_eigenspace v hv /-- The mutual orthogonal complement of the eigenspaces of a self-adjoint operator on an inner
product space has no eigenvalues. -/ theorem orthogonalComplement_iSup_eigenspaces (hT : T.IsSymmetric) (μ : 𝕜) : eigenspace (T.restrict hT.orthogonalComplement_iSup_eigenspaces_invariant) μ = ⊥ := by set p : Submodule 𝕜 E := (⨆ μ, eigenspace T μ)ᗮ
Mathlib/Analysis/InnerProductSpace/Spectrum.lean
102
105
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MvPolynomial.Eval /-! # Renaming variables of polynomials This file establishes the `rename` operation on multivariate polynomials, which modifies the set of variables. ## Main declarations * `MvPolynomial.rename` * `MvPolynomial.renameEquiv` ## Notation As in other polynomial files, we typically use the notation: + `σ τ α : Type*` (indexing the variables) + `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` elements of the coefficient ring + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ α` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra variable {σ τ α R S : Type*} [CommSemiring R] [CommSemiring S] namespace MvPolynomial section Rename /-- Rename all the variables in a multivariable polynomial. -/ def rename (f : σ → τ) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R := aeval (X ∘ f) theorem rename_C (f : σ → τ) (r : R) : rename f (C r) = C r := eval₂_C _ _ _ @[simp] theorem rename_X (f : σ → τ) (i : σ) : rename f (X i : MvPolynomial σ R) = X (f i) := eval₂_X _ _ _ theorem map_rename (f : R →+* S) (g : σ → τ) (p : MvPolynomial σ R) : map f (rename g p) = rename g (map f p) := by apply MvPolynomial.induction_on p (fun a => by simp only [map_C, rename_C]) (fun p q hp hq => by simp only [hp, hq, map_add]) fun p n hp => by simp only [hp, rename_X, map_X, map_mul] lemma map_comp_rename (f : R →+* S) (g : σ → τ) : (map f).comp (rename g).toRingHom = (rename g).toRingHom.comp (map f) := RingHom.ext fun p ↦ map_rename f g p @[simp] theorem rename_rename (f : σ → τ) (g : τ → α) (p : MvPolynomial σ R) : rename g (rename f p) = rename (g ∘ f) p := show rename g (eval₂ C (X ∘ f) p) = _ by simp only [rename, aeval_eq_eval₂Hom] -- Porting note: the Lean 3 proof of this was very fragile and included a nonterminal `simp`. -- Hopefully this is less prone to breaking rw [eval₂_comp_left (eval₂Hom (algebraMap R (MvPolynomial α R)) (X ∘ g)) C (X ∘ f) p] simp only [comp_def, eval₂Hom_X'] refine eval₂Hom_congr ?_ rfl rfl ext1; simp only [comp_apply, RingHom.coe_comp, eval₂Hom_C] lemma rename_comp_rename (f : σ → τ) (g : τ → α) : (rename (R := R) g).comp (rename f) = rename (g ∘ f) := AlgHom.ext fun p ↦ rename_rename f g p @[simp] theorem rename_id : rename id = AlgHom.id R (MvPolynomial σ R) := AlgHom.ext fun p ↦ eval₂_eta p lemma rename_id_apply (p : MvPolynomial σ R) : rename id p = p := by simp theorem rename_monomial (f : σ → τ) (d : σ →₀ ℕ) (r : R) : rename f (monomial d r) = monomial (d.mapDomain f) r := by rw [rename, aeval_monomial, monomial_eq (s := Finsupp.mapDomain f d), Finsupp.prod_mapDomain_index] · rfl · exact fun n => pow_zero _ · exact fun n i₁ i₂ => pow_add _ _ _ theorem rename_eq (f : σ → τ) (p : MvPolynomial σ R) : rename f p = Finsupp.mapDomain (Finsupp.mapDomain f) p := by simp only [rename, aeval_def, eval₂, Finsupp.mapDomain, algebraMap_eq, comp_apply, X_pow_eq_monomial, ← monomial_finsupp_sum_index] rfl theorem rename_injective (f : σ → τ) (hf : Function.Injective f) : Function.Injective (rename f : MvPolynomial σ R → MvPolynomial τ R) := by have : (rename f : MvPolynomial σ R → MvPolynomial τ R) = Finsupp.mapDomain (Finsupp.mapDomain f) := funext (rename_eq f) rw [this] exact Finsupp.mapDomain_injective (Finsupp.mapDomain_injective hf) theorem rename_leftInverse {f : σ → τ} {g : τ → σ} (hf : Function.LeftInverse f g) : Function.LeftInverse (rename f : MvPolynomial σ R → MvPolynomial τ R) (rename g) := by intro x simp [hf.comp_eq_id] theorem rename_rightInverse {f : σ → τ} {g : τ → σ} (hf : Function.RightInverse f g) : Function.RightInverse (rename f : MvPolynomial σ R → MvPolynomial τ R) (rename g) := rename_leftInverse hf theorem rename_surjective (f : σ → τ) (hf : Function.Surjective f) : Function.Surjective (rename f : MvPolynomial σ R → MvPolynomial τ R) := let ⟨_, hf⟩ := hf.hasRightInverse; rename_rightInverse hf |>.surjective section variable {f : σ → τ} (hf : Function.Injective f) open Classical in /-- Given a function between sets of variables `f : σ → τ` that is injective with proof `hf`, `MvPolynomial.killCompl hf` is the `AlgHom` from `R[τ]` to `R[σ]` that is left inverse to `rename f : R[σ] → R[τ]` and sends the variables in the complement of the range of `f` to `0`. -/ def killCompl : MvPolynomial τ R →ₐ[R] MvPolynomial σ R := aeval fun i => if h : i ∈ Set.range f then X <| (Equiv.ofInjective f hf).symm ⟨i, h⟩ else 0 theorem killCompl_C (r : R) : killCompl hf (C r) = C r := algHom_C _ _ theorem killCompl_comp_rename : (killCompl hf).comp (rename f) = AlgHom.id R _ := algHom_ext fun i => by dsimp rw [rename, killCompl, aeval_X, comp_apply, aeval_X, dif_pos, Equiv.ofInjective_symm_apply] @[simp] theorem killCompl_rename_app (p : MvPolynomial σ R) : killCompl hf (rename f p) = p := AlgHom.congr_fun (killCompl_comp_rename hf) p end section variable (R) /-- `MvPolynomial.rename e` is an equivalence when `e` is. -/ @[simps apply] def renameEquiv (f : σ ≃ τ) : MvPolynomial σ R ≃ₐ[R] MvPolynomial τ R := { rename f with toFun := rename f invFun := rename f.symm left_inv := fun p => by rw [rename_rename, f.symm_comp_self, rename_id_apply] right_inv := fun p => by rw [rename_rename, f.self_comp_symm, rename_id_apply] } @[simp] theorem renameEquiv_refl : renameEquiv R (Equiv.refl σ) = AlgEquiv.refl := AlgEquiv.ext (by simp) @[simp] theorem renameEquiv_symm (f : σ ≃ τ) : (renameEquiv R f).symm = renameEquiv R f.symm := rfl @[simp] theorem renameEquiv_trans (e : σ ≃ τ) (f : τ ≃ α) : (renameEquiv R e).trans (renameEquiv R f) = renameEquiv R (e.trans f) := AlgEquiv.ext (rename_rename e f) end section variable (f : R →+* S) (k : σ → τ) (g : τ → S) (p : MvPolynomial σ R) theorem eval₂_rename : (rename k p).eval₂ f g = p.eval₂ f (g ∘ k) := by apply MvPolynomial.induction_on p <;> · intros simp [*] theorem eval_rename (g : τ → R) (p : MvPolynomial σ R) : eval g (rename k p) = eval (g ∘ k) p := eval₂_rename _ _ _ _ theorem eval₂Hom_rename : eval₂Hom f g (rename k p) = eval₂Hom f (g ∘ k) p := eval₂_rename _ _ _ _ theorem aeval_rename [Algebra R S] : aeval g (rename k p) = aeval (g ∘ k) p := eval₂Hom_rename _ _ _ _ lemma aeval_comp_rename [Algebra R S] : (aeval (R := R) g).comp (rename k) = MvPolynomial.aeval (g ∘ k) := AlgHom.ext fun p ↦ aeval_rename k g p theorem rename_eval₂ (g : τ → MvPolynomial σ R) : rename k (p.eval₂ C (g ∘ k)) = (rename k p).eval₂ C (rename k ∘ g) := by apply MvPolynomial.induction_on p <;> · intros simp [*] theorem rename_prod_mk_eval₂ (j : τ) (g : σ → MvPolynomial σ R) : rename (Prod.mk j) (p.eval₂ C g) = p.eval₂ C fun x => rename (Prod.mk j) (g x) := by apply MvPolynomial.induction_on p <;> · intros simp [*] theorem eval₂_rename_prod_mk (g : σ × τ → S) (i : σ) (p : MvPolynomial τ R) : (rename (Prod.mk i) p).eval₂ f g = eval₂ f (fun j => g (i, j)) p := by apply MvPolynomial.induction_on p <;> · intros simp [*] theorem eval_rename_prod_mk (g : σ × τ → R) (i : σ) (p : MvPolynomial τ R) : eval g (rename (Prod.mk i) p) = eval (fun j => g (i, j)) p := eval₂_rename_prod_mk (RingHom.id _) _ _ _ end /-- Every polynomial is a polynomial in finitely many variables. -/ theorem exists_finset_rename (p : MvPolynomial σ R) : ∃ (s : Finset σ) (q : MvPolynomial { x // x ∈ s } R), p = rename (↑) q := by classical apply induction_on p · intro r exact ⟨∅, C r, by rw [rename_C]⟩ · rintro p q ⟨s, p, rfl⟩ ⟨t, q, rfl⟩ refine ⟨s ∪ t, ⟨?_, ?_⟩⟩ · refine rename (Subtype.map id ?_) p + rename (Subtype.map id ?_) q <;> simp +contextual only [id, true_or, or_true, Finset.mem_union, forall_true_iff] · simp only [rename_rename, map_add] rfl · rintro p n ⟨s, p, rfl⟩ refine ⟨insert n s, ⟨?_, ?_⟩⟩ · refine rename (Subtype.map id ?_) p * X ⟨n, s.mem_insert_self n⟩ simp +contextual only [id, or_true, Finset.mem_insert, forall_true_iff] · simp only [rename_rename, rename_X, Subtype.coe_mk, map_mul] rfl /-- `exists_finset_rename` for two polynomials at once: for any two polynomials `p₁`, `p₂` in a polynomial semiring `R[σ]` of possibly infinitely many variables, `exists_finset_rename₂` yields a finite subset `s` of `σ` such that both `p₁` and `p₂` are contained in the polynomial semiring `R[s]` of finitely many variables. -/ theorem exists_finset_rename₂ (p₁ p₂ : MvPolynomial σ R) : ∃ (s : Finset σ) (q₁ q₂ : MvPolynomial s R), p₁ = rename (↑) q₁ ∧ p₂ = rename (↑) q₂ := by obtain ⟨s₁, q₁, rfl⟩ := exists_finset_rename p₁ obtain ⟨s₂, q₂, rfl⟩ := exists_finset_rename p₂ classical use s₁ ∪ s₂ use rename (Set.inclusion s₁.subset_union_left) q₁ use rename (Set.inclusion s₁.subset_union_right) q₂ constructor <;> simp [Function.comp_def] /-- Every polynomial is a polynomial in finitely many variables. -/ theorem exists_fin_rename (p : MvPolynomial σ R) : ∃ (n : ℕ) (f : Fin n → σ) (_hf : Injective f) (q : MvPolynomial (Fin n) R), p = rename f q := by obtain ⟨s, q, rfl⟩ := exists_finset_rename p let n := Fintype.card { x // x ∈ s } let e := Fintype.equivFin { x // x ∈ s } refine ⟨n, (↑) ∘ e.symm, Subtype.val_injective.comp e.symm.injective, rename e q, ?_⟩ rw [← rename_rename, rename_rename e] simp only [Function.comp_def, Equiv.symm_apply_apply, rename_rename] end Rename theorem eval₂_cast_comp (f : σ → τ) (c : ℤ →+* R) (g : τ → R) (p : MvPolynomial σ ℤ) : eval₂ c (g ∘ f) p = eval₂ c g (rename f p) := by apply MvPolynomial.induction_on p (fun n => by simp only [eval₂_C, rename_C]) (fun p q hp hq => by simp only [hp, hq, rename, eval₂_add, map_add]) fun p n hp => by simp only [eval₂_mul, hp, eval₂_X, comp_apply, map_mul, rename_X, eval₂_mul] section Coeff @[simp] theorem coeff_rename_mapDomain (f : σ → τ) (hf : Injective f) (φ : MvPolynomial σ R) (d : σ →₀ ℕ) : (rename f φ).coeff (d.mapDomain f) = φ.coeff d := by classical apply φ.induction_on' (P := fun ψ => coeff (Finsupp.mapDomain f d) ((rename f) ψ) = coeff d ψ) -- Lean could no longer infer the motive · intro u r rw [rename_monomial, coeff_monomial, coeff_monomial] simp only [(Finsupp.mapDomain_injective hf).eq_iff] · intros simp only [*, map_add, coeff_add]
@[simp] theorem coeff_rename_embDomain (f : σ ↪ τ) (φ : MvPolynomial σ R) (d : σ →₀ ℕ) : (rename f φ).coeff (d.embDomain f) = φ.coeff d := by rw [Finsupp.embDomain_eq_mapDomain f, coeff_rename_mapDomain f f.injective] theorem coeff_rename_eq_zero (f : σ → τ) (φ : MvPolynomial σ R) (d : τ →₀ ℕ) (h : ∀ u : σ →₀ ℕ, u.mapDomain f = d → φ.coeff u = 0) : (rename f φ).coeff d = 0 := by classical rw [rename_eq, ← not_mem_support_iff] intro H
Mathlib/Algebra/MvPolynomial/Rename.lean
294
303
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `K.orthogonalProjection : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = K.orthogonalProjection u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `K.reflection : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `K.reflection u` to satisfy `u + (K.reflection u) = 2 • K.orthogonalProjection u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open InnerProductSpace open RCLike Real Filter open LinearMap (ker range) open Topology Finsupp variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- **Existence of minimizers**, aka the **Hilbert projection theorem**. Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by fun_prop) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this exact le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ variable (K : Submodule 𝕜 E) namespace Submodule /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superseded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).1 H intro w hw apply RCLike.ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).2 this /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if every vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : K.HasOrthogonalProjection where exists_orthogonal v := by rcases K.exists_norm_eq_iInf_of_complete_subspace (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← K.norm_eq_iInf_iff_inner_eq_zero hwK] instance [K.HasOrthogonalProjection] : Kᗮ.HasOrthogonalProjection where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [K.HasOrthogonalProjection] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')).HasOrthogonalProjection where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [K.HasOrthogonalProjection] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : (K.map f.toLinearIsometry).HasOrthogonalProjection := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : (⊤ : Submodule 𝕜 E).HasOrthogonalProjection := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [K.HasOrthogonalProjection] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose variable {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem (v : E) : K.orthogonalProjectionFn v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - K.orthogonalProjectionFn v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : K.orthogonalProjectionFn u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : K.orthogonalProjectionFn u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - K.orthogonalProjectionFn u, K.orthogonalProjectionFn u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, K.orthogonalProjectionFn u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - K.orthogonalProjectionFn u), K.orthogonalProjectionFn u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - K.orthogonalProjectionFn v‖ * ‖v - K.orthogonalProjectionFn v‖ + ‖K.orthogonalProjectionFn v‖ * ‖K.orthogonalProjectionFn v‖ := by set p := K.orthogonalProjectionFn v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨K.orthogonalProjectionFn v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : K.orthogonalProjectionFn x + K.orthogonalProjectionFn y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (K.orthogonalProjectionFn x + K.orthogonalProjectionFn y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • K.orthogonalProjectionFn x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • K.orthogonalProjectionFn x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left₀ two_ne_zero (norm_nonneg _) ?_ change ‖K.orthogonalProjectionFn x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [K.orthogonalProjectionFn_norm_sq x] variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : K.orthogonalProjectionFn v = (K.orthogonalProjection v : E) := rfl /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - K.orthogonalProjection v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - K.orthogonalProjection v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (K.orthogonalProjection u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (K.orthogonalProjection u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (K.orthogonalProjection u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (Kᗮ.orthogonalProjection u : E) = u - K.orthogonalProjection u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (K.orthogonalProjection u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : Kᗮ.orthogonalProjection u = ⟨u - K.orthogonalProjection u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [U.HasOrthogonalProjection] (y : E) : ‖y - U.orthogonalProjection y‖ = ⨅ x : U, ‖y - x‖ := by rw [U.norm_eq_iInf_iff_inner_eq_zero (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [K'.HasOrthogonalProjection] (h : K = K') (u : E) : (K.orthogonalProjection u : E) = (K'.orthogonalProjection u : E) := by subst h; rfl /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp] theorem orthogonalProjection_mem_subspace_eq_self (v : K) : K.orthogonalProjection v = v := by ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp /-- A point equals its orthogonal projection if and only if it lies in the subspace. -/ theorem orthogonalProjection_eq_self_iff {v : E} : (K.orthogonalProjection v : E) = v ↔ v ∈ K := by refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩ · rw [← h] simp · simp @[simp] theorem orthogonalProjection_eq_zero_iff {v : E} : K.orthogonalProjection v = 0 ↔ v ∈ Kᗮ := by refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal (zero_mem _) ?_⟩ · simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v · simpa @[simp] theorem ker_orthogonalProjection : LinearMap.ker K.orthogonalProjection = Kᗮ := by ext; exact orthogonalProjection_eq_zero_iff theorem _root_.LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f.toLinearMap).HasOrthogonalProjection] (x : E) : f (p.orthogonalProjection x) = (p.map f.toLinearMap).orthogonalProjection (f x) := by refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm · refine Submodule.apply_coe_mem_map _ _ rcases hy with ⟨x', hx', rfl : f x' = y⟩ rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx'] theorem _root_.LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f).HasOrthogonalProjection] (x : E) : f (p.orthogonalProjection x) = (p.map f).orthogonalProjection (f x) := have : (p.map f.toLinearMap).HasOrthogonalProjection := ‹_› f.map_orthogonalProjection p x /-- Orthogonal projection onto the `Submodule.map` of a subspace. -/ theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : Submodule 𝕜 E) [p.HasOrthogonalProjection] (x : E') : ((p.map (f.toLinearEquiv : E →ₗ[𝕜] E')).orthogonalProjection x : E') = f (p.orthogonalProjection (f.symm x)) := by simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using (f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm /-- The orthogonal projection onto the trivial submodule is the zero map. -/ @[simp] theorem orthogonalProjection_bot : (⊥ : Submodule 𝕜 E).orthogonalProjection = 0 := by ext variable (K) /-- The orthogonal projection has norm `≤ 1`. -/ theorem orthogonalProjection_norm_le : ‖K.orthogonalProjection‖ ≤ 1 := LinearMap.mkContinuous_norm_le _ (by norm_num) _ variable (𝕜) theorem smul_orthogonalProjection_singleton {v : E} (w : E) : ((‖v‖ ^ 2 : ℝ) : 𝕜) • ((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by suffices (((𝕜 ∙ v).orthogonalProjection (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by simpa using this apply eq_orthogonalProjection_of_mem_of_inner_eq_zero · rw [Submodule.mem_span_singleton] use ⟪v, w⟫ · rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left] simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm] /-- Formula for orthogonal projection onto a single vector. -/ theorem orthogonalProjection_singleton {v : E} (w : E) : ((𝕜 ∙ v).orthogonalProjection w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by
by_cases hv : v = 0
Mathlib/Analysis/InnerProductSpace/Projection.lean
604
604
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Adam Topaz, Eric Wieser -/ import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.FreeMonoid.UniqueProds import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Algebra.MonoidAlgebra.NoZeroDivisors /-! # Free Algebras Given a commutative semiring `R`, and a type `X`, we construct the free unital, associative `R`-algebra on `X`. ## Notation 1. `FreeAlgebra R X` is the free algebra itself. It is endowed with an `R`-algebra structure. 2. `FreeAlgebra.ι R` is the function `X → FreeAlgebra R X`. 3. Given a function `f : X → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `FreeAlgebra R X → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : FreeAlgebra R X → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. 5. `equivMonoidAlgebraFreeMonoid : FreeAlgebra R X ≃ₐ[R] MonoidAlgebra R (FreeMonoid X)` 6. An inductive principle `induction`. ## Implementation details We construct the free algebra on `X` as a quotient of an inductive type `FreeAlgebra.Pre` by an inductively defined relation `FreeAlgebra.Rel`. Explicitly, the construction involves three steps: 1. We construct an inductive type `FreeAlgebra.Pre R X`, the terms of which should be thought of as representatives for the elements of `FreeAlgebra R X`. It is the free type with maps from `R` and `X`, and with two binary operations `add` and `mul`. 2. We construct an inductive relation `FreeAlgebra.Rel R X` on `FreeAlgebra.Pre R X`. This is the smallest relation for which the quotient is an `R`-algebra where addition resp. multiplication are induced by `add` resp. `mul` from 1., and for which the map from `R` is the structure map for the algebra. 3. The free algebra `FreeAlgebra R X` is the quotient of `FreeAlgebra.Pre R X` by the relation `FreeAlgebra.Rel R X`. -/ variable (R : Type*) [CommSemiring R] variable (X : Type*) namespace FreeAlgebra /-- This inductive type is used to express representatives of the free algebra. -/ inductive Pre | of : X → Pre | ofScalar : R → Pre | add : Pre → Pre → Pre | mul : Pre → Pre → Pre namespace Pre instance : Inhabited (Pre R X) := ⟨ofScalar 0⟩ -- Note: These instances are only used to simplify the notation. /-- Coercion from `X` to `Pre R X`. Note: Used for notation only. -/ def hasCoeGenerator : Coe X (Pre R X) := ⟨of⟩ /-- Coercion from `R` to `Pre R X`. Note: Used for notation only. -/ def hasCoeSemiring : Coe R (Pre R X) := ⟨ofScalar⟩ /-- Multiplication in `Pre R X` defined as `Pre.mul`. Note: Used for notation only. -/ def hasMul : Mul (Pre R X) := ⟨mul⟩ /-- Addition in `Pre R X` defined as `Pre.add`. Note: Used for notation only. -/ def hasAdd : Add (Pre R X) := ⟨add⟩ /-- Zero in `Pre R X` defined as the image of `0` from `R`. Note: Used for notation only. -/ def hasZero : Zero (Pre R X) := ⟨ofScalar 0⟩ /-- One in `Pre R X` defined as the image of `1` from `R`. Note: Used for notation only. -/ def hasOne : One (Pre R X) := ⟨ofScalar 1⟩ /-- Scalar multiplication defined as multiplication by the image of elements from `R`. Note: Used for notation only. -/ def hasSMul : SMul R (Pre R X) := ⟨fun r m ↦ mul (ofScalar r) m⟩ end Pre attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd Pre.hasZero Pre.hasOne Pre.hasSMul /-- Given a function from `X` to an `R`-algebra `A`, `lift_fun` provides a lift of `f` to a function from `Pre R X` to `A`. This is mainly used in the construction of `FreeAlgebra.lift`. -/ def liftFun {A : Type*} [Semiring A] [Algebra R A] (f : X → A) : Pre R X → A | .of t => f t | .add a b => liftFun f a + liftFun f b | .mul a b => liftFun f a * liftFun f b | .ofScalar c => algebraMap _ _ c /-- An inductively defined relation on `Pre R X` used to force the initial algebra structure on the associated quotient. -/ inductive Rel : Pre R X → Pre R X → Prop -- force `ofScalar` to be a central semiring morphism | add_scalar {r s : R} : Rel (↑(r + s)) (↑r + ↑s) | mul_scalar {r s : R} : Rel (↑(r * s)) (↑r * ↑s) | central_scalar {r : R} {a : Pre R X} : Rel (r * a) (a * r) -- commutative additive semigroup | add_assoc {a b c : Pre R X} : Rel (a + b + c) (a + (b + c)) | add_comm {a b : Pre R X} : Rel (a + b) (b + a) | zero_add {a : Pre R X} : Rel (0 + a) a -- multiplicative monoid | mul_assoc {a b c : Pre R X} : Rel (a * b * c) (a * (b * c)) | one_mul {a : Pre R X} : Rel (1 * a) a | mul_one {a : Pre R X} : Rel (a * 1) a -- distributivity | left_distrib {a b c : Pre R X} : Rel (a * (b + c)) (a * b + a * c) | right_distrib {a b c : Pre R X} : Rel ((a + b) * c) (a * c + b * c) -- other relations needed for semiring | zero_mul {a : Pre R X} : Rel (0 * a) 0 | mul_zero {a : Pre R X} : Rel (a * 0) 0 -- compatibility | add_compat_left {a b c : Pre R X} : Rel a b → Rel (a + c) (b + c) | add_compat_right {a b c : Pre R X} : Rel a b → Rel (c + a) (c + b) | mul_compat_left {a b c : Pre R X} : Rel a b → Rel (a * c) (b * c) | mul_compat_right {a b c : Pre R X} : Rel a b → Rel (c * a) (c * b) end FreeAlgebra /-- If `α` is a type, and `R` is a commutative semiring, then `FreeAlgebra R α` is the free (unital, associative) `R`-algebra generated by `α`. This is an `R`-algebra equipped with a function `FreeAlgebra.ι R : α → FreeAlgebra R α` which has the following universal property: if `A` is any `R`-algebra, and `f : α → A` is any function, then this function is the composite of `FreeAlgebra.ι R` and a unique `R`-algebra homomorphism `FreeAlgebra.lift R f : FreeAlgebra R α →ₐ[R] A`. A typical element of `FreeAlgebra R α` is an `R`-linear combination of formal products of elements of `α`. For example if `x` and `y` are terms of type `α` and `a`, `b` are terms of type `R` then `(3 * a * a) • (x * y * x) + (2 * b + 1) • (y * x) + (a * b * b + 3)` is a "typical" element of `FreeAlgebra R α`. In particular if `α` is empty then `FreeAlgebra R α` is isomorphic to `R`, and if `α` has one term `t` then `FreeAlgebra R α` is isomorphic to the polynomial ring `R[t]`. If `α` has two or more terms then `FreeAlgebra R α` is not commutative. One can think of `FreeAlgebra R α` as the free non-commutative polynomial ring with coefficients in `R` and variables indexed by `α`. -/ def FreeAlgebra := Quot (FreeAlgebra.Rel R X) namespace FreeAlgebra attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd Pre.hasZero Pre.hasOne Pre.hasSMul /-! Define the basic operations -/ instance instSMul {A} [CommSemiring A] [Algebra R A] : SMul R (FreeAlgebra A X) where smul r := Quot.map (HMul.hMul (algebraMap R A r : Pre A X)) fun _ _ ↦ Rel.mul_compat_right instance instZero : Zero (FreeAlgebra R X) where zero := Quot.mk _ 0 instance instOne : One (FreeAlgebra R X) where one := Quot.mk _ 1 instance instAdd : Add (FreeAlgebra R X) where add := Quot.map₂ HAdd.hAdd (fun _ _ _ ↦ Rel.add_compat_right) fun _ _ _ ↦ Rel.add_compat_left instance instMul : Mul (FreeAlgebra R X) where mul := Quot.map₂ HMul.hMul (fun _ _ _ ↦ Rel.mul_compat_right) fun _ _ _ ↦ Rel.mul_compat_left -- `Quot.mk` is an implementation detail of `FreeAlgebra`, so this lemma is private private theorem mk_mul (x y : Pre R X) : Quot.mk (Rel R X) (x * y) = (HMul.hMul (self := instHMul (α := FreeAlgebra R X)) (Quot.mk (Rel R X) x) (Quot.mk (Rel R X) y)) := rfl /-! Build the semiring structure. We do this one piece at a time as this is convenient for proving the `nsmul` fields. -/ instance instMonoidWithZero : MonoidWithZero (FreeAlgebra R X) where mul_assoc := by rintro ⟨⟩ ⟨⟩ ⟨⟩ exact Quot.sound Rel.mul_assoc one := Quot.mk _ 1 one_mul := by rintro ⟨⟩ exact Quot.sound Rel.one_mul mul_one := by rintro ⟨⟩ exact Quot.sound Rel.mul_one zero_mul := by rintro ⟨⟩ exact Quot.sound Rel.zero_mul mul_zero := by rintro ⟨⟩ exact Quot.sound Rel.mul_zero instance instDistrib : Distrib (FreeAlgebra R X) where left_distrib := by rintro ⟨⟩ ⟨⟩ ⟨⟩ exact Quot.sound Rel.left_distrib right_distrib := by rintro ⟨⟩ ⟨⟩ ⟨⟩ exact Quot.sound Rel.right_distrib instance instAddCommMonoid : AddCommMonoid (FreeAlgebra R X) where add_assoc := by rintro ⟨⟩ ⟨⟩ ⟨⟩ exact Quot.sound Rel.add_assoc zero_add := by rintro ⟨⟩ exact Quot.sound Rel.zero_add add_zero := by rintro ⟨⟩ change Quot.mk _ _ = _ rw [Quot.sound Rel.add_comm, Quot.sound Rel.zero_add] add_comm := by rintro ⟨⟩ ⟨⟩ exact Quot.sound Rel.add_comm nsmul := (· • ·) nsmul_zero := by rintro ⟨⟩ change Quot.mk _ (_ * _) = _ rw [map_zero] exact Quot.sound Rel.zero_mul nsmul_succ n := by rintro ⟨a⟩ dsimp only [HSMul.hSMul, instSMul, Quot.map] rw [map_add, map_one, mk_mul, mk_mul, ← add_one_mul (_ : FreeAlgebra R X)] congr 1 exact Quot.sound Rel.add_scalar instance : Semiring (FreeAlgebra R X) where __ := instMonoidWithZero R X __ := instAddCommMonoid R X __ := instDistrib R X natCast n := Quot.mk _ (n : R) natCast_zero := by simp; rfl natCast_succ n := by simpa using Quot.sound Rel.add_scalar instance : Inhabited (FreeAlgebra R X) := ⟨0⟩ instance instAlgebra {A} [CommSemiring A] [Algebra R A] : Algebra R (FreeAlgebra A X) where algebraMap := ({ toFun := fun r => Quot.mk _ r map_one' := rfl map_mul' := fun _ _ => Quot.sound Rel.mul_scalar map_zero' := rfl map_add' := fun _ _ => Quot.sound Rel.add_scalar } : A →+* FreeAlgebra A X).comp (algebraMap R A) commutes' _ := by rintro ⟨⟩ exact Quot.sound Rel.central_scalar smul_def' _ _ := rfl -- verify there is no diamond at `default` transparency but we will need -- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906 variable (S : Type) [CommSemiring S] in example : (Semiring.toNatAlgebra : Algebra ℕ (FreeAlgebra S X)) = instAlgebra _ _ := rfl instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A] [SMul R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] : IsScalarTower R S (FreeAlgebra A X) where smul_assoc r s x := by change algebraMap S A (r • s) • x = algebraMap R A _ • (algebraMap S A _ • x) rw [← smul_assoc] congr simp only [Algebra.algebraMap_eq_smul_one, smul_eq_mul] rw [smul_assoc, ← smul_one_mul] instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A] [Algebra R A] [Algebra S A] : SMulCommClass R S (FreeAlgebra A X) where smul_comm r s x := smul_comm (algebraMap R A r) (algebraMap S A s) x instance {S : Type*} [CommRing S] : Ring (FreeAlgebra S X) := Algebra.semiringToRing S -- verify there is no diamond but we will need -- `reducible_and_instances` which currently fails https://github.com/leanprover-community/mathlib4/issues/10906 variable (S : Type) [CommRing S] in example : (Ring.toIntAlgebra _ : Algebra ℤ (FreeAlgebra S X)) = instAlgebra _ _ := rfl variable {X} /-- The canonical function `X → FreeAlgebra R X`. -/ irreducible_def ι : X → FreeAlgebra R X := fun m ↦ Quot.mk _ m
Mathlib/Algebra/FreeAlgebra.lean
303
303
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/
theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul]
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
109
118
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction n generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb rw [← image_comp, comm] exact ⟨a, ha, rfl⟩ lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ /-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`, then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/ theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t') (ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f rw [image_diff_preimage, image_inter_preimage] at hbij refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩ · exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left · rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff] exact ⟨htt', diff_subset.trans inter_subset_right⟩ · rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn] · refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_ rw [← h.image_eq] exact ⟨x, hxs, hxy⟩ exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo rw [image_union, h.image_eq, hbij.image_eq, union_diff_self] exact .inr ⟨ht' hyt', hyt'⟩ /-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`, then `f` maps some superset of `s` bijectively to `t'`. -/ theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) : ∃ s', s ⊆ s' ∧ BijOn f s' t' := by simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn]) theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) : ∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs (image_subset f hrs) Subset.rfl exact ⟨u, hru, hus, h.image_eq, h.injOn⟩ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ end Set namespace Function open Set variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α} theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) := hg.injOn.comp hf (mapsTo_univ _ _) theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s := (surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _) theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s := fun x _ => h x theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) : RightInvOn f g s := fun x _ => h x theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) : RightInvOn f g (range g) := forall_mem_range.2 fun i => congr_arg g (h i) namespace Semiconj theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) := fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩ theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) : MapsTo f (fa '' s) (fb '' t) := mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩ theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ => hy ▸ ⟨fa x, h x⟩ theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by rintro y ⟨x, hxt, rfl⟩ rcases ha hxt with ⟨x, hxs, rfl⟩ rw [h x] exact mem_image_of_mem _ (mem_image_of_mem _ hxs) theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) : SurjOn fb (range f) (range f) := by rw [← image_univ] exact h.surjOn_image (ha.surjOn univ) theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) : InjOn fb (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H simp only [← h.eq] at H exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H) theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) : InjOn fb (range f) := by rw [← image_univ] at * exact h.injOn_image ha.injOn hf theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) : BijOn fb (f '' s) (f '' t) := ⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf), h.surjOn_image ha.surjOn⟩ theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) : BijOn fb (range f) (range f) := by rw [← image_univ] exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) : MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx] theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s) (hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by intro x hx y hy H have := congr_arg f H rw [h.eq, h.eq] at this exact hf hx hy (hb hx hy this) end Semiconj theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β] (g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) : (fun j => update g i a (f j)) = fun j => g (f j) := (update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩ /-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/ theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β] (g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f := update_comp_eq_of_not_mem_range' g a h theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ => (insert_inj ha).1 lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) : f a = b := by simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a end Function /-! ### Equivalences, permutations -/ namespace Set variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α} protected lemma MapsTo.extendDomain (h : MapsTo g s t) : MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma SurjOn.extendDomain (h : SurjOn g s t) : SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩ obtain ⟨b, hb, rfl⟩ := h ha exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma BijOn.extendDomain (h : BijOn g s t) : BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩ protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) : LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) : RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) : InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.1.extendDomain, h.2.extendDomain⟩ end Set namespace Set variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂} {f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂} lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) : (s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) := fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2) lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) : SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by rintro x hx obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1 obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2 exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩ lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) : MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩ lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) : BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩ lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) : LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) : RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) : InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩ end Set namespace Equiv open Set variable (e : α ≃ β) {s : Set α} {t : Set β} lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t := ⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩ protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t := e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply] lemma invOn : InvOn e e.symm t s := ⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩ lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn variable {e} @[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm variable [DecidableEq α] {a b : α} lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s := (swap a b).bijOn fun x ↦ by obtain rfl | hxa := eq_or_ne x a <;> obtain rfl | hxb := eq_or_ne x b <;> simp [*, swap_apply_of_ne_of_ne] end Equiv
Mathlib/Data/Set/Function.lean
1,689
1,693
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Opposites import Mathlib.Algebra.GroupWithZero.InjSurj /-! # Pulling back rings along injective maps, and pushing them forward along surjective maps -/ variable {R S : Type*} namespace Function.Injective variable (f : S → R) (hf : Injective f) include hf variable [Add S] [Mul S] /-- Pullback a `LeftDistribClass` instance along an injective function. -/ theorem leftDistribClass [Mul R] [Add R] [LeftDistribClass R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : LeftDistribClass S where left_distrib x y z := hf <| by simp only [*, left_distrib] /-- Pullback a `RightDistribClass` instance along an injective function. -/
theorem rightDistribClass [Mul R] [Add R] [RightDistribClass R] (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) : RightDistribClass S where right_distrib x y z := hf <| by simp only [*, right_distrib]
Mathlib/Algebra/Ring/InjSurj.lean
28
30
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.InnerProductSpace.Subspace import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # Angles between vectors This file defines unoriented angles in real inner product spaces. ## Main definitions * `InnerProductGeometry.angle` is the undirected angle between two vectors. ## TODO Prove the triangle inequality for the angle. -/ assert_not_exists HasFDerivAt ConformalAt noncomputable section open Real Set open Real open RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V} /-- The undirected angle between two vectors. If either vector is 0, this is π/2. See `Orientation.oangle` for the corresponding oriented angle definition. -/ def angle (x y : V) : ℝ := Real.arccos (⟪x, y⟫ / (‖x‖ * ‖y‖)) theorem continuousAt_angle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => angle y.1 y.2) x := by unfold angle fun_prop (disch := simp [*]) theorem angle_smul_smul {c : ℝ} (hc : c ≠ 0) (x y : V) : angle (c • x) (c • y) = angle x y := by have : c * c ≠ 0 := mul_ne_zero hc hc rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs, mul_mul_mul_comm _ ‖x‖, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this] @[simp] theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F] [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] (f : E →ₗᵢ[ℝ] F) (u v : E) : angle (f u) (f v) = angle u v := by rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map] @[simp, norm_cast] theorem _root_.Submodule.angle_coe {s : Submodule ℝ V} (x y : s) : angle (x : V) (y : V) = angle x y := s.subtypeₗᵢ.angle_map x y /-- The cosine of the angle between two vectors. -/ theorem cos_angle (x y : V) : Real.cos (angle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1 (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2 /-- The angle between two vectors does not depend on their order. -/ theorem angle_comm (x y : V) : angle x y = angle y x := by unfold angle rw [real_inner_comm, mul_comm] /-- The angle between the negation of two vectors. -/ @[simp] theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by unfold angle rw [inner_neg_neg, norm_neg, norm_neg] /-- The angle between two vectors is nonnegative. -/ theorem angle_nonneg (x y : V) : 0 ≤ angle x y := Real.arccos_nonneg _ /-- The angle between two vectors is at most π. -/ theorem angle_le_pi (x y : V) : angle x y ≤ π := Real.arccos_le_pi _ /-- The sine of the angle between two vectors is nonnegative. -/
theorem sin_angle_nonneg (x y : V) : 0 ≤ sin (angle x y) := sin_nonneg_of_nonneg_of_le_pi (angle_nonneg x y) (angle_le_pi x y)
Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean
90
92
/- 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.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.FixedPoint /-! # Cofinality This file contains the definition of cofinality of an order and an ordinal number. ## Main Definitions * `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset `s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`. * `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order. ## Main Statements * `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for `c ≥ ℵ₀`. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. -/ noncomputable section open Function Cardinal Set Order open scoped Ordinal universe u v w variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop} /-! ### Cofinality of orders -/ attribute [local instance] IsRefl.swap namespace Order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) : Cardinal := sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c } /-- The set in the definition of `Order.cof` is nonempty. -/ private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] : { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S := csInf_le' ⟨S, h, rfl⟩ theorem le_cof [IsRefl α r] (c : Cardinal) : c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h end Order namespace RelIso private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) := have := f.toRelEmbedding.isRefl (f.cof_le_lift).antisymm (f.symm.cof_le_lift) theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (f.cof_eq_lift) end RelIso /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`. In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) := rfl theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] : (@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by rw [cof_type, compl_lt, swap_ge] theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by conv_lhs => rw [← type_toType o, cof_type_lt] theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S := (le_csInf_iff'' (Order.cof_nonempty _)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S := le_cof_type.1 le_rfl S h theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by simpa using not_imp_not.2 cof_type_le theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (Order.cof_nonempty (swap rᶜ)) theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ · exact asymm h (ha _ hn) · intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | ¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : ¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card := ⟨_, _, lsub_typein o, mk_toType o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty := ⟨_, card_mem_cof⟩ theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) · rintro a ⟨ι, f, hf, rfl⟩ rw [← type_toType o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this obtain ⟨i, hi⟩ := this refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩ · rw [type_toType, ← hf] apply lt_lsub · rw [mem_preimage, typein_enum] exact mem_range_self i · rwa [← typein_le_typein, typein_enum] · rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩ let f : S → Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩ rw [← type_toType o] at ha rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) @[simp] theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by refine inductionOn o fun α r _ ↦ ?_ rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _), ← Cardinal.lift_umax] apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩ simp [swap] theorem cof_le_card (o) : cof o ≤ card o := by rw [cof_eq_sInf_lsub] exact csInf_le' card_mem_cof theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o := (ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o) theorem exists_lsub_cof (o : Ordinal) : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by rw [cof_eq_sInf_lsub] exact csInf_mem (cof_lsub_def_nonempty o) theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by rw [cof_eq_sInf_lsub] exact csInf_le' ⟨ι, f, rfl, rfl⟩ theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) : cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← mk_uLift.{u, v}] convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down exact lsub_eq_of_range_eq.{u, max u v, max u v} (Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩) theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} : a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by rw [cof_eq_sInf_lsub] exact (le_csInf_iff'' (cof_lsub_def_nonempty o)).trans ⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by rw [← hb] exact H _ hf⟩ theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : lsub.{u, v} f < c := lt_of_le_of_ne (lsub_le hf) fun h => by subst h exact (cof_lsub_le_lift.{u, v} f).not_lt hι theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → lsub.{u, u} f < c := lsub_lt_ord_lift (by rwa [(#ι).lift_id]) theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) : cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by rw [← Ordinal.sup] at * rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H rw [H] exact cof_lsub_le_lift f theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) : cof (iSup f) ≤ #ι := by rw [← (#ι).lift_id] exact cof_iSup_le_lift H theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : iSup f < c := (sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf) theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_ord_lift (by rwa [(#ι).lift_id]) theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal} (hι : Cardinal.lift.{v, u} #ι < c.ord.cof) (hf : ∀ i, f i < c) : iSup f < c := by rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)] refine iSup_lt_ord_lift hι fun i => ?_ rw [ord_lt_ord] apply hf theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_lift (by rwa [(#ι).lift_id]) theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) : nfpFamily f a < c := by refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_ · rw [lift_max] apply max_lt _ hc' rwa [Cardinal.lift_aleph0] · induction' l with i l H · exact ha · exact hf _ _ H theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c := nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} : a < c → nfp f a < c := nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf theorem exists_blsub_cof (o : Ordinal) : ∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩ rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf rw [← hι, hι'] exact ⟨_, hf⟩ theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} : a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card := le_cof_iff_lsub.trans ⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf simpa using H _ hf⟩ theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← mk_toType o] exact cof_lsub_le_lift _ theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_blsub_le_lift f theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c := lt_of_le_of_ne (blsub_le hf) fun h => ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f) theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c := blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) : cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H rw [H] exact cof_blsub_le_lift.{u, v} f theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} : (∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_bsup_le_lift theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c := (bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf) theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) : (∀ i hi, f i hi < c) → bsup.{u, u} o f < c := bsup_lt_ord_lift (by rwa [o.card.lift_id]) /-! ### Basic results -/ @[simp] theorem cof_zero : cof 0 = 0 := by refine LE.le.antisymm ?_ (Cardinal.zero_le _) rw [← card_zero] exact cof_le_card 0 @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨inductionOn o fun _ r _ z => let ⟨_, hl, e⟩ := cof_eq r type_eq_zero_iff_isEmpty.2 <| ⟨fun a => let ⟨_, h, _⟩ := hl a (mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩, fun e => by simp [e]⟩ theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 := cof_eq_zero.not @[simp] theorem cof_succ (o) : cof (succ o) = 1 := by apply le_antisymm · refine inductionOn o fun α r _ => ?_ change cof (type _) ≤ _ rw [← (_ : #_ = 1)] · apply cof_type_le refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩ rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation] · rw [Cardinal.mk_fintype, Set.card_singleton] simp · rw [← Cardinal.succ_zero, succ_le_iff] simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h => succ_ne_zero o (cof_eq_zero.1 (Eq.symm h)) @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a := ⟨inductionOn o fun α r _ z => by rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) refine ⟨typein r a, Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩ · apply Sum.rec <;> [exact Subtype.val; exact fun _ => a] · rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;> simp [Subrel, Order.Preimage, EmptyRelation] exact x.2 · suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by convert this dsimp [RelEmbedding.ofMonotone]; simp rcases trichotomous_of r x a with (h | h | h) · exact Or.inl h · exact Or.inr ⟨PUnit.unit, h.symm⟩ · rcases hl x with ⟨a', aS, hn⟩ refine absurd h ?_ convert hn change (a : α) = ↑(⟨a', aS⟩ : S) have := le_one_iff_subsingleton.1 (le_of_eq e) congr!, fun ⟨a, e⟩ => by simp [e]⟩ /-! ### Fundamental sequences -/ -- TODO: move stuff about fundamental sequences to their own file. /-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at `a`. We provide `o` explicitly in order to avoid type rewrites. -/ def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop := o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a namespace IsFundamentalSequence variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o := hf.1.antisymm' <| by rw [← hf.2.2] exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o) protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} : ∀ hi hj, i < j → f i hi < f j hj := hf.2.1 theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a := hf.2.2 theorem ord_cof (hf : IsFundamentalSequence a o f) : IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by have H := hf.cof_eq subst H exact hf theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a := ⟨h, @fun _ _ _ _ => id, blsub_id o⟩ protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f := ⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩ protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩ · rw [cof_succ, ord_one] · rw [lt_one_iff_zero] at hi hj rw [hi, hj] at h exact h.false.elim protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o) (hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by rcases lt_or_eq_of_le hij with (hij | rfl) · exact (hf.2.1 hi hj hij).le · rfl theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f) {g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) : IsFundamentalSequence a o' fun i hi => f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩ · rw [hf.cof_eq] exact hg.1.trans (ord_cof_le o) · rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)] · exact hf.2.2 · exact hg.2.2 protected theorem lt {a o : Ordinal} {s : Π p < o, Ordinal} (h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a := h.blsub_eq ▸ lt_blsub s p hp end IsFundamentalSequence /-- Every ordinal has a fundamental sequence. -/ theorem exists_fundamental_sequence (a : Ordinal.{u}) : ∃ f, IsFundamentalSequence a a.cof.ord f := by suffices h : ∃ o f, IsFundamentalSequence a o f by rcases h with ⟨o, f, hf⟩ exact ⟨_, hf.ord_cof⟩ rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩ rcases ord_eq ι with ⟨r, wo, hr⟩ haveI := wo let r' := Subrel r fun i ↦ ∀ j, r j i → f j < f i let hrr' : r' ↪r r := Subrel.relEmbedding _ _ haveI := hrr'.isWellOrder refine ⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' ⟨j, h⟩).prop _ ?_, le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩ · rw [← hι, hr] · change r (hrr'.1 _) (hrr'.1 _) rwa [hrr'.2, @enum_lt_enum _ r'] · rw [← hf, lsub_le_iff] intro i suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by rcases h with ⟨i', hi', hfg⟩ exact hfg.trans_lt (lt_blsub _ _ _) by_cases h : ∀ j, r j i → f j < f i · refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩ rw [bfamilyOfFamily'_typein] · push_neg at h obtain ⟨hji, hij⟩ := wo.wf.min_mem _ h refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩ · by_contra! H exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj · rwa [bfamilyOfFamily'_typein] @[simp] theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by obtain ⟨f, hf⟩ := exists_fundamental_sequence a obtain ⟨g, hg⟩ := exists_fundamental_sequence a.cof.ord exact ord_injective (hf.trans hg).cof_eq.symm protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) {a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) : IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩ · rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩ rw [← hg.cof_eq, ord_le_ord, ← hι] suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by rw [← this] apply cof_lsub_le have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by have := lt_lsub.{u, u} f' i rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this simpa using this refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_) · rcases H i with ⟨b, hb, hb'⟩ exact lt_of_le_of_lt (csInf_le' hb') hb · have := hf.strictMono hb rw [← hf', lt_lsub_iff] at this obtain ⟨i, hi⟩ := this rcases H i with ⟨b, _, hb⟩ exact ((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc => hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i) · rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g hg.2.2] exact IsNormal.blsub_eq.{u, u} hf ha theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a := let ⟨_, hg⟩ := exists_fundamental_sequence a ord_injective (hf.isFundamentalSequence ha hg).cof_eq theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha) · rw [cof_zero] exact zero_le _ · rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero] exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b) · rw [hf.cof_eq ha] @[simp] theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) · contradiction · rw [add_succ, cof_succ, cof_succ] · exact (isNormal_add_right a).cof_eq hb theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l) · simp [not_zero_isLimit, Cardinal.aleph0_ne_zero] · simp [not_succ_isLimit, Cardinal.one_lt_aleph0] · simp only [l, iff_true] refine le_of_not_lt fun h => ?_ obtain ⟨n, e⟩ := Cardinal.lt_aleph0.1 h have := cof_cof o rw [e, ord_nat] at this cases n · simp at e simp [e, not_zero_isLimit] at l · rw [natCast_succ, cof_succ] at this rw [← this, cof_eq_one_iff_is_succ] at e rcases e with ⟨a, rfl⟩ exact not_succ_isLimit _ l @[simp] theorem cof_preOmega {o : Ordinal} (ho : IsSuccPrelimit o) : (preOmega o).cof = o.cof := by by_cases h : IsMin o · simp [h.eq_bot] · exact isNormal_preOmega.cof_eq ⟨h, ho⟩ @[simp] theorem cof_omega {o : Ordinal} (ho : o.IsLimit) : (ω_ o).cof = o.cof := isNormal_omega.cof_eq ho @[simp] theorem cof_omega0 : cof ω = ℵ₀ := (aleph0_le_cof.2 isLimit_omega0).antisymm' <| by rw [← card_omega0] apply cof_le_card theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) : ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) := let ⟨S, H, e⟩ := cof_eq r
⟨S, fun a => let a' := enum r ⟨_, h.succ_lt (typein_lt_type r a)⟩ let ⟨b, h, ab⟩ := H a' ⟨b, h, (IsOrderConnected.conn a b a' <| (typein_lt_typein r).1 (by rw [typein_enum] exact lt_succ (typein _ _))).resolve_right ab⟩, e⟩ @[simp] theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} := le_antisymm (cof_le_card _) (by refine le_of_forall_lt fun c h => ?_ rcases lt_univ'.1 h with ⟨c, rfl⟩ rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩ rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se] refine lt_of_not_ge fun h => ?_ obtain ⟨a, e⟩ := Cardinal.mem_range_lift_of_le h refine Quotient.inductionOn a (fun α e => ?_) e obtain ⟨f⟩ := Quotient.exact e have f := Equiv.ulift.symm.trans f let g a := (f a).1 let o := succ (iSup g) rcases H o with ⟨b, h, l⟩ refine l (lt_succ_iff.2 ?_) rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]] apply Ordinal.le_iSup)
Mathlib/SetTheory/Cardinal/Cofinality.lean
614
644
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Anne Baanen -/ import Mathlib.Algebra.Algebra.Equiv import Mathlib.LinearAlgebra.Span.Basic /-! # Towers of algebras In this file we prove basic facts about towers of algebra. An algebra tower A/S/R is expressed by having instances of `Algebra A S`, `Algebra R S`, `Algebra R A` and `IsScalarTower R S A`, the later asserting the compatibility condition `(r • s) • a = r • (s • a)`. An important definition is `toAlgHom R S A`, the canonical `R`-algebra homomorphism `S →ₐ[R] A`. -/ open Pointwise universe u v w u₁ v₁ variable (R : Type u) (S : Type v) (A : Type w) (B : Type u₁) (M : Type v₁) namespace Algebra variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] [Module A M] [Module B M] variable [IsScalarTower R A M] [IsScalarTower R B M] [SMulCommClass A B M] variable {A} /-- The `R`-algebra morphism `A → End (M)` corresponding to the representation of the algebra `A` on the `B`-module `M`. This is a stronger version of `DistribMulAction.toLinearMap`, and could also have been called `Algebra.toModuleEnd`. The typeclasses correspond to the situation where the types act on each other as ``` R ----→ B | ⟍ | | ⟍ | ↓ ↘ ↓ A ----→ M ``` where the diagram commutes, the action by `R` commutes with everything, and the action by `A` and `B` on `M` commute. Typically this is most useful with `B = R` as `Algebra.lsmul R R A : A →ₐ[R] Module.End R M`. However this can be used to get the fact that left-multiplication by `A` is right `A`-linear, and vice versa, as ```lean example : A →ₐ[R] Module.End Aᵐᵒᵖ A := Algebra.lsmul R Aᵐᵒᵖ A example : Aᵐᵒᵖ →ₐ[R] Module.End A A := Algebra.lsmul R A A ``` respectively; though `LinearMap.mulLeft` and `LinearMap.mulRight` can also be used here. -/ def lsmul : A →ₐ[R] Module.End B M where toFun := DistribMulAction.toLinearMap B M map_one' := LinearMap.ext fun _ => one_smul A _ map_mul' a b := LinearMap.ext <| smul_assoc a b map_zero' := LinearMap.ext fun _ => zero_smul A _ map_add' _a _b := LinearMap.ext fun _ => add_smul _ _ _ commutes' r := LinearMap.ext <| algebraMap_smul A r @[simp] theorem lsmul_coe (a : A) : (lsmul R B M a : M → M) = (a • ·) := rfl end Algebra namespace IsScalarTower section Module variable [CommSemiring R] [Semiring A] [Algebra R A] variable [MulAction A M] variable {R} {M} theorem algebraMap_smul [SMul R M] [IsScalarTower R A M] (r : R) (x : M) : algebraMap R A r • x = r • x := by rw [Algebra.algebraMap_eq_smul_one, smul_assoc, one_smul] variable {A} in theorem of_algebraMap_smul [SMul R M] (h : ∀ (r : R) (x : M), algebraMap R A r • x = r • x) : IsScalarTower R A M where smul_assoc r a x := by rw [Algebra.smul_def, mul_smul, h] variable (R M) in
theorem of_compHom : letI := MulAction.compHom M (algebraMap R A : R →* A); IsScalarTower R A M := letI := MulAction.compHom M (algebraMap R A : R →* A); of_algebraMap_smul fun _ _ ↦ rfl
Mathlib/Algebra/Algebra/Tower.lean
94
96
/- Copyright (c) 2024 Miguel Marco. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Miguel Marco -/ import Mathlib.Data.Set.Function import Mathlib.Data.Set.Functor /-! # Sets in subtypes This file is about sets in `Set A` when `A` is a set. It defines notation `↓∩` for sets in a type pulled down to sets in a subtype, as an inverse operation to the coercion that lifts sets in a subtype up to sets in the ambient type. This module also provides lemmas for `↓∩` and this coercion. ## Notation Let `α` be a `Type`, `A B : Set α` two sets in `α`, and `C : Set A` a set in the subtype `↑A`. - `A ↓∩ B` denotes `(Subtype.val ⁻¹' B : Set A)` (that is, `{x : ↑A | ↑x ∈ B}`). - `↑C` denotes `Subtype.val '' C` (that is, `{x : α | ∃ y ∈ C, ↑y = x}`). This notation, (together with the `↑` notation for `Set.CoeHead`) is defined in `Mathlib.Data.Set.Notation` and is scoped to the `Set.Notation` namespace. To enable it, use `open Set.Notation`. ## Naming conventions Theorem names refer to `↓∩` as `preimage_val`. ## Tags subsets -/ open Set variable {ι : Sort*} {α : Type*} {A B C : Set α} {D E : Set A} variable {S : Set (Set α)} {T : Set (Set A)} {s : ι → Set α} {t : ι → Set A} namespace Set open Notation lemma preimage_val_eq_univ_of_subset (h : A ⊆ B) : A ↓∩ B = univ := by rw [eq_univ_iff_forall, Subtype.forall] exact h lemma preimage_val_sUnion : A ↓∩ (⋃₀ S) = ⋃₀ { (A ↓∩ B) | B ∈ S } := by rw [← Set.image, sUnion_image] simp_rw [sUnion_eq_biUnion, preimage_iUnion] @[simp] lemma preimage_val_iInter : A ↓∩ (⋂ i, s i) = ⋂ i, A ↓∩ s i := preimage_iInter lemma preimage_val_sInter : A ↓∩ (⋂₀ S) = ⋂₀ { (A ↓∩ B) | B ∈ S } := by rw [← Set.image, sInter_image] simp_rw [sInter_eq_biInter, preimage_iInter] lemma preimage_val_sInter_eq_sInter : A ↓∩ (⋂₀ S) = ⋂₀ ((A ↓∩ ·) '' S) := by simp only [preimage_sInter, sInter_image] lemma eq_of_preimage_val_eq_of_subset (hB : B ⊆ A) (hC : C ⊆ A) (h : A ↓∩ B = A ↓∩ C) : B = C := by simp only [← inter_eq_right] at hB hC simp only [Subtype.preimage_val_eq_preimage_val_iff, hB, hC] at h exact h /-! The following simp lemmas try to transform operations in the subtype into operations in the ambient type, if possible. -/ @[simp] lemma image_val_union : (↑(D ∪ E) : Set α) = ↑D ∪ ↑E := image_union _ _ _ @[simp] lemma image_val_inter : (↑(D ∩ E) : Set α) = ↑D ∩ ↑E := image_inter Subtype.val_injective @[simp] lemma image_val_diff : (↑(D \ E) : Set α) = ↑D \ ↑E := image_diff Subtype.val_injective _ _ @[simp] lemma image_val_compl : ↑(Dᶜ) = A \ ↑D := by rw [compl_eq_univ_diff, image_val_diff, image_univ, Subtype.range_coe_subtype, setOf_mem_eq]
@[simp] lemma image_val_sUnion : ↑(⋃₀ T) = ⋃₀ { (B : Set α) | B ∈ T} := by rw [image_sUnion, image]
Mathlib/Data/Set/Subset.lean
90
92
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.ZPow import Mathlib.Data.Matrix.ConjTranspose /-! # Hermitian matrices This file defines hermitian matrices and some basic results about them. See also `IsSelfAdjoint`, which generalizes this definition to other star rings. ## Main definition * `Matrix.IsHermitian` : a matrix `A : Matrix n n α` is hermitian if `Aᴴ = A`. ## Tags self-adjoint matrix, hermitian matrix -/ namespace Matrix variable {α β : Type*} {m n : Type*} {A : Matrix n n α} open scoped Matrix local notation "⟪" x ", " y "⟫" => @inner α _ _ x y section Star variable [Star α] [Star β] /-- A matrix is hermitian if it is equal to its conjugate transpose. On the reals, this definition captures symmetric matrices. -/ def IsHermitian (A : Matrix n n α) : Prop := Aᴴ = A instance (A : Matrix n n α) [Decidable (Aᴴ = A)] : Decidable (IsHermitian A) := inferInstanceAs <| Decidable (_ = _) theorem IsHermitian.eq {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ = A := h protected theorem IsHermitian.isSelfAdjoint {A : Matrix n n α} (h : A.IsHermitian) : IsSelfAdjoint A := h theorem IsHermitian.ext {A : Matrix n n α} : (∀ i j, star (A j i) = A i j) → A.IsHermitian := by intro h; ext i j; exact h i j theorem IsHermitian.apply {A : Matrix n n α} (h : A.IsHermitian) (i j : n) : star (A j i) = A i j := congr_fun (congr_fun h _) _ theorem IsHermitian.ext_iff {A : Matrix n n α} : A.IsHermitian ↔ ∀ i j, star (A j i) = A i j := ⟨IsHermitian.apply, IsHermitian.ext⟩ @[simp] theorem IsHermitian.map {A : Matrix n n α} (h : A.IsHermitian) (f : α → β) (hf : Function.Semiconj f star star) : (A.map f).IsHermitian := (conjTranspose_map f hf).symm.trans <| h.eq.symm ▸ rfl theorem IsHermitian.transpose {A : Matrix n n α} (h : A.IsHermitian) : Aᵀ.IsHermitian := by rw [IsHermitian, conjTranspose, transpose_map] exact congr_arg Matrix.transpose h @[simp] theorem isHermitian_transpose_iff (A : Matrix n n α) : Aᵀ.IsHermitian ↔ A.IsHermitian := ⟨by intro h; rw [← transpose_transpose A]; exact IsHermitian.transpose h, IsHermitian.transpose⟩ theorem IsHermitian.conjTranspose {A : Matrix n n α} (h : A.IsHermitian) : Aᴴ.IsHermitian := h.transpose.map _ fun _ => rfl @[simp] theorem IsHermitian.submatrix {A : Matrix n n α} (h : A.IsHermitian) (f : m → n) : (A.submatrix f f).IsHermitian := (conjTranspose_submatrix _ _ _).trans (h.symm ▸ rfl) @[simp] theorem isHermitian_submatrix_equiv {A : Matrix n n α} (e : m ≃ n) : (A.submatrix e e).IsHermitian ↔ A.IsHermitian := ⟨fun h => by simpa using h.submatrix e.symm, fun h => h.submatrix _⟩ end Star section InvolutiveStar variable [InvolutiveStar α] @[simp] theorem isHermitian_conjTranspose_iff (A : Matrix n n α) : Aᴴ.IsHermitian ↔ A.IsHermitian := IsSelfAdjoint.star_iff /-- A block matrix `A.from_blocks B C D` is hermitian, if `A` and `D` are hermitian and `Bᴴ = C`. -/ theorem IsHermitian.fromBlocks {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} (hA : A.IsHermitian) (hBC : Bᴴ = C) (hD : D.IsHermitian) : (A.fromBlocks B C D).IsHermitian := by have hCB : Cᴴ = B := by rw [← hBC, conjTranspose_conjTranspose] unfold Matrix.IsHermitian rw [fromBlocks_conjTranspose, hBC, hCB, hA, hD] /-- This is the `iff` version of `Matrix.IsHermitian.fromBlocks`. -/ theorem isHermitian_fromBlocks_iff {A : Matrix m m α} {B : Matrix m n α} {C : Matrix n m α} {D : Matrix n n α} : (A.fromBlocks B C D).IsHermitian ↔ A.IsHermitian ∧ Bᴴ = C ∧ Cᴴ = B ∧ D.IsHermitian := ⟨fun h => ⟨congr_arg toBlocks₁₁ h, congr_arg toBlocks₂₁ h, congr_arg toBlocks₁₂ h, congr_arg toBlocks₂₂ h⟩, fun ⟨hA, hBC, _hCB, hD⟩ => IsHermitian.fromBlocks hA hBC hD⟩ end InvolutiveStar section AddMonoid variable [AddMonoid α] [StarAddMonoid α] /-- A diagonal matrix is hermitian if the entries are self-adjoint (as a vector) -/ theorem isHermitian_diagonal_of_self_adjoint [DecidableEq n] (v : n → α) (h : IsSelfAdjoint v) : (diagonal v).IsHermitian := (-- TODO: add a `pi.has_trivial_star` instance and remove the `funext` diagonal_conjTranspose v).trans <| congr_arg _ h /-- A diagonal matrix is hermitian if each diagonal entry is self-adjoint -/ lemma isHermitian_diagonal_iff [DecidableEq n] {d : n → α} : IsHermitian (diagonal d) ↔ (∀ i : n, IsSelfAdjoint (d i)) := by simp [isSelfAdjoint_iff, IsHermitian, conjTranspose, diagonal_transpose, diagonal_map] /-- A diagonal matrix is hermitian if the entries have the trivial `star` operation (such as on the reals). -/ @[simp] theorem isHermitian_diagonal [TrivialStar α] [DecidableEq n] (v : n → α) : (diagonal v).IsHermitian := isHermitian_diagonal_of_self_adjoint _ (IsSelfAdjoint.all _) @[simp] theorem isHermitian_zero : (0 : Matrix n n α).IsHermitian := IsSelfAdjoint.zero _ @[simp] theorem IsHermitian.add {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : (A + B).IsHermitian := IsSelfAdjoint.add hA hB end AddMonoid section AddCommMonoid variable [AddCommMonoid α] [StarAddMonoid α] theorem isHermitian_add_transpose_self (A : Matrix n n α) : (A + Aᴴ).IsHermitian := IsSelfAdjoint.add_star_self A theorem isHermitian_transpose_add_self (A : Matrix n n α) : (Aᴴ + A).IsHermitian := IsSelfAdjoint.star_add_self A end AddCommMonoid section AddGroup variable [AddGroup α] [StarAddMonoid α] @[simp] theorem IsHermitian.neg {A : Matrix n n α} (h : A.IsHermitian) : (-A).IsHermitian := IsSelfAdjoint.neg h @[simp] theorem IsHermitian.sub {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : (A - B).IsHermitian := IsSelfAdjoint.sub hA hB end AddGroup section NonUnitalSemiring variable [NonUnitalSemiring α] [StarRing α] /-- Note this is more general than `IsSelfAdjoint.mul_star_self` as `B` can be rectangular. -/ theorem isHermitian_mul_conjTranspose_self [Fintype n] (A : Matrix m n α) : (A * Aᴴ).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose] /-- Note this is more general than `IsSelfAdjoint.star_mul_self` as `B` can be rectangular. -/ theorem isHermitian_transpose_mul_self [Fintype m] (A : Matrix m n α) : (Aᴴ * A).IsHermitian := by rw [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose] /-- Note this is more general than `IsSelfAdjoint.conjugate'` as `B` can be rectangular. -/ theorem isHermitian_conjTranspose_mul_mul [Fintype m] {A : Matrix m m α} (B : Matrix m n α) (hA : A.IsHermitian) : (Bᴴ * A * B).IsHermitian := by simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc] /-- Note this is more general than `IsSelfAdjoint.conjugate` as `B` can be rectangular. -/ theorem isHermitian_mul_mul_conjTranspose [Fintype m] {A : Matrix m m α} (B : Matrix n m α) (hA : A.IsHermitian) : (B * A * Bᴴ).IsHermitian := by simp only [IsHermitian, conjTranspose_mul, conjTranspose_conjTranspose, hA.eq, Matrix.mul_assoc] lemma commute_iff [Fintype n] {A B : Matrix n n α} (hA : A.IsHermitian) (hB : B.IsHermitian) : Commute A B ↔ (A * B).IsHermitian := hA.isSelfAdjoint.commute_iff hB.isSelfAdjoint end NonUnitalSemiring section Semiring variable [Semiring α] [StarRing α] /-- Note this is more general for matrices than `isSelfAdjoint_one` as it does not require `Fintype n`, which is necessary for `Monoid (Matrix n n R)`. -/ @[simp] theorem isHermitian_one [DecidableEq n] : (1 : Matrix n n α).IsHermitian := conjTranspose_one @[simp] theorem isHermitian_natCast [DecidableEq n] (d : ℕ) : (d : Matrix n n α).IsHermitian := conjTranspose_natCast _ theorem IsHermitian.pow [Fintype n] [DecidableEq n] {A : Matrix n n α} (h : A.IsHermitian) (k : ℕ) : (A ^ k).IsHermitian := IsSelfAdjoint.pow h _ end Semiring
section Ring variable [Ring α] [StarRing α]
Mathlib/LinearAlgebra/Matrix/Hermitian.lean
221
223
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel] /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂]
· simp [h.symm]
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
292
293
/- Copyright (c) 2021 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.GroupTheory.OrderOfElement import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.Peel import Mathlib.Algebra.Order.BigOperators.Ring.Finset /-! # Exponent of a group This file defines the exponent of a group, or more generally a monoid. For a group `G` it is defined to be the minimal `n≥1` such that `g ^ n = 1` for all `g ∈ G`. For a finite group `G`, it is equal to the lowest common multiple of the order of all elements of the group `G`. ## Main definitions * `Monoid.ExponentExists` is a predicate on a monoid `G` saying that there is some positive `n` such that `g ^ n = 1` for all `g ∈ G`. * `Monoid.exponent` defines the exponent of a monoid `G` as the minimal positive `n` such that `g ^ n = 1` for all `g ∈ G`, by convention it is `0` if no such `n` exists. * `AddMonoid.ExponentExists` the additive version of `Monoid.ExponentExists`. * `AddMonoid.exponent` the additive version of `Monoid.exponent`. ## Main results * `Monoid.lcm_order_eq_exponent`: For a finite left cancel monoid `G`, the exponent is equal to the `Finset.lcm` of the order of its elements. * `Monoid.exponent_eq_iSup_orderOf(')`: For a commutative cancel monoid, the exponent is equal to `⨆ g : G, orderOf g` (or zero if it has any order-zero elements). * `Monoid.exponent_pi` and `Monoid.exponent_prod`: The exponent of a finite product of monoids is the least common multiple (`Finset.lcm` and `lcm`, respectively) of the exponents of the constituent monoids. * `MonoidHom.exponent_dvd`: If `f : M₁ →⋆ M₂` is surjective, then the exponent of `M₂` divides the exponent of `M₁`. ## TODO * Refactor the characteristic of a ring to be the exponent of its underlying additive group. -/ universe u variable {G : Type u} namespace Monoid section Monoid variable (G) [Monoid G] /-- A predicate on a monoid saying that there is a positive integer `n` such that `g ^ n = 1` for all `g`. -/ @[to_additive "A predicate on an additive monoid saying that there is a positive integer `n` such\n that `n • g = 0` for all `g`."] def ExponentExists := ∃ n, 0 < n ∧ ∀ g : G, g ^ n = 1 open scoped Classical in /-- The exponent of a group is the smallest positive integer `n` such that `g ^ n = 1` for all `g ∈ G` if it exists, otherwise it is zero by convention. -/ @[to_additive "The exponent of an additive group is the smallest positive integer `n` such that\n `n • g = 0` for all `g ∈ G` if it exists, otherwise it is zero by convention."] noncomputable def exponent := if h : ExponentExists G then Nat.find h else 0 variable {G} @[simp] theorem _root_.AddMonoid.exponent_additive : AddMonoid.exponent (Additive G) = exponent G := rfl @[simp] theorem exponent_multiplicative {G : Type*} [AddMonoid G] : exponent (Multiplicative G) = AddMonoid.exponent G := rfl open MulOpposite in @[to_additive (attr := simp)] theorem _root_.MulOpposite.exponent : exponent (MulOpposite G) = exponent G := by simp only [Monoid.exponent, ExponentExists] congr! all_goals exact ⟨(op_injective <| · <| op ·), (unop_injective <| · <| unop ·)⟩ @[to_additive] theorem ExponentExists.isOfFinOrder (h : ExponentExists G) {g : G} : IsOfFinOrder g := isOfFinOrder_iff_pow_eq_one.mpr <| by peel 2 h; exact this g @[to_additive] theorem ExponentExists.orderOf_pos (h : ExponentExists G) (g : G) : 0 < orderOf g := h.isOfFinOrder.orderOf_pos
@[to_additive] theorem exponent_ne_zero : exponent G ≠ 0 ↔ ExponentExists G := by
Mathlib/GroupTheory/Exponent.lean
98
99
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fin.Fin2 import Mathlib.Data.PFun import Mathlib.Data.Vector3 import Mathlib.NumberTheory.PellMatiyasevic /-! # Diophantine functions and Matiyasevic's theorem Hilbert's tenth problem asked whether there exists an algorithm which for a given integer polynomial determines whether this polynomial has integer solutions. It was answered in the negative in 1970, the final step being completed by Matiyasevic who showed that the power function is Diophantine. Here a function is called Diophantine if its graph is Diophantine as a set. A subset `S ⊆ ℕ ^ α` in turn is called Diophantine if there exists an integer polynomial on `α ⊕ β` such that `v ∈ S` iff there exists `t : ℕ^β` with `p (v, t) = 0`. ## Main definitions * `IsPoly`: a predicate stating that a function is a multivariate integer polynomial. * `Poly`: the type of multivariate integer polynomial functions. * `Dioph`: a predicate stating that a set is Diophantine, i.e. a set `S ⊆ ℕ^α` is Diophantine if there exists a polynomial on `α ⊕ β` such that `v ∈ S` iff there exists `t : ℕ^β` with `p (v, t) = 0`. * `DiophFn`: a predicate on a function stating that it is Diophantine in the sense that its graph is Diophantine as a set. ## Main statements * `pell_dioph` states that solutions to Pell's equation form a Diophantine set. * `pow_dioph` states that the power function is Diophantine, a version of Matiyasevic's theorem. ## References * [M. Carneiro, _A Lean formalization of Matiyasevic's theorem_][carneiro2018matiyasevic] * [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916] ## Tags Matiyasevic's theorem, Hilbert's tenth problem ## TODO * Finish the solution of Hilbert's tenth problem. * Connect `Poly` to `MvPolynomial` -/ open Fin2 Function Nat Sum local infixr:67 " ::ₒ " => Option.elim' local infixr:65 " ⊗ " => Sum.elim universe u /-! ### Multivariate integer polynomials Note that this duplicates `MvPolynomial`. -/ section Polynomials variable {α β : Type*} /-- A predicate asserting that a function is a multivariate integer polynomial. (We are being a bit lazy here by allowing many representations for multiplication, rather than only allowing monomials and addition, but the definition is equivalent and this is easier to use.) -/ inductive IsPoly : ((α → ℕ) → ℤ) → Prop | proj : ∀ i, IsPoly fun x : α → ℕ => x i | const : ∀ n : ℤ, IsPoly fun _ : α → ℕ => n | sub : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x - g x | mul : ∀ {f g : (α → ℕ) → ℤ}, IsPoly f → IsPoly g → IsPoly fun x => f x * g x theorem IsPoly.neg {f : (α → ℕ) → ℤ} : IsPoly f → IsPoly (-f) := by rw [← zero_sub]; exact (IsPoly.const 0).sub theorem IsPoly.add {f g : (α → ℕ) → ℤ} (hf : IsPoly f) (hg : IsPoly g) : IsPoly (f + g) := by rw [← sub_neg_eq_add]; exact hf.sub hg.neg /-- The type of multivariate integer polynomials -/ def Poly (α : Type u) := { f : (α → ℕ) → ℤ // IsPoly f } namespace Poly section instance instFunLike : FunLike (Poly α) (α → ℕ) ℤ := ⟨Subtype.val, Subtype.val_injective⟩ /-- The underlying function of a `Poly` is a polynomial -/ protected theorem isPoly (f : Poly α) : IsPoly f := f.2 /-- Extensionality for `Poly α` -/ @[ext] theorem ext {f g : Poly α} : (∀ x, f x = g x) → f = g := DFunLike.ext _ _ /-- The `i`th projection function, `x_i`. -/ def proj (i : α) : Poly α := ⟨_, IsPoly.proj i⟩ @[simp] theorem proj_apply (i : α) (x) : proj i x = x i := rfl /-- The constant function with value `n : ℤ`. -/ def const (n : ℤ) : Poly α := ⟨_, IsPoly.const n⟩ @[simp] theorem const_apply (n) (x : α → ℕ) : const n x = n := rfl instance : Zero (Poly α) := ⟨const 0⟩ instance : One (Poly α) := ⟨const 1⟩ instance : Neg (Poly α) := ⟨fun f => ⟨-f, f.2.neg⟩⟩ instance : Add (Poly α) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ instance : Sub (Poly α) := ⟨fun f g => ⟨f - g, f.2.sub g.2⟩⟩ instance : Mul (Poly α) := ⟨fun f g => ⟨f * g, f.2.mul g.2⟩⟩ @[simp] theorem coe_zero : ⇑(0 : Poly α) = const 0 := rfl @[simp] theorem coe_one : ⇑(1 : Poly α) = const 1 := rfl @[simp] theorem coe_neg (f : Poly α) : ⇑(-f) = -f := rfl @[simp] theorem coe_add (f g : Poly α) : ⇑(f + g) = f + g := rfl @[simp] theorem coe_sub (f g : Poly α) : ⇑(f - g) = f - g := rfl @[simp] theorem coe_mul (f g : Poly α) : ⇑(f * g) = f * g := rfl @[simp] theorem zero_apply (x) : (0 : Poly α) x = 0 := rfl @[simp] theorem one_apply (x) : (1 : Poly α) x = 1 := rfl @[simp] theorem neg_apply (f : Poly α) (x) : (-f) x = -f x := rfl @[simp] theorem add_apply (f g : Poly α) (x : α → ℕ) : (f + g) x = f x + g x := rfl @[simp] theorem sub_apply (f g : Poly α) (x : α → ℕ) : (f - g) x = f x - g x := rfl @[simp] theorem mul_apply (f g : Poly α) (x : α → ℕ) : (f * g) x = f x * g x := rfl instance (α : Type*) : Inhabited (Poly α) := ⟨0⟩ instance : AddCommGroup (Poly α) where add := ((· + ·) : Poly α → Poly α → Poly α) neg := (Neg.neg : Poly α → Poly α) sub := Sub.sub zero := 0 nsmul := @nsmulRec _ ⟨(0 : Poly α)⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec _ ⟨(0 : Poly α)⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec _ ⟨(0 : Poly α)⟩ ⟨(· + ·)⟩) add_zero _ := by ext; simp_rw [add_apply, zero_apply, add_zero] zero_add _ := by ext; simp_rw [add_apply, zero_apply, zero_add] add_comm _ _ := by ext; simp_rw [add_apply, add_comm] add_assoc _ _ _ := by ext; simp_rw [add_apply, ← add_assoc] neg_add_cancel _ := by ext; simp_rw [add_apply, neg_apply, neg_add_cancel, zero_apply] instance : AddGroupWithOne (Poly α) := { (inferInstance : AddCommGroup (Poly α)) with one := 1 natCast := fun n => Poly.const n intCast := Poly.const } instance : CommRing (Poly α) where __ := (inferInstance : AddCommGroup (Poly α)) __ := (inferInstance : AddGroupWithOne (Poly α)) mul := (· * ·) npow := @npowRec _ ⟨(1 : Poly α)⟩ ⟨(· * ·)⟩ mul_zero _ := by ext; rw [mul_apply, zero_apply, mul_zero] zero_mul _ := by ext; rw [mul_apply, zero_apply, zero_mul] mul_one _ := by ext; rw [mul_apply, one_apply, mul_one] one_mul _ := by ext; rw [mul_apply, one_apply, one_mul] mul_comm _ _ := by ext; simp_rw [mul_apply, mul_comm] mul_assoc _ _ _ := by ext; simp_rw [mul_apply, mul_assoc] left_distrib _ _ _ := by ext; simp_rw [add_apply, mul_apply]; apply mul_add right_distrib _ _ _ := by ext; simp only [add_apply, mul_apply]; apply add_mul theorem induction {C : Poly α → Prop} (H1 : ∀ i, C (proj i)) (H2 : ∀ n, C (const n)) (H3 : ∀ f g, C f → C g → C (f - g)) (H4 : ∀ f g, C f → C g → C (f * g)) (f : Poly α) : C f := by obtain ⟨f, pf⟩ := f induction pf with | proj => apply H1 | const => apply H2 | sub _ _ ihf ihg => apply H3 _ _ ihf ihg | mul _ _ ihf ihg => apply H4 _ _ ihf ihg /-- The sum of squares of a list of polynomials. This is relevant for Diophantine equations, because it means that a list of equations can be encoded as a single equation: `x = 0 ∧ y = 0 ∧ z = 0` is equivalent to `x^2 + y^2 + z^2 = 0`. -/ def sumsq : List (Poly α) → Poly α | [] => 0 | p::ps => p * p + sumsq ps theorem sumsq_nonneg (x : α → ℕ) : ∀ l, 0 ≤ sumsq l x | [] => le_refl 0 | p::ps => by rw [sumsq] exact add_nonneg (mul_self_nonneg _) (sumsq_nonneg _ ps) theorem sumsq_eq_zero (x) : ∀ l, sumsq l x = 0 ↔ l.Forall fun a : Poly α => a x = 0 | [] => eq_self_iff_true _ | p::ps => by rw [List.forall_cons, ← sumsq_eq_zero _ ps]; rw [sumsq] exact ⟨fun h : p x * p x + sumsq ps x = 0 => have : p x = 0 := eq_zero_of_mul_self_eq_zero <| le_antisymm (by rw [← h] have t := add_le_add_left (sumsq_nonneg x ps) (p x * p x) rwa [add_zero] at t) (mul_self_nonneg _) ⟨this, by simpa [this] using h⟩, fun ⟨h1, h2⟩ => by rw [add_apply, mul_apply, h1, h2]; rfl⟩ end /-- Map the index set of variables, replacing `x_i` with `x_(f i)`. -/ def map {α β} (f : α → β) (g : Poly α) : Poly β := ⟨fun v => g <| v ∘ f, Poly.induction (C := fun g => IsPoly (fun v => g (v ∘ f))) (fun i => by simpa using IsPoly.proj _) (fun n => by simpa using IsPoly.const _) (fun f g pf pg => by simpa using IsPoly.sub pf pg) (fun f g pf pg => by simpa using IsPoly.mul pf pg) _⟩ @[simp] theorem map_apply {α β} (f : α → β) (g : Poly α) (v) : map f g v = g (v ∘ f) := rfl end Poly end Polynomials /-! ### Diophantine sets -/ /-- A set `S ⊆ ℕ^α` is Diophantine if there exists a polynomial on `α ⊕ β` such that `v ∈ S` iff there exists `t : ℕ^β` with `p (v, t) = 0`. -/ def Dioph {α : Type u} (S : Set (α → ℕ)) : Prop := ∃ (β : Type u) (p : Poly (α ⊕ β)), ∀ v, S v ↔ ∃ t, p (v ⊗ t) = 0 namespace Dioph section variable {α β γ : Type u} {S S' : Set (α → ℕ)} theorem ext (d : Dioph S) (H : ∀ v, v ∈ S ↔ v ∈ S') : Dioph S' := by rwa [← Set.ext H] theorem of_no_dummies (S : Set (α → ℕ)) (p : Poly α) (h : ∀ v, S v ↔ p v = 0) : Dioph S := ⟨PEmpty, ⟨p.map inl, fun v => (h v).trans ⟨fun h => ⟨PEmpty.elim, h⟩, fun ⟨_, ht⟩ => ht⟩⟩⟩ theorem inject_dummies_lem (f : β → γ) (g : γ → Option β) (inv : ∀ x, g (f x) = some x) (p : Poly (α ⊕ β)) (v : α → ℕ) : (∃ t, p (v ⊗ t) = 0) ↔ ∃ t, p.map (inl ⊗ inr ∘ f) (v ⊗ t) = 0 := by dsimp; refine ⟨fun t => ?_, fun t => ?_⟩ <;> obtain ⟨t, ht⟩ := t · have : (v ⊗ (0 ::ₒ t) ∘ g) ∘ (inl ⊗ inr ∘ f) = v ⊗ t := funext fun s => by rcases s with a | b <;> dsimp [(· ∘ ·)]; try rw [inv]; rfl exact ⟨(0 ::ₒ t) ∘ g, by rwa [this]⟩ · have : v ⊗ t ∘ f = (v ⊗ t) ∘ (inl ⊗ inr ∘ f) := funext fun s => by rcases s with a | b <;> rfl exact ⟨t ∘ f, by rwa [this]⟩ theorem inject_dummies (f : β → γ) (g : γ → Option β) (inv : ∀ x, g (f x) = some x) (p : Poly (α ⊕ β)) (h : ∀ v, S v ↔ ∃ t, p (v ⊗ t) = 0) : ∃ q : Poly (α ⊕ γ), ∀ v, S v ↔ ∃ t, q (v ⊗ t) = 0 := ⟨p.map (inl ⊗ inr ∘ f), fun v => (h v).trans <| inject_dummies_lem f g inv _ _⟩ variable (β) in theorem reindex_dioph (f : α → β) : Dioph S → Dioph {v | v ∘ f ∈ S} | ⟨γ, p, pe⟩ => ⟨γ, p.map (inl ∘ f ⊗ inr), fun v => (pe _).trans <| exists_congr fun t => suffices v ∘ f ⊗ t = (v ⊗ t) ∘ (inl ∘ f ⊗ inr) by simp [this] funext fun s => by rcases s with a | b <;> rfl⟩ theorem DiophList.forall (l : List (Set <| α → ℕ)) (d : l.Forall Dioph) : Dioph {v | l.Forall fun S : Set (α → ℕ) => v ∈ S} := by suffices ∃ (β : _) (pl : List (Poly (α ⊕ β))), ∀ v, List.Forall (fun S : Set _ => S v) l ↔ ∃ t, List.Forall (fun p : Poly (α ⊕ β) => p (v ⊗ t) = 0) pl from let ⟨β, pl, h⟩ := this ⟨β, Poly.sumsq pl, fun v => (h v).trans <| exists_congr fun t => (Poly.sumsq_eq_zero _ _).symm⟩ induction l with | nil => exact ⟨ULift Empty, [], fun _ => by simp⟩ | cons S l IH => simp? at d says simp only [List.forall_cons] at d exact let ⟨⟨β, p, pe⟩, dl⟩ := d let ⟨γ, pl, ple⟩ := IH dl ⟨β ⊕ γ, p.map (inl ⊗ inr ∘ inl)::pl.map fun q => q.map (inl ⊗ inr ∘ inr), fun v => by simp; exact Iff.trans (and_congr (pe v) (ple v)) ⟨fun ⟨⟨m, hm⟩, ⟨n, hn⟩⟩ => ⟨m ⊗ n, by rw [show (v ⊗ m ⊗ n) ∘ (inl ⊗ inr ∘ inl) = v ⊗ m from funext fun s => by rcases s with a | b <;> rfl]; exact hm, by refine List.Forall.imp (fun q hq => ?_) hn; dsimp [Function.comp_def] rw [show (fun x : α ⊕ γ => (v ⊗ m ⊗ n) ((inl ⊗ fun x : γ => inr (inr x)) x)) = v ⊗ n from funext fun s => by rcases s with a | b <;> rfl]; exact hq⟩, fun ⟨t, hl, hr⟩ => ⟨⟨t ∘ inl, by rwa [show (v ⊗ t) ∘ (inl ⊗ inr ∘ inl) = v ⊗ t ∘ inl from funext fun s => by rcases s with a | b <;> rfl] at hl⟩, ⟨t ∘ inr, by refine List.Forall.imp (fun q hq => ?_) hr; dsimp [Function.comp_def] at hq rwa [show (fun x : α ⊕ γ => (v ⊗ t) ((inl ⊗ fun x : γ => inr (inr x)) x)) = v ⊗ t ∘ inr from funext fun s => by rcases s with a | b <;> rfl] at hq ⟩⟩⟩⟩ /-- Diophantine sets are closed under intersection. -/ theorem inter (d : Dioph S) (d' : Dioph S') : Dioph (S ∩ S') := DiophList.forall [S, S'] ⟨d, d'⟩ /-- Diophantine sets are closed under union. -/ theorem union : ∀ (_ : Dioph S) (_ : Dioph S'), Dioph (S ∪ S') | ⟨β, p, pe⟩, ⟨γ, q, qe⟩ => ⟨β ⊕ γ, p.map (inl ⊗ inr ∘ inl) * q.map (inl ⊗ inr ∘ inr), fun v => by refine Iff.trans (or_congr ((pe v).trans ?_) ((qe v).trans ?_)) (exists_or.symm.trans (exists_congr fun t => (@mul_eq_zero _ _ _ (p ((v ⊗ t) ∘ (inl ⊗ inr ∘ inl))) (q ((v ⊗ t) ∘ (inl ⊗ inr ∘ inr)))).symm)) · -- Porting note: putting everything on the same line fails refine inject_dummies_lem _ (some ⊗ fun _ => none) ?_ _ _ exact fun _ => by simp only [elim_inl] · -- Porting note: putting everything on the same line fails refine inject_dummies_lem _ ((fun _ => none) ⊗ some) ?_ _ _ exact fun _ => by simp only [elim_inr]⟩ /-- A partial function is Diophantine if its graph is Diophantine. -/ def DiophPFun (f : (α → ℕ) →. ℕ) : Prop := Dioph {v : Option α → ℕ | f.graph (v ∘ some, v none)} /-- A function is Diophantine if its graph is Diophantine. -/ def DiophFn (f : (α → ℕ) → ℕ) : Prop := Dioph {v : Option α → ℕ | f (v ∘ some) = v none} theorem reindex_diophFn {f : (α → ℕ) → ℕ} (g : α → β) (d : DiophFn f) : DiophFn fun v => f (v ∘ g) := by convert reindex_dioph (Option β) (Option.map g) d theorem ex_dioph {S : Set (α ⊕ β → ℕ)} : Dioph S → Dioph {v | ∃ x, v ⊗ x ∈ S} | ⟨γ, p, pe⟩ => ⟨β ⊕ γ, p.map ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr), fun v => ⟨fun ⟨x, hx⟩ => let ⟨t, ht⟩ := (pe _).1 hx ⟨x ⊗ t, by simp; rw [show (v ⊗ x ⊗ t) ∘ ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr) = (v ⊗ x) ⊗ t from funext fun s => by rcases s with a | b <;> try { cases a <;> rfl }; rfl] exact ht⟩, fun ⟨t, ht⟩ => ⟨t ∘ inl, (pe _).2 ⟨t ∘ inr, by simp only [Poly.map_apply] at ht rwa [show (v ⊗ t) ∘ ((inl ⊗ inr ∘ inl) ⊗ inr ∘ inr) = (v ⊗ t ∘ inl) ⊗ t ∘ inr from funext fun s => by rcases s with a | b <;> try { cases a <;> rfl }; rfl] at ht⟩⟩⟩⟩ theorem ex1_dioph {S : Set (Option α → ℕ)} : Dioph S → Dioph {v | ∃ x, x ::ₒ v ∈ S} | ⟨β, p, pe⟩ => ⟨Option β, p.map (inr none ::ₒ inl ⊗ inr ∘ some), fun v => ⟨fun ⟨x, hx⟩ => let ⟨t, ht⟩ := (pe _).1 hx ⟨x ::ₒ t, by simp only [Poly.map_apply] rw [show (v ⊗ x ::ₒ t) ∘ (inr none ::ₒ inl ⊗ inr ∘ some) = x ::ₒ v ⊗ t from funext fun s => by rcases s with a | b <;> try { cases a <;> rfl}; rfl] exact ht⟩, fun ⟨t, ht⟩ => ⟨t none, (pe _).2 ⟨t ∘ some, by simp only [Poly.map_apply] at ht rwa [show (v ⊗ t) ∘ (inr none ::ₒ inl ⊗ inr ∘ some) = t none ::ₒ v ⊗ t ∘ some from funext fun s => by rcases s with a | b <;> try { cases a <;> rfl }; rfl] at ht ⟩⟩⟩⟩ theorem dom_dioph {f : (α → ℕ) →. ℕ} (d : DiophPFun f) : Dioph f.Dom := cast (congr_arg Dioph <| Set.ext fun _ => (PFun.dom_iff_graph _ _).symm) (ex1_dioph d) theorem diophFn_iff_pFun (f : (α → ℕ) → ℕ) : DiophFn f = @DiophPFun α f := by refine congr_arg Dioph (Set.ext fun v => ?_); exact PFun.lift_graph.symm theorem abs_poly_dioph (p : Poly α) : DiophFn fun v => (p v).natAbs := of_no_dummies _ ((p.map some - Poly.proj none) * (p.map some + Poly.proj none))
fun v => (by dsimp; exact Int.natAbs_eq_iff_mul_eq_zero)
Mathlib/NumberTheory/Dioph.lean
407
408
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Order.Bounds.Defs import Mathlib.Order.Directed import Mathlib.Order.BoundedOrder.Monotone import Mathlib.Order.Interval.Set.Basic /-! # Upper / lower bounds In this file we prove various lemmas about upper/lower bounds of a set: monotonicity, behaviour under `∪`, `∩`, `insert`, and provide formulas for `∅`, `univ`, and intervals. -/ open Function Set open OrderDual (toDual ofDual) universe u v variable {α : Type u} {γ : Type v} section variable [Preorder α] {s t : Set α} {a b : α} theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a := Iff.rfl theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x := Iff.rfl lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x := Iff.rfl theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y := Iff.rfl theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top @[simp] theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s := and_iff_left <| bot_mem_lowerBounds _ @[simp] theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s := and_iff_left <| top_mem_upperBounds _ /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x` is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/ theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by simp [BddAbove, upperBounds, Set.Nonempty] /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x` is not less than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/ theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y := @not_bddAbove_iff' αᵒᵈ _ _ /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater than `x`. A version for preorders is called `not_bddAbove_iff'`. -/ theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by simp only [not_bddAbove_iff', not_le] /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less than `x`. A version for preorders is called `not_bddBelow_iff'`. -/ theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x := @not_bddAbove_iff αᵒᵈ _ _ @[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl @[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} : BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} : BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) := h theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) := h theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) := h theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) := h theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) := h theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) := h /-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/ abbrev IsLeast.orderBot (h : IsLeast s a) : OrderBot s where bot := ⟨a, h.1⟩ bot_le := Subtype.forall.2 h.2 /-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/ abbrev IsGreatest.orderTop (h : IsGreatest s a) : OrderTop s where top := ⟨a, h.1⟩ le_top := Subtype.forall.2 h.2 theorem isLUB_congr (h : upperBounds s = upperBounds t) : IsLUB s a ↔ IsLUB t a := by rw [IsLUB, IsLUB, h] theorem isGLB_congr (h : lowerBounds s = lowerBounds t) : IsGLB s a ↔ IsGLB t a := by rw [IsGLB, IsGLB, h] /-! ### Monotonicity -/ theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s := fun _ hb _ h => hb <| hst h theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s := fun _ hb _ h => hb <| hst h theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s := fun ha _ h => le_trans (ha h) hab theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s := fun hb _ h => le_trans hab (hb h) theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds t → b ∈ upperBounds s := fun ha => upperBounds_mono_set hst <| upperBounds_mono_mem hab ha theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb => lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb /-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/ theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s := Nonempty.mono <| upperBounds_mono_set h /-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/ theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s := Nonempty.mono <| lowerBounds_mono_set h /-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsLUB t a := ⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩ /-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsGLB t a := hs.dual.of_subset_of_superset hp hst htp theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a := hb.2 (hst ha.1) theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b := hb.2 (hst ha.1) theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b := IsLeast.mono hb ha <| upperBounds_mono_set hst theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a := IsGreatest.mono hb ha <| lowerBounds_mono_set hst theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) := fun _ hx _ hy => hy hx theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) := fun _ hx _ hy => hy hx theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) := hs.mono (subset_upperBounds_lowerBounds s) theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) := hs.mono (subset_lowerBounds_upperBounds s) /-! ### Conversions -/ theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a := ⟨h.2, fun _ hb => hb h.1⟩ theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a := ⟨h.2, fun _ hb => hb h.1⟩ theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a := Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩ theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a := h.dual.upperBounds_eq theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a := h.isGLB.lowerBounds_eq theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a := h.isLUB.upperBounds_eq theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b := ⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩ theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x := h.dual.lt_iff theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by rw [h.upperBounds_eq] rfl theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by rw [h.lowerBounds_eq] rfl theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s := ⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩ theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s := @isLUB_iff_le_iff αᵒᵈ _ _ _ /-- If `s` has a least upper bound, then it is bounded above. -/ theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s := ⟨a, h.1⟩ /-- If `s` has a greatest lower bound, then it is bounded below. -/ theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s := ⟨a, h.1⟩ /-- If `s` has a greatest element, then it is bounded above. -/ theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s := ⟨a, h.2⟩ /-- If `s` has a least element, then it is bounded below. -/ theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s := ⟨a, h.2⟩ theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty := ⟨a, h.1⟩ theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty := ⟨a, h.1⟩ /-! ### Union and intersection -/ @[simp] theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t := Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩) fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht @[simp] theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t := @upperBounds_union αᵒᵈ _ s t theorem union_upperBounds_subset_upperBounds_inter : upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) := union_subset (upperBounds_mono_set inter_subset_left) (upperBounds_mono_set inter_subset_right) theorem union_lowerBounds_subset_lowerBounds_inter : lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) := @union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t theorem isLeast_union_iff {a : α} {s t : Set α} : IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc] theorem isGreatest_union_iff : IsGreatest (s ∪ t) a ↔ IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a := @isLeast_union_iff αᵒᵈ _ a s t /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) := h.mono inter_subset_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) := h.mono inter_subset_right /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) := h.mono inter_subset_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) := h.mono inter_subset_right /-- In a directed order, the union of bounded above sets is bounded above. -/ theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove s → BddAbove t → BddAbove (s ∪ t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b rw [BddAbove, upperBounds_union] exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩ /-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/ theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t := ⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h => h.1.union h.2⟩ /-- In a codirected order, the union of bounded below sets is bounded below. -/ theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow s → BddBelow t → BddBelow (s ∪ t) := @BddAbove.union αᵒᵈ _ _ _ _ /-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/ theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t := @bddAbove_union αᵒᵈ _ _ _ _ /-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`, then `a ⊔ b` is the least upper bound of `s ∪ t`. -/ theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) : IsLUB (s ∪ t) (a ⊔ b) := ⟨fun _ h => h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h, fun _ hc => sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩ /-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`, then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/ theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁) (ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) := hs.dual.union ht /-- If `a` is the least element of `s` and `b` is the least element of `t`, then `min a b` is the least element of `s ∪ t`. -/ theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩ /-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`, then `max a b` is the greatest element of `s ∪ t`. -/ theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a) (hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩ theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) : IsLUB (s ∩ Ici b) a := ⟨fun _ hx => ha.1 hx.1, fun c hc => have hbc : b ≤ c := hc ⟨hb, le_rfl⟩ ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩ theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) : IsGLB (s ∩ Iic b) a := ha.dual.inter_Ici_of_mem hb theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) : BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by rw [bddAbove_def, exists_ge_and_iff_exists] exact Monotone.ball fun x _ => monotone_le theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) : BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := bddAbove_iff_exists_ge (toDual x₀) theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) : ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := (bddAbove_iff_exists_ge x₀).mp hs theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) : ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := (bddBelow_iff_exists_le x₀).mp hs /-! ### Specific sets #### Unbounded intervals -/ theorem isLeast_Ici : IsLeast (Ici a) a := ⟨left_mem_Ici, fun _ => id⟩ theorem isGreatest_Iic : IsGreatest (Iic a) a := ⟨right_mem_Iic, fun _ => id⟩ theorem isLUB_Iic : IsLUB (Iic a) a := isGreatest_Iic.isLUB theorem isGLB_Ici : IsGLB (Ici a) a := isLeast_Ici.isGLB theorem upperBounds_Iic : upperBounds (Iic a) = Ici a := isLUB_Iic.upperBounds_eq theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a := isGLB_Ici.lowerBounds_eq theorem bddAbove_Iic : BddAbove (Iic a) := isLUB_Iic.bddAbove theorem bddBelow_Ici : BddBelow (Ici a) := isGLB_Ici.bddBelow theorem bddAbove_Iio : BddAbove (Iio a) := ⟨a, fun _ hx => le_of_lt hx⟩ theorem bddBelow_Ioi : BddBelow (Ioi a) := ⟨a, fun _ hx => le_of_lt hx⟩ theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a := (isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b := @lub_Iio_le αᵒᵈ _ _ a hb theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) : j = i ∨ Iio i = Iic j := by rcases eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i | hj_lt_i · exact Or.inl hj_eq_i · right exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩ theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) : j = i ∨ Ioi i = Ici j := @lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj section variable [LinearOrder γ] theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i · obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩ · refine ⟨i, fun j hj => le_of_lt hj, ?_⟩ rw [mem_lowerBounds] by_contra h refine h_exists_lt ?_ push_neg at h exact h theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j := @exists_lub_Iio γᵒᵈ _ i variable [DenselyOrdered γ] theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a := ⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_lt_imp_le_of_dense hy⟩ theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a := @isLUB_Iio γᵒᵈ _ _ a theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a := isLUB_Iio.upperBounds_eq theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a := isGLB_Ioi.lowerBounds_eq end /-! #### Singleton -/ @[simp] theorem isGreatest_singleton : IsGreatest {a} a := ⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩ @[simp] theorem isLeast_singleton : IsLeast {a} a := @isGreatest_singleton αᵒᵈ _ a @[simp] theorem isLUB_singleton : IsLUB {a} a := isGreatest_singleton.isLUB @[simp] theorem isGLB_singleton : IsGLB {a} a := isLeast_singleton.isGLB @[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove @[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow
@[simp] theorem upperBounds_singleton : upperBounds {a} = Ici a := isLUB_singleton.upperBounds_eq
Mathlib/Order/Bounds/Basic.lean
494
497
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one]
theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound]
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
134
146
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Convex.Deriv import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne import Mathlib.Data.Nat.Factorial.Basic import Mathlib.NumberTheory.Harmonic.EulerMascheroni /-! # Derivative of Γ at positive integers We prove the formula for the derivative of `Real.Gamma` at a positive integer: `deriv Real.Gamma (n + 1) = Nat.factorial n * (-Real.eulerMascheroniConstant + harmonic n)` -/ open Nat Set Filter Topology local notation "γ" => Real.eulerMascheroniConstant namespace Real /-- Explicit formula for the derivative of the Gamma function at positive integers, in terms of harmonic numbers and the Euler-Mascheroni constant `γ`. -/ lemma deriv_Gamma_nat (n : ℕ) : deriv Gamma (n + 1) = n ! * (-γ + harmonic n) := by /- This follows from two properties of the function `f n = log (Gamma n)`: firstly, the elementary computation that `deriv f (n + 1) = deriv f n + 1 / n`, so that `deriv f n = deriv f 1 + harmonic n`; secondly, the convexity of `f` (the Bohr-Mollerup theorem), which shows that `deriv f n` is `log n + o(1)` as `n → ∞`. -/ let f := log ∘ Gamma -- First reduce to computing derivative of `log ∘ Gamma`. suffices deriv (log ∘ Gamma) (n + 1) = -γ + harmonic n by rwa [Function.comp_def, deriv.log (differentiableAt_Gamma (fun m ↦ by linarith)) (by positivity), Gamma_nat_eq_factorial, div_eq_iff_mul_eq (by positivity), mul_comm, Eq.comm] at this have hc : ConvexOn ℝ (Ioi 0) f := convexOn_log_Gamma have h_rec (x : ℝ) (hx : 0 < x) : f (x + 1) = f x + log x := by simp only [f, Function.comp_apply, Gamma_add_one hx.ne', log_mul hx.ne' (Gamma_pos_of_pos hx).ne', add_comm] have hder {x : ℝ} (hx : 0 < x) : DifferentiableAt ℝ f x := by refine ((differentiableAt_Gamma ?_).log (Gamma_ne_zero ?_)) <;> exact fun m ↦ ne_of_gt (by linarith) -- Express derivative at general `n` in terms of value at `1` using recurrence relation have hder_rec (x : ℝ) (hx : 0 < x) : deriv f (x + 1) = deriv f x + 1 / x := by rw [← deriv_comp_add_const, one_div, ← deriv_log, ← deriv_add (hder <| by positivity) (differentiableAt_log hx.ne')] apply EventuallyEq.deriv_eq filter_upwards [eventually_gt_nhds hx] using h_rec have hder_nat (n : ℕ) : deriv f (n + 1) = deriv f 1 + harmonic n := by induction n with | zero => simp | succ n hn => rw [cast_succ, hder_rec (n + 1) (by positivity), hn, harmonic_succ] push_cast ring suffices -deriv f 1 = γ by rw [hder_nat n, ← this, neg_neg] -- Use convexity to show derivative of `f` at `n + 1` is between `log n` and `log (n + 1)` have derivLB (n : ℕ) (hn : 0 < n) : log n ≤ deriv f (n + 1) := by refine (le_of_eq ?_).trans <| hc.slope_le_deriv (mem_Ioi.mpr <| Nat.cast_pos.mpr hn) (by positivity : _ < (_ : ℝ)) (by linarith) (hder <| by positivity) rw [slope_def_field, show n + 1 - n = (1 : ℝ) by ring, div_one, h_rec n (by positivity), add_sub_cancel_left] have derivUB (n : ℕ) : deriv f (n + 1) ≤ log (n + 1) := by refine (hc.deriv_le_slope (by positivity : (0 : ℝ) < n + 1) (by positivity : (0 : ℝ) < n + 2) (by linarith) (hder <| by positivity)).trans (le_of_eq ?_) rw [slope_def_field, show n + 2 - (n + 1) = (1 : ℝ) by ring, div_one, show n + 2 = (n + 1) + (1 : ℝ) by ring, h_rec (n + 1) (by positivity), add_sub_cancel_left] -- deduce `-deriv f 1` is bounded above + below by sequences which both tend to `γ` apply le_antisymm · apply ge_of_tendsto tendsto_harmonic_sub_log filter_upwards [eventually_gt_atTop 0] with n hn rw [le_sub_iff_add_le', ← sub_eq_add_neg, sub_le_iff_le_add', ← hder_nat] exact derivLB n hn · apply le_of_tendsto tendsto_harmonic_sub_log_add_one filter_upwards with n rw [sub_le_iff_le_add', ← sub_eq_add_neg, le_sub_iff_add_le', ← hder_nat] exact derivUB n
lemma hasDerivAt_Gamma_nat (n : ℕ) : HasDerivAt Gamma (n ! * (-γ + harmonic n)) (n + 1) := (deriv_Gamma_nat n).symm ▸
Mathlib/NumberTheory/Harmonic/GammaDeriv.lean
83
86
/- Copyright (c) 2021 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.Convex.Cone.Basic import Mathlib.Analysis.InnerProductSpace.Projection /-! # Convex cones in inner product spaces We define `Set.innerDualCone` to be the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. ## Main statements We prove the following theorems: * `ConvexCone.innerDualCone_of_innerDualCone_eq_self`: The `innerDualCone` of the `innerDualCone` of a nonempty, closed, convex cone is itself. * `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`: This variant of the [hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem) states that given a nonempty, closed, convex cone `K` in a complete, real inner product space `H` and a point `b` disjoint from it, there is a vector `y` which separates `b` from `K` in the sense that for all points `x` in `K`, `0 ≤ ⟪x, y⟫_ℝ` and `⟪y, b⟫_ℝ < 0`. This is also a geometric interpretation of the [Farkas lemma](https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation). -/ open Set LinearMap Pointwise /-! ### The dual cone -/ section Dual variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] (s t : Set H) open RealInnerProductSpace /-- The dual cone is the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. -/ def Set.innerDualCone (s : Set H) : ConvexCone ℝ H where carrier := { y | ∀ x ∈ s, 0 ≤ ⟪x, y⟫ } smul_mem' c hc y hy x hx := by rw [real_inner_smul_right] exact mul_nonneg hc.le (hy x hx) add_mem' u hu v hv x hx := by rw [inner_add_right] exact add_nonneg (hu x hx) (hv x hx) @[simp] theorem mem_innerDualCone (y : H) (s : Set H) : y ∈ s.innerDualCone ↔ ∀ x ∈ s, 0 ≤ ⟪x, y⟫ := Iff.rfl @[simp] theorem innerDualCone_empty : (∅ : Set H).innerDualCone = ⊤ := eq_top_iff.mpr fun _ _ _ => False.elim /-- Dual cone of the convex cone {0} is the total space. -/ @[simp] theorem innerDualCone_zero : (0 : Set H).innerDualCone = ⊤ := eq_top_iff.mpr fun _ _ y (hy : y = 0) => hy.symm ▸ (inner_zero_left _).ge /-- Dual cone of the total space is the convex cone {0}. -/ @[simp] theorem innerDualCone_univ : (univ : Set H).innerDualCone = 0 := by suffices ∀ x : H, x ∈ (univ : Set H).innerDualCone → x = 0 by apply SetLike.coe_injective exact eq_singleton_iff_unique_mem.mpr ⟨fun x _ => (inner_zero_right _).ge, this⟩ exact fun x hx => by simpa [← real_inner_self_nonpos] using hx (-x) (mem_univ _) variable {s t} in @[gcongr] theorem innerDualCone_le_innerDualCone (h : t ⊆ s) : s.innerDualCone ≤ t.innerDualCone := fun _ hy x hx => hy x (h hx)
theorem pointed_innerDualCone : s.innerDualCone.Pointed := fun x _ => by rw [inner_zero_right] /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `fun y ↦ ⟪x, y⟫`. -/ theorem innerDualCone_singleton (x : H) :
Mathlib/Analysis/Convex/Cone/InnerDual.lean
78
82
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals import Mathlib.MeasureTheory.Integral.ExpDecay /-! # The Gamma function This file defines the `Γ` function (of a real or complex variable `s`). We define this by Euler's integral `Γ(s) = ∫ x in Ioi 0, exp (-x) * x ^ (s - 1)` in the range where this integral converges (i.e., for `0 < s` in the real case, and `0 < re s` in the complex case). We show that this integral satisfies `Γ(1) = 1` and `Γ(s + 1) = s * Γ(s)`; hence we can define `Γ(s)` for all `s` as the unique function satisfying this recurrence and agreeing with Euler's integral in the convergence range. (If `s = -n` for `n ∈ ℕ`, then the function is undefined, and we set it to be `0` by convention.) ## Gamma function: main statements (complex case) * `Complex.Gamma`: the `Γ` function (of a complex variable). * `Complex.Gamma_eq_integral`: for `0 < re s`, `Γ(s)` agrees with Euler's integral. * `Complex.Gamma_add_one`: for all `s : ℂ` with `s ≠ 0`, we have `Γ (s + 1) = s Γ(s)`. * `Complex.Gamma_nat_eq_factorial`: for all `n : ℕ` we have `Γ (n + 1) = n!`. ## Gamma function: main statements (real case) * `Real.Gamma`: the `Γ` function (of a real variable). * Real counterparts of all the properties of the complex Gamma function listed above: `Real.Gamma_eq_integral`, `Real.Gamma_add_one`, `Real.Gamma_nat_eq_factorial`. ## Tags Gamma -/ noncomputable section open Filter intervalIntegral Set Real MeasureTheory Asymptotics open scoped Nat Topology ComplexConjugate namespace Real /-- Asymptotic bound for the `Γ` function integrand. -/ theorem Gamma_integrand_isLittleO (s : ℝ) : (fun x : ℝ => exp (-x) * x ^ s) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by refine isLittleO_of_tendsto (fun x hx => ?_) ?_ · exfalso; exact (exp_pos (-(1 / 2) * x)).ne' hx have : (fun x : ℝ => exp (-x) * x ^ s / exp (-(1 / 2) * x)) = (fun x : ℝ => exp (1 / 2 * x) / x ^ s)⁻¹ := by ext1 x field_simp [exp_ne_zero, exp_neg, ← Real.exp_add] left ring rw [this] exact (tendsto_exp_mul_div_rpow_atTop s (1 / 2) one_half_pos).inv_tendsto_atTop /-- The Euler integral for the `Γ` function converges for positive real `s`. -/ theorem GammaIntegral_convergent {s : ℝ} (h : 0 < s) : IntegrableOn (fun x : ℝ => exp (-x) * x ^ (s - 1)) (Ioi 0) := by rw [← Ioc_union_Ioi_eq_Ioi (@zero_le_one ℝ _ _ _ _), integrableOn_union] constructor · rw [← integrableOn_Icc_iff_integrableOn_Ioc] refine IntegrableOn.continuousOn_mul continuousOn_id.neg.rexp ?_ isCompact_Icc refine (intervalIntegrable_iff_integrableOn_Icc_of_le zero_le_one).mp ?_ exact intervalIntegrable_rpow' (by linarith) · refine integrable_of_isBigO_exp_neg one_half_pos ?_ (Gamma_integrand_isLittleO _).isBigO refine continuousOn_id.neg.rexp.mul (continuousOn_id.rpow_const ?_) intro x hx exact Or.inl ((zero_lt_one : (0 : ℝ) < 1).trans_le hx).ne' end Real namespace Complex /- Technical note: In defining the Gamma integrand exp (-x) * x ^ (s - 1) for s complex, we have to make a choice between ↑(Real.exp (-x)), Complex.exp (↑(-x)), and Complex.exp (-↑x), all of which are equal but not definitionally so. We use the first of these throughout. -/ /-- The integral defining the `Γ` function converges for complex `s` with `0 < re s`. This is proved by reduction to the real case. -/ theorem GammaIntegral_convergent {s : ℂ} (hs : 0 < s.re) : IntegrableOn (fun x => (-x).exp * x ^ (s - 1) : ℝ → ℂ) (Ioi 0) := by constructor · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi apply (continuous_ofReal.comp continuous_neg.rexp).continuousOn.mul apply continuousOn_of_forall_continuousAt intro x hx have : ContinuousAt (fun x : ℂ => x ^ (s - 1)) ↑x := continuousAt_cpow_const <| ofReal_mem_slitPlane.2 hx exact ContinuousAt.comp this continuous_ofReal.continuousAt · rw [← hasFiniteIntegral_norm_iff] refine HasFiniteIntegral.congr (Real.GammaIntegral_convergent hs).2 ?_ apply (ae_restrict_iff' measurableSet_Ioi).mpr filter_upwards with x hx rw [norm_mul, Complex.norm_of_nonneg <| le_of_lt <| exp_pos <| -x, norm_cpow_eq_rpow_re_of_pos hx _] simp /-- Euler's integral for the `Γ` function (of a complex variable `s`), defined as `∫ x in Ioi 0, exp (-x) * x ^ (s - 1)`. See `Complex.GammaIntegral_convergent` for a proof of the convergence of the integral for `0 < re s`. -/ def GammaIntegral (s : ℂ) : ℂ := ∫ x in Ioi (0 : ℝ), ↑(-x).exp * ↑x ^ (s - 1) theorem GammaIntegral_conj (s : ℂ) : GammaIntegral (conj s) = conj (GammaIntegral s) := by rw [GammaIntegral, GammaIntegral, ← integral_conj] refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ dsimp only rw [RingHom.map_mul, conj_ofReal, cpow_def_of_ne_zero (ofReal_ne_zero.mpr (ne_of_gt hx)), cpow_def_of_ne_zero (ofReal_ne_zero.mpr (ne_of_gt hx)), ← exp_conj, RingHom.map_mul, ← ofReal_log (le_of_lt hx), conj_ofReal, RingHom.map_sub, RingHom.map_one] theorem GammaIntegral_ofReal (s : ℝ) : GammaIntegral ↑s = ↑(∫ x : ℝ in Ioi 0, Real.exp (-x) * x ^ (s - 1)) := by have : ∀ r : ℝ, Complex.ofReal r = @RCLike.ofReal ℂ _ r := fun r => rfl rw [GammaIntegral] conv_rhs => rw [this, ← _root_.integral_ofReal] refine setIntegral_congr_fun measurableSet_Ioi ?_ intro x hx; dsimp only conv_rhs => rw [← this] rw [ofReal_mul, ofReal_cpow (mem_Ioi.mp hx).le] simp @[simp] theorem GammaIntegral_one : GammaIntegral 1 = 1 := by simpa only [← ofReal_one, GammaIntegral_ofReal, ofReal_inj, sub_self, rpow_zero, mul_one] using integral_exp_neg_Ioi_zero end Complex /-! Now we establish the recurrence relation `Γ(s + 1) = s * Γ(s)` using integration by parts. -/ namespace Complex section GammaRecurrence /-- The indefinite version of the `Γ` function, `Γ(s, X) = ∫ x ∈ 0..X, exp(-x) x ^ (s - 1)`. -/ def partialGamma (s : ℂ) (X : ℝ) : ℂ := ∫ x in (0)..X, (-x).exp * x ^ (s - 1) theorem tendsto_partialGamma {s : ℂ} (hs : 0 < s.re) : Tendsto (fun X : ℝ => partialGamma s X) atTop (𝓝 <| GammaIntegral s) := intervalIntegral_tendsto_integral_Ioi 0 (GammaIntegral_convergent hs) tendsto_id private theorem Gamma_integrand_intervalIntegrable (s : ℂ) {X : ℝ} (hs : 0 < s.re) (hX : 0 ≤ X) : IntervalIntegrable (fun x => (-x).exp * x ^ (s - 1) : ℝ → ℂ) volume 0 X := by rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hX] exact IntegrableOn.mono_set (GammaIntegral_convergent hs) Ioc_subset_Ioi_self private theorem Gamma_integrand_deriv_integrable_A {s : ℂ} (hs : 0 < s.re) {X : ℝ} (hX : 0 ≤ X) : IntervalIntegrable (fun x => -((-x).exp * x ^ s) : ℝ → ℂ) volume 0 X := by convert (Gamma_integrand_intervalIntegrable (s + 1) _ hX).neg · simp only [ofReal_exp, ofReal_neg, add_sub_cancel_right]; rfl · simp only [add_re, one_re]; linarith private theorem Gamma_integrand_deriv_integrable_B {s : ℂ} (hs : 0 < s.re) {Y : ℝ} (hY : 0 ≤ Y) : IntervalIntegrable (fun x : ℝ => (-x).exp * (s * x ^ (s - 1)) : ℝ → ℂ) volume 0 Y := by have : (fun x => (-x).exp * (s * x ^ (s - 1)) : ℝ → ℂ) = (fun x => s * ((-x).exp * x ^ (s - 1)) : ℝ → ℂ) := by ext1; ring rw [this, intervalIntegrable_iff_integrableOn_Ioc_of_le hY] constructor · refine (continuousOn_const.mul ?_).aestronglyMeasurable measurableSet_Ioc apply (continuous_ofReal.comp continuous_neg.rexp).continuousOn.mul apply continuousOn_of_forall_continuousAt intro x hx refine (?_ : ContinuousAt (fun x : ℂ => x ^ (s - 1)) _).comp continuous_ofReal.continuousAt exact continuousAt_cpow_const <| ofReal_mem_slitPlane.2 hx.1 rw [← hasFiniteIntegral_norm_iff] simp_rw [norm_mul] refine (((Real.GammaIntegral_convergent hs).mono_set Ioc_subset_Ioi_self).hasFiniteIntegral.congr ?_).const_mul _ rw [EventuallyEq, ae_restrict_iff'] · filter_upwards with x hx rw [Complex.norm_of_nonneg (exp_pos _).le, norm_cpow_eq_rpow_re_of_pos hx.1] simp · exact measurableSet_Ioc /-- The recurrence relation for the indefinite version of the `Γ` function. -/ theorem partialGamma_add_one {s : ℂ} (hs : 0 < s.re) {X : ℝ} (hX : 0 ≤ X) : partialGamma (s + 1) X = s * partialGamma s X - (-X).exp * X ^ s := by rw [partialGamma, partialGamma, add_sub_cancel_right] have F_der_I : ∀ x : ℝ, x ∈ Ioo 0 X → HasDerivAt (fun x => (-x).exp * x ^ s : ℝ → ℂ) (-((-x).exp * x ^ s) + (-x).exp * (s * x ^ (s - 1))) x := by intro x hx have d1 : HasDerivAt (fun y : ℝ => (-y).exp) (-(-x).exp) x := by simpa using (hasDerivAt_neg x).exp have d2 : HasDerivAt (fun y : ℝ => (y : ℂ) ^ s) (s * x ^ (s - 1)) x := by have t := @HasDerivAt.cpow_const _ _ _ s (hasDerivAt_id ↑x) ?_ · simpa only [mul_one] using t.comp_ofReal · exact ofReal_mem_slitPlane.2 hx.1 simpa only [ofReal_neg, neg_mul] using d1.ofReal_comp.mul d2 have cont := (continuous_ofReal.comp continuous_neg.rexp).mul (continuous_ofReal_cpow_const hs) have der_ible := (Gamma_integrand_deriv_integrable_A hs hX).add (Gamma_integrand_deriv_integrable_B hs hX) have int_eval := integral_eq_sub_of_hasDerivAt_of_le hX cont.continuousOn F_der_I der_ible -- We are basically done here but manipulating the output into the right form is fiddly. apply_fun fun x : ℂ => -x at int_eval rw [intervalIntegral.integral_add (Gamma_integrand_deriv_integrable_A hs hX) (Gamma_integrand_deriv_integrable_B hs hX), intervalIntegral.integral_neg, neg_add, neg_neg] at int_eval rw [eq_sub_of_add_eq int_eval, sub_neg_eq_add, neg_sub, add_comm, add_sub] have : (fun x => (-x).exp * (s * x ^ (s - 1)) : ℝ → ℂ) = (fun x => s * (-x).exp * x ^ (s - 1) : ℝ → ℂ) := by ext1; ring rw [this] have t := @integral_const_mul 0 X volume _ _ s fun x : ℝ => (-x).exp * x ^ (s - 1) rw [← t, ofReal_zero, zero_cpow] · rw [mul_zero, add_zero]; congr 2; ext1; ring · contrapose! hs; rw [hs, zero_re] /-- The recurrence relation for the `Γ` integral. -/ theorem GammaIntegral_add_one {s : ℂ} (hs : 0 < s.re) : GammaIntegral (s + 1) = s * GammaIntegral s := by suffices Tendsto (s + 1).partialGamma atTop (𝓝 <| s * GammaIntegral s) by refine tendsto_nhds_unique ?_ this apply tendsto_partialGamma; rw [add_re, one_re]; linarith have : (fun X : ℝ => s * partialGamma s X - X ^ s * (-X).exp) =ᶠ[atTop] (s + 1).partialGamma := by apply eventuallyEq_of_mem (Ici_mem_atTop (0 : ℝ)) intro X hX rw [partialGamma_add_one hs (mem_Ici.mp hX)] ring_nf refine Tendsto.congr' this ?_ suffices Tendsto (fun X => -X ^ s * (-X).exp : ℝ → ℂ) atTop (𝓝 0) by simpa using Tendsto.add (Tendsto.const_mul s (tendsto_partialGamma hs)) this rw [tendsto_zero_iff_norm_tendsto_zero] have : (fun e : ℝ => ‖-(e : ℂ) ^ s * (-e).exp‖) =ᶠ[atTop] fun e : ℝ => e ^ s.re * (-1 * e).exp := by refine eventuallyEq_of_mem (Ioi_mem_atTop 0) ?_ intro x hx; dsimp only rw [norm_mul, norm_neg, norm_cpow_eq_rpow_re_of_pos hx, Complex.norm_of_nonneg (exp_pos (-x)).le, neg_mul, one_mul] exact (tendsto_congr' this).mpr (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero _ _ zero_lt_one) end GammaRecurrence /-! Now we define `Γ(s)` on the whole complex plane, by recursion. -/ section GammaDef /-- The `n`th function in this family is `Γ(s)` if `-n < s.re`, and junk otherwise. -/ noncomputable def GammaAux : ℕ → ℂ → ℂ | 0 => GammaIntegral | n + 1 => fun s : ℂ => GammaAux n (s + 1) / s theorem GammaAux_recurrence1 (s : ℂ) (n : ℕ) (h1 : -s.re < ↑n) : GammaAux n s = GammaAux n (s + 1) / s := by induction' n with n hn generalizing s · simp only [CharP.cast_eq_zero, Left.neg_neg_iff] at h1 dsimp only [GammaAux]; rw [GammaIntegral_add_one h1] rw [mul_comm, mul_div_cancel_right₀]; contrapose! h1; rw [h1] simp · dsimp only [GammaAux] have hh1 : -(s + 1).re < n := by rw [Nat.cast_add, Nat.cast_one] at h1 rw [add_re, one_re]; linarith rw [← hn (s + 1) hh1] theorem GammaAux_recurrence2 (s : ℂ) (n : ℕ) (h1 : -s.re < ↑n) : GammaAux n s = GammaAux (n + 1) s := by rcases n with - | n · simp only [CharP.cast_eq_zero, Left.neg_neg_iff] at h1 dsimp only [GammaAux] rw [GammaIntegral_add_one h1, mul_div_cancel_left₀] rintro rfl rw [zero_re] at h1 exact h1.false · dsimp only [GammaAux] have : GammaAux n (s + 1 + 1) / (s + 1) = GammaAux n (s + 1) := by have hh1 : -(s + 1).re < n := by rw [Nat.cast_add, Nat.cast_one] at h1 rw [add_re, one_re]; linarith rw [GammaAux_recurrence1 (s + 1) n hh1] rw [this] /-- The `Γ` function (of a complex variable `s`). -/ @[pp_nodot] irreducible_def Gamma (s : ℂ) : ℂ := GammaAux ⌊1 - s.re⌋₊ s theorem Gamma_eq_GammaAux (s : ℂ) (n : ℕ) (h1 : -s.re < ↑n) : Gamma s = GammaAux n s := by have u : ∀ k : ℕ, GammaAux (⌊1 - s.re⌋₊ + k) s = Gamma s := by intro k; induction' k with k hk · simp [Gamma] · rw [← hk, ← add_assoc] refine (GammaAux_recurrence2 s (⌊1 - s.re⌋₊ + k) ?_).symm rw [Nat.cast_add] have i0 := Nat.sub_one_lt_floor (1 - s.re) simp only [sub_sub_cancel_left] at i0 refine lt_add_of_lt_of_nonneg i0 ?_ rw [← Nat.cast_zero, Nat.cast_le]; exact Nat.zero_le k convert (u <| n - ⌊1 - s.re⌋₊).symm; rw [Nat.add_sub_of_le] by_cases h : 0 ≤ 1 - s.re · apply Nat.le_of_lt_succ exact_mod_cast lt_of_le_of_lt (Nat.floor_le h) (by linarith : 1 - s.re < n + 1) · rw [Nat.floor_of_nonpos] · omega · linarith /-- The recurrence relation for the `Γ` function. -/ theorem Gamma_add_one (s : ℂ) (h2 : s ≠ 0) : Gamma (s + 1) = s * Gamma s := by let n := ⌊1 - s.re⌋₊ have t1 : -s.re < n := by simpa only [sub_sub_cancel_left] using Nat.sub_one_lt_floor (1 - s.re) have t2 : -(s + 1).re < n := by rw [add_re, one_re]; linarith rw [Gamma_eq_GammaAux s n t1, Gamma_eq_GammaAux (s + 1) n t2, GammaAux_recurrence1 s n t1] field_simp theorem Gamma_eq_integral {s : ℂ} (hs : 0 < s.re) : Gamma s = GammaIntegral s := Gamma_eq_GammaAux s 0 (by norm_cast; linarith) @[simp] theorem Gamma_one : Gamma 1 = 1 := by rw [Gamma_eq_integral] <;> simp theorem Gamma_nat_eq_factorial (n : ℕ) : Gamma (n + 1) = n ! := by induction n with | zero => simp | succ n hn => rw [Gamma_add_one n.succ <| Nat.cast_ne_zero.mpr <| Nat.succ_ne_zero n] simp only [Nat.cast_succ, Nat.factorial_succ, Nat.cast_mul] congr @[simp] theorem Gamma_ofNat_eq_factorial (n : ℕ) [(n + 1).AtLeastTwo] : Gamma (ofNat(n + 1) : ℂ) = n ! := mod_cast Gamma_nat_eq_factorial (n : ℕ) /-- At `0` the Gamma function is undefined; by convention we assign it the value `0`. -/ @[simp] theorem Gamma_zero : Gamma 0 = 0 := by simp_rw [Gamma, zero_re, sub_zero, Nat.floor_one, GammaAux, div_zero] /-- At `-n` for `n ∈ ℕ`, the Gamma function is undefined; by convention we assign it the value 0. -/ theorem Gamma_neg_nat_eq_zero (n : ℕ) : Gamma (-n) = 0 := by induction n with | zero => rw [Nat.cast_zero, neg_zero, Gamma_zero] | succ n IH => have A : -(n.succ : ℂ) ≠ 0 := by rw [neg_ne_zero, Nat.cast_ne_zero] apply Nat.succ_ne_zero have : -(n : ℂ) = -↑n.succ + 1 := by simp rw [this, Gamma_add_one _ A] at IH contrapose! IH exact mul_ne_zero A IH theorem Gamma_conj (s : ℂ) : Gamma (conj s) = conj (Gamma s) := by suffices ∀ (n : ℕ) (s : ℂ), GammaAux n (conj s) = conj (GammaAux n s) by simp [Gamma, this] intro n induction n with | zero => rw [GammaAux]; exact GammaIntegral_conj | succ n IH => intro s rw [GammaAux] dsimp only rw [div_eq_mul_inv _ s, RingHom.map_mul, conj_inv, ← div_eq_mul_inv] suffices conj s + 1 = conj (s + 1) by rw [this, IH] rw [RingHom.map_add, RingHom.map_one] /-- Expresses the integral over `Ioi 0` of `t ^ (a - 1) * exp (-(r * t))` in terms of the Gamma function, for complex `a`. -/ lemma integral_cpow_mul_exp_neg_mul_Ioi {a : ℂ} {r : ℝ} (ha : 0 < a.re) (hr : 0 < r) : ∫ (t : ℝ) in Ioi 0, t ^ (a - 1) * exp (-(r * t)) = (1 / r) ^ a * Gamma a := by have aux : (1 / r : ℂ) ^ a = 1 / r * (1 / r) ^ (a - 1) := by nth_rewrite 2 [← cpow_one (1 / r : ℂ)] rw [← cpow_add _ _ (one_div_ne_zero <| ofReal_ne_zero.mpr hr.ne'), add_sub_cancel] calc _ = ∫ (t : ℝ) in Ioi 0, (1 / r) ^ (a - 1) * (r * t) ^ (a - 1) * exp (-(r * t)) := by refine MeasureTheory.setIntegral_congr_fun measurableSet_Ioi (fun x hx ↦ ?_) rw [mem_Ioi] at hx rw [mul_cpow_ofReal_nonneg hr.le hx.le, ← mul_assoc, one_div, ← ofReal_inv, ← mul_cpow_ofReal_nonneg (inv_pos.mpr hr).le hr.le, ← ofReal_mul r⁻¹, inv_mul_cancel₀ hr.ne', ofReal_one, one_cpow, one_mul] _ = 1 / r * ∫ (t : ℝ) in Ioi 0, (1 / r) ^ (a - 1) * t ^ (a - 1) * exp (-t) := by simp_rw [← ofReal_mul] rw [integral_comp_mul_left_Ioi (fun x ↦ _ * x ^ (a - 1) * exp (-x)) _ hr, mul_zero, real_smul, ← one_div, ofReal_div, ofReal_one] _ = 1 / r * (1 / r : ℂ) ^ (a - 1) * (∫ (t : ℝ) in Ioi 0, t ^ (a - 1) * exp (-t)) := by simp_rw [← MeasureTheory.integral_const_mul, mul_assoc] _ = (1 / r) ^ a * Gamma a := by rw [aux, Gamma_eq_integral ha] congr 2 with x rw [ofReal_exp, ofReal_neg, mul_comm] end GammaDef end Complex namespace Real /-- The `Γ` function (of a real variable `s`). -/ @[pp_nodot] def Gamma (s : ℝ) : ℝ := (Complex.Gamma s).re theorem Gamma_eq_integral {s : ℝ} (hs : 0 < s) : Gamma s = ∫ x in Ioi 0, exp (-x) * x ^ (s - 1) := by rw [Gamma, Complex.Gamma_eq_integral (by rwa [Complex.ofReal_re] : 0 < Complex.re s)] dsimp only [Complex.GammaIntegral] simp_rw [← Complex.ofReal_one, ← Complex.ofReal_sub] suffices ∫ x : ℝ in Ioi 0, ↑(exp (-x)) * (x : ℂ) ^ ((s - 1 : ℝ) : ℂ) = ∫ x : ℝ in Ioi 0, ((exp (-x) * x ^ (s - 1) : ℝ) : ℂ) by have cc : ∀ r : ℝ, Complex.ofReal r = @RCLike.ofReal ℂ _ r := fun r => rfl conv_lhs => rw [this]; enter [1, 2, x]; rw [cc] rw [_root_.integral_ofReal, ← cc, Complex.ofReal_re] refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ push_cast rw [Complex.ofReal_cpow (le_of_lt hx)] push_cast; rfl theorem Gamma_add_one {s : ℝ} (hs : s ≠ 0) : Gamma (s + 1) = s * Gamma s := by simp_rw [Gamma] rw [Complex.ofReal_add, Complex.ofReal_one, Complex.Gamma_add_one, Complex.re_ofReal_mul] rwa [Complex.ofReal_ne_zero] @[simp] theorem Gamma_one : Gamma 1 = 1 := by
rw [Gamma, Complex.ofReal_one, Complex.Gamma_one, Complex.one_re]
Mathlib/Analysis/SpecialFunctions/Gamma/Basic.lean
426
427
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope /-! # Line derivatives We define the line derivative of a function `f : E → F`, at a point `x : E` along a vector `v : E`, as the element `f' : F` such that `f (x + t • v) = f x + t • f' + o (t)` as `t` tends to `0` in the scalar field `𝕜`, if it exists. It is denoted by `lineDeriv 𝕜 f x v`. This notion is generally less well behaved than the full Fréchet derivative (for instance, the composition of functions which are line-differentiable is not line-differentiable in general). The Fréchet derivative should therefore be favored over this one in general, although the line derivative may sometimes prove handy. The line derivative in direction `v` is also called the Gateaux derivative in direction `v`, although the term "Gateaux derivative" is sometimes reserved for the situation where there is such a derivative in all directions, for the map `v ↦ lineDeriv 𝕜 f x v` (which doesn't have to be linear in general). ## Main definition and results We mimic the definitions and statements for the Fréchet derivative and the one-dimensional derivative. We define in particular the following objects: * `LineDifferentiableWithinAt 𝕜 f s x v` * `LineDifferentiableAt 𝕜 f x v` * `HasLineDerivWithinAt 𝕜 f f' s x v` * `HasLineDerivAt 𝕜 f s x v` * `lineDerivWithin 𝕜 f s x v` * `lineDeriv 𝕜 f x v` and develop about them a basic API inspired by the one for the Fréchet derivative. We depart from the Fréchet derivative in two places, as the dependence of the following predicates on the direction would make them barely usable: * We do not define an analogue of the predicate `UniqueDiffOn`; * We do not define `LineDifferentiableOn` nor `LineDifferentiable`. -/ noncomputable section open scoped Topology Filter ENNReal NNReal open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section Module /-! Results that do not rely on a topological structure on `E` -/ variable (𝕜) variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] /-- `f` has the derivative `f'` at the point `x` along the direction `v` in the set `s`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivWithinAt (f : E → F) (f' : F) (s : Set E) (x : E) (v : E) := HasDerivWithinAt (fun t ↦ f (x + t • v)) f' ((fun t ↦ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` has the derivative `f'` at the point `x` along the direction `v`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivAt (f : E → F) (f' : F) (x : E) (v : E) := HasDerivAt (fun t ↦ f (x + t • v)) f' (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` in the set `s` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def LineDifferentiableWithinAt (f : E → F) (s : Set E) (x : E) (v : E) : Prop := DifferentiableWithinAt 𝕜 (fun t ↦ f (x + t • v)) ((fun t ↦ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. -/ def LineDifferentiableAt (f : E → F) (x : E) (v : E) : Prop := DifferentiableAt 𝕜 (fun t ↦ f (x + t • v)) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v` within the set `s`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivWithinAt 𝕜 f f' s x v`), then `f (x + t v) = f x + t lineDerivWithin 𝕜 f s x v + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def lineDerivWithin (f : E → F) (s : Set E) (x : E) (v : E) : F := derivWithin (fun t ↦ f (x + t • v)) ((fun t ↦ x + t • v) ⁻¹' s) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivAt 𝕜 f f' x v`), then `f (x + t v) = f x + t lineDeriv 𝕜 f x v + o (t)` when `t` tends to `0`. -/ def lineDeriv (f : E → F) (x : E) (v : E) : F := deriv (fun t ↦ f (x + t • v)) (0 : 𝕜) variable {𝕜} variable {f f₁ : E → F} {f' f₀' f₁' : F} {s t : Set E} {x v : E} lemma HasLineDerivWithinAt.mono (hf : HasLineDerivWithinAt 𝕜 f f' s x v) (hst : t ⊆ s) : HasLineDerivWithinAt 𝕜 f f' t x v := HasDerivWithinAt.mono hf (preimage_mono hst) lemma HasLineDerivAt.hasLineDerivWithinAt (hf : HasLineDerivAt 𝕜 f f' x v) (s : Set E) : HasLineDerivWithinAt 𝕜 f f' s x v := HasDerivAt.hasDerivWithinAt hf lemma HasLineDerivWithinAt.lineDifferentiableWithinAt (hf : HasLineDerivWithinAt 𝕜 f f' s x v) : LineDifferentiableWithinAt 𝕜 f s x v := HasDerivWithinAt.differentiableWithinAt hf theorem HasLineDerivAt.lineDifferentiableAt (hf : HasLineDerivAt 𝕜 f f' x v) : LineDifferentiableAt 𝕜 f x v := HasDerivAt.differentiableAt hf theorem LineDifferentiableWithinAt.hasLineDerivWithinAt (h : LineDifferentiableWithinAt 𝕜 f s x v) : HasLineDerivWithinAt 𝕜 f (lineDerivWithin 𝕜 f s x v) s x v := DifferentiableWithinAt.hasDerivWithinAt h theorem LineDifferentiableAt.hasLineDerivAt (h : LineDifferentiableAt 𝕜 f x v) : HasLineDerivAt 𝕜 f (lineDeriv 𝕜 f x v) x v := DifferentiableAt.hasDerivAt h @[simp] lemma hasLineDerivWithinAt_univ : HasLineDerivWithinAt 𝕜 f f' univ x v ↔ HasLineDerivAt 𝕜 f f' x v := by simp only [HasLineDerivWithinAt, HasLineDerivAt, preimage_univ, hasDerivWithinAt_univ] theorem lineDerivWithin_zero_of_not_lineDifferentiableWithinAt (h : ¬LineDifferentiableWithinAt 𝕜 f s x v) : lineDerivWithin 𝕜 f s x v = 0 := derivWithin_zero_of_not_differentiableWithinAt h theorem lineDeriv_zero_of_not_lineDifferentiableAt (h : ¬LineDifferentiableAt 𝕜 f x v) : lineDeriv 𝕜 f x v = 0 := deriv_zero_of_not_differentiableAt h theorem hasLineDerivAt_iff_isLittleO_nhds_zero : HasLineDerivAt 𝕜 f f' x v ↔ (fun t : 𝕜 => f (x + t • v) - f x - t • f') =o[𝓝 0] fun t => t := by simp only [HasLineDerivAt, hasDerivAt_iff_isLittleO_nhds_zero, zero_add, zero_smul, add_zero] theorem HasLineDerivAt.unique (h₀ : HasLineDerivAt 𝕜 f f₀' x v) (h₁ : HasLineDerivAt 𝕜 f f₁' x v) : f₀' = f₁' := HasDerivAt.unique h₀ h₁ protected theorem HasLineDerivAt.lineDeriv (h : HasLineDerivAt 𝕜 f f' x v) : lineDeriv 𝕜 f x v = f' := by rw [h.unique h.lineDifferentiableAt.hasLineDerivAt] theorem lineDifferentiableWithinAt_univ : LineDifferentiableWithinAt 𝕜 f univ x v ↔ LineDifferentiableAt 𝕜 f x v := by simp only [LineDifferentiableWithinAt, LineDifferentiableAt, preimage_univ, differentiableWithinAt_univ] theorem LineDifferentiableAt.lineDifferentiableWithinAt (h : LineDifferentiableAt 𝕜 f x v) : LineDifferentiableWithinAt 𝕜 f s x v := (differentiableWithinAt_univ.2 h).mono (subset_univ _) @[simp] theorem lineDerivWithin_univ : lineDerivWithin 𝕜 f univ x v = lineDeriv 𝕜 f x v := by simp [lineDerivWithin, lineDeriv] theorem LineDifferentiableWithinAt.mono (h : LineDifferentiableWithinAt 𝕜 f t x v) (st : s ⊆ t) : LineDifferentiableWithinAt 𝕜 f s x v := (h.hasLineDerivWithinAt.mono st).lineDifferentiableWithinAt theorem HasLineDerivWithinAt.congr_mono (h : HasLineDerivWithinAt 𝕜 f f' s x v) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : HasLineDerivWithinAt 𝕜 f₁ f' t x v := HasDerivWithinAt.congr_mono h (fun _ hy ↦ ht hy) (by simpa using hx) (preimage_mono h₁) theorem HasLineDerivWithinAt.congr (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : EqOn f₁ f s) (hx : f₁ x = f x) : HasLineDerivWithinAt 𝕜 f₁ f' s x v := h.congr_mono hs hx (Subset.refl _) theorem HasLineDerivWithinAt.congr' (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : EqOn f₁ f s) (hx : x ∈ s) : HasLineDerivWithinAt 𝕜 f₁ f' s x v := h.congr hs (hs hx) theorem LineDifferentiableWithinAt.congr_mono (h : LineDifferentiableWithinAt 𝕜 f s x v) (ht : EqOn f₁ f t) (hx : f₁ x = f x) (h₁ : t ⊆ s) : LineDifferentiableWithinAt 𝕜 f₁ t x v := (HasLineDerivWithinAt.congr_mono h.hasLineDerivWithinAt ht hx h₁).differentiableWithinAt theorem LineDifferentiableWithinAt.congr (h : LineDifferentiableWithinAt 𝕜 f s x v) (ht : ∀ x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : LineDifferentiableWithinAt 𝕜 f₁ s x v := LineDifferentiableWithinAt.congr_mono h ht hx (Subset.refl _) theorem lineDerivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := derivWithin_congr (fun _ hy ↦ hs hy) (by simpa using hx) theorem lineDerivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := lineDerivWithin_congr hs (hs hx) theorem hasLineDerivAt_iff_tendsto_slope_zero : HasLineDerivAt 𝕜 f f' x v ↔ Tendsto (fun (t : 𝕜) ↦ t⁻¹ • (f (x + t • v) - f x)) (𝓝[≠] 0) (𝓝 f') := by simp only [HasLineDerivAt, hasDerivAt_iff_tendsto_slope_zero, zero_add, zero_smul, add_zero] alias ⟨HasLineDerivAt.tendsto_slope_zero, _⟩ := hasLineDerivAt_iff_tendsto_slope_zero theorem HasLineDerivAt.tendsto_slope_zero_right [Preorder 𝕜] (h : HasLineDerivAt 𝕜 f f' x v) : Tendsto (fun (t : 𝕜) ↦ t⁻¹ • (f (x + t • v) - f x)) (𝓝[>] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhdsGT_le_nhdsNE 0) theorem HasLineDerivAt.tendsto_slope_zero_left [Preorder 𝕜] (h : HasLineDerivAt 𝕜 f f' x v) : Tendsto (fun (t : 𝕜) ↦ t⁻¹ • (f (x + t • v) - f x)) (𝓝[<] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhdsLT_le_nhdsNE 0) theorem HasLineDerivWithinAt.hasLineDerivAt' (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : ∀ᶠ t : 𝕜 in 𝓝 0, x + t • v ∈ s) : HasLineDerivAt 𝕜 f f' x v := h.hasDerivAt hs end Module section NormedSpace /-! Results that need a normed space structure on `E` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f f₀ f₁ : E → F} {f' : F} {s t : Set E} {x v : E} {L : E →L[𝕜] F} theorem HasLineDerivWithinAt.mono_of_mem_nhdsWithin (h : HasLineDerivWithinAt 𝕜 f f' t x v) (hst : t ∈ 𝓝[s] x) : HasLineDerivWithinAt 𝕜 f f' s x v := by apply HasDerivWithinAt.mono_of_mem_nhdsWithin h apply ContinuousWithinAt.preimage_mem_nhdsWithin'' _ hst (by simp) apply Continuous.continuousWithinAt; fun_prop @[deprecated (since := "2024-10-31")] alias HasLineDerivWithinAt.mono_of_mem := HasLineDerivWithinAt.mono_of_mem_nhdsWithin theorem HasLineDerivWithinAt.hasLineDerivAt (h : HasLineDerivWithinAt 𝕜 f f' s x v) (hs : s ∈ 𝓝 x) : HasLineDerivAt 𝕜 f f' x v := h.hasLineDerivAt' <| (Continuous.tendsto' (by fun_prop) 0 _ (by simp)).eventually hs theorem LineDifferentiableWithinAt.lineDifferentiableAt (h : LineDifferentiableWithinAt 𝕜 f s x v) (hs : s ∈ 𝓝 x) : LineDifferentiableAt 𝕜 f x v := (h.hasLineDerivWithinAt.hasLineDerivAt hs).lineDifferentiableAt lemma HasFDerivWithinAt.hasLineDerivWithinAt (hf : HasFDerivWithinAt f L s x) (v : E) : HasLineDerivWithinAt 𝕜 f (L v) s x v := by let F := fun (t : 𝕜) ↦ x + t • v rw [show x = F (0 : 𝕜) by simp [F]] at hf have A : HasDerivWithinAt F (0 + (1 : 𝕜) • v) (F ⁻¹' s) 0 := ((hasDerivAt_const (0 : 𝕜) x).add ((hasDerivAt_id' (0 : 𝕜)).smul_const v)).hasDerivWithinAt simp only [one_smul, zero_add] at A exact hf.comp_hasDerivWithinAt (x := (0 : 𝕜)) A (mapsTo_preimage F s) lemma HasFDerivAt.hasLineDerivAt (hf : HasFDerivAt f L x) (v : E) : HasLineDerivAt 𝕜 f (L v) x v := by rw [← hasLineDerivWithinAt_univ] exact hf.hasFDerivWithinAt.hasLineDerivWithinAt v lemma DifferentiableAt.lineDeriv_eq_fderiv (hf : DifferentiableAt 𝕜 f x) : lineDeriv 𝕜 f x v = fderiv 𝕜 f x v := (hf.hasFDerivAt.hasLineDerivAt v).lineDeriv theorem LineDifferentiableWithinAt.mono_of_mem_nhdsWithin (h : LineDifferentiableWithinAt 𝕜 f s x v) (hst : s ∈ 𝓝[t] x) : LineDifferentiableWithinAt 𝕜 f t x v := (h.hasLineDerivWithinAt.mono_of_mem_nhdsWithin hst).lineDifferentiableWithinAt @[deprecated (since := "2024-10-31")] alias LineDifferentiableWithinAt.mono_of_mem := LineDifferentiableWithinAt.mono_of_mem_nhdsWithin theorem lineDerivWithin_of_mem_nhds (h : s ∈ 𝓝 x) : lineDerivWithin 𝕜 f s x v = lineDeriv 𝕜 f x v := by apply derivWithin_of_mem_nhds apply (Continuous.continuousAt _).preimage_mem_nhds (by simpa using h) fun_prop theorem lineDerivWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) : lineDerivWithin 𝕜 f s x v = lineDeriv 𝕜 f x v := lineDerivWithin_of_mem_nhds (hs.mem_nhds hx) theorem hasLineDerivWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : HasLineDerivWithinAt 𝕜 f f' s x v ↔ HasLineDerivWithinAt 𝕜 f f' t x v := by apply hasDerivWithinAt_congr_set let F := fun (t : 𝕜) ↦ x + t • v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : s =ᶠ[𝓝 (F 0)] t := by convert h; simp [F] exact B.preimage_mem_nhds this theorem lineDifferentiableWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) : LineDifferentiableWithinAt 𝕜 f s x v ↔ LineDifferentiableWithinAt 𝕜 f t x v := ⟨fun h' ↦ ((hasLineDerivWithinAt_congr_set h).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt, fun h' ↦ ((hasLineDerivWithinAt_congr_set h.symm).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt⟩ theorem lineDerivWithin_congr_set (h : s =ᶠ[𝓝 x] t) : lineDerivWithin 𝕜 f s x v = lineDerivWithin 𝕜 f t x v := by apply derivWithin_congr_set let F := fun (t : 𝕜) ↦ x + t • v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : s =ᶠ[𝓝 (F 0)] t := by convert h; simp [F] exact B.preimage_mem_nhds this theorem Filter.EventuallyEq.hasLineDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) : HasLineDerivAt 𝕜 f₀ f' x v ↔ HasLineDerivAt 𝕜 f₁ f' x v := by apply hasDerivAt_iff let F := fun (t : 𝕜) ↦ x + t • v have B : ContinuousAt F 0 := by apply Continuous.continuousAt; fun_prop have : f₀ =ᶠ[𝓝 (F 0)] f₁ := by convert h; simp [F] exact B.preimage_mem_nhds this theorem Filter.EventuallyEq.lineDifferentiableAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) : LineDifferentiableAt 𝕜 f₀ x v ↔ LineDifferentiableAt 𝕜 f₁ x v := ⟨fun h' ↦ (h.hasLineDerivAt_iff.1 h'.hasLineDerivAt).lineDifferentiableAt, fun h' ↦ (h.hasLineDerivAt_iff.2 h'.hasLineDerivAt).lineDifferentiableAt⟩ theorem Filter.EventuallyEq.hasLineDerivWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : HasLineDerivWithinAt 𝕜 f₀ f' s x v ↔ HasLineDerivWithinAt 𝕜 f₁ f' s x v := by apply hasDerivWithinAt_iff · have A : Continuous (fun (t : 𝕜) ↦ x + t • v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' h (by simp) · simpa using hx theorem Filter.EventuallyEq.hasLineDerivWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : HasLineDerivWithinAt 𝕜 f₀ f' s x v ↔ HasLineDerivWithinAt 𝕜 f₁ f' s x v := h.hasLineDerivWithinAt_iff (h.eq_of_nhdsWithin hx) theorem Filter.EventuallyEq.lineDifferentiableWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : LineDifferentiableWithinAt 𝕜 f₀ s x v ↔ LineDifferentiableWithinAt 𝕜 f₁ s x v := ⟨fun h' ↦ ((h.hasLineDerivWithinAt_iff hx).1 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt, fun h' ↦ ((h.hasLineDerivWithinAt_iff hx).2 h'.hasLineDerivWithinAt).lineDifferentiableWithinAt⟩ theorem Filter.EventuallyEq.lineDifferentiableWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : LineDifferentiableWithinAt 𝕜 f₀ s x v ↔ LineDifferentiableWithinAt 𝕜 f₁ s x v := h.lineDifferentiableWithinAt_iff (h.eq_of_nhdsWithin hx) lemma HasLineDerivWithinAt.congr_of_eventuallyEq (hf : HasLineDerivWithinAt 𝕜 f f' s x v) (h'f : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasLineDerivWithinAt 𝕜 f₁ f' s x v := by apply HasDerivWithinAt.congr_of_eventuallyEq hf _ (by simp [hx]) have A : Continuous (fun (t : 𝕜) ↦ x + t • v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' h'f (by simp) theorem HasLineDerivAt.congr_of_eventuallyEq (h : HasLineDerivAt 𝕜 f f' x v) (h₁ : f₁ =ᶠ[𝓝 x] f) : HasLineDerivAt 𝕜 f₁ f' x v := by apply HasDerivAt.congr_of_eventuallyEq h let F := fun (t : 𝕜) ↦ x + t • v rw [show x = F 0 by simp [F]] at h₁ exact (Continuous.continuousAt (by fun_prop)).preimage_mem_nhds h₁ theorem LineDifferentiableWithinAt.congr_of_eventuallyEq (h : LineDifferentiableWithinAt 𝕜 f s x v) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : LineDifferentiableWithinAt 𝕜 f₁ s x v := (h.hasLineDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt theorem LineDifferentiableAt.congr_of_eventuallyEq (h : LineDifferentiableAt 𝕜 f x v) (hL : f₁ =ᶠ[𝓝 x] f) : LineDifferentiableAt 𝕜 f₁ x v := by apply DifferentiableAt.congr_of_eventuallyEq h let F := fun (t : 𝕜) ↦ x + t • v rw [show x = F 0 by simp [F]] at hL exact (Continuous.continuousAt (by fun_prop)).preimage_mem_nhds hL theorem Filter.EventuallyEq.lineDerivWithin_eq (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := by apply derivWithin_eq ?_ (by simpa using hx) have A : Continuous (fun (t : 𝕜) ↦ x + t • v) := by fun_prop exact A.continuousWithinAt.preimage_mem_nhdsWithin'' hs (by simp) theorem Filter.EventuallyEq.lineDerivWithin_eq_nhds (h : f₁ =ᶠ[𝓝 x] f) : lineDerivWithin 𝕜 f₁ s x v = lineDerivWithin 𝕜 f s x v := (h.filter_mono nhdsWithin_le_nhds).lineDerivWithin_eq h.self_of_nhds theorem Filter.EventuallyEq.lineDeriv_eq (h : f₁ =ᶠ[𝓝 x] f) : lineDeriv 𝕜 f₁ x v = lineDeriv 𝕜 f x v := by rw [← lineDerivWithin_univ, ← lineDerivWithin_univ, h.lineDerivWithin_eq_nhds] /-- Converse to the mean value inequality: if `f` is line differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. This version only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasLineDerivAt.le_of_lip' {f : E → F} {f' : F} {x₀ : E} (hf : HasLineDerivAt 𝕜 f f' x₀ v) {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖f'‖ ≤ C * ‖v‖ := by apply HasDerivAt.le_of_lip' hf (by positivity) have A : Continuous (fun (t : 𝕜) ↦ x₀ + t • v) := by fun_prop have : ∀ᶠ x in 𝓝 (x₀ + (0 : 𝕜) • v), ‖f x - f x₀‖ ≤ C * ‖x - x₀‖ := by simpa using hlip filter_upwards [(A.continuousAt (x := 0)).preimage_mem_nhds this] with t ht simp only [preimage_setOf_eq, add_sub_cancel_left, norm_smul, mem_setOf_eq, mul_comm (‖t‖)] at ht simpa [mul_assoc] using ht /-- Converse to the mean value inequality: if `f` is line differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. This version only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. -/ theorem HasLineDerivAt.le_of_lipschitzOn {f : E → F} {f' : F} {x₀ : E} (hf : HasLineDerivAt 𝕜 f f' x₀ v) {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖f'‖ ≤ C * ‖v‖ := by refine hf.le_of_lip' C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is line differentiable at `x₀` and `C`-lipschitz then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. -/ theorem HasLineDerivAt.le_of_lipschitz {f : E → F} {f' : F} {x₀ : E} (hf : HasLineDerivAt 𝕜 f f' x₀ v) {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖f'‖ ≤ C * ‖v‖ := hf.le_of_lipschitzOn univ_mem (lipschitzOnWith_univ.2 hlip) variable (𝕜) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. This version only assumes that `‖f x - f x₀‖ ≤ C * ‖x - x₀‖` in a neighborhood of `x`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lip' {f : E → F} {x₀ : E} {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ‖f x - f x₀‖ ≤ C * ‖x - x₀‖) : ‖lineDeriv 𝕜 f x₀ v‖ ≤ C * ‖v‖ := by apply norm_deriv_le_of_lip' (by positivity) have A : Continuous (fun (t : 𝕜) ↦ x₀ + t • v) := by fun_prop have : ∀ᶠ x in 𝓝 (x₀ + (0 : 𝕜) • v), ‖f x - f x₀‖ ≤ C * ‖x - x₀‖ := by simpa using hlip filter_upwards [(A.continuousAt (x := 0)).preimage_mem_nhds this] with t ht simp only [preimage_setOf_eq, add_sub_cancel_left, norm_smul, mem_setOf_eq, mul_comm (‖t‖)] at ht simpa [mul_assoc] using ht /-- Converse to the mean value inequality: if `f` is `C`-lipschitz on a neighborhood of `x₀` then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lipschitzOn {f : E → F} {x₀ : E} {s : Set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : LipschitzOnWith C f s) : ‖lineDeriv 𝕜 f x₀ v‖ ≤ C * ‖v‖ := by refine norm_lineDeriv_le_of_lip' 𝕜 C.coe_nonneg ?_ filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs) /-- Converse to the mean value inequality: if `f` is `C`-lipschitz then its line derivative at `x₀` in the direction `v` has norm bounded by `C * ‖v‖`. Version using `lineDeriv`. -/ theorem norm_lineDeriv_le_of_lipschitz {f : E → F} {x₀ : E} {C : ℝ≥0} (hlip : LipschitzWith C f) : ‖lineDeriv 𝕜 f x₀ v‖ ≤ C * ‖v‖ := norm_lineDeriv_le_of_lipschitzOn 𝕜 univ_mem (lipschitzOnWith_univ.2 hlip) variable {𝕜}
end NormedSpace
Mathlib/Analysis/Calculus/LineDeriv/Basic.lean
457
458
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Algebra.Order.Group.Nat import Mathlib.Topology.UniformSpace.Basic /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity variable {α : Type u} {β : Type v} [uniformSpace : UniformSpace α] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy sequences, because if `a : ℕ → α` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter α) := NeBot f ∧ f ×ˢ f ≤ 𝓤 α /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set α) := ∀ f, Cauchy f → f ≤ 𝓟 s → ∃ x ∈ s, f ≤ 𝓝 x theorem Filter.HasBasis.cauchy_iff {ι} {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ i, p i → ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] theorem cauchy_iff' {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, (x, y) ∈ s := (𝓤 α).basis_sets.cauchy_iff theorem cauchy_iff {f : Filter α} : Cauchy f ↔ NeBot f ∧ ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] lemma cauchy_iff_le {l : Filter α} [hl : l.NeBot] : Cauchy l ↔ l ×ˢ l ≤ 𝓤 α := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter α} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter α) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ theorem cauchy_map_iff {l : Filter β} {f : β → α} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] theorem cauchy_map_iff' {l : Filter β} [hl : NeBot l] {f : β → α} : Cauchy (l.map f) ↔ Tendsto (fun p : β × β => (f p.1, f p.2)) (l ×ˢ l) (𝓤 α) := cauchy_map_iff.trans <| and_iff_right hl theorem Cauchy.mono {f g : Filter α} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≤ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ theorem Cauchy.mono' {f g : Filter α} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≤ f) : Cauchy g := h_c.mono h_le theorem cauchy_nhds {a : α} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ theorem cauchy_pure {a : α} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) theorem Filter.Tendsto.cauchy_map {l : Filter β} [NeBot l] {f : β → α} {a : α} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h lemma Cauchy.mono_uniformSpace {u v : UniformSpace β} {F : Filter β} (huv : u ≤ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace β} {F : Filter β} : Cauchy (uniformSpace := u ⊓ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ι : Sort*} [Nonempty ι] {u : ι → UniformSpace β} {l : Filter β} : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ι : Sort*} {u : ι → UniformSpace β} {l : Filter β} [l.NeBot] : Cauchy (uniformSpace := ⨅ i, u i) l ↔ ∀ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace β} {α} {f : α → β} {l : Filter α} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace β] {F : Filter (α × β)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace β] {f : Filter α} {g : Filter β} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f ×ˢ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter α} {x : α} (adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, t ×ˢ t ⊆ s ∧ ∃ y, (x, y) ∈ s ∧ y ∈ t) : f ≤ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s` exact fun z hz => hU (prodMk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter α} {x : α} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≤ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : ∃ t ∈ f, t ×ˢ t ⊆ s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) theorem le_nhds_iff_adhp_of_cauchy {f : Filter α} {x : α} (hf : Cauchy f) : f ≤ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ nonrec theorem Cauchy.map [UniformSpace β] {f : Filter α} {m : α → β} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f ×ˢ map m f = map (Prod.map m m) (f ×ˢ f) := Filter.prod_map_map_eq _ ≤ Filter.map (Prod.map m m) (𝓤 α) := map_mono hf.right _ ≤ 𝓤 β := hm⟩ nonrec theorem Cauchy.comap [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) [NeBot (comap m f)] : Cauchy (comap m f) := ⟨‹_›, calc comap m f ×ˢ comap m f = comap (Prod.map m m) (f ×ˢ f) := prod_comap_comap_eq _ ≤ comap (Prod.map m m) (𝓤 β) := comap_mono hf.right _ ≤ 𝓤 α := hm⟩ theorem Cauchy.comap' [UniformSpace β] {f : Filter β} {m : α → β} (hf : Cauchy f) (hm : Filter.comap (fun p : α × α => (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm /-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder β] (u : β → α) := Cauchy (atTop.map u) theorem CauchySeq.tendsto_uniformity [Preorder β] {u : β → α} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓤 α) := by simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right theorem CauchySeq.nonempty [Preorder β] {u : β → α} (hu : CauchySeq u) : Nonempty β := @nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1 theorem CauchySeq.mem_entourage {β : Type*} [SemilatticeSup β] {u : β → α} (h : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∃ k₀, ∀ i j, k₀ ≤ i → k₀ ≤ j → (u i, u j) ∈ V := by haveI := h.nonempty have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV theorem Filter.Tendsto.cauchySeq [SemilatticeSup β] [Nonempty β] {f : β → α} {x} (hx : Tendsto f atTop (𝓝 x)) : CauchySeq f := hx.cauchy_map theorem cauchySeq_const [SemilatticeSup β] [Nonempty β] (x : α) : CauchySeq fun _ : β => x := tendsto_const_nhds.cauchySeq theorem cauchySeq_iff_tendsto [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓤 α) := cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def] theorem CauchySeq.comp_tendsto {γ} [Preorder β] [SemilatticeSup γ] [Nonempty γ] {f : β → α} (hf : CauchySeq f) {g : γ → β} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) := ⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩ theorem CauchySeq.comp_injective [SemilatticeSup β] [NoMaxOrder β] [Nonempty β] {u : ℕ → α} (hu : CauchySeq u) {f : β → ℕ} (hf : Injective f) : CauchySeq (u ∘ f) := hu.comp_tendsto <| Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite.mono_left atTop_le_cofinite theorem Function.Bijective.cauchySeq_comp_iff {f : ℕ → ℕ} (hf : Bijective f) (u : ℕ → α) : CauchySeq (u ∘ f) ↔ CauchySeq u := by refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩ lift f to ℕ ≃ ℕ using hf simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective theorem CauchySeq.subseq_subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) {f g : ℕ → ℕ} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, ((u ∘ f ∘ φ) n, (u ∘ g ∘ φ) n) ∈ V n := by rw [cauchySeq_iff_tendsto] at hu exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV -- todo: generalize this and other lemmas to a nonempty semilattice theorem cauchySeq_iff' {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∀ᶠ k in atTop, k ∈ Prod.map u u ⁻¹' V := cauchySeq_iff_tendsto theorem cauchySeq_iff {u : ℕ → α} : CauchySeq u ↔ ∀ V ∈ 𝓤 α, ∃ N, ∀ k ≥ N, ∀ l ≥ N, (u k, u l) ∈ V := by simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply] theorem CauchySeq.prodMap {γ δ} [UniformSpace β] [Preorder γ] [Preorder δ] {u : γ → α} {v : δ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv @[deprecated (since := "2025-03-10")] alias CauchySeq.prod_map := CauchySeq.prodMap theorem CauchySeq.prodMk {γ} [UniformSpace β] [Preorder γ] {u : γ → α} {v : γ → β} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) := haveI := hu.1.of_map (Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map) @[deprecated (since := "2025-03-10")] alias CauchySeq.prod := CauchySeq.prodMk theorem CauchySeq.eventually_eventually [Preorder β] {u : β → α} (hu : CauchySeq u) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : ∀ᶠ k in atTop, ∀ᶠ l in atTop, (u k, u l) ∈ V := eventually_atTop_curry <| hu.tendsto_uniformity hV theorem UniformContinuous.comp_cauchySeq {γ} [UniformSpace β] [Preorder γ] {f : α → β} (hf : UniformContinuous f) {u : γ → α} (hu : CauchySeq u) : CauchySeq (f ∘ u) := hu.map hf theorem CauchySeq.subseq_mem {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} (hu : CauchySeq u) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V n := by have : ∀ n, ∃ N, ∀ k ≥ N, ∀ l ≥ k, (u l, u k) ∈ V n := fun n => by rw [cauchySeq_iff] at hu rcases hu _ (hV n) with ⟨N, H⟩ exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩ obtain ⟨φ : ℕ → ℕ, φ_extr : StrictMono φ, hφ : ∀ n, ∀ l ≥ φ n, (u l, u <| φ n) ∈ V n⟩ := extraction_forall_of_eventually' this exact ⟨φ, φ_extr, fun n => hφ _ _ (φ_extr <| Nat.lt_add_one n).le⟩ theorem Filter.Tendsto.subseq_mem_entourage {V : ℕ → Set (α × α)} (hV : ∀ n, V n ∈ 𝓤 α) {u : ℕ → α} {a : α} (hu : Tendsto u atTop (𝓝 a)) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ (u (φ 0), a) ∈ V 0 ∧ ∀ n, (u <| φ (n + 1), u <| φ n) ∈ V (n + 1) := by rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩ rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with ⟨φ, φ_mono, hφV⟩ exact ⟨fun k => φ k + n, φ_mono.add_const _, hn _ le_add_self, hφV⟩ /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder β] {u : β → α} (hu : CauchySeq u) {ι : Type*} {f : ι → β} {p : Filter ι} [NeBot p] (hf : Tendsto f p atTop) {a : α} (ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) := le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf) /-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/ theorem cauchySeq_shift {u : ℕ → α} (k : ℕ) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by constructor <;> intro h · rw [cauchySeq_iff] at h ⊢ intro V mV obtain ⟨N, h⟩ := h V mV use N + k intro a ha b hb convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega · exact h.comp_tendsto (tendsto_add_atTop_nat k) theorem Filter.HasBasis.cauchySeq_iff {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α × α)} (h : (𝓤 α).HasBasis p s) :
CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → (u m, u n) ∈ s i := by rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq] refine (atTop_basis.prod_self.tendsto_iff h).trans ?_ simp only [exists_prop, true_and, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq, mem_setOf_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≤ _) β] theorem Filter.HasBasis.cauchySeq_iff' {γ} [Nonempty β] [SemilatticeSup β] {u : β → α} {p : γ → Prop} {s : γ → Set (α × α)} (H : (𝓤 α).HasBasis p s) : CauchySeq u ↔ ∀ i, p i → ∃ N, ∀ n ≥ N, (u n, u N) ∈ s i := by
Mathlib/Topology/UniformSpace/Cauchy.lean
288
296
/- 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.Topology.MetricSpace.HausdorffDistance /-! # Thickenings in pseudo-metric spaces ## Main definitions * `Metric.thickening δ s`, the open thickening by radius `δ` of a set `s` in a pseudo emetric space. * `Metric.cthickening δ s`, the closed thickening by radius `δ` of a set `s` in a pseudo emetric space. ## Main results * `Disjoint.exists_thickenings`: two disjoint sets admit disjoint thickenings * `Disjoint.exists_cthickenings`: two disjoint sets admit disjoint closed thickenings * `IsCompact.exists_cthickening_subset_open`: if `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. * `Metric.hasBasis_nhdsSet_cthickening`: the `cthickening`s of a compact set `K` form a basis of the neighbourhoods of `K` * `Metric.closure_eq_iInter_cthickening'`: the closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. The same holds for open thickenings. * `IsCompact.cthickening_eq_biUnion_closedBall`: if `s` is compact, `cthickening δ s` is the union of `closedBall`s of radius `δ` around `x : E`. -/ noncomputable section open NNReal ENNReal Topology Set Filter Bornology universe u v w variable {ι : Sort*} {α : Type u} namespace Metric section Thickening variable [PseudoEMetricSpace α] {δ : ℝ} {s : Set α} {x : α} open EMetric /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at distance less than `δ` from some point of `E`. -/ def thickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E < ENNReal.ofReal δ } theorem mem_thickening_iff_infEdist_lt : x ∈ thickening δ s ↔ infEdist x s < ENNReal.ofReal δ := Iff.rfl /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the (open) `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_thickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.thickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [thickening, mem_setOf_eq, not_lt] exact (ENNReal.ofReal_le_ofReal hδ.le).trans ε_lt.le /-- The (open) thickening equals the preimage of an open interval under `EMetric.infEdist`. -/ theorem thickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : thickening δ E = (infEdist · E) ⁻¹' Iio (ENNReal.ofReal δ) := rfl /-- The (open) thickening is an open set. -/ theorem isOpen_thickening {δ : ℝ} {E : Set α} : IsOpen (thickening δ E) := Continuous.isOpen_preimage continuous_infEdist _ isOpen_Iio /-- The (open) thickening of the empty set is empty. -/ @[simp] theorem thickening_empty (δ : ℝ) : thickening δ (∅ : Set α) = ∅ := by simp only [thickening, setOf_false, infEdist_empty, not_top_lt] theorem thickening_of_nonpos (hδ : δ ≤ 0) (s : Set α) : thickening δ s = ∅ := eq_empty_of_forall_not_mem fun _ => ((ENNReal.ofReal_of_nonpos hδ).trans_le bot_le).not_lt /-- The (open) thickening `Metric.thickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ @[gcongr] theorem thickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ thickening δ₂ E := preimage_mono (Iio_subset_Iio (ENNReal.ofReal_le_ofReal hle)) /-- The (open) thickening `Metric.thickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem thickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : thickening δ E₁ ⊆ thickening δ E₂ := fun _ hx => lt_of_le_of_lt (infEdist_anti h) hx theorem mem_thickening_iff_exists_edist_lt {δ : ℝ} (E : Set α) (x : α) : x ∈ thickening δ E ↔ ∃ z ∈ E, edist x z < ENNReal.ofReal δ := infEdist_lt_iff /-- The frontier of the (open) thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_thickening_subset (E : Set α) {δ : ℝ} : frontier (thickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_lt_subset_eq continuous_infEdist continuous_const open scoped Function in -- required for scoped `on` notation theorem frontier_thickening_disjoint (A : Set α) : Pairwise (Disjoint on fun r : ℝ => frontier (thickening r A)) := by refine (pairwise_disjoint_on _).2 fun r₁ r₂ hr => ?_ rcases le_total r₁ 0 with h₁ | h₁ · simp [thickening_of_nonpos h₁] refine ((disjoint_singleton.2 fun h => hr.ne ?_).preimage _).mono (frontier_thickening_subset _) (frontier_thickening_subset _) apply_fun ENNReal.toReal at h rwa [ENNReal.toReal_ofReal h₁, ENNReal.toReal_ofReal (h₁.trans hr.le)] at h /-- Any set is contained in the complement of the δ-thickening of the complement of its δ-thickening. -/ lemma subset_compl_thickening_compl_thickening_self (δ : ℝ) (E : Set α) : E ⊆ (thickening δ (thickening δ E)ᶜ)ᶜ := by intro x x_in_E simp only [thickening, mem_compl_iff, mem_setOf_eq, not_lt] apply EMetric.le_infEdist.mpr fun y hy ↦ ?_ simp only [mem_compl_iff, mem_setOf_eq, not_lt] at hy simpa only [edist_comm] using le_trans hy <| EMetric.infEdist_le_edist_of_mem x_in_E /-- The δ-thickening of the complement of the δ-thickening of a set is contained in the complement of the set. -/ lemma thickening_compl_thickening_self_subset_compl (δ : ℝ) (E : Set α) : thickening δ (thickening δ E)ᶜ ⊆ Eᶜ := by apply compl_subset_compl.mp simpa only [compl_compl] using subset_compl_thickening_compl_thickening_self δ E variable {X : Type u} [PseudoMetricSpace X] theorem mem_thickening_iff_infDist_lt {E : Set X} {x : X} (h : E.Nonempty) : x ∈ thickening δ E ↔ infDist x E < δ := lt_ofReal_iff_toReal_lt (infEdist_ne_top h) /-- A point in a metric space belongs to the (open) `δ`-thickening of a subset `E` if and only if it is at distance less than `δ` from some point of `E`. -/ theorem mem_thickening_iff {E : Set X} {x : X} : x ∈ thickening δ E ↔ ∃ z ∈ E, dist x z < δ := by have key_iff : ∀ z : X, edist x z < ENNReal.ofReal δ ↔ dist x z < δ := fun z ↦ by rw [dist_edist, lt_ofReal_iff_toReal_lt (edist_ne_top _ _)] simp_rw [mem_thickening_iff_exists_edist_lt, key_iff] @[simp] theorem thickening_singleton (δ : ℝ) (x : X) : thickening δ ({x} : Set X) = ball x δ := by ext simp [mem_thickening_iff] theorem ball_subset_thickening {x : X} {E : Set X} (hx : x ∈ E) (δ : ℝ) : ball x δ ⊆ thickening δ E := Subset.trans (by simp [Subset.rfl]) (thickening_subset_of_subset δ <| singleton_subset_iff.mpr hx) /-- The (open) `δ`-thickening `Metric.thickening δ E` of a subset `E` in a metric space equals the union of balls of radius `δ` centered at points of `E`. -/ theorem thickening_eq_biUnion_ball {δ : ℝ} {E : Set X} : thickening δ E = ⋃ x ∈ E, ball x δ := by ext x simp only [mem_iUnion₂, exists_prop] exact mem_thickening_iff protected theorem _root_.Bornology.IsBounded.thickening {δ : ℝ} {E : Set X} (h : IsBounded E) : IsBounded (thickening δ E) := by rcases E.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · simp · refine (isBounded_iff_subset_closedBall x).2 ⟨δ + diam E, fun y hy ↦ ?_⟩ calc dist y x ≤ infDist y E + diam E := dist_le_infDist_add_diam (x := y) h hx _ ≤ δ + diam E := add_le_add_right ((mem_thickening_iff_infDist_lt ⟨x, hx⟩).1 hy).le _ end Thickening section Cthickening variable [PseudoEMetricSpace α] {δ ε : ℝ} {s t : Set α} {x : α} open EMetric /-- The closed `δ`-thickening `Metric.cthickening δ E` of a subset `E` in a pseudo emetric space consists of those points that are at infimum distance at most `δ` from `E`. -/ def cthickening (δ : ℝ) (E : Set α) : Set α := { x : α | infEdist x E ≤ ENNReal.ofReal δ } @[simp] theorem mem_cthickening_iff : x ∈ cthickening δ s ↔ infEdist x s ≤ ENNReal.ofReal δ := Iff.rfl /-- An exterior point of a subset `E` (i.e., a point outside the closure of `E`) is not in the closed `δ`-thickening of `E` for small enough positive `δ`. -/ lemma eventually_not_mem_cthickening_of_infEdist_pos {E : Set α} {x : α} (h : x ∉ closure E) : ∀ᶠ δ in 𝓝 (0 : ℝ), x ∉ Metric.cthickening δ E := by obtain ⟨ε, ⟨ε_pos, ε_lt⟩⟩ := exists_real_pos_lt_infEdist_of_not_mem_closure h filter_upwards [eventually_lt_nhds ε_pos] with δ hδ simp only [cthickening, mem_setOf_eq, not_le] exact ((ofReal_lt_ofReal_iff ε_pos).mpr hδ).trans ε_lt theorem mem_cthickening_of_edist_le (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : edist x y ≤ ENNReal.ofReal δ) : x ∈ cthickening δ E := (infEdist_le_edist_of_mem h).trans h' theorem mem_cthickening_of_dist_le {α : Type*} [PseudoMetricSpace α] (x y : α) (δ : ℝ) (E : Set α) (h : y ∈ E) (h' : dist x y ≤ δ) : x ∈ cthickening δ E := by apply mem_cthickening_of_edist_le x y δ E h rw [edist_dist] exact ENNReal.ofReal_le_ofReal h' theorem cthickening_eq_preimage_infEdist (δ : ℝ) (E : Set α) : cthickening δ E = (fun x => infEdist x E) ⁻¹' Iic (ENNReal.ofReal δ) := rfl /-- The closed thickening is a closed set. -/ theorem isClosed_cthickening {δ : ℝ} {E : Set α} : IsClosed (cthickening δ E) := IsClosed.preimage continuous_infEdist isClosed_Iic /-- The closed thickening of the empty set is empty. -/ @[simp] theorem cthickening_empty (δ : ℝ) : cthickening δ (∅ : Set α) = ∅ := by simp only [cthickening, ENNReal.ofReal_ne_top, setOf_false, infEdist_empty, top_le_iff] theorem cthickening_of_nonpos {δ : ℝ} (hδ : δ ≤ 0) (E : Set α) : cthickening δ E = closure E := by ext x simp [mem_closure_iff_infEdist_zero, cthickening, ENNReal.ofReal_eq_zero.2 hδ] /-- The closed thickening with radius zero is the closure of the set. -/ @[simp] theorem cthickening_zero (E : Set α) : cthickening 0 E = closure E := cthickening_of_nonpos le_rfl E theorem cthickening_max_zero (δ : ℝ) (E : Set α) : cthickening (max 0 δ) E = cthickening δ E := by cases le_total δ 0 <;> simp [cthickening_of_nonpos, *] /-- The closed thickening `Metric.cthickening δ E` of a fixed subset `E` is an increasing function of the thickening radius `δ`. -/ theorem cthickening_mono {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : cthickening δ₁ E ⊆ cthickening δ₂ E := preimage_mono (Iic_subset_Iic.mpr (ENNReal.ofReal_le_ofReal hle)) @[simp] theorem cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) {δ : ℝ} (hδ : 0 ≤ δ) : cthickening δ ({x} : Set α) = closedBall x δ := by ext y simp [cthickening, edist_dist, ENNReal.ofReal_le_ofReal_iff hδ] theorem closedBall_subset_cthickening_singleton {α : Type*} [PseudoMetricSpace α] (x : α) (δ : ℝ) : closedBall x δ ⊆ cthickening δ ({x} : Set α) := by rcases lt_or_le δ 0 with (hδ | hδ) · simp only [closedBall_eq_empty.mpr hδ, empty_subset] · simp only [cthickening_singleton x hδ, Subset.rfl] /-- The closed thickening `Metric.cthickening δ E` with a fixed thickening radius `δ` is an increasing function of the subset `E`. -/ theorem cthickening_subset_of_subset (δ : ℝ) {E₁ E₂ : Set α} (h : E₁ ⊆ E₂) : cthickening δ E₁ ⊆ cthickening δ E₂ := fun _ hx => le_trans (infEdist_anti h) hx theorem cthickening_subset_thickening {δ₁ : ℝ≥0} {δ₂ : ℝ} (hlt : (δ₁ : ℝ) < δ₂) (E : Set α) : cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx => hx.out.trans_lt ((ENNReal.ofReal_lt_ofReal_iff (lt_of_le_of_lt δ₁.prop hlt)).mpr hlt) /-- The closed thickening `Metric.cthickening δ₁ E` is contained in the open thickening `Metric.thickening δ₂ E` if the radius of the latter is positive and larger. -/ theorem cthickening_subset_thickening' {δ₁ δ₂ : ℝ} (δ₂_pos : 0 < δ₂) (hlt : δ₁ < δ₂) (E : Set α) : cthickening δ₁ E ⊆ thickening δ₂ E := fun _ hx => lt_of_le_of_lt hx.out ((ENNReal.ofReal_lt_ofReal_iff δ₂_pos).mpr hlt) /-- The open thickening `Metric.thickening δ E` is contained in the closed thickening `Metric.cthickening δ E` with the same radius. -/ theorem thickening_subset_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ cthickening δ E := by intro x hx rw [thickening, mem_setOf_eq] at hx exact hx.le theorem thickening_subset_cthickening_of_le {δ₁ δ₂ : ℝ} (hle : δ₁ ≤ δ₂) (E : Set α) : thickening δ₁ E ⊆ cthickening δ₂ E := (thickening_subset_cthickening δ₁ E).trans (cthickening_mono hle E) theorem _root_.Bornology.IsBounded.cthickening {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α} (h : IsBounded E) : IsBounded (cthickening δ E) := by have : IsBounded (thickening (max (δ + 1) 1) E) := h.thickening apply this.subset exact cthickening_subset_thickening' (zero_lt_one.trans_le (le_max_right _ _)) ((lt_add_one _).trans_le (le_max_left _ _)) _ protected theorem _root_.IsCompact.cthickening {α : Type*} [PseudoMetricSpace α] [ProperSpace α] {s : Set α} (hs : IsCompact s) {r : ℝ} : IsCompact (cthickening r s) := isCompact_of_isClosed_isBounded isClosed_cthickening hs.isBounded.cthickening theorem thickening_subset_interior_cthickening (δ : ℝ) (E : Set α) : thickening δ E ⊆ interior (cthickening δ E) := (subset_interior_iff_isOpen.mpr isOpen_thickening).trans (interior_mono (thickening_subset_cthickening δ E)) theorem closure_thickening_subset_cthickening (δ : ℝ) (E : Set α) : closure (thickening δ E) ⊆ cthickening δ E := (closure_mono (thickening_subset_cthickening δ E)).trans isClosed_cthickening.closure_subset /-- The closed thickening of a set contains the closure of the set. -/ theorem closure_subset_cthickening (δ : ℝ) (E : Set α) : closure E ⊆ cthickening δ E := by rw [← cthickening_of_nonpos (min_le_right δ 0)] exact cthickening_mono (min_le_left δ 0) E /-- The (open) thickening of a set contains the closure of the set. -/ theorem closure_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : closure E ⊆ thickening δ E := by rw [← cthickening_zero] exact cthickening_subset_thickening' δ_pos δ_pos E /-- A set is contained in its own (open) thickening. -/ theorem self_subset_thickening {δ : ℝ} (δ_pos : 0 < δ) (E : Set α) : E ⊆ thickening δ E := (@subset_closure _ _ E).trans (closure_subset_thickening δ_pos E) /-- A set is contained in its own closed thickening. -/ theorem self_subset_cthickening {δ : ℝ} (E : Set α) : E ⊆ cthickening δ E := subset_closure.trans (closure_subset_cthickening δ E) theorem thickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : thickening δ E ∈ 𝓝ˢ E := isOpen_thickening.mem_nhdsSet.2 <| self_subset_thickening hδ E theorem cthickening_mem_nhdsSet (E : Set α) {δ : ℝ} (hδ : 0 < δ) : cthickening δ E ∈ 𝓝ˢ E := mem_of_superset (thickening_mem_nhdsSet E hδ) (thickening_subset_cthickening _ _) @[simp] theorem thickening_union (δ : ℝ) (s t : Set α) : thickening δ (s ∪ t) = thickening δ s ∪ thickening δ t := by simp_rw [thickening, infEdist_union, min_lt_iff, setOf_or] @[simp] theorem cthickening_union (δ : ℝ) (s t : Set α) : cthickening δ (s ∪ t) = cthickening δ s ∪ cthickening δ t := by simp_rw [cthickening, infEdist_union, min_le_iff, setOf_or] @[simp] theorem thickening_iUnion (δ : ℝ) (f : ι → Set α) : thickening δ (⋃ i, f i) = ⋃ i, thickening δ (f i) := by simp_rw [thickening, infEdist_iUnion, iInf_lt_iff, setOf_exists] lemma thickening_biUnion {ι : Type*} (δ : ℝ) (f : ι → Set α) (I : Set ι) : thickening δ (⋃ i ∈ I, f i) = ⋃ i ∈ I, thickening δ (f i) := by simp only [thickening_iUnion] theorem ediam_cthickening_le (ε : ℝ≥0) : EMetric.diam (cthickening ε s) ≤ EMetric.diam s + 2 * ε := by refine diam_le fun x hx y hy => ENNReal.le_of_forall_pos_le_add fun δ hδ _ => ?_ rw [mem_cthickening_iff, ENNReal.ofReal_coe_nnreal] at hx hy have hε : (ε : ℝ≥0∞) < ε + δ := ENNReal.coe_lt_coe.2 (lt_add_of_pos_right _ hδ) replace hx := hx.trans_lt hε obtain ⟨x', hx', hxx'⟩ := infEdist_lt_iff.mp hx calc edist x y ≤ edist x x' + edist y x' := edist_triangle_right _ _ _ _ ≤ ε + δ + (infEdist y s + EMetric.diam s) := add_le_add hxx'.le (edist_le_infEdist_add_ediam hx') _ ≤ ε + δ + (ε + EMetric.diam s) := add_le_add_left (add_le_add_right hy _) _ _ = _ := by rw [two_mul]; ac_rfl theorem ediam_thickening_le (ε : ℝ≥0) : EMetric.diam (thickening ε s) ≤ EMetric.diam s + 2 * ε := (EMetric.diam_mono <| thickening_subset_cthickening _ _).trans <| ediam_cthickening_le _ theorem diam_cthickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) : diam (cthickening ε s) ≤ diam s + 2 * ε := by lift ε to ℝ≥0 using hε refine (toReal_le_add' (ediam_cthickening_le _) ?_ ?_).trans_eq ?_ · exact fun h ↦ top_unique <| h ▸ EMetric.diam_mono (self_subset_cthickening _) · simp [mul_eq_top] · simp [diam] theorem diam_thickening_le {α : Type*} [PseudoMetricSpace α] (s : Set α) (hε : 0 ≤ ε) : diam (thickening ε s) ≤ diam s + 2 * ε := by by_cases hs : IsBounded s · exact (diam_mono (thickening_subset_cthickening _ _) hs.cthickening).trans (diam_cthickening_le _ hε) obtain rfl | hε := hε.eq_or_lt · simp [thickening_of_nonpos, diam_nonneg] · rw [diam_eq_zero_of_unbounded (mt (IsBounded.subset · <| self_subset_thickening hε _) hs)] positivity @[simp] theorem thickening_closure : thickening δ (closure s) = thickening δ s := by simp_rw [thickening, infEdist_closure] @[simp] theorem cthickening_closure : cthickening δ (closure s) = cthickening δ s := by simp_rw [cthickening, infEdist_closure] open ENNReal theorem _root_.Disjoint.exists_thickenings (hst : Disjoint s t) (hs : IsCompact s) (ht : IsClosed t) : ∃ δ, 0 < δ ∧ Disjoint (thickening δ s) (thickening δ t) := by obtain ⟨r, hr, h⟩ := exists_pos_forall_lt_edist hs ht hst refine ⟨r / 2, half_pos (NNReal.coe_pos.2 hr), ?_⟩ rw [disjoint_iff_inf_le] rintro z ⟨hzs, hzt⟩ rw [mem_thickening_iff_exists_edist_lt] at hzs hzt rw [← NNReal.coe_two, ← NNReal.coe_div, ENNReal.ofReal_coe_nnreal] at hzs hzt obtain ⟨x, hx, hzx⟩ := hzs obtain ⟨y, hy, hzy⟩ := hzt refine (h x hx y hy).not_le ?_ calc edist x y ≤ edist z x + edist z y := edist_triangle_left _ _ _ _ ≤ ↑(r / 2) + ↑(r / 2) := add_le_add hzx.le hzy.le _ = r := by rw [← ENNReal.coe_add, add_halves] theorem _root_.Disjoint.exists_cthickenings (hst : Disjoint s t) (hs : IsCompact s) (ht : IsClosed t) : ∃ δ, 0 < δ ∧ Disjoint (cthickening δ s) (cthickening δ t) := by obtain ⟨δ, hδ, h⟩ := hst.exists_thickenings hs ht refine ⟨δ / 2, half_pos hδ, h.mono ?_ ?_⟩ <;> exact cthickening_subset_thickening' hδ (half_lt_self hδ) _ /-- If `s` is compact, `t` is open and `s ⊆ t`, some `cthickening` of `s` is contained in `t`. -/ theorem _root_.IsCompact.exists_cthickening_subset_open (hs : IsCompact s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ δ, 0 < δ ∧ cthickening δ s ⊆ t := (hst.disjoint_compl_right.exists_cthickenings hs ht.isClosed_compl).imp fun _ h => ⟨h.1, disjoint_compl_right_iff_subset.1 <| h.2.mono_right <| self_subset_cthickening _⟩ theorem _root_.IsCompact.exists_isCompact_cthickening [LocallyCompactSpace α] (hs : IsCompact s) : ∃ δ, 0 < δ ∧ IsCompact (cthickening δ s) := by rcases exists_compact_superset hs with ⟨K, K_compact, hK⟩ rcases hs.exists_cthickening_subset_open isOpen_interior hK with ⟨δ, δpos, hδ⟩ refine ⟨δ, δpos, ?_⟩ exact K_compact.of_isClosed_subset isClosed_cthickening (hδ.trans interior_subset) theorem _root_.IsCompact.exists_thickening_subset_open (hs : IsCompact s) (ht : IsOpen t) (hst : s ⊆ t) : ∃ δ, 0 < δ ∧ thickening δ s ⊆ t := let ⟨δ, h₀, hδ⟩ := hs.exists_cthickening_subset_open ht hst ⟨δ, h₀, (thickening_subset_cthickening _ _).trans hδ⟩ theorem hasBasis_nhdsSet_thickening {K : Set α} (hK : IsCompact K) : (𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => thickening δ K := (hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_thickening_subset_open hU.1 hU.2) fun _ => thickening_mem_nhdsSet K theorem hasBasis_nhdsSet_cthickening {K : Set α} (hK : IsCompact K) : (𝓝ˢ K).HasBasis (fun δ : ℝ => 0 < δ) fun δ => cthickening δ K := (hasBasis_nhdsSet K).to_hasBasis' (fun _U hU => hK.exists_cthickening_subset_open hU.1 hU.2) fun _ => cthickening_mem_nhdsSet K theorem cthickening_eq_iInter_cthickening' {δ : ℝ} (s : Set ℝ) (hsδ : s ⊆ Ioi δ) (hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) : cthickening δ E = ⋂ ε ∈ s, cthickening ε E := by apply Subset.antisymm · exact subset_iInter₂ fun _ hε => cthickening_mono (le_of_lt (hsδ hε)) E · unfold cthickening intro x hx simp only [mem_iInter, mem_setOf_eq] at * apply ENNReal.le_of_forall_pos_le_add intro η η_pos _ rcases hs (δ + η) (lt_add_of_pos_right _ (NNReal.coe_pos.mpr η_pos)) with ⟨ε, ⟨hsε, hε⟩⟩ apply ((hx ε hsε).trans (ENNReal.ofReal_le_ofReal hε.2)).trans rw [ENNReal.coe_nnreal_eq η] exact ENNReal.ofReal_add_le theorem cthickening_eq_iInter_cthickening {δ : ℝ} (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), cthickening ε E := by apply cthickening_eq_iInter_cthickening' (Ioi δ) rfl.subset simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self] exact fun _ hε => nonempty_Ioc.mpr hε theorem cthickening_eq_iInter_thickening' {δ : ℝ} (δ_nn : 0 ≤ δ) (s : Set ℝ) (hsδ : s ⊆ Ioi δ) (hs : ∀ ε, δ < ε → (s ∩ Ioc δ ε).Nonempty) (E : Set α) : cthickening δ E = ⋂ ε ∈ s, thickening ε E := by refine (subset_iInter₂ fun ε hε => ?_).antisymm ?_ · obtain ⟨ε', -, hε'⟩ := hs ε (hsδ hε) have ss := cthickening_subset_thickening' (lt_of_le_of_lt δ_nn hε'.1) hε'.1 E exact ss.trans (thickening_mono hε'.2 E) · rw [cthickening_eq_iInter_cthickening' s hsδ hs E] exact iInter₂_mono fun ε _ => thickening_subset_cthickening ε E theorem cthickening_eq_iInter_thickening {δ : ℝ} (δ_nn : 0 ≤ δ) (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : δ < ε), thickening ε E := by apply cthickening_eq_iInter_thickening' δ_nn (Ioi δ) rfl.subset simp_rw [inter_eq_right.mpr Ioc_subset_Ioi_self] exact fun _ hε => nonempty_Ioc.mpr hε theorem cthickening_eq_iInter_thickening'' (δ : ℝ) (E : Set α) : cthickening δ E = ⋂ (ε : ℝ) (_ : max 0 δ < ε), thickening ε E := by rw [← cthickening_max_zero, cthickening_eq_iInter_thickening] exact le_max_left _ _ /-- The closure of a set equals the intersection of its closed thickenings of positive radii accumulating at zero. -/ theorem closure_eq_iInter_cthickening' (E : Set α) (s : Set ℝ) (hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, cthickening δ E := by by_cases hs₀ : s ⊆ Ioi 0 · rw [← cthickening_zero] apply cthickening_eq_iInter_cthickening' _ hs₀ hs obtain ⟨δ, hδs, δ_nonpos⟩ := not_subset.mp hs₀ rw [Set.mem_Ioi, not_lt] at δ_nonpos apply Subset.antisymm · exact subset_iInter₂ fun ε _ => closure_subset_cthickening ε E · rw [← cthickening_of_nonpos δ_nonpos E] exact biInter_subset_of_mem hδs /-- The closure of a set equals the intersection of its closed thickenings of positive radii. -/ theorem closure_eq_iInter_cthickening (E : Set α) : closure E = ⋂ (δ : ℝ) (_ : 0 < δ), cthickening δ E := by rw [← cthickening_zero] exact cthickening_eq_iInter_cthickening E /-- The closure of a set equals the intersection of its open thickenings of positive radii accumulating at zero. -/ theorem closure_eq_iInter_thickening' (E : Set α) (s : Set ℝ) (hs₀ : s ⊆ Ioi 0) (hs : ∀ ε, 0 < ε → (s ∩ Ioc 0 ε).Nonempty) : closure E = ⋂ δ ∈ s, thickening δ E := by rw [← cthickening_zero] apply cthickening_eq_iInter_thickening' le_rfl _ hs₀ hs /-- The closure of a set equals the intersection of its (open) thickenings of positive radii. -/ theorem closure_eq_iInter_thickening (E : Set α) : closure E = ⋂ (δ : ℝ) (_ : 0 < δ), thickening δ E := by rw [← cthickening_zero] exact cthickening_eq_iInter_thickening rfl.ge E /-- The frontier of the closed thickening of a set is contained in an `EMetric.infEdist` level set. -/ theorem frontier_cthickening_subset (E : Set α) {δ : ℝ} : frontier (cthickening δ E) ⊆ { x : α | infEdist x E = ENNReal.ofReal δ } := frontier_le_subset_eq continuous_infEdist continuous_const /-- The closed ball of radius `δ` centered at a point of `E` is included in the closed thickening of `E`. -/ theorem closedBall_subset_cthickening {α : Type*} [PseudoMetricSpace α] {x : α} {E : Set α} (hx : x ∈ E) (δ : ℝ) : closedBall x δ ⊆ cthickening δ E := by refine (closedBall_subset_cthickening_singleton _ _).trans (cthickening_subset_of_subset _ ?_) simpa using hx theorem cthickening_subset_iUnion_closedBall_of_lt {α : Type*} [PseudoMetricSpace α] (E : Set α) {δ δ' : ℝ} (hδ₀ : 0 < δ') (hδδ' : δ < δ') : cthickening δ E ⊆ ⋃ x ∈ E, closedBall x δ' := by refine (cthickening_subset_thickening' hδ₀ hδδ' E).trans fun x hx => ?_ obtain ⟨y, hy₁, hy₂⟩ := mem_thickening_iff.mp hx exact mem_iUnion₂.mpr ⟨y, hy₁, hy₂.le⟩ /-- The closed thickening of a compact set `E` is the union of the balls `Metric.closedBall x δ` over `x ∈ E`. See also `Metric.cthickening_eq_biUnion_closedBall`. -/ theorem _root_.IsCompact.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] {δ : ℝ} {E : Set α} (hE : IsCompact E) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ E, closedBall x δ := by rcases eq_empty_or_nonempty E with (rfl | hne) · simp only [cthickening_empty, biUnion_empty] refine Subset.antisymm (fun x hx ↦ ?_) (iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _) obtain ⟨y, yE, hy⟩ : ∃ y ∈ E, infEdist x E = edist x y := hE.exists_infEdist_eq_edist hne _ have D1 : edist x y ≤ ENNReal.ofReal δ := (le_of_eq hy.symm).trans hx have D2 : dist x y ≤ δ := by rw [edist_dist] at D1 exact (ENNReal.ofReal_le_ofReal_iff hδ).1 D1 exact mem_biUnion yE D2 theorem cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] [ProperSpace α] (E : Set α) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ closure E, closedBall x δ := by rcases eq_empty_or_nonempty E with (rfl | hne) · simp only [cthickening_empty, biUnion_empty, closure_empty] rw [← cthickening_closure] refine Subset.antisymm (fun x hx ↦ ?_) (iUnion₂_subset fun x hx ↦ closedBall_subset_cthickening hx _) obtain ⟨y, yE, hy⟩ : ∃ y ∈ closure E, infDist x (closure E) = dist x y := isClosed_closure.exists_infDist_eq_dist (closure_nonempty_iff.mpr hne) x replace hy : dist x y ≤ δ := (ENNReal.ofReal_le_ofReal_iff hδ).mp (((congr_arg ENNReal.ofReal hy.symm).le.trans ENNReal.ofReal_toReal_le).trans hx) exact mem_biUnion yE hy nonrec theorem _root_.IsClosed.cthickening_eq_biUnion_closedBall {α : Type*} [PseudoMetricSpace α] [ProperSpace α] {E : Set α} (hE : IsClosed E) (hδ : 0 ≤ δ) : cthickening δ E = ⋃ x ∈ E, closedBall x δ := by rw [cthickening_eq_biUnion_closedBall E hδ, hE.closure_eq] /-- For the equality, see `infEdist_cthickening`. -/ theorem infEdist_le_infEdist_cthickening_add : infEdist x s ≤ infEdist x (cthickening δ s) + ENNReal.ofReal δ := by refine le_of_forall_lt' fun r h => ?_ simp_rw [← lt_tsub_iff_right, infEdist_lt_iff, mem_cthickening_iff] at h obtain ⟨y, hy, hxy⟩ := h exact infEdist_le_edist_add_infEdist.trans_lt ((ENNReal.add_lt_add_of_lt_of_le (hy.trans_lt ENNReal.ofReal_lt_top).ne hxy hy).trans_eq (tsub_add_cancel_of_le <| le_self_add.trans (lt_tsub_iff_left.1 hxy).le)) /-- For the equality, see `infEdist_thickening`. -/ theorem infEdist_le_infEdist_thickening_add : infEdist x s ≤ infEdist x (thickening δ s) + ENNReal.ofReal δ := infEdist_le_infEdist_cthickening_add.trans <| add_le_add_right (infEdist_anti <| thickening_subset_cthickening _ _) _ /-- For the equality, see `thickening_thickening`. -/ @[simp] theorem thickening_thickening_subset (ε δ : ℝ) (s : Set α) : thickening ε (thickening δ s) ⊆ thickening (ε + δ) s := by obtain hε | hε := le_total ε 0 · simp only [thickening_of_nonpos hε, empty_subset] obtain hδ | hδ := le_total δ 0 · simp only [thickening_of_nonpos hδ, thickening_empty, empty_subset] intro x simp_rw [mem_thickening_iff_exists_edist_lt, ENNReal.ofReal_add hε hδ] exact fun ⟨y, ⟨z, hz, hy⟩, hx⟩ => ⟨z, hz, (edist_triangle _ _ _).trans_lt <| ENNReal.add_lt_add hx hy⟩ /-- For the equality, see `thickening_cthickening`. -/ @[simp] theorem thickening_cthickening_subset (ε : ℝ) (hδ : 0 ≤ δ) (s : Set α) : thickening ε (cthickening δ s) ⊆ thickening (ε + δ) s := by obtain hε | hε := le_total ε 0 · simp only [thickening_of_nonpos hε, empty_subset] intro x simp_rw [mem_thickening_iff_exists_edist_lt, mem_cthickening_iff, ← infEdist_lt_iff, ENNReal.ofReal_add hε hδ] rintro ⟨y, hy, hxy⟩ exact infEdist_le_edist_add_infEdist.trans_lt (ENNReal.add_lt_add_of_lt_of_le (hy.trans_lt ENNReal.ofReal_lt_top).ne hxy hy) /-- For the equality, see `cthickening_thickening`. -/ @[simp] theorem cthickening_thickening_subset (hε : 0 ≤ ε) (δ : ℝ) (s : Set α) : cthickening ε (thickening δ s) ⊆ cthickening (ε + δ) s := by obtain hδ | hδ := le_total δ 0 · simp only [thickening_of_nonpos hδ, cthickening_empty, empty_subset] intro x simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ] exact fun hx => infEdist_le_infEdist_thickening_add.trans (add_le_add_right hx _) /-- For the equality, see `cthickening_cthickening`. -/ @[simp] theorem cthickening_cthickening_subset (hε : 0 ≤ ε) (hδ : 0 ≤ δ) (s : Set α) : cthickening ε (cthickening δ s) ⊆ cthickening (ε + δ) s := by intro x simp_rw [mem_cthickening_iff, ENNReal.ofReal_add hε hδ] exact fun hx => infEdist_le_infEdist_cthickening_add.trans (add_le_add_right hx _) open scoped Function in -- required for scoped `on` notation theorem frontier_cthickening_disjoint (A : Set α) : Pairwise (Disjoint on fun r : ℝ≥0 => frontier (cthickening r A)) := fun r₁ r₂ hr => ((disjoint_singleton.2 <| by simpa).preimage _).mono (frontier_cthickening_subset _) (frontier_cthickening_subset _) end Cthickening theorem thickening_ball [PseudoMetricSpace α] (x : α) (ε δ : ℝ) : thickening ε (ball x δ) ⊆ ball x (ε + δ) := by rw [← thickening_singleton, ← thickening_singleton] apply thickening_thickening_subset end Metric open Metric in theorem IsCompact.exists_thickening_image_subset [PseudoEMetricSpace α] {β : Type*} [PseudoEMetricSpace β] {f : α → β} {K : Set α} {U : Set β} (hK : IsCompact K) (ho : IsOpen U) (hf : ∀ x ∈ K, ContinuousAt f x) (hKU : MapsTo f K U) : ∃ ε > 0, ∃ V ∈ 𝓝ˢ K, thickening ε (f '' V) ⊆ U := by apply hK.induction_on (p := fun K ↦ ∃ ε > 0, ∃ V ∈ 𝓝ˢ K, thickening ε (f '' V) ⊆ U) · use 1, by positivity, ∅, by simp, by simp · exact fun s t hst ⟨ε, hε, V, hV, hthickening⟩ ↦ ⟨ε, hε, V, nhdsSet_mono hst hV, hthickening⟩ · rintro s t ⟨ε₁, hε₁, V₁, hV₁, hV₁thickening⟩ ⟨ε₂, hε₂, V₂, hV₂, hV₂thickening⟩ refine ⟨min ε₁ ε₂, by positivity, V₁ ∪ V₂, union_mem_nhdsSet hV₁ hV₂, ?_⟩ rw [image_union, thickening_union] calc thickening (ε₁ ⊓ ε₂) (f '' V₁) ∪ thickening (ε₁ ⊓ ε₂) (f '' V₂) _ ⊆ thickening ε₁ (f '' V₁) ∪ thickening ε₂ (f '' V₂) := by gcongr <;> norm_num _ ⊆ U ∪ U := by gcongr _ = U := union_self _ · intro x hx have : {f x} ⊆ U := by rw [singleton_subset_iff]; exact hKU hx obtain ⟨δ, hδ, hthick⟩ := (isCompact_singleton (x := f x)).exists_thickening_subset_open ho this let V := f ⁻¹' (thickening (δ / 2) {f x}) have : V ∈ 𝓝 x := by apply hf x hx apply isOpen_thickening.mem_nhds exact (self_subset_thickening (by positivity) _) rfl refine ⟨K ∩ (interior V), inter_mem_nhdsWithin K (interior_mem_nhds.mpr this), δ / 2, by positivity, V, by rw [← subset_interior_iff_mem_nhdsSet]; simp, ?_⟩ calc thickening (δ / 2) (f '' V) _ ⊆ thickening (δ / 2) (thickening (δ / 2) {f x}) := thickening_subset_of_subset _ (image_preimage_subset f _) _ ⊆ thickening ((δ / 2) + (δ / 2)) ({f x}) := thickening_thickening_subset (δ / 2) (δ / 2) {f x} _ ⊆ U := by simp [hthick]
Mathlib/Topology/MetricSpace/Thickening.lean
688
694
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne -/ import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.IsBounded import Mathlib.Order.Hom.CompleteLattice /-! # liminfs and limsups of functions and filters Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with respect to an arbitrary filter. We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for `limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`. Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter. For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ. Then there is no guarantee that the quantity above really decreases (the value of the `sup` beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has to use a less tractable definition. In conditionally complete lattices, the definition is only useful for filters which are eventually bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the space either). We start with definitions of these concepts for arbitrary filters, before turning to the definitions of Limsup and Liminf. In complete lattices, however, it coincides with the `Inf Sup` definition. -/ open Filter Set Function variable {α β γ ι ι' : Type*} namespace Filter section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α} /-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `x ≤ a`. -/ def limsSup (f : Filter α) : α := sInf { a | ∀ᶠ n in f, n ≤ a } /-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `x ≥ a`. -/ def limsInf (f : Filter α) : α := sSup { a | ∀ᶠ n in f, a ≤ n } /-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `u x ≤ a`. -/ def limsup (u : β → α) (f : Filter β) : α := limsSup (map u f) /-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `u x ≥ a`. -/ def liminf (u : β → α) (f : Filter β) : α := limsInf (map u f) /-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/ def blimsup (u : β → α) (f : Filter β) (p : β → Prop) := sInf { a | ∀ᶠ x in f, p x → u x ≤ a } /-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/ def bliminf (u : β → α) (f : Filter β) (p : β → Prop) := sSup { a | ∀ᶠ x in f, p x → a ≤ u x } section variable {f : Filter β} {u : β → α} {p : β → Prop} theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } := rfl theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } := rfl theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) : liminf (u ∘ v) f = liminf u (map v f) := rfl lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) : limsup (u ∘ v) f = limsup u (map v f) := rfl end @[simp] theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by simp [blimsup_eq, limsup_eq] @[simp] theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by simp [bliminf_eq, liminf_eq] lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq] lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) := blimsup_eq_limsup (α := αᵒᵈ) theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val] theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := blimsup_eq_limsup_subtype (α := αᵒᵈ) theorem limsSup_le_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a := csInf_le hf h theorem le_limsInf_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f := le_csSup hf h theorem limsup_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a := csInf_le hf h theorem le_liminf_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f := le_csSup hf h theorem le_limsSup_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f := le_csInf hf h theorem limsInf_le_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a := csSup_le hf h theorem le_limsup_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f := le_csInf hf h theorem liminf_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a := csSup_le hf h theorem limsInf_le_limsSup {f : Filter α} [NeBot f] (h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsSup f := liminf_le_of_le h₂ fun a₀ ha₀ => le_limsup_of_le h₁ fun a₁ ha₁ => show a₀ ≤ a₁ from let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists le_trans hb₀ hb₁ theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α} (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ limsup u f := limsInf_le_limsSup h h' theorem limsSup_le_limsSup {f g : Filter α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g := csInf_le_csInf hf hg h theorem limsInf_le_limsInf {f g : Filter α} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g := csSup_le_csSup hg hf h theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : u ≤ᶠ[f] v) (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup u f ≤ limsup v f := limsSup_le_limsSup hu hv fun _ => h.trans theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a ≤ v a) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf u f ≤ liminf v f := limsup_le_limsup (β := βᵒᵈ) h hv hu theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g) (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) : limsSup f ≤ limsSup g := limsSup_le_limsSup hf hg fun _ ha => h ha theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f) (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsInf g := limsInf_le_limsInf hf hg fun _ ha => h ha theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g) {u : α → β} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ limsup u g := limsSup_le_limsSup_of_le (map_mono h) hf hg theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f) {u : α → β} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ liminf u g := limsInf_le_limsInf_of_le (map_mono h) hf hg lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal_eq_csSup (α := αᵒᵈ) h hs lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range] lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range] theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by rw [limsup_eq] congr with b exact eventually_congr (h.mono fun x hx => by simp [hx]) theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : blimsup u f p = blimsup v f p := by simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : bliminf u f p = bliminf v f p := blimsup_congr (α := αᵒᵈ) h theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f := limsup_congr (β := βᵒᵈ) h @[simp] theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : limsup (fun _ => b) f = b := by simpa only [limsup_eq, eventually_const] using csInf_Ici @[simp] theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : liminf (fun _ => b) f = b := limsup_const (β := βᵒᵈ) b theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by simp_rw [liminf_eq, hv.eventually_iff] congr ext x simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists, exists_prop] theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : liminf f v = sSup univ := by simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq] theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) := HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : limsup f v = sInf univ := HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i @[simp] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat] @[simp] theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop := @liminf_nat_add αᵒᵈ _ f k end ConditionallyCompleteLattice section CompleteLattice variable [CompleteLattice α] @[simp] theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ := bot_unique <| sInf_le <| by simp @[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup] @[simp] theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ := top_unique <| le_sSup <| by simp @[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf] @[simp] theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ := top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _ @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _ @[simp] theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by simp [blimsup_eq] @[simp] theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by simp [bliminf_eq] /-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/ @[simp] theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by rw [limsup_eq, eq_bot_iff] exact sInf_le (Eventually.of_forall fun _ => le_rfl) /-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/ @[simp] theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) := limsup_const_bot (α := αᵒᵈ) theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) : limsSup f = ⨅ (i) (_ : p i), sSup (s i) := le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩) (le_sInf fun _ ha => let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha iInf₂_le_of_le _ hi <| sSup_le ha) theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α} (h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) := HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s := f.basis_sets.limsSup_eq_iInf_sSup theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s := limsSup_eq_iInf_sSup (α := αᵒᵈ) theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n := limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u)) theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f := le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u)) /-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a := (f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i := (atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add] theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a := (h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s @[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range] @[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range] theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by simp only [blimsup_eq] congr with a refine eventually_congr (h.mono fun b hb => ?_) rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu] rw [hb hu] theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q := blimsup_congr' (α := αᵒᵈ) h lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (hf : f.HasBasis p s) {q : β → Prop} : blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and, mem_setOf_eq] theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} : blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm] theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} : blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true] /-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a := limsup_eq_iInf_iSup (α := αᵒᵈ) theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i := @limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) := @limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _ theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a := HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} : bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b := @blimsup_eq_iInf_biSup αᵒᵈ β _ f p u theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} : bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j := @blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by apply le_antisymm · rw [limsup_eq] refine sInf_le_sInf fun x hx => ?_ rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩ filter_upwards [I_mem_F] with i hi exact hI ▸ le_sSup (mem_image_of_mem _ hi) · refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_ rintro _ ⟨_, h, rfl⟩ exact h theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) := @Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by rw [liminf_eq] refine sSup_le fun b hb => ?_ have hbx : ∃ᶠ _ in f, b ≤ x := by revert h rw [← not_imp_not, not_frequently, not_frequently] exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax)) exact hbx.exists.choose_spec theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f := liminf_le_of_frequently_le' (β := βᵒᵈ) h /-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any `a : α` is a fixed point. -/ @[simp] theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) : f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by rw [limsup_eq_iInf_iSup_of_nat', map_iInf] simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f, ← Nat.add_succ] conv_rhs => rw [iInf_split _ (0 < ·)] simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf] refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_ simp only [zero_add, Function.comp_apply, iSup_le_iff] exact fun i => le_iSup (fun i => f^[i] a) (i + 1) /-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any `a : α` is a fixed point. -/ theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) : f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop := (CompleteLatticeHom.dual f).apply_limsup_iterate _ variable {f g : Filter β} {p q : β → Prop} {u v : β → α} theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q := sInf_le_sInf fun a ha => ha.mono <| by tauto theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p := sSup_le_sSup fun a ha => ha.mono <| by tauto theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx') theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := mono_blimsup' <| Eventually.of_forall h theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx') theorem mono_bliminf (h : ∀ x, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := mono_bliminf' <| Eventually.of_forall h theorem bliminf_antitone_filter (h : f ≤ g) : bliminf u g p ≤ bliminf u f p := sSup_le_sSup fun _ ha => ha.filter_mono h theorem blimsup_monotone_filter (h : f ≤ g) : blimsup u f p ≤ blimsup u g p := sInf_le_sInf fun _ ha => ha.filter_mono h theorem blimsup_and_le_inf : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q := le_inf (blimsup_mono <| by tauto) (blimsup_mono <| by tauto) @[simp] theorem bliminf_sup_le_inf_aux_left : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f p := blimsup_and_le_inf.trans inf_le_left @[simp] theorem bliminf_sup_le_inf_aux_right : (blimsup u f fun x => p x ∧ q x) ≤ blimsup u f q := blimsup_and_le_inf.trans inf_le_right theorem bliminf_sup_le_and : bliminf u f p ⊔ bliminf u f q ≤ bliminf u f fun x => p x ∧ q x := blimsup_and_le_inf (α := αᵒᵈ) @[simp] theorem bliminf_sup_le_and_aux_left : bliminf u f p ≤ bliminf u f fun x => p x ∧ q x := le_sup_left.trans bliminf_sup_le_and @[simp] theorem bliminf_sup_le_and_aux_right : bliminf u f q ≤ bliminf u f fun x => p x ∧ q x := le_sup_right.trans bliminf_sup_le_and /-- See also `Filter.blimsup_or_eq_sup`. -/ theorem blimsup_sup_le_or : blimsup u f p ⊔ blimsup u f q ≤ blimsup u f fun x => p x ∨ q x := sup_le (blimsup_mono <| by tauto) (blimsup_mono <| by tauto) @[simp] theorem bliminf_sup_le_or_aux_left : blimsup u f p ≤ blimsup u f fun x => p x ∨ q x := le_sup_left.trans blimsup_sup_le_or @[simp] theorem bliminf_sup_le_or_aux_right : blimsup u f q ≤ blimsup u f fun x => p x ∨ q x := le_sup_right.trans blimsup_sup_le_or /-- See also `Filter.bliminf_or_eq_inf`. -/ theorem bliminf_or_le_inf : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q := blimsup_sup_le_or (α := αᵒᵈ) @[simp] theorem bliminf_or_le_inf_aux_left : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f p := bliminf_or_le_inf.trans inf_le_left @[simp] theorem bliminf_or_le_inf_aux_right : (bliminf u f fun x => p x ∨ q x) ≤ bliminf u f q := bliminf_or_le_inf.trans inf_le_right theorem _root_.OrderIso.apply_blimsup [CompleteLattice γ] (e : α ≃o γ) : e (blimsup u f p) = blimsup (e ∘ u) f p := by simp only [blimsup_eq, map_sInf, Function.comp_apply, e.image_eq_preimage, Set.preimage_setOf_eq, e.le_symm_apply] theorem _root_.OrderIso.apply_bliminf [CompleteLattice γ] (e : α ≃o γ) : e (bliminf u f p) = bliminf (e ∘ u) f p := e.dual.apply_blimsup theorem _root_.sSupHom.apply_blimsup_le [CompleteLattice γ] (g : sSupHom α γ) : g (blimsup u f p) ≤ blimsup (g ∘ u) f p := by simp only [blimsup_eq_iInf_biSup, Function.comp] refine ((OrderHomClass.mono g).map_iInf₂_le _).trans ?_ simp only [_root_.map_iSup, le_refl] theorem _root_.sInfHom.le_apply_bliminf [CompleteLattice γ] (g : sInfHom α γ) : bliminf (g ∘ u) f p ≤ g (bliminf u f p) := (sInfHom.dual g).apply_blimsup_le end CompleteLattice section CompleteDistribLattice variable [CompleteDistribLattice α] {f : Filter β} {p q : β → Prop} {u : β → α} lemma limsup_sup_filter {g} : limsup u (f ⊔ g) = limsup u f ⊔ limsup u g := by refine le_antisymm ?_ (sup_le (limsup_le_limsup_of_le le_sup_left) (limsup_le_limsup_of_le le_sup_right)) simp_rw [limsup_eq, sInf_sup_eq, sup_sInf_eq, mem_setOf_eq, le_iInf₂_iff] intro a ha b hb exact sInf_le ⟨ha.mono fun _ h ↦ h.trans le_sup_left, hb.mono fun _ h ↦ h.trans le_sup_right⟩ lemma liminf_sup_filter {g} : liminf u (f ⊔ g) = liminf u f ⊓ liminf u g := limsup_sup_filter (α := αᵒᵈ) @[simp] theorem blimsup_or_eq_sup : (blimsup u f fun x => p x ∨ q x) = blimsup u f p ⊔ blimsup u f q := by simp only [blimsup_eq_limsup, ← limsup_sup_filter, ← inf_sup_left, sup_principal, setOf_or] @[simp] theorem bliminf_or_eq_inf : (bliminf u f fun x => p x ∨ q x) = bliminf u f p ⊓ bliminf u f q := blimsup_or_eq_sup (α := αᵒᵈ) @[simp] lemma blimsup_sup_not : blimsup u f p ⊔ blimsup u f (¬p ·) = limsup u f := by simp_rw [← blimsup_or_eq_sup, or_not, blimsup_true] @[simp] lemma bliminf_inf_not : bliminf u f p ⊓ bliminf u f (¬p ·) = liminf u f := blimsup_sup_not (α := αᵒᵈ) @[simp] lemma blimsup_not_sup : blimsup u f (¬p ·) ⊔ blimsup u f p = limsup u f := by simpa only [not_not] using blimsup_sup_not (p := (¬p ·)) @[simp] lemma bliminf_not_inf : bliminf u f (¬p ·) ⊓ bliminf u f p = liminf u f := blimsup_not_sup (α := αᵒᵈ) lemma limsup_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} : limsup (s.piecewise u v) f = blimsup u f (· ∈ s) ⊔ blimsup v f (· ∉ s) := by rw [← blimsup_sup_not (p := (· ∈ s))] refine congr_arg₂ _ (blimsup_congr ?_) (blimsup_congr ?_) <;> filter_upwards with _ h using by simp [h] lemma liminf_piecewise {s : Set β} [DecidablePred (· ∈ s)] {v} : liminf (s.piecewise u v) f = bliminf u f (· ∈ s) ⊓ bliminf v f (· ∉ s) := limsup_piecewise (α := αᵒᵈ) theorem sup_limsup [NeBot f] (a : α) : a ⊔ limsup u f = limsup (fun x => a ⊔ u x) f := by simp only [limsup_eq_iInf_iSup, iSup_sup_eq, sup_iInf₂_eq] congr; ext s; congr; ext hs; congr exact (biSup_const (nonempty_of_mem hs)).symm theorem inf_liminf [NeBot f] (a : α) : a ⊓ liminf u f = liminf (fun x => a ⊓ u x) f := sup_limsup (α := αᵒᵈ) a theorem sup_liminf (a : α) : a ⊔ liminf u f = liminf (fun x => a ⊔ u x) f := by simp only [liminf_eq_iSup_iInf] rw [sup_comm, biSup_sup (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)] simp_rw [iInf₂_sup_eq, sup_comm (a := a)] theorem inf_limsup (a : α) : a ⊓ limsup u f = limsup (fun x => a ⊓ u x) f := sup_liminf (α := αᵒᵈ) a end CompleteDistribLattice section CompleteBooleanAlgebra variable [CompleteBooleanAlgebra α] (f : Filter β) (u : β → α) theorem limsup_compl : (limsup u f)ᶜ = liminf (compl ∘ u) f := by simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply] theorem liminf_compl : (liminf u f)ᶜ = limsup (compl ∘ u) f := by simp only [limsup_eq_iInf_iSup, compl_iInf, compl_iSup, liminf_eq_iSup_iInf, Function.comp_apply] theorem limsup_sdiff (a : α) : limsup u f \ a = limsup (fun b => u b \ a) f := by simp only [limsup_eq_iInf_iSup, sdiff_eq] rw [biInf_inf (⟨univ, univ_mem⟩ : ∃ i : Set β, i ∈ f)] simp_rw [inf_comm, inf_iSup₂_eq, inf_comm] theorem liminf_sdiff [NeBot f] (a : α) : liminf u f \ a = liminf (fun b => u b \ a) f := by simp only [sdiff_eq, inf_comm _ aᶜ, inf_liminf] theorem sdiff_limsup [NeBot f] (a : α) : a \ limsup u f = liminf (fun b => a \ u b) f := by rw [← compl_inj_iff] simp only [sdiff_eq, liminf_compl, comp_def, compl_inf, compl_compl, sup_limsup] theorem sdiff_liminf (a : α) : a \ liminf u f = limsup (fun b => a \ u b) f := by rw [← compl_inj_iff] simp only [sdiff_eq, limsup_compl, comp_def, compl_inf, compl_compl, sup_liminf] end CompleteBooleanAlgebra section SetLattice variable {p : ι → Prop} {s : ι → Set α} {𝓕 : Filter ι} {a : α} lemma mem_liminf_iff_eventually_mem : (a ∈ liminf s 𝓕) ↔ (∀ᶠ i in 𝓕, a ∈ s i) := by simpa only [liminf_eq_iSup_iInf, iSup_eq_iUnion, iInf_eq_iInter, mem_iUnion, mem_iInter] using ⟨fun ⟨S, hS, hS'⟩ ↦ mem_of_superset hS (by tauto), fun h ↦ ⟨{i | a ∈ s i}, h, by tauto⟩⟩ lemma mem_limsup_iff_frequently_mem : (a ∈ limsup s 𝓕) ↔ (∃ᶠ i in 𝓕, a ∈ s i) := by simp only [Filter.Frequently, iff_not_comm, ← mem_compl_iff, limsup_compl, comp_apply, mem_liminf_iff_eventually_mem] theorem cofinite.blimsup_set_eq : blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.Infinite } := by simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, sInf_eq_sInter, exists_prop] ext x refine ⟨fun h => ?_, fun hx t h => ?_⟩ <;> contrapose! h · simp only [mem_sInter, mem_setOf_eq, not_forall, exists_prop] exact ⟨{x}ᶜ, by simpa using h, by simp⟩ · exact hx.mono fun i hi => ⟨hi.1, fun hit => h (hit hi.2)⟩ theorem cofinite.bliminf_set_eq : bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.Finite } := by rw [← compl_inj_iff] simp only [bliminf_eq_iSup_biInf, compl_iInf, compl_iSup, ← blimsup_eq_iInf_biSup, cofinite.blimsup_set_eq] rfl /-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s` infinitely often. -/ theorem cofinite.limsup_set_eq : limsup s cofinite = { x | { n | x ∈ s n }.Infinite } := by simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and] /-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s` finitely often. -/ theorem cofinite.liminf_set_eq : liminf s cofinite = { x | { n | x ∉ s n }.Finite } := by simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and] theorem exists_forall_mem_of_hasBasis_mem_blimsup {l : Filter β} {b : ι → Set β} {q : ι → Prop} (hl : l.HasBasis q b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) : ∃ f : { i | q i } → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by rw [blimsup_eq_iInf_biSup] at hx simp only [iSup_eq_iUnion, iInf_eq_iInter, mem_iInter, mem_iUnion, exists_prop] at hx choose g hg hg' using hx refine ⟨fun i : { i | q i } => g (b i) (hl.mem_of_mem i.2), fun i => ⟨?_, ?_⟩⟩ · exact hg' (b i) (hl.mem_of_mem i.2) · exact hg (b i) (hl.mem_of_mem i.2) theorem exists_forall_mem_of_hasBasis_mem_blimsup' {l : Filter β} {b : ι → Set β} (hl : l.HasBasis (fun _ => True) b) {u : β → Set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) : ∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i := by obtain ⟨f, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup hl hx exact ⟨fun i => f ⟨i, trivial⟩, fun i => hf ⟨i, trivial⟩⟩ end SetLattice section ConditionallyCompleteLinearOrder theorem frequently_lt_of_lt_limsSup {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : a < limsSup f) : ∃ᶠ n in f, a < n := by contrapose! h simp only [not_frequently, not_lt] at h exact limsSup_le_of_le hf h theorem frequently_lt_of_limsInf_lt {f : Filter α} [ConditionallyCompleteLinearOrder α] {a : α} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : limsInf f < a) : ∃ᶠ n in f, n < a := frequently_lt_of_lt_limsSup (α := OrderDual α) hf h theorem eventually_lt_of_lt_liminf {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β} {b : β} (h : b < liminf u f) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : ∀ᶠ a in f, b < u a := by obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (_ : c ∈ { c : β | ∀ᶠ n : α in f, c ≤ u n }), b < c := by simp_rw [exists_prop] exact exists_lt_of_lt_csSup hu h exact hc.mono fun x hx => lt_of_lt_of_le hbc hx theorem eventually_lt_of_limsup_lt {f : Filter α} [ConditionallyCompleteLinearOrder β] {u : α → β} {b : β} (h : limsup u f < b) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : ∀ᶠ a in f, u a < b := eventually_lt_of_lt_liminf (β := βᵒᵈ) h hu section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, eventually we have `u b < x + ε`. -/ theorem eventually_lt_add_pos_of_limsup_le [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∀ᶠ b : β in atTop, u b < x + ε := eventually_lt_of_limsup_lt (lt_of_le_of_lt hu (lt_add_of_pos_right x hε)) hu_bdd /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, eventually we have `x + ε < u b`. -/ theorem eventually_add_neg_lt_of_le_liminf [Preorder β] [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : β → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∀ᶠ b : β in atTop, x + ε < u b := eventually_lt_of_lt_liminf (lt_of_lt_of_le (add_lt_of_neg_right x hε) hu) hu_bdd /-- If `Filter.limsup u atTop ≤ x`, then for all `ε > 0`, there exists a positive natural number `n` such that `u n < x + ε`. -/ theorem exists_lt_of_limsup_le [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder LE.le atTop u) (hu : Filter.limsup u atTop ≤ x) (hε : 0 < ε) : ∃ n : PNat, u n < x + ε := by have h : ∀ᶠ n : ℕ in atTop, u n < x + ε := eventually_lt_add_pos_of_limsup_le hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ /-- If `x ≤ Filter.liminf u atTop`, then for all `ε < 0`, there exists a positive natural number `n` such that ` x + ε < u n`. -/ theorem exists_lt_of_le_liminf [AddZeroClass α] [AddLeftStrictMono α] {x ε : α} {u : ℕ → α} (hu_bdd : IsBoundedUnder GE.ge atTop u) (hu : x ≤ Filter.liminf u atTop) (hε : ε < 0) : ∃ n : PNat, x + ε < u n := by have h : ∀ᶠ n : ℕ in atTop, x + ε < u n := eventually_add_neg_lt_of_le_liminf hu_bdd hu hε simp only [eventually_atTop] at h obtain ⟨n, hn⟩ := h exact ⟨⟨n + 1, Nat.succ_pos _⟩, hn (n + 1) (Nat.le_succ _)⟩ end ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder β] {f : Filter α} {u : α → β} theorem le_limsup_of_frequently_le {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : b ≤ limsup u f := by revert hu_le rw [← not_imp_not, not_frequently] simp_rw [← lt_iff_not_ge] exact fun h => eventually_lt_of_limsup_lt h hu theorem liminf_le_of_frequently_le {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ b := le_limsup_of_frequently_le (β := βᵒᵈ) hu_le hu theorem frequently_lt_of_lt_limsup {b : β} (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : b < limsup u f) : ∃ᶠ x in f, b < u x := by contrapose! h apply limsSup_le_of_le hu simpa using h theorem frequently_lt_of_liminf_lt {b : β} (hu : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : liminf u f < b) : ∃ᶠ x in f, u x < b := frequently_lt_of_lt_limsup (β := βᵒᵈ) hu h theorem limsup_le_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ a in f, u a < y := by refine ⟨fun h _ h' ↦ eventually_lt_of_limsup_lt (h.trans_lt h') h₂, fun h ↦ ?_⟩ --Two cases: Either `x` is a cluster point from above, or it is not. --In the first case, we use `forall_lt_iff_le'` and split an interval. --In the second case, the function `u` must eventually be smaller or equal to `x`. by_cases h' : ∀ y > x, ∃ z, x < z ∧ z < y · rw [← forall_lt_iff_le'] intro y x_y rcases h' y x_y with ⟨z, x_z, z_y⟩ exact (limsup_le_of_le h₁ ((h z x_z).mono (fun _ ↦ le_of_lt))).trans_lt z_y · apply limsup_le_of_le h₁ set_option push_neg.use_distrib true in push_neg at h' rcases h' with ⟨z, x_z, hz⟩ exact (h z x_z).mono <| fun w hw ↦ (or_iff_left (not_le_of_lt hw)).1 (hz (u w)) /- A version of `limsup_le_iff` with large inequalities in densely ordered spaces.-/ lemma limsup_le_iff' [DenselyOrdered β] {x : β} (h₁ : IsCoboundedUnder (· ≤ ·) f u := by isBoundedDefault) (h₂ : IsBoundedUnder (· ≤ ·) f u := by isBoundedDefault) : limsup u f ≤ x ↔ ∀ y > x, ∀ᶠ (a : α) in f, u a ≤ y := by refine ⟨fun h _ h' ↦ (eventually_lt_of_limsup_lt (h.trans_lt h') h₂).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le'] intro h y x_y obtain ⟨z, x_z, z_y⟩ := exists_between x_y exact (limsup_le_of_le h₁ (h z x_z)).trans_lt z_y theorem le_limsup_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y < u a := by refine ⟨fun h _ h' ↦ frequently_lt_of_lt_limsup h₁ (h'.trans_le h), fun h ↦ ?_⟩ --Two cases: Either `x` is a cluster point from below, or it is not. --In the first case, we use `forall_lt_iff_le` and split an interval. --In the second case, the function `u` must frequently be larger or equal to `x`. by_cases h' : ∀ y < x, ∃ z, y < z ∧ z < x · rw [← forall_lt_iff_le] intro y y_x obtain ⟨z, y_z, z_x⟩ := h' y y_x exact y_z.trans_le (le_limsup_of_frequently_le ((h z z_x).mono (fun _ ↦ le_of_lt)) h₂) · apply le_limsup_of_frequently_le _ h₂ set_option push_neg.use_distrib true in push_neg at h' rcases h' with ⟨z, z_x, hz⟩ exact (h z z_x).mono <| fun w hw ↦ (or_iff_right (not_le_of_lt hw)).1 (hz (u w)) /- A version of `le_limsup_iff` with large inequalities in densely ordered spaces.-/ lemma le_limsup_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : x ≤ limsup u f ↔ ∀ y < x, ∃ᶠ a in f, y ≤ u a := by refine ⟨fun h _ h' ↦ (frequently_lt_of_lt_limsup h₁ (h'.trans_le h)).mono fun _ ↦ le_of_lt, ?_⟩ rw [← forall_lt_iff_le] intro h y y_x obtain ⟨z, y_z, z_x⟩ := exists_between y_x exact y_z.trans_le (le_limsup_of_frequently_le (h z z_x) h₂) theorem le_liminf_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y < u a := limsup_le_iff (β := βᵒᵈ) h₁ h₂ /- A version of `le_liminf_iff` with large inequalities in densely ordered spaces.-/ theorem le_liminf_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : x ≤ liminf u f ↔ ∀ y < x, ∀ᶠ a in f, y ≤ u a := limsup_le_iff' (β := βᵒᵈ) h₁ h₂ theorem liminf_le_iff {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a < y := le_limsup_iff (β := βᵒᵈ) h₁ h₂ /- A version of `liminf_le_iff` with large inequalities in densely ordered spaces.-/ theorem liminf_le_iff' [DenselyOrdered β] {x : β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ x ↔ ∀ y > x, ∃ᶠ a in f, u a ≤ y := le_limsup_iff' (β := βᵒᵈ) h₁ h₂ lemma liminf_le_limsup_of_frequently_le {v : α → β} (h : ∃ᶠ x in f, u x ≤ v x) (h₁ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : liminf u f ≤ limsup v f := by rcases f.eq_or_neBot with rfl | _ · exact (frequently_bot h).rec have h₃ : f.IsCoboundedUnder (· ≥ ·) u := by obtain ⟨a, ha⟩ := h₂.eventually_le apply IsCoboundedUnder.of_frequently_le (a := a) exact (h.and_eventually ha).mono fun x ⟨u_x, v_x⟩ ↦ u_x.trans v_x have h₄ : f.IsCoboundedUnder (· ≤ ·) v := by obtain ⟨a, ha⟩ := h₁.eventually_ge apply IsCoboundedUnder.of_frequently_ge (a := a) exact (ha.and_frequently h).mono fun x ⟨u_x, v_x⟩ ↦ u_x.trans v_x refine (le_limsup_iff h₄ h₂).2 fun y y_v ↦ ?_ have := (le_liminf_iff h₃ h₁).1 (le_refl (liminf u f)) y y_v exact (h.and_eventually this).mono fun x ⟨ux_vx, y_ux⟩ ↦ y_ux.trans_le ux_vx variable [ConditionallyCompleteLinearOrder α] {f : Filter α} {b : α} -- The linter erroneously claims that I'm not referring to `c` set_option linter.unusedVariables false in theorem lt_mem_sets_of_limsSup_lt (h : f.IsBounded (· ≤ ·)) (l : f.limsSup < b) : ∀ᶠ a in f, a < b := let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_csInf_lt h l mem_of_superset h fun _a => hcb.trans_le' theorem gt_mem_sets_of_limsInf_gt : f.IsBounded (· ≥ ·) → b < f.limsInf → ∀ᶠ a in f, b < a := @lt_mem_sets_of_limsSup_lt αᵒᵈ _ _ _ section Classical open Classical in /-- Given an indexed family of sets `s j` over `j : Subtype p` and a function `f`, then `liminf_reparam j` is equal to `j` if `f` is bounded below on `s j`, and otherwise to some index `k` such that `f` is bounded below on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index. This function is used to write down a liminf in a measurable way, in `Filter.HasBasis.liminf_eq_ciSup_ciInf` and `Filter.HasBasis.liminf_eq_ite`. -/ noncomputable def liminf_reparam (f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)] (j : Subtype p) : Subtype p := let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))} let g : ℕ → Subtype p := (exists_surjective_nat _).choose have Z : ∃ n, g n ∈ m ∨ ∀ j, j ∉ m := by by_cases H : ∃ j, j ∈ m · rcases H with ⟨j, hj⟩ rcases (exists_surjective_nat (Subtype p)).choose_spec j with ⟨n, rfl⟩ exact ⟨n, Or.inl hj⟩ · push_neg at H exact ⟨0, Or.inr H⟩ if j ∈ m then j else g (Nat.find Z) /-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are not bounded below. -/ theorem HasBasis.liminf_eq_ciSup_ciInf {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty) (H : ∃ (j : Subtype p), BddBelow (range (fun (i : s j) ↦ f i))) : liminf f v = ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by classical rcases H with ⟨j0, hj0⟩ let m : Set (Subtype p) := {j | BddBelow (range (fun (i : s j) ↦ f i))} have : ∀ (j : Subtype p), Nonempty (s j) := fun j ↦ Nonempty.coe_sort (hs j) have A : ⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ⋃ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) := by apply Subset.antisymm · apply iUnion_subset (fun j ↦ ?_) by_cases hj : j ∈ m · have : j = liminf_reparam f s p j := by simp only [m, liminf_reparam, hj, ite_true] conv_lhs => rw [this] apply subset_iUnion _ j · simp only [m, mem_setOf_eq, ← nonempty_iInter_Iic_iff, not_nonempty_iff_eq_empty] at hj simp only [hj, empty_subset] · apply iUnion_subset (fun j ↦ ?_) exact subset_iUnion (fun (k : Subtype p) ↦ (⋂ (i : s k), Iic (f i))) (liminf_reparam f s p j) have B : ∀ (j : Subtype p), ⋂ (i : s (liminf_reparam f s p j)), Iic (f i) = Iic (⨅ (i : s (liminf_reparam f s p j)), f i) := by intro j apply (Iic_ciInf _).symm change liminf_reparam f s p j ∈ m by_cases Hj : j ∈ m · simpa only [m, liminf_reparam, if_pos Hj] using Hj · simp only [m, liminf_reparam, if_neg Hj] have Z : ∃ n, (exists_surjective_nat (Subtype p)).choose n ∈ m ∨ ∀ j, j ∉ m := by rcases (exists_surjective_nat (Subtype p)).choose_spec j0 with ⟨n, rfl⟩ exact ⟨n, Or.inl hj0⟩ rcases Nat.find_spec Z with hZ|hZ · exact hZ · exact (hZ j0 hj0).elim simp_rw [hv.liminf_eq_sSup_iUnion_iInter, A, B, sSup_iUnion_Iic] open Classical in /-- Writing a liminf as a supremum of infimum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the infimum of sets which are not bounded below. -/ theorem HasBasis.liminf_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) : liminf f v = if ∃ (j : Subtype p), s j = ∅ then sSup univ else if ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) then sSup ∅ else ⨆ (j : Subtype p), ⨅ (i : s (liminf_reparam f s p j)), f i := by by_cases H : ∃ (j : Subtype p), s j = ∅ · rw [if_pos H] rcases H with ⟨j, hj⟩ simp [hv.liminf_eq_sSup_univ_of_empty j j.2 hj] rw [if_neg H] by_cases H' : ∀ (j : Subtype p), ¬BddBelow (range (fun (i : s j) ↦ f i)) · have A : ∀ (j : Subtype p), ⋂ (i : s j), Iic (f i) = ∅ := by simp_rw [← not_nonempty_iff_eq_empty, nonempty_iInter_Iic_iff] exact H' simp_rw [if_pos H', hv.liminf_eq_sSup_iUnion_iInter, A, iUnion_empty] rw [if_neg H'] apply hv.liminf_eq_ciSup_ciInf · push_neg at H simpa only [nonempty_iff_ne_empty] using H · push_neg at H' exact H' /-- Given an indexed family of sets `s j` and a function `f`, then `limsup_reparam j` is equal to `j` if `f` is bounded above on `s j`, and otherwise to some index `k` such that `f` is bounded above on `s k` (if there exists one). To ensure good measurability behavior, this index `k` is chosen as the minimal suitable index. This function is used to write down a limsup in a measurable way, in `Filter.HasBasis.limsup_eq_ciInf_ciSup` and `Filter.HasBasis.limsup_eq_ite`. -/ noncomputable def limsup_reparam (f : ι → α) (s : ι' → Set ι) (p : ι' → Prop) [Countable (Subtype p)] [Nonempty (Subtype p)] (j : Subtype p) : Subtype p := liminf_reparam (α := αᵒᵈ) f s p j /-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are not bounded above. -/ theorem HasBasis.limsup_eq_ciInf_ciSup {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) {f : ι → α} (hs : ∀ (j : Subtype p), (s j).Nonempty) (H : ∃ (j : Subtype p), BddAbove (range (fun (i : s j) ↦ f i))) : limsup f v = ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i := HasBasis.liminf_eq_ciSup_ciInf (α := αᵒᵈ) hv hs H open Classical in /-- Writing a limsup as an infimum of supremum, in a (possibly non-complete) conditionally complete linear order. A reparametrization trick is needed to avoid taking the supremum of sets which are not bounded below. -/ theorem HasBasis.limsup_eq_ite {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} [Countable (Subtype p)] [Nonempty (Subtype p)] (hv : v.HasBasis p s) (f : ι → α) : limsup f v = if ∃ (j : Subtype p), s j = ∅ then sInf univ else if ∀ (j : Subtype p), ¬BddAbove (range (fun (i : s j) ↦ f i)) then sInf ∅ else ⨅ (j : Subtype p), ⨆ (i : s (limsup_reparam f s p j)), f i := HasBasis.liminf_eq_ite (α := αᵒᵈ) hv f end Classical end ConditionallyCompleteLinearOrder end Filter section Order theorem GaloisConnection.l_limsup_le [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {v : α → β} {l : β → γ} {u : γ → β} (gc : GaloisConnection l u) (hlv : f.IsBoundedUnder (· ≤ ·) fun x => l (v x) := by isBoundedDefault) (hv_co : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault) : l (limsup v f) ≤ limsup (fun x => l (v x)) f := by refine le_limsSup_of_le hlv fun c hc => ?_ rw [Filter.eventually_map] at hc simp_rw [gc _ _] at hc ⊢ exact limsSup_le_of_le hv_co hc theorem OrderIso.limsup_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {u : α → β} (g : β ≃o γ) (hu : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (hu_co : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hgu : f.IsBoundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) (hgu_co : f.IsCoboundedUnder (· ≤ ·) fun x => g (u x) := by isBoundedDefault) : g (limsup u f) = limsup (fun x => g (u x)) f := by refine le_antisymm ((OrderIso.to_galoisConnection g).l_limsup_le hgu hu_co) ?_ rw [← g.symm.symm_apply_apply <| limsup (fun x => g (u x)) f, g.symm_symm] refine g.monotone ?_ have hf : u = fun i => g.symm (g (u i)) := funext fun i => (g.symm_apply_apply (u i)).symm nth_rw 2 [hf] refine (OrderIso.to_galoisConnection g.symm).l_limsup_le ?_ hgu_co simp_rw [g.symm_apply_apply] exact hu theorem OrderIso.liminf_apply {γ} [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {f : Filter α} {u : α → β} (g : β ≃o γ) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hu_co : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (hgu : f.IsBoundedUnder (· ≥ ·) fun x => g (u x) := by isBoundedDefault) (hgu_co : f.IsCoboundedUnder (· ≥ ·) fun x => g (u x) := by isBoundedDefault) : g (liminf u f) = liminf (fun x => g (u x)) f := OrderIso.limsup_apply (β := βᵒᵈ) (γ := γᵒᵈ) g.dual hu hu_co hgu hgu_co end Order section MinMax open Filter theorem limsup_max [ConditionallyCompleteLinearOrder β] {f : Filter α} {u v : α → β} (h₁ : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h₂ : f.IsCoboundedUnder (· ≤ ·) v := by isBoundedDefault) (h₃ : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h₄ : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup (fun a ↦ max (u a) (v a)) f = max (limsup u f) (limsup v f) := by have bddmax := IsBoundedUnder.sup h₃ h₄ have cobddmax := isCoboundedUnder_le_max (v := v) (Or.inl h₁) apply le_antisymm · refine (limsup_le_iff cobddmax bddmax).2 (fun b hb ↦ ?_) have hu := eventually_lt_of_limsup_lt (lt_of_le_of_lt (le_max_left _ _) hb) h₃ have hv := eventually_lt_of_limsup_lt (lt_of_le_of_lt (le_max_right _ _) hb) h₄ refine mem_of_superset (inter_mem hu hv) (fun _ ↦ by simp) · exact max_le (c := limsup (fun a ↦ max (u a) (v a)) f) (limsup_le_limsup (Eventually.of_forall (fun a : α ↦ le_max_left (u a) (v a))) h₁ bddmax) (limsup_le_limsup (Eventually.of_forall (fun a : α ↦ le_max_right (u a) (v a))) h₂ bddmax) theorem liminf_min [ConditionallyCompleteLinearOrder β] {f : Filter α} {u v : α → β} (h₁ : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h₂ : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) (h₃ : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h₄ : f.IsBoundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf (fun a ↦ min (u a) (v a)) f = min (liminf u f) (liminf v f) := limsup_max (β := βᵒᵈ) h₁ h₂ h₃ h₄ open Finset theorem limsup_finset_sup' [ConditionallyCompleteLinearOrder β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : limsup (fun a ↦ sup' s hs (fun i ↦ F i a)) f = sup' s hs (fun i ↦ limsup (F i) f) := by have bddsup := isBoundedUnder_le_finset_sup' hs h₂ apply le_antisymm · have h₃ : ∃ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by rcases hs with ⟨i, i_s⟩ use i, i_s exact h₁ i i_s have cobddsup := isCoboundedUnder_le_finset_sup' hs h₃ refine (limsup_le_iff cobddsup bddsup).2 (fun b hb ↦ ?_) rw [eventually_iff_exists_mem] use ⋂ i ∈ s, {a | F i a < b} split_ands · rw [biInter_finset_mem] suffices key : ∀ i ∈ s, ∀ᶠ a in f, F i a < b from fun i i_s ↦ eventually_iff.1 (key i i_s) intro i i_s apply eventually_lt_of_limsup_lt _ (h₂ i i_s) exact lt_of_le_of_lt (Finset.le_sup' (f := fun i ↦ limsup (F i) f) i_s) hb · simp only [mem_iInter, mem_setOf_eq, Finset.sup'_apply, sup'_lt_iff, imp_self, implies_true] · apply Finset.sup'_le hs (fun i ↦ limsup (F i) f) refine fun i i_s ↦ limsup_le_limsup (Eventually.of_forall (fun a ↦ ?_)) (h₁ i i_s) bddsup simp only [Finset.sup'_apply, le_sup'_iff] use i, i_s theorem limsup_finset_sup [ConditionallyCompleteLinearOrder β] [OrderBot β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≤ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : limsup (fun a ↦ sup s (fun i ↦ F i a)) f = sup s (fun i ↦ limsup (F i) f) := by rcases eq_or_neBot f with (rfl | _) · simp [limsup_eq, csInf_univ] rcases Finset.eq_empty_or_nonempty s with (rfl | s_nemp) · simp only [Finset.sup_apply, sup_empty, limsup_const] rw [← Finset.sup'_eq_sup s_nemp fun i ↦ limsup (F i) f, ← limsup_finset_sup' s_nemp h₁ h₂] congr ext a exact Eq.symm (Finset.sup'_eq_sup s_nemp (fun i ↦ F i a)) theorem liminf_finset_inf' [ConditionallyCompleteLinearOrder β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (hs : s.Nonempty) (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : liminf (fun a ↦ inf' s hs (fun i ↦ F i a)) f = inf' s hs (fun i ↦ liminf (F i) f) := limsup_finset_sup' (β := βᵒᵈ) hs h₁ h₂ theorem liminf_finset_inf [ConditionallyCompleteLinearOrder β] [OrderTop β] {f : Filter α} {F : ι → α → β} {s : Finset ι} (h₁ : ∀ i ∈ s, f.IsCoboundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) (h₂ : ∀ i ∈ s, f.IsBoundedUnder (· ≥ ·) (F i) := by exact fun _ _ ↦ by isBoundedDefault) : liminf (fun a ↦ inf s (fun i ↦ F i a)) f = inf s (fun i ↦ liminf (F i) f) := limsup_finset_sup (β := βᵒᵈ) h₁ h₂ end MinMax
Mathlib/Order/LiminfLimsup.lean
1,495
1,504
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.SmoothSeries import Mathlib.Analysis.Calculus.BumpFunction.InnerProduct import Mathlib.Analysis.Convolution import Mathlib.Analysis.InnerProductSpace.EuclideanDist import Mathlib.Data.Set.Pointwise.Support import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.MeasureTheory.Measure.Haar.Unique /-! # Bump functions in finite-dimensional vector spaces Let `E` be a finite-dimensional real normed vector space. We show that any open set `s` in `E` is exactly the support of a smooth function taking values in `[0, 1]`, in `IsOpen.exists_smooth_support_eq`. Then we use this construction to construct bump functions with nice behavior, by convolving the indicator function of `closedBall 0 1` with a function as above with `s = ball 0 D`. -/ noncomputable section open Set Metric TopologicalSpace Function Asymptotics MeasureTheory Module ContinuousLinearMap Filter MeasureTheory.Measure Bornology open scoped Pointwise Topology NNReal Convolution ContDiff variable {E : Type*} [NormedAddCommGroup E] section variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] /-- If a set `s` is a neighborhood of `x`, then there exists a smooth function `f` taking values in `[0, 1]`, supported in `s` and with `f x = 1`. -/ theorem exists_smooth_tsupport_subset {s : Set E} {x : E} (hs : s ∈ 𝓝 x) : ∃ f : E → ℝ, tsupport f ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ∞ f ∧ range f ⊆ Icc 0 1 ∧ f x = 1 := by obtain ⟨d : ℝ, d_pos : 0 < d, hd : Euclidean.closedBall x d ⊆ s⟩ := Euclidean.nhds_basis_closedBall.mem_iff.1 hs let c : ContDiffBump (toEuclidean x) := { rIn := d / 2 rOut := d rIn_pos := half_pos d_pos rIn_lt_rOut := half_lt_self d_pos } let f : E → ℝ := c ∘ toEuclidean have f_supp : f.support ⊆ Euclidean.ball x d := by intro y hy have : toEuclidean y ∈ Function.support c := by simpa only [Function.mem_support, Function.comp_apply, Ne] using hy rwa [c.support_eq] at this have f_tsupp : tsupport f ⊆ Euclidean.closedBall x d := by rw [tsupport, ← Euclidean.closure_ball _ d_pos.ne'] exact closure_mono f_supp refine ⟨f, f_tsupp.trans hd, ?_, ?_, ?_, ?_⟩ · refine isCompact_of_isClosed_isBounded isClosed_closure ?_ have : IsBounded (Euclidean.closedBall x d) := Euclidean.isCompact_closedBall.isBounded refine this.subset (Euclidean.isClosed_closedBall.closure_subset_iff.2 ?_) exact f_supp.trans Euclidean.ball_subset_closedBall · apply c.contDiff.comp exact ContinuousLinearEquiv.contDiff _ · rintro t ⟨y, rfl⟩ exact ⟨c.nonneg, c.le_one⟩ · apply c.one_of_mem_closedBall apply mem_closedBall_self exact (half_pos d_pos).le /-- Given an open set `s` in a finite-dimensional real normed vector space, there exists a smooth function with values in `[0, 1]` whose support is exactly `s`. -/ theorem IsOpen.exists_smooth_support_eq {s : Set E} (hs : IsOpen s) : ∃ f : E → ℝ, f.support = s ∧ ContDiff ℝ ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := by /- For any given point `x` in `s`, one can construct a smooth function with support in `s` and nonzero at `x`. By second-countability, it follows that we may cover `s` with the supports of countably many such functions, say `g i`. Then `∑ i, r i • g i` will be the desired function if `r i` is a sequence of positive numbers tending quickly enough to zero. Indeed, this ensures that, for any `k ≤ i`, the `k`-th derivative of `r i • g i` is bounded by a prescribed (summable) sequence `u i`. From this, the summability of the series and of its successive derivatives follows. -/ rcases eq_empty_or_nonempty s with (rfl | h's) · exact ⟨fun _ => 0, Function.support_zero, contDiff_const, by simp only [range_const, singleton_subset_iff, left_mem_Icc, zero_le_one]⟩ let ι := { f : E → ℝ // f.support ⊆ s ∧ HasCompactSupport f ∧ ContDiff ℝ ∞ f ∧ range f ⊆ Icc 0 1 } obtain ⟨T, T_count, hT⟩ : ∃ T : Set ι, T.Countable ∧ ⋃ f ∈ T, support (f : E → ℝ) = s := by have : ⋃ f : ι, (f : E → ℝ).support = s := by refine Subset.antisymm (iUnion_subset fun f => f.2.1) ?_ intro x hx rcases exists_smooth_tsupport_subset (hs.mem_nhds hx) with ⟨f, hf⟩ let g : ι := ⟨f, (subset_tsupport f).trans hf.1, hf.2.1, hf.2.2.1, hf.2.2.2.1⟩ have : x ∈ support (g : E → ℝ) := by simp only [g, hf.2.2.2.2, Subtype.coe_mk, mem_support, Ne, one_ne_zero, not_false_iff] exact mem_iUnion_of_mem _ this simp_rw [← this] apply isOpen_iUnion_countable rintro ⟨f, hf⟩ exact hf.2.2.1.continuous.isOpen_support obtain ⟨g0, hg⟩ : ∃ g0 : ℕ → ι, T = range g0 := by apply Countable.exists_eq_range T_count rcases eq_empty_or_nonempty T with (rfl | hT) · simp only [ι, iUnion_false, iUnion_empty] at hT simp only [← hT, mem_empty_iff_false, iUnion_of_empty, iUnion_empty, Set.not_nonempty_empty] at h's · exact hT let g : ℕ → E → ℝ := fun n => (g0 n).1 have g_s : ∀ n, support (g n) ⊆ s := fun n => (g0 n).2.1 have s_g : ∀ x ∈ s, ∃ n, x ∈ support (g n) := fun x hx ↦ by rw [← hT] at hx obtain ⟨i, iT, hi⟩ : ∃ i ∈ T, x ∈ support (i : E → ℝ) := by simpa only [mem_iUnion, exists_prop] using hx rw [hg, mem_range] at iT rcases iT with ⟨n, hn⟩ rw [← hn] at hi exact ⟨n, hi⟩ have g_smooth : ∀ n, ContDiff ℝ ∞ (g n) := fun n => (g0 n).2.2.2.1 have g_comp_supp : ∀ n, HasCompactSupport (g n) := fun n => (g0 n).2.2.1 have g_nonneg : ∀ n x, 0 ≤ g n x := fun n x => ((g0 n).2.2.2.2 (mem_range_self x)).1 obtain ⟨δ, δpos, c, δc, c_lt⟩ : ∃ δ : ℕ → ℝ≥0, (∀ i : ℕ, 0 < δ i) ∧ ∃ c : NNReal, HasSum δ c ∧ c < 1 := NNReal.exists_pos_sum_of_countable one_ne_zero ℕ have : ∀ n : ℕ, ∃ r : ℝ, 0 < r ∧ ∀ i ≤ n, ∀ x, ‖iteratedFDeriv ℝ i (r • g n) x‖ ≤ δ n := by intro n have : ∀ i, ∃ R, ∀ x, ‖iteratedFDeriv ℝ i (fun x => g n x) x‖ ≤ R := by intro i have : BddAbove (range fun x => ‖iteratedFDeriv ℝ i (fun x : E => g n x) x‖) := by apply ((g_smooth n).continuous_iteratedFDeriv (mod_cast le_top)).norm.bddAbove_range_of_hasCompactSupport apply HasCompactSupport.comp_left _ norm_zero apply (g_comp_supp n).iteratedFDeriv rcases this with ⟨R, hR⟩ exact ⟨R, fun x => hR (mem_range_self _)⟩ choose R hR using this let M := max (((Finset.range (n + 1)).image R).max' (by simp)) 1 have δnpos : 0 < δ n := δpos n have IR : ∀ i ≤ n, R i ≤ M := by intro i hi refine le_trans ?_ (le_max_left _ _) apply Finset.le_max' apply Finset.mem_image_of_mem simp only [Finset.mem_range] omega refine ⟨M⁻¹ * δ n, by positivity, fun i hi x => ?_⟩ calc ‖iteratedFDeriv ℝ i ((M⁻¹ * δ n) • g n) x‖ = ‖(M⁻¹ * δ n) • iteratedFDeriv ℝ i (g n) x‖ := by rw [iteratedFDeriv_const_smul_apply] exact (g_smooth n).contDiffAt.of_le (mod_cast le_top) _ = M⁻¹ * δ n * ‖iteratedFDeriv ℝ i (g n) x‖ := by rw [norm_smul _ (iteratedFDeriv ℝ i (g n) x), Real.norm_of_nonneg]; positivity _ ≤ M⁻¹ * δ n * M := by gcongr; exact (hR i x).trans (IR i hi) _ = δ n := by field_simp choose r rpos hr using this have S : ∀ x, Summable fun n => (r n • g n) x := fun x ↦ by refine .of_nnnorm_bounded _ δc.summable fun n => ?_ rw [← NNReal.coe_le_coe, coe_nnnorm] simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) x refine ⟨fun x => ∑' n, (r n • g n) x, ?_, ?_, ?_⟩ · apply Subset.antisymm · intro x hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, mem_support, Ne] at hx contrapose! hx have : ∀ n, g n x = 0 := by intro n contrapose! hx exact g_s n hx simp only [this, mul_zero, tsum_zero] · intro x hx obtain ⟨n, hn⟩ : ∃ n, x ∈ support (g n) := s_g x hx have I : 0 < r n * g n x := mul_pos (rpos n) (lt_of_le_of_ne (g_nonneg n x) (Ne.symm hn)) exact ne_of_gt ((S x).tsum_pos (fun i => mul_nonneg (rpos i).le (g_nonneg i x)) n I) · refine contDiff_tsum_of_eventually (fun n => (g_smooth n).const_smul (r n)) (fun k _ => (NNReal.hasSum_coe.2 δc).summable) ?_ intro i _ simp only [Nat.cofinite_eq_atTop, Pi.smul_apply, Algebra.id.smul_eq_mul, Filter.eventually_atTop] exact ⟨i, fun n hn x => hr _ _ hn _⟩ · rintro - ⟨y, rfl⟩ refine ⟨tsum_nonneg fun n => mul_nonneg (rpos n).le (g_nonneg n y), le_trans ?_ c_lt.le⟩ have A : HasSum (fun n => (δ n : ℝ)) c := NNReal.hasSum_coe.2 δc simp only [Pi.smul_apply, smul_eq_mul, NNReal.val_eq_coe, ← A.tsum_eq] apply Summable.tsum_le_tsum _ (S y) A.summable intro n apply (le_abs_self _).trans simpa only [norm_iteratedFDeriv_zero] using hr n 0 (zero_le n) y end section namespace ExistsContDiffBumpBase /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces. It is the characteristic function of the closed unit ball. -/ def φ : E → ℝ := (closedBall (0 : E) 1).indicator fun _ => (1 : ℝ) variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] section HelperDefinitions variable (E) theorem u_exists : ∃ u : E → ℝ, ContDiff ℝ ∞ u ∧ (∀ x, u x ∈ Icc (0 : ℝ) 1) ∧ support u = ball 0 1 ∧ ∀ x, u (-x) = u x := by have A : IsOpen (ball (0 : E) 1) := isOpen_ball obtain ⟨f, f_support, f_smooth, f_range⟩ : ∃ f : E → ℝ, f.support = ball (0 : E) 1 ∧ ContDiff ℝ ∞ f ∧ Set.range f ⊆ Set.Icc 0 1 := A.exists_smooth_support_eq have B : ∀ x, f x ∈ Icc (0 : ℝ) 1 := fun x => f_range (mem_range_self x) refine ⟨fun x => (f x + f (-x)) / 2, ?_, ?_, ?_, ?_⟩ · exact (f_smooth.add (f_smooth.comp contDiff_neg)).div_const _ · intro x simp only [mem_Icc] constructor · linarith [(B x).1, (B (-x)).1] · linarith [(B x).2, (B (-x)).2] · refine support_eq_iff.2 ⟨fun x hx => ?_, fun x hx => ?_⟩ · apply ne_of_gt have : 0 < f x := by apply lt_of_le_of_ne (B x).1 (Ne.symm _) rwa [← f_support] at hx linarith [(B (-x)).1] · have I1 : x ∉ support f := by rwa [f_support] have I2 : -x ∉ support f := by rw [f_support] simpa using hx simp only [mem_support, Classical.not_not] at I1 I2 simp only [I1, I2, add_zero, zero_div] · intro x; simp only [add_comm, neg_neg] variable {E} in /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces, which is smooth, symmetric, and with support equal to the unit ball. -/ def u (x : E) : ℝ := Classical.choose (u_exists E) x theorem u_smooth : ContDiff ℝ ∞ (u : E → ℝ) := (Classical.choose_spec (u_exists E)).1 theorem u_continuous : Continuous (u : E → ℝ) := (u_smooth E).continuous theorem u_support : support (u : E → ℝ) = ball 0 1 := (Classical.choose_spec (u_exists E)).2.2.1 theorem u_compact_support : HasCompactSupport (u : E → ℝ) := by rw [hasCompactSupport_def, u_support, closure_ball (0 : E) one_ne_zero] exact isCompact_closedBall _ _ variable {E} theorem u_nonneg (x : E) : 0 ≤ u x := ((Classical.choose_spec (u_exists E)).2.1 x).1 theorem u_le_one (x : E) : u x ≤ 1 := ((Classical.choose_spec (u_exists E)).2.1 x).2 theorem u_neg (x : E) : u (-x) = u x := (Classical.choose_spec (u_exists E)).2.2.2 x variable [MeasurableSpace E] [BorelSpace E] local notation "μ" => MeasureTheory.Measure.addHaar variable (E) in theorem u_int_pos : 0 < ∫ x : E, u x ∂μ := by refine (integral_pos_iff_support_of_nonneg u_nonneg ?_).mpr ?_ · exact (u_continuous E).integrable_of_hasCompactSupport (u_compact_support E) · rw [u_support]; exact measure_ball_pos _ _ zero_lt_one /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces, which is smooth, symmetric, with support equal to the ball of radius `D` and integral `1`. -/ def w (D : ℝ) (x : E) : ℝ := ((∫ x : E, u x ∂μ) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x) theorem w_def (D : ℝ) : (w D : E → ℝ) = fun x => ((∫ x : E, u x ∂μ) * |D| ^ finrank ℝ E)⁻¹ • u (D⁻¹ • x) := by ext1 x; rfl theorem w_nonneg (D : ℝ) (x : E) : 0 ≤ w D x := by apply mul_nonneg _ (u_nonneg _) apply inv_nonneg.2 apply mul_nonneg (u_int_pos E).le norm_cast apply pow_nonneg (abs_nonneg D) theorem w_mul_φ_nonneg (D : ℝ) (x y : E) : 0 ≤ w D y * φ (x - y) := mul_nonneg (w_nonneg D y) (indicator_nonneg (by simp only [zero_le_one, imp_true_iff]) _) variable (E) theorem w_integral {D : ℝ} (Dpos : 0 < D) : ∫ x : E, w D x ∂μ = 1 := by simp_rw [w, integral_smul] rw [integral_comp_inv_smul_of_nonneg μ (u : E → ℝ) Dpos.le, abs_of_nonneg Dpos.le, mul_comm] field_simp [(u_int_pos E).ne'] theorem w_support {D : ℝ} (Dpos : 0 < D) : support (w D : E → ℝ) = ball 0 D := by have B : D • ball (0 : E) 1 = ball 0 D := by rw [smul_unitBall Dpos.ne', Real.norm_of_nonneg Dpos.le] have C : D ^ finrank ℝ E ≠ 0 := by norm_cast exact pow_ne_zero _ Dpos.ne' simp only [w_def, Algebra.id.smul_eq_mul, support_mul, support_inv, univ_inter, support_comp_inv_smul₀ Dpos.ne', u_support, B, support_const (u_int_pos E).ne', support_const C, abs_of_nonneg Dpos.le] theorem w_compact_support {D : ℝ} (Dpos : 0 < D) : HasCompactSupport (w D : E → ℝ) := by rw [hasCompactSupport_def, w_support E Dpos, closure_ball (0 : E) Dpos.ne'] exact isCompact_closedBall _ _ variable {E} /-- An auxiliary function to construct partitions of unity on finite-dimensional real vector spaces. It is the convolution between a smooth function of integral `1` supported in the ball of radius `D`, with the indicator function of the closed unit ball. Therefore, it is smooth, equal to `1` on the ball of radius `1 - D`, with support equal to the ball of radius `1 + D`. -/ def y (D : ℝ) : E → ℝ := w D ⋆[lsmul ℝ ℝ, μ] φ theorem y_neg (D : ℝ) (x : E) : y D (-x) = y D x := by apply convolution_neg_of_neg_eq · filter_upwards with x simp only [w_def, Real.rpow_natCast, mul_inv_rev, smul_neg, u_neg, smul_eq_mul, forall_const] · filter_upwards with x simp only [φ, indicator, mem_closedBall, dist_zero_right, norm_neg, forall_const] theorem y_eq_one_of_mem_closedBall {D : ℝ} {x : E} (Dpos : 0 < D) (hx : x ∈ closedBall (0 : E) (1 - D)) : y D x = 1 := by change (w D ⋆[lsmul ℝ ℝ, μ] φ) x = 1 have B : ∀ y : E, y ∈ ball x D → φ y = 1 := by have C : ball x D ⊆ ball 0 1 := by apply ball_subset_ball' simp only [mem_closedBall] at hx linarith only [hx] intro y hy simp only [φ, indicator, mem_closedBall, ite_eq_left_iff, not_le, zero_ne_one] intro h'y linarith only [mem_ball.1 (C hy), h'y] have Bx : φ x = 1 := B _ (mem_ball_self Dpos) have B' : ∀ y, y ∈ ball x D → φ y = φ x := by rw [Bx]; exact B rw [convolution_eq_right' _ (le_of_eq (w_support E Dpos)) B'] simp only [lsmul_apply, Algebra.id.smul_eq_mul, integral_mul_const, w_integral E Dpos, Bx, one_mul] theorem y_eq_zero_of_not_mem_ball {D : ℝ} {x : E} (Dpos : 0 < D) (hx : x ∉ ball (0 : E) (1 + D)) : y D x = 0 := by change (w D ⋆[lsmul ℝ ℝ, μ] φ) x = 0 have B : ∀ y, y ∈ ball x D → φ y = 0 := by intro y hy simp only [φ, indicator, mem_closedBall_zero_iff, ite_eq_right_iff, one_ne_zero] intro h'y have C : ball y D ⊆ ball 0 (1 + D) := by apply ball_subset_ball' rw [← dist_zero_right] at h'y linarith only [h'y] exact hx (C (mem_ball_comm.1 hy)) have Bx : φ x = 0 := B _ (mem_ball_self Dpos) have B' : ∀ y, y ∈ ball x D → φ y = φ x := by rw [Bx]; exact B
rw [convolution_eq_right' _ (le_of_eq (w_support E Dpos)) B'] simp only [lsmul_apply, Algebra.id.smul_eq_mul, Bx, mul_zero, integral_const] theorem y_nonneg (D : ℝ) (x : E) : 0 ≤ y D x := integral_nonneg (w_mul_φ_nonneg D x) theorem y_le_one {D : ℝ} (x : E) (Dpos : 0 < D) : y D x ≤ 1 := by have A : (w D ⋆[lsmul ℝ ℝ, μ] φ) x ≤ (w D ⋆[lsmul ℝ ℝ, μ] 1) x := by apply convolution_mono_right_of_nonneg _ (w_nonneg D) (indicator_le_self' fun x _ => zero_le_one) fun _ => zero_le_one refine ((w_compact_support E Dpos).convolutionExists_left _ ?_ (locallyIntegrable_const (1 : ℝ)) x).integrable exact continuous_const.mul ((u_continuous E).comp (continuous_id.const_smul _)) have B : (w D ⋆[lsmul ℝ ℝ, μ] fun _ => (1 : ℝ)) x = 1 := by simp only [convolution, ContinuousLinearMap.map_smul, mul_inv_rev, coe_smul', mul_one, lsmul_apply, Algebra.id.smul_eq_mul, integral_const_mul, w_integral E Dpos, Pi.smul_apply]
Mathlib/Analysis/Calculus/BumpFunction/FiniteDimension.lean
365
381
/- Copyright (c) 2021 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.Homology.ComplexShape import Mathlib.CategoryTheory.Subobject.Limits import Mathlib.CategoryTheory.GradedObject import Mathlib.Algebra.Homology.ShortComplex.Basic /-! # Homological complexes. A `HomologicalComplex V c` with a "shape" controlled by `c : ComplexShape ι` has chain groups `X i` (objects in `V`) indexed by `i : ι`, and a differential `d i j` whenever `c.Rel i j`. We in fact ask for differentials `d i j` for all `i j : ι`, but have a field `shape` requiring that these are zero when not allowed by `c`. This avoids a lot of dependent type theory hell! The composite of any two differentials `d i j ≫ d j k` must be zero. We provide `ChainComplex V α` for `α`-indexed chain complexes in which `d i j ≠ 0` only if `j + 1 = i`, and similarly `CochainComplex V α`, with `i = j + 1`. There is a category structure, where morphisms are chain maps. For `C : HomologicalComplex V c`, we define `C.xNext i`, which is either `C.X j` for some arbitrarily chosen `j` such that `c.r i j`, or `C.X i` if there is no such `j`. Similarly we have `C.xPrev j`. Defined in terms of these we have `C.dFrom i : C.X i ⟶ C.xNext i` and `C.dTo j : C.xPrev j ⟶ C.X j`, which are either defined as `C.d i j`, or zero, as needed. -/ universe v u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {ι : Type*} variable (V : Type u) [Category.{v} V] [HasZeroMorphisms V] /-- A `HomologicalComplex V c` with a "shape" controlled by `c : ComplexShape ι` has chain groups `X i` (objects in `V`) indexed by `i : ι`, and a differential `d i j` whenever `c.Rel i j`. We in fact ask for differentials `d i j` for all `i j : ι`, but have a field `shape` requiring that these are zero when not allowed by `c`. This avoids a lot of dependent type theory hell! The composite of any two differentials `d i j ≫ d j k` must be zero. -/ structure HomologicalComplex (c : ComplexShape ι) where X : ι → V d : ∀ i j, X i ⟶ X j shape : ∀ i j, ¬c.Rel i j → d i j = 0 := by aesop_cat d_comp_d' : ∀ i j k, c.Rel i j → c.Rel j k → d i j ≫ d j k = 0 := by aesop_cat namespace HomologicalComplex attribute [simp] shape variable {V} {c : ComplexShape ι} @[reassoc (attr := simp)] theorem d_comp_d (C : HomologicalComplex V c) (i j k : ι) : C.d i j ≫ C.d j k = 0 := by by_cases hij : c.Rel i j · by_cases hjk : c.Rel j k · exact C.d_comp_d' i j k hij hjk · rw [C.shape j k hjk, comp_zero] · rw [C.shape i j hij, zero_comp] theorem ext {C₁ C₂ : HomologicalComplex V c} (h_X : C₁.X = C₂.X) (h_d : ∀ i j : ι, c.Rel i j → C₁.d i j ≫ eqToHom (congr_fun h_X j) = eqToHom (congr_fun h_X i) ≫ C₂.d i j) : C₁ = C₂ := by obtain ⟨X₁, d₁, s₁, h₁⟩ := C₁ obtain ⟨X₂, d₂, s₂, h₂⟩ := C₂ dsimp at h_X subst h_X simp only [mk.injEq, heq_eq_eq, true_and] ext i j by_cases hij : c.Rel i j · simpa only [comp_id, id_comp, eqToHom_refl] using h_d i j hij · rw [s₁ i j hij, s₂ i j hij] /-- The obvious isomorphism `K.X p ≅ K.X q` when `p = q`. -/ def XIsoOfEq (K : HomologicalComplex V c) {p q : ι} (h : p = q) : K.X p ≅ K.X q := eqToIso (by rw [h]) @[simp] lemma XIsoOfEq_rfl (K : HomologicalComplex V c) (p : ι) : K.XIsoOfEq (rfl : p = p) = Iso.refl _ := rfl @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₁₂ : p₁ = p₂) (h₂₃ : p₂ = p₃) : (K.XIsoOfEq h₁₂).hom ≫ (K.XIsoOfEq h₂₃).hom = (K.XIsoOfEq (h₁₂.trans h₂₃)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₁₂ : p₁ = p₂) (h₃₂ : p₃ = p₂) : (K.XIsoOfEq h₁₂).hom ≫ (K.XIsoOfEq h₃₂).inv = (K.XIsoOfEq (h₁₂.trans h₃₂.symm)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₂₁ : p₂ = p₁) (h₂₃ : p₂ = p₃) : (K.XIsoOfEq h₂₁).inv ≫ (K.XIsoOfEq h₂₃).hom = (K.XIsoOfEq (h₂₁.symm.trans h₂₃)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₂₁ : p₂ = p₁) (h₃₂ : p₃ = p₂) : (K.XIsoOfEq h₂₁).inv ≫ (K.XIsoOfEq h₃₂).inv = (K.XIsoOfEq (h₃₂.trans h₂₁).symm).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_d (K : HomologicalComplex V c) {p₁ p₂ : ι} (h : p₁ = p₂) (p₃ : ι) : (K.XIsoOfEq h).hom ≫ K.d p₂ p₃ = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_d (K : HomologicalComplex V c) {p₂ p₁ : ι} (h : p₂ = p₁) (p₃ : ι) : (K.XIsoOfEq h).inv ≫ K.d p₂ p₃ = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma d_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₂ p₃ : ι} (h : p₂ = p₃) (p₁ : ι) : K.d p₁ p₂ ≫ (K.XIsoOfEq h).hom = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma d_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₂ p₃ : ι} (h : p₃ = p₂) (p₁ : ι) : K.d p₁ p₂ ≫ (K.XIsoOfEq h).inv = K.d p₁ p₃ := by subst h; simp end HomologicalComplex /-- An `α`-indexed chain complex is a `HomologicalComplex` in which `d i j ≠ 0` only if `j + 1 = i`. -/ abbrev ChainComplex (α : Type*) [AddRightCancelSemigroup α] [One α] : Type _ := HomologicalComplex V (ComplexShape.down α) /-- An `α`-indexed cochain complex is a `HomologicalComplex` in which `d i j ≠ 0` only if `i + 1 = j`. -/ abbrev CochainComplex (α : Type*) [AddRightCancelSemigroup α] [One α] : Type _ := HomologicalComplex V (ComplexShape.up α) namespace ChainComplex @[simp] theorem prev (α : Type*) [AddRightCancelSemigroup α] [One α] (i : α) : (ComplexShape.down α).prev i = i + 1 := (ComplexShape.down α).prev_eq' rfl @[simp] theorem next (α : Type*) [AddGroup α] [One α] (i : α) : (ComplexShape.down α).next i = i - 1 := (ComplexShape.down α).next_eq' <| sub_add_cancel _ _ @[simp] theorem next_nat_zero : (ComplexShape.down ℕ).next 0 = 0 := by classical refine dif_neg ?_ push_neg intro apply Nat.noConfusion @[simp] theorem next_nat_succ (i : ℕ) : (ComplexShape.down ℕ).next (i + 1) = i := (ComplexShape.down ℕ).next_eq' rfl end ChainComplex namespace CochainComplex @[simp] theorem prev (α : Type*) [AddGroup α] [One α] (i : α) : (ComplexShape.up α).prev i = i - 1 := (ComplexShape.up α).prev_eq' <| sub_add_cancel _ _ @[simp] theorem next (α : Type*) [AddRightCancelSemigroup α] [One α] (i : α) : (ComplexShape.up α).next i = i + 1 := (ComplexShape.up α).next_eq' rfl @[simp] theorem prev_nat_zero : (ComplexShape.up ℕ).prev 0 = 0 := by classical refine dif_neg ?_ push_neg intro apply Nat.noConfusion @[simp] theorem prev_nat_succ (i : ℕ) : (ComplexShape.up ℕ).prev (i + 1) = i := (ComplexShape.up ℕ).prev_eq' rfl end CochainComplex namespace HomologicalComplex variable {V} variable {c : ComplexShape ι} (C : HomologicalComplex V c) /-- A morphism of homological complexes consists of maps between the chain groups, commuting with the differentials. -/ @[ext] structure Hom (A B : HomologicalComplex V c) where f : ∀ i, A.X i ⟶ B.X i comm' : ∀ i j, c.Rel i j → f i ≫ B.d i j = A.d i j ≫ f j := by aesop_cat @[reassoc (attr := simp)] theorem Hom.comm {A B : HomologicalComplex V c} (f : A.Hom B) (i j : ι) : f.f i ≫ B.d i j = A.d i j ≫ f.f j := by by_cases hij : c.Rel i j · exact f.comm' i j hij · rw [A.shape i j hij, B.shape i j hij, comp_zero, zero_comp] instance (A B : HomologicalComplex V c) : Inhabited (Hom A B) := ⟨{ f := fun _ => 0 }⟩ /-- Identity chain map. -/ def id (A : HomologicalComplex V c) : Hom A A where f _ := 𝟙 _ /-- Composition of chain maps. -/ def comp (A B C : HomologicalComplex V c) (φ : Hom A B) (ψ : Hom B C) : Hom A C where f i := φ.f i ≫ ψ.f i section attribute [local simp] id comp instance : Category (HomologicalComplex V c) where Hom := Hom id := id comp := comp _ _ _ end @[ext] lemma hom_ext {C D : HomologicalComplex V c} (f g : C ⟶ D) (h : ∀ i, f.f i = g.f i) : f = g := by apply Hom.ext funext apply h @[simp] theorem id_f (C : HomologicalComplex V c) (i : ι) : Hom.f (𝟙 C) i = 𝟙 (C.X i) := rfl @[simp, reassoc] theorem comp_f {C₁ C₂ C₃ : HomologicalComplex V c} (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) : (f ≫ g).f i = f.f i ≫ g.f i := rfl @[simp] theorem eqToHom_f {C₁ C₂ : HomologicalComplex V c} (h : C₁ = C₂) (n : ι) : HomologicalComplex.Hom.f (eqToHom h) n = eqToHom (congr_fun (congr_arg HomologicalComplex.X h) n) := by subst h rfl -- We'll use this later to show that `HomologicalComplex V c` is preadditive when `V` is. theorem hom_f_injective {C₁ C₂ : HomologicalComplex V c} : Function.Injective fun f : Hom C₁ C₂ => f.f := by aesop_cat instance (X Y : HomologicalComplex V c) : Zero (X ⟶ Y) := ⟨{ f := fun _ => 0}⟩ @[simp] theorem zero_f (C D : HomologicalComplex V c) (i : ι) : (0 : C ⟶ D).f i = 0 := rfl instance : HasZeroMorphisms (HomologicalComplex V c) where open ZeroObject /-- The zero complex -/ noncomputable def zero [HasZeroObject V] : HomologicalComplex V c where X _ := 0 d _ _ := 0 theorem isZero_zero [HasZeroObject V] : IsZero (zero : HomologicalComplex V c) := by refine ⟨fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩ all_goals ext dsimp only [zero] subsingleton instance [HasZeroObject V] : HasZeroObject (HomologicalComplex V c) := ⟨⟨zero, isZero_zero⟩⟩ noncomputable instance [HasZeroObject V] : Inhabited (HomologicalComplex V c) := ⟨zero⟩ theorem congr_hom {C D : HomologicalComplex V c} {f g : C ⟶ D} (w : f = g) (i : ι) : f.f i = g.f i := congr_fun (congr_arg Hom.f w) i lemma mono_of_mono_f {K L : HomologicalComplex V c} (φ : K ⟶ L) (hφ : ∀ i, Mono (φ.f i)) : Mono φ where right_cancellation g h eq := by ext i rw [← cancel_mono (φ.f i)] exact congr_hom eq i lemma epi_of_epi_f {K L : HomologicalComplex V c} (φ : K ⟶ L) (hφ : ∀ i, Epi (φ.f i)) : Epi φ where left_cancellation g h eq := by ext i rw [← cancel_epi (φ.f i)] exact congr_hom eq i section variable (V c) /-- The functor picking out the `i`-th object of a complex. -/ @[simps] def eval (i : ι) : HomologicalComplex V c ⥤ V where obj C := C.X i map f := f.f i instance (i : ι) : (eval V c i).PreservesZeroMorphisms where /-- The functor forgetting the differential in a complex, obtaining a graded object. -/ @[simps] def forget : HomologicalComplex V c ⥤ GradedObject ι V where obj C := C.X map f := f.f instance : (forget V c).Faithful where map_injective h := by ext i exact congr_fun h i /-- Forgetting the differentials than picking out the `i`-th object is the same as just picking out the `i`-th object. -/ @[simps!] def forgetEval (i : ι) : forget V c ⋙ GradedObject.eval i ≅ eval V c i := NatIso.ofComponents fun _ => Iso.refl _ end noncomputable section @[reassoc] lemma XIsoOfEq_hom_naturality {K L : HomologicalComplex V c} (φ : K ⟶ L) {n n' : ι} (h : n = n') : φ.f n ≫ (L.XIsoOfEq h).hom = (K.XIsoOfEq h).hom ≫ φ.f n' := by subst h; simp @[reassoc] lemma XIsoOfEq_inv_naturality {K L : HomologicalComplex V c} (φ : K ⟶ L) {n n' : ι} (h : n = n') : φ.f n' ≫ (L.XIsoOfEq h).inv = (K.XIsoOfEq h).inv ≫ φ.f n := by subst h; simp -- Porting note: removed @[simp] as the linter complained /-- If `C.d i j` and `C.d i j'` are both allowed, then we must have `j = j'`, and so the differentials only differ by an `eqToHom`. -/ theorem d_comp_eqToHom {i j j' : ι} (rij : c.Rel i j) (rij' : c.Rel i j') : C.d i j' ≫ eqToHom (congr_arg C.X (c.next_eq rij' rij)) = C.d i j := by obtain rfl := c.next_eq rij rij' simp only [eqToHom_refl, comp_id] -- Porting note: removed @[simp] as the linter complained /-- If `C.d i j` and `C.d i' j` are both allowed, then we must have `i = i'`, and so the differentials only differ by an `eqToHom`. -/ theorem eqToHom_comp_d {i i' j : ι} (rij : c.Rel i j) (rij' : c.Rel i' j) : eqToHom (congr_arg C.X (c.prev_eq rij rij')) ≫ C.d i' j = C.d i j := by obtain rfl := c.prev_eq rij rij' simp only [eqToHom_refl, id_comp] theorem kernel_eq_kernel [HasKernels V] {i j j' : ι} (r : c.Rel i j) (r' : c.Rel i j') : kernelSubobject (C.d i j) = kernelSubobject (C.d i j') := by rw [← d_comp_eqToHom C r r'] apply kernelSubobject_comp_mono theorem image_eq_image [HasImages V] [HasEqualizers V] {i i' j : ι} (r : c.Rel i j) (r' : c.Rel i' j) : imageSubobject (C.d i j) = imageSubobject (C.d i' j) := by rw [← eqToHom_comp_d C r r'] apply imageSubobject_iso_comp section /-- Either `C.X i`, if there is some `i` with `c.Rel i j`, or `C.X j`. -/ abbrev xPrev (j : ι) : V := C.X (c.prev j) /-- If `c.Rel i j`, then `C.xPrev j` is isomorphic to `C.X i`. -/ def xPrevIso {i j : ι} (r : c.Rel i j) : C.xPrev j ≅ C.X i := eqToIso <| by rw [← c.prev_eq' r] /-- If there is no `i` so `c.Rel i j`, then `C.xPrev j` is isomorphic to `C.X j`. -/ def xPrevIsoSelf {j : ι} (h : ¬c.Rel (c.prev j) j) : C.xPrev j ≅ C.X j := eqToIso <| congr_arg C.X (by dsimp [ComplexShape.prev] rw [dif_neg] push_neg; intro i hi have : c.prev j = i := c.prev_eq' hi rw [this] at h; contradiction) /-- Either `C.X j`, if there is some `j` with `c.rel i j`, or `C.X i`. -/ abbrev xNext (i : ι) : V := C.X (c.next i) /-- If `c.Rel i j`, then `C.xNext i` is isomorphic to `C.X j`. -/ def xNextIso {i j : ι} (r : c.Rel i j) : C.xNext i ≅ C.X j := eqToIso <| by rw [← c.next_eq' r] /-- If there is no `j` so `c.Rel i j`, then `C.xNext i` is isomorphic to `C.X i`. -/ def xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) : C.xNext i ≅ C.X i := eqToIso <| congr_arg C.X (by dsimp [ComplexShape.next] rw [dif_neg]; rintro ⟨j, hj⟩ have : c.next i = j := c.next_eq' hj rw [this] at h; contradiction) /-- The differential mapping into `C.X j`, or zero if there isn't one. -/ abbrev dTo (j : ι) : C.xPrev j ⟶ C.X j := C.d (c.prev j) j /-- The differential mapping out of `C.X i`, or zero if there isn't one. -/ abbrev dFrom (i : ι) : C.X i ⟶ C.xNext i := C.d i (c.next i) theorem dTo_eq {i j : ι} (r : c.Rel i j) : C.dTo j = (C.xPrevIso r).hom ≫ C.d i j := by obtain rfl := c.prev_eq' r exact (Category.id_comp _).symm @[simp] theorem dTo_eq_zero {j : ι} (h : ¬c.Rel (c.prev j) j) : C.dTo j = 0 := C.shape _ _ h theorem dFrom_eq {i j : ι} (r : c.Rel i j) : C.dFrom i = C.d i j ≫ (C.xNextIso r).inv := by obtain rfl := c.next_eq' r exact (Category.comp_id _).symm @[simp] theorem dFrom_eq_zero {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i = 0 := C.shape _ _ h @[reassoc (attr := simp)] theorem xPrevIso_comp_dTo {i j : ι} (r : c.Rel i j) : (C.xPrevIso r).inv ≫ C.dTo j = C.d i j := by simp [C.dTo_eq r] @[reassoc (attr := simp)] theorem xPrevIsoSelf_comp_dTo {j : ι} (h : ¬c.Rel (c.prev j) j) : (C.xPrevIsoSelf h).inv ≫ C.dTo j = 0 := by simp [h] @[reassoc (attr := simp)] theorem dFrom_comp_xNextIso {i j : ι} (r : c.Rel i j) : C.dFrom i ≫ (C.xNextIso r).hom = C.d i j := by simp [C.dFrom_eq r] @[reassoc (attr := simp)] theorem dFrom_comp_xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i ≫ (C.xNextIsoSelf h).hom = 0 := by simp [h] -- This is not a simp lemma; the LHS already simplifies. theorem dTo_comp_dFrom (j : ι) : C.dTo j ≫ C.dFrom j = 0 := C.d_comp_d _ _ _ theorem kernel_from_eq_kernel [HasKernels V] {i j : ι} (r : c.Rel i j) : kernelSubobject (C.dFrom i) = kernelSubobject (C.d i j) := by rw [C.dFrom_eq r] apply kernelSubobject_comp_mono theorem image_to_eq_image [HasImages V] [HasEqualizers V] {i j : ι} (r : c.Rel i j) : imageSubobject (C.dTo j) = imageSubobject (C.d i j) := by rw [C.dTo_eq r] apply imageSubobject_iso_comp end namespace Hom variable {C₁ C₂ C₃ : HomologicalComplex V c} /-- The `i`-th component of an isomorphism of chain complexes. -/ @[simps!] def isoApp (f : C₁ ≅ C₂) (i : ι) : C₁.X i ≅ C₂.X i := (eval V c i).mapIso f /-- Construct an isomorphism of chain complexes from isomorphism of the objects which commute with the differentials. -/ @[simps] def isoOfComponents (f : ∀ i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.Rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom := by aesop_cat) : C₁ ≅ C₂ where hom := { f := fun i => (f i).hom comm' := hf } inv := { f := fun i => (f i).inv comm' := fun i j hij => calc (f i).inv ≫ C₁.d i j = (f i).inv ≫ (C₁.d i j ≫ (f j).hom) ≫ (f j).inv := by simp _ = (f i).inv ≫ ((f i).hom ≫ C₂.d i j) ≫ (f j).inv := by rw [hf i j hij] _ = C₂.d i j ≫ (f j).inv := by simp } hom_inv_id := by ext i exact (f i).hom_inv_id inv_hom_id := by ext i exact (f i).inv_hom_id @[simp] theorem isoOfComponents_app (f : ∀ i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.Rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom) (i : ι) : isoApp (isoOfComponents f hf) i = f i := by ext simp theorem isIso_of_components (f : C₁ ⟶ C₂) [∀ n : ι, IsIso (f.f n)] : IsIso f := (HomologicalComplex.Hom.isoOfComponents fun n => asIso (f.f n)).isIso_hom /-! Lemmas relating chain maps and `dTo`/`dFrom`. -/ /-- `f.prev j` is `f.f i` if there is some `r i j`, and `f.f j` otherwise. -/ abbrev prev (f : Hom C₁ C₂) (j : ι) : C₁.xPrev j ⟶ C₂.xPrev j := f.f _ theorem prev_eq (f : Hom C₁ C₂) {i j : ι} (w : c.Rel i j) : f.prev j = (C₁.xPrevIso w).hom ≫ f.f i ≫ (C₂.xPrevIso w).inv := by obtain rfl := c.prev_eq' w simp only [xPrevIso, eqToIso_refl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp] /-- `f.next i` is `f.f j` if there is some `r i j`, and `f.f j` otherwise. -/ abbrev next (f : Hom C₁ C₂) (i : ι) : C₁.xNext i ⟶ C₂.xNext i := f.f _ theorem next_eq (f : Hom C₁ C₂) {i j : ι} (w : c.Rel i j) : f.next i = (C₁.xNextIso w).hom ≫ f.f j ≫ (C₂.xNextIso w).inv := by obtain rfl := c.next_eq' w simp only [xNextIso, eqToIso_refl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp] @[reassoc, elementwise] theorem comm_from (f : Hom C₁ C₂) (i : ι) : f.f i ≫ C₂.dFrom i = C₁.dFrom i ≫ f.next i := f.comm _ _ attribute [simp] comm_from_apply @[reassoc, elementwise] theorem comm_to (f : Hom C₁ C₂) (j : ι) : f.prev j ≫ C₂.dTo j = C₁.dTo j ≫ f.f j := f.comm _ _ attribute [simp] comm_to_apply /-- A morphism of chain complexes induces a morphism of arrows of the differentials out of each object. -/ def sqFrom (f : Hom C₁ C₂) (i : ι) : Arrow.mk (C₁.dFrom i) ⟶ Arrow.mk (C₂.dFrom i) := Arrow.homMk _ _ (f.comm_from i) @[simp] theorem sqFrom_left (f : Hom C₁ C₂) (i : ι) : (f.sqFrom i).left = f.f i := rfl @[simp] theorem sqFrom_right (f : Hom C₁ C₂) (i : ι) : (f.sqFrom i).right = f.next i := rfl @[simp] theorem sqFrom_id (C₁ : HomologicalComplex V c) (i : ι) : sqFrom (𝟙 C₁) i = 𝟙 _ := rfl @[simp] theorem sqFrom_comp (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) : sqFrom (f ≫ g) i = sqFrom f i ≫ sqFrom g i := rfl /-- A morphism of chain complexes induces a morphism of arrows of the differentials into each object. -/ def sqTo (f : Hom C₁ C₂) (j : ι) : Arrow.mk (C₁.dTo j) ⟶ Arrow.mk (C₂.dTo j) := Arrow.homMk _ _ (f.comm_to j) @[simp] theorem sqTo_left (f : Hom C₁ C₂) (j : ι) : (f.sqTo j).left = f.prev j := rfl @[simp] theorem sqTo_right (f : Hom C₁ C₂) (j : ι) : (f.sqTo j).right = f.f j := rfl end Hom end end HomologicalComplex namespace ChainComplex section Of variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] /-- Construct an `α`-indexed chain complex from a dependently-typed differential. -/ def of (X : α → V) (d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) : ChainComplex V α := { X := X d := fun i j => if h : i = j + 1 then eqToHom (by rw [h]) ≫ d j else 0 shape := fun i j w => by dsimp rw [dif_neg (Ne.symm w)] d_comp_d' := fun i j k hij hjk => by dsimp at hij hjk substs hij hjk simp only [eqToHom_refl, id_comp, dite_eq_ite, ite_true, sq] } variable (X : α → V) (d : ∀ n, X (n + 1) ⟶ X n) (sq : ∀ n, d (n + 1) ≫ d n = 0) @[simp] theorem of_x (n : α) : (of X d sq).X n = X n := rfl @[simp] theorem of_d (j : α) : (of X d sq).d (j + 1) j = d j := by dsimp [of] rw [if_pos rfl, Category.id_comp] theorem of_d_ne {i j : α} (h : i ≠ j + 1) : (of X d sq).d i j = 0 := by dsimp [of] rw [dif_neg h] end Of section OfHom variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] variable (X : α → V) (d_X : ∀ n, X (n + 1) ⟶ X n) (sq_X : ∀ n, d_X (n + 1) ≫ d_X n = 0) (Y : α → V) (d_Y : ∀ n, Y (n + 1) ⟶ Y n) (sq_Y : ∀ n, d_Y (n + 1) ≫ d_Y n = 0) /-- A constructor for chain maps between `α`-indexed chain complexes built using `ChainComplex.of`, from a dependently typed collection of morphisms. -/ @[simps] def ofHom (f : ∀ i : α, X i ⟶ Y i) (comm : ∀ i : α, f (i + 1) ≫ d_Y i = d_X i ≫ f i) : of X d_X sq_X ⟶ of Y d_Y sq_Y := { f comm' := fun n m => by by_cases h : n = m + 1 · subst h simpa using comm m · rw [of_d_ne X _ _ h, of_d_ne Y _ _ h] simp } end OfHom section Mk variable {V} variable (X₀ X₁ X₂ : V) (d₀ : X₁ ⟶ X₀) (d₁ : X₂ ⟶ X₁) (s : d₁ ≫ d₀ = 0) (succ : ∀ (S : ShortComplex V), Σ' (X₃ : V) (d₂ : X₃ ⟶ S.X₁), d₂ ≫ S.f = 0) /-- Auxiliary definition for `mk`. -/ def mkAux : ℕ → ShortComplex V | 0 => ShortComplex.mk _ _ s | n + 1 => ShortComplex.mk _ _ (succ (mkAux n)).2.2 /-- An inductive constructor for `ℕ`-indexed chain complexes. You provide explicitly the first two differentials, then a function which takes two differentials and the fact they compose to zero, and returns the next object, its differential, and the fact it composes appropriately to zero. See also `mk'`, which only sees the previous differential in the inductive step. -/ def mk : ChainComplex V ℕ := of (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).X₃) (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).g) fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).zero @[simp] theorem mk_X_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 0 = X₀ := rfl @[simp] theorem mk_X_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 1 = X₁ := rfl @[simp] theorem mk_X_2 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 2 = X₂ := rfl @[simp] theorem mk_d_1_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 1 0 = d₀ := by change ite (1 = 0 + 1) (𝟙 X₁ ≫ d₀) 0 = d₀ rw [if_pos rfl, Category.id_comp] @[simp] theorem mk_d_2_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 2 1 = d₁ := by change ite (2 = 1 + 1) (𝟙 X₂ ≫ d₁) 0 = d₁ rw [if_pos rfl, Category.id_comp] -- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed. /-- A simpler inductive constructor for `ℕ`-indexed chain complexes. You provide explicitly the first differential, then a function which takes a differential, and returns the next object, its differential, and the fact it composes appropriately to zero. -/ def mk' (X₀ X₁ : V) (d : X₁ ⟶ X₀) (succ' : ∀ {X₀ X₁ : V} (f : X₁ ⟶ X₀), Σ' (X₂ : V) (d : X₂ ⟶ X₁), d ≫ f = 0) : ChainComplex V ℕ := mk _ _ _ _ _ (succ' d).2.2 (fun S => succ' S.f) variable (succ' : ∀ {X₀ X₁ : V} (f : X₁ ⟶ X₀), Σ' (X₂ : V) (d : X₂ ⟶ X₁), d ≫ f = 0) @[simp] theorem mk'_X_0 : (mk' X₀ X₁ d₀ succ').X 0 = X₀ := rfl @[simp] theorem mk'_X_1 : (mk' X₀ X₁ d₀ succ').X 1 = X₁ := rfl @[simp] theorem mk'_d_1_0 : (mk' X₀ X₁ d₀ succ').d 1 0 = d₀ := by change ite (1 = 0 + 1) (𝟙 X₁ ≫ d₀) 0 = d₀ rw [if_pos rfl, Category.id_comp] /- Porting note: Downstream constructions using `mk'` (e.g. in `CategoryTheory.Abelian.Projective`) have very slow proofs, because of bad simp lemmas. It would be better to write good lemmas here if possible, such as ``` theorem mk'_X_succ (j : ℕ) : (mk' X₀ X₁ d₀ succ').X (j + 2) = (succ' ⟨_, _, (mk' X₀ X₁ d₀ succ').d (j + 1) j⟩).1 := by sorry theorem mk'_d_succ {i j : ℕ} : (mk' X₀ X₁ d₀ succ').d (j + 2) (j + 1) = eqToHom (mk'_X_succ X₀ X₁ d₀ succ' j) ≫ (succ' ⟨_, _, (mk' X₀ X₁ d₀ succ').d (j + 1) j⟩).2.1 := sorry ``` These are already tricky, and it may be better to write analogous lemmas for `mk` first. -/ end Mk section MkHom variable {V} variable (P Q : ChainComplex V ℕ) (zero : P.X 0 ⟶ Q.X 0) (one : P.X 1 ⟶ Q.X 1) (one_zero_comm : one ≫ Q.d 1 0 = P.d 1 0 ≫ zero) (succ : ∀ (n : ℕ) (p : Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f' ≫ Q.d (n + 1) n = P.d (n + 1) n ≫ f), Σ' f'' : P.X (n + 2) ⟶ Q.X (n + 2), f'' ≫ Q.d (n + 2) (n + 1) = P.d (n + 2) (n + 1) ≫ p.2.1) /-- An auxiliary construction for `mkHom`. Here we build by induction a family of commutative squares, but don't require at the type level that these successive commutative squares actually agree. They do in fact agree, and we then capture that at the type level (i.e. by constructing a chain map) in `mkHom`. -/ def mkHomAux : ∀ n, Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f' ≫ Q.d (n + 1) n = P.d (n + 1) n ≫ f | 0 => ⟨zero, one, one_zero_comm⟩ | n + 1 => ⟨(mkHomAux n).2.1, (succ n (mkHomAux n)).1, (succ n (mkHomAux n)).2⟩ /-- A constructor for chain maps between `ℕ`-indexed chain complexes, working by induction on commutative squares. You need to provide the components of the chain map in degrees 0 and 1, show that these form a commutative square, and then give a construction of each component, and the fact that it forms a commutative square with the previous component, using as an inductive hypothesis the data (and commutativity) of the previous two components. -/ def mkHom : P ⟶ Q where f n := (mkHomAux P Q zero one one_zero_comm succ n).1 comm' n m := by rintro (rfl : m + 1 = n) exact (mkHomAux P Q zero one one_zero_comm succ m).2.2 @[simp] theorem mkHom_f_0 : (mkHom P Q zero one one_zero_comm succ).f 0 = zero := rfl @[simp] theorem mkHom_f_1 : (mkHom P Q zero one one_zero_comm succ).f 1 = one := rfl @[simp] theorem mkHom_f_succ_succ (n : ℕ) : (mkHom P Q zero one one_zero_comm succ).f (n + 2) = (succ n ⟨(mkHom P Q zero one one_zero_comm succ).f n, (mkHom P Q zero one one_zero_comm succ).f (n + 1), (mkHom P Q zero one one_zero_comm succ).comm (n + 1) n⟩).1 := by dsimp [mkHom, mkHomAux] end MkHom end ChainComplex namespace CochainComplex section Of variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] /-- Construct an `α`-indexed cochain complex from a dependently-typed differential. -/ def of (X : α → V) (d : ∀ n, X n ⟶ X (n + 1)) (sq : ∀ n, d n ≫ d (n + 1) = 0) : CochainComplex V α := { X := X d := fun i j => if h : i + 1 = j then d _ ≫ eqToHom (by rw [h]) else 0 shape := fun i j w => by dsimp rw [dif_neg] exact w d_comp_d' := fun i j k => by dsimp split_ifs with h h' h' · substs h h' simp [sq] all_goals simp } variable (X : α → V) (d : ∀ n, X n ⟶ X (n + 1)) (sq : ∀ n, d n ≫ d (n + 1) = 0) @[simp] theorem of_x (n : α) : (of X d sq).X n = X n := rfl @[simp] theorem of_d (j : α) : (of X d sq).d j (j + 1) = d j := by dsimp [of] rw [if_pos rfl, Category.comp_id] theorem of_d_ne {i j : α} (h : i + 1 ≠ j) : (of X d sq).d i j = 0 := by dsimp [of] rw [dif_neg h] end Of section OfHom variable {V} {α : Type*} [AddRightCancelSemigroup α] [One α] [DecidableEq α] variable (X : α → V) (d_X : ∀ n, X n ⟶ X (n + 1)) (sq_X : ∀ n, d_X n ≫ d_X (n + 1) = 0) (Y : α → V) (d_Y : ∀ n, Y n ⟶ Y (n + 1)) (sq_Y : ∀ n, d_Y n ≫ d_Y (n + 1) = 0) /-- A constructor for chain maps between `α`-indexed cochain complexes built using `CochainComplex.of`, from a dependently typed collection of morphisms. -/ @[simps] def ofHom (f : ∀ i : α, X i ⟶ Y i) (comm : ∀ i : α, f i ≫ d_Y i = d_X i ≫ f (i + 1)) : of X d_X sq_X ⟶ of Y d_Y sq_Y := { f comm' := fun n m => by by_cases h : n + 1 = m · subst h simpa using comm n · rw [of_d_ne X _ _ h, of_d_ne Y _ _ h] simp } end OfHom section Mk variable {V} variable (X₀ X₁ X₂ : V) (d₀ : X₀ ⟶ X₁) (d₁ : X₁ ⟶ X₂) (s : d₀ ≫ d₁ = 0) (succ : ∀ (S : ShortComplex V), Σ' (X₄ : V) (d₂ : S.X₃ ⟶ X₄), S.g ≫ d₂ = 0) /-- Auxiliary definition for `mk`. -/ def mkAux : ℕ → ShortComplex V | 0 => ShortComplex.mk _ _ s | n + 1 => ShortComplex.mk _ _ (succ (mkAux n)).2.2 /-- An inductive constructor for `ℕ`-indexed cochain complexes. You provide explicitly the first two differentials, then a function which takes two differentials and the fact they compose to zero, and returns the next object, its differential, and the fact it composes appropriately to zero. See also `mk'`, which only sees the previous differential in the inductive step. -/ def mk : CochainComplex V ℕ := of (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).X₁) (fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).f) fun n => (mkAux X₀ X₁ X₂ d₀ d₁ s succ n).zero @[simp] theorem mk_X_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 0 = X₀ := rfl @[simp] theorem mk_X_1 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 1 = X₁ := rfl @[simp] theorem mk_X_2 : (mk X₀ X₁ X₂ d₀ d₁ s succ).X 2 = X₂ := rfl @[simp] theorem mk_d_1_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 0 1 = d₀ := by change ite (1 = 0 + 1) (d₀ ≫ 𝟙 X₁) 0 = d₀ rw [if_pos rfl, Category.comp_id] @[simp] theorem mk_d_2_0 : (mk X₀ X₁ X₂ d₀ d₁ s succ).d 1 2 = d₁ := by change ite (2 = 1 + 1) (d₁ ≫ 𝟙 X₂) 0 = d₁ rw [if_pos rfl, Category.comp_id] -- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed. /-- A simpler inductive constructor for `ℕ`-indexed cochain complexes. You provide explicitly the first differential, then a function which takes a differential, and returns the next object, its differential, and the fact it composes appropriately to zero. -/ def mk' (X₀ X₁ : V) (d : X₀ ⟶ X₁) -- (succ' : ∀ : ΣX₀ X₁ : V, X₀ ⟶ X₁, Σ' (X₂ : V) (d : t.2.1 ⟶ X₂), t.2.2 ≫ d = 0) : (succ' : ∀ {X₀ X₁ : V} (f : X₀ ⟶ X₁), Σ' (X₂ : V) (d : X₁ ⟶ X₂), f ≫ d = 0) : CochainComplex V ℕ := mk _ _ _ _ _ (succ' d).2.2 (fun S => succ' S.g) variable (succ' : ∀ {X₀ X₁ : V} (f : X₀ ⟶ X₁), Σ' (X₂ : V) (d : X₁ ⟶ X₂), f ≫ d = 0) @[simp] theorem mk'_X_0 : (mk' X₀ X₁ d₀ succ').X 0 = X₀ := rfl @[simp] theorem mk'_X_1 : (mk' X₀ X₁ d₀ succ').X 1 = X₁ := rfl @[simp] theorem mk'_d_1_0 : (mk' X₀ X₁ d₀ succ').d 0 1 = d₀ := by change ite (1 = 0 + 1) (d₀ ≫ 𝟙 X₁) 0 = d₀ rw [if_pos rfl, Category.comp_id] -- TODO simp lemmas for the inductive steps? It's not entirely clear that they are needed. end Mk section MkHom variable {V} variable (P Q : CochainComplex V ℕ) (zero : P.X 0 ⟶ Q.X 0) (one : P.X 1 ⟶ Q.X 1) (one_zero_comm : zero ≫ Q.d 0 1 = P.d 0 1 ≫ one) (succ : ∀ (n : ℕ) (p : Σ' (f : P.X n ⟶ Q.X n) (f' : P.X (n + 1) ⟶ Q.X (n + 1)), f ≫ Q.d n (n + 1) = P.d n (n + 1) ≫ f'), Σ' f'' : P.X (n + 2) ⟶ Q.X (n + 2), p.2.1 ≫ Q.d (n + 1) (n + 2) = P.d (n + 1) (n + 2) ≫ f'')
/-- An auxiliary construction for `mkHom`.
Mathlib/Algebra/Homology/HomologicalComplex.lean
970
972
/- 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.Filter.Curry import Mathlib.Data.Set.Countable /-! # Filters with countable intersection property In this file we define `CountableInterFilter` to be the class of filters with the following property: for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well. Two main examples are the `residual` filter defined in `Mathlib.Topology.GDelta` and the `MeasureTheory.ae` filter defined in `Mathlib/MeasureTheory.OuterMeasure/AE`. We reformulate the definition in terms of indexed intersection and in terms of `Filter.Eventually` and provide instances for some basic constructions (`⊥`, `⊤`, `Filter.principal`, `Filter.map`, `Filter.comap`, `Inf.inf`). We also provide a custom constructor `Filter.ofCountableInter` that deduces two axioms of a `Filter` from the countable intersection property. Note that there also exists a typeclass `CardinalInterFilter`, and thus an alternative spelling of `CountableInterFilter` as `CardinalInterFilter l ℵ₁`. The former (defined here) is the preferred spelling; it has the advantage of not requiring the user to import the theory of ordinals. ## Tags filter, countable -/ open Set Filter open Filter variable {ι : Sort*} {α β : Type*} /-- A filter `l` has the countable intersection property if for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well. -/ class CountableInterFilter (l : Filter α) : Prop where /-- For a countable collection of sets `s ∈ l`, their intersection belongs to `l` as well. -/ countable_sInter_mem : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l variable {l : Filter α} [CountableInterFilter l] theorem countable_sInter_mem {S : Set (Set α)} (hSc : S.Countable) : ⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l := ⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs), CountableInterFilter.countable_sInter_mem _ hSc⟩ theorem countable_iInter_mem [Countable ι] {s : ι → Set α} : (⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l := sInter_range s ▸ (countable_sInter_mem (countable_range _)).trans forall_mem_range theorem countable_bInter_mem {ι : Type*} {S : Set ι} (hS : S.Countable) {s : ∀ i ∈ S, Set α} : (⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by rw [biInter_eq_iInter] haveI := hS.toEncodable exact countable_iInter_mem.trans Subtype.forall theorem eventually_countable_forall [Countable ι] {p : α → ι → Prop} : (∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by simpa only [Filter.Eventually, setOf_forall] using @countable_iInter_mem _ _ l _ _ fun i => { x | p x i } theorem eventually_countable_ball {ι : Type*} {S : Set ι} (hS : S.Countable) {p : α → ∀ i ∈ S, Prop} : (∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by simpa only [Filter.Eventually, setOf_forall] using @countable_bInter_mem _ l _ _ _ hS fun i hi => { x | p x i hi } theorem EventuallyLE.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : ⋃ i, s i ≤ᶠ[l] ⋃ i, t i := (eventually_countable_forall.2 h).mono fun _ hst hs => mem_iUnion.2 <| (mem_iUnion.1 hs).imp hst theorem EventuallyEq.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : ⋃ i, s i =ᶠ[l] ⋃ i, t i := (EventuallyLE.countable_iUnion fun i => (h i).le).antisymm (EventuallyLE.countable_iUnion fun i => (h i).symm.le) theorem EventuallyLE.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by simp only [biUnion_eq_iUnion] haveI := hS.toEncodable exact EventuallyLE.countable_iUnion fun i => h i i.2 theorem EventuallyEq.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› :=
(EventuallyLE.countable_bUnion hS fun i hi => (h i hi).le).antisymm (EventuallyLE.countable_bUnion hS fun i hi => (h i hi).symm.le) theorem EventuallyLE.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : ⋂ i, s i ≤ᶠ[l] ⋂ i, t i := (eventually_countable_forall.2 h).mono fun _ hst hs =>
Mathlib/Order/Filter/CountableInter.lean
89
94
/- Copyright (c) 2023 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.Discriminant import Mathlib.RingTheory.DedekindDomain.IntegralClosure import Mathlib.NumberTheory.KummerDedekind import Mathlib.RingTheory.IntegralClosure.IntegralRestrict import Mathlib.RingTheory.Trace.Quotient /-! # The different ideal ## Main definition - `Submodule.traceDual`: The dual `L`-sub `B`-module under the trace form. - `FractionalIdeal.dual`: The dual fractional ideal under the trace form. - `differentIdeal`: The different ideal of an extension of integral domains. ## Main results - `conductor_mul_differentIdeal`: If `L = K[x]`, with `x` integral over `A`, then `𝔣 * 𝔇 = (f'(x))` with `f` being the minimal polynomial of `x`. - `aeval_derivative_mem_differentIdeal`: If `L = K[x]`, with `x` integral over `A`, then `f'(x) ∈ 𝔇` with `f` being the minimal polynomial of `x`. ## TODO - Show properties of the different ideal -/ universe u attribute [local instance] FractionRing.liftAlgebra FractionRing.isScalarTower_liftAlgebra variable (A K : Type*) {L : Type u} {B} [CommRing A] [Field K] [CommRing B] [Field L] variable [Algebra A K] [Algebra B L] [Algebra A B] [Algebra K L] [Algebra A L] variable [IsScalarTower A K L] [IsScalarTower A B L] open nonZeroDivisors IsLocalization Matrix Algebra section BIsDomain /-- Under the AKLB setting, `Iᵛ := traceDual A K (I : Submodule B L)` is the `Submodule B L` such that `x ∈ Iᵛ ↔ ∀ y ∈ I, Tr(x, y) ∈ A` -/ noncomputable def Submodule.traceDual (I : Submodule B L) : Submodule B L where __ := (traceForm K L).dualSubmodule (I.restrictScalars A) smul_mem' c x hx a ha := by rw [traceForm_apply, smul_mul_assoc, mul_comm, ← smul_mul_assoc, mul_comm] exact hx _ (Submodule.smul_mem _ c ha) variable {A K} local notation:max I:max "ᵛ" => Submodule.traceDual A K I namespace Submodule lemma mem_traceDual {I : Submodule B L} {x} : x ∈ Iᵛ ↔ ∀ a ∈ I, traceForm K L x a ∈ (algebraMap A K).range := forall₂_congr fun _ _ ↦ mem_one lemma le_traceDual_iff_map_le_one {I J : Submodule B L} : I ≤ Jᵛ ↔ ((I * J : Submodule B L).restrictScalars A).map ((trace K L).restrictScalars A) ≤ 1 := by rw [Submodule.map_le_iff_le_comap, Submodule.restrictScalars_mul, Submodule.mul_le] simp [SetLike.le_def, mem_traceDual] lemma le_traceDual_mul_iff {I J J' : Submodule B L} : I ≤ (J * J')ᵛ ↔ I * J ≤ J'ᵛ := by simp_rw [le_traceDual_iff_map_le_one, mul_assoc] lemma le_traceDual {I J : Submodule B L} : I ≤ Jᵛ ↔ I * J ≤ 1ᵛ := by rw [← le_traceDual_mul_iff, mul_one] lemma le_traceDual_comm {I J : Submodule B L} : I ≤ Jᵛ ↔ J ≤ Iᵛ := by rw [le_traceDual, mul_comm, ← le_traceDual] lemma le_traceDual_traceDual {I : Submodule B L} : I ≤ Iᵛᵛ := le_traceDual_comm.mpr le_rfl @[simp] lemma traceDual_bot : (⊥ : Submodule B L)ᵛ = ⊤ := by ext; simpa [mem_traceDual, -RingHom.mem_range] using zero_mem _ open scoped Classical in lemma traceDual_top' : (⊤ : Submodule B L)ᵛ = if ((LinearMap.range (Algebra.trace K L)).restrictScalars A ≤ 1) then ⊤ else ⊥ := by classical split_ifs with h · rw [_root_.eq_top_iff] exact fun _ _ _ _ ↦ h ⟨_, rfl⟩ · simp only [SetLike.le_def, restrictScalars_mem, LinearMap.mem_range, mem_one, forall_exists_index, forall_apply_eq_imp_iff, not_forall, not_exists] at h obtain ⟨b, hb⟩ := h simp_rw [eq_bot_iff, SetLike.le_def, mem_bot, mem_traceDual, mem_top, true_implies, traceForm_apply, RingHom.mem_range] contrapose! hb with hx' obtain ⟨c, hc, hc0⟩ := hx' simpa [hc0] using hc (c⁻¹ * b) variable [IsDomain A] [IsFractionRing A K] [FiniteDimensional K L] [Algebra.IsSeparable K L] lemma traceDual_top [Decidable (IsField A)] : (⊤ : Submodule B L)ᵛ = if IsField A then ⊤ else ⊥ := by convert traceDual_top' rw [← IsFractionRing.surjective_iff_isField (R := A) (K := K), LinearMap.range_eq_top.mpr (Algebra.trace_surjective K L), ← RingHom.range_eq_top, _root_.eq_top_iff] simp [SetLike.le_def] end Submodule open Submodule variable [IsFractionRing A K] variable (A K) in lemma map_equiv_traceDual [IsDomain A] [IsFractionRing B L] [IsDomain B] [FaithfulSMul A B] (I : Submodule B (FractionRing B)) : (traceDual A (FractionRing A) I).map (FractionRing.algEquiv B L) = traceDual A K (I.map (FractionRing.algEquiv B L)) := by show Submodule.map (FractionRing.algEquiv B L).toLinearEquiv.toLinearMap _ = traceDual A K (I.map (FractionRing.algEquiv B L).toLinearEquiv.toLinearMap) rw [Submodule.map_equiv_eq_comap_symm, Submodule.map_equiv_eq_comap_symm] ext x simp only [AlgEquiv.toLinearEquiv_symm, AlgEquiv.toLinearEquiv_toLinearMap, traceDual, traceForm_apply, Submodule.mem_comap, AlgEquiv.toLinearMap_apply, Submodule.mem_mk, AddSubmonoid.mem_mk, AddSubsemigroup.mem_mk, Set.mem_setOf_eq] apply (FractionRing.algEquiv B L).forall_congr simp only [restrictScalars_mem, traceForm_apply, AlgEquiv.toEquiv_eq_coe, EquivLike.coe_coe, mem_comap, AlgEquiv.toLinearMap_apply, AlgEquiv.symm_apply_apply] refine fun {y} ↦ (forall_congr' fun hy ↦ ?_) rw [Algebra.trace_eq_of_equiv_equiv (FractionRing.algEquiv A K).toRingEquiv (FractionRing.algEquiv B L).toRingEquiv] swap · apply IsLocalization.ringHom_ext (M := A⁰); ext simp only [AlgEquiv.toRingEquiv_eq_coe, AlgEquiv.toRingEquiv_toRingHom, RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply A B (FractionRing B), AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] simp only [AlgEquiv.toRingEquiv_eq_coe, map_mul, AlgEquiv.coe_ringEquiv, AlgEquiv.apply_symm_apply, ← AlgEquiv.symm_toRingEquiv, mem_one, AlgEquiv.algebraMap_eq_apply] variable [IsIntegrallyClosed A] lemma Submodule.mem_traceDual_iff_isIntegral {I : Submodule B L} {x} : x ∈ Iᵛ ↔ ∀ a ∈ I, IsIntegral A (traceForm K L x a) := forall₂_congr fun _ _ ↦ mem_one.trans IsIntegrallyClosed.isIntegral_iff.symm variable [FiniteDimensional K L] [IsIntegralClosure B A L] lemma Submodule.one_le_traceDual_one : (1 : Submodule B L) ≤ 1ᵛ := by rw [le_traceDual_iff_map_le_one, mul_one, one_eq_range] rintro _ ⟨x, ⟨x, rfl⟩, rfl⟩ rw [mem_one] apply IsIntegrallyClosed.isIntegral_iff.mp apply isIntegral_trace rw [IsIntegralClosure.isIntegral_iff (A := B)] exact ⟨_, rfl⟩ variable [Algebra.IsSeparable K L] /-- If `b` is an `A`-integral basis of `L` with discriminant `b`, then `d • a * x` is integral over `A` for all `a ∈ I` and `x ∈ Iᵛ`. -/ lemma isIntegral_discr_mul_of_mem_traceDual (I : Submodule B L) {ι} [DecidableEq ι] [Fintype ι] {b : Basis ι K L} (hb : ∀ i, IsIntegral A (b i)) {a x : L} (ha : a ∈ I) (hx : x ∈ Iᵛ) : IsIntegral A ((discr K b) • a * x) := by have hinv : IsUnit (traceMatrix K b).det := by simpa [← discr_def] using discr_isUnit_of_basis _ b have H := mulVec_cramer (traceMatrix K b) fun i => trace K L (x * a * b i) have : Function.Injective (traceMatrix K b).mulVec := by rwa [mulVec_injective_iff_isUnit, isUnit_iff_isUnit_det] rw [← traceMatrix_of_basis_mulVec, ← mulVec_smul, this.eq_iff, traceMatrix_of_basis_mulVec] at H rw [← b.equivFun.symm_apply_apply (_ * _), b.equivFun_symm_apply] apply IsIntegral.sum intro i _ rw [smul_mul_assoc, b.equivFun.map_smul, discr_def, mul_comm, ← H, Algebra.smul_def] refine RingHom.IsIntegralElem.mul _ ?_ (hb _) apply IsIntegral.algebraMap rw [cramer_apply] apply IsIntegral.det intros j k rw [updateCol_apply] split · rw [mul_assoc] rw [mem_traceDual_iff_isIntegral] at hx apply hx have ⟨y, hy⟩ := (IsIntegralClosure.isIntegral_iff (A := B)).mp (hb j) rw [mul_comm, ← hy, ← Algebra.smul_def] exact I.smul_mem _ (ha) · exact isIntegral_trace (RingHom.IsIntegralElem.mul _ (hb j) (hb k)) variable (A K) variable [IsDomain A] [IsFractionRing B L] [Nontrivial B] [NoZeroDivisors B] namespace FractionalIdeal open scoped Classical in /-- The dual of a non-zero fractional ideal is the dual of the submodule under the traceform. -/ noncomputable def dual (I : FractionalIdeal B⁰ L) : FractionalIdeal B⁰ L := if hI : I = 0 then 0 else ⟨Iᵛ, by classical have ⟨s, b, hb⟩ := FiniteDimensional.exists_is_basis_integral A K L obtain ⟨x, hx, hx'⟩ := exists_ne_zero_mem_isInteger hI have ⟨y, hy⟩ := (IsIntegralClosure.isIntegral_iff (A := B)).mp (IsIntegral.algebraMap (B := L) (discr_isIntegral K hb)) refine ⟨y * x, mem_nonZeroDivisors_iff_ne_zero.mpr (mul_ne_zero ?_ hx), fun z hz ↦ ?_⟩ · rw [← (IsIntegralClosure.algebraMap_injective B A L).ne_iff, hy, RingHom.map_zero, ← (algebraMap K L).map_zero, (algebraMap K L).injective.ne_iff] exact discr_not_zero_of_basis K b · convert isIntegral_discr_mul_of_mem_traceDual I hb hx' hz using 1 · ext w; exact (IsIntegralClosure.isIntegral_iff (A := B)).symm · rw [Algebra.smul_def, RingHom.map_mul, hy, ← Algebra.smul_def]⟩ end FractionalIdeal end BIsDomain variable [IsDomain A] [IsFractionRing A K] [FiniteDimensional K L] [Algebra.IsSeparable K L] [IsIntegralClosure B A L] namespace FractionalIdeal variable [IsFractionRing B L] [IsIntegrallyClosed A] open Submodule local notation:max I:max "ᵛ" => Submodule.traceDual A K I variable [IsDedekindDomain B] {I J : FractionalIdeal B⁰ L} lemma coe_dual (hI : I ≠ 0) : (dual A K I : Submodule B L) = Iᵛ := by rw [dual, dif_neg hI, coe_mk] variable (B L) @[simp] lemma coe_dual_one : (dual A K (1 : FractionalIdeal B⁰ L) : Submodule B L) = 1ᵛ := by rw [← coe_one, coe_dual] exact one_ne_zero @[simp] lemma dual_zero : dual A K (0 : FractionalIdeal B⁰ L) = 0 := by rw [dual, dif_pos rfl] variable {A K L B} lemma mem_dual (hI : I ≠ 0) {x} : x ∈ dual A K I ↔ ∀ a ∈ I, traceForm K L x a ∈ (algebraMap A K).range := by rw [dual, dif_neg hI]; exact forall₂_congr fun _ _ ↦ mem_one variable (A K) lemma dual_ne_zero (hI : I ≠ 0) : dual A K I ≠ 0 := by obtain ⟨b, hb, hb'⟩ := I.prop suffices algebraMap B L b ∈ dual A K I by intro e rw [e, mem_zero_iff, ← (algebraMap B L).map_zero, (IsIntegralClosure.algebraMap_injective B A L).eq_iff] at this exact mem_nonZeroDivisors_iff_ne_zero.mp hb this rw [mem_dual hI] intro a ha apply IsIntegrallyClosed.isIntegral_iff.mp apply isIntegral_trace dsimp convert hb' a ha using 1 · ext w exact IsIntegralClosure.isIntegral_iff (A := B) · exact (Algebra.smul_def _ _).symm variable {A K} @[simp] lemma dual_eq_zero_iff : dual A K I = 0 ↔ I = 0 := ⟨not_imp_not.mp (dual_ne_zero A K), fun e ↦ e.symm ▸ dual_zero A K L B⟩ lemma dual_ne_zero_iff : dual A K I ≠ 0 ↔ I ≠ 0 := dual_eq_zero_iff.not variable (A K) lemma le_dual_inv_aux (hI : I ≠ 0) (hIJ : I * J ≤ 1) : J ≤ dual A K I := by rw [dual, dif_neg hI] intro x hx y hy rw [mem_one] apply IsIntegrallyClosed.isIntegral_iff.mp apply isIntegral_trace rw [IsIntegralClosure.isIntegral_iff (A := B)] have ⟨z, _, hz⟩ := hIJ (FractionalIdeal.mul_mem_mul hy hx) rw [mul_comm] at hz exact ⟨z, hz⟩ lemma one_le_dual_one : 1 ≤ dual A K (1 : FractionalIdeal B⁰ L) := le_dual_inv_aux A K one_ne_zero (by rw [one_mul]) lemma le_dual_iff (hJ : J ≠ 0) : I ≤ dual A K J ↔ I * J ≤ dual A K 1 := by by_cases hI : I = 0 · simp [hI, zero_le] rw [← coe_le_coe, ← coe_le_coe, coe_mul, coe_dual A K hJ, coe_dual_one, le_traceDual] variable (I) lemma inv_le_dual : I⁻¹ ≤ dual A K I := by classical exact if hI : I = 0 then by simp [hI] else le_dual_inv_aux A K hI (le_of_eq (mul_inv_cancel₀ hI)) lemma dual_inv_le : (dual A K I)⁻¹ ≤ I := by by_cases hI : I = 0; · simp [hI] convert mul_right_mono ((dual A K I)⁻¹) (mul_left_mono I (inv_le_dual A K I)) using 1 · simp only [mul_inv_cancel₀ hI, one_mul] · simp only [mul_inv_cancel₀ (dual_ne_zero A K (hI := hI)), mul_assoc, mul_one] lemma dual_eq_mul_inv : dual A K I = dual A K 1 * I⁻¹ := by by_cases hI : I = 0; · simp [hI] apply le_antisymm · suffices dual A K I * I ≤ dual A K 1 by convert mul_right_mono I⁻¹ this using 1; simp only [mul_inv_cancel₀ hI, mul_one, mul_assoc] rw [← le_dual_iff A K hI] rw [le_dual_iff A K hI, mul_assoc, inv_mul_cancel₀ hI, mul_one] variable {I} lemma dual_div_dual : dual A K J / dual A K I = I / J := by rw [dual_eq_mul_inv A K J, dual_eq_mul_inv A K I, mul_div_mul_comm, div_self, one_mul] · exact inv_div_inv J I · simp only [ne_eq, dual_eq_zero_iff, one_ne_zero, not_false_eq_true] lemma dual_mul_self (hI : I ≠ 0) : dual A K I * I = dual A K 1 := by rw [dual_eq_mul_inv, mul_assoc, inv_mul_cancel₀ hI, mul_one] lemma self_mul_dual (hI : I ≠ 0) : I * dual A K I = dual A K 1 := by rw [mul_comm, dual_mul_self A K hI] lemma dual_inv : dual A K I⁻¹ = dual A K 1 * I := by rw [dual_eq_mul_inv, inv_inv] variable (I) @[simp] lemma dual_dual : dual A K (dual A K I) = I := by rw [dual_eq_mul_inv, dual_eq_mul_inv A K (I := I), mul_inv, inv_inv, ← mul_assoc, mul_inv_cancel₀, one_mul] rw [dual_ne_zero_iff] exact one_ne_zero variable {I} @[simp] lemma dual_le_dual (hI : I ≠ 0) (hJ : J ≠ 0) : dual A K I ≤ dual A K J ↔ J ≤ I := by nth_rewrite 2 [← dual_dual A K I] rw [le_dual_iff A K hJ, le_dual_iff A K (I := J) (by rwa [dual_ne_zero_iff]), mul_comm] variable {A K} lemma dual_involutive : Function.Involutive (dual A K : FractionalIdeal B⁰ L → FractionalIdeal B⁰ L) := dual_dual A K lemma dual_injective : Function.Injective (dual A K : FractionalIdeal B⁰ L → FractionalIdeal B⁰ L) := dual_involutive.injective end FractionalIdeal variable (B) variable [IsIntegrallyClosed A] [IsDedekindDomain B] /-- The different ideal of an extension of integral domains `B/A` is the inverse of the dual of `A` as an ideal of `B`. See `coeIdeal_differentIdeal` and `coeSubmodule_differentIdeal`. -/ def differentIdeal [NoZeroSMulDivisors A B] : Ideal B := (1 / Submodule.traceDual A (FractionRing A) 1 : Submodule B (FractionRing B)).comap (Algebra.linearMap B (FractionRing B)) lemma coeSubmodule_differentIdeal_fractionRing [NoZeroSMulDivisors A B] [Algebra.IsIntegral A B] [Algebra.IsSeparable (FractionRing A) (FractionRing B)] [FiniteDimensional (FractionRing A) (FractionRing B)] : coeSubmodule (FractionRing B) (differentIdeal A B) = 1 / Submodule.traceDual A (FractionRing A) 1 := by have : IsIntegralClosure B A (FractionRing B) := IsIntegralClosure.of_isIntegrallyClosed _ _ _ rw [coeSubmodule, differentIdeal, Submodule.map_comap_eq, inf_eq_right] have := FractionalIdeal.dual_inv_le (A := A) (K := FractionRing A) (1 : FractionalIdeal B⁰ (FractionRing B)) have : _ ≤ ((1 : FractionalIdeal B⁰ (FractionRing B)) : Submodule B (FractionRing B)) := this simp only [← one_div, FractionalIdeal.val_eq_coe] at this rw [FractionalIdeal.coe_div (FractionalIdeal.dual_ne_zero _ _ _), FractionalIdeal.coe_dual] at this · simpa only [FractionalIdeal.coe_one, Submodule.one_eq_range] using this · exact one_ne_zero · exact one_ne_zero section variable [IsFractionRing B L] lemma coeSubmodule_differentIdeal [NoZeroSMulDivisors A B] : coeSubmodule L (differentIdeal A B) = 1 / Submodule.traceDual A K 1 := by have : (FractionRing.algEquiv B L).toLinearEquiv.comp (Algebra.linearMap B (FractionRing B)) = Algebra.linearMap B L := by ext; simp rw [coeSubmodule, ← this] have H : RingHom.comp (algebraMap (FractionRing A) (FractionRing B)) ↑(FractionRing.algEquiv A K).symm.toRingEquiv = RingHom.comp ↑(FractionRing.algEquiv B L).symm.toRingEquiv (algebraMap K L) := by apply IsLocalization.ringHom_ext A⁰ ext simp only [AlgEquiv.toRingEquiv_eq_coe, RingHom.coe_comp, RingHom.coe_coe, AlgEquiv.coe_ringEquiv, Function.comp_apply, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply A B L, AlgEquiv.commutes, ← IsScalarTower.algebraMap_apply] have : Algebra.IsSeparable (FractionRing A) (FractionRing B) := Algebra.IsSeparable.of_equiv_equiv _ _ H have : FiniteDimensional (FractionRing A) (FractionRing B) := Module.Finite.of_equiv_equiv _ _ H have : Algebra.IsIntegral A B := IsIntegralClosure.isIntegral_algebra _ L simp only [AlgEquiv.toLinearEquiv_toLinearMap, Submodule.map_comp] rw [← coeSubmodule, coeSubmodule_differentIdeal_fractionRing _ _, Submodule.map_div, ← AlgEquiv.toAlgHom_toLinearMap, Submodule.map_one] congr 1
refine (map_equiv_traceDual A K _).trans ?_ congr 1 ext simp variable (L) lemma coeIdeal_differentIdeal [NoZeroSMulDivisors A B] : ↑(differentIdeal A B) = (FractionalIdeal.dual A K (1 : FractionalIdeal B⁰ L))⁻¹ := by apply FractionalIdeal.coeToSubmodule_injective simp only [FractionalIdeal.coe_div (FractionalIdeal.dual_ne_zero _ _ (@one_ne_zero (FractionalIdeal B⁰ L) _ _ _)), FractionalIdeal.coe_coeIdeal, coeSubmodule_differentIdeal A K, inv_eq_one_div, FractionalIdeal.coe_dual_one, FractionalIdeal.coe_one] variable {A K B L} open Submodule lemma differentialIdeal_le_fractionalIdeal_iff {I : FractionalIdeal B⁰ L} (hI : I ≠ 0) [NoZeroSMulDivisors A B] : differentIdeal A B ≤ I ↔ (((I⁻¹ :) : Submodule B L).restrictScalars A).map ((Algebra.trace K L).restrictScalars A) ≤ 1 := by rw [coeIdeal_differentIdeal A K L B, FractionalIdeal.inv_le_comm (by simp) hI, ← FractionalIdeal.coe_le_coe, FractionalIdeal.coe_dual_one] refine le_traceDual_iff_map_le_one.trans ?_ simp lemma differentialIdeal_le_iff {I : Ideal B} (hI : I ≠ ⊥) [NoZeroSMulDivisors A B] : differentIdeal A B ≤ I ↔ (((I⁻¹ : FractionalIdeal B⁰ L) : Submodule B L).restrictScalars A).map ((Algebra.trace K L).restrictScalars A) ≤ 1 := (FractionalIdeal.coeIdeal_le_coeIdeal _).symm.trans (differentialIdeal_le_fractionalIdeal_iff (I := (I : FractionalIdeal B⁰ L)) (by simpa)) variable (A K) open Pointwise Polynomial in lemma traceForm_dualSubmodule_adjoin {x : L} (hx : Algebra.adjoin K {x} = ⊤) (hAx : IsIntegral A x) :
Mathlib/RingTheory/DedekindDomain/Different.lean
444
482
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Topology.Category.TopCat.Limits.Pullbacks import Mathlib.Geometry.RingedSpace.LocallyRingedSpace /-! # Open immersions of structured spaces We say that a morphism of presheafed spaces `f : X ⟶ Y` is an open immersion if the underlying map of spaces is an open embedding `f : X ⟶ U ⊆ Y`, and the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. Abbreviations are also provided for `SheafedSpace`, `LocallyRingedSpace` and `Scheme`. ## Main definitions * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a PresheafedSpace hom `f` is an open_immersion. * `AlgebraicGeometry.IsOpenImmersion`: the `Prop`-valued typeclass asserting that a Scheme morphism `f` is an open_immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.isoRestrict`: The source of an open immersion is isomorphic to the restriction of the target onto the image. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.lift`: Any morphism whose range is contained in an open immersion factors though the open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toSheafedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a sheafed space, then `X` is also a sheafed space. The morphism as morphisms of sheafed spaces is given by `toSheafedSpaceHom`. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.toLocallyRingedSpace`: If `f : X ⟶ Y` is an open immersion of presheafed spaces, and `Y` is a locally ringed space, then `X` is also a locally ringed space. The morphism as morphisms of locally ringed spaces is given by `toLocallyRingedSpaceHom`. ## Main results * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.comp`: The composition of two open immersions is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso`: An iso is an open immersion. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.to_iso`: A surjective open immersion is an isomorphism. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.stalk_iso`: An open immersion induces an isomorphism on stalks. * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.hasPullback_of_left`: If `f` is an open immersion, then the pullback `(f, g)` exists (and the forgetful functor to `TopCat` preserves it). * `AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.pullbackSndOfLeft`: Open immersions are stable under pullbacks. * `AlgebraicGeometry.SheafedSpace.IsOpenImmersion.of_stalk_iso` An (topological) open embedding between two sheafed spaces is an open immersion if all the stalk maps are isomorphisms. -/ open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits namespace AlgebraicGeometry universe w v v₁ v₂ u variable {C : Type u} [Category.{v} C] /-- An open immersion of PresheafedSpaces is an open embedding `f : X ⟶ U ⊆ Y` of the underlying spaces, such that the sheaf map `Y(V) ⟶ f _* X(V)` is an iso for each `V ⊆ U`. -/ class PresheafedSpace.IsOpenImmersion {X Y : PresheafedSpace C} (f : X ⟶ Y) : Prop where /-- the underlying continuous map of underlying spaces from the source to an open subset of the target. -/ base_open : IsOpenEmbedding f.base /-- the underlying sheaf morphism is an isomorphism on each open subset -/ c_iso : ∀ U : Opens X, IsIso (f.c.app (op (base_open.isOpenMap.functor.obj U))) /-- A morphism of SheafedSpaces is an open immersion if it is an open immersion as a morphism of PresheafedSpaces -/ abbrev SheafedSpace.IsOpenImmersion {X Y : SheafedSpace C} (f : X ⟶ Y) : Prop := PresheafedSpace.IsOpenImmersion f /-- A morphism of LocallyRingedSpaces is an open immersion if it is an open immersion as a morphism of SheafedSpaces -/ abbrev LocallyRingedSpace.IsOpenImmersion {X Y : LocallyRingedSpace} (f : X ⟶ Y) : Prop := SheafedSpace.IsOpenImmersion f.1 namespace PresheafedSpace.IsOpenImmersion open PresheafedSpace local notation "IsOpenImmersion" => PresheafedSpace.IsOpenImmersion attribute [instance] IsOpenImmersion.c_iso section variable {X Y : PresheafedSpace C} (f : X ⟶ Y) [H : IsOpenImmersion f] /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor := H.base_open.isOpenMap.functor /-- An open immersion `f : X ⟶ Y` induces an isomorphism `X ≅ Y|_{f(X)}`. -/ @[simps! hom_c_app] noncomputable def isoRestrict : X ≅ Y.restrict H.base_open := PresheafedSpace.isoOfComponents (Iso.refl _) <| by symm fapply NatIso.ofComponents · intro U refine asIso (f.c.app (op (opensFunctor f |>.obj (unop U)))) ≪≫ X.presheaf.mapIso (eqToIso ?_) induction U with | op U => ?_ cases U dsimp only [IsOpenMap.functor, Functor.op, Opens.map] congr 2 erw [Set.preimage_image_eq _ H.base_open.injective] rfl · intro U V i dsimp simp only [NatTrans.naturality_assoc, TopCat.Presheaf.pushforward_obj_obj, TopCat.Presheaf.pushforward_obj_map, Quiver.Hom.unop_op, Category.assoc] rw [← X.presheaf.map_comp, ← X.presheaf.map_comp] congr 1 @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ rfl <| NatTrans.ext <| funext fun x => ?_ simp only [isoRestrict_hom_c_app, NatTrans.comp_app, eqToHom_refl, ofRestrict_c_app, Category.assoc, whiskerRight_id'] erw [Category.comp_id, comp_c_app, f.c.naturality_assoc, ← X.presheaf.map_comp] trans f.c.app x ≫ X.presheaf.map (𝟙 _) · congr 1 · simp @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := by rw [Iso.inv_comp_eq, isoRestrict_hom_ofRestrict] instance mono : Mono f := by rw [← H.isoRestrict_hom_ofRestrict]; apply mono_comp lemma c_iso' {V : Opens Y} (U : Opens X) (h : V = (opensFunctor f).obj U) : IsIso (f.c.app (Opposite.op V)) := by subst h infer_instance /-- The composition of two open immersions is an open immersion. -/ instance comp {Z : PresheafedSpace C} (g : Y ⟶ Z) [hg : IsOpenImmersion g] : IsOpenImmersion (f ≫ g) where base_open := hg.base_open.comp H.base_open c_iso U := by generalize_proofs h dsimp only [AlgebraicGeometry.PresheafedSpace.comp_c_app, unop_op, Functor.op, comp_base, Opens.map_comp_obj] apply IsIso.comp_isIso' · exact c_iso' g ((opensFunctor f).obj U) (by ext; simp) · apply c_iso' f U ext1 dsimp only [Opens.map_coe, IsOpenMap.coe_functor_obj, comp_base, TopCat.coe_comp] rw [Set.image_comp, Set.preimage_image_eq _ hg.base_open.injective] /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) ≫ inv (f.c.app (op (opensFunctor f |>.obj U))) @[simp, reassoc] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = invApp f (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := by simp only [invApp, ← Category.assoc] rw [IsIso.comp_inv_eq] simp only [Functor.op_obj, op_unop, ← X.presheaf.map_comp, Functor.op_map, Category.assoc, NatTrans.naturality, Quiver.Hom.unop_op, IsIso.inv_hom_id_assoc, TopCat.Presheaf.pushforward_obj_map] congr 1 instance (U : Opens X) : IsIso (invApp f U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [← cancel_epi (H.invApp _ U), IsIso.hom_inv_id] delta invApp simp [← Functor.map_comp] @[simp, reassoc, elementwise] theorem invApp_app (U : Opens X) : invApp f U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := by rw [invApp, Category.assoc, IsIso.inv_hom_id, Category.comp_id] @[simp, reassoc] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := by erw [← Category.assoc]; rw [IsIso.comp_inv_eq, f.c.naturality]; congr /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) : f.c.app (op U) ≫ invApp f ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom (le_antisymm (Set.image_preimage_subset f.base U.1) <| (Set.image_preimage_eq_inter_range (f := f.base) (t := U.1)).symm ▸ Set.subset_inter_iff.mpr ⟨fun _ h => h, hU⟩)).op := by erw [← Category.assoc]; rw [IsIso.comp_inv_eq, f.c.naturality]; congr /-- An isomorphism is an open immersion. -/ instance ofIso {X Y : PresheafedSpace C} (H : X ≅ Y) : IsOpenImmersion H.hom where base_open := (TopCat.homeoOfIso ((forget C).mapIso H)).isOpenEmbedding -- Porting note: `inferInstance` will fail if Lean is not told that `H.hom.c` is iso c_iso _ := letI : IsIso H.hom.c := c_isIso_of_iso H.hom; inferInstance instance (priority := 100) ofIsIso {X Y : PresheafedSpace C} (f : X ⟶ Y) [IsIso f] : IsOpenImmersion f := AlgebraicGeometry.PresheafedSpace.IsOpenImmersion.ofIso (asIso f) instance ofRestrict {X : TopCat} (Y : PresheafedSpace C) {f : X ⟶ Y.carrier} (hf : IsOpenEmbedding f) : IsOpenImmersion (Y.ofRestrict hf) where base_open := hf c_iso U := by dsimp have : (Opens.map f).obj (hf.isOpenMap.functor.obj U) = U := by ext1 exact Set.preimage_image_eq _ hf.injective convert_to IsIso (Y.presheaf.map (𝟙 _)) · congr · -- Porting note: was `apply Subsingleton.helim; rw [this]` -- See https://github.com/leanprover/lean4/issues/2273 congr · simp only [unop_op] congr apply Subsingleton.helim rw [this] · infer_instance @[elementwise, simp] theorem ofRestrict_invApp {C : Type*} [Category C] (X : PresheafedSpace C) {Y : TopCat} {f : Y ⟶ TopCat.of X.carrier} (h : IsOpenEmbedding f) (U : Opens (X.restrict h).carrier) : (PresheafedSpace.IsOpenImmersion.ofRestrict X h).invApp _ U = 𝟙 _ := by delta invApp rw [IsIso.comp_inv_eq, Category.id_comp] change X.presheaf.map _ = X.presheaf.map _ congr 1 /-- An open immersion is an iso if the underlying continuous map is epi. -/ theorem to_iso [h' : Epi f.base] : IsIso f := by have : ∀ (U : (Opens Y)ᵒᵖ), IsIso (f.c.app U) := by intro U have : U = op (opensFunctor f |>.obj ((Opens.map f.base).obj (unop U))) := by induction U with | op U => ?_ cases U dsimp only [Functor.op, Opens.map] congr exact (Set.image_preimage_eq _ ((TopCat.epi_iff_surjective _).mp h')).symm convert H.c_iso (Opens.map f.base |>.obj <| unop U) have : IsIso f.c := NatIso.isIso_of_isIso_app _ apply (config := { allowSynthFailures := true }) isIso_of_components let t : X ≃ₜ Y := H.base_open.isEmbedding.toHomeomorph.trans { toFun := Subtype.val invFun := fun x => ⟨x, by rw [Set.range_eq_univ.mpr ((TopCat.epi_iff_surjective _).mp h')]; trivial⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun _ => rfl } exact (TopCat.isoOfHomeo t).isIso_hom instance stalk_iso [HasColimits C] (x : X) : IsIso (f.stalkMap x) := by rw [← H.isoRestrict_hom_ofRestrict, PresheafedSpace.stalkMap.comp] infer_instance end noncomputable section Pullback variable {X Y Z : PresheafedSpace C} (f : X ⟶ Z) [hf : IsOpenImmersion f] (g : Y ⟶ Z) /-- (Implementation.) The projection map when constructing the pullback along an open immersion. -/ def pullbackConeOfLeftFst : Y.restrict (TopCat.snd_isOpenEmbedding_of_left hf.base_open g.base) ⟶ X where base := pullback.fst _ _ c := { app := fun U => hf.invApp _ (unop U) ≫ g.c.app (op (hf.base_open.isOpenMap.functor.obj (unop U))) ≫ Y.presheaf.map (eqToHom (by simp only [IsOpenMap.functor, Subtype.mk_eq_mk, unop_op, op_inj_iff, Opens.map, Subtype.coe_mk, Functor.op_obj] apply LE.le.antisymm · rintro _ ⟨_, h₁, h₂⟩ use (TopCat.pullbackIsoProdSubtype _ _).inv ⟨⟨_, _⟩, h₂⟩ -- Porting note: need a slight hand holding -- used to be `simpa using h₁` before https://github.com/leanprover-community/mathlib4/pull/13170 change _ ∈ _ ⁻¹' _ ∧ _ simp only [TopCat.coe_of, restrict_carrier, Set.preimage_id', Set.mem_preimage, SetLike.mem_coe] constructor · change _ ∈ U.unop at h₁ convert h₁ rw [TopCat.pullbackIsoProdSubtype_inv_fst_apply] · rw [TopCat.pullbackIsoProdSubtype_inv_snd_apply] · rintro _ ⟨x, h₁, rfl⟩ exact ⟨_, h₁, CategoryTheory.congr_fun pullback.condition x⟩)) naturality := by intro U V i induction U induction V -- Note: this doesn't fire in `simp` because of reduction of the term via structure eta -- before discrimination tree key generation rw [inv_naturality_assoc] dsimp simp only [NatTrans.naturality_assoc, TopCat.Presheaf.pushforward_obj_map, Quiver.Hom.unop_op, ← Functor.map_comp, Category.assoc] rfl } theorem pullback_cone_of_left_condition : pullbackConeOfLeftFst f g ≫ f = Y.ofRestrict _ ≫ g := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ ?_ <| NatTrans.ext <| funext fun U => ?_ · simpa using pullback.condition · induction U -- Porting note: `NatTrans.comp_app` is not picked up by `dsimp` -- Perhaps see : https://github.com/leanprover-community/mathlib4/issues/5026 rw [NatTrans.comp_app] dsimp only [comp_c_app, unop_op, whiskerRight_app, pullbackConeOfLeftFst] -- simp only [ofRestrict_c_app, NatTrans.comp_app] simp only [app_invApp_assoc, eqToHom_app, Category.assoc, NatTrans.naturality_assoc] erw [← Y.presheaf.map_comp, ← Y.presheaf.map_comp] congr 1 /-- We construct the pullback along an open immersion via restricting along the pullback of the maps of underlying spaces (which is also an open embedding). -/ def pullbackConeOfLeft : PullbackCone f g := PullbackCone.mk (pullbackConeOfLeftFst f g) (Y.ofRestrict _) (pullback_cone_of_left_condition f g) variable (s : PullbackCone f g) /-- (Implementation.) Any cone over `cospan f g` indeed factors through the constructed cone. -/ def pullbackConeOfLeftLift : s.pt ⟶ (pullbackConeOfLeft f g).pt where base := pullback.lift s.fst.base s.snd.base (congr_arg (fun x => PresheafedSpace.Hom.base x) s.condition) c := { app := fun U => s.snd.c.app _ ≫ s.pt.presheaf.map (eqToHom (by dsimp only [Opens.map, IsOpenMap.functor, Functor.op] congr 2 let s' : PullbackCone f.base g.base := PullbackCone.mk s.fst.base s.snd.base -- Porting note: in mathlib3, this is just an underscore (congr_arg Hom.base s.condition) have : _ = s.snd.base := limit.lift_π s' WalkingCospan.right conv_lhs => rw [← this] dsimp [s'] rw [Function.comp_def, ← Set.preimage_preimage] rw [Set.preimage_image_eq _ (TopCat.snd_isOpenEmbedding_of_left hf.base_open g.base).injective] rfl)) naturality := fun U V i => by erw [s.snd.c.naturality_assoc] rw [Category.assoc] erw [← s.pt.presheaf.map_comp, ← s.pt.presheaf.map_comp] congr 1 } -- this lemma is not a `simp` lemma, because it is an implementation detail theorem pullbackConeOfLeftLift_fst : pullbackConeOfLeftLift f g s ≫ (pullbackConeOfLeft f g).fst = s.fst := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ ?_ <| NatTrans.ext <| funext fun x => ?_ · change pullback.lift _ _ _ ≫ pullback.fst _ _ = _ simp · induction x with | op x => ?_ change ((_ ≫ _) ≫ _ ≫ _) ≫ _ = _ simp_rw [Category.assoc] erw [← s.pt.presheaf.map_comp] erw [s.snd.c.naturality_assoc] have := congr_app s.condition (op (opensFunctor f |>.obj x)) dsimp only [comp_c_app, unop_op] at this rw [← IsIso.comp_inv_eq] at this replace this := reassoc_of% this erw [← this, hf.invApp_app_assoc, s.fst.c.naturality_assoc] simp [eqToHom_map] -- this lemma is not a `simp` lemma, because it is an implementation detail theorem pullbackConeOfLeftLift_snd : pullbackConeOfLeftLift f g s ≫ (pullbackConeOfLeft f g).snd = s.snd := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `NatTrans.ext` refine PresheafedSpace.Hom.ext _ _ ?_ <| NatTrans.ext <| funext fun x => ?_ · change pullback.lift _ _ _ ≫ pullback.snd _ _ = _ simp · change (_ ≫ _ ≫ _) ≫ _ = _ simp_rw [Category.assoc] erw [s.snd.c.naturality_assoc] erw [← s.pt.presheaf.map_comp, ← s.pt.presheaf.map_comp] trans s.snd.c.app x ≫ s.pt.presheaf.map (𝟙 _) · congr 1 · simp instance pullbackConeSndIsOpenImmersion : IsOpenImmersion (pullbackConeOfLeft f g).snd := by erw [CategoryTheory.Limits.PullbackCone.mk_snd] infer_instance /-- The constructed pullback cone is indeed the pullback. -/ def pullbackConeOfLeftIsLimit : IsLimit (pullbackConeOfLeft f g) := by apply PullbackCone.isLimitAux' intro s use pullbackConeOfLeftLift f g s use pullbackConeOfLeftLift_fst f g s use pullbackConeOfLeftLift_snd f g s intro m _ h₂ rw [← cancel_mono (pullbackConeOfLeft f g).snd] exact h₂.trans (pullbackConeOfLeftLift_snd f g s).symm instance hasPullback_of_left : HasPullback f g := ⟨⟨⟨_, pullbackConeOfLeftIsLimit f g⟩⟩⟩ instance hasPullback_of_right : HasPullback g f := hasPullback_symmetry f g /-- Open immersions are stable under base-change. -/ instance pullbackSndOfLeft : IsOpenImmersion (pullback.snd f g) := by delta pullback.snd rw [← limit.isoLimitCone_hom_π ⟨_, pullbackConeOfLeftIsLimit f g⟩ WalkingCospan.right] infer_instance /-- Open immersions are stable under base-change. -/ instance pullbackFstOfRight : IsOpenImmersion (pullback.fst g f) := by rw [← pullbackSymmetry_hom_comp_snd] infer_instance instance pullbackToBaseIsOpenImmersion [IsOpenImmersion g] : IsOpenImmersion (limit.π (cospan f g) WalkingCospan.one) := by rw [← limit.w (cospan f g) WalkingCospan.Hom.inl, cospan_map_inl] infer_instance instance forget_preservesLimitsOfLeft : PreservesLimit (cospan f g) (forget C) := preservesLimit_of_preserves_limit_cone (pullbackConeOfLeftIsLimit f g) (by apply (IsLimit.postcomposeHomEquiv (diagramIsoCospan _) _).toFun refine (IsLimit.equivIsoLimit ?_).toFun (limit.isLimit (cospan f.base g.base)) fapply Cones.ext · exact Iso.refl _ change ∀ j, _ = 𝟙 _ ≫ _ ≫ _ simp_rw [Category.id_comp] rintro (_ | _ | _) <;> symm · erw [Category.comp_id] exact limit.w (cospan f.base g.base) WalkingCospan.Hom.inl · exact Category.comp_id _ · exact Category.comp_id _) instance forget_preservesLimitsOfRight : PreservesLimit (cospan g f) (forget C) := preservesPullback_symmetry (forget C) f g theorem pullback_snd_isIso_of_range_subset (H : Set.range g.base ⊆ Set.range f.base) : IsIso (pullback.snd f g) := by haveI := TopCat.snd_iso_of_left_embedding_range_subset hf.base_open.isEmbedding g.base H have : IsIso (pullback.snd f g).base := by delta pullback.snd rw [← limit.isoLimitCone_hom_π ⟨_, pullbackConeOfLeftIsLimit f g⟩ WalkingCospan.right] change IsIso (_ ≫ pullback.snd _ _) infer_instance apply to_iso /-- The universal property of open immersions: For an open immersion `f : X ⟶ Z`, given any morphism of schemes `g : Y ⟶ Z` whose topological image is contained in the image of `f`, we can lift this morphism to a unique `Y ⟶ X` that commutes with these maps. -/ def lift (H : Set.range g.base ⊆ Set.range f.base) : Y ⟶ X := haveI := pullback_snd_isIso_of_range_subset f g H inv (pullback.snd f g) ≫ pullback.fst _ _ @[simp, reassoc] theorem lift_fac (H : Set.range g.base ⊆ Set.range f.base) : lift f g H ≫ f = g := by erw [Category.assoc]; rw [IsIso.inv_comp_eq]; exact pullback.condition theorem lift_uniq (H : Set.range g.base ⊆ Set.range f.base) (l : Y ⟶ X) (hl : l ≫ f = g) : l = lift f g H := by rw [← cancel_mono f, hl, lift_fac] /-- Two open immersions with equal range is isomorphic. -/ @[simps] def isoOfRangeEq [IsOpenImmersion g] (e : Set.range f.base = Set.range g.base) : X ≅ Y where hom := lift g f (le_of_eq e) inv := lift f g (le_of_eq e.symm) hom_inv_id := by rw [← cancel_mono f]; simp inv_hom_id := by rw [← cancel_mono g]; simp end Pullback open CategoryTheory.Limits.WalkingCospan section ToSheafedSpace variable {X : PresheafedSpace C} (Y : SheafedSpace C) /-- If `X ⟶ Y` is an open immersion, and `Y` is a SheafedSpace, then so is `X`. -/ def toSheafedSpace (f : X ⟶ Y.toPresheafedSpace) [H : IsOpenImmersion f] : SheafedSpace C where IsSheaf := by apply TopCat.Presheaf.isSheaf_of_iso (sheafIsoOfIso (isoRestrict f).symm).symm apply TopCat.Sheaf.pushforward_sheaf_of_sheaf exact (Y.restrict H.base_open).IsSheaf toPresheafedSpace := X variable (f : X ⟶ Y.toPresheafedSpace) [H : IsOpenImmersion f] @[simp] theorem toSheafedSpace_toPresheafedSpace : (toSheafedSpace Y f).toPresheafedSpace = X := rfl /-- If `X ⟶ Y` is an open immersion of PresheafedSpaces, and `Y` is a SheafedSpace, we can upgrade it into a morphism of SheafedSpaces. -/ def toSheafedSpaceHom : toSheafedSpace Y f ⟶ Y := f @[simp] theorem toSheafedSpaceHom_base : (toSheafedSpaceHom Y f).base = f.base := rfl @[simp] theorem toSheafedSpaceHom_c : (toSheafedSpaceHom Y f).c = f.c := rfl instance toSheafedSpace_isOpenImmersion : SheafedSpace.IsOpenImmersion (toSheafedSpaceHom Y f) := H @[simp] theorem sheafedSpace_toSheafedSpace {X Y : SheafedSpace C} (f : X ⟶ Y) [IsOpenImmersion f] : toSheafedSpace Y f = X := by cases X; rfl end ToSheafedSpace section ToLocallyRingedSpace variable {X : PresheafedSpace CommRingCat} (Y : LocallyRingedSpace) variable (f : X ⟶ Y.toPresheafedSpace) [H : IsOpenImmersion f] /-- If `X ⟶ Y` is an open immersion, and `Y` is a LocallyRingedSpace, then so is `X`. -/ def toLocallyRingedSpace : LocallyRingedSpace where toSheafedSpace := toSheafedSpace Y.toSheafedSpace f isLocalRing x := haveI : IsLocalRing (Y.presheaf.stalk (f.base x)) := Y.isLocalRing _ (asIso (f.stalkMap x)).commRingCatIsoToRingEquiv.isLocalRing @[simp] theorem toLocallyRingedSpace_toSheafedSpace : (toLocallyRingedSpace Y f).toSheafedSpace = toSheafedSpace Y.1 f := rfl /-- If `X ⟶ Y` is an open immersion of PresheafedSpaces, and `Y` is a LocallyRingedSpace, we can upgrade it into a morphism of LocallyRingedSpace. -/ def toLocallyRingedSpaceHom : toLocallyRingedSpace Y f ⟶ Y := ⟨f, fun _ => inferInstance⟩ @[simp] theorem toLocallyRingedSpaceHom_val : (toLocallyRingedSpaceHom Y f).toShHom = f := rfl instance toLocallyRingedSpace_isOpenImmersion : LocallyRingedSpace.IsOpenImmersion (toLocallyRingedSpaceHom Y f) := H @[simp] theorem locallyRingedSpace_toLocallyRingedSpace {X Y : LocallyRingedSpace} (f : X ⟶ Y) [LocallyRingedSpace.IsOpenImmersion f] : toLocallyRingedSpace Y f.1 = X := by cases X; delta toLocallyRingedSpace; simp end ToLocallyRingedSpace theorem isIso_of_subset {X Y : PresheafedSpace C} (f : X ⟶ Y) [H : PresheafedSpace.IsOpenImmersion f] (U : Opens Y.carrier) (hU : (U : Set Y.carrier) ⊆ Set.range f.base) : IsIso (f.c.app <| op U) := by have : U = H.base_open.isOpenMap.functor.obj ((Opens.map f.base).obj U) := by ext1 exact (Set.inter_eq_left.mpr hU).symm.trans Set.image_preimage_eq_inter_range.symm convert H.c_iso ((Opens.map f.base).obj U) end PresheafedSpace.IsOpenImmersion namespace SheafedSpace.IsOpenImmersion instance (priority := 100) of_isIso {X Y : SheafedSpace C} (f : X ⟶ Y) [IsIso f] : SheafedSpace.IsOpenImmersion f := @PresheafedSpace.IsOpenImmersion.ofIsIso _ _ _ _ f (SheafedSpace.forgetToPresheafedSpace.map_isIso _) instance comp {X Y Z : SheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) [SheafedSpace.IsOpenImmersion f] [SheafedSpace.IsOpenImmersion g] : SheafedSpace.IsOpenImmersion (f ≫ g) := PresheafedSpace.IsOpenImmersion.comp f g noncomputable section Pullback variable {X Y Z : SheafedSpace C} (f : X ⟶ Z) (g : Y ⟶ Z) variable [H : SheafedSpace.IsOpenImmersion f] -- Porting note: in mathlib3, this local notation is often followed by a space to avoid confusion -- with the forgetful functor, now it is often wrapped in a parenthesis local notation "forget" => SheafedSpace.forgetToPresheafedSpace open CategoryTheory.Limits.WalkingCospan instance : Mono f := (forget).mono_of_mono_map (show @Mono (PresheafedSpace C) _ _ _ f by infer_instance) instance forgetMapIsOpenImmersion : PresheafedSpace.IsOpenImmersion ((forget).map f) := ⟨H.base_open, H.c_iso⟩ instance hasLimit_cospan_forget_of_left : HasLimit (cospan f g ⋙ forget) := by have : HasLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) := by change HasLimit (cospan ((forget).map f) ((forget).map g)) infer_instance apply hasLimit_of_iso (diagramIsoCospan _).symm instance hasLimit_cospan_forget_of_left' : HasLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map f) ((forget).map g)) from inferInstance instance hasLimit_cospan_forget_of_right : HasLimit (cospan g f ⋙ forget) := by have : HasLimit (cospan ((cospan g f ⋙ forget).map Hom.inl) ((cospan g f ⋙ forget).map Hom.inr)) := by change HasLimit (cospan ((forget).map g) ((forget).map f)) infer_instance apply hasLimit_of_iso (diagramIsoCospan _).symm instance hasLimit_cospan_forget_of_right' : HasLimit (cospan ((cospan g f ⋙ forget).map Hom.inl) ((cospan g f ⋙ forget).map Hom.inr)) := show HasLimit (cospan ((forget).map g) ((forget).map f)) from inferInstance instance forgetCreatesPullbackOfLeft : CreatesLimit (cospan f g) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toSheafedSpace Y (@pullback.snd (PresheafedSpace C) _ _ _ _ f g _)) (eqToIso (show pullback _ _ = pullback _ _ by congr) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) instance forgetCreatesPullbackOfRight : CreatesLimit (cospan g f) forget := createsLimitOfFullyFaithfulOfIso (PresheafedSpace.IsOpenImmersion.toSheafedSpace Y (@pullback.fst (PresheafedSpace C) _ _ _ _ g f _)) (eqToIso (show pullback _ _ = pullback _ _ by congr) ≪≫ HasLimit.isoOfNatIso (diagramIsoCospan _).symm) instance sheafedSpace_forgetPreserves_of_left : PreservesLimit (cospan f g) (SheafedSpace.forget C) := @Limits.comp_preservesLimit _ _ _ _ _ _ (cospan f g) _ _ forget (PresheafedSpace.forget C) inferInstance <| by have : PreservesLimit (cospan ((cospan f g ⋙ forget).map Hom.inl) ((cospan f g ⋙ forget).map Hom.inr)) (PresheafedSpace.forget C) := by dsimp infer_instance apply preservesLimit_of_iso_diagram _ (diagramIsoCospan _).symm instance sheafedSpace_forgetPreserves_of_right : PreservesLimit (cospan g f) (SheafedSpace.forget C) := preservesPullback_symmetry _ _ _ instance sheafedSpace_hasPullback_of_left : HasPullback f g := hasLimit_of_created (cospan f g) forget instance sheafedSpace_hasPullback_of_right : HasPullback g f := hasLimit_of_created (cospan g f) forget /-- Open immersions are stable under base-change. -/ instance sheafedSpace_pullback_snd_of_left : SheafedSpace.IsOpenImmersion (pullback.snd f g) := by delta pullback.snd have : _ = limit.π (cospan f g) right := preservesLimitIso_hom_π forget (cospan f g) right rw [← this] have := HasLimit.isoOfNatIso_hom_π (diagramIsoCospan (cospan f g ⋙ forget)) right erw [Category.comp_id] at this rw [← this] dsimp infer_instance instance sheafedSpace_pullback_fst_of_right : SheafedSpace.IsOpenImmersion (pullback.fst g f) := by delta pullback.fst have : _ = limit.π (cospan g f) left := preservesLimitIso_hom_π forget (cospan g f) left rw [← this] have := HasLimit.isoOfNatIso_hom_π (diagramIsoCospan (cospan g f ⋙ forget)) left erw [Category.comp_id] at this rw [← this] dsimp infer_instance instance sheafedSpace_pullback_to_base_isOpenImmersion [SheafedSpace.IsOpenImmersion g] : SheafedSpace.IsOpenImmersion (limit.π (cospan f g) one : pullback f g ⟶ Z) := by rw [← limit.w (cospan f g) Hom.inl, cospan_map_inl] infer_instance end Pullback section OfStalkIso variable [HasLimits C] [HasColimits C] {FC : C → C → Type*} {CC : C → Type v} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [instCC : ConcreteCategory.{v} C FC] variable [(CategoryTheory.forget C).ReflectsIsomorphisms] [PreservesLimits (CategoryTheory.forget C)] variable [PreservesFilteredColimits (CategoryTheory.forget C)] include instCC in /-- Suppose `X Y : SheafedSpace C`, where `C` is a concrete category, whose forgetful functor reflects isomorphisms, preserves limits and filtered colimits. Then a morphism `X ⟶ Y` that is a topological open embedding is an open immersion iff every stalk map is an iso. -/ theorem of_stalk_iso {X Y : SheafedSpace C} (f : X ⟶ Y) (hf : IsOpenEmbedding f.base) [H : ∀ x : X.1, IsIso (f.stalkMap x)] : SheafedSpace.IsOpenImmersion f := { base_open := hf c_iso := fun U => by apply (config := {allowSynthFailures := true}) TopCat.Presheaf.app_isIso_of_stalkFunctor_map_iso (show Y.sheaf ⟶ (TopCat.Sheaf.pushforward _ f.base).obj X.sheaf from ⟨f.c⟩) rintro ⟨_, y, hy, rfl⟩ specialize H y delta PresheafedSpace.Hom.stalkMap at H haveI H' := TopCat.Presheaf.stalkPushforward.stalkPushforward_iso_of_isInducing C hf.toIsInducing X.presheaf y have := IsIso.comp_isIso' H (@IsIso.inv_isIso _ _ _ _ _ H') rwa [Category.assoc, IsIso.hom_inv_id, Category.comp_id] at this } end OfStalkIso section variable {X Y : SheafedSpace C} (f : X ⟶ Y) [H : IsOpenImmersion f] /-- The functor `Opens X ⥤ Opens Y` associated with an open immersion `f : X ⟶ Y`. -/ abbrev opensFunctor : Opens X ⥤ Opens Y := H.base_open.isOpenMap.functor /-- An open immersion `f : X ⟶ Y` induces an isomorphism `X ≅ Y|_{f(X)}`. -/ @[simps! hom_c_app] noncomputable def isoRestrict : X ≅ Y.restrict H.base_open := SheafedSpace.isoMk <| PresheafedSpace.IsOpenImmersion.isoRestrict f @[reassoc (attr := simp)] theorem isoRestrict_hom_ofRestrict : (isoRestrict f).hom ≫ Y.ofRestrict _ = f := PresheafedSpace.IsOpenImmersion.isoRestrict_hom_ofRestrict f @[reassoc (attr := simp)] theorem isoRestrict_inv_ofRestrict : (isoRestrict f).inv ≫ f = Y.ofRestrict _ := PresheafedSpace.IsOpenImmersion.isoRestrict_inv_ofRestrict f /-- For an open immersion `f : X ⟶ Y` and an open set `U ⊆ X`, we have the map `X(U) ⟶ Y(U)`. -/ noncomputable def invApp (U : Opens X) : X.presheaf.obj (op U) ⟶ Y.presheaf.obj (op (opensFunctor f |>.obj U)) := PresheafedSpace.IsOpenImmersion.invApp f U @[reassoc (attr := simp)] theorem inv_naturality {U V : (Opens X)ᵒᵖ} (i : U ⟶ V) : X.presheaf.map i ≫ H.invApp _ (unop V) = H.invApp _ (unop U) ≫ Y.presheaf.map (opensFunctor f |>.op.map i) := PresheafedSpace.IsOpenImmersion.inv_naturality f i instance (U : Opens X) : IsIso (H.invApp _ U) := by delta invApp; infer_instance theorem inv_invApp (U : Opens X) : inv (H.invApp _ U) = f.c.app (op (opensFunctor f |>.obj U)) ≫ X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := PresheafedSpace.IsOpenImmersion.inv_invApp f U @[reassoc (attr := simp)] theorem invApp_app (U : Opens X) : H.invApp _ U ≫ f.c.app (op (opensFunctor f |>.obj U)) = X.presheaf.map (eqToHom (by simp [Opens.map, Set.preimage_image_eq _ H.base_open.injective])) := PresheafedSpace.IsOpenImmersion.invApp_app f U attribute [elementwise] invApp_app @[reassoc (attr := simp)] theorem app_invApp (U : Opens Y) : f.c.app (op U) ≫ H.invApp _ ((Opens.map f.base).obj U) = Y.presheaf.map ((homOfLE (Set.image_preimage_subset f.base U.1)).op : op U ⟶ op (opensFunctor f |>.obj ((Opens.map f.base).obj U))) := PresheafedSpace.IsOpenImmersion.app_invApp f U /-- A variant of `app_inv_app` that gives an `eqToHom` instead of `homOfLe`. -/ @[reassoc] theorem app_inv_app' (U : Opens Y) (hU : (U : Set Y) ⊆ Set.range f.base) : f.c.app (op U) ≫ invApp f ((Opens.map f.base).obj U) = Y.presheaf.map (eqToHom <| le_antisymm (Set.image_preimage_subset f.base U.1) <| (Set.image_preimage_eq_inter_range (f := f.base) (t := U.1)).symm ▸ Set.subset_inter_iff.mpr ⟨fun _ h => h, hU⟩).op := PresheafedSpace.IsOpenImmersion.app_invApp f U instance ofRestrict {X : TopCat} (Y : SheafedSpace C) {f : X ⟶ Y.carrier} (hf : IsOpenEmbedding f) : IsOpenImmersion (Y.ofRestrict hf) := PresheafedSpace.IsOpenImmersion.ofRestrict _ hf @[elementwise, simp] theorem ofRestrict_invApp {C : Type*} [Category C] (X : SheafedSpace C) {Y : TopCat} {f : Y ⟶ TopCat.of X.carrier} (h : IsOpenEmbedding f) (U : Opens (X.restrict h).carrier) : (SheafedSpace.IsOpenImmersion.ofRestrict X h).invApp _ U = 𝟙 _ := PresheafedSpace.IsOpenImmersion.ofRestrict_invApp _ h U /-- An open immersion is an iso if the underlying continuous map is epi. -/ theorem to_iso [h' : Epi f.base] : IsIso f := by haveI : IsIso (forgetToPresheafedSpace.map f) := PresheafedSpace.IsOpenImmersion.to_iso f apply isIso_of_reflects_iso _ (SheafedSpace.forgetToPresheafedSpace) instance stalk_iso [HasColimits C] (x : X) : IsIso (f.stalkMap x) := PresheafedSpace.IsOpenImmersion.stalk_iso f x end section Prod -- Porting note: here `ι` should have same universe level as morphism of `C`, so needs explicit -- universe level now variable [HasLimits C] {ι : Type v} (F : Discrete ι ⥤ SheafedSpace.{_, v, v} C) [HasColimit F] (i : Discrete ι) theorem sigma_ι_isOpenEmbedding : IsOpenEmbedding (colimit.ι F i).base := by rw [← show _ = (colimit.ι F i).base from ι_preservesColimitIso_inv (SheafedSpace.forget C) F i] have : _ = _ ≫ colimit.ι (Discrete.functor ((F ⋙ SheafedSpace.forget C).obj ∘ Discrete.mk)) i := HasColimit.isoOfNatIso_ι_hom Discrete.natIsoFunctor i rw [← Iso.eq_comp_inv] at this rw [this] have : colimit.ι _ _ ≫ _ = _ := TopCat.sigmaIsoSigma_hom_ι.{v, v} ((F ⋙ SheafedSpace.forget C).obj ∘ Discrete.mk) i.as rw [← Iso.eq_comp_inv] at this cases i rw [this, ← Category.assoc] -- Porting note: `simp_rw` can't use `TopCat.isOpenEmbedding_iff_comp_isIso` and -- `TopCat.isOpenEmbedding_iff_isIso_comp`. -- See https://github.com/leanprover-community/mathlib4/issues/5026 rw [TopCat.isOpenEmbedding_iff_comp_isIso, TopCat.isOpenEmbedding_iff_comp_isIso, TopCat.isOpenEmbedding_iff_comp_isIso, TopCat.isOpenEmbedding_iff_isIso_comp] exact .sigmaMk theorem image_preimage_is_empty (j : Discrete ι) (h : i ≠ j) (U : Opens (F.obj i)) : (Opens.map (colimit.ι (F ⋙ SheafedSpace.forgetToPresheafedSpace) j).base).obj ((Opens.map (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv.base).obj ((sigma_ι_isOpenEmbedding F i).isOpenMap.functor.obj U)) = ⊥ := by ext x apply iff_false_intro rintro ⟨y, hy, eq⟩ replace eq := ConcreteCategory.congr_arg (preservesColimitIso (SheafedSpace.forget C) F ≪≫ HasColimit.isoOfNatIso Discrete.natIsoFunctor ≪≫ TopCat.sigmaIsoSigma.{v, v} _).hom eq simp_rw [CategoryTheory.Iso.trans_hom, ← TopCat.comp_app, ← PresheafedSpace.comp_base] at eq rw [ι_preservesColimitIso_inv] at eq change ((SheafedSpace.forget C).map (colimit.ι F i) ≫ _) y = ((SheafedSpace.forget C).map (colimit.ι F j) ≫ _) x at eq cases i; cases j rw [ι_preservesColimitIso_hom_assoc, ι_preservesColimitIso_hom_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, HasColimit.isoOfNatIso_ι_hom_assoc, TopCat.sigmaIsoSigma_hom_ι, TopCat.sigmaIsoSigma_hom_ι] at eq exact h (congr_arg Discrete.mk (congr_arg Sigma.fst eq)) instance sigma_ι_isOpenImmersion_aux [HasStrictTerminalObjects C] : SheafedSpace.IsOpenImmersion (colimit.ι F i) where base_open := sigma_ι_isOpenEmbedding F i c_iso U := by have e : colimit.ι F i = _ := (ι_preservesColimitIso_inv SheafedSpace.forgetToPresheafedSpace F i).symm have H : IsOpenEmbedding (colimit.ι (F ⋙ SheafedSpace.forgetToPresheafedSpace) i ≫ (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv).base := e ▸ sigma_ι_isOpenEmbedding F i suffices IsIso <| (colimit.ι (F ⋙ SheafedSpace.forgetToPresheafedSpace) i ≫ (preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv).c.app <| op (H.isOpenMap.functor.obj U) by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): just `convert` is very slow, so helps it a bit convert this using 2 <;> congr rw [PresheafedSpace.comp_c_app, ← PresheafedSpace.colimitPresheafObjIsoComponentwiseLimit_hom_π] -- Porting note: this instance created manually to make the `inferInstance` below work have inst1 : IsIso (preservesColimitIso forgetToPresheafedSpace F).inv.c := PresheafedSpace.c_isIso_of_iso _ rsuffices : IsIso (limit.π (PresheafedSpace.componentwiseDiagram (F ⋙ SheafedSpace.forgetToPresheafedSpace) ((Opens.map
(preservesColimitIso SheafedSpace.forgetToPresheafedSpace F).inv.base).obj (unop <| op <| H.isOpenMap.functor.obj U))) (op i))
Mathlib/Geometry/RingedSpace/OpenImmersion.lean
905
907
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Data.Matrix.ConjTranspose /-! # Row and column matrices This file provides results about row and column matrices. ## Main definitions * `Matrix.replicateRow ι r : Matrix ι n α`: the matrix where every row is the vector `r : n → α` * `Matrix.replicateCol ι c : Matrix m ι α`: the matrix where every column is the vector `c : m → α` * `Matrix.updateRow M i r`: update the `i`th row of `M` to `r` * `Matrix.updateCol M j c`: update the `j`th column of `M` to `c` -/ variable {l m n o : Type*} universe u v w variable {R : Type*} {α : Type v} {β : Type w} namespace Matrix /-- `Matrix.replicateCol ι u` is the matrix with all columns equal to the vector `u`. To get a column matrix with exactly one column, `Matrix.replicateCol (Fin 1) u` is the canonical choice. -/ def replicateCol (ι : Type*) (w : m → α) : Matrix m ι α := of fun x _ => w x -- TODO: set as an equation lemma for `replicateCol`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem replicateCol_apply {ι : Type*} (w : m → α) (i) (j : ι) : replicateCol ι w i j = w i := rfl /-- `Matrix.replicateRow ι u` is the matrix with all rows equal to the vector `u`. To get a row matrix with exactly one row, `Matrix.replicateRow (Fin 1) u` is the canonical choice. -/ def replicateRow (ι : Type*) (v : n → α) : Matrix ι n α := of fun _ y => v y variable {ι : Type*} -- TODO: set as an equation lemma for `replicateRow`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem replicateRow_apply (v : n → α) (i : ι) (j) : replicateRow ι v i j = v j := rfl theorem replicateCol_injective [Nonempty ι] : Function.Injective (replicateCol ι : (m → α) → Matrix m ι α) := by inhabit ι exact fun _x _y h => funext fun i => congr_fun₂ h i default @[deprecated (since := "2025-03-20")] alias col_injective := replicateCol_injective @[simp] theorem replicateCol_inj [Nonempty ι] {v w : m → α} : replicateCol ι v = replicateCol ι w ↔ v = w := replicateCol_injective.eq_iff @[deprecated (since := "2025-03-20")] alias col_inj := replicateCol_inj @[simp] theorem replicateCol_zero [Zero α] : replicateCol ι (0 : m → α) = 0 := rfl @[deprecated (since := "2025-03-20")] alias col_zero := replicateCol_zero @[simp] theorem replicateCol_eq_zero [Zero α] [Nonempty ι] (v : m → α) : replicateCol ι v = 0 ↔ v = 0 := replicateCol_inj @[deprecated (since := "2025-03-20")] alias col_eq_zero := replicateCol_eq_zero @[simp] theorem replicateCol_add [Add α] (v w : m → α) : replicateCol ι (v + w) = replicateCol ι v + replicateCol ι w := by ext rfl @[deprecated (since := "2025-03-20")] alias col_add := replicateCol_add @[simp] theorem replicateCol_smul [SMul R α] (x : R) (v : m → α) : replicateCol ι (x • v) = x • replicateCol ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias col_smul := replicateCol_smul theorem replicateRow_injective [Nonempty ι] : Function.Injective (replicateRow ι : (n → α) → Matrix ι n α) := by inhabit ι exact fun _x _y h => funext fun j => congr_fun₂ h default j @[deprecated (since := "2025-03-20")] alias row_injective := replicateRow_injective @[simp] theorem replicateRow_inj [Nonempty ι] {v w : n → α} : replicateRow ι v = replicateRow ι w ↔ v = w := replicateRow_injective.eq_iff @[simp] theorem replicateRow_zero [Zero α] : replicateRow ι (0 : n → α) = 0 := rfl @[deprecated (since := "2025-03-20")] alias row_zero := replicateRow_zero @[simp] theorem replicateRow_eq_zero [Zero α] [Nonempty ι] (v : n → α) : replicateRow ι v = 0 ↔ v = 0 := replicateRow_inj @[deprecated (since := "2025-03-20")] alias row_eq_zero := replicateRow_eq_zero @[simp] theorem replicateRow_add [Add α] (v w : m → α) : replicateRow ι (v + w) = replicateRow ι v + replicateRow ι w := by ext rfl @[deprecated (since := "2025-03-20")] alias row_add := replicateRow_add @[simp] theorem replicateRow_smul [SMul R α] (x : R) (v : m → α) : replicateRow ι (x • v) = x • replicateRow ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias row_smul := replicateRow_smul @[simp] theorem transpose_replicateCol (v : m → α) : (replicateCol ι v)ᵀ = replicateRow ι v := by ext rfl @[simp] theorem transpose_replicateRow (v : m → α) : (replicateRow ι v)ᵀ = replicateCol ι v := by ext rfl @[simp] theorem conjTranspose_replicateCol [Star α] (v : m → α) : (replicateCol ι v)ᴴ = replicateRow ι (star v) := by
ext rfl @[deprecated (since := "2025-03-20")] alias conjTranspose_col := conjTranspose_replicateCol
Mathlib/Data/Matrix/RowCol.lean
147
150
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Yury Kudryashov -/ import Mathlib.Algebra.Algebra.Defs import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Submodule.Ker import Mathlib.Algebra.Module.Submodule.RestrictScalars import Mathlib.Algebra.Module.ULift import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Ring.Subring.Basic import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Int.CharZero /-! # Further basic results about `Algebra`. This file could usefully be split further. -/ universe u v w u₁ v₁ open Function namespace Algebra variable {R : Type u} {A : Type w} section Semiring variable [CommSemiring R] variable [Semiring A] [Algebra R A] section PUnit instance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where algebraMap := { toFun _ := PUnit.unit map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl } commutes' _ _ := rfl smul_def' _ _ := rfl @[simp] theorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit := rfl end PUnit section ULift instance _root_.ULift.algebra : Algebra R (ULift A) := { ULift.module' with algebraMap := { (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with toFun := fun r => ULift.up (algebraMap R A r) } commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down } theorem _root_.ULift.algebraMap_eq (r : R) : algebraMap R (ULift A) r = ULift.up (algebraMap R A r) := rfl @[simp] theorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r := rfl end ULift /-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/ instance ofSubsemiring (S : Subsemiring R) : Algebra S A where algebraMap := (algebraMap R A).comp S.subtype smul := (· • ·) commutes' r x := Algebra.commutes (r : R) x smul_def' r x := Algebra.smul_def (r : R) x theorem algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S →+* R) = Subsemiring.subtype S := rfl theorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val := rfl theorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x := rfl /-- Algebra over a subring. This builds upon `Subring.module`. -/ instance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) : Algebra S A where algebraMap := (algebraMap R A).comp S.subtype smul := (· • ·) commutes' r x := Algebra.commutes (r : R) x smul_def' r x := Algebra.smul_def (r : R) x theorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) : (algebraMap S R : S →+* R) = Subring.subtype S := rfl theorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) : (algebraMap S R : S → R) = Subtype.val := rfl theorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) : algebraMap S R x = x := rfl /-- Explicit characterization of the submonoid map in the case of an algebra. `S` is made explicit to help with type inference -/ def algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S := M.map (algebraMap R S) theorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R} (x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M := Set.mem_image_of_mem (algebraMap R S) x.2 end Semiring section CommSemiring variable [CommSemiring R] theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) : x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul] theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) : x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by induction n with | zero => simp | succ n ih => rw [pow_succ', ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc] end CommSemiring section Ring /-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure. See note [reducible non-instances]. -/ abbrev semiringToRing (R : Type*) [CommRing R] [Semiring A] [Algebra R A] : Ring A := { __ := (inferInstance : Semiring A) __ := Module.addCommMonoidToAddCommGroup R intCast := fun z => algebraMap R A z intCast_ofNat := fun z => by simp only [Int.cast_natCast, map_natCast] intCast_negSucc := fun z => by simp } instance {R : Type*} [Ring R] : Algebra (Subring.center R) R where algebraMap := { toFun := Subtype.val map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl } commutes' r x := (Subring.mem_center_iff.1 r.2 x).symm smul_def' _ _ := rfl end Ring end Algebra open scoped Algebra namespace Module variable (R : Type u) (S : Type v) (M : Type w) variable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M] variable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M] instance End.instAlgebra : Algebra R (Module.End S M) := Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm -- to prove this is a special case of the above example : Algebra R (Module.End R M) := End.instAlgebra _ _ _ theorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id := rfl @[simp] theorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m := rfl @[simp] theorem ker_algebraMap_end (K : Type u) (V : Type v) [Semifield K] [AddCommMonoid V] [Module K V] (a : K) (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ := LinearMap.ker_smul _ _ ha section variable {R M} theorem End.algebraMap_isUnit_inv_apply_eq_iff {x : R} (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) : (↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' where mp H := H ▸ (isUnit_apply_inv_apply_of_isUnit h m).symm mpr H := H.symm ▸ by apply_fun ⇑h.unit.val using ((isUnit_iff _).mp h).injective simpa using Module.End.isUnit_apply_inv_apply_of_isUnit h (x • m') @[deprecated (since := "2025-04-28")] alias End_algebraMap_isUnit_inv_apply_eq_iff := End.algebraMap_isUnit_inv_apply_eq_iff theorem End.algebraMap_isUnit_inv_apply_eq_iff' {x : R} (h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) : m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' where mp H := H ▸ (isUnit_apply_inv_apply_of_isUnit h m).symm mpr H := H.symm ▸ by apply_fun (↑h.unit : M → M) using ((isUnit_iff _).mp h).injective simpa using isUnit_apply_inv_apply_of_isUnit h (x • m') |>.symm @[deprecated (since := "2025-04-28")] alias End_algebraMap_isUnit_inv_apply_eq_iff' := End.algebraMap_isUnit_inv_apply_eq_iff' end end Module namespace LinearMap variable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to work with than `•`. -/ theorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) : f (algebraMap R A r * a) = algebraMap R B r * f a := by rw [← Algebra.smul_def, ← Algebra.smul_def, map_smul] theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) : f (a * algebraMap R A r) = f a * algebraMap R B r := by rw [← Algebra.commutes, ← Algebra.commutes, map_algebraMap_mul] end LinearMap section Nat variable {R : Type*} [Semiring R] -- Lower the priority so that `Algebra.id` is picked most of the time when working with -- `ℕ`-algebras. -- TODO: is this still needed? /-- Semiring ⥤ ℕ-Alg -/ instance (priority := 99) Semiring.toNatAlgebra : Algebra ℕ R where commutes' := Nat.cast_commute smul_def' _ _ := nsmul_eq_mul _ _ algebraMap := Nat.castRingHom R instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) := ⟨fun P Q => by ext; simp⟩ @[simp] lemma algebraMap_comp_natCast (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] : algebraMap R A ∘ Nat.cast = Nat.cast := by ext; simp end Nat section Int variable (R : Type*) [Ring R] -- Lower the priority so that `Algebra.id` is picked most of the time when working with -- `ℤ`-algebras. -- TODO: is this still needed? /-- Ring ⥤ ℤ-Alg -/ instance (priority := 99) Ring.toIntAlgebra : Algebra ℤ R where commutes' := Int.cast_commute smul_def' _ _ := zsmul_eq_mul _ _ algebraMap := Int.castRingHom R /-- A special case of `eq_intCast'` that happens to be true definitionally -/ @[simp] theorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R := rfl variable {R} instance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) := ⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩ @[simp] lemma algebraMap_comp_intCast (R A : Type*) [CommRing R] [Ring A] [Algebra R A] : algebraMap R A ∘ Int.cast = Int.cast := by ext; simp end Int section FaithfulSMul instance (R : Type*) [NonAssocSemiring R] : FaithfulSMul R R := ⟨fun {r₁ r₂} h ↦ by simpa using h 1⟩ variable (R A : Type*) [CommSemiring R] [Semiring A] lemma faithfulSMul_iff_injective_smul_one [Module R A] [IsScalarTower R A A] : FaithfulSMul R A ↔ Injective (fun r : R ↦ r • (1 : A)) := by refine ⟨fun ⟨h⟩ {r₁ r₂} hr ↦ h fun a ↦ ?_, fun h ↦ ⟨fun {r₁ r₂} hr ↦ h ?_⟩⟩ · simp only at hr rw [← one_mul a, ← smul_mul_assoc, ← smul_mul_assoc, hr] · simpa using hr 1 variable [Algebra R A] lemma faithfulSMul_iff_algebraMap_injective : FaithfulSMul R A ↔ Injective (algebraMap R A) := by rw [faithfulSMul_iff_injective_smul_one, Algebra.algebraMap_eq_smul_one'] variable [FaithfulSMul R A] namespace FaithfulSMul lemma algebraMap_injective : Injective (algebraMap R A) := (faithfulSMul_iff_algebraMap_injective R A).mp inferInstance @[deprecated (since := "2025-01-31")] alias _root_.NoZeroSMulDivisors.algebraMap_injective := algebraMap_injective @[simp] lemma algebraMap_eq_zero_iff {r : R} : algebraMap R A r = 0 ↔ r = 0 := map_eq_zero_iff (algebraMap R A) <| algebraMap_injective R A @[deprecated (since := "2025-01-31")] alias _root_.NoZeroSMulDivisors.algebraMap_eq_zero_iff := algebraMap_eq_zero_iff @[simp] lemma algebraMap_eq_one_iff {r : R} : algebraMap R A r = 1 ↔ r = 1 := map_eq_one_iff _ <| FaithfulSMul.algebraMap_injective R A @[deprecated (since := "2025-01-31")] alias _root_.NoZeroSMulDivisors.algebraMap_eq_one_iff := algebraMap_eq_one_iff theorem _root_.NeZero.of_faithfulSMul (n : ℕ) [NeZero (n : R)] : NeZero (n : A) := NeZero.nat_of_injective <| FaithfulSMul.algebraMap_injective R A @[deprecated (since := "2025-01-31")] alias _root_.NeZero.of_noZeroSMulDivisors := NeZero.of_faithfulSMul end FaithfulSMul lemma Algebra.charZero_of_charZero [CharZero R] : CharZero A := have := algebraMap_comp_natCast R A ⟨this ▸ (FaithfulSMul.algebraMap_injective R A).comp CharZero.cast_injective⟩ -- see note [lower instance priority] instance (priority := 100) [CharZero R] : FaithfulSMul ℕ R := by simpa only [faithfulSMul_iff_algebraMap_injective] using (algebraMap ℕ R).injective_nat -- see note [lower instance priority] instance (priority := 100) (R : Type*) [Ring R] [CharZero R] : FaithfulSMul ℤ R := by simpa only [faithfulSMul_iff_algebraMap_injective] using (algebraMap ℤ R).injective_int end FaithfulSMul namespace NoZeroSMulDivisors -- see Note [lower instance priority] instance (priority := 100) instOfFaithfulSMul {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A] [FaithfulSMul R A] : NoZeroSMulDivisors R A := ⟨fun hcx => (mul_eq_zero.mp ((Algebra.smul_def _ _).symm.trans hcx)).imp_left (map_eq_zero_iff (algebraMap R A) <| FaithfulSMul.algebraMap_injective R A).mp⟩ @[deprecated (since := "2025-01-31")] alias of_algebraMap_injective := instOfFaithfulSMul variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A] instance [Nontrivial A] [NoZeroSMulDivisors R A] : FaithfulSMul R A where eq_of_smul_eq_smul {r₁ r₂} h := by specialize h 1 rw [← sub_eq_zero, ← sub_smul, smul_eq_zero, sub_eq_zero] at h exact h.resolve_right one_ne_zero theorem iff_faithfulSMul [IsDomain A] : NoZeroSMulDivisors R A ↔ FaithfulSMul R A := ⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩ theorem iff_algebraMap_injective [IsDomain A] : NoZeroSMulDivisors R A ↔ Injective (algebraMap R A) := by rw [iff_faithfulSMul] exact faithfulSMul_iff_algebraMap_injective R A end NoZeroSMulDivisors section IsScalarTower variable {R : Type*} [CommSemiring R] variable (A : Type*) [Semiring A] [Algebra R A] variable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by rw [← one_smul A m, ← smul_assoc, Algebra.smul_def, mul_one, one_smul] @[simp] theorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m := (algebra_compatible_smul A r m).symm /-- If `M` is `A`-torsion free and `algebraMap R A` is injective, `M` is also `R`-torsion free. -/ theorem NoZeroSMulDivisors.trans_faithfulSMul (R A M : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [FaithfulSMul R A] [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M where eq_zero_or_eq_zero_of_smul_eq_zero hx := by rw [← algebraMap_smul (A := A)] at hx simpa only [map_eq_zero_iff _ <| FaithfulSMul.algebraMap_injective R A] using eq_zero_or_eq_zero_of_smul_eq_zero hx @[deprecated (since := "2025-01-31")] alias NoZeroSMulDivisors.of_algebraMap_injective' := NoZeroSMulDivisors.trans_faithfulSMul variable {A} -- see Note [lower instance priority] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980, as it is a very common path instance (priority := 120) IsScalarTower.to_smulCommClass : SMulCommClass R A M := ⟨fun r a m => by rw [algebra_compatible_smul A r (a • m), smul_smul, Algebra.commutes, mul_smul, ←
algebra_compatible_smul]⟩ -- see Note [lower instance priority] -- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980, as it is a very common path instance (priority := 110) IsScalarTower.to_smulCommClass' : SMulCommClass A R M := SMulCommClass.symm _ _ _ -- see Note [lower instance priority] instance (priority := 200) Algebra.to_smulCommClass {R A} [CommSemiring R] [Semiring A] [Algebra R A] : SMulCommClass R A A := IsScalarTower.to_smulCommClass
Mathlib/Algebra/Algebra/Basic.lean
417
428
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Michael Stoll -/ import Mathlib.Analysis.PSeries import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.Data.Complex.FiniteDimensional /-! # L-series Given a sequence `f: ℕ → ℂ`, we define the corresponding L-series. ## Main Definitions * `LSeries.term f s n` is the `n`th term of the L-series of the sequence `f` at `s : ℂ`. We define it to be zero when `n = 0`. * `LSeries f` is the L-series with a given sequence `f` as its coefficients. This is not the analytic continuation (which does not necessarily exist), just the sum of the infinite series if it exists and zero otherwise. * `LSeriesSummable f s` indicates that the L-series of `f` converges at `s : ℂ`. * `LSeriesHasSum f s a` expresses that the L-series of `f` converges (absolutely) at `s : ℂ` to `a : ℂ`. ## Main Results * `LSeriesSummable_of_isBigO_rpow`: the `LSeries` of a sequence `f` such that `f = O(n^(x-1))` converges at `s` when `x < s.re`. * `LSeriesSummable.isBigO_rpow`: if the `LSeries` of `f` is summable at `s`, then `f = O(n^(re s))`. ## Notation We introduce `L` as notation for `LSeries` and `↗f` as notation for `fun n : ℕ ↦ (f n : ℂ)`, both scoped to `LSeries.notation`. The latter makes it convenient to use arithmetic functions or Dirichlet characters (or anything that coerces to a function `N → R`, where `ℕ` coerces to `N` and `R` coerces to `ℂ`) as arguments to `LSeries` etc. ## Reference For some background on the design decisions made when implementing L-series in Mathlib (and applications motivating the development), see the paper [Formalizing zeta and L-functions in Lean](https://arxiv.org/abs/2503.00959) by David Loeffler and Michael Stoll. ## Tags L-series -/ open Complex /-! ### The terms of an L-series We define the `n`th term evaluated at a complex number `s` of the L-series associated to a sequence `f : ℕ → ℂ`, `LSeries.term f s n`, and provide some basic API. We set `LSeries.term f s 0 = 0`, and for positive `n`, `LSeries.term f s n = f n / n ^ s`. -/ namespace LSeries /-- The `n`th term of the L-series of `f` evaluated at `s`. We set it to zero when `n = 0`. -/ noncomputable def term (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : ℂ := if n = 0 then 0 else f n / n ^ s lemma term_def (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : term f s n = if n = 0 then 0 else f n / n ^ s := rfl /-- An alternate spelling of `term_def` for the case `f 0 = 0`. -/ lemma term_def₀ {f : ℕ → ℂ} (hf : f 0 = 0) (s : ℂ) (n : ℕ) : LSeries.term f s n = f n * (n : ℂ) ^ (- s) := by rw [LSeries.term] split_ifs with h <;> simp [h, hf, cpow_neg, div_eq_inv_mul, mul_comm] @[simp] lemma term_zero (f : ℕ → ℂ) (s : ℂ) : term f s 0 = 0 := rfl -- We put `hn` first for convnience, so that we can write `rw [LSeries.term_of_ne_zero hn]` etc. @[simp] lemma term_of_ne_zero {n : ℕ} (hn : n ≠ 0) (f : ℕ → ℂ) (s : ℂ) : term f s n = f n / n ^ s := if_neg hn /-- If `s ≠ 0`, then the `if .. then .. else` construction in `LSeries.term` isn't needed, since `0 ^ s = 0`. -/ lemma term_of_ne_zero' {s : ℂ} (hs : s ≠ 0) (f : ℕ → ℂ) (n : ℕ) : term f s n = f n / n ^ s := by rcases eq_or_ne n 0 with rfl | hn · rw [term_zero, Nat.cast_zero, zero_cpow hs, div_zero] · rw [term_of_ne_zero hn] lemma term_congr {f g : ℕ → ℂ} (h : ∀ {n}, n ≠ 0 → f n = g n) (s : ℂ) (n : ℕ) : term f s n = term g s n := by rcases eq_or_ne n 0 with hn | hn <;> simp [hn, h] lemma pow_mul_term_eq (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : (n + 1) ^ s * term f s (n + 1) = f (n + 1) := by simp [term, natCast_add_one_cpow_ne_zero n _, mul_comm (f _), mul_div_assoc'] lemma norm_term_eq (f : ℕ → ℂ) (s : ℂ) (n : ℕ) : ‖term f s n‖ = if n = 0 then 0 else ‖f n‖ / n ^ s.re := by rcases eq_or_ne n 0 with rfl | hn · simp · simp [hn, norm_natCast_cpow_of_pos <| Nat.pos_of_ne_zero hn] lemma norm_term_le {f g : ℕ → ℂ} (s : ℂ) {n : ℕ} (h : ‖f n‖ ≤ ‖g n‖) : ‖term f s n‖ ≤ ‖term g s n‖ := by simp only [norm_term_eq] split · rfl · gcongr lemma norm_term_le_of_re_le_re (f : ℕ → ℂ) {s s' : ℂ} (h : s.re ≤ s'.re) (n : ℕ) : ‖term f s' n‖ ≤ ‖term f s n‖ := by simp only [norm_term_eq] split · next => rfl · next hn => gcongr; exact Nat.one_le_cast.mpr <| Nat.one_le_iff_ne_zero.mpr hn section positivity open scoped ComplexOrder lemma term_nonneg {a : ℕ → ℂ} {n : ℕ} (h : 0 ≤ a n) (x : ℝ) : 0 ≤ term a x n := by rw [term_def] split_ifs with hn exacts [le_rfl, mul_nonneg h (inv_natCast_cpow_ofReal_pos hn x).le]
lemma term_pos {a : ℕ → ℂ} {n : ℕ} (hn : n ≠ 0) (h : 0 < a n) (x : ℝ) : 0 < term a x n := by simpa only [term_of_ne_zero hn] using mul_pos h <| inv_natCast_cpow_ofReal_pos hn x end positivity end LSeries /-! ### Definition of the L-series and related statements We define `LSeries f s` of `f : ℕ → ℂ` as the sum over `LSeries.term f s`. We also provide predicates `LSeriesSummable f s` stating that `LSeries f s` is summable and `LSeriesHasSum f s a` stating that the L-series of `f` is summable at `s` and converges
Mathlib/NumberTheory/LSeries/Basic.lean
140
152
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Algebra.CharP.Reduced import Mathlib.Algebra.Field.ZMod import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.ValMinAbs import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix import Mathlib.FieldTheory.Finiteness import Mathlib.FieldTheory.Perfect import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * #(univ.image fun x => eval x p) := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = #(p - C a).roots.toFinset := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_cancel]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g))) <| calc 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * #(univ.image fun x : R => eval x f) + natDegree (-g) * #(univ.image fun x : R => eval x (-g)) := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) := by rw [card_union_of_disjoint hd] simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp +contextual [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) : ∑ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G ↪ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x simp only [h_unchanged, mulLeftEmbedding_apply, Subgroup.coe_mul, Units.val_mul, ← mul_sum, a_mul_emb] at h_sum_map -- thus one of (a - 1) or ∑ G, x is zero have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] : ∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by by_cases G_bot : G = ⊥ · subst G_bot simp only [univ_unique, sum_singleton, ↓reduceIte, Units.val_eq_one, OneMemClass.coe_eq_one] rw [Set.default_coe_singleton] rfl · simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by rw [← Nat.card_eq_fintype_card] at k_lt_card_G nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k) = (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by funext x simp only [Function.comp_apply, Subgroup.coe_mul, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : Kˣ) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K] theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one] rfl theorem pow_card (a : K) : a ^ q = a := by by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one, pow_card_sub_one_eq_one a h, one_mul] theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by induction n with | zero => simp | succ n ih => simp [pow_succ, pow_mul, ih, pow_card] end variable (K) [Field K] [Fintype K] /-- The cardinality `q` is a power of the characteristic of `K`. -/ @[stacks 09HY "first part"] theorem card (p : ℕ) [CharP K p] : ∃ n : ℕ+, Nat.Prime p ∧ q = p ^ (n : ℕ) := by haveI hp : Fact p.Prime := ⟨CharP.char_is_prime K p⟩ letI : Module (ZMod p) K := { (ZMod.castHom dvd_rfl K : ZMod p →+* _).toModule with } obtain ⟨n, h⟩ := VectorSpace.card_fintype (ZMod p) K rw [ZMod.card] at h refine ⟨⟨n, ?_⟩, hp.1, h⟩ apply Or.resolve_left (Nat.eq_zero_or_pos n) rintro rfl rw [pow_zero] at h have : (0 : K) = 1 := by apply Fintype.card_le_one_iff.mp (le_of_eq h) exact absurd this zero_ne_one -- this statement doesn't use `q` because we want `K` to be an explicit parameter theorem card' : ∃ (p : ℕ), CharP K p ∧ ∃ (n : ℕ+), Nat.Prime p ∧ Fintype.card K = p ^ (n : ℕ) := let ⟨p, hc⟩ := CharP.exists K ⟨p, hc, @FiniteField.card K _ _ p hc⟩ lemma isPrimePow_card : IsPrimePow (Fintype.card K) := by obtain ⟨p, _, n, hp, hn⟩ := card' K exact ⟨p, n, Nat.prime_iff.mp hp, n.prop, hn.symm⟩ theorem cast_card_eq_zero : (q : K) = 0 := by simp theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣ i := by classical obtain ⟨x, hx⟩ := IsCyclic.exists_generator (α := Kˣ) rw [← Nat.card_eq_fintype_card, ← Nat.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hx, orderOf_dvd_iff_pow_eq_one] constructor · intro h; apply h · intro h y simp_rw [← mem_powers_iff_mem_zpowers] at hx rcases hx y with ⟨j, rfl⟩ rw [← pow_mul, mul_comm, pow_mul, h, one_pow] /-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q` is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/ theorem sum_pow_units [DecidableEq K] (i : ℕ) : (∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by let φ : Kˣ →* K := { toFun := fun x => x ^ i map_one' := by simp map_mul' := by intros; simp [mul_pow] } have : Decidable (φ = 1) := by classical infer_instance calc (∑ x : Kˣ, φ x) = if φ = 1 then Fintype.card Kˣ else 0 := sum_hom_units φ _ = if q - 1 ∣ i then -1 else 0 := by suffices q - 1 ∣ i ↔ φ = 1 by simp only [this] split_ifs; swap · exact Nat.cast_zero · rw [Fintype.card_units, Nat.cast_sub, cast_card_eq_zero, Nat.cast_one, zero_sub] show 1 ≤ q; exact Fintype.card_pos_iff.mpr ⟨0⟩ rw [← forall_pow_eq_one_iff, DFunLike.ext_iff] apply forall_congr'; intro x; simp [φ, Units.ext_iff] /-- The sum of `x ^ i` as `x` ranges over a finite field of cardinality `q` is equal to `0` if `i < q - 1`. -/ theorem sum_pow_lt_card_sub_one (i : ℕ) (h : i < q - 1) : ∑ x : K, x ^ i = 0 := by by_cases hi : i = 0 · simp only [hi, nsmul_one, sum_const, pow_zero, card_univ, cast_card_eq_zero] classical have hiq : ¬q - 1 ∣ i := by contrapose! h; exact Nat.le_of_dvd (Nat.pos_of_ne_zero hi) h let φ : Kˣ ↪ K := ⟨fun x ↦ x, Units.ext⟩ have : univ.map φ = univ \ {0} := by ext x simpa only [mem_map, mem_univ, Function.Embedding.coeFn_mk, true_and, mem_sdiff, mem_singleton, φ] using isUnit_iff_ne_zero calc ∑ x : K, x ^ i = ∑ x ∈ univ \ {(0 : K)}, x ^ i := by rw [← sum_sdiff ({0} : Finset K).subset_univ, sum_singleton, zero_pow hi, add_zero] _ = ∑ x : Kˣ, (x ^ i : K) := by simp [φ, ← this, univ.sum_map φ] _ = 0 := by rw [sum_pow_units K i, if_neg]; exact hiq section frobenius variable (R) [CommRing R] [Algebra K R] /-- If `R` is an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is given by raising every element of `R` to its `#K`-th power. -/ @[simps!] def frobeniusAlgHom : R →ₐ[K] R where __ := powMonoidHom q map_zero' := zero_pow Fintype.card_pos.ne' map_add' _ _ := by obtain ⟨p, _, _, hp, card_eq⟩ := card' K nontriviality R have : CharP R p := charP_of_injective_algebraMap' K R p have : ExpChar R p := .prime hp simp only [OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, powMonoidHom_apply, card_eq] exact add_pow_expChar_pow .. commutes' _ := by simp [← RingHom.map_pow, pow_card] theorem coe_frobeniusAlgHom : ⇑(frobeniusAlgHom K R) = (· ^ q) := rfl /-- If `R` is a perfect ring and an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquiv (p : ℕ) [ExpChar R p] [PerfectRing R p] : R ≃ₐ[K] R := .ofBijective (frobeniusAlgHom K R) <| by obtain ⟨p', _, n, hp, card_eq⟩ := card' K rw [coe_frobeniusAlgHom, card_eq] have : ExpChar K p' := ExpChar.prime hp nontriviality R have := ExpChar.eq ‹_› (expChar_of_injective_algebraMap (algebraMap K R).injective p') subst this apply bijective_iterateFrobenius variable (L : Type*) [Field L] [Algebra K L] /-- If `L/K` is an algebraic extension of a finite field, the Frobenius `K`-algebra endomorphism of `L` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : L ≃ₐ[K] L := (Algebra.IsAlgebraic.algEquivEquivAlgHom K L).symm (frobeniusAlgHom K L) theorem coe_frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : ⇑(frobeniusAlgEquivOfAlgebraic K L) = (· ^ q) := rfl variable [Finite L] open Polynomial in theorem orderOf_frobeniusAlgHom : orderOf (frobeniusAlgHom K L) = Module.finrank K L := (orderOf_eq_iff Module.finrank_pos).mpr <| by have := Fintype.ofFinite L refine ⟨DFunLike.ext _ _ fun x ↦ ?_, fun m lt pos eq ↦ ?_⟩ · simp_rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← Module.card_eq_pow_finrank, pow_card] have := card_le_degree_of_subset_roots (R := L) (p := X ^ q ^ m - X) (Z := univ) fun x _ ↦ by simp_rw [mem_roots', IsRoot, eval_sub, eval_pow, eval_X] have := DFunLike.congr_fun eq x rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← sub_eq_zero] at this refine ⟨fun h ↦ ?_, this⟩ simpa [if_neg (Nat.one_lt_pow pos.ne' Fintype.one_lt_card).ne] using congr_arg (coeff · 1) h refine this.not_lt (((natDegree_sub_le ..).trans_eq ?_).trans_lt <| (Nat.pow_lt_pow_right Fintype.one_lt_card lt).trans_eq Module.card_eq_pow_finrank.symm) simp [Nat.one_le_pow _ _ Fintype.card_pos] theorem orderOf_frobeniusAlgEquivOfAlgebraic : orderOf (frobeniusAlgEquivOfAlgebraic K L) = Module.finrank K L := by simpa [orderOf_eq_iff Module.finrank_pos, DFunLike.ext_iff] using orderOf_frobeniusAlgHom K L theorem bijective_frobeniusAlgHom_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgHom K L ^ n.1 := let e := (finCongr <| orderOf_frobeniusAlgHom K L).symm.trans <| finEquivPowers (orderOf_pos_iff.mp <| orderOf_frobeniusAlgHom K L ▸ Module.finrank_pos) (Subtype.val_injective.comp e.injective).bijective_of_nat_card_le ((card_algHom_le_finrank K L L).trans_eq <| by simp) theorem bijective_frobeniusAlgEquivOfAlgebraic_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgEquivOfAlgebraic K L ^ n.1 := ((Algebra.IsAlgebraic.algEquivEquivAlgHom K L).bijective.of_comp_iff' _).mp <| by simpa only [Function.comp_def, map_pow] using bijective_frobeniusAlgHom_pow K L instance (K L) [Finite L] [Field K] [Field L] [Algebra K L] : IsCyclic (L ≃ₐ[K] L) where exists_zpow_surjective := have := Finite.of_injective _ (algebraMap K L).injective have := Fintype.ofFinite K ⟨frobeniusAlgEquivOfAlgebraic K L, fun f ↦ have ⟨n, hn⟩ := (bijective_frobeniusAlgEquivOfAlgebraic_pow K L).2 f; ⟨n, hn⟩⟩ end frobenius open Polynomial section variable [Fintype K] (K' : Type*) [Field K'] {p n : ℕ} theorem X_pow_card_sub_X_natDegree_eq (hp : 1 < p) : (X ^ p - X : K'[X]).natDegree = p := by have h1 : (X : K'[X]).degree < (X ^ p : K'[X]).degree := by rw [degree_X_pow, degree_X] exact mod_cast hp rw [natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt h1), natDegree_X_pow] theorem X_pow_card_pow_sub_X_natDegree_eq (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]).natDegree = p ^ n := X_pow_card_sub_X_natDegree_eq K' <| Nat.one_lt_pow hn hp theorem X_pow_card_sub_X_ne_zero (hp : 1 < p) : (X ^ p - X : K'[X]) ≠ 0 := ne_zero_of_natDegree_gt <| calc 1 < _ := hp _ = _ := (X_pow_card_sub_X_natDegree_eq K' hp).symm theorem X_pow_card_pow_sub_X_ne_zero (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K' <| Nat.one_lt_pow hn hp end theorem roots_X_pow_card_sub_X : roots (X ^ q - X : K[X]) = Finset.univ.val := by classical have aux : (X ^ q - X : K[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K Fintype.one_lt_card have : (roots (X ^ q - X : K[X])).toFinset = Finset.univ := by rw [eq_univ_iff_forall] intro x rw [Multiset.mem_toFinset, mem_roots aux, IsRoot.def, eval_sub, eval_pow, eval_X, sub_eq_zero, pow_card] rw [← this, Multiset.toFinset_val, eq_comm, Multiset.dedup_eq_self] apply nodup_roots rw [separable_def] convert isCoprime_one_right.neg_right (R := K[X]) using 1 rw [derivative_sub, derivative_X, derivative_X_pow, Nat.cast_card_eq_zero K, C_0, zero_mul, zero_sub] variable {K} theorem frobenius_pow {p : ℕ} [Fact p.Prime] [CharP K p] {n : ℕ} (hcard : q = p ^ n) : frobenius K p ^ n = 1 := by ext x; conv_rhs => rw [RingHom.one_def, RingHom.id_apply, ← pow_card x, hcard] clear hcard induction n with | zero => simp | succ n hn => rw [pow_succ', pow_succ, pow_mul, RingHom.mul_def, RingHom.comp_apply, frobenius_def, hn] open Polynomial theorem expand_card (f : K[X]) : expand K q f = f ^ q := by obtain ⟨p, hp⟩ := CharP.exists K letI := hp rcases FiniteField.card K p with ⟨⟨n, npos⟩, ⟨hp, hn⟩⟩ haveI : Fact p.Prime := ⟨hp⟩ dsimp at hn rw [hn, ← map_expand_pow_char, frobenius_pow hn, RingHom.one_def, map_id] end FiniteField namespace ZMod open FiniteField Polynomial theorem sq_add_sq (p : ℕ) [hp : Fact p.Prime] (x : ZMod p) : ∃ a b : ZMod p, a ^ 2 + b ^ 2 = x := by rcases hp.1.eq_two_or_odd with hp2 | hp_odd · subst p change Fin 2 at x fin_cases x · use 0; simp · use 0, 1; simp let f : (ZMod p)[X] := X ^ 2 let g : (ZMod p)[X] := X ^ 2 - C x obtain ⟨a, b, hab⟩ : ∃ a b, f.eval a + g.eval b = 0 := @exists_root_sum_quadratic _ _ _ _ f g (degree_X_pow 2) (degree_X_pow_sub_C (by decide) _) (by rw [ZMod.card, hp_odd]) refine ⟨a, b, ?_⟩ rw [← sub_eq_zero] simpa only [f, g, eval_C, eval_X, eval_pow, eval_sub, ← add_sub_assoc] using hab end ZMod /-- If `p` is a prime natural number and `x` is an integer number, then there exist natural numbers `a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [ZMOD p]`. This is a version of `ZMod.sq_add_sq` with estimates on `a` and `b`. -/ theorem Nat.sq_add_sq_zmodEq (p : ℕ) [Fact p.Prime] (x : ℤ) : ∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ (a : ℤ) ^ 2 + (b : ℤ) ^ 2 ≡ x [ZMOD p] := by rcases ZMod.sq_add_sq p x with ⟨a, b, hx⟩ refine ⟨a.valMinAbs.natAbs, b.valMinAbs.natAbs, ZMod.natAbs_valMinAbs_le _, ZMod.natAbs_valMinAbs_le _, ?_⟩ rw [← a.coe_valMinAbs, ← b.coe_valMinAbs] at hx push_cast rw [sq_abs, sq_abs, ← ZMod.intCast_eq_intCast_iff] exact mod_cast hx /-- If `p` is a prime natural number and `x` is a natural number, then there exist natural numbers `a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [MOD p]`. This is a version of `ZMod.sq_add_sq` with estimates on `a` and `b`. -/ theorem Nat.sq_add_sq_modEq (p : ℕ) [Fact p.Prime] (x : ℕ) : ∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ a ^ 2 + b ^ 2 ≡ x [MOD p] := by simpa only [← Int.natCast_modEq_iff] using Nat.sq_add_sq_zmodEq p x namespace CharP theorem sq_add_sq (R : Type*) [Ring R] [IsDomain R] (p : ℕ) [NeZero p] [CharP R p] (x : ℤ) : ∃ a b : ℕ, ((a : R) ^ 2 + (b : R) ^ 2) = x := by haveI := char_is_prime_of_pos R p obtain ⟨a, b, hab⟩ := ZMod.sq_add_sq p x refine ⟨a.val, b.val, ?_⟩ simpa using congr_arg (ZMod.castHom dvd_rfl R) hab end CharP open scoped Nat open ZMod /-- The **Fermat-Euler totient theorem**. `Nat.ModEq.pow_totient` is an alternative statement of the same theorem. -/ @[simp] theorem ZMod.pow_totient {n : ℕ} (x : (ZMod n)ˣ) : x ^ φ n = 1 := by cases n · rw [Nat.totient_zero, pow_zero] · rw [← card_units_eq_totient, pow_card_eq_one] /-- The **Fermat-Euler totient theorem**. `ZMod.pow_totient` is an alternative statement of the same theorem. -/ theorem Nat.ModEq.pow_totient {x n : ℕ} (h : Nat.Coprime x n) : x ^ φ n ≡ 1 [MOD n] := by rw [← ZMod.eq_iff_modEq_nat] let x' : Units (ZMod n) := ZMod.unitOfCoprime _ h have := ZMod.pow_totient x' apply_fun ((fun (x : Units (ZMod n)) => (x : ZMod n)) : Units (ZMod n) → ZMod n) at this simpa only [Nat.succ_eq_add_one, Nat.cast_pow, Units.val_one, Nat.cast_one, coe_unitOfCoprime, Units.val_pow_eq_pow_val] /-- For each `n ≥ 0`, the unit group of `ZMod n` is finite. -/ instance instFiniteZModUnits : (n : ℕ) → Finite (ZMod n)ˣ | 0 => Finite.of_fintype ℤˣ | _ + 1 => inferInstance open FiniteField namespace ZMod variable {p : ℕ} [Fact p.Prime]
instance : Subsingleton (Subfield (ZMod p)) :=
Mathlib/FieldTheory/Finite/Basic.lean
552
553
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Data.Set.BooleanAlgebra /-! # The set lattice This file is a collection of results on the complete atomic boolean algebra structure of `Set α`. Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`. ## Main declarations * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`, `< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference. See `Set.instBooleanAlgebra`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `⋂ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`. * `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂` where `j : i ∈ s`. * `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `⋂`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `⋂₀`: `Set.sInter` -/ open Function Set universe u variable {α β γ δ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by simp_rw [mem_iUnion] theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by simp_rw [mem_iInter] theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnion₂.2 ⟨i, j, ha⟩ theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_iInter.2 h theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) : a ∈ ⋂ (i) (j), s i j := mem_iInter₂.2 h /-! ### Union and intersection over an indexed family of sets -/ @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ := iSup_congr_Prop pq f @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ := iInf_congr_Prop pq f theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i := iInf_plift_up _ theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i := iInf_plift_down _ theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ := iSup_eq_if _ theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋃ h : p, s h = if h : p then s h else ∅ := iSup_eq_dif _ theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ := iInf_eq_if _ theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋂ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β) (w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by have p : x ∈ ⊤ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α) (H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ theorem nonempty_of_nonempty_iUnion {s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } := ext fun _ => mem_iInter.symm theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t := iSup_le h theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) : ⋃ (i) (j), s i j ⊆ t := iUnion_subset fun x => iUnion_subset (h x) theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := le_iInf h theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) : s ⊆ ⋂ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x @[simp] theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} : ⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff] @[simp] theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i := le_iInf_iff theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} : (s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff] theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i := le_iSup theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i := iInf_le lemma iInter_subset_iUnion [Nonempty ι] {s : ι → Set α} : ⋂ i, s i ⊆ ⋃ i, s i := iInf_le_iSup theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' := le_iSup₂ i j theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j := iInf₂_le i j /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i := le_iSup_of_le i h /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) : ⋂ i, s i ⊆ t := iInf_le_of_le i h /-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i) (h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j := le_iSup₂_of_le i j h /-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i) (h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t := iInf₂_le_of_le i j h theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono h @[gcongr] theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t := iSup_mono h theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j := iSup₂_mono h theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i := iInf_mono h @[gcongr] theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t := iInf_mono h theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j := iInf₂_mono h theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono' h theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' := iSup₂_mono' h theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) : ⋂ i, s i ⊆ ⋂ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' := subset_iInter₂_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInter₂_subset _ _).trans hst theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) : ⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) : ⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by ext exact mem_iUnion theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by ext exact mem_iInter theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y :=
h1.iSup_congr h h2
Mathlib/Data/Set/Lattice.lean
263
264
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.RingTheory.AlgebraTower import Mathlib.SetTheory.Cardinal.Finsupp /-! # Rank of free modules ## Main result - `LinearEquiv.nonempty_equiv_iff_lift_rank_eq`: Two free modules are isomorphic iff they have the same dimension. - `Module.finBasis`: An arbitrary basis of a finite free module indexed by `Fin n` given `finrank R M = n`. -/ noncomputable section universe u v v' w open Cardinal Basis Submodule Function Set Module section Tower variable (F : Type u) (K : Type v) (A : Type w) variable [Semiring F] [Semiring K] [AddCommMonoid A] variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A] variable [StrongRankCondition F] [StrongRankCondition K] [Module.Free F K] [Module.Free K A] /-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then $\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$. The universe polymorphic version of `rank_mul_rank` below. -/ theorem lift_rank_mul_lift_rank : Cardinal.lift.{w} (Module.rank F K) * Cardinal.lift.{v} (Module.rank K A) = Cardinal.lift.{v} (Module.rank F A) := by let b := Module.Free.chooseBasis F K let c := Module.Free.chooseBasis K A rw [← (Module.rank F K).lift_id, ← b.mk_eq_rank, ← (Module.rank K A).lift_id, ← c.mk_eq_rank, ← lift_umax.{w, v}, ← (b.smulTower c).mk_eq_rank, mk_prod, lift_mul, lift_lift, lift_lift, lift_lift, lift_lift, lift_umax.{v, w}] /-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then $\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$. This is a simpler version of `lift_rank_mul_lift_rank` with `K` and `A` in the same universe. -/ @[stacks 09G9] theorem rank_mul_rank (A : Type v) [AddCommMonoid A] [Module K A] [Module F A] [IsScalarTower F K A] [Module.Free K A] : Module.rank F K * Module.rank K A = Module.rank F A := by convert lift_rank_mul_lift_rank F K A <;> rw [lift_id] /-- Tower law: if `A` is a `K`-module and `K` is an extension of `F` then $\operatorname{rank}_F(A) = \operatorname{rank}_F(K) * \operatorname{rank}_K(A)$. -/ theorem Module.finrank_mul_finrank : finrank F K * finrank K A = finrank F A := by simp_rw [finrank] rw [← toNat_lift.{w} (Module.rank F K), ← toNat_lift.{v} (Module.rank K A), ← toNat_mul, lift_rank_mul_lift_rank, toNat_lift] end Tower variable {R : Type u} {M M₁ : Type v} {M' : Type v'} variable [Semiring R] [StrongRankCondition R] variable [AddCommMonoid M] [Module R M] [Module.Free R M] variable [AddCommMonoid M'] [Module R M'] [Module.Free R M'] variable [AddCommMonoid M₁] [Module R M₁] [Module.Free R M₁] namespace Module.Free variable (R M) /-- The rank of a free module `M` over `R` is the cardinality of `ChooseBasisIndex R M`. -/ theorem rank_eq_card_chooseBasisIndex : Module.rank R M = #(ChooseBasisIndex R M) := (chooseBasis R M).mk_eq_rank''.symm /-- The finrank of a free module `M` over `R` is the cardinality of `ChooseBasisIndex R M`. -/ theorem _root_.Module.finrank_eq_card_chooseBasisIndex [Module.Finite R M] : finrank R M = Fintype.card (ChooseBasisIndex R M) := by simp [finrank, rank_eq_card_chooseBasisIndex] /-- The rank of a free module `M` over an infinite scalar ring `R` is the cardinality of `M` whenever `#R < #M`. -/ lemma rank_eq_mk_of_infinite_lt [Infinite R] (h_lt : lift.{v} #R < lift.{u} #M) : Module.rank R M = #M := by have : Infinite M := infinite_iff.mpr <| lift_le.mp <| le_trans (by simp) h_lt.le have h : lift #M = lift #(ChooseBasisIndex R M →₀ R) := lift_mk_eq'.mpr ⟨(chooseBasis R M).repr⟩
simp only [mk_finsupp_lift_of_infinite', lift_id', ← rank_eq_card_chooseBasisIndex, lift_max, lift_lift] at h refine lift_inj.mp ((max_eq_iff.mp h.symm).resolve_right <| not_and_of_not_left _ ?_).left exact (lift_umax.{v, u}.symm ▸ h_lt).ne end Module.Free open Module.Free open Cardinal
Mathlib/LinearAlgebra/Dimension/Free.lean
93
102
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Ring.Invertible import Mathlib.Data.Nat.Cast.Order.Ring /-! # Lemmas about `invOf` in ordered (semi)rings. -/ variable {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] {a : R} @[simp] theorem invOf_pos [Invertible a] : 0 < ⅟ a ↔ 0 < a := haveI : 0 < a * ⅟ a := by simp only [mul_invOf_self, zero_lt_one] ⟨fun h => pos_of_mul_pos_left this h.le, fun h => pos_of_mul_pos_right this h.le⟩ @[simp] theorem invOf_nonpos [Invertible a] : ⅟ a ≤ 0 ↔ a ≤ 0 := by simp only [← not_lt, invOf_pos] @[simp]
theorem invOf_nonneg [Invertible a] : 0 ≤ ⅟ a ↔ 0 ≤ a :=
Mathlib/Algebra/Order/Invertible.lean
25
25
/- Copyright (c) 2024 Brendan Murphy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Brendan Murphy -/ import Mathlib.RingTheory.Regular.IsSMulRegular import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nakayama import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.Noetherian.Basic /-! # Regular sequences and weakly regular sequences The notion of a regular sequence is fundamental in commutative algebra. Properties of regular sequences encode information about singularities of a ring and regularity of a sequence can be tested homologically. However the notion of a regular sequence is only really sensible for Noetherian local rings. TODO: Koszul regular sequences, H_1-regular sequences, quasi-regular sequences, depth. ## Tags module, regular element, regular sequence, commutative algebra -/ universe u v open scoped Pointwise variable {R S M M₂ M₃ M₄ : Type*} namespace Ideal variable [Semiring R] [Semiring S] /-- The ideal generated by a list of elements. -/ abbrev ofList (rs : List R) := span { r | r ∈ rs } @[simp] lemma ofList_nil : (ofList [] : Ideal R) = ⊥ := have : { r | r ∈ [] } = ∅ := Set.eq_empty_of_forall_not_mem (fun _ => List.not_mem_nil) Eq.trans (congrArg span this) span_empty @[simp] lemma ofList_append (rs₁ rs₂ : List R) : ofList (rs₁ ++ rs₂) = ofList rs₁ ⊔ ofList rs₂ := have : { r | r ∈ rs₁ ++ rs₂ } = _ := Set.ext (fun _ => List.mem_append) Eq.trans (congrArg span this) (span_union _ _) lemma ofList_singleton (r : R) : ofList [r] = span {r} := congrArg span (Set.ext fun _ => List.mem_singleton) @[simp] lemma ofList_cons (r : R) (rs : List R) : ofList (r::rs) = span {r} ⊔ ofList rs := Eq.trans (ofList_append [r] rs) (congrArg (· ⊔ _) (ofList_singleton r)) @[simp] lemma map_ofList (f : R →+* S) (rs : List R) : map f (ofList rs) = ofList (rs.map f) := Eq.trans (map_span f { r | r ∈ rs }) <| congrArg span <| Set.ext (fun _ => List.mem_map.symm) lemma ofList_cons_smul {R} [CommSemiring R] (r : R) (rs : List R) {M} [AddCommMonoid M] [Module R M] (N : Submodule R M) : ofList (r :: rs) • N = r • N ⊔ ofList rs • N := by rw [ofList_cons, Submodule.sup_smul, Submodule.ideal_span_singleton_smul] end Ideal namespace Submodule lemma smul_top_le_comap_smul_top [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (I : Ideal R) (f : M →ₗ[R] M₂) : I • ⊤ ≤ comap f (I • ⊤) := map_le_iff_le_comap.mp <| le_of_eq_of_le (map_smul'' _ _ _) <| smul_mono_right _ le_top variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module R M₂] (r : R) (rs : List R) /-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ r₀M) ⧸ (r₁, …, rₙ) (M ⧸ r₀M). -/ def quotOfListConsSMulTopEquivQuotSMulTopInner : (M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R] QuotSMulTop r M ⧸ (Ideal.ofList rs • ⊤ : Submodule R (QuotSMulTop r M)) := quotEquivOfEq _ _ (Ideal.ofList_cons_smul r rs ⊤) ≪≫ₗ (quotientQuotientEquivQuotientSup (r • ⊤) (Ideal.ofList rs • ⊤)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_smul'', map_top, range_mkQ]) /-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ (r₁, …, rₙ)) ⧸ r₀ (M ⧸ (r₁, …, rₙ)). -/ def quotOfListConsSMulTopEquivQuotSMulTopOuter : (M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R] QuotSMulTop r (M ⧸ (Ideal.ofList rs • ⊤ : Submodule R M)) := quotEquivOfEq _ _ (Eq.trans (Ideal.ofList_cons_smul r rs ⊤) (sup_comm _ _)) ≪≫ₗ (quotientQuotientEquivQuotientSup (Ideal.ofList rs • ⊤) (r • ⊤)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_pointwise_smul, map_top, range_mkQ]) variable {M} lemma quotOfListConsSMulTopEquivQuotSMulTopInner_naturality (f : M →ₗ[R] M₂) : (quotOfListConsSMulTopEquivQuotSMulTopInner M₂ r rs).toLinearMap ∘ₗ mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList (r :: rs)) f) = mapQ _ _ _ (smul_top_le_comap_smul_top _ (QuotSMulTop.map r f)) ∘ₗ (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toLinearMap := quot_hom_ext _ _ _ fun _ => rfl lemma top_eq_ofList_cons_smul_iff : (⊤ : Submodule R M) = Ideal.ofList (r :: rs) • ⊤ ↔ (⊤ : Submodule R (QuotSMulTop r M)) = Ideal.ofList rs • ⊤ := by conv => congr <;> rw [eq_comm, ← subsingleton_quotient_iff_eq_top] exact (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toEquiv.subsingleton_congr end Submodule namespace RingTheory.Sequence open scoped TensorProduct List open Function Submodule QuotSMulTop variable (S M) section Definitions /- In theory, regularity of `rs : List α` on `M` makes sense as soon as `[Monoid α]`, `[AddCommGroup M]`, and `[DistribMulAction α M]`. Instead of `Ideal.ofList (rs.take i) • (⊤ : Submodule R M)` we use `⨆ (j : Fin i), rs[j] • (⊤ : AddSubgroup M)`. However it's not clear that this is a useful generalization. If we add the assumption `[SMulCommClass α α M]` this is essentially the same as focusing on the commutative ring case, by passing to the monoid ring `ℤ[abelianization of α]`. -/ variable [CommRing R] [AddCommGroup M] [Module R M] open Ideal /-- A sequence `[r₁, …, rₙ]` is weakly regular on `M` iff `rᵢ` is regular on `M⧸(r₁, …, rᵢ₋₁)M` for all `1 ≤ i ≤ n`. -/ @[mk_iff] structure IsWeaklyRegular (rs : List R) : Prop where regular_mod_prev : ∀ i (h : i < rs.length), IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] lemma isWeaklyRegular_iff_Fin (rs : List R) : IsWeaklyRegular M rs ↔ ∀ (i : Fin rs.length), IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i] := Iff.trans (isWeaklyRegular_iff M rs) (Iff.symm Fin.forall_iff) /-- A weakly regular sequence `rs` on `M` is regular if also `M/rsM ≠ 0`. -/ @[mk_iff] structure IsRegular (rs : List R) : Prop extends IsWeaklyRegular M rs where top_ne_smul : (⊤ : Submodule R M) ≠ Ideal.ofList rs • ⊤ end Definitions section Congr variable {S M} [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] open DistribMulAction AddSubgroup in private lemma _root_.AddHom.map_smul_top_toAddSubgroup_of_surjective {f : M →+ M₂} {as : List R} {bs : List S} (hf : Function.Surjective f) (h : List.Forall₂ (fun r s => ∀ x, f (r • x) = s • f x) as bs) : (Ideal.ofList as • ⊤ : Submodule R M).toAddSubgroup.map f = (Ideal.ofList bs • ⊤ : Submodule S M₂).toAddSubgroup := by induction h with | nil => convert AddSubgroup.map_bot f using 1 <;> rw [Ideal.ofList_nil, bot_smul, bot_toAddSubgroup] | @cons r s _ _ h _ ih => conv => congr <;> rw [Ideal.ofList_cons, sup_smul, sup_toAddSubgroup, ideal_span_singleton_smul, pointwise_smul_toAddSubgroup, top_toAddSubgroup, pointwise_smul_def] apply DFunLike.ext (f.comp (toAddMonoidEnd R M r)) ((toAddMonoidEnd S M₂ s).comp f) at h rw [AddSubgroup.map_sup, ih, map_map, h, ← map_map, map_top_of_surjective f hf] lemma _root_.AddEquiv.isWeaklyRegular_congr {e : M ≃+ M₂} {as bs} (h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) : IsWeaklyRegular M as ↔ IsWeaklyRegular M₂ bs := by conv => congr <;> rw [isWeaklyRegular_iff_Fin] let e' i : (M ⧸ (Ideal.ofList (as.take i) • ⊤ : Submodule R M)) ≃+ M₂ ⧸ (Ideal.ofList (bs.take i) • ⊤ : Submodule S M₂) := QuotientAddGroup.congr _ _ e <| AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective <| List.forall₂_take i h refine (finCongr h.length_eq).forall_congr @fun _ => (e' _).isSMulRegular_congr ?_ exact (mkQ_surjective _).forall.mpr fun _ => congrArg (mkQ _) (h.get _ _ _) lemma _root_.LinearEquiv.isWeaklyRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) : IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ (rs.map σ) := e.toAddEquiv.isWeaklyRegular_congr <| List.forall₂_map_right_iff.mpr <| List.forall₂_same.mpr fun r _ x => e.map_smul' r x lemma _root_.LinearEquiv.isWeaklyRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) : IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ rs := Iff.trans (e.isWeaklyRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id lemma _root_.AddEquiv.isRegular_congr {e : M ≃+ M₂} {as bs} (h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) : IsRegular M as ↔ IsRegular M₂ bs := by conv => congr <;> rw [isRegular_iff, ne_eq, eq_comm, ← subsingleton_quotient_iff_eq_top] let e' := QuotientAddGroup.congr _ _ e <| AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective h exact and_congr (e.isWeaklyRegular_congr h) e'.subsingleton_congr.not lemma _root_.LinearEquiv.isRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) : IsRegular M rs ↔ IsRegular M₂ (rs.map σ) := e.toAddEquiv.isRegular_congr <| List.forall₂_map_right_iff.mpr <| List.forall₂_same.mpr fun r _ x => e.map_smul' r x lemma _root_.LinearEquiv.isRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) : IsRegular M rs ↔ IsRegular M₂ rs := Iff.trans (e.isRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id end Congr lemma isWeaklyRegular_map_algebraMap_iff [CommRing R] [CommRing S] [Algebra R S] [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] (rs : List R) : IsWeaklyRegular M (rs.map (algebraMap R S)) ↔ IsWeaklyRegular M rs := (AddEquiv.refl M).isWeaklyRegular_congr <| List.forall₂_map_left_iff.mpr <| List.forall₂_same.mpr fun r _ => algebraMap_smul S r variable [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] @[simp] lemma isWeaklyRegular_cons_iff (r : R) (rs : List R) : IsWeaklyRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) rs := have := Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤) let e i := quotOfListConsSMulTopEquivQuotSMulTopInner M r (rs.take i) Iff.trans (isWeaklyRegular_iff_Fin _ _) <| Iff.trans Fin.forall_iff_succ <| and_congr ((quotEquivOfEqBot _ this).isSMulRegular_congr r) <| Iff.trans (forall_congr' fun i => (e i).isSMulRegular_congr (rs.get i)) (isWeaklyRegular_iff_Fin _ _).symm lemma isWeaklyRegular_cons_iff' (r : R) (rs : List R) : IsWeaklyRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := Iff.trans (isWeaklyRegular_cons_iff M r rs) <| and_congr_right' <| Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.span {r}) _ rs @[simp] lemma isRegular_cons_iff (r : R) (rs : List R) : IsRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) rs := by rw [isRegular_iff, isRegular_iff, isWeaklyRegular_cons_iff M r rs, ne_eq, top_eq_ofList_cons_smul_iff, and_assoc] lemma isRegular_cons_iff' (r : R) (rs : List R) : IsRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := by conv => congr <;> rw [isRegular_iff, ne_eq] rw [isWeaklyRegular_cons_iff', ← restrictScalars_inj R (R ⧸ _), ← Ideal.map_ofList, ← Ideal.Quotient.algebraMap_eq, Ideal.smul_restrictScalars, restrictScalars_top, top_eq_ofList_cons_smul_iff, and_assoc] variable {M} namespace IsWeaklyRegular variable (R M) in @[simp] lemma nil : IsWeaklyRegular M ([] : List R) := .mk (False.elim <| Nat.not_lt_zero · ·) lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsWeaklyRegular (QuotSMulTop r M) rs) : IsWeaklyRegular M (r :: rs) := (isWeaklyRegular_cons_iff M r rs).mpr ⟨h1, h2⟩ lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) : IsWeaklyRegular M (r :: rs) := (isWeaklyRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩ /-- Weakly regular sequences can be inductively characterized by: * The empty sequence is weakly regular on any module. * If `r` is regular on `M` and `rs` is a weakly regular sequence on `M⧸rM` then the sequence obtained from `rs` by prepending `r` is weakly regular on `M`. This is the induction principle produced by the inductive definition above. The motive will usually be valued in `Prop`, but `Sort*` works too. -/ @[induction_eliminator] def recIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [] (nil R M)) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsWeaklyRegular (QuotSMulTop r M) rs) → (ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) : {M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive M rs h | M, _, _, [], _ => nil M | M, _, _, r :: rs, h => let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff M r rs).mp h cons r rs h1 h2 (recIterModByRegular nil cons h2) /-- A simplified version of `IsWeaklyRegular.recIterModByRegular` where the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/ def ndrecIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M []) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) rs → motive (QuotSMulTop r M) rs → motive M (r :: rs)) {M} [AddCommGroup M] [Module R M] {rs} : IsWeaklyRegular M rs → motive M rs := recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons /-- An alternate induction principle from `IsWeaklyRegular.recIterModByRegular` where we mod out by successive elements in both the module and the base ring. This is useful for propagating certain properties of the initial `M`, e.g. faithfulness or freeness, throughout the induction. -/ def recIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → motive R M [] (nil R M)) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) → (ih : motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) → motive R M (r :: rs) (cons' h1 h2)) : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive R M rs h | R, _, M, _, _, [], _ => nil R M | _, _, M, _, _, r :: rs, h => let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff' M r rs).mp h cons r rs h1 h2 (recIterModByRegularWithRing nil cons h2) termination_by _ _ _ _ _ rs => List.length rs /-- A simplified version of `IsWeaklyRegular.recIterModByRegularWithRing` where the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/ def ndrecWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → motive R M []) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} : IsWeaklyRegular M rs → motive R M rs := recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs) nil cons end IsWeaklyRegular section variable (M) lemma isWeaklyRegular_singleton_iff (r : R) : IsWeaklyRegular M [r] ↔ IsSMulRegular M r := Iff.trans (isWeaklyRegular_cons_iff M r []) (and_iff_left (.nil R _)) lemma isWeaklyRegular_append_iff (rs₁ rs₂ : List R) : IsWeaklyRegular M (rs₁ ++ rs₂) ↔ IsWeaklyRegular M rs₁ ∧ IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M)) rs₂ := by induction rs₁ generalizing M with | nil => refine Iff.symm <| Iff.trans (and_iff_right (.nil R M)) ?_ refine (quotEquivOfEqBot _ ?_).isWeaklyRegular_congr rs₂ rw [Ideal.ofList_nil, bot_smul] | cons r rs₁ ih => let e := quotOfListConsSMulTopEquivQuotSMulTopInner M r rs₁ rw [List.cons_append, isWeaklyRegular_cons_iff, isWeaklyRegular_cons_iff, ih, ← and_assoc, ← e.isWeaklyRegular_congr rs₂] lemma isWeaklyRegular_append_iff' (rs₁ rs₂ : List R) : IsWeaklyRegular M (rs₁ ++ rs₂) ↔ IsWeaklyRegular M rs₁ ∧ IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M)) (rs₂.map (Ideal.Quotient.mk (Ideal.ofList rs₁))) := Iff.trans (isWeaklyRegular_append_iff M rs₁ rs₂) <| and_congr_right' <| Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.ofList rs₁) _ rs₂ end namespace IsRegular variable (R M) in lemma nil [Nontrivial M] : IsRegular M ([] : List R) where toIsWeaklyRegular := IsWeaklyRegular.nil R M top_ne_smul h := by rw [Ideal.ofList_nil, bot_smul, eq_comm, subsingleton_iff_bot_eq_top] at h exact not_subsingleton M ((Submodule.subsingleton_iff _).mp h) lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsRegular (QuotSMulTop r M) rs) : IsRegular M (r :: rs) := (isRegular_cons_iff M r rs).mpr ⟨h1, h2⟩ lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) : IsRegular M (r :: rs) := (isRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩ /-- Regular sequences can be inductively characterized by: * The empty sequence is regular on any nonzero module. * If `r` is regular on `M` and `rs` is a regular sequence on `M⧸rM` then the sequence obtained from `rs` by prepending `r` is regular on `M`. This is the induction principle produced by the inductive definition above. The motive will usually be valued in `Prop`, but `Sort*` works too. -/ @[induction_eliminator] def recIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsRegular M rs → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M [] (nil R M)) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) rs) → (ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) {M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive M rs h := h.toIsWeaklyRegular.recIterModByRegular (motive := fun N _ _ rs' h' => ∀ h'', motive N rs' ⟨h', h''⟩) (fun N _ _ h' => haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil N) (fun r rs' h1 h2 h3 h4 => have ⟨h5, h6⟩ := (isRegular_cons_iff _ _ _).mp ⟨h2.cons h1, h4⟩ cons r rs' h5 h6 (h3 h6.top_ne_smul)) h.top_ne_smul /-- A simplified version of `IsRegular.recIterModByRegular` where the motive is not allowed to depend on the proof of `IsRegular`. -/ def ndrecIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M []) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) rs → motive (QuotSMulTop r M) rs → motive M (r :: rs)) {M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive M rs := recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons /-- An alternate induction principle from `IsRegular.recIterModByRegular` where we mod out by successive elements in both the module and the base ring. This is useful for propagating certain properties of the initial `M`, e.g. faithfulness or freeness, throughout the induction. -/ def recIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsRegular M rs → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M [] (nil R M)) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) → (ih : motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) → motive R M (r :: rs) (cons' h1 h2)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive R M rs h := h.toIsWeaklyRegular.recIterModByRegularWithRing (motive := fun R _ N _ _ rs' h' => ∀ h'', motive R N rs' ⟨h', h''⟩) (fun R _ N _ _ h' => haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil R N) (fun r rs' h1 h2 h3 h4 => have ⟨h5, h6⟩ := (isRegular_cons_iff' _ _ _).mp ⟨h2.cons' h1, h4⟩ cons r rs' h5 h6 <| h3 h6.top_ne_smul) h.top_ne_smul /-- A simplified version of `IsRegular.recIterModByRegularWithRing` where the motive is not allowed to depend on the proof of `IsRegular`. -/ def ndrecIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M []) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive (R ⧸ Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive R M rs := recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs) nil cons lemma quot_ofList_smul_nontrivial {rs : List R} (h : IsRegular M rs) (N : Submodule R M) : Nontrivial (M ⧸ Ideal.ofList rs • N) := Submodule.Quotient.nontrivial_of_lt_top _ <| lt_of_le_of_lt (smul_mono_right _ le_top) h.top_ne_smul.symm.lt_top lemma nontrivial {rs : List R} (h : IsRegular M rs) : Nontrivial M := haveI := quot_ofList_smul_nontrivial h ⊤ (mkQ_surjective (Ideal.ofList rs • ⊤ : Submodule R M)).nontrivial end IsRegular lemma isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator [Nontrivial M] [Module.Finite R M] {rs : List R} (h : ∀ r ∈ rs, r ∈ Ideal.jacobson (Module.annihilator R M)) : IsRegular M rs ↔ IsWeaklyRegular M rs := Iff.trans (isRegular_iff M rs) <| and_iff_left <| top_ne_ideal_smul_of_le_jacobson_annihilator <| Ideal.span_le.mpr h lemma _root_.IsLocalRing.isRegular_iff_isWeaklyRegular_of_subset_maximalIdeal [IsLocalRing R] [Nontrivial M] [Module.Finite R M] {rs : List R} (h : ∀ r ∈ rs, r ∈ IsLocalRing.maximalIdeal R) : IsRegular M rs ↔ IsWeaklyRegular M rs := have H h' := bot_ne_top.symm <| annihilator_eq_top_iff.mp <| Eq.trans annihilator_top h' isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator fun r hr => IsLocalRing.jacobson_eq_maximalIdeal (Module.annihilator R M) H ▸ h r hr open IsWeaklyRegular IsArtinian in lemma eq_nil_of_isRegular_on_artinian [IsArtinian R M] : {rs : List R} → IsRegular M rs → rs = [] | [], _ => rfl | r :: rs, h => by rw [isRegular_iff, ne_comm, ← lt_top_iff_ne_top, Ideal.ofList_cons, sup_smul, ideal_span_singleton_smul, isWeaklyRegular_cons_iff] at h refine absurd ?_ (ne_of_lt (lt_of_le_of_lt le_sup_left h.right)) exact Eq.trans (Submodule.map_top _) <| LinearMap.range_eq_top.mpr <| surjective_of_injective_endomorphism (LinearMap.lsmul R M r) h.left.left lemma IsWeaklyRegular.isWeaklyRegular_lTensor [Module.Flat R M₂] {rs : List R} (h : IsWeaklyRegular M rs) : IsWeaklyRegular (M₂ ⊗[R] M) rs := by induction h with | nil N => exact nil R (M₂ ⊗[R] N) | @cons N _ _ r rs' h1 _ ih => let e := tensorQuotSMulTopEquivQuotSMulTop r M₂ N exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.lTensor M₂) lemma IsWeaklyRegular.isWeaklyRegular_rTensor [Module.Flat R M₂] {rs : List R} (h : IsWeaklyRegular M rs) : IsWeaklyRegular (M ⊗[R] M₂) rs := by induction h with | nil N => exact nil R (N ⊗[R] M₂) | @cons N _ _ r rs' h1 _ ih => let e := quotSMulTopTensorEquivQuotSMulTop r M₂ N exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.rTensor M₂) -- TODO: apply the above to localization and completion (Corollary 1.1.3 in B&H) lemma map_first_exact_on_four_term_right_exact_of_isSMulRegular_last {rs : List R} {f₁ : M →ₗ[R] M₂} {f₂ : M₂ →ₗ[R] M₃} {f₃ : M₃ →ₗ[R] M₄} (h₁₂ : Exact f₁ f₂) (h₂₃ : Exact f₂ f₃) (h₃ : Surjective f₃) (h₄ : IsWeaklyRegular M₄ rs) : Exact (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₁)) (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₂)) := by induction h₄ generalizing M M₂ M₃ with | nil => apply (Exact.iff_of_ladder_linearEquiv ?_ ?_).mp h₁₂ any_goals exact quotEquivOfEqBot _ <| Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤) all_goals exact quot_hom_ext _ _ _ fun _ => rfl | cons r rs h₄ _ ih => specialize ih (map_first_exact_on_four_term_exact_of_isSMulRegular_last h₁₂ h₂₃ h₄) (map_exact r h₂₃ h₃) (map_surjective r h₃) have H₁ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₁ have H₂ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₂ exact (Exact.iff_of_ladder_linearEquiv H₁.symm H₂.symm).mp ih -- todo: modding out a complex by a regular sequence (prop 1.1.5 in B&H) section Perm open LinearMap in private lemma IsWeaklyRegular.swap {a b : R} (h1 : IsWeaklyRegular M [a, b]) (h2 : torsionBy R M b = a • torsionBy R M b → torsionBy R M b = ⊥) : IsWeaklyRegular M [b, a] := by rw [isWeaklyRegular_cons_iff, isWeaklyRegular_singleton_iff] at h1 ⊢ obtain ⟨ha, hb⟩ := h1 rw [← isSMulRegular_iff_torsionBy_eq_bot] at h2 specialize h2 (le_antisymm ?_ (smul_le_self_of_tower a (torsionBy R M b))) · refine le_of_eq_of_le ?_ <| smul_top_inf_eq_smul_of_isSMulRegular_on_quot <| ha.of_injective _ <| ker_eq_bot.mp <| ker_liftQ_eq_bot' _ (lsmul R M b) rfl rw [← (isSMulRegular_on_quot_iff_lsmul_comap_eq _ _).mp hb] exact (inf_eq_right.mpr (ker_le_comap _)).symm · rwa [ha.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, inf_comm, smul_comm, ← h2.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, and_iff_left hb] -- TODO: Equivalence of permutability of regular sequences to regularity of -- subsequences and regularity on poly ring. See [07DW] in stacks project
-- We need a theory of multivariate polynomial modules first -- This is needed due to a bug in the linter set_option linter.unusedVariables false in lemma IsWeaklyRegular.prototype_perm {rs : List R} (h : IsWeaklyRegular M rs) {rs'} (h'' : rs ~ rs') (h' : ∀ a b rs', (a :: b :: rs') <+~ rs → let K := torsionBy R (M ⧸ (Ideal.ofList rs' • ⊤ : Submodule R M)) b K = a • K → K = ⊥) : IsWeaklyRegular M rs' := have H := LinearEquiv.isWeaklyRegular_congr <| quotEquivOfEqBot _ <| Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤) (H rs').mp <| (aux [] h'' (.refl rs) (h''.symm.subperm)) <| (H rs).mpr h where aux {rs₁ rs₂} (rs₀ : List R) (h₁₂ : rs₁ ~ rs₂) (H₁ : rs₀ ++ rs₁ <+~ rs) (H₃ : rs₀ ++ rs₂ <+~ rs) (h : IsWeaklyRegular (M ⧸ (Ideal.ofList rs₀ • ⊤ : Submodule R M)) rs₁) : IsWeaklyRegular (M ⧸ (Ideal.ofList rs₀ • ⊤ : Submodule R M)) rs₂ := by { induction h₁₂ generalizing rs₀ with | nil => exact .nil R _ | cons r _ ih => let e := quotOfListConsSMulTopEquivQuotSMulTopOuter M r rs₀ rw [isWeaklyRegular_cons_iff, ← e.isWeaklyRegular_congr] at h ⊢ refine h.imp_right (ih (r :: rs₀) ?_ ?_) <;> exact List.perm_middle.subperm_right.mp ‹_› | swap a b t => rw [show ∀ x y z, x :: y :: z = [x, y] ++ z from fun _ _ _ => rfl, isWeaklyRegular_append_iff] at h ⊢ have : Ideal.ofList [b, a] = Ideal.ofList [a, b] := congrArg Ideal.span <| Set.ext fun _ => (List.Perm.swap a b []).mem_iff rw [(quotEquivOfEq _ _ (congrArg₂ _ this rfl)).isWeaklyRegular_congr] at h rw [List.append_cons, List.append_cons, List.append_assoc _ [b] [a]] at H₁ apply (List.sublist_append_left (rs₀ ++ [b, a]) _).subperm.trans at H₁ apply List.perm_append_comm.subperm.trans at H₁
Mathlib/RingTheory/Regular/RegularSequence.lean
595
625
/- 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.Independence.Kernel import Mathlib.Probability.Kernel.Condexp /-! # Conditional Independence We define conditional independence of sets/σ-algebras/functions with respect to a σ-algebra. Two σ-algebras `m₁` and `m₂` are conditionally independent given a third σ-algebra `m'` if for all `m₁`-measurable sets `t₁` and `m₂`-measurable sets `t₂`, `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`. On standard Borel spaces, the conditional expectation with respect to `m'` defines a kernel `ProbabilityTheory.condExpKernel`, and the definition above is equivalent to `∀ᵐ ω ∂μ, condExpKernel μ m' ω (t₁ ∩ t₂) = condExpKernel μ m' ω t₁ * condExpKernel μ m' ω t₂`. We use this property as the definition of conditional independence. ## Main definitions We provide four definitions of conditional independence: * `iCondIndepSets`: conditional independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to be used with π-systems. * `iCondIndep`: conditional independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`, * `iCondIndepSet`: conditional independence of a family of sets `s : ι → Set Ω`, * `iCondIndepFun`: conditional independence of a family of functions. For measurable spaces `m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`. Additionally, we provide four corresponding statements for two measurable space structures (resp. sets of sets, sets, functions) instead of a family. These properties are denoted by the same names as for a family, but without the starting `i`, for example `CondIndepFun` is the version of `iCondIndepFun` for two functions. ## Main statements * `ProbabilityTheory.iCondIndepSets.iCondIndep`: if π-systems are conditionally independent as sets of sets, then the measurable space structures they generate are conditionally independent. * `ProbabilityTheory.condIndepSets.condIndep`: variant with two π-systems. ## Implementation notes The definitions of conditional independence in this file are a particular case of independence with respect to a kernel and a measure, as defined in the file `Probability/Independence/Kernel.lean`. The kernel used is `ProbabilityTheory.condExpKernel`. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {Ω ι : Type*} section Definitions section variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ) /-- A family of sets of sets `π : ι → Set (Set Ω)` is conditionally independent given `m'` with respect to 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 `μ⟦⋂ i in s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, μ⟦f i | m'⟧`. See `ProbabilityTheory.iCondIndepSets_iff`. It will be used for families of pi_systems. -/ def iCondIndepSets (π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndepSets π (condExpKernel μ m') (μ.trim hm') /-- Two sets of sets `s₁, s₂` are conditionally independent given `m'` with respect to a measure `μ` if for any sets `t₁ ∈ s₁, t₂ ∈ s₂`, then `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`. See `ProbabilityTheory.condIndepSets_iff`. -/ def CondIndepSets (s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.IndepSets s1 s2 (condExpKernel μ m') (μ.trim hm') /-- A family of measurable space structures (i.e. of σ-algebras) is conditionally independent given `m'` with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. `m : ι → MeasurableSpace Ω` is conditionally independent given `m'` with respect to measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ⟦⋂ i in s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, μ⟦f i | m'⟧ `. See `ProbabilityTheory.iCondIndep_iff`. -/ def iCondIndep (m : ι → MeasurableSpace Ω) (μ : @Measure Ω mΩ := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndep m (condExpKernel (mΩ := mΩ) μ m') (μ.trim hm') end /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are conditionally independent given `m'` with respect to a measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `μ⟦t₁ ∩ t₂ | m'⟧ =ᵐ[μ] μ⟦t₁ | m'⟧ * μ⟦t₂ | m'⟧`. See `ProbabilityTheory.condIndep_iff`. -/ def CondIndep (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.Indep m₁ m₂ (condExpKernel μ m') (μ.trim hm') section variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ) /-- A family of sets is conditionally independent if the family of measurable space structures they generate is conditionally independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. See `ProbabilityTheory.iCondIndepSet_iff`. -/ def iCondIndepSet (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndepSet s (condExpKernel μ m') (μ.trim hm') /-- Two sets are conditionally independent if the two measurable space structures they generate are conditionally independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. See `ProbabilityTheory.condIndepSet_iff`. -/ def CondIndepSet (s t : Set Ω) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.IndepSet s t (condExpKernel μ m') (μ.trim hm') /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is conditionally independent if the family of measurable space structures they generate on `Ω` is conditionally independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `m.comap g`. See `ProbabilityTheory.iCondIndepFun_iff`. -/ def iCondIndepFun {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)] (f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.iIndepFun f (condExpKernel μ m') (μ.trim hm') /-- Two functions are conditionally independent if the two measurable space structures they generate are conditionally independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `m.comap f`. See `ProbabilityTheory.condIndepFun_iff`. -/ def CondIndepFun {β γ : Type*} [MeasurableSpace β] [MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) [IsFiniteMeasure μ] : Prop := Kernel.IndepFun f g (condExpKernel μ m') (μ.trim hm') end end Definitions section DefinitionLemmas section variable (m' : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ) lemma iCondIndepSets_iff (π : ι → Set (Set Ω)) (hπ : ∀ i s (_hs : s ∈ π i), MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSets m' hm' π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), μ⟦⋂ i ∈ s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦f i | m'⟧) := by simp only [iCondIndepSets, Kernel.iIndepSets] have h_eq' : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i) i (_hi : i ∈ s), (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω (f i))) =ᵐ[μ] μ⟦f i | m'⟧ := fun s f H i hi ↦ condExpKernel_ae_eq_condExp hm' (hπ i (f i) (H i hi)) have h_eq : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i), ∀ᵐ ω ∂μ, ∀ i ∈ s, ENNReal.toReal (condExpKernel μ m' ω (f i)) = (μ⟦f i | m'⟧) ω := by intros s f H simp_rw [← Finset.mem_coe] rw [ae_ball_iff (Finset.countable_toSet s)] exact h_eq' s f H have h_inter_eq : ∀ (s : Finset ι) (f : ι → Set Ω) (_H : ∀ i, i ∈ s → f i ∈ π i), (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω (⋂ i ∈ s, f i))) =ᵐ[μ] μ⟦⋂ i ∈ s, f i | m'⟧ := by refine fun s f H ↦ condExpKernel_ae_eq_condExp hm' ?_ exact MeasurableSet.biInter (Finset.countable_toSet _) (fun i hi ↦ hπ i _ (H i hi)) refine ⟨fun h s f hf ↦ ?_, fun h s f hf ↦ ?_⟩ <;> specialize h s hf · have h' := ae_eq_of_ae_eq_trim h filter_upwards [h_eq s f hf, h_inter_eq s f hf, h'] with ω h_eq h_inter_eq h' rw [← h_inter_eq, h', ENNReal.toReal_prod, Finset.prod_apply] exact Finset.prod_congr rfl h_eq · refine ((stronglyMeasurable_condExpKernel ?_).ae_eq_trim_iff hm' ?_).mpr ?_ · exact .biInter (Finset.countable_toSet _) (fun i hi ↦ hπ i _ (hf i hi)) · refine Measurable.stronglyMeasurable ?_ exact Finset.measurable_prod s (fun i hi ↦ measurable_condExpKernel (hπ i _ (hf i hi))) filter_upwards [h_eq s f hf, h_inter_eq s f hf, h] with ω h_eq h_inter_eq h have h_ne_top : condExpKernel μ m' ω (⋂ i ∈ s, f i) ≠ ∞ := (measure_ne_top (condExpKernel μ m' ω) _) have : (∏ i ∈ s, condExpKernel μ m' ω (f i)) ≠ ∞ := ENNReal.prod_ne_top fun _ _ ↦ measure_ne_top (condExpKernel μ m' ω) _ rw [← ENNReal.ofReal_toReal h_ne_top, h_inter_eq, h, Finset.prod_apply, ← ENNReal.ofReal_toReal this, ENNReal.toReal_prod] congr 1 exact Finset.prod_congr rfl (fun i hi ↦ (h_eq i hi).symm) lemma condIndepSets_iff (s1 s2 : Set (Set Ω)) (hs1 : ∀ s ∈ s1, MeasurableSet s) (hs2 : ∀ s ∈ s2, MeasurableSet s) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndepSets m' hm' s1 s2 μ ↔ ∀ (t1 t2 : Set Ω) (_ : t1 ∈ s1) (_ : t2 ∈ s2), (μ⟦t1 ∩ t2 | m'⟧) =ᵐ[μ] (μ⟦t1 | m'⟧) * (μ⟦t2 | m'⟧) := by simp only [CondIndepSets, Kernel.IndepSets] have hs1_eq : ∀ s ∈ s1, (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω s)) =ᵐ[μ] μ⟦s | m'⟧ := fun s hs ↦ condExpKernel_ae_eq_condExp hm' (hs1 s hs) have hs2_eq : ∀ s ∈ s2, (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω s)) =ᵐ[μ] μ⟦s | m'⟧ := fun s hs ↦ condExpKernel_ae_eq_condExp hm' (hs2 s hs) have hs12_eq : ∀ s ∈ s1, ∀ t ∈ s2, (fun ω ↦ ENNReal.toReal (condExpKernel μ m' ω (s ∩ t))) =ᵐ[μ] μ⟦s ∩ t | m'⟧ := fun s hs t ht ↦ condExpKernel_ae_eq_condExp hm' ((hs1 s hs).inter ((hs2 t ht))) refine ⟨fun h s t hs ht ↦ ?_, fun h s t hs ht ↦ ?_⟩ <;> specialize h s t hs ht · have h' := ae_eq_of_ae_eq_trim h filter_upwards [hs1_eq s hs, hs2_eq t ht, hs12_eq s hs t ht, h'] with ω hs_eq ht_eq hst_eq h' rw [← hst_eq, Pi.mul_apply, ← hs_eq, ← ht_eq, h', ENNReal.toReal_mul] · refine ((stronglyMeasurable_condExpKernel ((hs1 s hs).inter (hs2 t ht))).ae_eq_trim_iff hm' ((measurable_condExpKernel (hs1 s hs)).mul (measurable_condExpKernel (hs2 t ht))).stronglyMeasurable).mpr ?_ filter_upwards [hs1_eq s hs, hs2_eq t ht, hs12_eq s hs t ht, h] with ω hs_eq ht_eq hst_eq h have h_ne_top : condExpKernel μ m' ω (s ∩ t) ≠ ∞ := measure_ne_top (condExpKernel μ m' ω) _ rw [← ENNReal.ofReal_toReal h_ne_top, hst_eq, h, Pi.mul_apply, ← hs_eq, ← ht_eq, ← ENNReal.toReal_mul, ENNReal.ofReal_toReal] exact ENNReal.mul_ne_top (measure_ne_top (condExpKernel μ m' ω) s) (measure_ne_top (condExpKernel μ m' ω) t) lemma iCondIndepSets_singleton_iff (s : ι → Set Ω) (hπ : ∀ i, MeasurableSet (s i)) (μ : Measure Ω) [IsFiniteMeasure μ] : iCondIndepSets m' hm' (fun i ↦ {s i}) μ ↔ ∀ S : Finset ι, μ⟦⋂ i ∈ S, s i | m'⟧ =ᵐ[μ] ∏ i ∈ S, (μ⟦s i | m'⟧) := by rw [iCondIndepSets_iff] · simp only [Set.mem_singleton_iff] refine ⟨fun h S ↦ h S (fun i _ ↦ rfl), fun h S f hf ↦ ?_⟩ filter_upwards [h S] with a ha refine Eq.trans ?_ (ha.trans ?_) · congr apply congr_arg₂ · exact Set.iInter₂_congr hf · rfl · simp_rw [Finset.prod_apply] refine Finset.prod_congr rfl (fun i hi ↦ ?_) rw [hf i hi] · simpa only [Set.mem_singleton_iff, forall_eq] theorem condIndepSets_singleton_iff {μ : Measure Ω} [IsFiniteMeasure μ] {s t : Set Ω} (hs : MeasurableSet s) (ht : MeasurableSet t) : CondIndepSets m' hm' {s} {t} μ ↔ (μ⟦s ∩ t | m'⟧) =ᵐ[μ] (μ⟦s | m'⟧) * (μ⟦t | m'⟧) := by rw [condIndepSets_iff _ _ _ _ ?_ ?_] · simp only [Set.mem_singleton_iff, forall_eq_apply_imp_iff, forall_eq] · intros s' hs' rw [Set.mem_singleton_iff] at hs' rwa [hs'] · intros s' hs' rw [Set.mem_singleton_iff] at hs' rwa [hs'] lemma iCondIndep_iff_iCondIndepSets (m : ι → MeasurableSpace Ω) (μ : @Measure Ω mΩ) [IsFiniteMeasure μ] : iCondIndep m' hm' m μ ↔ iCondIndepSets m' hm' (fun x ↦ {s | MeasurableSet[m x] s}) μ := by simp only [iCondIndep, iCondIndepSets, Kernel.iIndep] lemma iCondIndep_iff (m : ι → MeasurableSpace Ω) (hm : ∀ i, m i ≤ mΩ) (μ : @Measure Ω mΩ) [IsFiniteMeasure μ] : iCondIndep m' hm' m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)), μ⟦⋂ i ∈ s, f i | m'⟧ =ᵐ[μ] ∏ i ∈ s, (μ⟦f i | m'⟧) := by rw [iCondIndep_iff_iCondIndepSets, iCondIndepSets_iff] · rfl · exact hm end section CondIndep lemma condIndep_iff_condIndepSets (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ) (μ : Measure Ω ) [IsFiniteMeasure μ] : CondIndep m' m₁ m₂ hm' μ ↔ CondIndepSets m' hm' {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by simp only [CondIndep, CondIndepSets, Kernel.Indep]
lemma condIndep_iff (m' m₁ m₂ : MeasurableSpace Ω) {mΩ : MeasurableSpace Ω} [StandardBorelSpace Ω] (hm' : m' ≤ mΩ) (hm₁ : m₁ ≤ mΩ) (hm₂ : m₂ ≤ mΩ) (μ : Measure Ω) [IsFiniteMeasure μ] : CondIndep m' m₁ m₂ hm' μ ↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2
Mathlib/Probability/Independence/Conditional.lean
269
273
/- 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₀] theorem div_mul_eq_mul_div₀ (a b c : G₀) : a / c * b = a * b / c := by simp_rw [div_eq_mul_inv, mul_assoc, mul_comm c⁻¹] lemma div_sq_cancel (a b : G₀) : a ^ 2 * b / a = a * b := by obtain rfl | ha := eq_or_ne a 0 · simp · rw [sq, mul_assoc, mul_div_cancel_left₀ _ ha] end CommGroupWithZero
Mathlib/Algebra/GroupWithZero/Basic.lean
491
491
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Data.Set.Finite.Lemmas import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Localization.FractionRing import Mathlib.SetTheory.Cardinal.Order /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ assert_not_exists Ideal open Multiset Finset noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : ℕ} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then ∅ else Classical.choose (exists_multiset_roots h) := by rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl theorem card_roots (hp0 : p ≠ 0) : (Multiset.card (roots p) : WithBot ℕ) ≤ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 theorem card_roots' (p : R[X]) : Multiset.card p.roots ≤ natDegree p := by by_cases hp0 : p = 0 · simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree p := calc (Multiset.card (p - C a).roots : WithBot ℕ) ≤ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm ▸ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≤ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 · simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a @[simp] theorem mem_roots' : a ∈ p.roots ↔ p ≠ 0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] theorem mem_roots (hp : p ≠ 0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p ≠ 0 := (mem_roots'.1 h).1 theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S →+* R} (hf : Function.Injective f) {x : R} (hp : p ≠ 0) : x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map] lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p ≠ 0) : x ∈ roots p ↔ aeval x p = 0 := by rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w, Algebra.id.map_eq_id, map_id] theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val ⊆ p.roots) : #Z ≤ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) theorem finite_setOf_isRoot {p : R[X]} (hp : p ≠ 0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x ≤ x₀ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p ≠ 0) : ∃ x₀, ∀ x, p.IsRoot x → x₀ ≤ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] theorem roots_mul {p q : R[X]} (hpq : p * q ≠ 0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] theorem roots.le_of_dvd (h : q ≠ 0) : p ∣ q → roots p ≤ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p ≠ C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm ▸ degree_C_le @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] @[simp] theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r) @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) @[simp] theorem roots_one : (1 : R[X]).roots = ∅ := roots_C 1 @[simp] theorem roots_C_mul (p : R[X]) (ha : a ≠ 0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a ≠ 0) : (a • p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] @[simp] theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X - C b).roots = {a⁻¹ * b} := by rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul, Units.inv_mul, C_1, one_mul] exact roots_X_sub_C (a⁻¹ * b) @[simp] theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : Rˣ) : (C (a : R) * X + C b).roots = {-(a⁻¹ * b)} := by rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) ∉ L → L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) ∉ m → m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L theorem roots_prod {ι : Type*} (f : ι → R[X]) (s : Finset ι) : s.prod f ≠ 0 → (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) @[simp] theorem roots_pow (p : R[X]) (n : ℕ) : (p ^ n).roots = n • p.roots := by induction n with | zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero] | succ n ihn => rcases eq_or_ne p 0 with (rfl | hp) · rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] · rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : ℕ) : (X ^ n : R[X]).roots = n • ({0} : Multiset R) := by rw [roots_pow, roots_X]
Mathlib/Algebra/Polynomial/Roots.lean
236
238
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by rcases le_or_lt 0 x with hx | hx · rw [abs_rpow_of_nonneg hx] · rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 · by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] · rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hx₀, mul_inv_cancel₀] exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by calc _ ≤ |x ^ (log x)⁻¹| := le_abs_self _ _ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt · simp [hx] · rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg
variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add]
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
179
184
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, Yaël Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) ⊔ (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) ⊓ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a ∆ b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ assert_not_exists RelIso open Function OrderDual variable {ι α β : Type*} {π : ι → Type*} /-- The symmetric difference operator on a type with `⊔` and `\` is `(A \ B) ⊔ (B \ A)`. -/ def symmDiff [Max α] [SDiff α] (a b : α) : α := a \ b ⊔ b \ a /-- The Heyting bi-implication is `(b ⇨ a) ⊓ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Min α] [HImp α] (a b : α) : α := (b ⇨ a) ⊓ (a ⇨ b) /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " ∆ " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Max α] [SDiff α] (a b : α) : a ∆ b = a \ b ⊔ b \ a := rfl theorem bihimp_def [Min α] [HImp α] (a b : α) : a ⇔ b = (b ⇨ a) ⊓ (a ⇨ b) := rfl theorem symmDiff_eq_Xor' (p q : Prop) : p ∆ q = Xor' p q := rfl @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := iff_iff_implies_and_implies.symm.trans Iff.comm @[simp] theorem Bool.symmDiff_eq_xor : ∀ p q : Bool, p ∆ q = xor p q := by decide section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] (a b c : α) @[simp] theorem toDual_symmDiff : toDual (a ∆ b) = toDual a ⇔ toDual b := rfl @[simp] theorem ofDual_bihimp (a b : αᵒᵈ) : ofDual (a ⇔ b) = ofDual a ∆ ofDual b := rfl theorem symmDiff_comm : a ∆ b = b ∆ a := by simp only [symmDiff, sup_comm] instance symmDiff_isCommutative : Std.Commutative (α := α) (· ∆ ·) := ⟨symmDiff_comm⟩ @[simp] theorem symmDiff_self : a ∆ a = ⊥ := by rw [symmDiff, sup_idem, sdiff_self] @[simp] theorem symmDiff_bot : a ∆ ⊥ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] @[simp] theorem bot_symmDiff : ⊥ ∆ a = a := by rw [symmDiff_comm, symmDiff_bot] @[simp] theorem symmDiff_eq_bot {a b : α} : a ∆ b = ⊥ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] theorem symmDiff_of_le {a b : α} (h : a ≤ b) : a ∆ b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] theorem symmDiff_of_ge {a b : α} (h : b ≤ a) : a ∆ b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] theorem symmDiff_le {a b c : α} (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ∆ b ≤ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb theorem symmDiff_le_iff {a b c : α} : a ∆ b ≤ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] @[simp] theorem symmDiff_le_sup {a b : α} : a ∆ b ≤ a ⊔ b := sup_le_sup sdiff_le sdiff_le theorem symmDiff_eq_sup_sdiff_inf : a ∆ b = (a ⊔ b) \ (a ⊓ b) := by simp [sup_sdiff, symmDiff] theorem Disjoint.symmDiff_eq_sup {a b : α} (h : Disjoint a b) : a ∆ b = a ⊔ b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] theorem symmDiff_sdiff : a ∆ b \ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] @[simp] theorem symmDiff_sdiff_inf : a ∆ b \ (a ⊓ b) = a ∆ b := by rw [symmDiff_sdiff] simp [symmDiff] @[simp] theorem symmDiff_sdiff_eq_sup : a ∆ (b \ a) = a ⊔ b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) ∆ b = a ⊔ b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] @[simp] theorem symmDiff_sup_inf : a ∆ b ⊔ a ⊓ b = a ⊔ b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) · rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup · rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup @[simp] theorem inf_sup_symmDiff : a ⊓ b ⊔ a ∆ b = a ⊔ b := by rw [sup_comm, symmDiff_sup_inf] @[simp] theorem symmDiff_symmDiff_inf : a ∆ b ∆ (a ⊓ b) = a ⊔ b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] @[simp] theorem inf_symmDiff_symmDiff : (a ⊓ b) ∆ (a ∆ b) = a ⊔ b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] theorem symmDiff_triangle : a ∆ c ≤ a ∆ b ⊔ b ∆ c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] theorem le_symmDiff_sup_right (a b : α) : a ≤ (a ∆ b) ⊔ b := by convert symmDiff_triangle a b ⊥ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : α) : b ≤ (a ∆ b) ⊔ a := symmDiff_comm a b ▸ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] (a b c : α) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a ∆ toDual b := rfl @[simp] theorem ofDual_symmDiff (a b : αᵒᵈ) : ofDual (a ∆ b) = ofDual a ⇔ ofDual b := rfl theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(· ⇔ ·), inf_comm] instance bihimp_isCommutative : Std.Commutative (α := α) (· ⇔ ·) := ⟨bihimp_comm⟩ @[simp] theorem bihimp_self : a ⇔ a = ⊤ := by rw [bihimp, inf_idem, himp_self] @[simp] theorem bihimp_top : a ⇔ ⊤ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] @[simp] theorem top_bihimp : ⊤ ⇔ a = a := by rw [bihimp_comm, bihimp_top] @[simp] theorem bihimp_eq_top {a b : α} : a ⇔ b = ⊤ ↔ a = b := @symmDiff_eq_bot αᵒᵈ _ _ _ theorem bihimp_of_le {a b : α} (h : a ≤ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] theorem bihimp_of_ge {a b : α} (h : b ≤ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] theorem le_bihimp {a b c : α} (hb : a ⊓ b ≤ c) (hc : a ⊓ c ≤ b) : a ≤ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb theorem le_bihimp_iff {a b c : α} : a ≤ b ⇔ c ↔ a ⊓ b ≤ c ∧ a ⊓ c ≤ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] @[simp] theorem inf_le_bihimp {a b : α} : a ⊓ b ≤ a ⇔ b := inf_le_inf le_himp le_himp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a ⊔ b ⇨ a ⊓ b := by simp [himp_inf_distrib, bihimp] theorem Codisjoint.bihimp_eq_inf {a b : α} (h : Codisjoint a b) : a ⇔ b = a ⊓ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] theorem himp_bihimp : a ⇨ b ⇔ c = (a ⊓ c ⇨ b) ⊓ (a ⊓ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] @[simp] theorem sup_himp_bihimp : a ⊔ b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a ⊓ b := @symmDiff_sdiff_eq_sup αᵒᵈ _ _ _ @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a ⊓ b := @sdiff_symmDiff_eq_sup αᵒᵈ _ _ _ @[simp] theorem bihimp_inf_sup : a ⇔ b ⊓ (a ⊔ b) = a ⊓ b := @symmDiff_sup_inf αᵒᵈ _ _ _ @[simp] theorem sup_inf_bihimp : (a ⊔ b) ⊓ a ⇔ b = a ⊓ b := @inf_sup_symmDiff αᵒᵈ _ _ _ @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a ⊔ b) = a ⊓ b := @symmDiff_symmDiff_inf αᵒᵈ _ _ _ @[simp] theorem sup_bihimp_bihimp : (a ⊔ b) ⇔ (a ⇔ b) = a ⊓ b := @inf_symmDiff_symmDiff αᵒᵈ _ _ _ theorem bihimp_triangle : a ⇔ b ⊓ b ⇔ c ≤ a ⇔ c := @symmDiff_triangle αᵒᵈ _ _ _ _ end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] (a : α) @[simp] theorem symmDiff_top' : a ∆ ⊤ = ¬a := by simp [symmDiff] @[simp] theorem top_symmDiff' : ⊤ ∆ a = ¬a := by simp [symmDiff] @[simp] theorem hnot_symmDiff_self : (¬a) ∆ a = ⊤ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left @[simp] theorem symmDiff_hnot_self : a ∆ (¬a) = ⊤ := by rw [symmDiff_comm, hnot_symmDiff_self] theorem IsCompl.symmDiff_eq_top {a b : α} (h : IsCompl a b) : a ∆ b = ⊤ := by rw [h.eq_hnot, hnot_symmDiff_self] end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] (a : α) @[simp] theorem bihimp_bot : a ⇔ ⊥ = aᶜ := by simp [bihimp] @[simp] theorem bot_bihimp : ⊥ ⇔ a = aᶜ := by simp [bihimp] @[simp] theorem compl_bihimp_self : aᶜ ⇔ a = ⊥ := @hnot_symmDiff_self αᵒᵈ _ _ @[simp] theorem bihimp_hnot_self : a ⇔ aᶜ = ⊥ := @symmDiff_hnot_self αᵒᵈ _ _ theorem IsCompl.bihimp_eq_bot {a b : α} (h : IsCompl a b) : a ⇔ b = ⊥ := by rw [h.eq_compl, compl_bihimp_self] end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra α] (a b c d : α) @[simp] theorem sup_sdiff_symmDiff : (a ⊔ b) \ a ∆ b = a ⊓ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) theorem disjoint_symmDiff_inf : Disjoint (a ∆ b) (a ⊓ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left theorem inf_symmDiff_distrib_left : a ⊓ b ∆ c = (a ⊓ b) ∆ (a ⊓ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] theorem inf_symmDiff_distrib_right : a ∆ b ⊓ c = (a ⊓ c) ∆ (b ⊓ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] theorem sdiff_symmDiff : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ a ⊓ c \ b := by simp only [(· ∆ ·), sdiff_sdiff_sup_sdiff'] theorem sdiff_symmDiff' : c \ a ∆ b = c ⊓ a ⊓ b ⊔ c \ (a ⊔ b) := by rw [sdiff_symmDiff, sdiff_sup] @[simp] theorem symmDiff_sdiff_left : a ∆ b \ a = b \ a := by rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq] @[simp] theorem symmDiff_sdiff_right : a ∆ b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left] @[simp] theorem sdiff_symmDiff_left : a \ a ∆ b = a ⊓ b := by simp [sdiff_symmDiff] @[simp] theorem sdiff_symmDiff_right : b \ a ∆ b = a ⊓ b := by rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left] theorem symmDiff_eq_sup : a ∆ b = a ⊔ b ↔ Disjoint a b := by refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩ rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h exact h.of_disjoint_inf_of_le le_sup_left @[simp] theorem le_symmDiff_iff_left : a ≤ a ∆ b ↔ Disjoint a b := by refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm ▸ le_sup_left⟩ rw [symmDiff_eq_sup_sdiff_inf] at h exact disjoint_iff_inf_le.mpr (le_sdiff_right.1 <| inf_le_of_left_le h).le @[simp] theorem le_symmDiff_iff_right : b ≤ a ∆ b ↔ Disjoint a b := by rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm] theorem symmDiff_symmDiff_left : a ∆ b ∆ c = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := calc a ∆ b ∆ c = a ∆ b \ c ⊔ c \ a ∆ b := symmDiff_def _ _ _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ (c \ (a ⊔ b) ⊔ c ⊓ a ⊓ b) := by { rw [sdiff_symmDiff', sup_comm (c ⊓ a ⊓ b), symmDiff_sdiff] } _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl theorem symmDiff_symmDiff_right : a ∆ (b ∆ c) = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := calc a ∆ (b ∆ c) = a \ b ∆ c ⊔ b ∆ c \ a := symmDiff_def _ _ _ = a \ (b ⊔ c) ⊔ a ⊓ b ⊓ c ⊔ (b \ (c ⊔ a) ⊔ c \ (b ⊔ a)) := by { rw [sdiff_symmDiff', sup_comm (a ⊓ b ⊓ c), symmDiff_sdiff] } _ = a \ (b ⊔ c) ⊔ b \ (a ⊔ c) ⊔ c \ (a ⊔ b) ⊔ a ⊓ b ⊓ c := by ac_rfl theorem symmDiff_assoc : a ∆ b ∆ c = a ∆ (b ∆ c) := by rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right] instance symmDiff_isAssociative : Std.Associative (α := α) (· ∆ ·) := ⟨symmDiff_assoc⟩ theorem symmDiff_left_comm : a ∆ (b ∆ c) = b ∆ (a ∆ c) := by simp_rw [← symmDiff_assoc, symmDiff_comm] theorem symmDiff_right_comm : a ∆ b ∆ c = a ∆ c ∆ b := by simp_rw [symmDiff_assoc, symmDiff_comm] theorem symmDiff_symmDiff_symmDiff_comm : a ∆ b ∆ (c ∆ d) = a ∆ c ∆ (b ∆ d) := by simp_rw [symmDiff_assoc, symmDiff_left_comm] @[simp] theorem symmDiff_symmDiff_cancel_left : a ∆ (a ∆ b) = b := by simp [← symmDiff_assoc] @[simp] theorem symmDiff_symmDiff_cancel_right : b ∆ a ∆ a = b := by simp [symmDiff_assoc] @[simp] theorem symmDiff_symmDiff_self' : a ∆ b ∆ a = b := by rw [symmDiff_comm, symmDiff_symmDiff_cancel_left] theorem symmDiff_left_involutive (a : α) : Involutive (· ∆ a) := symmDiff_symmDiff_cancel_right _ theorem symmDiff_right_involutive (a : α) : Involutive (a ∆ ·) := symmDiff_symmDiff_cancel_left _ theorem symmDiff_left_injective (a : α) : Injective (· ∆ a) := Function.Involutive.injective (symmDiff_left_involutive a) theorem symmDiff_right_injective (a : α) : Injective (a ∆ ·) := Function.Involutive.injective (symmDiff_right_involutive _) theorem symmDiff_left_surjective (a : α) : Surjective (· ∆ a) := Function.Involutive.surjective (symmDiff_left_involutive _) theorem symmDiff_right_surjective (a : α) : Surjective (a ∆ ·) := Function.Involutive.surjective (symmDiff_right_involutive _) variable {a b c} @[simp] theorem symmDiff_left_inj : a ∆ b = c ∆ b ↔ a = c := (symmDiff_left_injective _).eq_iff @[simp] theorem symmDiff_right_inj : a ∆ b = a ∆ c ↔ b = c := (symmDiff_right_injective _).eq_iff @[simp] theorem symmDiff_eq_left : a ∆ b = a ↔ b = ⊥ := calc a ∆ b = a ↔ a ∆ b = a ∆ ⊥ := by rw [symmDiff_bot] _ ↔ b = ⊥ := by rw [symmDiff_right_inj] @[simp] theorem symmDiff_eq_right : a ∆ b = b ↔ a = ⊥ := by rw [symmDiff_comm, symmDiff_eq_left] protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a ∆ b) c := by rw [symmDiff_eq_sup_sdiff_inf] exact (ha.sup_left hb).disjoint_sdiff_left protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) : Disjoint a (b ∆ c) := (ha.symm.symmDiff_left hb.symm).symm theorem symmDiff_eq_iff_sdiff_eq (ha : a ≤ c) : a ∆ b = c ↔ c \ a = b := by rw [← symmDiff_of_le ha] exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm end GeneralizedBooleanAlgebra section BooleanAlgebra variable [BooleanAlgebra α] (a b c d : α) /-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to the `GeneralizedBooleanAlgebra` ones -/ section CogeneralizedBooleanAlgebra @[simp] theorem inf_himp_bihimp : a ⇔ b ⇨ a ⊓ b = a ⊔ b := @sup_sdiff_symmDiff αᵒᵈ _ _ _ theorem codisjoint_bihimp_sup : Codisjoint (a ⇔ b) (a ⊔ b) := @disjoint_symmDiff_inf αᵒᵈ _ _ _ @[simp] theorem himp_bihimp_left : a ⇨ a ⇔ b = a ⇨ b := @symmDiff_sdiff_left αᵒᵈ _ _ _ @[simp] theorem himp_bihimp_right : b ⇨ a ⇔ b = b ⇨ a := @symmDiff_sdiff_right αᵒᵈ _ _ _ @[simp] theorem bihimp_himp_left : a ⇔ b ⇨ a = a ⊔ b := @sdiff_symmDiff_left αᵒᵈ _ _ _ @[simp] theorem bihimp_himp_right : a ⇔ b ⇨ b = a ⊔ b := @sdiff_symmDiff_right αᵒᵈ _ _ _ @[simp] theorem bihimp_eq_inf : a ⇔ b = a ⊓ b ↔ Codisjoint a b := @symmDiff_eq_sup αᵒᵈ _ _ _ @[simp] theorem bihimp_le_iff_left : a ⇔ b ≤ a ↔ Codisjoint a b := @le_symmDiff_iff_left αᵒᵈ _ _ _ @[simp] theorem bihimp_le_iff_right : a ⇔ b ≤ b ↔ Codisjoint a b := @le_symmDiff_iff_right αᵒᵈ _ _ _ theorem bihimp_assoc : a ⇔ b ⇔ c = a ⇔ (b ⇔ c) := @symmDiff_assoc αᵒᵈ _ _ _ _ instance bihimp_isAssociative : Std.Associative (α := α) (· ⇔ ·) := ⟨bihimp_assoc⟩ theorem bihimp_left_comm : a ⇔ (b ⇔ c) = b ⇔ (a ⇔ c) := by simp_rw [← bihimp_assoc, bihimp_comm] theorem bihimp_right_comm : a ⇔ b ⇔ c = a ⇔ c ⇔ b := by simp_rw [bihimp_assoc, bihimp_comm] theorem bihimp_bihimp_bihimp_comm : a ⇔ b ⇔ (c ⇔ d) = a ⇔ c ⇔ (b ⇔ d) := by simp_rw [bihimp_assoc, bihimp_left_comm] @[simp] theorem bihimp_bihimp_cancel_left : a ⇔ (a ⇔ b) = b := by simp [← bihimp_assoc] @[simp] theorem bihimp_bihimp_cancel_right : b ⇔ a ⇔ a = b := by simp [bihimp_assoc] @[simp] theorem bihimp_bihimp_self : a ⇔ b ⇔ a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left] theorem bihimp_left_involutive (a : α) : Involutive (· ⇔ a) := bihimp_bihimp_cancel_right _ theorem bihimp_right_involutive (a : α) : Involutive (a ⇔ ·) := bihimp_bihimp_cancel_left _ theorem bihimp_left_injective (a : α) : Injective (· ⇔ a) := @symmDiff_left_injective αᵒᵈ _ _ theorem bihimp_right_injective (a : α) : Injective (a ⇔ ·) := @symmDiff_right_injective αᵒᵈ _ _ theorem bihimp_left_surjective (a : α) : Surjective (· ⇔ a) := @symmDiff_left_surjective αᵒᵈ _ _ theorem bihimp_right_surjective (a : α) : Surjective (a ⇔ ·) := @symmDiff_right_surjective αᵒᵈ _ _ variable {a b c} @[simp] theorem bihimp_left_inj : a ⇔ b = c ⇔ b ↔ a = c := (bihimp_left_injective _).eq_iff @[simp] theorem bihimp_right_inj : a ⇔ b = a ⇔ c ↔ b = c := (bihimp_right_injective _).eq_iff @[simp] theorem bihimp_eq_left : a ⇔ b = a ↔ b = ⊤ := @symmDiff_eq_left αᵒᵈ _ _ _ @[simp] theorem bihimp_eq_right : a ⇔ b = b ↔ a = ⊤ := @symmDiff_eq_right αᵒᵈ _ _ _ protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⇔ b) c := (ha.inf_left hb).mono_left inf_le_bihimp protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) : Codisjoint a (b ⇔ c) := (ha.inf_right hb).mono_right inf_le_bihimp end CogeneralizedBooleanAlgebra theorem symmDiff_eq : a ∆ b = a ⊓ bᶜ ⊔ b ⊓ aᶜ := by simp only [(· ∆ ·), sdiff_eq] theorem bihimp_eq : a ⇔ b = (a ⊔ bᶜ) ⊓ (b ⊔ aᶜ) := by simp only [(· ⇔ ·), himp_eq] theorem symmDiff_eq' : a ∆ b = (a ⊔ b) ⊓ (aᶜ ⊔ bᶜ) := by rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf] theorem bihimp_eq' : a ⇔ b = a ⊓ b ⊔ aᶜ ⊓ bᶜ := @symmDiff_eq' αᵒᵈ _ _ _ theorem symmDiff_top : a ∆ ⊤ = aᶜ := symmDiff_top' _ theorem top_symmDiff : ⊤ ∆ a = aᶜ := top_symmDiff' _ @[simp] theorem compl_symmDiff : (a ∆ b)ᶜ = a ⇔ b := by simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm] @[simp] theorem compl_bihimp : (a ⇔ b)ᶜ = a ∆ b := @compl_symmDiff αᵒᵈ _ _ _ @[simp] theorem compl_symmDiff_compl : aᶜ ∆ bᶜ = a ∆ b := (sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq] @[simp] theorem compl_bihimp_compl : aᶜ ⇔ bᶜ = a ⇔ b := @compl_symmDiff_compl αᵒᵈ _ _ _ @[simp] theorem symmDiff_eq_top : a ∆ b = ⊤ ↔ IsCompl a b := by rw [symmDiff_eq', ← compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff, codisjoint_iff, and_comm] @[simp] theorem bihimp_eq_bot : a ⇔ b = ⊥ ↔ IsCompl a b := by rw [bihimp_eq', ← compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff, codisjoint_iff] @[simp] theorem compl_symmDiff_self : aᶜ ∆ a = ⊤ := hnot_symmDiff_self _ @[simp] theorem symmDiff_compl_self : a ∆ aᶜ = ⊤ := symmDiff_hnot_self _ theorem symmDiff_symmDiff_right' : a ∆ (b ∆ c) = a ⊓ b ⊓ c ⊔ a ⊓ bᶜ ⊓ cᶜ ⊔ aᶜ ⊓ b ⊓ cᶜ ⊔ aᶜ ⊓ bᶜ ⊓ c := calc a ∆ (b ∆ c) = a ⊓ (b ⊓ c ⊔ bᶜ ⊓ cᶜ) ⊔ (b ⊓ cᶜ ⊔ c ⊓ bᶜ) ⊓ aᶜ := by
{ rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] }
Mathlib/Order/SymmDiff.lean
639
639
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite import Mathlib.Data.Set.Finite.Powerset /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = ENat.card α := by rw [encard, ENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] @[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl theorem toENat_cardinalMk_subtype (P : α → Prop) : (Cardinal.mk {x // P x}).toENat = {x | P x}.encard := rfl @[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by simp [encard_eq_coe_toFinset_card] @[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp @[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one] theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical simp [encard, ENat.card_congr (Equiv.Set.union h)] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by induction s, h using Set.Finite.induction_on with | empty => simp | insert hat _ ht' => rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ @[simp] theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)] section Lattice theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add @[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_encard theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_inj h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_encard inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_inj WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by rw [encard_le_one_iff, Set.Subsingleton] tauto theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range]
end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
Mathlib/Data/Set/Card.lean
363
375
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.LSeries.HurwitzZetaEven import Mathlib.NumberTheory.LSeries.HurwitzZetaOdd import Mathlib.Analysis.SpecialFunctions.Gamma.Beta /-! # The Hurwitz zeta function This file gives the definition and properties of the following two functions: * The **Hurwitz zeta function**, which is the meromorphic continuation to all `s ∈ ℂ` of the function defined for `1 < re s` by the series `∑' n, 1 / (n + a) ^ s` for a parameter `a ∈ ℝ`, with the sum taken over all `n` such that `n + a > 0`; * the related sum, which we call the "**exponential zeta function**" (does it have a standard name?) `∑' n : ℕ, exp (2 * π * I * n * a) / n ^ s`. ## Main definitions and results * `hurwitzZeta`: the Hurwitz zeta function (defined to be periodic in `a` with period 1) * `expZeta`: the exponential zeta function * `hasSum_hurwitzZeta_of_one_lt_re` and `hasSum_expZeta_of_one_lt_re`: relation to Dirichlet series for `1 < re s` * ` hurwitzZeta_residue_one` shows that the residue at `s = 1` equals `1` * `differentiableAt_hurwitzZeta` and `differentiableAt_expZeta`: analyticity away from `s = 1` * `hurwitzZeta_one_sub` and `expZeta_one_sub`: functional equations `s ↔ 1 - s`. -/ open Set Real Complex Filter Topology namespace HurwitzZeta /-! ## The Hurwitz zeta function -/ /-- The Hurwitz zeta function, which is the meromorphic continuation of `∑ (n : ℕ), 1 / (n + a) ^ s` if `0 ≤ a ≤ 1`. See `hasSum_hurwitzZeta_of_one_lt_re` for the relation to the Dirichlet series in the convergence range. -/ noncomputable def hurwitzZeta (a : UnitAddCircle) (s : ℂ) := hurwitzZetaEven a s + hurwitzZetaOdd a s lemma hurwitzZetaEven_eq (a : UnitAddCircle) (s : ℂ) : hurwitzZetaEven a s = (hurwitzZeta a s + hurwitzZeta (-a) s) / 2 := by simp only [hurwitzZeta, hurwitzZetaEven_neg, hurwitzZetaOdd_neg] ring_nf lemma hurwitzZetaOdd_eq (a : UnitAddCircle) (s : ℂ) : hurwitzZetaOdd a s = (hurwitzZeta a s - hurwitzZeta (-a) s) / 2 := by simp only [hurwitzZeta, hurwitzZetaEven_neg, hurwitzZetaOdd_neg] ring_nf /-- The Hurwitz zeta function is differentiable away from `s = 1`. -/ lemma differentiableAt_hurwitzZeta (a : UnitAddCircle) {s : ℂ} (hs : s ≠ 1) : DifferentiableAt ℂ (hurwitzZeta a) s := (differentiableAt_hurwitzZetaEven a hs).add (differentiable_hurwitzZetaOdd a s) /-- Formula for `hurwitzZeta s` as a Dirichlet series in the convergence range. We restrict to `a ∈ Icc 0 1` to simplify the statement. -/ lemma hasSum_hurwitzZeta_of_one_lt_re {a : ℝ} (ha : a ∈ Icc 0 1) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℕ ↦ 1 / (n + a : ℂ) ^ s) (hurwitzZeta a s) := by convert (hasSum_nat_hurwitzZetaEven_of_mem_Icc ha hs).add (hasSum_nat_hurwitzZetaOdd_of_mem_Icc ha hs) using 1 ext1 n -- plain `ring_nf` works here, but the following is faster: apply show ∀ (x y : ℂ), x = (x + y) / 2 + (x - y) / 2 by intros; ring /-- The residue of the Hurwitz zeta function at `s = 1` is `1`. -/ lemma hurwitzZeta_residue_one (a : UnitAddCircle) : Tendsto (fun s ↦ (s - 1) * hurwitzZeta a s) (𝓝[≠] 1) (𝓝 1) := by simp only [hurwitzZeta, mul_add, (by simp : 𝓝 (1 : ℂ) = 𝓝 (1 + (1 - 1) * hurwitzZetaOdd a 1))] refine (hurwitzZetaEven_residue_one a).add ((Tendsto.mul ?_ ?_).mono_left nhdsWithin_le_nhds) exacts [tendsto_id.sub_const _, (differentiable_hurwitzZetaOdd a).continuous.tendsto _] lemma differentiableAt_hurwitzZeta_sub_one_div (a : UnitAddCircle) : DifferentiableAt ℂ (fun s ↦ hurwitzZeta a s - 1 / (s - 1) / Gammaℝ s) 1 := by simp only [hurwitzZeta, add_sub_right_comm] exact (differentiableAt_hurwitzZetaEven_sub_one_div a).add (differentiable_hurwitzZetaOdd a 1) /-- Expression for `hurwitzZeta a 1` as a limit. (Mathematically `hurwitzZeta a 1` is undefined, but our construction assigns some value to it; this lemma is mostly of interest for determining what that value is). -/ lemma tendsto_hurwitzZeta_sub_one_div_nhds_one (a : UnitAddCircle) : Tendsto (fun s ↦ hurwitzZeta a s - 1 / (s - 1) / Gammaℝ s) (𝓝 1) (𝓝 (hurwitzZeta a 1)) := by simp only [hurwitzZeta, add_sub_right_comm] refine (tendsto_hurwitzZetaEven_sub_one_div_nhds_one a).add (differentiable_hurwitzZetaOdd a 1).continuousAt.tendsto /-- The difference of two Hurwitz zeta functions is differentiable everywhere. -/ lemma differentiable_hurwitzZeta_sub_hurwitzZeta (a b : UnitAddCircle) : Differentiable ℂ (fun s ↦ hurwitzZeta a s - hurwitzZeta b s) := by simp only [hurwitzZeta, add_sub_add_comm] refine (differentiable_hurwitzZetaEven_sub_hurwitzZetaEven a b).add (.sub ?_ ?_) all_goals apply differentiable_hurwitzZetaOdd /-! ## The exponential zeta function -/ /-- Meromorphic continuation of the series `∑' (n : ℕ), exp (2 * π * I * a * n) / n ^ s`. See `hasSum_expZeta_of_one_lt_re` for the relation to the Dirichlet series. -/ noncomputable def expZeta (a : UnitAddCircle) (s : ℂ) := cosZeta a s + I * sinZeta a s lemma cosZeta_eq (a : UnitAddCircle) (s : ℂ) : cosZeta a s = (expZeta a s + expZeta (-a) s) / 2 := by rw [expZeta, expZeta, cosZeta_neg, sinZeta_neg] ring_nf lemma sinZeta_eq (a : UnitAddCircle) (s : ℂ) : sinZeta a s = (expZeta a s - expZeta (-a) s) / (2 * I) := by rw [expZeta, expZeta, cosZeta_neg, sinZeta_neg] field_simp ring_nf lemma hasSum_expZeta_of_one_lt_re (a : ℝ) {s : ℂ} (hs : 1 < re s) : HasSum (fun n : ℕ ↦ cexp (2 * π * I * a * n) / n ^ s) (expZeta a s) := by convert (hasSum_nat_cosZeta a hs).add ((hasSum_nat_sinZeta a hs).mul_left I) using 1 ext1 n simp only [mul_right_comm _ I, ← cos_add_sin_I, push_cast] rw [add_div, mul_div, mul_comm _ I] lemma differentiableAt_expZeta (a : UnitAddCircle) (s : ℂ) (hs : s ≠ 1 ∨ a ≠ 0) : DifferentiableAt ℂ (expZeta a) s := by apply DifferentiableAt.add · exact differentiableAt_cosZeta a hs · apply (differentiableAt_const _).mul (differentiableAt_sinZeta a s) /-- If `a ≠ 0` then the exponential zeta function is analytic everywhere. -/ lemma differentiable_expZeta_of_ne_zero {a : UnitAddCircle} (ha : a ≠ 0) : Differentiable ℂ (expZeta a) := (differentiableAt_expZeta a · (Or.inr ha)) /-- Reformulation of `hasSum_expZeta_of_one_lt_re` using `LSeriesHasSum`. -/ lemma LSeriesHasSum_exp (a : ℝ) {s : ℂ} (hs : 1 < re s) : LSeriesHasSum (cexp <| 2 * π * I * a * ·) s (expZeta a s) := (hasSum_expZeta_of_one_lt_re a hs).congr_fun (LSeries.term_of_ne_zero' (ne_zero_of_one_lt_re hs) _) /-! ## The functional equation -/ lemma hurwitzZeta_one_sub (a : UnitAddCircle) {s : ℂ} (hs : ∀ (n : ℕ), s ≠ -n) (hs' : a ≠ 0 ∨ s ≠ 1) : hurwitzZeta a (1 - s) = (2 * π) ^ (-s) * Gamma s * (exp (-π * I * s / 2) * expZeta a s + exp (π * I * s / 2) * expZeta (-a) s) := by rw [hurwitzZeta, hurwitzZetaEven_one_sub a hs hs', hurwitzZetaOdd_one_sub a hs, expZeta, expZeta, Complex.cos, Complex.sin, sinZeta_neg, cosZeta_neg] rw [show ↑π * I * s / 2 = ↑π * s / 2 * I by ring, show -↑π * I * s / 2 = -(↑π * s / 2) * I by ring] -- these `generalize` commands are not strictly needed for the `ring_nf` call to succeed, but -- make it run faster: generalize (2 * π : ℂ) ^ (-s) = x generalize (↑π * s / 2 * I).exp = y generalize (-(↑π * s / 2) * I).exp = z ring_nf /-- Functional equation for the exponential zeta function. -/ lemma expZeta_one_sub (a : UnitAddCircle) {s : ℂ} (hs : ∀ (n : ℕ), s ≠ 1 - n) :
expZeta a (1 - s) = (2 * π) ^ (-s) * Gamma s * (exp (π * I * s / 2) * hurwitzZeta a s + exp (-π * I * s / 2) * hurwitzZeta (-a) s) := by have hs' (n : ℕ) : s ≠ -↑n := by convert hs (n + 1) using 1 push_cast ring rw [expZeta, cosZeta_one_sub a hs, sinZeta_one_sub a hs', hurwitzZeta, hurwitzZeta, hurwitzZetaEven_neg, hurwitzZetaOdd_neg, Complex.cos, Complex.sin] rw [show ↑π * I * s / 2 = ↑π * s / 2 * I by ring, show -↑π * I * s / 2 = -(↑π * s / 2) * I by ring] -- these `generalize` commands are not strictly needed for the `ring_nf` call to succeed, but -- make it run faster: generalize (2 * π : ℂ) ^ (-s) = x generalize (↑π * s / 2 * I).exp = y generalize (-(↑π * s / 2) * I).exp = z ring_nf rw [I_sq] ring_nf end HurwitzZeta
Mathlib/NumberTheory/LSeries/HurwitzZeta.lean
170
189
/- 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]
Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean
126
129
/- 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
Mathlib/Data/Num/Lemmas.lean
733
734
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Johan Commelin -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.CommRing import Mathlib.Logic.Equiv.Functor import Mathlib.RingTheory.FreeRing /-! # Free commutative rings The theory of the free commutative ring generated by a type `α`. It is isomorphic to the polynomial ring over ℤ with variables in `α` ## Main definitions * `FreeCommRing α` : the free commutative ring on a type α * `lift (f : α → R)` : the ring hom `FreeCommRing α →+* R` induced by functoriality from `f`. * `map (f : α → β)` : the ring hom `FreeCommRing α →*+ FreeCommRing β` induced by functoriality from f. ## Main results `FreeCommRing` has functorial properties (it is an adjoint to the forgetful functor). In this file we have: * `of : α → FreeCommRing α` * `lift (f : α → R) : FreeCommRing α →+* R` * `map (f : α → β) : FreeCommRing α →+* FreeCommRing β` * `freeCommRingEquivMvPolynomialInt : FreeCommRing α ≃+* MvPolynomial α ℤ` : `FreeCommRing α` is isomorphic to a polynomial ring. ## Implementation notes `FreeCommRing α` is implemented not using `MvPolynomial` but directly as the free abelian group on `Multiset α`, the type of monomials in this free commutative ring. ## Tags free commutative ring, free ring -/ noncomputable section open Polynomial universe u v variable (α : Type u) /-- If `α` is a type, then `FreeCommRing α` is the free commutative ring generated by `α`. This is a commutative ring equipped with a function `FreeCommRing.of : α → FreeCommRing α` which has the following universal property: if `R` is any commutative ring, and `f : α → R` is any function, then this function is the composite of `FreeCommRing.of` and a unique ring homomorphism `FreeCommRing.lift f : FreeCommRing α →+* R`. A typical element of `FreeCommRing α` is a `ℤ`-linear combination of formal products of elements of `α`. For example if `x` and `y` are terms of type `α` then `3 * x * x * y - 2 * x * y + 1` is a "typical" element of `FreeCommRing α`. In particular if `α` is empty then `FreeCommRing α` is isomorphic to `ℤ`, and if `α` has one term `t` then `FreeCommRing α` is isomorphic to the polynomial ring `ℤ[t]`. One can think of `FreeRing α` as the free polynomial ring with coefficients in the integers and variables indexed by `α`. -/ def FreeCommRing (α : Type u) : Type u := FreeAbelianGroup <| Multiplicative <| Multiset α -- The `CommRing, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance FreeCommRing.instCommRing : CommRing (FreeCommRing α) := by delta FreeCommRing; infer_instance instance FreeCommRing.instInhabited : Inhabited (FreeCommRing α) := by delta FreeCommRing; infer_instance namespace FreeCommRing variable {α} /-- The canonical map from `α` to the free commutative ring on `α`. -/
def of (x : α) : FreeCommRing α := FreeAbelianGroup.of <| Multiplicative.ofAdd ({x} : Multiset α) theorem of_injective : Function.Injective (of : α → FreeCommRing α) := FreeAbelianGroup.of_injective.comp fun _ _ => (Multiset.coe_eq_coe.trans List.singleton_perm_singleton).mp
Mathlib/RingTheory/FreeCommRing.lean
91
96
/- Copyright (c) 2022 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.Algebra.BigOperators.Ring.Finset import Mathlib.Combinatorics.SimpleGraph.Density import Mathlib.Data.Nat.Cast.Order.Field import Mathlib.Order.Partition.Equipartition import Mathlib.SetTheory.Cardinal.Order /-! # Graph uniformity and uniform partitions In this file we define uniformity of a pair of vertices in a graph and uniformity of a partition of vertices of a graph. Both are also known as ε-regularity. Finsets of vertices `s` and `t` are `ε`-uniform in a graph `G` if their edge density is at most `ε`-far from the density of any big enough `s'` and `t'` where `s' ⊆ s`, `t' ⊆ t`. The definition is pretty technical, but it amounts to the edges between `s` and `t` being "random" The literature contains several definitions which are equivalent up to scaling `ε` by some constant when the partition is equitable. A partition `P` of the vertices is `ε`-uniform if the proportion of non `ε`-uniform pairs of parts is less than `ε`. ## Main declarations * `SimpleGraph.IsUniform`: Graph uniformity of a pair of finsets of vertices. * `SimpleGraph.nonuniformWitness`: `G.nonuniformWitness ε s t` and `G.nonuniformWitness ε t s` together witness the non-uniformity of `s` and `t`. * `Finpartition.nonUniforms`: Non uniform pairs of parts of a partition. * `Finpartition.IsUniform`: Uniformity of a partition. * `Finpartition.nonuniformWitnesses`: For each non-uniform pair of parts of a partition, pick witnesses of non-uniformity and dump them all together. ## References [Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp] -/ open Finset variable {α 𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] /-! ### Graph uniformity -/ namespace SimpleGraph variable (G : SimpleGraph α) [DecidableRel G.Adj] (ε : 𝕜) {s t : Finset α} {a b : α} /-- A pair of finsets of vertices is `ε`-uniform (aka `ε`-regular) iff their edge density is close to the density of any big enough pair of subsets. Intuitively, the edges between them are random-like. -/ def IsUniform (s t : Finset α) : Prop := ∀ ⦃s'⦄, s' ⊆ s → ∀ ⦃t'⦄, t' ⊆ t → (#s : 𝕜) * ε ≤ #s' → (#t : 𝕜) * ε ≤ #t' → |(G.edgeDensity s' t' : 𝕜) - (G.edgeDensity s t : 𝕜)| < ε variable {G ε} instance IsUniform.instDecidableRel : DecidableRel (G.IsUniform ε) := by unfold IsUniform; infer_instance theorem IsUniform.mono {ε' : 𝕜} (h : ε ≤ ε') (hε : IsUniform G ε s t) : IsUniform G ε' s t := fun s' hs' t' ht' hs ht => by refine (hε hs' ht' (le_trans ?_ hs) (le_trans ?_ ht)).trans_le h <;> gcongr omit [IsStrictOrderedRing 𝕜] in theorem IsUniform.symm : Symmetric (IsUniform G ε) := fun s t h t' ht' s' hs' ht hs => by rw [edgeDensity_comm _ t', edgeDensity_comm _ t] exact h hs' ht' hs ht variable (G) omit [IsStrictOrderedRing 𝕜] in theorem isUniform_comm : IsUniform G ε s t ↔ IsUniform G ε t s := ⟨fun h => h.symm, fun h => h.symm⟩ lemma isUniform_one : G.IsUniform (1 : 𝕜) s t := by intro s' hs' t' ht' hs ht rw [mul_one] at hs ht rw [eq_of_subset_of_card_le hs' (Nat.cast_le.1 hs), eq_of_subset_of_card_le ht' (Nat.cast_le.1 ht), sub_self, abs_zero] exact zero_lt_one variable {G} lemma IsUniform.pos (hG : G.IsUniform ε s t) : 0 < ε := not_le.1 fun hε ↦ (hε.trans <| abs_nonneg _).not_lt <| hG (empty_subset _) (empty_subset _) (by simpa using mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hε) (by simpa using mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hε) @[simp] lemma isUniform_singleton : G.IsUniform ε {a} {b} ↔ 0 < ε := by refine ⟨IsUniform.pos, fun hε s' hs' t' ht' hs ht ↦ ?_⟩ rw [card_singleton, Nat.cast_one, one_mul] at hs ht obtain rfl | rfl := Finset.subset_singleton_iff.1 hs' · replace hs : ε ≤ 0 := by simpa using hs exact (hε.not_le hs).elim obtain rfl | rfl := Finset.subset_singleton_iff.1 ht' · replace ht : ε ≤ 0 := by simpa using ht exact (hε.not_le ht).elim · rwa [sub_self, abs_zero] theorem not_isUniform_zero : ¬G.IsUniform (0 : 𝕜) s t := fun h => (abs_nonneg _).not_lt <| h (empty_subset _) (empty_subset _) (by simp) (by simp) theorem not_isUniform_iff : ¬G.IsUniform ε s t ↔ ∃ s', s' ⊆ s ∧ ∃ t', t' ⊆ t ∧ #s * ε ≤ #s' ∧ #t * ε ≤ #t' ∧ ε ≤ |G.edgeDensity s' t' - G.edgeDensity s t| := by unfold IsUniform simp only [not_forall, not_lt, exists_prop, exists_and_left, Rat.cast_abs, Rat.cast_sub] variable (G) /-- An arbitrary pair of subsets witnessing the non-uniformity of `(s, t)`. If `(s, t)` is uniform, returns `(s, t)`. Witnesses for `(s, t)` and `(t, s)` don't necessarily match. See `SimpleGraph.nonuniformWitness`. -/ noncomputable def nonuniformWitnesses (ε : 𝕜) (s t : Finset α) : Finset α × Finset α := if h : ¬G.IsUniform ε s t then ((not_isUniform_iff.1 h).choose, (not_isUniform_iff.1 h).choose_spec.2.choose) else (s, t) theorem left_nonuniformWitnesses_subset (h : ¬G.IsUniform ε s t) : (G.nonuniformWitnesses ε s t).1 ⊆ s := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.1 theorem left_nonuniformWitnesses_card (h : ¬G.IsUniform ε s t) : #s * ε ≤ #(G.nonuniformWitnesses ε s t).1 := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.1 theorem right_nonuniformWitnesses_subset (h : ¬G.IsUniform ε s t) : (G.nonuniformWitnesses ε s t).2 ⊆ t := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.1 theorem right_nonuniformWitnesses_card (h : ¬G.IsUniform ε s t) : #t * ε ≤ #(G.nonuniformWitnesses ε s t).2 := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.2.1 theorem nonuniformWitnesses_spec (h : ¬G.IsUniform ε s t) : ε ≤ |G.edgeDensity (G.nonuniformWitnesses ε s t).1 (G.nonuniformWitnesses ε s t).2 - G.edgeDensity s t| := by rw [nonuniformWitnesses, dif_pos h] exact (not_isUniform_iff.1 h).choose_spec.2.choose_spec.2.2.2 open scoped Classical in /-- Arbitrary witness of non-uniformity. `G.nonuniformWitness ε s t` and `G.nonuniformWitness ε t s` form a pair of subsets witnessing the non-uniformity of `(s, t)`. If `(s, t)` is uniform, returns `s`. -/ noncomputable def nonuniformWitness (ε : 𝕜) (s t : Finset α) : Finset α := if WellOrderingRel s t then (G.nonuniformWitnesses ε s t).1 else (G.nonuniformWitnesses ε t s).2 theorem nonuniformWitness_subset (h : ¬G.IsUniform ε s t) : G.nonuniformWitness ε s t ⊆ s := by unfold nonuniformWitness split_ifs · exact G.left_nonuniformWitnesses_subset h · exact G.right_nonuniformWitnesses_subset fun i => h i.symm theorem le_card_nonuniformWitness (h : ¬G.IsUniform ε s t) : #s * ε ≤ #(G.nonuniformWitness ε s t) := by unfold nonuniformWitness split_ifs · exact G.left_nonuniformWitnesses_card h · exact G.right_nonuniformWitnesses_card fun i => h i.symm theorem nonuniformWitness_spec (h₁ : s ≠ t) (h₂ : ¬G.IsUniform ε s t) : ε ≤ |G.edgeDensity (G.nonuniformWitness ε s t) (G.nonuniformWitness ε t s) - G.edgeDensity s t| := by unfold nonuniformWitness rcases trichotomous_of WellOrderingRel s t with (lt | rfl | gt) · rw [if_pos lt, if_neg (asymm lt)] exact G.nonuniformWitnesses_spec h₂ · cases h₁ rfl · rw [if_neg (asymm gt), if_pos gt, edgeDensity_comm, edgeDensity_comm _ s] apply G.nonuniformWitnesses_spec fun i => h₂ i.symm end SimpleGraph /-! ### Uniform partitions -/ variable [DecidableEq α] {A : Finset α} (P : Finpartition A) (G : SimpleGraph α) [DecidableRel G.Adj] {ε δ : 𝕜} {u v : Finset α} namespace Finpartition /-- The pairs of parts of a partition `P` which are not `ε`-dense in a graph `G`. Note that we dismiss the diagonal. We do not care whether `s` is `ε`-dense with itself. -/ def sparsePairs (ε : 𝕜) : Finset (Finset α × Finset α) := P.parts.offDiag.filter fun (u, v) ↦ G.edgeDensity u v < ε omit [IsStrictOrderedRing 𝕜] in @[simp] lemma mk_mem_sparsePairs (u v : Finset α) (ε : 𝕜) : (u, v) ∈ P.sparsePairs G ε ↔ u ∈ P.parts ∧ v ∈ P.parts ∧ u ≠ v ∧ G.edgeDensity u v < ε := by rw [sparsePairs, mem_filter, mem_offDiag, and_assoc, and_assoc] omit [IsStrictOrderedRing 𝕜] in lemma sparsePairs_mono {ε ε' : 𝕜} (h : ε ≤ ε') : P.sparsePairs G ε ⊆ P.sparsePairs G ε' := monotone_filter_right _ fun _ ↦ h.trans_lt' /-- The pairs of parts of a partition `P` which are not `ε`-uniform in a graph `G`. Note that we dismiss the diagonal. We do not care whether `s` is `ε`-uniform with itself. -/ def nonUniforms (ε : 𝕜) : Finset (Finset α × Finset α) := P.parts.offDiag.filter fun (u, v) ↦ ¬G.IsUniform ε u v omit [IsStrictOrderedRing 𝕜] in @[simp] lemma mk_mem_nonUniforms : (u, v) ∈ P.nonUniforms G ε ↔ u ∈ P.parts ∧ v ∈ P.parts ∧ u ≠ v ∧ ¬G.IsUniform ε u v := by rw [nonUniforms, mem_filter, mem_offDiag, and_assoc, and_assoc] theorem nonUniforms_mono {ε ε' : 𝕜} (h : ε ≤ ε') : P.nonUniforms G ε' ⊆ P.nonUniforms G ε := monotone_filter_right _ fun _ => mt <| SimpleGraph.IsUniform.mono h theorem nonUniforms_bot (hε : 0 < ε) : (⊥ : Finpartition A).nonUniforms G ε = ∅ := by rw [eq_empty_iff_forall_not_mem] rintro ⟨u, v⟩ simp only [mk_mem_nonUniforms, parts_bot, mem_map, not_and, Classical.not_not, exists_imp]; dsimp rintro x ⟨_, rfl⟩ y ⟨_,rfl⟩ _ rwa [SimpleGraph.isUniform_singleton] /-- A finpartition of a graph's vertex set is `ε`-uniform (aka `ε`-regular) iff the proportion of its pairs of parts that are not `ε`-uniform is at most `ε`. -/ def IsUniform (ε : 𝕜) : Prop := (#(P.nonUniforms G ε) : 𝕜) ≤ (#P.parts * (#P.parts - 1) : ℕ) * ε lemma bot_isUniform (hε : 0 < ε) : (⊥ : Finpartition A).IsUniform G ε := by rw [Finpartition.IsUniform, Finpartition.card_bot, nonUniforms_bot _ hε, Finset.card_empty, Nat.cast_zero] exact mul_nonneg (Nat.cast_nonneg _) hε.le lemma isUniform_one : P.IsUniform G (1 : 𝕜) := by rw [IsUniform, mul_one, Nat.cast_le] refine (card_filter_le _ (fun uv => ¬SimpleGraph.IsUniform G 1 (Prod.fst uv) (Prod.snd uv))).trans ?_ rw [offDiag_card, Nat.mul_sub_left_distrib, mul_one] variable {P G} theorem IsUniform.mono {ε ε' : 𝕜} (hP : P.IsUniform G ε) (h : ε ≤ ε') : P.IsUniform G ε' := ((Nat.cast_le.2 <| card_le_card <| P.nonUniforms_mono G h).trans hP).trans <| by gcongr omit [IsStrictOrderedRing 𝕜] in theorem isUniformOfEmpty (hP : P.parts = ∅) : P.IsUniform G ε := by simp [IsUniform, hP, nonUniforms] omit [IsStrictOrderedRing 𝕜] in theorem nonempty_of_not_uniform (h : ¬P.IsUniform G ε) : P.parts.Nonempty := nonempty_of_ne_empty fun h₁ => h <| isUniformOfEmpty h₁ variable (P G ε) (s : Finset α) /-- A choice of witnesses of non-uniformity among the parts of a finpartition. -/ noncomputable def nonuniformWitnesses : Finset (Finset α) := {t ∈ P.parts | s ≠ t ∧ ¬G.IsUniform ε s t}.image (G.nonuniformWitness ε s) variable {P G ε s} {t : Finset α} theorem nonuniformWitness_mem_nonuniformWitnesses (h : ¬G.IsUniform ε s t) (ht : t ∈ P.parts) (hst : s ≠ t) : G.nonuniformWitness ε s t ∈ P.nonuniformWitnesses G ε s := mem_image_of_mem _ <| mem_filter.2 ⟨ht, hst, h⟩ /-! ### Equipartitions -/ open SimpleGraph in lemma IsEquipartition.card_interedges_sparsePairs_le' (hP : P.IsEquipartition)
(hε : 0 ≤ ε) : #((P.sparsePairs G ε).biUnion fun (U, V) ↦ G.interedges U V) ≤ ε * (#A + #P.parts) ^ 2 := by
Mathlib/Combinatorics/SimpleGraph/Regularity/Uniform.lean
273
274
/- 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
384
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, Yury Kudryashov, Kexing Ying -/ import Mathlib.Topology.Semicontinuous import Mathlib.MeasureTheory.Function.AEMeasurableSequence import Mathlib.MeasureTheory.Order.Lattice import Mathlib.Topology.Order.Lattice import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic /-! # Borel sigma algebras on spaces with orders ## Main statements * `borel_eq_generateFrom_Ixx` (where Ixx is one of {Iio, Ioi, Iic, Ici, Ico, Ioc}): The Borel sigma algebra of a linear order topology is generated by intervals of the given kind. * `Dense.borel_eq_generateFrom_Ico_mem`, `Dense.borel_eq_generateFrom_Ioc_mem`: The Borel sigma algebra of a dense linear order topology is generated by intervals of a given kind, with endpoints from dense subsets. * `ext_of_Ico`, `ext_of_Ioc`: A locally finite Borel measure on a second countable conditionally complete linear order is characterized by the measures of intervals of the given kind. * `ext_of_Iic`, `ext_of_Ici`: A finite Borel measure on a second countable linear order is characterized by the measures of intervals of the given kind. * `UpperSemicontinuous.measurable`, `LowerSemicontinuous.measurable`: Semicontinuous functions are measurable. * `Measurable.iSup`, `Measurable.iInf`, `Measurable.sSup`, `Measurable.sInf`: Countable supremums and infimums of measurable functions to conditionally complete linear orders are measurable. * `Measurable.liminf`, `Measurable.limsup`: Countable liminfs and limsups of measurable functions to conditionally complete linear orders are measurable. -/ open Set Filter MeasureTheory MeasurableSpace TopologicalSpace open scoped Topology NNReal ENNReal MeasureTheory universe u v w x y variable {α β γ δ : Type*} {ι : Sort y} {s t u : Set α} section OrderTopology variable (α) variable [TopologicalSpace α] [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] theorem borel_eq_generateFrom_Iio : borel α = .generateFrom (range Iio) := by refine le_antisymm ?_ (generateFrom_le ?_) · rw [borel_eq_generateFrom_of_subbasis (@OrderTopology.topology_eq_generate_intervals α _ _ _)] letI : MeasurableSpace α := MeasurableSpace.generateFrom (range Iio) have H : ∀ a : α, MeasurableSet (Iio a) := fun a => GenerateMeasurable.basic _ ⟨_, rfl⟩ refine generateFrom_le ?_ rintro _ ⟨a, rfl | rfl⟩ · rcases em (∃ b, a ⋖ b) with ⟨b, hb⟩ | hcovBy · rw [hb.Ioi_eq, ← compl_Iio] exact (H _).compl · rcases isOpen_biUnion_countable (Ioi a) Ioi fun _ _ ↦ isOpen_Ioi with ⟨t, hat, htc, htU⟩ have : Ioi a = ⋃ b ∈ t, Ici b := by refine Subset.antisymm ?_ <| iUnion₂_subset fun b hb ↦ Ici_subset_Ioi.2 (hat hb) refine Subset.trans ?_ <| iUnion₂_mono fun _ _ ↦ Ioi_subset_Ici_self simpa [CovBy, htU, subset_def] using hcovBy simp only [this, ← compl_Iio] exact .biUnion htc <| fun _ _ ↦ (H _).compl · apply H · rw [forall_mem_range] intro a exact GenerateMeasurable.basic _ isOpen_Iio theorem borel_eq_generateFrom_Ioi : borel α = .generateFrom (range Ioi) := @borel_eq_generateFrom_Iio αᵒᵈ _ (by infer_instance : SecondCountableTopology α) _ _ theorem borel_eq_generateFrom_Iic : borel α = MeasurableSpace.generateFrom (range Iic) := by rw [borel_eq_generateFrom_Ioi] refine le_antisymm ?_ ?_ · refine MeasurableSpace.generateFrom_le fun t ht => ?_ obtain ⟨u, rfl⟩ := ht rw [← compl_Iic] exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl · refine MeasurableSpace.generateFrom_le fun t ht => ?_ obtain ⟨u, rfl⟩ := ht rw [← compl_Ioi] exact (MeasurableSpace.measurableSet_generateFrom (mem_range.mpr ⟨u, rfl⟩)).compl theorem borel_eq_generateFrom_Ici : borel α = MeasurableSpace.generateFrom (range Ici) := @borel_eq_generateFrom_Iic αᵒᵈ _ _ _ _ end OrderTopology section Orders variable [TopologicalSpace α] {mα : MeasurableSpace α} [OpensMeasurableSpace α] variable {mδ : MeasurableSpace δ} section Preorder variable [Preorder α] [OrderClosedTopology α] {a b x : α} {μ : Measure α} @[simp, measurability] theorem measurableSet_Ici : MeasurableSet (Ici a) := isClosed_Ici.measurableSet theorem nullMeasurableSet_Ici : NullMeasurableSet (Ici a) μ := measurableSet_Ici.nullMeasurableSet @[simp, measurability] theorem measurableSet_Iic : MeasurableSet (Iic a) := isClosed_Iic.measurableSet theorem nullMeasurableSet_Iic : NullMeasurableSet (Iic a) μ := measurableSet_Iic.nullMeasurableSet @[simp, measurability] theorem measurableSet_Icc : MeasurableSet (Icc a b) := isClosed_Icc.measurableSet theorem nullMeasurableSet_Icc : NullMeasurableSet (Icc a b) μ := measurableSet_Icc.nullMeasurableSet instance nhdsWithin_Ici_isMeasurablyGenerated : (𝓝[Ici b] a).IsMeasurablyGenerated := measurableSet_Ici.nhdsWithin_isMeasurablyGenerated _ instance nhdsWithin_Iic_isMeasurablyGenerated : (𝓝[Iic b] a).IsMeasurablyGenerated := measurableSet_Iic.nhdsWithin_isMeasurablyGenerated _ instance nhdsWithin_Icc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[Icc a b] x) := by rw [← Ici_inter_Iic, nhdsWithin_inter] infer_instance instance atTop_isMeasurablyGenerated : (Filter.atTop : Filter α).IsMeasurablyGenerated := @Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a => (measurableSet_Ici : MeasurableSet (Ici a)).principal_isMeasurablyGenerated instance atBot_isMeasurablyGenerated : (Filter.atBot : Filter α).IsMeasurablyGenerated := @Filter.iInf_isMeasurablyGenerated _ _ _ _ fun a => (measurableSet_Iic : MeasurableSet (Iic a)).principal_isMeasurablyGenerated instance [R1Space α] : IsMeasurablyGenerated (cocompact α) where exists_measurable_subset := by intro _ hs obtain ⟨t, ht, hts⟩ := mem_cocompact.mp hs exact ⟨(closure t)ᶜ, ht.closure.compl_mem_cocompact, isClosed_closure.measurableSet.compl, (compl_subset_compl.2 subset_closure).trans hts⟩ end Preorder section PartialOrder variable [PartialOrder α] [OrderClosedTopology α] [SecondCountableTopology α] {a b : α} @[measurability] theorem measurableSet_le' : MeasurableSet { p : α × α | p.1 ≤ p.2 } := OrderClosedTopology.isClosed_le'.measurableSet @[measurability] theorem measurableSet_le {f g : δ → α} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { a | f a ≤ g a } := hf.prodMk hg measurableSet_le' end PartialOrder section LinearOrder variable [LinearOrder α] [OrderClosedTopology α] {a b x : α} {μ : Measure α} -- we open this locale only here to avoid issues with list being treated as intervals above open Interval @[simp, measurability] theorem measurableSet_Iio : MeasurableSet (Iio a) := isOpen_Iio.measurableSet theorem nullMeasurableSet_Iio : NullMeasurableSet (Iio a) μ := measurableSet_Iio.nullMeasurableSet @[simp, measurability] theorem measurableSet_Ioi : MeasurableSet (Ioi a) := isOpen_Ioi.measurableSet theorem nullMeasurableSet_Ioi : NullMeasurableSet (Ioi a) μ := measurableSet_Ioi.nullMeasurableSet @[simp, measurability] theorem measurableSet_Ioo : MeasurableSet (Ioo a b) := isOpen_Ioo.measurableSet theorem nullMeasurableSet_Ioo : NullMeasurableSet (Ioo a b) μ := measurableSet_Ioo.nullMeasurableSet @[simp, measurability] theorem measurableSet_Ioc : MeasurableSet (Ioc a b) := measurableSet_Ioi.inter measurableSet_Iic theorem nullMeasurableSet_Ioc : NullMeasurableSet (Ioc a b) μ := measurableSet_Ioc.nullMeasurableSet @[simp, measurability] theorem measurableSet_Ico : MeasurableSet (Ico a b) := measurableSet_Ici.inter measurableSet_Iio theorem nullMeasurableSet_Ico : NullMeasurableSet (Ico a b) μ := measurableSet_Ico.nullMeasurableSet instance nhdsWithin_Ioi_isMeasurablyGenerated : (𝓝[Ioi b] a).IsMeasurablyGenerated := measurableSet_Ioi.nhdsWithin_isMeasurablyGenerated _ instance nhdsWithin_Iio_isMeasurablyGenerated : (𝓝[Iio b] a).IsMeasurablyGenerated := measurableSet_Iio.nhdsWithin_isMeasurablyGenerated _ instance nhdsWithin_uIcc_isMeasurablyGenerated : IsMeasurablyGenerated (𝓝[[[a, b]]] x) := nhdsWithin_Icc_isMeasurablyGenerated @[measurability] theorem measurableSet_lt' [SecondCountableTopology α] : MeasurableSet { p : α × α | p.1 < p.2 } := (isOpen_lt continuous_fst continuous_snd).measurableSet @[measurability] theorem measurableSet_lt [SecondCountableTopology α] {f g : δ → α} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { a | f a < g a } := hf.prodMk hg measurableSet_lt' theorem nullMeasurableSet_lt [SecondCountableTopology α] {μ : Measure δ} {f g : δ → α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { a | f a < g a } μ := (hf.prodMk hg).nullMeasurable measurableSet_lt' theorem nullMeasurableSet_lt' [SecondCountableTopology α] {μ : Measure (α × α)} : NullMeasurableSet { p : α × α | p.1 < p.2 } μ := measurableSet_lt'.nullMeasurableSet theorem nullMeasurableSet_le [SecondCountableTopology α] {μ : Measure δ} {f g : δ → α} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { a | f a ≤ g a } μ := (hf.prodMk hg).nullMeasurable measurableSet_le' theorem Set.OrdConnected.measurableSet (h : OrdConnected s) : MeasurableSet s := by let u := ⋃ (x ∈ s) (y ∈ s), Ioo x y have huopen : IsOpen u := isOpen_biUnion fun _ _ => isOpen_biUnion fun _ _ => isOpen_Ioo have humeas : MeasurableSet u := huopen.measurableSet have hfinite : (s \ u).Finite := s.finite_diff_iUnion_Ioo have : u ⊆ s := iUnion₂_subset fun x hx => iUnion₂_subset fun y hy => Ioo_subset_Icc_self.trans (h.out hx hy) rw [← union_diff_cancel this] exact humeas.union hfinite.measurableSet theorem IsPreconnected.measurableSet (h : IsPreconnected s) : MeasurableSet s := h.ordConnected.measurableSet theorem generateFrom_Ico_mem_le_borel {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α] (s t : Set α) : MeasurableSpace.generateFrom { S | ∃ l ∈ s, ∃ u ∈ t, l < u ∧ Ico l u = S } ≤ borel α := by apply generateFrom_le borelize α rintro _ ⟨a, -, b, -, -, rfl⟩ exact measurableSet_Ico theorem Dense.borel_eq_generateFrom_Ico_mem_aux {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [SecondCountableTopology α] {s : Set α} (hd : Dense s) (hbot : ∀ x, IsBot x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → y ∈ s) : borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } := by set S : Set (Set α) := { S | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } refine le_antisymm ?_ (generateFrom_Ico_mem_le_borel _ _) letI : MeasurableSpace α := generateFrom S rw [borel_eq_generateFrom_Iio] refine generateFrom_le (forall_mem_range.2 fun a => ?_) rcases hd.exists_countable_dense_subset_bot_top with ⟨t, hts, hc, htd, htb, -⟩ by_cases ha : ∀ b < a, (Ioo b a).Nonempty · convert_to MeasurableSet (⋃ (l ∈ t) (u ∈ t) (_ : l < u) (_ : u ≤ a), Ico l u) · ext y simp only [mem_iUnion, mem_Iio, mem_Ico] constructor · intro hy rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) y with ⟨l, hlt, hly⟩ rcases htd.exists_mem_open isOpen_Ioo (ha y hy) with ⟨u, hut, hyu, hua⟩ exact ⟨l, hlt, u, hut, hly.trans_lt hyu, hua.le, hly, hyu⟩ · rintro ⟨l, -, u, -, -, hua, -, hyu⟩ exact hyu.trans_le hua · refine MeasurableSet.biUnion hc fun a ha => MeasurableSet.biUnion hc fun b hb => ?_ refine MeasurableSet.iUnion fun hab => MeasurableSet.iUnion fun _ => ?_ exact .basic _ ⟨a, hts ha, b, hts hb, hab, mem_singleton _⟩ · simp only [not_forall, not_nonempty_iff_eq_empty] at ha replace ha : a ∈ s := hIoo ha.choose a ha.choose_spec.fst ha.choose_spec.snd convert_to MeasurableSet (⋃ (l ∈ t) (_ : l < a), Ico l a) · symm simp only [← Ici_inter_Iio, ← iUnion_inter, inter_eq_right, subset_def, mem_iUnion, mem_Ici, mem_Iio] intro x hx rcases htd.exists_le' (fun b hb => htb _ hb (hbot b hb)) x with ⟨z, hzt, hzx⟩ exact ⟨z, hzt, hzx.trans_lt hx, hzx⟩ · refine .biUnion hc fun x hx => MeasurableSet.iUnion fun hlt => ?_ exact .basic _ ⟨x, hts hx, a, ha, hlt, mem_singleton _⟩ theorem Dense.borel_eq_generateFrom_Ico_mem {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [SecondCountableTopology α] [DenselyOrdered α] [NoMinOrder α] {s : Set α} (hd : Dense s) : borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ico l u = S } := hd.borel_eq_generateFrom_Ico_mem_aux (by simp) fun _ _ hxy H => ((nonempty_Ioo.2 hxy).ne_empty H).elim theorem borel_eq_generateFrom_Ico (α : Type*) [TopologicalSpace α] [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] : borel α = .generateFrom { S : Set α | ∃ (l u : α), l < u ∧ Ico l u = S } := by simpa only [exists_prop, mem_univ, true_and] using (@dense_univ α _).borel_eq_generateFrom_Ico_mem_aux (fun _ _ => mem_univ _) fun _ _ _ _ => mem_univ _ theorem Dense.borel_eq_generateFrom_Ioc_mem_aux {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [SecondCountableTopology α] {s : Set α} (hd : Dense s) (hbot : ∀ x, IsTop x → x ∈ s) (hIoo : ∀ x y : α, x < y → Ioo x y = ∅ → x ∈ s) : borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ioc l u = S } := by convert hd.orderDual.borel_eq_generateFrom_Ico_mem_aux hbot fun x y hlt he => hIoo y x hlt _ using 2 · ext s constructor <;> rintro ⟨l, hl, u, hu, hlt, rfl⟩ exacts [⟨u, hu, l, hl, hlt, Ico_toDual⟩, ⟨u, hu, l, hl, hlt, Ioc_toDual⟩] · erw [Ioo_toDual] exact he theorem Dense.borel_eq_generateFrom_Ioc_mem {α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderTopology α] [SecondCountableTopology α] [DenselyOrdered α] [NoMaxOrder α] {s : Set α} (hd : Dense s) : borel α = .generateFrom { S : Set α | ∃ l ∈ s, ∃ u ∈ s, l < u ∧ Ioc l u = S } := hd.borel_eq_generateFrom_Ioc_mem_aux (by simp) fun _ _ hxy H => ((nonempty_Ioo.2 hxy).ne_empty H).elim theorem borel_eq_generateFrom_Ioc (α : Type*) [TopologicalSpace α] [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] : borel α = .generateFrom { S : Set α | ∃ l u, l < u ∧ Ioc l u = S } := by simpa only [exists_prop, mem_univ, true_and] using (@dense_univ α _).borel_eq_generateFrom_Ioc_mem_aux (fun _ _ => mem_univ _) fun _ _ _ _ => mem_univ _ namespace MeasureTheory.Measure /-- Two finite measures on a Borel space are equal if they agree on all closed-open intervals. If `α` is a conditionally complete linear order with no top element, `MeasureTheory.Measure.ext_of_Ico` is an extensionality lemma with weaker assumptions on `μ` and `ν`. -/ theorem ext_of_Ico_finite {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α} [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α) [IsFiniteMeasure μ] (hμν : μ univ = ν univ) (h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν := by refine ext_of_generate_finite _ (BorelSpace.measurable_eq.trans (borel_eq_generateFrom_Ico α)) (isPiSystem_Ico (id : α → α) id) ?_ hμν rintro - ⟨a, b, hlt, rfl⟩ exact h hlt /-- Two finite measures on a Borel space are equal if they agree on all open-closed intervals. If `α` is a conditionally complete linear order with no top element, `MeasureTheory.Measure.ext_of_Ioc` is an extensionality lemma with weaker assumptions on `μ` and `ν`. -/ theorem ext_of_Ioc_finite {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α} [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α) [IsFiniteMeasure μ] (hμν : μ univ = ν univ) (h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν := by refine @ext_of_Ico_finite αᵒᵈ _ _ _ _ _ ‹_› μ ν _ hμν fun a b hab => ?_ erw [Ico_toDual (α := α)] exact h hab /-- Two measures which are finite on closed-open intervals are equal if they agree on all closed-open intervals. -/ theorem ext_of_Ico' {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α} [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] [NoMaxOrder α] (μ ν : Measure α) (hμ : ∀ ⦃a b⦄, a < b → μ (Ico a b) ≠ ∞) (h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν := by rcases exists_countable_dense_bot_top α with ⟨s, hsc, hsd, hsb, _⟩ have : (⋃ (l ∈ s) (u ∈ s) (_ : l < u), {Ico l u} : Set (Set α)).Countable := hsc.biUnion fun l _ => hsc.biUnion fun u _ => countable_iUnion fun _ => countable_singleton _ simp only [← setOf_eq_eq_singleton, ← setOf_exists] at this refine Measure.ext_of_generateFrom_of_cover_subset (BorelSpace.measurable_eq.trans (borel_eq_generateFrom_Ico α)) (isPiSystem_Ico id id) ?_ this ?_ ?_ ?_ · rintro _ ⟨l, -, u, -, h, rfl⟩ exact ⟨l, u, h, rfl⟩ · refine sUnion_eq_univ_iff.2 fun x => ?_ rcases hsd.exists_le' hsb x with ⟨l, hls, hlx⟩ rcases hsd.exists_gt x with ⟨u, hus, hxu⟩ exact ⟨_, ⟨l, hls, u, hus, hlx.trans_lt hxu, rfl⟩, hlx, hxu⟩ · rintro _ ⟨l, -, u, -, hlt, rfl⟩ exact hμ hlt · rintro _ ⟨l, u, hlt, rfl⟩ exact h hlt /-- Two measures which are finite on closed-open intervals are equal if they agree on all open-closed intervals. -/ theorem ext_of_Ioc' {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α} [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] [NoMinOrder α] (μ ν : Measure α) (hμ : ∀ ⦃a b⦄, a < b → μ (Ioc a b) ≠ ∞) (h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν := by refine @ext_of_Ico' αᵒᵈ _ _ _ _ _ ‹_› _ μ ν ?_ ?_ <;> intro a b hab <;> erw [Ico_toDual (α := α)] exacts [hμ hab, h hab] /-- Two measures which are finite on closed-open intervals are equal if they agree on all closed-open intervals. -/ theorem ext_of_Ico {α : Type*} [TopologicalSpace α] {_m : MeasurableSpace α} [SecondCountableTopology α] [ConditionallyCompleteLinearOrder α] [OrderTopology α] [BorelSpace α] [NoMaxOrder α] (μ ν : Measure α) [IsLocallyFiniteMeasure μ] (h : ∀ ⦃a b⦄, a < b → μ (Ico a b) = ν (Ico a b)) : μ = ν := μ.ext_of_Ico' ν (fun _ _ _ => measure_Ico_lt_top.ne) h /-- Two measures which are finite on closed-open intervals are equal if they agree on all open-closed intervals. -/ theorem ext_of_Ioc {α : Type*} [TopologicalSpace α] {_m : MeasurableSpace α} [SecondCountableTopology α] [ConditionallyCompleteLinearOrder α] [OrderTopology α] [BorelSpace α] [NoMinOrder α] (μ ν : Measure α) [IsLocallyFiniteMeasure μ] (h : ∀ ⦃a b⦄, a < b → μ (Ioc a b) = ν (Ioc a b)) : μ = ν := μ.ext_of_Ioc' ν (fun _ _ _ => measure_Ioc_lt_top.ne) h /-- Two finite measures on a Borel space are equal if they agree on all left-infinite right-closed intervals. -/ theorem ext_of_Iic {α : Type*} [TopologicalSpace α] {m : MeasurableSpace α} [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α) [IsFiniteMeasure μ] (h : ∀ a, μ (Iic a) = ν (Iic a)) : μ = ν := by refine ext_of_Ioc_finite μ ν ?_ fun a b hlt => ?_ · rcases exists_countable_dense_bot_top α with ⟨s, hsc, hsd, -, hst⟩ have : DirectedOn (· ≤ ·) s := directedOn_iff_directed.2 (Subtype.mono_coe _).directed_le simp only [← biSup_measure_Iic hsc (hsd.exists_ge' hst) this, h] rw [← Iic_diff_Iic, measure_diff (Iic_subset_Iic.2 hlt.le) nullMeasurableSet_Iic, measure_diff (Iic_subset_Iic.2 hlt.le) nullMeasurableSet_Iic, h a, h b] · rw [← h a] exact measure_ne_top μ _ · exact measure_ne_top μ _ /-- Two finite measures on a Borel space are equal if they agree on all left-closed right-infinite intervals. -/ theorem ext_of_Ici {α : Type*} [TopologicalSpace α] {_ : MeasurableSpace α} [SecondCountableTopology α] [LinearOrder α] [OrderTopology α] [BorelSpace α] (μ ν : Measure α) [IsFiniteMeasure μ] (h : ∀ a, μ (Ici a) = ν (Ici a)) : μ = ν := @ext_of_Iic αᵒᵈ _ _ _ _ _ ‹_› _ _ _ h end MeasureTheory.Measure @[measurability] theorem measurableSet_uIcc : MeasurableSet (uIcc a b) := measurableSet_Icc @[measurability] theorem measurableSet_uIoc : MeasurableSet (uIoc a b) := measurableSet_Ioc variable [SecondCountableTopology α] @[measurability, fun_prop] theorem Measurable.max {f g : δ → α} (hf : Measurable f) (hg : Measurable g) : Measurable fun a => max (f a) (g a) := by simpa only [max_def'] using hf.piecewise (measurableSet_le hg hf) hg @[measurability, fun_prop] nonrec theorem AEMeasurable.max {f g : δ → α} {μ : Measure δ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => max (f a) (g a)) μ := ⟨fun a => max (hf.mk f a) (hg.mk g a), hf.measurable_mk.max hg.measurable_mk, EventuallyEq.comp₂ hf.ae_eq_mk _ hg.ae_eq_mk⟩ @[measurability, fun_prop] theorem Measurable.min {f g : δ → α} (hf : Measurable f) (hg : Measurable g) : Measurable fun a => min (f a) (g a) := by simpa only [min_def] using hf.piecewise (measurableSet_le hf hg) hg @[measurability, fun_prop] nonrec theorem AEMeasurable.min {f g : δ → α} {μ : Measure δ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => min (f a) (g a)) μ := ⟨fun a => min (hf.mk f a) (hg.mk g a), hf.measurable_mk.min hg.measurable_mk, EventuallyEq.comp₂ hf.ae_eq_mk _ hg.ae_eq_mk⟩ end LinearOrder section Lattice variable [TopologicalSpace γ] {mγ : MeasurableSpace γ} [BorelSpace γ] instance (priority := 100) ContinuousSup.measurableSup [Max γ] [ContinuousSup γ] : MeasurableSup γ where measurable_const_sup _ := (continuous_const.sup continuous_id).measurable measurable_sup_const _ := (continuous_id.sup continuous_const).measurable instance (priority := 100) ContinuousSup.measurableSup₂ [SecondCountableTopology γ] [Max γ] [ContinuousSup γ] : MeasurableSup₂ γ := ⟨continuous_sup.measurable⟩ instance (priority := 100) ContinuousInf.measurableInf [Min γ] [ContinuousInf γ] : MeasurableInf γ where measurable_const_inf _ := (continuous_const.inf continuous_id).measurable measurable_inf_const _ := (continuous_id.inf continuous_const).measurable instance (priority := 100) ContinuousInf.measurableInf₂ [SecondCountableTopology γ] [Min γ] [ContinuousInf γ] : MeasurableInf₂ γ := ⟨continuous_inf.measurable⟩ end Lattice end Orders section BorelSpace variable [TopologicalSpace α] {mα : MeasurableSpace α} [BorelSpace α] variable [TopologicalSpace β] {mβ : MeasurableSpace β} [BorelSpace β] variable {mδ : MeasurableSpace δ} section LinearOrder variable [LinearOrder α] [OrderTopology α] [SecondCountableTopology α] theorem measurable_of_Iio {f : δ → α} (hf : ∀ x, MeasurableSet (f ⁻¹' Iio x)) : Measurable f := by convert measurable_generateFrom (α := δ) _ · exact BorelSpace.measurable_eq.trans (borel_eq_generateFrom_Iio _) · rintro _ ⟨x, rfl⟩; exact hf x theorem UpperSemicontinuous.measurable [TopologicalSpace δ] [OpensMeasurableSpace δ] {f : δ → α} (hf : UpperSemicontinuous f) : Measurable f := measurable_of_Iio fun y => (hf.isOpen_preimage y).measurableSet theorem measurable_of_Ioi {f : δ → α} (hf : ∀ x, MeasurableSet (f ⁻¹' Ioi x)) : Measurable f := by convert measurable_generateFrom (α := δ) _ · exact BorelSpace.measurable_eq.trans (borel_eq_generateFrom_Ioi _) · rintro _ ⟨x, rfl⟩; exact hf x theorem LowerSemicontinuous.measurable [TopologicalSpace δ] [OpensMeasurableSpace δ] {f : δ → α} (hf : LowerSemicontinuous f) : Measurable f := measurable_of_Ioi fun y => (hf.isOpen_preimage y).measurableSet theorem measurable_of_Iic {f : δ → α} (hf : ∀ x, MeasurableSet (f ⁻¹' Iic x)) : Measurable f := by apply measurable_of_Ioi simp_rw [← compl_Iic, preimage_compl, MeasurableSet.compl_iff] assumption theorem measurable_of_Ici {f : δ → α} (hf : ∀ x, MeasurableSet (f ⁻¹' Ici x)) : Measurable f := by apply measurable_of_Iio simp_rw [← compl_Ici, preimage_compl, MeasurableSet.compl_iff] assumption /-- If a function is the least upper bound of countably many measurable functions, then it is measurable. -/ theorem Measurable.isLUB {ι} [Countable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, Measurable (f i)) (hg : ∀ b, IsLUB { a | ∃ i, f i b = a } (g b)) : Measurable g := by change ∀ b, IsLUB (range fun i => f i b) (g b) at hg rw [‹BorelSpace α›.measurable_eq, borel_eq_generateFrom_Ioi α] apply measurable_generateFrom rintro _ ⟨a, rfl⟩ simp_rw [Set.preimage, mem_Ioi, lt_isLUB_iff (hg _), exists_range_iff, setOf_exists] exact MeasurableSet.iUnion fun i => hf i (isOpen_lt' _).measurableSet /-- If a function is the least upper bound of countably many measurable functions on a measurable set `s`, and coincides with a measurable function outside of `s`, then it is measurable. -/ theorem Measurable.isLUB_of_mem {ι} [Countable ι] {f : ι → δ → α} {g g' : δ → α} (hf : ∀ i, Measurable (f i)) {s : Set δ} (hs : MeasurableSet s) (hg : ∀ b ∈ s, IsLUB { a | ∃ i, f i b = a } (g b)) (hg' : EqOn g g' sᶜ) (g'_meas : Measurable g') : Measurable g := by classical rcases isEmpty_or_nonempty ι with hι|⟨⟨i⟩⟩ · rcases eq_empty_or_nonempty s with rfl|⟨x, hx⟩ · convert g'_meas rwa [compl_empty, eqOn_univ] at hg' · have A : ∀ b ∈ s, IsBot (g b) := by simpa using hg have B : ∀ b ∈ s, g b = g x := by intro b hb apply le_antisymm (A b hb (g x)) (A x hx (g b)) have : g = s.piecewise (fun _y ↦ g x) g' := by ext b by_cases hb : b ∈ s · simp [hb, B] · simp [hb, hg' hb] rw [this] exact Measurable.piecewise hs measurable_const g'_meas · have : Nonempty ι := ⟨i⟩ let f' : ι → δ → α := fun i ↦ s.piecewise (f i) g' suffices ∀ b, IsLUB { a | ∃ i, f' i b = a } (g b) from Measurable.isLUB (fun i ↦ Measurable.piecewise hs (hf i) g'_meas) this intro b by_cases hb : b ∈ s · have A : ∀ i, f' i b = f i b := fun i ↦ by simp [f', hb] simpa [A] using hg b hb · have A : ∀ i, f' i b = g' b := fun i ↦ by simp [f', hb] simp [A, hg' hb, isLUB_singleton] theorem AEMeasurable.isLUB {ι} {μ : Measure δ} [Countable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, AEMeasurable (f i) μ) (hg : ∀ᵐ b ∂μ, IsLUB { a | ∃ i, f i b = a } (g b)) : AEMeasurable g μ := by classical nontriviality α haveI hα : Nonempty α := inferInstance rcases isEmpty_or_nonempty ι with hι | hι · simp only [IsEmpty.exists_iff, setOf_false, isLUB_empty_iff] at hg exact aemeasurable_const' (hg.mono fun a ha => hg.mono fun b hb => (ha _).antisymm (hb _)) let p : δ → (ι → α) → Prop := fun x f' => IsLUB { a | ∃ i, f' i = a } (g x) let g_seq := (aeSeqSet hf p).piecewise g fun _ => hα.some have hg_seq : ∀ b, IsLUB { a | ∃ i, aeSeq hf p i b = a } (g_seq b) := by intro b simp only [g_seq, aeSeq, Set.piecewise] split_ifs with h · have h_set_eq : { a : α | ∃ i : ι, (hf i).mk (f i) b = a } = { a : α | ∃ i : ι, f i b = a } := by ext x simp_rw [Set.mem_setOf_eq, aeSeq.mk_eq_fun_of_mem_aeSeqSet hf h] rw [h_set_eq] exact aeSeq.fun_prop_of_mem_aeSeqSet hf h · exact IsGreatest.isLUB ⟨(@exists_const (hα.some = hα.some) ι _).2 rfl, fun x ⟨i, hi⟩ => hi.ge⟩ refine ⟨g_seq, Measurable.isLUB (aeSeq.measurable hf p) hg_seq, ?_⟩ exact (ite_ae_eq_of_measure_compl_zero g (fun _ => hα.some) (aeSeqSet hf p) (aeSeq.measure_compl_aeSeqSet_eq_zero hf hg)).symm /-- If a function is the greatest lower bound of countably many measurable functions, then it is measurable. -/ theorem Measurable.isGLB {ι} [Countable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, Measurable (f i)) (hg : ∀ b, IsGLB { a | ∃ i, f i b = a } (g b)) : Measurable g := Measurable.isLUB (α := αᵒᵈ) hf hg /-- If a function is the greatest lower bound of countably many measurable functions on a measurable set `s`, and coincides with a measurable function outside of `s`, then it is measurable. -/ theorem Measurable.isGLB_of_mem {ι} [Countable ι] {f : ι → δ → α} {g g' : δ → α} (hf : ∀ i, Measurable (f i)) {s : Set δ} (hs : MeasurableSet s) (hg : ∀ b ∈ s, IsGLB { a | ∃ i, f i b = a } (g b)) (hg' : EqOn g g' sᶜ) (g'_meas : Measurable g') : Measurable g := Measurable.isLUB_of_mem (α := αᵒᵈ) hf hs hg hg' g'_meas theorem AEMeasurable.isGLB {ι} {μ : Measure δ} [Countable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, AEMeasurable (f i) μ) (hg : ∀ᵐ b ∂μ, IsGLB { a | ∃ i, f i b = a } (g b)) : AEMeasurable g μ := AEMeasurable.isLUB (α := αᵒᵈ) hf hg protected theorem Monotone.measurable [LinearOrder β] [OrderClosedTopology β] {f : β → α} (hf : Monotone f) : Measurable f := suffices h : ∀ x, OrdConnected (f ⁻¹' Ioi x) from measurable_of_Ioi fun x => (h x).measurableSet fun _ => ordConnected_def.mpr fun _a ha _ _ _c hc => lt_of_lt_of_le ha (hf hc.1) theorem aemeasurable_restrict_of_monotoneOn [LinearOrder β] [OrderClosedTopology β] {μ : Measure β} {s : Set β} (hs : MeasurableSet s) {f : β → α} (hf : MonotoneOn f s) : AEMeasurable f (μ.restrict s) := have : Monotone (f ∘ (↑) : s → α) := fun ⟨x, hx⟩ ⟨y, hy⟩ => fun (hxy : x ≤ y) => hf hx hy hxy aemeasurable_restrict_of_measurable_subtype hs this.measurable protected theorem Antitone.measurable [LinearOrder β] [OrderClosedTopology β] {f : β → α} (hf : Antitone f) : Measurable f := @Monotone.measurable αᵒᵈ β _ _ ‹_› _ _ _ _ _ ‹_› _ _ _ hf theorem aemeasurable_restrict_of_antitoneOn [LinearOrder β] [OrderClosedTopology β] {μ : Measure β} {s : Set β} (hs : MeasurableSet s) {f : β → α} (hf : AntitoneOn f s) : AEMeasurable f (μ.restrict s) := @aemeasurable_restrict_of_monotoneOn αᵒᵈ β _ _ ‹_› _ _ _ _ _ ‹_› _ _ _ _ hs _ hf theorem MeasurableSet.of_mem_nhdsGT_aux {s : Set α} (h : ∀ x ∈ s, s ∈ 𝓝[>] x) (h' : ∀ x ∈ s, ∃ y, x < y) : MeasurableSet s := by choose! M hM using h' suffices H : (s \ interior s).Countable by have : s = interior s ∪ s \ interior s := by rw [union_diff_cancel interior_subset] rw [this] exact isOpen_interior.measurableSet.union H.measurableSet have A : ∀ x ∈ s, ∃ y ∈ Ioi x, Ioo x y ⊆ s := fun x hx => (mem_nhdsGT_iff_exists_Ioo_subset' (hM x hx)).1 (h x hx) choose! y hy h'y using A have B : Set.PairwiseDisjoint (s \ interior s) fun x => Ioo x (y x) := by intro x hx x' hx' hxx' rcases lt_or_gt_of_ne hxx' with (h' | h') · refine disjoint_left.2 fun z hz h'z => ?_ have : x' ∈ interior s := mem_interior.2 ⟨Ioo x (y x), h'y _ hx.1, isOpen_Ioo, ⟨h', h'z.1.trans hz.2⟩⟩ exact False.elim (hx'.2 this) · refine disjoint_left.2 fun z hz h'z => ?_ have : x ∈ interior s := mem_interior.2 ⟨Ioo x' (y x'), h'y _ hx'.1, isOpen_Ioo, ⟨h', hz.1.trans h'z.2⟩⟩ exact False.elim (hx.2 this) exact B.countable_of_Ioo fun x hx => hy x hx.1 @[deprecated (since := "2024-12-22")] alias measurableSet_of_mem_nhdsWithin_Ioi_aux := MeasurableSet.of_mem_nhdsGT_aux /-- If a set is a right-neighborhood of all of its points, then it is measurable. -/ theorem MeasurableSet.of_mem_nhdsGT {s : Set α} (h : ∀ x ∈ s, s ∈ 𝓝[>] x) : MeasurableSet s := by by_cases H : ∃ x ∈ s, IsTop x · rcases H with ⟨x₀, x₀s, h₀⟩ have : s = { x₀ } ∪ s \ { x₀ } := by rw [union_diff_cancel (singleton_subset_iff.2 x₀s)] rw [this] refine (measurableSet_singleton _).union ?_ have A : ∀ x ∈ s \ { x₀ }, x < x₀ := fun x hx => lt_of_le_of_ne (h₀ _) (by simpa using hx.2) refine .of_mem_nhdsGT_aux (fun x hx => ?_) fun x hx => ⟨x₀, A x hx⟩ obtain ⟨u, hu, us⟩ : ∃ (u : α), u ∈ Ioi x ∧ Ioo x u ⊆ s := (mem_nhdsGT_iff_exists_Ioo_subset' (A x hx)).1 (h x hx.1) refine (mem_nhdsGT_iff_exists_Ioo_subset' (A x hx)).2 ⟨u, hu, fun y hy => ⟨us hy, ?_⟩⟩ exact ne_of_lt (hy.2.trans_le (h₀ _)) · refine .of_mem_nhdsGT_aux h ?_ simp only [IsTop] at H push_neg at H exact H @[deprecated (since := "2024-12-22")] alias measurableSet_of_mem_nhdsWithin_Ioi := MeasurableSet.of_mem_nhdsGT lemma measurableSet_bddAbove_range {ι} [Countable ι] {f : ι → δ → α} (hf : ∀ i, Measurable (f i)) : MeasurableSet {b | BddAbove (range (fun i ↦ f i b))} := by rcases isEmpty_or_nonempty α with hα|hα · have : ∀ b, range (fun i ↦ f i b) = ∅ := fun b ↦ eq_empty_of_isEmpty _ simp [this] have A : ∀ (i : ι) (c : α), MeasurableSet {x | f i x ≤ c} := by intro i c exact measurableSet_le (hf i) measurable_const have B : ∀ (c : α), MeasurableSet {x | ∀ i, f i x ≤ c} := by intro c rw [setOf_forall] exact MeasurableSet.iInter (fun i ↦ A i c) obtain ⟨u, hu⟩ : ∃ (u : ℕ → α), Tendsto u atTop atTop := exists_seq_tendsto (atTop : Filter α) have : {b | BddAbove (range (fun i ↦ f i b))} = {x | ∃ n, ∀ i, f i x ≤ u n} := by apply Subset.antisymm · rintro x ⟨c, hc⟩ obtain ⟨n, hn⟩ : ∃ n, c ≤ u n := (tendsto_atTop.1 hu c).exists exact ⟨n, fun i ↦ (hc ((mem_range_self i))).trans hn⟩ · rintro x ⟨n, hn⟩ refine ⟨u n, ?_⟩ rintro - ⟨i, rfl⟩ exact hn i rw [this, setOf_exists] exact MeasurableSet.iUnion (fun n ↦ B (u n)) lemma measurableSet_bddBelow_range {ι} [Countable ι] {f : ι → δ → α} (hf : ∀ i, Measurable (f i)) : MeasurableSet {b | BddBelow (range (fun i ↦ f i b))} := measurableSet_bddAbove_range (α := αᵒᵈ) hf end LinearOrder section ConditionallyCompleteLattice @[measurability, fun_prop] theorem Measurable.iSup_Prop {α} {mα : MeasurableSpace α} [ConditionallyCompleteLattice α] (p : Prop) {f : δ → α} (hf : Measurable f) : Measurable fun b => ⨆ _ : p, f b := by classical simp_rw [ciSup_eq_ite] split_ifs with h · exact hf · exact measurable_const @[measurability, fun_prop] theorem Measurable.iInf_Prop {α} {mα : MeasurableSpace α} [ConditionallyCompleteLattice α] (p : Prop) {f : δ → α} (hf : Measurable f) : Measurable fun b => ⨅ _ : p, f b := by classical simp_rw [ciInf_eq_ite] split_ifs with h · exact hf · exact measurable_const end ConditionallyCompleteLattice section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] [OrderTopology α] [SecondCountableTopology α] @[measurability, fun_prop] protected theorem Measurable.iSup {ι} [Countable ι] {f : ι → δ → α} (hf : ∀ i, Measurable (f i)) : Measurable (fun b ↦ ⨆ i, f i b) := by rcases isEmpty_or_nonempty ι with hι|hι · simp [iSup_of_empty'] have A : MeasurableSet {b | BddAbove (range (fun i ↦ f i b))} := measurableSet_bddAbove_range hf have : Measurable (fun (_b : δ) ↦ sSup (∅ : Set α)) := measurable_const apply Measurable.isLUB_of_mem hf A _ _ this · rintro b ⟨c, hc⟩ apply isLUB_ciSup refine ⟨c, ?_⟩ rintro d ⟨i, rfl⟩ exact hc (mem_range_self i) · intro b hb apply csSup_of_not_bddAbove exact hb -- TODO: Why does this error? -- /-- Compositional version of `Measurable.iSup` for use by `fun_prop`. -/ -- @[fun_prop] -- protected lemma Measurable.iSup'' {_ : MeasurableSpace γ} {ι : Sort*} [Countable ι] -- {f : ι → γ → δ → α} {h : γ → δ} (hf : ∀ i, Measurable ↿(f i)) (hh : Measurable h) : -- Measurable fun a ↦ (⨆ i, f i a) (h a) := by -- simp_rw [iSup_apply] -- exact .iSup fun i ↦ by fun_prop @[measurability, fun_prop] protected theorem AEMeasurable.iSup {ι} {μ : Measure δ} [Countable ι] {f : ι → δ → α} (hf : ∀ i, AEMeasurable (f i) μ) : AEMeasurable (fun b => ⨆ i, f i b) μ := by refine ⟨fun b ↦ ⨆ i, (hf i).mk (f i) b, .iSup (fun i ↦ (hf i).measurable_mk), ?_⟩ filter_upwards [ae_all_iff.2 (fun i ↦ (hf i).ae_eq_mk)] with b hb using by simp [hb] @[measurability, fun_prop] protected theorem Measurable.iInf {ι} [Countable ι] {f : ι → δ → α} (hf : ∀ i, Measurable (f i)) : Measurable fun b => ⨅ i, f i b := .iSup (α := αᵒᵈ) hf @[measurability, fun_prop] protected theorem AEMeasurable.iInf {ι} {μ : Measure δ} [Countable ι] {f : ι → δ → α} (hf : ∀ i, AEMeasurable (f i) μ) : AEMeasurable (fun b => ⨅ i, f i b) μ := .iSup (α := αᵒᵈ) hf protected theorem Measurable.sSup {ι} {f : ι → δ → α} {s : Set ι} (hs : s.Countable) (hf : ∀ i ∈ s, Measurable (f i)) : Measurable fun x => sSup ((fun i => f i x) '' s) := by simp_rw [image_eq_range] have : Countable s := hs.to_subtype exact .iSup fun i ↦ hf i i.2 protected theorem Measurable.sInf {ι} {f : ι → δ → α} {s : Set ι} (hs : s.Countable) (hf : ∀ i ∈ s, Measurable (f i)) : Measurable fun x => sInf ((fun i => f i x) '' s) := .sSup (α := αᵒᵈ) hs hf theorem Measurable.biSup {ι} (s : Set ι) {f : ι → δ → α} (hs : s.Countable) (hf : ∀ i ∈ s, Measurable (f i)) : Measurable fun b => ⨆ i ∈ s, f i b := by haveI : Encodable s := hs.toEncodable by_cases H : ∀ i, i ∈ s · have : ∀ b, ⨆ i ∈ s, f i b = ⨆ (i : s), f i b := fun b ↦ cbiSup_eq_of_forall (f := fun i ↦ f i b) H simp only [this] exact .iSup (fun (i : s) ↦ hf i i.2) · have : ∀ b, ⨆ i ∈ s, f i b = (⨆ (i : s), f i b) ⊔ sSup ∅ := fun b ↦ cbiSup_eq_of_not_forall (f := fun i ↦ f i b) H simp only [this] apply Measurable.sup _ measurable_const exact .iSup (fun (i : s) ↦ hf i i.2) theorem AEMeasurable.biSup {ι} {μ : Measure δ} (s : Set ι) {f : ι → δ → α} (hs : s.Countable) (hf : ∀ i ∈ s, AEMeasurable (f i) μ) : AEMeasurable (fun b => ⨆ i ∈ s, f i b) μ := by classical let g : ι → δ → α := fun i ↦ if hi : i ∈ s then (hf i hi).mk (f i) else fun _b ↦ sSup ∅ have : ∀ i ∈ s, Measurable (g i) := by intro i hi simpa [g, hi] using (hf i hi).measurable_mk refine ⟨fun b ↦ ⨆ (i) (_ : i ∈ s), g i b, .biSup s hs this, ?_⟩ have : ∀ i ∈ s, ∀ᵐ b ∂μ, f i b = g i b := fun i hi ↦ by simpa [g, hi] using (hf i hi).ae_eq_mk filter_upwards [(ae_ball_iff hs).2 this] with b hb exact iSup_congr fun i => iSup_congr (hb i) theorem Measurable.biInf {ι} (s : Set ι) {f : ι → δ → α} (hs : s.Countable) (hf : ∀ i ∈ s, Measurable (f i)) : Measurable fun b => ⨅ i ∈ s, f i b := .biSup (α := αᵒᵈ) s hs hf theorem AEMeasurable.biInf {ι} {μ : Measure δ} (s : Set ι) {f : ι → δ → α} (hs : s.Countable) (hf : ∀ i ∈ s, AEMeasurable (f i) μ) : AEMeasurable (fun b => ⨅ i ∈ s, f i b) μ := .biSup (α := αᵒᵈ) s hs hf /-- `liminf` over a general filter is measurable. See `Measurable.liminf` for the version over `ℕ`. -/ theorem Measurable.liminf' {ι ι'} {f : ι → δ → α} {v : Filter ι} (hf : ∀ i, Measurable (f i)) {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasCountableBasis p s) (hs : ∀ j, (s j).Countable) : Measurable fun x => liminf (f · x) v := by classical /- We would like to write the liminf as `⨆ (j : Subtype p), ⨅ (i : s j), f i x`, as the
measurability would follow from the measurability of infs and sups. Unfortunately, this is not true in general conditionally complete linear orders because of issues with empty sets or sets which are not bounded above or below. A slightly more complicated expression for the liminf, valid in general, is given in `Filter.HasBasis.liminf_eq_ite`. This expression, built from `if ... then ... else` and infs and sups, can be readily checked to be measurable. -/ have : Countable (Subtype p) := hv.countable rcases isEmpty_or_nonempty (Subtype p) with hp|hp · simp [hv.liminf_eq_sSup_iUnion_iInter] by_cases H : ∃ (j : Subtype p), s j = ∅ · simp_rw [hv.liminf_eq_ite, if_pos H, measurable_const] simp_rw [hv.liminf_eq_ite, if_neg H] have : ∀ i, Countable (s i) := fun i ↦ countable_coe_iff.2 (hs i) let m : Subtype p → Set δ := fun j ↦ {x | BddBelow (range (fun (i : s j) ↦ f i x))}
Mathlib/MeasureTheory/Constructions/BorelSpace/Order.lean
849
861
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Ines Wright, Joachim Breitner -/ import Mathlib.GroupTheory.Solvable import Mathlib.GroupTheory.Sylow import Mathlib.Algebra.Group.Subgroup.Order import Mathlib.GroupTheory.Commutator.Finite /-! # Nilpotent groups An API for nilpotent groups, that is, groups for which the upper central series reaches `⊤`. ## Main definitions Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`. * `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`. This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and `H (n + 1) / H n` is the centre of `G / H n`. * `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`. This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and `H (n + 1) = ⁅H n, G⁆`. * `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or equivalently if its lower central series reaches `⊥`. * `Group.nilpotencyClass` : the length of the upper central series of a nilpotent group. * `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and * `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups `H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)` central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an *ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no requirement that the series reaches `⊤` or that the `H i` are normal. ## Main theorems `G` is *defined* to be nilpotent if the upper central series reaches `⊤`. * `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central series reaches `⊤`. * `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central series reaches `⊥`. * `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`. * The `Group.nilpotencyClass` can likewise be obtained from these equivalent definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`, `least_descending_central_series_length_eq_nilpotencyClass` and `lowerCentralSeries_length_eq_nilpotencyClass`. * If `G` is nilpotent, then so are its subgroups, images, quotients and preimages. Binary and finite products of nilpotent groups are nilpotent. Infinite products are nilpotent if their nilpotent class is bounded. Corresponding lemmas about the `Group.nilpotencyClass` are provided. * The `Group.nilpotencyClass` of `G ⧸ center G` is given explicitly, and an induction principle is derived from that. * `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable. ## Warning A "central series" is usually defined to be a finite sequence of normal subgroups going from `⊥` to `⊤` with the property that each subquotient is contained within the centre of the associated quotient of `G`. This means that if `G` is not nilpotent, then none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries` are actually central series. Note that the fact that the upper and lower central series are not central series if `G` is not nilpotent is a standard abuse of notation. -/ open Subgroup section WithGroup variable {G : Type*} [Group G] (H : Subgroup G) [Normal H] /-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}` is a subgroup of `G` (because it is the preimage in `G` of the centre of the quotient group `G/H`.) -/ def upperCentralSeriesStep : Subgroup G where carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H } one_mem' y := by simp [Subgroup.one_mem] mul_mem' {a b} ha hb y := by convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1 group inv_mem' {x} hx y := by specialize hx y⁻¹ rw [mul_assoc, inv_inv] at hx ⊢ exact Subgroup.Normal.mem_comm inferInstance hx theorem mem_upperCentralSeriesStep (x : G) : x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl open QuotientGroup /-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under the canonical surjection. -/ theorem upperCentralSeriesStep_eq_comap_center : upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by ext rw [mem_comap, mem_center_iff, forall_mk] apply forall_congr' intro y rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem, div_eq_mul_inv, mul_inv_rev, mul_assoc] instance : Normal (upperCentralSeriesStep H) := by rw [upperCentralSeriesStep_eq_comap_center] infer_instance variable (G) /-- An auxiliary type-theoretic definition defining both the upper central series of a group, and a proof that it is normal, all in one go. -/ def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H | 0 => ⟨⊥, inferInstance⟩ | n + 1 => let un := upperCentralSeriesAux n let _un_normal := un.2 ⟨upperCentralSeriesStep un.1, inferInstance⟩ /-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/ def upperCentralSeries (n : ℕ) : Subgroup G := (upperCentralSeriesAux G n).1 instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) := (upperCentralSeriesAux G n).2 @[simp] theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl @[simp] theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by ext simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq] exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm] variable {G} /-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such that `⁅x,G⁆ ⊆ H n`. -/ theorem mem_upperCentralSeries_succ_iff {n : ℕ} {x : G} : x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n := Iff.rfl @[simp] lemma comap_upperCentralSeries {H : Type*} [Group H] (e : H ≃* G) : ∀ n, (upperCentralSeries G n).comap e = upperCentralSeries H n | 0 => by simpa [MonoidHom.ker_eq_bot_iff] using e.injective | n + 1 => by ext simp [mem_upperCentralSeries_succ_iff, ← comap_upperCentralSeries e n, ← e.toEquiv.forall_congr_right] namespace Group variable (G) in -- `IsNilpotent` is already defined in the root namespace (for elements of rings). -- TODO: Rename it to `IsNilpotentElement`? /-- A group `G` is nilpotent if its upper central series is eventually `G`. -/ @[mk_iff] class IsNilpotent (G : Type*) [Group G] : Prop where nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤ lemma IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] : ∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent' lemma isNilpotent_congr {H : Type*} [Group H] (e : G ≃* H) : IsNilpotent G ↔ IsNilpotent H := by simp_rw [isNilpotent_iff] refine exists_congr fun n ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simp [← Subgroup.comap_top e.symm.toMonoidHom, ← h] · simp [← Subgroup.comap_top e.toMonoidHom, ← h] @[simp] lemma isNilpotent_top : IsNilpotent (⊤ : Subgroup G) ↔ IsNilpotent G := isNilpotent_congr Subgroup.topEquiv variable (G) in /-- A group `G` is virtually nilpotent if it has a nilpotent cofinite subgroup `N`. -/ def IsVirtuallyNilpotent : Prop := ∃ N : Subgroup G, IsNilpotent N ∧ FiniteIndex N lemma IsNilpotent.isVirtuallyNilpotent (hG : IsNilpotent G) : IsVirtuallyNilpotent G := ⟨⊤, by simpa, inferInstance⟩ end Group open Group /-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and `⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/ def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop := H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n /-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and `⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/ def IsDescendingCentralSeries (H : ℕ → Subgroup G) := H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1) /-- Any ascending central series for a group is bounded above by the upper central series. -/ theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) : ∀ n : ℕ, H n ≤ upperCentralSeries G n | 0 => hH.1.symm ▸ le_refl ⊥ | n + 1 => by intro x hx rw [mem_upperCentralSeries_succ_iff] exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y) variable (G) /-- The upper central series of a group is an ascending central series. -/ theorem upperCentralSeries_isAscendingCentralSeries : IsAscendingCentralSeries (upperCentralSeries G) := ⟨rfl, fun _x _n h => h⟩ theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by refine monotone_nat_of_le_succ ?_ intro n x hx y rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹] exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y) /-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in finitely many steps. -/ theorem nilpotent_iff_finite_ascending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by constructor · rintro ⟨n, nH⟩ exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩ · rintro ⟨n, H, hH, hn⟩ use n rw [eq_top_iff, ← hn] exact ascending_central_series_le_upper H hH n theorem is_descending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤) (hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by obtain ⟨h0, hH⟩ := hasc refine ⟨hn, fun x m hx g => ?_⟩ dsimp at hx by_cases hm : n ≤ m · rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx subst hx rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group] exact Subgroup.one_mem _ · push_neg at hm apply hH convert hx using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] @[deprecated (since := "2024-12-25")] alias is_decending_rev_series_of_is_ascending := is_descending_rev_series_of_is_ascending theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥) (hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by obtain ⟨h0, hH⟩ := hdesc refine ⟨hn, fun x m hx g => ?_⟩ dsimp only at hx ⊢ by_cases hm : n ≤ m · have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm rw [hnm, h0] exact mem_top _ · push_neg at hm convert hH x _ hx g using 1 rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right] /-- A group `G` is nilpotent iff there exists a descending central series which reaches the trivial group in a finite time. -/ theorem nilpotent_iff_finite_descending_central_series : IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by rw [nilpotent_iff_finite_ascending_central_series] constructor · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 · rintro ⟨n, H, hH, hn⟩ refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩ dsimp only rw [tsub_self] exact hH.1 /-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/ def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅lowerCentralSeries G n, ⊤⁆ variable {G} @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) : q ∈ lowerCentralSeries G (n + 1) ↔ q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl theorem lowerCentralSeries_succ (n : ℕ) : lowerCentralSeries G (n + 1) = closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := rfl instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by induction' n with d hd · exact (⊤ : Subgroup G).normal_of_characteristic · exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _ theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by refine antitone_nat_of_succ_le fun n x hx => ?_ simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left, true_and] at hx refine closure_induction ?_ (Subgroup.one_mem _) (fun _ _ _ _ ↦ mul_mem) (fun _ _ ↦ inv_mem) hx rintro y ⟨z, hz, a, ha⟩ rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹] exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a) /-- The lower central series of a group is a descending central series. -/ theorem lowerCentralSeries_isDescendingCentralSeries : IsDescendingCentralSeries (lowerCentralSeries G) := by constructor · rfl intro x n hxn g exact commutator_mem_commutator hxn (mem_top g) /-- Any descending central series for a group is bounded below by the lower central series. -/ theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) : ∀ n : ℕ, lowerCentralSeries G n ≤ H n | 0 => hH.1.symm ▸ le_refl ⊤ | n + 1 => commutator_le.mpr fun x hx q _ => hH.2 x n (descending_central_series_ge_lower H hH n hx) q /-- A group is nilpotent if and only if its lower central series eventually reaches the trivial subgroup. -/ theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by rw [nilpotent_iff_finite_descending_central_series] constructor · rintro ⟨n, H, ⟨h0, hs⟩, hn⟩ use n rw [eq_bot_iff, ← hn] exact descending_central_series_ge_lower H ⟨h0, hs⟩ n · rintro ⟨n, hn⟩ exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩ section Classical variable [hG : IsNilpotent G] variable (G) in open scoped Classical in /-- The nilpotency class of a nilpotent group is the smallest natural `n` such that the `n`'th term of the upper central series is `G`. -/ noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G) open scoped Classical in @[simp] theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ := Nat.find_spec (IsNilpotent.nilpotent G) theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} : upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by classical constructor · intro h exact Nat.find_le h · intro h rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass] exact upperCentralSeries_mono _ h open scoped Classical in /-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending central series reaches `G` in its `n`'th term. -/ theorem least_ascending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) = Group.nilpotencyClass G := by refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_) · intro n hn exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩ · rintro n ⟨H, ⟨hH, hn⟩⟩ rw [← top_le_iff, ← hn] exact ascending_central_series_le_upper H hH n
Mathlib/GroupTheory/Nilpotent.lean
384
392
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x := AddCircle.coe_eq_zero_iff (2 * π) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero]
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero,
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
214
215
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.Degree.TrailingDegree import Mathlib.Algebra.Polynomial.EraseLead /-! # Reverse of a univariate polynomial The main definition is `reverse`. Applying `reverse` to a polynomial `f : R[X]` produces the polynomial with a reversed list of coefficients, equivalent to `X^f.natDegree * f(1/X)`. The main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading coefficients of `f` and `g` do not multiply to zero. -/ namespace Polynomial open Finsupp Finset open scoped Polynomial section Semiring variable {R : Type*} [Semiring R] {f : R[X]} /-- If `i ≤ N`, then `revAtFun N i` returns `N - i`, otherwise it returns `i`. This is the map used by the embedding `revAt`. -/ def revAtFun (N i : ℕ) : ℕ := ite (i ≤ N) (N - i) i theorem revAtFun_invol {N i : ℕ} : revAtFun N (revAtFun N i) = i := by unfold revAtFun split_ifs with h j · exact tsub_tsub_cancel_of_le h · exfalso apply j exact Nat.sub_le N i · rfl theorem revAtFun_inj {N : ℕ} : Function.Injective (revAtFun N) := by intro a b hab rw [← @revAtFun_invol N a, hab, revAtFun_invol] /-- If `i ≤ N`, then `revAt N i` returns `N - i`, otherwise it returns `i`. Essentially, this embedding is only used for `i ≤ N`. The advantage of `revAt N i` over `N - i` is that `revAt` is an involution. -/ def revAt (N : ℕ) : Function.Embedding ℕ ℕ where toFun i := ite (i ≤ N) (N - i) i inj' := revAtFun_inj /-- We prefer to use the bundled `revAt` over unbundled `revAtFun`. -/ @[simp] theorem revAtFun_eq (N i : ℕ) : revAtFun N i = revAt N i := rfl @[simp] theorem revAt_invol {N i : ℕ} : (revAt N) (revAt N i) = i := revAtFun_invol @[simp] theorem revAt_le {N i : ℕ} (H : i ≤ N) : revAt N i = N - i := if_pos H lemma revAt_eq_self_of_lt {N i : ℕ} (h : N < i) : revAt N i = i := by simp [revAt, Nat.not_le.mpr h] theorem revAt_add {N O n o : ℕ} (hn : n ≤ N) (ho : o ≤ O) : revAt (N + O) (n + o) = revAt N n + revAt O o := by rcases Nat.le.dest hn with ⟨n', rfl⟩ rcases Nat.le.dest ho with ⟨o', rfl⟩ repeat' rw [revAt_le (le_add_right rfl.le)] rw [add_assoc, add_left_comm n' o, ← add_assoc, revAt_le (le_add_right rfl.le)] repeat' rw [add_tsub_cancel_left] theorem revAt_zero (N : ℕ) : revAt N 0 = N := by simp /-- `reflect N f` is the polynomial such that `(reflect N f).coeff i = f.coeff (revAt N i)`. In other words, the terms with exponent `[0, ..., N]` now have exponent `[N, ..., 0]`. In practice, `reflect` is only used when `N` is at least as large as the degree of `f`. Eventually, it will be used with `N` exactly equal to the degree of `f`. -/ noncomputable def reflect (N : ℕ) : R[X] → R[X] | ⟨f⟩ => ⟨Finsupp.embDomain (revAt N) f⟩ theorem reflect_support (N : ℕ) (f : R[X]) : (reflect N f).support = Finset.image (revAt N) f.support := by rcases f with ⟨⟩ ext1 simp only [reflect, support_ofFinsupp, support_embDomain, Finset.mem_map, Finset.mem_image] @[simp] theorem coeff_reflect (N : ℕ) (f : R[X]) (i : ℕ) : coeff (reflect N f) i = f.coeff (revAt N i) := by rcases f with ⟨f⟩ simp only [reflect, coeff] calc Finsupp.embDomain (revAt N) f i = Finsupp.embDomain (revAt N) f (revAt N (revAt N i)) := by rw [revAt_invol] _ = f (revAt N i) := Finsupp.embDomain_apply _ _ _ @[simp] theorem reflect_zero {N : ℕ} : reflect N (0 : R[X]) = 0 := rfl @[simp] theorem reflect_eq_zero_iff {N : ℕ} {f : R[X]} : reflect N (f : R[X]) = 0 ↔ f = 0 := by rw [ofFinsupp_eq_zero, reflect, embDomain_eq_zero, ofFinsupp_eq_zero] @[simp] theorem reflect_add (f g : R[X]) (N : ℕ) : reflect N (f + g) = reflect N f + reflect N g := by ext simp only [coeff_add, coeff_reflect] @[simp] theorem reflect_C_mul (f : R[X]) (r : R) (N : ℕ) : reflect N (C r * f) = C r * reflect N f := by ext simp only [coeff_reflect, coeff_C_mul] theorem reflect_C_mul_X_pow (N n : ℕ) {c : R} : reflect N (C c * X ^ n) = C c * X ^ revAt N n := by ext rw [reflect_C_mul, coeff_C_mul, coeff_C_mul, coeff_X_pow, coeff_reflect] split_ifs with h · rw [h, revAt_invol, coeff_X_pow_self] · rw [not_mem_support_iff.mp] intro a rw [← one_mul (X ^ n), ← C_1] at a apply h rw [← mem_support_C_mul_X_pow a, revAt_invol] @[simp] theorem reflect_C (r : R) (N : ℕ) : reflect N (C r) = C r * X ^ N := by conv_lhs => rw [← mul_one (C r), ← pow_zero X, reflect_C_mul_X_pow, revAt_zero] @[simp] theorem reflect_monomial (N n : ℕ) : reflect N ((X : R[X]) ^ n) = X ^ revAt N n := by rw [← one_mul (X ^ n), ← one_mul (X ^ revAt N n), ← C_1, reflect_C_mul_X_pow] @[simp] lemma reflect_one_X : reflect 1 (X : R[X]) = 1 := by simpa using reflect_monomial 1 1 (R := R) lemma reflect_map {S : Type*} [Semiring S] (f : R →+* S) (p : R[X]) (n : ℕ) : (p.map f).reflect n = (p.reflect n).map f := by ext; simp @[simp] lemma reflect_one (n : ℕ) : (1 : R[X]).reflect n = Polynomial.X ^ n := by rw [← C.map_one, reflect_C, map_one, one_mul] theorem reflect_mul_induction (cf cg : ℕ) : ∀ N O : ℕ, ∀ f g : R[X], #f.support ≤ cf.succ → #g.support ≤ cg.succ → f.natDegree ≤ N → g.natDegree ≤ O → reflect (N + O) (f * g) = reflect N f * reflect O g := by induction' cf with cf hcf --first induction (left): base case · induction' cg with cg hcg -- second induction (right): base case · intro N O f g Cf Cg Nf Og rw [← C_mul_X_pow_eq_self Cf, ← C_mul_X_pow_eq_self Cg] simp_rw [mul_assoc, X_pow_mul, mul_assoc, ← pow_add (X : R[X]), reflect_C_mul, reflect_monomial, add_comm, revAt_add Nf Og, mul_assoc, X_pow_mul, mul_assoc, ← pow_add (X : R[X]), add_comm] -- second induction (right): induction step · intro N O f g Cf Cg Nf Og by_cases g0 : g = 0 · rw [g0, reflect_zero, mul_zero, mul_zero, reflect_zero] rw [← eraseLead_add_C_mul_X_pow g, mul_add, reflect_add, reflect_add, mul_add, hcg, hcg] <;> try assumption · exact le_add_left card_support_C_mul_X_pow_le_one · exact le_trans (natDegree_C_mul_X_pow_le g.leadingCoeff g.natDegree) Og · exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cg (eraseLead_support_card_lt g0)) · exact le_trans eraseLead_natDegree_le_aux Og --first induction (left): induction step · intro N O f g Cf Cg Nf Og by_cases f0 : f = 0 · rw [f0, reflect_zero, zero_mul, zero_mul, reflect_zero] rw [← eraseLead_add_C_mul_X_pow f, add_mul, reflect_add, reflect_add, add_mul, hcf, hcf] <;> try assumption · exact le_add_left card_support_C_mul_X_pow_le_one · exact le_trans (natDegree_C_mul_X_pow_le f.leadingCoeff f.natDegree) Nf · exact Nat.lt_succ_iff.mp (gt_of_ge_of_gt Cf (eraseLead_support_card_lt f0)) · exact le_trans eraseLead_natDegree_le_aux Nf @[simp] theorem reflect_mul (f g : R[X]) {F G : ℕ} (Ff : f.natDegree ≤ F) (Gg : g.natDegree ≤ G) : reflect (F + G) (f * g) = reflect F f * reflect G g := reflect_mul_induction _ _ F G f g f.support.card.le_succ g.support.card.le_succ Ff Gg section Eval₂ variable {S : Type*} [CommSemiring S] theorem eval₂_reflect_mul_pow (i : R →+* S) (x : S) [Invertible x] (N : ℕ) (f : R[X]) (hf : f.natDegree ≤ N) : eval₂ i (⅟ x) (reflect N f) * x ^ N = eval₂ i x f := by refine induction_with_natDegree_le (fun f => eval₂ i (⅟ x) (reflect N f) * x ^ N = eval₂ i x f) _ ?_ ?_ ?_ f hf · simp · intro n r _ hnN simp only [revAt_le hnN, reflect_C_mul_X_pow, eval₂_X_pow, eval₂_C, eval₂_mul] conv in x ^ N => rw [← Nat.sub_add_cancel hnN] rw [pow_add, ← mul_assoc, mul_assoc (i r), ← mul_pow, invOf_mul_self, one_pow, mul_one] · intros simp [*, add_mul] theorem eval₂_reflect_eq_zero_iff (i : R →+* S) (x : S) [Invertible x] (N : ℕ) (f : R[X]) (hf : f.natDegree ≤ N) : eval₂ i (⅟ x) (reflect N f) = 0 ↔ eval₂ i x f = 0 := by conv_rhs => rw [← eval₂_reflect_mul_pow i x N f hf] constructor · intro h rw [h, zero_mul] · intro h rw [← mul_one (eval₂ i (⅟ x) _), ← one_pow N, ← mul_invOf_self x, mul_pow, ← mul_assoc, h, zero_mul] end Eval₂ /-- The reverse of a polynomial f is the polynomial obtained by "reading f backwards". Even though this is not the actual definition, `reverse f = f (1/X) * X ^ f.natDegree`. -/ noncomputable def reverse (f : R[X]) : R[X] := reflect f.natDegree f theorem coeff_reverse (f : R[X]) (n : ℕ) : f.reverse.coeff n = f.coeff (revAt f.natDegree n) := by rw [reverse, coeff_reflect] @[simp] theorem coeff_zero_reverse (f : R[X]) : coeff (reverse f) 0 = leadingCoeff f := by rw [coeff_reverse, revAt_le (zero_le f.natDegree), tsub_zero, leadingCoeff] @[simp] theorem reverse_zero : reverse (0 : R[X]) = 0 := rfl @[simp] theorem reverse_eq_zero : f.reverse = 0 ↔ f = 0 := by simp [reverse] theorem reverse_natDegree_le (f : R[X]) : f.reverse.natDegree ≤ f.natDegree := by rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero] intro n hn rw [Nat.cast_lt] at hn rw [coeff_reverse, revAt, Function.Embedding.coeFn_mk, if_neg (not_le_of_gt hn), coeff_eq_zero_of_natDegree_lt hn] theorem natDegree_eq_reverse_natDegree_add_natTrailingDegree (f : R[X]) : f.natDegree = f.reverse.natDegree + f.natTrailingDegree := by by_cases hf : f = 0
· rw [hf, reverse_zero, natDegree_zero, natTrailingDegree_zero] apply le_antisymm
Mathlib/Algebra/Polynomial/Reverse.lean
254
255
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.BigOperators.Group.Finset.Sigma import Mathlib.Algebra.Order.Interval.Finset.Basic import Mathlib.Order.Interval.Finset.Nat import Mathlib.Tactic.Linarith /-! # Results about big operators over intervals We prove results about big operators over intervals. -/ open Nat variable {α M : Type*} namespace Finset section PartialOrder variable [PartialOrder α] [CommMonoid M] {f : α → M} {a b : α} section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[to_additive] lemma mul_prod_Ico_eq_prod_Icc (h : a ≤ b) : f b * ∏ x ∈ Ico a b, f x = ∏ x ∈ Icc a b, f x := by rw [Icc_eq_cons_Ico h, prod_cons] @[to_additive] lemma prod_Ico_mul_eq_prod_Icc (h : a ≤ b) : (∏ x ∈ Ico a b, f x) * f b = ∏ x ∈ Icc a b, f x := by rw [mul_comm, mul_prod_Ico_eq_prod_Icc h] @[to_additive] lemma mul_prod_Ioc_eq_prod_Icc (h : a ≤ b) : f a * ∏ x ∈ Ioc a b, f x = ∏ x ∈ Icc a b, f x := by rw [Icc_eq_cons_Ioc h, prod_cons] @[to_additive] lemma prod_Ioc_mul_eq_prod_Icc (h : a ≤ b) : (∏ x ∈ Ioc a b, f x) * f a = ∏ x ∈ Icc a b, f x := by rw [mul_comm, mul_prod_Ioc_eq_prod_Icc h] end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[to_additive] lemma mul_prod_Ioi_eq_prod_Ici (a : α) : f a * ∏ x ∈ Ioi a, f x = ∏ x ∈ Ici a, f x := by
rw [Ici_eq_cons_Ioi, prod_cons] @[to_additive]
Mathlib/Algebra/BigOperators/Intervals.lean
51
53
/- 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.Subalgebra import Mathlib.LinearAlgebra.Finsupp.Span /-! # Lie submodules of a Lie algebra In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we use it to define various important operations, notably the Lie span of a subset of a Lie module. ## Main definitions * `LieSubmodule` * `LieSubmodule.wellFounded_of_noetherian` * `LieSubmodule.lieSpan` * `LieSubmodule.map` * `LieSubmodule.comap` ## Tags lie algebra, lie submodule, lie ideal, lattice structure -/ universe u v w w₁ w₂ section LieSubmodule variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] /-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie module. -/ structure LieSubmodule extends Submodule R M where lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier attribute [nolint docBlame] LieSubmodule.toSubmodule attribute [coe] LieSubmodule.toSubmodule namespace LieSubmodule variable {R L M} variable (N N' : LieSubmodule R L M) instance : SetLike (LieSubmodule R L M) M where coe s := s.carrier coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubmodule R L M) M where add_mem {N} _ _ := N.add_mem' zero_mem N := N.zero_mem' neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where smul_mem {s} c _ h := s.smul_mem' c h /-- The zero module is a Lie submodule of any Lie module. -/ instance : Zero (LieSubmodule R L M) := ⟨{ (0 : Submodule R M) with lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩ instance : Inhabited (LieSubmodule R L M) := ⟨0⟩ instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where coe N := { x : M // x ∈ N } instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) := ⟨toSubmodule⟩ instance : CanLift (Submodule R M) (LieSubmodule R L M) (·) (fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where prf N hN := ⟨⟨N, hN⟩, rfl⟩ @[norm_cast] theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N := rfl theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) := Iff.rfl theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S := Iff.rfl @[simp] theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} : x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p := Iff.rfl @[simp] theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N := Iff.rfl @[deprecated (since := "2024-12-30")] alias mem_coeSubmodule := mem_toSubmodule theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N := Iff.rfl @[simp] protected theorem zero_mem : (0 : M) ∈ N := zero_mem N @[simp] theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 := Subtype.ext_iff_val @[simp] theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S := rfl theorem toSubmodule_mk (p : Submodule R M) (h) : (({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl @[deprecated (since := "2024-12-30")] alias coe_toSubmodule_mk := toSubmodule_mk theorem toSubmodule_injective : Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by cases x; cases y; congr @[deprecated (since := "2024-12-30")] alias coeSubmodule_injective := toSubmodule_injective @[ext] theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' := SetLike.ext h @[simp] theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' := toSubmodule_injective.eq_iff @[deprecated (since := "2024-12-30")] alias coe_toSubmodule_inj := toSubmodule_inj @[deprecated (since := "2024-12-29")] alias toSubmodule_eq_iff := toSubmodule_inj /-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where carrier := s zero_mem' := by simp [hs] add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y smul_mem' := by exact hs.symm ▸ N.smul_mem' lie_mem := by exact hs.symm ▸ N.lie_mem @[simp] theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s := rfl theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs instance : LieRingModule L N where bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩ add_lie := by intro x y m; apply SetCoe.ext; apply add_lie lie_add := by intro x m n; apply SetCoe.ext; apply lie_add leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie @[simp, norm_cast] theorem coe_zero : ((0 : N) : M) = (0 : M) := rfl @[simp, norm_cast] theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) := rfl @[simp, norm_cast] theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) := rfl @[simp, norm_cast] theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) := rfl @[simp, norm_cast] theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) := rfl @[simp, norm_cast] theorem coe_bracket (x : L) (m : N) : (↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ := rfl -- Copying instances from `Submodule` for correct discrimination keys instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N := inferInstanceAs <| IsNoetherian R N.toSubmodule instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N := inferInstanceAs <| IsArtinian R N.toSubmodule instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N := inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule variable [LieAlgebra R L] [LieModule R L M] instance instLieModule : LieModule R L N where lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie instance [Subsingleton M] : Unique (LieSubmodule R L M) := ⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩ end LieSubmodule variable {R M} theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) : (∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by constructor · rintro ⟨N, rfl⟩ _ _; exact N.lie_mem · intro h; use { p with lie_mem := @h } namespace LieSubalgebra variable {L} variable [LieAlgebra R L] variable (K : LieSubalgebra R L) /-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains a distinguished Lie submodule for the action of `K`, namely `K` itself. -/ def toLieSubmodule : LieSubmodule R K L := { (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy } @[simp] theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl variable {K} @[simp] theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K := Iff.rfl end LieSubalgebra end LieSubmodule namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (N N' : LieSubmodule R L M) section LatticeStructure open Set theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) := SetLike.coe_injective @[simp, norm_cast] theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' := Iff.rfl @[deprecated (since := "2024-12-30")] alias coeSubmodule_le_coeSubmodule := toSubmodule_le_toSubmodule instance : Bot (LieSubmodule R L M) := ⟨0⟩ instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) := inferInstanceAs <| Unique (⊥ : Submodule R M) @[simp] theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} := rfl @[simp] theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ := rfl @[deprecated (since := "2024-12-30")] alias bot_coeSubmodule := bot_toSubmodule @[simp] theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by rw [← toSubmodule_inj, bot_toSubmodule] @[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_bot_iff := toSubmodule_eq_bot @[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by rw [← toSubmodule_inj, bot_toSubmodule] @[simp] theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 := mem_singleton_iff instance : Top (LieSubmodule R L M) := ⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ := rfl @[simp] theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ := rfl @[deprecated (since := "2024-12-30")] alias top_coeSubmodule := top_toSubmodule @[simp] theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by rw [← toSubmodule_inj, top_toSubmodule] @[deprecated (since := "2024-12-30")] alias coeSubmodule_eq_top_iff := toSubmodule_eq_top @[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by rw [← toSubmodule_inj, top_toSubmodule] @[simp] theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) := mem_univ x instance : Min (LieSubmodule R L M) := ⟨fun N N' ↦ { (N ⊓ N' : Submodule R M) with lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩ instance : InfSet (LieSubmodule R L M) := ⟨fun S ↦ { toSubmodule := sInf {(s : Submodule R M) | s ∈ S} lie_mem := fun {x m} h ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq, forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢ intro N hN; apply N.lie_mem (h N hN) }⟩ @[simp] theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' := rfl @[norm_cast, simp] theorem inf_toSubmodule : (↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) := rfl @[deprecated (since := "2024-12-30")] alias inf_coe_toSubmodule := inf_toSubmodule @[simp] theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} := rfl @[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule := sInf_toSubmodule theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by rw [sInf_toSubmodule, ← Set.image, sInf_image] @[deprecated (since := "2024-12-30")] alias sInf_coe_toSubmodule' := sInf_toSubmodule_eq_iInf @[simp] theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by rw [iInf, sInf_toSubmodule]; ext; simp @[deprecated (since := "2024-12-30")] alias iInf_coe_toSubmodule := iInf_toSubmodule @[simp] theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe] ext m simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp, SetLike.mem_coe, mem_toSubmodule] @[simp] theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq'] @[simp] theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl instance : Max (LieSubmodule R L M) where max N N' := { toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M) lie_mem := by rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)) change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M) rw [Submodule.mem_sup] at hm ⊢ obtain ⟨y, hy, z, hz, rfl⟩ := hm exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ } instance : SupSet (LieSubmodule R L M) where sSup S := { toSubmodule := sSup {(p : Submodule R M) | p ∈ S} lie_mem := by intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S}) change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S} obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm clear hm classical induction s using Finset.induction_on generalizing m with | empty => replace hsm : m = 0 := by simpa using hsm simp [hsm] | insert q t hqt ih => rw [Finset.iSup_insert] at hsm obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm rw [lie_add] refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu) obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t) suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm') exact le_sSup ⟨p, hp, rfl⟩ } @[norm_cast, simp] theorem sup_toSubmodule : (↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by rfl @[deprecated (since := "2024-12-30")] alias sup_coe_toSubmodule := sup_toSubmodule @[simp] theorem sSup_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} := rfl @[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule := sSup_toSubmodule theorem sSup_toSubmodule_eq_iSup (S : Set (LieSubmodule R L M)) : (↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by rw [sSup_toSubmodule, ← Set.image, sSup_image] @[deprecated (since := "2024-12-30")] alias sSup_coe_toSubmodule' := sSup_toSubmodule_eq_iSup @[simp] theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by rw [iSup, sSup_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup] @[deprecated (since := "2024-12-30")] alias iSup_coe_toSubmodule := iSup_toSubmodule /-- The set of Lie submodules of a Lie module form a complete lattice. -/ instance : CompleteLattice (LieSubmodule R L M) := { toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with toPartialOrder := SetLike.instPartialOrder } theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) : b ∈ ⨆ i, N i := (le_iSup N i) h @[elab_as_elim] lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {motive : M → Prop} {x : M} (hx : x ∈ ⨆ i, N i) (mem : ∀ i, ∀ y ∈ N i, motive y) (zero : motive 0) (add : ∀ y z, motive y → motive z → motive (y + z)) : motive x := by rw [← LieSubmodule.mem_toSubmodule, LieSubmodule.iSup_toSubmodule] at hx exact Submodule.iSup_induction (motive := motive) (fun i ↦ (N i : Submodule R M)) hx mem zero add @[elab_as_elim] theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {motive : (x : M) → (x ∈ ⨆ i, N i) → Prop} (mem : ∀ (i) (x) (hx : x ∈ N i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _)) (add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M} (hx : x ∈ ⨆ i, N i) : motive x hx := by refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : motive x hx) => hc refine iSup_induction N (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), motive x hx) hx (fun i x hx => ?_) ?_ fun x y => ?_ · exact ⟨_, mem _ _ hx⟩ · exact ⟨_, zero⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, add _ _ _ _ Cx Cy⟩ variable {N N'} @[simp] lemma disjoint_toSubmodule : Disjoint (N : Submodule R M) (N' : Submodule R M) ↔ Disjoint N N' := by rw [disjoint_iff, disjoint_iff, ← toSubmodule_inj, inf_toSubmodule, bot_toSubmodule, ← disjoint_iff] @[deprecated disjoint_toSubmodule (since := "2025-04-03")] theorem disjoint_iff_toSubmodule : Disjoint N N' ↔ Disjoint (N : Submodule R M) (N' : Submodule R M) := disjoint_toSubmodule.symm @[deprecated (since := "2024-12-30")] alias disjoint_iff_coe_toSubmodule := disjoint_iff_toSubmodule @[simp] lemma codisjoint_toSubmodule : Codisjoint (N : Submodule R M) (N' : Submodule R M) ↔ Codisjoint N N' := by rw [codisjoint_iff, codisjoint_iff, ← toSubmodule_inj, sup_toSubmodule, top_toSubmodule, ← codisjoint_iff] @[deprecated codisjoint_toSubmodule (since := "2025-04-03")] theorem codisjoint_iff_toSubmodule : Codisjoint N N' ↔ Codisjoint (N : Submodule R M) (N' : Submodule R M) := codisjoint_toSubmodule.symm @[deprecated (since := "2024-12-30")] alias codisjoint_iff_coe_toSubmodule := codisjoint_iff_toSubmodule @[simp] lemma isCompl_toSubmodule : IsCompl (N : Submodule R M) (N' : Submodule R M) ↔ IsCompl N N' := by simp [isCompl_iff] @[deprecated isCompl_toSubmodule (since := "2025-04-03")] theorem isCompl_iff_toSubmodule : IsCompl N N' ↔ IsCompl (N : Submodule R M) (N' : Submodule R M) := isCompl_toSubmodule.symm @[deprecated (since := "2024-12-30")] alias isCompl_iff_coe_toSubmodule := isCompl_iff_toSubmodule @[simp] lemma iSupIndep_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} : iSupIndep (fun i ↦ (N i : Submodule R M)) ↔ iSupIndep N := by simp [iSupIndep_def, ← disjoint_toSubmodule] @[deprecated iSupIndep_toSubmodule (since := "2025-04-03")] theorem iSupIndep_iff_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} : iSupIndep N ↔ iSupIndep fun i ↦ (N i : Submodule R M) := iSupIndep_toSubmodule.symm @[deprecated (since := "2024-12-30")] alias iSupIndep_iff_coe_toSubmodule := iSupIndep_iff_toSubmodule @[deprecated (since := "2024-11-24")] alias independent_iff_toSubmodule := iSupIndep_iff_toSubmodule @[deprecated (since := "2024-12-30")] alias independent_iff_coe_toSubmodule := independent_iff_toSubmodule @[simp] lemma iSup_toSubmodule_eq_top {ι : Sort*} {N : ι → LieSubmodule R L M} : ⨆ i, (N i : Submodule R M) = ⊤ ↔ ⨆ i, N i = ⊤ := by rw [← iSup_toSubmodule, ← top_toSubmodule (L := L), toSubmodule_inj] @[deprecated iSup_toSubmodule_eq_top (since := "2025-04-03")] theorem iSup_eq_top_iff_toSubmodule {ι : Sort*} {N : ι → LieSubmodule R L M} : ⨆ i, N i = ⊤ ↔ ⨆ i, (N i : Submodule R M) = ⊤ := iSup_toSubmodule_eq_top.symm @[deprecated (since := "2024-12-30")] alias iSup_eq_top_iff_coe_toSubmodule := iSup_eq_top_iff_toSubmodule instance : Add (LieSubmodule R L M) where add := max instance : Zero (LieSubmodule R L M) where zero := ⊥ instance : AddCommMonoid (LieSubmodule R L M) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec variable (N N') @[simp] theorem add_eq_sup : N + N' = N ⊔ N' := rfl @[simp] theorem mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' := by rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule, Submodule.mem_inf] theorem mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ y ∈ N, ∃ z ∈ N', y + z = x := by rw [← mem_toSubmodule, sup_toSubmodule, Submodule.mem_sup]; exact Iff.rfl nonrec theorem eq_bot_iff : N = ⊥ ↔ ∀ m : M, m ∈ N → m = 0 := by rw [eq_bot_iff]; exact Iff.rfl instance subsingleton_of_bot : Subsingleton (LieSubmodule R L (⊥ : LieSubmodule R L M)) := by apply subsingleton_of_bot_eq_top ext ⟨_, hx⟩ simp only [mem_bot, mk_eq_zero, mem_top, iff_true] exact hx instance : IsModularLattice (LieSubmodule R L M) where sup_inf_le_assoc_of_le _ _ := by simp only [← toSubmodule_le_toSubmodule, sup_toSubmodule, inf_toSubmodule] exact IsModularLattice.sup_inf_le_assoc_of_le _ variable (R L M) /-- The natural functor that forgets the action of `L` as an order embedding. -/ @[simps] def toSubmodule_orderEmbedding : LieSubmodule R L M ↪o Submodule R M := { toFun := (↑) inj' := toSubmodule_injective map_rel_iff' := Iff.rfl } instance wellFoundedGT_of_noetherian [IsNoetherian R M] : WellFoundedGT (LieSubmodule R L M) := RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).dual.ltEmbedding theorem wellFoundedLT_of_isArtinian [IsArtinian R M] : WellFoundedLT (LieSubmodule R L M) := RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).ltEmbedding instance [IsArtinian R M] : IsAtomic (LieSubmodule R L M) := isAtomic_of_orderBot_wellFounded_lt <| (wellFoundedLT_of_isArtinian R L M).wf @[simp] theorem subsingleton_iff : Subsingleton (LieSubmodule R L M) ↔ Subsingleton M := have h : Subsingleton (LieSubmodule R L M) ↔ Subsingleton (Submodule R M) := by rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← toSubmodule_inj, top_toSubmodule, bot_toSubmodule] h.trans <| Submodule.subsingleton_iff R @[simp] theorem nontrivial_iff : Nontrivial (LieSubmodule R L M) ↔ Nontrivial M := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R L M).trans not_nontrivial_iff_subsingleton.symm) instance [Nontrivial M] : Nontrivial (LieSubmodule R L M) := (nontrivial_iff R L M).mpr ‹_› theorem nontrivial_iff_ne_bot {N : LieSubmodule R L M} : Nontrivial N ↔ N ≠ ⊥ := by constructor <;> contrapose! · rintro rfl ⟨⟨m₁, h₁ : m₁ ∈ (⊥ : LieSubmodule R L M)⟩, ⟨m₂, h₂ : m₂ ∈ (⊥ : LieSubmodule R L M)⟩, h₁₂⟩ simp [(LieSubmodule.mem_bot _).mp h₁, (LieSubmodule.mem_bot _).mp h₂] at h₁₂ · rw [not_nontrivial_iff_subsingleton, LieSubmodule.eq_bot_iff] rintro ⟨h⟩ m hm simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩ variable {R L M} section InclusionMaps /-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/ def incl : N →ₗ⁅R,L⁆ M := { Submodule.subtype (N : Submodule R M) with map_lie' := fun {_ _} ↦ rfl } @[simp] theorem incl_coe : (N.incl : N →ₗ[R] M) = (N : Submodule R M).subtype := rfl @[simp] theorem incl_apply (m : N) : N.incl m = m := rfl theorem incl_eq_val : (N.incl : N → M) = Subtype.val := rfl theorem injective_incl : Function.Injective N.incl := Subtype.coe_injective variable {N N'} variable (h : N ≤ N') /-- Given two nested Lie submodules `N ⊆ N'`, the inclusion `N ↪ N'` is a morphism of Lie modules. -/ def inclusion : N →ₗ⁅R,L⁆ N' where __ := Submodule.inclusion (show N.toSubmodule ≤ N'.toSubmodule from h) map_lie' := rfl @[simp] theorem coe_inclusion (m : N) : (inclusion h m : M) = m := rfl theorem inclusion_apply (m : N) : inclusion h m = ⟨m.1, h m.2⟩ := rfl theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] end InclusionMaps section LieSpan variable (R L) (s : Set M) /-- The `lieSpan` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/ def lieSpan : LieSubmodule R L M := sInf { N | s ⊆ N } variable {R L s} theorem mem_lieSpan {x : M} : x ∈ lieSpan R L s ↔ ∀ N : LieSubmodule R L M, s ⊆ N → x ∈ N := by rw [← SetLike.mem_coe, lieSpan, sInf_coe] exact mem_iInter₂ theorem subset_lieSpan : s ⊆ lieSpan R L s := by intro m hm rw [SetLike.mem_coe, mem_lieSpan] intro N hN exact hN hm theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by rw [Submodule.span_le] apply subset_lieSpan @[simp] theorem lieSpan_le {N} : lieSpan R L s ≤ N ↔ s ⊆ N := by constructor · exact Subset.trans subset_lieSpan · intro hs m hm; rw [mem_lieSpan] at hm; exact hm _ hs theorem lieSpan_mono {t : Set M} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by rw [lieSpan_le] exact Subset.trans h subset_lieSpan theorem lieSpan_eq (N : LieSubmodule R L M) : lieSpan R L (N : Set M) = N := le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan theorem coe_lieSpan_submodule_eq_iff {p : Submodule R M} : (lieSpan R L (p : Set M) : Submodule R M) = p ↔ ∃ N : LieSubmodule R L M, ↑N = p := by rw [p.exists_lieSubmodule_coe_eq_iff L]; constructor <;> intro h · intro x m hm; rw [← h, mem_toSubmodule]; exact lie_mem _ (subset_lieSpan hm) · rw [← toSubmodule_mk p @h, coe_toSubmodule, toSubmodule_inj, lieSpan_eq] variable (R L M) /-- `lieSpan` forms a Galois insertion with the coercion from `LieSubmodule` to `Set`. -/ protected def gi : GaloisInsertion (lieSpan R L : Set M → LieSubmodule R L M) (↑) where choice s _ := lieSpan R L s gc _ _ := lieSpan_le le_l_u _ := subset_lieSpan choice_eq _ _ := rfl @[simp] theorem span_empty : lieSpan R L (∅ : Set M) = ⊥ := (LieSubmodule.gi R L M).gc.l_bot @[simp] theorem span_univ : lieSpan R L (Set.univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan theorem lieSpan_eq_bot_iff : lieSpan R L s = ⊥ ↔ ∀ m ∈ s, m = (0 : M) := by rw [_root_.eq_bot_iff, lieSpan_le, bot_coe, subset_singleton_iff] variable {M} theorem span_union (s t : Set M) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t := (LieSubmodule.gi R L M).gc.l_sup
theorem span_iUnion {ι} (s : ι → Set M) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) :=
Mathlib/Algebra/Lie/Submodule.lean
720
721
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Stopping import Mathlib.Tactic.AdaptationNote /-! # Hitting time Given a stochastic process, the hitting time provides the first time the process "hits" some subset of the state space. The hitting time is a stopping time in the case that the time index is discrete and the process is adapted (this is true in a far more general setting however we have only proved it for the discrete case so far). ## Main definition * `MeasureTheory.hitting`: the hitting time of a stochastic process ## Main results * `MeasureTheory.hitting_isStoppingTime`: a discrete hitting time of an adapted process is a stopping time ## Implementation notes In the definition of the hitting time, we bound the hitting time by an upper and lower bound. This is to ensure that our result is meaningful in the case we are taking the infimum of an empty set or the infimum of a set which is unbounded from below. With this, we can talk about hitting times indexed by the natural numbers or the reals. By taking the bounds to be `⊤` and `⊥`, we obtain the standard definition in the case that the index is `ℕ∞` or `ℝ≥0∞`. -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} open scoped Classical in /-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time `u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and before `m` then the hitting time is simply `m`). The hitting time is a stopping time if the process is adapted and discrete. -/ noncomputable def hitting [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : Ω → ι := fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m open scoped Classical in theorem hitting_def [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : hitting u s n m = fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m := rfl section Inequalities variable [ConditionallyCompleteLinearOrder ι] {u : ι → Ω → β} {s : Set β} {n i : ι} {ω : Ω} /-- This lemma is strictly weaker than `hitting_of_le`. -/ theorem hitting_of_lt {m : ι} (h : m < n) : hitting u s n m ω = m := by simp_rw [hitting] have h_not : ¬∃ (j : ι) (_ : j ∈ Set.Icc n m), u j ω ∈ s := by push_neg intro j rw [Set.Icc_eq_empty_of_lt h] simp only [Set.mem_empty_iff_false, IsEmpty.forall_iff] simp only [exists_prop] at h_not simp only [h_not, if_false] theorem hitting_le {m : ι} (ω : Ω) : hitting u s n m ω ≤ m := by simp only [hitting] split_ifs with h · obtain ⟨j, hj₁, hj₂⟩ := h change j ∈ {i | u i ω ∈ s} at hj₂ exact (csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter hj₁ hj₂)).trans hj₁.2 · exact le_rfl theorem not_mem_of_lt_hitting {m k : ι} (hk₁ : k < hitting u s n m ω) (hk₂ : n ≤ k) : u k ω ∉ s := by classical intro h have hexists : ∃ j ∈ Set.Icc n m, u j ω ∈ s := ⟨k, ⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ refine not_le.2 hk₁ ?_ simp_rw [hitting, if_pos hexists] exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ theorem hitting_eq_end_iff {m : ι} : hitting u s n m ω = m ↔ (∃ j ∈ Set.Icc n m, u j ω ∈ s) → sInf (Set.Icc n m ∩ {i : ι | u i ω ∈ s}) = m := by classical rw [hitting, ite_eq_right_iff] theorem hitting_of_le {m : ι} (hmn : m ≤ n) : hitting u s n m ω = m := by obtain rfl | h := le_iff_eq_or_lt.1 hmn · classical rw [hitting, ite_eq_right_iff, forall_exists_index] conv => intro; rw [Set.mem_Icc, Set.Icc_self, and_imp, and_imp] intro i hi₁ hi₂ hi rw [Set.inter_eq_left.2, csInf_singleton] exact Set.singleton_subset_iff.2 (le_antisymm hi₂ hi₁ ▸ hi) · exact hitting_of_lt h theorem le_hitting {m : ι} (hnm : n ≤ m) (ω : Ω) : n ≤ hitting u s n m ω := by simp only [hitting] split_ifs with h · refine le_csInf ?_ fun b hb => ?_ · obtain ⟨k, hk_Icc, hk_s⟩ := h exact ⟨k, hk_Icc, hk_s⟩ · rw [Set.mem_inter_iff] at hb exact hb.1.1 · exact hnm theorem le_hitting_of_exists {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : n ≤ hitting u s n m ω := by refine le_hitting ?_ ω by_contra h rw [Set.Icc_eq_empty_of_lt (not_le.mp h)] at h_exists simp at h_exists theorem hitting_mem_Icc {m : ι} (hnm : n ≤ m) (ω : Ω) : hitting u s n m ω ∈ Set.Icc n m := ⟨le_hitting hnm ω, hitting_le ω⟩ theorem hitting_mem_set [WellFoundedLT ι] {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : u (hitting u s n m ω) ω ∈ s := by simp_rw [hitting, if_pos h_exists] have h_nonempty : (Set.Icc n m ∩ {i : ι | u i ω ∈ s}).Nonempty := by obtain ⟨k, hk₁, hk₂⟩ := h_exists exact ⟨k, Set.mem_inter hk₁ hk₂⟩ have h_mem := csInf_mem h_nonempty rw [Set.mem_inter_iff] at h_mem exact h_mem.2 theorem hitting_mem_set_of_hitting_lt [WellFoundedLT ι] {m : ι} (hl : hitting u s n m ω < m) : u (hitting u s n m ω) ω ∈ s := by by_cases h : ∃ j ∈ Set.Icc n m, u j ω ∈ s · exact hitting_mem_set h · simp_rw [hitting, if_neg h] at hl exact False.elim (hl.ne rfl) theorem hitting_le_of_mem {m : ι} (hin : n ≤ i) (him : i ≤ m) (his : u i ω ∈ s) : hitting u s n m ω ≤ i := by have h_exists : ∃ k ∈ Set.Icc n m, u k ω ∈ s := ⟨i, ⟨hin, him⟩, his⟩ simp_rw [hitting, if_pos h_exists] exact csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter ⟨hin, him⟩ his) theorem hitting_le_iff_of_exists [WellFoundedLT ι] {m : ι} (h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : hitting u s n m ω ≤ i ↔ ∃ j ∈ Set.Icc n i, u j ω ∈ s := by constructor <;> intro h' · exact ⟨hitting u s n m ω, ⟨le_hitting_of_exists h_exists, h'⟩, hitting_mem_set h_exists⟩ · have h'' : ∃ k ∈ Set.Icc n (min m i), u k ω ∈ s := by obtain ⟨k₁, hk₁_mem, hk₁_s⟩ := h_exists obtain ⟨k₂, hk₂_mem, hk₂_s⟩ := h' refine ⟨min k₁ k₂, ⟨le_min hk₁_mem.1 hk₂_mem.1, min_le_min hk₁_mem.2 hk₂_mem.2⟩, ?_⟩ exact min_rec' (fun j => u j ω ∈ s) hk₁_s hk₂_s obtain ⟨k, hk₁, hk₂⟩ := h'' refine le_trans ?_ (hk₁.2.trans (min_le_right _ _)) exact hitting_le_of_mem hk₁.1 (hk₁.2.trans (min_le_left _ _)) hk₂ theorem hitting_le_iff_of_lt [WellFoundedLT ι] {m : ι} (i : ι) (hi : i < m) : hitting u s n m ω ≤ i ↔ ∃ j ∈ Set.Icc n i, u j ω ∈ s := by by_cases h_exists : ∃ j ∈ Set.Icc n m, u j ω ∈ s · rw [hitting_le_iff_of_exists h_exists] · simp_rw [hitting, if_neg h_exists] push_neg at h_exists simp only [not_le.mpr hi, Set.mem_Icc, false_iff, not_exists, not_and, and_imp] exact fun k hkn hki => h_exists k ⟨hkn, hki.trans hi.le⟩ theorem hitting_lt_iff [WellFoundedLT ι] {m : ι} (i : ι) (hi : i ≤ m) : hitting u s n m ω < i ↔ ∃ j ∈ Set.Ico n i, u j ω ∈ s := by constructor <;> intro h' · have h : ∃ j ∈ Set.Icc n m, u j ω ∈ s := by by_contra h simp_rw [hitting, if_neg h, ← not_le] at h' exact h' hi exact ⟨hitting u s n m ω, ⟨le_hitting_of_exists h, h'⟩, hitting_mem_set h⟩ · obtain ⟨k, hk₁, hk₂⟩ := h' refine lt_of_le_of_lt ?_ hk₁.2 exact hitting_le_of_mem hk₁.1 (hk₁.2.le.trans hi) hk₂ theorem hitting_eq_hitting_of_exists {m₁ m₂ : ι} (h : m₁ ≤ m₂) (h' : ∃ j ∈ Set.Icc n m₁, u j ω ∈ s) : hitting u s n m₁ ω = hitting u s n m₂ ω := by simp only [hitting, if_pos h'] obtain ⟨j, hj₁, hj₂⟩ := h' rw [if_pos] · refine le_antisymm ?_ (csInf_le_csInf bddBelow_Icc.inter_of_left ⟨j, hj₁, hj₂⟩ (Set.inter_subset_inter_left _ (Set.Icc_subset_Icc_right h))) refine le_csInf ⟨j, Set.Icc_subset_Icc_right h hj₁, hj₂⟩ fun i hi => ?_ by_cases hi' : i ≤ m₁ · exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hi.1.1, hi'⟩, hi.2⟩ · change j ∈ {i | u i ω ∈ s} at hj₂ exact ((csInf_le bddBelow_Icc.inter_of_left ⟨hj₁, hj₂⟩).trans (hj₁.2.trans le_rfl)).trans (le_of_lt (not_le.1 hi')) exact ⟨j, ⟨hj₁.1, hj₁.2.trans h⟩, hj₂⟩ theorem hitting_mono {m₁ m₂ : ι} (hm : m₁ ≤ m₂) : hitting u s n m₁ ω ≤ hitting u s n m₂ ω := by by_cases h : ∃ j ∈ Set.Icc n m₁, u j ω ∈ s · exact (hitting_eq_hitting_of_exists hm h).le · simp_rw [hitting, if_neg h] split_ifs with h' · obtain ⟨j, hj₁, hj₂⟩ := h' refine le_csInf ⟨j, hj₁, hj₂⟩ ?_ by_contra hneg; push_neg at hneg obtain ⟨i, hi₁, hi₂⟩ := hneg exact h ⟨i, ⟨hi₁.1.1, hi₂.le⟩, hi₁.2⟩ · exact hm end Inequalities /-- A discrete hitting time is a stopping time. -/ theorem hitting_isStoppingTime [ConditionallyCompleteLinearOrder ι] [WellFoundedLT ι] [Countable ι] [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {f : Filtration ι m} {u : ι → Ω → β} {s : Set β} {n n' : ι} (hu : Adapted f u) (hs : MeasurableSet s) : IsStoppingTime f (hitting u s n n') := by intro i rcases le_or_lt n' i with hi | hi · have h_le : ∀ ω, hitting u s n n' ω ≤ i := fun x => (hitting_le x).trans hi simp [h_le] · have h_set_eq_Union : {ω | hitting u s n n' ω ≤ i} = ⋃ j ∈ Set.Icc n i, u j ⁻¹' s := by ext x rw [Set.mem_setOf_eq, hitting_le_iff_of_lt _ hi] simp only [Set.mem_Icc, exists_prop, Set.mem_iUnion, Set.mem_preimage] rw [h_set_eq_Union] exact MeasurableSet.iUnion fun j => MeasurableSet.iUnion fun hj => f.mono hj.2 _ ((hu j).measurable hs) theorem stoppedValue_hitting_mem [ConditionallyCompleteLinearOrder ι] [WellFoundedLT ι] {u : ι → Ω → β} {s : Set β} {n m : ι} {ω : Ω} (h : ∃ j ∈ Set.Icc n m, u j ω ∈ s) : stoppedValue u (hitting u s n m) ω ∈ s := by simp only [stoppedValue, hitting, if_pos h] obtain ⟨j, hj₁, hj₂⟩ := h have : sInf (Set.Icc n m ∩ {i | u i ω ∈ s}) ∈ Set.Icc n m ∩ {i | u i ω ∈ s} := csInf_mem (Set.nonempty_of_mem ⟨hj₁, hj₂⟩) exact this.2 /-- The hitting time of a discrete process with the starting time indexed by a stopping time is a stopping time. -/ theorem isStoppingTime_hitting_isStoppingTime [ConditionallyCompleteLinearOrder ι] [WellFoundedLT ι] [Countable ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {N : ι} (hτbdd : ∀ x, τ x ≤ N) {s : Set β} (hs : MeasurableSet s) (hf : Adapted f u) : IsStoppingTime f fun x => hitting u s (τ x) N x := by intro n have h₁ : {x | hitting u s (τ x) N x ≤ n} = (⋃ i ≤ n, {x | τ x = i} ∩ {x | hitting u s i N x ≤ n}) ∪ ⋃ i > n, {x | τ x = i} ∩ {x | hitting u s i N x ≤ n} := by ext x simp [← exists_or, ← or_and_right, le_or_lt] have h₂ : ⋃ i > n, {x | τ x = i} ∩ {x | hitting u s i N x ≤ n} = ∅ := by ext x simp only [gt_iff_lt, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, Set.mem_empty_iff_false, iff_false, not_exists, not_and, not_le] rintro m hm rfl exact lt_of_lt_of_le hm (le_hitting (hτbdd _) _) rw [h₁, h₂, Set.union_empty] exact MeasurableSet.iUnion fun i => MeasurableSet.iUnion fun hi => (f.mono hi _ (hτ.measurableSet_eq i)).inter (hitting_isStoppingTime hf hs n) section CompleteLattice variable [CompleteLattice ι] {u : ι → Ω → β} {s : Set β} theorem hitting_eq_sInf (ω : Ω) : hitting u s ⊥ ⊤ ω = sInf {i : ι | u i ω ∈ s} := by simp only [hitting, Set.mem_Icc, bot_le, le_top, and_self_iff, exists_true_left, Set.Icc_bot, Set.Iic_top, Set.univ_inter, ite_eq_left_iff, not_exists] intro h_nmem_s symm rw [sInf_eq_top] simp only [Set.mem_univ, true_and] at h_nmem_s exact fun i hi_mem_s => absurd hi_mem_s (h_nmem_s i) end CompleteLattice section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] [WellFoundedLT ι] variable {u : ι → Ω → β} {s : Set β} theorem hitting_bot_le_iff {i n : ι} {ω : Ω} (hx : ∃ j, j ≤ n ∧ u j ω ∈ s) : hitting u s ⊥ n ω ≤ i ↔ ∃ j ≤ i, u j ω ∈ s := by rcases lt_or_le i n with hi | hi · rw [hitting_le_iff_of_lt _ hi] simp · simp only [(hitting_le ω).trans hi, true_iff] obtain ⟨j, hj₁, hj₂⟩ := hx exact ⟨j, hj₁.trans hi, hj₂⟩ end ConditionallyCompleteLinearOrderBot end MeasureTheory
Mathlib/Probability/Process/HittingTime.lean
304
311
/- Copyright (c) 2022 Bolton Bailey. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Data.Int.Log /-! # Real logarithm base `b` In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We define this as the division of the natural logarithms of the argument and the base, so that we have a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and `logb (-b) x = logb b x`. We prove some basic properties of this function and its relation to `rpow`. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {b x y : ℝ} /-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/ @[pp_nodot] noncomputable def logb (b x : ℝ) : ℝ := log x / log b theorem log_div_log : log x / log b = logb b x := rfl @[simp] theorem logb_zero : logb b 0 = 0 := by simp [logb] @[simp] theorem logb_one : logb b 1 = 0 := by simp [logb] theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero] @[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply] theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero] @[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply] @[simp] lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 := div_self (log_pos hb).ne' lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 := Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero @[simp] theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs] @[simp] theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by rw [← logb_abs x, ← logb_abs (-x), abs_neg] theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by simp_rw [logb, log_mul hx hy, add_div] theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by simp_rw [logb, log_div hx hy, sub_div] @[simp] theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div] theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div] theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_mul h₁ h₂ theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : (logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by simp_rw [inv_logb]; exact logb_div h₁ h₂ theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv] theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) : logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv] theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) : logb a b * logb b c = logb a c := by unfold logb
rw [mul_comm, div_mul_div_cancel₀ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)]
Mathlib/Analysis/SpecialFunctions/Log/Base.lean
101
102
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import Mathlib.Algebra.FreeAlgebra import Mathlib.Algebra.RingQuot import Mathlib.Algebra.TrivSqZeroExt import Mathlib.Algebra.Algebra.Operations import Mathlib.LinearAlgebra.Multilinear.Basic /-! # Tensor Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`. This is the free `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation 1. `TensorAlgebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure. 2. `TensorAlgebra.ι R` is the canonical R-linear map `M → TensorAlgebra R M`. 3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `TensorAlgebra R M → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : TensorAlgebra R M → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. ## Implementation details As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`, modulo the additional relations making the inclusion of `M` into an `R`-linear map. -/ variable (R : Type*) [CommSemiring R] variable (M : Type*) [AddCommMonoid M] [Module R M] namespace TensorAlgebra /-- An inductively defined relation on `Pre R M` used to force the initial algebra structure on the associated quotient. -/ inductive Rel : FreeAlgebra R M → FreeAlgebra R M → Prop -- force `ι` to be linear | add {a b : M} : Rel (FreeAlgebra.ι R (a + b)) (FreeAlgebra.ι R a + FreeAlgebra.ι R b) | smul {r : R} {a : M} : Rel (FreeAlgebra.ι R (r • a)) (algebraMap R (FreeAlgebra R M) r * FreeAlgebra.ι R a) end TensorAlgebra /-- The tensor algebra of the module `M` over the commutative semiring `R`. -/ def TensorAlgebra := RingQuot (TensorAlgebra.Rel R M) -- The `Inhabited, Semiring, Algebra` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : Inhabited (TensorAlgebra R M) := RingQuot.instInhabited _ instance : Semiring (TensorAlgebra R M) := RingQuot.instSemiring _ -- `IsScalarTower` is not needed, but the instance isn't really canonical without it. @[nolint unusedArguments] instance instAlgebra {R A M} [CommSemiring R] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Module R M] [Module A M] [IsScalarTower R A M] : Algebra R (TensorAlgebra A M) := RingQuot.instAlgebra _ -- verify there is no diamond -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Semiring.toNatAlgebra : Algebra ℕ (TensorAlgebra R M)) = instAlgebra := rfl instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (TensorAlgebra A M) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [CommSemiring A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] : IsScalarTower R S (TensorAlgebra A M) := RingQuot.instIsScalarTower _ namespace TensorAlgebra instance {S : Type*} [CommRing S] [Module S M] : Ring (TensorAlgebra S M) := RingQuot.instRing (Rel S M) -- verify there is no diamond -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 variable (S M : Type) [CommRing S] [AddCommGroup M] [Module S M] in example : (Ring.toIntAlgebra _ : Algebra ℤ (TensorAlgebra S M)) = instAlgebra := rfl variable {M} /-- The canonical linear map `M →ₗ[R] TensorAlgebra R M`. -/ irreducible_def ι : M →ₗ[R] TensorAlgebra R M := { toFun := fun m => RingQuot.mkAlgHom R _ (FreeAlgebra.ι R m) map_add' := fun x y => by rw [← map_add (RingQuot.mkAlgHom R (Rel R M))] exact RingQuot.mkAlgHom_rel R Rel.add map_smul' := fun r x => by rw [← map_smul (RingQuot.mkAlgHom R (Rel R M))] exact RingQuot.mkAlgHom_rel R Rel.smul } theorem ringQuot_mkAlgHom_freeAlgebra_ι_eq_ι (m : M) : RingQuot.mkAlgHom R (Rel R M) (FreeAlgebra.ι R m) = ι R m := by rw [ι] rfl /-- Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift of `f` to a morphism of `R`-algebras `TensorAlgebra R M → A`. -/ @[simps symm_apply] def lift {A : Type*} [Semiring A] [Algebra R A] : (M →ₗ[R] A) ≃ (TensorAlgebra R M →ₐ[R] A) := { toFun := RingQuot.liftAlgHom R ∘ fun f => ⟨FreeAlgebra.lift R (⇑f), fun x y (h : Rel R M x y) => by induction h <;> simp only [Algebra.smul_def, FreeAlgebra.lift_ι_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, map_mul, AlgHom.commutes, map_add]⟩ invFun := fun F => F.toLinearMap.comp (ι R) left_inv := fun f => by rw [ι] ext1 x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply f x) right_inv := fun F => RingQuot.ringQuot_ext' _ _ _ <| FreeAlgebra.hom_ext <| funext fun x => by rw [ι] exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (FreeAlgebra.lift_ι_apply _ _) } variable {R} @[simp] theorem ι_comp_lift {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) : (lift R f).toLinearMap.comp (ι R) = f := by convert (lift R).symm_apply_apply f @[simp] theorem lift_ι_apply {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (x) : lift R f (ι R x) = f x := by conv_rhs => rw [← ι_comp_lift f] rfl @[simp] theorem lift_unique {A : Type*} [Semiring A] [Algebra R A] (f : M →ₗ[R] A) (g : TensorAlgebra R M →ₐ[R] A) : g.toLinearMap.comp (ι R) = f ↔ g = lift R f := by rw [← (lift R).symm_apply_eq] simp only [lift, Equiv.coe_fn_symm_mk] -- Marking `TensorAlgebra` irreducible makes `Ring` instances inaccessible on quotients. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. @[simp] theorem lift_comp_ι {A : Type*} [Semiring A] [Algebra R A] (g : TensorAlgebra R M →ₐ[R] A) : lift R (g.toLinearMap.comp (ι R)) = g := by rw [← lift_symm_apply] exact (lift R).apply_symm_apply g /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : TensorAlgebra R M →ₐ[R] A} (w : f.toLinearMap.comp (ι R) = g.toLinearMap.comp (ι R)) : f = g := by rw [← lift_symm_apply, ← lift_symm_apply] at w exact (lift R).symm.injective w -- This proof closely follows `FreeAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `TensorAlgebra R M`, the `ι` of `x : M`, and is preserved under addition and multiplication, then it holds for all of `TensorAlgebra R M`. -/ @[elab_as_elim] theorem induction {C : TensorAlgebra R M → Prop} (algebraMap : ∀ r, C (algebraMap R (TensorAlgebra R M) r)) (ι : ∀ x, C (ι R x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : TensorAlgebra R M) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (TensorAlgebra R M) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } let of : M →ₗ[R] s := (TensorAlgebra.ι R).codRestrict (Subalgebra.toSubmodule s) ι -- the mapping through the subalgebra is the identity have of_id : AlgHom.id R (TensorAlgebra R M) = s.val.comp (lift R of) := by ext simp only [AlgHom.toLinearMap_id, LinearMap.id_comp, AlgHom.comp_toLinearMap, LinearMap.coe_comp, Function.comp_apply, AlgHom.toLinearMap_apply, lift_ι_apply, Subalgebra.coe_val] erw [LinearMap.codRestrict_apply] -- finding a proof is finding an element of the subalgebra rw [← AlgHom.id_apply (R := R) a, of_id] exact Subtype.prop (lift R of a) /-- The left-inverse of `algebraMap`. -/ def algebraMapInv : TensorAlgebra R M →ₐ[R] R := lift R (0 : M →ₗ[R] R) variable (M) theorem algebraMap_leftInverse : Function.LeftInverse algebraMapInv (algebraMap R <| TensorAlgebra R M) := fun x => by simp [algebraMapInv] @[simp] theorem algebraMap_inj (x y : R) : algebraMap R (TensorAlgebra R M) x = algebraMap R (TensorAlgebra R M) y ↔ x = y := (algebraMap_leftInverse M).injective.eq_iff @[simp] theorem algebraMap_eq_zero_iff (x : R) : algebraMap R (TensorAlgebra R M) x = 0 ↔ x = 0 := map_eq_zero_iff (algebraMap _ _) (algebraMap_leftInverse _).injective @[simp] theorem algebraMap_eq_one_iff (x : R) : algebraMap R (TensorAlgebra R M) x = 1 ↔ x = 1 := map_eq_one_iff (algebraMap _ _) (algebraMap_leftInverse _).injective
/-- A `TensorAlgebra` over a nontrivial semiring is nontrivial. -/ instance [Nontrivial R] : Nontrivial (TensorAlgebra R M) :=
Mathlib/LinearAlgebra/TensorAlgebra/Basic.lean
227
229
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Simon Hudon -/ import Mathlib.Data.PFunctor.Multivariate.W import Mathlib.Data.QPF.Multivariate.Basic /-! # The initial algebra of a multivariate qpf is again a qpf. For an `(n+1)`-ary QPF `F (α₀,..,αₙ)`, we take the least fixed point of `F` with regards to its last argument `αₙ`. The result is an `n`-ary functor: `Fix F (α₀,..,αₙ₋₁)`. Making `Fix F` into a functor allows us to take the fixed point, compose with other functors and take a fixed point again. ## Main definitions * `Fix.mk` - constructor * `Fix.dest` - destructor * `Fix.rec` - recursor: basis for defining functions by structural recursion on `Fix F α` * `Fix.drec` - dependent recursor: generalization of `Fix.rec` where the result type of the function is allowed to depend on the `Fix F α` value * `Fix.rec_eq` - defining equation for `recursor` * `Fix.ind` - induction principle for `Fix F α` ## Implementation notes For `F` a `QPF`, we define `Fix F α` in terms of the W-type of the polynomial functor `P` of `F`. We define the relation `WEquiv` and take its quotient as the definition of `Fix F α`. See [avigad-carneiro-hudon2019] for more details. ## Reference * Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u v namespace MvQPF open TypeVec open MvFunctor (LiftP LiftR) open MvFunctor variable {n : ℕ} {F : TypeVec.{u} (n + 1) → Type u} [q : MvQPF F] /-- `recF` is used as a basis for defining the recursor on `Fix F α`. `recF` traverses recursively the W-type generated by `q.P` using a function on `F` as a recursive step -/ def recF {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) : q.P.W α → β := q.P.wRec fun a f' _f rec => g (abs ⟨a, splitFun f' rec⟩) theorem recF_eq {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f : q.P.last.B a → q.P.W α) : recF g (q.P.wMk a f' f) = g (abs ⟨a, splitFun f' (recF g ∘ f)⟩) := by rw [recF, MvPFunctor.wRec_eq]; rfl theorem recF_eq' {α : TypeVec n} {β : Type u} (g : F (α.append1 β) → β) (x : q.P.W α) : recF g x = g (abs (appendFun id (recF g) <$$> q.P.wDest' x)) := by apply q.P.w_cases _ x intro a f' f rw [recF_eq, q.P.wDest'_wMk, MvPFunctor.map_eq, appendFun_comp_splitFun, TypeVec.id_comp] /-- Equivalence relation on W-types that represent the same `Fix F` value -/ inductive WEquiv {α : TypeVec n} : q.P.W α → q.P.W α → Prop | ind (a : q.P.A) (f' : q.P.drop.B a ⟹ α) (f₀ f₁ : q.P.last.B a → q.P.W α) : (∀ x, WEquiv (f₀ x) (f₁ x)) → WEquiv (q.P.wMk a f' f₀) (q.P.wMk a f' f₁) | abs (a₀ : q.P.A) (f'₀ : q.P.drop.B a₀ ⟹ α) (f₀ : q.P.last.B a₀ → q.P.W α) (a₁ : q.P.A) (f'₁ : q.P.drop.B a₁ ⟹ α) (f₁ : q.P.last.B a₁ → q.P.W α) : abs ⟨a₀, q.P.appendContents f'₀ f₀⟩ = abs ⟨a₁, q.P.appendContents f'₁ f₁⟩ → WEquiv (q.P.wMk a₀ f'₀ f₀) (q.P.wMk a₁ f'₁ f₁) | trans (u v w : q.P.W α) : WEquiv u v → WEquiv v w → WEquiv u w theorem recF_eq_of_wEquiv (α : TypeVec n) {β : Type u} (u : F (α.append1 β) → β) (x y : q.P.W α) : WEquiv x y → recF u x = recF u y := by apply q.P.w_cases _ x intro a₀ f'₀ f₀ apply q.P.w_cases _ y intro a₁ f'₁ f₁ intro h -- Porting note: induction on h doesn't work. refine @WEquiv.recOn _ _ _ _ (fun a a' _ ↦ recF u a = recF u a') _ _ h ?_ ?_ ?_ · intros a f' f₀ f₁ _h ih; simp only [recF_eq, Function.comp]
congr; funext; congr; funext; apply ih · intros a₀ f'₀ f₀ a₁ f'₁ f₁ h; simp only [recF_eq', abs_map, MvPFunctor.wDest'_wMk, h] · intros x y z _e₁ _e₂ ih₁ ih₂; exact Eq.trans ih₁ ih₂ theorem wEquiv.abs' {α : TypeVec n} (x y : q.P.W α) (h : MvQPF.abs (q.P.wDest' x) = MvQPF.abs (q.P.wDest' y)) : WEquiv x y := by revert h apply q.P.w_cases _ x intro a₀ f'₀ f₀ apply q.P.w_cases _ y intro a₁ f'₁ f₁ apply WEquiv.abs
Mathlib/Data/QPF/Multivariate/Constructions/Fix.lean
92
104