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) 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.SpecialFunctions.Gamma.Basic
import Mathlib.Analysis.SpecialFunctions.PolarCoord
import Mathlib.Analysis.Complex.Convex
import Mathlib.Data.Nat.Factorial.DoubleFactorial
/-!
# Gaussian integral
We prove various versions of the formula for the Gaussian integral:
* `integral_gaussian`: for real `b` we have `∫ x:ℝ, exp (-b * x^2) = √(π / b)`.
* `integral_gaussian_complex`: for complex `b` with `0 < re b` we have
`∫ x:ℝ, exp (-b * x^2) = (π / b) ^ (1 / 2)`.
* `integral_gaussian_Ioi` and `integral_gaussian_complex_Ioi`: variants for integrals over `Ioi 0`.
* `Complex.Gamma_one_half_eq`: the formula `Γ (1 / 2) = √π`.
-/
noncomputable section
open Real Set MeasureTheory Filter Asymptotics
open scoped Real Topology
open Complex hiding exp abs_of_nonneg
theorem exp_neg_mul_rpow_isLittleO_exp_neg {p b : ℝ} (hb : 0 < b) (hp : 1 < p) :
(fun x : ℝ => exp (- b * x ^ p)) =o[atTop] fun x : ℝ => exp (-x) := by
rw [isLittleO_exp_comp_exp_comp]
suffices Tendsto (fun x => x * (b * x ^ (p - 1) + -1)) atTop atTop by
refine Tendsto.congr' ?_ this
refine eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) (fun x hx => ?_)
rw [mem_Ioi] at hx
rw [rpow_sub_one hx.ne']
field_simp [hx.ne']
ring
apply tendsto_id.atTop_mul_atTop₀
refine tendsto_atTop_add_const_right atTop (-1 : ℝ) ?_
exact Tendsto.const_mul_atTop hb (tendsto_rpow_atTop (by linarith))
theorem exp_neg_mul_sq_isLittleO_exp_neg {b : ℝ} (hb : 0 < b) :
(fun x : ℝ => exp (-b * x ^ 2)) =o[atTop] fun x : ℝ => exp (-x) := by
simp_rw [← rpow_two]
exact exp_neg_mul_rpow_isLittleO_exp_neg hb one_lt_two
theorem rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg (s : ℝ) {b p : ℝ} (hp : 1 < p) (hb : 0 < b) :
(fun x : ℝ => x ^ s * exp (- b * x ^ p)) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by
apply ((isBigO_refl (fun x : ℝ => x ^ s) atTop).mul_isLittleO
(exp_neg_mul_rpow_isLittleO_exp_neg hb hp)).trans
simpa only [mul_comm] using Real.Gamma_integrand_isLittleO s
theorem rpow_mul_exp_neg_mul_sq_isLittleO_exp_neg {b : ℝ} (hb : 0 < b) (s : ℝ) :
(fun x : ℝ => x ^ s * exp (-b * x ^ 2)) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by
simp_rw [← rpow_two]
exact rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg s one_lt_two hb
theorem integrableOn_rpow_mul_exp_neg_rpow {p s : ℝ} (hs : -1 < s) (hp : 1 ≤ p) :
IntegrableOn (fun x : ℝ => x ^ s * exp (- x ^ p)) (Ioi 0) := by
obtain hp | hp := le_iff_lt_or_eq.mp hp
· have h_exp : ∀ x, ContinuousAt (fun x => exp (- x)) x := fun x => continuousAt_neg.rexp
rw [← Ioc_union_Ioi_eq_Ioi zero_le_one, integrableOn_union]
constructor
· rw [← integrableOn_Icc_iff_integrableOn_Ioc]
refine IntegrableOn.mul_continuousOn ?_ ?_ isCompact_Icc
· refine (intervalIntegrable_iff_integrableOn_Icc_of_le zero_le_one).mp ?_
exact intervalIntegral.intervalIntegrable_rpow' hs
· intro x _
change ContinuousWithinAt ((fun x => exp (- x)) ∘ (fun x => x ^ p)) (Icc 0 1) x
refine ContinuousAt.comp_continuousWithinAt (h_exp _) ?_
exact continuousWithinAt_id.rpow_const (Or.inr (le_of_lt (lt_trans zero_lt_one hp)))
· have h_rpow : ∀ (x r : ℝ), x ∈ Ici 1 → ContinuousWithinAt (fun x => x ^ r) (Ici 1) x := by
intro _ _ hx
refine continuousWithinAt_id.rpow_const (Or.inl ?_)
exact ne_of_gt (lt_of_lt_of_le zero_lt_one hx)
refine integrable_of_isBigO_exp_neg (by norm_num : (0 : ℝ) < 1 / 2)
(ContinuousOn.mul (fun x hx => h_rpow x s hx) (fun x hx => ?_)) (IsLittleO.isBigO ?_)
· change ContinuousWithinAt ((fun x => exp (- x)) ∘ (fun x => x ^ p)) (Ici 1) x
exact ContinuousAt.comp_continuousWithinAt (h_exp _) (h_rpow x p hx)
· convert rpow_mul_exp_neg_mul_rpow_isLittleO_exp_neg s hp (by norm_num : (0 : ℝ) < 1) using 3
rw [neg_mul, one_mul]
· simp_rw [← hp, Real.rpow_one]
convert Real.GammaIntegral_convergent (by linarith : 0 < s + 1) using 2
rw [add_sub_cancel_right, mul_comm]
theorem integrableOn_rpow_mul_exp_neg_mul_rpow {p s b : ℝ} (hs : -1 < s) (hp : 1 ≤ p) (hb : 0 < b) :
IntegrableOn (fun x : ℝ => x ^ s * exp (- b * x ^ p)) (Ioi 0) := by
have hib : 0 < b ^ (-p⁻¹) := rpow_pos_of_pos hb _
suffices IntegrableOn (fun x ↦ (b ^ (-p⁻¹)) ^ s * (x ^ s * exp (-x ^ p))) (Ioi 0) by
rw [show 0 = b ^ (-p⁻¹) * 0 by rw [mul_zero], ← integrableOn_Ioi_comp_mul_left_iff _ _ hib]
refine this.congr_fun (fun _ hx => ?_) measurableSet_Ioi
rw [← mul_assoc, mul_rpow, mul_rpow, ← rpow_mul (z := p), neg_mul, neg_mul, inv_mul_cancel₀,
rpow_neg_one, mul_inv_cancel_left₀]
all_goals linarith [mem_Ioi.mp hx]
refine Integrable.const_mul ?_ _
rw [← IntegrableOn]
exact integrableOn_rpow_mul_exp_neg_rpow hs hp
theorem integrableOn_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) :
IntegrableOn (fun x : ℝ => x ^ s * exp (-b * x ^ 2)) (Ioi 0) := by
simp_rw [← rpow_two]
exact integrableOn_rpow_mul_exp_neg_mul_rpow hs one_le_two hb
theorem integrable_rpow_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) {s : ℝ} (hs : -1 < s) :
Integrable fun x : ℝ => x ^ s * exp (-b * x ^ 2) := by
rw [← integrableOn_univ, ← @Iio_union_Ici _ _ (0 : ℝ), integrableOn_union,
integrableOn_Ici_iff_integrableOn_Ioi]
refine ⟨?_, integrableOn_rpow_mul_exp_neg_mul_sq hb hs⟩
rw [← (Measure.measurePreserving_neg (volume : Measure ℝ)).integrableOn_comp_preimage
(Homeomorph.neg ℝ).measurableEmbedding]
simp only [Function.comp_def, neg_sq, neg_preimage, neg_Iio, neg_neg, neg_zero]
apply Integrable.mono' (integrableOn_rpow_mul_exp_neg_mul_sq hb hs)
· apply Measurable.aestronglyMeasurable
exact (measurable_id'.neg.pow measurable_const).mul
((measurable_id'.pow measurable_const).const_mul (-b)).exp
· have : MeasurableSet (Ioi (0 : ℝ)) := measurableSet_Ioi
filter_upwards [ae_restrict_mem this] with x hx
have h'x : 0 ≤ x := le_of_lt hx
rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (exp_pos _).le]
apply mul_le_mul_of_nonneg_right _ (exp_pos _).le
simpa [abs_of_nonneg h'x] using abs_rpow_le_abs_rpow (-x) s
theorem integrable_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) :
Integrable fun x : ℝ => exp (-b * x ^ 2) := by
simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by norm_num : (-1 : ℝ) < 0)
theorem integrableOn_Ioi_exp_neg_mul_sq_iff {b : ℝ} :
IntegrableOn (fun x : ℝ => exp (-b * x ^ 2)) (Ioi 0) ↔ 0 < b := by
refine ⟨fun h => ?_, fun h => (integrable_exp_neg_mul_sq h).integrableOn⟩
by_contra! hb
have : ∫⁻ _ : ℝ in Ioi 0, 1 ≤ ∫⁻ x : ℝ in Ioi 0, ‖exp (-b * x ^ 2)‖₊ := by
apply lintegral_mono (fun x ↦ _)
simp only [neg_mul, ENNReal.one_le_coe_iff, ← toNNReal_one, toNNReal_le_iff_le_coe,
Real.norm_of_nonneg (exp_pos _).le, coe_nnnorm, one_le_exp_iff, Right.nonneg_neg_iff]
exact fun x ↦ mul_nonpos_of_nonpos_of_nonneg hb (sq_nonneg x)
simpa using this.trans_lt h.2
theorem integrable_exp_neg_mul_sq_iff {b : ℝ} :
(Integrable fun x : ℝ => exp (-b * x ^ 2)) ↔ 0 < b :=
⟨fun h => integrableOn_Ioi_exp_neg_mul_sq_iff.mp h.integrableOn, integrable_exp_neg_mul_sq⟩
theorem integrable_mul_exp_neg_mul_sq {b : ℝ} (hb : 0 < b) :
Integrable fun x : ℝ => x * exp (-b * x ^ 2) := by
simpa using integrable_rpow_mul_exp_neg_mul_sq hb (by norm_num : (-1 : ℝ) < 1)
theorem norm_cexp_neg_mul_sq (b : ℂ) (x : ℝ) :
‖Complex.exp (-b * (x : ℂ) ^ 2)‖ = exp (-b.re * x ^ 2) := by
rw [norm_exp, ← ofReal_pow, mul_comm (-b) _, re_ofReal_mul, neg_re, mul_comm]
theorem integrable_cexp_neg_mul_sq {b : ℂ} (hb : 0 < b.re) :
Integrable fun x : ℝ => cexp (-b * (x : ℂ) ^ 2) := by
refine ⟨(Complex.continuous_exp.comp
(continuous_const.mul (continuous_ofReal.pow 2))).aestronglyMeasurable, ?_⟩
rw [← hasFiniteIntegral_norm_iff]
simp_rw [norm_cexp_neg_mul_sq]
exact (integrable_exp_neg_mul_sq hb).2
theorem integrable_mul_cexp_neg_mul_sq {b : ℂ} (hb : 0 < b.re) :
Integrable fun x : ℝ => ↑x * cexp (-b * (x : ℂ) ^ 2) := by
refine ⟨(continuous_ofReal.mul (Complex.continuous_exp.comp ?_)).aestronglyMeasurable, ?_⟩
· exact continuous_const.mul (continuous_ofReal.pow 2)
have := (integrable_mul_exp_neg_mul_sq hb).hasFiniteIntegral
rw [← hasFiniteIntegral_norm_iff] at this ⊢
convert this
rw [norm_mul, norm_mul, norm_cexp_neg_mul_sq b, norm_real, norm_of_nonneg (exp_pos _).le]
theorem integral_mul_cexp_neg_mul_sq {b : ℂ} (hb : 0 < b.re) :
∫ r : ℝ in Ioi 0, (r : ℂ) * cexp (-b * (r : ℂ) ^ 2) = (2 * b)⁻¹ := by
have hb' : b ≠ 0 := by contrapose! hb; rw [hb, zero_re]
have A : ∀ x : ℂ, HasDerivAt (fun x => -(2 * b)⁻¹ * cexp (-b * x ^ 2))
(x * cexp (-b * x ^ 2)) x := by
intro x
convert ((hasDerivAt_pow 2 x).const_mul (-b)).cexp.const_mul (-(2 * b)⁻¹) using 1
field_simp [hb']
ring
have B : Tendsto (fun y : ℝ ↦ -(2 * b)⁻¹ * cexp (-b * (y : ℂ) ^ 2))
atTop (𝓝 (-(2 * b)⁻¹ * 0)) := by
refine Tendsto.const_mul _ (tendsto_zero_iff_norm_tendsto_zero.mpr ?_)
simp_rw [norm_cexp_neg_mul_sq b]
exact tendsto_exp_atBot.comp
((tendsto_pow_atTop two_ne_zero).const_mul_atTop_of_neg (neg_lt_zero.2 hb))
convert integral_Ioi_of_hasDerivAt_of_tendsto' (fun x _ => (A ↑x).comp_ofReal)
(integrable_mul_cexp_neg_mul_sq hb).integrableOn B using 1
simp only [mul_zero, ofReal_zero, zero_pow, Ne, Nat.one_ne_zero,
not_false_iff, Complex.exp_zero, mul_one, sub_neg_eq_add, zero_add, reduceCtorEq]
/-- The *square* of the Gaussian integral `∫ x:ℝ, exp (-b * x^2)` is equal to `π / b`. -/
theorem integral_gaussian_sq_complex {b : ℂ} (hb : 0 < b.re) :
(∫ x : ℝ, cexp (-b * (x : ℂ) ^ 2)) ^ 2 = π / b := by
/- We compute `(∫ exp (-b x^2))^2` as an integral over `ℝ^2`, and then make a polar change
of coordinates. We are left with `∫ r * exp (-b r^2)`, which has been computed in
`integral_mul_cexp_neg_mul_sq` using the fact that this function has an obvious primitive. -/
calc
(∫ x : ℝ, cexp (-b * (x : ℂ) ^ 2)) ^ 2 =
∫ p : ℝ × ℝ, cexp (-b * (p.1 : ℂ) ^ 2) * cexp (-b * (p.2 : ℂ) ^ 2) := by
rw [pow_two, ← integral_prod_mul]; rfl
_ = ∫ p : ℝ × ℝ, cexp (-b * ((p.1 : ℂ)^ 2 + (p.2 : ℂ) ^ 2)) := by
congr
ext1 p
rw [← Complex.exp_add, mul_add]
_ = ∫ p in polarCoord.target, p.1 •
cexp (-b * ((p.1 * Complex.cos p.2) ^ 2 + (p.1 * Complex.sin p.2) ^ 2)) := by
rw [← integral_comp_polarCoord_symm]
simp only [polarCoord_symm_apply, ofReal_mul, ofReal_cos, ofReal_sin]
_ = (∫ r in Ioi (0 : ℝ), r * cexp (-b * (r : ℂ) ^ 2)) * ∫ θ in Ioo (-π) π, 1 := by
rw [← setIntegral_prod_mul]
congr with p : 1
rw [mul_one]
congr
conv_rhs => rw [← one_mul ((p.1 : ℂ) ^ 2), ← sin_sq_add_cos_sq (p.2 : ℂ)]
ring
_ = ↑π / b := by
simp only [neg_mul, integral_const, MeasurableSet.univ, measureReal_restrict_apply,
univ_inter, real_smul, mul_one, ← neg_mul, integral_mul_cexp_neg_mul_sq hb]
rw [volume_real_Ioo_of_le (by linarith [pi_nonneg])]
field_simp [(by contrapose! hb; rw [hb, zero_re] : b ≠ 0)]
ring
theorem integral_gaussian (b : ℝ) : ∫ x : ℝ, exp (-b * x ^ 2) = √(π / b) := by
-- First we deal with the crazy case where `b ≤ 0`: then both sides vanish.
rcases le_or_lt b 0 with (hb | hb)
· rw [integral_undef, sqrt_eq_zero_of_nonpos]
· exact div_nonpos_of_nonneg_of_nonpos pi_pos.le hb
· simpa only [not_lt, integrable_exp_neg_mul_sq_iff] using hb
-- Assume now `b > 0`. Then both sides are non-negative and their squares agree.
refine (sq_eq_sq₀ (by positivity) (by positivity)).1 ?_
rw [← ofReal_inj, ofReal_pow, ← coe_algebraMap, RCLike.algebraMap_eq_ofReal, ← integral_ofReal,
sq_sqrt (div_pos pi_pos hb).le, ← RCLike.algebraMap_eq_ofReal, coe_algebraMap, ofReal_div]
convert integral_gaussian_sq_complex (by rwa [ofReal_re] : 0 < (b : ℂ).re) with _ x
rw [ofReal_exp, ofReal_mul, ofReal_pow, ofReal_neg]
theorem continuousAt_gaussian_integral (b : ℂ) (hb : 0 < re b) :
ContinuousAt (fun c : ℂ => ∫ x : ℝ, cexp (-c * (x : ℂ) ^ 2)) b := by
let f : ℂ → ℝ → ℂ := fun (c : ℂ) (x : ℝ) => cexp (-c * (x : ℂ) ^ 2)
obtain ⟨d, hd, hd'⟩ := exists_between hb
have f_meas : ∀ c : ℂ, AEStronglyMeasurable (f c) volume := fun c => by
apply Continuous.aestronglyMeasurable
exact Complex.continuous_exp.comp (continuous_const.mul (continuous_ofReal.pow 2))
have f_cts : ∀ x : ℝ, ContinuousAt (fun c => f c x) b := fun x =>
(Complex.continuous_exp.comp (continuous_id'.neg.mul continuous_const)).continuousAt
have f_le_bd : ∀ᶠ c : ℂ in 𝓝 b, ∀ᵐ x : ℝ, ‖f c x‖ ≤ exp (-d * x ^ 2) := by
refine eventually_of_mem ((continuous_re.isOpen_preimage _ isOpen_Ioi).mem_nhds hd') ?_
intro c hc; filter_upwards with x
rw [norm_cexp_neg_mul_sq]
gcongr
exact le_of_lt hc
exact
continuousAt_of_dominated (Eventually.of_forall f_meas) f_le_bd (integrable_exp_neg_mul_sq hd)
(ae_of_all _ f_cts)
theorem integral_gaussian_complex {b : ℂ} (hb : 0 < re b) :
∫ x : ℝ, cexp (-b * (x : ℂ) ^ 2) = (π / b) ^ (1 / 2 : ℂ) := by
have nv : ∀ {b : ℂ}, 0 < re b → b ≠ 0 := by intro b hb; contrapose! hb; rw [hb]; simp
apply
(convex_halfSpace_re_gt 0).isPreconnected.eq_of_sq_eq ?_ ?_ (fun c hc => ?_) (fun {c} hc => ?_)
(by simp : 0 < re (1 : ℂ)) ?_ hb
· -- integral is continuous
exact continuousOn_of_forall_continuousAt continuousAt_gaussian_integral
· -- `(π / b) ^ (1 / 2 : ℂ)` is continuous
refine
continuousOn_of_forall_continuousAt fun b hb =>
(continuousAt_cpow_const (Or.inl ?_)).comp (continuousAt_const.div continuousAt_id (nv hb))
rw [div_re, ofReal_im, ofReal_re, zero_mul, zero_div, add_zero]
exact div_pos (mul_pos pi_pos hb) (normSq_pos.mpr (nv hb))
· -- equality at 1
have : ∀ x : ℝ, cexp (-(1 : ℂ) * (x : ℂ) ^ 2) = exp (-(1 : ℝ) * x ^ 2) := by
intro x
simp only [ofReal_exp, neg_mul, one_mul, ofReal_neg, ofReal_pow]
simp_rw [this, ← coe_algebraMap, RCLike.algebraMap_eq_ofReal, integral_ofReal,
← RCLike.algebraMap_eq_ofReal, coe_algebraMap]
conv_rhs =>
congr
· rw [← ofReal_one, ← ofReal_div]
· rw [← ofReal_one, ← ofReal_ofNat, ← ofReal_div]
rw [← ofReal_cpow, ofReal_inj]
· convert integral_gaussian (1 : ℝ) using 1
rw [sqrt_eq_rpow]
· rw [div_one]; exact pi_pos.le
· -- squares of both sides agree
dsimp only [Pi.pow_apply]
rw [integral_gaussian_sq_complex hc, sq]
conv_lhs => rw [← cpow_one (↑π / c)]
rw [← cpow_add _ _ (div_ne_zero (ofReal_ne_zero.mpr pi_ne_zero) (nv hc))]
norm_num
· -- RHS doesn't vanish
rw [Ne, cpow_eq_zero_iff, not_and_or]
exact Or.inl (div_ne_zero (ofReal_ne_zero.mpr pi_ne_zero) (nv hc))
-- The Gaussian integral on the half-line, `∫ x in Ioi 0, exp (-b * x^2)`, for complex `b`.
theorem integral_gaussian_complex_Ioi {b : ℂ} (hb : 0 < re b) :
∫ x : ℝ in Ioi 0, cexp (-b * (x : ℂ) ^ 2) = (π / b) ^ (1 / 2 : ℂ) / 2 := by
have full_integral := integral_gaussian_complex hb
have : MeasurableSet (Ioi (0 : ℝ)) := measurableSet_Ioi
rw [← integral_add_compl this (integrable_cexp_neg_mul_sq hb), compl_Ioi] at full_integral
suffices ∫ x : ℝ in Iic 0, cexp (-b * (x : ℂ) ^ 2) = ∫ x : ℝ in Ioi 0, cexp (-b * (x : ℂ) ^ 2) by
rw [this, ← mul_two] at full_integral
rwa [eq_div_iff]; exact two_ne_zero
have : ∀ c : ℝ, ∫ x in (0 : ℝ)..c, cexp (-b * (x : ℂ) ^ 2) =
∫ x in -c..0, cexp (-b * (x : ℂ) ^ 2) := by
intro c
have := intervalIntegral.integral_comp_sub_left (a := 0) (b := c)
(fun x => cexp (-b * (x : ℂ) ^ 2)) 0
simpa [zero_sub, neg_sq, neg_zero] using this
have t1 :=
intervalIntegral_tendsto_integral_Ioi 0 (integrable_cexp_neg_mul_sq hb).integrableOn tendsto_id
have t2 :
Tendsto (fun c : ℝ => ∫ x : ℝ in (0 : ℝ)..c, cexp (-b * (x : ℂ) ^ 2)) atTop
(𝓝 (∫ x : ℝ in Iic 0, cexp (-b * (x : ℂ) ^ 2))) := by
simp_rw [this]
refine intervalIntegral_tendsto_integral_Iic _ ?_ tendsto_neg_atTop_atBot
apply (integrable_cexp_neg_mul_sq hb).integrableOn
exact tendsto_nhds_unique t2 t1
-- The Gaussian integral on the half-line, `∫ x in Ioi 0, exp (-b * x^2)`, for real `b`.
theorem integral_gaussian_Ioi (b : ℝ) :
∫ x in Ioi (0 : ℝ), exp (-b * x ^ 2) = √(π / b) / 2 := by
rcases le_or_lt b 0 with (hb | hb)
· rw [integral_undef, sqrt_eq_zero_of_nonpos, zero_div]
· exact div_nonpos_of_nonneg_of_nonpos pi_pos.le hb
· rwa [← IntegrableOn, integrableOn_Ioi_exp_neg_mul_sq_iff, not_lt]
rw [← RCLike.ofReal_inj (K := ℂ), ← integral_ofReal, ← RCLike.algebraMap_eq_ofReal,
coe_algebraMap]
convert integral_gaussian_complex_Ioi (by rwa [ofReal_re] : 0 < (b : ℂ).re)
· simp
· rw [sqrt_eq_rpow, ← ofReal_div, ofReal_div, ofReal_cpow]
· norm_num
· exact (div_pos pi_pos hb).le
/-- The special-value formula `Γ(1/2) = √π`, which is equivalent to the Gaussian integral. -/
theorem Real.Gamma_one_half_eq : Real.Gamma (1 / 2) = √π := by
rw [Gamma_eq_integral one_half_pos, ← integral_comp_rpow_Ioi_of_pos zero_lt_two]
convert congr_arg (fun x : ℝ => 2 * x) (integral_gaussian_Ioi 1) using 1
· rw [← integral_const_mul]
refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_
dsimp only
have : (x ^ (2 : ℝ)) ^ (1 / (2 : ℝ) - 1) = x⁻¹ := by
rw [← rpow_mul (le_of_lt hx)]
norm_num
rw [rpow_neg (le_of_lt hx), rpow_one]
rw [smul_eq_mul, this]
field_simp [(ne_of_lt (show 0 < x from hx)).symm]
norm_num; ring
· rw [div_one, ← mul_div_assoc, mul_comm, mul_div_cancel_right₀ _ (two_ne_zero' ℝ)]
/-- The special-value formula `Γ(1/2) = √π`, which is equivalent to the Gaussian integral. -/
theorem Complex.Gamma_one_half_eq : Complex.Gamma (1 / 2) = (π : ℂ) ^ (1 / 2 : ℂ) := by
convert congr_arg ((↑) : ℝ → ℂ) Real.Gamma_one_half_eq
· simpa only [one_div, ofReal_inv, ofReal_ofNat] using Gamma_ofReal (1 / 2)
· rw [sqrt_eq_rpow, ofReal_cpow pi_pos.le, ofReal_div, ofReal_ofNat, ofReal_one]
open scoped Nat in
| /-- The special-value formula `Γ(k + 1 + 1/2) = (2 * k + 1)‼ * √π / (2 ^ (k + 1))` for half-integer
values of the gamma function in terms of `Nat.doubleFactorial`. -/
lemma Real.Gamma_nat_add_one_add_half (k : ℕ) :
Gamma (k + 1 + 1 / 2) = (2 * k + 1 : ℕ)‼ * √π / (2 ^ (k + 1)) := by
induction k with
| zero => simp [-one_div, add_comm (1 : ℝ), Gamma_add_one, Gamma_one_half_eq]; ring
| succ k ih =>
rw [add_right_comm, Gamma_add_one (by positivity), Nat.cast_add, Nat.cast_one, ih, Nat.mul_add]
field_simp
ring
open scoped Nat in
/-- The special-value formula `Γ(k + 1/2) = (2 * k - 1)‼ * √π / (2 ^ k))` for half-integer
values of the gamma function in terms of `Nat.doubleFactorial`. -/
| Mathlib/Analysis/SpecialFunctions/Gaussian/GaussianIntegral.lean | 354 | 367 |
/-
Copyright (c) 2022 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.MeasureTheory.Group.GeometryOfNumbers
import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls
import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic
import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup
/-!
# Convex Bodies
The file contains the definitions of several convex bodies lying in the mixed space `ℝ^r₁ × ℂ^r₂`
associated to a number field of signature `K` and proves several existence theorems by applying
*Minkowski Convex Body Theorem* to those.
## Main definitions and results
* `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all
infinite places `w` with `f : InfinitePlace K → ℝ≥0`.
* `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`.
Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a
nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`.
* `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal
of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see
`convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic
number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`.
## Tags
number field, infinite places
-/
variable (K : Type*) [Field K]
namespace NumberField.mixedEmbedding
open NumberField NumberField.InfinitePlace Module
section convexBodyLT
open Metric NNReal
variable (f : InfinitePlace K → ℝ≥0)
/-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all
infinite places `w`. -/
abbrev convexBodyLT : Set (mixedSpace K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w)))
theorem convexBodyLT_mem {x : K} :
mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real,
embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em,
forall_true_left, norm_embedding_eq]
theorem convexBodyLT_neg_mem (x : mixedSpace K) (hx : x ∈ (convexBodyLT K f)) :
-x ∈ (convexBodyLT K f) := by
simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply,
mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall,
Prod.snd_neg] at hx ⊢
exact hx
theorem convexBodyLT_convex : Convex ℝ (convexBodyLT K f) :=
Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => convex_ball _ _))
open Fintype MeasureTheory MeasureTheory.Measure ENNReal
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT`. -/
noncomputable abbrev convexBodyLTFactor : ℝ≥0 :=
(2 : ℝ≥0) ^ nrRealPlaces K * NNReal.pi ^ nrComplexPlaces K
theorem convexBodyLTFactor_ne_zero : convexBodyLTFactor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLTFactor : 1 ≤ convexBodyLTFactor K :=
one_le_mul (one_le_pow₀ one_le_two) (one_le_pow₀ (one_le_two.trans Real.two_le_pi))
open scoped Classical in
/-- The volume of `(ConvexBodyLt K f)` where `convexBodyLT K f` is the set of points `x`
such that `‖x w‖ < f w` for all infinite places `w`. -/
theorem convexBodyLT_volume :
volume (convexBodyLT K f) = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
∏ x : {w // InfinitePlace.IsComplex w}, ENNReal.ofReal (f x.val) ^ 2 * NNReal.pi := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball, Complex.volume_ball]
_ = ((2 : ℝ≥0) ^ nrRealPlaces K
* (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val)))
* ((∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) *
NNReal.pi ^ nrComplexPlaces K) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat]
_ = (convexBodyLTFactor K) * ((∏ x : {w // InfinitePlace.IsReal w}, .ofReal (f x.val)) *
(∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2)) := by
simp_rw [convexBodyLTFactor, coe_mul, ENNReal.coe_pow]
ring
_ = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by
simp_rw [prod_eq_prod_mul_prod, coe_mul, coe_finset_prod, mult_isReal, mult_isComplex,
pow_one, ENNReal.coe_pow, ofReal_coe_nnreal]
variable {f}
/-- This is a technical result: quite often, we want to impose conditions at all infinite places
but one and choose the value at the remaining place so that we can apply
`exists_ne_zero_mem_ringOfIntegers_lt`. -/
theorem adjust_f {w₁ : InfinitePlace K} (B : ℝ≥0) (hf : ∀ w, w ≠ w₁ → f w ≠ 0) :
∃ g : InfinitePlace K → ℝ≥0, (∀ w, w ≠ w₁ → g w = f w) ∧ ∏ w, (g w) ^ mult w = B := by
classical
let S := ∏ w ∈ Finset.univ.erase w₁, (f w) ^ mult w
refine ⟨Function.update f w₁ ((B * S⁻¹) ^ (mult w₁ : ℝ)⁻¹), ?_, ?_⟩
· exact fun w hw => Function.update_of_ne hw _ f
· rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ w₁), Function.update_self,
Finset.prod_congr rfl fun w hw => by rw [Function.update_of_ne (Finset.ne_of_mem_erase hw)],
← NNReal.rpow_natCast, ← NNReal.rpow_mul, inv_mul_cancel₀, NNReal.rpow_one, mul_assoc,
inv_mul_cancel₀, mul_one]
· rw [Finset.prod_ne_zero_iff]
exact fun w hw => pow_ne_zero _ (hf w (Finset.ne_of_mem_erase hw))
· rw [mult]; split_ifs <;> norm_num
end convexBodyLT
section convexBodyLT'
open Metric ENNReal NNReal
variable (f : InfinitePlace K → ℝ≥0) (w₀ : {w : InfinitePlace K // IsComplex w})
open scoped Classical in
/-- A version of `convexBodyLT` with an additional condition at a fixed complex place. This is
needed to ensure the element constructed is not real, see for example
`exists_primitive_element_lt_of_isComplex`.
-/
abbrev convexBodyLT' : Set (mixedSpace K) :=
(Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } ↦ ball 0 (f w))) ×ˢ
(Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } ↦
if w = w₀ then {x | |x.re| < 1 ∧ |x.im| < (f w : ℝ) ^ 2} else ball 0 (f w)))
theorem convexBodyLT'_mem {x : K} :
mixedEmbedding K x ∈ convexBodyLT' K f w₀ ↔
(∀ w : InfinitePlace K, w ≠ w₀ → w x < f w) ∧
|(w₀.val.embedding x).re| < 1 ∧ |(w₀.val.embedding x).im| < (f w₀ : ℝ) ^ 2 := by
simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ,
forall_true_left, Pi.ringHom_apply, mem_ball_zero_iff, ← Complex.norm_real,
embedding_of_isReal_apply, norm_embedding_eq, Subtype.forall]
refine ⟨fun ⟨h₁, h₂⟩ ↦ ⟨fun w h_ne ↦ ?_, ?_⟩, fun ⟨h₁, h₂⟩ ↦ ⟨fun w hw ↦ ?_, fun w hw ↦ ?_⟩⟩
· by_cases hw : IsReal w
· exact norm_embedding_eq w _ ▸ h₁ w hw
· specialize h₂ w (not_isReal_iff_isComplex.mp hw)
rw [apply_ite (w.embedding x ∈ ·), Set.mem_setOf_eq,
mem_ball_zero_iff, norm_embedding_eq] at h₂
rwa [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] at h₂
· simpa [if_true] using h₂ w₀.val w₀.prop
· exact h₁ w (ne_of_isReal_isComplex hw w₀.prop)
· by_cases h_ne : w = w₀
· simpa [h_ne]
· rw [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)]
rw [mem_ball_zero_iff, norm_embedding_eq]
exact h₁ w h_ne
theorem convexBodyLT'_neg_mem (x : mixedSpace K) (hx : x ∈ convexBodyLT' K f w₀) :
-x ∈ convexBodyLT' K f w₀ := by
simp only [Set.mem_prod, Set.mem_pi, Set.mem_univ, mem_ball, dist_zero_right, Real.norm_eq_abs,
true_implies, Subtype.forall, Prod.fst_neg, Pi.neg_apply, norm_neg, Prod.snd_neg] at hx ⊢
convert hx using 3
split_ifs <;> simp
theorem convexBodyLT'_convex : Convex ℝ (convexBodyLT' K f w₀) := by
refine Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => ?_))
split_ifs
· simp_rw [abs_lt]
refine Convex.inter ((convex_halfSpace_re_gt _).inter (convex_halfSpace_re_lt _))
((convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _))
· exact convex_ball _ _
open MeasureTheory MeasureTheory.Measure
variable [NumberField K]
/-- The fudge factor that appears in the formula for the volume of `convexBodyLT'`. -/
noncomputable abbrev convexBodyLT'Factor : ℝ≥0 :=
(2 : ℝ≥0) ^ (nrRealPlaces K + 2) * NNReal.pi ^ (nrComplexPlaces K - 1)
theorem convexBodyLT'Factor_ne_zero : convexBodyLT'Factor K ≠ 0 :=
mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero)
theorem one_le_convexBodyLT'Factor : 1 ≤ convexBodyLT'Factor K :=
one_le_mul (one_le_pow₀ one_le_two) (one_le_pow₀ (one_le_two.trans Real.two_le_pi))
open scoped Classical in
theorem convexBodyLT'_volume :
volume (convexBodyLT' K f w₀) = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
have vol_box : ∀ B : ℝ≥0, volume {x : ℂ | |x.re| < 1 ∧ |x.im| < B^2} = 4*B^2 := by
intro B
rw [← (Complex.volume_preserving_equiv_real_prod.symm).measure_preimage]
· simp_rw [Set.preimage_setOf_eq, Complex.measurableEquivRealProd_symm_apply]
rw [show {a : ℝ × ℝ | |a.1| < 1 ∧ |a.2| < B ^ 2} =
Set.Ioo (-1 : ℝ) (1 : ℝ) ×ˢ Set.Ioo (- (B : ℝ) ^ 2) ((B : ℝ) ^ 2) by
ext; simp_rw [Set.mem_setOf_eq, Set.mem_prod, Set.mem_Ioo, abs_lt]]
simp_rw [volume_eq_prod, prod_prod, Real.volume_Ioo, sub_neg_eq_add, one_add_one_eq_two,
← two_mul, ofReal_mul zero_le_two, ofReal_pow (coe_nonneg B), ofReal_ofNat,
ofReal_coe_nnreal, ← mul_assoc, show (2 : ℝ≥0∞) * 2 = 4 by norm_num]
· refine (MeasurableSet.inter ?_ ?_).nullMeasurableSet
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_re) measurable_const
· exact measurableSet_lt (measurable_norm.comp Complex.measurable_im) measurable_const
calc
_ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2 * pi) *
(4 * (f w₀) ^ 2)) := by
simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball]
rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)]
congr 2
· refine Finset.prod_congr rfl (fun w' hw' ↦ ?_)
rw [if_neg (Finset.ne_of_mem_erase hw'), Complex.volume_ball]
· simpa only [ite_true] using vol_box (f w₀)
_ = ((2 : ℝ≥0) ^ nrRealPlaces K *
(∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) *
((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2) *
↑pi ^ (nrComplexPlaces K - 1) * (4 * (f w₀) ^ 2)) := by
simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const,
Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ofReal_ofNat,
ofReal_coe_nnreal, coe_ofNat]
_ = convexBodyLT'Factor K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))
* (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) := by
rw [show (4 : ℝ≥0∞) = (2 : ℝ≥0) ^ 2 by norm_num, convexBodyLT'Factor, pow_add,
← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀), ofReal_coe_nnreal]
simp_rw [coe_mul, ENNReal.coe_pow]
ring
_ = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by
simp_rw [prod_eq_prod_mul_prod, coe_mul, coe_finset_prod, mult_isReal, mult_isComplex,
pow_one, ENNReal.coe_pow, ofReal_coe_nnreal, mul_assoc]
end convexBodyLT'
section convexBodySum
open ENNReal MeasureTheory Fintype
open scoped Real NNReal
variable [NumberField K] (B : ℝ)
variable {K}
/-- The function that sends `x : mixedSpace K` to `∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖`. It defines a
norm and it used to define `convexBodySum`. -/
noncomputable abbrev convexBodySumFun (x : mixedSpace K) : ℝ := ∑ w, mult w * normAtPlace w x
theorem convexBodySumFun_apply (x : mixedSpace K) :
convexBodySumFun x = ∑ w, mult w * normAtPlace w x := rfl
open scoped Classical in
theorem convexBodySumFun_apply' (x : mixedSpace K) :
convexBodySumFun x = ∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖ := by
simp_rw [convexBodySumFun_apply, sum_eq_sum_add_sum, mult_isReal, mult_isComplex,
Nat.cast_one, one_mul, Nat.cast_ofNat, normAtPlace_apply_of_isReal (Subtype.prop _),
normAtPlace_apply_of_isComplex (Subtype.prop _), Finset.mul_sum]
theorem convexBodySumFun_nonneg (x : mixedSpace K) :
0 ≤ convexBodySumFun x :=
Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _))
theorem convexBodySumFun_neg (x : mixedSpace K) :
convexBodySumFun (- x) = convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_neg]
theorem convexBodySumFun_add_le (x y : mixedSpace K) :
convexBodySumFun (x + y) ≤ convexBodySumFun x + convexBodySumFun y := by
simp_rw [convexBodySumFun, ← Finset.sum_add_distrib, ← mul_add]
exact Finset.sum_le_sum
fun _ _ ↦ mul_le_mul_of_nonneg_left (normAtPlace_add_le _ x y) (Nat.cast_pos.mpr mult_pos).le
theorem convexBodySumFun_smul (c : ℝ) (x : mixedSpace K) :
convexBodySumFun (c • x) = |c| * convexBodySumFun x := by
simp_rw [convexBodySumFun, normAtPlace_smul, ← mul_assoc, mul_comm, Finset.mul_sum, mul_assoc]
theorem convexBodySumFun_eq_zero_iff (x : mixedSpace K) :
convexBodySumFun x = 0 ↔ x = 0 := by
rw [← forall_normAtPlace_eq_zero_iff, convexBodySumFun, Finset.sum_eq_zero_iff_of_nonneg
fun _ _ ↦ mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)]
conv =>
enter [1, w, hw]
rw [mul_left_mem_nonZeroDivisors_eq_zero_iff
(mem_nonZeroDivisors_iff_ne_zero.mpr <| Nat.cast_ne_zero.mpr mult_ne_zero)]
simp_rw [Finset.mem_univ, true_implies]
open scoped Classical in
theorem norm_le_convexBodySumFun (x : mixedSpace K) : ‖x‖ ≤ convexBodySumFun x := by
rw [norm_eq_sup'_normAtPlace]
refine (Finset.sup'_le_iff _ _).mpr fun w _ ↦ ?_
rw [convexBodySumFun_apply, ← Finset.univ.add_sum_erase _ (Finset.mem_univ w)]
refine le_add_of_le_of_nonneg ?_ ?_
· exact le_mul_of_one_le_left (normAtPlace_nonneg w x) one_le_mult
· exact Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le
(normAtPlace_nonneg _ _))
variable (K)
theorem convexBodySumFun_continuous :
Continuous (convexBodySumFun : mixedSpace K → ℝ) := by
refine continuous_finset_sum Finset.univ fun w ↦ ?_
obtain hw | hw := isReal_or_isComplex w
all_goals
· simp only [normAtPlace_apply_of_isReal, normAtPlace_apply_of_isComplex, hw]
fun_prop
/-- The convex body equal to the set of points `x : mixedSpace K` such that
`∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`. -/
abbrev convexBodySum : Set (mixedSpace K) := { x | convexBodySumFun x ≤ B }
open scoped Classical in
theorem convexBodySum_volume_eq_zero_of_le_zero {B} (hB : B ≤ 0) :
volume (convexBodySum K B) = 0 := by
obtain hB | hB := lt_or_eq_of_le hB
· suffices convexBodySum K B = ∅ by rw [this, measure_empty]
ext x
refine ⟨fun hx => ?_, fun h => h.elim⟩
rw [Set.mem_setOf] at hx
linarith [convexBodySumFun_nonneg x]
· suffices convexBodySum K B = { 0 } by rw [this, measure_singleton]
ext
rw [convexBodySum, Set.mem_setOf_eq, Set.mem_singleton_iff, hB, ← convexBodySumFun_eq_zero_iff]
exact (convexBodySumFun_nonneg _).le_iff_eq
theorem convexBodySum_mem {x : K} :
mixedEmbedding K x ∈ (convexBodySum K B) ↔
∑ w : InfinitePlace K, (mult w) * w.val x ≤ B := by
| simp_rw [Set.mem_setOf_eq, convexBodySumFun, normAtPlace_apply]
rfl
theorem convexBodySum_neg_mem {x : mixedSpace K} (hx : x ∈ (convexBodySum K B)) :
-x ∈ (convexBodySum K B) := by
rw [Set.mem_setOf, convexBodySumFun_neg]
exact hx
| Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean | 337 | 343 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Data.Finset.Attach
import Mathlib.Data.Finset.Disjoint
import Mathlib.Data.Finset.Erase
import Mathlib.Data.Finset.Filter
import Mathlib.Data.Finset.Range
import Mathlib.Data.Finset.SDiff
import Mathlib.Data.Multiset.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.Directed
import Mathlib.Order.Interval.Set.Defs
import Mathlib.Data.Set.SymmDiff
/-!
# Basic lemmas on finite sets
This file contains lemmas on the interaction of various definitions on the `Finset` type.
For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`.
## Main declarations
### Main definitions
* `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element
satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate.
### Equivalences between finsets
* The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there
for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that
`s ≃ t`.
TODO: examples
## Tags
finite sets, finset
-/
-- Assert that we define `Finset` without the material on `List.sublists`.
-- Note that we cannot use `List.sublists` itself as that is defined very early.
assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid
open Multiset Subtype Function
universe u
variable {α : Type*} {β : Type*} {γ : Type*}
namespace Finset
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
set_option linter.deprecated false in
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) :
SizeOf.sizeOf x < SizeOf.sizeOf s := by
cases s
dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf]
rw [Nat.add_comm]
refine lt_trans ?_ (Nat.lt_succ_self _)
exact Multiset.sizeOf_lt_sizeOf_of_mem hx
/-! ### Lattice structure -/
section Lattice
variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α}
/-! #### union -/
@[simp]
theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t :=
ext fun a => by simp
@[simp]
theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by
simp only [disjoint_left, mem_union, or_imp, forall_and]
@[simp]
theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by
simp only [disjoint_right, mem_union, or_imp, forall_and]
/-! #### inter -/
theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty :=
not_disjoint_iff.trans <| by simp [Finset.Nonempty]
alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter
theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by
rw [← not_disjoint_iff_nonempty_inter]
exact em _
omit [DecidableEq α] in
theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) :
Disjoint s t ↔ s = ∅ :=
disjoint_of_le_iff_left_eq_bot h
lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} :
s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by
simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _),
not_disjoint_iff_nonempty_inter]
end Lattice
instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance
instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le
/-! ### erase -/
section Erase
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
@[simp]
theorem erase_empty (a : α) : erase ∅ a = ∅ :=
rfl
protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty :=
(hs.exists_ne a).imp <| by aesop
@[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by
simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)]
refine ⟨?_, fun hs ↦ hs.exists_ne a⟩
rintro ⟨b, hb, hba⟩
exact ⟨_, hb, _, ha, hba⟩
@[simp]
theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by
ext x
simp
@[simp]
theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a :=
ext fun x => by
simp +contextual only [mem_erase, mem_insert, and_congr_right_iff,
false_or, iff_self, imp_true_iff]
theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by
rw [erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) :
erase (insert a s) b = insert a (erase s b) :=
ext fun x => by
have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h
simp only [mem_erase, mem_insert, and_or_left, this]
theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) :
erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by
simp only [cons_eq_insert, erase_insert_of_ne hb]
@[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s :=
ext fun x => by
simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and]
apply or_iff_right_of_imp
rintro rfl
exact h
lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by
aesop
lemma insert_erase_invOn :
Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} :=
⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩
theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s :=
calc
s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _
_ = _ := insert_erase h
theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by
refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩
obtain ⟨a, ht, hs⟩ := not_subset.1 h.2
exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩
theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s :=
ssubset_iff_exists_subset_erase.2
⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩
theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by
rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by
simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp]
exact forall_congr' fun x => forall_swap
theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s :=
subset_insert_iff.1 <| Subset.rfl
theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) :=
subset_insert_iff.2 <| Subset.rfl
theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by
rw [subset_insert_iff, erase_eq_of_not_mem h]
theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by
rw [← subset_insert_iff, insert_eq_of_mem h]
theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a :=
fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h]
end Erase
lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) :
∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by
classical
obtain ⟨a, ha, b, hb, hab⟩ := hs
have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩
refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;>
simp [insert_erase this, insert_erase ha, *]
/-! ### sdiff -/
section Sdiff
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by
ext; aesop
-- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`,
-- or instead add `Finset.union_singleton`/`Finset.singleton_union`?
theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ {a} = erase s a := by
ext
rw [mem_erase, mem_sdiff, mem_singleton, and_comm]
-- This lemma matches `Finset.insert_eq` in functionality.
theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} :=
(sdiff_singleton_eq_erase _ _).symm
theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by
simp_rw [erase_eq, disjoint_sdiff_comm]
lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by
rw [disjoint_erase_comm, erase_insert ha]
lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by
rw [← disjoint_erase_comm, erase_insert ha]
theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by
rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right]
exact ⟨not_mem_erase _ _, hst⟩
theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by
rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left]
exact ⟨not_mem_erase _ _, hst⟩
theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by
simp only [erase_eq, inter_sdiff_assoc]
@[simp]
theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by
simpa only [inter_comm t] using inter_erase a t s
theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by
simp_rw [erase_eq, sdiff_right_comm]
theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by
rw [erase_inter, inter_erase]
theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by
simp_rw [erase_eq, union_sdiff_distrib]
theorem insert_inter_distrib (s t : Finset α) (a : α) :
insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left]
theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by
simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm]
theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by
rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha]
theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by
rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha]
theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by
simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)]
theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by
simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib,
inter_comm]
theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) :
insert x (s \ insert x t) = s \ t := by
rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)]
theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by
rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq,
union_comm]
theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by
rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq]
theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by
rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff]
--TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra`
theorem sdiff_disjoint : Disjoint (t \ s) s :=
disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2
theorem disjoint_sdiff : Disjoint s (t \ s) :=
sdiff_disjoint.symm
theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) :=
disjoint_of_subset_right inter_subset_right sdiff_disjoint
end Sdiff
/-! ### attach -/
@[simp]
theorem attach_empty : attach (∅ : Finset α) = ∅ :=
rfl
@[simp]
theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by
simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff
@[simp]
theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by
simp [eq_empty_iff_forall_not_mem]
/-! ### filter -/
section Filter
variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α}
theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by
classical
ext x
simp only [mem_singleton, forall_eq, mem_filter]
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) :
filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) :=
eq_of_veq <| Multiset.filter_cons_of_pos s.val hp
theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) :
filter p (cons a s ha) = filter p s :=
eq_of_veq <| Multiset.filter_cons_of_neg s.val hp
theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] :
Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by
constructor <;> simp +contextual [disjoint_left]
theorem disjoint_filter_filter' (s t : Finset α)
{p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) :
Disjoint (s.filter p) (t.filter q) := by
simp_rw [disjoint_left, mem_filter]
rintro a ⟨_, hp⟩ ⟨_, hq⟩
rw [Pi.disjoint_iff] at h
simpa [hp, hq] using h a
theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop)
[DecidablePred p] [∀ x, Decidable (¬p x)] :
Disjoint (s.filter p) (t.filter fun a => ¬p a) :=
disjoint_filter_filter' s t disjoint_compl_right
theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) :
filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) :=
eq_of_veq <| Multiset.filter_add _ _ _
theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) :
filter p (cons a s ha) =
if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by
split_ifs with h
· rw [filter_cons_of_pos _ _ _ ha h]
· rw [filter_cons_of_neg _ _ _ ha h]
section
variable [DecidableEq α]
theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p :=
ext fun _ => by simp only [mem_filter, mem_union, or_and_right]
theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x :=
ext fun x => by simp [mem_filter, mem_union, ← and_or_left]
theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] :
(s.filter fun i => i ∈ t) = s ∩ t :=
ext fun i => by simp [mem_filter, mem_inter]
theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by
ext
simp [mem_filter, mem_inter, and_assoc]
theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by
ext
simp only [mem_inter, mem_filter, and_right_comm]
theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by
rw [inter_comm, filter_inter, inter_comm]
theorem filter_insert (a : α) (s : Finset α) :
filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by
ext x
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by
ext x
simp only [and_assoc, mem_filter, iff_self, mem_erase]
theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q :=
ext fun _ => by simp [mem_filter, mem_union, and_or_left]
theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q :=
ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc]
theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p :=
ext fun a => by
simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or,
Bool.not_eq_true, and_or_left, and_not_self, or_false]
lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] :
s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by
rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)]
theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ :=
ext fun _ => by simp [mem_sdiff, mem_filter]
theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) :
∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by
classical
refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩
· simp [filter_union_right, em]
· intro x
simp
· intro x
simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp]
intro hx hx₂
exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩
-- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing
-- on, e.g. `x ∈ s.filter (Eq b)`.
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq'` with the equality the other way.
-/
theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) :
s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by
split_ifs with h
· ext
simp only [mem_filter, mem_singleton, decide_eq_true_eq]
refine ⟨fun h => h.2.symm, ?_⟩
rintro rfl
exact ⟨h, rfl⟩
· ext
simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq]
rintro m rfl
exact h m
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq` with the equality the other way.
-/
theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) :
(s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b)
theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) :
(s.filter fun a => b ≠ a) = s.erase b := by
ext
simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not]
tauto
theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b)
theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) :
s.filter p ∪ s.filter q = s :=
(filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial
theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) :
(s.filter p ∪ s.filter fun a => ¬p a) = s :=
filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p
end
end Filter
/-! ### range -/
section Range
open Nat
variable {n m l : ℕ}
@[simp]
theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by
convert filter_eq (range n) m using 2
· ext
rw [eq_comm]
· simp
end Range
end Finset
/-! ### dedup on list and multiset -/
namespace Multiset
variable [DecidableEq α] {s t : Multiset α}
@[simp]
theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by
ext; simp
@[simp]
theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 :=
Finset.val_inj.symm.trans Multiset.dedup_eq_zero
@[simp]
theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by
simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty
@[simp]
theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] :
Multiset.toFinset (s.filter p) = s.toFinset.filter p := by
ext; simp
end Multiset
namespace List
variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β}
{s : Finset α} {t : Set β} {t' : Finset β}
@[simp]
theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by
ext
simp
@[simp]
theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by
ext
simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff
@[simp]
theorem toFinset_filter (s : List α) (p : α → Bool) :
(s.filter p).toFinset = s.toFinset.filter (p ·) := by
ext; simp [List.mem_filter]
end List
namespace Finset
section ToList
@[simp]
theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ :=
Multiset.toList_eq_nil.trans val_eq_zero
theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by simp
@[simp]
theorem toList_empty : (∅ : Finset α).toList = [] :=
toList_eq_nil.mpr rfl
theorem Nonempty.toList_ne_nil {s : Finset α} (hs : s.Nonempty) : s.toList ≠ [] :=
mt toList_eq_nil.mp hs.ne_empty
theorem Nonempty.not_empty_toList {s : Finset α} (hs : s.Nonempty) : ¬s.toList.isEmpty :=
mt empty_toList.mp hs.ne_empty
end ToList
/-! ### choose -/
section Choose
variable (p : α → Prop) [DecidablePred p] (l : Finset α)
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the corresponding subtype. -/
def chooseX (hp : ∃! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } :=
Multiset.chooseX p l.val hp
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the ambient type. -/
def choose (hp : ∃! a, a ∈ l ∧ p a) : α :=
chooseX p l hp
theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
end Finset
namespace Equiv
variable [DecidableEq α] {s t : Finset α}
open Finset
/-- The disjoint union of finsets is a sum -/
def Finset.union (s t : Finset α) (h : Disjoint s t) :
s ⊕ t ≃ (s ∪ t : Finset α) :=
Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm
@[simp]
theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) :
Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ :=
rfl
@[simp]
theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) :
Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ :=
rfl
/-- The type of dependent functions on the disjoint union of finsets `s ∪ t` is equivalent to the
type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/
def piFinsetUnion {ι} [DecidableEq ι] (α : ι → Type*) {s t : Finset ι} (h : Disjoint s t) :
((∀ i : s, α i) × ∀ i : t, α i) ≃ ∀ i : (s ∪ t : Finset ι), α i :=
let e := Equiv.Finset.union s t h
sumPiEquivProdPi (fun b ↦ α (e b)) |>.symm.trans (.piCongrLeft (fun i : ↥(s ∪ t) ↦ α i) e)
/-- A finset is equivalent to its coercion as a set. -/
def _root_.Finset.equivToSet (s : Finset α) : s ≃ s.toSet where
toFun a := ⟨a.1, mem_coe.2 a.2⟩
invFun a := ⟨a.1, mem_coe.1 a.2⟩
left_inv := fun _ ↦ rfl
right_inv := fun _ ↦ rfl
end Equiv
namespace Multiset
variable [DecidableEq α]
@[simp]
lemma toFinset_replicate (n : ℕ) (a : α) :
(replicate n a).toFinset = if n = 0 then ∅ else {a} := by
ext x
simp only [mem_toFinset, Finset.mem_singleton, mem_replicate]
split_ifs with hn <;> simp [hn]
end Multiset
| Mathlib/Data/Finset/Basic.lean | 2,248 | 2,249 | |
/-
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.Order.Archimedean.Basic
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Topology.Algebra.InfiniteSum.NatInt
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Topology.Order.MonotoneConvergence
/-!
# Infinite sum or product in an order
This file provides lemmas about the interaction of infinite sums and products and order operations.
-/
open Finset Filter Function
variable {ι κ α : Type*}
section Preorder
variable [Preorder α] [CommMonoid α] [TopologicalSpace α] {a c : α} {f : ι → α}
@[to_additive]
lemma hasProd_le_of_prod_le [ClosedIicTopology α]
(hf : HasProd f a) (h : ∀ s, ∏ i ∈ s, f i ≤ c) : a ≤ c :=
le_of_tendsto' hf h
@[to_additive]
theorem le_hasProd_of_le_prod [ClosedIciTopology α]
(hf : HasProd f a) (h : ∀ s, c ≤ ∏ i ∈ s, f i) : c ≤ a :=
ge_of_tendsto' hf h
@[to_additive]
protected theorem Multipliable.tprod_le_of_prod_range_le [ClosedIicTopology α] {f : ℕ → α}
(hf : Multipliable f) (h : ∀ n, ∏ i ∈ range n, f i ≤ c) : ∏' n, f n ≤ c :=
le_of_tendsto' hf.hasProd.tendsto_prod_nat h
@[deprecated (since := "2025-04-12")] alias tsum_le_of_sum_range_le :=
Summable.tsum_le_of_sum_range_le
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_of_prod_range_le :=
Multipliable.tprod_le_of_prod_range_le
end Preorder
section OrderedCommMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
[TopologicalSpace α] [OrderClosedTopology α] {f g : ι → α}
{a a₁ a₂ : α}
@[to_additive]
theorem hasProd_le (h : ∀ i, f i ≤ g i) (hf : HasProd f a₁) (hg : HasProd g a₂) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto' hf hg fun _ ↦ prod_le_prod' fun i _ ↦ h i
@[to_additive]
theorem hasProd_mono (hf : HasProd f a₁) (hg : HasProd g a₂) (h : f ≤ g) : a₁ ≤ a₂ :=
hasProd_le h hf hg
@[to_additive]
theorem hasProd_le_inj {g : κ → α} (e : ι → κ) (he : Injective e)
(hs : ∀ c, c ∉ Set.range e → 1 ≤ g c) (h : ∀ i, f i ≤ g (e i)) (hf : HasProd f a₁)
(hg : HasProd g a₂) : a₁ ≤ a₂ := by
rw [← hasProd_extend_one he] at hf
refine hasProd_le (fun c ↦ ?_) hf hg
obtain ⟨i, rfl⟩ | h := em (c ∈ Set.range e)
· rw [he.extend_apply]
exact h _
· rw [extend_apply' _ _ _ h]
exact hs _ h
@[to_additive]
protected theorem Multipliable.tprod_le_tprod_of_inj {g : κ → α} (e : ι → κ) (he : Injective e)
(hs : ∀ c, c ∉ Set.range e → 1 ≤ g c) (h : ∀ i, f i ≤ g (e i)) (hf : Multipliable f)
(hg : Multipliable g) : tprod f ≤ tprod g :=
hasProd_le_inj _ he hs h hf.hasProd hg.hasProd
@[deprecated (since := "2025-04-12")] alias tsum_le_tsum_of_inj := Summable.tsum_le_tsum_of_inj
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_tprod_of_inj :=
Multipliable.tprod_le_tprod_of_inj
@[to_additive]
protected lemma Multipliable.tprod_subtype_le {κ γ : Type*} [CommGroup γ] [PartialOrder γ]
[IsOrderedMonoid γ] [UniformSpace γ] [IsUniformGroup γ] [OrderClosedTopology γ]
[CompleteSpace γ] (f : κ → γ) (β : Set κ) (h : ∀ a : κ, 1 ≤ f a) (hf : Multipliable f) :
(∏' (b : β), f b) ≤ (∏' (a : κ), f a) := by
apply Multipliable.tprod_le_tprod_of_inj _
(Subtype.coe_injective)
(by simp only [Subtype.range_coe_subtype, Set.setOf_mem_eq, h, implies_true])
(by simp only [le_refl, Subtype.forall, implies_true])
(by apply hf.subtype)
apply hf
@[deprecated (since := "2025-04-12")] alias tsum_subtype_le := Summable.tsum_subtype_le
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_subtype_le :=
Multipliable.tprod_subtype_le
@[to_additive]
theorem prod_le_hasProd (s : Finset ι) (hs : ∀ i, i ∉ s → 1 ≤ f i) (hf : HasProd f a) :
∏ i ∈ s, f i ≤ a :=
ge_of_tendsto hf (eventually_atTop.2
⟨s, fun _t hst ↦ prod_le_prod_of_subset_of_one_le' hst fun i _ hbs ↦ hs i hbs⟩)
@[to_additive]
theorem isLUB_hasProd (h : ∀ i, 1 ≤ f i) (hf : HasProd f a) :
IsLUB (Set.range fun s ↦ ∏ i ∈ s, f i) a := by
classical
exact isLUB_of_tendsto_atTop (Finset.prod_mono_set_of_one_le' h) hf
@[to_additive]
theorem le_hasProd (hf : HasProd f a) (i : ι) (hb : ∀ j, j ≠ i → 1 ≤ f j) : f i ≤ a :=
calc
f i = ∏ i ∈ {i}, f i := by rw [prod_singleton]
_ ≤ a := prod_le_hasProd _ (by simpa) hf
@[to_additive]
theorem lt_hasProd [MulRightStrictMono α] (hf : HasProd f a) (i : ι)
(hi : ∀ (j : ι), j ≠ i → 1 ≤ f j) (j : ι) (hij : j ≠ i) (hj : 1 < f j) :
f i < a := by
classical
calc
f i < f j * f i := lt_mul_of_one_lt_left' (f i) hj
_ = ∏ k ∈ {j, i}, f k := by rw [Finset.prod_pair hij]
_ ≤ a := prod_le_hasProd _ (fun k hk ↦ hi k (hk ∘ mem_insert_of_mem ∘ mem_singleton.mpr)) hf
@[to_additive]
protected theorem Multipliable.prod_le_tprod {f : ι → α} (s : Finset ι) (hs : ∀ i, i ∉ s → 1 ≤ f i)
(hf : Multipliable f) : ∏ i ∈ s, f i ≤ ∏' i, f i :=
prod_le_hasProd s hs hf.hasProd
@[deprecated (since := "2025-04-12")] alias sum_le_tsum := Summable.sum_le_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias prod_le_tprod :=
Multipliable.prod_le_tprod
@[to_additive]
protected theorem Multipliable.le_tprod (hf : Multipliable f) (i : ι) (hb : ∀ j, j ≠ i → 1 ≤ f j) :
f i ≤ ∏' i, f i :=
le_hasProd hf.hasProd i hb
@[deprecated (since := "2025-04-12")] alias le_tsum := Summable.le_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias le_tprod := Multipliable.le_tprod
@[to_additive]
protected theorem Multipliable.tprod_le_tprod (h : ∀ i, f i ≤ g i) (hf : Multipliable f)
(hg : Multipliable g) : ∏' i, f i ≤ ∏' i, g i :=
hasProd_le h hf.hasProd hg.hasProd
@[deprecated (since := "2025-04-12")] alias tsum_le_tsum := Summable.tsum_le_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_tprod :=
Multipliable.tprod_le_tprod
@[to_additive (attr := mono)]
protected theorem Multipliable.tprod_mono (hf : Multipliable f) (hg : Multipliable g) (h : f ≤ g) :
∏' n, f n ≤ ∏' n, g n :=
hf.tprod_le_tprod h hg
@[deprecated (since := "2025-04-12")] alias tsum_mono := Summable.tsum_mono
@[to_additive existing (attr := mono), deprecated (since := "2025-04-12")] alias tprod_mono :=
Multipliable.tprod_mono
omit [IsOrderedMonoid α] in
@[to_additive]
protected theorem Multipliable.tprod_le_of_prod_le (hf : Multipliable f)
(h : ∀ s, ∏ i ∈ s, f i ≤ a₂) : ∏' i, f i ≤ a₂ :=
hasProd_le_of_prod_le hf.hasProd h
@[deprecated (since := "2025-04-12")] alias tsum_le_of_sum_le := Summable.tsum_le_of_sum_le
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_of_prod_le :=
Multipliable.tprod_le_of_prod_le
omit [IsOrderedMonoid α] in
@[to_additive]
theorem tprod_le_of_prod_le' (ha₂ : 1 ≤ a₂) (h : ∀ s, ∏ i ∈ s, f i ≤ a₂) : ∏' i, f i ≤ a₂ := by
by_cases hf : Multipliable f
· exact hf.tprod_le_of_prod_le h
· rw [tprod_eq_one_of_not_multipliable hf]
exact ha₂
@[to_additive]
theorem HasProd.one_le (h : ∀ i, 1 ≤ g i) (ha : HasProd g a) : 1 ≤ a :=
hasProd_le h hasProd_one ha
@[to_additive]
theorem HasProd.le_one (h : ∀ i, g i ≤ 1) (ha : HasProd g a) : a ≤ 1 :=
hasProd_le h ha hasProd_one
@[to_additive tsum_nonneg]
theorem one_le_tprod (h : ∀ i, 1 ≤ g i) : 1 ≤ ∏' i, g i := by
by_cases hg : Multipliable g
· exact hg.hasProd.one_le h
| · rw [tprod_eq_one_of_not_multipliable hg]
@[to_additive]
theorem tprod_le_one (h : ∀ i, f i ≤ 1) : ∏' i, f i ≤ 1 := by
by_cases hf : Multipliable f
| Mathlib/Topology/Algebra/InfiniteSum/Order.lean | 193 | 197 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Batteries.Data.Nat.Gcd
import Mathlib.Algebra.Group.Nat.Units
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.GroupWithZero.Nat
/-!
# Properties of `Nat.gcd`, `Nat.lcm`, and `Nat.Coprime`
Definitions are provided in batteries.
Generalizations of these are provided in a later file as `GCDMonoid.gcd` and
`GCDMonoid.lcm`.
Note that the global `IsCoprime` is not a straightforward generalization of `Nat.Coprime`, see
`Nat.isCoprime_iff_coprime` for the connection between the two.
Most of this file could be moved to batteries as well.
-/
assert_not_exists OrderedCommMonoid
namespace Nat
variable {a a₁ a₂ b b₁ b₂ c : ℕ}
/-! ### `gcd` -/
theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) :
d = a.gcd b :=
(dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm
/-! Lemmas where one argument consists of addition of a multiple of the other -/
@[simp]
theorem pow_sub_one_mod_pow_sub_one (a b c : ℕ) : (a ^ c - 1) % (a ^ b - 1) = a ^ (c % b) - 1 := by
rcases eq_zero_or_pos a with rfl | ha0
· simp [zero_pow_eq]; split_ifs <;> simp
rcases Nat.eq_or_lt_of_le ha0 with rfl | ha1
· simp
rcases eq_zero_or_pos b with rfl | hb0
· simp
rcases lt_or_le c b with h | h
· rw [mod_eq_of_lt, mod_eq_of_lt h]
rwa [Nat.sub_lt_sub_iff_right (one_le_pow c a ha0), Nat.pow_lt_pow_iff_right ha1]
· suffices a ^ (c - b + b) - 1 = a ^ (c - b) * (a ^ b - 1) + (a ^ (c - b) - 1) by
rw [← Nat.sub_add_cancel h, add_mod_right, this, add_mod, mul_mod, mod_self,
mul_zero, zero_mod, zero_add, mod_mod, pow_sub_one_mod_pow_sub_one]
rw [← Nat.add_sub_assoc (one_le_pow (c - b) a ha0), ← mul_add_one, pow_add,
Nat.sub_add_cancel (one_le_pow b a ha0)]
@[simp]
theorem pow_sub_one_gcd_pow_sub_one (a b c : ℕ) :
gcd (a ^ b - 1) (a ^ c - 1) = a ^ gcd b c - 1 := by
| rcases eq_zero_or_pos b with rfl | hb
· simp
| Mathlib/Data/Nat/GCD/Basic.lean | 58 | 59 |
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Contraction
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.RingTheory.Finiteness.Prod
import Mathlib.RingTheory.TensorProduct.Finite
import Mathlib.RingTheory.TensorProduct.Free
/-!
# Trace of a linear map
This file defines the trace of a linear map.
See also `LinearAlgebra/Matrix/Trace.lean` for the trace of a matrix.
## Tags
linear_map, trace, diagonal
-/
noncomputable section
universe u v w
namespace LinearMap
open scoped Matrix
open Module TensorProduct
section
variable (R : Type u) [CommSemiring R] {M : Type v} [AddCommMonoid M] [Module R M]
variable {ι : Type w} [DecidableEq ι] [Fintype ι]
variable {κ : Type*} [DecidableEq κ] [Fintype κ]
variable (b : Basis ι R M) (c : Basis κ R M)
/-- The trace of an endomorphism given a basis. -/
def traceAux : (M →ₗ[R] M) →ₗ[R] R :=
Matrix.traceLinearMap ι R R ∘ₗ ↑(LinearMap.toMatrix b b)
-- Can't be `simp` because it would cause a loop.
theorem traceAux_def (b : Basis ι R M) (f : M →ₗ[R] M) :
traceAux R b f = Matrix.trace (LinearMap.toMatrix b b f) :=
rfl
theorem traceAux_eq : traceAux R b = traceAux R c :=
LinearMap.ext fun f =>
calc
Matrix.trace (LinearMap.toMatrix b b f) =
Matrix.trace (LinearMap.toMatrix b b ((LinearMap.id.comp f).comp LinearMap.id)) := by
rw [LinearMap.id_comp, LinearMap.comp_id]
_ = Matrix.trace (LinearMap.toMatrix c b LinearMap.id * LinearMap.toMatrix c c f *
LinearMap.toMatrix b c LinearMap.id) := by
rw [LinearMap.toMatrix_comp _ c, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f * LinearMap.toMatrix b c LinearMap.id *
LinearMap.toMatrix c b LinearMap.id) := by
rw [Matrix.mul_assoc, Matrix.trace_mul_comm]
_ = Matrix.trace (LinearMap.toMatrix c c ((f.comp LinearMap.id).comp LinearMap.id)) := by
rw [LinearMap.toMatrix_comp _ b, LinearMap.toMatrix_comp _ c]
_ = Matrix.trace (LinearMap.toMatrix c c f) := by rw [LinearMap.comp_id, LinearMap.comp_id]
variable (M) in
open Classical in
/-- Trace of an endomorphism independent of basis. -/
def trace : (M →ₗ[R] M) →ₗ[R] R :=
if H : ∃ s : Finset M, Nonempty (Basis s R M) then traceAux R H.choose_spec.some else 0
open Classical in
/-- Auxiliary lemma for `trace_eq_matrix_trace`. -/
theorem trace_eq_matrix_trace_of_finset {s : Finset M} (b : Basis s R M) (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s R M) := ⟨s, ⟨b⟩⟩
rw [trace, dif_pos this, ← traceAux_def]
congr 1
apply traceAux_eq
theorem trace_eq_matrix_trace (f : M →ₗ[R] M) :
trace R M f = Matrix.trace (LinearMap.toMatrix b b f) := by
classical
rw [trace_eq_matrix_trace_of_finset R b.reindexFinsetRange, ← traceAux_def, ← traceAux_def,
traceAux_eq R b b.reindexFinsetRange]
theorem trace_mul_comm (f g : M →ₗ[R] M) : trace R M (f * g) = trace R M (g * f) := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s R M)
· let ⟨s, ⟨b⟩⟩ := H
simp_rw [trace_eq_matrix_trace R b, LinearMap.toMatrix_mul]
apply Matrix.trace_mul_comm
· rw [trace, dif_neg H, LinearMap.zero_apply, LinearMap.zero_apply]
lemma trace_mul_cycle (f g h : M →ₗ[R] M) :
trace R M (f * g * h) = trace R M (h * f * g) := by
rw [LinearMap.trace_mul_comm, ← mul_assoc]
lemma trace_mul_cycle' (f g h : M →ₗ[R] M) :
trace R M (f * (g * h)) = trace R M (h * (f * g)) := by
rw [← mul_assoc, LinearMap.trace_mul_comm]
/-- The trace of an endomorphism is invariant under conjugation -/
@[simp]
theorem trace_conj (g : M →ₗ[R] M) (f : (M →ₗ[R] M)ˣ) :
trace R M (↑f * g * ↑f⁻¹) = trace R M g := by
rw [trace_mul_comm]
simp
@[simp]
lemma trace_lie {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] (f g : Module.End R M) :
trace R M ⁅f, g⁆ = 0 := by
rw [Ring.lie_def, map_sub, trace_mul_comm]
exact sub_self _
end
section
variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]
variable (N P : Type*) [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P]
variable {ι : Type*}
/-- The trace of a linear map correspond to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M` -/
theorem trace_eq_contract_of_basis [Finite ι] (b : Basis ι R M) :
LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M := by
classical
cases nonempty_fintype ι
apply Basis.ext (Basis.tensorProduct (Basis.dualBasis b) b)
rintro ⟨i, j⟩
simp only [Function.comp_apply, Basis.tensorProduct_apply, Basis.coe_dualBasis, coe_comp]
rw [trace_eq_matrix_trace R b, toMatrix_dualTensorHom]
by_cases hij : i = j
· rw [hij]
simp
rw [Matrix.StdBasisMatrix.trace_zero j i (1 : R) hij]
simp [Finsupp.single_eq_pi_single, hij]
/-- The trace of a linear map corresponds to the contraction pairing under the isomorphism
`End(M) ≃ M* ⊗ M`. -/
theorem trace_eq_contract_of_basis' [Fintype ι] [DecidableEq ι] (b : Basis ι R M) :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquivOfBasis b).symm.toLinearMap := by
simp [LinearEquiv.eq_comp_toLinearMap_symm, trace_eq_contract_of_basis b]
section
variable (R M)
variable [Module.Free R M] [Module.Finite R M] [Module.Free R N] [Module.Finite R N]
/-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`. -/
@[simp]
theorem trace_eq_contract : LinearMap.trace R M ∘ₗ dualTensorHom R M M = contractLeft R M :=
trace_eq_contract_of_basis (Module.Free.chooseBasis R M)
@[simp]
theorem trace_eq_contract_apply (x : Module.Dual R M ⊗[R] M) :
(LinearMap.trace R M) ((dualTensorHom R M M) x) = contractLeft R M x := by
rw [← comp_apply, trace_eq_contract]
/-- When `M` is finite free, the trace of a linear map corresponds to the contraction pairing under
the isomorphism `End(M) ≃ M* ⊗ M`. -/
theorem trace_eq_contract' :
LinearMap.trace R M = contractLeft R M ∘ₗ (dualTensorHomEquiv R M M).symm.toLinearMap :=
trace_eq_contract_of_basis' (Module.Free.chooseBasis R M)
/-- The trace of the identity endomorphism is the dimension of the free module. -/
@[simp]
theorem trace_one : trace R M 1 = (finrank R M : R) := by
cases subsingleton_or_nontrivial R
· simp [eq_iff_true_of_subsingleton]
have b := Module.Free.chooseBasis R M
rw [trace_eq_matrix_trace R b, toMatrix_one, finrank_eq_card_chooseBasisIndex]
simp
/-- The trace of the identity endomorphism is the dimension of the free module. -/
@[simp]
theorem trace_id : trace R M id = (finrank R M : R) := by rw [← Module.End.one_eq_id, trace_one]
@[simp]
theorem trace_transpose : trace R (Module.Dual R M) ∘ₗ Module.Dual.transpose = trace R M := by
let e := dualTensorHomEquiv R M M
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f m; simp [e]
theorem trace_prodMap :
trace R (M × N) ∘ₗ prodMapLinear R M N M N R =
(coprod id id : R × R →ₗ[R] R) ∘ₗ prodMap (trace R M) (trace R N) := by
let e := (dualTensorHomEquiv R M M).prodCongr (dualTensorHomEquiv R N N)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext
· simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr,
dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp,
curry_apply, coe_comp, coe_restrictScalars, coe_inl, Function.comp_apply, prodMap_apply,
map_zero, prodMapLinear_apply, dualTensorHom_prodMap_zero, trace_eq_contract_apply,
contractLeft_apply, coe_fst, coprod_apply, id_coe, id_eq, add_zero, e]
· simp only [dualTensorHomEquiv, LinearEquiv.coe_prodCongr,
dualTensorHomEquivOfBasis_toLinearMap, AlgebraTensorModule.curry_apply, restrictScalars_comp,
curry_apply, coe_comp, coe_restrictScalars, coe_inr, Function.comp_apply, prodMap_apply,
map_zero, prodMapLinear_apply, zero_prodMap_dualTensorHom, trace_eq_contract_apply,
contractLeft_apply, coe_snd, coprod_apply, id_coe, id_eq, zero_add, e]
variable {R M N P}
theorem trace_prodMap' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M × N) (prodMap f g) = trace R M f + trace R N g := by
have h := LinearMap.ext_iff.1 (trace_prodMap R M N) (f, g)
simp only [coe_comp, Function.comp_apply, prodMap_apply, coprod_apply, id_coe, id,
prodMapLinear_apply] at h
exact h
variable (R M N P)
open TensorProduct Function
theorem trace_tensorProduct : compr₂ (mapBilinear R M N M N) (trace R (M ⊗ N)) =
compl₁₂ (lsmul R R : R →ₗ[R] R →ₗ[R] R) (trace R M) (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R M M) from (dualTensorHomEquiv R M M).surjective)
(show Surjective (dualTensorHom R N N) from (dualTensorHomEquiv R N N).surjective)).1
ext f m g n
simp only [AlgebraTensorModule.curry_apply, toFun_eq_coe, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, mapBilinear_apply,
trace_eq_contract_apply, contractLeft_apply, lsmul_apply, Algebra.id.smul_eq_mul,
map_dualTensorHom, dualDistrib_apply]
theorem trace_comp_comm :
compr₂ (llcomp R M N M) (trace R M) = compr₂ (llcomp R N M N).flip (trace R N) := by
apply
(compl₁₂_inj (show Surjective (dualTensorHom R N M) from (dualTensorHomEquiv R N M).surjective)
(show Surjective (dualTensorHom R M N) from (dualTensorHomEquiv R M N).surjective)).1
ext g m f n
simp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply,
coe_restrictScalars, compl₁₂_apply, compr₂_apply, flip_apply, llcomp_apply',
comp_dualTensorHom, LinearMapClass.map_smul, trace_eq_contract_apply,
contractLeft_apply, smul_eq_mul, mul_comm]
variable {R M N P}
@[simp]
theorem trace_transpose' (f : M →ₗ[R] M) :
trace R _ (Module.Dual.transpose (R := R) f) = trace R M f := by
rw [← comp_apply, trace_transpose]
theorem trace_tensorProduct' (f : M →ₗ[R] M) (g : N →ₗ[R] N) :
trace R (M ⊗ N) (map f g) = trace R M f * trace R N g := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_tensorProduct R M N) f) g
simp only [compr₂_apply, mapBilinear_apply, compl₁₂_apply, lsmul_apply,
Algebra.id.smul_eq_mul] at h
exact h
theorem trace_comp_comm' (f : M →ₗ[R] N) (g : N →ₗ[R] M) :
trace R M (g ∘ₗ f) = trace R N (f ∘ₗ g) := by
have h := LinearMap.ext_iff.1 (LinearMap.ext_iff.1 (trace_comp_comm R M N) g) f
simp only [llcomp_apply', compr₂_apply, flip_apply] at h
exact h
end
variable {N P}
variable [Module.Free R N] [Module.Finite R N] [Module.Free R P] [Module.Finite R P] in
lemma trace_comp_cycle (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) :
trace R P (g ∘ₗ f ∘ₗ h) = trace R N (f ∘ₗ h ∘ₗ g) := by
rw [trace_comp_comm', comp_assoc]
variable [Module.Free R M] [Module.Finite R M] [Module.Free R P] [Module.Finite R P] in
lemma trace_comp_cycle' (f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : P →ₗ[R] M) :
trace R P ((g ∘ₗ f) ∘ₗ h) = trace R M ((h ∘ₗ g) ∘ₗ f) := by
rw [trace_comp_comm', ← comp_assoc]
@[simp]
theorem trace_conj' (f : M →ₗ[R] M) (e : M ≃ₗ[R] N) : trace R N (e.conj f) = trace R M f := by
classical
by_cases hM : ∃ s : Finset M, Nonempty (Basis s R M)
· obtain ⟨s, ⟨b⟩⟩ := hM
haveI := Module.Finite.of_basis b
haveI := (Module.free_def R M).mpr ⟨_, ⟨b⟩⟩
haveI := Module.Finite.of_basis (b.map e)
haveI := (Module.free_def R N).mpr ⟨_, ⟨(b.map e).reindex (e.toEquiv.image _)⟩⟩
rw [e.conj_apply, trace_comp_comm', ← comp_assoc, LinearEquiv.comp_coe,
LinearEquiv.self_trans_symm, LinearEquiv.refl_toLinearMap, id_comp]
· rw [trace, trace, dif_neg hM, dif_neg ?_, zero_apply, zero_apply]
rintro ⟨s, ⟨b⟩⟩
exact hM ⟨s.image e.symm, ⟨(b.map e.symm).reindex
((e.symm.toEquiv.image s).trans (Equiv.setCongr Finset.coe_image.symm))⟩⟩
theorem IsProj.trace {p : Submodule R M} {f : M →ₗ[R] M} (h : IsProj p f) [Module.Free R p]
[Module.Finite R p] [Module.Free R (ker f)] [Module.Finite R (ker f)] :
trace R M f = (finrank R p : R) := by
rw [h.eq_conj_prodMap, trace_conj', trace_prodMap', trace_id, map_zero, add_zero]
lemma isNilpotent_trace_of_isNilpotent {f : M →ₗ[R] M} (hf : IsNilpotent f) :
IsNilpotent (trace R M f) := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s R M)
swap
· rw [LinearMap.trace, dif_neg H]
exact IsNilpotent.zero
obtain ⟨s, ⟨b⟩⟩ := H
classical
rw [trace_eq_matrix_trace R b]
apply Matrix.isNilpotent_trace_of_isNilpotent
simpa
lemma trace_comp_eq_mul_of_commute_of_isNilpotent [IsReduced R] {f g : Module.End R M}
(μ : R) (h_comm : Commute f g) (hg : IsNilpotent (g - algebraMap R _ μ)) :
trace R M (f ∘ₗ g) = μ * trace R M f := by
set n := g - algebraMap R _ μ
replace hg : trace R M (f ∘ₗ n) = 0 := by
rw [← isNilpotent_iff_eq_zero, ← Module.End.mul_eq_comp]
refine isNilpotent_trace_of_isNilpotent (Commute.isNilpotent_mul_right ?_ hg)
exact h_comm.sub_right (Algebra.commute_algebraMap_right μ f)
have hμ : g = algebraMap R _ μ + n := eq_add_of_sub_eq' rfl
have : f ∘ₗ algebraMap R _ μ = μ • f := by ext; simp -- TODO Surely exists?
rw [hμ, comp_add, map_add, hg, add_zero, this, LinearMap.map_smul, smul_eq_mul]
-- This result requires `Mathlib.RingTheory.TensorProduct.Free`. Maybe it should move elsewhere?
@[simp]
lemma trace_baseChange [Module.Free R M] [Module.Finite R M]
(f : M →ₗ[R] M) (A : Type*) [CommRing A] [Algebra R A] :
trace A _ (f.baseChange A) = algebraMap R A (trace R _ f) := by
let b := Module.Free.chooseBasis R M
let b' := Algebra.TensorProduct.basis A b
change _ = (algebraMap R A : R →+ A) _
simp [b', trace_eq_matrix_trace R b, trace_eq_matrix_trace A b', AddMonoidHom.map_trace]
end
end LinearMap
| Mathlib/LinearAlgebra/Trace.lean | 335 | 342 | |
/-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Algebra.Algebra.Spectrum.Basic
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.Nilpotent.Defs
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.Tactic.Peel
/-!
# Eigenvectors and eigenvalues
This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized
counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties
without choosing a basis and without using matrices.
An eigenspace of a linear map `f` for a scalar `μ` is the kernel of the map `(f - μ • id)`. The
nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = μ • x`. If
there are eigenvectors for a scalar `μ`, the scalar `μ` is called an eigenvalue.
There is no consensus in the literature whether `0` is an eigenvector. Our definition of
`HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we
write `x ∈ f.eigenspace μ`.
A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `μ` is the kernel
of the map `(f - μ • id) ^ k`. The nonzero elements of a generalized eigenspace are generalized
eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `μ`,
the scalar `μ` is called a generalized eigenvalue.
The fact that the eigenvalues are the roots of the minimal polynomial is proved in
`LinearAlgebra.Eigenspace.Minpoly`.
The existence of eigenvalues over an algebraically closed field
(and the fact that the generalized eigenspaces then span) is deferred to
`LinearAlgebra.Eigenspace.IsAlgClosed`.
## References
* [Sheldon Axler, *Linear Algebra Done Right*][axler2015]
* https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
## Tags
eigenspace, eigenvector, eigenvalue, eigen
-/
universe u v w
namespace Module
namespace End
open Module Set
variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K]
[AddCommGroup V] [Module K V]
/-- The submodule `genEigenspace f μ k` for a linear map `f`, a scalar `μ`,
and a number `k : ℕ∞` is the kernel of `(f - μ • id) ^ k` if `k` is a natural number
(see Def 8.10 of [axler2015]), or the union of all these kernels if `k = ∞`.
A generalized eigenspace for some exponent `k` is contained in
the generalized eigenspace for exponents larger than `k`. -/
def genEigenspace (f : End R M) (μ : R) : ℕ∞ →o Submodule R M where
toFun k := ⨆ l : ℕ, ⨆ _ : l ≤ k, LinearMap.ker ((f - μ • 1) ^ l)
monotone' _ _ hkl := biSup_mono fun _ hi ↦ hi.trans hkl
lemma mem_genEigenspace {f : End R M} {μ : R} {k : ℕ∞} {x : M} :
x ∈ f.genEigenspace μ k ↔ ∃ l : ℕ, l ≤ k ∧ x ∈ LinearMap.ker ((f - μ • 1) ^ l) := by
have : Nonempty {l : ℕ // l ≤ k} := ⟨⟨0, zero_le _⟩⟩
have : Directed (ι := { i : ℕ // i ≤ k }) (· ≤ ·) fun i ↦ LinearMap.ker ((f - μ • 1) ^ (i : ℕ)) :=
Monotone.directed_le fun m n h ↦ by simpa using (f - μ • 1).iterateKer.monotone h
simp_rw [genEigenspace, OrderHom.coe_mk, LinearMap.mem_ker, iSup_subtype',
Submodule.mem_iSup_of_directed _ this, LinearMap.mem_ker, Subtype.exists, exists_prop]
lemma genEigenspace_directed {f : End R M} {μ : R} {k : ℕ∞} :
Directed (· ≤ ·) (fun l : {l : ℕ // l ≤ k} ↦ f.genEigenspace μ l) := by
have aux : Monotone ((↑) : {l : ℕ // l ≤ k} → ℕ∞) := fun x y h ↦ by simpa using h
exact ((genEigenspace f μ).monotone.comp aux).directed_le
lemma mem_genEigenspace_nat {f : End R M} {μ : R} {k : ℕ} {x : M} :
x ∈ f.genEigenspace μ k ↔ x ∈ LinearMap.ker ((f - μ • 1) ^ k) := by
rw [mem_genEigenspace]
constructor
· rintro ⟨l, hl, hx⟩
simp only [Nat.cast_le] at hl
exact (f - μ • 1).iterateKer.monotone hl hx
· intro hx
exact ⟨k, le_rfl, hx⟩
lemma mem_genEigenspace_top {f : End R M} {μ : R} {x : M} :
x ∈ f.genEigenspace μ ⊤ ↔ ∃ k : ℕ, x ∈ LinearMap.ker ((f - μ • 1) ^ k) := by
simp [mem_genEigenspace]
lemma genEigenspace_nat {f : End R M} {μ : R} {k : ℕ} :
f.genEigenspace μ k = LinearMap.ker ((f - μ • 1) ^ k) := by
ext; simp [mem_genEigenspace_nat]
lemma genEigenspace_eq_iSup_genEigenspace_nat (f : End R M) (μ : R) (k : ℕ∞) :
f.genEigenspace μ k = ⨆ l : {l : ℕ // l ≤ k}, f.genEigenspace μ l := by
simp_rw [genEigenspace_nat, genEigenspace, OrderHom.coe_mk, iSup_subtype]
lemma genEigenspace_top (f : End R M) (μ : R) :
f.genEigenspace μ ⊤ = ⨆ k : ℕ, f.genEigenspace μ k := by
rw [genEigenspace_eq_iSup_genEigenspace_nat, iSup_subtype]
simp only [le_top, iSup_pos, OrderHom.coe_mk]
lemma genEigenspace_one {f : End R M} {μ : R} :
f.genEigenspace μ 1 = LinearMap.ker (f - μ • 1) := by
rw [← Nat.cast_one, genEigenspace_nat, pow_one]
@[simp]
lemma mem_genEigenspace_one {f : End R M} {μ : R} {x : M} :
x ∈ f.genEigenspace μ 1 ↔ f x = μ • x := by
rw [genEigenspace_one, LinearMap.mem_ker, LinearMap.sub_apply,
sub_eq_zero, LinearMap.smul_apply, Module.End.one_apply]
-- `simp` can prove this using `genEigenspace_zero`
lemma mem_genEigenspace_zero {f : End R M} {μ : R} {x : M} :
x ∈ f.genEigenspace μ 0 ↔ x = 0 := by
rw [← Nat.cast_zero, mem_genEigenspace_nat, pow_zero, LinearMap.mem_ker, Module.End.one_apply]
@[simp]
lemma genEigenspace_zero {f : End R M} {μ : R} :
f.genEigenspace μ 0 = ⊥ := by
ext; apply mem_genEigenspace_zero
@[simp]
lemma genEigenspace_zero_nat (f : End R M) (k : ℕ) :
f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by
ext; simp [mem_genEigenspace_nat]
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`,
and let `μ : R` and `k : ℕ∞` be given.
Then `x : M` satisfies `HasUnifEigenvector f μ k x` if
`x ∈ f.genEigenspace μ k` and `x ≠ 0`.
For `k = 1`, this means that `x` is an eigenvector of `f` with eigenvalue `μ`. -/
def HasUnifEigenvector (f : End R M) (μ : R) (k : ℕ∞) (x : M) : Prop :=
x ∈ f.genEigenspace μ k ∧ x ≠ 0
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`.
Then `μ : R` and `k : ℕ∞` satisfy `HasUnifEigenvalue f μ k` if
`f.genEigenspace μ k ≠ ⊥`.
For `k = 1`, this means that `μ` is an eigenvalue of `f`. -/
def HasUnifEigenvalue (f : End R M) (μ : R) (k : ℕ∞) : Prop :=
f.genEigenspace μ k ≠ ⊥
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`.
For `k : ℕ∞`, we define `UnifEigenvalues f k` to be the type of all
`μ : R` that satisfy `f.HasUnifEigenvalue μ k`.
For `k = 1` this is the type of all eigenvalues of `f`. -/
def UnifEigenvalues (f : End R M) (k : ℕ∞) : Type _ :=
{ μ : R // f.HasUnifEigenvalue μ k }
/-- The underlying value of a bundled eigenvalue. -/
@[coe]
def UnifEigenvalues.val (f : Module.End R M) (k : ℕ∞) : UnifEigenvalues f k → R := Subtype.val
instance UnifEigenvalues.instCoeOut {f : Module.End R M} (k : ℕ∞) :
CoeOut (UnifEigenvalues f k) R where
coe := UnifEigenvalues.val f k
instance UnivEigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) (k : ℕ∞) :
DecidableEq (UnifEigenvalues f k) :=
inferInstanceAs (DecidableEq (Subtype (fun x : R ↦ f.HasUnifEigenvalue x k)))
lemma HasUnifEigenvector.hasUnifEigenvalue {f : End R M} {μ : R} {k : ℕ∞} {x : M}
(h : f.HasUnifEigenvector μ k x) : f.HasUnifEigenvalue μ k := by
rw [HasUnifEigenvalue, Submodule.ne_bot_iff]
use x; exact h
lemma HasUnifEigenvector.apply_eq_smul {f : End R M} {μ : R} {x : M}
(hx : f.HasUnifEigenvector μ 1 x) : f x = μ • x :=
mem_genEigenspace_one.mp hx.1
lemma HasUnifEigenvector.pow_apply {f : End R M} {μ : R} {v : M} (hv : f.HasUnifEigenvector μ 1 v)
(n : ℕ) : (f ^ n) v = μ ^ n • v := by
induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' μ]
theorem HasUnifEigenvalue.exists_hasUnifEigenvector
{f : End R M} {μ : R} {k : ℕ∞} (hμ : f.HasUnifEigenvalue μ k) :
∃ v, f.HasUnifEigenvector μ k v :=
Submodule.exists_mem_ne_zero_of_ne_bot hμ
lemma HasUnifEigenvalue.pow {f : End R M} {μ : R} (h : f.HasUnifEigenvalue μ 1) (n : ℕ) :
(f ^ n).HasUnifEigenvalue (μ ^ n) 1 := by
rw [HasUnifEigenvalue, Submodule.ne_bot_iff]
obtain ⟨m : M, hm⟩ := h.exists_hasUnifEigenvector
exact ⟨m, by simpa [mem_genEigenspace_one] using hm.pow_apply n, hm.2⟩
/-- A nilpotent endomorphism has nilpotent eigenvalues.
See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/
lemma HasUnifEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M}
(hfn : IsNilpotent f) {μ : R} (hf : f.HasUnifEigenvalue μ 1) :
IsNilpotent μ := by
obtain ⟨m : M, hm⟩ := hf.exists_hasUnifEigenvector
obtain ⟨n : ℕ, hn : f ^ n = 0⟩ := hfn
exact ⟨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply n⟩
lemma HasUnifEigenvalue.mem_spectrum {f : End R M} {μ : R} (hμ : HasUnifEigenvalue f μ 1) :
μ ∈ spectrum R f := by
refine spectrum.mem_iff.mpr fun h_unit ↦ ?_
set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit
rcases hμ.exists_hasUnifEigenvector with ⟨v, hv⟩
refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : μ • v - f v = 0))
rw [hv.apply_eq_smul, sub_self]
lemma hasUnifEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {μ : K} :
f.HasUnifEigenvalue μ 1 ↔ μ ∈ spectrum K f := by
rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot,
HasUnifEigenvalue, genEigenspace_one, ne_eq, not_iff_not]
simp [Submodule.ext_iff, LinearMap.mem_ker]
alias ⟨_, HasUnifEigenvalue.of_mem_spectrum⟩ := hasUnifEigenvalue_iff_mem_spectrum
lemma genEigenspace_div (f : End K V) (a b : K) (hb : b ≠ 0) :
genEigenspace f (a / b) 1 = LinearMap.ker (b • f - a • 1) :=
calc
genEigenspace f (a / b) 1 = genEigenspace f (b⁻¹ * a) 1 := by rw [div_eq_mul_inv, mul_comm]
_ = LinearMap.ker (f - (b⁻¹ * a) • 1) := by rw [genEigenspace_one]
_ = LinearMap.ker (f - b⁻¹ • a • 1) := by rw [smul_smul]
_ = LinearMap.ker (b • (f - b⁻¹ • a • 1)) := by rw [LinearMap.ker_smul _ b hb]
_ = LinearMap.ker (b • f - a • 1) := by rw [smul_sub, smul_inv_smul₀ hb]
/-- The generalized eigenrange for a linear map `f`, a scalar `μ`, and an exponent `k ∈ ℕ∞`
is the range of `(f - μ • id) ^ k` if `k` is a natural number,
or the infimum of these ranges if `k = ∞`. -/
def genEigenrange (f : End R M) (μ : R) (k : ℕ∞) : Submodule R M :=
⨅ l : ℕ, ⨅ (_ : l ≤ k), LinearMap.range ((f - μ • 1) ^ l)
lemma genEigenrange_nat {f : End R M} {μ : R} {k : ℕ} :
f.genEigenrange μ k = LinearMap.range ((f - μ • 1) ^ k) := by
ext x
simp only [genEigenrange, Nat.cast_le, Submodule.mem_iInf, LinearMap.mem_range]
constructor
· intro h
exact h _ le_rfl
· rintro ⟨x, rfl⟩ i hi
have : k = i + (k - i) := by omega
rw [this, pow_add]
exact ⟨_, rfl⟩
/-- The exponent of a generalized eigenvalue is never 0. -/
lemma HasUnifEigenvalue.exp_ne_zero {f : End R M} {μ : R} {k : ℕ}
(h : f.HasUnifEigenvalue μ k) : k ≠ 0 := by
rintro rfl
simp [HasUnifEigenvalue, Nat.cast_zero, genEigenspace_zero] at h
/-- If there exists a natural number `k` such that the kernel of `(f - μ • id) ^ k` is the
maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not
meaningful. -/
noncomputable def maxUnifEigenspaceIndex (f : End R M) (μ : R) :=
monotonicSequenceLimitIndex <| (f.genEigenspace μ).comp <| WithTop.coeOrderHom.toOrderHom
/-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel
`(f - μ • id) ^ k` for some `k`. -/
lemma genEigenspace_top_eq_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (μ : R) :
genEigenspace f μ ⊤ = f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := by
have := WellFoundedGT.iSup_eq_monotonicSequenceLimit <|
(f.genEigenspace μ).comp <| WithTop.coeOrderHom.toOrderHom
convert this using 1
simp only [genEigenspace, OrderHom.coe_mk, le_top, iSup_pos, OrderHom.comp_coe,
Function.comp_def]
rw [iSup_prod', iSup_subtype', ← sSup_range, ← sSup_range]
congr
aesop
lemma genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M)
(μ : R) (k : ℕ∞) :
f.genEigenspace μ k ≤ f.genEigenspace μ (maxUnifEigenspaceIndex f μ) := by
rw [← genEigenspace_top_eq_maxUnifEigenspaceIndex]
exact (f.genEigenspace μ).monotone le_top
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_maxUnifEigenspaceIndex_of_le [IsNoetherian R M]
(f : End R M) (μ : R) {k : ℕ} (hk : maxUnifEigenspaceIndex f μ ≤ k) :
f.genEigenspace μ k = f.genEigenspace μ (maxUnifEigenspaceIndex f μ) :=
le_antisymm
(genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex _ _ _)
((f.genEigenspace μ).monotone <| by simpa using hk)
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for exponents larger than `k`. -/
lemma HasUnifEigenvalue.le {f : End R M} {μ : R} {k m : ℕ∞}
(hm : k ≤ m) (hk : f.HasUnifEigenvalue μ k) :
f.HasUnifEigenvalue μ m := by
unfold HasUnifEigenvalue at *
contrapose! hk
rw [← le_bot_iff, ← hk]
exact (f.genEigenspace _).monotone hm
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for positive exponents. -/
lemma HasUnifEigenvalue.lt {f : End R M} {μ : R} {k m : ℕ∞}
(hm : 0 < m) (hk : f.HasUnifEigenvalue μ k) :
f.HasUnifEigenvalue μ m := by
apply HasUnifEigenvalue.le (k := 1) (Order.one_le_iff_pos.mpr hm)
intro contra; apply hk
rw [genEigenspace_one, LinearMap.ker_eq_bot] at contra
rw [eq_bot_iff]
intro x hx
rw [mem_genEigenspace] at hx
rcases hx with ⟨l, -, hx⟩
rwa [LinearMap.ker_eq_bot.mpr] at hx
rw [Module.End.coe_pow (f - μ • 1) l]
exact Function.Injective.iterate contra l
/-- Generalized eigenvalues are actually just eigenvalues. -/
@[simp]
lemma hasUnifEigenvalue_iff_hasUnifEigenvalue_one {f : End R M} {μ : R} {k : ℕ∞} (hk : 0 < k) :
f.HasUnifEigenvalue μ k ↔ f.HasUnifEigenvalue μ 1 :=
⟨HasUnifEigenvalue.lt zero_lt_one, HasUnifEigenvalue.lt hk⟩
lemma maxUnifEigenspaceIndex_le_finrank [FiniteDimensional K V] (f : End K V) (μ : K) :
maxUnifEigenspaceIndex f μ ≤ finrank K V := by
apply Nat.sInf_le
intro n hn
apply le_antisymm
· exact (f.genEigenspace μ).monotone <| WithTop.coeOrderHom.monotone hn
· show (f.genEigenspace μ) n ≤ (f.genEigenspace μ) (finrank K V)
rw [genEigenspace_nat, genEigenspace_nat]
apply ker_pow_le_ker_pow_finrank
/-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`.
(Lemma 8.11 of [axler2015]) -/
lemma genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V)
(μ : K) (k : ℕ∞) : f.genEigenspace μ k ≤ f.genEigenspace μ (finrank K V) := by
calc f.genEigenspace μ k
≤ f.genEigenspace μ ⊤ := (f.genEigenspace _).monotone le_top
_ ≤ f.genEigenspace μ (finrank K V) := by
rw [genEigenspace_top_eq_maxUnifEigenspaceIndex]
exact (f.genEigenspace _).monotone <| by simpa using maxUnifEigenspaceIndex_le_finrank f μ
| /-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V]
(f : End K V) (μ : K) {k : ℕ} (hk : finrank K V ≤ k) :
f.genEigenspace μ k = f.genEigenspace μ (finrank K V) :=
le_antisymm
(genEigenspace_le_genEigenspace_finrank _ _ _)
((f.genEigenspace μ).monotone <| by simpa using hk)
lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (μ : R) (k : ℕ∞) :
MapsTo g (f.genEigenspace μ k) (f.genEigenspace μ k) := by
intro x hx
simp only [SetLike.mem_coe, mem_genEigenspace, LinearMap.mem_ker] at hx ⊢
rcases hx with ⟨l, hl, hx⟩
replace h : Commute ((f - μ • (1 : End R M)) ^ l) g :=
(h.sub_left <| Algebra.commute_algebraMap_left μ g).pow_left l
use l, hl
rw [← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp,
LinearMap.comp_apply, hx, map_zero]
/-- The restriction of `f - μ • 1` to the `k`-fold generalized `μ`-eigenspace is nilpotent. -/
lemma isNilpotent_restrict_genEigenspace_nat (f : End R M) (μ : R) (k : ℕ)
(h : MapsTo (f - μ • (1 : End R M))
(f.genEigenspace μ k) (f.genEigenspace μ k) :=
| Mathlib/LinearAlgebra/Eigenspace/Basic.lean | 343 | 365 |
/-
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
-/
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Algebra.Ring.Int.Units
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# Absolute values in linear ordered rings.
-/
variable {α : Type*}
section LinearOrderedAddCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α]
@[to_additive] lemma mabs_zpow (n : ℤ) (a : α) : |a ^ n|ₘ = |a|ₘ ^ |n| := by
obtain n0 | n0 := le_total 0 n
· obtain ⟨n, rfl⟩ := Int.eq_ofNat_of_zero_le n0
simp only [mabs_pow, zpow_natCast, Nat.abs_cast]
· obtain ⟨m, h⟩ := Int.eq_ofNat_of_zero_le (neg_nonneg.2 n0)
rw [← mabs_inv, ← zpow_neg, ← abs_neg, h, zpow_natCast, Nat.abs_cast, zpow_natCast]
exact mabs_pow m _
end LinearOrderedAddCommGroup
lemma odd_abs [LinearOrder α] [Ring α] {a : α} : Odd (abs a) ↔ Odd a := by
rcases abs_choice a with h | h <;> simp only [h, odd_neg]
section LinearOrderedRing
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] {n : ℕ} {a b : α}
@[simp] lemma abs_one : |(1 : α)| = 1 := abs_of_pos zero_lt_one
lemma abs_two : |(2 : α)| = 2 := abs_of_pos zero_lt_two
lemma abs_mul (a b : α) : |a * b| = |a| * |b| := by
rw [abs_eq (mul_nonneg (abs_nonneg a) (abs_nonneg b))]
rcases le_total a 0 with ha | ha <;> rcases le_total b 0 with hb | hb <;>
simp only [abs_of_nonpos, abs_of_nonneg, true_or, or_true, eq_self_iff_true, neg_mul,
mul_neg, neg_neg, *]
/-- `abs` as a `MonoidWithZeroHom`. -/
def absHom : α →*₀ α where
toFun := abs
map_zero' := abs_zero
map_one' := abs_one
map_mul' := abs_mul
@[simp]
lemma abs_pow (a : α) (n : ℕ) : |a ^ n| = |a| ^ n := (absHom.toMonoidHom : α →* α).map_pow _ _
lemma pow_abs (a : α) (n : ℕ) : |a| ^ n = |a ^ n| := (abs_pow a n).symm
lemma Even.pow_abs (hn : Even n) (a : α) : |a| ^ n = a ^ n := by
rw [← abs_pow, abs_eq_self]; exact hn.pow_nonneg _
lemma abs_neg_one_pow (n : ℕ) : |(-1 : α) ^ n| = 1 := by rw [← pow_abs, abs_neg, abs_one, one_pow]
lemma abs_pow_eq_one (a : α) (h : n ≠ 0) : |a ^ n| = 1 ↔ |a| = 1 := by
convert pow_left_inj₀ (abs_nonneg a) zero_le_one h
exacts [(pow_abs _ _).symm, (one_pow _).symm]
omit [IsStrictOrderedRing α] in
@[simp] lemma abs_mul_abs_self (a : α) : |a| * |a| = a * a :=
abs_by_cases (fun x => x * x = a * a) rfl (neg_mul_neg a a)
@[simp]
lemma abs_mul_self (a : α) : |a * a| = a * a := by rw [abs_mul, abs_mul_abs_self]
lemma abs_eq_iff_mul_self_eq : |a| = |b| ↔ a * a = b * b := by
rw [← abs_mul_abs_self, ← abs_mul_abs_self b]
exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm
lemma abs_lt_iff_mul_self_lt : |a| < |b| ↔ a * a < b * b := by
rw [← abs_mul_abs_self, ← abs_mul_abs_self b]
exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)
lemma abs_le_iff_mul_self_le : |a| ≤ |b| ↔ a * a ≤ b * b := by
rw [← abs_mul_abs_self, ← abs_mul_abs_self b]
exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)
lemma abs_le_one_iff_mul_self_le_one : |a| ≤ 1 ↔ a * a ≤ 1 := by
simpa only [abs_one, one_mul] using abs_le_iff_mul_self_le (a := a) (b := 1)
omit [IsStrictOrderedRing α] in
@[simp] lemma sq_abs (a : α) : |a| ^ 2 = a ^ 2 := by simpa only [sq] using abs_mul_abs_self a
lemma abs_sq (x : α) : |x ^ 2| = x ^ 2 := by simpa only [sq] using abs_mul_self x
lemma sq_lt_sq : a ^ 2 < b ^ 2 ↔ |a| < |b| := by
simpa only [sq_abs] using sq_lt_sq₀ (abs_nonneg a) (abs_nonneg b)
lemma sq_lt_sq' (h1 : -b < a) (h2 : a < b) : a ^ 2 < b ^ 2 :=
sq_lt_sq.2 (lt_of_lt_of_le (abs_lt.2 ⟨h1, h2⟩) (le_abs_self _))
lemma sq_le_sq : a ^ 2 ≤ b ^ 2 ↔ |a| ≤ |b| := by
simpa only [sq_abs] using sq_le_sq₀ (abs_nonneg a) (abs_nonneg b)
lemma sq_le_sq' (h1 : -b ≤ a) (h2 : a ≤ b) : a ^ 2 ≤ b ^ 2 :=
sq_le_sq.2 (le_trans (abs_le.mpr ⟨h1, h2⟩) (le_abs_self _))
| lemma abs_lt_of_sq_lt_sq (h : a ^ 2 < b ^ 2) (hb : 0 ≤ b) : |a| < b := by
| Mathlib/Algebra/Order/Ring/Abs.lean | 110 | 110 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.FinMeasAdditive
/-!
# Extension of a linear function from indicators to L1
Given `T : Set α → E →L[ℝ] F` with `DominatedFinMeasAdditive μ T C`, we construct an extension
of `T` to integrable simple functions, which are finite sums of indicators of measurable sets
with finite measure, then to integrable functions, which are limits of integrable simple functions.
The main result is a continuous linear map `(α →₁[μ] E) →L[ℝ] F`.
This extension process is used to define the Bochner integral
in the `Mathlib.MeasureTheory.Integral.Bochner.Basic` file
and the conditional expectation of an integrable function
in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`.
## Main definitions
- `setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F`: the extension of `T`
from indicators to L1.
- `setToFun μ T (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F`: a version of the
extension which applies to functions (with value 0 if the function is not integrable).
## Properties
For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on
all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on
measurable sets with finite measure, like `∀ s, MeasurableSet s → μ s < ∞ → T s = T' s`.
The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details.
Linearity:
- `setToFun_zero_left : setToFun μ 0 hT f = 0`
- `setToFun_add_left : setToFun μ (T + T') _ f = setToFun μ T hT f + setToFun μ T' hT' f`
- `setToFun_smul_left : setToFun μ (fun s ↦ c • (T s)) (hT.smul c) f = c • setToFun μ T hT f`
- `setToFun_zero : setToFun μ T hT (0 : α → E) = 0`
- `setToFun_neg : setToFun μ T hT (-f) = - setToFun μ T hT f`
If `f` and `g` are integrable:
- `setToFun_add : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g`
- `setToFun_sub : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g`
If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`:
- `setToFun_smul : setToFun μ T hT (c • f) = c • setToFun μ T hT f`
Other:
- `setToFun_congr_ae (h : f =ᵐ[μ] g) : setToFun μ T hT f = setToFun μ T hT g`
- `setToFun_measure_zero (h : μ = 0) : setToFun μ T hT f = 0`
If the space is also an ordered additive group with an order closed topology and `T` is such that
`0 ≤ T s x` for `0 ≤ x`, we also prove order-related properties:
- `setToFun_mono_left (h : ∀ s x, T s x ≤ T' s x) : setToFun μ T hT f ≤ setToFun μ T' hT' f`
- `setToFun_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f`
- `setToFun_mono (hfg : f ≤ᵐ[μ] g) : setToFun μ T hT f ≤ setToFun μ T hT g`
-/
noncomputable section
open scoped Topology NNReal
open Set Filter TopologicalSpace ENNReal
namespace MeasureTheory
variable {α E F F' G 𝕜 : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F']
[NormedAddCommGroup G] {m : MeasurableSpace α} {μ : Measure α}
namespace L1
open AEEqFun Lp.simpleFunc Lp
namespace SimpleFunc
theorem norm_eq_sum_mul (f : α →₁ₛ[μ] G) :
‖f‖ = ∑ x ∈ (toSimpleFunc f).range, μ.real (toSimpleFunc f ⁻¹' {x}) * ‖x‖ := by
rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm]
have h_eq := SimpleFunc.map_apply (‖·‖ₑ) (toSimpleFunc f)
simp_rw [← h_eq, measureReal_def]
rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum]
· congr
ext1 x
rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_enorm,
ENNReal.toReal_ofReal (norm_nonneg _)]
· intro x _
by_cases hx0 : x = 0
· rw [hx0]; simp
· exact
ENNReal.mul_ne_top ENNReal.coe_ne_top
(SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne
section SetToL1S
variable [NormedField 𝕜] [NormedSpace 𝕜 E]
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
/-- Extend `Set α → (E →L[ℝ] F')` to `(α →₁ₛ[μ] E) → F'`. -/
def setToL1S (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) : F :=
(toSimpleFunc f).setToSimpleFunc T
theorem setToL1S_eq_setToSimpleFunc (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
setToL1S T f = (toSimpleFunc f).setToSimpleFunc T :=
rfl
@[simp]
theorem setToL1S_zero_left (f : α →₁ₛ[μ] E) : setToL1S (0 : Set α → E →L[ℝ] F) f = 0 :=
SimpleFunc.setToSimpleFunc_zero _
theorem setToL1S_zero_left' {T : Set α → E →L[ℝ] F}
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) : setToL1S T f = 0 :=
SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f)
theorem setToL1S_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
setToL1S T f = setToL1S T g :=
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h
theorem setToL1S_congr_left (T T' : Set α → E →L[ℝ] F)
(h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁ₛ[μ] E) :
setToL1S T f = setToL1S T' f :=
SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f)
/-- `setToL1S` does not change if we replace the measure `μ` by `μ'` with `μ ≪ μ'`. The statement
uses two functions `f` and `f'` because they have to belong to different types, but morally these
are the same function (we have `f =ᵐ[μ] f'`). -/
theorem setToL1S_congr_measure {μ' : Measure α} (T : Set α → E →L[ℝ] F)
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (hμ : μ ≪ μ')
(f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E) (h : (f : α → E) =ᵐ[μ] f') :
setToL1S T f = setToL1S T f' := by
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_
refine (toSimpleFunc_eq_toFun f).trans ?_
suffices (f' : α → E) =ᵐ[μ] simpleFunc.toSimpleFunc f' from h.trans this
have goal' : (f' : α → E) =ᵐ[μ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm
exact hμ.ae_eq goal'
theorem setToL1S_add_left (T T' : Set α → E →L[ℝ] F) (f : α →₁ₛ[μ] E) :
setToL1S (T + T') f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left T T'
theorem setToL1S_add_left' (T T' T'' : Set α → E →L[ℝ] F)
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
setToL1S T'' f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f)
theorem setToL1S_smul_left (T : Set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[μ] E) :
setToL1S (fun s => c • T s) f = c • setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left T c _
theorem setToL1S_smul_left' (T T' : Set α → E →L[ℝ] F) (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) :
setToL1S T' f = c • setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f)
theorem setToL1S_add (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) :
setToL1S T (f + g) = setToL1S T f + setToL1S T g := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f)
(SimpleFunc.integrable g)]
exact
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _)
(add_toSimpleFunc f g)
theorem setToL1S_neg {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f : α →₁ₛ[μ] E) : setToL1S T (-f) = -setToL1S T f := by
simp_rw [setToL1S]
have : simpleFunc.toSimpleFunc (-f) =ᵐ[μ] ⇑(-simpleFunc.toSimpleFunc f) :=
neg_toSimpleFunc f
rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this]
exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f)
theorem setToL1S_sub {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (f g : α →₁ₛ[μ] E) :
setToL1S T (f - g) = setToL1S T f - setToL1S T g := by
rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg]
theorem setToL1S_smul_real (T : Set α → E →L[ℝ] F)
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (c : ℝ)
(f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E]
[DistribSMul 𝕜 F] (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜)
(f : α →₁ₛ[μ] E) : setToL1S T (c • f) = c • setToL1S T f := by
simp_rw [setToL1S]
rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem norm_setToL1S_le (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * μ.real s) (f : α →₁ₛ[μ] E) :
‖setToL1S T f‖ ≤ C * ‖f‖ := by
rw [setToL1S, norm_eq_sum_mul f]
exact
SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _
(SimpleFunc.integrable f)
theorem setToL1S_indicatorConst {T : Set α → E →L[ℝ] F} {s : Set α}
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T)
(hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by
have h_empty : T ∅ = 0 := h_zero _ MeasurableSet.empty measure_empty
rw [setToL1S_eq_setToSimpleFunc]
refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x)
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact toSimpleFunc_indicatorConst hs hμs.ne x
theorem setToL1S_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F}
(h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0) (h_add : FinMeasAdditive μ T) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) = T univ x :=
setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x
section Order
variable {G'' G' : Type*}
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G']
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G'']
{T : Set α → G'' →L[ℝ] G'}
theorem setToL1S_mono_left {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≤ T' s x)
(f : α →₁ₛ[μ] E) : setToL1S T f ≤ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1S_mono_left' {T T' : Set α → E →L[ℝ] G''}
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1S T f ≤ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G''] in
theorem setToL1S_nonneg (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G''}
(hf : 0 ≤ f) : 0 ≤ setToL1S T f := by
simp_rw [setToL1S]
obtain ⟨f', hf', hff'⟩ := exists_simpleFunc_nonneg_ae_eq hf
replace hff' : simpleFunc.toSimpleFunc f =ᵐ[μ] f' :=
(Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff'
rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff']
exact
SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff')
theorem setToL1S_mono (h_zero : ∀ s, MeasurableSet s → μ s = 0 → T s = 0)
(h_add : FinMeasAdditive μ T)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G''}
(hfg : f ≤ g) : setToL1S T f ≤ setToL1S T g := by
rw [← sub_nonneg] at hfg ⊢
rw [← setToL1S_sub h_zero h_add]
exact setToL1S_nonneg h_zero h_add hT_nonneg hfg
end Order
variable [NormedSpace 𝕜 F]
variable (α E μ 𝕜)
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[𝕜] F`. -/
def setToL1SCLM' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁ₛ[μ] E) →L[𝕜] F :=
LinearMap.mkContinuous
⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩,
setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smul⟩
C fun f => norm_setToL1S_le T hT.2 f
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[μ] E) →L[ℝ] F`. -/
def setToL1SCLM {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) :
(α →₁ₛ[μ] E) →L[ℝ] F :=
LinearMap.mkContinuous
⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩,
setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩
C fun f => norm_setToL1S_le T hT.2 f
variable {α E μ 𝕜}
variable {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ}
@[simp]
theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C)
(f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = 0 :=
setToL1S_zero_left _
theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f = 0 :=
setToL1S_zero_left' h_zero f
theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f :=
setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f
theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s)
(f : α →₁ₛ[μ] E) : setToL1SCLM α E μ hT f = setToL1SCLM α E μ hT' f :=
setToL1S_congr_left T T' h f
theorem setToL1SCLM_congr_measure {μ' : Measure α} (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (hμ : μ ≪ μ') (f : α →₁ₛ[μ] E) (f' : α →₁ₛ[μ'] E)
(h : (f : α → E) =ᵐ[μ] f') : setToL1SCLM α E μ hT f = setToL1SCLM α E μ' hT' f' :=
setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hμ _ _ h
theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ (hT.add hT') f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f :=
setToL1S_add_left T T' f
theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT'' f = setToL1SCLM α E μ hT f + setToL1SCLM α E μ hT' f :=
setToL1S_add_left' T T' T'' h_add f
theorem setToL1SCLM_smul_left (c : ℝ) (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ (hT.smul c) f = c • setToL1SCLM α E μ hT f :=
setToL1S_smul_left T c f
theorem setToL1SCLM_smul_left' (c : ℝ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C')
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT' f = c • setToL1SCLM α E μ hT f :=
setToL1S_smul_left' T T' c h_smul f
theorem norm_setToL1SCLM_le {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hC : 0 ≤ C) : ‖setToL1SCLM α E μ hT‖ ≤ C :=
LinearMap.mkContinuous_norm_le _ hC _
theorem norm_setToL1SCLM_le' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C) :
‖setToL1SCLM α E μ hT‖ ≤ max C 0 :=
LinearMap.mkContinuous_norm_le' _ _
theorem setToL1SCLM_const [IsFiniteMeasure μ] {T : Set α → E →L[ℝ] F} {C : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (x : E) :
setToL1SCLM α E μ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top μ _) x) =
T univ x :=
setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G'']
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G']
theorem setToL1SCLM_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1SCLM_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁ₛ[μ] E) :
setToL1SCLM α E μ hT f ≤ setToL1SCLM α E μ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G'] in
theorem setToL1SCLM_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁ₛ[μ] G'}
(hf : 0 ≤ f) : 0 ≤ setToL1SCLM α G' μ hT f :=
setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf
theorem setToL1SCLM_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁ₛ[μ] G'}
(hfg : f ≤ g) : setToL1SCLM α G' μ hT f ≤ setToL1SCLM α G' μ hT g :=
setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg
end Order
end SetToL1S
end SimpleFunc
open SimpleFunc
section SetToL1
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
variable (𝕜) [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [CompleteSpace F]
{T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ}
/-- Extend `Set α → (E →L[ℝ] F)` to `(α →₁[μ] E) →L[𝕜] F`. -/
def setToL1' (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁[μ] E) →L[𝕜] F :=
(setToL1SCLM' α E 𝕜 μ hT h_smul).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
variable {𝕜}
/-- Extend `Set α → E →L[ℝ] F` to `(α →₁[μ] E) →L[ℝ] F`. -/
def setToL1 (hT : DominatedFinMeasAdditive μ T C) : (α →₁[μ] E) →L[ℝ] F :=
(setToL1SCLM α E μ hT).extend (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) (f : α →₁ₛ[μ] E) :
setToL1 hT f = setToL1SCLM α E μ hT f :=
uniformly_extend_of_ind simpleFunc.isUniformInducing (simpleFunc.denseRange one_ne_top)
(setToL1SCLM α E μ hT).uniformContinuous _
theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[μ] E) :
setToL1 hT f = setToL1' 𝕜 hT h_smul f :=
rfl
@[simp]
theorem setToL1_zero_left (hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C)
(f : α →₁[μ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply]
theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) (f : α →₁[μ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp,
ContinuousLinearMap.zero_apply]
theorem setToL1_congr_left (T T' : Set α → E →L[ℝ] F) {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C') (h : T = T')
(f : α →₁[μ] E) : setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact setToL1SCLM_congr_left hT' hT h.symm f
theorem setToL1_congr_left' (T T' : Set α → E →L[ℝ] F) {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s) (f : α →₁[μ] E) :
setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM α E μ hT f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact (setToL1SCLM_congr_left' hT hT' h f).symm
theorem setToL1_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α →₁[μ] E) :
setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by
rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.add hT')) _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ (hT.add hT') f by
rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT']
theorem setToL1_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α →₁[μ] E) :
setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT'') _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E μ hT'' f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM,
setToL1SCLM_add_left' hT hT' hT'' h_add]
theorem setToL1_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α →₁[μ] E) :
setToL1 (hT.smul c) f = c • setToL1 hT f := by
suffices setToL1 (hT.smul c) = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ (hT.smul c)) _ _ _ _ ?_
ext1 f
suffices c • setToL1 hT f = setToL1SCLM α E μ (hT.smul c) f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT]
theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α →₁[μ] E) :
setToL1 hT' f = c • setToL1 hT f := by
suffices setToL1 hT' = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM α E μ hT') _ _ _ _ ?_
ext1 f
suffices c • setToL1 hT f = setToL1SCLM α E μ hT' f by rw [← this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul]
theorem setToL1_smul (hT : DominatedFinMeasAdditive μ T C)
(h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[μ] E) :
setToL1 hT (c • f) = c • setToL1 hT f := by
rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul]
exact ContinuousLinearMap.map_smul _ _ _
theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s < ∞) (x : E) :
setToL1 hT (simpleFunc.indicatorConst 1 hs hμs.ne x) = T s x := by
rw [setToL1_eq_setToL1SCLM]
exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hμs x
theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) :
setToL1 hT (indicatorConstLp 1 hs hμs x) = T s x := by
rw [← Lp.simpleFunc.coe_indicatorConst hs hμs x]
exact setToL1_simpleFunc_indicatorConst hT hs hμs.lt_top x
theorem setToL1_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) :
setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x :=
setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace ℝ G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G']
theorem setToL1_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α →₁[μ] E) :
setToL1 hT f ≤ setToL1 hT' f := by
induction f using Lp.induction (hp_ne_top := one_ne_top) with
| @indicatorConst c s hs hμs =>
rw [setToL1_simpleFunc_indicatorConst hT hs hμs, setToL1_simpleFunc_indicatorConst hT' hs hμs]
exact hTT' s hs hμs c
| @add f g hf hg _ hf_le hg_le =>
rw [(setToL1 hT).map_add, (setToL1 hT').map_add]
exact add_le_add hf_le hg_le
| isClosed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous
theorem setToL1_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToL1 hT f ≤ setToL1 hT' f :=
setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToL1_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α →₁[μ] G'}
(hf : 0 ≤ f) : 0 ≤ setToL1 hT f := by
suffices ∀ f : { g : α →₁[μ] G' // 0 ≤ g }, 0 ≤ setToL1 hT f from
this (⟨f, hf⟩ : { g : α →₁[μ] G' // 0 ≤ g })
refine fun g =>
@isClosed_property { g : α →₁ₛ[μ] G' // 0 ≤ g } { g : α →₁[μ] G' // 0 ≤ g } _ _
(fun g => 0 ≤ setToL1 hT g)
(denseRange_coeSimpleFuncNonnegToLpNonneg 1 μ G' one_ne_top) ?_ ?_ g
· exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom)
· intro g
have : (coeSimpleFuncNonnegToLpNonneg 1 μ G' g : α →₁[μ] G') = (g : α →₁ₛ[μ] G') := rfl
rw [this, setToL1_eq_setToL1SCLM]
exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2
theorem setToL1_mono [IsOrderedAddMonoid G']
{T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α →₁[μ] G'}
(hfg : f ≤ g) : setToL1 hT f ≤ setToL1 hT g := by
rw [← sub_nonneg] at hfg ⊢
rw [← (setToL1 hT).map_sub]
exact setToL1_nonneg hT hT_nonneg hfg
end Order
theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive μ T C) :
‖setToL1 hT‖ ≤ ‖setToL1SCLM α E μ hT‖ :=
calc
‖setToL1 hT‖ ≤ (1 : ℝ≥0) * ‖setToL1SCLM α E μ hT‖ := by
refine
ContinuousLinearMap.opNorm_extend_le (setToL1SCLM α E μ hT) (coeToLp α E ℝ)
(simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_
rw [NNReal.coe_one, one_mul]
simp [coeToLp]
_ = ‖setToL1SCLM α E μ hT‖ := by rw [NNReal.coe_one, one_mul]
theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C)
(f : α →₁[μ] E) : ‖setToL1 hT f‖ ≤ C * ‖f‖ :=
calc
‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ ≤ C * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC
theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
‖setToL1 hT f‖ ≤ max C 0 * ‖f‖ :=
calc
‖setToL1 hT f‖ ≤ ‖setToL1SCLM α E μ hT‖ * ‖f‖ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ ≤ max C 0 * ‖f‖ :=
mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _)
theorem norm_setToL1_le (hT : DominatedFinMeasAdditive μ T C) (hC : 0 ≤ C) : ‖setToL1 hT‖ ≤ C :=
ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC)
theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive μ T C) : ‖setToL1 hT‖ ≤ max C 0 :=
ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT)
theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive μ T C) :
LipschitzWith (Real.toNNReal C) (setToL1 hT) :=
(setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT)
/-- If `fs i → f` in `L1`, then `setToL1 hT (fs i) → setToL1 hT f`. -/
theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) {ι}
(fs : ι → α →₁[μ] E) {l : Filter ι} (hfs : Tendsto fs l (𝓝 f)) :
Tendsto (fun i => setToL1 hT (fs i)) l (𝓝 <| setToL1 hT f) :=
((setToL1 hT).continuous.tendsto _).comp hfs
end SetToL1
end L1
section Function
variable [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E}
variable (μ T)
open Classical in
/-- Extend `T : Set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to
0 if the function is not integrable. -/
def setToFun (hT : DominatedFinMeasAdditive μ T C) (f : α → E) : F :=
if hf : Integrable f μ then L1.setToL1 hT (hf.toL1 f) else 0
variable {μ T}
theorem setToFun_eq (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
setToFun μ T hT f = L1.setToL1 hT (hf.toL1 f) :=
dif_pos hf
theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
setToFun μ T hT f = L1.setToL1 hT f := by
rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn]
theorem setToFun_undef (hT : DominatedFinMeasAdditive μ T C) (hf : ¬Integrable f μ) :
setToFun μ T hT f = 0 :=
dif_neg hf
theorem setToFun_non_aestronglyMeasurable (hT : DominatedFinMeasAdditive μ T C)
(hf : ¬AEStronglyMeasurable f μ) : setToFun μ T hT f = 0 :=
setToFun_undef hT (not_and_of_not_left _ hf)
@[deprecated (since := "2025-04-09")]
alias setToFun_non_aEStronglyMeasurable := setToFun_non_aestronglyMeasurable
theorem setToFun_congr_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : T = T') (f : α → E) :
setToFun μ T hT f = setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h]
· simp_rw [setToFun_undef _ hf]
theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (h : ∀ s, MeasurableSet s → μ s < ∞ → T s = T' s)
(f : α → E) : setToFun μ T hT f = setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h]
· simp_rw [setToFun_undef _ hf]
theorem setToFun_add_left (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (f : α → E) :
setToFun μ (T + T') (hT.add hT') f = setToFun μ T hT f + setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT']
· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_add_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (hT'' : DominatedFinMeasAdditive μ T'' C'')
(h_add : ∀ s, MeasurableSet s → μ s < ∞ → T'' s = T s + T' s) (f : α → E) :
setToFun μ T'' hT'' f = setToFun μ T hT f + setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add]
· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_smul_left (hT : DominatedFinMeasAdditive μ T C) (c : ℝ) (f : α → E) :
setToFun μ (fun s => c • T s) (hT.smul c) f = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c]
· simp_rw [setToFun_undef _ hf, smul_zero]
theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ T' C') (c : ℝ)
(h_smul : ∀ s, MeasurableSet s → μ s < ∞ → T' s = c • T s) (f : α → E) :
setToFun μ T' hT' f = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul]
· simp_rw [setToFun_undef _ hf, smul_zero]
@[simp]
theorem setToFun_zero (hT : DominatedFinMeasAdditive μ T C) : setToFun μ T hT (0 : α → E) = 0 := by
rw [Pi.zero_def, setToFun_eq hT (integrable_zero _ _ _)]
simp only [← Pi.zero_def]
rw [Integrable.toL1_zero, ContinuousLinearMap.map_zero]
@[simp]
theorem setToFun_zero_left {hT : DominatedFinMeasAdditive μ (0 : Set α → E →L[ℝ] F) C} :
setToFun μ 0 hT f = 0 := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _
· exact setToFun_undef hT hf
theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive μ T C)
(h_zero : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0) : setToFun μ T hT f = 0 := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _
· exact setToFun_undef hT hf
theorem setToFun_add (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ)
(hg : Integrable g μ) : setToFun μ T hT (f + g) = setToFun μ T hT f + setToFun μ T hT g := by
rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add,
(L1.setToL1 hT).map_add]
theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι)
{f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) μ) :
setToFun μ T hT (∑ i ∈ s, f i) = ∑ i ∈ s, setToFun μ T hT (f i) := by
classical
revert hf
refine Finset.induction_on s ?_ ?_
· intro _
simp only [setToFun_zero, Finset.sum_empty]
· intro i s his ih hf
simp only [his, Finset.sum_insert, not_false_iff]
rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _]
· rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)]
· convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x
simp
theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive μ T C) {ι} (s : Finset ι) {f : ι → α → E}
(hf : ∀ i ∈ s, Integrable (f i) μ) :
(setToFun μ T hT fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, setToFun μ T hT (f i) := by
convert setToFun_finset_sum' hT s hf with a; simp
theorem setToFun_neg (hT : DominatedFinMeasAdditive μ T C) (f : α → E) :
setToFun μ T hT (-f) = -setToFun μ T hT f := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg,
(L1.setToL1 hT).map_neg]
· rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero]
rwa [← integrable_neg_iff] at hf
theorem setToFun_sub (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ)
(hg : Integrable g μ) : setToFun μ T hT (f - g) = setToFun μ T hT f - setToFun μ T hT g := by
rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g]
theorem setToFun_smul [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F]
(hT : DominatedFinMeasAdditive μ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜)
(f : α → E) : setToFun μ T hT (c • f) = c • setToFun μ T hT f := by
by_cases hf : Integrable f μ
· rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul',
L1.setToL1_smul hT h_smul c _]
· by_cases hr : c = 0
· rw [hr]; simp
· have hf' : ¬Integrable (c • f) μ := by rwa [integrable_smul_iff hr f]
rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero]
theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive μ T C) (h : f =ᵐ[μ] g) :
setToFun μ T hT f = setToFun μ T hT g := by
by_cases hfi : Integrable f μ
· have hgi : Integrable g μ := hfi.congr h
rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h]
· have hgi : ¬Integrable g μ := by rw [integrable_congr h] at hfi; exact hfi
rw [setToFun_undef hT hfi, setToFun_undef hT hgi]
theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive μ T C) (h : μ = 0) :
setToFun μ T hT f = 0 := by
have : f =ᵐ[μ] 0 := by simp [h, EventuallyEq]
rw [setToFun_congr_ae hT this, setToFun_zero]
theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive μ T C)
(h : ∀ s, MeasurableSet s → μ s < ∞ → μ s = 0) : setToFun μ T hT f = 0 :=
setToFun_zero_left' hT fun s hs hμs => hT.eq_zero_of_measure_zero hs (h s hs hμs)
theorem setToFun_toL1 (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
setToFun μ T hT (hf.toL1 f) = setToFun μ T hT f :=
setToFun_congr_ae hT hf.coeFn_toL1
theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive μ T C) {s : Set α}
(hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E) :
setToFun μ T hT (s.indicator fun _ => x) = T s x := by
rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hμs x).symm]
rw [L1.setToFun_eq_setToL1 hT]
exact L1.setToL1_indicatorConstLp hT hs hμs x
theorem setToFun_const [IsFiniteMeasure μ] (hT : DominatedFinMeasAdditive μ T C) (x : E) :
(setToFun μ T hT fun _ => x) = T univ x := by
have : (fun _ : α => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm
rw [this]
exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace ℝ G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G']
theorem setToFun_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, T s x ≤ T' s x) (f : α → E) :
setToFun μ T hT f ≤ setToFun μ T' hT' f := by
by_cases hf : Integrable f μ
· simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _
· simp_rw [setToFun_undef _ hf, le_rfl]
theorem setToFun_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ}
(hT : DominatedFinMeasAdditive μ T C) (hT' : DominatedFinMeasAdditive μ T' C')
(hTT' : ∀ s x, T s x ≤ T' s x) (f : α →₁[μ] E) : setToFun μ T hT f ≤ setToFun μ T' hT' f :=
setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToFun_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f : α → G'}
(hf : 0 ≤ᵐ[μ] f) : 0 ≤ setToFun μ T hT f := by
by_cases hfi : Integrable f μ
· simp_rw [setToFun_eq _ hfi]
refine L1.setToL1_nonneg hT hT_nonneg ?_
rw [← Lp.coeFn_le]
have h0 := Lp.coeFn_zero G' 1 μ
have h := Integrable.coeFn_toL1 hfi
filter_upwards [h0, h, hf] with _ h0a ha hfa
rw [h0a, ha]
exact hfa
· simp_rw [setToFun_undef _ hfi, le_rfl]
theorem setToFun_mono [IsOrderedAddMonoid G']
{T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive μ T C)
(hT_nonneg : ∀ s, MeasurableSet s → μ s < ∞ → ∀ x, 0 ≤ x → 0 ≤ T s x) {f g : α → G'}
(hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) :
setToFun μ T hT f ≤ setToFun μ T hT g := by
rw [← sub_nonneg, ← setToFun_sub hT hg hf]
refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_)
rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg]
exact ha
end Order
@[continuity]
theorem continuous_setToFun (hT : DominatedFinMeasAdditive μ T C) :
Continuous fun f : α →₁[μ] E => setToFun μ T hT f := by
simp_rw [L1.setToFun_eq_setToL1 hT]; exact ContinuousLinearMap.continuous _
/-- If `F i → f` in `L1`, then `setToFun μ T hT (F i) → setToFun μ T hT f`. -/
theorem tendsto_setToFun_of_L1 (hT : DominatedFinMeasAdditive μ T C) {ι} (f : α → E)
(hfi : Integrable f μ) {fs : ι → α → E} {l : Filter ι} (hfsi : ∀ᶠ i in l, Integrable (fs i) μ)
(hfs : Tendsto (fun i => ∫⁻ x, ‖fs i x - f x‖ₑ ∂μ) l (𝓝 0)) :
Tendsto (fun i => setToFun μ T hT (fs i)) l (𝓝 <| setToFun μ T hT f) := by
classical
let f_lp := hfi.toL1 f
let F_lp i := if hFi : Integrable (fs i) μ then hFi.toL1 (fs i) else 0
have tendsto_L1 : Tendsto F_lp l (𝓝 f_lp) := by
rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm']
simp_rw [eLpNorm_one_eq_lintegral_enorm, Pi.sub_apply]
refine (tendsto_congr' ?_).mp hfs
filter_upwards [hfsi] with i hi
refine lintegral_congr_ae ?_
filter_upwards [hi.coeFn_toL1, hfi.coeFn_toL1] with x hxi hxf
simp_rw [F_lp, dif_pos hi, hxi, f_lp, hxf]
suffices Tendsto (fun i => setToFun μ T hT (F_lp i)) l (𝓝 (setToFun μ T hT f)) by
refine (tendsto_congr' ?_).mp this
filter_upwards [hfsi] with i hi
suffices h_ae_eq : F_lp i =ᵐ[μ] fs i from setToFun_congr_ae hT h_ae_eq
simp_rw [F_lp, dif_pos hi]
exact hi.coeFn_toL1
rw [setToFun_congr_ae hT hfi.coeFn_toL1.symm]
exact ((continuous_setToFun hT).tendsto f_lp).comp tendsto_L1
theorem tendsto_setToFun_approxOn_of_measurable (hT : DominatedFinMeasAdditive μ T C)
[MeasurableSpace E] [BorelSpace E] {f : α → E} {s : Set E} [SeparableSpace s]
(hfi : Integrable f μ) (hfm : Measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E}
(h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) μ) :
Tendsto (fun n => setToFun μ T hT (SimpleFunc.approxOn f hfm s y₀ h₀ n)) atTop
(𝓝 <| setToFun μ T hT f) :=
tendsto_setToFun_of_L1 hT _ hfi
(Eventually.of_forall (SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i))
(SimpleFunc.tendsto_approxOn_L1_enorm hfm _ hs (hfi.sub h₀i).2)
theorem tendsto_setToFun_approxOn_of_measurable_of_range_subset
(hT : DominatedFinMeasAdditive μ T C) [MeasurableSpace E] [BorelSpace E] {f : α → E}
(fmeas : Measurable f) (hf : Integrable f μ) (s : Set E) [SeparableSpace s]
(hs : range f ∪ {0} ⊆ s) :
Tendsto (fun n => setToFun μ T hT (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n)) atTop
(𝓝 <| setToFun μ T hT f) := by
refine tendsto_setToFun_approxOn_of_measurable hT hf fmeas ?_ _ (integrable_zero _ _ _)
exact Eventually.of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))
/-- Auxiliary lemma for `setToFun_congr_measure`: the function sending `f : α →₁[μ] G` to
`f : α →₁[μ'] G` is continuous when `μ' ≤ c' • μ` for `c' ≠ ∞`. -/
theorem continuous_L1_toL1 {μ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hμ'_le : μ' ≤ c' • μ) :
Continuous fun f : α →₁[μ] G =>
(Integrable.of_measure_le_smul hc' hμ'_le (L1.integrable_coeFn f)).toL1 f := by
by_cases hc'0 : c' = 0
· have hμ'0 : μ' = 0 := by rw [← Measure.nonpos_iff_eq_zero']; refine hμ'_le.trans ?_; simp [hc'0]
have h_im_zero :
(fun f : α →₁[μ] G =>
(Integrable.of_measure_le_smul hc' hμ'_le (L1.integrable_coeFn f)).toL1 f) =
0 := by
ext1 f; ext1; simp_rw [hμ'0]; simp only [ae_zero, EventuallyEq, eventually_bot]
rw [h_im_zero]
exact continuous_zero
rw [Metric.continuous_iff]
intro f ε hε_pos
use ε / 2 / c'.toReal
refine ⟨div_pos (half_pos hε_pos) (toReal_pos hc'0 hc'), ?_⟩
intro g hfg
rw [Lp.dist_def] at hfg ⊢
let h_int := fun f' : α →₁[μ] G => (L1.integrable_coeFn f').of_measure_le_smul hc' hμ'_le
have :
eLpNorm (⇑(Integrable.toL1 g (h_int g)) - ⇑(Integrable.toL1 f (h_int f))) 1 μ' =
eLpNorm (⇑g - ⇑f) 1 μ' :=
eLpNorm_congr_ae ((Integrable.coeFn_toL1 _).sub (Integrable.coeFn_toL1 _))
rw [this]
have h_eLpNorm_ne_top : eLpNorm (⇑g - ⇑f) 1 μ ≠ ∞ := by
rw [← eLpNorm_congr_ae (Lp.coeFn_sub _ _)]; exact Lp.eLpNorm_ne_top _
calc
(eLpNorm (⇑g - ⇑f) 1 μ').toReal ≤ (c' * eLpNorm (⇑g - ⇑f) 1 μ).toReal := by
refine toReal_mono (ENNReal.mul_ne_top hc' h_eLpNorm_ne_top) ?_
refine (eLpNorm_mono_measure (⇑g - ⇑f) hμ'_le).trans_eq ?_
rw [eLpNorm_smul_measure_of_ne_zero hc'0, smul_eq_mul]
simp
_ = c'.toReal * (eLpNorm (⇑g - ⇑f) 1 μ).toReal := toReal_mul
_ ≤ c'.toReal * (ε / 2 / c'.toReal) := by gcongr
_ = ε / 2 := by
refine mul_div_cancel₀ (ε / 2) ?_; rw [Ne, toReal_eq_zero_iff]; simp [hc', hc'0]
_ < ε := half_lt_self hε_pos
theorem setToFun_congr_measure_of_integrable {μ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞)
(hμ'_le : μ' ≤ c' • μ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (f : α → E) (hfμ : Integrable f μ) :
setToFun μ T hT f = setToFun μ' T hT' f := by
-- integrability for `μ` implies integrability for `μ'`.
have h_int : ∀ g : α → E, Integrable g μ → Integrable g μ' := fun g hg =>
Integrable.of_measure_le_smul hc' hμ'_le hg
-- We use `Integrable.induction`
apply hfμ.induction (P := fun f => setToFun μ T hT f = setToFun μ' T hT' f)
· intro c s hs hμs
have hμ's : μ' s ≠ ∞ := by
refine ((hμ'_le s).trans_lt ?_).ne
rw [Measure.smul_apply, smul_eq_mul]
exact ENNReal.mul_lt_top hc'.lt_top hμs
rw [setToFun_indicator_const hT hs hμs.ne, setToFun_indicator_const hT' hs hμ's]
· intro f₂ g₂ _ hf₂ hg₂ h_eq_f h_eq_g
rw [setToFun_add hT hf₂ hg₂, setToFun_add hT' (h_int f₂ hf₂) (h_int g₂ hg₂), h_eq_f, h_eq_g]
· refine isClosed_eq (continuous_setToFun hT) ?_
have :
(fun f : α →₁[μ] E => setToFun μ' T hT' f) = fun f : α →₁[μ] E =>
setToFun μ' T hT' ((h_int f (L1.integrable_coeFn f)).toL1 f) := by
ext1 f; exact setToFun_congr_ae hT' (Integrable.coeFn_toL1 _).symm
rw [this]
exact (continuous_setToFun hT').comp (continuous_L1_toL1 c' hc' hμ'_le)
· intro f₂ g₂ hfg _ hf_eq
have hfg' : f₂ =ᵐ[μ'] g₂ := (Measure.absolutelyContinuous_of_le_smul hμ'_le).ae_eq hfg
rw [← setToFun_congr_ae hT hfg, hf_eq, setToFun_congr_ae hT' hfg']
theorem setToFun_congr_measure {μ' : Measure α} (c c' : ℝ≥0∞) (hc : c ≠ ∞) (hc' : c' ≠ ∞)
(hμ_le : μ ≤ c • μ') (hμ'_le : μ' ≤ c' • μ) (hT : DominatedFinMeasAdditive μ T C)
(hT' : DominatedFinMeasAdditive μ' T C') (f : α → E) :
setToFun μ T hT f = setToFun μ' T hT' f := by
by_cases hf : Integrable f μ
· exact setToFun_congr_measure_of_integrable c' hc' hμ'_le hT hT' f hf
· -- if `f` is not integrable, both `setToFun` are 0.
have h_int : ∀ g : α → E, ¬Integrable g μ → ¬Integrable g μ' := fun g =>
mt fun h => h.of_measure_le_smul hc hμ_le
simp_rw [setToFun_undef _ hf, setToFun_undef _ (h_int f hf)]
theorem setToFun_congr_measure_of_add_right {μ' : Measure α}
(hT_add : DominatedFinMeasAdditive (μ + μ') T C') (hT : DominatedFinMeasAdditive μ T C)
(f : α → E) (hf : Integrable f (μ + μ')) :
setToFun (μ + μ') T hT_add f = setToFun μ T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [← add_zero μ]
exact add_le_add le_rfl bot_le
theorem setToFun_congr_measure_of_add_left {μ' : Measure α}
(hT_add : DominatedFinMeasAdditive (μ + μ') T C') (hT : DominatedFinMeasAdditive μ' T C)
(f : α → E) (hf : Integrable f (μ + μ')) :
setToFun (μ + μ') T hT_add f = setToFun μ' T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [← zero_add μ']
exact add_le_add_right bot_le μ'
theorem setToFun_top_smul_measure (hT : DominatedFinMeasAdditive (∞ • μ) T C) (f : α → E) :
setToFun (∞ • μ) T hT f = 0 := by
refine setToFun_measure_zero' hT fun s _ hμs => ?_
rw [lt_top_iff_ne_top] at hμs
simp only [true_and, Measure.smul_apply, ENNReal.mul_eq_top, eq_self_iff_true,
top_ne_zero, Ne, not_false_iff, not_or, Classical.not_not, smul_eq_mul] at hμs
simp only [hμs.right, Measure.smul_apply, mul_zero, smul_eq_mul]
theorem setToFun_congr_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞)
(hT : DominatedFinMeasAdditive μ T C) (hT_smul : DominatedFinMeasAdditive (c • μ) T C')
(f : α → E) : setToFun μ T hT f = setToFun (c • μ) T hT_smul f := by
by_cases hc0 : c = 0
· simp [hc0] at hT_smul
have h : ∀ s, MeasurableSet s → μ s < ∞ → T s = 0 := fun s hs _ => hT_smul.eq_zero hs
rw [setToFun_zero_left' _ h, setToFun_measure_zero]
simp [hc0]
refine setToFun_congr_measure c⁻¹ c ?_ hc_ne_top (le_of_eq ?_) le_rfl hT hT_smul f
· simp [hc0]
· rw [smul_smul, ENNReal.inv_mul_cancel hc0 hc_ne_top, one_smul]
theorem norm_setToFun_le_mul_norm (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E)
(hC : 0 ≤ C) : ‖setToFun μ T hT f‖ ≤ C * ‖f‖ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm hT hC f
theorem norm_setToFun_le_mul_norm' (hT : DominatedFinMeasAdditive μ T C) (f : α →₁[μ] E) :
‖setToFun μ T hT f‖ ≤ max C 0 * ‖f‖ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm' hT f
theorem norm_setToFun_le (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) (hC : 0 ≤ C) :
‖setToFun μ T hT f‖ ≤ C * ‖hf.toL1 f‖ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm hT hC _
theorem norm_setToFun_le' (hT : DominatedFinMeasAdditive μ T C) (hf : Integrable f μ) :
‖setToFun μ T hT f‖ ≤ max C 0 * ‖hf.toL1 f‖ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm' hT _
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their image by
`setToFun`.
We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound μ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_setToFun_of_dominated_convergence (hT : DominatedFinMeasAdditive μ T C)
{fs : ℕ → α → E} {f : α → E} (bound : α → ℝ)
(fs_measurable : ∀ n, AEStronglyMeasurable (fs n) μ) (bound_integrable : Integrable bound μ)
(h_bound : ∀ n, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => fs n a) atTop (𝓝 (f a))) :
Tendsto (fun n => setToFun μ T hT (fs n)) atTop (𝓝 <| setToFun μ T hT f) := by
-- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions.
have f_measurable : AEStronglyMeasurable f μ :=
aestronglyMeasurable_of_tendsto_ae _ fs_measurable h_lim
-- all functions we consider are integrable
have fs_int : ∀ n, Integrable (fs n) μ := fun n =>
bound_integrable.mono' (fs_measurable n) (h_bound _)
have f_int : Integrable f μ :=
⟨f_measurable,
hasFiniteIntegral_of_dominated_convergence bound_integrable.hasFiniteIntegral h_bound
h_lim⟩
-- it suffices to prove the result for the corresponding L1 functions
suffices
Tendsto (fun n => L1.setToL1 hT ((fs_int n).toL1 (fs n))) atTop
(𝓝 (L1.setToL1 hT (f_int.toL1 f))) by
convert this with n
· exact setToFun_eq hT (fs_int n)
· exact setToFun_eq hT f_int
-- the convergence of setToL1 follows from the convergence of the L1 functions
refine L1.tendsto_setToL1 hT _ _ ?_
-- up to some rewriting, what we need to prove is `h_lim`
rw [tendsto_iff_norm_sub_tendsto_zero]
have lintegral_norm_tendsto_zero :
Tendsto (fun n => ENNReal.toReal <| ∫⁻ a, ENNReal.ofReal ‖fs n a - f a‖ ∂μ) atTop (𝓝 0) :=
(tendsto_toReal zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence fs_measurable
bound_integrable.hasFiniteIntegral h_bound h_lim)
convert lintegral_norm_tendsto_zero with n
rw [L1.norm_def]
congr 1
refine lintegral_congr_ae ?_
rw [← Integrable.toL1_sub]
refine ((fs_int n).sub f_int).coeFn_toL1.mono fun x hx => ?_
dsimp only
rw [hx, ofReal_norm_eq_enorm, Pi.sub_apply]
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
theorem tendsto_setToFun_filter_of_dominated_convergence (hT : DominatedFinMeasAdditive μ T C) {ι}
{l : Filter ι} [l.IsCountablyGenerated] {fs : ι → α → E} {f : α → E} (bound : α → ℝ)
(hfs_meas : ∀ᶠ n in l, AEStronglyMeasurable (fs n) μ)
(h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_lim : ∀ᵐ a ∂μ, Tendsto (fun n => fs n a) l (𝓝 (f a))) :
Tendsto (fun n => setToFun μ T hT (fs n)) l (𝓝 <| setToFun μ T hT f) := by
rw [tendsto_iff_seq_tendsto]
intro x xl
have hxl : ∀ s ∈ l, ∃ a, ∀ b ≥ a, x b ∈ s := by rwa [tendsto_atTop'] at xl
have h :
{ x : ι | (fun n => AEStronglyMeasurable (fs n) μ) x } ∩
{ x : ι | (fun n => ∀ᵐ a ∂μ, ‖fs n a‖ ≤ bound a) x } ∈ l :=
inter_mem hfs_meas h_bound
obtain ⟨k, h⟩ := hxl _ h
rw [← tendsto_add_atTop_iff_nat k]
refine tendsto_setToFun_of_dominated_convergence hT bound ?_ bound_integrable ?_ ?_
· exact fun n => (h _ (self_le_add_left _ _)).1
· exact fun n => (h _ (self_le_add_left _ _)).2
· filter_upwards [h_lim]
refine fun a h_lin => @Tendsto.comp _ _ _ (fun n => x (n + k)) (fun n => fs n a) _ _ _ h_lin ?_
rwa [tendsto_add_atTop_iff_nat]
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
theorem continuousWithinAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C)
{fs : X → α → E} {x₀ : X} {bound : α → ℝ} {s : Set X}
(hfs_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousWithinAt (fun x => fs x a) s x₀) :
ContinuousWithinAt (fun x => setToFun μ T hT (fs x)) s x₀ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
theorem continuousAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{x₀ : X} {bound : α → ℝ} (hfs_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousAt (fun x => fs x a) x₀) :
ContinuousAt (fun x => setToFun μ T hT (fs x)) x₀ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_›
theorem continuousOn_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{bound : α → ℝ} {s : Set X} (hfs_meas : ∀ x ∈ s, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, ContinuousOn (fun x => fs x a) s) :
ContinuousOn (fun x => setToFun μ T hT (fs x)) s := by
intro x hx
refine continuousWithinAt_setToFun_of_dominated hT ?_ ?_ bound_integrable ?_
· filter_upwards [self_mem_nhdsWithin] with x hx using hfs_meas x hx
· filter_upwards [self_mem_nhdsWithin] with x hx using h_bound x hx
· filter_upwards [h_cont] with a ha using ha x hx
theorem continuous_setToFun_of_dominated (hT : DominatedFinMeasAdditive μ T C) {fs : X → α → E}
{bound : α → ℝ} (hfs_meas : ∀ x, AEStronglyMeasurable (fs x) μ)
(h_bound : ∀ x, ∀ᵐ a ∂μ, ‖fs x a‖ ≤ bound a) (bound_integrable : Integrable bound μ)
(h_cont : ∀ᵐ a ∂μ, Continuous fun x => fs x a) : Continuous fun x => setToFun μ T hT (fs x) :=
continuous_iff_continuousAt.mpr fun _ =>
continuousAt_setToFun_of_dominated hT (Eventually.of_forall hfs_meas)
(Eventually.of_forall h_bound) ‹_› <|
h_cont.mono fun _ => Continuous.continuousAt
end Function
end MeasureTheory
| Mathlib/MeasureTheory/Integral/SetToL1.lean | 1,483 | 1,490 | |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Properties
/-!
# Function field of integral schemes
We define the function field of an irreducible scheme as the stalk of the generic point.
This is a field when the scheme is integral.
## Main definition
* `AlgebraicGeometry.Scheme.functionField`: The function field of an integral scheme.
* `AlgebraicGeometry.Scheme.germToFunctionField`: The canonical map from a component into the
function field. This map is injective.
-/
-- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737
universe u v
open TopologicalSpace Opposite CategoryTheory CategoryTheory.Limits TopCat
namespace AlgebraicGeometry
variable (X : Scheme)
/-- The function field of an irreducible scheme is the local ring at its generic point.
Despite the name, this is a field only when the scheme is integral. -/
noncomputable abbrev Scheme.functionField [IrreducibleSpace X] : CommRingCat :=
X.presheaf.stalk (genericPoint X)
/-- The restriction map from a component to the function field. -/
noncomputable abbrev Scheme.germToFunctionField [IrreducibleSpace X] (U : X.Opens)
[h : Nonempty U] : Γ(X, U) ⟶ X.functionField :=
X.presheaf.germ U
(genericPoint X)
(((genericPoint_spec X).mem_open_set_iff U.isOpen).mpr (by simpa using h))
noncomputable instance [IrreducibleSpace X] (U : X.Opens) [Nonempty U] :
Algebra Γ(X, U) X.functionField :=
(X.germToFunctionField U).hom.toAlgebra
noncomputable instance [IsIntegral X] : Field X.functionField := by
refine .ofIsUnitOrEqZero fun a ↦ ?_
obtain ⟨U, m, s, rfl⟩ := TopCat.Presheaf.germ_exist _ _ a
rw [or_iff_not_imp_right, ← (X.presheaf.germ _ _ m).hom.map_zero]
intro ha
replace ha := ne_of_apply_ne _ ha
have hs : genericPoint X ∈ RingedSpace.basicOpen _ s := by
rw [← SetLike.mem_coe, (genericPoint_spec X).mem_open_set_iff,
Set.univ_inter, Set.nonempty_iff_ne_empty, Ne, ← Opens.coe_bot, ← SetLike.ext'_iff]
· erw [basicOpen_eq_bot_iff]
exact ha
· exact (RingedSpace.basicOpen _ _).isOpen
have := (X.presheaf.germ _ _ hs).hom.isUnit_map (RingedSpace.isUnit_res_basicOpen _ s)
rwa [Presheaf.germ_res_apply] at this
theorem germ_injective_of_isIntegral [IsIntegral X] {U : X.Opens} (x : X) (hx : x ∈ U) :
Function.Injective (X.presheaf.germ U x hx) := by
rw [injective_iff_map_eq_zero]
intro y hy
rw [← (X.presheaf.germ U x hx).hom.map_zero] at hy
obtain ⟨W, hW, iU, iV, e⟩ := X.presheaf.germ_eq _ hx hx _ _ hy
cases Subsingleton.elim iU iV
haveI : Nonempty W := ⟨⟨_, hW⟩⟩
exact map_injective_of_isIntegral X iU e
theorem Scheme.germToFunctionField_injective [IsIntegral X] (U : X.Opens) [Nonempty U] :
Function.Injective (X.germToFunctionField U) :=
germ_injective_of_isIntegral _ _ _
theorem genericPoint_eq_of_isOpenImmersion {X Y : Scheme} (f : X ⟶ Y) [H : IsOpenImmersion f]
[hX : IrreducibleSpace X] [IrreducibleSpace Y] :
f.base (genericPoint X) = genericPoint Y := by
apply ((genericPoint_spec Y).eq _).symm
convert (genericPoint_spec X).image (show Continuous f.base by fun_prop)
symm
rw [← Set.univ_subset_iff]
| convert subset_closure_inter_of_isPreirreducible_of_isOpen _ H.base_open.isOpen_range _
· rw [Set.univ_inter, Set.image_univ]
· apply PreirreducibleSpace.isPreirreducible_univ (X := Y)
· exact ⟨_, trivial, Set.mem_range_self hX.2.some⟩
noncomputable instance stalkFunctionFieldAlgebra [IrreducibleSpace X] (x : X) :
Algebra (X.presheaf.stalk x) X.functionField := by
-- TODO: can we write this normally after the refactor finishes?
apply RingHom.toAlgebra
exact (X.presheaf.stalkSpecializes ((genericPoint_spec X).specializes trivial)).hom
| Mathlib/AlgebraicGeometry/FunctionField.lean | 83 | 93 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Data.Finset.Attach
import Mathlib.Data.Finset.Disjoint
import Mathlib.Data.Finset.Erase
import Mathlib.Data.Finset.Filter
import Mathlib.Data.Finset.Range
import Mathlib.Data.Finset.SDiff
import Mathlib.Data.Multiset.Basic
import Mathlib.Logic.Equiv.Set
import Mathlib.Order.Directed
import Mathlib.Order.Interval.Set.Defs
import Mathlib.Data.Set.SymmDiff
/-!
# Basic lemmas on finite sets
This file contains lemmas on the interaction of various definitions on the `Finset` type.
For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`.
## Main declarations
### Main definitions
* `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element
satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate.
### Equivalences between finsets
* The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there
for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that
`s ≃ t`.
TODO: examples
## Tags
finite sets, finset
-/
-- Assert that we define `Finset` without the material on `List.sublists`.
-- Note that we cannot use `List.sublists` itself as that is defined very early.
assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid
open Multiset Subtype Function
universe u
variable {α : Type*} {β : Type*} {γ : Type*}
namespace Finset
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
set_option linter.deprecated false in
@[deprecated "Deprecated without replacement." (since := "2025-02-07")]
theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) :
SizeOf.sizeOf x < SizeOf.sizeOf s := by
cases s
dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf]
rw [Nat.add_comm]
refine lt_trans ?_ (Nat.lt_succ_self _)
exact Multiset.sizeOf_lt_sizeOf_of_mem hx
/-! ### Lattice structure -/
section Lattice
variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α}
/-! #### union -/
@[simp]
theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t :=
ext fun a => by simp
@[simp]
theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by
simp only [disjoint_left, mem_union, or_imp, forall_and]
@[simp]
theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by
simp only [disjoint_right, mem_union, or_imp, forall_and]
/-! #### inter -/
theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty :=
not_disjoint_iff.trans <| by simp [Finset.Nonempty]
alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter
theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by
rw [← not_disjoint_iff_nonempty_inter]
exact em _
omit [DecidableEq α] in
theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) :
Disjoint s t ↔ s = ∅ :=
disjoint_of_le_iff_left_eq_bot h
lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} :
s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by
simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _),
not_disjoint_iff_nonempty_inter]
end Lattice
instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance
instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le
/-! ### erase -/
section Erase
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
@[simp]
theorem erase_empty (a : α) : erase ∅ a = ∅ :=
rfl
protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty :=
(hs.exists_ne a).imp <| by aesop
@[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by
simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)]
refine ⟨?_, fun hs ↦ hs.exists_ne a⟩
rintro ⟨b, hb, hba⟩
exact ⟨_, hb, _, ha, hba⟩
@[simp]
theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by
ext x
simp
@[simp]
theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a :=
ext fun x => by
simp +contextual only [mem_erase, mem_insert, and_congr_right_iff,
false_or, iff_self, imp_true_iff]
theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by
rw [erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) :
erase (insert a s) b = insert a (erase s b) :=
ext fun x => by
have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h
simp only [mem_erase, mem_insert, and_or_left, this]
theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) :
erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by
simp only [cons_eq_insert, erase_insert_of_ne hb]
@[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s :=
ext fun x => by
simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and]
apply or_iff_right_of_imp
rintro rfl
exact h
lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by
aesop
lemma insert_erase_invOn :
Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} :=
⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩
theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s :=
calc
s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _
_ = _ := insert_erase h
theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by
refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩
obtain ⟨a, ht, hs⟩ := not_subset.1 h.2
exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩
theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s :=
ssubset_iff_exists_subset_erase.2
⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩
theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by
rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h]
theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by
simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp]
exact forall_congr' fun x => forall_swap
theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s :=
subset_insert_iff.1 <| Subset.rfl
theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) :=
subset_insert_iff.2 <| Subset.rfl
theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by
rw [subset_insert_iff, erase_eq_of_not_mem h]
theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by
rw [← subset_insert_iff, insert_eq_of_mem h]
theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a :=
fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h]
end Erase
lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) :
∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by
classical
obtain ⟨a, ha, b, hb, hab⟩ := hs
have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩
refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;>
simp [insert_erase this, insert_erase ha, *]
/-! ### sdiff -/
section Sdiff
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by
ext; aesop
-- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`,
-- or instead add `Finset.union_singleton`/`Finset.singleton_union`?
theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ {a} = erase s a := by
ext
rw [mem_erase, mem_sdiff, mem_singleton, and_comm]
-- This lemma matches `Finset.insert_eq` in functionality.
theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} :=
(sdiff_singleton_eq_erase _ _).symm
theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by
simp_rw [erase_eq, disjoint_sdiff_comm]
lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by
rw [disjoint_erase_comm, erase_insert ha]
lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by
rw [← disjoint_erase_comm, erase_insert ha]
theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by
rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right]
exact ⟨not_mem_erase _ _, hst⟩
theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by
rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left]
exact ⟨not_mem_erase _ _, hst⟩
theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by
simp only [erase_eq, inter_sdiff_assoc]
@[simp]
theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by
simpa only [inter_comm t] using inter_erase a t s
theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by
simp_rw [erase_eq, sdiff_right_comm]
theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by
rw [erase_inter, inter_erase]
theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by
simp_rw [erase_eq, union_sdiff_distrib]
theorem insert_inter_distrib (s t : Finset α) (a : α) :
insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left]
theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by
simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm]
theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by
rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha]
theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by
rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha]
theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by
simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)]
theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by
simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib,
inter_comm]
theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) :
insert x (s \ insert x t) = s \ t := by
rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)]
theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by
rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq,
union_comm]
theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by
rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq]
theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by
rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff]
--TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra`
theorem sdiff_disjoint : Disjoint (t \ s) s :=
disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2
theorem disjoint_sdiff : Disjoint s (t \ s) :=
sdiff_disjoint.symm
theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) :=
disjoint_of_subset_right inter_subset_right sdiff_disjoint
end Sdiff
/-! ### attach -/
@[simp]
theorem attach_empty : attach (∅ : Finset α) = ∅ :=
rfl
@[simp]
theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by
simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff
@[simp]
theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by
simp [eq_empty_iff_forall_not_mem]
/-! ### filter -/
section Filter
variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α}
theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by
classical
ext x
simp only [mem_singleton, forall_eq, mem_filter]
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) :
filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) :=
eq_of_veq <| Multiset.filter_cons_of_pos s.val hp
theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) :
filter p (cons a s ha) = filter p s :=
eq_of_veq <| Multiset.filter_cons_of_neg s.val hp
theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] :
Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by
constructor <;> simp +contextual [disjoint_left]
theorem disjoint_filter_filter' (s t : Finset α)
{p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) :
Disjoint (s.filter p) (t.filter q) := by
simp_rw [disjoint_left, mem_filter]
rintro a ⟨_, hp⟩ ⟨_, hq⟩
rw [Pi.disjoint_iff] at h
simpa [hp, hq] using h a
theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop)
[DecidablePred p] [∀ x, Decidable (¬p x)] :
Disjoint (s.filter p) (t.filter fun a => ¬p a) :=
disjoint_filter_filter' s t disjoint_compl_right
theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) :
filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) :=
eq_of_veq <| Multiset.filter_add _ _ _
theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) :
filter p (cons a s ha) =
if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by
split_ifs with h
· rw [filter_cons_of_pos _ _ _ ha h]
· rw [filter_cons_of_neg _ _ _ ha h]
section
variable [DecidableEq α]
theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p :=
ext fun _ => by simp only [mem_filter, mem_union, or_and_right]
theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x :=
ext fun x => by simp [mem_filter, mem_union, ← and_or_left]
theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] :
(s.filter fun i => i ∈ t) = s ∩ t :=
ext fun i => by simp [mem_filter, mem_inter]
theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by
ext
simp [mem_filter, mem_inter, and_assoc]
theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by
ext
simp only [mem_inter, mem_filter, and_right_comm]
theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by
rw [inter_comm, filter_inter, inter_comm]
theorem filter_insert (a : α) (s : Finset α) :
filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by
ext x
split_ifs with h <;> by_cases h' : x = a <;> simp [h, h']
theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by
ext x
simp only [and_assoc, mem_filter, iff_self, mem_erase]
theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q :=
ext fun _ => by simp [mem_filter, mem_union, and_or_left]
theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q :=
ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc]
theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p :=
ext fun a => by
simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or,
Bool.not_eq_true, and_or_left, and_not_self, or_false]
lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] :
s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by
rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)]
theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ :=
ext fun _ => by simp [mem_sdiff, mem_filter]
theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) :
∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by
classical
refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩
· simp [filter_union_right, em]
· intro x
simp
· intro x
simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp]
intro hx hx₂
exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩
-- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing
-- on, e.g. `x ∈ s.filter (Eq b)`.
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq'` with the equality the other way.
-/
theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) :
s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by
split_ifs with h
· ext
simp only [mem_filter, mem_singleton, decide_eq_true_eq]
refine ⟨fun h => h.2.symm, ?_⟩
rintro rfl
exact ⟨h, rfl⟩
· ext
simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq]
rintro m rfl
exact h m
/-- After filtering out everything that does not equal a given value, at most that value remains.
This is equivalent to `filter_eq` with the equality the other way.
-/
theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) :
(s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b)
theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) :
(s.filter fun a => b ≠ a) = s.erase b := by
ext
simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not]
tauto
theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b :=
_root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b)
theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) :
s.filter p ∪ s.filter q = s :=
(filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial
theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) :
(s.filter p ∪ s.filter fun a => ¬p a) = s :=
filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p
end
end Filter
/-! ### range -/
section Range
open Nat
variable {n m l : ℕ}
@[simp]
theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by
convert filter_eq (range n) m using 2
· ext
rw [eq_comm]
· simp
end Range
end Finset
/-! ### dedup on list and multiset -/
namespace Multiset
variable [DecidableEq α] {s t : Multiset α}
@[simp]
theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t :=
Finset.ext <| by simp
@[simp]
theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by
ext; simp
@[simp]
theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 :=
Finset.val_inj.symm.trans Multiset.dedup_eq_zero
@[simp]
theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by
simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty
@[simp]
theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] :
Multiset.toFinset (s.filter p) = s.toFinset.filter p := by
ext; simp
end Multiset
namespace List
variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β}
{s : Finset α} {t : Set β} {t' : Finset β}
@[simp]
theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by
ext
simp
@[simp]
theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by
ext
simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff
@[simp]
theorem toFinset_filter (s : List α) (p : α → Bool) :
(s.filter p).toFinset = s.toFinset.filter (p ·) := by
ext; simp [List.mem_filter]
end List
namespace Finset
section ToList
@[simp]
theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ :=
Multiset.toList_eq_nil.trans val_eq_zero
theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by simp
@[simp]
theorem toList_empty : (∅ : Finset α).toList = [] :=
toList_eq_nil.mpr rfl
theorem Nonempty.toList_ne_nil {s : Finset α} (hs : s.Nonempty) : s.toList ≠ [] :=
mt toList_eq_nil.mp hs.ne_empty
theorem Nonempty.not_empty_toList {s : Finset α} (hs : s.Nonempty) : ¬s.toList.isEmpty :=
mt empty_toList.mp hs.ne_empty
end ToList
/-! ### choose -/
section Choose
variable (p : α → Prop) [DecidablePred p] (l : Finset α)
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the corresponding subtype. -/
def chooseX (hp : ∃! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } :=
Multiset.chooseX p l.val hp
/-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of
`l` satisfying `p` this unique element, as an element of the ambient type. -/
def choose (hp : ∃! a, a ∈ l ∧ p a) : α :=
chooseX p l hp
theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) :=
(chooseX p l hp).property
theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l :=
(choose_spec _ _ _).1
theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) :=
(choose_spec _ _ _).2
end Choose
end Finset
namespace Equiv
variable [DecidableEq α] {s t : Finset α}
open Finset
/-- The disjoint union of finsets is a sum -/
def Finset.union (s t : Finset α) (h : Disjoint s t) :
s ⊕ t ≃ (s ∪ t : Finset α) :=
Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm
@[simp]
theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) :
Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ :=
rfl
@[simp]
theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) :
Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ :=
rfl
/-- The type of dependent functions on the disjoint union of finsets `s ∪ t` is equivalent to the
type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/
def piFinsetUnion {ι} [DecidableEq ι] (α : ι → Type*) {s t : Finset ι} (h : Disjoint s t) :
((∀ i : s, α i) × ∀ i : t, α i) ≃ ∀ i : (s ∪ t : Finset ι), α i :=
let e := Equiv.Finset.union s t h
sumPiEquivProdPi (fun b ↦ α (e b)) |>.symm.trans (.piCongrLeft (fun i : ↥(s ∪ t) ↦ α i) e)
/-- A finset is equivalent to its coercion as a set. -/
def _root_.Finset.equivToSet (s : Finset α) : s ≃ s.toSet where
toFun a := ⟨a.1, mem_coe.2 a.2⟩
invFun a := ⟨a.1, mem_coe.1 a.2⟩
left_inv := fun _ ↦ rfl
right_inv := fun _ ↦ rfl
end Equiv
namespace Multiset
variable [DecidableEq α]
@[simp]
lemma toFinset_replicate (n : ℕ) (a : α) :
(replicate n a).toFinset = if n = 0 then ∅ else {a} := by
ext x
simp only [mem_toFinset, Finset.mem_singleton, mem_replicate]
split_ifs with hn <;> simp [hn]
end Multiset
| Mathlib/Data/Finset/Basic.lean | 1,727 | 1,728 | |
/-
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.Nilpotent
import Mathlib.Algebra.Lie.Normalizer
/-!
# Cartan subalgebras
Cartan subalgebras are one of the most important concepts in Lie theory. We define them here.
The standard example is the set of diagonal matrices in the Lie algebra of matrices.
## Main definitions
* `LieSubmodule.IsUcsLimit`
* `LieSubalgebra.IsCartanSubalgebra`
* `LieSubalgebra.isCartanSubalgebra_iff_isUcsLimit`
## Tags
lie subalgebra, normalizer, idealizer, cartan subalgebra
-/
universe u v w w₁ w₂
variable {R : Type u} {L : Type v}
variable [CommRing R] [LieRing L] [LieAlgebra R L] (H : LieSubalgebra R L)
/-- Given a Lie module `M` of a Lie algebra `L`, `LieSubmodule.IsUcsLimit` is the proposition
that a Lie submodule `N ⊆ M` is the limiting value for the upper central series.
This is a characteristic property of Cartan subalgebras with the roles of `L`, `M`, `N` played by
`H`, `L`, `H`, respectively. See `LieSubalgebra.isCartanSubalgebra_iff_isUcsLimit`. -/
def LieSubmodule.IsUcsLimit {M : Type*} [AddCommGroup M] [Module R M] [LieRingModule L M]
[LieModule R L M] (N : LieSubmodule R L M) : Prop :=
∃ k, ∀ l, k ≤ l → (⊥ : LieSubmodule R L M).ucs l = N
namespace LieSubalgebra
/-- A Cartan subalgebra is a nilpotent, self-normalizing subalgebra.
A _splitting_ Cartan subalgebra can be defined by mixing in `LieModule.IsTriangularizable R H L`. -/
class IsCartanSubalgebra : Prop where
nilpotent : LieRing.IsNilpotent H
self_normalizing : H.normalizer = H
instance [H.IsCartanSubalgebra] : LieRing.IsNilpotent H :=
IsCartanSubalgebra.nilpotent
@[simp]
theorem normalizer_eq_self_of_isCartanSubalgebra (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
H.toLieSubmodule.normalizer = H.toLieSubmodule := by
rw [← LieSubmodule.toSubmodule_inj, coe_normalizer_eq_normalizer,
IsCartanSubalgebra.self_normalizing, coe_toLieSubmodule]
@[simp]
theorem ucs_eq_self_of_isCartanSubalgebra (H : LieSubalgebra R L) [H.IsCartanSubalgebra] (k : ℕ) :
H.toLieSubmodule.ucs k = H.toLieSubmodule := by
induction k with
| zero => simp
| succ k ih => simp [ih]
theorem isCartanSubalgebra_iff_isUcsLimit : H.IsCartanSubalgebra ↔ H.toLieSubmodule.IsUcsLimit := by
constructor
· intro h
have h₁ : LieRing.IsNilpotent H := by infer_instance
obtain ⟨k, hk⟩ := H.toLieSubmodule.isNilpotent_iff_exists_self_le_ucs.mp h₁
replace hk : H.toLieSubmodule = LieSubmodule.ucs k ⊥ :=
le_antisymm hk
(LieSubmodule.ucs_le_of_normalizer_eq_self H.normalizer_eq_self_of_isCartanSubalgebra k)
refine ⟨k, fun l hl => ?_⟩
rw [← Nat.sub_add_cancel hl, LieSubmodule.ucs_add, ← hk,
LieSubalgebra.ucs_eq_self_of_isCartanSubalgebra]
· rintro ⟨k, hk⟩
exact
{ nilpotent := by
dsimp only [LieRing.IsNilpotent]
-- The instance for the second `H` in the goal is `lieRingSelfModule`
-- but `rw` expects it to be `H.toLieSubmodule.instLieRingModuleSubtypeMem`,
-- and these are not reducibly defeq.
erw [H.toLieSubmodule.isNilpotent_iff_exists_lcs_eq_bot]
use k
rw [_root_.eq_bot_iff, LieSubmodule.lcs_le_iff, hk k (le_refl k)]
self_normalizing := by
have hk' := hk (k + 1) k.le_succ
rw [LieSubmodule.ucs_succ, hk k (le_refl k)] at hk'
rw [← LieSubalgebra.toSubmodule_inj, ← LieSubalgebra.coe_normalizer_eq_normalizer,
hk', LieSubalgebra.coe_toLieSubmodule] }
lemma ne_bot_of_isCartanSubalgebra [Nontrivial L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
H ≠ ⊥ := by
intro e
obtain ⟨x, hx⟩ := exists_ne (0 : L)
| have : x ∈ H.normalizer := by simp [LieSubalgebra.mem_normalizer_iff, e]
exact hx (by rwa [LieSubalgebra.IsCartanSubalgebra.self_normalizing, e] at this)
instance (priority := 500) [Nontrivial L] (H : LieSubalgebra R L) [H.IsCartanSubalgebra] :
Nontrivial H := by
refine (subsingleton_or_nontrivial H).elim (fun inst ↦ False.elim ?_) id
| Mathlib/Algebra/Lie/CartanSubalgebra.lean | 97 | 102 |
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.Shift.ShiftSequence
import Mathlib.CategoryTheory.Triangulated.Functor
import Mathlib.CategoryTheory.Triangulated.Subcategory
import Mathlib.Algebra.Homology.ExactSequence
/-! # Homological functors
In this file, given a functor `F : C ⥤ A` from a pretriangulated category to
an abelian category, we define the type class `F.IsHomological`, which is the property
that `F` sends distinguished triangles in `C` to exact sequences in `A`.
If `F` has been endowed with `[F.ShiftSequence ℤ]`, then we may think
of the functor `F` as a `H^0`, and then the `H^n` functors are the functors `F.shift n : C ⥤ A`:
we have isomorphisms `(F.shift n).obj X ≅ F.obj (X⟦n⟧)`, but through the choice of this
"shift sequence", the user may provide functors with better definitional properties.
Given a triangle `T` in `C`, we define a connecting homomorphism
`F.homologySequenceδ T n₀ n₁ h : (F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁`
under the assumption `h : n₀ + 1 = n₁`. When `T` is distinguished, this connecting
homomorphism is part of a long exact sequence
`... ⟶ (F.shift n₀).obj T.obj₁ ⟶ (F.shift n₀).obj T.obj₂ ⟶ (F.shift n₀).obj T.obj₃ ⟶ ...`
The exactness of this long exact sequence is given by three lemmas
`F.homologySequence_exact₁`, `F.homologySequence_exact₂` and `F.homologySequence_exact₃`.
If `F` is a homological functor, we define the strictly full triangulated subcategory
`F.homologicalKernel`: it consists of objects `X : C` such that for all `n : ℤ`,
`(F.shift n).obj X` (or `F.obj (X⟦n⟧)`) is zero. We show that a morphism `f` in `C`
belongs to `F.homologicalKernel.W` (i.e. the cone of `f` is in this kernel) iff
`(F.shift n).map f` is an isomorphism for all `n : ℤ`.
Note: depending on the sources, homological functors are sometimes
called cohomological functors, while certain authors use "cohomological functors"
for "contravariant" functors (i.e. functors `Cᵒᵖ ⥤ A`).
## TODO
* The long exact sequence in homology attached to an homological functor.
## References
* [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996]
-/
namespace CategoryTheory
open Category Limits Pretriangulated ZeroObject Preadditive
variable {C D A : Type*} [Category C] [HasShift C ℤ]
[Category D] [HasZeroObject D] [HasShift D ℤ] [Preadditive D]
[∀ (n : ℤ), (CategoryTheory.shiftFunctor D n).Additive] [Pretriangulated D]
[Category A]
namespace Functor
variable (F : C ⥤ A)
section Pretriangulated
variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
[Pretriangulated C] [Abelian A]
/-- A functor from a pretriangulated category to an abelian category is an homological functor
if it sends distinguished triangles to exact sequences. -/
class IsHomological : Prop extends F.PreservesZeroMorphisms where
exact (T : Triangle C) (hT : T ∈ distTriang C) :
((shortComplexOfDistTriangle T hT).map F).Exact
lemma map_distinguished_exact [F.IsHomological] (T : Triangle C) (hT : T ∈ distTriang C) :
((shortComplexOfDistTriangle T hT).map F).Exact :=
IsHomological.exact _ hT
instance (L : C ⥤ D) (F : D ⥤ A) [L.CommShift ℤ] [L.IsTriangulated] [F.IsHomological] :
(L ⋙ F).IsHomological where
exact T hT := F.map_distinguished_exact _ (L.map_distinguished T hT)
lemma IsHomological.mk' [F.PreservesZeroMorphisms]
(hF : ∀ (T : Pretriangulated.Triangle C) (hT : T ∈ distTriang C),
∃ (T' : Pretriangulated.Triangle C) (e : T ≅ T'),
((shortComplexOfDistTriangle T' (isomorphic_distinguished _ hT _ e.symm)).map F).Exact) :
F.IsHomological where
exact T hT := by
obtain ⟨T', e, h'⟩ := hF T hT
exact (ShortComplex.exact_iff_of_iso
(F.mapShortComplex.mapIso ((shortComplexOfDistTriangleIsoOfIso e hT)))).2 h'
lemma IsHomological.of_iso {F₁ F₂ : C ⥤ A} [F₁.IsHomological] (e : F₁ ≅ F₂) :
F₂.IsHomological :=
have := preservesZeroMorphisms_of_iso e
⟨fun T hT => ShortComplex.exact_of_iso (ShortComplex.mapNatIso _ e)
(F₁.map_distinguished_exact T hT)⟩
/-- The kernel of a homological functor `F : C ⥤ A` is the strictly full
triangulated subcategory consisting of objects `X` such that
for all `n : ℤ`, `F.obj (X⟦n⟧)` is zero. -/
def homologicalKernel [F.IsHomological] :
Triangulated.Subcategory C := Triangulated.Subcategory.mk'
(fun X => ∀ (n : ℤ), IsZero (F.obj (X⟦n⟧)))
(fun n => by
rw [IsZero.iff_id_eq_zero, ← F.map_id, ← Functor.map_id,
id_zero, Functor.map_zero, Functor.map_zero])
(fun X a hX b => IsZero.of_iso (hX (a + b)) (F.mapIso ((shiftFunctorAdd C a b).app X).symm))
(fun T hT h₁ h₃ n => (F.map_distinguished_exact _
(Triangle.shift_distinguished T hT n)).isZero_of_both_zeros
(IsZero.eq_of_src (h₁ n) _ _) (IsZero.eq_of_tgt (h₃ n) _ _))
instance [F.IsHomological] : F.homologicalKernel.P.IsClosedUnderIsomorphisms := by
dsimp only [homologicalKernel]
infer_instance
lemma mem_homologicalKernel_iff [F.IsHomological] [F.ShiftSequence ℤ] (X : C) :
F.homologicalKernel.P X ↔ ∀ (n : ℤ), IsZero ((F.shift n).obj X) := by
simp only [← fun (n : ℤ) => Iso.isZero_iff ((F.isoShift n).app X)]
rfl
noncomputable instance (priority := 100) [F.IsHomological] :
PreservesLimitsOfShape (Discrete WalkingPair) F := by
suffices ∀ (X₁ X₂ : C), PreservesLimit (pair X₁ X₂) F from
⟨fun {X} => preservesLimit_of_iso_diagram F (diagramIsoPair X).symm⟩
intro X₁ X₂
have : HasBinaryBiproduct (F.obj X₁) (F.obj X₂) := HasBinaryBiproducts.has_binary_biproduct _ _
have : Mono (F.biprodComparison X₁ X₂) := by
rw [mono_iff_cancel_zero]
intro Z f hf
let S := (ShortComplex.mk _ _ (biprod.inl_snd (X := X₁) (Y := X₂))).map F
have : Mono S.f := by dsimp [S]; infer_instance
have ex : S.Exact := F.map_distinguished_exact _ (binaryBiproductTriangle_distinguished X₁ X₂)
obtain ⟨g, rfl⟩ := ex.lift' f (by simpa using hf =≫ biprod.snd)
dsimp [S] at hf ⊢
replace hf := hf =≫ biprod.fst
simp only [assoc, biprodComparison_fst, zero_comp, ← F.map_comp, biprod.inl_fst,
F.map_id, comp_id] at hf
rw [hf, zero_comp]
have : PreservesBinaryBiproduct X₁ X₂ F := preservesBinaryBiproduct_of_mono_biprodComparison _
apply Limits.preservesBinaryProduct_of_preservesBinaryBiproduct
instance (priority := 100) [F.IsHomological] : F.Additive :=
F.additive_of_preserves_binary_products
lemma isHomological_of_localization (L : C ⥤ D)
[L.CommShift ℤ] [L.IsTriangulated] [L.mapArrow.EssSurj] (F : D ⥤ A)
(G : C ⥤ A) (e : L ⋙ F ≅ G) [G.IsHomological] :
F.IsHomological := by
have : F.PreservesZeroMorphisms := preservesZeroMorphisms_of_map_zero_object
(F.mapIso L.mapZeroObject.symm ≪≫ e.app _ ≪≫ G.mapZeroObject)
have : (L ⋙ F).IsHomological := IsHomological.of_iso e.symm
refine IsHomological.mk' _ (fun T hT => ?_)
rw [L.distTriang_iff] at hT
obtain ⟨T₀, e, hT₀⟩ := hT
exact ⟨L.mapTriangle.obj T₀, e, (L ⋙ F).map_distinguished_exact _ hT₀⟩
end Pretriangulated
section
/-- The connecting homomorphism in the long exact sequence attached to an homological
functor and a distinguished triangle. -/
noncomputable def homologySequenceδ
[F.ShiftSequence ℤ] (T : Triangle C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
(F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁ :=
F.shiftMap T.mor₃ n₀ n₁ (by rw [add_comm 1, h])
variable {T T'}
@[reassoc]
lemma homologySequenceδ_naturality
[F.ShiftSequence ℤ] (T T' : Triangle C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
(F.shift n₀).map φ.hom₃ ≫ F.homologySequenceδ T' n₀ n₁ h =
F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map φ.hom₁ := by
dsimp only [homologySequenceδ]
rw [← shiftMap_comp', ← φ.comm₃, shiftMap_comp]
variable (T)
variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
[Pretriangulated C] [Abelian A] [F.IsHomological]
variable [F.ShiftSequence ℤ] (T T' : Triangle C) (hT : T ∈ distTriang C)
(hT' : T' ∈ distTriang C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁)
section
include hT
@[reassoc]
lemma comp_homologySequenceδ :
(F.shift n₀).map T.mor₂ ≫ F.homologySequenceδ T n₀ n₁ h = 0 := by
dsimp only [homologySequenceδ]
rw [← F.shiftMap_comp', comp_distTriang_mor_zero₂₃ _ hT, shiftMap_zero]
@[reassoc]
lemma homologySequenceδ_comp :
F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map T.mor₁ = 0 := by
dsimp only [homologySequenceδ]
| rw [← F.shiftMap_comp, comp_distTriang_mor_zero₃₁ _ hT, shiftMap_zero]
@[reassoc]
lemma homologySequence_comp :
(F.shift n₀).map T.mor₁ ≫ (F.shift n₀).map T.mor₂ = 0 := by
rw [← Functor.map_comp, comp_distTriang_mor_zero₁₂ _ hT, Functor.map_zero]
| Mathlib/CategoryTheory/Triangulated/HomologicalFunctor.lean | 197 | 202 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.Find
import Mathlib.Data.Stream.Init
import Mathlib.Tactic.Common
/-!
# Coinductive formalization of unbounded computations.
This file provides a `Computation` type where `Computation α` is the type of
unbounded computations returning `α`.
-/
open Function
universe u v w
/-
coinductive Computation (α : Type u) : Type u
| pure : α → Computation α
| think : Computation α → Computation α
-/
/-- `Computation α` is the type of unbounded computations returning `α`.
An element of `Computation α` is an infinite sequence of `Option α` such
that if `f n = some a` for some `n` then it is constantly `some a` after that. -/
def Computation (α : Type u) : Type u :=
{ f : Stream' (Option α) // ∀ ⦃n a⦄, f n = some a → f (n + 1) = some a }
namespace Computation
variable {α : Type u} {β : Type v} {γ : Type w}
-- constructors
/-- `pure a` is the computation that immediately terminates with result `a`. -/
def pure (a : α) : Computation α :=
⟨Stream'.const (some a), fun _ _ => id⟩
instance : CoeTC α (Computation α) :=
⟨pure⟩
-- note [use has_coe_t]
/-- `think c` is the computation that delays for one "tick" and then performs
computation `c`. -/
def think (c : Computation α) : Computation α :=
⟨Stream'.cons none c.1, fun n a h => by
rcases n with - | n
· contradiction
· exact c.2 h⟩
/-- `thinkN c n` is the computation that delays for `n` ticks and then performs
computation `c`. -/
def thinkN (c : Computation α) : ℕ → Computation α
| 0 => c
| n + 1 => think (thinkN c n)
-- check for immediate result
/-- `head c` is the first step of computation, either `some a` if `c = pure a`
or `none` if `c = think c'`. -/
def head (c : Computation α) : Option α :=
c.1.head
-- one step of computation
/-- `tail c` is the remainder of computation, either `c` if `c = pure a`
or `c'` if `c = think c'`. -/
def tail (c : Computation α) : Computation α :=
⟨c.1.tail, fun _ _ h => c.2 h⟩
/-- `empty α` is the computation that never returns, an infinite sequence of
`think`s. -/
def empty (α) : Computation α :=
⟨Stream'.const none, fun _ _ => id⟩
instance : Inhabited (Computation α) :=
⟨empty _⟩
/-- `runFor c n` evaluates `c` for `n` steps and returns the result, or `none`
if it did not terminate after `n` steps. -/
def runFor : Computation α → ℕ → Option α :=
Subtype.val
/-- `destruct c` is the destructor for `Computation α` as a coinductive type.
It returns `inl a` if `c = pure a` and `inr c'` if `c = think c'`. -/
def destruct (c : Computation α) : α ⊕ (Computation α) :=
match c.1 0 with
| none => Sum.inr (tail c)
| some a => Sum.inl a
/-- `run c` is an unsound meta function that runs `c` to completion, possibly
resulting in an infinite loop in the VM. -/
unsafe def run : Computation α → α
| c =>
match destruct c with
| Sum.inl a => a
| Sum.inr ca => run ca
theorem destruct_eq_pure {s : Computation α} {a : α} : destruct s = Sum.inl a → s = pure a := by
dsimp [destruct]
induction' f0 : s.1 0 with _ <;> intro h
· contradiction
· apply Subtype.eq
funext n
induction' n with n IH
· injection h with h'
rwa [h'] at f0
· exact s.2 IH
theorem destruct_eq_think {s : Computation α} {s'} : destruct s = Sum.inr s' → s = think s' := by
dsimp [destruct]
induction' f0 : s.1 0 with a' <;> intro h
· injection h with h'
rw [← h']
obtain ⟨f, al⟩ := s
apply Subtype.eq
dsimp [think, tail]
rw [← f0]
exact (Stream'.eta f).symm
· contradiction
@[simp]
theorem destruct_pure (a : α) : destruct (pure a) = Sum.inl a :=
rfl
@[simp]
theorem destruct_think : ∀ s : Computation α, destruct (think s) = Sum.inr s
| ⟨_, _⟩ => rfl
@[simp]
theorem destruct_empty : destruct (empty α) = Sum.inr (empty α) :=
rfl
@[simp]
theorem head_pure (a : α) : head (pure a) = some a :=
rfl
@[simp]
theorem head_think (s : Computation α) : head (think s) = none :=
rfl
@[simp]
theorem head_empty : head (empty α) = none :=
rfl
@[simp]
theorem tail_pure (a : α) : tail (pure a) = pure a :=
rfl
@[simp]
theorem tail_think (s : Computation α) : tail (think s) = s := by
obtain ⟨f, al⟩ := s; apply Subtype.eq; dsimp [tail, think]
@[simp]
theorem tail_empty : tail (empty α) = empty α :=
rfl
theorem think_empty : empty α = think (empty α) :=
destruct_eq_think destruct_empty
/-- Recursion principle for computations, compare with `List.recOn`. -/
def recOn {C : Computation α → Sort v} (s : Computation α) (h1 : ∀ a, C (pure a))
(h2 : ∀ s, C (think s)) : C s :=
match H : destruct s with
| Sum.inl v => by
rw [destruct_eq_pure H]
apply h1
| Sum.inr v => match v with
| ⟨a, s'⟩ => by
rw [destruct_eq_think H]
apply h2
/-- Corecursor constructor for `corec` -/
def Corec.f (f : β → α ⊕ β) : α ⊕ β → Option α × (α ⊕ β)
| Sum.inl a => (some a, Sum.inl a)
| Sum.inr b =>
(match f b with
| Sum.inl a => some a
| Sum.inr _ => none,
f b)
/-- `corec f b` is the corecursor for `Computation α` as a coinductive type.
If `f b = inl a` then `corec f b = pure a`, and if `f b = inl b'` then
`corec f b = think (corec f b')`. -/
def corec (f : β → α ⊕ β) (b : β) : Computation α := by
refine ⟨Stream'.corec' (Corec.f f) (Sum.inr b), fun n a' h => ?_⟩
rw [Stream'.corec'_eq]
change Stream'.corec' (Corec.f f) (Corec.f f (Sum.inr b)).2 n = some a'
revert h; generalize Sum.inr b = o; revert o
induction' n with n IH <;> intro o
· change (Corec.f f o).1 = some a' → (Corec.f f (Corec.f f o).2).1 = some a'
rcases o with _ | b <;> intro h
· exact h
unfold Corec.f at *; split <;> simp_all
· rw [Stream'.corec'_eq (Corec.f f) (Corec.f f o).2, Stream'.corec'_eq (Corec.f f) o]
exact IH (Corec.f f o).2
/-- left map of `⊕` -/
def lmap (f : α → β) : α ⊕ γ → β ⊕ γ
| Sum.inl a => Sum.inl (f a)
| Sum.inr b => Sum.inr b
/-- right map of `⊕` -/
def rmap (f : β → γ) : α ⊕ β → α ⊕ γ
| Sum.inl a => Sum.inl a
| Sum.inr b => Sum.inr (f b)
attribute [simp] lmap rmap
@[simp]
theorem corec_eq (f : β → α ⊕ β) (b : β) : destruct (corec f b) = rmap (corec f) (f b) := by
dsimp [corec, destruct]
rw [show Stream'.corec' (Corec.f f) (Sum.inr b) 0 =
Sum.rec Option.some (fun _ ↦ none) (f b) by
dsimp [Corec.f, Stream'.corec', Stream'.corec, Stream'.map, Stream'.get, Stream'.iterate]
match (f b) with
| Sum.inl x => rfl
| Sum.inr x => rfl
]
induction' h : f b with a b'; · rfl
dsimp [Corec.f, destruct]
apply congr_arg; apply Subtype.eq
dsimp [corec, tail]
rw [Stream'.corec'_eq, Stream'.tail_cons]
dsimp [Corec.f]; rw [h]
section Bisim
variable (R : Computation α → Computation α → Prop)
/-- bisimilarity relation -/
local infixl:50 " ~ " => R
/-- Bisimilarity over a sum of `Computation`s -/
def BisimO : α ⊕ (Computation α) → α ⊕ (Computation α) → Prop
| Sum.inl a, Sum.inl a' => a = a'
| Sum.inr s, Sum.inr s' => R s s'
| _, _ => False
attribute [simp] BisimO
attribute [nolint simpNF] BisimO.eq_3
/-- Attribute expressing bisimilarity over two `Computation`s -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ → BisimO R (destruct s₁) (destruct s₂)
-- If two computations are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} (r : s₁ ~ s₂) : s₁ = s₂ := by
apply Subtype.eq
apply Stream'.eq_of_bisim fun x y => ∃ s s' : Computation α, s.1 = x ∧ s'.1 = y ∧ R s s'
· dsimp [Stream'.IsBisimulation]
intro t₁ t₂ e
match t₁, t₂, e with
| _, _, ⟨s, s', rfl, rfl, r⟩ =>
suffices head s = head s' ∧ R (tail s) (tail s') from
And.imp id (fun r => ⟨tail s, tail s', by cases s; rfl, by cases s'; rfl, r⟩) this
have h := bisim r; revert r h
apply recOn s _ _ <;> intro r' <;> apply recOn s' _ _ <;> intro a' r h
· constructor <;> dsimp at h
· rw [h]
· rw [h] at r
rw [tail_pure, tail_pure,h]
assumption
· rw [destruct_pure, destruct_think] at h
exact False.elim h
· rw [destruct_pure, destruct_think] at h
exact False.elim h
· simp_all
· exact ⟨s₁, s₂, rfl, rfl, r⟩
end Bisim
-- It's more of a stretch to use ∈ for this relation, but it
-- asserts that the computation limits to the given value.
/-- Assertion that a `Computation` limits to a given value -/
protected def Mem (s : Computation α) (a : α) :=
some a ∈ s.1
instance : Membership α (Computation α) :=
⟨Computation.Mem⟩
theorem le_stable (s : Computation α) {a m n} (h : m ≤ n) : s.1 m = some a → s.1 n = some a := by
obtain ⟨f, al⟩ := s
induction' h with n _ IH
exacts [id, fun h2 => al (IH h2)]
theorem mem_unique {s : Computation α} {a b : α} : a ∈ s → b ∈ s → a = b
| ⟨m, ha⟩, ⟨n, hb⟩ => by
injection
(le_stable s (le_max_left m n) ha.symm).symm.trans (le_stable s (le_max_right m n) hb.symm)
theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Computation α → Prop) := fun _ _ _ =>
mem_unique
/-- `Terminates s` asserts that the computation `s` eventually terminates with some value. -/
class Terminates (s : Computation α) : Prop where
/-- assertion that there is some term `a` such that the `Computation` terminates -/
term : ∃ a, a ∈ s
theorem terminates_iff (s : Computation α) : Terminates s ↔ ∃ a, a ∈ s :=
⟨fun h => h.1, Terminates.mk⟩
theorem terminates_of_mem {s : Computation α} {a : α} (h : a ∈ s) : Terminates s :=
⟨⟨a, h⟩⟩
theorem terminates_def (s : Computation α) : Terminates s ↔ ∃ n, (s.1 n).isSome :=
⟨fun ⟨⟨a, n, h⟩⟩ =>
⟨n, by
dsimp [Stream'.get] at h
rw [← h]
exact rfl⟩,
fun ⟨n, h⟩ => ⟨⟨Option.get _ h, n, (Option.eq_some_of_isSome h).symm⟩⟩⟩
theorem ret_mem (a : α) : a ∈ pure a :=
Exists.intro 0 rfl
theorem eq_of_pure_mem {a a' : α} (h : a' ∈ pure a) : a' = a :=
mem_unique h (ret_mem _)
@[simp]
theorem mem_pure_iff (a b : α) : a ∈ pure b ↔ a = b :=
⟨eq_of_pure_mem, fun h => h ▸ ret_mem _⟩
instance ret_terminates (a : α) : Terminates (pure a) :=
terminates_of_mem (ret_mem _)
theorem think_mem {s : Computation α} {a} : a ∈ s → a ∈ think s
| ⟨n, h⟩ => ⟨n + 1, h⟩
instance think_terminates (s : Computation α) : ∀ [Terminates s], Terminates (think s)
| ⟨⟨a, n, h⟩⟩ => ⟨⟨a, n + 1, h⟩⟩
theorem of_think_mem {s : Computation α} {a} : a ∈ think s → a ∈ s
| ⟨n, h⟩ => by
rcases n with - | n'
· contradiction
· exact ⟨n', h⟩
theorem of_think_terminates {s : Computation α} : Terminates (think s) → Terminates s
| ⟨⟨a, h⟩⟩ => ⟨⟨a, of_think_mem h⟩⟩
theorem not_mem_empty (a : α) : a ∉ empty α := fun ⟨n, h⟩ => by contradiction
theorem not_terminates_empty : ¬Terminates (empty α) := fun ⟨⟨a, h⟩⟩ => not_mem_empty a h
theorem eq_empty_of_not_terminates {s} (H : ¬Terminates s) : s = empty α := by
apply Subtype.eq; funext n
induction' h : s.val n with _; · rfl
refine absurd ?_ H; exact ⟨⟨_, _, h.symm⟩⟩
theorem thinkN_mem {s : Computation α} {a} : ∀ n, a ∈ thinkN s n ↔ a ∈ s
| 0 => Iff.rfl
| n + 1 => Iff.trans ⟨of_think_mem, think_mem⟩ (thinkN_mem n)
instance thinkN_terminates (s : Computation α) : ∀ [Terminates s] (n), Terminates (thinkN s n)
| ⟨⟨a, h⟩⟩, n => ⟨⟨a, (thinkN_mem n).2 h⟩⟩
theorem of_thinkN_terminates (s : Computation α) (n) : Terminates (thinkN s n) → Terminates s
| ⟨⟨a, h⟩⟩ => ⟨⟨a, (thinkN_mem _).1 h⟩⟩
/-- `Promises s a`, or `s ~> a`, asserts that although the computation `s`
may not terminate, if it does, then the result is `a`. -/
def Promises (s : Computation α) (a : α) : Prop :=
∀ ⦃a'⦄, a' ∈ s → a = a'
/-- `Promises s a`, or `s ~> a`, asserts that although the computation `s`
may not terminate, if it does, then the result is `a`. -/
scoped infixl:50 " ~> " => Promises
theorem mem_promises {s : Computation α} {a : α} : a ∈ s → s ~> a := fun h _ => mem_unique h
theorem empty_promises (a : α) : empty α ~> a := fun _ h => absurd h (not_mem_empty _)
section get
variable (s : Computation α) [h : Terminates s]
/-- `length s` gets the number of steps of a terminating computation -/
def length : ℕ :=
Nat.find ((terminates_def _).1 h)
/-- `get s` returns the result of a terminating computation -/
def get : α :=
Option.get _ (Nat.find_spec <| (terminates_def _).1 h)
theorem get_mem : get s ∈ s :=
Exists.intro (length s) (Option.eq_some_of_isSome _).symm
theorem get_eq_of_mem {a} : a ∈ s → get s = a :=
mem_unique (get_mem _)
theorem mem_of_get_eq {a} : get s = a → a ∈ s := by intro h; rw [← h]; apply get_mem
@[simp]
theorem get_think : get (think s) = get s :=
get_eq_of_mem _ <|
let ⟨n, h⟩ := get_mem s
⟨n + 1, h⟩
@[simp]
theorem get_thinkN (n) : get (thinkN s n) = get s :=
get_eq_of_mem _ <| (thinkN_mem _).2 (get_mem _)
theorem get_promises : s ~> get s := fun _ => get_eq_of_mem _
theorem mem_of_promises {a} (p : s ~> a) : a ∈ s := by
obtain ⟨h⟩ := h
obtain ⟨a', h⟩ := h
rw [p h]
exact h
theorem get_eq_of_promises {a} : s ~> a → get s = a :=
get_eq_of_mem _ ∘ mem_of_promises _
end get
/-- `Results s a n` completely characterizes a terminating computation:
it asserts that `s` terminates after exactly `n` steps, with result `a`. -/
def Results (s : Computation α) (a : α) (n : ℕ) :=
∃ h : a ∈ s, @length _ s (terminates_of_mem h) = n
theorem results_of_terminates (s : Computation α) [_T : Terminates s] :
Results s (get s) (length s) :=
⟨get_mem _, rfl⟩
theorem results_of_terminates' (s : Computation α) [T : Terminates s] {a} (h : a ∈ s) :
Results s a (length s) := by rw [← get_eq_of_mem _ h]; apply results_of_terminates
theorem Results.mem {s : Computation α} {a n} : Results s a n → a ∈ s
| ⟨m, _⟩ => m
theorem Results.terminates {s : Computation α} {a n} (h : Results s a n) : Terminates s :=
terminates_of_mem h.mem
theorem Results.length {s : Computation α} {a n} [_T : Terminates s] : Results s a n → length s = n
| ⟨_, h⟩ => h
theorem Results.val_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) :
a = b :=
mem_unique h1.mem h2.mem
theorem Results.len_unique {s : Computation α} {a b m n} (h1 : Results s a m) (h2 : Results s b n) :
m = n := by haveI := h1.terminates; haveI := h2.terminates; rw [← h1.length, h2.length]
theorem exists_results_of_mem {s : Computation α} {a} (h : a ∈ s) : ∃ n, Results s a n :=
haveI := terminates_of_mem h
⟨_, results_of_terminates' s h⟩
@[simp]
theorem get_pure (a : α) : get (pure a) = a :=
get_eq_of_mem _ ⟨0, rfl⟩
@[simp]
theorem length_pure (a : α) : length (pure a) = 0 :=
let h := Computation.ret_terminates a
Nat.eq_zero_of_le_zero <| Nat.find_min' ((terminates_def (pure a)).1 h) rfl
theorem results_pure (a : α) : Results (pure a) a 0 :=
⟨ret_mem a, length_pure _⟩
@[simp]
theorem length_think (s : Computation α) [h : Terminates s] : length (think s) = length s + 1 := by
apply le_antisymm
· exact Nat.find_min' _ (Nat.find_spec ((terminates_def _).1 h))
· have : (Option.isSome ((think s).val (length (think s))) : Prop) :=
Nat.find_spec ((terminates_def _).1 s.think_terminates)
revert this; rcases length (think s) with - | n <;> intro this
· simp [think, Stream'.cons] at this
· apply Nat.succ_le_succ
apply Nat.find_min'
apply this
theorem results_think {s : Computation α} {a n} (h : Results s a n) : Results (think s) a (n + 1) :=
haveI := h.terminates
⟨think_mem h.mem, by rw [length_think, h.length]⟩
theorem of_results_think {s : Computation α} {a n} (h : Results (think s) a n) :
∃ m, Results s a m ∧ n = m + 1 := by
haveI := of_think_terminates h.terminates
have := results_of_terminates' _ (of_think_mem h.mem)
exact ⟨_, this, Results.len_unique h (results_think this)⟩
@[simp]
theorem results_think_iff {s : Computation α} {a n} : Results (think s) a (n + 1) ↔ Results s a n :=
⟨fun h => by
let ⟨n', r, e⟩ := of_results_think h
injection e with h'; rwa [h'], results_think⟩
theorem results_thinkN {s : Computation α} {a m} :
∀ n, Results s a m → Results (thinkN s n) a (m + n)
| 0, h => h
| n + 1, h => results_think (results_thinkN n h)
theorem results_thinkN_pure (a : α) (n) : Results (thinkN (pure a) n) a n := by
have := results_thinkN n (results_pure a); rwa [Nat.zero_add] at this
@[simp]
theorem length_thinkN (s : Computation α) [_h : Terminates s] (n) :
length (thinkN s n) = length s + n :=
(results_thinkN n (results_of_terminates _)).length
theorem eq_thinkN {s : Computation α} {a n} (h : Results s a n) : s = thinkN (pure a) n := by
| revert s
induction n with | zero => _ | succ n IH => _ <;>
| Mathlib/Data/Seq/Computation.lean | 503 | 504 |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Complex.AbsMax
import Mathlib.Analysis.Asymptotics.SuperpolynomialDecay
/-!
# Phragmen-Lindelöf principle
In this file we prove several versions of the Phragmen-Lindelöf principle, a version of the maximum
modulus principle for an unbounded domain.
## Main statements
* `PhragmenLindelof.horizontal_strip`: the Phragmen-Lindelöf principle in a horizontal strip
`{z : ℂ | a < complex.im z < b}`;
* `PhragmenLindelof.eq_zero_on_horizontal_strip`, `PhragmenLindelof.eqOn_horizontal_strip`:
extensionality lemmas based on the Phragmen-Lindelöf principle in a horizontal strip;
* `PhragmenLindelof.vertical_strip`: the Phragmen-Lindelöf principle in a vertical strip
`{z : ℂ | a < complex.re z < b}`;
* `PhragmenLindelof.eq_zero_on_vertical_strip`, `PhragmenLindelof.eqOn_vertical_strip`:
extensionality lemmas based on the Phragmen-Lindelöf principle in a vertical strip;
* `PhragmenLindelof.quadrant_I`, `PhragmenLindelof.quadrant_II`, `PhragmenLindelof.quadrant_III`,
`PhragmenLindelof.quadrant_IV`: the Phragmen-Lindelöf principle in the coordinate quadrants;
* `PhragmenLindelof.right_half_plane_of_tendsto_zero_on_real`,
`PhragmenLindelof.right_half_plane_of_bounded_on_real`: two versions of the Phragmen-Lindelöf
principle in the right half-plane;
* `PhragmenLindelof.eq_zero_on_right_half_plane_of_superexponential_decay`,
`PhragmenLindelof.eqOn_right_half_plane_of_superexponential_decay`: extensionality lemmas based
on the Phragmen-Lindelöf principle in the right half-plane.
In the case of the right half-plane, we prove a version of the Phragmen-Lindelöf principle that is
useful for Ilyashenko's proof of the individual finiteness theorem (a polynomial vector field on the
real plane has only finitely many limit cycles).
-/
open Set Function Filter Asymptotics Metric Complex Bornology
open scoped Topology Filter Real
local notation "expR" => Real.exp
namespace PhragmenLindelof
/-!
### Auxiliary lemmas
-/
variable {E : Type*} [NormedAddCommGroup E]
/-- An auxiliary lemma that combines two double exponential estimates into a similar estimate
on the difference of the functions. -/
theorem isBigO_sub_exp_exp {a : ℝ} {f g : ℂ → E} {l : Filter ℂ} {u : ℂ → ℝ}
(hBf : ∃ c < a, ∃ B, f =O[l] fun z => expR (B * expR (c * |u z|)))
(hBg : ∃ c < a, ∃ B, g =O[l] fun z => expR (B * expR (c * |u z|))) :
∃ c < a, ∃ B, (f - g) =O[l] fun z => expR (B * expR (c * |u z|)) := by
have : ∀ {c₁ c₂ B₁ B₂}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ → ∀ z,
‖expR (B₁ * expR (c₁ * |u z|))‖ ≤ ‖expR (B₂ * expR (c₂ * |u z|))‖ := fun hc hB₀ hB z ↦ by
simp only [Real.norm_eq_abs, Real.abs_exp]; gcongr
rcases hBf with ⟨cf, hcf, Bf, hOf⟩; rcases hBg with ⟨cg, hcg, Bg, hOg⟩
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), ?_⟩
refine (hOf.trans_le <| this ?_ ?_ ?_).sub (hOg.trans_le <| this ?_ ?_ ?_)
exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _),
le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)]
/-- An auxiliary lemma that combines two “exponential of a power” estimates into a similar estimate
on the difference of the functions. -/
theorem isBigO_sub_exp_rpow {a : ℝ} {f g : ℂ → E} {l : Filter ℂ}
(hBf : ∃ c < a, ∃ B, f =O[cobounded ℂ ⊓ l] fun z => expR (B * ‖z‖ ^ c))
(hBg : ∃ c < a, ∃ B, g =O[cobounded ℂ ⊓ l] fun z => expR (B * ‖z‖ ^ c)) :
∃ c < a, ∃ B, (f - g) =O[cobounded ℂ ⊓ l] fun z => expR (B * ‖z‖ ^ c) := by
have : ∀ {c₁ c₂ B₁ B₂ : ℝ}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ →
(fun z : ℂ => expR (B₁ * ‖z‖ ^ c₁)) =O[cobounded ℂ ⊓ l]
fun z => expR (B₂ * ‖z‖ ^ c₂) := fun hc hB₀ hB ↦ .of_norm_eventuallyLE <| by
filter_upwards [(eventually_cobounded_le_norm 1).filter_mono inf_le_left] with z hz
simp only [Real.norm_eq_abs, Real.abs_exp]
gcongr; assumption
rcases hBf with ⟨cf, hcf, Bf, hOf⟩; rcases hBg with ⟨cg, hcg, Bg, hOg⟩
refine ⟨max cf cg, max_lt hcf hcg, max 0 (max Bf Bg), ?_⟩
refine (hOf.trans <| this ?_ ?_ ?_).sub (hOg.trans <| this ?_ ?_ ?_)
exacts [le_max_left _ _, le_max_left _ _, (le_max_left _ _).trans (le_max_right _ _),
le_max_right _ _, le_max_left _ _, (le_max_right _ _).trans (le_max_right _ _)]
variable [NormedSpace ℂ E] {a b C : ℝ} {f g : ℂ → E} {z : ℂ}
/-!
### Phragmen-Lindelöf principle in a horizontal strip
-/
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < π / (b - a)`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of `U`.
Then `‖f z‖` is bounded by the same constant on the closed strip
`{z : ℂ | a ≤ im z ≤ b}`. Moreover, it suffices to verify the second assumption
only for sufficiently large values of `|re z|`.
-/
theorem horizontal_strip (hfd : DiffContOnCl ℂ f (im ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(hle_a : ∀ z : ℂ, im z = a → ‖f z‖ ≤ C) (hle_b : ∀ z, im z = b → ‖f z‖ ≤ C) (hza : a ≤ im z)
(hzb : im z ≤ b) : ‖f z‖ ≤ C := by
-- If `im z = a` or `im z = b`, then we apply `hle_a` or `hle_b`, otherwise `im z ∈ Ioo a b`.
rw [le_iff_eq_or_lt] at hza hzb
rcases hza with hza | hza; · exact hle_a _ hza.symm
rcases hzb with hzb | hzb; · exact hle_b _ hzb
wlog hC₀ : 0 < C generalizing C
· refine le_of_forall_gt_imp_ge_of_dense fun C' hC' => this (fun w hw => ?_) (fun w hw => ?_) ?_
· exact (hle_a _ hw).trans hC'.le
· exact (hle_b _ hw).trans hC'.le
· refine ((norm_nonneg (f (a * I))).trans (hle_a _ ?_)).trans_lt hC'
rw [mul_I_im, ofReal_re]
-- After a change of variables, we deal with the strip `a - b < im z < a + b` instead
-- of `a < im z < b`
obtain ⟨a, b, rfl, rfl⟩ : ∃ a' b', a = a' - b' ∧ b = a' + b' :=
⟨(a + b) / 2, (b - a) / 2, by ring, by ring⟩
have hab : a - b < a + b := hza.trans hzb
have hb : 0 < b := by simpa only [sub_eq_add_neg, add_lt_add_iff_left, neg_lt_self_iff] using hab
rw [add_sub_sub_cancel, ← two_mul, div_mul_eq_div_div] at hB
have hπb : 0 < π / 2 / b := div_pos Real.pi_div_two_pos hb
-- Choose some `c B : ℝ` satisfying `hB`, then choose `max c 0 < d < π / 2 / b`.
rcases hB with ⟨c, hc, B, hO⟩
obtain ⟨d, ⟨hcd, hd₀⟩, hd⟩ : ∃ d, (c < d ∧ 0 < d) ∧ d < π / 2 / b := by
simpa only [max_lt_iff] using exists_between (max_lt hc hπb)
have hb' : d * b < π / 2 := (lt_div_iff₀ hb).1 hd
set aff := (fun w => d * (w - a * I) : ℂ → ℂ)
set g := fun (ε : ℝ) (w : ℂ) => exp (ε * (exp (aff w) + exp (-aff w)))
/- Since `g ε z → 1` as `ε → 0⁻`, it suffices to prove that `‖g ε z • f z‖ ≤ C`
for all negative `ε`. -/
suffices ∀ᶠ ε : ℝ in 𝓝[<] (0 : ℝ), ‖g ε z • f z‖ ≤ C by
refine le_of_tendsto (Tendsto.mono_left ?_ nhdsWithin_le_nhds) this
apply ((continuous_ofReal.mul continuous_const).cexp.smul continuous_const).norm.tendsto'
simp
filter_upwards [self_mem_nhdsWithin] with ε ε₀; change ε < 0 at ε₀
-- An upper estimate on `‖g ε w‖` that will be used in two branches of the proof.
obtain ⟨δ, δ₀, hδ⟩ :
∃ δ : ℝ,
δ < 0 ∧ ∀ ⦃w⦄, im w ∈ Icc (a - b) (a + b) → ‖g ε w‖ ≤ expR (δ * expR (d * |re w|)) := by
refine
⟨ε * Real.cos (d * b),
mul_neg_of_neg_of_pos ε₀
(Real.cos_pos_of_mem_Ioo <| abs_lt.1 <| (abs_of_pos (mul_pos hd₀ hb)).symm ▸ hb'),
fun w hw => ?_⟩
replace hw : |im (aff w)| ≤ d * b := by
rw [← Real.closedBall_eq_Icc] at hw
rwa [im_ofReal_mul, sub_im, mul_I_im, ofReal_re, _root_.abs_mul, abs_of_pos hd₀,
mul_le_mul_left hd₀]
simpa only [aff, re_ofReal_mul, _root_.abs_mul, abs_of_pos hd₀, sub_re, mul_I_re, ofReal_im,
zero_mul, neg_zero, sub_zero] using
norm_exp_mul_exp_add_exp_neg_le_of_abs_im_le ε₀.le hw hb'.le
-- `abs (g ε w) ≤ 1` on the lines `w.im = a ± b` (actually, it holds everywhere in the strip)
have hg₁ : ∀ w, im w = a - b ∨ im w = a + b → ‖g ε w‖ ≤ 1 := by
refine fun w hw => (hδ <| hw.by_cases ?_ ?_).trans (Real.exp_le_one_iff.2 ?_)
exacts [fun h => h.symm ▸ left_mem_Icc.2 hab.le, fun h => h.symm ▸ right_mem_Icc.2 hab.le,
mul_nonpos_of_nonpos_of_nonneg δ₀.le (Real.exp_pos _).le]
/- Our apriori estimate on `f` implies that `g ε w • f w → 0` as `|w.re| → ∞` along the strip. In
particular, its norm is less than or equal to `C` for sufficiently large `|w.re|`. -/
obtain ⟨R, hzR, hR⟩ :
∃ R : ℝ, |z.re| < R ∧ ∀ w, |re w| = R → im w ∈ Ioo (a - b) (a + b) → ‖g ε w • f w‖ ≤ C := by
refine ((eventually_gt_atTop _).and ?_).exists
rcases hO.exists_pos with ⟨A, hA₀, hA⟩
simp only [isBigOWith_iff, eventually_inf_principal, eventually_comap, mem_Ioo, ← abs_lt,
mem_preimage, (· ∘ ·), Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] at hA
suffices
Tendsto (fun R => expR (δ * expR (d * R) + B * expR (c * R) + Real.log A)) atTop (𝓝 0) by
filter_upwards [this.eventually (ge_mem_nhds hC₀), hA] with R hR Hle w hre him
calc
‖g ε w • f w‖ ≤ expR (δ * expR (d * R) + B * expR (c * R) + Real.log A) := ?_
_ ≤ C := hR
rw [norm_smul, Real.exp_add, ← hre, Real.exp_add, Real.exp_log hA₀, mul_assoc, mul_comm _ A]
gcongr
exacts [hδ <| Ioo_subset_Icc_self him, Hle _ hre him]
refine Real.tendsto_exp_atBot.comp ?_
suffices H : Tendsto (fun R => δ + B * (expR ((d - c) * R))⁻¹) atTop (𝓝 (δ + B * 0)) by
rw [mul_zero, add_zero] at H
refine Tendsto.atBot_add ?_ tendsto_const_nhds
simpa only [id, (· ∘ ·), add_mul, mul_assoc, ← div_eq_inv_mul, ← Real.exp_sub, ← sub_mul,
sub_sub_cancel]
using H.neg_mul_atTop δ₀ <| Real.tendsto_exp_atTop.comp <| tendsto_id.const_mul_atTop hd₀
refine tendsto_const_nhds.add (tendsto_const_nhds.mul ?_)
exact tendsto_inv_atTop_zero.comp <| Real.tendsto_exp_atTop.comp <|
tendsto_id.const_mul_atTop (sub_pos.2 hcd)
have hR₀ : 0 < R := (_root_.abs_nonneg _).trans_lt hzR
/- Finally, we apply the bounded version of the maximum modulus principle to the rectangle
`(-R, R) × (a - b, a + b)`. The function is bounded by `C` on the horizontal sides by assumption
(and because `‖g ε w‖ ≤ 1`) and on the vertical sides by the choice of `R`. -/
have hgd : Differentiable ℂ (g ε) :=
((((differentiable_id.sub_const _).const_mul _).cexp.add
((differentiable_id.sub_const _).const_mul _).neg.cexp).const_mul _).cexp
replace hd : DiffContOnCl ℂ (fun w => g ε w • f w) (Ioo (-R) R ×ℂ Ioo (a - b) (a + b)) :=
(hgd.diffContOnCl.smul hfd).mono inter_subset_right
convert norm_le_of_forall_mem_frontier_norm_le ((isBounded_Ioo _ _).reProdIm (isBounded_Ioo _ _))
hd (fun w hw => _) _
· rw [frontier_reProdIm, closure_Ioo (neg_lt_self hR₀).ne, frontier_Ioo hab, closure_Ioo hab.ne,
frontier_Ioo (neg_lt_self hR₀)] at hw
by_cases him : w.im = a - b ∨ w.im = a + b
· rw [norm_smul, ← one_mul C]
exact mul_le_mul (hg₁ _ him) (him.by_cases (hle_a _) (hle_b _)) (norm_nonneg _) zero_le_one
· replace hw : w ∈ {-R, R} ×ℂ Icc (a - b) (a + b) := hw.resolve_left fun h ↦ him h.2
have hw' := eq_endpoints_or_mem_Ioo_of_mem_Icc hw.2; rw [← or_assoc] at hw'
exact hR _ ((abs_eq hR₀.le).2 hw.1.symm) (hw'.resolve_left him)
· rw [closure_reProdIm, closure_Ioo hab.ne, closure_Ioo (neg_lt_self hR₀).ne]
exact ⟨abs_le.1 hzR.le, ⟨hza.le, hzb.le⟩⟩
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some `c < π / (b - a)`;
* `f z = 0` on the boundary of `U`.
Then `f` is equal to zero on the closed strip `{z : ℂ | a ≤ im z ≤ b}`.
-/
theorem eq_zero_on_horizontal_strip (hd : DiffContOnCl ℂ f (im ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(ha : ∀ z : ℂ, z.im = a → f z = 0) (hb : ∀ z : ℂ, z.im = b → f z = 0) :
EqOn f 0 (im ⁻¹' Icc a b) := fun _z hz =>
norm_le_zero_iff.1 <| horizontal_strip hd hB (fun z hz => (ha z hz).symm ▸ norm_zero.le)
(fun z hz => (hb z hz).symm ▸ norm_zero.le) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < im z < b}`.
Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable on `U` and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * exp(c * |re z|))` on `U` for some
`c < π / (b - a)`;
* `f z = g z` on the boundary of `U`.
Then `f` is equal to `g` on the closed strip `{z : ℂ | a ≤ im z ≤ b}`.
-/
theorem eqOn_horizontal_strip {g : ℂ → E} (hdf : DiffContOnCl ℂ f (im ⁻¹' Ioo a b))
(hBf : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(hdg : DiffContOnCl ℂ g (im ⁻¹' Ioo a b))
(hBg : ∃ c < π / (b - a), ∃ B, g =O[comap (_root_.abs ∘ re) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.re|)))
(ha : ∀ z : ℂ, z.im = a → f z = g z) (hb : ∀ z : ℂ, z.im = b → f z = g z) :
EqOn f g (im ⁻¹' Icc a b) := fun _z hz =>
sub_eq_zero.1 (eq_zero_on_horizontal_strip (hdf.sub hdg) (isBigO_sub_exp_exp hBf hBg)
(fun w hw => sub_eq_zero.2 (ha w hw)) (fun w hw => sub_eq_zero.2 (hb w hw)) hz)
/-!
### Phragmen-Lindelöf principle in a vertical strip
-/
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < π / (b - a)`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of `U`.
Then `‖f z‖` is bounded by the same constant on the closed strip
`{z : ℂ | a ≤ re z ≤ b}`. Moreover, it suffices to verify the second assumption
only for sufficiently large values of `|im z|`.
-/
theorem vertical_strip (hfd : DiffContOnCl ℂ f (re ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(hle_a : ∀ z : ℂ, re z = a → ‖f z‖ ≤ C) (hle_b : ∀ z, re z = b → ‖f z‖ ≤ C) (hza : a ≤ re z)
(hzb : re z ≤ b) : ‖f z‖ ≤ C := by
suffices ‖f (z * I * -I)‖ ≤ C by simpa [mul_assoc] using this
have H : MapsTo (· * -I) (im ⁻¹' Ioo a b) (re ⁻¹' Ioo a b) := fun z hz ↦ by simpa using hz
refine horizontal_strip (f := fun z ↦ f (z * -I))
(hfd.comp (differentiable_id.mul_const _).diffContOnCl H) ?_ (fun z hz => hle_a _ ?_)
(fun z hz => hle_b _ ?_) ?_ ?_
· rcases hB with ⟨c, hc, B, hO⟩
refine ⟨c, hc, B, ?_⟩
have : Tendsto (· * -I) (comap (|re ·|) atTop ⊓ 𝓟 (im ⁻¹' Ioo a b))
(comap (|im ·|) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)) := by
refine (tendsto_comap_iff.2 ?_).inf H.tendsto
simpa [Function.comp_def] using tendsto_comap
simpa [Function.comp_def] using hO.comp_tendsto this
all_goals simpa
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f : ℂ → E` be a function such that
* `f` is differentiable on `U` and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some `c < π / (b - a)`;
* `f z = 0` on the boundary of `U`.
Then `f` is equal to zero on the closed strip `{z : ℂ | a ≤ re z ≤ b}`.
-/
theorem eq_zero_on_vertical_strip (hd : DiffContOnCl ℂ f (re ⁻¹' Ioo a b))
(hB : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(ha : ∀ z : ℂ, re z = a → f z = 0) (hb : ∀ z : ℂ, re z = b → f z = 0) :
EqOn f 0 (re ⁻¹' Icc a b) := fun _z hz =>
norm_le_zero_iff.1 <| vertical_strip hd hB (fun z hz => (ha z hz).symm ▸ norm_zero.le)
(fun z hz => (hb z hz).symm ▸ norm_zero.le) hz.1 hz.2
/-- **Phragmen-Lindelöf principle** in a strip `U = {z : ℂ | a < re z < b}`.
Let `f g : ℂ → E` be functions such that
* `f` and `g` are differentiable on `U` and are continuous on its closure;
* `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * exp(c * |im z|))` on `U` for some
`c < π / (b - a)`;
* `f z = g z` on the boundary of `U`.
Then `f` is equal to `g` on the closed strip `{z : ℂ | a ≤ re z ≤ b}`.
-/
theorem eqOn_vertical_strip {g : ℂ → E} (hdf : DiffContOnCl ℂ f (re ⁻¹' Ioo a b))
(hBf : ∃ c < π / (b - a), ∃ B, f =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(hdg : DiffContOnCl ℂ g (re ⁻¹' Ioo a b))
(hBg : ∃ c < π / (b - a), ∃ B, g =O[comap (_root_.abs ∘ im) atTop ⊓ 𝓟 (re ⁻¹' Ioo a b)]
fun z ↦ expR (B * expR (c * |z.im|)))
(ha : ∀ z : ℂ, re z = a → f z = g z) (hb : ∀ z : ℂ, re z = b → f z = g z) :
EqOn f g (re ⁻¹' Icc a b) := fun _z hz =>
sub_eq_zero.1 (eq_zero_on_vertical_strip (hdf.sub hdg) (isBigO_sub_exp_exp hBf hBg)
(fun w hw => sub_eq_zero.2 (ha w hw)) (fun w hw => sub_eq_zero.2 (hb w hw)) hz)
/-!
### Phragmen-Lindelöf principle in coordinate quadrants
-/
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open first quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * ‖z‖ ^ c)` on the open first quadrant
for some `c < 2`;
* `‖f z‖` is bounded from above by a constant `C` on the boundary of the first quadrant.
Then `‖f z‖` is bounded from above by the same constant on the closed first quadrant. -/
nonrec theorem quadrant_I (hd : DiffContOnCl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * ‖z‖ ^ c))
(hre : ∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C) (him : ∀ x : ℝ, 0 ≤ x → ‖f (x * I)‖ ≤ C) (hz_re : 0 ≤ z.re)
(hz_im : 0 ≤ z.im) : ‖f z‖ ≤ C := by
-- The case `z = 0` is trivial.
rcases eq_or_ne z 0 with (rfl | hzne)
· exact hre 0 le_rfl
-- Otherwise, `z = e ^ ζ` for some `ζ : ℂ`, `0 < Im ζ < π / 2`.
obtain ⟨ζ, hζ, rfl⟩ : ∃ ζ : ℂ, ζ.im ∈ Icc 0 (π / 2) ∧ exp ζ = z := by
refine ⟨log z, ?_, exp_log hzne⟩
rw [log_im]
exact ⟨arg_nonneg_iff.2 hz_im, arg_le_pi_div_two_iff.2 (Or.inl hz_re)⟩
| -- We are going to apply `PhragmenLindelof.horizontal_strip` to `f ∘ Complex.exp` and `ζ`.
change ‖(f ∘ exp) ζ‖ ≤ C
have H : MapsTo exp (im ⁻¹' Ioo 0 (π / 2)) (Ioi 0 ×ℂ Ioi 0) := fun z hz ↦ by
rw [mem_reProdIm, exp_re, exp_im, mem_Ioi, mem_Ioi]
have : 0 < Real.cos z.im := Real.cos_pos_of_mem_Ioo ⟨by linarith [hz.1, hz.2], hz.2⟩
have : 0 < Real.sin z.im :=
Real.sin_pos_of_mem_Ioo ⟨hz.1, hz.2.trans (half_lt_self Real.pi_pos)⟩
constructor <;> positivity
refine horizontal_strip (hd.comp differentiable_exp.diffContOnCl H) ?_ ?_ ?_ hζ.1 hζ.2
· -- The estimate `hB` on `f` implies the required estimate on
-- `f ∘ exp` with the same `c` and `B' = max B 0`.
rw [sub_zero, div_div_cancel₀ Real.pi_pos.ne']
rcases hB with ⟨c, hc, B, hO⟩
refine ⟨c, hc, max B 0, ?_⟩
rw [← comap_comap, comap_abs_atTop, comap_sup, inf_sup_right]
-- We prove separately the estimates as `ζ.re → ∞` and as `ζ.re → -∞`
refine IsBigO.sup ?_ <| (hO.comp_tendsto <| tendsto_exp_comap_re_atTop.inf H.tendsto).trans <|
.of_norm_eventuallyLE ?_
· -- For the estimate as `ζ.re → -∞`, note that `f` is continuous within the first quadrant at
-- zero, hence `f (exp ζ)` has a limit as `ζ.re → -∞`, `0 < ζ.im < π / 2`.
have hc : ContinuousWithinAt f (Ioi 0 ×ℂ Ioi 0) 0 := by
refine (hd.continuousOn _ ?_).mono subset_closure
simp [closure_reProdIm, mem_reProdIm]
refine ((hc.tendsto.comp <| tendsto_exp_comap_re_atBot.inf H.tendsto).isBigO_one ℝ).trans
(isBigO_of_le _ fun w => ?_)
rw [norm_one, Real.norm_of_nonneg (Real.exp_pos _).le, Real.one_le_exp_iff]
positivity
· -- For the estimate as `ζ.re → ∞`, we reuse the upper estimate on `f`
simp only [EventuallyLE, eventually_inf_principal, eventually_comap, comp_apply, one_mul,
Real.norm_of_nonneg (Real.exp_pos _).le, norm_exp, ← Real.exp_mul, Real.exp_le_exp]
filter_upwards [eventually_ge_atTop 0] with x hx z hz _
rw [hz, abs_of_nonneg hx, mul_comm _ c]
gcongr; apply le_max_left
· -- If `ζ.im = 0`, then `Complex.exp ζ` is a positive real number
intro ζ hζ; lift ζ to ℝ using hζ
rw [comp_apply, ← ofReal_exp]
exact hre _ (Real.exp_pos _).le
· -- If `ζ.im = π / 2`, then `Complex.exp ζ` is a purely imaginary number with positive `im`
intro ζ hζ
rw [← re_add_im ζ, hζ, comp_apply, exp_add_mul_I, ← ofReal_cos, ← ofReal_sin,
Real.cos_pi_div_two, Real.sin_pi_div_two, ofReal_zero, ofReal_one, one_mul, zero_add, ←
ofReal_exp]
exact him _ (Real.exp_pos _).le
/-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f : ℂ → E` be a function such that
* `f` is differentiable in the open first quadrant and is continuous on its closure;
* `‖f z‖` is bounded from above by `A * exp(B * ‖z‖ ^ c)` on the open first quadrant
for some `A`, `B`, and `c < 2`;
* `f` is equal to zero on the boundary of the first quadrant.
Then `f` is equal to zero on the closed first quadrant. -/
theorem eq_zero_on_quadrant_I (hd : DiffContOnCl ℂ f (Ioi 0 ×ℂ Ioi 0))
(hB : ∃ c < (2 : ℝ), ∃ B,
f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * ‖z‖ ^ c))
(hre : ∀ x : ℝ, 0 ≤ x → f x = 0) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = 0) :
EqOn f 0 {z | 0 ≤ z.re ∧ 0 ≤ z.im} := fun _z hz =>
norm_le_zero_iff.1 <|
| Mathlib/Analysis/Complex/PhragmenLindelof.lean | 351 | 408 |
/-
Copyright (c) 2022 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.Module.End
import Mathlib.RingTheory.OreLocalization.Basic
/-!
# Module and Ring instances of Ore Localizations
The `Monoid` and `DistribMulAction` instances and additive versions are provided in
`Mathlib/RingTheory/OreLocalization/Basic.lean`.
-/
assert_not_exists Subgroup
universe u
namespace OreLocalization
section Module
variable {R : Type*} [Semiring R] {S : Submonoid R} [OreSet S]
variable {X : Type*} [AddCommMonoid X] [Module R X]
protected theorem zero_smul (x : X[S⁻¹]) : (0 : R[S⁻¹]) • x = 0 := by
induction' x with r s
rw [OreLocalization.zero_def, oreDiv_smul_char 0 r 1 s 0 1 (by simp)]; simp
|
protected theorem add_smul (y z : R[S⁻¹]) (x : X[S⁻¹]) :
(y + z) • x = y • x + z • x := by
induction' x with r₁ s₁
induction' y with r₂ s₂
induction' z with r₃ s₃
rcases oreDivAddChar' r₂ r₃ s₂ s₃ with ⟨ra, sa, ha, q⟩
rw [q]
clear q
rw [OreLocalization.expand' r₂ s₂ sa]
rcases oreDivSMulChar' (sa • r₂) r₁ (sa * s₂) s₁ with ⟨rb, sb, hb, q⟩
rw [q]
clear q
have hs₃rasb : sb * ra * s₃ ∈ S := by
rw [mul_assoc, ← ha]
norm_cast
apply SetLike.coe_mem
rw [OreLocalization.expand _ _ _ hs₃rasb]
have ha' : ↑((sb * sa) * s₂) = sb * ra * s₃ := by simp [ha, mul_assoc]
rw [← Subtype.coe_eq_of_eq_mk ha']
rcases oreDivSMulChar' ((sb * ra) • r₃) r₁ (sb * sa * s₂) s₁ with ⟨rc, sc, hc, hc'⟩
rw [hc']
rw [oreDiv_add_char _ _ 1 sc (by simp [mul_assoc])]
rw [OreLocalization.expand' (sa • r₂ + ra • r₃) (sa * s₂) (sc * sb)]
simp only [smul_eq_mul, one_smul, Submonoid.smul_def, mul_add, Submonoid.coe_mul] at hb hc ⊢
rw [mul_assoc, hb, mul_assoc, ← mul_assoc _ ra, hc, ← mul_assoc, ← add_mul]
rw [OreLocalization.smul_cancel']
| Mathlib/RingTheory/OreLocalization/Ring.lean | 36 | 62 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Order.Group.Finset
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $R[X]$
-/
noncomputable section
open Polynomial
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ}
section CommRing
variable [CommRing R]
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero
(p : R[X]) (t : R) (hnezero : derivative p ≠ 0) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t :=
(le_rootMultiplicity_iff hnezero).2 <|
pow_sub_one_dvd_derivative_of_pow_dvd (p.pow_rootMultiplicity_dvd t)
theorem derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors
{p : R[X]} {t : R} (hpt : Polynomial.IsRoot p t)
(hnzd : (p.rootMultiplicity t : R) ∈ nonZeroDivisors R) :
(derivative p).rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· simp only [h, map_zero, rootMultiplicity_zero]
obtain ⟨g, hp, hndvd⟩ := p.exists_eq_pow_rootMultiplicity_mul_and_not_dvd h t
set m := p.rootMultiplicity t
have hm : m - 1 + 1 = m := Nat.sub_add_cancel <| (rootMultiplicity_pos h).2 hpt
have hndvd : ¬(X - C t) ^ m ∣ derivative p := by
rw [hp, derivative_mul, dvd_add_left (dvd_mul_right _ _),
derivative_X_sub_C_pow, ← hm, pow_succ, hm, mul_comm (C _), mul_assoc,
dvd_cancel_left_mem_nonZeroDivisors (monic_X_sub_C t |>.pow _ |>.mem_nonZeroDivisors)]
rw [dvd_iff_isRoot, IsRoot] at hndvd ⊢
rwa [eval_mul, eval_C, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd]
have hnezero : derivative p ≠ 0 := fun h ↦ hndvd (by rw [h]; exact dvd_zero _)
exact le_antisymm (by rwa [rootMultiplicity_le_iff hnezero, hm])
(rootMultiplicity_sub_one_le_derivative_rootMultiplicity_of_ne_zero _ t hnezero)
theorem isRoot_iterate_derivative_of_lt_rootMultiplicity {p : R[X]} {t : R} {n : ℕ}
(hn : n < p.rootMultiplicity t) : (derivative^[n] p).IsRoot t :=
dvd_iff_isRoot.mp <| (dvd_pow_self _ <| Nat.sub_ne_zero_of_lt hn).trans
(pow_sub_dvd_iterate_derivative_of_pow_dvd _ <| p.pow_rootMultiplicity_dvd t)
open Finset in
theorem eval_iterate_derivative_rootMultiplicity {p : R[X]} {t : R} :
(derivative^[p.rootMultiplicity t] p).eval t =
(p.rootMultiplicity t).factorial • (p /ₘ (X - C t) ^ p.rootMultiplicity t).eval t := by
set m := p.rootMultiplicity t with hm
conv_lhs => rw [← p.pow_mul_divByMonic_rootMultiplicity_eq t, ← hm]
rw [iterate_derivative_mul, eval_finset_sum, sum_eq_single_of_mem _ (mem_range.mpr m.succ_pos)]
· rw [m.choose_zero_right, one_smul, eval_mul, m.sub_zero, iterate_derivative_X_sub_pow_self,
eval_natCast, nsmul_eq_mul]; rfl
· intro b hb hb0
rw [iterate_derivative_X_sub_pow, eval_smul, eval_mul, eval_smul, eval_pow,
Nat.sub_sub_self (mem_range_succ_iff.mp hb), eval_sub, eval_X, eval_C, sub_self,
zero_pow hb0, smul_zero, zero_mul, smul_zero]
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
by_contra! h'
replace hroot := hroot _ h'
simp only [IsRoot, eval_iterate_derivative_rootMultiplicity] at hroot
obtain ⟨q, hq⟩ := Nat.cast_dvd_cast (α := R) <| Nat.factorial_dvd_factorial h'
rw [hq, mul_mem_nonZeroDivisors] at hnzd
rw [nsmul_eq_mul, mul_left_mem_nonZeroDivisors_eq_zero_iff hnzd.1] at hroot
exact eval_divByMonic_pow_rootMultiplicity_ne_zero t h hroot
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t := by
apply lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot
clear hroot
induction n with
| zero =>
simp only [Nat.factorial_zero, Nat.cast_one]
exact Submonoid.one_mem _
| succ n ih =>
rw [Nat.factorial_succ, Nat.cast_mul, mul_mem_nonZeroDivisors]
exact ⟨hnzd _ le_rfl n.succ_ne_zero, ih fun m h ↦ hnzd m (h.trans n.le_succ)⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : (n.factorial : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| hm.trans_lt hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hr hnzd⟩
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors'
{p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hnzd : ∀ m ≤ n, m ≠ 0 → (m : R) ∈ nonZeroDivisors R) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors' h hr hnzd⟩
theorem one_lt_rootMultiplicity_iff_isRoot_iterate_derivative
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ ∀ m ≤ 1, (derivative^[m] p).IsRoot t :=
lt_rootMultiplicity_iff_isRoot_iterate_derivative_of_mem_nonZeroDivisors h
(by rw [Nat.factorial_one, Nat.cast_one]; exact Submonoid.one_mem _)
theorem one_lt_rootMultiplicity_iff_isRoot
{p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ p.IsRoot t ∧ (derivative p).IsRoot t := by
rw [one_lt_rootMultiplicity_iff_isRoot_iterate_derivative h]
refine ⟨fun h ↦ ⟨h 0 (by norm_num), h 1 (by norm_num)⟩, fun ⟨h0, h1⟩ m hm ↦ ?_⟩
obtain (_|_|m) := m
exacts [h0, h1, by omega]
end CommRing
section IsDomain
variable [CommRing R] [IsDomain R]
theorem one_lt_rootMultiplicity_iff_isRoot_gcd
[GCDMonoid R[X]] {p : R[X]} {t : R} (h : p ≠ 0) :
1 < p.rootMultiplicity t ↔ (gcd p (derivative p)).IsRoot t := by
simp_rw [one_lt_rootMultiplicity_iff_isRoot h, ← dvd_iff_isRoot, dvd_gcd_iff]
theorem derivative_rootMultiplicity_of_root [CharZero R] {p : R[X]} {t : R} (hpt : p.IsRoot t) :
p.derivative.rootMultiplicity t = p.rootMultiplicity t - 1 := by
by_cases h : p = 0
· rw [h, map_zero, rootMultiplicity_zero]
exact derivative_rootMultiplicity_of_root_of_mem_nonZeroDivisors hpt <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 ((rootMultiplicity_pos h).2 hpt).ne'
theorem rootMultiplicity_sub_one_le_derivative_rootMultiplicity [CharZero R] (p : R[X]) (t : R) :
p.rootMultiplicity t - 1 ≤ p.derivative.rootMultiplicity t := by
by_cases h : p.IsRoot t
· exact (derivative_rootMultiplicity_of_root h).symm.le
· rw [rootMultiplicity_eq_zero h, zero_tsub]
exact zero_le _
theorem lt_rootMultiplicity_of_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0)
(hroot : ∀ m ≤ n, (derivative^[m] p).IsRoot t) :
n < p.rootMultiplicity t :=
lt_rootMultiplicity_of_isRoot_iterate_derivative_of_mem_nonZeroDivisors h hroot <|
mem_nonZeroDivisors_of_ne_zero <| Nat.cast_ne_zero.2 <| Nat.factorial_ne_zero n
theorem lt_rootMultiplicity_iff_isRoot_iterate_derivative
[CharZero R] {p : R[X]} {t : R} {n : ℕ} (h : p ≠ 0) :
n < p.rootMultiplicity t ↔ ∀ m ≤ n, (derivative^[m] p).IsRoot t :=
⟨fun hn _ hm ↦ isRoot_iterate_derivative_of_lt_rootMultiplicity <| Nat.lt_of_le_of_lt hm hn,
fun hr ↦ lt_rootMultiplicity_of_isRoot_iterate_derivative h hr⟩
/-- A sufficient condition for the set of roots of a nonzero polynomial `f` to be a subset of the
set of roots of `g` is that `f` divides `f.derivative * g`. Over an algebraically closed field of
characteristic zero, this is also a necessary condition.
See `isRoot_of_isRoot_iff_dvd_derivative_mul` -/
theorem isRoot_of_isRoot_of_dvd_derivative_mul [CharZero R] {f g : R[X]} (hf0 : f ≠ 0)
(hfd : f ∣ f.derivative * g) {a : R} (haf : f.IsRoot a) : g.IsRoot a := by
rcases hfd with ⟨r, hr⟩
have hdf0 : derivative f ≠ 0 := by
contrapose! haf
rw [eq_C_of_derivative_eq_zero haf] at hf0 ⊢
exact not_isRoot_C _ _ <| C_ne_zero.mp hf0
by_contra hg
have hdfg0 : f.derivative * g ≠ 0 := mul_ne_zero hdf0 (by rintro rfl; simp at hg)
have hr' := congr_arg (rootMultiplicity a) hr
rw [rootMultiplicity_mul hdfg0, derivative_rootMultiplicity_of_root haf,
rootMultiplicity_eq_zero hg, add_zero, rootMultiplicity_mul (hr ▸ hdfg0), add_comm,
Nat.sub_eq_iff_eq_add (Nat.succ_le_iff.2 ((rootMultiplicity_pos hf0).2 haf))] at hr'
omega
section NormalizationMonoid
variable [NormalizationMonoid R]
instance instNormalizationMonoid : NormalizationMonoid R[X] where
normUnit p :=
⟨C ↑(normUnit p.leadingCoeff), C ↑(normUnit p.leadingCoeff)⁻¹, by
rw [← RingHom.map_mul, Units.mul_inv, C_1], by rw [← RingHom.map_mul, Units.inv_mul, C_1]⟩
normUnit_zero := Units.ext (by simp)
normUnit_mul hp0 hq0 :=
Units.ext
(by
dsimp
rw [Ne, ← leadingCoeff_eq_zero] at *
rw [leadingCoeff_mul, normUnit_mul hp0 hq0, Units.val_mul, C_mul])
normUnit_coe_units u :=
Units.ext
(by
dsimp
rw [← mul_one u⁻¹, Units.val_mul, Units.eq_inv_mul_iff_mul_eq]
rcases Polynomial.isUnit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩
rw [← h2, leadingCoeff_C, normUnit_coe_units, ← C_mul, Units.mul_inv, C_1]
rfl)
@[simp]
theorem coe_normUnit {p : R[X]} : (normUnit p : R[X]) = C ↑(normUnit p.leadingCoeff) := by
simp [normUnit]
@[simp]
theorem leadingCoeff_normalize (p : R[X]) :
leadingCoeff (normalize p) = normalize (leadingCoeff p) := by simp [normalize_apply]
theorem Monic.normalize_eq_self {p : R[X]} (hp : p.Monic) : normalize p = p := by
simp only [Polynomial.coe_normUnit, normalize_apply, hp.leadingCoeff, normUnit_one,
Units.val_one, Polynomial.C.map_one, mul_one]
theorem roots_normalize {p : R[X]} : (normalize p).roots = p.roots := by
rw [normalize_apply, mul_comm, coe_normUnit, roots_C_mul _ (normUnit (leadingCoeff p)).ne_zero]
theorem normUnit_X : normUnit (X : Polynomial R) = 1 := by
have := coe_normUnit (R := R) (p := X)
rwa [leadingCoeff_X, normUnit_one, Units.val_one, map_one, Units.val_eq_one] at this
theorem X_eq_normalize : (X : Polynomial R) = normalize X := by
simp only [normalize_apply, normUnit_X, Units.val_one, mul_one]
end NormalizationMonoid
end IsDomain
section DivisionRing
variable [DivisionRing R] {p q : R[X]}
theorem degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬IsUnit p) : 0 < degree p :=
lt_of_not_ge fun h => by
rw [eq_C_of_degree_le_zero h] at hp0 hp
exact hp (IsUnit.map C (IsUnit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0))))
@[simp]
protected theorem map_eq_zero [Semiring S] [Nontrivial S] (f : R →+* S) : p.map f = 0 ↔ p = 0 := by
simp only [Polynomial.ext_iff]
congr!
simp [map_eq_zero, coeff_map, coeff_zero]
theorem map_ne_zero [Semiring S] [Nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 :=
mt (Polynomial.map_eq_zero f).1 hp
@[simp]
theorem degree_map [Semiring S] [Nontrivial S] (p : R[X]) (f : R →+* S) :
degree (p.map f) = degree p :=
p.degree_map_eq_of_injective f.injective
@[simp]
theorem natDegree_map [Semiring S] [Nontrivial S] (f : R →+* S) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map _ f)
@[simp]
theorem leadingCoeff_map [Semiring S] [Nontrivial S] (f : R →+* S) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
simp only [← coeff_natDegree, coeff_map f, natDegree_map]
theorem monic_map_iff [Semiring S] [Nontrivial S] {f : R →+* S} {p : R[X]} :
(p.map f).Monic ↔ p.Monic := by
rw [Monic, leadingCoeff_map, ← f.map_one, Function.Injective.eq_iff f.injective, Monic]
end DivisionRing
section Field
variable [Field R] {p q : R[X]}
theorem isUnit_iff_degree_eq_zero : IsUnit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_isUnit, fun h =>
have : degree p ≤ 0 := by simp [*, le_refl]
have hc : coeff p 0 ≠ 0 := fun hc => by
rw [eq_C_of_degree_le_zero this, hc] at h; simp only [map_zero] at h; contradiction
isUnit_iff_dvd_one.2
⟨C (coeff p 0)⁻¹, by
conv in p => rw [eq_C_of_degree_le_zero this]
rw [← C_mul, mul_inv_cancel₀ hc, C_1]⟩⟩
/-- Division of polynomials. See `Polynomial.divByMonic` for more details. -/
def div (p q : R[X]) :=
C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹))
/-- Remainder of polynomial division. See `Polynomial.modByMonic` for more details. -/
def mod (p q : R[X]) :=
p %ₘ (q * C (leadingCoeff q)⁻¹)
private theorem quotient_mul_add_remainder_eq_aux (p q : R[X]) : q * div p q + mod p q = p := by
by_cases h : q = 0
· simp only [h, zero_mul, mod, modByMonic_zero, zero_add]
· conv =>
rhs
rw [← modByMonic_add_div p (monic_mul_leadingCoeff_inv h)]
rw [div, mod, add_comm, mul_assoc]
private theorem remainder_lt_aux (p : R[X]) (hq : q ≠ 0) : degree (mod p q) < degree q := by
rw [← degree_mul_leadingCoeff_inv q hq]
exact degree_modByMonic_lt p (monic_mul_leadingCoeff_inv hq)
instance : Div R[X] :=
⟨div⟩
instance : Mod R[X] :=
⟨mod⟩
theorem div_def : p / q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) :=
rfl
theorem mod_def : p % q = p %ₘ (q * C (leadingCoeff q)⁻¹) := rfl
theorem modByMonic_eq_mod (p : R[X]) (hq : Monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leadingCoeff q)⁻¹) by
simp only [Monic.def.1 hq, inv_one, mul_one, C_1]
theorem divByMonic_eq_div (p : R[X]) (hq : Monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leadingCoeff q)⁻¹ * (p /ₘ (q * C (leadingCoeff q)⁻¹)) by
simp only [Monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
theorem mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) :=
modByMonic_eq_mod p (monic_X_sub_C a) ▸ modByMonic_X_sub_C_eq_C_eval _ _
theorem mul_div_eq_iff_isRoot : (X - C a) * (p / (X - C a)) = p ↔ IsRoot p a :=
divByMonic_eq_div p (monic_X_sub_C a) ▸ mul_divByMonic_eq_iff_isRoot
instance instEuclideanDomain : EuclideanDomain R[X] :=
{ Polynomial.commRing,
Polynomial.nontrivial with
quotient := (· / ·)
quotient_zero := by simp [div_def]
remainder := (· % ·)
r := _
r_wellFounded := degree_lt_wf
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux
remainder_lt := fun _ _ hq => remainder_lt_aux _ hq
mul_left_not_lt := fun _ _ hq => not_lt_of_ge (degree_le_mul_left _ hq) }
theorem mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨fun h => h ▸ EuclideanDomain.mod_lt _ hq0, fun h => by
classical
have : ¬degree (q * C (leadingCoeff q)⁻¹) ≤ degree p :=
not_le_of_gt <| by rwa [degree_mul_leadingCoeff_inv q hq0]
rw [mod_def, modByMonic, dif_pos (monic_mul_leadingCoeff_inv hq0)]
unfold divModByMonicAux
dsimp
simp only [this, false_and, if_false]⟩
theorem div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨fun h => by
have := EuclideanDomain.div_add_mod p q
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
fun h => by
have hlt : degree p < degree (q * C (leadingCoeff q)⁻¹) := by
rwa [degree_mul_leadingCoeff_inv q hq0]
have hm : Monic (q * C (leadingCoeff q)⁻¹) := monic_mul_leadingCoeff_inv hq0
rw [div_def, (divByMonic_eq_zero_iff hm).2 hlt, mul_zero]⟩
theorem degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p := by
have : degree (p % q) < degree (q * (p / q)) :=
calc
degree (p % q) < degree q := EuclideanDomain.mod_lt _ hq0
_ ≤ _ := degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq))
conv_rhs =>
rw [← EuclideanDomain.div_add_mod p q, degree_add_eq_left_of_degree_lt this, degree_mul]
theorem degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p := by
by_cases hq : q = 0
· simp [hq]
· rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq]; exact degree_divByMonic_le _ _
theorem degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p := by
have hq0 : q ≠ 0 := fun hq0 => by simp [hq0] at hq
rw [div_def, mul_comm, degree_mul_leadingCoeff_inv _ hq0]
exact degree_divByMonic_lt _ (monic_mul_leadingCoeff_inv hq0) hp
(by rw [degree_mul_leadingCoeff_inv _ hq0]; exact hq)
theorem isUnit_map [Field k] (f : R →+* k) : IsUnit (p.map f) ↔ IsUnit p := by
simp_rw [isUnit_iff_degree_eq_zero, degree_map]
theorem map_div [Field k] (f : R →+* k) : (p / q).map f = p.map f / q.map f := by
if hq0 : q = 0 then simp [hq0]
else
rw [div_def, div_def, Polynomial.map_mul, map_divByMonic f (monic_mul_leadingCoeff_inv hq0),
Polynomial.map_mul, map_C, leadingCoeff_map, map_inv₀]
theorem map_mod [Field k] (f : R →+* k) : (p % q).map f = p.map f % q.map f := by
by_cases hq0 : q = 0
· simp [hq0]
· rw [mod_def, mod_def, leadingCoeff_map f, ← map_inv₀ f, ← map_C f, ← Polynomial.map_mul f,
map_modByMonic f (monic_mul_leadingCoeff_inv hq0)]
lemma natDegree_mod_lt [Field k] (p : k[X]) {q : k[X]} (hq : q.natDegree ≠ 0) :
(p % q).natDegree < q.natDegree := by
have hq' : q.leadingCoeff ≠ 0 := by
rw [leadingCoeff_ne_zero]
contrapose! hq
simp [hq]
rw [mod_def]
refine (natDegree_modByMonic_lt p ?_ ?_).trans_le ?_
· refine monic_mul_C_of_leadingCoeff_mul_eq_one ?_
rw [mul_inv_eq_one₀ hq']
· contrapose! hq
rw [← natDegree_mul_C_eq_of_mul_eq_one ((inv_mul_eq_one₀ hq').mpr rfl)]
simp [hq]
· exact natDegree_mul_C_le q q.leadingCoeff⁻¹
section
open EuclideanDomain
theorem gcd_map [Field k] [DecidableEq R] [DecidableEq k] (f : R →+* k) :
gcd (p.map f) (q.map f) = (gcd p q).map f :=
GCD.induction p q (fun x => by simp_rw [Polynomial.map_zero, EuclideanDomain.gcd_zero_left])
fun x y _ ih => by rw [gcd_val, ← map_mod, ih, ← gcd_val]
end
theorem eval₂_gcd_eq_zero [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} (hf : f.eval₂ ϕ α = 0)
(hg : g.eval₂ ϕ α = 0) : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0 := by
rw [EuclideanDomain.gcd_eq_gcd_ab f g, Polynomial.eval₂_add, Polynomial.eval₂_mul,
Polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add]
theorem eval_gcd_eq_zero [DecidableEq R] {f g : R[X]} {α : R}
(hf : f.eval α = 0) (hg : g.eval α = 0) : (EuclideanDomain.gcd f g).eval α = 0 :=
eval₂_gcd_eq_zero hf hg
theorem root_left_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 := by
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_left f g
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
theorem root_right_of_root_gcd [CommSemiring k] [DecidableEq R] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (EuclideanDomain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 := by
obtain ⟨p, hp⟩ := EuclideanDomain.gcd_dvd_right f g
rw [hp, Polynomial.eval₂_mul, hα, zero_mul]
theorem root_gcd_iff_root_left_right [CommSemiring k] [DecidableEq R]
{ϕ : R →+* k} {f g : R[X]} {α : k} :
(EuclideanDomain.gcd f g).eval₂ ϕ α = 0 ↔ f.eval₂ ϕ α = 0 ∧ g.eval₂ ϕ α = 0 :=
⟨fun h => ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, fun h => eval₂_gcd_eq_zero h.1 h.2⟩
theorem isRoot_gcd_iff_isRoot_left_right [DecidableEq R] {f g : R[X]} {α : R} :
(EuclideanDomain.gcd f g).IsRoot α ↔ f.IsRoot α ∧ g.IsRoot α :=
root_gcd_iff_root_left_right
theorem isCoprime_map [Field k] (f : R →+* k) : IsCoprime (p.map f) (q.map f) ↔ IsCoprime p q := by
classical
rw [← EuclideanDomain.gcd_isUnit_iff, ← EuclideanDomain.gcd_isUnit_iff, gcd_map, isUnit_map]
theorem mem_roots_map [CommRing k] [IsDomain k] {f : R →+* k} {x : k} (hp : p ≠ 0) :
x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 := by
rw [mem_roots (map_ne_zero hp), IsRoot, Polynomial.eval_map]
theorem rootSet_monomial [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : (monomial n a).rootSet S = {0} := by
classical
rw [rootSet, aroots_monomial ha,
Multiset.toFinset_nsmul _ _ hn, Multiset.toFinset_singleton, Finset.coe_singleton]
theorem rootSet_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) {a : R}
(ha : a ≠ 0) : rootSet (C a * X ^ n) S = {0} := by
rw [C_mul_X_pow_eq_monomial, rootSet_monomial hn ha]
theorem rootSet_X_pow [CommRing S] [IsDomain S] [Algebra R S] {n : ℕ} (hn : n ≠ 0) :
(X ^ n : R[X]).rootSet S = {0} := by
rw [← one_mul (X ^ n : R[X]), ← C_1, rootSet_C_mul_X_pow hn]
exact one_ne_zero
theorem rootSet_prod [CommRing S] [IsDomain S] [Algebra R S] {ι : Type*} (f : ι → R[X])
(s : Finset ι) (h : s.prod f ≠ 0) : (s.prod f).rootSet S = ⋃ i ∈ s, (f i).rootSet S := by
classical
simp only [rootSet, aroots, ← Finset.mem_coe]
rw [Polynomial.map_prod, roots_prod, Finset.bind_toFinset, s.val_toFinset, Finset.coe_biUnion]
rwa [← Polynomial.map_prod, Ne, Polynomial.map_eq_zero]
theorem roots_C_mul_X_sub_C (b : R) (ha : a ≠ 0) : (C a * X - C b).roots = {a⁻¹ * b} := by
simp [roots_C_mul_X_sub_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩]
theorem roots_C_mul_X_add_C (b : R) (ha : a ≠ 0) : (C a * X + C b).roots = {-(a⁻¹ * b)} := by
simp [roots_C_mul_X_add_C_of_IsUnit b ⟨a, a⁻¹, mul_inv_cancel₀ ha, inv_mul_cancel₀ ha⟩]
theorem roots_degree_eq_one (h : degree p = 1) : p.roots = {-((p.coeff 1)⁻¹ * p.coeff 0)} := by
rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1 by rw [h])]
have : p.coeff 1 ≠ 0 := coeff_ne_zero_of_eq_degree h
| simp [roots_C_mul_X_add_C _ this]
theorem exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, IsRoot p x :=
⟨-((p.coeff 1)⁻¹ * p.coeff 0), by
rw [← mem_roots (by simp [← zero_le_degree_iff, h])]
simp [roots_degree_eq_one h]⟩
theorem coeff_inv_units (u : R[X]ˣ) (n : ℕ) : ((↑u : R[X]).coeff n)⁻¹ = (↑u⁻¹ : R[X]).coeff n := by
| Mathlib/Algebra/Polynomial/FieldDivision.lean | 502 | 509 |
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.DirectSum.LinearMap
import Mathlib.Algebra.Lie.Weights.Cartan
import Mathlib.Data.Int.Interval
import Mathlib.LinearAlgebra.Trace
import Mathlib.RingTheory.Finiteness.Nilpotent
/-!
# Chains of roots and weights
Given roots `α` and `β` of a Lie algebra, together with elements `x` in the `α`-root space and
`y` in the `β`-root space, it follows from the Leibniz identity that `⁅x, y⁆` is either zero or
belongs to the `α + β`-root space. Iterating this operation leads to the study of families of
roots of the form `k • α + β`. Such a family is known as the `α`-chain through `β` (or sometimes,
the `α`-string through `β`) and the study of the sum of the corresponding root spaces is an
important technique.
More generally if `α` is a root and `χ` is a weight of a representation, it is useful to study the
`α`-chain through `χ`.
We provide basic definitions and results to support `α`-chain techniques in this file.
## Main definitions / results
* `LieModule.exists₂_genWeightSpace_smul_add_eq_bot`: given weights `χ₁`, `χ₂` if `χ₁ ≠ 0`, we can
find `p < 0` and `q > 0` such that the weight spaces `p • χ₁ + χ₂` and `q • χ₁ + χ₂` are both
trivial.
* `LieModule.genWeightSpaceChain`: given weights `χ₁`, `χ₂` together with integers `p` and `q`,
this is the sum of the weight spaces `k • χ₁ + χ₂` for `p < k < q`.
* `LieModule.trace_toEnd_genWeightSpaceChain_eq_zero`: given a root `α` relative to a Cartan
subalgebra `H`, there is a natural ideal `corootSpace α` in `H`. This lemma
states that this ideal acts by trace-zero endomorphisms on the sum of root spaces of any
`α`-chain, provided the weight spaces at the endpoints are both trivial.
* `LieModule.exists_forall_mem_corootSpace_smul_add_eq_zero`: given a (potential) root
`α` relative to a Cartan subalgebra `H`, if we restrict to the ideal
`corootSpace α` of `H`, we may find an integral linear combination between
`α` and any weight `χ` of a representation.
## TODO
It should be possible to unify some of the definitions here such as `LieModule.chainBotCoeff`,
`LieModule.chainTopCoeff` with corresponding definitions such as `RootPairing.chainBotCoeff`,
`RootPairing.chainTopCoeff`. This is not quite trivial since:
* The definitions here allow for chains in representations of Lie algebras.
* The proof that the roots of a Lie algebra are a root system currently depends on these results.
(This can be resolved by proving the root reflection formula using the approach outlined in
Bourbaki Ch. VIII §2.2 Lemma 1 (page 80 of English translation, 88 of English PDF).)
-/
open Module Function Set
variable {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L]
(M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
namespace LieModule
section IsNilpotent
variable [LieRing.IsNilpotent L] (χ₁ χ₂ : L → R) (p q : ℤ)
section
variable [NoZeroSMulDivisors ℤ R] [NoZeroSMulDivisors R M] [IsNoetherian R M] (hχ₁ : χ₁ ≠ 0)
include hχ₁
lemma eventually_genWeightSpace_smul_add_eq_bot :
∀ᶠ (k : ℕ) in Filter.atTop, genWeightSpace M (k • χ₁ + χ₂) = ⊥ := by
let f : ℕ → L → R := fun k ↦ k • χ₁ + χ₂
suffices Injective f by
| rw [← Nat.cofinite_eq_atTop, Filter.eventually_cofinite, ← finite_image_iff this.injOn]
apply (finite_genWeightSpace_ne_bot R L M).subset
simp [f]
intro k l hkl
replace hkl : (k : ℤ) • χ₁ = (l : ℤ) • χ₁ := by
simpa only [f, add_left_inj, natCast_zsmul] using hkl
exact Nat.cast_inj.mp <| smul_left_injective ℤ hχ₁ hkl
lemma exists_genWeightSpace_smul_add_eq_bot :
∃ k > 0, genWeightSpace M (k • χ₁ + χ₂) = ⊥ :=
(Nat.eventually_pos.and <| eventually_genWeightSpace_smul_add_eq_bot M χ₁ χ₂ hχ₁).exists
| Mathlib/Algebra/Lie/Weights/Chain.lean | 75 | 85 |
/-
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'
| Mathlib/Analysis/Normed/Group/Basic.lean | 736 | 739 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Module.NatInt
import Mathlib.GroupTheory.Abelianization
import Mathlib.GroupTheory.FreeGroup.Basic
/-!
# Free abelian groups
The free abelian group on a type `α`, defined as the abelianisation of
the free group on `α`.
The free abelian group on `α` can be abstractly defined as the left adjoint of the
forgetful functor from abelian groups to types. Alternatively, one could define
it as the functions `α → ℤ` which send all but finitely many `(a : α)` to `0`,
under pointwise addition. In this file, it is defined as the abelianisation
of the free group on `α`. All the constructions and theorems required to show
the adjointness of the construction and the forgetful functor are proved in this
file, but the category-theoretic adjunction statement is in
`Algebra.Category.Group.Adjunctions`.
## Main definitions
Here we use the following variables: `(α β : Type*) (A : Type*) [AddCommGroup A]`
* `FreeAbelianGroup α` : the free abelian group on a type `α`. As an abelian
group it is `α →₀ ℤ`, the functions from `α` to `ℤ` such that all but finitely
many elements get mapped to zero, however this is not how it is implemented.
* `lift f : FreeAbelianGroup α →+ A` : the group homomorphism induced
by the map `f : α → A`.
* `map (f : α → β) : FreeAbelianGroup α →+ FreeAbelianGroup β` : functoriality
of `FreeAbelianGroup`.
* `instance [Monoid α] : Semigroup (FreeAbelianGroup α)`
* `instance [CommMonoid α] : CommRing (FreeAbelianGroup α)`
It has been suggested that we would be better off refactoring this file
and using `Finsupp` instead.
## Implementation issues
The definition is `def FreeAbelianGroup : Type u := Additive <| Abelianization <| FreeGroup α`.
Chris Hughes has suggested that this all be rewritten in terms of `Finsupp`.
Johan Commelin has written all the API relating the definition to `Finsupp`
in the lean-liquid repo.
The lemmas `map_pure`, `map_of`, `map_zero`, `map_add`, `map_neg` and `map_sub`
are proved about the `Functor.map` `<$>` construction, and need `α` and `β` to
be in the same universe. But
`FreeAbelianGroup.map (f : α → β)` is defined to be the `AddGroup`
homomorphism `FreeAbelianGroup α →+ FreeAbelianGroup β` (with `α` and `β` now
allowed to be in different universes), so `(map f).map_add`
etc can be used to prove that `FreeAbelianGroup.map` preserves addition. The
functions `map_id`, `map_id_apply`, `map_comp`, `map_comp_apply` and `map_of_apply`
are about `FreeAbelianGroup.map`.
-/
universe u v
variable (α : Type u)
/--
If `α` is a type, then `FreeAbelianGroup α` is the free abelian group generated by `α`.
This is an abelian group equipped with a function
`FreeAbelianGroup.of : α → FreeAbelianGroup α` which has the following universal property:
if `G` is any abelian group, and `f : α → G` is any function, then this function is
the composite of `FreeAbelianGroup.of` and a unique group homomorphism
`FreeAbelianGroup.lift f : FreeAbelianGroup α →+ G`.
A typical element of `FreeAbelianGroup α` is a formal sum of
elements of `α` and their formal inverses.
For example if `x` and `y` are terms of type `α` then `x + x + x - y` is a
"typical" element of `FreeAbelianGroup α`. In particular if `α` is empty
then `FreeAbelianGroup α` is isomorphic to the trivial group, and if `α` has one term
then `FreeAbelianGroup α` is isomorphic to `ℤ`.
One can think of `FreeAbelianGroup α` as the functions `α →₀ ℤ` with finite support,
and addition given pointwise.
TODO: rename to `FreeAddCommGroup` and introduce a multiplicative version
-/
def FreeAbelianGroup : Type u :=
Additive <| Abelianization <| FreeGroup α
-- FIXME: this is super broken, because the functions have type `Additive .. → ..`
-- instead of `FreeAbelianGroup α → ..` and those are not defeq!
instance FreeAbelianGroup.addCommGroup : AddCommGroup (FreeAbelianGroup α) :=
@Additive.addCommGroup _ <| Abelianization.commGroup _
instance : Inhabited (FreeAbelianGroup α) :=
⟨0⟩
instance [IsEmpty α] : Unique (FreeAbelianGroup α) := by unfold FreeAbelianGroup; infer_instance
variable {α}
namespace FreeAbelianGroup
/-- The canonical map from `α` to `FreeAbelianGroup α`. -/
def of (x : α) : FreeAbelianGroup α :=
Additive.ofMul <| Abelianization.of <| FreeGroup.of x
/-- The map `FreeAbelianGroup α →+ A` induced by a map of types `α → A`. -/
def lift {β : Type v} [AddCommGroup β] : (α → β) ≃ (FreeAbelianGroup α →+ β) :=
(@FreeGroup.lift _ (Multiplicative β) _).trans <|
(@Abelianization.lift _ _ (Multiplicative β) _).trans MonoidHom.toAdditive
namespace lift
variable {β : Type v} [AddCommGroup β] (f : α → β)
open FreeAbelianGroup
-- Porting note: needed to add `(β := Multiplicative β)` and `using 1`.
@[simp]
protected theorem of (x : α) : lift f (of x) = f x := by
convert Abelianization.lift.of
(FreeGroup.lift f (β := Multiplicative β)) (FreeGroup.of x) using 1
exact (FreeGroup.lift.of (β := Multiplicative β)).symm
protected theorem unique (g : FreeAbelianGroup α →+ β) (hg : ∀ x, g (of x) = f x) {x} :
g x = lift f x :=
DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ of = f)) _
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
protected theorem ext (g h : FreeAbelianGroup α →+ β) (H : ∀ x, g (of x) = h (of x)) : g = h :=
lift.symm.injective <| funext H
theorem map_hom {α β γ} [AddCommGroup β] [AddCommGroup γ] (a : FreeAbelianGroup α) (f : α → β)
(g : β →+ γ) : g (lift f a) = lift (g ∘ f) a := by
show (g.comp (lift f)) a = lift (g ∘ f) a
apply lift.unique
intro a
show g ((lift f) (of a)) = g (f a)
simp only [(· ∘ ·), lift.of]
end lift
section
open scoped Classical in
theorem of_injective : Function.Injective (of : α → FreeAbelianGroup α) :=
fun x y hoxy ↦ Classical.by_contradiction fun hxy : x ≠ y ↦
let f : FreeAbelianGroup α →+ ℤ := lift fun z ↦ if x = z then (1 : ℤ) else 0
have hfx1 : f (of x) = 1 := (lift.of _ _).trans <| if_pos rfl
have hfy1 : f (of y) = 1 := hoxy ▸ hfx1
have hfy0 : f (of y) = 0 := (lift.of _ _).trans <| if_neg hxy
one_ne_zero <| hfy1.symm.trans hfy0
@[simp]
theorem of_ne_zero (x : α) : of x ≠ 0 := by
intro h
let f : FreeAbelianGroup α →+ ℤ := lift 1
have hfx : f (of x) = 1 := lift.of _ _
have hf0 : f (of x) = 0 := by rw [h, map_zero]
exact one_ne_zero <| hfx.symm.trans hf0
@[simp]
theorem zero_ne_of (x : α) : 0 ≠ of x := of_ne_zero _ |>.symm
instance [Nonempty α] : Nontrivial (FreeAbelianGroup α) where
exists_pair_ne := let ⟨x⟩ := ‹Nonempty α›; ⟨0, of x, zero_ne_of _⟩
end
attribute [local instance] QuotientGroup.leftRel
@[elab_as_elim]
protected theorem induction_on {C : FreeAbelianGroup α → Prop} (z : FreeAbelianGroup α) (C0 : C 0)
(C1 : ∀ x, C <| of x) (Cn : ∀ x, C (of x) → C (-of x)) (Cp : ∀ x y, C x → C y → C (x + y)) :
C z :=
Quotient.inductionOn' z fun x ↦
Quot.inductionOn x fun L ↦
List.recOn L C0 fun ⟨x, b⟩ _ ih ↦ Bool.recOn b (Cp _ _ (Cn _ (C1 x)) ih) (Cp _ _ (C1 x) ih)
theorem lift.add' {α β} [AddCommGroup β] (a : FreeAbelianGroup α) (f g : α → β) :
lift (f + g) a = lift f a + lift g a := by
refine FreeAbelianGroup.induction_on a ?_ ?_ ?_ ?_
· simp only [(lift _).map_zero, zero_add]
· intro x
simp only [lift.of, Pi.add_apply]
· intro x _
simp only [map_neg, lift.of, Pi.add_apply, neg_add]
· intro x y hx hy
simp only [(lift _).map_add, hx, hy, add_add_add_comm]
/-- If `g : FreeAbelianGroup X` and `A` is an abelian group then `liftAddGroupHom g`
is the additive group homomorphism sending a function `X → A` to the term of type `A`
corresponding to the evaluation of the induced map `FreeAbelianGroup X → A` at `g`. -/
@[simps!]
def liftAddGroupHom {α} (β) [AddCommGroup β] (a : FreeAbelianGroup α) : (α → β) →+ β :=
AddMonoidHom.mk' (fun f ↦ lift f a) (lift.add' a)
theorem lift_neg' {β} [AddCommGroup β] (f : α → β) : lift (-f) = -lift f :=
AddMonoidHom.ext fun _ ↦ (liftAddGroupHom _ _ : (α → β) →+ β).map_neg _
section Monad
variable {β : Type u}
instance : Monad FreeAbelianGroup.{u} where
pure α := of α
bind x f := lift f x
@[elab_as_elim]
protected theorem induction_on' {C : FreeAbelianGroup α → Prop} (z : FreeAbelianGroup α) (C0 : C 0)
(C1 : ∀ x, C <| pure x) (Cn : ∀ x, C (pure x) → C (-pure x))
(Cp : ∀ x y, C x → C y → C (x + y)) : C z :=
FreeAbelianGroup.induction_on z C0 C1 Cn Cp
@[simp]
theorem map_pure (f : α → β) (x : α) : f <$> (pure x : FreeAbelianGroup α) = pure (f x) :=
rfl
@[simp]
protected theorem map_zero (f : α → β) : f <$> (0 : FreeAbelianGroup α) = 0 :=
(lift (of ∘ f)).map_zero
@[simp]
protected theorem map_add (f : α → β) (x y : FreeAbelianGroup α) :
f <$> (x + y) = f <$> x + f <$> y :=
(lift _).map_add _ _
@[simp]
protected theorem map_neg (f : α → β) (x : FreeAbelianGroup α) : f <$> (-x) = -f <$> x :=
map_neg (lift <| of ∘ f) _
@[simp]
protected theorem map_sub (f : α → β) (x y : FreeAbelianGroup α) :
f <$> (x - y) = f <$> x - f <$> y :=
map_sub (lift <| of ∘ f) _ _
@[simp]
theorem map_of (f : α → β) (y : α) : f <$> of y = of (f y) :=
rfl
theorem pure_bind (f : α → FreeAbelianGroup β) (x) : pure x >>= f = f x :=
lift.of _ _
@[simp]
theorem zero_bind (f : α → FreeAbelianGroup β) : 0 >>= f = 0 :=
(lift f).map_zero
@[simp]
theorem add_bind (f : α → FreeAbelianGroup β) (x y : FreeAbelianGroup α) :
x + y >>= f = (x >>= f) + (y >>= f) :=
(lift _).map_add _ _
@[simp]
theorem neg_bind (f : α → FreeAbelianGroup β) (x : FreeAbelianGroup α) : -x >>= f = -(x >>= f) :=
map_neg (lift f) _
@[simp]
theorem sub_bind (f : α → FreeAbelianGroup β) (x y : FreeAbelianGroup α) :
x - y >>= f = (x >>= f) - (y >>= f) :=
map_sub (lift f) _ _
@[simp]
theorem pure_seq (f : α → β) (x : FreeAbelianGroup α) : pure f <*> x = f <$> x :=
pure_bind _ _
@[simp]
theorem zero_seq (x : FreeAbelianGroup α) : (0 : FreeAbelianGroup (α → β)) <*> x = 0 :=
zero_bind _
@[simp]
theorem add_seq (f g : FreeAbelianGroup (α → β)) (x : FreeAbelianGroup α) :
f + g <*> x = (f <*> x) + (g <*> x) :=
add_bind _ _ _
@[simp]
theorem neg_seq (f : FreeAbelianGroup (α → β)) (x : FreeAbelianGroup α) : -f <*> x = -(f <*> x) :=
neg_bind _ _
@[simp]
theorem sub_seq (f g : FreeAbelianGroup (α → β)) (x : FreeAbelianGroup α) :
f - g <*> x = (f <*> x) - (g <*> x) :=
sub_bind _ _ _
/-- If `f : FreeAbelianGroup (α → β)`, then `f <*>` is an additive morphism
`FreeAbelianGroup α →+ FreeAbelianGroup β`. -/
def seqAddGroupHom (f : FreeAbelianGroup (α → β)) : FreeAbelianGroup α →+ FreeAbelianGroup β :=
AddMonoidHom.mk' (f <*> ·) fun x y ↦
show lift (· <$> (x + y)) _ = _ by
simp only [FreeAbelianGroup.map_add]
exact lift.add' f _ _
@[simp]
theorem seq_zero (f : FreeAbelianGroup (α → β)) : f <*> 0 = 0 :=
(seqAddGroupHom f).map_zero
@[simp]
theorem seq_add (f : FreeAbelianGroup (α → β)) (x y : FreeAbelianGroup α) :
f <*> x + y = (f <*> x) + (f <*> y) :=
(seqAddGroupHom f).map_add x y
@[simp]
theorem seq_neg (f : FreeAbelianGroup (α → β)) (x : FreeAbelianGroup α) : f <*> -x = -(f <*> x) :=
(seqAddGroupHom f).map_neg x
@[simp]
theorem seq_sub (f : FreeAbelianGroup (α → β)) (x y : FreeAbelianGroup α) :
f <*> x - y = (f <*> x) - (f <*> y) :=
(seqAddGroupHom f).map_sub x y
instance : LawfulMonad FreeAbelianGroup.{u} := LawfulMonad.mk'
(id_map := fun x ↦ FreeAbelianGroup.induction_on' x (FreeAbelianGroup.map_zero id) (map_pure id)
(fun x ih ↦ by rw [FreeAbelianGroup.map_neg, ih])
fun x y ihx ihy ↦ by rw [FreeAbelianGroup.map_add, ihx, ihy])
(pure_bind := fun x f ↦ pure_bind f x)
(bind_assoc := fun x f g ↦ FreeAbelianGroup.induction_on' x (by iterate 3 rw [zero_bind])
(fun x ↦ by iterate 2 rw [pure_bind]) (fun x ih ↦ by iterate 3 rw [neg_bind] <;> try rw [ih])
fun x y ihx ihy ↦ by iterate 3 rw [add_bind] <;> try rw [ihx, ihy])
instance : CommApplicative FreeAbelianGroup.{u} where
commutative_prod x y := by
refine FreeAbelianGroup.induction_on' x ?_ ?_ ?_ ?_
· rw [FreeAbelianGroup.map_zero, zero_seq, seq_zero]
· intro p
rw [map_pure, pure_seq]
exact FreeAbelianGroup.induction_on' y
(by rw [FreeAbelianGroup.map_zero, FreeAbelianGroup.map_zero, zero_seq])
(fun q ↦ by rw [map_pure, map_pure, pure_seq, map_pure])
(fun q ih ↦ by rw [FreeAbelianGroup.map_neg, FreeAbelianGroup.map_neg, neg_seq, ih])
fun y₁ y₂ ih1 ih2 ↦ by
rw [FreeAbelianGroup.map_add, FreeAbelianGroup.map_add, add_seq, ih1, ih2]
· intro p ih
rw [FreeAbelianGroup.map_neg, neg_seq, seq_neg, ih]
· intro x₁ x₂ ih1 ih2
rw [FreeAbelianGroup.map_add, add_seq, seq_add, ih1, ih2]
end Monad
universe w
variable {β : Type v} {γ : Type w}
/-- The additive group homomorphism `FreeAbelianGroup α →+ FreeAbelianGroup β` induced from a
map `α → β`. -/
def map (f : α → β) : FreeAbelianGroup α →+ FreeAbelianGroup β :=
lift (of ∘ f)
theorem lift_comp {α} {β} {γ} [AddCommGroup γ] (f : α → β) (g : β → γ) (x : FreeAbelianGroup α) :
lift (g ∘ f) x = lift g (map f x) := by
induction x using FreeAbelianGroup.induction_on with
| C0 => simp only [map_zero]
| C1 => simp only [lift.of, map, Function.comp]
| Cn _ h => simp only [h, AddMonoidHom.map_neg]
| Cp _ _ h₁ h₂ => simp only [h₁, h₂, AddMonoidHom.map_add]
theorem map_id : map id = AddMonoidHom.id (FreeAbelianGroup α) :=
Eq.symm <|
lift.ext _ _ fun _ ↦ lift.unique of (AddMonoidHom.id _) fun _ ↦ AddMonoidHom.id_apply _ _
theorem map_id_apply (x : FreeAbelianGroup α) : map id x = x := by
rw [map_id]
rfl
theorem map_comp {f : α → β} {g : β → γ} : map (g ∘ f) = (map g).comp (map f) :=
Eq.symm <| lift.ext _ _ fun _ ↦ by simp [map]
theorem map_comp_apply {f : α → β} {g : β → γ} (x : FreeAbelianGroup α) :
map (g ∘ f) x = (map g) ((map f) x) := by
rw [map_comp]
rfl
-- version of map_of which uses `map`
@[simp]
theorem map_of_apply {f : α → β} (a : α) : map f (of a) = of (f a) :=
rfl
variable (α)
| section Mul
| Mathlib/GroupTheory/FreeAbelianGroup.lean | 383 | 384 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Algebra.Basic
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Eval.Algebra
import Mathlib.Tactic.Abel
/-!
# The Pochhammer polynomials
We define and prove some basic relations about
`ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)`
which is also known as the rising factorial and about
`descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)`
which is also known as the falling factorial. Versions of this definition
that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and
`Nat.descFactorial`.
## Implementation
As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` ,
we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`.
In an integral domain `S`, we show that `ascPochhammer S n` is zero iff
`n` is a sufficiently large non-positive integer.
## TODO
There is lots more in this direction:
* q-factorials, q-binomials, q-Pochhammer.
-/
universe u v
open Polynomial
section Semiring
variable (S : Type u) [Semiring S]
/-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`,
with coefficients in the semiring `S`.
-/
noncomputable def ascPochhammer : ℕ → S[X]
| 0 => 1
| n + 1 => X * (ascPochhammer n).comp (X + 1)
@[simp]
theorem ascPochhammer_zero : ascPochhammer S 0 = 1 :=
rfl
@[simp]
theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer]
theorem ascPochhammer_succ_left (n : ℕ) :
ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by
rw [ascPochhammer]
theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] :
Monic <| ascPochhammer S n := by
induction' n with n hn
· simp
· have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1
rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul,
leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn,
monic_X, one_mul, one_mul, this, one_pow]
section
variable {S} {T : Type v} [Semiring T]
@[simp]
theorem ascPochhammer_map (f : S →+* T) (n : ℕ) :
(ascPochhammer S n).map f = ascPochhammer T n := by
induction n with
| zero => simp
| succ n ih => simp [ih, ascPochhammer_succ_left, map_comp]
theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) :
(ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by
rw [← ascPochhammer_map f]
exact eval_map f t
theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S]
(x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x =
(ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by
rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S),
← map_comp, eval_map]
end
@[simp, norm_cast]
theorem ascPochhammer_eval_cast (n k : ℕ) :
(((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by
rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S),
eval₂_at_natCast,Nat.cast_id]
theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by
cases n
· simp
· simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left]
theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp
@[simp]
theorem ascPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (ascPochhammer S n).eval 0 = 0 := by
simp [ascPochhammer_eval_zero, h]
theorem ascPochhammer_succ_right (n : ℕ) :
ascPochhammer S (n + 1) = ascPochhammer S n * (X + (n : S[X])) := by
suffices h : ascPochhammer ℕ (n + 1) = ascPochhammer ℕ n * (X + (n : ℕ[X])) by
apply_fun Polynomial.map (algebraMap ℕ S) at h
simpa only [ascPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X,
Polynomial.map_natCast] using h
induction n with
| zero => simp
| succ n ih =>
conv_lhs =>
rw [ascPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← ascPochhammer_succ_left, add_comp,
X_comp, natCast_comp, add_assoc, add_comm (1 : ℕ[X]), ← Nat.cast_succ]
theorem ascPochhammer_succ_eval {S : Type*} [Semiring S] (n : ℕ) (k : S) :
(ascPochhammer S (n + 1)).eval k = (ascPochhammer S n).eval k * (k + n) := by
rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast,
eval_C_mul, Nat.cast_comm, ← mul_add]
theorem ascPochhammer_succ_comp_X_add_one (n : ℕ) :
(ascPochhammer S (n + 1)).comp (X + 1) =
ascPochhammer S (n + 1) + (n + 1) • (ascPochhammer S n).comp (X + 1) := by
suffices (ascPochhammer ℕ (n + 1)).comp (X + 1) =
ascPochhammer ℕ (n + 1) + (n + 1) * (ascPochhammer ℕ n).comp (X + 1)
by simpa [map_comp] using congr_arg (Polynomial.map (Nat.castRingHom S)) this
nth_rw 2 [ascPochhammer_succ_left]
rw [← add_mul, ascPochhammer_succ_right ℕ n, mul_comp, mul_comm, add_comp, X_comp, natCast_comp,
add_comm, ← add_assoc]
ring
theorem ascPochhammer_mul (n m : ℕ) :
ascPochhammer S n * (ascPochhammer S m).comp (X + (n : S[X])) = ascPochhammer S (n + m) := by
induction' m with m ih
· simp
· rw [ascPochhammer_succ_right, Polynomial.mul_X_add_natCast_comp, ← mul_assoc, ih,
← add_assoc, ascPochhammer_succ_right, Nat.cast_add, add_assoc]
theorem ascPochhammer_nat_eq_ascFactorial (n : ℕ) :
∀ k, (ascPochhammer ℕ k).eval n = n.ascFactorial k
| 0 => by rw [ascPochhammer_zero, eval_one, Nat.ascFactorial_zero]
| t + 1 => by
rw [ascPochhammer_succ_right, eval_mul, ascPochhammer_nat_eq_ascFactorial n t, eval_add, eval_X,
eval_natCast, Nat.cast_id, Nat.ascFactorial_succ, mul_comm]
theorem ascPochhammer_nat_eq_natCast_ascFactorial (S : Type*) [Semiring S] (n k : ℕ) :
(ascPochhammer S k).eval (n : S) = n.ascFactorial k := by
norm_cast
rw [ascPochhammer_nat_eq_ascFactorial]
theorem ascPochhammer_nat_eq_descFactorial (a b : ℕ) :
(ascPochhammer ℕ b).eval a = (a + b - 1).descFactorial b := by
rw [ascPochhammer_nat_eq_ascFactorial, Nat.add_descFactorial_eq_ascFactorial']
theorem ascPochhammer_nat_eq_natCast_descFactorial (S : Type*) [Semiring S] (a b : ℕ) :
(ascPochhammer S b).eval (a : S) = (a + b - 1).descFactorial b := by
norm_cast
rw [ascPochhammer_nat_eq_descFactorial]
@[simp]
theorem ascPochhammer_natDegree (n : ℕ) [NoZeroDivisors S] [Nontrivial S] :
(ascPochhammer S n).natDegree = n := by
induction' n with n hn
· simp
· have : natDegree (X + (n : S[X])) = 1 := natDegree_X_add_C (n : S)
rw [ascPochhammer_succ_right,
natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this]
cases n
· simp
· refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _
end Semiring
section StrictOrderedSemiring
variable {S : Type*} [Semiring S] [PartialOrder S] [IsStrictOrderedRing S]
theorem ascPochhammer_pos (n : ℕ) (s : S) (h : 0 < s) : 0 < (ascPochhammer S n).eval s := by
induction n with
| zero =>
simp only [ascPochhammer_zero, eval_one]
exact zero_lt_one
| succ n ih =>
rw [ascPochhammer_succ_right, mul_add, eval_add, ← Nat.cast_comm, eval_natCast_mul, eval_mul_X,
Nat.cast_comm, ← mul_add]
exact mul_pos ih (lt_of_lt_of_le h (le_add_of_nonneg_right (Nat.cast_nonneg n)))
end StrictOrderedSemiring
section Factorial
open Nat
variable (S : Type*) [Semiring S] (r n : ℕ)
@[simp]
theorem ascPochhammer_eval_one (S : Type*) [Semiring S] (n : ℕ) :
(ascPochhammer S n).eval (1 : S) = (n ! : S) := by
rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.one_ascFactorial]
theorem factorial_mul_ascPochhammer (S : Type*) [Semiring S] (r n : ℕ) :
(r ! : S) * (ascPochhammer S n).eval (r + 1 : S) = (r + n)! := by
rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.factorial_mul_ascFactorial]
theorem ascPochhammer_nat_eval_succ (r : ℕ) :
∀ n : ℕ, n * (ascPochhammer ℕ r).eval (n + 1) = (n + r) * (ascPochhammer ℕ r).eval n
| 0 => by
by_cases h : r = 0
· simp only [h, zero_mul, zero_add]
· simp only [ascPochhammer_eval_zero, zero_mul, if_neg h, mul_zero]
| k + 1 => by simp only [ascPochhammer_nat_eq_ascFactorial, Nat.succ_ascFactorial, add_right_comm]
theorem ascPochhammer_eval_succ (r n : ℕ) :
(n : S) * (ascPochhammer S r).eval (n + 1 : S) =
(n + r) * (ascPochhammer S r).eval (n : S) :=
mod_cast congr_arg Nat.cast (ascPochhammer_nat_eval_succ r n)
end Factorial
section Ring
variable (R : Type u) [Ring R]
/-- `descPochhammer R n` is the polynomial `X * (X - 1) * ... * (X - n + 1)`,
with coefficients in the ring `R`.
-/
noncomputable def descPochhammer : ℕ → R[X]
| 0 => 1
| n + 1 => X * (descPochhammer n).comp (X - 1)
@[simp]
theorem descPochhammer_zero : descPochhammer R 0 = 1 :=
rfl
@[simp]
theorem descPochhammer_one : descPochhammer R 1 = X := by simp [descPochhammer]
theorem descPochhammer_succ_left (n : ℕ) :
descPochhammer R (n + 1) = X * (descPochhammer R n).comp (X - 1) := by
rw [descPochhammer]
theorem monic_descPochhammer (n : ℕ) [Nontrivial R] [NoZeroDivisors R] :
Monic <| descPochhammer R n := by
induction' n with n hn
· simp
· have h : leadingCoeff (X - 1 : R[X]) = 1 := leadingCoeff_X_sub_C 1
have : natDegree (X - (1 : R[X])) ≠ 0 := ne_zero_of_eq_one <| natDegree_X_sub_C (1 : R)
rw [descPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp this, hn, monic_X,
one_mul, one_mul, h, one_pow]
section
variable {R} {T : Type v} [Ring T]
@[simp]
theorem descPochhammer_map (f : R →+* T) (n : ℕ) :
(descPochhammer R n).map f = descPochhammer T n := by
induction n with
| zero => simp
| succ n ih => simp [ih, descPochhammer_succ_left, map_comp]
end
@[simp, norm_cast]
theorem descPochhammer_eval_cast (n : ℕ) (k : ℤ) :
(((descPochhammer ℤ n).eval k : ℤ) : R) = ((descPochhammer R n).eval k : R) := by
rw [← descPochhammer_map (algebraMap ℤ R), eval_map, ← eq_intCast (algebraMap ℤ R)]
simp only [algebraMap_int_eq, eq_intCast, eval₂_at_intCast, Nat.cast_id, eq_natCast, Int.cast_id]
theorem descPochhammer_eval_zero {n : ℕ} :
(descPochhammer R n).eval 0 = if n = 0 then 1 else 0 := by
cases n
· simp
· simp [X_mul, Nat.succ_ne_zero, descPochhammer_succ_left]
theorem descPochhammer_zero_eval_zero : (descPochhammer R 0).eval 0 = 1 := by simp
@[simp]
theorem descPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (descPochhammer R n).eval 0 = 0 := by
| simp [descPochhammer_eval_zero, h]
theorem descPochhammer_succ_right (n : ℕ) :
descPochhammer R (n + 1) = descPochhammer R n * (X - (n : R[X])) := by
suffices h : descPochhammer ℤ (n + 1) = descPochhammer ℤ n * (X - (n : ℤ[X])) by
| Mathlib/RingTheory/Polynomial/Pochhammer.lean | 289 | 293 |
/-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro, Anne Baanen,
Frédéric Dupuis, Heather Macbeth, Antoine Chambert-Loir
-/
import Mathlib.Algebra.Group.Pointwise.Set.Scalar
import Mathlib.Data.Set.Function
import Mathlib.GroupTheory.GroupAction.Hom
import Mathlib.Algebra.Group.Units.Hom
/-!
# Pointwise actions of equivariant maps
- `image_smul_setₛₗ` : under a `σ`-equivariant map,
one has `f '' (c • s) = (σ c) • f '' s`.
- `preimage_smul_setₛₗ'` is a general version of the equality
`f ⁻¹' (σ c • s) = c • f⁻¹' s`.
It requires that `c` acts surjectively and `σ c` acts injectively and
is provided with specific versions:
- `preimage_smul_setₛₗ_of_isUnit_isUnit` when `c` and `σ c` are units
- `IsUnit.preimage_smul_setₛₗ` when `σ` belongs to a `MonoidHomClass`and `c` is a unit
- `MonoidHom.preimage_smul_setₛₗ` when `σ` is a `MonoidHom` and `c` is a unit
- `Group.preimage_smul_setₛₗ` : when the types of `c` and `σ c` are groups.
- `image_smul_set`, `preimage_smul_set` and `Group.preimage_smul_set` are
the variants when `σ` is the identity.
-/
open Function Set Pointwise
section MulActionSemiHomClass
section SMul
variable {M N F : Type*} {α β : Type*} {σ : M → N} [SMul M α] [SMul N β] [FunLike F α β]
[MulActionSemiHomClass F σ α β] {f : F} {s : Set α} {t : Set β}
@[to_additive (attr := simp)]
theorem image_smul_setₛₗ (f : F) (c : M) (s : Set α) :
f '' (c • s) = σ c • f '' s :=
Semiconj.set_image (map_smulₛₗ f c) s
@[to_additive]
theorem Set.MapsTo.smul_setₛₗ (hst : MapsTo f s t) (c : M) : MapsTo f (c • s) (σ c • t) :=
Function.Semiconj.mapsTo_image_right (map_smulₛₗ _ _) hst
/-- Translation of preimage is contained in preimage of translation -/
@[to_additive]
theorem smul_preimage_set_subsetₛₗ (f : F) (c : M) (t : Set β) : c • f ⁻¹' t ⊆ f ⁻¹' (σ c • t) :=
((mapsTo_preimage f t).smul_setₛₗ c).subset_preimage
@[deprecated (since := "2025-03-03")]
alias vadd_preimage_set_leₛₗ := vadd_preimage_set_subsetₛₗ
@[to_additive existing, deprecated (since := "2025-03-03")]
alias smul_preimage_set_leₛₗ := smul_preimage_set_subsetₛₗ
/-- General version of `preimage_smul_setₛₗ`.
This version assumes that the scalar multiplication by `c` is surjective
while the scalar multiplication by `σ c` is injective. -/
@[to_additive "General version of `preimage_vadd_setₛₗ`.
This version assumes that the vector addition of `c` is surjective
while the vector addition of `σ c` is injective."]
theorem preimage_smul_setₛₗ' {c : M}
(hc : Function.Surjective (fun (m : α) ↦ c • m))
(hc' : Function.Injective (fun (n : β) ↦ σ c • n)) :
f ⁻¹' (σ c • t) = c • f ⁻¹' t := by
| refine Subset.antisymm ?_ (smul_preimage_set_subsetₛₗ f c t)
rw [subset_def, hc.forall]
rintro x ⟨y, hy, hxy⟩
rw [map_smulₛₗ, hc'.eq_iff] at hxy
subst y
exact smul_mem_smul_set hy
end SMul
section Monoid
variable {M N F : Type*} {α β : Type*} {σ : M → N} [Monoid M] [Monoid N]
[MulAction M α] [MulAction N β] [FunLike F α β] [MulActionSemiHomClass F σ α β]
| Mathlib/GroupTheory/GroupAction/Pointwise.lean | 72 | 84 |
/-
Copyright (c) 2022 Jake Levinson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jake Levinson
-/
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Finset.Prod
import Mathlib.Data.SetLike.Basic
import Mathlib.Order.UpperLower.Basic
/-!
# Young diagrams
A Young diagram is a finite set of up-left justified boxes:
```text
□□□□□
□□□
□□□
□
```
This Young diagram corresponds to the [5, 3, 3, 1] partition of 12.
We represent it as a lower set in `ℕ × ℕ` in the product partial order. We write `(i, j) ∈ μ`
to say that `(i, j)` (in matrix coordinates) is in the Young diagram `μ`.
## Main definitions
- `YoungDiagram` : Young diagrams
- `YoungDiagram.card` : the number of cells in a Young diagram (its *cardinality*)
- `YoungDiagram.instDistribLatticeYoungDiagram` : a distributive lattice instance for Young diagrams
ordered by containment, with `(⊥ : YoungDiagram)` the empty diagram.
- `YoungDiagram.row` and `YoungDiagram.rowLen`: rows of a Young diagram and their lengths
- `YoungDiagram.col` and `YoungDiagram.colLen`: columns of a Young diagram and their lengths
## Notation
In "English notation", a Young diagram is drawn so that (i1, j1) ≤ (i2, j2)
means (i1, j1) is weakly up-and-left of (i2, j2). This terminology is used
below, e.g. in `YoungDiagram.up_left_mem`.
## Tags
Young diagram
## References
<https://en.wikipedia.org/wiki/Young_tableau>
-/
open Function
/-- A Young diagram is a finite collection of cells on the `ℕ × ℕ` grid such that whenever
a cell is present, so are all the ones above and to the left of it. Like matrices, an `(i, j)` cell
is a cell in row `i` and column `j`, where rows are enumerated downward and columns rightward.
Young diagrams are modeled as finite sets in `ℕ × ℕ` that are lower sets with respect to the
standard order on products. -/
@[ext]
structure YoungDiagram where
/-- A finite set which represents a finite collection of cells on the `ℕ × ℕ` grid. -/
cells : Finset (ℕ × ℕ)
/-- Cells are up-left justified, witnessed by the fact that `cells` is a lower set in `ℕ × ℕ`. -/
isLowerSet : IsLowerSet (cells : Set (ℕ × ℕ))
namespace YoungDiagram
instance : SetLike YoungDiagram (ℕ × ℕ) where
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: figure out how to do this correctly
coe y := y.cells
coe_injective' μ ν h := by rwa [YoungDiagram.ext_iff, ← Finset.coe_inj]
@[simp]
theorem mem_cells {μ : YoungDiagram} (c : ℕ × ℕ) : c ∈ μ.cells ↔ c ∈ μ :=
Iff.rfl
@[simp]
theorem mem_mk (c : ℕ × ℕ) (cells) (isLowerSet) :
c ∈ YoungDiagram.mk cells isLowerSet ↔ c ∈ cells :=
Iff.rfl
instance decidableMem (μ : YoungDiagram) : DecidablePred (· ∈ μ) :=
inferInstanceAs (DecidablePred (· ∈ μ.cells))
/-- In "English notation", a Young diagram is drawn so that (i1, j1) ≤ (i2, j2)
means (i1, j1) is weakly up-and-left of (i2, j2). -/
theorem up_left_mem (μ : YoungDiagram) {i1 i2 j1 j2 : ℕ} (hi : i1 ≤ i2) (hj : j1 ≤ j2)
(hcell : (i2, j2) ∈ μ) : (i1, j1) ∈ μ :=
μ.isLowerSet (Prod.mk_le_mk.mpr ⟨hi, hj⟩) hcell
section DistribLattice
@[simp]
theorem cells_subset_iff {μ ν : YoungDiagram} : μ.cells ⊆ ν.cells ↔ μ ≤ ν :=
Iff.rfl
@[simp]
theorem cells_ssubset_iff {μ ν : YoungDiagram} : μ.cells ⊂ ν.cells ↔ μ < ν :=
Iff.rfl
instance : Max YoungDiagram where
max μ ν :=
{ cells := μ.cells ∪ ν.cells
isLowerSet := by
rw [Finset.coe_union]
exact μ.isLowerSet.union ν.isLowerSet }
@[simp]
theorem cells_sup (μ ν : YoungDiagram) : (μ ⊔ ν).cells = μ.cells ∪ ν.cells :=
rfl
@[simp, norm_cast]
theorem coe_sup (μ ν : YoungDiagram) : ↑(μ ⊔ ν) = (μ ∪ ν : Set (ℕ × ℕ)) :=
Finset.coe_union _ _
@[simp]
theorem mem_sup {μ ν : YoungDiagram} {x : ℕ × ℕ} : x ∈ μ ⊔ ν ↔ x ∈ μ ∨ x ∈ ν :=
Finset.mem_union
instance : Min YoungDiagram where
min μ ν :=
{ cells := μ.cells ∩ ν.cells
isLowerSet := by
rw [Finset.coe_inter]
exact μ.isLowerSet.inter ν.isLowerSet }
@[simp]
theorem cells_inf (μ ν : YoungDiagram) : (μ ⊓ ν).cells = μ.cells ∩ ν.cells :=
rfl
@[simp, norm_cast]
theorem coe_inf (μ ν : YoungDiagram) : ↑(μ ⊓ ν) = (μ ∩ ν : Set (ℕ × ℕ)) :=
Finset.coe_inter _ _
@[simp]
theorem mem_inf {μ ν : YoungDiagram} {x : ℕ × ℕ} : x ∈ μ ⊓ ν ↔ x ∈ μ ∧ x ∈ ν :=
Finset.mem_inter
/-- The empty Young diagram is (⊥ : young_diagram). -/
instance : OrderBot YoungDiagram where
bot :=
{ cells := ∅
isLowerSet := by
intros a b _ h
simp only [Finset.coe_empty, Set.mem_empty_iff_false]
simp only [Finset.coe_empty, Set.mem_empty_iff_false] at h }
bot_le _ _ := by
intro y
simp only [mem_mk, Finset.not_mem_empty] at y
@[simp]
theorem cells_bot : (⊥ : YoungDiagram).cells = ∅ :=
rfl
@[simp]
theorem not_mem_bot (x : ℕ × ℕ) : x ∉ (⊥ : YoungDiagram) :=
Finset.not_mem_empty x
@[norm_cast]
theorem coe_bot : (⊥ : YoungDiagram) = (∅ : Set (ℕ × ℕ)) := by
ext; simp
instance : Inhabited YoungDiagram :=
⟨⊥⟩
instance : DistribLattice YoungDiagram :=
Function.Injective.distribLattice YoungDiagram.cells (fun μ ν h => by rwa [YoungDiagram.ext_iff])
(fun _ _ => rfl) fun _ _ => rfl
end DistribLattice
/-- Cardinality of a Young diagram -/
protected abbrev card (μ : YoungDiagram) : ℕ :=
μ.cells.card
section Transpose
/-- The `transpose` of a Young diagram is obtained by swapping i's with j's. -/
def transpose (μ : YoungDiagram) : YoungDiagram where
cells := (Equiv.prodComm _ _).finsetCongr μ.cells
isLowerSet _ _ h := by
simp only [Finset.mem_coe, Equiv.finsetCongr_apply, Finset.mem_map_equiv]
intro hcell
apply μ.isLowerSet _ hcell
simp [h]
@[simp]
theorem mem_transpose {μ : YoungDiagram} {c : ℕ × ℕ} : c ∈ μ.transpose ↔ c.swap ∈ μ := by
simp [transpose]
@[simp]
theorem transpose_transpose (μ : YoungDiagram) : μ.transpose.transpose = μ := by
ext x
simp
theorem transpose_eq_iff_eq_transpose {μ ν : YoungDiagram} : μ.transpose = ν ↔ μ = ν.transpose := by
constructor <;>
· rintro rfl
simp
@[simp]
theorem transpose_eq_iff {μ ν : YoungDiagram} : μ.transpose = ν.transpose ↔ μ = ν := by
rw [transpose_eq_iff_eq_transpose]
simp
-- This is effectively both directions of `transpose_le_iff` below.
protected theorem le_of_transpose_le {μ ν : YoungDiagram} (h_le : μ.transpose ≤ ν) :
μ ≤ ν.transpose := fun c hc => by
simp only [mem_cells, mem_transpose]
apply h_le
simpa
@[simp]
theorem transpose_le_iff {μ ν : YoungDiagram} : μ.transpose ≤ ν.transpose ↔ μ ≤ ν :=
⟨fun h => by
convert YoungDiagram.le_of_transpose_le h
simp, fun h => by
rw [← transpose_transpose μ] at h
exact YoungDiagram.le_of_transpose_le h ⟩
@[mono]
protected theorem transpose_mono {μ ν : YoungDiagram} (h_le : μ ≤ ν) : μ.transpose ≤ ν.transpose :=
transpose_le_iff.mpr h_le
/-- Transposing Young diagrams is an `OrderIso`. -/
@[simps]
def transposeOrderIso : YoungDiagram ≃o YoungDiagram :=
⟨⟨transpose, transpose, fun _ => by simp, fun _ => by simp⟩, by simp⟩
end Transpose
section Rows
/-! ### Rows and row lengths of Young diagrams.
This section defines `μ.row` and `μ.rowLen`, with the following API:
1. `(i, j) ∈ μ ↔ j < μ.rowLen i`
2. `μ.row i = {i} ×ˢ (Finset.range (μ.rowLen i))`
3. `μ.rowLen i = (μ.row i).card`
4. `∀ {i1 i2}, i1 ≤ i2 → μ.rowLen i2 ≤ μ.rowLen i1`
Note: #3 is not convenient for defining `μ.rowLen`; instead, `μ.rowLen` is defined
as the smallest `j` such that `(i, j) ∉ μ`. -/
/-- The `i`-th row of a Young diagram consists of the cells whose first coordinate is `i`. -/
def row (μ : YoungDiagram) (i : ℕ) : Finset (ℕ × ℕ) :=
μ.cells.filter fun c => c.fst = i
theorem mem_row_iff {μ : YoungDiagram} {i : ℕ} {c : ℕ × ℕ} : c ∈ μ.row i ↔ c ∈ μ ∧ c.fst = i := by
simp [row]
theorem mk_mem_row_iff {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ.row i ↔ (i, j) ∈ μ := by simp [row]
protected theorem exists_not_mem_row (μ : YoungDiagram) (i : ℕ) : ∃ j, (i, j) ∉ μ := by
obtain ⟨j, hj⟩ :=
Infinite.exists_not_mem_finset
(μ.cells.preimage (Prod.mk i) fun _ _ _ _ h => by
cases h
rfl)
rw [Finset.mem_preimage] at hj
exact ⟨j, hj⟩
/-- Length of a row of a Young diagram -/
def rowLen (μ : YoungDiagram) (i : ℕ) : ℕ :=
Nat.find <| μ.exists_not_mem_row i
theorem mem_iff_lt_rowLen {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ ↔ j < μ.rowLen i := by
rw [rowLen, Nat.lt_find_iff]
push_neg
exact ⟨fun h _ hmj => μ.up_left_mem (by rfl) hmj h, fun h => h _ (by rfl)⟩
theorem row_eq_prod {μ : YoungDiagram} {i : ℕ} : μ.row i = {i} ×ˢ Finset.range (μ.rowLen i) := by
ext ⟨a, b⟩
simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_row_iff,
mem_iff_lt_rowLen, and_comm, and_congr_right_iff]
rintro rfl
rfl
theorem rowLen_eq_card (μ : YoungDiagram) {i : ℕ} : μ.rowLen i = (μ.row i).card := by
simp [row_eq_prod]
@[mono]
theorem rowLen_anti (μ : YoungDiagram) (i1 i2 : ℕ) (hi : i1 ≤ i2) : μ.rowLen i2 ≤ μ.rowLen i1 := by
by_contra! h_lt
rw [← lt_self_iff_false (μ.rowLen i1)]
rw [← mem_iff_lt_rowLen] at h_lt ⊢
exact μ.up_left_mem hi (by rfl) h_lt
end Rows
section Columns
/-! ### Columns and column lengths of Young diagrams.
This section has an identical API to the rows section. -/
/-- The `j`-th column of a Young diagram consists of the cells whose second coordinate is `j`. -/
def col (μ : YoungDiagram) (j : ℕ) : Finset (ℕ × ℕ) :=
μ.cells.filter fun c => c.snd = j
theorem mem_col_iff {μ : YoungDiagram} {j : ℕ} {c : ℕ × ℕ} : c ∈ μ.col j ↔ c ∈ μ ∧ c.snd = j := by
simp [col]
theorem mk_mem_col_iff {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ.col j ↔ (i, j) ∈ μ := by simp [col]
protected theorem exists_not_mem_col (μ : YoungDiagram) (j : ℕ) : ∃ i, (i, j) ∉ μ.cells := by
convert μ.transpose.exists_not_mem_row j using 1
simp
/-- Length of a column of a Young diagram -/
def colLen (μ : YoungDiagram) (j : ℕ) : ℕ :=
Nat.find <| μ.exists_not_mem_col j
@[simp]
theorem colLen_transpose (μ : YoungDiagram) (j : ℕ) : μ.transpose.colLen j = μ.rowLen j := by
simp [rowLen, colLen]
@[simp]
theorem rowLen_transpose (μ : YoungDiagram) (i : ℕ) : μ.transpose.rowLen i = μ.colLen i := by
simp [rowLen, colLen]
theorem mem_iff_lt_colLen {μ : YoungDiagram} {i j : ℕ} : (i, j) ∈ μ ↔ i < μ.colLen j := by
rw [← rowLen_transpose, ← mem_iff_lt_rowLen]
simp
theorem col_eq_prod {μ : YoungDiagram} {j : ℕ} : μ.col j = Finset.range (μ.colLen j) ×ˢ {j} := by
ext ⟨a, b⟩
simp only [Finset.mem_product, Finset.mem_singleton, Finset.mem_range, mem_col_iff,
mem_iff_lt_colLen, and_comm, and_congr_right_iff]
rintro rfl
rfl
theorem colLen_eq_card (μ : YoungDiagram) {j : ℕ} : μ.colLen j = (μ.col j).card := by
simp [col_eq_prod]
@[mono]
theorem colLen_anti (μ : YoungDiagram) (j1 j2 : ℕ) (hj : j1 ≤ j2) : μ.colLen j2 ≤ μ.colLen j1 := by
convert μ.transpose.rowLen_anti j1 j2 hj using 1 <;> simp
end Columns
section RowLens
/-! ### The list of row lengths of a Young diagram
This section defines `μ.rowLens : List ℕ`, the list of row lengths of a Young diagram `μ`.
1. `YoungDiagram.rowLens_sorted` : It is weakly decreasing (`List.Sorted (· ≥ ·)`).
2. `YoungDiagram.rowLens_pos` : It is strictly positive.
-/
/-- List of row lengths of a Young diagram -/
def rowLens (μ : YoungDiagram) : List ℕ :=
(List.range <| μ.colLen 0).map μ.rowLen
@[simp]
theorem get_rowLens {μ : YoungDiagram} {i : Nat} {h : i < μ.rowLens.length} :
μ.rowLens[i] = μ.rowLen i := by simp only [rowLens, List.getElem_range, List.getElem_map]
@[simp]
theorem length_rowLens {μ : YoungDiagram} : μ.rowLens.length = μ.colLen 0 := by
simp only [rowLens, List.length_map, List.length_range]
theorem rowLens_sorted (μ : YoungDiagram) : μ.rowLens.Sorted (· ≥ ·) :=
List.pairwise_le_range.map _ μ.rowLen_anti
theorem pos_of_mem_rowLens (μ : YoungDiagram) (x : ℕ) (hx : x ∈ μ.rowLens) : 0 < x := by
rw [rowLens, List.mem_map] at hx
obtain ⟨i, hi, rfl : μ.rowLen i = x⟩ := hx
rwa [List.mem_range, ← mem_iff_lt_colLen, mem_iff_lt_rowLen] at hi
end RowLens
section EquivListRowLens
/-! ### Equivalence between Young diagrams and lists of natural numbers
This section defines the equivalence between Young diagrams `μ` and weakly decreasing lists `w`
of positive natural numbers, corresponding to row lengths of the diagram:
`YoungDiagram.equivListRowLens :`
`YoungDiagram ≃ {w : List ℕ // w.Sorted (· ≥ ·) ∧ ∀ x ∈ w, 0 < x}`
The two directions are `YoungDiagram.rowLens` (defined above) and `YoungDiagram.ofRowLens`.
-/
/-- The cells making up a `YoungDiagram` from a list of row lengths -/
protected def cellsOfRowLens : List ℕ → Finset (ℕ × ℕ)
| [] => ∅
| w::ws =>
({0} : Finset ℕ) ×ˢ Finset.range w ∪
(YoungDiagram.cellsOfRowLens ws).map
(Embedding.prodMap ⟨_, Nat.succ_injective⟩ (Embedding.refl ℕ))
protected theorem mem_cellsOfRowLens {w : List ℕ} {c : ℕ × ℕ} :
c ∈ YoungDiagram.cellsOfRowLens w ↔ ∃ h : c.fst < w.length, c.snd < w[c.fst] := by
induction w generalizing c <;> rw [YoungDiagram.cellsOfRowLens]
· simp [YoungDiagram.cellsOfRowLens]
· rcases c with ⟨⟨_, _⟩, _⟩ <;> simp_all
/-- Young diagram from a sorted list -/
def ofRowLens (w : List ℕ) (hw : w.Sorted (· ≥ ·)) : YoungDiagram where
cells := YoungDiagram.cellsOfRowLens w
isLowerSet := by
rintro ⟨i2, j2⟩ ⟨i1, j1⟩ ⟨hi : i1 ≤ i2, hj : j1 ≤ j2⟩ hcell
rw [Finset.mem_coe, YoungDiagram.mem_cellsOfRowLens] at hcell ⊢
obtain ⟨h1, h2⟩ := hcell
refine ⟨hi.trans_lt h1, ?_⟩
calc
j1 ≤ j2 := hj
_ < w[i2] := h2
_ ≤ w[i1] := by
obtain rfl | h := eq_or_lt_of_le hi
· rfl
· exact List.pairwise_iff_get.mp hw _ _ h
theorem mem_ofRowLens {w : List ℕ} {hw : w.Sorted (· ≥ ·)} {c : ℕ × ℕ} :
c ∈ ofRowLens w hw ↔ ∃ h : c.fst < w.length, c.snd < w[c.fst] :=
YoungDiagram.mem_cellsOfRowLens
/-- The number of rows in `ofRowLens w hw` is the length of `w` -/
theorem rowLens_length_ofRowLens {w : List ℕ} {hw : w.Sorted (· ≥ ·)} (hpos : ∀ x ∈ w, 0 < x) :
(ofRowLens w hw).rowLens.length = w.length := by
simp only [length_rowLens, colLen, Nat.find_eq_iff, mem_cells, mem_ofRowLens,
lt_self_iff_false, IsEmpty.exists_iff, Classical.not_not]
exact ⟨not_false, fun n hn => ⟨hn, hpos _ (List.getElem_mem hn)⟩⟩
/-- The length of the `i`th row in `ofRowLens w hw` is the `i`th entry of `w` -/
theorem rowLen_ofRowLens {w : List ℕ} {hw : w.Sorted (· ≥ ·)} (i : Fin w.length) :
(ofRowLens w hw).rowLen i = w[i] := by
simp [rowLen, Nat.find_eq_iff, mem_ofRowLens]
/-- The left_inv direction of the equivalence -/
theorem ofRowLens_to_rowLens_eq_self {μ : YoungDiagram} : ofRowLens _ (rowLens_sorted μ) = μ := by
ext ⟨i, j⟩
simp only [mem_cells, mem_ofRowLens, length_rowLens, get_rowLens]
simpa [← mem_iff_lt_colLen, mem_iff_lt_rowLen] using j.zero_le.trans_lt
/-- The right_inv direction of the equivalence -/
theorem rowLens_ofRowLens_eq_self {w : List ℕ} {hw : w.Sorted (· ≥ ·)} (hpos : ∀ x ∈ w, 0 < x) :
(ofRowLens w hw).rowLens = w :=
List.ext_get (rowLens_length_ofRowLens hpos) fun i h₁ h₂ =>
(get_rowLens (h := h₁)).trans <| rowLen_ofRowLens ⟨i, h₂⟩
/-- Equivalence between Young diagrams and weakly decreasing lists of positive natural numbers.
A Young diagram `μ` is equivalent to a list of row lengths. -/
@[simps]
def equivListRowLens : YoungDiagram ≃ { w : List ℕ // w.Sorted (· ≥ ·) ∧ ∀ x ∈ w, 0 < x } where
toFun μ := ⟨μ.rowLens, μ.rowLens_sorted, μ.pos_of_mem_rowLens⟩
invFun ww := ofRowLens ww.1 ww.2.1
left_inv _ := ofRowLens_to_rowLens_eq_self
right_inv := fun ⟨_, hw⟩ => Subtype.mk_eq_mk.mpr (rowLens_ofRowLens_eq_self hw.2)
end EquivListRowLens
end YoungDiagram
| Mathlib/Combinatorics/Young/YoungDiagram.lean | 492 | 496 | |
/-
Copyright (c) 2021 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Damiano Testa, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Division
import Mathlib.Algebra.Polynomial.Degree.Operations
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Order.Interval.Finset.Nat
/-!
# Induction on polynomials
This file contains lemmas dealing with different flavours of induction on polynomials.
-/
noncomputable section
open Polynomial
open Finset
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ}
section Semiring
variable [Semiring R] {p q : R[X]}
/-- `divX p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`.
It can be used in a semiring where the usual division algorithm is not possible -/
def divX (p : R[X]) : R[X] :=
⟨AddMonoidAlgebra.divOf p.toFinsupp 1⟩
@[simp]
theorem coeff_divX : (divX p).coeff n = p.coeff (n + 1) := by
rw [add_comm]; cases p; rfl
theorem divX_mul_X_add (p : R[X]) : divX p * X + C (p.coeff 0) = p :=
ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, Nat.succ_ne_zero, coeff_mul_X]
@[simp]
theorem X_mul_divX_add (p : R[X]) : X * divX p + C (p.coeff 0) = p :=
ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, Nat.succ_ne_zero, coeff_mul_X]
@[simp]
theorem divX_C (a : R) : divX (C a) = 0 :=
ext fun n => by simp [coeff_divX, coeff_C, Finsupp.single_eq_of_ne _]
theorem divX_eq_zero_iff : divX p = 0 ↔ p = C (p.coeff 0) :=
⟨fun h => by simpa [eq_comm, h] using divX_mul_X_add p, fun h => by rw [h, divX_C]⟩
theorem divX_add : divX (p + q) = divX p + divX q :=
ext <| by simp
@[simp]
theorem divX_zero : divX (0 : R[X]) = 0 := leadingCoeff_eq_zero.mp rfl
@[simp]
theorem divX_one : divX (1 : R[X]) = 0 := by
ext
simpa only [coeff_divX, coeff_zero] using coeff_one
@[simp]
theorem divX_C_mul : divX (C a * p) = C a * divX p := by
ext
simp
theorem divX_X_pow : divX (X ^ n : R[X]) = if (n = 0) then 0 else X ^ (n - 1) := by
cases n
· simp
· ext n
simp [coeff_X_pow]
/-- `divX` as an additive homomorphism. -/
noncomputable
def divX_hom : R[X] →+ R[X] :=
{ toFun := divX
map_zero' := divX_zero
map_add' := fun _ _ => divX_add }
@[simp] theorem divX_hom_toFun : divX_hom p = divX p := rfl
theorem natDegree_divX_eq_natDegree_tsub_one : p.divX.natDegree = p.natDegree - 1 := by
apply map_natDegree_eq_sub (φ := divX_hom)
· intro f
simpa [divX_hom, divX_eq_zero_iff] using eq_C_of_natDegree_eq_zero
· intros n c c0
rw [← C_mul_X_pow_eq_monomial, divX_hom_toFun, divX_C_mul, divX_X_pow]
split_ifs with n0
· simp [n0]
· exact natDegree_C_mul_X_pow (n - 1) c c0
theorem natDegree_divX_le : p.divX.natDegree ≤ p.natDegree :=
natDegree_divX_eq_natDegree_tsub_one.trans_le (Nat.pred_le _)
theorem divX_C_mul_X_pow : divX (C a * X ^ n) = if n = 0 then 0 else C a * X ^ (n - 1) := by
simp only [divX_C_mul, divX_X_pow, mul_ite, mul_zero]
|
theorem degree_divX_lt (hp0 : p ≠ 0) : (divX p).degree < p.degree := by
haveI := Nontrivial.of_polynomial_ne hp0
calc
degree (divX p) < (divX p * X + C (p.coeff 0)).degree :=
if h : degree p ≤ 0 then by
have h' : C (p.coeff 0) ≠ 0 := by rwa [← eq_C_of_degree_le_zero h]
rw [eq_C_of_degree_le_zero h, divX_C, degree_zero, zero_mul, zero_add]
exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 <| by simpa using h'))
| Mathlib/Algebra/Polynomial/Inductions.lean | 103 | 111 |
/-
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.GeomSum
import Mathlib.Algebra.GroupWithZero.Action.Defs
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Data.Nat.Lattice
import Mathlib.RingTheory.Nilpotent.Defs
import Mathlib.Algebra.BigOperators.Finprod
/-!
# Nilpotent elements
This file develops the basic theory of nilpotent elements. In particular it shows that the
nilpotent elements are closed under many operations.
For the definition of `nilradical`, see `Mathlib.RingTheory.Nilpotent.Lemmas`.
## Main definitions
* `isNilpotent_neg_iff`
* `Commute.isNilpotent_add`
* `Commute.isNilpotent_sub`
-/
universe u v
open Function Set
variable {R S : Type*} {x y : R}
theorem IsNilpotent.neg [Ring R] (h : IsNilpotent x) : IsNilpotent (-x) := by
| obtain ⟨n, hn⟩ := h
use n
rw [neg_pow, hn, mul_zero]
| Mathlib/RingTheory/Nilpotent/Basic.lean | 40 | 43 |
/-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Bhavik Mehta
-/
import Mathlib.Analysis.Calculus.Deriv.Support
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.MeasureTheory.Function.Jacobian
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
import Mathlib.MeasureTheory.Measure.Haar.NormedSpace
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Links between an integral and its "improper" version
In its current state, mathlib only knows how to talk about definite ("proper") integrals,
in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over
`[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of
the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**.
Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample
is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral.
Although definite integrals have better properties, they are hardly usable when it comes to
computing integrals on unbounded sets, which is much easier using limits. Thus, in this file,
we prove various ways of studying the proper integral by studying the improper one.
## Definitions
The main definition of this file is `MeasureTheory.AECover`. It is a rather technical definition
whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably
generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α`
equipped with a measure `μ`, one should think of a hypothesis `hφ : MeasureTheory.AECover μ l φ` as
a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x
in φ i, f x ∂μ` as `i` tends to `l`.
When using this definition with a measure restricted to a set `s`, which happens fairly often, one
should not try too hard to use a `MeasureTheory.AECover` of subsets of `s`, as it often makes proofs
more complicated than necessary. See for example the proof of
`MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto` where we use `(fun x ↦ oi x)` as a
`MeasureTheory.AECover` w.r.t. `μ.restrict (Iic b)`, instead of using `(fun x ↦ Ioc x b)`.
## Main statements
- `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated` : if `φ` is a
`MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is a measurable
`ENNReal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l`
- `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` : if `φ` is a
`MeasureTheory.AECover μ l`, where `l` is a countably generated filter, if `f` is measurable and
integrable on each `φ n`, and if `∫ x in φ n, ‖f x‖ ∂μ` tends to some `I : ℝ` as n tends to `l`,
then `f` is integrable
- `MeasureTheory.AECover.integral_tendsto_of_countably_generated` : if `φ` is a
`MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is measurable
and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`.
We then specialize these lemmas to various use cases involving intervals, which are frequent
in analysis. In particular,
- `MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto` is a version of FTC-2 on the interval
`(a, +∞)`, giving the formula `∫ x in (a, +∞), g' x = l - g a` if `g'` is integrable and
`g` tends to `l` at `+∞`.
- `MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg` gives the same result assuming that
`g'` is nonnegative instead of integrable. Its automatic integrability in this context is proved
in `MeasureTheory.integrableOn_Ioi_deriv_of_nonneg`.
- `MeasureTheory.integral_comp_smul_deriv_Ioi` is a version of the change of variables formula
on semi-infinite intervals.
- `MeasureTheory.tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi` shows that a function whose
derivative is integrable on `(a, +∞)` has a limit at `+∞`.
- `MeasureTheory.tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi` shows that an integrable function
whose derivative is integrable on `(a, +∞)` tends to `0` at `+∞`.
Versions of these results are also given on the intervals `(-∞, a]` and `(-∞, +∞)`, as well as
the corresponding versions of integration by parts.
-/
open MeasureTheory Filter Set TopologicalSpace Topology
open scoped ENNReal NNReal
namespace MeasureTheory
section AECover
variable {α ι : Type*} [MeasurableSpace α] (μ : Measure α) (l : Filter ι)
/-- A sequence `φ` of subsets of `α` is a `MeasureTheory.AECover` w.r.t. a measure `μ` and a filter
`l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if
each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of
proofs. It should be thought of as a sufficient condition for being able to interpret
`∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`.
See for example `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated`,
`MeasureTheory.AECover.integrable_of_integral_norm_tendsto` and
`MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/
structure AECover (φ : ι → Set α) : Prop where
ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i
protected measurableSet : ∀ i, MeasurableSet <| φ i
variable {μ} {l}
namespace AECover
/-!
## Operations on `AECover`s
-/
/-- Elementwise intersection of two `AECover`s is an `AECover`. -/
theorem inter {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hψ : AECover μ l ψ) :
AECover μ l (fun i ↦ φ i ∩ ψ i) where
ae_eventually_mem := hψ.1.mp <| hφ.1.mono fun _ ↦ Eventually.and
measurableSet _ := (hφ.2 _).inter (hψ.2 _)
theorem superset {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hsub : ∀ i, φ i ⊆ ψ i)
(hmeas : ∀ i, MeasurableSet (ψ i)) : AECover μ l ψ :=
⟨hφ.1.mono fun _x hx ↦ hx.mono fun i hi ↦ hsub i hi, hmeas⟩
theorem mono_ac {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≪ μ) :
AECover ν l φ := ⟨hle hφ.1, hφ.2⟩
theorem mono {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≤ μ) :
AECover ν l φ := hφ.mono_ac hle.absolutelyContinuous
end AECover
section MetricSpace
variable [PseudoMetricSpace α] [OpensMeasurableSpace α]
theorem aecover_ball {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) :
AECover μ l (fun i ↦ Metric.ball x (r i)) where
measurableSet _ := Metric.isOpen_ball.measurableSet
ae_eventually_mem := by
filter_upwards with y
filter_upwards [hr (Ioi_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha
theorem aecover_closedBall {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) :
AECover μ l (fun i ↦ Metric.closedBall x (r i)) where
measurableSet _ := Metric.isClosed_closedBall.measurableSet
ae_eventually_mem := by
filter_upwards with y
filter_upwards [hr (Ici_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha
end MetricSpace
section Preorderα
variable [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α]
{a b : ι → α}
theorem aecover_Ici (ha : Tendsto a l atBot) : AECover μ l fun i => Ici (a i) where
ae_eventually_mem := ae_of_all μ ha.eventually_le_atBot
measurableSet _ := measurableSet_Ici
theorem aecover_Iic (hb : Tendsto b l atTop) : AECover μ l fun i => Iic <| b i :=
aecover_Ici (α := αᵒᵈ) hb
theorem aecover_Icc (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) :
AECover μ l fun i => Icc (a i) (b i) :=
(aecover_Ici ha).inter (aecover_Iic hb)
end Preorderα
section LinearOrderα
variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α]
{a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop)
include ha in
theorem aecover_Ioi [NoMinOrder α] : AECover μ l fun i => Ioi (a i) where
ae_eventually_mem := ae_of_all μ ha.eventually_lt_atBot
measurableSet _ := measurableSet_Ioi
include hb in
theorem aecover_Iio [NoMaxOrder α] : AECover μ l fun i => Iio (b i) := aecover_Ioi (α := αᵒᵈ) hb
include ha hb
theorem aecover_Ioo [NoMinOrder α] [NoMaxOrder α] : AECover μ l fun i => Ioo (a i) (b i) :=
(aecover_Ioi ha).inter (aecover_Iio hb)
theorem aecover_Ioc [NoMinOrder α] : AECover μ l fun i => Ioc (a i) (b i) :=
(aecover_Ioi ha).inter (aecover_Iic hb)
theorem aecover_Ico [NoMaxOrder α] : AECover μ l fun i => Ico (a i) (b i) :=
(aecover_Ici ha).inter (aecover_Iio hb)
end LinearOrderα
section FiniteIntervals
variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α]
{a b : ι → α} {A B : α} (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B))
include ha in
theorem aecover_Ioi_of_Ioi : AECover (μ.restrict (Ioi A)) l fun i ↦ Ioi (a i) where
ae_eventually_mem := (ae_restrict_mem measurableSet_Ioi).mono fun _x hx ↦ ha.eventually <|
eventually_lt_nhds hx
measurableSet _ := measurableSet_Ioi
include hb in
theorem aecover_Iio_of_Iio : AECover (μ.restrict (Iio B)) l fun i ↦ Iio (b i) :=
aecover_Ioi_of_Ioi (α := αᵒᵈ) hb
include ha in
theorem aecover_Ioi_of_Ici : AECover (μ.restrict (Ioi A)) l fun i ↦ Ici (a i) :=
(aecover_Ioi_of_Ioi ha).superset (fun _ ↦ Ioi_subset_Ici_self) fun _ ↦ measurableSet_Ici
include hb in
theorem aecover_Iio_of_Iic : AECover (μ.restrict (Iio B)) l fun i ↦ Iic (b i) :=
aecover_Ioi_of_Ici (α := αᵒᵈ) hb
include ha hb in
theorem aecover_Ioo_of_Ioo : AECover (μ.restrict <| Ioo A B) l fun i => Ioo (a i) (b i) :=
((aecover_Ioi_of_Ioi ha).mono <| Measure.restrict_mono Ioo_subset_Ioi_self le_rfl).inter
((aecover_Iio_of_Iio hb).mono <| Measure.restrict_mono Ioo_subset_Iio_self le_rfl)
include ha hb in
theorem aecover_Ioo_of_Icc : AECover (μ.restrict <| Ioo A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Icc_self) fun _ ↦ measurableSet_Icc
include ha hb in
theorem aecover_Ioo_of_Ico : AECover (μ.restrict <| Ioo A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ico_self) fun _ ↦ measurableSet_Ico
include ha hb in
theorem aecover_Ioo_of_Ioc : AECover (μ.restrict <| Ioo A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ioc_self) fun _ ↦ measurableSet_Ioc
variable [NoAtoms μ]
theorem aecover_Ioc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ioc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ioc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ioc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ioc A B) l fun i => Ioo (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge
theorem aecover_Ico_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Ico_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Ico_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Ico_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Ico A B) l fun i => Ioo (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge
theorem aecover_Icc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Icc (a i) (b i) :=
(aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
theorem aecover_Icc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Ico (a i) (b i) :=
(aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
theorem aecover_Icc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Ioc (a i) (b i) :=
(aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
theorem aecover_Icc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) :
AECover (μ.restrict <| Icc A B) l fun i => Ioo (a i) (b i) :=
(aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge
end FiniteIntervals
protected theorem AECover.restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} :
AECover (μ.restrict s) l φ :=
hφ.mono Measure.restrict_le_self
theorem aecover_restrict_of_ae_imp {s : Set α} {φ : ι → Set α} (hs : MeasurableSet s)
(ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n)
(measurable : ∀ n, MeasurableSet <| φ n) : AECover (μ.restrict s) l φ where
ae_eventually_mem := by rwa [ae_restrict_iff' hs]
measurableSet := measurable
theorem AECover.inter_restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α}
(hs : MeasurableSet s) : AECover (μ.restrict s) l fun i => φ i ∩ s :=
aecover_restrict_of_ae_imp hs
(hφ.ae_eventually_mem.mono fun _x hx hxs => hx.mono fun _i hi => ⟨hi, hxs⟩) fun i =>
(hφ.measurableSet i).inter hs
theorem AECover.ae_tendsto_indicator {β : Type*} [Zero β] [TopologicalSpace β] (f : α → β)
{φ : ι → Set α} (hφ : AECover μ l φ) :
∀ᵐ x ∂μ, Tendsto (fun i => (φ i).indicator f x) l (𝓝 <| f x) :=
hφ.ae_eventually_mem.mono fun _x hx =>
tendsto_const_nhds.congr' <| hx.mono fun _n hn => (indicator_of_mem hn _).symm
theorem AECover.aemeasurable {β : Type*} [MeasurableSpace β] [l.IsCountablyGenerated] [l.NeBot]
{f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ)
(hfm : ∀ i, AEMeasurable f (μ.restrict <| φ i)) : AEMeasurable f μ := by
obtain ⟨u, hu⟩ := l.exists_seq_tendsto
have := aemeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n)
rwa [Measure.restrict_eq_self_of_ae_mem] at this
filter_upwards [hφ.ae_eventually_mem] with x hx using
mem_iUnion.mpr (hu.eventually hx).exists
theorem AECover.aestronglyMeasurable {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β]
[l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ)
(hfm : ∀ i, AEStronglyMeasurable f (μ.restrict <| φ i)) : AEStronglyMeasurable f μ := by
obtain ⟨u, hu⟩ := l.exists_seq_tendsto
have := aestronglyMeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n)
rwa [Measure.restrict_eq_self_of_ae_mem] at this
filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists
end AECover
theorem AECover.comp_tendsto {α ι ι' : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι}
{l' : Filter ι'} {φ : ι → Set α} (hφ : AECover μ l φ) {u : ι' → ι} (hu : Tendsto u l' l) :
AECover μ l' (φ ∘ u) where
ae_eventually_mem := hφ.ae_eventually_mem.mono fun _x hx => hu.eventually hx
measurableSet i := hφ.measurableSet (u i)
section AECoverUnionInterCountable
variable {α ι : Type*} [Countable ι] [MeasurableSpace α] {μ : Measure α}
theorem AECover.biUnion_Iic_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) :
AECover μ atTop fun n : ι => ⋃ (k) (_h : k ∈ Iic n), φ k :=
hφ.superset (fun _ ↦ subset_biUnion_of_mem right_mem_Iic) fun _ ↦ .biUnion (to_countable _)
fun _ _ ↦ (hφ.2 _)
theorem AECover.biInter_Ici_aecover [Preorder ι] {φ : ι → Set α}
(hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋂ (k) (_h : k ∈ Ici n), φ k where
ae_eventually_mem := hφ.ae_eventually_mem.mono fun x h ↦ by
simpa only [mem_iInter, mem_Ici, eventually_forall_ge_atTop]
measurableSet _ := .biInter (to_countable _) fun n _ => hφ.measurableSet n
end AECoverUnionInterCountable
section Lintegral
variable {α ι : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι}
private theorem lintegral_tendsto_of_monotone_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ)
(hmono : Monotone φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) :
Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) :=
let F n := (φ n).indicator f
have key₁ : ∀ n, AEMeasurable (F n) μ := fun n => hfm.indicator (hφ.measurableSet n)
have key₂ : ∀ᵐ x : α ∂μ, Monotone fun n => F n x := ae_of_all _ fun x _i _j hij =>
indicator_le_indicator_of_subset (hmono hij) (fun x => zero_le <| f x) x
have key₃ : ∀ᵐ x : α ∂μ, Tendsto (fun n => F n x) atTop (𝓝 (f x)) := hφ.ae_tendsto_indicator f
(lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr fun n =>
lintegral_indicator (hφ.measurableSet n) _
theorem AECover.lintegral_tendsto_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) {f : α → ℝ≥0∞}
(hfm : AEMeasurable f μ) : Tendsto (∫⁻ x in φ ·, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := by
have lim₁ := lintegral_tendsto_of_monotone_of_nat hφ.biInter_Ici_aecover
(fun i j hij => biInter_subset_biInter_left (Ici_subset_Ici.mpr hij)) hfm
have lim₂ := lintegral_tendsto_of_monotone_of_nat hφ.biUnion_Iic_aecover
(fun i j hij => biUnion_subset_biUnion_left (Iic_subset_Iic.mpr hij)) hfm
refine tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ (fun n ↦ ?_) fun n ↦ ?_
exacts [lintegral_mono_set (biInter_subset_of_mem left_mem_Ici),
lintegral_mono_set (subset_biUnion_of_mem right_mem_Iic)]
theorem AECover.lintegral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) :
Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 <| ∫⁻ x, f x ∂μ) :=
tendsto_of_seq_tendsto fun _u hu => (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm
theorem AECover.lintegral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : AEMeasurable f μ)
(htendsto : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I :=
tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto
theorem AECover.iSup_lintegral_eq_of_countably_generated [Nonempty ι] [l.NeBot]
[l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞}
(hfm : AEMeasurable f μ) : ⨆ i : ι, ∫⁻ x in φ i, f x ∂μ = ∫⁻ x, f x ∂μ := by
have := hφ.lintegral_tendsto_of_countably_generated hfm
refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt
(fun i => lintegral_mono' Measure.restrict_le_self le_rfl) fun w hw => ?_
exact (this.eventually_const_lt hw).exists
end Lintegral
section Integrable
variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E]
theorem AECover.integrable_of_lintegral_enorm_bounded [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ)
(hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ ENNReal.ofReal I) : Integrable f μ := by
refine ⟨hfm, (le_of_tendsto ?_ hbounded).trans_lt ENNReal.ofReal_lt_top⟩
exact hφ.lintegral_tendsto_of_countably_generated hfm.enorm
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_bounded :=
AECover.integrable_of_lintegral_enorm_bounded
theorem AECover.integrable_of_lintegral_enorm_tendsto [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ)
(htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 <| .ofReal I)) :
Integrable f μ := by
refine hφ.integrable_of_lintegral_enorm_bounded (max 1 (I + 1)) hfm ?_
refine htendsto.eventually (ge_mem_nhds ?_)
refine (ENNReal.ofReal_lt_ofReal_iff (lt_max_of_lt_left zero_lt_one)).2 ?_
exact lt_max_of_lt_right (lt_add_one I)
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_tendsto :=
AECover.integrable_of_lintegral_enorm_tendsto
theorem AECover.integrable_of_lintegral_enorm_bounded' [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ)
(hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ I) : Integrable f μ :=
hφ.integrable_of_lintegral_enorm_bounded I hfm
(by simpa only [ENNReal.ofReal_coe_nnreal] using hbounded)
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_bounded' :=
AECover.integrable_of_lintegral_enorm_bounded'
theorem AECover.integrable_of_lintegral_enorm_tendsto' [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ)
(htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 I)) : Integrable f μ :=
hφ.integrable_of_lintegral_enorm_tendsto I hfm
(by simpa only [ENNReal.ofReal_coe_nnreal] using htendsto)
@[deprecated (since := "2025-01-22")]
alias AECover.integrable_of_lintegral_nnnorm_tendsto' :=
AECover.integrable_of_lintegral_enorm_tendsto'
theorem AECover.integrable_of_integral_norm_bounded [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(hbounded : ∀ᶠ i in l, (∫ x in φ i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by
have hfm : AEStronglyMeasurable f μ :=
hφ.aestronglyMeasurable fun i => (hfi i).aestronglyMeasurable
refine hφ.integrable_of_lintegral_enorm_bounded I hfm ?_
conv at hbounded in integral _ _ =>
rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun x => @norm_nonneg E _ (f x))
hfm.norm.restrict]
conv at hbounded in ENNReal.ofReal _ =>
rw [← coe_nnnorm, ENNReal.ofReal_coe_nnreal]
refine hbounded.mono fun i hi => ?_
rw [← ENNReal.ofReal_toReal <| ne_top_of_lt <| hasFiniteIntegral_iff_enorm.mp (hfi i).2]
apply ENNReal.ofReal_le_ofReal hi
theorem AECover.integrable_of_integral_norm_tendsto [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(htendsto : Tendsto (fun i => ∫ x in φ i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ :=
let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le
hφ.integrable_of_integral_norm_bounded I' hfi hI'
theorem AECover.integrable_of_integral_bounded_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, (∫ x in φ i, f x ∂μ) ≤ I) : Integrable f μ :=
hφ.integrable_of_integral_norm_bounded I hfi <| hbounded.mono fun _i hi =>
(integral_congr_ae <| ae_restrict_of_ae <| hnng.mono fun _ => Real.norm_of_nonneg).le.trans hi
theorem AECover.integrable_of_integral_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ)
(hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 I)) :
Integrable f μ :=
let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le
hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI'
end Integrable
section Integral
variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E]
[NormedSpace ℝ E]
theorem AECover.integral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → E} (hfi : Integrable f μ) :
Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) :=
suffices h : Tendsto (fun i => ∫ x : α, (φ i).indicator f x ∂μ) l (𝓝 (∫ x : α, f x ∂μ)) from by
convert h using 2; rw [integral_indicator (hφ.measurableSet _)]
tendsto_integral_filter_of_dominated_convergence (fun x => ‖f x‖)
(Eventually.of_forall fun i => hfi.aestronglyMeasurable.indicator <| hφ.measurableSet i)
(Eventually.of_forall fun _ => ae_of_all _ fun _ => norm_indicator_le_norm_self _ _) hfi.norm
(hφ.ae_tendsto_indicator f)
/-- Slight reformulation of
`MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/
theorem AECover.integral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α}
(hφ : AECover μ l φ) {f : α → E} (I : E) (hfi : Integrable f μ)
(h : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I :=
tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h
theorem AECover.integral_eq_of_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated]
{φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f)
(hfi : ∀ n, IntegrableOn f (φ n) μ) (htendsto : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) :
∫ x, f x ∂μ = I :=
have hfi' : Integrable f μ := hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto
hφ.integral_eq_of_tendsto I hfi' htendsto
end Integral
section IntegrableOfIntervalIntegral
variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [Filter.NeBot l] [IsCountablyGenerated l]
[NormedAddCommGroup E] {a b : ι → ℝ} {f : ℝ → E}
theorem integrable_of_intervalIntegral_norm_bounded (I : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot)
(hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a i..b i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by
have hφ : AECover μ l _ := aecover_Ioc ha hb
refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_)
filter_upwards [ha.eventually (eventually_le_atBot 0),
hb.eventually (eventually_ge_atTop 0)] with i hai hbi ht
rwa [← intervalIntegral.integral_of_le (hai.trans hbi)]
/-- If `f` is integrable on intervals `Ioc (a i) (b i)`,
where `a i` tends to -∞ and `b i` tends to ∞, and
`∫ x in a i .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`,
then `f` is integrable on the interval (-∞, ∞) -/
theorem integrable_of_intervalIntegral_norm_tendsto (I : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot)
(hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a i..b i, ‖f x‖ ∂μ) l (𝓝 I)) :
Integrable f μ :=
let ⟨I', hI'⟩ := h.isBoundedUnder_le
integrable_of_intervalIntegral_norm_bounded I' hfi ha hb hI'
theorem integrableOn_Iic_of_intervalIntegral_norm_bounded (I b : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot)
(h : ∀ᶠ i in l, (∫ x in a i..b, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Iic b) μ := by
have hφ : AECover (μ.restrict <| Iic b) l _ := aecover_Ioi ha
have hfi : ∀ i, IntegrableOn f (Ioi (a i)) (μ.restrict <| Iic b) := by
intro i
rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i)]
exact hfi i
refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_)
filter_upwards [ha.eventually (eventually_le_atBot b)] with i hai
rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)]
exact id
/-- If `f` is integrable on intervals `Ioc (a i) b`,
where `a i` tends to -∞, and
`∫ x in a i .. b, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`,
then `f` is integrable on the interval (-∞, b) -/
theorem integrableOn_Iic_of_intervalIntegral_norm_tendsto (I b : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot)
(h : Tendsto (fun i => ∫ x in a i..b, ‖f x‖ ∂μ) l (𝓝 I)) : IntegrableOn f (Iic b) μ :=
let ⟨I', hI'⟩ := h.isBoundedUnder_le
integrableOn_Iic_of_intervalIntegral_norm_bounded I' b hfi ha hI'
theorem integrableOn_Ioi_of_intervalIntegral_norm_bounded (I a : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop)
(h : ∀ᶠ i in l, (∫ x in a..b i, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Ioi a) μ := by
have hφ : AECover (μ.restrict <| Ioi a) l _ := aecover_Iic hb
have hfi : ∀ i, IntegrableOn f (Iic (b i)) (μ.restrict <| Ioi a) := by
intro i
rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i), inter_comm]
exact hfi i
refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_)
filter_upwards [hb.eventually (eventually_ge_atTop a)] with i hbi
rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i),
inter_comm]
exact id
/-- If `f` is integrable on intervals `Ioc a (b i)`,
where `b i` tends to ∞, and
`∫ x in a .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`,
then `f` is integrable on the interval (a, ∞) -/
theorem integrableOn_Ioi_of_intervalIntegral_norm_tendsto (I a : ℝ)
(hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop)
(h : Tendsto (fun i => ∫ x in a..b i, ‖f x‖ ∂μ) l (𝓝 <| I)) : IntegrableOn f (Ioi a) μ :=
let ⟨I', hI'⟩ := h.isBoundedUnder_le
integrableOn_Ioi_of_intervalIntegral_norm_bounded I' a hfi hb hI'
theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded {I a₀ b₀ : ℝ}
(hfi : ∀ i, IntegrableOn f <| Ioc (a i) (b i)) (ha : Tendsto a l <| 𝓝 a₀)
(hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ‖f x‖) ≤ I) :
IntegrableOn f (Ioc a₀ b₀) := by
refine (aecover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I
(fun i => (hfi i).restrict) (h.mono fun i hi ↦ ?_)
rw [Measure.restrict_restrict measurableSet_Ioc]
refine le_trans (setIntegral_mono_set (hfi i).norm ?_ ?_) hi <;> apply ae_of_all
· simp only [Pi.zero_apply, norm_nonneg, forall_const]
· intro c hc; exact hc.1
theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_left {I a₀ b : ℝ}
(hfi : ∀ i, IntegrableOn f <| Ioc (a i) b) (ha : Tendsto a l <| 𝓝 a₀)
(h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b) :=
integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi ha tendsto_const_nhds h
theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_right {I a b₀ : ℝ}
(hfi : ∀ i, IntegrableOn f <| Ioc a (b i)) (hb : Tendsto b l <| 𝓝 b₀)
(h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a b₀) :=
integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi tendsto_const_nhds hb h
end IntegrableOfIntervalIntegral
section IntegralOfIntervalIntegral
variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [IsCountablyGenerated l]
[NormedAddCommGroup E] [NormedSpace ℝ E] {a b : ι → ℝ} {f : ℝ → E}
theorem intervalIntegral_tendsto_integral (hfi : Integrable f μ) (ha : Tendsto a l atBot)
(hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a i..b i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by
let φ i := Ioc (a i) (b i)
have hφ : AECover μ l φ := aecover_Ioc ha hb
refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_
filter_upwards [ha.eventually (eventually_le_atBot 0),
hb.eventually (eventually_ge_atTop 0)] with i hai hbi
exact (intervalIntegral.integral_of_le (hai.trans hbi)).symm
theorem intervalIntegral_tendsto_integral_Iic (b : ℝ) (hfi : IntegrableOn f (Iic b) μ)
(ha : Tendsto a l atBot) :
Tendsto (fun i => ∫ x in a i..b, f x ∂μ) l (𝓝 <| ∫ x in Iic b, f x ∂μ) := by
let φ i := Ioi (a i)
have hφ : AECover (μ.restrict <| Iic b) l φ := aecover_Ioi ha
refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_
filter_upwards [ha.eventually (eventually_le_atBot <| b)] with i hai
rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)]
rfl
theorem intervalIntegral_tendsto_integral_Ioi (a : ℝ) (hfi : IntegrableOn f (Ioi a) μ)
(hb : Tendsto b l atTop) :
Tendsto (fun i => ∫ x in a..b i, f x ∂μ) l (𝓝 <| ∫ x in Ioi a, f x ∂μ) := by
let φ i := Iic (b i)
have hφ : AECover (μ.restrict <| Ioi a) l φ := aecover_Iic hb
refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_
filter_upwards [hb.eventually (eventually_ge_atTop <| a)] with i hbi
rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i),
inter_comm]
rfl
end IntegralOfIntervalIntegral
open Real
open scoped Interval
section IoiFTC
variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a l : ℝ} {m : E} [NormedAddCommGroup E]
[NormedSpace ℝ E]
/-- If the derivative of a function defined on the real line is integrable close to `+∞`, then
the function has a limit at `+∞`. -/
theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi [CompleteSpace E]
(hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) :
Tendsto f atTop (𝓝 (limUnder atTop f)) := by
suffices ∃ a, Tendsto f atTop (𝓝 a) from tendsto_nhds_limUnder this
suffices CauchySeq f from cauchySeq_tendsto_of_complete this
apply Metric.cauchySeq_iff'.2 (fun ε εpos ↦ ?_)
have A : ∀ᶠ (n : ℕ) in atTop, ∫ (x : ℝ) in Ici ↑n, ‖f' x‖ < ε := by
have L : Tendsto (fun (n : ℕ) ↦ ∫ x in Ici (n : ℝ), ‖f' x‖) atTop
(𝓝 (∫ x in ⋂ (n : ℕ), Ici (n : ℝ), ‖f' x‖)) := by
apply tendsto_setIntegral_of_antitone (fun n ↦ measurableSet_Ici)
· intro m n hmn
exact Ici_subset_Ici.2 (Nat.cast_le.mpr hmn)
· rcases exists_nat_gt a with ⟨n, hn⟩
exact ⟨n, IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 hn)⟩
have B : ⋂ (n : ℕ), Ici (n : ℝ) = ∅ := by
apply eq_empty_of_forall_not_mem (fun x ↦ ?_)
simpa only [mem_iInter, mem_Ici, not_forall, not_le] using exists_nat_gt x
simp only [B, Measure.restrict_empty, integral_zero_measure] at L
exact (tendsto_order.1 L).2 _ εpos
have B : ∀ᶠ (n : ℕ) in atTop, a < n := by
rcases exists_nat_gt a with ⟨n, hn⟩
filter_upwards [Ioi_mem_atTop n] with m (hm : n < m) using hn.trans (Nat.cast_lt.mpr hm)
rcases (A.and B).exists with ⟨N, hN, h'N⟩
refine ⟨N, fun x hx ↦ ?_⟩
calc
dist (f x) (f ↑N)
= ‖f x - f N‖ := dist_eq_norm _ _
_ = ‖∫ t in Ioc ↑N x, f' t‖ := by
rw [← intervalIntegral.integral_of_le hx, intervalIntegral.integral_eq_sub_of_hasDerivAt]
· intro y hy
simp only [hx, uIcc_of_le, mem_Icc] at hy
exact hderiv _ (h'N.trans_le hy.1)
· rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx]
exact f'int.mono_set (Ioc_subset_Ioi_self.trans (Ioi_subset_Ioi h'N.le))
_ ≤ ∫ t in Ioc ↑N x, ‖f' t‖ := norm_integral_le_integral_norm fun a ↦ f' a
_ ≤ ∫ t in Ici ↑N, ‖f' t‖ := by
apply setIntegral_mono_set
· apply IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 h'N)
· filter_upwards with x using norm_nonneg _
· have : Ioc (↑N) x ⊆ Ici ↑N := Ioc_subset_Ioi_self.trans Ioi_subset_Ici_self
exact this.eventuallyLE
_ < ε := hN
open UniformSpace in
/-- If a function and its derivative are integrable on `(a, +∞)`, then the function tends to zero
at `+∞`. -/
theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi
(hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x)
(f'int : IntegrableOn f' (Ioi a)) (fint : IntegrableOn f (Ioi a)) :
Tendsto f atTop (𝓝 0) := by
let F : E →L[ℝ] Completion E := Completion.toComplL
have Fderiv : ∀ x ∈ Ioi a, HasDerivAt (F ∘ f) (F (f' x)) x :=
fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx)
have Fint : IntegrableOn (F ∘ f) (Ioi a) := by apply F.integrable_comp fint
have F'int : IntegrableOn (F ∘ f') (Ioi a) := by apply F.integrable_comp f'int
have A : Tendsto (F ∘ f) atTop (𝓝 (limUnder atTop (F ∘ f))) := by
apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi Fderiv F'int
have B : limUnder atTop (F ∘ f) = F 0 := by
have : IntegrableAtFilter (F ∘ f) atTop := by exact ⟨Ioi a, Ioi_mem_atTop _, Fint⟩
apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A
intro s hs
rcases mem_atTop_sets.1 hs with ⟨b, hb⟩
rw [← top_le_iff, ← volume_Ici (a := b)]
exact measure_mono hb
rwa [B, ← IsEmbedding.tendsto_nhds_iff] at A
exact (Completion.isUniformEmbedding_coe E).isEmbedding
variable [CompleteSpace E]
/-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`.
When a function has a limit at infinity `m`, and its derivative is integrable, then the
integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability
on `(a, +∞)` and continuity at `a⁺`.
Note that such a function always has a limit at infinity,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/
theorem integral_Ioi_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a))
(hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by
have hcont : ContinuousOn f (Ici a) := by
intro x hx
rcases hx.out.eq_or_lt with rfl|hx
· exact hcont
· exact (hderiv x hx).continuousAt.continuousWithinAt
refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi a f'int tendsto_id) ?_
apply Tendsto.congr' _ (hf.sub_const _)
filter_upwards [Ioi_mem_atTop a] with x hx
have h'x : a ≤ id x := le_of_lt hx
symm
apply
intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self)
fun y hy => hderiv y hy.1
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x]
exact f'int.mono (fun y hy => hy.1) le_rfl
/-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`.
When a function has a limit at infinity `m`, and its derivative is integrable, then the
integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability
on `[a, +∞)`.
Note that such a function always has a limit at infinity,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/
theorem integral_Ioi_of_hasDerivAt_of_tendsto' (hderiv : ∀ x ∈ Ici a, HasDerivAt f (f' x) x)
(f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) :
∫ x in Ioi a, f' x = m - f a := by
refine integral_Ioi_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le)
f'int hf
exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt
/-- A special case of `integral_Ioi_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with
compact support. -/
theorem _root_.HasCompactSupport.integral_Ioi_deriv_eq (hf : ContDiff ℝ 1 f)
(h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Ioi b, deriv f x = - f b := by
have := fun x (_ : x ∈ Ioi b) ↦ hf.differentiable le_rfl x |>.hasDerivAt
rw [integral_Ioi_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, zero_sub]
· refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn
rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f
exact h2f.filter_mono _root_.atTop_le_cocompact |>.tendsto
/-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `(a, +∞)` and continuity at `a⁺`. -/
theorem integrableOn_Ioi_deriv_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x)
(hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
have hcont : ContinuousOn g (Ici a) := by
intro x hx
rcases hx.out.eq_or_lt with rfl|hx
· exact hcont
· exact (hderiv x hx).continuousAt.continuousWithinAt
refine integrableOn_Ioi_of_intervalIntegral_norm_tendsto (l - g a) a (fun x => ?_) tendsto_id ?_
· exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self)
(fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1
apply Tendsto.congr' _ (hg.sub_const _)
filter_upwards [Ioi_mem_atTop a] with x hx
have h'x : a ≤ id x := le_of_lt hx
calc
g x - g a = ∫ y in a..id x, g' y := by
symm
apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x
(hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x]
exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self)
(fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1
_ = ∫ y in a..id x, ‖g' y‖ := by
simp_rw [intervalIntegral.integral_of_le h'x]
refine setIntegral_congr_fun measurableSet_Ioc fun y hy => ?_
dsimp
rw [abs_of_nonneg]
exact g'pos _ hy.1
/-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `[a, +∞)`. -/
theorem integrableOn_Ioi_deriv_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
refine integrableOn_Ioi_deriv_of_nonneg ?_ (fun x hx => hderiv x hx.out.le) g'pos hg
exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt
/-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and
continuity at `a⁺`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x)
(hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv
(integrableOn_Ioi_deriv_of_nonneg hcont hderiv g'pos hg) hg
/-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonneg' hderiv g'pos hg)
hg
/-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `(a, +∞)` and continuity at `a⁺`. -/
theorem integrableOn_Ioi_deriv_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0)
(hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
apply integrable_neg_iff.1
exact integrableOn_Ioi_deriv_of_nonneg hcont.neg (fun x hx => (hderiv x hx).neg)
(fun x hx => neg_nonneg_of_nonpos (g'neg x hx)) hg.neg
/-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative
is automatically integrable on `(a, +∞)`. Version assuming differentiability
on `[a, +∞)`. -/
theorem integrableOn_Ioi_deriv_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by
refine integrableOn_Ioi_deriv_of_nonpos ?_ (fun x hx ↦ hderiv x hx.out.le) g'neg hg
exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt
/-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and
continuity at `a⁺`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a)
(hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0)
(hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv
(integrableOn_Ioi_deriv_of_nonpos hcont hderiv g'neg hg) hg
/-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the
integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see
`integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/
theorem integral_Ioi_of_hasDerivAt_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x)
(g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a :=
integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonpos' hderiv g'neg hg)
hg
end IoiFTC
section IicFTC
variable {E : Type*} {f f' : ℝ → E} {a : ℝ} {m : E} [NormedAddCommGroup E]
[NormedSpace ℝ E]
/-- If the derivative of a function defined on the real line is integrable close to `-∞`, then
the function has a limit at `-∞`. -/
theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic [CompleteSpace E]
(hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) :
Tendsto f atBot (𝓝 (limUnder atBot f)) := by
suffices ∃ a, Tendsto f atBot (𝓝 a) from tendsto_nhds_limUnder this
let g := f ∘ (fun x ↦ -x)
have hdg : ∀ x ∈ Ioi (-a), HasDerivAt g (-f' (-x)) x := by
intro x hx
have : -x ∈ Iic a := by simp only [mem_Iic, mem_Ioi, neg_le] at *; exact hx.le
simpa using HasDerivAt.scomp x (hderiv (-x) this) (hasDerivAt_neg' x)
have L : Tendsto g atTop (𝓝 (limUnder atTop g)) := by
apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi hdg
exact ((MeasurePreserving.integrableOn_comp_preimage (Measure.measurePreserving_neg _)
(Homeomorph.neg ℝ).measurableEmbedding).2 f'int.neg).mono_set (by simp)
refine ⟨limUnder atTop g, ?_⟩
have : Tendsto (fun x ↦ g (-x)) atBot (𝓝 (limUnder atTop g)) := L.comp tendsto_neg_atBot_atTop
simpa [g] using this
open UniformSpace in
/-- If a function and its derivative are integrable on `(-∞, a]`, then the function tends to zero
at `-∞`. -/
theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Iic
(hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x)
(f'int : IntegrableOn f' (Iic a)) (fint : IntegrableOn f (Iic a)) :
Tendsto f atBot (𝓝 0) := by
let F : E →L[ℝ] Completion E := Completion.toComplL
have Fderiv : ∀ x ∈ Iic a, HasDerivAt (F ∘ f) (F (f' x)) x :=
fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx)
have Fint : IntegrableOn (F ∘ f) (Iic a) := by apply F.integrable_comp fint
have F'int : IntegrableOn (F ∘ f') (Iic a) := by apply F.integrable_comp f'int
have A : Tendsto (F ∘ f) atBot (𝓝 (limUnder atBot (F ∘ f))) := by
apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic Fderiv F'int
have B : limUnder atBot (F ∘ f) = F 0 := by
have : IntegrableAtFilter (F ∘ f) atBot := by exact ⟨Iic a, Iic_mem_atBot _, Fint⟩
apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A
intro s hs
rcases mem_atBot_sets.1 hs with ⟨b, hb⟩
apply le_antisymm (le_top)
rw [← volume_Iic (a := b)]
exact measure_mono hb
rwa [B, ← IsEmbedding.tendsto_nhds_iff] at A
exact (Completion.isUniformEmbedding_coe E).isEmbedding
variable [CompleteSpace E]
/-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(-∞, a)`.
When a function has a limit `m` at `-∞`, and its derivative is integrable, then the
integral of the derivative on `(-∞, a)` is `f a - m`. Version assuming differentiability
on `(-∞, a)` and continuity at `a⁻`.
Note that such a function always has a limit at minus infinity,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic`. -/
theorem integral_Iic_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Iic a) a)
(hderiv : ∀ x ∈ Iio a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a))
(hf : Tendsto f atBot (𝓝 m)) : ∫ x in Iic a, f' x = f a - m := by
have hcont : ContinuousOn f (Iic a) := by
intro x hx
rcases hx.out.eq_or_lt with rfl|hx
· exact hcont
· exact (hderiv x hx).continuousAt.continuousWithinAt
refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Iic a f'int tendsto_id) ?_
apply Tendsto.congr' _ (hf.const_sub _)
filter_upwards [Iic_mem_atBot a] with x hx
symm
apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hx
(hcont.mono Icc_subset_Iic_self) fun y hy => hderiv y hy.2
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx]
exact f'int.mono (fun y hy => hy.2) le_rfl
/-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(-∞, a)`.
When a function has a limit `m` at `-∞`, and its derivative is integrable, then the
integral of the derivative on `(-∞, a)` is `f a - m`. Version assuming differentiability
on `(-∞, a]`.
Note that such a function always has a limit at minus infinity,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic`. -/
theorem integral_Iic_of_hasDerivAt_of_tendsto'
(hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a))
(hf : Tendsto f atBot (𝓝 m)) : ∫ x in Iic a, f' x = f a - m := by
refine integral_Iic_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le)
f'int hf
exact (hderiv a right_mem_Iic).continuousAt.continuousWithinAt
/-- A special case of `integral_Iic_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with
compact support. -/
theorem _root_.HasCompactSupport.integral_Iic_deriv_eq (hf : ContDiff ℝ 1 f)
(h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Iic b, deriv f x = f b := by
have := fun x (_ : x ∈ Iio b) ↦ hf.differentiable le_rfl x |>.hasDerivAt
rw [integral_Iic_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, sub_zero]
· refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn
rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f
exact h2f.filter_mono _root_.atBot_le_cocompact |>.tendsto
open UniformSpace in
lemma _root_.HasCompactSupport.enorm_le_lintegral_Ici_deriv
{F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F]
{f : ℝ → F} (hf : ContDiff ℝ 1 f) (h'f : HasCompactSupport f) (x : ℝ) :
‖f x‖ₑ ≤ ∫⁻ y in Iic x, ‖deriv f y‖ₑ := by
let I : F →L[ℝ] Completion F := Completion.toComplL
let f' : ℝ → Completion F := I ∘ f
have hf' : ContDiff ℝ 1 f' := hf.continuousLinearMap_comp I
have h'f' : HasCompactSupport f' := h'f.comp_left rfl
have : ‖f' x‖ₑ ≤ ∫⁻ y in Iic x, ‖deriv f' y‖ₑ := by
rw [← HasCompactSupport.integral_Iic_deriv_eq hf' h'f' x]
exact enorm_integral_le_lintegral_enorm _
convert this with y
· simp [f', I, Completion.enorm_coe]
· rw [fderiv_comp_deriv _ I.differentiableAt (hf.differentiable le_rfl _)]
simp only [ContinuousLinearMap.fderiv]
simp [I]
@[deprecated (since := "2025-01-22")]
alias _root_.HasCompactSupport.ennnorm_le_lintegral_Ici_deriv :=
HasCompactSupport.enorm_le_lintegral_Ici_deriv
end IicFTC
section UnivFTC
variable {E : Type*} {f f' : ℝ → E} {m n : E} [NormedAddCommGroup E]
[NormedSpace ℝ E]
/-- **Fundamental theorem of calculus-2**, on the whole real line
When a function has a limit `m` at `-∞` and `n` at `+∞`, and its derivative is integrable, then the
integral of the derivative is `n - m`.
Note that such a function always has a limit at `-∞` and `+∞`,
see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic` and
`tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/
theorem integral_of_hasDerivAt_of_tendsto [CompleteSpace E]
(hderiv : ∀ x, HasDerivAt f (f' x) x) (hf' : Integrable f')
(hbot : Tendsto f atBot (𝓝 m)) (htop : Tendsto f atTop (𝓝 n)) : ∫ x, f' x = n - m := by
rw [← setIntegral_univ, ← Set.Iic_union_Ioi (a := 0),
setIntegral_union (Iic_disjoint_Ioi le_rfl) measurableSet_Ioi hf'.integrableOn hf'.integrableOn,
integral_Iic_of_hasDerivAt_of_tendsto' (fun x _ ↦ hderiv x) hf'.integrableOn hbot,
integral_Ioi_of_hasDerivAt_of_tendsto' (fun x _ ↦ hderiv x) hf'.integrableOn htop]
abel
/-- If a function and its derivative are integrable on the real line, then the integral of the
derivative is zero. -/
theorem integral_eq_zero_of_hasDerivAt_of_integrable
(hderiv : ∀ x, HasDerivAt f (f' x) x) (hf' : Integrable f') (hf : Integrable f) :
∫ x, f' x = 0 := by
by_cases hE : CompleteSpace E; swap
· simp [integral, hE]
have A : Tendsto f atBot (𝓝 0) :=
tendsto_zero_of_hasDerivAt_of_integrableOn_Iic (a := 0) (fun x _hx ↦ hderiv x)
hf'.integrableOn hf.integrableOn
have B : Tendsto f atTop (𝓝 0) :=
tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (a := 0) (fun x _hx ↦ hderiv x)
hf'.integrableOn hf.integrableOn
simpa using integral_of_hasDerivAt_of_tendsto hderiv hf' A B
end UnivFTC
section IoiChangeVariables
open Real
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
/-- Change-of-variables formula for `Ioi` integrals of vector-valued functions, proved by taking
limits from the result for finite intervals. -/
theorem integral_comp_smul_deriv_Ioi {f f' : ℝ → ℝ} {g : ℝ → E} {a : ℝ}
(hf : ContinuousOn f <| Ici a) (hft : Tendsto f atTop atTop)
(hff' : ∀ x ∈ Ioi a, HasDerivWithinAt f (f' x) (Ioi x) x)
(hg_cont : ContinuousOn g <| f '' Ioi a) (hg1 : IntegrableOn g <| f '' Ici a)
(hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) (Ici a)) :
(∫ x in Ioi a, f' x • (g ∘ f) x) = ∫ u in Ioi (f a), g u := by
have eq : ∀ b : ℝ, a < b → (∫ x in a..b, f' x • (g ∘ f) x) = ∫ u in f a..f b, g u := fun b hb ↦ by
have i1 : Ioo (min a b) (max a b) ⊆ Ioi a := by
rw [min_eq_left hb.le]
exact Ioo_subset_Ioi_self
have i2 : [[a, b]] ⊆ Ici a := by rw [uIcc_of_le hb.le]; exact Icc_subset_Ici_self
refine
intervalIntegral.integral_comp_smul_deriv''' (hf.mono i2)
(fun x hx => hff' x <| mem_of_mem_of_subset hx i1) (hg_cont.mono <| image_subset _ ?_)
(hg1.mono_set <| image_subset _ ?_) (hg2.mono_set i2)
· rw [min_eq_left hb.le]; exact Ioo_subset_Ioi_self
· rw [uIcc_of_le hb.le]; exact Icc_subset_Ici_self
rw [integrableOn_Ici_iff_integrableOn_Ioi] at hg2
have t2 := intervalIntegral_tendsto_integral_Ioi _ hg2 tendsto_id
have : Ioi (f a) ⊆ f '' Ici a :=
Ioi_subset_Ici_self.trans <|
IsPreconnected.intermediate_value_Ici isPreconnected_Ici left_mem_Ici
(le_principal_iff.mpr <| Ici_mem_atTop _) hf hft
have t1 := (intervalIntegral_tendsto_integral_Ioi _ (hg1.mono_set this) tendsto_id).comp hft
exact tendsto_nhds_unique (Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop a) eq) t2) t1
/-- Change-of-variables formula for `Ioi` integrals of scalar-valued functions -/
theorem integral_comp_mul_deriv_Ioi {f f' : ℝ → ℝ} {g : ℝ → ℝ} {a : ℝ}
(hf : ContinuousOn f <| Ici a) (hft : Tendsto f atTop atTop)
(hff' : ∀ x ∈ Ioi a, HasDerivWithinAt f (f' x) (Ioi x) x)
(hg_cont : ContinuousOn g <| f '' Ioi a) (hg1 : IntegrableOn g <| f '' Ici a)
(hg2 : IntegrableOn (fun x => (g ∘ f) x * f' x) (Ici a)) :
(∫ x in Ioi a, (g ∘ f) x * f' x) = ∫ u in Ioi (f a), g u := by
have hg2' : IntegrableOn (fun x => f' x • (g ∘ f) x) (Ici a) := by simpa [mul_comm] using hg2
simpa [mul_comm] using integral_comp_smul_deriv_Ioi hf hft hff' hg_cont hg1 hg2'
/-- Substitution `y = x ^ p` in integrals over `Ioi 0` -/
theorem integral_comp_rpow_Ioi (g : ℝ → E) {p : ℝ} (hp : p ≠ 0) :
(∫ x in Ioi 0, (|p| * x ^ (p - 1)) • g (x ^ p)) = ∫ y in Ioi 0, g y := by
let S := Ioi (0 : ℝ)
have a1 : ∀ x : ℝ, x ∈ S → HasDerivWithinAt (fun t : ℝ => t ^ p) (p * x ^ (p - 1)) S x :=
fun x hx => (hasDerivAt_rpow_const (Or.inl (mem_Ioi.mp hx).ne')).hasDerivWithinAt
have a2 : InjOn (fun x : ℝ => x ^ p) S := by
rcases lt_or_gt_of_ne hp with (h | h)
· apply StrictAntiOn.injOn
intro x hx y hy hxy
rw [← inv_lt_inv₀ (rpow_pos_of_pos hx p) (rpow_pos_of_pos hy p), ← rpow_neg (le_of_lt hx),
← rpow_neg (le_of_lt hy)]
exact rpow_lt_rpow (le_of_lt hx) hxy (neg_pos.mpr h)
exact StrictMonoOn.injOn fun x hx y _ hxy => rpow_lt_rpow (mem_Ioi.mp hx).le hxy h
have a3 : (fun t : ℝ => t ^ p) '' S = S := by
ext1 x; rw [mem_image]; constructor
· rintro ⟨y, hy, rfl⟩; exact rpow_pos_of_pos hy p
· intro hx; refine ⟨x ^ (1 / p), rpow_pos_of_pos hx _, ?_⟩
rw [← rpow_mul (le_of_lt hx), one_div_mul_cancel hp, rpow_one]
have := integral_image_eq_integral_abs_deriv_smul measurableSet_Ioi a1 a2 g
rw [a3] at this; rw [this]
refine setIntegral_congr_fun measurableSet_Ioi ?_
intro x hx; dsimp only
rw [abs_mul, abs_of_nonneg (rpow_nonneg (le_of_lt hx) _)]
theorem integral_comp_rpow_Ioi_of_pos {g : ℝ → E} {p : ℝ} (hp : 0 < p) :
(∫ x in Ioi 0, (p * x ^ (p - 1)) • g (x ^ p)) = ∫ y in Ioi 0, g y := by
convert integral_comp_rpow_Ioi g hp.ne'
rw [abs_of_nonneg hp.le]
theorem integral_comp_mul_left_Ioi (g : ℝ → E) (a : ℝ) {b : ℝ} (hb : 0 < b) :
(∫ x in Ioi a, g (b * x)) = b⁻¹ • ∫ x in Ioi (b * a), g x := by
have : ∀ c : ℝ, MeasurableSet (Ioi c) := fun c => measurableSet_Ioi
rw [← integral_indicator (this a), ← integral_indicator (this (b * a)),
← abs_of_pos (inv_pos.mpr hb), ← Measure.integral_comp_mul_left]
congr
ext1 x
rw [← indicator_comp_right, preimage_const_mul_Ioi _ hb, mul_div_cancel_left₀ _ hb.ne']
rfl
theorem integral_comp_mul_right_Ioi (g : ℝ → E) (a : ℝ) {b : ℝ} (hb : 0 < b) :
(∫ x in Ioi a, g (x * b)) = b⁻¹ • ∫ x in Ioi (a * b), g x := by
simpa only [mul_comm] using integral_comp_mul_left_Ioi g a hb
end IoiChangeVariables
section IoiIntegrability
open Real
open scoped Interval
variable {E : Type*} [NormedAddCommGroup E]
/-- The substitution `y = x ^ p` in integrals over `Ioi 0` preserves integrability. -/
theorem integrableOn_Ioi_comp_rpow_iff [NormedSpace ℝ E] (f : ℝ → E) {p : ℝ} (hp : p ≠ 0) :
IntegrableOn (fun x => (|p| * x ^ (p - 1)) • f (x ^ p)) (Ioi 0) ↔ IntegrableOn f (Ioi 0) := by
let S := Ioi (0 : ℝ)
have a1 : ∀ x : ℝ, x ∈ S → HasDerivWithinAt (fun t : ℝ => t ^ p) (p * x ^ (p - 1)) S x :=
fun x hx => (hasDerivAt_rpow_const (Or.inl (mem_Ioi.mp hx).ne')).hasDerivWithinAt
have a2 : InjOn (fun x : ℝ => x ^ p) S := by
rcases lt_or_gt_of_ne hp with (h | h)
· apply StrictAntiOn.injOn
intro x hx y hy hxy
rw [← inv_lt_inv₀ (rpow_pos_of_pos hx p) (rpow_pos_of_pos hy p), ← rpow_neg (le_of_lt hx), ←
rpow_neg (le_of_lt hy)]
exact rpow_lt_rpow (le_of_lt hx) hxy (neg_pos.mpr h)
exact StrictMonoOn.injOn fun x hx y _hy hxy => rpow_lt_rpow (mem_Ioi.mp hx).le hxy h
have a3 : (fun t : ℝ => t ^ p) '' S = S := by
ext1 x; rw [mem_image]; constructor
· rintro ⟨y, hy, rfl⟩; exact rpow_pos_of_pos hy p
· intro hx; refine ⟨x ^ (1 / p), rpow_pos_of_pos hx _, ?_⟩
rw [← rpow_mul (le_of_lt hx), one_div_mul_cancel hp, rpow_one]
have := integrableOn_image_iff_integrableOn_abs_deriv_smul measurableSet_Ioi a1 a2 f
rw [a3] at this
rw [this]
refine integrableOn_congr_fun (fun x hx => ?_) measurableSet_Ioi
simp_rw [abs_mul, abs_of_nonneg (rpow_nonneg (le_of_lt hx) _)]
/-- The substitution `y = x ^ p` in integrals over `Ioi 0` preserves integrability (version
without `|p|` factor) -/
theorem integrableOn_Ioi_comp_rpow_iff' [NormedSpace ℝ E] (f : ℝ → E) {p : ℝ} (hp : p ≠ 0) :
IntegrableOn (fun x => x ^ (p - 1) • f (x ^ p)) (Ioi 0) ↔ IntegrableOn f (Ioi 0) := by
simpa only [← integrableOn_Ioi_comp_rpow_iff f hp, mul_smul] using
(integrable_smul_iff (abs_pos.mpr hp).ne' _).symm
theorem integrableOn_Ioi_comp_mul_left_iff (f : ℝ → E) (c : ℝ) {a : ℝ} (ha : 0 < a) :
IntegrableOn (fun x => f (a * x)) (Ioi c) ↔ IntegrableOn f (Ioi <| a * c) := by
rw [← integrable_indicator_iff (measurableSet_Ioi : MeasurableSet <| Ioi c)]
rw [← integrable_indicator_iff (measurableSet_Ioi : MeasurableSet <| Ioi <| a * c)]
convert integrable_comp_mul_left_iff ((Ioi (a * c)).indicator f) ha.ne' using 2
ext1 x
rw [← indicator_comp_right, preimage_const_mul_Ioi _ ha, mul_comm a c,
mul_div_cancel_right₀ _ ha.ne']
rfl
theorem integrableOn_Ioi_comp_mul_right_iff (f : ℝ → E) (c : ℝ) {a : ℝ} (ha : 0 < a) :
IntegrableOn (fun x => f (x * a)) (Ioi c) ↔ IntegrableOn f (Ioi <| c * a) := by
simpa only [mul_comm, mul_zero] using integrableOn_Ioi_comp_mul_left_iff f c ha
end IoiIntegrability
/-!
## Integration by parts
-/
section IntegrationByPartsBilinear
variable {E F G : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup G] [NormedSpace ℝ G]
{L : E →L[ℝ] F →L[ℝ] G} {u : ℝ → E} {v : ℝ → F} {u' : ℝ → E} {v' : ℝ → F}
{m n : G}
theorem integral_bilinear_hasDerivAt_eq_sub [CompleteSpace G]
(hu : ∀ x, HasDerivAt u (u' x) x) (hv : ∀ x, HasDerivAt v (v' x) x)
(huv : Integrable (fun x ↦ L (u x) (v' x) + L (u' x) (v x)))
(h_bot : Tendsto (fun x ↦ L (u x) (v x)) atBot (𝓝 m))
(h_top : Tendsto (fun x ↦ L (u x) (v x)) atTop (𝓝 n)) :
∫ (x : ℝ), L (u x) (v' x) + L (u' x) (v x) = n - m :=
integral_of_hasDerivAt_of_tendsto (fun x ↦ L.hasDerivAt_of_bilinear (hu x) (hv x))
huv h_bot h_top
/-- **Integration by parts on (-∞, ∞).**
With respect to a general bilinear form. For the specific case of multiplication, see
`integral_mul_deriv_eq_deriv_mul`. -/
theorem integral_bilinear_hasDerivAt_right_eq_sub [CompleteSpace G]
(hu : ∀ x, HasDerivAt u (u' x) x) (hv : ∀ x, HasDerivAt v (v' x) x)
(huv' : Integrable (fun x ↦ L (u x) (v' x))) (hu'v : Integrable (fun x ↦ L (u' x) (v x)))
(h_bot : Tendsto (fun x ↦ L (u x) (v x)) atBot (𝓝 m))
(h_top : Tendsto (fun x ↦ L (u x) (v x)) atTop (𝓝 n)) :
∫ (x : ℝ), L (u x) (v' x) = n - m - ∫ (x : ℝ), L (u' x) (v x) := by
rw [eq_sub_iff_add_eq, ← integral_add huv' hu'v]
exact integral_bilinear_hasDerivAt_eq_sub hu hv (huv'.add hu'v) h_bot h_top
/-- **Integration by parts on (-∞, ∞).**
With respect to a general bilinear form, assuming moreover that the total function is integrable.
-/
theorem integral_bilinear_hasDerivAt_right_eq_neg_left_of_integrable
(hu : ∀ x, HasDerivAt u (u' x) x) (hv : ∀ x, HasDerivAt v (v' x) x)
(huv' : Integrable (fun x ↦ L (u x) (v' x))) (hu'v : Integrable (fun x ↦ L (u' x) (v x)))
(huv : Integrable (fun x ↦ L (u x) (v x))) :
∫ (x : ℝ), L (u x) (v' x) = - ∫ (x : ℝ), L (u' x) (v x) := by
by_cases hG : CompleteSpace G; swap
· simp [integral, hG]
have I : Tendsto (fun x ↦ L (u x) (v x)) atBot (𝓝 0) :=
tendsto_zero_of_hasDerivAt_of_integrableOn_Iic (a := 0)
(fun x _hx ↦ L.hasDerivAt_of_bilinear (hu x) (hv x))
(huv'.add hu'v).integrableOn huv.integrableOn
have J : Tendsto (fun x ↦ L (u x) (v x)) atTop (𝓝 0) :=
tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (a := 0)
(fun x _hx ↦ L.hasDerivAt_of_bilinear (hu x) (hv x))
(huv'.add hu'v).integrableOn huv.integrableOn
simp [integral_bilinear_hasDerivAt_right_eq_sub hu hv huv' hu'v I J]
|
end IntegrationByPartsBilinear
section IntegrationByPartsAlgebra
variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A]
{a : ℝ} {a' b' : A} {u : ℝ → A} {v : ℝ → A} {u' : ℝ → A} {v' : ℝ → A}
/-- For finite intervals, see: `intervalIntegral.integral_deriv_mul_eq_sub`. -/
| Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean | 1,223 | 1,231 |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yaël Dillies
-/
import Mathlib.Algebra.Module.BigOperators
import Mathlib.GroupTheory.Perm.Basic
import Mathlib.GroupTheory.Perm.Finite
import Mathlib.GroupTheory.Perm.List
import Mathlib.GroupTheory.Perm.Sign
/-!
# Cycles of a permutation
This file starts the theory of cycles in permutations.
## Main definitions
In the following, `f : Equiv.Perm β`.
* `Equiv.Perm.SameCycle`: `f.SameCycle x y` when `x` and `y` are in the same cycle of `f`.
* `Equiv.Perm.IsCycle`: `f` is a cycle if any two nonfixed points of `f` are related by repeated
applications of `f`, and `f` is not the identity.
* `Equiv.Perm.IsCycleOn`: `f` is a cycle on a set `s` when any two points of `s` are related by
repeated applications of `f`.
## Notes
`Equiv.Perm.IsCycle` and `Equiv.Perm.IsCycleOn` are different in three ways:
* `IsCycle` is about the entire type while `IsCycleOn` is restricted to a set.
* `IsCycle` forbids the identity while `IsCycleOn` allows it (if `s` is a subsingleton).
* `IsCycleOn` forbids fixed points on `s` (if `s` is nontrivial), while `IsCycle` allows them.
-/
open Equiv Function Finset
variable {ι α β : Type*}
namespace Equiv.Perm
/-! ### `SameCycle` -/
section SameCycle
variable {f g : Perm α} {p : α → Prop} {x y z : α}
/-- The equivalence relation indicating that two points are in the same cycle of a permutation. -/
def SameCycle (f : Perm α) (x y : α) : Prop :=
∃ i : ℤ, (f ^ i) x = y
@[refl]
theorem SameCycle.refl (f : Perm α) (x : α) : SameCycle f x x :=
⟨0, rfl⟩
theorem SameCycle.rfl : SameCycle f x x :=
SameCycle.refl _ _
protected theorem _root_.Eq.sameCycle (h : x = y) (f : Perm α) : f.SameCycle x y := by rw [h]
@[symm]
theorem SameCycle.symm : SameCycle f x y → SameCycle f y x := fun ⟨i, hi⟩ =>
⟨-i, by rw [zpow_neg, ← hi, inv_apply_self]⟩
theorem sameCycle_comm : SameCycle f x y ↔ SameCycle f y x :=
⟨SameCycle.symm, SameCycle.symm⟩
@[trans]
theorem SameCycle.trans : SameCycle f x y → SameCycle f y z → SameCycle f x z :=
fun ⟨i, hi⟩ ⟨j, hj⟩ => ⟨j + i, by rw [zpow_add, mul_apply, hi, hj]⟩
variable (f) in
theorem SameCycle.equivalence : Equivalence (SameCycle f) :=
⟨SameCycle.refl f, SameCycle.symm, SameCycle.trans⟩
/-- The setoid defined by the `SameCycle` relation. -/
def SameCycle.setoid (f : Perm α) : Setoid α where
r := f.SameCycle
iseqv := SameCycle.equivalence f
@[simp]
theorem sameCycle_one : SameCycle 1 x y ↔ x = y := by simp [SameCycle]
@[simp]
theorem sameCycle_inv : SameCycle f⁻¹ x y ↔ SameCycle f x y :=
(Equiv.neg _).exists_congr_left.trans <| by simp [SameCycle]
alias ⟨SameCycle.of_inv, SameCycle.inv⟩ := sameCycle_inv
@[simp]
theorem sameCycle_conj : SameCycle (g * f * g⁻¹) x y ↔ SameCycle f (g⁻¹ x) (g⁻¹ y) :=
exists_congr fun i => by simp [conj_zpow, eq_inv_iff_eq]
theorem SameCycle.conj : SameCycle f x y → SameCycle (g * f * g⁻¹) (g x) (g y) := by
simp [sameCycle_conj]
theorem SameCycle.apply_eq_self_iff : SameCycle f x y → (f x = x ↔ f y = y) := fun ⟨i, hi⟩ => by
rw [← hi, ← mul_apply, ← zpow_one_add, add_comm, zpow_add_one, mul_apply,
(f ^ i).injective.eq_iff]
theorem SameCycle.eq_of_left (h : SameCycle f x y) (hx : IsFixedPt f x) : x = y :=
let ⟨_, hn⟩ := h
(hx.perm_zpow _).eq.symm.trans hn
theorem SameCycle.eq_of_right (h : SameCycle f x y) (hy : IsFixedPt f y) : x = y :=
h.eq_of_left <| h.apply_eq_self_iff.2 hy
@[simp]
theorem sameCycle_apply_left : SameCycle f (f x) y ↔ SameCycle f x y :=
(Equiv.addRight 1).exists_congr_left.trans <| by
simp [zpow_sub, SameCycle, Int.add_neg_one, Function.comp]
@[simp]
theorem sameCycle_apply_right : SameCycle f x (f y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_apply_left, sameCycle_comm]
@[simp]
theorem sameCycle_inv_apply_left : SameCycle f (f⁻¹ x) y ↔ SameCycle f x y := by
rw [← sameCycle_apply_left, apply_inv_self]
@[simp]
theorem sameCycle_inv_apply_right : SameCycle f x (f⁻¹ y) ↔ SameCycle f x y := by
rw [← sameCycle_apply_right, apply_inv_self]
@[simp]
theorem sameCycle_zpow_left {n : ℤ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y :=
(Equiv.addRight (n : ℤ)).exists_congr_left.trans <| by simp [SameCycle, zpow_add]
@[simp]
theorem sameCycle_zpow_right {n : ℤ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [sameCycle_comm, sameCycle_zpow_left, sameCycle_comm]
@[simp]
theorem sameCycle_pow_left {n : ℕ} : SameCycle f ((f ^ n) x) y ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_left]
@[simp]
theorem sameCycle_pow_right {n : ℕ} : SameCycle f x ((f ^ n) y) ↔ SameCycle f x y := by
rw [← zpow_natCast, sameCycle_zpow_right]
alias ⟨SameCycle.of_apply_left, SameCycle.apply_left⟩ := sameCycle_apply_left
alias ⟨SameCycle.of_apply_right, SameCycle.apply_right⟩ := sameCycle_apply_right
alias ⟨SameCycle.of_inv_apply_left, SameCycle.inv_apply_left⟩ := sameCycle_inv_apply_left
alias ⟨SameCycle.of_inv_apply_right, SameCycle.inv_apply_right⟩ := sameCycle_inv_apply_right
alias ⟨SameCycle.of_pow_left, SameCycle.pow_left⟩ := sameCycle_pow_left
alias ⟨SameCycle.of_pow_right, SameCycle.pow_right⟩ := sameCycle_pow_right
alias ⟨SameCycle.of_zpow_left, SameCycle.zpow_left⟩ := sameCycle_zpow_left
alias ⟨SameCycle.of_zpow_right, SameCycle.zpow_right⟩ := sameCycle_zpow_right
theorem SameCycle.of_pow {n : ℕ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
theorem SameCycle.of_zpow {n : ℤ} : SameCycle (f ^ n) x y → SameCycle f x y := fun ⟨m, h⟩ =>
⟨n * m, by simp [zpow_mul, h]⟩
@[simp]
theorem sameCycle_subtypePerm {h} {x y : { x // p x }} :
(f.subtypePerm h).SameCycle x y ↔ f.SameCycle x y :=
exists_congr fun n => by simp [Subtype.ext_iff]
alias ⟨_, SameCycle.subtypePerm⟩ := sameCycle_subtypePerm
@[simp]
theorem sameCycle_extendDomain {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} :
SameCycle (g.extendDomain f) (f x) (f y) ↔ g.SameCycle x y :=
exists_congr fun n => by
rw [← extendDomain_zpow, extendDomain_apply_image, Subtype.coe_inj, f.injective.eq_iff]
alias ⟨_, SameCycle.extendDomain⟩ := sameCycle_extendDomain
theorem SameCycle.exists_pow_eq' [Finite α] : SameCycle f x y → ∃ i < orderOf f, (f ^ i) x = y := by
rintro ⟨k, rfl⟩
use (k % orderOf f).natAbs
have h₀ := Int.natCast_pos.mpr (orderOf_pos f)
have h₁ := Int.emod_nonneg k h₀.ne'
rw [← zpow_natCast, Int.natAbs_of_nonneg h₁, zpow_mod_orderOf]
refine ⟨?_, by rfl⟩
rw [← Int.ofNat_lt, Int.natAbs_of_nonneg h₁]
exact Int.emod_lt_of_pos _ h₀
theorem SameCycle.exists_pow_eq'' [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, 0 < i ∧ i ≤ orderOf f ∧ (f ^ i) x = y := by
obtain ⟨_ | i, hi, rfl⟩ := h.exists_pow_eq'
· refine ⟨orderOf f, orderOf_pos f, le_rfl, ?_⟩
rw [pow_orderOf_eq_one, pow_zero]
· exact ⟨i.succ, i.zero_lt_succ, hi.le, by rfl⟩
theorem SameCycle.exists_fin_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : Fin (orderOf f), (f ^ (i : ℕ)) x = y := by
obtain ⟨i, hi, hx⟩ := SameCycle.exists_pow_eq' h
exact ⟨⟨i, hi⟩, hx⟩
theorem SameCycle.exists_nat_pow_eq [Finite α] (h : SameCycle f x y) :
∃ i : ℕ, (f ^ i) x = y := by
obtain ⟨i, _, hi⟩ := h.exists_pow_eq'
exact ⟨i, hi⟩
instance (f : Perm α) [DecidableRel (SameCycle f)] :
DecidableRel (SameCycle f⁻¹) := fun x y =>
decidable_of_iff (f.SameCycle x y) (sameCycle_inv).symm
instance (priority := 100) [DecidableEq α] : DecidableRel (SameCycle (1 : Perm α)) := fun x y =>
decidable_of_iff (x = y) sameCycle_one.symm
end SameCycle
/-!
### `IsCycle`
-/
section IsCycle
variable {f g : Perm α} {x y : α}
/-- A cycle is a non identity permutation where any two nonfixed points of the permutation are
related by repeated application of the permutation. -/
def IsCycle (f : Perm α) : Prop :=
∃ x, f x ≠ x ∧ ∀ ⦃y⦄, f y ≠ y → SameCycle f x y
theorem IsCycle.ne_one (h : IsCycle f) : f ≠ 1 := fun hf => by simp [hf, IsCycle] at h
@[simp]
theorem not_isCycle_one : ¬(1 : Perm α).IsCycle := fun H => H.ne_one rfl
protected theorem IsCycle.sameCycle (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
SameCycle f x y :=
let ⟨g, hg⟩ := hf
let ⟨a, ha⟩ := hg.2 hx
let ⟨b, hb⟩ := hg.2 hy
⟨b - a, by rw [← ha, ← mul_apply, ← zpow_add, sub_add_cancel, hb]⟩
theorem IsCycle.exists_zpow_eq : IsCycle f → f x ≠ x → f y ≠ y → ∃ i : ℤ, (f ^ i) x = y :=
IsCycle.sameCycle
theorem IsCycle.inv (hf : IsCycle f) : IsCycle f⁻¹ :=
hf.imp fun _ ⟨hx, h⟩ =>
⟨inv_eq_iff_eq.not.2 hx.symm, fun _ hy => (h <| inv_eq_iff_eq.not.2 hy.symm).inv⟩
@[simp]
theorem isCycle_inv : IsCycle f⁻¹ ↔ IsCycle f :=
⟨fun h => h.inv, IsCycle.inv⟩
theorem IsCycle.conj : IsCycle f → IsCycle (g * f * g⁻¹) := by
rintro ⟨x, hx, h⟩
refine ⟨g x, by simp [coe_mul, inv_apply_self, hx], fun y hy => ?_⟩
rw [← apply_inv_self g y]
exact (h <| eq_inv_iff_eq.not.2 hy).conj
protected theorem IsCycle.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p) :
IsCycle g → IsCycle (g.extendDomain f) := by
rintro ⟨a, ha, ha'⟩
refine ⟨f a, ?_, fun b hb => ?_⟩
· rw [extendDomain_apply_image]
exact Subtype.coe_injective.ne (f.injective.ne ha)
have h : b = f (f.symm ⟨b, of_not_not <| hb ∘ extendDomain_apply_not_subtype _ _⟩) := by
rw [apply_symm_apply, Subtype.coe_mk]
rw [h] at hb ⊢
simp only [extendDomain_apply_image, Subtype.coe_injective.ne_iff, f.injective.ne_iff] at hb
exact (ha' hb).extendDomain
theorem isCycle_iff_sameCycle (hx : f x ≠ x) : IsCycle f ↔ ∀ {y}, SameCycle f x y ↔ f y ≠ y :=
⟨fun hf y =>
⟨fun ⟨i, hi⟩ hy =>
hx <| by
rw [← zpow_apply_eq_self_of_apply_eq_self hy i, (f ^ i).injective.eq_iff] at hi
rw [hi, hy],
hf.exists_zpow_eq hx⟩,
fun h => ⟨x, hx, fun _ hy => h.2 hy⟩⟩
section Finite
variable [Finite α]
theorem IsCycle.exists_pow_eq (hf : IsCycle f) (hx : f x ≠ x) (hy : f y ≠ y) :
∃ i : ℕ, (f ^ i) x = y := by
let ⟨n, hn⟩ := hf.exists_zpow_eq hx hy
classical exact
⟨(n % orderOf f).toNat, by
{have := n.emod_nonneg (Int.natCast_ne_zero.mpr (ne_of_gt (orderOf_pos f)))
rwa [← zpow_natCast, Int.toNat_of_nonneg this, zpow_mod_orderOf]}⟩
end Finite
variable [DecidableEq α]
theorem isCycle_swap (hxy : x ≠ y) : IsCycle (swap x y) :=
⟨y, by rwa [swap_apply_right], fun a (ha : ite (a = x) y (ite (a = y) x a) ≠ a) =>
if hya : y = a then ⟨0, hya⟩
else
⟨1, by
rw [zpow_one, swap_apply_def]
split_ifs at * <;> tauto⟩⟩
protected theorem IsSwap.isCycle : IsSwap f → IsCycle f := by
rintro ⟨x, y, hxy, rfl⟩
exact isCycle_swap hxy
variable [Fintype α]
theorem IsCycle.two_le_card_support (h : IsCycle f) : 2 ≤ #f.support :=
two_le_card_support_of_ne_one h.ne_one
/-- The subgroup generated by a cycle is in bijection with its support -/
noncomputable def IsCycle.zpowersEquivSupport {σ : Perm α} (hσ : IsCycle σ) :
(Subgroup.zpowers σ) ≃ σ.support :=
Equiv.ofBijective
(fun (τ : ↥ ((Subgroup.zpowers σ) : Set (Perm α))) =>
⟨(τ : Perm α) (Classical.choose hσ), by
obtain ⟨τ, n, rfl⟩ := τ
rw [Subtype.coe_mk, zpow_apply_mem_support, mem_support]
exact (Classical.choose_spec hσ).1⟩)
(by
constructor
· rintro ⟨a, m, rfl⟩ ⟨b, n, rfl⟩ h
ext y
by_cases hy : σ y = y
· simp_rw [zpow_apply_eq_self_of_apply_eq_self hy]
· obtain ⟨i, rfl⟩ := (Classical.choose_spec hσ).2 hy
rw [Subtype.coe_mk, Subtype.coe_mk, zpow_apply_comm σ m i, zpow_apply_comm σ n i]
exact congr_arg _ (Subtype.ext_iff.mp h)
· rintro ⟨y, hy⟩
rw [mem_support] at hy
obtain ⟨n, rfl⟩ := (Classical.choose_spec hσ).2 hy
exact ⟨⟨σ ^ n, n, rfl⟩, rfl⟩)
@[simp]
theorem IsCycle.zpowersEquivSupport_apply {σ : Perm α} (hσ : IsCycle σ) {n : ℕ} :
hσ.zpowersEquivSupport ⟨σ ^ n, n, rfl⟩ =
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ :=
rfl
@[simp]
theorem IsCycle.zpowersEquivSupport_symm_apply {σ : Perm α} (hσ : IsCycle σ) (n : ℕ) :
hσ.zpowersEquivSupport.symm
⟨(σ ^ n) (Classical.choose hσ),
pow_apply_mem_support.2 (mem_support.2 (Classical.choose_spec hσ).1)⟩ =
⟨σ ^ n, n, rfl⟩ :=
(Equiv.symm_apply_eq _).2 hσ.zpowersEquivSupport_apply
protected theorem IsCycle.orderOf (hf : IsCycle f) : orderOf f = #f.support := by
rw [← Fintype.card_zpowers, ← Fintype.card_coe]
convert Fintype.card_congr (IsCycle.zpowersEquivSupport hf)
theorem isCycle_swap_mul_aux₁ {α : Type*} [DecidableEq α] :
∀ (n : ℕ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
induction n with
| zero => exact fun _ h => ⟨0, h⟩
| succ n hn =>
intro b x f hb h
exact if hfbx : f x = b then ⟨0, hfbx⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb' : (swap x (f x) * f) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, apply_inv_self, swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx), Ne, ←
f.injective.eq_iff, apply_inv_self]
exact this.1
let ⟨i, hi⟩ := hn hb' (f.injective <| by
rw [apply_inv_self]; rwa [pow_succ', mul_apply] at h)
⟨i + 1, by
rw [add_comm, zpow_add, mul_apply, hi, zpow_one, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne (ne_and_ne_of_swap_mul_apply_ne_self hb).2 (Ne.symm hfbx)]⟩
theorem isCycle_swap_mul_aux₂ {α : Type*} [DecidableEq α] :
∀ (n : ℤ) {b x : α} {f : Perm α} (_ : (swap x (f x) * f) b ≠ b) (_ : (f ^ n) (f x) = b),
∃ i : ℤ, ((swap x (f x) * f) ^ i) (f x) = b := by
intro n
cases n with
| ofNat n => exact isCycle_swap_mul_aux₁ n
| negSucc n =>
intro b x f hb h
exact if hfbx' : f x = b then ⟨0, hfbx'⟩
else
have : f b ≠ b ∧ b ≠ x := ne_and_ne_of_swap_mul_apply_ne_self hb
have hb : (swap x (f⁻¹ x) * f⁻¹) (f⁻¹ b) ≠ f⁻¹ b := by
rw [mul_apply, swap_apply_def]
split_ifs <;>
simp only [inv_eq_iff_eq, Perm.mul_apply, zpow_negSucc, Ne, Perm.apply_inv_self] at *
<;> tauto
let ⟨i, hi⟩ :=
isCycle_swap_mul_aux₁ n hb
(show (f⁻¹ ^ n) (f⁻¹ x) = f⁻¹ b by
rw [← zpow_natCast, ← h, ← mul_apply, ← mul_apply, ← mul_apply, zpow_negSucc,
← inv_pow, pow_succ, mul_assoc, mul_assoc, inv_mul_cancel, mul_one, zpow_natCast,
← pow_succ', ← pow_succ])
have h : (swap x (f⁻¹ x) * f⁻¹) (f x) = f⁻¹ x := by
rw [mul_apply, inv_apply_self, swap_apply_left]
⟨-i, by
rw [← add_sub_cancel_right i 1, neg_sub, sub_eq_add_neg, zpow_add, zpow_one, zpow_neg,
← inv_zpow, mul_inv_rev, swap_inv, mul_swap_eq_swap_mul, inv_apply_self, swap_comm _ x,
zpow_add, zpow_one, mul_apply, mul_apply (_ ^ i), h, hi, mul_apply, apply_inv_self,
swap_apply_of_ne_of_ne this.2 (Ne.symm hfbx')]⟩
theorem IsCycle.eq_swap_of_apply_apply_eq_self {α : Type*} [DecidableEq α] {f : Perm α}
(hf : IsCycle f) {x : α} (hfx : f x ≠ x) (hffx : f (f x) = x) : f = swap x (f x) :=
Equiv.ext fun y =>
let ⟨z, hz⟩ := hf
let ⟨i, hi⟩ := hz.2 hfx
if hyx : y = x then by simp [hyx]
else
if hfyx : y = f x then by simp [hfyx, hffx]
else by
rw [swap_apply_of_ne_of_ne hyx hfyx]
refine by_contradiction fun hy => ?_
obtain ⟨j, hj⟩ := hz.2 hy
rw [← sub_add_cancel j i, zpow_add, mul_apply, hi] at hj
rcases zpow_apply_eq_of_apply_apply_eq_self hffx (j - i) with hji | hji
· rw [← hj, hji] at hyx
tauto
· rw [← hj, hji] at hfyx
tauto
theorem IsCycle.swap_mul {α : Type*} [DecidableEq α] {f : Perm α} (hf : IsCycle f) {x : α}
(hx : f x ≠ x) (hffx : f (f x) ≠ x) : IsCycle (swap x (f x) * f) :=
⟨f x, by simp [swap_apply_def, mul_apply, if_neg hffx, f.injective.eq_iff, if_neg hx, hx],
fun y hy =>
let ⟨i, hi⟩ := hf.exists_zpow_eq hx (ne_and_ne_of_swap_mul_apply_ne_self hy).1
have hi : (f ^ (i - 1)) (f x) = y :=
calc
(f ^ (i - 1) : Perm α) (f x) = (f ^ (i - 1) * f ^ (1 : ℤ) : Perm α) x := by simp
_ = y := by rwa [← zpow_add, sub_add_cancel]
isCycle_swap_mul_aux₂ (i - 1) hy hi⟩
theorem IsCycle.sign {f : Perm α} (hf : IsCycle f) : sign f = -(-1) ^ #f.support :=
let ⟨x, hx⟩ := hf
calc
Perm.sign f = Perm.sign (swap x (f x) * (swap x (f x) * f)) := by
{rw [← mul_assoc, mul_def, mul_def, swap_swap, trans_refl]}
_ = -(-1) ^ #f.support :=
if h1 : f (f x) = x then by
have h : swap x (f x) * f = 1 := by
simp only [mul_def, one_def]
rw [hf.eq_swap_of_apply_apply_eq_self hx.1 h1, swap_apply_left, swap_swap]
rw [sign_mul, sign_swap hx.1.symm, h, sign_one,
hf.eq_swap_of_apply_apply_eq_self hx.1 h1, card_support_swap hx.1.symm]
rfl
else by
have h : #(swap x (f x) * f).support + 1 = #f.support := by
rw [← insert_erase (mem_support.2 hx.1), support_swap_mul_eq _ _ h1,
card_insert_of_not_mem (not_mem_erase _ _), sdiff_singleton_eq_erase]
have : #(swap x (f x) * f).support < #f.support := card_support_swap_mul hx.1
rw [sign_mul, sign_swap hx.1.symm, (hf.swap_mul hx.1 h1).sign, ← h]
simp only [mul_neg, neg_mul, one_mul, neg_neg, pow_add, pow_one, mul_one]
termination_by #f.support
theorem IsCycle.of_pow {n : ℕ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
have key : ∀ x : α, (f ^ n) x ≠ x ↔ f x ≠ x := by
simp_rw [← mem_support, ← Finset.ext_iff]
exact (support_pow_le _ n).antisymm h2
obtain ⟨x, hx1, hx2⟩ := h1
refine ⟨x, (key x).mp hx1, fun y hy => ?_⟩
obtain ⟨i, _⟩ := hx2 ((key y).mpr hy)
exact ⟨n * i, by rwa [zpow_mul]⟩
-- The lemma `support_zpow_le` is relevant. It means that `h2` is equivalent to
-- `σ.support = (σ ^ n).support`, as well as to `#σ.support ≤ #(σ ^ n).support`.
theorem IsCycle.of_zpow {n : ℤ} (h1 : IsCycle (f ^ n)) (h2 : f.support ⊆ (f ^ n).support) :
IsCycle f := by
cases n
· exact h1.of_pow h2
· simp only [le_eq_subset, zpow_negSucc, Perm.support_inv] at h1 h2
exact (inv_inv (f ^ _) ▸ h1.inv).of_pow h2
theorem nodup_of_pairwise_disjoint_cycles {l : List (Perm β)} (h1 : ∀ f ∈ l, IsCycle f)
(h2 : l.Pairwise Disjoint) : l.Nodup :=
nodup_of_pairwise_disjoint (fun h => (h1 1 h).ne_one rfl) h2
/-- Unlike `support_congr`, which assumes that `∀ (x ∈ g.support), f x = g x)`, here
we have the weaker assumption that `∀ (x ∈ f.support), f x = g x`. -/
theorem IsCycle.support_congr (hf : IsCycle f) (hg : IsCycle g) (h : f.support ⊆ g.support)
(h' : ∀ x ∈ f.support, f x = g x) : f = g := by
have : f.support = g.support := by
refine le_antisymm h ?_
intro z hz
obtain ⟨x, hx, _⟩ := id hf
have hx' : g x ≠ x := by rwa [← h' x (mem_support.mpr hx)]
obtain ⟨m, hm⟩ := hg.exists_pow_eq hx' (mem_support.mp hz)
have h'' : ∀ x ∈ f.support ∩ g.support, f x = g x := by
intro x hx
exact h' x (mem_of_mem_inter_left hx)
rwa [← hm, ←
pow_eq_on_of_mem_support h'' _ x
(mem_inter_of_mem (mem_support.mpr hx) (mem_support.mpr hx')),
pow_apply_mem_support, mem_support]
refine Equiv.Perm.support_congr h ?_
simpa [← this] using h'
/-- If two cyclic permutations agree on all terms in their intersection,
and that intersection is not empty, then the two cyclic permutations must be equal. -/
theorem IsCycle.eq_on_support_inter_nonempty_congr (hf : IsCycle f) (hg : IsCycle g)
(h : ∀ x ∈ f.support ∩ g.support, f x = g x)
(hx : f x = g x) (hx' : x ∈ f.support) : f = g := by
have hx'' : x ∈ g.support := by rwa [mem_support, ← hx, ← mem_support]
have : f.support ⊆ g.support := by
intro y hy
obtain ⟨k, rfl⟩ := hf.exists_pow_eq (mem_support.mp hx') (mem_support.mp hy)
rwa [pow_eq_on_of_mem_support h _ _ (mem_inter_of_mem hx' hx''), pow_apply_mem_support]
rw [inter_eq_left.mpr this] at h
exact hf.support_congr hg this h
theorem IsCycle.support_pow_eq_iff (hf : IsCycle f) {n : ℕ} :
support (f ^ n) = support f ↔ ¬orderOf f ∣ n := by
rw [orderOf_dvd_iff_pow_eq_one]
constructor
· intro h H
refine hf.ne_one ?_
rw [← support_eq_empty_iff, ← h, H, support_one]
· intro H
apply le_antisymm (support_pow_le _ n) _
intro x hx
contrapose! H
ext z
by_cases hz : f z = z
· rw [pow_apply_eq_self_of_apply_eq_self hz, one_apply]
· obtain ⟨k, rfl⟩ := hf.exists_pow_eq hz (mem_support.mp hx)
apply (f ^ k).injective
rw [← mul_apply, (Commute.pow_pow_self _ _ _).eq, mul_apply]
simpa using H
theorem IsCycle.support_pow_of_pos_of_lt_orderOf (hf : IsCycle f) {n : ℕ} (npos : 0 < n)
(hn : n < orderOf f) : (f ^ n).support = f.support :=
hf.support_pow_eq_iff.2 <| Nat.not_dvd_of_pos_of_lt npos hn
theorem IsCycle.pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
IsCycle (f ^ n) ↔ n.Coprime (orderOf f) := by
classical
cases nonempty_fintype β
constructor
· intro h
have hr : support (f ^ n) = support f := by
rw [hf.support_pow_eq_iff]
rintro ⟨k, rfl⟩
refine h.ne_one ?_
simp [pow_mul, pow_orderOf_eq_one]
have : orderOf (f ^ n) = orderOf f := by rw [h.orderOf, hr, hf.orderOf]
rw [orderOf_pow, Nat.div_eq_self] at this
rcases this with h | _
· exact absurd h (orderOf_pos _).ne'
· rwa [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm]
· intro h
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h
have hf' : IsCycle ((f ^ n) ^ m) := by rwa [hm]
refine hf'.of_pow fun x hx => ?_
rw [hm]
exact support_pow_le _ n hx
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
f ^ n = 1 ↔ ∃ x, f x ≠ x ∧ (f ^ n) x = x := by
classical
cases nonempty_fintype β
constructor
· intro h
obtain ⟨x, hx, -⟩ := id hf
exact ⟨x, hx, by simp [h]⟩
· rintro ⟨x, hx, hx'⟩
by_cases h : support (f ^ n) = support f
· rw [← mem_support, ← h, mem_support] at hx
contradiction
· rw [hf.support_pow_eq_iff, Classical.not_not] at h
obtain ⟨k, rfl⟩ := h
rw [pow_mul, pow_orderOf_eq_one, one_pow]
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} {x : β}
(hx : f x ≠ x) : f ^ n = 1 ↔ (f ^ n) x = x :=
⟨fun h => DFunLike.congr_fun h x, fun h => hf.pow_eq_one_iff.2 ⟨x, hx, h⟩⟩
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_one_iff'' [Finite β] {f : Perm β} (hf : IsCycle f) {n : ℕ} :
f ^ n = 1 ↔ ∀ x, f x ≠ x → (f ^ n) x = x :=
⟨fun h _ hx => (hf.pow_eq_one_iff' hx).1 h, fun h =>
let ⟨_, hx, _⟩ := id hf
(hf.pow_eq_one_iff' hx).2 (h _ hx)⟩
-- TODO: Define a `Set`-valued support to get rid of the `Finite β` assumption
theorem IsCycle.pow_eq_pow_iff [Finite β] {f : Perm β} (hf : IsCycle f) {a b : ℕ} :
f ^ a = f ^ b ↔ ∃ x, f x ≠ x ∧ (f ^ a) x = (f ^ b) x := by
classical
cases nonempty_fintype β
constructor
· intro h
obtain ⟨x, hx, -⟩ := id hf
exact ⟨x, hx, by simp [h]⟩
· rintro ⟨x, hx, hx'⟩
wlog hab : a ≤ b generalizing a b
· exact (this hx'.symm (le_of_not_le hab)).symm
suffices f ^ (b - a) = 1 by
rw [pow_sub _ hab, mul_inv_eq_one] at this
rw [this]
rw [hf.pow_eq_one_iff]
by_cases hfa : (f ^ a) x ∈ f.support
· refine ⟨(f ^ a) x, mem_support.mp hfa, ?_⟩
simp only [pow_sub _ hab, Equiv.Perm.coe_mul, Function.comp_apply, inv_apply_self, ← hx']
· have h := @Equiv.Perm.zpow_apply_comm _ f 1 a x
simp only [zpow_one, zpow_natCast] at h
rw [not_mem_support, h, Function.Injective.eq_iff (f ^ a).injective] at hfa
contradiction
theorem IsCycle.isCycle_pow_pos_of_lt_prime_order [Finite β] {f : Perm β} (hf : IsCycle f)
(hf' : (orderOf f).Prime) (n : ℕ) (hn : 0 < n) (hn' : n < orderOf f) : IsCycle (f ^ n) := by
classical
cases nonempty_fintype β
have : n.Coprime (orderOf f) := by
refine Nat.Coprime.symm ?_
rw [Nat.Prime.coprime_iff_not_dvd hf']
exact Nat.not_dvd_of_pos_of_lt hn hn'
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime this
have hf'' := hf
rw [← hm] at hf''
refine hf''.of_pow ?_
rw [hm]
exact support_pow_le f n
end IsCycle
open Equiv
theorem _root_.Int.addLeft_one_isCycle : (Equiv.addLeft 1 : Perm ℤ).IsCycle :=
⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩
theorem _root_.Int.addRight_one_isCycle : (Equiv.addRight 1 : Perm ℤ).IsCycle :=
⟨0, one_ne_zero, fun n _ => ⟨n, by simp⟩⟩
section Conjugation
variable [Fintype α] [DecidableEq α] {σ τ : Perm α}
theorem IsCycle.isConj (hσ : IsCycle σ) (hτ : IsCycle τ) (h : #σ.support = #τ.support) :
IsConj σ τ := by
refine
isConj_of_support_equiv
(hσ.zpowersEquivSupport.symm.trans <|
(zpowersEquivZPowers <| by rw [hσ.orderOf, h, hτ.orderOf]).trans hτ.zpowersEquivSupport)
?_
intro x hx
simp only [Perm.mul_apply, Equiv.trans_apply, Equiv.sumCongr_apply]
obtain ⟨n, rfl⟩ := hσ.exists_pow_eq (Classical.choose_spec hσ).1 (mem_support.1 hx)
simp [← Perm.mul_apply, ← pow_succ']
theorem IsCycle.isConj_iff (hσ : IsCycle σ) (hτ : IsCycle τ) :
IsConj σ τ ↔ #σ.support = #τ.support where
mp h := by
obtain ⟨π, rfl⟩ := (_root_.isConj_iff).1 h
refine Finset.card_bij (fun a _ => π a) (fun _ ha => ?_) (fun _ _ _ _ ab => π.injective ab)
fun b hb ↦ ⟨π⁻¹ b, ?_, π.apply_inv_self b⟩
· simp [mem_support.1 ha]
contrapose! hb
rw [mem_support, Classical.not_not] at hb
rw [mem_support, Classical.not_not, Perm.mul_apply, Perm.mul_apply, hb, Perm.apply_inv_self]
mpr := hσ.isConj hτ
end Conjugation
/-! ### `IsCycleOn` -/
section IsCycleOn
variable {f g : Perm α} {s t : Set α} {a b x y : α}
/-- A permutation is a cycle on `s` when any two points of `s` are related by repeated application
of the permutation. Note that this means the identity is a cycle of subsingleton sets. -/
def IsCycleOn (f : Perm α) (s : Set α) : Prop :=
Set.BijOn f s s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → f.SameCycle x y
@[simp]
theorem isCycleOn_empty : f.IsCycleOn ∅ := by simp [IsCycleOn, Set.bijOn_empty]
|
@[simp]
theorem isCycleOn_one : (1 : Perm α).IsCycleOn s ↔ s.Subsingleton := by
simp [IsCycleOn, Set.bijOn_id, Set.Subsingleton]
alias ⟨IsCycleOn.subsingleton, _root_.Set.Subsingleton.isCycleOn_one⟩ := isCycleOn_one
@[simp]
theorem isCycleOn_singleton : f.IsCycleOn {a} ↔ f a = a := by simp [IsCycleOn, SameCycle.rfl]
theorem isCycleOn_of_subsingleton [Subsingleton α] (f : Perm α) (s : Set α) : f.IsCycleOn s :=
⟨s.bijOn_of_subsingleton _, fun x _ y _ => (Subsingleton.elim x y).sameCycle _⟩
@[simp]
theorem isCycleOn_inv : f⁻¹.IsCycleOn s ↔ f.IsCycleOn s := by
simp only [IsCycleOn, sameCycle_inv, and_congr_left_iff]
exact fun _ ↦ ⟨fun h ↦ Set.BijOn.perm_inv h, fun h ↦ Set.BijOn.perm_inv h⟩
alias ⟨IsCycleOn.of_inv, IsCycleOn.inv⟩ := isCycleOn_inv
theorem IsCycleOn.conj (h : f.IsCycleOn s) : (g * f * g⁻¹).IsCycleOn ((g : Perm α) '' s) :=
⟨(g.bijOn_image.comp h.1).comp g.bijOn_symm_image, fun x hx y hy => by
| Mathlib/GroupTheory/Perm/Cycle/Basic.lean | 680 | 701 |
/-
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, Kim Morrison
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.NonUnitalHom
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Algebra.MonoidAlgebra.MapDomain
import Mathlib.Data.Finsupp.SMul
import Mathlib.LinearAlgebra.Finsupp.SumProd
/-!
# Monoid algebras
-/
noncomputable section
open Finset
open Finsupp hiding single mapDomain
universe u₁ u₂ u₃ u₄
variable (k : Type u₁) (G : Type u₂) (H : Type*) {R : Type*}
/-! ### Multiplicative monoids -/
namespace MonoidAlgebra
variable {k G}
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Mul G]
variable {A : Type u₃} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A}
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
NonUnitalAlgHom.to_distribMulActionHom_injective <|
Finsupp.distribMulActionHom_ext' fun a => DistribMulActionHom.ext_ring (h a)
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A}
(h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ :=
nonUnitalAlgHom_ext k <| DFunLike.congr_fun h
/-- The functor `G ↦ MonoidAlgebra k G`, from the category of magmas to the category of non-unital,
non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(G →ₙ* A) ≃ (MonoidAlgebra k G →ₙₐ[k] A) where
toFun f :=
{ liftAddHom fun x => (smulAddHom k A).flip (f x) with
toFun := fun a => a.sum fun m t => t • f m
map_smul' := fun t' a => by
rw [Finsupp.smul_sum, sum_smul_index']
· simp_rw [smul_assoc, MonoidHom.id_apply]
· intro m
exact zero_smul k (f m)
map_mul' := fun a₁ a₂ => by
let g : G → k → A := fun m t => t • f m
have h₁ : ∀ m, g m 0 = 0 := by
intro m
exact zero_smul k (f m)
have h₂ : ∀ (m) (t₁ t₂ : k), g m (t₁ + t₂) = g m t₁ + g m t₂ := by
intros
rw [← add_smul]
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp_rw [Finsupp.mul_sum, Finsupp.sum_mul, smul_mul_smul_comm, ← f.map_mul, mul_def,
sum_comm a₂ a₁]
rw [sum_sum_index h₁ h₂]; congr; ext
rw [sum_sum_index h₁ h₂]; congr; ext
rw [sum_single_index (h₁ _)] }
invFun F := F.toMulHom.comp (ofMagma k G)
left_inv f := by
ext m
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
right_inv F := by
ext m
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
/-- The instance `Algebra k (MonoidAlgebra A G)` whenever we have `Algebra k A`.
In particular this provides the instance `Algebra k (MonoidAlgebra k G)`.
-/
instance algebra {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
Algebra k (MonoidAlgebra A G) where
algebraMap := singleOneRingHom.comp (algebraMap k A)
smul_def' := fun r a => by
ext
rw [Finsupp.coe_smul]
simp [single_one_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_one_mul_apply, mul_single_one_apply, Algebra.commutes]
/-- `Finsupp.single 1` as an `AlgHom` -/
@[simps! apply]
def singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
A →ₐ[k] MonoidAlgebra A G :=
{ singleOneRingHom with
commutes' := fun r => by
ext
simp
rfl }
@[simp]
theorem coe_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
⇑(algebraMap k (MonoidAlgebra A G)) = single 1 ∘ algebraMap k A :=
rfl
theorem single_eq_algebraMap_mul_of [CommSemiring k] [Monoid G] (a : G) (b : k) :
single a b = algebraMap k (MonoidAlgebra k G) b * of k G a := by simp
theorem single_algebraMap_eq_algebraMap_mul_of {A : Type*} [CommSemiring k] [Semiring A]
[Algebra k A] [Monoid G] (a : G) (b : k) :
single a (algebraMap k A b) = algebraMap k (MonoidAlgebra A G) b * of A G a := by simp
instance isLocalHom_singleOneAlgHom
{A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
IsLocalHom (singleOneAlgHom : A →ₐ[k] MonoidAlgebra A G) where
map_nonunit := isLocalHom_singleOneRingHom.map_nonunit
instance isLocalHom_algebraMap
{A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G]
[IsLocalHom (algebraMap k A)] :
IsLocalHom (algebraMap k (MonoidAlgebra A G)) where
map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleOneAlgHom (k := k).map_nonunit _ hx
end Algebra
section lift
variable [CommSemiring k] [Monoid G] [Monoid H]
variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A →ₐ[k] B) (g : G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) :
MonoidAlgebra A G →ₐ[k] B :=
{ liftNCRingHom (f : A →+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
/-- A `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
AlgHom.toLinearMap_injective <| Finsupp.lhom_ext' fun a => LinearMap.ext_ring (h a)
-- The priority must be `high`.
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄
(h :
(φ₁ : MonoidAlgebra k G →* A).comp (of k G) = (φ₂ : MonoidAlgebra k G →* A).comp (of k G)) :
φ₁ = φ₂ :=
algHom_ext <| DFunLike.congr_fun h
variable (k G A)
/-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism
`MonoidAlgebra k G →ₐ[k] A`. -/
def lift : (G →* A) ≃ (MonoidAlgebra k G →ₐ[k] A) where
invFun f := (f : MonoidAlgebra k G →* A).comp (of k G)
toFun F := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _
left_inv f := by
ext
simp [liftNCAlgHom, liftNCRingHom]
right_inv F := by
ext
simp [liftNCAlgHom, liftNCRingHom]
variable {k G H A}
theorem lift_apply' (F : G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F a :=
rfl
theorem lift_apply (F : G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b • F a := by simp only [lift_apply', Algebra.smul_def]
theorem lift_def (F : G →* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F :=
rfl
@[simp]
theorem lift_symm_apply (F : MonoidAlgebra k G →ₐ[k] A) (x : G) :
(lift k G A).symm F x = F (single x 1) :=
rfl
@[simp]
theorem lift_single (F : G →* A) (a b) : lift k G A F (single a b) = b • F a := by
rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe]
theorem lift_of (F : G →* A) (x) : lift k G A F (of k G x) = F x := by simp
theorem lift_unique' (F : MonoidAlgebra k G →ₐ[k] A) :
F = lift k G A ((F : MonoidAlgebra k G →* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : MonoidAlgebra k G →ₐ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b • F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
/-- If `f : G → H` is a homomorphism between two magmas, then
`Finsupp.mapDomain f` is a non-unital algebra homomorphism between their magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Mul G] [Mul H] [FunLike F G H] [MulHomClass F G H] (f : F) :
MonoidAlgebra A G →ₙₐ[k] MonoidAlgebra A H :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
variable (A) in
theorem mapDomain_algebraMap {F : Type*} [FunLike F G H] [MonoidHomClass F G H] (f : F) (r : k) :
mapDomain f (algebraMap k (MonoidAlgebra A G) r) = algebraMap k (MonoidAlgebra A H) r := by
simp only [coe_algebraMap, mapDomain_single, map_one, (· ∘ ·)]
/-- If `f : G → H` is a multiplicative homomorphism between two monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*}
[Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) :
MonoidAlgebra A G →ₐ[k] MonoidAlgebra A H :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
@[simp]
lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] :
mapDomainAlgHom k A (MonoidHom.id G) = AlgHom.id k (MonoidAlgebra A G) := by
ext; simp [MonoidHom.id, ← Function.id_def]
@[simp]
lemma mapDomainAlgHom_comp (k A) {G₁ G₂ G₃} [CommSemiring k] [Semiring A] [Algebra k A]
[Monoid G₁] [Monoid G₂] [Monoid G₃] (f : G₁ →* G₂) (g : G₂ →* G₃) :
mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by
ext; simp [mapDomain_comp]
variable (k A)
/-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then
`MonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/
def domCongr (e : G ≃* H) : MonoidAlgebra A G ≃ₐ[k] MonoidAlgebra A H :=
AlgEquiv.ofLinearEquiv
(Finsupp.domLCongr e : (G →₀ A) ≃ₗ[k] (H →₀ A))
((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e)
(fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <|
congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm)
theorem domCongr_toAlgHom (e : G ≃* H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e :=
AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _
@[simp] theorem domCongr_apply (e : G ≃* H) (f : MonoidAlgebra A G) (h : H) :
domCongr k A e f h = f (e.symm h) :=
rfl
@[simp] theorem domCongr_support (e : G ≃* H) (f : MonoidAlgebra A G) :
(domCongr k A e f).support = f.support.map e :=
rfl
@[simp] theorem domCongr_single (e : G ≃* H) (g : G) (a : A) :
domCongr k A e (single g a) = single (e g) a :=
Finsupp.equivMapDomain_single _ _ _
@[simp] theorem domCongr_refl : domCongr k A (MulEquiv.refl G) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl
@[simp] theorem domCongr_symm (e : G ≃* H) : (domCongr k A e).symm = domCongr k A e.symm := rfl
end lift
section
variable (k)
/-- When `V` is a `k[G]`-module, multiplication by a group element `g` is a `k`-linear map. -/
def GroupSMul.linearMap [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V] [Module k V]
[Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) : V →ₗ[k] V where
toFun v := single g (1 : k) • v
map_add' x y := smul_add (single g (1 : k)) x y
map_smul' _c _x := smul_algebra_smul_comm _ _ _
@[simp]
theorem GroupSMul.linearMap_apply [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V]
[Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G)
(v : V) : (GroupSMul.linearMap k V g) v = single g (1 : k) • v :=
rfl
section
variable {k}
variable [Monoid G] [CommSemiring k] {V : Type u₃} {W : Type u₄} [AddCommMonoid V] [Module k V]
[Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] [AddCommMonoid W]
[Module k W] [Module (MonoidAlgebra k G) W] [IsScalarTower k (MonoidAlgebra k G) W]
(f : V →ₗ[k] W)
/-- Build a `k[G]`-linear map from a `k`-linear map and evidence that it is `G`-equivariant. -/
def equivariantOfLinearOfComm
(h : ∀ (g : G) (v : V), f (single g (1 : k) • v) = single g (1 : k) • f v) :
V →ₗ[MonoidAlgebra k G] W where
toFun := f
map_add' v v' := by simp
map_smul' c v := by
refine Finsupp.induction c ?_ ?_
· simp
· intro g r c' _nm _nz w
dsimp at *
simp only [add_smul, f.map_add, w, add_left_inj, single_eq_algebraMap_mul_of, ← smul_smul]
rw [algebraMap_smul (MonoidAlgebra k G) r, algebraMap_smul (MonoidAlgebra k G) r, f.map_smul,
of_apply, h g v]
variable (h : ∀ (g : G) (v : V), f (single g (1 : k) • v) = single g (1 : k) • f v)
@[simp]
theorem equivariantOfLinearOfComm_apply (v : V) : (equivariantOfLinearOfComm f h) v = f v :=
rfl
end
end
end MonoidAlgebra
namespace AddMonoidAlgebra
variable {k G H}
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Add G]
variable {A : Type u₃} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `k[G]` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : k[G] →ₙₐ[k] A}
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
@MonoidAlgebra.nonUnitalAlgHom_ext k (Multiplicative G) _ _ _ _ _ φ₁ φ₂ h
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : k[G] →ₙₐ[k] A}
(h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ :=
@MonoidAlgebra.nonUnitalAlgHom_ext' k (Multiplicative G) _ _ _ _ _ φ₁ φ₂ h
/-- The functor `G ↦ k[G]`, from the category of magmas to the category of
non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other
direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(Multiplicative G →ₙ* A) ≃ (k[G] →ₙₐ[k] A) :=
{ (MonoidAlgebra.liftMagma k : (Multiplicative G →ₙ* A) ≃ (_ →ₙₐ[k] A)) with
toFun := fun f =>
{ (MonoidAlgebra.liftMagma k f :) with
toFun := fun a => sum a fun m t => t • f (Multiplicative.ofAdd m) }
invFun := fun F => F.toMulHom.comp (ofMagma k G) }
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
/-- The instance `Algebra R k[G]` whenever we have `Algebra R k`.
In particular this provides the instance `Algebra k k[G]`.
-/
instance algebra [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
Algebra R k[G] where
algebraMap := singleZeroRingHom.comp (algebraMap R k)
smul_def' := fun r a => by
ext
rw [Finsupp.coe_smul]
simp [single_zero_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_zero_mul_apply, mul_single_zero_apply, Algebra.commutes]
/-- `Finsupp.single 0` as an `AlgHom` -/
@[simps! apply]
def singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : k →ₐ[R] k[G] :=
{ singleZeroRingHom with
commutes' := fun r => by
ext
simp
rfl }
@[simp]
theorem coe_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
(algebraMap R k[G] : R → k[G]) = single 0 ∘ algebraMap R k :=
rfl
instance isLocalHom_singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
IsLocalHom (singleZeroAlgHom : k →ₐ[R] k[G]) where
map_nonunit := isLocalHom_singleZeroRingHom.map_nonunit
instance isLocalHom_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G]
[IsLocalHom (algebraMap R k)] :
IsLocalHom (algebraMap R k[G]) where
map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleZeroAlgHom (R := R).map_nonunit _ hx
end Algebra
section lift
variable [CommSemiring k] [AddMonoid G]
variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A →ₐ[k] B) (g : Multiplicative G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) :
A[G] →ₐ[k] B :=
{ liftNCRingHom (f : A →+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
/-- A `k`-algebra homomorphism from `k[G]` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext ⦃φ₁ φ₂ : k[G] →ₐ[k] A⦄
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
@MonoidAlgebra.algHom_ext k (Multiplicative G) _ _ _ _ _ _ _ h
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' ⦃φ₁ φ₂ : k[G] →ₐ[k] A⦄
(h : (φ₁ : k[G] →* A).comp (of k G) = (φ₂ : k[G] →* A).comp (of k G)) :
φ₁ = φ₂ :=
algHom_ext <| DFunLike.congr_fun h
variable (k G A)
/-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism
`k[G] →ₐ[k] A`. -/
def lift : (Multiplicative G →* A) ≃ (k[G] →ₐ[k] A) :=
{ @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ with
invFun := fun f => (f : k[G] →* A).comp (of k G)
toFun := fun F =>
{ @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ F with
toFun := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ } }
variable {k G A}
theorem lift_apply' (F : Multiplicative G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F (Multiplicative.ofAdd a) :=
rfl
theorem lift_apply (F : Multiplicative G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b • F (Multiplicative.ofAdd a) := by
simp only [lift_apply', Algebra.smul_def]
theorem lift_def (F : Multiplicative G →* A) :
⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F :=
rfl
@[simp]
theorem lift_symm_apply (F : k[G] →ₐ[k] A) (x : Multiplicative G) :
(lift k G A).symm F x = F (single x.toAdd 1) :=
rfl
theorem lift_of (F : Multiplicative G →* A) (x : Multiplicative G) :
lift k G A F (of k G x) = F x := MonoidAlgebra.lift_of F x
@[simp]
theorem lift_single (F : Multiplicative G →* A) (a b) :
lift k G A F (single a b) = b • F (Multiplicative.ofAdd a) :=
MonoidAlgebra.lift_single F (.ofAdd a) b
lemma lift_of' (F : Multiplicative G →* A) (x : G) :
lift k G A F (of' k G x) = F (Multiplicative.ofAdd x) :=
lift_of F x
theorem lift_unique' (F : k[G] →ₐ[k] A) :
F = lift k G A ((F : k[G] →* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : k[G] →ₐ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b • F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
theorem algHom_ext_iff {φ₁ φ₂ : k[G] →ₐ[k] A} :
(∀ x, φ₁ (Finsupp.single x 1) = φ₂ (Finsupp.single x 1)) ↔ φ₁ = φ₂ :=
⟨fun h => algHom_ext h, by rintro rfl _; rfl⟩
end lift
theorem mapDomain_algebraMap (A : Type*) {H F : Type*} [CommSemiring k] [Semiring A] [Algebra k A]
[AddMonoid G] [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H]
(f : F) (r : k) :
mapDomain f (algebraMap k A[G] r) = algebraMap k A[H] r := by
simp only [Function.comp_apply, mapDomain_single, AddMonoidAlgebra.coe_algebraMap, map_zero]
/-- If `f : G → H` is a homomorphism between two additive magmas, then `Finsupp.mapDomain f` is a
non-unital algebra homomorphism between their additive magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Add G] [Add H] [FunLike F G H] [AddHomClass F G H] (f : F) :
A[G] →ₙₐ[k] A[H] :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
/-- If `f : G → H` is an additive homomorphism between two additive monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their add monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G]
| {H F : Type*} [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) :
A[G] →ₐ[k] A[H] :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
| Mathlib/Algebra/MonoidAlgebra/Basic.lean | 531 | 533 |
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Neil Strickland
-/
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.PNat.Basic
/-!
# Primality and GCD on pnat
This file extends the theory of `ℕ+` with `gcd`, `lcm` and `Prime` functions, analogous to those on
`Nat`.
-/
namespace Nat.Primes
/-- The canonical map from `Nat.Primes` to `ℕ+` -/
@[coe] def toPNat : Nat.Primes → ℕ+ :=
fun p => ⟨(p : ℕ), p.property.pos⟩
instance coePNat : Coe Nat.Primes ℕ+ :=
⟨toPNat⟩
@[norm_cast]
theorem coe_pnat_nat (p : Nat.Primes) : ((p : ℕ+) : ℕ) = p :=
rfl
theorem coe_pnat_injective : Function.Injective ((↑) : Nat.Primes → ℕ+) := fun p q h =>
Subtype.ext (by injection h)
@[norm_cast]
theorem coe_pnat_inj (p q : Nat.Primes) : (p : ℕ+) = (q : ℕ+) ↔ p = q :=
| coe_pnat_injective.eq_iff
| Mathlib/Data/PNat/Prime.lean | 35 | 36 |
/-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.Normal.Closure
import Mathlib.RingTheory.AlgebraicIndependent.Adjoin
import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis
import Mathlib.RingTheory.Polynomial.SeparableDegree
import Mathlib.RingTheory.Polynomial.UniqueFactorization
/-!
# Separable degree
This file contains basics about the separable degree of a field extension.
## Main definitions
- `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`
(the algebraic closure of `F` is usually used in the literature, but our definition has the
advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F`
and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks.
- `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F`
of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic
closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense.
**Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E`
for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is
the separable closure of `F` in `E`, which is not defined in this file yet. Later we
will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two
definitions coincide. If `E / F` is algebraic with infinite separable degree, we have
`#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead.
(See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if
$F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$
is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to
$\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable.
- `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
## Main results
- `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`:
a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. In particular, they have the same cardinality (so their
`Field.finSepDegree` are equal).
- `Field.embEquivOfAdjoinSplits`,
`Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F`
and whose minimal polynomial splits in `K`. In particular, they have the same cardinality.
- `Field.embEquivOfIsAlgClosed`,
`Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed.
In particular, they have the same cardinality.
- `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`:
if `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`.
In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$
(see also `Module.finrank_mul_finrank`).
- `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions.
- `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than
its degree.
- `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is
equal to its degree if and only if it is separable.
- `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree
is equal to the number of distinct roots of it over `E`.
- `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field.
- `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic
`q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree.
- `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable
contraction, then its separable degree is equal to its separable contraction degree.
- `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible
polynomial divides its degree.
- `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of
`F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`.
- `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then
the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a
separable element.
- `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides
the degree of `E / F`.
- `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller
than the degree of `E / F`.
- `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree
is equal to its degree if and only if it is a separable extension.
- `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension
if and only if `x` is a separable element.
- `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also
separable.
## Tags
separable degree, degree, polynomial
-/
open Module Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
namespace Field
/-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure
of `E`. -/
abbrev Emb := E →ₐ[F] AlgebraicClosure E
/-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F`
is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`,
as a natural number. It is defined to be zero if there are infinitely many of them.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/
def finSepDegree : ℕ := Nat.card (Emb F E)
instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩
instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) :=
⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩
/-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. -/
def embEquivOfEquiv (i : E ≃ₐ[F] K) :
Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by
let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra
have : Algebra.IsAlgebraic E K := by
constructor
intro x
have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x)
rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h
simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h
apply AlgEquiv.restrictScalars (R := F) (S := E)
exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree`
over `F`. -/
theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i)
@[simp]
theorem finSepDegree_self : finSepDegree F F = 1 := by
have : Cardinal.mk (Emb F F) = 1 := le_antisymm
(Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton)
(Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _)
rw [finSepDegree, Nat.card, this, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self]
section Tower
variable {F}
variable [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E :=
finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K :=
finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
end Tower
end IntermediateField
namespace Field
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every
element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`.
Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of
`IntermediateField.nonempty_algHom_of_adjoin_splits`. -/
def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
Emb F E ≃ (E →ₐ[F] K) :=
have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) :=
(hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1)
have halg := (topEquiv (F := F) (E := E)).isAlgebraic
Classical.choice <| Function.Embedding.antisymm
(halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _)
(halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _)
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K`
if `E = F(S)` such that every element
`s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/
theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK)
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic
and `K / F` is algebraically closed. -/
def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
Emb F E ≃ (E →ₐ[F] K) :=
embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦
⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number,
when `E / F` is algebraic and `K / F` is algebraically closed. -/
@[stacks 09HJ "We use `finSepDegree` to state a more general result."]
theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K)
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection
`Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/
def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
Emb F E × Emb E K ≃ Emb F K :=
let e : ∀ f : E →ₐ[F] AlgebraicClosure K,
@AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦
(@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm
(algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans
(Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <|
fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <|
(IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K)
(AlgebraicClosure E)).restrictScalars F).symm
/-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/
instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by
obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E
have := hx.isAlgebraic_field
rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff]
refine @Prod.infinite_of_left _ _ ?_ _
rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff]
obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H
let K := FractionRing (MvPolynomial ι F)
let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K)
have hi1 : Function.Injective i1 := by
rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K]
exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _)
let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom
(g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by
simpa [algebraicIndependent_iff_injective_aeval] using
MvPolynomial.algebraicIndependent_polynomial_aeval_X _
fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos
refine Infinite.of_injective f fun m n h ↦ ?_
replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by
simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i)))
simpa using congr(MvPolynomial.totalDegree $h)
/-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which
actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/
theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] :
finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their
separable degrees satisfy the tower law
$[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/
@[stacks 09HK "Part 1, `finSepDegree` variant"]
theorem finSepDegree_mul_finSepDegree_of_isAlgebraic
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
finSepDegree F E * finSepDegree E K = finSepDegree F K := by
simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
namespace Polynomial
variable {F E}
variable (f : F[X])
open Classical in
/-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable
degree of `0` is `0`, not negative infinity. -/
def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card
/-- The separable degree of a polynomial is smaller than its degree. -/
theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by
have := f.map (algebraMap F f.SplittingField) |>.card_roots'
rw [← aroots_def, natDegree_map] at this
classical
exact (f.aroots f.SplittingField).toFinset_card_le.trans this
@[simp]
theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton]
@[simp]
theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton]
/-- A constant polynomial has zero separable degree. -/
theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by
linarith only [natSepDegree_le_natDegree f, h]
@[simp]
theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _)
@[simp]
theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by
rw [← C_0, natSepDegree_C]
@[simp]
theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by
rw [← C_1, natSepDegree_C]
/-- A non-constant polynomial has non-zero separable degree. -/
theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by
rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty]
use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)
classical
rw [Multiset.mem_toFinset, mem_aroots]
exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩
/-- A polynomial has zero separable degree if and only if it is constant. -/
theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 :=
⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩
/-- A polynomial has non-zero separable degree if and only if it is non-constant. -/
theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 :=
Iff.not <| natSepDegree_eq_zero_iff f
/-- The separable degree of a non-zero polynomial is equal to its degree if and only if
it is separable. -/
theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) :
f.natSepDegree = f.natDegree ↔ f.Separable := by
classical
simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f),
rootSet_def, Finset.coe_sort_coe, Fintype.card_coe]
rfl
/-- If a polynomial is separable, then its separable degree is equal to its degree. -/
theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) :
f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h
variable {f} in
/-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of
dot notation. -/
theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) :
f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h
/-- If a polynomial splits over `E`, then its separable degree is equal to
the number of distinct roots of it over `E`. -/
theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) :
f.natSepDegree = (f.aroots E).toFinset.card := by
classical
rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map,
roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f),
Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree]
variable (E) in
/-- The separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field. -/
theorem natSepDegree_eq_of_isAlgClosed [DecidableEq E] [IsAlgClosed E] :
f.natSepDegree = (f.aroots E).toFinset.card :=
natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f)
theorem natSepDegree_map (f : E[X]) (i : E →+* K) : (f.map i).natSepDegree = f.natSepDegree := by
classical
let _ := i.toAlgebra
simp_rw [show i = algebraMap E K by rfl, natSepDegree_eq_of_isAlgClosed (AlgebraicClosure K),
aroots_def, map_map, ← IsScalarTower.algebraMap_eq]
@[simp]
theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) :
(C x * f).natSepDegree = f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx]
@[simp]
theorem natSepDegree_smul_nonzero {x : F} (hx : x ≠ 0) :
(x • f).natSepDegree = f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_smul_nonzero _ hx]
@[simp]
theorem natSepDegree_pow {n : ℕ} : (f ^ n).natSepDegree = if n = 0 then 0 else f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_pow]
by_cases h : n = 0
· simp only [h, zero_smul, Multiset.toFinset_zero, Finset.card_empty, ite_true]
simp only [h, Multiset.toFinset_nsmul _ n h, ite_false]
theorem natSepDegree_pow_of_ne_zero {n : ℕ} (hn : n ≠ 0) :
(f ^ n).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_pow, hn, ite_false]
theorem natSepDegree_X_pow {n : ℕ} : (X ^ n : F[X]).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_pow, natSepDegree_X]
theorem natSepDegree_X_sub_C_pow {x : F} {n : ℕ} :
((X - C x) ^ n).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_pow, natSepDegree_X_sub_C]
theorem natSepDegree_C_mul_X_sub_C_pow {x y : F} {n : ℕ} (hx : x ≠ 0) :
(C x * (X - C y) ^ n).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_C_mul _ hx, natSepDegree_X_sub_C_pow]
theorem natSepDegree_mul (g : F[X]) :
(f * g).natSepDegree ≤ f.natSepDegree + g.natSepDegree := by
by_cases h : f * g = 0
· simp only [h, natSepDegree_zero, zero_le]
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add]
exact Finset.card_union_le _ _
theorem natSepDegree_mul_eq_iff (g : F[X]) :
(f * g).natSepDegree = f.natSepDegree + g.natSepDegree ↔ (f = 0 ∧ g = 0) ∨ IsCoprime f g := by
by_cases h : f * g = 0
· rw [mul_eq_zero] at h
wlog hf : f = 0 generalizing f g
· simpa only [mul_comm, add_comm, and_comm,
isCoprime_comm] using this g f h.symm (h.resolve_left hf)
rw [hf, zero_mul, natSepDegree_zero, zero_add, isCoprime_zero_left, isUnit_iff, eq_comm,
natSepDegree_eq_zero_iff, natDegree_eq_zero]
refine ⟨fun ⟨x, h⟩ ↦ ?_, ?_⟩
· by_cases hx : x = 0
· exact .inl ⟨rfl, by rw [← h, hx, map_zero]⟩
exact .inr ⟨x, Ne.isUnit hx, h⟩
rintro (⟨-, h⟩ | ⟨x, -, h⟩)
· exact ⟨0, by rw [h, map_zero]⟩
exact ⟨x, h⟩
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add,
Finset.card_union_eq_card_add_card, Finset.disjoint_iff_ne, Multiset.mem_toFinset, mem_aroots]
rw [mul_eq_zero, not_or] at h
refine ⟨fun H ↦ .inr (isCoprime_of_irreducible_dvd (not_and.2 fun _ ↦ h.2)
fun u hu ⟨v, hf⟩ ⟨w, hg⟩ ↦ ?_), ?_⟩
· obtain ⟨x, hx⟩ := IsAlgClosed.exists_aeval_eq_zero
(AlgebraicClosure F) _ (degree_pos_of_irreducible hu).ne'
exact H x ⟨h.1, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hf)⟩
x ⟨h.2, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hg)⟩ rfl
rintro (⟨rfl, rfl⟩ | hc)
· exact (h.1 rfl).elim
rintro x hf _ hg rfl
obtain ⟨u, v, hfg⟩ := hc
simpa only [map_add, map_mul, map_one, hf.2, hg.2, mul_zero, add_zero,
zero_ne_one] using congr(aeval x $hfg)
theorem natSepDegree_mul_of_isCoprime (g : F[X]) (hc : IsCoprime f g) :
(f * g).natSepDegree = f.natSepDegree + g.natSepDegree :=
(natSepDegree_mul_eq_iff f g).2 (.inr hc)
theorem natSepDegree_le_of_dvd (g : F[X]) (h1 : f ∣ g) (h2 : g ≠ 0) :
f.natSepDegree ≤ g.natSepDegree := by
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F)]
exact Finset.card_le_card <| Multiset.toFinset_subset.mpr <|
Multiset.Le.subset <| roots.le_of_dvd (map_ne_zero h2) <| map_dvd _ h1
/-- If a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f`
and `f` have the same separable degree. -/
theorem natSepDegree_expand (q : ℕ) [hF : ExpChar F q] {n : ℕ} :
(expand F (q ^ n) f).natSepDegree = f.natSepDegree := by
obtain - | hprime := hF
· simp only [one_pow, expand_one]
haveI := Fact.mk hprime
classical
simpa only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_def, map_expand,
Fintype.card_coe] using Fintype.card_eq.2
⟨(f.map (algebraMap F (AlgebraicClosure F))).rootsExpandPowEquivRoots q n⟩
theorem natSepDegree_X_pow_char_pow_sub_C (q : ℕ) [ExpChar F q] (n : ℕ) (y : F) :
(X ^ q ^ n - C y).natSepDegree = 1 := by
rw [← expand_X, ← expand_C (q ^ n), ← map_sub, natSepDegree_expand, natSepDegree_X_sub_C]
variable {f} in
/-- If `g` is a separable contraction of `f`, then the separable degree of `f` is equal to
the degree of `g`. -/
theorem IsSeparableContraction.natSepDegree_eq {g : Polynomial F} {q : ℕ} [ExpChar F q]
(h : IsSeparableContraction q f g) : f.natSepDegree = g.natDegree := by
obtain ⟨h1, m, h2⟩ := h
rw [← h2, natSepDegree_expand, h1.natSepDegree_eq_natDegree]
variable {f} in
/-- If a polynomial has separable contraction, then its separable degree is equal to the degree of
the given separable contraction. -/
theorem HasSeparableContraction.natSepDegree_eq
{q : ℕ} [ExpChar F q] (hf : f.HasSeparableContraction q) :
f.natSepDegree = hf.degree := hf.isSeparableContraction.natSepDegree_eq
end Polynomial
namespace Irreducible
variable {F}
variable {f : F[X]}
/-- The separable degree of an irreducible polynomial divides its degree. -/
theorem natSepDegree_dvd_natDegree (h : Irreducible f) :
f.natSepDegree ∣ f.natDegree := by
obtain ⟨q, _⟩ := ExpChar.exists F
have hf := h.hasSeparableContraction q
rw [hf.natSepDegree_eq]
exact hf.dvd_degree
/-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one if and only if it is of the form `Polynomial.expand F (q ^ n) (X - C y)`
for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_of_monic' (q : ℕ) [ExpChar F q] (hm : f.Monic)
(hi : Irreducible f) : f.natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), f = expand F (q ^ n) (X - C y) := by
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· obtain ⟨g, h1, n, rfl⟩ := hi.hasSeparableContraction q
have h2 : g.natDegree = 1 := by
rwa [natSepDegree_expand _ q, h1.natSepDegree_eq_natDegree] at h
rw [((monic_expand_iff <| expChar_pow_pos F q n).mp hm).eq_X_add_C h2]
exact ⟨n, -(g.coeff 0), by rw [map_neg, sub_neg_eq_add]⟩
rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C]
/-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one if and only if it is of the form `X ^ (q ^ n) - C y`
for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_of_monic (q : ℕ) [ExpChar F q] (hm : f.Monic)
(hi : Irreducible f) : f.natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), f = X ^ q ^ n - C y := by
simp_rw [hi.natSepDegree_eq_one_iff_of_monic' q hm, map_sub, expand_X, expand_C]
end Irreducible
namespace Polynomial
namespace Monic
variable {F}
variable {f : F[X]}
alias natSepDegree_eq_one_iff_of_irreducible' := Irreducible.natSepDegree_eq_one_iff_of_monic'
alias natSepDegree_eq_one_iff_of_irreducible := Irreducible.natSepDegree_eq_one_iff_of_monic
/-- If a monic polynomial of separable degree one splits, then it is of form `(X - C y) ^ m` for
some non-zero natural number `m` and some element `y` of `F`. -/
theorem eq_X_sub_C_pow_of_natSepDegree_eq_one_of_splits (hm : f.Monic)
(hs : f.Splits (RingHom.id F))
(h : f.natSepDegree = 1) : ∃ (m : ℕ) (y : F), m ≠ 0 ∧ f = (X - C y) ^ m := by
classical
have h1 := eq_prod_roots_of_monic_of_splits_id hm hs
have h2 := (natSepDegree_eq_of_splits f hs).symm
rw [h, aroots_def, Algebra.id.map_eq_id, map_id, Multiset.toFinset_card_eq_one_iff] at h2
obtain ⟨h2, y, h3⟩ := h2
exact ⟨_, y, h2, by rwa [h3, Multiset.map_nsmul, Multiset.map_singleton, Multiset.prod_nsmul,
Multiset.prod_singleton] at h1⟩
/-- If a monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one, then it is of the form `X ^ (q ^ n) - C y` for some natural number `n`,
and some element `y` of `F`, such that either `n = 0` or `y` has no `q`-th root in `F`. -/
theorem eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible (q : ℕ) [ExpChar F q]
(hm : f.Monic) (hi : Irreducible f) (h : f.natSepDegree = 1) : ∃ (n : ℕ) (y : F),
(n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = X ^ q ^ n - C y := by
obtain ⟨n, y, hf⟩ := (hm.natSepDegree_eq_one_iff_of_irreducible q hi).1 h
cases id ‹ExpChar F q› with
| zero =>
simp_rw [one_pow, pow_one] at hf ⊢
exact ⟨0, y, .inl rfl, hf⟩
| prime hq =>
refine ⟨n, y, (em _).imp id fun hn ⟨z, hy⟩ ↦ ?_, hf⟩
haveI := expChar_of_injective_ringHom (R := F) C_injective q
rw [hf, ← Nat.succ_pred hn, pow_succ, pow_mul, ← hy, frobenius_def, map_pow,
← sub_pow_expChar] at hi
exact not_irreducible_pow hq.ne_one hi
/-- If a monic polynomial over a field `F` of exponential characteristic `q` has separable degree
one, then it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`,
some natural number `n`, and some element `y` of `F`, such that either `n = 0` or `y` has no
`q`-th root in `F`. -/
theorem eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one (q : ℕ) [ExpChar F q] (hm : f.Monic)
(h : f.natSepDegree = 1) : ∃ (m n : ℕ) (y : F),
m ≠ 0 ∧ (n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = (X ^ q ^ n - C y) ^ m := by
obtain ⟨p, hM, hI, hf⟩ := exists_monic_irreducible_factor _ <| not_isUnit_of_natDegree_pos _
<| Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).1 (h.symm ▸ Nat.one_ne_zero)
have hD := (h ▸ natSepDegree_le_of_dvd p f hf hm.ne_zero).antisymm <|
Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).2 hI.natDegree_pos.ne'
obtain ⟨n, y, H, hp⟩ := hM.eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible q hI hD
have hF := finiteMultiplicity_of_degree_pos_of_monic (degree_pos_of_irreducible hI) hM hm.ne_zero
classical
have hne := (multiplicity_pos_of_dvd hf).ne'
refine ⟨_, n, y, hne, H, ?_⟩
obtain ⟨c, hf, H⟩ := hF.exists_eq_pow_mul_and_not_dvd
rw [hf, natSepDegree_mul_of_isCoprime _ c <| IsCoprime.pow_left <|
(hI.isCoprime_or_dvd c).resolve_right H, natSepDegree_pow_of_ne_zero _ hne, hD,
| add_eq_left, natSepDegree_eq_zero_iff] at h
simpa only [eq_one_of_monic_natDegree_zero ((hM.pow _).of_mul_monic_left (hf ▸ hm)) h,
mul_one, ← hp] using hf
/-- A monic polynomial over a field `F` of exponential characteristic `q` has separable degree one
if and only if it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`,
some natural number `n`, and some element `y` of `F`. -/
theorem natSepDegree_eq_one_iff (q : ℕ) [ExpChar F q] (hm : f.Monic) :
f.natSepDegree = 1 ↔ ∃ (m n : ℕ) (y : F), m ≠ 0 ∧ f = (X ^ q ^ n - C y) ^ m := by
refine ⟨fun h ↦ ?_, fun ⟨m, n, y, hm, h⟩ ↦ ?_⟩
· obtain ⟨m, n, y, hm, -, h⟩ := hm.eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one q h
exact ⟨m, n, y, hm, h⟩
| Mathlib/FieldTheory/SeparableDegree.lean | 602 | 613 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Bounded
import Mathlib.Analysis.Normed.Group.Uniform
import Mathlib.Topology.MetricSpace.Thickening
/-!
# Properties of pointwise addition of sets in normed groups
We explore the relationships between pointwise addition of sets in normed groups, and the norm.
Notably, we show that the sum of bounded sets remain bounded.
-/
open Metric Set Pointwise Topology
variable {E : Type*}
section SeminormedGroup
variable [SeminormedGroup E] {s t : Set E}
-- note: we can't use `LipschitzOnWith.isBounded_image2` here without adding `[IsIsometricSMul E E]`
@[to_additive]
theorem Bornology.IsBounded.mul (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s * t) := by
obtain ⟨Rs, hRs⟩ : ∃ R, ∀ x ∈ s, ‖x‖ ≤ R := hs.exists_norm_le'
obtain ⟨Rt, hRt⟩ : ∃ R, ∀ x ∈ t, ‖x‖ ≤ R := ht.exists_norm_le'
refine isBounded_iff_forall_norm_le'.2 ⟨Rs + Rt, ?_⟩
rintro z ⟨x, hx, y, hy, rfl⟩
exact norm_mul_le_of_le' (hRs x hx) (hRt y hy)
@[to_additive]
theorem Bornology.IsBounded.of_mul (hst : IsBounded (s * t)) : IsBounded s ∨ IsBounded t :=
AntilipschitzWith.isBounded_of_image2_left _ (fun x => (isometry_mul_right x).antilipschitz) hst
@[to_additive]
theorem Bornology.IsBounded.inv : IsBounded s → IsBounded s⁻¹ := by
simp_rw [isBounded_iff_forall_norm_le', ← image_inv_eq_inv, forall_mem_image, norm_inv']
exact id
@[to_additive]
theorem Bornology.IsBounded.div (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s / t) :=
div_eq_mul_inv s t ▸ hs.mul ht.inv
end SeminormedGroup
section SeminormedCommGroup
variable [SeminormedCommGroup E] {δ : ℝ} {s : Set E} {x y : E}
section EMetric
open EMetric
@[to_additive (attr := simp)]
theorem infEdist_inv_inv (x : E) (s : Set E) : infEdist x⁻¹ s⁻¹ = infEdist x s := by
rw [← image_inv_eq_inv, infEdist_image isometry_inv]
@[to_additive]
theorem infEdist_inv (x : E) (s : Set E) : infEdist x⁻¹ s = infEdist x s⁻¹ := by
rw [← infEdist_inv_inv, inv_inv]
@[to_additive]
theorem ediam_mul_le (x y : Set E) : EMetric.diam (x * y) ≤ EMetric.diam x + EMetric.diam y :=
(LipschitzOnWith.ediam_image2_le (· * ·) _ _
(fun _ _ => (isometry_mul_right _).lipschitz.lipschitzOnWith) fun _ _ =>
(isometry_mul_left _).lipschitz.lipschitzOnWith).trans_eq <|
by simp only [ENNReal.coe_one, one_mul]
end EMetric
variable (δ s x y)
@[to_additive (attr := simp)]
theorem inv_thickening : (thickening δ s)⁻¹ = thickening δ s⁻¹ := by
simp_rw [thickening, ← infEdist_inv]
rfl
@[to_additive (attr := simp)]
theorem inv_cthickening : (cthickening δ s)⁻¹ = cthickening δ s⁻¹ := by
simp_rw [cthickening, ← infEdist_inv]
rfl
@[to_additive (attr := simp)]
theorem inv_ball : (ball x δ)⁻¹ = ball x⁻¹ δ := (IsometryEquiv.inv E).preimage_ball x δ
@[to_additive (attr := simp)]
theorem inv_closedBall : (closedBall x δ)⁻¹ = closedBall x⁻¹ δ :=
(IsometryEquiv.inv E).preimage_closedBall x δ
@[to_additive]
theorem singleton_mul_ball : {x} * ball y δ = ball (x * y) δ := by
simp only [preimage_mul_ball, image_mul_left, singleton_mul, div_inv_eq_mul, mul_comm y x]
@[to_additive]
theorem singleton_div_ball : {x} / ball y δ = ball (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_ball, singleton_mul_ball]
@[to_additive]
theorem ball_mul_singleton : ball x δ * {y} = ball (x * y) δ := by
rw [mul_comm, singleton_mul_ball, mul_comm y]
@[to_additive]
theorem ball_div_singleton : ball x δ / {y} = ball (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_singleton, ball_mul_singleton]
@[to_additive]
theorem singleton_mul_ball_one : {x} * ball 1 δ = ball x δ := by simp
@[to_additive]
theorem singleton_div_ball_one : {x} / ball 1 δ = ball x δ := by
rw [singleton_div_ball, div_one]
@[to_additive]
theorem ball_one_mul_singleton : ball 1 δ * {x} = ball x δ := by simp [ball_mul_singleton]
@[to_additive]
theorem ball_one_div_singleton : ball 1 δ / {x} = ball x⁻¹ δ := by
rw [ball_div_singleton, one_div]
@[to_additive]
theorem smul_ball_one : x • ball (1 : E) δ = ball x δ := by
rw [smul_ball, smul_eq_mul, mul_one]
@[to_additive (attr := simp 1100)]
theorem singleton_mul_closedBall : {x} * closedBall y δ = closedBall (x * y) δ := by
simp_rw [singleton_mul, ← smul_eq_mul, image_smul, smul_closedBall]
@[to_additive (attr := simp 1100)]
theorem singleton_div_closedBall : {x} / closedBall y δ = closedBall (x / y) δ := by
simp_rw [div_eq_mul_inv, inv_closedBall, singleton_mul_closedBall]
@[to_additive (attr := simp 1100)]
theorem closedBall_mul_singleton : closedBall x δ * {y} = closedBall (x * y) δ := by
simp [mul_comm _ {y}, mul_comm y]
@[to_additive (attr := simp 1100)]
theorem closedBall_div_singleton : closedBall x δ / {y} = closedBall (x / y) δ := by
simp [div_eq_mul_inv]
@[to_additive]
theorem singleton_mul_closedBall_one : {x} * closedBall 1 δ = closedBall x δ := by simp
@[to_additive]
theorem singleton_div_closedBall_one : {x} / closedBall 1 δ = closedBall x δ := by
rw [singleton_div_closedBall, div_one]
@[to_additive]
theorem closedBall_one_mul_singleton : closedBall 1 δ * {x} = closedBall x δ := by simp
@[to_additive]
theorem closedBall_one_div_singleton : closedBall 1 δ / {x} = closedBall x⁻¹ δ := by simp
@[to_additive (attr := simp 1100)]
theorem smul_closedBall_one : x • closedBall (1 : E) δ = closedBall x δ := by simp
@[to_additive]
theorem mul_ball_one : s * ball 1 δ = thickening δ s := by
rw [thickening_eq_biUnion_ball]
convert iUnion₂_mul (fun x (_ : x ∈ s) => {x}) (ball (1 : E) δ)
· exact s.biUnion_of_singleton.symm
ext x
simp_rw [singleton_mul_ball, mul_one]
@[to_additive]
theorem div_ball_one : s / ball 1 δ = thickening δ s := by simp [div_eq_mul_inv, mul_ball_one]
@[to_additive]
theorem ball_mul_one : ball 1 δ * s = thickening δ s := by rw [mul_comm, mul_ball_one]
@[to_additive]
theorem ball_div_one : ball 1 δ / s = thickening δ s⁻¹ := by simp [div_eq_mul_inv, ball_mul_one]
@[to_additive (attr := simp)]
theorem mul_ball : s * ball x δ = x • thickening δ s := by
rw [← smul_ball_one, mul_smul_comm, mul_ball_one]
@[to_additive (attr := simp)]
theorem div_ball : s / ball x δ = x⁻¹ • thickening δ s := by simp [div_eq_mul_inv]
@[to_additive (attr := simp)]
theorem ball_mul : ball x δ * s = x • thickening δ s := by rw [mul_comm, mul_ball]
@[to_additive (attr := simp)]
theorem ball_div : ball x δ / s = x • thickening δ s⁻¹ := by simp [div_eq_mul_inv]
variable {δ s x y}
@[to_additive]
theorem IsCompact.mul_closedBall_one (hs : IsCompact s) (hδ : 0 ≤ δ) :
s * closedBall (1 : E) δ = cthickening δ s := by
rw [hs.cthickening_eq_biUnion_closedBall hδ]
ext x
simp only [mem_mul, dist_eq_norm_div, exists_prop, mem_iUnion, mem_closedBall, exists_and_left,
mem_closedBall_one_iff, ← eq_div_iff_mul_eq'', div_one, exists_eq_right]
@[to_additive]
theorem IsCompact.div_closedBall_one (hs : IsCompact s) (hδ : 0 ≤ δ) :
s / closedBall 1 δ = cthickening δ s := by simp [div_eq_mul_inv, hs.mul_closedBall_one hδ]
@[to_additive]
theorem IsCompact.closedBall_one_mul (hs : IsCompact s) (hδ : 0 ≤ δ) :
closedBall 1 δ * s = cthickening δ s := by rw [mul_comm, hs.mul_closedBall_one hδ]
@[to_additive]
theorem IsCompact.closedBall_one_div (hs : IsCompact s) (hδ : 0 ≤ δ) :
closedBall 1 δ / s = cthickening δ s⁻¹ := by
simp [div_eq_mul_inv, mul_comm, hs.inv.mul_closedBall_one hδ]
@[to_additive]
theorem IsCompact.mul_closedBall (hs : IsCompact s) (hδ : 0 ≤ δ) (x : E) :
s * closedBall x δ = x • cthickening δ s := by
rw [← smul_closedBall_one, mul_smul_comm, hs.mul_closedBall_one hδ]
@[to_additive]
theorem IsCompact.div_closedBall (hs : IsCompact s) (hδ : 0 ≤ δ) (x : E) :
s / closedBall x δ = x⁻¹ • cthickening δ s := by
simp [div_eq_mul_inv, mul_comm, hs.mul_closedBall hδ]
@[to_additive]
theorem IsCompact.closedBall_mul (hs : IsCompact s) (hδ : 0 ≤ δ) (x : E) :
closedBall x δ * s = x • cthickening δ s := by rw [mul_comm, hs.mul_closedBall hδ]
@[to_additive]
theorem IsCompact.closedBall_div (hs : IsCompact s) (hδ : 0 ≤ δ) (x : E) :
closedBall x δ * s = x • cthickening δ s := by
simp [div_eq_mul_inv, hs.closedBall_mul hδ]
end SeminormedCommGroup
| Mathlib/Analysis/Normed/Group/Pointwise.lean | 306 | 308 | |
/-
Copyright (c) 2020 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Utensil Song
-/
import Mathlib.Algebra.RingQuot
import Mathlib.LinearAlgebra.TensorAlgebra.Basic
import Mathlib.LinearAlgebra.QuadraticForm.Isometry
import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv
/-!
# Clifford Algebras
We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with
a quadratic form `Q`.
## Notation
The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is
an `R`-algebra denoted `CliffordAlgebra Q`.
Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that
`cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra
morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`.
The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`.
## Theorems
The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property
of the Clifford algebra.
1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`.
2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1.
## Implementation details
The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows.
1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`.
This is the smallest relation which identifies squares of elements of `M` with `Q m`.
2. The Clifford algebra is the quotient of the tensor algebra by this relation.
This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`.
-/
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
open TensorAlgebra
/-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`.
The Clifford algebra of `M` is defined as the quotient modulo this relation.
-/
inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop
| of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m))
end CliffordAlgebra
/-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`.
-/
def CliffordAlgebra :=
RingQuot (CliffordAlgebra.Rel Q)
namespace CliffordAlgebra
-- The `Inhabited, Semiring, Algebra` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _
instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _
instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A]
[Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M)
[IsScalarTower R A M] :
Algebra R (CliffordAlgebra Q) :=
RingQuot.instAlgebra _
-- verify there are no diamonds
-- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example : (Semiring.toNatAlgebra : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl
-- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example : (Ring.toIntAlgebra _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl
-- shortcut instance, as the other instance is slow
instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _
instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A]
[Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M)
[IsScalarTower R A M] [IsScalarTower S A M] :
SMulCommClass R S (CliffordAlgebra Q) :=
RingQuot.instSMulCommClass _
instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing 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] (Q : QuadraticForm A M) :
IsScalarTower R S (CliffordAlgebra Q) :=
RingQuot.instIsScalarTower _
/-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`.
-/
def ι : M →ₗ[R] CliffordAlgebra Q :=
(RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R)
/-- As well as being linear, `ι Q` squares to the quadratic form -/
@[simp]
theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by
rw [ι]
erw [LinearMap.comp_apply]
rw [AlgHom.toLinearMap_apply, ← map_mul (RingQuot.mkAlgHom R (Rel Q)),
RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes]
rfl
variable {Q} {A : Type*} [Semiring A] [Algebra R A]
@[simp]
theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) :
g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by
rw [← map_mul, ι_sq_scalar, AlgHom.commutes]
variable (Q) in
/-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition:
`cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras
from `CliffordAlgebra Q` to `A`.
-/
@[simps symm_apply]
def lift :
{ f : M →ₗ[R] A // ∀ m, f m * f m = algebraMap _ _ (Q m) } ≃ (CliffordAlgebra Q →ₐ[R] A) where
toFun f :=
RingQuot.liftAlgHom R
⟨TensorAlgebra.lift R (f : M →ₗ[R] A), fun x y (h : Rel Q x y) => by
induction h
rw [AlgHom.commutes, map_mul, TensorAlgebra.lift_ι_apply, f.prop]⟩
invFun F :=
⟨F.toLinearMap.comp (ι Q), fun m => by
rw [LinearMap.comp_apply, AlgHom.toLinearMap_apply, comp_ι_sq_scalar]⟩
left_inv f := by
ext x
exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x)
right_inv F :=
RingQuot.ringQuot_ext' _ _ _ <|
TensorAlgebra.hom_ext <|
LinearMap.ext fun x ↦
(RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _)
@[simp]
theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) :
(lift Q ⟨f, cond⟩).toLinearMap.comp (ι Q) = f :=
Subtype.mk_eq_mk.mp <| (lift Q).symm_apply_apply ⟨f, cond⟩
@[simp]
theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) (x) :
lift Q ⟨f, cond⟩ (ι Q x) = f x :=
(LinearMap.ext_iff.mp <| ι_comp_lift f cond) x
@[simp]
theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebraMap _ _ (Q m))
(g : CliffordAlgebra Q →ₐ[R] A) : g.toLinearMap.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ := by
convert (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).symm_apply_eq
rw [lift_symm_apply, Subtype.mk_eq_mk]
@[simp]
theorem lift_comp_ι (g : CliffordAlgebra Q →ₐ[R] A) :
lift Q ⟨g.toLinearMap.comp (ι Q), comp_ι_sq_scalar _⟩ = g := by
exact (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).apply_symm_apply g
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : CliffordAlgebra Q →ₐ[R] A} :
f.toLinearMap.comp (ι Q) = g.toLinearMap.comp (ι Q) → f = g := by
intro h
apply (lift Q).symm.injective
rw [lift_symm_apply, lift_symm_apply]
simp only [h]
-- This proof closely follows `TensorAlgebra.induction`
/-- If `C` holds for the `algebraMap` of `r : R` into `CliffordAlgebra Q`, the `ι` of `x : M`,
and is preserved under addition and multiplication, then it holds for all of `CliffordAlgebra Q`.
See also the stronger `CliffordAlgebra.left_induction` and `CliffordAlgebra.right_induction`.
-/
@[elab_as_elim]
theorem induction {C : CliffordAlgebra Q → Prop}
(algebraMap : ∀ r, C (algebraMap R (CliffordAlgebra Q) r)) (ι : ∀ x, C (ι Q x))
(mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b))
(a : CliffordAlgebra Q) : C a := by
-- the arguments are enough to construct a subalgebra, and a mapping into it from M
let s : Subalgebra R (CliffordAlgebra Q) :=
{ carrier := C
mul_mem' := @mul
add_mem' := @add
algebraMap_mem' := algebraMap }
let of : { f : M →ₗ[R] s // ∀ m, f m * f m = _root_.algebraMap _ _ (Q m) } :=
⟨(CliffordAlgebra.ι Q).codRestrict (Subalgebra.toSubmodule s) ι,
fun m => Subtype.eq <| ι_sq_scalar Q m⟩
-- the mapping through the subalgebra is the identity
have of_id : s.val.comp (lift Q of) = AlgHom.id R (CliffordAlgebra Q) := by
ext x
simp [of]
-- porting note: `simp` should fire with the following lemma automatically
have := LinearMap.codRestrict_apply s.toSubmodule (CliffordAlgebra.ι Q) x (h := ι)
exact this
-- finding a proof is finding an element of the subalgebra
rw [← AlgHom.id_apply (R := R) a, ← of_id]
exact (lift Q of a).prop
theorem mul_add_swap_eq_polar_of_forall_mul_self_eq {A : Type*} [Ring A] [Algebra R A]
(f : M →ₗ[R] A) (hf : ∀ x, f x * f x = algebraMap _ _ (Q x)) (a b : M) :
f a * f b + f b * f a = algebraMap R _ (QuadraticMap.polar Q a b) :=
calc
f a * f b + f b * f a = f (a + b) * f (a + b) - f a * f a - f b * f b := by
rw [f.map_add, mul_add, add_mul, add_mul]; abel
_ = algebraMap R _ (Q (a + b)) - algebraMap R _ (Q a) - algebraMap R _ (Q b) := by
rw [hf, hf, hf]
_ = algebraMap R _ (Q (a + b) - Q a - Q b) := by rw [← RingHom.map_sub, ← RingHom.map_sub]
_ = algebraMap R _ (QuadraticMap.polar Q a b) := rfl
/-- An alternative way to provide the argument to `CliffordAlgebra.lift` when `2` is invertible.
To show a function squares to the quadratic form, it suffices to show that
`f x * f y + f y * f x = algebraMap _ _ (polar Q x y)` -/
theorem forall_mul_self_eq_iff {A : Type*} [Ring A] [Algebra R A] (h2 : IsUnit (2 : A))
(f : M →ₗ[R] A) :
(∀ x, f x * f x = algebraMap _ _ (Q x)) ↔
(LinearMap.mul R A).compl₂ f ∘ₗ f + (LinearMap.mul R A).flip.compl₂ f ∘ₗ f =
Q.polarBilin.compr₂ (Algebra.linearMap R A) := by
simp_rw [DFunLike.ext_iff]
refine ⟨mul_add_swap_eq_polar_of_forall_mul_self_eq _, fun h x => ?_⟩
change ∀ x y : M, f x * f y + f y * f x = algebraMap R A (QuadraticMap.polar Q x y) at h
apply h2.mul_left_cancel
rw [two_mul, two_mul, h x x, QuadraticMap.polar_self, two_smul, map_add]
/-- The symmetric product of vectors is a scalar -/
theorem ι_mul_ι_add_swap (a b : M) :
ι Q a * ι Q b + ι Q b * ι Q a = algebraMap R _ (QuadraticMap.polar Q a b) :=
mul_add_swap_eq_polar_of_forall_mul_self_eq _ (ι_sq_scalar _) _ _
theorem ι_mul_ι_comm (a b : M) :
ι Q a * ι Q b = algebraMap R _ (QuadraticMap.polar Q a b) - ι Q b * ι Q a :=
eq_sub_of_add_eq (ι_mul_ι_add_swap a b)
section isOrtho
@[simp] theorem ι_mul_ι_add_swap_of_isOrtho {a b : M} (h : Q.IsOrtho a b) :
ι Q a * ι Q b + ι Q b * ι Q a = 0 := by
rw [ι_mul_ι_add_swap, h.polar_eq_zero]
simp
theorem ι_mul_ι_comm_of_isOrtho {a b : M} (h : Q.IsOrtho a b) :
ι Q a * ι Q b = -(ι Q b * ι Q a) :=
eq_neg_of_add_eq_zero_left <| ι_mul_ι_add_swap_of_isOrtho h
theorem mul_ι_mul_ι_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) :
x * ι Q a * ι Q b = -(x * ι Q b * ι Q a) := by
rw [mul_assoc, ι_mul_ι_comm_of_isOrtho h, mul_neg, mul_assoc]
theorem ι_mul_ι_mul_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) :
ι Q a * (ι Q b * x) = -(ι Q b * (ι Q a * x)) := by
rw [← mul_assoc, ι_mul_ι_comm_of_isOrtho h, neg_mul, mul_assoc]
end isOrtho
/-- $aba$ is a vector. -/
theorem ι_mul_ι_mul_ι (a b : M) :
ι Q a * ι Q b * ι Q a = ι Q (QuadraticMap.polar Q a b • a - Q a • b) := by
rw [ι_mul_ι_comm, sub_mul, mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← Algebra.commutes, ←
Algebra.smul_def, ← map_smul, ← map_smul, ← map_sub]
@[simp]
theorem ι_range_map_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) :
(LinearMap.range (ι Q)).map (lift Q ⟨f, cond⟩).toLinearMap = LinearMap.range f := by
rw [← LinearMap.range_comp, ι_comp_lift]
section Map
variable {M₁ M₂ M₃ : Type*}
variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃]
variable [Module R M₁] [Module R M₂] [Module R M₃]
variable {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃}
/-- Any linear map that preserves the quadratic form lifts to an `AlgHom` between algebras.
See `CliffordAlgebra.equivOfIsometry` for the case when `f` is a `QuadraticForm.IsometryEquiv`. -/
def map (f : Q₁ →qᵢ Q₂) :
CliffordAlgebra Q₁ →ₐ[R] CliffordAlgebra Q₂ :=
CliffordAlgebra.lift Q₁
⟨ι Q₂ ∘ₗ f.toLinearMap, fun m => (ι_sq_scalar _ _).trans <| RingHom.congr_arg _ <| f.map_app m⟩
@[simp]
theorem map_comp_ι (f : Q₁ →qᵢ Q₂) :
(map f).toLinearMap ∘ₗ ι Q₁ = ι Q₂ ∘ₗ f.toLinearMap :=
ι_comp_lift _ _
@[simp]
theorem map_apply_ι (f : Q₁ →qᵢ Q₂) (m : M₁) : map f (ι Q₁ m) = ι Q₂ (f m) :=
lift_ι_apply _ _ m
variable (Q₁) in
@[simp]
theorem map_id : map (QuadraticMap.Isometry.id Q₁) = AlgHom.id R (CliffordAlgebra Q₁) := by
ext m; exact map_apply_ι _ m
@[simp]
theorem map_comp_map (f : Q₂ →qᵢ Q₃) (g : Q₁ →qᵢ Q₂) :
(map f).comp (map g) = map (f.comp g) := by
ext m
dsimp only [LinearMap.comp_apply, AlgHom.comp_apply, AlgHom.toLinearMap_apply, AlgHom.id_apply]
rw [map_apply_ι, map_apply_ι, map_apply_ι, QuadraticMap.Isometry.comp_apply]
@[simp]
theorem ι_range_map_map (f : Q₁ →qᵢ Q₂) :
(LinearMap.range (ι Q₁)).map (map f).toLinearMap = (LinearMap.range f).map (ι Q₂) :=
(ι_range_map_lift _ _).trans (LinearMap.range_comp _ _)
open Function in
/-- If `f` is a linear map from `M₁` to `M₂` that preserves the quadratic forms, and if it has
a linear retraction `g` that also preserves the quadratic forms, then `CliffordAlgebra.map g`
is a retraction of `CliffordAlgebra.map f`. -/
lemma leftInverse_map_of_leftInverse {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂}
(f : Q₁ →qᵢ Q₂) (g : Q₂ →qᵢ Q₁) (h : LeftInverse g f) : LeftInverse (map g) (map f) := by
refine fun x => ?_
replace h : g.comp f = QuadraticMap.Isometry.id Q₁ := DFunLike.ext _ _ h
rw [← AlgHom.comp_apply, map_comp_map, h, map_id, AlgHom.coe_id, id_eq]
/-- If a linear map preserves the quadratic forms and is surjective, then the algebra
maps it induces between Clifford algebras is also surjective. -/
lemma map_surjective {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} (f : Q₁ →qᵢ Q₂)
(hf : Function.Surjective f) : Function.Surjective (CliffordAlgebra.map f) :=
CliffordAlgebra.induction
(fun r ↦ ⟨algebraMap R (CliffordAlgebra Q₁) r, by simp only [AlgHom.commutes]⟩)
(fun y ↦ let ⟨x, hx⟩ := hf y; ⟨CliffordAlgebra.ι Q₁ x, by simp only [map_apply_ι, hx]⟩)
(fun _ _ ⟨x, hx⟩ ⟨y, hy⟩ ↦ ⟨x * y, by simp only [map_mul, hx, hy]⟩)
(fun _ _ ⟨x, hx⟩ ⟨y, hy⟩ ↦ ⟨x + y, by simp only [map_add, hx, hy]⟩)
/-- Two `CliffordAlgebra`s are equivalent as algebras if their quadratic forms are
equivalent. -/
@[simps! apply]
def equivOfIsometry (e : Q₁.IsometryEquiv Q₂) : CliffordAlgebra Q₁ ≃ₐ[R] CliffordAlgebra Q₂ :=
AlgEquiv.ofAlgHom (map e.toIsometry) (map e.symm.toIsometry)
((map_comp_map _ _).trans <| by
convert map_id Q₂ using 2
ext m
exact e.toLinearEquiv.apply_symm_apply m)
((map_comp_map _ _).trans <| by
convert map_id Q₁ using 2
ext m
exact e.toLinearEquiv.symm_apply_apply m)
@[simp]
theorem equivOfIsometry_symm (e : Q₁.IsometryEquiv Q₂) :
(equivOfIsometry e).symm = equivOfIsometry e.symm :=
rfl
@[simp]
theorem equivOfIsometry_trans (e₁₂ : Q₁.IsometryEquiv Q₂) (e₂₃ : Q₂.IsometryEquiv Q₃) :
(equivOfIsometry e₁₂).trans (equivOfIsometry e₂₃) = equivOfIsometry (e₁₂.trans e₂₃) := by
ext x
exact AlgHom.congr_fun (map_comp_map _ _) x
@[simp]
theorem equivOfIsometry_refl :
(equivOfIsometry <| QuadraticMap.IsometryEquiv.refl Q₁) = AlgEquiv.refl := by
ext x
exact AlgHom.congr_fun (map_id Q₁) x
end Map
end CliffordAlgebra
namespace TensorAlgebra
variable {Q}
/-- The canonical image of the `TensorAlgebra` in the `CliffordAlgebra`, which maps
`TensorAlgebra.ι R x` to `CliffordAlgebra.ι Q x`. -/
def toClifford : TensorAlgebra R M →ₐ[R] CliffordAlgebra Q :=
TensorAlgebra.lift R (CliffordAlgebra.ι Q)
@[simp]
theorem toClifford_ι (m : M) : toClifford (TensorAlgebra.ι R m) = CliffordAlgebra.ι Q m := by
simp [toClifford]
end TensorAlgebra
| Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean | 400 | 403 | |
/-
Copyright (c) 2022 Joachim Breitner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joachim Breitner
-/
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Order.SupIndep
/-!
# Canonical homomorphism from a finite family of monoids
This file defines the construction of the canonical homomorphism from a family of monoids.
Given a family of morphisms `ϕ i : N i →* M` for each `i : ι` where elements in the
images of different morphisms commute, we obtain a canonical morphism
`MonoidHom.noncommPiCoprod : (Π i, N i) →* M` that coincides with `ϕ`
## Main definitions
* `MonoidHom.noncommPiCoprod : (Π i, N i) →* M` is the main homomorphism
* `Subgroup.noncommPiCoprod : (Π i, H i) →* G` is the specialization to `H i : Subgroup G`
and the subgroup embedding.
## Main theorems
* `MonoidHom.noncommPiCoprod` coincides with `ϕ i` when restricted to `N i`
* `MonoidHom.noncommPiCoprod_mrange`: The range of `MonoidHom.noncommPiCoprod` is
`⨆ (i : ι), (ϕ i).mrange`
* `MonoidHom.noncommPiCoprod_range`: The range of `MonoidHom.noncommPiCoprod` is
`⨆ (i : ι), (ϕ i).range`
* `Subgroup.noncommPiCoprod_range`: The range of `Subgroup.noncommPiCoprod` is `⨆ (i : ι), H i`.
* `MonoidHom.injective_noncommPiCoprod_of_iSupIndep`: in the case of groups, `pi_hom.hom` is
injective if the `ϕ` are injective and the ranges of the `ϕ` are independent.
* `MonoidHom.independent_range_of_coprime_order`: If the `N i` have coprime orders, then the ranges
of the `ϕ` are independent.
* `Subgroup.independent_of_coprime_order`: If commuting normal subgroups `H i` have coprime orders,
they are independent.
-/
assert_not_exists Field
namespace Subgroup
variable {G : Type*} [Group G]
/-- `Finset.noncommProd` is “injective” in `f` if `f` maps into independent subgroups. This
generalizes (one direction of) `Subgroup.disjoint_iff_mul_eq_one`. -/
@[to_additive "`Finset.noncommSum` is “injective” in `f` if `f` maps into independent subgroups.
This generalizes (one direction of) `AddSubgroup.disjoint_iff_add_eq_zero`. "]
theorem eq_one_of_noncommProd_eq_one_of_iSupIndep {ι : Type*} (s : Finset ι) (f : ι → G) (comm)
(K : ι → Subgroup G) (hind : iSupIndep K) (hmem : ∀ x ∈ s, f x ∈ K x)
(heq1 : s.noncommProd f comm = 1) : ∀ i ∈ s, f i = 1 := by
classical
revert heq1
induction' s using Finset.induction_on with i s hnmem ih
· simp
· have hcomm := comm.mono (Finset.coe_subset.2 <| Finset.subset_insert _ _)
simp only [Finset.forall_mem_insert] at hmem
have hmem_bsupr : s.noncommProd f hcomm ∈ ⨆ i ∈ (s : Set ι), K i := by
refine Subgroup.noncommProd_mem _ _ ?_
intro x hx
have : K x ≤ ⨆ i ∈ (s : Set ι), K i := le_iSup₂ (f := fun i _ => K i) x hx
exact this (hmem.2 x hx)
intro heq1
rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ hnmem] at heq1
have hnmem' : i ∉ (s : Set ι) := by simpa
obtain ⟨heq1i : f i = 1, heq1S : s.noncommProd f _ = 1⟩ :=
Subgroup.disjoint_iff_mul_eq_one.mp (hind.disjoint_biSup hnmem') hmem.1 hmem_bsupr heq1
intro i h
simp only [Finset.mem_insert] at h
rcases h with (rfl | h)
· exact heq1i
· refine ih hcomm hmem.2 heq1S _ h
@[deprecated (since := "2024-11-24")]
alias eq_one_of_noncommProd_eq_one_of_independent := eq_one_of_noncommProd_eq_one_of_iSupIndep
end Subgroup
section FamilyOfMonoids
variable {M : Type*} [Monoid M]
-- We have a family of monoids
-- The fintype assumption is not always used, but declared here, to keep things in order
variable {ι : Type*} [Fintype ι]
variable {N : ι → Type*} [∀ i, Monoid (N i)]
-- And morphisms ϕ into G
variable (ϕ : ∀ i : ι, N i →* M)
-- We assume that the elements of different morphism commute
variable (hcomm : Pairwise fun i j => ∀ x y, Commute (ϕ i x) (ϕ j y))
namespace MonoidHom
/-- The canonical homomorphism from a family of monoids. -/
@[to_additive "The canonical homomorphism from a family of additive monoids. See also
`LinearMap.lsum` for a linear version without the commutativity assumption."]
def noncommPiCoprod : (∀ i : ι, N i) →* M where
toFun f := Finset.univ.noncommProd (fun i => ϕ i (f i)) fun _ _ _ _ h => hcomm h _ _
map_one' := by
apply (Finset.noncommProd_eq_pow_card _ _ _ _ _).trans (one_pow _)
simp
map_mul' f g := by
classical
convert @Finset.noncommProd_mul_distrib _ _ _ _ (fun i => ϕ i (f i)) (fun i => ϕ i (g i)) _ _ _
· exact map_mul _ _ _
· rintro i - j - h
exact hcomm h _ _
variable {hcomm}
@[to_additive (attr := simp)]
theorem noncommPiCoprod_mulSingle [DecidableEq ι] (i : ι) (y : N i) :
noncommPiCoprod ϕ hcomm (Pi.mulSingle i y) = ϕ i y := by
change Finset.univ.noncommProd (fun j => ϕ j (Pi.mulSingle i y j)) (fun _ _ _ _ h => hcomm h _ _)
= ϕ i y
rw [← Finset.insert_erase (Finset.mem_univ i)]
rw [Finset.noncommProd_insert_of_not_mem _ _ _ _ (Finset.not_mem_erase i _)]
rw [Pi.mulSingle_eq_same]
rw [Finset.noncommProd_eq_pow_card]
· rw [one_pow]
exact mul_one _
· intro j hj
simp only [Finset.mem_erase] at hj
simp [hj]
/--
The universal property of `MonoidHom.noncommPiCoprod`
Given monoid morphisms `φᵢ : Nᵢ → M` whose images pairwise commute,
there exists a unique monoid morphism `φ : Πᵢ Nᵢ → M` that induces the `φᵢ`,
and it is given by `MonoidHom.noncommPiCoprod`. -/
@[to_additive "The universal property of `MonoidHom.noncommPiCoprod`
Given monoid morphisms `φᵢ : Nᵢ → M` whose images pairwise commute,
there exists a unique monoid morphism `φ : Πᵢ Nᵢ → M` that induces the `φᵢ`,
and it is given by `AddMonoidHom.noncommPiCoprod`."]
def noncommPiCoprodEquiv [DecidableEq ι] :
{ ϕ : ∀ i, N i →* M // Pairwise fun i j => ∀ x y, Commute (ϕ i x) (ϕ j y) } ≃
((∀ i, N i) →* M) where
toFun ϕ := noncommPiCoprod ϕ.1 ϕ.2
invFun f :=
⟨fun i => f.comp (MonoidHom.mulSingle N i), fun _ _ hij x y =>
Commute.map (Pi.mulSingle_commute hij x y) f⟩
left_inv ϕ := by
ext
simp only [coe_comp, Function.comp_apply, mulSingle_apply, noncommPiCoprod_mulSingle]
right_inv f := pi_ext fun i x => by
simp only [noncommPiCoprod_mulSingle, coe_comp, Function.comp_apply, mulSingle_apply]
@[to_additive]
theorem noncommPiCoprod_mrange :
MonoidHom.mrange (noncommPiCoprod ϕ hcomm) = ⨆ i : ι, MonoidHom.mrange (ϕ i) := by
letI := Classical.decEq ι
apply le_antisymm
· rintro x ⟨f, rfl⟩
refine Submonoid.noncommProd_mem _ _ _ (fun _ _ _ _ h => hcomm h _ _) (fun i _ => ?_)
apply Submonoid.mem_sSup_of_mem
· use i
simp
· refine iSup_le ?_
rintro i x ⟨y, rfl⟩
exact ⟨Pi.mulSingle i y, noncommPiCoprod_mulSingle _ _ _⟩
@[to_additive]
lemma commute_noncommPiCoprod {m : M}
(comm : ∀ i (x : N i), Commute m ((ϕ i x))) (h : (i : ι) → N i) :
Commute m (MonoidHom.noncommPiCoprod ϕ hcomm h) := by
dsimp only [MonoidHom.noncommPiCoprod, MonoidHom.coe_mk, OneHom.coe_mk]
apply Finset.noncommProd_induction
· exact fun x y ↦ Commute.mul_right
· exact Commute.one_right _
· exact fun x _ ↦ comm x (h x)
@[to_additive]
lemma noncommPiCoprod_apply (h : (i : ι) → N i) :
MonoidHom.noncommPiCoprod ϕ hcomm h = Finset.noncommProd Finset.univ (fun i ↦ ϕ i (h i))
(Pairwise.set_pairwise (fun ⦃i j⦄ a ↦ hcomm a (h i) (h j)) _) := by
dsimp only [MonoidHom.noncommPiCoprod, MonoidHom.coe_mk, OneHom.coe_mk]
/--
Given monoid morphisms `φᵢ : Nᵢ → M` and `f : M → P`, if we have sufficient commutativity, then
`f ∘ (∐ᵢ φᵢ) = ∐ᵢ (f ∘ φᵢ)` -/
@[to_additive]
theorem comp_noncommPiCoprod {P : Type*} [Monoid P] {f : M →* P}
(hcomm' : Pairwise fun i j => ∀ x y, Commute (f.comp (ϕ i) x) (f.comp (ϕ j) y) :=
Pairwise.mono hcomm (fun i j ↦ forall_imp (fun x h y ↦ by
simp only [MonoidHom.coe_comp, Function.comp_apply, Commute.map (h y) f]))) :
| f.comp (MonoidHom.noncommPiCoprod ϕ hcomm) =
MonoidHom.noncommPiCoprod (fun i ↦ f.comp (ϕ i)) hcomm' :=
MonoidHom.ext fun _ ↦ by
simp only [MonoidHom.noncommPiCoprod, MonoidHom.coe_comp, MonoidHom.coe_mk, OneHom.coe_mk,
Function.comp_apply, Finset.map_noncommProd]
end MonoidHom
end FamilyOfMonoids
section FamilyOfGroups
| Mathlib/GroupTheory/NoncommPiCoprod.lean | 193 | 204 |
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Joël Riou
-/
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.ConeCategory
/-!
# Multi-(co)equalizers
A *multiequalizer* is an equalizer of two morphisms between two products.
Since both products and equalizers are limits, such an object is again a limit.
This file provides the diagram whose limit is indeed such an object.
In fact, it is well-known that any limit can be obtained as a multiequalizer.
The dual construction (multicoequalizers) is also provided.
## Projects
Prove that a multiequalizer can be identified with
an equalizer between products (and analogously for multicoequalizers).
Prove that the limit of any diagram is a multiequalizer (and similarly for colimits).
-/
namespace CategoryTheory.Limits
universe w w' v u
/-- The shape of a multiequalizer diagram. It involves two types `L` and `R`,
and two maps `R → L`. -/
@[nolint checkUnivs]
structure MulticospanShape where
/-- the left type -/
L : Type w
/-- the right type -/
R : Type w'
/-- the first map `R → L` -/
fst : R → L
/-- the second map `R → L` -/
snd : R → L
/-- Given a type `ι`, this is the shape of multiequalizer diagrams corresponding
to situations where we want to equalize two families of maps `U i ⟶ V ⟨i, j⟩`
and `U j ⟶ V ⟨i, j⟩` with `i : ι` and `j : ι`. -/
@[simps]
def MulticospanShape.prod (ι : Type w) : MulticospanShape where
L := ι
R := ι × ι
fst := _root_.Prod.fst
snd := _root_.Prod.snd
/-- The shape of a multicoequalizer diagram. It involves two types `L` and `R`,
and two maps `L → R`. -/
@[nolint checkUnivs]
structure MultispanShape where
/-- the left type -/
L : Type w
/-- the right type -/
R : Type w'
/-- the first map `L → R` -/
fst : L → R
/-- the second map `L → R` -/
snd : L → R
/-- Given a type `ι`, this is the shape of multicoequalizer diagrams corresponding
to situations where we want to coequalize two families of maps `V ⟨i, j⟩ ⟶ U i`
and `V ⟨i, j⟩ ⟶ U j` with `i : ι` and `j : ι`. -/
@[simps]
def MultispanShape.prod (ι : Type w) : MultispanShape where
L := ι × ι
R := ι
fst := _root_.Prod.fst
snd := _root_.Prod.snd
/-- Given a linearly ordered type `ι`, this is the shape of multicoequalizer diagrams
corresponding to situations where we want to coequalize two families of maps
`V ⟨i, j⟩ ⟶ U i` and `V ⟨i, j⟩ ⟶ U j` with `i < j`. -/
@[simps]
def MultispanShape.ofLinearOrder (ι : Type w) [LinearOrder ι] : MultispanShape where
L := {x : ι × ι | x.1 < x.2}
R := ι
fst x := x.1.1
snd x := x.1.2
/-- The type underlying the multiequalizer diagram. -/
inductive WalkingMulticospan (J : MulticospanShape.{w, w'}) : Type max w w'
| left : J.L → WalkingMulticospan J
| right : J.R → WalkingMulticospan J
/-- The type underlying the multiecoqualizer diagram. -/
inductive WalkingMultispan (J : MultispanShape.{w, w'}) : Type max w w'
| left : J.L → WalkingMultispan J
| right : J.R → WalkingMultispan J
namespace WalkingMulticospan
variable {J : MulticospanShape.{w, w'}}
instance [Inhabited J.L] : Inhabited (WalkingMulticospan J) :=
⟨left default⟩
-- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- Morphisms for `WalkingMulticospan`. -/
inductive Hom : ∀ _ _ : WalkingMulticospan J, Type max w w'
| id (A) : Hom A A
| fst (b) : Hom (left (J.fst b)) (right b)
| snd (b) : Hom (left (J.snd b)) (right b)
instance {a : WalkingMulticospan J} : Inhabited (Hom a a) :=
⟨Hom.id _⟩
/-- Composition of morphisms for `WalkingMulticospan`. -/
def Hom.comp : ∀ {A B C : WalkingMulticospan J} (_ : Hom A B) (_ : Hom B C), Hom A C
| _, _, _, Hom.id X, f => f
| _, _, _, Hom.fst b, Hom.id _ => Hom.fst b
| _, _, _, Hom.snd b, Hom.id _ => Hom.snd b
instance : SmallCategory (WalkingMulticospan J) where
Hom := Hom
id := Hom.id
comp := Hom.comp
id_comp := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
comp_id := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
assoc := by
rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl
@[simp]
lemma Hom.id_eq_id (X : WalkingMulticospan J) :
Hom.id X = 𝟙 X := rfl
@[simp]
lemma Hom.comp_eq_comp {X Y Z : WalkingMulticospan J}
(f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl
end WalkingMulticospan
namespace WalkingMultispan
variable {J : MultispanShape.{w, w'}}
instance [Inhabited J.L] : Inhabited (WalkingMultispan J) :=
⟨left default⟩
-- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- Morphisms for `WalkingMultispan`. -/
inductive Hom : ∀ _ _ : WalkingMultispan J, Type max w w'
| id (A) : Hom A A
| fst (a) : Hom (left a) (right (J.fst a))
| snd (a) : Hom (left a) (right (J.snd a))
instance {a : WalkingMultispan J} : Inhabited (Hom a a) :=
⟨Hom.id _⟩
/-- Composition of morphisms for `WalkingMultispan`. -/
def Hom.comp : ∀ {A B C : WalkingMultispan J} (_ : Hom A B) (_ : Hom B C), Hom A C
| _, _, _, Hom.id X, f => f
| _, _, _, Hom.fst a, Hom.id _ => Hom.fst a
| _, _, _, Hom.snd a, Hom.id _ => Hom.snd a
instance : SmallCategory (WalkingMultispan J) where
Hom := Hom
id := Hom.id
comp := Hom.comp
id_comp := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
comp_id := by
rintro (_ | _) (_ | _) (_ | _ | _) <;> rfl
assoc := by
rintro (_ | _) (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) (_ | _ | _) <;> rfl
@[simp]
lemma Hom.id_eq_id (X : WalkingMultispan J) : Hom.id X = 𝟙 X := rfl
@[simp]
lemma Hom.comp_eq_comp {X Y Z : WalkingMultispan J}
(f : X ⟶ Y) (g : Y ⟶ Z) : Hom.comp f g = f ≫ g := rfl
end WalkingMultispan
/-- This is a structure encapsulating the data necessary to define a `Multicospan`. -/
@[nolint checkUnivs]
structure MulticospanIndex (J : MulticospanShape.{w, w'})
(C : Type u) [Category.{v} C] where
/-- Left map, from `J.L` to `C` -/
left : J.L → C
/-- Right map, from `J.R` to `C` -/
right : J.R → C
/-- A family of maps from `left (J.fst b)` to `right b` -/
fst : ∀ b, left (J.fst b) ⟶ right b
/-- A family of maps from `left (J.snd b)` to `right b` -/
snd : ∀ b, left (J.snd b) ⟶ right b
/-- This is a structure encapsulating the data necessary to define a `Multispan`. -/
@[nolint checkUnivs]
structure MultispanIndex (J : MultispanShape.{w, w'})
(C : Type u) [Category.{v} C] where
/-- Left map, from `J.L` to `C` -/
left : J.L → C
/-- Right map, from `J.R` to `C` -/
right : J.R → C
/-- A family of maps from `left a` to `right (J.fst a)` -/
fst : ∀ a, left a ⟶ right (J.fst a)
/-- A family of maps from `left a` to `right (J.snd a)` -/
snd : ∀ a, left a ⟶ right (J.snd a)
namespace MulticospanIndex
variable {C : Type u} [Category.{v} C] {J : MulticospanShape.{w, w'}}
(I : MulticospanIndex J C)
/-- The multicospan associated to `I : MulticospanIndex`. -/
@[simps]
def multicospan : WalkingMulticospan J ⥤ C where
obj x :=
match x with
| WalkingMulticospan.left a => I.left a
| WalkingMulticospan.right b => I.right b
map {x y} f :=
match x, y, f with
| _, _, WalkingMulticospan.Hom.id x => 𝟙 _
| _, _, WalkingMulticospan.Hom.fst b => I.fst _
| _, _, WalkingMulticospan.Hom.snd b => I.snd _
map_id := by
rintro (_ | _) <;> rfl
map_comp := by
rintro (_ | _) (_ | _) (_ | _) (_ | _ | _) (_ | _ | _) <;> aesop_cat
variable [HasProduct I.left] [HasProduct I.right]
/-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.fst`. -/
noncomputable def fstPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right :=
Pi.lift fun b => Pi.π I.left (J.fst b) ≫ I.fst b
/-- The induced map `∏ᶜ I.left ⟶ ∏ᶜ I.right` via `I.snd`. -/
noncomputable def sndPiMap : ∏ᶜ I.left ⟶ ∏ᶜ I.right :=
Pi.lift fun b => Pi.π I.left (J.snd b) ≫ I.snd b
@[reassoc (attr := simp)]
theorem fstPiMap_π (b) : I.fstPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.fst b := by
simp [fstPiMap]
@[reassoc (attr := simp)]
theorem sndPiMap_π (b) : I.sndPiMap ≫ Pi.π I.right b = Pi.π I.left _ ≫ I.snd b := by
simp [sndPiMap]
/-- Taking the multiequalizer over the multicospan index is equivalent to taking the equalizer over
the two morphisms `∏ᶜ I.left ⇉ ∏ᶜ I.right`. This is the diagram of the latter.
-/
@[simps!]
protected noncomputable def parallelPairDiagram :=
parallelPair I.fstPiMap I.sndPiMap
end MulticospanIndex
namespace MultispanIndex
variable {C : Type u} [Category.{v} C] {J : MultispanShape.{w, w'}}
(I : MultispanIndex J C)
/-- The multispan associated to `I : MultispanIndex`. -/
def multispan : WalkingMultispan J ⥤ C where
obj x :=
match x with
| WalkingMultispan.left a => I.left a
| WalkingMultispan.right b => I.right b
map {x y} f :=
match x, y, f with
| _, _, WalkingMultispan.Hom.id x => 𝟙 _
| _, _, WalkingMultispan.Hom.fst b => I.fst _
| _, _, WalkingMultispan.Hom.snd b => I.snd _
map_id := by
| rintro (_ | _) <;> rfl
map_comp := by
| Mathlib/CategoryTheory/Limits/Shapes/Multiequalizer.lean | 281 | 282 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Card
import Mathlib.Data.Finset.Lattice.Union
import Mathlib.Data.Multiset.Powerset
import Mathlib.Data.Set.Pairwise.Lattice
/-!
# The powerset of a finset
-/
namespace Finset
open Function Multiset
variable {α : Type*} {s t : Finset α}
/-! ### powerset -/
section Powerset
/-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/
def powerset (s : Finset α) : Finset (Finset α) :=
⟨(s.1.powerset.pmap Finset.mk) fun _t h => nodup_of_le (mem_powerset.1 h) s.nodup,
s.nodup.powerset.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩
@[simp]
theorem mem_powerset {s t : Finset α} : s ∈ powerset t ↔ s ⊆ t := by
cases s
simp [powerset, mem_mk, mem_pmap, mk.injEq, mem_powerset, exists_prop, exists_eq_right,
← val_le_iff]
@[simp, norm_cast]
theorem coe_powerset (s : Finset α) :
(s.powerset : Set (Finset α)) = ((↑) : Finset α → Set α) ⁻¹' (s : Set α).powerset := by
ext
simp
theorem empty_mem_powerset (s : Finset α) : ∅ ∈ powerset s := by simp
theorem mem_powerset_self (s : Finset α) : s ∈ powerset s := by simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem powerset_nonempty (s : Finset α) : s.powerset.Nonempty :=
⟨∅, empty_mem_powerset _⟩
@[simp]
theorem powerset_mono {s t : Finset α} : powerset s ⊆ powerset t ↔ s ⊆ t :=
⟨fun h => mem_powerset.1 <| h <| mem_powerset_self _, fun st _u h =>
mem_powerset.2 <| Subset.trans (mem_powerset.1 h) st⟩
theorem powerset_injective : Injective (powerset : Finset α → Finset (Finset α)) :=
(injective_of_le_imp_le _) powerset_mono.1
@[simp]
theorem powerset_inj : powerset s = powerset t ↔ s = t :=
powerset_injective.eq_iff
@[simp]
theorem powerset_empty : (∅ : Finset α).powerset = {∅} :=
rfl
@[simp]
theorem powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ := by
rw [← powerset_empty, powerset_inj]
/-- **Number of Subsets of a Set** -/
@[simp]
theorem card_powerset (s : Finset α) : card (powerset s) = 2 ^ card s :=
(card_pmap _ _ _).trans (Multiset.card_powerset s.1)
theorem not_mem_of_mem_powerset_of_not_mem {s t : Finset α} {a : α} (ht : t ∈ s.powerset)
(h : a ∉ s) : a ∉ t := by
apply mt _ h
apply mem_powerset.1 ht
theorem powerset_insert [DecidableEq α] (s : Finset α) (a : α) :
powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) := by
ext t
simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff]
by_cases h : a ∈ t
· constructor
· exact fun H => Or.inr ⟨_, H, insert_erase h⟩
· intro H
rcases H with H | H
· exact Subset.trans (erase_subset a t) H
· rcases H with ⟨u, hu⟩
rw [← hu.2]
exact Subset.trans (erase_insert_subset a u) hu.1
· have : ¬∃ u : Finset α, u ⊆ s ∧ insert a u = t := by simp [Ne.symm (ne_insert_of_not_mem _ _ h)]
simp [Finset.erase_eq_of_not_mem h, this]
lemma pairwiseDisjoint_pair_insert [DecidableEq α] {a : α} (ha : a ∉ s) :
(s.powerset : Set (Finset α)).PairwiseDisjoint fun t ↦ ({t, insert a t} : Set (Finset α)) := by
simp_rw [Set.pairwiseDisjoint_iff, mem_coe, mem_powerset]
rintro i hi j hj
simp only [Set.Nonempty, Set.mem_inter_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
exists_eq_or_imp, exists_eq_left, or_imp, imp_self, true_and]
refine ⟨?_, ?_, insert_erase_invOn.2.injOn (not_mem_mono hi ha) (not_mem_mono hj ha)⟩ <;>
rintro rfl <;>
cases Finset.not_mem_mono ‹_› ha (Finset.mem_insert_self _ _)
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidableExistsOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop}
[∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∃ (t : _) (h : t ⊆ s), p t h) :=
decidable_of_iff (∃ (t : _) (hs : t ∈ s.powerset), p t (mem_powerset.1 hs))
⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_powerset.2 hs, hp⟩⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidableForallOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop}
[∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∀ (t) (h : t ⊆ s), p t h) :=
decidable_of_iff (∀ (t) (h : t ∈ s.powerset), p t (mem_powerset.1 h))
⟨fun h t hs => h t (mem_powerset.2 hs), fun h _ _ => h _ _⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidableExistsOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop}
[∀ t, Decidable (p t)] : Decidable (∃ t ⊆ s, p t) :=
decidable_of_iff (∃ (t : _) (_h : t ⊆ s), p t) <| by simp
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidableForallOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop}
[∀ t, Decidable (p t)] : Decidable (∀ t ⊆ s, p t) :=
decidable_of_iff (∀ (t : _) (_h : t ⊆ s), p t) <| by simp
end Powerset
section SSubsets
variable [DecidableEq α]
/-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/
def ssubsets (s : Finset α) : Finset (Finset α) :=
erase (powerset s) s
@[simp]
theorem mem_ssubsets {s t : Finset α} : t ∈ s.ssubsets ↔ t ⊂ s := by
rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and_comm]
theorem empty_mem_ssubsets {s : Finset α} (h : s.Nonempty) : ∅ ∈ s.ssubsets := by
rw [mem_ssubsets, ssubset_iff_subset_ne]
exact ⟨empty_subset s, h.ne_empty.symm⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/
def decidableExistsOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop}
[∀ t h, Decidable (p t h)] : Decidable (∃ t h, p t h) :=
decidable_of_iff (∃ (t : _) (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs))
⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_ssubsets.2 hs, hp⟩⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/
def decidableForallOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop}
[∀ t h, Decidable (p t h)] : Decidable (∀ t h, p t h) :=
decidable_of_iff (∀ (t) (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h))
| ⟨fun h t hs => h t (mem_ssubsets.2 hs), fun h _ _ => h _ _⟩
/-- A version of `Finset.decidableExistsOfDecidableSSubsets` with a non-dependent `p`.
| Mathlib/Data/Finset/Powerset.lean | 158 | 160 |
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice.Fold
/-!
# Irreducible and prime elements in an order
This file defines irreducible and prime elements in an order and shows that in a well-founded
lattice every element decomposes as a supremum of irreducible elements.
An element is sup-irreducible (resp. inf-irreducible) if it isn't `⊥` and can't be written as the
supremum of any strictly smaller elements. An element is sup-prime (resp. inf-prime) if it isn't `⊥`
and is greater than the supremum of any two elements less than it.
Primality implies irreducibility in general. The converse only holds in distributive lattices.
Both hold for all (non-minimal) elements in a linear order.
## Main declarations
* `SupIrred a`: Sup-irreducibility, `a` isn't minimal and `a = b ⊔ c → a = b ∨ a = c`
* `InfIrred a`: Inf-irreducibility, `a` isn't maximal and `a = b ⊓ c → a = b ∨ a = c`
* `SupPrime a`: Sup-primality, `a` isn't minimal and `a ≤ b ⊔ c → a ≤ b ∨ a ≤ c`
* `InfIrred a`: Inf-primality, `a` isn't maximal and `a ≥ b ⊓ c → a ≥ b ∨ a ≥ c`
* `exists_supIrred_decomposition`/`exists_infIrred_decomposition`: Decomposition into irreducibles
in a well-founded semilattice.
-/
open Finset OrderDual
variable {ι α : Type*}
/-! ### Irreducible and prime elements -/
section SemilatticeSup
variable [SemilatticeSup α] {a b c : α}
/-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller.
-/
def SupIrred (a : α) : Prop :=
¬IsMin a ∧ ∀ ⦃b c⦄, b ⊔ c = a → b = a ∨ c = a
/-- A sup-prime element is a non-bottom element which isn't less than the supremum of anything
smaller. -/
def SupPrime (a : α) : Prop :=
¬IsMin a ∧ ∀ ⦃b c⦄, a ≤ b ⊔ c → a ≤ b ∨ a ≤ c
theorem SupIrred.not_isMin (ha : SupIrred a) : ¬IsMin a :=
ha.1
theorem SupPrime.not_isMin (ha : SupPrime a) : ¬IsMin a :=
ha.1
theorem IsMin.not_supIrred (ha : IsMin a) : ¬SupIrred a := fun h => h.1 ha
theorem IsMin.not_supPrime (ha : IsMin a) : ¬SupPrime a := fun h => h.1 ha
@[simp]
theorem not_supIrred : ¬SupIrred a ↔ IsMin a ∨ ∃ b c, b ⊔ c = a ∧ b < a ∧ c < a := by
rw [SupIrred, not_and_or]
push_neg
rw [exists₂_congr]
simp +contextual [@eq_comm _ _ a]
@[simp]
theorem not_supPrime : ¬SupPrime a ↔ IsMin a ∨ ∃ b c, a ≤ b ⊔ c ∧ ¬a ≤ b ∧ ¬a ≤ c := by
rw [SupPrime, not_and_or]; push_neg; rfl
protected theorem SupPrime.supIrred : SupPrime a → SupIrred a :=
And.imp_right fun h b c ha => by simpa [← ha] using h ha.ge
theorem SupPrime.le_sup (ha : SupPrime a) : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c :=
⟨fun h => ha.2 h, fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩
variable [OrderBot α] {s : Finset ι} {f : ι → α}
@[simp]
theorem not_supIrred_bot : ¬SupIrred (⊥ : α) :=
isMin_bot.not_supIrred
@[simp]
theorem not_supPrime_bot : ¬SupPrime (⊥ : α) :=
isMin_bot.not_supPrime
theorem SupIrred.ne_bot (ha : SupIrred a) : a ≠ ⊥ := by rintro rfl; exact not_supIrred_bot ha
theorem SupPrime.ne_bot (ha : SupPrime a) : a ≠ ⊥ := by rintro rfl; exact not_supPrime_bot ha
theorem SupIrred.finset_sup_eq (ha : SupIrred a) (h : s.sup f = a) : ∃ i ∈ s, f i = a := by
classical
induction' s using Finset.induction with i s _ ih
· simpa [ha.ne_bot] using h.symm
simp only [exists_prop, exists_mem_insert] at ih ⊢
rw [sup_insert] at h
exact (ha.2 h).imp_right ih
theorem SupPrime.le_finset_sup (ha : SupPrime a) : a ≤ s.sup f ↔ ∃ i ∈ s, a ≤ f i := by
classical
induction' s using Finset.induction with i s _ ih
· simp [ha.ne_bot]
· simp only [exists_prop, exists_mem_insert, sup_insert, ha.le_sup, ih]
variable [WellFoundedLT α]
/-- In a well-founded lattice, any element is the supremum of finitely many sup-irreducible
elements. This is the order-theoretic analogue of prime factorisation. -/
theorem exists_supIrred_decomposition (a : α) :
∃ s : Finset α, s.sup id = a ∧ ∀ ⦃b⦄, b ∈ s → SupIrred b := by
classical
apply WellFoundedLT.induction a _
clear a
rintro a ih
by_cases ha : SupIrred a
· exact ⟨{a}, by simp [ha]⟩
rw [not_supIrred] at ha
obtain ha | ⟨b, c, rfl, hb, hc⟩ := ha
· exact ⟨∅, by simp [ha.eq_bot]⟩
obtain ⟨s, rfl, hs⟩ := ih _ hb
obtain ⟨t, rfl, ht⟩ := ih _ hc
exact ⟨s ∪ t, sup_union, forall_mem_union.2 ⟨hs, ht⟩⟩
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] {a b c : α}
/-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/
def InfIrred (a : α) : Prop :=
¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c = a → b = a ∨ c = a
/-- An inf-prime element is a non-top element which isn't bigger than the infimum of anything
bigger. -/
def InfPrime (a : α) : Prop :=
¬IsMax a ∧ ∀ ⦃b c⦄, b ⊓ c ≤ a → b ≤ a ∨ c ≤ a
@[simp]
theorem IsMax.not_infIrred (ha : IsMax a) : ¬InfIrred a := fun h => h.1 ha
@[simp]
theorem IsMax.not_infPrime (ha : IsMax a) : ¬InfPrime a := fun h => h.1 ha
@[simp]
theorem not_infIrred : ¬InfIrred a ↔ IsMax a ∨ ∃ b c, b ⊓ c = a ∧ a < b ∧ a < c :=
@not_supIrred αᵒᵈ _ _
@[simp]
theorem not_infPrime : ¬InfPrime a ↔ IsMax a ∨ ∃ b c, b ⊓ c ≤ a ∧ ¬b ≤ a ∧ ¬c ≤ a :=
@not_supPrime αᵒᵈ _ _
protected theorem InfPrime.infIrred : InfPrime a → InfIrred a :=
And.imp_right fun h b c ha => by simpa [← ha] using h ha.le
theorem InfPrime.inf_le (ha : InfPrime a) : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a :=
⟨fun h => ha.2 h, fun h => h.elim inf_le_of_left_le inf_le_of_right_le⟩
variable [OrderTop α] {s : Finset ι} {f : ι → α}
theorem not_infIrred_top : ¬InfIrred (⊤ : α) :=
isMax_top.not_infIrred
theorem not_infPrime_top : ¬InfPrime (⊤ : α) :=
isMax_top.not_infPrime
theorem InfIrred.ne_top (ha : InfIrred a) : a ≠ ⊤ := by rintro rfl; exact not_infIrred_top ha
theorem InfPrime.ne_top (ha : InfPrime a) : a ≠ ⊤ := by rintro rfl; exact not_infPrime_top ha
theorem InfIrred.finset_inf_eq : InfIrred a → s.inf f = a → ∃ i ∈ s, f i = a :=
@SupIrred.finset_sup_eq _ αᵒᵈ _ _ _ _ _
theorem InfPrime.finset_inf_le (ha : InfPrime a) : s.inf f ≤ a ↔ ∃ i ∈ s, f i ≤ a :=
@SupPrime.le_finset_sup _ αᵒᵈ _ _ _ _ _ ha
variable [WellFoundedGT α]
/-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible
elements. This is the order-theoretic analogue of prime factorisation. -/
theorem exists_infIrred_decomposition (a : α) :
∃ s : Finset α, s.inf id = a ∧ ∀ ⦃b⦄, b ∈ s → InfIrred b :=
exists_supIrred_decomposition (α := αᵒᵈ) _
end SemilatticeInf
section SemilatticeSup
variable [SemilatticeSup α]
@[simp]
theorem infIrred_toDual {a : α} : InfIrred (toDual a) ↔ SupIrred a :=
Iff.rfl
@[simp]
theorem infPrime_toDual {a : α} : InfPrime (toDual a) ↔ SupPrime a :=
Iff.rfl
@[simp]
theorem supIrred_ofDual {a : αᵒᵈ} : SupIrred (ofDual a) ↔ InfIrred a :=
Iff.rfl
@[simp]
theorem supPrime_ofDual {a : αᵒᵈ} : SupPrime (ofDual a) ↔ InfPrime a :=
Iff.rfl
alias ⟨_, SupIrred.dual⟩ := infIrred_toDual
alias ⟨_, SupPrime.dual⟩ := infPrime_toDual
alias ⟨_, InfIrred.ofDual⟩ := supIrred_ofDual
alias ⟨_, InfPrime.ofDual⟩ := supPrime_ofDual
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α]
@[simp]
theorem supIrred_toDual {a : α} : SupIrred (toDual a) ↔ InfIrred a :=
Iff.rfl
@[simp]
theorem supPrime_toDual {a : α} : SupPrime (toDual a) ↔ InfPrime a :=
Iff.rfl
@[simp]
theorem infIrred_ofDual {a : αᵒᵈ} : InfIrred (ofDual a) ↔ SupIrred a :=
Iff.rfl
@[simp]
theorem infPrime_ofDual {a : αᵒᵈ} : InfPrime (ofDual a) ↔ SupPrime a :=
Iff.rfl
alias ⟨_, InfIrred.dual⟩ := supIrred_toDual
alias ⟨_, InfPrime.dual⟩ := supPrime_toDual
alias ⟨_, SupIrred.ofDual⟩ := infIrred_ofDual
alias ⟨_, SupPrime.ofDual⟩ := infPrime_ofDual
end SemilatticeInf
section DistribLattice
variable [DistribLattice α] {a : α}
@[simp]
theorem supPrime_iff_supIrred : SupPrime a ↔ SupIrred a :=
⟨SupPrime.supIrred,
And.imp_right fun h b c => by simp_rw [← inf_eq_left, inf_sup_left]; exact @h _ _⟩
@[simp]
theorem infPrime_iff_infIrred : InfPrime a ↔ InfIrred a :=
⟨InfPrime.infIrred,
And.imp_right fun h b c => by simp_rw [← sup_eq_left, sup_inf_left]; exact @h _ _⟩
protected alias ⟨_, SupIrred.supPrime⟩ := supPrime_iff_supIrred
protected alias ⟨_, InfIrred.infPrime⟩ := infPrime_iff_infIrred
end DistribLattice
section LinearOrder
variable [LinearOrder α] {a : α}
theorem supPrime_iff_not_isMin : SupPrime a ↔ ¬IsMin a :=
and_iff_left <| by simp
theorem infPrime_iff_not_isMax : InfPrime a ↔ ¬IsMax a :=
and_iff_left <| by simp
@[simp]
theorem supIrred_iff_not_isMin : SupIrred a ↔ ¬IsMin a :=
and_iff_left fun _ _ => by simpa only [max_eq_iff] using Or.imp And.left And.left
@[simp]
theorem infIrred_iff_not_isMax : InfIrred a ↔ ¬IsMax a :=
and_iff_left fun _ _ => by simpa only [min_eq_iff] using Or.imp And.left And.left
end LinearOrder
| Mathlib/Order/Irreducible.lean | 338 | 339 | |
/-
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
variable [Semifield K] {a b d : K}
theorem div_add_div (a : K) (c : K) (hb : b ≠ 0) (hd : d ≠ 0) :
a / b + c / d = (a * d + b * c) / (b * d) :=
(Commute.all b _).div_add_div (Commute.all _ _) hb hd
theorem one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) : 1 / a + 1 / b = (a + b) / (a * b) :=
(Commute.all a _).one_div_add_one_div ha hb
theorem inv_add_inv (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = (a + b) / (a * b) :=
(Commute.all a _).inv_add_inv ha hb
end Semifield
section Field
variable [Field K]
attribute [local simp] mul_assoc mul_comm mul_left_comm
@[field_simps]
theorem div_sub_div (a : K) {b : K} (c : K) {d : K} (hb : b ≠ 0) (hd : d ≠ 0) :
a / b - c / d = (a * d - b * c) / (b * d) :=
(Commute.all b _).div_sub_div (Commute.all _ _) hb hd
theorem inv_sub_inv {a b : K} (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = (b - a) / (a * b) := by
rw [inv_eq_one_div, inv_eq_one_div, div_sub_div _ _ ha hb, one_mul, mul_one]
@[field_simps]
theorem sub_div' {a b c : K} (hc : c ≠ 0) : b - a / c = (b * c - a) / c := by
simpa using div_sub_div b a one_ne_zero hc
@[field_simps]
theorem div_sub' {a b c : K} (hc : c ≠ 0) : a / c - b = (a - c * b) / c := by
simpa using div_sub_div a b hc one_ne_zero
-- see Note [lower instance priority]
instance (priority := 100) Field.isDomain : IsDomain K :=
{ DivisionRing.isDomain with }
end Field
section NoncomputableDefs
variable {R : Type*} [Nontrivial R]
/-- Constructs a `DivisionRing` structure on a `Ring` consisting only of units and 0. -/
-- See note [reducible non-instances]
noncomputable abbrev DivisionRing.ofIsUnitOrEqZero [Ring R] (h : ∀ a : R, IsUnit a ∨ a = 0) :
DivisionRing R where
toRing := ‹Ring R›
__ := groupWithZeroOfIsUnitOrEqZero h
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
/-- Constructs a `Field` structure on a `CommRing` consisting only of units and 0. -/
-- See note [reducible non-instances]
noncomputable abbrev Field.ofIsUnitOrEqZero [CommRing R] (h : ∀ a : R, IsUnit a ∨ a = 0) :
Field R where
toCommRing := ‹CommRing R›
__ := DivisionRing.ofIsUnitOrEqZero h
end NoncomputableDefs
namespace Function.Injective
variable [Zero K] [Add K] [Neg K] [Sub K] [One K] [Mul K] [Inv K] [Div K] [SMul ℕ K] [SMul ℤ K]
[SMul ℚ≥0 K] [SMul ℚ K] [Pow K ℕ] [Pow K ℤ] [NatCast K] [IntCast K] [NNRatCast K] [RatCast K]
(f : K → L) (hf : Injective f)
/-- Pullback a `DivisionSemiring` along an injective function. -/
-- See note [reducible non-instances]
protected abbrev divisionSemiring [DivisionSemiring L] (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(inv : ∀ x, f x⁻¹ = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q) : DivisionSemiring K where
toSemiring := hf.semiring f zero one add mul nsmul npow natCast
__ := hf.groupWithZero f zero one mul inv div npow zpow
nnratCast_def q := hf <| by rw [nnratCast, NNRat.cast_def, div, natCast, natCast]
nnqsmul := (· • ·)
nnqsmul_def q a := hf <| by rw [nnqsmul, NNRat.smul_def, mul, nnratCast]
/-- Pullback a `DivisionSemiring` along an injective function. -/
-- See note [reducible non-instances]
protected abbrev divisionRing [DivisionRing L] (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) (inv : ∀ x, f x⁻¹ = (f x)⁻¹)
(div : ∀ x y, f (x / y) = f x / f y)
(nsmul : ∀ (n : ℕ) (x), f (n • x) = n • f x) (zsmul : ∀ (n : ℤ) (x), f (n • x) = n • f x)
(nnqsmul : ∀ (q : ℚ≥0) (x), f (q • x) = q • f x) (qsmul : ∀ (q : ℚ) (x), f (q • x) = q • f x)
(npow : ∀ (x) (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ (x) (n : ℤ), f (x ^ n) = f x ^ n)
(natCast : ∀ n : ℕ, f n = n) (intCast : ∀ n : ℤ, f n = n) (nnratCast : ∀ q : ℚ≥0, f q = q)
(ratCast : ∀ q : ℚ, f q = q) : DivisionRing K where
| toRing := hf.ring f zero one add mul neg sub nsmul zsmul npow natCast intCast
__ := hf.groupWithZero f zero one mul inv div npow zpow
| Mathlib/Algebra/Field/Basic.lean | 236 | 237 |
/-
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.Order.ConditionallyCompleteLattice.Indexed
import Mathlib.Order.SuccPred.Limit
/-!
# Relation between `IsSuccPrelimit` and `iSup` in (conditionally) complete linear orders.
-/
open Order Set
variable {ι : Sort*} {α : Type*}
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] [Nonempty ι] {f : ι → α} {s : Set α} {x : α}
lemma csSup_mem_of_not_isSuccPrelimit
(hne : s.Nonempty) (hbdd : BddAbove s) (hlim : ¬ IsSuccPrelimit (sSup s)) : sSup s ∈ s := by
obtain ⟨y, hy⟩ := not_forall_not.mp hlim
obtain ⟨i, his, hi⟩ := exists_lt_of_lt_csSup hne hy.lt
exact eq_of_le_of_not_lt (le_csSup hbdd his) (hy.2 hi) ▸ his
lemma csInf_mem_of_not_isPredPrelimit
(hne : s.Nonempty) (hbdd : BddBelow s) (hlim : ¬ IsPredPrelimit (sInf s)) : sInf s ∈ s := by
obtain ⟨y, hy⟩ := not_forall_not.mp hlim
obtain ⟨i, his, hi⟩ := exists_lt_of_csInf_lt hne hy.lt
exact eq_of_le_of_not_lt (csInf_le hbdd his) (hy.2 · hi) ▸ his
lemma exists_eq_ciSup_of_not_isSuccPrelimit
(hf : BddAbove (range f)) (hf' : ¬ IsSuccPrelimit (⨆ i, f i)) : ∃ i, f i = ⨆ i, f i :=
csSup_mem_of_not_isSuccPrelimit (range_nonempty f) hf hf'
lemma exists_eq_ciInf_of_not_isPredPrelimit
(hf : BddBelow (range f)) (hf' : ¬ IsPredPrelimit (⨅ i, f i)) : ∃ i, f i = ⨅ i, f i :=
csInf_mem_of_not_isPredPrelimit (range_nonempty f) hf hf'
lemma IsLUB.mem_of_nonempty_of_not_isSuccPrelimit
(hs : IsLUB s x) (hne : s.Nonempty) (hx : ¬ IsSuccPrelimit x) : x ∈ s :=
hs.csSup_eq hne ▸ csSup_mem_of_not_isSuccPrelimit hne hs.bddAbove (hs.csSup_eq hne ▸ hx)
lemma IsGLB.mem_of_nonempty_of_not_isPredPrelimit
(hs : IsGLB s x) (hne : s.Nonempty) (hx : ¬ IsPredPrelimit x) : x ∈ s :=
hs.csInf_eq hne ▸ csInf_mem_of_not_isPredPrelimit hne hs.bddBelow (hs.csInf_eq hne ▸ hx)
lemma IsLUB.exists_of_nonempty_of_not_isSuccPrelimit
(hf : IsLUB (range f) x) (hx : ¬ IsSuccPrelimit x) : ∃ i, f i = x :=
hf.mem_of_nonempty_of_not_isSuccPrelimit (range_nonempty f) hx
lemma IsGLB.exists_of_nonempty_of_not_isPredPrelimit
(hf : IsGLB (range f) x) (hx : ¬ IsPredPrelimit x) : ∃ i, f i = x :=
hf.mem_of_nonempty_of_not_isPredPrelimit (range_nonempty f) hx
open Classical in
/-- Every conditionally complete linear order with well-founded `<` is a successor order, by setting
the successor of an element to be the infimum of all larger elements. -/
noncomputable def ConditionallyCompleteLinearOrder.toSuccOrder [WellFoundedLT α] :
SuccOrder α where
succ a := if IsMax a then a else sInf {b | a < b}
le_succ a := by
by_cases h : IsMax a
· simp [h]
· simp only [h, ↓reduceIte]
rw [not_isMax_iff] at h
exact le_csInf h (fun b => le_of_lt)
max_of_succ_le hs := by
by_contra h
simp [h] at hs
rw [not_isMax_iff] at h
exact hs.not_lt (csInf_mem h)
succ_le_of_lt {a b} ha := by
simp [ha.not_isMax]
exact csInf_le ⟨a, fun _ hc => hc.le⟩ ha
end ConditionallyCompleteLinearOrder
section ConditionallyCompleteLinearOrderBot
| variable [ConditionallyCompleteLinearOrderBot α] {f : ι → α} {s : Set α} {x : α}
/-- See `csSup_mem_of_not_isSuccPrelimit` for the `ConditionallyCompleteLinearOrder` version. -/
lemma csSup_mem_of_not_isSuccPrelimit'
(hbdd : BddAbove s) (hlim : ¬ IsSuccPrelimit (sSup s)) : sSup s ∈ s := by
| Mathlib/Order/SuccPred/CompleteLinearOrder.lean | 82 | 86 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent
import Mathlib.Analysis.Calculus.FDeriv.Linear
import Mathlib.Analysis.Calculus.FDeriv.Comp
/-!
# The derivative of a linear equivalence
For detailed documentation of the Fréchet derivative,
see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`.
This file contains the usual formulas (and existence assertions) for the derivative of
continuous linear equivalences.
We also prove the usual formula for the derivative of the inverse function, assuming it exists.
The inverse function theorem is in `Mathlib/Analysis/Calculus/InverseFunctionTheorem/FDeriv.lean`.
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
variable {G' : Type*} [NormedAddCommGroup G'] [NormedSpace 𝕜 G']
variable {f : E → F} {f' : E →L[𝕜] F} {x : E} {s : Set E} {c : F}
namespace ContinuousLinearEquiv
/-! ### Differentiability of linear equivs, and invariance of differentiability -/
variable (iso : E ≃L[𝕜] F)
@[fun_prop]
protected theorem hasStrictFDerivAt : HasStrictFDerivAt iso (iso : E →L[𝕜] F) x :=
iso.toContinuousLinearMap.hasStrictFDerivAt
@[fun_prop]
protected theorem hasFDerivWithinAt : HasFDerivWithinAt iso (iso : E →L[𝕜] F) s x :=
iso.toContinuousLinearMap.hasFDerivWithinAt
@[fun_prop]
protected theorem hasFDerivAt : HasFDerivAt iso (iso : E →L[𝕜] F) x :=
iso.toContinuousLinearMap.hasFDerivAtFilter
@[fun_prop]
protected theorem differentiableAt : DifferentiableAt 𝕜 iso x :=
iso.hasFDerivAt.differentiableAt
@[fun_prop]
protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 iso s x :=
iso.differentiableAt.differentiableWithinAt
protected theorem fderiv : fderiv 𝕜 iso x = iso :=
iso.hasFDerivAt.fderiv
protected theorem fderivWithin (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 iso s x = iso :=
iso.toContinuousLinearMap.fderivWithin hxs
@[fun_prop]
protected theorem differentiable : Differentiable 𝕜 iso := fun _ => iso.differentiableAt
@[fun_prop]
protected theorem differentiableOn : DifferentiableOn 𝕜 iso s :=
iso.differentiable.differentiableOn
theorem comp_differentiableWithinAt_iff {f : G → E} {s : Set G} {x : G} :
DifferentiableWithinAt 𝕜 (iso ∘ f) s x ↔ DifferentiableWithinAt 𝕜 f s x := by
refine
⟨fun H => ?_, fun H => iso.differentiable.differentiableAt.comp_differentiableWithinAt x H⟩
have : DifferentiableWithinAt 𝕜 (iso.symm ∘ iso ∘ f) s x :=
iso.symm.differentiable.differentiableAt.comp_differentiableWithinAt x H
rwa [← Function.comp_assoc iso.symm iso f, iso.symm_comp_self] at this
theorem comp_differentiableAt_iff {f : G → E} {x : G} :
DifferentiableAt 𝕜 (iso ∘ f) x ↔ DifferentiableAt 𝕜 f x := by
rw [← differentiableWithinAt_univ, ← differentiableWithinAt_univ,
iso.comp_differentiableWithinAt_iff]
theorem comp_differentiableOn_iff {f : G → E} {s : Set G} :
DifferentiableOn 𝕜 (iso ∘ f) s ↔ DifferentiableOn 𝕜 f s := by
rw [DifferentiableOn, DifferentiableOn]
simp only [iso.comp_differentiableWithinAt_iff]
theorem comp_differentiable_iff {f : G → E} : Differentiable 𝕜 (iso ∘ f) ↔ Differentiable 𝕜 f := by
rw [← differentiableOn_univ, ← differentiableOn_univ]
exact iso.comp_differentiableOn_iff
theorem comp_hasFDerivWithinAt_iff {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] E} :
HasFDerivWithinAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ HasFDerivWithinAt f f' s x := by
refine ⟨fun H => ?_, fun H => iso.hasFDerivAt.comp_hasFDerivWithinAt x H⟩
have A : f = iso.symm ∘ iso ∘ f := by
rw [← Function.comp_assoc, iso.symm_comp_self]
rfl
have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f') := by
rw [← ContinuousLinearMap.comp_assoc, iso.coe_symm_comp_coe, ContinuousLinearMap.id_comp]
rw [A, B]
exact iso.symm.hasFDerivAt.comp_hasFDerivWithinAt x H
theorem comp_hasStrictFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasStrictFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasStrictFDerivAt f f' x := by
refine ⟨fun H => ?_, fun H => iso.hasStrictFDerivAt.comp x H⟩
convert iso.symm.hasStrictFDerivAt.comp x H using 1 <;>
ext z <;> apply (iso.symm_apply_apply _).symm
theorem comp_hasFDerivAt_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} :
HasFDerivAt (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ HasFDerivAt f f' x := by
simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff]
theorem comp_hasFDerivWithinAt_iff' {f : G → E} {s : Set G} {x : G} {f' : G →L[𝕜] F} :
HasFDerivWithinAt (iso ∘ f) f' s x ↔
HasFDerivWithinAt f ((iso.symm : F →L[𝕜] E).comp f') s x := by
rw [← iso.comp_hasFDerivWithinAt_iff, ← ContinuousLinearMap.comp_assoc, iso.coe_comp_coe_symm,
ContinuousLinearMap.id_comp]
theorem comp_hasFDerivAt_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} :
HasFDerivAt (iso ∘ f) f' x ↔ HasFDerivAt f ((iso.symm : F →L[𝕜] E).comp f') x := by
simp_rw [← hasFDerivWithinAt_univ, iso.comp_hasFDerivWithinAt_iff']
theorem comp_fderivWithin {f : G → E} {s : Set G} {x : G} (hxs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderivWithin 𝕜 f s x) := by
by_cases h : DifferentiableWithinAt 𝕜 f s x
· rw [fderiv_comp_fderivWithin x iso.differentiableAt h hxs, iso.fderiv]
· have : ¬DifferentiableWithinAt 𝕜 (iso ∘ f) s x := mt iso.comp_differentiableWithinAt_iff.1 h
rw [fderivWithin_zero_of_not_differentiableWithinAt h,
fderivWithin_zero_of_not_differentiableWithinAt this, ContinuousLinearMap.comp_zero]
theorem comp_fderiv {f : G → E} {x : G} :
fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := by
rw [← fderivWithin_univ, ← fderivWithin_univ]
exact iso.comp_fderivWithin uniqueDiffWithinAt_univ
lemma _root_.fderivWithin_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G))
(hs : UniqueDiffWithinAt 𝕜 s x) :
fderivWithin 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) s x =
(((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderivWithin 𝕜 f s x) := by
change fderivWithin 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) s x = _
rw [ContinuousLinearEquiv.comp_fderivWithin _ hs]
lemma _root_.fderiv_continuousLinearEquiv_comp (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) (x : E) :
fderiv 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) x =
(((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by
change fderiv 𝕜 (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L) ∘ f) x = _
rw [ContinuousLinearEquiv.comp_fderiv]
lemma _root_.fderiv_continuousLinearEquiv_comp' (L : G ≃L[𝕜] G') (f : E → (F →L[𝕜] G)) :
fderiv 𝕜 (fun x ↦ (L : G →L[𝕜] G').comp (f x)) =
fun x ↦ (((ContinuousLinearEquiv.refl 𝕜 F).arrowCongr L)) ∘L (fderiv 𝕜 f x) := by
ext x : 1
exact fderiv_continuousLinearEquiv_comp L f x
theorem comp_right_differentiableWithinAt_iff {f : F → G} {s : Set F} {x : E} :
DifferentiableWithinAt 𝕜 (f ∘ iso) (iso ⁻¹' s) x ↔ DifferentiableWithinAt 𝕜 f s (iso x) := by
refine ⟨fun H => ?_, fun H => H.comp x iso.differentiableWithinAt (mapsTo_preimage _ s)⟩
have : DifferentiableWithinAt 𝕜 ((f ∘ iso) ∘ iso.symm) s (iso x) := by
rw [← iso.symm_apply_apply x] at H
apply H.comp (iso x) iso.symm.differentiableWithinAt
intro y hy
simpa only [mem_preimage, apply_symm_apply] using hy
rwa [Function.comp_assoc, iso.self_comp_symm] at this
theorem comp_right_differentiableAt_iff {f : F → G} {x : E} :
| DifferentiableAt 𝕜 (f ∘ iso) x ↔ DifferentiableAt 𝕜 f (iso x) := by
simp only [← differentiableWithinAt_univ, ← iso.comp_right_differentiableWithinAt_iff,
preimage_univ]
theorem comp_right_differentiableOn_iff {f : F → G} {s : Set F} :
DifferentiableOn 𝕜 (f ∘ iso) (iso ⁻¹' s) ↔ DifferentiableOn 𝕜 f s := by
| Mathlib/Analysis/Calculus/FDeriv/Equiv.lean | 172 | 177 |
/-
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.Homotopy
import Mathlib.Algebra.Ring.NegOnePow
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Tactic.Linarith
import Mathlib.CategoryTheory.Linear.LinearFunctor
/-! The cochain complex of homomorphisms between cochain complexes
If `F` and `G` are cochain complexes (indexed by `ℤ`) in a preadditive category,
there is a cochain complex of abelian groups whose `0`-cocycles identify to
morphisms `F ⟶ G`. Informally, in degree `n`, this complex shall consist of
cochains of degree `n` from `F` to `G`, i.e. arbitrary families for morphisms
`F.X p ⟶ G.X (p + n)`. This complex shall be denoted `HomComplex F G`.
In order to avoid type theoretic issues, a cochain of degree `n : ℤ`
(i.e. a term of type of `Cochain F G n`) shall be defined here
as the data of a morphism `F.X p ⟶ G.X q` for all triplets
`⟨p, q, hpq⟩` where `p` and `q` are integers and `hpq : p + n = q`.
If `α : Cochain F G n`, we shall define `α.v p q hpq : F.X p ⟶ G.X q`.
We follow the signs conventions appearing in the introduction of
[Brian Conrad's book *Grothendieck duality and base change*][conrad2000].
## References
* [Brian Conrad, Grothendieck duality and base change][conrad2000]
-/
assert_not_exists TwoSidedIdeal
open CategoryTheory Category Limits Preadditive
universe v u
variable {C : Type u} [Category.{v} C] [Preadditive C] {R : Type*} [Ring R] [Linear R C]
namespace CochainComplex
variable {F G K L : CochainComplex C ℤ} (n m : ℤ)
namespace HomComplex
/-- A term of type `HomComplex.Triplet n` consists of two integers `p` and `q`
such that `p + n = q`. (This type is introduced so that the instance
`AddCommGroup (Cochain F G n)` defined below can be found automatically.) -/
structure Triplet (n : ℤ) where
/-- a first integer -/
p : ℤ
/-- a second integer -/
q : ℤ
/-- the condition on the two integers -/
hpq : p + n = q
variable (F G)
/-- A cochain of degree `n : ℤ` between to cochain complexes `F` and `G` consists
of a family of morphisms `F.X p ⟶ G.X q` whenever `p + n = q`, i.e. for all
triplets in `HomComplex.Triplet n`. -/
def Cochain := ∀ (T : Triplet n), F.X T.p ⟶ G.X T.q
instance : AddCommGroup (Cochain F G n) := by
dsimp only [Cochain]
infer_instance
instance : Module R (Cochain F G n) := by
dsimp only [Cochain]
infer_instance
namespace Cochain
variable {F G n}
/-- A practical constructor for cochains. -/
def mk (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) : Cochain F G n :=
fun ⟨p, q, hpq⟩ => v p q hpq
/-- The value of a cochain on a triplet `⟨p, q, hpq⟩`. -/
def v (γ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
F.X p ⟶ G.X q := γ ⟨p, q, hpq⟩
@[simp]
lemma mk_v (v : ∀ (p q : ℤ) (_ : p + n = q), F.X p ⟶ G.X q) (p q : ℤ) (hpq : p + n = q) :
(Cochain.mk v).v p q hpq = v p q hpq := rfl
lemma congr_v {z₁ z₂ : Cochain F G n} (h : z₁ = z₂) (p q : ℤ) (hpq : p + n = q) :
z₁.v p q hpq = z₂.v p q hpq := by subst h; rfl
@[ext]
lemma ext (z₁ z₂ : Cochain F G n)
(h : ∀ (p q hpq), z₁.v p q hpq = z₂.v p q hpq) : z₁ = z₂ := by
funext ⟨p, q, hpq⟩
apply h
@[ext 1100]
lemma ext₀ (z₁ z₂ : Cochain F G 0)
(h : ∀ (p : ℤ), z₁.v p p (add_zero p) = z₂.v p p (add_zero p)) : z₁ = z₂ := by
ext p q hpq
obtain rfl : q = p := by rw [← hpq, add_zero]
exact h q
@[simp]
lemma zero_v {n : ℤ} (p q : ℤ) (hpq : p + n = q) :
(0 : Cochain F G n).v p q hpq = 0 := rfl
@[simp]
lemma add_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(z₁ + z₂).v p q hpq = z₁.v p q hpq + z₂.v p q hpq := rfl
@[simp]
lemma sub_v {n : ℤ} (z₁ z₂ : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(z₁ - z₂).v p q hpq = z₁.v p q hpq - z₂.v p q hpq := rfl
@[simp]
lemma neg_v {n : ℤ} (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(-z).v p q hpq = - (z.v p q hpq) := rfl
@[simp]
lemma smul_v {n : ℤ} (k : R) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(k • z).v p q hpq = k • (z.v p q hpq) := rfl
@[simp]
lemma units_smul_v {n : ℤ} (k : Rˣ) (z : Cochain F G n) (p q : ℤ) (hpq : p + n = q) :
(k • z).v p q hpq = k • (z.v p q hpq) := rfl
/-- A cochain of degree `0` from `F` to `G` can be constructed from a family
of morphisms `F.X p ⟶ G.X p` for all `p : ℤ`. -/
def ofHoms (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) : Cochain F G 0 :=
Cochain.mk (fun p q hpq => ψ p ≫ eqToHom (by rw [← hpq, add_zero]))
@[simp]
lemma ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p : ℤ) :
(ofHoms ψ).v p p (add_zero p) = ψ p := by
simp only [ofHoms, mk_v, eqToHom_refl, comp_id]
@[simp]
lemma ofHoms_zero : ofHoms (fun p => (0 : F.X p ⟶ G.X p)) = 0 := by aesop_cat
@[simp]
lemma ofHoms_v_comp_d (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p q q' : ℤ) (hpq : p + 0 = q) :
(ofHoms ψ).v p q hpq ≫ G.d q q' = ψ p ≫ G.d p q' := by
rw [add_zero] at hpq
subst hpq
rw [ofHoms_v]
@[simp]
lemma d_comp_ofHoms_v (ψ : ∀ (p : ℤ), F.X p ⟶ G.X p) (p' p q : ℤ) (hpq : p + 0 = q) :
F.d p' p ≫ (ofHoms ψ).v p q hpq = F.d p' q ≫ ψ q := by
rw [add_zero] at hpq
subst hpq
rw [ofHoms_v]
/-- The `0`-cochain attached to a morphism of cochain complexes. -/
def ofHom (φ : F ⟶ G) : Cochain F G 0 := ofHoms (fun p => φ.f p)
variable (F G)
@[simp]
lemma ofHom_zero : ofHom (0 : F ⟶ G) = 0 := by
simp only [ofHom, HomologicalComplex.zero_f_apply, ofHoms_zero]
variable {F G}
@[simp]
lemma ofHom_v (φ : F ⟶ G) (p : ℤ) : (ofHom φ).v p p (add_zero p) = φ.f p := by
simp only [ofHom, ofHoms_v]
@[simp]
lemma ofHom_v_comp_d (φ : F ⟶ G) (p q q' : ℤ) (hpq : p + 0 = q) :
(ofHom φ).v p q hpq ≫ G.d q q' = φ.f p ≫ G.d p q' := by
simp only [ofHom, ofHoms_v_comp_d]
@[simp]
lemma d_comp_ofHom_v (φ : F ⟶ G) (p' p q : ℤ) (hpq : p + 0 = q) :
F.d p' p ≫ (ofHom φ).v p q hpq = F.d p' q ≫ φ.f q := by
simp only [ofHom, d_comp_ofHoms_v]
@[simp]
lemma ofHom_add (φ₁ φ₂ : F ⟶ G) :
Cochain.ofHom (φ₁ + φ₂) = Cochain.ofHom φ₁ + Cochain.ofHom φ₂ := by aesop_cat
@[simp]
lemma ofHom_sub (φ₁ φ₂ : F ⟶ G) :
Cochain.ofHom (φ₁ - φ₂) = Cochain.ofHom φ₁ - Cochain.ofHom φ₂ := by aesop_cat
@[simp]
lemma ofHom_neg (φ : F ⟶ G) :
Cochain.ofHom (-φ) = -Cochain.ofHom φ := by aesop_cat
/-- The cochain of degree `-1` given by an homotopy between two morphism of complexes. -/
def ofHomotopy {φ₁ φ₂ : F ⟶ G} (ho : Homotopy φ₁ φ₂) : Cochain F G (-1) :=
Cochain.mk (fun p q _ => ho.hom p q)
@[simp]
lemma ofHomotopy_ofEq {φ₁ φ₂ : F ⟶ G} (h : φ₁ = φ₂) :
ofHomotopy (Homotopy.ofEq h) = 0 := rfl
@[simp]
lemma ofHomotopy_refl (φ : F ⟶ G) :
ofHomotopy (Homotopy.refl φ) = 0 := rfl
@[reassoc]
lemma v_comp_XIsoOfEq_hom
(γ : Cochain F G n) (p q q' : ℤ) (hpq : p + n = q) (hq' : q = q') :
γ.v p q hpq ≫ (HomologicalComplex.XIsoOfEq G hq').hom = γ.v p q' (by rw [← hq', hpq]) := by
subst hq'
| simp only [HomologicalComplex.XIsoOfEq, eqToIso_refl, Iso.refl_hom, comp_id]
@[reassoc]
lemma v_comp_XIsoOfEq_inv
(γ : Cochain F G n) (p q q' : ℤ) (hpq : p + n = q) (hq' : q' = q) :
γ.v p q hpq ≫ (HomologicalComplex.XIsoOfEq G hq').inv = γ.v p q' (by rw [hq', hpq]) := by
| Mathlib/Algebra/Homology/HomotopyCategory/HomComplex.lean | 211 | 216 |
/-
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.PartrecCode
import Mathlib.Data.Set.Subsingleton
/-!
# Computability theory and the halting problem
A universal partial recursive function, Rice's theorem, and the halting problem.
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open List (Vector)
open Encodable Denumerable
namespace Nat.Partrec
open Computable Part
theorem merge' {f g} (hf : Nat.Partrec f) (hg : Nat.Partrec g) :
∃ h, Nat.Partrec h ∧
∀ a, (∀ x ∈ h a, x ∈ f a ∨ x ∈ g a) ∧ ((h a).Dom ↔ (f a).Dom ∨ (g a).Dom) := by
obtain ⟨cf, rfl⟩ := Code.exists_code.1 hf
obtain ⟨cg, rfl⟩ := Code.exists_code.1 hg
have : Nat.Partrec fun n => Nat.rfindOpt fun k => cf.evaln k n <|> cg.evaln k n :=
Partrec.nat_iff.1
(Partrec.rfindOpt <|
Primrec.option_orElse.to_comp.comp
(Code.evaln_prim.to_comp.comp <| (snd.pair (const cf)).pair fst)
(Code.evaln_prim.to_comp.comp <| (snd.pair (const cg)).pair fst))
refine ⟨_, this, fun n => ?_⟩
have : ∀ x ∈ rfindOpt fun k ↦ HOrElse.hOrElse (Code.evaln k cf n) fun _x ↦ Code.evaln k cg n,
x ∈ Code.eval cf n ∨ x ∈ Code.eval cg n := by
intro x h
obtain ⟨k, e⟩ := Nat.rfindOpt_spec h
revert e
simp only [Option.mem_def]
rcases e' : cf.evaln k n with - | y <;> simp <;> intro e
· exact Or.inr (Code.evaln_sound e)
· subst y
exact Or.inl (Code.evaln_sound e')
refine ⟨this, ⟨fun h => (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, ?_⟩⟩
intro h
rw [Nat.rfindOpt_dom]
simp only [dom_iff_mem, Code.evaln_complete, Option.mem_def] at h
obtain ⟨x, k, e⟩ | ⟨x, k, e⟩ := h
· refine ⟨k, x, ?_⟩
simp only [e, Option.some_orElse, Option.mem_def]
· refine ⟨k, ?_⟩
rcases cf.evaln k n with - | y
· exact ⟨x, by simp only [e, Option.mem_def, Option.none_orElse]⟩
· exact ⟨y, by simp only [Option.some_orElse, Option.mem_def]⟩
end Nat.Partrec
namespace Partrec
variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*}
variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ]
open Computable Part
open Nat.Partrec (Code)
open Nat.Partrec.Code
theorem merge' {f g : α →. σ} (hf : Partrec f) (hg : Partrec g) :
∃ k : α →. σ,
Partrec k ∧ ∀ a, (∀ x ∈ k a, x ∈ f a ∨ x ∈ g a) ∧ ((k a).Dom ↔ (f a).Dom ∨ (g a).Dom) := by
let ⟨k, hk, H⟩ := Nat.Partrec.merge' (bind_decode₂_iff.1 hf) (bind_decode₂_iff.1 hg)
let k' (a : α) := (k (encode a)).bind fun n => (decode (α := σ) n : Part σ)
refine
⟨k', ((nat_iff.2 hk).comp Computable.encode).bind (Computable.decode.ofOption.comp snd).to₂,
fun a => ?_⟩
have : ∀ x ∈ k' a, x ∈ f a ∨ x ∈ g a := by
intro x h'
simp only [k', exists_prop, mem_coe, mem_bind_iff, Option.mem_def] at h'
obtain ⟨n, hn, hx⟩ := h'
have := (H _).1 _ hn
simp only [decode₂_encode, coe_some, bind_some, mem_map_iff] at this
obtain ⟨a', ha, rfl⟩ | ⟨a', ha, rfl⟩ := this <;> simp only [encodek, Option.some_inj] at hx <;>
rw [hx] at ha
· exact Or.inl ha
· exact Or.inr ha
refine ⟨this, ⟨fun h => (this _ ⟨h, rfl⟩).imp Exists.fst Exists.fst, ?_⟩⟩
intro h
rw [bind_dom]
have hk : (k (encode a)).Dom :=
(H _).2.2 (by simpa only [encodek₂, bind_some, coe_some] using h)
exists hk
simp only [exists_prop, mem_map_iff, mem_coe, mem_bind_iff, Option.mem_def] at H
obtain ⟨a', _, y, _, e⟩ | ⟨a', _, y, _, e⟩ := (H _).1 _ ⟨hk, rfl⟩ <;>
simp only [e.symm, encodek, coe_some, some_dom]
theorem merge {f g : α →. σ} (hf : Partrec f) (hg : Partrec g)
(H : ∀ (a), ∀ x ∈ f a, ∀ y ∈ g a, x = y) :
∃ k : α →. σ, Partrec k ∧ ∀ a x, x ∈ k a ↔ x ∈ f a ∨ x ∈ g a :=
let ⟨k, hk, K⟩ := merge' hf hg
⟨k, hk, fun a x =>
⟨(K _).1 _, fun h => by
have : (k a).Dom := (K _).2.2 (h.imp Exists.fst Exists.fst)
refine ⟨this, ?_⟩
rcases h with h | h <;> rcases (K _).1 _ ⟨this, rfl⟩ with h' | h'
· exact mem_unique h' h
· exact (H _ _ h _ h').symm
· exact H _ _ h' _ h
· exact mem_unique h' h⟩⟩
theorem cond {c : α → Bool} {f : α →. σ} {g : α →. σ} (hc : Computable c) (hf : Partrec f)
(hg : Partrec g) : Partrec fun a => cond (c a) (f a) (g a) :=
let ⟨cf, ef⟩ := exists_code.1 hf
let ⟨cg, eg⟩ := exists_code.1 hg
((eval_part.comp (Computable.cond hc (const cf) (const cg)) Computable.encode).bind
((@Computable.decode σ _).comp snd).ofOption.to₂).of_eq
fun a => by cases c a <;> simp [ef, eg, encodek]
nonrec theorem sumCasesOn {f : α → β ⊕ γ} {g : α → β →. σ} {h : α → γ →. σ} (hf : Computable f)
(hg : Partrec₂ g) (hh : Partrec₂ h) : @Partrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) :=
option_some_iff.1 <|
(cond (sumCasesOn hf (const true).to₂ (const false).to₂)
(sumCasesOn_left hf (option_some_iff.2 hg).to₂ (const Option.none).to₂)
(sumCasesOn_right hf (const Option.none).to₂ (option_some_iff.2 hh).to₂)).of_eq
fun a => by cases f a <;> simp only [Bool.cond_true, Bool.cond_false]
@[deprecated (since := "2025-02-21")] alias sum_casesOn := Partrec.sumCasesOn
end Partrec
/-- A computable predicate is one whose indicator function is computable. -/
def ComputablePred {α} [Primcodable α] (p : α → Prop) :=
∃ _ : DecidablePred p, Computable fun a => decide (p a)
/-- A recursively enumerable predicate is one which is the domain of a computable partial function.
-/
def REPred {α} [Primcodable α] (p : α → Prop) :=
Partrec fun a => Part.assert (p a) fun _ => Part.some ()
@[deprecated (since := "2025-02-06")] alias RePred := REPred
@[deprecated (since := "2025-02-06")] alias RePred.of_eq := RePred
theorem REPred.of_eq {α} [Primcodable α] {p q : α → Prop} (hp : REPred p) (H : ∀ a, p a ↔ q a) :
REPred q :=
(funext fun a => propext (H a) : p = q) ▸ hp
theorem Partrec.dom_re {α β} [Primcodable α] [Primcodable β] {f : α →. β} (h : Partrec f) :
REPred fun a => (f a).Dom :=
(h.map (Computable.const ()).to₂).of_eq fun n => Part.ext fun _ => by simp [Part.dom_iff_mem]
theorem ComputablePred.of_eq {α} [Primcodable α] {p q : α → Prop} (hp : ComputablePred p)
(H : ∀ a, p a ↔ q a) : ComputablePred q :=
(funext fun a => propext (H a) : p = q) ▸ hp
namespace ComputablePred
variable {α : Type*} [Primcodable α]
open Nat.Partrec (Code)
open Nat.Partrec.Code Computable
theorem computable_iff {p : α → Prop} :
ComputablePred p ↔ ∃ f : α → Bool, Computable f ∧ p = fun a => (f a : Prop) :=
⟨fun ⟨_, h⟩ => ⟨_, h, funext fun _ => propext (Bool.decide_iff _).symm⟩, by
rintro ⟨f, h, rfl⟩; exact ⟨by infer_instance, by simpa using h⟩⟩
protected theorem not {p : α → Prop} (hp : ComputablePred p) : ComputablePred fun a => ¬p a := by
obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp
exact
⟨by infer_instance,
(cond hf (const false) (const true)).of_eq fun n => by
simp only [Bool.not_eq_true]
cases f n <;> rfl⟩
/-- The computable functions are closed under if-then-else definitions
with computable predicates. -/
theorem ite {f₁ f₂ : ℕ → ℕ} (hf₁ : Computable f₁) (hf₂ : Computable f₂)
{c : ℕ → Prop} [DecidablePred c] (hc : ComputablePred c) :
Computable fun k ↦ if c k then f₁ k else f₂ k := by
simp_rw [← Bool.cond_decide]
obtain ⟨inst, hc⟩ := hc
convert hc.cond hf₁ hf₂
theorem to_re {p : α → Prop} (hp : ComputablePred p) : REPred p := by
obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp
unfold REPred
dsimp only []
refine
(Partrec.cond hf (Decidable.Partrec.const' (Part.some ())) Partrec.none).of_eq fun n =>
Part.ext fun a => ?_
cases a; cases f n <;> simp
/-- **Rice's Theorem** -/
theorem rice (C : Set (ℕ →. ℕ)) (h : ComputablePred fun c => eval c ∈ C) {f g} (hf : Nat.Partrec f)
(hg : Nat.Partrec g) (fC : f ∈ C) : g ∈ C := by
obtain ⟨_, h⟩ := h
obtain ⟨c, e⟩ :=
fixed_point₂
(Partrec.cond (h.comp fst) ((Partrec.nat_iff.2 hg).comp snd).to₂
((Partrec.nat_iff.2 hf).comp snd).to₂).to₂
simp only [Bool.cond_decide] at e
by_cases H : eval c ∈ C
· simp only [H, if_true] at e
change (fun b => g b) ∈ C
rwa [← e]
· simp only [H, if_false] at e
rw [e] at H
contradiction
theorem rice₂ (C : Set Code) (H : ∀ cf cg, eval cf = eval cg → (cf ∈ C ↔ cg ∈ C)) :
(ComputablePred fun c => c ∈ C) ↔ C = ∅ ∨ C = Set.univ := by
classical exact
have hC : ∀ f, f ∈ C ↔ eval f ∈ eval '' C := fun f =>
⟨Set.mem_image_of_mem _, fun ⟨g, hg, e⟩ => (H _ _ e).1 hg⟩
⟨fun h =>
or_iff_not_imp_left.2 fun C0 =>
Set.eq_univ_of_forall fun cg =>
let ⟨cf, fC⟩ := Set.nonempty_iff_ne_empty.2 C0
(hC _).2 <|
rice (eval '' C) (h.of_eq hC)
(Partrec.nat_iff.1 <| eval_part.comp (const cf) Computable.id)
(Partrec.nat_iff.1 <| eval_part.comp (const cg) Computable.id) ((hC _).1 fC),
fun h => by {
obtain rfl | rfl := h <;> simpa [ComputablePred, Set.mem_empty_iff_false] using
Computable.const _}⟩
/-- The Halting problem is recursively enumerable -/
theorem halting_problem_re (n) : REPred fun c => (eval c n).Dom :=
(eval_part.comp Computable.id (Computable.const _)).dom_re
/-- The **Halting problem** is not computable -/
theorem halting_problem (n) : ¬ComputablePred fun c => (eval c n).Dom
| h => rice { f | (f n).Dom } h Nat.Partrec.zero Nat.Partrec.none trivial
-- Post's theorem on the equivalence of r.e., co-r.e. sets and
-- computable sets. The assumption that p is decidable is required
-- unless we assume Markov's principle or LEM.
-- @[nolint decidable_classical]
theorem computable_iff_re_compl_re {p : α → Prop} [DecidablePred p] :
ComputablePred p ↔ REPred p ∧ REPred fun a => ¬p a :=
⟨fun h => ⟨h.to_re, h.not.to_re⟩, fun ⟨h₁, h₂⟩ =>
⟨‹_›, by
obtain ⟨k, pk, hk⟩ :=
Partrec.merge (h₁.map (Computable.const true).to₂) (h₂.map (Computable.const false).to₂)
(by
intro a x hx y hy
simp only [Part.mem_map_iff, Part.mem_assert_iff, Part.mem_some_iff, exists_prop,
and_true, exists_const] at hx hy
cases hy.1 hx.1)
refine Partrec.of_eq pk fun n => Part.eq_some_iff.2 ?_
rw [hk]
simp only [Part.mem_map_iff, Part.mem_assert_iff, Part.mem_some_iff, exists_prop, and_true,
true_eq_decide_iff, and_self, exists_const, false_eq_decide_iff]
apply Decidable.em⟩⟩
theorem computable_iff_re_compl_re' {p : α → Prop} :
ComputablePred p ↔ REPred p ∧ REPred fun a => ¬p a := by
classical exact computable_iff_re_compl_re
theorem halting_problem_not_re (n) : ¬REPred fun c => ¬(eval c n).Dom
| h => halting_problem _ <| computable_iff_re_compl_re'.2 ⟨halting_problem_re _, h⟩
end ComputablePred
namespace Nat
open Vector Part
/-- A simplified basis for `Partrec`. -/
inductive Partrec' : ∀ {n}, (List.Vector ℕ n →. ℕ) → Prop
| prim {n f} : @Primrec' n f → @Partrec' n f
| comp {m n f} (g : Fin n → List.Vector ℕ m →. ℕ) :
Partrec' f → (∀ i, Partrec' (g i)) →
Partrec' fun v => (List.Vector.mOfFn fun i => g i v) >>= f
| rfind {n} {f : List.Vector ℕ (n + 1) → ℕ} :
@Partrec' (n + 1) f → Partrec' fun v => rfind fun n => some (f (n ::ᵥ v) = 0)
end Nat
namespace Nat.Partrec'
open List.Vector Partrec Computable
open Nat.Partrec'
theorem to_part {n f} (pf : @Partrec' n f) : _root_.Partrec f := by
induction pf with
| prim hf => exact hf.to_prim.to_comp
| comp _ _ _ hf hg => exact (Partrec.vector_mOfFn hg).bind (hf.comp snd)
| rfind _ hf =>
have := hf.comp (vector_cons.comp snd fst)
have :=
((Primrec.eq.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp
this).to₂.partrec₂
exact _root_.Partrec.rfind this
theorem of_eq {n} {f g : List.Vector ℕ n →. ℕ} (hf : Partrec' f) (H : ∀ i, f i = g i) :
Partrec' g :=
(funext H : f = g) ▸ hf
theorem of_prim {n} {f : List.Vector ℕ n → ℕ} (hf : Primrec f) : @Partrec' n f :=
prim (Nat.Primrec'.of_prim hf)
theorem head {n : ℕ} : @Partrec' n.succ (@head ℕ n) :=
prim Nat.Primrec'.head
theorem tail {n f} (hf : @Partrec' n f) : @Partrec' n.succ fun v => f v.tail :=
(hf.comp _ fun i => @prim _ _ <| Nat.Primrec'.get i.succ).of_eq fun v => by
simp; rw [← ofFn_get v.tail]; congr; funext i; simp
protected theorem bind {n f g} (hf : @Partrec' n f) (hg : @Partrec' (n + 1) g) :
@Partrec' n fun v => (f v).bind fun a => g (a ::ᵥ v) :=
(@comp n (n + 1) g (fun i => Fin.cases f (fun i v => some (v.get i)) i) hg fun i => by
refine Fin.cases ?_ (fun i => ?_) i <;> simp [*]
exact prim (Nat.Primrec'.get _)).of_eq
fun v => by simp [mOfFn, Part.bind_assoc, pure]
protected theorem map {n f} {g : List.Vector ℕ (n + 1) → ℕ} (hf : @Partrec' n f)
(hg : @Partrec' (n + 1) g) : @Partrec' n fun v => (f v).map fun a => g (a ::ᵥ v) := by
simpa [(Part.bind_some_eq_map _ _).symm] using hf.bind hg
/-- Analogous to `Nat.Partrec'` for `ℕ`-valued functions, a predicate for partial recursive
vector-valued functions. -/
def Vec {n m} (f : List.Vector ℕ n → List.Vector ℕ m) :=
∀ i, Partrec' fun v => (f v).get i
nonrec theorem Vec.prim {n m f} (hf : @Nat.Primrec'.Vec n m f) : Vec f := fun i => prim <| hf i
protected theorem nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0
protected theorem cons {n m} {f : List.Vector ℕ n → ℕ} {g} (hf : @Partrec' n f)
(hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i =>
Fin.cases (by simpa using hf) (fun i => by simp only [hg i, get_cons_succ]) i
theorem idv {n} : @Vec n n id :=
Vec.prim Nat.Primrec'.idv
theorem comp' {n m f g} (hf : @Partrec' m f) (hg : @Vec n m g) : Partrec' fun v => f (g v) :=
(hf.comp _ hg).of_eq fun v => by simp
theorem comp₁ {n} (f : ℕ →. ℕ) {g : List.Vector ℕ n → ℕ} (hf : @Partrec' 1 fun v => f v.head)
(hg : @Partrec' n g) : @Partrec' n fun v => f (g v) := by
simpa using hf.comp' (Partrec'.cons hg Partrec'.nil)
theorem rfindOpt {n} {f : List.Vector ℕ (n + 1) → ℕ} (hf : @Partrec' (n + 1) f) :
@Partrec' n fun v => Nat.rfindOpt fun a => ofNat (Option ℕ) (f (a ::ᵥ v)) :=
((rfind <|
(of_prim (Primrec.nat_sub.comp (_root_.Primrec.const 1) Primrec.vector_head)).comp₁
(fun n => Part.some (1 - n)) hf).bind
((prim Nat.Primrec'.pred).comp₁ Nat.pred hf)).of_eq
fun v =>
Part.ext fun b => by
simp only [Nat.rfindOpt, exists_prop, Nat.sub_eq_zero_iff_le, PFun.coe_val, Part.mem_bind_iff,
Part.mem_some_iff, Option.mem_def, Part.mem_coe]
refine
exists_congr fun a => (and_congr (iff_of_eq ?_) Iff.rfl).trans (and_congr_right fun h => ?_)
· congr
funext n
cases f (n ::ᵥ v) <;> simp [Nat.succ_le_succ] <;> rfl
· have := Nat.rfind_spec h
simp only [Part.coe_some, Part.mem_some_iff] at this
revert this; rcases f (a ::ᵥ v) with - | c <;> intro this
· cases this
| rw [← Option.some_inj, eq_comm]
rfl
| Mathlib/Computability/Halting.lean | 370 | 372 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Ring.Prod
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Canonical
import Mathlib.Order.Interval.Basic
import Mathlib.Tactic.Positivity.Core
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Interval arithmetic
This file defines arithmetic operations on intervals and prove their correctness. Note that this is
full precision operations. The essentials of float operations can be found
in `Data.FP.Basic`. We have not yet integrated these with the rest of the library.
-/
open Function Set
open scoped Pointwise
universe u
variable {ι α : Type*}
/-! ### One/zero -/
section One
section Preorder
variable [Preorder α] [One α]
@[to_additive]
instance : One (NonemptyInterval α) :=
⟨NonemptyInterval.pure 1⟩
namespace NonemptyInterval
@[to_additive (attr := simp) toProd_zero]
theorem toProd_one : (1 : NonemptyInterval α).toProd = 1 :=
rfl
@[to_additive]
theorem fst_one : (1 : NonemptyInterval α).fst = 1 :=
rfl
@[to_additive]
theorem snd_one : (1 : NonemptyInterval α).snd = 1 :=
rfl
@[to_additive (attr := push_cast, simp)]
theorem coe_one_interval : ((1 : NonemptyInterval α) : Interval α) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem pure_one : pure (1 : α) = 1 :=
rfl
end NonemptyInterval
namespace Interval
@[to_additive (attr := simp)]
theorem pure_one : pure (1 : α) = 1 :=
rfl
@[to_additive] lemma one_ne_bot : (1 : Interval α) ≠ ⊥ := pure_ne_bot
@[to_additive] lemma bot_ne_one : (⊥ : Interval α) ≠ 1 := bot_ne_pure
end Interval
end Preorder
section PartialOrder
variable [PartialOrder α] [One α]
namespace NonemptyInterval
@[to_additive (attr := simp)]
theorem coe_one : ((1 : NonemptyInterval α) : Set α) = 1 :=
coe_pure _
@[to_additive]
theorem one_mem_one : (1 : α) ∈ (1 : NonemptyInterval α) :=
⟨le_rfl, le_rfl⟩
end NonemptyInterval
namespace Interval
@[to_additive (attr := simp)]
theorem coe_one : ((1 : Interval α) : Set α) = 1 :=
Icc_self _
@[to_additive]
theorem one_mem_one : (1 : α) ∈ (1 : Interval α) :=
⟨le_rfl, le_rfl⟩
end Interval
end PartialOrder
end One
/-!
### Addition/multiplication
Note that this multiplication does not apply to `ℚ` or `ℝ`.
-/
section Mul
variable [Preorder α] [Mul α] [MulLeftMono α] [MulRightMono α]
@[to_additive]
instance : Mul (NonemptyInterval α) :=
⟨fun s t => ⟨s.toProd * t.toProd, mul_le_mul' s.fst_le_snd t.fst_le_snd⟩⟩
@[to_additive]
instance : Mul (Interval α) :=
⟨Option.map₂ (· * ·)⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a b : α)
@[to_additive (attr := simp) toProd_add]
theorem toProd_mul : (s * t).toProd = s.toProd * t.toProd :=
rfl
@[to_additive]
theorem fst_mul : (s * t).fst = s.fst * t.fst :=
rfl
@[to_additive]
theorem snd_mul : (s * t).snd = s.snd * t.snd :=
rfl
@[to_additive (attr := simp)]
theorem coe_mul_interval : (↑(s * t) : Interval α) = s * t :=
rfl
@[to_additive (attr := simp)]
theorem pure_mul_pure : pure a * pure b = pure (a * b) :=
rfl
end NonemptyInterval
namespace Interval
variable (s t : Interval α)
@[to_additive (attr := simp)]
theorem bot_mul : ⊥ * t = ⊥ :=
rfl
@[to_additive]
theorem mul_bot : s * ⊥ = ⊥ :=
Option.map₂_none_right _ _
-- simp can already prove `add_bot`
attribute [simp] mul_bot
end Interval
end Mul
/-! ### Powers -/
-- TODO: if `to_additive` gets improved sufficiently, derive this from `hasPow`
instance NonemptyInterval.hasNSMul [AddMonoid α] [Preorder α] [AddLeftMono α]
[AddRightMono α] : SMul ℕ (NonemptyInterval α) :=
⟨fun n s => ⟨(n • s.fst, n • s.snd), nsmul_le_nsmul_right s.fst_le_snd _⟩⟩
section Pow
variable [Monoid α] [Preorder α]
@[to_additive existing]
instance NonemptyInterval.hasPow [MulLeftMono α] [MulRightMono α] :
Pow (NonemptyInterval α) ℕ :=
⟨fun s n => ⟨s.toProd ^ n, pow_le_pow_left' s.fst_le_snd _⟩⟩
namespace NonemptyInterval
variable [MulLeftMono α] [MulRightMono α]
variable (s : NonemptyInterval α) (a : α) (n : ℕ)
@[to_additive (attr := simp) toProd_nsmul]
theorem toProd_pow : (s ^ n).toProd = s.toProd ^ n :=
rfl
@[to_additive]
theorem fst_pow : (s ^ n).fst = s.fst ^ n :=
rfl
@[to_additive]
theorem snd_pow : (s ^ n).snd = s.snd ^ n :=
rfl
@[to_additive (attr := simp)]
theorem pure_pow : pure a ^ n = pure (a ^ n) :=
rfl
end NonemptyInterval
end Pow
namespace NonemptyInterval
@[to_additive]
instance commMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
CommMonoid (NonemptyInterval α) :=
NonemptyInterval.toProd_injective.commMonoid _ toProd_one toProd_mul toProd_pow
end NonemptyInterval
@[to_additive]
instance Interval.mulOneClass [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
MulOneClass (Interval α) where
mul := (· * ·)
one := 1
one_mul s :=
(Option.map₂_coe_left _ _ _).trans <| by
simp_rw [one_mul, ← Function.id_def, Option.map_id, id]
mul_one s :=
(Option.map₂_coe_right _ _ _).trans <| by
simp_rw [mul_one, ← Function.id_def, Option.map_id, id]
@[to_additive]
instance Interval.commMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
CommMonoid (Interval α) :=
{ Interval.mulOneClass with
mul_comm := fun _ _ => Option.map₂_comm mul_comm
mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc }
namespace NonemptyInterval
@[to_additive]
theorem coe_pow_interval [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
(s : NonemptyInterval α) (n : ℕ) :
↑(s ^ n) = (s : Interval α) ^ n :=
map_pow (⟨⟨(↑), coe_one_interval⟩, coe_mul_interval⟩ : NonemptyInterval α →* Interval α) _ _
-- simp can already prove `coe_nsmul_interval`
attribute [simp] coe_pow_interval
end NonemptyInterval
namespace Interval
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] (s : Interval α) {n : ℕ}
@[to_additive]
theorem bot_pow : ∀ {n : ℕ}, n ≠ 0 → (⊥ : Interval α) ^ n = ⊥
| 0, h => (h rfl).elim
| Nat.succ n, _ => mul_bot (⊥ ^ n)
end Interval
/-!
### Semiring structure
When `α` is a canonically `OrderedCommSemiring`, the previous `+` and `*` on `NonemptyInterval α`
form a `CommSemiring`.
-/
section NatCast
variable [Preorder α] [NatCast α]
namespace NonemptyInterval
instance : NatCast (NonemptyInterval α) where
natCast n := pure <| Nat.cast n
theorem fst_natCast (n : ℕ) : (n : NonemptyInterval α).fst = n := rfl
theorem snd_natCast (n : ℕ) : (n : NonemptyInterval α).snd = n := rfl
@[simp]
theorem pure_natCast (n : ℕ) : pure (n : α) = n := rfl
end NonemptyInterval
end NatCast
namespace NonemptyInterval
instance [CommSemiring α] [PartialOrder α] [CanonicallyOrderedAdd α] :
CommSemiring (NonemptyInterval α) :=
NonemptyInterval.toProd_injective.commSemiring _
toProd_zero toProd_one toProd_add toProd_mul (swap toProd_nsmul) toProd_pow (fun _ => rfl)
end NonemptyInterval
/-!
### Subtraction
Subtraction is defined more generally than division so that it applies to `ℕ` (and `OrderedDiv`
is not a thing and probably should not become one).
-/
section Sub
variable [Preorder α] [AddCommSemigroup α] [Sub α] [OrderedSub α] [AddLeftMono α]
instance : Sub (NonemptyInterval α) :=
⟨fun s t => ⟨(s.fst - t.snd, s.snd - t.fst), tsub_le_tsub s.fst_le_snd t.fst_le_snd⟩⟩
instance : Sub (Interval α) :=
⟨Option.map₂ Sub.sub⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) {a b : α}
@[simp]
theorem fst_sub : (s - t).fst = s.fst - t.snd :=
rfl
@[simp]
theorem snd_sub : (s - t).snd = s.snd - t.fst :=
rfl
@[simp]
theorem coe_sub_interval : (↑(s - t) : Interval α) = s - t :=
rfl
theorem sub_mem_sub (ha : a ∈ s) (hb : b ∈ t) : a - b ∈ s - t :=
⟨tsub_le_tsub ha.1 hb.2, tsub_le_tsub ha.2 hb.1⟩
@[simp]
theorem pure_sub_pure (a b : α) : pure a - pure b = pure (a - b) :=
rfl
end NonemptyInterval
namespace Interval
variable (s t : Interval α)
@[simp]
theorem bot_sub : ⊥ - t = ⊥ :=
rfl
@[simp]
theorem sub_bot : s - ⊥ = ⊥ :=
Option.map₂_none_right _ _
end Interval
end Sub
/-!
### Division in ordered groups
Note that this division does not apply to `ℚ` or `ℝ`.
-/
section Div
variable [Preorder α] [CommGroup α] [MulLeftMono α]
@[to_additive existing]
instance : Div (NonemptyInterval α) :=
⟨fun s t => ⟨(s.fst / t.snd, s.snd / t.fst), div_le_div'' s.fst_le_snd t.fst_le_snd⟩⟩
@[to_additive existing]
instance : Div (Interval α) :=
⟨Option.map₂ (· / ·)⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a b : α)
@[to_additive existing (attr := simp)]
theorem fst_div : (s / t).fst = s.fst / t.snd :=
rfl
@[to_additive existing (attr := simp)]
theorem snd_div : (s / t).snd = s.snd / t.fst :=
rfl
@[to_additive existing (attr := simp)]
theorem coe_div_interval : (↑(s / t) : Interval α) = s / t :=
rfl
@[to_additive existing]
theorem div_mem_div (ha : a ∈ s) (hb : b ∈ t) : a / b ∈ s / t :=
⟨div_le_div'' ha.1 hb.2, div_le_div'' ha.2 hb.1⟩
@[to_additive existing (attr := simp)]
theorem pure_div_pure : pure a / pure b = pure (a / b) :=
rfl
end NonemptyInterval
namespace Interval
variable (s t : Interval α)
@[to_additive existing (attr := simp)]
theorem bot_div : ⊥ / t = ⊥ :=
rfl
@[to_additive existing (attr := simp)]
theorem div_bot : s / ⊥ = ⊥ :=
Option.map₂_none_right _ _
end Interval
end Div
/-! ### Negation/inversion -/
section Inv
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α]
@[to_additive]
instance : Inv (NonemptyInterval α) :=
⟨fun s => ⟨(s.snd⁻¹, s.fst⁻¹), inv_le_inv' s.fst_le_snd⟩⟩
@[to_additive]
instance : Inv (Interval α) :=
⟨Option.map Inv.inv⟩
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a : α)
@[to_additive (attr := simp)]
theorem fst_inv : s⁻¹.fst = s.snd⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem snd_inv : s⁻¹.snd = s.fst⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem coe_inv_interval : (↑(s⁻¹) : Interval α) = (↑s)⁻¹ :=
rfl
@[to_additive]
theorem inv_mem_inv (ha : a ∈ s) : a⁻¹ ∈ s⁻¹ :=
⟨inv_le_inv' ha.2, inv_le_inv' ha.1⟩
@[to_additive (attr := simp)]
theorem inv_pure : (pure a)⁻¹ = pure a⁻¹ :=
rfl
end NonemptyInterval
@[to_additive (attr := simp)]
theorem Interval.inv_bot : (⊥ : Interval α)⁻¹ = ⊥ :=
rfl
end Inv
namespace NonemptyInterval
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : NonemptyInterval α}
@[to_additive]
protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 := by
refine ⟨fun h => ?_, ?_⟩
· rw [NonemptyInterval.ext_iff, Prod.ext_iff] at h
have := (mul_le_mul_iff_of_ge s.fst_le_snd t.fst_le_snd).1 (h.2.trans h.1.symm).le
refine ⟨s.fst, t.fst, ?_, ?_, h.1⟩ <;> apply NonemptyInterval.ext <;> dsimp [pure]
· nth_rw 2 [this.1]
· nth_rw 2 [this.2]
· rintro ⟨b, c, rfl, rfl, h⟩
rw [pure_mul_pure, h, pure_one]
instance subtractionCommMonoid {α : Type u}
[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] :
SubtractionCommMonoid (NonemptyInterval α) :=
{ NonemptyInterval.addCommMonoid with
neg := Neg.neg
sub := Sub.sub
sub_eq_add_neg := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact sub_eq_add_neg _ _
neg_neg := fun s => by apply NonemptyInterval.ext; exact neg_neg _
neg_add_rev := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact neg_add_rev _ _
neg_eq_of_add := fun s t h => by
obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.add_eq_zero_iff.1 h
rw [neg_pure, neg_eq_of_add_eq_zero_right hab]
-- TODO: use a better defeq
zsmul := zsmulRec }
@[to_additive existing NonemptyInterval.subtractionCommMonoid]
instance divisionCommMonoid : DivisionCommMonoid (NonemptyInterval α) :=
{ NonemptyInterval.commMonoid with
inv := Inv.inv
div := (· / ·)
div_eq_mul_inv := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact div_eq_mul_inv _ _
inv_inv := fun s => by apply NonemptyInterval.ext; exact inv_inv _
mul_inv_rev := fun s t => by
refine NonemptyInterval.ext (Prod.ext ?_ ?_) <;>
exact mul_inv_rev _ _
inv_eq_of_mul := fun s t h => by
obtain ⟨a, b, rfl, rfl, hab⟩ := NonemptyInterval.mul_eq_one_iff.1 h
rw [inv_pure, inv_eq_of_mul_eq_one_right hab] }
end NonemptyInterval
namespace Interval
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {s t : Interval α}
@[to_additive]
protected theorem mul_eq_one_iff : s * t = 1 ↔ ∃ a b, s = pure a ∧ t = pure b ∧ a * b = 1 := by
cases s
· simp
cases t
· simp
· simp_rw [← NonemptyInterval.coe_mul_interval, ← NonemptyInterval.coe_one_interval,
WithBot.coe_inj, NonemptyInterval.coe_eq_pure]
exact NonemptyInterval.mul_eq_one_iff
instance subtractionCommMonoid {α : Type u}
[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] :
SubtractionCommMonoid (Interval α) :=
{ Interval.addCommMonoid with
neg := Neg.neg
sub := Sub.sub
sub_eq_add_neg := by
rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (sub_eq_add_neg _ _)
neg_neg := by rintro (_ | s) <;> first |rfl|exact congr_arg some (neg_neg _)
neg_add_rev := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (neg_add_rev _ _)
neg_eq_of_add := by
rintro (_ | s) (_ | t) h <;>
first
| cases h
| exact congr_arg some (neg_eq_of_add_eq_zero_right <| Option.some_injective _ h)
-- TODO: use a better defeq
zsmul := zsmulRec }
@[to_additive existing Interval.subtractionCommMonoid]
instance divisionCommMonoid : DivisionCommMonoid (Interval α) :=
{ Interval.commMonoid with
inv := Inv.inv
div := (· / ·)
div_eq_mul_inv := by
rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (div_eq_mul_inv _ _)
inv_inv := by rintro (_ | s) <;> first |rfl|exact congr_arg some (inv_inv _)
mul_inv_rev := by rintro (_ | s) (_ | t) <;> first |rfl|exact congr_arg some (mul_inv_rev _ _)
inv_eq_of_mul := by
rintro (_ | s) (_ | t) h <;>
first
| cases h
| exact congr_arg some (inv_eq_of_mul_eq_one_right <| Option.some_injective _ h) }
end Interval
section Length
variable [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]
namespace NonemptyInterval
variable (s t : NonemptyInterval α) (a : α)
/-- The length of an interval is its first component minus its second component. This measures the
accuracy of the approximation by an interval. -/
def length : α :=
s.snd - s.fst
@[simp]
theorem length_nonneg : 0 ≤ s.length :=
sub_nonneg_of_le s.fst_le_snd
omit [IsOrderedAddMonoid α] in
@[simp]
theorem length_pure : (pure a).length = 0 :=
sub_self _
omit [IsOrderedAddMonoid α] in
@[simp]
theorem length_zero : (0 : NonemptyInterval α).length = 0 :=
length_pure _
@[simp]
theorem length_neg : (-s).length = s.length :=
neg_sub_neg _ _
@[simp]
theorem length_add : (s + t).length = s.length + t.length :=
add_sub_add_comm _ _ _ _
@[simp]
theorem length_sub : (s - t).length = s.length + t.length := by simp [sub_eq_add_neg]
@[simp]
theorem length_sum (f : ι → NonemptyInterval α) (s : Finset ι) :
(∑ i ∈ s, f i).length = ∑ i ∈ s, (f i).length :=
map_sum (⟨⟨length, length_zero⟩, length_add⟩ : NonemptyInterval α →+ α) _ _
end NonemptyInterval
namespace Interval
variable (s t : Interval α) (a : α)
/-- The length of an interval is its first component minus its second component. This measures the
accuracy of the approximation by an interval. -/
def length : Interval α → α
| ⊥ => 0
| (s : NonemptyInterval α) => s.length
@[simp]
theorem length_nonneg : ∀ s : Interval α, 0 ≤ s.length
| ⊥ => le_rfl
| (s : NonemptyInterval α) => s.length_nonneg
omit [IsOrderedAddMonoid α] in
@[simp]
theorem length_pure : (pure a).length = 0 :=
NonemptyInterval.length_pure _
omit [IsOrderedAddMonoid α] in
@[simp]
theorem length_zero : (0 : Interval α).length = 0 :=
length_pure _
@[simp]
theorem length_neg : ∀ s : Interval α, (-s).length = s.length
| ⊥ => rfl
| (s : NonemptyInterval α) => s.length_neg
theorem length_add_le : ∀ s t : Interval α, (s + t).length ≤ s.length + t.length
| ⊥, _ => by simp
| _, ⊥ => by simp
| (s : NonemptyInterval α), (t : NonemptyInterval α) => (s.length_add t).le
theorem length_sub_le : (s - t).length ≤ s.length + t.length := by
simpa [sub_eq_add_neg] using length_add_le s (-t)
theorem length_sum_le (f : ι → Interval α) (s : Finset ι) :
(∑ i ∈ s, f i).length ≤ ∑ i ∈ s, (f i).length :=
Finset.le_sum_of_subadditive _ length_zero length_add_le _ _
end Interval
end Length
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
/-- Extension for the `positivity` tactic: The length of an interval is always nonnegative. -/
@[positivity NonemptyInterval.length _]
def evalNonemptyIntervalLength : PositivityExt where
eval {u α} _ _ e := do
let ~q(@NonemptyInterval.length _ $ig $ipo $a) := e |
throwError "not NonemptyInterval.length"
let _i ← synthInstanceQ q(IsOrderedAddMonoid $α)
assertInstancesCommute
return .nonnegative q(NonemptyInterval.length_nonneg $a)
/-- Extension for the `positivity` tactic: The length of an interval is always nonnegative. -/
@[positivity Interval.length _]
def evalIntervalLength : PositivityExt where
eval {u α} _ _ e := do
let ~q(@Interval.length _ $ig $ipo $a) := e | throwError "not Interval.length"
let _i ← synthInstanceQ q(IsOrderedAddMonoid $α)
assumeInstancesCommute
return .nonnegative q(Interval.length_nonneg $a)
end Mathlib.Meta.Positivity
| Mathlib/Algebra/Order/Interval/Basic.lean | 710 | 715 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn
-/
import Mathlib.Analysis.Calculus.ContDiff.Defs
import Mathlib.Analysis.Calculus.ContDiff.FaaDiBruno
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Mul
/-!
# Higher differentiability of composition
We prove that the composition of `C^n` functions is `C^n`.
We also expand the API around `C^n` functions.
## Main results
* `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`.
Similar results are given for `C^n` functions on domains.
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞` and `⊤ : WithTop ℕ∞` with `ω`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open scoped NNReal Nat ContDiff
universe u uE uF uG
attribute [local instance 1001]
NormedAddCommGroup.toAddCommGroup AddCommGroup.toAddCommMonoid
open Set Fin Filter Function
open scoped Topology
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF}
[NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s t : Set E} {f : E → F}
{g : F → G} {x x₀ : E} {b : E × F → G} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Constants -/
section constants
theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) :
iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↦ c) s = 0 := by
induction n with
| zero =>
ext1
simp [iteratedFDerivWithin_succ_eq_comp_left, iteratedFDerivWithin_zero_eq_comp, comp_def]
| succ n IH =>
rw [iteratedFDerivWithin_succ_eq_comp_left, IH]
simp only [Pi.zero_def, comp_def, fderivWithin_const, map_zero]
@[simp]
theorem iteratedFDerivWithin_zero_fun {i : ℕ} :
iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s = 0 := by
cases i with
| zero => ext; simp
| succ i => apply iteratedFDerivWithin_succ_const
@[simp]
theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 :=
funext fun x ↦ by simp only [← iteratedFDerivWithin_univ, iteratedFDerivWithin_zero_fun]
theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) :=
analyticOnNhd_const.contDiff
/-- Constants are `C^∞`. -/
theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c :=
analyticOnNhd_const.contDiff
theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s :=
contDiff_const.contDiffOn
theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x :=
contDiff_const.contDiffAt
theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x :=
contDiffAt_const.contDiffWithinAt
@[nontriviality]
theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const
@[nontriviality]
theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const
@[nontriviality]
theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const
@[nontriviality]
theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const
theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) (s : Set E) :
iteratedFDerivWithin 𝕜 n (fun _ : E ↦ c) s = 0 := by
cases n with
| zero => contradiction
| succ n => exact iteratedFDerivWithin_succ_const n c
theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) :
(iteratedFDeriv 𝕜 n fun _ : E ↦ c) = 0 := by
simp only [← iteratedFDerivWithin_univ, iteratedFDerivWithin_const_of_ne hn]
theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) :
(iteratedFDeriv 𝕜 (n + 1) fun _ : E ↦ c) = 0 :=
iteratedFDeriv_const_of_ne (by simp) _
theorem contDiffWithinAt_singleton : ContDiffWithinAt 𝕜 n f {x} x :=
(contDiffWithinAt_const (c := f x)).congr (by simp) rfl
end constants
/-! ### Smoothness of linear functions -/
section linear
/-- Unbundled bounded linear functions are `C^n`. -/
theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f :=
(ContinuousLinearMap.analyticOnNhd hf.toContinuousLinearMap univ).contDiff
theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f :=
f.isBoundedLinearMap.contDiff
theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
f.toContinuousLinearMap.contDiff
theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
/-- The identity is `C^n`. -/
theorem contDiff_id : ContDiff 𝕜 n (id : E → E) :=
IsBoundedLinearMap.id.contDiff
theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x :=
contDiff_id.contDiffWithinAt
theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x :=
contDiff_id.contDiffAt
theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s :=
contDiff_id.contDiffOn
/-- Bilinear functions are `C^n`. -/
theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b :=
(hb.toContinuousLinearMap.analyticOnNhd_bilinear _).contDiff
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor
series whose `k`-th term is given by `g ∘ (p k)`. -/
theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp {n : WithTop ℕ∞} (g : F →L[𝕜] G)
(hf : HasFTaylorSeriesUpToOn n f p s) :
HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where
zero_eq x hx := congr_arg g (hf.zero_eq x hx)
fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx)
cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm)
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
refine ⟨u, hu, _, hp.continuousLinearMap_comp g, fun i ↦ ?_⟩
change AnalyticOn 𝕜
(fun x ↦ (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin i ↦ E) F G g) (p x i)) u
apply AnalyticOnNhd.comp_analyticOn _ (h'p i) (Set.mapsTo_univ _ _)
exact ContinuousLinearMap.analyticOnNhd _ _
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
exact ⟨u, hu, _, hp.continuousLinearMap_comp g⟩
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
ContDiffWithinAt.continuousLinearMap_comp g hf
/-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/
theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g
/-- Composition by continuous linear maps on the left preserves `C^n` functions. -/
theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n fun x => g (f x) :=
contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf)
/-- The iterated derivative within a set of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by
rcases hf.contDiffOn' hi (by simp) with ⟨U, hU, hxU, hfU⟩
rw [← iteratedFDerivWithin_inter_open hU hxU, ← iteratedFDerivWithin_inter_open (f := f) hU hxU]
rw [insert_eq_of_mem hx] at hfU
exact .symm <| (hfU.ftaylorSeriesWithin (hs.inter hU)).continuousLinearMap_comp g
|>.eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter hU) ⟨hx, hxU⟩
/-- The iterated derivative of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffAt 𝕜 n f x) {i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by
simp only [← iteratedFDerivWithin_univ]
exact g.iteratedFDerivWithin_comp_left hf.contDiffWithinAt uniqueDiffOn_univ (mem_univ x) hi
/-- The iterated derivative within a set of the composition with a linear equiv on the left is
obtained by applying the linear equiv to the iterated derivative. This is true without
differentiability assumptions. -/
theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_left (g : F ≃L[𝕜] G) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by
induction' i with i IH generalizing x
· ext1 m
simp only [iteratedFDerivWithin_zero_apply, comp_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, coe_coe]
· ext1 m
rw [iteratedFDerivWithin_succ_apply_left]
have Z : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (g ∘ f) s) s x =
fderivWithin 𝕜 (g.continuousMultilinearMapCongrRight (fun _ : Fin i => E) ∘
iteratedFDerivWithin 𝕜 i f s) s x :=
fderivWithin_congr' (@IH) hx
simp_rw [Z]
rw [(g.continuousMultilinearMapCongrRight fun _ : Fin i => E).comp_fderivWithin (hs x hx)]
simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply,
ContinuousLinearEquiv.continuousMultilinearMapCongrRight_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, EmbeddingLike.apply_eq_iff_eq]
rw [iteratedFDerivWithin_succ_apply_left]
/-- Composition with a linear isometry on the left preserves the norm of the iterated
derivative within a set. -/
theorem LinearIsometry.norm_iteratedFDerivWithin_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : i ≤ n) :
‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by
have :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.toContinuousLinearMap.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
g.toContinuousLinearMap.iteratedFDerivWithin_comp_left hf hs hx hi
rw [this]
apply LinearIsometry.norm_compContinuousMultilinearMap
/-- Composition with a linear isometry on the left preserves the norm of the iterated
derivative. -/
theorem LinearIsometry.norm_iteratedFDeriv_comp_left {f : E → F} (g : F →ₗᵢ[𝕜] G)
(hf : ContDiffAt 𝕜 n f x) {i : ℕ} (hi : i ≤ n) :
‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by
simp only [← iteratedFDerivWithin_univ]
exact g.norm_iteratedFDerivWithin_comp_left hf.contDiffWithinAt uniqueDiffOn_univ (mem_univ x) hi
/-- Composition with a linear isometry equiv on the left preserves the norm of the iterated
derivative within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (i : ℕ) :
‖iteratedFDerivWithin 𝕜 i (g ∘ f) s x‖ = ‖iteratedFDerivWithin 𝕜 i f s x‖ := by
have :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(g : F →L[𝕜] G).compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) :=
g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_left f hs hx i
rw [this]
apply LinearIsometry.norm_compContinuousMultilinearMap g.toLinearIsometry
/-- Composition with a linear isometry equiv on the left preserves the norm of the iterated
derivative. -/
theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_left (g : F ≃ₗᵢ[𝕜] G) (f : E → F) (x : E)
(i : ℕ) : ‖iteratedFDeriv 𝕜 i (g ∘ f) x‖ = ‖iteratedFDeriv 𝕜 i f x‖ := by
rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ]
apply g.norm_iteratedFDerivWithin_comp_left f uniqueDiffOn_univ (mem_univ x) i
/-- Composition by continuous linear equivs on the left respects higher differentiability at a
point in a domain. -/
theorem ContinuousLinearEquiv.comp_contDiffWithinAt_iff (e : F ≃L[𝕜] G) :
ContDiffWithinAt 𝕜 n (e ∘ f) s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H => by
simpa only [Function.comp_def, e.symm.coe_coe, e.symm_apply_apply] using
H.continuousLinearMap_comp (e.symm : G →L[𝕜] F),
fun H => H.continuousLinearMap_comp (e : F →L[𝕜] G)⟩
/-- Composition by continuous linear equivs on the left respects higher differentiability at a
point. -/
theorem ContinuousLinearEquiv.comp_contDiffAt_iff (e : F ≃L[𝕜] G) :
ContDiffAt 𝕜 n (e ∘ f) x ↔ ContDiffAt 𝕜 n f x := by
simp only [← contDiffWithinAt_univ, e.comp_contDiffWithinAt_iff]
/-- Composition by continuous linear equivs on the left respects higher differentiability on
domains. -/
theorem ContinuousLinearEquiv.comp_contDiffOn_iff (e : F ≃L[𝕜] G) :
ContDiffOn 𝕜 n (e ∘ f) s ↔ ContDiffOn 𝕜 n f s := by
simp [ContDiffOn, e.comp_contDiffWithinAt_iff]
/-- Composition by continuous linear equivs on the left respects higher differentiability. -/
theorem ContinuousLinearEquiv.comp_contDiff_iff (e : F ≃L[𝕜] G) :
ContDiff 𝕜 n (e ∘ f) ↔ ContDiff 𝕜 n f := by
simp only [← contDiffOn_univ, e.comp_contDiffOn_iff]
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `f ∘ g` admits a Taylor
series in `g ⁻¹' s`, whose `k`-th term is given by `p k (g v₁, ..., g vₖ)` . -/
theorem HasFTaylorSeriesUpToOn.compContinuousLinearMap
(hf : HasFTaylorSeriesUpToOn n f p s) (g : G →L[𝕜] E) :
HasFTaylorSeriesUpToOn n (f ∘ g) (fun x k => (p (g x) k).compContinuousLinearMap fun _ => g)
(g ⁻¹' s) := by
let A : ∀ m : ℕ, (E[×m]→L[𝕜] F) → G[×m]→L[𝕜] F := fun m h => h.compContinuousLinearMap fun _ => g
have hA : ∀ m, IsBoundedLinearMap 𝕜 (A m) := fun m =>
isBoundedLinearMap_continuousMultilinearMap_comp_linear g
constructor
· intro x hx
simp only [(hf.zero_eq (g x) hx).symm, Function.comp_apply]
change (p (g x) 0 fun _ : Fin 0 => g 0) = p (g x) 0 0
rw [ContinuousLinearMap.map_zero]
rfl
· intro m hm x hx
convert (hA m).hasFDerivAt.comp_hasFDerivWithinAt x
((hf.fderivWithin m hm (g x) hx).comp x g.hasFDerivWithinAt (Subset.refl _))
ext y v
change p (g x) (Nat.succ m) (g ∘ cons y v) = p (g x) m.succ (cons (g y) (g ∘ v))
rw [comp_cons]
· intro m hm
exact (hA m).continuous.comp_continuousOn <| (hf.cont m hm).comp g.continuous.continuousOn <|
Subset.refl _
/-- Composition by continuous linear maps on the right preserves `C^n` functions at a point on
a domain. -/
theorem ContDiffWithinAt.comp_continuousLinearMap {x : G} (g : G →L[𝕜] E)
(hf : ContDiffWithinAt 𝕜 n f s (g x)) : ContDiffWithinAt 𝕜 n (f ∘ g) (g ⁻¹' s) x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g, ?_⟩
· refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu
exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _)
· intro i
change AnalyticOn 𝕜 (fun x ↦
ContinuousMultilinearMap.compContinuousLinearMapL (fun _ ↦ g) (p (g x) i)) (⇑g ⁻¹' u)
apply AnalyticOn.comp _ _ (Set.mapsTo_univ _ _)
· exact ContinuousLinearEquiv.analyticOn _ _
· exact (h'p i).comp (g.analyticOn _) (mapsTo_preimage _ _)
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
refine ⟨g ⁻¹' u, ?_, _, hp.compContinuousLinearMap g⟩
refine g.continuous.continuousWithinAt.tendsto_nhdsWithin ?_ hu
exact (mapsTo_singleton.2 <| mem_singleton _).union_union (mapsTo_preimage _ _)
/-- Composition by continuous linear maps on the right preserves `C^n` functions on domains. -/
theorem ContDiffOn.comp_continuousLinearMap (hf : ContDiffOn 𝕜 n f s) (g : G →L[𝕜] E) :
ContDiffOn 𝕜 n (f ∘ g) (g ⁻¹' s) := fun x hx => (hf (g x) hx).comp_continuousLinearMap g
/-- Composition by continuous linear maps on the right preserves `C^n` functions. -/
theorem ContDiff.comp_continuousLinearMap {f : E → F} {g : G →L[𝕜] E} (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n (f ∘ g) :=
contDiffOn_univ.1 <| ContDiffOn.comp_continuousLinearMap (contDiffOn_univ.2 hf) _
/-- The iterated derivative within a set of the composition with a linear map on the right is
obtained by composing the iterated derivative with the linear map. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_right {f : E → F} (g : G →L[𝕜] E)
(hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (h's : UniqueDiffOn 𝕜 (g ⁻¹' s)) {x : G}
(hx : g x ∈ s) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g :=
((((hf.of_le hi).ftaylorSeriesWithin hs).compContinuousLinearMap
g).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl h's hx).symm
/-- The iterated derivative within a set of the composition with a linear equiv on the right is
obtained by composing the iterated derivative with the linear equiv. -/
theorem ContinuousLinearEquiv.iteratedFDerivWithin_comp_right (g : G ≃L[𝕜] E) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) :
iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g := by
induction' i with i IH generalizing x
· ext1
simp only [iteratedFDerivWithin_zero_apply, comp_apply,
ContinuousMultilinearMap.compContinuousLinearMap_apply]
· ext1 m
simp only [ContinuousMultilinearMap.compContinuousLinearMap_apply,
ContinuousLinearEquiv.coe_coe, iteratedFDerivWithin_succ_apply_left]
have : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s)) (g ⁻¹' s) x =
fderivWithin 𝕜
(ContinuousLinearEquiv.continuousMultilinearMapCongrLeft _ (fun _x : Fin i => g) ∘
(iteratedFDerivWithin 𝕜 i f s ∘ g)) (g ⁻¹' s) x :=
fderivWithin_congr' (@IH) hx
rw [this, ContinuousLinearEquiv.comp_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx)]
simp only [ContinuousLinearMap.coe_comp', ContinuousLinearEquiv.coe_coe, comp_apply,
ContinuousLinearEquiv.continuousMultilinearMapCongrLeft_apply,
ContinuousMultilinearMap.compContinuousLinearMap_apply]
rw [ContinuousLinearEquiv.comp_right_fderivWithin _ (g.uniqueDiffOn_preimage_iff.2 hs x hx),
ContinuousLinearMap.coe_comp', coe_coe, comp_apply, tail_def, tail_def]
/-- The iterated derivative of the composition with a linear map on the right is
obtained by composing the iterated derivative with the linear map. -/
theorem ContinuousLinearMap.iteratedFDeriv_comp_right (g : G →L[𝕜] E) {f : E → F}
(hf : ContDiff 𝕜 n f) (x : G) {i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (f ∘ g) x =
(iteratedFDeriv 𝕜 i f (g x)).compContinuousLinearMap fun _ => g := by
simp only [← iteratedFDerivWithin_univ]
exact g.iteratedFDerivWithin_comp_right hf.contDiffOn uniqueDiffOn_univ uniqueDiffOn_univ
(mem_univ _) hi
/-- Composition with a linear isometry on the right preserves the norm of the iterated derivative
within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F)
(hs : UniqueDiffOn 𝕜 s) {x : G} (hx : g x ∈ s) (i : ℕ) :
‖iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x‖ = ‖iteratedFDerivWithin 𝕜 i f s (g x)‖ := by
have : iteratedFDerivWithin 𝕜 i (f ∘ g) (g ⁻¹' s) x =
(iteratedFDerivWithin 𝕜 i f s (g x)).compContinuousLinearMap fun _ => g :=
g.toContinuousLinearEquiv.iteratedFDerivWithin_comp_right f hs hx i
rw [this, ContinuousMultilinearMap.norm_compContinuous_linearIsometryEquiv]
/-- Composition with a linear isometry on the right preserves the norm of the iterated derivative
within a set. -/
theorem LinearIsometryEquiv.norm_iteratedFDeriv_comp_right (g : G ≃ₗᵢ[𝕜] E) (f : E → F) (x : G)
(i : ℕ) : ‖iteratedFDeriv 𝕜 i (f ∘ g) x‖ = ‖iteratedFDeriv 𝕜 i f (g x)‖ := by
simp only [← iteratedFDerivWithin_univ]
apply g.norm_iteratedFDerivWithin_comp_right f uniqueDiffOn_univ (mem_univ (g x)) i
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point in a domain. -/
theorem ContinuousLinearEquiv.contDiffWithinAt_comp_iff (e : G ≃L[𝕜] E) :
ContDiffWithinAt 𝕜 n (f ∘ e) (e ⁻¹' s) (e.symm x) ↔ ContDiffWithinAt 𝕜 n f s x := by
constructor
· intro H
simpa [← preimage_comp, Function.comp_def] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G)
· intro H
rw [← e.apply_symm_apply x, ← e.coe_coe] at H
exact H.comp_continuousLinearMap _
/-- Composition by continuous linear equivs on the right respects higher differentiability at a
point. -/
theorem ContinuousLinearEquiv.contDiffAt_comp_iff (e : G ≃L[𝕜] E) :
ContDiffAt 𝕜 n (f ∘ e) (e.symm x) ↔ ContDiffAt 𝕜 n f x := by
rw [← contDiffWithinAt_univ, ← contDiffWithinAt_univ, ← preimage_univ]
exact e.contDiffWithinAt_comp_iff
/-- Composition by continuous linear equivs on the right respects higher differentiability on
domains. -/
theorem ContinuousLinearEquiv.contDiffOn_comp_iff (e : G ≃L[𝕜] E) :
ContDiffOn 𝕜 n (f ∘ e) (e ⁻¹' s) ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => by simpa [Function.comp_def] using H.comp_continuousLinearMap (e.symm : E →L[𝕜] G),
fun H => H.comp_continuousLinearMap (e : G →L[𝕜] E)⟩
/-- Composition by continuous linear equivs on the right respects higher differentiability. -/
theorem ContinuousLinearEquiv.contDiff_comp_iff (e : G ≃L[𝕜] E) :
ContDiff 𝕜 n (f ∘ e) ↔ ContDiff 𝕜 n f := by
rw [← contDiffOn_univ, ← contDiffOn_univ, ← preimage_univ]
exact e.contDiffOn_comp_iff
end linear
/-! ### The Cartesian product of two C^n functions is C^n. -/
section prod
/-- If two functions `f` and `g` admit Taylor series `p` and `q` in a set `s`, then the cartesian
product of `f` and `g` admits the cartesian product of `p` and `q` as a Taylor series. -/
theorem HasFTaylorSeriesUpToOn.prodMk {n : WithTop ℕ∞}
(hf : HasFTaylorSeriesUpToOn n f p s) {g : E → G}
{q : E → FormalMultilinearSeries 𝕜 E G} (hg : HasFTaylorSeriesUpToOn n g q s) :
HasFTaylorSeriesUpToOn n (fun y => (f y, g y)) (fun y k => (p y k).prod (q y k)) s := by
set L := fun m => ContinuousMultilinearMap.prodL 𝕜 (fun _ : Fin m => E) F G
constructor
· intro x hx; rw [← hf.zero_eq x hx, ← hg.zero_eq x hx]; rfl
· intro m hm x hx
convert (L m).hasFDerivAt.comp_hasFDerivWithinAt x
((hf.fderivWithin m hm x hx).prodMk (hg.fderivWithin m hm x hx))
· intro m hm
exact (L m).continuous.comp_continuousOn ((hf.cont m hm).prodMk (hg.cont m hm))
@[deprecated (since := "2025-03-09")]
alias HasFTaylorSeriesUpToOn.prod := HasFTaylorSeriesUpToOn.prodMk
/-- The cartesian product of `C^n` functions at a point in a domain is `C^n`. -/
theorem ContDiffWithinAt.prodMk {s : Set E} {f : E → F} {g : E → G}
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
ContDiffWithinAt 𝕜 n (fun x : E => (f x, g x)) s x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
obtain ⟨v, hv, q, hq, h'q⟩ := hg
refine ⟨u ∩ v, Filter.inter_mem hu hv, _,
(hp.mono inter_subset_left).prodMk (hq.mono inter_subset_right), fun i ↦ ?_⟩
change AnalyticOn 𝕜 (fun x ↦ ContinuousMultilinearMap.prodL _ _ _ _ (p x i, q x i)) (u ∩ v)
apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn _ (Set.mapsTo_univ _ _)
exact ((h'p i).mono inter_subset_left).prod ((h'q i).mono inter_subset_right)
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
rcases hg m hm with ⟨v, hv, q, hq⟩
exact ⟨u ∩ v, Filter.inter_mem hu hv, _,
(hp.mono inter_subset_left).prodMk (hq.mono inter_subset_right)⟩
@[deprecated (since := "2025-03-09")]
alias ContDiffWithinAt.prod := ContDiffWithinAt.prodMk
/-- The cartesian product of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.prodMk {s : Set E} {f : E → F} {g : E → G} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x : E => (f x, g x)) s := fun x hx =>
(hf x hx).prodMk (hg x hx)
@[deprecated (since := "2025-03-09")]
alias ContDiffOn.prod := ContDiffOn.prodMk
/-- The cartesian product of `C^n` functions at a point is `C^n`. -/
theorem ContDiffAt.prodMk {f : E → F} {g : E → G} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x : E => (f x, g x)) x :=
contDiffWithinAt_univ.1 <| hf.contDiffWithinAt.prodMk hg.contDiffWithinAt
@[deprecated (since := "2025-03-09")]
alias ContDiffAt.prod := ContDiffAt.prodMk
/-- The cartesian product of `C^n` functions is `C^n`. -/
theorem ContDiff.prodMk {f : E → F} {g : E → G} (hf : ContDiff 𝕜 n f) (hg : ContDiff 𝕜 n g) :
ContDiff 𝕜 n fun x : E => (f x, g x) :=
contDiffOn_univ.1 <| hf.contDiffOn.prodMk hg.contDiffOn
@[deprecated (since := "2025-03-09")]
alias ContDiff.prod := ContDiff.prodMk
end prod
section comp
/-!
### Composition of `C^n` functions
We show that the composition of `C^n` functions is `C^n`. One way to do this would be to
use the following simple inductive proof. Assume it is done for `n`.
Then, to check it for `n+1`, one needs to check that the derivative of `g ∘ f` is `C^n`, i.e.,
that `Dg(f x) ⬝ Df(x)` is `C^n`. The term `Dg (f x)` is the composition of two `C^n` functions, so
it is `C^n` by the inductive assumption. The term `Df(x)` is also `C^n`. Then, the matrix
multiplication is the application of a bilinear map (which is `C^∞`, and therefore `C^n`) to
`x ↦ (Dg(f x), Df x)`. As the composition of two `C^n` maps, it is again `C^n`, and we are done.
There are two difficulties in this proof.
The first one is that it is an induction over all Banach
spaces. In Lean, this is only possible if they belong to a fixed universe. One could formalize this
by first proving the statement in this case, and then extending the result to general universes
by embedding all the spaces we consider in a common universe through `ULift`.
The second one is that it does not work cleanly for analytic maps: for this case, we need to
exhibit a whole sequence of derivatives which are all analytic, not just finitely many of them, so
an induction is never enough at a finite step.
Both these difficulties can be overcome with some cost. However, we choose a different path: we
write down an explicit formula for the `n`-th derivative of `g ∘ f` in terms of derivatives of
`g` and `f` (this is the formula of Faa-Di Bruno) and use this formula to get a suitable Taylor
expansion for `g ∘ f`. Writing down the formula of Faa-Di Bruno is not easy as the formula is quite
intricate, but it is also useful for other purposes and once available it makes the proof here
essentially trivial.
-/
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) (st : MapsTo f s t) :
ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
match n with
| ω =>
have h'f : ContDiffWithinAt 𝕜 ω f s x := hf
obtain ⟨u, hu, p, hp, h'p⟩ := h'f
obtain ⟨v, hv, q, hq, h'q⟩ := hg
let w := insert x s ∩ (u ∩ f ⁻¹' v)
have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
have wu : w ⊆ u := fun y hy => hy.2.1
refine ⟨w, ?_, fun y ↦ (q (f y)).taylorComp (p y), hq.comp (hp.mono wu) wv, ?_⟩
· apply inter_mem self_mem_nhdsWithin (inter_mem hu ?_)
apply (continuousWithinAt_insert_self.2 hf.continuousWithinAt).preimage_mem_nhdsWithin'
apply nhdsWithin_mono _ _ hv
simp only [image_insert_eq]
apply insert_subset_insert
exact image_subset_iff.mpr st
· have : AnalyticOn 𝕜 f w := by
have : AnalyticOn 𝕜 (fun y ↦ (continuousMultilinearCurryFin0 𝕜 E F).symm (f y)) w :=
((h'p 0).mono wu).congr fun y hy ↦ (hp.zero_eq' (wu hy)).symm
have : AnalyticOn 𝕜 (fun y ↦ (continuousMultilinearCurryFin0 𝕜 E F)
((continuousMultilinearCurryFin0 𝕜 E F).symm (f y))) w :=
AnalyticOnNhd.comp_analyticOn (LinearIsometryEquiv.analyticOnNhd _ _ ) this
(mapsTo_univ _ _)
simpa using this
exact analyticOn_taylorComp h'q (fun n ↦ (h'p n).mono wu) this wv
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
rcases hg m hm with ⟨v, hv, q, hq⟩
let w := insert x s ∩ (u ∩ f ⁻¹' v)
have wv : w ⊆ f ⁻¹' v := fun y hy => hy.2.2
have wu : w ⊆ u := fun y hy => hy.2.1
refine ⟨w, ?_, fun y ↦ (q (f y)).taylorComp (p y), hq.comp (hp.mono wu) wv⟩
apply inter_mem self_mem_nhdsWithin (inter_mem hu ?_)
apply (continuousWithinAt_insert_self.2 hf.continuousWithinAt).preimage_mem_nhdsWithin'
apply nhdsWithin_mono _ _ hv
simp only [image_insert_eq]
apply insert_subset_insert
exact image_subset_iff.mpr st
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
(hf : ContDiffOn 𝕜 n f s) (st : MapsTo f s t) : ContDiffOn 𝕜 n (g ∘ f) s :=
fun x hx ↦ ContDiffWithinAt.comp x (hg (f x) (st hx)) (hf x hx) st
/-- The composition of `C^n` functions on domains is `C^n`. -/
theorem ContDiffOn.comp_inter
{s : Set E} {t : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g t)
(hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) :=
hg.comp (hf.mono inter_subset_left) inter_subset_right
@[deprecated (since := "2024-10-30")] alias ContDiffOn.comp' := ContDiffOn.comp_inter
/-- The composition of a `C^n` function on a domain with a `C^n` function is `C^n`. -/
theorem ContDiff.comp_contDiffOn {s : Set E} {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g)
(hf : ContDiffOn 𝕜 n f s) : ContDiffOn 𝕜 n (g ∘ f) s :=
(contDiffOn_univ.2 hg).comp hf (mapsTo_univ _ _)
theorem ContDiffOn.comp_contDiff {s : Set F} {g : F → G} {f : E → F} (hg : ContDiffOn 𝕜 n g s)
(hf : ContDiff 𝕜 n f) (hs : ∀ x, f x ∈ s) : ContDiff 𝕜 n (g ∘ f) := by
rw [← contDiffOn_univ] at *
exact hg.comp hf fun x _ => hs x
theorem ContDiffOn.image_comp_contDiff {s : Set E} {g : F → G} {f : E → F}
(hg : ContDiffOn 𝕜 n g (f '' s)) (hf : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n (g ∘ f) s :=
hg.comp hf.contDiffOn (s.mapsTo_image f)
/-- The composition of `C^n` functions is `C^n`. -/
theorem ContDiff.comp {g : F → G} {f : E → F} (hg : ContDiff 𝕜 n g) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n (g ∘ f) :=
contDiffOn_univ.1 <| ContDiffOn.comp (contDiffOn_univ.2 hg) (contDiffOn_univ.2 hf) (subset_univ _)
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp_of_eq {s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x) (st : MapsTo f s t)
(hy : f x = y) :
ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp x hf st
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_mem_nhdsWithin_image
{s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : t ∈ 𝓝[f '' s] f x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
(hg.mono_of_mem_nhdsWithin hs).comp x hf (subset_preimage_image f s)
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_mem_nhdsWithin_image_of_eq
{s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : t ∈ 𝓝[f '' s] f x) (hy : f x = y) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp_of_mem_nhdsWithin_image x hf hs
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp_inter {s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x :=
hg.comp x (hf.mono inter_subset_left) inter_subset_right
/-- The composition of `C^n` functions at points in domains is `C^n`. -/
theorem ContDiffWithinAt.comp_inter_of_eq {s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F}
(x : E) (hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x) (hy : f x = y) :
ContDiffWithinAt 𝕜 n (g ∘ f) (s ∩ f ⁻¹' t) x := by
subst hy; exact hg.comp_inter x hf
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_preimage_mem_nhdsWithin
{s : Set E} {t : Set F} {g : F → G} {f : E → F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : f ⁻¹' t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
(hg.comp_inter x hf).mono_of_mem_nhdsWithin (inter_mem self_mem_nhdsWithin hs)
/-- The composition of `C^n` functions at points in domains is `C^n`,
with a weaker condition on `s` and `t`. -/
theorem ContDiffWithinAt.comp_of_preimage_mem_nhdsWithin_of_eq
{s : Set E} {t : Set F} {g : F → G} {f : E → F} {y : F} (x : E)
(hg : ContDiffWithinAt 𝕜 n g t y) (hf : ContDiffWithinAt 𝕜 n f s x)
(hs : f ⁻¹' t ∈ 𝓝[s] x) (hy : f x = y) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp_of_preimage_mem_nhdsWithin x hf hs
theorem ContDiffAt.comp_contDiffWithinAt (x : E) (hg : ContDiffAt 𝕜 n g (f x))
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x :=
hg.comp x hf (mapsTo_univ _ _)
theorem ContDiffAt.comp_contDiffWithinAt_of_eq {y : F} (x : E) (hg : ContDiffAt 𝕜 n g y)
(hf : ContDiffWithinAt 𝕜 n f s x) (hy : f x = y) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
subst hy; exact hg.comp_contDiffWithinAt x hf
/-- The composition of `C^n` functions at points is `C^n`. -/
nonrec theorem ContDiffAt.comp (x : E) (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
hg.comp x hf (mapsTo_univ _ _)
theorem ContDiff.comp_contDiffWithinAt {g : F → G} {f : E → F} (h : ContDiff 𝕜 n g)
(hf : ContDiffWithinAt 𝕜 n f t x) : ContDiffWithinAt 𝕜 n (g ∘ f) t x :=
haveI : ContDiffWithinAt 𝕜 n g univ (f x) := h.contDiffAt.contDiffWithinAt
this.comp x hf (subset_univ _)
theorem ContDiff.comp_contDiffAt {g : F → G} {f : E → F} (x : E) (hg : ContDiff 𝕜 n g)
(hf : ContDiffAt 𝕜 n f x) : ContDiffAt 𝕜 n (g ∘ f) x :=
hg.comp_contDiffWithinAt hf
theorem iteratedFDerivWithin_comp_of_eventually_mem {t : Set F}
(hg : ContDiffWithinAt 𝕜 n g t (f x)) (hf : ContDiffWithinAt 𝕜 n f s x)
(ht : UniqueDiffOn 𝕜 t) (hs : UniqueDiffOn 𝕜 s) (hxs : x ∈ s) (hst : ∀ᶠ y in 𝓝[s] x, f y ∈ t)
{i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(ftaylorSeriesWithin 𝕜 g t (f x)).taylorComp (ftaylorSeriesWithin 𝕜 f s x) i := by
obtain ⟨u, hxu, huo, hfu, hgu⟩ : ∃ u, x ∈ u ∧ IsOpen u ∧
HasFTaylorSeriesUpToOn i f (ftaylorSeriesWithin 𝕜 f s) (s ∩ u) ∧
HasFTaylorSeriesUpToOn i g (ftaylorSeriesWithin 𝕜 g t) (f '' (s ∩ u)) := by
have hxt : f x ∈ t := hst.self_of_nhdsWithin hxs
have hf_tendsto : Tendsto f (𝓝[s] x) (𝓝[t] (f x)) :=
tendsto_nhdsWithin_iff.mpr ⟨hf.continuousWithinAt, hst⟩
have H₁ : ∀ᶠ u in (𝓝[s] x).smallSets,
HasFTaylorSeriesUpToOn i f (ftaylorSeriesWithin 𝕜 f s) u :=
hf.eventually_hasFTaylorSeriesUpToOn hs hxs hi
have H₂ : ∀ᶠ u in (𝓝[s] x).smallSets,
HasFTaylorSeriesUpToOn i g (ftaylorSeriesWithin 𝕜 g t) (f '' u) :=
hf_tendsto.image_smallSets.eventually (hg.eventually_hasFTaylorSeriesUpToOn ht hxt hi)
rcases (nhdsWithin_basis_open _ _).smallSets.eventually_iff.mp (H₁.and H₂)
with ⟨u, ⟨hxu, huo⟩, hu⟩
exact ⟨u, hxu, huo, hu (by simp [inter_comm])⟩
exact .symm <| (hgu.comp hfu (mapsTo_image _ _)).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl
(hs.inter huo) ⟨hxs, hxu⟩ |>.trans <| iteratedFDerivWithin_inter_open huo hxu
theorem iteratedFDerivWithin_comp {t : Set F} (hg : ContDiffWithinAt 𝕜 n g t (f x))
(hf : ContDiffWithinAt 𝕜 n f s x) (ht : UniqueDiffOn 𝕜 t) (hs : UniqueDiffOn 𝕜 s)
(hx : x ∈ s) (hst : MapsTo f s t) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
(ftaylorSeriesWithin 𝕜 g t (f x)).taylorComp (ftaylorSeriesWithin 𝕜 f s x) i :=
iteratedFDerivWithin_comp_of_eventually_mem hg hf ht hs hx (eventually_mem_nhdsWithin.mono hst) hi
theorem iteratedFDeriv_comp (hg : ContDiffAt 𝕜 n g (f x)) (hf : ContDiffAt 𝕜 n f x)
{i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (g ∘ f) x =
(ftaylorSeries 𝕜 g (f x)).taylorComp (ftaylorSeries 𝕜 f x) i := by
simp only [← iteratedFDerivWithin_univ, ← ftaylorSeriesWithin_univ]
exact iteratedFDerivWithin_comp hg.contDiffWithinAt hf.contDiffWithinAt
uniqueDiffOn_univ uniqueDiffOn_univ (mem_univ _) (mapsTo_univ _ _) hi
end comp
/-!
### Smoothness of projections
-/
/-- The first projection in a product is `C^∞`. -/
theorem contDiff_fst : ContDiff 𝕜 n (Prod.fst : E × F → E) :=
IsBoundedLinearMap.contDiff IsBoundedLinearMap.fst
/-- Postcomposing `f` with `Prod.fst` is `C^n` -/
theorem ContDiff.fst {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).1 :=
contDiff_fst.comp hf
/-- Precomposing `f` with `Prod.fst` is `C^n` -/
theorem ContDiff.fst' {f : E → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.1 :=
hf.comp contDiff_fst
/-- The first projection on a domain in a product is `C^∞`. -/
theorem contDiffOn_fst {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.fst : E × F → E) s :=
ContDiff.contDiffOn contDiff_fst
theorem ContDiffOn.fst {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (f x).1) s :=
contDiff_fst.comp_contDiffOn hf
/-- The first projection at a point in a product is `C^∞`. -/
theorem contDiffAt_fst {p : E × F} : ContDiffAt 𝕜 n (Prod.fst : E × F → E) p :=
contDiff_fst.contDiffAt
/-- Postcomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/
theorem ContDiffAt.fst {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (f x).1) x :=
contDiffAt_fst.comp x hf
/-- Precomposing `f` with `Prod.fst` is `C^n` at `(x, y)` -/
theorem ContDiffAt.fst' {f : E → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x : E × F => f x.1) (x, y) :=
ContDiffAt.comp (x, y) hf contDiffAt_fst
/-- Precomposing `f` with `Prod.fst` is `C^n` at `x : E × F` -/
theorem ContDiffAt.fst'' {f : E → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.1) :
ContDiffAt 𝕜 n (fun x : E × F => f x.1) x :=
hf.comp x contDiffAt_fst
/-- The first projection within a domain at a point in a product is `C^∞`. -/
theorem contDiffWithinAt_fst {s : Set (E × F)} {p : E × F} :
ContDiffWithinAt 𝕜 n (Prod.fst : E × F → E) s p :=
contDiff_fst.contDiffWithinAt
/-- The second projection in a product is `C^∞`. -/
theorem contDiff_snd : ContDiff 𝕜 n (Prod.snd : E × F → F) :=
IsBoundedLinearMap.contDiff IsBoundedLinearMap.snd
/-- Postcomposing `f` with `Prod.snd` is `C^n` -/
theorem ContDiff.snd {f : E → F × G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (f x).2 :=
contDiff_snd.comp hf
/-- Precomposing `f` with `Prod.snd` is `C^n` -/
theorem ContDiff.snd' {f : F → G} (hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x : E × F => f x.2 :=
hf.comp contDiff_snd
/-- The second projection on a domain in a product is `C^∞`. -/
theorem contDiffOn_snd {s : Set (E × F)} : ContDiffOn 𝕜 n (Prod.snd : E × F → F) s :=
ContDiff.contDiffOn contDiff_snd
theorem ContDiffOn.snd {f : E → F × G} {s : Set E} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (f x).2) s :=
contDiff_snd.comp_contDiffOn hf
/-- The second projection at a point in a product is `C^∞`. -/
theorem contDiffAt_snd {p : E × F} : ContDiffAt 𝕜 n (Prod.snd : E × F → F) p :=
contDiff_snd.contDiffAt
/-- Postcomposing `f` with `Prod.snd` is `C^n` at `x` -/
theorem ContDiffAt.snd {f : E → F × G} {x : E} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (f x).2) x :=
contDiffAt_snd.comp x hf
/-- Precomposing `f` with `Prod.snd` is `C^n` at `(x, y)` -/
theorem ContDiffAt.snd' {f : F → G} {x : E} {y : F} (hf : ContDiffAt 𝕜 n f y) :
ContDiffAt 𝕜 n (fun x : E × F => f x.2) (x, y) :=
ContDiffAt.comp (x, y) hf contDiffAt_snd
/-- Precomposing `f` with `Prod.snd` is `C^n` at `x : E × F` -/
theorem ContDiffAt.snd'' {f : F → G} {x : E × F} (hf : ContDiffAt 𝕜 n f x.2) :
ContDiffAt 𝕜 n (fun x : E × F => f x.2) x :=
hf.comp x contDiffAt_snd
/-- The second projection within a domain at a point in a product is `C^∞`. -/
theorem contDiffWithinAt_snd {s : Set (E × F)} {p : E × F} :
ContDiffWithinAt 𝕜 n (Prod.snd : E × F → F) s p :=
contDiff_snd.contDiffWithinAt
section NAry
variable {E₁ E₂ E₃ : Type*}
variable [NormedAddCommGroup E₁] [NormedAddCommGroup E₂] [NormedAddCommGroup E₃]
[NormedSpace 𝕜 E₁] [NormedSpace 𝕜 E₂] [NormedSpace 𝕜 E₃]
theorem ContDiff.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} (hg : ContDiff 𝕜 n g)
(hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) : ContDiff 𝕜 n fun x => g (f₁ x, f₂ x) :=
hg.comp <| hf₁.prodMk hf₂
theorem ContDiffAt.comp₂ {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {x : F}
(hg : ContDiffAt 𝕜 n g (f₁ x, f₂ x))
(hf₁ : ContDiffAt 𝕜 n f₁ x) (hf₂ : ContDiffAt 𝕜 n f₂ x) :
ContDiffAt 𝕜 n (fun x => g (f₁ x, f₂ x)) x :=
hg.comp x (hf₁.prodMk hf₂)
theorem ContDiffAt.comp₂_contDiffWithinAt {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂}
{s : Set F} {x : F} (hg : ContDiffAt 𝕜 n g (f₁ x, f₂ x))
(hf₁ : ContDiffWithinAt 𝕜 n f₁ s x) (hf₂ : ContDiffWithinAt 𝕜 n f₂ s x) :
ContDiffWithinAt 𝕜 n (fun x => g (f₁ x, f₂ x)) s x :=
hg.comp_contDiffWithinAt x (hf₁.prodMk hf₂)
@[deprecated (since := "2024-10-30")]
alias ContDiffAt.comp_contDiffWithinAt₂ := ContDiffAt.comp₂_contDiffWithinAt
theorem ContDiff.comp₂_contDiffAt {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {x : F}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiffAt 𝕜 n f₁ x) (hf₂ : ContDiffAt 𝕜 n f₂ x) :
ContDiffAt 𝕜 n (fun x => g (f₁ x, f₂ x)) x :=
hg.contDiffAt.comp₂ hf₁ hf₂
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffAt₂ := ContDiff.comp₂_contDiffAt
theorem ContDiff.comp₂_contDiffWithinAt {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂}
{s : Set F} {x : F} (hg : ContDiff 𝕜 n g)
(hf₁ : ContDiffWithinAt 𝕜 n f₁ s x) (hf₂ : ContDiffWithinAt 𝕜 n f₂ s x) :
ContDiffWithinAt 𝕜 n (fun x => g (f₁ x, f₂ x)) s x :=
hg.contDiffAt.comp_contDiffWithinAt x (hf₁.prodMk hf₂)
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffWithinAt₂ := ContDiff.comp₂_contDiffWithinAt
theorem ContDiff.comp₂_contDiffOn {g : E₁ × E₂ → G} {f₁ : F → E₁} {f₂ : F → E₂} {s : Set F}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s) :
ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x)) s :=
hg.comp_contDiffOn <| hf₁.prodMk hf₂
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffOn₂ := ContDiff.comp₂_contDiffOn
theorem ContDiff.comp₃ {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃}
(hg : ContDiff 𝕜 n g) (hf₁ : ContDiff 𝕜 n f₁) (hf₂ : ContDiff 𝕜 n f₂) (hf₃ : ContDiff 𝕜 n f₃) :
ContDiff 𝕜 n fun x => g (f₁ x, f₂ x, f₃ x) :=
hg.comp₂ hf₁ <| hf₂.prodMk hf₃
theorem ContDiff.comp₃_contDiffOn {g : E₁ × E₂ × E₃ → G} {f₁ : F → E₁} {f₂ : F → E₂} {f₃ : F → E₃}
{s : Set F} (hg : ContDiff 𝕜 n g) (hf₁ : ContDiffOn 𝕜 n f₁ s) (hf₂ : ContDiffOn 𝕜 n f₂ s)
(hf₃ : ContDiffOn 𝕜 n f₃ s) : ContDiffOn 𝕜 n (fun x => g (f₁ x, f₂ x, f₃ x)) s :=
hg.comp₂_contDiffOn hf₁ <| hf₂.prodMk hf₃
@[deprecated (since := "2024-10-30")]
alias ContDiff.comp_contDiffOn₃ := ContDiff.comp₃_contDiffOn
end NAry
section SpecificBilinearMaps
theorem ContDiff.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} (hg : ContDiff 𝕜 n g)
(hf : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => (g x).comp (f x) :=
isBoundedBilinearMap_comp.contDiff.comp₂ (g := fun p => p.1.comp p.2) hg hf
theorem ContDiffOn.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X}
(hg : ContDiffOn 𝕜 n g s) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => (g x).comp (f x)) s :=
(isBoundedBilinearMap_comp (E := E) (F := F) (G := G)).contDiff.comp₂_contDiffOn hg hf
theorem ContDiffAt.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {x : X}
(hg : ContDiffAt 𝕜 n g x) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => (g x).comp (f x)) x :=
(isBoundedBilinearMap_comp (E := E) (G := G)).contDiff.comp₂_contDiffAt hg hf
theorem ContDiffWithinAt.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F} {s : Set X} {x : X}
(hg : ContDiffWithinAt 𝕜 n g s x) (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (fun x => (g x).comp (f x)) s x :=
(isBoundedBilinearMap_comp (E := E) (G := G)).contDiff.comp₂_contDiffWithinAt hg hf
theorem ContDiff.clm_apply {f : E → F →L[𝕜] G} {g : E → F} (hf : ContDiff 𝕜 n f)
(hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x) (g x) :=
isBoundedBilinearMap_apply.contDiff.comp₂ hf hg
theorem ContDiffOn.clm_apply {f : E → F →L[𝕜] G} {g : E → F} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x) (g x)) s :=
isBoundedBilinearMap_apply.contDiff.comp₂_contDiffOn hf hg
theorem ContDiffAt.clm_apply {f : E → F →L[𝕜] G} {g : E → F} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => (f x) (g x)) x :=
isBoundedBilinearMap_apply.contDiff.comp₂_contDiffAt hf hg
theorem ContDiffWithinAt.clm_apply {f : E → F →L[𝕜] G} {g : E → F}
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
ContDiffWithinAt 𝕜 n (fun x => (f x) (g x)) s x :=
isBoundedBilinearMap_apply.contDiff.comp₂_contDiffWithinAt hf hg
theorem ContDiff.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} (hf : ContDiff 𝕜 n f)
(hg : ContDiff 𝕜 n g) : ContDiff 𝕜 n fun x => (f x).smulRight (g x) :=
isBoundedBilinearMap_smulRight.contDiff.comp₂ (g := fun p => p.1.smulRight p.2) hf hg
theorem ContDiffOn.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} (hf : ContDiffOn 𝕜 n f s)
(hg : ContDiffOn 𝕜 n g s) : ContDiffOn 𝕜 n (fun x => (f x).smulRight (g x)) s :=
(isBoundedBilinearMap_smulRight (E := F)).contDiff.comp₂_contDiffOn hf hg
theorem ContDiffAt.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G} (hf : ContDiffAt 𝕜 n f x)
(hg : ContDiffAt 𝕜 n g x) : ContDiffAt 𝕜 n (fun x => (f x).smulRight (g x)) x :=
(isBoundedBilinearMap_smulRight (E := F)).contDiff.comp₂_contDiffAt hf hg
theorem ContDiffWithinAt.smulRight {f : E → F →L[𝕜] 𝕜} {g : E → G}
(hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) :
ContDiffWithinAt 𝕜 n (fun x => (f x).smulRight (g x)) s x :=
(isBoundedBilinearMap_smulRight (E := F)).contDiff.comp₂_contDiffWithinAt hf hg
end SpecificBilinearMaps
section ClmApplyConst
/-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDerivWithin`. -/
theorem iteratedFDerivWithin_clm_apply_const_apply
{s : Set E} (hs : UniqueDiffOn 𝕜 s) {c : E → F →L[𝕜] G}
(hc : ContDiffOn 𝕜 n c s) {i : ℕ} (hi : i ≤ n) {x : E} (hx : x ∈ s) {u : F} {m : Fin i → E} :
(iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s x) m = (iteratedFDerivWithin 𝕜 i c s x) m u := by
induction i generalizing x with
| zero => simp
| succ i ih =>
replace hi : (i : WithTop ℕ∞) < n := lt_of_lt_of_le (by norm_cast; simp) hi
have h_deriv_apply : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i (fun y ↦ (c y) u) s) s :=
(hc.clm_apply contDiffOn_const).differentiableOn_iteratedFDerivWithin hi hs
have h_deriv : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 i c s) s :=
hc.differentiableOn_iteratedFDerivWithin hi hs
simp only [iteratedFDerivWithin_succ_apply_left]
rw [← fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv_apply x hx)]
rw [fderivWithin_congr' (fun x hx ↦ ih hi.le hx) hx]
rw [fderivWithin_clm_apply (hs x hx) (h_deriv.continuousMultilinear_apply_const _ x hx)
(differentiableWithinAt_const u)]
rw [fderivWithin_const_apply]
simp only [ContinuousLinearMap.flip_apply, ContinuousLinearMap.comp_zero, zero_add]
rw [fderivWithin_continuousMultilinear_apply_const_apply (hs x hx) (h_deriv x hx)]
/-- Application of a `ContinuousLinearMap` to a constant commutes with `iteratedFDeriv`. -/
theorem iteratedFDeriv_clm_apply_const_apply
{c : E → F →L[𝕜] G} (hc : ContDiff 𝕜 n c)
{i : ℕ} (hi : i ≤ n) {x : E} {u : F} {m : Fin i → E} :
(iteratedFDeriv 𝕜 i (fun y ↦ (c y) u) x) m = (iteratedFDeriv 𝕜 i c x) m u := by
simp only [← iteratedFDerivWithin_univ]
exact iteratedFDerivWithin_clm_apply_const_apply uniqueDiffOn_univ hc.contDiffOn hi (mem_univ _)
end ClmApplyConst
/-- The natural equivalence `(E × F) × G ≃ E × (F × G)` is smooth.
Warning: if you think you need this lemma, it is likely that you can simplify your proof by
reformulating the lemma that you're applying next using the tips in
Note [continuity lemma statement]
-/
theorem contDiff_prodAssoc {n : WithTop ℕ∞} : ContDiff 𝕜 n <| Equiv.prodAssoc E F G :=
(LinearIsometryEquiv.prodAssoc 𝕜 E F G).contDiff
/-- The natural equivalence `E × (F × G) ≃ (E × F) × G` is smooth.
Warning: see remarks attached to `contDiff_prodAssoc`
-/
theorem contDiff_prodAssoc_symm {n : WithTop ℕ∞} : ContDiff 𝕜 n <| (Equiv.prodAssoc E F G).symm :=
(LinearIsometryEquiv.prodAssoc 𝕜 E F G).symm.contDiff
/-! ### Bundled derivatives are smooth -/
section bundled
/-- One direction of `contDiffWithinAt_succ_iff_hasFDerivWithinAt`, but where all derivatives are
taken within the same set. Version for partial derivatives / functions with parameters. If `f x` is
a `C^n+1` family of functions and `g x` is a `C^n` family of points, then the derivative of `f x` at
`g x` depends in a `C^n` way on `x`. We give a general version of this fact relative to sets which
may not have unique derivatives, in the following form. If `f : E × F → G` is `C^n+1` at
`(x₀, g(x₀))` in `(s ∪ {x₀}) × t ⊆ E × F` and `g : E → F` is `C^n` at `x₀` within some set `s ⊆ E`,
then there is a function `f' : E → F →L[𝕜] G` that is `C^n` at `x₀` within `s` such that for all `x`
sufficiently close to `x₀` within `s ∪ {x₀}` the function `y ↦ f x y` has derivative `f' x` at `g x`
within `t ⊆ F`. For convenience, we return an explicit set of `x`'s where this holds that is a
subset of `s ∪ {x₀}`. We need one additional condition, namely that `t` is a neighborhood of
`g(x₀)` within `g '' s`. -/
theorem ContDiffWithinAt.hasFDerivWithinAt_nhds {f : E → F → G} {g : E → F} {t : Set F} (hn : n ≠ ∞)
{x₀ : E} (hf : ContDiffWithinAt 𝕜 (n + 1) (uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 n g s x₀) (hgt : t ∈ 𝓝[g '' s] g x₀) :
∃ v ∈ 𝓝[insert x₀ s] x₀, v ⊆ insert x₀ s ∧ ∃ f' : E → F →L[𝕜] G,
(∀ x ∈ v, HasFDerivWithinAt (f x) (f' x) t (g x)) ∧
ContDiffWithinAt 𝕜 n (fun x => f' x) s x₀ := by
have hst : insert x₀ s ×ˢ t ∈ 𝓝[(fun x => (x, g x)) '' s] (x₀, g x₀) := by
refine nhdsWithin_mono _ ?_ (nhdsWithin_prod self_mem_nhdsWithin hgt)
simp_rw [image_subset_iff, mk_preimage_prod, preimage_id', subset_inter_iff, subset_insert,
true_and, subset_preimage_image]
obtain ⟨v, hv, hvs, f_an, f', hvf', hf'⟩ :=
(contDiffWithinAt_succ_iff_hasFDerivWithinAt' hn).mp hf
refine
⟨(fun z => (z, g z)) ⁻¹' v ∩ insert x₀ s, ?_, inter_subset_right, fun z =>
(f' (z, g z)).comp (ContinuousLinearMap.inr 𝕜 E F), ?_, ?_⟩
· refine inter_mem ?_ self_mem_nhdsWithin
have := mem_of_mem_nhdsWithin (mem_insert _ _) hv
refine mem_nhdsWithin_insert.mpr ⟨this, ?_⟩
refine (continuousWithinAt_id.prodMk hg.continuousWithinAt).preimage_mem_nhdsWithin' ?_
rw [← nhdsWithin_le_iff] at hst hv ⊢
exact (hst.trans <| nhdsWithin_mono _ <| subset_insert _ _).trans hv
· intro z hz
have := hvf' (z, g z) hz.1
refine this.comp _ (hasFDerivAt_prodMk_right _ _).hasFDerivWithinAt ?_
exact mapsTo'.mpr (image_prodMk_subset_prod_right hz.2)
· exact (hf'.continuousLinearMap_comp <| (ContinuousLinearMap.compL 𝕜 F (E × F) G).flip
(ContinuousLinearMap.inr 𝕜 E F)).comp_of_mem_nhdsWithin_image x₀
(contDiffWithinAt_id.prodMk hg) hst
/-- The most general lemma stating that `x ↦ fderivWithin 𝕜 (f x) t (g x)` is `C^n`
at a point within a set.
To show that `x ↦ D_yf(x,y)g(x)` (taken within `t`) is `C^m` at `x₀` within `s`, we require that
* `f` is `C^n` at `(x₀, g(x₀))` within `(s ∪ {x₀}) × t` for `n ≥ m+1`.
* `g` is `C^m` at `x₀` within `s`;
* Derivatives are unique at `g(x)` within `t` for `x` sufficiently close to `x₀` within `s ∪ {x₀}`;
* `t` is a neighborhood of `g(x₀)` within `g '' s`; -/
theorem ContDiffWithinAt.fderivWithin'' {f : E → F → G} {g : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀)
(ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n)
(hgt : t ∈ 𝓝[g '' s] g x₀) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
have : ∀ k : ℕ, k ≤ m → ContDiffWithinAt 𝕜 k (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
intro k hkm
obtain ⟨v, hv, -, f', hvf', hf'⟩ :=
(hf.of_le <| (add_le_add_right hkm 1).trans hmn).hasFDerivWithinAt_nhds (by simp)
(hg.of_le hkm) hgt
refine hf'.congr_of_eventuallyEq_insert ?_
filter_upwards [hv, ht]
exact fun y hy h2y => (hvf' y hy).fderivWithin h2y
match m with
| ω =>
obtain rfl : n = ω := by simpa using hmn
obtain ⟨v, hv, -, f', hvf', hf'⟩ := hf.hasFDerivWithinAt_nhds (by simp) hg hgt
refine hf'.congr_of_eventuallyEq_insert ?_
filter_upwards [hv, ht]
exact fun y hy h2y => (hvf' y hy).fderivWithin h2y
| ∞ =>
rw [contDiffWithinAt_infty]
exact fun k ↦ this k (by exact_mod_cast le_top)
| (m : ℕ) => exact this _ le_rfl
/-- A special case of `ContDiffWithinAt.fderivWithin''` where we require that `s ⊆ g⁻¹(t)`. -/
theorem ContDiffWithinAt.fderivWithin' {f : E → F → G} {g : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (insert x₀ s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀)
(ht : ∀ᶠ x in 𝓝[insert x₀ s] x₀, UniqueDiffWithinAt 𝕜 t (g x)) (hmn : m + 1 ≤ n)
(hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ :=
hf.fderivWithin'' hg ht hmn <| mem_of_superset self_mem_nhdsWithin <| image_subset_iff.mpr hst
/-- A special case of `ContDiffWithinAt.fderivWithin'` where we require that `x₀ ∈ s` and there
are unique derivatives everywhere within `t`. -/
protected theorem ContDiffWithinAt.fderivWithin {f : E → F → G} {g : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀) (ht : UniqueDiffOn 𝕜 t) (hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s)
(hst : s ⊆ g ⁻¹' t) : ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x)) s x₀ := by
rw [← insert_eq_self.mpr hx₀] at hf
refine hf.fderivWithin' hg ?_ hmn hst
rw [insert_eq_self.mpr hx₀]
exact eventually_of_mem self_mem_nhdsWithin fun x hx => ht _ (hst hx)
/-- `x ↦ fderivWithin 𝕜 (f x) t (g x) (k x)` is smooth at a point within a set. -/
theorem ContDiffWithinAt.fderivWithin_apply {f : E → F → G} {g k : E → F} {t : Set F}
(hf : ContDiffWithinAt 𝕜 n (Function.uncurry f) (s ×ˢ t) (x₀, g x₀))
(hg : ContDiffWithinAt 𝕜 m g s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀) (ht : UniqueDiffOn 𝕜 t)
(hmn : m + 1 ≤ n) (hx₀ : x₀ ∈ s) (hst : s ⊆ g ⁻¹' t) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 (f x) t (g x) (k x)) s x₀ :=
(contDiff_fst.clm_apply contDiff_snd).contDiffAt.comp_contDiffWithinAt x₀
((hf.fderivWithin hg ht hmn hx₀ hst).prodMk hk)
/-- `fderivWithin 𝕜 f s` is smooth at `x₀` within `s`. -/
theorem ContDiffWithinAt.fderivWithin_right (hf : ContDiffWithinAt 𝕜 n f s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (fderivWithin 𝕜 f s) s x₀ :=
ContDiffWithinAt.fderivWithin
(ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s)
contDiffWithinAt_id hs hmn hx₀s (by rw [preimage_id'])
/-- `x ↦ fderivWithin 𝕜 f s x (k x)` is smooth at `x₀` within `s`. -/
theorem ContDiffWithinAt.fderivWithin_right_apply
{f : F → G} {k : F → F} {s : Set F} {x₀ : F}
(hf : ContDiffWithinAt 𝕜 n f s x₀) (hk : ContDiffWithinAt 𝕜 m k s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (fun x => fderivWithin 𝕜 f s x (k x)) s x₀ :=
ContDiffWithinAt.fderivWithin_apply
(ContDiffWithinAt.comp (x₀, x₀) hf contDiffWithinAt_snd <| prod_subset_preimage_snd s s)
contDiffWithinAt_id hk hs hmn hx₀s (by rw [preimage_id'])
-- TODO: can we make a version of `ContDiffWithinAt.fderivWithin` for iterated derivatives?
theorem ContDiffWithinAt.iteratedFDerivWithin_right {i : ℕ} (hf : ContDiffWithinAt 𝕜 n f s x₀)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + i ≤ n) (hx₀s : x₀ ∈ s) :
ContDiffWithinAt 𝕜 m (iteratedFDerivWithin 𝕜 i f s) s x₀ := by
induction' i with i hi generalizing m
· simp only [CharP.cast_eq_zero, add_zero] at hmn
exact (hf.of_le hmn).continuousLinearMap_comp
((continuousMultilinearCurryFin0 𝕜 E F).symm : _ →L[𝕜] E [×0]→L[𝕜] F)
· rw [Nat.cast_succ, add_comm _ 1, ← add_assoc] at hmn
exact ((hi hmn).fderivWithin_right hs le_rfl hx₀s).continuousLinearMap_comp
((continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (i+1) ↦ E) F).symm :
_ →L[𝕜] E [×(i+1)]→L[𝕜] F)
@[deprecated (since := "2025-01-15")]
alias ContDiffWithinAt.iteratedFderivWithin_right := ContDiffWithinAt.iteratedFDerivWithin_right
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth at `x₀`. -/
protected theorem ContDiffAt.fderiv {f : E → F → G} {g : E → F}
(hf : ContDiffAt 𝕜 n (Function.uncurry f) (x₀, g x₀)) (hg : ContDiffAt 𝕜 m g x₀)
(hmn : m + 1 ≤ n) : ContDiffAt 𝕜 m (fun x => fderiv 𝕜 (f x) (g x)) x₀ := by
simp_rw [← fderivWithin_univ]
refine (ContDiffWithinAt.fderivWithin hf.contDiffWithinAt hg.contDiffWithinAt uniqueDiffOn_univ
hmn (mem_univ x₀) ?_).contDiffAt univ_mem
rw [preimage_univ]
/-- `fderiv 𝕜 f` is smooth at `x₀`. -/
theorem ContDiffAt.fderiv_right (hf : ContDiffAt 𝕜 n f x₀) (hmn : m + 1 ≤ n) :
ContDiffAt 𝕜 m (fderiv 𝕜 f) x₀ :=
ContDiffAt.fderiv (ContDiffAt.comp (x₀, x₀) hf contDiffAt_snd) contDiffAt_id hmn
theorem ContDiffAt.iteratedFDeriv_right {i : ℕ} (hf : ContDiffAt 𝕜 n f x₀)
(hmn : m + i ≤ n) : ContDiffAt 𝕜 m (iteratedFDeriv 𝕜 i f) x₀ := by
rw [← iteratedFDerivWithin_univ, ← contDiffWithinAt_univ] at *
exact hf.iteratedFDerivWithin_right uniqueDiffOn_univ hmn trivial
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is smooth. -/
protected theorem ContDiff.fderiv {f : E → F → G} {g : E → F}
(hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hnm : n + 1 ≤ m) :
ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) :=
contDiff_iff_contDiffAt.mpr fun _ => hf.contDiffAt.fderiv hg.contDiffAt hnm
/-- `fderiv 𝕜 f` is smooth. -/
theorem ContDiff.fderiv_right (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≤ n) :
ContDiff 𝕜 m (fderiv 𝕜 f) :=
contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.fderiv_right hmn
theorem ContDiff.iteratedFDeriv_right {i : ℕ} (hf : ContDiff 𝕜 n f)
(hmn : m + i ≤ n) : ContDiff 𝕜 m (iteratedFDeriv 𝕜 i f) :=
contDiff_iff_contDiffAt.mpr fun _x => hf.contDiffAt.iteratedFDeriv_right hmn
/-- `x ↦ fderiv 𝕜 (f x) (g x)` is continuous. -/
theorem Continuous.fderiv {f : E → F → G} {g : E → F}
(hf : ContDiff 𝕜 n <| Function.uncurry f) (hg : Continuous g) (hn : 1 ≤ n) :
Continuous fun x => fderiv 𝕜 (f x) (g x) :=
(hf.fderiv (contDiff_zero.mpr hg) hn).continuous
/-- `x ↦ fderiv 𝕜 (f x) (g x) (k x)` is smooth. -/
theorem ContDiff.fderiv_apply {f : E → F → G} {g k : E → F}
(hf : ContDiff 𝕜 m <| Function.uncurry f) (hg : ContDiff 𝕜 n g) (hk : ContDiff 𝕜 n k)
(hnm : n + 1 ≤ m) : ContDiff 𝕜 n fun x => fderiv 𝕜 (f x) (g x) (k x) :=
(hf.fderiv hg hnm).clm_apply hk
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
theorem contDiffOn_fderivWithin_apply {s : Set E} {f : E → F} (hf : ContDiffOn 𝕜 n f s)
(hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E →L[𝕜] F) p.2) (s ×ˢ univ) :=
((hf.fderivWithin hs hmn).comp contDiffOn_fst (prod_subset_preimage_fst _ _)).clm_apply
contDiffOn_snd
/-- If a function is at least `C^1`, its bundled derivative (mapping `(x, v)` to `Df(x) v`) is
continuous. -/
theorem ContDiffOn.continuousOn_fderivWithin_apply (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) :
ContinuousOn (fun p : E × E => (fderivWithin 𝕜 f s p.1 : E → F) p.2) (s ×ˢ univ) :=
(contDiffOn_fderivWithin_apply (m := 0) hf hs hn).continuousOn
/-- The bundled derivative of a `C^{n+1}` function is `C^n`. -/
theorem ContDiff.contDiff_fderiv_apply {f : E → F} (hf : ContDiff 𝕜 n f) (hmn : m + 1 ≤ n) :
ContDiff 𝕜 m fun p : E × E => (fderiv 𝕜 f p.1 : E →L[𝕜] F) p.2 := by
rw [← contDiffOn_univ] at hf ⊢
rw [← fderivWithin_univ, ← univ_prod_univ]
exact contDiffOn_fderivWithin_apply hf uniqueDiffOn_univ hmn
end bundled
section deriv
/-!
### One dimension
All results up to now have been expressed in terms of the general Fréchet derivative `fderiv`. For
maps defined on the field, the one-dimensional derivative `deriv` is often easier to use. In this
paragraph, we reformulate some higher smoothness results in terms of `deriv`.
-/
variable {f₂ : 𝕜 → F} {s₂ : Set 𝕜}
open ContinuousLinearMap (smulRight)
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (formulated with `derivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_derivWithin (hs : UniqueDiffOn 𝕜 s₂) :
ContDiffOn 𝕜 (n + 1) f₂ s₂ ↔
DifferentiableOn 𝕜 f₂ s₂ ∧ (n = ω → AnalyticOn 𝕜 f₂ s₂) ∧
ContDiffOn 𝕜 n (derivWithin f₂ s₂) s₂ := by
rw [contDiffOn_succ_iff_fderivWithin hs, and_congr_right_iff]
intro _
constructor
· rintro ⟨h', h⟩
refine ⟨h', ?_⟩
have : derivWithin f₂ s₂ = (fun u : 𝕜 →L[𝕜] F => u 1) ∘ fderivWithin 𝕜 f₂ s₂ := by
ext x; rfl
simp_rw [this]
apply ContDiff.comp_contDiffOn _ h
| exact (isBoundedBilinearMap_apply.isBoundedLinearMap_left _).contDiff
· rintro ⟨h', h⟩
refine ⟨h', ?_⟩
have : fderivWithin 𝕜 f₂ s₂ = smulRight (1 : 𝕜 →L[𝕜] 𝕜) ∘ derivWithin f₂ s₂ := by
| Mathlib/Analysis/Calculus/ContDiff/Basic.lean | 1,262 | 1,265 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.Data.Finset.Sym
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.LinearAlgebra.Matrix.Symmetric
/-!
# Quadratic maps
This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`.
An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such
that:
* `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x`
* `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`,
`QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`:
the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear.
This notion generalizes to commutative semirings using the approach in [izhakian2016][] which
requires that there be a (possibly non-unique) companion bilinear map `B` such that
`∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`.
To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`.
Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `QuadraticMap.ofPolar`: a more familiar constructor that works on rings
* `QuadraticMap.associated`: associated bilinear map
* `QuadraticMap.PosDef`: positive definite quadratic maps
* `QuadraticMap.Anisotropic`: anisotropic quadratic maps
* `QuadraticMap.discr`: discriminant of a quadratic map
* `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map.
## Main statements
* `QuadraticMap.associated_left_inverse`,
* `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic maps and symmetric
bilinear forms
* `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear map `B`.
## Notation
In this file, the variable `R` is used when a `CommSemiring` structure is available.
The variable `S` is used when `R` itself has a `•` action.
## Implementation notes
While the definition and many results make sense if we drop commutativity assumptions,
the correct definition of a quadratic maps in the noncommutative setting would require
substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some
suitable conjugation $r^*$.
The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867)
has some further discussion.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic map, homogeneous polynomial, quadratic polynomial
-/
universe u v w
variable {S T : Type*}
variable {R : Type*} {M N P A : Type*}
open LinearMap (BilinMap BilinForm)
section Polar
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
namespace QuadraticMap
/-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`.
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → N) (x y : M) :=
f (x + y) - f x - f y
protected theorem map_add (f : M → N) (x y : M) :
f (x + y) = f x + f y + polar f x y := by
rw [polar]
abel
| theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
| Mathlib/LinearAlgebra/QuadraticForm/Basic.lean | 103 | 104 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Algebra.NeZero
import Mathlib.Data.Finset.Attach
import Mathlib.Data.Finset.Disjoint
import Mathlib.Data.Finset.Erase
import Mathlib.Data.Finset.Filter
import Mathlib.Data.Finset.Range
import Mathlib.Data.Finset.SDiff
/-! # Image and map operations on finite sets
This file provides the finite analog of `Set.image`, along with some other similar functions.
Note there are two ways to take the image over a finset; via `Finset.image` which applies the
function then removes duplicates (requiring `DecidableEq`), or via `Finset.map` which exploits
injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to
choosing between `insert` and `Finset.cons`, or between `Finset.union` and `Finset.disjUnion`.
## Main definitions
* `Finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`.
* `Finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`.
* `Finset.filterMap` Given a function `f : α → Option β`, `s.filterMap f` is the
image finset in `β`, filtering out `none`s.
* `Finset.subtype`: `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`.
* `Finset.fin`:`s.fin n` is the finset of all elements of `s` less than `n`.
-/
assert_not_exists Monoid OrderedCommMonoid
variable {α β γ : Type*}
open Multiset
open Function
namespace Finset
/-! ### map -/
section Map
open Function
/-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image
finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/
def map (f : α ↪ β) (s : Finset α) : Finset β :=
⟨s.1.map f, s.2.map f.2⟩
@[simp]
theorem map_val (f : α ↪ β) (s : Finset α) : (map f s).1 = s.1.map f :=
rfl
@[simp]
theorem map_empty (f : α ↪ β) : (∅ : Finset α).map f = ∅ :=
rfl
variable {f : α ↪ β} {s : Finset α}
@[simp]
theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b :=
Multiset.mem_map
-- Higher priority to apply before `mem_map`.
@[simp 1100]
theorem mem_map_equiv {f : α ≃ β} {b : β} : b ∈ s.map f.toEmbedding ↔ f.symm b ∈ s := by
rw [mem_map]
exact
⟨by
rintro ⟨a, H, rfl⟩
simpa, fun h => ⟨_, h, by simp⟩⟩
@[simp 1100]
theorem mem_map' (f : α ↪ β) {a} {s : Finset α} : f a ∈ s.map f ↔ a ∈ s :=
mem_map_of_injective f.2
theorem mem_map_of_mem (f : α ↪ β) {a} {s : Finset α} : a ∈ s → f a ∈ s.map f :=
(mem_map' _).2
theorem forall_mem_map {f : α ↪ β} {s : Finset α} {p : ∀ a, a ∈ s.map f → Prop} :
(∀ y (H : y ∈ s.map f), p y H) ↔ ∀ x (H : x ∈ s), p (f x) (mem_map_of_mem _ H) :=
⟨fun h y hy => h (f y) (mem_map_of_mem _ hy),
fun h x hx => by
obtain ⟨y, hy, rfl⟩ := mem_map.1 hx
exact h _ hy⟩
theorem apply_coe_mem_map (f : α ↪ β) (s : Finset α) (x : s) : f x ∈ s.map f :=
mem_map_of_mem f x.prop
@[simp, norm_cast]
theorem coe_map (f : α ↪ β) (s : Finset α) : (s.map f : Set β) = f '' s :=
Set.ext (by simp only [mem_coe, mem_map, Set.mem_image, implies_true])
theorem coe_map_subset_range (f : α ↪ β) (s : Finset α) : (s.map f : Set β) ⊆ Set.range f :=
calc
↑(s.map f) = f '' s := coe_map f s
_ ⊆ Set.range f := Set.image_subset_range f ↑s
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem map_perm {σ : Equiv.Perm α} (hs : { a | σ a ≠ a } ⊆ s) : s.map (σ : α ↪ α) = s :=
coe_injective <| (coe_map _ _).trans <| Set.image_perm hs
theorem map_toFinset [DecidableEq α] [DecidableEq β] {s : Multiset α} :
s.toFinset.map f = (s.map f).toFinset :=
ext fun _ => by simp only [mem_map, Multiset.mem_map, exists_prop, Multiset.mem_toFinset]
@[simp]
theorem map_refl : s.map (Embedding.refl _) = s :=
ext fun _ => by simpa only [mem_map, exists_prop] using exists_eq_right
@[simp]
theorem map_cast_heq {α β} (h : α = β) (s : Finset α) :
HEq (s.map (Equiv.cast h).toEmbedding) s := by
subst h
simp
theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : Finset α) : (s.map f).map g = s.map (f.trans g) :=
eq_of_veq <| by simp only [map_val, Multiset.map_map]; rfl
theorem map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.map g).map f = (s.map f').map g' := by
simp_rw [map_map, Embedding.trans, Function.comp_def, h_comm]
theorem _root_.Function.Semiconj.finset_map {f : α ↪ β} {ga : α ↪ α} {gb : β ↪ β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := fun _ =>
map_comm h
theorem _root_.Function.Commute.finset_map {f g : α ↪ α} (h : Function.Commute f g) :
Function.Commute (map f) (map g) :=
Function.Semiconj.finset_map h
@[simp]
theorem map_subset_map {s₁ s₂ : Finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ :=
⟨fun h _ xs => (mem_map' _).1 <| h <| (mem_map' f).2 xs,
fun h => by simp [subset_def, Multiset.map_subset_map h]⟩
@[gcongr] alias ⟨_, _root_.GCongr.finsetMap_subset⟩ := map_subset_map
/-- The `Finset` version of `Equiv.subset_symm_image`. -/
theorem subset_map_symm {t : Finset β} {f : α ≃ β} : s ⊆ t.map f.symm ↔ s.map f ⊆ t := by
constructor <;> intro h x hx
· simp only [mem_map_equiv, Equiv.symm_symm] at hx
simpa using h hx
· simp only [mem_map_equiv]
exact h (by simp [hx])
/-- The `Finset` version of `Equiv.symm_image_subset`. -/
theorem map_symm_subset {t : Finset β} {f : α ≃ β} : t.map f.symm ⊆ s ↔ t ⊆ s.map f := by
simp only [← subset_map_symm, Equiv.symm_symm]
/-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a finset to its
image under `f`. -/
def mapEmbedding (f : α ↪ β) : Finset α ↪o Finset β :=
OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_subset_map
@[simp]
theorem map_inj {s₁ s₂ : Finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ :=
(mapEmbedding f).injective.eq_iff
theorem map_injective (f : α ↪ β) : Injective (map f) :=
(mapEmbedding f).injective
@[simp]
theorem map_ssubset_map {s t : Finset α} : s.map f ⊂ t.map f ↔ s ⊂ t := (mapEmbedding f).lt_iff_lt
@[gcongr] alias ⟨_, _root_.GCongr.finsetMap_ssubset⟩ := map_ssubset_map
@[simp]
theorem mapEmbedding_apply : mapEmbedding f s = map f s :=
rfl
theorem filter_map {p : β → Prop} [DecidablePred p] :
(s.map f).filter p = (s.filter (p ∘ f)).map f :=
eq_of_veq (Multiset.filter_map _ _ _)
lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α)
[DecidablePred (∃ a, p a ∧ f a = ·)] :
(s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [Function.comp_def, filter_map, f.injective.eq_iff]
lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] :
s.attach.filter p =
(s.filter fun x => ∃ h, p ⟨x, h⟩).attach.map
⟨Subtype.map id <| filter_subset _ _, Subtype.map_injective _ injective_id⟩ :=
eq_of_veq <| Multiset.filter_attach' _ _
lemma filter_attach (p : α → Prop) [DecidablePred p] (s : Finset α) :
s.attach.filter (fun a : s ↦ p a) =
(s.filter p).attach.map ((Embedding.refl _).subtypeMap mem_of_mem_filter) :=
eq_of_veq <| Multiset.filter_attach _ _
theorem map_filter {f : α ≃ β} {p : α → Prop} [DecidablePred p] :
(s.filter p).map f.toEmbedding = (s.map f.toEmbedding).filter (p ∘ f.symm) := by
simp only [filter_map, Function.comp_def, Equiv.toEmbedding_apply, Equiv.symm_apply_apply]
@[simp]
theorem disjoint_map {s t : Finset α} (f : α ↪ β) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
mod_cast Set.disjoint_image_iff f.injective (s := s) (t := t)
theorem map_disjUnion {f : α ↪ β} (s₁ s₂ : Finset α) (h) (h' := (disjoint_map _).mpr h) :
(s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' :=
eq_of_veq <| Multiset.map_add _ _ _
/-- A version of `Finset.map_disjUnion` for writing in the other direction. -/
theorem map_disjUnion' {f : α ↪ β} (s₁ s₂ : Finset α) (h') (h := (disjoint_map _).mp h') :
(s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' :=
map_disjUnion _ _ _
theorem map_union [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) :
(s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f :=
mod_cast Set.image_union f s₁ s₂
theorem map_inter [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) :
(s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f :=
mod_cast Set.image_inter f.injective (s := s₁) (t := s₂)
@[simp]
theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} :=
coe_injective <| by simp only [coe_map, coe_singleton, Set.image_singleton]
@[simp]
theorem map_insert [DecidableEq α] [DecidableEq β] (f : α ↪ β) (a : α) (s : Finset α) :
(insert a s).map f = insert (f a) (s.map f) := by
simp only [insert_eq, map_union, map_singleton]
@[simp]
theorem map_cons (f : α ↪ β) (a : α) (s : Finset α) (ha : a ∉ s) :
(cons a s ha).map f = cons (f a) (s.map f) (by simpa using ha) :=
eq_of_veq <| Multiset.map_cons f a s.val
@[simp]
theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := (map_injective f).eq_iff' (map_empty f)
@[simp]
theorem map_nonempty : (s.map f).Nonempty ↔ s.Nonempty :=
mod_cast Set.image_nonempty (f := f) (s := s)
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Nonempty.map⟩ := map_nonempty
@[simp]
theorem map_nontrivial : (s.map f).Nontrivial ↔ s.Nontrivial :=
mod_cast Set.image_nontrivial f.injective (s := s)
theorem attach_map_val {s : Finset α} : s.attach.map (Embedding.subtype _) = s :=
eq_of_veq <| by rw [map_val, attach_val]; exact Multiset.attach_map_val _
end Map
theorem range_add_one' (n : ℕ) :
range (n + 1) = insert 0 ((range n).map ⟨fun i => i + 1, fun i j => by simp⟩) := by
ext (⟨⟩ | ⟨n⟩) <;> simp [Nat.zero_lt_succ n]
/-! ### image -/
section Image
variable [DecidableEq β]
/-- `image f s` is the forward image of `s` under `f`. -/
def image (f : α → β) (s : Finset α) : Finset β :=
(s.1.map f).toFinset
@[simp]
theorem image_val (f : α → β) (s : Finset α) : (image f s).1 = (s.1.map f).dedup :=
rfl
@[simp]
theorem image_empty (f : α → β) : (∅ : Finset α).image f = ∅ :=
rfl
variable {f g : α → β} {s : Finset α} {t : Finset β} {a : α} {b c : β}
@[simp]
theorem mem_image : b ∈ s.image f ↔ ∃ a ∈ s, f a = b := by
simp only [mem_def, image_val, mem_dedup, Multiset.mem_map, exists_prop]
theorem mem_image_of_mem (f : α → β) {a} (h : a ∈ s) : f a ∈ s.image f :=
mem_image.2 ⟨_, h, rfl⟩
lemma forall_mem_image {p : β → Prop} : (∀ y ∈ s.image f, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp
lemma exists_mem_image {p : β → Prop} : (∃ y ∈ s.image f, p y) ↔ ∃ x ∈ s, p (f x) := by simp
@[deprecated (since := "2024-11-23")] alias forall_image := forall_mem_image
theorem map_eq_image (f : α ↪ β) (s : Finset α) : s.map f = s.image f :=
eq_of_veq (s.map f).2.dedup.symm
-- Not `@[simp]` since `mem_image` already gets most of the way there.
theorem mem_image_const : c ∈ s.image (const α b) ↔ s.Nonempty ∧ b = c := by
rw [mem_image]
simp only [exists_prop, const_apply, exists_and_right]
rfl
theorem mem_image_const_self : b ∈ s.image (const α b) ↔ s.Nonempty :=
mem_image_const.trans <| and_iff_left rfl
instance canLift (c) (p) [CanLift β α c p] :
CanLift (Finset β) (Finset α) (image c) fun s => ∀ x ∈ s, p x where
prf := by
rintro ⟨⟨l⟩, hd : l.Nodup⟩ hl
lift l to List α using hl
exact ⟨⟨l, hd.of_map _⟩, ext fun a => by simp⟩
theorem image_congr (h : (s : Set α).EqOn f g) : Finset.image f s = Finset.image g s := by
ext
simp_rw [mem_image, ← bex_def]
exact exists₂_congr fun x hx => by rw [h hx]
theorem _root_.Function.Injective.mem_finset_image (hf : Injective f) :
f a ∈ s.image f ↔ a ∈ s := by
refine ⟨fun h => ?_, Finset.mem_image_of_mem f⟩
obtain ⟨y, hy, heq⟩ := mem_image.1 h
exact hf heq ▸ hy
@[simp, norm_cast]
theorem coe_image : ↑(s.image f) = f '' ↑s :=
Set.ext <| by simp only [mem_coe, mem_image, Set.mem_image, implies_true]
@[simp]
lemma image_nonempty : (s.image f).Nonempty ↔ s.Nonempty :=
mod_cast Set.image_nonempty (f := f) (s := (s : Set α))
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.image (h : s.Nonempty) (f : α → β) : (s.image f).Nonempty :=
image_nonempty.2 h
alias ⟨Nonempty.of_image, _⟩ := image_nonempty
theorem image_toFinset [DecidableEq α] {s : Multiset α} :
s.toFinset.image f = (s.map f).toFinset :=
ext fun _ => by simp only [mem_image, Multiset.mem_toFinset, exists_prop, Multiset.mem_map]
theorem image_val_of_injOn (H : Set.InjOn f s) : (image f s).1 = s.1.map f :=
(s.2.map_on H).dedup
@[simp]
theorem image_id [DecidableEq α] : s.image id = s :=
ext fun _ => by simp only [mem_image, exists_prop, id, exists_eq_right]
@[simp]
theorem image_id' [DecidableEq α] : (s.image fun x => x) = s :=
image_id
theorem image_image [DecidableEq γ] {g : β → γ} : (s.image f).image g = s.image (g ∘ f) :=
eq_of_veq <| by simp only [image_val, dedup_map_dedup_eq, Multiset.map_map]
theorem image_comm {β'} [DecidableEq β'] [DecidableEq γ] {f : β → γ} {g : α → β} {f' : α → β'}
{g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) :
(s.image g).image f = (s.image f').image g' := by simp_rw [image_image, comp_def, h_comm]
theorem _root_.Function.Semiconj.finset_image [DecidableEq α] {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
theorem _root_.Function.Commute.finset_image [DecidableEq α] {f g : α → α}
(h : Function.Commute f g) : Function.Commute (image f) (image g) :=
Function.Semiconj.finset_image h
theorem image_subset_image {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁.image f ⊆ s₂.image f := by
simp only [subset_def, image_val, subset_dedup', dedup_subset', Multiset.map_subset_map h]
theorem image_subset_iff : s.image f ⊆ t ↔ ∀ x ∈ s, f x ∈ t :=
calc
s.image f ⊆ t ↔ f '' ↑s ⊆ ↑t := by norm_cast
_ ↔ _ := Set.image_subset_iff
theorem image_mono (f : α → β) : Monotone (Finset.image f) := fun _ _ => image_subset_image
lemma image_injective (hf : Injective f) : Injective (image f) := by
simpa only [funext (map_eq_image _)] using map_injective ⟨f, hf⟩
lemma image_inj {t : Finset α} (hf : Injective f) : s.image f = t.image f ↔ s = t :=
(image_injective hf).eq_iff
theorem image_subset_image_iff {t : Finset α} (hf : Injective f) :
s.image f ⊆ t.image f ↔ s ⊆ t :=
mod_cast Set.image_subset_image_iff hf (s := s) (t := t)
lemma image_ssubset_image {t : Finset α} (hf : Injective f) : s.image f ⊂ t.image f ↔ s ⊂ t := by
simp_rw [← lt_iff_ssubset]
exact lt_iff_lt_of_le_iff_le' (image_subset_image_iff hf) (image_subset_image_iff hf)
theorem coe_image_subset_range : ↑(s.image f) ⊆ Set.range f :=
calc
↑(s.image f) = f '' ↑s := coe_image
_ ⊆ Set.range f := Set.image_subset_range f ↑s
theorem filter_image {p : β → Prop} [DecidablePred p] :
(s.image f).filter p = (s.filter fun a ↦ p (f a)).image f :=
ext fun b => by
simp only [mem_filter, mem_image, exists_prop]
exact
⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, ⟨h1, h2⟩, rfl⟩,
by rintro ⟨x, ⟨h1, h2⟩, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩
theorem fiber_nonempty_iff_mem_image {y : β} : (s.filter (f · = y)).Nonempty ↔ y ∈ s.image f := by
simp [Finset.Nonempty]
theorem image_union [DecidableEq α] {f : α → β} (s₁ s₂ : Finset α) :
(s₁ ∪ s₂).image f = s₁.image f ∪ s₂.image f :=
mod_cast Set.image_union f s₁ s₂
theorem image_inter_subset [DecidableEq α] (f : α → β) (s t : Finset α) :
(s ∩ t).image f ⊆ s.image f ∩ t.image f :=
(image_mono f).map_inf_le s t
theorem image_inter_of_injOn [DecidableEq α] {f : α → β} (s t : Finset α)
(hf : Set.InjOn f (s ∪ t)) : (s ∩ t).image f = s.image f ∩ t.image f :=
coe_injective <| by
push_cast
exact Set.image_inter_on fun a ha b hb => hf (Or.inr ha) <| Or.inl hb
theorem image_inter [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective f) :
(s₁ ∩ s₂).image f = s₁.image f ∩ s₂.image f :=
image_inter_of_injOn _ _ hf.injOn
@[simp]
theorem image_singleton (f : α → β) (a : α) : image f {a} = {f a} :=
ext fun x => by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm
@[simp]
theorem image_insert [DecidableEq α] (f : α → β) (a : α) (s : Finset α) :
(insert a s).image f = insert (f a) (s.image f) := by
simp only [insert_eq, image_singleton, image_union]
theorem erase_image_subset_image_erase [DecidableEq α] (f : α → β) (s : Finset α) (a : α) :
(s.image f).erase (f a) ⊆ (s.erase a).image f := by
simp only [subset_iff, and_imp, exists_prop, mem_image, exists_imp, mem_erase]
rintro b hb x hx rfl
exact ⟨_, ⟨ne_of_apply_ne f hb, hx⟩, rfl⟩
@[simp]
theorem image_erase [DecidableEq α] {f : α → β} (hf : Injective f) (s : Finset α) (a : α) :
(s.erase a).image f = (s.image f).erase (f a) :=
coe_injective <| by push_cast [Set.image_diff hf, Set.image_singleton]; rfl
@[simp]
theorem image_eq_empty : s.image f = ∅ ↔ s = ∅ := mod_cast Set.image_eq_empty (f := f) (s := s)
theorem image_sdiff [DecidableEq α] {f : α → β} (s t : Finset α) (hf : Injective f) :
(s \ t).image f = s.image f \ t.image f :=
mod_cast Set.image_diff hf s t
lemma image_sdiff_of_injOn [DecidableEq α] {t : Finset α} (hf : Set.InjOn f s) (hts : t ⊆ s) :
(s \ t).image f = s.image f \ t.image f :=
mod_cast Set.image_diff_of_injOn hf <| coe_subset.2 hts
theorem _root_.Disjoint.of_image_finset {s t : Finset α} {f : α → β}
(h : Disjoint (s.image f) (t.image f)) : Disjoint s t :=
disjoint_iff_ne.2 fun _ ha _ hb =>
ne_of_apply_ne f <| h.forall_ne_finset (mem_image_of_mem _ ha) (mem_image_of_mem _ hb)
theorem mem_range_iff_mem_finset_range_of_mod_eq' [DecidableEq α] {f : ℕ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀ i, f (i % n) = f i) :
a ∈ Set.range f ↔ a ∈ (Finset.range n).image fun i => f i := by
constructor
· rintro ⟨i, hi⟩
simp only [mem_image, exists_prop, mem_range]
exact ⟨i % n, Nat.mod_lt i hn, (rfl.congr hi).mp (h i)⟩
· rintro h
simp only [mem_image, exists_prop, Set.mem_range, mem_range] at *
rcases h with ⟨i, _, ha⟩
exact ⟨i, ha⟩
theorem mem_range_iff_mem_finset_range_of_mod_eq [DecidableEq α] {f : ℤ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀ i, f (i % n) = f i) :
a ∈ Set.range f ↔ a ∈ (Finset.range n).image (fun (i : ℕ) => f i) :=
suffices (∃ i, f (i % n) = a) ↔ ∃ i, i < n ∧ f ↑i = a by simpa [h]
have hn' : 0 < (n : ℤ) := Int.ofNat_lt.mpr hn
Iff.intro
(fun ⟨i, hi⟩ =>
have : 0 ≤ i % ↑n := Int.emod_nonneg _ (ne_of_gt hn')
⟨Int.toNat (i % n), by
rw [← Int.ofNat_lt, Int.toNat_of_nonneg this]; exact ⟨Int.emod_lt_of_pos i hn', hi⟩⟩)
fun ⟨i, hi, ha⟩ =>
⟨i, by rw [Int.emod_eq_of_lt (Int.ofNat_zero_le _) (Int.ofNat_lt_ofNat_of_lt hi), ha]⟩
@[simp]
theorem attach_image_val [DecidableEq α] {s : Finset α} : s.attach.image Subtype.val = s :=
eq_of_veq <| by rw [image_val, attach_val, Multiset.attach_map_val, dedup_eq_self]
@[simp]
theorem attach_insert [DecidableEq α] {a : α} {s : Finset α} :
attach (insert a s) =
insert (⟨a, mem_insert_self a s⟩ : { x // x ∈ insert a s })
((attach s).image fun x => ⟨x.1, mem_insert_of_mem x.2⟩) :=
ext fun ⟨x, hx⟩ =>
⟨Or.casesOn (mem_insert.1 hx)
(fun h : x = a => fun _ => mem_insert.2 <| Or.inl <| Subtype.eq h) fun h : x ∈ s => fun _ =>
mem_insert_of_mem <| mem_image.2 <| ⟨⟨x, h⟩, mem_attach _ _, Subtype.eq rfl⟩,
fun _ => Finset.mem_attach _ _⟩
@[simp]
theorem disjoint_image {s t : Finset α} {f : α → β} (hf : Injective f) :
Disjoint (s.image f) (t.image f) ↔ Disjoint s t :=
mod_cast Set.disjoint_image_iff hf (s := s) (t := t)
theorem image_const {s : Finset α} (h : s.Nonempty) (b : β) : (s.image fun _ => b) = singleton b :=
mod_cast Set.Nonempty.image_const (coe_nonempty.2 h) b
@[simp]
theorem map_erase [DecidableEq α] (f : α ↪ β) (s : Finset α) (a : α) :
(s.erase a).map f = (s.map f).erase (f a) := by
simp_rw [map_eq_image]
exact s.image_erase f.2 a
end Image
/-! ### filterMap -/
section FilterMap
/-- `filterMap f s` is a combination filter/map operation on `s`.
The function `f : α → Option β` is applied to each element of `s`;
if `f a` is `some b` then `b` is included in the result, otherwise
`a` is excluded from the resulting finset.
In notation, `filterMap f s` is the finset `{b : β | ∃ a ∈ s , f a = some b}`. -/
-- TODO: should there be `filterImage` too?
def filterMap (f : α → Option β) (s : Finset α)
(f_inj : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') : Finset β :=
⟨s.val.filterMap f, s.nodup.filterMap f f_inj⟩
variable (f : α → Option β) (s' : Finset α) {s t : Finset α}
{f_inj : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a'}
@[simp]
theorem filterMap_val : (filterMap f s' f_inj).1 = s'.1.filterMap f := rfl
@[simp]
theorem filterMap_empty : (∅ : Finset α).filterMap f f_inj = ∅ := rfl
@[simp]
theorem mem_filterMap {b : β} : b ∈ s.filterMap f f_inj ↔ ∃ a ∈ s, f a = some b :=
s.val.mem_filterMap f
@[simp, norm_cast]
theorem coe_filterMap : (s.filterMap f f_inj : Set β) = {b | ∃ a ∈ s, f a = some b} :=
Set.ext (by simp only [mem_coe, mem_filterMap, Option.mem_def, Set.mem_setOf_eq, implies_true])
@[simp]
theorem filterMap_some : s.filterMap some (by simp) = s :=
ext fun _ => by simp only [mem_filterMap, Option.some.injEq, exists_eq_right]
theorem filterMap_mono (h : s ⊆ t) :
filterMap f s f_inj ⊆ filterMap f t f_inj := by
rw [← val_le_iff] at h ⊢
exact Multiset.filterMap_le_filterMap f h
@[simp]
theorem _root_.List.toFinset_filterMap [DecidableEq α] [DecidableEq β] (s : List α) :
(s.filterMap f).toFinset = s.toFinset.filterMap f f_inj := by
simp [← Finset.coe_inj]
end FilterMap
/-! ### Subtype -/
section Subtype
/-- Given a finset `s` and a predicate `p`, `s.subtype p` is the finset of `Subtype p` whose
elements belong to `s`. -/
protected def subtype {α} (p : α → Prop) [DecidablePred p] (s : Finset α) : Finset (Subtype p) :=
(s.filter p).attach.map
⟨fun x => ⟨x.1, by simpa using (Finset.mem_filter.1 x.2).2⟩,
fun _ _ H => Subtype.eq <| Subtype.mk.inj H⟩
@[simp]
theorem mem_subtype {p : α → Prop} [DecidablePred p] {s : Finset α} :
∀ {a : Subtype p}, a ∈ s.subtype p ↔ (a : α) ∈ s
| ⟨a, ha⟩ => by simp [Finset.subtype, ha]
theorem subtype_eq_empty {p : α → Prop} [DecidablePred p] {s : Finset α} :
s.subtype p = ∅ ↔ ∀ x, p x → x ∉ s := by simp [Finset.ext_iff, Subtype.forall, Subtype.coe_mk]
@[mono]
theorem subtype_mono {p : α → Prop} [DecidablePred p] : Monotone (Finset.subtype p) :=
fun _ _ h _ hx => mem_subtype.2 <| h <| mem_subtype.1 hx
/-- `s.subtype p` converts back to `s.filter p` with
`Embedding.subtype`. -/
@[simp]
theorem subtype_map (p : α → Prop) [DecidablePred p] {s : Finset α} :
(s.subtype p).map (Embedding.subtype _) = s.filter p := by
ext x
simp [@and_comm _ (_ = _), @and_left_comm _ (_ = _), @and_comm (p x) (x ∈ s)]
/-- If all elements of a `Finset` satisfy the predicate `p`,
`s.subtype p` converts back to `s` with `Embedding.subtype`. -/
theorem subtype_map_of_mem {p : α → Prop} [DecidablePred p] {s : Finset α} (h : ∀ x ∈ s, p x) :
(s.subtype p).map (Embedding.subtype _) = s := ext <| by simpa [subtype_map] using h
/-- If a `Finset` of a subtype is converted to the main type with
`Embedding.subtype`, all elements of the result have the property of
the subtype. -/
theorem property_of_mem_map_subtype {p : α → Prop} (s : Finset { x // p x }) {a : α}
(h : a ∈ s.map (Embedding.subtype _)) : p a := by
rcases mem_map.1 h with ⟨x, _, rfl⟩
exact x.2
/-- If a `Finset` of a subtype is converted to the main type with
`Embedding.subtype`, the result does not contain any value that does
not satisfy the property of the subtype. -/
theorem not_mem_map_subtype_of_not_property {p : α → Prop} (s : Finset { x // p x }) {a : α}
(h : ¬p a) : a ∉ s.map (Embedding.subtype _) :=
mt s.property_of_mem_map_subtype h
/-- If a `Finset` of a subtype is converted to the main type with
`Embedding.subtype`, the result is a subset of the set giving the
subtype. -/
theorem map_subtype_subset {t : Set α} (s : Finset t) : ↑(s.map (Embedding.subtype _)) ⊆ t := by
intro a ha
rw [mem_coe] at ha
convert property_of_mem_map_subtype s ha
end Subtype
/-- If a `Finset` is a subset of the image of a `Set` under `f`,
then it is equal to the `Finset.image` of a `Finset` subset of that `Set`. -/
theorem subset_set_image_iff [DecidableEq β] {s : Set α} {t : Finset β} {f : α → β} :
↑t ⊆ f '' s ↔ ∃ s' : Finset α, ↑s' ⊆ s ∧ s'.image f = t := by
constructor
· intro h
letI : CanLift β s (f ∘ (↑)) fun y => y ∈ f '' s := ⟨fun y ⟨x, hxt, hy⟩ => ⟨⟨x, hxt⟩, hy⟩⟩
lift t to Finset s using h
refine ⟨t.map (Embedding.subtype _), map_subtype_subset _, ?_⟩
ext y; simp
· rintro ⟨t, ht, rfl⟩
rw [coe_image]
exact Set.image_subset f ht
/--
If a finset `t` is a subset of the image of another finset `s` under `f`, then it is equal to the
image of a subset of `s`.
For the version where `s` is a set, see `subset_set_image_iff`.
-/
theorem subset_image_iff [DecidableEq β] {s : Finset α} {t : Finset β} {f : α → β} :
t ⊆ s.image f ↔ ∃ s' : Finset α, s' ⊆ s ∧ s'.image f = t := by
simp only [← coe_subset, coe_image, subset_set_image_iff]
theorem range_sdiff_zero {n : ℕ} : range (n + 1) \ {0} = (range n).image Nat.succ := by
induction' n with k hk
· simp
conv_rhs => rw [range_succ]
rw [range_succ, image_insert, ← hk, insert_sdiff_of_not_mem]
simp
end Finset
theorem Multiset.toFinset_map [DecidableEq α] [DecidableEq β] (f : α → β) (m : Multiset α) :
(m.map f).toFinset = m.toFinset.image f :=
Finset.val_inj.1 (Multiset.dedup_map_dedup_eq _ _).symm
namespace Equiv
/-- Given an equivalence `α` to `β`, produce an equivalence between `Finset α` and `Finset β`. -/
protected def finsetCongr (e : α ≃ β) : Finset α ≃ Finset β where
toFun s := s.map e.toEmbedding
invFun s := s.map e.symm.toEmbedding
left_inv s := by simp [Finset.map_map]
right_inv s := by simp [Finset.map_map]
@[simp]
theorem finsetCongr_apply (e : α ≃ β) (s : Finset α) : e.finsetCongr s = s.map e.toEmbedding :=
rfl
@[simp]
theorem finsetCongr_refl : (Equiv.refl α).finsetCongr = Equiv.refl _ := by
ext
simp
@[simp]
theorem finsetCongr_symm (e : α ≃ β) : e.finsetCongr.symm = e.symm.finsetCongr :=
rfl
@[simp]
theorem finsetCongr_trans (e : α ≃ β) (e' : β ≃ γ) :
e.finsetCongr.trans e'.finsetCongr = (e.trans e').finsetCongr := by
ext
simp [-Finset.mem_map, -Equiv.trans_toEmbedding]
theorem finsetCongr_toEmbedding (e : α ≃ β) :
e.finsetCongr.toEmbedding = (Finset.mapEmbedding e.toEmbedding).toEmbedding :=
rfl
/-- Given a predicate `p : α → Prop`, produces an equivalence between
`Finset {a : α // p a}` and `{s : Finset α // ∀ a ∈ s, p a}`. -/
@[simps]
protected def finsetSubtypeComm (p : α → Prop) :
Finset {a : α // p a} ≃ {s : Finset α // ∀ a ∈ s, p a} where
toFun s := ⟨s.map ⟨fun a ↦ a.val, Subtype.val_injective⟩, fun _ h ↦
have ⟨v, _, h⟩ := Embedding.coeFn_mk _ _ ▸ mem_map.mp h; h ▸ v.property⟩
invFun s := s.val.attach.map (Subtype.impEmbedding _ _ s.property)
left_inv s := by
ext a; constructor <;> intro h <;>
simp only [Finset.mem_map, Finset.mem_attach, true_and, Subtype.exists, Embedding.coeFn_mk,
exists_and_right, exists_eq_right, Subtype.impEmbedding, Subtype.mk.injEq] at *
· rcases h with ⟨_, ⟨_, h₁⟩, h₂⟩; exact h₂ ▸ h₁
· use a, ⟨a.property, h⟩
right_inv s := by
ext a; constructor <;> intro h <;>
simp only [Finset.mem_map, Finset.mem_attach, true_and, Subtype.exists, Embedding.coeFn_mk,
exists_and_right, exists_eq_right, Subtype.impEmbedding, Subtype.mk.injEq] at *
· rcases h with ⟨_, _, h₁, h₂⟩; exact h₂ ▸ h₁
· use s.property _ h, a
end Equiv
| Mathlib/Data/Finset/Image.lean | 811 | 812 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Data.Nat.Factorization.Defs
import Mathlib.Analysis.NormedSpace.Real
import Mathlib.Data.Rat.Cast.CharZero
/-!
# Real logarithm
In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from
its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and
`log (-x) = log x`.
We prove some basic properties of this function and show that it is continuous.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {x y : ℝ}
/-- The real logarithm function, equal to the inverse of the exponential for `x > 0`,
to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to
`(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and
the derivative of `log` is `1/x` away from `0`. -/
@[pp_nodot]
noncomputable def log (x : ℝ) : ℝ :=
if hx : x = 0 then 0 else expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩
theorem log_of_ne_zero (hx : x ≠ 0) : log x = expOrderIso.symm ⟨|x|, abs_pos.2 hx⟩ :=
dif_neg hx
theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟨x, hx⟩ := by
rw [log_of_ne_zero hx.ne']
congr
exact abs_of_pos hx
theorem exp_log_eq_abs (hx : x ≠ 0) : exp (log x) = |x| := by
rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk]
theorem exp_log (hx : 0 < x) : exp (log x) = x := by
rw [exp_log_eq_abs hx.ne']
exact abs_of_pos hx
theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by
rw [exp_log_eq_abs (ne_of_lt hx)]
exact abs_of_neg hx
theorem le_exp_log (x : ℝ) : x ≤ exp (log x) := by
by_cases h_zero : x = 0
· rw [h_zero, log, dif_pos rfl, exp_zero]
exact zero_le_one
· rw [exp_log_eq_abs h_zero]
exact le_abs_self _
@[simp]
theorem log_exp (x : ℝ) : log (exp x) = x :=
exp_injective <| exp_log (exp_pos x)
theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≤ exp x := by
by_cases hx0 : x ≤ 0
· apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x)
· have h := add_one_le_exp (log x)
rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h
theorem two_mul_le_exp {x : ℝ} : 2 * x ≤ exp x := by
by_cases hx0 : x < 0
· exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le)
(exp_nonneg x)
· apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp
have := Real.add_one_le_exp 1
rwa [one_add_one_eq_two] at this
theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟨exp x, exp_pos x, log_exp x⟩
theorem log_surjective : Surjective log := fun x => ⟨exp x, log_exp x⟩
@[simp]
theorem range_log : range log = univ :=
log_surjective.range_eq
@[simp]
theorem log_zero : log 0 = 0 :=
dif_pos rfl
@[simp]
theorem log_one : log 1 = 0 :=
exp_injective <| by rw [exp_log zero_lt_one, exp_zero]
/-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/
@[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by
obtain rfl | hx := eq_or_ne x 0 <;> simp [*]
@[simp]
theorem log_abs (x : ℝ) : log |x| = log x := by
by_cases h : x = 0
· simp [h]
· rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs]
@[simp]
theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg]
theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by
rw [sinh_eq, exp_neg, exp_log hx]
theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by
rw [cosh_eq, exp_neg, exp_log hx]
theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ =>
⟨-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩
theorem log_mul (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y :=
exp_injective <| by
rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul]
theorem log_div (hx : x ≠ 0) (hy : y ≠ 0) : log (x / y) = log x - log y :=
exp_injective <| by
rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div]
@[simp]
theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by
by_cases hx : x = 0; · simp [hx]
rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv]
theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≤ log y ↔ x ≤ y := by
rw [← exp_le_exp, exp_log h, exp_log h₁]
@[gcongr, bound]
lemma log_le_log (hx : 0 < x) (hxy : x ≤ y) : log x ≤ log y :=
(log_le_log_iff hx (hx.trans_le hxy)).2 hxy
@[gcongr, bound]
theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by
rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)]
theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by
rw [← exp_lt_exp, exp_log hx, exp_log hy]
theorem log_le_iff_le_exp (hx : 0 < x) : log x ≤ y ↔ x ≤ exp y := by rw [← exp_le_exp, exp_log hx]
theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx]
theorem le_log_iff_exp_le (hy : 0 < y) : x ≤ log y ↔ exp x ≤ y := by rw [← exp_le_exp, exp_log hy]
theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy]
theorem log_pos_iff (hx : 0 ≤ x) : 0 < log x ↔ 1 < x := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
rw [← log_one]
exact log_lt_log_iff zero_lt_one hx
@[bound]
theorem log_pos (hx : 1 < x) : 0 < log x :=
(log_pos_iff (lt_trans zero_lt_one hx).le).2 hx
theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by
rw [← neg_neg x, log_neg_eq_log]
have : 1 < -x := by linarith
exact log_pos this
theorem log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 := by
rw [← log_one]
exact log_lt_log_iff h zero_lt_one
@[bound]
| theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 :=
(log_neg_iff h0).2 h1
theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by
| Mathlib/Analysis/SpecialFunctions/Log/Basic.lean | 180 | 183 |
/-
Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.GroupWithZero.Finset
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.Group.FiniteSupport
import Mathlib.Algebra.NoZeroSMulDivisors.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Data.Set.Finite.Lattice
import Mathlib.Data.Set.Subsingleton
/-!
# Finite products and sums over types and sets
We define products and sums over types and subsets of types, with no finiteness hypotheses.
All infinite products and sums are defined to be junk values (i.e. one or zero).
This approach is sometimes easier to use than `Finset.sum`,
when issues arise with `Finset` and `Fintype` being data.
## Main definitions
We use the following variables:
* `α`, `β` - types with no structure;
* `s`, `t` - sets
* `M`, `N` - additive or multiplicative commutative monoids
* `f`, `g` - functions
Definitions in this file:
* `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite.
Zero otherwise.
* `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if
it's finite. One otherwise.
## Notation
* `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f`
* `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f`
This notation works for functions `f : p → M`, where `p : Prop`, so the following works:
* `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : Set α` : sum over the set `s`;
* `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`;
* `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`.
## Implementation notes
`finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However
experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings
where the user is not interested in computability and wants to do reasoning without running into
typeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and
`Fintype`. By sticking solely to `Set.Finite` we avoid these problems. We are aware that there are
other solutions but for beginner mathematicians this approach is easier in practice.
Another application is the construction of a partition of unity from a collection of “bump”
function. In this case the finite set depends on the point and it's convenient to have a definition
that does not mention the set explicitly.
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
We did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`.
## Tags
finsum, finprod, finite sum, finite product
-/
open Function Set
/-!
### Definition and relation to `Finset.sum` and `Finset.prod`
-/
-- Porting note: Used to be section Sort
section sort
variable {G M N : Type*} {α β ι : Sort*} [CommMonoid M] [CommMonoid N]
section
/- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas
with `Classical.dec` in their statement. -/
open Classical in
/-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero
otherwise. -/
noncomputable irreducible_def finsum (lemma := finsum_def') [AddCommMonoid M] (f : α → M) : M :=
if h : (support (f ∘ PLift.down)).Finite then ∑ i ∈ h.toFinset, f i.down else 0
open Classical in
/-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's
finite. One otherwise. -/
@[to_additive existing]
noncomputable irreducible_def finprod (lemma := finprod_def') (f : α → M) : M :=
if h : (mulSupport (f ∘ PLift.down)).Finite then ∏ i ∈ h.toFinset, f i.down else 1
attribute [to_additive existing] finprod_def'
end
open Batteries.ExtendedBinder
/-- `∑ᶠ x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the
support of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or
conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/
notation3"∑ᶠ "(...)", "r:67:(scoped f => finsum f) => r
/-- `∏ᶠ x, f x` is notation for `finprod f`. It is the product of `f x`, where `x` ranges over the
multiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple
arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/
notation3"∏ᶠ "(...)", "r:67:(scoped f => finprod f) => r
-- Porting note: The following ports the lean3 notation for this file, but is currently very fickle.
-- syntax (name := bigfinsum) "∑ᶠ" extBinders ", " term:67 : term
-- macro_rules (kind := bigfinsum)
-- | `(∑ᶠ $x:ident, $p) => `(finsum (fun $x:ident ↦ $p))
-- | `(∑ᶠ $x:ident : $t, $p) => `(finsum (fun $x:ident : $t ↦ $p))
-- | `(∑ᶠ $x:ident $b:binderPred, $p) =>
-- `(finsum fun $x => (finsum (α := satisfies_binder_pred% $x $b) (fun _ => $p)))
-- | `(∑ᶠ ($x:ident) ($h:ident : $t), $p) =>
-- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p))
-- | `(∑ᶠ ($x:ident : $_) ($h:ident : $t), $p) =>
-- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p))
-- | `(∑ᶠ ($x:ident) ($y:ident), $p) =>
-- `(finsum fun $x => (finsum fun $y => $p))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum (α := $t) fun $h => $p)))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p)))
-- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>
-- `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (α := $t) fun $h => $p))))
--
--
-- syntax (name := bigfinprod) "∏ᶠ " extBinders ", " term:67 : term
-- macro_rules (kind := bigfinprod)
-- | `(∏ᶠ $x:ident, $p) => `(finprod (fun $x:ident ↦ $p))
-- | `(∏ᶠ $x:ident : $t, $p) => `(finprod (fun $x:ident : $t ↦ $p))
-- | `(∏ᶠ $x:ident $b:binderPred, $p) =>
-- `(finprod fun $x => (finprod (α := satisfies_binder_pred% $x $b) (fun _ => $p)))
-- | `(∏ᶠ ($x:ident) ($h:ident : $t), $p) =>
-- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p))
-- | `(∏ᶠ ($x:ident : $_) ($h:ident : $t), $p) =>
-- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p))
-- | `(∏ᶠ ($x:ident) ($y:ident), $p) =>
-- `(finprod fun $x => (finprod fun $y => $p))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod (α := $t) fun $h => $p)))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p)))
-- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) =>
-- `(finprod fun $x => (finprod fun $y => (finprod fun $z =>
-- (finprod (α := $t) fun $h => $p))))
@[to_additive]
theorem finprod_eq_prod_plift_of_mulSupport_toFinset_subset {f : α → M}
(hf : (mulSupport (f ∘ PLift.down)).Finite) {s : Finset (PLift α)} (hs : hf.toFinset ⊆ s) :
∏ᶠ i, f i = ∏ i ∈ s, f i.down := by
rw [finprod, dif_pos]
refine Finset.prod_subset hs fun x _ hxf => ?_
rwa [hf.mem_toFinset, nmem_mulSupport] at hxf
@[to_additive]
theorem finprod_eq_prod_plift_of_mulSupport_subset {f : α → M} {s : Finset (PLift α)}
(hs : mulSupport (f ∘ PLift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down :=
finprod_eq_prod_plift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx => by
rw [Finite.mem_toFinset] at hx
exact hs hx
@[to_additive (attr := simp)]
theorem finprod_one : (∏ᶠ _ : α, (1 : M)) = 1 := by
have : (mulSupport fun x : PLift α => (fun _ => 1 : α → M) x.down) ⊆ (∅ : Finset (PLift α)) :=
fun x h => by simp at h
rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_empty]
@[to_additive]
theorem finprod_of_isEmpty [IsEmpty α] (f : α → M) : ∏ᶠ i, f i = 1 := by
rw [← finprod_one]
congr
simp [eq_iff_true_of_subsingleton]
@[to_additive (attr := simp)]
theorem finprod_false (f : False → M) : ∏ᶠ i, f i = 1 :=
finprod_of_isEmpty _
@[to_additive]
theorem finprod_eq_single (f : α → M) (a : α) (ha : ∀ x, x ≠ a → f x = 1) :
∏ᶠ x, f x = f a := by
have : mulSupport (f ∘ PLift.down) ⊆ ({PLift.up a} : Finset (PLift α)) := by
intro x
contrapose
simpa [PLift.eq_up_iff_down_eq] using ha x.down
rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_singleton]
@[to_additive]
theorem finprod_unique [Unique α] (f : α → M) : ∏ᶠ i, f i = f default :=
finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim
@[to_additive (attr := simp)]
theorem finprod_true (f : True → M) : ∏ᶠ i, f i = f trivial :=
@finprod_unique M True _ ⟨⟨trivial⟩, fun _ => rfl⟩ f
@[to_additive]
theorem finprod_eq_dif {p : Prop} [Decidable p] (f : p → M) :
∏ᶠ i, f i = if h : p then f h else 1 := by
split_ifs with h
· haveI : Unique p := ⟨⟨h⟩, fun _ => rfl⟩
exact finprod_unique f
· haveI : IsEmpty p := ⟨h⟩
exact finprod_of_isEmpty f
@[to_additive]
theorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : ∏ᶠ _ : p, x = if p then x else 1 :=
finprod_eq_dif fun _ => x
@[to_additive]
theorem finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g :=
congr_arg _ <| funext h
@[to_additive (attr := congr)]
theorem finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q)
(hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by
subst q
exact finprod_congr hfg
/-- To prove a property of a finite product, it suffices to prove that the property is
multiplicative and holds on the factors. -/
@[to_additive
"To prove a property of a finite sum, it suffices to prove that the property is
additive and holds on the summands."]
theorem finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1)
(hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := by
rw [finprod]
split_ifs
exacts [Finset.prod_induction _ _ hp₁ hp₀ fun i _ => hp₂ _, hp₀]
theorem finprod_nonneg {R : Type*} [CommSemiring R] [PartialOrder R] [IsOrderedRing R]
{f : α → R} (hf : ∀ x, 0 ≤ f x) :
0 ≤ ∏ᶠ x, f x :=
finprod_induction (fun x => 0 ≤ x) zero_le_one (fun _ _ => mul_nonneg) hf
@[to_additive finsum_nonneg]
theorem one_le_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M]
{f : α → M} (hf : ∀ i, 1 ≤ f i) :
1 ≤ ∏ᶠ i, f i :=
finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf
@[to_additive]
theorem MonoidHom.map_finprod_plift (f : M →* N) (g : α → M)
(h : (mulSupport <| g ∘ PLift.down).Finite) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := by
rw [finprod_eq_prod_plift_of_mulSupport_subset h.coe_toFinset.ge,
finprod_eq_prod_plift_of_mulSupport_subset, map_prod]
rw [h.coe_toFinset]
exact mulSupport_comp_subset f.map_one (g ∘ PLift.down)
@[to_additive]
theorem MonoidHom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) :
f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) :=
f.map_finprod_plift g (Set.toFinite _)
@[to_additive]
theorem MonoidHom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) :
f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := by
by_cases hg : (mulSupport <| g ∘ PLift.down).Finite; · exact f.map_finprod_plift g hg
rw [finprod, dif_neg, f.map_one, finprod, dif_neg]
exacts [Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg]
@[to_additive]
theorem MonoidHom.map_finprod_of_injective (g : M →* N) (hg : Injective g) (f : α → M) :
g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f
@[to_additive]
theorem MulEquiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f
@[to_additive]
theorem MulEquivClass.map_finprod {F : Type*} [EquivLike F M N] [MulEquivClass F M N] (g : F)
(f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) :=
MulEquiv.map_finprod (MulEquivClass.toMulEquiv g) f
/-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is
infinite. For a more usual version assuming `(support f).Finite` instead, see `finsum_smul'`. -/
theorem finsum_smul {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M]
(f : ι → R) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _
/-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is
infinite. For a more usual version assuming `(support f).Finite` instead, see `smul_finsum'`. -/
theorem smul_finsum {R M : Type*} [Semiring R] [AddCommGroup M] [Module R M]
[NoZeroSMulDivisors R M] (c : R) (f : ι → M) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := by
rcases eq_or_ne c 0 with (rfl | hc)
· simp
· exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _
@[to_additive]
theorem finprod_inv_distrib [DivisionCommMonoid G] (f : α → G) : (∏ᶠ x, (f x)⁻¹) = (∏ᶠ x, f x)⁻¹ :=
((MulEquiv.inv G).map_finprod f).symm
end sort
-- Porting note: Used to be section Type
section type
variable {α β ι G M N : Type*} [CommMonoid M] [CommMonoid N]
@[to_additive]
theorem finprod_eq_mulIndicator_apply (s : Set α) (f : α → M) (a : α) :
∏ᶠ _ : a ∈ s, f a = mulIndicator s f a := by
classical convert finprod_eq_if (M := M) (p := a ∈ s) (x := f a)
@[to_additive (attr := simp)]
theorem finprod_apply_ne_one (f : α → M) (a : α) : ∏ᶠ _ : f a ≠ 1, f a = f a := by
rw [← mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport]
@[to_additive]
theorem finprod_mem_def (s : Set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mulIndicator s f a :=
finprod_congr <| finprod_eq_mulIndicator_apply s f
@[to_additive]
lemma finprod_mem_mulSupport (f : α → M) : ∏ᶠ a ∈ mulSupport f, f a = ∏ᶠ a, f a := by
rw [finprod_mem_def, mulIndicator_mulSupport]
@[to_additive]
theorem finprod_eq_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ s) :
∏ᶠ i, f i = ∏ i ∈ s, f i := by
have A : mulSupport (f ∘ PLift.down) = Equiv.plift.symm '' mulSupport f := by
rw [mulSupport_comp_eq_preimage]
exact (Equiv.plift.symm.image_eq_preimage _).symm
have : mulSupport (f ∘ PLift.down) ⊆ s.map Equiv.plift.symm.toEmbedding := by
rw [A, Finset.coe_map]
exact image_subset _ h
rw [finprod_eq_prod_plift_of_mulSupport_subset this]
simp only [Finset.prod_map, Equiv.coe_toEmbedding]
congr
@[to_additive]
theorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : α → M) (hf : (mulSupport f).Finite)
{s : Finset α} (h : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i :=
finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx
@[to_additive]
theorem finprod_eq_finset_prod_of_mulSupport_subset (f : α → M) {s : Finset α}
(h : mulSupport f ⊆ (s : Set α)) : ∏ᶠ i, f i = ∏ i ∈ s, f i :=
haveI h' : (s.finite_toSet.subset h).toFinset ⊆ s := by
simpa [← Finset.coe_subset, Set.coe_toFinset]
finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h'
@[to_additive]
theorem finprod_def (f : α → M) [Decidable (mulSupport f).Finite] :
∏ᶠ i : α, f i = if h : (mulSupport f).Finite then ∏ i ∈ h.toFinset, f i else 1 := by
split_ifs with h
· exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _)
· rw [finprod, dif_neg]
rw [mulSupport_comp_eq_preimage]
exact mt (fun hf => hf.of_preimage Equiv.plift.surjective) h
@[to_additive]
theorem finprod_of_infinite_mulSupport {f : α → M} (hf : (mulSupport f).Infinite) :
∏ᶠ i, f i = 1 := by classical rw [finprod_def, dif_neg hf]
@[to_additive]
theorem finprod_eq_prod (f : α → M) (hf : (mulSupport f).Finite) :
∏ᶠ i : α, f i = ∏ i ∈ hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf]
@[to_additive]
theorem finprod_eq_prod_of_fintype [Fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i :=
finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _
@[to_additive]
theorem map_finset_prod {α F : Type*} [Fintype α] [EquivLike F M N] [MulEquivClass F M N] (f : F)
(g : α → M) : f (∏ i : α, g i) = ∏ i : α, f (g i) := by
simp [← finprod_eq_prod_of_fintype, MulEquivClass.map_finprod]
@[to_additive]
theorem finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : Finset α}
(h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : (∏ᶠ (i) (_ : p i), f i) = ∏ i ∈ t, f i := by
set s := { x | p x }
change ∏ᶠ (i : α) (_ : i ∈ s), f i = ∏ i ∈ t, f i
have : mulSupport (s.mulIndicator f) ⊆ t := by
rw [Set.mulSupport_mulIndicator]
intro x hx
exact (h hx.2).1 hx.1
rw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this]
refine Finset.prod_congr rfl fun x hx => mulIndicator_apply_eq_self.2 fun hxs => ?_
contrapose! hxs
exact (h hxs).2 hx
@[to_additive]
theorem finprod_cond_ne (f : α → M) (a : α) [DecidableEq α] (hf : (mulSupport f).Finite) :
(∏ᶠ (i) (_ : i ≠ a), f i) = ∏ i ∈ hf.toFinset.erase a, f i := by
apply finprod_cond_eq_prod_of_cond_iff
intro x hx
rw [Finset.mem_erase, Finite.mem_toFinset, mem_mulSupport]
exact ⟨fun h => And.intro h hx, fun h => h.1⟩
@[to_additive]
theorem finprod_mem_eq_prod_of_inter_mulSupport_eq (f : α → M) {s : Set α} {t : Finset α}
(h : s ∩ mulSupport f = t.toSet ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i :=
finprod_cond_eq_prod_of_cond_iff _ <| by
intro x hxf
rw [← mem_mulSupport] at hxf
refine ⟨fun hx => ?_, fun hx => ?_⟩
· refine ((mem_inter_iff x t (mulSupport f)).mp ?_).1
rw [← Set.ext_iff.mp h x, mem_inter_iff]
exact ⟨hx, hxf⟩
· refine ((mem_inter_iff x s (mulSupport f)).mp ?_).1
rw [Set.ext_iff.mp h x, mem_inter_iff]
exact ⟨hx, hxf⟩
@[to_additive]
theorem finprod_mem_eq_prod_of_subset (f : α → M) {s : Set α} {t : Finset α}
(h₁ : s ∩ mulSupport f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i :=
finprod_cond_eq_prod_of_cond_iff _ fun hx => ⟨fun h => h₁ ⟨h, hx⟩, fun h => h₂ h⟩
@[to_additive]
theorem finprod_mem_eq_prod (f : α → M) {s : Set α} (hf : (s ∩ mulSupport f).Finite) :
∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_assoc]
@[to_additive]
theorem finprod_mem_eq_prod_filter (f : α → M) (s : Set α) [DecidablePred (· ∈ s)]
(hf : (mulSupport f).Finite) :
∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset with i ∈ s, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by
ext x
simp [and_comm]
@[to_additive]
theorem finprod_mem_eq_toFinset_prod (f : α → M) (s : Set α) [Fintype s] :
∏ᶠ i ∈ s, f i = ∏ i ∈ s.toFinset, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp_rw [coe_toFinset s]
@[to_additive]
theorem finprod_mem_eq_finite_toFinset_prod (f : α → M) {s : Set α} (hs : s.Finite) :
∏ᶠ i ∈ s, f i = ∏ i ∈ hs.toFinset, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [hs.coe_toFinset]
@[to_additive]
theorem finprod_mem_finset_eq_prod (f : α → M) (s : Finset α) : ∏ᶠ i ∈ s, f i = ∏ i ∈ s, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl
@[to_additive]
theorem finprod_mem_coe_finset (f : α → M) (s : Finset α) :
(∏ᶠ i ∈ (s : Set α), f i) = ∏ i ∈ s, f i :=
finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl
@[to_additive]
theorem finprod_mem_eq_one_of_infinite {f : α → M} {s : Set α} (hs : (s ∩ mulSupport f).Infinite) :
∏ᶠ i ∈ s, f i = 1 := by
rw [finprod_mem_def]
apply finprod_of_infinite_mulSupport
rwa [← mulSupport_mulIndicator] at hs
@[to_additive]
theorem finprod_mem_eq_one_of_forall_eq_one {f : α → M} {s : Set α} (h : ∀ x ∈ s, f x = 1) :
∏ᶠ i ∈ s, f i = 1 := by simp +contextual [h]
@[to_additive]
theorem finprod_mem_inter_mulSupport (f : α → M) (s : Set α) :
∏ᶠ i ∈ s ∩ mulSupport f, f i = ∏ᶠ i ∈ s, f i := by
rw [finprod_mem_def, finprod_mem_def, mulIndicator_inter_mulSupport]
@[to_additive]
theorem finprod_mem_inter_mulSupport_eq (f : α → M) (s t : Set α)
(h : s ∩ mulSupport f = t ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by
rw [← finprod_mem_inter_mulSupport, h, finprod_mem_inter_mulSupport]
@[to_additive]
theorem finprod_mem_inter_mulSupport_eq' (f : α → M) (s t : Set α)
(h : ∀ x ∈ mulSupport f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by
apply finprod_mem_inter_mulSupport_eq
ext x
exact and_congr_left (h x)
@[to_additive]
theorem finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @Set.univ α, f i = ∏ᶠ i : α, f i :=
finprod_congr fun _ => finprod_true _
variable {f g : α → M} {a b : α} {s t : Set α}
@[to_additive]
theorem finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) :
∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i :=
h₀.symm ▸ finprod_congr fun i => finprod_congr_Prop rfl (h₁ i)
@[to_additive]
theorem finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) : ∏ᶠ i, f i = 1 := by
simp +contextual [h]
@[to_additive finsum_pos']
theorem one_lt_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M]
{f : ι → M}
(h : ∀ i, 1 ≤ f i) (h' : ∃ i, 1 < f i) (hf : (mulSupport f).Finite) : 1 < ∏ᶠ i, f i := by
rcases h' with ⟨i, hi⟩
rw [finprod_eq_prod _ hf]
refine Finset.one_lt_prod' (fun i _ ↦ h i) ⟨i, ?_, hi⟩
simpa only [Finite.mem_toFinset, mem_mulSupport] using ne_of_gt hi
/-!
### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication
-/
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals
the product of `f i` multiplied by the product of `g i`. -/
@[to_additive
"If the additive supports of `f` and `g` are finite, then the sum of `f i + g i`
equals the sum of `f i` plus the sum of `g i`."]
theorem finprod_mul_distrib (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) :
∏ᶠ i, f i * g i = (∏ᶠ i, f i) * ∏ᶠ i, g i := by
classical
rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf Finset.subset_union_left,
finprod_eq_prod_of_mulSupport_toFinset_subset g hg Finset.subset_union_right, ←
Finset.prod_mul_distrib]
refine finprod_eq_prod_of_mulSupport_subset _ ?_
simp only [Finset.coe_union, Finite.coe_toFinset, mulSupport_subset_iff,
mem_union, mem_mulSupport]
intro x
contrapose!
rintro ⟨hf, hg⟩
simp [hf, hg]
/-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i`
equals the product of `f i` divided by the product of `g i`. -/
@[to_additive
"If the additive supports of `f` and `g` are finite, then the sum of `f i - g i`
equals the sum of `f i` minus the sum of `g i`."]
theorem finprod_div_distrib [DivisionCommMonoid G] {f g : α → G} (hf : (mulSupport f).Finite)
(hg : (mulSupport g).Finite) : ∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i := by
simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mulSupport_inv g).symm.rec hg),
finprod_inv_distrib]
/-- A more general version of `finprod_mem_mul_distrib` that only requires `s ∩ mulSupport f` and
`s ∩ mulSupport g` rather than `s` to be finite. -/
@[to_additive
| "A more general version of `finsum_mem_add_distrib` that only requires `s ∩ support f`
and `s ∩ support g` rather than `s` to be finite."]
theorem finprod_mem_mul_distrib' (hf : (s ∩ mulSupport f).Finite) (hg : (s ∩ mulSupport g).Finite) :
| Mathlib/Algebra/BigOperators/Finprod.lean | 554 | 556 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Analytic.Within
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries
/-!
# Higher differentiability
A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous.
By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or,
equivalently, if it is `C^1` and its derivative is `C^{n-1}`.
It is `C^∞` if it is `C^n` for all n.
Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the
space is complete).
We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and
`ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set
and on the whole space respectively.
To avoid the issue of choice when choosing a derivative in sets where the derivative is not
necessarily unique, `ContDiffOn` is not defined directly in terms of the
regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the
existence of a nice sequence of derivatives, expressed with a predicate
`HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`.
We prove basic properties of these notions.
## Main definitions and results
Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`.
* `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to
rank `n`.
* `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`.
* `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`.
* `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`.
In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the
properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space,
`ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f`
for `m ≤ n`.
## Implementation notes
The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more
complicated than the naive definitions one would guess from the intuition over the real or complex
numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity
in general. In the usual situations, they coincide with the usual definitions.
### Definition of `C^n` functions in domains
One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this
is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are
continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n`
functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a
function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`.
This definition still has the problem that a function which is locally `C^n` would not need to
be `C^n`, as different choices of sequences of derivatives around different points might possibly
not be glued together to give a globally defined sequence of derivatives. (Note that this issue
can not happen over reals, thanks to partition of unity, but the behavior over a general field is
not so clear, and we want a definition for general fields). Also, there are locality
problems for the order parameter: one could image a function which, for each `n`, has a nice
sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore
not be glued to give rise to an infinite sequence of derivatives. This would give a function
which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions
in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`.
The resulting definition is slightly more complicated to work with (in fact not so much), but it
gives rise to completely satisfactory theorems.
For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)`
for each natural `m` is by definition `C^∞` at `0`.
There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can
require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x`
within `s`. However, this does not imply continuity or differentiability within `s` of the function
at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on
a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file).
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To
avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`.
These notations are scoped in `ContDiff`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open Set Fin Filter Function
open scoped NNReal Topology ContDiff
universe u uE uF uG uX
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG}
[NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X]
{s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞}
{p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Smooth functions within a set around a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if
it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we
give (all the derivatives should be analytic) is more involved to work around issues when the space
is not complete, but it is equivalent when the space is complete.
For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not
better, is `C^∞` at `0` within `univ`.
-/
def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop :=
match n with
| ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F,
HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u
| (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u
lemma HasFTaylorSeriesUpToOn.analyticOn
(hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) :
AnalyticOn 𝕜 f s := by
have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s :=
(LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn
h (Set.mapsTo_univ _ _)
exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm)
lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) :
∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by
obtain ⟨u, hu, p, hp, h'p⟩ := h
exact ⟨u, hu, hp.analyticOn (h'p 0)⟩
lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) :
AnalyticWithinAt 𝕜 f s x := by
obtain ⟨u, hu, hf⟩ := h.analyticOn
have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu
exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] :
ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by
refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩
obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω
exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩
theorem contDiffWithinAt_nat {n : ℕ} :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u :=
⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩
/-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n`
as the existence of a neighborhood on which there is a Taylor series up to order `n`,
requiring in addition that its terms are analytic in the `ω` case. -/
lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧
(n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by
match n with
| ω => simp [ContDiffWithinAt]
| ∞ => simp at hn
| (n : ℕ) => simp [contDiffWithinAt_nat]
theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) :
ContDiffWithinAt 𝕜 m f s x := by
match n with
| ω => match m with
| ω => exact h
| (m : ℕ∞) =>
intro k _
obtain ⟨u, hu, p, hp, -⟩ := h
exact ⟨u, hu, p, hp.of_le le_top⟩
| (n : ℕ∞) => match m with
| ω => simp at hmn
| (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn))
/-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there.
Note that the same statement for `AnalyticOn` does not require completeness, see
`AnalyticOn.contDiffOn`. -/
theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) :
ContDiffWithinAt 𝕜 n f s x :=
(contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top
theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} :
ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩
theorem contDiffWithinAt_infty :
ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top]
@[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty
theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) :
ContinuousWithinAt f s x := by
have := h.of_le (zero_le _)
simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero,
mem_pure, forall_eq, CharP.cast_eq_zero] at this
rcases this with ⟨u, hu, p, H⟩
rw [mem_nhdsWithin_insert] at hu
exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2
theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right,
fun i ↦ (H' i).mono (sep_subset _ _)⟩
| (n : ℕ∞) =>
intro m hm
let ⟨u, hu, p, H⟩ := h m hm
exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩
theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁)
(mem_of_mem_nhdsWithin (mem_insert x s) h₁ :)
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s):
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩
theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx
theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩
theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr h₁ (h₁ _ hx)
theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr h₁ (h₁ x hx)
theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩
| (n : ℕ∞) =>
intro m hm
rcases h m hm with ⟨u, hu, p, H⟩
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩
@[deprecated (since := "2024-10-30")]
alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin
theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) :
ContDiffWithinAt 𝕜 n f t x :=
h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst
theorem ContDiffWithinAt.congr_mono
(h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s₁ x :=
(h.mono h₁).congr h' hx
theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by
rw [← nhdsWithin_eq_iff_eventuallyEq] at hst
apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin
@[deprecated (since := "2024-10-23")]
alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set
theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x :=
⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩
@[deprecated (since := "2024-10-23")]
alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set
theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm
theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h)
theorem contDiffWithinAt_insert_self :
ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
match n with
| ω => simp [ContDiffWithinAt]
| (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem]
theorem contDiffWithinAt_insert {y : E} :
ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rcases eq_or_ne x y with (rfl | hx)
· exact contDiffWithinAt_insert_self
refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩
apply h.mono_of_mem_nhdsWithin
simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin]
alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert
protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n f (insert x s) x :=
h.insert'
theorem contDiffWithinAt_diff_singleton {y : E} :
ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert]
/-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable
within this set at this point. -/
theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f (insert x s) x := by
rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩
rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩
rw [inter_comm] at tu
exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <|
((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩
theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f s x :=
(h.differentiableWithinAt' hn).mono (subset_insert x s)
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`
(and moreover the function is analytic when `n = ω`). -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by
have h'n : n + 1 ≠ ∞ := by simpa using hn
constructor
· intro h
rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩
refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1),
fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩
· rintro rfl
exact Hp.analyticOn (H'p rfl 0)
apply (contDiffWithinAt_iff_of_ne_infty hn).2
refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩
· convert @self_mem_nhdsWithin _ _ x u
have : x ∈ insert x s := by simp
exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu)
· rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp
refine ⟨Hp.2.2, ?_⟩
rintro rfl i
change AnalyticOn 𝕜
(fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u
apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn
?_ (Set.mapsTo_univ _ _)
exact H'p rfl _
· rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩
rw [contDiffWithinAt_iff_of_ne_infty h'n]
rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩
refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩
· apply Filter.inter_mem _ hu
apply nhdsWithin_le_of_mem hu
exact nhdsWithin_mono _ (subset_insert x u) hv
· rw [hasFTaylorSeriesUpToOn_succ_iff_right]
refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩
· change
HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z))
(FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y
rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff']
convert (f'_eq_deriv y hy.2).mono inter_subset_right
rw [← Hp'.zero_eq y hy.1]
ext z
change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) =
((p' y 0) 0) z
congr
norm_num [eq_iff_true_of_subsingleton]
· convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1
· ext x y
change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y
rw [init_snoc]
· ext x k v y
change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y))
(@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y
rw [snoc_last, init_snoc]
· intro h i
simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h
match i with
| 0 =>
simp only [FormalMultilinearSeries.unshift]
apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
| i + 1 =>
simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one]
apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
/-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives
are taken within the same set. -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by
refine ⟨fun hf => ?_, ?_⟩
· obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf
obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu
rw [inter_comm] at hwu
refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f',
fun y hy => ?_, ?_⟩
· intro h
apply (f_an h).mono hwu
· refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_
refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _))
exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2)
· exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
· rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem (mem_insert _ _)]
rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩
exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩
/-! ### Smooth functions within a set -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it
admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
-/
def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x
theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F}
(hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by
intro x hx m hm
use s
simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and]
exact ⟨f', hf.of_le (mod_cast hm)⟩
theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f s x :=
h x hx
theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx =>
(h x hx).of_le hmn
theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by
rcases eq_or_ne n ω with rfl | hn
· obtain ⟨t, ht, p, hp, h'p⟩ := h
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
refine ⟨u, huo, hxu, ?_⟩
suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top
intro y hy
refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩
simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin]
· match m with
| ω => simp [hn] at hm
| ∞ => exact (hn (h' rfl)).elim
| (m : ℕ) =>
rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩
theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by
obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h'
exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩
theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s :=
fun x hx ↦ (h x hx).analyticWithinAt
/-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on
a neighborhood of this point. -/
theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩
exact ⟨u, hu, h'u.2⟩
· rcases h with ⟨u, u_mem, hu⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem
exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem)
protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) :
∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by
rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩
have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u :=
(eventually_eventually_nhdsWithin.2 hu).and hu
refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_
exact nhdsWithin_mono y (subset_insert _ _) hy.1
theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s :=
h.of_le le_self_add
theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s :=
h.of_le le_add_self
theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} :
ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩
theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s :=
contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true]
@[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty
@[deprecated (since := "2024-11-27")]
alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty
theorem contDiffOn_all_iff_nat :
(∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by
refine ⟨fun H n => H n, ?_⟩
rintro H (_ | n)
exacts [contDiffOn_infty.2 H, H n]
theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) :
ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx)
theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩
theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t :=
fun x hx => (h x (hst hx)).mono hst
theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) :
ContDiffOn 𝕜 n f₁ s₁ :=
(hf.mono hs).congr h₁
/-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/
theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) :
DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn
/-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/
theorem contDiffOn_of_locally_contDiffOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by
intro x xs
rcases h x xs with ⟨u, u_open, xu, hu⟩
apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩)
exact IsOpen.mem_nhds u_open xu
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/
theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffOn 𝕜 (n + 1) f s ↔
∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by
constructor
· intro h x hx
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with
⟨u, hu, f_an, f', hf', Hf'⟩
rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩
rw [insert_eq_of_mem hx] at hu ⊢
have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
rw [insert_eq_of_mem xu] at vu v'u
exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f',
fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩
· intro h x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn]
rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd
exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩
/-! ### Iterated derivative within a set -/
@[simp]
theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by
refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩
have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le
rw [this]
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
rw [hasFTaylorSeriesUpToOn_zero_iff]
exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩
theorem contDiffWithinAt_zero (hx : x ∈ s) :
ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by
constructor
· intro h
obtain ⟨u, H, p, hp⟩ := h 0 le_rfl
refine ⟨u, ?_, ?_⟩
· simpa [hx] using H
· simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp
exact hp.1.mono inter_subset_right
· rintro ⟨u, H, hu⟩
rw [← contDiffWithinAt_inter' H]
have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩
exact (contDiffOn_zero.mpr hu).contDiffWithinAt h'
/-- When a function is `C^n` in a set `s` of unique differentiability, it admits
`ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/
protected theorem ContDiffOn.ftaylorSeriesWithin
(h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) :
HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by
constructor
· intro x _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro m hm x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm
rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩
rw [insert_eq_of_mem hx] at hu
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm] at ho
have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by
change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x
rw [← iteratedFDerivWithin_inter_open o_open xo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩
rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)]
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact
(Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m)
(hs.inter o_open) ⟨hy, yo⟩
exact
((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr
(fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm
· intro m hm
apply continuousOn_of_locally_continuousOn
intro x hx
rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [insert_eq_of_mem hx] at ho
rw [inter_comm] at ho
refine ⟨o, o_open, xo, ?_⟩
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩
exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm
theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s)
(ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x :=
(((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm
theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E}
(h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) :
∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by
rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩
have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by
rw [eventually_smallSets_subset]
exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU
refine this.mono fun t ht ↦ .mono ?_ ht
rw [insert_eq_of_mem ha] at hfU
refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_
exact iteratedFDerivWithin_inter_open hUo hx.2
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOn.contDiffOn_of_completeSpace`. -/
theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩
intro x hx
refine ⟨s, ?_, p, hp⟩
rw [insert_eq_of_mem hx]
exact self_mem_nhdsWithin
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/
theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
fun x hx ↦ (h x hx).contDiffWithinAt
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
h.analyticOn.contDiffOn_of_completeSpace
theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞}
(Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s)
(Hdiff : ∀ m : ℕ, m < n →
DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) :
ContDiffOn 𝕜 n f s := by
intro x hx m hm
rw [insert_eq_of_mem hx]
refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k hk y hy
convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt
· intro k hk
exact Hcont k (le_trans (mod_cast hk) (mod_cast hm))
theorem contDiffOn_of_differentiableOn {n : ℕ∞}
(h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s :=
contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm =>
h m (le_of_lt hm)
theorem contDiffOn_of_analyticOn_iteratedFDerivWithin
(h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
intro x hx
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩
· rw [insert_eq_of_mem hx]
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k _ y hy
exact ((h k).differentiableOn y hy).hasFDerivWithinAt
· intro k _
exact (h k).continuousOn
· intro i
rw [insert_eq_of_mem hx]
exact h i
theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s :=
⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩
theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s :=
((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl
theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m < n) (hs : UniqueDiffOn 𝕜 s) :
DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by
intro x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn
apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt
exact_mod_cast lt_add_one m
theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ}
(h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) :
DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by
have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl)
rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this])
with ⟨u, uo, xu, hu⟩
set t := insert x s ∩ u
have A : t =ᶠ[𝓝[≠] x] s := by
simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter']
rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem,
diff_eq_compl_inter]
exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)]
have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t :=
iteratedFDerivWithin_eventually_congr_set' _ A.symm _
have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x :=
hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x
⟨mem_insert _ _, xu⟩
rw [differentiableWithinAt_congr_set' _ A] at C
exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds
theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s :=
⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs,
fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩,
fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩
theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by
rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs]
simp
theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s)
(h' : n = ω → AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by
rcases eq_or_ne n ∞ with rfl | hn
· rw [ENat.coe_top_add_one, contDiffOn_infty]
intro m x hx
apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add)
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp),
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩
· intro x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩
theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top
exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by
refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩
refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩
· rintro rfl
exact H.analyticOn
have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1
(H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm, insert_eq_of_mem hx] at ho
have := hf'.mono ho
rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this
apply this.congr_of_eventuallyEq_of_mem _ hx
have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩
rw [inter_comm] at this
refine Filter.eventuallyEq_of_mem this fun y hy => ?_
have A : fderivWithin 𝕜 f (s ∩ o) y = f' y :=
((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy)
rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A
match n with
| ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx
| ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top))
| (n : ℕ) => exact A n le_rfl
theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧
∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by
rw [contDiffOn_succ_iff_fderivWithin hs]
refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2,
fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩
rcases h with ⟨f', h1, h2⟩
refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩
exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx
@[deprecated (since := "2024-11-27")]
alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn
theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by
rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn,
contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx]
theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen
protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2
theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fderiv 𝕜 f) s :=
(hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm
theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s)
(hn : 1 ≤ n) : ContinuousOn (fderiv 𝕜 f) s :=
((contDiffOn_succ_iff_fderiv_of_isOpen hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
/-! ### Smooth functions at a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`,
there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous.
-/
def ContDiffAt (n : WithTop ℕ∞) (f : E → F) (x : E) : Prop :=
ContDiffWithinAt 𝕜 n f univ x
theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x :=
Iff.rfl
theorem contDiffAt_infty : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by
simp [← contDiffWithinAt_univ, contDiffWithinAt_infty]
@[deprecated (since := "2024-11-27")] alias contDiffAt_top := contDiffAt_infty
theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x :=
h.mono (subset_univ _)
theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) :
ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter]
theorem contDiffWithinAt_iff_contDiffAt (h : s ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffAt 𝕜 n f x := by
rw [← univ_inter s, contDiffWithinAt_inter h, contDiffWithinAt_univ]
theorem IsOpen.contDiffOn_iff (hs : IsOpen s) :
ContDiffOn 𝕜 n f s ↔ ∀ ⦃a⦄, a ∈ s → ContDiffAt 𝕜 n f a :=
forall₂_congr fun _ => contDiffWithinAt_iff_contDiffAt ∘ hs.mem_nhds
theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) :
ContDiffAt 𝕜 n f x :=
(h _ (mem_of_mem_nhds hx)).contDiffAt hx
theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) :
ContDiffAt 𝕜 n f₁ x :=
h.congr_of_eventuallyEq_of_mem (by rwa [nhdsWithin_univ]) (mem_univ x)
theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x :=
ContDiffWithinAt.of_le h hmn
theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by
simpa [continuousWithinAt_univ] using h.continuousWithinAt
theorem ContDiffAt.analyticAt (h : ContDiffAt 𝕜 ω f x) : AnalyticAt 𝕜 f x := by
rw [← contDiffWithinAt_univ] at h
rw [← analyticWithinAt_univ]
exact h.analyticWithinAt
/-- In a complete space, a function which is analytic at a point is also `C^ω` there.
Note that the same statement for `AnalyticOn` does not require completeness, see
`AnalyticOn.contDiffOn`. -/
theorem AnalyticAt.contDiffAt [CompleteSpace F] (h : AnalyticAt 𝕜 f x) :
ContDiffAt 𝕜 n f x := by
rw [← contDiffWithinAt_univ]
rw [← analyticWithinAt_univ] at h
exact h.contDiffWithinAt
@[simp]
theorem contDiffWithinAt_compl_self :
ContDiffWithinAt 𝕜 n f {x}ᶜ x ↔ ContDiffAt 𝕜 n f x := by
rw [compl_eq_univ_diff, contDiffWithinAt_diff_singleton, contDiffWithinAt_univ]
/-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/
theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≤ n) :
DifferentiableAt 𝕜 f x := by
simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt
nonrec lemma ContDiffAt.contDiffOn (h : ContDiffAt 𝕜 n f x) (hm : m ≤ n) (h' : m = ∞ → n = ω):
∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by
simpa [nhdsWithin_univ] using h.contDiffOn hm h'
/-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/
theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} :
ContDiffAt 𝕜 (n + 1) f x ↔ ∃ f' : E → E →L[𝕜] F,
(∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by
rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp)]
simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem]
constructor
· rintro ⟨u, H, -, f', h_fderiv, h_cont_diff⟩
rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩
refine ⟨f', ⟨t, ?_⟩, h_cont_diff.contDiffAt H⟩
refine ⟨mem_nhds_iff.mpr ⟨t, Subset.rfl, ht, hxt⟩, ?_⟩
intro y hyt
refine (h_fderiv y (htu hyt)).hasFDerivAt ?_
exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩
· rintro ⟨f', ⟨u, H, h_fderiv⟩, h_cont_diff⟩
refine ⟨u, H, by simp, f', fun x hxu ↦ ?_, h_cont_diff.contDiffWithinAt⟩
exact (h_fderiv x hxu).hasFDerivWithinAt
protected theorem ContDiffAt.eventually (h : ContDiffAt 𝕜 n f x) (h' : n ≠ ∞) :
∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by
simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h h'
theorem iteratedFDerivWithin_eq_iteratedFDeriv {n : ℕ}
(hs : UniqueDiffOn 𝕜 s) (h : ContDiffAt 𝕜 n f x) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n f s x = iteratedFDeriv 𝕜 n f x := by
rw [← iteratedFDerivWithin_univ]
rcases h.contDiffOn' le_rfl (by simp) with ⟨u, u_open, xu, hu⟩
rw [← iteratedFDerivWithin_inter_open u_open xu,
← iteratedFDerivWithin_inter_open u_open xu (s := univ)]
apply iteratedFDerivWithin_subset
· exact inter_subset_inter_left _ (subset_univ _)
· exact hs.inter u_open
· apply uniqueDiffOn_univ.inter u_open
· simpa using hu
· exact ⟨hx, xu⟩
/-! ### Smooth functions -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` if it admits derivatives up to
order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives
might not be unique) we do not need to localize the definition in space or time.
-/
def ContDiff (n : WithTop ℕ∞) (f : E → F) : Prop :=
match n with
| ω => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo ⊤ f p
∧ ∀ i, AnalyticOnNhd 𝕜 (fun x ↦ p x i) univ
| (n : ℕ∞) => ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p
/-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/
theorem HasFTaylorSeriesUpTo.contDiff {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F}
(hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f :=
⟨f', hf⟩
theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by
match n with
| ω =>
constructor
· intro H
use ftaylorSeriesWithin 𝕜 f univ
rw [← hasFTaylorSeriesUpToOn_univ_iff]
refine ⟨H.ftaylorSeriesWithin uniqueDiffOn_univ, fun i ↦ ?_⟩
rw [← analyticOn_univ]
exact H.analyticOn.iteratedFDerivWithin uniqueDiffOn_univ _
· rintro ⟨p, hp, h'p⟩ x _
exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le le_top,
fun i ↦ (h'p i).analyticOn⟩
| (n : ℕ∞) =>
constructor
· intro H
use ftaylorSeriesWithin 𝕜 f univ
rw [← hasFTaylorSeriesUpToOn_univ_iff]
exact H.ftaylorSeriesWithin uniqueDiffOn_univ
· rintro ⟨p, hp⟩ x _ m hm
exact ⟨univ, Filter.univ_sets _, p,
(hp.hasFTaylorSeriesUpToOn univ).of_le (mod_cast hm)⟩
theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by
simp [← contDiffOn_univ, ContDiffOn, ContDiffAt]
theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x :=
contDiff_iff_contDiffAt.1 h x
theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x :=
h.contDiffAt.contDiffWithinAt
theorem contDiff_infty : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by
simp [contDiffOn_univ.symm, contDiffOn_infty]
@[deprecated (since := "2024-11-25")] alias contDiff_top := contDiff_infty
@[deprecated (since := "2024-11-25")] alias contDiff_infty_iff_contDiff_omega := contDiff_infty
theorem contDiff_all_iff_nat : (∀ n : ℕ∞, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by
simp only [← contDiffOn_univ, contDiffOn_all_iff_nat]
theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s :=
(contDiffOn_univ.2 h).mono (subset_univ _)
@[simp]
theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by
rw [← contDiffOn_univ, continuous_iff_continuousOn_univ]
exact contDiffOn_zero
theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by
rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ]
theorem contDiffAt_one_iff :
ContDiffAt 𝕜 1 f x ↔
∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by
rw [show (1 : WithTop ℕ∞) = (0 : ℕ) + 1 from rfl]
simp_rw [contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : WithTop ℕ∞) = 0 from rfl,
contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm]
theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≤ n) : ContDiff 𝕜 m f :=
contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn
theorem ContDiff.of_succ (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 n f :=
h.of_le le_self_add
theorem ContDiff.one_of_succ (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 1 f := by
apply h.of_le le_add_self
theorem ContDiff.continuous (h : ContDiff 𝕜 n f) : Continuous f :=
contDiff_zero.1 (h.of_le bot_le)
/-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/
theorem ContDiff.differentiable (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Differentiable 𝕜 f :=
differentiableOn_univ.1 <| (contDiffOn_univ.2 h).differentiableOn hn
theorem contDiff_iff_forall_nat_le {n : ℕ∞} :
ContDiff 𝕜 n f ↔ ∀ m : ℕ, ↑m ≤ n → ContDiff 𝕜 m f := by
simp_rw [← contDiffOn_univ]; exact contDiffOn_iff_forall_nat_le
/-- A function is `C^(n+1)` iff it has a `C^n` derivative. -/
theorem contDiff_succ_iff_hasFDerivAt {n : ℕ} :
ContDiff 𝕜 (n + 1) f ↔
∃ f' : E → E →L[𝕜] F, ContDiff 𝕜 n f' ∧ ∀ x, HasFDerivAt f (f' x) x := by
simp only [← contDiffOn_univ, ← hasFDerivWithinAt_univ, Set.mem_univ, forall_true_left,
contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn uniqueDiffOn_univ,
WithTop.natCast_ne_top, analyticOn_univ, false_implies, true_and]
theorem contDiff_one_iff_hasFDerivAt : ContDiff 𝕜 1 f ↔
∃ f' : E → E →L[𝕜] F, Continuous f' ∧ ∀ x, HasFDerivAt f (f' x) x := by
convert contDiff_succ_iff_hasFDerivAt using 4; simp
theorem AnalyticOn.contDiff (hf : AnalyticOn 𝕜 f univ) : ContDiff 𝕜 n f := by
rw [← contDiffOn_univ]
exact hf.contDiffOn (n := n) uniqueDiffOn_univ
theorem AnalyticOnNhd.contDiff (hf : AnalyticOnNhd 𝕜 f univ) : ContDiff 𝕜 n f :=
hf.analyticOn.contDiff
theorem ContDiff.analyticOnNhd (h : ContDiff 𝕜 ω f) : AnalyticOnNhd 𝕜 f s := by
rw [← contDiffOn_univ] at h
have := h.analyticOn
rw [analyticOn_univ] at this
exact this.mono (subset_univ _)
theorem contDiff_omega_iff_analyticOnNhd :
ContDiff 𝕜 ω f ↔ AnalyticOnNhd 𝕜 f univ :=
⟨fun h ↦ h.analyticOnNhd, fun h ↦ h.contDiff⟩
/-! ### Iterated derivative -/
/-- When a function is `C^n`, it admits `ftaylorSeries 𝕜 f` as a Taylor series up
to order `n` in `s`. -/
theorem ContDiff.ftaylorSeries (hf : ContDiff 𝕜 n f) :
HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by
simp only [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ]
at hf ⊢
exact ContDiffOn.ftaylorSeriesWithin hf uniqueDiffOn_univ
/-- For `n : ℕ∞`, a function is `C^n` iff it admits `ftaylorSeries 𝕜 f`
as a Taylor series up to order `n`. -/
theorem contDiff_iff_ftaylorSeries {n : ℕ∞} :
ContDiff 𝕜 n f ↔ HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by
constructor
· rw [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ]
exact fun h ↦ ContDiffOn.ftaylorSeriesWithin h uniqueDiffOn_univ
· exact fun h ↦ ⟨ftaylorSeries 𝕜 f, h⟩
theorem contDiff_iff_continuous_differentiable {n : ℕ∞} :
ContDiff 𝕜 n f ↔
(∀ m : ℕ, m ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧
∀ m : ℕ, m < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by
simp [contDiffOn_univ.symm, continuous_iff_continuousOn_univ, differentiableOn_univ.symm,
iteratedFDerivWithin_univ, contDiffOn_iff_continuousOn_differentiableOn uniqueDiffOn_univ]
theorem contDiff_nat_iff_continuous_differentiable {n : ℕ} :
ContDiff 𝕜 n f ↔
(∀ m : ℕ, m ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧
∀ m : ℕ, m < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by
rw [← WithTop.coe_natCast, contDiff_iff_continuous_differentiable]
simp
/-- If `f` is `C^n` then its `m`-times iterated derivative is continuous for `m ≤ n`. -/
theorem ContDiff.continuous_iteratedFDeriv {m : ℕ} (hm : m ≤ n) (hf : ContDiff 𝕜 n f) :
Continuous fun x => iteratedFDeriv 𝕜 m f x :=
(contDiff_iff_continuous_differentiable.mp (hf.of_le hm)).1 m le_rfl
/-- If `f` is `C^n` then its `m`-times iterated derivative is differentiable for `m < n`. -/
theorem ContDiff.differentiable_iteratedFDeriv {m : ℕ} (hm : m < n) (hf : ContDiff 𝕜 n f) :
Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x :=
(contDiff_iff_continuous_differentiable.mp
(hf.of_le (ENat.add_one_natCast_le_withTop_of_lt hm))).2 m (mod_cast lt_add_one m)
theorem contDiff_of_differentiable_iteratedFDeriv {n : ℕ∞}
(h : ∀ m : ℕ, m ≤ n → Differentiable 𝕜 (iteratedFDeriv 𝕜 m f)) : ContDiff 𝕜 n f :=
contDiff_iff_continuous_differentiable.2
⟨fun m hm => (h m hm).continuous, fun m hm => h m (le_of_lt hm)⟩
/-- A function is `C^(n + 1)` if and only if it is differentiable,
and its derivative (formulated in terms of `fderiv`) is `C^n`. -/
theorem contDiff_succ_iff_fderiv :
ContDiff 𝕜 (n + 1) f ↔ Differentiable 𝕜 f ∧ (n = ω → AnalyticOnNhd 𝕜 f univ) ∧
ContDiff 𝕜 n (fderiv 𝕜 f) := by
simp only [← contDiffOn_univ, ← differentiableOn_univ, ← fderivWithin_univ,
contDiffOn_succ_iff_fderivWithin uniqueDiffOn_univ, analyticOn_univ]
theorem contDiff_one_iff_fderiv :
ContDiff 𝕜 1 f ↔ Differentiable 𝕜 f ∧ Continuous (fderiv 𝕜 f) := by
rw [← zero_add 1, contDiff_succ_iff_fderiv]
simp
theorem contDiff_infty_iff_fderiv :
ContDiff 𝕜 ∞ f ↔ Differentiable 𝕜 f ∧ ContDiff 𝕜 ∞ (fderiv 𝕜 f) := by
rw [← ENat.coe_top_add_one, contDiff_succ_iff_fderiv]
simp
@[deprecated (since := "2024-11-27")] alias contDiff_top_iff_fderiv := contDiff_infty_iff_fderiv
| theorem ContDiff.continuous_fderiv (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) :
Continuous (fderiv 𝕜 f) :=
(contDiff_one_iff_fderiv.1 (h.of_le hn)).2
| Mathlib/Analysis/Calculus/ContDiff/Defs.lean | 1,217 | 1,220 |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.BooleanAlgebra
/-!
# The set lattice
This file is a collection of results on the complete atomic boolean algebra structure of `Set α`.
Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`.
## Main declarations
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and
`⋃₀ s = ⋃ x ∈ s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`,
`< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference.
See `Set.instBooleanAlgebra`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `⋃ i, s i` is called `iUnion`
* `⋂ i, s i` is called `iInter`
* `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`.
* `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`.
* `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂`
where `j : i ∈ s`.
* `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂`
where `j : i ∈ s`.
## Notation
* `⋃`: `Set.iUnion`
* `⋂`: `Set.iInter`
* `⋃₀`: `Set.sUnion`
* `⋂₀`: `Set.sInter`
-/
open Function Set
universe u
variable {α β γ δ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by
simp_rw [mem_iUnion]
theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by
simp_rw [mem_iInter]
theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i :=
mem_iUnion.2 ⟨i, ha⟩
theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) :
a ∈ ⋃ (i) (j), s i j :=
mem_iUnion₂.2 ⟨i, j, ha⟩
theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i :=
mem_iInter.2 h
theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) :
a ∈ ⋂ (i) (j), s i j :=
mem_iInter₂.2 h
/-! ### Union and intersection over an indexed family of sets -/
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ :=
iSup_congr_Prop pq f
@[congr]
theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q)
(f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ :=
iInf_congr_Prop pq f
theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i :=
iSup_plift_up _
theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i :=
iSup_plift_down _
theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i :=
iInf_plift_up _
theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i :=
iInf_plift_down _
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ :=
iSup_eq_if _
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋃ h : p, s h = if h : p then s h else ∅ :=
iSup_eq_dif _
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ :=
iInf_eq_if _
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) :
⋂ h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β)
(w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by
have p : x ∈ ⊤ := Set.mem_univ x
rw [← w, Set.mem_iUnion] at p
simpa using p
theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α)
(H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by
obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some
exact ⟨x, m⟩
theorem nonempty_of_nonempty_iUnion
{s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by
obtain ⟨x, hx⟩ := h_Union
exact ⟨Classical.choose <| mem_iUnion.mp hx⟩
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } :=
ext fun _ => mem_iInter.symm
theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t :=
iSup_le h
theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) :
⋃ (i) (j), s i j ⊆ t :=
iUnion_subset fun x => iUnion_subset (h x)
theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i :=
le_iInf h
theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) :
s ⊆ ⋂ (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
@[simp]
theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t :=
⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩
theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} :
⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff]
@[simp]
theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i :=
le_iInf_iff
theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} :
(s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff]
theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i :=
le_iSup
theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i :=
iInf_le
lemma iInter_subset_iUnion [Nonempty ι] {s : ι → Set α} : ⋂ i, s i ⊆ ⋃ i, s i := iInf_le_iSup
theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' :=
le_iSup₂ i j
theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j :=
iInf₂_le i j
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i :=
le_iSup_of_le i h
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) :
⋂ i, s i ⊆ t :=
iInf_le_of_le i h
/-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i)
(h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j :=
le_iSup₂_of_le i j h
/-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i)
(h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t :=
iInf₂_le_of_le i j h
theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono h
@[gcongr]
theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t :=
iSup_mono h
theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j :=
iSup₂_mono h
theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i :=
iInf_mono h
@[gcongr]
theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t :=
iInf_mono h
theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) :
⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j :=
iInf₂_mono h
theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) :
⋃ i, s i ⊆ ⋃ i, t i :=
iSup_mono' h
theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' :=
iSup₂_mono' h
theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) :
⋂ i, s i ⊆ ⋂ j, t j :=
Set.subset_iInter fun j =>
let ⟨i, hi⟩ := h j
iInter_subset_of_subset i hi
theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α}
(h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' :=
subset_iInter₂_iff.2 fun i' j' =>
let ⟨_, _, hst⟩ := h i' j'
(iInter₂_subset _ _).trans hst
theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) :
⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) :
⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by
ext
exact mem_iUnion
theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by
ext
exact mem_iInter
theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y :=
h1.iSup_congr h h2
theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h)
(h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y :=
h1.iInf_congr h h2
lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h
lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h
lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋃ (i) (j), s i j = ⋃ (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) :
⋂ (i) (j), s i j = ⋂ (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
section Nonempty
variable [Nonempty ι] {f : ι → Set α} {s : Set α}
lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const
lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const
lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
end Nonempty
@[simp]
theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ :=
compl_iSup
theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iUnion]
@[simp]
theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ :=
compl_iInf
theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by
simp_rw [compl_iInter]
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by
simp only [compl_iInter, compl_compl]
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by
simp only [compl_iUnion, compl_compl]
theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i :=
inf_iSup_eq _ _
theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s :=
iSup_inf_eq _ _
theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) :
⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i :=
iSup_sup_eq
theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) :
⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i :=
iInf_inf_eq
theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i :=
sup_iSup
theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s :=
iSup_sup
theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i :=
inf_iInf
theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s :=
iInf_inf
theorem insert_iUnion [Nonempty ι] (x : β) (t : ι → Set β) :
insert x (⋃ i, t i) = ⋃ i, insert x (t i) := by
simp_rw [← union_singleton, iUnion_union]
-- classical
theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i :=
sup_iInf_eq _ _
theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
theorem insert_iInter (x : β) (t : ι → Set β) : insert x (⋂ i, t i) = ⋂ i, insert x (t i) := by
simp_rw [← union_singleton, iInter_union]
theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s :=
iUnion_inter _ _
theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i :=
le_iSup_inf_iSup s t
theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_monotone hs ht
theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i :=
iSup_inf_of_antitone hs ht
theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α}
(hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_monotone hs ht
theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α}
(hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i :=
iInf_sup_of_antitone hs ht
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) :=
iSup_option s
theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) :=
iInf_option s
section
variable (p : ι → Prop) [DecidablePred p]
theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h :=
iSup_dite _ _ _
theorem iUnion_ite (f g : ι → Set α) :
⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i :=
iUnion_dite _ _ _
theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) :
⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h :=
iInf_dite _ _ _
theorem iInter_ite (f g : ι → Set α) :
⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i :=
iInter_dite _ _ _
end
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False → Set α} : iInter s = univ :=
iInf_false
theorem iUnion_false {s : False → Set α} : iUnion s = ∅ :=
iSup_false
@[simp]
theorem iInter_true {s : True → Set α} : iInter s = s trivial :=
iInf_true
@[simp]
theorem iUnion_true {s : True → Set α} : iUnion s = s trivial :=
iSup_true
@[simp]
theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} :
⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ :=
iInf_exists
@[simp]
theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} :
⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ :=
iSup_exists
@[simp]
theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ :=
iSup_bot
@[simp]
theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ :=
iInf_top
section
variable {s : ι → Set α}
@[simp]
theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ :=
iSup_eq_bot
@[simp]
theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ :=
iInf_eq_top
@[simp]
theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
theorem nonempty_biUnion {t : Set α} {s : α → Set β} :
(⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp
theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) :
⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ :=
iSup_exists
end
@[simp]
theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋂ (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋂ (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} :
⋃ (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} :
⋃ (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) :
⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) :=
iInf_or
theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) :
⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) :=
iSup_or
theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ :=
iSup_and
theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ :=
iInf_and
theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' :=
iSup_comm
theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' :=
iInf_comm
theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_sigma
theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_sigma
theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 :=
iInf_sigma' _
theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iSup₂_comm _
theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) :
⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ :=
iInf₂_comm _
@[simp]
theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι']
@[simp]
theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iUnion_and, @iUnion_comm _ ι]
@[simp]
theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h =
⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by
simp only [iInter_and, @iInter_comm _ ι']
@[simp]
theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) :
⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h =
⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by
simp only [iInter_and, @iInter_comm _ ι]
@[simp]
theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
@[simp]
theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} :
⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
lemma iUnion_sum {s : α ⊕ β → Set γ} : ⋃ x, s x = (⋃ x, s (.inl x)) ∪ ⋃ x, s (.inr x) := iSup_sum
lemma iInter_sum {s : α ⊕ β → Set γ} : ⋂ x, s x = (⋂ x, s (.inl x)) ∩ ⋂ x, s (.inr x) := iInf_sum
theorem iUnion_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ :=
iSup_psigma _
/-- A reversed version of `iUnion_psigma` with a curried map. -/
theorem iUnion_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋃ i, ⋃ a, s i a = ⋃ ia : PSigma γ, s ia.1 ia.2 :=
iSup_psigma' _
theorem iInter_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ :=
iInf_psigma _
/-- A reversed version of `iInter_psigma` with a curried map. -/
theorem iInter_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) :
⋂ i, ⋂ a, s i a = ⋂ ia : PSigma γ, s ia.1 ia.2 :=
iInf_psigma' _
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnion₂`. -/
theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) :
y ∈ ⋃ x ∈ s, t x :=
mem_iUnion₂_of_mem xs ytx
/-- A specialization of `mem_iInter₂`. -/
theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) :
y ∈ ⋂ x ∈ s, t x :=
mem_iInter₂_of_mem h
/-- A specialization of `subset_iUnion₂`. -/
theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) :
u x ⊆ ⋃ x ∈ s, u x :=
subset_iUnion₂ (s := fun i _ => u i) x xs
/-- A specialization of `iInter₂_subset`. -/
theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) :
⋂ x ∈ s, t x ⊆ t x :=
iInter₂_subset x xs
lemma biInter_subset_biUnion {s : Set α} (hs : s.Nonempty) {t : α → Set β} :
⋂ x ∈ s, t x ⊆ ⋃ x ∈ s, t x := biInf_le_biSup hs
theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') :
⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x :=
iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx
theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) :
⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x :=
subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx
theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) :
⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h
theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) :
⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInter₂_mono h
theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) :
⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 :=
iSup_subtype'
theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) :
⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 :=
iInf_subtype'
@[simp] lemma biUnion_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋃ a ∈ s, t = t :=
biSup_const hs
@[simp] lemma biInter_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋂ a ∈ s, t = t :=
biInf_const hs
theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ :=
iSup_subtype
theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) :
⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ :=
iInf_subtype
theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ :=
iInf_emptyset
theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x :=
iInf_univ
@[simp]
theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s :=
Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
@[simp]
theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a :=
iInf_singleton
theorem biInter_union (s t : Set α) (u : α → Set β) :
⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x :=
iInf_union
theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) :
⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp
theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by
rw [biInter_insert, biInter_singleton]
theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, ← iInter_inter]
theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) :
⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by
rw [inter_comm, ← biInter_inter hs]
simp [inter_comm]
theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ :=
iSup_emptyset
theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x :=
iSup_univ
theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a :=
iSup_singleton
@[simp]
theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s :=
ext <| by simp
theorem biUnion_union (s t : Set α) (u : α → Set β) :
⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x :=
iSup_union
@[simp]
theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iUnion_subtype _ _
@[simp]
theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) :
⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ :=
iInter_subtype _ _
theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) :
⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp
theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by
simp
theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion]
theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) :
(⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter]
theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter]
theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union]
theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) :
x ∈ ⋃₀ S :=
⟨t, ht, hx⟩
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀ S)
(ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩
theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t :=
sInf_le tS
theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀ S :=
le_sSup tS
theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u)
(h₂ : u ∈ t) : s ⊆ ⋃₀ t :=
Subset.trans h₁ (subset_sUnion_of_mem h₂)
theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀ S ⊆ t :=
sSup_le h
@[simp]
theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀ s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t :=
sSup_le_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) :
⋃₀ s ⊆ ⋃₀ (f '' s) :=
fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) :
⋃₀ (f '' s) ⊆ ⋃₀ s :=
-- If t ∈ f '' s is arbitrary; t = f u for some u : Set α.
fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩
theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S :=
le_sInf h
@[simp]
theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' :=
le_sInf_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
@[simp]
theorem sUnion_empty : ⋃₀ ∅ = (∅ : Set α) :=
sSup_empty
@[simp]
theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) :=
sInf_empty
@[simp]
theorem sUnion_singleton (s : Set α) : ⋃₀ {s} = s :=
sSup_singleton
@[simp]
theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s :=
sInf_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀ S = ∅ ↔ ∀ s ∈ S, s = ∅ :=
sSup_eq_bot
@[simp]
theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ :=
sInf_eq_top
theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t :=
sUnion_subset_iff.symm
/-- `⋃₀` and `𝒫` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gc_sSup_Iic
/-- `⋃₀` and `𝒫` form a Galois insertion. -/
def sUnionPowersetGI :
GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) :=
gi_sSup_Iic
@[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI
/-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) :
⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro ⟨s, hs, hne⟩
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀ S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀ s).Nonempty) : s.Nonempty :=
let ⟨s, hs, _⟩ := nonempty_sUnion.1 h
⟨s, hs⟩
theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀ s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm ▸ univ_nonempty
theorem sUnion_union (S T : Set (Set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T :=
sSup_union
theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T :=
sInf_union
@[simp]
theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀ insert s T = s ∪ ⋃₀ T :=
sSup_insert
@[simp]
theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T :=
sInf_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀ (s \ {∅}) = ⋃₀ s :=
sSup_diff_singleton_bot s
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s :=
sInf_diff_singleton_top s
theorem sUnion_pair (s t : Set α) : ⋃₀ {s, t} = s ∪ t :=
sSup_pair
theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t :=
sInf_pair
@[simp]
theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀ (f '' s) = ⋃ a ∈ s, f a :=
sSup_image
@[simp]
theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ a ∈ s, f a :=
sInf_image
@[simp]
lemma sUnion_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) :
⋃₀ (image2 f s t) = ⋃ (a ∈ s) (b ∈ t), f a b := sSup_image2
@[simp]
lemma sInter_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) :
⋂₀ (image2 f s t) = ⋂ (a ∈ s) (b ∈ t), f a b := sInf_image2
@[simp]
theorem sUnion_range (f : ι → Set β) : ⋃₀ range f = ⋃ x, f x :=
rfl
@[simp]
theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x :=
rfl
theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} :
⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀ c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by
simp only [eq_univ_iff_forall, mem_sUnion]
-- classical
theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} :
⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
-- classical
theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
@[simp]
theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
-- classical
theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} :
(⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by
simp
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
-- classical
theorem compl_sUnion (S : Set (Set α)) : (⋃₀ S)ᶜ = ⋂₀ (compl '' S) :=
ext fun x => by simp
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀ S = (⋂₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋃₀ S), compl_sUnion]
-- classical
theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀ (compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀ (compl '' S))ᶜ := by
rw [← compl_compl (⋂₀ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S)
(h : s ∩ ⋃₀ S = ∅) : s ∩ t = ∅ :=
eq_empty_of_subset_empty <| by
rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) :
range f = ⋃ a, range fun b => f ⟨a, b⟩ :=
Set.ext <| by simp
theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) :
⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
· rintro ⟨i, a, h, rfl⟩
exact h
· intro h
obtain ⟨i, a⟩ := x
exact ⟨i, a, h, rfl⟩
theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩
alias sUnion_mono := sUnion_subset_sUnion
alias sInter_mono := sInter_subset_sInter
theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s :=
iSup_const_mono (α := Set α) h
@[simp]
theorem iUnion_singleton_eq_range (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x
simp [@eq_comm _ x]
theorem iUnion_insert_eq_range_union_iUnion {ι : Type*} (x : ι → β) (t : ι → Set β) :
⋃ i, insert (x i) (t i) = range x ∪ ⋃ i, t i := by
simp_rw [← union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range]
theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff]
theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp
theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀ s = ⋃ (i : Set α) (_ : i ∈ s), i := by
rw [← sUnion_image, image_id']
theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by
rw [← sInter_image, image_id']
theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀ s = ⋃ i : s, i := by
simp only [← sUnion_range, Subtype.range_coe]
theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by
simp only [← sInter_range, Subtype.range_coe]
@[simp]
theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ :=
iSup_of_empty _
@[simp]
theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ :=
iInf_of_empty _
theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ :=
sup_eq_iSup s₁ s₂
theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ :=
inf_eq_iInf s₁ s₂
theorem sInter_union_sInter {S T : Set (Set α)} :
⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 :=
sInf_sup_sInf
theorem sUnion_inter_sUnion {s t : Set (Set α)} :
⋃₀ s ∩ ⋃₀ t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 :=
sSup_inf_sSup
theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) :
⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι]
theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) :
⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι]
theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀ ⋃ i, s i = ⋃ i, ⋃₀ s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)}
(hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀ C := by
ext x; constructor
· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩
refine ⟨_, hs, ?_⟩
exact (f ⟨s, hs⟩ y).2
· rintro ⟨s, hs, hx⟩
obtain ⟨y, hy⟩ := hf ⟨s, hs⟩ ⟨x, hx⟩
refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩
exact congr_arg Subtype.val hy
theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x}
(hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
· rintro ⟨y, i, rfl⟩
exact ⟨i, (f i y).2⟩
· rintro ⟨i, hx⟩
obtain ⟨y, hy⟩ := hf i ⟨x, hx⟩
exact ⟨y, i, congr_arg Subtype.val hy⟩
theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i :=
sup_iInf_eq _ _
theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) :
(s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left]
theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t :=
iInf_sup_eq _ _
theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) :
(⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right]
lemma biUnion_lt_eq_iUnion [LT α] [NoMaxOrder α] {s : α → Set β} :
⋃ (n) (m < n), s m = ⋃ n, s n := biSup_lt_eq_iSup
lemma biUnion_le_eq_iUnion [Preorder α] {s : α → Set β} :
⋃ (n) (m ≤ n), s m = ⋃ n, s n := biSup_le_eq_iSup
lemma biInter_lt_eq_iInter [LT α] [NoMaxOrder α] {s : α → Set β} :
⋂ (n) (m < n), s m = ⋂ (n), s n := biInf_lt_eq_iInf
lemma biInter_le_eq_iInter [Preorder α] {s : α → Set β} :
⋂ (n) (m ≤ n), s m = ⋂ (n), s n := biInf_le_eq_iInf
lemma biUnion_gt_eq_iUnion [LT α] [NoMinOrder α] {s : α → Set β} :
⋃ (n) (m > n), s m = ⋃ n, s n := biSup_gt_eq_iSup
lemma biUnion_ge_eq_iUnion [Preorder α] {s : α → Set β} :
⋃ (n) (m ≥ n), s m = ⋃ n, s n := biSup_ge_eq_iSup
lemma biInter_gt_eq_iInf [LT α] [NoMinOrder α] {s : α → Set β} :
⋂ (n) (m > n), s m = ⋂ n, s n := biInf_gt_eq_iInf
lemma biInter_ge_eq_iInf [Preorder α] {s : α → Set β} :
⋂ (n) (m ≥ n), s m = ⋂ n, s n := biInf_ge_eq_iInf
section le
variable {ι : Type*} [PartialOrder ι] (s : ι → Set α) (i : ι)
theorem biUnion_le : (⋃ j ≤ i, s j) = (⋃ j < i, s j) ∪ s i :=
biSup_le_eq_sup s i
theorem biInter_le : (⋂ j ≤ i, s j) = (⋂ j < i, s j) ∩ s i :=
biInf_le_eq_inf s i
theorem biUnion_ge : (⋃ j ≥ i, s j) = s i ∪ ⋃ j > i, s j :=
biSup_ge_eq_sup s i
theorem biInter_ge : (⋂ j ≥ i, s j) = s i ∩ ⋂ j > i, s j :=
biInf_ge_eq_inf s i
end le
section Pi
variable {π : α → Type*}
theorem pi_def (i : Set α) (s : ∀ a, Set (π a)) : pi i s = ⋂ a ∈ i, eval a ⁻¹' s a := by
ext
simp
theorem univ_pi_eq_iInter (t : ∀ i, Set (π i)) : pi univ t = ⋂ i, eval i ⁻¹' t i := by
simp only [pi_def, iInter_true, mem_univ]
theorem pi_diff_pi_subset (i : Set α) (s t : ∀ a, Set (π a)) :
pi i s \ pi i t ⊆ ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by
refine diff_subset_comm.2 fun x hx a ha => ?_
simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not,
eval_apply] at hx
exact hx.2 _ ha (hx.1 _ ha)
theorem iUnion_univ_pi {ι : α → Type*} (t : (a : α) → ι a → Set (π a)) :
⋃ x : (a : α) → ι a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ι a, t a j := by
ext
simp [Classical.skolem]
end Pi
section Directed
theorem directedOn_iUnion {r} {f : ι → Set α} (hd : Directed (· ⊆ ·) f)
(h : ∀ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by
simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp]
exact fun a₁ b₁ fb₁ a₂ b₂ fb₂ =>
let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂
let ⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂)
⟨x, ⟨z, xf⟩, xa₁, xa₂⟩
theorem directedOn_sUnion {r} {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S)
(h : ∀ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by
rw [sUnion_eq_iUnion]
exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2)
theorem pairwise_iUnion₂ {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S)
(r : α → α → Prop) (h : ∀ s ∈ S, s.Pairwise r) : (⋃ s ∈ S, s).Pairwise r := by
simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp]
intro x S hS hx y T hT hy hne
obtain ⟨U, hU, hSU, hTU⟩ := hd S hS T hT
exact h U hU (hSU hx) (hTU hy) hne
end Directed
end Set
namespace Function
namespace Surjective
theorem iUnion_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋃ x, g (f x) = ⋃ y, g y :=
hf.iSup_comp g
theorem iInter_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋂ x, g (f x) = ⋂ y, g y :=
hf.iInf_comp g
end Surjective
end Function
/-!
### Disjoint sets
-/
section Disjoint
variable {s t : Set α}
namespace Set
@[simp]
theorem disjoint_iUnion_left {ι : Sort*} {s : ι → Set α} :
Disjoint (⋃ i, s i) t ↔ ∀ i, Disjoint (s i) t :=
iSup_disjoint_iff
@[simp]
theorem disjoint_iUnion_right {ι : Sort*} {s : ι → Set α} :
Disjoint t (⋃ i, s i) ↔ ∀ i, Disjoint t (s i) :=
disjoint_iSup_iff
theorem disjoint_iUnion₂_left {s : ∀ i, κ i → Set α} {t : Set α} :
Disjoint (⋃ (i) (j), s i j) t ↔ ∀ i j, Disjoint (s i j) t :=
iSup₂_disjoint_iff
theorem disjoint_iUnion₂_right {s : Set α} {t : ∀ i, κ i → Set α} :
Disjoint s (⋃ (i) (j), t i j) ↔ ∀ i j, Disjoint s (t i j) :=
disjoint_iSup₂_iff
@[simp]
theorem disjoint_sUnion_left {S : Set (Set α)} {t : Set α} :
Disjoint (⋃₀ S) t ↔ ∀ s ∈ S, Disjoint s t :=
sSup_disjoint_iff
@[simp]
theorem disjoint_sUnion_right {s : Set α} {S : Set (Set α)} :
Disjoint s (⋃₀ S) ↔ ∀ t ∈ S, Disjoint s t :=
disjoint_sSup_iff
lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ι : Type*} {Es : ι → Set α}
(Es_union : ⋃ i, Es i = univ) (Es_disj : Pairwise fun i j ↦ Disjoint (Es i) (Es j))
(I : Set ι) :
(⋃ i ∈ I, Es i)ᶜ = ⋃ i ∈ Iᶜ, Es i := by
ext x
obtain ⟨i, hix⟩ : ∃ i, x ∈ Es i := by simp [← mem_iUnion, Es_union]
have obs : ∀ (J : Set ι), x ∈ ⋃ j ∈ J, Es j ↔ i ∈ J := by
refine fun J ↦ ⟨?_, fun i_in_J ↦ by simpa only [mem_iUnion, exists_prop] using ⟨i, i_in_J, hix⟩⟩
intro x_in_U
simp only [mem_iUnion, exists_prop] at x_in_U
obtain ⟨j, j_in_J, hjx⟩ := x_in_U
rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl]
have obs' : ∀ (J : Set ι), x ∈ (⋃ j ∈ J, Es j)ᶜ ↔ i ∉ J :=
fun J ↦ by simpa only [mem_compl_iff, not_iff_not] using obs J
rw [obs, obs', mem_compl_iff]
end Set
end Disjoint
/-! ### Intervals -/
namespace Set
lemma nonempty_iInter_Iic_iff [Preorder α] {f : ι → α} :
(⋂ i, Iic (f i)).Nonempty ↔ BddBelow (range f) := by
have : (⋂ (i : ι), Iic (f i)) = lowerBounds (range f) := by
ext c; simp [lowerBounds]
simp [this, BddBelow]
lemma nonempty_iInter_Ici_iff [Preorder α] {f : ι → α} :
(⋂ i, Ici (f i)).Nonempty ↔ BddAbove (range f) :=
nonempty_iInter_Iic_iff (α := αᵒᵈ)
variable [CompleteLattice α]
theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) :=
ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter]
theorem Iic_iInf (f : ι → α) : Iic (⨅ i, f i) = ⋂ i, Iic (f i) :=
ext fun _ => by simp only [mem_Iic, le_iInf_iff, mem_iInter]
theorem Ici_iSup₂ (f : ∀ i, κ i → α) : Ici (⨆ (i) (j), f i j) = ⋂ (i) (j), Ici (f i j) := by
simp_rw [Ici_iSup]
theorem Iic_iInf₂ (f : ∀ i, κ i → α) : Iic (⨅ (i) (j), f i j) = ⋂ (i) (j), Iic (f i j) := by
simp_rw [Iic_iInf]
theorem Ici_sSup (s : Set α) : Ici (sSup s) = ⋂ a ∈ s, Ici a := by rw [sSup_eq_iSup, Ici_iSup₂]
theorem Iic_sInf (s : Set α) : Iic (sInf s) = ⋂ a ∈ s, Iic a := by rw [sInf_eq_iInf, Iic_iInf₂]
end Set
namespace Set
variable (t : α → Set β)
theorem biUnion_diff_biUnion_subset (s₁ s₂ : Set α) :
((⋃ x ∈ s₁, t x) \ ⋃ x ∈ s₂, t x) ⊆ ⋃ x ∈ s₁ \ s₂, t x := by
simp only [diff_subset_iff, ← biUnion_union]
apply biUnion_subset_biUnion_left
rw [union_diff_self]
apply subset_union_right
/-- If `t` is an indexed family of sets, then there is a natural map from `Σ i, t i` to `⋃ i, t i`
sending `⟨i, x⟩` to `x`. -/
def sigmaToiUnion (x : Σi, t i) : ⋃ i, t i :=
⟨x.2, mem_iUnion.2 ⟨x.1, x.2.2⟩⟩
theorem sigmaToiUnion_surjective : Surjective (sigmaToiUnion t)
| ⟨b, hb⟩ =>
have : ∃ a, b ∈ t a := by simpa using hb
let ⟨a, hb⟩ := this
⟨⟨a, b, hb⟩, rfl⟩
theorem sigmaToiUnion_injective (h : Pairwise (Disjoint on t)) :
Injective (sigmaToiUnion t)
| ⟨a₁, b₁, h₁⟩, ⟨a₂, b₂, h₂⟩, eq =>
have b_eq : b₁ = b₂ := congr_arg Subtype.val eq
have a_eq : a₁ = a₂ :=
by_contradiction fun ne =>
have : b₁ ∈ t a₁ ∩ t a₂ := ⟨h₁, b_eq.symm ▸ h₂⟩
(h ne).le_bot this
Sigma.eq a_eq <| Subtype.eq <| by subst b_eq; subst a_eq; rfl
theorem sigmaToiUnion_bijective (h : Pairwise (Disjoint on t)) :
Bijective (sigmaToiUnion t) :=
⟨sigmaToiUnion_injective t h, sigmaToiUnion_surjective t⟩
/-- Equivalence from the disjoint union of a family of sets forming a partition of `β`, to `β`
itself. -/
noncomputable def sigmaEquiv (s : α → Set β) (hs : ∀ b, ∃! i, b ∈ s i) :
(Σ i, s i) ≃ β where
toFun | ⟨_, b⟩ => b
invFun b := ⟨(hs b).choose, b, (hs b).choose_spec.1⟩
left_inv | ⟨i, b, hb⟩ => Sigma.subtype_ext ((hs b).choose_spec.2 i hb).symm rfl
right_inv _ := rfl
/-- Equivalence between a disjoint union and a dependent sum. -/
noncomputable def unionEqSigmaOfDisjoint {t : α → Set β}
(h : Pairwise (Disjoint on t)) :
(⋃ i, t i) ≃ Σi, t i :=
(Equiv.ofBijective _ <| sigmaToiUnion_bijective t h).symm
theorem iUnion_ge_eq_iUnion_nat_add (u : ℕ → Set α) (n : ℕ) : ⋃ i ≥ n, u i = ⋃ i, u (i + n) :=
iSup_ge_eq_iSup_nat_add u n
theorem iInter_ge_eq_iInter_nat_add (u : ℕ → Set α) (n : ℕ) : ⋂ i ≥ n, u i = ⋂ i, u (i + n) :=
iInf_ge_eq_iInf_nat_add u n
theorem _root_.Monotone.iUnion_nat_add {f : ℕ → Set α} (hf : Monotone f) (k : ℕ) :
⋃ n, f (n + k) = ⋃ n, f n :=
hf.iSup_nat_add k
theorem _root_.Antitone.iInter_nat_add {f : ℕ → Set α} (hf : Antitone f) (k : ℕ) :
⋂ n, f (n + k) = ⋂ n, f n :=
hf.iInf_nat_add k
@[simp]
theorem iUnion_iInter_ge_nat_add (f : ℕ → Set α) (k : ℕ) :
⋃ n, ⋂ i ≥ n, f (i + k) = ⋃ n, ⋂ i ≥ n, f i :=
iSup_iInf_ge_nat_add f k
theorem union_iUnion_nat_succ (u : ℕ → Set α) : (u 0 ∪ ⋃ i, u (i + 1)) = ⋃ i, u i :=
sup_iSup_nat_succ u
theorem inter_iInter_nat_succ (u : ℕ → Set α) : (u 0 ∩ ⋂ i, u (i + 1)) = ⋂ i, u i :=
inf_iInf_nat_succ u
end Set
open Set
variable [CompleteLattice β]
theorem iSup_iUnion (s : ι → Set α) (f : α → β) : ⨆ a ∈ ⋃ i, s i, f a = ⨆ (i) (a ∈ s i), f a := by
rw [iSup_comm]
simp_rw [mem_iUnion, iSup_exists]
theorem iInf_iUnion (s : ι → Set α) (f : α → β) : ⨅ a ∈ ⋃ i, s i, f a = ⨅ (i) (a ∈ s i), f a :=
iSup_iUnion (β := βᵒᵈ) s f
theorem sSup_iUnion (t : ι → Set β) : sSup (⋃ i, t i) = ⨆ i, sSup (t i) := by
simp_rw [sSup_eq_iSup, iSup_iUnion]
theorem sSup_sUnion (s : Set (Set β)) : sSup (⋃₀ s) = ⨆ t ∈ s, sSup t := by
simp only [sUnion_eq_biUnion, sSup_eq_iSup, iSup_iUnion]
theorem sInf_sUnion (s : Set (Set β)) : sInf (⋃₀ s) = ⨅ t ∈ s, sInf t :=
sSup_sUnion (β := βᵒᵈ) s
lemma iSup_sUnion (S : Set (Set α)) (f : α → β) :
(⨆ x ∈ ⋃₀ S, f x) = ⨆ (s ∈ S) (x ∈ s), f x := by
rw [sUnion_eq_iUnion, iSup_iUnion, ← iSup_subtype'']
lemma iInf_sUnion (S : Set (Set α)) (f : α → β) :
(⨅ x ∈ ⋃₀ S, f x) = ⨅ (s ∈ S) (x ∈ s), f x := by
rw [sUnion_eq_iUnion, iInf_iUnion, ← iInf_subtype'']
lemma forall_sUnion {S : Set (Set α)} {p : α → Prop} :
(∀ x ∈ ⋃₀ S, p x) ↔ ∀ s ∈ S, ∀ x ∈ s, p x := by
simp_rw [← iInf_Prop_eq, iInf_sUnion]
lemma exists_sUnion {S : Set (Set α)} {p : α → Prop} :
(∃ x ∈ ⋃₀ S, p x) ↔ ∃ s ∈ S, ∃ x ∈ s, p x := by
simp_rw [← exists_prop, ← iSup_Prop_eq, iSup_sUnion]
| Mathlib/Data/Set/Lattice.lean | 2,177 | 2,181 | |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.MeasurableSpace.MeasurablyGenerated
import Mathlib.MeasureTheory.Measure.NullMeasurable
import Mathlib.Order.Interval.Set.Monotone
/-!
# Measure spaces
The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to
be available in `MeasureSpace` (through `MeasurableSpace`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure.
## Implementation notes
Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generateFrom_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using
`C ∪ {univ}`, but is easier to work with.
A `MeasureSpace` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable section
open Set
open Filter hiding map
open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory
open scoped symmDiff
variable {α β γ δ ι R R' : Type*}
namespace MeasureTheory
section
variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α}
instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) :=
⟨fun _s hs =>
let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
/-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/
theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by
simp only [uIoc_eq_union, mem_union, or_imp, eventually_and]
theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀ h.nullMeasurableSet hd.aedisjoint
theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀' h.nullMeasurableSet hd.aedisjoint
theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s :=
measure_inter_add_diff₀ _ ht.nullMeasurableSet
theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s :=
(add_comm _ _).trans (measure_inter_add_diff s ht)
theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by
contrapose! hs
exact ((measure_mono (subset_diff_union s t)).trans_lt
((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne
theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ←
measure_inter_add_diff s ht]
ac_rfl
theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) :
μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by
rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm]
lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) :
μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by
simpa only [symmDiff_def, sup_eq_union]
using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint
lemma measure_symmDiff_le (s t u : Set α) :
μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) :=
le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u))
theorem measure_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ :=
measure_mono_top subset_union_right (measure_diff_eq_top ht hs)
theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ :=
measure_add_measure_compl₀ h.nullMeasurableSet
theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable)
(hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by
haveI := hs.toEncodable
rw [biUnion_eq_iUnion]
exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2
theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f)
(h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) :=
measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet
theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ))
(h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h]
theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint)
(h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by
rw [sUnion_eq_biUnion, measure_biUnion hs hd h]
theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α}
(hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) :
μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by
rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype]
exact measure_biUnion₀ s.countable_toSet hd hm
theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f)
(hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) :=
measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet
/-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least
the sum of the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ)
(As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by
rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff]
intro s
simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i]
gcongr
exact iUnion_subset fun _ ↦ Subset.rfl
/-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of
the measures of the sets. -/
theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α)
{As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i))
(As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) :=
tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet)
(fun _ _ h ↦ Disjoint.aedisjoint (As_disj h))
/-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by
rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf]
lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) :
μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by
rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs]
/-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`. -/
theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β}
(hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by
simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf,
Finset.set_biUnion_preimage_singleton]
@[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] :
∑ x ∈ s, μ {x} = μ s := by
trans ∑ x ∈ s, μ (id ⁻¹' {x})
· simp
rw [sum_measure_preimage_singleton]
· simp
· simp
theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ :=
measure_congr <| diff_ae_eq_self.2 h
theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) :
μ s + μ (t \ s) = μ (s ∪ t) := by
rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self]
theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) :
μ (s \ t) = μ (s ∪ t) - μ t :=
ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm]
theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) :
μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h]
theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) :=
tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by
gcongr; apply inter_subset_right
/-- If the measure of the symmetric difference of two sets is finite,
then one has infinite measure if and only if the other one does. -/
theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by
suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞
from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩
intro u v hμuv hμu
by_contra! hμv
apply hμuv
rw [Set.symmDiff_def, eq_top_iff]
calc
∞ = μ u - μ v := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩]
_ ≤ μ (u \ v) := le_measure_diff
_ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left
/-- If the measure of the symmetric difference of two sets is finite,
then one has finite measure if and only if the other one does. -/
theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ :=
(measure_eq_top_iff_of_symmDiff hμst).ne
theorem measure_diff_lt_of_lt_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞)
{ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by
rw [measure_diff hst hs hs']; rw [add_comm] at h
exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h
theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞)
{ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by
rw [measure_diff hst hs hs', tsub_le_iff_left]
theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) :
μ s = μ t := measure_congr <|
EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff)
theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃)
(h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by
have le12 : μ s₁ ≤ μ s₂ := measure_mono h12
have le23 : μ s₂ ≤ μ s₃ := measure_mono h23
have key : μ s₃ ≤ μ s₁ :=
calc
μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)]
_ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _
_ = μ s₁ := by simp only [h_nulldiff, zero_add]
exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩
theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1
theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂)
(h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ :=
(measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2
lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) :
μ sᶜ = μ Set.univ - μ s := by
rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs]
theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s :=
measure_compl₀ h₁.nullMeasurableSet h_fin
lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null']; rwa [← diff_eq]
lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by
rw [← diff_compl, measure_diff_null ht]
@[simp]
theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by
rw [ae_le_set]
refine
⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h =>
eventuallyLE_antisymm_iff.mpr
⟨by rwa [ae_le_set, union_diff_left],
HasSubset.Subset.eventuallyLE subset_union_left⟩⟩
@[simp]
theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by
rw [union_comm, union_ae_eq_left_iff_ae_subset]
theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s)
(hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by
refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩
replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁)
replace ht : μ s ≠ ∞ := h₂ ▸ ht
rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self]
/-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/
theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ)
(ht : μ t ≠ ∞) : s =ᵐ[μ] t :=
ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht
theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α}
(hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by
refine le_antisymm (by gcongr; apply hsub) ?_
rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop)
· calc
μ (⋃ i, t i) ≤ ∞ := le_top
_ ≤ μ (s i) := hi ▸ h_le i
_ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _
push_neg at htop
set M := toMeasurable μ
have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by
refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_
· calc
μ (M (t b)) = μ (t b) := measure_toMeasurable _
_ ≤ μ (s b) := h_le b
_ ≤ μ (M (t b) ∩ M (⋃ b, s b)) :=
measure_mono <|
subset_inter ((hsub b).trans <| subset_toMeasurable _ _)
((subset_iUnion _ _).trans <| subset_toMeasurable _ _)
· measurability
· rw [measure_toMeasurable]
exact htop b
calc
μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _)
_ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm
_ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right)
_ = μ (⋃ b, s b) := measure_toMeasurable _
theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁)
(ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by
rw [union_eq_iUnion, union_eq_iUnion]
exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩)
@[simp]
theorem measure_iUnion_toMeasurable {ι : Sort*} [Countable ι] (s : ι → Set α) :
μ (⋃ i, toMeasurable μ (s i)) = μ (⋃ i, s i) :=
Eq.symm <| measure_iUnion_congr_of_subset (fun _i => subset_toMeasurable _ _) fun _i ↦
(measure_toMeasurable _).le
theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) :
μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable]
@[simp]
theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl
le_rfl
@[simp]
theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) :=
Eq.symm <|
measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _)
(measure_toMeasurable _).le
theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α}
(h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) :
(∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by
rw [← measure_biUnion_finset₀ H h]
exact measure_mono (subset_univ _)
theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : Pairwise (AEDisjoint μ on s)) : ∑' i, μ (s i) ≤ μ (univ : Set α) := by
rw [ENNReal.tsum_eq_iSup_sum]
exact iSup_le fun s =>
sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij
/-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then
one of the intersections `s i ∩ s j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α}
(μ : Measure α) {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ)
(H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by
contrapose! H
apply tsum_measure_le_measure_univ hs
intro i j hij
exact (disjoint_iff_inter_eq_empty.mpr (H i j hij)).aedisjoint
/-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and
`∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/
theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α)
{s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ)
(H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) :
∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by
contrapose! H
apply sum_measure_le_measure_univ h
intro i hi j hj hij
exact (disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)).aedisjoint
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `t` is measurable. -/
theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [← Set.not_disjoint_iff_nonempty_inter]
contrapose! h
calc
μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm
_ ≤ μ u := measure_mono (union_subset h's h't)
/-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`,
then `s` intersects `t`. Version assuming that `s` is measurable. -/
theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α}
(hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) :
(s ∩ t).Nonempty := by
rw [add_comm] at h
rw [inter_comm]
exact nonempty_inter_of_measure_lt_add μ hs h't h's h
/-- Continuity from below:
the measure of the union of a directed sequence of (not necessarily measurable) sets
is the supremum of the measures. -/
theorem _root_.Directed.measure_iUnion [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
-- WLOG, `ι = ℕ`
rcases Countable.exists_injective_nat ι with ⟨e, he⟩
generalize ht : Function.extend e s ⊥ = t
replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot he
suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by
simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot he,
Function.comp_def, Pi.bot_apply, bot_eq_empty, measure_empty] at this
exact this.trans (iSup_extend_bot he _)
clear! ι
-- The `≥` inequality is trivial
refine le_antisymm ?_ (iSup_le fun i ↦ measure_mono <| subset_iUnion _ _)
-- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T`
set T : ℕ → Set α := fun n => toMeasurable μ (t n)
set Td : ℕ → Set α := disjointed T
have hm : ∀ n, MeasurableSet (Td n) := .disjointed fun n ↦ measurableSet_toMeasurable _ _
calc
μ (⋃ n, t n) = μ (⋃ n, Td n) := by rw [iUnion_disjointed, measure_iUnion_toMeasurable]
_ ≤ ∑' n, μ (Td n) := measure_iUnion_le _
_ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum
_ ≤ ⨆ n, μ (t n) := iSup_le fun I => by
rcases hd.finset_le I with ⟨N, hN⟩
calc
(∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) :=
(measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm
_ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _)
_ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _
_ ≤ μ (t N) := measure_mono (iUnion₂_subset hN)
_ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N
/-- Continuity from below:
the measure of the union of a monotone family of sets is equal to the supremum of their measures.
The theorem assumes that the `atTop` filter on the index set is countably generated,
so it works for a family indexed by a countable type, as well as `ℝ`. -/
theorem _root_.Monotone.measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) := by
cases isEmpty_or_nonempty ι with
| inl _ => simp
| inr _ =>
rcases exists_seq_monotone_tendsto_atTop_atTop ι with ⟨x, hxm, hx⟩
rw [← hs.iUnion_comp_tendsto_atTop hx, ← Monotone.iSup_comp_tendsto_atTop _ hx]
exacts [(hs.comp hxm).directed_le.measure_iUnion, fun _ _ h ↦ measure_mono (hs h)]
theorem _root_.Antitone.measure_iUnion [Preorder ι] [IsDirected ι (· ≥ ·)]
[(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) :
μ (⋃ i, s i) = ⨆ i, μ (s i) :=
hs.dual_left.measure_iUnion
/-- Continuity from below: the measure of the union of a sequence of
(not necessarily measurable) sets is the supremum of the measures of the partial unions. -/
theorem measure_iUnion_eq_iSup_accumulate [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {f : ι → Set α} :
μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by
rw [← iUnion_accumulate]
exact monotone_accumulate.measure_iUnion
theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable)
(hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by
haveI := ht.to_subtype
rw [biUnion_eq_iUnion, hd.directed_val.measure_iUnion, ← iSup_subtype'']
/-- **Continuity from above**:
the measure of the intersection of a directed downwards countable family of measurable sets
is the infimum of the measures. -/
theorem _root_.Directed.measure_iInter [Countable ι] {s : ι → Set α}
(h : ∀ i, NullMeasurableSet (s i) μ) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) := by
rcases hfin with ⟨k, hk⟩
have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht)
rw [← ENNReal.sub_sub_cancel hk (iInf_le (fun i => μ (s i)) k), ENNReal.sub_iInf, ←
ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ←
measure_diff (iInter_subset _ k) (.iInter h) (this _ (iInter_subset _ k)),
diff_iInter, Directed.measure_iUnion]
· congr 1
refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => le_measure_diff)
rcases hd i k with ⟨j, hji, hjk⟩
use j
rw [← measure_diff hjk (h _) (this _ hjk)]
gcongr
· exact hd.mono_comp _ fun _ _ => diff_subset_diff_right
/-- **Continuity from above**:
the measure of the intersection of a monotone family of measurable sets
indexed by a type with countably generated `atBot` filter
is equal to the infimum of the measures. -/
theorem _root_.Monotone.measure_iInter [Preorder ι] [IsDirected ι (· ≥ ·)]
[(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s)
(hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) := by
refine le_antisymm (le_iInf fun i ↦ measure_mono <| iInter_subset _ _) ?_
have := hfin.nonempty
rcases exists_seq_antitone_tendsto_atTop_atBot ι with ⟨x, hxm, hx⟩
calc
⨅ i, μ (s i) ≤ ⨅ n, μ (s (x n)) := le_iInf_comp (μ ∘ s) x
_ = μ (⋂ n, s (x n)) := by
refine .symm <| (hs.comp_antitone hxm).directed_ge.measure_iInter (fun n ↦ hsm _) ?_
rcases hfin with ⟨k, hk⟩
rcases (hx.eventually_le_atBot k).exists with ⟨n, hn⟩
exact ⟨n, ne_top_of_le_ne_top hk <| measure_mono <| hs hn⟩
_ ≤ μ (⋂ i, s i) := by
refine measure_mono <| iInter_mono' fun i ↦ ?_
rcases (hx.eventually_le_atBot i).exists with ⟨n, hn⟩
exact ⟨n, hs hn⟩
/-- **Continuity from above**:
the measure of the intersection of an antitone family of measurable sets
indexed by a type with countably generated `atTop` filter
is equal to the infimum of the measures. -/
theorem _root_.Antitone.measure_iInter [Preorder ι] [IsDirected ι (· ≤ ·)]
[(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s)
(hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) :
μ (⋂ i, s i) = ⨅ i, μ (s i) :=
hs.dual_left.measure_iInter hsm hfin
/-- Continuity from above: the measure of the intersection of a sequence of
measurable sets is the infimum of the measures of the partial intersections. -/
theorem measure_iInter_eq_iInf_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α}
{μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)]
{f : ι → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (hfin : ∃ i, μ (f i) ≠ ∞) :
μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by
rw [← Antitone.measure_iInter]
· rw [iInter_comm]
exact congrArg μ <| iInter_congr fun i ↦ (biInf_const nonempty_Ici).symm
· exact fun i j h ↦ biInter_mono (Iic_subset_Iic.2 h) fun _ _ ↦ Set.Subset.rfl
· exact fun i ↦ .biInter (to_countable _) fun _ _ ↦ h _
· refine hfin.imp fun k hk ↦ ne_top_of_le_ne_top hk <| measure_mono <| iInter₂_subset k ?_
rfl
/-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily
measurable) sets is the limit of the measures. -/
theorem tendsto_measure_iUnion_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)]
{s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by
refine .of_neBot_imp fun h ↦ ?_
have := (atTop_neBot_iff.1 h).2
rw [hm.measure_iUnion]
exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm
theorem tendsto_measure_iUnion_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)]
{s : ι → Set α} (hm : Antitone s) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋃ n, s n))) :=
tendsto_measure_iUnion_atTop (ι := ιᵒᵈ) hm.dual_left
|
/-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable)
sets is the limit of the measures of the partial unions. -/
theorem tendsto_measure_iUnion_accumulate {α ι : Type*}
[Preorder ι] [IsCountablyGenerated (atTop : Filter ι)]
| Mathlib/MeasureTheory/Measure/MeasureSpace.lean | 583 | 587 |
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Eric Wieser
-/
import Mathlib.Algebra.Quaternion
import Mathlib.Analysis.InnerProductSpace.Continuous
import Mathlib.Analysis.InnerProductSpace.PiL2
import Mathlib.Topology.Algebra.Algebra
/-!
# Quaternions as a normed algebra
In this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions:
* inner product space;
* normed ring;
* normed space over `ℝ`.
We show that the norm on `ℍ[ℝ]` agrees with the euclidean norm of its components.
## Notation
The following notation is available with `open Quaternion` or `open scoped Quaternion`:
* `ℍ` : quaternions
## Tags
quaternion, normed ring, normed space, normed algebra
-/
@[inherit_doc] scoped[Quaternion] notation "ℍ" => Quaternion ℝ
open scoped RealInnerProductSpace
namespace Quaternion
instance : Inner ℝ ℍ :=
⟨fun a b => (a * star b).re⟩
theorem inner_self (a : ℍ) : ⟪a, a⟫ = normSq a :=
rfl
theorem inner_def (a b : ℍ) : ⟪a, b⟫ = (a * star b).re :=
rfl
noncomputable instance : NormedAddCommGroup ℍ :=
@InnerProductSpace.Core.toNormedAddCommGroup ℝ ℍ _ _ _
{ toInner := inferInstance
conj_inner_symm := fun x y => by simp [inner_def, mul_comm]
re_inner_nonneg := fun _ => normSq_nonneg
definite := fun _ => normSq_eq_zero.1
add_left := fun x y z => by simp only [inner_def, add_mul, add_re]
smul_left := fun x y r => by simp [inner_def] }
noncomputable instance : InnerProductSpace ℝ ℍ :=
InnerProductSpace.ofCore _
theorem normSq_eq_norm_mul_self (a : ℍ) : normSq a = ‖a‖ * ‖a‖ := by
rw [← inner_self, real_inner_self_eq_norm_mul_norm]
instance : NormOneClass ℍ :=
⟨by rw [norm_eq_sqrt_real_inner, inner_self, normSq.map_one, Real.sqrt_one]⟩
@[simp, norm_cast]
theorem norm_coe (a : ℝ) : ‖(a : ℍ)‖ = ‖a‖ := by
rw [norm_eq_sqrt_real_inner, inner_self, normSq_coe, Real.sqrt_sq_eq_abs, Real.norm_eq_abs]
@[simp, norm_cast]
theorem nnnorm_coe (a : ℝ) : ‖(a : ℍ)‖₊ = ‖a‖₊ :=
Subtype.ext <| norm_coe a
-- This does not need to be `@[simp]`, as it is a consequence of later simp lemmas.
theorem norm_star (a : ℍ) : ‖star a‖ = ‖a‖ := by
simp_rw [norm_eq_sqrt_real_inner, inner_self, normSq_star]
-- This does not need to be `@[simp]`, as it is a consequence of later simp lemmas.
theorem nnnorm_star (a : ℍ) : ‖star a‖₊ = ‖a‖₊ :=
Subtype.ext <| norm_star a
noncomputable instance : NormedDivisionRing ℍ where
dist_eq _ _ := rfl
norm_mul _ _ := by simp [norm_eq_sqrt_real_inner, inner_self]
noncomputable instance : NormedAlgebra ℝ ℍ where
norm_smul_le := norm_smul_le
toAlgebra := Quaternion.algebra
instance : CStarRing ℍ where
norm_mul_self_le x :=
le_of_eq <| Eq.symm <| (norm_mul _ _).trans <| congr_arg (· * ‖x‖) (norm_star x)
/-- Coercion from `ℂ` to `ℍ`. -/
@[coe] def coeComplex (z : ℂ) : ℍ := ⟨z.re, z.im, 0, 0⟩
instance : Coe ℂ ℍ := ⟨coeComplex⟩
@[simp, norm_cast]
theorem coeComplex_re (z : ℂ) : (z : ℍ).re = z.re :=
rfl
@[simp, norm_cast]
theorem coeComplex_imI (z : ℂ) : (z : ℍ).imI = z.im :=
rfl
@[simp, norm_cast]
theorem coeComplex_imJ (z : ℂ) : (z : ℍ).imJ = 0 :=
rfl
@[simp, norm_cast]
theorem coeComplex_imK (z : ℂ) : (z : ℍ).imK = 0 :=
rfl
@[simp, norm_cast]
theorem coeComplex_add (z w : ℂ) : ↑(z + w) = (z + w : ℍ) := by ext <;> simp
@[simp, norm_cast]
theorem coeComplex_mul (z w : ℂ) : ↑(z * w) = (z * w : ℍ) := by ext <;> simp
@[simp, norm_cast]
theorem coeComplex_zero : ((0 : ℂ) : ℍ) = 0 :=
rfl
@[simp, norm_cast]
theorem coeComplex_one : ((1 : ℂ) : ℍ) = 1 :=
rfl
@[simp, norm_cast]
theorem coe_real_complex_mul (r : ℝ) (z : ℂ) : (r • z : ℍ) = ↑r * ↑z := by ext <;> simp
@[simp, norm_cast]
theorem coeComplex_coe (r : ℝ) : ((r : ℂ) : ℍ) = r :=
rfl
/-- Coercion `ℂ →ₐ[ℝ] ℍ` as an algebra homomorphism. -/
def ofComplex : ℂ →ₐ[ℝ] ℍ where
toFun := (↑)
map_one' := rfl
map_zero' := rfl
map_add' := coeComplex_add
map_mul' := coeComplex_mul
commutes' _ := rfl
@[simp]
theorem coe_ofComplex : ⇑ofComplex = coeComplex := rfl
/-- The norm of the components as a euclidean vector equals the norm of the quaternion. -/
theorem norm_piLp_equiv_symm_equivTuple (x : ℍ) :
‖(WithLp.equiv 2 (Fin 4 → _)).symm (equivTuple ℝ x)‖ = ‖x‖ := by
rw [norm_eq_sqrt_real_inner, norm_eq_sqrt_real_inner, inner_self, normSq_def', PiLp.inner_apply,
Fin.sum_univ_four]
simp_rw [RCLike.inner_apply, starRingEnd_apply, star_trivial, ← sq]
rfl
/-- `QuaternionAlgebra.linearEquivTuple` as a `LinearIsometryEquiv`. -/
@[simps apply symm_apply]
noncomputable def linearIsometryEquivTuple : ℍ ≃ₗᵢ[ℝ] EuclideanSpace ℝ (Fin 4) :=
{ (QuaternionAlgebra.linearEquivTuple (-1 : ℝ) (0 : ℝ) (-1 : ℝ)).trans
(WithLp.linearEquiv 2 ℝ (Fin 4 → ℝ)).symm with
toFun := fun a => !₂[a.1, a.2, a.3, a.4]
invFun := fun a => ⟨a 0, a 1, a 2, a 3⟩
norm_map' := norm_piLp_equiv_symm_equivTuple }
@[continuity]
theorem continuous_coe : Continuous (coe : ℝ → ℍ) :=
continuous_algebraMap ℝ ℍ
@[continuity]
theorem continuous_normSq : Continuous (normSq : ℍ → ℝ) := by
simpa [← normSq_eq_norm_mul_self] using
(continuous_norm.mul continuous_norm : Continuous fun q : ℍ => ‖q‖ * ‖q‖)
@[continuity]
theorem continuous_re : Continuous fun q : ℍ => q.re :=
(continuous_apply 0).comp linearIsometryEquivTuple.continuous
@[continuity]
theorem continuous_imI : Continuous fun q : ℍ => q.imI :=
(continuous_apply 1).comp linearIsometryEquivTuple.continuous
@[continuity]
theorem continuous_imJ : Continuous fun q : ℍ => q.imJ :=
(continuous_apply 2).comp linearIsometryEquivTuple.continuous
@[continuity]
theorem continuous_imK : Continuous fun q : ℍ => q.imK :=
(continuous_apply 3).comp linearIsometryEquivTuple.continuous
@[continuity]
theorem continuous_im : Continuous fun q : ℍ => q.im := by
simpa only [← sub_self_re] using continuous_id.sub (continuous_coe.comp continuous_re)
instance : CompleteSpace ℍ :=
haveI : IsUniformEmbedding linearIsometryEquivTuple.toLinearEquiv.toEquiv.symm :=
linearIsometryEquivTuple.toContinuousLinearEquiv.symm.isUniformEmbedding
(completeSpace_congr this).1 inferInstance
section infinite_sum
variable {α : Type*}
@[simp, norm_cast]
theorem hasSum_coe {f : α → ℝ} {r : ℝ} : HasSum (fun a => (f a : ℍ)) (↑r : ℍ) ↔ HasSum f r :=
⟨fun h => by
simpa only using
h.map (show ℍ →ₗ[ℝ] ℝ from QuaternionAlgebra.reₗ _ _ _) continuous_re,
fun h => by simpa only using h.map (algebraMap ℝ ℍ) (continuous_algebraMap _ _)⟩
@[simp, norm_cast]
theorem summable_coe {f : α → ℝ} : (Summable fun a => (f a : ℍ)) ↔ Summable f := by
simpa only using
Summable.map_iff_of_leftInverse (algebraMap ℝ ℍ) (show ℍ →ₗ[ℝ] ℝ from
QuaternionAlgebra.reₗ _ _ _)
(continuous_algebraMap _ _) continuous_re coe_re
@[norm_cast]
theorem tsum_coe (f : α → ℝ) : (∑' a, (f a : ℍ)) = ↑(∑' a, f a) := by
by_cases hf : Summable f
· exact (hasSum_coe.mpr hf.hasSum).tsum_eq
· simp [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable (summable_coe.not.mpr hf)]
end infinite_sum
end Quaternion
| Mathlib/Analysis/Quaternion.lean | 244 | 247 | |
/-
Copyright (c) 2024 Etienne Marion. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Etienne Marion
-/
import Mathlib.Data.Finite.Prod
import Mathlib.MeasureTheory.SetSemiring
/-!
# Algebra of sets
In this file we define the notion of algebra of sets and give its basic properties. An algebra
of sets is a family of sets containing the empty set and closed by complement and binary union.
It is therefore similar to a `σ`-algebra, except that it is not necessarily closed
by countable unions.
We also define the algebra of sets generated by a family of sets and give its basic properties,
and we prove that it is countable when it is generated by a countable family. We prove that
the `σ`-algebra generated by a family of sets `𝒜` is the same as the one generated by the algebra
of sets generated by `𝒜`.
## Main definitions
* `MeasureTheory.IsSetAlgebra`: property of being an algebra of sets.
* `MeasureTheory.generateSetAlgebra`: the algebra of sets generated by a family of sets.
## Main statements
* `MeasureTheory.mem_generateSetAlgebra_elim`: If a set `s` belongs to the algebra of sets
generated by `𝒜`, then it can be written as a finite union of finite intersections of sets which
are in `𝒜` or have their complement in `𝒜`.
* `MeasureTheory.countable_generateSetAlgebra`: If a family of sets is countable then so is
the algebra of sets generated by it.
## References
* <https://en.wikipedia.org/wiki/Field_of_sets>
## Tags
algebra of sets, generated algebra of sets
-/
open MeasurableSpace Set
namespace MeasureTheory
variable {α : Type*} {𝒜 : Set (Set α)} {s t : Set α}
/-! ### Definition and basic properties of an algebra of sets -/
/-- An algebra of sets is a family of sets containing the empty set and closed by complement and
union. Consequently it is also closed by difference (see `IsSetAlgebra.diff_mem`) and intersection
(see `IsSetAlgebra.inter_mem`). -/
structure IsSetAlgebra (𝒜 : Set (Set α)) : Prop where
empty_mem : ∅ ∈ 𝒜
compl_mem : ∀ ⦃s⦄, s ∈ 𝒜 → sᶜ ∈ 𝒜
union_mem : ∀ ⦃s t⦄, s ∈ 𝒜 → t ∈ 𝒜 → s ∪ t ∈ 𝒜
namespace IsSetAlgebra
/-- An algebra of sets contains the whole set. -/
theorem univ_mem (h𝒜 : IsSetAlgebra 𝒜) : univ ∈ 𝒜 :=
compl_empty ▸ h𝒜.compl_mem h𝒜.empty_mem
/-- An algebra of sets is closed by intersection. -/
theorem inter_mem (h𝒜 : IsSetAlgebra 𝒜) (s_mem : s ∈ 𝒜) (t_mem : t ∈ 𝒜) :
s ∩ t ∈ 𝒜 :=
inter_eq_compl_compl_union_compl .. ▸
h𝒜.compl_mem (h𝒜.union_mem (h𝒜.compl_mem s_mem) (h𝒜.compl_mem t_mem))
/-- An algebra of sets is closed by difference. -/
theorem diff_mem (h𝒜 : IsSetAlgebra 𝒜) (s_mem : s ∈ 𝒜) (t_mem : t ∈ 𝒜) :
s \ t ∈ 𝒜 := h𝒜.inter_mem s_mem (h𝒜.compl_mem t_mem)
/-- An algebra of sets is a ring of sets. -/
theorem isSetRing (h𝒜 : IsSetAlgebra 𝒜) : IsSetRing 𝒜 where
empty_mem := h𝒜.empty_mem
union_mem := h𝒜.union_mem
diff_mem := fun _ _ ↦ h𝒜.diff_mem
/-- An algebra of sets is closed by finite unions. -/
theorem biUnion_mem {ι : Type*} (h𝒜 : IsSetAlgebra 𝒜) {s : ι → Set α} (S : Finset ι)
(hs : ∀ i ∈ S, s i ∈ 𝒜) : ⋃ i ∈ S, s i ∈ 𝒜 := h𝒜.isSetRing.biUnion_mem S hs
| /-- An algebra of sets is closed by finite intersections. -/
theorem biInter_mem {ι : Type*} (h𝒜 : IsSetAlgebra 𝒜) {s : ι → Set α} (S : Finset ι)
(hs : ∀ i ∈ S, s i ∈ 𝒜) : ⋂ i ∈ S, s i ∈ 𝒜 := by
by_cases h : S = ∅
· rw [h, ← Finset.set_biInter_coe, Finset.coe_empty, biInter_empty]
exact h𝒜.univ_mem
· rw [← ne_eq, ← Finset.nonempty_iff_ne_empty] at h
| Mathlib/MeasureTheory/SetAlgebra.lean | 86 | 92 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# Biproducts and binary biproducts
We introduce the notion of (finite) biproducts.
Binary biproducts are defined in `CategoryTheory.Limits.Shapes.BinaryBiproducts`.
These are slightly unusual relative to the other shapes in the library,
as they are simultaneously limits and colimits.
(Zero objects are similar; they are "biterminal".)
For results about biproducts in preadditive categories see
`CategoryTheory.Preadditive.Biproducts`.
For biproducts indexed by a `Fintype J`, a `bicone` consists of a cone point `X`
and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`,
such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
## Notation
As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for
a binary biproduct. We introduce `⨁ f` for the indexed biproduct.
## Implementation notes
Prior to https://github.com/leanprover-community/mathlib3/pull/14046,
`HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type.
As this had no pay-off (everything about limits is non-constructive in mathlib),
and occasional cost
(constructing decidability instances appropriate for constructions involving the indexing type),
we made everything classical.
-/
noncomputable section
universe w w' v u
open CategoryTheory Functor
namespace CategoryTheory.Limits
variable {J : Type w}
universe uC' uC uD' uD
variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C]
variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D]
open scoped Classical in
/-- A `c : Bicone F` is:
* an object `c.pt` and
* morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`,
* such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
-/
structure Bicone (F : J → C) where
pt : C
π : ∀ j, pt ⟶ F j
ι : ∀ j, F j ⟶ pt
ι_π : ∀ j j', ι j ≫ π j' =
if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop
attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π
@[reassoc (attr := simp)]
theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by
simpa using B.ι_π j j
@[reassoc (attr := simp)]
theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by
simpa [h] using B.ι_π j j'
variable {F : J → C}
/-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points
which commutes with the cone and cocone legs. -/
structure BiconeMorphism {F : J → C} (A B : Bicone F) where
/-- A morphism between the two vertex objects of the bicones -/
hom : A.pt ⟶ B.pt
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat
attribute [reassoc (attr := simp)] BiconeMorphism.wι BiconeMorphism.wπ
/-- The category of bicones on a given diagram. -/
@[simps]
instance Bicone.category : Category (Bicone F) where
Hom A B := BiconeMorphism A B
comp f g := { hom := f.hom ≫ g.hom }
id B := { hom := 𝟙 B.pt }
-- Porting note: if we do not have `simps` automatically generate the lemma for simplifying
-- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical
-- morphism, rather than the underlying structure.
@[ext]
theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by
cases f
cases g
congr
namespace Bicones
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
@[aesop apply safe (rule_sets := [CategoryTheory]), simps]
def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt)
(wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat)
(wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where
hom := { hom := φ.hom }
inv :=
{ hom := φ.inv
wι := fun j => φ.comp_inv_eq.mpr (wι j).symm
wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm }
variable (F) in
/-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/
@[simps]
def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] :
Bicone F ⥤ Bicone (G.obj ∘ F) where
obj A :=
{ pt := G.obj A.pt
π := fun j => G.map (A.π j)
ι := fun j => G.map (A.ι j)
ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by
rw [A.ι_π]
aesop_cat }
map f :=
{ hom := G.map f.hom
wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j]
wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] }
variable (G : C ⥤ D)
instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] :
(functoriality F G).Full where
map_surjective t :=
⟨{ hom := G.preimage t.hom
wι := fun j => G.map_injective (by simpa using t.wι j)
wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by aesop_cat⟩
instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] :
(functoriality F G).Faithful where
map_injective {_X} {_Y} f g h :=
BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h
end Bicones
namespace Bicone
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
-- Porting note: would it be okay to use this more generally?
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq
/-- Extract the cone from a bicone. -/
def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where
obj B := { pt := B.pt, π := { app := fun j => B.π j.as } }
map {_ _} F := { hom := F.hom, w := fun _ => F.wπ _ }
/-- A shorthand for `toConeFunctor.obj` -/
abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B
-- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`.
@[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl
@[simp] theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl
theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl
@[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl
/-- Extract the cocone from a bicone. -/
def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where
obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } }
map {_ _} F := { hom := F.hom, w := fun _ => F.wι _ }
/-- A shorthand for `toCoconeFunctor.obj` -/
abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B
@[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl
@[simp]
theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl
@[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl
theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl
open scoped Classical in
/-- We can turn any limit cone over a discrete collection of objects into a bicone. -/
@[simps]
def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where
pt := t.pt
π j := t.π.app ⟨j⟩
ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0)
ι_π j j' := by simp
open scoped Classical in
theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) :
t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) :=
ht.hom_ext fun j' => by
rw [ht.fac]
simp [t.ι_π]
open scoped Classical in
/-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/
@[simps]
def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) :
Bicone f where
pt := t.pt
π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0)
ι j := t.ι.app ⟨j⟩
ι_π j j' := by simp
open scoped Classical in
theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) :
t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) :=
ht.hom_ext fun j' => by
rw [ht.fac]
simp [t.ι_π]
/-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/
structure IsBilimit {F : J → C} (B : Bicone F) where
isLimit : IsLimit B.toCone
isColimit : IsColimit B.toCocone
attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit
attribute [simp] IsBilimit.mk.injEq
attribute [local ext] Bicone.IsBilimit
instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit :=
⟨fun _ _ => Bicone.IsBilimit.ext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩
section Whisker
variable {K : Type w'}
/-- Whisker a bicone with an equivalence between the indexing types. -/
@[simps]
def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where
pt := c.pt
π k := c.π (g k)
ι k := c.ι (g k)
ι_π k k' := by
simp only [c.ι_π]
split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto
/-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained
by whiskering the cone and postcomposing with a suitable isomorphism. -/
def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).toCone ≅
(Cones.postcompose (Discrete.functorComp f g).inv).obj
(c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) :=
Cones.ext (Iso.refl _) (by simp)
/-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained
by whiskering the cocone and precomposing with a suitable isomorphism. -/
def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).toCocone ≅
(Cocones.precompose (Discrete.functorComp f g).hom).obj
(c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) :=
Cocones.ext (Iso.refl _) (by simp)
/-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/
noncomputable def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).IsBilimit ≃ c.IsBilimit := by
refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩
· let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g)
let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this
exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this
· let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g)
let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this
exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this
· apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm
apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _
exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g)
· apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm
apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _
exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g)
end Whisker
end Bicone
/-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone. -/
structure LimitBicone (F : J → C) where
bicone : Bicone F
isBilimit : bicone.IsBilimit
attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit
/-- `HasBiproduct F` expresses the mere existence of a bicone which is
simultaneously a limit and a colimit of the diagram `F`. -/
class HasBiproduct (F : J → C) : Prop where mk' ::
exists_biproduct : Nonempty (LimitBicone F)
attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct
theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F :=
⟨Nonempty.intro d⟩
/-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/
def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F :=
Classical.choice HasBiproduct.exists_biproduct
/-- A bicone for `F` which is both a limit cone and a colimit cocone. -/
def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F :=
(getBiproductData F).bicone
/-- `biproduct.bicone F` is a bilimit bicone. -/
def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit :=
(getBiproductData F).isBilimit
/-- `biproduct.bicone F` is a limit cone. -/
def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone :=
(getBiproductData F).isBilimit.isLimit
/-- `biproduct.bicone F` is a colimit cocone. -/
def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone :=
(getBiproductData F).isBilimit.isColimit
instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F :=
HasLimit.mk
{ cone := (biproduct.bicone F).toCone
isLimit := biproduct.isLimit F }
instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F :=
HasColimit.mk
{ cocone := (biproduct.bicone F).toCocone
isColimit := biproduct.isColimit F }
variable (J C)
/-- `C` has biproducts of shape `J` if we have
a limit and a colimit, with the same cone points,
of every function `F : J → C`. -/
class HasBiproductsOfShape : Prop where
has_biproduct : ∀ F : J → C, HasBiproduct F
attribute [instance 100] HasBiproductsOfShape.has_biproduct
/-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C`
indexed by a finite type. -/
class HasFiniteBiproducts : Prop where
out : ∀ n, HasBiproductsOfShape (Fin n) C
attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out
variable {J}
theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) :
HasBiproductsOfShape J C :=
⟨fun F =>
let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm)
let ⟨c, hc⟩ := h
HasBiproduct.mk <| by
simpa only [Function.comp_def, e.symm_apply_apply] using
LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩
instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] :
HasBiproductsOfShape J C := by
rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩
haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n
exact hasBiproductsOfShape_of_equiv C e
instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasFiniteProducts C where
out _ := ⟨fun _ => hasLimit_of_iso Discrete.natIsoFunctor.symm⟩
instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasFiniteCoproducts C where
out _ := ⟨fun _ => hasColimit_of_iso Discrete.natIsoFunctor⟩
instance (priority := 100) hasProductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] :
HasProductsOfShape J C where
has_limit _ := hasLimit_of_iso Discrete.natIsoFunctor.symm
instance (priority := 100) hasCoproductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] :
HasCoproductsOfShape J C where
has_colimit _ := hasColimit_of_iso Discrete.natIsoFunctor
variable {C}
/-- The isomorphism between the specified limit and the specified colimit for
a functor with a bilimit. -/
def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F :=
(IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <|
IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _)
variable {J : Type w} {K : Type*}
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C]
/-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an
abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will
just use general facts about limits and colimits.) -/
abbrev biproduct (f : J → C) [HasBiproduct f] : C :=
(biproduct.bicone f).pt
@[inherit_doc biproduct]
notation "⨁ " f:20 => biproduct f
/-- The projection onto a summand of a biproduct. -/
abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b :=
(biproduct.bicone f).π b
@[simp]
theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) :
(biproduct.bicone f).π b = biproduct.π f b := rfl
/-- The inclusion into a summand of a biproduct. -/
abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f :=
(biproduct.bicone f).ι b
@[simp]
theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) :
(biproduct.bicone f).ι b = biproduct.ι f b := rfl
/-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument.
This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/
@[reassoc]
theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) :
biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by
convert (biproduct.bicone f).ι_π j j'
@[reassoc] -- Porting note: both versions proven by simp
theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) :
biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp [biproduct.ι_π]
@[reassoc (attr := simp)]
theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') :
biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [biproduct.ι_π, h]
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `biproduct.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') :
eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by
cases w
simp
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- It seems the side condition `w` is not applied by `simpNF`.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `biproduct.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') :
biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by
cases w
simp
/-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/
abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f :=
(biproduct.isLimit f).lift (Fan.mk P p)
/-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/
abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P :=
(biproduct.isColimit f).desc (Cofan.mk P p)
@[reassoc (attr := simp)]
theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) :
biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩
@[reassoc (attr := simp)]
theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) :
biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩
/-- Given a collection of maps between corresponding summands of a pair of biproducts
indexed by the same type, we obtain a map between the biproducts. -/
abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g)
(Discrete.natTrans (fun j => p j.as))
/-- An alternative to `biproduct.map` constructed via colimits.
This construction only exists in order to show it is equal to `biproduct.map`. -/
abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone
(Discrete.natTrans fun j => p j.as)
-- We put this at slightly higher priority than `biproduct.hom_ext'`,
-- to get the matrix indices in the "right" order.
@[ext 1001]
theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f)
(w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h :=
(biproduct.isLimit f).hom_ext fun j => w j.as
@[ext]
theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z)
(w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h :=
(biproduct.isColimit f).hom_ext fun j => w j.as
/-- The canonical isomorphism between the chosen biproduct and the chosen product. -/
def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _)
@[simp]
theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] :
(biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) :=
limit.hom_ext fun j => by simp [biproduct.isoProduct]
@[simp]
theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] :
(biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) :=
biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq]
/-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/
def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f :=
IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _)
@[simp]
theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] :
(biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) :=
colimit.hom_ext fun j => by simp [biproduct.isoCoproduct]
@[simp]
theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] :
(biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) :=
biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv]
/-- If a category has biproducts of a shape `J`, its `colim` and `lim` functor on diagrams over `J`
are isomorphic. -/
@[simps!]
def HasBiproductsOfShape.colimIsoLim [HasBiproductsOfShape J C] :
colim (J := Discrete J) (C := C) ≅ lim :=
NatIso.ofComponents (fun F => (Sigma.isoColimit F).symm ≪≫
(biproduct.isoCoproduct _).symm ≪≫ biproduct.isoProduct _ ≪≫ Pi.isoLimit F)
fun η => colimit.hom_ext fun ⟨i⟩ => limit.hom_ext fun ⟨j⟩ => by
classical
by_cases h : i = j <;>
simp_all [h, Sigma.isoColimit, Pi.isoLimit, biproduct.ι_π, biproduct.ι_π_assoc]
theorem biproduct.map_eq_map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
biproduct.map p = biproduct.map' p := by
classical
ext
dsimp
simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π,
Category.assoc, ← Bicone.toCone_π_app_mk, ← biproduct.bicone_π, ← Bicone.toCocone_ι_app_mk,
← biproduct.bicone_ι]
dsimp
rw [biproduct.ι_π_assoc, biproduct.ι_π]
split_ifs with h
· subst h; simp
· simp
@[reassoc (attr := simp)]
theorem biproduct.map_π {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
(j : J) : biproduct.map p ≫ biproduct.π g j = biproduct.π f j ≫ p j :=
Limits.IsLimit.map_π _ _ _ (Discrete.mk j)
@[reassoc (attr := simp)]
theorem biproduct.ι_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
(j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j := by
rw [biproduct.map_eq_map']
apply
Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone
(Discrete.natTrans fun j => p j.as) (Discrete.mk j)
@[reassoc (attr := simp)]
theorem biproduct.map_desc {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
{P : C} (k : ∀ j, g j ⟶ P) :
biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by
ext; simp
@[reassoc (attr := simp)]
theorem biproduct.lift_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] {P : C}
(k : ∀ j, P ⟶ f j) (p : ∀ j, f j ⟶ g j) :
biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by
ext; simp
/-- Given a collection of isomorphisms between corresponding summands of a pair of biproducts
indexed by the same type, we obtain an isomorphism between the biproducts. -/
@[simps]
def biproduct.mapIso {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ≅ g b) :
⨁ f ≅ ⨁ g where
hom := biproduct.map fun b => (p b).hom
inv := biproduct.map fun b => (p b).inv
instance biproduct.map_epi {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
[∀ j, Epi (p j)] : Epi (biproduct.map p) := by
classical
have : biproduct.map p =
(biproduct.isoCoproduct _).hom ≫ Sigma.map p ≫ (biproduct.isoCoproduct _).inv := by
ext
simp only [map_π, isoCoproduct_hom, isoCoproduct_inv, Category.assoc, ι_desc_assoc,
ι_colimMap_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app, colimit.ι_desc_assoc,
Cofan.mk_pt, Cofan.mk_ι_app, ι_π, ι_π_assoc]
split
all_goals simp_all
rw [this]
infer_instance
instance Pi.map_epi {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
[∀ j, Epi (p j)] : Epi (Pi.map p) := by
rw [show Pi.map p = (biproduct.isoProduct _).inv ≫ biproduct.map p ≫
(biproduct.isoProduct _).hom by aesop]
infer_instance
instance biproduct.map_mono {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
[∀ j, Mono (p j)] : Mono (biproduct.map p) := by
rw [show biproduct.map p = (biproduct.isoProduct _).hom ≫ Pi.map p ≫
(biproduct.isoProduct _).inv by aesop]
infer_instance
instance Sigma.map_mono {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
[∀ j, Mono (p j)] : Mono (Sigma.map p) := by
rw [show Sigma.map p = (biproduct.isoCoproduct _).inv ≫ biproduct.map p ≫
(biproduct.isoCoproduct _).hom by aesop]
infer_instance
/-- Two biproducts which differ by an equivalence in the indexing type,
and up to isomorphism in the factors, are isomorphic.
Unfortunately there are two natural ways to define each direction of this isomorphism
(because it is true for both products and coproducts separately).
We give the alternative definitions as lemmas below. -/
@[simps]
def biproduct.whiskerEquiv {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j)
[HasBiproduct f] [HasBiproduct g] : ⨁ f ≅ ⨁ g where
hom := biproduct.desc fun j => (w j).inv ≫ biproduct.ι g (e j)
inv := biproduct.desc fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom ≫ biproduct.ι f _
lemma biproduct.whiskerEquiv_hom_eq_lift {f : J → C} {g : K → C} (e : J ≃ K)
(w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] :
(biproduct.whiskerEquiv e w).hom =
biproduct.lift fun k => biproduct.π f (e.symm k) ≫ (w _).inv ≫ eqToHom (by simp) := by
simp only [whiskerEquiv_hom]
ext k j
by_cases h : k = e j
· subst h
simp
· simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π]
rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc]
· simp
· rintro rfl
simp at h
· exact Ne.symm h
lemma biproduct.whiskerEquiv_inv_eq_lift {f : J → C} {g : K → C} (e : J ≃ K)
(w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] :
(biproduct.whiskerEquiv e w).inv =
biproduct.lift fun j => biproduct.π g (e j) ≫ (w j).hom := by
simp only [whiskerEquiv_inv]
ext j k
by_cases h : k = e j
· subst h
simp only [ι_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm,
Equiv.symm_apply_apply, eqToHom_comp_ι, Category.assoc, bicone_ι_π_self, Category.comp_id,
lift_π, bicone_ι_π_self_assoc]
· simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π]
rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc]
· simp
· exact h
· rintro rfl
simp at h
attribute [local simp] Sigma.forall in
instance {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C)
[∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] :
HasBiproduct fun p : Σ i, f i => g p.1 p.2 where
exists_biproduct := Nonempty.intro
{ bicone :=
{ pt := ⨁ fun i => ⨁ g i
ι := fun X => biproduct.ι (g X.1) X.2 ≫ biproduct.ι (fun i => ⨁ g i) X.1
π := fun X => biproduct.π (fun i => ⨁ g i) X.1 ≫ biproduct.π (g X.1) X.2
ι_π := fun ⟨j, x⟩ ⟨j', y⟩ => by
split_ifs with h
· obtain ⟨rfl, rfl⟩ := h
simp
· simp only [Sigma.mk.inj_iff, not_and] at h
by_cases w : j = j'
· cases w
simp only [heq_eq_eq, forall_true_left] at h
simp [biproduct.ι_π_ne _ h]
· simp [biproduct.ι_π_ne_assoc _ w] }
isBilimit :=
{ isLimit := mkFanLimit _
(fun s => biproduct.lift fun b => biproduct.lift fun c => s.proj ⟨b, c⟩)
isColimit := mkCofanColimit _
(fun s => biproduct.desc fun b => biproduct.desc fun c => s.inj ⟨b, c⟩) } }
/-- An iterated biproduct is a biproduct over a sigma type. -/
@[simps]
def biproductBiproductIso {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C)
[∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] :
(⨁ fun i => ⨁ g i) ≅ (⨁ fun p : Σ i, f i => g p.1 p.2) where
hom := biproduct.lift fun ⟨i, x⟩ => biproduct.π _ i ≫ biproduct.π _ x
inv := biproduct.lift fun i => biproduct.lift fun x => biproduct.π _ (⟨i, x⟩ : Σ i, f i)
section πKernel
section
variable (f : J → C) [HasBiproduct f]
variable (p : J → Prop) [HasBiproduct (Subtype.restrict p f)]
/-- The canonical morphism from the biproduct over a restricted index type to the biproduct of
the full index type. -/
def biproduct.fromSubtype : ⨁ Subtype.restrict p f ⟶ ⨁ f :=
biproduct.desc fun j => biproduct.ι _ j.val
/-- The canonical morphism from a biproduct to the biproduct over a restriction of its index
type. -/
def biproduct.toSubtype : ⨁ f ⟶ ⨁ Subtype.restrict p f :=
biproduct.lift fun _ => biproduct.π _ _
@[reassoc (attr := simp)]
theorem biproduct.fromSubtype_π [DecidablePred p] (j : J) :
biproduct.fromSubtype f p ≫ biproduct.π f j =
if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := by
classical
ext i; dsimp
rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π]
by_cases h : p j
· rw [dif_pos h, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
· rw [dif_neg h, dif_neg (show (i : J) ≠ j from fun h₂ => h (h₂ ▸ i.2)), comp_zero]
theorem biproduct.fromSubtype_eq_lift [DecidablePred p] :
biproduct.fromSubtype f p =
biproduct.lift fun j => if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 :=
biproduct.hom_ext _ _ (by simp)
@[reassoc] -- Porting note: both version solved using simp
theorem biproduct.fromSubtype_π_subtype (j : Subtype p) :
biproduct.fromSubtype f p ≫ biproduct.π f j = biproduct.π (Subtype.restrict p f) j := by
classical
ext
rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
@[reassoc (attr := simp)]
theorem biproduct.toSubtype_π (j : Subtype p) :
biproduct.toSubtype f p ≫ biproduct.π (Subtype.restrict p f) j = biproduct.π f j :=
biproduct.lift_π _ _
@[reassoc (attr := simp)]
theorem biproduct.ι_toSubtype [DecidablePred p] (j : J) :
biproduct.ι f j ≫ biproduct.toSubtype f p =
if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := by
classical
ext i
rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π]
by_cases h : p j
· rw [dif_pos h, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
· rw [dif_neg h, dif_neg (show j ≠ i from fun h₂ => h (h₂.symm ▸ i.2)), zero_comp]
theorem biproduct.toSubtype_eq_desc [DecidablePred p] :
biproduct.toSubtype f p =
biproduct.desc fun j => if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 :=
biproduct.hom_ext' _ _ (by simp)
@[reassoc]
theorem biproduct.ι_toSubtype_subtype (j : Subtype p) :
biproduct.ι f j ≫ biproduct.toSubtype f p = biproduct.ι (Subtype.restrict p f) j := by
classical
ext
rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
@[reassoc (attr := simp)]
theorem biproduct.ι_fromSubtype (j : Subtype p) :
biproduct.ι (Subtype.restrict p f) j ≫ biproduct.fromSubtype f p = biproduct.ι f j :=
biproduct.ι_desc _ _
@[reassoc (attr := simp)]
theorem biproduct.fromSubtype_toSubtype :
biproduct.fromSubtype f p ≫ biproduct.toSubtype f p = 𝟙 (⨁ Subtype.restrict p f) := by
refine biproduct.hom_ext _ _ fun j => ?_
rw [Category.assoc, biproduct.toSubtype_π, biproduct.fromSubtype_π_subtype, Category.id_comp]
@[reassoc (attr := simp)]
theorem biproduct.toSubtype_fromSubtype [DecidablePred p] :
biproduct.toSubtype f p ≫ biproduct.fromSubtype f p =
biproduct.map fun j => if p j then 𝟙 (f j) else 0 := by
ext1 i
by_cases h : p i
· simp [h]
· simp [h]
end
section
variable (f : J → C) (i : J) [HasBiproduct f] [HasBiproduct (Subtype.restrict (fun j => j ≠ i) f)]
open scoped Classical in
/-- The kernel of `biproduct.π f i` is the inclusion from the biproduct which omits `i`
from the index set `J` into the biproduct over `J`. -/
def biproduct.isLimitFromSubtype :
IsLimit (KernelFork.ofι (biproduct.fromSubtype f fun j => j ≠ i) (by simp) :
KernelFork (biproduct.π f i)) :=
Fork.IsLimit.mk' _ fun s =>
⟨s.ι ≫ biproduct.toSubtype _ _, by
apply biproduct.hom_ext; intro j
rw [KernelFork.ι_ofι, Category.assoc, Category.assoc,
biproduct.toSubtype_fromSubtype_assoc, biproduct.map_π]
rcases Classical.em (i = j) with (rfl | h)
· rw [if_neg (Classical.not_not.2 rfl), comp_zero, comp_zero, KernelFork.condition]
· rw [if_pos (Ne.symm h), Category.comp_id], by
intro m hm
rw [← hm, KernelFork.ι_ofι, Category.assoc, biproduct.fromSubtype_toSubtype]
exact (Category.comp_id _).symm⟩
instance : HasKernel (biproduct.π f i) :=
HasLimit.mk ⟨_, biproduct.isLimitFromSubtype f i⟩
/-- The kernel of `biproduct.π f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/
@[simps!]
def kernelBiproductπIso : kernel (biproduct.π f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f :=
limit.isoLimitCone ⟨_, biproduct.isLimitFromSubtype f i⟩
open scoped Classical in
/-- The cokernel of `biproduct.ι f i` is the projection from the biproduct over the index set `J`
onto the biproduct omitting `i`. -/
def biproduct.isColimitToSubtype :
IsColimit (CokernelCofork.ofπ (biproduct.toSubtype f fun j => j ≠ i) (by simp) :
CokernelCofork (biproduct.ι f i)) :=
Cofork.IsColimit.mk' _ fun s =>
⟨biproduct.fromSubtype _ _ ≫ s.π, by
apply biproduct.hom_ext'; intro j
rw [CokernelCofork.π_ofπ, biproduct.toSubtype_fromSubtype_assoc, biproduct.ι_map_assoc]
rcases Classical.em (i = j) with (rfl | h)
· rw [if_neg (Classical.not_not.2 rfl), zero_comp, CokernelCofork.condition]
· rw [if_pos (Ne.symm h), Category.id_comp], by
intro m hm
rw [← hm, CokernelCofork.π_ofπ, ← Category.assoc, biproduct.fromSubtype_toSubtype]
exact (Category.id_comp _).symm⟩
instance : HasCokernel (biproduct.ι f i) :=
HasColimit.mk ⟨_, biproduct.isColimitToSubtype f i⟩
/-- The cokernel of `biproduct.ι f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/
@[simps!]
def cokernelBiproductιIso : cokernel (biproduct.ι f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f :=
colimit.isoColimitCocone ⟨_, biproduct.isColimitToSubtype f i⟩
end
section
-- Per https://github.com/leanprover-community/mathlib3/pull/15067, we only allow indexing in `Type 0` here.
variable {K : Type} [Finite K] [HasFiniteBiproducts C] (f : K → C)
/-- The limit cone exhibiting `⨁ Subtype.restrict pᶜ f` as the kernel of
`biproduct.toSubtype f p` -/
@[simps]
def kernelForkBiproductToSubtype (p : Set K) :
LimitCone (parallelPair (biproduct.toSubtype f p) 0) where
cone :=
KernelFork.ofι (biproduct.fromSubtype f pᶜ)
(by
classical
ext j k
simp only [Category.assoc, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc,
comp_zero, zero_comp]
rw [dif_neg k.2]
simp only [zero_comp])
isLimit :=
KernelFork.IsLimit.ofι _ _ (fun {_} g _ => g ≫ biproduct.toSubtype f pᶜ)
(by
classical
intro W' g' w
ext j
simp only [Category.assoc, biproduct.toSubtype_fromSubtype, Pi.compl_apply,
biproduct.map_π]
split_ifs with h
· simp
· replace w := w =≫ biproduct.π _ ⟨j, not_not.mp h⟩
simpa using w.symm)
(by aesop_cat)
instance (p : Set K) : HasKernel (biproduct.toSubtype f p) :=
HasLimit.mk (kernelForkBiproductToSubtype f p)
/-- The kernel of `biproduct.toSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/
@[simps!]
def kernelBiproductToSubtypeIso (p : Set K) :
kernel (biproduct.toSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f :=
limit.isoLimitCone (kernelForkBiproductToSubtype f p)
/-- The colimit cocone exhibiting `⨁ Subtype.restrict pᶜ f` as the cokernel of
`biproduct.fromSubtype f p` -/
@[simps]
def cokernelCoforkBiproductFromSubtype (p : Set K) :
ColimitCocone (parallelPair (biproduct.fromSubtype f p) 0) where
cocone :=
CokernelCofork.ofπ (biproduct.toSubtype f pᶜ)
(by
classical
ext j k
simp only [Category.assoc, Pi.compl_apply, biproduct.ι_fromSubtype_assoc,
biproduct.ι_toSubtype_assoc, comp_zero, zero_comp]
rw [dif_neg]
· simp only [zero_comp]
· exact not_not.mpr k.2)
isColimit :=
CokernelCofork.IsColimit.ofπ _ _ (fun {_} g _ => biproduct.fromSubtype f pᶜ ≫ g)
(by
classical
intro W g' w
ext j
simp only [biproduct.toSubtype_fromSubtype_assoc, Pi.compl_apply, biproduct.ι_map_assoc]
split_ifs with h
· simp
· replace w := biproduct.ι _ (⟨j, not_not.mp h⟩ : p) ≫= w
simpa using w.symm)
(by aesop_cat)
instance (p : Set K) : HasCokernel (biproduct.fromSubtype f p) :=
HasColimit.mk (cokernelCoforkBiproductFromSubtype f p)
/-- The cokernel of `biproduct.fromSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/
@[simps!]
def cokernelBiproductFromSubtypeIso (p : Set K) :
cokernel (biproduct.fromSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f :=
colimit.isoColimitCocone (cokernelCoforkBiproductFromSubtype f p)
end
end πKernel
section FiniteBiproducts
variable {J : Type} [Finite J] {K : Type} [Finite K] {C : Type u} [Category.{v} C]
[HasZeroMorphisms C] [HasFiniteBiproducts C] {f : J → C} {g : K → C}
/-- Convert a (dependently typed) matrix to a morphism of biproducts. -/
def biproduct.matrix (m : ∀ j k, f j ⟶ g k) : ⨁ f ⟶ ⨁ g :=
biproduct.desc fun j => biproduct.lift fun k => m j k
@[reassoc (attr := simp)]
theorem biproduct.matrix_π (m : ∀ j k, f j ⟶ g k) (k : K) :
biproduct.matrix m ≫ biproduct.π g k = biproduct.desc fun j => m j k := by
ext
simp [biproduct.matrix]
@[reassoc (attr := simp)]
theorem biproduct.ι_matrix (m : ∀ j k, f j ⟶ g k) (j : J) :
biproduct.ι f j ≫ biproduct.matrix m = biproduct.lift fun k => m j k := by
ext
simp [biproduct.matrix]
/-- Extract the matrix components from a morphism of biproducts. -/
def biproduct.components (m : ⨁ f ⟶ ⨁ g) (j : J) (k : K) : f j ⟶ g k :=
biproduct.ι f j ≫ m ≫ biproduct.π g k
@[simp]
theorem biproduct.matrix_components (m : ∀ j k, f j ⟶ g k) (j : J) (k : K) :
biproduct.components (biproduct.matrix m) j k = m j k := by simp [biproduct.components]
@[simp]
theorem biproduct.components_matrix (m : ⨁ f ⟶ ⨁ g) :
(biproduct.matrix fun j k => biproduct.components m j k) = m := by
ext
simp [biproduct.components]
/-- Morphisms between direct sums are matrices. -/
@[simps]
def biproduct.matrixEquiv : (⨁ f ⟶ ⨁ g) ≃ ∀ j k, f j ⟶ g k where
toFun := biproduct.components
invFun := biproduct.matrix
left_inv := biproduct.components_matrix
right_inv m := by
ext
apply biproduct.matrix_components
end FiniteBiproducts
variable {J : Type w}
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C]
variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D]
instance biproduct.ι_mono (f : J → C) [HasBiproduct f] (b : J) : IsSplitMono (biproduct.ι f b) := by
classical exact IsSplitMono.mk' { retraction := biproduct.desc <| Pi.single b (𝟙 (f b)) }
instance biproduct.π_epi (f : J → C) [HasBiproduct f] (b : J) : IsSplitEpi (biproduct.π f b) := by
classical exact IsSplitEpi.mk' { section_ := biproduct.lift <| Pi.single b (𝟙 (f b)) }
/-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/
theorem biproduct.conePointUniqueUpToIso_hom (f : J → C) [HasBiproduct f] {b : Bicone f}
(hb : b.IsBilimit) :
(hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).hom = biproduct.lift b.π :=
rfl
/-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/
theorem biproduct.conePointUniqueUpToIso_inv (f : J → C) [HasBiproduct f] {b : Bicone f}
(hb : b.IsBilimit) :
(hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).inv = biproduct.desc b.ι := by
classical
refine biproduct.hom_ext' _ _ fun j => hb.isLimit.hom_ext fun j' => ?_
rw [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp, Bicone.toCone_π_app,
biproduct.bicone_π, biproduct.ι_desc, biproduct.ι_π, b.toCone_π_app, b.ι_π]
/-- Biproducts are unique up to isomorphism. This already follows because bilimits are limits,
but in the case of biproducts we can give an isomorphism with particularly nice definitional
properties, namely that `biproduct.lift b.π` and `biproduct.desc b.ι` are inverses of each
other. -/
@[simps]
def biproduct.uniqueUpToIso (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) :
b.pt ≅ ⨁ f where
hom := biproduct.lift b.π
inv := biproduct.desc b.ι
hom_inv_id := by
rw [← biproduct.conePointUniqueUpToIso_hom f hb, ←
biproduct.conePointUniqueUpToIso_inv f hb, Iso.hom_inv_id]
inv_hom_id := by
rw [← biproduct.conePointUniqueUpToIso_hom f hb, ←
biproduct.conePointUniqueUpToIso_inv f hb, Iso.inv_hom_id]
variable (C)
-- see Note [lower instance priority]
/-- A category with finite biproducts has a zero object. -/
instance (priority := 100) hasZeroObject_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasZeroObject C := by
refine ⟨⟨biproduct Empty.elim, fun X => ⟨⟨⟨0⟩, ?_⟩⟩, fun X => ⟨⟨⟨0⟩, ?_⟩⟩⟩⟩
· intro a; apply biproduct.hom_ext'; simp
· intro a; apply biproduct.hom_ext; simp
section
variable {C}
attribute [local simp] eq_iff_true_of_subsingleton in
/-- The limit bicone for the biproduct over an index type with exactly one term. -/
@[simps]
def limitBiconeOfUnique [Unique J] (f : J → C) : LimitBicone f where
bicone :=
{ pt := f default
π := fun j => eqToHom (by congr; rw [← Unique.uniq] )
ι := fun j => eqToHom (by congr; rw [← Unique.uniq] ) }
isBilimit :=
{ isLimit := (limitConeOfUnique f).isLimit
isColimit := (colimitCoconeOfUnique f).isColimit }
instance (priority := 100) hasBiproduct_unique [Subsingleton J] [Nonempty J] (f : J → C) :
HasBiproduct f :=
let ⟨_⟩ := nonempty_unique J; .mk (limitBiconeOfUnique f)
/-- A biproduct over an index type with exactly one term is just the object over that term. -/
@[simps!]
def biproductUniqueIso [Unique J] (f : J → C) : ⨁ f ≅ f default :=
(biproduct.uniqueUpToIso _ (limitBiconeOfUnique f).isBilimit).symm
end
end CategoryTheory.Limits
| Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean | 1,818 | 1,821 | |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-!
# Integral average of a function
In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average
value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it
is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability
measure, then the average of any function is equal to its integral.
For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For
average w.r.t. the volume, one can omit `∂volume`.
Both have a version for the Lebesgue integral rather than Bochner.
We prove several version of the first moment method: An integrable function is below/above its
average on a set of positive measure:
* `measure_le_setLAverage_pos` for the Lebesgue integral
* `measure_le_setAverage_pos` for the Bochner integral
## Implementation notes
The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner
integrals work for the average without modifications. For theorems that require integrability of a
function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`.
## Tags
integral, center mass, average value
-/
open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function
open scoped Topology ENNReal Convex
variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α}
{s t : Set α}
/-!
### Average value of a function w.r.t. a measure
The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation:
`⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total
measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if
`f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to
its integral.
-/
namespace MeasureTheory
section ENNReal
variable (μ) {f g : α → ℝ≥0∞}
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure.
It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite
measure. In a probability space, the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s`
has measure `1`, then the average of any function is equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If
`s` has measure `1`, then the average of any function is equal to its integral. -/
notation3 (prettyPrint := false)
"⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r
@[simp]
theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero]
@[simp]
theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage]
theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl
theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by
rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul]
theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) :
⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero]
· rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq
theorem setLAverage_eq' (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [laverage_eq', restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq'
variable {μ}
theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by
simp only [laverage_eq, lintegral_congr_ae h]
theorem setLAverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by
simp only [setLAverage_eq, setLIntegral_congr h, measure_congr h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr := setLAverage_congr
theorem setLAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by
simp only [laverage_eq, setLIntegral_congr_fun hs h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr_fun := setLAverage_congr_fun
theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [laverage_eq]
exact div_lt_top hf (measure_univ_ne_zero.2 hμ)
theorem setLAverage_lt_top : ∫⁻ x in s, f x ∂μ ≠ ∞ → ⨍⁻ x in s, f x ∂μ < ∞ :=
laverage_lt_top
@[deprecated (since := "2025-04-22")] alias setLaverage_lt_top := setLAverage_lt_top
theorem laverage_add_measure :
⨍⁻ x, f x ∂(μ + ν) =
μ univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂μ + ν univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂ν := by
by_cases hμ : IsFiniteMeasure μ; swap
· rw [not_isFiniteMeasure_iff] at hμ
simp [laverage_eq, hμ]
by_cases hν : IsFiniteMeasure ν; swap
· rw [not_isFiniteMeasure_iff] at hν
simp [laverage_eq, hν]
haveI := hμ; haveI := hν
simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div,
← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq]
theorem measure_mul_setLAverage (f : α → ℝ≥0∞) (h : μ s ≠ ∞) :
μ s * ⨍⁻ x in s, f x ∂μ = ∫⁻ x in s, f x ∂μ := by
have := Fact.mk h.lt_top
rw [← measure_mul_laverage, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias measure_mul_setLaverage := measure_mul_setLAverage
theorem laverage_union (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
⨍⁻ x in s ∪ t, f x ∂μ =
μ s / (μ s + μ t) * ⨍⁻ x in s, f x ∂μ + μ t / (μ s + μ t) * ⨍⁻ x in t, f x ∂μ := by
rw [restrict_union₀ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ]
theorem laverage_union_mem_openSegment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in t, f x ∂μ) := by
refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), ENNReal.div_pos hs₀ <| add_ne_top.2 ⟨hsμ, htμ⟩,
ENNReal.div_pos ht₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_union_mem_segment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ [⨍⁻ x in s, f x ∂μ -[ℝ≥0∞] ⨍⁻ x in t, f x ∂μ] := by
by_cases hs₀ : μ s = 0
· rw [← ae_eq_empty] at hs₀
rw [restrict_congr_set (hs₀.union EventuallyEq.rfl), empty_union]
exact right_mem_segment _ _ _
· refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_mem_openSegment_compl_self [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ)
(hs₀ : μ s ≠ 0) (hsc₀ : μ sᶜ ≠ 0) :
⨍⁻ x, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in sᶜ, f x ∂μ) := by
simpa only [union_compl_self, restrict_univ] using
laverage_union_mem_openSegment aedisjoint_compl_right hs.compl hs₀ hsc₀ (measure_ne_top _ _)
(measure_ne_top _ _)
@[simp]
theorem laverage_const (μ : Measure α) [IsFiniteMeasure μ] [h : NeZero μ] (c : ℝ≥0∞) :
⨍⁻ _x, c ∂μ = c := by
simp only [laverage, lintegral_const, measure_univ, mul_one]
theorem setLAverage_const (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) (c : ℝ≥0∞) : ⨍⁻ _x in s, c ∂μ = c := by
simp only [setLAverage_eq, lintegral_const, Measure.restrict_apply, MeasurableSet.univ,
univ_inter, div_eq_mul_inv, mul_assoc, ENNReal.mul_inv_cancel hs₀ hs, mul_one]
@[deprecated (since := "2025-04-22")] alias setLaverage_const := setLAverage_const
theorem laverage_one [IsFiniteMeasure μ] [NeZero μ] : ⨍⁻ _x, (1 : ℝ≥0∞) ∂μ = 1 :=
laverage_const _ _
theorem setLAverage_one (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) : ⨍⁻ _x in s, (1 : ℝ≥0∞) ∂μ = 1 :=
setLAverage_const hs₀ hs _
@[deprecated (since := "2025-04-22")] alias setLaverage_one := setLAverage_one
@[simp]
theorem laverage_mul_measure_univ (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
(⨍⁻ (a : α), f a ∂μ) * μ univ = ∫⁻ x, f x ∂μ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [laverage_eq, ENNReal.div_mul_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
theorem lintegral_laverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
∫⁻ _x, ⨍⁻ a, f a ∂μ ∂μ = ∫⁻ x, f x ∂μ := by
simp
theorem setLIntegral_setLAverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) (s : Set α) :
∫⁻ _x in s, ⨍⁻ a in s, f a ∂μ ∂μ = ∫⁻ x in s, f x ∂μ :=
lintegral_laverage _ _
@[deprecated (since := "2025-04-22")] alias setLintegral_setLaverage := setLIntegral_setLAverage
end ENNReal
section NormedAddCommGroup
variable (μ)
variable {f g : α → E}
/-- Average value of a function `f` w.r.t. a measure `μ`, denoted `⨍ x, f x ∂μ`.
It is equal to `(μ.real univ)⁻¹ • ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable or
if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is
equal to its integral.
For the average on a set, use `⨍ x in s, f x ∂μ`, defined as `⨍ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def average (f : α → E) :=
∫ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of a function `f` w.r.t. a measure `μ`.
It is equal to `(μ.real univ)⁻¹ • ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable or
if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is
equal to its integral.
For the average on a set, use `⨍ x in s, f x ∂μ`, defined as `⨍ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => average μ r
/-- Average value of a function `f` w.r.t. to the standard measure.
It is equal to `(volume.real univ)⁻¹ * ∫ x, f x`, so it takes value zero if `f` is not integrable
or if the space has infinite measure. In a probability space, the average of any function is equal
to its integral.
For the average on a set, use `⨍ x in s, f x`, defined as `⨍ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍ "(...)", "r:60:(scoped f => average volume f) => r
/-- Average value of a function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ.real s)⁻¹ * ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable on
`s` or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is
equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => average (Measure.restrict μ s) r
/-- Average value of a function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume.real s)⁻¹ * ∫ x, f x`, so it takes value zero `f` is not integrable on `s`
or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to
its integral. -/
notation3 "⨍ "(...)" in "s", "r:60:(scoped f => average (Measure.restrict volume s) f) => r
@[simp]
theorem average_zero : ⨍ _, (0 : E) ∂μ = 0 := by rw [average, integral_zero]
@[simp]
theorem average_zero_measure (f : α → E) : ⨍ x, f x ∂(0 : Measure α) = 0 := by
rw [average, smul_zero, integral_zero_measure]
@[simp]
theorem average_neg (f : α → E) : ⨍ x, -f x ∂μ = -⨍ x, f x ∂μ :=
integral_neg f
theorem average_eq' (f : α → E) : ⨍ x, f x ∂μ = ∫ x, f x ∂(μ univ)⁻¹ • μ :=
rfl
theorem average_eq (f : α → E) : ⨍ x, f x ∂μ = (μ.real univ)⁻¹ • ∫ x, f x ∂μ := by
rw [average_eq', integral_smul_measure, ENNReal.toReal_inv, measureReal_def]
theorem average_eq_integral [IsProbabilityMeasure μ] (f : α → E) : ⨍ x, f x ∂μ = ∫ x, f x ∂μ := by
rw [average, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_smul_average [IsFiniteMeasure μ] (f : α → E) :
μ.real univ • ⨍ x, f x ∂μ = ∫ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, integral_zero_measure, average_zero_measure, smul_zero]
· rw [average_eq, smul_inv_smul₀]
refine (ENNReal.toReal_pos ?_ <| measure_ne_top _ _).ne'
rwa [Ne, measure_univ_eq_zero]
theorem setAverage_eq (f : α → E) (s : Set α) :
⨍ x in s, f x ∂μ = (μ.real s)⁻¹ • ∫ x in s, f x ∂μ := by
rw [average_eq, measureReal_restrict_apply_univ]
theorem setAverage_eq' (f : α → E) (s : Set α) :
| ⨍ x in s, f x ∂μ = ∫ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [average_eq', restrict_apply_univ]
| Mathlib/MeasureTheory/Integral/Average.lean | 336 | 337 |
/-
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) :
| Mathlib/RingTheory/Regular/RegularSequence.lean | 60 | 63 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.Algebra.Prod
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.MonoidAlgebra.Basic
import Mathlib.Algebra.Polynomial.Eval.Algebra
import Mathlib.Algebra.Polynomial.Eval.Degree
import Mathlib.Algebra.Polynomial.Monomial
/-!
# Theory of univariate polynomials
We show that `A[X]` is an R-algebra when `A` is an R-algebra.
We promote `eval₂` to an algebra hom in `aeval`.
-/
assert_not_exists Ideal
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B : Type*} {a b : R} {n : ℕ}
section CommSemiring
variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
variable {p q r : R[X]}
/-- Note that this instance also provides `Algebra R R[X]`. -/
instance algebraOfAlgebra : Algebra R A[X] where
smul_def' r p :=
toFinsupp_injective <| by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply]
rw [toFinsupp_smul, toFinsupp_mul, toFinsupp_C]
exact Algebra.smul_def' _ _
commutes' r p :=
toFinsupp_injective <| by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply]
simp_rw [toFinsupp_mul, toFinsupp_C]
convert Algebra.commutes' r p.toFinsupp
algebraMap := C.comp (algebraMap R A)
@[simp]
theorem algebraMap_apply (r : R) : algebraMap R A[X] r = C (algebraMap R A r) :=
rfl
@[simp]
theorem toFinsupp_algebraMap (r : R) : (algebraMap R A[X] r).toFinsupp = algebraMap R _ r :=
show toFinsupp (C (algebraMap _ _ r)) = _ by
rw [toFinsupp_C]
rfl
theorem ofFinsupp_algebraMap (r : R) : (⟨algebraMap R _ r⟩ : A[X]) = algebraMap R A[X] r :=
toFinsupp_injective (toFinsupp_algebraMap _).symm
/-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[X]`.
(But note that `C` is defined when `R` is not necessarily commutative, in which case
`algebraMap` is not available.)
-/
theorem C_eq_algebraMap (r : R) : C r = algebraMap R R[X] r :=
rfl
@[simp]
theorem algebraMap_eq : algebraMap R R[X] = C :=
rfl
/-- `Polynomial.C` as an `AlgHom`. -/
@[simps! apply]
def CAlgHom : A →ₐ[R] A[X] where
toRingHom := C
commutes' _ := rfl
/-- Extensionality lemma for algebra maps out of `A'[X]` over a smaller base ring than `A'`
-/
@[ext 1100]
theorem algHom_ext' {f g : A[X] →ₐ[R] B}
(hC : f.comp CAlgHom = g.comp CAlgHom)
(hX : f X = g X) : f = g :=
AlgHom.coe_ringHom_injective (ringHom_ext' (congr_arg AlgHom.toRingHom hC) hX)
variable (R) in
open AddMonoidAlgebra in
/-- Algebra isomorphism between `R[X]` and `R[ℕ]`. This is just an
implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/
@[simps!]
def toFinsuppIsoAlg : R[X] ≃ₐ[R] R[ℕ] :=
{ toFinsuppIso R with
commutes' := fun r => by
dsimp }
instance subalgebraNontrivial [Nontrivial A] : Nontrivial (Subalgebra R A[X]) :=
⟨⟨⊥, ⊤, by
rw [Ne, SetLike.ext_iff, not_forall]
refine ⟨X, ?_⟩
simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true, Algebra.mem_top,
algebraMap_apply, not_forall]
intro x
rw [ext_iff, not_forall]
refine ⟨1, ?_⟩
simp [coeff_C]⟩⟩
@[simp]
theorem algHom_eval₂_algebraMap {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B]
[Algebra R A] [Algebra R B] (p : R[X]) (f : A →ₐ[R] B) (a : A) :
f (eval₂ (algebraMap R A) a p) = eval₂ (algebraMap R B) (f a) p := by
simp only [eval₂_eq_sum, sum_def]
simp only [map_sum, map_mul, map_pow, eq_intCast, map_intCast, AlgHom.commutes]
@[simp]
theorem eval₂_algebraMap_X {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (p : R[X])
(f : R[X] →ₐ[R] A) : eval₂ (algebraMap R A) (f X) p = f p := by
conv_rhs => rw [← Polynomial.sum_C_mul_X_pow_eq p]
simp only [eval₂_eq_sum, sum_def]
simp only [map_sum, map_mul, map_pow, eq_intCast, map_intCast]
simp [Polynomial.C_eq_algebraMap]
-- these used to be about `algebraMap ℤ R`, but now the simp-normal form is `Int.castRingHom R`.
@[simp]
theorem ringHom_eval₂_intCastRingHom {R S : Type*} [Ring R] [Ring S] (p : ℤ[X]) (f : R →+* S)
(r : R) : f (eval₂ (Int.castRingHom R) r p) = eval₂ (Int.castRingHom S) (f r) p :=
algHom_eval₂_algebraMap p f.toIntAlgHom r
@[simp]
theorem eval₂_intCastRingHom_X {R : Type*} [Ring R] (p : ℤ[X]) (f : ℤ[X] →+* R) :
eval₂ (Int.castRingHom R) (f X) p = f p :=
eval₂_algebraMap_X p f.toIntAlgHom
/-- `Polynomial.eval₂` as an `AlgHom` for noncommutative algebras.
This is `Polynomial.eval₂RingHom'` for `AlgHom`s. -/
@[simps!]
def eval₂AlgHom' (f : A →ₐ[R] B) (b : B) (hf : ∀ a, Commute (f a) b) : A[X] →ₐ[R] B where
toRingHom := eval₂RingHom' f b hf
commutes' _ := (eval₂_C _ _).trans (f.commutes _)
section Map
/-- `Polynomial.map` as an `AlgHom` for noncommutative algebras.
This is the algebra version of `Polynomial.mapRingHom`. -/
def mapAlgHom (f : A →ₐ[R] B) : Polynomial A →ₐ[R] Polynomial B where
toRingHom := mapRingHom f.toRingHom
commutes' := by simp
@[simp]
theorem coe_mapAlgHom (f : A →ₐ[R] B) : ⇑(mapAlgHom f) = map f :=
rfl
@[simp]
theorem mapAlgHom_id : mapAlgHom (AlgHom.id R A) = AlgHom.id R (Polynomial A) :=
AlgHom.ext fun _x => map_id
@[simp]
theorem mapAlgHom_coe_ringHom (f : A →ₐ[R] B) :
↑(mapAlgHom f : _ →ₐ[R] Polynomial B) = (mapRingHom ↑f : Polynomial A →+* Polynomial B) :=
rfl
@[simp]
theorem mapAlgHom_comp (C : Type z) [Semiring C] [Algebra R C] (f : B →ₐ[R] C) (g : A →ₐ[R] B) :
(mapAlgHom f).comp (mapAlgHom g) = mapAlgHom (f.comp g) := by
apply AlgHom.ext
intro x
simp [AlgHom.comp_algebraMap, map_map]
congr
theorem mapAlgHom_eq_eval₂AlgHom'_CAlgHom (f : A →ₐ[R] B) : mapAlgHom f = eval₂AlgHom'
(CAlgHom.comp f) X (fun a => (commute_X (C (f a))).symm) := by
apply AlgHom.ext
intro x
congr
/-- If `A` and `B` are isomorphic as `R`-algebras, then so are their polynomial rings -/
def mapAlgEquiv (f : A ≃ₐ[R] B) : Polynomial A ≃ₐ[R] Polynomial B :=
AlgEquiv.ofAlgHom (mapAlgHom f.toAlgHom) (mapAlgHom f.symm.toAlgHom) (by simp) (by simp)
@[simp]
theorem coe_mapAlgEquiv (f : A ≃ₐ[R] B) : ⇑(mapAlgEquiv f) = map f :=
rfl
@[simp]
theorem mapAlgEquiv_id : mapAlgEquiv (@AlgEquiv.refl R A _ _ _) = AlgEquiv.refl :=
AlgEquiv.ext fun _x => map_id
@[simp]
theorem mapAlgEquiv_coe_ringHom (f : A ≃ₐ[R] B) :
↑(mapAlgEquiv f : _ ≃ₐ[R] Polynomial B) = (mapRingHom ↑f : Polynomial A →+* Polynomial B) :=
rfl
@[simp]
theorem mapAlgEquiv_toAlgHom (f : A ≃ₐ[R] B) :
(mapAlgEquiv f : Polynomial A →ₐ[R] Polynomial B) = mapAlgHom f := rfl
@[simp]
theorem mapAlgEquiv_comp (C : Type*) [Semiring C] [Algebra R C] (f : A ≃ₐ[R] B) (g : B ≃ₐ[R] C) :
(mapAlgEquiv f).trans (mapAlgEquiv g) = mapAlgEquiv (f.trans g) := by
apply AlgEquiv.ext
intro x
simp [AlgEquiv.trans_apply, map_map]
congr
end Map
end CommSemiring
section aeval
variable [CommSemiring R] [Semiring A] [CommSemiring A'] [Semiring B]
variable [Algebra R A] [Algebra R B]
variable {p q : R[X]} (x : A)
/-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is
the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`.
This is a stronger variant of the linear map `Polynomial.leval`. -/
def aeval : R[X] →ₐ[R] A :=
eval₂AlgHom' (Algebra.ofId _ _) x (Algebra.commutes · _)
@[ext 1200]
theorem algHom_ext {f g : R[X] →ₐ[R] B} (hX : f X = g X) :
f = g :=
algHom_ext' (Subsingleton.elim _ _) hX
theorem aeval_def (p : R[X]) : aeval x p = eval₂ (algebraMap R A) x p :=
rfl
theorem aeval_zero : aeval x (0 : R[X]) = 0 :=
map_zero (aeval x)
@[simp]
theorem aeval_X : aeval x (X : R[X]) = x :=
eval₂_X _ x
@[simp]
theorem aeval_C (r : R) : aeval x (C r) = algebraMap R A r :=
eval₂_C _ x
@[simp]
theorem aeval_monomial {n : ℕ} {r : R} : aeval x (monomial n r) = algebraMap _ _ r * x ^ n :=
eval₂_monomial _ _
theorem aeval_X_pow {n : ℕ} : aeval x ((X : R[X]) ^ n) = x ^ n :=
eval₂_X_pow _ _
theorem aeval_add : aeval x (p + q) = aeval x p + aeval x q :=
map_add _ _ _
theorem aeval_one : aeval x (1 : R[X]) = 1 :=
map_one _
theorem aeval_natCast (n : ℕ) : aeval x (n : R[X]) = n :=
map_natCast _ _
theorem aeval_mul : aeval x (p * q) = aeval x p * aeval x q :=
map_mul _ _ _
theorem comp_eq_aeval : p.comp q = aeval q p := rfl
theorem aeval_comp {A : Type*} [Semiring A] [Algebra R A] (x : A) :
aeval x (p.comp q) = aeval (aeval x q) p :=
eval₂_comp' x p q
/-- Two polynomials `p` and `q` such that `p(q(X))=X` and `q(p(X))=X`
induces an automorphism of the polynomial algebra. -/
@[simps!]
def algEquivOfCompEqX (p q : R[X]) (hpq : p.comp q = X) (hqp : q.comp p = X) : R[X] ≃ₐ[R] R[X] := by
refine AlgEquiv.ofAlgHom (aeval p) (aeval q) ?_ ?_ <;>
exact AlgHom.ext fun _ ↦ by simp [← comp_eq_aeval, comp_assoc, hpq, hqp]
@[simp]
theorem algEquivOfCompEqX_eq_iff (p q p' q' : R[X])
(hpq : p.comp q = X) (hqp : q.comp p = X) (hpq' : p'.comp q' = X) (hqp' : q'.comp p' = X) :
algEquivOfCompEqX p q hpq hqp = algEquivOfCompEqX p' q' hpq' hqp' ↔ p = p' :=
⟨fun h ↦ by simpa using congr($h X), fun h ↦ by ext1; simp [h]⟩
@[simp]
theorem algEquivOfCompEqX_symm (p q : R[X]) (hpq : p.comp q = X) (hqp : q.comp p = X) :
(algEquivOfCompEqX p q hpq hqp).symm = algEquivOfCompEqX q p hqp hpq := rfl
/-- The automorphism of the polynomial algebra given by `p(X) ↦ p(a * X + b)`,
with inverse `p(X) ↦ p(a⁻¹ * (X - b))`. -/
@[simps!]
def algEquivCMulXAddC {R : Type*} [CommRing R] (a b : R) [Invertible a] : R[X] ≃ₐ[R] R[X] :=
algEquivOfCompEqX (C a * X + C b) (C ⅟ a * (X - C b))
(by simp [← C_mul, ← mul_assoc]) (by simp [← C_mul, ← mul_assoc])
theorem algEquivCMulXAddC_symm_eq {R : Type*} [CommRing R] (a b : R) [Invertible a] :
(algEquivCMulXAddC a b).symm = algEquivCMulXAddC (⅟ a) (- ⅟ a * b) := by
ext p : 1
simp only [algEquivCMulXAddC_symm_apply, neg_mul, algEquivCMulXAddC_apply, map_neg, map_mul]
congr
simp [mul_add, sub_eq_add_neg]
/-- The automorphism of the polynomial algebra given by `p(X) ↦ p(X+t)`,
with inverse `p(X) ↦ p(X-t)`. -/
@[simps!]
def algEquivAevalXAddC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] :=
algEquivOfCompEqX (X + C t) (X - C t) (by simp) (by simp)
@[simp]
theorem algEquivAevalXAddC_eq_iff {R : Type*} [CommRing R] (t t' : R) :
algEquivAevalXAddC t = algEquivAevalXAddC t' ↔ t = t' := by
simp [algEquivAevalXAddC]
@[simp]
theorem algEquivAevalXAddC_symm {R : Type*} [CommRing R] (t : R) :
(algEquivAevalXAddC t).symm = algEquivAevalXAddC (-t) := by
simp [algEquivAevalXAddC, sub_eq_add_neg]
/-- The involutive automorphism of the polynomial algebra given by `p(X) ↦ p(-X)`. -/
@[simps!]
def algEquivAevalNegX {R : Type*} [CommRing R] : R[X] ≃ₐ[R] R[X] :=
algEquivOfCompEqX (-X) (-X) (by simp) (by simp)
theorem comp_neg_X_comp_neg_X {R : Type*} [CommRing R] (p : R[X]) :
(p.comp (-X)).comp (-X) = p := by
rw [comp_assoc]
simp only [neg_comp, X_comp, neg_neg, comp_X]
theorem aeval_algHom (f : A →ₐ[R] B) (x : A) : aeval (f x) = f.comp (aeval x) :=
algHom_ext <| by simp only [aeval_X, AlgHom.comp_apply]
@[simp]
theorem aeval_X_left : aeval (X : R[X]) = AlgHom.id R R[X] :=
algHom_ext <| aeval_X X
theorem aeval_X_left_apply (p : R[X]) : aeval X p = p :=
AlgHom.congr_fun (@aeval_X_left R _) p
theorem eval_unique (φ : R[X] →ₐ[R] A) (p) : φ p = eval₂ (algebraMap R A) (φ X) p := by
rw [← aeval_def, aeval_algHom, aeval_X_left, AlgHom.comp_id]
theorem aeval_algHom_apply {F : Type*} [FunLike F A B] [AlgHomClass F R A B]
(f : F) (x : A) (p : R[X]) :
aeval (f x) p = f (aeval x p) := by
refine Polynomial.induction_on p (by simp [AlgHomClass.commutes]) (fun p q hp hq => ?_)
(by simp [AlgHomClass.commutes])
rw [map_add, hp, hq, ← map_add, ← map_add]
@[simp]
lemma coe_aeval_mk_apply {S : Subalgebra R A} (h : x ∈ S) :
(aeval (⟨x, h⟩ : S) p : A) = aeval x p :=
(aeval_algHom_apply S.val (⟨x, h⟩ : S) p).symm
theorem aeval_algEquiv (f : A ≃ₐ[R] B) (x : A) : aeval (f x) = (f : A →ₐ[R] B).comp (aeval x) :=
aeval_algHom (f : A →ₐ[R] B) x
theorem aeval_algebraMap_apply_eq_algebraMap_eval (x : R) (p : R[X]) :
aeval (algebraMap R A x) p = algebraMap R A (p.eval x) :=
aeval_algHom_apply (Algebra.ofId R A) x p
/-- Polynomial evaluation on a pair is a product of the evaluations on the components. -/
theorem aeval_prod (x : A × B) : aeval (R := R) x = (aeval x.1).prod (aeval x.2) :=
aeval_algHom (.fst R A B) x ▸ aeval_algHom (.snd R A B) x ▸
(aeval x).prod_comp (.fst R A B) (.snd R A B)
/-- Polynomial evaluation on a pair is a pair of evaluations. -/
theorem aeval_prod_apply (x : A × B) (p : Polynomial R) :
p.aeval x = (p.aeval x.1, p.aeval x.2) := by simp [aeval_prod]
section Pi
variable {I : Type*} {A : I → Type*} [∀ i, Semiring (A i)] [∀ i, Algebra R (A i)]
variable (x : Π i, A i) (p : R[X])
/-- Polynomial evaluation on an indexed tuple is the indexed product of the evaluations
on the components.
Generalizes `Polynomial.aeval_prod` to indexed products. -/
theorem aeval_pi (x : Π i, A i) : aeval (R := R) x = Pi.algHom R A (fun i ↦ aeval (x i)) :=
(funext fun i ↦ aeval_algHom (Pi.evalAlgHom R A i) x) ▸
(Pi.algHom_comp R A (Pi.evalAlgHom R A) (aeval x))
theorem aeval_pi_apply₂ (j : I) : p.aeval x j = p.aeval (x j) :=
aeval_pi (R := R) x ▸ Pi.algHom_apply R A (fun i ↦ aeval (x i)) p j
/-- Polynomial evaluation on an indexed tuple is the indexed tuple of the evaluations
on the components.
Generalizes `Polynomial.aeval_prod_apply` to indexed products. -/
theorem aeval_pi_apply : p.aeval x = fun j ↦ p.aeval (x j) :=
funext fun j ↦ aeval_pi_apply₂ x p j
end Pi
@[simp]
theorem coe_aeval_eq_eval (r : R) : (aeval r : R[X] → R) = eval r :=
rfl
@[simp]
theorem coe_aeval_eq_evalRingHom (x : R) :
((aeval x : R[X] →ₐ[R] R) : R[X] →+* R) = evalRingHom x :=
rfl
@[simp]
theorem aeval_fn_apply {X : Type*} (g : R[X]) (f : X → R) (x : X) :
((aeval f) g) x = aeval (f x) g :=
(aeval_algHom_apply (Pi.evalAlgHom R (fun _ => R) x) f g).symm
@[norm_cast]
theorem aeval_subalgebra_coe (g : R[X]) {A : Type*} [Semiring A] [Algebra R A] (s : Subalgebra R A)
(f : s) : (aeval f g : A) = aeval (f : A) g :=
(aeval_algHom_apply s.val f g).symm
theorem coeff_zero_eq_aeval_zero (p : R[X]) : p.coeff 0 = aeval 0 p := by
simp [coeff_zero_eq_eval_zero]
theorem coeff_zero_eq_aeval_zero' (p : R[X]) : algebraMap R A (p.coeff 0) = aeval (0 : A) p := by
simp [aeval_def]
theorem map_aeval_eq_aeval_map {S T U : Type*} [Semiring S] [CommSemiring T] [Semiring U]
[Algebra R S] [Algebra T U] {φ : R →+* T} {ψ : S →+* U}
(h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) (p : R[X]) (a : S) :
ψ (aeval a p) = aeval (ψ a) (p.map φ) := by
conv_rhs => rw [aeval_def, ← eval_map]
rw [map_map, h, ← map_map, eval_map, eval₂_at_apply, aeval_def, eval_map]
theorem aeval_eq_zero_of_dvd_aeval_eq_zero [CommSemiring S] [CommSemiring T] [Algebra S T]
{p q : S[X]} (h₁ : p ∣ q) {a : T} (h₂ : aeval a p = 0) : aeval a q = 0 := by
rw [aeval_def, ← eval_map] at h₂ ⊢
exact eval_eq_zero_of_dvd_of_eval_eq_zero (Polynomial.map_dvd (algebraMap S T) h₁) h₂
section Semiring
variable [Semiring S] {f : R →+* S}
theorem aeval_eq_sum_range [Algebra R S] {p : R[X]} (x : S) :
aeval x p = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i • x ^ i := by
simp_rw [Algebra.smul_def]
exact eval₂_eq_sum_range (algebraMap R S) x
theorem aeval_eq_sum_range' [Algebra R S] {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : S) :
aeval x p = ∑ i ∈ Finset.range n, p.coeff i • x ^ i := by
simp_rw [Algebra.smul_def]
exact eval₂_eq_sum_range' (algebraMap R S) hn x
theorem isRoot_of_eval₂_map_eq_zero (hf : Function.Injective f) {r : R} :
eval₂ f (f r) p = 0 → p.IsRoot r := by
intro h
apply hf
rw [← eval₂_hom, h, f.map_zero]
theorem isRoot_of_aeval_algebraMap_eq_zero [Algebra R S] {p : R[X]}
(inj : Function.Injective (algebraMap R S)) {r : R} (hr : aeval (algebraMap R S r) p = 0) :
p.IsRoot r :=
isRoot_of_eval₂_map_eq_zero inj hr
end Semiring
section CommSemiring
section aevalTower
variable [CommSemiring S] [Algebra S R] [Algebra S A'] [Algebra S B]
/-- Version of `aeval` for defining algebra homs out of `R[X]` over a smaller base ring
than `R`. -/
def aevalTower (f : R →ₐ[S] A') (x : A') : R[X] →ₐ[S] A' :=
eval₂AlgHom' f x fun _ => Commute.all _ _
variable (g : R →ₐ[S] A') (y : A')
@[simp]
theorem aevalTower_X : aevalTower g y X = y :=
eval₂_X _ _
@[simp]
theorem aevalTower_C (x : R) : aevalTower g y (C x) = g x :=
eval₂_C _ _
@[simp]
theorem aevalTower_comp_C : (aevalTower g y : R[X] →+* A').comp C = g :=
RingHom.ext <| aevalTower_C _ _
theorem aevalTower_algebraMap (x : R) : aevalTower g y (algebraMap R R[X] x) = g x :=
eval₂_C _ _
theorem aevalTower_comp_algebraMap : (aevalTower g y : R[X] →+* A').comp (algebraMap R R[X]) = g :=
aevalTower_comp_C _ _
theorem aevalTower_toAlgHom (x : R) : aevalTower g y (IsScalarTower.toAlgHom S R R[X] x) = g x :=
aevalTower_algebraMap _ _ _
@[simp]
theorem aevalTower_comp_toAlgHom : (aevalTower g y).comp (IsScalarTower.toAlgHom S R R[X]) = g :=
AlgHom.coe_ringHom_injective <| aevalTower_comp_algebraMap _ _
@[simp]
theorem aevalTower_id : aevalTower (AlgHom.id S S) = aeval := by
ext s
simp only [eval_X, aevalTower_X, coe_aeval_eq_eval]
@[simp]
theorem aevalTower_ofId : aevalTower (Algebra.ofId S A') = aeval := by
ext
simp only [aeval_X, aevalTower_X]
end aevalTower
end CommSemiring
section CommRing
variable [CommRing S] {f : R →+* S}
theorem dvd_term_of_dvd_eval_of_dvd_terms {z p : S} {f : S[X]} (i : ℕ) (dvd_eval : p ∣ f.eval z)
(dvd_terms : ∀ j ≠ i, p ∣ f.coeff j * z ^ j) : p ∣ f.coeff i * z ^ i := by
by_cases hi : i ∈ f.support
· rw [eval, eval₂_eq_sum, sum_def] at dvd_eval
rw [← Finset.insert_erase hi, Finset.sum_insert (Finset.not_mem_erase _ _)] at dvd_eval
refine (dvd_add_left ?_).mp dvd_eval
apply Finset.dvd_sum
intro j hj
exact dvd_terms j (Finset.ne_of_mem_erase hj)
· convert dvd_zero p
rw [not_mem_support_iff] at hi
simp [hi]
theorem dvd_term_of_isRoot_of_dvd_terms {r p : S} {f : S[X]} (i : ℕ) (hr : f.IsRoot r)
(h : ∀ j ≠ i, p ∣ f.coeff j * r ^ j) : p ∣ f.coeff i * r ^ i :=
dvd_term_of_dvd_eval_of_dvd_terms i (Eq.symm hr ▸ dvd_zero p) h
end CommRing
end aeval
section Ring
variable [Ring R]
/-- The evaluation map is not generally multiplicative when the coefficient ring is noncommutative,
but nevertheless any polynomial of the form `p * (X - monomial 0 r)` is sent to zero
when evaluated at `r`.
This is the key step in our proof of the Cayley-Hamilton theorem.
-/
theorem eval_mul_X_sub_C {p : R[X]} (r : R) : (p * (X - C r)).eval r = 0 := by
| simp only [eval, eval₂_eq_sum, RingHom.id_apply]
have bound :=
calc
(p * (X - C r)).natDegree ≤ p.natDegree + (X - C r).natDegree := natDegree_mul_le
| Mathlib/Algebra/Polynomial/AlgebraMap.lean | 548 | 551 |
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
import Mathlib.MeasureTheory.Integral.Bochner.FundThmCalculus
import Mathlib.MeasureTheory.Integral.Bochner.Set
deprecated_module (since := "2025-04-15")
| Mathlib/MeasureTheory/Integral/SetIntegral.lean | 1,644 | 1,711 | |
/-
Copyright (c) 2021 Martin Zinkevich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Zinkevich, Vincent Beffara
-/
import Mathlib.MeasureTheory.Integral.Bochner.Set
import Mathlib.Probability.Independence.Basic
/-!
# Integration in Probability Theory
Integration results for independent random variables. Specifically, for two
independent random variables X and Y over the extended non-negative
reals, `E[X * Y] = E[X] * E[Y]`, and similar results.
## Implementation notes
Many lemmas in this file take two arguments of the same typeclass. It is worth remembering that lean
will always pick the later typeclass in this situation, and does not care whether the arguments are
`[]`, `{}`, or `()`. All of these use the `MeasurableSpace` `M2` to define `μ`:
```lean
example {M1 : MeasurableSpace Ω} [M2 : MeasurableSpace Ω] {μ : Measure Ω} : sorry := sorry
example [M1 : MeasurableSpace Ω] {M2 : MeasurableSpace Ω} {μ : Measure Ω} : sorry := sorry
```
-/
noncomputable section
open Set MeasureTheory
open scoped ENNReal MeasureTheory
variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f g : Ω → ℝ≥0∞} {X Y : Ω → ℝ}
namespace ProbabilityTheory
/-- If a random variable `f` in `ℝ≥0∞` is independent of an event `T`, then if you restrict the
random variable to `T`, then `E[f * indicator T c 0]=E[f] * E[indicator T c 0]`. It is useful for
`lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace`. -/
theorem lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator {Mf mΩ : MeasurableSpace Ω}
{μ : Measure Ω} (hMf : Mf ≤ mΩ) (c : ℝ≥0∞) {T : Set Ω} (h_meas_T : MeasurableSet T)
(h_ind : IndepSets {s | MeasurableSet[Mf] s} {T} μ) (h_meas_f : Measurable[Mf] f) :
(∫⁻ ω, f ω * T.indicator (fun _ => c) ω ∂μ) =
(∫⁻ ω, f ω ∂μ) * ∫⁻ ω, T.indicator (fun _ => c) ω ∂μ := by
revert f
have h_mul_indicator : ∀ g, Measurable g → Measurable fun a => g a * T.indicator (fun _ => c) a :=
fun g h_mg => h_mg.mul (measurable_const.indicator h_meas_T)
apply @Measurable.ennreal_induction _ Mf
· intro c' s' h_meas_s'
simp_rw [← inter_indicator_mul]
rw [lintegral_indicator (MeasurableSet.inter (hMf _ h_meas_s') h_meas_T),
lintegral_indicator (hMf _ h_meas_s'), lintegral_indicator h_meas_T]
simp only [measurable_const, lintegral_const, univ_inter, lintegral_const_mul,
MeasurableSet.univ, Measure.restrict_apply]
rw [IndepSets_iff] at h_ind
rw [mul_mul_mul_comm, h_ind s' T h_meas_s' (Set.mem_singleton _)]
· intro f' g _ h_meas_f' _ h_ind_f' h_ind_g
have h_measM_f' : Measurable f' := h_meas_f'.mono hMf le_rfl
simp_rw [Pi.add_apply, right_distrib]
rw [lintegral_add_left (h_mul_indicator _ h_measM_f'), lintegral_add_left h_measM_f',
right_distrib, h_ind_f', h_ind_g]
· intro f h_meas_f h_mono_f h_ind_f
have h_measM_f : ∀ n, Measurable (f n) := fun n => (h_meas_f n).mono hMf le_rfl
simp_rw [ENNReal.iSup_mul]
rw [lintegral_iSup h_measM_f h_mono_f, lintegral_iSup, ENNReal.iSup_mul]
· simp_rw [← h_ind_f]
· exact fun n => h_mul_indicator _ (h_measM_f n)
· exact fun m n h_le a => mul_le_mul_right' (h_mono_f h_le a) _
/-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`,
then `E[f * g] = E[f] * E[g]`. However, instead of directly using the independence
of the random variables, it uses the independence of measurable spaces for the
domains of `f` and `g`. This is similar to the sigma-algebra approach to
independence. See `lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun` for
a more common variant of the product of independent variables. -/
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace
{Mf Mg mΩ : MeasurableSpace Ω} {μ : Measure Ω} (hMf : Mf ≤ mΩ) (hMg : Mg ≤ mΩ)
(h_ind : Indep Mf Mg μ) (h_meas_f : Measurable[Mf] f) (h_meas_g : Measurable[Mg] g) :
∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by
revert g
have h_measM_f : Measurable f := h_meas_f.mono hMf le_rfl
apply @Measurable.ennreal_induction _ Mg
· intro c s h_s
apply lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator hMf _ (hMg _ h_s) _ h_meas_f
apply indepSets_of_indepSets_of_le_right h_ind
rwa [singleton_subset_iff]
· intro f' g _ h_measMg_f' _ h_ind_f' h_ind_g'
have h_measM_f' : Measurable f' := h_measMg_f'.mono hMg le_rfl
simp_rw [Pi.add_apply, left_distrib]
rw [lintegral_add_left h_measM_f', lintegral_add_left (h_measM_f.mul h_measM_f'), left_distrib,
h_ind_f', h_ind_g']
· intro f' h_meas_f' h_mono_f' h_ind_f'
have h_measM_f' : ∀ n, Measurable (f' n) := fun n => (h_meas_f' n).mono hMg le_rfl
simp_rw [ENNReal.mul_iSup]
rw [lintegral_iSup, lintegral_iSup h_measM_f' h_mono_f', ENNReal.mul_iSup]
· simp_rw [← h_ind_f']
· exact fun n => h_measM_f.mul (h_measM_f' n)
· exact fun n m (h_le : n ≤ m) a => mul_le_mul_left' (h_mono_f' h_le a) _
/-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`,
then `E[f * g] = E[f] * E[g]`. -/
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun (h_meas_f : Measurable f)
(h_meas_g : Measurable g) (h_indep_fun : IndepFun f g μ) :
(∫⁻ ω, (f * g) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ :=
lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace
(measurable_iff_comap_le.1 h_meas_f) (measurable_iff_comap_le.1 h_meas_g) h_indep_fun
(Measurable.of_comap_le le_rfl) (Measurable.of_comap_le le_rfl)
/-- If `f` and `g` with values in `ℝ≥0∞` are independent and almost everywhere measurable,
then `E[f * g] = E[f] * E[g]` (slightly generalizing
`lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun`). -/
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' (h_meas_f : AEMeasurable f μ)
(h_meas_g : AEMeasurable g μ) (h_indep_fun : IndepFun f g μ) :
(∫⁻ ω, (f * g) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by
have fg_ae : f * g =ᵐ[μ] h_meas_f.mk _ * h_meas_g.mk _ := h_meas_f.ae_eq_mk.mul h_meas_g.ae_eq_mk
rw [lintegral_congr_ae h_meas_f.ae_eq_mk, lintegral_congr_ae h_meas_g.ae_eq_mk,
lintegral_congr_ae fg_ae]
apply lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun h_meas_f.measurable_mk
h_meas_g.measurable_mk
exact h_indep_fun.congr h_meas_f.ae_eq_mk h_meas_g.ae_eq_mk
theorem lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' (h_meas_f : AEMeasurable f μ)
(h_meas_g : AEMeasurable g μ) (h_indep_fun : IndepFun f g μ) :
∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ :=
lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' h_meas_f h_meas_g h_indep_fun
theorem lintegral_prod_eq_prod_lintegral_of_indepFun {ι : Type*}
(s : Finset ι) (X : ι → Ω → ℝ≥0∞) (hX : iIndepFun X μ)
(x_mea : ∀ i, Measurable (X i)) :
∫⁻ ω, ∏ i ∈ s, (X i ω) ∂μ = ∏ i ∈ s, ∫⁻ ω, X i ω ∂μ := by
have : IsProbabilityMeasure μ := hX.isProbabilityMeasure
induction s using Finset.cons_induction with
| empty => simp only [Finset.prod_empty, lintegral_const, measure_univ, mul_one]
| cons j s hj ihs =>
simp only [← Finset.prod_apply, Finset.prod_cons, ← ihs]
apply lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'
· exact (x_mea j).aemeasurable
· exact s.aemeasurable_prod' (fun i _ ↦ (x_mea i).aemeasurable)
· exact (iIndepFun.indepFun_finset_prod_of_not_mem hX x_mea hj).symm
/-- The product of two independent, integrable, real-valued random variables is integrable. -/
theorem IndepFun.integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β}
[NormedDivisionRing β] [BorelSpace β] (hXY : IndepFun X Y μ) (hX : Integrable X μ)
(hY : Integrable Y μ) : Integrable (X * Y) μ := by
let nX : Ω → ℝ≥0∞ := fun a => ‖X a‖ₑ
let nY : Ω → ℝ≥0∞ := fun a => ‖Y a‖ₑ
have hXY' : IndepFun nX nY μ := hXY.comp measurable_enorm measurable_enorm
have hnX : AEMeasurable nX μ := hX.1.aemeasurable.enorm
have hnY : AEMeasurable nY μ := hY.1.aemeasurable.enorm
have hmul : ∫⁻ a, nX a * nY a ∂μ = (∫⁻ a, nX a ∂μ) * ∫⁻ a, nY a ∂μ :=
lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun' hnX hnY hXY'
refine ⟨hX.1.mul hY.1, ?_⟩
simp only [nX, nY] at hmul
simp_rw [hasFiniteIntegral_iff_enorm, Pi.mul_apply, enorm_mul, hmul]
exact ENNReal.mul_lt_top hX.2 hY.2
/-- If the product of two independent real-valued random variables is integrable and
the second one is not almost everywhere zero, then the first one is integrable. -/
theorem IndepFun.integrable_left_of_integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β}
[NormedDivisionRing β] [BorelSpace β] (hXY : IndepFun X Y μ) (h'XY : Integrable (X * Y) μ)
(hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) (h'Y : ¬Y =ᵐ[μ] 0) :
Integrable X μ := by
refine ⟨hX, ?_⟩
have I : (∫⁻ ω, ‖Y ω‖ₑ ∂μ) ≠ 0 := fun H ↦ by
have I : (fun ω => ‖Y ω‖ₑ : Ω → ℝ≥0∞) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' hY.enorm).1 H
apply h'Y
filter_upwards [I] with ω hω
simpa using hω
refine hasFiniteIntegral_iff_enorm.mpr <| lt_top_iff_ne_top.2 fun H => ?_
have J : IndepFun (‖X ·‖ₑ) (‖Y ·‖ₑ) μ := hXY.comp measurable_enorm measurable_enorm
have A : ∫⁻ ω, ‖X ω * Y ω‖ₑ ∂μ < ∞ := h'XY.2
simp only [enorm_mul, ENNReal.coe_mul] at A
rw [lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' hX.enorm hY.enorm J, H] at A
simp only [ENNReal.top_mul I, lt_self_iff_false] at A
/-- If the product of two independent real-valued random variables is integrable and the
| first one is not almost everywhere zero, then the second one is integrable. -/
theorem IndepFun.integrable_right_of_integrable_mul {β : Type*} [MeasurableSpace β] {X Y : Ω → β}
[NormedDivisionRing β] [BorelSpace β] (hXY : IndepFun X Y μ) (h'XY : Integrable (X * Y) μ)
(hX : AEStronglyMeasurable X μ) (hY : AEStronglyMeasurable Y μ) (h'X : ¬X =ᵐ[μ] 0) :
Integrable Y μ := by
refine ⟨hY, ?_⟩
have I : ∫⁻ ω, ‖X ω‖ₑ ∂μ ≠ 0 := fun H ↦ by
have I : ((‖X ·‖ₑ) : Ω → ℝ≥0∞) =ᵐ[μ] 0 := (lintegral_eq_zero_iff' hX.enorm).1 H
apply h'X
filter_upwards [I] with ω hω
simpa using hω
refine lt_top_iff_ne_top.2 fun H => ?_
have J : IndepFun (fun ω => ‖X ω‖ₑ : Ω → ℝ≥0∞) (fun ω => ‖Y ω‖ₑ : Ω → ℝ≥0∞) μ :=
IndepFun.comp hXY measurable_enorm measurable_enorm
have A : ∫⁻ ω, ‖X ω * Y ω‖ₑ ∂μ < ∞ := h'XY.2
simp only [enorm_mul, ENNReal.coe_mul] at A
rw [lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun'' hX.enorm hY.enorm J, H] at A
simp only [ENNReal.mul_top I, lt_self_iff_false] at A
| Mathlib/Probability/Integration.lean | 180 | 197 |
/-
Copyright (c) 2023 Geoffrey Irving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler, Geoffrey Irving, Stefan Kebekus
-/
import Mathlib.Analysis.Analytic.Composition
import Mathlib.Analysis.Analytic.Linear
import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul
import Mathlib.Analysis.Normed.Ring.Units
import Mathlib.Analysis.Analytic.OfScalars
/-!
# Various ways to combine analytic functions
We show that the following are analytic:
1. Cartesian products of analytic functions
2. Arithmetic on analytic functions: `mul`, `smul`, `inv`, `div`
3. Finite sums and products: `Finset.sum`, `Finset.prod`
-/
noncomputable section
open scoped Topology
open Filter Asymptotics ENNReal NNReal
variable {α : Type*}
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E F G H : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H]
[NormedSpace 𝕜 H]
variable {𝕝 : Type*} [NontriviallyNormedField 𝕝] [NormedAlgebra 𝕜 𝕝]
variable {A : Type*} [NormedRing A] [NormedAlgebra 𝕜 A]
/-!
### Constants are analytic
-/
theorem hasFPowerSeriesOnBall_const {c : F} {e : E} :
HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e ⊤ := by
refine ⟨by simp, WithTop.top_pos, fun _ => hasSum_single 0 fun n hn => ?_⟩
simp [constFormalMultilinearSeries_apply hn]
theorem hasFPowerSeriesAt_const {c : F} {e : E} :
HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e :=
⟨⊤, hasFPowerSeriesOnBall_const⟩
@[fun_prop]
theorem analyticAt_const {v : F} {x : E} : AnalyticAt 𝕜 (fun _ => v) x :=
⟨constFormalMultilinearSeries 𝕜 E v, hasFPowerSeriesAt_const⟩
theorem analyticOnNhd_const {v : F} {s : Set E} : AnalyticOnNhd 𝕜 (fun _ => v) s :=
fun _ _ => analyticAt_const
theorem analyticWithinAt_const {v : F} {s : Set E} {x : E} : AnalyticWithinAt 𝕜 (fun _ => v) s x :=
analyticAt_const.analyticWithinAt
theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn 𝕜 (fun _ => v) s :=
analyticOnNhd_const.analyticOn
/-!
### Addition, negation, subtraction, scalar multiplication
-/
section
variable {f g : E → F} {pf pg : FormalMultilinearSeries 𝕜 E F} {s : Set E} {x : E} {r : ℝ≥0∞}
{c : 𝕜}
theorem HasFPowerSeriesWithinOnBall.add (hf : HasFPowerSeriesWithinOnBall f pf s x r)
(hg : HasFPowerSeriesWithinOnBall g pg s x r) :
HasFPowerSeriesWithinOnBall (f + g) (pf + pg) s x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
r_pos := hf.r_pos
hasSum := fun hy h'y => (hf.hasSum hy h'y).add (hg.hasSum hy h'y) }
theorem HasFPowerSeriesOnBall.add (hf : HasFPowerSeriesOnBall f pf x r)
(hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).add (hg.hasSum hy) }
theorem HasFPowerSeriesWithinAt.add
(hf : HasFPowerSeriesWithinAt f pf s x) (hg : HasFPowerSeriesWithinAt g pg s x) :
HasFPowerSeriesWithinAt (f + g) (pf + pg) s x := by
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
exact ⟨r, hr.1.add hr.2⟩
theorem HasFPowerSeriesAt.add (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
HasFPowerSeriesAt (f + g) (pf + pg) x := by
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
exact ⟨r, hr.1.add hr.2⟩
theorem AnalyticWithinAt.add (hf : AnalyticWithinAt 𝕜 f s x) (hg : AnalyticWithinAt 𝕜 g s x) :
AnalyticWithinAt 𝕜 (f + g) s x :=
let ⟨_, hpf⟩ := hf
let ⟨_, hqf⟩ := hg
(hpf.add hqf).analyticWithinAt
@[fun_prop]
theorem AnalyticAt.fun_add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (fun z ↦ f z + g z) x :=
let ⟨_, hpf⟩ := hf
let ⟨_, hqf⟩ := hg
(hpf.add hqf).analyticAt
@[deprecated (since := "2025-03-11")] alias AnalyticAt.add' := AnalyticAt.fun_add
@[fun_prop]
theorem AnalyticAt.add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f + g) x :=
hf.fun_add hg
theorem HasFPowerSeriesWithinOnBall.neg (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
HasFPowerSeriesWithinOnBall (-f) (-pf) s x r :=
{ r_le := by
rw [pf.radius_neg]
exact hf.r_le
r_pos := hf.r_pos
hasSum := fun hy h'y => (hf.hasSum hy h'y).neg }
theorem HasFPowerSeriesOnBall.neg (hf : HasFPowerSeriesOnBall f pf x r) :
HasFPowerSeriesOnBall (-f) (-pf) x r :=
{ r_le := by
rw [pf.radius_neg]
exact hf.r_le
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).neg }
theorem HasFPowerSeriesWithinAt.neg (hf : HasFPowerSeriesWithinAt f pf s x) :
HasFPowerSeriesWithinAt (-f) (-pf) s x :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFPowerSeriesWithinAt
theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFPowerSeriesAt
theorem AnalyticWithinAt.neg (hf : AnalyticWithinAt 𝕜 f s x) : AnalyticWithinAt 𝕜 (-f) s x :=
let ⟨_, hpf⟩ := hf
hpf.neg.analyticWithinAt
@[fun_prop]
theorem AnalyticAt.fun_neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ -f z) x :=
let ⟨_, hpf⟩ := hf
hpf.neg.analyticAt
@[fun_prop]
theorem AnalyticAt.neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (-f) x :=
hf.fun_neg
@[deprecated (since := "2025-03-11")] alias AnalyticAt.neg' := AnalyticAt.fun_neg
theorem HasFPowerSeriesWithinOnBall.sub (hf : HasFPowerSeriesWithinOnBall f pf s x r)
(hg : HasFPowerSeriesWithinOnBall g pg s x r) :
HasFPowerSeriesWithinOnBall (f - g) (pf - pg) s x r := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFPowerSeriesOnBall.sub (hf : HasFPowerSeriesOnBall f pf x r)
(hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f - g) (pf - pg) x r := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFPowerSeriesWithinAt.sub
(hf : HasFPowerSeriesWithinAt f pf s x) (hg : HasFPowerSeriesWithinAt g pg s x) :
HasFPowerSeriesWithinAt (f - g) (pf - pg) s x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem HasFPowerSeriesAt.sub (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
HasFPowerSeriesAt (f - g) (pf - pg) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem AnalyticWithinAt.sub (hf : AnalyticWithinAt 𝕜 f s x) (hg : AnalyticWithinAt 𝕜 g s x) :
AnalyticWithinAt 𝕜 (f - g) s x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
@[fun_prop]
theorem AnalyticAt.fun_sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (fun z ↦ f z - g z) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
@[fun_prop]
theorem AnalyticAt.sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (f - g) x :=
hf.fun_sub hg
@[deprecated (since := "2025-03-11")] alias AnalyticAt.sub' := AnalyticAt.fun_sub
theorem HasFPowerSeriesWithinOnBall.const_smul (hf : HasFPowerSeriesWithinOnBall f pf s x r) :
HasFPowerSeriesWithinOnBall (c • f) (c • pf) s x r where
r_le := le_trans hf.r_le pf.radius_le_smul
r_pos := hf.r_pos
hasSum := fun hy h'y => (hf.hasSum hy h'y).const_smul _
theorem HasFPowerSeriesOnBall.const_smul (hf : HasFPowerSeriesOnBall f pf x r) :
HasFPowerSeriesOnBall (c • f) (c • pf) x r where
r_le := le_trans hf.r_le pf.radius_le_smul
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).const_smul _
theorem HasFPowerSeriesWithinAt.const_smul (hf : HasFPowerSeriesWithinAt f pf s x) :
HasFPowerSeriesWithinAt (c • f) (c • pf) s x :=
let ⟨_, hrf⟩ := hf
hrf.const_smul.hasFPowerSeriesWithinAt
theorem HasFPowerSeriesAt.const_smul (hf : HasFPowerSeriesAt f pf x) :
HasFPowerSeriesAt (c • f) (c • pf) x :=
let ⟨_, hrf⟩ := hf
hrf.const_smul.hasFPowerSeriesAt
theorem AnalyticWithinAt.const_smul (hf : AnalyticWithinAt 𝕜 f s x) :
AnalyticWithinAt 𝕜 (c • f) s x :=
| let ⟨_, hpf⟩ := hf
hpf.const_smul.analyticWithinAt
@[fun_prop]
theorem AnalyticAt.fun_const_smul (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ c • f z) x :=
let ⟨_, hpf⟩ := hf
hpf.const_smul.analyticAt
@[fun_prop]
theorem AnalyticAt.const_smul (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (c • f) x :=
hf.fun_const_smul
@[deprecated (since := "2025-03-11")] alias AnalyticAt.const_smul' := AnalyticAt.fun_const_smul
theorem AnalyticOn.add (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
theorem AnalyticOnNhd.add (hf : AnalyticOnNhd 𝕜 f s) (hg : AnalyticOnNhd 𝕜 g s) :
AnalyticOnNhd 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
theorem AnalyticOn.neg (hf : AnalyticOn 𝕜 f s) : AnalyticOn 𝕜 (-f) s :=
fun z hz ↦ (hf z hz).neg
| Mathlib/Analysis/Analytic/Constructions.lean | 212 | 236 |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Lattice.Prod
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Set.Lattice.Image
/-!
# N-ary images of finsets
This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of
`Set.image2`. This is mostly useful to define pointwise operations.
## Notes
This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please
keep them in sync.
We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂`
and `Set.image2` already fulfills this task.
-/
open Function Set
variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*}
namespace Finset
variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ']
[DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ}
{s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ}
/-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`.
Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/
def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ :=
(s ×ˢ t).image <| uncurry f
@[simp]
theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by
simp [image₂, and_assoc]
@[simp, norm_cast]
theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) :
(image₂ f s t : Set γ) = Set.image2 f s t :=
Set.ext fun _ => mem_image₂
theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) :
#(image₂ f s t) ≤ #s * #t :=
card_image_le.trans_eq <| card_product _ _
theorem card_image₂_iff :
#(image₂ f s t) = #s * #t ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by
rw [← card_product, ← coe_product]
exact card_image_iff
theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) :
#(image₂ f s t) = #s * #t :=
(card_image_of_injective _ hf.uncurry).trans <| card_product _ _
theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t :=
mem_image₂.2 ⟨a, ha, b, hb, rfl⟩
theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by
rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe]
@[gcongr]
theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by
rw [← coe_subset, coe_image₂, coe_image₂]
exact image2_subset hs ht
@[gcongr]
theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' :=
image₂_subset Subset.rfl ht
@[gcongr]
theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t :=
image₂_subset hs Subset.rfl
theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb
theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t :=
image_subset_iff.2 fun _ => mem_image₂_of_mem ha
lemma forall_mem_image₂ {p : γ → Prop} :
(∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, forall_mem_image2]
lemma exists_mem_image₂ {p : γ → Prop} :
(∃ z ∈ image₂ f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by
simp_rw [← mem_coe, coe_image₂, exists_mem_image2]
@[deprecated (since := "2024-11-23")] alias forall_image₂_iff := forall_mem_image₂
@[simp]
theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u :=
forall_mem_image₂
theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff]
theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by
simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α]
@[simp]
theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by
rw [← coe_nonempty, coe_image₂]
exact image2_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty :=
image₂_nonempty_iff.2 ⟨hs, ht⟩
theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty :=
(image₂_nonempty_iff.1 h).1
theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty :=
(image₂_nonempty_iff.1 h).2
@[simp]
theorem image₂_empty_left : image₂ f ∅ t = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_empty_right : image₂ f s ∅ = ∅ :=
coe_injective <| by simp
@[simp]
theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or]
@[simp]
theorem image₂_singleton_left : image₂ f {a} t = t.image fun b => f a b :=
ext fun x => by simp
@[simp]
theorem image₂_singleton_right : image₂ f s {b} = s.image fun a => f a b :=
ext fun x => by simp
theorem image₂_singleton_left' : image₂ f {a} t = t.image (f a) :=
image₂_singleton_left
theorem image₂_singleton : image₂ f {a} {b} = {f a b} := by simp
theorem image₂_union_left [DecidableEq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_union_left
theorem image₂_union_right [DecidableEq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_union_right
@[simp]
theorem image₂_insert_left [DecidableEq α] :
image₂ f (insert a s) t = (t.image fun b => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_left
@[simp]
theorem image₂_insert_right [DecidableEq β] :
image₂ f s (insert b t) = (s.image fun a => f a b) ∪ image₂ f s t :=
coe_injective <| by
push_cast
exact image2_insert_right
theorem image₂_inter_left [DecidableEq α] (hf : Injective2 f) :
image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t :=
coe_injective <| by
push_cast
exact image2_inter_left hf
theorem image₂_inter_right [DecidableEq β] (hf : Injective2 f) :
image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' :=
coe_injective <| by
push_cast
exact image2_inter_right hf
theorem image₂_inter_subset_left [DecidableEq α] :
image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_left
theorem image₂_inter_subset_right [DecidableEq β] :
image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' :=
coe_subset.1 <| by
push_cast
exact image2_inter_subset_right
theorem image₂_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
coe_injective <| by
push_cast
exact image2_congr h
/-- A common special case of `image₂_congr` -/
theorem image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t :=
image₂_congr fun a _ b _ => h a b
variable (s t)
theorem card_image₂_singleton_left (hf : Injective (f a)) : #(image₂ f {a} t) = #t := by
rw [image₂_singleton_left, card_image_of_injective _ hf]
theorem card_image₂_singleton_right (hf : Injective fun a => f a b) :
#(image₂ f s {b}) = #s := by rw [image₂_singleton_right, card_image_of_injective _ hf]
theorem image₂_singleton_inter [DecidableEq β] (t₁ t₂ : Finset β) (hf : Injective (f a)) :
image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ := by
simp_rw [image₂_singleton_left, image_inter _ _ hf]
theorem image₂_inter_singleton [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective fun a => f a b) :
image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} := by
simp_rw [image₂_singleton_right, image_inter _ _ hf]
theorem card_le_card_image₂_left {s : Finset α} (hs : s.Nonempty) (hf : ∀ a, Injective (f a)) :
#t ≤ #(image₂ f s t) := by
obtain ⟨a, ha⟩ := hs
rw [← card_image₂_singleton_left _ (hf a)]
exact card_le_card (image₂_subset_right <| singleton_subset_iff.2 ha)
theorem card_le_card_image₂_right {t : Finset β} (ht : t.Nonempty)
(hf : ∀ b, Injective fun a => f a b) : #s ≤ #(image₂ f s t) := by
obtain ⟨b, hb⟩ := ht
rw [← card_image₂_singleton_right _ (hf b)]
exact card_le_card (image₂_subset_left <| singleton_subset_iff.2 hb)
variable {s t}
theorem biUnion_image_left : (s.biUnion fun a => t.image <| f a) = image₂ f s t :=
coe_injective <| by
push_cast
exact Set.iUnion_image_left _
theorem biUnion_image_right : (t.biUnion fun b => s.image fun a => f a b) = image₂ f s t :=
coe_injective <| by
push_cast
exact Set.iUnion_image_right _
/-!
### Algebraic replacement rules
A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations
to the associativity, commutativity, distributivity, ... of `Finset.image₂` of those operations.
The proof pattern is `image₂_lemma operation_lemma`. For example, `image₂_comm mul_comm` proves that
`image₂ (*) f g = image₂ (*) g f` in a `CommSemigroup`.
-/
section
variable [DecidableEq δ]
theorem image_image₂ (f : α → β → γ) (g : γ → δ) :
(image₂ f s t).image g = image₂ (fun a b => g (f a b)) s t :=
coe_injective <| by
push_cast
exact image_image2 _ _
theorem image₂_image_left (f : γ → β → δ) (g : α → γ) :
image₂ f (s.image g) t = image₂ (fun a b => f (g a) b) s t :=
coe_injective <| by
push_cast
exact image2_image_left _ _
theorem image₂_image_right (f : α → γ → δ) (g : β → γ) :
image₂ f s (t.image g) = image₂ (fun a b => f a (g b)) s t :=
coe_injective <| by
push_cast
exact image2_image_right _ _
@[simp]
theorem image₂_mk_eq_product [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) :
image₂ Prod.mk s t = s ×ˢ t := by ext; simp [Prod.ext_iff]
@[simp]
theorem image₂_curry (f : α × β → γ) (s : Finset α) (t : Finset β) :
image₂ (curry f) s t = (s ×ˢ t).image f := rfl
@[simp]
theorem image_uncurry_product (f : α → β → γ) (s : Finset α) (t : Finset β) :
(s ×ˢ t).image (uncurry f) = image₂ f s t := rfl
theorem image₂_swap (f : α → β → γ) (s : Finset α) (t : Finset β) :
image₂ f s t = image₂ (fun a b => f b a) t s :=
coe_injective <| by
push_cast
exact image2_swap _ _ _
@[simp]
theorem image₂_left [DecidableEq α] (h : t.Nonempty) : image₂ (fun x _ => x) s t = s :=
coe_injective <| by
push_cast
exact image2_left h
@[simp]
theorem image₂_right [DecidableEq β] (h : s.Nonempty) : image₂ (fun _ y => y) s t = t :=
coe_injective <| by
push_cast
exact image2_right h
theorem image₂_assoc {γ : Type*} {u : Finset γ}
{f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε}
{g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) :
image₂ f (image₂ g s t) u = image₂ f' s (image₂ g' t u) :=
coe_injective <| by
push_cast
exact image2_assoc h_assoc
theorem image₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image₂ f s t = image₂ g t s :=
(image₂_swap _ _ _).trans <| by simp_rw [h_comm]
theorem image₂_left_comm {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) :
image₂ f s (image₂ g t u) = image₂ g' t (image₂ f' s u) :=
coe_injective <| by
push_cast
exact image2_left_comm h_left_comm
theorem image₂_right_comm {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) :
image₂ f (image₂ g s t) u = image₂ g' (image₂ f' s u) t :=
coe_injective <| by
push_cast
exact image2_right_comm h_right_comm
theorem image₂_image₂_image₂_comm {γ δ : Type*} {u : Finset γ} {v : Finset δ} [DecidableEq ζ]
[DecidableEq ζ'] [DecidableEq ν] {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ}
{f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'}
(h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) :
image₂ f (image₂ g s t) (image₂ h u v) = image₂ f' (image₂ g' s u) (image₂ h' t v) :=
coe_injective <| by
push_cast
exact image2_image2_image2_comm h_comm
theorem image_image₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) :
(image₂ f s t).image g = image₂ f' (s.image g₁) (t.image g₂) :=
coe_injective <| by
push_cast
exact image_image2_distrib h_distrib
/-- Symmetric statement to `Finset.image₂_image_left_comm`. -/
theorem image_image₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'}
(h_distrib : ∀ a b, g (f a b) = f' (g' a) b) :
(image₂ f s t).image g = image₂ f' (s.image g') t :=
coe_injective <| by
push_cast
exact image_image2_distrib_left h_distrib
/-- Symmetric statement to `Finset.image_image₂_right_comm`. -/
theorem image_image₂_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'}
(h_distrib : ∀ a b, g (f a b) = f' a (g' b)) :
(image₂ f s t).image g = image₂ f' s (t.image g') :=
coe_injective <| by
push_cast
exact image_image2_distrib_right h_distrib
/-- Symmetric statement to `Finset.image_image₂_distrib_left`. -/
theorem image₂_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ}
(h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) :
image₂ f (s.image g) t = (image₂ f' s t).image g' :=
(image_image₂_distrib_left fun a b => (h_left_comm a b).symm).symm
/-- Symmetric statement to `Finset.image_image₂_distrib_right`. -/
theorem image_image₂_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ}
(h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) :
image₂ f s (t.image g) = (image₂ f' s t).image g' :=
(image_image₂_distrib_right fun a b => (h_right_comm a b).symm).symm
/-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/
theorem image₂_distrib_subset_left {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ}
{f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε}
(h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) :
image₂ f s (image₂ g t u) ⊆ image₂ g' (image₂ f₁ s t) (image₂ f₂ s u) :=
coe_subset.1 <| by
push_cast
exact Set.image2_distrib_subset_left h_distrib
/-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/
theorem image₂_distrib_subset_right {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ}
{f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε}
| (h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) :
image₂ f (image₂ g s t) u ⊆ image₂ g' (image₂ f₁ s u) (image₂ f₂ t u) :=
coe_subset.1 <| by
push_cast
exact Set.image2_distrib_subset_right h_distrib
| Mathlib/Data/Finset/NAry.lean | 386 | 391 |
/-
Copyright (c) 2022 Rémi Bottinelli. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémi Bottinelli
-/
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.PathCategory.Basic
/-!
# Free groupoid on a quiver
This file defines the free groupoid on a quiver, the lifting of a prefunctor to its unique
extension as a functor from the free groupoid, and proves uniqueness of this extension.
## Main results
Given the type `V` and a quiver instance on `V`:
- `FreeGroupoid V`: a type synonym for `V`.
- `FreeGroupoid.instGroupoid`: the `Groupoid` instance on `FreeGroupoid V`.
- `lift`: the lifting of a prefunctor from `V` to `V'` where `V'` is a groupoid, to a functor.
`FreeGroupoid V ⥤ V'`.
- `lift_spec` and `lift_unique`: the proofs that, respectively, `lift` indeed is a lifting
and is the unique one.
## Implementation notes
The free groupoid is first defined by symmetrifying the quiver, taking the induced path category
and finally quotienting by the reducibility relation.
-/
open Set Function
namespace CategoryTheory
namespace Groupoid
namespace Free
universe u v u' v' u'' v''
variable {V : Type u} [Quiver.{v + 1} V]
/-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/
abbrev _root_.Quiver.Hom.toPosPath {X Y : V} (f : X ⟶ Y) :
(CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom X Y :=
f.toPos.toPath
/-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/
abbrev _root_.Quiver.Hom.toNegPath {X Y : V} (f : X ⟶ Y) :
(CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom Y X :=
f.toNeg.toPath
/-- The "reduction" relation -/
inductive redStep : HomRel (Paths (Quiver.Symmetrify V))
| step (X Z : Quiver.Symmetrify V) (f : X ⟶ Z) :
redStep (𝟙 ((Paths.of (Quiver.Symmetrify V)).obj X)) (f.toPath ≫ (Quiver.reverse f).toPath)
/-- The underlying vertices of the free groupoid -/
def _root_.CategoryTheory.FreeGroupoid (V) [Q : Quiver V] :=
Quotient (@redStep V Q)
instance {V} [Quiver V] [Nonempty V] : Nonempty (FreeGroupoid V) := by
inhabit V; exact ⟨⟨@default V _⟩⟩
theorem congr_reverse {X Y : Paths <| Quiver.Symmetrify V} (p q : X ⟶ Y) :
Quotient.CompClosure redStep p q → Quotient.CompClosure redStep p.reverse q.reverse := by
rintro ⟨XW, pp, qq, WY, _, Z, f⟩
have : Quotient.CompClosure redStep (WY.reverse ≫ 𝟙 _ ≫ XW.reverse)
(WY.reverse ≫ (f.toPath ≫ (Quiver.reverse f).toPath) ≫ XW.reverse) := by
constructor
constructor
simpa only [CategoryStruct.comp, CategoryStruct.id, Quiver.Path.reverse, Quiver.Path.nil_comp,
Quiver.Path.reverse_comp, Quiver.reverse_reverse, Quiver.Path.reverse_toPath,
Quiver.Path.comp_assoc] using this
open Relation in
theorem congr_comp_reverse {X Y : Paths <| Quiver.Symmetrify V} (p : X ⟶ Y) :
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p ≫ p.reverse) =
| Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (𝟙 X) := by
apply Quot.eqvGen_sound
induction p with
| nil => apply EqvGen.refl
| cons q f ih =>
simp only [Quiver.Path.reverse]
fapply EqvGen.trans
-- Porting note: `Quiver.Path.*` and `Quiver.Hom.*` notation not working
· exact q ≫ Quiver.Path.reverse q
· apply EqvGen.symm
| Mathlib/CategoryTheory/Groupoid/FreeGroupoid.lean | 81 | 90 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.AffineMap
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.Normed.Module.Convex
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Topology.Instances.RealVectorSpace
import Mathlib.Topology.LocallyConstant.Basic
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or
`‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `ℝ`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with
right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`).
* `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is
strictly differentiable. (This is a corollary of the mean value inequality.)
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace ℝ F]
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by
change Icc a b ⊆ { x | f x ≤ B x }
set s := { x | f x ≤ B x } ∩ Icc a b
have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB
have : IsClosed s := by
simp only [s, inter_comm]
exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le'
apply this.Icc_subset_of_forall_exists_gt ha
rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy
rcases hxB.lt_or_eq with hxB | hxB
· -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy))
have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x :=
A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB)
have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this
exact this.mono fun y => le_of_lt
· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩
specialize hf' x xab r hfr
have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z :=
(hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici
(Ioi_mem_nhds hrB)
obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y :=
hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists
refine ⟨z, ?_, hz⟩
have := (hfz.trans hzB).le
rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
-- `bound` actually says `liminf (f z - f x) / (z - x) ≤ B' x`
(bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by
have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≤ B x + r * (x - a) := fun x hx r hr => by
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound
· rwa [sub_self, mul_zero, add_zero]
· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
· intro x hx
exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r)
· intro x _ _
rw [mul_one]
exact (lt_add_iff_pos_right _).2 hr
exact hx
intro x hx
have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 :=
continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x ≤ B' x` on `[a, b)`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, f' x ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr =>
(hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr)
/-! ### Vector-valued functions `f : ℝ → E` -/
section
variable {f : ℝ → E} {a b : ℝ}
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `B` has right derivative at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(‖f z‖ - ‖f x‖) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `‖f x‖ = B x`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. -/
theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*}
[NormedAddCommGroup E] {f : ℝ → E} {f' : ℝ → ℝ} (hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (‖f z‖ - ‖f x‖) / (z - x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope (norm ∘ f) x z < r)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB
hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `ℝ`;
* the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b))
(hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB'
fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr)
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `‖f a‖ ≤ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `ℝ`;
* we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`.
Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x :=
image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C`
satisfies `‖f x - f a‖ ≤ C * (x - a)`. -/
theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ}
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by
let g x := f x - f a
have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
have hg' : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by
intro x hx
simp [g, hf' x hx]
let B x := C * (x - a)
have hB : ∀ x, HasDerivAt B C x := by
intro x
simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero]
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ}
(hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x)
(bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by
refine
norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt)
(fun x hx => ?_) bound
exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx)
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `derivWithin`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b))
(bound : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ C) :
∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by
refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound
exact fun x hx => (hf x hx).hasDerivWithinAt
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ}
(hf : ∀ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x)
(bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖f' x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `derivWithin` version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ}
(hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1))
(bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖derivWithin f (Icc (0 : ℝ) 1) x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b))
(hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : ∀ x ∈ Icc a b, f x = f a := by
have : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ 0 * (x - a) := fun x hx =>
norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b))
(hderiv : ∀ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : ∀ x ∈ Icc a b, f x = f a := by
have H : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ 0 := by
simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx =>
norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx
variable {f' g : ℝ → E}
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`,
then they are equal everywhere on `[a, b]`. -/
theorem eq_of_has_deriv_right_eq (derivf : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(derivg : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b))
(gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by
simp only [← @sub_eq_zero _ _ (f _)] at hi ⊢
exact hi ▸ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by
simpa only [sub_self] using (derivf y hy).sub (derivg y hy)
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere
on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/
theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b))
(gdiff : DifferentiableOn ℝ g (Icc a b))
(hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) :
∀ y ∈ Icc a b, f y = g y := by
have A : ∀ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy =>
(fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
have B : ∀ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy =>
(gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm ▸ B y hy) fdiff.continuousOn
gdiff.continuousOn hi
end
/-!
### Vector-valued functions `f : E → G`
Theorems in this section work both for real and complex differentiable functions. We use assumptions
`[NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 G]` to
achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion
of a `Convex` set. -/
section
namespace Convex
variable {𝕜 G : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜]
[NormedSpace 𝕜 E] [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{f g : E → G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E → E →L[𝕜] G} {φ : E →L[𝕜] G}
instance (priority := 100) : PathConnectedSpace 𝕜 := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
infer_instance
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then
the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le
(hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖ ≤ C) (hs : Convex ℝ s)
(xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x‖ ≤ C * ‖y - x‖ := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ 𝕜 G
/- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined
on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`.
We just have to check the differentiability of the composition and bounds on its derivative,
which is straightforward but tedious for lack of automation. -/
set g := (AffineMap.lineMap x y : ℝ → E)
have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys
have hD : ∀ t ∈ Icc (0 : ℝ) 1,
HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by
simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _
AffineMap.hasDerivWithinAt_lineMap segm
have bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖f' (g t) (y - x)‖ ≤ C * ‖y - x‖ := fun t ht =>
le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝ≥0}
(hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x‖₊ ≤ C)
(hs : Convex ℝ s) : LipschitzOnWith C f s := by
rw [lipschitzOnWith_iff_norm_sub_le]
intro x x_in y y_in
exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is
`K`-Lipschitz on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims
existence of `K` instead of an explicit estimate. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s)
{f : E → G} (hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y)
(hcont : ContinuousWithinAt f' s x) (K : ℝ≥0) (hK : ‖f' x‖₊ < K) :
∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by
obtain ⟨ε, ε0, hε⟩ : ∃ ε > 0,
ball x ε ∩ s ⊆ { y | HasFDerivWithinAt f (f' y) s y ∧ ‖f' y‖₊ < K } :=
mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
rw [inter_comm] at hε
refine ⟨s ∩ ball x ε, inter_mem_nhdsWithin _ (ball_mem_nhds _ ε0), ?_⟩
exact
(hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun y hy => (hε hy).1.mono inter_subset_left) fun y hy => (hε hy).2.le
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E → G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ℝ≥0` larger than `‖f' x‖₊`, `f` is Lipschitz
on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version
with an explicit estimate on the Lipschitz constant. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E → G}
(hder : ∀ᶠ y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) :
∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t :=
(exists_gt _).imp <|
hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont
/-- The mean value theorem on a convex set: if the derivative of a function within this set is
bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn 𝕜 f s)
(bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) :
‖f y - f x‖ ≤ C * ‖y - x‖ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound
xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝ≥0} (hf : DifferentiableOn 𝕜 f s)
(bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖₊ ≤ C) (hs : Convex ℝ s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`,
then the function is `C`-Lipschitz. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x)
(bound : ∀ x ∈ s, ‖fderiv 𝕜 f x‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) :
‖f y - f x‖ ≤ C * ‖y - x‖ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝ≥0} (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x)
(bound : ∀ x ∈ s, ‖fderiv 𝕜 f x‖₊ ≤ C) (hs : Convex ℝ s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is
`C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/
theorem _root_.lipschitzWith_of_nnnorm_fderiv_le
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → G}
{C : ℝ≥0} (hf : Differentiable 𝕜 f)
(bound : ∀ x, ‖fderiv 𝕜 f x‖₊ ≤ C) : LipschitzWith C f := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E
rw [← lipschitzOnWith_univ]
exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between
the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with
`HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le'
(hf : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : ∀ x ∈ s, ‖f' x - φ‖ ≤ C)
(hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : ‖f y - f x - φ (y - x)‖ ≤ C * ‖y - x‖ := by
/- We subtract `φ` to define a new function `g` for which `g' = 0`, for which the previous theorem
applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue
together the pieces, expressing back `f` in terms of `g`. -/
let g y := f y - φ y
have hg : ∀ x ∈ s, HasFDerivWithinAt g (f' x - φ) s x := fun x xs =>
(hf x xs).sub φ.hasFDerivWithinAt
calc
‖f y - f x - φ (y - x)‖ = ‖f y - f x - (φ y - φ x)‖ := by simp
_ = ‖f y - φ y - (f x - φ x)‖ := by congr 1; abel
_ = ‖g y - g x‖ := by simp [g]
_ ≤ C * ‖y - x‖ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn 𝕜 f s)
(bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x - φ‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) :
‖f y - f x - φ (y - x)‖ ≤ C * ‖y - x‖ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound
xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le' (hf : ∀ x ∈ s, DifferentiableAt 𝕜 f x)
(bound : ∀ x ∈ s, ‖fderiv 𝕜 f x - φ‖ ≤ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) :
‖f y - f x - φ (y - x)‖ ≤ C * ‖y - x‖ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le'
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys
/-- If a function has zero Fréchet derivative at every point of a convex set,
then it is a constant on this set. -/
theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s)
(hf' : ∀ x ∈ s, fderivWithin 𝕜 f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by
have bound : ∀ x ∈ s, ‖fderivWithin 𝕜 f s x‖ ≤ 0 := fun x hx => by
simp only [hf' x hx, norm_zero, le_rfl]
simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using
hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy
theorem _root_.is_const_of_fderiv_eq_zero
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → G}
(hf : Differentiable 𝕜 f) (hf' : ∀ x, fderiv 𝕜 f x = 0)
(x y : E) : f x = f y := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E
exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn
(fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial
/-- If two functions have equal Fréchet derivatives at every point of a convex set, and are equal at
one point in that set, then they are equal on that set. -/
theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn 𝕜 f s)
(hg : DifferentiableOn 𝕜 g s) (hs' : UniqueDiffOn 𝕜 s)
(hf' : s.EqOn (fderivWithin 𝕜 f s) (fderivWithin 𝕜 g s)) (hx : x ∈ s) (hfgx : f x = g x) :
s.EqOn f g := fun y hy => by
suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy
rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' hz]
/-- If `f` has zero derivative on an open set, then `f` is locally constant on `s`. -/
-- TODO: change the spelling once we have `IsLocallyConstantOn`.
theorem _root_.IsOpen.isOpen_inter_preimage_of_fderiv_eq_zero
(hs : IsOpen s) (hf : DifferentiableOn 𝕜 f s)
(hf' : s.EqOn (fderiv 𝕜 f) 0) (t : Set G) : IsOpen (s ∩ f ⁻¹' t) := by
refine Metric.isOpen_iff.mpr fun y ⟨hy, hy'⟩ ↦ ?_
obtain ⟨r, hr, h⟩ := Metric.isOpen_iff.mp hs y hy
refine ⟨r, hr, Set.subset_inter h fun x hx ↦ ?_⟩
have := (convex_ball y r).is_const_of_fderivWithin_eq_zero (hf.mono h) ?_ hx (mem_ball_self hr)
· simpa [this]
· intro z hz
simpa only [fderivWithin_of_isOpen Metric.isOpen_ball hz] using hf' (h hz)
theorem _root_.isLocallyConstant_of_fderiv_eq_zero (h₁ : Differentiable 𝕜 f)
(h₂ : ∀ x, fderiv 𝕜 f x = 0) : IsLocallyConstant f := by
simpa using isOpen_univ.isOpen_inter_preimage_of_fderiv_eq_zero h₁.differentiableOn fun _ _ ↦ h₂ _
/-- If `f` has zero derivative on a connected open set, then `f` is constant on `s`. -/
theorem _root_.IsOpen.exists_is_const_of_fderiv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s)
(hf' : s.EqOn (fderiv 𝕜 f) 0) : ∃ a, ∀ x ∈ s, f x = a := by
obtain (rfl|⟨y, hy⟩) := s.eq_empty_or_nonempty
· exact ⟨0, by simp⟩
· refine ⟨f y, fun x hx ↦ ?_⟩
have h₁ := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf hf' {f y}
have h₂ := hf.continuousOn.comp_continuous continuous_subtype_val (fun x ↦ x.2)
by_contra h₃
obtain ⟨t, ht, ht'⟩ := (isClosed_singleton (x := f y)).preimage h₂
have ht'' : ∀ a ∈ s, a ∈ t ↔ f a ≠ f y := by simpa [Set.ext_iff] using ht'
obtain ⟨z, H₁, H₂, H₃⟩ := hs' _ _ h₁ ht (fun x h ↦ by simp [h, ht'', eq_or_ne]) ⟨y, by simpa⟩
⟨x, by simp [ht'' _ hx, hx, h₃]⟩
exact (ht'' _ H₁).mp H₃ H₂.2
theorem _root_.IsOpen.is_const_of_fderiv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn 𝕜 f s)
(hf' : s.EqOn (fderiv 𝕜 f) 0) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by
obtain ⟨a, ha⟩ := hs.exists_is_const_of_fderiv_eq_zero hs' hf hf'
rw [ha x hx, ha y hy]
theorem _root_.IsOpen.exists_eq_add_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s)
(hf' : s.EqOn (fderiv 𝕜 f) (fderiv 𝕜 g)) : ∃ a, s.EqOn f (g · + a) := by
simp_rw [Set.EqOn, ← sub_eq_iff_eq_add']
refine hs.exists_is_const_of_fderiv_eq_zero hs' (hf.sub hg) fun x hx ↦ ?_
rw [fderiv_sub (hf.differentiableAt (hs.mem_nhds hx)) (hg.differentiableAt (hs.mem_nhds hx)),
hf' hx, sub_self, Pi.zero_apply]
/-- If two functions have equal Fréchet derivatives at every point of a connected open set,
and are equal at one point in that set, then they are equal on that set. -/
theorem _root_.IsOpen.eqOn_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s)
(hf' : ∀ x ∈ s, fderiv 𝕜 f x = fderiv 𝕜 g x) (hx : x ∈ s) (hfgx : f x = g x) :
s.EqOn f g := by
obtain ⟨a, ha⟩ := hs.exists_eq_add_of_fderiv_eq hs' hf hg hf'
obtain rfl := left_eq_add.mp (hfgx.symm.trans (ha hx))
simpa using ha
theorem _root_.eq_of_fderiv_eq
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {f g : E → G}
(hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g)
(hf' : ∀ x, fderiv 𝕜 f x = fderiv 𝕜 g x) (x : E) (hfgx : f x = g x) : f = g := by
letI : RCLike 𝕜 := IsRCLikeNormedField.rclike 𝕜
let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ 𝕜 E
suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x
| exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn
uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx
lemma isLittleO_pow_succ {x₀ : E} {n : ℕ} (hs : Convex ℝ s) (hx₀s : x₀ ∈ s)
(hff' : ∀ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf' : f' =o[𝓝[s] x₀] fun x ↦ ‖x - x₀‖ ^ n) :
| Mathlib/Analysis/Calculus/MeanValue.lean | 645 | 649 |
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Products.Basic
/-!
# Curry and uncurry, as functors.
We define `curry : ((C × D) ⥤ E) ⥤ (C ⥤ (D ⥤ E))` and `uncurry : (C ⥤ (D ⥤ E)) ⥤ ((C × D) ⥤ E)`,
and verify that they provide an equivalence of categories
`currying : (C ⥤ (D ⥤ E)) ≌ ((C × D) ⥤ E)`.
-/
namespace CategoryTheory
universe v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅
variable {B : Type u₁} [Category.{v₁} B] {C : Type u₂} [Category.{v₂} C] {D : Type u₃}
[Category.{v₃} D] {E : Type u₄} [Category.{v₄} E] {H : Type u₅} [Category.{v₅} H]
/-- The uncurrying functor, taking a functor `C ⥤ (D ⥤ E)` and producing a functor `(C × D) ⥤ E`.
-/
@[simps]
def uncurry : (C ⥤ D ⥤ E) ⥤ C × D ⥤ E where
obj F :=
{ obj := fun X => (F.obj X.1).obj X.2
map := fun {X} {Y} f => (F.map f.1).app X.2 ≫ (F.obj Y.1).map f.2
map_comp := fun f g => by
simp only [prod_comp_fst, prod_comp_snd, Functor.map_comp, NatTrans.comp_app,
Category.assoc]
slice_lhs 2 3 => rw [← NatTrans.naturality]
rw [Category.assoc] }
map T :=
{ app := fun X => (T.app X.1).app X.2
naturality := fun X Y f => by
simp only [prod_comp_fst, prod_comp_snd, Category.comp_id, Category.assoc, Functor.map_id,
Functor.map_comp, NatTrans.id_app, NatTrans.comp_app]
slice_lhs 2 3 => rw [NatTrans.naturality]
slice_lhs 1 2 => rw [← NatTrans.comp_app, NatTrans.naturality, NatTrans.comp_app]
rw [Category.assoc] }
/-- The object level part of the currying functor. (See `curry` for the functorial version.)
-/
def curryObj (F : C × D ⥤ E) : C ⥤ D ⥤ E where
obj X :=
{ obj := fun Y => F.obj (X, Y)
map := fun g => F.map (𝟙 X, g)
map_id := fun Y => by simp only [F.map_id]; rw [← prod_id]; exact F.map_id ⟨X,Y⟩
map_comp := fun f g => by simp [← F.map_comp]}
map f :=
{ app := fun Y => F.map (f, 𝟙 Y)
naturality := fun {Y} {Y'} g => by simp [← F.map_comp] }
map_id := fun X => by ext Y; exact F.map_id _
map_comp := fun f g => by ext Y; dsimp; simp [← F.map_comp]
/-- The currying functor, taking a functor `(C × D) ⥤ E` and producing a functor `C ⥤ (D ⥤ E)`.
-/
@[simps! obj_obj_obj obj_obj_map obj_map_app map_app_app]
def curry : (C × D ⥤ E) ⥤ C ⥤ D ⥤ E where
obj F := curryObj F
map T :=
{ app := fun X =>
{ app := fun Y => T.app (X, Y)
naturality := fun Y Y' g => by
dsimp [curryObj]
rw [NatTrans.naturality] }
naturality := fun X X' f => by
ext; dsimp [curryObj]
rw [NatTrans.naturality] }
-- create projection simp lemmas even though this isn't a `{ .. }`.
/-- The equivalence of functor categories given by currying/uncurrying.
-/
@[simps!]
def currying : C ⥤ D ⥤ E ≌ C × D ⥤ E where
functor := uncurry
inverse := curry
unitIso := NatIso.ofComponents (fun _ ↦ NatIso.ofComponents
(fun _ ↦ NatIso.ofComponents (fun _ ↦ Iso.refl _)))
counitIso := NatIso.ofComponents
(fun F ↦ NatIso.ofComponents (fun _ ↦ Iso.refl _) (by
rintro ⟨X₁, X₂⟩ ⟨Y₁, Y₂⟩ ⟨f₁, f₂⟩
dsimp at f₁ f₂ ⊢
simp only [← F.map_comp, prod_comp, Category.comp_id, Category.id_comp]))
/-- The functor `uncurry : (C ⥤ D ⥤ E) ⥤ C × D ⥤ E` is fully faithful. -/
def fullyFaithfulUncurry : (uncurry : (C ⥤ D ⥤ E) ⥤ C × D ⥤ E).FullyFaithful :=
currying.fullyFaithfulFunctor
instance : (uncurry : (C ⥤ D ⥤ E) ⥤ C × D ⥤ E).Full :=
fullyFaithfulUncurry.full
instance : (uncurry : (C ⥤ D ⥤ E) ⥤ C × D ⥤ E).Faithful :=
fullyFaithfulUncurry.faithful
/-- Given functors `F₁ : C ⥤ D`, `F₂ : C' ⥤ D'` and `G : D × D' ⥤ E`, this is the isomorphism
between `curry.obj ((F₁.prod F₂).comp G)` and
`F₁ ⋙ curry.obj G ⋙ (whiskeringLeft C' D' E).obj F₂` in the category `C ⥤ C' ⥤ E`. -/
@[simps!]
def curryObjProdComp {C' D' : Type*} [Category C'] [Category D']
(F₁ : C ⥤ D) (F₂ : C' ⥤ D') (G : D × D' ⥤ E) :
curry.obj ((F₁.prod F₂).comp G) ≅
F₁ ⋙ curry.obj G ⋙ (whiskeringLeft C' D' E).obj F₂ :=
NatIso.ofComponents (fun X₁ ↦ NatIso.ofComponents (fun X₂ ↦ Iso.refl _))
/-- `F.flip` is isomorphic to uncurrying `F`, swapping the variables, and currying. -/
@[simps!]
def flipIsoCurrySwapUncurry (F : C ⥤ D ⥤ E) : F.flip ≅ curry.obj (Prod.swap _ _ ⋙ uncurry.obj F) :=
NatIso.ofComponents fun d => NatIso.ofComponents fun _ => Iso.refl _
/-- The uncurrying of `F.flip` is isomorphic to
swapping the factors followed by the uncurrying of `F`. -/
@[simps!]
def uncurryObjFlip (F : C ⥤ D ⥤ E) : uncurry.obj F.flip ≅ Prod.swap _ _ ⋙ uncurry.obj F :=
| NatIso.ofComponents fun _ => Iso.refl _
variable (B C D E)
| Mathlib/CategoryTheory/Functor/Currying.lean | 120 | 123 |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Subsemigroup.Operations
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Order.Filter.Extr
/-!
# Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra`
## TODO
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized for some yet-to-be-defined `degree`s.
-/
variable {R R' A T B ι : Type*}
namespace AddMonoidAlgebra
/-!
# sup-degree and inf-degree of an `AddMonoidAlgebra`
Let `R` be a semiring and let `A` be a `SemilatticeSup`.
For an element `f : R[A]`, this file defines
* `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`,
* `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`.
If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree
coincide with the standard one:
* the sup-degree is the maximum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊥`, if `f = 0`;
* the inf-degree is the minimum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `⊤`, if `f = 0`.
The main results are
* `AddMonoidAlgebra.supDegree_mul_le`:
the sup-degree of a product is at most the sum of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_mul`:
the inf-degree of a product is at least the sum of the inf-degrees,
* `AddMonoidAlgebra.supDegree_add_le`:
the sup-degree of a sum is at most the sup of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_add`:
the inf-degree of a sum is at least the inf of the inf-degrees.
## Implementation notes
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized twice:
* once for `supDegree` (essentially a simple application) and
* once for `infDegree` (a simple application, via `OrderDual`).
These final lemmas are the ones that likely get used the most. The generic lemmas about
`Finset.support.sup` may not be used directly much outside of this file.
To see this in action, you can look at the triple
`(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`.
-/
section GeneralResultsAssumingSemilatticeSup
variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T]
section Semiring
variable [Semiring R]
section ExplicitDegrees
/-!
In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in
a type with *b*ot or *t*op respectively.
-/
variable (degb : A → B) (degt : A → T) (f g : R[A])
theorem sup_support_add_le :
(f + g).support.sup degb ≤ f.support.sup degb ⊔ g.support.sup degb := by
classical
exact (Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union
theorem le_inf_support_add : f.support.inf degt ⊓ g.support.inf degt ≤ (f + g).support.inf degt :=
sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g
end ExplicitDegrees
section AddOnly
variable [Add A] [Add B] [Add T] [AddLeftMono B] [AddRightMono B]
[AddLeftMono T] [AddRightMono T]
theorem sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b)
(f g : R[A]) :
(f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb := by
classical
exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦
degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds)
theorem le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b))
(f g : R[A]) :
f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt :=
sup_support_mul_le (B := Tᵒᵈ) degtm f g
end AddOnly
section AddMonoids
variable [AddMonoid A] [AddMonoid B] [AddLeftMono B] [AddRightMono B]
[AddMonoid T] [AddLeftMono T] [AddRightMono T]
{degb : A → B} {degt : A → T}
theorem sup_support_list_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) :
∀ l : List R[A],
l.prod.support.sup degb ≤ (l.map fun f : R[A] => f.support.sup degb).sum
| [] => by
rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil]
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
| f::fs => by
rw [List.prod_cons, List.map_cons, List.sum_cons]
exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans
(add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
theorem le_inf_support_list_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (l : List R[A]) :
(l.map fun f : R[A] => f.support.inf degt).sum ≤ l.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr ?_
refine sup_support_list_prod_le ?_ ?_ l
· refine (OrderDual.ofDual_le_ofDual.mp ?_)
exact degt0
· refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_)
exact degtm a b
theorem sup_support_pow_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
(n : ℕ) (f : R[A]) : (f ^ n).support.sup degb ≤ n • f.support.sup degb := by
rw [← List.prod_replicate, ← List.sum_replicate]
refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_
rw [List.map_replicate]
theorem le_inf_support_pow (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
(n : ℕ) (f : R[A]) : n • f.support.inf degt ≤ (f ^ n).support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <| sup_support_pow_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) n f
· exact degt0
· exact degtm _ _
end AddMonoids
end Semiring
section CommutativeLemmas
variable [CommSemiring R] [AddCommMonoid A] [AddCommMonoid B] [AddLeftMono B] [AddRightMono B]
[AddCommMonoid T] [AddLeftMono T] [AddRightMono T]
{degb : A → B} {degt : A → T}
theorem sup_support_multiset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (m : Multiset R[A]) :
m.prod.support.sup degb ≤ (m.map fun f : R[A] => f.support.sup degb).sum := by
induction m using Quot.inductionOn
rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.sum_coe, Multiset.prod_coe]
exact sup_support_list_prod_le degb0 degbm _
theorem le_inf_support_multiset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (m : Multiset R[A]) :
(m.map fun f : R[A] => f.support.inf degt).sum ≤ m.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr <|
sup_support_multiset_prod_le (OrderDual.ofDual_le_ofDual.mp ?_)
(fun a b => OrderDual.ofDual_le_ofDual.mp ?_) m
· exact degt0
· exact degtm _ _
theorem sup_support_finset_prod_le (degb0 : degb 0 ≤ 0)
(degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) (s : Finset ι) (f : ι → R[A]) :
(∏ i ∈ s, f i).support.sup degb ≤ ∑ i ∈ s, (f i).support.sup degb :=
(sup_support_multiset_prod_le degb0 degbm _).trans_eq <| congr_arg _ <| Multiset.map_map _ _ _
theorem le_inf_support_finset_prod (degt0 : 0 ≤ degt 0)
(degtm : ∀ a b, degt a + degt b ≤ degt (a + b)) (s : Finset ι) (f : ι → R[A]) :
(∑ i ∈ s, (f i).support.inf degt) ≤ (∏ i ∈ s, f i).support.inf degt :=
le_of_eq_of_le (by rw [Multiset.map_map]; rfl) (le_inf_support_multiset_prod degt0 degtm _)
end CommutativeLemmas
end GeneralResultsAssumingSemilatticeSup
/-! ### Shorthands for special cases
Note that these definitions are reducible, in order to make it easier to apply the more generic
lemmas above. -/
section Degrees
variable [Semiring R] [Ring R']
section SupDegree
variable [SemilatticeSup B] [OrderBot B] (D : A → B)
/-- Let `R` be a semiring, let `A` be an `AddZeroClass`, let `B` be an `OrderBot`,
and let `D : A → B` be a "degree" function.
For an element `f : R[A]`, the element `supDegree f : B` is the supremum of all the elements in the
support of `f`, or `⊥` if `f` is zero.
Often, the Type `B` is `WithBot A`,
If, further, `A` has a linear order, then this notion coincides with the usual one,
using the maximum of the exponents.
If `A := σ →₀ ℕ` then `R[A] = MvPolynomial σ R`, and if we equip `σ` with a linear order then
the induced linear order on `Lex A` equips `MvPolynomial` ring with a
[monomial order](https://en.wikipedia.org/wiki/Monomial_order) (i.e. a linear order on `A`, the
type of (monic) monomials in `R[A]`, that respects addition). We make use of this monomial order
by taking `D := toLex`, and different monomial orders could be accessed via different type
synonyms once they are added. -/
abbrev supDegree (f : R[A]) : B :=
f.support.sup D
variable {D}
theorem supDegree_add_le {f g : R[A]} :
(f + g).supDegree D ≤ (f.supDegree D) ⊔ (g.supDegree D) :=
sup_support_add_le D f g
@[simp]
theorem supDegree_neg {f : R'[A]} :
(-f).supDegree D = f.supDegree D := by
rw [supDegree, supDegree, Finsupp.support_neg]
theorem supDegree_sub_le {f g : R'[A]} :
(f - g).supDegree D ≤ f.supDegree D ⊔ g.supDegree D := by
rw [sub_eq_add_neg, ← supDegree_neg (f := g)]; apply supDegree_add_le
theorem supDegree_sum_le {ι} {s : Finset ι} {f : ι → R[A]} :
(∑ i ∈ s, f i).supDegree D ≤ s.sup (fun i => (f i).supDegree D) := by
classical
exact (Finset.sup_mono Finsupp.support_finset_sum).trans_eq (Finset.sup_biUnion _ _)
theorem supDegree_single_ne_zero (a : A) {r : R} (hr : r ≠ 0) :
(single a r).supDegree D = D a := by
rw [supDegree, Finsupp.support_single_ne_zero a hr, Finset.sup_singleton]
open Classical in
theorem supDegree_single (a : A) (r : R) :
(single a r).supDegree D = if r = 0 then ⊥ else D a := by
split_ifs with hr <;> simp [supDegree_single_ne_zero, hr]
theorem apply_eq_zero_of_not_le_supDegree {p : R[A]} {a : A} (hlt : ¬ D a ≤ p.supDegree D) :
p a = 0 := by
contrapose! hlt
exact Finset.le_sup (Finsupp.mem_support_iff.2 hlt)
theorem supDegree_withBot_some_comp {s : AddMonoidAlgebra R A} (hs : s.support.Nonempty) :
supDegree (WithBot.some ∘ D) s = supDegree D s := by
unfold AddMonoidAlgebra.supDegree
| rw [← Finset.coe_sup' hs, Finset.sup'_eq_sup]
| Mathlib/Algebra/MonoidAlgebra/Degree.lean | 263 | 263 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Devon Tuma
-/
import Mathlib.Probability.ProbabilityMassFunction.Monad
import Mathlib.Control.ULiftable
/-!
# Specific Constructions of Probability Mass Functions
This file gives a number of different `PMF` constructions for common probability distributions.
`map` and `seq` allow pushing a `PMF α` along a function `f : α → β` (or distribution of
functions `f : PMF (α → β)`) to get a `PMF β`.
`ofFinset` and `ofFintype` simplify the construction of a `PMF α` from a function `f : α → ℝ≥0∞`,
by allowing the "sum equals 1" constraint to be in terms of `Finset.sum` instead of `tsum`.
`normalize` constructs a `PMF α` by normalizing a function `f : α → ℝ≥0∞` by its sum,
and `filter` uses this to filter the support of a `PMF` and re-normalize the new distribution.
`bernoulli` represents the bernoulli distribution on `Bool`.
-/
universe u v
namespace PMF
noncomputable section
variable {α β γ : Type*}
open NNReal ENNReal Finset MeasureTheory
section Map
/-- The functorial action of a function on a `PMF`. -/
def map (f : α → β) (p : PMF α) : PMF β :=
bind p (pure ∘ f)
variable (f : α → β) (p : PMF α) (b : β)
theorem monad_map_eq_map {α β : Type u} (f : α → β) (p : PMF α) : f <$> p = p.map f := rfl
open scoped Classical in
@[simp]
theorem map_apply : (map f p) b = ∑' a, if b = f a then p a else 0 := by simp [map]
@[simp]
| theorem support_map : (map f p).support = f '' p.support :=
| Mathlib/Probability/ProbabilityMassFunction/Constructions.lean | 52 | 52 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro
-/
import Mathlib.Algebra.MonoidAlgebra.Degree
import Mathlib.Algebra.MvPolynomial.Rename
/-!
# Degrees of polynomials
This file establishes many results about the degree of a multivariate polynomial.
The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the
variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a
monomial of $P$.
## Main declarations
* `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets
corresponding to each non-zero monomial in `p`.
For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}`
* `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`.
For example if `p = x⁴y+yz` then `degreeOf y p = 1`.
* `MvPolynomial.totalDegree p : ℕ` :
the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`.
For example if `p = x⁴y+yz` then `totalDegree p = 5`.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
+ `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set.
This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s`
+ `r : R`
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `p : MvPolynomial σ R`
-/
noncomputable section
open Set Function Finsupp AddMonoidAlgebra
universe u v w
variable {R : Type u} {S : Type v}
namespace MvPolynomial
variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ}
section CommSemiring
variable [CommSemiring R] {p q : MvPolynomial σ R}
section Degrees
/-! ### `degrees` -/
/-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset.
(For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.)
-/
def degrees (p : MvPolynomial σ R) : Multiset σ :=
letI := Classical.decEq σ
p.support.sup fun s : σ →₀ ℕ => toMultiset s
theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) :
p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl
theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by
classical
refine (supDegree_single s a).trans_le ?_
split_ifs
exacts [bot_le, le_rfl]
theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) :
degrees (monomial s a) = toMultiset s := by
classical
exact (supDegree_single s a).trans (if_neg ha)
theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 :=
Multiset.le_zero.1 <| degrees_monomial _ _
theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} :=
le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _
@[simp]
theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} :=
(degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _)
@[simp]
theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by
rw [← C_0]
exact degrees_C 0
@[simp]
theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 :=
degrees_C 1
theorem degrees_add_le [DecidableEq σ] {p q : MvPolynomial σ R} :
(p + q).degrees ≤ p.degrees ⊔ q.degrees := by
simp_rw [degrees_def]; exact supDegree_add_le
theorem degrees_sum_le {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) :
(∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by
simp_rw [degrees_def]; exact supDegree_sum_le
theorem degrees_mul_le {p q : MvPolynomial σ R} : (p * q).degrees ≤ p.degrees + q.degrees := by
classical
simp_rw [degrees_def]
exact supDegree_mul_le (map_add _)
theorem degrees_prod_le {ι : Type*} {s : Finset ι} {f : ι → MvPolynomial σ R} :
(∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by
classical exact supDegree_prod_le (map_zero _) (map_add _)
theorem degrees_pow_le {p : MvPolynomial σ R} {n : ℕ} : (p ^ n).degrees ≤ n • p.degrees := by
simpa using degrees_prod_le (s := .range n) (f := fun _ ↦ p)
@[deprecated (since := "2024-12-28")] alias degrees_add := degrees_add_le
@[deprecated (since := "2024-12-28")] alias degrees_sum := degrees_sum_le
@[deprecated (since := "2024-12-28")] alias degrees_mul := degrees_mul_le
@[deprecated (since := "2024-12-28")] alias degrees_prod := degrees_prod_le
@[deprecated (since := "2024-12-28")] alias degrees_pow := degrees_pow_le
theorem mem_degrees {p : MvPolynomial σ R} {i : σ} :
i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by
classical
simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop]
theorem le_degrees_add_left (h : Disjoint p.degrees q.degrees) : p.degrees ≤ (p + q).degrees := by
classical
apply Finset.sup_le
intro d hd
rw [Multiset.disjoint_iff_ne] at h
obtain rfl | h0 := eq_or_ne d 0
· rw [toMultiset_zero]; apply Multiset.zero_le
· refine Finset.le_sup_of_le (b := d) ?_ le_rfl
rw [mem_support_iff, coeff_add]
suffices q.coeff d = 0 by rwa [this, add_zero, coeff, ← Finsupp.mem_support_iff]
rw [Ne, ← Finsupp.support_eq_empty, ← Ne, ← Finset.nonempty_iff_ne_empty] at h0
obtain ⟨j, hj⟩ := h0
contrapose! h
rw [mem_support_iff] at hd
refine ⟨j, ?_, j, ?_, rfl⟩
all_goals rw [mem_degrees]; refine ⟨d, ?_, hj⟩; assumption
@[deprecated (since := "2024-12-28")] alias le_degrees_add := le_degrees_add_left
lemma le_degrees_add_right (h : Disjoint p.degrees q.degrees) : q.degrees ≤ (p + q).degrees := by
simpa [add_comm] using le_degrees_add_left h.symm
theorem degrees_add_of_disjoint [DecidableEq σ] (h : Disjoint p.degrees q.degrees) :
(p + q).degrees = p.degrees ∪ q.degrees :=
degrees_add_le.antisymm <| Multiset.union_le (le_degrees_add_left h) (le_degrees_add_right h)
lemma degrees_map_le [CommSemiring S] {f : R →+* S} : (map f p).degrees ≤ p.degrees := by
classical exact Finset.sup_mono <| support_map_subset ..
@[deprecated (since := "2024-12-28")] alias degrees_map := degrees_map_le
theorem degrees_rename (f : σ → τ) (φ : MvPolynomial σ R) :
(rename f φ).degrees ⊆ φ.degrees.map f := by
classical
intro i
rw [mem_degrees, Multiset.mem_map]
rintro ⟨d, hd, hi⟩
obtain ⟨x, rfl, hx⟩ := coeff_rename_ne_zero _ _ _ hd
simp only [Finsupp.mapDomain, Finsupp.mem_support_iff] at hi
rw [sum_apply, Finsupp.sum] at hi
contrapose! hi
rw [Finset.sum_eq_zero]
intro j hj
simp only [exists_prop, mem_degrees] at hi
specialize hi j ⟨x, hx, hj⟩
rw [Finsupp.single_apply, if_neg hi]
theorem degrees_map_of_injective [CommSemiring S] (p : MvPolynomial σ R) {f : R →+* S}
(hf : Injective f) : (map f p).degrees = p.degrees := by
simp only [degrees, MvPolynomial.support_map_of_injective _ hf]
theorem degrees_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f) :
degrees (rename f p) = (degrees p).map f := by
classical
simp only [degrees, Multiset.map_finset_sup p.support Finsupp.toMultiset f h,
support_rename_of_injective h, Finset.sup_image]
refine Finset.sup_congr rfl fun x _ => ?_
exact (Finsupp.toMultiset_map _ _).symm
end Degrees
section DegreeOf
/-! ### `degreeOf` -/
/-- `degreeOf n p` gives the highest power of X_n that appears in `p` -/
def degreeOf (n : σ) (p : MvPolynomial σ R) : ℕ :=
letI := Classical.decEq σ
p.degrees.count n
theorem degreeOf_def [DecidableEq σ] (n : σ) (p : MvPolynomial σ R) :
p.degreeOf n = p.degrees.count n := by rw [degreeOf]; convert rfl
theorem degreeOf_eq_sup (n : σ) (f : MvPolynomial σ R) :
degreeOf n f = f.support.sup fun m => m n := by
classical
rw [degreeOf_def, degrees, Multiset.count_finset_sup]
congr
ext
simp only [count_toMultiset]
theorem degreeOf_lt_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} (h : 0 < d) :
degreeOf n f < d ↔ ∀ m : σ →₀ ℕ, m ∈ f.support → m n < d := by
rwa [degreeOf_eq_sup, Finset.sup_lt_iff]
lemma degreeOf_le_iff {n : σ} {f : MvPolynomial σ R} {d : ℕ} :
degreeOf n f ≤ d ↔ ∀ m ∈ support f, m n ≤ d := by
rw [degreeOf_eq_sup, Finset.sup_le_iff]
@[simp]
theorem degreeOf_zero (n : σ) : degreeOf n (0 : MvPolynomial σ R) = 0 := by
classical simp only [degreeOf_def, degrees_zero, Multiset.count_zero]
@[simp]
theorem degreeOf_C (a : R) (x : σ) : degreeOf x (C a : MvPolynomial σ R) = 0 := by
classical simp [degreeOf_def, degrees_C]
theorem degreeOf_X [DecidableEq σ] (i j : σ) [Nontrivial R] :
degreeOf i (X j : MvPolynomial σ R) = if i = j then 1 else 0 := by
classical
by_cases c : i = j
· simp only [c, if_true, eq_self_iff_true, degreeOf_def, degrees_X, Multiset.count_singleton]
simp [c, if_false, degreeOf_def, degrees_X]
theorem degreeOf_add_le (n : σ) (f g : MvPolynomial σ R) :
degreeOf n (f + g) ≤ max (degreeOf n f) (degreeOf n g) := by
simp_rw [degreeOf_eq_sup]; exact supDegree_add_le
theorem monomial_le_degreeOf (i : σ) {f : MvPolynomial σ R} {m : σ →₀ ℕ} (h_m : m ∈ f.support) :
m i ≤ degreeOf i f := by
rw [degreeOf_eq_sup i]
apply Finset.le_sup h_m
lemma degreeOf_monomial_eq (s : σ →₀ ℕ) (i : σ) {a : R} (ha : a ≠ 0) :
(monomial s a).degreeOf i = s i := by
classical rw [degreeOf_def, degrees_monomial_eq _ _ ha, Finsupp.count_toMultiset]
-- TODO we can prove equality with `NoZeroDivisors R`
theorem degreeOf_mul_le (i : σ) (f g : MvPolynomial σ R) :
degreeOf i (f * g) ≤ degreeOf i f + degreeOf i g := by
classical
simp only [degreeOf]
convert Multiset.count_le_of_le i degrees_mul_le
rw [Multiset.count_add]
theorem degreeOf_sum_le {ι : Type*} (i : σ) (s : Finset ι) (f : ι → MvPolynomial σ R) :
degreeOf i (∑ j ∈ s, f j) ≤ s.sup fun j => degreeOf i (f j) := by
simp_rw [degreeOf_eq_sup]
exact supDegree_sum_le
-- TODO we can prove equality with `NoZeroDivisors R`
theorem degreeOf_prod_le {ι : Type*} (i : σ) (s : Finset ι) (f : ι → MvPolynomial σ R) :
degreeOf i (∏ j ∈ s, f j) ≤ ∑ j ∈ s, (f j).degreeOf i := by
simp_rw [degreeOf_eq_sup]
exact supDegree_prod_le (by simp only [coe_zero, Pi.zero_apply])
(fun _ _ => by simp only [coe_add, Pi.add_apply])
-- TODO we can prove equality with `NoZeroDivisors R`
theorem degreeOf_pow_le (i : σ) (p : MvPolynomial σ R) (n : ℕ) :
degreeOf i (p ^ n) ≤ n * degreeOf i p := by
simpa using degreeOf_prod_le i (Finset.range n) (fun _ => p)
theorem degreeOf_mul_X_of_ne {i j : σ} (f : MvPolynomial σ R) (h : i ≠ j) :
degreeOf i (f * X j) = degreeOf i f := by
classical
simp only [degreeOf_eq_sup i, support_mul_X, Finset.sup_map]
congr
ext
simp only [Finsupp.single, add_eq_left, addRightEmbedding_apply, coe_mk,
Pi.add_apply, comp_apply, ite_eq_right_iff, Finsupp.coe_add, Pi.single_eq_of_ne h]
@[deprecated (since := "2024-12-01")] alias degreeOf_mul_X_ne := degreeOf_mul_X_of_ne
theorem degreeOf_mul_X_self (j : σ) (f : MvPolynomial σ R) :
degreeOf j (f * X j) ≤ degreeOf j f + 1 := by
classical
simp only [degreeOf]
apply (Multiset.count_le_of_le j degrees_mul_le).trans
simp only [Multiset.count_add, add_le_add_iff_left]
convert Multiset.count_le_of_le j <| degrees_X' j
rw [Multiset.count_singleton_self]
@[deprecated (since := "2024-12-01")] alias degreeOf_mul_X_eq := degreeOf_mul_X_self
theorem degreeOf_mul_X_eq_degreeOf_add_one_iff (j : σ) (f : MvPolynomial σ R) :
degreeOf j (f * X j) = degreeOf j f + 1 ↔ f ≠ 0 := by
refine ⟨fun h => by by_contra ha; simp [ha] at h, fun h => ?_⟩
apply Nat.le_antisymm (degreeOf_mul_X_self j f)
have : (f.support.sup fun m ↦ m j) + 1 = (f.support.sup fun m ↦ (m j + 1)) :=
Finset.comp_sup_eq_sup_comp_of_nonempty @Nat.succ_le_succ (support_nonempty.mpr h)
simp only [degreeOf_eq_sup, support_mul_X, this]
apply Finset.sup_le
intro x hx
simp only [Finset.sup_map, bot_eq_zero', add_pos_iff, zero_lt_one, or_true, Finset.le_sup_iff]
use x
simpa using mem_support_iff.mp hx
theorem degreeOf_C_mul_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(C c * p).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf
convert Multiset.count_le_of_le i degrees_mul_le
simp only [degrees_C, zero_add]
theorem degreeOf_mul_C_le (p : MvPolynomial σ R) (i : σ) (c : R) :
(p * C c).degreeOf i ≤ p.degreeOf i := by
unfold degreeOf
convert Multiset.count_le_of_le i degrees_mul_le
simp only [degrees_C, add_zero]
theorem degreeOf_rename_of_injective {p : MvPolynomial σ R} {f : σ → τ} (h : Function.Injective f)
(i : σ) : degreeOf (f i) (rename f p) = degreeOf i p := by
classical
simp only [degreeOf, degrees_rename_of_injective h, Multiset.count_map_eq_count' f p.degrees h]
end DegreeOf
section TotalDegree
/-! ### `totalDegree` -/
/-- `totalDegree p` gives the maximum |s| over the monomials X^s in `p` -/
def totalDegree (p : MvPolynomial σ R) : ℕ :=
p.support.sup fun s => s.sum fun _ e => e
theorem totalDegree_eq (p : MvPolynomial σ R) :
p.totalDegree = p.support.sup fun m => Multiset.card (toMultiset m) := by
rw [totalDegree]
congr; funext m
exact (Finsupp.card_toMultiset _).symm
theorem le_totalDegree {p : MvPolynomial σ R} {s : σ →₀ ℕ} (h : s ∈ p.support) :
(s.sum fun _ e => e) ≤ totalDegree p :=
Finset.le_sup (α := ℕ) (f := fun s => sum s fun _ e => e) h
theorem totalDegree_le_degrees_card (p : MvPolynomial σ R) :
p.totalDegree ≤ Multiset.card p.degrees := by
classical
rw [totalDegree_eq]
exact Finset.sup_le fun s hs => Multiset.card_le_card <| Finset.le_sup hs
theorem totalDegree_le_of_support_subset (h : p.support ⊆ q.support) :
totalDegree p ≤ totalDegree q :=
Finset.sup_mono h
@[simp]
theorem totalDegree_C (a : R) : (C a : MvPolynomial σ R).totalDegree = 0 :=
(supDegree_single 0 a).trans <| by rw [sum_zero_index, bot_eq_zero', ite_self]
@[simp]
theorem totalDegree_zero : (0 : MvPolynomial σ R).totalDegree = 0 := by
rw [← C_0]; exact totalDegree_C (0 : R)
@[simp]
theorem totalDegree_one : (1 : MvPolynomial σ R).totalDegree = 0 :=
totalDegree_C (1 : R)
@[simp]
theorem totalDegree_X {R} [CommSemiring R] [Nontrivial R] (s : σ) :
(X s : MvPolynomial σ R).totalDegree = 1 := by
rw [totalDegree, support_X]
simp only [Finset.sup, Finsupp.sum_single_index, Finset.fold_singleton, sup_bot_eq]
theorem totalDegree_add (a b : MvPolynomial σ R) :
(a + b).totalDegree ≤ max a.totalDegree b.totalDegree :=
sup_support_add_le _ _ _
theorem totalDegree_add_eq_left_of_totalDegree_lt {p q : MvPolynomial σ R}
(h : q.totalDegree < p.totalDegree) : (p + q).totalDegree = p.totalDegree := by
classical
apply le_antisymm
· rw [← max_eq_left_of_lt h]
exact totalDegree_add p q
by_cases hp : p = 0
· simp [hp]
obtain ⟨b, hb₁, hb₂⟩ :=
p.support.exists_mem_eq_sup (Finsupp.support_nonempty_iff.mpr hp) fun m : σ →₀ ℕ =>
Multiset.card (toMultiset m)
have hb : ¬b ∈ q.support := by
contrapose! h
rw [totalDegree_eq p, hb₂, totalDegree_eq]
apply Finset.le_sup h
have hbb : b ∈ (p + q).support := by
apply support_sdiff_support_subset_support_add
rw [Finset.mem_sdiff]
exact ⟨hb₁, hb⟩
rw [totalDegree_eq, hb₂, totalDegree_eq]
exact Finset.le_sup (f := fun m => Multiset.card (Finsupp.toMultiset m)) hbb
theorem totalDegree_add_eq_right_of_totalDegree_lt {p q : MvPolynomial σ R}
(h : q.totalDegree < p.totalDegree) : (q + p).totalDegree = p.totalDegree := by
rw [add_comm, totalDegree_add_eq_left_of_totalDegree_lt h]
theorem totalDegree_mul (a b : MvPolynomial σ R) :
(a * b).totalDegree ≤ a.totalDegree + b.totalDegree :=
sup_support_mul_le (by exact (Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl)).le) _ _
theorem totalDegree_smul_le [CommSemiring S] [DistribMulAction R S] (a : R) (f : MvPolynomial σ S) :
(a • f).totalDegree ≤ f.totalDegree :=
Finset.sup_mono support_smul
theorem totalDegree_pow (a : MvPolynomial σ R) (n : ℕ) :
(a ^ n).totalDegree ≤ n * a.totalDegree := by
rw [Finset.pow_eq_prod_const, ← Nat.nsmul_eq_mul, Finset.nsmul_eq_sum_const]
refine supDegree_prod_le rfl (fun _ _ => ?_)
exact Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl)
@[simp]
theorem totalDegree_monomial (s : σ →₀ ℕ) {c : R} (hc : c ≠ 0) :
(monomial s c : MvPolynomial σ R).totalDegree = s.sum fun _ e => e := by
classical simp [totalDegree, support_monomial, if_neg hc]
theorem totalDegree_monomial_le (s : σ →₀ ℕ) (c : R) :
(monomial s c).totalDegree ≤ s.sum fun _ ↦ id := by
if hc : c = 0 then
simp only [hc, map_zero, totalDegree_zero, zero_le]
else
rw [totalDegree_monomial _ hc, Function.id_def]
@[simp]
theorem totalDegree_X_pow [Nontrivial R] (s : σ) (n : ℕ) :
(X s ^ n : MvPolynomial σ R).totalDegree = n := by simp [X_pow_eq_monomial, one_ne_zero]
theorem totalDegree_list_prod :
∀ s : List (MvPolynomial σ R), s.prod.totalDegree ≤ (s.map MvPolynomial.totalDegree).sum
| [] => by rw [List.prod_nil, totalDegree_one, List.map_nil, List.sum_nil]
| p::ps => by
rw [List.prod_cons, List.map, List.sum_cons]
exact le_trans (totalDegree_mul _ _) (add_le_add_left (totalDegree_list_prod ps) _)
theorem totalDegree_multiset_prod (s : Multiset (MvPolynomial σ R)) :
s.prod.totalDegree ≤ (s.map MvPolynomial.totalDegree).sum := by
refine Quotient.inductionOn s fun l => ?_
rw [Multiset.quot_mk_to_coe, Multiset.prod_coe, Multiset.map_coe, Multiset.sum_coe]
exact totalDegree_list_prod l
theorem totalDegree_finset_prod {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) :
(s.prod f).totalDegree ≤ ∑ i ∈ s, (f i).totalDegree := by
refine le_trans (totalDegree_multiset_prod _) ?_
simp only [Multiset.map_map, comp_apply, Finset.sum_map_val, le_refl]
theorem totalDegree_finset_sum {ι : Type*} (s : Finset ι) (f : ι → MvPolynomial σ R) :
(s.sum f).totalDegree ≤ Finset.sup s fun i => (f i).totalDegree := by
induction' s using Finset.cons_induction with a s has hind
· exact zero_le _
· rw [Finset.sum_cons, Finset.sup_cons]
exact (MvPolynomial.totalDegree_add _ _).trans (max_le_max le_rfl hind)
lemma totalDegree_finsetSum_le {ι : Type*} {s : Finset ι} {f : ι → MvPolynomial σ R} {d : ℕ}
(hf : ∀ i ∈ s, (f i).totalDegree ≤ d) : (s.sum f).totalDegree ≤ d :=
(totalDegree_finset_sum ..).trans <| Finset.sup_le hf
lemma degreeOf_le_totalDegree (f : MvPolynomial σ R) (i : σ) : f.degreeOf i ≤ f.totalDegree :=
degreeOf_le_iff.mpr fun d hd ↦ (eq_or_ne (d i) 0).elim (·.trans_le zero_le') fun h ↦
(Finset.single_le_sum (fun _ _ ↦ zero_le') <| Finsupp.mem_support_iff.mpr h).trans
(le_totalDegree hd)
theorem exists_degree_lt [Fintype σ] (f : MvPolynomial σ R) (n : ℕ)
(h : f.totalDegree < n * Fintype.card σ) {d : σ →₀ ℕ} (hd : d ∈ f.support) : ∃ i, d i < n := by
contrapose! h
calc
n * Fintype.card σ = ∑ _s : σ, n := by
rw [Finset.sum_const, Nat.nsmul_eq_mul, mul_comm, Finset.card_univ]
_ ≤ ∑ s, d s := Finset.sum_le_sum fun s _ => h s
_ ≤ d.sum fun _ e => e := by
rw [Finsupp.sum_fintype]
intros
rfl
_ ≤ f.totalDegree := le_totalDegree hd
theorem coeff_eq_zero_of_totalDegree_lt {f : MvPolynomial σ R} {d : σ →₀ ℕ}
(h : f.totalDegree < ∑ i ∈ d.support, d i) : coeff d f = 0 := by
classical
rw [totalDegree, Finset.sup_lt_iff] at h
· specialize h d
rw [mem_support_iff] at h
refine not_not.mp (mt h ?_)
exact lt_irrefl _
· exact lt_of_le_of_lt (Nat.zero_le _) h
theorem totalDegree_eq_zero_iff_eq_C {p : MvPolynomial σ R} :
p.totalDegree = 0 ↔ p = C (p.coeff 0) := by
constructor <;> intro h
· ext m; classical rw [coeff_C]; split_ifs with hm; · rw [← hm]
| apply coeff_eq_zero_of_totalDegree_lt; rw [h]
exact Finset.sum_pos (fun i hi ↦ Nat.pos_of_ne_zero <| Finsupp.mem_support_iff.mp hi)
(Finsupp.support_nonempty_iff.mpr <| Ne.symm hm)
· rw [h, totalDegree_C]
theorem totalDegree_rename_le (f : σ → τ) (p : MvPolynomial σ R) :
(rename f p).totalDegree ≤ p.totalDegree :=
Finset.sup_le fun b => by
classical
intro h
rw [rename_eq] at h
have h' := Finsupp.mapDomain_support h
| Mathlib/Algebra/MvPolynomial/Degrees.lean | 509 | 520 |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.PowerSeries.Basic
/-! # Formal power series (in one variable) - Order
The `PowerSeries.order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`.
If the coefficients form an integral domain, then `PowerSeries.order` is an
additive valuation (`PowerSeries.order_mul`, `PowerSeries.min_order_le_order_add`).
We prove that if the commutative ring `R` of coefficients is an integral domain,
then the ring `R⟦X⟧` of formal power series in one variable over `R`
is an integral domain.
Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order. This is useful when
proving that `R⟦X⟧` is a normalization monoid, which is done in `PowerSeries.Inverse`.
-/
noncomputable section
open Polynomial
open Finset (antidiagonal mem_antidiagonal)
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section OrderBasic
variable [Semiring R] {φ : R⟦X⟧}
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
refine not_iff_not.mp ?_
push_neg
simp [(coeff R _).map_zero]
/-- The order of a formal power series `φ` is the greatest `n : PartENat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
def order (φ : R⟦X⟧) : ℕ∞ :=
letI := Classical.decEq R
letI := Classical.decEq R⟦X⟧
if h : φ = 0 then ⊤ else Nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h)
/-- The order of the `0` power series is infinite. -/
@[simp]
theorem order_zero : order (0 : R⟦X⟧) = ⊤ :=
dif_pos rfl
theorem order_finite_iff_ne_zero : (order φ < ⊤) ↔ φ ≠ 0 := by
simp only [order]
split_ifs with h <;> simpa
/-- The `0` power series is the unique power series with infinite order. -/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
simpa using order_finite_iff_ne_zero.not_left
theorem coe_toNat_order {φ : R⟦X⟧} (hf : φ ≠ 0) : φ.order.toNat = φ.order := by
rw [ENat.coe_toNat_eq_self.mpr (order_eq_top.not.mpr hf)]
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero. -/
theorem coeff_order (h : φ ≠ 0) : coeff R φ.order.toNat φ ≠ 0 := by
classical
simp only [order, h, not_false_iff, dif_neg]
generalize_proofs h
exact Nat.find_spec h
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`. -/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
classical
rw [order, dif_neg]
· simpa using ⟨n, le_rfl, h⟩
· exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series. -/
theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by
contrapose! h
exact order_le _ h
theorem coeff_of_lt_order_toNat (n : ℕ) (h : n < φ.order.toNat) : coeff R n φ = 0 := by
by_cases h' : φ = 0
· simp [h']
· refine coeff_of_lt_order _ ?_
rwa [← coe_toNat_order h', ENat.coe_lt_coe]
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`. -/
theorem nat_le_order (φ : R⟦X⟧) (n : ℕ) (h : ∀ i < n, coeff R i φ = 0) : ↑n ≤ order φ := by
classical
simp only [order]
split_ifs
· simp
· simpa [Nat.le_find_iff]
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`. -/
theorem le_order (φ : R⟦X⟧) (n : ℕ∞) (h : ∀ i : ℕ, ↑i < n → coeff R i φ = 0) :
n ≤ order φ := by
cases n with
| top => simpa using ext (by simpa using h)
| coe n =>
convert nat_le_order φ n _
simpa using h
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`. -/
theorem order_eq_nat {φ : R⟦X⟧} {n : ℕ} :
order φ = n ↔ coeff R n φ ≠ 0 ∧ ∀ i, i < n → coeff R i φ = 0 := by
classical
rcases eq_or_ne φ 0 with (rfl | hφ)
· simp
simp [order, dif_neg hφ, Nat.find_eq_iff]
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`. -/
theorem order_eq {φ : R⟦X⟧} {n : ℕ∞} :
order φ = n ↔ (∀ i : ℕ, ↑i = n → coeff R i φ ≠ 0) ∧ ∀ i : ℕ, ↑i < n → coeff R i φ = 0 := by
cases n with
| top => simp [ext_iff]
| coe n => simp [order_eq_nat]
/-- The order of the sum of two formal power series
is at least the minimum of their orders. -/
theorem min_order_le_order_add (φ ψ : R⟦X⟧) : min (order φ) (order ψ) ≤ order (φ + ψ) := by
refine le_order _ _ ?_
simp +contextual [coeff_of_lt_order]
@[deprecated (since := "2024-11-12")] alias le_order_add := min_order_le_order_add
private theorem order_add_of_order_eq.aux (φ ψ : R⟦X⟧)
(H : order φ < order ψ) : order (φ + ψ) ≤ order φ ⊓ order ψ := by
suffices order (φ + ψ) = order φ by
rw [le_inf_iff, this]
exact ⟨le_rfl, le_of_lt H⟩
rw [order_eq]
constructor
· intro i hi
rw [← hi] at H
rw [(coeff _ _).map_add, coeff_of_lt_order i H, add_zero]
exact (order_eq_nat.1 hi.symm).1
· intro i hi
rw [(coeff _ _).map_add, coeff_of_lt_order i hi, coeff_of_lt_order i (lt_trans hi H),
zero_add]
/-- The order of the sum of two formal power series
is the minimum of their orders if their orders differ. -/
theorem order_add_of_order_eq (φ ψ : R⟦X⟧) (h : order φ ≠ order ψ) :
order (φ + ψ) = order φ ⊓ order ψ := by
refine le_antisymm ?_ (min_order_le_order_add _ _)
rcases h.lt_or_lt with (φ_lt_ψ | ψ_lt_φ)
· apply order_add_of_order_eq.aux _ _ φ_lt_ψ
· simpa only [add_comm, inf_comm] using order_add_of_order_eq.aux _ _ ψ_lt_φ
/-- The order of the product of two formal power series
is at least the sum of their orders. -/
theorem le_order_mul (φ ψ : R⟦X⟧) : order φ + order ψ ≤ order (φ * ψ) := by
apply le_order
intro n hn; rw [coeff_mul, Finset.sum_eq_zero]
rintro ⟨i, j⟩ hij
by_cases hi : ↑i < order φ
· rw [coeff_of_lt_order i hi, zero_mul]
by_cases hj : ↑j < order ψ
· rw [coeff_of_lt_order j hj, mul_zero]
rw [not_lt] at hi hj; rw [mem_antidiagonal] at hij
exfalso
apply ne_of_lt (lt_of_lt_of_le hn <| add_le_add hi hj)
rw [← Nat.cast_add, hij]
theorem le_order_pow (φ : R⟦X⟧) (n : ℕ) : n • order φ ≤ order (φ ^ n) := by
induction n with
| zero => simp
| succ n hn =>
simp only [add_smul, one_smul, pow_succ]
apply le_trans _ (le_order_mul _ _)
exact add_le_add_right hn φ.order
alias order_mul_ge := le_order_mul
/-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise. -/
theorem order_monomial (n : ℕ) (a : R) [Decidable (a = 0)] :
order (monomial R n a) = if a = 0 then (⊤ : ℕ∞) else n := by
split_ifs with h
· rw [h, order_eq_top, LinearMap.map_zero]
· rw [order_eq]
constructor <;> intro i hi
· simp only [Nat.cast_inj] at hi
rwa [hi, coeff_monomial_same]
· simp only [Nat.cast_lt] at hi
rw [coeff_monomial, if_neg]
exact ne_of_lt hi
/-- The order of the monomial `a*X^n` is `n` if `a ≠ 0`. -/
theorem order_monomial_of_ne_zero (n : ℕ) (a : R) (h : a ≠ 0) : order (monomial R n a) = n := by
classical
rw [order_monomial, if_neg h]
/-- If `n` is strictly smaller than the order of `ψ`, then the `n`th coefficient of its product
with any other power series is `0`. -/
theorem coeff_mul_of_lt_order {φ ψ : R⟦X⟧} {n : ℕ} (h : ↑n < ψ.order) :
coeff R n (φ * ψ) = 0 := by
suffices coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, 0 by rw [this, Finset.sum_const_zero]
rw [coeff_mul]
apply Finset.sum_congr rfl
intro x hx
refine mul_eq_zero_of_right (coeff R x.fst φ) (coeff_of_lt_order x.snd (lt_of_le_of_lt ?_ h))
rw [mem_antidiagonal] at hx
norm_cast
omega
theorem coeff_mul_one_sub_of_lt_order {R : Type*} [Ring R] {φ ψ : R⟦X⟧} (n : ℕ)
(h : ↑n < ψ.order) : coeff R n (φ * (1 - ψ)) = coeff R n φ := by
simp [coeff_mul_of_lt_order h, mul_sub]
theorem coeff_mul_prod_one_sub_of_lt_order {R ι : Type*} [CommRing R] (k : ℕ) (s : Finset ι)
(φ : R⟦X⟧) (f : ι → R⟦X⟧) :
(∀ i ∈ s, ↑k < (f i).order) → coeff R k (φ * ∏ i ∈ s, (1 - f i)) = coeff R k φ := by
classical
induction' s using Finset.induction_on with a s ha ih t
· simp
· intro t
simp only [Finset.mem_insert, forall_eq_or_imp] at t
rw [Finset.prod_insert ha, ← mul_assoc, mul_right_comm, coeff_mul_one_sub_of_lt_order _ t.1]
exact ih t.2
/-- Given a non-zero power series `f`, `divXPowOrder f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order -/
def divXPowOrder (f : R⟦X⟧) : R⟦X⟧ :=
.mk fun n ↦ coeff R (n + f.order.toNat) f
@[deprecated (since := "2025-04-15")]
noncomputable alias divided_by_X_pow_order := divXPowOrder
@[simp]
lemma coeff_divXPowOrder {f : R⟦X⟧} {n : ℕ} :
coeff R n (divXPowOrder f) = coeff R (n + f.order.toNat) f :=
coeff_mk _ _
@[simp]
lemma divXPowOrder_zero :
divXPowOrder (0 : R⟦X⟧) = 0 := by
ext
simp
lemma constantCoeff_divXPowOrder {f : R⟦X⟧} :
constantCoeff R (divXPowOrder f) = coeff R f.order.toNat f := by
simp [← coeff_zero_eq_constantCoeff]
lemma constantCoeff_divXPowOrder_eq_zero_iff {f : R⟦X⟧} :
constantCoeff R (divXPowOrder f) = 0 ↔ f = 0 := by
by_cases h : f = 0
· simp [h]
· simp [constantCoeff_divXPowOrder, coeff_order h, h]
theorem X_pow_order_mul_divXPowOrder {f : R⟦X⟧} :
X ^ f.order.toNat * divXPowOrder f = f := by
ext n
rw [coeff_X_pow_mul']
split_ifs with h
· simp [h]
· push_neg at h
rw [coeff_of_lt_order_toNat _ h]
@[deprecated (since := "2025-04-15")]
alias self_eq_X_pow_order_mul_divided_by_X_pow_order := X_pow_order_mul_divXPowOrder
theorem X_pow_order_dvd : X ^ φ.order.toNat ∣ φ := by
simpa only [X_pow_dvd_iff] using coeff_of_lt_order_toNat
theorem order_eq_emultiplicity_X {R : Type*} [Semiring R] (φ : R⟦X⟧) :
order φ = emultiplicity X φ := by
classical
rcases eq_or_ne φ 0 with (rfl | hφ)
· simp
cases ho : order φ with
| top => simp [hφ] at ho
| coe n =>
have hn : φ.order.toNat = n := by simp [ho]
rw [← hn, eq_comm]
apply le_antisymm _
· apply le_emultiplicity_of_pow_dvd
apply X_pow_order_dvd
· apply Order.le_of_lt_add_one
rw [← not_le, ← Nat.cast_one, ← Nat.cast_add, ← pow_dvd_iff_le_emultiplicity]
rintro ⟨ψ, H⟩
have := congr_arg (coeff R n) H
rw [X_pow_mul, coeff_mul_of_lt_order, ← hn] at this
· exact coeff_order hφ this
· rw [X_pow_eq, order_monomial]
split_ifs
· simp
· rw [← hn, ENat.coe_lt_coe]
simp
end OrderBasic
section OrderZeroNeOne
variable [Semiring R] [Nontrivial R]
/-- The order of the formal power series `1` is `0`. -/
@[simp]
theorem order_one : order (1 : R⟦X⟧) = 0 := by
simpa using order_monomial_of_ne_zero 0 (1 : R) one_ne_zero
/-- The order of an invertible power series is `0`. -/
theorem order_zero_of_unit {f : R⟦X⟧} : IsUnit f → f.order = 0 := by
rintro ⟨⟨u, v, hu, hv⟩, hf⟩
apply And.left
rw [← add_eq_zero, ← hf, ← nonpos_iff_eq_zero, ← @order_one R _ _, ← hu]
exact order_mul_ge _ _
/-- The order of the formal power series `X` is `1`. -/
@[simp]
theorem order_X : order (X : R⟦X⟧) = 1 := by
simpa only [Nat.cast_one] using order_monomial_of_ne_zero 1 (1 : R) one_ne_zero
/-- The order of the formal power series `X^n` is `n`. -/
@[simp]
theorem order_X_pow (n : ℕ) : order ((X : R⟦X⟧) ^ n) = n := by
rw [X_pow_eq, order_monomial_of_ne_zero]
exact one_ne_zero
/-- Dividing `X` by the maximal power of `X` dividing it leaves `1`. -/
@[simp]
theorem divXPowOrder_X :
divXPowOrder X = (1 : R⟦X⟧) := by
ext n
simp [coeff_X]
@[deprecated (since := "2025-04-15")] alias divided_by_X_pow_order_of_X_eq_one := divXPowOrder_X
end OrderZeroNeOne
section NoZeroDivisors
variable [Semiring R] [NoZeroDivisors R]
/-- The order of the product of two formal power series over an integral domain
is the sum of their orders. -/
theorem order_mul (φ ψ : R⟦X⟧) : order (φ * ψ) = order φ + order ψ := by
apply le_antisymm _ (le_order_mul _ _)
by_cases h : φ = 0 ∨ ψ = 0
· rcases h with h | h <;> simp [h]
· push_neg at h
rw [← coe_toNat_order h.1, ← coe_toNat_order h.2, ← ENat.coe_add]
apply order_le
| rw [coeff_mul, Finset.sum_eq_single_of_mem ⟨φ.order.toNat, ψ.order.toNat⟩ (by simp)]
· exact mul_ne_zero (coeff_order h.1) (coeff_order h.2)
· intro ij hij h
rcases trichotomy_of_add_eq_add (mem_antidiagonal.mp hij) with h' | h' | h'
| Mathlib/RingTheory/PowerSeries/Order.lean | 362 | 365 |
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.UniformSpace.Cauchy
/-!
# Uniform convergence
A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality
`dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `ℕ` with `atTop`).
## Main results
Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β`
(where the index `n` belongs to an indexing type `ι` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fₙ y) ∈ u` for all `y ∈ s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends
to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then
`Fₙ gₙ` tends to `f x`.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set Uniform
variable {α β γ ι : Type*} [UniformSpace β]
variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α}
/-!
### Different notions of uniform convergence
We define uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/
def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u
/--
A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) :=
Iff.rfl
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/
def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forall₂_congr
simp_rw [eventually_prod_principal_iff]
simp
alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto :
TendstoUniformlyOn F f p s ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x`. -/
def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by
rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter]
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p :=
| forall₂_congr fun u _ => by simp
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity.
| Mathlib/Topology/UniformSpace/UniformConvergence.lean | 124 | 127 |
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Sébastien Gouëzel
-/
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Measure.Doubling
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
/-!
# Relationship between the Haar and Lebesgue measures
We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ι`, in
`MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`.
We deduce basic properties of any Haar measure on a finite dimensional real vector space:
* `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the
absolute value of its determinant.
* `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure
of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the
determinant of `f`.
* `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the
measure of `s` multiplied by the absolute value of the determinant of `f`.
* `addHaar_submodule` : a strict submodule has measure `0`.
* `addHaar_smul` : the measure of `r • s` is `|r| ^ dim * μ s`.
* `addHaar_ball`: the measure of `ball x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * μ (ball 0 1)`.
* `addHaar_sphere`: spheres have zero measure.
This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`.
This measure is called `AlternatingMap.measure`. Its main property is
`ω.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned
by vectors `v₁, ..., vₙ` is given by `|ω v|`.
We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has
density one for the rescaled copies `{x} + r • t` of a given set `t` with positive measure, in
`tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r • t` for
small `r`, see `eventually_nonempty_inter_smul_of_density_one`.
Statements on integrals of functions with respect to an additive Haar measure can be found in
`MeasureTheory.Measure.Haar.NormedSpace`.
-/
assert_not_exists MeasureTheory.integral
open TopologicalSpace Set Filter Metric Bornology
open scoped ENNReal Pointwise Topology NNReal
/-- The interval `[0,1]` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where
carrier := Icc 0 1
isCompact' := isCompact_Icc
interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]
universe u
/-- The set `[0,1]^ι` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.piIcc01 (ι : Type*) [Finite ι] :
PositiveCompacts (ι → ℝ) where
carrier := pi univ fun _ => Icc 0 1
isCompact' := isCompact_univ_pi fun _ => isCompact_Icc
interior_nonempty' := by
simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,
imp_true_iff, zero_lt_one]
/-- The parallelepiped formed from the standard basis for `ι → ℝ` is `[0,1]^ι` -/
theorem Basis.parallelepiped_basisFun (ι : Type*) [Fintype ι] :
(Pi.basisFun ℝ ι).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ι :=
SetLike.coe_injective <| by
refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm)
· classical convert parallelepiped_single (ι := ι) 1
· exact zero_le_one
/-- A parallelepiped can be expressed on the standard basis. -/
theorem Basis.parallelepiped_eq_map {ι E : Type*} [Fintype ι] [NormedAddCommGroup E]
[NormedSpace ℝ E] (b : Basis ι ℝ E) :
b.parallelepiped = (PositiveCompacts.piIcc01 ι).map b.equivFun.symm
b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by
classical
rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map]
congr with x
simp [Pi.single_apply]
open MeasureTheory MeasureTheory.Measure
theorem Basis.map_addHaar {ι E F : Type*} [Fintype ι] [NormedAddCommGroup E] [NormedAddCommGroup F]
[NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E]
[BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F]
(b : Basis ι ℝ E) (f : E ≃L[ℝ] F) :
map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by
have : IsAddHaarMeasure (map f b.addHaar) :=
AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous
rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable
(PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map]
erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self]
namespace MeasureTheory
open Measure TopologicalSpace.PositiveCompacts Module
/-!
### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ι`.
-/
/-- The Haar measure equals the Lebesgue measure on `ℝ`. -/
theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by
convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01]
/-- The Haar measure equals the Lebesgue measure on `ℝ^ι`. -/
theorem addHaarMeasure_eq_volume_pi (ι : Type*) [Fintype ι] :
addHaarMeasure (piIcc01 ι) = volume := by
convert (addHaarMeasure_unique volume (piIcc01 ι)).symm
simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk,
Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero]
theorem isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] :
IsAddHaarMeasure (volume : Measure (ι → ℝ)) :=
inferInstance
namespace Measure
/-!
### Strict subspaces have zero measure
-/
open scoped Function -- required for scoped `on` notation
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/
theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (sb : IsBounded s) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
by_contra h
apply lt_irrefl ∞
calc
∞ = ∑' _ : ℕ, μ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm
_ = ∑' n : ℕ, μ ({u n} + s) := by
congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add]
_ = μ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by
simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's
_ = μ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range]
_ < ∞ := (hu.add sb).measure_lt_top
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. -/
theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E)
[IsAddHaarMeasure μ] {s : Set E} (u : ℕ → E) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : μ s = 0 := by
suffices H : ∀ R, μ (s ∩ closedBall 0 R) = 0 by
apply le_antisymm _ (zero_le _)
calc
μ s ≤ ∑' n : ℕ, μ (s ∩ closedBall 0 n) := by
conv_lhs => rw [← iUnion_inter_closedBall_nat s 0]
exact measure_iUnion_le _
_ = 0 := by simp only [H, tsum_zero]
intro R
apply addHaar_eq_zero_of_disjoint_translates_aux μ u
(isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall)
refine pairwise_disjoint_mono hs fun n => ?_
exact add_subset_add Subset.rfl inter_subset_left
/-- A strict vector subspace has measure zero. -/
theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E]
[BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] (s : Submodule ℝ E)
(hs : s ≠ ⊤) : μ s = 0 := by
obtain ⟨x, hx⟩ : ∃ x, x ∉ s := by
simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs
obtain ⟨c, cpos, cone⟩ : ∃ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩
have A : IsBounded (range fun n : ℕ => c ^ n • x) :=
have : Tendsto (fun n : ℕ => c ^ n • x) atTop (𝓝 ((0 : ℝ) • x)) :=
(tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x
isBounded_range_of_tendsto _ this
apply addHaar_eq_zero_of_disjoint_translates μ _ A _
(Submodule.closed_of_finiteDimensional s).measurableSet
intro m n hmn
simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage,
SetLike.mem_coe]
intro y hym hyn
have A : (c ^ n - c ^ m) • x ∈ s := by
convert s.sub_mem hym hyn using 1
simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub]
have H : c ^ n - c ^ m ≠ 0 := by
simpa only [sub_eq_zero, Ne] using (pow_right_strictAnti₀ cpos cone).injective.ne hmn.symm
have : x ∈ s := by
convert s.smul_mem (c ^ n - c ^ m)⁻¹ A
rw [smul_smul, inv_mul_cancel₀ H, one_smul]
exact hx this
/-- A strict affine subspace has measure zero. -/
theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
(s : AffineSubspace ℝ E) (hs : s ≠ ⊤) : μ s = 0 := by
rcases s.eq_bot_or_nonempty with (rfl | hne)
· rw [AffineSubspace.bot_coe, measure_empty]
rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs
rcases hne with ⟨x, hx : x ∈ s⟩
simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg,
image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule μ s.direction hs
/-!
### Applying a linear map rescales Haar measure by the determinant
We first prove this on `ι → ℝ`, using that this is already known for the product Lebesgue
measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real
vector space by using a linear equiv with a space of the form `ι → ℝ`, and arguing that such a
linear equiv maps Haar measure to Haar measure.
-/
theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ι : Type*} [Finite ι] {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ}
(hf : LinearMap.det f ≠ 0) (μ : Measure (ι → ℝ)) [IsAddHaarMeasure μ] :
Measure.map f μ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • μ := by
cases nonempty_fintype ι
/- We have already proved the result for the Lebesgue product measure, using matrices.
We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/
have := addHaarMeasure_unique μ (piIcc01 ι)
rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul,
Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ]
theorem map_linearMap_addHaar_eq_smul_addHaar {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) :
Measure.map f μ = ENNReal.ofReal |(LinearMap.det f)⁻¹| • μ := by
-- we reduce to the case of `E = ι → ℝ`, for which we have already proved the result using
-- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`.
let ι := Fin (finrank ℝ E)
haveI : FiniteDimensional ℝ (ι → ℝ) := by infer_instance
have : finrank ℝ E = finrank ℝ (ι → ℝ) := by simp [ι]
have e : E ≃ₗ[ℝ] ι → ℝ := LinearEquiv.ofFinrankEq E (ι → ℝ) this
-- next line is to avoid `g` getting reduced by `simp`.
obtain ⟨g, hg⟩ : ∃ g, g = (e : E →ₗ[ℝ] ι → ℝ).comp (f.comp (e.symm : (ι → ℝ) →ₗ[ℝ] E)) := ⟨_, rfl⟩
have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e
rw [← gdet] at hf ⊢
have fg : f = (e.symm : (ι → ℝ) →ₗ[ℝ] E).comp (g.comp (e : E →ₗ[ℝ] ι → ℝ)) := by
ext x
simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp,
LinearEquiv.symm_apply_apply, hg]
simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp]
have Ce : Continuous e := (e : E →ₗ[ℝ] ι → ℝ).continuous_of_finiteDimensional
have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g
have Cesymm : Continuous e.symm := (e.symm : (ι → ℝ) →ₗ[ℝ] E).continuous_of_finiteDimensional
rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable]
haveI : IsAddHaarMeasure (map e μ) := (e : E ≃+ (ι → ℝ)).isAddHaarMeasure_map μ Ce Cesymm
have ecomp : e.symm ∘ e = id := by
ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply]
rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e μ), Measure.map_smul,
map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id]
/-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearMap {f : E →ₗ[ℝ] E} (hf : LinearMap.det f ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s :=
calc
μ (f ⁻¹' s) = Measure.map f μ s :=
((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply
s).symm
_ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * μ s := by
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]; rfl
/-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearMap {f : E →L[ℝ] E}
(hf : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E →ₗ[ℝ] E))⁻¹) * μ s :=
addHaar_preimage_linearMap μ hf s
/-- The preimage of a set `s` under a linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s := by
have A : LinearMap.det (f : E →ₗ[ℝ] E) ≠ 0 := (LinearEquiv.isUnit_det' f).ne_zero
convert addHaar_preimage_linearMap μ A s
simp only [LinearEquiv.det_coe_symm]
/-- The preimage of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E →ₗ[ℝ] E)| * μ s :=
addHaar_preimage_linearEquiv μ _ s
/-- The image of a set `s` under a linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_linearMap (f : E →ₗ[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det f| * μ s := by
rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf)
· let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv
change μ (g '' s) = _
rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv]
congr
· simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero]
have : μ (LinearMap.range f) = 0 :=
addHaar_submodule μ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne
exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _)
/-- The image of a set `s` under a continuous linear map `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearMap (f : E →L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
addHaar_image_linearMap μ _ s
/-- The image of a set `s` under a continuous linear equiv `f` has measure
equal to `μ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) :
μ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E →ₗ[ℝ] E)| * μ s :=
μ.addHaar_image_linearMap (f : E →ₗ[ℝ] E) s
theorem LinearMap.quasiMeasurePreserving (f : E →ₗ[ℝ] E) (hf : LinearMap.det f ≠ 0) :
QuasiMeasurePreserving f μ μ := by
refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩
rw [map_linearMap_addHaar_eq_smul_addHaar μ hf]
exact smul_absolutelyContinuous
theorem ContinuousLinearMap.quasiMeasurePreserving (f : E →L[ℝ] E) (hf : f.det ≠ 0) :
QuasiMeasurePreserving f μ μ :=
LinearMap.quasiMeasurePreserving μ (f : E →ₗ[ℝ] E) hf
/-!
### Basic properties of Haar measures on real vector spaces
-/
theorem map_addHaar_smul {r : ℝ} (hr : r ≠ 0) :
Measure.map (r • ·) μ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) • μ := by
let f : E →ₗ[ℝ] E := r • (1 : E →ₗ[ℝ] E)
change Measure.map f μ = _
have hf : LinearMap.det f ≠ 0 := by
simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one]
intro h
exact hr (pow_eq_zero h)
simp only [f, map_linearMap_addHaar_eq_smul_addHaar μ hf, mul_one, LinearMap.det_smul, map_one]
theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r ≠ 0) :
QuasiMeasurePreserving (r • ·) μ μ := by
refine ⟨measurable_const_smul r, ?_⟩
rw [map_addHaar_smul μ hr]
exact smul_absolutelyContinuous
@[simp]
theorem addHaar_preimage_smul {r : ℝ} (hr : r ≠ 0) (s : Set E) :
μ ((r • ·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s :=
calc
μ ((r • ·) ⁻¹' s) = Measure.map (r • ·) μ s :=
((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * μ s := by
rw [map_addHaar_smul μ hr, coe_smul, Pi.smul_apply, smul_eq_mul]
/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/
@[simp]
theorem addHaar_smul (r : ℝ) (s : Set E) :
μ (r • s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
rcases ne_or_eq r 0 with (h | rfl)
· rw [← preimage_smul_inv₀ h, addHaar_preimage_smul μ (inv_ne_zero h), inv_pow, inv_inv]
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp only [measure_empty, mul_zero, smul_set_empty]
rw [zero_smul_set hs, ← singleton_zero]
by_cases h : finrank ℝ E = 0
· haveI : Subsingleton E := finrank_zero_iff.1 h
simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs,
pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))]
· haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h)
simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff,
zero_pow, measure_singleton]
theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≤ r) (s : Set E) :
μ (r • s) = ENNReal.ofReal (r ^ finrank ℝ E) * μ s := by
rw [addHaar_smul, abs_pow, abs_of_nonneg hr]
variable {μ} {s : Set E}
-- Note: We might want to rename this once we acquire the lemma corresponding to
-- `MeasurableSet.const_smul`
theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s μ) (r : ℝ) :
NullMeasurableSet (r • s) μ := by
obtain rfl | hs' := s.eq_empty_or_nonempty
· simp
obtain rfl | hr := eq_or_ne r 0
· simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _
obtain ⟨t, ht, hst⟩ := hs
refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩
rw [← measure_symmDiff_eq_zero_iff] at hst ⊢
rw [← smul_set_symmDiff₀ hr, addHaar_smul μ, hst, mul_zero]
variable (μ)
@[simp]
theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) :
μ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s :=
calc
μ (AffineMap.homothety x r '' s) = μ ((fun y => y + x) '' (r • (fun y => y + -x) '' s)) := by
simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl
_ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * μ s := by
simp only [image_add_right, measure_preimage_add_right, addHaar_smul]
/-! We don't need to state `map_addHaar_neg` here, because it has already been proved for
general Haar measures on general commutative groups. -/
/-! ### Measure of balls -/
theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E]
(μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) : μ (ball x r) = μ (ball (0 : E) r) := by
have : ball (0 : E) r = (x + ·) ⁻¹' ball x r := by simp [preimage_add_ball]
rw [this, measure_preimage_add]
theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ.real (ball x r) = μ.real (ball (0 : E) r) := by
simp [measureReal_def, addHaar_ball_center]
theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ (closedBall x r) = μ (closedBall (0 : E) r) := by
have : closedBall (0 : E) r = (x + ·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall]
rw [this, measure_preimage_add]
theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (x : E) (r : ℝ) :
μ.real (closedBall x r) = μ.real (closedBall (0 : E) r) := by
simp [measureReal_def, addHaar_closedBall_center]
theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
have : ball (0 : E) (r * s) = r • ball (0 : E) s := by
simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow]
theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul_of_pos μ x hr, mul_one]
theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) (s : ℝ) :
μ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 s) := by
rcases hr.eq_or_lt with (rfl | h)
· simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul,
ENNReal.ofReal_zero, ball_zero]
· exact addHaar_ball_mul_of_pos μ x h s
theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by
rw [← addHaar_ball_mul μ x hr, mul_one]
theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow]
theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ s) :
μ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r • closedBall (0 : E) s := by
simp [smul_closedBall r (0 : E) hs, abs_of_nonneg hr]
simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow]
/-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball.
Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard
form. -/
theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by
rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one]
| theorem addHaar_real_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) :
μ.real (closedBall x r) = r ^ finrank ℝ E * μ.real (closedBall 0 1) := by
simp only [measureReal_def, addHaar_closedBall' μ x hr, ENNReal.toReal_mul, mul_eq_mul_right_iff,
| Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean | 474 | 476 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Projection
import Mathlib.Geometry.Euclidean.Sphere.Basic
import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional
import Mathlib.Tactic.DeriveFintype
/-!
# Circumcenter and circumradius
This file proves some lemmas on points equidistant from a set of
points, and defines the circumradius and circumcenter of a simplex.
There are also some definitions for use in calculations where it is
convenient to work with affine combinations of vertices together with
the circumcenter.
## Main definitions
* `circumcenter` and `circumradius` are the circumcenter and
circumradius of a simplex.
## References
* https://en.wikipedia.org/wiki/Circumscribed_circle
-/
noncomputable section
open RealInnerProductSpace
namespace EuclideanGeometry
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P]
open AffineSubspace
/-- The induction step for the existence and uniqueness of the
circumcenter. Given a nonempty set of points in a nonempty affine
subspace whose direction is complete, such that there is a unique
(circumcenter, circumradius) pair for those points in that subspace,
and a point `p` not in that subspace, there is a unique (circumcenter,
circumradius) pair for the set with `p` added, in the span of the
subspace with `p` added. -/
theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P}
[s.direction.HasOrthogonalProjection] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s)
(hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) :
∃! cs₂ : Sphere P,
cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by
haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps)
rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩
simp only at hcc hcr hcccru
let x := dist cc (orthogonalProjection s p)
let y := dist p (orthogonalProjection s p)
have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_not_mem hp
let ycc₂ := (x * x + y * y - cr * cr) / (2 * y)
let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc
let cr₂ := √(cr * cr + ycc₂ * ycc₂)
use ⟨cc₂, cr₂⟩
simp -zeta -proj only
have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) :=
by simp
constructor
· constructor
· refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc))
rw [direction_affineSpan]
exact
Submodule.smul_mem _ _
(vsub_mem_vectorSpan ℝ (Set.mem_insert _ _)
(Set.mem_insert_of_mem _ (orthogonalProjection_mem _)))
· intro p₁ hp₁
rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _),
Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))]
rcases hp₁ with hp₁ | hp₁
· rw [hp₁]
rw [hpo,
dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _
(vsub_orthogonalProjection_mem_direction_orthogonal s p),
← dist_eq_norm_vsub V p, dist_comm _ cc]
-- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp`, but was really slow
-- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster.
simp (disch := field_simp_discharge) only [div_div, sub_div', one_mul, mul_div_assoc',
div_mul_eq_mul_div, add_div', eq_div_iff, div_eq_iff, ycc₂]
ring
· rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp₁),
orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk,
dist_of_mem_subset_mk_sphere hp₁ hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ←
dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg,
div_mul_cancel₀ _ hy0, abs_mul_abs_self]
· rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩
simp only at hcc₃ hcr₃
obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ :
∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by
rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃
have hcr₃' : ∃ r, ∀ p₁ ∈ ps, dist p₁ cc₃ = r :=
⟨cr₃, fun p₁ hp₁ => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp₁) hcr₃⟩
rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'',
orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃'
obtain ⟨cr₃', hcr₃'⟩ := hcr₃'
have hu := hcccru ⟨cc₃', cr₃'⟩
simp only at hu
replace hu := hu ⟨hcc₃', hcr₃'⟩
-- Porting note: was
-- cases' hu with hucc hucr
-- substs hucc hucr
cases hu
have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by
obtain ⟨p0, hp0⟩ := hnps
have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl
rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ←
mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _),
Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)),
dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0),
orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h',
dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ←
dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc,
abs_mul_abs_self]
ring
replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃
rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _),
dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _
(vsub_orthogonalProjection_mem_direction_orthogonal s p),
dist_comm, ← dist_eq_norm_vsub V p,
Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃
change x * x + _ * (y * y) = _ at hcr₃
rw [show
x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y)
by ring,
add_left_inj] at hcr₃
have ht₃ : t₃ = ycc₂ / y := by field_simp [ycc₂, ← hcr₃, hy0]
subst ht₃
change cc₃ = cc₂ at hcc₃''
congr
rw [hcr₃val]
congr 2
field_simp [hy0]
/-- Given a finite nonempty affinely independent family of points,
there is a unique (circumcenter, circumradius) pair for those points
in the affine subspace they span. -/
theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι]
{p : ι → P} (ha : AffineIndependent ℝ p) :
∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by
cases nonempty_fintype ι
induction' hn : Fintype.card ι with m hm generalizing ι
· exfalso
have h := Fintype.card_pos_iff.2 hne
rw [hn] at h
exact lt_irrefl 0 h
· rcases m with - | m
· rw [Fintype.card_eq_one_iff] at hn
obtain ⟨i, hi⟩ := hn
haveI : Unique ι := ⟨⟨i⟩, hi⟩
use ⟨p i, 0⟩
simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton]
constructor
· simp_rw [hi default, Set.singleton_subset_iff]
exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩
· rintro ⟨cc, cr⟩
simp only
rintro ⟨rfl, hdist⟩
simp? [Set.singleton_subset_iff] at hdist says
simp only [Set.singleton_subset_iff, Metric.mem_sphere, dist_self] at hdist
rw [hi default, hdist]
· have i := hne.some
let ι2 := { x // x ≠ i }
classical
have hc : Fintype.card ι2 = m + 1 := by
rw [Fintype.card_of_subtype {x | x ≠ i}]
· rw [Finset.filter_not]
-- Porting note: removed `simp_rw [eq_comm]` and used `filter_eq'` instead of `filter_eq`
rw [Finset.filter_eq' _ i, if_pos (Finset.mem_univ _),
Finset.card_sdiff (Finset.subset_univ _), Finset.card_singleton, Finset.card_univ, hn]
simp
· simp
haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _)
have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _
replace hm := hm ha2 _ hc
have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by
change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2)
rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq]
congr with j
simp [Classical.em]
rw [hr, ← affineSpan_insert_affineSpan]
refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_affineSpan ℝ _) ?_ hm
convert ha.not_mem_affineSpan_diff i Set.univ
change (Set.range fun i2 : { x | x ≠ i } => p i2) = _
rw [← Set.image_eq_range]
congr with j
simp
end EuclideanGeometry
namespace Affine
namespace Simplex
open Finset AffineSubspace EuclideanGeometry
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P]
/-- The circumsphere of a simplex. -/
def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P :=
s.independent.existsUnique_dist_eq.choose
/-- The property satisfied by the circumsphere. -/
theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) :
(s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧
Set.range s.points ⊆ s.circumsphere) ∧
∀ cs : Sphere P,
cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs →
cs = s.circumsphere :=
s.independent.existsUnique_dist_eq.choose_spec
/-- The circumcenter of a simplex. -/
def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P :=
s.circumsphere.center
/-- The circumradius of a simplex. -/
def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ :=
s.circumsphere.radius
/-- The center of the circumsphere is the circumcenter. -/
@[simp]
theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter :=
rfl
/-- The radius of the circumsphere is the circumradius. -/
@[simp]
theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius :=
rfl
/-- The circumcenter lies in the affine span. -/
theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) :
s.circumcenter ∈ affineSpan ℝ (Set.range s.points) :=
s.circumsphere_unique_dist_eq.1.1
/-- All points have distance from the circumcenter equal to the
circumradius. -/
@[simp]
theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) :
dist (s.points i) s.circumcenter = s.circumradius :=
dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2
/-- All points lie in the circumsphere. -/
theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) :
s.points i ∈ s.circumsphere :=
s.dist_circumcenter_eq_circumradius i
/-- All points have distance to the circumcenter equal to the
circumradius. -/
@[simp]
theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) :
∀ i, dist s.circumcenter (s.points i) = s.circumradius := by
intro i
rw [dist_comm]
exact dist_circumcenter_eq_circumradius _ _
/-- Given a point in the affine span from which all the points are
equidistant, that point is the circumcenter. -/
theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P}
(hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) :
p = s.circumcenter := by
have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩
simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff,
Set.forall_mem_range, mem_sphere, true_and] at h
-- Porting note: added the next three lines (`simp` less powerful)
rw [subset_sphere (s := ⟨p, r⟩)] at h
simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff,
Set.forall_mem_range, mem_sphere, true_and] at h
exact h.1
/-- Given a point in the affine span from which all the points are
equidistant, that distance is the circumradius. -/
theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P}
(hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) :
r = s.circumradius := by
have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩
simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff,
Set.forall_mem_range, mem_sphere] at h
-- Porting note: added the next three lines (`simp` less powerful)
rw [subset_sphere (s := ⟨p, r⟩)] at h
simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff,
Set.forall_mem_range, mem_sphere, true_and] at h
exact h.2
/-- The circumradius is non-negative. -/
theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius :=
s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg
/-- The circumradius of a simplex with at least two points is
positive. -/
theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by
refine lt_of_le_of_ne s.circumradius_nonneg ?_
intro h
have hr := s.dist_circumcenter_eq_circumradius
simp_rw [← h, dist_eq_zero] at hr
have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1)
simp [hr] at h01
/-- The circumcenter of a 0-simplex equals its unique point. -/
theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by
have h := s.circumcenter_mem_affineSpan
have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩
simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h
rw [h]
congr
simp only [eq_iff_true_of_subsingleton]
/-- The circumcenter of a 1-simplex equals its centroid. -/
theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) :
s.circumcenter = Finset.univ.centroid ℝ s.points := by
have hr :
Set.Pairwise Set.univ fun i j : Fin 2 =>
dist (s.points i) (Finset.univ.centroid ℝ s.points) =
dist (s.points j) (Finset.univ.centroid ℝ s.points) := by
intro i hi j hj hij
rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i),
dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ←
one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)]
fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num
rw [Set.pairwise_eq_iff_exists_eq] at hr
obtain ⟨r, hr⟩ := hr
exact
(s.eq_circumcenter_of_dist_eq
(centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i =>
hr i (Set.mem_univ _)).symm
/-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/
@[simp]
theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) :
(s.reindex e).circumsphere = s.circumsphere := by
refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e]
· exact (s.reindex e).circumsphere_unique_dist_eq.1.1
· exact (s.reindex e).circumsphere_unique_dist_eq.1.2
/-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/
@[simp]
theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) :
(s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex]
/-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/
@[simp]
theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) :
(s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex]
attribute [local instance] AffineSubspace.toAddTorsor
theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P}
(h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r)
(h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter)
(h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) :
dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by
rw [dist_comm, ← h₁ 0,
s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h]
simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius]
/-- If there exists a distance that a point has from all vertices of a
simplex, the orthogonal projection of that point onto the subspace
spanned by that simplex is its circumcenter. -/
theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P}
(hr : ∃ r, ∀ i, dist (s.points i) p = r) :
↑(s.orthogonalProjectionSpan p) = s.circumcenter := by
change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr
have hr : ∃ (r : ℝ), ∀ (a : P),
a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by
obtain ⟨r, hr⟩ := hr
use r
refine Set.forall_mem_range.mpr ?_
exact hr
rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr
obtain ⟨r, hr⟩ := hr
exact
s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i)
/-- If a point has the same distance from all vertices of a simplex,
the orthogonal projection of that point onto the subspace spanned by
that simplex is its circumcenter. -/
theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ}
(hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter :=
s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩
/-- The orthogonal projection of the circumcenter onto a face is the
circumcenter of that face. -/
theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))}
{m : ℕ} (h : #fs = m + 1) :
↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter :=
haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by
use s.circumradius
simp [face_points]
orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr
/-- Two simplices with the same points have the same circumcenter. -/
theorem circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n}
(h : Set.range s₁.points = Set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := by
have hs : s₁.circumcenter ∈ affineSpan ℝ (Set.range s₂.points) :=
h ▸ s₁.circumcenter_mem_affineSpan
have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius := by
intro i
have hi : s₂.points i ∈ Set.range s₂.points := Set.mem_range_self _
rw [← h, Set.mem_range] at hi
rcases hi with ⟨j, hj⟩
rw [← hj, s₁.dist_circumcenter_eq_circumradius j]
exact s₂.eq_circumcenter_of_dist_eq hs hr
/-- An index type for the vertices of a simplex plus its circumcenter.
This is for use in calculations where it is convenient to work with
affine combinations of vertices together with the circumcenter. (An
equivalent form sometimes used in the literature is placing the
circumcenter at the origin and working with vectors for the vertices.) -/
inductive PointsWithCircumcenterIndex (n : ℕ)
| pointIndex : Fin (n + 1) → PointsWithCircumcenterIndex n
| circumcenterIndex : PointsWithCircumcenterIndex n
deriving Fintype
open PointsWithCircumcenterIndex
instance pointsWithCircumcenterIndexInhabited (n : ℕ) : Inhabited (PointsWithCircumcenterIndex n) :=
⟨circumcenterIndex⟩
/-- `pointIndex` as an embedding. -/
def pointIndexEmbedding (n : ℕ) : Fin (n + 1) ↪ PointsWithCircumcenterIndex n :=
⟨fun i => pointIndex i, fun _ _ h => by injection h⟩
/-- The sum of a function over `PointsWithCircumcenterIndex`. -/
theorem sum_pointsWithCircumcenter {α : Type*} [AddCommMonoid α] {n : ℕ}
(f : PointsWithCircumcenterIndex n → α) :
∑ i, f i = (∑ i : Fin (n + 1), f (pointIndex i)) + f circumcenterIndex := by
classical
| have h : univ = insert circumcenterIndex (univ.map (pointIndexEmbedding n)) := by
ext x
refine ⟨fun h => ?_, fun _ => mem_univ _⟩
obtain i | - := x
· exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i))
· exact mem_insert_self _ _
change _ = (∑ i, f (pointIndexEmbedding n i)) + _
rw [add_comm, h, ← sum_map, sum_insert]
simp_rw [Finset.mem_map, not_exists]
rintro x ⟨_, h⟩
injection h
| Mathlib/Geometry/Euclidean/Circumcenter.lean | 435 | 445 |
/-
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]
| Mathlib/Analysis/Calculus/LineDeriv/Basic.lean | 160 | 163 |
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.GroupTheory.MonoidLocalization.Away
import Mathlib.Algebra.Algebra.Pi
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.Localization.Basic
import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicity
/-!
# Localizations away from an element
## Main definitions
* `IsLocalization.Away (x : R) S` expresses that `S` is a localization away from `x`, as an
abbreviation of `IsLocalization (Submonoid.powers x) S`.
* `exists_reduced_fraction' (hb : b ≠ 0)` produces a reduced fraction of the form `b = a * x^n` for
some `n : ℤ` and some `a : R` that is not divisible by `x`.
## Implementation notes
See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
section CommSemiring
variable {R : Type*} [CommSemiring R] (M : Submonoid R) {S : Type*} [CommSemiring S]
variable [Algebra R S] {P : Type*} [CommSemiring P]
namespace IsLocalization
section Away
variable (x : R)
/-- Given `x : R`, the typeclass `IsLocalization.Away x S` states that `S` is
isomorphic to the localization of `R` at the submonoid generated by `x`.
See `IsLocalization.Away.mk` for a specialized constructor. -/
abbrev Away (S : Type*) [CommSemiring S] [Algebra R S] :=
IsLocalization (Submonoid.powers x) S
namespace Away
variable [IsLocalization.Away x S]
/-- Given `x : R` and a localization map `F : R →+* S` away from `x`, `invSelf` is `(F x)⁻¹`. -/
noncomputable def invSelf : S :=
mk' S (1 : R) ⟨x, Submonoid.mem_powers _⟩
@[simp]
theorem mul_invSelf : algebraMap R S x * invSelf x = 1 := by
convert IsLocalization.mk'_mul_mk'_eq_one (M := Submonoid.powers x) (S := S) _ 1
symm
apply IsLocalization.mk'_one
/-- For `s : S` with `S` being the localization of `R` away from `x`,
this is a choice of `(r, n) : R × ℕ` such that `s * algebraMap R S (x ^ n) = algebraMap R S r`. -/
noncomputable def sec (s : S) : R × ℕ :=
⟨(IsLocalization.sec (Submonoid.powers x) s).1,
(IsLocalization.sec (Submonoid.powers x) s).2.property.choose⟩
lemma sec_spec (s : S) : s * (algebraMap R S) (x ^ (IsLocalization.Away.sec x s).2) =
algebraMap R S (IsLocalization.Away.sec x s).1 := by
simp only [IsLocalization.Away.sec, ← IsLocalization.sec_spec]
congr
exact (IsLocalization.sec (Submonoid.powers x) s).2.property.choose_spec
lemma algebraMap_pow_isUnit (n : ℕ) : IsUnit (algebraMap R S x ^ n) :=
IsUnit.pow _ <| IsLocalization.map_units _ (⟨x, 1, by simp⟩ : Submonoid.powers x)
lemma algebraMap_isUnit : IsUnit (algebraMap R S x) :=
IsLocalization.map_units _ (⟨x, 1, by simp⟩ : Submonoid.powers x)
lemma algebraMap_isUnit_iff {y : R} : IsUnit (algebraMap R S y) ↔ ∃ n, y ∣ x ^ n :=
(IsLocalization.algebraMap_isUnit_iff <| .powers x).trans <| by simp [Submonoid.mem_powers_iff]
lemma surj (z : S) : ∃ (n : ℕ) (a : R), z * algebraMap R S x ^ n = algebraMap R S a := by
obtain ⟨⟨a, ⟨-, n, rfl⟩⟩, h⟩ := IsLocalization.surj (Submonoid.powers x) z
use n, a
simpa using h
lemma exists_of_eq {a b : R} (h : algebraMap R S a = algebraMap R S b) :
∃ (n : ℕ), x ^ n * a = x ^ n * b := by
obtain ⟨⟨-, n, rfl⟩, hx⟩ := IsLocalization.exists_of_eq (M := Submonoid.powers x) h
use n
/-- Specialized constructor for `IsLocalization.Away`. -/
lemma mk (r : R) (map_unit : IsUnit (algebraMap R S r))
(surj : ∀ s, ∃ (n : ℕ) (a : R), s * algebraMap R S r ^ n = algebraMap R S a)
(exists_of_eq : ∀ a b, algebraMap R S a = algebraMap R S b → ∃ (n : ℕ), r ^ n * a = r ^ n * b) :
IsLocalization.Away r S where
map_units' := by
rintro ⟨-, n, rfl⟩
simp only [map_pow]
exact IsUnit.pow _ map_unit
surj' z := by
obtain ⟨n, a, hn⟩ := surj z
use ⟨a, ⟨r ^ n, n, rfl⟩⟩
simpa using hn
exists_of_eq {x y} h := by
obtain ⟨n, hn⟩ := exists_of_eq x y h
use ⟨r ^ n, n, rfl⟩
lemma of_associated {r r' : R} (h : Associated r r') [IsLocalization.Away r S] :
IsLocalization.Away r' S := by
obtain ⟨u, rfl⟩ := h
refine mk _ ?_ (fun s ↦ ?_) (fun a b hab ↦ ?_)
· simp [algebraMap_isUnit r, IsUnit.map _ u.isUnit]
· obtain ⟨n, a, hn⟩ := surj r s
use n, a * u ^ n
simp [mul_pow, ← mul_assoc, hn]
· obtain ⟨n, hn⟩ := exists_of_eq r hab
use n
rw [mul_pow, mul_comm (r ^ n), mul_assoc, mul_assoc, hn]
/-- If `r` and `r'` are associated elements of `R`, an `R`-algebra `S`
is the localization of `R` away from `r` if and only of it is the localization of `R` away from
`r'`. -/
lemma iff_of_associated {r r' : R} (h : Associated r r') :
IsLocalization.Away r S ↔ IsLocalization.Away r' S :=
⟨fun _ ↦ IsLocalization.Away.of_associated h, fun _ ↦ IsLocalization.Away.of_associated h.symm⟩
lemma isUnit_of_dvd {r : R} (h : r ∣ x) : IsUnit (algebraMap R S r) :=
isUnit_of_dvd_unit (map_dvd _ h) (algebraMap_isUnit x)
variable {g : R →+* P}
/-- Given `x : R`, a localization map `F : R →+* S` away from `x`, and a map of `CommSemiring`s
`g : R →+* P` such that `g x` is invertible, the homomorphism induced from `S` to `P` sending
`z : S` to `g y * (g x)⁻ⁿ`, where `y : R, n : ℕ` are such that `z = F y * (F x)⁻ⁿ`. -/
noncomputable def lift (hg : IsUnit (g x)) : S →+* P :=
IsLocalization.lift fun y : Submonoid.powers x =>
show IsUnit (g y.1) by
obtain ⟨n, hn⟩ := y.2
rw [← hn, g.map_pow]
exact IsUnit.map (powMonoidHom n : P →* P) hg
@[simp]
theorem lift_eq (hg : IsUnit (g x)) (a : R) : lift x hg (algebraMap R S a) = g a :=
IsLocalization.lift_eq _ _
@[simp]
theorem lift_comp (hg : IsUnit (g x)) : (lift x hg).comp (algebraMap R S) = g :=
IsLocalization.lift_comp _
@[deprecated (since := "2024-11-25")] alias AwayMap.lift_eq := lift_eq
@[deprecated (since := "2024-11-25")] alias AwayMap.lift_comp := lift_comp
/-- Given `x y : R` and localizations `S`, `P` away from `x` and `y * x`
respectively, the homomorphism induced from `S` to `P`. -/
noncomputable def awayToAwayLeft (y : R) [Algebra R P] [IsLocalization.Away (y * x) P] : S →+* P :=
lift x <| isUnit_of_dvd (y * x) (dvd_mul_left _ _)
/-- Given `x y : R` and localizations `S`, `P` away from `x` and `x * y`
respectively, the homomorphism induced from `S` to `P`. -/
noncomputable def awayToAwayRight (y : R) [Algebra R P] [IsLocalization.Away (x * y) P] : S →+* P :=
lift x <| isUnit_of_dvd (x * y) (dvd_mul_right _ _)
theorem awayToAwayLeft_eq (y : R) [Algebra R P] [IsLocalization.Away (y * x) P] (a : R) :
awayToAwayLeft x y (algebraMap R S a) = algebraMap R P a :=
lift_eq _ _ _
theorem awayToAwayRight_eq (y : R) [Algebra R P] [IsLocalization.Away (x * y) P] (a : R) :
awayToAwayRight x y (algebraMap R S a) = algebraMap R P a :=
lift_eq _ _ _
variable (S) (Q : Type*) [CommSemiring Q] [Algebra P Q]
/-- Given a map `f : R →+* S` and an element `r : R`, we may construct a map `Rᵣ →+* Sᵣ`. -/
noncomputable def map (f : R →+* P) (r : R) [IsLocalization.Away r S]
[IsLocalization.Away (f r) Q] : S →+* Q :=
IsLocalization.map Q f
(show Submonoid.powers r ≤ (Submonoid.powers (f r)).comap f by
rintro x ⟨n, rfl⟩
use n
simp)
section Algebra
variable {A : Type*} [CommSemiring A] [Algebra R A]
variable {B : Type*} [CommSemiring B] [Algebra R B]
variable (Aₚ : Type*) [CommSemiring Aₚ] [Algebra A Aₚ] [Algebra R Aₚ] [IsScalarTower R A Aₚ]
variable (Bₚ : Type*) [CommSemiring Bₚ] [Algebra B Bₚ] [Algebra R Bₚ] [IsScalarTower R B Bₚ]
instance {f : A →+* B} (a : A) [Away (f a) Bₚ] : IsLocalization (.map f (.powers a)) Bₚ := by
simpa
/-- Given a algebra map `f : A →ₐ[R] B` and an element `a : A`, we may construct a map
`Aₐ →ₐ[R] Bₐ`. -/
noncomputable def mapₐ (f : A →ₐ[R] B) (a : A) [Away a Aₚ] [Away (f a) Bₚ] : Aₚ →ₐ[R] Bₚ :=
⟨map Aₚ Bₚ f.toRingHom a, fun r ↦ by
dsimp only [AlgHom.toRingHom_eq_coe, map, RingHom.coe_coe, OneHom.toFun_eq_coe]
rw [IsScalarTower.algebraMap_apply R A Aₚ, IsScalarTower.algebraMap_eq R B Bₚ]
simp⟩
@[simp]
lemma mapₐ_apply (f : A →ₐ[R] B) (a : A) [Away a Aₚ] [Away (f a) Bₚ] (x : Aₚ) :
mapₐ Aₚ Bₚ f a x = map Aₚ Bₚ f.toRingHom a x :=
rfl
variable {Aₚ} {Bₚ}
lemma mapₐ_injective_of_injective {f : A →ₐ[R] B} (a : A) [Away a Aₚ] [Away (f a) Bₚ]
(hf : Function.Injective f) : Function.Injective (mapₐ Aₚ Bₚ f a) :=
IsLocalization.map_injective_of_injective _ _ _ hf
lemma mapₐ_surjective_of_surjective {f : A →ₐ[R] B} (a : A) [Away a Aₚ] [Away (f a) Bₚ]
(hf : Function.Surjective f) : Function.Surjective (mapₐ Aₚ Bₚ f a) :=
have : IsLocalization (Submonoid.map f.toRingHom (Submonoid.powers a)) Bₚ := by
simp only [AlgHom.toRingHom_eq_coe, Submonoid.map_powers, RingHom.coe_coe]
infer_instance
IsLocalization.map_surjective_of_surjective _ _ _ hf
end Algebra
/-- Localizing the localization of `R` at `x` at the image of `y` is the same as localizing
`R` at `y * x`. See `IsLocalization.Away.mul'` for the `x * y` version. -/
lemma mul (T : Type*) [CommSemiring T] [Algebra S T]
[Algebra R T] [IsScalarTower R S T] (x y : R)
[IsLocalization.Away x S] [IsLocalization.Away (algebraMap R S y) T] :
IsLocalization.Away (y * x) T := by
refine mk _ ?_ (fun z ↦ ?_) (fun a b h ↦ ?_)
· simp only [map_mul, IsUnit.mul_iff, IsScalarTower.algebraMap_apply R S T]
exact ⟨algebraMap_isUnit _, IsUnit.map _ (algebraMap_isUnit x)⟩
· obtain ⟨m, p, hpq⟩ := surj (algebraMap R S y) z
obtain ⟨n, a, hab⟩ := surj x p
use m + n, a * x ^ m * y ^ n
simp only [mul_pow, pow_add, map_pow, map_mul, ← mul_assoc, hpq,
IsScalarTower.algebraMap_apply R S T, ← hab]
ring
· repeat rw [IsScalarTower.algebraMap_apply R S T] at h
obtain ⟨n, hn⟩ := exists_of_eq (algebraMap R S y) h
simp only [← map_pow, ← map_mul, ← map_mul] at hn
obtain ⟨m, hm⟩ := exists_of_eq x hn
use n + m
convert_to y ^ m * x ^ n * (x ^ m * (y ^ n * a)) = y ^ m * x ^ n * (x ^ m * (y ^ n * b))
· ring
· ring
· rw [hm]
/-- Localizing the localization of `R` at `x` at the image of `y` is the same as localizing
`R` at `x * y`. See `IsLocalization.Away.mul` for the `y * x` version. -/
lemma mul' (T : Type*) [CommSemiring T] [Algebra S T] [Algebra R T] [IsScalarTower R S T] (x y : R)
[IsLocalization.Away x S] [IsLocalization.Away (algebraMap R S y) T] :
IsLocalization.Away (x * y) T :=
mul_comm x y ▸ mul S T x y
/-- Localizing the localization of `R` at `x` at the image of `y` is the same as localizing
`R` at `y * x`. -/
instance (x y : R) [IsLocalization.Away x S] :
IsLocalization.Away (y * x) (Localization.Away (algebraMap R S y)) :=
IsLocalization.Away.mul S (Localization.Away (algebraMap R S y)) _ _
/-- Localizing the localization of `R` at `x` at the image of `y` is the same as localizing
`R` at `x * y`. -/
instance (x y : R) [IsLocalization.Away x S] :
IsLocalization.Away (x * y) (Localization.Away (algebraMap R S y)) :=
IsLocalization.Away.mul' S (Localization.Away (algebraMap R S y)) _ _
/-- If `S₁` is the localization of `R` away from `f` and `S₂` is the localization away from `g`,
then any localization `T` of `S₂` away from `f` is also a localization of `S₁` away from `g`. -/
lemma commutes {R : Type*} [CommSemiring R] (S₁ S₂ T : Type*) [CommSemiring S₁]
[CommSemiring S₂] [CommSemiring T] [Algebra R S₁] [Algebra R S₂] [Algebra R T] [Algebra S₁ T]
[Algebra S₂ T] [IsScalarTower R S₁ T] [IsScalarTower R S₂ T] (x y : R)
[IsLocalization.Away x S₁] [IsLocalization.Away y S₂]
[IsLocalization.Away (algebraMap R S₂ x) T] :
IsLocalization.Away (algebraMap R S₁ y) T := by
haveI : IsLocalization (Algebra.algebraMapSubmonoid S₂ (Submonoid.powers x)) T := by
simp only [Algebra.algebraMapSubmonoid, Submonoid.map_powers]
infer_instance
convert IsLocalization.commutes S₁ S₂ T (Submonoid.powers x) (Submonoid.powers y)
ext x
simp [Algebra.algebraMapSubmonoid]
| end Away
end Away
variable [IsLocalization M S]
section AtUnits
variable (R) (S)
/-- The localization away from a unit is isomorphic to the ring. -/
noncomputable def atUnit (x : R) (e : IsUnit x) [IsLocalization.Away x S] : R ≃ₐ[R] S :=
atUnits R (Submonoid.powers x)
| Mathlib/RingTheory/Localization/Away/Basic.lean | 282 | 294 |
/-
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.MeasureTheory.Integral.IntegralEqImproper
/-!
# Integrals against peak functions
A sequence of peak functions is a sequence of functions with average one concentrating around
a point `x₀`. Given such a sequence `φₙ`, then `∫ φₙ g` tends to `g x₀` in many situations, with
a whole zoo of possible assumptions on `φₙ` and `g`. This file is devoted to such results. Such
functions are also called approximations of unity, or approximations of identity.
## Main results
* `tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto`: If a sequence of peak
functions `φᵢ` converges uniformly to zero away from a point `x₀`, and
`g` is integrable and continuous at `x₀`, then `∫ φᵢ • g` converges to `g x₀`.
* `tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn`:
If a continuous function `c` realizes its maximum at a unique point `x₀` in a compact set `s`,
then the sequence of functions `(c x) ^ n / ∫ (c x) ^ n` is a sequence of peak functions
concentrating around `x₀`. Therefore, `∫ (c x) ^ n * g / ∫ (c x) ^ n` converges to `g x₀`
if `g` is continuous on `s`.
* `tendsto_integral_comp_smul_smul_of_integrable`:
If a nonnegative function `φ` has integral one and decays quickly enough at infinity,
then its renormalizations `x ↦ c ^ d * φ (c • x)` form a sequence of peak functions as `c → ∞`.
Therefore, `∫ (c ^ d * φ (c • x)) • g x` converges to `g 0` as `c → ∞` if `g` is continuous
at `0` and integrable.
Note that there are related results about convolution with respect to peak functions in the file
`Mathlib.Analysis.Convolution`, such as `MeasureTheory.convolution_tendsto_right` there.
-/
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace Metric
open scoped Topology ENNReal
/-!
### General convergent result for integrals against a sequence of peak functions
-/
open Set
variable {α E ι : Type*} {hm : MeasurableSpace α} {μ : Measure α} [TopologicalSpace α]
[BorelSpace α] [NormedAddCommGroup E] [NormedSpace ℝ E] {g : α → E} {l : Filter ι} {x₀ : α}
{s t : Set α} {φ : ι → α → ℝ} {a : E}
/-- If a sequence of peak functions `φᵢ` converges uniformly to zero away from a point `x₀`, and
`g` is integrable and has a limit at `x₀`, then `φᵢ • g` is eventually integrable. -/
theorem integrableOn_peak_smul_of_integrableOn_of_tendsto
(hs : MeasurableSet s) (h'st : t ∈ 𝓝[s] x₀)
(hlφ : ∀ u : Set α, IsOpen u → x₀ ∈ u → TendstoUniformlyOn φ 0 l (s \ u))
(hiφ : Tendsto (fun i ↦ ∫ x in t, φ i x ∂μ) l (𝓝 1))
(h'iφ : ∀ᶠ i in l, AEStronglyMeasurable (φ i) (μ.restrict s))
(hmg : IntegrableOn g s μ) (hcg : Tendsto g (𝓝[s] x₀) (𝓝 a)) :
∀ᶠ i in l, IntegrableOn (fun x => φ i x • g x) s μ := by
obtain ⟨u, u_open, x₀u, ut, hu⟩ :
∃ u, IsOpen u ∧ x₀ ∈ u ∧ s ∩ u ⊆ t ∧ ∀ x ∈ u ∩ s, g x ∈ ball a 1 := by
rcases mem_nhdsWithin.1 (Filter.inter_mem h'st (hcg (ball_mem_nhds _ zero_lt_one)))
with ⟨u, u_open, x₀u, hu⟩
refine ⟨u, u_open, x₀u, ?_, hu.trans inter_subset_right⟩
rw [inter_comm]
exact hu.trans inter_subset_left
rw [tendsto_iff_norm_sub_tendsto_zero] at hiφ
filter_upwards [tendstoUniformlyOn_iff.1 (hlφ u u_open x₀u) 1 zero_lt_one,
(tendsto_order.1 hiφ).2 1 zero_lt_one, h'iφ] with i hi h'i h''i
have I : IntegrableOn (φ i) t μ := .of_integral_ne_zero (fun h ↦ by simp [h] at h'i)
have A : IntegrableOn (fun x => φ i x • g x) (s \ u) μ := by
refine Integrable.smul_of_top_right (hmg.mono diff_subset le_rfl) ?_
apply memLp_top_of_bound (h''i.mono_set diff_subset) 1
filter_upwards [self_mem_ae_restrict (hs.diff u_open.measurableSet)] with x hx
simpa only [Pi.zero_apply, dist_zero_left] using (hi x hx).le
have B : IntegrableOn (fun x => φ i x • g x) (s ∩ u) μ := by
apply Integrable.smul_of_top_left
· exact IntegrableOn.mono_set I ut
· apply
memLp_top_of_bound (hmg.mono_set inter_subset_left).aestronglyMeasurable (‖a‖ + 1)
filter_upwards [self_mem_ae_restrict (hs.inter u_open.measurableSet)] with x hx
rw [inter_comm] at hx
exact (norm_lt_of_mem_ball (hu x hx)).le
convert A.union B
simp only [diff_union_inter]
/-- If a sequence of peak functions `φᵢ` converges uniformly to zero away from a point `x₀` and its
integral on some finite-measure neighborhood of `x₀` converges to `1`, and `g` is integrable and
has a limit `a` at `x₀`, then `∫ φᵢ • g` converges to `a`.
Auxiliary lemma where one assumes additionally `a = 0`. -/
theorem tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto_aux
(hs : MeasurableSet s) (ht : MeasurableSet t) (hts : t ⊆ s) (h'ts : t ∈ 𝓝[s] x₀)
(hnφ : ∀ᶠ i in l, ∀ x ∈ s, 0 ≤ φ i x)
(hlφ : ∀ u : Set α, IsOpen u → x₀ ∈ u → TendstoUniformlyOn φ 0 l (s \ u))
(hiφ : Tendsto (fun i ↦ ∫ x in t, φ i x ∂μ) l (𝓝 1))
(h'iφ : ∀ᶠ i in l, AEStronglyMeasurable (φ i) (μ.restrict s))
(hmg : IntegrableOn g s μ) (hcg : Tendsto g (𝓝[s] x₀) (𝓝 0)) :
Tendsto (fun i : ι => ∫ x in s, φ i x • g x ∂μ) l (𝓝 0) := by
refine Metric.tendsto_nhds.2 fun ε εpos => ?_
obtain ⟨δ, hδ, δpos, δone⟩ : ∃ δ, (δ * ∫ x in s, ‖g x‖ ∂μ) + 2 * δ < ε ∧ 0 < δ ∧ δ < 1 := by
have A :
Tendsto (fun δ => (δ * ∫ x in s, ‖g x‖ ∂μ) + 2 * δ) (𝓝[>] 0)
(𝓝 ((0 * ∫ x in s, ‖g x‖ ∂μ) + 2 * 0)) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact (tendsto_id.mul tendsto_const_nhds).add (tendsto_id.const_mul _)
rw [zero_mul, zero_add, mul_zero] at A
have : Ioo (0 : ℝ) 1 ∈ 𝓝[>] 0 := Ioo_mem_nhdsGT zero_lt_one
rcases (((tendsto_order.1 A).2 ε εpos).and this).exists with ⟨δ, hδ, h'δ⟩
exact ⟨δ, hδ, h'δ.1, h'δ.2⟩
suffices ∀ᶠ i in l, ‖∫ x in s, φ i x • g x ∂μ‖ ≤ (δ * ∫ x in s, ‖g x‖ ∂μ) + 2 * δ by
filter_upwards [this] with i hi
simp only [dist_zero_right]
exact hi.trans_lt hδ
obtain ⟨u, u_open, x₀u, ut, hu⟩ :
∃ u, IsOpen u ∧ x₀ ∈ u ∧ s ∩ u ⊆ t ∧ ∀ x ∈ u ∩ s, g x ∈ ball 0 δ := by
rcases mem_nhdsWithin.1 (Filter.inter_mem h'ts (hcg (ball_mem_nhds _ δpos)))
with ⟨u, u_open, x₀u, hu⟩
refine ⟨u, u_open, x₀u, ?_, hu.trans inter_subset_right⟩
rw [inter_comm]
exact hu.trans inter_subset_left
filter_upwards [tendstoUniformlyOn_iff.1 (hlφ u u_open x₀u) δ δpos,
(tendsto_order.1 (tendsto_iff_norm_sub_tendsto_zero.1 hiφ)).2 δ δpos, hnφ,
integrableOn_peak_smul_of_integrableOn_of_tendsto hs h'ts hlφ hiφ h'iφ hmg hcg]
with i hi h'i hφpos h''i
have I : IntegrableOn (φ i) t μ := by
apply Integrable.of_integral_ne_zero (fun h ↦ ?_)
simp [h] at h'i
linarith
have B : ‖∫ x in s ∩ u, φ i x • g x ∂μ‖ ≤ 2 * δ :=
calc
‖∫ x in s ∩ u, φ i x • g x ∂μ‖ ≤ ∫ x in s ∩ u, ‖φ i x • g x‖ ∂μ :=
norm_integral_le_integral_norm _
_ ≤ ∫ x in s ∩ u, ‖φ i x‖ * δ ∂μ := by
refine setIntegral_mono_on ?_ ?_ (hs.inter u_open.measurableSet) fun x hx => ?_
· exact IntegrableOn.mono_set h''i.norm inter_subset_left
· exact IntegrableOn.mono_set (I.norm.mul_const _) ut
rw [norm_smul]
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _)
rw [inter_comm] at hu
exact (mem_ball_zero_iff.1 (hu x hx)).le
_ ≤ ∫ x in t, ‖φ i x‖ * δ ∂μ := by
apply setIntegral_mono_set
· exact I.norm.mul_const _
· exact Eventually.of_forall fun x => mul_nonneg (norm_nonneg _) δpos.le
· exact Eventually.of_forall ut
_ = ∫ x in t, φ i x * δ ∂μ := by
apply setIntegral_congr_fun ht fun x hx => ?_
rw [Real.norm_of_nonneg (hφpos _ (hts hx))]
_ = (∫ x in t, φ i x ∂μ) * δ := by rw [integral_mul_const]
_ ≤ 2 * δ := by gcongr; linarith [(le_abs_self _).trans h'i.le]
have C : ‖∫ x in s \ u, φ i x • g x ∂μ‖ ≤ δ * ∫ x in s, ‖g x‖ ∂μ :=
calc
‖∫ x in s \ u, φ i x • g x ∂μ‖ ≤ ∫ x in s \ u, ‖φ i x • g x‖ ∂μ :=
norm_integral_le_integral_norm _
_ ≤ ∫ x in s \ u, δ * ‖g x‖ ∂μ := by
refine setIntegral_mono_on ?_ ?_ (hs.diff u_open.measurableSet) fun x hx => ?_
· exact IntegrableOn.mono_set h''i.norm diff_subset
· exact IntegrableOn.mono_set (hmg.norm.const_mul _) diff_subset
rw [norm_smul]
apply mul_le_mul_of_nonneg_right _ (norm_nonneg _)
simpa only [Pi.zero_apply, dist_zero_left] using (hi x hx).le
_ ≤ δ * ∫ x in s, ‖g x‖ ∂μ := by
rw [integral_const_mul]
apply mul_le_mul_of_nonneg_left (setIntegral_mono_set hmg.norm _ _) δpos.le
· filter_upwards with x using norm_nonneg _
· filter_upwards using diff_subset (s := s) (t := u)
calc
‖∫ x in s, φ i x • g x ∂μ‖ =
‖(∫ x in s \ u, φ i x • g x ∂μ) + ∫ x in s ∩ u, φ i x • g x ∂μ‖ := by
conv_lhs => rw [← diff_union_inter s u]
rw [setIntegral_union disjoint_sdiff_inter (hs.inter u_open.measurableSet)
(h''i.mono_set diff_subset) (h''i.mono_set inter_subset_left)]
_ ≤ ‖∫ x in s \ u, φ i x • g x ∂μ‖ + ‖∫ x in s ∩ u, φ i x • g x ∂μ‖ := norm_add_le _ _
_ ≤ (δ * ∫ x in s, ‖g x‖ ∂μ) + 2 * δ := add_le_add C B
variable [CompleteSpace E]
/-- If a sequence of peak functions `φᵢ` converges uniformly to zero away from a point `x₀` and its
integral on some finite-measure neighborhood of `x₀` converges to `1`, and `g` is integrable and
has a limit `a` at `x₀`, then `∫ φᵢ • g` converges to `a`. Version localized to a subset. -/
theorem tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto
(hs : MeasurableSet s) {t : Set α} (ht : MeasurableSet t) (hts : t ⊆ s) (h'ts : t ∈ 𝓝[s] x₀)
(h't : μ t ≠ ∞) (hnφ : ∀ᶠ i in l, ∀ x ∈ s, 0 ≤ φ i x)
(hlφ : ∀ u : Set α, IsOpen u → x₀ ∈ u → TendstoUniformlyOn φ 0 l (s \ u))
(hiφ : Tendsto (fun i ↦ ∫ x in t, φ i x ∂μ) l (𝓝 1))
(h'iφ : ∀ᶠ i in l, AEStronglyMeasurable (φ i) (μ.restrict s))
(hmg : IntegrableOn g s μ) (hcg : Tendsto g (𝓝[s] x₀) (𝓝 a)) :
Tendsto (fun i : ι ↦ ∫ x in s, φ i x • g x ∂μ) l (𝓝 a) := by
let h := g - t.indicator (fun _ ↦ a)
have A : Tendsto (fun i : ι => (∫ x in s, φ i x • h x ∂μ) + (∫ x in t, φ i x ∂μ) • a) l
(𝓝 (0 + (1 : ℝ) • a)) := by
refine Tendsto.add ?_ (Tendsto.smul hiφ tendsto_const_nhds)
| apply tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto_aux hs ht hts h'ts
hnφ hlφ hiφ h'iφ
· apply hmg.sub
simp only [integrable_indicator_iff ht, integrableOn_const, ht, Measure.restrict_apply]
right
exact lt_of_le_of_lt (measure_mono inter_subset_left) (h't.lt_top)
· rw [← sub_self a]
apply Tendsto.sub hcg
apply tendsto_const_nhds.congr'
filter_upwards [h'ts] with x hx using by simp [hx]
simp only [one_smul, zero_add] at A
refine Tendsto.congr' ?_ A
filter_upwards [integrableOn_peak_smul_of_integrableOn_of_tendsto hs h'ts
hlφ hiφ h'iφ hmg hcg,
(tendsto_order.1 (tendsto_iff_norm_sub_tendsto_zero.1 hiφ)).2 1 zero_lt_one] with i hi h'i
simp only [h, Pi.sub_apply, smul_sub, ← indicator_smul_apply]
rw [integral_sub hi, setIntegral_indicator ht, inter_eq_right.mpr hts,
integral_smul_const, sub_add_cancel]
rw [integrable_indicator_iff ht]
apply Integrable.smul_const
rw [restrict_restrict ht, inter_eq_left.mpr hts]
exact .of_integral_ne_zero (fun h ↦ by simp [h] at h'i)
/-- If a sequence of peak functions `φᵢ` converges uniformly to zero away from a point `x₀` and its
integral on some finite-measure neighborhood of `x₀` converges to `1`, and `g` is integrable and
has a limit `a` at `x₀`, then `∫ φᵢ • g` converges to `a`. -/
theorem tendsto_integral_peak_smul_of_integrable_of_tendsto
{t : Set α} (ht : MeasurableSet t) (h'ts : t ∈ 𝓝 x₀)
(h't : μ t ≠ ∞) (hnφ : ∀ᶠ i in l, ∀ x, 0 ≤ φ i x)
(hlφ : ∀ u : Set α, IsOpen u → x₀ ∈ u → TendstoUniformlyOn φ 0 l uᶜ)
(hiφ : Tendsto (fun i ↦ ∫ x in t, φ i x ∂μ) l (𝓝 1))
(h'iφ : ∀ᶠ i in l, AEStronglyMeasurable (φ i) μ)
(hmg : Integrable g μ) (hcg : Tendsto g (𝓝 x₀) (𝓝 a)) :
Tendsto (fun i : ι ↦ ∫ x, φ i x • g x ∂μ) l (𝓝 a) := by
| Mathlib/MeasureTheory/Integral/PeakFunction.lean | 192 | 225 |
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn
-/
import Mathlib.Tactic.CategoryTheory.Reassoc
/-!
# Isomorphisms
This file defines isomorphisms between objects of a category.
## Main definitions
- `structure Iso` : a bundled isomorphism between two objects of a category;
- `class IsIso` : an unbundled version of `iso`;
note that `IsIso f` is a `Prop`, and only asserts the existence of an inverse.
Of course, this inverse is unique, so it doesn't cost us much to use choice to retrieve it.
- `inv f`, for the inverse of a morphism with `[IsIso f]`
- `asIso` : convert from `IsIso` to `Iso` (noncomputable);
- `of_iso` : convert from `Iso` to `IsIso`;
- standard operations on isomorphisms (composition, inverse etc)
## Notations
- `X ≅ Y` : same as `Iso X Y`;
- `α ≪≫ β` : composition of two isomorphisms; it is called `Iso.trans`
## Tags
category, category theory, isomorphism
-/
universe v u
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
open Category
/-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category.
The inverse morphism is bundled.
See also `CategoryTheory.Core` for the category with the same objects and isomorphisms playing
the role of morphisms. -/
@[stacks 0017]
structure Iso {C : Type u} [Category.{v} C] (X Y : C) where
/-- The forward direction of an isomorphism. -/
hom : X ⟶ Y
/-- The backwards direction of an isomorphism. -/
inv : Y ⟶ X
/-- Composition of the two directions of an isomorphism is the identity on the source. -/
hom_inv_id : hom ≫ inv = 𝟙 X := by aesop_cat
/-- Composition of the two directions of an isomorphism in reverse order
is the identity on the target. -/
inv_hom_id : inv ≫ hom = 𝟙 Y := by aesop_cat
attribute [reassoc (attr := simp)] Iso.hom_inv_id Iso.inv_hom_id
/-- Notation for an isomorphism in a category. -/
infixr:10 " ≅ " => Iso -- type as \cong or \iso
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace Iso
@[ext]
theorem ext ⦃α β : X ≅ Y⦄ (w : α.hom = β.hom) : α = β :=
suffices α.inv = β.inv by
cases α
cases β
cases w
cases this
rfl
calc
α.inv = α.inv ≫ β.hom ≫ β.inv := by rw [Iso.hom_inv_id, Category.comp_id]
_ = (α.inv ≫ α.hom) ≫ β.inv := by rw [Category.assoc, ← w]
_ = β.inv := by rw [Iso.inv_hom_id, Category.id_comp]
/-- Inverse isomorphism. -/
@[symm]
def symm (I : X ≅ Y) : Y ≅ X where
hom := I.inv
inv := I.hom
@[simp]
theorem symm_hom (α : X ≅ Y) : α.symm.hom = α.inv :=
rfl
@[simp]
theorem symm_inv (α : X ≅ Y) : α.symm.inv = α.hom :=
rfl
@[simp]
theorem symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) :
Iso.symm { hom, inv, hom_inv_id := hom_inv_id, inv_hom_id := inv_hom_id } =
{ hom := inv, inv := hom, hom_inv_id := inv_hom_id, inv_hom_id := hom_inv_id } :=
rfl
@[simp]
theorem symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α := rfl
theorem symm_bijective {X Y : C} : Function.Bijective (symm : (X ≅ Y) → _) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm_eq, symm_symm_eq⟩
@[simp]
theorem symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β :=
symm_bijective.injective.eq_iff
theorem nonempty_iso_symm (X Y : C) : Nonempty (X ≅ Y) ↔ Nonempty (Y ≅ X) :=
⟨fun h => ⟨h.some.symm⟩, fun h => ⟨h.some.symm⟩⟩
/-- Identity isomorphism. -/
@[refl, simps]
def refl (X : C) : X ≅ X where
hom := 𝟙 X
inv := 𝟙 X
instance : Inhabited (X ≅ X) := ⟨Iso.refl X⟩
theorem nonempty_iso_refl (X : C) : Nonempty (X ≅ X) := ⟨default⟩
@[simp]
theorem refl_symm (X : C) : (Iso.refl X).symm = Iso.refl X := rfl
/-- Composition of two isomorphisms -/
@[simps]
def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z where
hom := α.hom ≫ β.hom
inv := β.inv ≫ α.inv
@[simps]
instance instTransIso : Trans (α := C) (· ≅ ·) (· ≅ ·) (· ≅ ·) where
trans := trans
/-- Notation for composition of isomorphisms. -/
infixr:80 " ≪≫ " => Iso.trans -- type as `\ll \gg`.
@[simp]
theorem trans_mk {X Y Z : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id)
(hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') :
Iso.trans ⟨hom, inv, hom_inv_id, inv_hom_id⟩ ⟨hom', inv', hom_inv_id', inv_hom_id'⟩ =
⟨hom ≫ hom', inv' ≫ inv, hom_inv_id'', inv_hom_id''⟩ :=
rfl
@[simp]
theorem trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm :=
rfl
@[simp]
theorem trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') :
(α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ := by
ext; simp only [trans_hom, Category.assoc]
@[simp]
theorem refl_trans (α : X ≅ Y) : Iso.refl X ≪≫ α = α := by ext; apply Category.id_comp
@[simp]
theorem trans_refl (α : X ≅ Y) : α ≪≫ Iso.refl Y = α := by ext; apply Category.comp_id
@[simp]
theorem symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = Iso.refl Y :=
ext α.inv_hom_id
@[simp]
theorem self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = Iso.refl X :=
ext α.hom_inv_id
@[simp]
theorem symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β := by
rw [← trans_assoc, symm_self_id, refl_trans]
@[simp]
theorem self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β := by
rw [← trans_assoc, self_symm_id, refl_trans]
theorem inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g :=
⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
theorem eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f :=
(inv_comp_eq α.symm).symm
theorem comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom :=
⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
theorem eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f :=
(comp_inv_eq α.symm).symm
theorem inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom :=
have : ∀ {X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv := fun f g h => by rw [ext h]
⟨this f.symm g.symm, this f g⟩
theorem hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv := by
rw [← eq_inv_comp, comp_id]
theorem comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv := by
rw [← eq_comp_inv, id_comp]
theorem inv_comp_eq_id (α : X ≅ Y) {f : X ⟶ Y} : α.inv ≫ f = 𝟙 Y ↔ f = α.hom :=
hom_comp_eq_id α.symm
theorem comp_inv_eq_id (α : X ≅ Y) {f : X ⟶ Y} : f ≫ α.inv = 𝟙 X ↔ f = α.hom :=
comp_hom_eq_id α.symm
theorem hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv := by
rw [← symm_inv, inv_eq_inv α.symm β, eq_comm]
rfl
/-- The bijection `(Z ⟶ X) ≃ (Z ⟶ Y)` induced by `α : X ≅ Y`. -/
@[simps]
def homToEquiv (α : X ≅ Y) {Z : C} : (Z ⟶ X) ≃ (Z ⟶ Y) where
toFun f := f ≫ α.hom
invFun g := g ≫ α.inv
left_inv := by aesop_cat
right_inv := by aesop_cat
/-- The bijection `(X ⟶ Z) ≃ (Y ⟶ Z)` induced by `α : X ≅ Y`. -/
@[simps]
def homFromEquiv (α : X ≅ Y) {Z : C} : (X ⟶ Z) ≃ (Y ⟶ Z) where
toFun f := α.inv ≫ f
invFun g := α.hom ≫ g
left_inv := by aesop_cat
right_inv := by aesop_cat
end Iso
/-- `IsIso` typeclass expressing that a morphism is invertible. -/
class IsIso (f : X ⟶ Y) : Prop where
/-- The existence of an inverse morphism. -/
out : ∃ inv : Y ⟶ X, f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y
/-- The inverse of a morphism `f` when we have `[IsIso f]`.
-/
noncomputable def inv (f : X ⟶ Y) [I : IsIso f] : Y ⟶ X :=
Classical.choose I.1
namespace IsIso
@[simp]
theorem hom_inv_id (f : X ⟶ Y) [I : IsIso f] : f ≫ inv f = 𝟙 X :=
(Classical.choose_spec I.1).left
@[simp]
theorem inv_hom_id (f : X ⟶ Y) [I : IsIso f] : inv f ≫ f = 𝟙 Y :=
(Classical.choose_spec I.1).right
-- FIXME putting @[reassoc] on the `hom_inv_id` above somehow unfolds `inv`
-- This happens even if we make `inv` irreducible!
-- I don't understand how this is happening: it is likely a bug.
-- attribute [reassoc] hom_inv_id inv_hom_id
-- #print hom_inv_id_assoc
-- theorem CategoryTheory.IsIso.hom_inv_id_assoc {X Y : C} (f : X ⟶ Y) [I : IsIso f]
-- {Z : C} (h : X ⟶ Z),
-- f ≫ Classical.choose (_ : Exists fun inv ↦ f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y) ≫ h = h := ...
@[simp]
theorem hom_inv_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : X ⟶ Z) : f ≫ inv f ≫ g = g := by
simp [← Category.assoc]
@[simp]
theorem inv_hom_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : Y ⟶ Z) : inv f ≫ f ≫ g = g := by
simp [← Category.assoc]
end IsIso
lemma Iso.isIso_hom (e : X ≅ Y) : IsIso e.hom :=
⟨e.inv, by simp, by simp⟩
lemma Iso.isIso_inv (e : X ≅ Y) : IsIso e.inv := e.symm.isIso_hom
attribute [instance] Iso.isIso_hom Iso.isIso_inv
open IsIso
/-- Reinterpret a morphism `f` with an `IsIso f` instance as an `Iso`. -/
noncomputable def asIso (f : X ⟶ Y) [IsIso f] : X ≅ Y :=
⟨f, inv f, hom_inv_id f, inv_hom_id f⟩
-- Porting note: the `IsIso f` argument had been instance implicit,
-- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor`
-- was failing to generate it by typeclass search.
@[simp]
theorem asIso_hom (f : X ⟶ Y) {_ : IsIso f} : (asIso f).hom = f :=
rfl
-- Porting note: the `IsIso f` argument had been instance implicit,
-- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor`
-- was failing to generate it by typeclass search.
@[simp]
theorem asIso_inv (f : X ⟶ Y) {_ : IsIso f} : (asIso f).inv = inv f :=
rfl
namespace IsIso
-- see Note [lower instance priority]
instance (priority := 100) epi_of_iso (f : X ⟶ Y) [IsIso f] : Epi f where
left_cancellation g h w := by
rw [← IsIso.inv_hom_id_assoc f g, w, IsIso.inv_hom_id_assoc f h]
-- see Note [lower instance priority]
instance (priority := 100) mono_of_iso (f : X ⟶ Y) [IsIso f] : Mono f where
right_cancellation g h w := by
rw [← Category.comp_id g, ← Category.comp_id h, ← IsIso.hom_inv_id f,
← Category.assoc, w, ← Category.assoc]
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem inv_eq_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) :
inv f = g := by
apply (cancel_epi f).mp
simp [hom_inv_id]
theorem inv_eq_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) :
inv f = g := by
apply (cancel_mono f).mp
simp [inv_hom_id]
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem eq_inv_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) :
g = inv f :=
(inv_eq_of_hom_inv_id hom_inv_id).symm
theorem eq_inv_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) :
g = inv f :=
(inv_eq_of_inv_hom_id inv_hom_id).symm
instance id (X : C) : IsIso (𝟙 X) := ⟨⟨𝟙 X, by simp⟩⟩
variable {f : X ⟶ Y} {h : Y ⟶ Z}
instance inv_isIso [IsIso f] : IsIso (inv f) :=
(asIso f).isIso_inv
/- The following instance has lower priority for the following reason:
Suppose we are given `f : X ≅ Y` with `X Y : Type u`.
Without the lower priority, typeclass inference cannot deduce `IsIso f.hom`
because `f.hom` is defeq to `(fun x ↦ x) ≫ f.hom`, triggering a loop. -/
instance (priority := 900) comp_isIso [IsIso f] [IsIso h] : IsIso (f ≫ h) :=
(asIso f ≪≫ asIso h).isIso_hom
/--
The composition of isomorphisms is an isomorphism. Here the arguments of type `IsIso` are
explicit, to make this easier to use with the `refine` tactic, for instance.
-/
lemma comp_isIso' (_ : IsIso f) (_ : IsIso h) : IsIso (f ≫ h) := inferInstance
@[simp]
theorem inv_id : inv (𝟙 X) = 𝟙 X := by
apply inv_eq_of_hom_inv_id
simp
@[simp, reassoc]
theorem inv_comp [IsIso f] [IsIso h] : inv (f ≫ h) = inv h ≫ inv f := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem inv_inv [IsIso f] : inv (inv f) = f := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem Iso.inv_inv (f : X ≅ Y) : inv f.inv = f.hom := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem Iso.inv_hom (f : X ≅ Y) : inv f.hom = f.inv := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem inv_comp_eq (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = α ≫ g :=
(asIso α).inv_comp_eq
@[simp]
theorem eq_inv_comp (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ α ≫ g = f :=
(asIso α).eq_inv_comp
@[simp]
theorem comp_inv_eq (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ α :=
(asIso α).comp_inv_eq
@[simp]
theorem eq_comp_inv (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ α = f :=
(asIso α).eq_comp_inv
theorem of_isIso_comp_left {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [IsIso (f ≫ g)] :
IsIso g := by
rw [← id_comp g, ← inv_hom_id f, assoc]
infer_instance
theorem of_isIso_comp_right {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] [IsIso (f ≫ g)] :
IsIso f := by
rw [← comp_id f, ← hom_inv_id g, ← assoc]
infer_instance
theorem of_isIso_fac_left {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [IsIso f]
[hh : IsIso h] (w : f ≫ g = h) : IsIso g := by
rw [← w] at hh
haveI := hh
exact of_isIso_comp_left f g
theorem of_isIso_fac_right {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [IsIso g]
[hh : IsIso h] (w : f ≫ g = h) : IsIso f := by
rw [← w] at hh
haveI := hh
exact of_isIso_comp_right f g
end IsIso
open IsIso
theorem eq_of_inv_eq_inv {f g : X ⟶ Y} [IsIso f] [IsIso g] (p : inv f = inv g) : f = g := by
apply (cancel_epi (inv f)).1
rw [inv_hom_id, p, inv_hom_id]
theorem IsIso.inv_eq_inv {f g : X ⟶ Y} [IsIso f] [IsIso g] : inv f = inv g ↔ f = g :=
Iso.inv_eq_inv (asIso f) (asIso g)
theorem hom_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} : g ≫ f = 𝟙 X ↔ f = inv g :=
(asIso g).hom_comp_eq_id
theorem comp_hom_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} : f ≫ g = 𝟙 Y ↔ f = inv g :=
(asIso g).comp_hom_eq_id
theorem inv_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : X ⟶ Y} : inv g ≫ f = 𝟙 Y ↔ f = g :=
(asIso g).inv_comp_eq_id
theorem comp_inv_eq_id (g : X ⟶ Y) [IsIso g] {f : X ⟶ Y} : f ≫ inv g = 𝟙 X ↔ f = g :=
(asIso g).comp_inv_eq_id
theorem isIso_of_hom_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} (h : g ≫ f = 𝟙 X) : IsIso f := by
rw [(hom_comp_eq_id _).mp h]
infer_instance
theorem isIso_of_comp_hom_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} (h : f ≫ g = 𝟙 Y) : IsIso f := by
rw [(comp_hom_eq_id _).mp h]
infer_instance
namespace Iso
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem inv_ext {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : f.inv = g :=
((hom_comp_eq_id f).1 hom_inv_id).symm
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem inv_ext' {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : g = f.inv :=
(hom_comp_eq_id f).1 hom_inv_id
/-!
All these cancellation lemmas can be solved by `simp [cancel_mono]` (or `simp [cancel_epi]`),
but with the current design `cancel_mono` is not a good `simp` lemma,
because it generates a typeclass search.
When we can see syntactically that a morphism is a `mono` or an `epi`
because it came from an isomorphism, it's fine to do the cancellation via `simp`.
In the longer term, it might be worth exploring making `mono` and `epi` structures,
rather than typeclasses, with coercions back to `X ⟶ Y`.
Presumably we could write `X ↪ Y` and `X ↠ Y`.
-/
@[simp]
theorem cancel_iso_hom_left {X Y Z : C} (f : X ≅ Y) (g g' : Y ⟶ Z) :
f.hom ≫ g = f.hom ≫ g' ↔ g = g' := by
simp only [cancel_epi]
@[simp]
theorem cancel_iso_inv_left {X Y Z : C} (f : Y ≅ X) (g g' : Y ⟶ Z) :
f.inv ≫ g = f.inv ≫ g' ↔ g = g' := by
simp only [cancel_epi]
@[simp]
theorem cancel_iso_hom_right {X Y Z : C} (f f' : X ⟶ Y) (g : Y ≅ Z) :
f ≫ g.hom = f' ≫ g.hom ↔ f = f' := by
simp only [cancel_mono]
@[simp]
theorem cancel_iso_inv_right {X Y Z : C} (f f' : X ⟶ Y) (g : Z ≅ Y) :
f ≫ g.inv = f' ≫ g.inv ↔ f = f' := by
simp only [cancel_mono]
/-
Unfortunately cancelling an isomorphism from the right of a chain of compositions is awkward.
We would need separate lemmas for each chain length (worse: for each pair of chain lengths).
We provide two more lemmas, for case of three morphisms, because this actually comes up in practice,
but then stop.
-/
@[simp]
theorem cancel_iso_hom_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X')
(g' : X' ⟶ Y) (h : Y ≅ Z) : f ≫ g ≫ h.hom = f' ≫ g' ≫ h.hom ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono]
@[simp]
theorem cancel_iso_inv_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X')
(g' : X' ⟶ Y) (h : Z ≅ Y) : f ≫ g ≫ h.inv = f' ≫ g' ≫ h.inv ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono]
section
variable {D : Type*} [Category D] {X Y : C} (e : X ≅ Y)
@[reassoc (attr := simp)]
lemma map_hom_inv_id (F : C ⥤ D) :
F.map e.hom ≫ F.map e.inv = 𝟙 _ := by
rw [← F.map_comp, e.hom_inv_id, F.map_id]
@[reassoc (attr := simp)]
lemma map_inv_hom_id (F : C ⥤ D) :
F.map e.inv ≫ F.map e.hom = 𝟙 _ := by
rw [← F.map_comp, e.inv_hom_id, F.map_id]
end
end Iso
namespace Functor
universe u₁ v₁ u₂ v₂
variable {D : Type u₂}
variable [Category.{v₂} D]
/-- A functor `F : C ⥤ D` sends isomorphisms `i : X ≅ Y` to isomorphisms `F.obj X ≅ F.obj Y` -/
@[simps]
def mapIso (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.obj X ≅ F.obj Y where
hom := F.map i.hom
inv := F.map i.inv
@[simp]
theorem mapIso_symm (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.mapIso i.symm = (F.mapIso i).symm :=
rfl
@[simp]
theorem mapIso_trans (F : C ⥤ D) {X Y Z : C} (i : X ≅ Y) (j : Y ≅ Z) :
F.mapIso (i ≪≫ j) = F.mapIso i ≪≫ F.mapIso j := by
ext; apply Functor.map_comp
@[simp]
theorem mapIso_refl (F : C ⥤ D) (X : C) : F.mapIso (Iso.refl X) = Iso.refl (F.obj X) :=
Iso.ext <| F.map_id X
instance map_isIso (F : C ⥤ D) (f : X ⟶ Y) [IsIso f] : IsIso (F.map f) :=
(F.mapIso (asIso f)).isIso_hom
@[simp]
theorem map_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [IsIso f] : F.map (inv f) = inv (F.map f) := by
apply eq_inv_of_hom_inv_id
simp [← F.map_comp]
@[reassoc]
theorem map_hom_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [IsIso f] :
F.map f ≫ F.map (inv f) = 𝟙 (F.obj X) := by simp
@[reassoc]
theorem map_inv_hom (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [IsIso f] :
F.map (inv f) ≫ F.map f = 𝟙 (F.obj Y) := by simp
end Functor
end CategoryTheory
| Mathlib/CategoryTheory/Iso.lean | 591 | 593 | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Johan Commelin, Patrick Massot
-/
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.Tactic.TFAE
/-!
# The basics of valuation theory.
The basic theory of valuations (non-archimedean norms) on a commutative ring,
following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]).
The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic].
A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered
commutative monoid with zero, that in addition satisfies the following two axioms:
* `v 0 = 0`
* `∀ x y, v (x + y) ≤ max (v x) (v y)`
`Valuation R Γ₀` is the type of valuations `R → Γ₀`, with a coercion to the underlying
function. If `v` is a valuation from `R` to `Γ₀` then the induced group
homomorphism `Units(R) → Γ₀` is called `unit_map v`.
The equivalence "relation" `IsEquiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly
speaking a relation, because `v₁ : Valuation R Γ₁` and `v₂ : Valuation R Γ₂` might
not have the same type. This corresponds in ZFC to the set-theoretic difficulty
that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set.
The "relation" is however reflexive, symmetric and transitive in the obvious
sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence.
## Main definitions
* `Valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀`
* `Valuation.IsNontrivial` is the class of non-trivial valuations, namely those for which there
is an element in the ring whose valuation is `≠ 0` and `≠ 1`.
* `Valuation.IsEquiv`, the heterogeneous equivalence relation on valuations
* `Valuation.supp`, the support of a valuation
* `AddValuation R Γ₀`, the type of additive valuations on `R` with values in a
linearly ordered additive commutative group with a top element, `Γ₀`.
## Implementation Details
`AddValuation R Γ₀` is implemented as `Valuation R (Multiplicative Γ₀)ᵒᵈ`.
## Notation
In the `DiscreteValuation` locale:
* `ℕₘ₀` is a shorthand for `WithZero (Multiplicative ℕ)`
* `ℤₘ₀` is a shorthand for `WithZero (Multiplicative ℤ)`
## TODO
If ever someone extends `Valuation`, we should fully comply to the `DFunLike` by migrating the
boilerplate lemmas to `ValuationClass`.
-/
open Function Ideal
noncomputable section
variable {K F R : Type*} [DivisionRing K]
section
variable (F R) (Γ₀ : Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R]
/-- The type of `Γ₀`-valued valuations on `R`.
When you extend this structure, make sure to extend `ValuationClass`. -/
structure Valuation extends R →*₀ Γ₀ where
/-- The valuation of a sum is less than or equal to the maximum of the valuations. -/
map_add_le_max' : ∀ x y, toFun (x + y) ≤ max (toFun x) (toFun y)
/-- `ValuationClass F α β` states that `F` is a type of valuations.
You should also extend this typeclass when you extend `Valuation`. -/
class ValuationClass (F) (R Γ₀ : outParam Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R]
[FunLike F R Γ₀] : Prop
extends MonoidWithZeroHomClass F R Γ₀ where
/-- The valuation of a sum is less than or equal to the maximum of the valuations. -/
map_add_le_max (f : F) (x y : R) : f (x + y) ≤ max (f x) (f y)
export ValuationClass (map_add_le_max)
instance [FunLike F R Γ₀] [ValuationClass F R Γ₀] : CoeTC F (Valuation R Γ₀) :=
⟨fun f =>
{ toFun := f
map_one' := map_one f
map_zero' := map_zero f
map_mul' := map_mul f
map_add_le_max' := map_add_le_max f }⟩
end
namespace Valuation
variable {Γ₀ : Type*}
variable {Γ'₀ : Type*}
variable {Γ''₀ : Type*} [LinearOrderedCommMonoidWithZero Γ''₀]
section Basic
variable [Ring R]
section Monoid
variable [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀]
instance : FunLike (Valuation R Γ₀) R Γ₀ where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨⟨_,_⟩, _⟩, _⟩ := f
congr
instance : ValuationClass (Valuation R Γ₀) R Γ₀ where
map_mul f := f.map_mul'
map_one f := f.map_one'
map_zero f := f.map_zero'
map_add_le_max f := f.map_add_le_max'
@[simp]
theorem coe_mk (f : R →*₀ Γ₀) (h) : ⇑(Valuation.mk f h) = f := rfl
theorem toFun_eq_coe (v : Valuation R Γ₀) : v.toFun = v := rfl
@[simp]
theorem toMonoidWithZeroHom_coe_eq_coe (v : Valuation R Γ₀) :
(v.toMonoidWithZeroHom : R → Γ₀) = v := rfl
@[ext]
theorem ext {v₁ v₂ : Valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ :=
DFunLike.ext _ _ h
variable (v : Valuation R Γ₀)
@[simp, norm_cast]
theorem coe_coe : ⇑(v : R →*₀ Γ₀) = v := rfl
protected theorem map_zero : v 0 = 0 :=
v.map_zero'
protected theorem map_one : v 1 = 1 :=
v.map_one'
protected theorem map_mul : ∀ x y, v (x * y) = v x * v y :=
v.map_mul'
-- Porting note: LHS side simplified so created map_add'
protected theorem map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) :=
v.map_add_le_max'
@[simp]
theorem map_add' : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y := by
intro x y
rw [← le_max_iff, ← ge_iff_le]
apply v.map_add
theorem map_add_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x + y) ≤ g :=
le_trans (v.map_add x y) <| max_le hx hy
theorem map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g :=
lt_of_le_of_lt (v.map_add x y) <| max_lt hx hy
theorem map_sum_le {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, v (f i) ≤ g) :
v (∑ i ∈ s, f i) ≤ g := by
classical
refine
Finset.induction_on s (fun _ => v.map_zero ▸ zero_le')
(fun a s has ih hf => ?_) hf
rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has]
exact v.map_add_le hf.1 (ih hf.2)
theorem map_sum_lt {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ 0)
(hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := by
classical
refine
Finset.induction_on s (fun _ => v.map_zero ▸ (zero_lt_iff.2 hg))
(fun a s has ih hf => ?_) hf
rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has]
exact v.map_add_lt hf.1 (ih hf.2)
theorem map_sum_lt' {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : 0 < g)
(hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g :=
v.map_sum_lt (ne_of_gt hg) hf
protected theorem map_pow : ∀ (x) (n : ℕ), v (x ^ n) = v x ^ n :=
v.toMonoidWithZeroHom.toMonoidHom.map_pow
-- The following definition is not an instance, because we have more than one `v` on a given `R`.
-- In addition, type class inference would not be able to infer `v`.
/-- A valuation gives a preorder on the underlying ring. -/
def toPreorder : Preorder R :=
Preorder.lift v
/-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/
theorem zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 :=
map_eq_zero v
theorem ne_zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 :=
map_ne_zero v
lemma pos_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : 0 < v x ↔ x ≠ 0 := by
rw [zero_lt_iff, ne_zero_iff]
theorem unit_map_eq (u : Rˣ) : (Units.map (v : R →* Γ₀) u : Γ₀) = v u :=
rfl
theorem ne_zero_of_unit [Nontrivial Γ₀] (v : Valuation K Γ₀) (x : Kˣ) : v x ≠ (0 : Γ₀) := by
simp only [ne_eq, Valuation.zero_iff, Units.ne_zero x, not_false_iff]
theorem ne_zero_of_isUnit [Nontrivial Γ₀] (v : Valuation K Γ₀) (x : K) (hx : IsUnit x) :
v x ≠ (0 : Γ₀) := by
simpa [hx.choose_spec] using ne_zero_of_unit v hx.choose
/-- A ring homomorphism `S → R` induces a map `Valuation R Γ₀ → Valuation S Γ₀`. -/
def comap {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) : Valuation S Γ₀ :=
{ v.toMonoidWithZeroHom.comp f.toMonoidWithZeroHom with
toFun := v ∘ f
map_add_le_max' := fun x y => by simp only [comp_apply, v.map_add, map_add] }
@[simp]
theorem comap_apply {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) (s : S) :
v.comap f s = v (f s) := rfl
@[simp]
theorem comap_id : v.comap (RingHom.id R) = v :=
ext fun _r => rfl
theorem comap_comp {S₁ : Type*} {S₂ : Type*} [Ring S₁] [Ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) :
v.comap (g.comp f) = (v.comap g).comap f :=
ext fun _r => rfl
/-- A `≤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `Valuation R Γ₀ → Valuation R Γ'₀`.
-/
def map (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (v : Valuation R Γ₀) : Valuation R Γ'₀ :=
{ MonoidWithZeroHom.comp f v.toMonoidWithZeroHom with
toFun := f ∘ v
map_add_le_max' := fun r s =>
calc
f (v (r + s)) ≤ f (max (v r) (v s)) := hf (v.map_add r s)
_ = max (f (v r)) (f (v s)) := hf.map_max
}
@[simp]
lemma map_apply (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (v : Valuation R Γ₀) (r : R) :
v.map f hf r = f (v r) := rfl
/-- Two valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/
def IsEquiv (v₁ : Valuation R Γ₀) (v₂ : Valuation R Γ'₀) : Prop :=
∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s
@[simp]
theorem map_neg (x : R) : v (-x) = v x :=
v.toMonoidWithZeroHom.toMonoidHom.map_neg x
theorem map_sub_swap (x y : R) : v (x - y) = v (y - x) :=
v.toMonoidWithZeroHom.toMonoidHom.map_sub_swap x y
theorem map_sub (x y : R) : v (x - y) ≤ max (v x) (v y) :=
calc
v (x - y) = v (x + -y) := by rw [sub_eq_add_neg]
_ ≤ max (v x) (v <| -y) := v.map_add _ _
_ = max (v x) (v y) := by rw [map_neg]
theorem map_sub_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x - y) ≤ g := by
rw [sub_eq_add_neg]
exact v.map_add_le hx <| (v.map_neg y).trans_le hy
theorem map_sub_lt {x y : R} {g : Γ₀} (hx : v x < g) (hy : v y < g) : v (x - y) < g := by
rw [sub_eq_add_neg]
exact v.map_add_lt hx <| (v.map_neg y).trans_lt hy
variable {x y : R}
theorem map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := by
suffices ¬v (x + y) < max (v x) (v y) from
or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this
intro h'
wlog vyx : v y < v x generalizing x y
· refine this h.symm ?_ (h.lt_or_lt.resolve_right vyx)
rwa [add_comm, max_comm]
rw [max_eq_left_of_lt vyx] at h'
apply lt_irrefl (v x)
calc
v x = v (x + y - y) := by simp
_ ≤ max (v <| x + y) (v y) := map_sub _ _ _
_ < v x := max_lt h' vyx
theorem map_add_eq_of_lt_right (h : v x < v y) : v (x + y) = v y :=
(v.map_add_of_distinct_val h.ne).trans (max_eq_right_iff.mpr h.le)
theorem map_add_eq_of_lt_left (h : v y < v x) : v (x + y) = v x := by
rw [add_comm]; exact map_add_eq_of_lt_right _ h
theorem map_sub_eq_of_lt_right (h : v x < v y) : v (x - y) = v y := by
rw [sub_eq_add_neg, map_add_eq_of_lt_right, map_neg]
rwa [map_neg]
open scoped Classical in
theorem map_sum_eq_of_lt {ι : Type*} {s : Finset ι} {f : ι → R} {j : ι}
(hj : j ∈ s) (h0 : v (f j) ≠ 0) (hf : ∀ i ∈ s \ {j}, v (f i) < v (f j)) :
v (∑ i ∈ s, f i) = v (f j) := by
rw [Finset.sum_eq_add_sum_diff_singleton hj]
exact map_add_eq_of_lt_left _ (map_sum_lt _ h0 hf)
theorem map_sub_eq_of_lt_left (h : v y < v x) : v (x - y) = v x := by
rw [sub_eq_add_neg, map_add_eq_of_lt_left]
rwa [map_neg]
theorem map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x := by
have := Valuation.map_add_of_distinct_val v (ne_of_gt h).symm
rw [max_eq_right (le_of_lt h)] at this
simpa using this
theorem map_one_add_of_lt (h : v x < 1) : v (1 + x) = 1 := by
rw [← v.map_one] at h
simpa only [v.map_one] using v.map_add_eq_of_lt_left h
theorem map_one_sub_of_lt (h : v x < 1) : v (1 - x) = 1 := by
rw [← v.map_one, ← v.map_neg] at h
rw [sub_eq_add_neg 1 x]
simpa only [v.map_one, v.map_neg] using v.map_add_eq_of_lt_left h
/-- An ordered monoid isomorphism `Γ₀ ≃ Γ'₀` induces an equivalence
`Valuation R Γ₀ ≃ Valuation R Γ'₀`. -/
def congr (f : Γ₀ ≃*o Γ'₀) : Valuation R Γ₀ ≃ Valuation R Γ'₀ where
toFun := map f f.toOrderIso.monotone
invFun := map f.symm f.toOrderIso.symm.monotone
left_inv ν := by ext; simp
right_inv ν := by ext; simp
end Monoid
section Group
| variable [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation R Γ₀) {x y : R}
theorem map_inv {R : Type*} [DivisionRing R] (v : Valuation R Γ₀) : ∀ x, v x⁻¹ = (v x)⁻¹ :=
map_inv₀ _
| Mathlib/RingTheory/Valuation/Basic.lean | 342 | 345 |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Analytic.Within
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries
/-!
# Higher differentiability
A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous.
By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or,
equivalently, if it is `C^1` and its derivative is `C^{n-1}`.
It is `C^∞` if it is `C^n` for all n.
Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the
space is complete).
We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and
`ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set
and on the whole space respectively.
To avoid the issue of choice when choosing a derivative in sets where the derivative is not
necessarily unique, `ContDiffOn` is not defined directly in terms of the
regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the
existence of a nice sequence of derivatives, expressed with a predicate
`HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`.
We prove basic properties of these notions.
## Main definitions and results
Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`.
* `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to
rank `n`.
* `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`.
* `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`.
* `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`.
In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the
properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space,
`ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f`
for `m ≤ n`.
## Implementation notes
The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more
complicated than the naive definitions one would guess from the intuition over the real or complex
numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity
in general. In the usual situations, they coincide with the usual definitions.
### Definition of `C^n` functions in domains
One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this
is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are
continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n`
functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a
function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`.
This definition still has the problem that a function which is locally `C^n` would not need to
be `C^n`, as different choices of sequences of derivatives around different points might possibly
not be glued together to give a globally defined sequence of derivatives. (Note that this issue
can not happen over reals, thanks to partition of unity, but the behavior over a general field is
not so clear, and we want a definition for general fields). Also, there are locality
problems for the order parameter: one could image a function which, for each `n`, has a nice
sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore
not be glued to give rise to an infinite sequence of derivatives. This would give a function
which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions
in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`.
The resulting definition is slightly more complicated to work with (in fact not so much), but it
gives rise to completely satisfactory theorems.
For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)`
for each natural `m` is by definition `C^∞` at `0`.
There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can
require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x`
within `s`. However, this does not imply continuity or differentiability within `s` of the function
at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on
a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file).
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To
avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`.
These notations are scoped in `ContDiff`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open Set Fin Filter Function
open scoped NNReal Topology ContDiff
universe u uE uF uG uX
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG}
[NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X]
{s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞}
{p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Smooth functions within a set around a point -/
variable (𝕜) in
/-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if
it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we
give (all the derivatives should be analytic) is more involved to work around issues when the space
is not complete, but it is equivalent when the space is complete.
For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not
better, is `C^∞` at `0` within `univ`.
-/
def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop :=
match n with
| ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F,
HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u
| (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u
lemma HasFTaylorSeriesUpToOn.analyticOn
(hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) :
AnalyticOn 𝕜 f s := by
have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s :=
(LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn
h (Set.mapsTo_univ _ _)
exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm)
lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) :
∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by
obtain ⟨u, hu, p, hp, h'p⟩ := h
exact ⟨u, hu, hp.analyticOn (h'p 0)⟩
lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) :
AnalyticWithinAt 𝕜 f s x := by
obtain ⟨u, hu, hf⟩ := h.analyticOn
have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu
exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] :
ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by
refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩
obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω
exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩
theorem contDiffWithinAt_nat {n : ℕ} :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u :=
⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩
/-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n`
as the existence of a neighborhood on which there is a Taylor series up to order `n`,
requiring in addition that its terms are analytic in the `ω` case. -/
lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x,
∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧
(n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by
match n with
| ω => simp [ContDiffWithinAt]
| ∞ => simp at hn
| (n : ℕ) => simp [contDiffWithinAt_nat]
theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) :
ContDiffWithinAt 𝕜 m f s x := by
match n with
| ω => match m with
| ω => exact h
| (m : ℕ∞) =>
intro k _
obtain ⟨u, hu, p, hp, -⟩ := h
exact ⟨u, hu, p, hp.of_le le_top⟩
| (n : ℕ∞) => match m with
| ω => simp at hmn
| (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn))
/-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there.
Note that the same statement for `AnalyticOn` does not require completeness, see
`AnalyticOn.contDiffOn`. -/
theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) :
ContDiffWithinAt 𝕜 n f s x :=
(contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top
theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} :
ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩
theorem contDiffWithinAt_infty :
ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top]
@[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty
theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) :
ContinuousWithinAt f s x := by
have := h.of_le (zero_le _)
simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero,
mem_pure, forall_eq, CharP.cast_eq_zero] at this
rcases this with ⟨u, hu, p, H⟩
rw [mem_nhdsWithin_insert] at hu
exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2
theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right,
fun i ↦ (H' i).mono (sep_subset _ _)⟩
| (n : ℕ∞) =>
intro m hm
let ⟨u, hu, p, H⟩ := h m hm
exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p,
(H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩
theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁)
(mem_of_mem_nhdsWithin (mem_insert x s) h₁ :)
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩
theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx
theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s):
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩
theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx
theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩
theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y)
(hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr h₁ (h₁ _ hx)
theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr h₁ (h₁ x hx)
theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x)
(h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x :=
h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) :
ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _))
theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by
match n with
| ω =>
obtain ⟨u, hu, p, H, H'⟩ := h
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩
| (n : ℕ∞) =>
intro m hm
rcases h m hm with ⟨u, hu, p, H⟩
exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩
@[deprecated (since := "2024-10-30")]
alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin
theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) :
ContDiffWithinAt 𝕜 n f t x :=
h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst
theorem ContDiffWithinAt.congr_mono
(h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) :
ContDiffWithinAt 𝕜 n f₁ s₁ x :=
(h.mono h₁).congr h' hx
theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E}
(hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by
rw [← nhdsWithin_eq_iff_eventuallyEq] at hst
apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin
@[deprecated (since := "2024-10-23")]
alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set
theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) :
ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x :=
⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩
@[deprecated (since := "2024-10-23")]
alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set
theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm
theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) :
ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x :=
contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h)
theorem contDiffWithinAt_insert_self :
ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
match n with
| ω => simp [ContDiffWithinAt]
| (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem]
theorem contDiffWithinAt_insert {y : E} :
ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rcases eq_or_ne x y with (rfl | hx)
· exact contDiffWithinAt_insert_self
refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩
apply h.mono_of_mem_nhdsWithin
simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin]
alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert
protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n f (insert x s) x :=
h.insert'
theorem contDiffWithinAt_diff_singleton {y : E} :
ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by
rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert]
/-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable
within this set at this point. -/
theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f (insert x s) x := by
rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩
rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩
rw [inter_comm] at tu
exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <|
((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩
theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) :
DifferentiableWithinAt 𝕜 f s x :=
(h.differentiableWithinAt' hn).mono (subset_insert x s)
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`
(and moreover the function is analytic when `n = ω`). -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by
have h'n : n + 1 ≠ ∞ := by simpa using hn
constructor
· intro h
rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩
refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1),
fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩
· rintro rfl
exact Hp.analyticOn (H'p rfl 0)
apply (contDiffWithinAt_iff_of_ne_infty hn).2
refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩
· convert @self_mem_nhdsWithin _ _ x u
have : x ∈ insert x s := by simp
exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu)
· rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp
refine ⟨Hp.2.2, ?_⟩
rintro rfl i
change AnalyticOn 𝕜
(fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u
apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn
?_ (Set.mapsTo_univ _ _)
exact H'p rfl _
· rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩
rw [contDiffWithinAt_iff_of_ne_infty h'n]
rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩
refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩
· apply Filter.inter_mem _ hu
apply nhdsWithin_le_of_mem hu
exact nhdsWithin_mono _ (subset_insert x u) hv
· rw [hasFTaylorSeriesUpToOn_succ_iff_right]
refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩
· change
HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z))
(FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y
rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff']
convert (f'_eq_deriv y hy.2).mono inter_subset_right
rw [← Hp'.zero_eq y hy.1]
ext z
change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) =
((p' y 0) 0) z
congr
norm_num [eq_iff_true_of_subsingleton]
· convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1
· ext x y
change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y
rw [init_snoc]
· ext x k v y
change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y))
(@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y
rw [snoc_last, init_snoc]
· intro h i
simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h
match i with
| 0 =>
simp only [FormalMultilinearSeries.unshift]
apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
| i + 1 =>
simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one]
apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left)
(Set.mapsTo_univ _ _)
exact LinearIsometryEquiv.analyticOnNhd _ _
/-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives
are taken within the same set. -/
theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 (n + 1) f s x ↔
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧
∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by
refine ⟨fun hf => ?_, ?_⟩
· obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf
obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu
rw [inter_comm] at hwu
refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f',
fun y hy => ?_, ?_⟩
· intro h
apply (f_an h).mono hwu
· refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_
refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _))
exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2)
· exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu)
· rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem (mem_insert _ _)]
rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩
exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩
/-! ### Smooth functions within a set -/
variable (𝕜) in
/-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it
admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`.
For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may
depend on the finite order we consider).
-/
def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x
theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F}
(hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by
intro x hx m hm
use s
simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and]
exact ⟨f', hf.of_le (mod_cast hm)⟩
theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 n f s x :=
h x hx
theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx =>
(h x hx).of_le hmn
theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by
rcases eq_or_ne n ω with rfl | hn
· obtain ⟨t, ht, p, hp, h'p⟩ := h
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
refine ⟨u, huo, hxu, ?_⟩
suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top
intro y hy
refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩
simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin]
· match m with
| ω => simp [hn] at hm
| ∞ => exact (hn (h' rfl)).elim
| (m : ℕ) =>
rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩
rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩
rw [inter_comm] at hut
exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩
theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω)
(h : ContDiffWithinAt 𝕜 n f s x) :
∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by
obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h'
exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩
theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s :=
fun x hx ↦ (h x hx).analyticWithinAt
/-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on
a neighborhood of this point. -/
theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) :
ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩
exact ⟨u, hu, h'u.2⟩
· rcases h with ⟨u, u_mem, hu⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem
exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem)
protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) :
∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by
rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩
have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u :=
(eventually_eventually_nhdsWithin.2 hu).and hu
refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_
exact nhdsWithin_mono y (subset_insert _ _) hy.1
theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s :=
h.of_le le_self_add
theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s :=
h.of_le le_add_self
theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} :
ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s :=
⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩
theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s :=
contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true]
@[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty
@[deprecated (since := "2024-11-27")]
alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty
theorem contDiffOn_all_iff_nat :
(∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by
refine ⟨fun H n => H n, ?_⟩
rintro H (_ | n)
exacts [contDiffOn_infty.2 H, H n]
theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx =>
(h x hx).continuousWithinAt
theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) :
ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx)
theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s :=
⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩
theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t :=
fun x hx => (h x (hst hx)).mono hst
theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) :
ContDiffOn 𝕜 n f₁ s₁ :=
(hf.mono hs).congr h₁
/-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/
theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) :
DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn
/-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/
theorem contDiffOn_of_locally_contDiffOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by
intro x xs
rcases h x xs with ⟨u, u_open, xu, hu⟩
apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩)
exact IsOpen.mem_nhds u_open xu
/-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/
theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) :
ContDiffOn 𝕜 (n + 1) f s ↔
∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F,
(∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by
constructor
· intro h x hx
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with
⟨u, hu, f_an, f', hf', Hf'⟩
rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩
rw [insert_eq_of_mem hx] at hu ⊢
have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu
rw [insert_eq_of_mem xu] at vu v'u
exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f',
fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩
· intro h x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn]
rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩
have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd
exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩
/-! ### Iterated derivative within a set -/
@[simp]
theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by
refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩
have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le
rw [this]
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
rw [hasFTaylorSeriesUpToOn_zero_iff]
exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩
theorem contDiffWithinAt_zero (hx : x ∈ s) :
ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by
constructor
· intro h
obtain ⟨u, H, p, hp⟩ := h 0 le_rfl
refine ⟨u, ?_, ?_⟩
· simpa [hx] using H
· simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp
exact hp.1.mono inter_subset_right
· rintro ⟨u, H, hu⟩
rw [← contDiffWithinAt_inter' H]
have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩
exact (contDiffOn_zero.mpr hu).contDiffWithinAt h'
/-- When a function is `C^n` in a set `s` of unique differentiability, it admits
`ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/
protected theorem ContDiffOn.ftaylorSeriesWithin
(h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) :
HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by
constructor
· intro x _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro m hm x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm
rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩
rw [insert_eq_of_mem hx] at hu
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm] at ho
have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by
change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x
rw [← iteratedFDerivWithin_inter_open o_open xo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩
rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)]
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact
(Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m)
(hs.inter o_open) ⟨hy, yo⟩
exact
((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr
(fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm
· intro m hm
apply continuousOn_of_locally_continuousOn
intro x hx
rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [insert_eq_of_mem hx] at ho
rw [inter_comm] at ho
refine ⟨o, o_open, xo, ?_⟩
have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by
rintro y ⟨hy, yo⟩
change p y m = iteratedFDerivWithin 𝕜 m f s y
rw [← iteratedFDerivWithin_inter_open o_open yo]
exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩
exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm
theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s)
(ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) :
iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x :=
(((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm
theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E}
(h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) :
∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by
rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩
have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by
rw [eventually_smallSets_subset]
exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU
refine this.mono fun t ht ↦ .mono ?_ ht
rw [insert_eq_of_mem ha] at hfU
refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_
exact iteratedFDerivWithin_inter_open hUo hx.2
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOn.contDiffOn_of_completeSpace`. -/
theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩
intro x hx
refine ⟨s, ?_, p, hp⟩
rw [insert_eq_of_mem hx]
exact self_mem_nhdsWithin
/-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its
successive derivatives are also analytic. This does not require completeness of the space. See
also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/
theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
fun x hx ↦ (h x hx).contDiffWithinAt
/-- An analytic function is automatically `C^ω` in a complete space -/
theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) :
ContDiffOn 𝕜 n f s :=
h.analyticOn.contDiffOn_of_completeSpace
theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞}
(Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s)
(Hdiff : ∀ m : ℕ, m < n →
DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) :
ContDiffOn 𝕜 n f s := by
intro x hx m hm
rw [insert_eq_of_mem hx]
refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k hk y hy
convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt
· intro k hk
exact Hcont k (le_trans (mod_cast hk) (mod_cast hm))
theorem contDiffOn_of_differentiableOn {n : ℕ∞}
(h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s :=
contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm =>
h m (le_of_lt hm)
theorem contDiffOn_of_analyticOn_iteratedFDerivWithin
(h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) :
ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 ω f s from this.of_le le_top
intro x hx
refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩
· rw [insert_eq_of_mem hx]
constructor
· intro y _
simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply,
iteratedFDerivWithin_zero_apply]
· intro k _ y hy
exact ((h k).differentiableOn y hy).hasFDerivWithinAt
· intro k _
exact (h k).continuousOn
· intro i
rw [insert_eq_of_mem hx]
exact h i
theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s :=
⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩
theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s :=
((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl
theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s)
(hmn : m < n) (hs : UniqueDiffOn 𝕜 s) :
DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by
intro x hx
have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn
apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt
exact_mod_cast lt_add_one m
theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ}
(h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) :
DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by
have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl)
rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this])
with ⟨u, uo, xu, hu⟩
set t := insert x s ∩ u
have A : t =ᶠ[𝓝[≠] x] s := by
simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter']
rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem,
diff_eq_compl_inter]
exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)]
have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t :=
iteratedFDerivWithin_eventually_congr_set' _ A.symm _
have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x :=
hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x
⟨mem_insert _ _, xu⟩
rw [differentiableWithinAt_congr_set' _ A] at C
exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds
theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s :=
⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs,
fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩,
fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩
theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 n f s ↔
(∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by
rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs]
simp
theorem contDiffOn_succ_of_fderivWithin (hf : DifferentiableOn 𝕜 f s)
(h' : n = ω → AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1) f s := by
rcases eq_or_ne n ∞ with rfl | hn
· rw [ENat.coe_top_add_one, contDiffOn_infty]
intro m x hx
apply ContDiffWithinAt.of_le _ (show (m : WithTop ℕ∞) ≤ m + 1 from le_self_add)
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt (by simp),
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, (by simp), fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, (h x hx).of_le (mod_cast le_top)⟩
· intro x hx
rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn,
insert_eq_of_mem hx]
exact ⟨s, self_mem_nhdsWithin, h', fderivWithin 𝕜 f s,
fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩
theorem contDiffOn_of_analyticOn_of_fderivWithin (hf : AnalyticOn 𝕜 f s)
(h : ContDiffOn 𝕜 ω (fun y ↦ fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 n f s := by
suffices ContDiffOn 𝕜 (ω + 1) f s from this.of_le le_top
exact contDiffOn_succ_of_fderivWithin hf.differentiableOn (fun _ ↦ hf) h
/-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is
differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderivWithin 𝕜 f s) s := by
refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2.1 h.2.2⟩
refine ⟨H.differentiableOn le_add_self, ?_, fun x hx => ?_⟩
· rintro rfl
exact H.analyticOn
have A (m : ℕ) (hm : m ≤ n) : ContDiffWithinAt 𝕜 m (fun y => fderivWithin 𝕜 f s y) s x := by
rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt (n := m) (ne_of_beq_false rfl)).1
(H.of_le (add_le_add_right hm 1) x hx) with ⟨u, hu, -, f', hff', hf'⟩
rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩
rw [inter_comm, insert_eq_of_mem hx] at ho
have := hf'.mono ho
rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this
apply this.congr_of_eventuallyEq_of_mem _ hx
have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩
rw [inter_comm] at this
refine Filter.eventuallyEq_of_mem this fun y hy => ?_
have A : fderivWithin 𝕜 f (s ∩ o) y = f' y :=
((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy)
rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A
match n with
| ω => exact (H.analyticOn.fderivWithin hs).contDiffOn hs (n := ω) x hx
| ∞ => exact contDiffWithinAt_infty.2 (fun m ↦ A m (mod_cast le_top))
| (n : ℕ) => exact A n le_rfl
theorem contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 (n + 1) f s ↔ (n = ω → AnalyticOn 𝕜 f s) ∧
∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by
rw [contDiffOn_succ_iff_fderivWithin hs]
refine ⟨fun h => ⟨h.2.1, fderivWithin 𝕜 f s, h.2.2,
fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun ⟨f_an, h⟩ => ?_⟩
rcases h with ⟨f', h1, h2⟩
refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, f_an, fun x hx => ?_⟩
exact (h1 x hx).congr_of_mem (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx
@[deprecated (since := "2024-11-27")]
alias contDiffOn_succ_iff_hasFDerivWithin := contDiffOn_succ_iff_hasFDerivWithinAt_of_uniqueDiffOn
theorem contDiffOn_infty_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderivWithin 𝕜 f s) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderivWithin hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderivWithin := contDiffOn_infty_iff_fderivWithin
/-- A function is `C^(n + 1)` on an open domain if and only if it is
differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/
theorem contDiffOn_succ_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 (n + 1) f s ↔
DifferentiableOn 𝕜 f s ∧ (n = ω → AnalyticOn 𝕜 f s) ∧
ContDiffOn 𝕜 n (fderiv 𝕜 f) s := by
rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn,
contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx]
theorem contDiffOn_infty_iff_fderiv_of_isOpen (hs : IsOpen s) :
ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fderiv 𝕜 f) s := by
rw [← ENat.coe_top_add_one, contDiffOn_succ_iff_fderiv_of_isOpen hs]
simp
@[deprecated (since := "2024-11-27")]
alias contDiffOn_top_iff_fderiv_of_isOpen := contDiffOn_infty_iff_fderiv_of_isOpen
protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2.2
theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (fderiv 𝕜 f) s :=
(hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm
|
theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s)
(hn : 1 ≤ n) : ContinuousOn (fderivWithin 𝕜 f s) s :=
((contDiffOn_succ_iff_fderivWithin hs).1
(h.of_le (show 0 + (1 : WithTop ℕ∞) ≤ n from hn))).2.2.continuousOn
| Mathlib/Analysis/Calculus/ContDiff/Defs.lean | 901 | 905 |
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.GradedObject.Associator
import Mathlib.CategoryTheory.GradedObject.Single
/-!
# The left and right unitors
Given a bifunctor `F : C ⥤ D ⥤ D`, an object `X : C` such that `F.obj X ≅ 𝟭 D` and a
map `p : I × J → J` such that `hp : ∀ (j : J), p ⟨0, j⟩ = j`,
we define an isomorphism of `J`-graded objects for any `Y : GradedObject J D`.
`mapBifunctorLeftUnitor F X e p hp Y : mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y`.
Under similar assumptions, we also obtain a right unitor isomorphism
`mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X`. Finally,
the lemma `mapBifunctor_triangle` promotes a triangle identity involving functors
to a triangle identity for the induced functors on graded objects.
-/
namespace CategoryTheory
open Category Limits
namespace GradedObject
section LeftUnitor
variable {C D I J : Type*} [Category C] [Category D]
[Zero I] [DecidableEq I] [HasInitial C]
(F : C ⥤ D ⥤ D) (X : C) (e : F.obj X ≅ 𝟭 D)
[∀ (Y : D), PreservesColimit (Functor.empty.{0} C) (F.flip.obj Y)]
(p : I × J → J) (hp : ∀ (j : J), p ⟨0, j⟩ = j)
(Y Y' : GradedObject J D) (φ : Y ⟶ Y')
/-- Given `F : C ⥤ D ⥤ D`, `X : C`, `e : F.obj X ≅ 𝟭 D` and `Y : GradedObject J D`,
this is the isomorphism `((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a ≅ Y a.2`
when `a : I × J` is such that `a.1 = 0`. -/
@[simps!]
noncomputable def mapBifunctorObjSingle₀ObjIso (a : I × J) (ha : a.1 = 0) :
((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a ≅ Y a.2 :=
(F.mapIso (singleObjApplyIsoOfEq _ X _ ha)).app _ ≪≫ e.app (Y a.2)
/-- Given `F : C ⥤ D ⥤ D`, `X : C` and `Y : GradedObject J D`,
`((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a` is an initial object
when `a : I × J` is such that `a.1 ≠ 0`. -/
noncomputable def mapBifunctorObjSingle₀ObjIsInitial (a : I × J) (ha : a.1 ≠ 0) :
IsInitial (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y a) :=
IsInitial.isInitialObj (F.flip.obj (Y a.2)) _ (isInitialSingleObjApply _ _ _ ha)
/-- Given `F : C ⥤ D ⥤ D`, `X : C`, `e : F.obj X ≅ 𝟭 D`, `Y : GradedObject J D` and
`p : I × J → J` such that `p ⟨0, j⟩ = j` for all `j`,
this is the (colimit) cofan which shall be used to construct the isomorphism
`mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y`, see `mapBifunctorLeftUnitor`. -/
noncomputable def mapBifunctorLeftUnitorCofan (hp : ∀ (j : J), p ⟨0, j⟩ = j) (Y) (j : J) :
(((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y).CofanMapObjFun p j :=
CofanMapObjFun.mk _ _ _ (Y j) (fun a ha =>
if ha : a.1 = 0 then
(mapBifunctorObjSingle₀ObjIso F X e Y a ha).hom ≫ eqToHom (by aesop)
else
(mapBifunctorObjSingle₀ObjIsInitial F X Y a ha).to _)
@[simp, reassoc]
lemma mapBifunctorLeftUnitorCofan_inj (j : J) :
(mapBifunctorLeftUnitorCofan F X e p hp Y j).inj ⟨⟨0, j⟩, hp j⟩ =
(F.map (singleObjApplyIso (0 : I) X).hom).app (Y j) ≫ e.hom.app (Y j) := by
simp [mapBifunctorLeftUnitorCofan]
/-- The cofan `mapBifunctorLeftUnitorCofan F X e p hp Y j` is a colimit. -/
noncomputable def mapBifunctorLeftUnitorCofanIsColimit (j : J) :
IsColimit (mapBifunctorLeftUnitorCofan F X e p hp Y j) :=
mkCofanColimit _
(fun s => e.inv.app (Y j) ≫
(F.map (singleObjApplyIso (0 : I) X).inv).app (Y j) ≫ s.inj ⟨⟨0, j⟩, hp j⟩)
(fun s => by
rintro ⟨⟨i, j'⟩, h⟩
by_cases hi : i = 0
· subst hi
simp only [Set.mem_preimage, hp, Set.mem_singleton_iff] at h
subst h
simp
· apply IsInitial.hom_ext
exact mapBifunctorObjSingle₀ObjIsInitial _ _ _ _ hi)
(fun s m hm => by simp [← hm ⟨⟨0, j⟩, hp j⟩])
include e hp in
lemma mapBifunctorLeftUnitor_hasMap :
HasMap (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y) p :=
CofanMapObjFun.hasMap _ _ _ (mapBifunctorLeftUnitorCofanIsColimit F X e p hp Y)
variable [HasMap (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y) p]
[HasMap (((mapBifunctor F I J).obj ((single₀ I).obj X)).obj Y') p]
/-- Given `F : C ⥤ D ⥤ D`, `X : C`, `e : F.obj X ≅ 𝟭 D`, `Y : GradedObject J D` and
`p : I × J → J` such that `p ⟨0, j⟩ = j` for all `j`,
this is the left unitor isomorphism `mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y`. -/
noncomputable def mapBifunctorLeftUnitor : mapBifunctorMapObj F p ((single₀ I).obj X) Y ≅ Y :=
isoMk _ _ (fun j => (CofanMapObjFun.iso
(mapBifunctorLeftUnitorCofanIsColimit F X e p hp Y j)).symm)
@[reassoc (attr := simp)]
lemma ι_mapBifunctorLeftUnitor_hom_apply (j : J) :
ιMapBifunctorMapObj F p ((single₀ I).obj X) Y 0 j j (hp j) ≫
(mapBifunctorLeftUnitor F X e p hp Y).hom j =
(F.map (singleObjApplyIso (0 : I) X).hom).app _ ≫ e.hom.app (Y j) := by
dsimp [mapBifunctorLeftUnitor]
erw [CofanMapObjFun.ιMapObj_iso_inv]
rw [mapBifunctorLeftUnitorCofan_inj]
lemma mapBifunctorLeftUnitor_inv_apply (j : J) :
(mapBifunctorLeftUnitor F X e p hp Y).inv j =
e.inv.app (Y j) ≫ (F.map (singleObjApplyIso (0 : I) X).inv).app (Y j) ≫
ιMapBifunctorMapObj F p ((single₀ I).obj X) Y 0 j j (hp j) := rfl
variable {Y Y'}
@[reassoc]
lemma mapBifunctorLeftUnitor_inv_naturality :
φ ≫ (mapBifunctorLeftUnitor F X e p hp Y').inv =
(mapBifunctorLeftUnitor F X e p hp Y).inv ≫ mapBifunctorMapMap F p (𝟙 _) φ := by
ext j
dsimp
rw [mapBifunctorLeftUnitor_inv_apply, mapBifunctorLeftUnitor_inv_apply, assoc, assoc,
ι_mapBifunctorMapMap]
dsimp
rw [Functor.map_id, NatTrans.id_app, id_comp, ← NatTrans.naturality_assoc,
← NatTrans.naturality_assoc]
rfl
@[reassoc]
lemma mapBifunctorLeftUnitor_naturality :
mapBifunctorMapMap F p (𝟙 _) φ ≫ (mapBifunctorLeftUnitor F X e p hp Y').hom =
(mapBifunctorLeftUnitor F X e p hp Y).hom ≫ φ := by
rw [← cancel_mono (mapBifunctorLeftUnitor F X e p hp Y').inv, assoc, assoc, Iso.hom_inv_id,
comp_id, mapBifunctorLeftUnitor_inv_naturality, Iso.hom_inv_id_assoc]
end LeftUnitor
section RightUnitor
variable {C D I J : Type*} [Category C] [Category D]
[Zero I] [DecidableEq I] [HasInitial C]
(F : D ⥤ C ⥤ D) (Y : C) (e : F.flip.obj Y ≅ 𝟭 D)
[∀ (X : D), PreservesColimit (Functor.empty.{0} C) (F.obj X)]
(p : J × I → J)
(hp : ∀ (j : J), p ⟨j, 0⟩ = j) (X X' : GradedObject J D) (φ : X ⟶ X')
/-- Given `F : D ⥤ C ⥤ D`, `Y : C`, `e : F.flip.obj X ≅ 𝟭 D` and `X : GradedObject J D`,
this is the isomorphism `((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y) a ≅ Y a.2`
when `a : J × I` is such that `a.2 = 0`. -/
@[simps!]
noncomputable def mapBifunctorObjObjSingle₀Iso (a : J × I) (ha : a.2 = 0) :
((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y) a ≅ X a.1 :=
Functor.mapIso _ (singleObjApplyIsoOfEq _ Y _ ha) ≪≫ e.app (X a.1)
/-- Given `F : D ⥤ C ⥤ D`, `Y : C` and `X : GradedObject J D`,
`((mapBifunctor F J I).obj X).obj ((single₀ I).obj X) a` is an initial when `a : J × I`
is such that `a.2 ≠ 0`. -/
noncomputable def mapBifunctorObjObjSingle₀IsInitial (a : J × I) (ha : a.2 ≠ 0) :
IsInitial (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y) a) :=
IsInitial.isInitialObj (F.obj (X a.1)) _ (isInitialSingleObjApply _ _ _ ha)
/-- Given `F : D ⥤ C ⥤ D`, `Y : C`, `e : F.flip.obj Y ≅ 𝟭 D`, `X : GradedObject J D` and
`p : J × I → J` such that `p ⟨j, 0⟩ = j` for all `j`,
this is the (colimit) cofan which shall be used to construct the isomorphism
`mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X`, see `mapBifunctorRightUnitor`. -/
noncomputable def mapBifunctorRightUnitorCofan (hp : ∀ (j : J), p ⟨j, 0⟩ = j) (X) (j : J) :
(((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y)).CofanMapObjFun p j :=
CofanMapObjFun.mk _ _ _ (X j) (fun a ha =>
if ha : a.2 = 0 then
(mapBifunctorObjObjSingle₀Iso F Y e X a ha).hom ≫ eqToHom (by aesop)
else
(mapBifunctorObjObjSingle₀IsInitial F Y X a ha).to _)
@[simp, reassoc]
lemma mapBifunctorRightUnitorCofan_inj (j : J) :
(mapBifunctorRightUnitorCofan F Y e p hp X j).inj ⟨⟨j, 0⟩, hp j⟩ =
(F.obj (X j)).map (singleObjApplyIso (0 : I) Y).hom ≫ e.hom.app (X j) := by
simp [mapBifunctorRightUnitorCofan]
/-- The cofan `mapBifunctorRightUnitorCofan F Y e p hp X j` is a colimit. -/
noncomputable def mapBifunctorRightUnitorCofanIsColimit (j : J) :
IsColimit (mapBifunctorRightUnitorCofan F Y e p hp X j) :=
mkCofanColimit _
(fun s => e.inv.app (X j) ≫
(F.obj (X j)).map (singleObjApplyIso (0 : I) Y).inv ≫ s.inj ⟨⟨j, 0⟩, hp j⟩)
(fun s => by
rintro ⟨⟨j', i⟩, h⟩
by_cases hi : i = 0
· subst hi
simp only [Set.mem_preimage, hp, Set.mem_singleton_iff] at h
subst h
dsimp
rw [mapBifunctorRightUnitorCofan_inj, assoc, Iso.hom_inv_id_app_assoc,
← Functor.map_comp_assoc, Iso.hom_inv_id, Functor.map_id, id_comp]
· apply IsInitial.hom_ext
exact mapBifunctorObjObjSingle₀IsInitial _ _ _ _ hi)
(fun s m hm => by
dsimp
rw [← hm ⟨⟨j, 0⟩, hp j⟩, mapBifunctorRightUnitorCofan_inj, assoc, ← Functor.map_comp_assoc,
Iso.inv_hom_id, Functor.map_id, id_comp, Iso.inv_hom_id_app_assoc])
include e hp in
lemma mapBifunctorRightUnitor_hasMap :
HasMap (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y)) p :=
CofanMapObjFun.hasMap _ _ _ (mapBifunctorRightUnitorCofanIsColimit F Y e p hp X)
variable [HasMap (((mapBifunctor F J I).obj X).obj ((single₀ I).obj Y)) p]
[HasMap (((mapBifunctor F J I).obj X').obj ((single₀ I).obj Y)) p]
/-- Given `F : D ⥤ C ⥤ D`, `Y : C`, `e : F.flip.obj Y ≅ 𝟭 D`, `X : GradedObject J D` and
`p : J × I → J` such that `p ⟨j, 0⟩ = j` for all `j`,
this is the right unitor isomorphism `mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X`. -/
noncomputable def mapBifunctorRightUnitor : mapBifunctorMapObj F p X ((single₀ I).obj Y) ≅ X :=
isoMk _ _ (fun j => (CofanMapObjFun.iso
| (mapBifunctorRightUnitorCofanIsColimit F Y e p hp X j)).symm)
@[reassoc (attr := simp)]
lemma ι_mapBifunctorRightUnitor_hom_apply (j : J) :
ιMapBifunctorMapObj F p X ((single₀ I).obj Y) j 0 j (hp j) ≫
(mapBifunctorRightUnitor F Y e p hp X).hom j =
(F.obj (X j)).map (singleObjApplyIso (0 : I) Y).hom ≫ e.hom.app (X j) := by
dsimp [mapBifunctorRightUnitor]
| Mathlib/CategoryTheory/GradedObject/Unitor.lean | 217 | 224 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.MeasurableSpace.MeasurablyGenerated
import Mathlib.MeasureTheory.Measure.NullMeasurable
import Mathlib.Order.Interval.Set.Monotone
/-!
# Measure spaces
The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to
be available in `MeasureSpace` (through `MeasurableSpace`).
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding
outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the
measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0`
on the null sets.
## Main statements
* `completion` is the completion of a measure to all null measurable sets.
* `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure.
## Implementation notes
Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
You often don't want to define a measure via its constructor.
Two ways that are sometimes more convenient:
* `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets
and proving the properties (1) and (2) mentioned above.
* `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that
all measurable sets in the measurable space are Carathéodory measurable.
To prove that two measures are equal, there are multiple options:
* `ext`: two measures are equal if they are equal on all measurable sets.
* `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating
the measurable sets, if the π-system contains a spanning increasing sequence of sets where the
measures take finite value (in particular the measures are σ-finite). This is a special case of
the more general `ext_of_generateFrom_of_cover`
* `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system
generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using
`C ∪ {univ}`, but is easier to work with.
A `MeasureSpace` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Complete_measure>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space, completion, null set, null measurable set
-/
noncomputable section
open Set
open Filter hiding map
open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory
open scoped symmDiff
variable {α β γ δ ι R R' : Type*}
namespace MeasureTheory
section
variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α}
instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) :=
⟨fun _s hs =>
let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs
⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
/-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/
theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} :
(∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by
simp only [uIoc_eq_union, mem_union, or_imp, eventually_and]
| theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ :=
measure_union₀ h.nullMeasurableSet hd.aedisjoint
| Mathlib/MeasureTheory/Measure/MeasureSpace.lean | 107 | 109 |
/-
Copyright (c) 2023 Koundinya Vajjha. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Koundinya Vajjha, Thomas Browning
-/
import Mathlib.Data.Rat.Defs
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
This file defines the harmonic numbers.
* `Mathilb/NumberTheory/Harmonic/Int.lean` proves that the `n`th harmonic number is not an integer.
* `Mathlib/NumberTheory/Harmonic/Bounds.lean` provides basic log bounds.
-/
/-- The nth-harmonic number defined as a finset sum of consecutive reciprocals. -/
def harmonic : ℕ → ℚ := fun n => ∑ i ∈ Finset.range n, (↑(i + 1))⁻¹
@[simp]
lemma harmonic_zero : harmonic 0 = 0 :=
rfl
@[simp]
lemma harmonic_succ (n : ℕ) : harmonic (n + 1) = harmonic n + (↑(n + 1))⁻¹ :=
Finset.sum_range_succ ..
| Mathlib/NumberTheory/Harmonic/Defs.lean | 37 | 41 | |
/-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez, Eric Wieser
-/
import Mathlib.Data.List.Chain
/-!
# Destuttering of Lists
This file proves theorems about `List.destutter` (in `Data.List.Defs`), which greedily removes all
non-related items that are adjacent in a list, e.g. `[2, 2, 3, 3, 2].destutter (≠) = [2, 3, 2]`.
Note that we make no guarantees of being the longest sublist with this property; e.g.,
`[123, 1, 2, 5, 543, 1000].destutter (<) = [123, 543, 1000]`, but a longer ascending chain could be
`[1, 2, 5, 543, 1000]`.
## Main statements
* `List.destutter_sublist`: `l.destutter` is a sublist of `l`.
* `List.destutter_is_chain'`: `l.destutter` satisfies `Chain' R`.
* Analogies of these theorems for `List.destutter'`, which is the `destutter` equivalent of `Chain`.
## Tags
adjacent, chain, duplicates, remove, list, stutter, destutter
-/
open Function
variable {α β : Type*} (l l₁ l₂ : List α) (R : α → α → Prop) [DecidableRel R] {a b : α}
variable {R₂ : β → β → Prop} [DecidableRel R₂]
namespace List
@[simp]
theorem destutter'_nil : destutter' R a [] = [a] :=
rfl
theorem destutter'_cons :
(b :: l).destutter' R a = if R a b then a :: destutter' R b l else destutter' R a l :=
rfl
variable {R}
@[simp]
theorem destutter'_cons_pos (h : R b a) : (a :: l).destutter' R b = b :: l.destutter' R a := by
rw [destutter', if_pos h]
@[simp]
theorem destutter'_cons_neg (h : ¬R b a) : (a :: l).destutter' R b = l.destutter' R b := by
rw [destutter', if_neg h]
variable (R)
@[simp]
theorem destutter'_singleton : [b].destutter' R a = if R a b then [a, b] else [a] := by
split_ifs with h <;> simp! [h]
theorem destutter'_sublist (a) : l.destutter' R a <+ a :: l := by
induction' l with b l hl generalizing a
· simp
rw [destutter']
split_ifs
· exact Sublist.cons₂ a (hl b)
· exact (hl a).trans ((l.sublist_cons_self b).cons_cons a)
theorem mem_destutter' (a) : a ∈ l.destutter' R a := by
induction' l with b l hl
· simp
rw [destutter']
split_ifs
· simp
· assumption
theorem destutter'_is_chain : ∀ l : List α, ∀ {a b}, R a b → (l.destutter' R b).Chain R a
| [], _, _, h => chain_singleton.mpr h
| c :: l, a, b, h => by
rw [destutter']
split_ifs with hbc
· rw [chain_cons]
exact ⟨h, destutter'_is_chain l hbc⟩
· exact destutter'_is_chain l h
theorem destutter'_is_chain' (a) : (l.destutter' R a).Chain' R := by
induction' l with b l hl generalizing a
· simp
rw [destutter']
split_ifs with h
· exact destutter'_is_chain R l h
· exact hl a
theorem destutter'_of_chain (h : l.Chain R a) : l.destutter' R a = a :: l := by
induction' l with b l hb generalizing a
· simp
obtain ⟨h, hc⟩ := chain_cons.mp h
rw [l.destutter'_cons_pos h, hb hc]
@[simp]
theorem destutter'_eq_self_iff (a) : l.destutter' R a = a :: l ↔ l.Chain R a :=
⟨fun h => by
suffices Chain' R (a::l) by
assumption
rw [← h]
exact l.destutter'_is_chain' R a, destutter'_of_chain _ _⟩
theorem destutter'_ne_nil : l.destutter' R a ≠ [] :=
ne_nil_of_mem <| l.mem_destutter' R a
|
@[simp]
theorem destutter_nil : ([] : List α).destutter R = [] :=
rfl
theorem destutter_cons' : (a :: l).destutter R = destutter' R a l :=
| Mathlib/Data/List/Destutter.lean | 109 | 114 |
/-
Copyright (c) 2024 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Lie.EngelSubalgebra
import Mathlib.Algebra.Lie.OfAssociative
import Mathlib.Algebra.Module.LinearMap.Polynomial
import Mathlib.LinearAlgebra.Eigenspace.Zero
/-!
# Rank of a Lie algebra and regular elements
Let `L` be a Lie algebra over a nontrivial commutative ring `R`,
and assume that `L` is finite free as `R`-module.
Then the coefficients of the characteristic polynomial of `ad R L x` are polynomial in `x`.
The *rank* of `L` is the smallest `n` for which the `n`-th coefficient is not the zero polynomial.
Continuing to write `n` for the rank of `L`, an element `x` of `L` is *regular*
if the `n`-th coefficient of the characteristic polynomial of `ad R L x` is non-zero.
## Main declarations
* `LieAlgebra.rank R L` is the rank of a Lie algebra `L` over a commutative ring `R`.
* `LieAlgebra.IsRegular R x` is the predicate that an element `x` of a Lie algebra `L` is regular.
## References
* [barnes1967]: "On Cartan subalgebras of Lie algebras" by D.W. Barnes.
-/
variable {R A L M ι ιₘ : Type*}
variable [CommRing R]
variable [CommRing A] [Algebra R A]
variable [LieRing L] [LieAlgebra R L] [Module.Finite R L] [Module.Free R L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
variable [Module.Finite R M] [Module.Free R M]
variable [Fintype ι]
variable [Fintype ιₘ]
variable (b : Basis ι R L) (bₘ : Basis ιₘ R M) (x : L)
namespace LieModule
open LieAlgebra LinearMap Module.Free
variable (R L M)
local notation "φ" => LieHom.toLinearMap (LieModule.toEnd R L M)
/--
Let `M` be a representation of a Lie algebra `L` over a nontrivial commutative ring `R`,
and assume that `L` and `M` are finite free as `R`-module.
Then the coefficients of the characteristic polynomial of `⁅x, ·⁆` are polynomial in `x`.
The *rank* of `M` is the smallest `n` for which the `n`-th coefficient is not the zero polynomial.
-/
noncomputable
def rank : ℕ := nilRank φ
lemma polyCharpoly_coeff_rank_ne_zero [Nontrivial R] [DecidableEq ι] :
(polyCharpoly φ b).coeff (rank R L M) ≠ 0 :=
polyCharpoly_coeff_nilRank_ne_zero _ _
| lemma rank_eq_natTrailingDegree [Nontrivial R] [DecidableEq ι] :
rank R L M = (polyCharpoly φ b).natTrailingDegree := by
apply nilRank_eq_polyCharpoly_natTrailingDegree
| Mathlib/Algebra/Lie/Rank.lean | 64 | 66 |
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Logic.Relator
import Mathlib.Tactic.Use
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Tactic.SimpRw
import Mathlib.Logic.Basic
import Mathlib.Order.Defs.Unbundled
/-!
# Relation closures
This file defines the reflexive, transitive, reflexive transitive and equivalence closures
of relations and proves some basic results on them.
Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For
the bundled version, see `Rel`.
## Definitions
* `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all
`a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`.
* `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related
transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`.
* `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything
`r` related transitively, plus for all `a` it relates `a` with itself. So
`ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as
the reflexive closure of the transitive closure, or the transitive closure of the reflexive
closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of
rewrites.
* `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates,
plus for all related pairs it relates them in the opposite order.
* `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and
`s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to
both.
* `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`,
`g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b`
related by `r`.
* `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In
terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term.
-/
open Function
variable {α β γ δ ε ζ : Type*}
section NeImp
variable {r : α → α → Prop}
theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x
/-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`,
it suffices to show it holds when `x ≠ y`. -/
theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by
by_cases hxy : x = y
· exact hxy ▸ h x
· exact hr hxy
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. -/
theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y :=
⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩
/-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`,
then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/
theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y :=
IsRefl.reflexive.ne_imp_iff
protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x :=
⟨fun h ↦ H h, fun h ↦ H h⟩
theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r :=
funext₂ fun _ _ ↦ propext <| h.iff _ _
theorem Symmetric.swap_eq : Symmetric r → swap r = r :=
Symmetric.flip_eq
theorem flip_eq_iff : flip r = r ↔ Symmetric r :=
⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩
theorem swap_eq_iff : swap r = r ↔ Symmetric r :=
flip_eq_iff
end NeImp
section Comap
variable {r : β → β → Prop}
theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a)
theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab
theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) :=
fun _ _ _ hab hbc ↦ h hab hbc
theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) :=
⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩
end Comap
namespace Relation
section Comp
variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop}
/-- The composition of two relations, yielding a new relation. The result
relates a term of `α` and a term of `γ` if there is an intermediate
term of `β` related to both.
-/
def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop :=
∃ b, r a b ∧ p b c
@[inherit_doc]
local infixr:80 " ∘r " => Relation.Comp
@[simp]
theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun ..
@[simp]
theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by
ext x y
simp [Comp]
@[simp]
theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp ..
@[simp]
theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, eq_comp]
@[simp]
theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by
have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq
rw [this, comp_eq]
theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by
funext a d
apply propext
constructor
· exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩
· exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩
theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by
funext c a
apply propext
constructor
· exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩
· exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩
end Comp
section Fibration
variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β)
/-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all
`a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image
of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/
def Fibration :=
∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b
variable {rα rβ}
/-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is
accessible under `rα`, then `f a` is accessible under `rβ`. -/
theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by
induction ha with | intro a _ ih => ?_
refine Acc.intro (f a) fun b hr ↦ ?_
obtain ⟨a', hr', rfl⟩ := fib hr
exact ih a' hr'
theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α)
(ha : Acc (InvImage rβ f) a) : Acc rβ (f a) :=
ha.of_fibration f fun a _ h ↦
let ⟨a', he⟩ := dc h
⟨a', by simp_all [InvImage], he⟩
end Fibration
section Map
variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ}
/-- The map of a relation `r` through a pair of functions pushes the
relation to the codomains of the functions. The resulting relation is
defined by having pairs of terms related if they have preimages
related by `r`.
-/
protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦
∃ a b, r a b ∧ f a = c ∧ g b = d
lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl
@[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) :
Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by
ext a b
simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ]
refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩
rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩
exact ⟨hab, h⟩
@[simp]
lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) :
Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff]
@[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map]
instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) :=
‹Decidable _›
lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) :
Reflexive (Relation.Map r f f) := by
intro x
obtain ⟨y, rfl⟩ := hf x
exact ⟨y, y, hr y, rfl, rfl⟩
lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) :
Symmetric (Relation.Map r f f) := by
rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩
lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β}
(hf : ∀ x y, f x = f y → r x y) :
Transitive (Relation.Map r f f) := by
rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩
exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩
lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β)
(hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) :
Equivalence (Relation.Map r f f) where
refl := map_reflexive hr.reflexive hf
symm := @(map_symmetric hr.symmetric _)
trans := @(map_transitive hr.transitive hf_ker)
-- TODO: state this using `≤`, after adjusting imports.
lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) :
∀ x y, Relation.Map r f g x y → Relation.Map s f g x y :=
fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩
end Map
variable {r : α → α → Prop} {a b c : α}
/-- `ReflTransGen r`: reflexive transitive closure of `r` -/
@[mk_iff ReflTransGen.cases_tail_iff]
inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflTransGen r a a
| tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c
attribute [refl] ReflTransGen.refl
/-- `ReflGen r`: reflexive closure of `r` -/
@[mk_iff]
inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflGen r a a
| single {b} : r a b → ReflGen r a b
variable (r) in
/-- `EqvGen r`: equivalence closure of `r`. -/
@[mk_iff]
inductive EqvGen : α → α → Prop
| rel x y : r x y → EqvGen x y
| refl x : EqvGen x x
| symm x y : EqvGen x y → EqvGen y x
| trans x y z : EqvGen x y → EqvGen y z → EqvGen x z
attribute [mk_iff] TransGen
attribute [refl] ReflGen.refl
namespace ReflGen
theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b
| a, _, refl => by rfl
| _, _, single h => ReflTransGen.tail ReflTransGen.refl h
theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b
| a, _, ReflGen.refl => by rfl
| a, b, single h => single (hp a b h)
instance : IsRefl α (ReflGen r) :=
⟨@refl α r⟩
end ReflGen
namespace ReflTransGen
@[trans]
theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
theorem single (hab : r a b) : ReflTransGen r a b :=
refl.tail hab
theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by
induction hbc with
| refl => exact refl.tail hab
| tail _ hcd hac => exact hac.tail hcd
theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by
intro x y h
induction h with
| refl => rfl
| tail _ b c => apply Relation.ReflTransGen.head (h b) c
theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b :=
(cases_tail_iff r a b).1
@[elab_as_elim]
theorem head_induction_on {P : ∀ a : α, ReflTransGen r a b → Prop} {a : α} (h : ReflTransGen r a b)
(refl : P b refl)
(head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), P c h → P a (h.head h')) : P a h := by
induction h with
| refl => exact refl
| @tail b c _ hbc ih =>
apply ih
· exact head hbc _ refl
· exact fun h1 h2 ↦ head h1 (h2.tail hbc)
@[elab_as_elim]
theorem trans_induction_on {P : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α}
(h : ReflTransGen r a b) (ih₁ : ∀ a, @P a a refl) (ih₂ : ∀ {a b} (h : r a b), P (single h))
(ih₃ : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), P h₁ → P h₂ →
P (h₁.trans h₂)) : P h := by
induction h with
| refl => exact ih₁ a
| tail hab hbc ih => exact ih₃ hab (single hbc) ih (ih₂ hbc)
theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
induction h using Relation.ReflTransGen.head_induction_on
· left
rfl
· right
exact ⟨_, by assumption, by assumption⟩
theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by
use cases_head
rintro (rfl | ⟨c, hac, hcb⟩)
· rfl
· exact head hac hcb
theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b)
(ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by
induction ab with
| refl => exact Or.inl ac
| tail _ bd IH =>
rcases IH with (IH | IH)
· rcases cases_head IH with (rfl | ⟨e, be, ec⟩)
· exact Or.inr (single bd)
· cases U bd be
exact Or.inl ec
· exact Or.inr (IH.tail bd)
end ReflTransGen
namespace TransGen
theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by
induction h with
| single h => exact ReflTransGen.single h
| tail _ bc ab => exact ReflTransGen.tail ab bc
theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by
induction hbc with
| refl => assumption
| tail _ hcd hac => exact hac.tail hcd
instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) :=
⟨trans_left⟩
attribute [trans] trans
instance : Trans (TransGen r) (TransGen r) (TransGen r) :=
⟨trans⟩
theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c :=
trans_left (single hab) hbc
theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by
induction hab generalizing c with
| refl => exact single hbc
| tail _ hdb IH => exact tail (IH hdb) hbc
theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c :=
head' hab hbc.to_reflTransGen
@[elab_as_elim]
theorem head_induction_on {P : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b)
(base : ∀ {a} (h : r a b), P a (single h))
(ih : ∀ {a c} (h' : r a c) (h : TransGen r c b), P c h → P a (h.head h')) : P a h := by
induction h with
| single h => exact base h
| @tail b c _ hbc h_ih =>
apply h_ih
· exact fun h ↦ ih h (single hbc) (base hbc)
· exact fun hab hbc ↦ ih hab _
@[elab_as_elim]
theorem trans_induction_on {P : ∀ {a b : α}, TransGen r a b → Prop} {a b : α} (h : TransGen r a b)
(base : ∀ {a b} (h : r a b), P (single h))
(ih : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) :
P h := by
induction h with
| single h => exact base h
| tail hab hbc h_ih => exact ih hab (single hbc) h_ih (base hbc)
theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by
induction hbc with
| single hbc => exact tail' hab hbc
| tail _ hcd hac => exact hac.tail hcd
instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) :=
⟨trans_right⟩
theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩
cases h with
| single hac => exact ⟨_, by rfl, hac⟩
| tail hab hbc => exact ⟨_, hab.to_reflTransGen, hbc⟩
theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by
refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩
induction h with
| single hac => exact ⟨_, hac, by rfl⟩
| tail _ hbc IH =>
rcases IH with ⟨d, had, hdb⟩
exact ⟨_, had, hdb.tail hbc⟩
end TransGen
section reflGen
lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by
ext x y
simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y
lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl
lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α}
(hxy : ReflGen r x y) : r' x y := by
simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy
end reflGen
section TransGen
theorem transGen_eq_self (trans : Transitive r) : TransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| single hc => exact hc
| tail _ hcd hac => exact trans hac hcd, TransGen.single⟩
theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans
instance : IsTrans α (TransGen r) :=
⟨@TransGen.trans α r⟩
theorem transGen_idem : TransGen (TransGen r) = TransGen r :=
transGen_eq_self transitive_transGen
theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b))
(hab : TransGen r a b) : TransGen p (f a) (f b) := by
induction hab with
| single hac => exact TransGen.single (h a _ hac)
| tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd)
theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) :
TransGen p (f a) (f b) := by
simpa [transGen_idem] using hab.lift f h
theorem TransGen.closed {p : α → α → Prop} :
(∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift' id
lemma TransGen.closed' {P : α → Prop} (dc : ∀ {a b}, r a b → P b → P a)
{a b : α} (h : TransGen r a b) : P b → P a :=
h.head_induction_on dc fun hr _ hi ↦ dc hr ∘ hi
theorem TransGen.mono {p : α → α → Prop} :
(∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b :=
TransGen.lift id
lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y)
{x y : α} (hxy : TransGen r x y) : r' x y := by
simpa [transGen_eq_self hr'] using TransGen.mono h hxy
theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by
induction h with
| single h => exact TransGen.single h
| tail _ hbc ih => exact ih.head hbc
theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a :=
⟨TransGen.swap, TransGen.swap⟩
end TransGen
section ReflTransGen
open ReflTransGen
theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by
rw [cases_head_iff]; simp [h, eq_comm]
theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· cases h with
| refl => exact Or.inl rfl
| tail hac hcb => exact Or.inr (TransGen.tail' hac hcb)
· rcases h with (rfl | h)
· rfl
· exact h.to_reflTransGen
theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) :=
ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans
theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) →
ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift id
theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r :=
funext fun a ↦ funext fun b ↦ propext <|
⟨fun h ↦ by
induction h with
| refl => apply refl
| tail _ h₂ IH => exact trans IH h₂, single⟩
lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r')
(h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by
simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy
theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl
theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans
instance : IsRefl α (ReflTransGen r) :=
⟨@ReflTransGen.refl α r⟩
instance : IsTrans α (ReflTransGen r) :=
⟨@ReflTransGen.trans α r⟩
theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r :=
reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen
theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀ a b, r a b → ReflTransGen p (f a) (f b))
(hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by
simpa [reflTransGen_idem] using hab.lift f h
theorem reflTransGen_closed {p : α → α → Prop} :
(∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b :=
ReflTransGen.lift' id
theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by
induction h with
| refl => rfl
| tail _ hbc ih => exact ih.head hbc
theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a :=
⟨ReflTransGen.swap, ReflTransGen.swap⟩
@[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by
ext x y
simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff]
@[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by
ext x y
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simpa [reflTransGen_idem]
using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h
· obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h
· exact .single .refl
· exact TransGen.mono (fun _ _ ↦ .single) h
@[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by
simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen]
@[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by
simp only [← reflGen_transGen, transGen_idem]
lemma reflTransGen_eq_transGen (hr : Reflexive r) :
ReflTransGen r = TransGen r := by
rw [← transGen_reflGen, reflGen_eq_self hr]
lemma reflTransGen_eq_reflGen (hr : Transitive r) :
ReflTransGen r = ReflGen r := by
rw [← reflGen_transGen, transGen_eq_self hr]
end ReflTransGen
namespace EqvGen
variable (r)
theorem is_equivalence : Equivalence (@EqvGen α r) :=
Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _)
/-- `EqvGen.setoid r` is the setoid generated by a relation `r`.
The motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.setoid r)`,
see for example `Quot.eqvGen_exact` and `Quot.eqvGen_sound`. -/
def setoid : Setoid α :=
Setoid.mk _ (EqvGen.is_equivalence r)
theorem mono {r p : α → α → Prop} (hrp : ∀ a b, r a b → p a b) (h : EqvGen r a b) :
EqvGen p a b := by
induction h with
| rel a b h => exact EqvGen.rel _ _ (hrp _ _ h)
| refl => exact EqvGen.refl _
| symm a b _ ih => exact EqvGen.symm _ _ ih
| trans a b c _ _ hab hbc => exact EqvGen.trans _ _ _ hab hbc
end EqvGen
/-- The join of a relation on a single type is a new relation for which
pairs of terms are related if there is a third term they are both
related to. For example, if `r` is a relation representing rewrites
in a term rewriting system, then *confluence* is the property that if
`a` rewrites to both `b` and `c`, then `join r` relates `b` and `c`
| (see `Relation.church_rosser`).
-/
def Join (r : α → α → Prop) : α → α → Prop := fun a b ↦ ∃ c, r a c ∧ r b c
section Join
open ReflTransGen ReflGen
| Mathlib/Logic/Relation.lean | 636 | 643 |
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.MeasureTheory.Integral.Bochner.ContinuousLinearMap
/-!
# Integral average of a function
In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average
value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it
is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability
measure, then the average of any function is equal to its integral.
For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For
average w.r.t. the volume, one can omit `∂volume`.
Both have a version for the Lebesgue integral rather than Bochner.
We prove several version of the first moment method: An integrable function is below/above its
average on a set of positive measure:
* `measure_le_setLAverage_pos` for the Lebesgue integral
* `measure_le_setAverage_pos` for the Bochner integral
## Implementation notes
The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner
integrals work for the average without modifications. For theorems that require integrability of a
function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`.
## Tags
integral, center mass, average value
-/
open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function
open scoped Topology ENNReal Convex
variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α}
{s t : Set α}
/-!
### Average value of a function w.r.t. a measure
The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation:
`⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total
measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if
`f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to
its integral.
-/
namespace MeasureTheory
section ENNReal
variable (μ) {f g : α → ℝ≥0∞}
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`.
It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If
`μ` is a probability measure, then the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure.
It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite
measure. In a probability space, the average of any function is equal to its integral.
For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s`
has measure `1`, then the average of any function is equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r
/-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If
`s` has measure `1`, then the average of any function is equal to its integral. -/
notation3 (prettyPrint := false)
"⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r
@[simp]
theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero]
@[simp]
theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage]
theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl
theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by
rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul]
theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) :
⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero]
· rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
theorem setLAverage_eq (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq
theorem setLAverage_eq' (f : α → ℝ≥0∞) (s : Set α) :
⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [laverage_eq', restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq'
variable {μ}
theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by
simp only [laverage_eq, lintegral_congr_ae h]
theorem setLAverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by
simp only [setLAverage_eq, setLIntegral_congr h, measure_congr h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr := setLAverage_congr
theorem setLAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by
simp only [laverage_eq, setLIntegral_congr_fun hs h]
@[deprecated (since := "2025-04-22")] alias setLaverage_congr_fun := setLAverage_congr_fun
theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [laverage_eq]
exact div_lt_top hf (measure_univ_ne_zero.2 hμ)
theorem setLAverage_lt_top : ∫⁻ x in s, f x ∂μ ≠ ∞ → ⨍⁻ x in s, f x ∂μ < ∞ :=
laverage_lt_top
@[deprecated (since := "2025-04-22")] alias setLaverage_lt_top := setLAverage_lt_top
theorem laverage_add_measure :
⨍⁻ x, f x ∂(μ + ν) =
μ univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂μ + ν univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂ν := by
by_cases hμ : IsFiniteMeasure μ; swap
· rw [not_isFiniteMeasure_iff] at hμ
simp [laverage_eq, hμ]
by_cases hν : IsFiniteMeasure ν; swap
· rw [not_isFiniteMeasure_iff] at hν
simp [laverage_eq, hν]
haveI := hμ; haveI := hν
simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div,
← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq]
theorem measure_mul_setLAverage (f : α → ℝ≥0∞) (h : μ s ≠ ∞) :
μ s * ⨍⁻ x in s, f x ∂μ = ∫⁻ x in s, f x ∂μ := by
have := Fact.mk h.lt_top
rw [← measure_mul_laverage, restrict_apply_univ]
@[deprecated (since := "2025-04-22")] alias measure_mul_setLaverage := measure_mul_setLAverage
theorem laverage_union (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) :
⨍⁻ x in s ∪ t, f x ∂μ =
μ s / (μ s + μ t) * ⨍⁻ x in s, f x ∂μ + μ t / (μ s + μ t) * ⨍⁻ x in t, f x ∂μ := by
rw [restrict_union₀ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ]
theorem laverage_union_mem_openSegment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in t, f x ∂μ) := by
refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), ENNReal.div_pos hs₀ <| add_ne_top.2 ⟨hsμ, htμ⟩,
ENNReal.div_pos ht₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_union_mem_segment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) :
⨍⁻ x in s ∪ t, f x ∂μ ∈ [⨍⁻ x in s, f x ∂μ -[ℝ≥0∞] ⨍⁻ x in t, f x ∂μ] := by
by_cases hs₀ : μ s = 0
· rw [← ae_eq_empty] at hs₀
rw [restrict_congr_set (hs₀.union EventuallyEq.rfl), empty_union]
exact right_mem_segment _ _ _
· refine
⟨μ s / (μ s + μ t), μ t / (μ s + μ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩
rw [← ENNReal.add_div,
ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
theorem laverage_mem_openSegment_compl_self [IsFiniteMeasure μ] (hs : NullMeasurableSet s μ)
(hs₀ : μ s ≠ 0) (hsc₀ : μ sᶜ ≠ 0) :
⨍⁻ x, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in sᶜ, f x ∂μ) := by
simpa only [union_compl_self, restrict_univ] using
laverage_union_mem_openSegment aedisjoint_compl_right hs.compl hs₀ hsc₀ (measure_ne_top _ _)
(measure_ne_top _ _)
@[simp]
theorem laverage_const (μ : Measure α) [IsFiniteMeasure μ] [h : NeZero μ] (c : ℝ≥0∞) :
⨍⁻ _x, c ∂μ = c := by
simp only [laverage, lintegral_const, measure_univ, mul_one]
theorem setLAverage_const (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) (c : ℝ≥0∞) : ⨍⁻ _x in s, c ∂μ = c := by
simp only [setLAverage_eq, lintegral_const, Measure.restrict_apply, MeasurableSet.univ,
univ_inter, div_eq_mul_inv, mul_assoc, ENNReal.mul_inv_cancel hs₀ hs, mul_one]
@[deprecated (since := "2025-04-22")] alias setLaverage_const := setLAverage_const
theorem laverage_one [IsFiniteMeasure μ] [NeZero μ] : ⨍⁻ _x, (1 : ℝ≥0∞) ∂μ = 1 :=
laverage_const _ _
theorem setLAverage_one (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) : ⨍⁻ _x in s, (1 : ℝ≥0∞) ∂μ = 1 :=
setLAverage_const hs₀ hs _
@[deprecated (since := "2025-04-22")] alias setLaverage_one := setLAverage_one
@[simp]
theorem laverage_mul_measure_univ (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
(⨍⁻ (a : α), f a ∂μ) * μ univ = ∫⁻ x, f x ∂μ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [laverage_eq, ENNReal.div_mul_cancel (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)]
theorem lintegral_laverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) :
∫⁻ _x, ⨍⁻ a, f a ∂μ ∂μ = ∫⁻ x, f x ∂μ := by
simp
theorem setLIntegral_setLAverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → ℝ≥0∞) (s : Set α) :
∫⁻ _x in s, ⨍⁻ a in s, f a ∂μ ∂μ = ∫⁻ x in s, f x ∂μ :=
lintegral_laverage _ _
@[deprecated (since := "2025-04-22")] alias setLintegral_setLaverage := setLIntegral_setLAverage
end ENNReal
section NormedAddCommGroup
variable (μ)
variable {f g : α → E}
/-- Average value of a function `f` w.r.t. a measure `μ`, denoted `⨍ x, f x ∂μ`.
It is equal to `(μ.real univ)⁻¹ • ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable or
if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is
equal to its integral.
For the average on a set, use `⨍ x in s, f x ∂μ`, defined as `⨍ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
noncomputable def average (f : α → E) :=
∫ x, f x ∂(μ univ)⁻¹ • μ
/-- Average value of a function `f` w.r.t. a measure `μ`.
It is equal to `(μ.real univ)⁻¹ • ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable or
if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is
equal to its integral.
For the average on a set, use `⨍ x in s, f x ∂μ`, defined as `⨍ x, f x ∂(μ.restrict s)`. For the
average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => average μ r
/-- Average value of a function `f` w.r.t. to the standard measure.
It is equal to `(volume.real univ)⁻¹ * ∫ x, f x`, so it takes value zero if `f` is not integrable
or if the space has infinite measure. In a probability space, the average of any function is equal
to its integral.
For the average on a set, use `⨍ x in s, f x`, defined as `⨍ x, f x ∂(volume.restrict s)`. -/
notation3 "⨍ "(...)", "r:60:(scoped f => average volume f) => r
/-- Average value of a function `f` w.r.t. a measure `μ` on a set `s`.
It is equal to `(μ.real s)⁻¹ * ∫ x, f x ∂μ`, so it takes value zero if `f` is not integrable on
`s` or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is
equal to its integral.
For the average w.r.t. the volume, one can omit `∂volume`. -/
notation3 "⨍ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => average (Measure.restrict μ s) r
/-- Average value of a function `f` w.r.t. to the standard measure on a set `s`.
It is equal to `(volume.real s)⁻¹ * ∫ x, f x`, so it takes value zero `f` is not integrable on `s`
or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to
its integral. -/
notation3 "⨍ "(...)" in "s", "r:60:(scoped f => average (Measure.restrict volume s) f) => r
@[simp]
theorem average_zero : ⨍ _, (0 : E) ∂μ = 0 := by rw [average, integral_zero]
@[simp]
theorem average_zero_measure (f : α → E) : ⨍ x, f x ∂(0 : Measure α) = 0 := by
rw [average, smul_zero, integral_zero_measure]
@[simp]
theorem average_neg (f : α → E) : ⨍ x, -f x ∂μ = -⨍ x, f x ∂μ :=
integral_neg f
theorem average_eq' (f : α → E) : ⨍ x, f x ∂μ = ∫ x, f x ∂(μ univ)⁻¹ • μ :=
rfl
theorem average_eq (f : α → E) : ⨍ x, f x ∂μ = (μ.real univ)⁻¹ • ∫ x, f x ∂μ := by
rw [average_eq', integral_smul_measure, ENNReal.toReal_inv, measureReal_def]
theorem average_eq_integral [IsProbabilityMeasure μ] (f : α → E) : ⨍ x, f x ∂μ = ∫ x, f x ∂μ := by
rw [average, measure_univ, inv_one, one_smul]
@[simp]
theorem measure_smul_average [IsFiniteMeasure μ] (f : α → E) :
μ.real univ • ⨍ x, f x ∂μ = ∫ x, f x ∂μ := by
rcases eq_or_ne μ 0 with hμ | hμ
· rw [hμ, integral_zero_measure, average_zero_measure, smul_zero]
· rw [average_eq, smul_inv_smul₀]
refine (ENNReal.toReal_pos ?_ <| measure_ne_top _ _).ne'
rwa [Ne, measure_univ_eq_zero]
theorem setAverage_eq (f : α → E) (s : Set α) :
⨍ x in s, f x ∂μ = (μ.real s)⁻¹ • ∫ x in s, f x ∂μ := by
rw [average_eq, measureReal_restrict_apply_univ]
theorem setAverage_eq' (f : α → E) (s : Set α) :
⨍ x in s, f x ∂μ = ∫ x, f x ∂(μ s)⁻¹ • μ.restrict s := by
simp only [average_eq', restrict_apply_univ]
variable {μ}
theorem average_congr {f g : α → E} (h : f =ᵐ[μ] g) : ⨍ x, f x ∂μ = ⨍ x, g x ∂μ := by
simp only [average_eq, integral_congr_ae h]
theorem setAverage_congr (h : s =ᵐ[μ] t) : ⨍ x in s, f x ∂μ = ⨍ x in t, f x ∂μ := by
simp only [setAverage_eq, setIntegral_congr_set h, measureReal_congr h]
theorem setAverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
⨍ x in s, f x ∂μ = ⨍ x in s, g x ∂μ := by simp only [average_eq, setIntegral_congr_ae hs h]
theorem average_add_measure [IsFiniteMeasure μ] {ν : Measure α} [IsFiniteMeasure ν] {f : α → E}
(hμ : Integrable f μ) (hν : Integrable f ν) :
⨍ x, f x ∂(μ + ν) =
(μ.real univ / (μ.real univ + ν.real univ)) • ⨍ x, f x ∂μ +
(ν.real univ / (μ.real univ + ν.real univ)) • ⨍ x, f x ∂ν := by
simp only [div_eq_inv_mul, mul_smul, measure_smul_average, ← smul_add,
← integral_add_measure hμ hν, ← ENNReal.toReal_add (measure_ne_top μ _) (measure_ne_top ν _)]
rw [average_eq, measureReal_add_apply]
theorem average_pair [CompleteSpace E]
{f : α → E} {g : α → F} (hfi : Integrable f μ) (hgi : Integrable g μ) :
⨍ x, (f x, g x) ∂μ = (⨍ x, f x ∂μ, ⨍ x, g x ∂μ) :=
integral_pair hfi.to_average hgi.to_average
theorem measure_smul_setAverage (f : α → E) {s : Set α} (h : μ s ≠ ∞) :
μ.real s • ⨍ x in s, f x ∂μ = ∫ x in s, f x ∂μ := by
haveI := Fact.mk h.lt_top
rw [← measure_smul_average, measureReal_restrict_apply_univ]
theorem average_union {f : α → E} {s t : Set α} (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ)
(hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) (hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) :
⨍ x in s ∪ t, f x ∂μ =
(μ.real s / (μ.real s + μ.real t)) • ⨍ x in s, f x ∂μ +
(μ.real t / (μ.real s + μ.real t)) • ⨍ x in t, f x ∂μ := by
haveI := Fact.mk hsμ.lt_top; haveI := Fact.mk htμ.lt_top
rw [restrict_union₀ hd ht, average_add_measure hfs hft, measureReal_restrict_apply_univ,
measureReal_restrict_apply_univ]
theorem average_union_mem_openSegment {f : α → E} {s t : Set α} (hd : AEDisjoint μ s t)
(ht : NullMeasurableSet t μ) (hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞)
(hfs : IntegrableOn f s μ) (hft : IntegrableOn f t μ) :
⨍ x in s ∪ t, f x ∂μ ∈ openSegment ℝ (⨍ x in s, f x ∂μ) (⨍ x in t, f x ∂μ) := by
replace hs₀ : 0 < μ.real s := ENNReal.toReal_pos hs₀ hsμ
replace ht₀ : 0 < μ.real t := ENNReal.toReal_pos ht₀ htμ
exact mem_openSegment_iff_div.mpr
⟨μ.real s, μ.real t, hs₀, ht₀, (average_union hd ht hsμ htμ hfs hft).symm⟩
theorem average_union_mem_segment {f : α → E} {s t : Set α} (hd : AEDisjoint μ s t)
(ht : NullMeasurableSet t μ) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) (hfs : IntegrableOn f s μ)
(hft : IntegrableOn f t μ) :
⨍ x in s ∪ t, f x ∂μ ∈ [⨍ x in s, f x ∂μ -[ℝ] ⨍ x in t, f x ∂μ] := by
by_cases hse : μ s = 0
· rw [← ae_eq_empty] at hse
rw [restrict_congr_set (hse.union EventuallyEq.rfl), empty_union]
exact right_mem_segment _ _ _
· refine
mem_segment_iff_div.mpr
⟨μ.real s, μ.real t, ENNReal.toReal_nonneg, ENNReal.toReal_nonneg, ?_,
(average_union hd ht hsμ htμ hfs hft).symm⟩
calc
0 < μ.real s := ENNReal.toReal_pos hse hsμ
_ ≤ _ := le_add_of_nonneg_right ENNReal.toReal_nonneg
theorem average_mem_openSegment_compl_self [IsFiniteMeasure μ] {f : α → E} {s : Set α}
(hs : NullMeasurableSet s μ) (hs₀ : μ s ≠ 0) (hsc₀ : μ sᶜ ≠ 0) (hfi : Integrable f μ) :
⨍ x, f x ∂μ ∈ openSegment ℝ (⨍ x in s, f x ∂μ) (⨍ x in sᶜ, f x ∂μ) := by
simpa only [union_compl_self, restrict_univ] using
average_union_mem_openSegment aedisjoint_compl_right hs.compl hs₀ hsc₀ (measure_ne_top _ _)
(measure_ne_top _ _) hfi.integrableOn hfi.integrableOn
variable [CompleteSpace E]
@[simp]
theorem average_const (μ : Measure α) [IsFiniteMeasure μ] [h : NeZero μ] (c : E) :
⨍ _x, c ∂μ = c := by
rw [average, integral_const, measureReal_def, measure_univ, ENNReal.toReal_one, one_smul]
theorem setAverage_const {s : Set α} (hs₀ : μ s ≠ 0) (hs : μ s ≠ ∞) (c : E) :
⨍ _ in s, c ∂μ = c :=
have := NeZero.mk hs₀; have := Fact.mk hs.lt_top; average_const _ _
theorem integral_average (μ : Measure α) [IsFiniteMeasure μ] (f : α → E) :
∫ _, ⨍ a, f a ∂μ ∂μ = ∫ x, f x ∂μ := by simp
theorem setIntegral_setAverage (μ : Measure α) [IsFiniteMeasure μ] (f : α → E) (s : Set α) :
∫ _ in s, ⨍ a in s, f a ∂μ ∂μ = ∫ x in s, f x ∂μ :=
integral_average _ _
theorem integral_sub_average (μ : Measure α) [IsFiniteMeasure μ] (f : α → E) :
∫ x, f x - ⨍ a, f a ∂μ ∂μ = 0 := by
by_cases hf : Integrable f μ
· rw [integral_sub hf (integrable_const _), integral_average, sub_self]
refine integral_undef fun h => hf ?_
convert h.add (integrable_const (⨍ a, f a ∂μ))
exact (sub_add_cancel _ _).symm
theorem setAverage_sub_setAverage (hs : μ s ≠ ∞) (f : α → E) :
∫ x in s, f x - ⨍ a in s, f a ∂μ ∂μ = 0 :=
haveI : Fact (μ s < ∞) := ⟨lt_top_iff_ne_top.2 hs⟩
integral_sub_average _ _
theorem integral_average_sub [IsFiniteMeasure μ] (hf : Integrable f μ) :
∫ x, ⨍ a, f a ∂μ - f x ∂μ = 0 := by
rw [integral_sub (integrable_const _) hf, integral_average, sub_self]
theorem setIntegral_setAverage_sub (hs : μ s ≠ ∞) (hf : IntegrableOn f s μ) :
∫ x in s, ⨍ a in s, f a ∂μ - f x ∂μ = 0 :=
haveI : Fact (μ s < ∞) := ⟨lt_top_iff_ne_top.2 hs⟩
integral_average_sub hf
end NormedAddCommGroup
theorem ofReal_average {f : α → ℝ} (hf : Integrable f μ) (hf₀ : 0 ≤ᵐ[μ] f) :
ENNReal.ofReal (⨍ x, f x ∂μ) = (∫⁻ x, ENNReal.ofReal (f x) ∂μ) / μ univ := by
obtain rfl | hμ := eq_or_ne μ 0
· simp
· rw [average_eq, smul_eq_mul, measureReal_def, ← toReal_inv, ofReal_mul toReal_nonneg,
ofReal_toReal (inv_ne_top.2 <| measure_univ_ne_zero.2 hμ),
ofReal_integral_eq_lintegral_ofReal hf hf₀, ENNReal.div_eq_inv_mul]
theorem ofReal_setAverage {f : α → ℝ} (hf : IntegrableOn f s μ) (hf₀ : 0 ≤ᵐ[μ.restrict s] f) :
ENNReal.ofReal (⨍ x in s, f x ∂μ) = (∫⁻ x in s, ENNReal.ofReal (f x) ∂μ) / μ s := by
simpa using ofReal_average hf hf₀
theorem toReal_laverage {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf' : ∀ᵐ x ∂μ, f x ≠ ∞) :
(⨍⁻ x, f x ∂μ).toReal = ⨍ x, (f x).toReal ∂μ := by
rw [average_eq, laverage_eq, smul_eq_mul, toReal_div, div_eq_inv_mul, ←
integral_toReal hf (hf'.mono fun _ => lt_top_iff_ne_top.2), measureReal_def]
theorem toReal_setLAverage {f : α → ℝ≥0∞} (hf : AEMeasurable f (μ.restrict s))
(hf' : ∀ᵐ x ∂μ.restrict s, f x ≠ ∞) :
(⨍⁻ x in s, f x ∂μ).toReal = ⨍ x in s, (f x).toReal ∂μ := by
simpa [laverage_eq] using toReal_laverage hf hf'
@[deprecated (since := "2025-04-22")] alias toReal_setLaverage := toReal_setLAverage
/-! ### First moment method -/
section FirstMomentReal
variable {N : Set α} {f : α → ℝ}
/-- **First moment method**. An integrable function is smaller than its mean on a set of positive
measure. -/
theorem measure_le_setAverage_pos (hμ : μ s ≠ 0) (hμ₁ : μ s ≠ ∞) (hf : IntegrableOn f s μ) :
0 < μ ({x ∈ s | f x ≤ ⨍ a in s, f a ∂μ}) := by
refine pos_iff_ne_zero.2 fun H => ?_
replace H : (μ.restrict s) {x | f x ≤ ⨍ a in s, f a ∂μ} = 0 := by
rwa [restrict_apply₀, inter_comm]
exact AEStronglyMeasurable.nullMeasurableSet_le hf.1 aestronglyMeasurable_const
haveI := Fact.mk hμ₁.lt_top
refine (integral_sub_average (μ.restrict s) f).not_gt ?_
refine (setIntegral_pos_iff_support_of_nonneg_ae ?_ ?_).2 ?_
· refine measure_mono_null (fun x hx ↦ ?_) H
simp only [Pi.zero_apply, sub_nonneg, mem_compl_iff, mem_setOf_eq, not_le] at hx
exact hx.le
· exact hf.sub (integrableOn_const.2 <| Or.inr <| lt_top_iff_ne_top.2 hμ₁)
· rwa [pos_iff_ne_zero, inter_comm, ← diff_compl, ← diff_inter_self_eq_diff, measure_diff_null]
refine measure_mono_null ?_ (measure_inter_eq_zero_of_restrict H)
exact inter_subset_inter_left _ fun a ha => (sub_eq_zero.1 <| of_not_not ha).le
/-- **First moment method**. An integrable function is greater than its mean on a set of positive
measure. -/
theorem measure_setAverage_le_pos (hμ : μ s ≠ 0) (hμ₁ : μ s ≠ ∞) (hf : IntegrableOn f s μ) :
0 < μ ({x ∈ s | ⨍ a in s, f a ∂μ ≤ f x}) := by
simpa [integral_neg, neg_div] using measure_le_setAverage_pos hμ hμ₁ hf.neg
/-- **First moment method**. The minimum of an integrable function is smaller than its mean. -/
theorem exists_le_setAverage (hμ : μ s ≠ 0) (hμ₁ : μ s ≠ ∞) (hf : IntegrableOn f s μ) :
∃ x ∈ s, f x ≤ ⨍ a in s, f a ∂μ :=
let ⟨x, hx, h⟩ := nonempty_of_measure_ne_zero (measure_le_setAverage_pos hμ hμ₁ hf).ne'
⟨x, hx, h⟩
/-- **First moment method**. The maximum of an integrable function is greater than its mean. -/
theorem exists_setAverage_le (hμ : μ s ≠ 0) (hμ₁ : μ s ≠ ∞) (hf : IntegrableOn f s μ) :
∃ x ∈ s, ⨍ a in s, f a ∂μ ≤ f x :=
let ⟨x, hx, h⟩ := nonempty_of_measure_ne_zero (measure_setAverage_le_pos hμ hμ₁ hf).ne'
⟨x, hx, h⟩
section FiniteMeasure
variable [IsFiniteMeasure μ]
/-- **First moment method**. An integrable function is smaller than its mean on a set of positive
measure. -/
theorem measure_le_average_pos (hμ : μ ≠ 0) (hf : Integrable f μ) :
0 < μ {x | f x ≤ ⨍ a, f a ∂μ} := by
simpa using measure_le_setAverage_pos (Measure.measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)
hf.integrableOn
/-- **First moment method**. An integrable function is greater than its mean on a set of positive
measure. -/
theorem measure_average_le_pos (hμ : μ ≠ 0) (hf : Integrable f μ) :
0 < μ {x | ⨍ a, f a ∂μ ≤ f x} := by
simpa using measure_setAverage_le_pos (Measure.measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)
hf.integrableOn
/-- **First moment method**. The minimum of an integrable function is smaller than its mean. -/
theorem exists_le_average (hμ : μ ≠ 0) (hf : Integrable f μ) : ∃ x, f x ≤ ⨍ a, f a ∂μ :=
let ⟨x, hx⟩ := nonempty_of_measure_ne_zero (measure_le_average_pos hμ hf).ne'
⟨x, hx⟩
/-- **First moment method**. The maximum of an integrable function is greater than its mean. -/
theorem exists_average_le (hμ : μ ≠ 0) (hf : Integrable f μ) : ∃ x, ⨍ a, f a ∂μ ≤ f x :=
let ⟨x, hx⟩ := nonempty_of_measure_ne_zero (measure_average_le_pos hμ hf).ne'
⟨x, hx⟩
/-- **First moment method**. The minimum of an integrable function is smaller than its mean, while
avoiding a null set. -/
theorem exists_not_mem_null_le_average (hμ : μ ≠ 0) (hf : Integrable f μ) (hN : μ N = 0) :
∃ x, x ∉ N ∧ f x ≤ ⨍ a, f a ∂μ := by
have := measure_le_average_pos hμ hf
rw [← measure_diff_null hN] at this
obtain ⟨x, hx, hxN⟩ := nonempty_of_measure_ne_zero this.ne'
exact ⟨x, hxN, hx⟩
/-- **First moment method**. The maximum of an integrable function is greater than its mean, while
avoiding a null set. -/
theorem exists_not_mem_null_average_le (hμ : μ ≠ 0) (hf : Integrable f μ) (hN : μ N = 0) :
∃ x, x ∉ N ∧ ⨍ a, f a ∂μ ≤ f x := by
simpa [integral_neg, neg_div] using exists_not_mem_null_le_average hμ hf.neg hN
end FiniteMeasure
section ProbabilityMeasure
variable [IsProbabilityMeasure μ]
/-- **First moment method**. An integrable function is smaller than its integral on a set of
positive measure. -/
theorem measure_le_integral_pos (hf : Integrable f μ) : 0 < μ {x | f x ≤ ∫ a, f a ∂μ} := by
simpa only [average_eq_integral] using
measure_le_average_pos (IsProbabilityMeasure.ne_zero μ) hf
/-- **First moment method**. An integrable function is greater than its integral on a set of
positive measure. -/
theorem measure_integral_le_pos (hf : Integrable f μ) : 0 < μ {x | ∫ a, f a ∂μ ≤ f x} := by
simpa only [average_eq_integral] using
measure_average_le_pos (IsProbabilityMeasure.ne_zero μ) hf
/-- **First moment method**. The minimum of an integrable function is smaller than its integral. -/
theorem exists_le_integral (hf : Integrable f μ) : ∃ x, f x ≤ ∫ a, f a ∂μ := by
simpa only [average_eq_integral] using exists_le_average (IsProbabilityMeasure.ne_zero μ) hf
/-- **First moment method**. The maximum of an integrable function is greater than its integral. -/
theorem exists_integral_le (hf : Integrable f μ) : ∃ x, ∫ a, f a ∂μ ≤ f x := by
simpa only [average_eq_integral] using exists_average_le (IsProbabilityMeasure.ne_zero μ) hf
/-- **First moment method**. The minimum of an integrable function is smaller than its integral,
while avoiding a null set. -/
theorem exists_not_mem_null_le_integral (hf : Integrable f μ) (hN : μ N = 0) :
∃ x, x ∉ N ∧ f x ≤ ∫ a, f a ∂μ := by
simpa only [average_eq_integral] using
exists_not_mem_null_le_average (IsProbabilityMeasure.ne_zero μ) hf hN
/-- **First moment method**. The maximum of an integrable function is greater than its integral,
while avoiding a null set. -/
theorem exists_not_mem_null_integral_le (hf : Integrable f μ) (hN : μ N = 0) :
∃ x, x ∉ N ∧ ∫ a, f a ∂μ ≤ f x := by
simpa only [average_eq_integral] using
exists_not_mem_null_average_le (IsProbabilityMeasure.ne_zero μ) hf hN
end ProbabilityMeasure
end FirstMomentReal
section FirstMomentENNReal
variable {N : Set α} {f : α → ℝ≥0∞}
/-- **First moment method**. A measurable function is smaller than its mean on a set of positive
measure. -/
theorem measure_le_setLAverage_pos (hμ : μ s ≠ 0) (hμ₁ : μ s ≠ ∞)
(hf : AEMeasurable f (μ.restrict s)) : 0 < μ {x ∈ s | f x ≤ ⨍⁻ a in s, f a ∂μ} := by
obtain h | h := eq_or_ne (∫⁻ a in s, f a ∂μ) ∞
· simpa [mul_top, hμ₁, laverage, h, top_div_of_ne_top hμ₁, pos_iff_ne_zero] using hμ
have := measure_le_setAverage_pos hμ hμ₁ (integrable_toReal_of_lintegral_ne_top hf h)
rw [← setOf_inter_eq_sep, ← Measure.restrict_apply₀
(hf.aestronglyMeasurable.nullMeasurableSet_le aestronglyMeasurable_const)]
rw [← setOf_inter_eq_sep, ← Measure.restrict_apply₀
(hf.ennreal_toReal.aestronglyMeasurable.nullMeasurableSet_le aestronglyMeasurable_const),
← measure_diff_null (measure_eq_top_of_lintegral_ne_top hf h)] at this
refine this.trans_le (measure_mono ?_)
rintro x ⟨hfx, hx⟩
dsimp at hfx
rwa [← toReal_laverage hf, toReal_le_toReal hx (setLAverage_lt_top h).ne] at hfx
simp_rw [ae_iff, not_ne_iff]
exact measure_eq_top_of_lintegral_ne_top hf h
@[deprecated (since := "2025-04-22")] alias measure_le_setLaverage_pos := measure_le_setLAverage_pos
/-- **First moment method**. A measurable function is greater than its mean on a set of positive
| measure. -/
theorem measure_setLAverage_le_pos (hμ : μ s ≠ 0) (hs : NullMeasurableSet s μ)
| Mathlib/MeasureTheory/Integral/Average.lean | 629 | 630 |
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn, Joachim Breitner
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.Group.Submonoid.Membership
import Mathlib.GroupTheory.Congruence.Basic
import Mathlib.GroupTheory.FreeGroup.IsFreeGroup
import Mathlib.SetTheory.Cardinal.Basic
/-!
# The coproduct (a.k.a. the free product) of groups or monoids
Given an `ι`-indexed family `M` of monoids,
we define their coproduct (a.k.a. free product) `Monoid.CoprodI M`.
As usual, we use the suffix `I` for an indexed (co)product,
leaving `Coprod` for the coproduct of two monoids.
When `ι` and all `M i` have decidable equality,
the free product bijects with the type `Monoid.CoprodI.Word M` of reduced words.
This bijection is constructed
by defining an action of `Monoid.CoprodI M` on `Monoid.CoprodI.Word M`.
When `M i` are all groups, `Monoid.CoprodI M` is also a group
(and the coproduct in the category of groups).
## Main definitions
- `Monoid.CoprodI M`: the free product, defined as a quotient of a free monoid.
- `Monoid.CoprodI.of {i} : M i →* Monoid.CoprodI M`.
- `Monoid.CoprodI.lift : (∀ {i}, M i →* N) ≃ (Monoid.CoprodI M →* N)`: the universal property.
- `Monoid.CoprodI.Word M`: the type of reduced words.
- `Monoid.CoprodI.Word.equiv M : Monoid.CoprodI M ≃ word M`.
- `Monoid.CoprodI.NeWord M i j`: an inductive description of non-empty words
with first letter from `M i` and last letter from `M j`,
together with an API (`singleton`, `append`, `head`, `tail`, `to_word`, `Prod`, `inv`).
Used in the proof of the Ping-Pong-lemma.
- `Monoid.CoprodI.lift_injective_of_ping_pong`: The Ping-Pong-lemma,
proving injectivity of the `lift`. See the documentation of that theorem for more information.
## Remarks
There are many answers to the question "what is the coproduct of a family `M` of monoids?",
and they are all equivalent but not obviously equivalent.
We provide two answers.
The first, almost tautological answer is given by `Monoid.CoprodI M`,
which is a quotient of the type of words in the alphabet `Σ i, M i`.
It's straightforward to define and easy to prove its universal property.
But this answer is not completely satisfactory,
because it's difficult to tell when two elements `x y : Monoid.CoprodI M` are distinct
since `Monoid.CoprodI M` is defined as a quotient.
The second, maximally efficient answer is given by `Monoid.CoprodI.Word M`.
An element of `Monoid.CoprodI.Word M` is a word in the alphabet `Σ i, M i`,
where the letter `⟨i, 1⟩` doesn't occur and no adjacent letters share an index `i`.
Since we only work with reduced words, there is no need for quotienting,
and it is easy to tell when two elements are distinct.
However it's not obvious that this is even a monoid!
We prove that every element of `Monoid.CoprodI M` can be represented by a unique reduced word,
i.e. `Monoid.CoprodI M` and `Monoid.CoprodI.Word M` are equivalent types.
This means that `Monoid.CoprodI.Word M` can be given a monoid structure,
and it lets us tell when two elements of `Monoid.CoprodI M` are distinct.
There is also a completely tautological, maximally inefficient answer
given by `MonCat.Colimits.ColimitType`.
Whereas `Monoid.CoprodI M` at least ensures that
(any instance of) associativity holds by reflexivity,
in this answer associativity holds because of quotienting.
Yet another answer, which is constructively more satisfying,
could be obtained by showing that `Monoid.CoprodI.Rel` is confluent.
## References
[van der Waerden, *Free products of groups*][MR25465]
-/
open Set
variable {ι : Type*} (M : ι → Type*) [∀ i, Monoid (M i)]
/-- A relation on the free monoid on alphabet `Σ i, M i`,
relating `⟨i, 1⟩` with `1` and `⟨i, x⟩ * ⟨i, y⟩` with `⟨i, x * y⟩`. -/
inductive Monoid.CoprodI.Rel : FreeMonoid (Σ i, M i) → FreeMonoid (Σ i, M i) → Prop
| of_one (i : ι) : Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, 1⟩) 1
| of_mul {i : ι} (x y : M i) :
Monoid.CoprodI.Rel (FreeMonoid.of ⟨i, x⟩ * FreeMonoid.of ⟨i, y⟩) (FreeMonoid.of ⟨i, x * y⟩)
/-- The free product (categorical coproduct) of an indexed family of monoids. -/
def Monoid.CoprodI : Type _ := (conGen (Monoid.CoprodI.Rel M)).Quotient
-- The `Monoid` instance should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : Monoid (Monoid.CoprodI M) := by
delta Monoid.CoprodI; infer_instance
instance : Inhabited (Monoid.CoprodI M) :=
⟨1⟩
namespace Monoid.CoprodI
/-- The type of reduced words. A reduced word cannot contain a letter `1`, and no two adjacent
letters can come from the same summand. -/
@[ext]
structure Word where
/-- A `Word` is a `List (Σ i, M i)`, such that `1` is not in the list, and no
two adjacent letters are from the same summand -/
toList : List (Σi, M i)
/-- A reduced word does not contain `1` -/
ne_one : ∀ l ∈ toList, Sigma.snd l ≠ 1
/-- Adjacent letters are not from the same summand. -/
chain_ne : toList.Chain' fun l l' => Sigma.fst l ≠ Sigma.fst l'
variable {M}
/-- The inclusion of a summand into the free product. -/
def of {i : ι} : M i →* CoprodI M where
toFun x := Con.mk' _ (FreeMonoid.of <| Sigma.mk i x)
map_one' := (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_one i))
map_mul' x y := Eq.symm <| (Con.eq _).mpr (ConGen.Rel.of _ _ (CoprodI.Rel.of_mul x y))
theorem of_apply {i} (m : M i) : of m = Con.mk' _ (FreeMonoid.of <| Sigma.mk i m) :=
rfl
variable {N : Type*} [Monoid N]
/-- See note [partially-applied ext lemmas]. -/
-- Porting note: higher `ext` priority
@[ext 1100]
theorem ext_hom (f g : CoprodI M →* N) (h : ∀ i, f.comp (of : M i →* _) = g.comp of) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
FreeMonoid.hom_eq fun ⟨i, x⟩ => by
rw [MonoidHom.comp_apply, MonoidHom.comp_apply, ← of_apply]
unfold CoprodI
rw [← MonoidHom.comp_apply, ← MonoidHom.comp_apply, h]
/-- A map out of the free product corresponds to a family of maps out of the summands. This is the
universal property of the free product, characterizing it as a categorical coproduct. -/
@[simps symm_apply]
def lift : (∀ i, M i →* N) ≃ (CoprodI M →* N) where
toFun fi :=
Con.lift _ (FreeMonoid.lift fun p : Σi, M i => fi p.fst p.snd) <|
Con.conGen_le <| by
simp_rw [Con.ker_rel]
rintro _ _ (i | ⟨x, y⟩) <;> simp
invFun f _ := f.comp of
left_inv := by
intro fi
ext i x
rfl
right_inv := by
intro f
ext i x
rfl
@[simp]
theorem lift_comp_of {N} [Monoid N] (fi : ∀ i, M i →* N) i : (lift fi).comp of = fi i :=
congr_fun (lift.symm_apply_apply fi) i
@[simp]
theorem lift_of {N} [Monoid N] (fi : ∀ i, M i →* N) {i} (m : M i) : lift fi (of m) = fi i m :=
DFunLike.congr_fun (lift_comp_of ..) m
@[simp]
theorem lift_comp_of' {N} [Monoid N] (f : CoprodI M →* N) :
lift (fun i ↦ f.comp (of (i := i))) = f :=
lift.apply_symm_apply f
@[simp]
theorem lift_of' : lift (fun i ↦ (of : M i →* CoprodI M)) = .id (CoprodI M) :=
lift_comp_of' (.id _)
theorem of_leftInverse [DecidableEq ι] (i : ι) :
Function.LeftInverse (lift <| Pi.mulSingle i (MonoidHom.id (M i))) of := fun x => by
simp only [lift_of, Pi.mulSingle_eq_same, MonoidHom.id_apply]
theorem of_injective (i : ι) : Function.Injective (of : M i →* _) := by
classical exact (of_leftInverse i).injective
theorem mrange_eq_iSup {N} [Monoid N] (f : ∀ i, M i →* N) :
MonoidHom.mrange (lift f) = ⨆ i, MonoidHom.mrange (f i) := by
rw [lift, Equiv.coe_fn_mk, Con.lift_range, FreeMonoid.mrange_lift,
range_sigma_eq_iUnion_range, Submonoid.closure_iUnion]
simp only [MonoidHom.mclosure_range]
theorem lift_mrange_le {N} [Monoid N] (f : ∀ i, M i →* N) {s : Submonoid N} :
MonoidHom.mrange (lift f) ≤ s ↔ ∀ i, MonoidHom.mrange (f i) ≤ s := by
simp [mrange_eq_iSup]
@[simp]
theorem iSup_mrange_of : ⨆ i, MonoidHom.mrange (of : M i →* CoprodI M) = ⊤ := by
simp [← mrange_eq_iSup]
@[simp]
theorem mclosure_iUnion_range_of :
Submonoid.closure (⋃ i, Set.range (of : M i →* CoprodI M)) = ⊤ := by
simp [Submonoid.closure_iUnion]
@[elab_as_elim]
theorem induction_left {motive : CoprodI M → Prop} (m : CoprodI M) (one : motive 1)
(mul : ∀ {i} (m : M i) x, motive x → motive (of m * x)) : motive m := by
induction m using Submonoid.induction_of_closure_eq_top_left mclosure_iUnion_range_of with
| one => exact one
| mul x hx y ihy =>
obtain ⟨i, m, rfl⟩ : ∃ (i : ι) (m : M i), of m = x := by simpa using hx
exact mul m y ihy
@[elab_as_elim]
theorem induction_on {motive : CoprodI M → Prop} (m : CoprodI M) (one : motive 1)
(of : ∀ (i) (m : M i), motive (of m))
(mul : ∀ x y, motive x → motive y → motive (x * y)) : motive m := by
induction m using CoprodI.induction_left with
| one => exact one
| mul m x hx => exact mul _ _ (of _ _) hx
section Group
variable (G : ι → Type*) [∀ i, Group (G i)]
instance : Inv (CoprodI G) where
inv :=
MulOpposite.unop ∘ lift fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom
theorem inv_def (x : CoprodI G) :
x⁻¹ =
MulOpposite.unop
(lift (fun i => (of : G i →* _).op.comp (MulEquiv.inv' (G i)).toMonoidHom) x) :=
rfl
instance : Group (CoprodI G) :=
{ inv_mul_cancel := by
intro m
rw [inv_def]
induction m using CoprodI.induction_on with
| one => rw [MonoidHom.map_one, MulOpposite.unop_one, one_mul]
| of m ih =>
change of _⁻¹ * of _ = 1
rw [← of.map_mul, inv_mul_cancel, of.map_one]
| mul x y ihx ihy =>
rw [MonoidHom.map_mul, MulOpposite.unop_mul, mul_assoc, ← mul_assoc _ x y, ihx, one_mul,
ihy] }
theorem lift_range_le {N} [Group N] (f : ∀ i, G i →* N) {s : Subgroup N}
(h : ∀ i, (f i).range ≤ s) : (lift f).range ≤ s := by
rintro _ ⟨x, rfl⟩
induction x using CoprodI.induction_on with
| one => exact s.one_mem
| of i x =>
simp only [lift_of, SetLike.mem_coe]
exact h i (Set.mem_range_self x)
| mul x y hx hy =>
simp only [map_mul, SetLike.mem_coe]
exact s.mul_mem hx hy
theorem range_eq_iSup {N} [Group N] (f : ∀ i, G i →* N) : (lift f).range = ⨆ i, (f i).range := by
apply le_antisymm (lift_range_le _ f fun i => le_iSup (fun i => MonoidHom.range (f i)) i)
apply iSup_le _
rintro i _ ⟨x, rfl⟩
exact ⟨of x, by simp only [lift_of]⟩
end Group
namespace Word
/-- The empty reduced word. -/
@[simps]
def empty : Word M where
toList := []
ne_one := by simp
chain_ne := List.chain'_nil
instance : Inhabited (Word M) :=
⟨empty⟩
/-- A reduced word determines an element of the free product, given by multiplication. -/
def prod (w : Word M) : CoprodI M :=
List.prod (w.toList.map fun l => of l.snd)
@[simp]
theorem prod_empty : prod (empty : Word M) = 1 :=
rfl
/-- `fstIdx w` is `some i` if the first letter of `w` is `⟨i, m⟩` with `m : M i`. If `w` is empty
then it's `none`. -/
def fstIdx (w : Word M) : Option ι :=
w.toList.head?.map Sigma.fst
theorem fstIdx_ne_iff {w : Word M} {i} :
fstIdx w ≠ some i ↔ ∀ l ∈ w.toList.head?, i ≠ Sigma.fst l :=
not_iff_not.mp <| by simp [fstIdx]
variable (M)
/-- Given an index `i : ι`, `Pair M i` is the type of pairs `(head, tail)` where `head : M i` and
`tail : Word M`, subject to the constraint that first letter of `tail` can't be `⟨i, m⟩`.
By prepending `head` to `tail`, one obtains a new word. We'll show that any word can be uniquely
obtained in this way. -/
@[ext]
structure Pair (i : ι) where
/-- An element of `M i`, the first letter of the word. -/
head : M i
/-- The remaining letters of the word, excluding the first letter -/
tail : Word M
/-- The index first letter of tail of a `Pair M i` is not equal to `i` -/
fstIdx_ne : fstIdx tail ≠ some i
instance (i : ι) : Inhabited (Pair M i) :=
⟨⟨1, empty, by tauto⟩⟩
variable {M}
/-- Construct a new `Word` without any reduction. The underlying list of
`cons m w _ _` is `⟨_, m⟩::w` -/
@[simps]
def cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) : Word M :=
{ toList := ⟨i, m⟩ :: w.toList,
ne_one := by
simp only [List.mem_cons]
rintro l (rfl | hl)
· exact h1
· exact w.ne_one l hl
chain_ne := w.chain_ne.cons' (fstIdx_ne_iff.mp hmw) }
@[simp]
theorem fstIdx_cons {i} (m : M i) (w : Word M) (hmw : w.fstIdx ≠ some i) (h1 : m ≠ 1) :
fstIdx (cons m w hmw h1) = some i := by simp [cons, fstIdx]
@[simp]
theorem prod_cons (i) (m : M i) (w : Word M) (h1 : m ≠ 1) (h2 : w.fstIdx ≠ some i) :
prod (cons m w h2 h1) = of m * prod w := by
simp [cons, prod, List.map_cons, List.prod_cons]
section
variable [∀ i, DecidableEq (M i)]
/-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, except if `head`
is `1 : M i` then we have to just return `Word` since we need the result to be reduced. -/
def rcons {i} (p : Pair M i) : Word M :=
if h : p.head = 1 then p.tail
else cons p.head p.tail p.fstIdx_ne h
@[simp]
theorem prod_rcons {i} (p : Pair M i) : prod (rcons p) = of p.head * prod p.tail :=
if hm : p.head = 1 then by rw [rcons, dif_pos hm, hm, MonoidHom.map_one, one_mul]
else by rw [rcons, dif_neg hm, cons, prod, List.map_cons, List.prod_cons, prod]
theorem rcons_inj {i} : Function.Injective (rcons : Pair M i → Word M) := by
rintro ⟨m, w, h⟩ ⟨m', w', h'⟩ he
by_cases hm : m = 1 <;> by_cases hm' : m' = 1
· simp only [rcons, dif_pos hm, dif_pos hm'] at he
aesop
· exfalso
simp only [rcons, dif_pos hm, dif_neg hm'] at he
rw [he] at h
exact h rfl
· exfalso
simp only [rcons, dif_pos hm', dif_neg hm] at he
rw [← he] at h'
exact h' rfl
· have : m = m' ∧ w.toList = w'.toList := by
simpa [cons, rcons, dif_neg hm, dif_neg hm', eq_self_iff_true, Subtype.mk_eq_mk,
heq_iff_eq, ← Subtype.ext_iff_val] using he
rcases this with ⟨rfl, h⟩
congr
exact Word.ext h
theorem mem_rcons_iff {i j : ι} (p : Pair M i) (m : M j) :
⟨_, m⟩ ∈ (rcons p).toList ↔ ⟨_, m⟩ ∈ p.tail.toList ∨
m ≠ 1 ∧ (∃ h : i = j, m = h ▸ p.head) := by
simp only [rcons, cons, ne_eq]
by_cases hij : i = j
· subst i
by_cases hm : m = p.head
· subst m
split_ifs <;> simp_all
· split_ifs <;> simp_all
· split_ifs <;> simp_all [Ne.symm hij]
end
/-- Induct on a word by adding letters one at a time without reduction,
effectively inducting on the underlying `List`. -/
@[elab_as_elim]
def consRecOn {motive : Word M → Sort*} (w : Word M) (empty : motive empty)
(cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) :
motive w := by
rcases w with ⟨w, h1, h2⟩
induction w with
| nil => exact empty
| cons m w ih =>
refine cons m.1 m.2 ⟨w, fun _ hl => h1 _ (List.mem_cons_of_mem _ hl), h2.tail⟩ ?_ ?_ (ih _ _)
· rw [List.chain'_cons'] at h2
simp only [fstIdx, ne_eq, Option.map_eq_some_iff,
Sigma.exists, exists_and_right, exists_eq_right, not_exists]
intro m' hm'
exact h2.1 _ hm' rfl
· exact h1 _ List.mem_cons_self
@[simp]
theorem consRecOn_empty {motive : Word M → Sort*} (h_empty : motive empty)
(h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) :
consRecOn empty h_empty h_cons = h_empty := rfl
@[simp]
theorem consRecOn_cons {motive : Word M → Sort*} (i) (m : M i) (w : Word M) h1 h2
(h_empty : motive empty)
(h_cons : ∀ (i) (m : M i) (w) h1 h2, motive w → motive (cons m w h1 h2)) :
consRecOn (cons m w h1 h2) h_empty h_cons = h_cons i m w h1 h2
(consRecOn w h_empty h_cons) := rfl
variable [DecidableEq ι] [∀ i, DecidableEq (M i)]
-- This definition is computable but not very nice to look at. Thankfully we don't have to inspect
-- it, since `rcons` is known to be injective.
/-- Given `i : ι`, any reduced word can be decomposed into a pair `p` such that `w = rcons p`. -/
private def equivPairAux (i) (w : Word M) : { p : Pair M i // rcons p = w } :=
consRecOn w ⟨⟨1, .empty, by simp [fstIdx, empty]⟩, by simp [rcons]⟩ <|
fun j m w h1 h2 _ =>
if ij : i = j then
{ val :=
{ head := ij ▸ m
tail := w
fstIdx_ne := ij ▸ h1 }
property := by subst ij; simp [rcons, h2] }
else ⟨⟨1, cons m w h1 h2, by simp [cons, fstIdx, Ne.symm ij]⟩, by simp [rcons]⟩
/-- The equivalence between words and pairs. Given a word, it decomposes it as a pair by removing
the first letter if it comes from `M i`. Given a pair, it prepends the head to the tail. -/
def equivPair (i) : Word M ≃ Pair M i where
toFun w := (equivPairAux i w).val
invFun := rcons
left_inv w := (equivPairAux i w).property
right_inv _ := rcons_inj (equivPairAux i _).property
theorem equivPair_symm (i) (p : Pair M i) : (equivPair i).symm p = rcons p :=
rfl
theorem equivPair_eq_of_fstIdx_ne {i} {w : Word M} (h : fstIdx w ≠ some i) :
equivPair i w = ⟨1, w, h⟩ :=
(equivPair i).apply_eq_iff_eq_symm_apply.mpr <| Eq.symm (dif_pos rfl)
theorem mem_equivPair_tail_iff {i j : ι} {w : Word M} (m : M i) :
(⟨i, m⟩ ∈ (equivPair j w).tail.toList) ↔ ⟨i, m⟩ ∈ w.toList.tail
∨ i ≠ j ∧ ∃ h : w.toList ≠ [], w.toList.head h = ⟨i, m⟩ := by
simp only [equivPair, equivPairAux, ne_eq, Equiv.coe_fn_mk]
induction w using consRecOn with
| empty => simp
| cons k g tail h1 h2 ih =>
simp only [consRecOn_cons]
split_ifs with h
· subst k
by_cases hij : j = i <;> simp_all
· by_cases hik : i = k
· subst i; simp_all [@eq_comm _ m g, @eq_comm _ k j, or_comm]
· simp [hik, Ne.symm hik]
theorem mem_of_mem_equivPair_tail {i j : ι} {w : Word M} (m : M i) :
(⟨i, m⟩ ∈ (equivPair j w).tail.toList) → ⟨i, m⟩ ∈ w.toList := by
rw [mem_equivPair_tail_iff]
rintro (h | h)
· exact List.mem_of_mem_tail h
· revert h; cases w.toList <;> simp +contextual
theorem equivPair_head {i : ι} {w : Word M} :
(equivPair i w).head =
if h : ∃ (h : w.toList ≠ []), (w.toList.head h).1 = i
then h.snd ▸ (w.toList.head h.1).2
else 1 := by
simp only [equivPair, equivPairAux]
induction w using consRecOn with
| empty => simp
| cons head =>
by_cases hi : i = head
· subst hi; simp
· simp [hi, Ne.symm hi]
instance summandAction (i) : MulAction (M i) (Word M) where
smul m w := rcons { equivPair i w with head := m * (equivPair i w).head }
one_smul w := by
apply (equivPair i).symm_apply_eq.mpr
simp [equivPair]
mul_smul m m' w := by
dsimp [instHSMul]
simp [mul_assoc, ← equivPair_symm, Equiv.apply_symm_apply]
instance : MulAction (CoprodI M) (Word M) :=
MulAction.ofEndHom (lift fun _ => MulAction.toEndHom)
theorem smul_def {i} (m : M i) (w : Word M) :
m • w = rcons { equivPair i w with head := m * (equivPair i w).head } :=
rfl
theorem of_smul_def (i) (w : Word M) (m : M i) :
of m • w = rcons { equivPair i w with head := m * (equivPair i w).head } :=
rfl
theorem equivPair_smul_same {i} (m : M i) (w : Word M) :
equivPair i (of m • w) = ⟨m * (equivPair i w).head, (equivPair i w).tail,
(equivPair i w).fstIdx_ne⟩ := by
rw [of_smul_def, ← equivPair_symm]
simp
@[simp]
theorem equivPair_tail {i} (p : Pair M i) :
equivPair i p.tail = ⟨1, p.tail, p.fstIdx_ne⟩ :=
equivPair_eq_of_fstIdx_ne _
theorem smul_eq_of_smul {i} (m : M i) (w : Word M) :
m • w = of m • w := rfl
theorem mem_smul_iff {i j : ι} {m₁ : M i} {m₂ : M j} {w : Word M} :
⟨_, m₁⟩ ∈ (of m₂ • w).toList ↔
(¬i = j ∧ ⟨i, m₁⟩ ∈ w.toList)
∨ (m₁ ≠ 1 ∧ ∃ (hij : i = j),(⟨i, m₁⟩ ∈ w.toList.tail) ∨
(∃ m', ⟨j, m'⟩ ∈ w.toList.head? ∧ m₁ = hij ▸ (m₂ * m')) ∨
(w.fstIdx ≠ some j ∧ m₁ = hij ▸ m₂)) := by
rw [of_smul_def, mem_rcons_iff, mem_equivPair_tail_iff, equivPair_head, or_assoc]
by_cases hij : i = j
· subst i
simp only [not_true, ne_eq, false_and, exists_prop, true_and, false_or]
by_cases hw : ⟨j, m₁⟩ ∈ w.toList.tail
· simp [hw, show m₁ ≠ 1 from w.ne_one _ (List.mem_of_mem_tail hw)]
· simp only [hw, false_or, Option.mem_def, ne_eq, and_congr_right_iff]
intro hm1
split_ifs with h
· rcases h with ⟨hnil, rfl⟩
simp only [List.head?_eq_head hnil, Option.some.injEq, ne_eq]
constructor
· rintro rfl
exact Or.inl ⟨_, rfl, rfl⟩
· rintro (⟨_, h, rfl⟩ | hm')
· simp only [Sigma.ext_iff, heq_eq_eq, true_and] at h
subst h
rfl
· simp only [fstIdx, Option.map_eq_some_iff, Sigma.exists,
exists_and_right, exists_eq_right, not_exists, ne_eq] at hm'
exact (hm'.1 (w.toList.head hnil).2 (by rw [List.head?_eq_head])).elim
· revert h
rw [fstIdx]
cases w.toList
· simp
· simp +contextual [Sigma.ext_iff]
· rcases w with ⟨_ | _, _, _⟩ <;>
simp [or_comm, hij, Ne.symm hij]; rw [eq_comm]
theorem mem_smul_iff_of_ne {i j : ι} (hij : i ≠ j) {m₁ : M i} {m₂ : M j} {w : Word M} :
⟨_, m₁⟩ ∈ (of m₂ • w).toList ↔ ⟨i, m₁⟩ ∈ w.toList := by
simp [mem_smul_iff, *]
theorem cons_eq_smul {i} {m : M i} {ls h1 h2} :
cons m ls h1 h2 = of m • ls := by
rw [of_smul_def, equivPair_eq_of_fstIdx_ne _]
· simp [cons, rcons, h2]
· exact h1
theorem rcons_eq_smul {i} (p : Pair M i) :
rcons p = of p.head • p.tail := by
simp [of_smul_def]
@[simp]
theorem equivPair_head_smul_equivPair_tail {i : ι} (w : Word M) :
of (equivPair i w).head • (equivPair i w).tail = w := by
rw [← rcons_eq_smul, ← equivPair_symm, Equiv.symm_apply_apply]
theorem equivPair_tail_eq_inv_smul {G : ι → Type*} [∀ i, Group (G i)]
[∀ i, DecidableEq (G i)] {i} (w : Word G) :
(equivPair i w).tail = (of (equivPair i w).head)⁻¹ • w :=
Eq.symm <| inv_smul_eq_iff.2 (equivPair_head_smul_equivPair_tail w).symm
@[elab_as_elim]
theorem smul_induction {motive : Word M → Prop} (empty : motive empty)
(smul : ∀ (i) (m : M i) (w), motive w → motive (of m • w)) (w : Word M) : motive w := by
induction w using consRecOn with
| empty => exact empty
| cons _ _ _ _ _ ih =>
rw [cons_eq_smul]
exact smul _ _ _ ih
@[simp]
theorem prod_smul (m) : ∀ w : Word M, prod (m • w) = m * prod w := by
induction m using CoprodI.induction_on with
| one =>
intro
| rw [one_smul, one_mul]
| of _ =>
intros
rw [of_smul_def, prod_rcons, of.map_mul, mul_assoc, ← prod_rcons, ← equivPair_symm,
Equiv.symm_apply_apply]
| Mathlib/GroupTheory/CoprodI.lean | 588 | 592 |
/-
Copyright (c) 2023 Alex Keizer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Keizer
-/
import Mathlib.Data.Vector.Basic
/-!
This file establishes a `snoc : Vector α n → α → Vector α (n+1)` operation, that appends a single
element to the back of a vector.
It provides a collection of lemmas that show how different `Vector` operations reduce when their
argument is `snoc xs x`.
Also, an alternative, reverse, induction principle is added, that breaks down a vector into
`snoc xs x` for its inductive case. Effectively doing induction from right-to-left
-/
namespace List
namespace Vector
variable {α β σ φ : Type*} {n : ℕ} {x : α} {s : σ} (xs : Vector α n)
/-- Append a single element to the end of a vector -/
def snoc : Vector α n → α → Vector α (n+1) :=
fun xs x => append xs (x ::ᵥ Vector.nil)
/-! ## Simplification lemmas -/
section Simp
variable {y : α}
@[simp]
theorem snoc_cons : (x ::ᵥ xs).snoc y = x ::ᵥ (xs.snoc y) :=
rfl
@[simp]
theorem snoc_nil : (nil.snoc x) = x ::ᵥ nil :=
rfl
@[simp]
theorem reverse_cons : reverse (x ::ᵥ xs) = (reverse xs).snoc x := by
cases xs
simp only [reverse, cons, toList_mk, List.reverse_cons, snoc]
congr
@[simp]
theorem reverse_snoc : reverse (xs.snoc x) = x ::ᵥ (reverse xs) := by
cases xs
simp only [reverse, snoc, cons, toList_mk]
congr
simp [toList, Vector.append, Append.append]
theorem replicate_succ_to_snoc (val : α) :
replicate (n+1) val = (replicate n val).snoc val := by
induction n with
| zero => rfl
| succ n ih =>
rw [replicate_succ]
conv => rhs; rw [replicate_succ]
rw [snoc_cons, ih]
end Simp
/-! ## Reverse induction principle -/
section Induction
/-- Define `C v` by *reverse* induction on `v : Vector α n`.
That is, break the vector down starting from the right-most element, using `snoc`
This function has two arguments: `nil` handles the base case on `C nil`,
and `snoc` defines the inductive step using `∀ x : α, C xs → C (xs.snoc x)`.
This can be used as `induction v using Vector.revInductionOn`. -/
@[elab_as_elim]
def revInductionOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (x : α), C xs → C (xs.snoc x)) :
C v :=
cast (by simp) <| inductionOn
(C := fun v => C v.reverse)
v.reverse
nil
(@fun n x xs (r : C xs.reverse) => cast (by simp) <| snoc xs.reverse x r)
/-- Define `C v w` by *reverse* induction on a pair of vectors `v : Vector α n` and
`w : Vector β n`. -/
@[elab_as_elim]
def revInductionOn₂ {C : ∀ {n : ℕ}, Vector α n → Vector β n → Sort*} {n : ℕ}
(v : Vector α n) (w : Vector β n)
(nil : C nil nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (ys : Vector β n) (x : α) (y : β),
C xs ys → C (xs.snoc x) (ys.snoc y)) :
C v w :=
cast (by simp) <| inductionOn₂
(C := fun v w => C v.reverse w.reverse)
v.reverse
w.reverse
nil
(@fun n x y xs ys (r : C xs.reverse ys.reverse) =>
cast (by simp) <| snoc xs.reverse ys.reverse x y r)
/-- Define `C v` by *reverse* case analysis, i.e. by handling the cases `nil` and `xs.snoc x`
separately -/
@[elab_as_elim]
def revCasesOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (x : α), C (xs.snoc x)) :
C v :=
revInductionOn v nil fun xs x _ => snoc xs x
end Induction
/-! ## More simplification lemmas -/
section Simp
@[simp]
theorem map_snoc {f : α → β} : map f (xs.snoc x) = (map f xs).snoc (f x) := by
induction xs <;> simp_all
@[simp]
theorem mapAccumr_nil {f : α → σ → σ × β} {s : σ} : mapAccumr f Vector.nil s = (s, Vector.nil) :=
rfl
@[simp]
theorem mapAccumr_snoc {f : α → σ → σ × β} {s : σ} :
mapAccumr f (xs.snoc x) s
= let q := f x s
let r := mapAccumr f xs q.1
(r.1, r.2.snoc q.2) := by
induction xs
· rfl
· simp [*]
variable (ys : Vector β n)
@[simp]
theorem map₂_snoc {f : α → β → σ} {y : β} :
map₂ f (xs.snoc x) (ys.snoc y) = (map₂ f xs ys).snoc (f x y) := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all
| @[simp]
theorem mapAccumr₂_nil {f : α → β → σ → σ × φ} :
| Mathlib/Data/Vector/Snoc.lean | 146 | 147 |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Pointwise
import Mathlib.Analysis.NormedSpace.Real
/-!
# Properties of pointwise scalar multiplication of sets in normed spaces.
We explore the relationships between scalar multiplication of sets in vector spaces, and the norm.
Notably, we express arbitrary balls as rescaling of other balls, and we show that the
multiplication of bounded sets remain bounded.
-/
open Metric Set
open Pointwise Topology
variable {𝕜 E : Type*}
section SMulZeroClass
variable [SeminormedAddCommGroup 𝕜] [SeminormedAddCommGroup E]
variable [SMulZeroClass 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem ediam_smul_le (c : 𝕜) (s : Set E) : EMetric.diam (c • s) ≤ ‖c‖₊ • EMetric.diam s :=
(lipschitzWith_smul c).ediam_image_le s
end SMulZeroClass
section DivisionRing
variable [NormedDivisionRing 𝕜] [SeminormedAddCommGroup E]
variable [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem ediam_smul₀ (c : 𝕜) (s : Set E) : EMetric.diam (c • s) = ‖c‖₊ • EMetric.diam s := by
refine le_antisymm (ediam_smul_le c s) ?_
obtain rfl | hc := eq_or_ne c 0
· obtain rfl | hs := s.eq_empty_or_nonempty
· simp
simp [zero_smul_set hs, ← Set.singleton_zero]
· have := (lipschitzWith_smul c⁻¹).ediam_image_le (c • s)
rwa [← smul_eq_mul, ← ENNReal.smul_def, Set.image_smul, inv_smul_smul₀ hc s, nnnorm_inv,
le_inv_smul_iff_of_pos (nnnorm_pos.2 hc)] at this
theorem diam_smul₀ (c : 𝕜) (x : Set E) : diam (c • x) = ‖c‖ * diam x := by
simp_rw [diam, ediam_smul₀, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm, smul_eq_mul]
theorem infEdist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) :
EMetric.infEdist (c • x) (c • s) = ‖c‖₊ • EMetric.infEdist x s := by
simp_rw [EMetric.infEdist]
have : Function.Surjective ((c • ·) : E → E) :=
Function.RightInverse.surjective (smul_inv_smul₀ hc)
trans ⨅ (y) (_ : y ∈ s), ‖c‖₊ • edist x y
· refine (this.iInf_congr _ fun y => ?_).symm
simp_rw [smul_mem_smul_set_iff₀ hc, edist_smul₀]
· have : (‖c‖₊ : ENNReal) ≠ 0 := by simp [hc]
simp_rw [ENNReal.smul_def, smul_eq_mul, ENNReal.mul_iInf_of_ne this ENNReal.coe_ne_top]
theorem infDist_smul₀ {c : 𝕜} (hc : c ≠ 0) (s : Set E) (x : E) :
Metric.infDist (c • x) (c • s) = ‖c‖ * Metric.infDist x s := by
simp_rw [Metric.infDist, infEdist_smul₀ hc s, ENNReal.toReal_smul, NNReal.smul_def, coe_nnnorm,
smul_eq_mul]
end DivisionRing
variable [NormedField 𝕜]
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup E] [NormedSpace 𝕜 E]
theorem smul_ball {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) : c • ball x r = ball (c • x) (‖c‖ * r) := by
ext y
rw [mem_smul_set_iff_inv_smul_mem₀ hc]
conv_lhs => rw [← inv_smul_smul₀ hc x]
simp [← div_eq_inv_mul, div_lt_iff₀ (norm_pos_iff.2 hc), mul_comm _ r, dist_smul₀]
theorem smul_unitBall {c : 𝕜} (hc : c ≠ 0) : c • ball (0 : E) (1 : ℝ) = ball (0 : E) ‖c‖ := by
rw [_root_.smul_ball hc, smul_zero, mul_one]
theorem smul_sphere' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • sphere x r = sphere (c • x) (‖c‖ * r) := by
ext y
rw [mem_smul_set_iff_inv_smul_mem₀ hc]
conv_lhs => rw [← inv_smul_smul₀ hc x]
simp only [mem_sphere, dist_smul₀, norm_inv, ← div_eq_inv_mul, div_eq_iff (norm_pos_iff.2 hc).ne',
mul_comm r]
theorem smul_closedBall' {c : 𝕜} (hc : c ≠ 0) (x : E) (r : ℝ) :
c • closedBall x r = closedBall (c • x) (‖c‖ * r) := by
simp only [← ball_union_sphere, Set.smul_set_union, _root_.smul_ball hc, smul_sphere' hc]
theorem set_smul_sphere_zero {s : Set 𝕜} (hs : 0 ∉ s) (r : ℝ) :
s • sphere (0 : E) r = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) :=
calc
s • sphere (0 : E) r = ⋃ c ∈ s, c • sphere (0 : E) r := iUnion_smul_left_image.symm
_ = ⋃ c ∈ s, sphere (0 : E) (‖c‖ * r) := iUnion₂_congr fun c hc ↦ by
rw [smul_sphere' (ne_of_mem_of_not_mem hc hs), smul_zero]
_ = (‖·‖) ⁻¹' ((‖·‖ * r) '' s) := by ext; simp [eq_comm]
/-- Image of a bounded set in a normed space under scalar multiplication by a constant is
bounded. See also `Bornology.IsBounded.smul` for a similar lemma about an isometric action. -/
theorem Bornology.IsBounded.smul₀ {s : Set E} (hs : IsBounded s) (c : 𝕜) : IsBounded (c • s) :=
(lipschitzWith_smul c).isBounded_image hs
/-- If `s` is a bounded set, then for small enough `r`, the set `{x} + r • s` is contained in any
fixed neighborhood of `x`. -/
theorem eventually_singleton_add_smul_subset {x : E} {s : Set E} (hs : Bornology.IsBounded s)
{u : Set E} (hu : u ∈ 𝓝 x) : ∀ᶠ r in 𝓝 (0 : 𝕜), {x} + r • s ⊆ u := by
obtain ⟨ε, εpos, hε⟩ : ∃ ε : ℝ, 0 < ε ∧ closedBall x ε ⊆ u := nhds_basis_closedBall.mem_iff.1 hu
obtain ⟨R, Rpos, hR⟩ : ∃ R : ℝ, 0 < R ∧ s ⊆ closedBall 0 R := hs.subset_closedBall_lt 0 0
have : Metric.closedBall (0 : 𝕜) (ε / R) ∈ 𝓝 (0 : 𝕜) := closedBall_mem_nhds _ (div_pos εpos Rpos)
filter_upwards [this] with r hr
simp only [image_add_left, singleton_add]
intro y hy
obtain ⟨z, zs, hz⟩ : ∃ z : E, z ∈ s ∧ r • z = -x + y := by simpa [mem_smul_set] using hy
have I : ‖r • z‖ ≤ ε :=
calc
‖r • z‖ = ‖r‖ * ‖z‖ := norm_smul _ _
_ ≤ ε / R * R :=
(mul_le_mul (mem_closedBall_zero_iff.1 hr) (mem_closedBall_zero_iff.1 (hR zs))
(norm_nonneg _) (div_pos εpos Rpos).le)
_ = ε := by field_simp
have : y = x + r • z := by simp only [hz, add_neg_cancel_left]
apply hε
simpa only [this, dist_eq_norm, add_sub_cancel_left, mem_closedBall] using I
variable [NormedSpace ℝ E] {x y z : E} {δ ε : ℝ}
/-- In a real normed space, the image of the unit ball under scalar multiplication by a positive
constant `r` is the ball of radius `r`. -/
theorem smul_unitBall_of_pos {r : ℝ} (hr : 0 < r) : r • ball (0 : E) 1 = ball (0 : E) r := by
rw [smul_unitBall hr.ne', Real.norm_of_nonneg hr.le]
lemma Ioo_smul_sphere_zero {a b r : ℝ} (ha : 0 ≤ a) (hr : 0 < r) :
Ioo a b • sphere (0 : E) r = ball 0 (b * r) \ closedBall 0 (a * r) := by
have : EqOn (‖·‖) id (Ioo a b) := fun x hx ↦ abs_of_pos (ha.trans_lt hx.1)
rw [set_smul_sphere_zero (by simp [ha.not_lt]), ← image_image (· * r), this.image_eq, image_id,
image_mul_right_Ioo _ _ hr]
ext x; simp [and_comm]
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_eq (x z : E) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) :
∃ y, dist x y = b * dist x z ∧ dist y z = a * dist x z := by
use a • x + b • z
nth_rw 1 [← one_smul ℝ x]
nth_rw 4 [← one_smul ℝ z]
simp [dist_eq_norm, ← hab, add_smul, ← smul_sub, norm_smul_of_nonneg, ha, hb]
theorem exists_dist_le_le (hδ : 0 ≤ δ) (hε : 0 ≤ ε) (h : dist x z ≤ ε + δ) :
∃ y, dist x y ≤ δ ∧ dist y z ≤ ε := by
obtain rfl | hε' := hε.eq_or_lt
· exact ⟨z, by rwa [zero_add] at h, (dist_self _).le⟩
have hεδ := add_pos_of_pos_of_nonneg hε' hδ
refine (exists_dist_eq x z (div_nonneg hε <| add_nonneg hε hδ)
(div_nonneg hδ <| add_nonneg hε hδ) <| by
rw [← add_div, div_self hεδ.ne']).imp
fun y hy => ?_
rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε]
rw [← div_le_one hεδ] at h
exact ⟨mul_le_of_le_one_left hδ h, mul_le_of_le_one_left hε h⟩
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_le_lt (hδ : 0 ≤ δ) (hε : 0 < ε) (h : dist x z < ε + δ) :
∃ y, dist x y ≤ δ ∧ dist y z < ε := by
refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ)
(div_nonneg hδ <| add_nonneg hε.le hδ) <| by
rw [← add_div, div_self (add_pos_of_pos_of_nonneg hε hδ).ne']).imp
fun y hy => ?_
rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε]
rw [← div_lt_one (add_pos_of_pos_of_nonneg hε hδ)] at h
exact ⟨mul_le_of_le_one_left hδ h.le, mul_lt_of_lt_one_left hε h⟩
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_lt_le (hδ : 0 < δ) (hε : 0 ≤ ε) (h : dist x z < ε + δ) :
∃ y, dist x y < δ ∧ dist y z ≤ ε := by
obtain ⟨y, yz, xy⟩ :=
exists_dist_le_lt hε hδ (show dist z x < δ + ε by simpa only [dist_comm, add_comm] using h)
exact ⟨y, by simp [dist_comm x y, dist_comm y z, *]⟩
-- This is also true for `ℚ`-normed spaces
theorem exists_dist_lt_lt (hδ : 0 < δ) (hε : 0 < ε) (h : dist x z < ε + δ) :
∃ y, dist x y < δ ∧ dist y z < ε := by
refine (exists_dist_eq x z (div_nonneg hε.le <| add_nonneg hε.le hδ.le)
(div_nonneg hδ.le <| add_nonneg hε.le hδ.le) <| by
rw [← add_div, div_self (add_pos hε hδ).ne']).imp
fun y hy => ?_
rw [hy.1, hy.2, div_mul_comm, div_mul_comm ε]
rw [← div_lt_one (add_pos hε hδ)] at h
exact ⟨mul_lt_of_lt_one_left hδ h, mul_lt_of_lt_one_left hε h⟩
| -- This is also true for `ℚ`-normed spaces
theorem disjoint_ball_ball_iff (hδ : 0 < δ) (hε : 0 < ε) :
Disjoint (ball x δ) (ball y ε) ↔ δ + ε ≤ dist x y := by
refine ⟨fun h => le_of_not_lt fun hxy => ?_, ball_disjoint_ball⟩
rw [add_comm] at hxy
| Mathlib/Analysis/NormedSpace/Pointwise.lean | 197 | 201 |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
-/
import Mathlib.Data.Finset.Basic
import Mathlib.Data.Finset.Image
/-!
# Cardinality of a finite set
This defines the cardinality of a `Finset` and provides induction principles for finsets.
## Main declarations
* `Finset.card`: `#s : ℕ` returns the cardinality of `s : Finset α`.
### Induction principles
* `Finset.strongInduction`: Strong induction
* `Finset.strongInductionOn`
* `Finset.strongDownwardInduction`
* `Finset.strongDownwardInductionOn`
* `Finset.case_strong_induction_on`
* `Finset.Nonempty.strong_induction`
-/
assert_not_exists Monoid
open Function Multiset Nat
variable {α β R : Type*}
namespace Finset
variable {s t : Finset α} {a b : α}
/-- `s.card` is the number of elements of `s`, aka its cardinality.
The notation `#s` can be accessed in the `Finset` locale. -/
def card (s : Finset α) : ℕ :=
Multiset.card s.1
@[inherit_doc] scoped prefix:arg "#" => Finset.card
theorem card_def (s : Finset α) : #s = Multiset.card s.1 :=
rfl
@[simp] lemma card_val (s : Finset α) : Multiset.card s.1 = #s := rfl
@[simp]
theorem card_mk {m nodup} : #(⟨m, nodup⟩ : Finset α) = Multiset.card m :=
rfl
@[simp]
theorem card_empty : #(∅ : Finset α) = 0 :=
rfl
@[gcongr]
theorem card_le_card : s ⊆ t → #s ≤ #t :=
Multiset.card_le_card ∘ val_le_iff.mpr
@[mono]
theorem card_mono : Monotone (@card α) := by apply card_le_card
@[simp] lemma card_eq_zero : #s = 0 ↔ s = ∅ := Multiset.card_eq_zero.trans val_eq_zero
lemma card_ne_zero : #s ≠ 0 ↔ s.Nonempty := card_eq_zero.ne.trans nonempty_iff_ne_empty.symm
@[simp] lemma card_pos : 0 < #s ↔ s.Nonempty := Nat.pos_iff_ne_zero.trans card_ne_zero
@[simp] lemma one_le_card : 1 ≤ #s ↔ s.Nonempty := card_pos
alias ⟨_, Nonempty.card_pos⟩ := card_pos
alias ⟨_, Nonempty.card_ne_zero⟩ := card_ne_zero
theorem card_ne_zero_of_mem (h : a ∈ s) : #s ≠ 0 :=
(not_congr card_eq_zero).2 <| ne_empty_of_mem h
@[simp]
theorem card_singleton (a : α) : #{a} = 1 :=
Multiset.card_singleton _
theorem card_singleton_inter [DecidableEq α] : #({a} ∩ s) ≤ 1 := by
obtain h | h := Finset.decidableMem a s
· simp [Finset.singleton_inter_of_not_mem h]
· simp [Finset.singleton_inter_of_mem h]
@[simp]
theorem card_cons (h : a ∉ s) : #(s.cons a h) = #s + 1 :=
Multiset.card_cons _ _
section InsertErase
variable [DecidableEq α]
@[simp]
theorem card_insert_of_not_mem (h : a ∉ s) : #(insert a s) = #s + 1 := by
rw [← cons_eq_insert _ _ h, card_cons]
theorem card_insert_of_mem (h : a ∈ s) : #(insert a s) = #s := by rw [insert_eq_of_mem h]
theorem card_insert_le (a : α) (s : Finset α) : #(insert a s) ≤ #s + 1 := by
by_cases h : a ∈ s
· rw [insert_eq_of_mem h]
exact Nat.le_succ _
· rw [card_insert_of_not_mem h]
section
variable {a b c d e f : α}
theorem card_le_two : #{a, b} ≤ 2 := card_insert_le _ _
theorem card_le_three : #{a, b, c} ≤ 3 :=
(card_insert_le _ _).trans (Nat.succ_le_succ card_le_two)
theorem card_le_four : #{a, b, c, d} ≤ 4 :=
(card_insert_le _ _).trans (Nat.succ_le_succ card_le_three)
theorem card_le_five : #{a, b, c, d, e} ≤ 5 :=
(card_insert_le _ _).trans (Nat.succ_le_succ card_le_four)
theorem card_le_six : #{a, b, c, d, e, f} ≤ 6 :=
(card_insert_le _ _).trans (Nat.succ_le_succ card_le_five)
end
/-- If `a ∈ s` is known, see also `Finset.card_insert_of_mem` and `Finset.card_insert_of_not_mem`.
-/
theorem card_insert_eq_ite : #(insert a s) = if a ∈ s then #s else #s + 1 := by
by_cases h : a ∈ s
· rw [card_insert_of_mem h, if_pos h]
· rw [card_insert_of_not_mem h, if_neg h]
@[simp]
theorem card_pair_eq_one_or_two : #{a, b} = 1 ∨ #{a, b} = 2 := by
simp [card_insert_eq_ite]
tauto
@[simp]
theorem card_pair (h : a ≠ b) : #{a, b} = 2 := by
rw [card_insert_of_not_mem (not_mem_singleton.2 h), card_singleton]
/-- $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. -/
@[simp]
theorem card_erase_of_mem : a ∈ s → #(s.erase a) = #s - 1 :=
Multiset.card_erase_of_mem
@[simp]
theorem card_erase_add_one : a ∈ s → #(s.erase a) + 1 = #s :=
Multiset.card_erase_add_one
theorem card_erase_lt_of_mem : a ∈ s → #(s.erase a) < #s :=
Multiset.card_erase_lt_of_mem
theorem card_erase_le : #(s.erase a) ≤ #s :=
Multiset.card_erase_le
theorem pred_card_le_card_erase : #s - 1 ≤ #(s.erase a) := by
by_cases h : a ∈ s
· exact (card_erase_of_mem h).ge
· rw [erase_eq_of_not_mem h]
exact Nat.sub_le _ _
/-- If `a ∈ s` is known, see also `Finset.card_erase_of_mem` and `Finset.erase_eq_of_not_mem`. -/
theorem card_erase_eq_ite : #(s.erase a) = if a ∈ s then #s - 1 else #s :=
Multiset.card_erase_eq_ite
end InsertErase
@[simp]
theorem card_range (n : ℕ) : #(range n) = n :=
Multiset.card_range n
@[simp]
theorem card_attach : #s.attach = #s :=
Multiset.card_attach
end Finset
open scoped Finset
section ToMLListultiset
variable [DecidableEq α] (m : Multiset α) (l : List α)
theorem Multiset.card_toFinset : #m.toFinset = Multiset.card m.dedup :=
rfl
theorem Multiset.toFinset_card_le : #m.toFinset ≤ Multiset.card m :=
card_le_card <| dedup_le _
theorem Multiset.toFinset_card_of_nodup {m : Multiset α} (h : m.Nodup) :
#m.toFinset = Multiset.card m :=
congr_arg card <| Multiset.dedup_eq_self.mpr h
theorem Multiset.dedup_card_eq_card_iff_nodup {m : Multiset α} :
card m.dedup = card m ↔ m.Nodup :=
.trans ⟨fun h ↦ eq_of_le_of_card_le (dedup_le m) h.ge, congr_arg _⟩ dedup_eq_self
theorem Multiset.toFinset_card_eq_card_iff_nodup {m : Multiset α} :
#m.toFinset = card m ↔ m.Nodup := dedup_card_eq_card_iff_nodup
theorem List.card_toFinset : #l.toFinset = l.dedup.length :=
rfl
theorem List.toFinset_card_le : #l.toFinset ≤ l.length :=
Multiset.toFinset_card_le ⟦l⟧
theorem List.toFinset_card_of_nodup {l : List α} (h : l.Nodup) : #l.toFinset = l.length :=
Multiset.toFinset_card_of_nodup h
end ToMLListultiset
namespace Finset
variable {s t u : Finset α} {f : α → β} {n : ℕ}
@[simp]
theorem length_toList (s : Finset α) : s.toList.length = #s := by
rw [toList, ← Multiset.coe_card, Multiset.coe_toList, card_def]
theorem card_image_le [DecidableEq β] : #(s.image f) ≤ #s := by
simpa only [card_map] using (s.1.map f).toFinset_card_le
theorem card_image_of_injOn [DecidableEq β] (H : Set.InjOn f s) : #(s.image f) = #s := by
simp only [card, image_val_of_injOn H, card_map]
theorem injOn_of_card_image_eq [DecidableEq β] (H : #(s.image f) = #s) : Set.InjOn f s := by
rw [card_def, card_def, image, toFinset] at H
dsimp only at H
have : (s.1.map f).dedup = s.1.map f := by
refine Multiset.eq_of_le_of_card_le (Multiset.dedup_le _) ?_
simp only [H, Multiset.card_map, le_rfl]
rw [Multiset.dedup_eq_self] at this
exact inj_on_of_nodup_map this
theorem card_image_iff [DecidableEq β] : #(s.image f) = #s ↔ Set.InjOn f s :=
⟨injOn_of_card_image_eq, card_image_of_injOn⟩
theorem card_image_of_injective [DecidableEq β] (s : Finset α) (H : Injective f) :
#(s.image f) = #s :=
card_image_of_injOn fun _ _ _ _ h => H h
theorem fiber_card_ne_zero_iff_mem_image (s : Finset α) (f : α → β) [DecidableEq β] (y : β) :
#(s.filter fun x ↦ f x = y) ≠ 0 ↔ y ∈ s.image f := by
rw [← Nat.pos_iff_ne_zero, card_pos, fiber_nonempty_iff_mem_image]
lemma card_filter_le_iff (s : Finset α) (P : α → Prop) [DecidablePred P] (n : ℕ) :
#(s.filter P) ≤ n ↔ ∀ s' ⊆ s, n < #s' → ∃ a ∈ s', ¬ P a :=
(s.1.card_filter_le_iff P n).trans ⟨fun H s' hs' h ↦ H s'.1 (by aesop) h,
fun H s' hs' h ↦ H ⟨s', nodup_of_le hs' s.2⟩ (fun _ hx ↦ Multiset.subset_of_le hs' hx) h⟩
@[simp]
theorem card_map (f : α ↪ β) : #(s.map f) = #s :=
Multiset.card_map _ _
@[simp]
theorem card_subtype (p : α → Prop) [DecidablePred p] (s : Finset α) :
#(s.subtype p) = #(s.filter p) := by simp [Finset.subtype]
theorem card_filter_le (s : Finset α) (p : α → Prop) [DecidablePred p] :
#(s.filter p) ≤ #s :=
card_le_card <| filter_subset _ _
theorem eq_of_subset_of_card_le {s t : Finset α} (h : s ⊆ t) (h₂ : #t ≤ #s) : s = t :=
eq_of_veq <| Multiset.eq_of_le_of_card_le (val_le_iff.mpr h) h₂
theorem eq_iff_card_le_of_subset (hst : s ⊆ t) : #t ≤ #s ↔ s = t :=
⟨eq_of_subset_of_card_le hst, (ge_of_eq <| congr_arg _ ·)⟩
theorem eq_of_superset_of_card_ge (hst : s ⊆ t) (hts : #t ≤ #s) : t = s :=
(eq_of_subset_of_card_le hst hts).symm
theorem eq_iff_card_ge_of_superset (hst : s ⊆ t) : #t ≤ #s ↔ t = s :=
(eq_iff_card_le_of_subset hst).trans eq_comm
theorem subset_iff_eq_of_card_le (h : #t ≤ #s) : s ⊆ t ↔ s = t :=
⟨fun hst => eq_of_subset_of_card_le hst h, Eq.subset'⟩
theorem map_eq_of_subset {f : α ↪ α} (hs : s.map f ⊆ s) : s.map f = s :=
eq_of_subset_of_card_le hs (card_map _).ge
theorem card_filter_eq_iff {p : α → Prop} [DecidablePred p] :
#(s.filter p) = #s ↔ ∀ x ∈ s, p x := by
rw [(card_filter_le s p).eq_iff_not_lt, not_lt, eq_iff_card_le_of_subset (filter_subset p s),
filter_eq_self]
alias ⟨filter_card_eq, _⟩ := card_filter_eq_iff
theorem card_filter_eq_zero_iff {p : α → Prop} [DecidablePred p] :
#(s.filter p) = 0 ↔ ∀ x ∈ s, ¬ p x := by
rw [card_eq_zero, filter_eq_empty_iff]
nonrec lemma card_lt_card (h : s ⊂ t) : #s < #t := card_lt_card <| val_lt_iff.2 h
lemma card_strictMono : StrictMono (card : Finset α → ℕ) := fun _ _ ↦ card_lt_card
theorem card_eq_of_bijective (f : ∀ i, i < n → α) (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a)
(hf' : ∀ i (h : i < n), f i h ∈ s)
(f_inj : ∀ i j (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : #s = n := by
classical
have : s = (range n).attach.image fun i => f i.1 (mem_range.1 i.2) := by
ext a
suffices _ : a ∈ s ↔ ∃ (i : _) (hi : i ∈ range n), f i (mem_range.1 hi) = a by
simpa only [mem_image, mem_attach, true_and, Subtype.exists]
constructor
· intro ha; obtain ⟨i, hi, rfl⟩ := hf a ha; use i, mem_range.2 hi
· rintro ⟨i, hi, rfl⟩; apply hf'
calc
#s = #((range n).attach.image fun i => f i.1 (mem_range.1 i.2)) := by rw [this]
_ = #(range n).attach := ?_
_ = #(range n) := card_attach
_ = n := card_range n
apply card_image_of_injective
intro ⟨i, hi⟩ ⟨j, hj⟩ eq
exact Subtype.eq <| f_inj i j (mem_range.1 hi) (mem_range.1 hj) eq
section bij
variable {t : Finset β}
/-- Reorder a finset.
The difference with `Finset.card_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
The difference with `Finset.card_nbij` is that the bijection is allowed to use membership of the
domain, rather than being a non-dependent function. -/
lemma card_bij (i : ∀ a ∈ s, β) (hi : ∀ a ha, i a ha ∈ t)
(i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) : #s = #t := by
classical
calc
#s = #s.attach := card_attach.symm
_ = #(s.attach.image fun a ↦ i a.1 a.2) := Eq.symm ?_
_ = #t := ?_
· apply card_image_of_injective
intro ⟨_, _⟩ ⟨_, _⟩ h
simpa using i_inj _ _ _ _ h
· congr 1
ext b
constructor <;> intro h
· obtain ⟨_, _, rfl⟩ := mem_image.1 h; apply hi
· obtain ⟨a, ha, rfl⟩ := i_surj b h; exact mem_image.2 ⟨⟨a, ha⟩, by simp⟩
/-- Reorder a finset.
The difference with `Finset.card_bij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.card_nbij'` is that the bijection and its inverse are allowed to use
membership of the domains, rather than being non-dependent functions. -/
lemma card_bij' (i : ∀ a ∈ s, β) (j : ∀ a ∈ t, α) (hi : ∀ a ha, i a ha ∈ t)
(hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a)
(right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) : #s = #t := by
refine card_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩)
rw [← left_inv a1 h1, ← left_inv a2 h2]
simp only [eq]
/-- Reorder a finset.
The difference with `Finset.card_nbij'` is that the bijection is specified as a surjective
injection, rather than by an inverse function.
The difference with `Finset.card_bij` is that the bijection is a non-dependent function, rather than
being allowed to use membership of the domain. -/
lemma card_nbij (i : α → β) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set α).InjOn i)
(i_surj : (s : Set α).SurjOn i t) : #s = #t :=
card_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj)
/-- Reorder a finset.
The difference with `Finset.card_nbij` is that the bijection is specified with an inverse, rather
than as a surjective injection.
The difference with `Finset.card_bij'` is that the bijection and its inverse are non-dependent
functions, rather than being allowed to use membership of the domains.
The difference with `Finset.card_equiv` is that bijectivity is only required to hold on the domains,
rather than on the entire types. -/
lemma card_nbij' (i : α → β) (j : β → α) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s)
(left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a) : #s = #t :=
card_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv
/-- Specialization of `Finset.card_nbij'` that automatically fills in most arguments.
See `Fintype.card_equiv` for the version where `s` and `t` are `univ`. -/
lemma card_equiv (e : α ≃ β) (hst : ∀ i, i ∈ s ↔ e i ∈ t) : #s = #t := by
refine card_nbij' e e.symm ?_ ?_ ?_ ?_ <;> simp [hst]
/-- Specialization of `Finset.card_nbij` that automatically fills in most arguments.
See `Fintype.card_bijective` for the version where `s` and `t` are `univ`. -/
lemma card_bijective (e : α → β) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t) :
#s = #t := card_equiv (.ofBijective e he) hst
lemma card_le_card_of_injOn (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : (s : Set α).InjOn f) :
#s ≤ #t := by
classical
calc
#s = #(s.image f) := (card_image_of_injOn f_inj).symm
_ ≤ #t := card_le_card <| image_subset_iff.2 hf
lemma card_le_card_of_injective {f : s → t} (hf : f.Injective) : #s ≤ #t := by
rcases s.eq_empty_or_nonempty with rfl | ⟨a₀, ha₀⟩
· simp
· classical
let f' : α → β := fun a => f (if ha : a ∈ s then ⟨a, ha⟩ else ⟨a₀, ha₀⟩)
apply card_le_card_of_injOn f'
· aesop
· intro a₁ ha₁ a₂ ha₂ haa
rw [mem_coe] at ha₁ ha₂
simp only [f', ha₁, ha₂, ← Subtype.ext_iff] at haa
exact Subtype.ext_iff.mp (hf haa)
lemma card_le_card_of_surjOn (f : α → β) (hf : Set.SurjOn f s t) : #t ≤ #s := by
classical unfold Set.SurjOn at hf; exact (card_le_card (mod_cast hf)).trans card_image_le
/-- If there are more pigeons than pigeonholes, then there are two pigeons in the same pigeonhole.
-/
theorem exists_ne_map_eq_of_card_lt_of_maps_to {t : Finset β} (hc : #t < #s) {f : α → β}
(hf : ∀ a ∈ s, f a ∈ t) : ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ f x = f y := by
classical
by_contra! hz
refine hc.not_le (card_le_card_of_injOn f hf ?_)
intro x hx y hy
contrapose
exact hz x hx y hy
lemma le_card_of_inj_on_range (f : ℕ → α) (hf : ∀ i < n, f i ∈ s)
(f_inj : ∀ i < n, ∀ j < n, f i = f j → i = j) : n ≤ #s :=
calc
n = #(range n) := (card_range n).symm
_ ≤ #s := card_le_card_of_injOn f (by simpa only [mem_range]) (by simpa)
lemma surjOn_of_injOn_of_card_le (f : α → β) (hf : Set.MapsTo f s t) (hinj : Set.InjOn f s)
(hst : #t ≤ #s) : Set.SurjOn f s t := by
classical
suffices s.image f = t by simp [← this, Set.SurjOn]
have : s.image f ⊆ t := by aesop (add simp Finset.subset_iff)
exact eq_of_subset_of_card_le this (hst.trans_eq (card_image_of_injOn hinj).symm)
lemma surj_on_of_inj_on_of_card_le (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hinj : ∀ a₁ a₂ ha₁ ha₂, f a₁ ha₁ = f a₂ ha₂ → a₁ = a₂) (hst : #t ≤ #s) :
∀ b ∈ t, ∃ a ha, b = f a ha := by
let f' : s → β := fun a ↦ f a a.2
have hinj' : Set.InjOn f' s.attach := fun x hx y hy hxy ↦ Subtype.ext (hinj _ _ x.2 y.2 hxy)
have hmapsto' : Set.MapsTo f' s.attach t := fun x hx ↦ hf _ _
intro b hb
obtain ⟨a, ha, rfl⟩ := surjOn_of_injOn_of_card_le _ hmapsto' hinj' (by rwa [card_attach]) hb
exact ⟨a, a.2, rfl⟩
lemma injOn_of_surjOn_of_card_le (f : α → β) (hf : Set.MapsTo f s t) (hsurj : Set.SurjOn f s t)
(hst : #s ≤ #t) : Set.InjOn f s := by
classical
have : s.image f = t := Finset.coe_injective <| by simp [hsurj.image_eq_of_mapsTo hf]
have : #(s.image f) = #t := by rw [this]
have : #(s.image f) ≤ #s := card_image_le
rw [← card_image_iff]
omega
theorem inj_on_of_surj_on_of_card_le (f : ∀ a ∈ s, β) (hf : ∀ a ha, f a ha ∈ t)
(hsurj : ∀ b ∈ t, ∃ a ha, f a ha = b) (hst : #s ≤ #t) ⦃a₁⦄ (ha₁ : a₁ ∈ s) ⦃a₂⦄
(ha₂ : a₂ ∈ s) (ha₁a₂ : f a₁ ha₁ = f a₂ ha₂) : a₁ = a₂ := by
let f' : s → β := fun a ↦ f a a.2
have hsurj' : Set.SurjOn f' s.attach t := fun x hx ↦ by simpa [f'] using hsurj x hx
have hinj' := injOn_of_surjOn_of_card_le f' (fun x hx ↦ hf _ _) hsurj' (by simpa)
exact congrArg Subtype.val (@hinj' ⟨a₁, ha₁⟩ (by simp) ⟨a₂, ha₂⟩ (by simp) ha₁a₂)
end bij
@[simp]
theorem card_disjUnion (s t : Finset α) (h) : #(s.disjUnion t h) = #s + #t :=
Multiset.card_add _ _
/-! ### Lattice structure -/
section Lattice
variable [DecidableEq α]
theorem card_union_add_card_inter (s t : Finset α) :
#(s ∪ t) + #(s ∩ t) = #s + #t :=
Finset.induction_on t (by simp) fun a r har h => by by_cases a ∈ s <;>
simp [*, ← Nat.add_assoc, Nat.add_right_comm _ 1]
theorem card_inter_add_card_union (s t : Finset α) :
#(s ∩ t) + #(s ∪ t) = #s + #t := by rw [Nat.add_comm, card_union_add_card_inter]
lemma card_union (s t : Finset α) : #(s ∪ t) = #s + #t - #(s ∩ t) := by
rw [← card_union_add_card_inter, Nat.add_sub_cancel]
lemma card_inter (s t : Finset α) : #(s ∩ t) = #s + #t - #(s ∪ t) := by
rw [← card_inter_add_card_union, Nat.add_sub_cancel]
theorem card_union_le (s t : Finset α) : #(s ∪ t) ≤ #s + #t :=
card_union_add_card_inter s t ▸ Nat.le_add_right _ _
lemma card_union_eq_card_add_card : #(s ∪ t) = #s + #t ↔ Disjoint s t := by
rw [← card_union_add_card_inter]; simp [disjoint_iff_inter_eq_empty]
@[simp] alias ⟨_, card_union_of_disjoint⟩ := card_union_eq_card_add_card
theorem card_sdiff (h : s ⊆ t) : #(t \ s) = #t - #s := by
suffices #(t \ s) = #(t \ s ∪ s) - #s by rwa [sdiff_union_of_subset h] at this
rw [card_union_of_disjoint sdiff_disjoint, Nat.add_sub_cancel_right]
theorem card_sdiff_add_card_eq_card {s t : Finset α} (h : s ⊆ t) : #(t \ s) + #s = #t :=
((Nat.sub_eq_iff_eq_add (card_le_card h)).mp (card_sdiff h).symm).symm
theorem le_card_sdiff (s t : Finset α) : #t - #s ≤ #(t \ s) :=
calc
#t - #s ≤ #t - #(s ∩ t) :=
Nat.sub_le_sub_left (card_le_card inter_subset_left) _
_ = #(t \ (s ∩ t)) := (card_sdiff inter_subset_right).symm
_ ≤ #(t \ s) := by rw [sdiff_inter_self_right t s]
theorem card_le_card_sdiff_add_card : #s ≤ #(s \ t) + #t :=
Nat.sub_le_iff_le_add.1 <| le_card_sdiff _ _
theorem card_sdiff_add_card (s t : Finset α) : #(s \ t) + #t = #(s ∪ t) := by
rw [← card_union_of_disjoint sdiff_disjoint, sdiff_union_self_eq_union]
lemma card_sdiff_comm (h : #s = #t) : #(s \ t) = #(t \ s) :=
Nat.add_right_cancel (m := #t) <| by
simp_rw [card_sdiff_add_card, ← h, card_sdiff_add_card, union_comm]
theorem sdiff_nonempty_of_card_lt_card (h : #s < #t) : (t \ s).Nonempty := by
rw [nonempty_iff_ne_empty, Ne, sdiff_eq_empty_iff_subset]
exact fun h' ↦ h.not_le (card_le_card h')
omit [DecidableEq α] in
theorem exists_mem_not_mem_of_card_lt_card (h : #s < #t) : ∃ e, e ∈ t ∧ e ∉ s := by
classical simpa [Finset.Nonempty] using sdiff_nonempty_of_card_lt_card h
@[simp]
lemma card_sdiff_add_card_inter (s t : Finset α) :
#(s \ t) + #(s ∩ t) = #s := by
rw [← card_union_of_disjoint (disjoint_sdiff_inter _ _), sdiff_union_inter]
@[simp]
lemma card_inter_add_card_sdiff (s t : Finset α) :
#(s ∩ t) + #(s \ t) = #s := by
rw [Nat.add_comm, card_sdiff_add_card_inter]
/-- **Pigeonhole principle** for two finsets inside an ambient finset. -/
theorem inter_nonempty_of_card_lt_card_add_card (hts : t ⊆ s) (hus : u ⊆ s)
(hstu : #s < #t + #u) : (t ∩ u).Nonempty := by
contrapose! hstu
calc
_ = #(t ∪ u) := by simp [← card_union_add_card_inter, not_nonempty_iff_eq_empty.1 hstu]
_ ≤ #s := by gcongr; exact union_subset hts hus
end Lattice
theorem filter_card_add_filter_neg_card_eq_card
(p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] :
#(s.filter p) + #(s.filter fun a ↦ ¬ p a) = #s := by
classical
rw [← card_union_of_disjoint (disjoint_filter_filter_neg _ _ _), filter_union_filter_neg_eq]
/-- Given a subset `s` of a set `t`, of sizes at most and at least `n` respectively, there exists a
set `u` of size `n` which is both a superset of `s` and a subset of `t`. -/
lemma exists_subsuperset_card_eq (hst : s ⊆ t) (hsn : #s ≤ n) (hnt : n ≤ #t) :
∃ u, s ⊆ u ∧ u ⊆ t ∧ #u = n := by
classical
refine Nat.decreasingInduction' ?_ hnt ⟨t, by simp [hst]⟩
intro k _ hnk ⟨u, hu₁, hu₂, hu₃⟩
obtain ⟨a, ha⟩ : (u \ s).Nonempty := by rw [← card_pos, card_sdiff hu₁]; omega
simp only [mem_sdiff] at ha
exact ⟨u.erase a, by simp [subset_erase, erase_subset_iff_of_mem (hu₂ _), *]⟩
/-- We can shrink a set to any smaller size. -/
lemma exists_subset_card_eq (hns : n ≤ #s) : ∃ t ⊆ s, #t = n := by
simpa using exists_subsuperset_card_eq s.empty_subset (by simp) hns
theorem le_card_iff_exists_subset_card : n ≤ #s ↔ ∃ t ⊆ s, #t = n := by
refine ⟨fun h => ?_, fun ⟨t, hst, ht⟩ => ht ▸ card_le_card hst⟩
exact exists_subset_card_eq h
theorem exists_subset_or_subset_of_two_mul_lt_card [DecidableEq α] {X Y : Finset α} {n : ℕ}
(hXY : 2 * n < #(X ∪ Y)) : ∃ C : Finset α, n < #C ∧ (C ⊆ X ∨ C ⊆ Y) := by
have h₁ : #(X ∩ (Y \ X)) = 0 := Finset.card_eq_zero.mpr (Finset.inter_sdiff_self X Y)
have h₂ : #(X ∪ Y) = #X + #(Y \ X) := by
rw [← card_union_add_card_inter X (Y \ X), Finset.union_sdiff_self_eq_union, h₁, Nat.add_zero]
rw [h₂, Nat.two_mul] at hXY
obtain h | h : n < #X ∨ n < #(Y \ X) := by contrapose! hXY; omega
· exact ⟨X, h, Or.inl (Finset.Subset.refl X)⟩
· exact ⟨Y \ X, h, Or.inr sdiff_subset⟩
/-! ### Explicit description of a finset from its card -/
|
theorem card_eq_one : #s = 1 ↔ ∃ a, s = {a} := by
| Mathlib/Data/Finset/Card.lean | 590 | 592 |
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.MeasureTheory.Function.SimpleFuncDense
/-!
# Strongly measurable and finitely strongly measurable functions
A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions.
It is said to be finitely strongly measurable with respect to a measure `μ` if the supports
of those simple functions have finite measure.
If the target space has a second countable topology, strongly measurable and measurable are
equivalent.
If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent.
The main property of finitely strongly measurable functions is
`FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the
function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some
results for those functions as if the measure was sigma-finite.
We provide a solid API for strongly measurable functions, as a basis for the Bochner integral.
## Main definitions
* `StronglyMeasurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`.
* `FinStronglyMeasurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`
such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite.
## References
* [Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces.
Springer, 2016.][Hytonen_VanNeerven_Veraar_Wies_2016]
-/
-- Guard against import creep
assert_not_exists InnerProductSpace
open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure
open ENNReal Topology MeasureTheory NNReal
variable {α β γ ι : Type*} [Countable ι]
namespace MeasureTheory
local infixr:25 " →ₛ " => SimpleFunc
section Definitions
variable [TopologicalSpace β]
/-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/
def StronglyMeasurable [MeasurableSpace α] (f : α → β) : Prop :=
∃ fs : ℕ → α →ₛ β, ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))
/-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/
scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m
/-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple
functions with support with finite measure. -/
def FinStronglyMeasurable [Zero β]
{_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop :=
∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))
end Definitions
open MeasureTheory
/-! ## Strongly measurable functions -/
section StronglyMeasurable
variable {_ : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : ℕ → α} {m : ℕ}
variable [TopologicalSpace β]
theorem SimpleFunc.stronglyMeasurable (f : α →ₛ β) : StronglyMeasurable f :=
⟨fun _ => f, fun _ => tendsto_const_nhds⟩
@[simp, nontriviality]
lemma StronglyMeasurable.of_subsingleton_dom [Subsingleton α] : StronglyMeasurable f :=
⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩
@[simp, nontriviality]
lemma StronglyMeasurable.of_subsingleton_cod [Subsingleton β] : StronglyMeasurable f := by
let f_sf : α →ₛ β := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩
· exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩
· simp [Set.preimage, eq_iff_true_of_subsingleton]
@[deprecated StronglyMeasurable.of_subsingleton_cod (since := "2025-04-09")]
lemma Subsingleton.stronglyMeasurable [Subsingleton β] (f : α → β) : StronglyMeasurable f :=
.of_subsingleton_cod
@[deprecated StronglyMeasurable.of_subsingleton_dom (since := "2025-04-09")]
lemma Subsingleton.stronglyMeasurable' [Subsingleton α] (f : α → β) : StronglyMeasurable f :=
.of_subsingleton_dom
theorem stronglyMeasurable_const {b : β} : StronglyMeasurable fun _ : α => b :=
⟨fun _ => SimpleFunc.const α b, fun _ => tendsto_const_nhds⟩
@[to_additive]
theorem stronglyMeasurable_one [One β] : StronglyMeasurable (1 : α → β) := stronglyMeasurable_const
/-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`.
This version works for functions between empty types. -/
theorem stronglyMeasurable_const' (hf : ∀ x y, f x = f y) : StronglyMeasurable f := by
nontriviality α
inhabit α
convert stronglyMeasurable_const (β := β) using 1
exact funext fun x => hf x default
| variable [MeasurableSingletonClass α]
section aux
omit [TopologicalSpace β]
/-- Auxiliary definition for `StronglyMeasurable.of_discrete`. -/
private noncomputable def simpleFuncAux (f : α → β) (g : ℕ → α) : ℕ → SimpleFunc α β
| 0 => .const _ (f (g 0))
| n + 1 => .piecewise {g n} (.singleton _) (.const _ <| f (g n)) (simpleFuncAux f g n)
| Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean | 117 | 125 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.Limits.Filtered
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.CategoryTheory.Discrete.Basic
/-!
# Limits in `C` give colimits in `Cᵒᵖ`.
We also give special cases for (co)products,
(co)equalizers, and pullbacks / pushouts.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
open CategoryTheory
open CategoryTheory.Functor
open Opposite
namespace CategoryTheory.Limits
variable {C : Type u₁} [Category.{v₁} C]
variable {J : Type u₂} [Category.{v₂} J]
/-- Turn a colimit for `F : J ⥤ Cᵒᵖ` into a limit for `F.leftOp : Jᵒᵖ ⥤ C`. -/
@[simps]
def isLimitConeLeftOpOfCocone (F : J ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) :
IsLimit (coneLeftOpOfCocone c) where
lift s := (hc.desc (coconeOfConeLeftOp s)).unop
fac s j :=
Quiver.Hom.op_inj <| by
simp only [coneLeftOpOfCocone_π_app, op_comp, Quiver.Hom.op_unop, IsColimit.fac,
coconeOfConeLeftOp_ι_app, op_unop]
uniq s m w := by
refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_)
simpa only [Quiver.Hom.op_unop, IsColimit.fac, coconeOfConeLeftOp_ι_app] using w (op j)
/-- Turn a limit of `F : J ⥤ Cᵒᵖ` into a colimit of `F.leftOp : Jᵒᵖ ⥤ C`. -/
@[simps]
def isColimitCoconeLeftOpOfCone (F : J ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) :
IsColimit (coconeLeftOpOfCone c) where
desc s := (hc.lift (coneOfCoconeLeftOp s)).unop
fac s j :=
Quiver.Hom.op_inj <| by
simp only [coconeLeftOpOfCone_ι_app, op_comp, Quiver.Hom.op_unop, IsLimit.fac,
coneOfCoconeLeftOp_π_app, op_unop]
uniq s m w := by
refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_)
simpa only [Quiver.Hom.op_unop, IsLimit.fac, coneOfCoconeLeftOp_π_app] using w (op j)
/-- Turn a colimit for `F : Jᵒᵖ ⥤ C` into a limit for `F.rightOp : J ⥤ Cᵒᵖ`. -/
@[simps]
def isLimitConeRightOpOfCocone (F : Jᵒᵖ ⥤ C) {c : Cocone F} (hc : IsColimit c) :
IsLimit (coneRightOpOfCocone c) where
lift s := (hc.desc (coconeOfConeRightOp s)).op
fac s j := Quiver.Hom.unop_inj (by simp)
uniq s m w := by
refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_)
simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (unop j)
/-- Turn a limit for `F : Jᵒᵖ ⥤ C` into a colimit for `F.rightOp : J ⥤ Cᵒᵖ`. -/
@[simps]
def isColimitCoconeRightOpOfCone (F : Jᵒᵖ ⥤ C) {c : Cone F} (hc : IsLimit c) :
IsColimit (coconeRightOpOfCone c) where
desc s := (hc.lift (coneOfCoconeRightOp s)).op
fac s j := Quiver.Hom.unop_inj (by simp)
uniq s m w := by
refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_)
simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (unop j)
/-- Turn a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a limit for `F.unop : J ⥤ C`. -/
@[simps]
def isLimitConeUnopOfCocone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F} (hc : IsColimit c) :
IsLimit (coneUnopOfCocone c) where
lift s := (hc.desc (coconeOfConeUnop s)).unop
fac s j := Quiver.Hom.op_inj (by simp)
uniq s m w := by
refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_)
simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (unop j)
/-- Turn a limit of `F : Jᵒᵖ ⥤ Cᵒᵖ` into a colimit of `F.unop : J ⥤ C`. -/
@[simps]
def isColimitCoconeUnopOfCone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F} (hc : IsLimit c) :
IsColimit (coconeUnopOfCone c) where
desc s := (hc.lift (coneOfCoconeUnop s)).unop
fac s j := Quiver.Hom.op_inj (by simp)
uniq s m w := by
refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_)
simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (unop j)
/-- Turn a colimit for `F.leftOp : Jᵒᵖ ⥤ C` into a limit for `F : J ⥤ Cᵒᵖ`. -/
@[simps]
def isLimitConeOfCoconeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cocone F.leftOp} (hc : IsColimit c) :
IsLimit (coneOfCoconeLeftOp c) where
lift s := (hc.desc (coconeLeftOpOfCone s)).op
fac s j :=
Quiver.Hom.unop_inj <| by
simp only [coneOfCoconeLeftOp_π_app, unop_comp, Quiver.Hom.unop_op, IsColimit.fac,
coconeLeftOpOfCone_ι_app, unop_op]
uniq s m w := by
refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_)
simpa only [Quiver.Hom.unop_op, IsColimit.fac, coneOfCoconeLeftOp_π_app] using w (unop j)
/-- Turn a limit of `F.leftOp : Jᵒᵖ ⥤ C` into a colimit of `F : J ⥤ Cᵒᵖ`. -/
@[simps]
def isColimitCoconeOfConeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cone F.leftOp} (hc : IsLimit c) :
IsColimit (coconeOfConeLeftOp c) where
desc s := (hc.lift (coneLeftOpOfCocone s)).op
fac s j :=
Quiver.Hom.unop_inj <| by
simp only [coconeOfConeLeftOp_ι_app, unop_comp, Quiver.Hom.unop_op, IsLimit.fac,
coneLeftOpOfCocone_π_app, unop_op]
uniq s m w := by
refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_)
simpa only [Quiver.Hom.unop_op, IsLimit.fac, coconeOfConeLeftOp_ι_app] using w (unop j)
/-- Turn a colimit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/
@[simps]
def isLimitConeOfCoconeRightOp (F : Jᵒᵖ ⥤ C) {c : Cocone F.rightOp} (hc : IsColimit c) :
IsLimit (coneOfCoconeRightOp c) where
lift s := (hc.desc (coconeRightOpOfCone s)).unop
fac s j := Quiver.Hom.op_inj (by simp)
uniq s m w := by
refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_)
simpa only [Quiver.Hom.op_unop, IsColimit.fac] using w (op j)
/-- Turn a limit for `F.rightOp : J ⥤ Cᵒᵖ` into a colimit for `F : Jᵒᵖ ⥤ C`. -/
@[simps]
def isColimitCoconeOfConeRightOp (F : Jᵒᵖ ⥤ C) {c : Cone F.rightOp} (hc : IsLimit c) :
IsColimit (coconeOfConeRightOp c) where
desc s := (hc.lift (coneRightOpOfCocone s)).unop
fac s j := Quiver.Hom.op_inj (by simp)
uniq s m w := by
refine Quiver.Hom.op_inj (hc.hom_ext fun j => Quiver.Hom.unop_inj ?_)
simpa only [Quiver.Hom.op_unop, IsLimit.fac] using w (op j)
/-- Turn a colimit for `F.unop : J ⥤ C` into a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/
@[simps]
def isLimitConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F.unop} (hc : IsColimit c) :
IsLimit (coneOfCoconeUnop c) where
lift s := (hc.desc (coconeUnopOfCone s)).op
fac s j := Quiver.Hom.unop_inj (by simp)
uniq s m w := by
refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_)
simpa only [Quiver.Hom.unop_op, IsColimit.fac] using w (op j)
/-- Turn a limit for `F.unop : J ⥤ C` into a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/
@[simps]
def isColimitCoconeOfConeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F.unop} (hc : IsLimit c) :
IsColimit (coconeOfConeUnop c) where
desc s := (hc.lift (coneUnopOfCocone s)).op
fac s j := Quiver.Hom.unop_inj (by simp)
uniq s m w := by
refine Quiver.Hom.unop_inj (hc.hom_ext fun j => Quiver.Hom.op_inj ?_)
simpa only [Quiver.Hom.unop_op, IsLimit.fac] using w (op j)
/-- Turn a limit for `F.leftOp : Jᵒᵖ ⥤ C` into a colimit for `F : J ⥤ Cᵒᵖ`. -/
@[simps!]
def isColimitOfConeLeftOpOfCocone (F : J ⥤ Cᵒᵖ) {c : Cocone F}
(hc : IsLimit (coneLeftOpOfCocone c)) : IsColimit c :=
isColimitCoconeOfConeLeftOp F hc
/-- Turn a colimit for `F.leftOp : Jᵒᵖ ⥤ C` into a limit for `F : J ⥤ Cᵒᵖ`. -/
@[simps!]
def isLimitOfCoconeLeftOpOfCone (F : J ⥤ Cᵒᵖ) {c : Cone F}
(hc : IsColimit (coconeLeftOpOfCone c)) : IsLimit c :=
isLimitConeOfCoconeLeftOp F hc
/-- Turn a limit for `F.rightOp : J ⥤ Cᵒᵖ` into a colimit for `F : Jᵒᵖ ⥤ C`. -/
@[simps!]
def isColimitOfConeRightOpOfCocone (F : Jᵒᵖ ⥤ C) {c : Cocone F}
(hc : IsLimit (coneRightOpOfCocone c)) : IsColimit c :=
isColimitCoconeOfConeRightOp F hc
/-- Turn a colimit for `F.rightOp : J ⥤ Cᵒᵖ` into a limit for `F : Jᵒᵖ ⥤ C`. -/
@[simps!]
def isLimitOfCoconeRightOpOfCone (F : Jᵒᵖ ⥤ C) {c : Cone F}
(hc : IsColimit (coconeRightOpOfCone c)) : IsLimit c :=
isLimitConeOfCoconeRightOp F hc
/-- Turn a limit for `F.unop : J ⥤ C` into a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/
@[simps!]
def isColimitOfConeUnopOfCocone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F}
(hc : IsLimit (coneUnopOfCocone c)) : IsColimit c :=
isColimitCoconeOfConeUnop F hc
/-- Turn a colimit for `F.unop : J ⥤ C` into a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ`. -/
@[simps!]
def isLimitOfCoconeUnopOfCone (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F}
(hc : IsColimit (coconeUnopOfCone c)) : IsLimit c :=
isLimitConeOfCoconeUnop F hc
/-- Turn a limit for `F : J ⥤ Cᵒᵖ` into a colimit for `F.leftOp : Jᵒᵖ ⥤ C`. -/
@[simps!]
def isColimitOfConeOfCoconeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cocone F.leftOp}
(hc : IsLimit (coneOfCoconeLeftOp c)) : IsColimit c :=
isColimitCoconeLeftOpOfCone F hc
/-- Turn a colimit for `F : J ⥤ Cᵒᵖ` into a limit for `F.leftOp : Jᵒᵖ ⥤ C`. -/
@[simps!]
def isLimitOfCoconeOfConeLeftOp (F : J ⥤ Cᵒᵖ) {c : Cone F.leftOp}
(hc : IsColimit (coconeOfConeLeftOp c)) : IsLimit c :=
isLimitConeLeftOpOfCocone F hc
/-- Turn a limit for `F : Jᵒᵖ ⥤ C` into a colimit for `F.rightOp : J ⥤ Cᵒᵖ.` -/
@[simps!]
def isColimitOfConeOfCoconeRightOp (F : Jᵒᵖ ⥤ C) {c : Cocone F.rightOp}
(hc : IsLimit (coneOfCoconeRightOp c)) : IsColimit c :=
isColimitCoconeRightOpOfCone F hc
/-- Turn a colimit for `F : Jᵒᵖ ⥤ C` into a limit for `F.rightOp : J ⥤ Cᵒᵖ`. -/
@[simps!]
def isLimitOfCoconeOfConeRightOp (F : Jᵒᵖ ⥤ C) {c : Cone F.rightOp}
(hc : IsColimit (coconeOfConeRightOp c)) : IsLimit c :=
isLimitConeRightOpOfCocone F hc
/-- Turn a limit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a colimit for `F.unop : J ⥤ C`. -/
@[simps!]
def isColimitOfConeOfCoconeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cocone F.unop}
(hc : IsLimit (coneOfCoconeUnop c)) : IsColimit c :=
isColimitCoconeUnopOfCone F hc
/-- Turn a colimit for `F : Jᵒᵖ ⥤ Cᵒᵖ` into a limit for `F.unop : J ⥤ C`. -/
@[simps!]
def isLimitOfCoconeOfConeUnop (F : Jᵒᵖ ⥤ Cᵒᵖ) {c : Cone F.unop}
(hc : IsColimit (coconeOfConeUnop c)) : IsLimit c :=
isLimitConeUnopOfCocone F hc
@[deprecated (since := "2024-11-01")] alias isColimitConeOfCoconeUnop := isColimitCoconeOfConeUnop
/-- If `F.leftOp : Jᵒᵖ ⥤ C` has a colimit, we can construct a limit for `F : J ⥤ Cᵒᵖ`.
-/
theorem hasLimit_of_hasColimit_leftOp (F : J ⥤ Cᵒᵖ) [HasColimit F.leftOp] : HasLimit F :=
HasLimit.mk
{ cone := coneOfCoconeLeftOp (colimit.cocone F.leftOp)
isLimit := isLimitConeOfCoconeLeftOp _ (colimit.isColimit _) }
theorem hasLimit_of_hasColimit_op (F : J ⥤ C) [HasColimit F.op] : HasLimit F :=
HasLimit.mk
{ cone := (colimit.cocone F.op).unop
isLimit := (colimit.isColimit _).unop }
theorem hasLimit_of_hasColimit_rightOp (F : Jᵒᵖ ⥤ C) [HasColimit F.rightOp] : HasLimit F :=
HasLimit.mk
{ cone := coneOfCoconeRightOp (colimit.cocone F.rightOp)
isLimit := isLimitConeOfCoconeRightOp _ (colimit.isColimit _) }
theorem hasLimit_of_hasColimit_unop (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F.unop] : HasLimit F :=
HasLimit.mk
{ cone := coneOfCoconeUnop (colimit.cocone F.unop)
isLimit := isLimitConeOfCoconeUnop _ (colimit.isColimit _) }
instance hasLimit_op_of_hasColimit (F : J ⥤ C) [HasColimit F] : HasLimit F.op :=
HasLimit.mk
{ cone := (colimit.cocone F).op
isLimit := (colimit.isColimit _).op }
instance hasLimit_leftOp_of_hasColimit (F : J ⥤ Cᵒᵖ) [HasColimit F] : HasLimit F.leftOp :=
HasLimit.mk
{ cone := coneLeftOpOfCocone (colimit.cocone F)
isLimit := isLimitConeLeftOpOfCocone _ (colimit.isColimit _) }
instance hasLimit_rightOp_of_hasColimit (F : Jᵒᵖ ⥤ C) [HasColimit F] : HasLimit F.rightOp :=
HasLimit.mk
{ cone := coneRightOpOfCocone (colimit.cocone F)
isLimit := isLimitConeRightOpOfCocone _ (colimit.isColimit _) }
instance hasLimit_unop_of_hasColimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] : HasLimit F.unop :=
HasLimit.mk
{ cone := coneUnopOfCocone (colimit.cocone F)
isLimit := isLimitConeUnopOfCocone _ (colimit.isColimit _) }
/-- The limit of `F.op` is the opposite of `colimit F`. -/
def limitOpIsoOpColimit (F : J ⥤ C) [HasColimit F] :
limit F.op ≅ op (colimit F) :=
limit.isoLimitCone ⟨_, (colimit.isColimit _).op⟩
@[reassoc (attr := simp)]
lemma limitOpIsoOpColimit_inv_comp_π (F : J ⥤ C) [HasColimit F] (j : Jᵒᵖ) :
(limitOpIsoOpColimit F).inv ≫ limit.π F.op j = (colimit.ι F j.unop).op := by
simp [limitOpIsoOpColimit]
@[reassoc (attr := simp)]
lemma limitOpIsoOpColimit_hom_comp_ι (F : J ⥤ C) [HasColimit F] (j : J) :
(limitOpIsoOpColimit F).hom ≫ (colimit.ι F j).op = limit.π F.op (op j) := by
simp [← Iso.eq_inv_comp]
/-- The limit of `F.leftOp` is the unopposite of `colimit F`. -/
def limitLeftOpIsoUnopColimit (F : J ⥤ Cᵒᵖ) [HasColimit F] :
limit F.leftOp ≅ unop (colimit F) :=
limit.isoLimitCone ⟨_, isLimitConeLeftOpOfCocone _ (colimit.isColimit _)⟩
@[reassoc (attr := simp)]
lemma limitLeftOpIsoUnopColimit_inv_comp_π (F : J ⥤ Cᵒᵖ) [HasColimit F] (j : Jᵒᵖ) :
(limitLeftOpIsoUnopColimit F).inv ≫ limit.π F.leftOp j = (colimit.ι F j.unop).unop := by
simp [limitLeftOpIsoUnopColimit]
@[reassoc (attr := simp)]
lemma limitLeftOpIsoUnopColimit_hom_comp_ι (F : J ⥤ Cᵒᵖ) [HasColimit F] (j : J) :
(limitLeftOpIsoUnopColimit F).hom ≫ (colimit.ι F j).unop = limit.π F.leftOp (op j) := by
simp [← Iso.eq_inv_comp]
/-- The limit of `F.rightOp` is the opposite of `colimit F`. -/
def limitRightOpIsoOpColimit (F : Jᵒᵖ ⥤ C) [HasColimit F] :
limit F.rightOp ≅ op (colimit F) :=
limit.isoLimitCone ⟨_, isLimitConeRightOpOfCocone _ (colimit.isColimit _)⟩
@[reassoc (attr := simp)]
lemma limitRightOpIsoOpColimit_inv_comp_π (F : Jᵒᵖ ⥤ C) [HasColimit F] (j : J) :
(limitRightOpIsoOpColimit F).inv ≫ limit.π F.rightOp j = (colimit.ι F (op j)).op := by
simp [limitRightOpIsoOpColimit]
@[reassoc (attr := simp)]
lemma limitRightOpIsoOpColimit_hom_comp_ι (F : Jᵒᵖ ⥤ C) [HasColimit F] (j : Jᵒᵖ) :
(limitRightOpIsoOpColimit F).hom ≫ (colimit.ι F j).op = limit.π F.rightOp j.unop := by
simp [← Iso.eq_inv_comp]
/-- The limit of `F.unop` is the unopposite of `colimit F`. -/
def limitUnopIsoUnopColimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] :
limit F.unop ≅ unop (colimit F) :=
limit.isoLimitCone ⟨_, isLimitConeUnopOfCocone _ (colimit.isColimit _)⟩
@[reassoc (attr := simp)]
lemma limitUnopIsoUnopColimit_inv_comp_π (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] (j : J) :
(limitUnopIsoUnopColimit F).inv ≫ limit.π F.unop j = (colimit.ι F (op j)).unop := by
simp [limitUnopIsoUnopColimit]
@[reassoc (attr := simp)]
lemma limitUnopIsoUnopColimit_hom_comp_ι (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasColimit F] (j : Jᵒᵖ) :
(limitUnopIsoUnopColimit F).hom ≫ (colimit.ι F j).unop = limit.π F.unop j.unop := by
simp [← Iso.eq_inv_comp]
/-- If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`.
-/
theorem hasLimitsOfShape_op_of_hasColimitsOfShape [HasColimitsOfShape Jᵒᵖ C] :
HasLimitsOfShape J Cᵒᵖ :=
{ has_limit := fun F => hasLimit_of_hasColimit_leftOp F }
theorem hasLimitsOfShape_of_hasColimitsOfShape_op [HasColimitsOfShape Jᵒᵖ Cᵒᵖ] :
HasLimitsOfShape J C :=
{ has_limit := fun F => hasLimit_of_hasColimit_op F }
attribute [local instance] hasLimitsOfShape_op_of_hasColimitsOfShape
/-- If `C` has colimits, we can construct limits for `Cᵒᵖ`.
-/
instance hasLimits_op_of_hasColimits [HasColimitsOfSize.{v₂, u₂} C] :
HasLimitsOfSize.{v₂, u₂} Cᵒᵖ :=
⟨fun _ => inferInstance⟩
theorem hasLimits_of_hasColimits_op [HasColimitsOfSize.{v₂, u₂} Cᵒᵖ] :
HasLimitsOfSize.{v₂, u₂} C :=
{ has_limits_of_shape := fun _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op }
instance has_cofiltered_limits_op_of_has_filtered_colimits [HasFilteredColimitsOfSize.{v₂, u₂} C] :
HasCofilteredLimitsOfSize.{v₂, u₂} Cᵒᵖ where
HasLimitsOfShape _ _ _ := hasLimitsOfShape_op_of_hasColimitsOfShape
theorem has_cofiltered_limits_of_has_filtered_colimits_op [HasFilteredColimitsOfSize.{v₂, u₂} Cᵒᵖ] :
HasCofilteredLimitsOfSize.{v₂, u₂} C :=
{ HasLimitsOfShape := fun _ _ _ => hasLimitsOfShape_of_hasColimitsOfShape_op }
/-- If `F.leftOp : Jᵒᵖ ⥤ C` has a limit, we can construct a colimit for `F : J ⥤ Cᵒᵖ`. -/
theorem hasColimit_of_hasLimit_leftOp (F : J ⥤ Cᵒᵖ) [HasLimit F.leftOp] : HasColimit F :=
HasColimit.mk
{ cocone := coconeOfConeLeftOp (limit.cone F.leftOp)
isColimit := isColimitCoconeOfConeLeftOp _ (limit.isLimit _) }
theorem hasColimit_of_hasLimit_op (F : J ⥤ C) [HasLimit F.op] : HasColimit F :=
HasColimit.mk
{ cocone := (limit.cone F.op).unop
isColimit := (limit.isLimit _).unop }
theorem hasColimit_of_hasLimit_rightOp (F : Jᵒᵖ ⥤ C) [HasLimit F.rightOp] : HasColimit F :=
HasColimit.mk
{ cocone := coconeOfConeRightOp (limit.cone F.rightOp)
isColimit := isColimitCoconeOfConeRightOp _ (limit.isLimit _) }
theorem hasColimit_of_hasLimit_unop (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F.unop] : HasColimit F :=
HasColimit.mk
{ cocone := coconeOfConeUnop (limit.cone F.unop)
isColimit := isColimitCoconeOfConeUnop _ (limit.isLimit _) }
instance hasColimit_op_of_hasLimit (F : J ⥤ C) [HasLimit F] : HasColimit F.op :=
HasColimit.mk
{ cocone := (limit.cone F).op
isColimit := (limit.isLimit _).op }
instance hasColimit_leftOp_of_hasLimit (F : J ⥤ Cᵒᵖ) [HasLimit F] : HasColimit F.leftOp :=
HasColimit.mk
{ cocone := coconeLeftOpOfCone (limit.cone F)
isColimit := isColimitCoconeLeftOpOfCone _ (limit.isLimit _) }
instance hasColimit_rightOp_of_hasLimit (F : Jᵒᵖ ⥤ C) [HasLimit F] : HasColimit F.rightOp :=
| HasColimit.mk
{ cocone := coconeRightOpOfCone (limit.cone F)
isColimit := isColimitCoconeRightOpOfCone _ (limit.isLimit _) }
instance hasColimit_unop_of_hasLimit (F : Jᵒᵖ ⥤ Cᵒᵖ) [HasLimit F] : HasColimit F.unop :=
HasColimit.mk
{ cocone := coconeUnopOfCone (limit.cone F)
isColimit := isColimitCoconeUnopOfCone _ (limit.isLimit _) }
/-- The colimit of `F.op` is the opposite of `limit F`. -/
def colimitOpIsoOpLimit (F : J ⥤ C) [HasLimit F] :
colimit F.op ≅ op (limit F) :=
colimit.isoColimitCocone ⟨_, (limit.isLimit _).op⟩
@[reassoc (attr := simp)]
lemma ι_comp_colimitOpIsoOpLimit_hom (F : J ⥤ C) [HasLimit F] (j : Jᵒᵖ) :
| Mathlib/CategoryTheory/Limits/Opposites.lean | 406 | 421 |
/-
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.Data.ENNReal.Holder
/-!
# Real conjugate exponents
This file defines Hölder triple and Hölder conjugate exponents in `ℝ` and `ℝ≥0`. Real numbers `p`,
`q` and `r` form a *Hölder triple* if `0 < p` and `0 < q` and `p⁻¹ + q⁻¹ = r⁻¹` (which of course
implies `0 < r`). We say `p` and `q` are *Hölder conjugate* if `p`, `q` and `1` are a Hölder triple.
In this case, `1 < p` and `1 < q`. This property shows up often in analysis, especially when dealing
with `L^p` spaces.
These notions mimic the same notions for extended nonnegative reals where `p q r : ℝ≥0∞` are allowed
to take the values `0` and `∞`.
## Main declarations
* `Real.HolderTriple`: Predicate for two real numbers to be a Hölder triple.
* `Real.HolderConjugate`: Predicate for two real numbers to be Hölder conjugate.
* `Real.conjExponent`: Conjugate exponent of a real number.
* `NNReal.HolderTriple`: Predicate for two nonnegative real numbers to be a Hölder triple.
* `NNReal.HolderConjugate`: Predicate for two nonnegative real numbers to be Hölder conjugate.
* `NNReal.conjExponent`: Conjugate exponent of a nonnegative real number.
* `ENNReal.conjExponent`: Conjugate exponent of an extended nonnegative real number.
## TODO
* Eradicate the `1 / p` spelling in lemmas.
-/
noncomputable section
open scoped ENNReal NNReal
namespace Real
/-- Real numbers `p q r : ℝ` are said to be a **Hölder triple** if `p` and `q` are positive
and `p⁻¹ + q⁻¹ = r⁻¹`. -/
@[mk_iff]
structure HolderTriple (p q r : ℝ) : Prop where
inv_add_inv_eq_inv : p⁻¹ + q⁻¹ = r⁻¹
left_pos : 0 < p
right_pos : 0 < q
/-- Real numbers `p q : ℝ` are **Hölder conjugate** if they are positive and satisfy the
equality `p⁻¹ + q⁻¹ = 1`. This is an abbreviation for `Real.HolderTriple p q 1`. This condition
shows up in many theorems in analysis, notably related to `L^p` norms.
It is equivalent that `1 < p` and `p⁻¹ + q⁻¹ = 1`. See `Real.holderConjugate_iff`. -/
abbrev HolderConjugate (p q : ℝ) := HolderTriple p q 1
/-- The conjugate exponent of `p` is `q = p / (p-1)`, so that `p⁻¹ + q⁻¹ = 1`. -/
def conjExponent (p : ℝ) : ℝ := p / (p - 1)
variable {a b p q r : ℝ}
namespace HolderTriple
lemma of_pos (hp : 0 < p) (hq : 0 < q) : HolderTriple p q (p⁻¹ + q⁻¹)⁻¹ where
inv_add_inv_eq_inv := inv_inv _ |>.symm
left_pos := hp
right_pos := hq
variable (h : p.HolderTriple q r)
include h
@[symm]
protected lemma symm : q.HolderTriple p r where
inv_add_inv_eq_inv := add_comm p⁻¹ q⁻¹ ▸ h.inv_add_inv_eq_inv
left_pos := h.right_pos
right_pos := h.left_pos
theorem pos : 0 < p := h.left_pos
theorem nonneg : 0 ≤ p := h.pos.le
theorem ne_zero : p ≠ 0 := h.pos.ne'
protected lemma inv_pos : 0 < p⁻¹ := inv_pos.2 h.pos
protected lemma inv_nonneg : 0 ≤ p⁻¹ := h.inv_pos.le
protected lemma inv_ne_zero : p⁻¹ ≠ 0 := h.inv_pos.ne'
theorem one_div_pos : 0 < 1 / p := _root_.one_div_pos.2 h.pos
theorem one_div_nonneg : 0 ≤ 1 / p := le_of_lt h.one_div_pos
theorem one_div_ne_zero : 1 / p ≠ 0 := ne_of_gt h.one_div_pos
/-- For `r`, instead of `p` -/
theorem pos' : 0 < r := inv_pos.mp <| h.inv_add_inv_eq_inv ▸ add_pos h.inv_pos h.symm.inv_pos
/-- For `r`, instead of `p` -/
theorem nonneg' : 0 ≤ r := h.pos'.le
/-- For `r`, instead of `p` -/
theorem ne_zero' : r ≠ 0 := h.pos'.ne'
/-- For `r`, instead of `p` -/
protected lemma inv_pos' : 0 < r⁻¹ := inv_pos.2 h.pos'
/-- For `r`, instead of `p` -/
protected lemma inv_nonneg' : 0 ≤ r⁻¹ := h.inv_pos'.le
/-- For `r`, instead of `p` -/
protected lemma inv_ne_zero' : r⁻¹ ≠ 0 := h.inv_pos'.ne'
/-- For `r`, instead of `p` -/
theorem one_div_pos' : 0 < 1 / r := _root_.one_div_pos.2 h.pos'
/-- For `r`, instead of `p` -/
theorem one_div_nonneg' : 0 ≤ 1 / r := le_of_lt h.one_div_pos'
/-- For `r`, instead of `p` -/
theorem one_div_ne_zero' : 1 / r ≠ 0 := ne_of_gt h.one_div_pos'
lemma inv_eq : r⁻¹ = p⁻¹ + q⁻¹ := h.inv_add_inv_eq_inv.symm
lemma one_div_add_one_div : 1 / p + 1 / q = 1 / r := by simpa using h.inv_add_inv_eq_inv
lemma one_div_eq : 1 / r = 1 / p + 1 / q := h.one_div_add_one_div.symm
lemma inv_inv_add_inv : (p⁻¹ + q⁻¹)⁻¹ = r := by simp [h.inv_add_inv_eq_inv]
protected lemma inv_lt_inv : p⁻¹ < r⁻¹ := calc
p⁻¹ = p⁻¹ + 0 := add_zero _ |>.symm
_ < p⁻¹ + q⁻¹ := by gcongr; exact h.symm.inv_pos
_ = r⁻¹ := h.inv_add_inv_eq_inv
lemma lt : r < p := by simpa using inv_strictAnti₀ h.inv_pos h.inv_lt_inv
lemma inv_sub_inv_eq_inv : r⁻¹ - q⁻¹ = p⁻¹ := sub_eq_of_eq_add h.inv_eq
lemma holderConjugate_div_div : (p / r).HolderConjugate (q / r) where
inv_add_inv_eq_inv := by
simp [inv_div, div_eq_mul_inv, ← mul_add, h.inv_add_inv_eq_inv, h.ne_zero']
left_pos := by have := h.left_pos; have := h.pos'; positivity
right_pos := by have := h.right_pos; have := h.pos'; positivity
end HolderTriple
namespace HolderConjugate
lemma two_two : HolderConjugate 2 2 where
inv_add_inv_eq_inv := by norm_num
left_pos := zero_lt_two
right_pos := zero_lt_two
section
variable (h : p.HolderConjugate q)
include h
@[symm]
protected lemma symm : q.HolderConjugate p := HolderTriple.symm h
theorem inv_add_inv_eq_one : p⁻¹ + q⁻¹ = 1 := inv_one (G := ℝ) ▸ h.inv_add_inv_eq_inv
theorem sub_one_pos : 0 < p - 1 := sub_pos.2 h.lt
theorem sub_one_ne_zero : p - 1 ≠ 0 := h.sub_one_pos.ne'
theorem conjugate_eq : q = p / (p - 1) := by
convert inv_inv q ▸ congr($(h.symm.inv_sub_inv_eq_inv.symm)⁻¹) using 1
field_simp [h.ne_zero]
lemma conjExponent_eq : conjExponent p = q := h.conjugate_eq.symm
lemma one_sub_inv : 1 - p⁻¹ = q⁻¹ := sub_eq_of_eq_add h.symm.inv_add_inv_eq_one.symm
lemma inv_sub_one : p⁻¹ - 1 = -q⁻¹ := by simpa using congr(-$(h.one_sub_inv))
theorem sub_one_mul_conj : (p - 1) * q = p :=
mul_comm q (p - 1) ▸ (eq_div_iff h.sub_one_ne_zero).1 h.conjugate_eq
theorem mul_eq_add : p * q = p + q := by
simpa only [sub_mul, sub_eq_iff_eq_add, one_mul] using h.sub_one_mul_conj
theorem div_conj_eq_sub_one : p / q = p - 1 := by
field_simp [h.symm.ne_zero]
rw [h.sub_one_mul_conj]
theorem inv_add_inv_ennreal : (ENNReal.ofReal p)⁻¹ + (ENNReal.ofReal q)⁻¹ = 1 := by
rw [← ENNReal.ofReal_one, ← ENNReal.ofReal_inv_of_pos h.pos,
← ENNReal.ofReal_inv_of_pos h.symm.pos, ← ENNReal.ofReal_add h.inv_nonneg h.symm.inv_nonneg,
h.inv_add_inv_eq_one]
end
lemma _root_.Real.holderConjugate_iff : p.HolderConjugate q ↔ 1 < p ∧ p⁻¹ + q⁻¹ = 1 := by
refine ⟨fun h ↦ ⟨h.lt, h.inv_add_inv_eq_one⟩, ?_⟩
rintro ⟨hp, h⟩
have hp' := zero_lt_one.trans hp
refine ⟨inv_one (G := ℝ) |>.symm ▸ h, hp', ?_⟩
rw [← inv_lt_one₀ hp', ← sub_pos] at hp
exact inv_pos.mp <| eq_sub_of_add_eq' h ▸ hp
protected lemma inv_inv (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : a⁻¹.HolderConjugate b⁻¹ where
inv_add_inv_eq_inv := by simpa using hab
left_pos := inv_pos.mpr ha
right_pos := inv_pos.mpr hb
lemma inv_one_sub_inv (ha₀ : 0 < a) (ha₁ : a < 1) : a⁻¹.HolderConjugate (1 - a)⁻¹ :=
holderConjugate_iff.mpr ⟨one_lt_inv₀ ha₀ |>.mpr ha₁, by simp⟩
lemma one_sub_inv_inv (ha₀ : 0 < a) (ha₁ : a < 1) : (1 - a)⁻¹.HolderConjugate a⁻¹ :=
(inv_one_sub_inv ha₀ ha₁).symm
end HolderConjugate
lemma holderConjugate_comm : p.HolderConjugate q ↔ q.HolderConjugate p := ⟨.symm, .symm⟩
lemma holderConjugate_iff_eq_conjExponent (hp : 1 < p) : p.HolderConjugate q ↔ q = p / (p - 1) :=
⟨HolderConjugate.conjugate_eq, fun h ↦ holderConjugate_iff.mpr ⟨hp, by field_simp [h]⟩⟩
lemma HolderConjugate.conjExponent (h : 1 < p) : p.HolderConjugate (conjExponent p) :=
(holderConjugate_iff_eq_conjExponent h).2 rfl
lemma holderConjugate_one_div (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
(1 / a).HolderConjugate (1 / b) := by simpa using HolderConjugate.inv_inv ha hb hab
end Real
| Mathlib/Data/Real/ConjExponents.lean | 204 | 204 | |
/-
Copyright (c) 2018 Sean Leather. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sean Leather, Mario Carneiro
-/
import Mathlib.Data.List.Sigma
/-!
# Association Lists
This file defines association lists. An association list is a list where every element consists of
a key and a value, and no two entries have the same key. The type of the value is allowed to be
dependent on the type of the key.
This type dependence is implemented using `Sigma`: The elements of the list are of type `Sigma β`,
for some type index `β`.
## Main definitions
Association lists are represented by the `AList` structure. This file defines this structure and
provides ways to access, modify, and combine `AList`s.
* `AList.keys` returns a list of keys of the alist.
* `AList.membership` returns membership in the set of keys.
* `AList.erase` removes a certain key.
* `AList.insert` adds a key-value mapping to the list.
* `AList.union` combines two association lists.
## References
* <https://en.wikipedia.org/wiki/Association_list>
-/
universe u v w
open List
variable {α : Type u} {β : α → Type v}
/-- `AList β` is a key-value map stored as a `List` (i.e. a linked list).
It is a wrapper around certain `List` functions with the added constraint
that the list have unique keys. -/
structure AList (β : α → Type v) : Type max u v where
/-- The underlying `List` of an `AList` -/
entries : List (Sigma β)
/-- There are no duplicate keys in `entries` -/
nodupKeys : entries.NodupKeys
/-- Given `l : List (Sigma β)`, create a term of type `AList β` by removing
entries with duplicate keys. -/
def List.toAList [DecidableEq α] {β : α → Type v} (l : List (Sigma β)) : AList β where
entries := _
nodupKeys := nodupKeys_dedupKeys l
namespace AList
@[ext]
theorem ext : ∀ {s t : AList β}, s.entries = t.entries → s = t
| ⟨l₁, h₁⟩, ⟨l₂, _⟩, H => by congr
instance [DecidableEq α] [∀ a, DecidableEq (β a)] : DecidableEq (AList β) := fun xs ys => by
rw [AList.ext_iff]; infer_instance
/-! ### keys -/
/-- The list of keys of an association list. -/
def keys (s : AList β) : List α :=
s.entries.keys
theorem keys_nodup (s : AList β) : s.keys.Nodup :=
s.nodupKeys
/-! ### mem -/
/-- The predicate `a ∈ s` means that `s` has a value associated to the key `a`. -/
instance : Membership α (AList β) :=
⟨fun s a => a ∈ s.keys⟩
theorem mem_keys {a : α} {s : AList β} : a ∈ s ↔ a ∈ s.keys :=
Iff.rfl
theorem mem_of_perm {a : α} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) : a ∈ s₁ ↔ a ∈ s₂ :=
(p.map Sigma.fst).mem_iff
/-! ### empty -/
/-- The empty association list. -/
instance : EmptyCollection (AList β) :=
⟨⟨[], nodupKeys_nil⟩⟩
instance : Inhabited (AList β) :=
⟨∅⟩
@[simp]
theorem not_mem_empty (a : α) : a ∉ (∅ : AList β) :=
not_mem_nil
@[simp]
theorem empty_entries : (∅ : AList β).entries = [] :=
rfl
@[simp]
theorem keys_empty : (∅ : AList β).keys = [] :=
rfl
/-! ### singleton -/
/-- The singleton association list. -/
def singleton (a : α) (b : β a) : AList β :=
⟨[⟨a, b⟩], nodupKeys_singleton _⟩
@[simp]
theorem singleton_entries (a : α) (b : β a) : (singleton a b).entries = [Sigma.mk a b] :=
rfl
@[simp]
theorem keys_singleton (a : α) (b : β a) : (singleton a b).keys = [a] :=
rfl
/-! ### lookup -/
section
variable [DecidableEq α]
/-- Look up the value associated to a key in an association list. -/
def lookup (a : α) (s : AList β) : Option (β a) :=
s.entries.dlookup a
@[simp]
theorem lookup_empty (a) : lookup a (∅ : AList β) = none :=
rfl
theorem lookup_isSome {a : α} {s : AList β} : (s.lookup a).isSome ↔ a ∈ s :=
dlookup_isSome
theorem lookup_eq_none {a : α} {s : AList β} : lookup a s = none ↔ a ∉ s :=
dlookup_eq_none
theorem mem_lookup_iff {a : α} {b : β a} {s : AList β} :
b ∈ lookup a s ↔ Sigma.mk a b ∈ s.entries :=
mem_dlookup_iff s.nodupKeys
theorem perm_lookup {a : α} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) :
s₁.lookup a = s₂.lookup a :=
perm_dlookup _ s₁.nodupKeys s₂.nodupKeys p
instance (a : α) (s : AList β) : Decidable (a ∈ s) :=
decidable_of_iff _ lookup_isSome
end
theorem keys_subset_keys_of_entries_subset_entries
{s₁ s₂ : AList β} (h : s₁.entries ⊆ s₂.entries) : s₁.keys ⊆ s₂.keys := by
intro k hk
letI : DecidableEq α := Classical.decEq α
have := h (mem_lookup_iff.1 (Option.get_mem (lookup_isSome.2 hk)))
rw [← mem_lookup_iff, Option.mem_def] at this
rw [← mem_keys, ← lookup_isSome, this]
exact Option.isSome_some
/-! ### replace -/
section
variable [DecidableEq α]
/-- Replace a key with a given value in an association list.
If the key is not present it does nothing. -/
def replace (a : α) (b : β a) (s : AList β) : AList β :=
⟨kreplace a b s.entries, (kreplace_nodupKeys a b).2 s.nodupKeys⟩
@[simp]
theorem keys_replace (a : α) (b : β a) (s : AList β) : (replace a b s).keys = s.keys :=
keys_kreplace _ _ _
@[simp]
theorem mem_replace {a a' : α} {b : β a} {s : AList β} : a' ∈ replace a b s ↔ a' ∈ s := by
rw [mem_keys, keys_replace, ← mem_keys]
theorem perm_replace {a : α} {b : β a} {s₁ s₂ : AList β} :
s₁.entries ~ s₂.entries → (replace a b s₁).entries ~ (replace a b s₂).entries :=
Perm.kreplace s₁.nodupKeys
end
/-- Fold a function over the key-value pairs in the map. -/
def foldl {δ : Type w} (f : δ → ∀ a, β a → δ) (d : δ) (m : AList β) : δ :=
m.entries.foldl (fun r a => f r a.1 a.2) d
/-! ### erase -/
section
variable [DecidableEq α]
/-- Erase a key from the map. If the key is not present, do nothing. -/
def erase (a : α) (s : AList β) : AList β :=
⟨s.entries.kerase a, s.nodupKeys.kerase a⟩
@[simp]
theorem keys_erase (a : α) (s : AList β) : (erase a s).keys = s.keys.erase a :=
keys_kerase
@[simp]
theorem mem_erase {a a' : α} {s : AList β} : a' ∈ erase a s ↔ a' ≠ a ∧ a' ∈ s := by
rw [mem_keys, keys_erase, s.keys_nodup.mem_erase_iff, ← mem_keys]
theorem perm_erase {a : α} {s₁ s₂ : AList β} :
s₁.entries ~ s₂.entries → (erase a s₁).entries ~ (erase a s₂).entries :=
Perm.kerase s₁.nodupKeys
@[simp]
theorem lookup_erase (a) (s : AList β) : lookup a (erase a s) = none :=
dlookup_kerase a s.nodupKeys
@[simp]
theorem lookup_erase_ne {a a'} {s : AList β} (h : a ≠ a') : lookup a (erase a' s) = lookup a s :=
dlookup_kerase_ne h
theorem erase_erase (a a' : α) (s : AList β) : (s.erase a).erase a' = (s.erase a').erase a :=
ext <| kerase_kerase
/-! ### insert -/
/-- Insert a key-value pair into an association list and erase any existing pair
with the same key. -/
def insert (a : α) (b : β a) (s : AList β) : AList β :=
⟨kinsert a b s.entries, kinsert_nodupKeys a b s.nodupKeys⟩
@[simp]
theorem entries_insert {a} {b : β a} {s : AList β} :
(insert a b s).entries = Sigma.mk a b :: kerase a s.entries :=
rfl
@[deprecated (since := "2024-12-17")] alias insert_entries := entries_insert
theorem entries_insert_of_not_mem {a} {b : β a} {s : AList β} (h : a ∉ s) :
(insert a b s).entries = ⟨a, b⟩ :: s.entries := by rw [entries_insert, kerase_of_not_mem_keys h]
theorem insert_of_not_mem {a} {b : β a} {s : AList β} (h : a ∉ s) :
insert a b s = ⟨⟨a, b⟩ :: s.entries, nodupKeys_cons.2 ⟨h, s.2⟩⟩ :=
ext <| entries_insert_of_not_mem h
@[deprecated (since := "2024-12-14")] alias insert_entries_of_neg := entries_insert_of_not_mem
@[deprecated (since := "2024-12-14")] alias insert_of_neg := insert_of_not_mem
@[simp]
theorem insert_empty (a) (b : β a) : insert a b ∅ = singleton a b :=
rfl
@[simp]
theorem mem_insert {a a'} {b' : β a'} (s : AList β) : a ∈ insert a' b' s ↔ a = a' ∨ a ∈ s :=
mem_keys_kinsert
@[simp]
theorem keys_insert {a} {b : β a} (s : AList β) : (insert a b s).keys = a :: s.keys.erase a := by
simp [insert, keys, keys_kerase]
theorem perm_insert {a} {b : β a} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) :
(insert a b s₁).entries ~ (insert a b s₂).entries := by
simp only [entries_insert]; exact p.kinsert s₁.nodupKeys
@[simp]
theorem lookup_insert {a} {b : β a} (s : AList β) : lookup a (insert a b s) = some b := by
simp only [lookup, insert, dlookup_kinsert]
@[simp]
theorem lookup_insert_ne {a a'} {b' : β a'} {s : AList β} (h : a ≠ a') :
lookup a (insert a' b' s) = lookup a s :=
dlookup_kinsert_ne h
@[simp] theorem lookup_insert_eq_none {l : AList β} {k k' : α} {v : β k} :
(l.insert k v).lookup k' = none ↔ (k' ≠ k) ∧ l.lookup k' = none := by
by_cases h : k' = k
· subst h; simp
· simp_all [lookup_insert_ne h]
@[simp]
theorem lookup_to_alist {a} (s : List (Sigma β)) : lookup a s.toAList = s.dlookup a := by
rw [List.toAList, lookup, dlookup_dedupKeys]
@[simp]
theorem insert_insert {a} {b b' : β a} (s : AList β) :
(s.insert a b).insert a b' = s.insert a b' := by
ext : 1; simp only [AList.entries_insert, List.kerase_cons_eq]
theorem insert_insert_of_ne {a a'} {b : β a} {b' : β a'} (s : AList β) (h : a ≠ a') :
((s.insert a b).insert a' b').entries ~ ((s.insert a' b').insert a b).entries := by
simp only [entries_insert]; rw [kerase_cons_ne, kerase_cons_ne, kerase_comm] <;>
[apply Perm.swap; exact h; exact h.symm]
@[simp]
theorem insert_singleton_eq {a : α} {b b' : β a} : insert a b (singleton a b') = singleton a b :=
ext <| by
simp only [AList.entries_insert, List.kerase_cons_eq, and_self_iff, AList.singleton_entries,
heq_iff_eq, eq_self_iff_true]
@[simp]
theorem entries_toAList (xs : List (Sigma β)) : (List.toAList xs).entries = dedupKeys xs :=
rfl
theorem toAList_cons (a : α) (b : β a) (xs : List (Sigma β)) :
List.toAList (⟨a, b⟩ :: xs) = insert a b xs.toAList :=
rfl
theorem mk_cons_eq_insert (c : Sigma β) (l : List (Sigma β)) (h : (c :: l).NodupKeys) :
(⟨c :: l, h⟩ : AList β) = insert c.1 c.2 ⟨l, nodupKeys_of_nodupKeys_cons h⟩ := by
simpa [insert] using (kerase_of_not_mem_keys <| not_mem_keys_of_nodupKeys_cons h).symm
/-- Recursion on an `AList`, using `insert`. Use as `induction l`. -/
@[elab_as_elim, induction_eliminator]
def insertRec {C : AList β → Sort*} (H0 : C ∅)
(IH : ∀ (a : α) (b : β a) (l : AList β), a ∉ l → C l → C (l.insert a b)) :
∀ l : AList β, C l
| ⟨[], _⟩ => H0
| ⟨c :: l, h⟩ => by
rw [mk_cons_eq_insert]
| refine IH _ _ _ ?_ (insertRec H0 IH _)
exact not_mem_keys_of_nodupKeys_cons h
| Mathlib/Data/List/AList.lean | 327 | 328 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Moritz Doll
-/
import Mathlib.Algebra.GroupWithZero.Action.Opposite
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
import Mathlib.LinearAlgebra.Matrix.Basis
import Mathlib.LinearAlgebra.Matrix.Nondegenerate
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv
import Mathlib.LinearAlgebra.SesquilinearForm
import Mathlib.LinearAlgebra.Basis.Bilinear
/-!
# Sesquilinear form
This file defines the conversion between sesquilinear maps and matrices.
## Main definitions
* `Matrix.toLinearMap₂` given a basis define a bilinear map
* `Matrix.toLinearMap₂'` define the bilinear map on `n → R`
* `LinearMap.toMatrix₂`: calculate the matrix coefficients of a bilinear map
* `LinearMap.toMatrix₂'`: calculate the matrix coefficients of a bilinear map on `n → R`
## TODO
At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be
generalized to fully semibilinear forms.
## Tags
Sesquilinear form, Sesquilinear map, matrix, basis
-/
variable {R R₁ S₁ R₂ S₂ M₁ M₂ M₁' M₂' N₂ n m n' m' ι : Type*}
open Finset LinearMap Matrix
open Matrix
open scoped RightActions
section AuxToLinearMap
variable [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] [AddCommMonoid N₂]
[Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₂ S₁ N₂]
variable [Fintype n] [Fintype m]
variable (σ₁ : R₁ →+* S₁) (σ₂ : R₂ →+* S₂)
/-- The map from `Matrix n n R` to bilinear maps on `n → R`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMap₂'`. -/
def Matrix.toLinearMap₂'Aux (f : Matrix n m N₂) : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ :=
-- porting note: we don't seem to have `∑ i j` as valid notation yet
mk₂'ₛₗ σ₁ σ₂ (fun (v : n → R₁) (w : m → R₂) => ∑ i, ∑ j, σ₂ (w j) • σ₁ (v i) • f i j)
(fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul])
(fun c v w => by
simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c),
MulAction.mul_smul])
(fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, smul_add, sum_add_distrib])
(fun _ v w => by
simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum])
variable [DecidableEq n] [DecidableEq m]
theorem Matrix.toLinearMap₂'Aux_single (f : Matrix n m N₂) (i : n) (j : m) :
f.toLinearMap₂'Aux σ₁ σ₂ (Pi.single i 1) (Pi.single j 1) = f i j := by
rw [Matrix.toLinearMap₂'Aux, mk₂'ₛₗ_apply]
have : (∑ i', ∑ j', (if i = i' then (1 : S₁) else (0 : S₁)) •
(if j = j' then (1 : S₂) else (0 : S₂)) • f i' j') =
f i j := by
simp_rw [← Finset.smul_sum]
simp only [op_smul_eq_smul, ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte]
rw [← this]
exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop
end AuxToLinearMap
section AuxToMatrix
section CommSemiring
variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂]
variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid N₂]
[Module R N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂]
[SMulCommClass S₂ S₁ N₂]
variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂}
variable (R)
/-- The linear map from sesquilinear maps to `Matrix n m N₂` given an `n`-indexed basis for `M₁`
and an `m`-indexed basis for `M₂`.
This is an auxiliary definition for the equivalence `Matrix.toLinearMapₛₗ₂'`. -/
def LinearMap.toMatrix₂Aux (b₁ : n → M₁) (b₂ : m → M₂) :
(M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) →ₗ[R] Matrix n m N₂ where
toFun f := of fun i j => f (b₁ i) (b₂ j)
map_add' _f _g := rfl
map_smul' _f _g := rfl
@[simp]
theorem LinearMap.toMatrix₂Aux_apply (f : M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) (b₁ : n → M₁) (b₂ : m → M₂)
(i : n) (j : m) : LinearMap.toMatrix₂Aux R b₁ b₂ f i j = f (b₁ i) (b₂ j) :=
rfl
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
theorem LinearMap.toLinearMap₂'Aux_toMatrix₂Aux (f : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) :
Matrix.toLinearMap₂'Aux σ₁ σ₂
(LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) =
f := by
refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun R₂ m) fun i j => ?_
simp_rw [Pi.basisFun_apply, Matrix.toLinearMap₂'Aux_single, LinearMap.toMatrix₂Aux_apply]
theorem Matrix.toMatrix₂Aux_toLinearMap₂'Aux (f : Matrix n m N₂) :
LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1)
(fun j => Pi.single j 1) (f.toLinearMap₂'Aux σ₁ σ₂) =
f := by
ext i j
simp_rw [LinearMap.toMatrix₂Aux_apply, Matrix.toLinearMap₂'Aux_single]
end CommSemiring
end AuxToMatrix
section ToMatrix'
/-! ### Bilinear maps over `n → R`
This section deals with the conversion between matrices and sesquilinear maps on `n → R`.
-/
variable [CommSemiring R] [AddCommMonoid N₂] [Module R N₂] [Semiring R₁] [Semiring R₂]
[Semiring S₁] [Semiring S₂] [Module S₁ N₂] [Module S₂ N₂]
[SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂]
variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂}
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable (R)
/-- The linear equivalence between sesquilinear maps and `n × m` matrices -/
def LinearMap.toMatrixₛₗ₂' : ((n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) ≃ₗ[R] Matrix n m N₂ :=
{ LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with
toFun := LinearMap.toMatrix₂Aux R _ _
invFun := Matrix.toLinearMap₂'Aux σ₁ σ₂
left_inv := LinearMap.toLinearMap₂'Aux_toMatrix₂Aux R
right_inv := Matrix.toMatrix₂Aux_toLinearMap₂'Aux R }
/-- The linear equivalence between bilinear maps and `n × m` matrices -/
def LinearMap.toMatrix₂' : ((n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) ≃ₗ[R] Matrix n m N₂ :=
LinearMap.toMatrixₛₗ₂' R
variable (σ₁ σ₂)
/-- The linear equivalence between `n × n` matrices and sesquilinear maps on `n → R` -/
def Matrix.toLinearMapₛₗ₂' : Matrix n m N₂ ≃ₗ[R] (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ :=
(LinearMap.toMatrixₛₗ₂' R).symm
/-- The linear equivalence between `n × n` matrices and bilinear maps on `n → R` -/
def Matrix.toLinearMap₂' : Matrix n m N₂ ≃ₗ[R] (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂ :=
(LinearMap.toMatrix₂' R).symm
variable {R}
theorem Matrix.toLinearMapₛₗ₂'_aux_eq (M : Matrix n m N₂) :
Matrix.toLinearMap₂'Aux σ₁ σ₂ M = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M :=
rfl
theorem Matrix.toLinearMapₛₗ₂'_apply (M : Matrix n m N₂) (x : n → R₁) (y : m → R₂) :
-- porting note: we don't seem to have `∑ i j` as valid notation yet
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M x y = ∑ i, ∑ j, σ₁ (x i) • σ₂ (y j) • M i j := by
rw [toLinearMapₛₗ₂', toMatrixₛₗ₂', LinearEquiv.coe_symm_mk, toLinearMap₂'Aux, mk₂'ₛₗ_apply]
apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [smul_comm]
theorem Matrix.toLinearMap₂'_apply (M : Matrix n m N₂) (x : n → S₁) (y : m → S₂) :
-- porting note: we don't seem to have `∑ i j` as valid notation yet
Matrix.toLinearMap₂' R M x y = ∑ i, ∑ j, x i • y j • M i j :=
Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by
rw [RingHom.id_apply, RingHom.id_apply, smul_comm]
theorem Matrix.toLinearMap₂'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n → T)
(w : m → T) : Matrix.toLinearMap₂' T M v w = dotProduct v (M *ᵥ w) := by
simp_rw [Matrix.toLinearMap₂'_apply, dotProduct, Matrix.mulVec, dotProduct]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [Finset.mul_sum]
refine Finset.sum_congr rfl fun _ _ => ?_
rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc]
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_single (M : Matrix n m N₂) (i : n) (j : m) :
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMap₂'Aux_single σ₁ σ₂ M i j
@[simp]
theorem Matrix.toLinearMap₂'_single (M : Matrix n m N₂) (i : n) (j : m) :
Matrix.toLinearMap₂' R M (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMap₂'Aux_single _ _ M i j
@[simp]
theorem LinearMap.toMatrixₛₗ₂'_symm :
((LinearMap.toMatrixₛₗ₂' R).symm : Matrix n m N₂ ≃ₗ[R] _) = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ :=
rfl
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_symm :
((Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).symm : _ ≃ₗ[R] Matrix n m N₂) = LinearMap.toMatrixₛₗ₂' R :=
(LinearMap.toMatrixₛₗ₂' R).symm_symm
@[simp]
theorem Matrix.toLinearMapₛₗ₂'_toMatrix' (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) :
Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ (LinearMap.toMatrixₛₗ₂' R B) = B :=
(Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).apply_symm_apply B
@[simp]
theorem Matrix.toLinearMap₂'_toMatrix' (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) :
Matrix.toLinearMap₂' R (LinearMap.toMatrix₂' R B) = B :=
(Matrix.toLinearMap₂' R).apply_symm_apply B
@[simp]
theorem LinearMap.toMatrix'_toLinearMapₛₗ₂' (M : Matrix n m N₂) :
LinearMap.toMatrixₛₗ₂' R (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M) = M :=
(LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrix'_toLinearMap₂' (M : Matrix n m N₂) :
LinearMap.toMatrix₂' R (Matrix.toLinearMap₂' R (S₁ := S₁) (S₂ := S₂) M) = M :=
(LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M
@[simp]
theorem LinearMap.toMatrixₛₗ₂'_apply (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) (i : n) (j : m) :
LinearMap.toMatrixₛₗ₂' R B i j = B (Pi.single i 1) (Pi.single j 1) :=
rfl
@[simp]
theorem LinearMap.toMatrix₂'_apply (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) (i : n) (j : m) :
LinearMap.toMatrix₂' R B i j = B (Pi.single i 1) (Pi.single j 1) :=
rfl
end ToMatrix'
section CommToMatrix'
-- TODO: Introduce matrix multiplication by matrices of scalars
variable {R : Type*} [CommSemiring R]
variable [Fintype n] [Fintype m]
variable [DecidableEq n] [DecidableEq m]
variable [Fintype n'] [Fintype m']
variable [DecidableEq n'] [DecidableEq m']
@[simp]
theorem LinearMap.toMatrix₂'_compl₁₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (l : (n' → R) →ₗ[R] n → R)
(r : (m' → R) →ₗ[R] m → R) :
toMatrix₂' R (B.compl₁₂ l r) = (toMatrix' l)ᵀ * toMatrix₂' R B * toMatrix' r := by
ext i j
simp only [LinearMap.toMatrix₂'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply,
LinearMap.toMatrix', LinearEquiv.coe_mk, sum_mul]
rw [sum_comm]
conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)]
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro i' -
rw [Finsupp.sum_fintype]
· apply sum_congr rfl
rintro j' -
simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm,
Pi.basisFun_apply, of_apply]
· intros
simp only [zero_smul, smul_zero]
· intros
simp only [zero_smul, Finsupp.sum_zero]
theorem LinearMap.toMatrix₂'_comp (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (n' → R) →ₗ[R] n → R) :
toMatrix₂' R (B.comp f) = (toMatrix' f)ᵀ * toMatrix₂' R B := by
rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂]
simp
theorem LinearMap.toMatrix₂'_compl₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (m' → R) →ₗ[R] m → R) :
toMatrix₂' R (B.compl₂ f) = toMatrix₂' R B * toMatrix' f := by
rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂]
simp
theorem LinearMap.mul_toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R)
(N : Matrix m m' R) :
M * toMatrix₂' R B * N = toMatrix₂' R (B.compl₁₂ (toLin' Mᵀ) (toLin' N)) := by
simp
theorem LinearMap.mul_toMatrix' (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) :
M * toMatrix₂' R B = toMatrix₂' R (B.comp <| toLin' Mᵀ) := by
simp only [B.toMatrix₂'_comp, transpose_transpose, toMatrix'_toLin']
theorem LinearMap.toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix m m' R) :
toMatrix₂' R B * M = toMatrix₂' R (B.compl₂ <| toLin' M) := by
simp only [B.toMatrix₂'_compl₂, toMatrix'_toLin']
theorem Matrix.toLinearMap₂'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) :
LinearMap.compl₁₂ (Matrix.toLinearMap₂' R M) (toLin' P) (toLin' Q) =
toLinearMap₂' R (Pᵀ * M * Q) :=
(LinearMap.toMatrix₂' R).injective (by simp)
end CommToMatrix'
section ToMatrix
/-! ### Bilinear maps over arbitrary vector spaces
This section deals with the conversion between matrices and bilinear maps on
a module with a fixed basis.
-/
variable [CommSemiring R]
| variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid N₂]
[Module R N₂]
variable [DecidableEq n] [Fintype n]
| Mathlib/LinearAlgebra/Matrix/SesquilinearForm.lean | 319 | 321 |
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Data.Matrix.Notation
import Mathlib.Data.Fin.Tuple.Reflection
/-!
# Lemmas for concrete matrices `Matrix (Fin m) (Fin n) α`
This file contains alternative definitions of common operators on matrices that expand
definitionally to the expected expression when evaluated on `!![]` notation.
This allows "proof by reflection", where we prove `A = !![A 0 0, A 0 1; A 1 0, A 1 1]` by defining
`Matrix.etaExpand A` to be equal to the RHS definitionally, and then prove that
`A = eta_expand A`.
The definitions in this file should normally not be used directly; the intent is for the
corresponding `*_eq` lemmas to be used in a place where they are definitionally unfolded.
## Main definitions
* `Matrix.transposeᵣ`
* `dotProductᵣ`
* `Matrix.mulᵣ`
* `Matrix.mulVecᵣ`
* `Matrix.vecMulᵣ`
* `Matrix.etaExpand`
-/
open Matrix
namespace Matrix
variable {l m n : ℕ} {α : Type*}
/-- `∀` with better defeq for `∀ x : Matrix (Fin m) (Fin n) α, P x`. -/
def Forall : ∀ {m n} (_ : Matrix (Fin m) (Fin n) α → Prop), Prop
| 0, _, P => P (of ![])
| _ + 1, _, P => FinVec.Forall fun r => Forall fun A => P (of (Matrix.vecCons r A))
/-- This can be used to prove
```lean
example (P : Matrix (Fin 2) (Fin 3) α → Prop) :
(∀ x, P x) ↔ ∀ a b c d e f, P !![a, b, c; d, e, f] :=
(forall_iff _).symm
```
-/
theorem forall_iff : ∀ {m n} (P : Matrix (Fin m) (Fin n) α → Prop), Forall P ↔ ∀ x, P x
| 0, _, _ => Iff.symm Fin.forall_fin_zero_pi
| m + 1, n, P => by
simp only [Forall, FinVec.forall_iff, forall_iff]
| exact Iff.symm Fin.forall_fin_succ_pi
example (P : Matrix (Fin 2) (Fin 3) α → Prop) :
(∀ x, P x) ↔ ∀ a b c d e f, P !![a, b, c; d, e, f] :=
(forall_iff _).symm
| Mathlib/Data/Matrix/Reflection.lean | 56 | 60 |
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.CategoryTheory.Galois.Basic
import Mathlib.CategoryTheory.Limits.FintypeCat
import Mathlib.CategoryTheory.Limits.Preserves.Limits
import Mathlib.CategoryTheory.Limits.Shapes.SingleObj
import Mathlib.GroupTheory.GroupAction.Basic
import Mathlib.Algebra.Equiv.TransferInstance
/-!
# Galois objects in Galois categories
We define when a connected object of a Galois category `C` is Galois in a fiber functor independent
way and show equivalent characterisations.
## Main definitions
* `IsGalois` : Connected object `X` of `C` such that `X / Aut X` is terminal.
## Main results
* `galois_iff_pretransitive` : A connected object `X` is Galois if and only if `Aut X`
acts transitively on `F.obj X` for a fiber functor `F`.
-/
universe u₁ u₂ v₁ v₂ v w
namespace CategoryTheory
namespace PreGaloisCategory
open Limits Functor
noncomputable instance {G : Type v} [Group G] [Finite G] :
PreservesColimitsOfShape (SingleObj G) FintypeCat.incl.{w} := by
choose G' hg hf e using Finite.exists_type_univ_nonempty_mulEquiv G
exact Limits.preservesColimitsOfShape_of_equiv (Classical.choice e).toSingleObjEquiv.symm _
/-- A connected object `X` of `C` is Galois if the quotient `X / Aut X` is terminal. -/
class IsGalois {C : Type u₁} [Category.{u₂, u₁} C] [GaloisCategory C] (X : C) : Prop
extends IsConnected X where
quotientByAutTerminal : Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X)
variable {C : Type u₁} [Category.{u₂, u₁} C]
/-- The natural action of `Aut X` on `F.obj X`. -/
instance autMulFiber (F : C ⥤ FintypeCat.{w}) (X : C) : MulAction (Aut X) (F.obj X) where
smul σ a := F.map σ.hom a
one_smul a := by
show F.map (𝟙 X) a = a
simp only [map_id, FintypeCat.id_apply]
mul_smul g h a := by
show F.map (h.hom ≫ g.hom) a = (F.map h.hom ≫ F.map g.hom) a
simp only [map_comp, FintypeCat.comp_apply]
variable [GaloisCategory C] (F : C ⥤ FintypeCat.{w}) [FiberFunctor F]
/-- For a connected object `X` of `C`, the quotient `X / Aut X` is terminal if and only if
the quotient `F.obj X / Aut X` has exactly one element. -/
noncomputable def quotientByAutTerminalEquivUniqueQuotient
(X : C) [IsConnected X] :
IsTerminal (colimit <| SingleObj.functor <| Aut.toEnd X) ≃
Unique (MulAction.orbitRel.Quotient (Aut X) (F.obj X)) := by
let J : SingleObj (Aut X) ⥤ C := SingleObj.functor (Aut.toEnd X)
let e : (F ⋙ FintypeCat.incl).obj (colimit J) ≅ _ :=
preservesColimitIso (F ⋙ FintypeCat.incl) J ≪≫
(Equiv.toIso <| SingleObj.Types.colimitEquivQuotient (J ⋙ F ⋙ FintypeCat.incl))
apply Equiv.trans
· apply (IsTerminal.isTerminalIffObj (F ⋙ FintypeCat.incl) _).trans
(isLimitEmptyConeEquiv _ (asEmptyCone _) (asEmptyCone _) e)
exact Types.isTerminalEquivUnique _
lemma isGalois_iff_aux (X : C) [IsConnected X] :
IsGalois X ↔ Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) :=
⟨fun h ↦ h.quotientByAutTerminal, fun h ↦ ⟨h⟩⟩
/-- Given a fiber functor `F` and a connected object `X` of `C`. Then `X` is Galois if and only if
| the natural action of `Aut X` on `F.obj X` is transitive. -/
theorem isGalois_iff_pretransitive (X : C) [IsConnected X] :
IsGalois X ↔ MulAction.IsPretransitive (Aut X) (F.obj X) := by
rw [isGalois_iff_aux, Equiv.nonempty_congr <| quotientByAutTerminalEquivUniqueQuotient F X]
| Mathlib/CategoryTheory/Galois/GaloisObjects.lean | 81 | 84 |
/-
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.Real
/-!
# Power function on `ℝ≥0` and `ℝ≥0∞`
We construct the power functions `x ^ y` where
* `x` is a nonnegative real number and `y` is a real number;
* `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number.
We also prove basic properties of these functions.
-/
noncomputable section
open Real NNReal ENNReal ComplexConjugate Finset Function Set
namespace NNReal
variable {x : ℝ≥0} {w y z : ℝ}
/-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the
restriction of the real 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`. -/
noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 :=
⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩
noncomputable instance : Pow ℝ≥0 ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp, norm_cast]
theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y :=
rfl
@[simp]
theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 :=
NNReal.eq <| Real.rpow_zero _
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero]
exact Real.rpow_eq_zero_iff_of_nonneg x.2
lemma rpow_eq_zero (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [hy]
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 :=
NNReal.eq <| Real.zero_rpow h
@[simp]
theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x :=
NNReal.eq <| Real.rpow_one _
lemma rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ :=
NNReal.eq <| Real.rpow_neg x.2 _
@[simp, norm_cast]
lemma rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n
@[simp, norm_cast]
lemma rpow_intCast (x : ℝ≥0) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast,
Int.cast_negSucc, rpow_neg, zpow_negSucc]
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 :=
NNReal.eq <| Real.one_rpow _
theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _
theorem rpow_add' (h : y + z ≠ 0) (x : ℝ≥0) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add' x.2 h
lemma rpow_add_intCast (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast (mod_cast hx) _ _
lemma rpow_add_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast (mod_cast hx) _ _
lemma rpow_sub_intCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _
lemma rpow_sub_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _
lemma rpow_add_intCast' {n : ℤ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast' (mod_cast x.2) h
lemma rpow_add_natCast' {n : ℕ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast' (mod_cast x.2) h
lemma rpow_sub_intCast' {n : ℤ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h
lemma rpow_sub_natCast' {n : ℕ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h
lemma rpow_add_one (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_natCast hx y 1
lemma rpow_sub_one (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_natCast hx y 1
lemma rpow_add_one' (h : y + 1 ≠ 0) (x : ℝ≥0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' h, rpow_one]
lemma rpow_one_add' (h : 1 + y ≠ 0) (x : ℝ≥0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' h, rpow_one]
theorem rpow_add_of_nonneg (x : ℝ≥0) {y z : ℝ} (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
ext; exact Real.rpow_add_of_nonneg x.2 hy hz
/-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add']; rwa [h]
theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
NNReal.eq <| Real.rpow_mul x.2 y z
lemma rpow_natCast_mul (x : ℝ≥0) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_natCast]
lemma rpow_mul_natCast (x : ℝ≥0) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_natCast]
lemma rpow_intCast_mul (x : ℝ≥0) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_intCast]
lemma rpow_mul_intCast (x : ℝ≥0) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_intCast]
theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z
theorem rpow_sub' (h : y - z ≠ 0) (x : ℝ≥0) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub' x.2 h
lemma rpow_sub_one' (h : y - 1 ≠ 0) (x : ℝ≥0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' h, rpow_one]
lemma rpow_one_sub' (h : 1 - y ≠ 0) (x : ℝ≥0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' h, rpow_one]
theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by
field_simp [← rpow_mul]
theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by
field_simp [← rpow_mul]
theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ :=
NNReal.eq <| Real.inv_rpow x.2 y
theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z :=
NNReal.eq <| Real.div_rpow x.2 y.2 z
theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by
refine NNReal.eq ?_
push_cast
exact Real.sqrt_eq_rpow x.1
@[simp]
lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) :=
rpow_natCast x n
theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z :=
NNReal.eq <| Real.mul_rpow x.2 y.2
/-- `rpow` as a `MonoidHom` -/
@[simps]
def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where
toFun := (· ^ r)
map_one' := one_rpow _
map_mul' _x _y := mul_rpow
/-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0` -/
theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r :=
l.prod_hom (rpowMonoidHom r)
theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← list_prod_map_rpow, List.map_map]; rfl
/-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/
lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r :=
s.prod_hom' (rpowMonoidHom r) _
/-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/
lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
multiset_prod_map_rpow _ _ _
-- note: these don't really belong here, but they're much easier to prove in terms of the above
section Real
/-- `rpow` version of `List.prod_map_pow` for `Real`. -/
theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r := by
lift l to List ℝ≥0 using hl
have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r)
push_cast at this
rw [List.map_map] at this ⊢
exact mod_cast this
theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ)
(hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map]
· rfl
simpa using hl
/-- `rpow` version of `Multiset.prod_map_pow`. -/
theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ)
(hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r := by
induction' s using Quotient.inductionOn with l
simpa using Real.list_prod_map_rpow' l f hs r
/-- `rpow` version of `Finset.prod_pow`. -/
theorem _root_.Real.finset_prod_rpow
{ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
Real.multiset_prod_map_rpow s.val f hs r
end Real
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
Real.rpow_le_rpow x.2 h₁ h₂
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
Real.rpow_lt_rpow x.2 h₁ h₂
theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
Real.rpow_lt_rpow_iff x.2 y.2 hz
theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
Real.rpow_le_rpow_iff x.2 y.2 hz
theorem le_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem rpow_inv_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem lt_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by
simp only [← not_le, rpow_inv_le_iff hz]
theorem rpow_inv_lt_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by
simp only [← not_le, le_rpow_inv_iff hz]
section
variable {y : ℝ≥0}
lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z :=
Real.rpow_lt_rpow_of_neg hx hxy hz
lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z :=
Real.rpow_le_rpow_of_nonpos hx hxy hz
lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x :=
Real.rpow_lt_rpow_iff_of_neg hx hy hz
lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x :=
Real.rpow_le_rpow_iff_of_neg hx hy hz
lemma le_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y :=
Real.le_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_le_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z :=
Real.rpow_inv_le_iff_of_pos x.2 hy hz
lemma lt_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x < y ^ z⁻¹ ↔ x ^ z < y :=
Real.lt_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_lt_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ < y ↔ x < y ^ z :=
Real.rpow_inv_lt_iff_of_pos x.2 hy hz
lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z :=
Real.le_rpow_inv_iff_of_neg hx hy hz
lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z :=
Real.lt_rpow_inv_iff_of_neg hx hy hz
lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x :=
Real.rpow_inv_lt_iff_of_neg hx hy hz
lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x :=
Real.rpow_inv_le_iff_of_neg hx hy hz
end
@[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_lt hx hyz
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_le hx hyz
theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz
theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by
have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by
intro p hp_pos
rw [← zero_rpow hp_pos.ne']
exact rpow_lt_rpow hx_pos hp_pos
rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg)
· exact rpow_pos_of_nonneg hp_pos
· simp only [zero_lt_one, rpow_zero]
· rw [← neg_neg p, rpow_neg, inv_pos]
exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg)
theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 :=
Real.rpow_lt_one (coe_nonneg x) hx1 hz
theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 :=
Real.rpow_le_one x.2 hx2 hz
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 :=
Real.rpow_lt_one_of_one_lt_of_neg hx hz
theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 :=
Real.rpow_le_one_of_one_le_of_nonpos hx hz
theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z :=
Real.one_lt_rpow hx hz
theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z :=
Real.one_le_rpow h h₁
theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x ^ z :=
Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz
theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z ≤ 0) : 1 ≤ x ^ z :=
Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz
theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x))
· have : z ≠ 0 := by linarith
simp [this]
nth_rw 2 [← NNReal.rpow_one x]
exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le
theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x :=
fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz
theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y :=
(rpow_left_injective hz).eq_iff
theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x :=
fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancel₀ hx, rpow_one]⟩
theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x :=
⟨rpow_left_injective hx, rpow_left_surjective hx⟩
theorem eq_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
theorem rpow_inv_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
@[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul, inv_mul_cancel₀ hy, rpow_one]
theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow]
exact Real.pow_rpow_inv_natCast x.2 hn
theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow]
exact Real.rpow_inv_natCast_pow x.2 hn
theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) :
Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by
nth_rw 1 [← Real.coe_toNNReal x hx]
rw [← NNReal.coe_rpow, Real.toNNReal_coe]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z :=
fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe]
theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z :=
h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 =>
(strictMono_rpow_of_pos h0).monotone
/-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive,
where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/
@[simps! apply]
def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 :=
(strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y))
fun x => by
dsimp
rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one]
theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) :
(orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by
simp only [orderIsoRpow, one_div_one_div]; rfl
theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : ‖x ^ y‖₊ = ‖x‖₊ ^ y := by
ext; exact Real.norm_rpow_of_nonneg hx
end NNReal
namespace ENNReal
/-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and
`y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values
for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and
`⊤ ^ x = 1 / 0 ^ x`). -/
noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞
| some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0)
| none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0
noncomputable instance : Pow ℝ≥0∞ ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp]
theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by
cases x <;>
· dsimp only [(· ^ ·), Pow.pow, rpow]
simp [lt_irrefl]
theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 :=
rfl
@[simp]
theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h]
@[simp]
theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by
simp [top_rpow_def, asymm h, ne_of_lt h]
@[simp]
theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, asymm h, ne_of_gt h]
@[simp]
theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, ne_of_gt h]
theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by
rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H)
· simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl]
· simp [lt_irrefl]
· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg]
@[simp]
theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by
rw [zero_rpow_def]
split_ifs
exacts [zero_mul _, one_mul _, top_mul_top]
@[norm_cast]
theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (↑(x ^ y) : ℝ≥0∞) = x ^ y := by
rw [← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), Pow.pow, rpow]
simp [h]
@[norm_cast]
theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : ↑(x ^ y) = (x : ℝ≥0∞) ^ y := by
by_cases hx : x = 0
· rcases le_iff_eq_or_lt.1 h with (H | H)
· simp [hx, H.symm]
· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)]
· exact coe_rpow_of_ne_zero hx _
theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) :
(x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) :=
rfl
theorem rpow_ofNNReal {M : ℝ≥0} {P : ℝ} (hP : 0 ≤ P) : (M : ℝ≥0∞) ^ P = ↑(M ^ P) := by
rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow]
@[simp]
theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by
cases x
· exact dif_pos zero_lt_one
· change ite _ _ _ = _
simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp]
exact fun _ => zero_le_one.not_lt
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by
rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero]
simp
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by
simp [hy, hy.not_lt]
@[simp]
theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by
simp [rpow_eq_top_iff, hy, asymm hy]
lemma rpow_lt_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by
simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy]
theorem rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ := by
rw [ENNReal.rpow_eq_top_iff]
rintro (h|h)
· exfalso
rw [lt_iff_not_ge] at h
exact h.right hy0
· exact h.left
theorem rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ :=
mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h
theorem rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ :=
lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h)
theorem rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z := by
cases x with
| top => exact (h'x rfl).elim
| coe x =>
have : x ≠ 0 := fun h => by simp [h] at hx
simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this]
theorem rpow_add_of_nonneg {x : ℝ≥0∞} (y z : ℝ) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
induction x using recTopCoe
· rcases hy.eq_or_lt with rfl|hy
· rw [rpow_zero, one_mul, zero_add]
rcases hz.eq_or_lt with rfl|hz
· rw [rpow_zero, mul_one, add_zero]
simp [top_rpow_of_pos, hy, hz, add_pos hy hz]
simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz]
theorem rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr]
· have A : x ^ y ≠ 0 := by simp [h]
simp [← coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg]
theorem rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z := by
rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv]
theorem rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
· have : x ^ y ≠ 0 := by simp [h]
simp [← coe_rpow_of_ne_zero, h, this, NNReal.rpow_mul]
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by
cases x
· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)]
· simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)]
@[simp]
lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n) :=
rpow_natCast x n
@[simp, norm_cast]
lemma rpow_intCast (x : ℝ≥0∞) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast,
Int.cast_negSucc, rpow_neg, zpow_negSucc]
theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) :
(x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z := by
rcases eq_or_ne z 0 with (rfl | hz); · simp
replace hz := hz.lt_or_lt
wlog hxy : x ≤ y
· convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm]
rcases eq_or_ne x 0 with (rfl | hx0)
· induction y <;> rcases hz with hz | hz <;> simp [*, hz.not_lt]
rcases eq_or_ne y 0 with (rfl | hy0)
· exact (hx0 (bot_unique hxy)).elim
induction x
· rcases hz with hz | hz <;> simp [hz, top_unique hxy]
induction y
· rw [ne_eq, coe_eq_zero] at hx0
rcases hz with hz | hz <;> simp [*]
simp only [*, if_false]
norm_cast at *
rw [← coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow]
norm_cast
theorem mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite]
@[norm_cast]
theorem coe_mul_rpow (x y : ℝ≥0) (z : ℝ) : ((x : ℝ≥0∞) * y) ^ z = (x : ℝ≥0∞) ^ z * (y : ℝ≥0∞) ^ z :=
mul_rpow_of_ne_top coe_ne_top coe_ne_top z
theorem prod_coe_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
∏ i ∈ s, (f i : ℝ≥0∞) ^ r = ((∏ i ∈ s, f i : ℝ≥0) : ℝ≥0∞) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul]
theorem mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite]
theorem mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x * y) ^ z = x ^ z * y ^ z := by
simp [hz.not_lt, mul_rpow_eq_ite]
theorem prod_rpow_of_ne_top {ι} {s : Finset ι} {f : ι → ℝ≥0∞} (hf : ∀ i ∈ s, f i ≠ ∞) (r : ℝ) :
∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert i s hi ih =>
have h2f : ∀ i ∈ s, f i ≠ ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi
rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..]
apply prod_ne_top h2f
theorem prod_rpow_of_nonneg {ι} {s : Finset ι} {f : ι → ℝ≥0∞} {r : ℝ} (hr : 0 ≤ r) :
∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr]
theorem inv_rpow (x : ℝ≥0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by
rcases eq_or_ne y 0 with (rfl | hy); · simp only [rpow_zero, inv_one]
replace hy := hy.lt_or_lt
rcases eq_or_ne x 0 with (rfl | h0); · cases hy <;> simp [*]
rcases eq_or_ne x ⊤ with (rfl | h_top); · cases hy <;> simp [*]
apply ENNReal.eq_inv_of_mul_eq_one_left
rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top,
one_rpow]
theorem div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x / y) ^ z = x ^ z / y ^ z := by
rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0∞ => x ^ z := by
intro x y hxy
lift x to ℝ≥0 using ne_top_of_lt hxy
rcases eq_or_ne y ∞ with (rfl | hy)
· simp only [top_rpow_of_pos h, ← coe_rpow_of_nonneg _ h.le, coe_lt_top]
· lift y to ℝ≥0 using hy
simp only [← coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe]
theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0∞ => x ^ z :=
h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 =>
(strictMono_rpow_of_pos h0).monotone
/-- Bundles `fun x : ℝ≥0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive,
where the inverse is `fun x : ℝ≥0∞ => x ^ (1 / y)`. -/
@[simps! apply]
def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0∞ ≃o ℝ≥0∞ :=
(strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y))
fun x => by
dsimp
rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one]
theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) :
(orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by
simp only [orderIsoRpow, one_div_one_div]
rfl
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
monotone_rpow_of_nonneg h₂ h₁
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
strictMono_rpow_of_pos h₂ h₁
theorem rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
(strictMono_rpow_of_pos hz).le_iff_le
theorem rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
(strictMono_rpow_of_pos hz).lt_iff_lt
theorem le_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
nth_rw 1 [← rpow_one x]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne']
rw [rpow_mul, @rpow_le_rpow_iff _ _ z⁻¹ (by simp [hz])]
theorem rpow_inv_lt_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by
simp only [← not_le, le_rpow_inv_iff hz]
theorem lt_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := by
nth_rw 1 [← rpow_one x]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z (ne_of_lt hz).symm]
rw [rpow_mul, @rpow_lt_rpow_iff _ _ z⁻¹ (by simp [hz])]
theorem rpow_inv_le_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
nth_rw 1 [← ENNReal.rpow_one y]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne.symm]
rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (inv_pos.2 hz)]
theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) :
x ^ y < x ^ z := by
lift x to ℝ≥0 using hx'
rw [one_lt_coe_iff] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
NNReal.rpow_lt_rpow_of_exponent_lt hx hyz]
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0∞} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) :
x ^ y ≤ x ^ z := by
cases x
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;>
linarith
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
NNReal.rpow_le_rpow_of_exponent_le hx hyz]
theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x ^ y < x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top)
simp only [coe_lt_one_iff, coe_pos] at hx0 hx1
simp [← coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz]
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top)
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;>
linarith
· rw [coe_le_one_iff] at hx1
simp [← coe_rpow_of_ne_zero h,
NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz]
theorem rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
nth_rw 2 [← ENNReal.rpow_one x]
exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le
theorem le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z := by
nth_rw 1 [← ENNReal.rpow_one x]
exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le
theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≤ p) : 0 < x ^ p := by
by_cases hp_zero : p = 0
· simp [hp_zero, zero_lt_one]
· rw [← Ne] at hp_zero
have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm
rw [← zero_rpow_of_pos hp_pos]
exact rpow_lt_rpow hx_pos hp_pos
theorem rpow_pos {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hx_ne_top : x ≠ ⊤) : 0 < x ^ p := by
rcases lt_or_le 0 p with hp_pos | hp_nonpos
· exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos)
· rw [← neg_neg p, rpow_neg, ENNReal.inv_pos]
exact rpow_ne_top_of_nonneg (Right.nonneg_neg_iff.mpr hp_nonpos) hx_ne_top
theorem rpow_lt_one {x : ℝ≥0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x ^ z < 1 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx le_top)
simp only [coe_lt_one_iff] at hx
simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.rpow_lt_one hx hz]
theorem rpow_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top)
simp only [coe_le_one_iff] at hx
simp [← coe_rpow_of_nonneg _ hz, NNReal.rpow_le_one hx hz]
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by
cases x
· simp [top_rpow_of_neg hz, zero_lt_one]
· simp only [some_eq_coe, one_lt_coe_iff] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
NNReal.rpow_lt_one_of_one_lt_of_neg hx hz]
theorem rpow_le_one_of_one_le_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : z < 0) : x ^ z ≤ 1 := by
cases x
· simp [top_rpow_of_neg hz, zero_lt_one]
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
NNReal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)]
theorem one_lt_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by
cases x
· simp [top_rpow_of_pos hz]
· simp only [some_eq_coe, one_lt_coe_iff] at hx
simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_lt_rpow hx hz]
theorem one_le_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : 0 < z) : 1 ≤ x ^ z := by
cases x
· simp [top_rpow_of_pos hz]
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_nonneg _ (le_of_lt hz), NNReal.one_le_rpow hx (le_of_lt hz)]
theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx2 le_top)
simp only [coe_lt_one_iff, coe_pos] at hx1 hx2 ⊢
simp [← coe_rpow_of_ne_zero (ne_of_gt hx1), NNReal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz]
theorem one_le_rpow_of_pos_of_le_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z < 0) : 1 ≤ x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx2 coe_lt_top)
simp only [coe_le_one_iff, coe_pos] at hx1 hx2 ⊢
simp [← coe_rpow_of_ne_zero (ne_of_gt hx1),
NNReal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 (le_of_lt hz)]
@[simp] lemma toNNReal_rpow (x : ℝ≥0∞) (z : ℝ) : (x ^ z).toNNReal = x.toNNReal ^ z := by
rcases lt_trichotomy z 0 with (H | H | H)
· cases x with
| top => simp [H, ne_of_lt]
| coe x =>
by_cases hx : x = 0
· simp [hx, H, ne_of_lt]
· simp [← coe_rpow_of_ne_zero hx]
· simp [H]
· cases x
· simp [H, ne_of_gt]
simp [← coe_rpow_of_nonneg _ (le_of_lt H)]
theorem toReal_rpow (x : ℝ≥0∞) (z : ℝ) : x.toReal ^ z = (x ^ z).toReal := by
rw [ENNReal.toReal, ENNReal.toReal, ← NNReal.coe_rpow, ENNReal.toNNReal_rpow]
theorem ofReal_rpow_of_pos {x p : ℝ} (hx_pos : 0 < x) :
ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by
simp_rw [ENNReal.ofReal]
rw [← coe_rpow_of_ne_zero, coe_inj, Real.toNNReal_rpow_of_nonneg hx_pos.le]
simp [hx_pos]
theorem ofReal_rpow_of_nonneg {x p : ℝ} (hx_nonneg : 0 ≤ x) (hp_nonneg : 0 ≤ p) :
ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by
by_cases hp0 : p = 0
· simp [hp0]
by_cases hx0 : x = 0
· rw [← Ne] at hp0
have hp_pos : 0 < p := lt_of_le_of_ne hp_nonneg hp0.symm
simp [hx0, hp_pos, hp_pos.ne.symm]
rw [← Ne] at hx0
exact ofReal_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm)
@[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0∞) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0∞) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul, inv_mul_cancel₀ hy, rpow_one]
lemma pow_rpow_inv_natCast {n : ℕ} (hn : n ≠ 0) (x : ℝ≥0∞) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← rpow_natCast, ← rpow_mul, mul_inv_cancel₀ (by positivity), rpow_one]
lemma rpow_inv_natCast_pow {n : ℕ} (hn : n ≠ 0) (x : ℝ≥0∞) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← rpow_natCast, ← rpow_mul, inv_mul_cancel₀ (by positivity), rpow_one]
lemma rpow_natCast_mul (x : ℝ≥0∞) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_natCast]
lemma rpow_mul_natCast (x : ℝ≥0∞) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_natCast]
|
lemma rpow_intCast_mul (x : ℝ≥0∞) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 920 | 921 |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad
-/
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Data.Set.Finite.Range
import Mathlib.Data.Set.Lattice
import Mathlib.Topology.Defs.Filter
/-!
# Openness and closedness of a set
This file provides lemmas relating to the predicates `IsOpen` and `IsClosed` of a set endowed with
a topology.
## Implementation notes
Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in
<https://leanprover-community.github.io/theories/topology.html>.
## References
* [N. Bourbaki, *General Topology*][bourbaki1966]
* [I. M. James, *Topologies and Uniformities*][james1999]
## Tags
topological space
-/
open Set Filter Topology
universe u v
/-- A constructor for topologies by specifying the closed sets,
and showing that they satisfy the appropriate conditions. -/
def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T)
(sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T)
(union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where
IsOpen X := Xᶜ ∈ T
isOpen_univ := by simp [empty_mem]
isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht
isOpen_sUnion s hs := by
simp only [Set.compl_sUnion]
exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy
section TopologicalSpace
variable {X : Type u} {ι : Sort v} {α : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop}
lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl
@[ext (iff := false)]
protected theorem TopologicalSpace.ext :
∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl
protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} :
t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s :=
⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩
theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s :=
rfl
variable [TopologicalSpace X]
theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) :=
isOpen_sUnion (forall_mem_range.2 h)
theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋃ i ∈ s, f i) :=
isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi
theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by
rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩)
lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) :
IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by
refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩
rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter]
exact isOpen_iUnion fun i ↦ h i
@[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by
rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim
theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) (h : ∀ t ∈ s, IsOpen t) :
IsOpen (⋂₀ s) := by
induction s, hs using Set.Finite.induction_on with
| empty => rw [sInter_empty]; exact isOpen_univ
| insert _ _ ih =>
simp only [sInter_insert, forall_mem_insert] at h ⊢
exact h.1.inter (ih h.2)
theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite)
(h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋂ i ∈ s, f i) :=
sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h)
theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) :
IsOpen (⋂ i, s i) :=
(finite_range _).isOpen_sInter (forall_mem_range.2 h)
theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) :
IsOpen (⋂ i ∈ s, f i) :=
s.finite_toSet.isOpen_biInter h
@[simp]
theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*]
theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } :=
IsOpen.inter
@[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s :=
⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩
theorem TopologicalSpace.ext_iff_isClosed {X} {t₁ t₂ : TopologicalSpace X} :
t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by
rw [TopologicalSpace.ext_iff, compl_surjective.forall]
simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂]
alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed
theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩
@[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const
@[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const
lemma IsOpen.isLocallyClosed (hs : IsOpen s) : IsLocallyClosed s :=
⟨_, _, hs, isClosed_univ, (inter_univ _).symm⟩
lemma IsClosed.isLocallyClosed (hs : IsClosed s) : IsLocallyClosed s :=
⟨_, _, isOpen_univ, hs, (univ_inter _).symm⟩
theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by
simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter
theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by
simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion
theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) :=
isClosed_sInter <| forall_mem_range.2 h
theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋂ i ∈ s, f i) :=
isClosed_iInter fun i => isClosed_iInter <| h i
@[simp]
theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by
rw [← isOpen_compl_iff, compl_compl]
alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff
theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) :=
IsOpen.inter h₁ h₂.isOpen_compl
theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by
rw [← isOpen_compl_iff] at *
rw [compl_inter]
exact IsOpen.union h₁ h₂
theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) :=
IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂)
theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite)
(h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋃ i ∈ s, f i) := by
simp only [← isOpen_compl_iff, compl_iUnion] at *
exact hs.isOpen_biInter h
lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) :
IsClosed (⋃ i ∈ s, f i) :=
s.finite_toSet.isClosed_biUnion h
theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) :
IsClosed (⋃ i, s i) := by
simp only [← isOpen_compl_iff, compl_iUnion] at *
exact isOpen_iInter_of_finite h
theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) :
IsClosed { x | p x → q x } := by
simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq
theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } :=
isOpen_compl_iff.mpr
/-!
### Limits of filters in topological spaces
In this section we define functions that return a limit of a filter (or of a function along a
filter), if it exists, and a random point otherwise. These functions are rarely used in Mathlib,
most of the theorems are written using `Filter.Tendsto`. One of the reasons is that
`Filter.limUnder f g = x` is not equivalent to `Filter.Tendsto g f (𝓝 x)` unless the codomain is a
Hausdorff space and `g` has a limit along `f`.
-/
section lim
/-- If a filter `f` is majorated by some `𝓝 x`, then it is majorated by `𝓝 (Filter.lim f)`. We
formulate this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for
types without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify
this instance with any other instance. -/
theorem le_nhds_lim {f : Filter X} (h : ∃ x, f ≤ 𝓝 x) : f ≤ 𝓝 (@lim _ _ (nonempty_of_exists h) f) :=
Classical.epsilon_spec h
/-- If `g` tends to some `𝓝 x` along `f`, then it tends to `𝓝 (Filter.limUnder f g)`. We formulate
this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for types
without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify this
instance with any other instance. -/
theorem tendsto_nhds_limUnder {f : Filter α} {g : α → X} (h : ∃ x, Tendsto g f (𝓝 x)) :
Tendsto g f (𝓝 (@limUnder _ _ _ (nonempty_of_exists h) f g)) :=
le_nhds_lim h
theorem limUnder_of_not_tendsto [hX : Nonempty X] {f : Filter α} {g : α → X}
(h : ¬ ∃ x, Tendsto g f (𝓝 x)) :
limUnder f g = Classical.choice hX := by
simp_rw [Tendsto] at h
simp_rw [limUnder, lim, Classical.epsilon, Classical.strongIndefiniteDescription, dif_neg h]
end lim
end TopologicalSpace
| Mathlib/Topology/Basic.lean | 483 | 484 | |
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Shift.CommShift
/-!
# Functors from a category to a category with a shift
Given a category `C`, and a category `D` equipped with a shift by a monoid `A`,
we define a structure `SingleFunctors C D A` which contains the data of
functors `functor a : C ⥤ D` for all `a : A` and isomorphisms
`shiftIso n a a' h : functor a' ⋙ shiftFunctor D n ≅ functor a`
whenever `n + a = a'`. These isomorphisms should satisfy certain compatibilities
with respect to the shift on `D`.
This notion is similar to `Functor.ShiftSequence` which can be used in order to
attach shifted versions of a homological functor `D ⥤ C` with `D` a
triangulated category and `C` an abelian category. However, the definition
`SingleFunctors` is for functors in the other direction: it is meant to
ease the formalization of the compatibilities with shifts of the
functors `C ⥤ CochainComplex C ℤ` (or `C ⥤ DerivedCategory C` (TODO))
which sends an object `X : C` to a complex where `X` sits in a single degree.
-/
open CategoryTheory Category ZeroObject Limits
variable (C D E E' : Type*) [Category C] [Category D] [Category E] [Category E']
(A : Type*) [AddMonoid A] [HasShift D A] [HasShift E A] [HasShift E' A]
namespace CategoryTheory
/-- The type of families of functors `A → C ⥤ D` which are compatible with
the shift by `A` on the category `D`. -/
structure SingleFunctors where
/-- a family of functors `C ⥤ D` indexed by the elements of the additive monoid `A` -/
functor (a : A) : C ⥤ D
/-- the isomorphism `functor a' ⋙ shiftFunctor D n ≅ functor a` when `n + a = a'` -/
shiftIso (n a a' : A) (ha' : n + a = a') : functor a' ⋙ shiftFunctor D n ≅ functor a
/-- `shiftIso 0` is the obvious isomorphism. -/
shiftIso_zero (a : A) :
shiftIso 0 a a (zero_add a) = isoWhiskerLeft _ (shiftFunctorZero D A)
/-- `shiftIso (m + n)` is determined by `shiftIso m` and `shiftIso n`. -/
shiftIso_add (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') :
shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) =
isoWhiskerLeft _ (shiftFunctorAdd D m n) ≪≫ (Functor.associator _ _ _).symm ≪≫
isoWhiskerRight (shiftIso m a' a'' ha'') _ ≪≫ shiftIso n a a' ha'
variable {C D E A}
variable (F G H : SingleFunctors C D A)
namespace SingleFunctors
lemma shiftIso_add_hom_app (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X =
(shiftFunctorAdd D m n).hom.app ((F.functor a'').obj X) ≫
((F.shiftIso m a' a'' ha'').hom.app X)⟦n⟧' ≫
(F.shiftIso n a a' ha').hom.app X := by
simp [F.shiftIso_add n m a a' a'' ha' ha'']
| lemma shiftIso_add_inv_app (n m a a' a'' : A) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
(F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X =
(F.shiftIso n a a' ha').inv.app X ≫
((F.shiftIso m a' a'' ha'').inv.app X)⟦n⟧' ≫
(shiftFunctorAdd D m n).inv.app ((F.functor a'').obj X) := by
simp [F.shiftIso_add n m a a' a'' ha' ha'']
| Mathlib/CategoryTheory/Shift/SingleFunctors.lean | 63 | 68 |
/-
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.List.TakeDrop
import Mathlib.Data.List.Induction
/-!
# Prefixes, suffixes, infixes
This file proves properties about
* `List.isPrefix`: `l₁` is a prefix of `l₂` if `l₂` starts with `l₁`.
* `List.isSuffix`: `l₁` is a suffix of `l₂` if `l₂` ends with `l₁`.
* `List.isInfix`: `l₁` is an infix of `l₂` if `l₁` is a prefix of some suffix of `l₂`.
* `List.inits`: The list of prefixes of a list.
* `List.tails`: The list of prefixes of a list.
* `insert` on lists
All those (except `insert`) are defined in `Mathlib.Data.List.Defs`.
## Notation
* `l₁ <+: l₂`: `l₁` is a prefix of `l₂`.
* `l₁ <:+ l₂`: `l₁` is a suffix of `l₂`.
* `l₁ <:+: l₂`: `l₁` is an infix of `l₂`.
-/
variable {α β : Type*}
namespace List
variable {l l₁ l₂ l₃ : List α} {a b : α}
/-! ### prefix, suffix, infix -/
section Fix
@[gcongr] lemma IsPrefix.take (h : l₁ <+: l₂) (n : ℕ) : l₁.take n <+: l₂.take n := by
simpa [prefix_take_iff, Nat.min_le_left] using (take_prefix n l₁).trans h
@[gcongr] lemma IsPrefix.drop (h : l₁ <+: l₂) (n : ℕ) : l₁.drop n <+: l₂.drop n := by
rw [prefix_iff_eq_take.mp h, drop_take]; apply take_prefix
attribute [gcongr] take_prefix_take_left
lemma isPrefix_append_of_length (h : l₁.length ≤ l₂.length) : l₁ <+: l₂ ++ l₃ ↔ l₁ <+: l₂ :=
⟨fun h ↦ by rw [prefix_iff_eq_take] at *; nth_rw 1 [h, take_eq_left_iff]; tauto,
fun h ↦ h.trans <| l₂.prefix_append l₃⟩
@[simp] lemma take_isPrefix_take {m n : ℕ} : l.take m <+: l.take n ↔ m ≤ n ∨ l.length ≤ n := by
simp [prefix_take_iff, take_prefix]; omega
@[gcongr]
protected theorem IsPrefix.flatten {l₁ l₂ : List (List α)} (h : l₁ <+: l₂) :
l₁.flatten <+: l₂.flatten := by
rcases h with ⟨l, rfl⟩
simp
@[gcongr]
protected theorem IsPrefix.flatMap (h : l₁ <+: l₂) (f : α → List β) :
l₁.flatMap f <+: l₂.flatMap f :=
(h.map _).flatten
@[gcongr]
protected theorem IsSuffix.flatten {l₁ l₂ : List (List α)} (h : l₁ <:+ l₂) :
l₁.flatten <:+ l₂.flatten := by
rcases h with ⟨l, rfl⟩
simp
@[gcongr]
protected theorem IsSuffix.flatMap (h : l₁ <:+ l₂) (f : α → List β) :
l₁.flatMap f <:+ l₂.flatMap f :=
(h.map _).flatten
@[gcongr]
protected theorem IsInfix.flatten {l₁ l₂ : List (List α)} (h : l₁ <:+: l₂) :
l₁.flatten <:+: l₂.flatten := by
rcases h with ⟨l, l', rfl⟩
simp
@[gcongr]
protected theorem IsInfix.flatMap (h : l₁ <:+: l₂) (f : α → List β) :
l₁.flatMap f <:+: l₂.flatMap f :=
(h.map _).flatten
lemma dropSlice_sublist (n m : ℕ) (l : List α) : l.dropSlice n m <+ l :=
calc
l.dropSlice n m = take n l ++ drop m (drop n l) := by rw [dropSlice_eq, drop_drop, Nat.add_comm]
_ <+ take n l ++ drop n l := (Sublist.refl _).append (drop_sublist _ _)
_ = _ := take_append_drop _ _
lemma dropSlice_subset (n m : ℕ) (l : List α) : l.dropSlice n m ⊆ l :=
(dropSlice_sublist n m l).subset
lemma mem_of_mem_dropSlice {n m : ℕ} {l : List α} {a : α} (h : a ∈ l.dropSlice n m) : a ∈ l :=
dropSlice_subset n m l h
theorem tail_subset (l : List α) : tail l ⊆ l :=
(tail_sublist l).subset
theorem mem_of_mem_dropLast (h : a ∈ l.dropLast) : a ∈ l :=
dropLast_subset l h
attribute [gcongr] Sublist.drop
attribute [refl] prefix_refl suffix_refl infix_refl
theorem concat_get_prefix {x y : List α} (h : x <+: y) (hl : x.length < y.length) :
x ++ [y.get ⟨x.length, hl⟩] <+: y := by
use y.drop (x.length + 1)
nth_rw 1 [List.prefix_iff_eq_take.mp h]
convert List.take_append_drop (x.length + 1) y using 2
rw [← List.take_concat_get, List.concat_eq_append]; rfl
instance decidableInfix [DecidableEq α] : ∀ l₁ l₂ : List α, Decidable (l₁ <:+: l₂)
| [], l₂ => isTrue ⟨[], l₂, rfl⟩
| a :: l₁, [] => isFalse fun ⟨s, t, te⟩ => by simp at te
| l₁, b :: l₂ =>
letI := l₁.decidableInfix l₂
@decidable_of_decidable_of_iff (l₁ <+: b :: l₂ ∨ l₁ <:+: l₂) _ _
infix_cons_iff.symm
protected theorem IsPrefix.reduceOption {l₁ l₂ : List (Option α)} (h : l₁ <+: l₂) :
l₁.reduceOption <+: l₂.reduceOption :=
h.filterMap id
instance : IsPartialOrder (List α) (· <+: ·) where
refl _ := prefix_rfl
trans _ _ _ := IsPrefix.trans
antisymm _ _ h₁ h₂ := h₁.eq_of_length <| h₁.length_le.antisymm h₂.length_le
instance : IsPartialOrder (List α) (· <:+ ·) where
refl _ := suffix_rfl
trans _ _ _ := IsSuffix.trans
antisymm _ _ h₁ h₂ := h₁.eq_of_length <| h₁.length_le.antisymm h₂.length_le
instance : IsPartialOrder (List α) (· <:+: ·) where
refl _ := infix_rfl
trans _ _ _ := IsInfix.trans
antisymm _ _ h₁ h₂ := h₁.eq_of_length <| h₁.length_le.antisymm h₂.length_le
end Fix
section InitsTails
@[simp]
theorem mem_inits : ∀ s t : List α, s ∈ inits t ↔ s <+: t
| s, [] =>
suffices s = nil ↔ s <+: nil by simpa only [inits, mem_singleton]
⟨fun h => h.symm ▸ prefix_rfl, eq_nil_of_prefix_nil⟩
| s, a :: t =>
suffices (s = nil ∨ ∃ l ∈ inits t, a :: l = s) ↔ s <+: a :: t by simpa
⟨fun o =>
match s, o with
| _, Or.inl rfl => ⟨_, rfl⟩
| s, Or.inr ⟨r, hr, hs⟩ => by
let ⟨s, ht⟩ := (mem_inits _ _).1 hr
rw [← hs, ← ht]; exact ⟨s, rfl⟩,
fun mi =>
match s, mi with
| [], ⟨_, rfl⟩ => Or.inl rfl
| b :: s, ⟨r, hr⟩ =>
(List.noConfusion hr) fun ba (st : s ++ r = t) =>
Or.inr <| by rw [ba]; exact ⟨_, (mem_inits _ _).2 ⟨_, st⟩, rfl⟩⟩
@[simp]
theorem mem_tails : ∀ s t : List α, s ∈ tails t ↔ s <:+ t
| s, [] => by
simp only [tails, mem_singleton, suffix_nil]
| s, a :: t => by
simp only [tails, mem_cons, mem_tails s t]
exact
show s = a :: t ∨ s <:+ t ↔ s <:+ a :: t from
⟨fun o =>
match s, t, o with
| _, t, Or.inl rfl => suffix_rfl
| s, _, Or.inr ⟨l, rfl⟩ => ⟨a :: l, rfl⟩,
fun e =>
match s, t, e with
| _, t, ⟨[], rfl⟩ => Or.inl rfl
| s, t, ⟨b :: l, he⟩ => List.noConfusion he fun _ lt => Or.inr ⟨l, lt⟩⟩
theorem inits_cons (a : α) (l : List α) : inits (a :: l) = [] :: l.inits.map fun t => a :: t := by
simp
theorem tails_cons (a : α) (l : List α) : tails (a :: l) = (a :: l) :: l.tails := by simp
@[simp]
theorem inits_append : ∀ s t : List α, inits (s ++ t) = s.inits ++ t.inits.tail.map fun l => s ++ l
| [], [] => by simp
| [], a :: t => by simp
| a :: s, t => by simp [inits_append s t, Function.comp_def]
@[simp]
theorem tails_append :
∀ s t : List α, tails (s ++ t) = (s.tails.map fun l => l ++ t) ++ t.tails.tail
| [], [] => by simp
| [], a :: t => by simp
| a :: s, t => by simp [tails_append s t]
-- the lemma names `inits_eq_tails` and `tails_eq_inits` are like `sublists_eq_sublists'`
theorem inits_eq_tails : ∀ l : List α, l.inits = (reverse <| map reverse <| tails <| reverse l)
| [] => by simp
| a :: l => by simp [inits_eq_tails l, map_inj_left, ← map_reverse]
theorem tails_eq_inits : ∀ l : List α, l.tails = (reverse <| map reverse <| inits <| reverse l)
| [] => by simp
| a :: l => by simp [tails_eq_inits l, append_left_inj]
theorem inits_reverse (l : List α) : inits (reverse l) = reverse (map reverse l.tails) := by
rw [tails_eq_inits l]
simp [reverse_involutive.comp_self, ← map_reverse]
theorem tails_reverse (l : List α) : tails (reverse l) = reverse (map reverse l.inits) := by
rw [inits_eq_tails l]
simp [reverse_involutive.comp_self, ← map_reverse]
theorem map_reverse_inits (l : List α) : map reverse l.inits = (reverse <| tails <| reverse l) := by
rw [inits_eq_tails l]
simp [reverse_involutive.comp_self, ← map_reverse]
theorem map_reverse_tails (l : List α) : map reverse l.tails = (reverse <| inits <| reverse l) := by
rw [tails_eq_inits l]
simp [reverse_involutive.comp_self, ← map_reverse]
@[simp]
theorem length_tails (l : List α) : length (tails l) = length l + 1 := by
induction' l with x l IH
· simp
· simpa using IH
@[simp]
theorem length_inits (l : List α) : length (inits l) = length l + 1 := by simp [inits_eq_tails]
@[simp]
theorem getElem_tails (l : List α) (n : Nat) (h : n < (tails l).length) :
(tails l)[n] = l.drop n := by
induction l generalizing n with
| nil => simp
| cons a l ihl =>
cases n with
| zero => simp
| succ n => simp [ihl]
theorem get_tails (l : List α) (n : Fin (length (tails l))) : (tails l).get n = l.drop n := by
simp
@[simp]
theorem getElem_inits (l : List α) (n : Nat) (h : n < length (inits l)) :
(inits l)[n] = l.take n := by
induction l generalizing n with
| nil => simp
| cons a l ihl =>
cases n with
| zero => simp
| succ n => simp [ihl]
theorem get_inits (l : List α) (n : Fin (length (inits l))) : (inits l).get n = l.take n := by
simp
lemma map_inits {β : Type*} (g : α → β) : (l.map g).inits = l.inits.map (map g) := by
induction' l using reverseRecOn <;> simp [*]
lemma map_tails {β : Type*} (g : α → β) : (l.map g).tails = l.tails.map (map g) := by
induction' l using reverseRecOn <;> simp [*]
lemma take_inits {n} : (l.take n).inits = l.inits.take (n + 1) := by
apply ext_getElem <;> (simp [take_take] <;> omega)
end InitsTails
/-! ### insert -/
section Insert
variable [DecidableEq α]
theorem insert_eq_ite (a : α) (l : List α) : insert a l = if a ∈ l then l else a :: l := by
simp only [← elem_iff]
rfl
@[simp]
theorem suffix_insert (a : α) (l : List α) : l <:+ l.insert a := by
by_cases h : a ∈ l
· simp only [insert_of_mem h, insert, suffix_refl]
· simp only [insert_of_not_mem h, suffix_cons, insert]
theorem infix_insert (a : α) (l : List α) : l <:+: l.insert a :=
(suffix_insert a l).isInfix
theorem sublist_insert (a : α) (l : List α) : l <+ l.insert a :=
(suffix_insert a l).sublist
theorem subset_insert (a : α) (l : List α) : l ⊆ l.insert a :=
(sublist_insert a l).subset
end Insert
end List
| Mathlib/Data/List/Infix.lean | 524 | 527 | |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Module.Opposite
import Mathlib.Topology.Algebra.Group.Quotient
import Mathlib.Topology.Algebra.Ring.Basic
import Mathlib.Topology.UniformSpace.UniformEmbedding
import Mathlib.LinearAlgebra.Finsupp.LinearCombination
import Mathlib.LinearAlgebra.Pi
import Mathlib.LinearAlgebra.Quotient.Defs
/-!
# Theory of topological modules
We use the class `ContinuousSMul` for topological (semi) modules and topological vector spaces.
-/
assert_not_exists Star.star
open LinearMap (ker range)
open Topology Filter Pointwise
universe u v w u'
section
variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M]
[AddCommGroup M] [Module R M]
theorem ContinuousSMul.of_nhds_zero [IsTopologicalRing R] [IsTopologicalAddGroup M]
(hmul : Tendsto (fun p : R × M => p.1 • p.2) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0))
(hmulleft : ∀ m : M, Tendsto (fun a : R => a • m) (𝓝 0) (𝓝 0))
(hmulright : ∀ a : R, Tendsto (fun m : M => a • m) (𝓝 0) (𝓝 0)) : ContinuousSMul R M where
continuous_smul := by
rw [← nhds_prod_eq] at hmul
refine continuous_of_continuousAt_zero₂ (AddMonoidHom.smul : R →+ M →+ M) ?_ ?_ ?_ <;>
simpa [ContinuousAt]
variable (R M) in
omit [TopologicalSpace R] in
/-- A topological module over a ring has continuous negation.
This cannot be an instance, because it would cause search for `[Module ?R M]` with unknown `R`. -/
theorem ContinuousNeg.of_continuousConstSMul [ContinuousConstSMul R M] : ContinuousNeg M where
continuous_neg := by simpa using continuous_const_smul (T := M) (-1 : R)
end
section
variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M]
[AddCommGroup M] [ContinuousAdd M] [Module R M] [ContinuousSMul R M]
/-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then
`⊤` is the only submodule of `M` with a nonempty interior.
This is the case, e.g., if `R` is a nontrivially normed field. -/
theorem Submodule.eq_top_of_nonempty_interior' [NeBot (𝓝[{ x : R | IsUnit x }] 0)]
(s : Submodule R M) (hs : (interior (s : Set M)).Nonempty) : s = ⊤ := by
rcases hs with ⟨y, hy⟩
refine Submodule.eq_top_iff'.2 fun x => ?_
rw [mem_interior_iff_mem_nhds] at hy
have : Tendsto (fun c : R => y + c • x) (𝓝[{ x : R | IsUnit x }] 0) (𝓝 (y + (0 : R) • x)) :=
tendsto_const_nhds.add ((tendsto_nhdsWithin_of_tendsto_nhds tendsto_id).smul tendsto_const_nhds)
rw [zero_smul, add_zero] at this
obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ :=
nonempty_of_mem (inter_mem (Filter.mem_map.1 (this hy)) self_mem_nhdsWithin)
have hy' : y ∈ ↑s := mem_of_mem_nhds hy
rwa [s.add_mem_iff_right hy', ← Units.smul_def, s.smul_mem_iff' u] at hu
variable (R M)
/-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nontrivially
normed field, see `NormedField.punctured_nhds_neBot`). Let `M` be a nontrivial module over `R`
such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this
using `NeBot (𝓝[≠] x)`.
This lemma is not an instance because Lean would need to find `[ContinuousSMul ?m_1 M]` with
unknown `?m_1`. We register this as an instance for `R = ℝ` in `Real.punctured_nhds_module_neBot`.
One can also use `haveI := Module.punctured_nhds_neBot R M` in a proof.
-/
theorem Module.punctured_nhds_neBot [Nontrivial M] [NeBot (𝓝[≠] (0 : R))] [NoZeroSMulDivisors R M]
(x : M) : NeBot (𝓝[≠] x) := by
rcases exists_ne (0 : M) with ⟨y, hy⟩
suffices Tendsto (fun c : R => x + c • y) (𝓝[≠] 0) (𝓝[≠] x) from this.neBot
refine Tendsto.inf ?_ (tendsto_principal_principal.2 <| ?_)
· convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y)
rw [zero_smul, add_zero]
· intro c hc
simpa [hy] using hc
end
section LatticeOps
variable {R M₁ M₂ : Type*} [SMul R M₁] [SMul R M₂] [u : TopologicalSpace R]
{t : TopologicalSpace M₂} [ContinuousSMul R M₂]
{F : Type*} [FunLike F M₁ M₂] [MulActionHomClass F R M₁ M₂] (f : F)
theorem continuousSMul_induced : @ContinuousSMul R M₁ _ u (t.induced f) :=
let _ : TopologicalSpace M₁ := t.induced f
IsInducing.continuousSMul ⟨rfl⟩ continuous_id (map_smul f _ _)
end LatticeOps
/-- The span of a separable subset with respect to a separable scalar ring is again separable. -/
lemma TopologicalSpace.IsSeparable.span {R M : Type*} [AddCommMonoid M] [Semiring R] [Module R M]
[TopologicalSpace M] [TopologicalSpace R] [SeparableSpace R]
[ContinuousAdd M] [ContinuousSMul R M] {s : Set M} (hs : IsSeparable s) :
IsSeparable (Submodule.span R s : Set M) := by
rw [Submodule.span_eq_iUnion_nat]
refine .iUnion fun n ↦ .image ?_ ?_
· have : IsSeparable {f : Fin n → R × M | ∀ (i : Fin n), f i ∈ Set.univ ×ˢ s} := by
apply isSeparable_pi (fun i ↦ .prod (.of_separableSpace Set.univ) hs)
rwa [Set.univ_prod] at this
· apply continuous_finset_sum _ (fun i _ ↦ ?_)
exact (continuous_fst.comp (continuous_apply i)).smul (continuous_snd.comp (continuous_apply i))
namespace Submodule
instance topologicalAddGroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
[TopologicalSpace M] [IsTopologicalAddGroup M] (S : Submodule R M) : IsTopologicalAddGroup S :=
inferInstanceAs (IsTopologicalAddGroup S.toAddSubgroup)
end Submodule
section closure
variable {R : Type u} {M : Type v} [Semiring R] [TopologicalSpace M] [AddCommMonoid M] [Module R M]
[ContinuousConstSMul R M]
theorem Submodule.mapsTo_smul_closure (s : Submodule R M) (c : R) :
Set.MapsTo (c • ·) (closure s : Set M) (closure s) :=
have : Set.MapsTo (c • ·) (s : Set M) s := fun _ h ↦ s.smul_mem c h
this.closure (continuous_const_smul c)
theorem Submodule.smul_closure_subset (s : Submodule R M) (c : R) :
c • closure (s : Set M) ⊆ closure (s : Set M) :=
(s.mapsTo_smul_closure c).image_subset
variable [ContinuousAdd M]
/-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself
a submodule. -/
def Submodule.topologicalClosure (s : Submodule R M) : Submodule R M :=
{ s.toAddSubmonoid.topologicalClosure with
smul_mem' := s.mapsTo_smul_closure }
@[simp, norm_cast]
theorem Submodule.topologicalClosure_coe (s : Submodule R M) :
(s.topologicalClosure : Set M) = closure (s : Set M) :=
rfl
theorem Submodule.le_topologicalClosure (s : Submodule R M) : s ≤ s.topologicalClosure :=
subset_closure
theorem Submodule.closure_subset_topologicalClosure_span (s : Set M) :
closure s ⊆ (span R s).topologicalClosure := by
rw [Submodule.topologicalClosure_coe]
exact closure_mono subset_span
theorem Submodule.isClosed_topologicalClosure (s : Submodule R M) :
IsClosed (s.topologicalClosure : Set M) := isClosed_closure
theorem Submodule.topologicalClosure_minimal (s : Submodule R M) {t : Submodule R M} (h : s ≤ t)
(ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t :=
closure_minimal h ht
theorem Submodule.topologicalClosure_mono {s : Submodule R M} {t : Submodule R M} (h : s ≤ t) :
s.topologicalClosure ≤ t.topologicalClosure :=
closure_mono h
/-- The topological closure of a closed submodule `s` is equal to `s`. -/
theorem IsClosed.submodule_topologicalClosure_eq {s : Submodule R M} (hs : IsClosed (s : Set M)) :
s.topologicalClosure = s :=
SetLike.ext' hs.closure_eq
/-- A subspace is dense iff its topological closure is the entire space. -/
theorem Submodule.dense_iff_topologicalClosure_eq_top {s : Submodule R M} :
Dense (s : Set M) ↔ s.topologicalClosure = ⊤ := by
rw [← SetLike.coe_set_eq, dense_iff_closure_eq]
simp
instance Submodule.topologicalClosure.completeSpace {M' : Type*} [AddCommMonoid M'] [Module R M']
[UniformSpace M'] [ContinuousAdd M'] [ContinuousConstSMul R M'] [CompleteSpace M']
(U : Submodule R M') : CompleteSpace U.topologicalClosure :=
isClosed_closure.completeSpace_coe
/-- A maximal proper subspace of a topological module (i.e a `Submodule` satisfying `IsCoatom`)
is either closed or dense. -/
theorem Submodule.isClosed_or_dense_of_isCoatom (s : Submodule R M) (hs : IsCoatom s) :
IsClosed (s : Set M) ∨ Dense (s : Set M) := by
refine (hs.le_iff.mp s.le_topologicalClosure).symm.imp ?_ dense_iff_topologicalClosure_eq_top.mpr
exact fun h ↦ h ▸ isClosed_closure
end closure
namespace Submodule
variable {ι R : Type*} {M : ι → Type*} [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
[∀ i, TopologicalSpace (M i)] [DecidableEq ι]
/-- If `s i` is a family of submodules, each is in its module,
then the closure of their span in the indexed product of the modules
is the product of their closures.
In case of a finite index type, this statement immediately follows from `Submodule.iSup_map_single`.
However, the statement is true for an infinite index type as well. -/
theorem closure_coe_iSup_map_single (s : ∀ i, Submodule R (M i)) :
closure (↑(⨆ i, (s i).map (LinearMap.single R M i)) : Set (∀ i, M i)) =
Set.univ.pi fun i ↦ closure (s i) := by
rw [← closure_pi_set]
refine (closure_mono ?_).antisymm <| closure_minimal ?_ isClosed_closure
· exact SetLike.coe_mono <| iSup_map_single_le
· simp only [Set.subset_def, mem_closure_iff]
intro x hx U hU hxU
rcases isOpen_pi_iff.mp hU x hxU with ⟨t, V, hV, hVU⟩
refine ⟨∑ i ∈ t, Pi.single i (x i), hVU ?_, ?_⟩
· simp_all [Finset.sum_pi_single]
· exact sum_mem fun i hi ↦ mem_iSup_of_mem i <| mem_map_of_mem <| hx _ <| Set.mem_univ _
| /-- If `s i` is a family of submodules, each is in its module,
then the closure of their span in the indexed product of the modules
is the product of their closures.
In case of a finite index type, this statement immediately follows from `Submodule.iSup_map_single`.
However, the statement is true for an infinite index type as well.
This version is stated in terms of `Submodule.topologicalClosure`,
thus assumes that `M i`s are topological modules over `R`.
However, the statement is true without assuming continuity of the operations,
see `Submodule.closure_coe_iSup_map_single` above. -/
theorem topologicalClosure_iSup_map_single [∀ i, ContinuousAdd (M i)]
[∀ i, ContinuousConstSMul R (M i)] (s : ∀ i, Submodule R (M i)) :
| Mathlib/Topology/Algebra/Module/Basic.lean | 224 | 236 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.Data.Finset.Sym
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.LinearAlgebra.Matrix.Symmetric
/-!
# Quadratic maps
This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`.
An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such
that:
* `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x`
* `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`,
`QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`:
the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear.
This notion generalizes to commutative semirings using the approach in [izhakian2016][] which
requires that there be a (possibly non-unique) companion bilinear map `B` such that
`∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`.
To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`.
Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `QuadraticMap.ofPolar`: a more familiar constructor that works on rings
* `QuadraticMap.associated`: associated bilinear map
* `QuadraticMap.PosDef`: positive definite quadratic maps
* `QuadraticMap.Anisotropic`: anisotropic quadratic maps
* `QuadraticMap.discr`: discriminant of a quadratic map
* `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map.
## Main statements
* `QuadraticMap.associated_left_inverse`,
* `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic maps and symmetric
bilinear forms
* `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear map `B`.
## Notation
In this file, the variable `R` is used when a `CommSemiring` structure is available.
The variable `S` is used when `R` itself has a `•` action.
## Implementation notes
While the definition and many results make sense if we drop commutativity assumptions,
the correct definition of a quadratic maps in the noncommutative setting would require
substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some
suitable conjugation $r^*$.
The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867)
has some further discussion.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic map, homogeneous polynomial, quadratic polynomial
-/
universe u v w
variable {S T : Type*}
variable {R : Type*} {M N P A : Type*}
open LinearMap (BilinMap BilinForm)
section Polar
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
namespace QuadraticMap
/-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`.
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → N) (x y : M) :=
f (x + y) - f x - f y
protected theorem map_add (f : M → N) (x y : M) :
f (x + y) = f x + f y + polar f x y := by
rw [polar]
abel
theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
abel
theorem polar_neg (f : M → N) (x y : M) : polar (-f) x y = -polar f x y := by
simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add]
theorem polar_smul [Monoid S] [DistribMulAction S N] (f : M → N) (s : S) (x y : M) :
polar (s • f) x y = s • polar f x y := by simp only [polar, Pi.smul_apply, smul_sub]
theorem polar_comm (f : M → N) (x y : M) : polar f x y = polar f y x := by
rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
/-- Auxiliary lemma to express bilinearity of `QuadraticMap.polar` without subtraction. -/
theorem polar_add_left_iff {f : M → N} {x x' y : M} :
polar f (x + x') y = polar f x y + polar f x' y ↔
f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by
simp only [← add_assoc]
simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub]
simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)]
rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)),
add_right_comm (f (x + y)), add_left_inj]
theorem polar_comp {F : Type*} [AddCommGroup S] [FunLike F N S] [AddMonoidHomClass F N S]
(f : M → N) (g : F) (x y : M) :
polar (g ∘ f) x y = g (polar f x y) := by
simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub]
/-- `QuadraticMap.polar` as a function from `Sym2`. -/
def polarSym2 (f : M → N) : Sym2 M → N :=
Sym2.lift ⟨polar f, polar_comm _⟩
@[simp]
lemma polarSym2_sym2Mk (f : M → N) (xy : M × M) : polarSym2 f (.mk xy) = polar f xy.1 xy.2 := rfl
end QuadraticMap
end Polar
/-- A quadratic map on a module.
For a more familiar constructor when `R` is a ring, see `QuadraticMap.ofPolar`. -/
structure QuadraticMap (R : Type u) (M : Type v) (N : Type w) [CommSemiring R] [AddCommMonoid M]
[Module R M] [AddCommMonoid N] [Module R N] where
toFun : M → N
toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = (a * a) • toFun x
exists_companion' : ∃ B : BilinMap R M N, ∀ x y, toFun (x + y) = toFun x + toFun y + B x y
section QuadraticForm
variable (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M]
/-- A quadratic form on a module. -/
abbrev QuadraticForm : Type _ := QuadraticMap R M R
end QuadraticForm
namespace QuadraticMap
section DFunLike
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable {Q Q' : QuadraticMap R M N}
instance instFunLike : FunLike (QuadraticMap R M N) M N where
coe := toFun
coe_injective' x y h := by cases x; cases y; congr
variable (Q)
/-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/
@[simp]
theorem toFun_eq_coe : Q.toFun = ⇑Q :=
rfl
-- this must come after the coe_to_fun definition
initialize_simps_projections QuadraticMap (toFun → apply)
variable {Q}
@[ext]
theorem ext (H : ∀ x : M, Q x = Q' x) : Q = Q' :=
DFunLike.ext _ _ H
theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x :=
DFunLike.congr_fun h _
/-- Copy of a `QuadraticMap` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : QuadraticMap R M N where
toFun := Q'
toFun_smul := h.symm ▸ Q.toFun_smul
exists_companion' := h.symm ▸ Q.exists_companion'
@[simp]
theorem coe_copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' :=
rfl
theorem copy_eq (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : Q.copy Q' h = Q :=
DFunLike.ext' h
end DFunLike
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable (Q : QuadraticMap R M N)
protected theorem map_smul (a : R) (x : M) : Q (a • x) = (a * a) • Q x :=
Q.toFun_smul a x
theorem exists_companion : ∃ B : BilinMap R M N, ∀ x y, Q (x + y) = Q x + Q y + B x y :=
Q.exists_companion'
theorem map_add_add_add_map (x y z : M) :
Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by
obtain ⟨B, h⟩ := Q.exists_companion
rw [add_comm z x]
simp only [h, LinearMap.map_add₂]
abel
theorem map_add_self (x : M) : Q (x + x) = 4 • Q x := by
rw [← two_smul R x, Q.map_smul, ← Nat.cast_smul_eq_nsmul R]
norm_num
-- not @[simp] because it is superseded by `ZeroHomClass.map_zero`
protected theorem map_zero : Q 0 = 0 := by
rw [← @zero_smul R _ _ _ _ (0 : M), Q.map_smul, zero_mul, zero_smul]
instance zeroHomClass : ZeroHomClass (QuadraticMap R M N) M N :=
{ QuadraticMap.instFunLike (R := R) (M := M) (N := N) with map_zero := QuadraticMap.map_zero }
theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [SMul S M] [IsScalarTower S R M]
[Module S N] [IsScalarTower S R N] (a : S)
(x : M) : Q (a • x) = (a * a) • Q x := by
rw [← IsScalarTower.algebraMap_smul R a x, Q.map_smul, ← RingHom.map_mul, algebraMap_smul]
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] (Q : QuadraticMap R M N)
@[simp]
protected theorem map_neg (x : M) : Q (-x) = Q x := by
rw [← @neg_one_smul R _ _ _ _ x, Q.map_smul, neg_one_mul, neg_neg, one_smul]
protected theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, Q.map_neg]
@[simp]
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by
simp only [polar, zero_add, QuadraticMap.map_zero, sub_zero, sub_self]
@[simp]
theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y :=
polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a • polar Q x y := by
obtain ⟨B, h⟩ := Q.exists_companion
simp_rw [polar, h, Q.map_smul, LinearMap.map_smul₂, sub_sub, add_sub_cancel_left]
@[simp]
theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by
rw [← neg_one_smul R x, polar_smul_left, neg_one_smul]
@[simp]
theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by
simp only [add_zero, polar, QuadraticMap.map_zero, sub_self]
@[simp]
theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by
rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left]
@[simp]
theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a • polar Q x y := by
rw [polar_comm Q x, polar_comm Q x, polar_smul_left]
@[simp]
theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by
rw [← neg_one_smul R y, polar_smul_right, neg_one_smul]
@[simp]
theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
@[simp]
theorem polar_self (x : M) : polar Q x x = 2 • Q x := by
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_smul ℕ, ← two_smul ℕ, ← mul_smul]
norm_num
/-- `QuadraticMap.polar` as a bilinear map -/
@[simps!]
def polarBilin : BilinMap R M N :=
LinearMap.mk₂ R (polar Q) (polar_add_left Q) (polar_smul_left Q) (polar_add_right Q)
(polar_smul_right Q)
lemma polarSym2_map_smul {ι} (Q : QuadraticMap R M N) (g : ι → M) (l : ι → R) (p : Sym2 ι) :
polarSym2 Q (p.map (l • g)) = (p.map l).mul • polarSym2 Q (p.map g) := by
obtain ⟨_, _⟩ := p; simp [← smul_assoc, mul_comm]
variable [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] [Module S N]
[IsScalarTower S R N]
|
@[simp]
| Mathlib/LinearAlgebra/QuadraticForm/Basic.lean | 311 | 312 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.