path
stringlengths
11
71
content
stringlengths
75
124k
Analysis\Calculus\LocalExtr\LineDeriv.lean
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.LocalExtr.Basic import Mathlib.Analysis.Calculus.LineDeriv.Basic /-! # Local extremum and line derivatives If `f` has a local extremum at a point, then the derivative at this point is zero. In this file we prove several versions of this fact for line derivatives. -/ open Function Set Filter open scoped Topology section Module variable {E : Type*} [AddCommGroup E] [Module ℝ E] {f : E → ℝ} {s : Set E} {a b : E} {f' : ℝ} theorem IsExtrFilter.hasLineDerivAt_eq_zero {l : Filter E} (h : IsExtrFilter f l a) (hd : HasLineDerivAt ℝ f f' a b) (h' : Tendsto (fun t : ℝ ↦ a + t • b) (𝓝 0) l) : f' = 0 := IsLocalExtr.hasDerivAt_eq_zero (IsExtrFilter.comp_tendsto (by simpa using h) h') hd theorem IsExtrFilter.lineDeriv_eq_zero {l : Filter E} (h : IsExtrFilter f l a) (h' : Tendsto (fun t : ℝ ↦ a + t • b) (𝓝 0) l) : lineDeriv ℝ f a b = 0 := by classical exact if hd : LineDifferentiableAt ℝ f a b then h.hasLineDerivAt_eq_zero hd.hasLineDerivAt h' else lineDeriv_zero_of_not_lineDifferentiableAt hd theorem IsExtrOn.hasLineDerivAt_eq_zero (h : IsExtrOn f s a) (hd : HasLineDerivAt ℝ f f' a b) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : f' = 0 := IsExtrFilter.hasLineDerivAt_eq_zero h hd <| tendsto_principal.2 h' theorem IsExtrOn.lineDeriv_eq_zero (h : IsExtrOn f s a) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : lineDeriv ℝ f a b = 0 := IsExtrFilter.lineDeriv_eq_zero h <| tendsto_principal.2 h' theorem IsMinOn.hasLineDerivAt_eq_zero (h : IsMinOn f s a) (hd : HasLineDerivAt ℝ f f' a b) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : f' = 0 := h.isExtr.hasLineDerivAt_eq_zero hd h' theorem IsMinOn.lineDeriv_eq_zero (h : IsMinOn f s a) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : lineDeriv ℝ f a b = 0 := h.isExtr.lineDeriv_eq_zero h' theorem IsMaxOn.hasLineDerivAt_eq_zero (h : IsMaxOn f s a) (hd : HasLineDerivAt ℝ f f' a b) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : f' = 0 := h.isExtr.hasLineDerivAt_eq_zero hd h' theorem IsMaxOn.lineDeriv_eq_zero (h : IsMaxOn f s a) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : lineDeriv ℝ f a b = 0 := h.isExtr.lineDeriv_eq_zero h' theorem IsExtrOn.hasLineDerivWithinAt_eq_zero (h : IsExtrOn f s a) (hd : HasLineDerivWithinAt ℝ f f' s a b) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : f' = 0 := h.hasLineDerivAt_eq_zero (hd.hasLineDerivAt' h') h' theorem IsExtrOn.lineDerivWithin_eq_zero (h : IsExtrOn f s a) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : lineDerivWithin ℝ f s a b = 0 := by classical exact if hd : LineDifferentiableWithinAt ℝ f s a b then h.hasLineDerivWithinAt_eq_zero hd.hasLineDerivWithinAt h' else lineDerivWithin_zero_of_not_lineDifferentiableWithinAt hd theorem IsMinOn.hasLineDerivWithinAt_eq_zero (h : IsMinOn f s a) (hd : HasLineDerivWithinAt ℝ f f' s a b) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : f' = 0 := h.isExtr.hasLineDerivWithinAt_eq_zero hd h' theorem IsMinOn.lineDerivWithin_eq_zero (h : IsMinOn f s a) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : lineDerivWithin ℝ f s a b = 0 := h.isExtr.lineDerivWithin_eq_zero h' theorem IsMaxOn.hasLineDerivWithinAt_eq_zero (h : IsMaxOn f s a) (hd : HasLineDerivWithinAt ℝ f f' s a b) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : f' = 0 := h.isExtr.hasLineDerivWithinAt_eq_zero hd h' theorem IsMaxOn.lineDerivWithin_eq_zero (h : IsMaxOn f s a) (h' : ∀ᶠ t : ℝ in 𝓝 0, a + t • b ∈ s) : lineDerivWithin ℝ f s a b = 0 := h.isExtr.lineDerivWithin_eq_zero h' end Module variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] {f : E → ℝ} {s : Set E} {a b : E} {f' : ℝ} theorem IsLocalExtr.hasLineDerivAt_eq_zero (h : IsLocalExtr f a) (hd : HasLineDerivAt ℝ f f' a b) : f' = 0 := IsExtrFilter.hasLineDerivAt_eq_zero h hd <| Continuous.tendsto' (by fun_prop) _ _ (by simp) theorem IsLocalExtr.lineDeriv_eq_zero (h : IsLocalExtr f a) : lineDeriv ℝ f a = 0 := funext fun b ↦ IsExtrFilter.lineDeriv_eq_zero h <| Continuous.tendsto' (by fun_prop) _ _ (by simp) theorem IsLocalMin.hasLineDerivAt_eq_zero (h : IsLocalMin f a) (hd : HasLineDerivAt ℝ f f' a b) : f' = 0 := IsLocalExtr.hasLineDerivAt_eq_zero (.inl h) hd theorem IsLocalMin.lineDeriv_eq_zero (h : IsLocalMin f a) : lineDeriv ℝ f a = 0 := IsLocalExtr.lineDeriv_eq_zero (.inl h) theorem IsLocalMax.hasLineDerivAt_eq_zero (h : IsLocalMax f a) (hd : HasLineDerivAt ℝ f f' a b) : f' = 0 := IsLocalExtr.hasLineDerivAt_eq_zero (.inr h) hd theorem IsLocalMax.lineDeriv_eq_zero (h : IsLocalMax f a) : lineDeriv ℝ f a = 0 := IsLocalExtr.lineDeriv_eq_zero (.inr h)
Analysis\Calculus\LocalExtr\Polynomial.lean
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson, Yury Kudryashov -/ import Mathlib.Algebra.Star.Order import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Topology.Algebra.Polynomial /-! # Rolle's Theorem for polynomials In this file we use Rolle's Theorem to relate the number of real roots of a real polynomial and its derivative. Namely, we prove the following facts. * `Polynomial.card_roots_toFinset_le_card_roots_derivative_diff_roots_succ`: the number of roots of a real polynomial `p` is at most the number of roots of its derivative that are not roots of `p` plus one. * `Polynomial.card_roots_toFinset_le_derivative`, `Polynomial.card_rootSet_le_derivative`: the number of roots of a real polynomial is at most the number of roots of its derivative plus one. * `Polynomial.card_roots_le_derivative`: same, but the roots are counted with multiplicities. ## Keywords polynomial, Rolle's Theorem, root -/ namespace Polynomial /-- The number of roots of a real polynomial `p` is at most the number of roots of its derivative that are not roots of `p` plus one. -/ theorem card_roots_toFinset_le_card_roots_derivative_diff_roots_succ (p : ℝ[X]) : p.roots.toFinset.card ≤ (p.derivative.roots.toFinset \ p.roots.toFinset).card + 1 := by rcases eq_or_ne (derivative p) 0 with hp' | hp' · rw [eq_C_of_derivative_eq_zero hp', roots_C, Multiset.toFinset_zero, Finset.card_empty] exact zero_le _ have hp : p ≠ 0 := ne_of_apply_ne derivative (by rwa [derivative_zero]) refine Finset.card_le_diff_of_interleaved fun x hx y hy hxy hxy' => ?_ rw [Multiset.mem_toFinset, mem_roots hp] at hx hy obtain ⟨z, hz1, hz2⟩ := exists_deriv_eq_zero hxy p.continuousOn (hx.trans hy.symm) refine ⟨z, ?_, hz1⟩ rwa [Multiset.mem_toFinset, mem_roots hp', IsRoot, ← p.deriv] /-- The number of roots of a real polynomial is at most the number of roots of its derivative plus one. -/ theorem card_roots_toFinset_le_derivative (p : ℝ[X]) : p.roots.toFinset.card ≤ p.derivative.roots.toFinset.card + 1 := p.card_roots_toFinset_le_card_roots_derivative_diff_roots_succ.trans <| add_le_add_right (Finset.card_mono Finset.sdiff_subset) _ /-- The number of roots of a real polynomial (counted with multiplicities) is at most the number of roots of its derivative (counted with multiplicities) plus one. -/ theorem card_roots_le_derivative (p : ℝ[X]) : Multiset.card p.roots ≤ Multiset.card (derivative p).roots + 1 := calc Multiset.card p.roots = ∑ x ∈ p.roots.toFinset, p.roots.count x := (Multiset.toFinset_sum_count_eq _).symm _ = ∑ x ∈ p.roots.toFinset, (p.roots.count x - 1 + 1) := (Eq.symm <| Finset.sum_congr rfl fun x hx => tsub_add_cancel_of_le <| Nat.succ_le_iff.2 <| Multiset.count_pos.2 <| Multiset.mem_toFinset.1 hx) _ = (∑ x ∈ p.roots.toFinset, (p.rootMultiplicity x - 1)) + p.roots.toFinset.card := by simp only [Finset.sum_add_distrib, Finset.card_eq_sum_ones, count_roots] _ ≤ (∑ x ∈ p.roots.toFinset, p.derivative.rootMultiplicity x) + ((p.derivative.roots.toFinset \ p.roots.toFinset).card + 1) := (add_le_add (Finset.sum_le_sum fun x _ => rootMultiplicity_sub_one_le_derivative_rootMultiplicity _ _) p.card_roots_toFinset_le_card_roots_derivative_diff_roots_succ) _ ≤ (∑ x ∈ p.roots.toFinset, p.derivative.roots.count x) + ((∑ x ∈ p.derivative.roots.toFinset \ p.roots.toFinset, p.derivative.roots.count x) + 1) := by simp only [← count_roots] refine add_le_add_left (add_le_add_right ((Finset.card_eq_sum_ones _).trans_le ?_) _) _ refine Finset.sum_le_sum fun x hx => Nat.succ_le_iff.2 <| ?_ rw [Multiset.count_pos, ← Multiset.mem_toFinset] exact (Finset.mem_sdiff.1 hx).1 _ = Multiset.card (derivative p).roots + 1 := by rw [← add_assoc, ← Finset.sum_union Finset.disjoint_sdiff, Finset.union_sdiff_self_eq_union, ← Multiset.toFinset_sum_count_eq, ← Finset.sum_subset Finset.subset_union_right] intro x _ hx₂ simpa only [Multiset.mem_toFinset, Multiset.count_eq_zero] using hx₂ /-- The number of real roots of a polynomial is at most the number of roots of its derivative plus one. -/ theorem card_rootSet_le_derivative {F : Type*} [CommRing F] [Algebra F ℝ] (p : F[X]) : Fintype.card (p.rootSet ℝ) ≤ Fintype.card (p.derivative.rootSet ℝ) + 1 := by simpa only [rootSet_def, Finset.coe_sort_coe, Fintype.card_coe, derivative_map] using card_roots_toFinset_le_derivative (p.map (algebraMap F ℝ)) end Polynomial
Analysis\Calculus\LocalExtr\Rolle.lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Anatole Dedecker -/ import Mathlib.Analysis.Calculus.LocalExtr.Basic import Mathlib.Topology.Algebra.Order.Rolle /-! # Rolle's Theorem In this file we prove Rolle's Theorem. The theorem says that for a function `f : ℝ → ℝ` such that * $f$ is differentiable on an open interval $(a, b)$, $a < b$; * $f$ is continuous on the corresponding closed interval $[a, b]$; * $f(a) = f(b)$, there exists a point $c∈(a, b)$ such that $f'(c)=0$. We prove four versions of this theorem. * `exists_hasDerivAt_eq_zero` is closest to the statement given above. It assumes that at every point $x ∈ (a, b)$ function $f$ has derivative $f'(x)$, then concludes that $f'(c)=0$ for some $c∈(a, b)$. * `exists_deriv_eq_zero` deals with `deriv f` instead of an arbitrary function `f'` and a predicate `HasDerivAt`; since we use zero as the "junk" value for `deriv f c`, this version does not assume that `f` is differentiable on the open interval. * `exists_hasDerivAt_eq_zero'` is similar to `exists_hasDerivAt_eq_zero` but instead of assuming continuity on the closed interval $[a, b]$ it assumes that $f$ tends to the same limit as $x$ tends to $a$ from the right and as $x$ tends to $b$ from the left. * `exists_deriv_eq_zero'` relates to `exists_deriv_eq_zero` as `exists_hasDerivAt_eq_zero'` relates to ``exists_hasDerivAt_eq_zero`. ## References * [Rolle's Theorem](https://en.wikipedia.org/wiki/Rolle's_theorem); ## Tags local extremum, Rolle's Theorem -/ open Set Filter Topology variable {f f' : ℝ → ℝ} {a b l : ℝ} /-- **Rolle's Theorem** `HasDerivAt` version -/ theorem exists_hasDerivAt_eq_zero (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hfI : f a = f b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) : ∃ c ∈ Ioo a b, f' c = 0 := let ⟨c, cmem, hc⟩ := exists_isLocalExtr_Ioo hab hfc hfI ⟨c, cmem, hc.hasDerivAt_eq_zero <| hff' c cmem⟩ /-- **Rolle's Theorem** `deriv` version -/ theorem exists_deriv_eq_zero (hab : a < b) (hfc : ContinuousOn f (Icc a b)) (hfI : f a = f b) : ∃ c ∈ Ioo a b, deriv f c = 0 := let ⟨c, cmem, hc⟩ := exists_isLocalExtr_Ioo hab hfc hfI ⟨c, cmem, hc.deriv_eq_zero⟩ /-- **Rolle's Theorem**, a version for a function on an open interval: if `f` has derivative `f'` on `(a, b)` and has the same limit `l` at `𝓝[>] a` and `𝓝[<] b`, then `f' c = 0` for some `c ∈ (a, b)`. -/ theorem exists_hasDerivAt_eq_zero' (hab : a < b) (hfa : Tendsto f (𝓝[>] a) (𝓝 l)) (hfb : Tendsto f (𝓝[<] b) (𝓝 l)) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) : ∃ c ∈ Ioo a b, f' c = 0 := let ⟨c, cmem, hc⟩ := exists_isLocalExtr_Ioo_of_tendsto hab (fun x hx ↦ (hff' x hx).continuousAt.continuousWithinAt) hfa hfb ⟨c, cmem, hc.hasDerivAt_eq_zero <| hff' c cmem⟩ /-- **Rolle's Theorem**, a version for a function on an open interval: if `f` has the same limit `l` at `𝓝[>] a` and `𝓝[<] b`, then `deriv f c = 0` for some `c ∈ (a, b)`. This version does not require differentiability of `f` because we define `deriv f c = 0` whenever `f` is not differentiable at `c`. -/ theorem exists_deriv_eq_zero' (hab : a < b) (hfa : Tendsto f (𝓝[>] a) (𝓝 l)) (hfb : Tendsto f (𝓝[<] b) (𝓝 l)) : ∃ c ∈ Ioo a b, deriv f c = 0 := by by_cases h : ∀ x ∈ Ioo a b, DifferentiableAt ℝ f x · exact exists_hasDerivAt_eq_zero' hab hfa hfb fun x hx => (h x hx).hasDerivAt · obtain ⟨c, hc, hcdiff⟩ : ∃ x ∈ Ioo a b, ¬DifferentiableAt ℝ f x := by push_neg at h; exact h exact ⟨c, hc, deriv_zero_of_not_differentiableAt hcdiff⟩
Analysis\Complex\AbelLimit.lean
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Tactic.Peel /-! # Abel's limit theorem If a real or complex power series for a function has radius of convergence 1 and the series is only known to converge conditionally at 1, Abel's limit theorem gives the value at 1 as the limit of the function at 1 from the left. "Left" for complex numbers means within a fixed cone opening to the left with angle less than `π`. ## Main theorems * `Complex.tendsto_tsum_powerSeries_nhdsWithin_stolzCone`: Abel's limit theorem for complex power series. * `Real.tendsto_tsum_powerSeries_nhdsWithin_lt`: Abel's limit theorem for real power series. ## References * https://planetmath.org/proofofabelslimittheorem * https://en.wikipedia.org/wiki/Abel%27s_theorem -/ open Filter Finset open scoped Topology namespace Complex section StolzSet open Real /-- The Stolz set for a given `M`, roughly teardrop-shaped with the tip at 1 but tending to the open unit disc as `M` tends to infinity. -/ def stolzSet (M : ℝ) : Set ℂ := {z | ‖z‖ < 1 ∧ ‖1 - z‖ < M * (1 - ‖z‖)} /-- The cone to the left of `1` with angle `2θ` such that `tan θ = s`. -/ def stolzCone (s : ℝ) : Set ℂ := {z | |z.im| < s * (1 - z.re)} theorem stolzSet_empty {M : ℝ} (hM : M ≤ 1) : stolzSet M = ∅ := by ext z rw [stolzSet, Set.mem_setOf, Set.mem_empty_iff_false, iff_false, not_and, not_lt, ← sub_pos] intro zn calc _ ≤ 1 * (1 - ‖z‖) := mul_le_mul_of_nonneg_right hM zn.le _ = ‖(1 : ℂ)‖ - ‖z‖ := by rw [one_mul, norm_one] _ ≤ _ := norm_sub_norm_le _ _ theorem nhdsWithin_lt_le_nhdsWithin_stolzSet {M : ℝ} (hM : 1 < M) : (𝓝[<] 1).map ofReal' ≤ 𝓝[stolzSet M] 1 := by rw [← tendsto_id'] refine tendsto_map' <| tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within ofReal' (tendsto_nhdsWithin_of_tendsto_nhds <| ofRealCLM.continuous.tendsto' 1 1 rfl) ?_ simp only [eventually_iff, norm_eq_abs, abs_ofReal, abs_lt, mem_nhdsWithin] refine ⟨Set.Ioo 0 2, isOpen_Ioo, by norm_num, fun x hx ↦ ?_⟩ simp only [Set.mem_inter_iff, Set.mem_Ioo, Set.mem_Iio] at hx simp only [Set.mem_setOf_eq, stolzSet, ← ofReal_one, ← ofReal_sub, norm_eq_abs, abs_ofReal, abs_of_pos hx.1.1, abs_of_pos <| sub_pos.mpr hx.2] exact ⟨hx.2, lt_mul_left (sub_pos.mpr hx.2) hM⟩ -- An ugly technical lemma private lemma stolzCone_subset_stolzSet_aux' (s : ℝ) : ∃ M ε, 0 < M ∧ 0 < ε ∧ ∀ x y, 0 < x → x < ε → |y| < s * x → sqrt (x ^ 2 + y ^ 2) < M * (1 - sqrt ((1 - x) ^ 2 + y ^ 2)) := by refine ⟨2 * sqrt (1 + s ^ 2) + 1, 1 / (1 + s ^ 2), by positivity, by positivity, fun x y hx₀ hx₁ hy ↦ ?_⟩ have H : sqrt ((1 - x) ^ 2 + y ^ 2) ≤ 1 - x / 2 := by calc sqrt ((1 - x) ^ 2 + y ^ 2) _ ≤ sqrt ((1 - x) ^ 2 + (s * x) ^ 2) := sqrt_le_sqrt <| by rw [← _root_.sq_abs y]; gcongr _ = sqrt (1 - 2 * x + (1 + s ^ 2) * x * x) := by congr 1; ring _ ≤ sqrt (1 - 2 * x + (1 + s ^ 2) * (1 / (1 + s ^ 2)) * x) := sqrt_le_sqrt <| by gcongr _ = sqrt (1 - x) := by congr 1; field_simp; ring _ ≤ 1 - x / 2 := by simp_rw [sub_eq_add_neg, ← neg_div] refine sqrt_one_add_le <| neg_le_neg_iff.mpr (hx₁.trans_le ?_).le rw [div_le_one (by positivity)] exact le_add_of_nonneg_right <| sq_nonneg s calc sqrt (x ^ 2 + y ^ 2) _ ≤ sqrt (x ^ 2 + (s * x) ^ 2) := sqrt_le_sqrt <| by rw [← _root_.sq_abs y]; gcongr _ = sqrt ((1 + s ^ 2) * x ^ 2) := by congr; ring _ = sqrt (1 + s ^ 2) * x := by rw [sqrt_mul' _ (sq_nonneg x), sqrt_sq hx₀.le] _ = 2 * sqrt (1 + s ^ 2) * (x / 2) := by ring _ < (2 * sqrt (1 + s ^ 2) + 1) * (x / 2) := by gcongr; exact lt_add_one _ _ ≤ _ := by gcongr; exact le_sub_comm.mpr H lemma stolzCone_subset_stolzSet_aux {s : ℝ} (hs : 0 < s) : ∃ M ε, 0 < M ∧ 0 < ε ∧ {z : ℂ | 1 - ε < z.re} ∩ stolzCone s ⊆ stolzSet M := by peel stolzCone_subset_stolzSet_aux' s with M ε hM hε H rintro z ⟨hzl, hzr⟩ rw [Set.mem_setOf_eq, sub_lt_comm, ← one_re, ← sub_re] at hzl rw [stolzCone, Set.mem_setOf_eq, ← one_re, ← sub_re] at hzr replace H := H (1 - z).re z.im ((mul_pos_iff_of_pos_left hs).mp <| (abs_nonneg z.im).trans_lt hzr) hzl hzr have h : z.im ^ 2 = (1 - z).im ^ 2 := by simp only [sub_im, one_im, zero_sub, even_two, neg_sq] rw [h, ← abs_eq_sqrt_sq_add_sq, ← norm_eq_abs, ← h, sub_re, one_re, sub_sub_cancel, ← abs_eq_sqrt_sq_add_sq, ← norm_eq_abs] at H exact ⟨sub_pos.mp <| (mul_pos_iff_of_pos_left hM).mp <| (norm_nonneg _).trans_lt H, H⟩ lemma nhdsWithin_stolzCone_le_nhdsWithin_stolzSet {s : ℝ} (hs : 0 < s) : ∃ M, 𝓝[stolzCone s] 1 ≤ 𝓝[stolzSet M] 1 := by obtain ⟨M, ε, _, hε, H⟩ := stolzCone_subset_stolzSet_aux hs use M rw [nhdsWithin_le_iff, mem_nhdsWithin] refine ⟨{w | 1 - ε < w.re}, isOpen_lt continuous_const continuous_re, ?_, H⟩ simp only [Set.mem_setOf_eq, one_re, sub_lt_self_iff, hε] end StolzSet variable {f : ℕ → ℂ} {l : ℂ} /-- Auxiliary lemma for Abel's limit theorem. The difference between the sum `l` at 1 and the power series's value at a point `z` away from 1 can be rewritten as `1 - z` times a power series whose coefficients are tail sums of `l`. -/ lemma abel_aux (h : Tendsto (fun n ↦ ∑ i ∈ range n, f i) atTop (𝓝 l)) {z : ℂ} (hz : ‖z‖ < 1) : Tendsto (fun n ↦ (1 - z) * ∑ i ∈ range n, (l - ∑ j ∈ range (i + 1), f j) * z ^ i) atTop (𝓝 (l - ∑' n, f n * z ^ n)) := by let s := fun n ↦ ∑ i ∈ range n, f i have k := h.sub (summable_powerSeries_of_norm_lt_one h.cauchySeq hz).hasSum.tendsto_sum_nat simp_rw [← sum_sub_distrib, ← mul_one_sub, ← geom_sum_mul_neg, ← mul_assoc, ← sum_mul, mul_comm, mul_sum _ _ (f _), range_eq_Ico, ← sum_Ico_Ico_comm', ← range_eq_Ico, ← sum_mul] at k conv at k => enter [1, n] rw [sum_congr (g := fun j ↦ (∑ k ∈ range n, f k - ∑ k ∈ range (j + 1), f k) * z ^ j) rfl (fun j hj ↦ by congr 1; exact sum_Ico_eq_sub _ (mem_range.mp hj))] suffices Tendsto (fun n ↦ (l - s n) * ∑ i ∈ range n, z ^ i) atTop (𝓝 0) by simp_rw [mul_sum] at this replace this := (this.const_mul (1 - z)).add k conv at this => enter [1, n] rw [← mul_add, ← sum_add_distrib] enter [2, 2, i] rw [← add_mul, sub_add_sub_cancel] rwa [mul_zero, zero_add] at this rw [← zero_mul (-1 / (z - 1))] apply Tendsto.mul · simpa only [neg_zero, neg_sub] using (tendsto_sub_nhds_zero_iff.mpr h).neg · conv => enter [1, n] rw [geom_sum_eq (by contrapose! hz; simp [hz]), sub_div, sub_eq_add_neg, ← neg_div] rw [← zero_add (-1 / (z - 1)), ← zero_div (z - 1)] apply Tendsto.add (Tendsto.div_const (tendsto_pow_atTop_nhds_zero_of_norm_lt_one hz) (z - 1)) simp only [zero_div, zero_add, tendsto_const_nhds_iff] /-- **Abel's limit theorem**. Given a power series converging at 1, the corresponding function is continuous at 1 when approaching 1 within a fixed Stolz set. -/ theorem tendsto_tsum_powerSeries_nhdsWithin_stolzSet (h : Tendsto (fun n ↦ ∑ i ∈ range n, f i) atTop (𝓝 l)) {M : ℝ} : Tendsto (fun z ↦ ∑' n, f n * z ^ n) (𝓝[stolzSet M] 1) (𝓝 l) := by -- If `M ≤ 1` the Stolz set is empty and the statement is trivial cases' le_or_lt M 1 with hM hM · simp_rw [stolzSet_empty hM, nhdsWithin_empty, tendsto_bot] -- Abbreviations let s := fun n ↦ ∑ i ∈ range n, f i let g := fun z ↦ ∑' n, f n * z ^ n have hm := Metric.tendsto_atTop.mp h rw [Metric.tendsto_nhdsWithin_nhds] simp only [dist_eq_norm] at hm ⊢ -- Introduce the "challenge" `ε` intro ε εpos -- First bound, handles the tail obtain ⟨B₁, hB₁⟩ := hm (ε / 4 / M) (by positivity) -- Second bound, handles the head let F := ∑ i ∈ range B₁, ‖l - s (i + 1)‖ use ε / 4 / (F + 1), by positivity intro z ⟨zn, zm⟩ zd have p := abel_aux h zn simp_rw [Metric.tendsto_atTop, dist_eq_norm, norm_sub_rev] at p -- Third bound, regarding the distance between `l - g z` and the rearranged sum obtain ⟨B₂, hB₂⟩ := p (ε / 2) (by positivity) clear hm p replace hB₂ := hB₂ (max B₁ B₂) (by simp) suffices ‖(1 - z) * ∑ i ∈ range (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ < ε / 2 by calc _ = ‖l - g z‖ := by rw [norm_sub_rev] _ = ‖l - g z - (1 - z) * ∑ i ∈ range (max B₁ B₂), (l - s (i + 1)) * z ^ i + (1 - z) * ∑ i ∈ range (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ := by rw [sub_add_cancel _] _ ≤ ‖l - g z - (1 - z) * ∑ i ∈ range (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ + ‖(1 - z) * ∑ i ∈ range (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ := norm_add_le _ _ _ < ε / 2 + ε / 2 := add_lt_add hB₂ this _ = _ := add_halves ε -- We break the rearranged sum along `B₁` calc _ = ‖(1 - z) * ∑ i ∈ range B₁, (l - s (i + 1)) * z ^ i + (1 - z) * ∑ i ∈ Ico B₁ (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ := by rw [← mul_add, sum_range_add_sum_Ico _ (le_max_left B₁ B₂)] _ ≤ ‖(1 - z) * ∑ i ∈ range B₁, (l - s (i + 1)) * z ^ i‖ + ‖(1 - z) * ∑ i ∈ Ico B₁ (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ := norm_add_le _ _ _ = ‖1 - z‖ * ‖∑ i ∈ range B₁, (l - s (i + 1)) * z ^ i‖ + ‖1 - z‖ * ‖∑ i ∈ Ico B₁ (max B₁ B₂), (l - s (i + 1)) * z ^ i‖ := by rw [norm_mul, norm_mul] _ ≤ ‖1 - z‖ * ∑ i ∈ range B₁, ‖l - s (i + 1)‖ * ‖z‖ ^ i + ‖1 - z‖ * ∑ i ∈ Ico B₁ (max B₁ B₂), ‖l - s (i + 1)‖ * ‖z‖ ^ i := by gcongr <;> simp_rw [← norm_pow, ← norm_mul, norm_sum_le] -- then prove that the two pieces are each less than `ε / 4` have S₁ : ‖1 - z‖ * ∑ i ∈ range B₁, ‖l - s (i + 1)‖ * ‖z‖ ^ i < ε / 4 := calc _ ≤ ‖1 - z‖ * ∑ i ∈ range B₁, ‖l - s (i + 1)‖ := by gcongr; nth_rw 3 [← mul_one ‖_‖] gcongr; exact pow_le_one _ (norm_nonneg _) zn.le _ ≤ ‖1 - z‖ * (F + 1) := by gcongr; linarith only _ < _ := by rwa [norm_sub_rev, lt_div_iff (by positivity)] at zd have S₂ : ‖1 - z‖ * ∑ i ∈ Ico B₁ (max B₁ B₂), ‖l - s (i + 1)‖ * ‖z‖ ^ i < ε / 4 := calc _ ≤ ‖1 - z‖ * ∑ i ∈ Ico B₁ (max B₁ B₂), ε / 4 / M * ‖z‖ ^ i := by gcongr with i hi have := hB₁ (i + 1) (by linarith only [(mem_Ico.mp hi).1]) rw [norm_sub_rev] at this exact this.le _ = ‖1 - z‖ * (ε / 4 / M) * ∑ i ∈ Ico B₁ (max B₁ B₂), ‖z‖ ^ i := by rw [← mul_sum, ← mul_assoc] _ ≤ ‖1 - z‖ * (ε / 4 / M) * ∑' i, ‖z‖ ^ i := by gcongr exact sum_le_tsum _ (fun _ _ ↦ by positivity) (summable_geometric_of_lt_one (by positivity) zn) _ = ‖1 - z‖ * (ε / 4 / M) / (1 - ‖z‖) := by rw [tsum_geometric_of_lt_one (by positivity) zn, ← div_eq_mul_inv] _ < M * (1 - ‖z‖) * (ε / 4 / M) / (1 - ‖z‖) := by gcongr; linarith only [zn] _ = _ := by rw [← mul_rotate, mul_div_cancel_right₀ _ (by linarith only [zn]), div_mul_cancel₀ _ (by linarith only [hM])] convert add_lt_add S₁ S₂ using 1 linarith only /-- **Abel's limit theorem**. Given a power series converging at 1, the corresponding function is continuous at 1 when approaching 1 within any fixed Stolz cone. -/ theorem tendsto_tsum_powerSeries_nhdsWithin_stolzCone (h : Tendsto (fun n ↦ ∑ i ∈ range n, f i) atTop (𝓝 l)) {s : ℝ} (hs : 0 < s) : Tendsto (fun z ↦ ∑' n, f n * z ^ n) (𝓝[stolzCone s] 1) (𝓝 l) := (tendsto_tsum_powerSeries_nhdsWithin_stolzSet h).mono_left (nhdsWithin_stolzCone_le_nhdsWithin_stolzSet hs).choose_spec theorem tendsto_tsum_powerSeries_nhdsWithin_lt (h : Tendsto (fun n ↦ ∑ i ∈ range n, f i) atTop (𝓝 l)) : Tendsto (fun z ↦ ∑' n, f n * z ^ n) ((𝓝[<] 1).map ofReal') (𝓝 l) := (tendsto_tsum_powerSeries_nhdsWithin_stolzSet (M := 2) h).mono_left (nhdsWithin_lt_le_nhdsWithin_stolzSet one_lt_two) end Complex namespace Real open Complex variable {f : ℕ → ℝ} {l : ℝ} /-- **Abel's limit theorem**. Given a real power series converging at 1, the corresponding function is continuous at 1 when approaching 1 from the left. -/ theorem tendsto_tsum_powerSeries_nhdsWithin_lt (h : Tendsto (fun n ↦ ∑ i ∈ range n, f i) atTop (𝓝 l)) : Tendsto (fun x ↦ ∑' n, f n * x ^ n) (𝓝[<] 1) (𝓝 l) := by have m : (𝓝 l).map ofReal' ≤ 𝓝 ↑l := ofRealCLM.continuous.tendsto l replace h := (tendsto_map.comp h).mono_right m rw [Function.comp_def] at h push_cast at h replace h := Complex.tendsto_tsum_powerSeries_nhdsWithin_lt h rw [tendsto_map'_iff] at h rw [Metric.tendsto_nhdsWithin_nhds] at h ⊢ convert h simp_rw [Function.comp_apply, dist_eq_norm] norm_cast rw [norm_real] end Real
Analysis\Complex\AbsMax.lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.Normed.Module.Completion import Mathlib.Analysis.NormedSpace.Extr import Mathlib.Topology.Order.ExtrClosure /-! # Maximum modulus principle In this file we prove several versions of the maximum modulus principle. There are several statements that can be called "the maximum modulus principle" for maps between normed complex spaces. They differ by assumptions on the domain (any space, a nontrivial space, a finite dimensional space), assumptions on the codomain (any space, a strictly convex space), and by conclusion (either equality of norms or of the values of the function). ## Main results ### Theorems for any codomain Consider a function `f : E → F` that is complex differentiable on a set `s`, is continuous on its closure, and `‖f x‖` has a maximum on `s` at `c`. We prove the following theorems. - `Complex.norm_eqOn_closedBall_of_isMaxOn`: if `s = Metric.ball c r`, then `‖f x‖ = ‖f c‖` for any `x` from the corresponding closed ball; - `Complex.norm_eq_norm_of_isMaxOn_of_ball_subset`: if `Metric.ball c (dist w c) ⊆ s`, then `‖f w‖ = ‖f c‖`; - `Complex.norm_eqOn_of_isPreconnected_of_isMaxOn`: if `U` is an open (pre)connected set, `f` is complex differentiable on `U`, and `‖f x‖` has a maximum on `U` at `c ∈ U`, then `‖f x‖ = ‖f c‖` for all `x ∈ U`; - `Complex.norm_eqOn_closure_of_isPreconnected_of_isMaxOn`: if `s` is open and (pre)connected and `c ∈ s`, then `‖f x‖ = ‖f c‖` for all `x ∈ closure s`; - `Complex.norm_eventually_eq_of_isLocalMax`: if `f` is complex differentiable in a neighborhood of `c` and `‖f x‖` has a local maximum at `c`, then `‖f x‖` is locally a constant in a neighborhood of `c`. ### Theorems for a strictly convex codomain If the codomain `F` is a strictly convex space, then in the lemmas from the previous section we can prove `f w = f c` instead of `‖f w‖ = ‖f c‖`, see `Complex.eqOn_of_isPreconnected_of_isMaxOn_norm`, `Complex.eqOn_closure_of_isPreconnected_of_isMaxOn_norm`, `Complex.eq_of_isMaxOn_of_ball_subset`, `Complex.eqOn_closedBall_of_isMaxOn_norm`, and `Complex.eventually_eq_of_isLocalMax_norm`. ### Values on the frontier Finally, we prove some corollaries that relate the (norm of the) values of a function on a set to its values on the frontier of the set. All these lemmas assume that `E` is a nontrivial space. In this section `f g : E → F` are functions that are complex differentiable on a bounded set `s` and are continuous on its closure. We prove the following theorems. - `Complex.exists_mem_frontier_isMaxOn_norm`: If `E` is a finite dimensional space and `s` is a nonempty bounded set, then there exists a point `z ∈ frontier s` such that `(‖f ·‖)` takes it maximum value on `closure s` at `z`. - `Complex.norm_le_of_forall_mem_frontier_norm_le`: if `‖f z‖ ≤ C` for all `z ∈ frontier s`, then `‖f z‖ ≤ C` for all `z ∈ s`; note that this theorem does not require `E` to be a finite dimensional space. - `Complex.eqOn_closure_of_eqOn_frontier`: if `f x = g x` on the frontier of `s`, then `f x = g x` on `closure s`; - `Complex.eqOn_of_eqOn_frontier`: if `f x = g x` on the frontier of `s`, then `f x = g x` on `s`. ## Tags maximum modulus principle, complex analysis -/ open TopologicalSpace Metric Set Filter Asymptotics Function MeasureTheory AffineMap Bornology open scoped Topology Filter NNReal Real universe u v w variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] {F : Type v} [NormedAddCommGroup F] [NormedSpace ℂ F] local postfix:100 "̂" => UniformSpace.Completion namespace Complex /-! ### Auxiliary lemmas We split the proof into a series of lemmas. First we prove the principle for a function `f : ℂ → F` with an additional assumption that `F` is a complete space, then drop unneeded assumptions one by one. The lemmas with names `*_auxₙ` are considered to be private and should not be used outside of this file. -/ theorem norm_max_aux₁ [CompleteSpace F] {f : ℂ → F} {z w : ℂ} (hd : DiffContOnCl ℂ f (ball z (dist w z))) (hz : IsMaxOn (norm ∘ f) (closedBall z (dist w z)) z) : ‖f w‖ = ‖f z‖ := by -- Consider a circle of radius `r = dist w z`. set r : ℝ := dist w z have hw : w ∈ closedBall z r := mem_closedBall.2 le_rfl -- Assume the converse. Since `‖f w‖ ≤ ‖f z‖`, we have `‖f w‖ < ‖f z‖`. refine (isMaxOn_iff.1 hz _ hw).antisymm (not_lt.1 ?_) rintro hw_lt : ‖f w‖ < ‖f z‖ have hr : 0 < r := dist_pos.2 (ne_of_apply_ne (norm ∘ f) hw_lt.ne) -- Due to Cauchy integral formula, it suffices to prove the following inequality. suffices ‖∮ ζ in C(z, r), (ζ - z)⁻¹ • f ζ‖ < 2 * π * ‖f z‖ by refine this.ne ?_ have A : (∮ ζ in C(z, r), (ζ - z)⁻¹ • f ζ) = (2 * π * I : ℂ) • f z := hd.circleIntegral_sub_inv_smul (mem_ball_self hr) simp [A, norm_smul, Real.pi_pos.le] suffices ‖∮ ζ in C(z, r), (ζ - z)⁻¹ • f ζ‖ < 2 * π * r * (‖f z‖ / r) by rwa [mul_assoc, mul_div_cancel₀ _ hr.ne'] at this /- This inequality is true because `‖(ζ - z)⁻¹ • f ζ‖ ≤ ‖f z‖ / r` for all `ζ` on the circle and this inequality is strict at `ζ = w`. -/ have hsub : sphere z r ⊆ closedBall z r := sphere_subset_closedBall refine circleIntegral.norm_integral_lt_of_norm_le_const_of_lt hr ?_ ?_ ⟨w, rfl, ?_⟩ · show ContinuousOn (fun ζ : ℂ => (ζ - z)⁻¹ • f ζ) (sphere z r) refine ((continuousOn_id.sub continuousOn_const).inv₀ ?_).smul (hd.continuousOn_ball.mono hsub) exact fun ζ hζ => sub_ne_zero.2 (ne_of_mem_sphere hζ hr.ne') · show ∀ ζ ∈ sphere z r, ‖(ζ - z)⁻¹ • f ζ‖ ≤ ‖f z‖ / r rintro ζ (hζ : abs (ζ - z) = r) rw [le_div_iff hr, norm_smul, norm_inv, norm_eq_abs, hζ, mul_comm, mul_inv_cancel_left₀ hr.ne'] exact hz (hsub hζ) show ‖(w - z)⁻¹ • f w‖ < ‖f z‖ / r rw [norm_smul, norm_inv, norm_eq_abs, ← div_eq_inv_mul] exact (div_lt_div_right hr).2 hw_lt /-! Now we drop the assumption `CompleteSpace F` by embedding `F` into its completion. -/ theorem norm_max_aux₂ {f : ℂ → F} {z w : ℂ} (hd : DiffContOnCl ℂ f (ball z (dist w z))) (hz : IsMaxOn (norm ∘ f) (closedBall z (dist w z)) z) : ‖f w‖ = ‖f z‖ := by set e : F →L[ℂ] F̂ := UniformSpace.Completion.toComplL have he : ∀ x, ‖e x‖ = ‖x‖ := UniformSpace.Completion.norm_coe replace hz : IsMaxOn (norm ∘ e ∘ f) (closedBall z (dist w z)) z := by simpa only [IsMaxOn, (· ∘ ·), he] using hz simpa only [he, (· ∘ ·)] using norm_max_aux₁ (e.differentiable.comp_diffContOnCl hd) hz /-! Then we replace the assumption `IsMaxOn (norm ∘ f) (Metric.closedBall z r) z` with a seemingly weaker assumption `IsMaxOn (norm ∘ f) (Metric.ball z r) z`. -/ theorem norm_max_aux₃ {f : ℂ → F} {z w : ℂ} {r : ℝ} (hr : dist w z = r) (hd : DiffContOnCl ℂ f (ball z r)) (hz : IsMaxOn (norm ∘ f) (ball z r) z) : ‖f w‖ = ‖f z‖ := by subst r rcases eq_or_ne w z with (rfl | hne); · rfl rw [← dist_ne_zero] at hne exact norm_max_aux₂ hd (closure_ball z hne ▸ hz.closure hd.continuousOn.norm) /-! ### Maximum modulus principle for any codomain If we do not assume that the codomain is a strictly convex space, then we can only claim that the **norm** `‖f x‖` is locally constant. -/ /-! Finally, we generalize the theorem from a disk in `ℂ` to a closed ball in any normed space. -/ /-- **Maximum modulus principle** on a closed ball: if `f : E → F` is continuous on a closed ball, is complex differentiable on the corresponding open ball, and the norm `‖f w‖` takes its maximum value on the open ball at its center, then the norm `‖f w‖` is constant on the closed ball. -/ theorem norm_eqOn_closedBall_of_isMaxOn {f : E → F} {z : E} {r : ℝ} (hd : DiffContOnCl ℂ f (ball z r)) (hz : IsMaxOn (norm ∘ f) (ball z r) z) : EqOn (norm ∘ f) (const E ‖f z‖) (closedBall z r) := by intro w hw rw [mem_closedBall, dist_comm] at hw rcases eq_or_ne z w with (rfl | hne); · rfl set e := (lineMap z w : ℂ → E) have hde : Differentiable ℂ e := (differentiable_id.smul_const (w - z)).add_const z suffices ‖(f ∘ e) (1 : ℂ)‖ = ‖(f ∘ e) (0 : ℂ)‖ by simpa [e] have hr : dist (1 : ℂ) 0 = 1 := by simp have hball : MapsTo e (ball 0 1) (ball z r) := by refine ((lipschitzWith_lineMap z w).mapsTo_ball (mt nndist_eq_zero.1 hne) 0 1).mono Subset.rfl ?_ simpa only [lineMap_apply_zero, mul_one, coe_nndist] using ball_subset_ball hw exact norm_max_aux₃ hr (hd.comp hde.diffContOnCl hball) (hz.comp_mapsTo hball (lineMap_apply_zero z w)) /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable on a set `s`, the norm of `f` takes it maximum on `s` at `z`, and `w` is a point such that the closed ball with center `z` and radius `dist w z` is included in `s`, then `‖f w‖ = ‖f z‖`. -/ theorem norm_eq_norm_of_isMaxOn_of_ball_subset {f : E → F} {s : Set E} {z w : E} (hd : DiffContOnCl ℂ f s) (hz : IsMaxOn (norm ∘ f) s z) (hsub : ball z (dist w z) ⊆ s) : ‖f w‖ = ‖f z‖ := norm_eqOn_closedBall_of_isMaxOn (hd.mono hsub) (hz.on_subset hsub) (mem_closedBall.2 le_rfl) /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable in a neighborhood of `c` and the norm `‖f z‖` has a local maximum at `c`, then `‖f z‖` is locally constant in a neighborhood of `c`. -/ theorem norm_eventually_eq_of_isLocalMax {f : E → F} {c : E} (hd : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z) (hc : IsLocalMax (norm ∘ f) c) : ∀ᶠ y in 𝓝 c, ‖f y‖ = ‖f c‖ := by rcases nhds_basis_closedBall.eventually_iff.1 (hd.and hc) with ⟨r, hr₀, hr⟩ exact nhds_basis_closedBall.eventually_iff.2 ⟨r, hr₀, norm_eqOn_closedBall_of_isMaxOn (DifferentiableOn.diffContOnCl fun x hx => (hr <| closure_ball_subset_closedBall hx).1.differentiableWithinAt) fun x hx => (hr <| ball_subset_closedBall hx).2⟩ theorem isOpen_setOf_mem_nhds_and_isMaxOn_norm {f : E → F} {s : Set E} (hd : DifferentiableOn ℂ f s) : IsOpen {z | s ∈ 𝓝 z ∧ IsMaxOn (norm ∘ f) s z} := by refine isOpen_iff_mem_nhds.2 fun z hz => (eventually_eventually_nhds.2 hz.1).and ?_ replace hd : ∀ᶠ w in 𝓝 z, DifferentiableAt ℂ f w := hd.eventually_differentiableAt hz.1 exact (norm_eventually_eq_of_isLocalMax hd <| hz.2.isLocalMax hz.1).mono fun x hx y hy => le_trans (hz.2 hy).out hx.ge /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U`. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `‖f x‖ = ‖f c‖` for all `x ∈ U`. -/ theorem norm_eqOn_of_isPreconnected_of_isMaxOn {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DifferentiableOn ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn (norm ∘ f) (const E ‖f c‖) U := by set V := U ∩ {z | IsMaxOn (norm ∘ f) U z} have hV : ∀ x ∈ V, ‖f x‖ = ‖f c‖ := fun x hx => le_antisymm (hm hx.1) (hx.2 hcU) suffices U ⊆ V from fun x hx => hV x (this hx) have hVo : IsOpen V := by simpa only [ho.mem_nhds_iff, setOf_and, setOf_mem_eq] using isOpen_setOf_mem_nhds_and_isMaxOn_norm hd have hVne : (U ∩ V).Nonempty := ⟨c, hcU, hcU, hm⟩ set W := U ∩ {z | ‖f z‖ ≠ ‖f c‖} have hWo : IsOpen W := hd.continuousOn.norm.isOpen_inter_preimage ho isOpen_ne have hdVW : Disjoint V W := disjoint_left.mpr fun x hxV hxW => hxW.2 (hV x hxV) have hUVW : U ⊆ V ∪ W := fun x hx => (eq_or_ne ‖f x‖ ‖f c‖).imp (fun h => ⟨hx, fun y hy => (hm hy).out.trans_eq h.symm⟩) (And.intro hx) exact hc.subset_left_of_subset_union hVo hWo hdVW hUVW hVne /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U` and is continuous on its closure. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `‖f x‖ = ‖f c‖` for all `x ∈ closure U`. -/ theorem norm_eqOn_closure_of_isPreconnected_of_isMaxOn {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DiffContOnCl ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn (norm ∘ f) (const E ‖f c‖) (closure U) := (norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hd.differentiableOn hcU hm).of_subset_closure hd.continuousOn.norm continuousOn_const subset_closure Subset.rfl section StrictConvex /-! ### The case of a strictly convex codomain If the codomain `F` is a strictly convex space, then we can claim equalities like `f w = f z` instead of `‖f w‖ = ‖f z‖`. Instead of repeating the proof starting with lemmas about integrals, we apply a corresponding lemma above twice: for `f` and for `(f · + f c)`. Then we have `‖f w‖ = ‖f z‖` and `‖f w + f z‖ = ‖f z + f z‖`, thus `‖f w + f z‖ = ‖f w‖ + ‖f z‖`. This is only possible if `f w = f z`, see `eq_of_norm_eq_of_norm_add_eq`. -/ variable [StrictConvexSpace ℝ F] /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U`. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `f x = f c` for all `x ∈ U`. TODO: change assumption from `IsMaxOn` to `IsLocalMax`. -/ theorem eqOn_of_isPreconnected_of_isMaxOn_norm {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DifferentiableOn ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn f (const E (f c)) U := fun x hx => have H₁ : ‖f x‖ = ‖f c‖ := norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hd hcU hm hx have H₂ : ‖f x + f c‖ = ‖f c + f c‖ := norm_eqOn_of_isPreconnected_of_isMaxOn hc ho (hd.add_const _) hcU hm.norm_add_self hx eq_of_norm_eq_of_norm_add_eq H₁ <| by simp only [H₂, SameRay.rfl.norm_add, H₁, Function.const] /-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a complex normed space. Let `f : E → F` be a function that is complex differentiable on `U` and is continuous on its closure. Suppose that `‖f x‖` takes its maximum value on `U` at `c ∈ U`. Then `f x = f c` for all `x ∈ closure U`. -/ theorem eqOn_closure_of_isPreconnected_of_isMaxOn_norm {f : E → F} {U : Set E} {c : E} (hc : IsPreconnected U) (ho : IsOpen U) (hd : DiffContOnCl ℂ f U) (hcU : c ∈ U) (hm : IsMaxOn (norm ∘ f) U c) : EqOn f (const E (f c)) (closure U) := (eqOn_of_isPreconnected_of_isMaxOn_norm hc ho hd.differentiableOn hcU hm).of_subset_closure hd.continuousOn continuousOn_const subset_closure Subset.rfl /-- **Maximum modulus principle**. Let `f : E → F` be a function between complex normed spaces. Suppose that the codomain `F` is a strictly convex space, `f` is complex differentiable on a set `s`, `f` is continuous on the closure of `s`, the norm of `f` takes it maximum on `s` at `z`, and `w` is a point such that the closed ball with center `z` and radius `dist w z` is included in `s`, then `f w = f z`. -/ theorem eq_of_isMaxOn_of_ball_subset {f : E → F} {s : Set E} {z w : E} (hd : DiffContOnCl ℂ f s) (hz : IsMaxOn (norm ∘ f) s z) (hsub : ball z (dist w z) ⊆ s) : f w = f z := have H₁ : ‖f w‖ = ‖f z‖ := norm_eq_norm_of_isMaxOn_of_ball_subset hd hz hsub have H₂ : ‖f w + f z‖ = ‖f z + f z‖ := norm_eq_norm_of_isMaxOn_of_ball_subset (hd.add_const _) hz.norm_add_self hsub eq_of_norm_eq_of_norm_add_eq H₁ <| by simp only [H₂, SameRay.rfl.norm_add, H₁] /-- **Maximum modulus principle** on a closed ball. Suppose that a function `f : E → F` from a normed complex space to a strictly convex normed complex space has the following properties: - it is continuous on a closed ball `Metric.closedBall z r`, - it is complex differentiable on the corresponding open ball; - the norm `‖f w‖` takes its maximum value on the open ball at its center. Then `f` is a constant on the closed ball. -/ theorem eqOn_closedBall_of_isMaxOn_norm {f : E → F} {z : E} {r : ℝ} (hd : DiffContOnCl ℂ f (ball z r)) (hz : IsMaxOn (norm ∘ f) (ball z r) z) : EqOn f (const E (f z)) (closedBall z r) := fun _x hx => eq_of_isMaxOn_of_ball_subset hd hz <| ball_subset_ball hx /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable in a neighborhood of `c` and the norm `‖f z‖` has a local maximum at `c`, then `f` is locally constant in a neighborhood of `c`. -/ theorem eventually_eq_of_isLocalMax_norm {f : E → F} {c : E} (hd : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z) (hc : IsLocalMax (norm ∘ f) c) : ∀ᶠ y in 𝓝 c, f y = f c := by rcases nhds_basis_closedBall.eventually_iff.1 (hd.and hc) with ⟨r, hr₀, hr⟩ exact nhds_basis_closedBall.eventually_iff.2 ⟨r, hr₀, eqOn_closedBall_of_isMaxOn_norm (DifferentiableOn.diffContOnCl fun x hx => (hr <| closure_ball_subset_closedBall hx).1.differentiableWithinAt) fun x hx => (hr <| ball_subset_closedBall hx).2⟩ theorem eventually_eq_or_eq_zero_of_isLocalMin_norm {f : E → ℂ} {c : E} (hf : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z) (hc : IsLocalMin (norm ∘ f) c) : (∀ᶠ z in 𝓝 c, f z = f c) ∨ f c = 0 := by refine or_iff_not_imp_right.mpr fun h => ?_ have h1 : ∀ᶠ z in 𝓝 c, f z ≠ 0 := hf.self_of_nhds.continuousAt.eventually_ne h have h2 : IsLocalMax (norm ∘ f)⁻¹ c := hc.inv (h1.mono fun z => norm_pos_iff.mpr) have h3 : IsLocalMax (norm ∘ f⁻¹) c := by refine h2.congr (eventually_of_forall ?_); simp have h4 : ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f⁻¹ z := by filter_upwards [hf, h1] with z h using h.inv filter_upwards [eventually_eq_of_isLocalMax_norm h4 h3] with z using inv_inj.mp end StrictConvex /-! ### Maximum on a set vs maximum on its frontier In this section we prove corollaries of the maximum modulus principle that relate the values of a function on a set to its values on the frontier of this set. -/ variable [Nontrivial E] /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable on a nonempty bounded set `U` and is continuous on its closure, then there exists a point `z ∈ frontier U` such that `(‖f ·‖)` takes it maximum value on `closure U` at `z`. -/ theorem exists_mem_frontier_isMaxOn_norm [FiniteDimensional ℂ E] {f : E → F} {U : Set E} (hb : IsBounded U) (hne : U.Nonempty) (hd : DiffContOnCl ℂ f U) : ∃ z ∈ frontier U, IsMaxOn (norm ∘ f) (closure U) z := by have hc : IsCompact (closure U) := hb.isCompact_closure obtain ⟨w, hwU, hle⟩ : ∃ w ∈ closure U, IsMaxOn (norm ∘ f) (closure U) w := hc.exists_isMaxOn hne.closure hd.continuousOn.norm rw [closure_eq_interior_union_frontier, mem_union] at hwU cases' hwU with hwU hwU; rotate_left; · exact ⟨w, hwU, hle⟩ have : interior U ≠ univ := ne_top_of_le_ne_top hc.ne_univ interior_subset_closure rcases exists_mem_frontier_infDist_compl_eq_dist hwU this with ⟨z, hzU, hzw⟩ refine ⟨z, frontier_interior_subset hzU, fun x hx => (hle hx).out.trans_eq ?_⟩ refine (norm_eq_norm_of_isMaxOn_of_ball_subset hd (hle.on_subset subset_closure) ?_).symm rw [dist_comm, ← hzw] exact ball_infDist_compl_subset.trans interior_subset /-- **Maximum modulus principle**: if `f : E → F` is complex differentiable on a bounded set `U` and `‖f z‖ ≤ C` for any `z ∈ frontier U`, then the same is true for any `z ∈ closure U`. -/ theorem norm_le_of_forall_mem_frontier_norm_le {f : E → F} {U : Set E} (hU : IsBounded U) (hd : DiffContOnCl ℂ f U) {C : ℝ} (hC : ∀ z ∈ frontier U, ‖f z‖ ≤ C) {z : E} (hz : z ∈ closure U) : ‖f z‖ ≤ C := by rw [closure_eq_self_union_frontier, union_comm, mem_union] at hz cases' hz with hz hz; · exact hC z hz /- In case of a finite dimensional domain, one can just apply `Complex.exists_mem_frontier_isMaxOn_norm`. To make it work in any Banach space, we restrict the function to a line first. -/ rcases exists_ne z with ⟨w, hne⟩ set e := (lineMap z w : ℂ → E) have hde : Differentiable ℂ e := (differentiable_id.smul_const (w - z)).add_const z have hL : AntilipschitzWith (nndist z w)⁻¹ e := antilipschitzWith_lineMap hne.symm replace hd : DiffContOnCl ℂ (f ∘ e) (e ⁻¹' U) := hd.comp hde.diffContOnCl (mapsTo_preimage _ _) have h₀ : (0 : ℂ) ∈ e ⁻¹' U := by simpa only [e, mem_preimage, lineMap_apply_zero] rcases exists_mem_frontier_isMaxOn_norm (hL.isBounded_preimage hU) ⟨0, h₀⟩ hd with ⟨ζ, hζU, hζ⟩ calc ‖f z‖ = ‖f (e 0)‖ := by simp only [e, lineMap_apply_zero] _ ≤ ‖f (e ζ)‖ := hζ (subset_closure h₀) _ ≤ C := hC _ (hde.continuous.frontier_preimage_subset _ hζU) /-- If two complex differentiable functions `f g : E → F` are equal on the boundary of a bounded set `U`, then they are equal on `closure U`. -/ theorem eqOn_closure_of_eqOn_frontier {f g : E → F} {U : Set E} (hU : IsBounded U) (hf : DiffContOnCl ℂ f U) (hg : DiffContOnCl ℂ g U) (hfg : EqOn f g (frontier U)) : EqOn f g (closure U) := by suffices H : ∀ z ∈ closure U, ‖(f - g) z‖ ≤ 0 by simpa [sub_eq_zero] using H refine fun z hz => norm_le_of_forall_mem_frontier_norm_le hU (hf.sub hg) (fun w hw => ?_) hz simp [hfg hw] /-- If two complex differentiable functions `f g : E → F` are equal on the boundary of a bounded set `U`, then they are equal on `U`. -/ theorem eqOn_of_eqOn_frontier {f g : E → F} {U : Set E} (hU : IsBounded U) (hf : DiffContOnCl ℂ f U) (hg : DiffContOnCl ℂ g U) (hfg : EqOn f g (frontier U)) : EqOn f g U := (eqOn_closure_of_eqOn_frontier hU hf hg hfg).mono subset_closure end Complex
Analysis\Complex\Angle.lean
/- Copyright (c) 2024 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Angle between complex numbers This file relates the Euclidean geometric notion of angle between complex numbers to the argument of their quotient. It also shows that the arc and chord distances between two unit complex numbers are equivalent up to a factor of `π / 2`. ## TODO Prove the corresponding results for oriented angles. ## Tags arc-length, arc-distance -/ open InnerProductGeometry Set open scoped Real namespace Complex variable {a x y : ℂ} /-- The angle between two non-zero complex numbers is the absolute value of the argument of their quotient. Note that this does not hold when `x` or `y` is `0` as the LHS is `π / 2` while the RHS is `0`. -/ lemma angle_eq_abs_arg (hx : x ≠ 0) (hy : y ≠ 0) : angle x y = |(x / y).arg| := by refine Real.arccos_eq_of_eq_cos (abs_nonneg _) (abs_arg_le_pi _) ?_ rw [Real.cos_abs, Complex.cos_arg (div_ne_zero hx hy)] have := (map_ne_zero Complex.abs).2 hx have := (map_ne_zero Complex.abs).2 hy simp [div_eq_mul_inv, Complex.normSq_eq_norm_sq] field_simp ring lemma angle_one_left (hy : y ≠ 0) : angle 1 y = |y.arg| := by simp [angle_eq_abs_arg, hy] lemma angle_one_right (hx : x ≠ 0) : angle x 1 = |x.arg| := by simp [angle_eq_abs_arg, hx] @[simp] lemma angle_mul_left (ha : a ≠ 0) (x y : ℂ) : angle (a * x) (a * y) = angle x y := by obtain rfl | hx := eq_or_ne x 0 <;> obtain rfl | hy := eq_or_ne y 0 <;> simp [angle_eq_abs_arg, mul_div_mul_left, *] @[simp] lemma angle_mul_right (ha : a ≠ 0) (x y : ℂ) : angle (x * a) (y * a) = angle x y := by simp [mul_comm, angle_mul_left ha] lemma angle_div_left_eq_angle_mul_right (a x y : ℂ) : angle (x / a) y = angle x (y * a) := by obtain rfl | ha := eq_or_ne a 0 · simp · rw [← angle_mul_right ha, div_mul_cancel₀ _ ha] lemma angle_div_right_eq_angle_mul_left (a x y : ℂ) : angle x (y / a) = angle (x * a) y := by rw [angle_comm, angle_div_left_eq_angle_mul_right, angle_comm] lemma angle_exp_exp (x y : ℝ) : angle (exp (x * I)) (exp (y * I)) = |toIocMod Real.two_pi_pos (-π) (x - y)| := by simp_rw [angle_eq_abs_arg (exp_ne_zero _) (exp_ne_zero _), ← exp_sub, ← sub_mul, ← ofReal_sub, arg_exp_mul_I] lemma angle_exp_one (x : ℝ) : angle (exp (x * I)) 1 = |toIocMod Real.two_pi_pos (-π) x| := by simpa using angle_exp_exp x 0 /-! ### Arc-length and chord-length are equivalent This section shows that the arc and chord distances between two unit complex numbers are equivalent up to a factor of `π / 2`. -/ /-- Chord-length is a multiple of arc-length up to constants. -/ lemma norm_sub_mem_Icc_angle (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) : ‖x - y‖ ∈ Icc (2 / π * angle x y) (angle x y) := by clear a wlog h : y = 1 · have := @this (x / y) 1 (by simp only [norm_div, hx, hy, div_one]) norm_one rfl rwa [angle_div_left_eq_angle_mul_right, div_sub_one, norm_div, hy, div_one, one_mul] at this rintro rfl simp at hy subst y rw [norm_eq_abs, abs_eq_one_iff'] at hx obtain ⟨θ, hθ, rfl⟩ := hx rw [angle_exp_one, exp_mul_I, add_sub_right_comm, (toIocMod_eq_self _).2] · norm_cast rw [norm_eq_abs, abs_add_mul_I] refine ⟨Real.le_sqrt_of_sq_le ?_, ?_⟩ · rw [mul_pow, ← _root_.abs_pow, abs_sq] calc _ = 2 * (1 - (1 - 2 / π ^ 2 * θ ^ 2)) := by ring _ ≤ 2 * (1 - θ.cos) := by gcongr; exact Real.cos_quadratic_upper_bound <| abs_le.2 <| Ioc_subset_Icc_self hθ _ = _ := by linear_combination -θ.cos_sq_add_sin_sq · rw [Real.sqrt_le_left (by positivity), ← _root_.abs_pow, abs_sq] calc _ = 2 * (1 - θ.cos) := by linear_combination θ.cos_sq_add_sin_sq _ ≤ 2 * (1 - (1 - θ ^ 2 / 2)) := by gcongr; exact Real.one_sub_sq_div_two_le_cos _ = _ := by ring · convert hθ ring /-- Chord-length is always less than arc-length. -/ lemma norm_sub_le_angle (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) : ‖x - y‖ ≤ angle x y := (norm_sub_mem_Icc_angle hx hy).2 /-- Chord-length is always greater than a multiple of arc-length. -/ lemma mul_angle_le_norm_sub (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) : 2 / π * angle x y ≤ ‖x - y‖ := (norm_sub_mem_Icc_angle hx hy).1 /-- Arc-length is always less than a multiple of chord-length. -/ lemma angle_le_mul_norm_sub (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) : angle x y ≤ π / 2 * ‖x - y‖ := by rw [← div_le_iff' <| by positivity, div_eq_inv_mul, inv_div]; exact mul_angle_le_norm_sub hx hy end Complex
Analysis\Complex\Arg.lean
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.SpecialFunctions.Complex.Arg /-! # Rays in the complex numbers This file links the definition `SameRay ℝ x y` with the equality of arguments of complex numbers, the usual way this is considered. ## Main statements * `Complex.sameRay_iff` : Two complex numbers are on the same ray iff one of them is zero, or they have the same argument. * `Complex.abs_add_eq/Complex.abs_sub_eq`: If two non zero complex numbers have the same argument, then the triangle inequality is an equality. -/ variable {x y : ℂ} namespace Complex theorem sameRay_iff : SameRay ℝ x y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := by rcases eq_or_ne x 0 with (rfl | hx) · simp rcases eq_or_ne y 0 with (rfl | hy) · simp simp only [hx, hy, false_or_iff, sameRay_iff_norm_smul_eq, arg_eq_arg_iff hx hy] field_simp [hx, hy] rw [mul_comm, eq_comm] theorem sameRay_iff_arg_div_eq_zero : SameRay ℝ x y ↔ arg (x / y) = 0 := by rw [← Real.Angle.toReal_zero, ← arg_coe_angle_eq_iff_eq_toReal, sameRay_iff] by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] simp [hx, hy, arg_div_coe_angle, sub_eq_zero] -- Porting note: `(x + y).abs` stopped working. theorem abs_add_eq_iff : abs (x + y) = abs x + abs y ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := sameRay_iff_norm_add.symm.trans sameRay_iff theorem abs_sub_eq_iff : abs (x - y) = |abs x - abs y| ↔ x = 0 ∨ y = 0 ∨ x.arg = y.arg := sameRay_iff_norm_sub.symm.trans sameRay_iff theorem sameRay_of_arg_eq (h : x.arg = y.arg) : SameRay ℝ x y := sameRay_iff.mpr <| Or.inr <| Or.inr h theorem abs_add_eq (h : x.arg = y.arg) : abs (x + y) = abs x + abs y := (sameRay_of_arg_eq h).norm_add theorem abs_sub_eq (h : x.arg = y.arg) : abs (x - y) = ‖abs x - abs y‖ := (sameRay_of_arg_eq h).norm_sub end Complex
Analysis\Complex\Asymptotics.lean
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Asymptotics.Theta /-! # Lemmas about asymptotics and the natural embedding `ℝ → ℂ` In this file we prove several trivial lemmas about `Asymptotics.IsBigO` etc and `(↑) : ℝ → ℂ`. -/ namespace Complex variable {α E : Type*} [Norm E] {l : Filter α} theorem isTheta_ofReal (f : α → ℝ) (l : Filter α) : (f · : α → ℂ) =Θ[l] f := .of_norm_left <| by simpa using (Asymptotics.isTheta_rfl (f := f)).norm_left @[simp, norm_cast] theorem isLittleO_ofReal_left {f : α → ℝ} {g : α → E} : (f · : α → ℂ) =o[l] g ↔ f =o[l] g := (isTheta_ofReal f l).isLittleO_congr_left @[simp, norm_cast] theorem isLittleO_ofReal_right {f : α → E} {g : α → ℝ} : f =o[l] (g · : α → ℂ) ↔ f =o[l] g := (isTheta_ofReal g l).isLittleO_congr_right @[simp, norm_cast] theorem isBigO_ofReal_left {f : α → ℝ} {g : α → E} : (f · : α → ℂ) =O[l] g ↔ f =O[l] g := (isTheta_ofReal f l).isBigO_congr_left @[simp, norm_cast] theorem isBigO_ofReal_right {f : α → E} {g : α → ℝ} : f =O[l] (g · : α → ℂ) ↔ f =O[l] g := (isTheta_ofReal g l).isBigO_congr_right @[simp, norm_cast] theorem isTheta_ofReal_left {f : α → ℝ} {g : α → E} : (f · : α → ℂ) =Θ[l] g ↔ f =Θ[l] g := (isTheta_ofReal f l).isTheta_congr_left @[simp, norm_cast] theorem isTheta_ofReal_right {f : α → E} {g : α → ℝ} : f =Θ[l] (g · : α → ℂ) ↔ f =Θ[l] g := (isTheta_ofReal g l).isTheta_congr_right end Complex
Analysis\Complex\Basic.lean
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Complex.Module import Mathlib.Data.Complex.Order import Mathlib.Data.Complex.Exponential import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.RealVectorSpace /-! # Normed space structure on `ℂ`. This file gathers basic facts of analytic nature on the complex numbers. ## Main results This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives tools on the real vector space structure of `ℂ`. Notably, it defines the following functions in the namespace `Complex`. |Name |Type |Description | |------------------|-------------|--------------------------------------------------------| |`equivRealProdCLM`|ℂ ≃L[ℝ] ℝ × ℝ|The natural `ContinuousLinearEquiv` from `ℂ` to `ℝ × ℝ` | |`reCLM` |ℂ →L[ℝ] ℝ |Real part function as a `ContinuousLinearMap` | |`imCLM` |ℂ →L[ℝ] ℝ |Imaginary part function as a `ContinuousLinearMap` | |`ofRealCLM` |ℝ →L[ℝ] ℂ |Embedding of the reals as a `ContinuousLinearMap` | |`ofRealLI` |ℝ →ₗᵢ[ℝ] ℂ |Embedding of the reals as a `LinearIsometry` | |`conjCLE` |ℂ ≃L[ℝ] ℂ |Complex conjugation as a `ContinuousLinearEquiv` | |`conjLIE` |ℂ ≃ₗᵢ[ℝ] ℂ |Complex conjugation as a `LinearIsometryEquiv` | We also register the fact that `ℂ` is an `RCLike` field. -/ assert_not_exists Absorbs noncomputable section namespace Complex variable {z : ℂ} open ComplexConjugate Topology Filter instance : Norm ℂ := ⟨abs⟩ @[simp] theorem norm_eq_abs (z : ℂ) : ‖z‖ = abs z := rfl lemma norm_I : ‖I‖ = 1 := abs_I theorem norm_exp_ofReal_mul_I (t : ℝ) : ‖exp (t * I)‖ = 1 := by simp only [norm_eq_abs, abs_exp_ofReal_mul_I] instance instNormedAddCommGroup : NormedAddCommGroup ℂ := AddGroupNorm.toNormedAddCommGroup { abs with map_zero' := map_zero abs neg' := abs.map_neg eq_zero_of_map_eq_zero' := fun _ => abs.eq_zero.1 } instance : NormedField ℂ where dist_eq _ _ := rfl norm_mul' := map_mul abs instance : DenselyNormedField ℂ where lt_norm_lt r₁ r₂ h₀ hr := let ⟨x, h⟩ := exists_between hr ⟨x, by rwa [norm_eq_abs, abs_ofReal, abs_of_pos (h₀.trans_lt h.1)]⟩ instance {R : Type*} [NormedField R] [NormedAlgebra R ℝ] : NormedAlgebra R ℂ where norm_smul_le r x := by rw [← algebraMap_smul ℝ r x, real_smul, norm_mul, norm_eq_abs, abs_ofReal, ← Real.norm_eq_abs, norm_algebraMap'] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E] -- see Note [lower instance priority] /-- The module structure from `Module.complexToReal` is a normed space. -/ instance (priority := 900) _root_.NormedSpace.complexToReal : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ ℂ E -- see Note [lower instance priority] /-- The algebra structure from `Algebra.complexToReal` is a normed algebra. -/ instance (priority := 900) _root_.NormedAlgebra.complexToReal {A : Type*} [SeminormedRing A] [NormedAlgebra ℂ A] : NormedAlgebra ℝ A := NormedAlgebra.restrictScalars ℝ ℂ A theorem dist_eq (z w : ℂ) : dist z w = abs (z - w) := rfl theorem dist_eq_re_im (z w : ℂ) : dist z w = √((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) := by rw [sq, sq] rfl @[simp] theorem dist_mk (x₁ y₁ x₂ y₂ : ℝ) : dist (mk x₁ y₁) (mk x₂ y₂) = √((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) := dist_eq_re_im _ _ theorem dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, zero_add, Real.sqrt_sq_eq_abs, Real.dist_eq] theorem nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im := NNReal.eq <| dist_of_re_eq h theorem edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im := by rw [edist_nndist, edist_nndist, nndist_of_re_eq h] theorem dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, add_zero, Real.sqrt_sq_eq_abs, Real.dist_eq] theorem nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re := NNReal.eq <| dist_of_im_eq h theorem edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re := by rw [edist_nndist, edist_nndist, nndist_of_im_eq h] theorem dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| := by rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, Real.dist_eq, sub_neg_eq_add, ← two_mul, _root_.abs_mul, abs_of_pos (zero_lt_two' ℝ)] theorem nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * Real.nnabs z.im := NNReal.eq <| by rw [← dist_nndist, NNReal.coe_mul, NNReal.coe_two, Real.coe_nnabs, dist_conj_self] theorem dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| := by rw [dist_comm, dist_conj_self] theorem nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * Real.nnabs z.im := by rw [nndist_comm, nndist_conj_self] @[simp 1100] theorem comap_abs_nhds_zero : comap abs (𝓝 0) = 𝓝 0 := comap_norm_nhds_zero theorem norm_real (r : ℝ) : ‖(r : ℂ)‖ = ‖r‖ := abs_ofReal _ @[simp 1100] theorem norm_rat (r : ℚ) : ‖(r : ℂ)‖ = |(r : ℝ)| := by rw [← ofReal_ratCast] exact norm_real _ @[simp 1100] theorem norm_nat (n : ℕ) : ‖(n : ℂ)‖ = n := abs_natCast _ @[simp 1100] lemma norm_int {n : ℤ} : ‖(n : ℂ)‖ = |(n : ℝ)| := abs_intCast n theorem norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ‖(n : ℂ)‖ = n := by rw [norm_int, ← Int.cast_abs, _root_.abs_of_nonneg hn] lemma normSq_eq_norm_sq (z : ℂ) : normSq z = ‖z‖ ^ 2 := by rw [normSq_eq_abs, norm_eq_abs] @[continuity] theorem continuous_abs : Continuous abs := continuous_norm @[continuity] theorem continuous_normSq : Continuous normSq := by simpa [← normSq_eq_abs] using continuous_abs.pow 2 @[simp, norm_cast] theorem nnnorm_real (r : ℝ) : ‖(r : ℂ)‖₊ = ‖r‖₊ := Subtype.ext <| norm_real r @[simp, norm_cast] theorem nnnorm_nat (n : ℕ) : ‖(n : ℂ)‖₊ = n := Subtype.ext <| by simp @[simp, norm_cast] theorem nnnorm_int (n : ℤ) : ‖(n : ℂ)‖₊ = ‖n‖₊ := Subtype.ext norm_int theorem nnnorm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖₊ = 1 := (pow_left_inj zero_le' zero_le' hn).1 <| by rw [← nnnorm_pow, h, nnnorm_one, one_pow] theorem norm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖ = 1 := congr_arg Subtype.val (nnnorm_eq_one_of_pow_eq_one h hn) lemma le_of_eq_sum_of_eq_sum_norm {ι : Type*} {a b : ℝ} (f : ι → ℂ) (s : Finset ι) (ha₀ : 0 ≤ a) (ha : a = ∑ i ∈ s, f i) (hb : b = ∑ i ∈ s, (‖f i‖ : ℂ)) : a ≤ b := by norm_cast at hb; rw [← Complex.abs_of_nonneg ha₀, ha, hb]; exact norm_sum_le s f theorem equivRealProd_apply_le (z : ℂ) : ‖equivRealProd z‖ ≤ abs z := by simp [Prod.norm_def, abs_re_le_abs, abs_im_le_abs] theorem equivRealProd_apply_le' (z : ℂ) : ‖equivRealProd z‖ ≤ 1 * abs z := by simpa using equivRealProd_apply_le z theorem lipschitz_equivRealProd : LipschitzWith 1 equivRealProd := by simpa using AddMonoidHomClass.lipschitz_of_bound equivRealProdLm 1 equivRealProd_apply_le' theorem antilipschitz_equivRealProd : AntilipschitzWith (NNReal.sqrt 2) equivRealProd := AddMonoidHomClass.antilipschitz_of_bound equivRealProdLm fun z ↦ by simpa only [Real.coe_sqrt, NNReal.coe_ofNat] using abs_le_sqrt_two_mul_max z theorem uniformEmbedding_equivRealProd : UniformEmbedding equivRealProd := antilipschitz_equivRealProd.uniformEmbedding lipschitz_equivRealProd.uniformContinuous instance : CompleteSpace ℂ := (completeSpace_congr uniformEmbedding_equivRealProd).mpr inferInstance instance instT2Space : T2Space ℂ := TopologicalSpace.t2Space_of_metrizableSpace /-- The natural `ContinuousLinearEquiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps! (config := { simpRhs := true }) apply symm_apply_re symm_apply_im] def equivRealProdCLM : ℂ ≃L[ℝ] ℝ × ℝ := equivRealProdLm.toContinuousLinearEquivOfBounds 1 (√2) equivRealProd_apply_le' fun p => abs_le_sqrt_two_mul_max (equivRealProd.symm p) theorem equivRealProdCLM_symm_apply (p : ℝ × ℝ) : Complex.equivRealProdCLM.symm p = p.1 + p.2 * Complex.I := Complex.equivRealProd_symm_apply p instance : ProperSpace ℂ := (id lipschitz_equivRealProd : LipschitzWith 1 equivRealProdCLM.toHomeomorph).properSpace /-- The `abs` function on `ℂ` is proper. -/ theorem tendsto_abs_cocompact_atTop : Tendsto abs (cocompact ℂ) atTop := tendsto_norm_cocompact_atTop /-- The `normSq` function on `ℂ` is proper. -/ theorem tendsto_normSq_cocompact_atTop : Tendsto normSq (cocompact ℂ) atTop := by simpa [mul_self_abs] using tendsto_abs_cocompact_atTop.atTop_mul_atTop tendsto_abs_cocompact_atTop open ContinuousLinearMap /-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/ def reCLM : ℂ →L[ℝ] ℝ := reLm.mkContinuous 1 fun x => by simp [abs_re_le_abs] @[continuity, fun_prop] theorem continuous_re : Continuous re := reCLM.continuous @[simp] theorem reCLM_coe : (reCLM : ℂ →ₗ[ℝ] ℝ) = reLm := rfl @[simp] theorem reCLM_apply (z : ℂ) : (reCLM : ℂ → ℝ) z = z.re := rfl /-- Continuous linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/ def imCLM : ℂ →L[ℝ] ℝ := imLm.mkContinuous 1 fun x => by simp [abs_im_le_abs] @[continuity, fun_prop] theorem continuous_im : Continuous im := imCLM.continuous @[simp] theorem imCLM_coe : (imCLM : ℂ →ₗ[ℝ] ℝ) = imLm := rfl @[simp] theorem imCLM_apply (z : ℂ) : (imCLM : ℂ → ℝ) z = z.im := rfl theorem restrictScalars_one_smulRight' (x : E) : ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] E) = reCLM.smulRight x + I • imCLM.smulRight x := by ext ⟨a, b⟩ simp [mk_eq_add_mul_I, mul_smul, smul_comm I b x] theorem restrictScalars_one_smulRight (x : ℂ) : ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] ℂ) = x • (1 : ℂ →L[ℝ] ℂ) := by ext1 z dsimp apply mul_comm /-- The complex-conjugation function from `ℂ` to itself is an isometric linear equivalence. -/ def conjLIE : ℂ ≃ₗᵢ[ℝ] ℂ := ⟨conjAe.toLinearEquiv, abs_conj⟩ @[simp] theorem conjLIE_apply (z : ℂ) : conjLIE z = conj z := rfl @[simp] theorem conjLIE_symm : conjLIE.symm = conjLIE := rfl theorem isometry_conj : Isometry (conj : ℂ → ℂ) := conjLIE.isometry @[simp] theorem dist_conj_conj (z w : ℂ) : dist (conj z) (conj w) = dist z w := isometry_conj.dist_eq z w @[simp] theorem nndist_conj_conj (z w : ℂ) : nndist (conj z) (conj w) = nndist z w := isometry_conj.nndist_eq z w theorem dist_conj_comm (z w : ℂ) : dist (conj z) w = dist z (conj w) := by rw [← dist_conj_conj, conj_conj] theorem nndist_conj_comm (z w : ℂ) : nndist (conj z) w = nndist z (conj w) := Subtype.ext <| dist_conj_comm _ _ instance : ContinuousStar ℂ := ⟨conjLIE.continuous⟩ @[continuity] theorem continuous_conj : Continuous (conj : ℂ → ℂ) := continuous_star /-- The only continuous ring homomorphisms from `ℂ` to `ℂ` are the identity and the complex conjugation. -/ theorem ringHom_eq_id_or_conj_of_continuous {f : ℂ →+* ℂ} (hf : Continuous f) : f = RingHom.id ℂ ∨ f = conj := by simpa only [DFunLike.ext_iff] using real_algHom_eq_id_or_conj (AlgHom.mk' f (map_real_smul f hf)) /-- Continuous linear equiv version of the conj function, from `ℂ` to `ℂ`. -/ def conjCLE : ℂ ≃L[ℝ] ℂ := conjLIE @[simp] theorem conjCLE_coe : conjCLE.toLinearEquiv = conjAe.toLinearEquiv := rfl @[simp] theorem conjCLE_apply (z : ℂ) : conjCLE z = conj z := rfl /-- Linear isometry version of the canonical embedding of `ℝ` in `ℂ`. -/ def ofRealLI : ℝ →ₗᵢ[ℝ] ℂ := ⟨ofRealAm.toLinearMap, norm_real⟩ theorem isometry_ofReal : Isometry ((↑) : ℝ → ℂ) := ofRealLI.isometry @[continuity, fun_prop] theorem continuous_ofReal : Continuous ((↑) : ℝ → ℂ) := ofRealLI.continuous lemma _root_.Filter.Tendsto.ofReal {α : Type*} {l : Filter α} {f : α → ℝ} {x : ℝ} (hf : Tendsto f l (𝓝 x)) : Tendsto (fun x ↦ (f x : ℂ)) l (𝓝 (x : ℂ)) := (continuous_ofReal.tendsto _).comp hf /-- The only continuous ring homomorphism from `ℝ` to `ℂ` is the identity. -/ theorem ringHom_eq_ofReal_of_continuous {f : ℝ →+* ℂ} (h : Continuous f) : f = Complex.ofReal := by convert congr_arg AlgHom.toRingHom <| Subsingleton.elim (AlgHom.mk' f <| map_real_smul f h) (Algebra.ofId ℝ ℂ) /-- Continuous linear map version of the canonical embedding of `ℝ` in `ℂ`. -/ def ofRealCLM : ℝ →L[ℝ] ℂ := ofRealLI.toContinuousLinearMap @[simp] theorem ofRealCLM_coe : (ofRealCLM : ℝ →ₗ[ℝ] ℂ) = ofRealAm.toLinearMap := rfl @[simp] theorem ofRealCLM_apply (x : ℝ) : ofRealCLM x = x := rfl noncomputable instance : RCLike ℂ where re := ⟨⟨Complex.re, Complex.zero_re⟩, Complex.add_re⟩ im := ⟨⟨Complex.im, Complex.zero_im⟩, Complex.add_im⟩ I := Complex.I I_re_ax := I_re I_mul_I_ax := .inr Complex.I_mul_I re_add_im_ax := re_add_im ofReal_re_ax := ofReal_re ofReal_im_ax := ofReal_im mul_re_ax := mul_re mul_im_ax := mul_im conj_re_ax _ := rfl conj_im_ax _ := rfl conj_I_ax := conj_I norm_sq_eq_def_ax z := (normSq_eq_abs z).symm mul_im_I_ax _ := mul_one _ toPartialOrder := Complex.partialOrder le_iff_re_im := Iff.rfl theorem _root_.RCLike.re_eq_complex_re : ⇑(RCLike.re : ℂ →+ ℝ) = Complex.re := rfl theorem _root_.RCLike.im_eq_complex_im : ⇑(RCLike.im : ℂ →+ ℝ) = Complex.im := rfl -- TODO: Replace `mul_conj` and `conj_mul` once `norm` has replaced `abs` lemma mul_conj' (z : ℂ) : z * conj z = ‖z‖ ^ 2 := RCLike.mul_conj z lemma conj_mul' (z : ℂ) : conj z * z = ‖z‖ ^ 2 := RCLike.conj_mul z lemma inv_eq_conj (hz : ‖z‖ = 1) : z⁻¹ = conj z := RCLike.inv_eq_conj hz lemma exists_norm_eq_mul_self (z : ℂ) : ∃ c, ‖c‖ = 1 ∧ ‖z‖ = c * z := RCLike.exists_norm_eq_mul_self _ lemma exists_norm_mul_eq_self (z : ℂ) : ∃ c, ‖c‖ = 1 ∧ c * ‖z‖ = z := RCLike.exists_norm_mul_eq_self _ /-- The natural isomorphism between `𝕜` satisfying `RCLike 𝕜` and `ℂ` when `RCLike.im RCLike.I = 1`. -/ @[simps] def _root_.RCLike.complexRingEquiv {𝕜 : Type*} [RCLike 𝕜] (h : RCLike.im (RCLike.I : 𝕜) = 1) : 𝕜 ≃+* ℂ where toFun x := RCLike.re x + RCLike.im x * I invFun x := re x + im x * RCLike.I left_inv x := by simp right_inv x := by simp [h] map_add' x y := by simp only [map_add, ofReal_add]; ring map_mul' x y := by simp only [RCLike.mul_re, ofReal_sub, ofReal_mul, RCLike.mul_im, ofReal_add] ring_nf rw [I_sq] ring /-- The natural `ℝ`-linear isometry equivalence between `𝕜` satisfying `RCLike 𝕜` and `ℂ` when `RCLike.im RCLike.I = 1`. -/ @[simps] def _root_.RCLike.complexLinearIsometryEquiv {𝕜 : Type*} [RCLike 𝕜] (h : RCLike.im (RCLike.I : 𝕜) = 1) : 𝕜 ≃ₗᵢ[ℝ] ℂ where map_smul' _ _ := by simp [RCLike.smul_re, RCLike.smul_im, ofReal_mul]; ring norm_map' _ := by rw [← sq_eq_sq (by positivity) (by positivity), ← normSq_eq_norm_sq, ← RCLike.normSq_eq_def', RCLike.normSq_apply] simp [normSq_add] __ := RCLike.complexRingEquiv h section ComplexOrder open ComplexOrder theorem eq_coe_norm_of_nonneg {z : ℂ} (hz : 0 ≤ z) : z = ↑‖z‖ := by lift z to ℝ using hz.2.symm rw [norm_eq_abs, abs_ofReal, _root_.abs_of_nonneg (id hz.1 : 0 ≤ z)] /-- We show that the partial order and the topology on `ℂ` are compatible. We turn this into an instance scoped to `ComplexOrder`. -/ lemma orderClosedTopology : OrderClosedTopology ℂ where isClosed_le' := by simp_rw [le_def, Set.setOf_and] refine IsClosed.inter (isClosed_le ?_ ?_) (isClosed_eq ?_ ?_) <;> continuity scoped[ComplexOrder] attribute [instance] Complex.orderClosedTopology end ComplexOrder end Complex namespace RCLike open ComplexConjugate local notation "reC" => @RCLike.re ℂ _ local notation "imC" => @RCLike.im ℂ _ local notation "IC" => @RCLike.I ℂ _ local notation "norm_sqC" => @RCLike.normSq ℂ _ @[simp] theorem re_to_complex {x : ℂ} : reC x = x.re := rfl @[simp] theorem im_to_complex {x : ℂ} : imC x = x.im := rfl @[simp] theorem I_to_complex : IC = Complex.I := rfl @[simp] theorem normSq_to_complex {x : ℂ} : norm_sqC x = Complex.normSq x := rfl section tsum variable {α : Type*} (𝕜 : Type*) [RCLike 𝕜] @[simp] theorem hasSum_conj {f : α → 𝕜} {x : 𝕜} : HasSum (fun x => conj (f x)) x ↔ HasSum f (conj x) := conjCLE.hasSum theorem hasSum_conj' {f : α → 𝕜} {x : 𝕜} : HasSum (fun x => conj (f x)) (conj x) ↔ HasSum f x := conjCLE.hasSum' @[simp] theorem summable_conj {f : α → 𝕜} : (Summable fun x => conj (f x)) ↔ Summable f := summable_star_iff variable {𝕜} theorem conj_tsum (f : α → 𝕜) : conj (∑' a, f a) = ∑' a, conj (f a) := tsum_star variable (𝕜) @[simp, norm_cast] theorem hasSum_ofReal {f : α → ℝ} {x : ℝ} : HasSum (fun x => (f x : 𝕜)) x ↔ HasSum f x := ⟨fun h => by simpa only [RCLike.reCLM_apply, RCLike.ofReal_re] using reCLM.hasSum h, ofRealCLM.hasSum⟩ @[simp, norm_cast] theorem summable_ofReal {f : α → ℝ} : (Summable fun x => (f x : 𝕜)) ↔ Summable f := ⟨fun h => by simpa only [RCLike.reCLM_apply, RCLike.ofReal_re] using reCLM.summable h, ofRealCLM.summable⟩ @[norm_cast] theorem ofReal_tsum (f : α → ℝ) : (↑(∑' a, f a) : 𝕜) = ∑' a, (f a : 𝕜) := by by_cases h : Summable f · exact ContinuousLinearMap.map_tsum ofRealCLM h · rw [tsum_eq_zero_of_not_summable h, tsum_eq_zero_of_not_summable ((summable_ofReal _).not.mpr h), ofReal_zero] theorem hasSum_re {f : α → 𝕜} {x : 𝕜} (h : HasSum f x) : HasSum (fun x => re (f x)) (re x) := reCLM.hasSum h theorem hasSum_im {f : α → 𝕜} {x : 𝕜} (h : HasSum f x) : HasSum (fun x => im (f x)) (im x) := imCLM.hasSum h theorem re_tsum {f : α → 𝕜} (h : Summable f) : re (∑' a, f a) = ∑' a, re (f a) := reCLM.map_tsum h theorem im_tsum {f : α → 𝕜} (h : Summable f) : im (∑' a, f a) = ∑' a, im (f a) := imCLM.map_tsum h variable {𝕜} theorem hasSum_iff (f : α → 𝕜) (c : 𝕜) : HasSum f c ↔ HasSum (fun x => re (f x)) (re c) ∧ HasSum (fun x => im (f x)) (im c) := by refine ⟨fun h => ⟨hasSum_re _ h, hasSum_im _ h⟩, ?_⟩ rintro ⟨h₁, h₂⟩ simpa only [re_add_im] using ((hasSum_ofReal 𝕜).mpr h₁).add (((hasSum_ofReal 𝕜).mpr h₂).mul_right I) end tsum end RCLike namespace Complex /-! We have to repeat the lemmas about `RCLike.re` and `RCLike.im` as they are not syntactic matches for `Complex.re` and `Complex.im`. We do not have this problem with `ofReal` and `conj`, although we repeat them anyway for discoverability and to avoid the need to unify `𝕜`. -/ section tsum variable {α : Type*} open ComplexConjugate -- Porting note: @[simp] unneeded due to `RCLike.hasSum_conj` theorem hasSum_conj {f : α → ℂ} {x : ℂ} : HasSum (fun x => conj (f x)) x ↔ HasSum f (conj x) := RCLike.hasSum_conj _ theorem hasSum_conj' {f : α → ℂ} {x : ℂ} : HasSum (fun x => conj (f x)) (conj x) ↔ HasSum f x := RCLike.hasSum_conj' _ -- Porting note: @[simp] unneeded due to `RCLike.summable_conj` theorem summable_conj {f : α → ℂ} : (Summable fun x => conj (f x)) ↔ Summable f := RCLike.summable_conj _ theorem conj_tsum (f : α → ℂ) : conj (∑' a, f a) = ∑' a, conj (f a) := RCLike.conj_tsum _ @[simp, norm_cast] theorem hasSum_ofReal {f : α → ℝ} {x : ℝ} : HasSum (fun x => (f x : ℂ)) x ↔ HasSum f x := RCLike.hasSum_ofReal _ @[simp, norm_cast] theorem summable_ofReal {f : α → ℝ} : (Summable fun x => (f x : ℂ)) ↔ Summable f := RCLike.summable_ofReal _ @[norm_cast] theorem ofReal_tsum (f : α → ℝ) : (↑(∑' a, f a) : ℂ) = ∑' a, ↑(f a) := RCLike.ofReal_tsum _ _ theorem hasSum_re {f : α → ℂ} {x : ℂ} (h : HasSum f x) : HasSum (fun x => (f x).re) x.re := RCLike.hasSum_re _ h theorem hasSum_im {f : α → ℂ} {x : ℂ} (h : HasSum f x) : HasSum (fun x => (f x).im) x.im := RCLike.hasSum_im _ h theorem re_tsum {f : α → ℂ} (h : Summable f) : (∑' a, f a).re = ∑' a, (f a).re := RCLike.re_tsum _ h theorem im_tsum {f : α → ℂ} (h : Summable f) : (∑' a, f a).im = ∑' a, (f a).im := RCLike.im_tsum _ h theorem hasSum_iff (f : α → ℂ) (c : ℂ) : HasSum f c ↔ HasSum (fun x => (f x).re) c.re ∧ HasSum (fun x => (f x).im) c.im := RCLike.hasSum_iff _ _ end tsum section slitPlane /-! ### Define the "slit plane" `ℂ ∖ ℝ≤0` and provide some API -/ open scoped ComplexOrder /-- The *slit plane* is the complex plane with the closed negative real axis removed. -/ def slitPlane : Set ℂ := {z | 0 < z.re ∨ z.im ≠ 0} lemma mem_slitPlane_iff {z : ℂ} : z ∈ slitPlane ↔ 0 < z.re ∨ z.im ≠ 0 := Set.mem_setOf lemma slitPlane_eq_union : slitPlane = {z | 0 < z.re} ∪ {z | z.im ≠ 0} := Set.setOf_or.symm lemma isOpen_slitPlane : IsOpen slitPlane := (isOpen_lt continuous_const continuous_re).union (isOpen_ne_fun continuous_im continuous_const) @[simp] lemma ofReal_mem_slitPlane {x : ℝ} : ↑x ∈ slitPlane ↔ 0 < x := by simp [mem_slitPlane_iff] @[simp] lemma neg_ofReal_mem_slitPlane {x : ℝ} : -↑x ∈ slitPlane ↔ x < 0 := by simpa using ofReal_mem_slitPlane (x := -x) @[simp] lemma one_mem_slitPlane : 1 ∈ slitPlane := ofReal_mem_slitPlane.2 one_pos @[simp] lemma zero_not_mem_slitPlane : 0 ∉ slitPlane := mt ofReal_mem_slitPlane.1 (lt_irrefl _) @[simp] lemma natCast_mem_slitPlane {n : ℕ} : ↑n ∈ slitPlane ↔ n ≠ 0 := by simpa [pos_iff_ne_zero] using @ofReal_mem_slitPlane n @[deprecated (since := "2024-04-17")] alias nat_cast_mem_slitPlane := natCast_mem_slitPlane @[simp] lemma ofNat_mem_slitPlane (n : ℕ) [n.AtLeastTwo] : no_index (OfNat.ofNat n) ∈ slitPlane := natCast_mem_slitPlane.2 (NeZero.ne n) lemma mem_slitPlane_iff_not_le_zero {z : ℂ} : z ∈ slitPlane ↔ ¬z ≤ 0 := mem_slitPlane_iff.trans not_le_zero_iff.symm protected lemma compl_Iic_zero : (Set.Iic 0)ᶜ = slitPlane := Set.ext fun _ ↦ mem_slitPlane_iff_not_le_zero.symm lemma slitPlane_ne_zero {z : ℂ} (hz : z ∈ slitPlane) : z ≠ 0 := ne_of_mem_of_not_mem hz zero_not_mem_slitPlane /-- The slit plane includes the open unit ball of radius `1` around `1`. -/ lemma ball_one_subset_slitPlane : Metric.ball 1 1 ⊆ slitPlane := fun z hz ↦ .inl <| have : -1 < z.re - 1 := neg_lt_of_abs_lt <| (abs_re_le_abs _).trans_lt hz by linarith /-- The slit plane includes the open unit ball of radius `1` around `1`. -/ lemma mem_slitPlane_of_norm_lt_one {z : ℂ} (hz : ‖z‖ < 1) : 1 + z ∈ slitPlane := ball_one_subset_slitPlane <| by simpa end slitPlane end Complex
Analysis\Complex\CauchyIntegral.lean
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.Lebesgue.Complex import Mathlib.MeasureTheory.Integral.DivergenceTheorem import Mathlib.MeasureTheory.Integral.CircleIntegral import Mathlib.Analysis.Calculus.Dslope import Mathlib.Analysis.Analytic.Basic import Mathlib.Analysis.Complex.ReImTopology import Mathlib.Analysis.Calculus.DiffContOnCl import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Data.Real.Cardinality /-! # Cauchy integral formula In this file we prove the Cauchy-Goursat theorem and the Cauchy integral formula for integrals over circles. Most results are formulated for a function `f : ℂ → E` that takes values in a complex Banach space with second countable topology. ## Main statements In the following theorems, if the name ends with `off_countable`, then the actual theorem assumes differentiability at all but countably many points of the set mentioned below. * `Complex.integral_boundary_rect_of_hasFDerivAt_real_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and *real* differentiable on its interior, then its integral over the boundary of this rectangle is equal to the integral of `I • f' (x + y * I) 1 - f' (x + y * I) I` over the rectangle, where `f' z w : E` is the derivative of `f` at `z` in the direction `w` and `I = Complex.I` is the imaginary unit. * `Complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and is *complex* differentiable on its interior, then its integral over the boundary of this rectangle is equal to zero. * `Complex.circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable`: If a function `f : ℂ → E` is continuous on a closed annulus `{z | r ≤ |z - c| ≤ R}` and is complex differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)⁻¹ • f z` over the outer boundary and over the inner boundary are equal. * `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto`, `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a punctured closed disc `{z | |z - c| ≤ R ∧ z ≠ c}`, is complex differentiable on the corresponding punctured open disc, and tends to `y` as `z → c`, `z ≠ c`, then the integral of `(z - c)⁻¹ • f z` over the circle `|z - c| = R` is equal to `2πiy`. In particular, if `f` is continuous on the whole closed disc and is complex differentiable on the corresponding open disc, then this integral is equal to `2πif(c)`. * `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`, `Complex.two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable` **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable on the corresponding open disc, then for any `w` in the corresponding open disc the integral of `(z - w)⁻¹ • f z` over the boundary of the disc is equal to `2πif(w)`. Two versions of the lemma put the multiplier `2πi` at the different sides of the equality. * `Complex.hasFPowerSeriesOnBall_of_differentiable_off_countable`: If `f : ℂ → E` is continuous on a closed disc of positive radius and is complex differentiable on the corresponding open disc, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.hasFPowerSeriesOnBall`: If `f : ℂ → E` is complex differentiable on a closed disc of positive radius, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.analyticAt`, `Differentiable.analyticAt`: If `f : ℂ → E` is differentiable on a neighborhood of a point, then it is analytic at this point. In particular, if `f : ℂ → E` is differentiable on the whole `ℂ`, then it is analytic at every point `z : ℂ`. * `Differentiable.hasFPowerSeriesOnBall`: If `f : ℂ → E` is differentiable everywhere then the `cauchyPowerSeries f z R` is a formal power series representing `f` at `z` with infinite radius of convergence (this holds for any choice of `0 < R`). ## Implementation details The proof of the Cauchy integral formula in this file is based on a very general version of the divergence theorem, see `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` (a version for functions defined on `Fin (n + 1) → ℝ`), `MeasureTheory.integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le`, and `MeasureTheory.integral2_divergence_prod_of_hasFDerivWithinAt_off_countable` (versions for functions defined on `ℝ × ℝ`). Usually, the divergence theorem is formulated for a $C^1$ smooth function. The theorems formulated above deal with a function that is * continuous on a closed box/rectangle; * differentiable at all but countably many points of its interior; * have divergence integrable over the closed box/rectangle. First, we reformulate the theorem for a *real*-differentiable map `ℂ → E`, and relate the integral of `f` over the boundary of a rectangle in `ℂ` to the integral of the derivative $\frac{\partial f}{\partial \bar z}$ over the interior of this box. In particular, for a *complex* differentiable function, the latter derivative is zero, hence the integral over the boundary of a rectangle is zero. Thus we get the Cauchy-Goursat theorem for a rectangle in `ℂ`. Next, we apply this theorem to the function $F(z)=f(c+e^{z})$ on the rectangle $[\ln r, \ln R]\times [0, 2\pi]$ to prove that $$ \oint_{|z-c|=r}\frac{f(z)\,dz}{z-c}=\oint_{|z-c|=R}\frac{f(z)\,dz}{z-c} $$ provided that `f` is continuous on the closed annulus `r ≤ |z - c| ≤ R` and is complex differentiable on its interior `r < |z - c| < R` (possibly, at all but countably many points). Here and below, we write $\frac{f(z)}{z-c}$ in the documentation while the actual lemmas use `(z - c)⁻¹ • f z` because `f z` belongs to some Banach space over `ℂ` and `f z / (z - c)` is undefined. Taking the limit of this equality as `r` tends to `𝓝[>] 0`, we prove $$ \oint_{|z-c|=R}\frac{f(z)\,dz}{z-c}=2\pi if(c) $$ provided that `f` is continuous on the closed disc `|z - c| ≤ R` and is differentiable at all but countably many points of its interior. This is the Cauchy integral formula for the center of a circle. In particular, if we apply this function to `F z = (z - c) • f z`, then we get $$ \oint_{|z-c|=R} f(z)\,dz=0. $$ In order to deduce the Cauchy integral formula for any point `w`, `|w - c| < R`, we consider the slope function `g : ℂ → E` given by `g z = (z - w)⁻¹ • (f z - f w)` if `z ≠ w` and `g w = f' w`. This function satisfies assumptions of the previous theorem, so we have $$ \oint_{|z-c|=R} \frac{f(z)\,dz}{z-w}=\oint_{|z-c|=R} \frac{f(w)\,dz}{z-w}= \left(\oint_{|z-c|=R} \frac{dz}{z-w}\right)f(w). $$ The latter integral was computed in `circleIntegral.integral_sub_inv_of_mem_ball` and is equal to `2 * π * Complex.I`. There is one more step in the actual proof. Since we allow `f` to be non-differentiable on a countable set `s`, we cannot immediately claim that `g` is continuous at `w` if `w ∈ s`. So, we use the proof outlined in the previous paragraph for `w ∉ s` (see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux`), then use continuity of both sides of the formula and density of `sᶜ` to prove the formula for all points of the open ball, see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. Finally, we use the properties of the Cauchy integrals established elsewhere (see `hasFPowerSeriesOn_cauchy_integral`) and Cauchy integral formula to prove that the original function is analytic on the open ball. ## Tags Cauchy-Goursat theorem, Cauchy integral formula -/ open TopologicalSpace Set MeasureTheory intervalIntegral Metric Filter Function open scoped Interval Real NNReal ENNReal Topology noncomputable section universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] namespace Complex /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable at all but countably many points of the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_hasFDerivAt_real_off_countable (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := by set e : (ℝ × ℝ) ≃L[ℝ] ℂ := equivRealProdCLM.symm have he : ∀ x y : ℝ, ↑x + ↑y * I = e (x, y) := fun x y => (mk_eq_add_mul_I x y).symm have he₁ : e (1, 0) = 1 := rfl; have he₂ : e (0, 1) = I := rfl simp only [he] at * set F : ℝ × ℝ → E := f ∘ e set F' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E := fun p => (f' (e p)).comp (e : ℝ × ℝ →L[ℝ] ℂ) have hF' : ∀ p : ℝ × ℝ, (-(I • F' p)) (1, 0) + F' p (0, 1) = -(I • f' (e p) 1 - f' (e p) I) := by rintro ⟨x, y⟩ simp only [F', ContinuousLinearMap.neg_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, ContinuousLinearEquiv.coe_coe, he₁, he₂, neg_add_eq_sub, neg_sub] set R : Set (ℝ × ℝ) := [[z.re, w.re]] ×ˢ [[w.im, z.im]] set t : Set (ℝ × ℝ) := e ⁻¹' s rw [uIcc_comm z.im] at Hc Hi; rw [min_comm z.im, max_comm z.im] at Hd have hR : e ⁻¹' ([[z.re, w.re]] ×ℂ [[w.im, z.im]]) = R := rfl have htc : ContinuousOn F R := Hc.comp e.continuousOn hR.ge have htd : ∀ p ∈ Ioo (min z.re w.re) (max z.re w.re) ×ˢ Ioo (min w.im z.im) (max w.im z.im) \ t, HasFDerivAt F (F' p) p := fun p hp => (Hd (e p) hp).comp p e.hasFDerivAt simp_rw [← intervalIntegral.integral_smul, intervalIntegral.integral_symm w.im z.im, ← intervalIntegral.integral_neg, ← hF'] refine (integral2_divergence_prod_of_hasFDerivWithinAt_off_countable (fun p => -(I • F p)) F (fun p => -(I • F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective) (htc.const_smul _).neg htc (fun p hp => ((htd p hp).const_smul I).neg) htd ?_).symm rw [← (volume_preserving_equiv_real_prod.symm _).integrableOn_comp_preimage (MeasurableEquiv.measurableEmbedding _)] at Hi simpa only [hF'] using Hi.neg /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable on the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_continuousOn_of_hasFDerivAt_real (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im), HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f f' z w ∅ countable_empty Hc (fun x hx => Hd x hx.1) Hi /-- Suppose that a function `f : ℂ → E` is *real* differentiable on a closed rectangle with opposite corners at `z w : ℂ` and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_differentiableOn_real (f : ℂ → E) (z w : ℂ) (Hd : DifferentiableOn ℝ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hi : IntegrableOn (fun z => I • fderiv ℝ f z 1 - fderiv ℝ f z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • fderiv ℝ f (x + y * I) 1 - fderiv ℝ f (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fderiv ℝ f) z w ∅ countable_empty Hd.continuousOn (fun x hx => Hd.hasFDerivAt <| by simpa only [← mem_interior_iff_mem_nhds, interior_reProdIm, uIcc, interior_Icc] using hx.1) Hi /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable at all but countably many points of the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiable_on_off_countable (f : ℂ → E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, DifferentiableAt ℂ f x) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := by refine (integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fun z => (fderiv ℂ f z).restrictScalars ℝ) z w s hs Hc (fun x hx => (Hd x hx).hasFDerivAt.restrictScalars ℝ) ?_).trans ?_ <;> simp [← ContinuousLinearMap.map_smul] /-- **Cauchy-Goursat theorem for a rectangle**: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable on the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn (f : ℂ → E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : DifferentiableOn ℂ f (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im))) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w ∅ countable_empty Hc fun _x hx => Hd.differentiableAt <| (isOpen_Ioo.reProdIm isOpen_Ioo).mem_nhds hx.1 /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is complex differentiable on a closed rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiableOn (f : ℂ → E) (z w : ℂ) (H : DifferentiableOn ℂ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn f z w H.continuousOn <| H.mono <| inter_subset_inter (preimage_mono Ioo_subset_Icc_self) (preimage_mono Ioo_subset_Icc_self) /-- If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f z / (z - c)` (formally, `(z - c)⁻¹ • f z`) over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = ∮ z in C(c, r), (z - c)⁻¹ • f z := by /- We apply the previous lemma to `fun z ↦ f (c + exp z)` on the rectangle `[log r, log R] × [0, 2 * π]`. -/ set A := closedBall c R \ ball c r obtain ⟨a, rfl⟩ : ∃ a, Real.exp a = r := ⟨Real.log r, Real.exp_log h0⟩ obtain ⟨b, rfl⟩ : ∃ b, Real.exp b = R := ⟨Real.log R, Real.exp_log (h0.trans_le hle)⟩ rw [Real.exp_le_exp] at hle -- Unfold definition of `circleIntegral` and cancel some terms. suffices (∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp b) θ)) = ∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp a) θ) by simpa only [circleIntegral, add_sub_cancel_left, ofReal_exp, ← exp_add, smul_smul, ← div_eq_mul_inv, mul_div_cancel_left₀ _ (circleMap_ne_center (Real.exp_pos _).ne'), circleMap_sub_center, deriv_circleMap] set R := [[a, b]] ×ℂ [[0, 2 * π]] set g : ℂ → ℂ := (c + exp ·) have hdg : Differentiable ℂ g := differentiable_exp.const_add _ replace hs : (g ⁻¹' s).Countable := (hs.preimage (add_right_injective c)).preimage_cexp have h_maps : MapsTo g R A := by rintro z ⟨h, -⟩; simpa [g, A, dist_eq, abs_exp, hle] using h.symm replace hc : ContinuousOn (f ∘ g) R := hc.comp hdg.continuous.continuousOn h_maps replace hd : ∀ z ∈ Ioo (min a b) (max a b) ×ℂ Ioo (min 0 (2 * π)) (max 0 (2 * π)) \ g ⁻¹' s, DifferentiableAt ℂ (f ∘ g) z := by refine fun z hz => (hd (g z) ⟨?_, hz.2⟩).comp z (hdg _) simpa [g, dist_eq, abs_exp, hle, and_comm] using hz.1.1 simpa [g, circleMap, exp_periodic _, sub_eq_zero, ← exp_add] using integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ ⟨a, 0⟩ ⟨b, 2 * π⟩ _ hs hc hd /-- **Cauchy-Goursat theorem** for an annulus. If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f` over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = ∮ z in C(c, r), f z := calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = ∮ z in C(c, r), (z - c)⁻¹ • (z - c) • f z := (circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable h0 hle hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = ∮ z in C(c, r), f z := circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _ /-- **Cauchy integral formula** for the value at the center of a disc. If `f` is continuous on a punctured closed disc of radius `R`, is differentiable at all but countably many points of the interior of this disc, and has a limit `y` at the center of the disc, then the integral $\oint_{‖z-c‖=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto {c : ℂ} {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {y : E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ {c})) (hd : ∀ z ∈ (ball c R \ {c}) \ s, DifferentiableAt ℂ f z) (hy : Tendsto f (𝓝[{c}ᶜ] c) (𝓝 y)) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • y := by rw [← sub_eq_zero, ← norm_le_zero_iff] refine le_of_forall_le_of_dense fun ε ε0 => ?_ obtain ⟨δ, δ0, hδ⟩ : ∃ δ > (0 : ℝ), ∀ z ∈ closedBall c δ \ {c}, dist (f z) y < ε / (2 * π) := ((nhdsWithin_hasBasis nhds_basis_closedBall _).tendsto_iff nhds_basis_ball).1 hy _ (div_pos ε0 Real.two_pi_pos) obtain ⟨r, hr0, hrδ, hrR⟩ : ∃ r, 0 < r ∧ r ≤ δ ∧ r ≤ R := ⟨min δ R, lt_min δ0 h0, min_le_left _ _, min_le_right _ _⟩ have hsub : closedBall c R \ ball c r ⊆ closedBall c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_ball_self hr0) have hsub' : ball c R \ closedBall c r ⊆ ball c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_closedBall_self hr0.le) have hzne : ∀ z ∈ sphere c r, z ≠ c := fun z hz => ne_of_mem_of_not_mem hz fun h => hr0.ne' <| dist_self c ▸ Eq.symm h /- The integral `∮ z in C(c, r), f z / (z - c)` does not depend on `0 < r ≤ R` and tends to `2πIy` as `r → 0`. -/ calc ‖(∮ z in C(c, R), (z - c)⁻¹ • f z) - (2 * ↑π * I) • y‖ = ‖(∮ z in C(c, r), (z - c)⁻¹ • f z) - ∮ z in C(c, r), (z - c)⁻¹ • y‖ := by congr 2 · exact circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable hr0 hrR hs (hc.mono hsub) fun z hz => hd z ⟨hsub' hz.1, hz.2⟩ · simp [hr0.ne'] _ = ‖∮ z in C(c, r), (z - c)⁻¹ • (f z - y)‖ := by simp only [smul_sub] have hc' : ContinuousOn (fun z => (z - c)⁻¹) (sphere c r) := (continuousOn_id.sub continuousOn_const).inv₀ fun z hz => sub_ne_zero.2 <| hzne _ hz rw [circleIntegral.integral_sub] <;> refine (hc'.smul ?_).circleIntegrable hr0.le · exact hc.mono <| subset_inter (sphere_subset_closedBall.trans <| closedBall_subset_closedBall hrR) hzne · exact continuousOn_const _ ≤ 2 * π * r * (r⁻¹ * (ε / (2 * π))) := by refine circleIntegral.norm_integral_le_of_norm_le_const hr0.le fun z hz => ?_ specialize hzne z hz rw [mem_sphere, dist_eq_norm] at hz rw [norm_smul, norm_inv, hz, ← dist_eq_norm] refine mul_le_mul_of_nonneg_left (hδ _ ⟨?_, hzne⟩).le (inv_nonneg.2 hr0.le) rwa [mem_closedBall_iff_norm, hz] _ = ε := by field_simp [hr0.ne', Real.two_pi_pos.ne']; ac_rfl /-- **Cauchy integral formula** for the value at the center of a disc. If `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • f c := circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs (hc.mono diff_subset) (fun z hz => hd z ⟨hz.1.1, hz.2⟩) (hc.continuousAt <| closedBall_mem_nhds _ h0).continuousWithinAt /-- **Cauchy-Goursat theorem** for a disk: if `f : ℂ → E` is continuous on a closed disk `{z | ‖z - c‖ ≤ R}` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R}f(z)\,dz$ equals zero. -/ theorem circleIntegral_eq_zero_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 ≤ R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = 0 := by rcases h0.eq_or_lt with (rfl | h0); · apply circleIntegral.integral_radius_zero calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = (2 * ↑π * I : ℂ) • (c - c) • f c := (circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable h0 hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = 0 := by rw [sub_self, zero_smul, smul_zero] /-- An auxiliary lemma for `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. This lemma assumes `w ∉ s` while the main lemma drops this assumption. -/ theorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R \ s) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ x ∈ ball c R \ s, DifferentiableAt ℂ f x) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := by have hR : 0 < R := dist_nonneg.trans_lt hw.1 set F : ℂ → E := dslope f w have hws : (insert w s).Countable := hs.insert w have hcF : ContinuousOn F (closedBall c R) := (continuousOn_dslope <| closedBall_mem_nhds_of_mem hw.1).2 ⟨hc, hd _ hw⟩ have hdF : ∀ z ∈ ball (c : ℂ) R \ insert w s, DifferentiableAt ℂ F z := fun z hz => (differentiableAt_dslope_of_ne (ne_of_mem_of_not_mem (mem_insert _ _) hz.2).symm).2 (hd _ (diff_subset_diff_right (subset_insert _ _) hz)) have HI := circleIntegral_eq_zero_of_differentiable_on_off_countable hR.le hws hcF hdF have hne : ∀ z ∈ sphere c R, z ≠ w := fun z hz => ne_of_mem_of_not_mem hz (ne_of_lt hw.1) have hFeq : EqOn F (fun z => (z - w)⁻¹ • f z - (z - w)⁻¹ • f w) (sphere c R) := fun z hz ↦ calc F z = (z - w)⁻¹ • (f z - f w) := update_noteq (hne z hz) _ _ _ = (z - w)⁻¹ • f z - (z - w)⁻¹ • f w := smul_sub _ _ _ have hc' : ContinuousOn (fun z => (z - w)⁻¹) (sphere c R) := (continuousOn_id.sub continuousOn_const).inv₀ fun z hz => sub_ne_zero.2 <| hne z hz rw [← circleIntegral.integral_sub_inv_of_mem_ball hw.1, ← circleIntegral.integral_smul_const, ← sub_eq_zero, ← circleIntegral.integral_sub, ← circleIntegral.integral_congr hR.le hFeq, HI] exacts [(hc'.smul (hc.mono sphere_subset_closedBall)).circleIntegrable hR.le, (hc'.smul continuousOn_const).circleIntegrable hR.le] /-- **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then for any `w` in this interior we have $\frac{1}{2πi}\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=f(w)$. -/ theorem two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ x ∈ ball c R \ s, DifferentiableAt ℂ f x) : ((2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z) = f w := by have hR : 0 < R := dist_nonneg.trans_lt hw suffices w ∈ closure (ball c R \ s) by lift R to ℝ≥0 using hR.le have A : ContinuousAt (fun w => (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z) w := by have := hasFPowerSeriesOn_cauchy_integral ((hc.mono sphere_subset_closedBall).circleIntegrable R.coe_nonneg) hR refine this.continuousOn.continuousAt (EMetric.isOpen_ball.mem_nhds ?_) rwa [Metric.emetric_ball_nnreal] have B : ContinuousAt f w := hc.continuousAt (closedBall_mem_nhds_of_mem hw) refine tendsto_nhds_unique_of_frequently_eq A B ((mem_closure_iff_frequently.1 this).mono ?_) intro z hz rw [circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux hs hz hc hd, inv_smul_smul₀] simp [Real.pi_ne_zero, I_ne_zero] refine mem_closure_iff_nhds.2 fun t ht => ?_ -- TODO: generalize to any vector space over `ℝ` set g : ℝ → ℂ := fun x => w + ofReal x have : Tendsto g (𝓝 0) (𝓝 w) := (continuous_const.add continuous_ofReal).tendsto' 0 w (add_zero _) rcases mem_nhds_iff_exists_Ioo_subset.1 (this <| inter_mem ht <| isOpen_ball.mem_nhds hw) with ⟨l, u, hlu₀, hlu_sub⟩ obtain ⟨x, hx⟩ : (Ioo l u \ g ⁻¹' s).Nonempty := by refine nonempty_diff.2 fun hsub => ?_ have : (Ioo l u).Countable := (hs.preimage ((add_right_injective w).comp ofReal_injective)).mono hsub rw [← Cardinal.le_aleph0_iff_set_countable, Cardinal.mk_Ioo_real (hlu₀.1.trans hlu₀.2)] at this exact this.not_lt Cardinal.aleph0_lt_continuum exact ⟨g x, (hlu_sub hx.1).1, (hlu_sub hx.1).2, hx.2⟩ /-- **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then for any `w` in this interior we have $\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=2πif(w)$. -/ theorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ x ∈ ball c R \ s, DifferentiableAt ℂ f x) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := by rw [← two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable hs hw hc hd, smul_inv_smul₀] simp [Real.pi_ne_zero, I_ne_zero] /-- **Cauchy integral formula**: if `f : ℂ → E` is complex differentiable on an open disc and is continuous on its closure, then for any `w` in this open ball we have $\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=2πif(w)$. -/ theorem _root_.DiffContOnCl.circleIntegral_sub_inv_smul {R : ℝ} {c w : ℂ} {f : ℂ → E} (h : DiffContOnCl ℂ f (ball c R)) (hw : w ∈ ball c R) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := circleIntegral_sub_inv_smul_of_differentiable_on_off_countable countable_empty hw h.continuousOn_ball fun _x hx => h.differentiableAt isOpen_ball hx.1 /-- **Cauchy integral formula**: if `f : ℂ → E` is complex differentiable on an open disc and is continuous on its closure, then for any `w` in this open ball we have $\frac{1}{2πi}\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=f(w)$. -/ theorem _root_.DiffContOnCl.two_pi_i_inv_smul_circleIntegral_sub_inv_smul {R : ℝ} {c w : ℂ} {f : ℂ → E} (hf : DiffContOnCl ℂ f (ball c R)) (hw : w ∈ ball c R) : ((2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - w)⁻¹ • f z) = f w := by have hR : 0 < R := not_le.mp (ball_eq_empty.not.mp (Set.nonempty_of_mem hw).ne_empty) refine two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable countable_empty hw ?_ ?_ · simpa only [closure_ball c hR.ne.symm] using hf.continuousOn · simpa only [diff_empty] using fun z hz => hf.differentiableAt isOpen_ball hz /-- **Cauchy integral formula**: if `f : ℂ → E` is complex differentiable on a closed disc of radius `R`, then for any `w` in its interior we have $\oint_{|z-c|=R}(z-w)^{-1}f(z)\,dz=2πif(w)$. -/ theorem _root_.DifferentiableOn.circleIntegral_sub_inv_smul {R : ℝ} {c w : ℂ} {f : ℂ → E} (hd : DifferentiableOn ℂ f (closedBall c R)) (hw : w ∈ ball c R) : (∮ z in C(c, R), (z - w)⁻¹ • f z) = (2 * π * I : ℂ) • f w := (hd.mono closure_ball_subset_closedBall).diffContOnCl.circleIntegral_sub_inv_smul hw /-- **Cauchy integral formula**: if `f : ℂ → ℂ` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then for any `w` in this interior we have $\oint_{|z-c|=R}\frac{f(z)}{z-w}dz=2\pi i\,f(w)$. -/ theorem circleIntegral_div_sub_of_differentiable_on_off_countable {R : ℝ} {c w : ℂ} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R) {f : ℂ → ℂ} (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z / (z - w)) = 2 * π * I * f w := by simpa only [smul_eq_mul, div_eq_inv_mul] using circleIntegral_sub_inv_smul_of_differentiable_on_off_countable hs hw hc hd /-- If `f : ℂ → E` is continuous on a closed ball of positive radius and is differentiable at all but countably many points of the corresponding open ball, then it is analytic on the open ball with coefficients of the power series given by Cauchy integral formulas. -/ theorem hasFPowerSeriesOnBall_of_differentiable_off_countable {R : ℝ≥0} {c : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) (hR : 0 < R) : HasFPowerSeriesOnBall f (cauchyPowerSeries f c R) c R where r_le := le_radius_cauchyPowerSeries _ _ _ r_pos := ENNReal.coe_pos.2 hR hasSum := fun {w} hw => by have hw' : c + w ∈ ball c R := by simpa only [add_mem_ball_iff_norm, ← coe_nnnorm, mem_emetric_ball_zero_iff, NNReal.coe_lt_coe, ENNReal.coe_lt_coe] using hw rw [← two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable hs hw' hc hd] exact (hasFPowerSeriesOn_cauchy_integral ((hc.mono sphere_subset_closedBall).circleIntegrable R.2) hR).hasSum hw /-- If `f : ℂ → E` is complex differentiable on an open disc of positive radius and is continuous on its closure, then it is analytic on the open disc with coefficients of the power series given by Cauchy integral formulas. -/ theorem _root_.DiffContOnCl.hasFPowerSeriesOnBall {R : ℝ≥0} {c : ℂ} {f : ℂ → E} (hf : DiffContOnCl ℂ f (ball c R)) (hR : 0 < R) : HasFPowerSeriesOnBall f (cauchyPowerSeries f c R) c R := hasFPowerSeriesOnBall_of_differentiable_off_countable countable_empty hf.continuousOn_ball (fun _z hz => hf.differentiableAt isOpen_ball hz.1) hR /-- If `f : ℂ → E` is complex differentiable on a closed disc of positive radius, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. See also `Complex.hasFPowerSeriesOnBall_of_differentiable_off_countable` for a version of this lemma with weaker assumptions. -/ protected theorem _root_.DifferentiableOn.hasFPowerSeriesOnBall {R : ℝ≥0} {c : ℂ} {f : ℂ → E} (hd : DifferentiableOn ℂ f (closedBall c R)) (hR : 0 < R) : HasFPowerSeriesOnBall f (cauchyPowerSeries f c R) c R := (hd.mono closure_ball_subset_closedBall).diffContOnCl.hasFPowerSeriesOnBall hR /-- If `f : ℂ → E` is complex differentiable on some set `s`, then it is analytic at any point `z` such that `s ∈ 𝓝 z` (equivalently, `z ∈ interior s`). -/ protected theorem _root_.DifferentiableOn.analyticAt {s : Set ℂ} {f : ℂ → E} {z : ℂ} (hd : DifferentiableOn ℂ f s) (hz : s ∈ 𝓝 z) : AnalyticAt ℂ f z := by rcases nhds_basis_closedBall.mem_iff.1 hz with ⟨R, hR0, hRs⟩ lift R to ℝ≥0 using hR0.le exact ((hd.mono hRs).hasFPowerSeriesOnBall hR0).analyticAt theorem _root_.DifferentiableOn.analyticOn {s : Set ℂ} {f : ℂ → E} (hd : DifferentiableOn ℂ f s) (hs : IsOpen s) : AnalyticOn ℂ f s := fun _z hz => hd.analyticAt (hs.mem_nhds hz) /-- If `f : ℂ → E` is complex differentiable on some open set `s`, then it is continuously differentiable on `s`. -/ protected theorem _root_.DifferentiableOn.contDiffOn {s : Set ℂ} {f : ℂ → E} {n : ℕ} (hd : DifferentiableOn ℂ f s) (hs : IsOpen s) : ContDiffOn ℂ n f s := (hd.analyticOn hs).contDiffOn /-- A complex differentiable function `f : ℂ → E` is analytic at every point. -/ protected theorem _root_.Differentiable.analyticAt {f : ℂ → E} (hf : Differentiable ℂ f) (z : ℂ) : AnalyticAt ℂ f z := hf.differentiableOn.analyticAt univ_mem /-- A complex differentiable function `f : ℂ → E` is continuously differentiable at every point. -/ protected theorem _root_.Differentiable.contDiff {f : ℂ → E} (hf : Differentiable ℂ f) {n : ℕ∞} : ContDiff ℂ n f := contDiff_iff_contDiffAt.mpr fun z ↦ (hf.analyticAt z).contDiffAt /-- When `f : ℂ → E` is differentiable, the `cauchyPowerSeries f z R` represents `f` as a power series centered at `z` in the entirety of `ℂ`, regardless of `R : ℝ≥0`, with `0 < R`. -/ protected theorem _root_.Differentiable.hasFPowerSeriesOnBall {f : ℂ → E} (h : Differentiable ℂ f) (z : ℂ) {R : ℝ≥0} (hR : 0 < R) : HasFPowerSeriesOnBall f (cauchyPowerSeries f z R) z ∞ := (h.differentiableOn.hasFPowerSeriesOnBall hR).r_eq_top_of_exists fun _r hr => ⟨_, h.differentiableOn.hasFPowerSeriesOnBall hr⟩ /-- On an open set, `f : ℂ → E` is analytic iff it is differentiable -/ theorem analyticOn_iff_differentiableOn {f : ℂ → E} {s : Set ℂ} (o : IsOpen s) : AnalyticOn ℂ f s ↔ DifferentiableOn ℂ f s := ⟨AnalyticOn.differentiableOn, fun d _ zs ↦ d.analyticAt (o.mem_nhds zs)⟩ /-- `f : ℂ → E` is entire iff it's differentiable -/ theorem analyticOn_univ_iff_differentiable {f : ℂ → E} : AnalyticOn ℂ f univ ↔ Differentiable ℂ f := by simp only [← differentiableOn_univ] exact analyticOn_iff_differentiableOn isOpen_univ /-- `f : ℂ → E` is analytic at `z` iff it's differentiable near `z` -/ theorem analyticAt_iff_eventually_differentiableAt {f : ℂ → E} {c : ℂ} : AnalyticAt ℂ f c ↔ ∀ᶠ z in 𝓝 c, DifferentiableAt ℂ f z := by constructor · intro fa filter_upwards [fa.eventually_analyticAt] apply AnalyticAt.differentiableAt · intro d rcases _root_.eventually_nhds_iff.mp d with ⟨s, d, o, m⟩ have h : AnalyticOn ℂ f s := by refine DifferentiableOn.analyticOn ?_ o intro z m exact (d z m).differentiableWithinAt exact h _ m end Complex
Analysis\Complex\Circle.lean
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Topology.ContinuousFunction.Basic import Mathlib.Analysis.Normed.Field.UnitBall /-! # The circle This file defines `circle` to be the metric sphere (`Metric.sphere`) in `ℂ` centred at `0` of radius `1`. We equip it with the following structure: * a submonoid of `ℂ` * a group * a topological group We furthermore define `expMapCircle` to be the natural map `fun t ↦ exp (t * I)` from `ℝ` to `circle`, and show that this map is a group homomorphism. ## Implementation notes Because later (in `Geometry.Manifold.Instances.Sphere`) one wants to equip the circle with a smooth manifold structure borrowed from `Metric.sphere`, the underlying set is `{z : ℂ | abs (z - 0) = 1}`. This prevents certain algebraic facts from working definitionally -- for example, the circle is not defeq to `{z : ℂ | abs z = 1}`, which is the kernel of `Complex.abs` considered as a homomorphism from `ℂ` to `ℝ`, nor is it defeq to `{z : ℂ | normSq z = 1}`, which is the kernel of the homomorphism `Complex.normSq` from `ℂ` to `ℝ`. -/ noncomputable section open Complex Metric open ComplexConjugate /-- The unit circle in `ℂ`, here given the structure of a submonoid of `ℂ`. -/ def circle : Submonoid ℂ := Submonoid.unitSphere ℂ @[simp] theorem mem_circle_iff_abs {z : ℂ} : z ∈ circle ↔ abs z = 1 := mem_sphere_zero_iff_norm theorem circle_def : ↑circle = { z : ℂ | abs z = 1 } := Set.ext fun _ => mem_circle_iff_abs @[simp] theorem abs_coe_circle (z : circle) : abs z = 1 := mem_circle_iff_abs.mp z.2 theorem mem_circle_iff_normSq {z : ℂ} : z ∈ circle ↔ normSq z = 1 := by simp [Complex.abs] @[simp] theorem normSq_eq_of_mem_circle (z : circle) : normSq z = 1 := by simp [normSq_eq_abs] theorem ne_zero_of_mem_circle (z : circle) : (z : ℂ) ≠ 0 := ne_zero_of_mem_unit_sphere z instance commGroup : CommGroup circle := Metric.sphere.commGroup @[simp] theorem coe_inv_circle (z : circle) : ↑z⁻¹ = (z : ℂ)⁻¹ := rfl theorem coe_inv_circle_eq_conj (z : circle) : ↑z⁻¹ = conj (z : ℂ) := by rw [coe_inv_circle, inv_def, normSq_eq_of_mem_circle, inv_one, ofReal_one, mul_one] @[simp] theorem coe_div_circle (z w : circle) : ↑(z / w) = (z : ℂ) / w := circle.subtype.map_div z w /-- The elements of the circle embed into the units. -/ def circle.toUnits : circle →* Units ℂ := unitSphereToUnits ℂ -- written manually because `@[simps]` was slow and generated the wrong lemma @[simp] theorem circle.toUnits_apply (z : circle) : circle.toUnits z = Units.mk0 ↑z (ne_zero_of_mem_circle z) := rfl instance : CompactSpace circle := Metric.sphere.compactSpace _ _ instance : TopologicalGroup circle := Metric.sphere.topologicalGroup instance : UniformGroup circle := by convert topologicalGroup_is_uniform_of_compactSpace circle exact unique_uniformity_of_compact rfl rfl /-- If `z` is a nonzero complex number, then `conj z / z` belongs to the unit circle. -/ @[simps] def circle.ofConjDivSelf (z : ℂ) (hz : z ≠ 0) : circle := ⟨conj z / z, mem_circle_iff_abs.2 <| by rw [map_div₀, abs_conj, div_self]; exact Complex.abs.ne_zero hz⟩ /-- The map `fun t => exp (t * I)` from `ℝ` to the unit circle in `ℂ`. -/ def expMapCircle : C(ℝ, circle) where toFun t := ⟨exp (t * I), by simp [exp_mul_I, abs_cos_add_sin_mul_I]⟩ @[simp] theorem expMapCircle_apply (t : ℝ) : ↑(expMapCircle t) = Complex.exp (t * Complex.I) := rfl @[simp] theorem expMapCircle_zero : expMapCircle 0 = 1 := Subtype.ext <| by rw [expMapCircle_apply, ofReal_zero, zero_mul, exp_zero, Submonoid.coe_one] @[simp] theorem expMapCircle_add (x y : ℝ) : expMapCircle (x + y) = expMapCircle x * expMapCircle y := Subtype.ext <| by simp only [expMapCircle_apply, Submonoid.coe_mul, ofReal_add, add_mul, Complex.exp_add] /-- The map `fun t => exp (t * I)` from `ℝ` to the unit circle in `ℂ`, considered as a homomorphism of groups. -/ @[simps] def expMapCircleHom : ℝ →+ Additive circle where toFun := Additive.ofMul ∘ expMapCircle map_zero' := expMapCircle_zero map_add' := expMapCircle_add @[simp] theorem expMapCircle_sub (x y : ℝ) : expMapCircle (x - y) = expMapCircle x / expMapCircle y := expMapCircleHom.map_sub x y @[simp] theorem expMapCircle_neg (x : ℝ) : expMapCircle (-x) = (expMapCircle x)⁻¹ := expMapCircleHom.map_neg x @[simp] lemma norm_circle_smul {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E] (u : circle) (v : E) : ‖u • v‖ = ‖v‖ := by rw [Submonoid.smul_def, norm_smul, norm_eq_of_mem_sphere, one_mul]
Analysis\Complex\Conformal.lean
/- Copyright (c) 2021 Yourong Zang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yourong Zang -/ import Mathlib.Analysis.Complex.Isometry import Mathlib.Analysis.NormedSpace.ConformalLinearMap import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.Data.Complex.FiniteDimensional /-! # Conformal maps between complex vector spaces We prove the sufficient and necessary conditions for a real-linear map between complex vector spaces to be conformal. ## Main results * `isConformalMap_complex_linear`: a nonzero complex linear map into an arbitrary complex normed space is conformal. * `isConformalMap_complex_linear_conj`: the composition of a nonzero complex linear map with `conj` is complex linear. * `isConformalMap_iff_is_complex_or_conj_linear`: a real linear map between the complex plane is conformal iff it's complex linear or the composition of some complex linear map and `conj`. ## Warning Antiholomorphic functions such as the complex conjugate are considered as conformal functions in this file. -/ noncomputable section open Complex ContinuousLinearMap ComplexConjugate theorem isConformalMap_conj : IsConformalMap (conjLIE : ℂ →L[ℝ] ℂ) := conjLIE.toLinearIsometry.isConformalMap section ConformalIntoComplexNormed variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace ℂ E] {z : ℂ} {g : ℂ →L[ℝ] E} {f : ℂ → E} theorem isConformalMap_complex_linear {map : ℂ →L[ℂ] E} (nonzero : map ≠ 0) : IsConformalMap (map.restrictScalars ℝ) := by have minor₁ : ‖map 1‖ ≠ 0 := by simpa only [ContinuousLinearMap.ext_ring_iff, Ne, norm_eq_zero] using nonzero refine ⟨‖map 1‖, minor₁, ⟨‖map 1‖⁻¹ • ((map : ℂ →ₗ[ℂ] E) : ℂ →ₗ[ℝ] E), ?_⟩, ?_⟩ · intro x simp only [LinearMap.smul_apply] have : x = x • (1 : ℂ) := by rw [smul_eq_mul, mul_one] nth_rw 1 [this] rw [LinearMap.coe_restrictScalars] simp only [map.coe_coe, map.map_smul, norm_smul, norm_inv, norm_norm] field_simp only [one_mul] · ext1 -- porting note (#10745): was `simp`; explicitly supplied simp lemma simp [smul_inv_smul₀ minor₁] theorem isConformalMap_complex_linear_conj {map : ℂ →L[ℂ] E} (nonzero : map ≠ 0) : IsConformalMap ((map.restrictScalars ℝ).comp (conjCLE : ℂ →L[ℝ] ℂ)) := (isConformalMap_complex_linear nonzero).comp isConformalMap_conj end ConformalIntoComplexNormed section ConformalIntoComplexPlane open ContinuousLinearMap variable {f : ℂ → ℂ} {z : ℂ} {g : ℂ →L[ℝ] ℂ} theorem IsConformalMap.is_complex_or_conj_linear (h : IsConformalMap g) : (∃ map : ℂ →L[ℂ] ℂ, map.restrictScalars ℝ = g) ∨ ∃ map : ℂ →L[ℂ] ℂ, map.restrictScalars ℝ = g ∘L ↑conjCLE := by rcases h with ⟨c, -, li, rfl⟩ obtain ⟨li, rfl⟩ : ∃ li' : ℂ ≃ₗᵢ[ℝ] ℂ, li'.toLinearIsometry = li := ⟨li.toLinearIsometryEquiv rfl, by ext1; rfl⟩ rcases linear_isometry_complex li with ⟨a, rfl | rfl⟩ -- let rot := c • (a : ℂ) • ContinuousLinearMap.id ℂ ℂ, · refine Or.inl ⟨c • (a : ℂ) • ContinuousLinearMap.id ℂ ℂ, ?_⟩ ext1 simp · refine Or.inr ⟨c • (a : ℂ) • ContinuousLinearMap.id ℂ ℂ, ?_⟩ ext1 simp /-- A real continuous linear map on the complex plane is conformal if and only if the map or its conjugate is complex linear, and the map is nonvanishing. -/ theorem isConformalMap_iff_is_complex_or_conj_linear : IsConformalMap g ↔ ((∃ map : ℂ →L[ℂ] ℂ, map.restrictScalars ℝ = g) ∨ ∃ map : ℂ →L[ℂ] ℂ, map.restrictScalars ℝ = g ∘L ↑conjCLE) ∧ g ≠ 0 := by constructor · exact fun h => ⟨h.is_complex_or_conj_linear, h.ne_zero⟩ · rintro ⟨⟨map, rfl⟩ | ⟨map, hmap⟩, h₂⟩ · refine isConformalMap_complex_linear ?_ contrapose! h₂ with w simp only [w, restrictScalars_zero] · have minor₁ : g = map.restrictScalars ℝ ∘L ↑conjCLE := by ext1 simp only [hmap, coe_comp', ContinuousLinearEquiv.coe_coe, Function.comp_apply, conjCLE_apply, starRingEnd_self_apply] rw [minor₁] at h₂ ⊢ refine isConformalMap_complex_linear_conj ?_ contrapose! h₂ with w simp only [w, restrictScalars_zero, zero_comp] end ConformalIntoComplexPlane
Analysis\Complex\Convex.lean
/- Copyright (c) 2023 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Complex.Basic /-! # Theorems about convexity on the complex plane -/ open Set open scoped ComplexOrder namespace Complex /-- A version of `convexHull_prod` for `Set.reProdIm`. -/ lemma convexHull_reProdIm (s t : Set ℝ) : convexHull ℝ (s ×ℂ t) = convexHull ℝ s ×ℂ convexHull ℝ t := calc convexHull ℝ (equivRealProdLm ⁻¹' (s ×ˢ t)) = equivRealProdLm ⁻¹' convexHull ℝ (s ×ˢ t) := by simpa only [← LinearEquiv.image_symm_eq_preimage] using ((equivRealProdLm.symm.toLinearMap).image_convexHull (s ×ˢ t)).symm _ = convexHull ℝ s ×ℂ convexHull ℝ t := by rw [convexHull_prod]; rfl /-- The slit plane is star-convex at a positive number. -/ lemma starConvex_slitPlane {z : ℂ} (hz : 0 < z) : StarConvex ℝ z slitPlane := Complex.compl_Iic_zero ▸ starConvex_compl_Iic hz /-- The slit plane is star-shaped at a positive real number. -/ lemma starConvex_ofReal_slitPlane {x : ℝ} (hx : 0 < x) : StarConvex ℝ ↑x slitPlane := starConvex_slitPlane <| zero_lt_real.2 hx /-- The slit plane is star-shaped at `1`. -/ lemma starConvex_one_slitPlane : StarConvex ℝ 1 slitPlane := starConvex_slitPlane one_pos end Complex
Analysis\Complex\Hadamard.lean
/- Copyright (c) 2023 Xavier Généreux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Généreux -/ import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.Complex.PhragmenLindelof /-! # Hadamard three-lines Theorem In this file we present a proof of a special case of Hadamard's three-lines Theorem. ## Main result - `norm_le_interp_of_mem_verticalClosedStrip` : Hadamard three-line theorem on `re ⁻¹' [0,1]`: If `f` is a bounded function, continuous on `re ⁻¹' [0,1]` and differentiable on `re ⁻¹' (0,1)`, then for `M(x) := sup ((norm ∘ f) '' (re ⁻¹' {x}))`, that is `M(x)` is the supremum of the absolute value of `f` along the vertical lines `re z = x`, we have that `∀ z ∈ re ⁻¹' [0,1]` the inequality `‖f(z)‖ ≤ M(0) ^ (1 - z.re) * M(1) ^ z.re` holds. This can be seen to be equivalent to the statement that `log M(re z)` is a convex function on `[0,1]`. - `norm_le_interp_of_mem_verticalClosedStrip'` : Variant of the above lemma in simpler terms. In particular, it makes no mention of the helper functions defined in this file. ## Main definitions - `Complex.HadamardThreeLines.verticalStrip` : The vertical strip defined by : `re ⁻¹' Ioo a b` - `Complex.HadamardThreeLines.verticalClosedStrip` : The vertical strip defined by : `re ⁻¹' Icc a b` - `Complex.HadamardThreeLines.sSupNormIm` : The supremum function on vertical lines defined by : `sSup {|f(z)| : z.re = x}` - `Complex.HadamardThreeLines.interpStrip` : The interpolation between the `sSupNormIm` on the edges of the vertical strip. - `Complex.HadamardThreeLines.invInterpStrip` : Inverse of the interpolation between the `sSupNormIm` on the edges of the vertical strip. - `Complex.HadamardThreeLines.F` : Function defined by `f` times `invInterpStrip`. Convenient form for proofs. ## Note The proof follows from Phragmén-Lindelöf when both frontiers are not everywhere zero. We then use a limit argument to cover the case when either of the sides are `0`. -/ open Set Filter Function Complex Topology namespace Complex namespace HadamardThreeLines /-- The vertical strip in the complex plane containing all `z ∈ ℂ` such that `z.re ∈ Ioo a b`. -/ def verticalStrip (a : ℝ) (b : ℝ) : Set ℂ := re ⁻¹' Ioo a b /-- The vertical strip in the complex plane containing all `z ∈ ℂ` such that `z.re ∈ Icc a b`. -/ def verticalClosedStrip (a : ℝ) (b : ℝ) : Set ℂ := re ⁻¹' Icc a b /-- The supremum of the norm of `f` on imaginary lines. (Fixed real part) This is also known as the function `M` -/ noncomputable def sSupNormIm {E : Type*} [NormedAddCommGroup E] (f : ℂ → E) (x : ℝ) : ℝ := sSup ((norm ∘ f) '' (re ⁻¹' {x})) section invInterpStrip variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] (f : ℂ → E) (z : ℂ) /-- The inverse of the interpolation of `sSupNormIm` on the two boundaries. In other words, this is the inverse of the right side of the target inequality: `|f(z)| ≤ |M(0) ^ (1-z)| * |M(1) ^ z|`. Shifting this by a positive epsilon allows us to prove the case when either of the boundaries is zero.-/ noncomputable def invInterpStrip (ε : ℝ) : ℂ := (ε + sSupNormIm f 0) ^ (z - 1) * (ε + sSupNormIm f 1) ^ (-z) /-- A function useful for the proofs steps. We will aim to show that it is bounded by 1. -/ noncomputable def F (ε : ℝ) := fun z ↦ invInterpStrip f z ε • f z /-- `sSup` of `norm` is nonneg applied to the image of `f` on the vertical line `re z = x` -/ lemma sSupNormIm_nonneg (x : ℝ) : 0 ≤ sSupNormIm f x := by apply Real.sSup_nonneg rintro y ⟨z1, _, hz2⟩ simp only [← hz2, comp, norm_nonneg] /-- `sSup` of `norm` translated by `ε > 0` is positive applied to the image of `f` on the vertical line `re z = x` -/ lemma sSupNormIm_eps_pos {ε : ℝ} (hε : ε > 0) (x : ℝ) : 0 < ε + sSupNormIm f x := by linarith [sSupNormIm_nonneg f x] /-- Useful rewrite for the absolute value of `invInterpStrip`-/ lemma abs_invInterpStrip {ε : ℝ} (hε : ε > 0) : abs (invInterpStrip f z ε) = (ε + sSupNormIm f 0) ^ (z.re - 1) * (ε + sSupNormIm f 1) ^ (-z.re) := by simp only [invInterpStrip, map_mul] repeat rw [← ofReal_add] repeat rw [abs_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε _) _] simp only [sub_re, one_re, neg_re] /-- The function `invInterpStrip` is `diffContOnCl`. -/ lemma diffContOnCl_invInterpStrip {ε : ℝ} (hε : ε > 0) : DiffContOnCl ℂ (fun z ↦ invInterpStrip f z ε) (verticalStrip 0 1) := by apply Differentiable.diffContOnCl apply Differentiable.mul · apply Differentiable.const_cpow (Differentiable.sub_const (differentiable_id') 1) _ left rw [← ofReal_add, ofReal_ne_zero] simp only [ne_eq, ne_of_gt (sSupNormIm_eps_pos f hε 0), not_false_eq_true] · apply Differentiable.const_cpow (Differentiable.neg differentiable_id') apply Or.inl rw [← ofReal_add, ofReal_ne_zero] exact (ne_of_gt (sSupNormIm_eps_pos f hε 1)) /-- If `f` is bounded on the unit vertical strip, then `f` is bounded by `sSupNormIm` there. -/ lemma norm_le_sSupNormIm (f : ℂ → E) (z : ℂ) (hD : z ∈ verticalClosedStrip 0 1) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) : ‖f z‖ ≤ sSupNormIm f (z.re) := by refine le_csSup ?_ ?_ · apply BddAbove.mono (image_subset (norm ∘ f) _) hB exact preimage_mono (singleton_subset_iff.mpr hD) · apply mem_image_of_mem (norm ∘ f) simp only [mem_preimage, mem_singleton] /-- Alternative version of `norm_le_sSupNormIm` with a strict inequality and a positive `ε`. -/ lemma norm_lt_sSupNormIm_eps (f : ℂ → E) (ε : ℝ) (hε : ε > 0) (z : ℂ) (hD : z ∈ verticalClosedStrip 0 1) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) : ‖f z‖ < ε + sSupNormIm f (z.re) := lt_add_of_pos_of_le hε (norm_le_sSupNormIm f z hD hB) /-- When the function `f` is bounded above on a vertical strip, then so is `F`. -/ lemma F_BddAbove (f : ℂ → E) (ε : ℝ) (hε : ε > 0) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) : BddAbove ((norm ∘ (F f ε)) '' (verticalClosedStrip 0 1)) := by -- Rewriting goal simp only [F, image_congr, comp_apply, map_mul, invInterpStrip] rw [bddAbove_def] at * rcases hB with ⟨B, hB⟩ -- Using bound use ((max 1 ((ε + sSupNormIm f 0) ^ (-(1 : ℝ)))) * max 1 ((ε + sSupNormIm f 1) ^ (-(1 : ℝ)))) * B simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intros z hset specialize hB (‖f z‖) (by simpa [image_congr, mem_image, comp_apply] using ⟨z, hset, rfl⟩) -- Proof that the bound is correct simp only [norm_smul, norm_mul, ← ofReal_add] gcongr -- Bounding individual terms · by_cases hM0_one : 1 ≤ ε + sSupNormIm f 0 -- `1 ≤ (sSupNormIm f 0)` · apply le_trans _ (le_max_left _ _) simp only [norm_eq_abs, abs_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 0), sub_re, one_re, Real.rpow_le_one_of_one_le_of_nonpos hM0_one (sub_nonpos.mpr hset.2)] -- `0 < (sSupNormIm f 0) < 1` · rw [not_le] at hM0_one; apply le_trans _ (le_max_right _ _) simp only [norm_eq_abs, abs_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 0), sub_re, one_re] apply Real.rpow_le_rpow_of_exponent_ge (sSupNormIm_eps_pos f hε 0) (le_of_lt hM0_one) _ simp only [neg_le_sub_iff_le_add, le_add_iff_nonneg_left, hset.1] · by_cases hM1_one : 1 ≤ ε + sSupNormIm f 1 -- `1 ≤ sSupNormIm f 1` · apply le_trans _ (le_max_left _ _) simp only [norm_eq_abs, abs_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 1), sub_re, one_re, neg_re, Real.rpow_le_one_of_one_le_of_nonpos hM1_one (Right.neg_nonpos_iff.mpr hset.1)] -- `0 < sSupNormIm f 1 < 1` · rw [not_le] at hM1_one; apply le_trans _ (le_max_right _ _) simp only [norm_eq_abs, abs_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε 1), sub_re, one_re, neg_re, Real.rpow_le_rpow_of_exponent_ge (sSupNormIm_eps_pos f hε 1) (le_of_lt hM1_one) (neg_le_neg_iff.mpr hset.2)] /-- Proof that `F` is bounded by one one the edges. -/ lemma F_edge_le_one (f : ℂ → E) (ε : ℝ) (hε : ε > 0) (z : ℂ) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) (hz : z ∈ re ⁻¹' {0, 1}) : ‖F f ε z‖ ≤ 1 := by simp only [F, norm_smul, norm_eq_abs, map_mul, abs_cpow_eq_rpow_re_of_pos, abs_invInterpStrip f z hε, sSupNormIm_eps_pos f hε 1, sub_re, one_re, neg_re] rcases hz with hz0 | hz1 -- `z.re = 0` · simp only [hz0, zero_sub, Real.rpow_neg_one, neg_zero, Real.rpow_zero, mul_one, inv_mul_le_iff (sSupNormIm_eps_pos f hε 0)] rw [← hz0] apply le_of_lt (norm_lt_sSupNormIm_eps f ε hε _ _ hB) simp only [verticalClosedStrip, mem_preimage, zero_le_one, left_mem_Icc, hz0] -- `z.re = 1` · rw [mem_singleton_iff] at hz1 simp only [hz1, one_mul, Real.rpow_zero, sub_self, Real.rpow_neg_one, inv_mul_le_iff (sSupNormIm_eps_pos f hε 1), mul_one] rw [← hz1] apply le_of_lt (norm_lt_sSupNormIm_eps f ε hε _ _ hB) simp only [verticalClosedStrip, mem_preimage, zero_le_one, hz1, right_mem_Icc] theorem norm_mul_invInterpStrip_le_one_of_mem_verticalClosedStrip (f : ℂ → E) (ε : ℝ) (hε : 0 < ε) (z : ℂ) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) (hz : z ∈ verticalClosedStrip 0 1) : ‖F f ε z‖ ≤ 1 := by apply PhragmenLindelof.vertical_strip (DiffContOnCl.smul (diffContOnCl_invInterpStrip f hε) hd) _ (fun x hx ↦ F_edge_le_one f ε hε x hB (Or.inl hx)) (fun x hx ↦ F_edge_le_one f ε hε x hB (Or.inr hx)) hz.1 hz.2 use 0 rw [sub_zero, div_one] refine ⟨ Real.pi_pos, ?_⟩ obtain ⟨BF, hBF⟩ := F_BddAbove f ε hε hB simp only [comp_apply, mem_upperBounds, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] at hBF use BF rw [Asymptotics.isBigO_iff] use 1 rw [eventually_inf_principal] apply eventually_of_forall intro x hx norm_num exact (hBF x ((preimage_mono Ioo_subset_Icc_self) hx)).trans ((le_of_lt (lt_add_one BF)).trans (Real.add_one_le_exp BF)) end invInterpStrip ----- variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] (f : ℂ → E) /-- The interpolation of `sSupNormIm` on the two boundaries. In other words, this is the right side of the target inequality: `|f(z)| ≤ |M(0) ^ (1-z)| * |M(1) ^ z|`. Note that if `(sSupNormIm f 0) = 0 ∨ (sSupNormIm f 1) = 0` then the power is not continuous since `0 ^ 0 = 1`. Hence the use of `ite`. -/ noncomputable def interpStrip (z : ℂ) : ℂ := if (sSupNormIm f 0) = 0 ∨ (sSupNormIm f 1) = 0 then 0 else (sSupNormIm f 0) ^ (1-z) * (sSupNormIm f 1) ^ z /-- Rewrite for `InterpStrip` when `0 < sSupNormIm f 0` and `0 < sSupNormIm f 1`. -/ lemma interpStrip_eq_of_pos (z : ℂ) (h0 : 0 < sSupNormIm f 0) (h1 : 0 < sSupNormIm f 1) : interpStrip f z = (sSupNormIm f 0) ^ (1 - z) * (sSupNormIm f 1) ^ z := by simp only [ne_of_gt h0, ne_of_gt h1, interpStrip, if_false, or_false] /-- Rewrite for `InterpStrip` when `0 = sSupNormIm f 0` or `0 = sSupNormIm f 1`. -/ lemma interpStrip_eq_of_zero (z : ℂ) (h : sSupNormIm f 0 = 0 ∨ sSupNormIm f 1 = 0) : interpStrip f z = 0 := if_pos h /-- Rewrite for `InterpStrip` on the open vertical strip. -/ lemma interpStrip_eq_of_mem_verticalStrip (z : ℂ) (hz : z ∈ verticalStrip 0 1) : interpStrip f z = (sSupNormIm f 0) ^ (1 - z) * (sSupNormIm f 1) ^ z := by by_cases h : sSupNormIm f 0 = 0 ∨ sSupNormIm f 1 = 0 · rw [interpStrip_eq_of_zero _ z h] rcases h with h0 | h1 · simp only [h0, ofReal_zero, zero_eq_mul, cpow_eq_zero_iff, ne_eq, true_and, ofReal_eq_zero] left rw [sub_eq_zero, eq_comm] simp only [ne_eq, Complex.ext_iff, one_re, ne_of_lt hz.2, or_iff_left, false_and, not_false_eq_true] · simp only [h1, ofReal_zero, zero_eq_mul, cpow_eq_zero_iff, ofReal_eq_zero, ne_eq, true_and] right rw [eq_comm] simp only [ne_eq, Complex.ext_iff, zero_re, ne_of_lt hz.1, or_iff_left, false_and, not_false_eq_true] · push_neg at h replace h : (0 < sSupNormIm f 0) ∧ (0 < sSupNormIm f 1) := ⟨(lt_of_le_of_ne (sSupNormIm_nonneg f 0) (ne_comm.mp h.1)), (lt_of_le_of_ne (sSupNormIm_nonneg f 1) (ne_comm.mp h.2))⟩ exact interpStrip_eq_of_pos f z h.1 h.2 lemma diffContOnCl_interpStrip : DiffContOnCl ℂ (interpStrip f) (verticalStrip 0 1) := by by_cases h : sSupNormIm f 0 = 0 ∨ sSupNormIm f 1 = 0 -- Case everywhere 0 · eta_expand; simp_rw [interpStrip_eq_of_zero f _ h]; exact diffContOnCl_const -- Case nowhere 0 · push_neg at h rcases h with ⟨h0, h1⟩ rw [ne_comm] at h0 h1 apply Differentiable.diffContOnCl intro z eta_expand simp_rw [interpStrip_eq_of_pos f _ (lt_of_le_of_ne (sSupNormIm_nonneg f 0) h0) (lt_of_le_of_ne (sSupNormIm_nonneg f 1) h1)] refine DifferentiableAt.mul ?_ ?_ · apply DifferentiableAt.const_cpow (DifferentiableAt.const_sub (differentiableAt_id') 1) _ left; simp only [Ne, ofReal_eq_zero]; rwa [eq_comm] · refine DifferentiableAt.const_cpow ?_ ?_ · apply differentiableAt_id' · left; simp only [Ne, ofReal_eq_zero]; rwa [eq_comm] lemma norm_le_interpStrip_of_mem_verticalClosedStrip_eps (ε : ℝ) (hε : ε > 0) (z : ℂ) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hz : z ∈ verticalClosedStrip 0 1) : ‖f z‖ ≤ ‖((ε + sSupNormIm f 0) ^ (1-z) * (ε + sSupNormIm f 1) ^ z : ℂ)‖ := by simp only [F, abs_invInterpStrip _ _ hε, norm_smul, norm_mul, norm_eq_abs, ← ofReal_add, abs_cpow_eq_rpow_re_of_pos (sSupNormIm_eps_pos f hε _) _, sub_re, one_re] rw [← mul_inv_le_iff, ← one_mul (((ε + sSupNormIm f 1) ^ z.re)), ← mul_inv_le_iff', ← Real.rpow_neg_one, ← Real.rpow_neg_one] · simp only [← Real.rpow_mul (le_of_lt (sSupNormIm_eps_pos f hε _)), mul_neg, mul_one, neg_sub, mul_assoc] simpa [F, abs_invInterpStrip _ _ hε, norm_smul, mul_comm] using norm_mul_invInterpStrip_le_one_of_mem_verticalClosedStrip f ε hε z hd hB hz · simp only [Real.rpow_pos_of_pos (sSupNormIm_eps_pos f hε _) z.re] · simp only [Real.rpow_pos_of_pos (sSupNormIm_eps_pos f hε _) (1-z.re)] lemma eventuallyle (z : ℂ) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hz : z ∈ verticalStrip 0 1) : (fun _ : ℝ ↦ ‖f z‖) ≤ᶠ[𝓝[>] 0] (fun ε ↦ ‖((ε + sSupNormIm f 0) ^ (1 - z) * (ε + sSupNormIm f 1) ^ z : ℂ)‖) := by filter_upwards [self_mem_nhdsWithin] with ε (hε : 0 < ε) using norm_le_interpStrip_of_mem_verticalClosedStrip_eps f ε hε z hB hd (mem_of_mem_of_subset hz (preimage_mono Ioo_subset_Icc_self)) lemma norm_le_interpStrip_of_mem_verticalStrip_zero (z : ℂ) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) (hz : z ∈ verticalStrip 0 1) : ‖f z‖ ≤ ‖interpStrip f z‖ := by apply tendsto_le_of_eventuallyLE _ _ (eventuallyle f z hB hd hz) · apply tendsto_inf_left simp only [tendsto_const_nhds_iff] -- Proof that we can let epsilon tend to zero. · rw [interpStrip_eq_of_mem_verticalStrip _ _ hz] convert ContinuousWithinAt.tendsto _ using 2 · simp only [ofReal_zero, zero_add] · simp_rw [← ofReal_add, norm_eq_abs] have : ∀ x ∈ Ioi 0, (x + sSupNormIm f 0) ^ (1 - z.re) * (x + (sSupNormIm f 1)) ^ z.re = abs (↑(x + sSupNormIm f 0) ^ (1 - z) * ↑(x + sSupNormIm f 1) ^ z) := by intro x hx simp only [map_mul] repeat rw [abs_cpow_eq_rpow_re_of_nonneg (le_of_lt (sSupNormIm_eps_pos f hx _)) _] · simp only [sub_re, one_re] · simpa using (ne_comm.mpr (ne_of_lt hz.1)) · simpa [sub_eq_zero] using (ne_comm.mpr (ne_of_lt hz.2)) apply tendsto_nhdsWithin_congr this _ simp only [zero_add] rw [map_mul, abs_cpow_eq_rpow_re_of_nonneg (sSupNormIm_nonneg _ _) _, abs_cpow_eq_rpow_re_of_nonneg (sSupNormIm_nonneg _ _) _] · apply Tendsto.mul · apply Tendsto.rpow_const · nth_rw 2 [← zero_add (sSupNormIm f 0)] exact Tendsto.add_const (sSupNormIm f 0) (tendsto_nhdsWithin_of_tendsto_nhds (Continuous.tendsto continuous_id' _)) · right; simp only [sub_nonneg, le_of_lt hz.2] · apply Tendsto.rpow_const · nth_rw 2 [← zero_add (sSupNormIm f 1)] exact Tendsto.add_const (sSupNormIm f 1) (tendsto_nhdsWithin_of_tendsto_nhds (Continuous.tendsto continuous_id' _)) · right; simp only [sub_nonneg, le_of_lt hz.1] · simpa using (ne_comm.mpr (ne_of_lt hz.1)) · simpa [sub_eq_zero] using (ne_comm.mpr (ne_of_lt hz.2)) /-- **Hadamard three-line theorem** on `re ⁻¹' [0,1]`: If `f` is a bounded function, continuous on the closed strip `re ⁻¹' [0,1]` and differentiable on open strip `re ⁻¹' (0,1)`, then for `M(x) := sup ((norm ∘ f) '' (re ⁻¹' {x}))` we have that for all `z` in the closed strip `re ⁻¹' [0,1]` the inequality `‖f(z)‖ ≤ M(0) ^ (1 - z.re) * M(1) ^ z.re` holds. -/ lemma norm_le_interpStrip_of_mem_verticalClosedStrip (f : ℂ → E) {z : ℂ} (hz : z ∈ verticalClosedStrip 0 1) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) : ‖f z‖ ≤ ‖interpStrip f z‖ := by apply le_on_closure (fun w hw ↦ norm_le_interpStrip_of_mem_verticalStrip_zero f w hd hB hw) (Continuous.comp_continuousOn' continuous_norm hd.2) (Continuous.comp_continuousOn' continuous_norm (diffContOnCl_interpStrip f).2) rwa [verticalClosedStrip, ← closure_Ioo zero_ne_one, ← closure_preimage_re] at hz /-- **Hadamard three-line theorem** on `re ⁻¹' [0,1]` (Variant in simpler terms): Let `f` be a bounded function, continuous on the closed strip `re ⁻¹' [0,1]` and differentiable on open strip `re ⁻¹' (0,1)`. If, for all `z.re = 0`, `‖f z‖ ≤ a` for some `a ∈ ℝ` and, similarly, for all `z.re = 1`, `‖f z‖ ≤ b` for some `b ∈ ℝ` then for all `z` in the closed strip `re ⁻¹' [0,1]` the inequality `‖f(z)‖ ≤ a ^ (1 - z.re) * b ^ z.re` holds. -/ lemma norm_le_interp_of_mem_verticalClosedStrip' (f : ℂ → E) {z : ℂ} {a b : ℝ} (hz : z ∈ verticalClosedStrip 0 1) (hd : DiffContOnCl ℂ f (verticalStrip 0 1)) (hB : BddAbove ((norm ∘ f) '' (verticalClosedStrip 0 1))) (ha : ∀ z ∈ re ⁻¹' {0}, ‖f z‖ ≤ a) (hb : ∀ z ∈ re ⁻¹' {1}, ‖f z‖ ≤ b) : ‖f z‖ ≤ a ^ (1 - z.re) * b ^ z.re := by have : ‖interpStrip f z‖ ≤ (sSupNormIm f 0) ^ (1 - z.re) * (sSupNormIm f 1) ^ z.re := by by_cases h : sSupNormIm f 0 = 0 ∨ sSupNormIm f 1 = 0 · rw [interpStrip_eq_of_zero f z h, norm_zero, mul_nonneg_iff] left exact ⟨Real.rpow_nonneg (sSupNormIm_nonneg f _) _, Real.rpow_nonneg (sSupNormIm_nonneg f _) _ ⟩ · push_neg at h rcases h with ⟨h0, h1⟩ rw [ne_comm] at h0 h1 simp_rw [interpStrip_eq_of_pos f _ (lt_of_le_of_ne (sSupNormIm_nonneg f 0) h0) (lt_of_le_of_ne (sSupNormIm_nonneg f 1) h1)] simp only [norm_eq_abs, map_mul] rw [abs_cpow_eq_rpow_re_of_pos ((Ne.le_iff_lt h0).mp (sSupNormIm_nonneg f _)) _] rw [abs_cpow_eq_rpow_re_of_pos ((Ne.le_iff_lt h1).mp (sSupNormIm_nonneg f _)) _] simp only [sub_re, one_re, le_refl] apply (norm_le_interpStrip_of_mem_verticalClosedStrip f hz hd hB).trans (this.trans _) apply mul_le_mul_of_nonneg _ _ (Real.rpow_nonneg (sSupNormIm_nonneg f _) _) · apply (Real.rpow_nonneg _ _) specialize hb 1 simp only [mem_preimage, one_re, mem_singleton_iff, forall_true_left] at hb exact (norm_nonneg _).trans hb · apply Real.rpow_le_rpow (sSupNormIm_nonneg f _) _ (sub_nonneg.mpr hz.2) · rw [sSupNormIm] apply csSup_le _ · simpa [comp_apply, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] using ha · use ‖(f 0)‖, 0 simp only [mem_preimage, zero_re, mem_singleton_iff, comp_apply, and_self] · apply Real.rpow_le_rpow (sSupNormIm_nonneg f _) _ hz.1 · rw [sSupNormIm] apply csSup_le _ · simpa [comp_apply, mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] using hb · use ‖(f 1)‖, 1 simp only [mem_preimage, one_re, mem_singleton_iff, comp_apply, and_self] end HadamardThreeLines end Complex
Analysis\Complex\HalfPlane.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Topology.Instances.EReal /-! # Half-planes in ℂ are open We state that open left, right, upper and lower half-planes in the complex numbers are open sets, where the bounding value of the real or imaginary part is given by an `EReal` `x`. So this includes the full plane and the empty set for `x = ⊤`/`x = ⊥`. -/ namespace Complex /-- An open left half-plane (with boundary real part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_re_lt_EReal (x : EReal) : IsOpen {z : ℂ | z.re < x} := isOpen_lt (EReal.continuous_coe_iff.mpr continuous_re) continuous_const /-- An open right half-plane (with boundary real part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_re_gt_EReal (x : EReal) : IsOpen {z : ℂ | x < z.re} := isOpen_lt continuous_const <| EReal.continuous_coe_iff.mpr continuous_re /-- An open lower half-plane (with boundary imaginary part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_im_lt_EReal (x : EReal) : IsOpen {z : ℂ | z.im < x} := isOpen_lt (EReal.continuous_coe_iff.mpr continuous_im) continuous_const /-- An open upper half-plane (with boundary imaginary part given by an `EReal`) is an open set in the complex plane. -/ lemma isOpen_im_gt_EReal (x : EReal) : IsOpen {z : ℂ | x < z.im} := isOpen_lt continuous_const <| EReal.continuous_coe_iff.mpr continuous_im end Complex
Analysis\Complex\Isometry.lean
/- Copyright (c) 2021 François Sunatori. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: François Sunatori -/ import Mathlib.Analysis.Complex.Circle import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Basic /-! # Isometries of the Complex Plane The lemma `linear_isometry_complex` states the classification of isometries in the complex plane. Specifically, isometries with rotations but without translation. The proof involves: 1. creating a linear isometry `g` with two fixed points, `g(0) = 0`, `g(1) = 1` 2. applying `linear_isometry_complex_aux` to `g` The proof of `linear_isometry_complex_aux` is separated in the following parts: 1. show that the real parts match up: `LinearIsometry.re_apply_eq_re` 2. show that I maps to either I or -I 3. every z is a linear combination of a + b * I ## References * [Isometries of the Complex Plane](http://helmut.knaust.info/mediawiki/images/b/b5/Iso.pdf) -/ noncomputable section open Complex open ComplexConjugate local notation "|" x "|" => Complex.abs x /-- An element of the unit circle defines a `LinearIsometryEquiv` from `ℂ` to itself, by rotation. -/ def rotation : circle →* ℂ ≃ₗᵢ[ℝ] ℂ where toFun a := { DistribMulAction.toLinearEquiv ℝ ℂ a with norm_map' := fun x => show |a * x| = |x| by rw [map_mul, abs_coe_circle, one_mul] } map_one' := LinearIsometryEquiv.ext <| one_smul circle map_mul' a b := LinearIsometryEquiv.ext <| mul_smul a b @[simp] theorem rotation_apply (a : circle) (z : ℂ) : rotation a z = a * z := rfl @[simp] theorem rotation_symm (a : circle) : (rotation a).symm = rotation a⁻¹ := LinearIsometryEquiv.ext fun _ => rfl @[simp] theorem rotation_trans (a b : circle) : (rotation a).trans (rotation b) = rotation (b * a) := by ext1 simp theorem rotation_ne_conjLIE (a : circle) : rotation a ≠ conjLIE := by intro h have h1 : rotation a 1 = conj 1 := LinearIsometryEquiv.congr_fun h 1 have hI : rotation a I = conj I := LinearIsometryEquiv.congr_fun h I rw [rotation_apply, RingHom.map_one, mul_one] at h1 rw [rotation_apply, conj_I, ← neg_one_mul, mul_left_inj' I_ne_zero, h1, eq_neg_self_iff] at hI exact one_ne_zero hI /-- Takes an element of `ℂ ≃ₗᵢ[ℝ] ℂ` and checks if it is a rotation, returns an element of the unit circle. -/ @[simps] def rotationOf (e : ℂ ≃ₗᵢ[ℝ] ℂ) : circle := ⟨e 1 / Complex.abs (e 1), by simp⟩ @[simp] theorem rotationOf_rotation (a : circle) : rotationOf (rotation a) = a := Subtype.ext <| by simp theorem rotation_injective : Function.Injective rotation := Function.LeftInverse.injective rotationOf_rotation theorem LinearIsometry.re_apply_eq_re_of_add_conj_eq (f : ℂ →ₗᵢ[ℝ] ℂ) (h₃ : ∀ z, z + conj z = f z + conj (f z)) (z : ℂ) : (f z).re = z.re := by simpa [Complex.ext_iff, add_re, add_im, conj_re, conj_im, ← two_mul, show (2 : ℝ) ≠ 0 by simp [two_ne_zero]] using (h₃ z).symm theorem LinearIsometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h₂ : ∀ z, (f z).re = z.re) (z : ℂ) : (f z).im = z.im ∨ (f z).im = -z.im := by have h₁ := f.norm_map z simp only [Complex.abs_def, norm_eq_abs] at h₁ rwa [Real.sqrt_inj (normSq_nonneg _) (normSq_nonneg _), normSq_apply (f z), normSq_apply z, h₂, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h₁ theorem LinearIsometry.im_apply_eq_im {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : z + conj z = f z + conj (f z) := by have : ‖f z - 1‖ = ‖z - 1‖ := by rw [← f.norm_map (z - 1), f.map_sub, h] apply_fun fun x => x ^ 2 at this simp only [norm_eq_abs, ← normSq_eq_abs] at this rw [← ofReal_inj, ← mul_conj, ← mul_conj] at this rw [RingHom.map_sub, RingHom.map_sub] at this simp only [sub_mul, mul_sub, one_mul, mul_one] at this rw [mul_conj, normSq_eq_abs, ← norm_eq_abs, LinearIsometry.norm_map] at this rw [mul_conj, normSq_eq_abs, ← norm_eq_abs] at this simp only [sub_sub, sub_right_inj, mul_one, ofReal_pow, RingHom.map_one, norm_eq_abs] at this simp only [add_sub, sub_left_inj] at this rw [add_comm, ← this, add_comm] theorem LinearIsometry.re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : (f z).re = z.re := by apply LinearIsometry.re_apply_eq_re_of_add_conj_eq intro z apply LinearIsometry.im_apply_eq_im h theorem linear_isometry_complex_aux {f : ℂ ≃ₗᵢ[ℝ] ℂ} (h : f 1 = 1) : f = LinearIsometryEquiv.refl ℝ ℂ ∨ f = conjLIE := by have h0 : f I = I ∨ f I = -I := by simp only [Complex.ext_iff, ← and_or_left, neg_re, I_re, neg_im, neg_zero] constructor · rw [← I_re] exact @LinearIsometry.re_apply_eq_re f.toLinearIsometry h I · apply @LinearIsometry.im_apply_eq_im_or_neg_of_re_apply_eq_re f.toLinearIsometry intro z rw [@LinearIsometry.re_apply_eq_re f.toLinearIsometry h] refine h0.imp (fun h' : f I = I => ?_) fun h' : f I = -I => ?_ <;> · apply LinearIsometryEquiv.toLinearEquiv_injective apply Complex.basisOneI.ext' intro i fin_cases i <;> simp [h, h'] theorem linear_isometry_complex (f : ℂ ≃ₗᵢ[ℝ] ℂ) : ∃ a : circle, f = rotation a ∨ f = conjLIE.trans (rotation a) := by let a : circle := ⟨f 1, by rw [mem_circle_iff_abs, ← Complex.norm_eq_abs, f.norm_map, norm_one]⟩ use a have : (f.trans (rotation a).symm) 1 = 1 := by simpa using rotation_apply a⁻¹ (f 1) refine (linear_isometry_complex_aux this).imp (fun h₁ => ?_) fun h₂ => ?_ · simpa using eq_mul_of_inv_mul_eq h₁ · exact eq_mul_of_inv_mul_eq h₂ /-- The matrix representation of `rotation a` is equal to the conformal matrix `!![re a, -im a; im a, re a]`. -/ theorem toMatrix_rotation (a : circle) : LinearMap.toMatrix basisOneI basisOneI (rotation a).toLinearEquiv = Matrix.planeConformalMatrix (re a) (im a) (by simp [pow_two, ← normSq_apply]) := by ext i j simp only [LinearMap.toMatrix_apply, coe_basisOneI, LinearEquiv.coe_coe, LinearIsometryEquiv.coe_toLinearEquiv, rotation_apply, coe_basisOneI_repr, mul_re, mul_im, Matrix.val_planeConformalMatrix, Matrix.of_apply, Matrix.cons_val', Matrix.empty_val', Matrix.cons_val_fin_one] fin_cases i <;> fin_cases j <;> simp /-- The determinant of `rotation` (as a linear map) is equal to `1`. -/ @[simp] theorem det_rotation (a : circle) : LinearMap.det ((rotation a).toLinearEquiv : ℂ →ₗ[ℝ] ℂ) = 1 := by rw [← LinearMap.det_toMatrix basisOneI, toMatrix_rotation, Matrix.det_fin_two] simp [← normSq_apply] /-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/ @[simp] theorem linearEquiv_det_rotation (a : circle) : LinearEquiv.det (rotation a).toLinearEquiv = 1 := by rw [← Units.eq_iff, LinearEquiv.coe_det, det_rotation, Units.val_one]
Analysis\Complex\Liouville.lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Normed.Module.Completion /-! # Liouville's theorem In this file we prove Liouville's theorem: if `f : E → F` is complex differentiable on the whole space and its range is bounded, then the function is a constant. Various versions of this theorem are formalized in `Differentiable.apply_eq_apply_of_bounded`, `Differentiable.exists_const_forall_eq_of_bounded`, and `Differentiable.exists_eq_const_of_bounded`. The proof is based on the Cauchy integral formula for the derivative of an analytic function, see `Complex.deriv_eq_smul_circleIntegral`. -/ open TopologicalSpace Metric Set Filter Asymptotics Function MeasureTheory Bornology open scoped Topology Filter NNReal Real universe u v variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] {F : Type v} [NormedAddCommGroup F] [NormedSpace ℂ F] local postfix:100 "̂" => UniformSpace.Completion namespace Complex /-- If `f` is complex differentiable on an open disc with center `c` and radius `R > 0` and is continuous on its closure, then `f' c` can be represented as an integral over the corresponding circle. TODO: add a version for `w ∈ Metric.ball c R`. TODO: add a version for higher derivatives. -/ theorem deriv_eq_smul_circleIntegral [CompleteSpace F] {R : ℝ} {c : ℂ} {f : ℂ → F} (hR : 0 < R) (hf : DiffContOnCl ℂ f (ball c R)) : deriv f c = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z := by lift R to ℝ≥0 using hR.le refine (hf.hasFPowerSeriesOnBall hR).hasFPowerSeriesAt.deriv.trans ?_ simp only [cauchyPowerSeries_apply, one_div, zpow_neg, pow_one, smul_smul, zpow_two, mul_inv] theorem norm_deriv_le_aux [CompleteSpace F] {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R) (hf : DiffContOnCl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) : ‖deriv f c‖ ≤ C / R := by have : ∀ z ∈ sphere c R, ‖(z - c) ^ (-2 : ℤ) • f z‖ ≤ C / (R * R) := fun z (hz : abs (z - c) = R) => by simpa [-mul_inv_rev, norm_smul, hz, zpow_two, ← div_eq_inv_mul] using (div_le_div_right (mul_pos hR hR)).2 (hC z hz) calc ‖deriv f c‖ = ‖(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z‖ := congr_arg norm (deriv_eq_smul_circleIntegral hR hf) _ ≤ R * (C / (R * R)) := (circleIntegral.norm_two_pi_i_inv_smul_integral_le_of_norm_le_const hR.le this) _ = C / R := by rw [mul_div_left_comm, div_self_mul_self', div_eq_mul_inv] /-- If `f` is complex differentiable on an open disc of radius `R > 0`, is continuous on its closure, and its values on the boundary circle of this disc are bounded from above by `C`, then the norm of its derivative at the center is at most `C / R`. -/ theorem norm_deriv_le_of_forall_mem_sphere_norm_le {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R) (hd : DiffContOnCl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) : ‖deriv f c‖ ≤ C / R := by set e : F →L[ℂ] F̂ := UniformSpace.Completion.toComplL have : HasDerivAt (e ∘ f) (e (deriv f c)) c := e.hasFDerivAt.comp_hasDerivAt c (hd.differentiableAt isOpen_ball <| mem_ball_self hR).hasDerivAt calc ‖deriv f c‖ = ‖deriv (e ∘ f) c‖ := by rw [this.deriv] exact (UniformSpace.Completion.norm_coe _).symm _ ≤ C / R := norm_deriv_le_aux hR (e.differentiable.comp_diffContOnCl hd) fun z hz => (UniformSpace.Completion.norm_coe _).trans_le (hC z hz) /-- An auxiliary lemma for Liouville's theorem `Differentiable.apply_eq_apply_of_bounded`. -/ theorem liouville_theorem_aux {f : ℂ → F} (hf : Differentiable ℂ f) (hb : IsBounded (range f)) (z w : ℂ) : f z = f w := by suffices ∀ c, deriv f c = 0 from is_const_of_deriv_eq_zero hf this z w clear z w; intro c obtain ⟨C, C₀, hC⟩ : ∃ C > (0 : ℝ), ∀ z, ‖f z‖ ≤ C := by rcases isBounded_iff_forall_norm_le.1 hb with ⟨C, hC⟩ exact ⟨max C 1, lt_max_iff.2 (Or.inr zero_lt_one), fun z => (hC (f z) (mem_range_self _)).trans (le_max_left _ _)⟩ refine norm_le_zero_iff.1 (le_of_forall_le_of_dense fun ε ε₀ => ?_) calc ‖deriv f c‖ ≤ C / (C / ε) := norm_deriv_le_of_forall_mem_sphere_norm_le (div_pos C₀ ε₀) hf.diffContOnCl fun z _ => hC z _ = ε := div_div_cancel' C₀.lt.ne' end Complex namespace Differentiable open Complex /-- **Liouville's theorem**: a complex differentiable bounded function `f : E → F` is a constant. -/ theorem apply_eq_apply_of_bounded {f : E → F} (hf : Differentiable ℂ f) (hb : IsBounded (range f)) (z w : E) : f z = f w := by set g : ℂ → F := f ∘ fun t : ℂ => t • (w - z) + z suffices g 0 = g 1 by simpa [g] apply liouville_theorem_aux exacts [hf.comp ((differentiable_id.smul_const (w - z)).add_const z), hb.subset (range_comp_subset_range _ _)] /-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/ theorem exists_const_forall_eq_of_bounded {f : E → F} (hf : Differentiable ℂ f) (hb : IsBounded (range f)) : ∃ c, ∀ z, f z = c := ⟨f 0, fun _ => hf.apply_eq_apply_of_bounded hb _ _⟩ /-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/ theorem exists_eq_const_of_bounded {f : E → F} (hf : Differentiable ℂ f) (hb : IsBounded (range f)) : ∃ c, f = const E c := (hf.exists_const_forall_eq_of_bounded hb).imp fun _ => funext /-- A corollary of Liouville's theorem where the function tends to a finite value at infinity (i.e., along `Filter.cocompact`, which in proper spaces coincides with `Bornology.cobounded`). -/ theorem eq_const_of_tendsto_cocompact [Nontrivial E] {f : E → F} (hf : Differentiable ℂ f) {c : F} (hb : Tendsto f (cocompact E) (𝓝 c)) : f = Function.const E c := by have h_bdd : Bornology.IsBounded (Set.range f) := by obtain ⟨s, hs, hs_bdd⟩ := Metric.exists_isBounded_image_of_tendsto hb obtain ⟨t, ht, hts⟩ := mem_cocompact.mp hs apply ht.image hf.continuous |>.isBounded.union hs_bdd |>.subset simpa [Set.image_union, Set.image_univ] using Set.image_subset _ <| calc Set.univ = t ∪ tᶜ := t.union_compl_self.symm _ ⊆ t ∪ s := by gcongr obtain ⟨c', hc'⟩ := hf.exists_eq_const_of_bounded h_bdd convert hc' exact tendsto_nhds_unique hb (by simpa [hc'] using tendsto_const_nhds) /-- A corollary of Liouville's theorem where the function tends to a finite value at infinity (i.e., along `Filter.cocompact`, which in proper spaces coincides with `Bornology.cobounded`). -/ theorem apply_eq_of_tendsto_cocompact [Nontrivial E] {f : E → F} (hf : Differentiable ℂ f) {c : F} (x : E) (hb : Tendsto f (cocompact E) (𝓝 c)) : f x = c := congr($(hf.eq_const_of_tendsto_cocompact hb) x) end Differentiable
Analysis\Complex\LocallyUniformLimit.lean
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Complex.RemovableSingularity import Mathlib.Analysis.Calculus.UniformLimitsDeriv import Mathlib.Analysis.NormedSpace.FunctionSeries /-! # Locally uniform limits of holomorphic functions This file gathers some results about locally uniform limits of holomorphic functions on an open subset of the complex plane. ## Main results * `TendstoLocallyUniformlyOn.differentiableOn`: A locally uniform limit of holomorphic functions is holomorphic. * `TendstoLocallyUniformlyOn.deriv`: Locally uniform convergence implies locally uniform convergence of the derivatives to the derivative of the limit. -/ open Set Metric MeasureTheory Filter Complex intervalIntegral open scoped Real Topology variable {E ι : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] {U K : Set ℂ} {z : ℂ} {M r δ : ℝ} {φ : Filter ι} {F : ι → ℂ → E} {f g : ℂ → E} namespace Complex section Cderiv /-- A circle integral which coincides with `deriv f z` whenever one can apply the Cauchy formula for the derivative. It is useful in the proof that locally uniform limits of holomorphic functions are holomorphic, because it depends continuously on `f` for the uniform topology. -/ noncomputable def cderiv (r : ℝ) (f : ℂ → E) (z : ℂ) : E := (2 * π * I : ℂ)⁻¹ • ∮ w in C(z, r), ((w - z) ^ 2)⁻¹ • f w theorem cderiv_eq_deriv (hU : IsOpen U) (hf : DifferentiableOn ℂ f U) (hr : 0 < r) (hzr : closedBall z r ⊆ U) : cderiv r f z = deriv f z := two_pi_I_inv_smul_circleIntegral_sub_sq_inv_smul_of_differentiable hU hzr hf (mem_ball_self hr) theorem norm_cderiv_le (hr : 0 < r) (hf : ∀ w ∈ sphere z r, ‖f w‖ ≤ M) : ‖cderiv r f z‖ ≤ M / r := by have hM : 0 ≤ M := by obtain ⟨w, hw⟩ : (sphere z r).Nonempty := NormedSpace.sphere_nonempty.mpr hr.le exact (norm_nonneg _).trans (hf w hw) have h1 : ∀ w ∈ sphere z r, ‖((w - z) ^ 2)⁻¹ • f w‖ ≤ M / r ^ 2 := by intro w hw simp only [mem_sphere_iff_norm, norm_eq_abs] at hw simp only [norm_smul, inv_mul_eq_div, hw, norm_eq_abs, map_inv₀, Complex.abs_pow] exact div_le_div hM (hf w hw) (sq_pos_of_pos hr) le_rfl have h2 := circleIntegral.norm_integral_le_of_norm_le_const hr.le h1 simp only [cderiv, norm_smul] refine (mul_le_mul le_rfl h2 (norm_nonneg _) (norm_nonneg _)).trans (le_of_eq ?_) field_simp [_root_.abs_of_nonneg Real.pi_pos.le] ring theorem cderiv_sub (hr : 0 < r) (hf : ContinuousOn f (sphere z r)) (hg : ContinuousOn g (sphere z r)) : cderiv r (f - g) z = cderiv r f z - cderiv r g z := by have h1 : ContinuousOn (fun w : ℂ => ((w - z) ^ 2)⁻¹) (sphere z r) := by refine ((continuous_id'.sub continuous_const).pow 2).continuousOn.inv₀ fun w hw h => hr.ne ?_ rwa [mem_sphere_iff_norm, sq_eq_zero_iff.mp h, norm_zero] at hw simp_rw [cderiv, ← smul_sub] congr 1 simpa only [Pi.sub_apply, smul_sub] using circleIntegral.integral_sub ((h1.smul hf).circleIntegrable hr.le) ((h1.smul hg).circleIntegrable hr.le) theorem norm_cderiv_lt (hr : 0 < r) (hfM : ∀ w ∈ sphere z r, ‖f w‖ < M) (hf : ContinuousOn f (sphere z r)) : ‖cderiv r f z‖ < M / r := by obtain ⟨L, hL1, hL2⟩ : ∃ L < M, ∀ w ∈ sphere z r, ‖f w‖ ≤ L := by have e1 : (sphere z r).Nonempty := NormedSpace.sphere_nonempty.mpr hr.le have e2 : ContinuousOn (fun w => ‖f w‖) (sphere z r) := continuous_norm.comp_continuousOn hf obtain ⟨x, hx, hx'⟩ := (isCompact_sphere z r).exists_isMaxOn e1 e2 exact ⟨‖f x‖, hfM x hx, hx'⟩ exact (norm_cderiv_le hr hL2).trans_lt ((div_lt_div_right hr).mpr hL1) theorem norm_cderiv_sub_lt (hr : 0 < r) (hfg : ∀ w ∈ sphere z r, ‖f w - g w‖ < M) (hf : ContinuousOn f (sphere z r)) (hg : ContinuousOn g (sphere z r)) : ‖cderiv r f z - cderiv r g z‖ < M / r := cderiv_sub hr hf hg ▸ norm_cderiv_lt hr hfg (hf.sub hg) theorem _root_.TendstoUniformlyOn.cderiv (hF : TendstoUniformlyOn F f φ (cthickening δ K)) (hδ : 0 < δ) (hFn : ∀ᶠ n in φ, ContinuousOn (F n) (cthickening δ K)) : TendstoUniformlyOn (cderiv δ ∘ F) (cderiv δ f) φ K := by rcases φ.eq_or_neBot with rfl | hne · simp only [TendstoUniformlyOn, eventually_bot, imp_true_iff] have e1 : ContinuousOn f (cthickening δ K) := TendstoUniformlyOn.continuousOn hF hFn rw [tendstoUniformlyOn_iff] at hF ⊢ rintro ε hε filter_upwards [hF (ε * δ) (mul_pos hε hδ), hFn] with n h h' z hz simp_rw [dist_eq_norm] at h ⊢ have e2 : ∀ w ∈ sphere z δ, ‖f w - F n w‖ < ε * δ := fun w hw1 => h w (closedBall_subset_cthickening hz δ (sphere_subset_closedBall hw1)) have e3 := sphere_subset_closedBall.trans (closedBall_subset_cthickening hz δ) have hf : ContinuousOn f (sphere z δ) := e1.mono (sphere_subset_closedBall.trans (closedBall_subset_cthickening hz δ)) simpa only [mul_div_cancel_right₀ _ hδ.ne.symm] using norm_cderiv_sub_lt hδ e2 hf (h'.mono e3) end Cderiv section Weierstrass theorem tendstoUniformlyOn_deriv_of_cthickening_subset (hf : TendstoLocallyUniformlyOn F f φ U) (hF : ∀ᶠ n in φ, DifferentiableOn ℂ (F n) U) {δ : ℝ} (hδ : 0 < δ) (hK : IsCompact K) (hU : IsOpen U) (hKU : cthickening δ K ⊆ U) : TendstoUniformlyOn (deriv ∘ F) (cderiv δ f) φ K := by have h1 : ∀ᶠ n in φ, ContinuousOn (F n) (cthickening δ K) := by filter_upwards [hF] with n h using h.continuousOn.mono hKU have h2 : IsCompact (cthickening δ K) := hK.cthickening have h3 : TendstoUniformlyOn F f φ (cthickening δ K) := (tendstoLocallyUniformlyOn_iff_forall_isCompact hU).mp hf (cthickening δ K) hKU h2 apply (h3.cderiv hδ h1).congr filter_upwards [hF] with n h z hz exact cderiv_eq_deriv hU h hδ ((closedBall_subset_cthickening hz δ).trans hKU) theorem exists_cthickening_tendstoUniformlyOn (hf : TendstoLocallyUniformlyOn F f φ U) (hF : ∀ᶠ n in φ, DifferentiableOn ℂ (F n) U) (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ δ > 0, cthickening δ K ⊆ U ∧ TendstoUniformlyOn (deriv ∘ F) (cderiv δ f) φ K := by obtain ⟨δ, hδ, hKδ⟩ := hK.exists_cthickening_subset_open hU hKU exact ⟨δ, hδ, hKδ, tendstoUniformlyOn_deriv_of_cthickening_subset hf hF hδ hK hU hKδ⟩ /-- A locally uniform limit of holomorphic functions on an open domain of the complex plane is holomorphic (the derivatives converge locally uniformly to that of the limit, which is proved as `TendstoLocallyUniformlyOn.deriv`). -/ theorem _root_.TendstoLocallyUniformlyOn.differentiableOn [φ.NeBot] (hf : TendstoLocallyUniformlyOn F f φ U) (hF : ∀ᶠ n in φ, DifferentiableOn ℂ (F n) U) (hU : IsOpen U) : DifferentiableOn ℂ f U := by rintro x hx obtain ⟨K, ⟨hKx, hK⟩, hKU⟩ := (compact_basis_nhds x).mem_iff.mp (hU.mem_nhds hx) obtain ⟨δ, _, _, h1⟩ := exists_cthickening_tendstoUniformlyOn hf hF hK hU hKU have h2 : interior K ⊆ U := interior_subset.trans hKU have h3 : ∀ᶠ n in φ, DifferentiableOn ℂ (F n) (interior K) := by filter_upwards [hF] with n h using h.mono h2 have h4 : TendstoLocallyUniformlyOn F f φ (interior K) := hf.mono h2 have h5 : TendstoLocallyUniformlyOn (deriv ∘ F) (cderiv δ f) φ (interior K) := h1.tendstoLocallyUniformlyOn.mono interior_subset have h6 : ∀ x ∈ interior K, HasDerivAt f (cderiv δ f x) x := fun x h => hasDerivAt_of_tendsto_locally_uniformly_on' isOpen_interior h5 h3 (fun _ => h4.tendsto_at) h have h7 : DifferentiableOn ℂ f (interior K) := fun x hx => (h6 x hx).differentiableAt.differentiableWithinAt exact (h7.differentiableAt (interior_mem_nhds.mpr hKx)).differentiableWithinAt theorem _root_.TendstoLocallyUniformlyOn.deriv (hf : TendstoLocallyUniformlyOn F f φ U) (hF : ∀ᶠ n in φ, DifferentiableOn ℂ (F n) U) (hU : IsOpen U) : TendstoLocallyUniformlyOn (deriv ∘ F) (deriv f) φ U := by rw [tendstoLocallyUniformlyOn_iff_forall_isCompact hU] rcases φ.eq_or_neBot with rfl | hne · simp only [TendstoUniformlyOn, eventually_bot, imp_true_iff] rintro K hKU hK obtain ⟨δ, hδ, hK4, h⟩ := exists_cthickening_tendstoUniformlyOn hf hF hK hU hKU refine h.congr_right fun z hz => cderiv_eq_deriv hU (hf.differentiableOn hF hU) hδ ?_ exact (closedBall_subset_cthickening hz δ).trans hK4 end Weierstrass section Tsums /-- If the terms in the sum `∑' (i : ι), F i` are uniformly bounded on `U` by a summable function, and each term in the sum is differentiable on `U`, then so is the sum. -/ theorem differentiableOn_tsum_of_summable_norm {u : ι → ℝ} (hu : Summable u) (hf : ∀ i : ι, DifferentiableOn ℂ (F i) U) (hU : IsOpen U) (hF_le : ∀ (i : ι) (w : ℂ), w ∈ U → ‖F i w‖ ≤ u i) : DifferentiableOn ℂ (fun w : ℂ => ∑' i : ι, F i w) U := by classical have hc := (tendstoUniformlyOn_tsum hu hF_le).tendstoLocallyUniformlyOn refine hc.differentiableOn (eventually_of_forall fun s => ?_) hU exact DifferentiableOn.sum fun i _ => hf i /-- If the terms in the sum `∑' (i : ι), F i` are uniformly bounded on `U` by a summable function, then the sum of `deriv F i` at a point in `U` is the derivative of the sum. -/ theorem hasSum_deriv_of_summable_norm {u : ι → ℝ} (hu : Summable u) (hf : ∀ i : ι, DifferentiableOn ℂ (F i) U) (hU : IsOpen U) (hF_le : ∀ (i : ι) (w : ℂ), w ∈ U → ‖F i w‖ ≤ u i) (hz : z ∈ U) : HasSum (fun i : ι => deriv (F i) z) (deriv (fun w : ℂ => ∑' i : ι, F i w) z) := by rw [HasSum] have hc := (tendstoUniformlyOn_tsum hu hF_le).tendstoLocallyUniformlyOn convert (hc.deriv (eventually_of_forall fun s => DifferentiableOn.sum fun i _ => hf i) hU).tendsto_at hz using 1 ext1 s exact (deriv_sum fun i _ => (hf i).differentiableAt (hU.mem_nhds hz)).symm end Tsums section LogDeriv /-- The logarithmic derivative of a sequence of functions converging locally uniformly to a function is the logarithmic derivative of the limit function. -/ theorem logDeriv_tendsto {ι : Type*} {p : Filter ι} (f : ι → ℂ → ℂ) (g : ℂ → ℂ) {s : Set ℂ} (hs : IsOpen s) (x : s) (hF : TendstoLocallyUniformlyOn f g p s) (hf : ∀ᶠ n : ι in p, DifferentiableOn ℂ (f n) s) (hg : g x ≠ 0) : Tendsto (fun n : ι => logDeriv (f n) x) p (𝓝 ((logDeriv g) x)) := by simp_rw [logDeriv] apply Tendsto.div ((hF.deriv hf hs).tendsto_at x.2) (hF.tendsto_at x.2) hg end LogDeriv end Complex
Analysis\Complex\OpenMapping.lean
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.Complex.AbsMax import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas /-! # The open mapping theorem for holomorphic functions This file proves the open mapping theorem for holomorphic functions, namely that an analytic function on a preconnected set of the complex plane is either constant or open. The main step is to show a local version of the theorem that states that if `f` is analytic at a point `z₀`, then either it is constant in a neighborhood of `z₀` or it maps any neighborhood of `z₀` to a neighborhood of its image `f z₀`. The results extend in higher dimension to `g : E → ℂ`. The proof of the local version on `ℂ` goes through two main steps: first, assuming that the function is not constant around `z₀`, use the isolated zero principle to show that `‖f z‖` is bounded below on a small `sphere z₀ r` around `z₀`, and then use the maximum principle applied to the auxiliary function `(fun z ↦ ‖f z - v‖)` to show that any `v` close enough to `f z₀` is in `f '' ball z₀ r`. That second step is implemented in `DiffContOnCl.ball_subset_image_closedBall`. ## Main results * `AnalyticAt.eventually_constant_or_nhds_le_map_nhds` is the local version of the open mapping theorem around a point; * `AnalyticOn.is_constant_or_isOpen` is the open mapping theorem on a connected open set. -/ open Set Filter Metric Complex open scoped Topology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {U : Set E} {f : ℂ → ℂ} {g : E → ℂ} {z₀ w : ℂ} {ε r m : ℝ} /-- If the modulus of a holomorphic function `f` is bounded below by `ε` on a circle, then its range contains a disk of radius `ε / 2`. -/ theorem DiffContOnCl.ball_subset_image_closedBall (h : DiffContOnCl ℂ f (ball z₀ r)) (hr : 0 < r) (hf : ∀ z ∈ sphere z₀ r, ε ≤ ‖f z - f z₀‖) (hz₀ : ∃ᶠ z in 𝓝 z₀, f z ≠ f z₀) : ball (f z₀) (ε / 2) ⊆ f '' closedBall z₀ r := by /- This is a direct application of the maximum principle. Pick `v` close to `f z₀`, and look at the function `fun z ↦ ‖f z - v‖`: it is bounded below on the circle, and takes a small value at `z₀` so it is not constant on the disk, which implies that its infimum is equal to `0` and hence that `v` is in the range of `f`. -/ rintro v hv have h1 : DiffContOnCl ℂ (fun z => f z - v) (ball z₀ r) := h.sub_const v have h2 : ContinuousOn (fun z => ‖f z - v‖) (closedBall z₀ r) := continuous_norm.comp_continuousOn (closure_ball z₀ hr.ne.symm ▸ h1.continuousOn) have h3 : AnalyticOn ℂ f (ball z₀ r) := h.differentiableOn.analyticOn isOpen_ball have h4 : ∀ z ∈ sphere z₀ r, ε / 2 ≤ ‖f z - v‖ := fun z hz => by linarith [hf z hz, show ‖v - f z₀‖ < ε / 2 from mem_ball.mp hv, norm_sub_sub_norm_sub_le_norm_sub (f z) v (f z₀)] have h5 : ‖f z₀ - v‖ < ε / 2 := by simpa [← dist_eq_norm, dist_comm] using mem_ball.mp hv obtain ⟨z, hz1, hz2⟩ : ∃ z ∈ ball z₀ r, IsLocalMin (fun z => ‖f z - v‖) z := exists_isLocalMin_mem_ball h2 (mem_closedBall_self hr.le) fun z hz => h5.trans_le (h4 z hz) refine ⟨z, ball_subset_closedBall hz1, sub_eq_zero.mp ?_⟩ have h6 := h1.differentiableOn.eventually_differentiableAt (isOpen_ball.mem_nhds hz1) refine (eventually_eq_or_eq_zero_of_isLocalMin_norm h6 hz2).resolve_left fun key => ?_ have h7 : ∀ᶠ w in 𝓝 z, f w = f z := by filter_upwards [key] with h; field_simp replace h7 : ∃ᶠ w in 𝓝[≠] z, f w = f z := (h7.filter_mono nhdsWithin_le_nhds).frequently have h8 : IsPreconnected (ball z₀ r) := (convex_ball z₀ r).isPreconnected have h9 := h3.eqOn_of_preconnected_of_frequently_eq analyticOn_const h8 hz1 h7 have h10 : f z = f z₀ := (h9 (mem_ball_self hr)).symm exact not_eventually.mpr hz₀ (mem_of_superset (ball_mem_nhds z₀ hr) (h10 ▸ h9)) /-- A function `f : ℂ → ℂ` which is analytic at a point `z₀` is either constant in a neighborhood of `z₀`, or behaves locally like an open function (in the sense that the image of every neighborhood of `z₀` is a neighborhood of `f z₀`, as in `isOpenMap_iff_nhds_le`). For a function `f : E → ℂ` the same result holds, see `AnalyticAt.eventually_constant_or_nhds_le_map_nhds`. -/ theorem AnalyticAt.eventually_constant_or_nhds_le_map_nhds_aux (hf : AnalyticAt ℂ f z₀) : (∀ᶠ z in 𝓝 z₀, f z = f z₀) ∨ 𝓝 (f z₀) ≤ map f (𝓝 z₀) := by /- The function `f` is analytic in a neighborhood of `z₀`; by the isolated zeros principle, if `f` is not constant in a neighborhood of `z₀`, then it is nonzero, and therefore bounded below, on every small enough circle around `z₀` and then `DiffContOnCl.ball_subset_image_closedBall` provides an explicit ball centered at `f z₀` contained in the range of `f`. -/ refine or_iff_not_imp_left.mpr fun h => ?_ refine (nhds_basis_ball.le_basis_iff (nhds_basis_closedBall.map f)).mpr fun R hR => ?_ have h1 := (hf.eventually_eq_or_eventually_ne analyticAt_const).resolve_left h have h2 : ∀ᶠ z in 𝓝 z₀, AnalyticAt ℂ f z := (isOpen_analyticAt ℂ f).eventually_mem hf obtain ⟨ρ, hρ, h3, h4⟩ : ∃ ρ > 0, AnalyticOn ℂ f (closedBall z₀ ρ) ∧ ∀ z ∈ closedBall z₀ ρ, z ≠ z₀ → f z ≠ f z₀ := by simpa only [setOf_and, subset_inter_iff] using nhds_basis_closedBall.mem_iff.mp (h2.and (eventually_nhdsWithin_iff.mp h1)) replace h3 : DiffContOnCl ℂ f (ball z₀ ρ) := ⟨h3.differentiableOn.mono ball_subset_closedBall, (closure_ball z₀ hρ.lt.ne.symm).symm ▸ h3.continuousOn⟩ let r := ρ ⊓ R have hr : 0 < r := lt_inf_iff.mpr ⟨hρ, hR⟩ have h5 : closedBall z₀ r ⊆ closedBall z₀ ρ := closedBall_subset_closedBall inf_le_left have h6 : DiffContOnCl ℂ f (ball z₀ r) := h3.mono (ball_subset_ball inf_le_left) have h7 : ∀ z ∈ sphere z₀ r, f z ≠ f z₀ := fun z hz => h4 z (h5 (sphere_subset_closedBall hz)) (ne_of_mem_sphere hz hr.ne.symm) have h8 : (sphere z₀ r).Nonempty := NormedSpace.sphere_nonempty.mpr hr.le have h9 : ContinuousOn (fun x => ‖f x - f z₀‖) (sphere z₀ r) := continuous_norm.comp_continuousOn ((h6.sub_const (f z₀)).continuousOn_ball.mono sphere_subset_closedBall) obtain ⟨x, hx, hfx⟩ := (isCompact_sphere z₀ r).exists_isMinOn h8 h9 refine ⟨‖f x - f z₀‖ / 2, half_pos (norm_sub_pos_iff.mpr (h7 x hx)), ?_⟩ exact (h6.ball_subset_image_closedBall hr (fun z hz => hfx hz) (not_eventually.mp h)).trans (image_subset f (closedBall_subset_closedBall inf_le_right)) /-- The *open mapping theorem* for holomorphic functions, local version: is a function `g : E → ℂ` is analytic at a point `z₀`, then either it is constant in a neighborhood of `z₀`, or it maps every neighborhood of `z₀` to a neighborhood of `z₀`. For the particular case of a holomorphic function on `ℂ`, see `AnalyticAt.eventually_constant_or_nhds_le_map_nhds_aux`. -/ theorem AnalyticAt.eventually_constant_or_nhds_le_map_nhds {z₀ : E} (hg : AnalyticAt ℂ g z₀) : (∀ᶠ z in 𝓝 z₀, g z = g z₀) ∨ 𝓝 (g z₀) ≤ map g (𝓝 z₀) := by /- The idea of the proof is to use the one-dimensional version applied to the restriction of `g` to lines going through `z₀` (indexed by `sphere (0 : E) 1`). If the restriction is eventually constant along each of these lines, then the identity theorem implies that `g` is constant on any ball centered at `z₀` on which it is analytic, and in particular `g` is eventually constant. If on the other hand there is one line along which `g` is not eventually constant, then the one-dimensional version of the open mapping theorem can be used to conclude. -/ let ray : E → ℂ → E := fun z t => z₀ + t • z let gray : E → ℂ → ℂ := fun z => g ∘ ray z obtain ⟨r, hr, hgr⟩ := isOpen_iff.mp (isOpen_analyticAt ℂ g) z₀ hg have h1 : ∀ z ∈ sphere (0 : E) 1, AnalyticOn ℂ (gray z) (ball 0 r) := by refine fun z hz t ht => AnalyticAt.comp ?_ ?_ · exact hgr (by simpa [ray, norm_smul, mem_sphere_zero_iff_norm.mp hz] using ht) · exact analyticAt_const.add ((ContinuousLinearMap.smulRight (ContinuousLinearMap.id ℂ ℂ) z).analyticAt t) by_cases h : ∀ z ∈ sphere (0 : E) 1, ∀ᶠ t in 𝓝 0, gray z t = gray z 0 · left -- If g is eventually constant along every direction, then it is eventually constant refine eventually_of_mem (ball_mem_nhds z₀ hr) fun z hz => ?_ refine (eq_or_ne z z₀).casesOn (congr_arg g) fun h' => ?_ replace h' : ‖z - z₀‖ ≠ 0 := by simpa only [Ne, norm_eq_zero, sub_eq_zero] let w : E := ‖z - z₀‖⁻¹ • (z - z₀) have h3 : ∀ t ∈ ball (0 : ℂ) r, gray w t = g z₀ := by have e1 : IsPreconnected (ball (0 : ℂ) r) := (convex_ball 0 r).isPreconnected have e2 : w ∈ sphere (0 : E) 1 := by simp [w, norm_smul, inv_mul_cancel h'] specialize h1 w e2 apply h1.eqOn_of_preconnected_of_eventuallyEq analyticOn_const e1 (mem_ball_self hr) simpa [ray, gray] using h w e2 have h4 : ‖z - z₀‖ < r := by simpa [dist_eq_norm] using mem_ball.mp hz replace h4 : ↑‖z - z₀‖ ∈ ball (0 : ℂ) r := by simpa only [mem_ball_zero_iff, norm_eq_abs, abs_ofReal, abs_norm] simpa only [ray, gray, w, smul_smul, mul_inv_cancel h', one_smul, add_sub_cancel, Function.comp_apply, coe_smul] using h3 (↑‖z - z₀‖) h4 · right -- Otherwise, it is open along at least one direction and that implies the result push_neg at h obtain ⟨z, hz, hrz⟩ := h specialize h1 z hz 0 (mem_ball_self hr) have h7 := h1.eventually_constant_or_nhds_le_map_nhds_aux.resolve_left hrz rw [show gray z 0 = g z₀ by simp [gray, ray], ← map_compose] at h7 refine h7.trans (map_mono ?_) have h10 : Continuous fun t : ℂ => z₀ + t • z := continuous_const.add (continuous_id'.smul continuous_const) simpa using h10.tendsto 0 /-- The *open mapping theorem* for holomorphic functions, global version: if a function `g : E → ℂ` is analytic on a connected set `U`, then either it is constant on `U`, or it is open on `U` (in the sense that it maps any open set contained in `U` to an open set in `ℂ`). -/ theorem AnalyticOn.is_constant_or_isOpen (hg : AnalyticOn ℂ g U) (hU : IsPreconnected U) : (∃ w, ∀ z ∈ U, g z = w) ∨ ∀ s ⊆ U, IsOpen s → IsOpen (g '' s) := by by_cases h : ∃ z₀ ∈ U, ∀ᶠ z in 𝓝 z₀, g z = g z₀ · obtain ⟨z₀, hz₀, h⟩ := h exact Or.inl ⟨g z₀, hg.eqOn_of_preconnected_of_eventuallyEq analyticOn_const hU hz₀ h⟩ · push_neg at h refine Or.inr fun s hs1 hs2 => isOpen_iff_mem_nhds.mpr ?_ rintro z ⟨w, hw1, rfl⟩ exact (hg w (hs1 hw1)).eventually_constant_or_nhds_le_map_nhds.resolve_left (h w (hs1 hw1)) (image_mem_map (hs2.mem_nhds hw1))
Analysis\Complex\OperatorNorm.lean
/- 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.Complex.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Data.Complex.Determinant /-! # The basic continuous linear maps associated to `ℂ` The continuous linear maps `Complex.reCLM` (real part), `Complex.imCLM` (imaginary part), `Complex.conjCLE` (conjugation), and `Complex.ofRealCLM` (inclusion of `ℝ`) were introduced in `Analysis.Complex.Basic`. This file contains a few calculations requiring more imports: the operator norm and (for `Complex.conjCLE`) the determinant. -/ open ContinuousLinearMap namespace Complex /-- The determinant of `conjLIE`, as a linear map. -/ @[simp] theorem det_conjLIE : LinearMap.det (conjLIE.toLinearEquiv : ℂ →ₗ[ℝ] ℂ) = -1 := det_conjAe /-- The determinant of `conjLIE`, as a linear equiv. -/ @[simp] theorem linearEquiv_det_conjLIE : LinearEquiv.det conjLIE.toLinearEquiv = -1 := linearEquiv_det_conjAe @[simp] theorem reCLM_norm : ‖reCLM‖ = 1 := le_antisymm (LinearMap.mkContinuous_norm_le _ zero_le_one _) <| calc 1 = ‖reCLM 1‖ := by simp _ ≤ ‖reCLM‖ := unit_le_opNorm _ _ (by simp) @[simp] theorem reCLM_nnnorm : ‖reCLM‖₊ = 1 := Subtype.ext reCLM_norm @[simp] theorem imCLM_norm : ‖imCLM‖ = 1 := le_antisymm (LinearMap.mkContinuous_norm_le _ zero_le_one _) <| calc 1 = ‖imCLM I‖ := by simp _ ≤ ‖imCLM‖ := unit_le_opNorm _ _ (by simp) @[simp] theorem imCLM_nnnorm : ‖imCLM‖₊ = 1 := Subtype.ext imCLM_norm @[simp] theorem conjCLE_norm : ‖(conjCLE : ℂ →L[ℝ] ℂ)‖ = 1 := conjLIE.toLinearIsometry.norm_toContinuousLinearMap @[simp] theorem conjCLE_nnorm : ‖(conjCLE : ℂ →L[ℝ] ℂ)‖₊ = 1 := Subtype.ext conjCLE_norm @[simp] theorem ofRealCLM_norm : ‖ofRealCLM‖ = 1 := ofRealLI.norm_toContinuousLinearMap @[simp] theorem ofRealCLM_nnnorm : ‖ofRealCLM‖₊ = 1 := Subtype.ext <| ofRealCLM_norm end Complex
Analysis\Complex\PhragmenLindelof.lean
/- 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 * abs z ^ c)) (hBg : ∃ c < a, ∃ B, g =O[cobounded ℂ ⊓ l] fun z => expR (B * abs z ^ c)) : ∃ c < a, ∃ B, (f - g) =O[cobounded ℂ ⊓ l] fun z => expR (B * abs z ^ c) := by have : ∀ {c₁ c₂ B₁ B₂ : ℝ}, c₁ ≤ c₂ → 0 ≤ B₂ → B₁ ≤ B₂ → (fun z : ℂ => expR (B₁ * abs z ^ c₁)) =O[cobounded ℂ ⊓ l] fun z => expR (B₂ * abs z ^ c₂) := fun hc hB₀ hB ↦ .of_bound 1 <| by filter_upwards [(eventually_cobounded_le_norm 1).filter_mono inf_le_left] with z hz simp only [one_mul, 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 cases' hza with hza hza; · exact hle_a _ hza.symm cases' hzb with hzb hzb; · exact hle_b _ hzb wlog hC₀ : 0 < C generalizing C · refine le_of_forall_le_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) → abs (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 abs_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 → abs (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_const_nhds.mul_atTop hd₀ tendsto_id refine tendsto_const_nhds.add (tendsto_const_nhds.mul ?_) exact tendsto_inv_atTop_zero.comp <| Real.tendsto_exp_atTop.comp <| tendsto_const_nhds.mul_atTop (sub_pos.2 hcd) tendsto_id 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 [(· ∘ ·)] using tendsto_comap simpa [(· ∘ ·)] 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 * (abs 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 * abs 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)⟩ -- Porting note: failed to clear `clear hz_re hz_im hzne` -- 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 -- Porting note: failed to clear hζ ζ · -- 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_bound 1 ?_) · -- 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 [eventually_inf_principal, eventually_comap, comp_apply, one_mul, Real.norm_of_nonneg (Real.exp_pos _).le, abs_exp, ← Real.exp_mul, Real.exp_le_exp] refine (eventually_ge_atTop 0).mono fun x hx z hz _ => ?_ rw [hz, _root_.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 * (abs 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 * abs 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 <| quadrant_I hd hB (fun x hx => norm_le_zero_iff.2 <| hre x hx) (fun x hx => norm_le_zero_iff.2 <| him x hx) hz.1 hz.2 /-- **Phragmen-Lindelöf principle** in the first quadrant. Let `f g : ℂ → E` be functions such that * `f` and `g` are differentiable in the open first quadrant and are continuous on its closure; * `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open first quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the first quadrant. Then `f` is equal to `g` on the closed first quadrant. -/ theorem eqOn_quadrant_I (hdf : DiffContOnCl ℂ f (Ioi 0 ×ℂ Ioi 0)) (hBf : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c)) (hdg : DiffContOnCl ℂ g (Ioi 0 ×ℂ Ioi 0)) (hBg : ∃ c < (2 : ℝ), ∃ B, g =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, 0 ≤ x → f x = g x) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = g (x * I)) : EqOn f g {z | 0 ≤ z.re ∧ 0 ≤ z.im} := fun _z hz => sub_eq_zero.1 <| eq_zero_on_quadrant_I (hdf.sub hdg) (isBigO_sub_exp_rpow hBf hBg) (fun x hx => sub_eq_zero.2 <| hre x hx) (fun x hx => sub_eq_zero.2 <| him x hx) hz /-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open second quadrant and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant for some `c < 2`; * `‖f z‖` is bounded from above by a constant `C` on the boundary of the second quadrant. Then `‖f z‖` is bounded from above by the same constant on the closed second quadrant. -/ theorem quadrant_II (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Ioi 0)) (hB : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, x ≤ 0 → ‖f x‖ ≤ C) (him : ∀ x : ℝ, 0 ≤ x → ‖f (x * I)‖ ≤ C) (hz_re : z.re ≤ 0) (hz_im : 0 ≤ z.im) : ‖f z‖ ≤ C := by obtain ⟨z, rfl⟩ : ∃ z', z' * I = z := ⟨z / I, div_mul_cancel₀ _ I_ne_zero⟩ simp only [mul_I_re, mul_I_im, neg_nonpos] at hz_re hz_im change ‖(f ∘ (· * I)) z‖ ≤ C have H : MapsTo (· * I) (Ioi 0 ×ℂ Ioi 0) (Iio 0 ×ℂ Ioi 0) := fun w hw ↦ by simpa only [mem_reProdIm, mul_I_re, mul_I_im, neg_lt_zero, mem_Iio] using hw.symm rcases hB with ⟨c, hc, B, hO⟩ refine quadrant_I (hd.comp (differentiable_id.mul_const _).diffContOnCl H) ⟨c, hc, B, ?_⟩ him (fun x hx => ?_) hz_im hz_re · simpa only [(· ∘ ·), map_mul, abs_I, mul_one] using hO.comp_tendsto ((tendsto_mul_right_cobounded I_ne_zero).inf H.tendsto) · rw [comp_apply, mul_assoc, I_mul_I, mul_neg_one, ← ofReal_neg] exact hre _ (neg_nonpos.2 hx) /-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open second quadrant and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the second quadrant. Then `f` is equal to zero on the closed second quadrant. -/ theorem eq_zero_on_quadrant_II (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Ioi 0)) (hB : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, x ≤ 0 → f x = 0) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = 0) : EqOn f 0 {z | z.re ≤ 0 ∧ 0 ≤ z.im} := fun _z hz => norm_le_zero_iff.1 <| quadrant_II hd hB (fun x hx => norm_le_zero_iff.2 <| hre x hx) (fun x hx => norm_le_zero_iff.2 <| him x hx) hz.1 hz.2 /-- **Phragmen-Lindelöf principle** in the second quadrant. Let `f g : ℂ → E` be functions such that * `f` and `g` are differentiable in the open second quadrant and are continuous on its closure; * `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open second quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the second quadrant. Then `f` is equal to `g` on the closed second quadrant. -/ theorem eqOn_quadrant_II (hdf : DiffContOnCl ℂ f (Iio 0 ×ℂ Ioi 0)) (hBf : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c)) (hdg : DiffContOnCl ℂ g (Iio 0 ×ℂ Ioi 0)) (hBg : ∃ c < (2 : ℝ), ∃ B, g =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Ioi 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, x ≤ 0 → f x = g x) (him : ∀ x : ℝ, 0 ≤ x → f (x * I) = g (x * I)) : EqOn f g {z | z.re ≤ 0 ∧ 0 ≤ z.im} := fun _z hz => sub_eq_zero.1 <| eq_zero_on_quadrant_II (hdf.sub hdg) (isBigO_sub_exp_rpow hBf hBg) (fun x hx => sub_eq_zero.2 <| hre x hx) (fun x hx => sub_eq_zero.2 <| him x hx) hz /-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open third quadrant and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp (B * (abs z) ^ c)` on the open third quadrant for some `c < 2`; * `‖f z‖` is bounded from above by a constant `C` on the boundary of the third quadrant. Then `‖f z‖` is bounded from above by the same constant on the closed third quadrant. -/ theorem quadrant_III (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Iio 0)) (hB : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, x ≤ 0 → ‖f x‖ ≤ C) (him : ∀ x : ℝ, x ≤ 0 → ‖f (x * I)‖ ≤ C) (hz_re : z.re ≤ 0) (hz_im : z.im ≤ 0) : ‖f z‖ ≤ C := by obtain ⟨z, rfl⟩ : ∃ z', -z' = z := ⟨-z, neg_neg z⟩ simp only [neg_re, neg_im, neg_nonpos] at hz_re hz_im change ‖(f ∘ Neg.neg) z‖ ≤ C have H : MapsTo Neg.neg (Ioi 0 ×ℂ Ioi 0) (Iio 0 ×ℂ Iio 0) := by intro w hw simpa only [mem_reProdIm, neg_re, neg_im, neg_lt_zero, mem_Iio] using hw refine quadrant_I (hd.comp differentiable_neg.diffContOnCl H) ?_ (fun x hx => ?_) (fun x hx => ?_) hz_re hz_im · rcases hB with ⟨c, hc, B, hO⟩ refine ⟨c, hc, B, ?_⟩ simpa only [(· ∘ ·), Complex.abs.map_neg] using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto) · rw [comp_apply, ← ofReal_neg] exact hre (-x) (neg_nonpos.2 hx) · rw [comp_apply, ← neg_mul, ← ofReal_neg] exact him (-x) (neg_nonpos.2 hx) /-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open third quadrant and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open third quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the third quadrant. Then `f` is equal to zero on the closed third quadrant. -/ theorem eq_zero_on_quadrant_III (hd : DiffContOnCl ℂ f (Iio 0 ×ℂ Iio 0)) (hB : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, x ≤ 0 → f x = 0) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = 0) : EqOn f 0 {z | z.re ≤ 0 ∧ z.im ≤ 0} := fun _z hz => norm_le_zero_iff.1 <| quadrant_III hd hB (fun x hx => norm_le_zero_iff.2 <| hre x hx) (fun x hx => norm_le_zero_iff.2 <| him x hx) hz.1 hz.2 /-- **Phragmen-Lindelöf principle** in the third quadrant. Let `f g : ℂ → E` be functions such that * `f` and `g` are differentiable in the open third quadrant and are continuous on its closure; * `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open third quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the third quadrant. Then `f` is equal to `g` on the closed third quadrant. -/ theorem eqOn_quadrant_III (hdf : DiffContOnCl ℂ f (Iio 0 ×ℂ Iio 0)) (hBf : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hdg : DiffContOnCl ℂ g (Iio 0 ×ℂ Iio 0)) (hBg : ∃ c < (2 : ℝ), ∃ B, g =O[cobounded ℂ ⊓ 𝓟 (Iio 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, x ≤ 0 → f x = g x) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = g (x * I)) : EqOn f g {z | z.re ≤ 0 ∧ z.im ≤ 0} := fun _z hz => sub_eq_zero.1 <| eq_zero_on_quadrant_III (hdf.sub hdg) (isBigO_sub_exp_rpow hBf hBg) (fun x hx => sub_eq_zero.2 <| hre x hx) (fun x hx => sub_eq_zero.2 <| him x hx) hz /-- **Phragmen-Lindelöf principle** in the fourth quadrant. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open fourth quadrant and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant for some `c < 2`; * `‖f z‖` is bounded from above by a constant `C` on the boundary of the fourth quadrant. Then `‖f z‖` is bounded from above by the same constant on the closed fourth quadrant. -/ theorem quadrant_IV (hd : DiffContOnCl ℂ f (Ioi 0 ×ℂ Iio 0)) (hB : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C) (him : ∀ x : ℝ, x ≤ 0 → ‖f (x * I)‖ ≤ C) (hz_re : 0 ≤ z.re) (hz_im : z.im ≤ 0) : ‖f z‖ ≤ C := by obtain ⟨z, rfl⟩ : ∃ z', -z' = z := ⟨-z, neg_neg z⟩ simp only [neg_re, neg_im, neg_nonpos, neg_nonneg] at hz_re hz_im change ‖(f ∘ Neg.neg) z‖ ≤ C have H : MapsTo Neg.neg (Iio 0 ×ℂ Ioi 0) (Ioi 0 ×ℂ Iio 0) := fun w hw ↦ by simpa only [mem_reProdIm, neg_re, neg_im, neg_lt_zero, neg_pos, mem_Ioi, mem_Iio] using hw refine quadrant_II (hd.comp differentiable_neg.diffContOnCl H) ?_ (fun x hx => ?_) (fun x hx => ?_) hz_re hz_im · rcases hB with ⟨c, hc, B, hO⟩ refine ⟨c, hc, B, ?_⟩ simpa only [(· ∘ ·), Complex.abs.map_neg] using hO.comp_tendsto (tendsto_neg_cobounded.inf H.tendsto) · rw [comp_apply, ← ofReal_neg] exact hre (-x) (neg_nonneg.2 hx) · rw [comp_apply, ← neg_mul, ← ofReal_neg] exact him (-x) (neg_nonpos.2 hx) /-- **Phragmen-Lindelöf principle** in the fourth quadrant. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open fourth quadrant and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to zero on the boundary of the fourth quadrant. Then `f` is equal to zero on the closed fourth quadrant. -/ theorem eq_zero_on_quadrant_IV (hd : DiffContOnCl ℂ f (Ioi 0 ×ℂ Iio 0)) (hB : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, 0 ≤ x → f x = 0) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = 0) : EqOn f 0 {z | 0 ≤ z.re ∧ z.im ≤ 0} := fun _z hz => norm_le_zero_iff.1 <| quadrant_IV hd hB (fun x hx => norm_le_zero_iff.2 <| hre x hx) (fun x hx => norm_le_zero_iff.2 <| him x hx) hz.1 hz.2 /-- **Phragmen-Lindelöf principle** in the fourth quadrant. Let `f g : ℂ → E` be functions such that * `f` and `g` are differentiable in the open fourth quadrant and are continuous on its closure; * `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open fourth quadrant for some `A`, `B`, and `c < 2`; * `f` is equal to `g` on the boundary of the fourth quadrant. Then `f` is equal to `g` on the closed fourth quadrant. -/ theorem eqOn_quadrant_IV (hdf : DiffContOnCl ℂ f (Ioi 0 ×ℂ Iio 0)) (hBf : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hdg : DiffContOnCl ℂ g (Ioi 0 ×ℂ Iio 0)) (hBg : ∃ c < (2 : ℝ), ∃ B, g =O[cobounded ℂ ⊓ 𝓟 (Ioi 0 ×ℂ Iio 0)] fun z => expR (B * abs z ^ c)) (hre : ∀ x : ℝ, 0 ≤ x → f x = g x) (him : ∀ x : ℝ, x ≤ 0 → f (x * I) = g (x * I)) : EqOn f g {z | 0 ≤ z.re ∧ z.im ≤ 0} := fun _z hz => sub_eq_zero.1 <| eq_zero_on_quadrant_IV (hdf.sub hdg) (isBigO_sub_exp_rpow hBf hBg) (fun x hx => sub_eq_zero.2 <| hre x hx) (fun x hx => sub_eq_zero.2 <| him x hx) hz /-! ### Phragmen-Lindelöf principle in the right half-plane -/ /-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open right half-plane and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `‖f z‖` is bounded from above by a constant `C` on the imaginary axis; * `f x → 0` as `x : ℝ` tends to infinity. Then `‖f z‖` is bounded from above by the same constant on the closed right half-plane. See also `PhragmenLindelof.right_half_plane_of_bounded_on_real` for a stronger version. -/ theorem right_half_plane_of_tendsto_zero_on_real (hd : DiffContOnCl ℂ f {z | 0 < z.re}) (hexp : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 {z | 0 < z.re}] fun z => expR (B * abs z ^ c)) (hre : Tendsto (fun x : ℝ => f x) atTop (𝓝 0)) (him : ∀ x : ℝ, ‖f (x * I)‖ ≤ C) (hz : 0 ≤ z.re) : ‖f z‖ ≤ C := by /- We are going to apply the Phragmen-Lindelöf principle in the first and fourth quadrants. The lemmas immediately imply that for any upper estimate `C'` on `‖f x‖`, `x : ℝ`, `0 ≤ x`, the number `max C C'` is an upper estimate on `f` in the whole right half-plane. -/ revert z have hle : ∀ C', (∀ x : ℝ, 0 ≤ x → ‖f x‖ ≤ C') → ∀ z : ℂ, 0 ≤ z.re → ‖f z‖ ≤ max C C' := fun C' hC' z hz ↦ by rcases hexp with ⟨c, hc, B, hO⟩ rcases le_total z.im 0 with h | h · refine quadrant_IV (hd.mono fun _ => And.left) ⟨c, hc, B, ?_⟩ (fun x hx => (hC' x hx).trans <| le_max_right _ _) (fun x _ => (him x).trans (le_max_left _ _)) hz h exact hO.mono (inf_le_inf_left _ <| principal_mono.2 fun _ => And.left) · refine quadrant_I (hd.mono fun _ => And.left) ⟨c, hc, B, ?_⟩ (fun x hx => (hC' x hx).trans <| le_max_right _ _) (fun x _ => (him x).trans (le_max_left _ _)) hz h exact hO.mono (inf_le_inf_left _ <| principal_mono.2 fun _ => And.left) -- Since `f` is continuous on `Ici 0` and `‖f x‖` tends to zero as `x → ∞`, -- the norm `‖f x‖` takes its maximum value at some `x₀ : ℝ`. obtain ⟨x₀, hx₀, hmax⟩ : ∃ x : ℝ, 0 ≤ x ∧ ∀ y : ℝ, 0 ≤ y → ‖f y‖ ≤ ‖f x‖ := by have hfc : ContinuousOn (fun x : ℝ => f x) (Ici 0) := by refine hd.continuousOn.comp continuous_ofReal.continuousOn fun x hx => ?_ rwa [closure_setOf_lt_re] by_cases h₀ : ∀ x : ℝ, 0 ≤ x → f x = 0 · refine ⟨0, le_rfl, fun y hy => ?_⟩; rw [h₀ y hy, h₀ 0 le_rfl] push_neg at h₀ rcases h₀ with ⟨x₀, hx₀, hne⟩ have hlt : ‖(0 : E)‖ < ‖f x₀‖ := by rwa [norm_zero, norm_pos_iff] suffices ∀ᶠ x : ℝ in cocompact ℝ ⊓ 𝓟 (Ici 0), ‖f x‖ ≤ ‖f x₀‖ by simpa only [exists_prop] using hfc.norm.exists_isMaxOn' isClosed_Ici hx₀ this rw [cocompact_eq_atBot_atTop, inf_sup_right, (disjoint_atBot_principal_Ici (0 : ℝ)).eq_bot, bot_sup_eq] exact (hre.norm.eventually <| ge_mem_nhds hlt).filter_mono inf_le_left rcases le_or_lt ‖f x₀‖ C with h | h ·-- If `‖f x₀‖ ≤ C`, then `hle` implies the required estimate simpa only [max_eq_left h] using hle _ hmax · -- Otherwise, `‖f z‖ ≤ ‖f x₀‖` for all `z` in the right half-plane due to `hle`. replace hmax : IsMaxOn (norm ∘ f) {z | 0 < z.re} x₀ := by rintro z (hz : 0 < z.re) simpa [max_eq_right h.le] using hle _ hmax _ hz.le -- Due to the maximum modulus principle applied to the closed ball of radius `x₀.re`, -- `‖f 0‖ = ‖f x₀‖`. have : ‖f 0‖ = ‖f x₀‖ := by apply norm_eq_norm_of_isMaxOn_of_ball_subset hd hmax -- move to a lemma? intro z hz rw [mem_ball, dist_zero_left, dist_eq, norm_eq_abs, Complex.abs_of_nonneg hx₀] at hz rw [mem_setOf_eq] contrapose! hz calc x₀ ≤ x₀ - z.re := (le_sub_self_iff _).2 hz _ ≤ |x₀ - z.re| := le_abs_self _ _ = |(z - x₀).re| := by rw [sub_re, ofReal_re, _root_.abs_sub_comm] _ ≤ abs (z - x₀) := abs_re_le_abs _ -- Thus we have `C < ‖f x₀‖ = ‖f 0‖ ≤ C`. Contradiction completes the proof. refine (h.not_le <| this ▸ ?_).elim simpa using him 0 /-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open right half-plane and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `‖f z‖` is bounded from above by a constant `C` on the imaginary axis; * `‖f x‖` is bounded from above by a constant for large real values of `x`. Then `‖f z‖` is bounded from above by `C` on the closed right half-plane. See also `PhragmenLindelof.right_half_plane_of_tendsto_zero_on_real` for a weaker version. -/ theorem right_half_plane_of_bounded_on_real (hd : DiffContOnCl ℂ f {z | 0 < z.re}) (hexp : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 {z | 0 < z.re}] fun z => expR (B * abs z ^ c)) (hre : IsBoundedUnder (· ≤ ·) atTop fun x : ℝ => ‖f x‖) (him : ∀ x : ℝ, ‖f (x * I)‖ ≤ C) (hz : 0 ≤ z.re) : ‖f z‖ ≤ C := by -- For each `ε < 0`, the function `fun z ↦ exp (ε * z) • f z` satisfies assumptions of -- `right_half_plane_of_tendsto_zero_on_real`, hence `‖exp (ε * z) • f z‖ ≤ C` for all `ε < 0`. -- Taking the limit as `ε → 0`, we obtain the required inequality. suffices ∀ᶠ ε : ℝ in 𝓝[<] 0, ‖exp (ε * 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 ε₀ set g : ℂ → E := fun z => exp (ε * z) • f z; change ‖g z‖ ≤ C replace hd : DiffContOnCl ℂ g {z : ℂ | 0 < z.re} := (differentiable_id.const_mul _).cexp.diffContOnCl.smul hd have hgn : ∀ z, ‖g z‖ = expR (ε * z.re) * ‖f z‖ := fun z ↦ by rw [norm_smul, norm_eq_abs, abs_exp, re_ofReal_mul] refine right_half_plane_of_tendsto_zero_on_real hd ?_ ?_ (fun y => ?_) hz · rcases hexp with ⟨c, hc, B, hO⟩ refine ⟨c, hc, B, (IsBigO.of_bound 1 ?_).trans hO⟩ refine eventually_inf_principal.2 <| eventually_of_forall fun z hz => ?_ rw [hgn, one_mul] refine mul_le_of_le_one_left (norm_nonneg _) (Real.exp_le_one_iff.2 ?_) exact mul_nonpos_of_nonpos_of_nonneg ε₀.le (le_of_lt hz) · simp_rw [g, ← ofReal_mul, ← ofReal_exp, coe_smul] have h₀ : Tendsto (fun x : ℝ => expR (ε * x)) atTop (𝓝 0) := Real.tendsto_exp_atBot.comp (tendsto_const_nhds.neg_mul_atTop ε₀ tendsto_id) exact h₀.zero_smul_isBoundedUnder_le hre · rw [hgn, re_ofReal_mul, I_re, mul_zero, mul_zero, Real.exp_zero, one_mul] exact him y /-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f : ℂ → E` be a function such that * `f` is differentiable in the open right half-plane and is continuous on its closure; * `‖f z‖` is bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `‖f z‖` is bounded from above by a constant on the imaginary axis; * `f x`, `x : ℝ`, tends to zero superexponentially fast as `x → ∞`: for any natural `n`, `exp (n * x) * ‖f x‖` tends to zero as `x → ∞`. Then `f` is equal to zero on the closed right half-plane. -/ theorem eq_zero_on_right_half_plane_of_superexponential_decay (hd : DiffContOnCl ℂ f {z | 0 < z.re}) (hexp : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 {z | 0 < z.re}] fun z => expR (B * abs z ^ c)) (hre : SuperpolynomialDecay atTop expR fun x => ‖f x‖) (him : ∃ C, ∀ x : ℝ, ‖f (x * I)‖ ≤ C) : EqOn f 0 {z : ℂ | 0 ≤ z.re} := by rcases him with ⟨C, hC⟩ -- Due to continuity, it suffices to prove the equality on the open right half-plane. suffices ∀ z : ℂ, 0 < z.re → f z = 0 by simpa only [closure_setOf_lt_re] using EqOn.of_subset_closure this hd.continuousOn continuousOn_const subset_closure Subset.rfl -- Consider $g_n(z)=e^{nz}f(z)$. set g : ℕ → ℂ → E := fun (n : ℕ) (z : ℂ) => exp z ^ n • f z have hg : ∀ n z, ‖g n z‖ = expR z.re ^ n * ‖f z‖ := fun n z ↦ by simp only [g, norm_smul, norm_eq_abs, Complex.abs_pow, abs_exp] intro z hz -- Since `e^{nz} → ∞` as `n → ∞`, it suffices to show that each `g_n` is bounded from above by `C` suffices H : ∀ n : ℕ, ‖g n z‖ ≤ C by contrapose! H simp only [hg] exact (((tendsto_pow_atTop_atTop_of_one_lt (Real.one_lt_exp_iff.2 hz)).atTop_mul (norm_pos_iff.2 H) tendsto_const_nhds).eventually (eventually_gt_atTop C)).exists intro n -- This estimate follows from the Phragmen-Lindelöf principle in the right half-plane. refine right_half_plane_of_tendsto_zero_on_real ((differentiable_exp.pow n).diffContOnCl.smul hd) ?_ ?_ (fun y => ?_) hz.le · rcases hexp with ⟨c, hc, B, hO⟩ refine ⟨max c 1, max_lt hc one_lt_two, n + max B 0, .of_norm_left ?_⟩ simp only [hg] refine ((isBigO_refl (fun z : ℂ => expR z.re ^ n) _).mul hO.norm_left).trans (.of_bound 1 ?_) filter_upwards [(eventually_cobounded_le_norm 1).filter_mono inf_le_left] with z hz simp only [← Real.exp_nat_mul, ← Real.exp_add, Real.norm_eq_abs, Real.abs_exp, add_mul, one_mul] gcongr · calc z.re ≤ abs z := re_le_abs _ _ = abs z ^ (1 : ℝ) := (Real.rpow_one _).symm _ ≤ abs z ^ max c 1 := Real.rpow_le_rpow_of_exponent_le hz (le_max_right _ _) exacts [le_max_left _ _, hz, le_max_left _ _] · rw [tendsto_zero_iff_norm_tendsto_zero]; simp only [hg] exact hre n · rw [hg, re_ofReal_mul, I_re, mul_zero, Real.exp_zero, one_pow, one_mul] exact hC y /-- **Phragmen-Lindelöf principle** in the right half-plane. Let `f g : ℂ → E` be functions such that * `f` and `g` are differentiable in the open right half-plane and are continuous on its closure; * `‖f z‖` and `‖g z‖` are bounded from above by `A * exp(B * (abs z) ^ c)` on the open right half-plane for some `c < 2`; * `‖f z‖` and `‖g z‖` are bounded from above by constants on the imaginary axis; * `f x - g x`, `x : ℝ`, tends to zero superexponentially fast as `x → ∞`: for any natural `n`, `exp (n * x) * ‖f x - g x‖` tends to zero as `x → ∞`. Then `f` is equal to `g` on the closed right half-plane. -/ theorem eqOn_right_half_plane_of_superexponential_decay {g : ℂ → E} (hfd : DiffContOnCl ℂ f {z | 0 < z.re}) (hgd : DiffContOnCl ℂ g {z | 0 < z.re}) (hfexp : ∃ c < (2 : ℝ), ∃ B, f =O[cobounded ℂ ⊓ 𝓟 {z | 0 < z.re}] fun z => expR (B * abs z ^ c)) (hgexp : ∃ c < (2 : ℝ), ∃ B, g =O[cobounded ℂ ⊓ 𝓟 {z | 0 < z.re}] fun z => expR (B * abs z ^ c)) (hre : SuperpolynomialDecay atTop expR fun x => ‖f x - g x‖) (hfim : ∃ C, ∀ x : ℝ, ‖f (x * I)‖ ≤ C) (hgim : ∃ C, ∀ x : ℝ, ‖g (x * I)‖ ≤ C) : EqOn f g {z : ℂ | 0 ≤ z.re} := by suffices EqOn (f - g) 0 {z : ℂ | 0 ≤ z.re} by simpa only [EqOn, Pi.sub_apply, Pi.zero_apply, sub_eq_zero] using this refine eq_zero_on_right_half_plane_of_superexponential_decay (hfd.sub hgd) ?_ hre ?_ · exact isBigO_sub_exp_rpow hfexp hgexp · rcases hfim with ⟨Cf, hCf⟩; rcases hgim with ⟨Cg, hCg⟩ exact ⟨Cf + Cg, fun x => norm_sub_le_of_le (hCf x) (hCg x)⟩ end PhragmenLindelof
Analysis\Complex\RealDeriv.lean
/- 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, Yourong Zang -/ import Mathlib.Analysis.Calculus.ContDiff.Basic import Mathlib.Analysis.Calculus.Deriv.Linear import Mathlib.Analysis.Complex.Conformal import Mathlib.Analysis.Calculus.Conformal.NormedSpace /-! # Real differentiability of complex-differentiable functions `HasDerivAt.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`), then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the complex derivative. `DifferentiableAt.conformalAt` states that a real-differentiable function with a nonvanishing differential from the complex plane into an arbitrary complex-normed space is conformal at a point if it's holomorphic at that point. This is a version of Cauchy-Riemann equations. `conformalAt_iff_differentiableAt_or_differentiableAt_comp_conj` proves that a real-differential function with a nonvanishing differential between the complex plane is conformal at a point if and only if it's holomorphic or antiholomorphic at that point. ## TODO * The classical form of Cauchy-Riemann equations * On a connected open set `u`, a function which is `ConformalAt` each point is either holomorphic throughout or antiholomorphic throughout. ## Warning We do NOT require conformal functions to be orientation-preserving in this file. -/ section RealDerivOfComplex /-! ### Differentiability of the restriction to `ℝ` of complex functions -/ open Complex variable {e : ℂ → ℂ} {e' : ℂ} {z : ℝ} /-- If a complex function is differentiable at a real point, then the induced real function is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem HasStrictDerivAt.real_of_complex (h : HasStrictDerivAt e e' z) : HasStrictDerivAt (fun x : ℝ => (e x).re) e'.re z := by have A : HasStrictFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasStrictFDerivAt have B : HasStrictFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ) (ofRealCLM z) := h.hasStrictFDerivAt.restrictScalars ℝ have C : HasStrictFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasStrictFDerivAt -- Porting note: this should be by: -- simpa using (C.comp z (B.comp z A)).hasStrictDerivAt -- but for some reason simp can not use `ContinuousLinearMap.comp_apply` convert (C.comp z (B.comp z A)).hasStrictDerivAt rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply] simp /-- If a complex function `e` is differentiable at a real point, then the function `ℝ → ℝ` given by the real part of `e` is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem HasDerivAt.real_of_complex (h : HasDerivAt e e' z) : HasDerivAt (fun x : ℝ => (e x).re) e'.re z := by have A : HasFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasFDerivAt have B : HasFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ) (ofRealCLM z) := h.hasFDerivAt.restrictScalars ℝ have C : HasFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasFDerivAt -- Porting note: this should be by: -- simpa using (C.comp z (B.comp z A)).hasStrictDerivAt -- but for some reason simp can not use `ContinuousLinearMap.comp_apply` convert (C.comp z (B.comp z A)).hasDerivAt rw [ContinuousLinearMap.comp_apply, ContinuousLinearMap.comp_apply] simp theorem ContDiffAt.real_of_complex {n : ℕ∞} (h : ContDiffAt ℂ n e z) : ContDiffAt ℝ n (fun x : ℝ => (e x).re) z := by have A : ContDiffAt ℝ n ((↑) : ℝ → ℂ) z := ofRealCLM.contDiff.contDiffAt have B : ContDiffAt ℝ n e z := h.restrict_scalars ℝ have C : ContDiffAt ℝ n re (e z) := reCLM.contDiff.contDiffAt exact C.comp z (B.comp z A) theorem ContDiff.real_of_complex {n : ℕ∞} (h : ContDiff ℂ n e) : ContDiff ℝ n fun x : ℝ => (e x).re := contDiff_iff_contDiffAt.2 fun _ => h.contDiffAt.real_of_complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] theorem HasStrictDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasStrictDerivAt f f' x) : HasStrictFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasStrictFDerivAt.restrictScalars ℝ theorem HasDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasDerivAt f f' x) : HasFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivAt.restrictScalars ℝ theorem HasDerivWithinAt.complexToReal_fderiv' {f : ℂ → E} {s : Set ℂ} {x : ℂ} {f' : E} (h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (reCLM.smulRight f' + I • imCLM.smulRight f') s x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivWithinAt.restrictScalars ℝ theorem HasStrictDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasStrictDerivAt f f' x) : HasStrictFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by simpa only [Complex.restrictScalars_one_smulRight] using h.hasStrictFDerivAt.restrictScalars ℝ theorem HasDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasDerivAt f f' x) : HasFDerivAt f (f' • (1 : ℂ →L[ℝ] ℂ)) x := by simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivAt.restrictScalars ℝ theorem HasDerivWithinAt.complexToReal_fderiv {f : ℂ → ℂ} {s : Set ℂ} {f' x : ℂ} (h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (f' • (1 : ℂ →L[ℝ] ℂ)) s x := by simpa only [Complex.restrictScalars_one_smulRight] using h.hasFDerivWithinAt.restrictScalars ℝ /-- If a complex function `e` is differentiable at a real point, then its restriction to `ℝ` is differentiable there as a function `ℝ → ℂ`, with the same derivative. -/ theorem HasDerivAt.comp_ofReal (hf : HasDerivAt e e' ↑z) : HasDerivAt (fun y : ℝ => e ↑y) e' z := by simpa only [ofRealCLM_apply, ofReal_one, mul_one] using hf.comp z ofRealCLM.hasDerivAt /-- If a function `f : ℝ → ℝ` is differentiable at a (real) point `x`, then it is also differentiable as a function `ℝ → ℂ`. -/ theorem HasDerivAt.ofReal_comp {f : ℝ → ℝ} {u : ℝ} (hf : HasDerivAt f u z) : HasDerivAt (fun y : ℝ => ↑(f y) : ℝ → ℂ) u z := by simpa only [ofRealCLM_apply, ofReal_one, real_smul, mul_one] using ofRealCLM.hasDerivAt.scomp z hf end RealDerivOfComplex section Conformality /-! ### Conformality of real-differentiable complex maps -/ open Complex ContinuousLinearMap open scoped ComplexConjugate variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {z : ℂ} {f : ℂ → E} /-- A real differentiable function of the complex plane into some complex normed space `E` is conformal at a point `z` if it is holomorphic at that point with a nonvanishing differential. This is a version of the Cauchy-Riemann equations. -/ theorem DifferentiableAt.conformalAt (h : DifferentiableAt ℂ f z) (hf' : deriv f z ≠ 0) : ConformalAt f z := by rw [conformalAt_iff_isConformalMap_fderiv, (h.hasFDerivAt.restrictScalars ℝ).fderiv] apply isConformalMap_complex_linear simpa only [Ne, ContinuousLinearMap.ext_ring_iff] /-- A complex function is conformal if and only if the function is holomorphic or antiholomorphic with a nonvanishing differential. -/ theorem conformalAt_iff_differentiableAt_or_differentiableAt_comp_conj {f : ℂ → ℂ} {z : ℂ} : ConformalAt f z ↔ (DifferentiableAt ℂ f z ∨ DifferentiableAt ℂ (f ∘ conj) (conj z)) ∧ fderiv ℝ f z ≠ 0 := by rw [conformalAt_iff_isConformalMap_fderiv] rw [isConformalMap_iff_is_complex_or_conj_linear] apply and_congr_left intro h have h_diff := h.imp_symm fderiv_zero_of_not_differentiableAt apply or_congr · rw [differentiableAt_iff_restrictScalars ℝ h_diff] rw [← conj_conj z] at h_diff rw [differentiableAt_iff_restrictScalars ℝ (h_diff.comp _ conjCLE.differentiableAt)] refine exists_congr fun g => rfl.congr ?_ have : fderiv ℝ conj (conj z) = _ := conjCLE.fderiv simp [fderiv.comp _ h_diff conjCLE.differentiableAt, this, conj_conj] end Conformality
Analysis\Complex\ReImTopology.lean
/- 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.Basic import Mathlib.Topology.FiberBundle.IsHomeomorphicTrivialBundle /-! # Closure, interior, and frontier of preimages under `re` and `im` In this fact we use the fact that `ℂ` is naturally homeomorphic to `ℝ × ℝ` to deduce some topological properties of `Complex.re` and `Complex.im`. ## Main statements Each statement about `Complex.re` listed below has a counterpart about `Complex.im`. * `Complex.isHomeomorphicTrivialFiberBundle_re`: `Complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`; * `Complex.isOpenMap_re`, `Complex.quotientMap_re`: in particular, `Complex.re` is an open map and is a quotient map; * `Complex.interior_preimage_re`, `Complex.closure_preimage_re`, `Complex.frontier_preimage_re`: formulas for `interior (Complex.re ⁻¹' s)` etc; * `Complex.interior_setOf_re_le` etc: particular cases of the above formulas in the cases when `s` is one of the infinite intervals `Set.Ioi a`, `Set.Ici a`, `Set.Iio a`, and `Set.Iic a`, formulated as `interior {z : ℂ | z.re ≤ a} = {z | z.re < a}` etc. ## Tags complex, real part, imaginary part, closure, interior, frontier -/ open Set noncomputable section namespace Complex /-- `Complex.re` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/ theorem isHomeomorphicTrivialFiberBundle_re : IsHomeomorphicTrivialFiberBundle ℝ re := ⟨equivRealProdCLM.toHomeomorph, fun _ => rfl⟩ /-- `Complex.im` turns `ℂ` into a trivial topological fiber bundle over `ℝ`. -/ theorem isHomeomorphicTrivialFiberBundle_im : IsHomeomorphicTrivialFiberBundle ℝ im := ⟨equivRealProdCLM.toHomeomorph.trans (Homeomorph.prodComm ℝ ℝ), fun _ => rfl⟩ theorem isOpenMap_re : IsOpenMap re := isHomeomorphicTrivialFiberBundle_re.isOpenMap_proj theorem isOpenMap_im : IsOpenMap im := isHomeomorphicTrivialFiberBundle_im.isOpenMap_proj theorem quotientMap_re : QuotientMap re := isHomeomorphicTrivialFiberBundle_re.quotientMap_proj theorem quotientMap_im : QuotientMap im := isHomeomorphicTrivialFiberBundle_im.quotientMap_proj theorem interior_preimage_re (s : Set ℝ) : interior (re ⁻¹' s) = re ⁻¹' interior s := (isOpenMap_re.preimage_interior_eq_interior_preimage continuous_re _).symm theorem interior_preimage_im (s : Set ℝ) : interior (im ⁻¹' s) = im ⁻¹' interior s := (isOpenMap_im.preimage_interior_eq_interior_preimage continuous_im _).symm theorem closure_preimage_re (s : Set ℝ) : closure (re ⁻¹' s) = re ⁻¹' closure s := (isOpenMap_re.preimage_closure_eq_closure_preimage continuous_re _).symm theorem closure_preimage_im (s : Set ℝ) : closure (im ⁻¹' s) = im ⁻¹' closure s := (isOpenMap_im.preimage_closure_eq_closure_preimage continuous_im _).symm theorem frontier_preimage_re (s : Set ℝ) : frontier (re ⁻¹' s) = re ⁻¹' frontier s := (isOpenMap_re.preimage_frontier_eq_frontier_preimage continuous_re _).symm theorem frontier_preimage_im (s : Set ℝ) : frontier (im ⁻¹' s) = im ⁻¹' frontier s := (isOpenMap_im.preimage_frontier_eq_frontier_preimage continuous_im _).symm @[simp] theorem interior_setOf_re_le (a : ℝ) : interior { z : ℂ | z.re ≤ a } = { z | z.re < a } := by simpa only [interior_Iic] using interior_preimage_re (Iic a) @[simp] theorem interior_setOf_im_le (a : ℝ) : interior { z : ℂ | z.im ≤ a } = { z | z.im < a } := by simpa only [interior_Iic] using interior_preimage_im (Iic a) @[simp] theorem interior_setOf_le_re (a : ℝ) : interior { z : ℂ | a ≤ z.re } = { z | a < z.re } := by simpa only [interior_Ici] using interior_preimage_re (Ici a) @[simp] theorem interior_setOf_le_im (a : ℝ) : interior { z : ℂ | a ≤ z.im } = { z | a < z.im } := by simpa only [interior_Ici] using interior_preimage_im (Ici a) @[simp] theorem closure_setOf_re_lt (a : ℝ) : closure { z : ℂ | z.re < a } = { z | z.re ≤ a } := by simpa only [closure_Iio] using closure_preimage_re (Iio a) @[simp] theorem closure_setOf_im_lt (a : ℝ) : closure { z : ℂ | z.im < a } = { z | z.im ≤ a } := by simpa only [closure_Iio] using closure_preimage_im (Iio a) @[simp] theorem closure_setOf_lt_re (a : ℝ) : closure { z : ℂ | a < z.re } = { z | a ≤ z.re } := by simpa only [closure_Ioi] using closure_preimage_re (Ioi a) @[simp] theorem closure_setOf_lt_im (a : ℝ) : closure { z : ℂ | a < z.im } = { z | a ≤ z.im } := by simpa only [closure_Ioi] using closure_preimage_im (Ioi a) @[simp] theorem frontier_setOf_re_le (a : ℝ) : frontier { z : ℂ | z.re ≤ a } = { z | z.re = a } := by simpa only [frontier_Iic] using frontier_preimage_re (Iic a) @[simp] theorem frontier_setOf_im_le (a : ℝ) : frontier { z : ℂ | z.im ≤ a } = { z | z.im = a } := by simpa only [frontier_Iic] using frontier_preimage_im (Iic a) @[simp] theorem frontier_setOf_le_re (a : ℝ) : frontier { z : ℂ | a ≤ z.re } = { z | z.re = a } := by simpa only [frontier_Ici] using frontier_preimage_re (Ici a) @[simp] theorem frontier_setOf_le_im (a : ℝ) : frontier { z : ℂ | a ≤ z.im } = { z | z.im = a } := by simpa only [frontier_Ici] using frontier_preimage_im (Ici a) @[simp] theorem frontier_setOf_re_lt (a : ℝ) : frontier { z : ℂ | z.re < a } = { z | z.re = a } := by simpa only [frontier_Iio] using frontier_preimage_re (Iio a) @[simp] theorem frontier_setOf_im_lt (a : ℝ) : frontier { z : ℂ | z.im < a } = { z | z.im = a } := by simpa only [frontier_Iio] using frontier_preimage_im (Iio a) @[simp] theorem frontier_setOf_lt_re (a : ℝ) : frontier { z : ℂ | a < z.re } = { z | z.re = a } := by simpa only [frontier_Ioi] using frontier_preimage_re (Ioi a) @[simp] theorem frontier_setOf_lt_im (a : ℝ) : frontier { z : ℂ | a < z.im } = { z | z.im = a } := by simpa only [frontier_Ioi] using frontier_preimage_im (Ioi a) theorem closure_reProdIm (s t : Set ℝ) : closure (s ×ℂ t) = closure s ×ℂ closure t := by simpa only [← preimage_eq_preimage equivRealProdCLM.symm.toHomeomorph.surjective, equivRealProdCLM.symm.toHomeomorph.preimage_closure] using @closure_prod_eq _ _ _ _ s t theorem interior_reProdIm (s t : Set ℝ) : interior (s ×ℂ t) = interior s ×ℂ interior t := by rw [Set.reProdIm, Set.reProdIm, interior_inter, interior_preimage_re, interior_preimage_im] theorem frontier_reProdIm (s t : Set ℝ) : frontier (s ×ℂ t) = closure s ×ℂ frontier t ∪ frontier s ×ℂ closure t := by simpa only [← preimage_eq_preimage equivRealProdCLM.symm.toHomeomorph.surjective, equivRealProdCLM.symm.toHomeomorph.preimage_frontier] using frontier_prod_eq s t theorem frontier_setOf_le_re_and_le_im (a b : ℝ) : frontier { z | a ≤ re z ∧ b ≤ im z } = { z | a ≤ re z ∧ im z = b ∨ re z = a ∧ b ≤ im z } := by simpa only [closure_Ici, frontier_Ici] using frontier_reProdIm (Ici a) (Ici b) theorem frontier_setOf_le_re_and_im_le (a b : ℝ) : frontier { z | a ≤ re z ∧ im z ≤ b } = { z | a ≤ re z ∧ im z = b ∨ re z = a ∧ im z ≤ b } := by simpa only [closure_Ici, closure_Iic, frontier_Ici, frontier_Iic] using frontier_reProdIm (Ici a) (Iic b) end Complex open Complex Metric variable {s t : Set ℝ} theorem IsOpen.reProdIm (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ×ℂ t) := (hs.preimage continuous_re).inter (ht.preimage continuous_im) theorem IsClosed.reProdIm (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s ×ℂ t) := (hs.preimage continuous_re).inter (ht.preimage continuous_im) theorem Bornology.IsBounded.reProdIm (hs : IsBounded s) (ht : IsBounded t) : IsBounded (s ×ℂ t) := antilipschitz_equivRealProd.isBounded_preimage (hs.prod ht)
Analysis\Complex\RemovableSingularity.lean
/- 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.Calculus.FDeriv.Analytic import Mathlib.Analysis.Asymptotics.SpecificAsymptotics import Mathlib.Analysis.Complex.CauchyIntegral /-! # Removable singularity theorem In this file we prove Riemann's removable singularity theorem: if `f : ℂ → E` is complex differentiable in a punctured neighborhood of a point `c` and is bounded in a punctured neighborhood of `c` (or, more generally, $f(z) - f(c)=o((z-c)^{-1})$), then it has a limit at `c` and the function `update f c (limUnder (𝓝[≠] c) f)` is complex differentiable in a neighborhood of `c`. -/ open TopologicalSpace Metric Set Filter Asymptotics Function open scoped Topology Filter NNReal Real universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] namespace Complex /-- **Removable singularity** theorem, weak version. If `f : ℂ → E` is differentiable in a punctured neighborhood of a point and is continuous at this point, then it is analytic at this point. -/ theorem analyticAt_of_differentiable_on_punctured_nhds_of_continuousAt {f : ℂ → E} {c : ℂ} (hd : ∀ᶠ z in 𝓝[≠] c, DifferentiableAt ℂ f z) (hc : ContinuousAt f c) : AnalyticAt ℂ f c := by rcases (nhdsWithin_hasBasis nhds_basis_closedBall _).mem_iff.1 hd with ⟨R, hR0, hRs⟩ lift R to ℝ≥0 using hR0.le replace hc : ContinuousOn f (closedBall c R) := by refine fun z hz => ContinuousAt.continuousWithinAt ?_ rcases eq_or_ne z c with (rfl | hne) exacts [hc, (hRs ⟨hz, hne⟩).continuousAt] exact (hasFPowerSeriesOnBall_of_differentiable_off_countable (countable_singleton c) hc (fun z hz => hRs (diff_subset_diff_left ball_subset_closedBall hz)) hR0).analyticAt theorem differentiableOn_compl_singleton_and_continuousAt_iff {f : ℂ → E} {s : Set ℂ} {c : ℂ} (hs : s ∈ 𝓝 c) : DifferentiableOn ℂ f (s \ {c}) ∧ ContinuousAt f c ↔ DifferentiableOn ℂ f s := by refine ⟨?_, fun hd => ⟨hd.mono diff_subset, (hd.differentiableAt hs).continuousAt⟩⟩ rintro ⟨hd, hc⟩ x hx rcases eq_or_ne x c with (rfl | hne) · refine (analyticAt_of_differentiable_on_punctured_nhds_of_continuousAt ?_ hc).differentiableAt.differentiableWithinAt refine eventually_nhdsWithin_iff.2 ((eventually_mem_nhds.2 hs).mono fun z hz hzx => ?_) exact hd.differentiableAt (inter_mem hz (isOpen_ne.mem_nhds hzx)) · simpa only [DifferentiableWithinAt, HasFDerivWithinAt, hne.nhdsWithin_diff_singleton] using hd x ⟨hx, hne⟩ theorem differentiableOn_dslope {f : ℂ → E} {s : Set ℂ} {c : ℂ} (hc : s ∈ 𝓝 c) : DifferentiableOn ℂ (dslope f c) s ↔ DifferentiableOn ℂ f s := ⟨fun h => h.of_dslope, fun h => (differentiableOn_compl_singleton_and_continuousAt_iff hc).mp <| ⟨Iff.mpr (differentiableOn_dslope_of_nmem fun h => h.2 rfl) (h.mono diff_subset), continuousAt_dslope_same.2 <| h.differentiableAt hc⟩⟩ /-- **Removable singularity** theorem: if `s` is a neighborhood of `c : ℂ`, a function `f : ℂ → E` is complex differentiable on `s \ {c}`, and $f(z) - f(c)=o((z-c)^{-1})$, then `f` redefined to be equal to `limUnder (𝓝[≠] c) f` at `c` is complex differentiable on `s`. -/ theorem differentiableOn_update_limUnder_of_isLittleO {f : ℂ → E} {s : Set ℂ} {c : ℂ} (hc : s ∈ 𝓝 c) (hd : DifferentiableOn ℂ f (s \ {c})) (ho : (fun z => f z - f c) =o[𝓝[≠] c] fun z => (z - c)⁻¹) : DifferentiableOn ℂ (update f c (limUnder (𝓝[≠] c) f)) s := by set F : ℂ → E := fun z => (z - c) • f z suffices DifferentiableOn ℂ F (s \ {c}) ∧ ContinuousAt F c by rw [differentiableOn_compl_singleton_and_continuousAt_iff hc, ← differentiableOn_dslope hc, dslope_sub_smul] at this have hc : Tendsto f (𝓝[≠] c) (𝓝 (deriv F c)) := continuousAt_update_same.mp (this.continuousOn.continuousAt hc) rwa [hc.limUnder_eq] refine ⟨(differentiableOn_id.sub_const _).smul hd, ?_⟩ rw [← continuousWithinAt_compl_self] have H := ho.tendsto_inv_smul_nhds_zero have H' : Tendsto (fun z => (z - c) • f c) (𝓝[≠] c) (𝓝 (F c)) := (continuousWithinAt_id.tendsto.sub tendsto_const_nhds).smul tendsto_const_nhds simpa [← smul_add, ContinuousWithinAt] using H.add H' /-- **Removable singularity** theorem: if `s` is a punctured neighborhood of `c : ℂ`, a function `f : ℂ → E` is complex differentiable on `s`, and $f(z) - f(c)=o((z-c)^{-1})$, then `f` redefined to be equal to `limUnder (𝓝[≠] c) f` at `c` is complex differentiable on `{c} ∪ s`. -/ theorem differentiableOn_update_limUnder_insert_of_isLittleO {f : ℂ → E} {s : Set ℂ} {c : ℂ} (hc : s ∈ 𝓝[≠] c) (hd : DifferentiableOn ℂ f s) (ho : (fun z => f z - f c) =o[𝓝[≠] c] fun z => (z - c)⁻¹) : DifferentiableOn ℂ (update f c (limUnder (𝓝[≠] c) f)) (insert c s) := differentiableOn_update_limUnder_of_isLittleO (insert_mem_nhds_iff.2 hc) (hd.mono fun _ hz => hz.1.resolve_left hz.2) ho /-- **Removable singularity** theorem: if `s` is a neighborhood of `c : ℂ`, a function `f : ℂ → E` is complex differentiable and is bounded on `s \ {c}`, then `f` redefined to be equal to `limUnder (𝓝[≠] c) f` at `c` is complex differentiable on `s`. -/ theorem differentiableOn_update_limUnder_of_bddAbove {f : ℂ → E} {s : Set ℂ} {c : ℂ} (hc : s ∈ 𝓝 c) (hd : DifferentiableOn ℂ f (s \ {c})) (hb : BddAbove (norm ∘ f '' (s \ {c}))) : DifferentiableOn ℂ (update f c (limUnder (𝓝[≠] c) f)) s := differentiableOn_update_limUnder_of_isLittleO hc hd <| IsBoundedUnder.isLittleO_sub_self_inv <| let ⟨C, hC⟩ := hb ⟨C + ‖f c‖, eventually_map.2 <| mem_nhdsWithin_iff_exists_mem_nhds_inter.2 ⟨s, hc, fun _ hz => norm_sub_le_of_le (hC <| mem_image_of_mem _ hz) le_rfl⟩⟩ /-- **Removable singularity** theorem: if a function `f : ℂ → E` is complex differentiable on a punctured neighborhood of `c` and $f(z) - f(c)=o((z-c)^{-1})$, then `f` has a limit at `c`. -/ theorem tendsto_limUnder_of_differentiable_on_punctured_nhds_of_isLittleO {f : ℂ → E} {c : ℂ} (hd : ∀ᶠ z in 𝓝[≠] c, DifferentiableAt ℂ f z) (ho : (fun z => f z - f c) =o[𝓝[≠] c] fun z => (z - c)⁻¹) : Tendsto f (𝓝[≠] c) (𝓝 <| limUnder (𝓝[≠] c) f) := by rw [eventually_nhdsWithin_iff] at hd have : DifferentiableOn ℂ f ({z | z ≠ c → DifferentiableAt ℂ f z} \ {c}) := fun z hz => (hz.1 hz.2).differentiableWithinAt have H := differentiableOn_update_limUnder_of_isLittleO hd this ho exact continuousAt_update_same.1 (H.differentiableAt hd).continuousAt /-- **Removable singularity** theorem: if a function `f : ℂ → E` is complex differentiable and bounded on a punctured neighborhood of `c`, then `f` has a limit at `c`. -/ theorem tendsto_limUnder_of_differentiable_on_punctured_nhds_of_bounded_under {f : ℂ → E} {c : ℂ} (hd : ∀ᶠ z in 𝓝[≠] c, DifferentiableAt ℂ f z) (hb : IsBoundedUnder (· ≤ ·) (𝓝[≠] c) fun z => ‖f z - f c‖) : Tendsto f (𝓝[≠] c) (𝓝 <| limUnder (𝓝[≠] c) f) := tendsto_limUnder_of_differentiable_on_punctured_nhds_of_isLittleO hd hb.isLittleO_sub_self_inv /-- The Cauchy formula for the derivative of a holomorphic function. -/ theorem two_pi_I_inv_smul_circleIntegral_sub_sq_inv_smul_of_differentiable {U : Set ℂ} (hU : IsOpen U) {c w₀ : ℂ} {R : ℝ} {f : ℂ → E} (hc : closedBall c R ⊆ U) (hf : DifferentiableOn ℂ f U) (hw₀ : w₀ ∈ ball c R) : ((2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), ((z - w₀) ^ 2)⁻¹ • f z) = deriv f w₀ := by -- We apply the removable singularity theorem and the Cauchy formula to `dslope f w₀` have hf' : DifferentiableOn ℂ (dslope f w₀) U := (differentiableOn_dslope (hU.mem_nhds ((ball_subset_closedBall.trans hc) hw₀))).mpr hf have h0 := (hf'.diffContOnCl_ball hc).two_pi_i_inv_smul_circleIntegral_sub_inv_smul hw₀ rw [← dslope_same, ← h0] congr 1 trans ∮ z in C(c, R), ((z - w₀) ^ 2)⁻¹ • (f z - f w₀) · have h1 : ContinuousOn (fun z : ℂ => ((z - w₀) ^ 2)⁻¹) (sphere c R) := by refine ((continuous_id'.sub continuous_const).pow 2).continuousOn.inv₀ fun w hw h => ?_ exact sphere_disjoint_ball.ne_of_mem hw hw₀ (sub_eq_zero.mp (sq_eq_zero_iff.mp h)) have h2 : CircleIntegrable (fun z : ℂ => ((z - w₀) ^ 2)⁻¹ • f z) c R := by refine ContinuousOn.circleIntegrable (pos_of_mem_ball hw₀).le ?_ exact h1.smul (hf.continuousOn.mono (sphere_subset_closedBall.trans hc)) have h3 : CircleIntegrable (fun z : ℂ => ((z - w₀) ^ 2)⁻¹ • f w₀) c R := ContinuousOn.circleIntegrable (pos_of_mem_ball hw₀).le (h1.smul continuousOn_const) have h4 : (∮ z : ℂ in C(c, R), ((z - w₀) ^ 2)⁻¹) = 0 := by simpa using circleIntegral.integral_sub_zpow_of_ne (by decide : (-2 : ℤ) ≠ -1) c w₀ R simp only [smul_sub, circleIntegral.integral_sub h2 h3, h4, circleIntegral.integral_smul_const, zero_smul, sub_zero] · refine circleIntegral.integral_congr (pos_of_mem_ball hw₀).le fun z hz => ?_ simp only [dslope_of_ne, Metric.sphere_disjoint_ball.ne_of_mem hz hw₀, slope, ← smul_assoc, sq, mul_inv, Ne, not_false_iff, vsub_eq_sub, Algebra.id.smul_eq_mul] end Complex
Analysis\Complex\Schwarz.lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.AbsMax import Mathlib.Analysis.Complex.RemovableSingularity /-! # Schwarz lemma In this file we prove several versions of the Schwarz lemma. * `Complex.norm_deriv_le_div_of_mapsTo_ball`, `Complex.abs_deriv_le_div_of_mapsTo_ball`: if `f : ℂ → E` sends an open disk with center `c` and a positive radius `R₁` to an open ball with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`; * `Complex.dist_le_div_mul_dist_of_mapsTo_ball`: if `f : ℂ → E` sends an open disk with center `c` and radius `R₁` to an open disk with center `f c` and radius `R₂`, then for any `z` in the former disk we have `dist (f z) (f c) ≤ (R₂ / R₁) * dist z c`; * `Complex.abs_deriv_le_one_of_mapsTo_ball`: if `f : ℂ → ℂ` sends an open disk of positive radius to itself and the center of this disk to itself, then the absolute value of the derivative of `f` at the center of this disk is at most `1`; * `Complex.dist_le_dist_of_mapsTo_ball_self`: if `f : ℂ → ℂ` sends an open disk to itself and the center `c` of this disk to itself, then for any point `z` of this disk we have `dist (f z) c ≤ dist z c`; * `Complex.abs_le_abs_of_mapsTo_ball_self`: if `f : ℂ → ℂ` sends an open disk with center `0` to itself, then for any point `z` of this disk we have `abs (f z) ≤ abs z`. ## Implementation notes We prove some versions of the Schwarz lemma for a map `f : ℂ → E` taking values in any normed space over complex numbers. ## TODO * Prove that these inequalities are strict unless `f` is an affine map. * Prove that any diffeomorphism of the unit disk to itself is a Möbius map. ## Tags Schwarz lemma -/ open Metric Set Function Filter TopologicalSpace open scoped Topology namespace Complex section Space variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {R R₁ R₂ : ℝ} {f : ℂ → E} {c z z₀ : ℂ} /-- An auxiliary lemma for `Complex.norm_dslope_le_div_of_mapsTo_ball`. -/ theorem schwarz_aux {f : ℂ → ℂ} (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : MapsTo f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : ‖dslope f c z‖ ≤ R₂ / R₁ := by have hR₁ : 0 < R₁ := nonempty_ball.1 ⟨z, hz⟩ suffices ∀ᶠ r in 𝓝[<] R₁, ‖dslope f c z‖ ≤ R₂ / r by refine ge_of_tendsto ?_ this exact (tendsto_const_nhds.div tendsto_id hR₁.ne').mono_left nhdsWithin_le_nhds rw [mem_ball] at hz filter_upwards [Ioo_mem_nhdsWithin_Iio ⟨hz, le_rfl⟩] with r hr have hr₀ : 0 < r := dist_nonneg.trans_lt hr.1 replace hd : DiffContOnCl ℂ (dslope f c) (ball c r) := by refine DifferentiableOn.diffContOnCl ?_ rw [closure_ball c hr₀.ne'] exact ((differentiableOn_dslope <| ball_mem_nhds _ hR₁).mpr hd).mono (closedBall_subset_ball hr.2) refine norm_le_of_forall_mem_frontier_norm_le isBounded_ball hd ?_ ?_ · rw [frontier_ball c hr₀.ne'] intro z hz have hz' : z ≠ c := ne_of_mem_sphere hz hr₀.ne' rw [dslope_of_ne _ hz', slope_def_module, norm_smul, norm_inv, mem_sphere_iff_norm.1 hz, ← div_eq_inv_mul, div_le_div_right hr₀, ← dist_eq_norm] exact le_of_lt (h_maps (mem_ball.2 (by rw [mem_sphere.1 hz]; exact hr.2))) · rw [closure_ball c hr₀.ne', mem_closedBall] exact hr.1.le /-- Two cases of the **Schwarz Lemma** (derivative and distance), merged together. -/ theorem norm_dslope_le_div_of_mapsTo_ball (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : MapsTo f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : ‖dslope f c z‖ ≤ R₂ / R₁ := by have hR₁ : 0 < R₁ := nonempty_ball.1 ⟨z, hz⟩ have hR₂ : 0 < R₂ := nonempty_ball.1 ⟨f z, h_maps hz⟩ rcases eq_or_ne (dslope f c z) 0 with hc | hc · rw [hc, norm_zero]; exact div_nonneg hR₂.le hR₁.le rcases exists_dual_vector ℂ _ hc with ⟨g, hg, hgf⟩ have hg' : ‖g‖₊ = 1 := NNReal.eq hg have hg₀ : ‖g‖₊ ≠ 0 := by simpa only [hg'] using one_ne_zero calc ‖dslope f c z‖ = ‖dslope (g ∘ f) c z‖ := by rw [g.dslope_comp, hgf, RCLike.norm_ofReal, abs_norm] exact fun _ => hd.differentiableAt (ball_mem_nhds _ hR₁) _ ≤ R₂ / R₁ := by refine schwarz_aux (g.differentiable.comp_differentiableOn hd) (MapsTo.comp ?_ h_maps) hz simpa only [hg', NNReal.coe_one, one_mul] using g.lipschitz.mapsTo_ball hg₀ (f c) R₂ /-- Equality case in the **Schwarz Lemma**: in the setup of `norm_dslope_le_div_of_mapsTo_ball`, if `‖dslope f c z₀‖ = R₂ / R₁` holds at a point in the ball then the map `f` is affine. -/ theorem affine_of_mapsTo_ball_of_exists_norm_dslope_eq_div [CompleteSpace E] [StrictConvexSpace ℝ E] (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : Set.MapsTo f (ball c R₁) (ball (f c) R₂)) (h_z₀ : z₀ ∈ ball c R₁) (h_eq : ‖dslope f c z₀‖ = R₂ / R₁) : Set.EqOn f (fun z => f c + (z - c) • dslope f c z₀) (ball c R₁) := by set g := dslope f c rintro z hz by_cases h : z = c; · simp [h] have h_R₁ : 0 < R₁ := nonempty_ball.mp ⟨_, h_z₀⟩ have g_le_div : ∀ z ∈ ball c R₁, ‖g z‖ ≤ R₂ / R₁ := fun z hz => norm_dslope_le_div_of_mapsTo_ball hd h_maps hz have g_max : IsMaxOn (norm ∘ g) (ball c R₁) z₀ := isMaxOn_iff.mpr fun z hz => by simpa [h_eq] using g_le_div z hz have g_diff : DifferentiableOn ℂ g (ball c R₁) := (differentiableOn_dslope (isOpen_ball.mem_nhds (mem_ball_self h_R₁))).mpr hd have : g z = g z₀ := eqOn_of_isPreconnected_of_isMaxOn_norm (convex_ball c R₁).isPreconnected isOpen_ball g_diff h_z₀ g_max hz simp only [g] at this simp [g, ← this] theorem affine_of_mapsTo_ball_of_exists_norm_dslope_eq_div' [CompleteSpace E] [StrictConvexSpace ℝ E] (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : Set.MapsTo f (ball c R₁) (ball (f c) R₂)) (h_z₀ : ∃ z₀ ∈ ball c R₁, ‖dslope f c z₀‖ = R₂ / R₁) : ∃ C : E, ‖C‖ = R₂ / R₁ ∧ Set.EqOn f (fun z => f c + (z - c) • C) (ball c R₁) := let ⟨z₀, h_z₀, h_eq⟩ := h_z₀ ⟨dslope f c z₀, h_eq, affine_of_mapsTo_ball_of_exists_norm_dslope_eq_div hd h_maps h_z₀ h_eq⟩ /-- The **Schwarz Lemma**: if `f : ℂ → E` sends an open disk with center `c` and a positive radius `R₁` to an open ball with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`. -/ theorem norm_deriv_le_div_of_mapsTo_ball (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : MapsTo f (ball c R₁) (ball (f c) R₂)) (h₀ : 0 < R₁) : ‖deriv f c‖ ≤ R₂ / R₁ := by simpa only [dslope_same] using norm_dslope_le_div_of_mapsTo_ball hd h_maps (mem_ball_self h₀) /-- The **Schwarz Lemma**: if `f : ℂ → E` sends an open disk with center `c` and radius `R₁` to an open ball with center `f c` and radius `R₂`, then for any `z` in the former disk we have `dist (f z) (f c) ≤ (R₂ / R₁) * dist z c`. -/ theorem dist_le_div_mul_dist_of_mapsTo_ball (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : MapsTo f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : dist (f z) (f c) ≤ R₂ / R₁ * dist z c := by rcases eq_or_ne z c with (rfl | hne) · simp only [dist_self, mul_zero, le_rfl] simpa only [dslope_of_ne _ hne, slope_def_module, norm_smul, norm_inv, ← div_eq_inv_mul, ← dist_eq_norm, div_le_iff (dist_pos.2 hne)] using norm_dslope_le_div_of_mapsTo_ball hd h_maps hz end Space variable {f : ℂ → ℂ} {c z : ℂ} {R R₁ R₂ : ℝ} /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk with center `c` and a positive radius `R₁` to an open disk with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`. -/ theorem abs_deriv_le_div_of_mapsTo_ball (hd : DifferentiableOn ℂ f (ball c R₁)) (h_maps : MapsTo f (ball c R₁) (ball (f c) R₂)) (h₀ : 0 < R₁) : abs (deriv f c) ≤ R₂ / R₁ := norm_deriv_le_div_of_mapsTo_ball hd h_maps h₀ /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk of positive radius to itself and the center of this disk to itself, then the absolute value of the derivative of `f` at the center of this disk is at most `1`. -/ theorem abs_deriv_le_one_of_mapsTo_ball (hd : DifferentiableOn ℂ f (ball c R)) (h_maps : MapsTo f (ball c R) (ball c R)) (hc : f c = c) (h₀ : 0 < R) : abs (deriv f c) ≤ 1 := (norm_deriv_le_div_of_mapsTo_ball hd (by rwa [hc]) h₀).trans_eq (div_self h₀.ne') /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk to itself and the center `c` of this disk to itself, then for any point `z` of this disk we have `dist (f z) c ≤ dist z c`. -/ theorem dist_le_dist_of_mapsTo_ball_self (hd : DifferentiableOn ℂ f (ball c R)) (h_maps : MapsTo f (ball c R) (ball c R)) (hc : f c = c) (hz : z ∈ ball c R) : dist (f z) c ≤ dist z c := by -- Porting note: `simp` was failing to use `div_self` have := dist_le_div_mul_dist_of_mapsTo_ball hd (by rwa [hc]) hz rwa [hc, div_self, one_mul] at this exact (nonempty_ball.1 ⟨z, hz⟩).ne' /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk with center `0` to itself, then for any point `z` of this disk we have `abs (f z) ≤ abs z`. -/ theorem abs_le_abs_of_mapsTo_ball_self (hd : DifferentiableOn ℂ f (ball 0 R)) (h_maps : MapsTo f (ball 0 R) (ball 0 R)) (h₀ : f 0 = 0) (hz : abs z < R) : abs (f z) ≤ abs z := by replace hz : z ∈ ball (0 : ℂ) R := mem_ball_zero_iff.2 hz simpa only [dist_zero_right] using dist_le_dist_of_mapsTo_ball_self hd h_maps h₀ hz end Complex
Analysis\Complex\TaylorSeries.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Complex.CauchyIntegral /-! # Convergence of Taylor series of holomorphic functions We show that the Taylor series around some point `c : ℂ` of a function `f` that is complex differentiable on the open ball of radius `r` around `c` converges to `f` on that open ball; see `Complex.hasSum_taylorSeries_on_ball` and `Complex.taylorSeries_eq_on_ball` for versions (in terms of `HasSum` and `tsum`, repsectively) for functions to a complete normed space over `ℂ`, and `Complex.taylorSeries_eq_on_ball'` for a variant when `f : ℂ → ℂ`. There are corresponding statements for `EMEtric.ball`s; see `Complex.hasSum_taylorSeries_on_emetric_ball`, `Complex.taylorSeries_eq_on_emetric_ball` and `Complex.taylorSeries_eq_on_ball'`. We also show that the Taylor series around some point `c : ℂ` of a function `f` that is complex differentiable on all of `ℂ` converges to `f` on `ℂ`; see `Complex.hasSum_taylorSeries_of_entire`, `Complex.taylorSeries_eq_of_entire` and `Complex.taylorSeries_eq_of_entire'`. -/ namespace Complex open Nat variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] [CompleteSpace E] ⦃f : ℂ → E⦄ section ball variable ⦃c : ℂ⦄ ⦃r : ℝ⦄ (hf : DifferentiableOn ℂ f (Metric.ball c r)) variable ⦃z : ℂ⦄ (hz : z ∈ Metric.ball c r) /-- A function that is complex differentiable on the open ball of radius `r` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma hasSum_taylorSeries_on_ball : HasSum (fun n : ℕ ↦ (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c) (f z) := by obtain ⟨r', hr', hr'₀, hzr'⟩ : ∃ r' < r, 0 < r' ∧ z ∈ Metric.ball c r' := by obtain ⟨r', h₁, h₂⟩ := exists_between (Metric.mem_ball'.mp hz) exact ⟨r', h₂, Metric.pos_of_mem_ball h₁, Metric.mem_ball'.mpr h₁⟩ lift r' to NNReal using hr'₀.le have hz' : z - c ∈ EMetric.ball 0 r' := by rw [Metric.emetric_ball_nnreal] exact mem_ball_zero_iff.mpr hzr' have H := (hf.mono <| Metric.closedBall_subset_ball hr').hasFPowerSeriesOnBall hr'₀ |>.hasSum_iteratedFDeriv hz' simp only [add_sub_cancel] at H convert H using 4 with n simpa only [iteratedDeriv_eq_iteratedFDeriv, smul_eq_mul, mul_one, Finset.prod_const, Finset.card_fin] using ((iteratedFDeriv ℂ n f c).map_smul_univ (fun _ ↦ z - c) (fun _ ↦ 1)).symm /-- A function that is complex differentiable on the open ball of radius `r` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma taylorSeries_eq_on_ball : ∑' n : ℕ, (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c = f z := (hasSum_taylorSeries_on_ball hf hz).tsum_eq /-- A function that is complex differentiable on the open ball of radius `r` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma taylorSeries_eq_on_ball' {f : ℂ → ℂ} (hf : DifferentiableOn ℂ f (Metric.ball c r)) : ∑' n : ℕ, (n ! : ℂ)⁻¹ * iteratedDeriv n f c * (z - c) ^ n = f z := by convert taylorSeries_eq_on_ball hf hz using 3 with n rw [mul_right_comm, smul_eq_mul, smul_eq_mul, mul_assoc] end ball section emetric variable ⦃c : ℂ⦄ ⦃r : ENNReal⦄ (hf : DifferentiableOn ℂ f (EMetric.ball c r)) variable ⦃z : ℂ⦄ (hz : z ∈ EMetric.ball c r) /-- A function that is complex differentiable on the open ball of radius `r ≤ ∞` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma hasSum_taylorSeries_on_emetric_ball : HasSum (fun n : ℕ ↦ (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c) (f z) := by obtain ⟨r', hzr', hr'⟩ := exists_between (EMetric.mem_ball'.mp hz) lift r' to NNReal using ne_top_of_lt hr' rw [← EMetric.mem_ball', Metric.emetric_ball_nnreal] at hzr' refine hasSum_taylorSeries_on_ball ?_ hzr' rw [← Metric.emetric_ball_nnreal] exact hf.mono <| EMetric.ball_subset_ball hr'.le /-- A function that is complex differentiable on the open ball of radius `r ≤ ∞` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma taylorSeries_eq_on_emetric_ball : ∑' n : ℕ, (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c = f z := (hasSum_taylorSeries_on_emetric_ball hf hz).tsum_eq /-- A function that is complex differentiable on the open ball of radius `r ≤ ∞` around `c` is given by evaluating its Taylor series at `c` on this open ball. -/ lemma taylorSeries_eq_on_emetric_ball' {f : ℂ → ℂ} (hf : DifferentiableOn ℂ f (EMetric.ball c r)) : ∑' n : ℕ, (n ! : ℂ)⁻¹ * iteratedDeriv n f c * (z - c) ^ n = f z := by convert taylorSeries_eq_on_emetric_ball hf hz using 3 with n rw [mul_right_comm, smul_eq_mul, smul_eq_mul, mul_assoc] end emetric section entire variable ⦃f : ℂ → E⦄ (hf : Differentiable ℂ f) (c z : ℂ) /-- A function that is complex differentiable on the complex plane is given by evaluating its Taylor series at any point `c`. -/ lemma hasSum_taylorSeries_of_entire : HasSum (fun n : ℕ ↦ (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c) (f z) := hasSum_taylorSeries_on_emetric_ball hf.differentiableOn <| EMetric.mem_ball.mpr <| edist_lt_top .. /-- A function that is complex differentiable on the complex plane is given by evaluating its Taylor series at any point `c`. -/ lemma taylorSeries_eq_of_entire : ∑' n : ℕ, (n ! : ℂ)⁻¹ • (z - c) ^ n • iteratedDeriv n f c = f z := (hasSum_taylorSeries_of_entire hf c z).tsum_eq /-- A function that is complex differentiable on the complex plane is given by evaluating its Taylor series at any point `c`. -/ lemma taylorSeries_eq_of_entire' {f : ℂ → ℂ} (hf : Differentiable ℂ f) : ∑' n : ℕ, (n ! : ℂ)⁻¹ * iteratedDeriv n f c * (z - c) ^ n = f z := by convert taylorSeries_eq_of_entire hf c z using 3 with n rw [mul_right_comm, smul_eq_mul, smul_eq_mul, mul_assoc] end entire end Complex
Analysis\Complex\Tietze.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Topology.TietzeExtension import Mathlib.Analysis.NormedSpace.HomeomorphBall import Mathlib.Analysis.NormedSpace.RCLike /-! # Finite dimensional topological vector spaces over `ℝ` satisfy the Tietze extension property There are two main results here: - `RCLike.instTietzeExtensionTVS`: finite dimensional topological vector spaces over `ℝ` (or `ℂ`) have the Tietze extension property. - `BoundedContinuousFunction.exists_norm_eq_restrict_eq`: when mapping into a finite dimensional normed vector space over `ℝ` (or `ℂ`), the extension can be chosen to preserve the norm of the bounded continuous function it extends. -/ universe u u₁ v w -- this is not an instance because Lean cannot determine `𝕜`. theorem TietzeExtension.of_tvs (𝕜 : Type v) [NontriviallyNormedField 𝕜] {E : Type w} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousSMul 𝕜 E] [T2Space E] [FiniteDimensional 𝕜 E] [CompleteSpace 𝕜] [TietzeExtension.{u, v} 𝕜] : TietzeExtension.{u, w} E := Basis.ofVectorSpace 𝕜 E |>.equivFun.toContinuousLinearEquiv.toHomeomorph |> .of_homeo instance Complex.instTietzeExtension : TietzeExtension ℂ := TietzeExtension.of_tvs ℝ instance (priority := 900) RCLike.instTietzeExtension {𝕜 : Type*} [RCLike 𝕜] : TietzeExtension 𝕜 := TietzeExtension.of_tvs ℝ instance RCLike.instTietzeExtensionTVS {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousSMul 𝕜 E] [T2Space E] [FiniteDimensional 𝕜 E] : TietzeExtension.{u, w} E := TietzeExtension.of_tvs 𝕜 instance Set.instTietzeExtensionUnitBall {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] : TietzeExtension.{u, w} (Metric.ball (0 : E) 1) := have : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E .of_homeo Homeomorph.unitBall.symm instance Set.instTietzeExtensionUnitClosedBall {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] : TietzeExtension.{u, w} (Metric.closedBall (0 : E) 1) := by have : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E have : IsScalarTower ℝ 𝕜 E := Real.isScalarTower -- I didn't find this retract in Mathlib. let g : E → E := fun x ↦ ‖x‖⁻¹ • x classical suffices this : Continuous (piecewise (Metric.closedBall 0 1) id g) by refine .of_retract ⟨Subtype.val, by fun_prop⟩ ⟨_, this.codRestrict fun x ↦ ?_⟩ ?_ · by_cases hx : x ∈ Metric.closedBall 0 1 · simpa [piecewise_eq_of_mem (hi := hx)] using hx · simp only [g, piecewise_eq_of_not_mem (hi := hx), RCLike.real_smul_eq_coe_smul (K := 𝕜)] by_cases hx' : x = 0 <;> simp [hx'] · ext x simp [piecewise_eq_of_mem (hi := x.property)] refine continuous_piecewise (fun x hx ↦ ?_) continuousOn_id ?_ · replace hx : ‖x‖ = 1 := by simpa [frontier_closedBall (0 : E) one_ne_zero] using hx simp [g, hx] · refine continuousOn_id.norm.inv₀ ?_ |>.smul continuousOn_id simp only [closure_compl, interior_closedBall (0 : E) one_ne_zero, mem_compl_iff, Metric.mem_ball, dist_zero_right, not_lt, id_eq, ne_eq, norm_eq_zero] exact fun x hx ↦ norm_pos_iff.mp <| one_pos.trans_le hx theorem Metric.instTietzeExtensionBall {𝕜 : Type v} [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] {r : ℝ} (hr : 0 < r) : TietzeExtension.{u, w} (Metric.ball (0 : E) r) := have : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E .of_homeo <| show (Metric.ball (0 : E) r) ≃ₜ (Metric.ball (0 : E) 1) from PartialHomeomorph.unitBallBall (0 : E) r hr |>.toHomeomorphSourceTarget.symm theorem Metric.instTietzeExtensionClosedBall (𝕜 : Type v) [RCLike 𝕜] {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] (y : E) {r : ℝ} (hr : 0 < r) : TietzeExtension.{u, w} (Metric.closedBall y r) := .of_homeo <| by show (Metric.closedBall y r) ≃ₜ (Metric.closedBall (0 : E) 1) symm apply (DilationEquiv.smulTorsor y (k := (r : 𝕜)) <| by exact_mod_cast hr.ne').toHomeomorph.sets ext x simp only [mem_closedBall, dist_zero_right, DilationEquiv.coe_toHomeomorph, Set.mem_preimage, DilationEquiv.smulTorsor_apply, vadd_eq_add, dist_add_self_left, norm_smul, RCLike.norm_ofReal, abs_of_nonneg hr.le] exact (mul_le_iff_le_one_right hr).symm variable {X : Type u} [TopologicalSpace X] [NormalSpace X] {s : Set X} (hs : IsClosed s) variable (𝕜 : Type v) [RCLike 𝕜] [TietzeExtension.{u, v} 𝕜] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [FiniteDimensional 𝕜 E] namespace BoundedContinuousFunction /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and bundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/ theorem exists_norm_eq_restrict_eq (f : s →ᵇ E) : ∃ g : X →ᵇ E, ‖g‖ = ‖f‖ ∧ g.restrict s = f := by by_cases hf : ‖f‖ = 0; · exact ⟨0, by aesop⟩ have := Metric.instTietzeExtensionClosedBall.{u, v} 𝕜 (0 : E) (by aesop : 0 < ‖f‖) have hf' x : f x ∈ Metric.closedBall 0 ‖f‖ := by simpa using f.norm_coe_le_norm x obtain ⟨g, hg_mem, hg⟩ := (f : C(s, E)).exists_forall_mem_restrict_eq hs hf' simp only [Metric.mem_closedBall, dist_zero_right] at hg_mem let g' : X →ᵇ E := .ofNormedAddCommGroup g (map_continuous g) ‖f‖ hg_mem refine ⟨g', ?_, by ext x; congrm($(hg) x)⟩ apply le_antisymm ((g'.norm_le <| by positivity).mpr hg_mem) refine (f.norm_le <| by positivity).mpr fun x ↦ ?_ have hx : f x = g' x := by simpa using congr($(hg) x).symm rw [hx] exact g'.norm_le (norm_nonneg g') |>.mp le_rfl x end BoundedContinuousFunction
Analysis\Complex\Polynomial\Basic.lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Junyan Xu, Yury Kudryashov -/ import Mathlib.Analysis.Complex.Liouville import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.FieldTheory.PolynomialGaloisGroup import Mathlib.Topology.Algebra.Polynomial /-! # The fundamental theorem of algebra This file proves that every nonconstant complex polynomial has a root using Liouville's theorem. As a consequence, the complex numbers are algebraically closed. We also provide some specific results about the Galois groups of ℚ-polynomials with specific numbers of non-real roots. We also show that an irreducible real polynomial has degree at most two. -/ open Polynomial Bornology Complex open scoped ComplexConjugate namespace Complex /-- **Fundamental theorem of algebra**: every non constant complex polynomial has a root -/ theorem exists_root {f : ℂ[X]} (hf : 0 < degree f) : ∃ z : ℂ, IsRoot f z := by by_contra! hf' /- Since `f` has no roots, `f⁻¹` is differentiable. And since `f` is a polynomial, it tends to infinity at infinity, thus `f⁻¹` tends to zero at infinity. By Liouville's theorem, `f⁻¹ = 0`. -/ have (z : ℂ) : (f.eval z)⁻¹ = 0 := (f.differentiable.inv hf').apply_eq_of_tendsto_cocompact z <| Metric.cobounded_eq_cocompact (α := ℂ) ▸ (Filter.tendsto_inv₀_cobounded.comp <| by simpa only [tendsto_norm_atTop_iff_cobounded] using f.tendsto_norm_atTop hf tendsto_norm_cobounded_atTop) -- Thus `f = 0`, contradicting the fact that `0 < degree f`. obtain rfl : f = C 0 := Polynomial.funext fun z ↦ inv_injective <| by simp [this] simp at hf instance isAlgClosed : IsAlgClosed ℂ := IsAlgClosed.of_exists_root _ fun _p _ hp => Complex.exists_root <| degree_pos_of_irreducible hp end Complex namespace Polynomial.Gal section Rationals theorem splits_ℚ_ℂ {p : ℚ[X]} : Fact (p.Splits (algebraMap ℚ ℂ)) := ⟨IsAlgClosed.splits_codomain p⟩ attribute [local instance] splits_ℚ_ℂ attribute [local ext] Complex.ext /-- The number of complex roots equals the number of real roots plus the number of roots not fixed by complex conjugation (i.e. with some imaginary component). -/ theorem card_complex_roots_eq_card_real_add_card_not_gal_inv (p : ℚ[X]) : (p.rootSet ℂ).toFinset.card = (p.rootSet ℝ).toFinset.card + (galActionHom p ℂ (restrict p ℂ (AlgEquiv.restrictScalars ℚ Complex.conjAe))).support.card := by by_cases hp : p = 0 · haveI : IsEmpty (p.rootSet ℂ) := by rw [hp, rootSet_zero]; infer_instance simp_rw [(galActionHom p ℂ _).support.eq_empty_of_isEmpty, hp, rootSet_zero, Set.toFinset_empty, Finset.card_empty] have inj : Function.Injective (IsScalarTower.toAlgHom ℚ ℝ ℂ) := (algebraMap ℝ ℂ).injective rw [← Finset.card_image_of_injective _ Subtype.coe_injective, ← Finset.card_image_of_injective _ inj] let a : Finset ℂ := ?_ on_goal 1 => let b : Finset ℂ := ?_ on_goal 1 => let c : Finset ℂ := ?_ -- Porting note: was -- change a.card = b.card + c.card suffices a.card = b.card + c.card by exact this have ha : ∀ z : ℂ, z ∈ a ↔ aeval z p = 0 := by intro z; rw [Set.mem_toFinset, mem_rootSet_of_ne hp] have hb : ∀ z : ℂ, z ∈ b ↔ aeval z p = 0 ∧ z.im = 0 := by intro z simp_rw [b, Finset.mem_image, Set.mem_toFinset, mem_rootSet_of_ne hp] constructor · rintro ⟨w, hw, rfl⟩ exact ⟨by rw [aeval_algHom_apply, hw, map_zero], rfl⟩ · rintro ⟨hz1, hz2⟩ have key : IsScalarTower.toAlgHom ℚ ℝ ℂ z.re = z := by ext · rfl · rw [hz2]; rfl exact ⟨z.re, inj (by rwa [← aeval_algHom_apply, key, map_zero]), key⟩ have hc0 : ∀ w : p.rootSet ℂ, galActionHom p ℂ (restrict p ℂ (Complex.conjAe.restrictScalars ℚ)) w = w ↔ w.val.im = 0 := by intro w rw [Subtype.ext_iff, galActionHom_restrict] exact Complex.conj_eq_iff_im have hc : ∀ z : ℂ, z ∈ c ↔ aeval z p = 0 ∧ z.im ≠ 0 := by intro z simp_rw [c, Finset.mem_image] constructor · rintro ⟨w, hw, rfl⟩ exact ⟨(mem_rootSet.mp w.2).2, mt (hc0 w).mpr (Equiv.Perm.mem_support.mp hw)⟩ · rintro ⟨hz1, hz2⟩ exact ⟨⟨z, mem_rootSet.mpr ⟨hp, hz1⟩⟩, Equiv.Perm.mem_support.mpr (mt (hc0 _).mp hz2), rfl⟩ rw [← Finset.card_union_of_disjoint] · apply congr_arg Finset.card simp_rw [Finset.ext_iff, Finset.mem_union, ha, hb, hc] tauto · rw [Finset.disjoint_left] intro z rw [hb, hc] tauto /-- An irreducible polynomial of prime degree with two non-real roots has full Galois group. -/ theorem galActionHom_bijective_of_prime_degree {p : ℚ[X]} (p_irr : Irreducible p) (p_deg : p.natDegree.Prime) (p_roots : Fintype.card (p.rootSet ℂ) = Fintype.card (p.rootSet ℝ) + 2) : Function.Bijective (galActionHom p ℂ) := by classical have h1 : Fintype.card (p.rootSet ℂ) = p.natDegree := by simp_rw [rootSet_def, Finset.coe_sort_coe, Fintype.card_coe] rw [Multiset.toFinset_card_of_nodup, ← natDegree_eq_card_roots] · exact IsAlgClosed.splits_codomain p · exact nodup_roots ((separable_map (algebraMap ℚ ℂ)).mpr p_irr.separable) let conj' := restrict p ℂ (Complex.conjAe.restrictScalars ℚ) refine ⟨galActionHom_injective p ℂ, fun x => (congr_arg (Membership.mem x) (show (galActionHom p ℂ).range = ⊤ from ?_)).mpr (Subgroup.mem_top x)⟩ apply Equiv.Perm.subgroup_eq_top_of_swap_mem · rwa [h1] · rw [h1] simpa only [Fintype.card_eq_nat_card, Nat.card_congr (MonoidHom.ofInjective (galActionHom_injective p ℂ)).toEquiv.symm] using prime_degree_dvd_card p_irr p_deg · exact ⟨conj', rfl⟩ · rw [← Equiv.Perm.card_support_eq_two] apply Nat.add_left_cancel rw [← p_roots, ← Set.toFinset_card (rootSet p ℝ), ← Set.toFinset_card (rootSet p ℂ)] exact (card_complex_roots_eq_card_real_add_card_not_gal_inv p).symm /-- An irreducible polynomial of prime degree with 1-3 non-real roots has full Galois group. -/ theorem galActionHom_bijective_of_prime_degree' {p : ℚ[X]} (p_irr : Irreducible p) (p_deg : p.natDegree.Prime) (p_roots1 : Fintype.card (p.rootSet ℝ) + 1 ≤ Fintype.card (p.rootSet ℂ)) (p_roots2 : Fintype.card (p.rootSet ℂ) ≤ Fintype.card (p.rootSet ℝ) + 3) : Function.Bijective (galActionHom p ℂ) := by apply galActionHom_bijective_of_prime_degree p_irr p_deg let n := (galActionHom p ℂ (restrict p ℂ (Complex.conjAe.restrictScalars ℚ))).support.card have hn : 2 ∣ n := Equiv.Perm.two_dvd_card_support (by rw [← MonoidHom.map_pow, ← MonoidHom.map_pow, show AlgEquiv.restrictScalars ℚ Complex.conjAe ^ 2 = 1 from AlgEquiv.ext Complex.conj_conj, MonoidHom.map_one, MonoidHom.map_one]) have key := card_complex_roots_eq_card_real_add_card_not_gal_inv p simp_rw [Set.toFinset_card] at key rw [key, add_le_add_iff_left] at p_roots1 p_roots2 rw [key, add_right_inj] suffices ∀ m : ℕ, 2 ∣ m → 1 ≤ m → m ≤ 3 → m = 2 by exact this n hn p_roots1 p_roots2 rintro m ⟨k, rfl⟩ h2 h3 exact le_antisymm (Nat.lt_succ_iff.mp (lt_of_le_of_ne h3 (show 2 * k ≠ 2 * 1 + 1 from Nat.two_mul_ne_two_mul_add_one))) (Nat.succ_le_iff.mpr (lt_of_le_of_ne h2 (show 2 * 0 + 1 ≠ 2 * k from Nat.two_mul_ne_two_mul_add_one.symm))) end Rationals end Polynomial.Gal lemma Polynomial.mul_star_dvd_of_aeval_eq_zero_im_ne_zero (p : ℝ[X]) {z : ℂ} (h0 : aeval z p = 0) (hz : z.im ≠ 0) : (X - C ((starRingEnd ℂ) z)) * (X - C z) ∣ map (algebraMap ℝ ℂ) p := by apply IsCoprime.mul_dvd · exact isCoprime_X_sub_C_of_isUnit_sub <| .mk0 _ <| sub_ne_zero.2 <| mt conj_eq_iff_im.1 hz · simpa [dvd_iff_isRoot, aeval_conj] · simpa [dvd_iff_isRoot] /-- If `z` is a non-real complex root of a real polynomial, then `p` is divisible by a quadratic polynomial. -/ lemma Polynomial.quadratic_dvd_of_aeval_eq_zero_im_ne_zero (p : ℝ[X]) {z : ℂ} (h0 : aeval z p = 0) (hz : z.im ≠ 0) : X ^ 2 - C (2 * z.re) * X + C (‖z‖ ^ 2) ∣ p := by rw [← map_dvd_map' (algebraMap ℝ ℂ)] convert p.mul_star_dvd_of_aeval_eq_zero_im_ne_zero h0 hz calc map (algebraMap ℝ ℂ) (X ^ 2 - C (2 * z.re) * X + C (‖z‖ ^ 2)) _ = X ^ 2 - C (↑(2 * z.re) : ℂ) * X + C (‖z‖ ^ 2 : ℂ) := by simp _ = (X - C (conj z)) * (X - C z) := by rw [← add_conj, map_add, ← mul_conj', map_mul] ring /-- An irreducible real polynomial has degree at most two. -/ lemma Irreducible.degree_le_two {p : ℝ[X]} (hp : Irreducible p) : degree p ≤ 2 := by obtain ⟨z, hz⟩ : ∃ z : ℂ, aeval z p = 0 := IsAlgClosed.exists_aeval_eq_zero _ p (degree_pos_of_irreducible hp).ne' cases eq_or_ne z.im 0 with | inl hz0 => lift z to ℝ using hz0 erw [aeval_ofReal, RCLike.ofReal_eq_zero] at hz exact (degree_eq_one_of_irreducible_of_root hp hz).trans_le one_le_two | inr hz0 => obtain ⟨q, rfl⟩ := p.quadratic_dvd_of_aeval_eq_zero_im_ne_zero hz hz0 have hd : degree (X ^ 2 - C (2 * z.re) * X + C (‖z‖ ^ 2)) = 2 := by compute_degree! have hq : IsUnit q := by refine (of_irreducible_mul hp).resolve_left (mt isUnit_iff_degree_eq_zero.1 ?_) rw [hd] exact two_ne_zero refine (degree_mul_le _ _).trans_eq ?_ rwa [isUnit_iff_degree_eq_zero.1 hq, add_zero] /-- An irreducible real polynomial has natural degree at most two. -/ lemma Irreducible.natDegree_le_two {p : ℝ[X]} (hp : Irreducible p) : natDegree p ≤ 2 := natDegree_le_iff_degree_le.2 hp.degree_le_two @[deprecated (since := "2024-02-18")] alias Irreducible.nat_degree_le_two := Irreducible.natDegree_le_two
Analysis\Complex\Polynomial\UnitTrinomial.lean
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.Polynomial.UnitTrinomial import Mathlib.Analysis.Complex.Polynomial.Basic /-! # Irreducibility of unit trinomials ## TODO Develop more theory (e.g., it suffices to check that `aeval z p ≠ 0` for `z = 0` and `z` a root of unity). -/ namespace Polynomial.IsUnitTrinomial variable {p : ℤ[X]} /-- A unit trinomial is irreducible if it has no complex roots in common with its mirror. -/ theorem irreducible_of_coprime' (hp : IsUnitTrinomial p) (h : ∀ z : ℂ, ¬(aeval z p = 0 ∧ aeval z (mirror p) = 0)) : Irreducible p := by refine hp.irreducible_of_coprime fun q hq hq' => ?_ suffices ¬0 < q.natDegree by rcases hq with ⟨p, rfl⟩ replace hp := hp.leadingCoeff_isUnit rw [leadingCoeff_mul] at hp replace hp := isUnit_of_mul_isUnit_left hp rw [not_lt, Nat.le_zero] at this rwa [eq_C_of_natDegree_eq_zero this, isUnit_C, ← this] intro hq'' rw [natDegree_pos_iff_degree_pos] at hq'' rw [← degree_map_eq_of_injective (algebraMap ℤ ℂ).injective_int] at hq'' cases' Complex.exists_root hq'' with z hz rw [IsRoot, eval_map, ← aeval_def] at hz refine h z ⟨?_, ?_⟩ · cases' hq with g' hg' rw [hg', aeval_mul, hz, zero_mul] · cases' hq' with g' hg' rw [hg', aeval_mul, hz, zero_mul] end Polynomial.IsUnitTrinomial
Analysis\Complex\UnitDisc\Basic.lean
/- 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.Circle import Mathlib.Analysis.NormedSpace.BallAction /-! # Poincaré disc In this file we define `Complex.UnitDisc` to be the unit disc in the complex plane. We also introduce some basic operations on this disc. -/ open Set Function Metric noncomputable section local notation "conj'" => starRingEnd ℂ namespace Complex /-- Complex unit disc. -/ def UnitDisc : Type := ball (0 : ℂ) 1 deriving TopologicalSpace @[inherit_doc] scoped[UnitDisc] notation "𝔻" => Complex.UnitDisc open UnitDisc namespace UnitDisc instance instCommSemigroup : CommSemigroup UnitDisc := by unfold UnitDisc; infer_instance instance instHasDistribNeg : HasDistribNeg UnitDisc := by unfold UnitDisc; infer_instance instance instCoe : Coe UnitDisc ℂ := ⟨Subtype.val⟩ theorem coe_injective : Injective ((↑) : 𝔻 → ℂ) := Subtype.coe_injective theorem abs_lt_one (z : 𝔻) : abs (z : ℂ) < 1 := mem_ball_zero_iff.1 z.2 theorem abs_ne_one (z : 𝔻) : abs (z : ℂ) ≠ 1 := z.abs_lt_one.ne theorem normSq_lt_one (z : 𝔻) : normSq z < 1 := by convert (Real.sqrt_lt' one_pos).1 z.abs_lt_one exact (one_pow 2).symm theorem coe_ne_one (z : 𝔻) : (z : ℂ) ≠ 1 := ne_of_apply_ne abs <| (map_one abs).symm ▸ z.abs_ne_one theorem coe_ne_neg_one (z : 𝔻) : (z : ℂ) ≠ -1 := ne_of_apply_ne abs <| by rw [abs.map_neg, map_one] exact z.abs_ne_one theorem one_add_coe_ne_zero (z : 𝔻) : (1 + z : ℂ) ≠ 0 := mt neg_eq_iff_add_eq_zero.2 z.coe_ne_neg_one.symm @[simp, norm_cast] theorem coe_mul (z w : 𝔻) : ↑(z * w) = (z * w : ℂ) := rfl /-- A constructor that assumes `abs z < 1` instead of `dist z 0 < 1` and returns an element of `𝔻` instead of `↥Metric.ball (0 : ℂ) 1`. -/ def mk (z : ℂ) (hz : abs z < 1) : 𝔻 := ⟨z, mem_ball_zero_iff.2 hz⟩ @[simp] theorem coe_mk (z : ℂ) (hz : abs z < 1) : (mk z hz : ℂ) = z := rfl @[simp] theorem mk_coe (z : 𝔻) (hz : abs (z : ℂ) < 1 := z.abs_lt_one) : mk z hz = z := Subtype.eta _ _ @[simp] theorem mk_neg (z : ℂ) (hz : abs (-z) < 1) : mk (-z) hz = -mk z (abs.map_neg z ▸ hz) := rfl instance : SemigroupWithZero 𝔻 := { instCommSemigroup with zero := mk 0 <| (map_zero _).trans_lt one_pos zero_mul := fun _ => coe_injective <| zero_mul _ mul_zero := fun _ => coe_injective <| mul_zero _ } @[simp] theorem coe_zero : ((0 : 𝔻) : ℂ) = 0 := rfl @[simp] theorem coe_eq_zero {z : 𝔻} : (z : ℂ) = 0 ↔ z = 0 := coe_injective.eq_iff' coe_zero instance : Inhabited 𝔻 := ⟨0⟩ instance circleAction : MulAction circle 𝔻 := mulActionSphereBall instance isScalarTower_circle_circle : IsScalarTower circle circle 𝔻 := isScalarTower_sphere_sphere_ball instance isScalarTower_circle : IsScalarTower circle 𝔻 𝔻 := isScalarTower_sphere_ball_ball instance instSMulCommClass_circle : SMulCommClass circle 𝔻 𝔻 := instSMulCommClass_sphere_ball_ball instance instSMulCommClass_circle' : SMulCommClass 𝔻 circle 𝔻 := SMulCommClass.symm _ _ _ @[simp, norm_cast] theorem coe_smul_circle (z : circle) (w : 𝔻) : ↑(z • w) = (z * w : ℂ) := rfl instance closedBallAction : MulAction (closedBall (0 : ℂ) 1) 𝔻 := mulActionClosedBallBall instance isScalarTower_closedBall_closedBall : IsScalarTower (closedBall (0 : ℂ) 1) (closedBall (0 : ℂ) 1) 𝔻 := isScalarTower_closedBall_closedBall_ball instance isScalarTower_closedBall : IsScalarTower (closedBall (0 : ℂ) 1) 𝔻 𝔻 := isScalarTower_closedBall_ball_ball instance instSMulCommClass_closedBall : SMulCommClass (closedBall (0 : ℂ) 1) 𝔻 𝔻 := ⟨fun _ _ _ => Subtype.ext <| mul_left_comm _ _ _⟩ instance instSMulCommClass_closedBall' : SMulCommClass 𝔻 (closedBall (0 : ℂ) 1) 𝔻 := SMulCommClass.symm _ _ _ instance instSMulCommClass_circle_closedBall : SMulCommClass circle (closedBall (0 : ℂ) 1) 𝔻 := instSMulCommClass_sphere_closedBall_ball instance instSMulCommClass_closedBall_circle : SMulCommClass (closedBall (0 : ℂ) 1) circle 𝔻 := SMulCommClass.symm _ _ _ @[simp, norm_cast] theorem coe_smul_closedBall (z : closedBall (0 : ℂ) 1) (w : 𝔻) : ↑(z • w) = (z * w : ℂ) := rfl /-- Real part of a point of the unit disc. -/ def re (z : 𝔻) : ℝ := Complex.re z /-- Imaginary part of a point of the unit disc. -/ def im (z : 𝔻) : ℝ := Complex.im z @[simp, norm_cast] theorem re_coe (z : 𝔻) : (z : ℂ).re = z.re := rfl @[simp, norm_cast] theorem im_coe (z : 𝔻) : (z : ℂ).im = z.im := rfl @[simp] theorem re_neg (z : 𝔻) : (-z).re = -z.re := rfl @[simp] theorem im_neg (z : 𝔻) : (-z).im = -z.im := rfl /-- Conjugate point of the unit disc. -/ def conj (z : 𝔻) : 𝔻 := mk (conj' ↑z) <| (abs_conj z).symm ▸ z.abs_lt_one -- Porting note: removed `norm_cast` because this is a bad `norm_cast` lemma -- because both sides have a head coe @[simp] theorem coe_conj (z : 𝔻) : (z.conj : ℂ) = conj' ↑z := rfl @[simp] theorem conj_zero : conj 0 = 0 := coe_injective (map_zero conj') @[simp] theorem conj_conj (z : 𝔻) : conj (conj z) = z := coe_injective <| Complex.conj_conj (z : ℂ) @[simp] theorem conj_neg (z : 𝔻) : (-z).conj = -z.conj := rfl @[simp] theorem re_conj (z : 𝔻) : z.conj.re = z.re := rfl @[simp] theorem im_conj (z : 𝔻) : z.conj.im = -z.im := rfl @[simp] theorem conj_mul (z w : 𝔻) : (z * w).conj = z.conj * w.conj := Subtype.ext <| map_mul _ _ _ end UnitDisc end Complex
Analysis\Complex\UpperHalfPlane\Basic.lean
/- Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu -/ import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Analysis.Complex.Basic import Mathlib.Data.Fintype.Parity import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.LinearCombination /-! # The upper half plane and its automorphisms This file defines `UpperHalfPlane` to be the upper half plane in `ℂ`. We furthermore equip it with the structure of a `GLPos 2 ℝ` action by fractional linear transformations. We define the notation `ℍ` for the upper half plane available in the locale `UpperHalfPlane` so as not to conflict with the quaternions. -/ noncomputable section open Matrix Matrix.SpecialLinearGroup open scoped MatrixGroups /- Disable these instances as they are not the simp-normal form, and having them disabled ensures we state lemmas in this file without spurious `coe_fn` terms. -/ attribute [-instance] Matrix.SpecialLinearGroup.instCoeFun attribute [-instance] Matrix.GeneralLinearGroup.instCoeFun local notation "GL(" n ", " R ")" "⁺" => Matrix.GLPos (Fin n) R local notation:1024 "↑ₘ" A:1024 => (((A : GL(2, ℝ)⁺) : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) _) local notation:1024 "↑ₘ[" R "]" A:1024 => ((A : GL (Fin 2) R) : Matrix (Fin 2) (Fin 2) R) /-- The open upper half plane -/ def UpperHalfPlane := { point : ℂ // 0 < point.im } @[inherit_doc] scoped[UpperHalfPlane] notation "ℍ" => UpperHalfPlane open UpperHalfPlane namespace UpperHalfPlane /-- Canonical embedding of the upper half-plane into `ℂ`. -/ @[coe] protected def coe (z : ℍ) : ℂ := z.1 -- Porting note: added to replace `deriving` instance : CoeOut ℍ ℂ := ⟨UpperHalfPlane.coe⟩ instance : Inhabited ℍ := ⟨⟨Complex.I, by simp⟩⟩ @[ext] theorem ext {a b : ℍ} (h : (a : ℂ) = b) : a = b := Subtype.eq h @[simp, norm_cast] theorem ext_iff' {a b : ℍ} : (a : ℂ) = b ↔ a = b := UpperHalfPlane.ext_iff.symm instance canLift : CanLift ℂ ℍ ((↑) : ℍ → ℂ) fun z => 0 < z.im := Subtype.canLift fun (z : ℂ) => 0 < z.im /-- Imaginary part -/ def im (z : ℍ) := (z : ℂ).im /-- Real part -/ def re (z : ℍ) := (z : ℂ).re /-- Extensionality lemma in terms of `UpperHalfPlane.re` and `UpperHalfPlane.im`. -/ theorem ext' {a b : ℍ} (hre : a.re = b.re) (him : a.im = b.im) : a = b := ext <| Complex.ext hre him /-- Constructor for `UpperHalfPlane`. It is useful if `⟨z, h⟩` makes Lean use a wrong typeclass instance. -/ def mk (z : ℂ) (h : 0 < z.im) : ℍ := ⟨z, h⟩ @[simp] theorem coe_im (z : ℍ) : (z : ℂ).im = z.im := rfl @[simp] theorem coe_re (z : ℍ) : (z : ℂ).re = z.re := rfl @[simp] theorem mk_re (z : ℂ) (h : 0 < z.im) : (mk z h).re = z.re := rfl @[simp] theorem mk_im (z : ℂ) (h : 0 < z.im) : (mk z h).im = z.im := rfl @[simp] theorem coe_mk (z : ℂ) (h : 0 < z.im) : (mk z h : ℂ) = z := rfl @[simp] theorem mk_coe (z : ℍ) (h : 0 < (z : ℂ).im := z.2) : mk z h = z := rfl theorem re_add_im (z : ℍ) : (z.re + z.im * Complex.I : ℂ) = z := Complex.re_add_im z theorem im_pos (z : ℍ) : 0 < z.im := z.2 theorem im_ne_zero (z : ℍ) : z.im ≠ 0 := z.im_pos.ne' theorem ne_zero (z : ℍ) : (z : ℂ) ≠ 0 := mt (congr_arg Complex.im) z.im_ne_zero /-- Define I := √-1 as an element on the upper half plane. -/ def I : ℍ := ⟨Complex.I, by simp⟩ @[simp] lemma I_im : I.im = 1 := rfl @[simp] lemma I_re : I.re = 0 := rfl @[simp, norm_cast] lemma coe_I : I = Complex.I := rfl end UpperHalfPlane namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: `UpperHalfPlane.im`. -/ @[positivity UpperHalfPlane.im _] def evalUpperHalfPlaneIm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(UpperHalfPlane.im $a) => assertInstancesCommute pure (.positive q(@UpperHalfPlane.im_pos $a)) | _, _, _ => throwError "not UpperHalfPlane.im" /-- Extension for the `positivity` tactic: `UpperHalfPlane.coe`. -/ @[positivity UpperHalfPlane.coe _] def evalUpperHalfPlaneCoe : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℂ), ~q(UpperHalfPlane.coe $a) => assertInstancesCommute pure (.nonzero q(@UpperHalfPlane.ne_zero $a)) | _, _, _ => throwError "not UpperHalfPlane.coe" end Mathlib.Meta.Positivity namespace UpperHalfPlane theorem normSq_pos (z : ℍ) : 0 < Complex.normSq (z : ℂ) := by rw [Complex.normSq_pos]; exact z.ne_zero theorem normSq_ne_zero (z : ℍ) : Complex.normSq (z : ℂ) ≠ 0 := (normSq_pos z).ne' theorem im_inv_neg_coe_pos (z : ℍ) : 0 < (-z : ℂ)⁻¹.im := by simpa using div_pos z.property (normSq_pos z) -- Porting note: removed `@[simp]` because it broke `field_simp` calls below. /-- Numerator of the formula for a fractional linear transformation -/ def num (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := (↑ₘg 0 0 : ℝ) * z + (↑ₘg 0 1 : ℝ) -- Porting note: removed `@[simp]` because it broke `field_simp` calls below. /-- Denominator of the formula for a fractional linear transformation -/ def denom (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := (↑ₘg 1 0 : ℝ) * z + (↑ₘg 1 1 : ℝ) theorem linear_ne_zero (cd : Fin 2 → ℝ) (z : ℍ) (h : cd ≠ 0) : (cd 0 : ℂ) * z + cd 1 ≠ 0 := by contrapose! h have : cd 0 = 0 := by -- we will need this twice apply_fun Complex.im at h simpa only [z.im_ne_zero, Complex.add_im, add_zero, coe_im, zero_mul, or_false_iff, Complex.ofReal_im, Complex.zero_im, Complex.mul_im, mul_eq_zero] using h simp only [this, zero_mul, Complex.ofReal_zero, zero_add, Complex.ofReal_eq_zero] at h ext i fin_cases i <;> assumption theorem denom_ne_zero (g : GL(2, ℝ)⁺) (z : ℍ) : denom g z ≠ 0 := by intro H have DET := (mem_glpos _).1 g.prop have hz := z.prop simp only [GeneralLinearGroup.val_det_apply] at DET have H1 : (↑ₘg 1 0 : ℝ) = 0 ∨ z.im = 0 := by simpa [num, denom] using congr_arg Complex.im H cases' H1 with H1 · simp only [H1, Complex.ofReal_zero, denom, zero_mul, zero_add, Complex.ofReal_eq_zero] at H rw [Matrix.det_fin_two (↑ₘg : Matrix (Fin 2) (Fin 2) ℝ)] at DET simp only [H, H1, mul_zero, sub_zero, lt_self_iff_false] at DET · change z.im > 0 at hz linarith theorem normSq_denom_pos (g : GL(2, ℝ)⁺) (z : ℍ) : 0 < Complex.normSq (denom g z) := Complex.normSq_pos.mpr (denom_ne_zero g z) theorem normSq_denom_ne_zero (g : GL(2, ℝ)⁺) (z : ℍ) : Complex.normSq (denom g z) ≠ 0 := ne_of_gt (normSq_denom_pos g z) /-- Fractional linear transformation, also known as the Moebius transformation -/ def smulAux' (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := num g z / denom g z theorem smulAux'_im (g : GL(2, ℝ)⁺) (z : ℍ) : (smulAux' g z).im = det ↑ₘg * z.im / Complex.normSq (denom g z) := by rw [smulAux', Complex.div_im] field_simp [smulAux', num, denom] -- Porting note: the local notation still didn't work here rw [Matrix.det_fin_two ((g : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) ℝ)] ring /-- Fractional linear transformation, also known as the Moebius transformation -/ def smulAux (g : GL(2, ℝ)⁺) (z : ℍ) : ℍ := mk (smulAux' g z) <| by rw [smulAux'_im] convert mul_pos ((mem_glpos _).1 g.prop) (div_pos z.im_pos (Complex.normSq_pos.mpr (denom_ne_zero g z))) using 1 simp only [GeneralLinearGroup.val_det_apply] ring theorem denom_cocycle (x y : GL(2, ℝ)⁺) (z : ℍ) : denom (x * y) z = denom x (smulAux y z) * denom y z := by change _ = (_ * (_ / _) + _) * _ field_simp [denom_ne_zero] simp only [Matrix.mul_apply, dotProduct, Fin.sum_univ_succ, denom, num, Subgroup.coe_mul, GeneralLinearGroup.coe_mul, Fintype.univ_ofSubsingleton, Fin.mk_zero, Finset.sum_singleton, Fin.succ_zero_eq_one, Complex.ofReal_add, Complex.ofReal_mul] ring theorem mul_smul' (x y : GL(2, ℝ)⁺) (z : ℍ) : smulAux (x * y) z = smulAux x (smulAux y z) := by ext1 -- Porting note: was `change _ / _ = (_ * (_ / _) + _) * _` change _ / _ = (_ * (_ / _) + _) / _ rw [denom_cocycle] field_simp [denom_ne_zero] simp only [Matrix.mul_apply, dotProduct, Fin.sum_univ_succ, num, denom, Subgroup.coe_mul, GeneralLinearGroup.coe_mul, Fintype.univ_ofSubsingleton, Fin.mk_zero, Finset.sum_singleton, Fin.succ_zero_eq_one, Complex.ofReal_add, Complex.ofReal_mul] ring /-- The action of `GLPos 2 ℝ` on the upper half-plane by fractional linear transformations. -/ instance : MulAction GL(2, ℝ)⁺ ℍ where smul := smulAux one_smul z := by ext1 change _ / _ = _ simp [num, denom] mul_smul := mul_smul' section ModularScalarTowers instance SLAction {R : Type*} [CommRing R] [Algebra R ℝ] : MulAction SL(2, R) ℍ := MulAction.compHom ℍ <| SpecialLinearGroup.toGLPos.comp <| map (algebraMap R ℝ) namespace ModularGroup variable (Γ : Subgroup (SpecialLinearGroup (Fin 2) ℤ)) /-- Canonical embedding of `SL(2, ℤ)` into `GL(2, ℝ)⁺`. -/ @[coe] def coe' : SL(2, ℤ) → GL(2, ℝ)⁺ := fun g => ((g : SL(2, ℝ)) : GL(2, ℝ)⁺) instance : Coe SL(2, ℤ) GL(2, ℝ)⁺ := ⟨coe'⟩ @[simp] theorem coe'_apply_complex {g : SL(2, ℤ)} {i j : Fin 2} : (Units.val <| Subtype.val <| coe' g) i j = (Subtype.val g i j : ℂ) := rfl @[simp] theorem det_coe' {g : SL(2, ℤ)} : det (Units.val <| Subtype.val <| coe' g) = 1 := by simp only [SpecialLinearGroup.coe_GLPos_coe_GL_coe_matrix, SpecialLinearGroup.det_coe, coe'] instance SLOnGLPos : SMul SL(2, ℤ) GL(2, ℝ)⁺ := ⟨fun s g => s * g⟩ theorem SLOnGLPos_smul_apply (s : SL(2, ℤ)) (g : GL(2, ℝ)⁺) (z : ℍ) : (s • g) • z = ((s : GL(2, ℝ)⁺) * g) • z := rfl instance SL_to_GL_tower : IsScalarTower SL(2, ℤ) GL(2, ℝ)⁺ ℍ where smul_assoc s g z := by simp only [SLOnGLPos_smul_apply] apply mul_smul' instance subgroupGLPos : SMul Γ GL(2, ℝ)⁺ := ⟨fun s g => s * g⟩ theorem subgroup_on_glpos_smul_apply (s : Γ) (g : GL(2, ℝ)⁺) (z : ℍ) : (s • g) • z = ((s : GL(2, ℝ)⁺) * g) • z := rfl instance subgroup_on_glpos : IsScalarTower Γ GL(2, ℝ)⁺ ℍ where smul_assoc s g z := by simp only [subgroup_on_glpos_smul_apply] apply mul_smul' instance subgroupSL : SMul Γ SL(2, ℤ) := ⟨fun s g => s * g⟩ theorem subgroup_on_SL_apply (s : Γ) (g : SL(2, ℤ)) (z : ℍ) : (s • g) • z = ((s : SL(2, ℤ)) * g) • z := rfl instance subgroup_to_SL_tower : IsScalarTower Γ SL(2, ℤ) ℍ where smul_assoc s g z := by rw [subgroup_on_SL_apply] apply MulAction.mul_smul end ModularGroup end ModularScalarTowers -- Porting note: in the statement, we used to have coercions `↑· : ℝ` -- rather than `algebraMap R ℝ ·`. theorem specialLinearGroup_apply {R : Type*} [CommRing R] [Algebra R ℝ] (g : SL(2, R)) (z : ℍ) : g • z = mk (((algebraMap R ℝ (↑ₘ[R] g 0 0) : ℂ) * z + (algebraMap R ℝ (↑ₘ[R] g 0 1) : ℂ)) / ((algebraMap R ℝ (↑ₘ[R] g 1 0) : ℂ) * z + (algebraMap R ℝ (↑ₘ[R] g 1 1) : ℂ))) (g • z).property := rfl @[simp] theorem coe_smul (g : GL(2, ℝ)⁺) (z : ℍ) : ↑(g • z) = num g z / denom g z := rfl @[simp] theorem re_smul (g : GL(2, ℝ)⁺) (z : ℍ) : (g • z).re = (num g z / denom g z).re := rfl theorem im_smul (g : GL(2, ℝ)⁺) (z : ℍ) : (g • z).im = (num g z / denom g z).im := rfl theorem im_smul_eq_div_normSq (g : GL(2, ℝ)⁺) (z : ℍ) : (g • z).im = det ↑ₘg * z.im / Complex.normSq (denom g z) := smulAux'_im g z theorem c_mul_im_sq_le_normSq_denom (z : ℍ) (g : SL(2, ℝ)) : ((↑ₘg 1 0 : ℝ) * z.im) ^ 2 ≤ Complex.normSq (denom g z) := by let c := (↑ₘg 1 0 : ℝ) let d := (↑ₘg 1 1 : ℝ) calc (c * z.im) ^ 2 ≤ (c * z.im) ^ 2 + (c * z.re + d) ^ 2 := by nlinarith _ = Complex.normSq (denom g z) := by dsimp [c, d, denom, Complex.normSq]; ring @[simp] theorem neg_smul (g : GL(2, ℝ)⁺) (z : ℍ) : -g • z = g • z := by ext1 change _ / _ = _ / _ field_simp [denom_ne_zero] simp only [num, denom, Complex.ofReal_neg, neg_mul, GLPos.coe_neg_GL, Units.val_neg, neg_apply] ring_nf section SLModularAction namespace ModularGroup variable (g : SL(2, ℤ)) (z : ℍ) (Γ : Subgroup SL(2, ℤ)) @[simp] theorem sl_moeb (A : SL(2, ℤ)) (z : ℍ) : A • z = (A : GL(2, ℝ)⁺) • z := rfl theorem subgroup_moeb (A : Γ) (z : ℍ) : A • z = (A : GL(2, ℝ)⁺) • z := rfl @[simp] theorem subgroup_to_sl_moeb (A : Γ) (z : ℍ) : A • z = (A : SL(2, ℤ)) • z := rfl @[simp high] theorem SL_neg_smul (g : SL(2, ℤ)) (z : ℍ) : -g • z = g • z := by simp only [coe_GLPos_neg, sl_moeb, coe_int_neg, neg_smul, coe'] nonrec theorem im_smul_eq_div_normSq : (g • z).im = z.im / Complex.normSq (denom g z) := by convert im_smul_eq_div_normSq g z simp only [GeneralLinearGroup.val_det_apply, coe_GLPos_coe_GL_coe_matrix, Int.coe_castRingHom, (g : SL(2, ℝ)).prop, one_mul, coe'] theorem denom_apply (g : SL(2, ℤ)) (z : ℍ) : denom g z = (↑g : Matrix (Fin 2) (Fin 2) ℤ) 1 0 * z + (↑g : Matrix (Fin 2) (Fin 2) ℤ) 1 1 := by simp [denom, coe'] end ModularGroup end SLModularAction section PosRealAction instance posRealAction : MulAction { x : ℝ // 0 < x } ℍ where smul x z := mk ((x : ℝ) • (z : ℂ)) <| by simpa using mul_pos x.2 z.2 one_smul z := Subtype.ext <| one_smul _ _ mul_smul x y z := Subtype.ext <| mul_smul (x : ℝ) y (z : ℂ) variable (x : { x : ℝ // 0 < x }) (z : ℍ) @[simp] theorem coe_pos_real_smul : ↑(x • z) = (x : ℝ) • (z : ℂ) := rfl @[simp] theorem pos_real_im : (x • z).im = x * z.im := Complex.smul_im _ _ @[simp] theorem pos_real_re : (x • z).re = x * z.re := Complex.smul_re _ _ end PosRealAction section RealAddAction instance : AddAction ℝ ℍ where vadd x z := mk (x + z) <| by simpa using z.im_pos zero_vadd _ := Subtype.ext <| by simp [HVAdd.hVAdd] add_vadd x y z := Subtype.ext <| by simp [HVAdd.hVAdd, add_assoc] variable (x : ℝ) (z : ℍ) @[simp] theorem coe_vadd : ↑(x +ᵥ z) = (x + z : ℂ) := rfl @[simp] theorem vadd_re : (x +ᵥ z).re = x + z.re := rfl @[simp] theorem vadd_im : (x +ᵥ z).im = z.im := zero_add _ end RealAddAction /- these next few lemmas are *not* flagged `@simp` because of the constructors on the RHS; instead we use the versions with coercions to `ℂ` as simp lemmas instead. -/ theorem modular_S_smul (z : ℍ) : ModularGroup.S • z = mk (-z : ℂ)⁻¹ z.im_inv_neg_coe_pos := by rw [specialLinearGroup_apply]; simp [ModularGroup.S, neg_div, inv_neg, coeToGL] theorem modular_T_zpow_smul (z : ℍ) (n : ℤ) : ModularGroup.T ^ n • z = (n : ℝ) +ᵥ z := by rw [UpperHalfPlane.ext_iff, coe_vadd, add_comm, specialLinearGroup_apply, coe_mk] -- Porting note: added `coeToGL` and merged `rw` and `simp` simp [coeToGL, ModularGroup.coe_T_zpow, of_apply, cons_val_zero, algebraMap.coe_one, Complex.ofReal_one, one_mul, cons_val_one, head_cons, algebraMap.coe_zero, zero_mul, zero_add, div_one] theorem modular_T_smul (z : ℍ) : ModularGroup.T • z = (1 : ℝ) +ᵥ z := by simpa only [Int.cast_one] using modular_T_zpow_smul z 1 theorem exists_SL2_smul_eq_of_apply_zero_one_eq_zero (g : SL(2, ℝ)) (hc : ↑ₘ[ℝ] g 1 0 = 0) : ∃ (u : { x : ℝ // 0 < x }) (v : ℝ), (g • · : ℍ → ℍ) = (v +ᵥ ·) ∘ (u • ·) := by obtain ⟨a, b, ha, rfl⟩ := g.fin_two_exists_eq_mk_of_apply_zero_one_eq_zero hc refine ⟨⟨_, mul_self_pos.mpr ha⟩, b * a, ?_⟩ ext1 ⟨z, hz⟩; ext1 suffices ↑a * z * a + b * a = b * a + a * a * z by -- Porting note: added `coeToGL` and merged `rw` and `simpa` simpa [coeToGL, specialLinearGroup_apply, add_mul] ring theorem exists_SL2_smul_eq_of_apply_zero_one_ne_zero (g : SL(2, ℝ)) (hc : ↑ₘ[ℝ] g 1 0 ≠ 0) : ∃ (u : { x : ℝ // 0 < x }) (v w : ℝ), (g • · : ℍ → ℍ) = (w +ᵥ ·) ∘ (ModularGroup.S • · : ℍ → ℍ) ∘ (v +ᵥ · : ℍ → ℍ) ∘ (u • · : ℍ → ℍ) := by have h_denom := denom_ne_zero g induction' g using Matrix.SpecialLinearGroup.fin_two_induction with a b c d h replace hc : c ≠ 0 := by simpa using hc refine ⟨⟨_, mul_self_pos.mpr hc⟩, c * d, a / c, ?_⟩ ext1 ⟨z, hz⟩; ext1 suffices (↑a * z + b) / (↑c * z + d) = a / c - (c * d + ↑c * ↑c * z)⁻¹ by -- Porting note: golfed broken proof simpa only [modular_S_smul, inv_neg, Function.comp_apply, coe_vadd, Complex.ofReal_mul, coe_pos_real_smul, Complex.real_smul, Complex.ofReal_div, coe_mk] replace hc : (c : ℂ) ≠ 0 := by norm_cast replace h_denom : ↑c * z + d ≠ 0 := by simpa using h_denom ⟨z, hz⟩ have h_aux : (c : ℂ) * d + ↑c * ↑c * z ≠ 0 := by rw [mul_assoc, ← mul_add, add_comm] exact mul_ne_zero hc h_denom replace h : (a * d - b * c : ℂ) = (1 : ℂ) := by norm_cast field_simp linear_combination (-(z * (c : ℂ) ^ 2) - c * d) * h end UpperHalfPlane
Analysis\Complex\UpperHalfPlane\Exp.lean
/- Copyright (c) 2024 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Complex.UpperHalfPlane.Basic /-! # Exp on the upper half plane This file contains lemmas about the exponential function on the upper half plane. Useful for q-expansions of modular forms. -/ open Real Complex UpperHalfPlane theorem UpperHalfPlane.abs_exp_two_pi_I_lt_one (z : ℍ) : ‖(Complex.exp (2 * π * Complex.I * z))‖ < 1 := by simp only [coe_I, Complex.norm_eq_abs, Complex.abs_exp, mul_re, re_ofNat, ofReal_re, im_ofNat, ofReal_im, mul_zero, sub_zero, Complex.I_re, mul_im, zero_mul, add_zero, Complex.I_im, mul_one, sub_self, coe_re, coe_im, zero_sub, exp_lt_one_iff, Left.neg_neg_iff] positivity
Analysis\Complex\UpperHalfPlane\FunctionsBoundedAtInfty.lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import Mathlib.Algebra.Module.Submodule.Basic import Mathlib.Analysis.Complex.UpperHalfPlane.Basic import Mathlib.Order.Filter.ZeroAndBoundedAtFilter /-! # Bounded at infinity For complex valued functions on the upper half plane, this file defines the filter `UpperHalfPlane.atImInfty` required for defining when functions are bounded at infinity and zero at infinity. Both of which are relevant for defining modular forms. -/ open Complex Filter open scoped Topology UpperHalfPlane noncomputable section namespace UpperHalfPlane /-- Filter for approaching `i∞`. -/ def atImInfty := Filter.atTop.comap UpperHalfPlane.im theorem atImInfty_basis : atImInfty.HasBasis (fun _ => True) fun i : ℝ => im ⁻¹' Set.Ici i := Filter.HasBasis.comap UpperHalfPlane.im Filter.atTop_basis theorem atImInfty_mem (S : Set ℍ) : S ∈ atImInfty ↔ ∃ A : ℝ, ∀ z : ℍ, A ≤ im z → z ∈ S := by simp only [atImInfty_basis.mem_iff, true_and]; rfl /-- A function `f : ℍ → α` is bounded at infinity if it is bounded along `atImInfty`. -/ def IsBoundedAtImInfty {α : Type*} [Norm α] (f : ℍ → α) : Prop := BoundedAtFilter atImInfty f /-- A function `f : ℍ → α` is zero at infinity it is zero along `atImInfty`. -/ def IsZeroAtImInfty {α : Type*} [Zero α] [TopologicalSpace α] (f : ℍ → α) : Prop := ZeroAtFilter atImInfty f theorem zero_form_isBoundedAtImInfty {α : Type*} [NormedField α] : IsBoundedAtImInfty (0 : ℍ → α) := const_boundedAtFilter atImInfty (0 : α) /-- Module of functions that are zero at infinity. -/ def zeroAtImInftySubmodule (α : Type*) [NormedField α] : Submodule α (ℍ → α) := zeroAtFilterSubmodule _ atImInfty /-- Subalgebra of functions that are bounded at infinity. -/ def boundedAtImInftySubalgebra (α : Type*) [NormedField α] : Subalgebra α (ℍ → α) := boundedFilterSubalgebra _ atImInfty nonrec theorem IsBoundedAtImInfty.mul {f g : ℍ → ℂ} (hf : IsBoundedAtImInfty f) (hg : IsBoundedAtImInfty g) : IsBoundedAtImInfty (f * g) := by simpa only [Pi.one_apply, mul_one, norm_eq_abs] using hf.mul hg theorem bounded_mem (f : ℍ → ℂ) : IsBoundedAtImInfty f ↔ ∃ M A : ℝ, ∀ z : ℍ, A ≤ im z → abs (f z) ≤ M := by simp [IsBoundedAtImInfty, BoundedAtFilter, Asymptotics.isBigO_iff, Filter.Eventually, atImInfty_mem] theorem zero_at_im_infty (f : ℍ → ℂ) : IsZeroAtImInfty f ↔ ∀ ε : ℝ, 0 < ε → ∃ A : ℝ, ∀ z : ℍ, A ≤ im z → abs (f z) ≤ ε := (atImInfty_basis.tendsto_iff Metric.nhds_basis_closedBall).trans <| by simp only [true_and, mem_closedBall_zero_iff]; rfl end UpperHalfPlane
Analysis\Complex\UpperHalfPlane\Manifold.lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Topology import Mathlib.Geometry.Manifold.MFDeriv.Basic /-! # Manifold structure on the upper half plane. In this file we define the complex manifold structure on the upper half-plane. -/ open scoped UpperHalfPlane Manifold namespace UpperHalfPlane noncomputable instance : ChartedSpace ℂ ℍ := UpperHalfPlane.openEmbedding_coe.singletonChartedSpace instance : SmoothManifoldWithCorners 𝓘(ℂ) ℍ := UpperHalfPlane.openEmbedding_coe.singleton_smoothManifoldWithCorners 𝓘(ℂ) /-- The inclusion map `ℍ → ℂ` is a smooth map of manifolds. -/ theorem smooth_coe : Smooth 𝓘(ℂ) 𝓘(ℂ) ((↑) : ℍ → ℂ) := fun _ => contMDiffAt_extChartAt /-- The inclusion map `ℍ → ℂ` is a differentiable map of manifolds. -/ theorem mdifferentiable_coe : MDifferentiable 𝓘(ℂ) 𝓘(ℂ) ((↑) : ℍ → ℂ) := smooth_coe.mdifferentiable end UpperHalfPlane
Analysis\Complex\UpperHalfPlane\Metric.lean
/- 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.UpperHalfPlane.Topology import Mathlib.Analysis.SpecialFunctions.Arsinh import Mathlib.Geometry.Euclidean.Inversion.Basic /-! # Metric on the upper half-plane In this file we define a `MetricSpace` structure on the `UpperHalfPlane`. We use hyperbolic (Poincaré) distance given by `dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))` instead of the induced Euclidean distance because the hyperbolic distance is invariant under holomorphic automorphisms of the upper half-plane. However, we ensure that the projection to `TopologicalSpace` is definitionally equal to the induced topological space structure. We also prove that a metric ball/closed ball/sphere in Poincaré metric is a Euclidean ball/closed ball/sphere with another center and radius. -/ noncomputable section open scoped UpperHalfPlane ComplexConjugate NNReal Topology MatrixGroups open Set Metric Filter Real variable {z w : ℍ} {r R : ℝ} namespace UpperHalfPlane instance : Dist ℍ := ⟨fun z w => 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im)))⟩ theorem dist_eq (z w : ℍ) : dist z w = 2 * arsinh (dist (z : ℂ) w / (2 * √(z.im * w.im))) := rfl theorem sinh_half_dist (z w : ℍ) : sinh (dist z w / 2) = dist (z : ℂ) w / (2 * √(z.im * w.im)) := by rw [dist_eq, mul_div_cancel_left₀ (arsinh _) two_ne_zero, sinh_arsinh] theorem cosh_half_dist (z w : ℍ) : cosh (dist z w / 2) = dist (z : ℂ) (conj (w : ℂ)) / (2 * √(z.im * w.im)) := by rw [← sq_eq_sq, cosh_sq', sinh_half_dist, div_pow, div_pow, one_add_div, mul_pow, sq_sqrt] · congr 1 simp only [Complex.dist_eq, Complex.sq_abs, Complex.normSq_sub, Complex.normSq_conj, Complex.conj_conj, Complex.mul_re, Complex.conj_re, Complex.conj_im, coe_im] ring all_goals positivity theorem tanh_half_dist (z w : ℍ) : tanh (dist z w / 2) = dist (z : ℂ) w / dist (z : ℂ) (conj ↑w) := by rw [tanh_eq_sinh_div_cosh, sinh_half_dist, cosh_half_dist, div_div_div_comm, div_self, div_one] positivity theorem exp_half_dist (z w : ℍ) : exp (dist z w / 2) = (dist (z : ℂ) w + dist (z : ℂ) (conj ↑w)) / (2 * √(z.im * w.im)) := by rw [← sinh_add_cosh, sinh_half_dist, cosh_half_dist, add_div] theorem cosh_dist (z w : ℍ) : cosh (dist z w) = 1 + dist (z : ℂ) w ^ 2 / (2 * z.im * w.im) := by rw [dist_eq, cosh_two_mul, cosh_sq', add_assoc, ← two_mul, sinh_arsinh, div_pow, mul_pow, sq_sqrt, sq (2 : ℝ), mul_assoc, ← mul_div_assoc, mul_assoc, mul_div_mul_left] <;> positivity theorem sinh_half_dist_add_dist (a b c : ℍ) : sinh ((dist a b + dist b c) / 2) = (dist (a : ℂ) b * dist (c : ℂ) (conj ↑b) + dist (b : ℂ) c * dist (a : ℂ) (conj ↑b)) / (2 * √(a.im * c.im) * dist (b : ℂ) (conj ↑b)) := by simp only [add_div _ _ (2 : ℝ), sinh_add, sinh_half_dist, cosh_half_dist, div_mul_div_comm] rw [← add_div, Complex.dist_self_conj, coe_im, abs_of_pos b.im_pos, mul_comm (dist (b : ℂ) _), dist_comm (b : ℂ), Complex.dist_conj_comm, mul_mul_mul_comm, mul_mul_mul_comm _ _ _ b.im] congr 2 rw [sqrt_mul, sqrt_mul, sqrt_mul, mul_comm (√a.im), mul_mul_mul_comm, mul_self_sqrt, mul_comm] <;> exact (im_pos _).le protected theorem dist_comm (z w : ℍ) : dist z w = dist w z := by simp only [dist_eq, dist_comm (z : ℂ), mul_comm] theorem dist_le_iff_le_sinh : dist z w ≤ r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) ≤ sinh (r / 2) := by rw [← div_le_div_right (zero_lt_two' ℝ), ← sinh_le_sinh, sinh_half_dist] theorem dist_eq_iff_eq_sinh : dist z w = r ↔ dist (z : ℂ) w / (2 * √(z.im * w.im)) = sinh (r / 2) := by rw [← div_left_inj' (two_ne_zero' ℝ), ← sinh_inj, sinh_half_dist] theorem dist_eq_iff_eq_sq_sinh (hr : 0 ≤ r) : dist z w = r ↔ dist (z : ℂ) w ^ 2 / (4 * z.im * w.im) = sinh (r / 2) ^ 2 := by rw [dist_eq_iff_eq_sinh, ← sq_eq_sq, div_pow, mul_pow, sq_sqrt, mul_assoc] · norm_num all_goals positivity protected theorem dist_triangle (a b c : ℍ) : dist a c ≤ dist a b + dist b c := by rw [dist_le_iff_le_sinh, sinh_half_dist_add_dist, div_mul_eq_div_div _ _ (dist _ _), le_div_iff, div_mul_eq_mul_div] · gcongr exact EuclideanGeometry.mul_dist_le_mul_dist_add_mul_dist (a : ℂ) b c (conj (b : ℂ)) · rw [dist_comm, dist_pos, Ne, Complex.conj_eq_iff_im] exact b.im_ne_zero theorem dist_le_dist_coe_div_sqrt (z w : ℍ) : dist z w ≤ dist (z : ℂ) w / √(z.im * w.im) := by rw [dist_le_iff_le_sinh, ← div_mul_eq_div_div_swap, self_le_sinh_iff] positivity /-- An auxiliary `MetricSpace` instance on the upper half-plane. This instance has bad projection to `TopologicalSpace`. We replace it later. -/ def metricSpaceAux : MetricSpace ℍ where dist := dist dist_self z := by rw [dist_eq, dist_self, zero_div, arsinh_zero, mul_zero] dist_comm := UpperHalfPlane.dist_comm dist_triangle := UpperHalfPlane.dist_triangle eq_of_dist_eq_zero {z w} h := by simpa [dist_eq, Real.sqrt_eq_zero', (mul_pos z.im_pos w.im_pos).not_le, Set.ext_iff] using h open Complex theorem cosh_dist' (z w : ℍ) : Real.cosh (dist z w) = ((z.re - w.re) ^ 2 + z.im ^ 2 + w.im ^ 2) / (2 * z.im * w.im) := by field_simp [cosh_dist, Complex.dist_eq, Complex.sq_abs, normSq_apply] ring /-- Euclidean center of the circle with center `z` and radius `r` in the hyperbolic metric. -/ def center (z : ℍ) (r : ℝ) : ℍ := ⟨⟨z.re, z.im * Real.cosh r⟩, by positivity⟩ @[simp] theorem center_re (z r) : (center z r).re = z.re := rfl @[simp] theorem center_im (z r) : (center z r).im = z.im * Real.cosh r := rfl @[simp] theorem center_zero (z : ℍ) : center z 0 = z := ext' rfl <| by rw [center_im, Real.cosh_zero, mul_one] theorem dist_coe_center_sq (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) ^ 2 = 2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2 := by have H : 2 * z.im * w.im ≠ 0 := by positivity simp only [Complex.dist_eq, Complex.sq_abs, normSq_apply, coe_re, coe_im, center_re, center_im, cosh_dist', mul_div_cancel₀ _ H, sub_sq z.im, mul_pow, Real.cosh_sq, sub_re, sub_im, mul_sub, ← sq] ring theorem dist_coe_center (z w : ℍ) (r : ℝ) : dist (z : ℂ) (w.center r) = √(2 * z.im * w.im * (Real.cosh (dist z w) - Real.cosh r) + (w.im * Real.sinh r) ^ 2) := by rw [← sqrt_sq dist_nonneg, dist_coe_center_sq] theorem cmp_dist_eq_cmp_dist_coe_center (z w : ℍ) (r : ℝ) : cmp (dist z w) r = cmp (dist (z : ℂ) (w.center r)) (w.im * Real.sinh r) := by letI := metricSpaceAux cases' lt_or_le r 0 with hr₀ hr₀ · trans Ordering.gt exacts [(hr₀.trans_le dist_nonneg).cmp_eq_gt, ((mul_neg_of_pos_of_neg w.im_pos (sinh_neg_iff.2 hr₀)).trans_le dist_nonneg).cmp_eq_gt.symm] have hr₀' : 0 ≤ w.im * Real.sinh r := by positivity have hzw₀ : 0 < 2 * z.im * w.im := by positivity simp only [← cosh_strictMonoOn.cmp_map_eq dist_nonneg hr₀, ← (pow_left_strictMonoOn two_ne_zero).cmp_map_eq dist_nonneg hr₀', dist_coe_center_sq] rw [← cmp_mul_pos_left hzw₀, ← cmp_sub_zero, ← mul_sub, ← cmp_add_right, zero_add] theorem dist_eq_iff_dist_coe_center_eq : dist z w = r ↔ dist (z : ℂ) (w.center r) = w.im * Real.sinh r := eq_iff_eq_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) @[simp] theorem dist_self_center (z : ℍ) (r : ℝ) : dist (z : ℂ) (z.center r) = z.im * (Real.cosh r - 1) := by rw [dist_of_re_eq (z.center_re r).symm, dist_comm, Real.dist_eq, mul_sub, mul_one] exact abs_of_nonneg (sub_nonneg.2 <| le_mul_of_one_le_right z.im_pos.le (one_le_cosh _)) @[simp] theorem dist_center_dist (z w : ℍ) : dist (z : ℂ) (w.center (dist z w)) = w.im * Real.sinh (dist z w) := dist_eq_iff_dist_coe_center_eq.1 rfl theorem dist_lt_iff_dist_coe_center_lt : dist z w < r ↔ dist (z : ℂ) (w.center r) < w.im * Real.sinh r := lt_iff_lt_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) theorem lt_dist_iff_lt_dist_coe_center : r < dist z w ↔ w.im * Real.sinh r < dist (z : ℂ) (w.center r) := lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r) theorem dist_le_iff_dist_coe_center_le : dist z w ≤ r ↔ dist (z : ℂ) (w.center r) ≤ w.im * Real.sinh r := le_iff_le_of_cmp_eq_cmp (cmp_dist_eq_cmp_dist_coe_center z w r) theorem le_dist_iff_le_dist_coe_center : r < dist z w ↔ w.im * Real.sinh r < dist (z : ℂ) (w.center r) := lt_iff_lt_of_cmp_eq_cmp (cmp_eq_cmp_symm.1 <| cmp_dist_eq_cmp_dist_coe_center z w r) /-- For two points on the same vertical line, the distance is equal to the distance between the logarithms of their imaginary parts. -/ nonrec theorem dist_of_re_eq (h : z.re = w.re) : dist z w = dist (log z.im) (log w.im) := by have h₀ : 0 < z.im / w.im := by positivity rw [dist_eq_iff_dist_coe_center_eq, Real.dist_eq, ← abs_sinh, ← log_div z.im_ne_zero w.im_ne_zero, sinh_log h₀, dist_of_re_eq, coe_im, coe_im, center_im, cosh_abs, cosh_log h₀, inv_div] <;> [skip; exact h] nth_rw 4 [← abs_of_pos w.im_pos] simp only [← _root_.abs_mul, coe_im, Real.dist_eq] congr 1 field_simp ring /-- Hyperbolic distance between two points is greater than or equal to the distance between the logarithms of their imaginary parts. -/ theorem dist_log_im_le (z w : ℍ) : dist (log z.im) (log w.im) ≤ dist z w := calc dist (log z.im) (log w.im) = dist (mk ⟨0, z.im⟩ z.im_pos) (mk ⟨0, w.im⟩ w.im_pos) := Eq.symm <| dist_of_re_eq rfl _ ≤ dist z w := by simp_rw [dist_eq] dsimp only [coe_mk, mk_im] gcongr simpa [sqrt_sq_eq_abs] using Complex.abs_im_le_abs (z - w) theorem im_le_im_mul_exp_dist (z w : ℍ) : z.im ≤ w.im * Real.exp (dist z w) := by rw [← div_le_iff' w.im_pos, ← exp_log z.im_pos, ← exp_log w.im_pos, ← Real.exp_sub, exp_le_exp] exact (le_abs_self _).trans (dist_log_im_le z w) theorem im_div_exp_dist_le (z w : ℍ) : z.im / Real.exp (dist z w) ≤ w.im := (div_le_iff (exp_pos _)).2 (im_le_im_mul_exp_dist z w) /-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance and the imaginary part of one of the points. -/ theorem dist_coe_le (z w : ℍ) : dist (z : ℂ) w ≤ w.im * (Real.exp (dist z w) - 1) := calc dist (z : ℂ) w ≤ dist (z : ℂ) (w.center (dist z w)) + dist (w : ℂ) (w.center (dist z w)) := dist_triangle_right _ _ _ _ = w.im * (Real.exp (dist z w) - 1) := by rw [dist_center_dist, dist_self_center, ← mul_add, ← add_sub_assoc, Real.sinh_add_cosh] /-- An upper estimate on the complex distance between two points in terms of the hyperbolic distance and the imaginary part of one of the points. -/ theorem le_dist_coe (z w : ℍ) : w.im * (1 - Real.exp (-dist z w)) ≤ dist (z : ℂ) w := calc w.im * (1 - Real.exp (-dist z w)) = dist (z : ℂ) (w.center (dist z w)) - dist (w : ℂ) (w.center (dist z w)) := by rw [dist_center_dist, dist_self_center, ← Real.cosh_sub_sinh]; ring _ ≤ dist (z : ℂ) w := sub_le_iff_le_add.2 <| dist_triangle _ _ _ /-- The hyperbolic metric on the upper half plane. We ensure that the projection to `TopologicalSpace` is definitionally equal to the subtype topology. -/ instance : MetricSpace ℍ := metricSpaceAux.replaceTopology <| by refine le_antisymm (continuous_id_iff_le.1 ?_) ?_ · refine (@continuous_iff_continuous_dist ℍ ℍ metricSpaceAux.toPseudoMetricSpace _ _).2 ?_ have : ∀ x : ℍ × ℍ, 2 * √(x.1.im * x.2.im) ≠ 0 := fun x => by positivity -- `continuity` fails to apply `Continuous.div` apply_rules [Continuous.div, Continuous.mul, continuous_const, Continuous.arsinh, Continuous.dist, continuous_coe.comp, continuous_fst, continuous_snd, Real.continuous_sqrt.comp, continuous_im.comp] · letI : MetricSpace ℍ := metricSpaceAux refine le_of_nhds_le_nhds fun z => ?_ rw [nhds_induced] refine (nhds_basis_ball.le_basis_iff (nhds_basis_ball.comap _)).2 fun R hR => ?_ have h₁ : 1 < R / im z + 1 := lt_add_of_pos_left _ (div_pos hR z.im_pos) have h₀ : 0 < R / im z + 1 := one_pos.trans h₁ refine ⟨log (R / im z + 1), Real.log_pos h₁, ?_⟩ refine fun w hw => (dist_coe_le w z).trans_lt ?_ rwa [← lt_div_iff' z.im_pos, sub_lt_iff_lt_add, ← Real.lt_log_iff_exp_lt h₀] theorem im_pos_of_dist_center_le {z : ℍ} {r : ℝ} {w : ℂ} (h : dist w (center z r) ≤ z.im * Real.sinh r) : 0 < w.im := calc 0 < z.im * (Real.cosh r - Real.sinh r) := mul_pos z.im_pos (sub_pos.2 <| sinh_lt_cosh _) _ = (z.center r).im - z.im * Real.sinh r := mul_sub _ _ _ _ ≤ (z.center r).im - dist (z.center r : ℂ) w := sub_le_sub_left (by rwa [dist_comm]) _ _ ≤ w.im := sub_le_comm.1 <| (le_abs_self _).trans (abs_im_le_abs <| z.center r - w) theorem image_coe_closedBall (z : ℍ) (r : ℝ) : ((↑) : ℍ → ℂ) '' closedBall (α := ℍ) z r = closedBall ↑(z.center r) (z.im * Real.sinh r) := by ext w; constructor · rintro ⟨w, hw, rfl⟩ exact dist_le_iff_dist_coe_center_le.1 hw · intro hw lift w to ℍ using im_pos_of_dist_center_le hw exact mem_image_of_mem _ (dist_le_iff_dist_coe_center_le.2 hw) theorem image_coe_ball (z : ℍ) (r : ℝ) : ((↑) : ℍ → ℂ) '' ball (α := ℍ) z r = ball ↑(z.center r) (z.im * Real.sinh r) := by ext w; constructor · rintro ⟨w, hw, rfl⟩ exact dist_lt_iff_dist_coe_center_lt.1 hw · intro hw lift w to ℍ using im_pos_of_dist_center_le (ball_subset_closedBall hw) exact mem_image_of_mem _ (dist_lt_iff_dist_coe_center_lt.2 hw) theorem image_coe_sphere (z : ℍ) (r : ℝ) : ((↑) : ℍ → ℂ) '' sphere (α := ℍ) z r = sphere ↑(z.center r) (z.im * Real.sinh r) := by ext w; constructor · rintro ⟨w, hw, rfl⟩ exact dist_eq_iff_dist_coe_center_eq.1 hw · intro hw lift w to ℍ using im_pos_of_dist_center_le (sphere_subset_closedBall hw) exact mem_image_of_mem _ (dist_eq_iff_dist_coe_center_eq.2 hw) instance : ProperSpace ℍ := by refine ⟨fun z r => ?_⟩ rw [inducing_subtype_val.isCompact_iff (f := ((↑) : ℍ → ℂ)), image_coe_closedBall] apply isCompact_closedBall theorem isometry_vertical_line (a : ℝ) : Isometry fun y => mk ⟨a, exp y⟩ (exp_pos y) := by refine Isometry.of_dist_eq fun y₁ y₂ => ?_ rw [dist_of_re_eq] exacts [congr_arg₂ _ (log_exp _) (log_exp _), rfl] theorem isometry_real_vadd (a : ℝ) : Isometry (a +ᵥ · : ℍ → ℍ) := Isometry.of_dist_eq fun y₁ y₂ => by simp only [dist_eq, coe_vadd, vadd_im, dist_add_left] theorem isometry_pos_mul (a : { x : ℝ // 0 < x }) : Isometry (a • · : ℍ → ℍ) := by refine Isometry.of_dist_eq fun y₁ y₂ => ?_ simp only [dist_eq, coe_pos_real_smul, pos_real_im]; congr 2 rw [dist_smul₀, mul_mul_mul_comm, Real.sqrt_mul (mul_self_nonneg _), Real.sqrt_mul_self_eq_abs, Real.norm_eq_abs, mul_left_comm] exact mul_div_mul_left _ _ (mt _root_.abs_eq_zero.1 a.2.ne') /-- `SL(2, ℝ)` acts on the upper half plane as an isometry. -/ instance : IsometricSMul SL(2, ℝ) ℍ := ⟨fun g => by have h₀ : Isometry (fun z => ModularGroup.S • z : ℍ → ℍ) := Isometry.of_dist_eq fun y₁ y₂ => by have h₁ : 0 ≤ im y₁ * im y₂ := mul_nonneg y₁.property.le y₂.property.le have h₂ : Complex.abs (y₁ * y₂) ≠ 0 := by simp [y₁.ne_zero, y₂.ne_zero] simp only [dist_eq, modular_S_smul, inv_neg, neg_div, div_mul_div_comm, coe_mk, mk_im, div_one, Complex.inv_im, Complex.neg_im, coe_im, neg_neg, Complex.normSq_neg, mul_eq_mul_left_iff, Real.arsinh_inj, one_ne_zero, or_false_iff, dist_neg_neg, mul_neg, neg_mul, dist_inv_inv₀ y₁.ne_zero y₂.ne_zero, ← AbsoluteValue.map_mul, ← Complex.normSq_mul, Real.sqrt_div h₁, ← Complex.abs_apply, mul_div (2 : ℝ), div_div_div_comm, div_self h₂, Complex.norm_eq_abs] by_cases hc : g 1 0 = 0 · obtain ⟨u, v, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_eq_zero g hc rw [h] exact (isometry_real_vadd v).comp (isometry_pos_mul u) · obtain ⟨u, v, w, h⟩ := exists_SL2_smul_eq_of_apply_zero_one_ne_zero g hc rw [h] exact (isometry_real_vadd w).comp (h₀.comp <| (isometry_real_vadd v).comp <| isometry_pos_mul u)⟩ end UpperHalfPlane
Analysis\Complex\UpperHalfPlane\Topology.lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Basic import Mathlib.Analysis.Convex.Contractible import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.Convex.Complex import Mathlib.Analysis.Complex.ReImTopology import Mathlib.Topology.Homotopy.Contractible import Mathlib.Topology.PartialHomeomorph /-! # Topology on the upper half plane In this file we introduce a `TopologicalSpace` structure on the upper half plane and provide various instances. -/ noncomputable section open Set Filter Function TopologicalSpace Complex open scoped Filter Topology UpperHalfPlane namespace UpperHalfPlane instance : TopologicalSpace ℍ := instTopologicalSpaceSubtype theorem openEmbedding_coe : OpenEmbedding ((↑) : ℍ → ℂ) := IsOpen.openEmbedding_subtype_val <| isOpen_lt continuous_const Complex.continuous_im theorem embedding_coe : Embedding ((↑) : ℍ → ℂ) := embedding_subtype_val theorem continuous_coe : Continuous ((↑) : ℍ → ℂ) := embedding_coe.continuous theorem continuous_re : Continuous re := Complex.continuous_re.comp continuous_coe theorem continuous_im : Continuous im := Complex.continuous_im.comp continuous_coe instance : SecondCountableTopology ℍ := TopologicalSpace.Subtype.secondCountableTopology _ instance : T3Space ℍ := Subtype.t3Space instance : T4Space ℍ := inferInstance instance : ContractibleSpace ℍ := (convex_halfspace_im_gt 0).contractibleSpace ⟨I, one_pos.trans_eq I_im.symm⟩ instance : LocPathConnectedSpace ℍ := locPathConnected_of_isOpen <| isOpen_lt continuous_const Complex.continuous_im instance : NoncompactSpace ℍ := by refine ⟨fun h => ?_⟩ have : IsCompact (Complex.im ⁻¹' Ioi 0) := isCompact_iff_isCompact_univ.2 h replace := this.isClosed.closure_eq rw [closure_preimage_im, closure_Ioi, Set.ext_iff] at this exact absurd ((this 0).1 (@left_mem_Ici ℝ _ 0)) (@lt_irrefl ℝ _ 0) instance : LocallyCompactSpace ℍ := openEmbedding_coe.locallyCompactSpace section strips /-- The vertical strip of width `A` and height `B`, defined by elements whose real part has absolute value less than or equal to `A` and imaginary part is at least `B`. -/ def verticalStrip (A B : ℝ) := {z : ℍ | |z.re| ≤ A ∧ B ≤ z.im} theorem mem_verticalStrip_iff (A B : ℝ) (z : ℍ) : z ∈ verticalStrip A B ↔ |z.re| ≤ A ∧ B ≤ z.im := Iff.rfl @[gcongr] lemma verticalStrip_mono {A B A' B' : ℝ} (hA : A ≤ A') (hB : B' ≤ B) : verticalStrip A B ⊆ verticalStrip A' B' := by rintro z ⟨hzre, hzim⟩ exact ⟨hzre.trans hA, hB.trans hzim⟩ @[gcongr] lemma verticalStrip_mono_left {A A'} (h : A ≤ A') (B) : verticalStrip A B ⊆ verticalStrip A' B := verticalStrip_mono h le_rfl @[gcongr] lemma verticalStrip_anti_right (A) {B B'} (h : B' ≤ B) : verticalStrip A B ⊆ verticalStrip A B' := verticalStrip_mono le_rfl h lemma subset_verticalStrip_of_isCompact {K : Set ℍ} (hK : IsCompact K) : ∃ A B : ℝ, 0 < B ∧ K ⊆ verticalStrip A B := by rcases K.eq_empty_or_nonempty with rfl | hne · exact ⟨1, 1, Real.zero_lt_one, empty_subset _⟩ obtain ⟨u, _, hu⟩ := hK.exists_isMaxOn hne (_root_.continuous_abs.comp continuous_re).continuousOn obtain ⟨v, _, hv⟩ := hK.exists_isMinOn hne continuous_im.continuousOn exact ⟨|re u|, im v, v.im_pos, fun k hk ↦ ⟨isMaxOn_iff.mp hu _ hk, isMinOn_iff.mp hv _ hk⟩⟩ theorem ModularGroup_T_zpow_mem_verticalStrip (z : ℍ) {N : ℕ} (hn : 0 < N) : ∃ n : ℤ, ModularGroup.T ^ (N * n) • z ∈ verticalStrip N z.im := by let n := Int.floor (z.re/N) use -n rw [modular_T_zpow_smul z (N * -n)] refine ⟨?_, (by simp only [mul_neg, Int.cast_neg, Int.cast_mul, Int.cast_natCast, vadd_im, le_refl])⟩ have h : (N * (-n : ℝ) +ᵥ z).re = -N * Int.floor (z.re / N) + z.re := by simp only [Int.cast_natCast, mul_neg, vadd_re, neg_mul] norm_cast at * rw [h, add_comm] simp only [neg_mul, Int.cast_neg, Int.cast_mul, Int.cast_natCast] have hnn : (0 : ℝ) < (N : ℝ) := by norm_cast at * have h2 : z.re + -(N * n) = z.re - n * N := by ring rw [h2, abs_eq_self.2 (Int.sub_floor_div_mul_nonneg (z.re : ℝ) hnn)] apply (Int.sub_floor_div_mul_lt (z.re : ℝ) hnn).le end strips /-- A continuous section `ℂ → ℍ` of the natural inclusion map, bundled as a `PartialHomeomorph`. -/ def ofComplex : PartialHomeomorph ℂ ℍ := (openEmbedding_coe.toPartialHomeomorph _).symm /-- Extend a function on `ℍ` arbitrarily to a function on all of `ℂ`. -/ scoped notation "↑ₕ" f => f ∘ ofComplex lemma ofComplex_apply (z : ℍ) : ofComplex (z : ℂ) = z := OpenEmbedding.toPartialHomeomorph_left_inv .. lemma comp_ofComplex (f : ℍ → ℂ) (z : ℍ) : (↑ₕ f) z = f z := by rw [Function.comp_apply, ofComplex_apply] end UpperHalfPlane
Analysis\Convex\AmpleSet.lean
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Floris van Doorn -/ import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.NormedSpace.Connected import Mathlib.LinearAlgebra.AffineSpace.ContinuousAffineEquiv /-! # Ample subsets of real vector spaces In this file we study ample sets in real vector spaces. A set is ample if all its connected component have full convex hull. Ample sets are an important ingredient for defining ample differential relations. ## Main results - `ampleSet_empty` and `ampleSet_univ`: the empty set and `univ` are ample - `AmpleSet.union`: the union of two ample sets is ample - `AmpleSet.{pre}image`: being ample is invariant under continuous affine equivalences; `AmpleSet.{pre}image_iff` are "iff" versions of these - `AmpleSet.vadd`: in particular, ample-ness is invariant under affine translations - `AmpleSet.of_one_lt_codim`: a linear subspace of codimension at least two has an ample complement. This is the crucial geometric ingredient which allows to apply convex integration to the theory of immersions in positive codimension. ## Implementation notes A priori, the definition of ample subset asks for a vector space structure and a topology on the ambient type without any link between those structures. In practice, we care most about using these for finite dimensional vector spaces with their natural topology. All vector spaces in the file are real vector spaces. While the definition generalises to other connected fields, that is not useful in practice. ## Tags ample set -/ /-! ## Definition and invariance -/ open Set variable {F : Type*} [AddCommGroup F] [Module ℝ F] [TopologicalSpace F] /-- A subset of a topological real vector space is ample if the convex hull of each of its connected components is the full space. -/ def AmpleSet (s : Set F) : Prop := ∀ x ∈ s, convexHull ℝ (connectedComponentIn s x) = univ /-- A whole vector space is ample. -/ @[simp] theorem ampleSet_univ {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] : AmpleSet (univ : Set F) := by intro x _ rw [connectedComponentIn_univ, PreconnectedSpace.connectedComponent_eq_univ, convexHull_univ] /-- The empty set in a vector space is ample. -/ @[simp] theorem ampleSet_empty : AmpleSet (∅ : Set F) := fun _ ↦ False.elim namespace AmpleSet /-- The union of two ample sets is ample. -/ theorem union {s t : Set F} (hs : AmpleSet s) (ht : AmpleSet t) : AmpleSet (s ∪ t) := by intro x hx rcases hx with (h | h) <;> -- The connected component of `x ∈ s` in `s ∪ t` contains the connected component of `x` in `s`, -- hence is also full; similarly for `t`. [have hx := hs x h; have hx := ht x h] <;> rw [← Set.univ_subset_iff, ← hx] <;> apply convexHull_mono <;> apply connectedComponentIn_mono <;> [apply subset_union_left; apply subset_union_right] variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] /-- Images of ample sets under continuous affine equivalences are ample. -/ theorem image {s : Set E} (h : AmpleSet s) (L : E ≃ᵃL[ℝ] F) : AmpleSet (L '' s) := forall_mem_image.mpr fun x hx ↦ calc (convexHull ℝ) (connectedComponentIn (L '' s) (L x)) _ = (convexHull ℝ) (L '' (connectedComponentIn s x)) := .symm <| congrArg _ <| L.toHomeomorph.image_connectedComponentIn hx _ = L '' (convexHull ℝ (connectedComponentIn s x)) := .symm <| L.toAffineMap.image_convexHull _ _ = univ := by rw [h x hx, image_univ, L.surjective.range_eq] /-- A set is ample iff its image under a continuous affine equivalence is. -/ theorem image_iff {s : Set E} (L : E ≃ᵃL[ℝ] F) : AmpleSet (L '' s) ↔ AmpleSet s := ⟨fun h ↦ (L.symm_image_image s) ▸ h.image L.symm, fun h ↦ h.image L⟩ /-- Pre-images of ample sets under continuous affine equivalences are ample. -/ theorem preimage {s : Set F} (h : AmpleSet s) (L : E ≃ᵃL[ℝ] F) : AmpleSet (L ⁻¹' s) := by rw [← L.image_symm_eq_preimage] exact h.image L.symm /-- A set is ample iff its pre-image under a continuous affine equivalence is. -/ theorem preimage_iff {s : Set F} (L : E ≃ᵃL[ℝ] F) : AmpleSet (L ⁻¹' s) ↔ AmpleSet s := ⟨fun h ↦ L.image_preimage s ▸ h.image L, fun h ↦ h.preimage L⟩ open scoped Pointwise /-- Affine translations of ample sets are ample. -/ theorem vadd [ContinuousAdd E] {s : Set E} (h : AmpleSet s) {y : E} : AmpleSet (y +ᵥ s) := h.image (ContinuousAffineEquiv.constVAdd ℝ E y) /-- A set is ample iff its affine translation is. -/ theorem vadd_iff [ContinuousAdd E] {s : Set E} {y : E} : AmpleSet (y +ᵥ s) ↔ AmpleSet s := AmpleSet.image_iff (ContinuousAffineEquiv.constVAdd ℝ E y) /-! ## Subspaces of codimension at least two have ample complement -/ section Codimension /-- Let `E` be a linear subspace in a real vector space. If `E` has codimension at least two, its complement is ample. -/ theorem of_one_lt_codim [TopologicalAddGroup F] [ContinuousSMul ℝ F] {E : Submodule ℝ F} (hcodim : 1 < Module.rank ℝ (F ⧸ E)) : AmpleSet (Eᶜ : Set F) := fun x hx ↦ by rw [E.connectedComponentIn_eq_self_of_one_lt_codim hcodim hx, eq_univ_iff_forall] intro y by_cases h : y ∈ E · obtain ⟨z, hz⟩ : ∃ z, z ∉ E := by rw [← not_forall, ← Submodule.eq_top_iff'] rintro rfl simp [rank_zero_iff.2 inferInstance] at hcodim refine segment_subset_convexHull ?_ ?_ (mem_segment_sub_add y z) <;> simpa [sub_eq_add_neg, Submodule.add_mem_iff_right _ h] · exact subset_convexHull ℝ (Eᶜ : Set F) h end Codimension end AmpleSet
Analysis\Convex\Basic.lean
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov, Yaël Dillies -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Analysis.Convex.Star import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace /-! # Convex sets and functions in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `Convex 𝕜 s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment 𝕜 x y`. * `stdSimplex 𝕜 ι`: The standard simplex in `ι → 𝕜` (currently requires `Fintype ι`). It is the intersection of the positive quadrant with the hyperplane `s.sum = 1`. We also provide various equivalent versions of the definitions above, prove that some specific sets are convex. ## TODO Generalize all this file to affine spaces. -/ variable {𝕜 E F β : Type*} open LinearMap Set open scoped Convex Pointwise /-! ### Convexity of sets -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E) {x : E} /-- Convexity of sets. -/ def Convex : Prop := ∀ ⦃x : E⦄, x ∈ s → StarConvex 𝕜 x s variable {𝕜 s} theorem Convex.starConvex (hs : Convex 𝕜 s) (hx : x ∈ s) : StarConvex 𝕜 x s := hs hx theorem convex_iff_segment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := forall₂_congr fun _ _ => starConvex_iff_segment_subset theorem Convex.segment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : [x -[𝕜] y] ⊆ s := convex_iff_segment_subset.1 h hx hy theorem Convex.openSegment_subset (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s := (openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hx hy) /-- Alternative definition of set convexity, in terms of pointwise set operations. -/ theorem convex_iff_pointwise_add_subset : Convex 𝕜 s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • s + b • s ⊆ s := Iff.intro (by rintro hA a b ha hb hab w ⟨au, ⟨u, hu, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩ exact hA hu hv ha hb hab) fun h x hx y hy a b ha hb hab => (h ha hb hab) (Set.add_mem_add ⟨_, hx, rfl⟩ ⟨_, hy, rfl⟩) alias ⟨Convex.set_combo_subset, _⟩ := convex_iff_pointwise_add_subset theorem convex_empty : Convex 𝕜 (∅ : Set E) := fun _ => False.elim theorem convex_univ : Convex 𝕜 (Set.univ : Set E) := fun _ _ => starConvex_univ _ theorem Convex.inter {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ∩ t) := fun _ hx => (hs hx.1).inter (ht hx.2) theorem convex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, Convex 𝕜 s) : Convex 𝕜 (⋂₀ S) := fun _ hx => starConvex_sInter fun _ hs => h _ hs <| hx _ hs theorem convex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, Convex 𝕜 (s i)) : Convex 𝕜 (⋂ i, s i) := sInter_range s ▸ convex_sInter <| forall_mem_range.2 h theorem convex_iInter₂ {ι : Sort*} {κ : ι → Sort*} {s : ∀ i, κ i → Set E} (h : ∀ i j, Convex 𝕜 (s i j)) : Convex 𝕜 (⋂ (i) (j), s i j) := convex_iInter fun i => convex_iInter <| h i theorem Convex.prod {s : Set E} {t : Set F} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s ×ˢ t) := fun _ hx => (hs hx.1).prod (ht hx.2) theorem convex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)] {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → Convex 𝕜 (t i)) : Convex 𝕜 (s.pi t) := fun _ hx => starConvex_pi fun _ hi => ht hi <| hx _ hi theorem Directed.convex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s) (hc : ∀ ⦃i : ι⦄, Convex 𝕜 (s i)) : Convex 𝕜 (⋃ i, s i) := by rintro x hx y hy a b ha hb hab rw [mem_iUnion] at hx hy ⊢ obtain ⟨i, hx⟩ := hx obtain ⟨j, hy⟩ := hy obtain ⟨k, hik, hjk⟩ := hdir i j exact ⟨k, hc (hik hx) (hjk hy) ha hb hab⟩ theorem DirectedOn.convex_sUnion {c : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) c) (hc : ∀ ⦃A : Set E⦄, A ∈ c → Convex 𝕜 A) : Convex 𝕜 (⋃₀ c) := by rw [sUnion_eq_iUnion] exact (directedOn_iff_directed.1 hdir).convex_iUnion fun A => hc A.2 end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E} {x : E} theorem convex_iff_openSegment_subset : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s := forall₂_congr fun _ => starConvex_iff_openSegment_subset theorem convex_iff_forall_pos : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := forall₂_congr fun _ => starConvex_iff_forall_pos theorem convex_iff_pairwise_pos : Convex 𝕜 s ↔ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine convex_iff_forall_pos.trans ⟨fun h x hx y hy _ => h hx hy, ?_⟩ intro h x hx y hy a b ha hb hab obtain rfl | hxy := eq_or_ne x y · rwa [Convex.combo_self hab] · exact h hx hy hxy ha hb hab theorem Convex.starConvex_iff (hs : Convex 𝕜 s) (h : s.Nonempty) : StarConvex 𝕜 x s ↔ x ∈ s := ⟨fun hxs => hxs.mem h, hs.starConvex⟩ protected theorem Set.Subsingleton.convex {s : Set E} (h : s.Subsingleton) : Convex 𝕜 s := convex_iff_pairwise_pos.mpr (h.pairwise _) theorem convex_singleton (c : E) : Convex 𝕜 ({c} : Set E) := subsingleton_singleton.convex theorem convex_zero : Convex 𝕜 (0 : Set E) := convex_singleton _ theorem convex_segment (x y : E) : Convex 𝕜 [x -[𝕜] y] := by rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ a b ha hb hab refine ⟨a * ap + b * aq, a * bp + b * bq, add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq), add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), ?_, ?_⟩ · rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab] · simp_rw [add_smul, mul_smul, smul_add] exact add_add_add_comm _ _ _ _ theorem Convex.linear_image (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ a b ha hb hab exact ⟨a • x + b • y, hs hx hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩ theorem Convex.is_linear_image (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) : Convex 𝕜 (f '' s) := hs.linear_image <| hf.mk' f theorem Convex.linear_preimage {s : Set F} (hs : Convex 𝕜 s) (f : E →ₗ[𝕜] F) : Convex 𝕜 (f ⁻¹' s) := by intro x hx y hy a b ha hb hab rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hx hy ha hb hab theorem Convex.is_linear_preimage {s : Set F} (hs : Convex 𝕜 s) {f : E → F} (hf : IsLinearMap 𝕜 f) : Convex 𝕜 (f ⁻¹' s) := hs.linear_preimage <| hf.mk' f theorem Convex.add {t : Set E} (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s + t) := by rw [← add_image_prod] exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add variable (𝕜 E) /-- The convex sets form an additive submonoid under pointwise addition. -/ def convexAddSubmonoid : AddSubmonoid (Set E) where carrier := {s : Set E | Convex 𝕜 s} zero_mem' := convex_zero add_mem' := Convex.add @[simp, norm_cast] theorem coe_convexAddSubmonoid : ↑(convexAddSubmonoid 𝕜 E) = {s : Set E | Convex 𝕜 s} := rfl variable {𝕜 E} @[simp] theorem mem_convexAddSubmonoid {s : Set E} : s ∈ convexAddSubmonoid 𝕜 E ↔ Convex 𝕜 s := Iff.rfl theorem convex_list_sum {l : List (Set E)} (h : ∀ i ∈ l, Convex 𝕜 i) : Convex 𝕜 l.sum := (convexAddSubmonoid 𝕜 E).list_sum_mem h theorem convex_multiset_sum {s : Multiset (Set E)} (h : ∀ i ∈ s, Convex 𝕜 i) : Convex 𝕜 s.sum := (convexAddSubmonoid 𝕜 E).multiset_sum_mem _ h theorem convex_sum {ι} {s : Finset ι} (t : ι → Set E) (h : ∀ i ∈ s, Convex 𝕜 (t i)) : Convex 𝕜 (∑ i ∈ s, t i) := (convexAddSubmonoid 𝕜 E).sum_mem h theorem Convex.vadd (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 (z +ᵥ s) := by simp_rw [← image_vadd, vadd_eq_add, ← singleton_add] exact (convex_singleton _).add hs theorem Convex.translate (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) '' s) := hs.vadd _ /-- The translation of a convex set is also convex. -/ theorem Convex.translate_preimage_right (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => z + x) ⁻¹' s) := by intro x hx y hy a b ha hb hab have h := hs hx hy ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h /-- The translation of a convex set is also convex. -/ theorem Convex.translate_preimage_left (hs : Convex 𝕜 s) (z : E) : Convex 𝕜 ((fun x => x + z) ⁻¹' s) := by simpa only [add_comm] using hs.translate_preimage_right z section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_Iic (r : β) : Convex 𝕜 (Iic r) := fun x hx y hy a b ha hb hab => calc a • x + b • y ≤ a • r + b • r := add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb) _ = r := Convex.combo_self hab _ theorem convex_Ici (r : β) : Convex 𝕜 (Ici r) := @convex_Iic 𝕜 βᵒᵈ _ _ _ _ r theorem convex_Icc (r s : β) : Convex 𝕜 (Icc r s) := Ici_inter_Iic.subst ((convex_Ici r).inter <| convex_Iic s) theorem convex_halfspace_le {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w ≤ r } := (convex_Iic r).is_linear_preimage h theorem convex_halfspace_ge {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r ≤ f w } := (convex_Ici r).is_linear_preimage h theorem convex_hyperplane {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w = r } := by simp_rw [le_antisymm_iff] exact (convex_halfspace_le h r).inter (convex_halfspace_ge h r) end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_Iio (r : β) : Convex 𝕜 (Iio r) := by intro x hx y hy a b ha hb hab obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [zero_smul, zero_add, hab, one_smul] rw [mem_Iio] at hx hy calc a • x + b • y < a • r + b • r := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx ha') (smul_le_smul_of_nonneg_left hy.le hb) _ = r := Convex.combo_self hab _ theorem convex_Ioi (r : β) : Convex 𝕜 (Ioi r) := convex_Iio (β := βᵒᵈ) r theorem convex_Ioo (r s : β) : Convex 𝕜 (Ioo r s) := Ioi_inter_Iio.subst ((convex_Ioi r).inter <| convex_Iio s) theorem convex_Ico (r s : β) : Convex 𝕜 (Ico r s) := Ici_inter_Iio.subst ((convex_Ici r).inter <| convex_Iio s) theorem convex_Ioc (r s : β) : Convex 𝕜 (Ioc r s) := Ioi_inter_Iic.subst ((convex_Ioi r).inter <| convex_Iic s) theorem convex_halfspace_lt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | f w < r } := (convex_Iio r).is_linear_preimage h theorem convex_halfspace_gt {f : E → β} (h : IsLinearMap 𝕜 f) (r : β) : Convex 𝕜 { w | r < f w } := (convex_Ioi r).is_linear_preimage h end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] theorem convex_uIcc (r s : β) : Convex 𝕜 (uIcc r s) := convex_Icc _ _ end LinearOrderedAddCommMonoid end Module end AddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid E] [OrderedAddCommMonoid β] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} {f : E → β} theorem MonotoneOn.convex_le (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy _ _ ha hb hab => ⟨hs hx.1 hy.1 ha hb hab, (hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans (max_rec' { x | f x ≤ r } hx.2 hy.2)⟩ theorem MonotoneOn.convex_lt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := fun x hx y hy _ _ ha hb hab => ⟨hs hx.1 hy.1 ha hb hab, (hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans_lt (max_rec' { x | f x < r } hx.2 hy.2)⟩ theorem MonotoneOn.convex_ge (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := MonotoneOn.convex_le (E := Eᵒᵈ) (β := βᵒᵈ) hf.dual hs r theorem MonotoneOn.convex_gt (hf : MonotoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := MonotoneOn.convex_lt (E := Eᵒᵈ) (β := βᵒᵈ) hf.dual hs r theorem AntitoneOn.convex_le (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := MonotoneOn.convex_ge (β := βᵒᵈ) hf hs r theorem AntitoneOn.convex_lt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := MonotoneOn.convex_gt (β := βᵒᵈ) hf hs r theorem AntitoneOn.convex_ge (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := MonotoneOn.convex_le (β := βᵒᵈ) hf hs r theorem AntitoneOn.convex_gt (hf : AntitoneOn f s) (hs : Convex 𝕜 s) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := MonotoneOn.convex_lt (β := βᵒᵈ) hf hs r theorem Monotone.convex_le (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) theorem Monotone.convex_lt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) theorem Monotone.convex_ge (hf : Monotone f) (r : β) : Convex 𝕜 { x | r ≤ f x } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_ge convex_univ r) theorem Monotone.convex_gt (hf : Monotone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r) theorem Antitone.convex_le (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x ≤ r } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_le convex_univ r) theorem Antitone.convex_lt (hf : Antitone f) (r : β) : Convex 𝕜 { x | f x < r } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_lt convex_univ r) theorem Antitone.convex_ge (hf : Antitone f) (r : β) : Convex 𝕜 { x | r ≤ f x } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_ge convex_univ r) theorem Antitone.convex_gt (hf : Antitone f) (r : β) : Convex 𝕜 { x | r < f x } := Set.sep_univ.subst ((hf.antitoneOn univ).convex_gt convex_univ r) end LinearOrderedAddCommMonoid end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} theorem Convex.smul (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 (c • s) := hs.linear_image (LinearMap.lsmul _ _ c) theorem Convex.smul_preimage (hs : Convex 𝕜 s) (c : 𝕜) : Convex 𝕜 ((fun z => c • z) ⁻¹' s) := hs.linear_preimage (LinearMap.lsmul _ _ c) theorem Convex.affinity (hs : Convex 𝕜 s) (z : E) (c : 𝕜) : Convex 𝕜 ((fun x => z + c • x) '' s) := by simpa only [← image_smul, ← image_vadd, image_image] using (hs.smul c).vadd z end AddCommMonoid end OrderedCommSemiring section StrictOrderedCommSemiring variable [StrictOrderedCommSemiring 𝕜] [AddCommGroup E] [Module 𝕜 E] theorem convex_openSegment (a b : E) : Convex 𝕜 (openSegment 𝕜 a b) := by rw [convex_iff_openSegment_subset] rintro p ⟨ap, bp, hap, hbp, habp, rfl⟩ q ⟨aq, bq, haq, hbq, habq, rfl⟩ z ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨a * ap + b * aq, a * bp + b * bq, by positivity, by positivity, ?_, ?_⟩ · rw [add_add_add_comm, ← mul_add, ← mul_add, habp, habq, mul_one, mul_one, hab] · simp_rw [add_smul, mul_smul, smul_add, add_add_add_comm] end StrictOrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s t : Set E} @[simp] theorem convex_vadd (a : E) : Convex 𝕜 (a +ᵥ s) ↔ Convex 𝕜 s := ⟨fun h ↦ by simpa using h.vadd (-a), fun h ↦ h.vadd _⟩ theorem Convex.add_smul_mem (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • y ∈ s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul] rw [h] exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _) theorem Convex.smul_mem_of_zero_mem (hs : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : t • x ∈ s := by simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht theorem Convex.mapsTo_lineMap (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : MapsTo (AffineMap.lineMap x y) (Icc (0 : 𝕜) 1) s := by simpa only [mapsTo', segment_eq_image_lineMap] using h.segment_subset hx hy theorem Convex.lineMap_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜} (ht : t ∈ Icc 0 1) : AffineMap.lineMap x y t ∈ s := h.mapsTo_lineMap hx hy ht theorem Convex.add_smul_sub_mem (h : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {t : 𝕜} (ht : t ∈ Icc (0 : 𝕜) 1) : x + t • (y - x) ∈ s := by rw [add_comm] exact h.lineMap_mem hx hy ht /-- Affine subspaces are convex. -/ theorem AffineSubspace.convex (Q : AffineSubspace 𝕜 E) : Convex 𝕜 (Q : Set E) := fun x hx y hy a b _ _ hab ↦ by simpa [Convex.combo_eq_smul_sub_add hab] using Q.2 _ hy hx hx /-- The preimage of a convex set under an affine map is convex. -/ theorem Convex.affine_preimage (f : E →ᵃ[𝕜] F) {s : Set F} (hs : Convex 𝕜 s) : Convex 𝕜 (f ⁻¹' s) := fun _ hx => (hs hx).affine_preimage _ /-- The image of a convex set under an affine map is convex. -/ theorem Convex.affine_image (f : E →ᵃ[𝕜] F) (hs : Convex 𝕜 s) : Convex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ exact (hs hx).affine_image _ theorem Convex.neg (hs : Convex 𝕜 s) : Convex 𝕜 (-s) := hs.is_linear_preimage IsLinearMap.isLinearMap_neg theorem Convex.sub (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (s - t) := by rw [sub_eq_add_neg] exact hs.add ht.neg end AddCommGroup end OrderedRing section LinearOrderedRing variable [LinearOrderedRing 𝕜] [AddCommMonoid E] theorem Convex_subadditive_le [SMul 𝕜 E] {f : E → 𝕜} (hf1 : ∀ x y, f (x + y) ≤ (f x) + (f y)) (hf2 : ∀ ⦃c⦄ x, 0 ≤ c → f (c • x) ≤ c * f x) (B : 𝕜) : Convex 𝕜 { x | f x ≤ B } := by rw [convex_iff_segment_subset] rintro x hx y hy z ⟨a, b, ha, hb, hs, rfl⟩ calc _ ≤ a • (f x) + b • (f y) := le_trans (hf1 _ _) (add_le_add (hf2 x ha) (hf2 y hb)) _ ≤ a • B + b • B := add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb) _ ≤ B := by rw [← add_smul, hs, one_smul] end LinearOrderedRing section LinearOrderedField variable [LinearOrderedField 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} /-- Alternative definition of set convexity, using division. -/ theorem convex_iff_div : Convex 𝕜 s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s := forall₂_congr fun _ _ => starConvex_iff_div theorem Convex.mem_smul_of_zero_mem (h : Convex 𝕜 s) {x : E} (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) : x ∈ t • s := by rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne'] exact h.smul_mem_of_zero_mem zero_mem hx ⟨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one ht⟩ theorem Convex.exists_mem_add_smul_eq (h : Convex 𝕜 s) {x y : E} {p q : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (hp : 0 ≤ p) (hq : 0 ≤ q) : ∃ z ∈ s, (p + q) • z = p • x + q • y := by rcases _root_.em (p = 0 ∧ q = 0) with (⟨rfl, rfl⟩ | hpq) · use x, hx simp · replace hpq : 0 < p + q := (add_nonneg hp hq).lt_of_ne' (mt (add_eq_zero_iff' hp hq).1 hpq) refine ⟨_, convex_iff_div.1 h hx hy hp hq hpq, ?_⟩ simp only [smul_add, smul_smul, mul_div_cancel₀ _ hpq.ne'] theorem Convex.add_smul (h_conv : Convex 𝕜 s) {p q : 𝕜} (hp : 0 ≤ p) (hq : 0 ≤ q) : (p + q) • s = p • s + q • s := (add_smul_subset _ _ _).antisymm <| by rintro _ ⟨_, ⟨v₁, h₁, rfl⟩, _, ⟨v₂, h₂, rfl⟩, rfl⟩ exact h_conv.exists_mem_add_smul_eq h₁ h₂ hp hq end AddCommGroup end LinearOrderedField /-! #### Convex sets in an ordered space Relates `Convex` and `OrdConnected`. -/ section theorem Set.OrdConnected.convex_of_chain [OrderedSemiring 𝕜] [OrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) (h : IsChain (· ≤ ·) s) : Convex 𝕜 s := by refine convex_iff_segment_subset.mpr fun x hx y hy => ?_ obtain hxy | hyx := h.total hx hy · exact (segment_subset_Icc hxy).trans (hs.out hx hy) · rw [segment_symm] exact (segment_subset_Icc hyx).trans (hs.out hy hx) theorem Set.OrdConnected.convex [OrderedSemiring 𝕜] [LinearOrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} (hs : s.OrdConnected) : Convex 𝕜 s := hs.convex_of_chain <| isChain_of_trichotomous s theorem convex_iff_ordConnected [LinearOrderedField 𝕜] {s : Set 𝕜} : Convex 𝕜 s ↔ s.OrdConnected := by simp_rw [convex_iff_segment_subset, segment_eq_uIcc, ordConnected_iff_uIcc_subset] alias ⟨Convex.ordConnected, _⟩ := convex_iff_ordConnected end /-! #### Convexity of submodules/subspaces -/ namespace Submodule variable [OrderedSemiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] protected theorem convex (K : Submodule 𝕜 E) : Convex 𝕜 (↑K : Set E) := by repeat' intro refine add_mem (smul_mem _ _ ?_) (smul_mem _ _ ?_) <;> assumption protected theorem starConvex (K : Submodule 𝕜 E) : StarConvex 𝕜 (0 : E) K := K.convex K.zero_mem end Submodule /-! ### Simplex -/ section Simplex section OrderedSemiring variable (𝕜) (ι : Type*) [OrderedSemiring 𝕜] [Fintype ι] /-- The standard simplex in the space of functions `ι → 𝕜` is the set of vectors with non-negative coordinates with total sum `1`. This is the free object in the category of convex spaces. -/ def stdSimplex : Set (ι → 𝕜) := { f | (∀ x, 0 ≤ f x) ∧ ∑ x, f x = 1 } theorem stdSimplex_eq_inter : stdSimplex 𝕜 ι = (⋂ x, { f | 0 ≤ f x }) ∩ { f | ∑ x, f x = 1 } := by ext f simp only [stdSimplex, Set.mem_inter_iff, Set.mem_iInter, Set.mem_setOf_eq] theorem convex_stdSimplex : Convex 𝕜 (stdSimplex 𝕜 ι) := by refine fun f hf g hg a b ha hb hab => ⟨fun x => ?_, ?_⟩ · apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1] · erw [Finset.sum_add_distrib] simp only [Pi.smul_apply] -- Porting note: `erw` failed to rewrite with `← Finset.smul_sum` rw [← Finset.smul_sum, ← Finset.smul_sum, hf.2, hg.2, smul_eq_mul, smul_eq_mul, mul_one, mul_one] exact hab @[nontriviality] lemma stdSimplex_of_subsingleton [Subsingleton 𝕜] : stdSimplex 𝕜 ι = univ := eq_univ_of_forall fun _ ↦ ⟨fun _ ↦ (Subsingleton.elim _ _).le, Subsingleton.elim _ _⟩ /-- The standard simplex in the zero-dimensional space is empty. -/ lemma stdSimplex_of_isEmpty_index [IsEmpty ι] [Nontrivial 𝕜] : stdSimplex 𝕜 ι = ∅ := eq_empty_of_forall_not_mem <| by rintro f ⟨-, hf⟩; simp at hf lemma stdSimplex_unique [Unique ι] : stdSimplex 𝕜 ι = {fun _ ↦ 1} := by refine eq_singleton_iff_unique_mem.2 ⟨⟨fun _ ↦ zero_le_one, Fintype.sum_unique _⟩, ?_⟩ rintro f ⟨-, hf⟩ rw [Fintype.sum_unique] at hf exact funext (Unique.forall_iff.2 hf) variable {ι} [DecidableEq ι] theorem single_mem_stdSimplex (i : ι) : Pi.single i 1 ∈ stdSimplex 𝕜 ι := ⟨le_update_iff.2 ⟨zero_le_one, fun _ _ ↦ le_rfl⟩, by simp⟩ theorem ite_eq_mem_stdSimplex (i : ι) : (if i = · then (1 : 𝕜) else 0) ∈ stdSimplex 𝕜 ι := by simpa only [@eq_comm _ i, ← Pi.single_apply] using single_mem_stdSimplex 𝕜 i #adaptation_note /-- as of `nightly-2024-03-11`, we need a type annotation on the segment in the following two lemmas. -/ /-- The edges are contained in the simplex. -/ lemma segment_single_subset_stdSimplex (i j : ι) : ([Pi.single i 1 -[𝕜] Pi.single j 1] : Set (ι → 𝕜)) ⊆ stdSimplex 𝕜 ι := (convex_stdSimplex 𝕜 ι).segment_subset (single_mem_stdSimplex _ _) (single_mem_stdSimplex _ _) lemma stdSimplex_fin_two : stdSimplex 𝕜 (Fin 2) = ([Pi.single 0 1 -[𝕜] Pi.single 1 1] : Set (Fin 2 → 𝕜)) := by refine Subset.antisymm ?_ (segment_single_subset_stdSimplex 𝕜 (0 : Fin 2) 1) rintro f ⟨hf₀, hf₁⟩ rw [Fin.sum_univ_two] at hf₁ refine ⟨f 0, f 1, hf₀ 0, hf₀ 1, hf₁, funext <| Fin.forall_fin_two.2 ?_⟩ simp end OrderedSemiring section OrderedRing variable (𝕜) [OrderedRing 𝕜] /-- The standard one-dimensional simplex in `Fin 2 → 𝕜` is equivalent to the unit interval. -/ @[simps (config := .asFn)] def stdSimplexEquivIcc : stdSimplex 𝕜 (Fin 2) ≃ Icc (0 : 𝕜) 1 where toFun f := ⟨f.1 0, f.2.1 _, f.2.2 ▸ Finset.single_le_sum (fun i _ ↦ f.2.1 i) (Finset.mem_univ _)⟩ invFun x := ⟨![x, 1 - x], Fin.forall_fin_two.2 ⟨x.2.1, sub_nonneg.2 x.2.2⟩, calc ∑ i : Fin 2, ![(x : 𝕜), 1 - x] i = x + (1 - x) := Fin.sum_univ_two _ _ = 1 := add_sub_cancel _ _⟩ left_inv f := Subtype.eq <| funext <| Fin.forall_fin_two.2 <| .intro rfl <| calc (1 : 𝕜) - f.1 0 = f.1 0 + f.1 1 - f.1 0 := by rw [← Fin.sum_univ_two f.1, f.2.2] _ = f.1 1 := add_sub_cancel_left _ _ right_inv x := Subtype.eq rfl end OrderedRing end Simplex
Analysis\Convex\Between.lean
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Segment import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.FieldSimp /-! # Betweenness in affine spaces This file defines notions of a point in an affine space being between two given points. ## Main definitions * `affineSegment R x y`: The segment of points weakly between `x` and `y`. * `Wbtw R x y z`: The point `y` is weakly between `x` and `z`. * `Sbtw R x y z`: The point `y` is strictly between `x` and `z`. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap section OrderedRing variable [OrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The segment of points weakly between `x` and `y`. When convexity is refactored to support abstract affine combination spaces, this will no longer need to be a separate definition from `segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a refactoring, as distinct from versions involving `+` or `-` in a module. -/ def affineSegment (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by rw [segment_eq_image_lineMap, affineSegment] theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by refine Set.ext fun z => ?_ constructor <;> · rintro ⟨t, ht, hxy⟩ refine ⟨1 - t, ?_, ?_⟩ · rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero] · rwa [lineMap_apply_one_sub] theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y := ⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩ theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y := ⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩ @[simp] theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by simp_rw [affineSegment, lineMap_same, AffineMap.coe_const, Function.const, (Set.nonempty_Icc.mpr zero_le_one).image_const] variable {R} @[simp] theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) : f '' affineSegment R x y = affineSegment R (f x) (f y) := by rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap] rfl variable (R) @[simp] theorem affineSegment_const_vadd_image (x y : P) (v : V) : (v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) := affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y @[simp] theorem affineSegment_vadd_const_image (x y : V) (p : P) : (· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) := affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y @[simp] theorem affineSegment_const_vsub_image (x y p : P) : (p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) := affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y @[simp] theorem affineSegment_vsub_const_image (x y p : P) : (· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) := affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y variable {R} @[simp] theorem mem_const_vadd_affineSegment {x y z : P} (v : V) : v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image] @[simp] theorem mem_vadd_const_affineSegment {x y z : V} (p : P) : z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image] @[simp] theorem mem_const_vsub_affineSegment {x y z : P} (p : P) : p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image] @[simp] theorem mem_vsub_const_affineSegment {x y z : P} (p : P) : z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image] variable (R) /-- The point `y` is weakly between `x` and `z`. -/ def Wbtw (x y z : P) : Prop := y ∈ affineSegment R x z /-- The point `y` is strictly between `x` and `z`. -/ def Sbtw (x y z : P) : Prop := Wbtw R x y z ∧ y ≠ x ∧ y ≠ z variable {R} lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by rw [Wbtw, affineSegment_eq_segment] theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by rw [Wbtw, ← affineSegment_image] exact Set.mem_image_of_mem _ h theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine ⟨fun h => ?_, fun h => h.map _⟩ rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff] @[simp] theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine Function.Injective.wbtw_map_iff (?_ : Function.Injective f.toAffineMap) exact f.injective @[simp] theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by refine Function.Injective.sbtw_map_iff (?_ : Function.Injective f.toAffineMap) exact f.injective @[simp] theorem wbtw_const_vadd_iff {x y z : P} (v : V) : Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z := mem_const_vadd_affineSegment _ @[simp] theorem wbtw_vadd_const_iff {x y z : V} (p : P) : Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z := mem_vadd_const_affineSegment _ @[simp] theorem wbtw_const_vsub_iff {x y z : P} (p : P) : Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z := mem_const_vsub_affineSegment _ @[simp] theorem wbtw_vsub_const_iff {x y z : P} (p : P) : Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z := mem_vsub_const_affineSegment _ @[simp] theorem sbtw_const_vadd_iff {x y z : P} (v : V) : Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff, (AddAction.injective v).ne_iff] @[simp] theorem sbtw_vadd_const_iff {x y z : V} (p : P) : Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff, (vadd_right_injective p).ne_iff] @[simp] theorem sbtw_const_vsub_iff {x y z : P} (p : P) : Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff, (vsub_right_injective p).ne_iff] @[simp] theorem sbtw_vsub_const_iff {x y z : P} (p : P) : Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff, (vsub_left_injective p).ne_iff] theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z := h.1 theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x := h.2.1 theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y := h.2.1.symm theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z := h.2.2 theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y := h.2.2.symm theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) : y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩ rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho) · exfalso exact hyx (lineMap_apply_zero _ _) · exfalso exact hyz (lineMap_apply_one _ _) · exact ⟨t, ho, rfl⟩ theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by rcases h with ⟨r, ⟨-, rfl⟩⟩ exact lineMap_mem_affineSpan_pair _ _ _ theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by rw [Wbtw, Wbtw, affineSegment_comm] alias ⟨Wbtw.symm, _⟩ := wbtw_comm theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm] alias ⟨Sbtw.symm, _⟩ := sbtw_comm variable (R) @[simp] theorem wbtw_self_left (x y : P) : Wbtw R x x y := left_mem_affineSegment _ _ _ @[simp] theorem wbtw_self_right (x y : P) : Wbtw R x y y := right_mem_affineSegment _ _ _ @[simp] theorem wbtw_self_iff {x y : P} : Wbtw R x y x ↔ y = x := by refine ⟨fun h => ?_, fun h => ?_⟩ · -- Porting note: Originally `simpa [Wbtw, affineSegment] using h` have ⟨_, _, h₂⟩ := h rw [h₂.symm, lineMap_same_apply] · rw [h] exact wbtw_self_left R x x @[simp] theorem not_sbtw_self_left (x y : P) : ¬Sbtw R x x y := fun h => h.ne_left rfl @[simp] theorem not_sbtw_self_right (x y : P) : ¬Sbtw R x y y := fun h => h.ne_right rfl variable {R} theorem Wbtw.left_ne_right_of_ne_left {x y z : P} (h : Wbtw R x y z) (hne : y ≠ x) : x ≠ z := by rintro rfl rw [wbtw_self_iff] at h exact hne h theorem Wbtw.left_ne_right_of_ne_right {x y z : P} (h : Wbtw R x y z) (hne : y ≠ z) : x ≠ z := by rintro rfl rw [wbtw_self_iff] at h exact hne h theorem Sbtw.left_ne_right {x y z : P} (h : Sbtw R x y z) : x ≠ z := h.wbtw.left_ne_right_of_ne_left h.2.1 theorem sbtw_iff_mem_image_Ioo_and_ne [NoZeroSMulDivisors R V] {x y z : P} : Sbtw R x y z ↔ y ∈ lineMap x z '' Set.Ioo (0 : R) 1 ∧ x ≠ z := by refine ⟨fun h => ⟨h.mem_image_Ioo, h.left_ne_right⟩, fun h => ?_⟩ rcases h with ⟨⟨t, ht, rfl⟩, hxz⟩ refine ⟨⟨t, Set.mem_Icc_of_Ioo ht, rfl⟩, ?_⟩ rw [lineMap_apply, ← @vsub_ne_zero V, ← @vsub_ne_zero V _ _ _ _ z, vadd_vsub_assoc, vsub_self, vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z x, ← @neg_one_smul R, ← add_smul, ← sub_eq_add_neg] simp [smul_ne_zero, sub_eq_zero, ht.1.ne.symm, ht.2.ne, hxz.symm] variable (R) @[simp] theorem not_sbtw_self (x y : P) : ¬Sbtw R x y x := fun h => h.left_ne_right rfl theorem wbtw_swap_left_iff [NoZeroSMulDivisors R V] {x y : P} (z : P) : Wbtw R x y z ∧ Wbtw R y x z ↔ x = y := by constructor · rintro ⟨hxyz, hyxz⟩ rcases hxyz with ⟨ty, hty, rfl⟩ rcases hyxz with ⟨tx, htx, hx⟩ rw [lineMap_apply, lineMap_apply, ← add_vadd] at hx rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, vsub_vadd_eq_vsub_sub, smul_sub, smul_smul, ← sub_smul, ← add_smul, smul_eq_zero] at hx rcases hx with (h | h) · nth_rw 1 [← mul_one tx] at h rw [← mul_sub, add_eq_zero_iff_neg_eq] at h have h' : ty = 0 := by refine le_antisymm ?_ hty.1 rw [← h, Left.neg_nonpos_iff] exact mul_nonneg htx.1 (sub_nonneg.2 hty.2) simp [h'] · rw [vsub_eq_zero_iff_eq] at h rw [h, lineMap_same_apply] · rintro rfl exact ⟨wbtw_self_left _ _ _, wbtw_self_left _ _ _⟩ theorem wbtw_swap_right_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} : Wbtw R x y z ∧ Wbtw R x z y ↔ y = z := by rw [wbtw_comm, wbtw_comm (z := y), eq_comm] exact wbtw_swap_left_iff R x theorem wbtw_rotate_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} : Wbtw R x y z ∧ Wbtw R z x y ↔ x = y := by rw [wbtw_comm, wbtw_swap_right_iff, eq_comm] variable {R} theorem Wbtw.swap_left_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R y x z ↔ x = y := by rw [← wbtw_swap_left_iff R z, and_iff_right h] theorem Wbtw.swap_right_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R x z y ↔ y = z := by rw [← wbtw_swap_right_iff R x, and_iff_right h] theorem Wbtw.rotate_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R z x y ↔ x = y := by rw [← wbtw_rotate_iff R x, and_iff_right h] theorem Sbtw.not_swap_left [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R y x z := fun hs => h.left_ne (h.wbtw.swap_left_iff.1 hs) theorem Sbtw.not_swap_right [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R x z y := fun hs => h.ne_right (h.wbtw.swap_right_iff.1 hs) theorem Sbtw.not_rotate [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R z x y := fun hs => h.left_ne (h.wbtw.rotate_iff.1 hs) @[simp] theorem wbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} : Wbtw R x (lineMap x y r) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := by by_cases hxy : x = y · rw [hxy, lineMap_same_apply] simp rw [or_iff_right hxy, Wbtw, affineSegment, (lineMap_injective R hxy).mem_set_image] @[simp] theorem sbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} : Sbtw R x (lineMap x y r) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := by rw [sbtw_iff_mem_image_Ioo_and_ne, and_comm, and_congr_right] intro hxy rw [(lineMap_injective R hxy).mem_set_image] @[simp] theorem wbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} : Wbtw R x (r * (y - x) + x) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := wbtw_lineMap_iff @[simp] theorem sbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} : Sbtw R x (r * (y - x) + x) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := sbtw_lineMap_iff @[simp] theorem wbtw_zero_one_iff {x : R} : Wbtw R 0 x 1 ↔ x ∈ Set.Icc (0 : R) 1 := by rw [Wbtw, affineSegment, Set.mem_image] simp_rw [lineMap_apply_ring] simp @[simp] theorem wbtw_one_zero_iff {x : R} : Wbtw R 1 x 0 ↔ x ∈ Set.Icc (0 : R) 1 := by rw [wbtw_comm, wbtw_zero_one_iff] @[simp] theorem sbtw_zero_one_iff {x : R} : Sbtw R 0 x 1 ↔ x ∈ Set.Ioo (0 : R) 1 := by rw [Sbtw, wbtw_zero_one_iff, Set.mem_Icc, Set.mem_Ioo] exact ⟨fun h => ⟨h.1.1.lt_of_ne (Ne.symm h.2.1), h.1.2.lt_of_ne h.2.2⟩, fun h => ⟨⟨h.1.le, h.2.le⟩, h.1.ne', h.2.ne⟩⟩ @[simp] theorem sbtw_one_zero_iff {x : R} : Sbtw R 1 x 0 ↔ x ∈ Set.Ioo (0 : R) 1 := by rw [sbtw_comm, sbtw_zero_one_iff] theorem Wbtw.trans_left {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R w x z := by rcases h₁ with ⟨t₁, ht₁, rfl⟩ rcases h₂ with ⟨t₂, ht₂, rfl⟩ refine ⟨t₂ * t₁, ⟨mul_nonneg ht₂.1 ht₁.1, mul_le_one ht₂.2 ht₁.1 ht₁.2⟩, ?_⟩ rw [lineMap_apply, lineMap_apply, lineMap_vsub_left, smul_smul] theorem Wbtw.trans_right {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w y z := by rw [wbtw_comm] at * exact h₁.trans_left h₂ theorem Wbtw.trans_sbtw_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R w x z := by refine ⟨h₁.trans_left h₂.wbtw, h₂.ne_left, ?_⟩ rintro rfl exact h₂.right_ne ((wbtw_swap_right_iff R w).1 ⟨h₁, h₂.wbtw⟩) theorem Wbtw.trans_sbtw_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w y z := by rw [wbtw_comm] at * rw [sbtw_comm] at * exact h₁.trans_sbtw_left h₂ theorem Sbtw.trans_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R w x z := h₁.wbtw.trans_sbtw_left h₂ theorem Sbtw.trans_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w y z := h₁.wbtw.trans_sbtw_right h₂ theorem Wbtw.trans_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) (h : y ≠ z) : x ≠ z := by rintro rfl exact h (h₁.swap_right_iff.1 h₂) theorem Wbtw.trans_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) (h : w ≠ x) : w ≠ y := by rintro rfl exact h (h₁.swap_left_iff.1 h₂) theorem Sbtw.trans_wbtw_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Wbtw R w x y) : x ≠ z := h₁.wbtw.trans_left_ne h₂ h₁.ne_right theorem Sbtw.trans_wbtw_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Wbtw R x y z) : w ≠ y := h₁.wbtw.trans_right_ne h₂ h₁.left_ne theorem Sbtw.affineCombination_of_mem_affineSpan_pair [NoZeroDivisors R] [NoZeroSMulDivisors R V] {ι : Type*} {p : ι → P} (ha : AffineIndependent R p) {w w₁ w₂ : ι → R} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (h : s.affineCombination R p w ∈ line[R, s.affineCombination R p w₁, s.affineCombination R p w₂]) {i : ι} (his : i ∈ s) (hs : Sbtw R (w₁ i) (w i) (w₂ i)) : Sbtw R (s.affineCombination R p w₁) (s.affineCombination R p w) (s.affineCombination R p w₂) := by rw [affineCombination_mem_affineSpan_pair ha hw hw₁ hw₂] at h rcases h with ⟨r, hr⟩ rw [hr i his, sbtw_mul_sub_add_iff] at hs change ∀ i ∈ s, w i = (r • (w₂ - w₁) + w₁) i at hr rw [s.affineCombination_congr hr fun _ _ => rfl] rw [← s.weightedVSub_vadd_affineCombination, s.weightedVSub_const_smul, ← s.affineCombination_vsub, ← lineMap_apply, sbtw_lineMap_iff, and_iff_left hs.2, ← @vsub_ne_zero V, s.affineCombination_vsub] intro hz have hw₁w₂ : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, hw₁, hw₂, sub_self] refine hs.1 ?_ have ha' := ha s (w₁ - w₂) hw₁w₂ hz i his rwa [Pi.sub_apply, sub_eq_zero] at ha' end OrderedRing section StrictOrderedCommRing variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable {R} theorem Wbtw.sameRay_vsub {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ y) := by rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩ simp_rw [lineMap_apply] rcases ht0.lt_or_eq with (ht0' | rfl); swap; · simp rcases ht1.lt_or_eq with (ht1' | rfl); swap; · simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) simp only [vadd_vsub, smul_smul, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul] ring_nf theorem Wbtw.sameRay_vsub_left {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ x) := by rcases h with ⟨t, ⟨ht0, _⟩, rfl⟩ simpa [lineMap_apply] using SameRay.sameRay_nonneg_smul_left (z -ᵥ x) ht0 theorem Wbtw.sameRay_vsub_right {x y z : P} (h : Wbtw R x y z) : SameRay R (z -ᵥ x) (z -ᵥ y) := by rcases h with ⟨t, ⟨_, ht1⟩, rfl⟩ simpa [lineMap_apply, vsub_vadd_eq_vsub_sub, sub_smul] using SameRay.sameRay_nonneg_smul_right (z -ᵥ x) (sub_nonneg.2 ht1) end StrictOrderedCommRing section LinearOrderedRing variable [LinearOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable {R} /-- Suppose lines from two vertices of a triangle to interior points of the opposite side meet at `p`. Then `p` lies in the interior of the first (and by symmetry the other) segment from a vertex to the point on the opposite side. -/ theorem sbtw_of_sbtw_of_sbtw_of_mem_affineSpan_pair [NoZeroSMulDivisors R V] {t : Affine.Triangle R P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) {p₁ p₂ p : P} (h₁ : Sbtw R (t.points i₂) p₁ (t.points i₃)) (h₂ : Sbtw R (t.points i₁) p₂ (t.points i₃)) (h₁' : p ∈ line[R, t.points i₁, p₁]) (h₂' : p ∈ line[R, t.points i₂, p₂]) : Sbtw R (t.points i₁) p p₁ := by -- Should not be needed; see comments on local instances in `Data.Sign`. letI : DecidableRel ((· < ·) : R → R → Prop) := LinearOrderedRing.decidableLT have h₁₃ : i₁ ≠ i₃ := by rintro rfl simp at h₂ have h₂₃ : i₂ ≠ i₃ := by rintro rfl simp at h₁ have h3 : ∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃ := by clear h₁ h₂ h₁' h₂' -- Porting note: Originally `decide!` intro i fin_cases i <;> fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp at h₁₂ h₁₃ h₂₃ ⊢ have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by clear h₁ h₂ h₁' h₂' -- Porting note: Originally `decide!` fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp (config := {decide := true}) at h₁₂ h₁₃ h₂₃ ⊢ have hp : p ∈ affineSpan R (Set.range t.points) := by have hle : line[R, t.points i₁, p₁] ≤ affineSpan R (Set.range t.points) := by refine affineSpan_pair_le_of_mem_of_mem (mem_affineSpan R (Set.mem_range_self _)) ?_ have hle : line[R, t.points i₂, t.points i₃] ≤ affineSpan R (Set.range t.points) := by refine affineSpan_mono R ?_ simp [Set.insert_subset_iff] rw [AffineSubspace.le_def'] at hle exact hle _ h₁.wbtw.mem_affineSpan rw [AffineSubspace.le_def'] at hle exact hle _ h₁' have h₁i := h₁.mem_image_Ioo have h₂i := h₂.mem_image_Ioo rw [Set.mem_image] at h₁i h₂i rcases h₁i with ⟨r₁, ⟨hr₁0, hr₁1⟩, rfl⟩ rcases h₂i with ⟨r₂, ⟨hr₂0, hr₂1⟩, rfl⟩ rcases eq_affineCombination_of_mem_affineSpan_of_fintype hp with ⟨w, hw, rfl⟩ have h₁s := sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _) (Finset.mem_univ _) (Finset.mem_univ _) h₁₂ h₁₃ h₂₃ hr₁0 hr₁1 h₁' have h₂s := sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _) (Finset.mem_univ _) (Finset.mem_univ _) h₁₂.symm h₂₃ h₁₃ hr₂0 hr₂1 h₂' rw [← Finset.univ.affineCombination_affineCombinationSingleWeights R t.points (Finset.mem_univ i₁), ← Finset.univ.affineCombination_affineCombinationLineMapWeights t.points (Finset.mem_univ _) (Finset.mem_univ _)] at h₁' ⊢ refine Sbtw.affineCombination_of_mem_affineSpan_pair t.independent hw (Finset.univ.sum_affineCombinationSingleWeights R (Finset.mem_univ _)) (Finset.univ.sum_affineCombinationLineMapWeights (Finset.mem_univ _) (Finset.mem_univ _) _) h₁' (Finset.mem_univ i₁) ?_ rw [Finset.affineCombinationSingleWeights_apply_self, Finset.affineCombinationLineMapWeights_apply_of_ne h₁₂ h₁₃, sbtw_one_zero_iff] have hs : ∀ i : Fin 3, SignType.sign (w i) = SignType.sign (w i₃) := by intro i rcases h3 i with (rfl | rfl | rfl) · exact h₂s · exact h₁s · rfl have hss : SignType.sign (∑ i, w i) = 1 := by simp [hw] have hs' := sign_sum Finset.univ_nonempty (SignType.sign (w i₃)) fun i _ => hs i rw [hs'] at hss simp_rw [hss, sign_eq_one_iff] at hs refine ⟨hs i₁, ?_⟩ rw [hu] at hw rw [Finset.sum_insert, Finset.sum_insert, Finset.sum_singleton] at hw · by_contra hle rw [not_lt] at hle exact (hle.trans_lt (lt_add_of_pos_right _ (Left.add_pos (hs i₂) (hs i₃)))).ne' hw · simpa using h₂₃ · simpa [not_or] using ⟨h₁₂, h₁₃⟩ end LinearOrderedRing section LinearOrderedField variable [LinearOrderedField R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable {R} theorem wbtw_iff_left_eq_or_right_mem_image_Ici {x y z : P} : Wbtw R x y z ↔ x = y ∨ z ∈ lineMap x y '' Set.Ici (1 : R) := by refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩ rcases hr0.lt_or_eq with (hr0' | rfl) · rw [Set.mem_image] refine Or.inr ⟨r⁻¹, one_le_inv hr0' hr1, ?_⟩ simp only [lineMap_apply, smul_smul, vadd_vsub] rw [inv_mul_cancel hr0'.ne', one_smul, vsub_vadd] · simp · rcases h with (rfl | ⟨r, ⟨hr, rfl⟩⟩) · exact wbtw_self_left _ _ _ · rw [Set.mem_Ici] at hr refine ⟨r⁻¹, ⟨inv_nonneg.2 (zero_le_one.trans hr), inv_le_one hr⟩, ?_⟩ simp only [lineMap_apply, smul_smul, vadd_vsub] rw [inv_mul_cancel (one_pos.trans_le hr).ne', one_smul, vsub_vadd] theorem Wbtw.right_mem_image_Ici_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) : z ∈ lineMap x y '' Set.Ici (1 : R) := (wbtw_iff_left_eq_or_right_mem_image_Ici.1 h).resolve_left hne theorem Wbtw.right_mem_affineSpan_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) : z ∈ line[R, x, y] := by rcases h.right_mem_image_Ici_of_left_ne hne with ⟨r, ⟨-, rfl⟩⟩ exact lineMap_mem_affineSpan_pair _ _ _ theorem sbtw_iff_left_ne_and_right_mem_image_Ioi {x y z : P} : Sbtw R x y z ↔ x ≠ y ∧ z ∈ lineMap x y '' Set.Ioi (1 : R) := by refine ⟨fun h => ⟨h.left_ne, ?_⟩, fun h => ?_⟩ · obtain ⟨r, ⟨hr, rfl⟩⟩ := h.wbtw.right_mem_image_Ici_of_left_ne h.left_ne rw [Set.mem_Ici] at hr rcases hr.lt_or_eq with (hrlt | rfl) · exact Set.mem_image_of_mem _ hrlt · exfalso simp at h · rcases h with ⟨hne, r, hr, rfl⟩ rw [Set.mem_Ioi] at hr refine ⟨wbtw_iff_left_eq_or_right_mem_image_Ici.2 (Or.inr (Set.mem_image_of_mem _ (Set.mem_of_mem_of_subset hr Set.Ioi_subset_Ici_self))), hne.symm, ?_⟩ rw [lineMap_apply, ← @vsub_ne_zero V, vsub_vadd_eq_vsub_sub] nth_rw 1 [← one_smul R (y -ᵥ x)] rw [← sub_smul, smul_ne_zero_iff, vsub_ne_zero, sub_ne_zero] exact ⟨hr.ne, hne.symm⟩ theorem Sbtw.right_mem_image_Ioi {x y z : P} (h : Sbtw R x y z) : z ∈ lineMap x y '' Set.Ioi (1 : R) := (sbtw_iff_left_ne_and_right_mem_image_Ioi.1 h).2 theorem Sbtw.right_mem_affineSpan {x y z : P} (h : Sbtw R x y z) : z ∈ line[R, x, y] := h.wbtw.right_mem_affineSpan_of_left_ne h.left_ne theorem wbtw_iff_right_eq_or_left_mem_image_Ici {x y z : P} : Wbtw R x y z ↔ z = y ∨ x ∈ lineMap z y '' Set.Ici (1 : R) := by rw [wbtw_comm, wbtw_iff_left_eq_or_right_mem_image_Ici] theorem Wbtw.left_mem_image_Ici_of_right_ne {x y z : P} (h : Wbtw R x y z) (hne : z ≠ y) : x ∈ lineMap z y '' Set.Ici (1 : R) := h.symm.right_mem_image_Ici_of_left_ne hne theorem Wbtw.left_mem_affineSpan_of_right_ne {x y z : P} (h : Wbtw R x y z) (hne : z ≠ y) : x ∈ line[R, z, y] := h.symm.right_mem_affineSpan_of_left_ne hne theorem sbtw_iff_right_ne_and_left_mem_image_Ioi {x y z : P} : Sbtw R x y z ↔ z ≠ y ∧ x ∈ lineMap z y '' Set.Ioi (1 : R) := by rw [sbtw_comm, sbtw_iff_left_ne_and_right_mem_image_Ioi] theorem Sbtw.left_mem_image_Ioi {x y z : P} (h : Sbtw R x y z) : x ∈ lineMap z y '' Set.Ioi (1 : R) := h.symm.right_mem_image_Ioi theorem Sbtw.left_mem_affineSpan {x y z : P} (h : Sbtw R x y z) : x ∈ line[R, z, y] := h.symm.right_mem_affineSpan theorem wbtw_smul_vadd_smul_vadd_of_nonneg_of_le (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁) (hr₂ : r₁ ≤ r₂) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) := by refine ⟨r₁ / r₂, ⟨div_nonneg hr₁ (hr₁.trans hr₂), div_le_one_of_le hr₂ (hr₁.trans hr₂)⟩, ?_⟩ by_cases h : r₁ = 0; · simp [h] simp [lineMap_apply, smul_smul, ((hr₁.lt_of_ne' h).trans_le hr₂).ne.symm] theorem wbtw_or_wbtw_smul_vadd_of_nonneg (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) ∨ Wbtw R x (r₂ • v +ᵥ x) (r₁ • v +ᵥ x) := by rcases le_total r₁ r₂ with (h | h) · exact Or.inl (wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x v hr₁ h) · exact Or.inr (wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x v hr₂ h) theorem wbtw_smul_vadd_smul_vadd_of_nonpos_of_le (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0) (hr₂ : r₂ ≤ r₁) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) := by convert wbtw_smul_vadd_smul_vadd_of_nonneg_of_le x (-v) (Left.nonneg_neg_iff.2 hr₁) (neg_le_neg_iff.2 hr₂) using 1 <;> rw [neg_smul_neg] theorem wbtw_or_wbtw_smul_vadd_of_nonpos (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0) (hr₂ : r₂ ≤ 0) : Wbtw R x (r₁ • v +ᵥ x) (r₂ • v +ᵥ x) ∨ Wbtw R x (r₂ • v +ᵥ x) (r₁ • v +ᵥ x) := by rcases le_total r₁ r₂ with (h | h) · exact Or.inr (wbtw_smul_vadd_smul_vadd_of_nonpos_of_le x v hr₂ h) · exact Or.inl (wbtw_smul_vadd_smul_vadd_of_nonpos_of_le x v hr₁ h) theorem wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg (x : P) (v : V) {r₁ r₂ : R} (hr₁ : r₁ ≤ 0) (hr₂ : 0 ≤ r₂) : Wbtw R (r₁ • v +ᵥ x) x (r₂ • v +ᵥ x) := by convert wbtw_smul_vadd_smul_vadd_of_nonneg_of_le (r₁ • v +ᵥ x) v (Left.nonneg_neg_iff.2 hr₁) (neg_le_sub_iff_le_add.2 ((le_add_iff_nonneg_left r₁).2 hr₂)) using 1 <;> simp [sub_smul, ← add_vadd] theorem wbtw_smul_vadd_smul_vadd_of_nonneg_of_nonpos (x : P) (v : V) {r₁ r₂ : R} (hr₁ : 0 ≤ r₁) (hr₂ : r₂ ≤ 0) : Wbtw R (r₁ • v +ᵥ x) x (r₂ • v +ᵥ x) := by rw [wbtw_comm] exact wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg x v hr₂ hr₁ theorem Wbtw.trans_left_right {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R x y z := by rcases h₁ with ⟨t₁, ht₁, rfl⟩ rcases h₂ with ⟨t₂, ht₂, rfl⟩ refine ⟨(t₁ - t₂ * t₁) / (1 - t₂ * t₁), ⟨div_nonneg (sub_nonneg.2 (mul_le_of_le_one_left ht₁.1 ht₂.2)) (sub_nonneg.2 (mul_le_one ht₂.2 ht₁.1 ht₁.2)), div_le_one_of_le (sub_le_sub_right ht₁.2 _) (sub_nonneg.2 (mul_le_one ht₂.2 ht₁.1 ht₁.2))⟩, ?_⟩ simp only [lineMap_apply, smul_smul, ← add_vadd, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul, ← add_smul, vadd_vsub, vadd_right_cancel_iff, div_mul_eq_mul_div, div_sub_div_same] nth_rw 1 [← mul_one (t₁ - t₂ * t₁)] rw [← mul_sub, mul_div_assoc] by_cases h : 1 - t₂ * t₁ = 0 · rw [sub_eq_zero, eq_comm] at h rw [h] suffices t₁ = 1 by simp [this] exact eq_of_le_of_not_lt ht₁.2 fun ht₁lt => (mul_lt_one_of_nonneg_of_lt_one_right ht₂.2 ht₁.1 ht₁lt).ne h · rw [div_self h] ring_nf theorem Wbtw.trans_right_left {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w x y := by rw [wbtw_comm] at * exact h₁.trans_left_right h₂ theorem Sbtw.trans_left_right {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R x y z := ⟨h₁.wbtw.trans_left_right h₂.wbtw, h₂.right_ne, h₁.ne_right⟩ theorem Sbtw.trans_right_left {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w x y := ⟨h₁.wbtw.trans_right_left h₂.wbtw, h₁.ne_left, h₂.left_ne⟩ theorem Wbtw.collinear {x y z : P} (h : Wbtw R x y z) : Collinear R ({x, y, z} : Set P) := by rw [collinear_iff_exists_forall_eq_smul_vadd] refine ⟨x, z -ᵥ x, ?_⟩ intro p hp simp_rw [Set.mem_insert_iff, Set.mem_singleton_iff] at hp rcases hp with (rfl | rfl | rfl) · refine ⟨0, ?_⟩ simp · rcases h with ⟨t, -, rfl⟩ exact ⟨t, rfl⟩ · refine ⟨1, ?_⟩ simp theorem Collinear.wbtw_or_wbtw_or_wbtw {x y z : P} (h : Collinear R ({x, y, z} : Set P)) : Wbtw R x y z ∨ Wbtw R y z x ∨ Wbtw R z x y := by rw [collinear_iff_of_mem (Set.mem_insert _ _)] at h rcases h with ⟨v, h⟩ simp_rw [Set.mem_insert_iff, Set.mem_singleton_iff] at h have hy := h y (Or.inr (Or.inl rfl)) have hz := h z (Or.inr (Or.inr rfl)) rcases hy with ⟨ty, rfl⟩ rcases hz with ⟨tz, rfl⟩ rcases lt_trichotomy ty 0 with (hy0 | rfl | hy0) · rcases lt_trichotomy tz 0 with (hz0 | rfl | hz0) · rw [wbtw_comm (z := x)] rw [← or_assoc] exact Or.inl (wbtw_or_wbtw_smul_vadd_of_nonpos _ _ hy0.le hz0.le) · simp · exact Or.inr (Or.inr (wbtw_smul_vadd_smul_vadd_of_nonneg_of_nonpos _ _ hz0.le hy0.le)) · simp · rcases lt_trichotomy tz 0 with (hz0 | rfl | hz0) · refine Or.inr (Or.inr (wbtw_smul_vadd_smul_vadd_of_nonpos_of_nonneg _ _ hz0.le hy0.le)) · simp · rw [wbtw_comm (z := x)] rw [← or_assoc] exact Or.inl (wbtw_or_wbtw_smul_vadd_of_nonneg _ _ hy0.le hz0.le) theorem wbtw_iff_sameRay_vsub {x y z : P} : Wbtw R x y z ↔ SameRay R (y -ᵥ x) (z -ᵥ y) := by refine ⟨Wbtw.sameRay_vsub, fun h => ?_⟩ rcases h with (h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩) · rw [vsub_eq_zero_iff_eq] at h simp [h] · rw [vsub_eq_zero_iff_eq] at h simp [h] · refine ⟨r₂ / (r₁ + r₂), ⟨div_nonneg hr₂.le (add_nonneg hr₁.le hr₂.le), div_le_one_of_le (le_add_of_nonneg_left hr₁.le) (add_nonneg hr₁.le hr₂.le)⟩, ?_⟩ have h' : z = r₂⁻¹ • r₁ • (y -ᵥ x) +ᵥ y := by simp [h, hr₂.ne'] rw [eq_comm] simp only [lineMap_apply, h', vadd_vsub_assoc, smul_smul, ← add_smul, eq_vadd_iff_vsub_eq, smul_add] convert (one_smul R (y -ᵥ x)).symm field_simp [(add_pos hr₁ hr₂).ne', hr₂.ne'] ring variable (R) theorem wbtw_pointReflection (x y : P) : Wbtw R y x (pointReflection R x y) := by refine ⟨2⁻¹, ⟨by norm_num, by norm_num⟩, ?_⟩ rw [lineMap_apply, pointReflection_apply, vadd_vsub_assoc, ← two_smul R (x -ᵥ y)] simp theorem sbtw_pointReflection_of_ne {x y : P} (h : x ≠ y) : Sbtw R y x (pointReflection R x y) := by refine ⟨wbtw_pointReflection _ _ _, h, ?_⟩ nth_rw 1 [← pointReflection_self R x] exact (pointReflection_involutive R x).injective.ne h theorem wbtw_midpoint (x y : P) : Wbtw R x (midpoint R x y) y := by convert wbtw_pointReflection R (midpoint R x y) x rw [pointReflection_midpoint_left] theorem sbtw_midpoint_of_ne {x y : P} (h : x ≠ y) : Sbtw R x (midpoint R x y) y := by have h : midpoint R x y ≠ x := by simp [h] convert sbtw_pointReflection_of_ne R h rw [pointReflection_midpoint_left] end LinearOrderedField
Analysis\Convex\Body.lean
/- Copyright (c) 2022 Paul A. Reichert. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul A. Reichert -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Convex bodies This file contains the definition of the type `ConvexBody V` consisting of convex, compact, nonempty subsets of a real topological vector space `V`. `ConvexBody V` is a module over the nonnegative reals (`NNReal`) and a pseudo-metric space. If `V` is a normed space, `ConvexBody V` is a metric space. ## TODO - define positive convex bodies, requiring the interior to be nonempty - introduce support sets - Characterise the interaction of the distance with algebraic operations, eg `dist (a • K) (a • L) = ‖a‖ * dist K L`, `dist (a +ᵥ K) (a +ᵥ L) = dist K L` ## Tags convex, convex body -/ open scoped Pointwise Topology NNReal variable {V : Type*} /-- Let `V` be a real topological vector space. A subset of `V` is a convex body if and only if it is convex, compact, and nonempty. -/ structure ConvexBody (V : Type*) [TopologicalSpace V] [AddCommMonoid V] [SMul ℝ V] where /-- The **carrier set** underlying a convex body: the set of points contained in it -/ carrier : Set V /-- A convex body has convex carrier set -/ convex' : Convex ℝ carrier /-- A convex body has compact carrier set -/ isCompact' : IsCompact carrier /-- A convex body has non-empty carrier set -/ nonempty' : carrier.Nonempty namespace ConvexBody section TVS variable [TopologicalSpace V] [AddCommGroup V] [Module ℝ V] instance : SetLike (ConvexBody V) V where coe := ConvexBody.carrier coe_injective' K L h := by cases K cases L congr protected theorem convex (K : ConvexBody V) : Convex ℝ (K : Set V) := K.convex' protected theorem isCompact (K : ConvexBody V) : IsCompact (K : Set V) := K.isCompact' protected theorem isClosed [T2Space V] (K : ConvexBody V) : IsClosed (K : Set V) := K.isCompact.isClosed protected theorem nonempty (K : ConvexBody V) : (K : Set V).Nonempty := K.nonempty' @[ext] protected theorem ext {K L : ConvexBody V} (h : (K : Set V) = L) : K = L := SetLike.ext' h @[simp] theorem coe_mk (s : Set V) (h₁ h₂ h₃) : (mk s h₁ h₂ h₃ : Set V) = s := rfl /-- A convex body that is symmetric contains `0`. -/ theorem zero_mem_of_symmetric (K : ConvexBody V) (h_symm : ∀ x ∈ K, - x ∈ K) : 0 ∈ K := by obtain ⟨x, hx⟩ := K.nonempty rw [show 0 = (1/2 : ℝ) • x + (1/2 : ℝ) • (- x) by field_simp] apply convex_iff_forall_pos.mp K.convex hx (h_symm x hx) all_goals linarith section ContinuousAdd variable [ContinuousAdd V] instance : Add (ConvexBody V) where add K L := ⟨K + L, K.convex.add L.convex, K.isCompact.add L.isCompact, K.nonempty.add L.nonempty⟩ instance : Zero (ConvexBody V) where zero := ⟨0, convex_singleton 0, isCompact_singleton, Set.singleton_nonempty 0⟩ instance : SMul ℕ (ConvexBody V) where smul := nsmulRec -- Porting note: add @[simp, norm_cast]; we leave it out for now to reproduce mathlib3 behavior. theorem coe_nsmul : ∀ (n : ℕ) (K : ConvexBody V), ↑(n • K) = n • (K : Set V) | 0, _ => rfl | (n + 1), K => congr_arg₂ (Set.image2 (· + ·)) (coe_nsmul n K) rfl instance : AddMonoid (ConvexBody V) := SetLike.coe_injective.addMonoid (↑) rfl (fun _ _ ↦ rfl) fun _ _ ↦ coe_nsmul _ _ @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_add (K L : ConvexBody V) : (↑(K + L) : Set V) = (K : Set V) + L := rfl @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_zero : (↑(0 : ConvexBody V) : Set V) = 0 := rfl instance : Inhabited (ConvexBody V) := ⟨0⟩ instance : AddCommMonoid (ConvexBody V) := SetLike.coe_injective.addCommMonoid (↑) rfl (fun _ _ ↦ rfl) fun _ _ ↦ coe_nsmul _ _ end ContinuousAdd variable [ContinuousSMul ℝ V] instance : SMul ℝ (ConvexBody V) where smul c K := ⟨c • (K : Set V), K.convex.smul _, K.isCompact.smul _, K.nonempty.smul_set⟩ @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_smul (c : ℝ) (K : ConvexBody V) : (↑(c • K) : Set V) = c • (K : Set V) := rfl variable [ContinuousAdd V] instance : DistribMulAction ℝ (ConvexBody V) := SetLike.coe_injective.distribMulAction ⟨⟨(↑), coe_zero⟩, coe_add⟩ coe_smul @[simp] -- Porting note: add norm_cast; we leave it out for now to reproduce mathlib3 behavior. theorem coe_smul' (c : ℝ≥0) (K : ConvexBody V) : (↑(c • K) : Set V) = c • (K : Set V) := rfl /-- The convex bodies in a fixed space $V$ form a module over the nonnegative reals. -/ instance : Module ℝ≥0 (ConvexBody V) where add_smul c d K := SetLike.ext' <| Convex.add_smul K.convex c.coe_nonneg d.coe_nonneg zero_smul K := SetLike.ext' <| Set.zero_smul_set K.nonempty theorem smul_le_of_le (K : ConvexBody V) (h_zero : 0 ∈ K) {a b : ℝ≥0} (h : a ≤ b) : a • K ≤ b • K := by rw [← SetLike.coe_subset_coe, coe_smul', coe_smul'] by_cases ha : a = 0 · rw [ha, Set.zero_smul_set K.nonempty, Set.zero_subset] exact Set.mem_smul_set.mpr ⟨0, h_zero, smul_zero _⟩ · intro x hx obtain ⟨y, hy, rfl⟩ := Set.mem_smul_set.mp hx rw [← Set.mem_inv_smul_set_iff₀ ha, smul_smul] exact Convex.mem_smul_of_zero_mem K.convex h_zero hy (by rwa [← NNReal.mul_le_iff_le_inv ha, mul_one] : 1 ≤ a⁻¹ * b) end TVS section SeminormedAddCommGroup variable [SeminormedAddCommGroup V] [NormedSpace ℝ V] (K L : ConvexBody V) protected theorem isBounded : Bornology.IsBounded (K : Set V) := K.isCompact.isBounded theorem hausdorffEdist_ne_top {K L : ConvexBody V} : EMetric.hausdorffEdist (K : Set V) L ≠ ⊤ := by apply_rules [Metric.hausdorffEdist_ne_top_of_nonempty_of_bounded, ConvexBody.nonempty, ConvexBody.isBounded] /-- Convex bodies in a fixed seminormed space $V$ form a pseudo-metric space under the Hausdorff metric. -/ noncomputable instance : PseudoMetricSpace (ConvexBody V) where dist K L := Metric.hausdorffDist (K : Set V) L dist_self _ := Metric.hausdorffDist_self_zero dist_comm _ _ := Metric.hausdorffDist_comm dist_triangle K L M := Metric.hausdorffDist_triangle hausdorffEdist_ne_top @[simp, norm_cast] theorem hausdorffDist_coe : Metric.hausdorffDist (K : Set V) L = dist K L := rfl @[simp, norm_cast] theorem hausdorffEdist_coe : EMetric.hausdorffEdist (K : Set V) L = edist K L := by rw [edist_dist] exact (ENNReal.ofReal_toReal hausdorffEdist_ne_top).symm open Filter /-- Let `K` be a convex body that contains `0` and let `u n` be a sequence of nonnegative real numbers that tends to `0`. Then the intersection of the dilated bodies `(1 + u n) • K` is equal to `K`. -/ theorem iInter_smul_eq_self [T2Space V] {u : ℕ → ℝ≥0} (K : ConvexBody V) (h_zero : 0 ∈ K) (hu : Tendsto u atTop (𝓝 0)) : ⋂ n : ℕ, (1 + (u n : ℝ)) • (K : Set V) = K := by ext x refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨C, hC_pos, hC_bdd⟩ := K.isBounded.exists_pos_norm_le rw [← K.isClosed.closure_eq, SeminormedAddCommGroup.mem_closure_iff] rw [← NNReal.tendsto_coe, NormedAddCommGroup.tendsto_atTop] at hu intro ε hε obtain ⟨n, hn⟩ := hu (ε / C) (div_pos hε hC_pos) obtain ⟨y, hyK, rfl⟩ := Set.mem_smul_set.mp (Set.mem_iInter.mp h n) refine ⟨y, hyK, ?_⟩ rw [show (1 + u n : ℝ) • y - y = (u n : ℝ) • y by rw [add_smul, one_smul, add_sub_cancel_left], norm_smul, Real.norm_eq_abs] specialize hn n le_rfl rw [_root_.lt_div_iff' hC_pos, mul_comm, NNReal.coe_zero, sub_zero, Real.norm_eq_abs] at hn refine lt_of_le_of_lt ?_ hn exact mul_le_mul_of_nonneg_left (hC_bdd _ hyK) (abs_nonneg _) · refine Set.mem_iInter.mpr (fun n => Convex.mem_smul_of_zero_mem K.convex h_zero h ?_) exact le_add_of_nonneg_right (by positivity) end SeminormedAddCommGroup section NormedAddCommGroup variable [NormedAddCommGroup V] [NormedSpace ℝ V] /-- Convex bodies in a fixed normed space `V` form a metric space under the Hausdorff metric. -/ noncomputable instance : MetricSpace (ConvexBody V) where eq_of_dist_eq_zero {K L} hd := ConvexBody.ext <| (K.isClosed.hausdorffDist_zero_iff_eq L.isClosed hausdorffEdist_ne_top).1 hd end NormedAddCommGroup end ConvexBody
Analysis\Convex\Caratheodory.lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Scott Morrison -/ import Mathlib.Analysis.Convex.Combination import Mathlib.LinearAlgebra.AffineSpace.Independent import Mathlib.Tactic.FieldSimp /-! # Carathéodory's convexity theorem Convex hull can be regarded as a refinement of affine span. Both are closure operators but whereas convex hull takes values in the lattice of convex subsets, affine span takes values in the much coarser sublattice of affine subspaces. The cost of this refinement is that one no longer has bases. However Carathéodory's convexity theorem offers some compensation. Given a set `s` together with a point `x` in its convex hull, Carathéodory says that one may find an affine-independent family of elements `s` whose convex hull contains `x`. Thus the difference from the case of affine span is that the affine-independent family depends on `x`. In particular, in finite dimensions Carathéodory's theorem implies that the convex hull of a set `s` in `𝕜ᵈ` is the union of the convex hulls of the `(d + 1)`-tuples in `s`. ## Main results * `convexHull_eq_union`: Carathéodory's convexity theorem ## Implementation details This theorem was formalized as part of the Sphere Eversion project. ## Tags convex hull, caratheodory -/ open Set Finset universe u variable {𝕜 : Type*} {E : Type u} [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] namespace Caratheodory /-- If `x` is in the convex hull of some finset `t` whose elements are not affine-independent, then it is in the convex hull of a strict subset of `t`. -/ theorem mem_convexHull_erase [DecidableEq E] {t : Finset E} (h : ¬AffineIndependent 𝕜 ((↑) : t → E)) {x : E} (m : x ∈ convexHull 𝕜 (↑t : Set E)) : ∃ y : (↑t : Set E), x ∈ convexHull 𝕜 (↑(t.erase y) : Set E) := by simp only [Finset.convexHull_eq, mem_setOf_eq] at m ⊢ obtain ⟨f, fpos, fsum, rfl⟩ := m obtain ⟨g, gcombo, gsum, gpos⟩ := exists_nontrivial_relation_sum_zero_of_not_affine_ind h replace gpos := exists_pos_of_sum_zero_of_exists_nonzero g gsum gpos clear h let s := @Finset.filter _ (fun z => 0 < g z) (fun _ => LinearOrder.decidableLT _ _) t obtain ⟨i₀, mem, w⟩ : ∃ i₀ ∈ s, ∀ i ∈ s, f i₀ / g i₀ ≤ f i / g i := by apply s.exists_min_image fun z => f z / g z obtain ⟨x, hx, hgx⟩ : ∃ x ∈ t, 0 < g x := gpos exact ⟨x, mem_filter.mpr ⟨hx, hgx⟩⟩ have hg : 0 < g i₀ := by rw [mem_filter] at mem exact mem.2 have hi₀ : i₀ ∈ t := filter_subset _ _ mem let k : E → 𝕜 := fun z => f z - f i₀ / g i₀ * g z have hk : k i₀ = 0 := by field_simp [k, ne_of_gt hg] have ksum : ∑ e ∈ t.erase i₀, k e = 1 := by calc ∑ e ∈ t.erase i₀, k e = ∑ e ∈ t, k e := by conv_rhs => rw [← insert_erase hi₀, sum_insert (not_mem_erase i₀ t), hk, zero_add] _ = ∑ e ∈ t, (f e - f i₀ / g i₀ * g e) := rfl _ = 1 := by rw [sum_sub_distrib, fsum, ← mul_sum, gsum, mul_zero, sub_zero] refine ⟨⟨i₀, hi₀⟩, k, ?_, by convert ksum, ?_⟩ · simp only [k, and_imp, sub_nonneg, mem_erase, Ne, Subtype.coe_mk] intro e _ het by_cases hes : e ∈ s · have hge : 0 < g e := by rw [mem_filter] at hes exact hes.2 rw [← le_div_iff hge] exact w _ hes · calc _ ≤ 0 := by apply mul_nonpos_of_nonneg_of_nonpos · apply div_nonneg (fpos i₀ (mem_of_subset (filter_subset _ t) mem)) (le_of_lt hg) · simpa only [s, mem_filter, het, true_and_iff, not_lt] using hes _ ≤ f e := fpos e het · rw [Subtype.coe_mk, centerMass_eq_of_sum_1 _ id ksum] calc ∑ e ∈ t.erase i₀, k e • e = ∑ e ∈ t, k e • e := sum_erase _ (by rw [hk, zero_smul]) _ = ∑ e ∈ t, (f e - f i₀ / g i₀ * g e) • e := rfl _ = t.centerMass f id := by simp only [sub_smul, mul_smul, sum_sub_distrib, ← smul_sum, gcombo, smul_zero, sub_zero, centerMass, fsum, inv_one, one_smul, id] variable {s : Set E} {x : E} (hx : x ∈ convexHull 𝕜 s) /-- Given a point `x` in the convex hull of a set `s`, this is a finite subset of `s` of minimum cardinality, whose convex hull contains `x`. -/ noncomputable def minCardFinsetOfMemConvexHull : Finset E := Function.argminOn Finset.card Nat.lt_wfRel.2 { t | ↑t ⊆ s ∧ x ∈ convexHull 𝕜 (t : Set E) } <| by simpa only [convexHull_eq_union_convexHull_finite_subsets s, exists_prop, mem_iUnion] using hx theorem minCardFinsetOfMemConvexHull_subseteq : ↑(minCardFinsetOfMemConvexHull hx) ⊆ s := (Function.argminOn_mem _ _ { t : Finset E | ↑t ⊆ s ∧ x ∈ convexHull 𝕜 (t : Set E) } _).1 theorem mem_minCardFinsetOfMemConvexHull : x ∈ convexHull 𝕜 (minCardFinsetOfMemConvexHull hx : Set E) := (Function.argminOn_mem _ _ { t : Finset E | ↑t ⊆ s ∧ x ∈ convexHull 𝕜 (t : Set E) } _).2 theorem minCardFinsetOfMemConvexHull_nonempty : (minCardFinsetOfMemConvexHull hx).Nonempty := by rw [← Finset.coe_nonempty, ← @convexHull_nonempty_iff 𝕜] exact ⟨x, mem_minCardFinsetOfMemConvexHull hx⟩ theorem minCardFinsetOfMemConvexHull_card_le_card {t : Finset E} (ht₁ : ↑t ⊆ s) (ht₂ : x ∈ convexHull 𝕜 (t : Set E)) : (minCardFinsetOfMemConvexHull hx).card ≤ t.card := Function.argminOn_le _ _ _ (by exact ⟨ht₁, ht₂⟩) theorem affineIndependent_minCardFinsetOfMemConvexHull : AffineIndependent 𝕜 ((↑) : minCardFinsetOfMemConvexHull hx → E) := by let k := (minCardFinsetOfMemConvexHull hx).card - 1 have hk : (minCardFinsetOfMemConvexHull hx).card = k + 1 := (Nat.succ_pred_eq_of_pos (Finset.card_pos.mpr (minCardFinsetOfMemConvexHull_nonempty hx))).symm classical by_contra h obtain ⟨p, hp⟩ := mem_convexHull_erase h (mem_minCardFinsetOfMemConvexHull hx) have contra := minCardFinsetOfMemConvexHull_card_le_card hx (Set.Subset.trans (Finset.erase_subset (p : E) (minCardFinsetOfMemConvexHull hx)) (minCardFinsetOfMemConvexHull_subseteq hx)) hp rw [← not_lt] at contra apply contra erw [card_erase_of_mem p.2, hk] exact lt_add_one _ end Caratheodory variable {s : Set E} /-- **Carathéodory's convexity theorem** -/ theorem convexHull_eq_union : convexHull 𝕜 s = ⋃ (t : Finset E) (hss : ↑t ⊆ s) (hai : AffineIndependent 𝕜 ((↑) : t → E)), convexHull 𝕜 ↑t := by apply Set.Subset.antisymm · intro x hx simp only [exists_prop, Set.mem_iUnion] exact ⟨Caratheodory.minCardFinsetOfMemConvexHull hx, Caratheodory.minCardFinsetOfMemConvexHull_subseteq hx, Caratheodory.affineIndependent_minCardFinsetOfMemConvexHull hx, Caratheodory.mem_minCardFinsetOfMemConvexHull hx⟩ · iterate 3 convert Set.iUnion_subset _; intro exact convexHull_mono ‹_› /-- A more explicit version of `convexHull_eq_union`. -/ theorem eq_pos_convex_span_of_mem_convexHull {x : E} (hx : x ∈ convexHull 𝕜 s) : ∃ (ι : Sort (u + 1)) (_ : Fintype ι), ∃ (z : ι → E) (w : ι → 𝕜), Set.range z ⊆ s ∧ AffineIndependent 𝕜 z ∧ (∀ i, 0 < w i) ∧ ∑ i, w i = 1 ∧ ∑ i, w i • z i = x := by rw [convexHull_eq_union] at hx simp only [exists_prop, Set.mem_iUnion] at hx obtain ⟨t, ht₁, ht₂, ht₃⟩ := hx simp only [t.convexHull_eq, exists_prop, Set.mem_setOf_eq] at ht₃ obtain ⟨w, hw₁, hw₂, hw₃⟩ := ht₃ let t' := t.filter fun i => w i ≠ 0 refine ⟨t', t'.fintypeCoeSort, ((↑) : t' → E), w ∘ ((↑) : t' → E), ?_, ?_, ?_, ?_, ?_⟩ · rw [Subtype.range_coe_subtype] exact Subset.trans (Finset.filter_subset _ t) ht₁ · exact ht₂.comp_embedding ⟨_, inclusion_injective (Finset.filter_subset (fun i => w i ≠ 0) t)⟩ · exact fun i => (hw₁ _ (Finset.mem_filter.mp i.2).1).lt_of_ne (Finset.mem_filter.mp i.property).2.symm · erw [Finset.sum_attach, Finset.sum_filter_ne_zero, hw₂] · change (∑ i ∈ t'.attach, (fun e => w e • e) ↑i) = x erw [Finset.sum_attach (f := fun e => w e • e), Finset.sum_filter_of_ne] · rw [t.centerMass_eq_of_sum_1 id hw₂] at hw₃ exact hw₃ · intro e _ hwe contra apply hwe rw [contra, zero_smul]
Analysis\Convex\Combination.lean
/- Copyright (c) 2019 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Basis /-! # Convex combinations This file defines convex combinations of points in a vector space. ## Main declarations * `Finset.centerMass`: Center of mass of a finite family of points. ## Implementation notes We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few lemmas unconditional on the sum of the weights being `1`. -/ open Set Function open scoped Classical open Pointwise universe u u' section variable {R R' E F ι ι' α : Type*} [LinearOrderedField R] [LinearOrderedField R'] [AddCommGroup E] [AddCommGroup F] [LinearOrderedAddCommGroup α] [Module R E] [Module R F] [Module R α] [OrderedSMul R α] {s : Set E} /-- Center of mass of a finite collection of points with prescribed weights. Note that we require neither `0 ≤ w i` nor `∑ w = 1`. -/ def Finset.centerMass (t : Finset ι) (w : ι → R) (z : ι → E) : E := (∑ i ∈ t, w i)⁻¹ • ∑ i ∈ t, w i • z i variable (i j : ι) (c : R) (t : Finset ι) (w : ι → R) (z : ι → E) open Finset theorem Finset.centerMass_empty : (∅ : Finset ι).centerMass w z = 0 := by simp only [centerMass, sum_empty, smul_zero] theorem Finset.centerMass_pair (hne : i ≠ j) : ({i, j} : Finset ι).centerMass w z = (w i / (w i + w j)) • z i + (w j / (w i + w j)) • z j := by simp only [centerMass, sum_pair hne, smul_add, (mul_smul _ _ _).symm, div_eq_inv_mul] variable {w} theorem Finset.centerMass_insert (ha : i ∉ t) (hw : ∑ j ∈ t, w j ≠ 0) : (insert i t).centerMass w z = (w i / (w i + ∑ j ∈ t, w j)) • z i + ((∑ j ∈ t, w j) / (w i + ∑ j ∈ t, w j)) • t.centerMass w z := by simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul] congr 2 rw [div_mul_eq_mul_div, mul_inv_cancel hw, one_div] theorem Finset.centerMass_singleton (hw : w i ≠ 0) : ({i} : Finset ι).centerMass w z = z i := by rw [centerMass, sum_singleton, sum_singleton, ← mul_smul, inv_mul_cancel hw, one_smul] @[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by simp [centerMass, inv_neg] lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R] [IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c ≠ 0) : t.centerMass (c • w) z = t.centerMass w z := by simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_inv₀, smul_smul_smul_comm, hc] theorem Finset.centerMass_eq_of_sum_1 (hw : ∑ i ∈ t, w i = 1) : t.centerMass w z = ∑ i ∈ t, w i • z i := by simp only [Finset.centerMass, hw, inv_one, one_smul] theorem Finset.centerMass_smul : (t.centerMass w fun i => c • z i) = c • t.centerMass w z := by simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc] /-- A convex combination of two centers of mass is a center of mass as well. This version deals with two different index types. -/ theorem Finset.centerMass_segment' (s : Finset ι) (t : Finset ι') (ws : ι → R) (zs : ι → E) (wt : ι' → R) (zt : ι' → E) (hws : ∑ i ∈ s, ws i = 1) (hwt : ∑ i ∈ t, wt i = 1) (a b : R) (hab : a + b = 1) : a • s.centerMass ws zs + b • t.centerMass wt zt = (s.disjSum t).centerMass (Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ← Finset.sum_sum_elim, Finset.centerMass_eq_of_sum_1] · congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul] · rw [sum_sum_elim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab] /-- A convex combination of two centers of mass is a center of mass as well. This version works if two centers of mass share the set of original points. -/ theorem Finset.centerMass_segment (s : Finset ι) (w₁ w₂ : ι → R) (z : ι → E) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (a b : R) (hab : a + b = 1) : a • s.centerMass w₁ z + b • s.centerMass w₂ z = s.centerMass (fun i => a * w₁ i + b * w₂ i) z := by have hw : (∑ i ∈ s, (a * w₁ i + b * w₂ i)) = 1 := by simp only [← mul_sum, sum_add_distrib, mul_one, *] simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw, smul_sum, sum_add_distrib, add_smul, mul_smul, *] theorem Finset.centerMass_ite_eq (hi : i ∈ t) : t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by rw [Finset.centerMass_eq_of_sum_1] · trans ∑ j ∈ t, if i = j then z i else 0 · congr with i split_ifs with h exacts [h ▸ one_smul _ _, zero_smul _ _] · rw [sum_ite_eq, if_pos hi] · rw [sum_ite_eq, if_pos hi] variable {t} theorem Finset.centerMass_subset {t' : Finset ι} (ht : t ⊆ t') (h : ∀ i ∈ t', i ∉ t → w i = 0) : t.centerMass w z = t'.centerMass w z := by rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum] apply sum_subset ht intro i hit' hit rw [h i hit' hit, zero_smul, smul_zero] theorem Finset.centerMass_filter_ne_zero : (t.filter fun i => w i ≠ 0).centerMass w z = t.centerMass w z := Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by simpa only [hit, mem_filter, true_and_iff, Ne, Classical.not_not] using hit' namespace Finset theorem centerMass_le_sup {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : 0 < ∑ i ∈ s, w i) : s.centerMass w f ≤ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f := by rw [centerMass, inv_smul_le_iff_of_pos hw₁, sum_smul] exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hw₀ i hi theorem inf_le_centerMass {s : Finset ι} {f : ι → α} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : 0 < ∑ i ∈ s, w i) : s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f ≤ s.centerMass w f := @centerMass_le_sup R _ αᵒᵈ _ _ _ _ _ _ _ hw₀ hw₁ end Finset variable {z} lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ι} (hw : ∑ i ∈ s, w i + ∑ i ∈ t, w i = 0) (hz : ∑ i ∈ s, w i • z i + ∑ i ∈ t, w i • z i = 0) : s.centerMass w z = t.centerMass w z := by simp [centerMass, eq_neg_of_add_eq_zero_right hw, eq_neg_of_add_eq_zero_left hz, ← neg_inv] /-- The center of mass of a finite subset of a convex set belongs to the set provided that all weights are non-negative, and the total weight is positive. -/ theorem Convex.centerMass_mem (hs : Convex R s) : (∀ i ∈ t, 0 ≤ w i) → (0 < ∑ i ∈ t, w i) → (∀ i ∈ t, z i ∈ s) → t.centerMass w z ∈ s := by induction' t using Finset.induction with i t hi ht · simp [lt_irrefl] intro h₀ hpos hmem have zi : z i ∈ s := hmem _ (mem_insert_self _ _) have hs₀ : ∀ j ∈ t, 0 ≤ w j := fun j hj => h₀ j <| mem_insert_of_mem hj rw [sum_insert hi] at hpos by_cases hsum_t : ∑ j ∈ t, w j = 0 · have ws : ∀ j ∈ t, w j = 0 := (sum_eq_zero_iff_of_nonneg hs₀).1 hsum_t have wz : ∑ j ∈ t, w j • z j = 0 := sum_eq_zero fun i hi => by simp [ws i hi] simp only [centerMass, sum_insert hi, wz, hsum_t, add_zero] simp only [hsum_t, add_zero] at hpos rw [← mul_smul, inv_mul_cancel (ne_of_gt hpos), one_smul] exact zi · rw [Finset.centerMass_insert _ _ _ hi hsum_t] refine convex_iff_div.1 hs zi (ht hs₀ ?_ ?_) ?_ (sum_nonneg hs₀) hpos · exact lt_of_le_of_ne (sum_nonneg hs₀) (Ne.symm hsum_t) · intro j hj exact hmem j (mem_insert_of_mem hj) · exact h₀ _ (mem_insert_self _ _) theorem Convex.sum_mem (hs : Convex R s) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hz : ∀ i ∈ t, z i ∈ s) : (∑ i ∈ t, w i • z i) ∈ s := by simpa only [h₁, centerMass, inv_one, one_smul] using hs.centerMass_mem h₀ (h₁.symm ▸ zero_lt_one) hz /-- A version of `Convex.sum_mem` for `finsum`s. If `s` is a convex set, `w : ι → R` is a family of nonnegative weights with sum one and `z : ι → E` is a family of elements of a module over `R` such that `z i ∈ s` whenever `w i ≠ 0`, then the sum `∑ᶠ i, w i • z i` belongs to `s`. See also `PartitionOfUnity.finsum_smul_mem_convex`. -/ theorem Convex.finsum_mem {ι : Sort*} {w : ι → R} {z : ι → E} {s : Set E} (hs : Convex R s) (h₀ : ∀ i, 0 ≤ w i) (h₁ : ∑ᶠ i, w i = 1) (hz : ∀ i, w i ≠ 0 → z i ∈ s) : (∑ᶠ i, w i • z i) ∈ s := by have hfin_w : (support (w ∘ PLift.down)).Finite := by by_contra H rw [finsum, dif_neg H] at h₁ exact zero_ne_one h₁ have hsub : support ((fun i => w i • z i) ∘ PLift.down) ⊆ hfin_w.toFinset := (support_smul_subset_left _ _).trans hfin_w.coe_toFinset.ge rw [finsum_eq_sum_plift_of_support_subset hsub] refine hs.sum_mem (fun _ _ => h₀ _) ?_ fun i hi => hz _ ?_ · rwa [finsum, dif_pos hfin_w] at h₁ · rwa [hfin_w.mem_toFinset] at hi theorem convex_iff_sum_mem : Convex R s ↔ ∀ (t : Finset E) (w : E → R), (∀ i ∈ t, 0 ≤ w i) → ∑ i ∈ t, w i = 1 → (∀ x ∈ t, x ∈ s) → (∑ x ∈ t, w x • x) ∈ s := by refine ⟨fun hs t w hw₀ hw₁ hts => hs.sum_mem hw₀ hw₁ hts, ?_⟩ intro h x hx y hy a b ha hb hab by_cases h_cases : x = y · rw [h_cases, ← add_smul, hab, one_smul] exact hy · convert h {x, y} (fun z => if z = y then b else a) _ _ _ -- Porting note: Original proof had 2 `simp_intro i hi` · simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial] · intro i _ simp only split_ifs <;> assumption · simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial, hab] · intro i hi simp only [Finset.mem_singleton, Finset.mem_insert] at hi cases hi <;> subst i <;> assumption theorem Finset.centerMass_mem_convexHull (t : Finset ι) {w : ι → R} (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i ∈ t, w i) {z : ι → E} (hz : ∀ i ∈ t, z i ∈ s) : t.centerMass w z ∈ convexHull R s := (convex_convexHull R s).centerMass_mem hw₀ hws fun i hi => subset_convexHull R s <| hz i hi /-- A version of `Finset.centerMass_mem_convexHull` for when the weights are nonpositive. -/ lemma Finset.centerMass_mem_convexHull_of_nonpos (t : Finset ι) (hw₀ : ∀ i ∈ t, w i ≤ 0) (hws : ∑ i ∈ t, w i < 0) (hz : ∀ i ∈ t, z i ∈ s) : t.centerMass w z ∈ convexHull R s := by rw [← centerMass_neg_left] exact Finset.centerMass_mem_convexHull _ (fun _i hi ↦ neg_nonneg.2 <| hw₀ _ hi) (by simpa) hz /-- A refinement of `Finset.centerMass_mem_convexHull` when the indexed family is a `Finset` of the space. -/ theorem Finset.centerMass_id_mem_convexHull (t : Finset E) {w : E → R} (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hws : 0 < ∑ i ∈ t, w i) : t.centerMass w id ∈ convexHull R (t : Set E) := t.centerMass_mem_convexHull hw₀ hws fun _ => mem_coe.2 /-- A version of `Finset.centerMass_mem_convexHull` for when the weights are nonpositive. -/ lemma Finset.centerMass_id_mem_convexHull_of_nonpos (t : Finset E) {w : E → R} (hw₀ : ∀ i ∈ t, w i ≤ 0) (hws : ∑ i ∈ t, w i < 0) : t.centerMass w id ∈ convexHull R (t : Set E) := t.centerMass_mem_convexHull_of_nonpos hw₀ hws fun _ ↦ mem_coe.2 theorem affineCombination_eq_centerMass {ι : Type*} {t : Finset ι} {p : ι → E} {w : ι → R} (hw₂ : ∑ i ∈ t, w i = 1) : t.affineCombination R p w = centerMass t w p := by rw [affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one _ w _ hw₂ (0 : E), Finset.weightedVSubOfPoint_apply, vadd_eq_add, add_zero, t.centerMass_eq_of_sum_1 _ hw₂] simp_rw [vsub_eq_sub, sub_zero] theorem affineCombination_mem_convexHull {s : Finset ι} {v : ι → E} {w : ι → R} (hw₀ : ∀ i ∈ s, 0 ≤ w i) (hw₁ : s.sum w = 1) : s.affineCombination R v w ∈ convexHull R (range v) := by rw [affineCombination_eq_centerMass hw₁] apply s.centerMass_mem_convexHull hw₀ · simp [hw₁] · simp /-- The centroid can be regarded as a center of mass. -/ @[simp] theorem Finset.centroid_eq_centerMass (s : Finset ι) (hs : s.Nonempty) (p : ι → E) : s.centroid R p = s.centerMass (s.centroidWeights R) p := affineCombination_eq_centerMass (s.sum_centroidWeights_eq_one_of_nonempty R hs) theorem Finset.centroid_mem_convexHull (s : Finset E) (hs : s.Nonempty) : s.centroid R id ∈ convexHull R (s : Set E) := by rw [s.centroid_eq_centerMass hs] apply s.centerMass_id_mem_convexHull · simp only [inv_nonneg, imp_true_iff, Nat.cast_nonneg, Finset.centroidWeights_apply] · have hs_card : (s.card : R) ≠ 0 := by simp [Finset.nonempty_iff_ne_empty.mp hs] simp only [hs_card, Finset.sum_const, nsmul_eq_mul, mul_inv_cancel, Ne, not_false_iff, Finset.centroidWeights_apply, zero_lt_one] theorem convexHull_range_eq_exists_affineCombination (v : ι → E) : convexHull R (range v) = { x | ∃ (s : Finset ι) (w : ι → R), (∀ i ∈ s, 0 ≤ w i) ∧ s.sum w = 1 ∧ s.affineCombination R v w = x } := by refine Subset.antisymm (convexHull_min ?_ ?_) ?_ · intro x hx obtain ⟨i, hi⟩ := Set.mem_range.mp hx exact ⟨{i}, Function.const ι (1 : R), by simp, by simp, by simp [hi]⟩ · rintro x ⟨s, w, hw₀, hw₁, rfl⟩ y ⟨s', w', hw₀', hw₁', rfl⟩ a b ha hb hab let W : ι → R := fun i => (if i ∈ s then a * w i else 0) + if i ∈ s' then b * w' i else 0 have hW₁ : (s ∪ s').sum W = 1 := by rw [sum_add_distrib, ← sum_subset subset_union_left, ← sum_subset subset_union_right, sum_ite_of_true, sum_ite_of_true, ← mul_sum, ← mul_sum, hw₁, hw₁', ← add_mul, hab, mul_one] <;> intros <;> simp_all refine ⟨s ∪ s', W, ?_, hW₁, ?_⟩ · rintro i - by_cases hi : i ∈ s <;> by_cases hi' : i ∈ s' <;> simp [W, hi, hi', add_nonneg, mul_nonneg ha (hw₀ i _), mul_nonneg hb (hw₀' i _)] · simp_rw [affineCombination_eq_linear_combination (s ∪ s') v _ hW₁, affineCombination_eq_linear_combination s v w hw₁, affineCombination_eq_linear_combination s' v w' hw₁', add_smul, sum_add_distrib] rw [← sum_subset subset_union_left, ← sum_subset subset_union_right] · simp only [ite_smul, sum_ite_of_true fun _ hi => hi, mul_smul, ← smul_sum] · intro i _ hi' simp [hi'] · intro i _ hi' simp [hi'] · rintro x ⟨s, w, hw₀, hw₁, rfl⟩ exact affineCombination_mem_convexHull hw₀ hw₁ /-- Convex hull of `s` is equal to the set of all centers of masses of `Finset`s `t`, `z '' t ⊆ s`. For universe reasons, you shouldn't use this lemma to prove that a given center of mass belongs to the convex hull. Use convexity of the convex hull instead. -/ theorem convexHull_eq (s : Set E) : convexHull R s = { x : E | ∃ (ι : Type) (t : Finset ι) (w : ι → R) (z : ι → E), (∀ i ∈ t, 0 ≤ w i) ∧ ∑ i ∈ t, w i = 1 ∧ (∀ i ∈ t, z i ∈ s) ∧ t.centerMass w z = x } := by refine Subset.antisymm (convexHull_min ?_ ?_) ?_ · intro x hx use PUnit, {PUnit.unit}, fun _ => 1, fun _ => x, fun _ _ => zero_le_one, sum_singleton _ _, fun _ _ => hx simp only [Finset.centerMass, Finset.sum_singleton, inv_one, one_smul] · rintro x ⟨ι, sx, wx, zx, hwx₀, hwx₁, hzx, rfl⟩ y ⟨ι', sy, wy, zy, hwy₀, hwy₁, hzy, rfl⟩ a b ha hb hab rw [Finset.centerMass_segment' _ _ _ _ _ _ hwx₁ hwy₁ _ _ hab] refine ⟨_, _, _, _, ?_, ?_, ?_, rfl⟩ · rintro i hi rw [Finset.mem_disjSum] at hi rcases hi with (⟨j, hj, rfl⟩ | ⟨j, hj, rfl⟩) <;> simp only [Sum.elim_inl, Sum.elim_inr] <;> apply_rules [mul_nonneg, hwx₀, hwy₀] · simp [Finset.sum_sum_elim, ← mul_sum, *] · intro i hi rw [Finset.mem_disjSum] at hi rcases hi with (⟨j, hj, rfl⟩ | ⟨j, hj, rfl⟩) <;> apply_rules [hzx, hzy] · rintro _ ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩ exact t.centerMass_mem_convexHull hw₀ (hw₁.symm ▸ zero_lt_one) hz /-- Universe polymorphic version of the reverse implication of `mem_convexHull_iff_exists_fintype`. -/ lemma mem_convexHull_of_exists_fintype {s : Set E} {x : E} [Fintype ι] (w : ι → R) (z : ι → E) (hw₀ : ∀ i, 0 ≤ w i) (hw₁ : ∑ i, w i = 1) (hz : ∀ i, z i ∈ s) (hx : ∑ i, w i • z i = x) : x ∈ convexHull R s := by rw [← hx, ← centerMass_eq_of_sum_1 _ _ hw₁] exact centerMass_mem_convexHull _ (by simpa using hw₀) (by simp [hw₁]) (by simpa using hz) /-- The convex hull of `s` is equal to the set of centers of masses of finite families of points in `s`. For universe reasons, you shouldn't use this lemma to prove that a given center of mass belongs to the convex hull. Use `mem_convexHull_of_exists_fintype` of the convex hull instead. -/ lemma mem_convexHull_iff_exists_fintype {s : Set E} {x : E} : x ∈ convexHull R s ↔ ∃ (ι : Type) (_ : Fintype ι) (w : ι → R) (z : ι → E), (∀ i, 0 ≤ w i) ∧ ∑ i, w i = 1 ∧ (∀ i, z i ∈ s) ∧ ∑ i, w i • z i = x := by constructor · simp only [convexHull_eq, mem_setOf_eq] rintro ⟨ι, t, w, z, h⟩ refine ⟨t, inferInstance, w ∘ (↑), z ∘ (↑), ?_⟩ simpa [← sum_attach t, centerMass_eq_of_sum_1 _ _ h.2.1] using h · rintro ⟨ι, _, w, z, hw₀, hw₁, hz, hx⟩ exact mem_convexHull_of_exists_fintype w z hw₀ hw₁ hz hx theorem Finset.convexHull_eq (s : Finset E) : convexHull R ↑s = { x : E | ∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ s, w y = 1 ∧ s.centerMass w id = x } := by refine Set.Subset.antisymm (convexHull_min ?_ ?_) ?_ · intro x hx rw [Finset.mem_coe] at hx refine ⟨_, ?_, ?_, Finset.centerMass_ite_eq _ _ _ hx⟩ · intros split_ifs exacts [zero_le_one, le_refl 0] · rw [Finset.sum_ite_eq, if_pos hx] · rintro x ⟨wx, hwx₀, hwx₁, rfl⟩ y ⟨wy, hwy₀, hwy₁, rfl⟩ a b ha hb hab rw [Finset.centerMass_segment _ _ _ _ hwx₁ hwy₁ _ _ hab] refine ⟨_, ?_, ?_, rfl⟩ · rintro i hi apply_rules [add_nonneg, mul_nonneg, hwx₀, hwy₀] · simp only [Finset.sum_add_distrib, ← mul_sum, mul_one, *] · rintro _ ⟨w, hw₀, hw₁, rfl⟩ exact s.centerMass_mem_convexHull (fun x hx => hw₀ _ hx) (hw₁.symm ▸ zero_lt_one) fun x hx => hx theorem Finset.mem_convexHull {s : Finset E} {x : E} : x ∈ convexHull R (s : Set E) ↔ ∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ s, w y = 1 ∧ s.centerMass w id = x := by rw [Finset.convexHull_eq, Set.mem_setOf_eq] /-- This is a version of `Finset.mem_convexHull` stated without `Finset.centerMass`. -/ lemma Finset.mem_convexHull' {s : Finset E} {x : E} : x ∈ convexHull R (s : Set E) ↔ ∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ s, w y = 1 ∧ ∑ y ∈ s, w y • y = x := by rw [mem_convexHull] refine exists_congr fun w ↦ and_congr_right' $ and_congr_right fun hw ↦ ?_ simp_rw [centerMass_eq_of_sum_1 _ _ hw, id_eq] theorem Set.Finite.convexHull_eq {s : Set E} (hs : s.Finite) : convexHull R s = { x : E | ∃ w : E → R, (∀ y ∈ s, 0 ≤ w y) ∧ ∑ y ∈ hs.toFinset, w y = 1 ∧ hs.toFinset.centerMass w id = x } := by simpa only [Set.Finite.coe_toFinset, Set.Finite.mem_toFinset, exists_prop] using hs.toFinset.convexHull_eq /-- A weak version of Carathéodory's theorem. -/ theorem convexHull_eq_union_convexHull_finite_subsets (s : Set E) : convexHull R s = ⋃ (t : Finset E) (w : ↑t ⊆ s), convexHull R ↑t := by refine Subset.antisymm ?_ ?_ · rw [_root_.convexHull_eq] rintro x ⟨ι, t, w, z, hw₀, hw₁, hz, rfl⟩ simp only [mem_iUnion] refine ⟨t.image z, ?_, ?_⟩ · rw [coe_image, Set.image_subset_iff] exact hz · apply t.centerMass_mem_convexHull hw₀ · simp only [hw₁, zero_lt_one] · exact fun i hi => Finset.mem_coe.2 (Finset.mem_image_of_mem _ hi) · exact iUnion_subset fun i => iUnion_subset convexHull_mono theorem mk_mem_convexHull_prod {t : Set F} {x : E} {y : F} (hx : x ∈ convexHull R s) (hy : y ∈ convexHull R t) : (x, y) ∈ convexHull R (s ×ˢ t) := by rw [mem_convexHull_iff_exists_fintype] at hx hy ⊢ obtain ⟨ι, _, w, f, hw₀, hw₁, hfs, hf⟩ := hx obtain ⟨κ, _, v, g, hv₀, hv₁, hgt, hg⟩ := hy have h_sum : ∑ i : ι × κ, w i.1 * v i.2 = 1 := by rw [Fintype.sum_prod_type, ← sum_mul_sum, hw₁, hv₁, mul_one] refine ⟨ι × κ, inferInstance, fun p => w p.1 * v p.2, fun p ↦ (f p.1, g p.2), fun p ↦ mul_nonneg (hw₀ _) (hv₀ _), h_sum, fun p ↦ ⟨hfs _, hgt _⟩, ?_⟩ ext · simp_rw [Prod.fst_sum, Prod.smul_mk, Fintype.sum_prod_type, mul_comm (w _), mul_smul, sum_comm (γ := ι), ← Fintype.sum_smul_sum, hv₁, one_smul, hf] · simp_rw [Prod.snd_sum, Prod.smul_mk, Fintype.sum_prod_type, mul_smul, ← Fintype.sum_smul_sum, hw₁, one_smul, hg] @[simp] theorem convexHull_prod (s : Set E) (t : Set F) : convexHull R (s ×ˢ t) = convexHull R s ×ˢ convexHull R t := Subset.antisymm (convexHull_min (prod_mono (subset_convexHull _ _) <| subset_convexHull _ _) <| (convex_convexHull _ _).prod <| convex_convexHull _ _) <| prod_subset_iff.2 fun _ hx _ => mk_mem_convexHull_prod hx theorem convexHull_add (s t : Set E) : convexHull R (s + t) = convexHull R s + convexHull R t := by simp_rw [← add_image_prod, ← IsLinearMap.isLinearMap_add.image_convexHull, convexHull_prod] variable (R E) /-- `convexHull` is an additive monoid morphism under pointwise addition. -/ @[simps] def convexHullAddMonoidHom : Set E →+ Set E where toFun := convexHull R map_add' := convexHull_add map_zero' := convexHull_zero variable {R E} theorem convexHull_sub (s t : Set E) : convexHull R (s - t) = convexHull R s - convexHull R t := by simp_rw [sub_eq_add_neg, convexHull_add, ← convexHull_neg] theorem convexHull_list_sum (l : List (Set E)) : convexHull R l.sum = (l.map <| convexHull R).sum := map_list_sum (convexHullAddMonoidHom R E) l theorem convexHull_multiset_sum (s : Multiset (Set E)) : convexHull R s.sum = (s.map <| convexHull R).sum := map_multiset_sum (convexHullAddMonoidHom R E) s theorem convexHull_sum {ι} (s : Finset ι) (t : ι → Set E) : convexHull R (∑ i ∈ s, t i) = ∑ i ∈ s, convexHull R (t i) := map_sum (convexHullAddMonoidHom R E) _ _ /-! ### `stdSimplex` -/ variable (ι) [Fintype ι] {f : ι → R} /-- `stdSimplex 𝕜 ι` is the convex hull of the canonical basis in `ι → 𝕜`. -/ theorem convexHull_basis_eq_stdSimplex : convexHull R (range fun i j : ι => if i = j then (1 : R) else 0) = stdSimplex R ι := by refine Subset.antisymm (convexHull_min ?_ (convex_stdSimplex R ι)) ?_ · rintro _ ⟨i, rfl⟩ exact ite_eq_mem_stdSimplex R i · rintro w ⟨hw₀, hw₁⟩ rw [pi_eq_sum_univ w, ← Finset.univ.centerMass_eq_of_sum_1 _ hw₁] exact Finset.univ.centerMass_mem_convexHull (fun i _ => hw₀ i) (hw₁.symm ▸ zero_lt_one) fun i _ => mem_range_self i variable {ι} /-- The convex hull of a finite set is the image of the standard simplex in `s → ℝ` under the linear map sending each function `w` to `∑ x ∈ s, w x • x`. Since we have no sums over finite sets, we use sum over `@Finset.univ _ hs.fintype`. The map is defined in terms of operations on `(s → ℝ) →ₗ[ℝ] ℝ` so that later we will not need to prove that this map is linear. -/ theorem Set.Finite.convexHull_eq_image {s : Set E} (hs : s.Finite) : convexHull R s = haveI := hs.fintype (⇑(∑ x : s, (@LinearMap.proj R s _ (fun _ => R) _ _ x).smulRight x.1)) '' stdSimplex R s := by letI := hs.fintype rw [← convexHull_basis_eq_stdSimplex, LinearMap.image_convexHull, ← Set.range_comp] apply congr_arg simp_rw [Function.comp] convert Subtype.range_coe.symm simp [LinearMap.sum_apply, ite_smul, Finset.filter_eq, Finset.mem_univ] /-- All values of a function `f ∈ stdSimplex 𝕜 ι` belong to `[0, 1]`. -/ theorem mem_Icc_of_mem_stdSimplex (hf : f ∈ stdSimplex R ι) (x) : f x ∈ Icc (0 : R) 1 := ⟨hf.1 x, hf.2 ▸ Finset.single_le_sum (fun y _ => hf.1 y) (Finset.mem_univ x)⟩ /-- The convex hull of an affine basis is the intersection of the half-spaces defined by the corresponding barycentric coordinates. -/ theorem AffineBasis.convexHull_eq_nonneg_coord {ι : Type*} (b : AffineBasis ι R E) : convexHull R (range b) = { x | ∀ i, 0 ≤ b.coord i x } := by rw [convexHull_range_eq_exists_affineCombination] ext x refine ⟨?_, fun hx => ?_⟩ · rintro ⟨s, w, hw₀, hw₁, rfl⟩ i by_cases hi : i ∈ s · rw [b.coord_apply_combination_of_mem hi hw₁] exact hw₀ i hi · rw [b.coord_apply_combination_of_not_mem hi hw₁] · have hx' : x ∈ affineSpan R (range b) := by rw [b.tot] exact AffineSubspace.mem_top R E x obtain ⟨s, w, hw₁, rfl⟩ := (mem_affineSpan_iff_eq_affineCombination R E).mp hx' refine ⟨s, w, ?_, hw₁, rfl⟩ intro i hi specialize hx i rw [b.coord_apply_combination_of_mem hi hw₁] at hx exact hx variable {s t t₁ t₂ : Finset E} /-- Two simplices glue nicely if the union of their vertices is affine independent. -/ lemma AffineIndependent.convexHull_inter (hs : AffineIndependent R ((↑) : s → E)) (ht₁ : t₁ ⊆ s) (ht₂ : t₂ ⊆ s) : convexHull R (t₁ ∩ t₂ : Set E) = convexHull R t₁ ∩ convexHull R t₂ := by refine (Set.subset_inter (convexHull_mono inf_le_left) $ convexHull_mono inf_le_right).antisymm ?_ simp_rw [Set.subset_def, mem_inter_iff, Set.inf_eq_inter, ← coe_inter, mem_convexHull'] rintro x ⟨⟨w₁, h₁w₁, h₂w₁, h₃w₁⟩, w₂, -, h₂w₂, h₃w₂⟩ let w (x : E) : R := (if x ∈ t₁ then w₁ x else 0) - if x ∈ t₂ then w₂ x else 0 have h₁w : ∑ i ∈ s, w i = 0 := by simp [w, Finset.inter_eq_right.2, *] replace hs := hs.eq_zero_of_sum_eq_zero_subtype h₁w $ by simp only [w, sub_smul, zero_smul, ite_smul, Finset.sum_sub_distrib, ← Finset.sum_filter, h₃w₁, Finset.filter_mem_eq_inter, Finset.inter_eq_right.2 ht₁, Finset.inter_eq_right.2 ht₂, h₃w₂, sub_self] have ht (x) (hx₁ : x ∈ t₁) (hx₂ : x ∉ t₂) : w₁ x = 0 := by simpa [w, hx₁, hx₂] using hs _ (ht₁ hx₁) refine ⟨w₁, ?_, ?_, ?_⟩ · simp only [and_imp, Finset.mem_inter] exact fun y hy₁ _ ↦ h₁w₁ y hy₁ all_goals · rwa [sum_subset inter_subset_left] rintro x simp_intro hx₁ hx₂ simp [ht x hx₁ hx₂] /-- Two simplices glue nicely if the union of their vertices is affine independent. Note that `AffineIndependent.convexHull_inter` should be more versatile in most use cases. -/ lemma AffineIndependent.convexHull_inter' (hs : AffineIndependent R ((↑) : ↑(t₁ ∪ t₂) → E)) : convexHull R (t₁ ∩ t₂ : Set E) = convexHull R t₁ ∩ convexHull R t₂ := hs.convexHull_inter subset_union_left subset_union_right end section pi variable {𝕜 ι : Type*} {E : ι → Type*} [Finite ι] [LinearOrderedField 𝕜] [Π i, AddCommGroup (E i)] [Π i, Module 𝕜 (E i)] {s : Set ι} {t : Π i, Set (E i)} {x : Π i, E i} open Finset Fintype lemma mem_convexHull_pi (h : ∀ i ∈ s, x i ∈ convexHull 𝕜 (t i)) : x ∈ convexHull 𝕜 (s.pi t) := by cases nonempty_fintype ι wlog hs : s = Set.univ generalizing s t · rw [← pi_univ_ite] refine this (fun i _ ↦ ?_) rfl split_ifs with hi · exact h i hi · simp subst hs simp only [Set.mem_univ, mem_convexHull_iff_exists_fintype, true_implies, Set.mem_pi] at h choose κ _ w f hw₀ hw₁ hft hf using h refine mem_convexHull_of_exists_fintype (fun k : Π i, κ i ↦ ∏ i, w i (k i)) (fun g i ↦ f _ (g i)) (fun g ↦ prod_nonneg fun _ _ ↦ hw₀ _ _) ?_ (fun _ _ _ ↦ hft _ _) ?_ · rw [← Fintype.prod_sum] exact prod_eq_one fun _ _ ↦ hw₁ _ ext i calc _ = ∑ g : ∀ i, κ i, (∏ i, w i (g i)) • f i (g i) := by simp only [Finset.sum_apply, Pi.smul_apply] _ = ∑ j : κ i, ∑ g : {g : ∀ k, κ k // g i = j}, (∏ k, w k (g.1 k)) • f i ((g : ∀ i, κ i) i) := by rw [← Fintype.sum_fiberwise fun g : ∀ k, κ k ↦ g i] _ = ∑ j : κ i, (∑ g : {g : ∀ k, κ k // g i = j}, ∏ k, w k (g.1 k)) • f i j := by simp_rw [sum_smul] congr! with j _ g _ exact g.2 _ = ∑ j : κ i, w i j • f i j := ?_ _ = x i := hf _ congr! with j _ calc ∑ g : {g : ∀ k, κ k // g i = j}, ∏ k, w k (g.1 k) = ∑ g ∈ piFinset fun k ↦ if hk : k = i then hk ▸ {j} else univ, ∏ k, w k (g k) := Finset.sum_bij' (fun g _ ↦ g) (fun g hg ↦ ⟨g, by simpa using mem_piFinset.1 hg i⟩) (by aesop) (by simp) (by simp) (by simp) (by simp) _ = w i j := by rw [← prod_univ_sum, ← prod_mul_prod_compl, Finset.prod_singleton, Finset.sum_eq_single, Finset.prod_eq_one, mul_one] <;> simp (config := { contextual := true }) [hw₁] @[simp] lemma convexHull_pi (s : Set ι) (t : Π i, Set (E i)) : convexHull 𝕜 (s.pi t) = s.pi (fun i ↦ convexHull 𝕜 (t i)) := Set.Subset.antisymm (convexHull_min (Set.pi_mono fun _ _ ↦ subset_convexHull _ _) $ convex_pi $ fun _ _ ↦ convex_convexHull _ _) fun _ ↦ mem_convexHull_pi end pi
Analysis\Convex\Complex.lean
/- Copyright (c) 2019 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Yaël Dillies -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Data.Complex.Module /-! # Convexity of half spaces in ℂ The open and closed half-spaces in ℂ given by an inequality on either the real or imaginary part are all convex over ℝ. -/ theorem convex_halfspace_re_lt (r : ℝ) : Convex ℝ { c : ℂ | c.re < r } := convex_halfspace_lt (IsLinearMap.mk Complex.add_re Complex.smul_re) _ theorem convex_halfspace_re_le (r : ℝ) : Convex ℝ { c : ℂ | c.re ≤ r } := convex_halfspace_le (IsLinearMap.mk Complex.add_re Complex.smul_re) _ theorem convex_halfspace_re_gt (r : ℝ) : Convex ℝ { c : ℂ | r < c.re } := convex_halfspace_gt (IsLinearMap.mk Complex.add_re Complex.smul_re) _ theorem convex_halfspace_re_ge (r : ℝ) : Convex ℝ { c : ℂ | r ≤ c.re } := convex_halfspace_ge (IsLinearMap.mk Complex.add_re Complex.smul_re) _ theorem convex_halfspace_im_lt (r : ℝ) : Convex ℝ { c : ℂ | c.im < r } := convex_halfspace_lt (IsLinearMap.mk Complex.add_im Complex.smul_im) _ theorem convex_halfspace_im_le (r : ℝ) : Convex ℝ { c : ℂ | c.im ≤ r } := convex_halfspace_le (IsLinearMap.mk Complex.add_im Complex.smul_im) _ theorem convex_halfspace_im_gt (r : ℝ) : Convex ℝ { c : ℂ | r < c.im } := convex_halfspace_gt (IsLinearMap.mk Complex.add_im Complex.smul_im) _ theorem convex_halfspace_im_ge (r : ℝ) : Convex ℝ { c : ℂ | r ≤ c.im } := convex_halfspace_ge (IsLinearMap.mk Complex.add_im Complex.smul_im) _
Analysis\Convex\Contractible.lean
/- 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.Convex.Star import Mathlib.Topology.Homotopy.Contractible /-! # A convex set is contractible In this file we prove that a (star) convex set in a real topological vector space is a contractible topological space. -/ variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] {s : Set E} {x : E} /-- A non-empty star convex set is a contractible space. -/ protected theorem StarConvex.contractibleSpace (h : StarConvex ℝ x s) (hne : s.Nonempty) : ContractibleSpace s := by refine (contractible_iff_id_nullhomotopic s).2 ⟨⟨x, h.mem hne⟩, ⟨⟨⟨fun p => ⟨p.1.1 • x + (1 - p.1.1) • (p.2 : E), ?_⟩, ?_⟩, fun x => ?_, fun x => ?_⟩⟩⟩ · exact h p.2.2 p.1.2.1 (sub_nonneg.2 p.1.2.2) (add_sub_cancel _ _) · exact ((continuous_subtype_val.fst'.smul continuous_const).add ((continuous_const.sub continuous_subtype_val.fst').smul continuous_subtype_val.snd')).subtype_mk _ · ext1 simp · ext1 simp /-- A non-empty convex set is a contractible space. -/ protected theorem Convex.contractibleSpace (hs : Convex ℝ s) (hne : s.Nonempty) : ContractibleSpace s := let ⟨_, hx⟩ := hne (hs.starConvex hx).contractibleSpace hne instance (priority := 100) RealTopologicalVectorSpace.contractibleSpace : ContractibleSpace E := (Homeomorph.Set.univ E).contractibleSpace_iff.mp <| convex_univ.contractibleSpace Set.univ_nonempty
Analysis\Convex\Deriv.lean
/- 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, David Loeffler -/ import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Convex.Slope /-! # Convexity of functions and derivatives Here we relate convexity of functions `ℝ → ℝ` to properties of their derivatives. ## Main results * `MonotoneOn.convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `ConvexOn.monotoneOn_deriv`: if a function is convex and differentiable, then its derivative is monotone. -/ open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ## Monotonicity of `f'` implies convexity of `f` -/ /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is monotone on the interior, then `f` is convex on `D`. -/ theorem MonotoneOn.convexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn ℝ D f := convexOn_of_slope_mono_adjacent hD (by intro x y z hx hz hxy hyz -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we apply MVT to both `[x, y]` and `[y, z]` obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y) := exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD') rw [← ha, ← hb] exact hf'_mono (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb).le) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is antitone on the interior, then `f` is concave on `D`. -/ theorem AntitoneOn.concaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn ℝ D f := haveI : MonotoneOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg) theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hay with ⟨b, ⟨hab, hby⟩⟩ refine ⟨b, ⟨hxa.trans hab, hby⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxa, hay⟩ ⟨hxa.trans hab, hby⟩ hab theorem StrictMonoOn.exists_slope_lt_deriv {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, (f w - f x) / (w - x) < deriv f a := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, (f y - f w) / (y - w) < deriv f b := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨b, ⟨hxw.trans hwb, hby⟩, ?_⟩ simp only [div_lt_iff, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (w - x) < deriv f b * (w - x) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hxa with ⟨b, ⟨hxb, hba⟩⟩ refine ⟨b, ⟨hxb, hba.trans hay⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxb, hba.trans hay⟩ ⟨hxa, hay⟩ hba theorem StrictMonoOn.exists_deriv_lt_slope {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, deriv f a < (f w - f x) / (w - x) := by apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, deriv f b < (f y - f w) / (y - w) := by apply StrictMonoOn.exists_deriv_lt_slope_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨a, ⟨hxa, haw.trans hwy⟩, ?_⟩ simp only [lt_div_iff, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (y - w) < deriv f b * (y - w) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hwy) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, and `f'` is strictly monotone on the interior, then `f` is strictly convex on `D`. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict monotonicity of `f'`. -/ theorem StrictMonoOn.strictConvexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : StrictMonoOn (deriv f) (interior D)) : StrictConvexOn ℝ D f := strictConvexOn_of_slope_strict_mono_adjacent hD fun {x y z} hx hz hxy hyz => by -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we get points `a` and `b` in each interval `[x, y]` and `[y, z]` where the derivatives -- can be compared to the slopes between `x, y` and `y, z` respectively. obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := StrictMonoOn.exists_slope_lt_deriv (hf.mono hxyD) hxy (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b < (f z - f y) / (z - y) := StrictMonoOn.exists_deriv_lt_slope (hf.mono hyzD) hyz (hf'.mono hyzD') apply ha.trans (lt_trans _ hb) exact hf' (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f'` is strictly antitone on the interior, then `f` is strictly concave on `D`. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict antitonicity of `f'`. -/ theorem StrictAntiOn.strictConcaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (h_anti : StrictAntiOn (deriv f) (interior D)) : StrictConcaveOn ℝ D f := have : StrictMonoOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_neg f ▸ (this.strictConvexOn_of_deriv hD hf.neg).neg /-- If a function `f` is differentiable and `f'` is monotone on `ℝ` then `f` is convex. -/ theorem Monotone.convexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf'_mono : Monotone (deriv f)) : ConvexOn ℝ univ f := (hf'_mono.monotoneOn _).convexOn_of_deriv convex_univ hf.continuous.continuousOn hf.differentiableOn /-- If a function `f` is differentiable and `f'` is antitone on `ℝ` then `f` is concave. -/ theorem Antitone.concaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf'_anti : Antitone (deriv f)) : ConcaveOn ℝ univ f := (hf'_anti.antitoneOn _).concaveOn_of_deriv convex_univ hf.continuous.continuousOn hf.differentiableOn /-- If a function `f` is continuous and `f'` is strictly monotone on `ℝ` then `f` is strictly convex. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict monotonicity of `f'`. -/ theorem StrictMono.strictConvexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f) (hf'_mono : StrictMono (deriv f)) : StrictConvexOn ℝ univ f := (hf'_mono.strictMonoOn _).strictConvexOn_of_deriv convex_univ hf.continuousOn /-- If a function `f` is continuous and `f'` is strictly antitone on `ℝ` then `f` is strictly concave. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict antitonicity of `f'`. -/ theorem StrictAnti.strictConcaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f) (hf'_anti : StrictAnti (deriv f)) : StrictConcaveOn ℝ univ f := (hf'_anti.strictAntiOn _).strictConcaveOn_of_deriv convex_univ hf.continuousOn /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/ theorem convexOn_of_deriv2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D)) (hf''_nonneg : ∀ x ∈ interior D, 0 ≤ deriv^[2] f x) : ConvexOn ℝ D f := (monotoneOn_of_deriv_nonneg hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by rwa [interior_interior]).convexOn_of_deriv hD hf hf' /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/ theorem concaveOn_of_deriv2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D)) (hf''_nonpos : ∀ x ∈ interior D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f := (antitoneOn_of_deriv_nonpos hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by rwa [interior_interior]).concaveOn_of_deriv hD hf hf' /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/ lemma convexOn_of_hasDerivWithinAt2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x) (hf''₀ : ∀ x ∈ interior D, 0 ≤ f'' x) : ConvexOn ℝ D f := by have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf' refine convexOn_of_deriv2_nonneg hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_ · rw [differentiableOn_congr this] exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt · rintro x hx convert hf''₀ _ hx using 1 dsimp rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx] exact (hf'' _ hy).congr this $ by rw [this hy] /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/ lemma concaveOn_of_hasDerivWithinAt2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x) (hf''₀ : ∀ x ∈ interior D, f'' x ≤ 0) : ConcaveOn ℝ D f := by have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf' refine concaveOn_of_deriv2_nonpos hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_ · rw [differentiableOn_congr this] exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt · rintro x hx convert hf''₀ _ hx using 1 dsimp rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx] exact (hf'' _ hy).congr this $ by rw [this hy] /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on the interior, then `f` is strictly convex on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_of_deriv2_pos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f := ((strictMonoOn_of_deriv_pos hD.interior fun z hz => (differentiableAt_of_deriv_ne_zero (hf'' z hz).ne').differentiableWithinAt.continuousWithinAt) <| by rwa [interior_interior]).strictConvexOn_of_deriv hD hf /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on the interior, then `f` is strictly concave on `D`. Note that we don't require twice differentiability explicitly as it already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_of_deriv2_neg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f := ((strictAntiOn_of_deriv_neg hD.interior fun z hz => (differentiableAt_of_deriv_ne_zero (hf'' z hz).ne).differentiableWithinAt.continuousWithinAt) <| by rwa [interior_interior]).strictConcaveOn_of_deriv hD hf /-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and `f''` is nonnegative on `D`, then `f` is convex on `D`. -/ theorem convexOn_of_deriv2_nonneg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D) (hf''_nonneg : ∀ x ∈ D, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ D f := convexOn_of_deriv2_nonneg hD hf'.continuousOn (hf'.mono interior_subset) (hf''.mono interior_subset) fun x hx => hf''_nonneg x (interior_subset hx) /-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and `f''` is nonpositive on `D`, then `f` is concave on `D`. -/ theorem concaveOn_of_deriv2_nonpos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D) (hf''_nonpos : ∀ x ∈ D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f := concaveOn_of_deriv2_nonpos hD hf'.continuousOn (hf'.mono interior_subset) (hf''.mono interior_subset) fun x hx => hf''_nonpos x (interior_subset hx) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on `D`, then `f` is strictly convex on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_of_deriv2_pos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f := strictConvexOn_of_deriv2_pos hD hf fun x hx => hf'' x (interior_subset hx) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on `D`, then `f` is strictly concave on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_of_deriv2_neg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f := strictConcaveOn_of_deriv2_neg hD hf fun x hx => hf'' x (interior_subset hx) /-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonnegative on `ℝ`, then `f` is convex on `ℝ`. -/ theorem convexOn_univ_of_deriv2_nonneg {f : ℝ → ℝ} (hf' : Differentiable ℝ f) (hf'' : Differentiable ℝ (deriv f)) (hf''_nonneg : ∀ x, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ univ f := convexOn_of_deriv2_nonneg' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ => hf''_nonneg x /-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonpositive on `ℝ`, then `f` is concave on `ℝ`. -/ theorem concaveOn_univ_of_deriv2_nonpos {f : ℝ → ℝ} (hf' : Differentiable ℝ f) (hf'' : Differentiable ℝ (deriv f)) (hf''_nonpos : ∀ x, deriv^[2] f x ≤ 0) : ConcaveOn ℝ univ f := concaveOn_of_deriv2_nonpos' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ => hf''_nonpos x /-- If a function `f` is continuous on `ℝ`, and `f''` is strictly positive on `ℝ`, then `f` is strictly convex on `ℝ`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_univ_of_deriv2_pos {f : ℝ → ℝ} (hf : Continuous f) (hf'' : ∀ x, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ univ f := strictConvexOn_of_deriv2_pos' convex_univ hf.continuousOn fun x _ => hf'' x /-- If a function `f` is continuous on `ℝ`, and `f''` is strictly negative on `ℝ`, then `f` is strictly concave on `ℝ`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_univ_of_deriv2_neg {f : ℝ → ℝ} (hf : Continuous f) (hf'' : ∀ x, deriv^[2] f x < 0) : StrictConcaveOn ℝ univ f := strictConcaveOn_of_deriv2_neg' convex_univ hf.continuousOn fun x _ => hf'' x /-! ## Convexity of `f` implies monotonicity of `f'` In this section we prove inequalities relating derivatives of convex functions to slopes of secant lines, and deduce that if `f` is convex then its derivative is monotone (and similarly for strict convexity / strict monotonicity). -/ section slope variable {𝕜 : Type*} [LinearOrderedField 𝕜] {s : Set 𝕜} {f : 𝕜 → 𝕜} {x : 𝕜} /-- If `f : 𝕜 → 𝕜` is convex on `s`, then for any point `x ∈ s` the slope of the secant line of `f` through `x` is monotone on `s \ {x}`. -/ lemma ConvexOn.slope_mono (hfc : ConvexOn 𝕜 s f) (hx : x ∈ s) : MonotoneOn (slope f x) (s \ {x}) := (slope_fun_def_field f _).symm ▸ fun _ hy _ hz hz' ↦ hfc.secant_mono hx (mem_of_mem_diff hy) (mem_of_mem_diff hz) (not_mem_of_mem_diff hy :) (not_mem_of_mem_diff hz :) hz' /-- If `f : 𝕜 → 𝕜` is concave on `s`, then for any point `x ∈ s` the slope of the secant line of `f` through `x` is antitone on `s \ {x}`. -/ lemma ConcaveOn.slope_anti (hfc : ConcaveOn 𝕜 s f) (hx : x ∈ s) : AntitoneOn (slope f x) (s \ {x}) := by rw [← neg_neg f, slope_neg_fun] exact (ConvexOn.slope_mono hfc.neg hx).neg end slope namespace ConvexOn variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} section left /-! ### Convex functions, derivative at left endpoint of secant -/ /-- If `f : ℝ → ℝ` is convex on `S` and right-differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is bounded below by the right derivative of `f` at `x`. -/ lemma le_slope_of_hasDerivWithinAt_Ioi (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : f' ≤ slope f x y := by apply le_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Ioi_self).mp hf' simp_rw [eventually_nhdsWithin_iff, slope_def_field] filter_upwards [eventually_lt_nhds hxy] with t ht (ht' : x < t) refine hfc.secant_mono hx (?_ : t ∈ S) hy ht'.ne' hxy.ne' ht.le exact hfc.1.ordConnected.out hx hy ⟨ht'.le, ht.le⟩ /-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` using `derivWithin`. -/ lemma right_deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : derivWithin f (Ioi x) x ≤ slope f x y := le_slope_of_hasDerivWithinAt_Ioi hfc hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `x`, then the slope of any secant line with left endpoint at `x` is bounded below by the derivative of `f` within `S` at `x`. This is fractionally weaker than `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma le_slope_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S x) : f' ≤ slope f x y := by refine hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Ioi_iff_exists_Ioc_subset] exact ⟨y, hxy, Ioc_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ /-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt` using `derivWithin`. -/ lemma derivWithin_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : derivWithin f S x ≤ slope f x y := le_slope_of_hasDerivWithinAt hfc hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is bounded below by the derivative of `f` at `x`. -/ lemma le_slope_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (ha : HasDerivAt f f' x) : f' ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy ha.hasDerivWithinAt /-- Reformulation of `ConvexOn.le_slope_of_hasDerivAt` using `deriv` -/ lemma deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : deriv f x ≤ slope f x y := le_slope_of_hasDerivAt hfc hx hy hxy hfd.hasDerivAt end left section right /-! ### Convex functions, derivative at right endpoint of secant -/ /-- If `f : ℝ → ℝ` is convex on `S` and left-differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is bounded above by the left derivative of `f` at `y`. -/ lemma slope_le_of_hasDerivWithinAt_Iio (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : slope f x y ≤ f' := by apply ge_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Iio_self).mp hf' simp_rw [eventually_nhdsWithin_iff, slope_comm f x y, slope_def_field] filter_upwards [eventually_gt_nhds hxy] with t ht (ht' : t < y) refine hfc.secant_mono hy hx (?_ : t ∈ S) hxy.ne ht'.ne ht.le exact hfc.1.ordConnected.out hx hy ⟨ht.le, ht'.le⟩ /-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` using `derivWithin`. -/ lemma slope_le_left_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : slope f x y ≤ derivWithin f (Iio y) y := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `y`, then the slope of any secant line with right endpoint at `y` is bounded above by the derivative of `f` within `S` at `y`. This is fractionally weaker than `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma slope_le_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : slope f x y ≤ f' := by refine hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Iio_iff_exists_Ico_subset] exact ⟨x, hxy, Ico_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ /-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt` using `derivWithin`. -/ lemma slope_le_derivWithin (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : slope f x y ≤ derivWithin f S y := hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is bounded above by the derivative of `f` at `y`. -/ lemma slope_le_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : slope f x y ≤ f' := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt /-- Reformulation of `ConvexOn.slope_le_of_hasDerivAt` using `deriv`. -/ lemma slope_le_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : slope f x y ≤ deriv f y := hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Convex functions, monotonicity of derivative -/ /-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone on `S`. -/ lemma monotoneOn_derivWithin (hfc : ConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : MonotoneOn (derivWithin f S) S := by intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.derivWithin_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_derivWithin hx hy hxy' (hfd y hy)) /-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone on `S`. -/ theorem monotoneOn_deriv (hfc : ConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : MonotoneOn (deriv f) S := by intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.deriv_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_deriv hx hy hxy' (hfd y hy)) end ConvexOn namespace StrictConvexOn variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} section left /-! ### Strict convex functions, derivative at left endpoint of secant -/ /-- If `f : ℝ → ℝ` is strictly convex on `S` and right-differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is strictly greater than the right derivative of `f` at `x`. -/ lemma lt_slope_of_hasDerivWithinAt_Ioi (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : f' < slope f x y := by obtain ⟨u, hxu, huy⟩ := exists_between hxy have hu : u ∈ S := hfc.1.ordConnected.out hx hy ⟨hxu.le, huy.le⟩ have := hfc.secant_strict_mono hx hu hy hxu.ne' hxy.ne' huy simp only [← slope_def_field] at this exact (hfc.convexOn.le_slope_of_hasDerivWithinAt_Ioi hx hu hxu hf').trans_lt this lemma right_deriv_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : derivWithin f (Ioi x) x < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable within `S` at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is strictly greater than the derivative of `f` within `S` at `x`. This is fractionally weaker than `StrictConvexOn.lt_slope_of_hasDerivWithinAt_Ioi` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma lt_slope_of_hasDerivWithinAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S x) : f' < slope f x y := by refine hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Ioi_iff_exists_Ioc_subset] exact ⟨y, hxy, Ioc_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ lemma derivWithin_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : derivWithin f S x < slope f x y := hfc.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is strictly greater than the derivative of `f` at `x`. -/ lemma lt_slope_of_hasDerivAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' x) : f' < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.hasDerivWithinAt lemma deriv_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : deriv f x < slope f x y := hfc.lt_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt end left section right /-! ### Strict convex functions, derivative at right endpoint of secant -/ /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is strictly less than the left derivative at `y`. -/ lemma slope_lt_of_hasDerivWithinAt_Iio (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : slope f x y < f' := by obtain ⟨u, hxu, huy⟩ := exists_between hxy have hu : u ∈ S := hfc.1.ordConnected.out hx hy ⟨hxu.le, huy.le⟩ have := hfc.secant_strict_mono hy hx hu hxy.ne huy.ne hxu simp_rw [← slope_def_field, slope_comm _ y] at this exact this.trans_le <| hfc.convexOn.slope_le_of_hasDerivWithinAt_Iio hu hy huy hf' lemma slope_lt_left_deriv (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : slope f x y < derivWithin f (Iio y) y := hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable within `S` at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is strictly less than the derivative of `f` within `S` at `y`. This is fractionally weaker than `StrictConvexOn.slope_lt_of_hasDerivWithinAt_Iio` but simpler to apply under a `DifferentiableOn S` hypothesis.-/ lemma slope_lt_of_hasDerivWithinAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : slope f x y < f' := by refine hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Iio_iff_exists_Ico_subset] exact ⟨x, hxy, Ico_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ lemma slope_lt_derivWithin (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : slope f x y < derivWithin f S y := hfc.slope_lt_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is strictly less than the derivative of `f` at `y`. -/ lemma slope_lt_of_hasDerivAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : slope f x y < f' := hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt lemma slope_lt_deriv (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : slope f x y < deriv f y := hfc.slope_lt_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Strict convex functions, strict monotonicity of derivative -/ /-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone on `S`. -/ lemma strictMonoOn_derivWithin (hfc : StrictConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : StrictMonoOn (derivWithin f S) S := by intro x hx y hy hxy exact (hfc.derivWithin_lt_slope hx hy hxy (hfd x hx)).trans (hfc.slope_lt_derivWithin hx hy hxy (hfd y hy)) /-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone on `S`. -/ lemma strictMonoOn_deriv (hfc : StrictConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : StrictMonoOn (deriv f) S := by intro x hx y hy hxy exact (hfc.deriv_lt_slope hx hy hxy (hfd x hx)).trans (hfc.slope_lt_deriv hx hy hxy (hfd y hy)) end StrictConvexOn section MirrorImage variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} namespace ConcaveOn section left /-! ### Concave functions, derivative at left endpoint of secant -/ lemma slope_le_of_hasDerivWithinAt_Ioi (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : slope f x y ≤ f' := by simpa only [Pi.neg_def, slope_neg, neg_neg] using neg_le_neg (hfc.neg.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.neg) lemma slope_le_right_deriv (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : slope f x y ≤ derivWithin f (Ioi x) x := hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt lemma slope_le_of_hasDerivWithinAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : HasDerivWithinAt f f' S x) : slope f x y ≤ f' := by refine hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy (hfd.mono_of_mem ?_) rw [mem_nhdsWithin_Ioi_iff_exists_Ioc_subset] exact ⟨y, hxy, Ioc_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ lemma slope_le_derivWithin (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : slope f x y ≤ derivWithin f S x := hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt lemma slope_le_of_hasDerivAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' x) : slope f x y ≤ f' := hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy hf'.hasDerivWithinAt lemma slope_le_deriv (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : slope f x y ≤ deriv f x := hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt end left section right /-! ### Concave functions, derivative at right endpoint of secant -/ lemma le_slope_of_hasDerivWithinAt_Iio (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : f' ≤ slope f x y := by simpa only [neg_neg, Pi.neg_def, slope_neg] using neg_le_neg (hfc.neg.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.neg) lemma left_deriv_le_slope (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : derivWithin f (Iio y) y ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt lemma le_slope_of_hasDerivWithinAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : f' ≤ slope f x y := by refine hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy (hf'.mono_of_mem ?_) rw [mem_nhdsWithin_Iio_iff_exists_Ico_subset] exact ⟨x, hxy, Ico_subset_Icc_self.trans (hfc.1.ordConnected.out hx hy)⟩ lemma derivWithin_le_slope (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : derivWithin f S y ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt lemma le_slope_of_hasDerivAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : f' ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt lemma deriv_le_slope (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : deriv f y ≤ slope f x y := hfc.le_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Concave functions, anti-monotonicity of derivative -/ lemma antitoneOn_derivWithin (hfc : ConcaveOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : AntitoneOn (derivWithin f S) S := by intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.derivWithin_le_slope hx hy hxy' (hfd y hy)).trans (hfc.slope_le_derivWithin hx hy hxy' (hfd x hx)) /-- If `f` is concave on `S` and differentiable at all points of `S`, then its derivative is antitone (monotone decreasing) on `S`. -/ theorem antitoneOn_deriv (hfc : ConcaveOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : AntitoneOn (deriv f) S := by simpa only [Pi.neg_def, deriv.neg, neg_neg] using (hfc.neg.monotoneOn_deriv (fun x hx ↦ (hfd x hx).neg)).neg end ConcaveOn namespace StrictConcaveOn section left /-! ### Strict concave functions, derivative at left endpoint of secant -/ lemma slope_lt_of_hasDerivWithinAt_Ioi (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : slope f x y < f' := by simpa only [Pi.neg_def, slope_neg, neg_neg] using neg_lt_neg (hfc.neg.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.neg) lemma slope_lt_right_deriv (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : slope f x y < derivWithin f (Ioi x) x := hfc.slope_lt_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt lemma slope_lt_of_hasDerivWithinAt (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : HasDerivWithinAt f f' S x) : slope f x y < f' := by simpa only [Pi.neg_def, slope_neg, neg_neg] using neg_lt_neg (hfc.neg.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.neg) lemma slope_lt_derivWithin (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : slope f x y < derivWithin f S x := hfc.slope_lt_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt lemma slope_lt_of_hasDerivAt (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : HasDerivAt f f' x) : slope f x y < f' := by simpa only [Pi.neg_def, slope_neg, neg_neg] using neg_lt_neg (hfc.neg.lt_slope_of_hasDerivAt hx hy hxy hfd.neg) lemma slope_lt_deriv (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : slope f x y < deriv f x := hfc.slope_lt_of_hasDerivAt hx hy hxy hfd.hasDerivAt end left section right /-! ### Strict concave functions, derivative at right endpoint of secant -/ lemma lt_slope_of_hasDerivWithinAt_Iio (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : f' < slope f x y := by simpa only [Pi.neg_def, slope_neg, neg_neg] using neg_lt_neg (hfc.neg.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hf'.neg) lemma left_deriv_lt_slope (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : derivWithin f (Iio y) y < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt lemma lt_slope_of_hasDerivWithinAt (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : f' < slope f x y := by simpa only [neg_neg, Pi.neg_def, slope_neg] using neg_lt_neg (hfc.neg.slope_lt_of_hasDerivWithinAt hx hy hxy hf'.neg) lemma derivWithin_lt_slope (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : derivWithin f S y < slope f x y := hfc.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt lemma lt_slope_of_hasDerivAt (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : f' < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt lemma deriv_lt_slope (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : deriv f y < slope f x y := hfc.lt_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Strict concave functions, anti-monotonicity of derivative -/ lemma strictAntiOn_derivWithin (hfc : StrictConcaveOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : StrictAntiOn (derivWithin f S) S := by intro x hx y hy hxy exact (hfc.derivWithin_lt_slope hx hy hxy (hfd y hy)).trans (hfc.slope_lt_derivWithin hx hy hxy (hfd x hx)) theorem strictAntiOn_deriv (hfc : StrictConcaveOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : StrictAntiOn (deriv f) S := by simpa only [Pi.neg_def, deriv.neg, neg_neg] using (hfc.neg.strictMonoOn_deriv (fun x hx ↦ (hfd x hx).neg)).neg end StrictConcaveOn end MirrorImage
Analysis\Convex\EGauge.lean
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Seminorm /-! # The Minkowski functional, normed field version In this file we define `(egauge 𝕜 s ·)` to be the Minkowski functional (gauge) of the set `s` in a topological vector space `E` over a normed field `𝕜`, as a function `E → ℝ≥0∞`. It is defined as the infimum of the norms of `c : 𝕜` such that `x ∈ c • s`. In particular, for `𝕜 = ℝ≥0` this definition gives an `ℝ≥0∞`-valued version of `gauge` defined in `Mathlib/Analysis/Convex/Gauge.lean`. This definition can be used to generalize the notion of Fréchet derivative to maps between topological vector spaces without norms. Currently, we can't reuse results about `egauge` for `gauge`, because we lack a theory of normed semifields. -/ open Set Filter Metric open scoped Topology Pointwise ENNReal NNReal section SMul /-- The Minkowski functional for vector spaces over normed fields. Given a set `s` in a vector space over a normed field `𝕜`, `egauge s` is the functional which sends `x : E` to the infimum of `‖c‖₊` over `c` such that `x` belongs to `s` scaled by `c`. The definition only requires `𝕜` to have a `NNNorm` instance and `(· • ·) : 𝕜 → E → E` to be defined. This way the definition applies, e.g., to `𝕜 = ℝ≥0`. For `𝕜 = ℝ≥0`, the function is equal (up to conversion to `ℝ`) to the usual Minkowski functional defined in `gauge`. -/ noncomputable def egauge (𝕜 : Type*) [NNNorm 𝕜] {E : Type*} [SMul 𝕜 E] (s : Set E) (x : E) : ℝ≥0∞ := ⨅ (c : 𝕜) (_ : x ∈ c • s), ‖c‖₊ variable (𝕜 : Type*) [NNNorm 𝕜] {E : Type*} [SMul 𝕜 E] {c : 𝕜} {s t : Set E} {x : E} {r : ℝ≥0∞} @[mono, gcongr] lemma egauge_anti (h : s ⊆ t) (x : E) : egauge 𝕜 t x ≤ egauge 𝕜 s x := iInf_mono fun _c ↦ iInf_mono' fun hc ↦ ⟨smul_set_mono h hc, le_rfl⟩ @[simp] lemma egauge_empty (x : E) : egauge 𝕜 ∅ x = ∞ := by simp [egauge] variable {𝕜} lemma egauge_le_of_mem_smul (h : x ∈ c • s) : egauge 𝕜 s x ≤ ‖c‖₊ := iInf₂_le c h lemma le_egauge_iff : r ≤ egauge 𝕜 s x ↔ ∀ c : 𝕜, x ∈ c • s → r ≤ ‖c‖₊ := le_iInf₂_iff lemma egauge_eq_top : egauge 𝕜 s x = ∞ ↔ ∀ c : 𝕜, x ∉ c • s := by simp [egauge] lemma egauge_lt_iff : egauge 𝕜 s x < r ↔ ∃ c : 𝕜, x ∈ c • s ∧ ‖c‖₊ < r := by simp [egauge, iInf_lt_iff] end SMul section SMulZero variable (𝕜 : Type*) [NNNorm 𝕜] [Nonempty 𝕜] {E : Type*} [Zero E] [SMulZeroClass 𝕜 E] {c : 𝕜} {s t : Set E} {x : E} {r : ℝ≥0∞} @[simp] lemma egauge_zero_left_eq_top : egauge 𝕜 0 x = ∞ ↔ x ≠ 0 := by simp [egauge_eq_top] @[simp] alias ⟨_, egauge_zero_left⟩ := egauge_zero_left_eq_top end SMulZero section Module variable {𝕜 : Type*} [NormedDivisionRing 𝕜] {α E : Type*} [AddCommGroup E] [Module 𝕜 E] {c : 𝕜} {s t : Set E} {x y : E} {r : ℝ≥0∞} /-- If `c • x ∈ s` and `c ≠ 0`, then `egauge 𝕜 s x` is at most `((‖c‖₊⁻¹ : ℝ≥0) : ℝ≥0∞). See also `egauge_le_of_smul_mem`. -/ lemma egauge_le_of_smul_mem_of_ne (h : c • x ∈ s) (hc : c ≠ 0) : egauge 𝕜 s x ≤ ↑(‖c‖₊⁻¹ : ℝ≥0) := by rw [← nnnorm_inv] exact egauge_le_of_mem_smul <| (mem_inv_smul_set_iff₀ hc _ _).2 h /-- If `c • x ∈ s`, then `egauge 𝕜 s x` is at most `(‖c‖₊ : ℝ≥0∞)⁻¹. See also `egauge_le_of_smul_mem_of_ne`. -/ lemma egauge_le_of_smul_mem (h : c • x ∈ s) : egauge 𝕜 s x ≤ (‖c‖₊ : ℝ≥0∞)⁻¹ := by rcases eq_or_ne c 0 with rfl | hc · simp · exact (egauge_le_of_smul_mem_of_ne h hc).trans ENNReal.coe_inv_le lemma mem_of_egauge_lt_one (hs : Balanced 𝕜 s) (hx : egauge 𝕜 s x < 1) : x ∈ s := let ⟨c, hxc, hc⟩ := egauge_lt_iff.1 hx hs c (mod_cast hc.le) hxc variable (𝕜) @[simp] lemma egauge_zero_right (hs : s.Nonempty) : egauge 𝕜 s 0 = 0 := by have : 0 ∈ (0 : 𝕜) • s := by simp [zero_smul_set hs] simpa using egauge_le_of_mem_smul this @[simp] lemma egauge_zero_zero : egauge 𝕜 (0 : Set E) 0 = 0 := egauge_zero_right _ ⟨0, rfl⟩ lemma egauge_le_one (h : x ∈ s) : egauge 𝕜 s x ≤ 1 := by rw [← one_smul 𝕜 s] at h simpa using egauge_le_of_mem_smul h variable {𝕜} lemma le_egauge_smul_left (c : 𝕜) (s : Set E) (x : E) : egauge 𝕜 s x / ‖c‖₊ ≤ egauge 𝕜 (c • s) x := by simp_rw [le_egauge_iff, smul_smul] rintro a ⟨x, hx, rfl⟩ apply ENNReal.div_le_of_le_mul rw [← ENNReal.coe_mul, ← nnnorm_mul] exact egauge_le_of_mem_smul <| smul_mem_smul_set hx lemma egauge_smul_left (hc : c ≠ 0) (s : Set E) (x : E) : egauge 𝕜 (c • s) x = egauge 𝕜 s x / ‖c‖₊ := by refine le_antisymm ?_ (le_egauge_smul_left _ _ _) rw [ENNReal.le_div_iff_mul_le (by simp [*]) (by simp)] calc egauge 𝕜 (c • s) x * ‖c‖₊ = egauge 𝕜 (c • s) x / ‖c⁻¹‖₊ := by rw [nnnorm_inv, ENNReal.coe_inv (by simpa), div_eq_mul_inv, inv_inv] _ ≤ egauge 𝕜 (c⁻¹ • c • s) x := le_egauge_smul_left _ _ _ _ = egauge 𝕜 s x := by rw [inv_smul_smul₀ hc] lemma le_egauge_smul_right (c : 𝕜) (s : Set E) (x : E) : ‖c‖₊ * egauge 𝕜 s x ≤ egauge 𝕜 s (c • x) := by rw [le_egauge_iff] rintro a ⟨y, hy, hxy⟩ rcases eq_or_ne c 0 with rfl | hc · simp · refine ENNReal.mul_le_of_le_div' <| le_trans ?_ ENNReal.coe_div_le rw [div_eq_inv_mul, ← nnnorm_inv, ← nnnorm_mul] refine egauge_le_of_mem_smul ⟨y, hy, ?_⟩ simp only [mul_smul, hxy, inv_smul_smul₀ hc] lemma egauge_smul_right (h : c = 0 → s.Nonempty) (x : E) : egauge 𝕜 s (c • x) = ‖c‖₊ * egauge 𝕜 s x := by refine le_antisymm ?_ (le_egauge_smul_right c s x) rcases eq_or_ne c 0 with rfl | hc · simp [egauge_zero_right _ (h rfl)] · rw [mul_comm, ← ENNReal.div_le_iff_le_mul (.inl <| by simpa) (.inl ENNReal.coe_ne_top), ENNReal.div_eq_inv_mul, ← ENNReal.coe_inv (by simpa), ← nnnorm_inv] refine (le_egauge_smul_right _ _ _).trans_eq ?_ rw [inv_smul_smul₀ hc] end Module section SeminormedAddCommGroup variable (𝕜 : Type*) [NormedField 𝕜] {α E : Type*} [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] {c : 𝕜} {s t : Set E} {x y : E} lemma div_le_egauge_closedBall (r : ℝ≥0) (x : E) : ‖x‖₊ / r ≤ egauge 𝕜 (closedBall 0 r) x := by rw [le_egauge_iff] rintro c ⟨y, hy, rfl⟩ rw [mem_closedBall_zero_iff, ← coe_nnnorm, NNReal.coe_le_coe] at hy simp only [nnnorm_smul, ENNReal.coe_mul] apply ENNReal.div_le_of_le_mul gcongr lemma le_egauge_closedBall_one (x : E) : ‖x‖₊ ≤ egauge 𝕜 (closedBall 0 1) x := by simpa using div_le_egauge_closedBall 𝕜 1 x lemma div_le_egauge_ball (r : ℝ≥0) (x : E) : ‖x‖₊ / r ≤ egauge 𝕜 (ball 0 r) x := (div_le_egauge_closedBall 𝕜 r x).trans <| egauge_anti _ ball_subset_closedBall _ lemma le_egauge_ball_one (x : E) : ‖x‖₊ ≤ egauge 𝕜 (ball 0 1) x := by simpa using div_le_egauge_ball 𝕜 1 x end SeminormedAddCommGroup section SeminormedAddCommGroup variable {𝕜 : Type*} [NormedField 𝕜] {α E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {c : 𝕜} {s t : Set E} {x y : E} {r : ℝ≥0} lemma egauge_ball_le_of_one_lt_norm (hc : 1 < ‖c‖) (h₀ : r ≠ 0 ∨ x ≠ 0) : egauge 𝕜 (ball 0 r) x ≤ ‖c‖₊ * ‖x‖₊ / r := by rcases (zero_le r).eq_or_lt with rfl | hr · rw [ENNReal.coe_zero, ENNReal.div_zero (mul_ne_zero _ _)] · apply le_top · simpa using one_pos.trans hc · simpa using h₀ · rcases eq_or_ne x 0 with rfl | hx · rw [egauge_zero_right] <;> simp [*] rcases rescale_to_shell hc hr hx with ⟨a, ha₀, har, -, hainv⟩ calc egauge 𝕜 (ball 0 r) x ≤ ↑(‖a‖₊⁻¹) := egauge_le_of_smul_mem_of_ne (mem_ball_zero_iff.2 har) ha₀ _ ≤ ↑(‖c‖₊ * ‖x‖₊ / r) := by rwa [ENNReal.coe_le_coe, div_eq_inv_mul, ← mul_assoc] _ ≤ ‖c‖₊ * ‖x‖₊ / r := ENNReal.coe_div_le.trans <| by rw [ENNReal.coe_mul] lemma egauge_ball_one_le_of_one_lt_norm (hc : 1 < ‖c‖) (x : E) : egauge 𝕜 (ball 0 1) x ≤ ‖c‖₊ * ‖x‖₊ := by simpa using egauge_ball_le_of_one_lt_norm hc (.inl one_ne_zero) end SeminormedAddCommGroup
Analysis\Convex\Exposed.lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Extreme import Mathlib.Analysis.Convex.Function import Mathlib.Topology.Algebra.Module.Basic import Mathlib.Topology.Order.OrderClosed /-! # Exposed sets This file defines exposed sets and exposed points for sets in a real vector space. An exposed subset of `A` is a subset of `A` that is the set of all maximal points of a functional (a continuous linear map `E → 𝕜`) over `A`. By convention, `∅` is an exposed subset of all sets. This allows for better functoriality of the definition (the intersection of two exposed subsets is exposed, faces of a polytope form a bounded lattice). This is an analytic notion of "being on the side of". It is stronger than being extreme (see `IsExposed.isExtreme`), but weaker (for exposed points) than being a vertex. An exposed set of `A` is sometimes called a "face of `A`", but we decided to reserve this terminology to the more specific notion of a face of a polytope (sometimes hopefully soon out on mathlib!). ## Main declarations * `IsExposed 𝕜 A B`: States that `B` is an exposed set of `A` (in the literature, `A` is often implicit). * `IsExposed.isExtreme`: An exposed set is also extreme. ## References See chapter 8 of [Barry Simon, *Convexity*][simon2011] ## TODO Prove lemmas relating exposed sets and points to the intrinsic frontier. -/ open scoped Classical open Affine open Set section PreorderSemiring variable (𝕜 : Type*) {E : Type*} [TopologicalSpace 𝕜] [Semiring 𝕜] [Preorder 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] {A B : Set E} /-- A set `B` is exposed with respect to `A` iff it maximizes some functional over `A` (and contains all points maximizing it). Written `IsExposed 𝕜 A B`. -/ def IsExposed (A B : Set E) : Prop := B.Nonempty → ∃ l : E →L[𝕜] 𝕜, B = { x ∈ A | ∀ y ∈ A, l y ≤ l x } end PreorderSemiring section OrderedRing variable {𝕜 : Type*} {E : Type*} [TopologicalSpace 𝕜] [OrderedRing 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] {l : E →L[𝕜] 𝕜} {A B C : Set E} {X : Finset E} {x : E} /-- A useful way to build exposed sets from intersecting `A` with halfspaces (modelled by an inequality with a functional). -/ def ContinuousLinearMap.toExposed (l : E →L[𝕜] 𝕜) (A : Set E) : Set E := { x ∈ A | ∀ y ∈ A, l y ≤ l x } theorem ContinuousLinearMap.toExposed.isExposed : IsExposed 𝕜 A (l.toExposed A) := fun _ => ⟨l, rfl⟩ theorem isExposed_empty : IsExposed 𝕜 A ∅ := fun ⟨_, hx⟩ => by exfalso exact hx namespace IsExposed protected theorem subset (hAB : IsExposed 𝕜 A B) : B ⊆ A := by rintro x hx obtain ⟨_, rfl⟩ := hAB ⟨x, hx⟩ exact hx.1 @[refl] protected theorem refl (A : Set E) : IsExposed 𝕜 A A := fun ⟨_, _⟩ => ⟨0, Subset.antisymm (fun _ hx => ⟨hx, fun _ _ => le_refl 0⟩) fun _ hx => hx.1⟩ protected theorem antisymm (hB : IsExposed 𝕜 A B) (hA : IsExposed 𝕜 B A) : A = B := hA.subset.antisymm hB.subset /-! `IsExposed` is *not* transitive: Consider a (topologically) open cube with vertices `A₀₀₀, ..., A₁₁₁` and add to it the triangle `A₀₀₀A₀₀₁A₀₁₀`. Then `A₀₀₁A₀₁₀` is an exposed subset of `A₀₀₀A₀₀₁A₀₁₀` which is an exposed subset of the cube, but `A₀₀₁A₀₁₀` is not itself an exposed subset of the cube. -/ protected theorem mono (hC : IsExposed 𝕜 A C) (hBA : B ⊆ A) (hCB : C ⊆ B) : IsExposed 𝕜 B C := by rintro ⟨w, hw⟩ obtain ⟨l, rfl⟩ := hC ⟨w, hw⟩ exact ⟨l, Subset.antisymm (fun x hx => ⟨hCB hx, fun y hy => hx.2 y (hBA hy)⟩) fun x hx => ⟨hBA hx.1, fun y hy => (hw.2 y hy).trans (hx.2 w (hCB hw))⟩⟩ /-- If `B` is a nonempty exposed subset of `A`, then `B` is the intersection of `A` with some closed halfspace. The converse is *not* true. It would require that the corresponding open halfspace doesn't intersect `A`. -/ theorem eq_inter_halfspace' {A B : Set E} (hAB : IsExposed 𝕜 A B) (hB : B.Nonempty) : ∃ l : E →L[𝕜] 𝕜, ∃ a, B = { x ∈ A | a ≤ l x } := by obtain ⟨l, rfl⟩ := hAB hB obtain ⟨w, hw⟩ := hB exact ⟨l, l w, Subset.antisymm (fun x hx => ⟨hx.1, hx.2 w hw.1⟩) fun x hx => ⟨hx.1, fun y hy => (hw.2 y hy).trans hx.2⟩⟩ /-- For nontrivial `𝕜`, if `B` is an exposed subset of `A`, then `B` is the intersection of `A` with some closed halfspace. The converse is *not* true. It would require that the corresponding open halfspace doesn't intersect `A`. -/ theorem eq_inter_halfspace [Nontrivial 𝕜] {A B : Set E} (hAB : IsExposed 𝕜 A B) : ∃ l : E →L[𝕜] 𝕜, ∃ a, B = { x ∈ A | a ≤ l x } := by obtain rfl | hB := B.eq_empty_or_nonempty · refine ⟨0, 1, ?_⟩ rw [eq_comm, eq_empty_iff_forall_not_mem] rintro x ⟨-, h⟩ rw [ContinuousLinearMap.zero_apply] at h have : ¬(1 : 𝕜) ≤ 0 := not_le_of_lt zero_lt_one contradiction exact hAB.eq_inter_halfspace' hB protected theorem inter [ContinuousAdd 𝕜] {A B C : Set E} (hB : IsExposed 𝕜 A B) (hC : IsExposed 𝕜 A C) : IsExposed 𝕜 A (B ∩ C) := by rintro ⟨w, hwB, hwC⟩ obtain ⟨l₁, rfl⟩ := hB ⟨w, hwB⟩ obtain ⟨l₂, rfl⟩ := hC ⟨w, hwC⟩ refine ⟨l₁ + l₂, Subset.antisymm ?_ ?_⟩ · rintro x ⟨⟨hxA, hxB⟩, ⟨-, hxC⟩⟩ exact ⟨hxA, fun z hz => add_le_add (hxB z hz) (hxC z hz)⟩ rintro x ⟨hxA, hx⟩ refine ⟨⟨hxA, fun y hy => ?_⟩, hxA, fun y hy => ?_⟩ · exact (add_le_add_iff_right (l₂ x)).1 ((add_le_add (hwB.2 y hy) (hwC.2 x hxA)).trans (hx w hwB.1)) · exact (add_le_add_iff_left (l₁ x)).1 (le_trans (add_le_add (hwB.2 x hxA) (hwC.2 y hy)) (hx w hwB.1)) theorem sInter [ContinuousAdd 𝕜] {F : Finset (Set E)} (hF : F.Nonempty) (hAF : ∀ B ∈ F, IsExposed 𝕜 A B) : IsExposed 𝕜 A (⋂₀ F) := by induction F using Finset.induction with | empty => exfalso; exact Finset.not_nonempty_empty hF | @insert C F _ hF' => rw [Finset.coe_insert, sInter_insert] obtain rfl | hFnemp := F.eq_empty_or_nonempty · rw [Finset.coe_empty, sInter_empty, inter_univ] exact hAF C (Finset.mem_singleton_self C) · exact (hAF C (Finset.mem_insert_self C F)).inter (hF' hFnemp fun B hB => hAF B (Finset.mem_insert_of_mem hB)) theorem inter_left (hC : IsExposed 𝕜 A C) (hCB : C ⊆ B) : IsExposed 𝕜 (A ∩ B) C := by rintro ⟨w, hw⟩ obtain ⟨l, rfl⟩ := hC ⟨w, hw⟩ exact ⟨l, Subset.antisymm (fun x hx => ⟨⟨hx.1, hCB hx⟩, fun y hy => hx.2 y hy.1⟩) fun x ⟨⟨hxC, _⟩, hx⟩ => ⟨hxC, fun y hy => (hw.2 y hy).trans (hx w ⟨hC.subset hw, hCB hw⟩)⟩⟩ theorem inter_right (hC : IsExposed 𝕜 B C) (hCA : C ⊆ A) : IsExposed 𝕜 (A ∩ B) C := by rw [inter_comm] exact hC.inter_left hCA protected theorem isClosed [OrderClosedTopology 𝕜] {A B : Set E} (hAB : IsExposed 𝕜 A B) (hA : IsClosed A) : IsClosed B := by obtain rfl | hB := B.eq_empty_or_nonempty · simp obtain ⟨l, a, rfl⟩ := hAB.eq_inter_halfspace' hB exact hA.isClosed_le continuousOn_const l.continuous.continuousOn protected theorem isCompact [OrderClosedTopology 𝕜] [T2Space E] {A B : Set E} (hAB : IsExposed 𝕜 A B) (hA : IsCompact A) : IsCompact B := hA.of_isClosed_subset (hAB.isClosed hA.isClosed) hAB.subset end IsExposed variable (𝕜) /-- A point is exposed with respect to `A` iff there exists a hyperplane whose intersection with `A` is exactly that point. -/ def Set.exposedPoints (A : Set E) : Set E := { x ∈ A | ∃ l : E →L[𝕜] 𝕜, ∀ y ∈ A, l y ≤ l x ∧ (l x ≤ l y → y = x) } variable {𝕜} theorem exposed_point_def : x ∈ A.exposedPoints 𝕜 ↔ x ∈ A ∧ ∃ l : E →L[𝕜] 𝕜, ∀ y ∈ A, l y ≤ l x ∧ (l x ≤ l y → y = x) := Iff.rfl theorem exposedPoints_subset : A.exposedPoints 𝕜 ⊆ A := fun _ hx => hx.1 @[simp] theorem exposedPoints_empty : (∅ : Set E).exposedPoints 𝕜 = ∅ := subset_empty_iff.1 exposedPoints_subset /-- Exposed points exactly correspond to exposed singletons. -/ theorem mem_exposedPoints_iff_exposed_singleton : x ∈ A.exposedPoints 𝕜 ↔ IsExposed 𝕜 A {x} := by use fun ⟨hxA, l, hl⟩ _ => ⟨l, Eq.symm <| eq_singleton_iff_unique_mem.2 ⟨⟨hxA, fun y hy => (hl y hy).1⟩, fun z hz => (hl z hz.1).2 (hz.2 x hxA)⟩⟩ rintro h obtain ⟨l, hl⟩ := h ⟨x, mem_singleton _⟩ rw [eq_comm, eq_singleton_iff_unique_mem] at hl exact ⟨hl.1.1, l, fun y hy => ⟨hl.1.2 y hy, fun hxy => hl.2 y ⟨hy, fun z hz => (hl.1.2 z hz).trans hxy⟩⟩⟩ end OrderedRing section LinearOrderedRing variable {𝕜 : Type*} {E : Type*} [TopologicalSpace 𝕜] [LinearOrderedRing 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] {A B C : Set E} namespace IsExposed protected theorem convex (hAB : IsExposed 𝕜 A B) (hA : Convex 𝕜 A) : Convex 𝕜 B := by obtain rfl | hB := B.eq_empty_or_nonempty · exact convex_empty obtain ⟨l, rfl⟩ := hAB hB exact fun x₁ hx₁ x₂ hx₂ a b ha hb hab => ⟨hA hx₁.1 hx₂.1 ha hb hab, fun y hy => ((l.toLinearMap.concaveOn convex_univ).convex_ge _ ⟨mem_univ _, hx₁.2 y hy⟩ ⟨mem_univ _, hx₂.2 y hy⟩ ha hb hab).2⟩ protected theorem isExtreme (hAB : IsExposed 𝕜 A B) : IsExtreme 𝕜 A B := by refine ⟨hAB.subset, fun x₁ hx₁A x₂ hx₂A x hxB hx => ?_⟩ obtain ⟨l, rfl⟩ := hAB ⟨x, hxB⟩ have hl : ConvexOn 𝕜 univ l := l.toLinearMap.convexOn convex_univ have hlx₁ := hxB.2 x₁ hx₁A have hlx₂ := hxB.2 x₂ hx₂A refine ⟨⟨hx₁A, fun y hy => ?_⟩, ⟨hx₂A, fun y hy => ?_⟩⟩ · rw [hlx₁.antisymm (hl.le_left_of_right_le (mem_univ _) (mem_univ _) hx hlx₂)] exact hxB.2 y hy · rw [hlx₂.antisymm (hl.le_right_of_left_le (mem_univ _) (mem_univ _) hx hlx₁)] exact hxB.2 y hy end IsExposed theorem exposedPoints_subset_extremePoints : A.exposedPoints 𝕜 ⊆ A.extremePoints 𝕜 := fun _ hx => (mem_exposedPoints_iff_exposed_singleton.1 hx).isExtreme.mem_extremePoints end LinearOrderedRing
Analysis\Convex\Extrema.lean
/- Copyright (c) 2020 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Convex.Function import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.MetricSpace.Pseudo.Lemmas import Mathlib.Topology.Order.LocalExtr /-! # Minima and maxima of convex functions We show that if a function `f : E → β` is convex, then a local minimum is also a global minimum, and likewise for concave functions. -/ variable {E β : Type*} [AddCommGroup E] [TopologicalSpace E] [Module ℝ E] [TopologicalAddGroup E] [ContinuousSMul ℝ E] [OrderedAddCommGroup β] [Module ℝ β] [OrderedSMul ℝ β] {s : Set E} open Set Filter Function open scoped Classical open Topology /-- Helper lemma for the more general case: `IsMinOn.of_isLocalMinOn_of_convexOn`. -/ theorem IsMinOn.of_isLocalMinOn_of_convexOn_Icc {f : ℝ → β} {a b : ℝ} (a_lt_b : a < b) (h_local_min : IsLocalMinOn f (Icc a b) a) (h_conv : ConvexOn ℝ (Icc a b) f) : IsMinOn f (Icc a b) a := by rintro c hc dsimp only [mem_setOf_eq] rw [IsLocalMinOn, nhdsWithin_Icc_eq_nhdsWithin_Ici a_lt_b] at h_local_min rcases hc.1.eq_or_lt with (rfl | a_lt_c) · exact le_rfl have H₁ : ∀ᶠ y in 𝓝[>] a, f a ≤ f y := h_local_min.filter_mono (nhdsWithin_mono _ Ioi_subset_Ici_self) have H₂ : ∀ᶠ y in 𝓝[>] a, y ∈ Ioc a c := Ioc_mem_nhdsWithin_Ioi (left_mem_Ico.2 a_lt_c) rcases (H₁.and H₂).exists with ⟨y, hfy, hy_ac⟩ rcases (Convex.mem_Ioc a_lt_c).mp hy_ac with ⟨ya, yc, ya₀, yc₀, yac, rfl⟩ suffices ya • f a + yc • f a ≤ ya • f a + yc • f c from (smul_le_smul_iff_of_pos_left yc₀).1 (le_of_add_le_add_left this) calc ya • f a + yc • f a = f a := by rw [← add_smul, yac, one_smul] _ ≤ f (ya * a + yc * c) := hfy _ ≤ ya • f a + yc • f c := h_conv.2 (left_mem_Icc.2 a_lt_b.le) hc ya₀ yc₀.le yac /-- A local minimum of a convex function is a global minimum, restricted to a set `s`. -/ theorem IsMinOn.of_isLocalMinOn_of_convexOn {f : E → β} {a : E} (a_in_s : a ∈ s) (h_localmin : IsLocalMinOn f s a) (h_conv : ConvexOn ℝ s f) : IsMinOn f s a := by intro x x_in_s let g : ℝ →ᵃ[ℝ] E := AffineMap.lineMap a x have hg0 : g 0 = a := AffineMap.lineMap_apply_zero a x have hg1 : g 1 = x := AffineMap.lineMap_apply_one a x have hgc : Continuous g := AffineMap.lineMap_continuous have h_maps : MapsTo g (Icc 0 1) s := by simpa only [g, mapsTo', ← segment_eq_image_lineMap] using h_conv.1.segment_subset a_in_s x_in_s have fg_local_min_on : IsLocalMinOn (f ∘ g) (Icc 0 1) 0 := by rw [← hg0] at h_localmin exact h_localmin.comp_continuousOn h_maps hgc.continuousOn (left_mem_Icc.2 zero_le_one) have fg_min_on : IsMinOn (f ∘ g) (Icc 0 1 : Set ℝ) 0 := by refine IsMinOn.of_isLocalMinOn_of_convexOn_Icc one_pos fg_local_min_on ?_ exact (h_conv.comp_affineMap g).subset h_maps (convex_Icc 0 1) simpa only [hg0, hg1, comp_apply, mem_setOf_eq] using fg_min_on (right_mem_Icc.2 zero_le_one) /-- A local maximum of a concave function is a global maximum, restricted to a set `s`. -/ theorem IsMaxOn.of_isLocalMaxOn_of_concaveOn {f : E → β} {a : E} (a_in_s : a ∈ s) (h_localmax : IsLocalMaxOn f s a) (h_conc : ConcaveOn ℝ s f) : IsMaxOn f s a := IsMinOn.of_isLocalMinOn_of_convexOn (β := βᵒᵈ) a_in_s h_localmax h_conc /-- A local minimum of a convex function is a global minimum. -/ theorem IsMinOn.of_isLocalMin_of_convex_univ {f : E → β} {a : E} (h_local_min : IsLocalMin f a) (h_conv : ConvexOn ℝ univ f) : ∀ x, f a ≤ f x := fun x => (IsMinOn.of_isLocalMinOn_of_convexOn (mem_univ a) (h_local_min.on univ) h_conv) (mem_univ x) /-- A local maximum of a concave function is a global maximum. -/ theorem IsMaxOn.of_isLocalMax_of_convex_univ {f : E → β} {a : E} (h_local_max : IsLocalMax f a) (h_conc : ConcaveOn ℝ univ f) : ∀ x, f x ≤ f a := IsMinOn.of_isLocalMin_of_convex_univ (β := βᵒᵈ) h_local_max h_conc
Analysis\Convex\Extreme.lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Hull /-! # Extreme sets This file defines extreme sets and extreme points for sets in a module. An extreme set of `A` is a subset of `A` that is as far as it can get in any outward direction: If point `x` is in it and point `y ∈ A`, then the line passing through `x` and `y` leaves `A` at `x`. This is an analytic notion of "being on the side of". It is weaker than being exposed (see `IsExposed.isExtreme`). ## Main declarations * `IsExtreme 𝕜 A B`: States that `B` is an extreme set of `A` (in the literature, `A` is often implicit). * `Set.extremePoints 𝕜 A`: Set of extreme points of `A` (corresponding to extreme singletons). * `Convex.mem_extremePoints_iff_convex_diff`: A useful equivalent condition to being an extreme point: `x` is an extreme point iff `A \ {x}` is convex. ## Implementation notes The exact definition of extremeness has been carefully chosen so as to make as many lemmas unconditional (in particular, the Krein-Milman theorem doesn't need the set to be convex!). In practice, `A` is often assumed to be a convex set. ## References See chapter 8 of [Barry Simon, *Convexity*][simon2011] ## TODO Prove lemmas relating extreme sets and points to the intrinsic frontier. -/ open Function Set open scoped Classical open Affine variable {𝕜 E F ι : Type*} {π : ι → Type*} section SMul variable (𝕜) [OrderedSemiring 𝕜] [AddCommMonoid E] [SMul 𝕜 E] /-- A set `B` is an extreme subset of `A` if `B ⊆ A` and all points of `B` only belong to open segments whose ends are in `B`. -/ def IsExtreme (A B : Set E) : Prop := B ⊆ A ∧ ∀ ⦃x₁⦄, x₁ ∈ A → ∀ ⦃x₂⦄, x₂ ∈ A → ∀ ⦃x⦄, x ∈ B → x ∈ openSegment 𝕜 x₁ x₂ → x₁ ∈ B ∧ x₂ ∈ B /-- A point `x` is an extreme point of a set `A` if `x` belongs to no open segment with ends in `A`, except for the obvious `openSegment x x`. -/ def Set.extremePoints (A : Set E) : Set E := { x ∈ A | ∀ ⦃x₁⦄, x₁ ∈ A → ∀ ⦃x₂⦄, x₂ ∈ A → x ∈ openSegment 𝕜 x₁ x₂ → x₁ = x ∧ x₂ = x } @[refl] protected theorem IsExtreme.refl (A : Set E) : IsExtreme 𝕜 A A := ⟨Subset.rfl, fun _ hx₁A _ hx₂A _ _ _ ↦ ⟨hx₁A, hx₂A⟩⟩ variable {𝕜} {A B C : Set E} {x : E} protected theorem IsExtreme.rfl : IsExtreme 𝕜 A A := IsExtreme.refl 𝕜 A @[trans] protected theorem IsExtreme.trans (hAB : IsExtreme 𝕜 A B) (hBC : IsExtreme 𝕜 B C) : IsExtreme 𝕜 A C := by refine ⟨Subset.trans hBC.1 hAB.1, fun x₁ hx₁A x₂ hx₂A x hxC hx ↦ ?_⟩ obtain ⟨hx₁B, hx₂B⟩ := hAB.2 hx₁A hx₂A (hBC.1 hxC) hx exact hBC.2 hx₁B hx₂B hxC hx protected theorem IsExtreme.antisymm : AntiSymmetric (IsExtreme 𝕜 : Set E → Set E → Prop) := fun _ _ hAB hBA ↦ Subset.antisymm hBA.1 hAB.1 instance : IsPartialOrder (Set E) (IsExtreme 𝕜) where refl := IsExtreme.refl 𝕜 trans _ _ _ := IsExtreme.trans antisymm := IsExtreme.antisymm theorem IsExtreme.inter (hAB : IsExtreme 𝕜 A B) (hAC : IsExtreme 𝕜 A C) : IsExtreme 𝕜 A (B ∩ C) := by use Subset.trans inter_subset_left hAB.1 rintro x₁ hx₁A x₂ hx₂A x ⟨hxB, hxC⟩ hx obtain ⟨hx₁B, hx₂B⟩ := hAB.2 hx₁A hx₂A hxB hx obtain ⟨hx₁C, hx₂C⟩ := hAC.2 hx₁A hx₂A hxC hx exact ⟨⟨hx₁B, hx₁C⟩, hx₂B, hx₂C⟩ protected theorem IsExtreme.mono (hAC : IsExtreme 𝕜 A C) (hBA : B ⊆ A) (hCB : C ⊆ B) : IsExtreme 𝕜 B C := ⟨hCB, fun _ hx₁B _ hx₂B _ hxC hx ↦ hAC.2 (hBA hx₁B) (hBA hx₂B) hxC hx⟩ theorem isExtreme_iInter {ι : Sort*} [Nonempty ι] {F : ι → Set E} (hAF : ∀ i : ι, IsExtreme 𝕜 A (F i)) : IsExtreme 𝕜 A (⋂ i : ι, F i) := by obtain i := Classical.arbitrary ι refine ⟨iInter_subset_of_subset i (hAF i).1, fun x₁ hx₁A x₂ hx₂A x hxF hx ↦ ?_⟩ simp_rw [mem_iInter] at hxF ⊢ have h := fun i ↦ (hAF i).2 hx₁A hx₂A (hxF i) hx exact ⟨fun i ↦ (h i).1, fun i ↦ (h i).2⟩ theorem isExtreme_biInter {F : Set (Set E)} (hF : F.Nonempty) (hA : ∀ B ∈ F, IsExtreme 𝕜 A B) : IsExtreme 𝕜 A (⋂ B ∈ F, B) := by haveI := hF.to_subtype simpa only [iInter_subtype] using isExtreme_iInter fun i : F ↦ hA _ i.2 theorem isExtreme_sInter {F : Set (Set E)} (hF : F.Nonempty) (hAF : ∀ B ∈ F, IsExtreme 𝕜 A B) : IsExtreme 𝕜 A (⋂₀ F) := by simpa [sInter_eq_biInter] using isExtreme_biInter hF hAF theorem mem_extremePoints : x ∈ A.extremePoints 𝕜 ↔ x ∈ A ∧ ∀ᵉ (x₁ ∈ A) (x₂ ∈ A), x ∈ openSegment 𝕜 x₁ x₂ → x₁ = x ∧ x₂ = x := Iff.rfl /-- x is an extreme point to A iff {x} is an extreme set of A. -/ @[simp] lemma isExtreme_singleton : IsExtreme 𝕜 A {x} ↔ x ∈ A.extremePoints 𝕜 := by refine ⟨fun hx ↦ ⟨singleton_subset_iff.1 hx.1, fun x₁ hx₁ x₂ hx₂ ↦ hx.2 hx₁ hx₂ rfl⟩, ?_⟩ rintro ⟨hxA, hAx⟩ use singleton_subset_iff.2 hxA rintro x₁ hx₁A x₂ hx₂A y (rfl : y = x) exact hAx hx₁A hx₂A alias ⟨IsExtreme.mem_extremePoints, _⟩ := isExtreme_singleton theorem extremePoints_subset : A.extremePoints 𝕜 ⊆ A := fun _ hx ↦ hx.1 @[simp] theorem extremePoints_empty : (∅ : Set E).extremePoints 𝕜 = ∅ := subset_empty_iff.1 extremePoints_subset @[simp] theorem extremePoints_singleton : ({x} : Set E).extremePoints 𝕜 = {x} := extremePoints_subset.antisymm <| singleton_subset_iff.2 ⟨mem_singleton x, fun _ hx₁ _ hx₂ _ ↦ ⟨hx₁, hx₂⟩⟩ theorem inter_extremePoints_subset_extremePoints_of_subset (hBA : B ⊆ A) : B ∩ A.extremePoints 𝕜 ⊆ B.extremePoints 𝕜 := fun _ ⟨hxB, hxA⟩ ↦ ⟨hxB, fun _ hx₁ _ hx₂ hx ↦ hxA.2 (hBA hx₁) (hBA hx₂) hx⟩ theorem IsExtreme.extremePoints_subset_extremePoints (hAB : IsExtreme 𝕜 A B) : B.extremePoints 𝕜 ⊆ A.extremePoints 𝕜 := fun _ ↦ by simpa only [← isExtreme_singleton] using hAB.trans theorem IsExtreme.extremePoints_eq (hAB : IsExtreme 𝕜 A B) : B.extremePoints 𝕜 = B ∩ A.extremePoints 𝕜 := Subset.antisymm (fun _ hx ↦ ⟨hx.1, hAB.extremePoints_subset_extremePoints hx⟩) (inter_extremePoints_subset_extremePoints_of_subset hAB.1) end SMul section OrderedSemiring variable [OrderedSemiring 𝕜] [AddCommGroup E] [AddCommGroup F] [∀ i, AddCommGroup (π i)] [Module 𝕜 E] [Module 𝕜 F] [∀ i, Module 𝕜 (π i)] {A B : Set E} {x : E} theorem IsExtreme.convex_diff (hA : Convex 𝕜 A) (hAB : IsExtreme 𝕜 A B) : Convex 𝕜 (A \ B) := convex_iff_openSegment_subset.2 fun _ ⟨hx₁A, hx₁B⟩ _ ⟨hx₂A, _⟩ _ hx ↦ ⟨hA.openSegment_subset hx₁A hx₂A hx, fun hxB ↦ hx₁B (hAB.2 hx₁A hx₂A hxB hx).1⟩ @[simp] theorem extremePoints_prod (s : Set E) (t : Set F) : (s ×ˢ t).extremePoints 𝕜 = s.extremePoints 𝕜 ×ˢ t.extremePoints 𝕜 := by ext refine (and_congr_right fun hx ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩).trans and_and_and_comm constructor · rintro x₁ hx₁ x₂ hx₂ hx_fst refine (h (mk_mem_prod hx₁ hx.2) (mk_mem_prod hx₂ hx.2) ?_).imp (congr_arg Prod.fst) (congr_arg Prod.fst) rw [← Prod.image_mk_openSegment_left] exact ⟨_, hx_fst, rfl⟩ · rintro x₁ hx₁ x₂ hx₂ hx_snd refine (h (mk_mem_prod hx.1 hx₁) (mk_mem_prod hx.1 hx₂) ?_).imp (congr_arg Prod.snd) (congr_arg Prod.snd) rw [← Prod.image_mk_openSegment_right] exact ⟨_, hx_snd, rfl⟩ · rintro x₁ hx₁ x₂ hx₂ ⟨a, b, ha, hb, hab, hx'⟩ simp_rw [Prod.ext_iff] exact and_and_and_comm.1 ⟨h.1 hx₁.1 hx₂.1 ⟨a, b, ha, hb, hab, congr_arg Prod.fst hx'⟩, h.2 hx₁.2 hx₂.2 ⟨a, b, ha, hb, hab, congr_arg Prod.snd hx'⟩⟩ @[simp] theorem extremePoints_pi (s : ∀ i, Set (π i)) : (univ.pi s).extremePoints 𝕜 = univ.pi fun i ↦ (s i).extremePoints 𝕜 := by ext x simp only [mem_extremePoints, mem_pi, mem_univ, true_imp_iff, @forall_and ι] refine and_congr_right fun hx ↦ ⟨fun h i ↦ ?_, fun h ↦ ?_⟩ · rintro x₁ hx₁ x₂ hx₂ hi refine (h (update x i x₁) ?_ (update x i x₂) ?_ ?_).imp (fun h₁ ↦ by rw [← h₁, update_same]) fun h₂ ↦ by rw [← h₂, update_same] iterate 2 rintro j obtain rfl | hji := eq_or_ne j i · rwa [update_same] · rw [update_noteq hji] exact hx _ rw [← Pi.image_update_openSegment] exact ⟨_, hi, update_eq_self _ _⟩ · rintro x₁ hx₁ x₂ hx₂ ⟨a, b, ha, hb, hab, hx'⟩ simp_rw [funext_iff, ← forall_and] exact fun i ↦ h _ _ (hx₁ _) _ (hx₂ _) ⟨a, b, ha, hb, hab, congr_fun hx' _⟩ end OrderedSemiring section OrderedRing variable {L : Type*} [OrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] [AddCommGroup F] [Module 𝕜 F] [EquivLike L E F] [LinearEquivClass L 𝕜 E F] lemma image_extremePoints (f : L) (s : Set E) : f '' extremePoints 𝕜 s = extremePoints 𝕜 (f '' s) := by ext b obtain ⟨a, rfl⟩ := EquivLike.surjective f b have : ∀ x y, f '' openSegment 𝕜 x y = openSegment 𝕜 (f x) (f y) := image_openSegment _ (LinearMapClass.linearMap f).toAffineMap simp only [mem_extremePoints, (EquivLike.surjective f).forall, (EquivLike.injective f).mem_set_image, (EquivLike.injective f).eq_iff, ← this] end OrderedRing section LinearOrderedRing variable [LinearOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] {A B : Set E} {x : E} /-- A useful restatement using `segment`: `x` is an extreme point iff the only (closed) segments that contain it are those with `x` as one of their endpoints. -/ theorem mem_extremePoints_iff_forall_segment : x ∈ A.extremePoints 𝕜 ↔ x ∈ A ∧ ∀ᵉ (x₁ ∈ A) (x₂ ∈ A), x ∈ segment 𝕜 x₁ x₂ → x₁ = x ∨ x₂ = x := by refine and_congr_right fun hxA ↦ forall₄_congr fun x₁ h₁ x₂ h₂ ↦ ?_ constructor · rw [← insert_endpoints_openSegment] rintro H (rfl | rfl | hx) exacts [Or.inl rfl, Or.inr rfl, Or.inl <| (H hx).1] · intro H hx rcases H (openSegment_subset_segment _ _ _ hx) with (rfl | rfl) exacts [⟨rfl, (left_mem_openSegment_iff.1 hx).symm⟩, ⟨right_mem_openSegment_iff.1 hx, rfl⟩] theorem Convex.mem_extremePoints_iff_convex_diff (hA : Convex 𝕜 A) : x ∈ A.extremePoints 𝕜 ↔ x ∈ A ∧ Convex 𝕜 (A \ {x}) := by use fun hx ↦ ⟨hx.1, (isExtreme_singleton.2 hx).convex_diff hA⟩ rintro ⟨hxA, hAx⟩ refine mem_extremePoints_iff_forall_segment.2 ⟨hxA, fun x₁ hx₁ x₂ hx₂ hx ↦ ?_⟩ rw [convex_iff_segment_subset] at hAx by_contra! h exact (hAx ⟨hx₁, fun hx₁ ↦ h.1 (mem_singleton_iff.2 hx₁)⟩ ⟨hx₂, fun hx₂ ↦ h.2 (mem_singleton_iff.2 hx₂)⟩ hx).2 rfl theorem Convex.mem_extremePoints_iff_mem_diff_convexHull_diff (hA : Convex 𝕜 A) : x ∈ A.extremePoints 𝕜 ↔ x ∈ A \ convexHull 𝕜 (A \ {x}) := by rw [hA.mem_extremePoints_iff_convex_diff, hA.convex_remove_iff_not_mem_convexHull_remove, mem_diff] theorem extremePoints_convexHull_subset : (convexHull 𝕜 A).extremePoints 𝕜 ⊆ A := by rintro x hx rw [(convex_convexHull 𝕜 _).mem_extremePoints_iff_convex_diff] at hx by_contra h exact (convexHull_min (subset_diff.2 ⟨subset_convexHull 𝕜 _, disjoint_singleton_right.2 h⟩) hx.2 hx.1).2 rfl end LinearOrderedRing
Analysis\Convex\Function.lean
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, François Dupuis -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Order.Filter.Extr import Mathlib.Tactic.NormNum /-! # Convex and concave functions This file defines convex and concave functions in vector spaces and proves the finite Jensen inequality. The integral version can be found in `Analysis.Convex.Integral`. A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`. Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set. ## Main declarations * `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`. * `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`. * `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`. * `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`. -/ open scoped Classical open LinearMap Set Convex Pointwise variable {𝕜 E F α β ι : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section OrderedAddCommMonoid variable [OrderedAddCommMonoid α] [OrderedAddCommMonoid β] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α} /-- Convexity of functions -/ def ConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y /-- Concavity of functions -/ def ConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) /-- Strict convexity of functions -/ def StrictConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y /-- Strict concavity of functions -/ def StrictConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y) variable {𝕜 s f} open OrderDual (toDual ofDual) theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ section congr variable {g : E → β} theorem ConvexOn.congr (hf : ConvexOn 𝕜 s f) (hfg : EqOn f g s) : ConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ theorem ConcaveOn.congr (hf : ConcaveOn 𝕜 s f) (hfg : EqOn f g s) : ConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ theorem StrictConvexOn.congr (hf : StrictConvexOn 𝕜 s f) (hfg : EqOn f g s) : StrictConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ theorem StrictConcaveOn.congr (hf : StrictConcaveOn 𝕜 s f) (hfg : EqOn f g s) : StrictConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ end congr theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <| hf.2 hx hy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩ theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) (mem_image_of_mem f <| hf.1 hx hy ha hb hab) <| hf.2 hx hy ha hb hab⟩ theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩ theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab⟩ theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' end SMul section DistribMulAction variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) := add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm] ⟩ theorem ConcaveOn.add (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f + g) := hf.dual.add hg end DistribMulAction section Module variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f : E → β} theorem convexOn_const (c : β) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s fun _ : E => c := ⟨hs, fun _ _ _ _ _ _ _ _ hab => (Convex.combo_self hab c).ge⟩ theorem concaveOn_const (c : β) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s fun _ => c := convexOn_const (β := βᵒᵈ) _ hs theorem ConvexOn.add_const (hf : ConvexOn 𝕜 s f) (b : β) : ConvexOn 𝕜 s (f + fun _ => b) := hf.add (convexOn_const _ hf.1) theorem ConcaveOn.add_const (hf : ConcaveOn 𝕜 s f) (b : β) : ConcaveOn 𝕜 s (f + fun _ => b) := hf.add (concaveOn_const _ hf.1) theorem convexOn_of_convex_epigraph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 }) : ConvexOn 𝕜 s f := ⟨fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).1, fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).2⟩ theorem concaveOn_of_convex_hypograph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 }) : ConcaveOn 𝕜 s f := convexOn_of_convex_epigraph (β := βᵒᵈ) h end Module section OrderedSMul variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_le (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha hb hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2 · exact hy.2 _ = r := Convex.combo_self hab r ⟩ theorem ConcaveOn.convex_ge (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := hf.dual.convex_le r theorem ConvexOn.convex_epigraph (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := by rintro ⟨x, r⟩ ⟨hx, hr⟩ ⟨y, t⟩ ⟨hy, ht⟩ a b ha hb hab refine ⟨hf.1 hx hy ha hb hab, ?_⟩ calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • r + b • t := by gcongr theorem ConcaveOn.convex_hypograph (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := hf.dual.convex_epigraph theorem convexOn_iff_convex_epigraph : ConvexOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := ⟨ConvexOn.convex_epigraph, convexOn_of_convex_epigraph⟩ theorem concaveOn_iff_convex_hypograph : ConcaveOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := convexOn_iff_convex_epigraph (β := βᵒᵈ) end OrderedSMul section Module variable [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β} /-- Right translation preserves convexity. -/ theorem ConvexOn.translate_right (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := ⟨hf.1.translate_preimage_right _, fun x hx y hy a b ha hb hab => calc f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab] _ ≤ a • f (c + x) + b • f (c + y) := hf.2 hx hy ha hb hab ⟩ /-- Right translation preserves concavity. -/ theorem ConcaveOn.translate_right (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := hf.dual.translate_right _ /-- Left translation preserves convexity. -/ theorem ConvexOn.translate_left (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm c] using hf.translate_right c /-- Left translation preserves concavity. -/ theorem ConcaveOn.translate_left (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := hf.dual.translate_left _ end Module section Module variable [Module 𝕜 E] [Module 𝕜 β] theorem convexOn_iff_forall_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by refine and_congr_right' ⟨fun h x hx y hy a b ha hb hab => h hx hy ha.le hb.le hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab subst b simp_rw [zero_smul, zero_add, one_smul, le_rfl] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab subst a simp_rw [zero_smul, add_zero, one_smul, le_rfl] exact h hx hy ha' hb' hab theorem concaveOn_iff_forall_pos {s : Set E} {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) := convexOn_iff_forall_pos (β := βᵒᵈ) theorem convexOn_iff_pairwise_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by rw [convexOn_iff_forall_pos] refine and_congr_right' ⟨fun h x hx y hy _ a b ha hb hab => h hx hy ha hb hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | hxy := eq_or_ne x y · rw [Convex.combo_self hab, Convex.combo_self hab] exact h hx hy hxy ha hb hab theorem concaveOn_iff_pairwise_pos {s : Set E} {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) := convexOn_iff_pairwise_pos (β := βᵒᵈ) /-- A linear map is convex. -/ theorem LinearMap.convexOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩ /-- A linear map is concave. -/ theorem LinearMap.concaveOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩ theorem StrictConvexOn.convexOn {s : Set E} {f : E → β} (hf : StrictConvexOn 𝕜 s f) : ConvexOn 𝕜 s f := convexOn_iff_pairwise_pos.mpr ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hf.2 hx hy hxy ha hb hab).le⟩ theorem StrictConcaveOn.concaveOn {s : Set E} {f : E → β} (hf : StrictConcaveOn 𝕜 s f) : ConcaveOn 𝕜 s f := hf.dual.convexOn section OrderedSMul variable [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem StrictConvexOn.convex_lt (hf : StrictConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := convex_iff_pairwise_pos.2 fun x hx y hy hxy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha.le hb.le hab, calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx.1 hy.1 hxy ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2.le · exact hy.2.le _ = r := Convex.combo_self hab r ⟩ theorem StrictConcaveOn.convex_gt (hf : StrictConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r end OrderedSMul section LinearOrder variable [LinearOrder E] {s : Set E} {f : E → β} /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is convex, it suffices to verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.convexOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y) : ConvexOn 𝕜 s f := by refine convexOn_iff_pairwise_pos.2 ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩ -- Porting note: without clearing the stray variables, `wlog` gives a bad term. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495 clear! α F ι wlog h : x < y · rw [add_comm (a • x), add_comm (a • f x)] rw [add_comm] at hab exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h) exact hf hx hy h ha hb hab /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is concave it suffices to verify the inequality `a • f x + b • f y ≤ f (a • x + b • y)` for `x < y` and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/ theorem LinearOrder.concaveOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y)) : ConcaveOn 𝕜 s f := LinearOrder.convexOn_of_lt (β := βᵒᵈ) hs hf /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is strictly convex, it suffices to verify the inequality `f (a • x + b • y) < a • f x + b • f y` for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.strictConvexOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y) : StrictConvexOn 𝕜 s f := by refine ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩ -- Porting note: without clearing the stray variables, `wlog` gives a bad term. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/wlog.20.2316495 clear! α F ι wlog h : x < y · rw [add_comm (a • x), add_comm (a • f x)] rw [add_comm] at hab exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h) exact hf hx hy h ha hb hab /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is strictly concave it suffices to verify the inequality `a • f x + b • f y < f (a • x + b • y)` for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.strictConcaveOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y)) : StrictConcaveOn 𝕜 s f := LinearOrder.strictConvexOn_of_lt (β := βᵒᵈ) hs hf end LinearOrder end Module section Module variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β] /-- If `g` is convex on `s`, so is `(f ∘ g)` on `f ⁻¹' s` for a linear `f`. -/ theorem ConvexOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConvexOn 𝕜 s f) (g : E →ₗ[𝕜] F) : ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) := ⟨hf.1.linear_preimage _, fun x hx y hy a b ha hb hab => calc f (g (a • x + b • y)) = f (a • g x + b • g y) := by rw [g.map_add, g.map_smul, g.map_smul] _ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩ /-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/ theorem ConcaveOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConcaveOn 𝕜 s f) (g : E →ₗ[𝕜] F) : ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) := hf.dual.comp_linearMap g end Module end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid β] section DistribMulAction variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem StrictConvexOn.add_convexOn (hf : StrictConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) := add_lt_add_of_lt_of_le (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy ha.le hb.le hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩ theorem ConvexOn.add_strictConvexOn (hf : ConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := add_comm g f ▸ hg.add_convexOn hf theorem StrictConvexOn.add (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) := add_lt_add (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy hxy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩ theorem StrictConcaveOn.add_concaveOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add_convexOn hg.dual theorem ConcaveOn.add_strictConcaveOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add_strictConvexOn hg.dual theorem StrictConcaveOn.add (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add hg theorem StrictConvexOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ] [Module 𝕜 γ] (hf : StrictConvexOn 𝕜 s f) (b : γ) : StrictConvexOn 𝕜 s (f + fun _ => b) := hf.add_convexOn (convexOn_const _ hf.1) theorem StrictConcaveOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ] [Module 𝕜 γ] (hf : StrictConcaveOn 𝕜 s f) (b : γ) : StrictConcaveOn 𝕜 s (f + fun _ => b) := hf.add_concaveOn (concaveOn_const _ hf.1) end DistribMulAction section Module variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_lt (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := convex_iff_forall_pos.2 fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha.le hb.le hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha.le hb.le hab _ < a • r + b • r := (add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx.2 ha) (smul_le_smul_of_nonneg_left hy.2.le hb.le)) _ = r := Convex.combo_self hab _⟩ theorem ConcaveOn.convex_gt (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r theorem ConvexOn.openSegment_subset_strict_epigraph (hf : ConvexOn 𝕜 s f) (p q : E × β) (hp : p.1 ∈ s ∧ f p.1 < p.2) (hq : q.1 ∈ s ∧ f q.1 ≤ q.2) : openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨hf.1 hp.1 hq.1 ha.le hb.le hab, ?_⟩ calc f (a • p.1 + b • q.1) ≤ a • f p.1 + b • f q.1 := hf.2 hp.1 hq.1 ha.le hb.le hab _ < a • p.2 + b • q.2 := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hp.2 ha) (smul_le_smul_of_nonneg_left hq.2 hb.le) theorem ConcaveOn.openSegment_subset_strict_hypograph (hf : ConcaveOn 𝕜 s f) (p q : E × β) (hp : p.1 ∈ s ∧ p.2 < f p.1) (hq : q.1 ∈ s ∧ q.2 ≤ f q.1) : openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } := hf.dual.openSegment_subset_strict_epigraph p q hp hq theorem ConvexOn.convex_strict_epigraph (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := convex_iff_openSegment_subset.mpr fun p hp q hq => hf.openSegment_subset_strict_epigraph p q hp ⟨hq.1, hq.2.le⟩ theorem ConcaveOn.convex_strict_hypograph (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } := hf.dual.convex_strict_epigraph end Module end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid β] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} /-- The pointwise maximum of convex functions is convex. -/ theorem ConvexOn.sup (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f ⊔ g) := by refine ⟨hf.left, fun x hx y hy a b ha hb hab => sup_le ?_ ?_⟩ · calc f (a • x + b • y) ≤ a • f x + b • f y := hf.right hx hy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left · calc g (a • x + b • y) ≤ a • g x + b • g y := hg.right hx hy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right /-- The pointwise minimum of concave functions is concave. -/ theorem ConcaveOn.inf (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg /-- The pointwise maximum of strictly convex functions is strictly convex. -/ theorem StrictConvexOn.sup (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f ⊔ g) := ⟨hf.left, fun x hx y hy hxy a b ha hb hab => max_lt (calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left) (calc g (a • x + b • y) < a • g x + b • g y := hg.2 hx hy hxy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right)⟩ /-- The pointwise minimum of strictly concave functions is strictly concave. -/ theorem StrictConcaveOn.inf (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem ConvexOn.le_on_segment' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : f (a • x + b • y) ≤ max (f x) (f y) := calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by gcongr · apply le_max_left · apply le_max_right _ = max (f x) (f y) := Convex.combo_self hab _ /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem ConcaveOn.ge_on_segment' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min (f x) (f y) ≤ f (a • x + b • y) := hf.dual.le_on_segment' hx hy ha hb hab /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem ConvexOn.le_on_segment (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[𝕜] y]) : f z ≤ max (f x) (f y) := let ⟨_, _, ha, hb, hab, hz⟩ := hz hz ▸ hf.le_on_segment' hx hy ha hb hab /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem ConcaveOn.ge_on_segment (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[𝕜] y]) : min (f x) (f y) ≤ f z := hf.dual.le_on_segment hx hy hz /-- A strictly convex function on an open segment is strictly upper-bounded by the max of its endpoints. -/ theorem StrictConvexOn.lt_on_open_segment' (hf : StrictConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : f (a • x + b • y) < max (f x) (f y) := calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab _ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by gcongr · apply le_max_left · apply le_max_right _ = max (f x) (f y) := Convex.combo_self hab _ /-- A strictly concave function on an open segment is strictly lower-bounded by the min of its endpoints. -/ theorem StrictConcaveOn.lt_on_open_segment' (hf : StrictConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : min (f x) (f y) < f (a • x + b • y) := hf.dual.lt_on_open_segment' hx hy hxy ha hb hab /-- A strictly convex function on an open segment is strictly upper-bounded by the max of its endpoints. -/ theorem StrictConvexOn.lt_on_openSegment (hf : StrictConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : f z < max (f x) (f y) := let ⟨_, _, ha, hb, hab, hz⟩ := hz hz ▸ hf.lt_on_open_segment' hx hy hxy ha hb hab /-- A strictly concave function on an open segment is strictly lower-bounded by the min of its endpoints. -/ theorem StrictConcaveOn.lt_on_openSegment (hf : StrictConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : min (f x) (f y) < f z := hf.dual.lt_on_openSegment hx hy hxy hz end LinearOrderedAddCommMonoid section LinearOrderedCancelAddCommMonoid variable [LinearOrderedCancelAddCommMonoid β] section OrderedSMul variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.le_left_of_right_le' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f y ≤ f (a • x + b • y)) : f (a • x + b • y) ≤ f x := le_of_not_lt fun h ↦ lt_irrefl (f (a • x + b • y)) <| calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb hab _ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left h ha) (smul_le_smul_of_nonneg_left hfy hb) _ = f (a • x + b • y) := Convex.combo_self hab _ theorem ConcaveOn.left_le_of_le_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f (a • x + b • y) ≤ f y) : f x ≤ f (a • x + b • y) := hf.dual.le_left_of_right_le' hx hy ha hb hab hfy theorem ConvexOn.le_right_of_left_le' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x ≤ f (a • x + b • y)) : f (a • x + b • y) ≤ f y := by rw [add_comm] at hab hfx ⊢ exact hf.le_left_of_right_le' hy hx hb ha hab hfx theorem ConcaveOn.right_le_of_le_left' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) ≤ f x) : f y ≤ f (a • x + b • y) := hf.dual.le_right_of_left_le' hx hy ha hb hab hfx theorem ConvexOn.le_left_of_right_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f y ≤ f z) : f z ≤ f x := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.le_left_of_right_le' hx hy ha hb.le hab hyz theorem ConcaveOn.left_le_of_le_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f z ≤ f y) : f x ≤ f z := hf.dual.le_left_of_right_le hx hy hz hyz theorem ConvexOn.le_right_of_left_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f x ≤ f z) : f z ≤ f y := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.le_right_of_left_le' hx hy ha.le hb hab hxz theorem ConcaveOn.right_le_of_le_left (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f z ≤ f x) : f y ≤ f z := hf.dual.le_right_of_left_le hx hy hz hxz end OrderedSMul section Module variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} /- The following lemmas don't require `Module 𝕜 E` if you add the hypothesis `x ≠ y`. At the time of the writing, we decided the resulting lemmas wouldn't be useful. Feel free to reintroduce them. -/ theorem ConvexOn.lt_left_of_right_lt' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f y < f (a • x + b • y)) : f (a • x + b • y) < f x := not_le.1 fun h ↦ lt_irrefl (f (a • x + b • y)) <| calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb.le hab _ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_le_of_lt (smul_le_smul_of_nonneg_left h ha.le) (smul_lt_smul_of_pos_left hfy hb) _ = f (a • x + b • y) := Convex.combo_self hab _ theorem ConcaveOn.left_lt_of_lt_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f (a • x + b • y) < f y) : f x < f (a • x + b • y) := hf.dual.lt_left_of_right_lt' hx hy ha hb hab hfy theorem ConvexOn.lt_right_of_left_lt' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x < f (a • x + b • y)) : f (a • x + b • y) < f y := by rw [add_comm] at hab hfx ⊢ exact hf.lt_left_of_right_lt' hy hx hb ha hab hfx theorem ConcaveOn.lt_right_of_left_lt' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) < f x) : f y < f (a • x + b • y) := hf.dual.lt_right_of_left_lt' hx hy ha hb hab hfx theorem ConvexOn.lt_left_of_right_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f y < f z) : f z < f x := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.lt_left_of_right_lt' hx hy ha hb hab hyz theorem ConcaveOn.left_lt_of_lt_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f z < f y) : f x < f z := hf.dual.lt_left_of_right_lt hx hy hz hyz theorem ConvexOn.lt_right_of_left_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f x < f z) : f z < f y := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.lt_right_of_left_lt' hx hy ha hb hab hxz theorem ConcaveOn.lt_right_of_left_lt (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f z < f x) : f y < f z := hf.dual.lt_right_of_left_lt hx hy hz hxz end Module end LinearOrderedCancelAddCommMonoid section OrderedAddCommGroup variable [OrderedAddCommGroup β] [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f g : E → β} /-- A function `-f` is convex iff `f` is concave. -/ @[simp] theorem neg_convexOn_iff : ConvexOn 𝕜 s (-f) ↔ ConcaveOn 𝕜 s f := by constructor · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy a b ha hb hab => ?_⟩ simp? [neg_apply, neg_le, add_comm] at h says simp only [Pi.neg_apply, smul_neg, le_add_neg_iff_add_le, add_comm, add_neg_le_iff_le_add] at h exact h hx hy ha hb hab · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy a b ha hb hab => ?_⟩ rw [← neg_le_neg_iff] simp_rw [neg_add, Pi.neg_apply, smul_neg, neg_neg] exact h hx hy ha hb hab /-- A function `-f` is concave iff `f` is convex. -/ @[simp] theorem neg_concaveOn_iff : ConcaveOn 𝕜 s (-f) ↔ ConvexOn 𝕜 s f := by rw [← neg_convexOn_iff, neg_neg f] /-- A function `-f` is strictly convex iff `f` is strictly concave. -/ @[simp] theorem neg_strictConvexOn_iff : StrictConvexOn 𝕜 s (-f) ↔ StrictConcaveOn 𝕜 s f := by constructor · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy hxy a b ha hb hab => ?_⟩ simp only [ne_eq, Pi.neg_apply, smul_neg, lt_add_neg_iff_add_lt, add_comm, add_neg_lt_iff_lt_add] at h exact h hx hy hxy ha hb hab · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy hxy a b ha hb hab => ?_⟩ rw [← neg_lt_neg_iff] simp_rw [neg_add, Pi.neg_apply, smul_neg, neg_neg] exact h hx hy hxy ha hb hab /-- A function `-f` is strictly concave iff `f` is strictly convex. -/ @[simp] theorem neg_strictConcaveOn_iff : StrictConcaveOn 𝕜 s (-f) ↔ StrictConvexOn 𝕜 s f := by rw [← neg_strictConvexOn_iff, neg_neg f] alias ⟨_, ConcaveOn.neg⟩ := neg_convexOn_iff alias ⟨_, ConvexOn.neg⟩ := neg_concaveOn_iff alias ⟨_, StrictConcaveOn.neg⟩ := neg_strictConvexOn_iff alias ⟨_, StrictConvexOn.neg⟩ := neg_strictConcaveOn_iff theorem ConvexOn.sub (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem ConcaveOn.sub (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem StrictConvexOn.sub (hf : StrictConvexOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem StrictConcaveOn.sub (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem ConvexOn.sub_strictConcaveOn (hf : ConvexOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_strictConvexOn hg.neg theorem ConcaveOn.sub_strictConvexOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_strictConcaveOn hg.neg theorem StrictConvexOn.sub_concaveOn (hf : StrictConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : StrictConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_convexOn hg.neg theorem StrictConcaveOn.sub_convexOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_concaveOn hg.neg end OrderedAddCommGroup end AddCommMonoid section AddCancelCommMonoid variable [AddCancelCommMonoid E] [OrderedAddCommMonoid β] [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β} /-- Right translation preserves strict convexity. -/ theorem StrictConvexOn.translate_right (hf : StrictConvexOn 𝕜 s f) (c : E) : StrictConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := ⟨hf.1.translate_preimage_right _, fun x hx y hy hxy a b ha hb hab => calc f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab] _ < a • f (c + x) + b • f (c + y) := hf.2 hx hy ((add_right_injective c).ne hxy) ha hb hab⟩ /-- Right translation preserves strict concavity. -/ theorem StrictConcaveOn.translate_right (hf : StrictConcaveOn 𝕜 s f) (c : E) : StrictConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := hf.dual.translate_right _ /-- Left translation preserves strict convexity. -/ theorem StrictConvexOn.translate_left (hf : StrictConvexOn 𝕜 s f) (c : E) : StrictConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm] using hf.translate_right c /-- Left translation preserves strict concavity. -/ theorem StrictConcaveOn.translate_left (hf : StrictConcaveOn 𝕜 s f) (c : E) : StrictConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm] using hf.translate_right c end AddCancelCommMonoid end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] [AddCommMonoid E] section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] section Module variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.smul {c : 𝕜} (hc : 0 ≤ c) (hf : ConvexOn 𝕜 s f) : ConvexOn 𝕜 s fun x => c • f x := ⟨hf.1, fun x hx y hy a b ha hb hab => calc c • f (a • x + b • y) ≤ c • (a • f x + b • f y) := smul_le_smul_of_nonneg_left (hf.2 hx hy ha hb hab) hc _ = a • c • f x + b • c • f y := by rw [smul_add, smul_comm c, smul_comm c]⟩ theorem ConcaveOn.smul {c : 𝕜} (hc : 0 ≤ c) (hf : ConcaveOn 𝕜 s f) : ConcaveOn 𝕜 s fun x => c • f x := hf.dual.smul hc end Module end OrderedAddCommMonoid end OrderedCommSemiring section OrderedRing variable [LinearOrderedField 𝕜] [AddCommGroup E] [AddCommGroup F] section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] section Module variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β] /-- If a function is convex on `s`, it remains convex when precomposed by an affine map. -/ theorem ConvexOn.comp_affineMap {f : F → β} (g : E →ᵃ[𝕜] F) {s : Set F} (hf : ConvexOn 𝕜 s f) : ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) := ⟨hf.1.affine_preimage _, fun x hx y hy a b ha hb hab => calc (f ∘ g) (a • x + b • y) = f (g (a • x + b • y)) := rfl _ = f (a • g x + b • g y) := by rw [Convex.combo_affine_apply hab] _ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩ /-- If a function is concave on `s`, it remains concave when precomposed by an affine map. -/ theorem ConcaveOn.comp_affineMap {f : F → β} (g : E →ᵃ[𝕜] F) {s : Set F} (hf : ConcaveOn 𝕜 s f) : ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) := hf.dual.comp_affineMap g end Module end OrderedAddCommMonoid end OrderedRing section LinearOrderedField variable [LinearOrderedField 𝕜] [AddCommMonoid E] section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] section SMul variable [SMul 𝕜 E] [SMul 𝕜 β] {s : Set E} theorem convexOn_iff_div {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → f ((a / (a + b)) • x + (b / (a + b)) • y) ≤ (a / (a + b)) • f x + (b / (a + b)) • f y := and_congr Iff.rfl ⟨by intro h x hx y hy a b ha hb hab apply h hx hy (div_nonneg ha hab.le) (div_nonneg hb hab.le) rw [← add_div, div_self hab.ne'], by intro h x hx y hy a b ha hb hab simpa [hab, zero_lt_one] using h hx hy ha hb⟩ theorem concaveOn_iff_div {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • f x + (b / (a + b)) • f y ≤ f ((a / (a + b)) • x + (b / (a + b)) • y) := convexOn_iff_div (β := βᵒᵈ) theorem strictConvexOn_iff_div {f : E → β} : StrictConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → f ((a / (a + b)) • x + (b / (a + b)) • y) < (a / (a + b)) • f x + (b / (a + b)) • f y := and_congr Iff.rfl ⟨by intro h x hx y hy hxy a b ha hb have hab := add_pos ha hb apply h hx hy hxy (div_pos ha hab) (div_pos hb hab) rw [← add_div, div_self hab.ne'], by intro h x hx y hy hxy a b ha hb hab simpa [hab, zero_lt_one] using h hx hy hxy ha hb⟩ theorem strictConcaveOn_iff_div {f : E → β} : StrictConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → (a / (a + b)) • f x + (b / (a + b)) • f y < f ((a / (a + b)) • x + (b / (a + b)) • y) := strictConvexOn_iff_div (β := βᵒᵈ) end SMul end OrderedAddCommMonoid end LinearOrderedField section OrderIso variable [OrderedSemiring 𝕜] [OrderedAddCommMonoid α] [SMul 𝕜 α] [OrderedAddCommMonoid β] [SMul 𝕜 β] theorem OrderIso.strictConvexOn_symm (f : α ≃o β) (hf : StrictConcaveOn 𝕜 univ f) : StrictConvexOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ have hxy' : x' ≠ y' := by rw [← f.injective.ne_iff, ← hx'', ← hy'']; exact hxy simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.lt_iff_lt, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) hxy' ha hb hab theorem OrderIso.convexOn_symm (f : α ≃o β) (hf : ConcaveOn 𝕜 univ f) : ConvexOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.le_iff_le, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) ha hb hab theorem OrderIso.strictConcaveOn_symm (f : α ≃o β) (hf : StrictConvexOn 𝕜 univ f) : StrictConcaveOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ have hxy' : x' ≠ y' := by rw [← f.injective.ne_iff, ← hx'', ← hy'']; exact hxy simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.lt_iff_lt, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) hxy' ha hb hab theorem OrderIso.concaveOn_symm (f : α ≃o β) (hf : ConvexOn 𝕜 univ f) : ConcaveOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.le_iff_le, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) ha hb hab end OrderIso section LinearOrderedField variable [LinearOrderedField 𝕜] section OrderedAddCommMonoid variable [OrderedAddCommMonoid β] [AddCommMonoid E] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {f : E → β} {s : Set E} {x y : E} /-- A strictly convex function admits at most one global minimum. -/ lemma StrictConvexOn.eq_of_isMinOn (hf : StrictConvexOn 𝕜 s f) (hfx : IsMinOn f s x) (hfy : IsMinOn f s y) (hx : x ∈ s) (hy : y ∈ s) : x = y := by by_contra hxy let z := (2 : 𝕜)⁻¹ • x + (2 : 𝕜)⁻¹ • y have hz : z ∈ s := hf.1 hx hy (by norm_num) (by norm_num) <| by norm_num refine lt_irrefl (f z) ?_ calc f z < _ := hf.2 hx hy hxy (by norm_num) (by norm_num) <| by norm_num _ ≤ (2 : 𝕜)⁻¹ • f z + (2 : 𝕜)⁻¹ • f z := by gcongr; exacts [hfx hz, hfy hz] _ = f z := by rw [← _root_.add_smul]; norm_num /-- A strictly concave function admits at most one global maximum. -/ lemma StrictConcaveOn.eq_of_isMaxOn (hf : StrictConcaveOn 𝕜 s f) (hfx : IsMaxOn f s x) (hfy : IsMaxOn f s y) (hx : x ∈ s) (hy : y ∈ s) : x = y := hf.dual.eq_of_isMinOn hfx hfy hx hy end OrderedAddCommMonoid section LinearOrderedCancelAddCommMonoid variable [LinearOrderedCancelAddCommMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] {x y z : 𝕜} {s : Set 𝕜} {f : 𝕜 → β} theorem ConvexOn.le_right_of_left_le'' (hf : ConvexOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y ≤ z) (h : f x ≤ f y) : f y ≤ f z := hyz.eq_or_lt.elim (fun hyz => (congr_arg f hyz).le) fun hyz => hf.le_right_of_left_le hx hz (Ioo_subset_openSegment ⟨hxy, hyz⟩) h theorem ConvexOn.le_left_of_right_le'' (hf : ConvexOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x ≤ y) (hyz : y < z) (h : f z ≤ f y) : f y ≤ f x := hxy.eq_or_lt.elim (fun hxy => (congr_arg f hxy).ge) fun hxy => hf.le_left_of_right_le hx hz (Ioo_subset_openSegment ⟨hxy, hyz⟩) h theorem ConcaveOn.right_le_of_le_left'' (hf : ConcaveOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y ≤ z) (h : f y ≤ f x) : f z ≤ f y := hf.dual.le_right_of_left_le'' hx hz hxy hyz h theorem ConcaveOn.left_le_of_le_right'' (hf : ConcaveOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x ≤ y) (hyz : y < z) (h : f y ≤ f z) : f x ≤ f y := hf.dual.le_left_of_right_le'' hx hz hxy hyz h end LinearOrderedCancelAddCommMonoid end LinearOrderedField
Analysis\Convex\Gauge.lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E F : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg _ fun _ hx => hx.1.le theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · -- Porting note: `convert` needed help convert convex_empty (𝕜 := ℝ) (E := E) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun x hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] section LinearOrderedField variable {α : Type*} [LinearOrderedField α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ] theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) : gauge (a • s) = a⁻¹ • gauge s := by obtain rfl | ha' := ha.eq_or_lt · rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] ext x rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, y, hy, h⟩ simp_rw [mem_Ioi] at hr ⊢ refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩ rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne'] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩ rw [smul_inv₀, smul_assoc, inv_inv] theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) : gauge (a • s) = |a|⁻¹ • gauge s := by rw [← gauge_smul_left_of_nonneg (abs_nonneg a)] obtain h | h := abs_choice a · rw [h] · rw [h, Set.neg_smul_set, ← Set.smul_set_neg] -- Porting note: was congr apply congr_arg apply congr_arg ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy end LinearOrderedField section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (‖r‖ • x) = gauge s (r • x) := by unfold gauge congr with θ rw [@RCLike.real_smul_eq_coe_smul 𝕜] refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] /-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/ theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩ have hrc := (lt_inv hr₀ hc₀).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smul₀ hc₀.ne'] variable [T1Space E] theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩ have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_sub_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩ exact hr (by simpa [h₀]) rfl theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : 0 < gauge s x ↔ x ≠ 0 := by simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb] end TopologicalSpace section ContinuousSMul variable [TopologicalSpace E] [ContinuousSMul ℝ E] open Filter in theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by intro x hx have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) := ((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left rw [inv_one, one_smul] at H₁ have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsWithin_Iio' one_pos] intro r h₁ h₂ exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩ rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩ exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁ theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) : { x | gauge s x < 1 } = s := by refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_ convert interior_subset_gauge_lt_one s exact hs₂.interior_eq.symm -- Porting note: droped unneeded assumptions theorem gauge_lt_one_of_mem_of_isOpen (hs₂ : IsOpen s) {x : E} (hx : x ∈ s) : gauge s x < 1 := interior_subset_gauge_lt_one s <| by rwa [hs₂.interior_eq] -- Porting note: droped unneeded assumptions theorem gauge_lt_of_mem_smul (x : E) (ε : ℝ) (hε : 0 < ε) (hs₂ : IsOpen s) (hx : x ∈ ε • s) : gauge s x < ε := by have : ε⁻¹ • x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_mem₀ hε.ne'] have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hs₂ this rwa [gauge_smul_of_nonneg (inv_nonneg.2 hε.le), smul_eq_mul, inv_mul_lt_iff hε, mul_one] at h_gauge_lt theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x ≤ 1) : x ∈ closure s := by have : ∀ᶠ r : ℝ in 𝓝[<] 1, r • x ∈ s := by filter_upwards [Ico_mem_nhdsWithin_Iio' one_pos] with r ⟨hr₀, hr₁⟩ apply gauge_lt_one_subset_self hc hs₀ ha rw [mem_setOf_eq, gauge_smul_of_nonneg hr₀] exact mul_lt_one_of_nonneg_of_lt_one_left hr₀ hr₁ h refine mem_closure_of_tendsto ?_ this exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _)) inf_le_left theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x = 1) : x ∈ frontier s := ⟨mem_closure_of_gauge_le_one hc hs₀ ha h.le, fun h' ↦ (interior_subset_gauge_lt_one s h').out.ne h⟩ theorem tendsto_gauge_nhds_zero' (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[≥] 0) := by refine nhdsWithin_Ici_basis_Icc.tendsto_right_iff.2 fun ε hε ↦ ?_ rw [← set_smul_mem_nhds_zero_iff hε.ne'] at hs filter_upwards [hs] with x hx exact ⟨gauge_nonneg _, gauge_le_of_mem hε.le hx⟩ theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) := (tendsto_gauge_nhds_zero' hs).mono_right inf_le_left /-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin. See also `continuousAt_gauge`. -/ theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by rw [ContinuousAt, gauge_zero] exact tendsto_gauge_nhds_zero hs theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (h₀ : s ∈ 𝓝 0) : comap (gauge s) (𝓝 0) = 𝓝 0 := (comap_gauge_nhds_zero_le (absorbent_nhds_zero h₀) hb).antisymm (tendsto_gauge_nhds_zero h₀).le_comap end ContinuousSMul section TopologicalVectorSpace open Filter variable [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousSMul ℝ E] /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ theorem continuousAt_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by have ha : Absorbent ℝ s := absorbent_nhds_zero hs₀ refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun ε hε₀ ↦ ?_ rw [← map_add_left_nhds_zero, eventually_map] have : ε • s ∩ -(ε • s) ∈ 𝓝 0 := inter_mem ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀) (neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀)) filter_upwards [this] with y hy constructor · rw [sub_le_iff_le_add] calc gauge s x = gauge s (x + y + (-y)) := by simp _ ≤ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _ _ ≤ gauge s (x + y) + ε := add_le_add_left (gauge_le_of_mem hε₀.le (mem_neg.1 hy.2)) _ · calc gauge s (x + y) ≤ gauge s x + gauge s y := gauge_add_le hc ha _ _ _ ≤ gauge s x + ε := add_le_add_left (gauge_le_of_mem hε₀.le hy.1) _ /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ @[continuity] theorem continuous_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : Continuous (gauge s) := continuous_iff_continuousAt.2 fun _ ↦ continuousAt_gauge hc hs₀ theorem gauge_lt_one_eq_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : { x | gauge s x < 1 } = interior s := by refine Subset.antisymm (fun x hx ↦ ?_) (interior_subset_gauge_lt_one s) rcases mem_openSegment_of_gauge_lt_one (absorbent_nhds_zero hs₀) hx with ⟨y, hys, hxy⟩ exact hc.openSegment_interior_self_subset_interior (mem_interior_iff_mem_nhds.2 hs₀) hys hxy theorem gauge_lt_one_iff_mem_interior (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x < 1 ↔ x ∈ interior s := Set.ext_iff.1 (gauge_lt_one_eq_interior hc hs₀) _ theorem gauge_le_one_iff_mem_closure (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x ≤ 1 ↔ x ∈ closure s := ⟨mem_closure_of_gauge_le_one hc (mem_of_mem_nhds hs₀) (absorbent_nhds_zero hs₀), fun h ↦ le_on_closure (fun _ ↦ gauge_le_one_of_mem) (continuous_gauge hc hs₀).continuousOn continuousOn_const h⟩ theorem gauge_eq_one_iff_mem_frontier (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : gauge s x = 1 ↔ x ∈ frontier s := by rw [eq_iff_le_not_lt, gauge_le_one_iff_mem_closure hc hs₀, gauge_lt_one_iff_mem_interior hc hs₀] rfl end TopologicalVectorSpace section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] /-- `gauge s` as a seminorm when `s` is balanced, convex and absorbent. -/ @[simps!] def gaugeSeminorm (hs₀ : Balanced 𝕜 s) (hs₁ : Convex ℝ s) (hs₂ : Absorbent ℝ s) : Seminorm 𝕜 E := Seminorm.of (gauge s) (gauge_add_le hs₁ hs₂) (gauge_smul hs₀) variable {hs₀ : Balanced 𝕜 s} {hs₁ : Convex ℝ s} {hs₂ : Absorbent ℝ s} [TopologicalSpace E] [ContinuousSMul ℝ E] theorem gaugeSeminorm_lt_one_of_isOpen (hs : IsOpen s) {x : E} (hx : x ∈ s) : gaugeSeminorm hs₀ hs₁ hs₂ x < 1 := gauge_lt_one_of_mem_of_isOpen hs hx theorem gaugeSeminorm_ball_one (hs : IsOpen s) : (gaugeSeminorm hs₀ hs₁ hs₂).ball 0 1 = s := by rw [Seminorm.ball_zero_eq] exact gauge_lt_one_eq_self_of_isOpen hs₁ hs₂.zero_mem hs end RCLike /-- Any seminorm arises as the gauge of its unit ball. -/ @[simp] protected theorem Seminorm.gauge_ball (p : Seminorm ℝ E) : gauge (p.ball 0 1) = p := by ext x obtain hp | hp := { r : ℝ | 0 < r ∧ x ∈ r • p.ball 0 1 }.eq_empty_or_nonempty · rw [gauge, hp, Real.sInf_empty] by_contra h have hpx : 0 < p x := (apply_nonneg _ _).lt_of_ne h have hpx₂ : 0 < 2 * p x := mul_pos zero_lt_two hpx refine hp.subset ⟨hpx₂, (2 * p x)⁻¹ • x, ?_, smul_inv_smul₀ hpx₂.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpx₂), inv_mul_lt_iff hpx₂, mul_one] exact lt_mul_of_one_lt_left hpx one_lt_two refine IsGLB.csInf_eq ⟨fun r => ?_, fun r hr => le_of_forall_pos_le_add fun ε hε => ?_⟩ hp · rintro ⟨hr, y, hy, rfl⟩ rw [p.mem_ball_zero] at hy rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos hr] exact mul_le_of_le_one_right hr.le hy.le · have hpε : 0 < p x + ε := -- Porting note: was `by positivity` add_pos_of_nonneg_of_pos (apply_nonneg _ _) hε refine hr ⟨hpε, (p x + ε)⁻¹ • x, ?_, smul_inv_smul₀ hpε.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpε), inv_mul_lt_iff hpε, mul_one] exact lt_add_of_pos_right _ hε theorem Seminorm.gaugeSeminorm_ball (p : Seminorm ℝ E) : gaugeSeminorm (p.balanced_ball_zero 1) (p.convex_ball 0 1) (p.absorbent_ball_zero zero_lt_one) = p := DFunLike.coe_injective p.gauge_ball end AddCommGroup section Seminormed variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E} open Metric theorem gauge_unit_ball (x : E) : gauge (ball (0 : E) 1) x = ‖x‖ := by rw [← ball_normSeminorm ℝ, Seminorm.gauge_ball, coe_normSeminorm] theorem gauge_ball (hr : 0 ≤ r) (x : E) : gauge (ball (0 : E) r) x = ‖x‖ / r := by rcases hr.eq_or_lt with rfl | hr · simp · rw [← smul_unitBall_of_pos hr, gauge_smul_left, Pi.smul_apply, gauge_unit_ball, smul_eq_mul, abs_of_nonneg hr.le, div_eq_inv_mul] simp_rw [mem_ball_zero_iff, norm_neg] exact fun _ => id @[deprecated gauge_ball (since := "2023-07-24")] theorem gauge_ball' (hr : 0 < r) (x : E) : gauge (ball (0 : E) r) x = ‖x‖ / r := gauge_ball hr.le x @[simp] theorem gauge_closure_zero : gauge (closure (0 : Set E)) = 0 := funext fun x ↦ by simp only [← singleton_zero, gauge_def', mem_closure_zero_iff_norm, norm_smul, mul_eq_zero, norm_eq_zero, inv_eq_zero] rcases (norm_nonneg x).eq_or_gt with hx | hx · convert csInf_Ioi (a := (0 : ℝ)) exact Set.ext fun r ↦ and_iff_left (.inr hx) · convert Real.sInf_empty exact eq_empty_of_forall_not_mem fun r ⟨hr₀, hr⟩ ↦ hx.ne' <| hr.resolve_left hr₀.out.ne' @[simp] theorem gauge_closedBall (hr : 0 ≤ r) (x : E) : gauge (closedBall (0 : E) r) x = ‖x‖ / r := by rcases hr.eq_or_lt with rfl | hr' · rw [div_zero, closedBall_zero', singleton_zero, gauge_closure_zero]; rfl · apply le_antisymm · rw [← gauge_ball hr] exact gauge_mono (absorbent_ball_zero hr') ball_subset_closedBall x · suffices ∀ᶠ R in 𝓝[>] r, ‖x‖ / R ≤ gauge (closedBall 0 r) x by refine le_of_tendsto ?_ this exact tendsto_const_nhds.div inf_le_left hr'.ne' filter_upwards [self_mem_nhdsWithin] with R hR rw [← gauge_ball (hr.trans hR.out.le)] refine gauge_mono ?_ (closedBall_subset_ball hR) _ exact (absorbent_ball_zero hr').mono ball_subset_closedBall theorem mul_gauge_le_norm (hs : Metric.ball (0 : E) r ⊆ s) : r * gauge s x ≤ ‖x‖ := by obtain hr | hr := le_or_lt r 0 · exact (mul_nonpos_of_nonpos_of_nonneg hr <| gauge_nonneg _).trans (norm_nonneg _) rw [mul_comm, ← le_div_iff hr, ← gauge_ball hr.le] exact gauge_mono (absorbent_ball_zero hr) hs x theorem Convex.lipschitzWith_gauge {r : ℝ≥0} (hc : Convex ℝ s) (hr : 0 < r) (hs : Metric.ball (0 : E) r ⊆ s) : LipschitzWith r⁻¹ (gauge s) := have : Absorbent ℝ (Metric.ball (0 : E) r) := absorbent_ball_zero hr LipschitzWith.of_le_add_mul _ fun x y => calc gauge s x = gauge s (y + (x - y)) := by simp _ ≤ gauge s y + gauge s (x - y) := gauge_add_le hc (this.mono hs) _ _ _ ≤ gauge s y + ‖x - y‖ / r := add_le_add_left ((gauge_mono this hs (x - y)).trans_eq (gauge_ball hr.le _)) _ _ = gauge s y + r⁻¹ * dist x y := by rw [dist_eq_norm, div_eq_inv_mul, NNReal.coe_inv] theorem Convex.lipschitz_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) : ∃ K, LipschitzWith K (gauge s) := let ⟨r, hr₀, hr⟩ := Metric.mem_nhds_iff.1 h₀ ⟨(⟨r, hr₀.le⟩ : ℝ≥0)⁻¹, hc.lipschitzWith_gauge hr₀ hr⟩ theorem Convex.uniformContinuous_gauge (hc : Convex ℝ s) (h₀ : s ∈ 𝓝 (0 : E)) : UniformContinuous (gauge s) := let ⟨_K, hK⟩ := hc.lipschitz_gauge h₀; hK.uniformContinuous end Seminormed section Normed variable [NormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E} open Metric theorem le_gauge_of_subset_closedBall (hs : Absorbent ℝ s) (hr : 0 ≤ r) (hsr : s ⊆ closedBall 0 r) : ‖x‖ / r ≤ gauge s x := by rw [← gauge_closedBall hr] exact gauge_mono hs hsr _ end Normed
Analysis\Convex\GaugeRescale.lean
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Convex.Gauge import Mathlib.Analysis.Convex.Normed /-! # "Gauge rescale" homeomorphism between convex sets Given two convex von Neumann bounded neighbourhoods of the origin in a real topological vector space, we construct a homeomorphism `gaugeRescaleHomeomorph` that sends the interior, the closure, and the frontier of one set to the interior, the closure, and the frontier of the other set. -/ open Metric Bornology Filter Set open scoped NNReal Topology Pointwise noncomputable section section Module variable {E : Type*} [AddCommGroup E] [Module ℝ E] /-- The gauge rescale map `gaugeRescale s t` sends each point `x` to the point `y` on the same ray that has the same gauge w.r.t. `t` as `x` has w.r.t. `s`. The characteristic property is satisfied if `gauge t x ≠ 0`, see `gauge_gaugeRescale'`. In particular, it is satisfied for all `x`, provided that `t` is absorbent and von Neumann bounded. -/ def gaugeRescale (s t : Set E) (x : E) : E := (gauge s x / gauge t x) • x theorem gaugeRescale_def (s t : Set E) (x : E) : gaugeRescale s t x = (gauge s x / gauge t x) • x := rfl @[simp] theorem gaugeRescale_zero (s t : Set E) : gaugeRescale s t 0 = 0 := smul_zero _ theorem gaugeRescale_smul (s t : Set E) {c : ℝ} (hc : 0 ≤ c) (x : E) : gaugeRescale s t (c • x) = c • gaugeRescale s t x := by simp only [gaugeRescale, gauge_smul_of_nonneg hc, smul_smul, smul_eq_mul] rw [mul_div_mul_comm, mul_right_comm, div_self_mul_self] variable [TopologicalSpace E] [T1Space E] theorem gaugeRescale_self_apply {s : Set E} (hsa : Absorbent ℝ s) (hsb : IsVonNBounded ℝ s) (x : E) : gaugeRescale s s x = x := by rcases eq_or_ne x 0 with rfl | hx; · simp rw [gaugeRescale, div_self, one_smul] exact ((gauge_pos hsa hsb).2 hx).ne' theorem gaugeRescale_self {s : Set E} (hsa : Absorbent ℝ s) (hsb : IsVonNBounded ℝ s) : gaugeRescale s s = id := funext <| gaugeRescale_self_apply hsa hsb theorem gauge_gaugeRescale' (s : Set E) {t : Set E} {x : E} (hx : gauge t x ≠ 0) : gauge t (gaugeRescale s t x) = gauge s x := by rw [gaugeRescale, gauge_smul_of_nonneg (div_nonneg (gauge_nonneg _) (gauge_nonneg _)), smul_eq_mul, div_mul_cancel₀ _ hx] theorem gauge_gaugeRescale (s : Set E) {t : Set E} (hta : Absorbent ℝ t) (htb : IsVonNBounded ℝ t) (x : E) : gauge t (gaugeRescale s t x) = gauge s x := by rcases eq_or_ne x 0 with rfl | hx · simp · exact gauge_gaugeRescale' s ((gauge_pos hta htb).2 hx).ne' theorem gauge_gaugeRescale_le (s t : Set E) (x : E) : gauge t (gaugeRescale s t x) ≤ gauge s x := by by_cases hx : gauge t x = 0 · simp [gaugeRescale, hx, gauge_nonneg] · exact (gauge_gaugeRescale' s hx).le theorem gaugeRescale_gaugeRescale {s t u : Set E} (hta : Absorbent ℝ t) (htb : IsVonNBounded ℝ t) (x : E) : gaugeRescale t u (gaugeRescale s t x) = gaugeRescale s u x := by rcases eq_or_ne x 0 with rfl | hx; · simp rw [gaugeRescale_def s t x, gaugeRescale_smul, gaugeRescale, gaugeRescale, smul_smul, div_mul_div_cancel] exacts [((gauge_pos hta htb).2 hx).ne', div_nonneg (gauge_nonneg _) (gauge_nonneg _)] /-- `gaugeRescale` bundled as an `Equiv`. -/ def gaugeRescaleEquiv (s t : Set E) (hsa : Absorbent ℝ s) (hsb : IsVonNBounded ℝ s) (hta : Absorbent ℝ t) (htb : IsVonNBounded ℝ t) : E ≃ E where toFun := gaugeRescale s t invFun := gaugeRescale t s left_inv x := by rw [gaugeRescale_gaugeRescale, gaugeRescale_self_apply] <;> assumption right_inv x := by rw [gaugeRescale_gaugeRescale, gaugeRescale_self_apply] <;> assumption variable [TopologicalAddGroup E] [ContinuousSMul ℝ E] {s t : Set E} theorem mapsTo_gaugeRescale_interior (h₀ : t ∈ 𝓝 0) (hc : Convex ℝ t) : MapsTo (gaugeRescale s t) (interior s) (interior t) := fun x hx ↦ by rw [← gauge_lt_one_iff_mem_interior] <;> try assumption exact (gauge_gaugeRescale_le _ _ _).trans_lt (interior_subset_gauge_lt_one _ hx) theorem mapsTo_gaugeRescale_closure {s t : Set E} (hsc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) (htc : Convex ℝ t) (ht₀ : 0 ∈ t) (hta : Absorbent ℝ t) : MapsTo (gaugeRescale s t) (closure s) (closure t) := fun _x hx ↦ mem_closure_of_gauge_le_one htc ht₀ hta <| (gauge_gaugeRescale_le _ _ _).trans <| (gauge_le_one_iff_mem_closure hsc hs₀).2 hx theorem continuous_gaugeRescale {s t : Set E} (hs : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) (ht : Convex ℝ t) (ht₀ : t ∈ 𝓝 0) (htb : IsVonNBounded ℝ t) : Continuous (gaugeRescale s t) := by have hta : Absorbent ℝ t := absorbent_nhds_zero ht₀ refine continuous_iff_continuousAt.2 fun x ↦ ?_ rcases eq_or_ne x 0 with rfl | hx · rw [ContinuousAt, gaugeRescale_zero] nth_rewrite 2 [← comap_gauge_nhds_zero htb ht₀] simp only [tendsto_comap_iff, (· ∘ ·), gauge_gaugeRescale _ hta htb] exact tendsto_gauge_nhds_zero hs₀ · exact ((continuousAt_gauge hs hs₀).div (continuousAt_gauge ht ht₀) ((gauge_pos hta htb).2 hx).ne').smul continuousAt_id /-- `gaugeRescale` bundled as a `Homeomorph`. -/ def gaugeRescaleHomeomorph (s t : Set E) (hsc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) (hsb : IsVonNBounded ℝ s) (htc : Convex ℝ t) (ht₀ : t ∈ 𝓝 0) (htb : IsVonNBounded ℝ t) : E ≃ₜ E where toEquiv := gaugeRescaleEquiv s t (absorbent_nhds_zero hs₀) hsb (absorbent_nhds_zero ht₀) htb continuous_toFun := by apply continuous_gaugeRescale <;> assumption continuous_invFun := by apply continuous_gaugeRescale <;> assumption theorem image_gaugeRescaleHomeomorph_interior {s t : Set E} (hsc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) (hsb : IsVonNBounded ℝ s) (htc : Convex ℝ t) (ht₀ : t ∈ 𝓝 0) (htb : IsVonNBounded ℝ t) : gaugeRescaleHomeomorph s t hsc hs₀ hsb htc ht₀ htb '' interior s = interior t := Subset.antisymm (mapsTo_gaugeRescale_interior ht₀ htc).image_subset <| by rw [← Homeomorph.preimage_symm, ← image_subset_iff] exact (mapsTo_gaugeRescale_interior hs₀ hsc).image_subset theorem image_gaugeRescaleHomeomorph_closure {s t : Set E} (hsc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) (hsb : IsVonNBounded ℝ s) (htc : Convex ℝ t) (ht₀ : t ∈ 𝓝 0) (htb : IsVonNBounded ℝ t) : gaugeRescaleHomeomorph s t hsc hs₀ hsb htc ht₀ htb '' closure s = closure t := by refine Subset.antisymm (mapsTo_gaugeRescale_closure hsc hs₀ htc (mem_of_mem_nhds ht₀) (absorbent_nhds_zero ht₀)).image_subset ?_ rw [← Homeomorph.preimage_symm, ← image_subset_iff] exact (mapsTo_gaugeRescale_closure htc ht₀ hsc (mem_of_mem_nhds hs₀) (absorbent_nhds_zero hs₀)).image_subset /-- Given two convex bounded sets in a topological vector space with nonempty interiors, there exists a homeomorphism of the ambient space that sends the interior, the closure, and the frontier of one set to the interior, the closure, and the frontier of the other set. In particular, if both `s` and `t` are open set or both `s` and `t` are closed sets, then `e` maps `s` to `t`. -/ theorem exists_homeomorph_image_eq {s t : Set E} (hsc : Convex ℝ s) (hsne : (interior s).Nonempty) (hsb : IsVonNBounded ℝ s) (hst : Convex ℝ t) (htne : (interior t).Nonempty) (htb : IsVonNBounded ℝ t) : ∃ e : E ≃ₜ E, e '' interior s = interior t ∧ e '' closure s = closure t ∧ e '' frontier s = frontier t := by rsuffices ⟨e, h₁, h₂⟩ : ∃ e : E ≃ₜ E, e '' interior s = interior t ∧ e '' closure s = closure t · refine ⟨e, h₁, h₂, ?_⟩ simp_rw [← closure_diff_interior, image_diff e.injective, h₁, h₂] rcases hsne with ⟨x, hx⟩ rcases htne with ⟨y, hy⟩ set h : E ≃ₜ E := by apply gaugeRescaleHomeomorph (-x +ᵥ s) (-y +ᵥ t) <;> simp [← mem_interior_iff_mem_nhds, interior_vadd, mem_vadd_set_iff_neg_vadd_mem, *] refine ⟨.trans (.addLeft (-x)) <| h.trans <| .addLeft y, ?_, ?_⟩ · calc (fun a ↦ y + h (-x + a)) '' interior s = y +ᵥ h '' interior (-x +ᵥ s) := by simp_rw [interior_vadd, ← image_vadd, image_image, vadd_eq_add] _ = _ := by rw [image_gaugeRescaleHomeomorph_interior, interior_vadd, vadd_neg_vadd] · calc (fun a ↦ y + h (-x + a)) '' closure s = y +ᵥ h '' closure (-x +ᵥ s) := by simp_rw [closure_vadd, ← image_vadd, image_image, vadd_eq_add] _ = _ := by rw [image_gaugeRescaleHomeomorph_closure, closure_vadd, vadd_neg_vadd] end Module variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If `s` is a convex bounded set with a nonempty interior in a real normed space, then there is a homeomorphism of the ambient space to itself that sends the interior of `s` to the unit open ball and the closure of `s` to the unit closed ball. -/ theorem exists_homeomorph_image_interior_closure_frontier_eq_unitBall {s : Set E} (hc : Convex ℝ s) (hne : (interior s).Nonempty) (hb : IsBounded s) : ∃ h : E ≃ₜ E, h '' interior s = ball 0 1 ∧ h '' closure s = closedBall 0 1 ∧ h '' frontier s = sphere 0 1 := by simpa [isOpen_ball.interior_eq, closure_ball, frontier_ball] using exists_homeomorph_image_eq hc hne (NormedSpace.isVonNBounded_of_isBounded _ hb) (convex_ball 0 1) (by simp [isOpen_ball.interior_eq]) (NormedSpace.isVonNBounded_ball _ _ _)
Analysis\Convex\Hull.lean
/- Copyright (c) 2020 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Yaël Dillies -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Order.Closure /-! # Convex hull This file defines the convex hull of a set `s` in a module. `convexHull 𝕜 s` is the smallest convex set containing `s`. In order theory speak, this is a closure operator. ## Implementation notes `convexHull` is defined as a closure operator. This gives access to the `ClosureOperator` API while the impact on writing code is minimal as `convexHull 𝕜 s` is automatically elaborated as `(convexHull 𝕜) s`. -/ open Set open Pointwise variable {𝕜 E F : Type*} section convexHull section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable (𝕜) variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] /-- The convex hull of a set `s` is the minimal convex set that includes `s`. -/ @[simps! isClosed] def convexHull : ClosureOperator (Set E) := .ofCompletePred (Convex 𝕜) fun _ ↦ convex_sInter variable (s : Set E) theorem subset_convexHull : s ⊆ convexHull 𝕜 s := (convexHull 𝕜).le_closure s theorem convex_convexHull : Convex 𝕜 (convexHull 𝕜 s) := (convexHull 𝕜).isClosed_closure s theorem convexHull_eq_iInter : convexHull 𝕜 s = ⋂ (t : Set E) (_ : s ⊆ t) (_ : Convex 𝕜 t), t := by simp [convexHull, iInter_subtype, iInter_and] variable {𝕜 s} {t : Set E} {x y : E} theorem mem_convexHull_iff : x ∈ convexHull 𝕜 s ↔ ∀ t, s ⊆ t → Convex 𝕜 t → x ∈ t := by simp_rw [convexHull_eq_iInter, mem_iInter] theorem convexHull_min : s ⊆ t → Convex 𝕜 t → convexHull 𝕜 s ⊆ t := (convexHull 𝕜).closure_min theorem Convex.convexHull_subset_iff (ht : Convex 𝕜 t) : convexHull 𝕜 s ⊆ t ↔ s ⊆ t := (show (convexHull 𝕜).IsClosed t from ht).closure_le_iff @[mono, gcongr] theorem convexHull_mono (hst : s ⊆ t) : convexHull 𝕜 s ⊆ convexHull 𝕜 t := (convexHull 𝕜).monotone hst lemma convexHull_eq_self : convexHull 𝕜 s = s ↔ Convex 𝕜 s := (convexHull 𝕜).isClosed_iff.symm alias ⟨_, Convex.convexHull_eq⟩ := convexHull_eq_self @[simp] theorem convexHull_univ : convexHull 𝕜 (univ : Set E) = univ := ClosureOperator.closure_top (convexHull 𝕜) @[simp] theorem convexHull_empty : convexHull 𝕜 (∅ : Set E) = ∅ := convex_empty.convexHull_eq @[simp] theorem convexHull_empty_iff : convexHull 𝕜 s = ∅ ↔ s = ∅ := by constructor · intro h rw [← Set.subset_empty_iff, ← h] exact subset_convexHull 𝕜 _ · rintro rfl exact convexHull_empty @[simp] theorem convexHull_nonempty_iff : (convexHull 𝕜 s).Nonempty ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, nonempty_iff_ne_empty, Ne, Ne] exact not_congr convexHull_empty_iff protected alias ⟨_, Set.Nonempty.convexHull⟩ := convexHull_nonempty_iff theorem segment_subset_convexHull (hx : x ∈ s) (hy : y ∈ s) : segment 𝕜 x y ⊆ convexHull 𝕜 s := (convex_convexHull _ _).segment_subset (subset_convexHull _ _ hx) (subset_convexHull _ _ hy) @[simp] theorem convexHull_singleton (x : E) : convexHull 𝕜 ({x} : Set E) = {x} := (convex_singleton x).convexHull_eq @[simp] theorem convexHull_zero : convexHull 𝕜 (0 : Set E) = 0 := convexHull_singleton 0 @[simp] theorem convexHull_pair (x y : E) : convexHull 𝕜 {x, y} = segment 𝕜 x y := by refine (convexHull_min ?_ <| convex_segment _ _).antisymm (segment_subset_convexHull (mem_insert _ _) <| subset_insert _ _ <| mem_singleton _) rw [insert_subset_iff, singleton_subset_iff] exact ⟨left_mem_segment _ _ _, right_mem_segment _ _ _⟩ theorem convexHull_convexHull_union_left (s t : Set E) : convexHull 𝕜 (convexHull 𝕜 s ∪ t) = convexHull 𝕜 (s ∪ t) := ClosureOperator.closure_sup_closure_left _ _ _ theorem convexHull_convexHull_union_right (s t : Set E) : convexHull 𝕜 (s ∪ convexHull 𝕜 t) = convexHull 𝕜 (s ∪ t) := ClosureOperator.closure_sup_closure_right _ _ _ theorem Convex.convex_remove_iff_not_mem_convexHull_remove {s : Set E} (hs : Convex 𝕜 s) (x : E) : Convex 𝕜 (s \ {x}) ↔ x ∉ convexHull 𝕜 (s \ {x}) := by constructor · rintro hsx hx rw [hsx.convexHull_eq] at hx exact hx.2 (mem_singleton _) rintro hx suffices h : s \ {x} = convexHull 𝕜 (s \ {x}) by rw [h] exact convex_convexHull 𝕜 _ exact Subset.antisymm (subset_convexHull 𝕜 _) fun y hy => ⟨convexHull_min diff_subset hs hy, by rintro (rfl : y = x) exact hx hy⟩ theorem IsLinearMap.image_convexHull {f : E → F} (hf : IsLinearMap 𝕜 f) (s : Set E) : f '' convexHull 𝕜 s = convexHull 𝕜 (f '' s) := Set.Subset.antisymm (image_subset_iff.2 <| convexHull_min (image_subset_iff.1 <| subset_convexHull 𝕜 _) ((convex_convexHull 𝕜 _).is_linear_preimage hf)) (convexHull_min (image_subset _ (subset_convexHull 𝕜 s)) <| (convex_convexHull 𝕜 s).is_linear_image hf) theorem LinearMap.image_convexHull (f : E →ₗ[𝕜] F) (s : Set E) : f '' convexHull 𝕜 s = convexHull 𝕜 (f '' s) := f.isLinear.image_convexHull s end AddCommMonoid end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] theorem convexHull_smul (a : 𝕜) (s : Set E) : convexHull 𝕜 (a • s) = a • convexHull 𝕜 s := (LinearMap.lsmul _ _ a).image_convexHull _ |>.symm end OrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] theorem AffineMap.image_convexHull (f : E →ᵃ[𝕜] F) (s : Set E) : f '' convexHull 𝕜 s = convexHull 𝕜 (f '' s) := by apply Set.Subset.antisymm · rw [Set.image_subset_iff] refine convexHull_min ?_ ((convex_convexHull 𝕜 (f '' s)).affine_preimage f) rw [← Set.image_subset_iff] exact subset_convexHull 𝕜 (f '' s) · exact convexHull_min (Set.image_subset _ (subset_convexHull 𝕜 s)) ((convex_convexHull 𝕜 s).affine_image f) theorem convexHull_subset_affineSpan (s : Set E) : convexHull 𝕜 s ⊆ (affineSpan 𝕜 s : Set E) := convexHull_min (subset_affineSpan 𝕜 s) (affineSpan 𝕜 s).convex @[simp] theorem affineSpan_convexHull (s : Set E) : affineSpan 𝕜 (convexHull 𝕜 s) = affineSpan 𝕜 s := by refine le_antisymm ?_ (affineSpan_mono 𝕜 (subset_convexHull 𝕜 s)) rw [affineSpan_le] exact convexHull_subset_affineSpan s theorem convexHull_neg (s : Set E) : convexHull 𝕜 (-s) = -convexHull 𝕜 s := by simp_rw [← image_neg] exact AffineMap.image_convexHull (-1) _ |>.symm lemma convexHull_vadd (x : E) (s : Set E) : convexHull 𝕜 (x +ᵥ s) = x +ᵥ convexHull 𝕜 s := (AffineEquiv.constVAdd 𝕜 _ x).toAffineMap.image_convexHull s |>.symm end AddCommGroup end OrderedRing end convexHull
Analysis\Convex\Independent.lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Extreme /-! # Convex independence This file defines convex independent families of points. Convex independence is closely related to affine independence. In both cases, no point can be written as a combination of others. When the combination is affine (that is, any coefficients), this yields affine independence. When the combination is convex (that is, all coefficients are nonnegative), then this yields convex independence. In particular, affine independence implies convex independence. ## Main declarations * `ConvexIndependent p`: Convex independence of the indexed family `p : ι → E`. Every point of the family only belongs to convex hulls of sets of the family containing it. * `convexIndependent_iff_finset`: Carathéodory's theorem allows us to only check finsets to conclude convex independence. * `Convex.convexIndependent_extremePoints`: Extreme points of a convex set are convex independent. ## References * https://en.wikipedia.org/wiki/Convex_position ## TODO Prove `AffineIndependent.convexIndependent`. This requires some glue between `affineCombination` and `Finset.centerMass`. ## Tags independence, convex position -/ open scoped Classical open Affine open Finset Function variable {𝕜 E ι : Type*} section OrderedSemiring variable (𝕜) [OrderedSemiring 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E} /-- An indexed family is said to be convex independent if every point only belongs to convex hulls of sets containing it. -/ def ConvexIndependent (p : ι → E) : Prop := ∀ (s : Set ι) (x : ι), p x ∈ convexHull 𝕜 (p '' s) → x ∈ s variable {𝕜} /-- A family with at most one point is convex independent. -/ theorem Subsingleton.convexIndependent [Subsingleton ι] (p : ι → E) : ConvexIndependent 𝕜 p := by intro s x hx have : (convexHull 𝕜 (p '' s)).Nonempty := ⟨p x, hx⟩ rw [convexHull_nonempty_iff, Set.image_nonempty] at this rwa [Subsingleton.mem_iff_nonempty] /-- A convex independent family is injective. -/ protected theorem ConvexIndependent.injective {p : ι → E} (hc : ConvexIndependent 𝕜 p) : Function.Injective p := by refine fun i j hij => hc {j} i ?_ rw [hij, Set.image_singleton, convexHull_singleton] exact Set.mem_singleton _ /-- If a family is convex independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ theorem ConvexIndependent.comp_embedding {ι' : Type*} (f : ι' ↪ ι) {p : ι → E} (hc : ConvexIndependent 𝕜 p) : ConvexIndependent 𝕜 (p ∘ f) := by intro s x hx rw [← f.injective.mem_set_image] exact hc _ _ (by rwa [Set.image_image]) /-- If a family is convex independent, so is any subfamily indexed by a subtype of the index type. -/ protected theorem ConvexIndependent.subtype {p : ι → E} (hc : ConvexIndependent 𝕜 p) (s : Set ι) : ConvexIndependent 𝕜 fun i : s => p i := hc.comp_embedding (Embedding.subtype _) /-- If an indexed family of points is convex independent, so is the corresponding set of points. -/ protected theorem ConvexIndependent.range {p : ι → E} (hc : ConvexIndependent 𝕜 p) : ConvexIndependent 𝕜 ((↑) : Set.range p → E) := by let f : Set.range p → ι := fun x => x.property.choose have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩ convert hc.comp_embedding fe ext rw [Embedding.coeFn_mk, comp_apply, hf] /-- A subset of a convex independent set of points is convex independent as well. -/ protected theorem ConvexIndependent.mono {s t : Set E} (hc : ConvexIndependent 𝕜 ((↑) : t → E)) (hs : s ⊆ t) : ConvexIndependent 𝕜 ((↑) : s → E) := hc.comp_embedding (s.embeddingOfSubset t hs) /-- The range of an injective indexed family of points is convex independent iff that family is. -/ theorem Function.Injective.convexIndependent_iff_set {p : ι → E} (hi : Function.Injective p) : ConvexIndependent 𝕜 ((↑) : Set.range p → E) ↔ ConvexIndependent 𝕜 p := ⟨fun hc => hc.comp_embedding (⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ : ι ↪ Set.range p), ConvexIndependent.range⟩ /-- If a family is convex independent, a point in the family is in the convex hull of some of the points given by a subset of the index type if and only if the point's index is in this subset. -/ @[simp] protected theorem ConvexIndependent.mem_convexHull_iff {p : ι → E} (hc : ConvexIndependent 𝕜 p) (s : Set ι) (i : ι) : p i ∈ convexHull 𝕜 (p '' s) ↔ i ∈ s := ⟨hc _ _, fun hi => subset_convexHull 𝕜 _ (Set.mem_image_of_mem p hi)⟩ /-- If a family is convex independent, a point in the family is not in the convex hull of the other points. See `convexIndependent_set_iff_not_mem_convexHull_diff` for the `Set` version. -/ theorem convexIndependent_iff_not_mem_convexHull_diff {p : ι → E} : ConvexIndependent 𝕜 p ↔ ∀ i s, p i ∉ convexHull 𝕜 (p '' (s \ {i})) := by refine ⟨fun hc i s h => ?_, fun h s i hi => ?_⟩ · rw [hc.mem_convexHull_iff] at h exact h.2 (Set.mem_singleton _) · by_contra H refine h i s ?_ rw [Set.diff_singleton_eq_self H] exact hi theorem convexIndependent_set_iff_inter_convexHull_subset {s : Set E} : ConvexIndependent 𝕜 ((↑) : s → E) ↔ ∀ t, t ⊆ s → s ∩ convexHull 𝕜 t ⊆ t := by constructor · rintro hc t h x ⟨hxs, hxt⟩ refine hc { x | ↑x ∈ t } ⟨x, hxs⟩ ?_ rw [Subtype.coe_image_of_subset h] exact hxt · intro hc t x h rw [← Subtype.coe_injective.mem_set_image] exact hc (t.image ((↑) : s → E)) (Subtype.coe_image_subset s t) ⟨x.prop, h⟩ /-- If a set is convex independent, a point in the set is not in the convex hull of the other points. See `convexIndependent_iff_not_mem_convexHull_diff` for the indexed family version. -/ theorem convexIndependent_set_iff_not_mem_convexHull_diff {s : Set E} : ConvexIndependent 𝕜 ((↑) : s → E) ↔ ∀ x ∈ s, x ∉ convexHull 𝕜 (s \ {x}) := by rw [convexIndependent_set_iff_inter_convexHull_subset] constructor · rintro hs x hxs hx exact (hs _ Set.diff_subset ⟨hxs, hx⟩).2 (Set.mem_singleton _) · rintro hs t ht x ⟨hxs, hxt⟩ by_contra h exact hs _ hxs (convexHull_mono (Set.subset_diff_singleton ht h) hxt) end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s : Set E} /-- To check convex independence, one only has to check finsets thanks to Carathéodory's theorem. -/ theorem convexIndependent_iff_finset {p : ι → E} : ConvexIndependent 𝕜 p ↔ ∀ (s : Finset ι) (x : ι), p x ∈ convexHull 𝕜 (s.image p : Set E) → x ∈ s := by refine ⟨fun hc s x hx => hc s x ?_, fun h s x hx => ?_⟩ · rwa [Finset.coe_image] at hx have hp : Injective p := by rintro a b hab rw [← mem_singleton] refine h {b} a ?_ rw [hab, image_singleton, coe_singleton, convexHull_singleton] exact Set.mem_singleton _ rw [convexHull_eq_union_convexHull_finite_subsets] at hx simp_rw [Set.mem_iUnion] at hx obtain ⟨t, ht, hx⟩ := hx rw [← hp.mem_set_image] refine ht ?_ suffices x ∈ t.preimage p hp.injOn by rwa [mem_preimage, ← mem_coe] at this refine h _ x ?_ rwa [t.image_preimage p hp.injOn, filter_true_of_mem] exact fun y hy => s.image_subset_range p (ht <| mem_coe.2 hy) /-! ### Extreme points -/ theorem Convex.convexIndependent_extremePoints (hs : Convex 𝕜 s) : ConvexIndependent 𝕜 ((↑) : s.extremePoints 𝕜 → E) := convexIndependent_set_iff_not_mem_convexHull_diff.2 fun _ hx h => (extremePoints_convexHull_subset (inter_extremePoints_subset_extremePoints_of_subset (convexHull_min (Set.diff_subset.trans extremePoints_subset) hs) ⟨h, hx⟩)).2 (Set.mem_singleton _) end LinearOrderedField
Analysis\Convex\Integral.lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Analysis.Convex.Function import Mathlib.Analysis.Convex.StrictConvexSpace import Mathlib.MeasureTheory.Function.AEEqOfIntegral import Mathlib.MeasureTheory.Integral.Average /-! # Jensen's inequality for integrals In this file we prove several forms of Jensen's inequality for integrals. - for convex sets: `Convex.average_mem`, `Convex.set_average_mem`, `Convex.integral_mem`; - for convex functions: `ConvexOn.average_mem_epigraph`, `ConvexOn.map_average_le`, `ConvexOn.set_average_mem_epigraph`, `ConvexOn.map_set_average_le`, `ConvexOn.map_integral_le`; - for strictly convex sets: `StrictConvex.ae_eq_const_or_average_mem_interior`; - for a closed ball in a strictly convex normed space: `ae_eq_const_or_norm_integral_lt_of_norm_le_const`; - for strictly convex functions: `StrictConvexOn.ae_eq_const_or_map_average_lt`. ## TODO - Use a typeclass for strict convexity of a closed ball. ## Tags convex, integral, center mass, average value, Jensen's inequality -/ open MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function open scoped Topology ENNReal Convex variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ : Measure α} {s : Set E} {t : Set α} {f : α → E} {g : E → ℝ} {C : ℝ} /-! ### Non-strict Jensen's inequality -/ /-- If `μ` is a probability measure on `α`, `s` is a convex closed set in `E`, and `f` is an integrable function sending `μ`-a.e. points to `s`, then the expected value of `f` belongs to `s`: `∫ x, f x ∂μ ∈ s`. See also `Convex.sum_mem` for a finite sum version of this lemma. -/ theorem Convex.integral_mem [IsProbabilityMeasure μ] (hs : Convex ℝ s) (hsc : IsClosed s) (hf : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) : (∫ x, f x ∂μ) ∈ s := by borelize E rcases hfi.aestronglyMeasurable with ⟨g, hgm, hfg⟩ haveI : SeparableSpace (range g ∩ s : Set E) := (hgm.isSeparable_range.mono inter_subset_left).separableSpace obtain ⟨y₀, h₀⟩ : (range g ∩ s).Nonempty := by rcases (hf.and hfg).exists with ⟨x₀, h₀⟩ exact ⟨f x₀, by simp only [h₀.2, mem_range_self], h₀.1⟩ rw [integral_congr_ae hfg]; rw [integrable_congr hfg] at hfi have hg : ∀ᵐ x ∂μ, g x ∈ closure (range g ∩ s) := by filter_upwards [hfg.rw (fun _ y => y ∈ s) hf] with x hx apply subset_closure exact ⟨mem_range_self _, hx⟩ set G : ℕ → SimpleFunc α E := SimpleFunc.approxOn _ hgm.measurable (range g ∩ s) y₀ h₀ have : Tendsto (fun n => (G n).integral μ) atTop (𝓝 <| ∫ x, g x ∂μ) := tendsto_integral_approxOn_of_measurable hfi _ hg _ (integrable_const _) refine hsc.mem_of_tendsto this (eventually_of_forall fun n => hs.sum_mem ?_ ?_ ?_) · exact fun _ _ => ENNReal.toReal_nonneg · rw [← ENNReal.toReal_sum, (G n).sum_range_measure_preimage_singleton, measure_univ, ENNReal.one_toReal] exact fun _ _ => measure_ne_top _ _ · simp only [SimpleFunc.mem_range, forall_mem_range] intro x apply (range g).inter_subset_right exact SimpleFunc.approxOn_mem hgm.measurable h₀ _ _ /-- If `μ` is a non-zero finite measure on `α`, `s` is a convex closed set in `E`, and `f` is an integrable function sending `μ`-a.e. points to `s`, then the average value of `f` belongs to `s`: `⨍ x, f x ∂μ ∈ s`. See also `Convex.centerMass_mem` for a finite sum version of this lemma. -/ theorem Convex.average_mem [IsFiniteMeasure μ] [NeZero μ] (hs : Convex ℝ s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) : (⨍ x, f x ∂μ) ∈ s := by refine hs.integral_mem hsc (ae_mono' ?_ hfs) hfi.to_average exact AbsolutelyContinuous.smul (refl _) _ /-- If `μ` is a non-zero finite measure on `α`, `s` is a convex closed set in `E`, and `f` is an integrable function sending `μ`-a.e. points to `s`, then the average value of `f` belongs to `s`: `⨍ x, f x ∂μ ∈ s`. See also `Convex.centerMass_mem` for a finite sum version of this lemma. -/ theorem Convex.set_average_mem (hs : Convex ℝ s) (hsc : IsClosed s) (h0 : μ t ≠ 0) (ht : μ t ≠ ∞) (hfs : ∀ᵐ x ∂μ.restrict t, f x ∈ s) (hfi : IntegrableOn f t μ) : (⨍ x in t, f x ∂μ) ∈ s := have := Fact.mk ht.lt_top have := NeZero.mk h0 hs.average_mem hsc hfs hfi /-- If `μ` is a non-zero finite measure on `α`, `s` is a convex set in `E`, and `f` is an integrable function sending `μ`-a.e. points to `s`, then the average value of `f` belongs to `closure s`: `⨍ x, f x ∂μ ∈ s`. See also `Convex.centerMass_mem` for a finite sum version of this lemma. -/ theorem Convex.set_average_mem_closure (hs : Convex ℝ s) (h0 : μ t ≠ 0) (ht : μ t ≠ ∞) (hfs : ∀ᵐ x ∂μ.restrict t, f x ∈ s) (hfi : IntegrableOn f t μ) : (⨍ x in t, f x ∂μ) ∈ closure s := hs.closure.set_average_mem isClosed_closure h0 ht (hfs.mono fun _ hx => subset_closure hx) hfi theorem ConvexOn.average_mem_epigraph [IsFiniteMeasure μ] [NeZero μ] (hg : ConvexOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : (⨍ x, f x ∂μ, ⨍ x, g (f x) ∂μ) ∈ {p : E × ℝ | p.1 ∈ s ∧ g p.1 ≤ p.2} := by have ht_mem : ∀ᵐ x ∂μ, (f x, g (f x)) ∈ {p : E × ℝ | p.1 ∈ s ∧ g p.1 ≤ p.2} := hfs.mono fun x hx => ⟨hx, le_rfl⟩ exact average_pair hfi hgi ▸ hg.convex_epigraph.average_mem (hsc.epigraph hgc) ht_mem (hfi.prod_mk hgi) theorem ConcaveOn.average_mem_hypograph [IsFiniteMeasure μ] [NeZero μ] (hg : ConcaveOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : (⨍ x, f x ∂μ, ⨍ x, g (f x) ∂μ) ∈ {p : E × ℝ | p.1 ∈ s ∧ p.2 ≤ g p.1} := by simpa only [mem_setOf_eq, Pi.neg_apply, average_neg, neg_le_neg_iff] using hg.neg.average_mem_epigraph hgc.neg hsc hfs hfi hgi.neg /-- **Jensen's inequality**: if a function `g : E → ℝ` is convex and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points to `s`, then the value of `g` at the average value of `f` is less than or equal to the average value of `g ∘ f` provided that both `f` and `g ∘ f` are integrable. See also `ConvexOn.map_centerMass_le` for a finite sum version of this lemma. -/ theorem ConvexOn.map_average_le [IsFiniteMeasure μ] [NeZero μ] (hg : ConvexOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : g (⨍ x, f x ∂μ) ≤ ⨍ x, g (f x) ∂μ := (hg.average_mem_epigraph hgc hsc hfs hfi hgi).2 /-- **Jensen's inequality**: if a function `g : E → ℝ` is concave and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points to `s`, then the average value of `g ∘ f` is less than or equal to the value of `g` at the average value of `f` provided that both `f` and `g ∘ f` are integrable. See also `ConcaveOn.le_map_centerMass` for a finite sum version of this lemma. -/ theorem ConcaveOn.le_map_average [IsFiniteMeasure μ] [NeZero μ] (hg : ConcaveOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : (⨍ x, g (f x) ∂μ) ≤ g (⨍ x, f x ∂μ) := (hg.average_mem_hypograph hgc hsc hfs hfi hgi).2 /-- **Jensen's inequality**: if a function `g : E → ℝ` is convex and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points of a set `t` to `s`, then the value of `g` at the average value of `f` over `t` is less than or equal to the average value of `g ∘ f` over `t` provided that both `f` and `g ∘ f` are integrable. -/ theorem ConvexOn.set_average_mem_epigraph (hg : ConvexOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (h0 : μ t ≠ 0) (ht : μ t ≠ ∞) (hfs : ∀ᵐ x ∂μ.restrict t, f x ∈ s) (hfi : IntegrableOn f t μ) (hgi : IntegrableOn (g ∘ f) t μ) : (⨍ x in t, f x ∂μ, ⨍ x in t, g (f x) ∂μ) ∈ {p : E × ℝ | p.1 ∈ s ∧ g p.1 ≤ p.2} := have := Fact.mk ht.lt_top have := NeZero.mk h0 hg.average_mem_epigraph hgc hsc hfs hfi hgi /-- **Jensen's inequality**: if a function `g : E → ℝ` is concave and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points of a set `t` to `s`, then the average value of `g ∘ f` over `t` is less than or equal to the value of `g` at the average value of `f` over `t` provided that both `f` and `g ∘ f` are integrable. -/ theorem ConcaveOn.set_average_mem_hypograph (hg : ConcaveOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (h0 : μ t ≠ 0) (ht : μ t ≠ ∞) (hfs : ∀ᵐ x ∂μ.restrict t, f x ∈ s) (hfi : IntegrableOn f t μ) (hgi : IntegrableOn (g ∘ f) t μ) : (⨍ x in t, f x ∂μ, ⨍ x in t, g (f x) ∂μ) ∈ {p : E × ℝ | p.1 ∈ s ∧ p.2 ≤ g p.1} := by simpa only [mem_setOf_eq, Pi.neg_apply, average_neg, neg_le_neg_iff] using hg.neg.set_average_mem_epigraph hgc.neg hsc h0 ht hfs hfi hgi.neg /-- **Jensen's inequality**: if a function `g : E → ℝ` is convex and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points of a set `t` to `s`, then the value of `g` at the average value of `f` over `t` is less than or equal to the average value of `g ∘ f` over `t` provided that both `f` and `g ∘ f` are integrable. -/ theorem ConvexOn.map_set_average_le (hg : ConvexOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (h0 : μ t ≠ 0) (ht : μ t ≠ ∞) (hfs : ∀ᵐ x ∂μ.restrict t, f x ∈ s) (hfi : IntegrableOn f t μ) (hgi : IntegrableOn (g ∘ f) t μ) : g (⨍ x in t, f x ∂μ) ≤ ⨍ x in t, g (f x) ∂μ := (hg.set_average_mem_epigraph hgc hsc h0 ht hfs hfi hgi).2 /-- **Jensen's inequality**: if a function `g : E → ℝ` is concave and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points of a set `t` to `s`, then the average value of `g ∘ f` over `t` is less than or equal to the value of `g` at the average value of `f` over `t` provided that both `f` and `g ∘ f` are integrable. -/ theorem ConcaveOn.le_map_set_average (hg : ConcaveOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (h0 : μ t ≠ 0) (ht : μ t ≠ ∞) (hfs : ∀ᵐ x ∂μ.restrict t, f x ∈ s) (hfi : IntegrableOn f t μ) (hgi : IntegrableOn (g ∘ f) t μ) : (⨍ x in t, g (f x) ∂μ) ≤ g (⨍ x in t, f x ∂μ) := (hg.set_average_mem_hypograph hgc hsc h0 ht hfs hfi hgi).2 /-- **Jensen's inequality**: if a function `g : E → ℝ` is convex and continuous on a convex closed set `s`, `μ` is a probability measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points to `s`, then the value of `g` at the expected value of `f` is less than or equal to the expected value of `g ∘ f` provided that both `f` and `g ∘ f` are integrable. See also `ConvexOn.map_centerMass_le` for a finite sum version of this lemma. -/ theorem ConvexOn.map_integral_le [IsProbabilityMeasure μ] (hg : ConvexOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : g (∫ x, f x ∂μ) ≤ ∫ x, g (f x) ∂μ := by simpa only [average_eq_integral] using hg.map_average_le hgc hsc hfs hfi hgi /-- **Jensen's inequality**: if a function `g : E → ℝ` is concave and continuous on a convex closed set `s`, `μ` is a probability measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points to `s`, then the expected value of `g ∘ f` is less than or equal to the value of `g` at the expected value of `f` provided that both `f` and `g ∘ f` are integrable. -/ theorem ConcaveOn.le_map_integral [IsProbabilityMeasure μ] (hg : ConcaveOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : (∫ x, g (f x) ∂μ) ≤ g (∫ x, f x ∂μ) := by simpa only [average_eq_integral] using hg.le_map_average hgc hsc hfs hfi hgi /-! ### Strict Jensen's inequality -/ /-- If `f : α → E` is an integrable function, then either it is a.e. equal to the constant `⨍ x, f x ∂μ` or there exists a measurable set such that `μ t ≠ 0`, `μ tᶜ ≠ 0`, and the average values of `f` over `t` and `tᶜ` are different. -/ theorem ae_eq_const_or_exists_average_ne_compl [IsFiniteMeasure μ] (hfi : Integrable f μ) : f =ᵐ[μ] const α (⨍ x, f x ∂μ) ∨ ∃ t, MeasurableSet t ∧ μ t ≠ 0 ∧ μ tᶜ ≠ 0 ∧ (⨍ x in t, f x ∂μ) ≠ ⨍ x in tᶜ, f x ∂μ := by refine or_iff_not_imp_right.mpr fun H => ?_; push_neg at H refine hfi.ae_eq_of_forall_setIntegral_eq _ _ (integrable_const _) fun t ht ht' => ?_; clear ht' simp only [const_apply, setIntegral_const] by_cases h₀ : μ t = 0 · rw [restrict_eq_zero.2 h₀, integral_zero_measure, h₀, ENNReal.zero_toReal, zero_smul] by_cases h₀' : μ tᶜ = 0 · rw [← ae_eq_univ] at h₀' rw [restrict_congr_set h₀', restrict_univ, measure_congr h₀', measure_smul_average] have := average_mem_openSegment_compl_self ht.nullMeasurableSet h₀ h₀' hfi rw [← H t ht h₀ h₀', openSegment_same, mem_singleton_iff] at this rw [this, measure_smul_setAverage _ (measure_ne_top μ _)] /-- If an integrable function `f : α → E` takes values in a convex set `s` and for some set `t` of positive measure, the average value of `f` over `t` belongs to the interior of `s`, then the average of `f` over the whole space belongs to the interior of `s`. -/ theorem Convex.average_mem_interior_of_set [IsFiniteMeasure μ] (hs : Convex ℝ s) (h0 : μ t ≠ 0) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (ht : (⨍ x in t, f x ∂μ) ∈ interior s) : (⨍ x, f x ∂μ) ∈ interior s := by rw [← measure_toMeasurable] at h0; rw [← restrict_toMeasurable (measure_ne_top μ t)] at ht by_cases h0' : μ (toMeasurable μ t)ᶜ = 0 · rw [← ae_eq_univ] at h0' rwa [restrict_congr_set h0', restrict_univ] at ht exact hs.openSegment_interior_closure_subset_interior ht (hs.set_average_mem_closure h0' (measure_ne_top _ _) (ae_restrict_of_ae hfs) hfi.integrableOn) (average_mem_openSegment_compl_self (measurableSet_toMeasurable μ t).nullMeasurableSet h0 h0' hfi) /-- If an integrable function `f : α → E` takes values in a strictly convex closed set `s`, then either it is a.e. equal to its average value, or its average value belongs to the interior of `s`. -/ theorem StrictConvex.ae_eq_const_or_average_mem_interior [IsFiniteMeasure μ] (hs : StrictConvex ℝ s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) : f =ᵐ[μ] const α (⨍ x, f x ∂μ) ∨ (⨍ x, f x ∂μ) ∈ interior s := by have : ∀ {t}, μ t ≠ 0 → (⨍ x in t, f x ∂μ) ∈ s := fun ht => hs.convex.set_average_mem hsc ht (measure_ne_top _ _) (ae_restrict_of_ae hfs) hfi.integrableOn refine (ae_eq_const_or_exists_average_ne_compl hfi).imp_right ?_ rintro ⟨t, hm, h₀, h₀', hne⟩ exact hs.openSegment_subset (this h₀) (this h₀') hne (average_mem_openSegment_compl_self hm.nullMeasurableSet h₀ h₀' hfi) /-- **Jensen's inequality**, strict version: if an integrable function `f : α → E` takes values in a convex closed set `s`, and `g : E → ℝ` is continuous and strictly convex on `s`, then either `f` is a.e. equal to its average value, or `g (⨍ x, f x ∂μ) < ⨍ x, g (f x) ∂μ`. -/ theorem StrictConvexOn.ae_eq_const_or_map_average_lt [IsFiniteMeasure μ] (hg : StrictConvexOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : f =ᵐ[μ] const α (⨍ x, f x ∂μ) ∨ g (⨍ x, f x ∂μ) < ⨍ x, g (f x) ∂μ := by have : ∀ {t}, μ t ≠ 0 → (⨍ x in t, f x ∂μ) ∈ s ∧ g (⨍ x in t, f x ∂μ) ≤ ⨍ x in t, g (f x) ∂μ := fun ht => hg.convexOn.set_average_mem_epigraph hgc hsc ht (measure_ne_top _ _) (ae_restrict_of_ae hfs) hfi.integrableOn hgi.integrableOn refine (ae_eq_const_or_exists_average_ne_compl hfi).imp_right ?_ rintro ⟨t, hm, h₀, h₀', hne⟩ rcases average_mem_openSegment_compl_self hm.nullMeasurableSet h₀ h₀' (hfi.prod_mk hgi) with ⟨a, b, ha, hb, hab, h_avg⟩ rw [average_pair hfi hgi, average_pair hfi.integrableOn hgi.integrableOn, average_pair hfi.integrableOn hgi.integrableOn, Prod.smul_mk, Prod.smul_mk, Prod.mk_add_mk, Prod.mk.inj_iff] at h_avg simp only [Function.comp] at h_avg rw [← h_avg.1, ← h_avg.2] calc g ((a • ⨍ x in t, f x ∂μ) + b • ⨍ x in tᶜ, f x ∂μ) < a * g (⨍ x in t, f x ∂μ) + b * g (⨍ x in tᶜ, f x ∂μ) := hg.2 (this h₀).1 (this h₀').1 hne ha hb hab _ ≤ (a * ⨍ x in t, g (f x) ∂μ) + b * ⨍ x in tᶜ, g (f x) ∂μ := add_le_add (mul_le_mul_of_nonneg_left (this h₀).2 ha.le) (mul_le_mul_of_nonneg_left (this h₀').2 hb.le) /-- **Jensen's inequality**, strict version: if an integrable function `f : α → E` takes values in a convex closed set `s`, and `g : E → ℝ` is continuous and strictly concave on `s`, then either `f` is a.e. equal to its average value, or `⨍ x, g (f x) ∂μ < g (⨍ x, f x ∂μ)`. -/ theorem StrictConcaveOn.ae_eq_const_or_lt_map_average [IsFiniteMeasure μ] (hg : StrictConcaveOn ℝ s g) (hgc : ContinuousOn g s) (hsc : IsClosed s) (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : Integrable f μ) (hgi : Integrable (g ∘ f) μ) : f =ᵐ[μ] const α (⨍ x, f x ∂μ) ∨ (⨍ x, g (f x) ∂μ) < g (⨍ x, f x ∂μ) := by simpa only [Pi.neg_apply, average_neg, neg_lt_neg_iff] using hg.neg.ae_eq_const_or_map_average_lt hgc.neg hsc hfs hfi hgi.neg /-- If `E` is a strictly convex normed space and `f : α → E` is a function such that `‖f x‖ ≤ C` a.e., then either this function is a.e. equal to its average value, or the norm of its average value is strictly less than `C`. -/ theorem ae_eq_const_or_norm_average_lt_of_norm_le_const [StrictConvexSpace ℝ E] (h_le : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : f =ᵐ[μ] const α (⨍ x, f x ∂μ) ∨ ‖⨍ x, f x ∂μ‖ < C := by rcases le_or_lt C 0 with hC0 | hC0 · have : f =ᵐ[μ] 0 := h_le.mono fun x hx => norm_le_zero_iff.1 (hx.trans hC0) simp only [average_congr this, Pi.zero_apply, average_zero] exact Or.inl this by_cases hfi : Integrable f μ; swap · simp [average_eq, integral_undef hfi, hC0, ENNReal.toReal_pos_iff] rcases (le_top : μ univ ≤ ∞).eq_or_lt with hμt | hμt; · simp [average_eq, hμt, hC0] haveI : IsFiniteMeasure μ := ⟨hμt⟩ replace h_le : ∀ᵐ x ∂μ, f x ∈ closedBall (0 : E) C := by simpa only [mem_closedBall_zero_iff] simpa only [interior_closedBall _ hC0.ne', mem_ball_zero_iff] using (strictConvex_closedBall ℝ (0 : E) C).ae_eq_const_or_average_mem_interior isClosed_ball h_le hfi /-- If `E` is a strictly convex normed space and `f : α → E` is a function such that `‖f x‖ ≤ C` a.e., then either this function is a.e. equal to its average value, or the norm of its integral is strictly less than `(μ univ).toReal * C`. -/ theorem ae_eq_const_or_norm_integral_lt_of_norm_le_const [StrictConvexSpace ℝ E] [IsFiniteMeasure μ] (h_le : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : f =ᵐ[μ] const α (⨍ x, f x ∂μ) ∨ ‖∫ x, f x ∂μ‖ < (μ univ).toReal * C := by rcases eq_or_ne μ 0 with h₀ | h₀; · left; simp [h₀, EventuallyEq] have hμ : 0 < (μ univ).toReal := by simp [ENNReal.toReal_pos_iff, pos_iff_ne_zero, h₀, measure_lt_top] refine (ae_eq_const_or_norm_average_lt_of_norm_le_const h_le).imp_right fun H => ?_ rwa [average_eq, norm_smul, norm_inv, Real.norm_eq_abs, abs_of_pos hμ, ← div_eq_inv_mul, div_lt_iff' hμ] at H /-- If `E` is a strictly convex normed space and `f : α → E` is a function such that `‖f x‖ ≤ C` a.e. on a set `t` of finite measure, then either this function is a.e. equal to its average value on `t`, or the norm of its integral over `t` is strictly less than `(μ t).toReal * C`. -/ theorem ae_eq_const_or_norm_setIntegral_lt_of_norm_le_const [StrictConvexSpace ℝ E] (ht : μ t ≠ ∞) (h_le : ∀ᵐ x ∂μ.restrict t, ‖f x‖ ≤ C) : f =ᵐ[μ.restrict t] const α (⨍ x in t, f x ∂μ) ∨ ‖∫ x in t, f x ∂μ‖ < (μ t).toReal * C := by haveI := Fact.mk ht.lt_top rw [← restrict_apply_univ] exact ae_eq_const_or_norm_integral_lt_of_norm_le_const h_le @[deprecated (since := "2024-04-17")] alias ae_eq_const_or_norm_set_integral_lt_of_norm_le_const := ae_eq_const_or_norm_setIntegral_lt_of_norm_le_const
Analysis\Convex\Intrinsic.lean
/- Copyright (c) 2023 Paul Reichert. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul Reichert, Yaël Dillies -/ import Mathlib.Analysis.NormedSpace.AddTorsorBases /-! # Intrinsic frontier and interior This file defines the intrinsic frontier, interior and closure of a set in a normed additive torsor. These are also known as relative frontier, interior, closure. The intrinsic frontier/interior/closure of a set `s` is the frontier/interior/closure of `s` considered as a set in its affine span. The intrinsic interior is in general greater than the topological interior, the intrinsic frontier in general less than the topological frontier, and the intrinsic closure in cases of interest the same as the topological closure. ## Definitions * `intrinsicInterior`: Intrinsic interior * `intrinsicFrontier`: Intrinsic frontier * `intrinsicClosure`: Intrinsic closure ## Results The main results are: * `AffineIsometry.image_intrinsicInterior`/`AffineIsometry.image_intrinsicFrontier`/ `AffineIsometry.image_intrinsicClosure`: Intrinsic interiors/frontiers/closures commute with taking the image under an affine isometry. * `Set.Nonempty.intrinsicInterior`: The intrinsic interior of a nonempty convex set is nonempty. ## References * Chapter 8 of [Barry Simon, *Convexity*][simon2011] * Chapter 1 of [Rolf Schneider, *Convex Bodies: The Brunn-Minkowski theory*][schneider2013]. ## TODO * `IsClosed s → IsExtreme 𝕜 s (intrinsicFrontier 𝕜 s)` * `x ∈ s → y ∈ intrinsicInterior 𝕜 s → openSegment 𝕜 x y ⊆ intrinsicInterior 𝕜 s` -/ open AffineSubspace Set open scoped Pointwise variable {𝕜 V W Q P : Type*} section AddTorsor variable (𝕜) [Ring 𝕜] [AddCommGroup V] [Module 𝕜 V] [TopologicalSpace P] [AddTorsor V P] {s t : Set P} {x : P} /-- The intrinsic interior of a set is its interior considered as a set in its affine span. -/ def intrinsicInterior (s : Set P) : Set P := (↑) '' interior ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) /-- The intrinsic frontier of a set is its frontier considered as a set in its affine span. -/ def intrinsicFrontier (s : Set P) : Set P := (↑) '' frontier ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) /-- The intrinsic closure of a set is its closure considered as a set in its affine span. -/ def intrinsicClosure (s : Set P) : Set P := (↑) '' closure ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) variable {𝕜} @[simp] theorem mem_intrinsicInterior : x ∈ intrinsicInterior 𝕜 s ↔ ∃ y, y ∈ interior ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) ∧ ↑y = x := mem_image _ _ _ @[simp] theorem mem_intrinsicFrontier : x ∈ intrinsicFrontier 𝕜 s ↔ ∃ y, y ∈ frontier ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) ∧ ↑y = x := mem_image _ _ _ @[simp] theorem mem_intrinsicClosure : x ∈ intrinsicClosure 𝕜 s ↔ ∃ y, y ∈ closure ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s) ∧ ↑y = x := mem_image _ _ _ theorem intrinsicInterior_subset : intrinsicInterior 𝕜 s ⊆ s := image_subset_iff.2 interior_subset theorem intrinsicFrontier_subset (hs : IsClosed s) : intrinsicFrontier 𝕜 s ⊆ s := image_subset_iff.2 (hs.preimage continuous_induced_dom).frontier_subset theorem intrinsicFrontier_subset_intrinsicClosure : intrinsicFrontier 𝕜 s ⊆ intrinsicClosure 𝕜 s := image_subset _ frontier_subset_closure theorem subset_intrinsicClosure : s ⊆ intrinsicClosure 𝕜 s := fun x hx => ⟨⟨x, subset_affineSpan _ _ hx⟩, subset_closure hx, rfl⟩ @[simp] theorem intrinsicInterior_empty : intrinsicInterior 𝕜 (∅ : Set P) = ∅ := by simp [intrinsicInterior] @[simp] theorem intrinsicFrontier_empty : intrinsicFrontier 𝕜 (∅ : Set P) = ∅ := by simp [intrinsicFrontier] @[simp] theorem intrinsicClosure_empty : intrinsicClosure 𝕜 (∅ : Set P) = ∅ := by simp [intrinsicClosure] @[simp] theorem intrinsicClosure_nonempty : (intrinsicClosure 𝕜 s).Nonempty ↔ s.Nonempty := ⟨by simp_rw [nonempty_iff_ne_empty]; rintro h rfl; exact h intrinsicClosure_empty, Nonempty.mono subset_intrinsicClosure⟩ alias ⟨Set.Nonempty.ofIntrinsicClosure, Set.Nonempty.intrinsicClosure⟩ := intrinsicClosure_nonempty --attribute [protected] Set.Nonempty.intrinsicClosure -- Porting note: removed @[simp] theorem intrinsicInterior_singleton (x : P) : intrinsicInterior 𝕜 ({x} : Set P) = {x} := by simpa only [intrinsicInterior, preimage_coe_affineSpan_singleton, interior_univ, image_univ, Subtype.range_coe] using coe_affineSpan_singleton _ _ _ @[simp] theorem intrinsicFrontier_singleton (x : P) : intrinsicFrontier 𝕜 ({x} : Set P) = ∅ := by rw [intrinsicFrontier, preimage_coe_affineSpan_singleton, frontier_univ, image_empty] @[simp] theorem intrinsicClosure_singleton (x : P) : intrinsicClosure 𝕜 ({x} : Set P) = {x} := by simpa only [intrinsicClosure, preimage_coe_affineSpan_singleton, closure_univ, image_univ, Subtype.range_coe] using coe_affineSpan_singleton _ _ _ /-! Note that neither `intrinsicInterior` nor `intrinsicFrontier` is monotone. -/ theorem intrinsicClosure_mono (h : s ⊆ t) : intrinsicClosure 𝕜 s ⊆ intrinsicClosure 𝕜 t := by refine image_subset_iff.2 fun x hx => ?_ refine ⟨Set.inclusion (affineSpan_mono _ h) x, ?_, rfl⟩ refine (continuous_inclusion (affineSpan_mono _ h)).closure_preimage_subset _ (closure_mono ?_ hx) exact fun y hy => h hy theorem interior_subset_intrinsicInterior : interior s ⊆ intrinsicInterior 𝕜 s := fun x hx => ⟨⟨x, subset_affineSpan _ _ <| interior_subset hx⟩, preimage_interior_subset_interior_preimage continuous_subtype_val hx, rfl⟩ theorem intrinsicClosure_subset_closure : intrinsicClosure 𝕜 s ⊆ closure s := image_subset_iff.2 <| continuous_subtype_val.closure_preimage_subset _ theorem intrinsicFrontier_subset_frontier : intrinsicFrontier 𝕜 s ⊆ frontier s := image_subset_iff.2 <| continuous_subtype_val.frontier_preimage_subset _ theorem intrinsicClosure_subset_affineSpan : intrinsicClosure 𝕜 s ⊆ affineSpan 𝕜 s := (image_subset_range _ _).trans Subtype.range_coe.subset @[simp] theorem intrinsicClosure_diff_intrinsicFrontier (s : Set P) : intrinsicClosure 𝕜 s \ intrinsicFrontier 𝕜 s = intrinsicInterior 𝕜 s := (image_diff Subtype.coe_injective _ _).symm.trans <| by rw [closure_diff_frontier, intrinsicInterior] @[simp] theorem intrinsicClosure_diff_intrinsicInterior (s : Set P) : intrinsicClosure 𝕜 s \ intrinsicInterior 𝕜 s = intrinsicFrontier 𝕜 s := (image_diff Subtype.coe_injective _ _).symm @[simp] theorem intrinsicInterior_union_intrinsicFrontier (s : Set P) : intrinsicInterior 𝕜 s ∪ intrinsicFrontier 𝕜 s = intrinsicClosure 𝕜 s := by simp [intrinsicClosure, intrinsicInterior, intrinsicFrontier, closure_eq_interior_union_frontier, image_union] @[simp] theorem intrinsicFrontier_union_intrinsicInterior (s : Set P) : intrinsicFrontier 𝕜 s ∪ intrinsicInterior 𝕜 s = intrinsicClosure 𝕜 s := by rw [union_comm, intrinsicInterior_union_intrinsicFrontier] theorem isClosed_intrinsicClosure (hs : IsClosed (affineSpan 𝕜 s : Set P)) : IsClosed (intrinsicClosure 𝕜 s) := (closedEmbedding_subtype_val hs).isClosedMap _ isClosed_closure theorem isClosed_intrinsicFrontier (hs : IsClosed (affineSpan 𝕜 s : Set P)) : IsClosed (intrinsicFrontier 𝕜 s) := (closedEmbedding_subtype_val hs).isClosedMap _ isClosed_frontier @[simp] theorem affineSpan_intrinsicClosure (s : Set P) : affineSpan 𝕜 (intrinsicClosure 𝕜 s) = affineSpan 𝕜 s := (affineSpan_le.2 intrinsicClosure_subset_affineSpan).antisymm <| affineSpan_mono _ subset_intrinsicClosure protected theorem IsClosed.intrinsicClosure (hs : IsClosed ((↑) ⁻¹' s : Set <| affineSpan 𝕜 s)) : intrinsicClosure 𝕜 s = s := by rw [intrinsicClosure, hs.closure_eq, image_preimage_eq_of_subset] exact (subset_affineSpan _ _).trans Subtype.range_coe.superset @[simp] theorem intrinsicClosure_idem (s : Set P) : intrinsicClosure 𝕜 (intrinsicClosure 𝕜 s) = intrinsicClosure 𝕜 s := by refine IsClosed.intrinsicClosure ?_ set t := affineSpan 𝕜 (intrinsicClosure 𝕜 s) with ht clear_value t obtain rfl := ht.trans (affineSpan_intrinsicClosure _) rw [intrinsicClosure, preimage_image_eq _ Subtype.coe_injective] exact isClosed_closure end AddTorsor namespace AffineIsometry variable [NormedField 𝕜] [SeminormedAddCommGroup V] [SeminormedAddCommGroup W] [NormedSpace 𝕜 V] [NormedSpace 𝕜 W] [MetricSpace P] [PseudoMetricSpace Q] [NormedAddTorsor V P] [NormedAddTorsor W Q] -- Porting note: Removed attribute `local nolint fails_quickly` attribute [local instance] AffineSubspace.toNormedAddTorsor AffineSubspace.nonempty_map @[simp] theorem image_intrinsicInterior (φ : P →ᵃⁱ[𝕜] Q) (s : Set P) : intrinsicInterior 𝕜 (φ '' s) = φ '' intrinsicInterior 𝕜 s := by obtain rfl | hs := s.eq_empty_or_nonempty · simp only [intrinsicInterior_empty, image_empty] haveI : Nonempty s := hs.to_subtype let f := ((affineSpan 𝕜 s).isometryEquivMap φ).toHomeomorph have : φ.toAffineMap ∘ (↑) ∘ f.symm = (↑) := funext isometryEquivMap.apply_symm_apply rw [intrinsicInterior, intrinsicInterior, ← φ.coe_toAffineMap, ← map_span φ.toAffineMap s, ← this, ← Function.comp.assoc, image_comp, image_comp, f.symm.image_interior, f.image_symm, ← preimage_comp, Function.comp.assoc, f.symm_comp_self, AffineIsometry.coe_toAffineMap, Function.comp_id, preimage_comp, φ.injective.preimage_image] @[simp] theorem image_intrinsicFrontier (φ : P →ᵃⁱ[𝕜] Q) (s : Set P) : intrinsicFrontier 𝕜 (φ '' s) = φ '' intrinsicFrontier 𝕜 s := by obtain rfl | hs := s.eq_empty_or_nonempty · simp haveI : Nonempty s := hs.to_subtype let f := ((affineSpan 𝕜 s).isometryEquivMap φ).toHomeomorph have : φ.toAffineMap ∘ (↑) ∘ f.symm = (↑) := funext isometryEquivMap.apply_symm_apply rw [intrinsicFrontier, intrinsicFrontier, ← φ.coe_toAffineMap, ← map_span φ.toAffineMap s, ← this, ← Function.comp.assoc, image_comp, image_comp, f.symm.image_frontier, f.image_symm, ← preimage_comp, Function.comp.assoc, f.symm_comp_self, AffineIsometry.coe_toAffineMap, Function.comp_id, preimage_comp, φ.injective.preimage_image] @[simp] theorem image_intrinsicClosure (φ : P →ᵃⁱ[𝕜] Q) (s : Set P) : intrinsicClosure 𝕜 (φ '' s) = φ '' intrinsicClosure 𝕜 s := by obtain rfl | hs := s.eq_empty_or_nonempty · simp haveI : Nonempty s := hs.to_subtype let f := ((affineSpan 𝕜 s).isometryEquivMap φ).toHomeomorph have : φ.toAffineMap ∘ (↑) ∘ f.symm = (↑) := funext isometryEquivMap.apply_symm_apply rw [intrinsicClosure, intrinsicClosure, ← φ.coe_toAffineMap, ← map_span φ.toAffineMap s, ← this, ← Function.comp.assoc, image_comp, image_comp, f.symm.image_closure, f.image_symm, ← preimage_comp, Function.comp.assoc, f.symm_comp_self, AffineIsometry.coe_toAffineMap, Function.comp_id, preimage_comp, φ.injective.preimage_image] end AffineIsometry section NormedAddTorsor variable (𝕜) [NontriviallyNormedField 𝕜] [CompleteSpace 𝕜] [NormedAddCommGroup V] [NormedSpace 𝕜 V] [FiniteDimensional 𝕜 V] [MetricSpace P] [NormedAddTorsor V P] (s : Set P) @[simp] theorem intrinsicClosure_eq_closure : intrinsicClosure 𝕜 s = closure s := by ext x simp only [mem_closure_iff, mem_intrinsicClosure] refine ⟨?_, fun h => ⟨⟨x, _⟩, ?_, Subtype.coe_mk _ ?_⟩⟩ · rintro ⟨x, h, rfl⟩ t ht hx obtain ⟨z, hz₁, hz₂⟩ := h _ (continuous_induced_dom.isOpen_preimage t ht) hx exact ⟨z, hz₁, hz₂⟩ · rintro _ ⟨t, ht, rfl⟩ hx obtain ⟨y, hyt, hys⟩ := h _ ht hx exact ⟨⟨_, subset_affineSpan 𝕜 s hys⟩, hyt, hys⟩ · by_contra hc obtain ⟨z, hz₁, hz₂⟩ := h _ (affineSpan 𝕜 s).closed_of_finiteDimensional.isOpen_compl hc exact hz₁ (subset_affineSpan 𝕜 s hz₂) variable {𝕜} @[simp] theorem closure_diff_intrinsicInterior (s : Set P) : closure s \ intrinsicInterior 𝕜 s = intrinsicFrontier 𝕜 s := intrinsicClosure_eq_closure 𝕜 s ▸ intrinsicClosure_diff_intrinsicInterior s @[simp] theorem closure_diff_intrinsicFrontier (s : Set P) : closure s \ intrinsicFrontier 𝕜 s = intrinsicInterior 𝕜 s := intrinsicClosure_eq_closure 𝕜 s ▸ intrinsicClosure_diff_intrinsicFrontier s end NormedAddTorsor private theorem aux {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] (φ : α ≃ₜ β) (s : Set β) : (interior s).Nonempty ↔ (interior (φ ⁻¹' s)).Nonempty := by rw [← φ.image_symm, ← φ.symm.image_interior, image_nonempty] variable [NormedAddCommGroup V] [NormedSpace ℝ V] [FiniteDimensional ℝ V] {s : Set V} /-- The intrinsic interior of a nonempty convex set is nonempty. -/ protected theorem Set.Nonempty.intrinsicInterior (hscv : Convex ℝ s) (hsne : s.Nonempty) : (intrinsicInterior ℝ s).Nonempty := by haveI := hsne.coe_sort obtain ⟨p, hp⟩ := hsne let p' : _root_.affineSpan ℝ s := ⟨p, subset_affineSpan _ _ hp⟩ rw [intrinsicInterior, image_nonempty, aux (AffineIsometryEquiv.constVSub ℝ p').symm.toHomeomorph, Convex.interior_nonempty_iff_affineSpan_eq_top, AffineIsometryEquiv.coe_toHomeomorph, ← AffineIsometryEquiv.coe_toAffineEquiv, ← comap_span, affineSpan_coe_preimage_eq_top, comap_top] exact hscv.affine_preimage ((_root_.affineSpan ℝ s).subtype.comp (AffineIsometryEquiv.constVSub ℝ p').symm.toAffineEquiv.toAffineMap) theorem intrinsicInterior_nonempty (hs : Convex ℝ s) : (intrinsicInterior ℝ s).Nonempty ↔ s.Nonempty := ⟨by simp_rw [nonempty_iff_ne_empty]; rintro h rfl; exact h intrinsicInterior_empty, Set.Nonempty.intrinsicInterior hs⟩
Analysis\Convex\Jensen.lean
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp /-! # Jensen's inequality and maximum principle for convex functions In this file, we prove the finite Jensen inequality and the finite maximum principle for convex functions. The integral versions are to be found in `Analysis.Convex.Integral`. ## Main declarations Jensen's inequalities: * `ConvexOn.map_centerMass_le`, `ConvexOn.map_sum_le`: Convex Jensen's inequality. The image of a convex combination of points under a convex function is less than the convex combination of the images. * `ConcaveOn.le_map_centerMass`, `ConcaveOn.le_map_sum`: Concave Jensen's inequality. * `StrictConvexOn.map_sum_lt`: Convex strict Jensen inequality. * `StrictConcaveOn.lt_map_sum`: Concave strict Jensen inequality. As corollaries, we get: * `StrictConvexOn.map_sum_eq_iff`: Equality case of the convex Jensen inequality. * `StrictConcaveOn.map_sum_eq_iff`: Equality case of the concave Jensen inequality. * `ConvexOn.exists_ge_of_mem_convexHull`: Maximum principle for convex functions. * `ConcaveOn.exists_le_of_mem_convexHull`: Minimum principle for concave functions. -/ open Finset LinearMap Set open scoped Classical open Convex Pointwise variable {𝕜 E F β ι : Type*} /-! ### Jensen's inequality -/ section Jensen variable [LinearOrderedField 𝕜] [AddCommGroup E] [OrderedAddCommGroup β] [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} {t : Finset ι} {w : ι → 𝕜} {p : ι → E} {v : 𝕜} {q : E} /-- Convex **Jensen's inequality**, `Finset.centerMass` version. -/ theorem ConvexOn.map_centerMass_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : 0 < ∑ i ∈ t, w i) (hmem : ∀ i ∈ t, p i ∈ s) : f (t.centerMass w p) ≤ t.centerMass w (f ∘ p) := by have hmem' : ∀ i ∈ t, (p i, (f ∘ p) i) ∈ { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := fun i hi => ⟨hmem i hi, le_rfl⟩ convert (hf.convex_epigraph.centerMass_mem h₀ h₁ hmem').2 <;> simp only [centerMass, Function.comp, Prod.smul_fst, Prod.fst_sum, Prod.smul_snd, Prod.snd_sum] /-- Concave **Jensen's inequality**, `Finset.centerMass` version. -/ theorem ConcaveOn.le_map_centerMass (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : 0 < ∑ i ∈ t, w i) (hmem : ∀ i ∈ t, p i ∈ s) : t.centerMass w (f ∘ p) ≤ f (t.centerMass w p) := ConvexOn.map_centerMass_le (β := βᵒᵈ) hf h₀ h₁ hmem /-- Convex **Jensen's inequality**, `Finset.sum` version. -/ theorem ConvexOn.map_sum_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) ≤ ∑ i ∈ t, w i • f (p i) := by simpa only [centerMass, h₁, inv_one, one_smul] using hf.map_centerMass_le h₀ (h₁.symm ▸ zero_lt_one) hmem /-- Concave **Jensen's inequality**, `Finset.sum` version. -/ theorem ConcaveOn.le_map_sum (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : (∑ i ∈ t, w i • f (p i)) ≤ f (∑ i ∈ t, w i • p i) := ConvexOn.map_sum_le (β := βᵒᵈ) hf h₀ h₁ hmem /-- Convex **Jensen's inequality** where an element plays a distinguished role. -/ lemma ConvexOn.map_add_sum_le (hf : ConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : v + ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hv : 0 ≤ v) (hq : q ∈ s) : f (v • q + ∑ i ∈ t, w i • p i) ≤ v • f q + ∑ i ∈ t, w i • f (p i) := by let W j := Option.elim j v w let P j := Option.elim j q p have : f (∑ j ∈ insertNone t, W j • P j) ≤ ∑ j ∈ insertNone t, W j • f (P j) := hf.map_sum_le (forall_mem_insertNone.2 ⟨hv, h₀⟩) (by simpa using h₁) (forall_mem_insertNone.2 ⟨hq, hmem⟩) simpa using this /-- Concave **Jensen's inequality** where an element plays a distinguished role. -/ lemma ConcaveOn.map_add_sum_le (hf : ConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : v + ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hv : 0 ≤ v) (hq : q ∈ s) : v • f q + ∑ i ∈ t, w i • f (p i) ≤ f (v • q + ∑ i ∈ t, w i • p i) := hf.dual.map_add_sum_le h₀ h₁ hmem hv hq /-! ### Strict Jensen inequality -/ /-- Convex **strict Jensen inequality**. If the function is strictly convex, the weights are strictly positive and the indexed family of points is non-constant, then Jensen's inequality is strict. See also `StrictConvexOn.map_sum_eq_iff`. -/ lemma StrictConvexOn.map_sum_lt (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hp : ∃ j ∈ t, ∃ k ∈ t, p j ≠ p k) : f (∑ i ∈ t, w i • p i) < ∑ i ∈ t, w i • f (p i) := by classical obtain ⟨j, hj, k, hk, hjk⟩ := hp -- We replace `t` by `t \ {j, k}` have : k ∈ t.erase j := mem_erase.2 ⟨ne_of_apply_ne _ hjk.symm, hk⟩ let u := (t.erase j).erase k have hj : j ∉ u := by simp [u] have hk : k ∉ u := by simp [u] have ht : t = (u.cons k hk).cons j (mem_cons.not.2 <| not_or_intro (ne_of_apply_ne _ hjk) hj) := by simp [insert_erase this, insert_erase ‹j ∈ t›, *] clear_value u subst ht simp only [sum_cons] have := h₀ j <| by simp have := h₀ k <| by simp let c := w j + w k have hc : w j / c + w k / c = 1 := by field_simp have hcj : c * (w j / c) = w j := by field_simp have hck : c * (w k / c) = w k := by field_simp calc f (w j • p j + (w k • p k + ∑ x ∈ u, w x • p x)) _ = f (c • ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • p x) := by rw [smul_add, ← mul_smul, ← mul_smul, hcj, hck, add_assoc] _ ≤ c • f ((w j / c) • p j + (w k / c) • p k) + ∑ x ∈ u, w x • f (p x) := -- apply the usual Jensen's inequality wrt the weighted average of the two distinguished -- points and all the other points hf.convexOn.map_add_sum_le (fun i hi ↦ (h₀ _ <| by simp [hi]).le) (by simpa [-cons_eq_insert, ← add_assoc] using h₁) (forall_of_forall_cons <| forall_of_forall_cons hmem) (by positivity) <| by refine hf.1 (hmem _ <| by simp) (hmem _ <| by simp) ?_ ?_ hc <;> positivity _ < c • ((w j / c) • f (p j) + (w k / c) • f (p k)) + ∑ x ∈ u, w x • f (p x) := by -- then apply the definition of strict convexity for the two distinguished points gcongr; refine hf.2 (hmem _ <| by simp) (hmem _ <| by simp) hjk ?_ ?_ hc <;> positivity _ = (w j • f (p j) + w k • f (p k)) + ∑ x ∈ u, w x • f (p x) := by rw [smul_add, ← mul_smul, ← mul_smul, hcj, hck] _ = w j • f (p j) + (w k • f (p k) + ∑ x ∈ u, w x • f (p x)) := by abel_nf /-- Concave **strict Jensen inequality**. If the function is strictly concave, the weights are strictly positive and the indexed family of points is non-constant, then Jensen's inequality is strict. See also `StrictConcaveOn.map_sum_eq_iff`. -/ lemma StrictConcaveOn.lt_map_sum (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (hp : ∃ j ∈ t, ∃ k ∈ t, p j ≠ p k) : ∑ i ∈ t, w i • f (p i) < f (∑ i ∈ t, w i • p i) := hf.dual.map_sum_lt h₀ h₁ hmem hp /-! ### Equality case of Jensen's inequality -/ /-- A form of the **equality case of Jensen's equality**. For a strictly convex function `f` and positive weights `w`, if `f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)`, then the points `p` are all equal. See also `StrictConvexOn.map_sum_eq_iff`. -/ lemma StrictConvexOn.eq_of_le_map_sum (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (h_eq : ∑ i ∈ t, w i • f (p i) ≤ f (∑ i ∈ t, w i • p i)) : ∀ ⦃j⦄, j ∈ t → ∀ ⦃k⦄, k ∈ t → p j = p k := by by_contra!; exact h_eq.not_lt <| hf.map_sum_lt h₀ h₁ hmem this /-- A form of the **equality case of Jensen's equality**. For a strictly concave function `f` and positive weights `w`, if `f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)`, then the points `p` are all equal. See also `StrictConcaveOn.map_sum_eq_iff`. -/ lemma StrictConcaveOn.eq_of_map_sum_eq (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) (h_eq : f (∑ i ∈ t, w i • p i) ≤ ∑ i ∈ t, w i • f (p i)) : ∀ ⦃j⦄, j ∈ t → ∀ ⦃k⦄, k ∈ t → p j = p k := by by_contra!; exact h_eq.not_lt <| hf.lt_map_sum h₀ h₁ hmem this /-- Canonical form of the **equality case of Jensen's equality**. For a strictly convex function `f` and positive weights `w`, we have `f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` are all equal (and in fact all equal to their center of mass wrt `w`). -/ lemma StrictConvexOn.map_sum_eq_iff {w : ι → 𝕜} {p : ι → E} (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔ ∀ j ∈ t, p j = ∑ i ∈ t, w i • p i := by constructor · obtain rfl | ⟨i₀, hi₀⟩ := t.eq_empty_or_nonempty · simp intro h_eq i hi have H : ∀ j ∈ t, p j = p i₀ := by intro j hj apply hf.eq_of_le_map_sum h₀ h₁ hmem h_eq.ge hj hi₀ calc p i = p i₀ := by rw [H _ hi] _ = (1 : 𝕜) • p i₀ := by simp _ = (∑ j ∈ t, w j) • p i₀ := by rw [h₁] _ = ∑ j ∈ t, (w j • p i₀) := by rw [sum_smul] _ = ∑ j ∈ t, (w j • p j) := by congr! 2 with j hj; rw [← H _ hj] · intro h have H : ∀ j ∈ t, w j • f (p j) = w j • f (∑ i ∈ t, w i • p i) := by intro j hj simp [h j hj] rw [sum_congr rfl H, ← sum_smul, h₁, one_smul] /-- Canonical form of the **equality case of Jensen's equality**. For a strictly concave function `f` and positive weights `w`, we have `f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` are all equal (and in fact all equal to their center of mass wrt `w`). -/ lemma StrictConcaveOn.map_sum_eq_iff (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 < w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔ ∀ j ∈ t, p j = ∑ i ∈ t, w i • p i := by simpa using hf.neg.map_sum_eq_iff h₀ h₁ hmem /-- Canonical form of the **equality case of Jensen's equality**. For a strictly convex function `f` and nonnegative weights `w`, we have `f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` with nonzero weight are all equal (and in fact all equal to their center of mass wrt `w`). -/ lemma StrictConvexOn.map_sum_eq_iff' (hf : StrictConvexOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔ ∀ j ∈ t, w j ≠ 0 → p j = ∑ i ∈ t, w i • p i := by have hw (i) (_ : i ∈ t) : w i • p i ≠ 0 → w i ≠ 0 := by aesop have hw' (i) (_ : i ∈ t) : w i • f (p i) ≠ 0 → w i ≠ 0 := by aesop rw [← sum_filter_of_ne hw, ← sum_filter_of_ne hw', hf.map_sum_eq_iff] · simp · simp (config := { contextual := true }) [(h₀ _ _).gt_iff_ne] · rwa [sum_filter_ne_zero] · simp (config := { contextual := true }) [hmem _ _] /-- Canonical form of the **equality case of Jensen's equality**. For a strictly concave function `f` and nonnegative weights `w`, we have `f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i)` if and only if the points `p` with nonzero weight are all equal (and in fact all equal to their center of mass wrt `w`). -/ lemma StrictConcaveOn.map_sum_eq_iff' (hf : StrictConcaveOn 𝕜 s f) (h₀ : ∀ i ∈ t, 0 ≤ w i) (h₁ : ∑ i ∈ t, w i = 1) (hmem : ∀ i ∈ t, p i ∈ s) : f (∑ i ∈ t, w i • p i) = ∑ i ∈ t, w i • f (p i) ↔ ∀ j ∈ t, w j ≠ 0 → p j = ∑ i ∈ t, w i • p i := hf.dual.map_sum_eq_iff' h₀ h₁ hmem end Jensen /-! ### Maximum principle -/ section MaximumPrinciple variable [LinearOrderedField 𝕜] [AddCommGroup E] [LinearOrderedAddCommGroup β] [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} {t : Finset ι} {w : ι → 𝕜} {p : ι → E} {x y z : E} theorem le_sup_of_mem_convexHull {s : Finset E} (hf : ConvexOn 𝕜 (convexHull 𝕜 (s : Set E)) f) (hx : x ∈ convexHull 𝕜 (s : Set E)) : f x ≤ s.sup' (coe_nonempty.1 <| convexHull_nonempty_iff.1 ⟨x, hx⟩) f := by obtain ⟨w, hw₀, hw₁, rfl⟩ := mem_convexHull.1 hx exact (hf.map_centerMass_le hw₀ (by positivity) <| subset_convexHull _ _).trans (centerMass_le_sup hw₀ <| by positivity) theorem inf_le_of_mem_convexHull {s : Finset E} (hf : ConcaveOn 𝕜 (convexHull 𝕜 (s : Set E)) f) (hx : x ∈ convexHull 𝕜 (s : Set E)) : s.inf' (coe_nonempty.1 <| convexHull_nonempty_iff.1 ⟨x, hx⟩) f ≤ f x := le_sup_of_mem_convexHull hf.dual hx /-- If a function `f` is convex on `s`, then the value it takes at some center of mass of points of `s` is less than the value it takes on one of those points. -/ theorem ConvexOn.exists_ge_of_centerMass (h : ConvexOn 𝕜 s f) (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hw₁ : 0 < ∑ i ∈ t, w i) (hp : ∀ i ∈ t, p i ∈ s) : ∃ i ∈ t, f (t.centerMass w p) ≤ f (p i) := by set y := t.centerMass w p -- TODO: can `rsuffices` be used to write the `exact` first, then the proof of this obtain? obtain ⟨i, hi, hfi⟩ : ∃ i ∈ t.filter fun i => w i ≠ 0, w i • f y ≤ w i • (f ∘ p) i := by have hw' : (0 : 𝕜) < ∑ i ∈ filter (fun i => w i ≠ 0) t, w i := by rwa [sum_filter_ne_zero] refine exists_le_of_sum_le (nonempty_of_sum_ne_zero hw'.ne') ?_ rw [← sum_smul, ← smul_le_smul_iff_of_pos_left (inv_pos.2 hw'), inv_smul_smul₀ hw'.ne', ← centerMass, centerMass_filter_ne_zero] exact h.map_centerMass_le hw₀ hw₁ hp rw [mem_filter] at hi exact ⟨i, hi.1, (smul_le_smul_iff_of_pos_left <| (hw₀ i hi.1).lt_of_ne hi.2.symm).1 hfi⟩ /-- If a function `f` is concave on `s`, then the value it takes at some center of mass of points of `s` is greater than the value it takes on one of those points. -/ theorem ConcaveOn.exists_le_of_centerMass (h : ConcaveOn 𝕜 s f) (hw₀ : ∀ i ∈ t, 0 ≤ w i) (hw₁ : 0 < ∑ i ∈ t, w i) (hp : ∀ i ∈ t, p i ∈ s) : ∃ i ∈ t, f (p i) ≤ f (t.centerMass w p) := ConvexOn.exists_ge_of_centerMass (β := βᵒᵈ) h hw₀ hw₁ hp /-- **Maximum principle** for convex functions. If a function `f` is convex on the convex hull of `s`, then the eventual maximum of `f` on `convexHull 𝕜 s` lies in `s`. -/ theorem ConvexOn.exists_ge_of_mem_convexHull (hf : ConvexOn 𝕜 (convexHull 𝕜 s) f) {x} (hx : x ∈ convexHull 𝕜 s) : ∃ y ∈ s, f x ≤ f y := by rw [_root_.convexHull_eq] at hx obtain ⟨α, t, w, p, hw₀, hw₁, hp, rfl⟩ := hx rcases hf.exists_ge_of_centerMass hw₀ (hw₁.symm ▸ zero_lt_one) fun i hi => subset_convexHull 𝕜 s (hp i hi) with ⟨i, hit, Hi⟩ exact ⟨p i, hp i hit, Hi⟩ /-- **Minimum principle** for concave functions. If a function `f` is concave on the convex hull of `s`, then the eventual minimum of `f` on `convexHull 𝕜 s` lies in `s`. -/ theorem ConcaveOn.exists_le_of_mem_convexHull (hf : ConcaveOn 𝕜 (convexHull 𝕜 s) f) {x} (hx : x ∈ convexHull 𝕜 s) : ∃ y ∈ s, f y ≤ f x := ConvexOn.exists_ge_of_mem_convexHull (β := βᵒᵈ) hf hx /-- **Maximum principle** for convex functions on a segment. If a function `f` is convex on the segment `[x, y]`, then the eventual maximum of `f` on `[x, y]` is at `x` or `y`. -/ lemma ConvexOn.le_max_of_mem_segment (hf : ConvexOn 𝕜 [x -[𝕜] y] f) (hz : z ∈ [x -[𝕜] y]) : f z ≤ max (f x) (f y) := by rw [← convexHull_pair] at hf hz; simpa using hf.exists_ge_of_mem_convexHull hz /-- **Minimum principle** for concave functions on a segment. If a function `f` is concave on the segment `[x, y]`, then the eventual minimum of `f` on `[x, y]` is at `x` or `y`. -/ lemma ConcaveOn.min_le_of_mem_segment (hf : ConcaveOn 𝕜 [x -[𝕜] y] f) (hz : z ∈ [x -[𝕜] y]) : min (f x) (f y) ≤ f z := by rw [← convexHull_pair] at hf hz; simpa using hf.exists_le_of_mem_convexHull hz /-- **Maximum principle** for convex functions on an interval. If a function `f` is convex on the interval `[x, y]`, then the eventual maximum of `f` on `[x, y]` is at `x` or `y`. -/ lemma ConvexOn.le_max_of_mem_Icc {f : 𝕜 → β} {x y z : 𝕜} (hf : ConvexOn 𝕜 (Icc x y) f) (hz : z ∈ Icc x y) : f z ≤ max (f x) (f y) := by rw [← segment_eq_Icc (hz.1.trans hz.2)] at hf hz; exact hf.le_max_of_mem_segment hz /-- **Minimum principle** for concave functions on an interval. If a function `f` is concave on the interval `[x, y]`, then the eventual minimum of `f` on `[x, y]` is at `x` or `y`. -/ lemma ConcaveOn.min_le_of_mem_Icc {f : 𝕜 → β} {x y z : 𝕜} (hf : ConcaveOn 𝕜 (Icc x y) f) (hz : z ∈ Icc x y) : min (f x) (f y) ≤ f z := by rw [← segment_eq_Icc (hz.1.trans hz.2)] at hf hz; exact hf.min_le_of_mem_segment hz end MaximumPrinciple
Analysis\Convex\Join.lean
/- 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.Analysis.Convex.Hull /-! # Convex join This file defines the convex join of two sets. The convex join of `s` and `t` is the union of the segments with one end in `s` and the other in `t`. This is notably a useful gadget to deal with convex hulls of finite sets. -/ open Set variable {ι : Sort*} {𝕜 E : Type*} section OrderedSemiring variable (𝕜) [OrderedSemiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] {s t s₁ s₂ t₁ t₂ u : Set E} {x y : E} /-- The join of two sets is the union of the segments joining them. This can be interpreted as the topological join, but within the original space. -/ def convexJoin (s t : Set E) : Set E := ⋃ (x ∈ s) (y ∈ t), segment 𝕜 x y variable {𝕜} theorem mem_convexJoin : x ∈ convexJoin 𝕜 s t ↔ ∃ a ∈ s, ∃ b ∈ t, x ∈ segment 𝕜 a b := by simp [convexJoin] theorem convexJoin_comm (s t : Set E) : convexJoin 𝕜 s t = convexJoin 𝕜 t s := (iUnion₂_comm _).trans <| by simp_rw [convexJoin, segment_symm] theorem convexJoin_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : convexJoin 𝕜 s₁ t₁ ⊆ convexJoin 𝕜 s₂ t₂ := biUnion_mono hs fun _ _ => biUnion_subset_biUnion_left ht theorem convexJoin_mono_left (hs : s₁ ⊆ s₂) : convexJoin 𝕜 s₁ t ⊆ convexJoin 𝕜 s₂ t := convexJoin_mono hs Subset.rfl theorem convexJoin_mono_right (ht : t₁ ⊆ t₂) : convexJoin 𝕜 s t₁ ⊆ convexJoin 𝕜 s t₂ := convexJoin_mono Subset.rfl ht @[simp] theorem convexJoin_empty_left (t : Set E) : convexJoin 𝕜 ∅ t = ∅ := by simp [convexJoin] @[simp] theorem convexJoin_empty_right (s : Set E) : convexJoin 𝕜 s ∅ = ∅ := by simp [convexJoin] @[simp] theorem convexJoin_singleton_left (t : Set E) (x : E) : convexJoin 𝕜 {x} t = ⋃ y ∈ t, segment 𝕜 x y := by simp [convexJoin] @[simp] theorem convexJoin_singleton_right (s : Set E) (y : E) : convexJoin 𝕜 s {y} = ⋃ x ∈ s, segment 𝕜 x y := by simp [convexJoin] -- Porting note (#10618): simp can prove it theorem convexJoin_singletons (x : E) : convexJoin 𝕜 {x} {y} = segment 𝕜 x y := by simp @[simp] theorem convexJoin_union_left (s₁ s₂ t : Set E) : convexJoin 𝕜 (s₁ ∪ s₂) t = convexJoin 𝕜 s₁ t ∪ convexJoin 𝕜 s₂ t := by simp_rw [convexJoin, mem_union, iUnion_or, iUnion_union_distrib] @[simp] theorem convexJoin_union_right (s t₁ t₂ : Set E) : convexJoin 𝕜 s (t₁ ∪ t₂) = convexJoin 𝕜 s t₁ ∪ convexJoin 𝕜 s t₂ := by simp_rw [convexJoin_comm s, convexJoin_union_left] @[simp] theorem convexJoin_iUnion_left (s : ι → Set E) (t : Set E) : convexJoin 𝕜 (⋃ i, s i) t = ⋃ i, convexJoin 𝕜 (s i) t := by simp_rw [convexJoin, mem_iUnion, iUnion_exists] exact iUnion_comm _ @[simp] theorem convexJoin_iUnion_right (s : Set E) (t : ι → Set E) : convexJoin 𝕜 s (⋃ i, t i) = ⋃ i, convexJoin 𝕜 s (t i) := by simp_rw [convexJoin_comm s, convexJoin_iUnion_left] theorem segment_subset_convexJoin (hx : x ∈ s) (hy : y ∈ t) : segment 𝕜 x y ⊆ convexJoin 𝕜 s t := subset_iUnion₂_of_subset x hx <| subset_iUnion₂ (s := fun y _ ↦ segment 𝕜 x y) y hy theorem subset_convexJoin_left (h : t.Nonempty) : s ⊆ convexJoin 𝕜 s t := fun _x hx => let ⟨_y, hy⟩ := h segment_subset_convexJoin hx hy <| left_mem_segment _ _ _ theorem subset_convexJoin_right (h : s.Nonempty) : t ⊆ convexJoin 𝕜 s t := convexJoin_comm (𝕜 := 𝕜) t s ▸ subset_convexJoin_left h theorem convexJoin_subset (hs : s ⊆ u) (ht : t ⊆ u) (hu : Convex 𝕜 u) : convexJoin 𝕜 s t ⊆ u := iUnion₂_subset fun _x hx => iUnion₂_subset fun _y hy => hu.segment_subset (hs hx) (ht hy) theorem convexJoin_subset_convexHull (s t : Set E) : convexJoin 𝕜 s t ⊆ convexHull 𝕜 (s ∪ t) := convexJoin_subset (subset_union_left.trans <| subset_convexHull _ _) (subset_union_right.trans <| subset_convexHull _ _) <| convex_convexHull _ _ end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t u : Set E} {x y : E} theorem convexJoin_assoc_aux (s t u : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) u ⊆ convexJoin 𝕜 s (convexJoin 𝕜 t u) := by simp_rw [subset_def, mem_convexJoin] rintro _ ⟨z, ⟨x, hx, y, hy, a₁, b₁, ha₁, hb₁, hab₁, rfl⟩, z, hz, a₂, b₂, ha₂, hb₂, hab₂, rfl⟩ obtain rfl | hb₂ := hb₂.eq_or_lt · refine ⟨x, hx, y, ⟨y, hy, z, hz, left_mem_segment 𝕜 _ _⟩, a₁, b₁, ha₁, hb₁, hab₁, ?_⟩ rw [add_zero] at hab₂ rw [hab₂, one_smul, zero_smul, add_zero] have ha₂b₁ : 0 ≤ a₂ * b₁ := mul_nonneg ha₂ hb₁ have hab : 0 < a₂ * b₁ + b₂ := add_pos_of_nonneg_of_pos ha₂b₁ hb₂ refine ⟨x, hx, (a₂ * b₁ / (a₂ * b₁ + b₂)) • y + (b₂ / (a₂ * b₁ + b₂)) • z, ⟨y, hy, z, hz, _, _, ?_, ?_, ?_, rfl⟩, a₂ * a₁, a₂ * b₁ + b₂, mul_nonneg ha₂ ha₁, hab.le, ?_, ?_⟩ · exact div_nonneg ha₂b₁ hab.le · exact div_nonneg hb₂.le hab.le · rw [← add_div, div_self hab.ne'] · rw [← add_assoc, ← mul_add, hab₁, mul_one, hab₂] · simp_rw [smul_add, ← mul_smul, mul_div_cancel₀ _ hab.ne', add_assoc] theorem convexJoin_assoc (s t u : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) u = convexJoin 𝕜 s (convexJoin 𝕜 t u) := by refine (convexJoin_assoc_aux _ _ _).antisymm ?_ simp_rw [convexJoin_comm s, convexJoin_comm _ u] exact convexJoin_assoc_aux _ _ _ theorem convexJoin_left_comm (s t u : Set E) : convexJoin 𝕜 s (convexJoin 𝕜 t u) = convexJoin 𝕜 t (convexJoin 𝕜 s u) := by simp_rw [← convexJoin_assoc, convexJoin_comm] theorem convexJoin_right_comm (s t u : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) u = convexJoin 𝕜 (convexJoin 𝕜 s u) t := by simp_rw [convexJoin_assoc, convexJoin_comm] theorem convexJoin_convexJoin_convexJoin_comm (s t u v : Set E) : convexJoin 𝕜 (convexJoin 𝕜 s t) (convexJoin 𝕜 u v) = convexJoin 𝕜 (convexJoin 𝕜 s u) (convexJoin 𝕜 t v) := by simp_rw [← convexJoin_assoc, convexJoin_right_comm] -- Porting note: moved 3 lemmas from below to golf protected theorem Convex.convexJoin (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) : Convex 𝕜 (convexJoin 𝕜 s t) := by simp only [Convex, StarConvex, convexJoin, mem_iUnion] rintro _ ⟨x₁, hx₁, y₁, hy₁, a₁, b₁, ha₁, hb₁, hab₁, rfl⟩ _ ⟨x₂, hx₂, y₂, hy₂, a₂, b₂, ha₂, hb₂, hab₂, rfl⟩ p q hp hq hpq rcases hs.exists_mem_add_smul_eq hx₁ hx₂ (mul_nonneg hp ha₁) (mul_nonneg hq ha₂) with ⟨x, hxs, hx⟩ rcases ht.exists_mem_add_smul_eq hy₁ hy₂ (mul_nonneg hp hb₁) (mul_nonneg hq hb₂) with ⟨y, hyt, hy⟩ refine ⟨_, hxs, _, hyt, p * a₁ + q * a₂, p * b₁ + q * b₂, ?_, ?_, ?_, ?_⟩ <;> try positivity · rwa [add_add_add_comm, ← mul_add, ← mul_add, hab₁, hab₂, mul_one, mul_one] · rw [hx, hy, add_add_add_comm] simp only [smul_add, smul_smul] protected theorem Convex.convexHull_union (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) (hs₀ : s.Nonempty) (ht₀ : t.Nonempty) : convexHull 𝕜 (s ∪ t) = convexJoin 𝕜 s t := (convexHull_min (union_subset (subset_convexJoin_left ht₀) <| subset_convexJoin_right hs₀) <| hs.convexJoin ht).antisymm <| convexJoin_subset_convexHull _ _ theorem convexHull_union (hs : s.Nonempty) (ht : t.Nonempty) : convexHull 𝕜 (s ∪ t) = convexJoin 𝕜 (convexHull 𝕜 s) (convexHull 𝕜 t) := by rw [← convexHull_convexHull_union_left, ← convexHull_convexHull_union_right] exact (convex_convexHull 𝕜 s).convexHull_union (convex_convexHull 𝕜 t) hs.convexHull ht.convexHull theorem convexHull_insert (hs : s.Nonempty) : convexHull 𝕜 (insert x s) = convexJoin 𝕜 {x} (convexHull 𝕜 s) := by rw [insert_eq, convexHull_union (singleton_nonempty _) hs, convexHull_singleton] theorem convexJoin_segments (a b c d : E) : convexJoin 𝕜 (segment 𝕜 a b) (segment 𝕜 c d) = convexHull 𝕜 {a, b, c, d} := by simp_rw [← convexHull_pair, convexHull_insert (insert_nonempty _ _), convexHull_insert (singleton_nonempty _), convexJoin_assoc, convexHull_singleton] theorem convexJoin_segment_singleton (a b c : E) : convexJoin 𝕜 (segment 𝕜 a b) {c} = convexHull 𝕜 {a, b, c} := by rw [← pair_eq_singleton, ← convexJoin_segments, segment_same, pair_eq_singleton] theorem convexJoin_singleton_segment (a b c : E) : convexJoin 𝕜 {a} (segment 𝕜 b c) = convexHull 𝕜 {a, b, c} := by rw [← segment_same 𝕜, convexJoin_segments, insert_idem] -- Porting note: moved 3 lemmas up to golf end LinearOrderedField
Analysis\Convex\KreinMilman.lean
/- 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.Analysis.Convex.Exposed import Mathlib.Analysis.NormedSpace.HahnBanach.Separation import Mathlib.Topology.Algebra.ContinuousAffineMap /-! # The Krein-Milman theorem This file proves the Krein-Milman lemma and the Krein-Milman theorem. ## The lemma The lemma states that a nonempty compact set `s` has an extreme point. The proof goes: 1. Using Zorn's lemma, find a minimal nonempty closed `t` that is an extreme subset of `s`. We will show that `t` is a singleton, thus corresponding to an extreme point. 2. By contradiction, `t` contains two distinct points `x` and `y`. 3. With the (geometric) Hahn-Banach theorem, find a hyperplane that separates `x` and `y`. 4. Look at the extreme (actually exposed) subset of `t` obtained by going the furthest away from the separating hyperplane in the direction of `x`. It is nonempty, closed and an extreme subset of `s`. 5. It is a strict subset of `t` (`y` isn't in it), so `t` isn't minimal. Absurd. ## The theorem The theorem states that a compact convex set `s` is the closure of the convex hull of its extreme points. It is an almost immediate strengthening of the lemma. The proof goes: 1. By contradiction, `s \ closure (convexHull ℝ (extremePoints ℝ s))` is nonempty, say with `x`. 2. With the (geometric) Hahn-Banach theorem, find a hyperplane that separates `x` from `closure (convexHull ℝ (extremePoints ℝ s))`. 3. Look at the extreme (actually exposed) subset of `s \ closure (convexHull ℝ (extremePoints ℝ s))` obtained by going the furthest away from the separating hyperplane. It is nonempty by assumption of nonemptiness and compactness, so by the lemma it has an extreme point. 4. This point is also an extreme point of `s`. Absurd. ## Related theorems When the space is finite dimensional, the `closure` can be dropped to strengthen the result of the Krein-Milman theorem. This leads to the Minkowski-Carathéodory theorem (currently not in mathlib). Birkhoff's theorem is the Minkowski-Carathéodory theorem applied to the set of bistochastic matrices, permutation matrices being the extreme points. ## References See chapter 8 of [Barry Simon, *Convexity*][simon2011] -/ open Set open scoped Classical variable {E F : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [T2Space E] [TopologicalAddGroup E] [ContinuousSMul ℝ E] [LocallyConvexSpace ℝ E] {s : Set E} [AddCommGroup F] [Module ℝ F] [TopologicalSpace F] [T1Space F] /-- **Krein-Milman lemma**: In a LCTVS, any nonempty compact set has an extreme point. -/ theorem IsCompact.extremePoints_nonempty (hscomp : IsCompact s) (hsnemp : s.Nonempty) : (s.extremePoints ℝ).Nonempty := by let S : Set (Set E) := { t | t.Nonempty ∧ IsClosed t ∧ IsExtreme ℝ s t } rsuffices ⟨t, ⟨⟨x, hxt⟩, htclos, hst⟩, hBmin⟩ : ∃ t ∈ S, ∀ u ∈ S, u ⊆ t → u = t · refine ⟨x, IsExtreme.mem_extremePoints ?_⟩ rwa [← eq_singleton_iff_unique_mem.2 ⟨hxt, fun y hyB => ?_⟩] by_contra hyx obtain ⟨l, hl⟩ := geometric_hahn_banach_point_point hyx obtain ⟨z, hzt, hz⟩ := (hscomp.of_isClosed_subset htclos hst.1).exists_isMaxOn ⟨x, hxt⟩ l.continuous.continuousOn have h : IsExposed ℝ t ({ z ∈ t | ∀ w ∈ t, l w ≤ l z }) := fun _ => ⟨l, rfl⟩ rw [← hBmin ({ z ∈ t | ∀ w ∈ t, l w ≤ l z }) ⟨⟨z, hzt, hz⟩, h.isClosed htclos, hst.trans h.isExtreme⟩ (t.sep_subset _)] at hyB exact hl.not_le (hyB.2 x hxt) refine zorn_superset _ fun F hFS hF => ?_ obtain rfl | hFnemp := F.eq_empty_or_nonempty · exact ⟨s, ⟨hsnemp, hscomp.isClosed, IsExtreme.rfl⟩, fun _ => False.elim⟩ refine ⟨⋂₀ F, ⟨?_, isClosed_sInter fun t ht => (hFS ht).2.1, isExtreme_sInter hFnemp fun t ht => (hFS ht).2.2⟩, fun t ht => sInter_subset_of_mem ht⟩ haveI : Nonempty (↥F) := hFnemp.to_subtype rw [sInter_eq_iInter] refine IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun t u => ?_) (fun t => (hFS t.mem).1) (fun t => hscomp.of_isClosed_subset (hFS t.mem).2.1 (hFS t.mem).2.2.1) fun t => (hFS t.mem).2.1 obtain htu | hut := hF.total t.mem u.mem exacts [⟨t, Subset.rfl, htu⟩, ⟨u, hut, Subset.rfl⟩] /-- **Krein-Milman theorem**: In a LCTVS, any compact convex set is the closure of the convex hull of its extreme points. -/ theorem closure_convexHull_extremePoints (hscomp : IsCompact s) (hAconv : Convex ℝ s) : closure (convexHull ℝ <| s.extremePoints ℝ) = s := by apply (closure_minimal (convexHull_min extremePoints_subset hAconv) hscomp.isClosed).antisymm by_contra hs obtain ⟨x, hxA, hxt⟩ := not_subset.1 hs obtain ⟨l, r, hlr, hrx⟩ := geometric_hahn_banach_closed_point (convex_convexHull _ _).closure isClosed_closure hxt have h : IsExposed ℝ s ({ y ∈ s | ∀ z ∈ s, l z ≤ l y }) := fun _ => ⟨l, rfl⟩ obtain ⟨z, hzA, hz⟩ := hscomp.exists_isMaxOn ⟨x, hxA⟩ l.continuous.continuousOn obtain ⟨y, hy⟩ := (h.isCompact hscomp).extremePoints_nonempty ⟨z, hzA, hz⟩ linarith [hlr _ (subset_closure <| subset_convexHull _ _ <| h.isExtreme.extremePoints_subset_extremePoints hy), hy.1.2 x hxA] /-- A continuous affine map is surjective from the extreme points of a compact set to the extreme points of the image of that set. This inclusion is in general strict. -/ lemma surjOn_extremePoints_image (f : E →ᴬ[ℝ] F) (hs : IsCompact s) : SurjOn f (extremePoints ℝ s) (extremePoints ℝ (f '' s)) := by rintro w hw -- The fiber of `w` is nonempty and compact have ht : IsCompact {x ∈ s | f x = w} := hs.inter_right <| isClosed_singleton.preimage f.continuous have ht₀ : {x ∈ s | f x = w}.Nonempty := by simpa using extremePoints_subset hw -- Hence by the Krein-Milman lemma it has an extreme point `x` obtain ⟨x, ⟨hx, rfl⟩, hyt⟩ := ht.extremePoints_nonempty ht₀ -- `f x = w` and `x` is an extreme point of `s`, so we're done refine mem_image_of_mem _ ⟨hx, fun y hy z hz hxyz ↦ ?_⟩ have := by simpa using image_openSegment _ f.toAffineMap y z have := hw.2 (mem_image_of_mem _ hy) (mem_image_of_mem _ hz) <| by rw [← this]; exact mem_image_of_mem _ hxyz exact hyt ⟨hy, this.1⟩ ⟨hz, this.2⟩ hxyz
Analysis\Convex\Measure.lean
/- 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.Convex.Topology import Mathlib.Analysis.NormedSpace.AddTorsorBases import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar /-! # Convex sets are null-measurable Let `E` be a finite dimensional real vector space, let `μ` be a Haar measure on `E`, let `s` be a convex set in `E`. Then the frontier of `s` has measure zero (see `Convex.addHaar_frontier`), hence `s` is a `NullMeasurableSet` (see `Convex.nullMeasurableSet`). -/ open MeasureTheory MeasureTheory.Measure Set Metric Filter Bornology open FiniteDimensional (finrank) open scoped Topology NNReal ENNReal variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {s : Set E} namespace Convex /-- Haar measure of the frontier of a convex set is zero. -/ theorem addHaar_frontier (hs : Convex ℝ s) : μ (frontier s) = 0 := by /- If `s` is included in a hyperplane, then `frontier s ⊆ closure s` is included in the same hyperplane, hence it has measure zero. -/ cases' ne_or_eq (affineSpan ℝ s) ⊤ with hspan hspan · refine measure_mono_null ?_ (addHaar_affineSubspace _ _ hspan) exact frontier_subset_closure.trans (closure_minimal (subset_affineSpan _ _) (affineSpan ℝ s).closed_of_finiteDimensional) rw [← hs.interior_nonempty_iff_affineSpan_eq_top] at hspan rcases hspan with ⟨x, hx⟩ /- Without loss of generality, `s` is bounded. Indeed, `∂s ⊆ ⋃ n, ∂(s ∩ ball x (n + 1))`, hence it suffices to prove that `∀ n, μ (s ∩ ball x (n + 1)) = 0`; the latter set is bounded. -/ suffices H : ∀ t : Set E, Convex ℝ t → x ∈ interior t → IsBounded t → μ (frontier t) = 0 by let B : ℕ → Set E := fun n => ball x (n + 1) have : μ (⋃ n : ℕ, frontier (s ∩ B n)) = 0 := by refine measure_iUnion_null fun n => H _ (hs.inter (convex_ball _ _)) ?_ (isBounded_ball.subset inter_subset_right) rw [interior_inter, isOpen_ball.interior_eq] exact ⟨hx, mem_ball_self (add_pos_of_nonneg_of_pos n.cast_nonneg zero_lt_one)⟩ refine measure_mono_null (fun y hy => ?_) this; clear this set N : ℕ := ⌊dist y x⌋₊ refine mem_iUnion.2 ⟨N, ?_⟩ have hN : y ∈ B N := by simp [B, N, Nat.lt_floor_add_one] suffices y ∈ frontier (s ∩ B N) ∩ B N from this.1 rw [frontier_inter_open_inter isOpen_ball] exact ⟨hy, hN⟩ intro s hs hx hb /- Since `s` is bounded, we have `μ (interior s) ≠ ∞`, hence it suffices to prove `μ (closure s) ≤ μ (interior s)`. -/ replace hb : μ (interior s) ≠ ∞ := (hb.subset interior_subset).measure_lt_top.ne suffices μ (closure s) ≤ μ (interior s) by rwa [frontier, measure_diff interior_subset_closure isOpen_interior.measurableSet hb, tsub_eq_zero_iff_le] /- Due to `Convex.closure_subset_image_homothety_interior_of_one_lt`, for any `r > 1` we have `closure s ⊆ homothety x r '' interior s`, hence `μ (closure s) ≤ r ^ d * μ (interior s)`, where `d = finrank ℝ E`. -/ set d : ℕ := FiniteDimensional.finrank ℝ E have : ∀ r : ℝ≥0, 1 < r → μ (closure s) ≤ ↑(r ^ d) * μ (interior s) := fun r hr ↦ by refine (measure_mono <| hs.closure_subset_image_homothety_interior_of_one_lt hx r hr).trans_eq ?_ rw [addHaar_image_homothety, ← NNReal.coe_pow, NNReal.abs_eq, ENNReal.ofReal_coe_nnreal] have : ∀ᶠ (r : ℝ≥0) in 𝓝[>] 1, μ (closure s) ≤ ↑(r ^ d) * μ (interior s) := mem_of_superset self_mem_nhdsWithin this -- Taking the limit as `r → 1`, we get `μ (closure s) ≤ μ (interior s)`. refine ge_of_tendsto ?_ this refine (((ENNReal.continuous_mul_const hb).comp (ENNReal.continuous_coe.comp (continuous_pow d))).tendsto' _ _ ?_).mono_left nhdsWithin_le_nhds simp /-- A convex set in a finite dimensional real vector space is null measurable with respect to an additive Haar measure on this space. -/ protected theorem nullMeasurableSet (hs : Convex ℝ s) : NullMeasurableSet s μ := nullMeasurableSet_of_null_frontier (hs.addHaar_frontier μ) end Convex
Analysis\Convex\Mul.lean
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Monovary import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp /-! # Product of convex functions This file proves that the product of convex functions is convex, provided they monovary. As corollaries, we also prove that `x ↦ x ^ n` is convex * `Even.convexOn_pow`: for even `n : ℕ`. * `convexOn_pow`: over $[0, +∞)$ for `n : ℕ`. * `convexOn_zpow`: over $(0, +∞)$ For `n : ℤ`. -/ open Set variable {𝕜 E F : Type*} section LinearOrderedCommRing variable [LinearOrderedCommRing 𝕜] [LinearOrderedCommRing E] [LinearOrderedAddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] [Module E F] [IsScalarTower 𝕜 E F] [SMulCommClass 𝕜 E F] [OrderedSMul 𝕜 F] [OrderedSMul E F] {s : Set 𝕜} {f : 𝕜 → E} {g : 𝕜 → F} lemma ConvexOn.smul' (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ dsimp refine (smul_le_smul (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) (hf₀ <| hf.1 hx hy ha hb hab) <| add_nonneg (smul_nonneg ha <| hg₀ hx) <| smul_nonneg hb <| hg₀ hy).trans ?_ calc _ = (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g y + f y • g x) := ?_ _ ≤ (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g x + f y • g y) := by gcongr _ + (a * b) • ?_; exact hfg.smul_add_smul_le_smul_add_smul hx hy _ = (a * (a + b)) • (f x • g x) + (b * (a + b)) • (f y • g y) := by simp only [mul_add, add_smul, smul_add, mul_comm _ a]; abel _ = _ := by simp_rw [hab, mul_one] simp only [mul_add, add_smul, smul_add] rw [← smul_smul_smul_comm a, ← smul_smul_smul_comm b, ← smul_smul_smul_comm a b, ← smul_smul_smul_comm b b, smul_eq_mul, smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_comm b, add_comm _ ((b * b) • f y • g y), add_add_add_comm, add_comm ((a * b) • f y • g x)] lemma ConcaveOn.smul' [OrderedSMul 𝕜 E] (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ dsimp refine (smul_le_smul (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) (add_nonneg (smul_nonneg ha <| hf₀ hx) <| smul_nonneg hb <| hf₀ hy) (hg₀ <| hf.1 hx hy ha hb hab)).trans' ?_ calc a • f x • g x + b • f y • g y = (a * (a + b)) • (f x • g x) + (b * (a + b)) • (f y • g y) := by simp_rw [hab, mul_one] _ = (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g x + f y • g y) := by simp only [mul_add, add_smul, smul_add, mul_comm _ a]; abel _ ≤ (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g y + f y • g x) := by gcongr _ + (a * b) • ?_; exact hfg.smul_add_smul_le_smul_add_smul hx hy _ = _ := ?_ simp only [mul_add, add_smul, smul_add] rw [← smul_smul_smul_comm a, ← smul_smul_smul_comm b, ← smul_smul_smul_comm a b, ← smul_smul_smul_comm b b, smul_eq_mul, smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_comm b a, add_comm ((a * b) • f x • g y), add_comm ((a * b) • f x • g y), add_add_add_comm] lemma ConvexOn.smul'' [OrderedSMul 𝕜 E] (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := by rw [← neg_smul_neg] exact hf.neg.smul' hg.neg (fun x hx ↦ neg_nonneg.2 <| hf₀ hx) (fun x hx ↦ neg_nonneg.2 <| hg₀ hx) hfg.neg lemma ConcaveOn.smul'' (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by rw [← neg_smul_neg] exact hf.neg.smul' hg.neg (fun x hx ↦ neg_nonneg.2 <| hf₀ hx) (fun x hx ↦ neg_nonneg.2 <| hg₀ hx) hfg.neg lemma ConvexOn.smul_concaveOn (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := by rw [← neg_convexOn_iff, ← smul_neg] exact hf.smul' hg.neg hf₀ (fun x hx ↦ neg_nonneg.2 <| hg₀ hx) hfg.neg_right lemma ConcaveOn.smul_convexOn [OrderedSMul 𝕜 E] (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by rw [← neg_concaveOn_iff, ← smul_neg] exact hf.smul' hg.neg hf₀ (fun x hx ↦ neg_nonneg.2 <| hg₀ hx) hfg.neg_right lemma ConvexOn.smul_concaveOn' [OrderedSMul 𝕜 E] (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by rw [← neg_concaveOn_iff, ← smul_neg] exact hf.smul'' hg.neg hf₀ (fun x hx ↦ neg_nonpos.2 <| hg₀ hx) hfg.neg_right lemma ConcaveOn.smul_convexOn' (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := by rw [← neg_convexOn_iff, ← smul_neg] exact hf.smul'' hg.neg hf₀ (fun x hx ↦ neg_nonpos.2 <| hg₀ hx) hfg.neg_right variable [OrderedSMul 𝕜 E] [IsScalarTower 𝕜 E E] [SMulCommClass 𝕜 E E] {f g : 𝕜 → E} lemma ConvexOn.mul (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f * g) := hf.smul' hg hf₀ hg₀ hfg lemma ConcaveOn.mul (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f * g) := hf.smul' hg hf₀ hg₀ hfg lemma ConvexOn.mul' (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f * g) := hf.smul'' hg hf₀ hg₀ hfg lemma ConcaveOn.mul' (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f * g) := hf.smul'' hg hf₀ hg₀ hfg lemma ConvexOn.mul_concaveOn (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f * g) := hf.smul_concaveOn hg hf₀ hg₀ hfg lemma ConcaveOn.mul_convexOn (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f * g) := hf.smul_convexOn hg hf₀ hg₀ hfg lemma ConvexOn.mul_concaveOn' (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f * g) := hf.smul_concaveOn' hg hf₀ hg₀ hfg lemma ConcaveOn.mul_convexOn' (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := hf.smul_convexOn' hg hf₀ hg₀ hfg lemma ConvexOn.pow (hf : ConvexOn 𝕜 s f) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) : ∀ n, ConvexOn 𝕜 s (f ^ n) | 0 => by simpa using convexOn_const 1 hf.1 | n + 1 => by rw [pow_succ'] exact hf.mul (hf.pow hf₀ _) hf₀ (fun x hx ↦ pow_nonneg (hf₀ hx) _) <| (monovaryOn_self f s).pow_right₀ hf₀ n /-- `x^n`, `n : ℕ` is convex on `[0, +∞)` for all `n`. -/ lemma convexOn_pow : ∀ n, ConvexOn 𝕜 (Ici 0) fun x : 𝕜 ↦ x ^ n := (convexOn_id <| convex_Ici _).pow fun _ ↦ id /-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even. -/ protected lemma Even.convexOn_pow {n : ℕ} (hn : Even n) : ConvexOn 𝕜 univ fun x : 𝕜 ↦ x ^ n := by obtain ⟨n, rfl⟩ := hn simp_rw [← two_mul, pow_mul] refine ConvexOn.pow ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ sub_nonneg.1 ?_⟩ (fun _ _ ↦ by positivity) _ calc (0 : 𝕜) ≤ (a * b) * (x - y) ^ 2 := by positivity _ = _ := by obtain rfl := eq_sub_of_add_eq hab; simp only [smul_eq_mul]; ring end LinearOrderedCommRing section LinearOrderedField variable [LinearOrderedField 𝕜] open Int in /-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m`. -/ lemma convexOn_zpow : ∀ n : ℤ, ConvexOn 𝕜 (Ioi 0) fun x : 𝕜 ↦ x ^ n | (n : ℕ) => by simp_rw [zpow_natCast] exact (convexOn_pow n).subset Ioi_subset_Ici_self (convex_Ioi _) | -[n+1] => by simp_rw [zpow_negSucc, ← inv_pow] refine (convexOn_iff_forall_pos.2 ⟨convex_Ioi _, ?_⟩).pow (fun x (hx : 0 < x) ↦ by positivity) _ rintro x (hx : 0 < x) y (hy : 0 < y) a b ha hb hab field_simp rw [div_le_div_iff, ← sub_nonneg] · calc 0 ≤ a * b * (x - y) ^ 2 := by positivity _ = _ := by obtain rfl := eq_sub_of_add_eq hab; ring all_goals positivity end LinearOrderedField
Analysis\Convex\Normed.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.Normed.Group.Pointwise import Mathlib.Analysis.NormedSpace.AddTorsor /-! # Topological and metric properties of convex sets in normed spaces We prove the following facts: * `convexOn_norm`, `convexOn_dist` : norm and distance to a fixed point is convex on any convex set; * `convexOn_univ_norm`, `convexOn_univ_dist` : norm and distance to a fixed point is convex on the whole space; * `convexHull_ediam`, `convexHull_diam` : convex hull of a set has the same (e)metric diameter as the original set; * `bounded_convexHull` : convex hull of a set is bounded if and only if the original set is bounded. -/ variable {ι : Type*} {E P : Type*} open Metric Set open scoped Convex variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] [PseudoMetricSpace P] [NormedAddTorsor E P] variable {s t : Set E} /-- The norm on a real normed space is convex on any convex set. See also `Seminorm.convexOn` and `convexOn_univ_norm`. -/ theorem convexOn_norm (hs : Convex ℝ s) : ConvexOn ℝ s norm := ⟨hs, fun x _ y _ a b ha hb _ => calc ‖a • x + b • y‖ ≤ ‖a • x‖ + ‖b • y‖ := norm_add_le _ _ _ = a * ‖x‖ + b * ‖y‖ := by rw [norm_smul, norm_smul, Real.norm_of_nonneg ha, Real.norm_of_nonneg hb]⟩ /-- The norm on a real normed space is convex on the whole space. See also `Seminorm.convexOn` and `convexOn_norm`. -/ theorem convexOn_univ_norm : ConvexOn ℝ univ (norm : E → ℝ) := convexOn_norm convex_univ theorem convexOn_dist (z : E) (hs : Convex ℝ s) : ConvexOn ℝ s fun z' => dist z' z := by simpa [dist_eq_norm, preimage_preimage] using (convexOn_norm (hs.translate (-z))).comp_affineMap (AffineMap.id ℝ E - AffineMap.const ℝ E z) theorem convexOn_univ_dist (z : E) : ConvexOn ℝ univ fun z' => dist z' z := convexOn_dist z convex_univ theorem convex_ball (a : E) (r : ℝ) : Convex ℝ (Metric.ball a r) := by simpa only [Metric.ball, sep_univ] using (convexOn_univ_dist a).convex_lt r theorem convex_closedBall (a : E) (r : ℝ) : Convex ℝ (Metric.closedBall a r) := by simpa only [Metric.closedBall, sep_univ] using (convexOn_univ_dist a).convex_le r theorem Convex.thickening (hs : Convex ℝ s) (δ : ℝ) : Convex ℝ (thickening δ s) := by rw [← add_ball_zero] exact hs.add (convex_ball 0 _) theorem Convex.cthickening (hs : Convex ℝ s) (δ : ℝ) : Convex ℝ (cthickening δ s) := by obtain hδ | hδ := le_total 0 δ · rw [cthickening_eq_iInter_thickening hδ] exact convex_iInter₂ fun _ _ => hs.thickening _ · rw [cthickening_of_nonpos hδ] exact hs.closure /-- Given a point `x` in the convex hull of `s` and a point `y`, there exists a point of `s` at distance at least `dist x y` from `y`. -/ theorem convexHull_exists_dist_ge {s : Set E} {x : E} (hx : x ∈ convexHull ℝ s) (y : E) : ∃ x' ∈ s, dist x y ≤ dist x' y := (convexOn_dist y (convex_convexHull ℝ _)).exists_ge_of_mem_convexHull hx /-- Given a point `x` in the convex hull of `s` and a point `y` in the convex hull of `t`, there exist points `x' ∈ s` and `y' ∈ t` at distance at least `dist x y`. -/ theorem convexHull_exists_dist_ge2 {s t : Set E} {x y : E} (hx : x ∈ convexHull ℝ s) (hy : y ∈ convexHull ℝ t) : ∃ x' ∈ s, ∃ y' ∈ t, dist x y ≤ dist x' y' := by rcases convexHull_exists_dist_ge hx y with ⟨x', hx', Hx'⟩ rcases convexHull_exists_dist_ge hy x' with ⟨y', hy', Hy'⟩ use x', hx', y', hy' exact le_trans Hx' (dist_comm y x' ▸ dist_comm y' x' ▸ Hy') /-- Emetric diameter of the convex hull of a set `s` equals the emetric diameter of `s`. -/ @[simp] theorem convexHull_ediam (s : Set E) : EMetric.diam (convexHull ℝ s) = EMetric.diam s := by refine (EMetric.diam_le fun x hx y hy => ?_).antisymm (EMetric.diam_mono <| subset_convexHull ℝ s) rcases convexHull_exists_dist_ge2 hx hy with ⟨x', hx', y', hy', H⟩ rw [edist_dist] apply le_trans (ENNReal.ofReal_le_ofReal H) rw [← edist_dist] exact EMetric.edist_le_diam_of_mem hx' hy' /-- Diameter of the convex hull of a set `s` equals the emetric diameter of `s`. -/ @[simp] theorem convexHull_diam (s : Set E) : Metric.diam (convexHull ℝ s) = Metric.diam s := by simp only [Metric.diam, convexHull_ediam] /-- Convex hull of `s` is bounded if and only if `s` is bounded. -/ @[simp] theorem isBounded_convexHull {s : Set E} : Bornology.IsBounded (convexHull ℝ s) ↔ Bornology.IsBounded s := by simp only [Metric.isBounded_iff_ediam_ne_top, convexHull_ediam] instance (priority := 100) NormedSpace.instPathConnectedSpace : PathConnectedSpace E := TopologicalAddGroup.pathConnectedSpace instance (priority := 100) NormedSpace.instLocPathConnectedSpace : LocPathConnectedSpace E := locPathConnected_of_bases (fun x => Metric.nhds_basis_ball) fun x r r_pos => (convex_ball x r).isPathConnected <| by simp [r_pos] theorem Wbtw.dist_add_dist {x y z : P} (h : Wbtw ℝ x y z) : dist x y + dist y z = dist x z := by obtain ⟨a, ⟨ha₀, ha₁⟩, rfl⟩ := h simp [abs_of_nonneg, ha₀, ha₁, sub_mul] theorem dist_add_dist_of_mem_segment {x y z : E} (h : y ∈ [x -[ℝ] z]) : dist x y + dist y z = dist x z := (mem_segment_iff_wbtw.1 h).dist_add_dist /-- The set of vectors in the same ray as `x` is connected. -/ theorem isConnected_setOf_sameRay (x : E) : IsConnected { y | SameRay ℝ x y } := by by_cases hx : x = 0; · simpa [hx] using isConnected_univ (α := E) simp_rw [← exists_nonneg_left_iff_sameRay hx] exact isConnected_Ici.image _ (continuous_id.smul continuous_const).continuousOn /-- The set of nonzero vectors in the same ray as the nonzero vector `x` is connected. -/ theorem isConnected_setOf_sameRay_and_ne_zero {x : E} (hx : x ≠ 0) : IsConnected { y | SameRay ℝ x y ∧ y ≠ 0 } := by simp_rw [← exists_pos_left_iff_sameRay_and_ne_zero hx] exact isConnected_Ioi.image _ (continuous_id.smul continuous_const).continuousOn
Analysis\Convex\PartitionOfUnity.lean
/- 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.Topology.PartitionOfUnity import Mathlib.Analysis.Convex.Combination /-! # Partition of unity and convex sets In this file we prove the following lemma, see `exists_continuous_forall_mem_convex_of_local`. Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a topological real vector space. Let `t : X → Set E` be a family of convex sets. Suppose that for each point `x : X`, there exists a neighborhood `U ∈ 𝓝 X` and a function `g : X → E` that is continuous on `U` and sends each `y ∈ U` to a point of `t y`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all `x`. We also formulate a useful corollary, see `exists_continuous_forall_mem_convex_of_local_const`, that assumes that local functions `g` are constants. ## Tags partition of unity -/ open Set Function open Topology variable {ι X E : Type*} [TopologicalSpace X] [AddCommGroup E] [Module ℝ E] theorem PartitionOfUnity.finsum_smul_mem_convex {s : Set X} (f : PartitionOfUnity ι X s) {g : ι → X → E} {t : Set E} {x : X} (hx : x ∈ s) (hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : Convex ℝ t) : (∑ᶠ i, f i x • g i x) ∈ t := ht.finsum_mem (fun _ => f.nonneg _ _) (f.sum_eq_one hx) hg variable [NormalSpace X] [ParacompactSpace X] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] {t : X → Set E} /-- Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a topological real vector space. Let `t : X → Set E` be a family of convex sets. Suppose that for each point `x : X`, there exists a neighborhood `U ∈ 𝓝 X` and a function `g : X → E` that is continuous on `U` and sends each `y ∈ U` to a point of `t y`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all `x`. See also `exists_continuous_forall_mem_convex_of_local_const`. -/ theorem exists_continuous_forall_mem_convex_of_local (ht : ∀ x, Convex ℝ (t x)) (H : ∀ x : X, ∃ U ∈ 𝓝 x, ∃ g : X → E, ContinuousOn g U ∧ ∀ y ∈ U, g y ∈ t y) : ∃ g : C(X, E), ∀ x, g x ∈ t x := by choose U hU g hgc hgt using H obtain ⟨f, hf⟩ := PartitionOfUnity.exists_isSubordinate isClosed_univ (fun x => interior (U x)) (fun x => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩ refine ⟨⟨fun x => ∑ᶠ i, f i x • g i x, hf.continuous_finsum_smul (fun i => isOpen_interior) fun i => (hgc i).mono interior_subset⟩, fun x => f.finsum_smul_mem_convex (mem_univ x) (fun i hi => hgt _ _ ?_) (ht _)⟩ exact interior_subset (hf _ <| subset_closure hi) /-- Let `X` be a normal paracompact topological space (e.g., any extended metric space). Let `E` be a topological real vector space. Let `t : X → Set E` be a family of convex sets. Suppose that for each point `x : X`, there exists a vector `c : E` that belongs to `t y` for all `y` in a neighborhood of `x`. Then there exists a continuous map `g : C(X, E)` such that `g x ∈ t x` for all `x`. See also `exists_continuous_forall_mem_convex_of_local`. -/ theorem exists_continuous_forall_mem_convex_of_local_const (ht : ∀ x, Convex ℝ (t x)) (H : ∀ x : X, ∃ c : E, ∀ᶠ y in 𝓝 x, c ∈ t y) : ∃ g : C(X, E), ∀ x, g x ∈ t x := exists_continuous_forall_mem_convex_of_local ht fun x => let ⟨c, hc⟩ := H x ⟨_, hc, fun _ => c, continuousOn_const, fun _ => id⟩
Analysis\Convex\Quasiconvex.lean
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Analysis.Convex.Function /-! # Quasiconvex and quasiconcave functions This file defines quasiconvexity, quasiconcavity and quasilinearity of functions, which are generalizations of unimodality and monotonicity. Convexity implies quasiconvexity, concavity implies quasiconcavity, and monotonicity implies quasilinearity. ## Main declarations * `QuasiconvexOn 𝕜 s f`: Quasiconvexity of the function `f` on the set `s` with scalars `𝕜`. This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. * `QuasiconcaveOn 𝕜 s f`: Quasiconcavity of the function `f` on the set `s` with scalars `𝕜`. This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. * `QuasilinearOn 𝕜 s f`: Quasilinearity of the function `f` on the set `s` with scalars `𝕜`. This means that `f` is both quasiconvex and quasiconcave. ## References * https://en.wikipedia.org/wiki/Quasiconvex_function -/ open Function OrderDual Set variable {𝕜 E F β : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid_E variable [AddCommMonoid E] [AddCommMonoid F] section LE_β variable (𝕜) [LE β] [SMul 𝕜 E] (s : Set E) (f : E → β) /-- A function is quasiconvex if all its sublevels are convex. This means that, for all `r`, `{x ∈ s | f x ≤ r}` is `𝕜`-convex. -/ def QuasiconvexOn : Prop := ∀ r, Convex 𝕜 ({ x ∈ s | f x ≤ r }) /-- A function is quasiconcave if all its superlevels are convex. This means that, for all `r`, `{x ∈ s | r ≤ f x}` is `𝕜`-convex. -/ def QuasiconcaveOn : Prop := ∀ r, Convex 𝕜 ({ x ∈ s | r ≤ f x }) /-- A function is quasilinear if it is both quasiconvex and quasiconcave. This means that, for all `r`, the sets `{x ∈ s | f x ≤ r}` and `{x ∈ s | r ≤ f x}` are `𝕜`-convex. -/ def QuasilinearOn : Prop := QuasiconvexOn 𝕜 s f ∧ QuasiconcaveOn 𝕜 s f variable {𝕜 s f} theorem QuasiconvexOn.dual : QuasiconvexOn 𝕜 s f → QuasiconcaveOn 𝕜 s (toDual ∘ f) := id theorem QuasiconcaveOn.dual : QuasiconcaveOn 𝕜 s f → QuasiconvexOn 𝕜 s (toDual ∘ f) := id theorem QuasilinearOn.dual : QuasilinearOn 𝕜 s f → QuasilinearOn 𝕜 s (toDual ∘ f) := And.symm theorem Convex.quasiconvexOn_of_convex_le (hs : Convex 𝕜 s) (h : ∀ r, Convex 𝕜 { x | f x ≤ r }) : QuasiconvexOn 𝕜 s f := fun r => hs.inter (h r) theorem Convex.quasiconcaveOn_of_convex_ge (hs : Convex 𝕜 s) (h : ∀ r, Convex 𝕜 { x | r ≤ f x }) : QuasiconcaveOn 𝕜 s f := @Convex.quasiconvexOn_of_convex_le 𝕜 E βᵒᵈ _ _ _ _ _ _ hs h theorem QuasiconvexOn.convex [IsDirected β (· ≤ ·)] (hf : QuasiconvexOn 𝕜 s f) : Convex 𝕜 s := fun x hx y hy _ _ ha hb hab => let ⟨_, hxz, hyz⟩ := exists_ge_ge (f x) (f y) (hf _ ⟨hx, hxz⟩ ⟨hy, hyz⟩ ha hb hab).1 theorem QuasiconcaveOn.convex [IsDirected β (· ≥ ·)] (hf : QuasiconcaveOn 𝕜 s f) : Convex 𝕜 s := hf.dual.convex end LE_β section Semilattice_β variable [SMul 𝕜 E] {s : Set E} {f g : E → β} theorem QuasiconvexOn.sup [SemilatticeSup β] (hf : QuasiconvexOn 𝕜 s f) (hg : QuasiconvexOn 𝕜 s g) : QuasiconvexOn 𝕜 s (f ⊔ g) := by intro r simp_rw [Pi.sup_def, sup_le_iff, Set.sep_and] exact (hf r).inter (hg r) theorem QuasiconcaveOn.inf [SemilatticeInf β] (hf : QuasiconcaveOn 𝕜 s f) (hg : QuasiconcaveOn 𝕜 s g) : QuasiconcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg end Semilattice_β section LinearOrder_β variable [LinearOrder β] [SMul 𝕜 E] {s : Set E} {f g : E → β} theorem quasiconvexOn_iff_le_max : QuasiconvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ max (f x) (f y) := ⟨fun hf => ⟨hf.convex, fun _ hx _ hy _ _ ha hb hab => (hf _ ⟨hx, le_max_left _ _⟩ ⟨hy, le_max_right _ _⟩ ha hb hab).2⟩, fun hf _ _ hx _ hy _ _ ha hb hab => ⟨hf.1 hx.1 hy.1 ha hb hab, (hf.2 hx.1 hy.1 ha hb hab).trans <| max_le hx.2 hy.2⟩⟩ theorem quasiconcaveOn_iff_min_le : QuasiconcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → min (f x) (f y) ≤ f (a • x + b • y) := @quasiconvexOn_iff_le_max 𝕜 E βᵒᵈ _ _ _ _ _ _ theorem quasilinearOn_iff_mem_uIcc : QuasilinearOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ∈ uIcc (f x) (f y) := by rw [QuasilinearOn, quasiconvexOn_iff_le_max, quasiconcaveOn_iff_min_le, and_and_and_comm, and_self_iff] apply and_congr_right' simp_rw [← forall_and, ← Icc_min_max, mem_Icc, and_comm] theorem QuasiconvexOn.convex_lt (hf : QuasiconvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := by refine fun x hx y hy a b ha hb hab => ?_ have h := hf _ ⟨hx.1, le_max_left _ _⟩ ⟨hy.1, le_max_right _ _⟩ ha hb hab exact ⟨h.1, h.2.trans_lt <| max_lt hx.2 hy.2⟩ theorem QuasiconcaveOn.convex_gt (hf : QuasiconcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r end LinearOrder_β section OrderedSMul_β variable [OrderedAddCommMonoid β] [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.quasiconvexOn (hf : ConvexOn 𝕜 s f) : QuasiconvexOn 𝕜 s f := hf.convex_le theorem ConcaveOn.quasiconcaveOn (hf : ConcaveOn 𝕜 s f) : QuasiconcaveOn 𝕜 s f := hf.convex_ge end OrderedSMul_β end AddCommMonoid_E section LinearOrderedAddCommMonoid_E variable [LinearOrderedAddCommMonoid E] [OrderedAddCommMonoid β] [Module 𝕜 E] [OrderedSMul 𝕜 E] {s : Set E} {f : E → β} theorem MonotoneOn.quasiconvexOn (hf : MonotoneOn f s) (hs : Convex 𝕜 s) : QuasiconvexOn 𝕜 s f := hf.convex_le hs theorem MonotoneOn.quasiconcaveOn (hf : MonotoneOn f s) (hs : Convex 𝕜 s) : QuasiconcaveOn 𝕜 s f := hf.convex_ge hs theorem MonotoneOn.quasilinearOn (hf : MonotoneOn f s) (hs : Convex 𝕜 s) : QuasilinearOn 𝕜 s f := ⟨hf.quasiconvexOn hs, hf.quasiconcaveOn hs⟩ theorem AntitoneOn.quasiconvexOn (hf : AntitoneOn f s) (hs : Convex 𝕜 s) : QuasiconvexOn 𝕜 s f := hf.convex_le hs theorem AntitoneOn.quasiconcaveOn (hf : AntitoneOn f s) (hs : Convex 𝕜 s) : QuasiconcaveOn 𝕜 s f := hf.convex_ge hs theorem AntitoneOn.quasilinearOn (hf : AntitoneOn f s) (hs : Convex 𝕜 s) : QuasilinearOn 𝕜 s f := ⟨hf.quasiconvexOn hs, hf.quasiconcaveOn hs⟩ theorem Monotone.quasiconvexOn (hf : Monotone f) : QuasiconvexOn 𝕜 univ f := (hf.monotoneOn _).quasiconvexOn convex_univ theorem Monotone.quasiconcaveOn (hf : Monotone f) : QuasiconcaveOn 𝕜 univ f := (hf.monotoneOn _).quasiconcaveOn convex_univ theorem Monotone.quasilinearOn (hf : Monotone f) : QuasilinearOn 𝕜 univ f := ⟨hf.quasiconvexOn, hf.quasiconcaveOn⟩ theorem Antitone.quasiconvexOn (hf : Antitone f) : QuasiconvexOn 𝕜 univ f := (hf.antitoneOn _).quasiconvexOn convex_univ theorem Antitone.quasiconcaveOn (hf : Antitone f) : QuasiconcaveOn 𝕜 univ f := (hf.antitoneOn _).quasiconcaveOn convex_univ theorem Antitone.quasilinearOn (hf : Antitone f) : QuasilinearOn 𝕜 univ f := ⟨hf.quasiconvexOn, hf.quasiconcaveOn⟩ end LinearOrderedAddCommMonoid_E end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] {s : Set 𝕜} {f : 𝕜 → β} theorem QuasilinearOn.monotoneOn_or_antitoneOn [LinearOrder β] (hf : QuasilinearOn 𝕜 s f) : MonotoneOn f s ∨ AntitoneOn f s := by simp_rw [monotoneOn_or_antitoneOn_iff_uIcc, ← segment_eq_uIcc] rintro a ha b hb c _ h refine ⟨((hf.2 _).segment_subset ?_ ?_ h).2, ((hf.1 _).segment_subset ?_ ?_ h).2⟩ <;> simp [*] theorem quasilinearOn_iff_monotoneOn_or_antitoneOn [LinearOrderedAddCommMonoid β] (hs : Convex 𝕜 s) : QuasilinearOn 𝕜 s f ↔ MonotoneOn f s ∨ AntitoneOn f s := ⟨fun h => h.monotoneOn_or_antitoneOn, fun h => h.elim (fun h => h.quasilinearOn hs) fun h => h.quasilinearOn hs⟩ end LinearOrderedField
Analysis\Convex\Radon.lean
/- Copyright (c) 2023 Vasily Nesterov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vasily Nesterov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Data.Set.Card import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Topology.Separation /-! # Radon's theorem on convex sets Radon's theorem states that any affine dependent set can be partitioned into two sets whose convex hulls intersect nontrivially. As a corollary, we prove Helly's theorem, which is a basic result in discrete geometry on the intersection of convex sets. Let `X₁, ⋯, Xₙ` be a finite family of convex sets in `ℝᵈ` with `n ≥ d + 1`. The theorem states that if any `d + 1` sets from this family intersect nontrivially, then the whole family intersect nontrivially. For the infinite family of sets it is not true, as example of `Set.Ioo 0 (1 / n)` for `n : ℕ` shows. But the statement is true, if we assume compactness of sets (see `helly_theorem_compact`) ## Tags convex hull, affine independence, Radon, Helly -/ open Fintype Finset Set namespace Convex variable {ι 𝕜 E : Type*} [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] /-- **Radon's theorem on convex sets**. Any family `f` of affine dependent vectors contains a set `I` with the property that convex hulls of `I` and `Iᶜ` intersect nontrivially. -/ theorem radon_partition {f : ι → E} (h : ¬ AffineIndependent 𝕜 f) : ∃ I, (convexHull 𝕜 (f '' I) ∩ convexHull 𝕜 (f '' Iᶜ)).Nonempty := by rw [affineIndependent_iff] at h push_neg at h obtain ⟨s, w, h_wsum, h_vsum, nonzero_w_index, h1, h2⟩ := h let I : Finset ι := s.filter fun i ↦ 0 ≤ w i let J : Finset ι := s.filter fun i ↦ w i < 0 let p : E := centerMass I w f -- point of intersection have hJI : ∑ j ∈ J, w j + ∑ i ∈ I, w i = 0 := by simpa only [h_wsum, not_lt] using sum_filter_add_sum_filter_not s (fun i ↦ w i < 0) w have hI : 0 < ∑ i ∈ I, w i := by rcases exists_pos_of_sum_zero_of_exists_nonzero _ h_wsum ⟨nonzero_w_index, h1, h2⟩ with ⟨pos_w_index, h1', h2'⟩ exact sum_pos' (fun _i hi ↦ (mem_filter.1 hi).2) ⟨pos_w_index, by simp only [I, mem_filter, h1', h2'.le, and_self, h2']⟩ have hp : centerMass J w f = p := centerMass_of_sum_add_sum_eq_zero hJI <| by simpa only [← h_vsum, not_lt] using sum_filter_add_sum_filter_not s (fun i ↦ w i < 0) _ refine ⟨I, p, ?_, ?_⟩ · exact centerMass_mem_convexHull _ (fun _i hi ↦ (mem_filter.mp hi).2) hI (fun _i hi ↦ mem_image_of_mem _ hi) rw [← hp] refine centerMass_mem_convexHull_of_nonpos _ (fun _ hi ↦ (mem_filter.mp hi).2.le) ?_ (fun _i hi ↦ mem_image_of_mem _ fun hi' ↦ ?_) · linarith only [hI, hJI] · exact (mem_filter.mp hi').2.not_lt (mem_filter.mp hi).2 open FiniteDimensional /-- Corner case for `helly_theorem'`. -/ private lemma helly_theorem_corner {F : ι → Set E} {s : Finset ι} (h_card_small : s.card ≤ finrank 𝕜 E + 1) (h_inter : ∀ I ⊆ s, I.card ≤ finrank 𝕜 E + 1 → (⋂ i ∈ I, F i).Nonempty) : (⋂ i ∈ s, F i).Nonempty := h_inter s (by simp) h_card_small variable [FiniteDimensional 𝕜 E] /-- **Helly's theorem** for finite families of convex sets. If `F` is a finite family of convex sets in a vector space of finite dimension `d`, and any `k ≤ d + 1` sets of `F` intersect nontrivially, then all sets of `F` intersect nontrivially. -/ theorem helly_theorem' {F : ι → Set E} {s : Finset ι} (h_convex : ∀ i ∈ s, Convex 𝕜 (F i)) (h_inter : ∀ I ⊆ s, I.card ≤ finrank 𝕜 E + 1 → (⋂ i ∈ I, F i).Nonempty) : (⋂ i ∈ s, F i).Nonempty := by classical obtain h_card | h_card := lt_or_le s.card (finrank 𝕜 E + 1) · exact helly_theorem_corner (le_of_lt h_card) h_inter generalize hn : s.card = n rw [hn] at h_card induction' n, h_card using Nat.le_induction with k h_card hk generalizing ι · exact helly_theorem_corner (le_of_eq hn) h_inter /- Construct a family of vectors indexed by `ι` such that the vector corresponding to `i : ι` is an arbitrary element of the intersection of all `F j` except `F i`. -/ let a (i : s) : E := Set.Nonempty.some (s := ⋂ j ∈ s.erase i, F j) <| by apply hk (s := s.erase i) · exact fun i hi ↦ h_convex i (mem_of_mem_erase hi) · intro J hJ_ss hJ_card exact h_inter J (subset_trans hJ_ss (erase_subset i.val s)) hJ_card · simp only [coe_mem, card_erase_of_mem]; omega /- This family of vectors is not affine independent because the number of them exceeds the dimension of the space. -/ have h_ind : ¬AffineIndependent 𝕜 a := by rw [← finrank_vectorSpan_le_iff_not_affineIndependent 𝕜 a (n := (k - 1))] · exact (Submodule.finrank_le (vectorSpan 𝕜 (range a))).trans (Nat.le_pred_of_lt h_card) · simp only [card_coe]; omega /- Use `radon_partition` to conclude there is a subset `I` of `s` and a point `p : E` which lies in the convex hull of either `a '' I` or `a '' Iᶜ`. We claim that `p ∈ ⋂ i ∈ s, F i`. -/ obtain ⟨I, p, hp_I, hp_Ic⟩ := radon_partition h_ind use p apply mem_biInter intro i hi let i : s := ⟨i, hi⟩ /- It suffices to show that for any subcollection `J` of `s` containing `i`, the convex hull of `a '' (s \ J)` is contained in `F i`. -/ suffices ∀ J : Set s, (i ∈ J) → (convexHull 𝕜) (a '' Jᶜ) ⊆ F i by by_cases h : i ∈ I · exact this I h hp_Ic · apply this Iᶜ h; rwa [compl_compl] /- Given any subcollection `J` of `ι` containing `i`, because `F i` is convex, we need only show that `a j ∈ F i` for each `j ∈ s \ J`. -/ intro J hi rw [convexHull_subset_iff (h_convex i.1 i.2)] rintro v ⟨j, hj, hj_v⟩ rw [← hj_v] /- Since `j ∈ Jᶜ` and `i ∈ J`, we conclude that `i ≠ j`, and hence by the definition of `a`: `a j ∈ ⋂ F '' (Set.univ \ {j}) ⊆ F i`. -/ apply mem_of_subset_of_mem (s₁ := ⋂ k ∈ (s.erase j), F k) · apply biInter_subset_of_mem simp only [erase_val] suffices h : i.val ∈ s.erase j by assumption simp only [mem_erase] constructor · exact fun h' ↦ hj ((show i = j from SetCoe.ext h') ▸ hi) · assumption · apply Nonempty.some_mem /-- **Helly's theorem** for finite families of convex sets in its classical form. If `F` is a family of `n` convex sets in a vector space of finite dimension `d`, with `n ≥ d + 1`, and any `d + 1` sets of `F` intersect nontrivially, then all sets of `F` intersect nontrivially. -/ theorem helly_theorem {F : ι → Set E} {s : Finset ι} (h_card : finrank 𝕜 E + 1 ≤ s.card) (h_convex : ∀ i ∈ s, Convex 𝕜 (F i)) (h_inter : ∀ I ⊆ s, I.card = finrank 𝕜 E + 1 → (⋂ i ∈ I, F i).Nonempty) : (⋂ i ∈ s, F i).Nonempty := by apply helly_theorem' h_convex intro I hI_ss hI_card obtain ⟨J, hI_ss_J, hJ_ss, hJ_card⟩ := exists_subsuperset_card_eq hI_ss hI_card h_card apply Set.Nonempty.mono <| biInter_mono hI_ss_J (fun _ _ ↦ Set.Subset.rfl) exact h_inter J hJ_ss hJ_card /-- **Helly's theorem** for finite sets of convex sets. If `F` is a finite set of convex sets in a vector space of finite dimension `d`, and any `k ≤ d + 1` sets from `F` intersect nontrivially, then all sets from `F` intersect nontrivially. -/ theorem helly_theorem_set' {F : Finset (Set E)} (h_convex : ∀ X ∈ F, Convex 𝕜 X) (h_inter : ∀ G : Finset (Set E), G ⊆ F → G.card ≤ finrank 𝕜 E + 1 → (⋂₀ G : Set E).Nonempty) : (⋂₀ (F : Set (Set E))).Nonempty := by classical -- for DecidableEq, required for the family version rw [show ⋂₀ F = ⋂ X ∈ F, (X : Set E) by ext; simp] apply helly_theorem' h_convex intro G hG_ss hG_card rw [show ⋂ X ∈ G, X = ⋂₀ G by ext; simp] exact h_inter G hG_ss hG_card /-- **Helly's theorem** for finite sets of convex sets in its classical form. If `F` is a finite set of convex sets in a vector space of finite dimension `d`, with `n ≥ d + 1`, and any `d + 1` sets from `F` intersect nontrivially, then all sets from `F` intersect nontrivially. -/ theorem helly_theorem_set {F : Finset (Set E)} (h_card : finrank 𝕜 E + 1 ≤ F.card) (h_convex : ∀ X ∈ F, Convex 𝕜 X) (h_inter : ∀ G : Finset (Set E), G ⊆ F → G.card = finrank 𝕜 E + 1 → (⋂₀ G : Set E).Nonempty) : (⋂₀ (F : Set (Set E))).Nonempty := by apply helly_theorem_set' h_convex intro I hI_ss hI_card obtain ⟨J, _, hJ_ss, hJ_card⟩ := exists_subsuperset_card_eq hI_ss hI_card h_card have : ⋂₀ (J : Set (Set E)) ⊆ ⋂₀ I := sInter_mono (by simpa [hI_ss]) apply Set.Nonempty.mono this exact h_inter J hJ_ss (by omega) /-- **Helly's theorem** for families of compact convex sets. If `F` is a family of compact convex sets in a vector space of finite dimension `d`, and any `k ≤ d + 1` sets of `F` intersect nontrivially, then all sets of `F` intersect nontrivially. -/ theorem helly_theorem_compact' [TopologicalSpace E] [T2Space E] {F : ι → Set E} (h_convex : ∀ i, Convex 𝕜 (F i)) (h_compact : ∀ i, IsCompact (F i)) (h_inter : ∀ I : Finset ι, I.card ≤ finrank 𝕜 E + 1 → (⋂ i ∈ I, F i).Nonempty) : (⋂ i, F i).Nonempty := by classical /- If `ι` is empty the statement is trivial. -/ cases' isEmpty_or_nonempty ι with _ h_nonempty · simp only [iInter_of_empty, Set.univ_nonempty] /- By the finite version of theorem, every finite subfamily has an intersection. -/ have h_fin (I : Finset ι) : (⋂ i ∈ I, F i).Nonempty := by apply helly_theorem' (s := I) (𝕜 := 𝕜) (by simp [h_convex]) exact fun J _ hJ_card ↦ h_inter J hJ_card /- The following is a clumsy proof that family of compact sets with the finite intersection property has a nonempty intersection. -/ have i0 : ι := Nonempty.some h_nonempty rw [show ⋂ i, F i = (F i0) ∩ ⋂ i, F i by simp [iInter_subset]] apply IsCompact.inter_iInter_nonempty · exact h_compact i0 · intro i exact (h_compact i).isClosed · intro I simpa using h_fin ({i0} ∪ I) /-- **Helly's theorem** for families of compact convex sets in its classical form. If `F` is a (possibly infinite) family of more than `d + 1` compact convex sets in a vector space of finite dimension `d`, and any `d + 1` sets of `F` intersect nontrivially, then all sets of `F` intersect nontrivially. -/ theorem helly_theorem_compact [TopologicalSpace E] [T2Space E] {F : ι → Set E} (h_card : finrank 𝕜 E + 1 ≤ PartENat.card ι) (h_convex : ∀ i, Convex 𝕜 (F i)) (h_compact : ∀ i, IsCompact (F i)) (h_inter : ∀ I : Finset ι, I.card = finrank 𝕜 E + 1 → (⋂ i ∈ I, F i).Nonempty) : (⋂ i, F i).Nonempty := by apply helly_theorem_compact' h_convex h_compact intro I hI_card have hJ : ∃ J : Finset ι, I ⊆ J ∧ J.card = finrank 𝕜 E + 1 := by by_cases h : Infinite ι · exact Infinite.exists_superset_card_eq _ _ hI_card · have : Finite ι := Finite.of_not_infinite h have : Fintype ι := Fintype.ofFinite ι apply exists_superset_card_eq hI_card simp only [PartENat.card_eq_coe_fintype_card] at h_card rwa [← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at h_card obtain ⟨J, hJ_ss, hJ_card⟩ := hJ apply Set.Nonempty.mono <| biInter_mono hJ_ss (by intro _ _; rfl) exact h_inter J hJ_card /-- **Helly's theorem** for sets of compact convex sets. If `F` is a set of compact convex sets in a vector space of finite dimension `d`, and any `k ≤ d + 1` sets from `F` intersect nontrivially, then all sets from `F` intersect nontrivially. -/ theorem helly_theorem_set_compact' [TopologicalSpace E] [T2Space E] {F : Set (Set E)} (h_convex : ∀ X ∈ F, Convex 𝕜 X) (h_compact : ∀ X ∈ F, IsCompact X) (h_inter : ∀ G : Finset (Set E), (G : Set (Set E)) ⊆ F → G.card ≤ finrank 𝕜 E + 1 → (⋂₀ G : Set E).Nonempty) : (⋂₀ (F : Set (Set E))).Nonempty := by classical -- for DecidableEq, required for the family version rw [show ⋂₀ F = ⋂ X : F, (X : Set E) by ext; simp] refine helly_theorem_compact' (F := fun x : F ↦ x.val) (fun X ↦ h_convex X (by simp)) (fun X ↦ h_compact X (by simp)) ?_ intro G _ let G' : Finset (Set E) := image Subtype.val G rw [show ⋂ i ∈ G, ↑i = ⋂₀ (G' : Set (Set E)) by simp [G']] apply h_inter G' · simp [G'] · apply le_trans card_image_le assumption /-- **Helly's theorem** for sets of compact convex sets in its classical version. If `F` is a (possibly infinite) set of more than `d + 1` compact convex sets in a vector space of finite dimension `d`, and any `d + 1` sets from `F` intersect nontrivially, then all sets from `F` intersect nontrivially. -/ theorem helly_theorem_set_compact [TopologicalSpace E] [T2Space E] {F : Set (Set E)} (h_card : finrank 𝕜 E + 1 ≤ F.encard) (h_convex : ∀ X ∈ F, Convex 𝕜 X) (h_compact : ∀ X ∈ F, IsCompact X) (h_inter : ∀ G : Finset (Set E), (G : Set (Set E)) ⊆ F → G.card = finrank 𝕜 E + 1 → (⋂₀ G : Set E).Nonempty) : (⋂₀ (F : Set (Set E))).Nonempty := by apply helly_theorem_set_compact' h_convex h_compact intro I hI_ss hI_card obtain ⟨J, _, hJ_ss, hJ_card⟩ := exists_superset_subset_encard_eq hI_ss (hkt := h_card) (by simpa only [encard_coe_eq_coe_finsetCard, ← ENat.coe_one, ← ENat.coe_add, Nat.cast_le]) apply Set.Nonempty.mono <| sInter_mono (by simpa [hI_ss]) have hJ_fin : Fintype J := Finite.fintype <| finite_of_encard_eq_coe hJ_card let J' := J.toFinset rw [← coe_toFinset J] apply h_inter J' · simpa [J'] · rwa [encard_eq_coe_toFinset_card J, ← ENat.coe_one, ← ENat.coe_add, Nat.cast_inj] at hJ_card end Convex
Analysis\Convex\Segment.lean
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov, Yaël Dillies -/ import Mathlib.Algebra.Order.Invertible import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.LinearAlgebra.AffineSpace.Midpoint import Mathlib.LinearAlgebra.Ray import Mathlib.Tactic.GCongr /-! # Segments in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `segment 𝕜 x y`: Closed segment joining `x` and `y`. * `openSegment 𝕜 x y`: Open segment joining `x` and `y`. ## Notations We provide the following notation: * `[x -[𝕜] y] = segment 𝕜 x y` in locale `Convex` ## TODO Generalize all this file to affine spaces. Should we rename `segment` and `openSegment` to `convex.Icc` and `convex.Ioo`? Should we also define `clopenSegment`/`convex.Ico`/`convex.Ioc`? -/ variable {𝕜 E F G ι : Type*} {π : ι → Type*} open Function Set open Pointwise Convex section OrderedSemiring variable [OrderedSemiring 𝕜] [AddCommMonoid E] section SMul variable (𝕜) [SMul 𝕜 E] {s : Set E} {x y : E} /-- Segments in a vector space. -/ def segment (x y : E) : Set E := { z : E | ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a • x + b • y = z } /-- Open segment in a vector space. Note that `openSegment 𝕜 x x = {x}` instead of being `∅` when the base semiring has some element between `0` and `1`. -/ def openSegment (x y : E) : Set E := { z : E | ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a • x + b • y = z } @[inherit_doc] scoped[Convex] notation (priority := high) "[" x "-[" 𝕜 "]" y "]" => segment 𝕜 x y theorem segment_eq_image₂ (x y : E) : [x -[𝕜] y] = (fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1 } := by simp only [segment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc] theorem openSegment_eq_image₂ (x y : E) : openSegment 𝕜 x y = (fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1 } := by simp only [openSegment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc] theorem segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ theorem openSegment_symm (x y : E) : openSegment 𝕜 x y = openSegment 𝕜 y x := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ theorem openSegment_subset_segment (x y : E) : openSegment 𝕜 x y ⊆ [x -[𝕜] y] := fun _ ⟨a, b, ha, hb, hab, hz⟩ => ⟨a, b, ha.le, hb.le, hab, hz⟩ theorem segment_subset_iff : [x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s := ⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ => hz ▸ H a b ha hb hab⟩ theorem openSegment_subset_iff : openSegment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := ⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ => hz ▸ H a b ha hb hab⟩ end SMul open Convex section MulActionWithZero variable (𝕜) variable [MulActionWithZero 𝕜 E] theorem left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] := ⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩ theorem right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] := segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x end MulActionWithZero section Module variable (𝕜) variable [Module 𝕜 E] {s : Set E} {x y z : E} @[simp] theorem segment_same (x : E) : [x -[𝕜] x] = {x} := Set.ext fun z => ⟨fun ⟨a, b, _, _, hab, hz⟩ => by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz, fun h => mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩ theorem insert_endpoints_openSegment (x y : E) : insert x (insert y (openSegment 𝕜 x y)) = [x -[𝕜] y] := by simp only [subset_antisymm_iff, insert_subset_iff, left_mem_segment, right_mem_segment, openSegment_subset_segment, true_and_iff] rintro z ⟨a, b, ha, hb, hab, rfl⟩ refine hb.eq_or_gt.imp ?_ fun hb' => ha.eq_or_gt.imp ?_ fun ha' => ?_ · rintro rfl rw [← add_zero a, hab, one_smul, zero_smul, add_zero] · rintro rfl rw [← zero_add b, hab, one_smul, zero_smul, zero_add] · exact ⟨a, b, ha', hb', hab, rfl⟩ variable {𝕜} theorem mem_openSegment_of_ne_left_right (hx : x ≠ z) (hy : y ≠ z) (hz : z ∈ [x -[𝕜] y]) : z ∈ openSegment 𝕜 x y := by rw [← insert_endpoints_openSegment] at hz exact (hz.resolve_left hx.symm).resolve_left hy.symm theorem openSegment_subset_iff_segment_subset (hx : x ∈ s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s := by simp only [← insert_endpoints_openSegment, insert_subset_iff, *, true_and_iff] end Module end OrderedSemiring open Convex section OrderedRing variable (𝕜) [OrderedRing 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] [Module 𝕜 E] [Module 𝕜 F] section DenselyOrdered variable [Nontrivial 𝕜] [DenselyOrdered 𝕜] @[simp] theorem openSegment_same (x : E) : openSegment 𝕜 x x = {x} := Set.ext fun z => ⟨fun ⟨a, b, _, _, hab, hz⟩ => by simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz, fun h : z = x => by obtain ⟨a, ha₀, ha₁⟩ := DenselyOrdered.dense (0 : 𝕜) 1 zero_lt_one refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel _ _, ?_⟩ rw [← add_smul, add_sub_cancel, one_smul, h]⟩ end DenselyOrdered theorem segment_eq_image (x y : E) : [x -[𝕜] y] = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 := Set.ext fun z => ⟨fun ⟨a, b, ha, hb, hab, hz⟩ => ⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩, fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ theorem openSegment_eq_image (x y : E) : openSegment 𝕜 x y = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 := Set.ext fun z => ⟨fun ⟨a, b, ha, hb, hab, hz⟩ => ⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩, fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ theorem segment_eq_image' (x y : E) : [x -[𝕜] y] = (fun θ : 𝕜 => x + θ • (y - x)) '' Icc (0 : 𝕜) 1 := by convert segment_eq_image 𝕜 x y using 2 simp only [smul_sub, sub_smul, one_smul] abel theorem openSegment_eq_image' (x y : E) : openSegment 𝕜 x y = (fun θ : 𝕜 => x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 := by convert openSegment_eq_image 𝕜 x y using 2 simp only [smul_sub, sub_smul, one_smul] abel theorem segment_eq_image_lineMap (x y : E) : [x -[𝕜] y] = AffineMap.lineMap x y '' Icc (0 : 𝕜) 1 := by convert segment_eq_image 𝕜 x y using 2 exact AffineMap.lineMap_apply_module _ _ _ theorem openSegment_eq_image_lineMap (x y : E) : openSegment 𝕜 x y = AffineMap.lineMap x y '' Ioo (0 : 𝕜) 1 := by convert openSegment_eq_image 𝕜 x y using 2 exact AffineMap.lineMap_apply_module _ _ _ @[simp] theorem image_segment (f : E →ᵃ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] := Set.ext fun x => by simp_rw [segment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap] @[simp] theorem image_openSegment (f : E →ᵃ[𝕜] F) (a b : E) : f '' openSegment 𝕜 a b = openSegment 𝕜 (f a) (f b) := Set.ext fun x => by simp_rw [openSegment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap] @[simp] theorem vadd_segment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) : a +ᵥ [b -[𝕜] c] = [a +ᵥ b -[𝕜] a +ᵥ c] := image_segment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c @[simp] theorem vadd_openSegment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) : a +ᵥ openSegment 𝕜 b c = openSegment 𝕜 (a +ᵥ b) (a +ᵥ c) := image_openSegment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c @[simp] theorem mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] := by simp_rw [← vadd_eq_add, ← vadd_segment, vadd_mem_vadd_set_iff] @[simp] theorem mem_openSegment_translate (a : E) {x b c : E} : a + x ∈ openSegment 𝕜 (a + b) (a + c) ↔ x ∈ openSegment 𝕜 b c := by simp_rw [← vadd_eq_add, ← vadd_openSegment, vadd_mem_vadd_set_iff] theorem segment_translate_preimage (a b c : E) : (fun x => a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] := Set.ext fun _ => mem_segment_translate 𝕜 a theorem openSegment_translate_preimage (a b c : E) : (fun x => a + x) ⁻¹' openSegment 𝕜 (a + b) (a + c) = openSegment 𝕜 b c := Set.ext fun _ => mem_openSegment_translate 𝕜 a theorem segment_translate_image (a b c : E) : (fun x => a + x) '' [b -[𝕜] c] = [a + b -[𝕜] a + c] := segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ <| add_left_surjective a theorem openSegment_translate_image (a b c : E) : (fun x => a + x) '' openSegment 𝕜 b c = openSegment 𝕜 (a + b) (a + c) := openSegment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ <| add_left_surjective a lemma segment_inter_eq_endpoint_of_linearIndependent_sub {c x y : E} (h : LinearIndependent 𝕜 ![x - c, y - c]) : [c -[𝕜] x] ∩ [c -[𝕜] y] = {c} := by apply Subset.antisymm; swap · simp [singleton_subset_iff, left_mem_segment] intro z ⟨hzt, hzs⟩ rw [segment_eq_image, mem_image] at hzt hzs rcases hzt with ⟨p, ⟨p0, p1⟩, rfl⟩ rcases hzs with ⟨q, ⟨q0, q1⟩, H⟩ have Hx : x = (x - c) + c := by abel have Hy : y = (y - c) + c := by abel rw [Hx, Hy, smul_add, smul_add] at H have : c + q • (y - c) = c + p • (x - c) := by convert H using 1 <;> simp [sub_smul] obtain ⟨rfl, rfl⟩ : p = 0 ∧ q = 0 := h.eq_zero_of_pair' ((add_right_inj c).1 this).symm simp end OrderedRing theorem sameRay_of_mem_segment [StrictOrderedCommRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E} (h : x ∈ [y -[𝕜] z]) : SameRay 𝕜 (x - y) (z - x) := by rw [segment_eq_image'] at h rcases h with ⟨θ, ⟨hθ₀, hθ₁⟩, rfl⟩ simpa only [add_sub_cancel_left, ← sub_sub, sub_smul, one_smul] using (SameRay.sameRay_nonneg_smul_left (z - y) hθ₀).nonneg_smul_right (sub_nonneg.2 hθ₁) lemma segment_inter_eq_endpoint_of_linearIndependent_of_ne [OrderedCommRing 𝕜] [NoZeroDivisors 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y : E} (h : LinearIndependent 𝕜 ![x, y]) {s t : 𝕜} (hs : s ≠ t) (c : E) : [c + x -[𝕜] c + t • y] ∩ [c + x -[𝕜] c + s • y] = {c + x} := by apply segment_inter_eq_endpoint_of_linearIndependent_sub simp only [add_sub_add_left_eq_sub] suffices H : LinearIndependent 𝕜 ![(-1 : 𝕜) • x + t • y, (-1 : 𝕜) • x + s • y] by convert H using 1; simp only [neg_smul, one_smul]; abel_nf apply h.linear_combination_pair_of_det_ne_zero contrapose! hs apply Eq.symm simpa [neg_mul, one_mul, mul_neg, mul_one, sub_neg_eq_add, add_comm _ t, ← sub_eq_add_neg, sub_eq_zero] using hs section LinearOrderedRing variable [LinearOrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y : E} theorem midpoint_mem_segment [Invertible (2 : 𝕜)] (x y : E) : midpoint 𝕜 x y ∈ [x -[𝕜] y] := by rw [segment_eq_image_lineMap] exact ⟨⅟ 2, ⟨invOf_nonneg.mpr zero_le_two, invOf_le_one one_le_two⟩, rfl⟩ theorem mem_segment_sub_add [Invertible (2 : 𝕜)] (x y : E) : x ∈ [x - y -[𝕜] x + y] := by convert @midpoint_mem_segment 𝕜 _ _ _ _ _ (x - y) (x + y) rw [midpoint_sub_add] theorem mem_segment_add_sub [Invertible (2 : 𝕜)] (x y : E) : x ∈ [x + y -[𝕜] x - y] := by convert @midpoint_mem_segment 𝕜 _ _ _ _ _ (x + y) (x - y) rw [midpoint_add_sub] @[simp] theorem left_mem_openSegment_iff [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] : x ∈ openSegment 𝕜 x y ↔ x = y := by constructor · rintro ⟨a, b, _, hb, hab, hx⟩ refine smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 ?_) rw [hx, ← add_smul, hab, one_smul] · rintro rfl rw [openSegment_same] exact mem_singleton _ @[simp] theorem right_mem_openSegment_iff [DenselyOrdered 𝕜] [NoZeroSMulDivisors 𝕜 E] : y ∈ openSegment 𝕜 x y ↔ x = y := by rw [openSegment_symm, left_mem_openSegment_iff, eq_comm] end LinearOrderedRing section LinearOrderedSemifield variable [LinearOrderedSemifield 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E} theorem mem_segment_iff_div : x ∈ [y -[𝕜] z] ↔ ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := by constructor · rintro ⟨a, b, ha, hb, hab, rfl⟩ use a, b, ha, hb simp [*] · rintro ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, ?_, rfl⟩ rw [← add_div, div_self hab.ne'] theorem mem_openSegment_iff_div : x ∈ openSegment 𝕜 y z ↔ ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := by constructor · rintro ⟨a, b, ha, hb, hab, rfl⟩ use a, b, ha, hb rw [hab, div_one, div_one] · rintro ⟨a, b, ha, hb, rfl⟩ have hab : 0 < a + b := add_pos' ha hb refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, ?_, rfl⟩ rw [← add_div, div_self hab.ne'] end LinearOrderedSemifield section LinearOrderedField variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {x y z : E} theorem mem_segment_iff_sameRay : x ∈ [y -[𝕜] z] ↔ SameRay 𝕜 (x - y) (z - x) := by refine ⟨sameRay_of_mem_segment, fun h => ?_⟩ rcases h.exists_eq_smul_add with ⟨a, b, ha, hb, hab, hxy, hzx⟩ rw [add_comm, sub_add_sub_cancel] at hxy hzx rw [← mem_segment_translate _ (-x), neg_add_self] refine ⟨b, a, hb, ha, add_comm a b ▸ hab, ?_⟩ rw [← sub_eq_neg_add, ← neg_sub, hxy, ← sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_self] open AffineMap /-- If `z = lineMap x y c` is a point on the line passing through `x` and `y`, then the open segment `openSegment 𝕜 x y` is included in the union of the open segments `openSegment 𝕜 x z`, `openSegment 𝕜 z y`, and the point `z`. Informally, `(x, y) ⊆ {z} ∪ (x, z) ∪ (z, y)`. -/ theorem openSegment_subset_union (x y : E) {z : E} (hz : z ∈ range (lineMap x y : 𝕜 → E)) : openSegment 𝕜 x y ⊆ insert z (openSegment 𝕜 x z ∪ openSegment 𝕜 z y) := by rcases hz with ⟨c, rfl⟩ simp only [openSegment_eq_image_lineMap, ← mapsTo'] rintro a ⟨h₀, h₁⟩ rcases lt_trichotomy a c with (hac | rfl | hca) · right left have hc : 0 < c := h₀.trans hac refine ⟨a / c, ⟨div_pos h₀ hc, (div_lt_one hc).2 hac⟩, ?_⟩ simp only [← homothety_eq_lineMap, ← homothety_mul_apply, div_mul_cancel₀ _ hc.ne'] · left rfl · right right have hc : 0 < 1 - c := sub_pos.2 (hca.trans h₁) simp only [← lineMap_apply_one_sub y] refine ⟨(a - c) / (1 - c), ⟨div_pos (sub_pos.2 hca) hc, (div_lt_one hc).2 <| sub_lt_sub_right h₁ _⟩, ?_⟩ simp only [← homothety_eq_lineMap, ← homothety_mul_apply, sub_mul, one_mul, div_mul_cancel₀ _ hc.ne', sub_sub_sub_cancel_right] end LinearOrderedField /-! #### Segments in an ordered space Relates `segment`, `openSegment` and `Set.Icc`, `Set.Ico`, `Set.Ioc`, `Set.Ioo` -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section OrderedAddCommMonoid variable [OrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E} theorem segment_subset_Icc (h : x ≤ y) : [x -[𝕜] y] ⊆ Icc x y := by rintro z ⟨a, b, ha, hb, hab, rfl⟩ constructor · calc x = a • x + b • x := (Convex.combo_self hab _).symm _ ≤ a • x + b • y := by gcongr · calc a • x + b • y ≤ a • y + b • y := by gcongr _ = y := Convex.combo_self hab _ end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [OrderedCancelAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E} theorem openSegment_subset_Ioo (h : x < y) : openSegment 𝕜 x y ⊆ Ioo x y := by rintro z ⟨a, b, ha, hb, hab, rfl⟩ constructor · calc x = a • x + b • x := (Convex.combo_self hab _).symm _ < a • x + b • y := by gcongr · calc a • x + b • y < a • y + b • y := by gcongr _ = y := Convex.combo_self hab _ end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [LinearOrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {a b : 𝕜} theorem segment_subset_uIcc (x y : E) : [x -[𝕜] y] ⊆ uIcc x y := by rcases le_total x y with h | h · rw [uIcc_of_le h] exact segment_subset_Icc h · rw [uIcc_of_ge h, segment_symm] exact segment_subset_Icc h theorem Convex.min_le_combo (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min x y ≤ a • x + b • y := (segment_subset_uIcc x y ⟨_, _, ha, hb, hab, rfl⟩).1 theorem Convex.combo_le_max (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ≤ max x y := (segment_subset_uIcc x y ⟨_, _, ha, hb, hab, rfl⟩).2 end LinearOrderedAddCommMonoid end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] {x y z : 𝕜} theorem Icc_subset_segment : Icc x y ⊆ [x -[𝕜] y] := by rintro z ⟨hxz, hyz⟩ obtain rfl | h := (hxz.trans hyz).eq_or_lt · rw [segment_same] exact hyz.antisymm hxz rw [← sub_nonneg] at hxz hyz rw [← sub_pos] at h refine ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, ?_, ?_⟩ · rw [← add_div, sub_add_sub_cancel, div_self h.ne'] · rw [smul_eq_mul, smul_eq_mul, ← mul_div_right_comm, ← mul_div_right_comm, ← add_div, div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub] @[simp] theorem segment_eq_Icc (h : x ≤ y) : [x -[𝕜] y] = Icc x y := (segment_subset_Icc h).antisymm Icc_subset_segment theorem Ioo_subset_openSegment : Ioo x y ⊆ openSegment 𝕜 x y := fun _ hz => mem_openSegment_of_ne_left_right hz.1.ne hz.2.ne' <| Icc_subset_segment <| Ioo_subset_Icc_self hz @[simp] theorem openSegment_eq_Ioo (h : x < y) : openSegment 𝕜 x y = Ioo x y := (openSegment_subset_Ioo h).antisymm Ioo_subset_openSegment theorem segment_eq_Icc' (x y : 𝕜) : [x -[𝕜] y] = Icc (min x y) (max x y) := by rcases le_total x y with h | h · rw [segment_eq_Icc h, max_eq_right h, min_eq_left h] · rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h] theorem openSegment_eq_Ioo' (hxy : x ≠ y) : openSegment 𝕜 x y = Ioo (min x y) (max x y) := by cases' hxy.lt_or_lt with h h · rw [openSegment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le] · rw [openSegment_symm, openSegment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le] theorem segment_eq_uIcc (x y : 𝕜) : [x -[𝕜] y] = uIcc x y := segment_eq_Icc' _ _ /-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/ theorem Convex.mem_Icc (h : x ≤ y) : z ∈ Icc x y ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by simp only [← segment_eq_Icc h, segment, mem_setOf_eq, smul_eq_mul, exists_and_left] /-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints. -/ theorem Convex.mem_Ioo (h : x < y) : z ∈ Ioo x y ↔ ∃ a b, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by simp only [← openSegment_eq_Ioo h, openSegment, smul_eq_mul, exists_and_left, mem_setOf_eq] /-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the endpoints. -/ theorem Convex.mem_Ioc (h : x < y) : z ∈ Ioc x y ↔ ∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by refine ⟨fun hz => ?_, ?_⟩ · obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz) obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rw [hab, one_mul, zero_mul, add_zero] at hz exact (hz.1.ne rfl).elim · exact ⟨a, b, ha, hb', hab, rfl⟩ · rintro ⟨a, b, ha, hb, hab, rfl⟩ obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc] · exact Ioo_subset_Ioc_self ((Convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩) /-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the endpoints. -/ theorem Convex.mem_Ico (h : x < y) : z ∈ Ico x y ↔ ∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by refine ⟨fun hz => ?_, ?_⟩ · obtain ⟨a, b, ha, hb, hab, rfl⟩ := (Convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz) obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rw [hab, one_mul, zero_mul, zero_add] at hz exact (hz.2.ne rfl).elim · exact ⟨a, b, ha', hb, hab, rfl⟩ · rintro ⟨a, b, ha, hb, hab, rfl⟩ obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico] · exact Ioo_subset_Ico_self ((Convex.mem_Ioo h).2 ⟨a, b, ha, hb', hab, rfl⟩) end LinearOrderedField namespace Prod variable [OrderedSemiring 𝕜] [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] theorem segment_subset (x y : E × F) : segment 𝕜 x y ⊆ segment 𝕜 x.1 y.1 ×ˢ segment 𝕜 x.2 y.2 := by rintro z ⟨a, b, ha, hb, hab, hz⟩ exact ⟨⟨a, b, ha, hb, hab, congr_arg Prod.fst hz⟩, a, b, ha, hb, hab, congr_arg Prod.snd hz⟩ theorem openSegment_subset (x y : E × F) : openSegment 𝕜 x y ⊆ openSegment 𝕜 x.1 y.1 ×ˢ openSegment 𝕜 x.2 y.2 := by rintro z ⟨a, b, ha, hb, hab, hz⟩ exact ⟨⟨a, b, ha, hb, hab, congr_arg Prod.fst hz⟩, a, b, ha, hb, hab, congr_arg Prod.snd hz⟩ theorem image_mk_segment_left (x₁ x₂ : E) (y : F) : (fun x => (x, y)) '' [x₁ -[𝕜] x₂] = [(x₁, y) -[𝕜] (x₂, y)] := by rw [segment_eq_image₂, segment_eq_image₂, image_image] refine EqOn.image_eq fun a ha ↦ ?_ simp [Convex.combo_self ha.2.2] theorem image_mk_segment_right (x : E) (y₁ y₂ : F) : (fun y => (x, y)) '' [y₁ -[𝕜] y₂] = [(x, y₁) -[𝕜] (x, y₂)] := by rw [segment_eq_image₂, segment_eq_image₂, image_image] refine EqOn.image_eq fun a ha ↦ ?_ simp [Convex.combo_self ha.2.2] theorem image_mk_openSegment_left (x₁ x₂ : E) (y : F) : (fun x => (x, y)) '' openSegment 𝕜 x₁ x₂ = openSegment 𝕜 (x₁, y) (x₂, y) := by rw [openSegment_eq_image₂, openSegment_eq_image₂, image_image] refine EqOn.image_eq fun a ha ↦ ?_ simp [Convex.combo_self ha.2.2] @[simp] theorem image_mk_openSegment_right (x : E) (y₁ y₂ : F) : (fun y => (x, y)) '' openSegment 𝕜 y₁ y₂ = openSegment 𝕜 (x, y₁) (x, y₂) := by rw [openSegment_eq_image₂, openSegment_eq_image₂, image_image] refine EqOn.image_eq fun a ha ↦ ?_ simp [Convex.combo_self ha.2.2] end Prod namespace Pi variable [OrderedSemiring 𝕜] [∀ i, AddCommMonoid (π i)] [∀ i, Module 𝕜 (π i)] {s : Set ι} theorem segment_subset (x y : ∀ i, π i) : segment 𝕜 x y ⊆ s.pi fun i => segment 𝕜 (x i) (y i) := by rintro z ⟨a, b, ha, hb, hab, hz⟩ i - exact ⟨a, b, ha, hb, hab, congr_fun hz i⟩ theorem openSegment_subset (x y : ∀ i, π i) : openSegment 𝕜 x y ⊆ s.pi fun i => openSegment 𝕜 (x i) (y i) := by rintro z ⟨a, b, ha, hb, hab, hz⟩ i - exact ⟨a, b, ha, hb, hab, congr_fun hz i⟩ variable [DecidableEq ι] theorem image_update_segment (i : ι) (x₁ x₂ : π i) (y : ∀ i, π i) : update y i '' [x₁ -[𝕜] x₂] = [update y i x₁ -[𝕜] update y i x₂] := by rw [segment_eq_image₂, segment_eq_image₂, image_image] refine EqOn.image_eq fun a ha ↦ ?_ simp only [← update_smul, ← update_add, Convex.combo_self ha.2.2] theorem image_update_openSegment (i : ι) (x₁ x₂ : π i) (y : ∀ i, π i) : update y i '' openSegment 𝕜 x₁ x₂ = openSegment 𝕜 (update y i x₁) (update y i x₂) := by rw [openSegment_eq_image₂, openSegment_eq_image₂, image_image] refine EqOn.image_eq fun a ha ↦ ?_ simp only [← update_smul, ← update_add, Convex.combo_self ha.2.2] end Pi
Analysis\Convex\Side.lean
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.Normed.Group.AddTorsor /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂) /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x ∉ s ∧ y ∉ s /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := ∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x ∉ s ∧ y ∉ s theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩ rw [mem_map] at hfp₁ hfp₂ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfp₂ with ⟨p₂, hp₂, rfl⟩ refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : (s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y := (show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff @[simp] theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') : (s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y := (show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : s.WSameSide x y := h.1 theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x ∉ s := h.2.1 theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y ∉ s := h.2.2 theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x ∉ s := h.2.1 theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y ∉ s := h.2.2 theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x := ⟨fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩, fun ⟨p₁, hp₁, p₂, hp₂, h⟩ => ⟨p₂, hp₂, p₁, hp₁, h.symm⟩⟩ alias ⟨WSameSide.symm, _⟩ := wSameSide_comm theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x ∉ s)] alias ⟨SSameSide.symm, _⟩ := sSameSide_comm theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] alias ⟨WOppSide.symm, _⟩ := wOppSide_comm theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x ∉ s)] alias ⟨SOppSide.symm, _⟩ := sOppSide_comm theorem not_wSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WSameSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sSameSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SSameSide x y := fun h => not_wSameSide_bot x y h.wSameSide theorem not_wOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).WOppSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sOppSide_bot (x y : P) : ¬(⊥ : AffineSubspace R P).SOppSide x y := fun h => not_wOppSide_bot x y h.wOppSide @[simp] theorem wSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.WSameSide x x ↔ (s : Set P).Nonempty := ⟨fun h => h.nonempty, fun ⟨p, hp⟩ => ⟨p, hp, p, hp, SameRay.rfl⟩⟩ theorem sSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.SSameSide x x ↔ (s : Set P).Nonempty ∧ x ∉ s := ⟨fun ⟨h, hx, _⟩ => ⟨wSameSide_self_iff.1 h, hx⟩, fun ⟨h, hx⟩ => ⟨wSameSide_self_iff.2 h, hx, hx⟩⟩ theorem wSameSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WSameSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left theorem wSameSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WSameSide x y := (wSameSide_of_left_mem x hy).symm theorem wOppSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left theorem wOppSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WOppSide x y := (wOppSide_of_left_mem x hy).symm theorem wSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide (v +ᵥ x) y ↔ s.WSameSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] theorem wSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide x (v +ᵥ y) ↔ s.WSameSide x y := by rw [wSameSide_comm, wSameSide_vadd_left_iff hv, wSameSide_comm] theorem sSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide (v +ᵥ x) y ↔ s.SSameSide x y := by rw [SSameSide, SSameSide, wSameSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] theorem sSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide x (v +ᵥ y) ↔ s.SSameSide x y := by rw [sSameSide_comm, sSameSide_vadd_left_iff hv, sSameSide_comm] theorem wOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide (v +ᵥ x) y ↔ s.WOppSide x y := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨-v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, p₂, hp₂, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ refine ⟨v +ᵥ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, p₂, hp₂, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] theorem wOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WOppSide x (v +ᵥ y) ↔ s.WOppSide x y := by rw [wOppSide_comm, wOppSide_vadd_left_iff hv, wOppSide_comm] theorem sOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide (v +ᵥ x) y ↔ s.SOppSide x y := by rw [SOppSide, SOppSide, wOppSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv] theorem sOppSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SOppSide x (v +ᵥ y) ↔ s.SOppSide x y := by rw [sOppSide_comm, sOppSide_vadd_left_iff hv, sOppSide_comm] theorem wSameSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub] exact SameRay.sameRay_nonneg_smul_left _ ht theorem wSameSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wSameSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm theorem wSameSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide (lineMap x y t) y := wSameSide_smul_vsub_vadd_left y h h ht theorem wSameSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : 0 ≤ t) : s.WSameSide y (lineMap x y t) := (wSameSide_lineMap_left y h ht).symm theorem wOppSide_smul_vsub_vadd_left {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨p₂, hp₂, p₁, hp₁, ?_⟩ rw [vadd_vsub, ← neg_neg t, neg_smul, ← smul_neg, neg_vsub_eq_vsub_rev] exact SameRay.sameRay_nonneg_smul_left _ (neg_nonneg.2 ht) theorem wOppSide_smul_vsub_vadd_right {s : AffineSubspace R P} {p₁ p₂ : P} (x : P) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (wOppSide_smul_vsub_vadd_left x hp₁ hp₂ ht).symm theorem wOppSide_lineMap_left {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide (lineMap x y t) y := wOppSide_smul_vsub_vadd_left y h h ht theorem wOppSide_lineMap_right {s : AffineSubspace R P} {x : P} (y : P) (h : x ∈ s) {t : R} (ht : t ≤ 0) : s.WOppSide y (lineMap x y t) := (wOppSide_lineMap_left y h ht).symm theorem _root_.Wbtw.wSameSide₂₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide y z := by rcases h with ⟨t, ⟨ht0, -⟩, rfl⟩ exact wSameSide_lineMap_left z hx ht0 theorem _root_.Wbtw.wSameSide₃₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hx : x ∈ s) : s.WSameSide z y := (h.wSameSide₂₃ hx).symm theorem _root_.Wbtw.wSameSide₁₂ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide x y := h.symm.wSameSide₃₂ hz theorem _root_.Wbtw.wSameSide₂₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hz : z ∈ s) : s.WSameSide y x := h.symm.wSameSide₂₃ hz theorem _root_.Wbtw.wOppSide₁₃ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide x z := by rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩ refine ⟨_, hy, _, hy, ?_⟩ rcases ht1.lt_or_eq with (ht1' | rfl); swap · rw [lineMap_apply_one]; simp rcases ht0.lt_or_eq with (ht0' | rfl); swap · rw [lineMap_apply_zero]; simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) -- TODO: after lean4#2336 "simp made no progress feature" -- had to add `_` to several lemmas here. Not sure why! simp_rw [lineMap_apply _, vadd_vsub_assoc _, vsub_vadd_eq_vsub_sub _, ← neg_vsub_eq_vsub_rev z x, vsub_self _, zero_sub, ← neg_one_smul R (z -ᵥ x), ← add_smul, smul_neg, ← neg_smul, smul_smul] ring_nf theorem _root_.Wbtw.wOppSide₃₁ {s : AffineSubspace R P} {x y z : P} (h : Wbtw R x y z) (hy : y ∈ s) : s.WOppSide z x := h.symm.wOppSide₁₃ hy end StrictOrderedCommRing section LinearOrderedField variable [LinearOrderedField R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] @[simp] theorem wOppSide_self_iff {s : AffineSubspace R P} {x : P} : s.WOppSide x x ↔ x ∈ s := by constructor · rintro ⟨p₁, hp₁, p₂, hp₂, h⟩ obtain ⟨a, -, -, -, -, h₁, -⟩ := h.exists_eq_smul_add rw [add_comm, vsub_add_vsub_cancel, ← eq_vadd_iff_vsub_eq] at h₁ rw [h₁] exact s.smul_vsub_vadd_mem a hp₂ hp₁ hp₁ · exact fun h => ⟨x, h, x, h, SameRay.rfl⟩ theorem not_sOppSide_self (s : AffineSubspace R P) (x : P) : ¬s.SOppSide x x := by rw [SOppSide] simp theorem wSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WSameSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vsub_vadd_eq_vsub_sub, smul_sub, ← hr, smul_smul, mul_div_cancel₀ _ hr₂.ne.symm, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wSameSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ theorem wSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WSameSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [wSameSide_comm, wSameSide_iff_exists_left h] simp_rw [SameRay.sameRay_comm] theorem sSameSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [SSameSide, and_comm, wSameSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] theorem sSameSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SSameSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (y -ᵥ p₂) := by rw [sSameSide_comm, sSameSide_iff_exists_left h, ← and_assoc, and_comm (a := y ∉ s), and_assoc] simp_rw [SameRay.sameRay_comm] theorem wOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.WOppSide x y ↔ x ∈ s ∨ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by constructor · rintro ⟨p₁', hp₁', p₂', hp₂', h0 | h0 | ⟨r₁, r₂, hr₁, hr₂, hr⟩⟩ · rw [vsub_eq_zero_iff_eq] at h0 rw [h0] exact Or.inl hp₁' · refine Or.inr ⟨p₂', hp₂', ?_⟩ rw [h0] exact SameRay.zero_right _ · refine Or.inr ⟨(-r₁ / r₂) • (p₁ -ᵥ p₁') +ᵥ p₂', s.smul_vsub_vadd_mem _ h hp₁' hp₂', Or.inr (Or.inr ⟨r₁, r₂, hr₁, hr₂, ?_⟩)⟩ rw [vadd_vsub_assoc, smul_add, ← hr, smul_smul, neg_div, mul_neg, mul_div_cancel₀ _ hr₂.ne.symm, neg_smul, neg_add_eq_sub, ← smul_sub, vsub_sub_vsub_cancel_right] · rintro (h' | ⟨h₁, h₂, h₃⟩) · exact wOppSide_of_left_mem y h' · exact ⟨p₁, h, h₁, h₂, h₃⟩ theorem wOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.WOppSide x y ↔ y ∈ s ∨ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [wOppSide_comm, wOppSide_iff_exists_left h] constructor · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] · rintro (hy | ⟨p, hp, hr⟩) · exact Or.inl hy refine Or.inr ⟨p, hp, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] theorem sOppSide_iff_exists_left {s : AffineSubspace R P} {x y p₁ : P} (h : p₁ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₂ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [SOppSide, and_comm, wOppSide_iff_exists_left h, and_assoc, and_congr_right_iff] intro hx rw [or_iff_right hx] theorem sOppSide_iff_exists_right {s : AffineSubspace R P} {x y p₂ : P} (h : p₂ ∈ s) : s.SOppSide x y ↔ x ∉ s ∧ y ∉ s ∧ ∃ p₁ ∈ s, SameRay R (x -ᵥ p₁) (p₂ -ᵥ y) := by rw [SOppSide, and_comm, wOppSide_iff_exists_right h, and_assoc, and_congr_right_iff, and_congr_right_iff] rintro _ hy rw [or_iff_right hy] theorem WSameSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.WSameSide y z) (hy : y ∉ s) : s.WSameSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wSameSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h.symm ▸ hp₂) theorem WSameSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.SSameSide y z) : s.WSameSide x z := hxy.trans hyz.1 hyz.2.1 theorem WSameSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.WOppSide y z) (hy : y ∉ s) : s.WOppSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wOppSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h.symm ▸ hp₂) theorem WSameSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WSameSide x y) (hyz : s.SOppSide y z) : s.WOppSide x z := hxy.trans_wOppSide hyz.1 hyz.2.1 theorem SSameSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.WSameSide y z) : s.WSameSide x z := (hyz.symm.trans_sSameSide hxy.symm).symm theorem SSameSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.SSameSide y z) : s.SSameSide x z := ⟨hxy.wSameSide.trans_sSameSide hyz, hxy.2.1, hyz.2.2⟩ theorem SSameSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.WOppSide y z) : s.WOppSide x z := hxy.wSameSide.trans_wOppSide hyz hxy.2.2 theorem SSameSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SSameSide x y) (hyz : s.SOppSide y z) : s.SOppSide x z := ⟨hxy.trans_wOppSide hyz.1, hxy.2.1, hyz.2.2⟩ theorem WOppSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.WSameSide y z) (hy : y ∉ s) : s.WOppSide x z := (hyz.symm.trans_wOppSide hxy.symm hy).symm theorem WOppSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.SSameSide y z) : s.WOppSide x z := hxy.trans_wSameSide hyz.1 hyz.2.1 theorem WOppSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.WOppSide y z) (hy : y ∉ s) : s.WSameSide x z := by rcases hxy with ⟨p₁, hp₁, p₂, hp₂, hxy⟩ rw [wOppSide_iff_exists_left hp₂, or_iff_right hy] at hyz rcases hyz with ⟨p₃, hp₃, hyz⟩ rw [← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] at hyz refine ⟨p₁, hp₁, p₃, hp₃, hxy.trans hyz ?_⟩ refine fun h => False.elim ?_ rw [vsub_eq_zero_iff_eq] at h exact hy (h ▸ hp₂) theorem WOppSide.trans_sOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.WOppSide x y) (hyz : s.SOppSide y z) : s.WSameSide x z := hxy.trans hyz.1 hyz.2.1 theorem SOppSide.trans_wSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.WSameSide y z) : s.WOppSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm theorem SOppSide.trans_sSameSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.SSameSide y z) : s.SOppSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm theorem SOppSide.trans_wOppSide {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.WOppSide y z) : s.WSameSide x z := (hyz.symm.trans_sOppSide hxy.symm).symm theorem SOppSide.trans {s : AffineSubspace R P} {x y z : P} (hxy : s.SOppSide x y) (hyz : s.SOppSide y z) : s.SSameSide x z := ⟨hxy.trans_wOppSide hyz.1, hxy.2.1, hyz.2.2⟩ theorem wSameSide_and_wOppSide_iff {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ∧ s.WOppSide x y ↔ x ∈ s ∨ y ∈ s := by constructor · rintro ⟨hs, ho⟩ rw [wOppSide_comm] at ho by_contra h rw [not_or] at h exact h.1 (wOppSide_self_iff.1 (hs.trans_wOppSide ho h.2)) · rintro (h | h) · exact ⟨wSameSide_of_left_mem y h, wOppSide_of_left_mem y h⟩ · exact ⟨wSameSide_of_right_mem x h, wOppSide_of_right_mem x h⟩ theorem WSameSide.not_sOppSide {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : ¬s.SOppSide x y := by intro ho have hxy := wSameSide_and_wOppSide_iff.1 ⟨h, ho.1⟩ rcases hxy with (hx | hy) · exact ho.2.1 hx · exact ho.2.2 hy theorem SSameSide.not_wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : ¬s.WOppSide x y := by intro ho have hxy := wSameSide_and_wOppSide_iff.1 ⟨h.1, ho⟩ rcases hxy with (hx | hy) · exact h.2.1 hx · exact h.2.2 hy theorem SSameSide.not_sOppSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : ¬s.SOppSide x y := fun ho => h.not_wOppSide ho.1 theorem WOppSide.not_sSameSide {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : ¬s.SSameSide x y := fun hs => hs.not_wOppSide h theorem SOppSide.not_wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : ¬s.WSameSide x y := fun hs => hs.not_sOppSide h theorem SOppSide.not_sSameSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : ¬s.SSameSide x y := fun hs => h.not_wSameSide hs.1 theorem wOppSide_iff_exists_wbtw {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ ∃ p ∈ s, Wbtw R x p y := by refine ⟨fun h => ?_, fun ⟨p, hp, h⟩ => h.wOppSide₁₃ hp⟩ rcases h with ⟨p₁, hp₁, p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h rw [h] exact ⟨p₁, hp₁, wbtw_self_left _ _ _⟩ · rw [vsub_eq_zero_iff_eq] at h rw [← h] exact ⟨p₂, hp₂, wbtw_self_right _ _ _⟩ · refine ⟨lineMap x y (r₂ / (r₁ + r₂)), ?_, ?_⟩ · have : (r₂ / (r₁ + r₂)) • (y -ᵥ p₂ + (p₂ -ᵥ p₁) - (x -ᵥ p₁)) + (x -ᵥ p₁) = (r₂ / (r₁ + r₂)) • (p₂ -ᵥ p₁) := by rw [add_comm (y -ᵥ p₂), smul_sub, smul_add, add_sub_assoc, add_assoc, add_right_eq_self, div_eq_inv_mul, ← neg_vsub_eq_vsub_rev, smul_neg, ← smul_smul, ← h, smul_smul, ← neg_smul, ← sub_smul, ← div_eq_inv_mul, ← div_eq_inv_mul, ← neg_div, ← sub_div, sub_eq_add_neg, ← neg_add, neg_div, div_self (Left.add_pos hr₁ hr₂).ne.symm, neg_one_smul, neg_add_self] rw [lineMap_apply, ← vsub_vadd x p₁, ← vsub_vadd y p₂, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, ← vadd_assoc, vadd_eq_add, this] exact s.smul_vsub_vadd_mem (r₂ / (r₁ + r₂)) hp₂ hp₁ hp₁ · exact Set.mem_image_of_mem _ ⟨div_nonneg hr₂.le (Left.add_pos hr₁ hr₂).le, div_le_one_of_le (le_add_of_nonneg_left hr₁.le) (Left.add_pos hr₁ hr₂).le⟩ theorem SOppSide.exists_sbtw {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : ∃ p ∈ s, Sbtw R x p y := by obtain ⟨p, hp, hw⟩ := wOppSide_iff_exists_wbtw.1 h.wOppSide refine ⟨p, hp, hw, ?_, ?_⟩ · rintro rfl exact h.2.1 hp · rintro rfl exact h.2.2 hp theorem _root_.Sbtw.sOppSide_of_not_mem_of_mem {s : AffineSubspace R P} {x y z : P} (h : Sbtw R x y z) (hx : x ∉ s) (hy : y ∈ s) : s.SOppSide x z := by refine ⟨h.wbtw.wOppSide₁₃ hy, hx, fun hz => hx ?_⟩ rcases h with ⟨⟨t, ⟨ht0, ht1⟩, rfl⟩, hyx, hyz⟩ rw [lineMap_apply] at hy have ht : t ≠ 1 := by rintro rfl simp [lineMap_apply] at hyz have hy' := vsub_mem_direction hy hz rw [vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z, ← neg_one_smul R (z -ᵥ x), ← add_smul, ← sub_eq_add_neg, s.direction.smul_mem_iff (sub_ne_zero_of_ne ht)] at hy' rwa [vadd_mem_iff_mem_of_mem_direction (Submodule.smul_mem _ _ hy')] at hy theorem sSameSide_smul_vsub_vadd_left {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 < t) : s.SSameSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨wSameSide_smul_vsub_vadd_left x hp₁ hp₂ ht.le, fun h => hx ?_, hx⟩ rwa [vadd_mem_iff_mem_direction _ hp₂, s.direction.smul_mem_iff ht.ne.symm, vsub_right_mem_direction_iff_mem hp₁] at h theorem sSameSide_smul_vsub_vadd_right {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : 0 < t) : s.SSameSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (sSameSide_smul_vsub_vadd_left hx hp₁ hp₂ ht).symm theorem sSameSide_lineMap_left {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : 0 < t) : s.SSameSide (lineMap x y t) y := sSameSide_smul_vsub_vadd_left hy hx hx ht theorem sSameSide_lineMap_right {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : 0 < t) : s.SSameSide y (lineMap x y t) := (sSameSide_lineMap_left hx hy ht).symm theorem sOppSide_smul_vsub_vadd_left {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t < 0) : s.SOppSide (t • (x -ᵥ p₁) +ᵥ p₂) x := by refine ⟨wOppSide_smul_vsub_vadd_left x hp₁ hp₂ ht.le, fun h => hx ?_, hx⟩ rwa [vadd_mem_iff_mem_direction _ hp₂, s.direction.smul_mem_iff ht.ne, vsub_right_mem_direction_iff_mem hp₁] at h theorem sOppSide_smul_vsub_vadd_right {s : AffineSubspace R P} {x p₁ p₂ : P} (hx : x ∉ s) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) {t : R} (ht : t < 0) : s.SOppSide x (t • (x -ᵥ p₁) +ᵥ p₂) := (sOppSide_smul_vsub_vadd_left hx hp₁ hp₂ ht).symm theorem sOppSide_lineMap_left {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : t < 0) : s.SOppSide (lineMap x y t) y := sOppSide_smul_vsub_vadd_left hy hx hx ht theorem sOppSide_lineMap_right {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) {t : R} (ht : t < 0) : s.SOppSide y (lineMap x y t) := (sOppSide_lineMap_left hx hy ht).symm theorem setOf_wSameSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.WSameSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Ici 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Ici] constructor · rw [wSameSide_iff_exists_left hp, or_iff_right hx] rintro ⟨p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h refine ⟨0, le_rfl, p₂, hp₂, ?_⟩ simp [h] · refine ⟨r₁ / r₂, (div_pos hr₁ hr₂).le, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, h, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact wSameSide_smul_vsub_vadd_right x hp hp' ht theorem setOf_sSameSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.SSameSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Ioi 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Ioi] constructor · rw [sSameSide_iff_exists_left hp] rintro ⟨-, hy, p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hy (h.symm ▸ hp₂)) · refine ⟨r₁ / r₂, div_pos hr₁ hr₂, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, h, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact sSameSide_smul_vsub_vadd_right hx hp hp' ht theorem setOf_wOppSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.WOppSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Iic 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Iic] constructor · rw [wOppSide_iff_exists_left hp, or_iff_right hx] rintro ⟨p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h refine ⟨0, le_rfl, p₂, hp₂, ?_⟩ simp [h] · refine ⟨-r₁ / r₂, (div_neg_of_neg_of_pos (Left.neg_neg_iff.2 hr₁) hr₂).le, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, neg_smul, h, smul_neg, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, neg_vsub_eq_vsub_rev, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact wOppSide_smul_vsub_vadd_right x hp hp' ht theorem setOf_sOppSide_eq_image2 {s : AffineSubspace R P} {x p : P} (hx : x ∉ s) (hp : p ∈ s) : { y | s.SOppSide x y } = Set.image2 (fun (t : R) q => t • (x -ᵥ p) +ᵥ q) (Set.Iio 0) s := by ext y simp_rw [Set.mem_setOf, Set.mem_image2, Set.mem_Iio] constructor · rw [sOppSide_iff_exists_left hp] rintro ⟨-, hy, p₂, hp₂, h | h | ⟨r₁, r₂, hr₁, hr₂, h⟩⟩ · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hx (h.symm ▸ hp)) · rw [vsub_eq_zero_iff_eq] at h exact False.elim (hy (h ▸ hp₂)) · refine ⟨-r₁ / r₂, div_neg_of_neg_of_pos (Left.neg_neg_iff.2 hr₁) hr₂, p₂, hp₂, ?_⟩ rw [div_eq_inv_mul, ← smul_smul, neg_smul, h, smul_neg, smul_smul, inv_mul_cancel hr₂.ne.symm, one_smul, neg_vsub_eq_vsub_rev, vsub_vadd] · rintro ⟨t, ht, p', hp', rfl⟩ exact sOppSide_smul_vsub_vadd_right hx hp hp' ht theorem wOppSide_pointReflection {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide y (pointReflection R x y) := (wbtw_pointReflection R _ _).wOppSide₁₃ hx theorem sOppSide_pointReflection {s : AffineSubspace R P} {x y : P} (hx : x ∈ s) (hy : y ∉ s) : s.SOppSide y (pointReflection R x y) := by refine (sbtw_pointReflection_of_ne R fun h => hy ?_).sOppSide_of_not_mem_of_mem hy hx rwa [← h] end LinearOrderedField section Normed variable [SeminormedAddCommGroup V] [NormedSpace ℝ V] [PseudoMetricSpace P] variable [NormedAddTorsor V P] theorem isConnected_setOf_wSameSide {s : AffineSubspace ℝ P} (x : P) (h : (s : Set P).Nonempty) : IsConnected { y | s.WSameSide x y } := by obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ by_cases hx : x ∈ s · simp only [wSameSide_of_left_mem, hx] have := AddTorsor.connectedSpace V P exact isConnected_univ · rw [setOf_wSameSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Ici.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s theorem isPreconnected_setOf_wSameSide (s : AffineSubspace ℝ P) (x : P) : IsPreconnected { y | s.WSameSide x y } := by rcases Set.eq_empty_or_nonempty (s : Set P) with (h | h) · rw [coe_eq_bot_iff] at h simp only [h, not_wSameSide_bot] exact isPreconnected_empty · exact (isConnected_setOf_wSameSide x h).isPreconnected theorem isConnected_setOf_sSameSide {s : AffineSubspace ℝ P} {x : P} (hx : x ∉ s) (h : (s : Set P).Nonempty) : IsConnected { y | s.SSameSide x y } := by obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ rw [setOf_sSameSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Ioi.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s theorem isPreconnected_setOf_sSameSide (s : AffineSubspace ℝ P) (x : P) : IsPreconnected { y | s.SSameSide x y } := by rcases Set.eq_empty_or_nonempty (s : Set P) with (h | h) · rw [coe_eq_bot_iff] at h simp only [h, not_sSameSide_bot] exact isPreconnected_empty · by_cases hx : x ∈ s · simp only [hx, SSameSide, not_true, false_and_iff, and_false_iff] exact isPreconnected_empty · exact (isConnected_setOf_sSameSide hx h).isPreconnected theorem isConnected_setOf_wOppSide {s : AffineSubspace ℝ P} (x : P) (h : (s : Set P).Nonempty) : IsConnected { y | s.WOppSide x y } := by obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ by_cases hx : x ∈ s · simp only [wOppSide_of_left_mem, hx] have := AddTorsor.connectedSpace V P exact isConnected_univ · rw [setOf_wOppSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Iic.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s theorem isPreconnected_setOf_wOppSide (s : AffineSubspace ℝ P) (x : P) : IsPreconnected { y | s.WOppSide x y } := by rcases Set.eq_empty_or_nonempty (s : Set P) with (h | h) · rw [coe_eq_bot_iff] at h simp only [h, not_wOppSide_bot] exact isPreconnected_empty · exact (isConnected_setOf_wOppSide x h).isPreconnected theorem isConnected_setOf_sOppSide {s : AffineSubspace ℝ P} {x : P} (hx : x ∉ s) (h : (s : Set P).Nonempty) : IsConnected { y | s.SOppSide x y } := by obtain ⟨p, hp⟩ := h haveI : Nonempty s := ⟨⟨p, hp⟩⟩ rw [setOf_sOppSide_eq_image2 hx hp, ← Set.image_prod] refine (isConnected_Iio.prod (isConnected_iff_connectedSpace.2 ?_)).image _ ((continuous_fst.smul continuous_const).vadd continuous_snd).continuousOn convert AddTorsor.connectedSpace s.direction s theorem isPreconnected_setOf_sOppSide (s : AffineSubspace ℝ P) (x : P) : IsPreconnected { y | s.SOppSide x y } := by rcases Set.eq_empty_or_nonempty (s : Set P) with (h | h) · rw [coe_eq_bot_iff] at h simp only [h, not_sOppSide_bot] exact isPreconnected_empty · by_cases hx : x ∈ s · simp only [hx, SOppSide, not_true, false_and_iff, and_false_iff] exact isPreconnected_empty · exact (isConnected_setOf_sOppSide hx h).isPreconnected end Normed end AffineSubspace
Analysis\Convex\Slope.lean
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo Jaffré -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {𝕜 : Type*} [LinearOrderedField 𝕜] {s : Set 𝕜} {f : 𝕜 → 𝕜} /-- If `f : 𝕜 → 𝕜` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[y, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≤ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≤ f x / (y - x) + f z / (z - y) by ring_nf at this ⊢ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a • x + b • z = y := by field_simp [a, b]; ring have key := hf.2 hx hz (show 0 ≤ a by apply div_nonneg <;> linarith) (show 0 ≤ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp [a, b]) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [a, b, mul_comm (z - x) _] at key ⊢ rw [div_le_div_right] · linarith · nlinarith /-- If `f : 𝕜 → 𝕜` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[y, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≤ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this /-- If `f : 𝕜 → 𝕜` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[y, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊢ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a • x + b • z = y := by field_simp [a, b]; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp [a, b]) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊢ rw [div_lt_div_right] · linarith · nlinarith /-- If `f : 𝕜 → 𝕜` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[y, z]`. -/ theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this /-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is less than the slope of the secant line of `f` on `[y, z]`, then `f` is convex. -/ theorem convexOn_of_slope_mono_adjacent (hs : Convex 𝕜 s) (hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) : ConvexOn 𝕜 s f := LinearOrder.convexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) ≤ (f z - f y) * (y - x) := (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab dsimp [y] simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab dsimp [y] simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add, sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this /-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is greater than the slope of the secant line of `f` on `[y, z]`, then `f` is concave. -/ theorem concaveOn_of_slope_anti_adjacent (hs : Convex 𝕜 s) (hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z → (f z - f y) / (z - y) ≤ (f y - f x) / (y - x)) : ConcaveOn 𝕜 s f := by rw [← neg_convexOn_iff] refine convexOn_of_slope_mono_adjacent hs fun hx hz hxy hyz => ?_ rw [← neg_le_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz /-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[y, z]`, then `f` is strictly convex. -/ theorem strictConvexOn_of_slope_strict_mono_adjacent (hs : Convex 𝕜 s) (hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) < (f z - f y) / (z - y)) : StrictConvexOn 𝕜 s f := LinearOrder.strictConvexOn_of_lt hs fun x hx z hz hxz a b ha hb hab => by let y := a * x + b * z have hxy : x < y := by rw [← one_mul x, ← hab, add_mul] exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ have hyz : y < z := by rw [← one_mul z, ← hab, add_mul] exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ have : (f y - f x) * (z - y) < (f z - f y) * (y - x) := (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz) have hxz : 0 < z - x := sub_pos.2 (hxy.trans hyz) have ha : (z - y) / (z - x) = a := by rw [eq_comm, ← sub_eq_iff_eq_add'] at hab dsimp [y] simp_rw [div_eq_iff hxz.ne', ← hab] ring have hb : (y - x) / (z - x) = b := by rw [eq_comm, ← sub_eq_iff_eq_add] at hab dsimp [y] simp_rw [div_eq_iff hxz.ne', ← hab] ring rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add, sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x), mul_comm (f z), ha, hb] at this /-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[y, z]`, then `f` is strictly concave. -/ theorem strictConcaveOn_of_slope_strict_anti_adjacent (hs : Convex 𝕜 s) (hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z → (f z - f y) / (z - y) < (f y - f x) / (y - x)) : StrictConcaveOn 𝕜 s f := by rw [← neg_strictConvexOn_iff] refine strictConvexOn_of_slope_strict_mono_adjacent hs fun hx hz hxy hyz => ?_ rw [← neg_lt_neg_iff] simp_rw [← neg_div, neg_sub, Pi.neg_apply, neg_sub_neg] exact hf hx hz hxy hyz /-- A function `f : 𝕜 → 𝕜` is convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[y, z]`. -/ theorem convexOn_iff_slope_mono_adjacent : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) ≤ (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_mono_adjacent⟩, fun h => convexOn_of_slope_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ /-- A function `f : 𝕜 → 𝕜` is concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[y, z]`. -/ theorem concaveOn_iff_slope_anti_adjacent : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z → (f z - f y) / (z - y) ≤ (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => concaveOn_of_slope_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ /-- A function `f : 𝕜 → 𝕜` is strictly convex iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[y, z]`. -/ theorem strictConvexOn_iff_slope_strict_mono_adjacent : StrictConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z → (f y - f x) / (y - x) < (f z - f y) / (z - y) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_strict_mono_adjacent⟩, fun h => strictConvexOn_of_slope_strict_mono_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ /-- A function `f : 𝕜 → 𝕜` is strictly concave iff for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[y, z]`. -/ theorem strictConcaveOn_iff_slope_strict_anti_adjacent : StrictConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z → (f z - f y) / (z - y) < (f y - f x) / (y - x) := ⟨fun h => ⟨h.1, fun _ _ _ => h.slope_anti_adjacent⟩, fun h => strictConcaveOn_of_slope_strict_anti_adjacent h.1 (@fun _ _ _ hx hy => h.2 hx hy)⟩ theorem ConvexOn.secant_mono_aux1 (hf : ConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y ≤ (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← le_div_iff' hxz'] have ha : 0 ≤ (z - y) / (z - x) := by positivity have hb : 0 ≤ (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ ≤ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ · congr 1 field_simp ring · field_simp · field_simp theorem ConvexOn.secant_mono_aux2 (hf : ConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≤ (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxy' hxz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] theorem ConvexOn.secant_mono_aux3 (hf : ConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) ≤ (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_le_div_iff hxz' hyz'] linarith only [hf.secant_mono_aux1 hx hz hxy hyz] /-- If `f : 𝕜 → 𝕜` is convex, then for any point `a` the slope of the secant line of `f` through `a` and `b ≠ a` is monotone with respect to `b`. -/ theorem ConvexOn.secant_mono (hf : ConvexOn 𝕜 s f) {a x y : 𝕜} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x ≠ a) (hya : y ≠ a) (hxy : x ≤ y) : (f x - f a) / (x - a) ≤ (f y - f a) / (y - a) := by rcases eq_or_lt_of_le hxy with (rfl | hxy) · simp cases' lt_or_gt_of_ne hxa with hxa hxa · cases' lt_or_gt_of_ne hya with hya hya · convert hf.secant_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp · convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp · exact hf.secant_mono_aux2 ha hy hxa hxy theorem StrictConvexOn.secant_strict_mono_aux1 (hf : StrictConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (z - x) * f y < (z - y) * f x + (y - x) * f z := by have hxy' : 0 < y - x := by linarith have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [← lt_div_iff' hxz'] have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) := ?_ _ < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z := hf.2 hx hz (by linarith) ha hb ?_ _ = ((z - y) * f x + (y - x) * f z) / (z - x) := ?_ · congr 1 field_simp ring · field_simp · field_simp theorem StrictConvexOn.secant_strict_mono_aux2 (hf : StrictConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f x) / (z - x) := by have hxy' : 0 < y - x := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxy' hxz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] theorem StrictConvexOn.secant_strict_mono_aux3 (hf : StrictConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f x) / (z - x) < (f z - f y) / (z - y) := by have hyz' : 0 < z - y := by linarith have hxz' : 0 < z - x := by linarith rw [div_lt_div_iff hxz' hyz'] linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz] /-- If `f : 𝕜 → 𝕜` is strictly convex, then for any point `a` the slope of the secant line of `f` through `a` and `b` is strictly monotone with respect to `b`. -/ theorem StrictConvexOn.secant_strict_mono (hf : StrictConvexOn 𝕜 s f) {a x y : 𝕜} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x ≠ a) (hya : y ≠ a) (hxy : x < y) : (f x - f a) / (x - a) < (f y - f a) / (y - a) := by cases' lt_or_gt_of_ne hxa with hxa hxa · cases' lt_or_gt_of_ne hya with hya hya · convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1 <;> rw [← neg_div_neg_eq] <;> field_simp · convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; field_simp · exact hf.secant_strict_mono_aux2 ha hy hxa hxy /-- If `f : 𝕜 → 𝕜` is strictly concave, then for any point `a` the slope of the secant line of `f` through `a` and `b` is strictly antitone with respect to `b`. -/ theorem StrictConcaveOn.secant_strict_mono (hf : StrictConcaveOn 𝕜 s f) {a x y : 𝕜} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x ≠ a) (hya : y ≠ a) (hxy : x < y) : (f y - f a) / (y - a) < (f x - f a) / (x - a) := by have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy simp only [Pi.neg_apply] at key rw [← neg_lt_neg_iff] convert key using 1 <;> field_simp <;> ring /-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points `x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/ theorem ConvexOn.strict_mono_of_lt (hf : ConvexOn 𝕜 s f) {x y : 𝕜} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ Set.Ici y) := by intro u hu v hv huv have step1 : ∀ {z : 𝕜}, z ∈ s ∩ Set.Ioi y → f y < f z := by intros z hz refine hf.lt_right_of_left_lt hx hz.1 ?_ hxy' rw [openSegment_eq_Ioo (hxy.trans hz.2)] exact ⟨hxy, hz.2⟩ rcases eq_or_lt_of_le hu.2 with (rfl | hu2) · exact step1 ⟨hv.1, huv⟩ · refine hf.lt_right_of_left_lt ?_ hv.1 ?_ (step1 ⟨hu.1, hu2⟩) · apply hf.1.segment_subset hx hu.1 rw [segment_eq_Icc (hxy.le.trans hu.2)] exact ⟨hxy.le, hu.2⟩ · rw [openSegment_eq_Ioo (hu2.trans huv)] exact ⟨hu2, huv⟩
Analysis\Convex\Star.lean
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Module.LinearMap.Prod import Mathlib.Algebra.Order.Group.Instances import Mathlib.Analysis.Convex.Segment import Mathlib.Tactic.GCongr /-! # Star-convex sets This files defines star-convex sets (aka star domains, star-shaped set, radially convex set). A set is star-convex at `x` if every segment from `x` to a point in the set is contained in the set. This is the prototypical example of a contractible set in homotopy theory (by scaling every point towards `x`), but has wider uses. Note that this has nothing to do with star rings, `Star` and co. ## Main declarations * `StarConvex 𝕜 x s`: `s` is star-convex at `x` with scalars `𝕜`. ## Implementation notes Instead of saying that a set is star-convex, we say a set is star-convex *at a point*. This has the advantage of allowing us to talk about convexity as being "everywhere star-convexity" and of making the union of star-convex sets be star-convex. Incidentally, this choice means we don't need to assume a set is nonempty for it to be star-convex. Concretely, the empty set is star-convex at every point. ## TODO Balanced sets are star-convex. The closure of a star-convex set is star-convex. Star-convex sets are contractible. A nonempty open star-convex set in `ℝ^n` is diffeomorphic to the entire space. -/ open Set open Convex Pointwise variable {𝕜 E F : Type*} section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 F] (x : E) (s : Set E) /-- Star-convexity of sets. `s` is star-convex at `x` if every segment from `x` to a point in `s` is contained in `s`. -/ def StarConvex : Prop := ∀ ⦃y : E⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s variable {𝕜 x s} {t : Set E} theorem starConvex_iff_segment_subset : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → [x -[𝕜] y] ⊆ s := by constructor · rintro h y hy z ⟨a, b, ha, hb, hab, rfl⟩ exact h hy ha hb hab · rintro h y hy a b ha hb hab exact h hy ⟨a, b, ha, hb, hab, rfl⟩ theorem StarConvex.segment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : [x -[𝕜] y] ⊆ s := starConvex_iff_segment_subset.1 h hy theorem StarConvex.openSegment_subset (h : StarConvex 𝕜 x s) {y : E} (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s := (openSegment_subset_segment 𝕜 x y).trans (h.segment_subset hy) /-- Alternative definition of star-convexity, in terms of pointwise set operations. -/ theorem starConvex_iff_pointwise_add_subset : StarConvex 𝕜 x s ↔ ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • {x} + b • s ⊆ s := by refine ⟨?_, fun h y hy a b ha hb hab => h ha hb hab (add_mem_add (smul_mem_smul_set <| mem_singleton _) ⟨_, hy, rfl⟩)⟩ rintro hA a b ha hb hab w ⟨au, ⟨u, rfl : u = x, rfl⟩, bv, ⟨v, hv, rfl⟩, rfl⟩ exact hA hv ha hb hab theorem starConvex_empty (x : E) : StarConvex 𝕜 x ∅ := fun _ hy => hy.elim theorem starConvex_univ (x : E) : StarConvex 𝕜 x univ := fun _ _ _ _ _ _ _ => trivial theorem StarConvex.inter (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∩ t) := fun _ hy _ _ ha hb hab => ⟨hs hy.left ha hb hab, ht hy.right ha hb hab⟩ theorem starConvex_sInter {S : Set (Set E)} (h : ∀ s ∈ S, StarConvex 𝕜 x s) : StarConvex 𝕜 x (⋂₀ S) := fun _ hy _ _ ha hb hab s hs => h s hs (hy s hs) ha hb hab theorem starConvex_iInter {ι : Sort*} {s : ι → Set E} (h : ∀ i, StarConvex 𝕜 x (s i)) : StarConvex 𝕜 x (⋂ i, s i) := sInter_range s ▸ starConvex_sInter <| forall_mem_range.2 h theorem StarConvex.union (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 x t) : StarConvex 𝕜 x (s ∪ t) := by rintro y (hy | hy) a b ha hb hab · exact Or.inl (hs hy ha hb hab) · exact Or.inr (ht hy ha hb hab) theorem starConvex_iUnion {ι : Sort*} {s : ι → Set E} (hs : ∀ i, StarConvex 𝕜 x (s i)) : StarConvex 𝕜 x (⋃ i, s i) := by rintro y hy a b ha hb hab rw [mem_iUnion] at hy ⊢ obtain ⟨i, hy⟩ := hy exact ⟨i, hs i hy ha hb hab⟩ theorem starConvex_sUnion {S : Set (Set E)} (hS : ∀ s ∈ S, StarConvex 𝕜 x s) : StarConvex 𝕜 x (⋃₀ S) := by rw [sUnion_eq_iUnion] exact starConvex_iUnion fun s => hS _ s.2 theorem StarConvex.prod {y : F} {s : Set E} {t : Set F} (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x, y) (s ×ˢ t) := fun _ hy _ _ ha hb hab => ⟨hs hy.1 ha hb hab, ht hy.2 ha hb hab⟩ theorem starConvex_pi {ι : Type*} {E : ι → Type*} [∀ i, AddCommMonoid (E i)] [∀ i, SMul 𝕜 (E i)] {x : ∀ i, E i} {s : Set ι} {t : ∀ i, Set (E i)} (ht : ∀ ⦃i⦄, i ∈ s → StarConvex 𝕜 (x i) (t i)) : StarConvex 𝕜 x (s.pi t) := fun _ hy _ _ ha hb hab i hi => ht hi (hy i hi) ha hb hab end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {x y z : E} {s : Set E} theorem StarConvex.mem (hs : StarConvex 𝕜 x s) (h : s.Nonempty) : x ∈ s := by obtain ⟨y, hy⟩ := h convert hs hy zero_le_one le_rfl (add_zero 1) rw [one_smul, zero_smul, add_zero] theorem starConvex_iff_forall_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine ⟨fun h y hy a b ha hb hab => h hy ha.le hb.le hab, ?_⟩ intro h y hy a b ha hb hab obtain rfl | ha := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, one_smul, zero_smul, zero_add] obtain rfl | hb := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, one_smul, zero_smul, add_zero] exact h hy ha hb hab theorem starConvex_iff_forall_ne_pos (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := by refine ⟨fun h y hy _ a b ha hb hab => h hy ha.le hb.le hab, ?_⟩ intro h y hy a b ha hb hab obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab rwa [hab, zero_smul, one_smul, zero_add] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab rwa [hab, zero_smul, one_smul, add_zero] obtain rfl | hxy := eq_or_ne x y · rwa [Convex.combo_self hab] exact h hy hxy ha' hb' hab theorem starConvex_iff_openSegment_subset (hx : x ∈ s) : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → openSegment 𝕜 x y ⊆ s := starConvex_iff_segment_subset.trans <| forall₂_congr fun _ hy => (openSegment_subset_iff_segment_subset hx hy).symm theorem starConvex_singleton (x : E) : StarConvex 𝕜 x {x} := by rintro y (rfl : y = x) a b _ _ hab exact Convex.combo_self hab _ theorem StarConvex.linear_image (hs : StarConvex 𝕜 x s) (f : E →ₗ[𝕜] F) : StarConvex 𝕜 (f x) (f '' s) := by rintro _ ⟨y, hy, rfl⟩ a b ha hb hab exact ⟨a • x + b • y, hs hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]⟩ theorem StarConvex.is_linear_image (hs : StarConvex 𝕜 x s) {f : E → F} (hf : IsLinearMap 𝕜 f) : StarConvex 𝕜 (f x) (f '' s) := hs.linear_image <| hf.mk' f theorem StarConvex.linear_preimage {s : Set F} (f : E →ₗ[𝕜] F) (hs : StarConvex 𝕜 (f x) s) : StarConvex 𝕜 x (f ⁻¹' s) := by intro y hy a b ha hb hab rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hy ha hb hab theorem StarConvex.is_linear_preimage {s : Set F} {f : E → F} (hs : StarConvex 𝕜 (f x) s) (hf : IsLinearMap 𝕜 f) : StarConvex 𝕜 x (preimage f s) := hs.linear_preimage <| hf.mk' f theorem StarConvex.add {t : Set E} (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x + y) (s + t) := by rw [← add_image_prod] exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add theorem StarConvex.add_left (hs : StarConvex 𝕜 x s) (z : E) : StarConvex 𝕜 (z + x) ((fun x => z + x) '' s) := by intro y hy a b ha hb hab obtain ⟨y', hy', rfl⟩ := hy refine ⟨a • x + b • y', hs hy' ha hb hab, ?_⟩ rw [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] theorem StarConvex.add_right (hs : StarConvex 𝕜 x s) (z : E) : StarConvex 𝕜 (x + z) ((fun x => x + z) '' s) := by intro y hy a b ha hb hab obtain ⟨y', hy', rfl⟩ := hy refine ⟨a • x + b • y', hs hy' ha hb hab, ?_⟩ rw [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] /-- The translation of a star-convex set is also star-convex. -/ theorem StarConvex.preimage_add_right (hs : StarConvex 𝕜 (z + x) s) : StarConvex 𝕜 x ((fun x => z + x) ⁻¹' s) := by intro y hy a b ha hb hab have h := hs hy ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← add_smul, hab, one_smul] at h /-- The translation of a star-convex set is also star-convex. -/ theorem StarConvex.preimage_add_left (hs : StarConvex 𝕜 (x + z) s) : StarConvex 𝕜 x ((fun x => x + z) ⁻¹' s) := by rw [add_comm] at hs simpa only [add_comm] using hs.preimage_add_right end Module end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [Module 𝕜 E] {x y : E} theorem StarConvex.sub' {s : Set (E × E)} (hs : StarConvex 𝕜 (x, y) s) : StarConvex 𝕜 (x - y) ((fun x : E × E => x.1 - x.2) '' s) := hs.is_linear_image IsLinearMap.isLinearMap_sub end AddCommGroup end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F] {x : E} {s : Set E} theorem StarConvex.smul (hs : StarConvex 𝕜 x s) (c : 𝕜) : StarConvex 𝕜 (c • x) (c • s) := hs.linear_image <| LinearMap.lsmul _ _ c theorem StarConvex.preimage_smul {c : 𝕜} (hs : StarConvex 𝕜 (c • x) s) : StarConvex 𝕜 x ((fun z => c • z) ⁻¹' s) := hs.linear_preimage (LinearMap.lsmul _ _ c) theorem StarConvex.affinity (hs : StarConvex 𝕜 x s) (z : E) (c : 𝕜) : StarConvex 𝕜 (z + c • x) ((fun x => z + c • x) '' s) := by have h := (hs.smul c).add_left z rwa [← image_smul, image_image] at h end AddCommMonoid end OrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] section AddCommMonoid variable [AddCommMonoid E] [SMulWithZero 𝕜 E] {s : Set E} theorem starConvex_zero_iff : StarConvex 𝕜 0 s ↔ ∀ ⦃x : E⦄, x ∈ s → ∀ ⦃a : 𝕜⦄, 0 ≤ a → a ≤ 1 → a • x ∈ s := by refine forall_congr' fun x => forall_congr' fun _ => ⟨fun h a ha₀ ha₁ => ?_, fun h a b ha hb hab => ?_⟩ · simpa only [sub_add_cancel, eq_self_iff_true, forall_true_left, zero_add, smul_zero] using h (sub_nonneg_of_le ha₁) ha₀ · rw [smul_zero, zero_add] exact h hb (by rw [← hab]; exact le_add_of_nonneg_left ha) end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {x y : E} {s t : Set E} theorem StarConvex.add_smul_mem (hs : StarConvex 𝕜 x s) (hy : x + y ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : x + t • y ∈ s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← add_smul, sub_add_cancel, one_smul] rw [h] exact hs hy (sub_nonneg_of_le ht₁) ht₀ (sub_add_cancel _ _) theorem StarConvex.smul_mem (hs : StarConvex 𝕜 0 s) (hx : x ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : t • x ∈ s := by simpa using hs.add_smul_mem (by simpa using hx) ht₀ ht₁ theorem StarConvex.add_smul_sub_mem (hs : StarConvex 𝕜 x s) (hy : y ∈ s) {t : 𝕜} (ht₀ : 0 ≤ t) (ht₁ : t ≤ 1) : x + t • (y - x) ∈ s := by apply hs.segment_subset hy rw [segment_eq_image'] exact mem_image_of_mem _ ⟨ht₀, ht₁⟩ /-- The preimage of a star-convex set under an affine map is star-convex. -/ theorem StarConvex.affine_preimage (f : E →ᵃ[𝕜] F) {s : Set F} (hs : StarConvex 𝕜 (f x) s) : StarConvex 𝕜 x (f ⁻¹' s) := by intro y hy a b ha hb hab rw [mem_preimage, Convex.combo_affine_apply hab] exact hs hy ha hb hab /-- The image of a star-convex set under an affine map is star-convex. -/ theorem StarConvex.affine_image (f : E →ᵃ[𝕜] F) {s : Set E} (hs : StarConvex 𝕜 x s) : StarConvex 𝕜 (f x) (f '' s) := by rintro y ⟨y', ⟨hy', hy'f⟩⟩ a b ha hb hab refine ⟨a • x + b • y', ⟨hs hy' ha hb hab, ?_⟩⟩ rw [Convex.combo_affine_apply hab, hy'f] theorem StarConvex.neg (hs : StarConvex 𝕜 x s) : StarConvex 𝕜 (-x) (-s) := by rw [← image_neg] exact hs.is_linear_image IsLinearMap.isLinearMap_neg theorem StarConvex.sub (hs : StarConvex 𝕜 x s) (ht : StarConvex 𝕜 y t) : StarConvex 𝕜 (x - y) (s - t) := by simp_rw [sub_eq_add_neg] exact hs.add ht.neg end AddCommGroup section OrderedAddCommGroup variable [OrderedAddCommGroup E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x y : E} /-- If `x < y`, then `(Set.Iic x)ᶜ` is star convex at `y`. -/ lemma starConvex_compl_Iic (h : x < y) : StarConvex 𝕜 y (Iic x)ᶜ := by refine (starConvex_iff_forall_pos <| by simp [h.not_le]).mpr fun z hz a b ha hb hab ↦ ?_ rw [mem_compl_iff, mem_Iic] at hz ⊢ contrapose! hz refine (lt_of_smul_lt_smul_of_nonneg_left ?_ hb.le).le calc b • z ≤ (a + b) • x - a • y := by rwa [le_sub_iff_add_le', hab, one_smul] _ < b • x := by rw [add_smul, sub_lt_iff_lt_add'] gcongr /-- If `x < y`, then `(Set.Ici y)ᶜ` is star convex at `x`. -/ lemma starConvex_compl_Ici (h : x < y) : StarConvex 𝕜 x (Ici y)ᶜ := starConvex_compl_Iic (E := Eᵒᵈ) h end OrderedAddCommGroup end OrderedRing section LinearOrderedField variable [LinearOrderedField 𝕜] section AddCommGroup variable [AddCommGroup E] [Module 𝕜 E] {x : E} {s : Set E} /-- Alternative definition of star-convexity, using division. -/ theorem starConvex_iff_div : StarConvex 𝕜 x s ↔ ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • x + (b / (a + b)) • y ∈ s := ⟨fun h y hy a b ha hb hab => by apply h hy · positivity · positivity · rw [← add_div] exact div_self hab.ne', fun h y hy a b ha hb hab => by have h' := h hy ha hb rw [hab, div_one, div_one] at h' exact h' zero_lt_one⟩ theorem StarConvex.mem_smul (hs : StarConvex 𝕜 0 s) (hx : x ∈ s) {t : 𝕜} (ht : 1 ≤ t) : x ∈ t • s := by rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans_le ht).ne'] exact hs.smul_mem hx (by positivity) (inv_le_one ht) end AddCommGroup end LinearOrderedField /-! #### Star-convex sets in an ordered space Relates `starConvex` and `Set.ordConnected`. -/ section OrdConnected /-- If `s` is an order-connected set in an ordered module over an ordered semiring and all elements of `s` are comparable with `x ∈ s`, then `s` is `StarConvex` at `x`. -/ theorem Set.OrdConnected.starConvex [OrderedSemiring 𝕜] [OrderedAddCommMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] {x : E} {s : Set E} (hs : s.OrdConnected) (hx : x ∈ s) (h : ∀ y ∈ s, x ≤ y ∨ y ≤ x) : StarConvex 𝕜 x s := by intro y hy a b ha hb hab obtain hxy | hyx := h _ hy · refine hs.out hx hy (mem_Icc.2 ⟨?_, ?_⟩) · calc x = a • x + b • x := (Convex.combo_self hab _).symm _ ≤ a • x + b • y := by gcongr calc a • x + b • y ≤ a • y + b • y := by gcongr _ = y := Convex.combo_self hab _ · refine hs.out hy hx (mem_Icc.2 ⟨?_, ?_⟩) · calc y = a • y + b • y := (Convex.combo_self hab _).symm _ ≤ a • x + b • y := by gcongr calc a • x + b • y ≤ a • x + b • x := by gcongr _ = x := Convex.combo_self hab _ theorem starConvex_iff_ordConnected [LinearOrderedField 𝕜] {x : 𝕜} {s : Set 𝕜} (hx : x ∈ s) : StarConvex 𝕜 x s ↔ s.OrdConnected := by simp_rw [ordConnected_iff_uIcc_subset_left hx, starConvex_iff_segment_subset, segment_eq_uIcc] alias ⟨StarConvex.ordConnected, _⟩ := starConvex_iff_ordConnected end OrdConnected
Analysis\Convex\StoneSeparation.lean
/- 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.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Join /-! # Stone's separation theorem This file proves Stone's separation theorem. This tells us that any two disjoint convex sets can be separated by a convex set whose complement is also convex. In locally convex real topological vector spaces, the Hahn-Banach separation theorems provide stronger statements: one may find a separating hyperplane, instead of merely a convex set whose complement is convex. -/ open Set variable {𝕜 E ι : Type*} [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {s t : Set E} /-- In a tetrahedron with vertices `x`, `y`, `p`, `q`, any segment `[u, v]` joining the opposite edges `[x, p]` and `[y, q]` passes through any triangle of vertices `p`, `q`, `z` where `z ∈ [x, y]`. -/ theorem not_disjoint_segment_convexHull_triple {p q u v x y z : E} (hz : z ∈ segment 𝕜 x y) (hu : u ∈ segment 𝕜 x p) (hv : v ∈ segment 𝕜 y q) : ¬Disjoint (segment 𝕜 u v) (convexHull 𝕜 {p, q, z}) := by rw [not_disjoint_iff] obtain ⟨az, bz, haz, hbz, habz, rfl⟩ := hz obtain rfl | haz' := haz.eq_or_lt · rw [zero_add] at habz rw [zero_smul, zero_add, habz, one_smul] refine ⟨v, by apply right_mem_segment, segment_subset_convexHull ?_ ?_ hv⟩ <;> simp obtain ⟨av, bv, hav, hbv, habv, rfl⟩ := hv obtain rfl | hav' := hav.eq_or_lt · rw [zero_add] at habv rw [zero_smul, zero_add, habv, one_smul] exact ⟨q, right_mem_segment _ _ _, subset_convexHull _ _ <| by simp⟩ obtain ⟨au, bu, hau, hbu, habu, rfl⟩ := hu have hab : 0 < az * av + bz * au := by positivity refine ⟨(az * av / (az * av + bz * au)) • (au • x + bu • p) + (bz * au / (az * av + bz * au)) • (av • y + bv • q), ⟨_, _, ?_, ?_, ?_, rfl⟩, ?_⟩ · positivity · positivity · rw [← add_div, div_self]; positivity rw [smul_add, smul_add, add_add_add_comm, add_comm, ← mul_smul, ← mul_smul] classical let w : Fin 3 → 𝕜 := ![az * av * bu, bz * au * bv, au * av] let z : Fin 3 → E := ![p, q, az • x + bz • y] have hw₀ : ∀ i, 0 ≤ w i := by rintro i fin_cases i · exact mul_nonneg (mul_nonneg haz hav) hbu · exact mul_nonneg (mul_nonneg hbz hau) hbv · exact mul_nonneg hau hav have hw : ∑ i, w i = az * av + bz * au := by trans az * av * bu + (bz * au * bv + au * av) · simp [w, Fin.sum_univ_succ, Fin.sum_univ_zero] rw [← one_mul (au * av), ← habz, add_mul, ← add_assoc, add_add_add_comm, mul_assoc, ← mul_add, mul_assoc, ← mul_add, mul_comm av, ← add_mul, ← mul_add, add_comm bu, add_comm bv, habu, habv, one_mul, mul_one] have hz : ∀ i, z i ∈ ({p, q, az • x + bz • y} : Set E) := fun i => by fin_cases i <;> simp [z] convert Finset.centerMass_mem_convexHull (Finset.univ : Finset (Fin 3)) (fun i _ => hw₀ i) (by rwa [hw]) fun i _ => hz i rw [Finset.centerMass] simp_rw [div_eq_inv_mul, hw, mul_assoc, mul_smul (az * av + bz * au)⁻¹, ← smul_add, add_assoc, ← mul_assoc] congr 3 rw [← mul_smul, ← mul_rotate, mul_right_comm, mul_smul, ← mul_smul _ av, mul_rotate, mul_smul _ bz, ← smul_add] simp only [w, z, smul_add, List.foldr, Matrix.cons_val_succ', Fin.mk_one, Matrix.cons_val_one, Matrix.head_cons, add_zero] /-- **Stone's Separation Theorem** -/ theorem exists_convex_convex_compl_subset (hs : Convex 𝕜 s) (ht : Convex 𝕜 t) (hst : Disjoint s t) : ∃ C : Set E, Convex 𝕜 C ∧ Convex 𝕜 Cᶜ ∧ s ⊆ C ∧ t ⊆ Cᶜ := by let S : Set (Set E) := { C | Convex 𝕜 C ∧ Disjoint C t } obtain ⟨C, hC, hsC, hCmax⟩ := zorn_subset_nonempty S (fun c hcS hc ⟨_, _⟩ => ⟨⋃₀ c, ⟨hc.directedOn.convex_sUnion fun s hs => (hcS hs).1, disjoint_sUnion_left.2 fun c hc => (hcS hc).2⟩, fun s => subset_sUnion_of_mem⟩) s ⟨hs, hst⟩ refine ⟨C, hC.1, convex_iff_segment_subset.2 fun x hx y hy z hz hzC => ?_, hsC, hC.2.subset_compl_left⟩ suffices h : ∀ c ∈ Cᶜ, ∃ a ∈ C, (segment 𝕜 c a ∩ t).Nonempty by obtain ⟨p, hp, u, hu, hut⟩ := h x hx obtain ⟨q, hq, v, hv, hvt⟩ := h y hy refine not_disjoint_segment_convexHull_triple hz hu hv (hC.2.symm.mono (ht.segment_subset hut hvt) <| convexHull_min ?_ hC.1) simp [insert_subset_iff, hp, hq, singleton_subset_iff.2 hzC] rintro c hc by_contra! h suffices h : Disjoint (convexHull 𝕜 (insert c C)) t by rw [← hCmax _ ⟨convex_convexHull _ _, h⟩ ((subset_insert _ _).trans <| subset_convexHull _ _)] at hc exact hc (subset_convexHull _ _ <| mem_insert _ _) rw [convexHull_insert ⟨z, hzC⟩, convexJoin_singleton_left] refine disjoint_iUnion₂_left.2 fun a ha => disjoint_iff_inter_eq_empty.2 (h a ?_) rwa [← hC.1.convexHull_eq]
Analysis\Convex\Strict.lean
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Topology.Algebra.Group.Basic import Mathlib.Topology.Order.Basic /-! # Strictly convex sets This file defines strictly convex sets. A set is strictly convex if the open segment between any two distinct points lies in its interior. -/ open Set open Convex Pointwise variable {𝕜 𝕝 E F β : Type*} open Function Set open Convex section OrderedSemiring variable [OrderedSemiring 𝕜] [TopologicalSpace E] [TopologicalSpace F] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable (𝕜) variable [SMul 𝕜 E] [SMul 𝕜 F] (s : Set E) /-- A set is strictly convex if the open segment between any two distinct points lies is in its interior. This basically means "convex and not flat on the boundary". -/ def StrictConvex : Prop := s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ interior s variable {𝕜 s} variable {x y : E} {a b : 𝕜} theorem strictConvex_iff_openSegment_subset : StrictConvex 𝕜 s ↔ s.Pairwise fun x y => openSegment 𝕜 x y ⊆ interior s := forall₅_congr fun _ _ _ _ _ => (openSegment_subset_iff 𝕜).symm theorem StrictConvex.openSegment_subset (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) (h : x ≠ y) : openSegment 𝕜 x y ⊆ interior s := strictConvex_iff_openSegment_subset.1 hs hx hy h theorem strictConvex_empty : StrictConvex 𝕜 (∅ : Set E) := pairwise_empty _ theorem strictConvex_univ : StrictConvex 𝕜 (univ : Set E) := by intro x _ y _ _ a b _ _ _ rw [interior_univ] exact mem_univ _ protected nonrec theorem StrictConvex.eq (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (h : a • x + b • y ∉ interior s) : x = y := hs.eq hx hy fun H => h <| H ha hb hab protected theorem StrictConvex.inter {t : Set E} (hs : StrictConvex 𝕜 s) (ht : StrictConvex 𝕜 t) : StrictConvex 𝕜 (s ∩ t) := by intro x hx y hy hxy a b ha hb hab rw [interior_inter] exact ⟨hs hx.1 hy.1 hxy ha hb hab, ht hx.2 hy.2 hxy ha hb hab⟩ theorem Directed.strictConvex_iUnion {ι : Sort*} {s : ι → Set E} (hdir : Directed (· ⊆ ·) s) (hs : ∀ ⦃i : ι⦄, StrictConvex 𝕜 (s i)) : StrictConvex 𝕜 (⋃ i, s i) := by rintro x hx y hy hxy a b ha hb hab rw [mem_iUnion] at hx hy obtain ⟨i, hx⟩ := hx obtain ⟨j, hy⟩ := hy obtain ⟨k, hik, hjk⟩ := hdir i j exact interior_mono (subset_iUnion s k) (hs (hik hx) (hjk hy) hxy ha hb hab) theorem DirectedOn.strictConvex_sUnion {S : Set (Set E)} (hdir : DirectedOn (· ⊆ ·) S) (hS : ∀ s ∈ S, StrictConvex 𝕜 s) : StrictConvex 𝕜 (⋃₀ S) := by rw [sUnion_eq_iUnion] exact (directedOn_iff_directed.1 hdir).strictConvex_iUnion fun s => hS _ s.2 end SMul section Module variable [Module 𝕜 E] [Module 𝕜 F] {s : Set E} protected theorem StrictConvex.convex (hs : StrictConvex 𝕜 s) : Convex 𝕜 s := convex_iff_pairwise_pos.2 fun _ hx _ hy hxy _ _ ha hb hab => interior_subset <| hs hx hy hxy ha hb hab /-- An open convex set is strictly convex. -/ protected theorem Convex.strictConvex_of_isOpen (h : IsOpen s) (hs : Convex 𝕜 s) : StrictConvex 𝕜 s := fun _ hx _ hy _ _ _ ha hb hab => h.interior_eq.symm ▸ hs hx hy ha.le hb.le hab theorem IsOpen.strictConvex_iff (h : IsOpen s) : StrictConvex 𝕜 s ↔ Convex 𝕜 s := ⟨StrictConvex.convex, Convex.strictConvex_of_isOpen h⟩ theorem strictConvex_singleton (c : E) : StrictConvex 𝕜 ({c} : Set E) := pairwise_singleton _ _ theorem Set.Subsingleton.strictConvex (hs : s.Subsingleton) : StrictConvex 𝕜 s := hs.pairwise _ theorem StrictConvex.linear_image [Semiring 𝕝] [Module 𝕝 E] [Module 𝕝 F] [LinearMap.CompatibleSMul E F 𝕜 𝕝] (hs : StrictConvex 𝕜 s) (f : E →ₗ[𝕝] F) (hf : IsOpenMap f) : StrictConvex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ hxy a b ha hb hab refine hf.image_interior_subset _ ⟨a • x + b • y, hs hx hy (ne_of_apply_ne _ hxy) ha hb hab, ?_⟩ rw [map_add, f.map_smul_of_tower a, f.map_smul_of_tower b] theorem StrictConvex.is_linear_image (hs : StrictConvex 𝕜 s) {f : E → F} (h : IsLinearMap 𝕜 f) (hf : IsOpenMap f) : StrictConvex 𝕜 (f '' s) := hs.linear_image (h.mk' f) hf theorem StrictConvex.linear_preimage {s : Set F} (hs : StrictConvex 𝕜 s) (f : E →ₗ[𝕜] F) (hf : Continuous f) (hfinj : Injective f) : StrictConvex 𝕜 (s.preimage f) := by intro x hx y hy hxy a b ha hb hab refine preimage_interior_subset_interior_preimage hf ?_ rw [mem_preimage, f.map_add, f.map_smul, f.map_smul] exact hs hx hy (hfinj.ne hxy) ha hb hab theorem StrictConvex.is_linear_preimage {s : Set F} (hs : StrictConvex 𝕜 s) {f : E → F} (h : IsLinearMap 𝕜 f) (hf : Continuous f) (hfinj : Injective f) : StrictConvex 𝕜 (s.preimage f) := hs.linear_preimage (h.mk' f) hf hfinj section LinearOrderedCancelAddCommMonoid variable [TopologicalSpace β] [LinearOrderedCancelAddCommMonoid β] [OrderTopology β] [Module 𝕜 β] [OrderedSMul 𝕜 β] protected theorem Set.OrdConnected.strictConvex {s : Set β} (hs : OrdConnected s) : StrictConvex 𝕜 s := by refine strictConvex_iff_openSegment_subset.2 fun x hx y hy hxy => ?_ cases' hxy.lt_or_lt with hlt hlt <;> [skip; rw [openSegment_symm]] <;> exact (openSegment_subset_Ioo hlt).trans (isOpen_Ioo.subset_interior_iff.2 <| Ioo_subset_Icc_self.trans <| hs.out ‹_› ‹_›) theorem strictConvex_Iic (r : β) : StrictConvex 𝕜 (Iic r) := ordConnected_Iic.strictConvex theorem strictConvex_Ici (r : β) : StrictConvex 𝕜 (Ici r) := ordConnected_Ici.strictConvex theorem strictConvex_Iio (r : β) : StrictConvex 𝕜 (Iio r) := ordConnected_Iio.strictConvex theorem strictConvex_Ioi (r : β) : StrictConvex 𝕜 (Ioi r) := ordConnected_Ioi.strictConvex theorem strictConvex_Icc (r s : β) : StrictConvex 𝕜 (Icc r s) := ordConnected_Icc.strictConvex theorem strictConvex_Ioo (r s : β) : StrictConvex 𝕜 (Ioo r s) := ordConnected_Ioo.strictConvex theorem strictConvex_Ico (r s : β) : StrictConvex 𝕜 (Ico r s) := ordConnected_Ico.strictConvex theorem strictConvex_Ioc (r s : β) : StrictConvex 𝕜 (Ioc r s) := ordConnected_Ioc.strictConvex theorem strictConvex_uIcc (r s : β) : StrictConvex 𝕜 (uIcc r s) := strictConvex_Icc _ _ theorem strictConvex_uIoc (r s : β) : StrictConvex 𝕜 (uIoc r s) := strictConvex_Ioc _ _ end LinearOrderedCancelAddCommMonoid end Module end AddCommMonoid section AddCancelCommMonoid variable [AddCancelCommMonoid E] [ContinuousAdd E] [Module 𝕜 E] {s : Set E} /-- The translation of a strictly convex set is also strictly convex. -/ theorem StrictConvex.preimage_add_right (hs : StrictConvex 𝕜 s) (z : E) : StrictConvex 𝕜 ((fun x => z + x) ⁻¹' s) := by intro x hx y hy hxy a b ha hb hab refine preimage_interior_subset_interior_preimage (continuous_add_left _) ?_ have h := hs hx hy ((add_right_injective _).ne hxy) ha hb hab rwa [smul_add, smul_add, add_add_add_comm, ← _root_.add_smul, hab, one_smul] at h /-- The translation of a strictly convex set is also strictly convex. -/ theorem StrictConvex.preimage_add_left (hs : StrictConvex 𝕜 s) (z : E) : StrictConvex 𝕜 ((fun x => x + z) ⁻¹' s) := by simpa only [add_comm] using hs.preimage_add_right z end AddCancelCommMonoid section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] section continuous_add variable [ContinuousAdd E] {s t : Set E} theorem StrictConvex.add (hs : StrictConvex 𝕜 s) (ht : StrictConvex 𝕜 t) : StrictConvex 𝕜 (s + t) := by rintro _ ⟨v, hv, w, hw, rfl⟩ _ ⟨x, hx, y, hy, rfl⟩ h a b ha hb hab rw [smul_add, smul_add, add_add_add_comm] obtain rfl | hvx := eq_or_ne v x · refine interior_mono (add_subset_add (singleton_subset_iff.2 hv) Subset.rfl) ?_ rw [Convex.combo_self hab, singleton_add] exact (isOpenMap_add_left _).image_interior_subset _ (mem_image_of_mem _ <| ht hw hy (ne_of_apply_ne _ h) ha hb hab) exact subset_interior_add_left (add_mem_add (hs hv hx hvx ha hb hab) <| ht.convex hw hy ha.le hb.le hab) theorem StrictConvex.add_left (hs : StrictConvex 𝕜 s) (z : E) : StrictConvex 𝕜 ((fun x => z + x) '' s) := by simpa only [singleton_add] using (strictConvex_singleton z).add hs theorem StrictConvex.add_right (hs : StrictConvex 𝕜 s) (z : E) : StrictConvex 𝕜 ((fun x => x + z) '' s) := by simpa only [add_comm] using hs.add_left z /-- The translation of a strictly convex set is also strictly convex. -/ theorem StrictConvex.vadd (hs : StrictConvex 𝕜 s) (x : E) : StrictConvex 𝕜 (x +ᵥ s) := hs.add_left x end continuous_add section ContinuousSMul variable [LinearOrderedField 𝕝] [Module 𝕝 E] [ContinuousConstSMul 𝕝 E] [LinearMap.CompatibleSMul E E 𝕜 𝕝] {s : Set E} {x : E} theorem StrictConvex.smul (hs : StrictConvex 𝕜 s) (c : 𝕝) : StrictConvex 𝕜 (c • s) := by obtain rfl | hc := eq_or_ne c 0 · exact (subsingleton_zero_smul_set _).strictConvex · exact hs.linear_image (LinearMap.lsmul _ _ c) (isOpenMap_smul₀ hc) theorem StrictConvex.affinity [ContinuousAdd E] (hs : StrictConvex 𝕜 s) (z : E) (c : 𝕝) : StrictConvex 𝕜 (z +ᵥ c • s) := (hs.smul c).vadd z end ContinuousSMul end AddCommGroup end OrderedSemiring section OrderedCommSemiring variable [OrderedCommSemiring 𝕜] [TopologicalSpace E] section AddCommGroup variable [AddCommGroup E] [Module 𝕜 E] [NoZeroSMulDivisors 𝕜 E] [ContinuousConstSMul 𝕜 E] {s : Set E} theorem StrictConvex.preimage_smul (hs : StrictConvex 𝕜 s) (c : 𝕜) : StrictConvex 𝕜 ((fun z => c • z) ⁻¹' s) := by classical obtain rfl | hc := eq_or_ne c 0 · simp_rw [zero_smul, preimage_const] split_ifs · exact strictConvex_univ · exact strictConvex_empty refine hs.linear_preimage (LinearMap.lsmul _ _ c) ?_ (smul_right_injective E hc) unfold LinearMap.lsmul LinearMap.mk₂ LinearMap.mk₂' LinearMap.mk₂'ₛₗ exact continuous_const_smul _ end AddCommGroup end OrderedCommSemiring section OrderedRing variable [OrderedRing 𝕜] [TopologicalSpace E] [TopologicalSpace F] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s t : Set E} {x y : E} theorem StrictConvex.eq_of_openSegment_subset_frontier [Nontrivial 𝕜] [DenselyOrdered 𝕜] (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) (h : openSegment 𝕜 x y ⊆ frontier s) : x = y := by obtain ⟨a, ha₀, ha₁⟩ := DenselyOrdered.dense (0 : 𝕜) 1 zero_lt_one classical by_contra hxy exact (h ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel _ _, rfl⟩).2 (hs hx hy hxy ha₀ (sub_pos_of_lt ha₁) <| add_sub_cancel _ _) theorem StrictConvex.add_smul_mem (hs : StrictConvex 𝕜 s) (hx : x ∈ s) (hxy : x + y ∈ s) (hy : y ≠ 0) {t : 𝕜} (ht₀ : 0 < t) (ht₁ : t < 1) : x + t • y ∈ interior s := by have h : x + t • y = (1 - t) • x + t • (x + y) := by rw [smul_add, ← add_assoc, ← _root_.add_smul, sub_add_cancel, one_smul] rw [h] exact hs hx hxy (fun h => hy <| add_left_cancel (a := x) (by rw [← h, add_zero])) (sub_pos_of_lt ht₁) ht₀ (sub_add_cancel 1 t) theorem StrictConvex.smul_mem_of_zero_mem (hs : StrictConvex 𝕜 s) (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) (hx₀ : x ≠ 0) {t : 𝕜} (ht₀ : 0 < t) (ht₁ : t < 1) : t • x ∈ interior s := by simpa using hs.add_smul_mem zero_mem (by simpa using hx) hx₀ ht₀ ht₁ theorem StrictConvex.add_smul_sub_mem (h : StrictConvex 𝕜 s) (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {t : 𝕜} (ht₀ : 0 < t) (ht₁ : t < 1) : x + t • (y - x) ∈ interior s := by apply h.openSegment_subset hx hy hxy rw [openSegment_eq_image'] exact mem_image_of_mem _ ⟨ht₀, ht₁⟩ /-- The preimage of a strictly convex set under an affine map is strictly convex. -/ theorem StrictConvex.affine_preimage {s : Set F} (hs : StrictConvex 𝕜 s) {f : E →ᵃ[𝕜] F} (hf : Continuous f) (hfinj : Injective f) : StrictConvex 𝕜 (f ⁻¹' s) := by intro x hx y hy hxy a b ha hb hab refine preimage_interior_subset_interior_preimage hf ?_ rw [mem_preimage, Convex.combo_affine_apply hab] exact hs hx hy (hfinj.ne hxy) ha hb hab /-- The image of a strictly convex set under an affine map is strictly convex. -/ theorem StrictConvex.affine_image (hs : StrictConvex 𝕜 s) {f : E →ᵃ[𝕜] F} (hf : IsOpenMap f) : StrictConvex 𝕜 (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ hxy a b ha hb hab exact hf.image_interior_subset _ ⟨a • x + b • y, ⟨hs hx hy (ne_of_apply_ne _ hxy) ha hb hab, Convex.combo_affine_apply hab⟩⟩ variable [TopologicalAddGroup E] theorem StrictConvex.neg (hs : StrictConvex 𝕜 s) : StrictConvex 𝕜 (-s) := hs.is_linear_preimage IsLinearMap.isLinearMap_neg continuous_id.neg neg_injective theorem StrictConvex.sub (hs : StrictConvex 𝕜 s) (ht : StrictConvex 𝕜 t) : StrictConvex 𝕜 (s - t) := (sub_eq_add_neg s t).symm ▸ hs.add ht.neg end AddCommGroup end OrderedRing section LinearOrderedField variable [LinearOrderedField 𝕜] [TopologicalSpace E] section AddCommGroup variable [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F] {s : Set E} {x : E} /-- Alternative definition of set strict convexity, using division. -/ theorem strictConvex_iff_div : StrictConvex 𝕜 s ↔ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → (a / (a + b)) • x + (b / (a + b)) • y ∈ interior s := ⟨fun h x hx y hy hxy a b ha hb => by apply h hx hy hxy (div_pos ha <| add_pos ha hb) (div_pos hb <| add_pos ha hb) rw [← add_div] exact div_self (add_pos ha hb).ne', fun h x hx y hy hxy a b ha hb hab => by convert h hx hy hxy ha hb <;> rw [hab, div_one]⟩ theorem StrictConvex.mem_smul_of_zero_mem (hs : StrictConvex 𝕜 s) (zero_mem : (0 : E) ∈ s) (hx : x ∈ s) (hx₀ : x ≠ 0) {t : 𝕜} (ht : 1 < t) : x ∈ t • interior s := by rw [mem_smul_set_iff_inv_smul_mem₀ (zero_lt_one.trans ht).ne'] exact hs.smul_mem_of_zero_mem zero_mem hx hx₀ (inv_pos.2 <| zero_lt_one.trans ht) (inv_lt_one ht) end AddCommGroup end LinearOrderedField /-! #### Convex sets in an ordered space Relates `Convex` and `Set.OrdConnected`. -/ section variable [LinearOrderedField 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {s : Set 𝕜} /-- A set in a linear ordered field is strictly convex if and only if it is convex. -/ @[simp] theorem strictConvex_iff_convex : StrictConvex 𝕜 s ↔ Convex 𝕜 s := ⟨StrictConvex.convex, fun hs => hs.ordConnected.strictConvex⟩ theorem strictConvex_iff_ordConnected : StrictConvex 𝕜 s ↔ s.OrdConnected := strictConvex_iff_convex.trans convex_iff_ordConnected alias ⟨StrictConvex.ordConnected, _⟩ := strictConvex_iff_ordConnected end
Analysis\Convex\StrictConvexBetween.lean
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.StrictConvexSpace import Mathlib.Analysis.NormedSpace.AffineIsometry /-! # Betweenness in affine spaces for strictly convex spaces This file proves results about betweenness for points in an affine space for a strictly convex space. -/ open Metric open scoped Convex variable {V P : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] variable [StrictConvexSpace ℝ V] section PseudoMetricSpace variable [PseudoMetricSpace P] [NormedAddTorsor V P] theorem Sbtw.dist_lt_max_dist (p : P) {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : dist p₂ p < max (dist p₁ p) (dist p₃ p) := by have hp₁p₃ : p₁ -ᵥ p ≠ p₃ -ᵥ p := by simpa using h.left_ne_right rw [Sbtw, ← wbtw_vsub_const_iff p, Wbtw, affineSegment_eq_segment, ← insert_endpoints_openSegment, Set.mem_insert_iff, Set.mem_insert_iff] at h rcases h with ⟨h | h | h, hp₂p₁, hp₂p₃⟩ · rw [vsub_left_cancel_iff] at h exact False.elim (hp₂p₁ h) · rw [vsub_left_cancel_iff] at h exact False.elim (hp₂p₃ h) · rw [openSegment_eq_image, Set.mem_image] at h rcases h with ⟨r, ⟨hr0, hr1⟩, hr⟩ simp_rw [@dist_eq_norm_vsub V, ← hr] exact norm_combo_lt_of_ne (le_max_left _ _) (le_max_right _ _) hp₁p₃ (sub_pos.2 hr1) hr0 (by abel) theorem Wbtw.dist_le_max_dist (p : P) {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : dist p₂ p ≤ max (dist p₁ p) (dist p₃ p) := by by_cases hp₁ : p₂ = p₁; · simp [hp₁] by_cases hp₃ : p₂ = p₃; · simp [hp₃] have hs : Sbtw ℝ p₁ p₂ p₃ := ⟨h, hp₁, hp₃⟩ exact (hs.dist_lt_max_dist _).le /-- Given three collinear points, two (not equal) with distance `r` from `p` and one with distance at most `r` from `p`, the third point is weakly between the other two points. -/ theorem Collinear.wbtw_of_dist_eq_of_dist_le {p p₁ p₂ p₃ : P} {r : ℝ} (h : Collinear ℝ ({p₁, p₂, p₃} : Set P)) (hp₁ : dist p₁ p = r) (hp₂ : dist p₂ p ≤ r) (hp₃ : dist p₃ p = r) (hp₁p₃ : p₁ ≠ p₃) : Wbtw ℝ p₁ p₂ p₃ := by rcases h.wbtw_or_wbtw_or_wbtw with (hw | hw | hw) · exact hw · by_cases hp₃p₂ : p₃ = p₂ · simp [hp₃p₂] have hs : Sbtw ℝ p₂ p₃ p₁ := ⟨hw, hp₃p₂, hp₁p₃.symm⟩ have hs' := hs.dist_lt_max_dist p rw [hp₁, hp₃, lt_max_iff, lt_self_iff_false, or_false_iff] at hs' exact False.elim (hp₂.not_lt hs') · by_cases hp₁p₂ : p₁ = p₂ · simp [hp₁p₂] have hs : Sbtw ℝ p₃ p₁ p₂ := ⟨hw, hp₁p₃, hp₁p₂⟩ have hs' := hs.dist_lt_max_dist p rw [hp₁, hp₃, lt_max_iff, lt_self_iff_false, false_or_iff] at hs' exact False.elim (hp₂.not_lt hs') /-- Given three collinear points, two (not equal) with distance `r` from `p` and one with distance less than `r` from `p`, the third point is strictly between the other two points. -/ theorem Collinear.sbtw_of_dist_eq_of_dist_lt {p p₁ p₂ p₃ : P} {r : ℝ} (h : Collinear ℝ ({p₁, p₂, p₃} : Set P)) (hp₁ : dist p₁ p = r) (hp₂ : dist p₂ p < r) (hp₃ : dist p₃ p = r) (hp₁p₃ : p₁ ≠ p₃) : Sbtw ℝ p₁ p₂ p₃ := by refine ⟨h.wbtw_of_dist_eq_of_dist_le hp₁ hp₂.le hp₃ hp₁p₃, ?_, ?_⟩ · rintro rfl exact hp₂.ne hp₁ · rintro rfl exact hp₂.ne hp₃ end PseudoMetricSpace section MetricSpace variable [MetricSpace P] [NormedAddTorsor V P] {a b c : P} /-- In a strictly convex space, the triangle inequality turns into an equality if and only if the middle point belongs to the segment joining two other points. -/ lemma dist_add_dist_eq_iff : dist a b + dist b c = dist a c ↔ Wbtw ℝ a b c := by have : dist (a -ᵥ a) (b -ᵥ a) + dist (b -ᵥ a) (c -ᵥ a) = dist (a -ᵥ a) (c -ᵥ a) ↔ b -ᵥ a ∈ segment ℝ (a -ᵥ a) (c -ᵥ a) := by simp only [mem_segment_iff_sameRay, sameRay_iff_norm_add, dist_eq_norm', sub_add_sub_cancel', eq_comm] simp_rw [dist_vsub_cancel_right, ← affineSegment_eq_segment, ← affineSegment_vsub_const_image] at this rwa [(vsub_left_injective _).mem_set_image] at this end MetricSpace variable {E F PE PF : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] [StrictConvexSpace ℝ E] [MetricSpace PE] [MetricSpace PF] [NormedAddTorsor E PE] [NormedAddTorsor F PF] {r : ℝ} {f : PF → PE} {x y z : PE} lemma eq_lineMap_of_dist_eq_mul_of_dist_eq_mul (hxy : dist x y = r * dist x z) (hyz : dist y z = (1 - r) * dist x z) : y = AffineMap.lineMap x z r := by have : y -ᵥ x ∈ [(0 : E) -[ℝ] z -ᵥ x] := by rw [mem_segment_iff_wbtw, ← dist_add_dist_eq_iff, dist_zero_left, dist_vsub_cancel_right, ← dist_eq_norm_vsub', ← dist_eq_norm_vsub', hxy, hyz, ← add_mul, add_sub_cancel, one_mul] obtain rfl | hne := eq_or_ne x z · obtain rfl : y = x := by simpa simp · rw [← dist_ne_zero] at hne obtain ⟨a, b, _, hb, _, H⟩ := this rw [smul_zero, zero_add] at H have H' := congr_arg norm H rw [norm_smul, Real.norm_of_nonneg hb, ← dist_eq_norm_vsub', ← dist_eq_norm_vsub', hxy, mul_left_inj' hne] at H' rw [AffineMap.lineMap_apply, ← H', H, vsub_vadd] lemma eq_midpoint_of_dist_eq_half (hx : dist x y = dist x z / 2) (hy : dist y z = dist x z / 2) : y = midpoint ℝ x z := by apply eq_lineMap_of_dist_eq_mul_of_dist_eq_mul · rwa [invOf_eq_inv, ← div_eq_inv_mul] · rwa [invOf_eq_inv, ← one_div, sub_half, one_div, ← div_eq_inv_mul] namespace Isometry /-- An isometry of `NormedAddTorsor`s for real normed spaces, strictly convex in the case of the codomain, is an affine isometry. Unlike Mazur-Ulam, this does not require the isometry to be surjective. -/ noncomputable def affineIsometryOfStrictConvexSpace (hi : Isometry f) : PF →ᵃⁱ[ℝ] PE := { AffineMap.ofMapMidpoint f (fun x y => by apply eq_midpoint_of_dist_eq_half · rw [hi.dist_eq, hi.dist_eq] simp only [dist_left_midpoint, Real.norm_of_nonneg zero_le_two, div_eq_inv_mul] · rw [hi.dist_eq, hi.dist_eq] simp only [dist_midpoint_right, Real.norm_of_nonneg zero_le_two, div_eq_inv_mul]) hi.continuous with norm_map := fun x => by simp [AffineMap.ofMapMidpoint, ← dist_eq_norm_vsub E, hi.dist_eq] } @[simp] lemma coe_affineIsometryOfStrictConvexSpace (hi : Isometry f) : ⇑hi.affineIsometryOfStrictConvexSpace = f := rfl @[simp] lemma affineIsometryOfStrictConvexSpace_apply (hi : Isometry f) (p : PF) : hi.affineIsometryOfStrictConvexSpace p = f p := rfl end Isometry
Analysis\Convex\StrictConvexSpace.lean
/- 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, Yury Kudryashov -/ import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.Convex.Strict import Mathlib.Analysis.Normed.Order.Basic import Mathlib.Analysis.NormedSpace.AddTorsor import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Normed.Module.Ray /-! # Strictly convex spaces This file defines strictly convex spaces. A normed space is strictly convex if all closed balls are strictly convex. This does **not** mean that the norm is strictly convex (in fact, it never is). ## Main definitions `StrictConvexSpace`: a typeclass saying that a given normed space over a normed linear ordered field (e.g., `ℝ` or `ℚ`) is strictly convex. The definition requires strict convexity of a closed ball of positive radius with center at the origin; strict convexity of any other closed ball follows from this assumption. ## Main results In a strictly convex space, we prove - `strictConvex_closedBall`: a closed ball is strictly convex. - `combo_mem_ball_of_ne`, `openSegment_subset_ball_of_ne`, `norm_combo_lt_of_ne`: a nontrivial convex combination of two points in a closed ball belong to the corresponding open ball; - `norm_add_lt_of_not_sameRay`, `sameRay_iff_norm_add`, `dist_add_dist_eq_iff`: the triangle inequality `dist x y + dist y z ≤ dist x z` is a strict inequality unless `y` belongs to the segment `[x -[ℝ] z]`. - `Isometry.affineIsometryOfStrictConvexSpace`: an isometry of `NormedAddTorsor`s for real normed spaces, strictly convex in the case of the codomain, is an affine isometry. We also provide several lemmas that can be used as alternative constructors for `StrictConvex ℝ E`: - `StrictConvexSpace.of_strictConvex_closed_unit_ball`: if `closed_ball (0 : E) 1` is strictly convex, then `E` is a strictly convex space; - `StrictConvexSpace.of_norm_add`: if `‖x + y‖ = ‖x‖ + ‖y‖` implies `SameRay ℝ x y` for all nonzero `x y : E`, then `E` is a strictly convex space. ## Implementation notes While the definition is formulated for any normed linear ordered field, most of the lemmas are formulated only for the case `𝕜 = ℝ`. ## Tags convex, strictly convex -/ open Convex Pointwise Set Metric /-- A *strictly convex space* is a normed space where the closed balls are strictly convex. We only require balls of positive radius with center at the origin to be strictly convex in the definition, then prove that any closed ball is strictly convex in `strictConvex_closedBall` below. See also `StrictConvexSpace.of_strictConvex_closed_unit_ball`. -/ class StrictConvexSpace (𝕜 E : Type*) [NormedLinearOrderedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] : Prop where strictConvex_closedBall : ∀ r : ℝ, 0 < r → StrictConvex 𝕜 (closedBall (0 : E) r) variable (𝕜 : Type*) {E : Type*} [NormedLinearOrderedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] /-- A closed ball in a strictly convex space is strictly convex. -/ theorem strictConvex_closedBall [StrictConvexSpace 𝕜 E] (x : E) (r : ℝ) : StrictConvex 𝕜 (closedBall x r) := by rcases le_or_lt r 0 with hr | hr · exact (subsingleton_closedBall x hr).strictConvex rw [← vadd_closedBall_zero] exact (StrictConvexSpace.strictConvex_closedBall r hr).vadd _ variable [NormedSpace ℝ E] /-- A real normed vector space is strictly convex provided that the unit ball is strictly convex. -/ theorem StrictConvexSpace.of_strictConvex_closed_unit_ball [LinearMap.CompatibleSMul E E 𝕜 ℝ] (h : StrictConvex 𝕜 (closedBall (0 : E) 1)) : StrictConvexSpace 𝕜 E := ⟨fun r hr => by simpa only [smul_closedUnitBall_of_nonneg hr.le] using h.smul r⟩ /-- Strict convexity is equivalent to `‖a • x + b • y‖ < 1` for all `x` and `y` of norm at most `1` and all strictly positive `a` and `b` such that `a + b = 1`. This lemma shows that it suffices to check this for points of norm one and some `a`, `b` such that `a + b = 1`. -/ theorem StrictConvexSpace.of_norm_combo_lt_one (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ∃ a b : ℝ, a + b = 1 ∧ ‖a • x + b • y‖ < 1) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_strictConvex_closed_unit_ball ℝ ((convex_closedBall _ _).strictConvex' fun x hx y hy hne => ?_) rw [interior_closedBall (0 : E) one_ne_zero, closedBall_diff_ball, mem_sphere_zero_iff_norm] at hx hy rcases h x y hx hy hne with ⟨a, b, hab, hlt⟩ use b rwa [AffineMap.lineMap_apply_module, interior_closedBall (0 : E) one_ne_zero, mem_ball_zero_iff, sub_eq_iff_eq_add.2 hab.symm] theorem StrictConvexSpace.of_norm_combo_ne_one (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ∃ a b : ℝ, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ ‖a • x + b • y‖ ≠ 1) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_strictConvex_closed_unit_ball ℝ ((convex_closedBall _ _).strictConvex ?_) simp only [interior_closedBall _ one_ne_zero, closedBall_diff_ball, Set.Pairwise, frontier_closedBall _ one_ne_zero, mem_sphere_zero_iff_norm] intro x hx y hy hne rcases h x y hx hy hne with ⟨a, b, ha, hb, hab, hne'⟩ exact ⟨_, ⟨a, b, ha, hb, hab, rfl⟩, mt mem_sphere_zero_iff_norm.1 hne'⟩ theorem StrictConvexSpace.of_norm_add_ne_two (h : ∀ ⦃x y : E⦄, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ‖x + y‖ ≠ 2) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_norm_combo_ne_one fun x y hx hy hne => ⟨1 / 2, 1 / 2, one_half_pos.le, one_half_pos.le, add_halves _, ?_⟩ rw [← smul_add, norm_smul, Real.norm_of_nonneg one_half_pos.le, one_div, ← div_eq_inv_mul, Ne, div_eq_one_iff_eq (two_ne_zero' ℝ)] exact h hx hy hne theorem StrictConvexSpace.of_pairwise_sphere_norm_ne_two (h : (sphere (0 : E) 1).Pairwise fun x y => ‖x + y‖ ≠ 2) : StrictConvexSpace ℝ E := StrictConvexSpace.of_norm_add_ne_two fun _ _ hx hy => h (mem_sphere_zero_iff_norm.2 hx) (mem_sphere_zero_iff_norm.2 hy) /-- If `‖x + y‖ = ‖x‖ + ‖y‖` implies that `x y : E` are in the same ray, then `E` is a strictly convex space. See also a more -/ theorem StrictConvexSpace.of_norm_add (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → ‖x + y‖ = 2 → SameRay ℝ x y) : StrictConvexSpace ℝ E := by refine StrictConvexSpace.of_pairwise_sphere_norm_ne_two fun x hx y hy => mt fun h₂ => ?_ rw [mem_sphere_zero_iff_norm] at hx hy exact (sameRay_iff_of_norm_eq (hx.trans hy.symm)).1 (h x y hx hy h₂) variable [StrictConvexSpace ℝ E] {x y z : E} {a b r : ℝ} /-- If `x ≠ y` belong to the same closed ball, then a convex combination of `x` and `y` with positive coefficients belongs to the corresponding open ball. -/ theorem combo_mem_ball_of_ne (hx : x ∈ closedBall z r) (hy : y ∈ closedBall z r) (hne : x ≠ y) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ ball z r := by rcases eq_or_ne r 0 with (rfl | hr) · rw [closedBall_zero, mem_singleton_iff] at hx hy exact (hne (hx.trans hy.symm)).elim · simp only [← interior_closedBall _ hr] at hx hy ⊢ exact strictConvex_closedBall ℝ z r hx hy hne ha hb hab /-- If `x ≠ y` belong to the same closed ball, then the open segment with endpoints `x` and `y` is included in the corresponding open ball. -/ theorem openSegment_subset_ball_of_ne (hx : x ∈ closedBall z r) (hy : y ∈ closedBall z r) (hne : x ≠ y) : openSegment ℝ x y ⊆ ball z r := (openSegment_subset_iff _).2 fun _ _ => combo_mem_ball_of_ne hx hy hne /-- If `x` and `y` are two distinct vectors of norm at most `r`, then a convex combination of `x` and `y` with positive coefficients has norm strictly less than `r`. -/ theorem norm_combo_lt_of_ne (hx : ‖x‖ ≤ r) (hy : ‖y‖ ≤ r) (hne : x ≠ y) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : ‖a • x + b • y‖ < r := by simp only [← mem_ball_zero_iff, ← mem_closedBall_zero_iff] at hx hy ⊢ exact combo_mem_ball_of_ne hx hy hne ha hb hab /-- In a strictly convex space, if `x` and `y` are not in the same ray, then `‖x + y‖ < ‖x‖ + ‖y‖`. -/ theorem norm_add_lt_of_not_sameRay (h : ¬SameRay ℝ x y) : ‖x + y‖ < ‖x‖ + ‖y‖ := by simp only [sameRay_iff_inv_norm_smul_eq, not_or, ← Ne.eq_def] at h rcases h with ⟨hx, hy, hne⟩ rw [← norm_pos_iff] at hx hy have hxy : 0 < ‖x‖ + ‖y‖ := add_pos hx hy have := combo_mem_ball_of_ne (inv_norm_smul_mem_closed_unit_ball x) (inv_norm_smul_mem_closed_unit_ball y) hne (div_pos hx hxy) (div_pos hy hxy) (by rw [← add_div, div_self hxy.ne']) rwa [mem_ball_zero_iff, div_eq_inv_mul, div_eq_inv_mul, mul_smul, mul_smul, smul_inv_smul₀ hx.ne', smul_inv_smul₀ hy.ne', ← smul_add, norm_smul, Real.norm_of_nonneg (inv_pos.2 hxy).le, ← div_eq_inv_mul, div_lt_one hxy] at this theorem lt_norm_sub_of_not_sameRay (h : ¬SameRay ℝ x y) : ‖x‖ - ‖y‖ < ‖x - y‖ := by nth_rw 1 [← sub_add_cancel x y] at h ⊢ exact sub_lt_iff_lt_add.2 (norm_add_lt_of_not_sameRay fun H' => h <| H'.add_left SameRay.rfl) theorem abs_lt_norm_sub_of_not_sameRay (h : ¬SameRay ℝ x y) : |‖x‖ - ‖y‖| < ‖x - y‖ := by refine abs_sub_lt_iff.2 ⟨lt_norm_sub_of_not_sameRay h, ?_⟩ rw [norm_sub_rev] exact lt_norm_sub_of_not_sameRay (mt SameRay.symm h) /-- In a strictly convex space, two vectors `x`, `y` are in the same ray if and only if the triangle inequality for `x` and `y` becomes an equality. -/ theorem sameRay_iff_norm_add : SameRay ℝ x y ↔ ‖x + y‖ = ‖x‖ + ‖y‖ := ⟨SameRay.norm_add, fun h => Classical.not_not.1 fun h' => (norm_add_lt_of_not_sameRay h').ne h⟩ /-- If `x` and `y` are two vectors in a strictly convex space have the same norm and the norm of their sum is equal to the sum of their norms, then they are equal. -/ theorem eq_of_norm_eq_of_norm_add_eq (h₁ : ‖x‖ = ‖y‖) (h₂ : ‖x + y‖ = ‖x‖ + ‖y‖) : x = y := (sameRay_iff_norm_add.mpr h₂).eq_of_norm_eq h₁ /-- In a strictly convex space, two vectors `x`, `y` are not in the same ray if and only if the triangle inequality for `x` and `y` is strict. -/ theorem not_sameRay_iff_norm_add_lt : ¬SameRay ℝ x y ↔ ‖x + y‖ < ‖x‖ + ‖y‖ := sameRay_iff_norm_add.not.trans (norm_add_le _ _).lt_iff_ne.symm theorem sameRay_iff_norm_sub : SameRay ℝ x y ↔ ‖x - y‖ = |‖x‖ - ‖y‖| := ⟨SameRay.norm_sub, fun h => Classical.not_not.1 fun h' => (abs_lt_norm_sub_of_not_sameRay h').ne' h⟩ theorem not_sameRay_iff_abs_lt_norm_sub : ¬SameRay ℝ x y ↔ |‖x‖ - ‖y‖| < ‖x - y‖ := sameRay_iff_norm_sub.not.trans <| ne_comm.trans (abs_norm_sub_norm_le _ _).lt_iff_ne.symm theorem norm_midpoint_lt_iff (h : ‖x‖ = ‖y‖) : ‖(1 / 2 : ℝ) • (x + y)‖ < ‖x‖ ↔ x ≠ y := by rw [norm_smul, Real.norm_of_nonneg (one_div_nonneg.2 zero_le_two), ← inv_eq_one_div, ← div_eq_inv_mul, div_lt_iff (zero_lt_two' ℝ), mul_two, ← not_sameRay_iff_of_norm_eq h, not_sameRay_iff_norm_add_lt, h]
Analysis\Convex\Strong.lean
/- Copyright (c) 2023 Yaël Dillies, Chenyi Li. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chenyi Li, Ziyu Wang, Yaël Dillies -/ import Mathlib.Analysis.InnerProductSpace.Basic /-! # Uniformly and strongly convex functions In this file, we define uniformly convex functions and strongly convex functions. For a real normed space `E`, a uniformly convex function with modulus `φ : ℝ → ℝ` is a function `f : E → ℝ` such that `f (t • x + (1 - t) • y) ≤ t • f x + (1 - t) • f y - t * (1 - t) * φ ‖x - y‖` for all `t ∈ [0, 1]`. A `m`-strongly convex function is a uniformly convex function with modulus `fun r ↦ m / 2 * r ^ 2`. If `E` is an inner product space, this is equivalent to `x ↦ f x - m / 2 * ‖x‖ ^ 2` being convex. ## TODO Prove derivative properties of strongly convex functions. -/ open Real variable {E : Type*} [NormedAddCommGroup E] section NormedSpace variable [NormedSpace ℝ E] {φ ψ : ℝ → ℝ} {s : Set E} {a b m : ℝ} {x y : E} {f g : E → ℝ} /-- A function `f` from a real normed space is uniformly convex with modulus `φ` if `f (t • x + (1 - t) • y) ≤ t • f x + (1 - t) • f y - t * (1 - t) * φ ‖x - y‖` for all `t ∈ [0, 1]`. `φ` is usually taken to be a monotone function such that `φ r = 0 ↔ r = 0`. -/ def UniformConvexOn (s : Set E) (φ : ℝ → ℝ) (f : E → ℝ) : Prop := Convex ℝ s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y - a * b * φ ‖x - y‖ /-- A function `f` from a real normed space is uniformly concave with modulus `φ` if `t • f x + (1 - t) • f y + t * (1 - t) * φ ‖x - y‖ ≤ f (t • x + (1 - t) • y)` for all `t ∈ [0, 1]`. `φ` is usually taken to be a monotone function such that `φ r = 0 ↔ r = 0`. -/ def UniformConcaveOn (s : Set E) (φ : ℝ → ℝ) (f : E → ℝ) : Prop := Convex ℝ s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • f x + b • f y + a * b * φ ‖x - y‖ ≤ f (a • x + b • y) @[simp] lemma uniformConvexOn_zero : UniformConvexOn s 0 f ↔ ConvexOn ℝ s f := by simp [UniformConvexOn, ConvexOn] @[simp] lemma uniformConcaveOn_zero : UniformConcaveOn s 0 f ↔ ConcaveOn ℝ s f := by simp [UniformConcaveOn, ConcaveOn] protected alias ⟨_, ConvexOn.uniformConvexOn_zero⟩ := uniformConvexOn_zero protected alias ⟨_, ConcaveOn.uniformConcaveOn_zero⟩ := uniformConcaveOn_zero lemma UniformConvexOn.mono (hψφ : ψ ≤ φ) (hf : UniformConvexOn s φ f) : UniformConvexOn s ψ f := ⟨hf.1, fun x hx y hy a b ha hb hab ↦ (hf.2 hx hy ha hb hab).trans <| by gcongr; apply hψφ⟩ lemma UniformConcaveOn.mono (hψφ : ψ ≤ φ) (hf : UniformConcaveOn s φ f) : UniformConcaveOn s ψ f := ⟨hf.1, fun x hx y hy a b ha hb hab ↦ (hf.2 hx hy ha hb hab).trans' <| by gcongr; apply hψφ⟩ lemma UniformConvexOn.convexOn (hf : UniformConvexOn s φ f) (hφ : 0 ≤ φ) : ConvexOn ℝ s f := by simpa using hf.mono hφ lemma UniformConcaveOn.concaveOn (hf : UniformConcaveOn s φ f) (hφ : 0 ≤ φ) : ConcaveOn ℝ s f := by simpa using hf.mono hφ lemma UniformConvexOn.strictConvexOn (hf : UniformConvexOn s φ f) (hφ : ∀ r, r ≠ 0 → 0 < φ r) : StrictConvexOn ℝ s f := by refine ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ (hf.2 hx hy ha.le hb.le hab).trans_lt <| sub_lt_self _ ?_⟩ rw [← sub_ne_zero, ← norm_pos_iff] at hxy have := hφ _ hxy.ne' positivity lemma UniformConcaveOn.strictConcaveOn (hf : UniformConcaveOn s φ f) (hφ : ∀ r, r ≠ 0 → 0 < φ r) : StrictConcaveOn ℝ s f := by refine ⟨hf.1, fun x hx y hy hxy a b ha hb hab ↦ (hf.2 hx hy ha.le hb.le hab).trans_lt' <| lt_add_of_pos_right _ ?_⟩ rw [← sub_ne_zero, ← norm_pos_iff] at hxy have := hφ _ hxy.ne' positivity lemma UniformConvexOn.add (hf : UniformConvexOn s φ f) (hg : UniformConvexOn s ψ g) : UniformConvexOn s (φ + ψ) (f + g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ simpa [mul_add, add_add_add_comm, sub_add_sub_comm] using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) lemma UniformConcaveOn.add (hf : UniformConcaveOn s φ f) (hg : UniformConcaveOn s ψ g) : UniformConcaveOn s (φ + ψ) (f + g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ simpa [mul_add, add_add_add_comm] using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) lemma UniformConvexOn.neg (hf : UniformConvexOn s φ f) : UniformConcaveOn s φ (-f) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ le_of_neg_le_neg ?_⟩ simpa [add_comm, -neg_le_neg_iff, le_sub_iff_add_le'] using hf.2 hx hy ha hb hab lemma UniformConcaveOn.neg (hf : UniformConcaveOn s φ f) : UniformConvexOn s φ (-f) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ le_of_neg_le_neg ?_⟩ simpa [add_comm, -neg_le_neg_iff, ← le_sub_iff_add_le', sub_eq_add_neg, neg_add] using hf.2 hx hy ha hb hab lemma UniformConvexOn.sub (hf : UniformConvexOn s φ f) (hg : UniformConcaveOn s ψ g) : UniformConvexOn s (φ + ψ) (f - g) := by simpa using hf.add hg.neg lemma UniformConcaveOn.sub (hf : UniformConcaveOn s φ f) (hg : UniformConvexOn s ψ g) : UniformConcaveOn s (φ + ψ) (f - g) := by simpa using hf.add hg.neg /-- A function `f` from a real normed space is `m`-strongly convex if it is uniformly convex with modulus `φ(r) = m / 2 * r ^ 2`. In an inner product space, this is equivalent to `x ↦ f x - m / 2 * ‖x‖ ^ 2` being convex. -/ def StrongConvexOn (s : Set E) (m : ℝ) : (E → ℝ) → Prop := UniformConvexOn s fun r ↦ m / (2 : ℝ) * r ^ 2 /-- A function `f` from a real normed space is `m`-strongly concave if is strongly concave with modulus `φ(r) = m / 2 * r ^ 2`. In an inner product space, this is equivalent to `x ↦ f x + m / 2 * ‖x‖ ^ 2` being concave. -/ def StrongConcaveOn (s : Set E) (m : ℝ) : (E → ℝ) → Prop := UniformConcaveOn s fun r ↦ m / (2 : ℝ) * r ^ 2 variable {s : Set E} {f : E → ℝ} {m n : ℝ} nonrec lemma StrongConvexOn.mono (hmn : m ≤ n) (hf : StrongConvexOn s n f) : StrongConvexOn s m f := hf.mono fun r ↦ by gcongr nonrec lemma StrongConcaveOn.mono (hmn : m ≤ n) (hf : StrongConcaveOn s n f) : StrongConcaveOn s m f := hf.mono fun r ↦ by gcongr @[simp] lemma strongConvexOn_zero : StrongConvexOn s 0 f ↔ ConvexOn ℝ s f := by simp [StrongConvexOn, ← Pi.zero_def] @[simp] lemma strongConcaveOn_zero : StrongConcaveOn s 0 f ↔ ConcaveOn ℝ s f := by simp [StrongConcaveOn, ← Pi.zero_def] nonrec lemma StrongConvexOn.strictConvexOn (hf : StrongConvexOn s m f) (hm : 0 < m) : StrictConvexOn ℝ s f := hf.strictConvexOn fun r hr ↦ by positivity nonrec lemma StrongConcaveOn.strictConcaveOn (hf : StrongConcaveOn s m f) (hm : 0 < m) : StrictConcaveOn ℝ s f := hf.strictConcaveOn fun r hr ↦ by positivity end NormedSpace section InnerProductSpace variable [InnerProductSpace ℝ E] {φ ψ : ℝ → ℝ} {s : Set E} {a b m : ℝ} {x y : E} {f : E → ℝ} private lemma aux_sub (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : a * (f x - m / (2 : ℝ) * ‖x‖ ^ 2) + b * (f y - m / (2 : ℝ) * ‖y‖ ^ 2) + m / (2 : ℝ) * ‖a • x + b • y‖ ^ 2 = a * f x + b * f y - m / (2 : ℝ) * a * b * ‖x - y‖ ^ 2 := by rw [norm_add_sq_real, norm_sub_sq_real, norm_smul, norm_smul, real_inner_smul_left, inner_smul_right, norm_of_nonneg ha, norm_of_nonneg hb, mul_pow, mul_pow] obtain rfl := eq_sub_of_add_eq hab ring_nf private lemma aux_add (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : a * (f x + m / (2 : ℝ) * ‖x‖ ^ 2) + b * (f y + m / (2 : ℝ) * ‖y‖ ^ 2) - m / (2 : ℝ) * ‖a • x + b • y‖ ^ 2 = a * f x + b * f y + m / (2 : ℝ) * a * b * ‖x - y‖ ^ 2 := by simpa [neg_div] using aux_sub (E := E) (m := -m) ha hb hab lemma strongConvexOn_iff_convex : StrongConvexOn s m f ↔ ConvexOn ℝ s fun x ↦ f x - m / (2 : ℝ) * ‖x‖ ^ 2 := by refine and_congr_right fun _ ↦ forall₄_congr fun x _ y _ ↦ forall₅_congr fun a b ha hb hab ↦ ?_ simp_rw [sub_le_iff_le_add, smul_eq_mul, aux_sub ha hb hab, mul_assoc, mul_left_comm] lemma strongConcaveOn_iff_convex : StrongConcaveOn s m f ↔ ConcaveOn ℝ s fun x ↦ f x + m / (2 : ℝ) * ‖x‖ ^ 2 := by refine and_congr_right fun _ ↦ forall₄_congr fun x _ y _ ↦ forall₅_congr fun a b ha hb hab ↦ ?_ simp_rw [← sub_le_iff_le_add, smul_eq_mul, aux_add ha hb hab, mul_assoc, mul_left_comm] end InnerProductSpace
Analysis\Convex\Topology.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov -/ import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Strict import Mathlib.Topology.Connected.PathConnected import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.Algebra.Module.Basic /-! # Topological properties of convex sets We prove the following facts: * `Convex.interior` : interior of a convex set is convex; * `Convex.closure` : closure of a convex set is convex; * `Set.Finite.isCompact_convexHull` : convex hull of a finite set is compact; * `Set.Finite.isClosed_convexHull` : convex hull of a finite set is closed. -/ assert_not_exists Norm open Metric Bornology Set Pointwise Convex variable {ι 𝕜 E : Type*} theorem Real.convex_iff_isPreconnected {s : Set ℝ} : Convex ℝ s ↔ IsPreconnected s := convex_iff_ordConnected.trans isPreconnected_iff_ordConnected.symm alias ⟨_, IsPreconnected.convex⟩ := Real.convex_iff_isPreconnected /-! ### Standard simplex -/ section stdSimplex variable [Fintype ι] /-- Every vector in `stdSimplex 𝕜 ι` has `max`-norm at most `1`. -/ theorem stdSimplex_subset_closedBall : stdSimplex ℝ ι ⊆ Metric.closedBall 0 1 := fun f hf ↦ by rw [Metric.mem_closedBall, dist_pi_le_iff zero_le_one] intro x rw [Pi.zero_apply, Real.dist_0_eq_abs, abs_of_nonneg <| hf.1 x] exact (mem_Icc_of_mem_stdSimplex hf x).2 variable (ι) /-- `stdSimplex ℝ ι` is bounded. -/ theorem bounded_stdSimplex : IsBounded (stdSimplex ℝ ι) := (Metric.isBounded_iff_subset_closedBall 0).2 ⟨1, stdSimplex_subset_closedBall⟩ /-- `stdSimplex ℝ ι` is closed. -/ theorem isClosed_stdSimplex : IsClosed (stdSimplex ℝ ι) := (stdSimplex_eq_inter ℝ ι).symm ▸ IsClosed.inter (isClosed_iInter fun i => isClosed_le continuous_const (continuous_apply i)) (isClosed_eq (continuous_finset_sum _ fun x _ => continuous_apply x) continuous_const) /-- `stdSimplex ℝ ι` is compact. -/ theorem isCompact_stdSimplex : IsCompact (stdSimplex ℝ ι) := Metric.isCompact_iff_isClosed_bounded.2 ⟨isClosed_stdSimplex ι, bounded_stdSimplex ι⟩ instance stdSimplex.instCompactSpace_coe : CompactSpace ↥(stdSimplex ℝ ι) := isCompact_iff_compactSpace.mp <| isCompact_stdSimplex _ /-- The standard one-dimensional simplex in `ℝ² = Fin 2 → ℝ` is homeomorphic to the unit interval. -/ @[simps! (config := .asFn)] def stdSimplexHomeomorphUnitInterval : stdSimplex ℝ (Fin 2) ≃ₜ unitInterval where toEquiv := stdSimplexEquivIcc ℝ continuous_toFun := .subtype_mk ((continuous_apply 0).comp continuous_subtype_val) _ continuous_invFun := by apply Continuous.subtype_mk exact (continuous_pi <| Fin.forall_fin_two.2 ⟨continuous_subtype_val, continuous_const.sub continuous_subtype_val⟩) end stdSimplex /-! ### Topological vector spaces -/ section TopologicalSpace variable [LinearOrderedRing 𝕜] [DenselyOrdered 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] [AddCommGroup E] [TopologicalSpace E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E] {x y : E} theorem segment_subset_closure_openSegment : [x -[𝕜] y] ⊆ closure (openSegment 𝕜 x y) := by rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)] exact image_closure_subset_closure_image (by fun_prop) end TopologicalSpace section PseudoMetricSpace variable [LinearOrderedRing 𝕜] [DenselyOrdered 𝕜] [PseudoMetricSpace 𝕜] [OrderTopology 𝕜] [ProperSpace 𝕜] [CompactIccSpace 𝕜] [AddCommGroup E] [TopologicalSpace E] [T2Space E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousSMul 𝕜 E] @[simp] theorem closure_openSegment (x y : E) : closure (openSegment 𝕜 x y) = [x -[𝕜] y] := by rw [segment_eq_image, openSegment_eq_image, ← closure_Ioo (zero_ne_one' 𝕜)] exact (image_closure_of_isCompact (isBounded_Ioo _ _).isCompact_closure <| Continuous.continuousOn <| by fun_prop).symm end PseudoMetricSpace section ContinuousConstSMul variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] /-- If `s` is a convex set, then `a • interior s + b • closure s ⊆ interior s` for all `0 < a`, `0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_self_subset_interior` for a weaker version. -/ theorem Convex.combo_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • closure s ⊆ interior s := interior_smul₀ ha.ne' s ▸ calc interior (a • s) + b • closure s ⊆ interior (a • s) + closure (b • s) := add_subset_add Subset.rfl (smul_closure_subset b s) _ = interior (a • s) + b • s := by rw [isOpen_interior.add_closure (b • s)] _ ⊆ interior (a • s + b • s) := subset_interior_add_left _ ⊆ interior s := interior_mono <| hs.set_combo_subset ha.le hb hab /-- If `s` is a convex set, then `a • interior s + b • s ⊆ interior s` for all `0 < a`, `0 ≤ b`, `a + b = 1`. See also `Convex.combo_interior_closure_subset_interior` for a stronger version. -/ theorem Convex.combo_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • interior s + b • s ⊆ interior s := calc a • interior s + b • s ⊆ a • interior s + b • closure s := add_subset_add Subset.rfl <| image_subset _ subset_closure _ ⊆ interior s := hs.combo_interior_closure_subset_interior ha hb hab /-- If `s` is a convex set, then `a • closure s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`, `a + b = 1`. See also `Convex.combo_self_interior_subset_interior` for a weaker version. -/ theorem Convex.combo_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • closure s + b • interior s ⊆ interior s := by rw [add_comm] exact hs.combo_interior_closure_subset_interior hb ha (add_comm a b ▸ hab) /-- If `s` is a convex set, then `a • s + b • interior s ⊆ interior s` for all `0 ≤ a`, `0 < b`, `a + b = 1`. See also `Convex.combo_closure_interior_subset_interior` for a stronger version. -/ theorem Convex.combo_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • s + b • interior s ⊆ interior s := by rw [add_comm] exact hs.combo_interior_self_subset_interior hb ha (add_comm a b ▸ hab) theorem Convex.combo_interior_closure_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ closure s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_interior_closure_subset_interior ha hb hab <| add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) theorem Convex.combo_interior_self_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_interior_closure_mem_interior hx (subset_closure hy) ha hb hab theorem Convex.combo_closure_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_closure_interior_subset_interior ha hb hab <| add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) theorem Convex.combo_self_interior_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ interior s := hs.combo_closure_interior_mem_interior (subset_closure hx) hy ha hb hab theorem Convex.openSegment_interior_closure_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ closure s) : openSegment 𝕜 x y ⊆ interior s := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ exact hs.combo_interior_closure_mem_interior hx hy ha hb.le hab theorem Convex.openSegment_interior_self_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ interior s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ interior s := hs.openSegment_interior_closure_subset_interior hx (subset_closure hy) theorem Convex.openSegment_closure_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ exact hs.combo_closure_interior_mem_interior hx hy ha.le hb hab theorem Convex.openSegment_self_interior_subset_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) : openSegment 𝕜 x y ⊆ interior s := hs.openSegment_closure_interior_subset_interior (subset_closure hx) hy /-- If `x ∈ closure s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/ theorem Convex.add_smul_sub_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s := by simpa only [sub_smul, smul_sub, one_smul, add_sub, add_comm] using hs.combo_interior_closure_mem_interior hy hx ht.1 (sub_nonneg.mpr ht.2) (add_sub_cancel _ _) /-- If `x ∈ s` and `y ∈ interior s`, then the segment `(x, y]` is included in `interior s`. -/ theorem Convex.add_smul_sub_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • (y - x) ∈ interior s := hs.add_smul_sub_mem_interior' (subset_closure hx) hy ht /-- If `x ∈ closure s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/ theorem Convex.add_smul_mem_interior' {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ closure s) (hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := by simpa only [add_sub_cancel_left] using hs.add_smul_sub_mem_interior' hx hy ht /-- If `x ∈ s` and `x + y ∈ interior s`, then `x + t y ∈ interior s` for `t ∈ (0, 1]`. -/ theorem Convex.add_smul_mem_interior {s : Set E} (hs : Convex 𝕜 s) {x y : E} (hx : x ∈ s) (hy : x + y ∈ interior s) {t : 𝕜} (ht : t ∈ Ioc (0 : 𝕜) 1) : x + t • y ∈ interior s := hs.add_smul_mem_interior' (subset_closure hx) hy ht /-- In a topological vector space, the interior of a convex set is convex. -/ protected theorem Convex.interior {s : Set E} (hs : Convex 𝕜 s) : Convex 𝕜 (interior s) := convex_iff_openSegment_subset.mpr fun _ hx _ hy => hs.openSegment_closure_interior_subset_interior (interior_subset_closure hx) hy /-- In a topological vector space, the closure of a convex set is convex. -/ protected theorem Convex.closure {s : Set E} (hs : Convex 𝕜 s) : Convex 𝕜 (closure s) := fun x hx y hy a b ha hb hab => let f : E → E → E := fun x' y' => a • x' + b • y' have hf : Continuous (Function.uncurry f) := (continuous_fst.const_smul _).add (continuous_snd.const_smul _) show f x y ∈ closure s from map_mem_closure₂ hf hx hy fun _ hx' _ hy' => hs hx' hy' ha hb hab open AffineMap /-- A convex set `s` is strictly convex provided that for any two distinct points of `s \ interior s`, the line passing through these points has nonempty intersection with `interior s`. -/ protected theorem Convex.strictConvex' {s : Set E} (hs : Convex 𝕜 s) (h : (s \ interior s).Pairwise fun x y => ∃ c : 𝕜, lineMap x y c ∈ interior s) : StrictConvex 𝕜 s := by refine strictConvex_iff_openSegment_subset.2 ?_ intro x hx y hy hne by_cases hx' : x ∈ interior s · exact hs.openSegment_interior_self_subset_interior hx' hy by_cases hy' : y ∈ interior s · exact hs.openSegment_self_interior_subset_interior hx hy' rcases h ⟨hx, hx'⟩ ⟨hy, hy'⟩ hne with ⟨c, hc⟩ refine (openSegment_subset_union x y ⟨c, rfl⟩).trans (insert_subset_iff.2 ⟨hc, union_subset ?_ ?_⟩) exacts [hs.openSegment_self_interior_subset_interior hx hc, hs.openSegment_interior_self_subset_interior hc hy] /-- A convex set `s` is strictly convex provided that for any two distinct points `x`, `y` of `s \ interior s`, the segment with endpoints `x`, `y` has nonempty intersection with `interior s`. -/ protected theorem Convex.strictConvex {s : Set E} (hs : Convex 𝕜 s) (h : (s \ interior s).Pairwise fun x y => ([x -[𝕜] y] \ frontier s).Nonempty) : StrictConvex 𝕜 s := by refine hs.strictConvex' <| h.imp_on fun x hx y hy _ => ?_ simp only [segment_eq_image_lineMap, ← self_diff_frontier] rintro ⟨_, ⟨⟨c, hc, rfl⟩, hcs⟩⟩ refine ⟨c, hs.segment_subset hx.1 hy.1 ?_, hcs⟩ exact (segment_eq_image_lineMap 𝕜 x y).symm ▸ mem_image_of_mem _ hc end ContinuousConstSMul section ContinuousSMul variable [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [TopologicalAddGroup E] [ContinuousSMul ℝ E] /-- Convex hull of a finite set is compact. -/ theorem Set.Finite.isCompact_convexHull {s : Set E} (hs : s.Finite) : IsCompact (convexHull ℝ s) := by rw [hs.convexHull_eq_image] apply (@isCompact_stdSimplex _ hs.fintype).image haveI := hs.fintype apply LinearMap.continuous_on_pi /-- Convex hull of a finite set is closed. -/ theorem Set.Finite.isClosed_convexHull [T2Space E] {s : Set E} (hs : s.Finite) : IsClosed (convexHull ℝ s) := hs.isCompact_convexHull.isClosed open AffineMap /-- If we dilate the interior of a convex set about a point in its interior by a scale `t > 1`, the result includes the closure of the original set. TODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/ theorem Convex.closure_subset_image_homothety_interior_of_one_lt {s : Set E} (hs : Convex ℝ s) {x : E} (hx : x ∈ interior s) (t : ℝ) (ht : 1 < t) : closure s ⊆ homothety x t '' interior s := by intro y hy have hne : t ≠ 0 := (one_pos.trans ht).ne' refine ⟨homothety x t⁻¹ y, hs.openSegment_interior_closure_subset_interior hx hy ?_, (AffineEquiv.homothetyUnitsMulHom x (Units.mk0 t hne)).apply_symm_apply y⟩ rw [openSegment_eq_image_lineMap, ← inv_one, ← inv_Ioi (zero_lt_one' ℝ), ← image_inv, image_image, homothety_eq_lineMap] exact mem_image_of_mem _ ht /-- If we dilate a convex set about a point in its interior by a scale `t > 1`, the interior of the result includes the closure of the original set. TODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/ theorem Convex.closure_subset_interior_image_homothety_of_one_lt {s : Set E} (hs : Convex ℝ s) {x : E} (hx : x ∈ interior s) (t : ℝ) (ht : 1 < t) : closure s ⊆ interior (homothety x t '' s) := (hs.closure_subset_image_homothety_interior_of_one_lt hx t ht).trans <| (homothety_isOpenMap x t (one_pos.trans ht).ne').image_interior_subset _ /-- If we dilate a convex set about a point in its interior by a scale `t > 1`, the interior of the result includes the closure of the original set. TODO Generalise this from convex sets to sets that are balanced / star-shaped about `x`. -/ theorem Convex.subset_interior_image_homothety_of_one_lt {s : Set E} (hs : Convex ℝ s) {x : E} (hx : x ∈ interior s) (t : ℝ) (ht : 1 < t) : s ⊆ interior (homothety x t '' s) := subset_closure.trans <| hs.closure_subset_interior_image_homothety_of_one_lt hx t ht theorem JoinedIn.of_segment_subset {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] {x y : E} {s : Set E} (h : [x -[ℝ] y] ⊆ s) : JoinedIn s x y := by have A : Continuous (fun t ↦ (1 - t) • x + t • y : ℝ → E) := by fun_prop apply JoinedIn.ofLine A.continuousOn (by simp) (by simp) convert h rw [segment_eq_image ℝ x y] /-- A nonempty convex set is path connected. -/ protected theorem Convex.isPathConnected {s : Set E} (hconv : Convex ℝ s) (hne : s.Nonempty) : IsPathConnected s := by refine isPathConnected_iff.mpr ⟨hne, ?_⟩ intro x x_in y y_in exact JoinedIn.of_segment_subset ((segment_subset_iff ℝ).2 (hconv x_in y_in)) /-- A nonempty convex set is connected. -/ protected theorem Convex.isConnected {s : Set E} (h : Convex ℝ s) (hne : s.Nonempty) : IsConnected s := (h.isPathConnected hne).isConnected /-- A convex set is preconnected. -/ protected theorem Convex.isPreconnected {s : Set E} (h : Convex ℝ s) : IsPreconnected s := s.eq_empty_or_nonempty.elim (fun h => h.symm ▸ isPreconnected_empty) fun hne => (h.isConnected hne).isPreconnected /-- Every topological vector space over ℝ is path connected. Not an instance, because it creates enormous TC subproblems (turn on `pp.all`). -/ protected theorem TopologicalAddGroup.pathConnectedSpace : PathConnectedSpace E := pathConnectedSpace_iff_univ.mpr <| convex_univ.isPathConnected ⟨(0 : E), trivial⟩ end ContinuousSMul section ComplementsConnected variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [TopologicalAddGroup E] local notation "π" => Submodule.linearProjOfIsCompl _ _ attribute [local instance 100] TopologicalAddGroup.pathConnectedSpace /-- Given two complementary subspaces `p` and `q` in `E`, if the complement of `{0}` is path connected in `p` then the complement of `q` is path connected in `E`. -/ theorem isPathConnected_compl_of_isPathConnected_compl_zero [ContinuousSMul ℝ E] {p q : Submodule ℝ E} (hpq : IsCompl p q) (hpc : IsPathConnected ({0}ᶜ : Set p)) : IsPathConnected (qᶜ : Set E) := by rw [isPathConnected_iff] at hpc ⊢ constructor · rcases hpc.1 with ⟨a, ha⟩ exact ⟨a, mt (Submodule.eq_zero_of_coe_mem_of_disjoint hpq.disjoint) ha⟩ · intro x hx y hy have : π hpq x ≠ 0 ∧ π hpq y ≠ 0 := by constructor <;> intro h <;> rw [Submodule.linearProjOfIsCompl_apply_eq_zero_iff hpq] at h <;> [exact hx h; exact hy h] rcases hpc.2 (π hpq x) this.1 (π hpq y) this.2 with ⟨γ₁, hγ₁⟩ let γ₂ := PathConnectedSpace.somePath (π hpq.symm x) (π hpq.symm y) let γ₁' : Path (_ : E) _ := γ₁.map continuous_subtype_val let γ₂' : Path (_ : E) _ := γ₂.map continuous_subtype_val refine ⟨(γ₁'.add γ₂').cast (Submodule.linear_proj_add_linearProjOfIsCompl_eq_self hpq x).symm (Submodule.linear_proj_add_linearProjOfIsCompl_eq_self hpq y).symm, fun t ↦ ?_⟩ rw [Path.cast_coe, Path.add_apply] change γ₁ t + (γ₂ t : E) ∉ q rw [← Submodule.linearProjOfIsCompl_apply_eq_zero_iff hpq, LinearMap.map_add, Submodule.linearProjOfIsCompl_apply_right, add_zero, Submodule.linearProjOfIsCompl_apply_eq_zero_iff] exact mt (Submodule.eq_zero_of_coe_mem_of_disjoint hpq.disjoint) (hγ₁ t) end ComplementsConnected
Analysis\Convex\Uniform.lean
/- 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.Analysis.Convex.StrictConvexSpace /-! # Uniformly convex spaces This file defines uniformly convex spaces, which are real normed vector spaces in which for all strictly positive `ε`, there exists some strictly positive `δ` such that `ε ≤ ‖x - y‖` implies `‖x + y‖ ≤ 2 - δ` for all `x` and `y` of norm at most than `1`. This means that the triangle inequality is strict with a uniform bound, as opposed to strictly convex spaces where the triangle inequality is strict but not necessarily uniformly (`‖x + y‖ < ‖x‖ + ‖y‖` for all `x` and `y` not in the same ray). ## Main declarations `UniformConvexSpace E` means that `E` is a uniformly convex space. ## TODO * Milman-Pettis * Hanner's inequalities ## Tags convex, uniformly convex -/ open Set Metric open Convex Pointwise /-- A *uniformly convex space* is a real normed space where the triangle inequality is strict with a uniform bound. Namely, over the `x` and `y` of norm `1`, `‖x + y‖` is uniformly bounded above by a constant `< 2` when `‖x - y‖` is uniformly bounded below by a positive constant. -/ class UniformConvexSpace (E : Type*) [SeminormedAddCommGroup E] : Prop where uniform_convex : ∀ ⦃ε : ℝ⦄, 0 < ε → ∃ δ, 0 < δ ∧ ∀ ⦃x : E⦄, ‖x‖ = 1 → ∀ ⦃y⦄, ‖y‖ = 1 → ε ≤ ‖x - y‖ → ‖x + y‖ ≤ 2 - δ variable {E : Type*} section SeminormedAddCommGroup variable (E) [SeminormedAddCommGroup E] [UniformConvexSpace E] {ε : ℝ} theorem exists_forall_sphere_dist_add_le_two_sub (hε : 0 < ε) : ∃ δ, 0 < δ ∧ ∀ ⦃x : E⦄, ‖x‖ = 1 → ∀ ⦃y⦄, ‖y‖ = 1 → ε ≤ ‖x - y‖ → ‖x + y‖ ≤ 2 - δ := UniformConvexSpace.uniform_convex hε variable [NormedSpace ℝ E] theorem exists_forall_closed_ball_dist_add_le_two_sub (hε : 0 < ε) : ∃ δ, 0 < δ ∧ ∀ ⦃x : E⦄, ‖x‖ ≤ 1 → ∀ ⦃y⦄, ‖y‖ ≤ 1 → ε ≤ ‖x - y‖ → ‖x + y‖ ≤ 2 - δ := by have hε' : 0 < ε / 3 := div_pos hε zero_lt_three obtain ⟨δ, hδ, h⟩ := exists_forall_sphere_dist_add_le_two_sub E hε' set δ' := min (1 / 2) (min (ε / 3) <| δ / 3) refine ⟨δ', lt_min one_half_pos <| lt_min hε' (div_pos hδ zero_lt_three), fun x hx y hy hxy => ?_⟩ obtain hx' | hx' := le_or_lt ‖x‖ (1 - δ') · rw [← one_add_one_eq_two] exact (norm_add_le_of_le hx' hy).trans (sub_add_eq_add_sub _ _ _).le obtain hy' | hy' := le_or_lt ‖y‖ (1 - δ') · rw [← one_add_one_eq_two] exact (norm_add_le_of_le hx hy').trans (add_sub_assoc _ _ _).ge have hδ' : 0 < 1 - δ' := sub_pos_of_lt (min_lt_of_left_lt one_half_lt_one) have h₁ : ∀ z : E, 1 - δ' < ‖z‖ → ‖‖z‖⁻¹ • z‖ = 1 := by rintro z hz rw [norm_smul_of_nonneg (inv_nonneg.2 <| norm_nonneg _), inv_mul_cancel (hδ'.trans hz).ne'] have h₂ : ∀ z : E, ‖z‖ ≤ 1 → 1 - δ' ≤ ‖z‖ → ‖‖z‖⁻¹ • z - z‖ ≤ δ' := by rintro z hz hδz nth_rw 3 [← one_smul ℝ z] rwa [← sub_smul, norm_smul_of_nonneg (sub_nonneg_of_le <| one_le_inv (hδ'.trans_le hδz) hz), sub_mul, inv_mul_cancel (hδ'.trans_le hδz).ne', one_mul, sub_le_comm] set x' := ‖x‖⁻¹ • x set y' := ‖y‖⁻¹ • y have hxy' : ε / 3 ≤ ‖x' - y'‖ := calc ε / 3 = ε - (ε / 3 + ε / 3) := by ring _ ≤ ‖x - y‖ - (‖x' - x‖ + ‖y' - y‖) := by gcongr · exact (h₂ _ hx hx'.le).trans <| min_le_of_right_le <| min_le_left _ _ · exact (h₂ _ hy hy'.le).trans <| min_le_of_right_le <| min_le_left _ _ _ ≤ _ := by have : ∀ x' y', x - y = x' - y' + (x - x') + (y' - y) := fun _ _ => by abel rw [sub_le_iff_le_add, norm_sub_rev _ x, ← add_assoc, this] exact norm_add₃_le _ _ _ calc ‖x + y‖ ≤ ‖x' + y'‖ + ‖x' - x‖ + ‖y' - y‖ := by have : ∀ x' y', x + y = x' + y' + (x - x') + (y - y') := fun _ _ => by abel rw [norm_sub_rev, norm_sub_rev y', this] exact norm_add₃_le _ _ _ _ ≤ 2 - δ + δ' + δ' := (add_le_add_three (h (h₁ _ hx') (h₁ _ hy') hxy') (h₂ _ hx hx'.le) (h₂ _ hy hy'.le)) _ ≤ 2 - δ' := by dsimp only [δ'] rw [← le_sub_iff_add_le, ← le_sub_iff_add_le, sub_sub, sub_sub] refine sub_le_sub_left ?_ _ ring_nf rw [← mul_div_cancel₀ δ three_ne_zero] norm_num -- Porting note: these three extra lines needed to make `exact` work have : 3 * (δ / 3) * (1 / 3) = δ / 3 := by linarith rw [this, mul_comm] gcongr exact min_le_of_right_le <| min_le_right _ _ theorem exists_forall_closed_ball_dist_add_le_two_mul_sub (hε : 0 < ε) (r : ℝ) : ∃ δ, 0 < δ ∧ ∀ ⦃x : E⦄, ‖x‖ ≤ r → ∀ ⦃y⦄, ‖y‖ ≤ r → ε ≤ ‖x - y‖ → ‖x + y‖ ≤ 2 * r - δ := by obtain hr | hr := le_or_lt r 0 · exact ⟨1, one_pos, fun x hx y hy h => (hε.not_le <| h.trans <| (norm_sub_le _ _).trans <| add_nonpos (hx.trans hr) (hy.trans hr)).elim⟩ obtain ⟨δ, hδ, h⟩ := exists_forall_closed_ball_dist_add_le_two_sub E (div_pos hε hr) refine ⟨δ * r, mul_pos hδ hr, fun x hx y hy hxy => ?_⟩ rw [← div_le_one hr, div_eq_inv_mul, ← norm_smul_of_nonneg (inv_nonneg.2 hr.le)] at hx hy have := h hx hy simp_rw [← smul_add, ← smul_sub, norm_smul_of_nonneg (inv_nonneg.2 hr.le), ← div_eq_inv_mul, div_le_div_right hr, div_le_iff hr, sub_mul] at this exact this hxy end SeminormedAddCommGroup variable [NormedAddCommGroup E] [NormedSpace ℝ E] [UniformConvexSpace E] -- See note [lower instance priority] instance (priority := 100) UniformConvexSpace.toStrictConvexSpace : StrictConvexSpace ℝ E := StrictConvexSpace.of_norm_add_ne_two fun _ _ hx hy hxy => let ⟨_, hδ, h⟩ := exists_forall_closed_ball_dist_add_le_two_sub E (norm_sub_pos_iff.2 hxy) ((h hx.le hy.le le_rfl).trans_lt <| sub_lt_self _ hδ).ne
Analysis\Convex\Cone\Basic.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis -/ import Mathlib.Analysis.Convex.Hull /-! # Convex cones In a `𝕜`-module `E`, we define a convex cone as a set `s` such that `a • x + b • y ∈ s` whenever `x, y ∈ s` and `a, b > 0`. We prove that convex cones form a `CompleteLattice`, and define their images (`ConvexCone.map`) and preimages (`ConvexCone.comap`) under linear maps. We define pointed, blunt, flat and salient cones, and prove the correspondence between convex cones and ordered modules. We define `Convex.toCone` to be the minimal cone that includes a given convex set. ## Main statements In `Mathlib/Analysis/Convex/Cone/Extension.lean` we prove the M. Riesz extension theorem and a form of the Hahn-Banach theorem. In `Mathlib/Analysis/Convex/Cone/Dual.lean` we prove a variant of the hyperplane separation theorem. ## Implementation notes While `Convex 𝕜` is a predicate on sets, `ConvexCone 𝕜 E` is a bundled convex cone. ## References * https://en.wikipedia.org/wiki/Convex_cone * [Stephen P. Boyd and Lieven Vandenberghe, *Convex Optimization*][boydVandenberghe2004] * [Emo Welzl and Bernd Gärtner, *Cone Programming*][welzl_garter] -/ assert_not_exists NormedSpace assert_not_exists Real open Set LinearMap open scoped Classical open Pointwise variable {𝕜 E F G : Type*} /-! ### Definition of `ConvexCone` and basic properties -/ section Definitions variable (𝕜 E) variable [OrderedSemiring 𝕜] /-- A convex cone is a subset `s` of a `𝕜`-module such that `a • x + b • y ∈ s` whenever `a, b > 0` and `x, y ∈ s`. -/ structure ConvexCone [AddCommMonoid E] [SMul 𝕜 E] where /-- The **carrier set** underlying this cone: the set of points contained in it -/ carrier : Set E smul_mem' : ∀ ⦃c : 𝕜⦄, 0 < c → ∀ ⦃x : E⦄, x ∈ carrier → c • x ∈ carrier add_mem' : ∀ ⦃x⦄ (_ : x ∈ carrier) ⦃y⦄ (_ : y ∈ carrier), x + y ∈ carrier end Definitions namespace ConvexCone section OrderedSemiring variable [OrderedSemiring 𝕜] [AddCommMonoid E] section SMul variable [SMul 𝕜 E] (S T : ConvexCone 𝕜 E) instance : SetLike (ConvexCone 𝕜 E) E where coe := carrier coe_injective' S T h := by cases S; cases T; congr @[simp] theorem coe_mk {s : Set E} {h₁ h₂} : ↑(@mk 𝕜 _ _ _ _ s h₁ h₂) = s := rfl @[simp] theorem mem_mk {s : Set E} {h₁ h₂ x} : x ∈ @mk 𝕜 _ _ _ _ s h₁ h₂ ↔ x ∈ s := Iff.rfl /-- Two `ConvexCone`s are equal if they have the same elements. -/ @[ext] theorem ext {S T : ConvexCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[aesop safe apply (rule_sets := [SetLike])] theorem smul_mem {c : 𝕜} {x : E} (hc : 0 < c) (hx : x ∈ S) : c • x ∈ S := S.smul_mem' hc hx theorem add_mem ⦃x⦄ (hx : x ∈ S) ⦃y⦄ (hy : y ∈ S) : x + y ∈ S := S.add_mem' hx hy instance : AddMemClass (ConvexCone 𝕜 E) E where add_mem ha hb := add_mem _ ha hb instance : Inf (ConvexCone 𝕜 E) := ⟨fun S T => ⟨S ∩ T, fun _ hc _ hx => ⟨S.smul_mem hc hx.1, T.smul_mem hc hx.2⟩, fun _ hx _ hy => ⟨S.add_mem hx.1 hy.1, T.add_mem hx.2 hy.2⟩⟩⟩ @[simp] theorem coe_inf : ((S ⊓ T : ConvexCone 𝕜 E) : Set E) = ↑S ∩ ↑T := rfl theorem mem_inf {x} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl instance : InfSet (ConvexCone 𝕜 E) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, fun _ hc _ hx => mem_biInter fun s hs => s.smul_mem hc <| mem_iInter₂.1 hx s hs, fun _ hx _ hy => mem_biInter fun s hs => s.add_mem (mem_iInter₂.1 hx s hs) (mem_iInter₂.1 hy s hs)⟩⟩ @[simp] theorem coe_sInf (S : Set (ConvexCone 𝕜 E)) : ↑(sInf S) = ⋂ s ∈ S, (s : Set E) := rfl theorem mem_sInf {x : E} {S : Set (ConvexCone 𝕜 E)} : x ∈ sInf S ↔ ∀ s ∈ S, x ∈ s := mem_iInter₂ @[simp] theorem coe_iInf {ι : Sort*} (f : ι → ConvexCone 𝕜 E) : ↑(iInf f) = ⋂ i, (f i : Set E) := by simp [iInf] theorem mem_iInf {ι : Sort*} {x : E} {f : ι → ConvexCone 𝕜 E} : x ∈ iInf f ↔ ∀ i, x ∈ f i := mem_iInter₂.trans <| by simp variable (𝕜) instance : Bot (ConvexCone 𝕜 E) := ⟨⟨∅, fun _ _ _ => False.elim, fun _ => False.elim⟩⟩ theorem mem_bot (x : E) : (x ∈ (⊥ : ConvexCone 𝕜 E)) = False := rfl @[simp] theorem coe_bot : ↑(⊥ : ConvexCone 𝕜 E) = (∅ : Set E) := rfl instance : Top (ConvexCone 𝕜 E) := ⟨⟨univ, fun _ _ _ _ => mem_univ _, fun _ _ _ _ => mem_univ _⟩⟩ theorem mem_top (x : E) : x ∈ (⊤ : ConvexCone 𝕜 E) := mem_univ x @[simp] theorem coe_top : ↑(⊤ : ConvexCone 𝕜 E) = (univ : Set E) := rfl instance : CompleteLattice (ConvexCone 𝕜 E) := { SetLike.instPartialOrder with le := (· ≤ ·) lt := (· < ·) bot := ⊥ bot_le := fun _ _ => False.elim top := ⊤ le_top := fun _ x _ => mem_top 𝕜 x inf := (· ⊓ ·) sInf := InfSet.sInf sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } sSup := fun s => sInf { T | ∀ S ∈ s, S ≤ T } le_sup_left := fun _ _ => fun _ hx => mem_sInf.2 fun _ hs => hs.1 hx le_sup_right := fun _ _ => fun _ hx => mem_sInf.2 fun _ hs => hs.2 hx sup_le := fun _ _ c ha hb _ hx => mem_sInf.1 hx c ⟨ha, hb⟩ le_inf := fun _ _ _ ha hb _ hx => ⟨ha hx, hb hx⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_sSup := fun _ p hs _ hx => mem_sInf.2 fun _ ht => ht p hs hx sSup_le := fun _ p hs _ hx => mem_sInf.1 hx p hs le_sInf := fun _ _ ha _ hx => mem_sInf.2 fun t ht => ha t ht hx sInf_le := fun _ _ ha _ hx => mem_sInf.1 hx _ ha } instance : Inhabited (ConvexCone 𝕜 E) := ⟨⊥⟩ end SMul section Module variable [Module 𝕜 E] (S : ConvexCone 𝕜 E) protected theorem convex : Convex 𝕜 (S : Set E) := convex_iff_forall_pos.2 fun _ hx _ hy _ _ ha hb _ => S.add_mem (S.smul_mem ha hx) (S.smul_mem hb hy) end Module section Maps variable [AddCommMonoid F] [AddCommMonoid G] variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G] /-- The image of a convex cone under a `𝕜`-linear map is a convex cone. -/ def map (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 E) : ConvexCone 𝕜 F where carrier := f '' S smul_mem' := fun c hc _ ⟨x, hx, hy⟩ => hy ▸ f.map_smul c x ▸ mem_image_of_mem f (S.smul_mem hc hx) add_mem' := fun _ ⟨x₁, hx₁, hy₁⟩ _ ⟨x₂, hx₂, hy₂⟩ => hy₁ ▸ hy₂ ▸ f.map_add x₁ x₂ ▸ mem_image_of_mem f (S.add_mem hx₁ hx₂) @[simp, norm_cast] theorem coe_map (S : ConvexCone 𝕜 E) (f : E →ₗ[𝕜] F) : (S.map f : Set F) = f '' S := rfl @[simp] theorem mem_map {f : E →ₗ[𝕜] F} {S : ConvexCone 𝕜 E} {y : F} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Set.mem_image f S y theorem map_map (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 E) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| image_image g f S @[simp] theorem map_id (S : ConvexCone 𝕜 E) : S.map LinearMap.id = S := SetLike.coe_injective <| image_id _ /-- The preimage of a convex cone under a `𝕜`-linear map is a convex cone. -/ def comap (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 F) : ConvexCone 𝕜 E where carrier := f ⁻¹' S smul_mem' c hc x hx := by rw [mem_preimage, f.map_smul c] exact S.smul_mem hc hx add_mem' x hx y hy := by rw [mem_preimage, f.map_add] exact S.add_mem hx hy @[simp] theorem coe_comap (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 F) : (S.comap f : Set E) = f ⁻¹' S := rfl @[simp] -- Porting note: was not a `dsimp` lemma theorem comap_id (S : ConvexCone 𝕜 E) : S.comap LinearMap.id = S := rfl theorem comap_comap (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : ConvexCone 𝕜 G) : (S.comap g).comap f = S.comap (g.comp f) := rfl @[simp] theorem mem_comap {f : E →ₗ[𝕜] F} {S : ConvexCone 𝕜 F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl end Maps end OrderedSemiring section LinearOrderedField variable [LinearOrderedField 𝕜] section MulAction variable [AddCommMonoid E] variable [MulAction 𝕜 E] (S : ConvexCone 𝕜 E) theorem smul_mem_iff {c : 𝕜} (hc : 0 < c) {x : E} : c • x ∈ S ↔ x ∈ S := ⟨fun h => inv_smul_smul₀ hc.ne' x ▸ S.smul_mem (inv_pos.2 hc) h, S.smul_mem hc⟩ end MulAction section OrderedAddCommGroup variable [OrderedAddCommGroup E] [Module 𝕜 E] /-- Constructs an ordered module given an `OrderedAddCommGroup`, a cone, and a proof that the order relation is the one defined by the cone. -/ theorem to_orderedSMul (S : ConvexCone 𝕜 E) (h : ∀ x y : E, x ≤ y ↔ y - x ∈ S) : OrderedSMul 𝕜 E := OrderedSMul.mk' (by intro x y z xy hz rw [h (z • x) (z • y), ← smul_sub z y x] exact smul_mem S hz ((h x y).mp xy.le)) end OrderedAddCommGroup end LinearOrderedField /-! ### Convex cones with extra properties -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [SMul 𝕜 E] (S : ConvexCone 𝕜 E) /-- A convex cone is pointed if it includes `0`. -/ def Pointed (S : ConvexCone 𝕜 E) : Prop := (0 : E) ∈ S /-- A convex cone is blunt if it doesn't include `0`. -/ def Blunt (S : ConvexCone 𝕜 E) : Prop := (0 : E) ∉ S theorem pointed_iff_not_blunt (S : ConvexCone 𝕜 E) : S.Pointed ↔ ¬S.Blunt := ⟨fun h₁ h₂ => h₂ h₁, Classical.not_not.mp⟩ theorem blunt_iff_not_pointed (S : ConvexCone 𝕜 E) : S.Blunt ↔ ¬S.Pointed := by rw [pointed_iff_not_blunt, Classical.not_not] theorem Pointed.mono {S T : ConvexCone 𝕜 E} (h : S ≤ T) : S.Pointed → T.Pointed := @h _ theorem Blunt.anti {S T : ConvexCone 𝕜 E} (h : T ≤ S) : S.Blunt → T.Blunt := (· ∘ @h 0) end AddCommMonoid section AddCommGroup variable [AddCommGroup E] [SMul 𝕜 E] (S : ConvexCone 𝕜 E) /-- A convex cone is flat if it contains some nonzero vector `x` and its opposite `-x`. -/ def Flat : Prop := ∃ x ∈ S, x ≠ (0 : E) ∧ -x ∈ S /-- A convex cone is salient if it doesn't include `x` and `-x` for any nonzero `x`. -/ def Salient : Prop := ∀ x ∈ S, x ≠ (0 : E) → -x ∉ S theorem salient_iff_not_flat (S : ConvexCone 𝕜 E) : S.Salient ↔ ¬S.Flat := by simp [Salient, Flat] theorem Flat.mono {S T : ConvexCone 𝕜 E} (h : S ≤ T) : S.Flat → T.Flat | ⟨x, hxS, hx, hnxS⟩ => ⟨x, h hxS, hx, h hnxS⟩ theorem Salient.anti {S T : ConvexCone 𝕜 E} (h : T ≤ S) : S.Salient → T.Salient := fun hS x hxT hx hnT => hS x (h hxT) hx (h hnT) /-- A flat cone is always pointed (contains `0`). -/ theorem Flat.pointed {S : ConvexCone 𝕜 E} (hS : S.Flat) : S.Pointed := by obtain ⟨x, hx, _, hxneg⟩ := hS rw [Pointed, ← add_neg_self x] exact add_mem S hx hxneg /-- A blunt cone (one not containing `0`) is always salient. -/ theorem Blunt.salient {S : ConvexCone 𝕜 E} : S.Blunt → S.Salient := by rw [salient_iff_not_flat, blunt_iff_not_pointed] exact mt Flat.pointed /-- A pointed convex cone defines a preorder. -/ def toPreorder (h₁ : S.Pointed) : Preorder E where le x y := y - x ∈ S le_refl x := by change x - x ∈ S; rw [sub_self x]; exact h₁ le_trans x y z xy zy := by simpa using add_mem S zy xy /-- A pointed and salient cone defines a partial order. -/ def toPartialOrder (h₁ : S.Pointed) (h₂ : S.Salient) : PartialOrder E := { toPreorder S h₁ with le_antisymm := by intro a b ab ba by_contra h have h' : b - a ≠ 0 := fun h'' => h (eq_of_sub_eq_zero h'').symm have H := h₂ (b - a) ab h' rw [neg_sub b a] at H exact H ba } /-- A pointed and salient cone defines an `OrderedAddCommGroup`. -/ def toOrderedAddCommGroup (h₁ : S.Pointed) (h₂ : S.Salient) : OrderedAddCommGroup E := { toPartialOrder S h₁ h₂, show AddCommGroup E by infer_instance with add_le_add_left := by intro a b hab c change c + b - (c + a) ∈ S rw [add_sub_add_left_eq_sub] exact hab } end AddCommGroup section Module variable [AddCommMonoid E] [Module 𝕜 E] instance : Zero (ConvexCone 𝕜 E) := ⟨⟨0, fun _ _ => by simp, fun _ => by simp⟩⟩ @[simp] theorem mem_zero (x : E) : x ∈ (0 : ConvexCone 𝕜 E) ↔ x = 0 := Iff.rfl @[simp] theorem coe_zero : ((0 : ConvexCone 𝕜 E) : Set E) = 0 := rfl theorem pointed_zero : (0 : ConvexCone 𝕜 E).Pointed := by rw [Pointed, mem_zero] instance instAdd : Add (ConvexCone 𝕜 E) := ⟨fun K₁ K₂ => { carrier := { z | ∃ x ∈ K₁, ∃ y ∈ K₂, x + y = z } smul_mem' := by rintro c hc _ ⟨x, hx, y, hy, rfl⟩ rw [smul_add] use c • x, K₁.smul_mem hc hx, c • y, K₂.smul_mem hc hy add_mem' := by rintro _ ⟨x₁, hx₁, x₂, hx₂, rfl⟩ y ⟨y₁, hy₁, y₂, hy₂, rfl⟩ use x₁ + y₁, K₁.add_mem hx₁ hy₁, x₂ + y₂, K₂.add_mem hx₂ hy₂ abel }⟩ @[simp] theorem mem_add {K₁ K₂ : ConvexCone 𝕜 E} {a : E} : a ∈ K₁ + K₂ ↔ ∃ x ∈ K₁, ∃ y ∈ K₂, x + y = a := Iff.rfl instance instAddZeroClass : AddZeroClass (ConvexCone 𝕜 E) where zero_add _ := by ext; simp add_zero _ := by ext; simp instance instAddCommSemigroup : AddCommSemigroup (ConvexCone 𝕜 E) where add := Add.add add_assoc _ _ _ := SetLike.coe_injective <| add_assoc _ _ _ add_comm _ _ := SetLike.coe_injective <| add_comm _ _ end Module end OrderedSemiring end ConvexCone namespace Submodule /-! ### Submodules are cones -/ section OrderedSemiring variable [OrderedSemiring 𝕜] section AddCommMonoid variable [AddCommMonoid E] [Module 𝕜 E] /-- Every submodule is trivially a convex cone. -/ def toConvexCone (S : Submodule 𝕜 E) : ConvexCone 𝕜 E where carrier := S smul_mem' c _ _ hx := S.smul_mem c hx add_mem' _ hx _ hy := S.add_mem hx hy @[simp] theorem coe_toConvexCone (S : Submodule 𝕜 E) : ↑S.toConvexCone = (S : Set E) := rfl @[simp] theorem mem_toConvexCone {x : E} {S : Submodule 𝕜 E} : x ∈ S.toConvexCone ↔ x ∈ S := Iff.rfl @[simp] theorem toConvexCone_le_iff {S T : Submodule 𝕜 E} : S.toConvexCone ≤ T.toConvexCone ↔ S ≤ T := Iff.rfl @[simp] theorem toConvexCone_bot : (⊥ : Submodule 𝕜 E).toConvexCone = 0 := rfl @[simp] theorem toConvexCone_top : (⊤ : Submodule 𝕜 E).toConvexCone = ⊤ := rfl @[simp] theorem toConvexCone_inf (S T : Submodule 𝕜 E) : (S ⊓ T).toConvexCone = S.toConvexCone ⊓ T.toConvexCone := rfl @[simp] theorem pointed_toConvexCone (S : Submodule 𝕜 E) : S.toConvexCone.Pointed := S.zero_mem end AddCommMonoid end OrderedSemiring end Submodule namespace ConvexCone /-! ### Positive cone of an ordered module -/ section PositiveCone variable (𝕜 E) [OrderedSemiring 𝕜] [OrderedAddCommGroup E] [Module 𝕜 E] [OrderedSMul 𝕜 E] /-- The positive cone is the convex cone formed by the set of nonnegative elements in an ordered module. -/ def positive : ConvexCone 𝕜 E where carrier := Set.Ici 0 smul_mem' _ hc _ (hx : _ ≤ _) := smul_nonneg hc.le hx add_mem' _ (hx : _ ≤ _) _ (hy : _ ≤ _) := add_nonneg hx hy @[simp] theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := Iff.rfl @[simp] theorem coe_positive : ↑(positive 𝕜 E) = Set.Ici (0 : E) := rfl /-- The positive cone of an ordered module is always salient. -/ theorem salient_positive : Salient (positive 𝕜 E) := fun x xs hx hx' => lt_irrefl (0 : E) (calc 0 < x := lt_of_le_of_ne xs hx.symm _ ≤ x + -x := le_add_of_nonneg_right hx' _ = 0 := add_neg_self x ) /-- The positive cone of an ordered module is always pointed. -/ theorem pointed_positive : Pointed (positive 𝕜 E) := le_refl 0 /-- The cone of strictly positive elements. Note that this naming diverges from the mathlib convention of `pos` and `nonneg` due to "positive cone" (`ConvexCone.positive`) being established terminology for the non-negative elements. -/ def strictlyPositive : ConvexCone 𝕜 E where carrier := Set.Ioi 0 smul_mem' _ hc _ (hx : _ < _) := smul_pos hc hx add_mem' _ hx _ hy := add_pos hx hy @[simp] theorem mem_strictlyPositive {x : E} : x ∈ strictlyPositive 𝕜 E ↔ 0 < x := Iff.rfl @[simp] theorem coe_strictlyPositive : ↑(strictlyPositive 𝕜 E) = Set.Ioi (0 : E) := rfl theorem positive_le_strictlyPositive : strictlyPositive 𝕜 E ≤ positive 𝕜 E := fun _ => le_of_lt /-- The strictly positive cone of an ordered module is always salient. -/ theorem salient_strictlyPositive : Salient (strictlyPositive 𝕜 E) := (salient_positive 𝕜 E).anti <| positive_le_strictlyPositive 𝕜 E /-- The strictly positive cone of an ordered module is always blunt. -/ theorem blunt_strictlyPositive : Blunt (strictlyPositive 𝕜 E) := lt_irrefl 0 end PositiveCone end ConvexCone /-! ### Cone over a convex set -/ section ConeFromConvex variable [LinearOrderedField 𝕜] [AddCommGroup E] [Module 𝕜 E] namespace Convex /-- The set of vectors proportional to those in a convex set forms a convex cone. -/ def toCone (s : Set E) (hs : Convex 𝕜 s) : ConvexCone 𝕜 E := by apply ConvexCone.mk (⋃ (c : 𝕜) (_ : 0 < c), c • s) <;> simp only [mem_iUnion, mem_smul_set] · rintro c c_pos _ ⟨c', c'_pos, x, hx, rfl⟩ exact ⟨c * c', mul_pos c_pos c'_pos, x, hx, (smul_smul _ _ _).symm⟩ · rintro _ ⟨cx, cx_pos, x, hx, rfl⟩ _ ⟨cy, cy_pos, y, hy, rfl⟩ have : 0 < cx + cy := add_pos cx_pos cy_pos refine ⟨_, this, _, convex_iff_div.1 hs hx hy cx_pos.le cy_pos.le this, ?_⟩ simp only [smul_add, smul_smul, mul_div_assoc', mul_div_cancel_left₀ _ this.ne'] variable {s : Set E} (hs : Convex 𝕜 s) {x : E} theorem mem_toCone : x ∈ hs.toCone s ↔ ∃ c : 𝕜, 0 < c ∧ ∃ y ∈ s, c • y = x := by simp only [toCone, ConvexCone.mem_mk, mem_iUnion, mem_smul_set, eq_comm, exists_prop] theorem mem_toCone' : x ∈ hs.toCone s ↔ ∃ c : 𝕜, 0 < c ∧ c • x ∈ s := by refine hs.mem_toCone.trans ⟨?_, ?_⟩ · rintro ⟨c, hc, y, hy, rfl⟩ exact ⟨c⁻¹, inv_pos.2 hc, by rwa [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ · rintro ⟨c, hc, hcx⟩ exact ⟨c⁻¹, inv_pos.2 hc, _, hcx, by rw [smul_smul, inv_mul_cancel hc.ne', one_smul]⟩ theorem subset_toCone : s ⊆ hs.toCone s := fun x hx => hs.mem_toCone'.2 ⟨1, zero_lt_one, by rwa [one_smul]⟩ /-- `hs.toCone s` is the least cone that includes `s`. -/ theorem toCone_isLeast : IsLeast { t : ConvexCone 𝕜 E | s ⊆ t } (hs.toCone s) := by refine ⟨hs.subset_toCone, fun t ht x hx => ?_⟩ rcases hs.mem_toCone.1 hx with ⟨c, hc, y, hy, rfl⟩ exact t.smul_mem hc (ht hy) theorem toCone_eq_sInf : hs.toCone s = sInf { t : ConvexCone 𝕜 E | s ⊆ t } := hs.toCone_isLeast.isGLB.sInf_eq.symm end Convex theorem convexHull_toCone_isLeast (s : Set E) : IsLeast { t : ConvexCone 𝕜 E | s ⊆ t } ((convex_convexHull 𝕜 s).toCone _) := by convert (convex_convexHull 𝕜 s).toCone_isLeast using 1 ext t exact ⟨fun h => convexHull_min h t.convex, (subset_convexHull 𝕜 s).trans⟩ theorem convexHull_toCone_eq_sInf (s : Set E) : (convex_convexHull 𝕜 s).toCone _ = sInf { t : ConvexCone 𝕜 E | s ⊆ t } := Eq.symm <| IsGLB.sInf_eq <| IsLeast.isGLB <| convexHull_toCone_isLeast s end ConeFromConvex
Analysis\Convex\Cone\Closure.lean
/- Copyright (c) 2023 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import Mathlib.Analysis.Convex.Cone.Pointed /-! # Closure of cones We define the closures of convex and pointed cones. This construction is primarily needed for defining maps between proper cones. The current API is basic and should be extended as necessary. -/ namespace ConvexCone variable {𝕜 : Type*} [OrderedSemiring 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [ContinuousAdd E] [SMul 𝕜 E] [ContinuousConstSMul 𝕜 E] /-- The closure of a convex cone inside a topological space as a convex cone. This construction is mainly used for defining maps between proper cones. -/ protected def closure (K : ConvexCone 𝕜 E) : ConvexCone 𝕜 E where carrier := closure ↑K smul_mem' c hc _ h₁ := map_mem_closure (continuous_id'.const_smul c) h₁ fun _ h₂ => K.smul_mem hc h₂ add_mem' _ h₁ _ h₂ := map_mem_closure₂ continuous_add h₁ h₂ K.add_mem @[simp, norm_cast] theorem coe_closure (K : ConvexCone 𝕜 E) : (K.closure : Set E) = closure K := rfl @[simp] protected theorem mem_closure {K : ConvexCone 𝕜 E} {a : E} : a ∈ K.closure ↔ a ∈ closure (K : Set E) := Iff.rfl @[simp] theorem closure_eq {K L : ConvexCone 𝕜 E} : K.closure = L ↔ closure (K : Set E) = L := SetLike.ext'_iff end ConvexCone namespace PointedCone variable {𝕜 : Type*} [OrderedSemiring 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [ContinuousAdd E] [Module 𝕜 E] [ContinuousConstSMul 𝕜 E] lemma toConvexCone_closure_pointed (K : PointedCone 𝕜 E) : (K : ConvexCone 𝕜 E).closure.Pointed := subset_closure $ PointedCone.toConvexCone_pointed _ /-- The closure of a pointed cone inside a topological space as a pointed cone. This construction is mainly used for defining maps between proper cones. -/ protected def closure (K : PointedCone 𝕜 E) : PointedCone 𝕜 E := ConvexCone.toPointedCone K.toConvexCone_closure_pointed @[simp, norm_cast] theorem coe_closure (K : PointedCone 𝕜 E) : (K.closure : Set E) = closure K := rfl @[simp] protected theorem mem_closure {K : PointedCone 𝕜 E} {a : E} : a ∈ K.closure ↔ a ∈ closure (K : Set E) := Iff.rfl @[simp] theorem closure_eq {K L : PointedCone 𝕜 E} : K.closure = L ↔ closure (K : Set E) = L := SetLike.ext'_iff end PointedCone
Analysis\Convex\Cone\Extension.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Frédéric Dupuis -/ import Mathlib.Analysis.Convex.Cone.Basic import Mathlib.Data.Real.Archimedean import Mathlib.LinearAlgebra.LinearPMap /-! # Extension theorems We prove two extension theorems: * `riesz_extension`: [M. Riesz extension theorem](https://en.wikipedia.org/wiki/M._Riesz_extension_theorem) says that if `s` is a convex cone in a real vector space `E`, `p` is a submodule of `E` such that `p + s = E`, and `f` is a linear function `p → ℝ` which is nonnegative on `p ∩ s`, then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. * `exists_extension_of_le_sublinear`: Hahn-Banach theorem: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x` -/ open Set LinearMap variable {𝕜 E F G : Type*} /-! ### M. Riesz extension theorem Given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. We prove this theorem using Zorn's lemma. `RieszExtension.step` is the main part of the proof. It says that if the domain `p` of `f` is not the whole space, then `f` can be extended to a larger subspace `p ⊔ span ℝ {y}` without breaking the non-negativity condition. In `RieszExtension.exists_top` we use Zorn's lemma to prove that we can extend `f` to a linear map `g` on `⊤ : Submodule E`. Mathematically this is the same as a linear map on `E` but in Lean `⊤ : Submodule E` is isomorphic but is not equal to `E`. In `riesz_extension` we use this isomorphism to prove the theorem. -/ variable [AddCommGroup E] [Module ℝ E] namespace RieszExtension open Submodule variable (s : ConvexCone ℝ E) (f : E →ₗ.[ℝ] ℝ) /-- Induction step in M. Riesz extension theorem. Given a convex cone `s` in a vector space `E`, a partially defined linear map `f : f.domain → ℝ`, assume that `f` is nonnegative on `f.domain ∩ p` and `p + s = E`. If `f` is not defined on the whole `E`, then we can extend it to a larger submodule without breaking the non-negativity condition. -/ theorem step (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) (hdom : f.domain ≠ ⊤) : ∃ g, f < g ∧ ∀ x : g.domain, (x : E) ∈ s → 0 ≤ g x := by obtain ⟨y, -, hy⟩ : ∃ y ∈ ⊤, y ∉ f.domain := SetLike.exists_of_lt (lt_top_iff_ne_top.2 hdom) obtain ⟨c, le_c, c_le⟩ : ∃ c, (∀ x : f.domain, -(x : E) - y ∈ s → f x ≤ c) ∧ ∀ x : f.domain, (x : E) + y ∈ s → c ≤ f x := by set Sp := f '' { x : f.domain | (x : E) + y ∈ s } set Sn := f '' { x : f.domain | -(x : E) - y ∈ s } suffices (upperBounds Sn ∩ lowerBounds Sp).Nonempty by simpa only [Set.Nonempty, upperBounds, lowerBounds, forall_mem_image] using this refine exists_between_of_forall_le (Nonempty.image f ?_) (Nonempty.image f (dense y)) ?_ · rcases dense (-y) with ⟨x, hx⟩ rw [← neg_neg x, NegMemClass.coe_neg, ← sub_eq_add_neg] at hx exact ⟨_, hx⟩ rintro a ⟨xn, hxn, rfl⟩ b ⟨xp, hxp, rfl⟩ have := s.add_mem hxp hxn rw [add_assoc, add_sub_cancel, ← sub_eq_add_neg, ← AddSubgroupClass.coe_sub] at this replace := nonneg _ this rwa [f.map_sub, sub_nonneg] at this -- Porting note: removed an unused `have` refine ⟨f.supSpanSingleton y (-c) hy, ?_, ?_⟩ · refine lt_iff_le_not_le.2 ⟨f.left_le_sup _ _, fun H => ?_⟩ replace H := LinearPMap.domain_mono.monotone H rw [LinearPMap.domain_supSpanSingleton, sup_le_iff, span_le, singleton_subset_iff] at H exact hy H.2 · rintro ⟨z, hz⟩ hzs rcases mem_sup.1 hz with ⟨x, hx, y', hy', rfl⟩ rcases mem_span_singleton.1 hy' with ⟨r, rfl⟩ simp only [Subtype.coe_mk] at hzs erw [LinearPMap.supSpanSingleton_apply_mk _ _ _ _ _ hx, smul_neg, ← sub_eq_add_neg, sub_nonneg] rcases lt_trichotomy r 0 with (hr | hr | hr) · have : -(r⁻¹ • x) - y ∈ s := by rwa [← s.smul_mem_iff (neg_pos.2 hr), smul_sub, smul_neg, neg_smul, neg_neg, smul_smul, mul_inv_cancel hr.ne, one_smul, sub_eq_add_neg, neg_smul, neg_neg] -- Porting note: added type annotation and `by exact` replace : f (r⁻¹ • ⟨x, hx⟩) ≤ c := le_c (r⁻¹ • ⟨x, hx⟩) (by exact this) rwa [← mul_le_mul_left (neg_pos.2 hr), neg_mul, neg_mul, neg_le_neg_iff, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne, one_mul] at this · subst r simp only [zero_smul, add_zero] at hzs ⊢ apply nonneg exact hzs · have : r⁻¹ • x + y ∈ s := by rwa [← s.smul_mem_iff hr, smul_add, smul_smul, mul_inv_cancel hr.ne', one_smul] -- Porting note: added type annotation and `by exact` replace : c ≤ f (r⁻¹ • ⟨x, hx⟩) := c_le (r⁻¹ • ⟨x, hx⟩) (by exact this) rwa [← mul_le_mul_left hr, f.map_smul, smul_eq_mul, ← mul_assoc, mul_inv_cancel hr.ne', one_mul] at this theorem exists_top (p : E →ₗ.[ℝ] ℝ) (hp_nonneg : ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x) (hp_dense : ∀ y, ∃ x : p.domain, (x : E) + y ∈ s) : ∃ q ≥ p, q.domain = ⊤ ∧ ∀ x : q.domain, (x : E) ∈ s → 0 ≤ q x := by set S := { p : E →ₗ.[ℝ] ℝ | ∀ x : p.domain, (x : E) ∈ s → 0 ≤ p x } have hSc : ∀ c, c ⊆ S → IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ S, ∀ z ∈ c, z ≤ ub := by intro c hcs c_chain y hy clear hp_nonneg hp_dense p have cne : c.Nonempty := ⟨y, hy⟩ have hcd : DirectedOn (· ≤ ·) c := c_chain.directedOn refine ⟨LinearPMap.sSup c hcd, ?_, fun _ ↦ LinearPMap.le_sSup hcd⟩ rintro ⟨x, hx⟩ hxs have hdir : DirectedOn (· ≤ ·) (LinearPMap.domain '' c) := directedOn_image.2 (hcd.mono LinearPMap.domain_mono.monotone) rcases (mem_sSup_of_directed (cne.image _) hdir).1 hx with ⟨_, ⟨f, hfc, rfl⟩, hfx⟩ have : f ≤ LinearPMap.sSup c hcd := LinearPMap.le_sSup _ hfc convert ← hcs hfc ⟨x, hfx⟩ hxs using 1 exact this.2 rfl obtain ⟨q, hqs, hpq, hq⟩ := zorn_nonempty_partialOrder₀ S hSc p hp_nonneg refine ⟨q, hpq, ?_, hqs⟩ contrapose! hq have hqd : ∀ y, ∃ x : q.domain, (x : E) + y ∈ s := fun y ↦ let ⟨x, hx⟩ := hp_dense y ⟨Submodule.inclusion hpq.left x, hx⟩ rcases step s q hqs hqd hq with ⟨r, hqr, hr⟩ exact ⟨r, hr, hqr.le, hqr.ne'⟩ end RieszExtension /-- M. **Riesz extension theorem**: given a convex cone `s` in a vector space `E`, a submodule `p`, and a linear `f : p → ℝ`, assume that `f` is nonnegative on `p ∩ s` and `p + s = E`. Then there exists a globally defined linear function `g : E → ℝ` that agrees with `f` on `p`, and is nonnegative on `s`. -/ theorem riesz_extension (s : ConvexCone ℝ E) (f : E →ₗ.[ℝ] ℝ) (nonneg : ∀ x : f.domain, (x : E) ∈ s → 0 ≤ f x) (dense : ∀ y, ∃ x : f.domain, (x : E) + y ∈ s) : ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ ∀ x ∈ s, 0 ≤ g x := by rcases RieszExtension.exists_top s f nonneg dense with ⟨⟨g_dom, g⟩, ⟨-, hfg⟩, rfl : g_dom = ⊤, hgs⟩ refine ⟨g.comp (LinearMap.id.codRestrict ⊤ fun _ ↦ trivial), ?_, ?_⟩ · exact fun x => (hfg rfl).symm · exact fun x hx => hgs ⟨x, _⟩ hx /-- **Hahn-Banach theorem**: if `N : E → ℝ` is a sublinear map, `f` is a linear map defined on a subspace of `E`, and `f x ≤ N x` for all `x` in the domain of `f`, then `f` can be extended to the whole space to a linear map `g` such that `g x ≤ N x` for all `x`. -/ theorem exists_extension_of_le_sublinear (f : E →ₗ.[ℝ] ℝ) (N : E → ℝ) (N_hom : ∀ c : ℝ, 0 < c → ∀ x, N (c • x) = c * N x) (N_add : ∀ x y, N (x + y) ≤ N x + N y) (hf : ∀ x : f.domain, f x ≤ N x) : ∃ g : E →ₗ[ℝ] ℝ, (∀ x : f.domain, g x = f x) ∧ ∀ x, g x ≤ N x := by let s : ConvexCone ℝ (E × ℝ) := { carrier := { p : E × ℝ | N p.1 ≤ p.2 } smul_mem' := fun c hc p hp => calc N (c • p.1) = c * N p.1 := N_hom c hc p.1 _ ≤ c * p.2 := mul_le_mul_of_nonneg_left hp hc.le add_mem' := fun x hx y hy => (N_add _ _).trans (add_le_add hx hy) } set f' := (-f).coprod (LinearMap.id.toPMap ⊤) have hf'_nonneg : ∀ x : f'.domain, x.1 ∈ s → 0 ≤ f' x := fun x (hx : N x.1.1 ≤ x.1.2) ↦ by simpa [f'] using le_trans (hf ⟨x.1.1, x.2.1⟩) hx have hf'_dense : ∀ y : E × ℝ, ∃ x : f'.domain, ↑x + y ∈ s := by rintro ⟨x, y⟩ refine ⟨⟨(0, N x - y), ⟨f.domain.zero_mem, trivial⟩⟩, ?_⟩ simp only [s, ConvexCone.mem_mk, mem_setOf_eq, Prod.fst_add, Prod.snd_add, zero_add, sub_add_cancel, le_rfl] obtain ⟨g, g_eq, g_nonneg⟩ := riesz_extension s f' hf'_nonneg hf'_dense replace g_eq : ∀ (x : f.domain) (y : ℝ), g (x, y) = y - f x := fun x y ↦ (g_eq ⟨(x, y), ⟨x.2, trivial⟩⟩).trans (sub_eq_neg_add _ _).symm refine ⟨-g.comp (inl ℝ E ℝ), fun x ↦ ?_, fun x ↦ ?_⟩ · simp [g_eq x 0] · calc -g (x, 0) = g (0, N x) - g (x, N x) := by simp [← map_sub, ← map_neg] _ = N x - g (x, N x) := by simpa using g_eq 0 (N x) _ ≤ N x := by simpa using g_nonneg ⟨x, N x⟩ (le_refl (N x))
Analysis\Convex\Cone\InnerDual.lean
/- Copyright (c) 2021 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.Convex.Cone.Basic import Mathlib.Analysis.InnerProductSpace.Projection /-! # Convex cones in inner product spaces We define `Set.innerDualCone` to be the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. ## Main statements We prove the following theorems: * `ConvexCone.innerDualCone_of_innerDualCone_eq_self`: The `innerDualCone` of the `innerDualCone` of a nonempty, closed, convex cone is itself. * `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`: This variant of the [hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem) states that given a nonempty, closed, convex cone `K` in a complete, real inner product space `H` and a point `b` disjoint from it, there is a vector `y` which separates `b` from `K` in the sense that for all points `x` in `K`, `0 ≤ ⟪x, y⟫_ℝ` and `⟪y, b⟫_ℝ < 0`. This is also a geometric interpretation of the [Farkas lemma](https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation). -/ open Set LinearMap open scoped Classical open Pointwise variable {𝕜 E F G : Type*} /-! ### The dual cone -/ section Dual variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] (s t : Set H) open RealInnerProductSpace /-- The dual cone is the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. -/ def Set.innerDualCone (s : Set H) : ConvexCone ℝ H where carrier := { y | ∀ x ∈ s, 0 ≤ ⟪x, y⟫ } smul_mem' c hc y hy x hx := by rw [real_inner_smul_right] exact mul_nonneg hc.le (hy x hx) add_mem' u hu v hv x hx := by rw [inner_add_right] exact add_nonneg (hu x hx) (hv x hx) @[simp] theorem mem_innerDualCone (y : H) (s : Set H) : y ∈ s.innerDualCone ↔ ∀ x ∈ s, 0 ≤ ⟪x, y⟫ := Iff.rfl @[simp] theorem innerDualCone_empty : (∅ : Set H).innerDualCone = ⊤ := eq_top_iff.mpr fun _ _ _ => False.elim /-- Dual cone of the convex cone {0} is the total space. -/ @[simp] theorem innerDualCone_zero : (0 : Set H).innerDualCone = ⊤ := eq_top_iff.mpr fun _ _ y (hy : y = 0) => hy.symm ▸ (inner_zero_left _).ge /-- Dual cone of the total space is the convex cone {0}. -/ @[simp] theorem innerDualCone_univ : (univ : Set H).innerDualCone = 0 := by suffices ∀ x : H, x ∈ (univ : Set H).innerDualCone → x = 0 by apply SetLike.coe_injective exact eq_singleton_iff_unique_mem.mpr ⟨fun x _ => (inner_zero_right _).ge, this⟩ exact fun x hx => by simpa [← real_inner_self_nonpos] using hx (-x) (mem_univ _) theorem innerDualCone_le_innerDualCone (h : t ⊆ s) : s.innerDualCone ≤ t.innerDualCone := fun _ hy x hx => hy x (h hx) theorem pointed_innerDualCone : s.innerDualCone.Pointed := fun x _ => by rw [inner_zero_right] /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `fun y ↦ ⟪x, y⟫`. -/ theorem innerDualCone_singleton (x : H) : ({x} : Set H).innerDualCone = (ConvexCone.positive ℝ ℝ).comap (innerₛₗ ℝ x) := ConvexCone.ext fun _ => forall_eq theorem innerDualCone_union (s t : Set H) : (s ∪ t).innerDualCone = s.innerDualCone ⊓ t.innerDualCone := le_antisymm (le_inf (fun _ hx _ hy => hx _ <| Or.inl hy) fun _ hx _ hy => hx _ <| Or.inr hy) fun _ hx _ => Or.rec (hx.1 _) (hx.2 _) theorem innerDualCone_insert (x : H) (s : Set H) : (insert x s).innerDualCone = Set.innerDualCone {x} ⊓ s.innerDualCone := by rw [insert_eq, innerDualCone_union] theorem innerDualCone_iUnion {ι : Sort*} (f : ι → Set H) : (⋃ i, f i).innerDualCone = ⨅ i, (f i).innerDualCone := by refine le_antisymm (le_iInf fun i x hx y hy => hx _ <| mem_iUnion_of_mem _ hy) ?_ intro x hx y hy rw [ConvexCone.mem_iInf] at hx obtain ⟨j, hj⟩ := mem_iUnion.mp hy exact hx _ _ hj theorem innerDualCone_sUnion (S : Set (Set H)) : (⋃₀ S).innerDualCone = sInf (Set.innerDualCone '' S) := by simp_rw [sInf_image, sUnion_eq_biUnion, innerDualCone_iUnion] /-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/ theorem innerDualCone_eq_iInter_innerDualCone_singleton : (s.innerDualCone : Set H) = ⋂ i : s, (({↑i} : Set H).innerDualCone : Set H) := by rw [← ConvexCone.coe_iInf, ← innerDualCone_iUnion, iUnion_of_singleton_coe] theorem isClosed_innerDualCone : IsClosed (s.innerDualCone : Set H) := by -- reduce the problem to showing that dual cone of a singleton `{x}` is closed rw [innerDualCone_eq_iInter_innerDualCone_singleton] apply isClosed_iInter intro x -- the dual cone of a singleton `{x}` is the preimage of `[0, ∞)` under `inner x` have h : ({↑x} : Set H).innerDualCone = (inner x : H → ℝ) ⁻¹' Set.Ici 0 := by rw [innerDualCone_singleton, ConvexCone.coe_comap, ConvexCone.coe_positive, innerₛₗ_apply_coe] -- the preimage is closed as `inner x` is continuous and `[0, ∞)` is closed rw [h] exact isClosed_Ici.preimage (continuous_const.inner continuous_id') theorem ConvexCone.pointed_of_nonempty_of_isClosed (K : ConvexCone ℝ H) (ne : (K : Set H).Nonempty) (hc : IsClosed (K : Set H)) : K.Pointed := by obtain ⟨x, hx⟩ := ne let f : ℝ → H := (· • x) -- f (0, ∞) is a subset of K have fI : f '' Set.Ioi 0 ⊆ (K : Set H) := by rintro _ ⟨_, h, rfl⟩ exact K.smul_mem (Set.mem_Ioi.1 h) hx -- closure of f (0, ∞) is a subset of K have clf : closure (f '' Set.Ioi 0) ⊆ (K : Set H) := hc.closure_subset_iff.2 fI -- f is continuous at 0 from the right have fc : ContinuousWithinAt f (Set.Ioi (0 : ℝ)) 0 := (continuous_id.smul continuous_const).continuousWithinAt -- 0 belongs to the closure of the f (0, ∞) have mem₀ := fc.mem_closure_image (by rw [closure_Ioi (0 : ℝ), mem_Ici]) -- as 0 ∈ closure f (0, ∞) and closure f (0, ∞) ⊆ K, 0 ∈ K. have f₀ : f 0 = 0 := zero_smul ℝ x simpa only [f₀, ConvexCone.Pointed, ← SetLike.mem_coe] using mem_of_subset_of_mem clf mem₀ section CompleteSpace variable [CompleteSpace H] /-- This is a stronger version of the Hahn-Banach separation theorem for closed convex cones. This is also the geometric interpretation of Farkas' lemma. -/ theorem ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem (K : ConvexCone ℝ H) (ne : (K : Set H).Nonempty) (hc : IsClosed (K : Set H)) {b : H} (disj : b ∉ K) : ∃ y : H, (∀ x : H, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ) ∧ ⟪y, b⟫_ℝ < 0 := by -- let `z` be the point in `K` closest to `b` obtain ⟨z, hzK, infi⟩ := exists_norm_eq_iInf_of_complete_convex ne hc.isComplete K.convex b -- for any `w` in `K`, we have `⟪b - z, w - z⟫_ℝ ≤ 0` have hinner := (norm_eq_iInf_iff_real_inner_le_zero K.convex hzK).1 infi -- set `y := z - b` use z - b constructor · -- the rest of the proof is a straightforward calculation rintro x hxK specialize hinner _ (K.add_mem hxK hzK) rwa [add_sub_cancel_right, real_inner_comm, ← neg_nonneg, neg_eq_neg_one_mul, ← real_inner_smul_right, neg_smul, one_smul, neg_sub] at hinner · -- as `K` is closed and non-empty, it is pointed have hinner₀ := hinner 0 (K.pointed_of_nonempty_of_isClosed ne hc) -- the rest of the proof is a straightforward calculation rw [zero_sub, inner_neg_right, Right.neg_nonpos_iff] at hinner₀ have hbz : b - z ≠ 0 := by rw [sub_ne_zero] contrapose! hzK rwa [← hzK] rw [← neg_zero, lt_neg, ← neg_one_mul, ← real_inner_smul_left, smul_sub, neg_smul, one_smul, neg_smul, neg_sub_neg, one_smul] calc 0 < ⟪b - z, b - z⟫_ℝ := lt_of_not_le ((Iff.not real_inner_self_nonpos).2 hbz) _ = ⟪b - z, b - z⟫_ℝ + 0 := (add_zero _).symm _ ≤ ⟪b - z, b - z⟫_ℝ + ⟪b - z, z⟫_ℝ := add_le_add rfl.ge hinner₀ _ = ⟪b - z, b - z + z⟫_ℝ := (inner_add_right _ _ _).symm _ = ⟪b - z, b⟫_ℝ := by rw [sub_add_cancel] /-- The inner dual of inner dual of a non-empty, closed convex cone is itself. -/ theorem ConvexCone.innerDualCone_of_innerDualCone_eq_self (K : ConvexCone ℝ H) (ne : (K : Set H).Nonempty) (hc : IsClosed (K : Set H)) : ((K : Set H).innerDualCone : Set H).innerDualCone = K := by ext x constructor · rw [mem_innerDualCone, ← SetLike.mem_coe] contrapose! exact K.hyperplane_separation_of_nonempty_of_isClosed_of_nmem ne hc · rintro hxK y h specialize h x hxK rwa [real_inner_comm] end CompleteSpace end Dual
Analysis\Convex\Cone\Pointed.lean
/- Copyright (c) 2023 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import Mathlib.Analysis.Convex.Cone.InnerDual import Mathlib.Algebra.Order.Nonneg.Module import Mathlib.Algebra.Module.Submodule.Basic /-! # Pointed cones A *pointed cone* is defined to be a submodule of a module where the scalars are restricted to be nonnegative. This is equivalent to saying that as a set a pointed cone is convex cone which contains `0`. This is a bundled version of `ConvexCone.Pointed`. We choose the submodule definition as it allows us to use the `Module` API to work with convex cones. -/ variable {𝕜 E F G : Type*} local notation3 "𝕜≥0" => {c : 𝕜 // 0 ≤ c} /-- A pointed cone is a submodule of a module with scalars restricted to being nonnegative. -/ abbrev PointedCone (𝕜 E) [OrderedSemiring 𝕜] [AddCommMonoid E] [Module 𝕜 E] := Submodule {c : 𝕜 // 0 ≤ c} E namespace PointedCone open Function section Definitions variable [OrderedSemiring 𝕜] variable [AddCommMonoid E] [Module 𝕜 E] /-- Every pointed cone is a convex cone. -/ @[coe] def toConvexCone (S : PointedCone 𝕜 E) : ConvexCone 𝕜 E where carrier := S smul_mem' c hc _ hx := S.smul_mem ⟨c, le_of_lt hc⟩ hx add_mem' _ hx _ hy := S.add_mem hx hy instance : Coe (PointedCone 𝕜 E) (ConvexCone 𝕜 E) where coe := toConvexCone theorem toConvexCone_injective : Injective ((↑) : PointedCone 𝕜 E → ConvexCone 𝕜 E) := fun _ _ => by simp [toConvexCone] @[simp] theorem toConvexCone_pointed (S : PointedCone 𝕜 E) : (S : ConvexCone 𝕜 E).Pointed := by simp [toConvexCone, ConvexCone.Pointed] @[ext] theorem ext {S T : PointedCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h instance instZero (S : PointedCone 𝕜 E) : Zero S := ⟨0, S.zero_mem⟩ /-- The `PointedCone` constructed from a pointed `ConvexCone`. -/ def _root_.ConvexCone.toPointedCone {S : ConvexCone 𝕜 E} (hS : S.Pointed) : PointedCone 𝕜 E where carrier := S add_mem' hx hy := S.add_mem hx hy zero_mem' := hS smul_mem' := fun ⟨c, hc⟩ x hx => by simp_rw [SetLike.mem_coe] cases' eq_or_lt_of_le hc with hzero hpos · unfold ConvexCone.Pointed at hS convert hS simp [← hzero] · apply ConvexCone.smul_mem · convert hpos · exact hx @[simp] lemma _root_.ConvexCone.mem_toPointedCone {S : ConvexCone 𝕜 E} (hS : S.Pointed) (x : E) : x ∈ S.toPointedCone hS ↔ x ∈ S := Iff.rfl @[simp, norm_cast] lemma _root_.ConvexCone.coe_toPointedCone {S : ConvexCone 𝕜 E} (hS : S.Pointed) : S.toPointedCone hS = S := rfl instance canLift : CanLift (ConvexCone 𝕜 E) (PointedCone 𝕜 E) (↑) ConvexCone.Pointed where prf S hS := ⟨S.toPointedCone hS, rfl⟩ end Definitions section Maps variable [OrderedSemiring 𝕜] variable [AddCommMonoid E] [Module 𝕜 E] variable [AddCommMonoid F] [Module 𝕜 F] variable [AddCommMonoid G] [Module 𝕜 G] /-! ## Maps between pointed cones There is already a definition of maps between submodules, `Submodule.map`. In our case, these maps are induced from linear maps between the ambient modules that are linear over nonnegative scalars. Such maps are unlikely to be of any use in practice. So, we construct some API to define maps between pointed cones induced from linear maps between the ambient modules that are linear over *all* scalars. -/ /-- The image of a pointed cone under a `𝕜`-linear map is a pointed cone. -/ def map (f : E →ₗ[𝕜] F) (S : PointedCone 𝕜 E) : PointedCone 𝕜 F := Submodule.map (f : E →ₗ[𝕜≥0] F) S @[simp, norm_cast] theorem toConvexCone_map (S : PointedCone 𝕜 E) (f : E →ₗ[𝕜] F) : (S.map f : ConvexCone 𝕜 F) = (S : ConvexCone 𝕜 E).map f := rfl @[simp, norm_cast] theorem coe_map (S : PointedCone 𝕜 E) (f : E →ₗ[𝕜] F) : (S.map f : Set F) = f '' S := rfl @[simp] theorem mem_map {f : E →ₗ[𝕜] F} {S : PointedCone 𝕜 E} {y : F} : y ∈ S.map f ↔ ∃ x ∈ S, f x = y := Iff.rfl theorem map_map (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : PointedCone 𝕜 E) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image g f S @[simp] theorem map_id (S : PointedCone 𝕜 E) : S.map LinearMap.id = S := SetLike.coe_injective <| Set.image_id _ /-- The preimage of a convex cone under a `𝕜`-linear map is a convex cone. -/ def comap (f : E →ₗ[𝕜] F) (S : PointedCone 𝕜 F) : PointedCone 𝕜 E := Submodule.comap (f : E →ₗ[𝕜≥0] F) S @[simp, norm_cast] theorem coe_comap (f : E →ₗ[𝕜] F) (S : PointedCone 𝕜 F) : (S.comap f : Set E) = f ⁻¹' S := rfl @[simp] theorem comap_id (S : PointedCone 𝕜 E) : S.comap LinearMap.id = S := rfl theorem comap_comap (g : F →ₗ[𝕜] G) (f : E →ₗ[𝕜] F) (S : PointedCone 𝕜 G) : (S.comap g).comap f = S.comap (g.comp f) := rfl @[simp] theorem mem_comap {f : E →ₗ[𝕜] F} {S : PointedCone 𝕜 F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl end Maps section PositiveCone variable (𝕜 E) variable [OrderedSemiring 𝕜] variable [OrderedAddCommGroup E] [Module 𝕜 E] [OrderedSMul 𝕜 E] /-- The positive cone is the pointed cone formed by the set of nonnegative elements in an ordered module. -/ def positive : PointedCone 𝕜 E := (ConvexCone.positive 𝕜 E).toPointedCone <| ConvexCone.pointed_positive 𝕜 E @[simp] theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := Iff.rfl @[simp, norm_cast] theorem toConvexCone_positive : ↑(positive 𝕜 E) = ConvexCone.positive 𝕜 E := rfl end PositiveCone section Dual variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] /-- The inner dual cone of a pointed cone is a pointed cone. -/ def dual (S : PointedCone ℝ E) : PointedCone ℝ E := ((S : Set E).innerDualCone).toPointedCone <| pointed_innerDualCone (S : Set E) @[simp, norm_cast] theorem toConvexCone_dual (S : PointedCone ℝ E) : ↑(dual S) = (S : Set E).innerDualCone := rfl @[simp] theorem mem_dual {S : PointedCone ℝ E} {y : E} : y ∈ dual S ↔ ∀ ⦃x⦄, x ∈ S → 0 ≤ ⟪x, y⟫_ℝ := by rfl end Dual end PointedCone
Analysis\Convex\Cone\Proper.lean
/- Copyright (c) 2022 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import Mathlib.Analysis.Convex.Cone.Closure import Mathlib.Analysis.InnerProductSpace.Adjoint /-! # Proper cones We define a *proper cone* as a closed, pointed cone. Proper cones are used in defining conic programs which generalize linear programs. A linear program is a conic program for the positive cone. We then prove Farkas' lemma for conic programs following the proof in the reference below. Farkas' lemma is equivalent to strong duality. So, once we have the definitions of conic and linear programs, the results from this file can be used to prove duality theorems. ## TODO The next steps are: - Add convex_cone_class that extends set_like and replace the below instance - Define primal and dual cone programs and prove weak duality. - Prove regular and strong duality for cone programs using Farkas' lemma (see reference). - Define linear programs and prove LP duality as a special case of cone duality. - Find a better reference (textbook instead of lecture notes). ## References - [B. Gartner and J. Matousek, Cone Programming][gartnerMatousek] -/ open ContinuousLinearMap Filter Set /-- A proper cone is a pointed cone `K` that is closed. Proper cones have the nice property that they are equal to their double dual, see `ProperCone.dual_dual`. This makes them useful for defining cone programs and proving duality theorems. -/ structure ProperCone (𝕜 : Type*) (E : Type*) [OrderedSemiring 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] extends Submodule {c : 𝕜 // 0 ≤ c} E where isClosed' : IsClosed (carrier : Set E) namespace ProperCone section Module variable {𝕜 : Type*} [OrderedSemiring 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] /-- A `PointedCone` is defined as an alias of submodule. We replicate the abbreviation here and define `toPointedCone` as an alias of `toSubmodule`. -/ abbrev toPointedCone (C : ProperCone 𝕜 E) := C.toSubmodule attribute [coe] toPointedCone instance : Coe (ProperCone 𝕜 E) (PointedCone 𝕜 E) := ⟨toPointedCone⟩ -- Porting note: now a syntactic tautology -- @[simp] -- theorem toConvexCone_eq_coe (K : ProperCone 𝕜 E) : K.toConvexCone = K := -- rfl theorem toPointedCone_injective : Function.Injective ((↑) : ProperCone 𝕜 E → PointedCone 𝕜 E) := fun S T h => by cases S; cases T; congr -- TODO: add `ConvexConeClass` that extends `SetLike` and replace the below instance instance : SetLike (ProperCone 𝕜 E) E where coe K := K.carrier coe_injective' _ _ h := ProperCone.toPointedCone_injective (SetLike.coe_injective h) @[ext] theorem ext {S T : ProperCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem mem_coe {x : E} {K : ProperCone 𝕜 E} : x ∈ (K : PointedCone 𝕜 E) ↔ x ∈ K := Iff.rfl instance instZero (K : ProperCone 𝕜 E) : Zero K := PointedCone.instZero (K.toSubmodule) protected theorem nonempty (K : ProperCone 𝕜 E) : (K : Set E).Nonempty := ⟨0, by { simp_rw [SetLike.mem_coe, ← ProperCone.mem_coe, Submodule.zero_mem] }⟩ protected theorem isClosed (K : ProperCone 𝕜 E) : IsClosed (K : Set E) := K.isClosed' end Module section PositiveCone variable (𝕜 E) variable [OrderedSemiring 𝕜] [OrderedAddCommGroup E] [Module 𝕜 E] [OrderedSMul 𝕜 E] [TopologicalSpace E] [OrderClosedTopology E] /-- The positive cone is the proper cone formed by the set of nonnegative elements in an ordered module. -/ def positive : ProperCone 𝕜 E where toSubmodule := PointedCone.positive 𝕜 E isClosed' := isClosed_Ici @[simp] theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := Iff.rfl @[simp] theorem coe_positive : ↑(positive 𝕜 E) = ConvexCone.positive 𝕜 E := rfl end PositiveCone section Module variable {𝕜 : Type*} [OrderedSemiring 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [T1Space E] [Module 𝕜 E] instance : Zero (ProperCone 𝕜 E) := ⟨{ toSubmodule := 0 isClosed' := isClosed_singleton }⟩ instance : Inhabited (ProperCone 𝕜 E) := ⟨0⟩ @[simp] theorem mem_zero (x : E) : x ∈ (0 : ProperCone 𝕜 E) ↔ x = 0 := Iff.rfl @[simp, norm_cast] theorem coe_zero : ↑(0 : ProperCone 𝕜 E) = (0 : ConvexCone 𝕜 E) := rfl theorem pointed_zero : ((0 : ProperCone 𝕜 E) : ConvexCone 𝕜 E).Pointed := by simp [ConvexCone.pointed_zero] end Module section InnerProductSpace variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace ℝ G] protected theorem pointed (K : ProperCone ℝ E) : (K : ConvexCone ℝ E).Pointed := (K : ConvexCone ℝ E).pointed_of_nonempty_of_isClosed K.nonempty K.isClosed /-- The closure of image of a proper cone under a continuous `ℝ`-linear map is a proper cone. We use continuous maps here so that the comap of f is also a map between proper cones. -/ noncomputable def map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ProperCone ℝ F where toSubmodule := PointedCone.closure (PointedCone.map (f : E →ₗ[ℝ] F) ↑K) isClosed' := isClosed_closure @[simp, norm_cast] theorem coe_map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ↑(K.map f) = (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure := rfl @[simp] theorem mem_map {f : E →L[ℝ] F} {K : ProperCone ℝ E} {y : F} : y ∈ K.map f ↔ y ∈ (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure := Iff.rfl @[simp] theorem map_id (K : ProperCone ℝ E) : K.map (ContinuousLinearMap.id ℝ E) = K := ProperCone.toPointedCone_injective <| by simpa using IsClosed.closure_eq K.isClosed /-- The inner dual cone of a proper cone is a proper cone. -/ def dual (K : ProperCone ℝ E) : ProperCone ℝ E where toSubmodule := PointedCone.dual (K : PointedCone ℝ E) isClosed' := isClosed_innerDualCone _ @[simp, norm_cast] theorem coe_dual (K : ProperCone ℝ E) : K.dual = (K : Set E).innerDualCone := rfl @[simp] theorem mem_dual {K : ProperCone ℝ E} {y : E} : y ∈ dual K ↔ ∀ ⦃x⦄, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ := by aesop /-- The preimage of a proper cone under a continuous `ℝ`-linear map is a proper cone. -/ noncomputable def comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : ProperCone ℝ E where toSubmodule := PointedCone.comap (f : E →ₗ[ℝ] F) S isClosed' := by rw [PointedCone.comap] apply IsClosed.preimage f.2 S.isClosed @[simp] theorem coe_comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : (S.comap f : Set E) = f ⁻¹' S := rfl @[simp] theorem comap_id (S : ConvexCone ℝ E) : S.comap LinearMap.id = S := SetLike.coe_injective preimage_id theorem comap_comap (g : F →L[ℝ] G) (f : E →L[ℝ] F) (S : ProperCone ℝ G) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by congr @[simp] theorem mem_comap {f : E →L[ℝ] F} {S : ProperCone ℝ F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl end InnerProductSpace section CompleteSpace variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [CompleteSpace F] /-- The dual of the dual of a proper cone is itself. -/ @[simp] theorem dual_dual (K : ProperCone ℝ E) : K.dual.dual = K := ProperCone.toPointedCone_injective <| PointedCone.toConvexCone_injective <| (K : ConvexCone ℝ E).innerDualCone_of_innerDualCone_eq_self K.nonempty K.isClosed /-- This is a relative version of `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`, which we recover by setting `f` to be the identity map. This is also a geometric interpretation of the Farkas' lemma stated using proper cones. -/ theorem hyperplane_separation (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F} : b ∈ K.map f ↔ ∀ y : F, adjoint f y ∈ K.dual → 0 ≤ ⟪y, b⟫_ℝ := Iff.intro (by -- suppose `b ∈ K.map f` simp_rw [mem_map, PointedCone.mem_closure, PointedCone.coe_map, coe_coe, mem_closure_iff_seq_limit, mem_image, SetLike.mem_coe, mem_coe, mem_dual, adjoint_inner_right, forall_exists_index, and_imp] -- there is a sequence `seq : ℕ → F` in the image of `f` that converges to `b` rintro seq hmem htends y hinner suffices h : ∀ n, 0 ≤ ⟪y, seq n⟫_ℝ from ge_of_tendsto' (Continuous.seqContinuous (Continuous.inner (@continuous_const _ _ _ _ y) continuous_id) htends) h intro n obtain ⟨_, h, hseq⟩ := hmem n simpa only [← hseq, real_inner_comm] using hinner h) (by -- proof by contradiction -- suppose `b ∉ K.map f` intro h contrapose! h -- as `b ∉ K.map f`, there is a hyperplane `y` separating `b` from `K.map f` let C := @PointedCone.toConvexCone ℝ F _ _ _ (K.map f) obtain ⟨y, hxy, hyb⟩ := @ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem _ _ _ _ C (K.map f).nonempty (K.map f).isClosed b h -- the rest of the proof is a straightforward algebraic manipulation refine ⟨y, ?_, hyb⟩ simp_rw [ProperCone.mem_dual, adjoint_inner_right] intro x hxK apply hxy (f x) simp_rw [C, coe_map] apply subset_closure simp_rw [PointedCone.toConvexCone_map, ConvexCone.coe_map, coe_coe, mem_image, SetLike.mem_coe] exact ⟨x, hxK, rfl⟩) theorem hyperplane_separation_of_nmem (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F} (disj : b ∉ K.map f) : ∃ y : F, adjoint f y ∈ K.dual ∧ ⟪y, b⟫_ℝ < 0 := by contrapose! disj; rwa [K.hyperplane_separation] end CompleteSpace end ProperCone
Analysis\Convex\SimplicialComplex\Basic.lean
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Independent /-! # Simplicial complexes In this file, we define simplicial complexes in `𝕜`-modules. A simplicial complex is a collection of simplices closed by inclusion (of vertices) and intersection (of underlying sets). We model them by a downward-closed set of affine independent finite sets whose convex hulls "glue nicely", each finite set and its convex hull corresponding respectively to the vertices and the underlying set of a simplex. ## Main declarations * `SimplicialComplex 𝕜 E`: A simplicial complex in the `𝕜`-module `E`. * `SimplicialComplex.vertices`: The zero dimensional faces of a simplicial complex. * `SimplicialComplex.facets`: The maximal faces of a simplicial complex. ## Notation `s ∈ K` means that `s` is a face of `K`. `K ≤ L` means that the faces of `K` are faces of `L`. ## Implementation notes "glue nicely" usually means that the intersection of two faces (as sets in the ambient space) is a face. Given that we store the vertices, not the faces, this would be a bit awkward to spell. Instead, `SimplicialComplex.inter_subset_convexHull` is an equivalent condition which works on the vertices. ## TODO Simplicial complexes can be generalized to affine spaces once `ConvexHull` has been ported. -/ open Finset Set variable (𝕜 E : Type*) {ι : Type*} [OrderedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] namespace Geometry -- TODO: update to new binder order? not sure what binder order is correct for `down_closed`. /-- A simplicial complex in a `𝕜`-module is a collection of simplices which glue nicely together. Note that the textbook meaning of "glue nicely" is given in `Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull`. It is mostly useless, as `Geometry.SimplicialComplex.convexHull_inter_convexHull` is enough for all purposes. -/ @[ext] structure SimplicialComplex where /-- the faces of this simplicial complex: currently, given by their spanning vertices -/ faces : Set (Finset E) /-- the empty set is not a face: hence, all faces are non-empty -/ not_empty_mem : ∅ ∉ faces /-- the vertices in each face are affine independent: this is an implementation detail -/ indep : ∀ {s}, s ∈ faces → AffineIndependent 𝕜 ((↑) : s → E) /-- faces are downward closed: a non-empty subset of its spanning vertices spans another face -/ down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ≠ ∅ → t ∈ faces inter_subset_convexHull : ∀ {s t}, s ∈ faces → t ∈ faces → convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E) namespace SimplicialComplex variable {𝕜 E} variable {K : SimplicialComplex 𝕜 E} {s t : Finset E} {x : E} /-- A `Finset` belongs to a `SimplicialComplex` if it's a face of it. -/ instance : Membership (Finset E) (SimplicialComplex 𝕜 E) := ⟨fun s K => s ∈ K.faces⟩ /-- The underlying space of a simplicial complex is the union of its faces. -/ def space (K : SimplicialComplex 𝕜 E) : Set E := ⋃ s ∈ K.faces, convexHull 𝕜 (s : Set E) -- Porting note: Expanded `∃ s ∈ K.faces` to get the type to match more closely with Lean 3 theorem mem_space_iff : x ∈ K.space ↔ ∃ s ∈ K.faces, x ∈ convexHull 𝕜 (s : Set E) := by simp [space] -- Porting note: Original proof was `:= subset_biUnion_of_mem hs` theorem convexHull_subset_space (hs : s ∈ K.faces) : convexHull 𝕜 ↑s ⊆ K.space := by convert subset_biUnion_of_mem hs rfl protected theorem subset_space (hs : s ∈ K.faces) : (s : Set E) ⊆ K.space := (subset_convexHull 𝕜 _).trans <| convexHull_subset_space hs theorem convexHull_inter_convexHull (hs : s ∈ K.faces) (ht : t ∈ K.faces) : convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t = convexHull 𝕜 (s ∩ t : Set E) := (K.inter_subset_convexHull hs ht).antisymm <| subset_inter (convexHull_mono Set.inter_subset_left) <| convexHull_mono Set.inter_subset_right /-- The conclusion is the usual meaning of "glue nicely" in textbooks. It turns out to be quite unusable, as it's about faces as sets in space rather than simplices. Further, additional structure on `𝕜` means the only choice of `u` is `s ∩ t` (but it's hard to prove). -/ theorem disjoint_or_exists_inter_eq_convexHull (hs : s ∈ K.faces) (ht : t ∈ K.faces) : Disjoint (convexHull 𝕜 (s : Set E)) (convexHull 𝕜 ↑t) ∨ ∃ u ∈ K.faces, convexHull 𝕜 (s : Set E) ∩ convexHull 𝕜 ↑t = convexHull 𝕜 ↑u := by classical by_contra! h refine h.2 (s ∩ t) (K.down_closed hs inter_subset_left fun hst => h.1 <| disjoint_iff_inf_le.mpr <| (K.inter_subset_convexHull hs ht).trans ?_) ?_ · rw [← coe_inter, hst, coe_empty, convexHull_empty] rfl · rw [coe_inter, convexHull_inter_convexHull hs ht] /-- Construct a simplicial complex by removing the empty face for you. -/ @[simps] def ofErase (faces : Set (Finset E)) (indep : ∀ s ∈ faces, AffineIndependent 𝕜 ((↑) : s → E)) (down_closed : ∀ s ∈ faces, ∀ t ⊆ s, t ∈ faces) (inter_subset_convexHull : ∀ᵉ (s ∈ faces) (t ∈ faces), convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E)) : SimplicialComplex 𝕜 E where faces := faces \ {∅} not_empty_mem h := h.2 (mem_singleton _) indep hs := indep _ hs.1 down_closed hs hts ht := ⟨down_closed _ hs.1 _ hts, ht⟩ inter_subset_convexHull hs ht := inter_subset_convexHull _ hs.1 _ ht.1 /-- Construct a simplicial complex as a subset of a given simplicial complex. -/ @[simps] def ofSubcomplex (K : SimplicialComplex 𝕜 E) (faces : Set (Finset E)) (subset : faces ⊆ K.faces) (down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ∈ faces) : SimplicialComplex 𝕜 E := { faces not_empty_mem := fun h => K.not_empty_mem (subset h) indep := fun hs => K.indep (subset hs) down_closed := fun hs hts _ => down_closed hs hts inter_subset_convexHull := fun hs ht => K.inter_subset_convexHull (subset hs) (subset ht) } /-! ### Vertices -/ /-- The vertices of a simplicial complex are its zero dimensional faces. -/ def vertices (K : SimplicialComplex 𝕜 E) : Set E := { x | {x} ∈ K.faces } theorem mem_vertices : x ∈ K.vertices ↔ {x} ∈ K.faces := Iff.rfl theorem vertices_eq : K.vertices = ⋃ k ∈ K.faces, (k : Set E) := by ext x refine ⟨fun h => mem_biUnion h <| mem_coe.2 <| mem_singleton_self x, fun h => ?_⟩ obtain ⟨s, hs, hx⟩ := mem_iUnion₂.1 h exact K.down_closed hs (Finset.singleton_subset_iff.2 <| mem_coe.1 hx) (singleton_ne_empty _) theorem vertices_subset_space : K.vertices ⊆ K.space := vertices_eq.subset.trans <| iUnion₂_mono fun x _ => subset_convexHull 𝕜 (x : Set E) theorem vertex_mem_convexHull_iff (hx : x ∈ K.vertices) (hs : s ∈ K.faces) : x ∈ convexHull 𝕜 (s : Set E) ↔ x ∈ s := by refine ⟨fun h => ?_, fun h => subset_convexHull 𝕜 _ h⟩ classical have h := K.inter_subset_convexHull hx hs ⟨by simp, h⟩ by_contra H rwa [← coe_inter, Finset.disjoint_iff_inter_eq_empty.1 (Finset.disjoint_singleton_right.2 H).symm, coe_empty, convexHull_empty] at h /-- A face is a subset of another one iff its vertices are. -/ theorem face_subset_face_iff (hs : s ∈ K.faces) (ht : t ∈ K.faces) : convexHull 𝕜 (s : Set E) ⊆ convexHull 𝕜 ↑t ↔ s ⊆ t := ⟨fun h _ hxs => (vertex_mem_convexHull_iff (K.down_closed hs (Finset.singleton_subset_iff.2 hxs) <| singleton_ne_empty _) ht).1 (h (subset_convexHull 𝕜 (↑s) hxs)), convexHull_mono⟩ /-! ### Facets -/ /-- A facet of a simplicial complex is a maximal face. -/ def facets (K : SimplicialComplex 𝕜 E) : Set (Finset E) := { s ∈ K.faces | ∀ ⦃t⦄, t ∈ K.faces → s ⊆ t → s = t } theorem mem_facets : s ∈ K.facets ↔ s ∈ K.faces ∧ ∀ t ∈ K.faces, s ⊆ t → s = t := mem_sep_iff theorem facets_subset : K.facets ⊆ K.faces := fun _ hs => hs.1 theorem not_facet_iff_subface (hs : s ∈ K.faces) : s ∉ K.facets ↔ ∃ t, t ∈ K.faces ∧ s ⊂ t := by refine ⟨fun hs' : ¬(_ ∧ _) => ?_, ?_⟩ · push_neg at hs' obtain ⟨t, ht⟩ := hs' hs exact ⟨t, ht.1, ⟨ht.2.1, fun hts => ht.2.2 (Subset.antisymm ht.2.1 hts)⟩⟩ · rintro ⟨t, ht⟩ ⟨hs, hs'⟩ have := hs' ht.1 ht.2.1 rw [this] at ht exact ht.2.2 (Subset.refl t) /-! ### The semilattice of simplicial complexes `K ≤ L` means that `K.faces ⊆ L.faces`. -/ -- `HasSSubset.SSubset.ne` would be handy here variable (𝕜 E) /-- The complex consisting of only the faces present in both of its arguments. -/ instance : Inf (SimplicialComplex 𝕜 E) := ⟨fun K L => { faces := K.faces ∩ L.faces not_empty_mem := fun h => K.not_empty_mem (Set.inter_subset_left h) indep := fun hs => K.indep hs.1 down_closed := fun hs hst ht => ⟨K.down_closed hs.1 hst ht, L.down_closed hs.2 hst ht⟩ inter_subset_convexHull := fun hs ht => K.inter_subset_convexHull hs.1 ht.1 }⟩ instance : SemilatticeInf (SimplicialComplex 𝕜 E) := { PartialOrder.lift faces (fun _ _ => SimplicialComplex.ext) with inf := (· ⊓ ·) inf_le_left := fun _ _ _ hs => hs.1 inf_le_right := fun _ _ _ hs => hs.2 le_inf := fun _ _ _ hKL hKM _ hs => ⟨hKL hs, hKM hs⟩ } instance hasBot : Bot (SimplicialComplex 𝕜 E) := ⟨{ faces := ∅ not_empty_mem := Set.not_mem_empty ∅ indep := fun hs => (Set.not_mem_empty _ hs).elim down_closed := fun hs => (Set.not_mem_empty _ hs).elim inter_subset_convexHull := fun hs => (Set.not_mem_empty _ hs).elim }⟩ instance : OrderBot (SimplicialComplex 𝕜 E) := { SimplicialComplex.hasBot 𝕜 E with bot_le := fun _ => Set.empty_subset _ } instance : Inhabited (SimplicialComplex 𝕜 E) := ⟨⊥⟩ variable {𝕜 E} theorem faces_bot : (⊥ : SimplicialComplex 𝕜 E).faces = ∅ := rfl theorem space_bot : (⊥ : SimplicialComplex 𝕜 E).space = ∅ := Set.biUnion_empty _ theorem facets_bot : (⊥ : SimplicialComplex 𝕜 E).facets = ∅ := eq_empty_of_subset_empty facets_subset end SimplicialComplex end Geometry
Analysis\Convex\SpecificFunctions\Basic.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Heather Macbeth -/ import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Tactic.LinearCombination /-! # Collection of convex functions In this file we prove that the following functions are convex or strictly convex: * `strictConvexOn_exp` : The exponential function is strictly convex. * `strictConcaveOn_log_Ioi`, `strictConcaveOn_log_Iio`: `Real.log` is strictly concave on $(0, +∞)$ and $(-∞, 0)$ respectively. * `convexOn_rpow`, `strictConvexOn_rpow` : For `p : ℝ`, `fun x ↦ x ^ p` is convex on $[0, +∞)$ when `1 ≤ p` and strictly convex when `1 < p`. The proofs in this file are deliberately elementary, *not* by appealing to the sign of the second derivative. This is in order to keep this file early in the import hierarchy, since it is on the path to Hölder's and Minkowski's inequalities and after that to Lp spaces and most of measure theory. (Strict) concavity of `fun x ↦ x ^ p` for `0 < p < 1` (`0 ≤ p ≤ 1`) can be found in `Mathlib.Analysis.Convex.SpecificFunctions.Pow`. ## See also `Mathlib.Analysis.Convex.Mul` for convexity of `x ↦ x ^ n` -/ open Real Set NNReal /-- `Real.exp` is strictly convex on the whole real line. -/ theorem strictConvexOn_exp : StrictConvexOn ℝ univ exp := by apply strictConvexOn_of_slope_strict_mono_adjacent convex_univ rintro x y z - - hxy hyz trans exp y · have h1 : 0 < y - x := by linarith have h2 : x - y < 0 := by linarith rw [div_lt_iff h1] calc exp y - exp x = exp y - exp y * exp (x - y) := by rw [← exp_add]; ring_nf _ = exp y * (1 - exp (x - y)) := by ring _ < exp y * -(x - y) := by gcongr; linarith [add_one_lt_exp h2.ne] _ = exp y * (y - x) := by ring · have h1 : 0 < z - y := by linarith rw [lt_div_iff h1] calc exp y * (z - y) < exp y * (exp (z - y) - 1) := by gcongr _ * ?_ linarith [add_one_lt_exp h1.ne'] _ = exp (z - y) * exp y - exp y := by ring _ ≤ exp z - exp y := by rw [← exp_add]; ring_nf; rfl /-- `Real.exp` is convex on the whole real line. -/ theorem convexOn_exp : ConvexOn ℝ univ exp := strictConvexOn_exp.convexOn /-- `Real.log` is strictly concave on `(0, +∞)`. -/ theorem strictConcaveOn_log_Ioi : StrictConcaveOn ℝ (Ioi 0) log := by apply strictConcaveOn_of_slope_strict_anti_adjacent (convex_Ioi (0 : ℝ)) intro x y z (hx : 0 < x) (hz : 0 < z) hxy hyz have hy : 0 < y := hx.trans hxy trans y⁻¹ · have h : 0 < z - y := by linarith rw [div_lt_iff h] have hyz' : 0 < z / y := by positivity have hyz'' : z / y ≠ 1 := by contrapose! h rw [div_eq_one_iff_eq hy.ne'] at h simp [h] calc log z - log y = log (z / y) := by rw [← log_div hz.ne' hy.ne'] _ < z / y - 1 := log_lt_sub_one_of_pos hyz' hyz'' _ = y⁻¹ * (z - y) := by field_simp · have h : 0 < y - x := by linarith rw [lt_div_iff h] have hxy' : 0 < x / y := by positivity have hxy'' : x / y ≠ 1 := by contrapose! h rw [div_eq_one_iff_eq hy.ne'] at h simp [h] calc y⁻¹ * (y - x) = 1 - x / y := by field_simp _ < -log (x / y) := by linarith [log_lt_sub_one_of_pos hxy' hxy''] _ = -(log x - log y) := by rw [log_div hx.ne' hy.ne'] _ = log y - log x := by ring /-- **Bernoulli's inequality** for real exponents, strict version: for `1 < p` and `-1 ≤ s`, with `s ≠ 0`, we have `1 + p * s < (1 + s) ^ p`. -/ theorem one_add_mul_self_lt_rpow_one_add {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp : 1 < p) : 1 + p * s < (1 + s) ^ p := by have hp' : 0 < p := zero_lt_one.trans hp rcases eq_or_lt_of_le hs with rfl | hs · rwa [add_right_neg, zero_rpow hp'.ne', mul_neg_one, add_neg_lt_iff_lt_add, zero_add] have hs1 : 0 < 1 + s := neg_lt_iff_pos_add'.mp hs rcases le_or_lt (1 + p * s) 0 with hs2 | hs2 · exact hs2.trans_lt (rpow_pos_of_pos hs1 _) have hs3 : 1 + s ≠ 1 := hs' ∘ add_right_eq_self.mp have hs4 : 1 + p * s ≠ 1 := by contrapose! hs'; rwa [add_right_eq_self, mul_eq_zero, eq_false_intro hp'.ne', false_or] at hs' rw [rpow_def_of_pos hs1, ← exp_log hs2] apply exp_strictMono cases' lt_or_gt_of_ne hs' with hs' hs' · rw [← div_lt_iff hp', ← div_lt_div_right_of_neg hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs2 hs1 hs4 hs3 _ using 1 · rw [add_sub_cancel_left, log_one, sub_zero] · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · apply add_lt_add_left (mul_lt_of_one_lt_left hs' hp) · rw [← div_lt_iff hp', ← div_lt_div_right hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs1 hs2 hs3 hs4 _ using 1 · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · rw [add_sub_cancel_left, log_one, sub_zero] · apply add_lt_add_left (lt_mul_of_one_lt_left hs' hp) /-- **Bernoulli's inequality** for real exponents, non-strict version: for `1 ≤ p` and `-1 ≤ s` we have `1 + p * s ≤ (1 + s) ^ p`. -/ theorem one_add_mul_self_le_rpow_one_add {s : ℝ} (hs : -1 ≤ s) {p : ℝ} (hp : 1 ≤ p) : 1 + p * s ≤ (1 + s) ^ p := by rcases eq_or_lt_of_le hp with (rfl | hp) · simp by_cases hs' : s = 0 · simp [hs'] exact (one_add_mul_self_lt_rpow_one_add hs hs' hp).le /-- **Bernoulli's inequality** for real exponents, strict version: for `0 < p < 1` and `-1 ≤ s`, with `s ≠ 0`, we have `(1 + s) ^ p < 1 + p * s`. -/ theorem rpow_one_add_lt_one_add_mul_self {s : ℝ} (hs : -1 ≤ s) (hs' : s ≠ 0) {p : ℝ} (hp1 : 0 < p) (hp2 : p < 1) : (1 + s) ^ p < 1 + p * s := by rcases eq_or_lt_of_le hs with rfl | hs · rwa [add_right_neg, zero_rpow hp1.ne', mul_neg_one, lt_add_neg_iff_add_lt, zero_add] have hs1 : 0 < 1 + s := neg_lt_iff_pos_add'.mp hs have hs2 : 0 < 1 + p * s := by rw [← neg_lt_iff_pos_add'] rcases lt_or_gt_of_ne hs' with h | h · exact hs.trans (lt_mul_of_lt_one_left h hp2) · exact neg_one_lt_zero.trans (mul_pos hp1 h) have hs3 : 1 + s ≠ 1 := hs' ∘ add_right_eq_self.mp have hs4 : 1 + p * s ≠ 1 := by contrapose! hs'; rwa [add_right_eq_self, mul_eq_zero, eq_false_intro hp1.ne', false_or] at hs' rw [rpow_def_of_pos hs1, ← exp_log hs2] apply exp_strictMono cases' lt_or_gt_of_ne hs' with hs' hs' · rw [← lt_div_iff hp1, ← div_lt_div_right_of_neg hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs1 hs2 hs3 hs4 _ using 1 · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · rw [add_sub_cancel_left, log_one, sub_zero] · apply add_lt_add_left (lt_mul_of_lt_one_left hs' hp2) · rw [← lt_div_iff hp1, ← div_lt_div_right hs'] convert strictConcaveOn_log_Ioi.secant_strict_mono (zero_lt_one' ℝ) hs2 hs1 hs4 hs3 _ using 1 · rw [add_sub_cancel_left, log_one, sub_zero] · rw [add_sub_cancel_left, div_div, log_one, sub_zero] · apply add_lt_add_left (mul_lt_of_lt_one_left hs' hp2) /-- **Bernoulli's inequality** for real exponents, non-strict version: for `0 ≤ p ≤ 1` and `-1 ≤ s` we have `(1 + s) ^ p ≤ 1 + p * s`. -/ theorem rpow_one_add_le_one_add_mul_self {s : ℝ} (hs : -1 ≤ s) {p : ℝ} (hp1 : 0 ≤ p) (hp2 : p ≤ 1) : (1 + s) ^ p ≤ 1 + p * s := by rcases eq_or_lt_of_le hp1 with (rfl | hp1) · simp rcases eq_or_lt_of_le hp2 with (rfl | hp2) · simp by_cases hs' : s = 0 · simp [hs'] exact (rpow_one_add_lt_one_add_mul_self hs hs' hp1 hp2).le /-- For `p : ℝ` with `1 < p`, `fun x ↦ x ^ p` is strictly convex on $[0, +∞)$. -/ theorem strictConvexOn_rpow {p : ℝ} (hp : 1 < p) : StrictConvexOn ℝ (Ici 0) fun x : ℝ ↦ x ^ p := by apply strictConvexOn_of_slope_strict_mono_adjacent (convex_Ici (0 : ℝ)) intro x y z (hx : 0 ≤ x) (hz : 0 ≤ z) hxy hyz have hy : 0 < y := hx.trans_lt hxy have hy' : 0 < y ^ p := rpow_pos_of_pos hy _ trans p * y ^ (p - 1) · have q : 0 < y - x := by rwa [sub_pos] rw [div_lt_iff q, ← div_lt_div_right hy', _root_.sub_div, div_self hy'.ne', ← div_rpow hx hy.le, sub_lt_comm, ← add_sub_cancel_right (x / y) 1, add_comm, add_sub_assoc, ← div_mul_eq_mul_div, mul_div_assoc, ← rpow_sub hy, sub_sub_cancel_left, rpow_neg_one, mul_assoc, ← div_eq_inv_mul, sub_eq_add_neg, ← mul_neg, ← neg_div, neg_sub, _root_.sub_div, div_self hy.ne'] apply one_add_mul_self_lt_rpow_one_add _ _ hp · rw [le_sub_iff_add_le, add_left_neg, div_nonneg_iff] exact Or.inl ⟨hx, hy.le⟩ · rw [sub_ne_zero] exact ((div_lt_one hy).mpr hxy).ne · have q : 0 < z - y := by rwa [sub_pos] rw [lt_div_iff q, ← div_lt_div_right hy', _root_.sub_div, div_self hy'.ne', ← div_rpow hz hy.le, lt_sub_iff_add_lt', ← add_sub_cancel_right (z / y) 1, add_comm _ 1, add_sub_assoc, ← div_mul_eq_mul_div, mul_div_assoc, ← rpow_sub hy, sub_sub_cancel_left, rpow_neg_one, mul_assoc, ← div_eq_inv_mul, _root_.sub_div, div_self hy.ne'] apply one_add_mul_self_lt_rpow_one_add _ _ hp · rw [le_sub_iff_add_le, add_left_neg, div_nonneg_iff] exact Or.inl ⟨hz, hy.le⟩ · rw [sub_ne_zero] exact ((one_lt_div hy).mpr hyz).ne' theorem convexOn_rpow {p : ℝ} (hp : 1 ≤ p) : ConvexOn ℝ (Ici 0) fun x : ℝ ↦ x ^ p := by rcases eq_or_lt_of_le hp with (rfl | hp) · simpa using convexOn_id (convex_Ici _) exact (strictConvexOn_rpow hp).convexOn theorem strictConcaveOn_log_Iio : StrictConcaveOn ℝ (Iio 0) log := by refine ⟨convex_Iio _, ?_⟩ intro x (hx : x < 0) y (hy : y < 0) hxy a b ha hb hab have hx' : 0 < -x := by linarith have hy' : 0 < -y := by linarith have hxy' : -x ≠ -y := by contrapose! hxy; linarith calc a • log x + b • log y = a • log (-x) + b • log (-y) := by simp_rw [log_neg_eq_log] _ < log (a • -x + b • -y) := strictConcaveOn_log_Ioi.2 hx' hy' hxy' ha hb hab _ = log (-(a • x + b • y)) := by congr 1; simp only [Algebra.id.smul_eq_mul]; ring _ = _ := by rw [log_neg_eq_log] namespace Real lemma exp_mul_le_cosh_add_mul_sinh {t : ℝ} (ht : |t| ≤ 1) (x : ℝ) : exp (t * x) ≤ cosh x + t * sinh x := by rw [abs_le] at ht calc _ = exp ((1 + t) / 2 * x + (1 - t) / 2 * (-x)) := by ring_nf _ ≤ (1 + t) / 2 * exp x + (1 - t) / 2 * exp (-x) := convexOn_exp.2 (Set.mem_univ _) (Set.mem_univ _) (by linarith) (by linarith) <| by ring _ = _ := by rw [cosh_eq, sinh_eq]; ring end Real
Analysis\Convex\SpecificFunctions\Deriv.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.ZPow import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv import Mathlib.Analysis.Convex.Deriv /-! # Collection of convex functions In this file we prove that certain specific functions are strictly convex, including the following: * `Even.strictConvexOn_pow` : For an even `n : ℕ` with `2 ≤ n`, `fun x => x ^ n` is strictly convex. * `strictConvexOn_pow` : For `n : ℕ`, with `2 ≤ n`, `fun x => x ^ n` is strictly convex on $[0,+∞)$. * `strictConvexOn_zpow` : For `m : ℤ` with `m ≠ 0, 1`, `fun x => x ^ m` is strictly convex on $[0, +∞)$. * `strictConcaveOn_sin_Icc` : `sin` is strictly concave on $[0, π]$ * `strictConcaveOn_cos_Icc` : `cos` is strictly concave on $[-π/2, π/2]$ ## TODO These convexity lemmas are proved by checking the sign of the second derivative. If desired, most of these could also be switched to elementary proofs, like in `Analysis.Convex.SpecificFunctions.Basic`. -/ open Real Set open scoped NNReal /-- `x^n`, `n : ℕ` is strictly convex on `[0, +∞)` for all `n` greater than `2`. -/ theorem strictConvexOn_pow {n : ℕ} (hn : 2 ≤ n) : StrictConvexOn ℝ (Ici 0) fun x : ℝ => x ^ n := by apply StrictMonoOn.strictConvexOn_of_deriv (convex_Ici _) (continuousOn_pow _) rw [deriv_pow', interior_Ici] exact fun x (hx : 0 < x) y _ hxy => mul_lt_mul_of_pos_left (pow_lt_pow_left hxy hx.le <| Nat.sub_ne_zero_of_lt hn) (by positivity) /-- `x^n`, `n : ℕ` is strictly convex on the whole real line whenever `n ≠ 0` is even. -/ theorem Even.strictConvexOn_pow {n : ℕ} (hn : Even n) (h : n ≠ 0) : StrictConvexOn ℝ Set.univ fun x : ℝ => x ^ n := by apply StrictMono.strictConvexOn_univ_of_deriv (continuous_pow n) rw [deriv_pow'] replace h := Nat.pos_of_ne_zero h exact StrictMono.const_mul (Odd.strictMono_pow <| Nat.Even.sub_odd h hn <| Nat.odd_iff.2 rfl) (Nat.cast_pos.2 h) theorem Finset.prod_nonneg_of_card_nonpos_even {α β : Type*} [LinearOrderedCommRing β] {f : α → β} [DecidablePred fun x => f x ≤ 0] {s : Finset α} (h0 : Even (s.filter fun x => f x ≤ 0).card) : 0 ≤ ∏ x ∈ s, f x := calc 0 ≤ ∏ x ∈ s, (if f x ≤ 0 then (-1 : β) else 1) * f x := Finset.prod_nonneg fun x _ => by split_ifs with hx · simp [hx] simp? at hx ⊢ says simp only [not_le, one_mul] at hx ⊢ exact le_of_lt hx _ = _ := by rw [Finset.prod_mul_distrib, Finset.prod_ite, Finset.prod_const_one, mul_one, Finset.prod_const, neg_one_pow_eq_pow_mod_two, Nat.even_iff.1 h0, pow_zero, one_mul] theorem int_prod_range_nonneg (m : ℤ) (n : ℕ) (hn : Even n) : 0 ≤ ∏ k ∈ Finset.range n, (m - k) := by rcases hn with ⟨n, rfl⟩ induction' n with n ihn · simp rw [← two_mul] at ihn rw [← two_mul, mul_add, mul_one, ← one_add_one_eq_two, ← add_assoc, Finset.prod_range_succ, Finset.prod_range_succ, mul_assoc] refine mul_nonneg ihn ?_; generalize (1 + 1) * n = k rcases le_or_lt m k with hmk | hmk · have : m ≤ k + 1 := hmk.trans (lt_add_one (k : ℤ)).le convert mul_nonneg_of_nonpos_of_nonpos (sub_nonpos_of_le hmk) _ convert sub_nonpos_of_le this · exact mul_nonneg (sub_nonneg_of_le hmk.le) (sub_nonneg_of_le hmk) theorem int_prod_range_pos {m : ℤ} {n : ℕ} (hn : Even n) (hm : m ∉ Ico (0 : ℤ) n) : 0 < ∏ k ∈ Finset.range n, (m - k) := by refine (int_prod_range_nonneg m n hn).lt_of_ne fun h => hm ?_ rw [eq_comm, Finset.prod_eq_zero_iff] at h obtain ⟨a, ha, h⟩ := h rw [sub_eq_zero.1 h] exact ⟨Int.ofNat_zero_le _, Int.ofNat_lt.2 <| Finset.mem_range.1 ha⟩ /-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` except `0` and `1`. -/ theorem strictConvexOn_zpow {m : ℤ} (hm₀ : m ≠ 0) (hm₁ : m ≠ 1) : StrictConvexOn ℝ (Ioi 0) fun x : ℝ => x ^ m := by apply strictConvexOn_of_deriv2_pos' (convex_Ioi 0) · exact (continuousOn_zpow₀ m).mono fun x hx => ne_of_gt hx intro x hx rw [mem_Ioi] at hx rw [iter_deriv_zpow] refine mul_pos ?_ (zpow_pos_of_pos hx _) norm_cast refine int_prod_range_pos (by decide) fun hm => ?_ rw [← Finset.coe_Ico] at hm norm_cast at hm fin_cases hm <;> simp_all section SqrtMulLog theorem hasDerivAt_sqrt_mul_log {x : ℝ} (hx : x ≠ 0) : HasDerivAt (fun x => √x * log x) ((2 + log x) / (2 * √x)) x := by convert (hasDerivAt_sqrt hx).mul (hasDerivAt_log hx) using 1 rw [add_div, div_mul_cancel_left₀ two_ne_zero, ← div_eq_mul_inv, sqrt_div_self', add_comm, one_div, one_div, ← div_eq_inv_mul] theorem deriv_sqrt_mul_log (x : ℝ) : deriv (fun x => √x * log x) x = (2 + log x) / (2 * √x) := by cases' lt_or_le 0 x with hx hx · exact (hasDerivAt_sqrt_mul_log hx.ne').deriv · rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] refine HasDerivWithinAt.deriv_eq_zero ?_ (uniqueDiffOn_Iic 0 x hx) refine (hasDerivWithinAt_const x _ 0).congr_of_mem (fun x hx => ?_) hx rw [sqrt_eq_zero_of_nonpos hx, zero_mul] theorem deriv_sqrt_mul_log' : (deriv fun x => √x * log x) = fun x => (2 + log x) / (2 * √x) := funext deriv_sqrt_mul_log theorem deriv2_sqrt_mul_log (x : ℝ) : deriv^[2] (fun x => √x * log x) x = -log x / (4 * √x ^ 3) := by simp only [Nat.iterate, deriv_sqrt_mul_log'] rcases le_or_lt x 0 with hx | hx · rw [sqrt_eq_zero_of_nonpos hx, zero_pow three_ne_zero, mul_zero, div_zero] refine HasDerivWithinAt.deriv_eq_zero ?_ (uniqueDiffOn_Iic 0 x hx) refine (hasDerivWithinAt_const _ _ 0).congr_of_mem (fun x hx => ?_) hx rw [sqrt_eq_zero_of_nonpos hx, mul_zero, div_zero] · have h₀ : √x ≠ 0 := sqrt_ne_zero'.2 hx convert (((hasDerivAt_log hx.ne').const_add 2).div ((hasDerivAt_sqrt hx.ne').const_mul 2) <| mul_ne_zero two_ne_zero h₀).deriv using 1 nth_rw 3 [← mul_self_sqrt hx.le] generalize √x = sqx at h₀ -- else field_simp rewrites sqrt x * sqrt x back to x field_simp ring theorem strictConcaveOn_sqrt_mul_log_Ioi : StrictConcaveOn ℝ (Set.Ioi 1) fun x => √x * log x := by apply strictConcaveOn_of_deriv2_neg' (convex_Ioi 1) _ fun x hx => ?_ · exact continuous_sqrt.continuousOn.mul (continuousOn_log.mono fun x hx => ne_of_gt (zero_lt_one.trans hx)) · rw [deriv2_sqrt_mul_log x] exact div_neg_of_neg_of_pos (neg_neg_of_pos (log_pos hx)) (mul_pos four_pos (pow_pos (sqrt_pos.mpr (zero_lt_one.trans hx)) 3)) end SqrtMulLog open scoped Real theorem strictConcaveOn_sin_Icc : StrictConcaveOn ℝ (Icc 0 π) sin := by apply strictConcaveOn_of_deriv2_neg (convex_Icc _ _) continuousOn_sin fun x hx => ?_ rw [interior_Icc] at hx simp [sin_pos_of_mem_Ioo hx] theorem strictConcaveOn_cos_Icc : StrictConcaveOn ℝ (Icc (-(π / 2)) (π / 2)) cos := by apply strictConcaveOn_of_deriv2_neg (convex_Icc _ _) continuousOn_cos fun x hx => ?_ rw [interior_Icc] at hx simp [cos_pos_of_mem_Ioo hx]
Analysis\Convex\SpecificFunctions\Pow.lean
/- Copyright (c) 2023 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Convexity properties of `rpow` We prove basic convexity properties of the `rpow` function. The proofs are elementary and do not require calculus, and as such this file has only moderate dependencies. ## Main declarations * `NNReal.strictConcaveOn_rpow`, `Real.strictConcaveOn_rpow`: strict concavity of `fun x ↦ x ^ p` for p ∈ (0,1) * `NNReal.concaveOn_rpow`, `Real.concaveOn_rpow`: concavity of `fun x ↦ x ^ p` for p ∈ [0,1] Note that convexity for `p > 1` can be found in `Analysis.Convex.SpecificFunctions.Basic`, which requires slightly less imports. ## TODO * Prove convexity for negative powers. -/ open Set namespace NNReal lemma strictConcaveOn_rpow {p : ℝ} (hp₀ : 0 < p) (hp₁ : p < 1) : StrictConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by have hp₀' : 0 < 1 / p := div_pos zero_lt_one hp₀ have hp₁' : 1 < 1 / p := by rw [one_lt_div hp₀]; exact hp₁ let f := NNReal.orderIsoRpow (1 / p) hp₀' have h₁ : StrictConvexOn ℝ≥0 univ f := by refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩ exact (strictConvexOn_rpow hp₁').2 x.2 y.2 (by simp [hxy]) ha hb (by simp; norm_cast) have h₂ : ∀ x, f.symm x = x ^ p := by simp [f, NNReal.orderIsoRpow_symm_eq] refine ⟨convex_univ, fun x mx y my hxy a b ha hb hab => ?_⟩ simp only [← h₂] exact (f.strictConcaveOn_symm h₁).2 mx my hxy ha hb hab lemma concaveOn_rpow {p : ℝ} (hp₀ : 0 ≤ p) (hp₁ : p ≤ 1) : ConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by rcases eq_or_lt_of_le hp₀ with (rfl | hp₀) · simpa only [rpow_zero] using concaveOn_const (c := 1) convex_univ rcases eq_or_lt_of_le hp₁ with (rfl | hp₁) · simpa only [rpow_one] using concaveOn_id convex_univ exact (strictConcaveOn_rpow hp₀ hp₁).concaveOn lemma strictConcaveOn_sqrt : StrictConcaveOn ℝ≥0 univ NNReal.sqrt := by have : NNReal.sqrt = fun x : ℝ≥0 ↦ x ^ (1 / (2 : ℝ)) := by ext x; exact mod_cast NNReal.sqrt_eq_rpow x rw [this] exact strictConcaveOn_rpow (by positivity) (by linarith) end NNReal namespace Real open NNReal lemma strictConcaveOn_rpow {p : ℝ} (hp₀ : 0 < p) (hp₁ : p < 1) : StrictConcaveOn ℝ (Set.Ici 0) fun x : ℝ ↦ x ^ p := by refine ⟨convex_Ici _, fun x hx y hy hxy a b ha hb hab => ?_⟩ let x' : ℝ≥0 := ⟨x, hx⟩ let y' : ℝ≥0 := ⟨y, hy⟩ let a' : ℝ≥0 := ⟨a, ha.le⟩ let b' : ℝ≥0 := ⟨b, hb.le⟩ have hxy' : x' ≠ y' := Subtype.coe_ne_coe.1 hxy have hab' : a' + b' = 1 := by ext; simp [a', b', hab] exact_mod_cast (NNReal.strictConcaveOn_rpow hp₀ hp₁).2 (Set.mem_univ x') (Set.mem_univ y') hxy' (mod_cast ha) (mod_cast hb) hab' lemma concaveOn_rpow {p : ℝ} (hp₀ : 0 ≤ p) (hp₁ : p ≤ 1) : ConcaveOn ℝ (Set.Ici 0) fun x : ℝ ↦ x ^ p := by rcases eq_or_lt_of_le hp₀ with (rfl | hp₀) · simpa only [rpow_zero] using concaveOn_const (c := 1) (convex_Ici _) rcases eq_or_lt_of_le hp₁ with (rfl | hp₁) · simpa only [rpow_one] using concaveOn_id (convex_Ici _) exact (strictConcaveOn_rpow hp₀ hp₁).concaveOn lemma strictConcaveOn_sqrt : StrictConcaveOn ℝ (Set.Ici 0) (√· : ℝ → ℝ) := by rw [funext Real.sqrt_eq_rpow] exact strictConcaveOn_rpow (by positivity) (by linarith) end Real
Analysis\CStarAlgebra\Basic.lean
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Normed.Group.Hom import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Analysis.Normed.Operator.LinearIsometry import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Star.Subalgebra import Mathlib.Algebra.Star.Unitary import Mathlib.Topology.Algebra.Module.Star /-! # Normed star rings and algebras A normed star group is a normed group with a compatible `star` which is isometric. A C⋆-ring is a normed star group that is also a ring and that verifies the stronger condition `‖x‖^2 ≤ ‖x⋆ * x‖` for all `x` (which actually implies equality). If a C⋆-ring is also a star algebra, then it is a C⋆-algebra. To get a C⋆-algebra `E` over field `𝕜`, use `[NormedField 𝕜] [StarRing 𝕜] [NormedRing E] [StarRing E] [CStarRing E] [NormedAlgebra 𝕜 E] [StarModule 𝕜 E]`. ## TODO - Show that `‖x⋆ * x‖ = ‖x‖^2` is equivalent to `‖x⋆ * x‖ = ‖x⋆‖ * ‖x‖`, which is used as the definition of C*-algebras in some sources (e.g. Wikipedia). -/ open Topology local postfix:max "⋆" => star /-- A normed star group is a normed group with a compatible `star` which is isometric. -/ class NormedStarGroup (E : Type*) [SeminormedAddCommGroup E] [StarAddMonoid E] : Prop where norm_star : ∀ x : E, ‖x⋆‖ = ‖x‖ export NormedStarGroup (norm_star) attribute [simp] norm_star variable {𝕜 E α : Type*} section NormedStarGroup variable [SeminormedAddCommGroup E] [StarAddMonoid E] [NormedStarGroup E] @[simp] theorem nnnorm_star (x : E) : ‖star x‖₊ = ‖x‖₊ := Subtype.ext <| norm_star _ /-- The `star` map in a normed star group is a normed group homomorphism. -/ def starNormedAddGroupHom : NormedAddGroupHom E E := { starAddEquiv with bound' := ⟨1, fun _ => le_trans (norm_star _).le (one_mul _).symm.le⟩ } /-- The `star` map in a normed star group is an isometry -/ theorem star_isometry : Isometry (star : E → E) := show Isometry starAddEquiv from AddMonoidHomClass.isometry_of_norm starAddEquiv (show ∀ x, ‖x⋆‖ = ‖x‖ from norm_star) instance (priority := 100) NormedStarGroup.to_continuousStar : ContinuousStar E := ⟨star_isometry.continuous⟩ end NormedStarGroup instance RingHomIsometric.starRingEnd [NormedCommRing E] [StarRing E] [NormedStarGroup E] : RingHomIsometric (starRingEnd E) := ⟨@norm_star _ _ _ _⟩ /-- A C*-ring is a normed star ring that satisfies the stronger condition `‖x‖ ^ 2 ≤ ‖x⋆ * x‖` for every `x`. Note that this condition actually implies equality, as is shown in `norm_star_mul_self` below. -/ class CStarRing (E : Type*) [NonUnitalNormedRing E] [StarRing E] : Prop where norm_mul_self_le : ∀ x : E, ‖x‖ * ‖x‖ ≤ ‖x⋆ * x‖ @[deprecated (since := "2024-08-04")] alias CstarRing := CStarRing instance : CStarRing ℝ where norm_mul_self_le x := by simp only [Real.norm_eq_abs, abs_mul_abs_self, star, id, norm_mul, le_refl] namespace CStarRing section NonUnital variable [NonUnitalNormedRing E] [StarRing E] [CStarRing E] -- see Note [lower instance priority] /-- In a C*-ring, star preserves the norm. -/ instance (priority := 100) to_normedStarGroup : NormedStarGroup E := ⟨by intro x by_cases htriv : x = 0 · simp only [htriv, star_zero] · have hnt : 0 < ‖x‖ := norm_pos_iff.mpr htriv have h₁ : ∀ z : E, ‖z⋆ * z‖ ≤ ‖z⋆‖ * ‖z‖ := fun z => norm_mul_le z⋆ z have h₂ : ∀ z : E, 0 < ‖z‖ → ‖z‖ ≤ ‖z⋆‖ := fun z hz => by rw [← mul_le_mul_right hz]; exact (CStarRing.norm_mul_self_le z).trans (h₁ z) have h₃ : ‖x⋆‖ ≤ ‖x‖ := by conv_rhs => rw [← star_star x] exact h₂ x⋆ (gt_of_ge_of_gt (h₂ x hnt) hnt) exact le_antisymm h₃ (h₂ x hnt)⟩ theorem norm_star_mul_self {x : E} : ‖x⋆ * x‖ = ‖x‖ * ‖x‖ := le_antisymm ((norm_mul_le _ _).trans (by rw [norm_star])) (CStarRing.norm_mul_self_le x) theorem norm_self_mul_star {x : E} : ‖x * x⋆‖ = ‖x‖ * ‖x‖ := by nth_rw 1 [← star_star x] simp only [norm_star_mul_self, norm_star] theorem norm_star_mul_self' {x : E} : ‖x⋆ * x‖ = ‖x⋆‖ * ‖x‖ := by rw [norm_star_mul_self, norm_star] theorem nnnorm_self_mul_star {x : E} : ‖x * x⋆‖₊ = ‖x‖₊ * ‖x‖₊ := Subtype.ext norm_self_mul_star theorem nnnorm_star_mul_self {x : E} : ‖x⋆ * x‖₊ = ‖x‖₊ * ‖x‖₊ := Subtype.ext norm_star_mul_self @[simp] theorem star_mul_self_eq_zero_iff (x : E) : x⋆ * x = 0 ↔ x = 0 := by rw [← norm_eq_zero, norm_star_mul_self] exact mul_self_eq_zero.trans norm_eq_zero theorem star_mul_self_ne_zero_iff (x : E) : x⋆ * x ≠ 0 ↔ x ≠ 0 := by simp only [Ne, star_mul_self_eq_zero_iff] @[simp] theorem mul_star_self_eq_zero_iff (x : E) : x * x⋆ = 0 ↔ x = 0 := by simpa only [star_eq_zero, star_star] using @star_mul_self_eq_zero_iff _ _ _ _ (star x) theorem mul_star_self_ne_zero_iff (x : E) : x * x⋆ ≠ 0 ↔ x ≠ 0 := by simp only [Ne, mul_star_self_eq_zero_iff] end NonUnital section ProdPi variable {ι R₁ R₂ : Type*} {R : ι → Type*} variable [NonUnitalNormedRing R₁] [StarRing R₁] [CStarRing R₁] variable [NonUnitalNormedRing R₂] [StarRing R₂] [CStarRing R₂] variable [∀ i, NonUnitalNormedRing (R i)] [∀ i, StarRing (R i)] /-- This instance exists to short circuit type class resolution because of problems with inference involving Π-types. -/ instance _root_.Pi.starRing' : StarRing (∀ i, R i) := inferInstance variable [Fintype ι] [∀ i, CStarRing (R i)] instance _root_.Prod.cstarRing : CStarRing (R₁ × R₂) where norm_mul_self_le x := by dsimp only [norm] simp only [Prod.fst_mul, Prod.fst_star, Prod.snd_mul, Prod.snd_star, norm_star_mul_self, ← sq] rw [le_sup_iff] rcases le_total ‖x.fst‖ ‖x.snd‖ with (h | h) <;> simp [h] instance _root_.Pi.cstarRing : CStarRing (∀ i, R i) where norm_mul_self_le x := by refine le_of_eq (Eq.symm ?_) simp only [norm, Pi.mul_apply, Pi.star_apply, nnnorm_star_mul_self, ← sq] norm_cast exact (Finset.comp_sup_eq_sup_comp_of_is_total (fun x : NNReal => x ^ 2) (fun x y h => by simpa only [sq] using mul_le_mul' h h) (by simp)).symm instance _root_.Pi.cstarRing' : CStarRing (ι → R₁) := Pi.cstarRing end ProdPi section Unital variable [NormedRing E] [StarRing E] [CStarRing E] @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem norm_one [Nontrivial E] : ‖(1 : E)‖ = 1 := by have : 0 < ‖(1 : E)‖ := norm_pos_iff.mpr one_ne_zero rw [← mul_left_inj' this.ne', ← norm_star_mul_self, mul_one, star_one, one_mul] -- see Note [lower instance priority] instance (priority := 100) [Nontrivial E] : NormOneClass E := ⟨norm_one⟩ theorem norm_coe_unitary [Nontrivial E] (U : unitary E) : ‖(U : E)‖ = 1 := by rw [← sq_eq_sq (norm_nonneg _) zero_le_one, one_pow 2, sq, ← CStarRing.norm_star_mul_self, unitary.coe_star_mul_self, CStarRing.norm_one] @[simp] theorem norm_of_mem_unitary [Nontrivial E] {U : E} (hU : U ∈ unitary E) : ‖U‖ = 1 := norm_coe_unitary ⟨U, hU⟩ @[simp] theorem norm_coe_unitary_mul (U : unitary E) (A : E) : ‖(U : E) * A‖ = ‖A‖ := by nontriviality E refine le_antisymm ?_ ?_ · calc _ ≤ ‖(U : E)‖ * ‖A‖ := norm_mul_le _ _ _ = ‖A‖ := by rw [norm_coe_unitary, one_mul] · calc _ = ‖(U : E)⋆ * U * A‖ := by rw [unitary.coe_star_mul_self U, one_mul] _ ≤ ‖(U : E)⋆‖ * ‖(U : E) * A‖ := by rw [mul_assoc] exact norm_mul_le _ _ _ = ‖(U : E) * A‖ := by rw [norm_star, norm_coe_unitary, one_mul] @[simp] theorem norm_unitary_smul (U : unitary E) (A : E) : ‖U • A‖ = ‖A‖ := norm_coe_unitary_mul U A theorem norm_mem_unitary_mul {U : E} (A : E) (hU : U ∈ unitary E) : ‖U * A‖ = ‖A‖ := norm_coe_unitary_mul ⟨U, hU⟩ A @[simp] theorem norm_mul_coe_unitary (A : E) (U : unitary E) : ‖A * U‖ = ‖A‖ := calc _ = ‖((U : E)⋆ * A⋆)⋆‖ := by simp only [star_star, star_mul] _ = ‖(U : E)⋆ * A⋆‖ := by rw [norm_star] _ = ‖A⋆‖ := norm_mem_unitary_mul (star A) (unitary.star_mem U.prop) _ = ‖A‖ := norm_star _ theorem norm_mul_mem_unitary (A : E) {U : E} (hU : U ∈ unitary E) : ‖A * U‖ = ‖A‖ := norm_mul_coe_unitary A ⟨U, hU⟩ end Unital end CStarRing theorem IsSelfAdjoint.nnnorm_pow_two_pow [NormedRing E] [StarRing E] [CStarRing E] {x : E} (hx : IsSelfAdjoint x) (n : ℕ) : ‖x ^ 2 ^ n‖₊ = ‖x‖₊ ^ 2 ^ n := by induction' n with k hk · simp only [pow_zero, pow_one, Nat.zero_eq] · rw [pow_succ', pow_mul', sq] nth_rw 1 [← selfAdjoint.mem_iff.mp hx] rw [← star_pow, CStarRing.nnnorm_star_mul_self, ← sq, hk, pow_mul'] theorem selfAdjoint.nnnorm_pow_two_pow [NormedRing E] [StarRing E] [CStarRing E] (x : selfAdjoint E) (n : ℕ) : ‖x ^ 2 ^ n‖₊ = ‖x‖₊ ^ 2 ^ n := x.prop.nnnorm_pow_two_pow _ section starₗᵢ variable [CommSemiring 𝕜] [StarRing 𝕜] variable [SeminormedAddCommGroup E] [StarAddMonoid E] [NormedStarGroup E] variable [Module 𝕜 E] [StarModule 𝕜 E] variable (𝕜) /-- `star` bundled as a linear isometric equivalence -/ def starₗᵢ : E ≃ₗᵢ⋆[𝕜] E := { starAddEquiv with map_smul' := star_smul norm_map' := norm_star } variable {𝕜} @[simp] theorem coe_starₗᵢ : (starₗᵢ 𝕜 : E → E) = star := rfl theorem starₗᵢ_apply {x : E} : starₗᵢ 𝕜 x = star x := rfl @[simp] theorem starₗᵢ_toContinuousLinearEquiv : (starₗᵢ 𝕜 : E ≃ₗᵢ⋆[𝕜] E).toContinuousLinearEquiv = (starL 𝕜 : E ≃L⋆[𝕜] E) := ContinuousLinearEquiv.ext rfl end starₗᵢ namespace StarSubalgebra instance toNormedAlgebra {𝕜 A : Type*} [NormedField 𝕜] [StarRing 𝕜] [SeminormedRing A] [StarRing A] [NormedAlgebra 𝕜 A] [StarModule 𝕜 A] (S : StarSubalgebra 𝕜 A) : NormedAlgebra 𝕜 S := NormedAlgebra.induced 𝕜 S A S.subtype instance to_cstarRing {R A} [CommRing R] [StarRing R] [NormedRing A] [StarRing A] [CStarRing A] [Algebra R A] [StarModule R A] (S : StarSubalgebra R A) : CStarRing S where norm_mul_self_le x := @CStarRing.norm_mul_self_le A _ _ _ x end StarSubalgebra
Analysis\CStarAlgebra\Exponential.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.Normed.Algebra.Exponential /-! # The exponential map from selfadjoint to unitary In this file, we establish various properties related to the map `fun a ↦ NormedSpace.exp ℂ A (I • a)` between the subtypes `selfAdjoint A` and `unitary A`. ## TODO * Show that any exponential unitary is path-connected in `unitary A` to `1 : unitary A`. * Prove any unitary whose distance to `1 : unitary A` is less than `1` can be expressed as an exponential unitary. * A unitary is in the path component of `1` if and only if it is a finite product of exponential unitaries. -/ open NormedSpace -- For `NormedSpace.exp`. section Star variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [StarRing A] [ContinuousStar A] [CompleteSpace A] [StarModule ℂ A] open Complex /-- The map from the selfadjoint real subspace to the unitary group. This map only makes sense over ℂ. -/ @[simps] noncomputable def selfAdjoint.expUnitary (a : selfAdjoint A) : unitary A := ⟨exp ℂ ((I • a.val) : A), exp_mem_unitary_of_mem_skewAdjoint _ (a.prop.smul_mem_skewAdjoint conj_I)⟩ open selfAdjoint theorem Commute.expUnitary_add {a b : selfAdjoint A} (h : Commute (a : A) (b : A)) : expUnitary (a + b) = expUnitary a * expUnitary b := by ext have hcomm : Commute (I • (a : A)) (I • (b : A)) := by unfold Commute SemiconjBy simp only [h.eq, Algebra.smul_mul_assoc, Algebra.mul_smul_comm] simpa only [expUnitary_coe, AddSubgroup.coe_add, smul_add] using exp_add_of_commute hcomm theorem Commute.expUnitary {a b : selfAdjoint A} (h : Commute (a : A) (b : A)) : Commute (expUnitary a) (expUnitary b) := calc selfAdjoint.expUnitary a * selfAdjoint.expUnitary b = selfAdjoint.expUnitary b * selfAdjoint.expUnitary a := by rw [← h.expUnitary_add, ← h.symm.expUnitary_add, add_comm] end Star
Analysis\CStarAlgebra\GelfandDuality.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.CStarAlgebra.Spectrum import Mathlib.Analysis.Normed.Group.Quotient import Mathlib.Analysis.Normed.Algebra.Basic import Mathlib.Topology.ContinuousFunction.Units import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.ContinuousFunction.Ideals import Mathlib.Topology.ContinuousFunction.StoneWeierstrass /-! # Gelfand Duality The `gelfandTransform` is an algebra homomorphism from a topological `𝕜`-algebra `A` to `C(characterSpace 𝕜 A, 𝕜)`. In the case where `A` is a commutative complex Banach algebra, then the Gelfand transform is actually spectrum-preserving (`spectrum.gelfandTransform_eq`). Moreover, when `A` is a commutative C⋆-algebra over `ℂ`, then the Gelfand transform is a surjective isometry, and even an equivalence between C⋆-algebras. Consider the contravariant functors between compact Hausdorff spaces and commutative unital C⋆algebras `F : Cpct → CommCStarAlg := X ↦ C(X, ℂ)` and `G : CommCStarAlg → Cpct := A → characterSpace ℂ A` whose actions on morphisms are given by `WeakDual.CharacterSpace.compContinuousMap` and `ContinuousMap.compStarAlgHom'`, respectively. Then `η₁ : id → F ∘ G := gelfandStarTransform` and `η₂ : id → G ∘ F := WeakDual.CharacterSpace.homeoEval` are the natural isomorphisms implementing **Gelfand Duality**, i.e., the (contravariant) equivalence of these categories. ## Main definitions * `Ideal.toCharacterSpace` : constructs an element of the character space from a maximal ideal in a commutative complex Banach algebra * `WeakDual.CharacterSpace.compContinuousMap`: The functorial map taking `ψ : A →⋆ₐ[𝕜] B` to a continuous function `characterSpace 𝕜 B → characterSpace 𝕜 A` given by pre-composition with `ψ`. ## Main statements * `spectrum.gelfandTransform_eq` : the Gelfand transform is spectrum-preserving when the algebra is a commutative complex Banach algebra. * `gelfandTransform_isometry` : the Gelfand transform is an isometry when the algebra is a commutative (unital) C⋆-algebra over `ℂ`. * `gelfandTransform_bijective` : the Gelfand transform is bijective when the algebra is a commutative (unital) C⋆-algebra over `ℂ`. * `gelfandStarTransform_naturality`: The `gelfandStarTransform` is a natural isomorphism * `WeakDual.CharacterSpace.homeoEval_naturality`: This map implements a natural isomorphism ## TODO * After defining the category of commutative unital C⋆-algebras, bundle the existing unbundled **Gelfand duality** into an actual equivalence (duality) of categories associated to the functors `C(·, ℂ)` and `characterSpace ℂ ·` and the natural isomorphisms `gelfandStarTransform` and `WeakDual.CharacterSpace.homeoEval`. ## Tags Gelfand transform, character space, C⋆-algebra -/ open WeakDual open scoped NNReal section ComplexBanachAlgebra open Ideal variable {A : Type*} [NormedCommRing A] [NormedAlgebra ℂ A] [CompleteSpace A] (I : Ideal A) [Ideal.IsMaximal I] /-- Every maximal ideal in a commutative complex Banach algebra gives rise to a character on that algebra. In particular, the character, which may be identified as an algebra homomorphism due to `WeakDual.CharacterSpace.equivAlgHom`, is given by the composition of the quotient map and the Gelfand-Mazur isomorphism `NormedRing.algEquivComplexOfComplete`. -/ noncomputable def Ideal.toCharacterSpace : characterSpace ℂ A := CharacterSpace.equivAlgHom.symm <| ((NormedRing.algEquivComplexOfComplete (letI := Quotient.field I; isUnit_iff_ne_zero (G₀ := A ⧸ I))).symm : A ⧸ I →ₐ[ℂ] ℂ).comp <| Quotient.mkₐ ℂ I theorem Ideal.toCharacterSpace_apply_eq_zero_of_mem {a : A} (ha : a ∈ I) : I.toCharacterSpace a = 0 := by unfold Ideal.toCharacterSpace simp only [CharacterSpace.equivAlgHom_symm_coe, AlgHom.coe_comp, AlgHom.coe_coe, Quotient.mkₐ_eq_mk, Function.comp_apply, NormedRing.algEquivComplexOfComplete_symm_apply] simp_rw [Quotient.eq_zero_iff_mem.mpr ha, spectrum.zero_eq] exact Set.eq_of_mem_singleton (Set.singleton_nonempty (0 : ℂ)).some_mem /-- If `a : A` is not a unit, then some character takes the value zero at `a`. This is equivalent to `gelfandTransform ℂ A a` takes the value zero at some character. -/ theorem WeakDual.CharacterSpace.exists_apply_eq_zero {a : A} (ha : ¬IsUnit a) : ∃ f : characterSpace ℂ A, f a = 0 := by obtain ⟨M, hM, haM⟩ := (span {a}).exists_le_maximal (span_singleton_ne_top ha) exact ⟨M.toCharacterSpace, M.toCharacterSpace_apply_eq_zero_of_mem (haM (mem_span_singleton.mpr ⟨1, (mul_one a).symm⟩))⟩ theorem WeakDual.CharacterSpace.mem_spectrum_iff_exists {a : A} {z : ℂ} : z ∈ spectrum ℂ a ↔ ∃ f : characterSpace ℂ A, f a = z := by refine ⟨fun hz => ?_, ?_⟩ · obtain ⟨f, hf⟩ := WeakDual.CharacterSpace.exists_apply_eq_zero hz simp only [map_sub, sub_eq_zero, AlgHomClass.commutes] at hf exact ⟨_, hf.symm⟩ · rintro ⟨f, rfl⟩ exact AlgHom.apply_mem_spectrum f a /-- The Gelfand transform is spectrum-preserving. -/ theorem spectrum.gelfandTransform_eq (a : A) : spectrum ℂ (gelfandTransform ℂ A a) = spectrum ℂ a := by ext z rw [ContinuousMap.spectrum_eq_range, WeakDual.CharacterSpace.mem_spectrum_iff_exists] exact Iff.rfl instance [Nontrivial A] : Nonempty (characterSpace ℂ A) := ⟨Classical.choose <| WeakDual.CharacterSpace.exists_apply_eq_zero <| zero_mem_nonunits.2 zero_ne_one⟩ end ComplexBanachAlgebra section ComplexCStarAlgebra variable {A : Type*} [NormedCommRing A] [NormedAlgebra ℂ A] [CompleteSpace A] variable [StarRing A] [CStarRing A] [StarModule ℂ A] theorem gelfandTransform_map_star (a : A) : gelfandTransform ℂ A (star a) = star (gelfandTransform ℂ A a) := ContinuousMap.ext fun φ => map_star φ a variable (A) /-- The Gelfand transform is an isometry when the algebra is a C⋆-algebra over `ℂ`. -/ theorem gelfandTransform_isometry : Isometry (gelfandTransform ℂ A) := by nontriviality A refine AddMonoidHomClass.isometry_of_norm (gelfandTransform ℂ A) fun a => ?_ /- By `spectrum.gelfandTransform_eq`, the spectra of `star a * a` and its `gelfandTransform` coincide. Therefore, so do their spectral radii, and since they are self-adjoint, so also do their norms. Applying the C⋆-property of the norm and taking square roots shows that the norm is preserved. -/ have : spectralRadius ℂ (gelfandTransform ℂ A (star a * a)) = spectralRadius ℂ (star a * a) := by unfold spectralRadius; rw [spectrum.gelfandTransform_eq] rw [map_mul, (IsSelfAdjoint.star_mul_self a).spectralRadius_eq_nnnorm, gelfandTransform_map_star, (IsSelfAdjoint.star_mul_self (gelfandTransform ℂ A a)).spectralRadius_eq_nnnorm] at this simp only [ENNReal.coe_inj, CStarRing.nnnorm_star_mul_self, ← sq] at this simpa only [Function.comp_apply, NNReal.sqrt_sq] using congr_arg (((↑) : ℝ≥0 → ℝ) ∘ ⇑NNReal.sqrt) this /-- The Gelfand transform is bijective when the algebra is a C⋆-algebra over `ℂ`. -/ theorem gelfandTransform_bijective : Function.Bijective (gelfandTransform ℂ A) := by refine ⟨(gelfandTransform_isometry A).injective, ?_⟩ /- The range of `gelfandTransform ℂ A` is actually a `StarSubalgebra`. The key lemma below may be hard to spot; it's `map_star` coming from `WeakDual.Complex.instStarHomClass`, which is a nontrivial result. -/ let rng : StarSubalgebra ℂ C(characterSpace ℂ A, ℂ) := { toSubalgebra := (gelfandTransform ℂ A).range star_mem' := by rintro - ⟨a, rfl⟩ use star a ext1 φ dsimp simp only [map_star, RCLike.star_def] } suffices rng = ⊤ from fun x => show x ∈ rng from this.symm ▸ StarSubalgebra.mem_top /- Because the `gelfandTransform ℂ A` is an isometry, it has closed range, and so by the Stone-Weierstrass theorem, it suffices to show that the image of the Gelfand transform separates points in `C(characterSpace ℂ A, ℂ)` and is closed under `star`. -/ have h : rng.topologicalClosure = rng := le_antisymm (StarSubalgebra.topologicalClosure_minimal le_rfl (gelfandTransform_isometry A).closedEmbedding.isClosed_range) (StarSubalgebra.le_topologicalClosure _) refine h ▸ ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints _ (fun _ _ => ?_) /- Separating points just means that elements of the `characterSpace` which agree at all points of `A` are the same functional, which is just extensionality. -/ contrapose! exact fun h => Subtype.ext (ContinuousLinearMap.ext fun a => h (gelfandTransform ℂ A a) ⟨gelfandTransform ℂ A a, ⟨a, rfl⟩, rfl⟩) /-- The Gelfand transform as a `StarAlgEquiv` between a commutative unital C⋆-algebra over `ℂ` and the continuous functions on its `characterSpace`. -/ @[simps!] noncomputable def gelfandStarTransform : A ≃⋆ₐ[ℂ] C(characterSpace ℂ A, ℂ) := StarAlgEquiv.ofBijective (show A →⋆ₐ[ℂ] C(characterSpace ℂ A, ℂ) from { gelfandTransform ℂ A with map_star' := fun x => gelfandTransform_map_star x }) (gelfandTransform_bijective A) end ComplexCStarAlgebra section Functoriality namespace WeakDual namespace CharacterSpace variable {A B C 𝕜 : Type*} [NontriviallyNormedField 𝕜] variable [NormedRing A] [NormedAlgebra 𝕜 A] [CompleteSpace A] [StarRing A] variable [NormedRing B] [NormedAlgebra 𝕜 B] [CompleteSpace B] [StarRing B] variable [NormedRing C] [NormedAlgebra 𝕜 C] [CompleteSpace C] [StarRing C] /-- The functorial map taking `ψ : A →⋆ₐ[ℂ] B` to a continuous function `characterSpace ℂ B → characterSpace ℂ A` obtained by pre-composition with `ψ`. -/ @[simps] noncomputable def compContinuousMap (ψ : A →⋆ₐ[𝕜] B) : C(characterSpace 𝕜 B, characterSpace 𝕜 A) where toFun φ := equivAlgHom.symm ((equivAlgHom φ).comp ψ.toAlgHom) continuous_toFun := Continuous.subtype_mk (continuous_of_continuous_eval fun a => map_continuous <| gelfandTransform 𝕜 B (ψ a)) _ variable (A) /-- `WeakDual.CharacterSpace.compContinuousMap` sends the identity to the identity. -/ @[simp] theorem compContinuousMap_id : compContinuousMap (StarAlgHom.id 𝕜 A) = ContinuousMap.id (characterSpace 𝕜 A) := ContinuousMap.ext fun _a => ext fun _x => rfl variable {A} /-- `WeakDual.CharacterSpace.compContinuousMap` is functorial. -/ @[simp] theorem compContinuousMap_comp (ψ₂ : B →⋆ₐ[𝕜] C) (ψ₁ : A →⋆ₐ[𝕜] B) : compContinuousMap (ψ₂.comp ψ₁) = (compContinuousMap ψ₁).comp (compContinuousMap ψ₂) := ContinuousMap.ext fun _a => ext fun _x => rfl end CharacterSpace end WeakDual end Functoriality open CharacterSpace in /-- Consider the contravariant functors between compact Hausdorff spaces and commutative unital C⋆algebras `F : Cpct → CommCStarAlg := X ↦ C(X, ℂ)` and `G : CommCStarAlg → Cpct := A → characterSpace ℂ A` whose actions on morphisms are given by `WeakDual.CharacterSpace.compContinuousMap` and `ContinuousMap.compStarAlgHom'`, respectively. Then `η : id → F ∘ G := gelfandStarTransform` is a natural isomorphism implementing (half of) the duality between these categories. That is, for commutative unital C⋆-algebras `A` and `B` and `φ : A →⋆ₐ[ℂ] B` the following diagram commutes: ``` A --- η A ---> C(characterSpace ℂ A, ℂ) | | φ (F ∘ G) φ | | V V B --- η B ---> C(characterSpace ℂ B, ℂ) ``` -/ theorem gelfandStarTransform_naturality {A B : Type*} [NormedCommRing A] [NormedAlgebra ℂ A] [CompleteSpace A] [StarRing A] [CStarRing A] [StarModule ℂ A] [NormedCommRing B] [NormedAlgebra ℂ B] [CompleteSpace B] [StarRing B] [CStarRing B] [StarModule ℂ B] (φ : A →⋆ₐ[ℂ] B) : (gelfandStarTransform B : _ →⋆ₐ[ℂ] _).comp φ = (compContinuousMap φ |>.compStarAlgHom' ℂ ℂ).comp (gelfandStarTransform A : _ →⋆ₐ[ℂ] _) := by rfl /-- Consider the contravariant functors between compact Hausdorff spaces and commutative unital C⋆algebras `F : Cpct → CommCStarAlg := X ↦ C(X, ℂ)` and `G : CommCStarAlg → Cpct := A → characterSpace ℂ A` whose actions on morphisms are given by `WeakDual.CharacterSpace.compContinuousMap` and `ContinuousMap.compStarAlgHom'`, respectively. Then `η : id → G ∘ F := WeakDual.CharacterSpace.homeoEval` is a natural isomorphism implementing (half of) the duality between these categories. That is, for compact Hausdorff spaces `X` and `Y`, `f : C(X, Y)` the following diagram commutes: ``` X --- η X ---> characterSpace ℂ C(X, ℂ) | | f (G ∘ F) f | | V V Y --- η Y ---> characterSpace ℂ C(Y, ℂ) ``` -/ lemma WeakDual.CharacterSpace.homeoEval_naturality {X Y 𝕜 : Type*} [RCLike 𝕜] [TopologicalSpace X] [CompactSpace X] [T2Space X] [TopologicalSpace Y] [CompactSpace Y] [T2Space Y] (f : C(X, Y)) : (homeoEval Y 𝕜 : C(_, _)).comp f = (f.compStarAlgHom' 𝕜 𝕜 |> compContinuousMap).comp (homeoEval X 𝕜 : C(_, _)) := rfl
Analysis\CStarAlgebra\Matrix.lean
/- Copyright (c) 2022 Hans Parshall. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hans Parshall -/ import Mathlib.Analysis.InnerProductSpace.Adjoint import Mathlib.Analysis.Matrix import Mathlib.Analysis.RCLike.Basic import Mathlib.LinearAlgebra.UnitaryGroup import Mathlib.Topology.UniformSpace.Matrix /-! # Analytic properties of the `star` operation on matrices This transports the operator norm on `EuclideanSpace 𝕜 n →L[𝕜] EuclideanSpace 𝕜 m` to `Matrix m n 𝕜`. See the file `Analysis.Matrix` for many other matrix norms. ## Main definitions * `Matrix.instNormedRingL2Op`: the (necessarily unique) normed ring structure on `Matrix n n 𝕜` which ensure it is a `CStarRing` in `Matrix.instCStarRing`. This is a scoped instance in the namespace `Matrix.L2OpNorm` in order to avoid choosing a global norm for `Matrix`. ## Main statements * `entry_norm_bound_of_unitary`: the entries of a unitary matrix are uniformly bound by `1`. ## Implementation details We take care to ensure the topology and uniformity induced by `Matrix.instMetricSpaceL2Op` coincide with the existing topology and uniformity on matrices. ## TODO * Show that `‖diagonal (v : n → 𝕜)‖ = ‖v‖`. -/ open scoped Matrix variable {𝕜 m n l E : Type*} section EntrywiseSupNorm variable [RCLike 𝕜] [Fintype n] [DecidableEq n] theorem entry_norm_bound_of_unitary {U : Matrix n n 𝕜} (hU : U ∈ Matrix.unitaryGroup n 𝕜) (i j : n) : ‖U i j‖ ≤ 1 := by -- The norm squared of an entry is at most the L2 norm of its row. have norm_sum : ‖U i j‖ ^ 2 ≤ ∑ x, ‖U i x‖ ^ 2 := by apply Multiset.single_le_sum · intro x h_x rw [Multiset.mem_map] at h_x cases' h_x with a h_a rw [← h_a.2] apply sq_nonneg · rw [Multiset.mem_map] use j simp only [eq_self_iff_true, Finset.mem_univ_val, and_self_iff, sq_eq_sq] -- The L2 norm of a row is a diagonal entry of U * Uᴴ have diag_eq_norm_sum : (U * Uᴴ) i i = (∑ x : n, ‖U i x‖ ^ 2 : ℝ) := by simp only [Matrix.mul_apply, Matrix.conjTranspose_apply, ← starRingEnd_apply, RCLike.mul_conj, RCLike.normSq_eq_def', RCLike.ofReal_pow]; norm_cast -- The L2 norm of a row is a diagonal entry of U * Uᴴ, real part have re_diag_eq_norm_sum : RCLike.re ((U * Uᴴ) i i) = ∑ x : n, ‖U i x‖ ^ 2 := by rw [RCLike.ext_iff] at diag_eq_norm_sum rw [diag_eq_norm_sum.1] norm_cast -- Since U is unitary, the diagonal entries of U * Uᴴ are all 1 have mul_eq_one : U * Uᴴ = 1 := unitary.mul_star_self_of_mem hU have diag_eq_one : RCLike.re ((U * Uᴴ) i i) = 1 := by simp only [mul_eq_one, eq_self_iff_true, Matrix.one_apply_eq, RCLike.one_re] -- Putting it all together rw [← sq_le_one_iff (norm_nonneg (U i j)), ← diag_eq_one, re_diag_eq_norm_sum] exact norm_sum attribute [local instance] Matrix.normedAddCommGroup /-- The entrywise sup norm of a unitary matrix is at most 1. -/ theorem entrywise_sup_norm_bound_of_unitary {U : Matrix n n 𝕜} (hU : U ∈ Matrix.unitaryGroup n 𝕜) : ‖U‖ ≤ 1 := by conv => -- Porting note: was `simp_rw [pi_norm_le_iff_of_nonneg zero_le_one]` rw [pi_norm_le_iff_of_nonneg zero_le_one] intro rw [pi_norm_le_iff_of_nonneg zero_le_one] intros exact entry_norm_bound_of_unitary hU _ _ end EntrywiseSupNorm noncomputable section L2OpNorm namespace Matrix open LinearMap variable [RCLike 𝕜] variable [Fintype m] [Fintype n] [DecidableEq n] [Fintype l] [DecidableEq l] /-- The natural star algebra equivalence between matrices and continuous linear endomoporphisms of Euclidean space induced by the orthonormal basis `EuclideanSpace.basisFun`. This is a more-bundled version of `Matrix.toEuclideanLin`, for the special case of square matrices, followed by a more-bundled version of `LinearMap.toContinuousLinearMap`. -/ def toEuclideanCLM : Matrix n n 𝕜 ≃⋆ₐ[𝕜] (EuclideanSpace 𝕜 n →L[𝕜] EuclideanSpace 𝕜 n) := toMatrixOrthonormal (EuclideanSpace.basisFun n 𝕜) |>.symm.trans <| { toContinuousLinearMap with map_mul' := fun _ _ ↦ rfl map_star' := adjoint_toContinuousLinearMap } lemma coe_toEuclideanCLM_eq_toEuclideanLin (A : Matrix n n 𝕜) : (toEuclideanCLM (n := n) (𝕜 := 𝕜) A : _ →ₗ[𝕜] _) = toEuclideanLin A := rfl @[simp] lemma toEuclideanCLM_piLp_equiv_symm (A : Matrix n n 𝕜) (x : n → 𝕜) : toEuclideanCLM (n := n) (𝕜 := 𝕜) A ((WithLp.equiv _ _).symm x) = (WithLp.equiv _ _).symm (toLin' A x) := rfl @[simp] lemma piLp_equiv_toEuclideanCLM (A : Matrix n n 𝕜) (x : EuclideanSpace 𝕜 n) : WithLp.equiv _ _ (toEuclideanCLM (n := n) (𝕜 := 𝕜) A x) = toLin' A (WithLp.equiv _ _ x) := rfl /-- An auxiliary definition used only to construct the true `NormedAddCommGroup` (and `Metric`) structure provided by `Matrix.instMetricSpaceL2Op` and `Matrix.instNormedAddCommGroupL2Op`. -/ def l2OpNormedAddCommGroupAux : NormedAddCommGroup (Matrix m n 𝕜) := @NormedAddCommGroup.induced ((Matrix m n 𝕜) ≃ₗ[𝕜] (EuclideanSpace 𝕜 n →L[𝕜] EuclideanSpace 𝕜 m)) _ _ _ _ ContinuousLinearMap.toNormedAddCommGroup.toNormedAddGroup _ _ <| (toEuclideanLin.trans toContinuousLinearMap).injective /-- An auxiliary definition used only to construct the true `NormedRing` (and `Metric`) structure provided by `Matrix.instMetricSpaceL2Op` and `Matrix.instNormedRingL2Op`. -/ def l2OpNormedRingAux : NormedRing (Matrix n n 𝕜) := @NormedRing.induced ((Matrix n n 𝕜) ≃⋆ₐ[𝕜] (EuclideanSpace 𝕜 n →L[𝕜] EuclideanSpace 𝕜 n)) _ _ _ _ ContinuousLinearMap.toNormedRing _ _ toEuclideanCLM.injective open Bornology Filter open scoped Topology Uniformity /-- The metric on `Matrix m n 𝕜` arising from the operator norm given by the identification with (continuous) linear maps of `EuclideanSpace`. -/ def instL2OpMetricSpace : MetricSpace (Matrix m n 𝕜) := by /- We first replace the topology so that we can automatically replace the uniformity using `UniformAddGroup.toUniformSpace_eq`. -/ letI normed_add_comm_group : NormedAddCommGroup (Matrix m n 𝕜) := { l2OpNormedAddCommGroupAux.replaceTopology <| (toEuclideanLin (𝕜 := 𝕜) (m := m) (n := n)).trans toContinuousLinearMap |>.toContinuousLinearEquiv.toHomeomorph.inducing.induced with norm := l2OpNormedAddCommGroupAux.norm dist_eq := l2OpNormedAddCommGroupAux.dist_eq } exact normed_add_comm_group.replaceUniformity <| by congr rw [← @UniformAddGroup.toUniformSpace_eq _ (Matrix.instUniformSpace m n 𝕜) _ _] rw [@UniformAddGroup.toUniformSpace_eq _ PseudoEMetricSpace.toUniformSpace _ _] scoped[Matrix.L2OpNorm] attribute [instance] Matrix.instL2OpMetricSpace open scoped Matrix.L2OpNorm /-- The norm structure on `Matrix m n 𝕜` arising from the operator norm given by the identification with (continuous) linear maps of `EuclideanSpace`. -/ def instL2OpNormedAddCommGroup : NormedAddCommGroup (Matrix m n 𝕜) where norm := l2OpNormedAddCommGroupAux.norm dist_eq := l2OpNormedAddCommGroupAux.dist_eq scoped[Matrix.L2OpNorm] attribute [instance] Matrix.instL2OpNormedAddCommGroup lemma l2_opNorm_def (A : Matrix m n 𝕜) : ‖A‖ = ‖(toEuclideanLin (𝕜 := 𝕜) (m := m) (n := n)).trans toContinuousLinearMap A‖ := rfl @[deprecated (since := "2024-02-02")] alias l2_op_norm_def := l2_opNorm_def lemma l2_opNNNorm_def (A : Matrix m n 𝕜) : ‖A‖₊ = ‖(toEuclideanLin (𝕜 := 𝕜) (m := m) (n := n)).trans toContinuousLinearMap A‖₊ := rfl @[deprecated (since := "2024-02-02")] alias l2_op_nnnorm_def := l2_opNNNorm_def lemma l2_opNorm_conjTranspose [DecidableEq m] (A : Matrix m n 𝕜) : ‖Aᴴ‖ = ‖A‖ := by rw [l2_opNorm_def, toEuclideanLin_eq_toLin_orthonormal, LinearEquiv.trans_apply, toLin_conjTranspose, adjoint_toContinuousLinearMap] exact ContinuousLinearMap.adjoint.norm_map _ @[deprecated (since := "2024-02-02")] alias l2_op_norm_conjTranspose := l2_opNorm_conjTranspose lemma l2_opNNNorm_conjTranspose [DecidableEq m] (A : Matrix m n 𝕜) : ‖Aᴴ‖₊ = ‖A‖₊ := Subtype.ext <| l2_opNorm_conjTranspose _ @[deprecated (since := "2024-02-02")] alias l2_op_nnnorm_conjTranspose := l2_opNNNorm_conjTranspose lemma l2_opNorm_conjTranspose_mul_self (A : Matrix m n 𝕜) : ‖Aᴴ * A‖ = ‖A‖ * ‖A‖ := by classical rw [l2_opNorm_def, toEuclideanLin_eq_toLin_orthonormal, LinearEquiv.trans_apply, Matrix.toLin_mul (v₂ := (EuclideanSpace.basisFun m 𝕜).toBasis), toLin_conjTranspose] exact ContinuousLinearMap.norm_adjoint_comp_self _ @[deprecated (since := "2024-02-02")] alias l2_op_norm_conjTranspose_mul_self := l2_opNorm_conjTranspose_mul_self lemma l2_opNNNorm_conjTranspose_mul_self (A : Matrix m n 𝕜) : ‖Aᴴ * A‖₊ = ‖A‖₊ * ‖A‖₊ := Subtype.ext <| l2_opNorm_conjTranspose_mul_self _ @[deprecated (since := "2024-02-02")] alias l2_op_nnnorm_conjTranspose_mul_self := l2_opNNNorm_conjTranspose_mul_self -- note: with only a type ascription in the left-hand side, Lean picks the wrong norm. lemma l2_opNorm_mulVec (A : Matrix m n 𝕜) (x : EuclideanSpace 𝕜 n) : ‖(EuclideanSpace.equiv m 𝕜).symm <| A *ᵥ x‖ ≤ ‖A‖ * ‖x‖ := toEuclideanLin (n := n) (m := m) (𝕜 := 𝕜) |>.trans toContinuousLinearMap A |>.le_opNorm x @[deprecated (since := "2024-02-02")] alias l2_op_norm_mulVec := l2_opNorm_mulVec lemma l2_opNNNorm_mulVec (A : Matrix m n 𝕜) (x : EuclideanSpace 𝕜 n) : ‖(EuclideanSpace.equiv m 𝕜).symm <| A *ᵥ x‖₊ ≤ ‖A‖₊ * ‖x‖₊ := A.l2_opNorm_mulVec x @[deprecated (since := "2024-02-02")] alias l2_op_nnnorm_mulVec := l2_opNNNorm_mulVec lemma l2_opNorm_mul (A : Matrix m n 𝕜) (B : Matrix n l 𝕜) : ‖A * B‖ ≤ ‖A‖ * ‖B‖ := by simp only [l2_opNorm_def] have := (toEuclideanLin (n := n) (m := m) (𝕜 := 𝕜) ≪≫ₗ toContinuousLinearMap) A |>.opNorm_comp_le <| (toEuclideanLin (n := l) (m := n) (𝕜 := 𝕜) ≪≫ₗ toContinuousLinearMap) B convert this ext1 x exact congr($(Matrix.toLin'_mul A B) x) @[deprecated (since := "2024-02-02")] alias l2_op_norm_mul := l2_opNorm_mul lemma l2_opNNNorm_mul (A : Matrix m n 𝕜) (B : Matrix n l 𝕜) : ‖A * B‖₊ ≤ ‖A‖₊ * ‖B‖₊ := l2_opNorm_mul A B @[deprecated (since := "2024-02-02")] alias l2_op_nnnorm_mul := l2_opNNNorm_mul /-- The normed algebra structure on `Matrix n n 𝕜` arising from the operator norm given by the identification with (continuous) linear endmorphisms of `EuclideanSpace 𝕜 n`. -/ def instL2OpNormedSpace : NormedSpace 𝕜 (Matrix m n 𝕜) where norm_smul_le r x := by rw [l2_opNorm_def, LinearEquiv.map_smul] exact norm_smul_le r ((toEuclideanLin (𝕜 := 𝕜) (m := m) (n := n)).trans toContinuousLinearMap x) scoped[Matrix.L2OpNorm] attribute [instance] Matrix.instL2OpNormedSpace /-- The normed ring structure on `Matrix n n 𝕜` arising from the operator norm given by the identification with (continuous) linear endmorphisms of `EuclideanSpace 𝕜 n`. -/ def instL2OpNormedRing : NormedRing (Matrix n n 𝕜) where dist_eq := l2OpNormedRingAux.dist_eq norm_mul := l2OpNormedRingAux.norm_mul scoped[Matrix.L2OpNorm] attribute [instance] Matrix.instL2OpNormedRing /-- This is the same as `Matrix.l2_opNorm_def`, but with a more bundled RHS for square matrices. -/ lemma cstar_norm_def (A : Matrix n n 𝕜) : ‖A‖ = ‖toEuclideanCLM (n := n) (𝕜 := 𝕜) A‖ := rfl /-- This is the same as `Matrix.l2_opNNNorm_def`, but with a more bundled RHS for square matrices. -/ lemma cstar_nnnorm_def (A : Matrix n n 𝕜) : ‖A‖₊ = ‖toEuclideanCLM (n := n) (𝕜 := 𝕜) A‖₊ := rfl /-- The normed algebra structure on `Matrix n n 𝕜` arising from the operator norm given by the identification with (continuous) linear endmorphisms of `EuclideanSpace 𝕜 n`. -/ def instL2OpNormedAlgebra : NormedAlgebra 𝕜 (Matrix n n 𝕜) where norm_smul_le := norm_smul_le scoped[Matrix.L2OpNorm] attribute [instance] Matrix.instL2OpNormedAlgebra /-- The operator norm on `Matrix n n 𝕜` given by the identification with (continuous) linear endmorphisms of `EuclideanSpace 𝕜 n` makes it into a `L2OpRing`. -/ lemma instCStarRing : CStarRing (Matrix n n 𝕜) where norm_mul_self_le M := le_of_eq <| Eq.symm <| l2_opNorm_conjTranspose_mul_self M scoped[Matrix.L2OpNorm] attribute [instance] Matrix.instCStarRing end Matrix end L2OpNorm
Analysis\CStarAlgebra\Module.lean
/- Copyright (c) 2024 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Order /-! # Hilbert C⋆-modules A Hilbert C⋆-module is a complex module `E` together with a right `A`-module structure, where `A` is a C⋆-algebra, and with an "inner product" that takes values in `A`. This inner product satisfies the Cauchy-Schwarz inequality, and induces a norm that makes `E` a normed vector space. ## Main declarations + `CStarModule`: The class containing the Hilbert C⋆-module structure + `CStarModule.normedSpaceCore`: The proof that a Hilbert C⋆-module is a normed vector space. This can be used with `NormedAddCommGroup.ofCore` and `NormedSpace.ofCore` to create the relevant instances on a type of interest. + `CStarModule.inner_mul_inner_swap_le`: The statement that `⟪y, x⟫ * ⟪x, y⟫ ≤ ‖x‖ ^ 2 • ⟪y, y⟫`, which can be viewed as a version of the Cauchy-Schwarz inequality for Hilbert C⋆-modules. + `CStarModule.norm_inner_le`, which states that `‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖`, i.e. the Cauchy-Schwarz inequality. ## Implementation notes The class `CStarModule A E` requires `E` to already have a `Norm E` instance on it, but no other norm-related instances. We then include the fact that this norm agrees with the norm induced by the inner product among the axioms of the class. Furthermore, instead of registering `NormedAddCommGroup E` and `NormedSpace ℂ E` instances (which might already be present on the type, and which would send the type class search algorithm on a chase for `A`), we provide a `NormedSpace.Core` structure which enables downstream users of the class to easily register these instances themselves on a particular type. ## References + Erin Wittlich. *Formalizing Hilbert Modules in C⋆-algebras with the Lean Proof Assistant*, December 2022. Master's thesis, Southern Illinois University Edwardsville. -/ open scoped ComplexOrder RightActions /-- A *Hilbert C⋆-module* is a complex module `E` endowed with a right `A`-module structure (where `A` is typically a C⋆-algebra) and an inner product `⟪x, y⟫_A` which satisfies the following properties. -/ class CStarModule (A : outParam <| Type*) (E : Type*) [NonUnitalSemiring A] [StarRing A] [Module ℂ A] [AddCommGroup E] [Module ℂ E] [PartialOrder A] [SMul Aᵐᵒᵖ E] [Norm A] [Norm E] extends Inner A E where inner_add_right {x} {y} {z} : inner x (y + z) = inner x y + inner x z inner_self_nonneg {x} : 0 ≤ inner x x inner_self {x} : inner x x = 0 ↔ x = 0 inner_op_smul_right {a : A} {x y : E} : inner x (y <• a) = inner x y * a inner_smul_right_complex {z : ℂ} {x} {y} : inner x (z • y) = z • inner x y star_inner x y : star (inner x y) = inner y x norm_eq_sqrt_norm_inner_self x : ‖x‖ = √‖inner x x‖ attribute [simp] CStarModule.inner_add_right CStarModule.star_inner CStarModule.inner_op_smul_right CStarModule.inner_smul_right_complex @[deprecated (since := "2024-08-04")] alias CstarModule := CStarModule namespace CStarModule section general variable {A E : Type*} [NonUnitalRing A] [StarRing A] [AddCommGroup E] [Module ℂ A] [Module ℂ E] [PartialOrder A] [SMul Aᵐᵒᵖ E] [Norm A] [Norm E] [CStarModule A E] local notation "⟪" x ", " y "⟫" => inner (𝕜 := A) x y @[simp] lemma inner_add_left {x y z : E} : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := by rw [← star_star (r := ⟪x + y, z⟫)] simp only [inner_add_right, star_add, star_inner] @[simp] lemma inner_op_smul_left {a : A} {x y : E} : ⟪x <• a, y⟫ = star a * ⟪x, y⟫ := by rw [← star_inner]; simp section StarModule variable [StarModule ℂ A] @[simp] lemma inner_smul_left_complex {z : ℂ} {x y : E} : ⟪z • x, y⟫ = star z • ⟪x, y⟫ := by rw [← star_inner] simp @[simp] lemma inner_smul_left_real {z : ℝ} {x y : E} : ⟪z • x, y⟫ = z • ⟪x, y⟫ := by have h₁ : z • x = (z : ℂ) • x := by simp rw [h₁, ← star_inner, inner_smul_right_complex] simp @[simp] lemma inner_smul_right_real {z : ℝ} {x y : E} : ⟪x, z • y⟫ = z • ⟪x, y⟫ := by have h₁ : z • y = (z : ℂ) • y := by simp rw [h₁, ← star_inner, inner_smul_left_complex] simp /-- The function `⟨x, y⟩ ↦ ⟪x, y⟫` bundled as a sesquilinear map. -/ def innerₛₗ : E →ₗ⋆[ℂ] E →ₗ[ℂ] A where toFun x := { toFun := fun y => ⟪x, y⟫ map_add' := fun z y => by simp map_smul' := fun z y => by simp } map_add' z y := by ext; simp map_smul' z y := by ext; simp lemma innerₛₗ_apply {x y : E} : innerₛₗ x y = ⟪x, y⟫ := rfl @[simp] lemma inner_zero_right {x : E} : ⟪x, 0⟫ = 0 := by simp [← innerₛₗ_apply] @[simp] lemma inner_zero_left {x : E} : ⟪0, x⟫ = 0 := by simp [← innerₛₗ_apply] @[simp] lemma inner_neg_right {x y : E} : ⟪x, -y⟫ = -⟪x, y⟫ := by simp [← innerₛₗ_apply] @[simp] lemma inner_neg_left {x y : E} : ⟪-x, y⟫ = -⟪x, y⟫ := by simp [← innerₛₗ_apply] @[simp] lemma inner_sub_right {x y z : E} : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [← innerₛₗ_apply] @[simp] lemma inner_sub_left {x y z : E} : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [← innerₛₗ_apply] @[simp] lemma inner_sum_right {ι : Type*} {s : Finset ι} {x : E} {y : ι → E} : ⟪x, ∑ i ∈ s, y i⟫ = ∑ i ∈ s, ⟪x, y i⟫ := map_sum (innerₛₗ x) .. @[simp] lemma inner_sum_left {ι : Type*} {s : Finset ι} {x : ι → E} {y : E} : ⟪∑ i ∈ s, x i, y⟫ = ∑ i ∈ s, ⟪x i, y⟫ := map_sum (innerₛₗ.flip y) .. end StarModule @[simp] lemma isSelfAdjoint_inner_self {x : E} : IsSelfAdjoint ⟪x, x⟫ := star_inner _ _ end general section norm variable {A E : Type*} [NonUnitalNormedRing A] [StarRing A] [PartialOrder A] [AddCommGroup E] [NormedSpace ℂ A] [Module ℂ E] [SMul Aᵐᵒᵖ E] [Norm E] [CStarModule A E] local notation "⟪" x ", " y "⟫" => inner (𝕜 := A) x y variable (A) in /-- The norm associated with a Hilbert C⋆-module. It is not registered as a norm, since a type might already have a norm defined on it. -/ noncomputable def norm : Norm E where norm x := Real.sqrt ‖⟪x, x⟫‖ lemma inner_self_eq_norm_sq {x : E} : ‖⟪x, x⟫‖ = ‖x‖ ^ 2 := by simp [norm_eq_sqrt_norm_inner_self] section protected lemma norm_nonneg {x : E} : 0 ≤ ‖x‖ := by simp [norm_eq_sqrt_norm_inner_self]; positivity protected lemma norm_pos {x : E} (hx : x ≠ 0) : 0 < ‖x‖ := by simp only [norm_eq_sqrt_norm_inner_self, Real.sqrt_pos, norm_pos_iff] intro H rw [inner_self] at H exact hx H variable [StarModule ℂ A] protected lemma norm_zero : ‖(0 : E)‖ = 0 := by simp [norm_eq_sqrt_norm_inner_self] lemma norm_zero_iff (x : E) : ‖x‖ = 0 ↔ x = 0 := ⟨fun h => by simpa [norm_eq_sqrt_norm_inner_self, inner_self] using h, fun h => by simp [norm, h]; rw [CStarModule.norm_zero] ⟩ end lemma norm_sq_eq {x : E} : ‖x‖ ^ 2 = ‖⟪x, x⟫‖ := by simp [norm_eq_sqrt_norm_inner_self] variable [CStarRing A] [StarOrderedRing A] [StarModule ℂ A] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] /-- The C⋆-algebra-valued Cauchy-Schwarz inequality for Hilbert C⋆-modules. -/ lemma inner_mul_inner_swap_le [CompleteSpace A] {x y : E} : ⟪y, x⟫ * ⟪x, y⟫ ≤ ‖x‖ ^ 2 • ⟪y, y⟫ := by rcases eq_or_ne x 0 with h|h · simp [h, CStarModule.norm_zero (E := E)] · have h₁ : ∀ (a : A), (0 : A) ≤ ‖x‖ ^ 2 • (star a * a) - ‖x‖ ^ 2 • (⟪y, x⟫ * a) - ‖x‖ ^ 2 • (star a * ⟪x, y⟫) + ‖x‖ ^ 2 • (‖x‖ ^ 2 • ⟪y, y⟫) := fun a => by calc (0 : A) ≤ ⟪x <• a - ‖x‖ ^ 2 • y, x <• a - ‖x‖ ^ 2 • y⟫_A := by exact inner_self_nonneg _ = star a * ⟪x, x⟫ * a - ‖x‖ ^ 2 • (⟪y, x⟫ * a) - ‖x‖ ^ 2 • (star a * ⟪x, y⟫) + ‖x‖ ^ 2 • (‖x‖ ^ 2 • ⟪y, y⟫) := by simp only [inner_sub_right, inner_op_smul_right, inner_sub_left, inner_op_smul_left, inner_smul_left_real, sub_mul, smul_mul_assoc, inner_smul_right_real, smul_sub] abel _ ≤ ‖x‖ ^ 2 • (star a * a) - ‖x‖ ^ 2 • (⟪y, x⟫ * a) - ‖x‖ ^ 2 • (star a * ⟪x, y⟫) + ‖x‖ ^ 2 • (‖x‖ ^ 2 • ⟪y, y⟫) := by gcongr calc _ ≤ ‖⟪x, x⟫_A‖ • (star a * a) := CStarRing.conjugate_le_norm_smul _ = (Real.sqrt ‖⟪x, x⟫_A‖) ^ 2 • (star a * a) := by congr have : 0 ≤ ‖⟪x, x⟫_A‖ := by positivity rw [Real.sq_sqrt this] _ = ‖x‖ ^ 2 • (star a * a) := by rw [← norm_eq_sqrt_norm_inner_self] specialize h₁ ⟪x, y⟫ simp only [star_inner, sub_self, zero_sub, le_neg_add_iff_add_le, add_zero] at h₁ rwa [smul_le_smul_iff_of_pos_left (pow_pos (CStarModule.norm_pos h) _)] at h₁ variable (E) in /-- The Cauchy-Schwarz inequality for Hilbert C⋆-modules. -/ lemma norm_inner_le [CompleteSpace A] {x y : E} : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by have := calc ‖⟪x, y⟫‖ ^ 2 = ‖⟪y, x⟫ * ⟪x, y⟫‖ := by rw [← star_inner x, CStarRing.norm_star_mul_self, pow_two] _ ≤ ‖‖x‖^ 2 • ⟪y, y⟫‖ := by refine CStarRing.norm_le_norm_of_nonneg_of_le ?_ inner_mul_inner_swap_le rw [← star_inner x] exact star_mul_self_nonneg ⟪x, y⟫_A _ = ‖x‖ ^ 2 * ‖⟪y, y⟫‖ := by simp [norm_smul] _ = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by simp only [norm_eq_sqrt_norm_inner_self, norm_nonneg, Real.sq_sqrt] _ = (‖x‖ * ‖y‖) ^ 2 := by simp only [mul_pow] refine (pow_le_pow_iff_left (R := ℝ) (norm_nonneg ⟪x, y⟫_A) ?_ (by norm_num)).mp this exact mul_nonneg CStarModule.norm_nonneg CStarModule.norm_nonneg protected lemma norm_triangle [CompleteSpace A] (x y : E) : ‖x + y‖ ≤ ‖x‖ + ‖y‖ := by have h : ‖x + y‖ ^ 2 ≤ (‖x‖ + ‖y‖) ^ 2 := by calc _ ≤ ‖⟪x, x⟫ + ⟪y, x⟫‖ + ‖⟪x, y⟫‖ + ‖⟪y, y⟫‖ := by simp only [norm_eq_sqrt_norm_inner_self, inner_add_right, inner_add_left, ← add_assoc, norm_nonneg, Real.sq_sqrt] exact norm_add₃_le _ _ _ _ ≤ ‖⟪x, x⟫‖ + ‖⟪y, x⟫‖ + ‖⟪x, y⟫‖ + ‖⟪y, y⟫‖ := by gcongr; exact norm_add_le _ _ _ ≤ ‖⟪x, x⟫‖ + ‖y‖ * ‖x‖ + ‖x‖ * ‖y‖ + ‖⟪y, y⟫‖ := by gcongr <;> exact norm_inner_le E _ = ‖x‖ ^ 2 + ‖y‖ * ‖x‖ + ‖x‖ * ‖y‖ + ‖y‖ ^ 2 := by simp [norm_eq_sqrt_norm_inner_self] _ = (‖x‖ + ‖y‖) ^ 2 := by simp only [add_pow_two, add_left_inj]; ring refine (pow_le_pow_iff_left CStarModule.norm_nonneg ?_ (by norm_num)).mp h exact add_nonneg CStarModule.norm_nonneg CStarModule.norm_nonneg /-- This allows us to get `NormedAddCommGroup` and `NormedSpace` instances on `E` via `NormedAddCommGroup.ofCore` and `NormedSpace.ofCore`. -/ lemma normedSpaceCore [CompleteSpace A] : NormedSpace.Core ℂ E where norm_nonneg x := CStarModule.norm_nonneg norm_eq_zero_iff x := norm_zero_iff x norm_smul c x := by simp [norm_eq_sqrt_norm_inner_self, norm_smul, ← mul_assoc] norm_triangle x y := CStarModule.norm_triangle x y lemma norm_eq_csSup [CompleteSpace A] (v : E) : ‖v‖ = sSup { ‖⟪w, v⟫_A‖ | (w : E) (_ : ‖w‖ ≤ 1) } := by let instNACG : NormedAddCommGroup E := NormedAddCommGroup.ofCore normedSpaceCore let instNS : NormedSpace ℂ E := .ofCore normedSpaceCore refine Eq.symm <| IsGreatest.csSup_eq ⟨⟨‖v‖⁻¹ • v, ?_, ?_⟩, ?_⟩ · simpa only [norm_smul, norm_inv, norm_norm] using inv_mul_le_one_of_le le_rfl (by positivity) · simp [norm_smul, CStarModule.inner_self_eq_norm_sq, pow_two, ← mul_assoc] · rintro - ⟨w, hw, rfl⟩ calc _ ≤ ‖w‖ * ‖v‖ := norm_inner_le E _ ≤ 1 * ‖v‖ := by gcongr _ = ‖v‖ := by simp end norm section NormedAddCommGroup variable {A E : Type*} [NonUnitalNormedRing A] [StarRing A] [CStarRing A] [PartialOrder A] [StarOrderedRing A] [NormedSpace ℂ A] [SMul Aᵐᵒᵖ E] [CompleteSpace A] [NormedAddCommGroup E] [NormedSpace ℂ E] [StarModule ℂ A] [CStarModule A E] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] /-- The function `⟨x, y⟩ ↦ ⟪x, y⟫` bundled as a continuous sesquilinear map. -/ noncomputable def innerSL : E →L⋆[ℂ] E →L[ℂ] A := LinearMap.mkContinuous₂ (innerₛₗ : E →ₗ⋆[ℂ] E →ₗ[ℂ] A) 1 <| fun x y => by simp [innerₛₗ_apply, norm_inner_le E] lemma innerSL_apply {x y : E} : innerSL x y = ⟪x, y⟫_A := rfl @[continuity, fun_prop] lemma continuous_inner : Continuous (fun x : E × E => ⟪x.1, x.2⟫_A) := by simp_rw [← innerSL_apply] fun_prop end NormedAddCommGroup end CStarModule
Analysis\CStarAlgebra\Multiplier.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux, Jon Bannon -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Completeness import Mathlib.Analysis.CStarAlgebra.Unitization import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Multiplier Algebra of a C⋆-algebra Define the multiplier algebra of a C⋆-algebra as the algebra (over `𝕜`) of double centralizers, for which we provide the localized notation `𝓜(𝕜, A)`. A double centralizer is a pair of continuous linear maps `L R : A →L[𝕜] A` satisfying the intertwining condition `R x * y = x * L y`. There is a natural embedding `A → 𝓜(𝕜, A)` which sends `a : A` to the continuous linear maps `L R : A →L[𝕜] A` given by left and right multiplication by `a`, and we provide this map as a coercion. The multiplier algebra corresponds to a non-commutative Stone–Čech compactification in the sense that when the algebra `A` is commutative, it can be identified with `C₀(X, ℂ)` for some locally compact Hausdorff space `X`, and in that case `𝓜(𝕜, A)` can be identified with `C(β X, ℂ)`. ## Implementation notes We make the hypotheses on `𝕜` as weak as possible so that, in particular, this construction works for both `𝕜 = ℝ` and `𝕜 = ℂ`. The reader familiar with C⋆-algebra theory may recognize that one only needs `L` and `R` to be functions instead of continuous linear maps, at least when `A` is a C⋆-algebra. Our intention is simply to eventually provide a constructor for this situation. We pull back the `NormedAlgebra` structure (and everything contained therein) through the ring (even algebra) homomorphism `DoubleCentralizer.toProdMulOppositeHom : 𝓜(𝕜, A) →+* (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ` which sends `a : 𝓜(𝕜, A)` to `(a.fst, MulOpposite.op a.snd)`. The star structure is provided separately. ## References * https://en.wikipedia.org/wiki/Multiplier_algebra ## TODO + Define a type synonym for `𝓜(𝕜, A)` which is equipped with the strict uniform space structure and show it is complete + Show that the image of `A` in `𝓜(𝕜, A)` is an essential ideal + Prove the universal property of `𝓜(𝕜, A)` + Construct a double centralizer from a pair of maps (not necessarily linear or continuous) `L : A → A`, `R : A → A` satisfying the centrality condition `∀ x y, R x * y = x * L y`. + Show that if `A` is unital, then `A ≃⋆ₐ[𝕜] 𝓜(𝕜, A)`. -/ open NNReal ENNReal ContinuousLinearMap MulOpposite universe u v /-- The type of *double centralizers*, also known as the *multiplier algebra* and denoted by `𝓜(𝕜, A)`, of a non-unital normed algebra. If `x : 𝓜(𝕜, A)`, then `x.fst` and `x.snd` are what is usually referred to as $L$ and $R$. -/ structure DoubleCentralizer (𝕜 : Type u) (A : Type v) [NontriviallyNormedField 𝕜] [NonUnitalNormedRing A] [NormedSpace 𝕜 A] [SMulCommClass 𝕜 A A] [IsScalarTower 𝕜 A A] extends (A →L[𝕜] A) × (A →L[𝕜] A) where /-- The centrality condition that the maps linear maps intertwine one another. -/ central : ∀ x y : A, snd x * y = x * fst y @[inherit_doc] scoped[MultiplierAlgebra] notation "𝓜(" 𝕜 ", " A ")" => DoubleCentralizer 𝕜 A open MultiplierAlgebra -- Porting note: `ext` was generating the wrong extensionality lemma; it deconstructed the `×`. @[ext] lemma DoubleCentralizer.ext (𝕜 : Type u) (A : Type v) [NontriviallyNormedField 𝕜] [NonUnitalNormedRing A] [NormedSpace 𝕜 A] [SMulCommClass 𝕜 A A] [IsScalarTower 𝕜 A A] (a b : 𝓜(𝕜, A)) (h : a.toProd = b.toProd) : a = b := by cases a cases b simpa using h namespace DoubleCentralizer section NontriviallyNormed variable (𝕜 A : Type*) [NontriviallyNormedField 𝕜] [NonUnitalNormedRing A] variable [NormedSpace 𝕜 A] [SMulCommClass 𝕜 A A] [IsScalarTower 𝕜 A A] /-! ### Algebraic structure Because the multiplier algebra is defined as the algebra of double centralizers, there is a natural injection `DoubleCentralizer.toProdMulOpposite : 𝓜(𝕜, A) → (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ` defined by `fun a ↦ (a.fst, MulOpposite.op a.snd)`. We use this map to pull back the ring, module and algebra structure from `(A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ` to `𝓜(𝕜, A)`. -/ variable {𝕜 A} theorem range_toProd : Set.range toProd = { lr : (A →L[𝕜] A) × (A →L[𝕜] A) | ∀ x y, lr.2 x * y = x * lr.1 y } := Set.ext fun x => ⟨by rintro ⟨a, rfl⟩ exact a.central, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩ instance instAdd : Add 𝓜(𝕜, A) where add a b := { toProd := a.toProd + b.toProd central := fun x y => show (a.snd + b.snd) x * y = x * (a.fst + b.fst) y by simp only [ContinuousLinearMap.add_apply, mul_add, add_mul, central] } instance instZero : Zero 𝓜(𝕜, A) where zero := { toProd := 0 central := fun x y => (zero_mul y).trans (mul_zero x).symm } instance instNeg : Neg 𝓜(𝕜, A) where neg a := { toProd := -a.toProd central := fun x y => show -a.snd x * y = x * -a.fst y by simp only [ContinuousLinearMap.neg_apply, neg_mul, mul_neg, central] } instance instSub : Sub 𝓜(𝕜, A) where sub a b := { toProd := a.toProd - b.toProd central := fun x y => show (a.snd - b.snd) x * y = x * (a.fst - b.fst) y by simp only [ContinuousLinearMap.sub_apply, _root_.sub_mul, _root_.mul_sub, central] } section Scalars variable {S : Type*} [Monoid S] [DistribMulAction S A] [SMulCommClass 𝕜 S A] [ContinuousConstSMul S A] [IsScalarTower S A A] [SMulCommClass S A A] instance instSMul : SMul S 𝓜(𝕜, A) where smul s a := { toProd := s • a.toProd central := fun x y => show (s • a.snd) x * y = x * (s • a.fst) y by simp only [ContinuousLinearMap.smul_apply, mul_smul_comm, smul_mul_assoc, central] } @[simp] theorem smul_toProd (s : S) (a : 𝓜(𝕜, A)) : (s • a).toProd = s • a.toProd := rfl theorem smul_fst (s : S) (a : 𝓜(𝕜, A)) : (s • a).fst = s • a.fst := rfl theorem smul_snd (s : S) (a : 𝓜(𝕜, A)) : (s • a).snd = s • a.snd := rfl variable {T : Type*} [Monoid T] [DistribMulAction T A] [SMulCommClass 𝕜 T A] [ContinuousConstSMul T A] [IsScalarTower T A A] [SMulCommClass T A A] instance instIsScalarTower [SMul S T] [IsScalarTower S T A] : IsScalarTower S T 𝓜(𝕜, A) where smul_assoc _ _ a := ext (𝕜 := 𝕜) (A := A) _ _ <| smul_assoc _ _ a.toProd instance instSMulCommClass [SMulCommClass S T A] : SMulCommClass S T 𝓜(𝕜, A) where smul_comm _ _ a := ext (𝕜 := 𝕜) (A := A) _ _ <| smul_comm _ _ a.toProd instance instIsCentralScalar {R : Type*} [Semiring R] [Module R A] [SMulCommClass 𝕜 R A] [ContinuousConstSMul R A] [IsScalarTower R A A] [SMulCommClass R A A] [Module Rᵐᵒᵖ A] [IsCentralScalar R A] : IsCentralScalar R 𝓜(𝕜, A) where op_smul_eq_smul _ a := ext (𝕜 := 𝕜) (A := A) _ _ <| op_smul_eq_smul _ a.toProd end Scalars instance instOne : One 𝓜(𝕜, A) := ⟨⟨1, fun _x _y => rfl⟩⟩ instance instMul : Mul 𝓜(𝕜, A) where mul a b := { toProd := (a.fst.comp b.fst, b.snd.comp a.snd) central := fun x y => show b.snd (a.snd x) * y = x * a.fst (b.fst y) by simp only [central] } instance instNatCast : NatCast 𝓜(𝕜, A) where natCast n := ⟨n, fun x y => by rw [Prod.snd_natCast, Prod.fst_natCast] simp only [← Nat.smul_one_eq_cast, smul_apply, one_apply, mul_smul_comm, smul_mul_assoc]⟩ instance instIntCast : IntCast 𝓜(𝕜, A) where intCast n := ⟨n, fun x y => by rw [Prod.snd_intCast, Prod.fst_intCast] simp only [← Int.smul_one_eq_cast, smul_apply, one_apply, mul_smul_comm, smul_mul_assoc]⟩ instance instPow : Pow 𝓜(𝕜, A) ℕ where pow a n := ⟨a.toProd ^ n, fun x y => by induction' n with k hk generalizing x y · rfl · rw [Prod.pow_snd, Prod.pow_fst] at hk ⊢ rw [pow_succ' a.snd, mul_apply, a.central, hk, pow_succ a.fst, mul_apply]⟩ instance instInhabited : Inhabited 𝓜(𝕜, A) := ⟨0⟩ @[simp] theorem add_toProd (a b : 𝓜(𝕜, A)) : (a + b).toProd = a.toProd + b.toProd := rfl @[simp] theorem zero_toProd : (0 : 𝓜(𝕜, A)).toProd = 0 := rfl @[simp] theorem neg_toProd (a : 𝓜(𝕜, A)) : (-a).toProd = -a.toProd := rfl @[simp] theorem sub_toProd (a b : 𝓜(𝕜, A)) : (a - b).toProd = a.toProd - b.toProd := rfl @[simp] theorem one_toProd : (1 : 𝓜(𝕜, A)).toProd = 1 := rfl @[simp] theorem natCast_toProd (n : ℕ) : (n : 𝓜(𝕜, A)).toProd = n := rfl @[deprecated (since := "2024-04-17")] alias nat_cast_toProd := natCast_toProd @[simp] theorem intCast_toProd (n : ℤ) : (n : 𝓜(𝕜, A)).toProd = n := rfl @[deprecated (since := "2024-04-17")] alias int_cast_toProd := intCast_toProd @[simp] theorem pow_toProd (n : ℕ) (a : 𝓜(𝕜, A)) : (a ^ n).toProd = a.toProd ^ n := rfl theorem add_fst (a b : 𝓜(𝕜, A)) : (a + b).fst = a.fst + b.fst := rfl theorem add_snd (a b : 𝓜(𝕜, A)) : (a + b).snd = a.snd + b.snd := rfl theorem zero_fst : (0 : 𝓜(𝕜, A)).fst = 0 := rfl theorem zero_snd : (0 : 𝓜(𝕜, A)).snd = 0 := rfl theorem neg_fst (a : 𝓜(𝕜, A)) : (-a).fst = -a.fst := rfl theorem neg_snd (a : 𝓜(𝕜, A)) : (-a).snd = -a.snd := rfl theorem sub_fst (a b : 𝓜(𝕜, A)) : (a - b).fst = a.fst - b.fst := rfl theorem sub_snd (a b : 𝓜(𝕜, A)) : (a - b).snd = a.snd - b.snd := rfl theorem one_fst : (1 : 𝓜(𝕜, A)).fst = 1 := rfl theorem one_snd : (1 : 𝓜(𝕜, A)).snd = 1 := rfl @[simp] theorem mul_fst (a b : 𝓜(𝕜, A)) : (a * b).fst = a.fst * b.fst := rfl @[simp] theorem mul_snd (a b : 𝓜(𝕜, A)) : (a * b).snd = b.snd * a.snd := rfl theorem natCast_fst (n : ℕ) : (n : 𝓜(𝕜, A)).fst = n := rfl @[deprecated (since := "2024-04-17")] alias nat_cast_fst := natCast_fst theorem natCast_snd (n : ℕ) : (n : 𝓜(𝕜, A)).snd = n := rfl @[deprecated (since := "2024-04-17")] alias nat_cast_snd := natCast_snd theorem intCast_fst (n : ℤ) : (n : 𝓜(𝕜, A)).fst = n := rfl @[deprecated (since := "2024-04-17")] alias int_cast_fst := intCast_fst theorem intCast_snd (n : ℤ) : (n : 𝓜(𝕜, A)).snd = n := rfl @[deprecated (since := "2024-04-17")] alias int_cast_snd := intCast_snd theorem pow_fst (n : ℕ) (a : 𝓜(𝕜, A)) : (a ^ n).fst = a.fst ^ n := rfl theorem pow_snd (n : ℕ) (a : 𝓜(𝕜, A)) : (a ^ n).snd = a.snd ^ n := rfl /-- The natural injection from `DoubleCentralizer.toProd` except the second coordinate inherits `MulOpposite.op`. The ring structure on `𝓜(𝕜, A)` is the pullback under this map. -/ def toProdMulOpposite : 𝓜(𝕜, A) → (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ := fun a => (a.fst, MulOpposite.op a.snd) theorem toProdMulOpposite_injective : Function.Injective (toProdMulOpposite : 𝓜(𝕜, A) → (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ) := fun _a _b h => let h' := Prod.ext_iff.mp h ext (𝕜 := 𝕜) (A := A) _ _ <| Prod.ext h'.1 <| MulOpposite.op_injective h'.2 theorem range_toProdMulOpposite : Set.range toProdMulOpposite = { lr : (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ | ∀ x y, unop lr.2 x * y = x * lr.1 y } := Set.ext fun x => ⟨by rintro ⟨a, rfl⟩ exact a.central, fun hx => ⟨⟨(x.1, unop x.2), hx⟩, Prod.ext rfl rfl⟩⟩ /-- The ring structure is inherited as the pullback under the injective map `DoubleCentralizer.toProdMulOpposite : 𝓜(𝕜, A) → (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ` -/ instance instRing : Ring 𝓜(𝕜, A) := toProdMulOpposite_injective.ring _ rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _x _n => Prod.ext rfl <| MulOpposite.op_smul _ _) (fun _x _n => Prod.ext rfl <| MulOpposite.op_smul _ _) (fun _x _n => Prod.ext rfl <| MulOpposite.op_pow _ _) (fun _ => rfl) fun _ => rfl /-- The canonical map `DoubleCentralizer.toProd` as an additive group homomorphism. -/ @[simps] def toProdHom : 𝓜(𝕜, A) →+ (A →L[𝕜] A) × (A →L[𝕜] A) where toFun := toProd map_zero' := rfl map_add' _x _y := rfl /-- The canonical map `DoubleCentralizer.toProdMulOpposite` as a ring homomorphism. -/ @[simps] def toProdMulOppositeHom : 𝓜(𝕜, A) →+* (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ where toFun := toProdMulOpposite map_zero' := rfl map_one' := rfl map_add' _x _y := rfl map_mul' _x _y := rfl /-- The module structure is inherited as the pullback under the additive group monomorphism `DoubleCentralizer.toProd : 𝓜(𝕜, A) →+ (A →L[𝕜] A) × (A →L[𝕜] A)` -/ instance instModule {S : Type*} [Semiring S] [Module S A] [SMulCommClass 𝕜 S A] [ContinuousConstSMul S A] [IsScalarTower S A A] [SMulCommClass S A A] : Module S 𝓜(𝕜, A) := Function.Injective.module S toProdHom (ext (𝕜 := 𝕜) (A := A)) fun _x _y => rfl -- TODO: generalize to `Algebra S 𝓜(𝕜, A)` once `ContinuousLinearMap.algebra` is generalized. instance instAlgebra : Algebra 𝕜 𝓜(𝕜, A) where toFun k := { toProd := algebraMap 𝕜 ((A →L[𝕜] A) × (A →L[𝕜] A)) k central := fun x y => by simp_rw [Prod.algebraMap_apply, Algebra.algebraMap_eq_smul_one, smul_apply, one_apply, mul_smul_comm, smul_mul_assoc] } map_one' := ext (𝕜 := 𝕜) (A := A) _ _ <| map_one <| algebraMap 𝕜 ((A →L[𝕜] A) × (A →L[𝕜] A)) map_mul' k₁ k₂ := ext (𝕜 := 𝕜) (A := A) _ _ <| Prod.ext (map_mul (algebraMap 𝕜 (A →L[𝕜] A)) _ _) ((map_mul (algebraMap 𝕜 (A →L[𝕜] A)) _ _).trans (Algebra.commutes _ _)) map_zero' := ext (𝕜 := 𝕜) (A := A) _ _ <| map_zero <| algebraMap 𝕜 ((A →L[𝕜] A) × (A →L[𝕜] A)) map_add' _ _ := ext (𝕜 := 𝕜) (A := A) _ _ <| map_add (algebraMap 𝕜 ((A →L[𝕜] A) × (A →L[𝕜] A))) _ _ commutes' _ _ := ext (𝕜 := 𝕜) (A := A) _ _ <| Prod.ext (Algebra.commutes _ _) (Algebra.commutes _ _).symm smul_def' _ _ := ext (𝕜 := 𝕜) (A := A) _ _ <| Prod.ext (Algebra.smul_def _ _) ((Algebra.smul_def _ _).trans <| Algebra.commutes _ _) @[simp] theorem algebraMap_toProd (k : 𝕜) : (algebraMap 𝕜 𝓜(𝕜, A) k).toProd = algebraMap 𝕜 _ k := rfl theorem algebraMap_fst (k : 𝕜) : (algebraMap 𝕜 𝓜(𝕜, A) k).fst = algebraMap 𝕜 _ k := rfl theorem algebraMap_snd (k : 𝕜) : (algebraMap 𝕜 𝓜(𝕜, A) k).snd = algebraMap 𝕜 _ k := rfl /-! ### Star structure -/ section Star variable [StarRing 𝕜] [StarRing A] [StarModule 𝕜 A] [NormedStarGroup A] /-- The star operation on `a : 𝓜(𝕜, A)` is given by `(star a).toProd = (star ∘ a.snd ∘ star, star ∘ a.fst ∘ star)`. -/ instance instStar : Star 𝓜(𝕜, A) where star a := { fst := (((starₗᵢ 𝕜 : A ≃ₗᵢ⋆[𝕜] A) : A →L⋆[𝕜] A).comp a.snd).comp ((starₗᵢ 𝕜 : A ≃ₗᵢ⋆[𝕜] A) : A →L⋆[𝕜] A) snd := (((starₗᵢ 𝕜 : A ≃ₗᵢ⋆[𝕜] A) : A →L⋆[𝕜] A).comp a.fst).comp ((starₗᵢ 𝕜 : A ≃ₗᵢ⋆[𝕜] A) : A →L⋆[𝕜] A) central := fun x y => by simpa only [star_mul, star_star] using (congr_arg star (a.central (star y) (star x))).symm } @[simp] theorem star_fst (a : 𝓜(𝕜, A)) (b : A) : (star a).fst b = star (a.snd (star b)) := rfl @[simp] theorem star_snd (a : 𝓜(𝕜, A)) (b : A) : (star a).snd b = star (a.fst (star b)) := rfl instance instStarAddMonoid : StarAddMonoid 𝓜(𝕜, A) := { DoubleCentralizer.instStar with star_involutive := fun x => by ext <;> simp only [star_fst, star_snd, star_star] star_add := fun x y => by ext <;> simp only [star_fst, star_snd, add_fst, add_snd, ContinuousLinearMap.add_apply, star_add] } instance instStarRing : StarRing 𝓜(𝕜, A) := { DoubleCentralizer.instStarAddMonoid with star_mul := fun a b => by ext <;> simp only [star_fst, star_snd, mul_fst, mul_snd, star_star, ContinuousLinearMap.coe_mul, Function.comp_apply] } instance instStarModule : StarModule 𝕜 𝓜(𝕜, A) := { DoubleCentralizer.instStarAddMonoid (𝕜 := 𝕜) (A := A) with star_smul := fun k a => by ext <;> exact star_smul _ _ } end Star /-! ### Coercion from an algebra into its multiplier algebra -/ variable (𝕜) /-- The natural coercion of `A` into `𝓜(𝕜, A)` given by sending `a : A` to the pair of linear maps `Lₐ Rₐ : A →L[𝕜] A` given by left- and right-multiplication by `a`, respectively. Warning: if `A = 𝕜`, then this is a coercion which is not definitionally equal to the `algebraMap 𝕜 𝓜(𝕜, 𝕜)` coercion, but these are propositionally equal. See `DoubleCentralizer.coe_eq_algebraMap` below. -/ -- Porting note: added `noncomputable`; IR check does not recognise `ContinuousLinearMap.mul` @[coe] protected noncomputable def coe (a : A) : 𝓜(𝕜, A) := { fst := ContinuousLinearMap.mul 𝕜 A a snd := (ContinuousLinearMap.mul 𝕜 A).flip a central := fun _x _y => mul_assoc _ _ _ } variable {𝕜} /-- The natural coercion of `A` into `𝓜(𝕜, A)` given by sending `a : A` to the pair of linear maps `Lₐ Rₐ : A →L[𝕜] A` given by left- and right-multiplication by `a`, respectively. Warning: if `A = 𝕜`, then this is a coercion which is not definitionally equal to the `algebraMap 𝕜 𝓜(𝕜, 𝕜)` coercion, but these are propositionally equal. See `DoubleCentralizer.coe_eq_algebraMap` below. -/ noncomputable instance : CoeTC A 𝓜(𝕜, A) where coe := DoubleCentralizer.coe 𝕜 @[simp, norm_cast] theorem coe_fst (a : A) : (a : 𝓜(𝕜, A)).fst = ContinuousLinearMap.mul 𝕜 A a := rfl @[simp, norm_cast] theorem coe_snd (a : A) : (a : 𝓜(𝕜, A)).snd = (ContinuousLinearMap.mul 𝕜 A).flip a := rfl theorem coe_eq_algebraMap : (DoubleCentralizer.coe 𝕜 : 𝕜 → 𝓜(𝕜, 𝕜)) = algebraMap 𝕜 𝓜(𝕜, 𝕜) := by ext x : 3 · rfl -- `fst` is defeq · refine ContinuousLinearMap.ext fun y => ?_ exact mul_comm y x -- `snd` multiplies on the wrong side /-- The coercion of an algebra into its multiplier algebra as a non-unital star algebra homomorphism. -/ @[simps] noncomputable def coeHom [StarRing 𝕜] [StarRing A] [StarModule 𝕜 A] [NormedStarGroup A] : A →⋆ₙₐ[𝕜] 𝓜(𝕜, A) where toFun a := a map_smul' _ _ := ext _ _ _ _ <| Prod.ext (map_smul _ _ _) (map_smul _ _ _) map_zero' := ext _ _ _ _ <| Prod.ext (map_zero _) (map_zero _) map_add' _ _ := ext _ _ _ _ <| Prod.ext (map_add _ _ _) (map_add _ _ _) map_mul' _ _ := ext _ _ _ _ <| Prod.ext (ContinuousLinearMap.ext fun _ => (mul_assoc _ _ _)) (ContinuousLinearMap.ext fun _ => (mul_assoc _ _ _).symm) map_star' _ := ext _ _ _ _ <| Prod.ext (ContinuousLinearMap.ext fun _ => (star_star_mul _ _).symm) (ContinuousLinearMap.ext fun _ => (star_mul_star _ _).symm) /-! ### Norm structures We define the norm structure on `𝓜(𝕜, A)` as the pullback under `DoubleCentralizer.toProdMulOppositeHom : 𝓜(𝕜, A) →+* (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ`, which provides a definitional isometric embedding. Consequently, completeness of `𝓜(𝕜, A)` is obtained by proving that the range of this map is closed. In addition, we prove that `𝓜(𝕜, A)` is a normed algebra, and, when `A` is a C⋆-algebra, we show that `𝓜(𝕜, A)` is also a C⋆-algebra. Moreover, in this case, for `a : 𝓜(𝕜, A)`, `‖a‖ = ‖a.fst‖ = ‖a.snd‖`. -/ /-- The normed group structure is inherited as the pullback under the ring monomorphism `DoubleCentralizer.toProdMulOppositeHom : 𝓜(𝕜, A) →+* (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ`. -/ noncomputable instance : NormedRing 𝓜(𝕜, A) := NormedRing.induced _ _ (toProdMulOppositeHom : 𝓜(𝕜, A) →+* (A →L[𝕜] A) × (A →L[𝕜] A)ᵐᵒᵖ) (by simpa using toProdMulOpposite_injective) -- even though the definition is actually in terms of `DoubleCentralizer.toProdMulOpposite`, we -- choose to see through that here to avoid `MulOpposite.op` appearing. theorem norm_def (a : 𝓜(𝕜, A)) : ‖a‖ = ‖toProdHom a‖ := rfl theorem nnnorm_def (a : 𝓜(𝕜, A)) : ‖a‖₊ = ‖toProdHom a‖₊ := rfl theorem norm_def' (a : 𝓜(𝕜, A)) : ‖a‖ = ‖toProdMulOppositeHom a‖ := rfl theorem nnnorm_def' (a : 𝓜(𝕜, A)) : ‖a‖₊ = ‖toProdMulOppositeHom a‖₊ := rfl instance instNormedSpace : NormedSpace 𝕜 𝓜(𝕜, A) := { DoubleCentralizer.instModule with norm_smul_le := fun k a => (norm_smul_le k a.toProdMulOpposite : _) } instance instNormedAlgebra : NormedAlgebra 𝕜 𝓜(𝕜, A) := { DoubleCentralizer.instAlgebra, DoubleCentralizer.instNormedSpace with } theorem uniformEmbedding_toProdMulOpposite : UniformEmbedding (@toProdMulOpposite 𝕜 A _ _ _ _ _) := uniformEmbedding_comap toProdMulOpposite_injective instance [CompleteSpace A] : CompleteSpace 𝓜(𝕜, A) := by rw [completeSpace_iff_isComplete_range uniformEmbedding_toProdMulOpposite.toUniformInducing] apply IsClosed.isComplete simp only [range_toProdMulOpposite, Set.setOf_forall] refine isClosed_iInter fun x => isClosed_iInter fun y => isClosed_eq ?_ ?_ · exact ((ContinuousLinearMap.apply 𝕜 A _).continuous.comp <| continuous_unop.comp continuous_snd).mul continuous_const exact continuous_const.mul ((ContinuousLinearMap.apply 𝕜 A _).continuous.comp continuous_fst) variable [StarRing A] [CStarRing A] /-- For `a : 𝓜(𝕜, A)`, the norms of `a.fst` and `a.snd` coincide, and hence these also coincide with `‖a‖` which is `max (‖a.fst‖) (‖a.snd‖)`. -/ theorem norm_fst_eq_snd (a : 𝓜(𝕜, A)) : ‖a.fst‖ = ‖a.snd‖ := by -- a handy lemma for this proof have h0 : ∀ f : A →L[𝕜] A, ∀ C : ℝ≥0, (∀ b : A, ‖f b‖₊ ^ 2 ≤ C * ‖f b‖₊ * ‖b‖₊) → ‖f‖₊ ≤ C := by intro f C h have h1 : ∀ b, C * ‖f b‖₊ * ‖b‖₊ ≤ C * ‖f‖₊ * ‖b‖₊ ^ 2 := by intro b convert mul_le_mul_right' (mul_le_mul_left' (f.le_opNNNorm b) C) ‖b‖₊ using 1 ring have := NNReal.div_le_of_le_mul $ f.opNNNorm_le_bound _ $ by simpa only [sqrt_sq, sqrt_mul] using fun b ↦ sqrt_le_sqrt.2 $ (h b).trans (h1 b) convert NNReal.rpow_le_rpow this two_pos.le · simp only [NNReal.rpow_two, div_pow, sq_sqrt] simp only [sq, mul_self_div_self] · simp only [NNReal.rpow_two, sq_sqrt] have h1 : ∀ b, ‖a.fst b‖₊ ^ 2 ≤ ‖a.snd‖₊ * ‖a.fst b‖₊ * ‖b‖₊ := by intro b calc ‖a.fst b‖₊ ^ 2 = ‖star (a.fst b) * a.fst b‖₊ := by simpa only [← sq] using CStarRing.nnnorm_star_mul_self.symm _ ≤ ‖a.snd (star (a.fst b))‖₊ * ‖b‖₊ := (a.central (star (a.fst b)) b ▸ nnnorm_mul_le _ _) _ ≤ ‖a.snd‖₊ * ‖a.fst b‖₊ * ‖b‖₊ := nnnorm_star (a.fst b) ▸ mul_le_mul_right' (a.snd.le_opNNNorm _) _ have h2 : ∀ b, ‖a.snd b‖₊ ^ 2 ≤ ‖a.fst‖₊ * ‖a.snd b‖₊ * ‖b‖₊ := by intro b calc ‖a.snd b‖₊ ^ 2 = ‖a.snd b * star (a.snd b)‖₊ := by simpa only [← sq] using CStarRing.nnnorm_self_mul_star.symm _ ≤ ‖b‖₊ * ‖a.fst (star (a.snd b))‖₊ := ((a.central b (star (a.snd b))).symm ▸ nnnorm_mul_le _ _) _ = ‖a.fst (star (a.snd b))‖₊ * ‖b‖₊ := mul_comm _ _ _ ≤ ‖a.fst‖₊ * ‖a.snd b‖₊ * ‖b‖₊ := nnnorm_star (a.snd b) ▸ mul_le_mul_right' (a.fst.le_opNNNorm _) _ exact le_antisymm (h0 _ _ h1) (h0 _ _ h2) theorem nnnorm_fst_eq_snd (a : 𝓜(𝕜, A)) : ‖a.fst‖₊ = ‖a.snd‖₊ := Subtype.ext <| norm_fst_eq_snd a @[simp] theorem norm_fst (a : 𝓜(𝕜, A)) : ‖a.fst‖ = ‖a‖ := by simp only [norm_def, toProdHom_apply, Prod.norm_def, norm_fst_eq_snd, max_eq_right le_rfl] @[simp] theorem norm_snd (a : 𝓜(𝕜, A)) : ‖a.snd‖ = ‖a‖ := by rw [← norm_fst, norm_fst_eq_snd] @[simp] theorem nnnorm_fst (a : 𝓜(𝕜, A)) : ‖a.fst‖₊ = ‖a‖₊ := Subtype.ext (norm_fst a) @[simp] theorem nnnorm_snd (a : 𝓜(𝕜, A)) : ‖a.snd‖₊ = ‖a‖₊ := Subtype.ext (norm_snd a) end NontriviallyNormed section DenselyNormed variable {𝕜 A : Type*} [DenselyNormedField 𝕜] [StarRing 𝕜] variable [NonUnitalNormedRing A] [StarRing A] [CStarRing A] variable [NormedSpace 𝕜 A] [SMulCommClass 𝕜 A A] [IsScalarTower 𝕜 A A] [StarModule 𝕜 A] instance instCStarRing : CStarRing 𝓜(𝕜, A) where norm_mul_self_le := fun (a : 𝓜(𝕜, A)) => le_of_eq <| Eq.symm <| congr_arg ((↑) : ℝ≥0 → ℝ) <| show ‖star a * a‖₊ = ‖a‖₊ * ‖a‖₊ by /- The essence of the argument is this: let `a = (L,R)` and recall `‖a‖ = ‖L‖`. `star a = (star ∘ R ∘ star, star ∘ L ∘ star)`. Then for any `x y : A`, we have `‖star a * a‖ = ‖(star a * a).snd‖ = ‖R (star (L (star x))) * y‖ = ‖star (L (star x)) * L y‖` Now, on the one hand, `‖star (L (star x)) * L y‖ ≤ ‖star (L (star x))‖ * ‖L y‖ = ‖L (star x)‖ * ‖L y‖ ≤ ‖L‖ ^ 2` whenever `‖x‖, ‖y‖ ≤ 1`, so the supremum over all such `x, y` is at most `‖L‖ ^ 2`. On the other hand, for any `‖z‖ ≤ 1`, we may choose `x := star z` and `y := z` to get: `‖star (L (star x)) * L y‖ = ‖star (L z) * (L z)‖ = ‖L z‖ ^ 2`, and taking the supremum over all such `z` yields that the supremum is at least `‖L‖ ^ 2`. It is the latter part of the argument where `DenselyNormedField 𝕜` is required (for `sSup_closed_unit_ball_eq_nnnorm`). -/ have hball : (Metric.closedBall (0 : A) 1).Nonempty := Metric.nonempty_closedBall.2 zero_le_one have key : ∀ x y, ‖x‖₊ ≤ 1 → ‖y‖₊ ≤ 1 → ‖a.snd (star (a.fst (star x))) * y‖₊ ≤ ‖a‖₊ * ‖a‖₊ := by intro x y hx hy rw [a.central] calc ‖star (a.fst (star x)) * a.fst y‖₊ ≤ ‖a.fst (star x)‖₊ * ‖a.fst y‖₊ := nnnorm_star (a.fst (star x)) ▸ nnnorm_mul_le _ _ _ ≤ ‖a.fst‖₊ * 1 * (‖a.fst‖₊ * 1) := (mul_le_mul' (a.fst.le_opNorm_of_le ((nnnorm_star x).trans_le hx)) (a.fst.le_opNorm_of_le hy)) _ ≤ ‖a‖₊ * ‖a‖₊ := by simp only [mul_one, nnnorm_fst, le_rfl] rw [← nnnorm_snd] simp only [mul_snd, ← sSup_closed_unit_ball_eq_nnnorm, star_snd, mul_apply] simp only [← @opNNNorm_mul_apply 𝕜 _ A] simp only [← sSup_closed_unit_ball_eq_nnnorm, mul_apply'] refine csSup_eq_of_forall_le_of_forall_lt_exists_gt (hball.image _) ?_ fun r hr => ?_ · rintro - ⟨x, hx, rfl⟩ refine csSup_le (hball.image _) ?_ rintro - ⟨y, hy, rfl⟩ exact key x y (mem_closedBall_zero_iff.1 hx) (mem_closedBall_zero_iff.1 hy) · simp only [Set.mem_image, Set.mem_setOf_eq, exists_prop, exists_exists_and_eq_and] have hr' : NNReal.sqrt r < ‖a‖₊ := ‖a‖₊.sqrt_mul_self ▸ NNReal.sqrt_lt_sqrt.2 hr simp_rw [← nnnorm_fst, ← sSup_closed_unit_ball_eq_nnnorm] at hr' obtain ⟨_, ⟨x, hx, rfl⟩, hxr⟩ := exists_lt_of_lt_csSup (hball.image _) hr' have hx' : ‖x‖₊ ≤ 1 := mem_closedBall_zero_iff.1 hx refine ⟨star x, mem_closedBall_zero_iff.2 ((nnnorm_star x).trans_le hx'), ?_⟩ refine lt_csSup_of_lt ?_ ⟨x, hx, rfl⟩ ?_ · refine ⟨‖a‖₊ * ‖a‖₊, ?_⟩ rintro - ⟨y, hy, rfl⟩ exact key (star x) y ((nnnorm_star x).trans_le hx') (mem_closedBall_zero_iff.1 hy) · simpa only [a.central, star_star, CStarRing.nnnorm_star_mul_self, NNReal.sq_sqrt, ← sq] using pow_lt_pow_left hxr zero_le' two_ne_zero end DenselyNormed end DoubleCentralizer
Analysis\CStarAlgebra\Spectrum.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.CStarAlgebra.Basic import Mathlib.Analysis.Normed.Algebra.Spectrum import Mathlib.Analysis.SpecialFunctions.Exponential import Mathlib.Algebra.Star.StarAlgHom /-! # Spectral properties in C⋆-algebras In this file, we establish various properties related to the spectrum of elements in C⋆-algebras. -/ local postfix:max "⋆" => star section open scoped Topology ENNReal open Filter ENNReal spectrum CStarRing NormedSpace section UnitarySpectrum variable {𝕜 : Type*} [NormedField 𝕜] {E : Type*} [NormedRing E] [StarRing E] [CStarRing E] [NormedAlgebra 𝕜 E] [CompleteSpace E] theorem unitary.spectrum_subset_circle (u : unitary E) : spectrum 𝕜 (u : E) ⊆ Metric.sphere 0 1 := by nontriviality E refine fun k hk => mem_sphere_zero_iff_norm.mpr (le_antisymm ?_ ?_) · simpa only [CStarRing.norm_coe_unitary u] using norm_le_norm_of_mem hk · rw [← unitary.val_toUnits_apply u] at hk have hnk := ne_zero_of_mem_of_unit hk rw [← inv_inv (unitary.toUnits u), ← spectrum.map_inv, Set.mem_inv] at hk have : ‖k‖⁻¹ ≤ ‖(↑(unitary.toUnits u)⁻¹ : E)‖ := by simpa only [norm_inv] using norm_le_norm_of_mem hk simpa using inv_le_of_inv_le (norm_pos_iff.mpr hnk) this theorem spectrum.subset_circle_of_unitary {u : E} (h : u ∈ unitary E) : spectrum 𝕜 u ⊆ Metric.sphere 0 1 := unitary.spectrum_subset_circle ⟨u, h⟩ end UnitarySpectrum section ComplexScalars open Complex variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [CompleteSpace A] [StarRing A] [CStarRing A] local notation "↑ₐ" => algebraMap ℂ A theorem IsSelfAdjoint.spectralRadius_eq_nnnorm {a : A} (ha : IsSelfAdjoint a) : spectralRadius ℂ a = ‖a‖₊ := by have hconst : Tendsto (fun _n : ℕ => (‖a‖₊ : ℝ≥0∞)) atTop _ := tendsto_const_nhds refine tendsto_nhds_unique ?_ hconst convert (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a : A)).comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) using 1 refine funext fun n => ?_ rw [Function.comp_apply, ha.nnnorm_pow_two_pow, ENNReal.coe_pow, ← rpow_natCast, ← rpow_mul] simp /-- In a C⋆-algebra, the spectral radius of a self-adjoint element is equal to its norm. See `IsSelfAdjoint.toReal_spectralRadius_eq_norm` for a version involving `spectralRadius ℝ a`. -/ lemma IsSelfAdjoint.toReal_spectralRadius_complex_eq_norm {a : A} (ha : IsSelfAdjoint a) : (spectralRadius ℂ a).toReal = ‖a‖ := by simp [ha.spectralRadius_eq_nnnorm] theorem IsStarNormal.spectralRadius_eq_nnnorm (a : A) [IsStarNormal a] : spectralRadius ℂ a = ‖a‖₊ := by refine (ENNReal.pow_strictMono two_ne_zero).injective ?_ have heq : (fun n : ℕ => (‖(a⋆ * a) ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ)) = (fun x => x ^ 2) ∘ fun n : ℕ => (‖a ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ) := by funext n rw [Function.comp_apply, ← rpow_natCast, ← rpow_mul, mul_comm, rpow_mul, rpow_natCast, ← coe_pow, sq, ← nnnorm_star_mul_self, Commute.mul_pow (star_comm_self' a), star_pow] have h₂ := ((ENNReal.continuous_pow 2).tendsto (spectralRadius ℂ a)).comp (spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius a) rw [← heq] at h₂ convert tendsto_nhds_unique h₂ (pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a⋆ * a)) rw [(IsSelfAdjoint.star_mul_self a).spectralRadius_eq_nnnorm, sq, nnnorm_star_mul_self, coe_mul] /-- Any element of the spectrum of a selfadjoint is real. -/ theorem IsSelfAdjoint.mem_spectrum_eq_re [StarModule ℂ A] {a : A} (ha : IsSelfAdjoint a) {z : ℂ} (hz : z ∈ spectrum ℂ a) : z = z.re := by have hu := exp_mem_unitary_of_mem_skewAdjoint ℂ (ha.smul_mem_skewAdjoint conj_I) let Iu := Units.mk0 I I_ne_zero have : NormedSpace.exp ℂ (I • z) ∈ spectrum ℂ (NormedSpace.exp ℂ (I • a)) := by simpa only [Units.smul_def, Units.val_mk0] using spectrum.exp_mem_exp (Iu • a) (smul_mem_smul_iff.mpr hz) exact Complex.ext (ofReal_re _) <| by simpa only [← Complex.exp_eq_exp_ℂ, mem_sphere_zero_iff_norm, norm_eq_abs, abs_exp, Real.exp_eq_one_iff, smul_eq_mul, I_mul, neg_eq_zero] using spectrum.subset_circle_of_unitary hu this /-- Any element of the spectrum of a selfadjoint is real. -/ theorem selfAdjoint.mem_spectrum_eq_re [StarModule ℂ A] (a : selfAdjoint A) {z : ℂ} (hz : z ∈ spectrum ℂ (a : A)) : z = z.re := a.prop.mem_spectrum_eq_re hz /-- The spectrum of a selfadjoint is real -/ theorem IsSelfAdjoint.val_re_map_spectrum [StarModule ℂ A] {a : A} (ha : IsSelfAdjoint a) : spectrum ℂ a = ((↑) ∘ re '' spectrum ℂ a : Set ℂ) := le_antisymm (fun z hz => ⟨z, hz, (ha.mem_spectrum_eq_re hz).symm⟩) fun z => by rintro ⟨z, hz, rfl⟩ simpa only [(ha.mem_spectrum_eq_re hz).symm, Function.comp_apply] using hz /-- The spectrum of a selfadjoint is real -/ theorem selfAdjoint.val_re_map_spectrum [StarModule ℂ A] (a : selfAdjoint A) : spectrum ℂ (a : A) = ((↑) ∘ re '' spectrum ℂ (a : A) : Set ℂ) := a.property.val_re_map_spectrum end ComplexScalars namespace StarAlgHom variable {F A B : Type*} [NormedRing A] [NormedAlgebra ℂ A] [CompleteSpace A] [StarRing A] [CStarRing A] [NormedRing B] [NormedAlgebra ℂ B] [CompleteSpace B] [StarRing B] [CStarRing B] [FunLike F A B] [AlgHomClass F ℂ A B] [StarAlgHomClass F ℂ A B] (φ : F) /-- A star algebra homomorphism of complex C⋆-algebras is norm contractive. -/ theorem nnnorm_apply_le (a : A) : ‖(φ a : B)‖₊ ≤ ‖a‖₊ := by suffices ∀ s : A, IsSelfAdjoint s → ‖φ s‖₊ ≤ ‖s‖₊ by exact nonneg_le_nonneg_of_sq_le_sq zero_le' <| by simpa only [nnnorm_star_mul_self, map_star, map_mul] using this _ (IsSelfAdjoint.star_mul_self a) intro s hs simpa only [hs.spectralRadius_eq_nnnorm, (hs.starHom_apply φ).spectralRadius_eq_nnnorm, coe_le_coe] using show spectralRadius ℂ (φ s) ≤ spectralRadius ℂ s from iSup_le_iSup_of_subset (AlgHom.spectrum_apply_subset φ s) /-- A star algebra homomorphism of complex C⋆-algebras is norm contractive. -/ theorem norm_apply_le (a : A) : ‖(φ a : B)‖ ≤ ‖a‖ := nnnorm_apply_le φ a /-- Star algebra homomorphisms between C⋆-algebras are continuous linear maps. See note [lower instance priority] -/ noncomputable instance (priority := 100) : ContinuousLinearMapClass F ℂ A B := { AlgHomClass.linearMapClass with map_continuous := fun φ => AddMonoidHomClass.continuous_of_bound φ 1 (by simpa only [one_mul] using nnnorm_apply_le φ) } end StarAlgHom namespace StarAlgEquiv variable {F A B : Type*} [NormedRing A] [NormedAlgebra ℂ A] [CompleteSpace A] [StarRing A] [CStarRing A] [NormedRing B] [NormedAlgebra ℂ B] [CompleteSpace B] [StarRing B] [CStarRing B] [EquivLike F A B] [NonUnitalAlgEquivClass F ℂ A B] [StarAlgEquivClass F ℂ A B] lemma nnnorm_map (φ : F) (a : A) : ‖φ a‖₊ = ‖a‖₊ := le_antisymm (StarAlgHom.nnnorm_apply_le φ a) <| by simpa using StarAlgHom.nnnorm_apply_le (symm (φ : A ≃⋆ₐ[ℂ] B)) ((φ : A ≃⋆ₐ[ℂ] B) a) lemma norm_map (φ : F) (a : A) : ‖φ a‖ = ‖a‖ := congr_arg NNReal.toReal (nnnorm_map φ a) lemma isometry (φ : F) : Isometry φ := AddMonoidHomClass.isometry_of_norm φ (norm_map φ) end StarAlgEquiv end namespace WeakDual open ContinuousMap Complex open scoped ComplexStarModule variable {F A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [CompleteSpace A] [StarRing A] [CStarRing A] [StarModule ℂ A] [FunLike F A ℂ] [hF : AlgHomClass F ℂ A ℂ] /-- This instance is provided instead of `StarAlgHomClass` to avoid type class inference loops. See note [lower instance priority] -/ noncomputable instance (priority := 100) Complex.instStarHomClass : StarHomClass F A ℂ where map_star φ a := by suffices hsa : ∀ s : selfAdjoint A, (φ s)⋆ = φ s by rw [← realPart_add_I_smul_imaginaryPart a] simp only [map_add, map_smul, star_add, star_smul, hsa, selfAdjoint.star_val_eq] intro s have := AlgHom.apply_mem_spectrum φ (s : A) rw [selfAdjoint.val_re_map_spectrum s] at this rcases this with ⟨⟨_, _⟩, _, heq⟩ simp only [Function.comp_apply] at heq rw [← heq, RCLike.star_def] exact RCLike.conj_ofReal _ /-- This is not an instance to avoid type class inference loops. See `WeakDual.Complex.instStarHomClass`. -/ lemma _root_.AlgHomClass.instStarAlgHomClass : StarAlgHomClass F ℂ A ℂ := { WeakDual.Complex.instStarHomClass, hF with } namespace CharacterSpace noncomputable instance instStarAlgHomClass : StarAlgHomClass (characterSpace ℂ A) ℂ A ℂ := { AlgHomClass.instStarAlgHomClass with } end CharacterSpace end WeakDual
Analysis\CStarAlgebra\Unitization.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.CStarAlgebra.Basic import Mathlib.Analysis.Normed.Algebra.Unitization /-! # The minimal unitization of a C⋆-algebra This file shows that when `E` is a C⋆-algebra (over a densely normed field `𝕜`), that the minimal `Unitization` is as well. In order to ensure that the norm structure is available, we must first show that every C⋆-algebra is a `RegularNormedAlgebra`. In addition, we show that in a `RegularNormedAlgebra` which is a `StarRing` for which the involution is isometric, that multiplication on the right is also an isometry (i.e., `Isometry (ContinuousLinearMap.mul 𝕜 E).flip`). -/ open ContinuousLinearMap local postfix:max "⋆" => star variable (𝕜 : Type*) {E : Type*} namespace ContinuousLinearMap variable [NontriviallyNormedField 𝕜] [NonUnitalNormedRing E] [StarRing E] [NormedStarGroup E] variable [NormedSpace 𝕜 E] [IsScalarTower 𝕜 E E] [SMulCommClass 𝕜 E E] [RegularNormedAlgebra 𝕜 E] lemma opNorm_mul_flip_apply (a : E) : ‖(mul 𝕜 E).flip a‖ = ‖a‖ := by refine le_antisymm (opNorm_le_bound _ (norm_nonneg _) fun b => by simpa only [mul_comm] using norm_mul_le b a) ?_ suffices ‖mul 𝕜 E (star a)‖ ≤ ‖(mul 𝕜 E).flip a‖ by simpa using this refine opNorm_le_bound _ (norm_nonneg _) fun b => ?_ calc ‖mul 𝕜 E (star a) b‖ = ‖(mul 𝕜 E).flip a (star b)‖ := by simpa using norm_star (star b * a) _ ≤ ‖(mul 𝕜 E).flip a‖ * ‖b‖ := by simpa using le_opNorm ((mul 𝕜 E).flip a) (star b) @[deprecated (since := "2024-02-02")] alias op_norm_mul_flip_apply := opNorm_mul_flip_apply lemma opNNNorm_mul_flip_apply (a : E) : ‖(mul 𝕜 E).flip a‖₊ = ‖a‖₊ := Subtype.ext (opNorm_mul_flip_apply 𝕜 a) @[deprecated (since := "2024-02-02")] alias op_nnnorm_mul_flip_apply := opNNNorm_mul_flip_apply variable (E) lemma isometry_mul_flip : Isometry (mul 𝕜 E).flip := AddMonoidHomClass.isometry_of_norm _ (opNorm_mul_flip_apply 𝕜) end ContinuousLinearMap variable [DenselyNormedField 𝕜] [NonUnitalNormedRing E] [StarRing E] [CStarRing E] variable [NormedSpace 𝕜 E] [IsScalarTower 𝕜 E E] [SMulCommClass 𝕜 E E] variable (E) /-- A C⋆-algebra over a densely normed field is a regular normed algebra. -/ instance CStarRing.instRegularNormedAlgebra : RegularNormedAlgebra 𝕜 E where isometry_mul' := AddMonoidHomClass.isometry_of_norm (mul 𝕜 E) fun a => NNReal.eq_iff.mp <| show ‖mul 𝕜 E a‖₊ = ‖a‖₊ by rw [← sSup_closed_unit_ball_eq_nnnorm] refine csSup_eq_of_forall_le_of_forall_lt_exists_gt ?_ ?_ fun r hr => ?_ · exact (Metric.nonempty_closedBall.mpr zero_le_one).image _ · rintro - ⟨x, hx, rfl⟩ exact ((mul 𝕜 E a).unit_le_opNorm x <| mem_closedBall_zero_iff.mp hx).trans (opNorm_mul_apply_le 𝕜 E a) · have ha : 0 < ‖a‖₊ := zero_le'.trans_lt hr rw [← inv_inv ‖a‖₊, NNReal.lt_inv_iff_mul_lt (inv_ne_zero ha.ne')] at hr obtain ⟨k, hk₁, hk₂⟩ := NormedField.exists_lt_nnnorm_lt 𝕜 (mul_lt_mul_of_pos_right hr <| inv_pos.2 ha) refine ⟨_, ⟨k • star a, ?_, rfl⟩, ?_⟩ · simpa only [mem_closedBall_zero_iff, norm_smul, one_mul, norm_star] using (NNReal.le_inv_iff_mul_le ha.ne').1 (one_mul ‖a‖₊⁻¹ ▸ hk₂.le : ‖k‖₊ ≤ ‖a‖₊⁻¹) · simp only [map_smul, nnnorm_smul, mul_apply', mul_smul_comm, CStarRing.nnnorm_self_mul_star] rwa [← NNReal.div_lt_iff (mul_pos ha ha).ne', div_eq_mul_inv, mul_inv, ← mul_assoc] section CStarProperty variable [StarRing 𝕜] [StarModule 𝕜 E] variable {E} /-- This is the key lemma used to establish the instance `Unitization.instCStarRing` (i.e., proving that the norm on `Unitization 𝕜 E` satisfies the C⋆-property). We split this one out so that declaring the `CStarRing` instance doesn't time out. -/ theorem Unitization.norm_splitMul_snd_sq (x : Unitization 𝕜 E) : ‖(Unitization.splitMul 𝕜 E x).snd‖ ^ 2 ≤ ‖(Unitization.splitMul 𝕜 E (star x * x)).snd‖ := by /- The key idea is that we can use `sSup_closed_unit_ball_eq_norm` to make this about applying this linear map to elements of norm at most one. There is a bit of `sqrt` and `sq` shuffling that needs to occur, which is primarily just an annoyance. -/ refine (Real.le_sqrt (norm_nonneg _) (norm_nonneg _)).mp ?_ simp only [Unitization.splitMul_apply] rw [← sSup_closed_unit_ball_eq_norm] refine csSup_le ((Metric.nonempty_closedBall.2 zero_le_one).image _) ?_ rintro - ⟨b, hb, rfl⟩ simp only -- rewrite to a more convenient form; this is where we use the C⋆-property rw [← Real.sqrt_sq (norm_nonneg _), Real.sqrt_le_sqrt_iff (norm_nonneg _), sq, ← CStarRing.norm_star_mul_self, ContinuousLinearMap.add_apply, star_add, mul_apply', Algebra.algebraMap_eq_smul_one, ContinuousLinearMap.smul_apply, ContinuousLinearMap.one_apply, star_mul, star_smul, add_mul, smul_mul_assoc, ← mul_smul_comm, mul_assoc, ← mul_add, ← sSup_closed_unit_ball_eq_norm] refine (norm_mul_le _ _).trans ?_ calc _ ≤ ‖star x.fst • (x.fst • b + x.snd * b) + star x.snd * (x.fst • b + x.snd * b)‖ := by nth_rewrite 2 [← one_mul ‖_ + _‖] gcongr exact (norm_star b).symm ▸ mem_closedBall_zero_iff.1 hb _ ≤ sSup (_ '' Metric.closedBall 0 1) := le_csSup ?_ ⟨b, hb, ?_⟩ -- now we just check the side conditions for `le_csSup`. There is nothing of interest here. · refine ⟨‖(star x * x).fst‖ + ‖(star x * x).snd‖, ?_⟩ rintro _ ⟨y, hy, rfl⟩ refine (norm_add_le _ _).trans ?_ gcongr · rw [Algebra.algebraMap_eq_smul_one] refine (norm_smul _ _).trans_le ?_ simpa only [mul_one] using mul_le_mul_of_nonneg_left (mem_closedBall_zero_iff.1 hy) (norm_nonneg (star x * x).fst) · exact (unit_le_opNorm _ y <| mem_closedBall_zero_iff.1 hy).trans (opNorm_mul_apply_le _ _ _) · simp only [ContinuousLinearMap.add_apply, mul_apply', Unitization.snd_star, Unitization.snd_mul, Unitization.fst_mul, Unitization.fst_star, Algebra.algebraMap_eq_smul_one, smul_apply, one_apply, smul_add, mul_add, add_mul] simp only [smul_smul, smul_mul_assoc, ← add_assoc, ← mul_assoc, mul_smul_comm] variable {𝕜} variable [CStarRing 𝕜] /-- The norm on `Unitization 𝕜 E` satisfies the C⋆-property -/ instance Unitization.instCStarRing : CStarRing (Unitization 𝕜 E) where norm_mul_self_le x := by -- rewrite both sides as a `⊔` simp only [Unitization.norm_def, Prod.norm_def, ← sup_eq_max] -- Show that `(Unitization.splitMul 𝕜 E x).snd` satisifes the C⋆-property, in two stages: have h₁ : ∀ x : Unitization 𝕜 E, ‖(Unitization.splitMul 𝕜 E x).snd‖ ≤ ‖(Unitization.splitMul 𝕜 E (star x)).snd‖ := by simp only [add_zero, Unitization.splitMul_apply, Unitization.snd_star, Unitization.fst_star] intro x /- split based on whether the term inside the norm is zero or not. If so, it's trivial. If not, then apply `norm_splitMul_snd_sq` and cancel one copy of the norm -/ by_cases h : algebraMap 𝕜 (E →L[𝕜] E) x.fst + mul 𝕜 E x.snd = 0 · simp only [h, norm_zero, norm_le_zero_iff] exact norm_nonneg _ · have : ‖(Unitization.splitMul 𝕜 E x).snd‖ ^ 2 ≤ ‖(Unitization.splitMul 𝕜 E (star x)).snd‖ * ‖(Unitization.splitMul 𝕜 E x).snd‖ := (norm_splitMul_snd_sq 𝕜 x).trans <| by rw [map_mul, Prod.snd_mul] exact norm_mul_le _ _ rw [sq] at this rw [← Ne, ← norm_pos_iff] at h simp only [add_zero, Unitization.splitMul_apply, Unitization.snd_star, Unitization.fst_star, star_star] at this exact (mul_le_mul_right h).mp this -- in this step we make use of the key lemma `norm_splitMul_snd_sq` have h₂ : ‖(Unitization.splitMul 𝕜 E (star x * x)).snd‖ = ‖(Unitization.splitMul 𝕜 E x).snd‖ ^ 2 := by refine le_antisymm ?_ (norm_splitMul_snd_sq 𝕜 x) rw [map_mul, Prod.snd_mul] exact (norm_mul_le _ _).trans <| by rw [sq] gcongr simpa only [star_star] using h₁ (star x) -- Show that `(Unitization.splitMul 𝕜 E x).fst` satisfies the C⋆-property have h₃ : ‖(Unitization.splitMul 𝕜 E (star x * x)).fst‖ = ‖(Unitization.splitMul 𝕜 E x).fst‖ ^ 2 := by simp only [Unitization.splitMul_apply, Unitization.fst_mul, Unitization.fst_star, add_zero, norm_mul, norm_star, sq] rw [h₂, h₃] /- use the definition of the norm, and split into cases based on whether the norm in the first coordinate is bigger or smaller than the norm in the second coordinate. -/ by_cases h : ‖(Unitization.splitMul 𝕜 E x).fst‖ ≤ ‖(Unitization.splitMul 𝕜 E x).snd‖ · rw [sq, sq, sup_eq_right.mpr h, sup_eq_right.mpr (mul_self_le_mul_self (norm_nonneg _) h)] · replace h := (not_le.mp h).le rw [sq, sq, sup_eq_left.mpr h, sup_eq_left.mpr (mul_self_le_mul_self (norm_nonneg _) h)] end CStarProperty
Analysis\CStarAlgebra\ContinuousFunctionalCalculus\Basic.lean
/- Copyright (c) 2022 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.CStarAlgebra.GelfandDuality import Mathlib.Topology.Algebra.StarSubalgebra /-! # Continuous functional calculus In this file we construct the `continuousFunctionalCalculus` for a normal element `a` of a (unital) C⋆-algebra over `ℂ`. This is a star algebra equivalence `C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elementalStarAlgebra ℂ a` which sends the (restriction of) the identity map `ContinuousMap.id ℂ` to the (unique) preimage of `a` under the coercion of `elementalStarAlgebra ℂ a` to `A`. Being a star algebra equivalence between C⋆-algebras, this map is continuous (even an isometry), and by the Stone-Weierstrass theorem it is the unique star algebra equivalence which extends the polynomial functional calculus (i.e., `Polynomial.aeval`). For any continuous function `f : spectrum ℂ a → ℂ`, this makes it possible to define an element `f a` (not valid notation) in the original algebra, which heuristically has the same eigenspaces as `a` and acts on eigenvector of `a` for an eigenvalue `λ` as multiplication by `f λ`. This description is perfectly accurate in finite dimension, but only heuristic in infinite dimension as there might be no genuine eigenvector. In particular, when `f` is a polynomial `∑ cᵢ Xⁱ`, then `f a` is `∑ cᵢ aⁱ`. Also, `id a = a`. This file also includes a proof of the **spectral permanence** theorem for (unital) C⋆-algebras (see `StarSubalgebra.spectrum_eq`) ## Main definitions * `continuousFunctionalCalculus : C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elementalStarAlgebra ℂ a`: this is the composition of the inverse of the `gelfandStarTransform` with the natural isomorphism induced by the homeomorphism `elementalStarAlgebra.characterSpaceHomeo`. * `elementalStarAlgebra.characterSpaceHomeo` : `characterSpace ℂ (elementalStarAlgebra ℂ a) ≃ₜ spectrum ℂ a`: this homeomorphism is defined by evaluating a character `φ` at `a`, and noting that `φ a ∈ spectrum ℂ a` since `φ` is an algebra homomorphism. Moreover, this map is continuous and bijective and since the spaces involved are compact Hausdorff, it is a homeomorphism. ## Main statements * `StarSubalgebra.coe_isUnit`: for `x : S` in a C⋆-Subalgebra `S` of `A`, then `↑x : A` is a Unit if and only if `x` is a unit. * `StarSubalgebra.spectrum_eq`: **spectral_permanence** for `x : S`, where `S` is a C⋆-Subalgebra of `A`, `spectrum ℂ x = spectrum ℂ (x : A)`. ## Notes The result we have established here is the strongest possible, but it is likely not the version which will be most useful in practice. Future work will include developing an appropriate API for the continuous functional calculus (including one for real-valued functions with real argument that applies to self-adjoint elements of the algebra). -/ open scoped Pointwise ENNReal NNReal ComplexOrder open WeakDual WeakDual.CharacterSpace elementalStarAlgebra variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] variable [StarRing A] [CStarRing A] [StarModule ℂ A] instance {R A : Type*} [CommRing R] [StarRing R] [NormedRing A] [Algebra R A] [StarRing A] [ContinuousStar A] [StarModule R A] (a : A) [IsStarNormal a] : NormedCommRing (elementalStarAlgebra R a) := { SubringClass.toNormedRing (elementalStarAlgebra R a) with mul_comm := mul_comm } -- Porting note: these hack instances no longer seem to be necessary variable [CompleteSpace A] (a : A) [IsStarNormal a] (S : StarSubalgebra ℂ A) /-- This lemma is used in the proof of `elementalStarAlgebra.isUnit_of_isUnit_of_isStarNormal`, which in turn is the key to spectral permanence `StarSubalgebra.spectrum_eq`, which is itself necessary for the continuous functional calculus. Using the continuous functional calculus, this lemma can be superseded by one that omits the `IsStarNormal` hypothesis. -/ theorem spectrum_star_mul_self_of_isStarNormal : spectrum ℂ (star a * a) ⊆ Set.Icc (0 : ℂ) ‖star a * a‖ := by -- this instance should be found automatically, but without providing it Lean goes on a wild -- goose chase when trying to apply `spectrum.gelfandTransform_eq`. --letI := elementalStarAlgebra.Complex.normedAlgebra a rcases subsingleton_or_nontrivial A with ⟨⟩ · simp only [spectrum.of_subsingleton, Set.empty_subset] · set a' : elementalStarAlgebra ℂ a := ⟨a, self_mem ℂ a⟩ refine (spectrum.subset_subalgebra (star a' * a')).trans ?_ rw [← spectrum.gelfandTransform_eq (star a' * a'), ContinuousMap.spectrum_eq_range] rintro - ⟨φ, rfl⟩ rw [gelfandTransform_apply_apply ℂ _ (star a' * a') φ, map_mul φ, map_star φ] rw [Complex.eq_coe_norm_of_nonneg (star_mul_self_nonneg _), ← map_star, ← map_mul] exact ⟨by positivity, Complex.real_le_real.2 (AlgHom.norm_apply_le_self φ (star a' * a'))⟩ variable {a} /-- This is the key lemma on the way to establishing spectral permanence for C⋆-algebras, which is established in `StarSubalgebra.spectrum_eq`. This lemma is superseded by `StarSubalgebra.coe_isUnit`, which does not require an `IsStarNormal` hypothesis and holds for any closed star subalgebra. -/ theorem elementalStarAlgebra.isUnit_of_isUnit_of_isStarNormal (h : IsUnit a) : IsUnit (⟨a, self_mem ℂ a⟩ : elementalStarAlgebra ℂ a) := by /- Sketch of proof: Because `a` is normal, it suffices to prove that `star a * a` is invertible in `elementalStarAlgebra ℂ a`. For this it suffices to prove that it is sufficiently close to a unit, namely `algebraMap ℂ _ ‖star a * a‖`, and in this case the required distance is `‖star a * a‖`. So one must show `‖star a * a - algebraMap ℂ _ ‖star a * a‖‖ < ‖star a * a‖`. Since `star a * a - algebraMap ℂ _ ‖star a * a‖` is selfadjoint, by a corollary of Gelfand's formula for the spectral radius (`IsSelfAdjoint.spectralRadius_eq_nnnorm`) its norm is the supremum of the norms of elements in its spectrum (we may use the spectrum in `A` here because the norm in `A` and the norm in the subalgebra coincide). By `spectrum_star_mul_self_of_isStarNormal`, the spectrum (in the algebra `A`) of `star a * a` is contained in the interval `[0, ‖star a * a‖]`, and since `a` (and hence `star a * a`) is invertible in `A`, we may omit `0` from this interval. Therefore, by basic spectral mapping properties, the spectrum (in the algebra `A`) of `star a * a - algebraMap ℂ _ ‖star a * a‖` is contained in `[0, ‖star a * a‖)`. The supremum of the (norms of) elements of the spectrum must be *strictly* less that `‖star a * a‖` because the spectrum is compact, which completes the proof. -/ /- We may assume `A` is nontrivial. It suffices to show that `star a * a` is invertible in the commutative (because `a` is normal) ring `elementalStarAlgebra ℂ a`. Indeed, by commutativity, if `star a * a` is invertible, then so is `a`. -/ nontriviality A set a' : elementalStarAlgebra ℂ a := ⟨a, self_mem ℂ a⟩ suffices IsUnit (star a' * a') from (IsUnit.mul_iff.1 this).2 replace h := (show Commute (star a) a from star_comm_self' a).isUnit_mul_iff.2 ⟨h.star, h⟩ /- Since `a` is invertible, `‖star a * a‖ ≠ 0`, so `‖star a * a‖ • 1` is invertible in `elementalStarAlgebra ℂ a`, and so it suffices to show that the distance between this unit and `star a * a` is less than `‖star a * a‖`. -/ have h₁ : (‖star a * a‖ : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr (norm_ne_zero_iff.mpr h.ne_zero) set u : Units (elementalStarAlgebra ℂ a) := Units.map (algebraMap ℂ (elementalStarAlgebra ℂ a)).toMonoidHom (Units.mk0 _ h₁) refine ⟨u.ofNearby _ ?_, rfl⟩ simp only [u, Units.coe_map, Units.val_inv_eq_inv_val, RingHom.toMonoidHom_eq_coe, Units.val_mk0, Units.coe_map_inv, MonoidHom.coe_coe, norm_algebraMap', norm_inv, Complex.norm_eq_abs, Complex.abs_ofReal, abs_norm, inv_inv] /- Since `a` is invertible, by `spectrum_star_mul_self_of_isStarNormal`, the spectrum (in `A`) of `star a * a` is contained in the half-open interval `(0, ‖star a * a‖]`. Therefore, by basic spectral mapping properties, the spectrum of `‖star a * a‖ • 1 - star a * a` is contained in `[0, ‖star a * a‖)`. -/ have h₂ : ∀ z ∈ spectrum ℂ (algebraMap ℂ A ‖star a * a‖ - star a * a), ‖z‖₊ < ‖star a * a‖₊ := by intro z hz rw [← spectrum.singleton_sub_eq, Set.singleton_sub] at hz have h₃ : z ∈ Set.Icc (0 : ℂ) ‖star a * a‖ := by replace hz := Set.image_subset _ (spectrum_star_mul_self_of_isStarNormal a) hz rwa [Set.image_const_sub_Icc, sub_self, sub_zero] at hz refine lt_of_le_of_ne (Complex.real_le_real.1 <| Complex.eq_coe_norm_of_nonneg h₃.1 ▸ h₃.2) ?_ · intro hz' replace hz' := congr_arg (fun x : ℝ≥0 => ((x : ℝ) : ℂ)) hz' simp only [coe_nnnorm] at hz' rw [← Complex.eq_coe_norm_of_nonneg h₃.1] at hz' obtain ⟨w, hw₁, hw₂⟩ := hz refine (spectrum.zero_not_mem_iff ℂ).mpr h ?_ rw [hz', sub_eq_self] at hw₂ rwa [hw₂] at hw₁ /- The norm of `‖star a * a‖ • 1 - star a * a` in the subalgebra and in `A` coincide. In `A`, because this element is selfadjoint, by `IsSelfAdjoint.spectralRadius_eq_nnnorm`, its norm is the supremum of the norms of the elements of the spectrum, which is strictly less than `‖star a * a‖` by `h₂` and because the spectrum is compact. -/ exact ENNReal.coe_lt_coe.1 (calc (‖star a' * a' - algebraMap ℂ _ ‖star a * a‖‖₊ : ℝ≥0∞) = ‖algebraMap ℂ A ‖star a * a‖ - star a * a‖₊ := by rw [← nnnorm_neg, neg_sub]; rfl _ = spectralRadius ℂ (algebraMap ℂ A ‖star a * a‖ - star a * a) := by refine (IsSelfAdjoint.spectralRadius_eq_nnnorm ?_).symm rw [IsSelfAdjoint, star_sub, star_mul, star_star, ← algebraMap_star_comm] congr! exact RCLike.conj_ofReal _ _ < ‖star a * a‖₊ := spectrum.spectralRadius_lt_of_forall_lt _ h₂) /-- For `x : A` which is invertible in `A`, the inverse lies in any unital C⋆-subalgebra `S` containing `x`. -/ theorem StarSubalgebra.isUnit_coe_inv_mem {S : StarSubalgebra ℂ A} (hS : IsClosed (S : Set A)) {x : A} (h : IsUnit x) (hxS : x ∈ S) : ↑h.unit⁻¹ ∈ S := by have hx := h.star.mul h suffices this : (↑hx.unit⁻¹ : A) ∈ S by rw [← one_mul (↑h.unit⁻¹ : A), ← hx.unit.inv_mul, mul_assoc, IsUnit.unit_spec, mul_assoc, h.mul_val_inv, mul_one] exact mul_mem this (star_mem hxS) refine le_of_isClosed_of_mem ℂ hS (mul_mem (star_mem hxS) hxS) ?_ haveI := (IsSelfAdjoint.star_mul_self x).isStarNormal have hx' := elementalStarAlgebra.isUnit_of_isUnit_of_isStarNormal hx convert (↑hx'.unit⁻¹ : elementalStarAlgebra ℂ (star x * x)).prop using 1 refine left_inv_eq_right_inv hx.unit.inv_mul ?_ exact (congr_arg ((↑) : _ → A) hx'.unit.mul_inv) /-- For a unital C⋆-subalgebra `S` of `A` and `x : S`, if `↑x : A` is invertible in `A`, then `x` is invertible in `S`. -/ theorem StarSubalgebra.coe_isUnit {S : StarSubalgebra ℂ A} (hS : IsClosed (S : Set A)) {x : S} : IsUnit (x : A) ↔ IsUnit x := by refine ⟨fun hx => ⟨⟨x, ⟨(↑hx.unit⁻¹ : A), StarSubalgebra.isUnit_coe_inv_mem hS hx x.prop⟩, ?_, ?_⟩, rfl⟩, fun hx => hx.map S.subtype⟩ exacts [Subtype.coe_injective hx.mul_val_inv, Subtype.coe_injective hx.val_inv_mul] theorem StarSubalgebra.mem_spectrum_iff {S : StarSubalgebra ℂ A} (hS : IsClosed (S : Set A)) {x : S} {z : ℂ} : z ∈ spectrum ℂ x ↔ z ∈ spectrum ℂ (x : A) := not_iff_not.2 (StarSubalgebra.coe_isUnit hS).symm /-- **Spectral permanence.** The spectrum of an element is invariant of the (closed) `StarSubalgebra` in which it is contained. -/ theorem StarSubalgebra.spectrum_eq {S : StarSubalgebra ℂ A} (hS : IsClosed (S : Set A)) (x : S) : spectrum ℂ x = spectrum ℂ (x : A) := Set.ext fun _z => StarSubalgebra.mem_spectrum_iff hS variable (a) /-- The natural map from `characterSpace ℂ (elementalStarAlgebra ℂ x)` to `spectrum ℂ x` given by evaluating `φ` at `x`. This is essentially just evaluation of the `gelfandTransform` of `x`, but because we want something in `spectrum ℂ x`, as opposed to `spectrum ℂ ⟨x, elementalStarAlgebra.self_mem ℂ x⟩` there is slightly more work to do. -/ @[simps] noncomputable def elementalStarAlgebra.characterSpaceToSpectrum (x : A) (φ : characterSpace ℂ (elementalStarAlgebra ℂ x)) : spectrum ℂ x where val := φ ⟨x, self_mem ℂ x⟩ property := by simpa only [StarSubalgebra.spectrum_eq (elementalStarAlgebra.isClosed ℂ x) ⟨x, self_mem ℂ x⟩] using AlgHom.apply_mem_spectrum φ ⟨x, self_mem ℂ x⟩ #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. See https://github.com/leanprover-community/mathlib4/issues/12227 -/ attribute [nolint simpNF] elementalStarAlgebra.characterSpaceToSpectrum_coe theorem elementalStarAlgebra.continuous_characterSpaceToSpectrum (x : A) : Continuous (elementalStarAlgebra.characterSpaceToSpectrum x) := continuous_induced_rng.2 (map_continuous <| gelfandTransform ℂ (elementalStarAlgebra ℂ x) ⟨x, self_mem ℂ x⟩) theorem elementalStarAlgebra.bijective_characterSpaceToSpectrum : Function.Bijective (elementalStarAlgebra.characterSpaceToSpectrum a) := by refine ⟨fun φ ψ h => starAlgHomClass_ext ℂ ?_ ?_ ?_, ?_⟩ · exact (map_continuous φ) · exact (map_continuous ψ) · simpa only [elementalStarAlgebra.characterSpaceToSpectrum, Subtype.mk_eq_mk, ContinuousMap.coe_mk] using h · rintro ⟨z, hz⟩ have hz' := (StarSubalgebra.spectrum_eq (elementalStarAlgebra.isClosed ℂ a) ⟨a, self_mem ℂ a⟩).symm.subst hz rw [CharacterSpace.mem_spectrum_iff_exists] at hz' obtain ⟨φ, rfl⟩ := hz' exact ⟨φ, rfl⟩ /-- The homeomorphism between the character space of the unital C⋆-subalgebra generated by a single normal element `a : A` and `spectrum ℂ a`. -/ noncomputable def elementalStarAlgebra.characterSpaceHomeo : characterSpace ℂ (elementalStarAlgebra ℂ a) ≃ₜ spectrum ℂ a := @Continuous.homeoOfEquivCompactToT2 _ _ _ _ _ _ (Equiv.ofBijective (elementalStarAlgebra.characterSpaceToSpectrum a) (elementalStarAlgebra.bijective_characterSpaceToSpectrum a)) (elementalStarAlgebra.continuous_characterSpaceToSpectrum a) /-- **Continuous functional calculus.** Given a normal element `a : A` of a unital C⋆-algebra, the continuous functional calculus is a `StarAlgEquiv` from the complex-valued continuous functions on the spectrum of `a` to the unital C⋆-subalgebra generated by `a`. Moreover, this equivalence identifies `(ContinuousMap.id ℂ).restrict (spectrum ℂ a))` with `a`; see `continuousFunctionalCalculus_map_id`. As such it extends the polynomial functional calculus. -/ noncomputable def continuousFunctionalCalculus : C(spectrum ℂ a, ℂ) ≃⋆ₐ[ℂ] elementalStarAlgebra ℂ a := ((elementalStarAlgebra.characterSpaceHomeo a).compStarAlgEquiv' ℂ ℂ).trans (gelfandStarTransform (elementalStarAlgebra ℂ a)).symm theorem continuousFunctionalCalculus_map_id : continuousFunctionalCalculus a ((ContinuousMap.id ℂ).restrict (spectrum ℂ a)) = ⟨a, self_mem ℂ a⟩ := (gelfandStarTransform (elementalStarAlgebra ℂ a)).symm_apply_apply _
Analysis\CStarAlgebra\ContinuousFunctionalCalculus\Instances.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Restrict import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Basic import Mathlib.Analysis.CStarAlgebra.Spectrum import Mathlib.Analysis.CStarAlgebra.Unitization import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique /-! # Instances of the continuous functional calculus ## Main theorems * `IsStarNormal.instContinuousFunctionalCalculus`: the continuous functional calculus for normal elements in a unital C⋆-algebra over `ℂ`. * `IsSelfAdjoint.instContinuousFunctionalCalculus`: the continuous functional calculus for selfadjoint elements in a `ℂ`-algebra with a continuous functional calculus for normal elements and where every element has compact spectrum. In particular, this includes unital C⋆-algebras over `ℂ`. * `Nonneg.instContinuousFunctionalCalculus`: the continuous functional calculus for nonnegative elements in an `ℝ`-algebra with a continuous functional calculus for selfadjoint elements, where every element has compact spectrum, and where nonnegative elements have nonnegative spectrum. In particular, this includes unital C⋆-algebras over `ℝ`. * `CStarRing.instNonnegSpectrumClass`: In a unital C⋆-algebra over `ℂ` which is also a `StarOrderedRing`, the spectrum of a nonnegative element is nonnegative. ## Tags continuous functional calculus, normal, selfadjoint -/ noncomputable section local notation "σₙ" => quasispectrum local notation "σ" => spectrum /-! ### Pull back a non-unital instance from a unital one on the unitization -/ section RCLike variable {𝕜 A : Type*} [RCLike 𝕜] [NonUnitalNormedRing A] [StarRing A] [CStarRing A] variable [CompleteSpace A] [NormedSpace 𝕜 A] [IsScalarTower 𝕜 A A] [SMulCommClass 𝕜 A A] variable [StarModule 𝕜 A] {p : A → Prop} {p₁ : Unitization 𝕜 A → Prop} local postfix:max "⁺¹" => Unitization 𝕜 variable (hp₁ : ∀ {x : A}, p₁ x ↔ p x) (a : A) (ha : p a) variable [ContinuousFunctionalCalculus 𝕜 p₁] open scoped ContinuousMapZero open Unitization in /-- This is an auxiliary definition used for constructing an instance of the non-unital continuous functional calculus given a instance of the unital one on the unitization. This is the natural non-unital star homomorphism obtained from the chain ```lean calc C(σₙ 𝕜 a, 𝕜)₀ →⋆ₙₐ[𝕜] C(σₙ 𝕜 a, 𝕜) := ContinuousMapZero.toContinuousMapHom _ ≃⋆[𝕜] C(σ 𝕜 (↑a : A⁺¹), 𝕜) := Homeomorph.compStarAlgEquiv' _ →⋆ₐ[𝕜] A⁺¹ := cfcHom ``` This range of this map is contained in the range of `(↑) : A → A⁺¹` (see `cfcₙAux_mem_range_inr`), and so we may restrict it to `A` to get the necessary homomorphism for the non-unital continuous functional calculus. -/ noncomputable def cfcₙAux : C(σₙ 𝕜 a, 𝕜)₀ →⋆ₙₐ[𝕜] A⁺¹ := (cfcHom (R := 𝕜) (hp₁.mpr ha) : C(σ 𝕜 (a : A⁺¹), 𝕜) →⋆ₙₐ[𝕜] A⁺¹) |>.comp (Homeomorph.compStarAlgEquiv' 𝕜 𝕜 <| .setCongr <| (quasispectrum_eq_spectrum_inr' 𝕜 𝕜 a).symm) |>.comp ContinuousMapZero.toContinuousMapHom lemma cfcₙAux_id : cfcₙAux hp₁ a ha (ContinuousMapZero.id rfl) = a := cfcHom_id (hp₁.mpr ha) open Unitization in lemma closedEmbedding_cfcₙAux : ClosedEmbedding (cfcₙAux hp₁ a ha) := by simp only [cfcₙAux, NonUnitalStarAlgHom.coe_comp] refine ((cfcHom_closedEmbedding (hp₁.mpr ha)).comp ?_).comp ContinuousMapZero.closedEmbedding_toContinuousMap let e : C(σₙ 𝕜 a, 𝕜) ≃ₜ C(σ 𝕜 (a : A⁺¹), 𝕜) := { (Homeomorph.compStarAlgEquiv' 𝕜 𝕜 <| .setCongr <| (quasispectrum_eq_spectrum_inr' 𝕜 𝕜 a).symm) with continuous_toFun := ContinuousMap.continuous_comp_left _ continuous_invFun := ContinuousMap.continuous_comp_left _ } exact e.closedEmbedding lemma spec_cfcₙAux (f : C(σₙ 𝕜 a, 𝕜)₀) : σ 𝕜 (cfcₙAux hp₁ a ha f) = Set.range f := by rw [cfcₙAux, NonUnitalStarAlgHom.comp_assoc, NonUnitalStarAlgHom.comp_apply] simp only [NonUnitalStarAlgHom.comp_apply, NonUnitalStarAlgHom.coe_coe] rw [cfcHom_map_spectrum (hp₁.mpr ha) (R := 𝕜) _] ext x constructor all_goals rintro ⟨x, rfl⟩ · exact ⟨⟨x, (Unitization.quasispectrum_eq_spectrum_inr' 𝕜 𝕜 a).symm ▸ x.property⟩, rfl⟩ · exact ⟨⟨x, Unitization.quasispectrum_eq_spectrum_inr' 𝕜 𝕜 a ▸ x.property⟩, rfl⟩ lemma cfcₙAux_mem_range_inr (f : C(σₙ 𝕜 a, 𝕜)₀) : cfcₙAux hp₁ a ha f ∈ NonUnitalStarAlgHom.range (Unitization.inrNonUnitalStarAlgHom 𝕜 A) := by have h₁ := (closedEmbedding_cfcₙAux hp₁ a ha).continuous.range_subset_closure_image_dense (ContinuousMapZero.adjoin_id_dense (s := σₙ 𝕜 a) rfl) ⟨f, rfl⟩ rw [← SetLike.mem_coe] refine closure_minimal ?_ ?_ h₁ · rw [← NonUnitalStarSubalgebra.coe_map, SetLike.coe_subset_coe, NonUnitalStarSubalgebra.map_le] apply NonUnitalStarAlgebra.adjoin_le apply Set.singleton_subset_iff.mpr rw [SetLike.mem_coe, NonUnitalStarSubalgebra.mem_comap, cfcₙAux_id hp₁ a ha] exact ⟨a, rfl⟩ · have : Continuous (Unitization.fst (R := 𝕜) (A := A)) := Unitization.uniformEquivProd.continuous.fst simp only [NonUnitalStarAlgHom.coe_range] convert IsClosed.preimage this (isClosed_singleton (x := 0)) aesop open Unitization NonUnitalStarAlgHom in theorem RCLike.nonUnitalContinuousFunctionalCalculus : NonUnitalContinuousFunctionalCalculus 𝕜 (p : A → Prop) where predicate_zero := by rw [← hp₁, Unitization.inr_zero 𝕜] exact cfc_predicate_zero 𝕜 exists_cfc_of_predicate a ha := by let ψ : C(σₙ 𝕜 a, 𝕜)₀ →⋆ₙₐ[𝕜] A := comp (inrRangeEquiv 𝕜 A).symm <| codRestrict (cfcₙAux hp₁ a ha) _ (cfcₙAux_mem_range_inr hp₁ a ha) have coe_ψ (f : C(σₙ 𝕜 a, 𝕜)₀) : ψ f = cfcₙAux hp₁ a ha f := congr_arg Subtype.val <| (inrRangeEquiv 𝕜 A).apply_symm_apply ⟨cfcₙAux hp₁ a ha f, cfcₙAux_mem_range_inr hp₁ a ha f⟩ refine ⟨ψ, ?closedEmbedding, ?map_id, fun f ↦ ?map_spec, fun f ↦ ?isStarNormal⟩ case closedEmbedding => apply isometry_inr (𝕜 := 𝕜) (A := A) |>.closedEmbedding |>.of_comp_iff.mp have : inr ∘ ψ = cfcₙAux hp₁ a ha := by ext1; rw [Function.comp_apply, coe_ψ] exact this ▸ closedEmbedding_cfcₙAux hp₁ a ha case map_id => exact inr_injective (R := 𝕜) <| coe_ψ _ ▸ cfcₙAux_id hp₁ a ha case map_spec => exact quasispectrum_eq_spectrum_inr' 𝕜 𝕜 (ψ f) ▸ coe_ψ _ ▸ spec_cfcₙAux hp₁ a ha f case isStarNormal => exact hp₁.mp <| coe_ψ _ ▸ cfcHom_predicate (R := 𝕜) (hp₁.mpr ha) _ end RCLike /-! ### Continuous functional calculus for normal elements -/ section Normal instance IsStarNormal.instContinuousFunctionalCalculus {A : Type*} [NormedRing A] [StarRing A] [CStarRing A] [CompleteSpace A] [NormedAlgebra ℂ A] [StarModule ℂ A] : ContinuousFunctionalCalculus ℂ (IsStarNormal : A → Prop) where predicate_zero := isStarNormal_zero exists_cfc_of_predicate a ha := by refine ⟨(elementalStarAlgebra ℂ a).subtype.comp <| continuousFunctionalCalculus a, ?hom_closedEmbedding, ?hom_id, ?hom_map_spectrum, ?predicate_hom⟩ case hom_closedEmbedding => exact Isometry.closedEmbedding <| isometry_subtype_coe.comp <| StarAlgEquiv.isometry (continuousFunctionalCalculus a) case hom_id => exact congr_arg Subtype.val <| continuousFunctionalCalculus_map_id a case hom_map_spectrum => intro f simp only [StarAlgHom.comp_apply, StarAlgHom.coe_coe, StarSubalgebra.coe_subtype] rw [← StarSubalgebra.spectrum_eq (elementalStarAlgebra.isClosed ℂ a), AlgEquiv.spectrum_eq (continuousFunctionalCalculus a), ContinuousMap.spectrum_eq_range] case predicate_hom => exact fun f ↦ ⟨by rw [← map_star]; exact Commute.all (star f) f |>.map _⟩ instance IsStarNormal.instNonUnitalContinuousFunctionalCalculus {A : Type*} [NonUnitalNormedRing A] [StarRing A] [CStarRing A] [CompleteSpace A] [NormedSpace ℂ A] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] [StarModule ℂ A] : NonUnitalContinuousFunctionalCalculus ℂ (IsStarNormal : A → Prop) := RCLike.nonUnitalContinuousFunctionalCalculus Unitization.isStarNormal_inr end Normal /-! ### Continuous functional calculus for selfadjoint elements -/ section SelfAdjointNonUnital variable {A : Type*} [TopologicalSpace A] [NonUnitalRing A] [StarRing A] [Module ℂ A] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] [StarModule ℂ A] [NonUnitalContinuousFunctionalCalculus ℂ (IsStarNormal : A → Prop)] /-- An element in a non-unital C⋆-algebra is selfadjoint if and only if it is normal and its quasispectrum is contained in `ℝ`. -/ lemma isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts {a : A} : IsSelfAdjoint a ↔ IsStarNormal a ∧ QuasispectrumRestricts a Complex.reCLM := by refine ⟨fun ha ↦ ⟨ha.isStarNormal, ⟨fun x hx ↦ ?_, Complex.ofReal_re⟩⟩, ?_⟩ · have := eqOn_of_cfcₙ_eq_cfcₙ <| (cfcₙ_star (id : ℂ → ℂ) a).symm ▸ (cfcₙ_id ℂ a).symm ▸ ha.star_eq exact Complex.conj_eq_iff_re.mp (by simpa using this hx) · rintro ⟨ha₁, ha₂⟩ rw [isSelfAdjoint_iff] nth_rw 2 [← cfcₙ_id ℂ a] rw [← cfcₙ_star_id a (R := ℂ)] refine cfcₙ_congr fun x hx ↦ ?_ obtain ⟨x, -, rfl⟩ := ha₂.algebraMap_image.symm ▸ hx exact Complex.conj_ofReal _ alias ⟨IsSelfAdjoint.quasispectrumRestricts, _⟩ := isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts /-- A normal element whose `ℂ`-quasispectrum is contained in `ℝ` is selfadjoint. -/ lemma QuasispectrumRestricts.isSelfAdjoint (a : A) (ha : QuasispectrumRestricts a Complex.reCLM) [IsStarNormal a] : IsSelfAdjoint a := isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts.mpr ⟨‹_›, ha⟩ instance IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus [∀ x : A, CompactSpace (σₙ ℂ x)] : NonUnitalContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop) := QuasispectrumRestricts.cfc (q := IsStarNormal) (p := IsSelfAdjoint) Complex.reCLM Complex.isometry_ofReal.uniformEmbedding (.zero _) (fun _ ↦ isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts) (fun _ _ ↦ inferInstance) end SelfAdjointNonUnital section SelfAdjointUnital variable {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra ℂ A] [StarModule ℂ A] [ContinuousFunctionalCalculus ℂ (IsStarNormal : A → Prop)] /- TODO: REMOVE this is a duplicate of `isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts`, because of `abbrev SpectrumRestricts := QuasispectrumRestricts` but we first need unital-to-non-unital instance) -/ /-- An element in a C⋆-algebra is selfadjoint if and only if it is normal and its spectrum is contained in `ℝ`. -/ lemma isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts {a : A} : IsSelfAdjoint a ↔ IsStarNormal a ∧ SpectrumRestricts a Complex.reCLM := by refine ⟨fun ha ↦ ⟨ha.isStarNormal, .of_rightInvOn Complex.ofReal_re fun x hx ↦ ?_⟩, ?_⟩ · have := eqOn_of_cfc_eq_cfc <| (cfc_star (id : ℂ → ℂ) a).symm ▸ (cfc_id ℂ a).symm ▸ ha.star_eq exact Complex.conj_eq_iff_re.mp (by simpa using this hx) · rintro ⟨ha₁, ha₂⟩ rw [isSelfAdjoint_iff] nth_rw 2 [← cfc_id ℂ a] rw [← cfc_star_id a (R := ℂ)] refine cfc_congr fun x hx ↦ ?_ obtain ⟨x, -, rfl⟩ := ha₂.algebraMap_image.symm ▸ hx exact Complex.conj_ofReal _ -- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`) lemma IsSelfAdjoint.spectrumRestricts {a : A} (ha : IsSelfAdjoint a) : SpectrumRestricts a Complex.reCLM := isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts.mp ha |>.right -- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`) /-- A normal element whose `ℂ`-spectrum is contained in `ℝ` is selfadjoint. -/ lemma SpectrumRestricts.isSelfAdjoint (a : A) (ha : SpectrumRestricts a Complex.reCLM) [IsStarNormal a] : IsSelfAdjoint a := isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts.mpr ⟨‹_›, ha⟩ instance IsSelfAdjoint.instContinuousFunctionalCalculus [∀ x : A, CompactSpace (spectrum ℂ x)] : ContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop) := SpectrumRestricts.cfc (q := IsStarNormal) (p := IsSelfAdjoint) Complex.reCLM Complex.isometry_ofReal.uniformEmbedding (.zero _) (fun _ ↦ isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts) (fun _ _ ↦ inferInstance) end SelfAdjointUnital /-! ### Continuous functional calculus for nonnegative elements -/ section Nonneg lemma CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts {A : Type*} [NonUnitalRing A] [StarRing A] [TopologicalSpace A] [Module ℝ A] [IsScalarTower ℝ A A] [SMulCommClass ℝ A A ] [NonUnitalContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop)] {a : A} (ha₁ : IsSelfAdjoint a) (ha₂ : QuasispectrumRestricts a ContinuousMap.realToNNReal) : ∃ x : A, IsSelfAdjoint x ∧ QuasispectrumRestricts x ContinuousMap.realToNNReal ∧ x * x = a := by use cfcₙ Real.sqrt a, cfcₙ_predicate Real.sqrt a constructor · simpa only [QuasispectrumRestricts.nnreal_iff, cfcₙ_map_quasispectrum Real.sqrt a, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] using fun x _ ↦ Real.sqrt_nonneg x · rw [← cfcₙ_mul ..] nth_rw 2 [← cfcₙ_id ℝ a] apply cfcₙ_congr fun x hx ↦ ?_ rw [QuasispectrumRestricts.nnreal_iff] at ha₂ apply ha₂ x at hx simp [← sq, Real.sq_sqrt hx] variable {A : Type*} [NonUnitalRing A] [PartialOrder A] [StarRing A] [StarOrderedRing A] variable [TopologicalSpace A] [Module ℝ A] [IsScalarTower ℝ A A] [SMulCommClass ℝ A A] variable [NonUnitalContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop)] variable [NonnegSpectrumClass ℝ A] [UniqueNonUnitalContinuousFunctionalCalculus ℝ A] lemma nonneg_iff_isSelfAdjoint_and_quasispectrumRestricts {a : A} : 0 ≤ a ↔ IsSelfAdjoint a ∧ QuasispectrumRestricts a ContinuousMap.realToNNReal := by refine ⟨fun ha ↦ ⟨.of_nonneg ha, .nnreal_of_nonneg ha⟩, ?_⟩ rintro ⟨ha₁, ha₂⟩ obtain ⟨x, hx, -, rfl⟩ := CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts ha₁ ha₂ simpa [sq, hx.star_eq] using star_mul_self_nonneg x open NNReal in instance Nonneg.instNonUnitalContinuousFunctionalCalculus [∀ a : A, CompactSpace (σₙ ℝ a)] : NonUnitalContinuousFunctionalCalculus ℝ≥0 (fun x : A ↦ 0 ≤ x) := QuasispectrumRestricts.cfc (q := IsSelfAdjoint) ContinuousMap.realToNNReal uniformEmbedding_subtype_val le_rfl (fun _ ↦ nonneg_iff_isSelfAdjoint_and_quasispectrumRestricts) (fun _ _ ↦ inferInstance) end Nonneg section Nonneg -- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`) lemma CFC.exists_sqrt_of_isSelfAdjoint_of_spectrumRestricts {A : Type*} [Ring A] [StarRing A] [TopologicalSpace A] [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop)] {a : A} (ha₁ : IsSelfAdjoint a) (ha₂ : SpectrumRestricts a ContinuousMap.realToNNReal) : ∃ x : A, IsSelfAdjoint x ∧ SpectrumRestricts x ContinuousMap.realToNNReal ∧ x ^ 2 = a := by use cfc Real.sqrt a, cfc_predicate Real.sqrt a constructor · simpa only [SpectrumRestricts.nnreal_iff, cfc_map_spectrum Real.sqrt a, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] using fun x _ ↦ Real.sqrt_nonneg x · rw [← cfc_pow ..] nth_rw 2 [← cfc_id ℝ a] apply cfc_congr fun x hx ↦ ?_ rw [SpectrumRestricts.nnreal_iff] at ha₂ apply ha₂ x at hx simp [Real.sq_sqrt hx] variable {A : Type*} [Ring A] [PartialOrder A] [StarRing A] [StarOrderedRing A] [TopologicalSpace A] variable [Algebra ℝ A] [ContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop)] variable [NonnegSpectrumClass ℝ A] [UniqueContinuousFunctionalCalculus ℝ A] -- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`) lemma nonneg_iff_isSelfAdjoint_and_spectrumRestricts {a : A} : 0 ≤ a ↔ IsSelfAdjoint a ∧ SpectrumRestricts a ContinuousMap.realToNNReal := by refine ⟨fun ha ↦ ⟨.of_nonneg ha, .nnreal_of_nonneg ha⟩, ?_⟩ rintro ⟨ha₁, ha₂⟩ obtain ⟨x, hx, -, rfl⟩ := CFC.exists_sqrt_of_isSelfAdjoint_of_spectrumRestricts ha₁ ha₂ simpa [sq, hx.star_eq] using star_mul_self_nonneg x open NNReal in instance Nonneg.instContinuousFunctionalCalculus [∀ a : A, CompactSpace (spectrum ℝ a)] : ContinuousFunctionalCalculus ℝ≥0 (fun x : A ↦ 0 ≤ x) := SpectrumRestricts.cfc (q := IsSelfAdjoint) ContinuousMap.realToNNReal uniformEmbedding_subtype_val le_rfl (fun _ ↦ nonneg_iff_isSelfAdjoint_and_spectrumRestricts) (fun _ _ ↦ inferInstance) end Nonneg /-! ### The spectrum of a nonnegative element is nonnegative -/ section SpectrumRestricts open NNReal ENNReal variable {A : Type*} [NormedRing A] [StarRing A] [CStarRing A] [CompleteSpace A] variable [NormedAlgebra ℂ A] [StarModule ℂ A] lemma SpectrumRestricts.nnreal_iff_nnnorm {a : A} {t : ℝ≥0} (ha : IsSelfAdjoint a) (ht : ‖a‖₊ ≤ t) : SpectrumRestricts a ContinuousMap.realToNNReal ↔ ‖algebraMap ℝ A t - a‖₊ ≤ t := by have : IsSelfAdjoint (algebraMap ℝ A t - a) := IsSelfAdjoint.algebraMap A (.all (t : ℝ)) |>.sub ha rw [← ENNReal.coe_le_coe, ← IsSelfAdjoint.spectralRadius_eq_nnnorm, ← SpectrumRestricts.spectralRadius_eq (f := Complex.reCLM)] at ht ⊢ · exact SpectrumRestricts.nnreal_iff_spectralRadius_le ht all_goals try apply IsSelfAdjoint.spectrumRestricts assumption lemma SpectrumRestricts.nnreal_add {a b : A} (ha₁ : IsSelfAdjoint a) (hb₁ : IsSelfAdjoint b) (ha₂ : SpectrumRestricts a ContinuousMap.realToNNReal) (hb₂ : SpectrumRestricts b ContinuousMap.realToNNReal) : SpectrumRestricts (a + b) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff_nnnorm (ha₁.add hb₁) (nnnorm_add_le a b), NNReal.coe_add, map_add, add_sub_add_comm] refine nnnorm_add_le _ _ |>.trans ?_ gcongr all_goals rw [← SpectrumRestricts.nnreal_iff_nnnorm] <;> first | rfl | assumption lemma IsSelfAdjoint.sq_spectrumRestricts {a : A} (ha : IsSelfAdjoint a) : SpectrumRestricts (a ^ 2) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff, ← cfc_id (R := ℝ) a, ← cfc_pow .., cfc_map_spectrum ..] rintro - ⟨x, -, rfl⟩ exact sq_nonneg x open ComplexStarModule lemma SpectrumRestricts.eq_zero_of_neg {a : A} (ha : IsSelfAdjoint a) (ha₁ : SpectrumRestricts a ContinuousMap.realToNNReal) (ha₂ : SpectrumRestricts (-a) ContinuousMap.realToNNReal) : a = 0 := by nontriviality A rw [SpectrumRestricts.nnreal_iff] at ha₁ ha₂ apply CFC.eq_zero_of_spectrum_subset_zero (R := ℝ) a rw [Set.subset_singleton_iff] simp only [← spectrum.neg_eq, Set.mem_neg] at ha₂ peel ha₁ with x hx _ linarith [ha₂ (-x) ((neg_neg x).symm ▸ hx)] lemma SpectrumRestricts.smul_of_nonneg {A : Type*} [Ring A] [Algebra ℝ A] {a : A} (ha : SpectrumRestricts a ContinuousMap.realToNNReal) {r : ℝ} (hr : 0 ≤ r) : SpectrumRestricts (r • a) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff] at ha ⊢ nontriviality A intro x hx by_cases hr' : r = 0 · simp [hr'] at hx ⊢ exact hx.symm.le · lift r to ℝˣ using IsUnit.mk0 r hr' rw [← Units.smul_def, spectrum.unit_smul_eq_smul, Set.mem_smul_set_iff_inv_smul_mem] at hx refine le_of_smul_le_smul_left ?_ (inv_pos.mpr <| lt_of_le_of_ne hr <| ne_comm.mpr hr') simpa [Units.smul_def] using ha _ hx lemma spectrum_star_mul_self_nonneg {b : A} : ∀ x ∈ spectrum ℝ (star b * b), 0 ≤ x := by set a := star b * b have a_def : a = star b * b := rfl let a_neg : A := cfc (fun x ↦ (- ContinuousMap.id ℝ ⊔ 0) x) a set c := b * a_neg have h_eq_a_neg : - (star c * c) = a_neg ^ 3 := by simp only [c, a_neg, star_mul] rw [← mul_assoc, mul_assoc _ _ b, ← cfc_star, ← cfc_id' ℝ (star b * b), a_def, ← neg_mul] rw [← cfc_mul _ _ (star b * b) (by simp; fun_prop), neg_mul] simp only [ContinuousMap.coe_neg, ContinuousMap.coe_id, Pi.sup_apply, Pi.neg_apply, star_trivial] rw [← cfc_mul .., ← cfc_neg .., ← cfc_pow ..] congr ext x by_cases hx : x ≤ 0 · rw [← neg_nonneg] at hx simp [sup_eq_left.mpr hx, pow_succ] · rw [not_le, ← neg_neg_iff_pos] at hx simp [sup_eq_right.mpr hx.le] have h_c_spec₀ : SpectrumRestricts (- (star c * c)) (ContinuousMap.realToNNReal ·) := by simp only [SpectrumRestricts.nnreal_iff, h_eq_a_neg] rw [← cfc_pow _ _ (ha := .star_mul_self b)] simp only [cfc_map_spectrum (R := ℝ) (fun x => (-ContinuousMap.id ℝ ⊔ 0) x ^ 3) (star b * b)] rintro - ⟨x, -, rfl⟩ simp have c_eq := star_mul_self_add_self_mul_star c rw [← eq_sub_iff_add_eq', sub_eq_add_neg, ← sq, ← sq] at c_eq have h_c_spec₁ : SpectrumRestricts (c * star c) ContinuousMap.realToNNReal := by rw [c_eq] refine SpectrumRestricts.nnreal_add ?_ ?_ ?_ h_c_spec₀ · exact IsSelfAdjoint.smul (by rfl) <| ((ℜ c).prop.pow 2).add ((ℑ c).prop.pow 2) · exact (IsSelfAdjoint.star_mul_self c).neg · rw [← Nat.cast_smul_eq_nsmul ℝ] refine (ℜ c).2.sq_spectrumRestricts.nnreal_add ((ℜ c).2.pow 2) ((ℑ c).2.pow 2) (ℑ c).2.sq_spectrumRestricts |>.smul_of_nonneg <| by norm_num have h_c_spec₂ : SpectrumRestricts (star c * c) ContinuousMap.realToNNReal := by rw [SpectrumRestricts.nnreal_iff] at h_c_spec₁ ⊢ intro x hx replace hx := Set.subset_diff_union _ {(0 : ℝ)} hx rw [spectrum.nonzero_mul_eq_swap_mul, Set.diff_union_self, Set.union_singleton, Set.mem_insert_iff] at hx obtain (rfl | hx) := hx exacts [le_rfl, h_c_spec₁ x hx] rw [h_c_spec₂.eq_zero_of_neg (.star_mul_self c) h_c_spec₀, neg_zero] at h_eq_a_neg simp only [a_neg] at h_eq_a_neg rw [← cfc_pow _ _ (ha := .star_mul_self b), ← cfc_zero a (R := ℝ)] at h_eq_a_neg intro x hx by_contra! hx' rw [← neg_pos] at hx' apply (pow_pos hx' 3).ne have h_eqOn := eqOn_of_cfc_eq_cfc (ha := IsSelfAdjoint.star_mul_self b) h_eq_a_neg simpa [sup_eq_left.mpr hx'.le] using h_eqOn hx lemma IsSelfAdjoint.coe_mem_spectrum_complex {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra ℂ A] [ContinuousFunctionalCalculus ℂ (IsStarNormal : A → Prop)] {a : A} {x : ℝ} (ha : IsSelfAdjoint a := by cfc_tac) : (x : ℂ) ∈ spectrum ℂ a ↔ x ∈ spectrum ℝ a := by simp [← ha.spectrumRestricts.algebraMap_image] end SpectrumRestricts section NonnegSpectrumClass variable {A : Type*} [NormedRing A] [CompleteSpace A] variable [PartialOrder A] [StarRing A] [StarOrderedRing A] [CStarRing A] variable [NormedAlgebra ℂ A] [StarModule ℂ A] instance CStarRing.instNonnegSpectrumClass : NonnegSpectrumClass ℝ A := .of_spectrum_nonneg fun a ha ↦ by rw [StarOrderedRing.nonneg_iff] at ha induction ha using AddSubmonoid.closure_induction' with | mem x hx => obtain ⟨b, rfl⟩ := hx exact spectrum_star_mul_self_nonneg | one => nontriviality A simp | mul x x_mem y y_mem hx hy => rw [← SpectrumRestricts.nnreal_iff] at hx hy ⊢ rw [← StarOrderedRing.nonneg_iff] at x_mem y_mem exact hx.nnreal_add (.of_nonneg x_mem) (.of_nonneg y_mem) hy open ComplexOrder in instance CStarRing.instNonnegSpectrumClassComplexUnital : NonnegSpectrumClass ℂ A where quasispectrum_nonneg_of_nonneg a ha x := by rw [mem_quasispectrum_iff] refine (Or.elim · ge_of_eq fun hx ↦ ?_) obtain ⟨y, hy, rfl⟩ := (IsSelfAdjoint.of_nonneg ha).spectrumRestricts.algebraMap_image ▸ hx simpa using spectrum_nonneg_of_nonneg ha hy end NonnegSpectrumClass section SpectralOrder variable (A : Type*) [NormedRing A] [CompleteSpace A] [StarRing A] [CStarRing A] variable [NormedAlgebra ℂ A] [StarModule ℂ A] /-- The partial order on a unital C⋆-algebra defined by `x ≤ y` if and only if `y - x` is selfadjoint and has nonnegative spectrum. This is not declared as an instance because one may already have a partial order with better definitional properties. However, it can be useful to invoke this as an instance in proofs. -/ @[reducible] def CStarRing.spectralOrder : PartialOrder A where le x y := IsSelfAdjoint (y - x) ∧ SpectrumRestricts (y - x) ContinuousMap.realToNNReal le_refl := by simp only [sub_self, IsSelfAdjoint.zero, true_and, forall_const] rw [SpectrumRestricts.nnreal_iff] nontriviality A simp le_antisymm x y hxy hyx := by rw [← sub_eq_zero] exact hyx.2.eq_zero_of_neg hyx.1 (neg_sub x y ▸ hxy.2) le_trans x y z hxy hyz := ⟨by simpa using hyz.1.add hxy.1, by simpa using hyz.2.nnreal_add hyz.1 hxy.1 hxy.2⟩ /-- The `CStarRing.spectralOrder` on a unital C⋆-algebra is a `StarOrderedRing`. -/ lemma CStarRing.spectralOrderedRing : @StarOrderedRing A _ (CStarRing.spectralOrder A) _ := let _ := CStarRing.spectralOrder A { le_iff := by intro x y constructor · intro h obtain ⟨s, hs₁, _, hs₂⟩ := CFC.exists_sqrt_of_isSelfAdjoint_of_spectrumRestricts h.1 h.2 refine ⟨s ^ 2, ?_, by rwa [eq_sub_iff_add_eq', eq_comm] at hs₂⟩ exact AddSubmonoid.subset_closure ⟨s, by simp [hs₁.star_eq, sq]⟩ · rintro ⟨p, hp, rfl⟩ suffices IsSelfAdjoint p ∧ SpectrumRestricts p ContinuousMap.realToNNReal from ⟨by simpa using this.1, by simpa using this.2⟩ induction hp using AddSubmonoid.closure_induction' with | mem x hx => obtain ⟨s, rfl⟩ := hx refine ⟨IsSelfAdjoint.star_mul_self s, ?_⟩ rw [SpectrumRestricts.nnreal_iff] exact spectrum_star_mul_self_nonneg | one => rw [SpectrumRestricts.nnreal_iff] nontriviality A simp | mul x _ y _ hx hy => exact ⟨hx.1.add hy.1, hx.2.nnreal_add hx.1 hy.1 hy.2⟩ } end SpectralOrder section NonnegSpectrumClass variable {A : Type*} [NonUnitalNormedRing A] [CompleteSpace A] variable [PartialOrder A] [StarRing A] [StarOrderedRing A] [CStarRing A] variable [NormedSpace ℂ A] [IsScalarTower ℂ A A] [SMulCommClass ℂ A A] [StarModule ℂ A] instance CStarRing.instNonnegSpectrumClass' : NonnegSpectrumClass ℝ A where quasispectrum_nonneg_of_nonneg a ha := by rw [Unitization.quasispectrum_eq_spectrum_inr' _ ℂ] -- should this actually be an instance on the `Unitization`? (probably scoped) let _ := CStarRing.spectralOrder (Unitization ℂ A) have := CStarRing.spectralOrderedRing (Unitization ℂ A) apply spectrum_nonneg_of_nonneg rw [StarOrderedRing.nonneg_iff] at ha ⊢ have := AddSubmonoid.mem_map_of_mem (Unitization.inrNonUnitalStarAlgHom ℂ A) ha rw [AddMonoidHom.map_mclosure, ← Set.range_comp] at this apply AddSubmonoid.closure_mono ?_ this rintro _ ⟨s, rfl⟩ exact ⟨s, by simp⟩ end NonnegSpectrumClass /-! ### The restriction of a continuous functional calculus is equal to the original one -/ section RealEqComplex variable {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra ℂ A] [StarModule ℂ A] [ContinuousFunctionalCalculus ℂ (IsStarNormal : A → Prop)] [ContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop)] [UniqueContinuousFunctionalCalculus ℝ A] [UniqueContinuousFunctionalCalculus ℂ A] lemma cfcHom_real_eq_restrict {a : A} (ha : IsSelfAdjoint a) : cfcHom ha = ha.spectrumRestricts.starAlgHom (cfcHom ha.isStarNormal) (f := Complex.reCLM) := have := UniqueContinuousFunctionalCalculus.compactSpace_spectrum a (R := ℂ) ha.spectrumRestricts.cfcHom_eq_restrict Complex.isometry_ofReal.uniformEmbedding ha ha.isStarNormal lemma cfc_real_eq_complex {a : A} (f : ℝ → ℝ) (ha : IsSelfAdjoint a := by cfc_tac) : cfc f a = cfc (fun x ↦ f x.re : ℂ → ℂ) a := by have := UniqueContinuousFunctionalCalculus.compactSpace_spectrum a (R := ℂ) replace ha : IsSelfAdjoint a := ha -- hack to avoid issues caused by autoParam exact ha.spectrumRestricts.cfc_eq_restrict (f := Complex.reCLM) Complex.isometry_ofReal.uniformEmbedding ha ha.isStarNormal f end RealEqComplex section NNRealEqReal open NNReal variable {A : Type*} [TopologicalSpace A] [Ring A] [PartialOrder A] [StarRing A] [StarOrderedRing A] [Algebra ℝ A] [TopologicalRing A] [ContinuousStar A] [StarModule ℝ A] [ContinuousFunctionalCalculus ℝ (IsSelfAdjoint : A → Prop)] [ContinuousFunctionalCalculus ℝ≥0 ((0 : A) ≤ ·)] [UniqueContinuousFunctionalCalculus ℝ A] [NonnegSpectrumClass ℝ A] lemma cfcHom_nnreal_eq_restrict {a : A} (ha : 0 ≤ a) : cfcHom ha = (SpectrumRestricts.nnreal_of_nonneg ha).starAlgHom (cfcHom (IsSelfAdjoint.of_nonneg ha)) := by have := UniqueContinuousFunctionalCalculus.compactSpace_spectrum a (R := ℝ) apply (SpectrumRestricts.nnreal_of_nonneg ha).cfcHom_eq_restrict uniformEmbedding_subtype_val lemma cfc_nnreal_eq_real {a : A} (f : ℝ≥0 → ℝ≥0) (ha : 0 ≤ a := by cfc_tac) : cfc f a = cfc (fun x ↦ f x.toNNReal : ℝ → ℝ) a := by have := UniqueContinuousFunctionalCalculus.compactSpace_spectrum a (R := ℝ) replace ha : 0 ≤ a := ha -- hack to avoid issues caused by autoParam apply (SpectrumRestricts.nnreal_of_nonneg ha).cfc_eq_restrict uniformEmbedding_subtype_val ha (.of_nonneg ha) end NNRealEqReal end
Analysis\CStarAlgebra\ContinuousFunctionalCalculus\NonUnital.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Quasispectrum import Mathlib.Topology.ContinuousFunction.Compact import Mathlib.Topology.ContinuousFunction.ContinuousMapZero import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unital import Mathlib.Topology.UniformSpace.CompactConvergence /-! # The continuous functional calculus for non-unital algebras This file defines a generic API for the *continuous functional calculus* in *non-unital* algebras which is suitable in a wide range of settings. The design is intended to match as closely as possible that for unital algebras in `Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unital`. Changes to either file should be mirrored in its counterpart whenever possible. The underlying reasons for the design decisions in the unital case apply equally in the non-unital case. See the module documentation in that file for more information. A continuous functional calculus for an element `a : A` in a non-unital topological `R`-algebra is a continuous extension of the polynomial functional calculus (i.e., `Polynomial.aeval`) for polynomials with no constant term to continuous `R`-valued functions on `quasispectrum R a` which vanish at zero. More precisely, it is a continuous star algebra homomorphism `C(quasispectrum R a, R)₀ →⋆ₙₐ[R] A` that sends `(ContinuousMap.id R).restrict (quasispectrum R a)` to `a`. In all cases of interest (e.g., when `quasispectrum R a` is compact and `R` is `ℝ≥0`, `ℝ`, or `ℂ`), this is sufficient to uniquely determine the continuous functional calculus which is encoded in the `UniqueNonUnitalContinuousFunctionalCalculus` class. ## Main declarations + `NonUnitalContinuousFunctionalCalculus R (p : A → Prop)`: a class stating that every `a : A` satisfying `p a` has a non-unital star algebra homomorphism from the continuous `R`-valued functions on the `R`-quasispectrum of `a` vanishing at zero into the algebra `A`. This map is a closed embedding, and satisfies the **spectral mapping theorem**. + `cfcₙHom : p a → C(quasispectrum R a, R)₀ →⋆ₐ[R] A`: the underlying non-unital star algebra homomorphism for an element satisfying property `p`. + `cfcₙ : (R → R) → A → A`: an unbundled version of `cfcₙHom` which takes the junk value `0` when `cfcₙHom` is not defined. ## Main theorems + `cfcₙ_comp : cfcₙ (x ↦ g (f x)) a = cfcₙ g (cfcₙ f a)` -/ local notation "σₙ" => quasispectrum open scoped ContinuousMapZero /-- A non-unital star `R`-algebra `A` has a *continuous functional calculus* for elements satisfying the property `p : A → Prop` if + for every such element `a : A` there is a non-unital star algebra homomorphism `cfcₙHom : C(quasispectrum R a, R)₀ →⋆ₙₐ[R] A` sending the (restriction of) the identity map to `a`. + `cfcₙHom` is a closed embedding for which the quasispectrum of the image of function `f` is its range. + `cfcₙHom` preserves the property `p`. The property `p` is marked as an `outParam` so that the user need not specify it. In practice, + for `R := ℂ`, we choose `p := IsStarNormal`, + for `R := ℝ`, we choose `p := IsSelfAdjoint`, + for `R := ℝ≥0`, we choose `p := (0 ≤ ·)`. Instead of directly providing the data we opt instead for a `Prop` class. In all relevant cases, the continuous functional calculus is uniquely determined, and utilizing this approach prevents diamonds or problems arising from multiple instances. -/ class NonUnitalContinuousFunctionalCalculus (R : Type*) {A : Type*} (p : outParam (A → Prop)) [CommSemiring R] [Nontrivial R] [StarRing R] [MetricSpace R] [TopologicalSemiring R] [ContinuousStar R] [NonUnitalRing A] [StarRing A] [TopologicalSpace A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : Prop where predicate_zero : p 0 exists_cfc_of_predicate : ∀ a, p a → ∃ φ : C(σₙ R a, R)₀ →⋆ₙₐ[R] A, ClosedEmbedding φ ∧ φ ⟨(ContinuousMap.id R).restrict <| σₙ R a, rfl⟩ = a ∧ (∀ f, σₙ R (φ f) = Set.range f) ∧ ∀ f, p (φ f) -- TODO: try to unify with the unital version. The `ℝ≥0` case makes it tricky. /-- A class guaranteeing that the non-unital continuous functional calculus is uniquely determined by the properties that it is a continuous non-unital star algebra homomorphism mapping the (restriction of) the identity to `a`. This is the necessary tool used to establish `cfcₙHom_comp` and the more common variant `cfcₙ_comp`. This class will have instances in each of the common cases `ℂ`, `ℝ` and `ℝ≥0` as a consequence of the Stone-Weierstrass theorem. -/ class UniqueNonUnitalContinuousFunctionalCalculus (R A : Type*) [CommSemiring R] [StarRing R] [MetricSpace R] [TopologicalSemiring R] [ContinuousStar R] [NonUnitalRing A] [StarRing A] [TopologicalSpace A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] : Prop where eq_of_continuous_of_map_id (s : Set R) [CompactSpace s] [Zero s] (h0 : (0 : s) = (0 : R)) (φ ψ : C(s, R)₀ →⋆ₙₐ[R] A) (hφ : Continuous φ) (hψ : Continuous ψ) (h : φ (⟨.restrict s <| .id R, h0⟩) = ψ (⟨.restrict s <| .id R, h0⟩)) : φ = ψ compactSpace_quasispectrum (a : A) : CompactSpace (σₙ R a) section Main variable {R A : Type*} {p : A → Prop} [CommSemiring R] [Nontrivial R] [StarRing R] [MetricSpace R] variable [TopologicalSemiring R] [ContinuousStar R] [NonUnitalRing A] [StarRing A] variable [TopologicalSpace A] [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] variable [NonUnitalContinuousFunctionalCalculus R p] lemma NonUnitalStarAlgHom.ext_continuousMap [UniqueNonUnitalContinuousFunctionalCalculus R A] (a : A) (φ ψ : C(σₙ R a, R)₀ →⋆ₙₐ[R] A) (hφ : Continuous φ) (hψ : Continuous ψ) (h : φ ⟨.restrict (σₙ R a) <| .id R, rfl⟩ = ψ ⟨.restrict (σₙ R a) <| .id R, rfl⟩) : φ = ψ := have := UniqueNonUnitalContinuousFunctionalCalculus.compactSpace_quasispectrum (R := R) a UniqueNonUnitalContinuousFunctionalCalculus.eq_of_continuous_of_map_id _ (by simp) φ ψ hφ hψ h section cfcₙHom variable {a : A} (ha : p a) /-- The non-unital star algebra homomorphism underlying a instance of the continuous functional calculus for non-unital algebras; a version for continuous functions on the quasispectrum. In this case, the user must supply the fact that `a` satisfies the predicate `p`. While `NonUnitalContinuousFunctionalCalculus` is stated in terms of these homomorphisms, in practice the user should instead prefer `cfcₙ` over `cfcₙHom`. -/ noncomputable def cfcₙHom : C(σₙ R a, R)₀ →⋆ₙₐ[R] A := (NonUnitalContinuousFunctionalCalculus.exists_cfc_of_predicate a ha).choose lemma cfcₙHom_closedEmbedding : ClosedEmbedding <| (cfcₙHom ha : C(σₙ R a, R)₀ →⋆ₙₐ[R] A) := (NonUnitalContinuousFunctionalCalculus.exists_cfc_of_predicate a ha).choose_spec.1 lemma cfcₙHom_id : cfcₙHom ha ⟨(ContinuousMap.id R).restrict <| σₙ R a, rfl⟩ = a := (NonUnitalContinuousFunctionalCalculus.exists_cfc_of_predicate a ha).choose_spec.2.1 /-- The **spectral mapping theorem** for the non-unital continuous functional calculus. -/ lemma cfcₙHom_map_quasispectrum (f : C(σₙ R a, R)₀) : σₙ R (cfcₙHom ha f) = Set.range f := (NonUnitalContinuousFunctionalCalculus.exists_cfc_of_predicate a ha).choose_spec.2.2.1 f lemma cfcₙHom_predicate (f : C(σₙ R a, R)₀) : p (cfcₙHom ha f) := (NonUnitalContinuousFunctionalCalculus.exists_cfc_of_predicate a ha).choose_spec.2.2.2 f lemma cfcₙHom_eq_of_continuous_of_map_id [UniqueNonUnitalContinuousFunctionalCalculus R A] (φ : C(σₙ R a, R)₀ →⋆ₙₐ[R] A) (hφ₁ : Continuous φ) (hφ₂ : φ ⟨.restrict (σₙ R a) <| .id R, rfl⟩ = a) : cfcₙHom ha = φ := (cfcₙHom ha).ext_continuousMap a φ (cfcₙHom_closedEmbedding ha).continuous hφ₁ <| by rw [cfcₙHom_id ha, hφ₂] theorem cfcₙHom_comp [UniqueNonUnitalContinuousFunctionalCalculus R A] (f : C(σₙ R a, R)₀) (f' : C(σₙ R a, σₙ R (cfcₙHom ha f))₀) (hff' : ∀ x, f x = f' x) (g : C(σₙ R (cfcₙHom ha f), R)₀) : cfcₙHom ha (g.comp f') = cfcₙHom (cfcₙHom_predicate ha f) g := by let ψ : C(σₙ R (cfcₙHom ha f), R)₀ →⋆ₙₐ[R] C(σₙ R a, R)₀ := { toFun := (ContinuousMapZero.comp · f') map_smul' := fun _ _ ↦ rfl map_add' := fun _ _ ↦ rfl map_mul' := fun _ _ ↦ rfl map_zero' := rfl map_star' := fun _ ↦ rfl } let φ : C(σₙ R (cfcₙHom ha f), R)₀ →⋆ₙₐ[R] A := (cfcₙHom ha).comp ψ suffices cfcₙHom (cfcₙHom_predicate ha f) = φ from DFunLike.congr_fun this.symm g refine cfcₙHom_eq_of_continuous_of_map_id (cfcₙHom_predicate ha f) φ ?_ ?_ · refine (cfcₙHom_closedEmbedding ha).continuous.comp <| continuous_induced_rng.mpr ?_ exact f'.toContinuousMap.continuous_comp_left.comp continuous_induced_dom · simp only [φ, ψ, NonUnitalStarAlgHom.comp_apply, NonUnitalStarAlgHom.coe_mk', NonUnitalAlgHom.coe_mk] congr ext x simp [hff'] end cfcₙHom section CFCn open Classical in /-- This is the *continuous functional calculus* of an element `a : A` in a non-unital algebra applied to bare functions. When either `a` does not satisfy the predicate `p` (i.e., `a` is not `IsStarNormal`, `IsSelfAdjoint`, or `0 ≤ a` when `R` is `ℂ`, `ℝ`, or `ℝ≥0`, respectively), or when `f : R → R` is not continuous on the quasispectrum of `a` or `f 0 ≠ 0`, then `cfcₙ f a` returns the junk value `0`. This is the primary declaration intended for widespread use of the continuous functional calculus for non-unital algebras, and all the API applies to this declaration. For more information, see the module documentation for `Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unital`. -/ noncomputable irreducible_def cfcₙ (f : R → R) (a : A) : A := if h : p a ∧ ContinuousOn f (σₙ R a) ∧ f 0 = 0 then cfcₙHom h.1 ⟨⟨_, h.2.1.restrict⟩, h.2.2⟩ else 0 variable (f g : R → R) (a : A) variable (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) variable (hg : ContinuousOn g (σₙ R a) := by cfc_cont_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) variable (ha : p a := by cfc_tac) lemma cfcₙ_apply : cfcₙ f a = cfcₙHom (a := a) ha ⟨⟨_, hf.restrict⟩, hf0⟩ := by rw [cfcₙ_def, dif_pos ⟨ha, hf, hf0⟩] lemma cfcₙ_apply_pi {ι : Type*} (f : ι → R → R) (a : A) (ha := by cfc_tac) (hf : ∀ i, ContinuousOn (f i) (σₙ R a) := by cfc_cont_tac) (hf0 : ∀ i, f i 0 = 0 := by cfc_zero_tac) : (fun i => cfcₙ (f i) a) = (fun i => cfcₙHom (a := a) ha ⟨⟨_, (hf i).restrict⟩, hf0 i⟩) := by ext i simp only [cfcₙ_apply (f i) a (hf i) (hf0 i)] lemma cfcₙ_apply_of_not_and_and {f : R → R} (a : A) (ha : ¬ (p a ∧ ContinuousOn f (σₙ R a) ∧ f 0 = 0)) : cfcₙ f a = 0 := by rw [cfcₙ_def, dif_neg ha] lemma cfcₙ_apply_of_not_predicate {f : R → R} (a : A) (ha : ¬ p a) : cfcₙ f a = 0 := by rw [cfcₙ_def, dif_neg (not_and_of_not_left _ ha)] lemma cfcₙ_apply_of_not_continuousOn {f : R → R} (a : A) (hf : ¬ ContinuousOn f (σₙ R a)) : cfcₙ f a = 0 := by rw [cfcₙ_def, dif_neg (not_and_of_not_right _ (not_and_of_not_left _ hf))] lemma cfcₙ_apply_of_not_map_zero {f : R → R} (a : A) (hf : ¬ f 0 = 0) : cfcₙ f a = 0 := by rw [cfcₙ_def, dif_neg (not_and_of_not_right _ (not_and_of_not_right _ hf))] lemma cfcₙHom_eq_cfcₙ_extend {a : A} (g : R → R) (ha : p a) (f : C(σₙ R a, R)₀) : cfcₙHom ha f = cfcₙ (Function.extend Subtype.val f g) a := by have h : f = (σₙ R a).restrict (Function.extend Subtype.val f g) := by ext; simp [Subtype.val_injective.extend_apply] have hg : ContinuousOn (Function.extend Subtype.val f g) (σₙ R a) := continuousOn_iff_continuous_restrict.mpr <| h ▸ map_continuous f have hg0 : (Function.extend Subtype.val f g) 0 = 0 := by rw [← quasispectrum.coe_zero (R := R) a, Subtype.val_injective.extend_apply] exact map_zero f rw [cfcₙ_apply ..] congr! lemma cfcₙ_cases (P : A → Prop) (a : A) (f : R → R) (h₀ : P 0) (haf : ∀ (hf : ContinuousOn f (σₙ R a)) h0 ha, P (cfcₙHom ha ⟨⟨_, hf.restrict⟩, h0⟩)) : P (cfcₙ f a) := by by_cases h : ContinuousOn f (σₙ R a) ∧ f 0 = 0 ∧ p a · rw [cfcₙ_apply f a h.1 h.2.1 h.2.2] exact haf h.1 h.2.1 h.2.2 · simp only [not_and_or] at h obtain (h | h | h) := h · rwa [cfcₙ_apply_of_not_continuousOn _ h] · rwa [cfcₙ_apply_of_not_map_zero _ h] · rwa [cfcₙ_apply_of_not_predicate _ h] variable (R) in lemma cfcₙ_id : cfcₙ (id : R → R) a = a := cfcₙ_apply (id : R → R) a ▸ cfcₙHom_id (p := p) ha variable (R) in lemma cfcₙ_id' : cfcₙ (fun x : R ↦ x) a = a := cfcₙ_id R a /-- The **spectral mapping theorem** for the non-unital continuous functional calculus. -/ lemma cfcₙ_map_quasispectrum : σₙ R (cfcₙ f a) = f '' σₙ R a := by simp [cfcₙ_apply f a, cfcₙHom_map_quasispectrum (p := p)] variable (R) in lemma cfcₙ_predicate_zero : p 0 := NonUnitalContinuousFunctionalCalculus.predicate_zero (R := R) lemma cfcₙ_predicate (f : R → R) (a : A) : p (cfcₙ f a) := cfcₙ_cases p a f (cfcₙ_predicate_zero R) fun _ _ _ ↦ cfcₙHom_predicate .. lemma cfcₙ_congr {f g : R → R} {a : A} (hfg : (σₙ R a).EqOn f g) : cfcₙ f a = cfcₙ g a := by by_cases h : p a ∧ ContinuousOn g (σₙ R a) ∧ g 0 = 0 · rw [cfcₙ_apply f a (h.2.1.congr hfg) (hfg (quasispectrum.zero_mem R a) ▸ h.2.2) h.1, cfcₙ_apply g a h.2.1 h.2.2 h.1] congr exact Set.restrict_eq_iff.mpr hfg · simp only [not_and_or] at h obtain (ha | hg | h0) := h · simp [cfcₙ_apply_of_not_predicate a ha] · rw [cfcₙ_apply_of_not_continuousOn a hg, cfcₙ_apply_of_not_continuousOn] exact fun hf ↦ hg (hf.congr hfg.symm) · rw [cfcₙ_apply_of_not_map_zero a h0, cfcₙ_apply_of_not_map_zero] exact fun hf ↦ h0 (hfg (quasispectrum.zero_mem R a) ▸ hf) lemma eqOn_of_cfcₙ_eq_cfcₙ {f g : R → R} {a : A} (h : cfcₙ f a = cfcₙ g a) (ha : p a := by cfc_tac) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (hg : ContinuousOn g (σₙ R a) := by cfc_cont_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) : (σₙ R a).EqOn f g := by rw [cfcₙ_apply f a, cfcₙ_apply g a] at h have := (cfcₙHom_closedEmbedding (show p a from ha) (R := R)).inj h intro x hx congrm($(this) ⟨x, hx⟩) lemma cfcₙ_eq_cfcₙ_iff_eqOn {f g : R → R} {a : A} (ha : p a := by cfc_tac) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (hg : ContinuousOn g (σₙ R a) := by cfc_cont_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) : cfcₙ f a = cfcₙ g a ↔ (σₙ R a).EqOn f g := ⟨eqOn_of_cfcₙ_eq_cfcₙ, cfcₙ_congr⟩ variable (R) @[simp] lemma cfcₙ_zero : cfcₙ (0 : R → R) a = 0 := by by_cases ha : p a · exact cfcₙ_apply (0 : R → R) a ▸ map_zero (cfcₙHom ha) · rw [cfcₙ_apply_of_not_predicate a ha] @[simp] lemma cfcₙ_const_zero : cfcₙ (fun _ : R ↦ 0) a = 0 := cfcₙ_zero R a variable {R} lemma cfcₙ_mul : cfcₙ (fun x ↦ f x * g x) a = cfcₙ f a * cfcₙ g a := by by_cases ha : p a · rw [cfcₙ_apply f a, cfcₙ_apply g a, ← map_mul, cfcₙ_apply _ a] congr · simp [cfcₙ_apply_of_not_predicate a ha] lemma cfcₙ_add : cfcₙ (fun x ↦ f x + g x) a = cfcₙ f a + cfcₙ g a := by by_cases ha : p a · rw [cfcₙ_apply f a, cfcₙ_apply g a, cfcₙ_apply _ a] simp_rw [← map_add] congr · simp [cfcₙ_apply_of_not_predicate a ha] open Finset in lemma cfcₙ_sum {ι : Type*} (f : ι → R → R) (a : A) (s : Finset ι) (hf : ∀ i ∈ s, ContinuousOn (f i) (σₙ R a) := by cfc_cont_tac) (hf0 : ∀ i ∈ s, f i 0 = 0 := by cfc_zero_tac) : cfcₙ (∑ i in s, f i) a = ∑ i in s, cfcₙ (f i) a := by by_cases ha : p a · have hsum : s.sum f = fun z => ∑ i ∈ s, f i z := by ext; simp have hf' : ContinuousOn (∑ i : s, f i) (σₙ R a) := by rw [sum_coe_sort s, hsum] exact continuousOn_finset_sum s fun i hi => hf i hi rw [← sum_coe_sort s, ← sum_coe_sort s] rw [cfcₙ_apply_pi _ a _ (fun ⟨i, hi⟩ => hf i hi), ← map_sum, cfcₙ_apply _ a hf'] congr 1 ext simp · simp [cfcₙ_apply_of_not_predicate a ha] open Finset in lemma cfcₙ_sum_univ {ι : Type*} [Fintype ι] (f : ι → R → R) (a : A) (hf : ∀ i, ContinuousOn (f i) (σₙ R a) := by cfc_cont_tac) (hf0 : ∀ i, f i 0 = 0 := by cfc_zero_tac) : cfcₙ (∑ i, f i) a = ∑ i, cfcₙ (f i) a := cfcₙ_sum f a _ (fun i _ ↦ hf i) (fun i _ ↦ hf0 i) lemma cfcₙ_smul {S : Type*} [SMulZeroClass S R] [ContinuousConstSMul S R] [SMulZeroClass S A] [IsScalarTower S R A] [IsScalarTower S R (R → R)] (s : S) (f : R → R) (a : A) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (h0 : f 0 = 0 := by cfc_zero_tac) : cfcₙ (fun x ↦ s • f x) a = s • cfcₙ f a := by by_cases ha : p a · rw [cfcₙ_apply f a, cfcₙ_apply _ a] simp_rw [← Pi.smul_def, ← smul_one_smul R s _] rw [← map_smul] congr · simp [cfcₙ_apply_of_not_predicate a ha] lemma cfcₙ_const_mul (r : R) (f : R → R) (a : A) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (h0 : f 0 = 0 := by cfc_zero_tac) : cfcₙ (fun x ↦ r * f x) a = r • cfcₙ f a := cfcₙ_smul r f a lemma cfcₙ_star : cfcₙ (fun x ↦ star (f x)) a = star (cfcₙ f a) := by by_cases h : p a ∧ ContinuousOn f (σₙ R a) ∧ f 0 = 0 · obtain ⟨ha, hf, h0⟩ := h rw [cfcₙ_apply f a, ← map_star, cfcₙ_apply _ a] congr · simp only [not_and_or] at h obtain (ha | hf | h0) := h · simp [cfcₙ_apply_of_not_predicate a ha] · rw [cfcₙ_apply_of_not_continuousOn a hf, cfcₙ_apply_of_not_continuousOn, star_zero] exact fun hf_star ↦ hf <| by simpa using hf_star.star · rw [cfcₙ_apply_of_not_map_zero a h0, cfcₙ_apply_of_not_map_zero, star_zero] exact fun hf0 ↦ h0 <| by simpa using congr(star $(hf0)) lemma cfcₙ_smul_id {S : Type*} [SMulZeroClass S R] [ContinuousConstSMul S R] [SMulZeroClass S A] [IsScalarTower S R A] [IsScalarTower S R (R → R)] (s : S) (a : A) (ha : p a := by cfc_tac) : cfcₙ (s • · : R → R) a = s • a := by rw [cfcₙ_smul s _ a, cfcₙ_id' R a] lemma cfcₙ_const_mul_id (r : R) (a : A) (ha : p a := by cfc_tac) : cfcₙ (r * ·) a = r • a := cfcₙ_smul_id r a lemma cfcₙ_star_id : cfcₙ (star · : R → R) a = star a := by rw [cfcₙ_star _ a, cfcₙ_id' R a] variable [UniqueNonUnitalContinuousFunctionalCalculus R A] lemma cfcₙ_comp (g f : R → R) (a : A) (hg : ContinuousOn g (f '' σₙ R a) := by cfc_cont_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ (g ∘ f) a = cfcₙ g (cfcₙ f a) := by have := hg.comp hf <| (σₙ R a).mapsTo_image f have sp_eq : σₙ R (cfcₙHom (show p a from ha) ⟨ContinuousMap.mk _ hf.restrict, hf0⟩) = f '' (σₙ R a) := by rw [cfcₙHom_map_quasispectrum (by exact ha) _] ext simp rw [cfcₙ_apply .., cfcₙ_apply f a, cfcₙ_apply _ (by convert hg) (ha := cfcₙHom_predicate (show p a from ha) _) , ← cfcₙHom_comp _ _] swap · exact ⟨.mk _ <| hf.restrict.codRestrict fun x ↦ by rw [sp_eq]; use x.1; simp, Subtype.ext hf0⟩ · congr · exact fun _ ↦ rfl lemma cfcₙ_comp' (g f : R → R) (a : A) (hg : ContinuousOn g (f '' σₙ R a) := by cfc_cont_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ (g <| f ·) a = cfcₙ g (cfcₙ f a) := cfcₙ_comp g f a lemma cfcₙ_comp_smul {S : Type*} [SMulZeroClass S R] [ContinuousConstSMul S R] [SMulZeroClass S A] [IsScalarTower S R A] [IsScalarTower S R (R → R)] (s : S) (f : R → R) (a : A) (hf : ContinuousOn f ((s • ·) '' (σₙ R a)) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ (f <| s • ·) a = cfcₙ f (s • a) := by rw [cfcₙ_comp' f (s • ·) a, cfcₙ_smul_id s a] lemma cfcₙ_comp_const_mul (r : R) (f : R → R) (a : A) (hf : ContinuousOn f ((r * ·) '' (σₙ R a)) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ (f <| r * ·) a = cfcₙ f (r • a) := by rw [cfcₙ_comp' f (r * ·) a, cfcₙ_const_mul_id r a] lemma cfcₙ_comp_star (hf : ContinuousOn f (star '' (σₙ R a)) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ (f <| star ·) a = cfcₙ f (star a) := by rw [cfcₙ_comp' f star a, cfcₙ_star_id a] lemma CFC.eq_zero_of_quasispectrum_eq_zero (h_spec : σₙ R a ⊆ {0}) (ha : p a := by cfc_tac) : a = 0 := by simpa [cfcₙ_id R a] using cfcₙ_congr (a := a) (f := id) (g := fun _ : R ↦ 0) fun x ↦ by simp_all lemma CFC.quasispectrum_zero_eq : σₙ R (0 : A) = {0} := by refine Set.eq_singleton_iff_unique_mem.mpr ⟨quasispectrum.zero_mem R 0, fun x hx ↦ ?_⟩ rw [← cfcₙ_zero R (0 : A), cfcₙ_map_quasispectrum _ _ (by cfc_cont_tac) (by cfc_zero_tac) (cfcₙ_predicate_zero R)] at hx simp_all @[simp] lemma cfcₙ_apply_zero {f : R → R} : cfcₙ f (0 : A) = 0 := by by_cases hf0 : f 0 = 0 · nth_rw 2 [← cfcₙ_zero R 0] apply cfcₙ_congr simpa [CFC.quasispectrum_zero_eq] · exact cfcₙ_apply_of_not_map_zero _ hf0 instance IsStarNormal.cfcₙ_map (f : R → R) (a : A) : IsStarNormal (cfcₙ f a) where star_comm_self := by refine cfcₙ_cases (fun x ↦ Commute (star x) x) _ _ (Commute.zero_right _) fun _ _ _ ↦ ?_ simp only [Commute, SemiconjBy] rw [← cfcₙ_apply f a, ← cfcₙ_star, ← cfcₙ_mul .., ← cfcₙ_mul ..] congr! 2 exact mul_comm _ _ end CFCn end Main section Neg variable {R A : Type*} {p : A → Prop} [CommRing R] [Nontrivial R] [StarRing R] [MetricSpace R] variable [TopologicalRing R] [ContinuousStar R] [TopologicalSpace A] [NonUnitalRing A] [StarRing A] variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] variable [NonUnitalContinuousFunctionalCalculus R p] variable (f g : R → R) (a : A) variable (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) variable (hg : ContinuousOn g (σₙ R a) := by cfc_cont_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) lemma cfcₙ_sub : cfcₙ (fun x ↦ f x - g x) a = cfcₙ f a - cfcₙ g a := by by_cases ha : p a · rw [cfcₙ_apply f a, cfcₙ_apply g a, ← map_sub, cfcₙ_apply ..] congr · simp [cfcₙ_apply_of_not_predicate a ha] lemma cfcₙ_neg : cfcₙ (fun x ↦ - (f x)) a = - (cfcₙ f a) := by by_cases h : p a ∧ ContinuousOn f (σₙ R a) ∧ f 0 = 0 · obtain ⟨ha, hf, h0⟩ := h rw [cfcₙ_apply f a, ← map_neg, cfcₙ_apply ..] congr · simp only [not_and_or] at h obtain (ha | hf | h0) := h · simp [cfcₙ_apply_of_not_predicate a ha] · rw [cfcₙ_apply_of_not_continuousOn a hf, cfcₙ_apply_of_not_continuousOn, neg_zero] exact fun hf_neg ↦ hf <| by simpa using hf_neg.neg · rw [cfcₙ_apply_of_not_map_zero a h0, cfcₙ_apply_of_not_map_zero, neg_zero] exact (h0 <| neg_eq_zero.mp ·) lemma cfcₙ_neg_id (ha : p a := by cfc_tac) : cfcₙ (- · : R → R) a = -a := by rw [cfcₙ_neg .., cfcₙ_id' R a] variable [UniqueNonUnitalContinuousFunctionalCalculus R A] lemma cfcₙ_comp_neg (hf : ContinuousOn f ((- ·) '' (σₙ R a)) := by cfc_cont_tac) (h0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ (f <| - ·) a = cfcₙ f (-a) := by rw [cfcₙ_comp' .., cfcₙ_neg_id _] end Neg section Order section Semiring variable {R A : Type*} {p : A → Prop} [OrderedCommSemiring R] [Nontrivial R] variable [StarRing R] [StarOrderedRing R] [MetricSpace R] [TopologicalSemiring R] [ContinuousStar R] variable [∀ (α) [Zero α] [TopologicalSpace α], StarOrderedRing C(α, R)₀] variable [TopologicalSpace A] [NonUnitalRing A] [StarRing A] [PartialOrder A] [StarOrderedRing A] variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable [NonUnitalContinuousFunctionalCalculus R p] [NonnegSpectrumClass R A] lemma cfcₙHom_mono {a : A} (ha : p a) {f g : C(σₙ R a, R)₀} (hfg : f ≤ g) : cfcₙHom ha f ≤ cfcₙHom ha g := OrderHomClass.mono (cfcₙHom ha) hfg lemma cfcₙHom_nonneg_iff {a : A} (ha : p a) {f : C(σₙ R a, R)₀} : 0 ≤ cfcₙHom ha f ↔ 0 ≤ f := by constructor · exact fun hf x ↦ (cfcₙHom_map_quasispectrum ha (R := R) _ ▸ quasispectrum_nonneg_of_nonneg (cfcₙHom ha f) hf) _ ⟨x, rfl⟩ · simpa using (cfcₙHom_mono ha (f := 0) (g := f) ·) lemma cfcₙ_mono {f g : R → R} {a : A} (h : ∀ x ∈ σₙ R a, f x ≤ g x) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hg : ContinuousOn g (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) : cfcₙ f a ≤ cfcₙ g a := by by_cases ha : p a · rw [cfcₙ_apply f a, cfcₙ_apply g a] exact cfcₙHom_mono ha fun x ↦ h x.1 x.2 · simp only [cfcₙ_apply_of_not_predicate _ ha, le_rfl] lemma cfcₙ_nonneg_iff (f : R → R) (a : A) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (h0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : 0 ≤ cfcₙ f a ↔ ∀ x ∈ σₙ R a, 0 ≤ f x := by rw [cfcₙ_apply .., cfcₙHom_nonneg_iff, ContinuousMapZero.le_def] simp only [ContinuousMapZero.coe_mk, ContinuousMap.coe_mk, Set.restrict_apply, Subtype.forall] congr! lemma StarOrderedRing.nonneg_iff_quasispectrum_nonneg (a : A) (ha : p a := by cfc_tac) : 0 ≤ a ↔ ∀ x ∈ quasispectrum R a, 0 ≤ x := by have := cfcₙ_nonneg_iff (id : R → R) a (by fun_prop) simpa [cfcₙ_id _ a ha] using this lemma cfcₙ_nonneg {f : R → R} {a : A} (h : ∀ x ∈ σₙ R a, 0 ≤ f x) : 0 ≤ cfcₙ f a := by by_cases hf : ContinuousOn f (σₙ R a) ∧ f 0 = 0 · obtain ⟨h₁, h₂⟩ := hf simpa using cfcₙ_mono h · simp only [not_and_or] at hf obtain (hf | hf) := hf · simp only [cfcₙ_apply_of_not_continuousOn _ hf, le_rfl] · simp only [cfcₙ_apply_of_not_map_zero _ hf, le_rfl] lemma cfcₙ_nonpos (f : R → R) (a : A) (h : ∀ x ∈ σₙ R a, f x ≤ 0) : cfcₙ f a ≤ 0 := by by_cases hf : ContinuousOn f (σₙ R a) ∧ f 0 = 0 · obtain ⟨h₁, h₂⟩ := hf simpa using cfcₙ_mono h · simp only [not_and_or] at hf obtain (hf | hf) := hf · simp only [cfcₙ_apply_of_not_continuousOn _ hf, le_rfl] · simp only [cfcₙ_apply_of_not_map_zero _ hf, le_rfl] end Semiring section Ring variable {R A : Type*} {p : A → Prop} [OrderedCommRing R] [Nontrivial R] variable [StarRing R] [StarOrderedRing R] [MetricSpace R] [TopologicalRing R] [ContinuousStar R] variable [∀ (α) [Zero α] [TopologicalSpace α], StarOrderedRing C(α, R)₀] variable [TopologicalSpace A] [NonUnitalRing A] [StarRing A] [PartialOrder A] [StarOrderedRing A] variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] variable [NonUnitalContinuousFunctionalCalculus R p] [NonnegSpectrumClass R A] lemma cfcₙHom_le_iff {a : A} (ha : p a) {f g : C(σₙ R a, R)₀} : cfcₙHom ha f ≤ cfcₙHom ha g ↔ f ≤ g := by rw [← sub_nonneg, ← map_sub, cfcₙHom_nonneg_iff, sub_nonneg] lemma cfcₙ_le_iff (f g : R → R) (a : A) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hg : ContinuousOn g (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) (hg0 : g 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ f a ≤ cfcₙ g a ↔ ∀ x ∈ σₙ R a, f x ≤ g x := by rw [cfcₙ_apply f a, cfcₙ_apply g a, cfcₙHom_le_iff (show p a from ha), ContinuousMapZero.le_def] simp lemma cfcₙ_nonpos_iff (f : R → R) (a : A) (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (h0 : f 0 = 0 := by cfc_zero_tac) (ha : p a := by cfc_tac) : cfcₙ f a ≤ 0 ↔ ∀ x ∈ σₙ R a, f x ≤ 0 := by simp_rw [← neg_nonneg, ← cfcₙ_neg] exact cfcₙ_nonneg_iff (fun x ↦ -f x) a end Ring end Order /-! ### Obtain a non-unital continuous functional calculus from a unital one -/ section UnitalToNonUnital open ContinuousMapZero Set Uniformity ContinuousMap variable {R A : Type*} {p : A → Prop} [Semifield R] [StarRing R] [MetricSpace R] [CompleteSpace R] variable [TopologicalSemiring R] [ContinuousStar R] [Ring A] [StarRing A] [TopologicalSpace A] variable [Algebra R A] [ContinuousFunctionalCalculus R p] variable [h_cpct : ∀ a : A, CompactSpace (spectrum R a)] variable (R) in /-- The non-unital continuous functional calculus obtained by restricting a unital calculus to functions that map zero to zero. This is an auxiliary definition and is not intended for use outside this file. The equality between the non-unital and unital calculi in this case is encoded in the lemma `cfcₙ_eq_cfc`. -/ noncomputable def cfcₙHom_of_cfcHom {a : A} (ha : p a) : C(σₙ R a, R)₀ →⋆ₙₐ[R] A := let e := ContinuousMapZero.toContinuousMapHom (X := σₙ R a) (R := R) let f : C(spectrum R a, quasispectrum R a) := ⟨_, continuous_inclusion <| spectrum_subset_quasispectrum R a⟩ let ψ := ContinuousMap.compStarAlgHom' R R f (cfcHom ha (R := R) : C(spectrum R a, R) →⋆ₙₐ[R] A).comp <| (ψ : C(σₙ R a, R) →⋆ₙₐ[R] C(spectrum R a, R)).comp e lemma closedEmbedding_cfcₙHom_of_cfcHom {a : A} (ha : p a) : ClosedEmbedding (cfcₙHom_of_cfcHom R ha) := by let f : C(spectrum R a, σₙ R a) := ⟨_, continuous_inclusion <| spectrum_subset_quasispectrum R a⟩ have h_cpct' : CompactSpace (σₙ R a) := by specialize h_cpct a simp_rw [← isCompact_iff_compactSpace, quasispectrum_eq_spectrum_union_zero] at h_cpct ⊢ exact h_cpct.union isCompact_singleton refine (cfcHom_closedEmbedding ha).comp <| (UniformInducing.uniformEmbedding ⟨?_⟩).toClosedEmbedding have := uniformSpace_eq_inf_precomp_of_cover (β := R) f (0 : C(Unit, σₙ R a)) (map_continuous f).isProperMap (map_continuous 0).isProperMap <| by simp only [← Subtype.val_injective.image_injective.eq_iff, f, ContinuousMap.coe_mk, ContinuousMap.coe_zero, range_zero, image_union, image_singleton, quasispectrum.coe_zero, ← range_comp, val_comp_inclusion, image_univ, Subtype.range_coe, quasispectrum_eq_spectrum_union_zero] simp_rw [ContinuousMapZero.instUniformSpace, this, uniformity_comap, @inf_uniformity _ (.comap _ _) (.comap _ _), uniformity_comap, Filter.comap_inf, Filter.comap_comap] refine .symm <| inf_eq_left.mpr <| le_top.trans <| eq_top_iff.mp ?_ have : ∀ U ∈ 𝓤 (C(Unit, R)), (0, 0) ∈ U := fun U hU ↦ refl_mem_uniformity hU convert Filter.comap_const_of_mem this with ⟨u, v⟩ <;> ext ⟨x, rfl⟩ <;> [exact map_zero u; exact map_zero v] lemma cfcₙHom_of_cfcHom_map_quasispectrum {a : A} (ha : p a) : ∀ f : C(σₙ R a, R)₀, σₙ R (cfcₙHom_of_cfcHom R ha f) = range f := by intro f simp only [cfcₙHom_of_cfcHom] rw [quasispectrum_eq_spectrum_union_zero] simp only [NonUnitalStarAlgHom.comp_assoc, NonUnitalStarAlgHom.comp_apply, NonUnitalStarAlgHom.coe_coe] rw [cfcHom_map_spectrum ha] ext x constructor · rintro (⟨x, rfl⟩ | rfl) · exact ⟨⟨x.1, spectrum_subset_quasispectrum R a x.2⟩, rfl⟩ · exact ⟨0, map_zero f⟩ · rintro ⟨x, rfl⟩ have hx := x.2 simp_rw [quasispectrum_eq_spectrum_union_zero R a] at hx obtain (hx | hx) := hx · exact Or.inl ⟨⟨x.1, hx⟩, rfl⟩ · apply Or.inr simp only [Set.mem_singleton_iff] at hx ⊢ rw [show x = 0 from Subtype.val_injective hx, map_zero] instance ContinuousFunctionalCalculus.toNonUnital : NonUnitalContinuousFunctionalCalculus R p where predicate_zero := cfc_predicate_zero R exists_cfc_of_predicate _ ha := ⟨cfcₙHom_of_cfcHom R ha, closedEmbedding_cfcₙHom_of_cfcHom ha, cfcHom_id ha, cfcₙHom_of_cfcHom_map_quasispectrum ha, fun _ ↦ cfcHom_predicate ha _⟩ lemma cfcₙHom_eq_cfcₙHom_of_cfcHom [UniqueNonUnitalContinuousFunctionalCalculus R A] {a : A} (ha : p a) : cfcₙHom (R := R) ha = cfcₙHom_of_cfcHom R ha := by have h_cpct' : CompactSpace (σₙ R a) := by specialize h_cpct a simp_rw [← isCompact_iff_compactSpace, quasispectrum_eq_spectrum_union_zero] at h_cpct ⊢ exact h_cpct.union isCompact_singleton refine UniqueNonUnitalContinuousFunctionalCalculus.eq_of_continuous_of_map_id (σₙ R a) ?_ _ _ ?_ ?_ ?_ · simp · exact (cfcₙHom_closedEmbedding (R := R) ha).continuous · exact (closedEmbedding_cfcₙHom_of_cfcHom ha).continuous · simpa only [cfcₙHom_id (R := R) ha] using (cfcHom_id ha).symm /-- When `cfc` is applied to a function that maps zero to zero, it is equivalent to using `cfcₙ`. -/ lemma cfcₙ_eq_cfc [UniqueNonUnitalContinuousFunctionalCalculus R A] {f : R → R} {a : A} (hf : ContinuousOn f (σₙ R a) := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) : cfcₙ f a = cfc f a := by by_cases ha : p a · have hf' := hf.mono <| spectrum_subset_quasispectrum R a rw [cfc_apply f a ha hf', cfcₙ_apply f a hf, cfcₙHom_eq_cfcₙHom_of_cfcHom, cfcₙHom_of_cfcHom] dsimp only [NonUnitalStarAlgHom.comp_apply, toContinuousMapHom_apply, NonUnitalStarAlgHom.coe_coe, compStarAlgHom'_apply] congr · simp [cfc_apply_of_not_predicate a ha, cfcₙ_apply_of_not_predicate (R := R) a ha] end UnitalToNonUnital
Analysis\CStarAlgebra\ContinuousFunctionalCalculus\Order.lean
/- Copyright (c) 2024 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Instances import Mathlib.Topology.ContinuousFunction.StarOrdered import Mathlib.Analysis.CStarAlgebra.Unitization /-! # Facts about star-ordered rings that depend on the continuous functional calculus This file contains various basic facts about star-ordered rings (i.e. mainly C⋆-algebras) that depend on the continuous functional calculus. We also put an order instance on `Unitization ℂ A` when `A` is a C⋆-algebra via the spectral order. ## Main theorems * `IsSelfAdjoint.le_algebraMap_norm_self` and `IsSelfAdjoint.le_algebraMap_norm_self`, which respectively show that `a ≤ algebraMap ℝ A ‖a‖` and `-(algebraMap ℝ A ‖a‖) ≤ a` in a C⋆-algebra. * `mul_star_le_algebraMap_norm_sq` and `star_mul_le_algebraMap_norm_sq`, which give similar statements for `a * star a` and `star a * a`. * `CStarRing.norm_le_norm_of_nonneg_of_le`: in a non-unital C⋆-algebra, if `0 ≤ a ≤ b`, then `‖a‖ ≤ ‖b‖`. * `CStarRing.conjugate_le_norm_smul`: in a non-unital C⋆-algebra, we have that `star a * b * a ≤ ‖b‖ • (star a * a)` (and a primed version for the `a * b * star a` case). ## Tags continuous functional calculus, normal, selfadjoint -/ open scoped NNReal namespace Unitization variable {A : Type*} [NonUnitalNormedRing A] [CompleteSpace A] [PartialOrder A] [StarRing A] [StarOrderedRing A] [CStarRing A] [NormedSpace ℂ A] [StarModule ℂ A] [SMulCommClass ℂ A A] [IsScalarTower ℂ A A] instance instPartialOrder : PartialOrder (Unitization ℂ A) := CStarRing.spectralOrder _ instance instStarOrderedRing : StarOrderedRing (Unitization ℂ A) := CStarRing.spectralOrderedRing _ lemma inr_le_iff (a b : A) (ha : IsSelfAdjoint a := by cfc_tac) (hb : IsSelfAdjoint b := by cfc_tac) : (a : Unitization ℂ A) ≤ (b : Unitization ℂ A) ↔ a ≤ b := by -- TODO: prove the more general result for star monomorphisms and use it here. rw [← sub_nonneg, ← sub_nonneg (a := b), StarOrderedRing.nonneg_iff_spectrum_nonneg (R := ℝ) _, ← inr_sub ℂ b a, ← Unitization.quasispectrum_eq_spectrum_inr' ℝ ℂ] exact StarOrderedRing.nonneg_iff_quasispectrum_nonneg _ |>.symm @[simp, norm_cast] lemma inr_nonneg_iff {a : A} : 0 ≤ (a : Unitization ℂ A) ↔ 0 ≤ a := by by_cases ha : IsSelfAdjoint a · exact inr_zero ℂ (A := A) ▸ inr_le_iff 0 a · refine ⟨?_, ?_⟩ all_goals refine fun h ↦ (ha ?_).elim · exact isSelfAdjoint_inr (R := ℂ) |>.mp <| .of_nonneg h · exact .of_nonneg h end Unitization section CStar_unital variable {A : Type*} [NormedRing A] [StarRing A] [CStarRing A] [CompleteSpace A] variable [NormedAlgebra ℂ A] [StarModule ℂ A] section StarOrderedRing variable [PartialOrder A] [StarOrderedRing A] lemma IsSelfAdjoint.le_algebraMap_norm_self {a : A} (ha : IsSelfAdjoint a := by cfc_tac) : a ≤ algebraMap ℝ A ‖a‖ := by by_cases nontriv : Nontrivial A · refine le_algebraMap_of_spectrum_le fun r hr => ?_ calc r ≤ ‖r‖ := Real.le_norm_self r _ ≤ ‖a‖ := spectrum.norm_le_norm_of_mem hr · rw [not_nontrivial_iff_subsingleton] at nontriv simp lemma IsSelfAdjoint.neg_algebraMap_norm_le_self {a : A} (ha : IsSelfAdjoint a := by cfc_tac) : - (algebraMap ℝ A ‖a‖) ≤ a := by have : - a ≤ algebraMap ℝ A ‖a‖ := by rw [← norm_neg] exact IsSelfAdjoint.le_algebraMap_norm_self (neg ha) exact neg_le.mp this lemma CStarRing.mul_star_le_algebraMap_norm_sq {a : A} : a * star a ≤ algebraMap ℝ A (‖a‖ ^ 2) := by have : a * star a ≤ algebraMap ℝ A ‖a * star a‖ := IsSelfAdjoint.le_algebraMap_norm_self rwa [CStarRing.norm_self_mul_star, ← pow_two] at this lemma CStarRing.star_mul_le_algebraMap_norm_sq {a : A} : star a * a ≤ algebraMap ℝ A (‖a‖ ^ 2) := by have : star a * a ≤ algebraMap ℝ A ‖star a * a‖ := IsSelfAdjoint.le_algebraMap_norm_self rwa [CStarRing.norm_star_mul_self, ← pow_two] at this end StarOrderedRing lemma IsSelfAdjoint.toReal_spectralRadius_eq_norm {a : A} (ha : IsSelfAdjoint a) : (spectralRadius ℝ a).toReal = ‖a‖ := by simp [ha.spectrumRestricts.spectralRadius_eq, ha.spectralRadius_eq_nnnorm] lemma CStarRing.norm_or_neg_norm_mem_spectrum [Nontrivial A] {a : A} (ha : IsSelfAdjoint a := by cfc_tac) : ‖a‖ ∈ spectrum ℝ a ∨ -‖a‖ ∈ spectrum ℝ a := by have ha' : SpectrumRestricts a Complex.reCLM := ha.spectrumRestricts rw [← ha.toReal_spectralRadius_eq_norm] exact Real.spectralRadius_mem_spectrum_or (ha'.image ▸ (spectrum.nonempty a).image _) variable [PartialOrder A] [StarOrderedRing A] lemma CStarRing.nnnorm_mem_spectrum_of_nonneg [Nontrivial A] {a : A} (ha : 0 ≤ a := by cfc_tac) : ‖a‖₊ ∈ spectrum ℝ≥0 a := by have : IsSelfAdjoint a := .of_nonneg ha convert NNReal.spectralRadius_mem_spectrum (a := a) ?_ (.nnreal_of_nonneg ha) · simp [this.spectrumRestricts.spectralRadius_eq, this.spectralRadius_eq_nnnorm] · exact this.spectrumRestricts.image ▸ (spectrum.nonempty a).image _ lemma CStarRing.norm_mem_spectrum_of_nonneg [Nontrivial A] {a : A} (ha : 0 ≤ a := by cfc_tac) : ‖a‖ ∈ spectrum ℝ a := by simpa using spectrum.algebraMap_mem ℝ <| CStarRing.nnnorm_mem_spectrum_of_nonneg ha end CStar_unital section CStar_nonunital variable {A : Type*} [NonUnitalNormedRing A] [CompleteSpace A] [PartialOrder A] [StarRing A] [StarOrderedRing A] [CStarRing A] [NormedSpace ℂ A] [StarModule ℂ A] [SMulCommClass ℂ A A] [IsScalarTower ℂ A A] open ComplexOrder in instance CStarRing.instNonnegSpectrumClassComplexNonUnital : NonnegSpectrumClass ℂ A where quasispectrum_nonneg_of_nonneg a ha x hx := by rw [Unitization.quasispectrum_eq_spectrum_inr' ℂ ℂ a] at hx exact spectrum_nonneg_of_nonneg (Unitization.inr_nonneg_iff.mpr ha) hx lemma CStarRing.norm_le_norm_of_nonneg_of_le {a b : A} (ha : 0 ≤ a := by cfc_tac) (hab : a ≤ b) : ‖a‖ ≤ ‖b‖ := by suffices ∀ a b : Unitization ℂ A, 0 ≤ a → a ≤ b → ‖a‖ ≤ ‖b‖ by have hb := ha.trans hab simpa only [ge_iff_le, Unitization.norm_inr] using this a b (by simpa) (by rwa [Unitization.inr_le_iff a b]) intro a b ha hab have hb_nonneg : 0 ≤ b := ha.trans hab have : 0 ≤ a := by cfc_tac have h₂ : cfc (id : ℝ → ℝ) a ≤ cfc (fun _ => ‖b‖) a := by calc _ = a := by rw [cfc_id ℝ a] _ ≤ cfc id b := (cfc_id ℝ b) ▸ hab _ ≤ cfc (fun _ => ‖b‖) b := by refine cfc_mono fun x hx => ?_ calc x = ‖x‖ := (Real.norm_of_nonneg (spectrum_nonneg_of_nonneg hb_nonneg hx)).symm _ ≤ ‖b‖ := spectrum.norm_le_norm_of_mem hx _ = _ := by rw [cfc_const _ _, cfc_const _ _] rw [cfc_le_iff id (fun _ => ‖b‖) a] at h₂ exact h₂ ‖a‖ <| norm_mem_spectrum_of_nonneg ha lemma CStarRing.conjugate_le_norm_smul {a b : A} (hb : IsSelfAdjoint b := by cfc_tac) : star a * b * a ≤ ‖b‖ • (star a * a) := by suffices ∀ a b : Unitization ℂ A, IsSelfAdjoint b → star a * b * a ≤ ‖b‖ • (star a * a) by rw [← Unitization.inr_le_iff _ _ (by aesop) ((IsSelfAdjoint.all _).smul (.star_mul_self a))] simpa [Unitization.norm_inr] using this a b <| hb.inr ℂ intro a b hb calc star a * b * a ≤ star a * (algebraMap ℝ (Unitization ℂ A) ‖b‖) * a := conjugate_le_conjugate hb.le_algebraMap_norm_self _ _ = ‖b‖ • (star a * a) := by simp [Algebra.algebraMap_eq_smul_one] lemma CStarRing.conjugate_le_norm_smul' {a b : A} (hb : IsSelfAdjoint b := by cfc_tac) : a * b * star a ≤ ‖b‖ • (a * star a) := by have h₁ : a * b * star a = star (star a) * b * star a := by simp have h₂ : a * star a = star (star a) * star a := by simp simp only [h₁, h₂] exact conjugate_le_norm_smul end CStar_nonunital
Analysis\CStarAlgebra\ContinuousFunctionalCalculus\Restrict.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.Normed.Algebra.Spectrum import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.NonUnital /-! # Restriction of the continuous functional calculus to a scalar subring The main declaration in this file is: + `SpectrumRestricts.cfc`: builds a continuous functional calculus over a subring of scalars. This is use for automatically deriving the continuous functional calculi on selfadjoint or positive elements from the one for normal elements. This will allow us to take an instance of the `ContinuousFunctionalCalculus ℂ IsStarNormal` and produce both of the instances `ContinuousFunctionalCalculus ℝ IsSelfAdjoint` and `ContinuousFunctionalCalculus ℝ≥0 (0 ≤ ·)` simply by proving: 1. `IsSelfAdjoint x ↔ IsStarNormal x ∧ SpectrumRestricts Complex.re x`, 2. `0 ≤ x ↔ IsSelfAdjoint x ∧ SpectrumRestricts Real.toNNReal x`. -/ open Set namespace SpectrumRestricts /-- The homeomorphism `spectrum S a ≃ₜ spectrum R a` induced by `SpectrumRestricts a f`. -/ def homeomorph {R S A : Type*} [Semifield R] [Semifield S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [TopologicalSpace R] [TopologicalSpace S] [ContinuousSMul R S] {a : A} {f : C(S, R)} (h : SpectrumRestricts a f) : spectrum S a ≃ₜ spectrum R a where toFun := MapsTo.restrict f _ _ h.subset_preimage invFun := MapsTo.restrict (algebraMap R S) _ _ (image_subset_iff.mp h.algebraMap_image.subset) left_inv x := Subtype.ext <| h.rightInvOn x.2 right_inv x := Subtype.ext <| h.left_inv x continuous_toFun := continuous_induced_rng.mpr <| f.continuous.comp continuous_induced_dom continuous_invFun := continuous_induced_rng.mpr <| continuous_algebraMap R S |>.comp continuous_induced_dom lemma compactSpace {R S A : Type*} [Semifield R] [Semifield S] [Ring A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [TopologicalSpace R] [TopologicalSpace S] {a : A} (f : C(S, R)) (h : SpectrumRestricts a f) [h_cpct : CompactSpace (spectrum S a)] : CompactSpace (spectrum R a) := by rw [← isCompact_iff_compactSpace] at h_cpct ⊢ exact h.image ▸ h_cpct.image (map_continuous f) universe u v w /-- If the spectrum of an element restricts to a smaller scalar ring, then a continuous functional calculus over the larger scalar ring descends to the smaller one. -/ @[simps!] def starAlgHom {R : Type u} {S : Type v} {A : Type w} [Semifield R] [StarRing R] [TopologicalSpace R] [TopologicalSemiring R] [ContinuousStar R] [Semifield S] [StarRing S] [TopologicalSpace S] [TopologicalSemiring S] [ContinuousStar S] [Ring A] [StarRing A] [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [StarModule R S] [ContinuousSMul R S] {a : A} (φ : C(spectrum S a, S) →⋆ₐ[S] A) {f : C(S, R)} (h : SpectrumRestricts a f) : C(spectrum R a, R) →⋆ₐ[R] A := (φ.restrictScalars R).comp <| (ContinuousMap.compStarAlgHom (spectrum S a) (.ofId R S) (algebraMapCLM R S).continuous).comp <| ContinuousMap.compStarAlgHom' R R ⟨Subtype.map f h.subset_preimage, (map_continuous f).subtype_map fun x (hx : x ∈ spectrum S a) => h.subset_preimage hx⟩ variable {R S A : Type*} {p q : A → Prop} variable [Semifield R] [StarRing R] [MetricSpace R] [TopologicalSemiring R] [ContinuousStar R] variable [Semifield S] [StarRing S] [MetricSpace S] [TopologicalSemiring S] [ContinuousStar S] variable [TopologicalSpace A] [Ring A] [StarRing A] [Algebra S A] [ContinuousFunctionalCalculus S q] variable [Algebra R S] [Algebra R A] [IsScalarTower R S A] [StarModule R S] [ContinuousSMul R S] variable [CompleteSpace R] lemma closedEmbedding_starAlgHom {a : A} {φ : C(spectrum S a, S) →⋆ₐ[S] A} (hφ : ClosedEmbedding φ) {f : C(S, R)} (h : SpectrumRestricts a f) (halg : UniformEmbedding (algebraMap R S)) [CompactSpace (spectrum S a)] : ClosedEmbedding (h.starAlgHom φ) := have := h.compactSpace hφ.comp <| UniformEmbedding.toClosedEmbedding <| .comp (ContinuousMap.uniformEmbedding_comp _ halg) (UniformEquiv.arrowCongr h.homeomorph.symm (.refl _) |>.uniformEmbedding) lemma starAlgHom_id {a : A} {φ : C(spectrum S a, S) →⋆ₐ[S] A} {f : C(S, R)} (h : SpectrumRestricts a f) (h_id : φ (.restrict (spectrum S a) <| .id S) = a) : h.starAlgHom φ (.restrict (spectrum R a) <| .id R) = a := by simp only [SpectrumRestricts.starAlgHom_apply] convert h_id ext x exact h.rightInvOn x.2 /-- Given a `ContinuousFunctionalCalculus S q`. If we form the predicate `p` for `a : A` characterized by: `q a` and the spectrum of `a` restricts to the scalar subring `R` via `f : C(S, R)`, then we can get a restricted functional calculus `ContinuousFunctionalCalculus R p`. -/ protected theorem cfc (f : C(S, R)) (halg : UniformEmbedding (algebraMap R S)) (h0 : p 0) (h : ∀ a, p a ↔ q a ∧ SpectrumRestricts a f) (h_cpct : ∀ a, q a → CompactSpace (spectrum S a)) : ContinuousFunctionalCalculus R p where predicate_zero := h0 exists_cfc_of_predicate a ha := by refine ⟨((h a).mp ha).2.starAlgHom (cfcHom ((h a).mp ha).1 (R := S)), ?hom_closedEmbedding, ?hom_id, ?hom_map_spectrum, ?predicate_hom⟩ case hom_closedEmbedding => have := h_cpct a ((h a).mp ha).1 exact ((h a).mp ha).2.closedEmbedding_starAlgHom (cfcHom_closedEmbedding ((h a).mp ha).1) halg case hom_id => exact ((h a).mp ha).2.starAlgHom_id <| cfcHom_id ((h a).mp ha).1 case hom_map_spectrum => intro g rw [SpectrumRestricts.starAlgHom_apply] simp only [← @spectrum.preimage_algebraMap (R := R) S, cfcHom_map_spectrum] ext x constructor · rintro ⟨y, hy⟩ have := congr_arg f hy simp only [ContinuousMap.coe_mk, ContinuousMap.comp_apply, StarAlgHom.ofId_apply] at this rw [((h a).mp ha).2.left_inv _, ((h a).mp ha).2.left_inv _] at this exact ⟨_, this⟩ · rintro ⟨y, rfl⟩ rw [Set.mem_preimage] refine ⟨⟨algebraMap R S y, spectrum.algebraMap_mem S y.prop⟩, ?_⟩ simp only [ContinuousMap.coe_mk, ContinuousMap.comp_apply, StarAlgHom.ofId_apply] congr exact Subtype.ext (((h a).mp ha).2.left_inv y) case predicate_hom => intro g rw [h] refine ⟨cfcHom_predicate _ _, ?_⟩ refine .of_rightInvOn (((h a).mp ha).2.left_inv) fun s hs ↦ ?_ rw [SpectrumRestricts.starAlgHom_apply, cfcHom_map_spectrum] at hs obtain ⟨r, rfl⟩ := hs simp [((h a).mp ha).2.left_inv _] variable [ContinuousFunctionalCalculus R p] [UniqueContinuousFunctionalCalculus R A] lemma cfcHom_eq_restrict (f : C(S, R)) (halg : UniformEmbedding (algebraMap R S)) {a : A} (hpa : p a) (hqa : q a) (h : SpectrumRestricts a f) [CompactSpace (spectrum S a)] : cfcHom hpa = h.starAlgHom (cfcHom hqa) := by apply cfcHom_eq_of_continuous_of_map_id · exact h.closedEmbedding_starAlgHom (cfcHom_closedEmbedding hqa) halg |>.continuous · exact h.starAlgHom_id (cfcHom_id hqa) lemma cfc_eq_restrict (f : C(S, R)) (halg : UniformEmbedding (algebraMap R S)) {a : A} (hpa : p a) (hqa : q a) (h : SpectrumRestricts a f) [CompactSpace (spectrum S a)] (g : R → R) : cfc g a = cfc (fun x ↦ algebraMap R S (g (f x))) a := by by_cases hg : ContinuousOn g (spectrum R a) · rw [cfc_apply g a, cfcHom_eq_restrict f halg hpa hqa h, SpectrumRestricts.starAlgHom_apply, cfcHom_eq_cfc_extend 0] apply cfc_congr fun x hx ↦ ?_ lift x to spectrum S a using hx simp [Function.comp, Subtype.val_injective.extend_apply] · have : ¬ ContinuousOn (fun x ↦ algebraMap R S (g (f x)) : S → S) (spectrum S a) := by refine fun hg' ↦ hg ?_ rw [halg.embedding.continuousOn_iff] simpa [halg.embedding.continuousOn_iff, Function.comp, h.left_inv _] using hg'.comp halg.embedding.continuous.continuousOn (fun _ : R ↦ spectrum.algebraMap_mem S) rw [cfc_apply_of_not_continuousOn a hg, cfc_apply_of_not_continuousOn a this] end SpectrumRestricts namespace QuasispectrumRestricts local notation "σₙ" => quasispectrum open ContinuousMapZero Set /-- The homeomorphism `quasispectrum S a ≃ₜ quasispectrum R a` induced by `QuasispectrumRestricts a f`. -/ def homeomorph {R S A : Type*} [Semifield R] [Field S] [NonUnitalRing A] [Algebra R S] [Module R A] [Module S A] [IsScalarTower R S A] [TopologicalSpace R] [TopologicalSpace S] [ContinuousSMul R S] [IsScalarTower S A A] [SMulCommClass S A A] {a : A} {f : C(S, R)} (h : QuasispectrumRestricts a f) : σₙ S a ≃ₜ σₙ R a where toFun := MapsTo.restrict f _ _ h.subset_preimage invFun := MapsTo.restrict (algebraMap R S) _ _ (image_subset_iff.mp h.algebraMap_image.subset) left_inv x := Subtype.ext <| h.rightInvOn x.2 right_inv x := Subtype.ext <| h.left_inv x continuous_toFun := continuous_induced_rng.mpr <| f.continuous.comp continuous_induced_dom continuous_invFun := continuous_induced_rng.mpr <| continuous_algebraMap R S |>.comp continuous_induced_dom universe u v w open ContinuousMapZero /-- If the quasispectrum of an element restricts to a smaller scalar ring, then a non-unital continuous functional calculus over the larger scalar ring descends to the smaller one. -/ @[simps!] def nonUnitalStarAlgHom {R : Type u} {S : Type v} {A : Type w} [Semifield R] [StarRing R] [TopologicalSpace R] [TopologicalSemiring R] [ContinuousStar R] [Field S] [StarRing S] [TopologicalSpace S] [TopologicalRing S] [ContinuousStar S] [NonUnitalRing A] [StarRing A] [Algebra R S] [Module R A] [Module S A] [IsScalarTower S A A] [SMulCommClass S A A] [IsScalarTower R S A] [StarModule R S] [ContinuousSMul R S] {a : A} (φ : C(σₙ S a, S)₀ →⋆ₙₐ[S] A) {f : C(S, R)} (h : QuasispectrumRestricts a f) : C(σₙ R a, R)₀ →⋆ₙₐ[R] A := (φ.restrictScalars R).comp <| (nonUnitalStarAlgHom_postcomp (σₙ S a) (StarAlgHom.ofId R S) (algebraMapCLM R S).continuous) |>.comp <| nonUnitalStarAlgHom_precomp R ⟨⟨Subtype.map f h.subset_preimage, (map_continuous f).subtype_map fun x (hx : x ∈ σₙ S a) => h.subset_preimage hx⟩, Subtype.ext h.map_zero⟩ variable {R S A : Type*} {p q : A → Prop} variable [Semifield R] [StarRing R] [MetricSpace R] [TopologicalSemiring R] [ContinuousStar R] variable [Field S] [StarRing S] [MetricSpace S] [TopologicalRing S] [ContinuousStar S] variable [TopologicalSpace A] [NonUnitalRing A] [StarRing A] [Module S A] [IsScalarTower S A A] variable [SMulCommClass S A A] [NonUnitalContinuousFunctionalCalculus S q] variable [Algebra R S] [Module R A] [IsScalarTower R S A] [StarModule R S] [ContinuousSMul R S] variable [CompleteSpace R] lemma closedEmbedding_nonUnitalStarAlgHom {a : A} {φ : C(σₙ S a, S)₀ →⋆ₙₐ[S] A} (hφ : ClosedEmbedding φ) {f : C(S, R)} (h : QuasispectrumRestricts a f) (halg : UniformEmbedding (algebraMap R S)) [h_cpct : CompactSpace (σₙ S a)] : ClosedEmbedding (h.nonUnitalStarAlgHom φ) := by have := h.compactSpace have : h.homeomorph.symm 0 = 0 := Subtype.ext (map_zero <| algebraMap _ _) refine hφ.comp <| UniformEmbedding.toClosedEmbedding <| .comp (ContinuousMapZero.uniformEmbedding_comp _ halg) (UniformEquiv.arrowCongrLeft₀ h.homeomorph.symm this |>.uniformEmbedding) lemma nonUnitalStarAlgHom_id {a : A} {φ : C(σₙ S a, S)₀ →⋆ₙₐ[S] A} {f : C(S, R)} (h : QuasispectrumRestricts a f) (h_id : φ (.id rfl) = a) : h.nonUnitalStarAlgHom φ (.id rfl) = a := by simp only [QuasispectrumRestricts.nonUnitalStarAlgHom_apply] convert h_id ext x exact h.rightInvOn x.2 variable [IsScalarTower R A A] [SMulCommClass R A A] /-- Given a `NonUnitalContinuousFunctionalCalculus S q`. If we form the predicate `p` for `a : A` characterized by: `q a` and the quasispectrum of `a` restricts to the scalar subring `R` via `f : C(S, R)`, then we can get a restricted functional calculus `NonUnitalContinuousFunctionalCalculus R p`. -/ protected theorem cfc (f : C(S, R)) (halg : UniformEmbedding (algebraMap R S)) (h0 : p 0) (h : ∀ a, p a ↔ q a ∧ QuasispectrumRestricts a f) (h_cpct : ∀ a, q a → CompactSpace (σₙ S a)) : NonUnitalContinuousFunctionalCalculus R p where predicate_zero := h0 exists_cfc_of_predicate a ha := by refine ⟨((h a).mp ha).2.nonUnitalStarAlgHom (cfcₙHom ((h a).mp ha).1 (R := S)), ?hom_closedEmbedding, ?hom_id, ?hom_map_spectrum, ?predicate_hom⟩ case hom_closedEmbedding => exact ((h a).mp ha).2.closedEmbedding_nonUnitalStarAlgHom (cfcₙHom_closedEmbedding ((h a).mp ha).1) halg (h_cpct := h_cpct a ((h a).mp ha).1) case hom_id => exact ((h a).mp ha).2.nonUnitalStarAlgHom_id <| cfcₙHom_id ((h a).mp ha).1 case hom_map_spectrum => intro g rw [nonUnitalStarAlgHom_apply] simp only [← @quasispectrum.preimage_algebraMap (R := R) S, cfcₙHom_map_quasispectrum] ext x constructor · rintro ⟨y, hy⟩ have := congr_arg f hy simp only [nonUnitalStarAlgHom_postcomp_apply, NonUnitalStarAlgHom.coe_coe, Function.comp_apply, comp_apply, coe_mk, ContinuousMap.coe_mk, StarAlgHom.ofId_apply] at this rw [((h a).mp ha).2.left_inv _, ((h a).mp ha).2.left_inv _] at this exact ⟨_, this⟩ · rintro ⟨y, rfl⟩ rw [Set.mem_preimage] refine ⟨⟨algebraMap R S y, quasispectrum.algebraMap_mem S y.prop⟩, ?_⟩ simp only [nonUnitalStarAlgHom_postcomp_apply, NonUnitalStarAlgHom.coe_coe, Function.comp_apply, comp_apply, coe_mk, ContinuousMap.coe_mk, StarAlgHom.ofId_apply] congr exact Subtype.ext (((h a).mp ha).2.left_inv y) case predicate_hom => intro g rw [h] refine ⟨cfcₙHom_predicate _ _, ?_⟩ refine { rightInvOn := fun s hs ↦ ?_, left_inv := ((h a).mp ha).2.left_inv } rw [nonUnitalStarAlgHom_apply, cfcₙHom_map_quasispectrum] at hs obtain ⟨r, rfl⟩ := hs simp [((h a).mp ha).2.left_inv _] variable [NonUnitalContinuousFunctionalCalculus R p] variable [UniqueNonUnitalContinuousFunctionalCalculus R A] lemma cfcₙHom_eq_restrict (f : C(S, R)) (halg : UniformEmbedding (algebraMap R S)) {a : A} (hpa : p a) (hqa : q a) (h : QuasispectrumRestricts a f) [CompactSpace (σₙ S a)] : cfcₙHom hpa = h.nonUnitalStarAlgHom (cfcₙHom hqa) := by apply cfcₙHom_eq_of_continuous_of_map_id · exact h.closedEmbedding_nonUnitalStarAlgHom (cfcₙHom_closedEmbedding hqa) halg |>.continuous · exact h.nonUnitalStarAlgHom_id (cfcₙHom_id hqa) lemma cfcₙ_eq_restrict (f : C(S, R)) (halg : UniformEmbedding (algebraMap R S)) {a : A} (hpa : p a) (hqa : q a) (h : QuasispectrumRestricts a f) [CompactSpace (σₙ S a)] (g : R → R) : cfcₙ g a = cfcₙ (fun x ↦ algebraMap R S (g (f x))) a := by by_cases hg : ContinuousOn g (σₙ R a) ∧ g 0 = 0 · obtain ⟨hg, hg0⟩ := hg rw [cfcₙ_apply g a, cfcₙHom_eq_restrict f halg hpa hqa h, nonUnitalStarAlgHom_apply, cfcₙHom_eq_cfcₙ_extend 0] apply cfcₙ_congr fun x hx ↦ ?_ lift x to σₙ S a using hx simp [Function.comp, Subtype.val_injective.extend_apply] · simp only [not_and_or] at hg obtain (hg | hg) := hg · have : ¬ ContinuousOn (fun x ↦ algebraMap R S (g (f x)) : S → S) (σₙ S a) := by refine fun hg' ↦ hg ?_ rw [halg.embedding.continuousOn_iff] simpa [halg.embedding.continuousOn_iff, Function.comp, h.left_inv _] using hg'.comp halg.embedding.continuous.continuousOn (fun _ : R ↦ quasispectrum.algebraMap_mem S) rw [cfcₙ_apply_of_not_continuousOn a hg, cfcₙ_apply_of_not_continuousOn a this] · rw [cfcₙ_apply_of_not_map_zero a hg, cfcₙ_apply_of_not_map_zero a (by simpa [h.map_zero])] end QuasispectrumRestricts
Analysis\CStarAlgebra\ContinuousFunctionalCalculus\Unique.lean
/- Copyright (c) 2024 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Analysis.Normed.Algebra.Spectrum import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.NonUnital import Mathlib.Topology.ContinuousFunction.StoneWeierstrass /-! # Uniqueness of the continuous functional calculus Let `s : Set 𝕜` be compact where `𝕜` is either `ℝ` or `ℂ`. By the Stone-Weierstrass theorem, the (star) subalgebra generated by polynomial functions on `s` is dense in `C(s, 𝕜)`. Moreover, this star subalgebra is generated by `X : 𝕜[X]` (i.e., `ContinuousMap.restrict s (.id 𝕜)`) alone. Consequently, any continuous star `𝕜`-algebra homomorphism with domain `C(s, 𝕜)`, is uniquely determined by its value on `X : 𝕜[X]`. The same is true for `𝕜 := ℝ≥0`, so long as the algebra `A` is an `ℝ`-algebra, which we establish by upgrading a map `C((s : Set ℝ≥0), ℝ≥0) →⋆ₐ[ℝ≥0] A` to `C(((↑) '' s : Set ℝ), ℝ) →⋆ₐ[ℝ] A` in the natural way, and then applying the uniqueness for `ℝ`-algebra homomorphisms. This is the reason the `UniqueContinuousFunctionalCalculus` class exists in the first place, as opposed to simply appealing directly to Stone-Weierstrass to prove `StarAlgHom.ext_continuousMap`. -/ section UniqueUnital section RCLike variable {𝕜 A : Type*} [RCLike 𝕜] theorem RCLike.uniqueContinuousFunctionalCalculus_of_compactSpace_spectrum [TopologicalSpace A] [T2Space A] [Ring A] [StarRing A] [Algebra 𝕜 A] [h : ∀ a : A, CompactSpace (spectrum 𝕜 a)] : UniqueContinuousFunctionalCalculus 𝕜 A where eq_of_continuous_of_map_id s hs φ ψ hφ hψ h := ContinuousMap.starAlgHom_ext_map_X hφ hψ <| by convert h using 1 all_goals exact congr_arg _ (by ext; simp) compactSpace_spectrum := h instance RCLike.instUniqueContinuousFunctionalCalculus [NormedRing A] [StarRing A] [NormedAlgebra 𝕜 A] [CompleteSpace A] : UniqueContinuousFunctionalCalculus 𝕜 A := RCLike.uniqueContinuousFunctionalCalculus_of_compactSpace_spectrum end RCLike section NNReal open NNReal variable {X : Type*} [TopologicalSpace X] namespace ContinuousMap /-- This map sends `f : C(X, ℝ)` to `Real.toNNReal ∘ f`, bundled as a continuous map `C(X, ℝ≥0)`. -/ noncomputable def toNNReal (f : C(X, ℝ)) : C(X, ℝ≥0) := .realToNNReal |>.comp f @[fun_prop] lemma continuous_toNNReal : Continuous (toNNReal (X := X)) := continuous_comp _ @[simp] lemma toNNReal_apply (f : C(X, ℝ)) (x : X) : f.toNNReal x = (f x).toNNReal := rfl lemma toNNReal_add_add_neg_add_neg_eq (f g : C(X, ℝ)) : (f + g).toNNReal + (-f).toNNReal + (-g).toNNReal = (-(f + g)).toNNReal + f.toNNReal + g.toNNReal := by ext x simp [max_neg_zero, -neg_add_rev] abel lemma toNNReal_mul_add_neg_mul_add_mul_neg_eq (f g : C(X, ℝ)) : (f * g).toNNReal + (-f).toNNReal * g.toNNReal + f.toNNReal * (-g).toNNReal = (-(f * g)).toNNReal + f.toNNReal * g.toNNReal + (-f).toNNReal * (-g).toNNReal := by ext x simp [max_neg_zero, add_mul, mul_add] abel @[simp] lemma toNNReal_algebraMap (r : ℝ≥0) : (algebraMap ℝ C(X, ℝ) r).toNNReal = algebraMap ℝ≥0 C(X, ℝ≥0) r := by ext; simp @[simp] lemma toNNReal_neg_algebraMap (r : ℝ≥0) : (- algebraMap ℝ C(X, ℝ) r).toNNReal = 0 := by ext; simp @[simp] lemma toNNReal_one : (1 : C(X, ℝ)).toNNReal = 1 := toNNReal_algebraMap 1 @[simp] lemma toNNReal_neg_one : (-1 : C(X, ℝ)).toNNReal = 0 := toNNReal_neg_algebraMap 1 end ContinuousMap variable {A : Type*} [Ring A] [StarRing A] [Algebra ℝ A] namespace StarAlgHom section TopologicalRing variable [TopologicalSpace A] [TopologicalRing A] /-- Given a star `ℝ≥0`-algebra homomorphism `φ` from `C(X, ℝ≥0)` into an `ℝ`-algebra `A`, this is the unique extension of `φ` from `C(X, ℝ)` to `A` as a star `ℝ`-algebra homomorphism. -/ @[simps] noncomputable def realContinuousMapOfNNReal (φ : C(X, ℝ≥0) →⋆ₐ[ℝ≥0] A) : C(X, ℝ) →⋆ₐ[ℝ] A where toFun f := φ f.toNNReal - φ (-f).toNNReal map_one' := by simp map_zero' := by simp map_mul' f g := by have := congr(φ $(f.toNNReal_mul_add_neg_mul_add_mul_neg_eq g)) simp only [map_add, map_mul, sub_mul, mul_sub] at this ⊢ rw [← sub_eq_zero] at this ⊢ convert this using 1 abel map_add' f g := by have := congr(φ $(f.toNNReal_add_add_neg_add_neg_eq g)) simp only [map_add] at this ⊢ rw [← sub_eq_zero] at this ⊢ convert this using 1 abel commutes' r := by simp only obtain (hr | hr) := le_total 0 r · lift r to ℝ≥0 using hr simpa only [ContinuousMap.toNNReal_algebraMap, ContinuousMap.toNNReal_neg_algebraMap, map_zero, sub_zero] using AlgHomClass.commutes φ r · rw [← neg_neg r, ← map_neg, neg_neg (-r)] rw [← neg_nonneg] at hr lift -r to ℝ≥0 using hr with r simpa only [map_neg, ContinuousMap.toNNReal_neg_algebraMap, map_zero, ContinuousMap.toNNReal_algebraMap, zero_sub, neg_inj] using AlgHomClass.commutes φ r map_star' f := by simp only [star_trivial, star_sub, ← map_star] @[fun_prop] lemma continuous_realContinuousMapOfNNReal (φ : C(X, ℝ≥0) →⋆ₐ[ℝ≥0] A) (hφ : Continuous φ) : Continuous φ.realContinuousMapOfNNReal := by simp [realContinuousMapOfNNReal] fun_prop end TopologicalRing @[simp high] lemma realContinuousMapOfNNReal_apply_comp_toReal (φ : C(X, ℝ≥0) →⋆ₐ[ℝ≥0] A) (f : C(X, ℝ≥0)) : φ.realContinuousMapOfNNReal ((ContinuousMap.mk toReal continuous_coe).comp f) = φ f := by simp only [realContinuousMapOfNNReal_apply] convert_to φ f - φ 0 = φ f using 2 on_goal -1 => rw [map_zero, sub_zero] all_goals congr ext x simp lemma realContinuousMapOfNNReal_injective : Function.Injective (realContinuousMapOfNNReal (X := X) (A := A)) := by intro φ ψ h ext f simpa using congr($(h) ((ContinuousMap.mk toReal continuous_coe).comp f)) end StarAlgHom variable [TopologicalSpace A] [TopologicalRing A] instance NNReal.instUniqueContinuousFunctionalCalculus [UniqueContinuousFunctionalCalculus ℝ A] : UniqueContinuousFunctionalCalculus ℝ≥0 A where compactSpace_spectrum a := by have : CompactSpace (spectrum ℝ a) := UniqueContinuousFunctionalCalculus.compactSpace_spectrum a rw [← isCompact_iff_compactSpace] at * rw [← spectrum.preimage_algebraMap ℝ] exact closedEmbedding_subtype_val isClosed_nonneg |>.isCompact_preimage <| by assumption eq_of_continuous_of_map_id s hs φ ψ hφ hψ h := by let s' : Set ℝ := (↑) '' s let e : s ≃ₜ s' := { toFun := Subtype.map (↑) (by simp [s']) invFun := Subtype.map Real.toNNReal (by simp [s']) left_inv := fun _ ↦ by ext; simp right_inv := fun x ↦ by ext obtain ⟨y, -, hy⟩ := x.2 simpa using hy ▸ NNReal.coe_nonneg y continuous_toFun := continuous_coe.subtype_map (by simp [s']) continuous_invFun := continuous_real_toNNReal.subtype_map (by simp [s']) } have (ξ : C(s, ℝ≥0) →⋆ₐ[ℝ≥0] A) (hξ : Continuous ξ) : (let ξ' := ξ.realContinuousMapOfNNReal.comp <| ContinuousMap.compStarAlgHom' ℝ ℝ e Continuous ξ' ∧ ξ' (.restrict s' <| .id ℝ) = ξ (.restrict s <| .id ℝ≥0)) := by intro ξ' refine ⟨ξ.continuous_realContinuousMapOfNNReal hξ |>.comp <| ContinuousMap.continuous_comp_left _, ?_⟩ exact ξ.realContinuousMapOfNNReal_apply_comp_toReal (.restrict s <| .id ℝ≥0) obtain ⟨hφ', hφ_id⟩ := this φ hφ obtain ⟨hψ', hψ_id⟩ := this ψ hψ have hs' : CompactSpace s' := e.compactSpace have h' := UniqueContinuousFunctionalCalculus.eq_of_continuous_of_map_id s' _ _ hφ' hψ' (hφ_id ▸ hψ_id ▸ h) have h'' := congr($(h').comp <| ContinuousMap.compStarAlgHom' ℝ ℝ (e.symm : C(s', s))) have : (ContinuousMap.compStarAlgHom' ℝ ℝ (e : C(s, s'))).comp (ContinuousMap.compStarAlgHom' ℝ ℝ (e.symm : C(s', s))) = StarAlgHom.id _ _ := by ext1; simp simp only [StarAlgHom.comp_assoc, this, StarAlgHom.comp_id] at h'' exact StarAlgHom.realContinuousMapOfNNReal_injective h'' end NNReal end UniqueUnital section UniqueNonUnital section RCLike variable {𝕜 A : Type*} [RCLike 𝕜] open NonUnitalStarAlgebra in theorem RCLike.uniqueNonUnitalContinuousFunctionalCalculus_of_compactSpace_quasispectrum [TopologicalSpace A] [T2Space A] [NonUnitalRing A] [StarRing A] [Module 𝕜 A] [IsScalarTower 𝕜 A A] [SMulCommClass 𝕜 A A] [h : ∀ a : A, CompactSpace (quasispectrum 𝕜 a)] : UniqueNonUnitalContinuousFunctionalCalculus 𝕜 A where eq_of_continuous_of_map_id s hs _inst h0 φ ψ hφ hψ h := by rw [DFunLike.ext'_iff, ← Set.eqOn_univ, ← (ContinuousMapZero.adjoin_id_dense h0).closure_eq] refine Set.EqOn.closure (fun f hf ↦ ?_) hφ hψ rw [← NonUnitalStarAlgHom.mem_equalizer] apply adjoin_le ?_ hf rw [Set.singleton_subset_iff] exact h compactSpace_quasispectrum := h instance RCLike.instUniqueNonUnitalContinuousFunctionalCalculus [NonUnitalNormedRing A] [StarRing A] [CompleteSpace A] [NormedSpace 𝕜 A] [IsScalarTower 𝕜 A A] [SMulCommClass 𝕜 A A] : UniqueNonUnitalContinuousFunctionalCalculus 𝕜 A := RCLike.uniqueNonUnitalContinuousFunctionalCalculus_of_compactSpace_quasispectrum end RCLike section NNReal open NNReal variable {X : Type*} [TopologicalSpace X] [Zero X] namespace ContinuousMapZero /-- This map sends `f : C(X, ℝ)` to `Real.toNNReal ∘ f`, bundled as a continuous map `C(X, ℝ≥0)`. -/ noncomputable def toNNReal (f : C(X, ℝ)₀) : C(X, ℝ≥0)₀ := ⟨.realToNNReal |>.comp f, by simp⟩ @[simp] lemma toNNReal_apply (f : C(X, ℝ)₀) (x : X) : f.toNNReal x = Real.toNNReal (f x) := rfl @[fun_prop] lemma continuous_toNNReal : Continuous (toNNReal (X := X)) := by rw [continuous_induced_rng] convert_to Continuous (ContinuousMap.toNNReal ∘ ((↑) : C(X, ℝ)₀ → C(X, ℝ))) using 1 exact ContinuousMap.continuous_comp _ |>.comp continuous_induced_dom lemma toContinuousMapHom_toNNReal (f : C(X, ℝ)₀) : (toContinuousMapHom (X := X) (R := ℝ) f).toNNReal = toContinuousMapHom (X := X) (R := ℝ≥0) f.toNNReal := rfl @[simp] lemma toNNReal_smul (r : ℝ≥0) (f : C(X, ℝ)₀) : (r • f).toNNReal = r • f.toNNReal := by ext x by_cases h : 0 ≤ f x · simpa [max_eq_left h, NNReal.smul_def] using mul_nonneg r.coe_nonneg h · push_neg at h simpa [max_eq_right h.le, NNReal.smul_def] using mul_nonpos_of_nonneg_of_nonpos r.coe_nonneg h.le @[simp] lemma toNNReal_neg_smul (r : ℝ≥0) (f : C(X, ℝ)₀) : (-(r • f)).toNNReal = r • (-f).toNNReal := by rw [NNReal.smul_def, ← smul_neg, ← NNReal.smul_def, toNNReal_smul] lemma toNNReal_mul_add_neg_mul_add_mul_neg_eq (f g : C(X, ℝ)₀) : ((f * g).toNNReal + (-f).toNNReal * g.toNNReal + f.toNNReal * (-g).toNNReal) = ((-(f * g)).toNNReal + f.toNNReal * g.toNNReal + (-f).toNNReal * (-g).toNNReal) := by -- Without this, Lean fails to find the instance in time have : SemilinearMapClass (C(X, ℝ≥0)₀ →⋆ₙₐ[ℝ≥0] C(X, ℝ≥0)) (RingHom.id ℝ≥0) C(X, ℝ≥0)₀ C(X, ℝ≥0) := NonUnitalAlgHomClass.instLinearMapClass apply toContinuousMap_injective simpa only [← toContinuousMapHom_apply, map_add, map_mul, map_neg, toContinuousMapHom_toNNReal] using (f : C(X, ℝ)).toNNReal_mul_add_neg_mul_add_mul_neg_eq g lemma toNNReal_add_add_neg_add_neg_eq (f g : C(X, ℝ)₀) : ((f + g).toNNReal + (-f).toNNReal + (-g).toNNReal) = ((-(f + g)).toNNReal + f.toNNReal + g.toNNReal) := by -- Without this, Lean fails to find the instance in time have : SemilinearMapClass (C(X, ℝ≥0)₀ →⋆ₙₐ[ℝ≥0] C(X, ℝ≥0)) (RingHom.id ℝ≥0) C(X, ℝ≥0)₀ C(X, ℝ≥0) := NonUnitalAlgHomClass.instLinearMapClass apply toContinuousMap_injective simpa only [← toContinuousMapHom_apply, map_add, map_mul, map_neg, toContinuousMapHom_toNNReal] using (f : C(X, ℝ)).toNNReal_add_add_neg_add_neg_eq g end ContinuousMapZero variable {A : Type*} [NonUnitalRing A] [StarRing A] [Module ℝ A] namespace NonUnitalStarAlgHom open ContinuousMapZero section TopologicalRing variable [TopologicalSpace A] [TopologicalRing A] /-- Given a non-unital star `ℝ≥0`-algebra homomorphism `φ` from `C(X, ℝ≥0)₀` into a non-unital `ℝ`-algebra `A`, this is the unique extension of `φ` from `C(X, ℝ)₀` to `A` as a non-unital star `ℝ`-algebra homomorphism. -/ @[simps] noncomputable def realContinuousMapZeroOfNNReal (φ : C(X, ℝ≥0)₀ →⋆ₙₐ[ℝ≥0] A) : C(X, ℝ)₀ →⋆ₙₐ[ℝ] A where toFun f := φ f.toNNReal - φ (-f).toNNReal map_zero' := by simp map_mul' f g := by have := congr(φ $(f.toNNReal_mul_add_neg_mul_add_mul_neg_eq g)) simp only [map_add, map_mul, sub_mul, mul_sub] at this ⊢ rw [← sub_eq_zero] at this ⊢ rw [← this] abel map_add' f g := by have := congr(φ $(f.toNNReal_add_add_neg_add_neg_eq g)) simp only [map_add, map_mul, sub_mul, mul_sub] at this ⊢ rw [← sub_eq_zero] at this ⊢ rw [← this] abel map_smul' r f := by simp only [MonoidHom.id_apply] by_cases hr : 0 ≤ r · lift r to ℝ≥0 using hr simp only [← smul_def, toNNReal_smul, map_smul, toNNReal_neg_smul, smul_sub] · rw [not_le, ← neg_pos] at hr rw [← neg_smul] nth_rw 1 [← neg_neg r] nth_rw 3 [← neg_neg r] lift -r to ℝ≥0 using hr.le with r simp only [neg_smul, ← smul_def, toNNReal_neg_smul, map_smul, toNNReal_smul, smul_sub, sub_neg_eq_add] rw [sub_eq_add_neg, add_comm] map_star' f := by simp only [star_trivial, star_sub, ← map_star] @[fun_prop] lemma continuous_realContinuousMapZeroOfNNReal (φ : C(X, ℝ≥0)₀ →⋆ₙₐ[ℝ≥0] A) (hφ : Continuous φ) : Continuous φ.realContinuousMapZeroOfNNReal := by simp [realContinuousMapZeroOfNNReal] fun_prop end TopologicalRing @[simp high] lemma realContinuousMapZeroOfNNReal_apply_comp_toReal (φ : C(X, ℝ≥0)₀ →⋆ₙₐ[ℝ≥0] A) (f : C(X, ℝ≥0)₀) : φ.realContinuousMapZeroOfNNReal ((ContinuousMapZero.mk ⟨toReal, continuous_coe⟩ rfl).comp f) = φ f := by simp only [realContinuousMapZeroOfNNReal_apply] convert_to φ f - φ 0 = φ f using 2 on_goal -1 => rw [map_zero, sub_zero] all_goals congr ext x simp lemma realContinuousMapZeroOfNNReal_injective : Function.Injective (realContinuousMapZeroOfNNReal (X := X) (A := A)) := by intro φ ψ h ext f simpa using congr($(h) ((ContinuousMapZero.mk ⟨toReal, continuous_coe⟩ rfl).comp f)) end NonUnitalStarAlgHom open ContinuousMapZero instance NNReal.instUniqueNonUnitalContinuousFunctionalCalculus [TopologicalSpace A] [TopologicalRing A] [IsScalarTower ℝ A A] [SMulCommClass ℝ A A] [UniqueNonUnitalContinuousFunctionalCalculus ℝ A] : UniqueNonUnitalContinuousFunctionalCalculus ℝ≥0 A where compactSpace_quasispectrum a := by have : CompactSpace (quasispectrum ℝ a) := UniqueNonUnitalContinuousFunctionalCalculus.compactSpace_quasispectrum a rw [← isCompact_iff_compactSpace] at * rw [← quasispectrum.preimage_algebraMap ℝ] exact closedEmbedding_subtype_val isClosed_nonneg |>.isCompact_preimage <| by assumption eq_of_continuous_of_map_id s hs _inst h0 φ ψ hφ hψ h := by let s' : Set ℝ := (↑) '' s let e : s ≃ₜ s' := { toFun := Subtype.map (↑) (by simp [s']) invFun := Subtype.map Real.toNNReal (by simp [s']) left_inv := fun _ ↦ by ext; simp right_inv := fun x ↦ by ext obtain ⟨y, -, hy⟩ := x.2 simpa using hy ▸ NNReal.coe_nonneg y continuous_toFun := continuous_coe.subtype_map (by simp [s']) continuous_invFun := continuous_real_toNNReal.subtype_map (by simp [s']) } let _inst₁ : Zero s' := ⟨0, ⟨0, h0 ▸ Subtype.property (0 : s), coe_zero⟩⟩ have h0' : ((0 : s') : ℝ) = 0 := rfl have e0 : e 0 = 0 := by ext; simp [e, h0, h0'] have e0' : e.symm 0 = 0 := by simpa only [Homeomorph.symm_apply_apply] using congr(e.symm $(e0)).symm have (ξ : C(s, ℝ≥0)₀ →⋆ₙₐ[ℝ≥0] A) (hξ : Continuous ξ) : (let ξ' := ξ.realContinuousMapZeroOfNNReal.comp <| ContinuousMapZero.nonUnitalStarAlgHom_precomp ℝ ⟨e, e0⟩; Continuous ξ' ∧ ξ' (ContinuousMapZero.id h0') = ξ (ContinuousMapZero.id h0)) := by intro ξ' refine ⟨ξ.continuous_realContinuousMapZeroOfNNReal hξ |>.comp <| ?_, ?_⟩ · rw [continuous_induced_rng] exact ContinuousMap.continuous_comp_left _ |>.comp continuous_induced_dom · exact ξ.realContinuousMapZeroOfNNReal_apply_comp_toReal (.id h0) obtain ⟨hφ', hφ_id⟩ := this φ hφ obtain ⟨hψ', hψ_id⟩ := this ψ hψ have hs' : CompactSpace s' := e.compactSpace have h' := UniqueNonUnitalContinuousFunctionalCalculus.eq_of_continuous_of_map_id s' h0' _ _ hφ' hψ' (hφ_id ▸ hψ_id ▸ h) have h'' := congr($(h').comp <| ContinuousMapZero.nonUnitalStarAlgHom_precomp ℝ ⟨(e.symm : C(s', s)), e0'⟩) have : (ContinuousMapZero.nonUnitalStarAlgHom_precomp ℝ ⟨(e : C(s, s')), e0⟩).comp (ContinuousMapZero.nonUnitalStarAlgHom_precomp ℝ ⟨(e.symm : C(s', s)), e0'⟩) = NonUnitalStarAlgHom.id _ _ := by ext; simp simp only [NonUnitalStarAlgHom.comp_assoc, this, NonUnitalStarAlgHom.comp_id] at h'' exact NonUnitalStarAlgHom.realContinuousMapZeroOfNNReal_injective h'' end NNReal end UniqueNonUnital