source
stringlengths
17
118
lean4
stringlengths
0
335k
.lake/packages/mathlib/Mathlib/Analysis/Real/Pi/Wallis.lean
import Mathlib.Analysis.SpecialFunctions.Integrals.Basic /-! # The Wallis formula for Pi This file establishes the Wallis product for `Ο€` (`Real.tendsto_prod_pi_div_two`). Our proof is largely about analyzing the behaviour of the sequence `∫ x in 0..Ο€, sin x ^ n` as `n β†’ ∞`. See: https://en.wikipedia.org/wiki/Wallis_product The proof can be broken down into two pieces. The first step (carried out in `Mathlib/Analysis/SpecialFunctions/Integrals/Basic.lean`) is to use repeated integration by parts to obtain an explicit formula for this integral, which is rational if `n` is odd and a rational multiple of `Ο€` if `n` is even. The second step, carried out here, is to estimate the ratio `∫ (x : ℝ) in 0..Ο€, sin x ^ (2 * k + 1) / ∫ (x : ℝ) in 0..Ο€, sin x ^ (2 * k)` and prove that it converges to one using the squeeze theorem. The final product for `Ο€` is obtained after some algebraic manipulation. ## Main statements * `Real.Wallis.W`: the product of the first `k` terms in Wallis' formula for `Ο€`. * `Real.Wallis.W_eq_integral_sin_pow_div_integral_sin_pow`: express `W n` as a ratio of integrals. * `Real.Wallis.W_le` and `Real.Wallis.le_W`: upper and lower bounds for `W n`. * `Real.tendsto_prod_pi_div_two`: the Wallis product formula. -/ open scoped Real Topology Nat open Filter Finset intervalIntegral namespace Real namespace Wallis /-- The product of the first `k` terms in Wallis' formula for `Ο€`. -/ noncomputable def W (k : β„•) : ℝ := ∏ i ∈ range k, (2 * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3)) theorem W_succ (k : β„•) : W (k + 1) = W k * ((2 * k + 2) / (2 * k + 1) * ((2 * k + 2) / (2 * k + 3))) := prod_range_succ _ _ theorem W_pos (k : β„•) : 0 < W k := by induction k with | zero => unfold W; simp | succ k hk => rw [W_succ] refine mul_pos hk (mul_pos (div_pos ?_ ?_) (div_pos ?_ ?_)) <;> positivity theorem W_eq_factorial_ratio (n : β„•) : W n = 2 ^ (4 * n) * n ! ^ 4 / ((2 * n)! ^ 2 * (2 * n + 1)) := by induction n with | zero => simp only [W, prod_range_zero, Nat.factorial_zero, mul_zero, pow_zero] norm_num | succ n IH => unfold W at IH ⊒ rw [prod_range_succ, IH, _root_.div_mul_div_comm, _root_.div_mul_div_comm] refine (div_eq_div_iff ?_ ?_).mpr ?_ any_goals exact ne_of_gt (by positivity) simp_rw [Nat.mul_succ, Nat.factorial_succ, pow_succ] push_cast ring_nf theorem W_eq_integral_sin_pow_div_integral_sin_pow (k : β„•) : (Ο€ / 2)⁻¹ * W k = (∫ x : ℝ in 0..Ο€, sin x ^ (2 * k + 1)) / ∫ x : ℝ in 0..Ο€, sin x ^ (2 * k) := by rw [integral_sin_pow_even, integral_sin_pow_odd, mul_div_mul_comm, ← prod_div_distrib, inv_div] simp_rw [div_div_div_comm, div_div_eq_mul_div, mul_div_assoc] rfl theorem W_le (k : β„•) : W k ≀ Ο€ / 2 := by rw [← div_le_one pi_div_two_pos, div_eq_inv_mul] rw [W_eq_integral_sin_pow_div_integral_sin_pow, div_le_one (integral_sin_pow_pos _)] apply integral_sin_pow_succ_le theorem le_W (k : β„•) : ((2 : ℝ) * k + 1) / (2 * k + 2) * (Ο€ / 2) ≀ W k := by rw [← le_div_iffβ‚€ pi_div_two_pos, div_eq_inv_mul (W k) _] rw [W_eq_integral_sin_pow_div_integral_sin_pow, le_div_iffβ‚€ (integral_sin_pow_pos _)] convert integral_sin_pow_succ_le (2 * k + 1) rw [integral_sin_pow (2 * k)] simp theorem tendsto_W_nhds_pi_div_two : Tendsto W atTop (𝓝 <| Ο€ / 2) := by refine tendsto_of_tendsto_of_tendsto_of_le_of_le ?_ tendsto_const_nhds le_W W_le have : 𝓝 (Ο€ / 2) = 𝓝 ((1 - 0) * (Ο€ / 2)) := by rw [sub_zero, one_mul] rw [this] refine Tendsto.mul ?_ tendsto_const_nhds have h : βˆ€ n : β„•, ((2 : ℝ) * n + 1) / (2 * n + 2) = 1 - 1 / (2 * n + 2) := by intro n rw [sub_div' (ne_of_gt (add_pos_of_nonneg_of_pos (mul_nonneg (two_pos : 0 < (2 : ℝ)).le (Nat.cast_nonneg _)) two_pos)), one_mul] congr 1; ring simp_rw [h] refine (tendsto_const_nhds.div_atTop ?_).const_sub _ refine Tendsto.atTop_add ?_ tendsto_const_nhds exact tendsto_natCast_atTop_atTop.const_mul_atTop two_pos end Wallis end Real /-- Wallis' product formula for `Ο€ / 2`. -/ theorem Real.tendsto_prod_pi_div_two : Tendsto (fun k => ∏ i ∈ range k, ((2 : ℝ) * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3))) atTop (𝓝 (Ο€ / 2)) := Real.Wallis.tendsto_W_nhds_pi_div_two
.lake/packages/mathlib/Mathlib/Analysis/Real/Pi/Irrational.lean
import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.Topology.Algebra.Order.Floor import Mathlib.NumberTheory.Real.Irrational /-! # `Real.pi` is irrational The main result of this file is `irrational_pi`. The proof is adapted from https://en.wikipedia.org/wiki/Proof_that_%CF%80_is_irrational#Cartwright's_proof. The proof idea is as follows. * Define a sequence of integrals `I n ΞΈ = ∫ x in (-1)..1, (1 - x ^ 2) ^ n * cos (x * ΞΈ)`. * Give a recursion formula for `I (n + 2) ΞΈ * ΞΈ ^ 2` in terms of `I n ΞΈ` and `I (n + 1) ΞΈ`. Note we do not find it helpful to define `J` as in the above proof, and instead work directly with `I`. * Define polynomials with integer coefficients `sinPoly n` and `cosPoly n` such that `I n ΞΈ * ΞΈ ^ (2 * n + 1) = n ! * (sinPoly n ΞΈ * sin ΞΈ + cosPoly n ΞΈ * cos ΞΈ)`. Note that in the informal proof, these polynomials are not defined explicitly, but we find it useful to define them by recursion. * Show that both these polynomials have degree bounded by `n`. * Show that `0 < I n (Ο€ / 2) ≀ 2` for all `n`. * Now we can finish: if `Ο€ / 2` is rational, write it as `a / b` with `a, b > 0`. Then `b ^ (2 * n + 1) * sinPoly n (a / b)` is a positive integer by the degree bound. But it is equal to `a ^ (2 * n + 1) / n ! * I n (Ο€ / 2) ≀ 2 * a * (2 * n + 1) / n !`, which converges to 0 as `n β†’ ∞`. -/ noncomputable section open intervalIntegral MeasureTheory.MeasureSpace Set Polynomial Real open scoped Nat /-- The sequence of integrals used for Cartwright's proof of irrationality of `Ο€`. -/ private def I (n : β„•) (ΞΈ : ℝ) : ℝ := ∫ x in (-1)..1, (1 - x ^ 2) ^ n * cos (x * ΞΈ) variable {n : β„•} {ΞΈ : ℝ} private lemma I_zero : I 0 ΞΈ * ΞΈ = 2 * sin ΞΈ := by rw [mul_comm, I] simp [mul_integral_comp_mul_right, two_mul] /-- Auxiliary for the proof that `Ο€` is irrational. While it is most natural to give the recursive formula for `I (n + 2) ΞΈ`, as well as give the second base case of `I 1 ΞΈ`, it is in fact more convenient to give the recursive formula for `I (n + 1) ΞΈ` in terms of `I n ΞΈ` and `I (n - 1) ΞΈ` (note the natural subtraction!). Despite the usually inconvenient subtraction, this in fact allows deducing both of the above facts with significantly fewer analysis computations. In addition, note the `0 ^ n` on the right-hand side - this is intentional, and again allows combining the proof of the "usual" recursion formula and the base case `I 1 ΞΈ`. -/ private lemma recursion' (n : β„•) : I (n + 1) ΞΈ * ΞΈ ^ 2 = - (2 * 2 * ((n + 1) * (0 ^ n * cos ΞΈ))) + 2 * (n + 1) * (2 * n + 1) * I n ΞΈ - 4 * (n + 1) * n * I (n - 1) ΞΈ := by rw [I] let f (x : ℝ) : ℝ := 1 - x ^ 2 let u₁ (x : ℝ) : ℝ := f x ^ (n + 1) let u₁' (x : ℝ) : ℝ := - (2 * (n + 1) * x * f x ^ n) let v₁ (x : ℝ) : ℝ := sin (x * ΞΈ) let v₁' (x : ℝ) : ℝ := cos (x * ΞΈ) * ΞΈ let uβ‚‚ (x : ℝ) : ℝ := x * (f x) ^ n let uβ‚‚' (x : ℝ) : ℝ := (f x) ^ n - 2 * n * x ^ 2 * (f x) ^ (n - 1) let vβ‚‚ (x : ℝ) : ℝ := cos (x * ΞΈ) let vβ‚‚' (x : ℝ) : ℝ := -sin (x * ΞΈ) * ΞΈ have hfd : Continuous f := by fun_prop have hu₁d : Continuous u₁' := by fun_prop have hv₁d : Continuous v₁' := by fun_prop have huβ‚‚d : Continuous uβ‚‚' := by fun_prop have hvβ‚‚d : Continuous vβ‚‚' := by fun_prop have hu₁_eval_one : u₁ 1 = 0 := by simp only [u₁, f]; simp have hu₁_eval_neg_one : u₁ (-1) = 0 := by simp only [u₁, f]; simp have t : uβ‚‚ 1 * vβ‚‚ 1 - uβ‚‚ (-1) * vβ‚‚ (-1) = 2 * (0 ^ n * cos ΞΈ) := by simp [uβ‚‚, vβ‚‚, f, ← two_mul] have hf (x) : HasDerivAt f (- 2 * x) x := by convert (hasDerivAt_pow 2 x).const_sub 1 using 1 simp have hu₁ (x) : HasDerivAt u₁ (u₁' x) x := by convert (hf x).pow _ using 1 simp only [Nat.add_succ_sub_one, u₁', Nat.cast_add_one] ring have hv₁ (x) : HasDerivAt v₁ (v₁' x) x := (hasDerivAt_mul_const ΞΈ).sin have huβ‚‚ (x) : HasDerivAt uβ‚‚ (uβ‚‚' x) x := by convert (hasDerivAt_id' x).fun_mul ((hf x).fun_pow _) using 1 simp only [uβ‚‚'] ring have hvβ‚‚ (x) : HasDerivAt vβ‚‚ (vβ‚‚' x) x := (hasDerivAt_mul_const ΞΈ).cos convert_to (∫ (x : ℝ) in (-1)..1, u₁ x * v₁' x) * ΞΈ = _ using 1 Β· simp_rw [u₁, v₁', f, ← intervalIntegral.integral_mul_const, sq ΞΈ, mul_assoc] rw [integral_mul_deriv_eq_deriv_mul (fun x _ => hu₁ x) (fun x _ => hv₁ x) (hu₁d.intervalIntegrable _ _) (hv₁d.intervalIntegrable _ _), hu₁_eval_one, hu₁_eval_neg_one, zero_mul, zero_mul, sub_zero, zero_sub, ← integral_neg, ← integral_mul_const] convert_to ((-2 : ℝ) * (n + 1)) * ∫ (x : ℝ) in (-1)..1, (uβ‚‚ x * vβ‚‚' x) = _ using 1 Β· rw [← integral_const_mul] congr 1 with x dsimp [u₁', v₁, uβ‚‚, vβ‚‚'] ring rw [integral_mul_deriv_eq_deriv_mul (fun x _ => huβ‚‚ x) (fun x _ => hvβ‚‚ x) (huβ‚‚d.intervalIntegrable _ _) (hvβ‚‚d.intervalIntegrable _ _), mul_sub, t, neg_mul, neg_mul, neg_mul, sub_neg_eq_add] have (x : _) : uβ‚‚' x = (2 * n + 1) * f x ^ n - 2 * n * f x ^ (n - 1) := by cases n with | zero => simp [uβ‚‚'] | succ n => ring! simp_rw [this, sub_mul, mul_assoc _ _ (vβ‚‚ _)] have : Continuous vβ‚‚ := by fun_prop rw [mul_mul_mul_comm, integral_sub, mul_sub, add_sub_assoc] Β· congr 1 simp_rw [integral_const_mul] ring! all_goals exact Continuous.intervalIntegrable (by fun_prop) _ _ /-- Auxiliary for the proof that `Ο€` is irrational. The recursive formula for `I (n + 2) ΞΈ * ΞΈ ^ 2` in terms of `I n ΞΈ` and `I (n + 1) ΞΈ`. -/ private lemma recursion (n : β„•) : I (n + 2) ΞΈ * ΞΈ ^ 2 = 2 * (n + 2) * (2 * n + 3) * I (n + 1) ΞΈ - 4 * (n + 2) * (n + 1) * I n ΞΈ := by rw [recursion' (n + 1)] push_cast ring /-- Auxiliary for the proof that `Ο€` is irrational. The second base case for the induction on `n`, giving an explicit formula for `I 1 ΞΈ`. -/ private lemma I_one : I 1 ΞΈ * ΞΈ ^ 3 = 4 * sin ΞΈ - 4 * ΞΈ * cos ΞΈ := by rw [_root_.pow_succ, ← mul_assoc, recursion' 0, sub_mul, add_mul, mul_assoc _ (I 0 ΞΈ), I_zero] ring /-- Auxiliary for the proof that `Ο€` is irrational. The first of the two integer-coefficient polynomials that describe the behaviour of the sequence of integrals `I`. While not given in the informal proof, these are easy to deduce from the recursion formulae. -/ private def sinPoly : β„• β†’ β„€[X] | 0 => C 2 | 1 => C 4 | (n+2) => ((2 : β„€) * (2 * n + 3)) β€’ sinPoly (n + 1) + monomial 2 (-4) * sinPoly n /-- Auxiliary for the proof that `Ο€` is irrational. The second of the two integer-coefficient polynomials that describe the behaviour of the sequence of integrals `I`. While not given in the informal proof, these are easy to deduce from the recursion formulae. -/ private def cosPoly : β„• β†’ β„€[X] | 0 => 0 | 1 => monomial 1 (-4) | (n+2) => ((2 : β„€) * (2 * n + 3)) β€’ cosPoly (n + 1) + monomial 2 (-4) * cosPoly n /-- Auxiliary for the proof that `Ο€` is irrational. Prove a degree bound for `sinPoly n` by induction. Note this is where we find the value in an explicit description of `sinPoly`. -/ private lemma sinPoly_natDegree_le : βˆ€ n : β„•, (sinPoly n).natDegree ≀ n | 0 => by simp [sinPoly] | 1 => by simp only [natDegree_C, zero_le', sinPoly] | n + 2 => by rw [sinPoly] refine natDegree_add_le_of_degree_le ((natDegree_smul_le _ _).trans ?_) ?_ Β· exact (sinPoly_natDegree_le (n + 1)).trans (by simp) refine natDegree_mul_le.trans ?_ simpa [add_comm 2] using sinPoly_natDegree_le n /-- Auxiliary for the proof that `Ο€` is irrational. Prove a degree bound for `cosPoly n` by induction. Note this is where we find the value in an explicit description of `cosPoly`. -/ private lemma cosPoly_natDegree_le : βˆ€ n : β„•, (cosPoly n).natDegree ≀ n | 0 => by simp [cosPoly] | 1 => (natDegree_monomial_le _).trans (by simp) | n + 2 => by rw [cosPoly] refine natDegree_add_le_of_degree_le ((natDegree_smul_le _ _).trans ?_) ?_ Β· exact (cosPoly_natDegree_le (n + 1)).trans (by simp) exact natDegree_mul_le.trans (by simp [add_comm 2, cosPoly_natDegree_le n]) /-- Auxiliary for the proof that `Ο€` is irrational. The key lemma: the sequence of integrals `I` can be written as a linear combination of `sin` and `cos`, with coefficients given by the polynomials `sinPoly` and `cosPoly`. -/ private lemma sinPoly_add_cosPoly_eval (ΞΈ : ℝ) : βˆ€ n : β„•, I n ΞΈ * ΞΈ ^ (2 * n + 1) = n ! * ((sinPoly n).evalβ‚‚ (Int.castRingHom _) ΞΈ * sin ΞΈ + (cosPoly n).evalβ‚‚ (Int.castRingHom _) ΞΈ * cos ΞΈ) | 0 => by simp [sinPoly, cosPoly, I_zero] | 1 => by simp [I_one, sinPoly, cosPoly, sub_eq_add_neg] | n + 2 => by calc I (n + 2) ΞΈ * ΞΈ ^ (2 * (n + 2) + 1) = I (n + 2) ΞΈ * ΞΈ ^ 2 * ΞΈ ^ (2 * n + 3) := by ring _ = 2 * (n + 2) * (2 * n + 3) * (I (n + 1) ΞΈ * ΞΈ ^ (2 * (n + 1) + 1)) - 4 * (n + 2) * (n + 1) * ΞΈ ^ 2 * (I n ΞΈ * ΞΈ ^ (2 * n + 1)) := by rw [recursion]; ring _ = _ := by simp [sinPoly_add_cosPoly_eval, sinPoly, cosPoly, Nat.factorial_succ]; ring /-- Auxiliary for the proof that `Ο€` is irrational. For a polynomial `p` with natural degree `≀ k` and integer coefficients, evaluating `p` at a rational `a / b` gives a rational of the form `z / b ^ k`. TODO: should this be moved elsewhere? It uses none of the pi-specific definitions. -/ private lemma is_integer {p : β„€[X]} (a b : β„€) {k : β„•} (hp : p.natDegree ≀ k) : βˆƒ z : β„€, p.evalβ‚‚ (Int.castRingHom ℝ) (a / b) * b ^ k = z := by rcases eq_or_ne b 0 with rfl | hb Β· rcases k.eq_zero_or_pos with rfl | hk Β· exact ⟨p.coeff 0, by simp⟩ exact ⟨0, by simp [hk.ne']⟩ refine βŸ¨βˆ‘ i ∈ p.support, p.coeff i * a ^ i * b ^ (k - i), ?_⟩ conv => lhs; rw [← sum_monomial_eq p] rw [evalβ‚‚_sum, sum, Finset.sum_mul, Int.cast_sum] simp only [evalβ‚‚_monomial, eq_intCast, div_pow, Int.cast_mul, Int.cast_pow] refine Finset.sum_congr rfl (fun i hi => ?_) have ik := (le_natDegree_of_mem_supp i hi).trans hp rw [mul_assoc, div_mul_comm, ← Int.cast_pow, ← Int.cast_pow, ← Int.cast_pow, ← pow_sub_mul_pow b ik, ← Int.cast_div_charZero, Int.mul_ediv_cancel _ (pow_ne_zero _ hb), ← mul_assoc, mul_right_comm, ← Int.cast_pow] exact dvd_mul_left _ _ open Filter /-- Auxiliary for the proof that `Ο€` is irrational. The integrand in the definition of `I` is nonnegative and takes a positive value at least one point, so the integral is positive. -/ private lemma I_pos : 0 < I n (Ο€ / 2) := by refine integral_pos (by simp) (by fun_prop) ?_ ⟨0, by simp⟩ refine fun x hx => mul_nonneg (pow_nonneg ?_ _) ?_ Β· rw [sub_nonneg, sq_le_one_iff_abs_le_one, abs_le] exact ⟨hx.1.le, hx.2⟩ refine cos_nonneg_of_neg_pi_div_two_le_of_le ?_ ?_ <;> nlinarith [hx.1, hx.2, pi_pos] /-- Auxiliary for the proof that `Ο€` is irrational. The integrand in the definition of `I` is bounded by 1 and the interval has length 2, so the integral is bounded above by `2`. -/ private lemma I_le (n : β„•) : I n (Ο€ / 2) ≀ 2 := by rw [← norm_of_nonneg I_pos.le] refine (norm_integral_le_of_norm_le_const ?_).trans (show (1 : ℝ) * _ ≀ _ by norm_num) intro x hx simp only [uIoc_of_le, neg_le_self_iff, zero_le_one, mem_Ioc] at hx rw [norm_eq_abs, abs_mul, abs_pow] refine mul_le_oneβ‚€ (pow_le_oneβ‚€ (abs_nonneg _) ?_) (abs_nonneg _) (abs_cos_le_one _) rw [abs_le] constructor <;> nlinarith /-- Auxiliary for the proof that `Ο€` is irrational. For any real `a`, we have that `a ^ (2n+1) / n!` tends to `0` as `n β†’ ∞`. This is just a reformulation of tendsto_pow_div_factorial_atTop, which asserts the same for `a ^ n / n!` -/ private lemma tendsto_pow_div_factorial_at_top_aux (a : ℝ) : Tendsto (fun n => (a : ℝ) ^ (2 * n + 1) / n !) atTop (nhds 0) := by rw [← mul_zero a] refine ((FloorSemiring.tendsto_pow_div_factorial_atTop (a ^ 2)).const_mul a).congr (fun x => ?_) rw [← pow_mul, mul_div_assoc', _root_.pow_succ'] /-- If `x` is rational, it can be written as `a / b` with `a : β„€` and `b : β„•` satisfying `b > 0`. -/ private lemma not_irrational_exists_rep {x : ℝ} : Β¬Irrational x β†’ βˆƒ (a : β„€) (b : β„•), 0 < b ∧ x = a / b := by rw [Irrational, not_not, mem_range] rintro ⟨q, rfl⟩ exact ⟨q.num, q.den, q.pos, by exact_mod_cast (Rat.num_div_den _).symm⟩ @[simp] theorem irrational_pi : Irrational Ο€ := by apply Irrational.of_div_natCast 2 rw [Nat.cast_two] by_contra h' obtain ⟨a, b, hb, h⟩ := not_irrational_exists_rep h' have ha : (0 : ℝ) < a := by have : 0 < (a : ℝ) / b := h β–Έ pi_div_two_pos rwa [lt_div_iffβ‚€ (by positivity), zero_mul] at this have k (n : β„•) : 0 < (a : ℝ) ^ (2 * n + 1) / n ! := by positivity have j : βˆ€αΆ  n : β„• in atTop, (a : ℝ) ^ (2 * n + 1) / n ! * I n (Ο€ / 2) < 1 := by have := (tendsto_pow_div_factorial_at_top_aux a).eventually_lt_const (show (0 : ℝ) < 1 / 2 by simp) filter_upwards [this] with n hn rw [lt_div_iffβ‚€ (zero_lt_two : (0 : ℝ) < 2)] at hn exact hn.trans_le' (mul_le_mul_of_nonneg_left (I_le _) (by positivity)) obtain ⟨n, hn⟩ := j.exists have hn' : 0 < a ^ (2 * n + 1) / n ! * I n (Ο€ / 2) := mul_pos (k _) I_pos obtain ⟨z, hz⟩ : βˆƒ z : β„€, (sinPoly n).evalβ‚‚ (Int.castRingHom ℝ) (a / b) * b ^ (2 * n + 1) = z := is_integer a b ((sinPoly_natDegree_le _).trans (by cutsat)) have e := sinPoly_add_cosPoly_eval (Ο€ / 2) n rw [cos_pi_div_two, sin_pi_div_two, mul_zero, mul_one, add_zero] at e have : a ^ (2 * n + 1) / n ! * I n (Ο€ / 2) = evalβ‚‚ (Int.castRingHom ℝ) (Ο€ / 2) (sinPoly n) * b ^ (2 * n + 1) := by nth_rw 2 [h] at e simp [field, div_pow] at e ⊒ linear_combination e have : (0 : ℝ) < z ∧ (z : ℝ) < 1 := by simp [← hz, ← h, ← this, hn', hn] norm_cast at this cutsat end
.lake/packages/mathlib/Mathlib/Analysis/Real/Pi/Chudnovsky.lean
import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Batteries.Data.Rat.Float /-! # Chudnovsky's formula for Ο€ This file defines the infinite sum in Chudnovsky's formula for computing `π⁻¹`. It does not (yet!) contain a proof; anyone is welcome to adopt this problem, but at present we are a long way off. ## Main definitions * `chudnovskySum`: The infinite sum in Chudnovsky's formula ## Future work * Use this formula to give approximations for `Ο€`. * Prove the sum equals `π⁻¹`, as stated using `proof_wanted` below. * Show that each imaginary quadratic field of class number 1 (corresponding to Heegner numbers) gives a Ramanujan type formula, and that this is the formula coming from 163, with $$j(\frac{1+\sqrt{-163}}{2}) = -640320^3$$, and the other magic constants coming from Eisenstein series. ## References * [Milla, *A detailed proof of the Chudnovsky formula*][Milla_2018] * [Chen and Glebov, *On Chudnovsky--Ramanujan type formulae*][Chen_Glebov_2018] -/ open scoped Real BigOperators open Nat /-- The numerator of the nth term in Chudnovsky's series -/ def chudnovskyNum (n : β„•) : β„€ := (-1 : β„€) ^ n * (6 * n)! * (545140134 * n + 13591409) /-- The denominator of the nth term in Chudnovsky's series -/ def chudnovskyDenom (n : β„•) : β„• := (3 * n)! * (n)! ^ 3 * 640320 ^ (3 * n) /-- The term at index `n` in Chudnovsky's series for `π⁻¹` -/ def chudnovskyTerm (n : β„•) : β„š := chudnovskyNum n / chudnovskyDenom n -- Sanity check that when calculated in `Float` we get the right answer: /-- info: 3.141593 -/ #guard_msgs in #eval 1 / (12 / (640320 : Float) ^ (3 / 2) * (List.ofFn fun n : Fin 37 => (chudnovskyTerm n).toFloat).sum) /-- The infinite sum in Chudnovsky's formula for `π⁻¹` -/ noncomputable def chudnovskySum : ℝ := 12 / (640320 : ℝ) ^ (3 / 2 : ℝ) * βˆ‘' n : β„•, (chudnovskyTerm n : ℝ) /-- **Chudnovsky's formula**: The sum equals `π⁻¹` -/ proof_wanted chudnovskySum_eq_pi_inv : chudnovskySum = π⁻¹
.lake/packages/mathlib/Mathlib/Analysis/Real/Pi/Leibniz.lean
import Mathlib.Analysis.Complex.AbelLimit import Mathlib.Analysis.SpecialFunctions.Complex.Arctan /-! ### Leibniz's series for `Ο€` -/ namespace Real open Filter Finset open scoped Topology /-- **Leibniz's series for `Ο€`**. The alternating sum of odd number reciprocals is `Ο€ / 4`, proved by using Abel's limit theorem to extend the Maclaurin series of `arctan` to 1. -/ theorem tendsto_sum_pi_div_four : Tendsto (fun k => βˆ‘ i ∈ range k, (-1 : ℝ) ^ i / (2 * i + 1)) atTop (𝓝 (Ο€ / 4)) := by -- The series is alternating with terms of decreasing magnitude, so it converges to some limit obtain ⟨l, h⟩ : βˆƒ l, Tendsto (fun n ↦ βˆ‘ i ∈ range n, (-1 : ℝ) ^ i / (2 * i + 1)) atTop (𝓝 l) := by apply Antitone.tendsto_alternating_series_of_tendsto_zero Β· exact antitone_iff_forall_lt.mpr fun _ _ _ ↦ by gcongr Β· apply Tendsto.inv_tendsto_atTop; apply tendsto_atTop_add_const_right exact tendsto_natCast_atTop_atTop.const_mul_atTop zero_lt_two -- Abel's limit theorem states that the corresponding power series has the same limit as `x β†’ 1⁻` have abel := tendsto_tsum_powerSeries_nhdsWithin_lt h -- Massage the expression to get `x ^ (2 * n + 1)` in the tsum rather than `x ^ n`... have m : 𝓝[<] (1 : ℝ) ≀ 𝓝 1 := tendsto_nhdsWithin_of_tendsto_nhds fun _ a ↦ a have q : Tendsto (fun x : ℝ ↦ x ^ 2) (𝓝[<] 1) (𝓝[<] 1) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within Β· nth_rw 3 [← one_pow 2] exact Tendsto.pow β€Ή_β€Ί _ Β· rw [eventually_iff_exists_mem] use Set.Ioo (-1) 1 exact ⟨Ioo_mem_nhdsLT <| by simp, fun _ _ ↦ by rwa [Set.mem_Iio, sq_lt_one_iff_abs_lt_one, abs_lt, ← Set.mem_Ioo]⟩ replace abel := (abel.comp q).mul m rw [mul_one] at abel -- ...so that we can replace the tsum with the real arctangent function replace abel : Tendsto arctan (𝓝[<] 1) (𝓝 l) := by apply abel.congr' rw [eventuallyEq_nhdsWithin_iff, Metric.eventually_nhds_iff] use 1, zero_lt_one intro y hy1 hy2 rw [dist_eq, abs_sub_lt_iff] at hy1 rw [Set.mem_Iio] at hy2 have ny : β€–yβ€– < 1 := by rw [norm_eq_abs, abs_lt]; constructor <;> linarith rw [← (hasSum_arctan ny).tsum_eq, Function.comp_apply, ← tsum_mul_right] simp_rw [mul_assoc, ← pow_mul, ← pow_succ, div_mul_eq_mul_div] norm_cast -- But `arctan` is continuous everywhere, so the limit is `arctan 1 = Ο€ / 4` rwa [tendsto_nhds_unique abel ((continuous_arctan.tendsto 1).mono_left m), arctan_one] at h end Real
.lake/packages/mathlib/Mathlib/Analysis/Real/Pi/Bounds.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds /-! # Pi This file contains lemmas which establish bounds on `Real.pi`. Notably, these include `pi_gt_sqrtTwoAddSeries` and `pi_lt_sqrtTwoAddSeries`, which bound `Ο€` using series; numerical bounds on `Ο€` such as `pi_gt_d2` and `pi_lt_d2` (more precise versions are given, too). See also `Mathlib/Analysis/Real/Pi/Leibniz.lean` and `Mathlib/Analysis/Real/Pi/Wallis.lean` for infinite formulas for `Ο€`. -/ open scoped Real namespace Real theorem pi_gt_sqrtTwoAddSeries (n : β„•) : 2 ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) < Ο€ := by have : √(2 - sqrtTwoAddSeries 0 n) / 2 * 2 ^ (n + 2) < Ο€ := by rw [← lt_div_iffβ‚€, ← sin_pi_over_two_pow_succ] focus apply sin_lt apply div_pos pi_pos all_goals apply pow_pos; norm_num refine lt_of_le_of_lt (le_of_eq ?_) this rw [pow_succ' _ (n + 1), ← mul_assoc, div_mul_cancelβ‚€, mul_comm]; simp theorem pi_lt_sqrtTwoAddSeries (n : β„•) : Ο€ < 2 ^ (n + 1) * √(2 - sqrtTwoAddSeries 0 n) + 1 / 4 ^ n := by have : Ο€ < (√(2 - sqrtTwoAddSeries 0 n) / 2 + 1 / (2 ^ n) ^ 3 / 4) * (2 : ℝ) ^ (n + 2) := by rw [← div_lt_iffβ‚€ (by simp), ← sin_pi_over_two_pow_succ, ← sub_lt_iff_lt_add'] calc Ο€ / 2 ^ (n + 2) - sin (Ο€ / 2 ^ (n + 2)) < (Ο€ / 2 ^ (n + 2)) ^ 3 / 4 := sub_lt_comm.1 <| sin_gt_sub_cube (by positivity) <| div_le_one_of_leβ‚€ ?_ (by positivity) _ ≀ (4 / 2 ^ (n + 2)) ^ 3 / 4 := by gcongr; exact pi_le_four _ = 1 / (2 ^ n) ^ 3 / 4 := by simp [add_comm n, pow_add, div_mul_eq_div_div]; norm_num calc Ο€ ≀ 4 := pi_le_four _ = 2 ^ (0 + 2) := by norm_num _ ≀ 2 ^ (n + 2) := by gcongr <;> norm_num refine lt_of_lt_of_le this (le_of_eq ?_); rw [add_mul]; congr 1 Β· ring simp only [show (4 : ℝ) = 2 ^ 2 by norm_num, ← pow_mul, div_div, ← pow_add] rw [one_div, one_div, inv_mul_eq_iff_eq_mulβ‚€, eq_comm, mul_inv_eq_iff_eq_mulβ‚€, ← pow_add] Β· rw [add_assoc, Nat.mul_succ, add_comm, add_comm n, add_assoc, mul_comm n] all_goals norm_num /-- From an upper bound on `sqrtTwoAddSeries 0 n = 2 cos (Ο€ / 2 ^ (n+1))` of the form `sqrtTwoAddSeries 0 n ≀ 2 - (a / 2 ^ (n + 1)) ^ 2)`, one can deduce the lower bound `a < Ο€` thanks to basic trigonometric inequalities as expressed in `pi_gt_sqrtTwoAddSeries`. -/ theorem pi_lower_bound_start (n : β„•) {a} (h : sqrtTwoAddSeries ((0 : β„•) / (1 : β„•)) n ≀ (2 : ℝ) - (a / (2 : ℝ) ^ (n + 1)) ^ 2) : a < Ο€ := by refine lt_of_le_of_lt ?_ (pi_gt_sqrtTwoAddSeries n); rw [mul_comm] refine (div_le_iffβ‚€ (pow_pos (by simp) _)).mp (le_sqrt_of_sq_le ?_) rwa [le_sub_comm, show (0 : ℝ) = (0 : β„•) / (1 : β„•) by rw [Nat.cast_zero, zero_div]] theorem sqrtTwoAddSeries_step_up (c d : β„•) {a b n : β„•} {z : ℝ} (hz : sqrtTwoAddSeries (c / d) n ≀ z) (hb : 0 < b) (hd : 0 < d) (h : (2 * b + a) * d ^ 2 ≀ c ^ 2 * b) : sqrtTwoAddSeries (a / b) (n + 1) ≀ z := by refine le_trans ?_ hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [sqrt_le_left (div_nonneg c.cast_nonneg d.cast_nonneg), div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hb'), div_le_div_iffβ‚€ hb' (pow_pos hd' _)] exact mod_cast h /-- From a lower bound on `sqrtTwoAddSeries 0 n = 2 cos (Ο€ / 2 ^ (n+1))` of the form `2 - ((a - 1 / 4 ^ n) / 2 ^ (n + 1)) ^ 2 ≀ sqrtTwoAddSeries 0 n`, one can deduce the upper bound `Ο€ < a` thanks to basic trigonometric formulas as expressed in `pi_lt_sqrtTwoAddSeries`. -/ theorem pi_upper_bound_start (n : β„•) {a} (h : (2 : ℝ) - ((a - 1 / (4 : ℝ) ^ n) / (2 : ℝ) ^ (n + 1)) ^ 2 ≀ sqrtTwoAddSeries ((0 : β„•) / (1 : β„•)) n) (hβ‚‚ : (1 : ℝ) / (4 : ℝ) ^ n ≀ a) : Ο€ < a := by refine lt_of_lt_of_le (pi_lt_sqrtTwoAddSeries n) ?_ rw [← le_sub_iff_add_le, ← le_div_iffβ‚€', sqrt_le_left, sub_le_comm] Β· rwa [Nat.cast_zero, zero_div] at h Β· exact div_nonneg (sub_nonneg.2 hβ‚‚) (pow_nonneg (le_of_lt zero_lt_two) _) Β· exact pow_pos zero_lt_two _ theorem sqrtTwoAddSeries_step_down (a b : β„•) {c d n : β„•} {z : ℝ} (hz : z ≀ sqrtTwoAddSeries (a / b) n) (hb : 0 < b) (hd : 0 < d) (h : a ^ 2 * d ≀ (2 * d + c) * b ^ 2) : z ≀ sqrtTwoAddSeries (c / d) (n + 1) := by apply le_trans hz; rw [sqrtTwoAddSeries_succ]; apply sqrtTwoAddSeries_monotone_left apply le_sqrt_of_sq_le have hb' : 0 < (b : ℝ) := Nat.cast_pos.2 hb have hd' : 0 < (d : ℝ) := Nat.cast_pos.2 hd rw [div_pow, add_div_eq_mul_add_div _ _ (ne_of_gt hd'), div_le_div_iffβ‚€ (pow_pos hb' _) hd'] exact mod_cast h section Tactic open Lean Elab Tactic Qq /-- Create a proof of `a < Ο€` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) ≀ r(i+1)`, where `r 0 = 0` and `√(2 - r n) β‰₯ a/2^(n+1)`. -/ elab "pi_lower_bound " "[" l:term,* "]" : tactic => do have els := l.getElems let n := quote els.size evalTactic (← `(tactic| apply pi_lower_bound_start $n)) for l in els do let {num, den, ..} ← unsafe Meta.evalExpr β„š q(β„š) (← Term.elabTermAndSynthesize l (some q(β„š))) evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_up $(quote num.toNat) $(quote den))) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals <| evalTactic (← `(tactic| norm_num1)) /-- Create a proof of `Ο€ < a` for a fixed rational number `a`, given a witness, which is a sequence of rational numbers `√2 < r 1 < r 2 < ... < r n < 2` satisfying the property that `√(2 + r i) β‰₯ r(i+1)`, where `r 0 = 0` and `√(2 - r n) ≀ (a - 1/4^n) / 2^(n+1)`. -/ elab "pi_upper_bound " "[" l:term,* "]" : tactic => do have els := l.getElems let n := quote els.size evalTactic (← `(tactic| apply pi_upper_bound_start $n)) for l in els do let {num, den, ..} ← unsafe Meta.evalExpr β„š q(β„š) (← Term.elabTermAndSynthesize l (some q(β„š))) evalTactic (← `(tactic| apply sqrtTwoAddSeries_step_down $(quote num.toNat) $(quote den))) evalTactic (← `(tactic| simp [sqrtTwoAddSeries])) allGoals <| evalTactic (← `(tactic| norm_num1)) end Tactic /-! The below witnesses were generated using the following Mathematica script: ```mathematica bound[a_, Iters -> n_, Rounding -> extra_, Precision -> prec_] := Module[{r0, r, r2, diff, sign}, On[Assert]; sign = If[a >= \[Pi], Print["upper"]; 1, Print["lower"]; -1]; r0 = 2 - ((a - (sign + 1)/2/4^n)/2^(n + 1))^2; r = Log[2 - NestList[#^2 - 2 &, N[r0, prec], n - 1]]; diff = (r[[-1]] - Log[2 - Sqrt[2]])/(Length[r] + 1); If[sign diff <= 0, Return["insufficient iterations"]]; r2 = Log[Rationalize[Exp[#], extra (Exp[#] - Exp[# - sign diff])] & /@ (r - diff Range[1, Length[r]])]; Assert[sign (2 - Exp@r2[[1]] - r0) >= 0]; Assert[And @@ Table[ sign (Sqrt@(4 - Exp@r2[[i + 1]]) - (2 - Exp@r2[[i]])) >= 0, {i, 1, Length[r2] - 1}]]; Assert[sign (Exp@r2[[-1]] - (2 - Sqrt[2])) >= 0]; With[{s1 = ToString@InputForm[2 - #], s2 = ToString@InputForm[#]}, If[StringLength[s1] <= StringLength[s2] + 2, s1, "2-" <> s2]] & /@ Exp@Reverse@r2 ]; ``` -/ theorem pi_gt_three : 3 < Ο€ := by -- bound[3, Iters -> 1, Rounding -> 2, Precision -> 3] pi_lower_bound [23 / 16] theorem pi_lt_four : Ο€ < 4 := by -- bound[4, Iters -> 1, Rounding -> 1, Precision -> 1] pi_upper_bound [4 / 3] theorem pi_gt_d2 : 3.14 < Ο€ := by -- bound[314*^-2, Iters -> 4, Rounding -> 1.5, Precision -> 8] pi_lower_bound [338 / 239, 704 / 381, 1940 / 989, 1447 / 727] theorem pi_lt_d2 : Ο€ < 3.15 := by -- bound[315*^-2, Iters -> 4, Rounding -> 1.4, Precision -> 7] pi_upper_bound [41 / 29, 109 / 59, 865 / 441, 412 / 207] theorem pi_gt_d4 : 3.1415 < Ο€ := by -- bound[31415*^-4, Iters -> 6, Rounding -> 1.1, Precision -> 10] pi_lower_bound [ 1970 / 1393, 3010 / 1629, 11689 / 5959, 10127 / 5088, 33997 / 17019, 23235 / 11621] theorem pi_lt_d4 : Ο€ < 3.1416 := by -- bound[31416*^-4, Iters -> 9, Rounding -> .9, Precision -> 16] pi_upper_bound [ 4756/3363, 14965/8099, 21183/10799, 49188/24713, 2-53/22000, 2-71/117869, 2-47/312092, 2-17/451533, 2-4/424971] theorem pi_gt_d6 : 3.141592 < Ο€ := by -- bound[3141592*^-6, Iters -> 10, Rounding -> .8, Precision -> 16] pi_lower_bound [ 11482/8119, 7792/4217, 54055/27557, 2-623/64690, 2-337/139887, 2-208/345307, 2-167/1108925, 2-64/1699893, 2-31/3293535, 2-48/20398657] theorem pi_lt_d6 : Ο€ < 3.141593 := by -- bound[3141593*^-6, Iters -> 11, Rounding -> .5, Precision -> 17] pi_upper_bound [ 35839/25342, 49143/26596, 145729/74292, 294095/147759, 2-137/56868, 2-471/781921, 2-153/1015961, 2-157/4170049, 2-28/2974805, 2-9/3824747, 2-7/11899211] theorem pi_gt_d20 : 3.14159265358979323846 < Ο€ := by -- bound[314159265358979323846*^-20, Iters -> 34, Rounding -> .6, Precision -> 46] pi_lower_bound [ 671574048197/474874563549, 58134718954/31462283181, 3090459598621/1575502640777, 2-7143849599/741790664068, 8431536490061/4220852446654, 2-2725579171/4524814682468, 2-2494895647/16566776788806, 2-608997841/16175484287402, 2-942567063/100141194694075, 2-341084060/144951150987041, 2-213717653/363295959742218, 2-71906926/488934711121807, 2-29337101/797916288104986, 2-45326311/4931175952730065, 2-7506877/3266776448781479, 2-5854787/10191338039232571, 2-4538642/31601378399861717, 2-276149/7691013341581098, 2-350197/39013283396653714, 2-442757/197299283738495963, 2-632505/1127415566199968707, 2-1157/8249230030392285, 2-205461/5859619883403334178, 2-33721/3846807755987625852, 2-11654/5317837263222296743, 2-8162/14897610345776687857, 2-731/5337002285107943372, 2-1320/38549072592845336201, 2-707/82588467645883795866, 2-53/24764858756615791675, 2-237/442963888703240952920, 2-128/956951523274512100791, 2-32/956951523274512100783, 2-27/3229711391051478340136] theorem pi_lt_d20 : Ο€ < 3.14159265358979323847 := by -- bound[314159265358979323847*^-20, Iters -> 34, Rounding -> .5, Precision -> 46] pi_upper_bound [ 215157040700/152139002499, 936715022285/506946517009, 1760670193473/897581880893, 2-6049918861/628200981455, 2-8543385003/3546315642356, 2-2687504973/4461606579043, 2-1443277808/9583752057175, 2-546886849/14525765179168, 2-650597193/69121426717657, 2-199969519/84981432264454, 2-226282901/384655467333100, 2-60729699/412934601558121, 2-25101251/682708800188252, 2-7156464/778571703825145, 2-7524725/3274543383827551, 2-4663362/8117442793616861, 2-1913009/13319781840326041, 2-115805/3225279830894912, 2-708749/78957345705688293, 2-131255/58489233342660393, 2-101921/181670219085488669, 2-44784/319302953916238627, 2-82141/2342610212364552264, 2-4609/525783249231842696, 2-4567/2083967975041722089, 2-2273/4148770928197796067, 2-563/4110440884426500846, 2-784/22895812812720260289, 2-1717/200571992854289218531, 2-368/171952226838388893139, 2-149/278487845640434185590, 2-207/1547570041545500037992, 2-20/598094702046570062987, 2-7/837332582865198088180] end Real
.lake/packages/mathlib/Mathlib/Analysis/Distribution/AEEqOfIntegralContDiff.lean
import Mathlib.Geometry.Manifold.PartitionOfUnity import Mathlib.Geometry.Manifold.Metrizable import Mathlib.MeasureTheory.Function.AEEqOfIntegral /-! # Functions which vanish as distributions vanish as functions In a finite-dimensional normed real vector space endowed with a Borel measure, consider a locally integrable function whose integral against all compactly supported smooth functions vanishes. Then the function is almost everywhere zero. This is proved in `ae_eq_zero_of_integral_contDiff_smul_eq_zero`. A version for two functions having the same integral when multiplied by smooth compactly supported functions is also given in `ae_eq_of_integral_contDiff_smul_eq`. These are deduced from the same results on finite-dimensional real manifolds, given respectively as `ae_eq_zero_of_integral_smooth_smul_eq_zero` and `ae_eq_of_integral_smooth_smul_eq`. -/ open MeasureTheory Filter Metric Function Set TopologicalSpace open scoped Topology Manifold ContDiff variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] section Manifold variable {H : Type*} [TopologicalSpace H] (I : ModelWithCorners ℝ E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] [IsManifold I ∞ M] [MeasurableSpace M] [BorelSpace M] [T2Space M] {f f' : M β†’ F} {ΞΌ : Measure M} /-- If a locally integrable function `f` on a finite-dimensional real manifold has zero integral when multiplied by any smooth compactly supported function, then `f` vanishes almost everywhere. -/ theorem ae_eq_zero_of_integral_smooth_smul_eq_zero [SigmaCompactSpace M] (hf : LocallyIntegrable f ΞΌ) (h : βˆ€ g : M β†’ ℝ, ContMDiff I π“˜(ℝ) ∞ g β†’ HasCompactSupport g β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = 0) : βˆ€α΅ x βˆ‚ΞΌ, f x = 0 := by -- record topological properties of `M` have := I.locallyCompactSpace have := ChartedSpace.locallyCompactSpace H M have := I.secondCountableTopology have := ChartedSpace.secondCountable_of_sigmaCompact H M have := Manifold.metrizableSpace I M let _ : MetricSpace M := TopologicalSpace.metrizableSpaceMetric M -- it suffices to show that the integral of the function vanishes on any compact set `s` apply ae_eq_zero_of_forall_setIntegral_isCompact_eq_zero' hf (fun s hs ↦ Eq.symm ?_) obtain ⟨δ, Ξ΄pos, hδ⟩ : βˆƒ Ξ΄, 0 < Ξ΄ ∧ IsCompact (cthickening Ξ΄ s) := hs.exists_isCompact_cthickening -- choose a sequence of smooth functions `gβ‚™` equal to `1` on `s` and vanishing outside of the -- `uβ‚™`-neighborhood of `s`, where `uβ‚™` tends to zero. Then each integral `∫ gβ‚™ f` vanishes, -- and by dominated convergence these integrals converge to `∫ x in s, f`. obtain ⟨u, -, u_pos, u_lim⟩ : βˆƒ u, StrictAnti u ∧ (βˆ€ (n : β„•), u n ∈ Ioo 0 Ξ΄) ∧ Tendsto u atTop (𝓝 0) := exists_seq_strictAnti_tendsto' Ξ΄pos let v : β„• β†’ Set M := fun n ↦ thickening (u n) s obtain ⟨K, K_compact, vK⟩ : βˆƒ K, IsCompact K ∧ βˆ€ n, v n βŠ† K := ⟨_, hΞ΄, fun n ↦ thickening_subset_cthickening_of_le (u_pos n).2.le _⟩ have : βˆ€ n, βˆƒ (g : M β†’ ℝ), support g = v n ∧ ContMDiff I π“˜(ℝ) ∞ g ∧ Set.range g βŠ† Set.Icc 0 1 ∧ βˆ€ x ∈ s, g x = 1 := by intro n rcases exists_msmooth_support_eq_eq_one_iff I isOpen_thickening hs.isClosed (self_subset_thickening (u_pos n).1 s) with ⟨g, g_smooth, g_range, g_supp, hg⟩ exact ⟨g, g_supp, g_smooth, g_range, fun x hx ↦ (hg x).1 hx⟩ choose g g_supp g_diff g_range hg using this -- main fact: the integral of `∫ gβ‚™ f` tends to `∫ x in s, f`. have L : Tendsto (fun n ↦ ∫ x, g n x β€’ f x βˆ‚ΞΌ) atTop (𝓝 (∫ x in s, f x βˆ‚ΞΌ)) := by rw [← integral_indicator hs.measurableSet] let bound : M β†’ ℝ := K.indicator (fun x ↦ β€–f xβ€–) have A : βˆ€ n, AEStronglyMeasurable (fun x ↦ g n x β€’ f x) ΞΌ := fun n ↦ (g_diff n).continuous.aestronglyMeasurable.smul hf.aestronglyMeasurable have B : Integrable bound ΞΌ := by rw [integrable_indicator_iff K_compact.measurableSet] exact (hf.integrableOn_isCompact K_compact).norm have C : βˆ€ n, βˆ€α΅ x βˆ‚ΞΌ, β€–g n x β€’ f xβ€– ≀ bound x := by intro n filter_upwards with x rw [norm_smul] refine le_indicator_apply (fun _ ↦ ?_) (fun hxK ↦ ?_) Β· have : β€–g n xβ€– ≀ 1 := by have := g_range n (mem_range_self (f := g n) x) rw [Real.norm_of_nonneg this.1] exact this.2 exact mul_le_of_le_one_left (norm_nonneg _) this Β· have : g n x = 0 := by rw [← notMem_support, g_supp]; contrapose! hxK; exact vK n hxK simp [this] have D : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun n => g n x β€’ f x) atTop (𝓝 (s.indicator f x)) := by filter_upwards with x by_cases hxs : x ∈ s Β· have : βˆ€ n, g n x = 1 := fun n ↦ hg n x hxs simp [this, indicator_of_mem hxs f] Β· simp_rw [indicator_of_notMem hxs f] apply tendsto_const_nhds.congr' suffices H : βˆ€αΆ  n in atTop, g n x = 0 by filter_upwards [H] with n hn using by simp [hn] obtain ⟨Ρ, Ξ΅pos, hΡ⟩ : βˆƒ Ξ΅, 0 < Ξ΅ ∧ x βˆ‰ thickening Ξ΅ s := by rw [← hs.isClosed.closure_eq, closure_eq_iInter_thickening s] at hxs simpa using hxs filter_upwards [(tendsto_order.1 u_lim).2 _ Ξ΅pos] with n hn rw [← notMem_support, g_supp] contrapose! hΞ΅ exact thickening_mono hn.le s hΞ΅ exact tendsto_integral_of_dominated_convergence bound A B C D -- deduce that `∫ x in s, f = 0` as each integral `∫ gβ‚™ f` vanishes by assumption have : βˆ€ n, ∫ x, g n x β€’ f x βˆ‚ΞΌ = 0 := by refine fun n ↦ h _ (g_diff n) ?_ apply HasCompactSupport.of_support_subset_isCompact K_compact simpa [g_supp] using vK n simpa [this] using L -- An instance with keys containing `Opens` instance (U : Opens M) : BorelSpace U := inferInstanceAs (BorelSpace (U : Set M)) /-- If a function `f` locally integrable on an open subset `U` of a finite-dimensional real manifold has zero integral when multiplied by any smooth function compactly supported in `U`, then `f` vanishes almost everywhere in `U`. -/ nonrec theorem IsOpen.ae_eq_zero_of_integral_smooth_smul_eq_zero' {U : Set M} (hU : IsOpen U) (hSig : IsSigmaCompact U) (hf : LocallyIntegrableOn f U ΞΌ) (h : βˆ€ g : M β†’ ℝ, ContMDiff I π“˜(ℝ) ∞ g β†’ HasCompactSupport g β†’ tsupport g βŠ† U β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = 0) : βˆ€α΅ x βˆ‚ΞΌ, x ∈ U β†’ f x = 0 := by have meas_U := hU.measurableSet rw [← ae_restrict_iff' meas_U, ae_restrict_iff_subtype meas_U] let U : Opens M := ⟨U, hU⟩ change βˆ€α΅ (x : U) βˆ‚_, _ haveI : SigmaCompactSpace U := isSigmaCompact_iff_sigmaCompactSpace.mp hSig refine ae_eq_zero_of_integral_smooth_smul_eq_zero I ?_ fun g g_smth g_supp ↦ ?_ Β· exact (locallyIntegrable_comap meas_U).mpr hf specialize h (Subtype.val.extend g 0) (g_smth.extend_zero g_supp) (g_supp.extend_zero continuous_subtype_val) ((g_supp.tsupport_extend_zero_subset continuous_subtype_val).trans <| Subtype.coe_image_subset _ _) rw [← setIntegral_eq_integral_of_forall_compl_eq_zero (s := U) fun x hx ↦ ?_] at h Β· rw [← integral_subtype_comap] at h Β· simp_rw [Subtype.val_injective.extend_apply] at h; exact h Β· exact meas_U rw [Function.extend_apply' _ _ _ (mt _ hx)] Β· apply zero_smul Β· rintro ⟨x, rfl⟩; exact x.2 variable [SigmaCompactSpace M] theorem IsOpen.ae_eq_zero_of_integral_smooth_smul_eq_zero {U : Set M} (hU : IsOpen U) (hf : LocallyIntegrableOn f U ΞΌ) (h : βˆ€ g : M β†’ ℝ, ContMDiff I π“˜(ℝ) ∞ g β†’ HasCompactSupport g β†’ tsupport g βŠ† U β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = 0) : βˆ€α΅ x βˆ‚ΞΌ, x ∈ U β†’ f x = 0 := haveI := I.locallyCompactSpace haveI := ChartedSpace.locallyCompactSpace H M haveI := hU.locallyCompactSpace haveI := I.secondCountableTopology haveI := ChartedSpace.secondCountable_of_sigmaCompact H M hU.ae_eq_zero_of_integral_smooth_smul_eq_zero' _ (isSigmaCompact_iff_sigmaCompactSpace.mpr inferInstance) hf h /-- If two locally integrable functions on a finite-dimensional real manifold have the same integral when multiplied by any smooth compactly supported function, then they coincide almost everywhere. -/ theorem ae_eq_of_integral_smooth_smul_eq (hf : LocallyIntegrable f ΞΌ) (hf' : LocallyIntegrable f' ΞΌ) (h : βˆ€ (g : M β†’ ℝ), ContMDiff I π“˜(ℝ) ∞ g β†’ HasCompactSupport g β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = ∫ x, g x β€’ f' x βˆ‚ΞΌ) : βˆ€α΅ x βˆ‚ΞΌ, f x = f' x := by have : βˆ€α΅ x βˆ‚ΞΌ, (f - f') x = 0 := by apply ae_eq_zero_of_integral_smooth_smul_eq_zero I (hf.sub hf') intro g g_diff g_supp simp only [Pi.sub_apply, smul_sub] rw [integral_sub, sub_eq_zero] Β· exact h g g_diff g_supp Β· exact hf.integrable_smul_left_of_hasCompactSupport g_diff.continuous g_supp Β· exact hf'.integrable_smul_left_of_hasCompactSupport g_diff.continuous g_supp filter_upwards [this] with x hx simpa [sub_eq_zero] using hx end Manifold section VectorSpace variable [MeasurableSpace E] [BorelSpace E] {f f' : E β†’ F} {ΞΌ : Measure E} /-- If a locally integrable function `f` on a finite-dimensional real vector space has zero integral when multiplied by any smooth compactly supported function, then `f` vanishes almost everywhere. -/ theorem ae_eq_zero_of_integral_contDiff_smul_eq_zero (hf : LocallyIntegrable f ΞΌ) (h : βˆ€ (g : E β†’ ℝ), ContDiff ℝ ∞ g β†’ HasCompactSupport g β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = 0) : βˆ€α΅ x βˆ‚ΞΌ, f x = 0 := ae_eq_zero_of_integral_smooth_smul_eq_zero π“˜(ℝ, E) hf (fun g g_diff g_supp ↦ h g g_diff.contDiff g_supp) /-- If two locally integrable functions on a finite-dimensional real vector space have the same integral when multiplied by any smooth compactly supported function, then they coincide almost everywhere. -/ theorem ae_eq_of_integral_contDiff_smul_eq (hf : LocallyIntegrable f ΞΌ) (hf' : LocallyIntegrable f' ΞΌ) (h : βˆ€ (g : E β†’ ℝ), ContDiff ℝ ∞ g β†’ HasCompactSupport g β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = ∫ x, g x β€’ f' x βˆ‚ΞΌ) : βˆ€α΅ x βˆ‚ΞΌ, f x = f' x := ae_eq_of_integral_smooth_smul_eq π“˜(ℝ, E) hf hf' (fun g g_diff g_supp ↦ h g g_diff.contDiff g_supp) /-- If a function `f` locally integrable on an open subset `U` of a finite-dimensional real vector space has zero integral when multiplied by any smooth function compactly supported in `U`, then `f` vanishes almost everywhere in `U`. -/ theorem IsOpen.ae_eq_zero_of_integral_contDiff_smul_eq_zero {U : Set E} (hU : IsOpen U) (hf : LocallyIntegrableOn f U ΞΌ) (h : βˆ€ (g : E β†’ ℝ), ContDiff ℝ ∞ g β†’ HasCompactSupport g β†’ tsupport g βŠ† U β†’ ∫ x, g x β€’ f x βˆ‚ΞΌ = 0) : βˆ€α΅ x βˆ‚ΞΌ, x ∈ U β†’ f x = 0 := hU.ae_eq_zero_of_integral_smooth_smul_eq_zero π“˜(ℝ, E) hf (fun g g_diff g_supp ↦ h g g_diff.contDiff g_supp) end VectorSpace
.lake/packages/mathlib/Mathlib/Analysis/Distribution/SchwartzSpace.lean
import Mathlib.Analysis.Calculus.IteratedDeriv.Defs import Mathlib.Analysis.Calculus.LineDeriv.Basic import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Analysis.Normed.Group.ZeroAtInfty import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.Distribution.TemperateGrowth import Mathlib.Topology.Algebra.UniformFilterBasis import Mathlib.MeasureTheory.Integral.IntegralEqImproper import Mathlib.Tactic.MoveAdd import Mathlib.MeasureTheory.Function.L2Space /-! # Schwartz space This file defines the Schwartz space. Usually, the Schwartz space is defined as the set of smooth functions $f : ℝ^n β†’ β„‚$ such that there exists $C_{Ξ±Ξ²} > 0$ with $$|x^Ξ± βˆ‚^Ξ² f(x)| < C_{Ξ±Ξ²}$$ for all $x ∈ ℝ^n$ and for all multiindices $Ξ±, Ξ²$. In mathlib, we use a slightly different approach and define the Schwartz space as all smooth functions `f : E β†’ F`, where `E` and `F` are real normed vector spaces such that for all natural numbers `k` and `n` we have uniform bounds `β€–xβ€–^k * β€–iteratedFDeriv ℝ n f xβ€– < C`. This approach completely avoids using partial derivatives as well as polynomials. We construct the topology on the Schwartz space by a family of seminorms, which are the best constants in the above estimates. The abstract theory of topological vector spaces developed in `SeminormFamily.moduleFilterBasis` and `WithSeminorms.toLocallyConvexSpace` turns the Schwartz space into a locally convex topological vector space. ## Main definitions * `SchwartzMap`: The Schwartz space is the space of smooth functions such that all derivatives decay faster than any power of `β€–xβ€–`. * `SchwartzMap.seminorm`: The family of seminorms as described above * `SchwartzMap.compCLM`: Composition with a function on the right as a continuous linear map `𝓒(E, F) β†’L[π•œ] 𝓒(D, F)`, provided that the function is temperate and grows polynomially near infinity * `SchwartzMap.fderivCLM`: The differential as a continuous linear map `𝓒(E, F) β†’L[π•œ] 𝓒(E, E β†’L[ℝ] F)` * `SchwartzMap.derivCLM`: The one-dimensional derivative as a continuous linear map `𝓒(ℝ, F) β†’L[π•œ] 𝓒(ℝ, F)` * `SchwartzMap.integralCLM`: Integration as a continuous linear map `𝓒(ℝ, F) β†’L[ℝ] F` ## Main statements * `SchwartzMap.instIsUniformAddGroup` and `SchwartzMap.instLocallyConvexSpace`: The Schwartz space is a locally convex topological vector space. * `SchwartzMap.one_add_le_sup_seminorm_apply`: For a Schwartz function `f` there is a uniform bound on `(1 + β€–xβ€–) ^ k * β€–iteratedFDeriv ℝ n f xβ€–`. ## Implementation details The implementation of the seminorms is taken almost literally from `ContinuousLinearMap.opNorm`. ## Notation * `𝓒(E, F)`: The Schwartz space `SchwartzMap E F` localized in `SchwartzSpace` ## Tags Schwartz space, tempered distributions -/ noncomputable section open scoped Nat NNReal ContDiff variable {π•œ π•œ' D E F G H V : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] variable [NormedAddCommGroup F] [NormedSpace ℝ F] variable (E F) in /-- A function is a Schwartz function if it is smooth and all derivatives decay faster than any power of `β€–xβ€–`. -/ structure SchwartzMap where /-- The underlying function. Do NOT use directly. Use the coercion instead. -/ toFun : E β†’ F smooth' : ContDiff ℝ ∞ toFun decay' : βˆ€ k n : β„•, βˆƒ C : ℝ, βˆ€ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n toFun xβ€– ≀ C /-- A function is a Schwartz function if it is smooth and all derivatives decay faster than any power of `β€–xβ€–`. -/ scoped[SchwartzMap] notation "𝓒(" E ", " F ")" => SchwartzMap E F namespace SchwartzMap instance instFunLike : FunLike 𝓒(E, F) E F where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr /-- All derivatives of a Schwartz function are rapidly decaying. -/ theorem decay (f : 𝓒(E, F)) (k n : β„•) : βˆƒ C : ℝ, 0 < C ∧ βˆ€ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ C := by rcases f.decay' k n with ⟨C, hC⟩ exact ⟨max C 1, by positivity, fun x => (hC x).trans (le_max_left _ _)⟩ /-- Every Schwartz function is smooth. -/ theorem smooth (f : 𝓒(E, F)) (n : β„•βˆž) : ContDiff ℝ n f := f.smooth'.of_le (mod_cast le_top) /-- Every Schwartz function is continuous. -/ @[continuity] protected theorem continuous (f : 𝓒(E, F)) : Continuous f := (f.smooth 0).continuous instance instContinuousMapClass : ContinuousMapClass 𝓒(E, F) E F where map_continuous := SchwartzMap.continuous /-- Every Schwartz function is differentiable. -/ protected theorem differentiable (f : 𝓒(E, F)) : Differentiable ℝ f := (f.smooth 1).differentiable rfl.le /-- Every Schwartz function is differentiable at any point. -/ protected theorem differentiableAt (f : 𝓒(E, F)) {x : E} : DifferentiableAt ℝ f x := f.differentiable.differentiableAt @[ext] theorem ext {f g : 𝓒(E, F)} (h : βˆ€ x, (f : E β†’ F) x = g x) : f = g := DFunLike.ext f g h section IsBigO open Asymptotics Filter variable (f : 𝓒(E, F)) /-- Auxiliary lemma, used in proving the more general result `isBigO_cocompact_rpow`. -/ theorem isBigO_cocompact_zpow_neg_nat (k : β„•) : f =O[cocompact E] fun x => β€–xβ€– ^ (-k : β„€) := by obtain ⟨d, _, hd'⟩ := f.decay k 0 simp only [norm_iteratedFDeriv_zero] at hd' simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith] refine ⟨d, Filter.Eventually.filter_mono Filter.cocompact_le_cofinite ?_⟩ refine (Filter.eventually_cofinite_ne 0).mono fun x hx => ?_ rw [Real.norm_of_nonneg (zpow_nonneg (norm_nonneg _) _), zpow_neg, ← div_eq_mul_inv, le_div_iffβ‚€'] exacts [hd' x, zpow_pos (norm_pos_iff.mpr hx) _] theorem isBigO_cocompact_rpow [ProperSpace E] (s : ℝ) : f =O[cocompact E] fun x => β€–xβ€– ^ s := by let k := ⌈-sβŒ‰β‚Š have hk : -(k : ℝ) ≀ s := neg_le.mp (Nat.le_ceil (-s)) refine (isBigO_cocompact_zpow_neg_nat f k).trans ?_ suffices (fun x : ℝ => x ^ (-k : β„€)) =O[atTop] fun x : ℝ => x ^ s from this.comp_tendsto tendsto_norm_cocompact_atTop simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith] refine ⟨1, (Filter.eventually_ge_atTop 1).mono fun x hx => ?_⟩ rw [one_mul, Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans hx) _), Real.norm_of_nonneg (zpow_nonneg (zero_le_one.trans hx) _), ← Real.rpow_intCast, Int.cast_neg, Int.cast_natCast] exact Real.rpow_le_rpow_of_exponent_le hx hk theorem isBigO_cocompact_zpow [ProperSpace E] (k : β„€) : f =O[cocompact E] fun x => β€–xβ€– ^ k := by simpa only [Real.rpow_intCast] using isBigO_cocompact_rpow f k end IsBigO section Aux theorem bounds_nonempty (k n : β„•) (f : 𝓒(E, F)) : βˆƒ c : ℝ, c ∈ { c : ℝ | 0 ≀ c ∧ βˆ€ x : E, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ c } := let ⟨M, hMp, hMb⟩ := f.decay k n ⟨M, le_of_lt hMp, hMb⟩ theorem bounds_bddBelow (k n : β„•) (f : 𝓒(E, F)) : BddBelow { c | 0 ≀ c ∧ βˆ€ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ c } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ theorem decay_add_le_aux (k n : β„•) (f g : 𝓒(E, F)) (x : E) : β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n ((f : E β†’ F) + (g : E β†’ F)) xβ€– ≀ β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– + β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n g xβ€– := by rw [← mul_add] gcongr _ * ?_ rw [iteratedFDeriv_add_apply (f.smooth _).contDiffAt (g.smooth _).contDiffAt] exact norm_add_le _ _ theorem decay_neg_aux (k n : β„•) (f : 𝓒(E, F)) (x : E) : β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n (-f : E β†’ F) xβ€– = β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– := by rw [iteratedFDeriv_neg_apply, norm_neg] variable [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] theorem decay_smul_aux (k n : β„•) (f : 𝓒(E, F)) (c : π•œ) (x : E) : β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n (c β€’ (f : E β†’ F)) xβ€– = β€–cβ€– * β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– := by rw [mul_comm β€–cβ€–, mul_assoc, iteratedFDeriv_const_smul_apply (f.smooth _).contDiffAt, norm_smul c (iteratedFDeriv ℝ n (⇑f) x)] end Aux section SeminormAux /-- Helper definition for the seminorms of the Schwartz space. -/ protected def seminormAux (k n : β„•) (f : 𝓒(E, F)) : ℝ := sInf { c | 0 ≀ c ∧ βˆ€ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ c } theorem seminormAux_nonneg (k n : β„•) (f : 𝓒(E, F)) : 0 ≀ f.seminormAux k n := le_csInf (bounds_nonempty k n f) fun _ ⟨hx, _⟩ => hx theorem le_seminormAux (k n : β„•) (f : 𝓒(E, F)) (x : E) : β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n (⇑f) xβ€– ≀ f.seminormAux k n := le_csInf (bounds_nonempty k n f) fun _ ⟨_, h⟩ => h x /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ theorem seminormAux_le_bound (k n : β„•) (f : 𝓒(E, F)) {M : ℝ} (hMp : 0 ≀ M) (hM : βˆ€ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ M) : f.seminormAux k n ≀ M := csInf_le (bounds_bddBelow k n f) ⟨hMp, hM⟩ end SeminormAux /-! ### Algebraic properties -/ section SMul variable [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] [NormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass ℝ π•œ' F] instance instSMul : SMul π•œ 𝓒(E, F) := ⟨fun c f => { toFun := c β€’ (f : E β†’ F) smooth' := (f.smooth _).const_smul c decay' k n := .intro (f.seminormAux k n * β€–cβ€–) fun x ↦ calc β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n (c β€’ ⇑f) xβ€– = β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– * β€–cβ€– := by rw [mul_comm _ β€–cβ€–, ← mul_assoc] exact decay_smul_aux k n f c x _ ≀ SchwartzMap.seminormAux k n f * β€–cβ€– := by gcongr apply f.le_seminormAux }⟩ @[simp] theorem smul_apply {f : 𝓒(E, F)} {c : π•œ} {x : E} : (c β€’ f) x = c β€’ f x := rfl instance instIsScalarTower [SMul π•œ π•œ'] [IsScalarTower π•œ π•œ' F] : IsScalarTower π•œ π•œ' 𝓒(E, F) := ⟨fun a b f => ext fun x => smul_assoc a b (f x)⟩ instance instSMulCommClass [SMulCommClass π•œ π•œ' F] : SMulCommClass π•œ π•œ' 𝓒(E, F) := ⟨fun a b f => ext fun x => smul_comm a b (f x)⟩ theorem seminormAux_smul_le (k n : β„•) (c : π•œ) (f : 𝓒(E, F)) : (c β€’ f).seminormAux k n ≀ β€–cβ€– * f.seminormAux k n := by refine (c β€’ f).seminormAux_le_bound k n (mul_nonneg (norm_nonneg _) (seminormAux_nonneg _ _ _)) fun x => (decay_smul_aux k n f c x).trans_le ?_ rw [mul_assoc] exact mul_le_mul_of_nonneg_left (f.le_seminormAux k n x) (norm_nonneg _) instance instNSMul : SMul β„• 𝓒(E, F) := ⟨fun c f => { toFun := c β€’ (f : E β†’ F) smooth' := (f.smooth _).const_smul c decay' := by simpa [← Nat.cast_smul_eq_nsmul ℝ] using ((c : ℝ) β€’ f).decay' }⟩ instance instZSMul : SMul β„€ 𝓒(E, F) := ⟨fun c f => { toFun := c β€’ (f : E β†’ F) smooth' := (f.smooth _).const_smul c decay' := by simpa [← Int.cast_smul_eq_zsmul ℝ] using ((c : ℝ) β€’ f).decay' }⟩ end SMul section Zero instance instZero : Zero 𝓒(E, F) := ⟨{ toFun := fun _ => 0 smooth' := contDiff_const decay' := fun _ _ => ⟨1, fun _ => by simp⟩ }⟩ instance instInhabited : Inhabited 𝓒(E, F) := ⟨0⟩ theorem coe_zero : DFunLike.coe (0 : 𝓒(E, F)) = (0 : E β†’ F) := rfl @[simp] theorem coeFn_zero : ⇑(0 : 𝓒(E, F)) = (0 : E β†’ F) := rfl @[simp] theorem zero_apply {x : E} : (0 : 𝓒(E, F)) x = 0 := rfl theorem seminormAux_zero (k n : β„•) : (0 : 𝓒(E, F)).seminormAux k n = 0 := le_antisymm (seminormAux_le_bound k n _ rfl.le fun _ => by simp [Pi.zero_def]) (seminormAux_nonneg _ _ _) end Zero section Neg instance instNeg : Neg 𝓒(E, F) := ⟨fun f => ⟨-f, (f.smooth _).neg, fun k n => ⟨f.seminormAux k n, fun x => (decay_neg_aux k n f x).le.trans (f.le_seminormAux k n x)⟩⟩⟩ @[simp] theorem neg_apply (f : 𝓒(E, F)) (x : E) : (-f) x = - (f x) := rfl end Neg section Add instance instAdd : Add 𝓒(E, F) := ⟨fun f g => ⟨f + g, (f.smooth _).add (g.smooth _), fun k n => ⟨f.seminormAux k n + g.seminormAux k n, fun x => (decay_add_le_aux k n f g x).trans (add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x))⟩⟩⟩ @[simp] theorem add_apply {f g : 𝓒(E, F)} {x : E} : (f + g) x = f x + g x := rfl theorem seminormAux_add_le (k n : β„•) (f g : 𝓒(E, F)) : (f + g).seminormAux k n ≀ f.seminormAux k n + g.seminormAux k n := (f + g).seminormAux_le_bound k n (add_nonneg (seminormAux_nonneg _ _ _) (seminormAux_nonneg _ _ _)) fun x => (decay_add_le_aux k n f g x).trans <| add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x) end Add section Sub instance instSub : Sub 𝓒(E, F) := ⟨fun f g => ⟨f - g, (f.smooth _).sub (g.smooth _), by intro k n refine ⟨f.seminormAux k n + g.seminormAux k n, fun x => ?_⟩ grw [← f.le_seminormAux k n x, ← g.le_seminormAux k n x] rw [sub_eq_add_neg] rw [← decay_neg_aux k n g x] exact decay_add_le_aux k n f (-g) x⟩⟩ @[simp] theorem sub_apply {f g : 𝓒(E, F)} {x : E} : (f - g) x = f x - g x := rfl end Sub section AddCommGroup instance instAddCommGroup : AddCommGroup 𝓒(E, F) := DFunLike.coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl variable (E F) /-- Coercion as an additive homomorphism. -/ def coeHom : 𝓒(E, F) β†’+ E β†’ F where toFun f := f map_zero' := coe_zero map_add' _ _ := rfl variable {E F} theorem coe_coeHom : (coeHom E F : 𝓒(E, F) β†’ E β†’ F) = DFunLike.coe := rfl theorem coeHom_injective : Function.Injective (coeHom E F) := by rw [coe_coeHom] exact DFunLike.coe_injective end AddCommGroup section Module variable [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] instance instModule : Module π•œ 𝓒(E, F) := coeHom_injective.module π•œ (coeHom E F) fun _ _ => rfl end Module section Seminorms /-! ### Seminorms on Schwartz space -/ variable [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] variable (π•œ) /-- The seminorms of the Schwartz space given by the best constants in the definition of `𝓒(E, F)`. -/ protected def seminorm (k n : β„•) : Seminorm π•œ 𝓒(E, F) := Seminorm.ofSMulLE (SchwartzMap.seminormAux k n) (seminormAux_zero k n) (seminormAux_add_le k n) (seminormAux_smul_le k n) /-- If one controls the seminorm for every `x`, then one controls the seminorm. -/ theorem seminorm_le_bound (k n : β„•) (f : 𝓒(E, F)) {M : ℝ} (hMp : 0 ≀ M) (hM : βˆ€ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ M) : SchwartzMap.seminorm π•œ k n f ≀ M := f.seminormAux_le_bound k n hMp hM /-- If one controls the seminorm for every `x`, then one controls the seminorm. Variant for functions `𝓒(ℝ, F)`. -/ theorem seminorm_le_bound' (k n : β„•) (f : 𝓒(ℝ, F)) {M : ℝ} (hMp : 0 ≀ M) (hM : βˆ€ x, |x| ^ k * β€–iteratedDeriv n f xβ€– ≀ M) : SchwartzMap.seminorm π•œ k n f ≀ M := by refine seminorm_le_bound π•œ k n f hMp ?_ simpa only [Real.norm_eq_abs, norm_iteratedFDeriv_eq_norm_iteratedDeriv] /-- The seminorm controls the Schwartz estimate for any fixed `x`. -/ theorem le_seminorm (k n : β„•) (f : 𝓒(E, F)) (x : E) : β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ SchwartzMap.seminorm π•œ k n f := f.le_seminormAux k n x /-- The seminorm controls the Schwartz estimate for any fixed `x`. Variant for functions `𝓒(ℝ, F)`. -/ theorem le_seminorm' (k n : β„•) (f : 𝓒(ℝ, F)) (x : ℝ) : |x| ^ k * β€–iteratedDeriv n f xβ€– ≀ SchwartzMap.seminorm π•œ k n f := by have := le_seminorm π•œ k n f x rwa [← Real.norm_eq_abs, ← norm_iteratedFDeriv_eq_norm_iteratedDeriv] theorem norm_iteratedFDeriv_le_seminorm (f : 𝓒(E, F)) (n : β„•) (xβ‚€ : E) : β€–iteratedFDeriv ℝ n f xβ‚€β€– ≀ (SchwartzMap.seminorm π•œ 0 n) f := by have := SchwartzMap.le_seminorm π•œ 0 n f xβ‚€ rwa [pow_zero, one_mul] at this theorem norm_pow_mul_le_seminorm (f : 𝓒(E, F)) (k : β„•) (xβ‚€ : E) : β€–xβ‚€β€– ^ k * β€–f xβ‚€β€– ≀ (SchwartzMap.seminorm π•œ k 0) f := by have := SchwartzMap.le_seminorm π•œ k 0 f xβ‚€ rwa [norm_iteratedFDeriv_zero] at this theorem norm_le_seminorm (f : 𝓒(E, F)) (xβ‚€ : E) : β€–f xβ‚€β€– ≀ (SchwartzMap.seminorm π•œ 0 0) f := by have := norm_pow_mul_le_seminorm π•œ f 0 xβ‚€ rwa [pow_zero, one_mul] at this variable (E F) /-- The family of Schwartz seminorms. -/ def _root_.schwartzSeminormFamily : SeminormFamily π•œ 𝓒(E, F) (β„• Γ— β„•) := fun m => SchwartzMap.seminorm π•œ m.1 m.2 @[simp] theorem schwartzSeminormFamily_apply (n k : β„•) : schwartzSeminormFamily π•œ E F (n, k) = SchwartzMap.seminorm π•œ n k := rfl @[simp] theorem schwartzSeminormFamily_apply_zero : schwartzSeminormFamily π•œ E F 0 = SchwartzMap.seminorm π•œ 0 0 := rfl variable {π•œ E F} /-- A more convenient version of `le_sup_seminorm_apply`. The set `Finset.Iic m` is the set of all pairs `(k', n')` with `k' ≀ m.1` and `n' ≀ m.2`. Note that the constant is far from optimal. -/ theorem one_add_le_sup_seminorm_apply {m : β„• Γ— β„•} {k n : β„•} (hk : k ≀ m.1) (hn : n ≀ m.2) (f : 𝓒(E, F)) (x : E) : (1 + β€–xβ€–) ^ k * β€–iteratedFDeriv ℝ n f xβ€– ≀ 2 ^ m.1 * (Finset.Iic m).sup (fun m => SchwartzMap.seminorm π•œ m.1 m.2) f := by rw [add_comm, add_pow] simp only [one_pow, mul_one, Finset.sum_mul] norm_cast rw [← Nat.sum_range_choose m.1] push_cast rw [Finset.sum_mul] have hk' : Finset.range (k + 1) βŠ† Finset.range (m.1 + 1) := by grind grw [hk'] gcongr βˆ‘ _i ∈ Finset.range (m.1 + 1), ?_ with i hi move_mul [(Nat.choose k i : ℝ), (Nat.choose m.1 i : ℝ)] gcongr Β· apply (le_seminorm π•œ i n f x).trans apply Seminorm.le_def.1 exact Finset.le_sup_of_le (Finset.mem_Iic.2 <| Prod.mk_le_mk.2 ⟨Finset.mem_range_succ_iff.mp hi, hn⟩) le_rfl Β· exact mod_cast Nat.choose_le_choose i hk end Seminorms section Topology /-! ### The topology on the Schwartz space -/ variable [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] variable (π•œ E F) instance instTopologicalSpace : TopologicalSpace 𝓒(E, F) := (schwartzSeminormFamily ℝ E F).moduleFilterBasis.topology' theorem _root_.schwartz_withSeminorms : WithSeminorms (schwartzSeminormFamily π•œ E F) := by have A : WithSeminorms (schwartzSeminormFamily ℝ E F) := ⟨rfl⟩ rw [SeminormFamily.withSeminorms_iff_nhds_eq_iInf] at A ⊒ rw [A] rfl variable {π•œ E F} instance instContinuousSMul : ContinuousSMul π•œ 𝓒(E, F) := by rw [(schwartz_withSeminorms π•œ E F).withSeminorms_eq] exact (schwartzSeminormFamily π•œ E F).moduleFilterBasis.continuousSMul instance instIsTopologicalAddGroup : IsTopologicalAddGroup 𝓒(E, F) := (schwartzSeminormFamily ℝ E F).addGroupFilterBasis.isTopologicalAddGroup instance instUniformSpace : UniformSpace 𝓒(E, F) := (schwartzSeminormFamily ℝ E F).addGroupFilterBasis.uniformSpace instance instIsUniformAddGroup : IsUniformAddGroup 𝓒(E, F) := (schwartzSeminormFamily ℝ E F).addGroupFilterBasis.isUniformAddGroup instance instLocallyConvexSpace : LocallyConvexSpace ℝ 𝓒(E, F) := (schwartz_withSeminorms ℝ E F).toLocallyConvexSpace instance instFirstCountableTopology : FirstCountableTopology 𝓒(E, F) := (schwartz_withSeminorms ℝ E F).firstCountableTopology end Topology theorem hasTemperateGrowth (f : 𝓒(E, F)) : Function.HasTemperateGrowth f := by refine ⟨smooth f ⊀, fun n => ?_⟩ rcases f.decay 0 n with ⟨C, Cpos, hC⟩ exact ⟨0, C, by simpa using hC⟩ section HasCompactSupport /-- A smooth compactly supported function is a Schwartz function. -/ @[simps] def _root_.HasCompactSupport.toSchwartzMap {f : E β†’ F} (h₁ : HasCompactSupport f) (hβ‚‚ : ContDiff ℝ ∞ f) : 𝓒(E, F) where toFun := f smooth' := hβ‚‚ decay' k n := by set g := fun x ↦ β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– have hg₁ : Continuous g := by apply Continuous.mul (by fun_prop) exact (hβ‚‚.of_le (mod_cast le_top)).continuous_iteratedFDeriv'.norm have hgβ‚‚ : HasCompactSupport g := (h₁.iteratedFDeriv _).norm.mul_left obtain ⟨xβ‚€, hxβ‚€βŸ© := hg₁.exists_forall_ge_of_hasCompactSupport hgβ‚‚ exact ⟨g xβ‚€, hxβ‚€βŸ© end HasCompactSupport section CLM /-! ### Construction of continuous linear maps between Schwartz spaces -/ variable [NormedField π•œ] [NormedField π•œ'] variable [NormedAddCommGroup D] [NormedSpace ℝ D] variable [NormedSpace π•œ E] [SMulCommClass ℝ π•œ E] variable [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedSpace π•œ' G] [SMulCommClass ℝ π•œ' G] variable {Οƒ : π•œ β†’+* π•œ'} /-- Create a semilinear map between Schwartz spaces. Note: This is a helper definition for `mkCLM`. -/ def mkLM (A : 𝓒(D, E) β†’ F β†’ G) (hadd : βˆ€ (f g : 𝓒(D, E)) (x), A (f + g) x = A f x + A g x) (hsmul : βˆ€ (a : π•œ) (f : 𝓒(D, E)) (x), A (a β€’ f) x = Οƒ a β€’ A f x) (hsmooth : βˆ€ f : 𝓒(D, E), ContDiff ℝ ∞ (A f)) (hbound : βˆ€ n : β„• Γ— β„•, βˆƒ (s : Finset (β„• Γ— β„•)) (C : ℝ), 0 ≀ C ∧ βˆ€ (f : 𝓒(D, E)) (x : F), β€–xβ€– ^ n.fst * β€–iteratedFDeriv ℝ n.snd (A f) xβ€– ≀ C * s.sup (schwartzSeminormFamily π•œ D E) f) : 𝓒(D, E) β†’β‚›β‚—[Οƒ] 𝓒(F, G) where toFun f := { toFun := A f smooth' := hsmooth f decay' := by intro k n rcases hbound ⟨k, n⟩ with ⟨s, C, _, h⟩ exact ⟨C * (s.sup (schwartzSeminormFamily π•œ D E)) f, h f⟩ } map_add' f g := ext (hadd f g) map_smul' a f := ext (hsmul a f) /-- Create a continuous semilinear map between Schwartz spaces. For an example of using this definition, see `fderivCLM`. -/ def mkCLM [RingHomIsometric Οƒ] (A : 𝓒(D, E) β†’ F β†’ G) (hadd : βˆ€ (f g : 𝓒(D, E)) (x), A (f + g) x = A f x + A g x) (hsmul : βˆ€ (a : π•œ) (f : 𝓒(D, E)) (x), A (a β€’ f) x = Οƒ a β€’ A f x) (hsmooth : βˆ€ f : 𝓒(D, E), ContDiff ℝ ∞ (A f)) (hbound : βˆ€ n : β„• Γ— β„•, βˆƒ (s : Finset (β„• Γ— β„•)) (C : ℝ), 0 ≀ C ∧ βˆ€ (f : 𝓒(D, E)) (x : F), β€–xβ€– ^ n.fst * β€–iteratedFDeriv ℝ n.snd (A f) xβ€– ≀ C * s.sup (schwartzSeminormFamily π•œ D E) f) : 𝓒(D, E) β†’SL[Οƒ] 𝓒(F, G) where cont := by change Continuous (mkLM A hadd hsmul hsmooth hbound : 𝓒(D, E) β†’β‚›β‚—[Οƒ] 𝓒(F, G)) refine Seminorm.continuous_from_bounded (schwartz_withSeminorms π•œ D E) (schwartz_withSeminorms π•œ' F G) _ fun n => ?_ rcases hbound n with ⟨s, C, hC, h⟩ refine ⟨s, ⟨C, hC⟩, fun f => ?_⟩ exact (mkLM A hadd hsmul hsmooth hbound f).seminorm_le_bound π•œ' n.1 n.2 (by positivity) (h f) toLinearMap := mkLM A hadd hsmul hsmooth hbound /-- Define a continuous semilinear map from Schwartz space to a normed space. -/ def mkCLMtoNormedSpace [RingHomIsometric Οƒ] (A : 𝓒(D, E) β†’ G) (hadd : βˆ€ (f g : 𝓒(D, E)), A (f + g) = A f + A g) (hsmul : βˆ€ (a : π•œ) (f : 𝓒(D, E)), A (a β€’ f) = Οƒ a β€’ A f) (hbound : βˆƒ (s : Finset (β„• Γ— β„•)) (C : ℝ), 0 ≀ C ∧ βˆ€ (f : 𝓒(D, E)), β€–A fβ€– ≀ C * s.sup (schwartzSeminormFamily π•œ D E) f) : 𝓒(D, E) β†’SL[Οƒ] G := letI f : 𝓒(D, E) β†’β‚›β‚—[Οƒ] G := { toFun := (A Β·) map_add' := hadd map_smul' := hsmul } { toLinearMap := f cont := by change Continuous (LinearMap.mk _ _) apply Seminorm.cont_withSeminorms_normedSpace G (schwartz_withSeminorms π•œ D E) rcases hbound with ⟨s, C, hC, h⟩ exact ⟨s, ⟨C, hC⟩, h⟩ } end CLM section EvalCLM variable [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] /-- The map applying a vector to Hom-valued Schwartz function as a continuous linear map. -/ protected def evalCLM (m : E) : 𝓒(E, E β†’L[ℝ] F) β†’L[π•œ] 𝓒(E, F) := mkCLM (fun f x => f x m) (fun _ _ _ => rfl) (fun _ _ _ => rfl) (fun f => ContDiff.clm_apply f.2 contDiff_const) <| by rintro ⟨k, n⟩ use {(k, n)}, β€–mβ€–, norm_nonneg _ intro f x simp only [Finset.sup_singleton, schwartzSeminormFamily_apply] calc β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n (f Β· m) xβ€– ≀ β€–xβ€– ^ k * (β€–mβ€– * β€–iteratedFDeriv ℝ n f xβ€–) := by gcongr exact norm_iteratedFDeriv_clm_apply_const (f.smooth _).contDiffAt le_rfl _ ≀ β€–mβ€– * SchwartzMap.seminorm π•œ k n f := by move_mul [β€–mβ€–] gcongr apply le_seminorm end EvalCLM section Multiplication variable [NontriviallyNormedField π•œ] [NormedAlgebra ℝ π•œ] [NormedAddCommGroup D] [NormedSpace ℝ D] [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedSpace π•œ E] [NormedSpace π•œ F] [NormedSpace π•œ G] /-- The map `f ↦ (x ↦ B (f x) (g x))` as a continuous `π•œ`-linear map on Schwartz space, where `B` is a continuous `π•œ`-linear map and `g` is a function of temperate growth. -/ def bilinLeftCLM (B : E β†’L[π•œ] F β†’L[π•œ] G) {g : D β†’ F} (hg : g.HasTemperateGrowth) : 𝓒(D, E) β†’L[π•œ] 𝓒(D, G) := by refine mkCLM (fun f x => B (f x) (g x)) (fun _ _ _ => by simp) (fun _ _ _ => by simp) (fun f => (B.bilinearRestrictScalars ℝ).isBoundedBilinearMap.contDiff.comp ((f.smooth ⊀).prodMk hg.1)) ?_ rintro ⟨k, n⟩ rcases hg.norm_iteratedFDeriv_le_uniform n with ⟨l, C, hC, hgrowth⟩ use Finset.Iic (l + k, n), β€–Bβ€– * ((n : ℝ) + (1 : ℝ)) * n.choose (n / 2) * (C * 2 ^ (l + k)), by positivity intro f x have hxk : 0 ≀ β€–xβ€– ^ k := by positivity simp_rw [← ContinuousLinearMap.bilinearRestrictScalars_apply_apply ℝ B] have hnorm_mul := ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear (B.bilinearRestrictScalars ℝ) (f.smooth ⊀) hg.1 x (n := n) (mod_cast le_top) grw [hnorm_mul] rw [ContinuousLinearMap.norm_bilinearRestrictScalars] move_mul [← β€–Bβ€–] simp_rw [mul_assoc β€–Bβ€–] gcongr _ * ?_ rw [Finset.mul_sum] have : (βˆ‘ _x ∈ Finset.range (n + 1), (1 : ℝ)) = n + 1 := by simp simp_rw [mul_assoc ((n : ℝ) + 1)] rw [← this, Finset.sum_mul] refine Finset.sum_le_sum fun i hi => ?_ simp only [one_mul] move_mul [(Nat.choose n i : ℝ), (Nat.choose n (n / 2) : ℝ)] gcongr ?_ * ?_ swap Β· norm_cast exact i.choose_le_middle n specialize hgrowth (n - i) (by simp only [tsub_le_self]) x grw [hgrowth] move_mul [C] gcongr ?_ * C rw [Finset.mem_range_succ_iff] at hi change i ≀ (l + k, n).snd at hi refine le_trans ?_ (one_add_le_sup_seminorm_apply le_rfl hi f x) rw [pow_add] move_mul [(1 + β€–xβ€–) ^ l] gcongr simp @[simp] theorem bilinLeftCLM_apply (B : E β†’L[π•œ] F β†’L[π•œ] G) {g : D β†’ F} (hg : g.HasTemperateGrowth) (f : 𝓒(D, E)) : bilinLeftCLM B hg f = fun x => B (f x) (g x) := rfl end Multiplication section Comp variable (π•œ) variable [RCLike π•œ] variable [NormedAddCommGroup D] [NormedSpace ℝ D] variable [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] /-- Composition with a function on the right is a continuous linear map on Schwartz space provided that the function is temperate and growths polynomially near infinity. -/ def compCLM {g : D β†’ E} (hg : g.HasTemperateGrowth) (hg_upper : βˆƒ (k : β„•) (C : ℝ), βˆ€ x, β€–xβ€– ≀ C * (1 + β€–g xβ€–) ^ k) : 𝓒(E, F) β†’L[π•œ] 𝓒(D, F) := by refine mkCLM (fun f => f ∘ g) (fun _ _ _ => by simp) (fun _ _ _ => rfl) (fun f => (f.smooth ⊀).comp hg.1) ?_ rintro ⟨k, n⟩ rcases hg.norm_iteratedFDeriv_le_uniform n with ⟨l, C, hC, hgrowth⟩ rcases hg_upper with ⟨kg, Cg, hg_upper'⟩ have hCg : 1 ≀ 1 + Cg := by refine le_add_of_nonneg_right ?_ specialize hg_upper' 0 rw [norm_zero] at hg_upper' exact nonneg_of_mul_nonneg_left hg_upper' (by positivity) let k' := kg * (k + l * n) use Finset.Iic (k', n), (1 + Cg) ^ (k + l * n) * ((C + 1) ^ n * n ! * 2 ^ k'), by positivity intro f x let seminorm_f := ((Finset.Iic (k', n)).sup (schwartzSeminormFamily π•œ _ _)) f have hg_upper'' : (1 + β€–xβ€–) ^ (k + l * n) ≀ (1 + Cg) ^ (k + l * n) * (1 + β€–g xβ€–) ^ k' := by rw [pow_mul, ← mul_pow] gcongr rw [add_mul] refine add_le_add ?_ (hg_upper' x) nth_rw 1 [← one_mul (1 : ℝ)] gcongr apply one_le_powβ‚€ simp only [le_add_iff_nonneg_right, norm_nonneg] have hbound (i) (hi : i ≀ n) : β€–iteratedFDeriv ℝ i f (g x)β€– ≀ 2 ^ k' * seminorm_f / (1 + β€–g xβ€–) ^ k' := by have hpos : 0 < (1 + β€–g xβ€–) ^ k' := by positivity rw [le_div_iffβ‚€' hpos] change i ≀ (k', n).snd at hi exact one_add_le_sup_seminorm_apply le_rfl hi _ _ have hgrowth' (N : β„•) (hN₁ : 1 ≀ N) (hNβ‚‚ : N ≀ n) : β€–iteratedFDeriv ℝ N g xβ€– ≀ ((C + 1) * (1 + β€–xβ€–) ^ l) ^ N := by refine (hgrowth N hNβ‚‚ x).trans ?_ rw [mul_pow] have hN₁' := (lt_of_lt_of_le zero_lt_one hN₁).ne' gcongr Β· exact le_trans (by simp) (le_self_powβ‚€ (by simp [hC]) hN₁') Β· refine le_self_powβ‚€ (one_le_powβ‚€ ?_) hN₁' simp only [le_add_iff_nonneg_right, norm_nonneg] have := norm_iteratedFDeriv_comp_le (f.smooth ⊀) hg.1 (mod_cast le_top) x hbound hgrowth' have hxk : β€–xβ€– ^ k ≀ (1 + β€–xβ€–) ^ k := pow_le_pow_leftβ‚€ (norm_nonneg _) (by simp only [zero_le_one, le_add_iff_nonneg_left]) _ grw [hxk, this] have rearrange : (1 + β€–xβ€–) ^ k * (n ! * (2 ^ k' * seminorm_f / (1 + β€–g xβ€–) ^ k') * ((C + 1) * (1 + β€–xβ€–) ^ l) ^ n) = (1 + β€–xβ€–) ^ (k + l * n) / (1 + β€–g xβ€–) ^ k' * ((C + 1) ^ n * n ! * 2 ^ k' * seminorm_f) := by rw [mul_pow, pow_add, ← pow_mul] ring rw [rearrange] have hgxk' : 0 < (1 + β€–g xβ€–) ^ k' := by positivity rw [← div_le_iffβ‚€ hgxk'] at hg_upper'' grw [hg_upper'', ← mul_assoc] @[simp] lemma compCLM_apply {g : D β†’ E} (hg : g.HasTemperateGrowth) (hg_upper : βˆƒ (k : β„•) (C : ℝ), βˆ€ x, β€–xβ€– ≀ C * (1 + β€–g xβ€–) ^ k) (f : 𝓒(E, F)) : compCLM π•œ hg hg_upper f = f ∘ g := rfl /-- Composition with a function on the right is a continuous linear map on Schwartz space provided that the function is temperate and antilipschitz. -/ def compCLMOfAntilipschitz {K : ℝβ‰₯0} {g : D β†’ E} (hg : g.HasTemperateGrowth) (h'g : AntilipschitzWith K g) : 𝓒(E, F) β†’L[π•œ] 𝓒(D, F) := by refine compCLM π•œ hg ⟨1, K * max 1 β€–g 0β€–, fun x ↦ ?_⟩ calc β€–xβ€– ≀ K * β€–g x - g 0β€– := by rw [← dist_zero_right, ← dist_eq_norm] apply h'g.le_mul_dist _ ≀ K * (β€–g xβ€– + β€–g 0β€–) := by gcongr exact norm_sub_le _ _ _ ≀ K * (β€–g xβ€– + max 1 β€–g 0β€–) := by gcongr exact le_max_right _ _ _ ≀ (K * max 1 β€–g 0β€– : ℝ) * (1 + β€–g xβ€–) ^ 1 := by simp only [mul_add, add_comm (K * β€–g xβ€–), pow_one, mul_one, add_le_add_iff_left] gcongr exact le_mul_of_one_le_right (by positivity) (le_max_left _ _) @[simp] lemma compCLMOfAntilipschitz_apply {K : ℝβ‰₯0} {g : D β†’ E} (hg : g.HasTemperateGrowth) (h'g : AntilipschitzWith K g) (f : 𝓒(E, F)) : compCLMOfAntilipschitz π•œ hg h'g f = f ∘ g := rfl /-- Composition with a continuous linear equiv on the right is a continuous linear map on Schwartz space. -/ def compCLMOfContinuousLinearEquiv (g : D ≃L[ℝ] E) : 𝓒(E, F) β†’L[π•œ] 𝓒(D, F) := compCLMOfAntilipschitz π•œ (g.toContinuousLinearMap.hasTemperateGrowth) g.antilipschitz @[simp] lemma compCLMOfContinuousLinearEquiv_apply (g : D ≃L[ℝ] E) (f : 𝓒(E, F)) : compCLMOfContinuousLinearEquiv π•œ g f = f ∘ g := rfl end Comp section Derivatives /-! ### Derivatives of Schwartz functions -/ variable (π•œ) variable [RCLike π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] /-- The FrΓ©chet derivative on Schwartz space as a continuous `π•œ`-linear map. -/ def fderivCLM : 𝓒(E, F) β†’L[π•œ] 𝓒(E, E β†’L[ℝ] F) := mkCLM (fderiv ℝ Β·) (fun f g _ => fderiv_add f.differentiableAt g.differentiableAt) (fun a f _ => fderiv_const_smul f.differentiableAt a) (fun f => (contDiff_succ_iff_fderiv.mp (f.smooth ⊀)).2.2) fun ⟨k, n⟩ => ⟨{⟨k, n + 1⟩}, 1, zero_le_one, fun f x => by simpa only [schwartzSeminormFamily_apply, Seminorm.comp_apply, Finset.sup_singleton, one_smul, norm_iteratedFDeriv_fderiv, one_mul] using f.le_seminorm π•œ k (n + 1) x⟩ @[simp] theorem fderivCLM_apply (f : 𝓒(E, F)) (x : E) : fderivCLM π•œ f x = fderiv ℝ f x := rfl theorem hasFDerivAt (f : 𝓒(E, F)) (x : E) : HasFDerivAt f (fderiv ℝ f x) x := f.differentiableAt.hasFDerivAt /-- The 1-dimensional derivative on Schwartz space as a continuous `π•œ`-linear map. -/ def derivCLM : 𝓒(ℝ, F) β†’L[π•œ] 𝓒(ℝ, F) := mkCLM (deriv Β·) (fun f g _ => deriv_add f.differentiableAt g.differentiableAt) (fun a f _ => deriv_const_smul a f.differentiableAt) (fun f => (contDiff_succ_iff_deriv.mp (f.smooth ⊀)).2.2) fun ⟨k, n⟩ => ⟨{⟨k, n + 1⟩}, 1, zero_le_one, fun f x => by simpa only [Real.norm_eq_abs, Finset.sup_singleton, schwartzSeminormFamily_apply, one_mul, norm_iteratedFDeriv_eq_norm_iteratedDeriv, ← iteratedDeriv_succ'] using f.le_seminorm' π•œ k (n + 1) x⟩ @[simp] theorem derivCLM_apply (f : 𝓒(ℝ, F)) (x : ℝ) : derivCLM π•œ f x = deriv f x := rfl theorem hasDerivAt (f : 𝓒(ℝ, F)) (x : ℝ) : HasDerivAt f (deriv f x) x := f.differentiableAt.hasDerivAt /-- The partial derivative (or directional derivative) in the direction `m : E` as a continuous linear map on Schwartz space. -/ def pderivCLM (m : E) : 𝓒(E, F) β†’L[π•œ] 𝓒(E, F) := (SchwartzMap.evalCLM m).comp (fderivCLM π•œ) @[simp] theorem pderivCLM_apply (m : E) (f : 𝓒(E, F)) (x : E) : pderivCLM π•œ m f x = fderiv ℝ f x m := rfl theorem pderivCLM_eq_lineDeriv (m : E) (f : 𝓒(E, F)) (x : E) : pderivCLM π•œ m f x = lineDeriv ℝ f x m := by simp only [pderivCLM_apply, f.differentiableAt.lineDeriv_eq_fderiv] /-- The iterated partial derivative (or directional derivative) as a continuous linear map on Schwartz space. -/ def iteratedPDeriv {n : β„•} : (Fin n β†’ E) β†’ 𝓒(E, F) β†’L[π•œ] 𝓒(E, F) := Nat.recOn n (fun _ => ContinuousLinearMap.id π•œ _) fun _ rec x => (pderivCLM π•œ (x 0)).comp (rec (Fin.tail x)) @[simp] theorem iteratedPDeriv_zero (m : Fin 0 β†’ E) (f : 𝓒(E, F)) : iteratedPDeriv π•œ m f = f := rfl @[simp] theorem iteratedPDeriv_one (m : Fin 1 β†’ E) (f : 𝓒(E, F)) : iteratedPDeriv π•œ m f = pderivCLM π•œ (m 0) f := rfl theorem iteratedPDeriv_succ_left {n : β„•} (m : Fin (n + 1) β†’ E) (f : 𝓒(E, F)) : iteratedPDeriv π•œ m f = pderivCLM π•œ (m 0) (iteratedPDeriv π•œ (Fin.tail m) f) := rfl theorem iteratedPDeriv_succ_right {n : β„•} (m : Fin (n + 1) β†’ E) (f : 𝓒(E, F)) : iteratedPDeriv π•œ m f = iteratedPDeriv π•œ (Fin.init m) (pderivCLM π•œ (m (Fin.last n)) f) := by induction n with | zero => rw [iteratedPDeriv_zero, iteratedPDeriv_one, Fin.last_zero] -- The proof is `βˆ‚^{n + 2} = βˆ‚ βˆ‚^{n + 1} = βˆ‚ βˆ‚^n βˆ‚ = βˆ‚^{n+1} βˆ‚` | succ n IH => have hmzero : Fin.init m 0 = m 0 := by simp only [Fin.init_def, Fin.castSucc_zero] have hmtail : Fin.tail m (Fin.last n) = m (Fin.last n.succ) := by simp only [Fin.tail_def, Fin.succ_last] calc _ = pderivCLM π•œ (m 0) (iteratedPDeriv π•œ _ f) := iteratedPDeriv_succ_left _ _ _ _ = pderivCLM π•œ (m 0) ((iteratedPDeriv π•œ _) ((pderivCLM π•œ _) f)) := by congr 1 exact IH _ _ = _ := by simp only [hmtail, iteratedPDeriv_succ_left, hmzero, Fin.tail_init_eq_init_tail] theorem iteratedPDeriv_eq_iteratedFDeriv {n : β„•} {m : Fin n β†’ E} {f : 𝓒(E, F)} {x : E} : iteratedPDeriv π•œ m f x = iteratedFDeriv ℝ n f x m := by induction n generalizing x with | zero => simp | succ n ih => simp only [iteratedPDeriv_succ_left, iteratedFDeriv_succ_apply_left] rw [← fderiv_continuousMultilinear_apply_const_apply] Β· simp [← ih] Β· exact (f.smooth ⊀).differentiable_iteratedFDeriv (mod_cast ENat.coe_lt_top n) x end Derivatives section Integration /-! ### Integration -/ open Real Complex Filter MeasureTheory MeasureTheory.Measure Module variable [RCLike π•œ] variable [NormedAddCommGroup D] [NormedSpace ℝ D] variable [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedSpace π•œ V] variable [MeasurableSpace D] variable {ΞΌ : Measure D} [hΞΌ : HasTemperateGrowth ΞΌ] attribute [local instance 101] secondCountableTopologyEither_of_left variable (π•œ ΞΌ) in lemma integral_pow_mul_iteratedFDeriv_le (f : 𝓒(D, V)) (k n : β„•) : ∫ x, β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€– βˆ‚ΞΌ ≀ 2 ^ ΞΌ.integrablePower * (∫ x, (1 + β€–xβ€–) ^ (- (ΞΌ.integrablePower : ℝ)) βˆ‚ΞΌ) * (SchwartzMap.seminorm π•œ 0 n f + SchwartzMap.seminorm π•œ (k + ΞΌ.integrablePower) n f) := integral_pow_mul_le_of_le_of_pow_mul_le (norm_iteratedFDeriv_le_seminorm ℝ _ _) (le_seminorm ℝ _ _ _) variable [BorelSpace D] [SecondCountableTopology D] variable (ΞΌ) in lemma integrable_pow_mul_iteratedFDeriv (f : 𝓒(D, V)) (k n : β„•) : Integrable (fun x ↦ β€–xβ€– ^ k * β€–iteratedFDeriv ℝ n f xβ€–) ΞΌ := integrable_of_le_of_pow_mul_le (norm_iteratedFDeriv_le_seminorm ℝ _ _) (le_seminorm ℝ _ _ _) ((f.smooth ⊀).continuous_iteratedFDeriv (mod_cast le_top)).aestronglyMeasurable variable (ΞΌ) in lemma integrable_pow_mul (f : 𝓒(D, V)) (k : β„•) : Integrable (fun x ↦ β€–xβ€– ^ k * β€–f xβ€–) ΞΌ := by convert integrable_pow_mul_iteratedFDeriv ΞΌ f k 0 with x simp lemma integrable (f : 𝓒(D, V)) : Integrable f ΞΌ := (f.integrable_pow_mul ΞΌ 0).mono f.continuous.aestronglyMeasurable (Eventually.of_forall (fun _ ↦ by simp)) variable (π•œ ΞΌ) in /-- The integral as a continuous linear map from Schwartz space to the codomain. -/ def integralCLM : 𝓒(D, V) β†’L[π•œ] V := by refine mkCLMtoNormedSpace (∫ x, Β· x βˆ‚ΞΌ) (fun f g ↦ integral_add f.integrable g.integrable) (integral_smul Β· Β·) ?_ rcases hΞΌ.exists_integrable with ⟨n, h⟩ let m := (n, 0) use Finset.Iic m, 2 ^ n * ∫ x : D, (1 + β€–xβ€–) ^ (- (n : ℝ)) βˆ‚ΞΌ refine ⟨by positivity, fun f ↦ (norm_integral_le_integral_norm f).trans ?_⟩ have h' : βˆ€ x, β€–f xβ€– ≀ (1 + β€–xβ€–) ^ (-(n : ℝ)) * (2 ^ n * ((Finset.Iic m).sup (fun m' => SchwartzMap.seminorm π•œ m'.1 m'.2) f)) := by intro x rw [rpow_neg (by positivity), ← div_eq_inv_mul, le_div_iffβ‚€' (by positivity), rpow_natCast] simpa using one_add_le_sup_seminorm_apply (m := m) (k := n) (n := 0) le_rfl le_rfl f x apply (integral_mono (by simpa using f.integrable_pow_mul ΞΌ 0) _ h').trans Β· unfold schwartzSeminormFamily rw [integral_mul_const, ← mul_assoc, mul_comm (2 ^ n)] apply h.mul_const variable (π•œ) in @[simp] lemma integralCLM_apply (f : 𝓒(D, V)) : integralCLM π•œ ΞΌ f = ∫ x, f x βˆ‚ΞΌ := by rfl end Integration section BoundedContinuousFunction /-! ### Inclusion into the space of bounded continuous functions -/ open scoped BoundedContinuousFunction instance instBoundedContinuousMapClass : BoundedContinuousMapClass 𝓒(E, F) E F where __ := instContinuousMapClass map_bounded := fun f ↦ ⟨2 * (SchwartzMap.seminorm ℝ 0 0) f, (BoundedContinuousFunction.dist_le_two_norm' (norm_le_seminorm ℝ f))⟩ /-- Schwartz functions as bounded continuous functions -/ def toBoundedContinuousFunction (f : 𝓒(E, F)) : E →ᡇ F := BoundedContinuousFunction.ofNormedAddCommGroup f (SchwartzMap.continuous f) (SchwartzMap.seminorm ℝ 0 0 f) (norm_le_seminorm ℝ f) @[simp] theorem toBoundedContinuousFunction_apply (f : 𝓒(E, F)) (x : E) : f.toBoundedContinuousFunction x = f x := rfl /-- Schwartz functions as continuous functions -/ def toContinuousMap (f : 𝓒(E, F)) : C(E, F) := f.toBoundedContinuousFunction.toContinuousMap variable (π•œ E F) variable [RCLike π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] /-- The inclusion map from Schwartz functions to bounded continuous functions as a continuous linear map. -/ def toBoundedContinuousFunctionCLM : 𝓒(E, F) β†’L[π•œ] E →ᡇ F := mkCLMtoNormedSpace toBoundedContinuousFunction (by intro f g; ext; exact add_apply) (by intro a f; ext; exact smul_apply) (⟨{0}, 1, zero_le_one, by simpa [BoundedContinuousFunction.norm_le (apply_nonneg _ _)] using norm_le_seminorm π•œ ⟩) @[simp] theorem toBoundedContinuousFunctionCLM_apply (f : 𝓒(E, F)) (x : E) : toBoundedContinuousFunctionCLM π•œ E F f x = f x := rfl variable {E} section DiracDelta /-- The Dirac delta distribution -/ def delta (x : E) : 𝓒(E, F) β†’L[π•œ] F := (BoundedContinuousFunction.evalCLM π•œ x).comp (toBoundedContinuousFunctionCLM π•œ E F) @[simp] theorem delta_apply (xβ‚€ : E) (f : 𝓒(E, F)) : delta π•œ F xβ‚€ f = f xβ‚€ := rfl open MeasureTheory MeasureTheory.Measure variable [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] [CompleteSpace F] /-- Integrating against the Dirac measure is equal to the delta distribution. -/ @[simp] theorem integralCLM_dirac_eq_delta (x : E) : integralCLM π•œ (dirac x) = delta π•œ F x := by aesop end DiracDelta end BoundedContinuousFunction section ZeroAtInfty open scoped ZeroAtInfty variable [ProperSpace E] instance instZeroAtInftyContinuousMapClass : ZeroAtInftyContinuousMapClass 𝓒(E, F) E F where __ := instContinuousMapClass zero_at_infty := by intro f apply zero_at_infty_of_norm_le intro Ξ΅ hΞ΅ use (SchwartzMap.seminorm ℝ 1 0) f / Ξ΅ intro x hx rw [div_lt_iffβ‚€ hΞ΅] at hx have hxpos : 0 < β€–xβ€– := by rw [norm_pos_iff] intro hxzero simp only [hxzero, norm_zero, zero_mul, ← not_le] at hx exact hx (apply_nonneg (SchwartzMap.seminorm ℝ 1 0) f) have := norm_pow_mul_le_seminorm ℝ f 1 x rw [pow_one, ← le_div_iffβ‚€' hxpos] at this apply lt_of_le_of_lt this rwa [div_lt_iffβ‚€' hxpos] /-- Schwartz functions as continuous functions vanishing at infinity. -/ def toZeroAtInfty (f : 𝓒(E, F)) : Cβ‚€(E, F) where toFun := f zero_at_infty' := zero_at_infty f @[simp] theorem toZeroAtInfty_apply (f : 𝓒(E, F)) (x : E) : f.toZeroAtInfty x = f x := rfl @[simp] theorem toZeroAtInfty_toBCF (f : 𝓒(E, F)) : f.toZeroAtInfty.toBCF = f.toBoundedContinuousFunction := rfl variable (π•œ E F) variable [RCLike π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] /-- The inclusion map from Schwartz functions to continuous functions vanishing at infinity as a continuous linear map. -/ def toZeroAtInftyCLM : 𝓒(E, F) β†’L[π•œ] Cβ‚€(E, F) := mkCLMtoNormedSpace toZeroAtInfty (by intro f g; ext; exact add_apply) (by intro a f; ext; exact smul_apply) (⟨{0}, 1, zero_le_one, by simpa [← ZeroAtInftyContinuousMap.norm_toBCF_eq_norm, BoundedContinuousFunction.norm_le (apply_nonneg _ _)] using norm_le_seminorm π•œ ⟩) @[simp] theorem toZeroAtInftyCLM_apply (f : 𝓒(E, F)) (x : E) : toZeroAtInftyCLM π•œ E F f x = f x := rfl end ZeroAtInfty section Lp /-! ### Inclusion into L^p space -/ open MeasureTheory open scoped NNReal ENNReal variable [NormedAddCommGroup D] [MeasurableSpace D] [MeasurableSpace E] [OpensMeasurableSpace E] [NormedField π•œ] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] variable (π•œ F) in /-- The `L^p` norm of a Schwartz function is controlled by a finite family of Schwartz seminorms. The maximum index `k` and the constant `C` depend on `p` and `ΞΌ`. -/ theorem eLpNorm_le_seminorm (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : βˆƒ (k : β„•) (C : ℝβ‰₯0), βˆ€ (f : 𝓒(E, F)), eLpNorm f p ΞΌ ≀ C * ENNReal.ofReal ((Finset.Iic (k, 0)).sup (schwartzSeminormFamily π•œ E F) f) := by -- Apply HΓΆlder's inequality `β€–fβ€–_p ≀ β€–f₁‖_p * β€–fβ‚‚β€–_∞` to obtain the `L^p` norm of `f = f₁ β€’ fβ‚‚` -- using `f₁ = (1 + β€–xβ€–) ^ (-k)` and `fβ‚‚ = (1 + β€–xβ€–) ^ k β€’ f x`. rcases hΞΌ.exists_eLpNorm_lt_top p with ⟨k, hk⟩ refine ⟨k, (eLpNorm (fun x ↦ (1 + β€–xβ€–) ^ (-k : ℝ)) p ΞΌ).toNNReal * 2 ^ k, fun f ↦ ?_⟩ have h_one_add (x : E) : 0 < 1 + β€–xβ€– := lt_add_of_pos_of_le zero_lt_one (norm_nonneg x) calc eLpNorm (⇑f) p ΞΌ _ = eLpNorm ((fun x : E ↦ (1 + β€–xβ€–) ^ (-k : ℝ)) β€’ fun x ↦ (1 + β€–xβ€–) ^ k β€’ f x) p ΞΌ := by refine congrArg (eLpNorm Β· p ΞΌ) (funext fun x ↦ ?_) simp [(h_one_add x).ne'] _ ≀ eLpNorm (fun x ↦ (1 + β€–xβ€–) ^ (-k : ℝ)) p ΞΌ * eLpNorm (fun x ↦ (1 + β€–xβ€–) ^ k β€’ f x) ⊀ ΞΌ := by refine eLpNorm_smul_le_eLpNorm_mul_eLpNorm_top p _ ?_ refine Continuous.aestronglyMeasurable ?_ exact .rpow_const (.add continuous_const continuous_norm) fun x ↦ .inl (h_one_add x).ne' _ ≀ eLpNorm (fun x ↦ (1 + β€–xβ€–) ^ (-k : ℝ)) p ΞΌ * (2 ^ k * ENNReal.ofReal (((Finset.Iic (k, 0)).sup (schwartzSeminormFamily π•œ E F)) f)) := by gcongr refine eLpNormEssSup_le_of_ae_nnnorm_bound (ae_of_all ΞΌ fun x ↦ ?_) rw [← norm_toNNReal, Real.toNNReal_le_iff_le_coe] simpa [norm_smul, abs_of_nonneg (h_one_add x).le] using one_add_le_sup_seminorm_apply (m := (k, 0)) (le_refl k) (le_refl 0) f x _ = _ := by rw [ENNReal.coe_mul, ENNReal.coe_toNNReal hk.ne] simp only [ENNReal.coe_pow, ENNReal.coe_ofNat] ring /-- The `L^p` norm of a Schwartz function is finite. -/ theorem eLpNorm_lt_top (f : 𝓒(E, F)) (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : eLpNorm f p ΞΌ < ⊀ := by rcases eLpNorm_le_seminorm ℝ F p ΞΌ with ⟨k, C, hC⟩ exact lt_of_le_of_lt (hC f) (ENNReal.mul_lt_top ENNReal.coe_lt_top ENNReal.ofReal_lt_top) variable [SecondCountableTopologyEither E F] /-- Schwartz functions are in `L^∞`; does not require `hΞΌ.HasTemperateGrowth`. -/ theorem memLp_top (f : 𝓒(E, F)) (ΞΌ : Measure E := by volume_tac) : MemLp f ⊀ ΞΌ := by rcases f.decay 0 0 with ⟨C, _, hC⟩ refine memLp_top_of_bound f.continuous.aestronglyMeasurable C (ae_of_all ΞΌ fun x ↦ ?_) simpa using hC x /-- Schwartz functions are in `L^p` for any `p`. -/ theorem memLp (f : 𝓒(E, F)) (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : MemLp f p ΞΌ := ⟨f.continuous.aestronglyMeasurable, f.eLpNorm_lt_top p μ⟩ /-- Map a Schwartz function to an `Lp` function for any `p`. -/ def toLp (f : 𝓒(E, F)) (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : Lp F p ΞΌ := (f.memLp p ΞΌ).toLp theorem coeFn_toLp (f : 𝓒(E, F)) (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : f.toLp p ΞΌ =ᡐ[ΞΌ] f := (f.memLp p ΞΌ).coeFn_toLp theorem norm_toLp {f : 𝓒(E, F)} {p : ℝβ‰₯0∞} {ΞΌ : Measure E} [hΞΌ : ΞΌ.HasTemperateGrowth] : β€–f.toLp p ΞΌβ€– = ENNReal.toReal (eLpNorm f p ΞΌ) := by rw [Lp.norm_def, eLpNorm_congr_ae (coeFn_toLp f p ΞΌ)] theorem injective_toLp (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] [ΞΌ.IsOpenPosMeasure] : Function.Injective (fun f : 𝓒(E, F) ↦ f.toLp p ΞΌ) := fun f g ↦ by simpa [toLp] using (Continuous.ae_eq_iff_eq ΞΌ f.continuous g.continuous).mp variable (π•œ F) in theorem norm_toLp_le_seminorm (p : ℝβ‰₯0∞) (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : βˆƒ k C, 0 ≀ C ∧ βˆ€ (f : 𝓒(E, F)), β€–f.toLp p ΞΌβ€– ≀ C * (Finset.Iic (k, 0)).sup (schwartzSeminormFamily π•œ E F) f := by rcases eLpNorm_le_seminorm π•œ F p ΞΌ with ⟨k, C, hC⟩ refine ⟨k, C, C.coe_nonneg, fun f ↦ ?_⟩ rw [norm_toLp] refine ENNReal.toReal_le_of_le_ofReal (by simp [mul_nonneg]) ?_ rw [ENNReal.ofReal_mul NNReal.zero_le_coe] simpa using hC f variable (π•œ F) in /-- Continuous linear map from Schwartz functions to `L^p`. -/ def toLpCLM (p : ℝβ‰₯0∞) [Fact (1 ≀ p)] (ΞΌ : Measure E := by volume_tac) [hΞΌ : ΞΌ.HasTemperateGrowth] : 𝓒(E, F) β†’L[π•œ] Lp F p ΞΌ := mkCLMtoNormedSpace (fun f ↦ f.toLp p ΞΌ) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) <| by rcases norm_toLp_le_seminorm π•œ F p ΞΌ with ⟨k, C, hC_pos, hC⟩ exact ⟨Finset.Iic (k, 0), C, hC_pos, hC⟩ @[simp] theorem toLpCLM_apply {p : ℝβ‰₯0∞} [Fact (1 ≀ p)] {ΞΌ : Measure E} [hΞΌ : ΞΌ.HasTemperateGrowth] {f : 𝓒(E, F)} : toLpCLM π•œ F p ΞΌ f = f.toLp p ΞΌ := rfl @[fun_prop] theorem continuous_toLp {p : ℝβ‰₯0∞} [Fact (1 ≀ p)] {ΞΌ : Measure E} [hΞΌ : ΞΌ.HasTemperateGrowth] : Continuous (fun f : 𝓒(E, F) ↦ f.toLp p ΞΌ) := (toLpCLM ℝ F p ΞΌ).continuous end Lp section L2 open MeasureTheory variable [NormedAddCommGroup H] [NormedSpace ℝ H] [FiniteDimensional ℝ H] [MeasurableSpace H] [BorelSpace H] [NormedAddCommGroup V] [InnerProductSpace β„‚ V] @[simp] theorem inner_toL2_toL2_eq (f g : 𝓒(H, V)) (ΞΌ : Measure H := by volume_tac) [ΞΌ.HasTemperateGrowth] : inner β„‚ (f.toLp 2 ΞΌ) (g.toLp 2 ΞΌ) = ∫ x, inner β„‚ (f x) (g x) βˆ‚ΞΌ := by apply integral_congr_ae have hf_ae := f.coeFn_toLp 2 ΞΌ have hg_ae := g.coeFn_toLp 2 ΞΌ filter_upwards [hf_ae, hg_ae] with _ hf hg rw [hf, hg] end L2 section integration_by_parts open ENNReal MeasureTheory variable [NormedAddCommGroup V] [NormedSpace ℝ V] /-- Integration by parts of Schwartz functions for the 1-dimensional derivative. Version for a general bilinear map. -/ theorem integral_bilinear_deriv_right_eq_neg_left (f : 𝓒(ℝ, E)) (g : 𝓒(ℝ, F)) (L : E β†’L[ℝ] F β†’L[ℝ] V) : ∫ (x : ℝ), L (f x) (deriv g x) = -∫ (x : ℝ), L (deriv f x) (g x) := MeasureTheory.integral_bilinear_hasDerivAt_right_eq_neg_left_of_integrable f.hasDerivAt g.hasDerivAt (bilinLeftCLM L (derivCLM ℝ g).hasTemperateGrowth f).integrable (bilinLeftCLM L g.hasTemperateGrowth (derivCLM ℝ f)).integrable (bilinLeftCLM L g.hasTemperateGrowth f).integrable variable [RCLike π•œ] [NormedSpace π•œ F] [NormedSpace π•œ V] /-- Integration by parts of Schwartz functions for the 1-dimensional derivative. Version for a Schwartz function with values in continuous linear maps. -/ theorem integral_clm_comp_deriv_right_eq_neg_left (f : 𝓒(ℝ, F β†’L[π•œ] V)) (g : 𝓒(ℝ, F)) : ∫ (x : ℝ), f x (deriv g x) = -∫ (x : ℝ), deriv f x (g x) := integral_bilinear_deriv_right_eq_neg_left f g ((ContinuousLinearMap.id π•œ (F β†’L[π•œ] V)).bilinearRestrictScalars ℝ) /-- Integration by parts of Schwartz functions for the 1-dimensional derivative. Version for multiplication of scalar-valued Schwartz functions. -/ theorem integral_mul_deriv_eq_neg_deriv_mul (f : 𝓒(ℝ, π•œ)) (g : 𝓒(ℝ, π•œ)) : ∫ (x : ℝ), f x * (deriv g x) = -∫ (x : ℝ), deriv f x * (g x) := integral_bilinear_deriv_right_eq_neg_left f g (ContinuousLinearMap.mul ℝ π•œ) end integration_by_parts end SchwartzMap
.lake/packages/mathlib/Mathlib/Analysis/Distribution/FourierSchwartz.lean
import Mathlib.Analysis.Distribution.SchwartzSpace import Mathlib.Analysis.Fourier.FourierTransformDeriv import Mathlib.Analysis.Fourier.Inversion /-! # Fourier transform on Schwartz functions This file constructs the Fourier transform as a continuous linear map acting on Schwartz functions, in `fourierTransformCLM`. It is also given as a continuous linear equiv, in `fourierTransformCLE`. -/ open Real MeasureTheory MeasureTheory.Measure open scoped FourierTransform ComplexInnerProductSpace noncomputable section namespace SchwartzMap variable (π•œ : Type*) [RCLike π•œ] {W : Type*} [NormedAddCommGroup W] [NormedSpace β„‚ W] [NormedSpace π•œ W] {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] [NormedSpace π•œ E] [SMulCommClass β„‚ π•œ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace β„‚ F] [NormedSpace π•œ F] [SMulCommClass β„‚ π•œ F] {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [FiniteDimensional ℝ V] [MeasurableSpace V] [BorelSpace V] section definition /-- The Fourier transform on a real inner product space, as a continuous linear map on the Schwartz space. -/ def fourierTransformCLM : 𝓒(V, E) β†’L[π•œ] 𝓒(V, E) := by refine mkCLM ((𝓕 : (V β†’ E) β†’ (V β†’ E)) Β·) ?_ ?_ ?_ ?_ Β· intro f g x simp only [fourierIntegral_eq, add_apply, smul_add] rw [integral_add] Β· exact (fourierIntegral_convergent_iff _).2 f.integrable Β· exact (fourierIntegral_convergent_iff _).2 g.integrable Β· intro c f x simp only [fourierIntegral_eq, smul_apply, smul_comm _ c, integral_smul, RingHom.id_apply] Β· intro f exact Real.contDiff_fourierIntegral (fun n _ ↦ integrable_pow_mul volume f n) Β· rintro ⟨k, n⟩ refine ⟨Finset.range (n + integrablePower (volume : Measure V) + 1) Γ—Λ’ Finset.range (k + 1), (2 * Ο€) ^ n * (2 * ↑n + 2) ^ k * (Finset.range (n + 1) Γ—Λ’ Finset.range (k + 1)).card * 2 ^ integrablePower (volume : Measure V) * (∫ (x : V), (1 + β€–xβ€–) ^ (- (integrablePower (volume : Measure V) : ℝ))) * 2, ⟨by positivity, fun f x ↦ ?_⟩⟩ apply (pow_mul_norm_iteratedFDeriv_fourierIntegral_le (f.smooth ⊀) (fun k n _hk _hn ↦ integrable_pow_mul_iteratedFDeriv _ f k n) le_top le_top x).trans simp only [mul_assoc] gcongr calc βˆ‘ p ∈ Finset.range (n + 1) Γ—Λ’ Finset.range (k + 1), ∫ (v : V), β€–vβ€– ^ p.1 * β€–iteratedFDeriv ℝ p.2 (⇑f) vβ€– ≀ βˆ‘ p ∈ Finset.range (n + 1) Γ—Λ’ Finset.range (k + 1), 2 ^ integrablePower (volume : Measure V) * (∫ (x : V), (1 + β€–xβ€–) ^ (- (integrablePower (volume : Measure V) : ℝ))) * 2 * ((Finset.range (n + integrablePower (volume : Measure V) + 1) Γ—Λ’ Finset.range (k + 1)).sup (schwartzSeminormFamily π•œ V E)) f := by gcongr with p hp simp only [Finset.mem_product, Finset.mem_range] at hp apply (f.integral_pow_mul_iteratedFDeriv_le π•œ _ _ _).trans simp only [mul_assoc] rw [two_mul] gcongr Β· apply Seminorm.le_def.1 have : (0, p.2) ∈ (Finset.range (n + integrablePower (volume : Measure V) + 1) Γ—Λ’ Finset.range (k + 1)) := by simp [hp.2] apply Finset.le_sup this (f := fun p ↦ SchwartzMap.seminorm π•œ p.1 p.2 (E := V) (F := E)) Β· apply Seminorm.le_def.1 have : (p.1 + integrablePower (volume : Measure V), p.2) ∈ (Finset.range (n + integrablePower (volume : Measure V) + 1) Γ—Λ’ Finset.range (k + 1)) := by simp [hp.2] omega apply Finset.le_sup this (f := fun p ↦ SchwartzMap.seminorm π•œ p.1 p.2 (E := V) (F := E)) _ = _ := by simp [mul_assoc] instance instFourierTransform : FourierTransform 𝓒(V, E) 𝓒(V, E) where fourierTransform f := fourierTransformCLM β„‚ f lemma fourier_coe (f : 𝓒(V, E)) : 𝓕 f = 𝓕 (f : V β†’ E) := rfl instance instFourierModule : FourierModule π•œ 𝓒(V, E) 𝓒(V, E) where fourier_add := ContinuousLinearMap.map_add _ fourier_smul := (fourierTransformCLM π•œ).map_smul @[simp] theorem fourierTransformCLM_apply (f : 𝓒(V, E)) : fourierTransformCLM π•œ f = 𝓕 f := rfl instance instFourierTransformInv : FourierTransformInv 𝓒(V, E) 𝓒(V, E) where fourierTransformInv := (compCLMOfContinuousLinearEquiv β„‚ (LinearIsometryEquiv.neg ℝ (E := V))) ∘L (fourierTransformCLM β„‚) lemma fourierInv_coe (f : 𝓒(V, E)) : 𝓕⁻ f = 𝓕⁻ (f : V β†’ E) := by ext x exact (fourierIntegralInv_eq_fourierIntegral_neg f x).symm instance instFourierInvModule : FourierInvModule π•œ 𝓒(V, E) 𝓒(V, E) where fourierInv_add := ContinuousLinearMap.map_add _ fourierInv_smul := ((compCLMOfContinuousLinearEquiv π•œ (D := V) (E := V) (F := E) (LinearIsometryEquiv.neg ℝ (E := V))) ∘L (fourierTransformCLM π•œ)).map_smul variable [CompleteSpace E] instance instFourierPair : FourierPair 𝓒(V, E) 𝓒(V, E) where inv_fourier := by intro f ext x rw [fourierInv_coe, fourier_coe, f.continuous.fourier_inversion f.integrable (𝓕 f).integrable] instance instFourierInvPair : FourierInvPair 𝓒(V, E) 𝓒(V, E) where fourier_inv := by intro f ext x rw [fourier_coe, fourierInv_coe, f.continuous.fourier_inversion_inv f.integrable (𝓕 f).integrable] @[deprecated (since := "2025-11-13")] alias fourier_inversion := FourierTransform.inv_fourier @[deprecated (since := "2025-11-13")] alias fourier_inversion_inv := FourierTransform.fourier_inv /-- The Fourier transform on a real inner product space, as a continuous linear equiv on the Schwartz space. -/ def fourierTransformCLE : 𝓒(V, E) ≃L[π•œ] 𝓒(V, E) where __ := FourierTransform.fourierEquiv π•œ 𝓒(V, E) 𝓒(V, E) continuous_toFun := (fourierTransformCLM π•œ).continuous continuous_invFun := ContinuousLinearMap.continuous _ @[simp] lemma fourierTransformCLE_apply (f : 𝓒(V, E)) : fourierTransformCLE π•œ f = 𝓕 f := rfl @[simp] lemma fourierTransformCLE_symm_apply (f : 𝓒(V, E)) : (fourierTransformCLE π•œ).symm f = 𝓕⁻ f := rfl end definition section fubini variable {F : Type*} [NormedAddCommGroup F] [NormedSpace β„‚ F] {G : Type*} [NormedAddCommGroup G] [NormedSpace β„‚ G] variable [CompleteSpace E] [CompleteSpace F] /-- The Fourier transform satisfies `∫ 𝓕 f * g = ∫ f * 𝓕 g`, i.e., it is self-adjoint. Version where the multiplication is replaced by a general bilinear form `M`. -/ theorem integral_bilin_fourierIntegral_eq (f : 𝓒(V, E)) (g : 𝓒(V, F)) (M : E β†’L[β„‚] F β†’L[β„‚] G) : ∫ ΞΎ, M (𝓕 f ΞΎ) (g ΞΎ) = ∫ x, M (f x) (𝓕 g x) := by simpa using VectorFourier.integral_bilin_fourierIntegral_eq_flip M (L := (innerβ‚— V)) continuous_fourierChar continuous_inner f.integrable g.integrable theorem integral_sesq_fourierIntegral_eq (f : 𝓒(V, E)) (g : 𝓒(V, F)) (M : E β†’L⋆[β„‚] F β†’L[β„‚] G) : ∫ ΞΎ, M (𝓕 f ΞΎ) (g ΞΎ) = ∫ x, M (f x) (𝓕⁻ g x) := by simpa [fourierInv_coe] using VectorFourier.integral_sesq_fourierIntegral_eq_neg_flip M (L := (innerβ‚— V)) continuous_fourierChar continuous_inner f.integrable g.integrable /-- Plancherel's theorem for Schwartz functions. Version where the multiplication is replaced by a general bilinear form `M`. -/ theorem integral_sesq_fourier_fourier (f : 𝓒(V, E)) (g : 𝓒(V, F)) (M : E β†’L⋆[β„‚] F β†’L[β„‚] G) : ∫ ΞΎ, M (𝓕 f ΞΎ) (𝓕 g ΞΎ) = ∫ x, M (f x) (g x) := by simpa using integral_sesq_fourierIntegral_eq f (𝓕 g) M end fubini section L2 variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace β„‚ H] [CompleteSpace H] /-- Plancherel's theorem for Schwartz functions. -/ theorem integral_inner_fourier_fourier (f g : 𝓒(V, H)) : ∫ ΞΎ, βŸͺ𝓕 f ΞΎ, 𝓕 g ξ⟫ = ∫ x, βŸͺf x, g x⟫ := integral_sesq_fourier_fourier f g (innerSL β„‚) theorem integral_norm_sq_fourier (f : 𝓒(V, H)) : ∫ ΞΎ, ‖𝓕 f ΞΎβ€–^2 = ∫ x, β€–f xβ€–^2 := by apply Complex.ofRealLI.injective simpa [← LinearIsometry.integral_comp_comm, inner_self_eq_norm_sq_to_K] using integral_inner_fourier_fourier f f theorem inner_fourier_toL2_eq (f : 𝓒(V, H)) : βŸͺ(𝓕 f).toLp 2, (𝓕 f).toLp 2⟫ = βŸͺf.toLp 2, f.toLp 2⟫ := by simp only [inner_toL2_toL2_eq] exact integral_sesq_fourier_fourier f f (innerSL β„‚) @[deprecated (since := "2025-11-13")] alias inner_fourierTransformCLM_toL2_eq := inner_fourier_toL2_eq @[simp] theorem norm_fourier_toL2_eq (f : 𝓒(V, H)) : β€–(𝓕 f).toLp 2β€– = β€–f.toLp 2β€– := by simp_rw [norm_eq_sqrt_re_inner (π•œ := β„‚), inner_fourier_toL2_eq] @[deprecated (since := "2025-11-13")] alias norm_fourierTransformCLM_toL2_eq := norm_fourier_toL2_eq end L2 end SchwartzMap
.lake/packages/mathlib/Mathlib/Analysis/Distribution/ContDiffMapSupportedIn.lean
import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.Sets.Compacts /-! # Continuously differentiable functions supported in a given compact set This file develops the basic theory of bundled `n`-times continuously differentiable functions with support contained in a given compact set. Given `n : β„•βˆž` and a compact subset `K` of a normed space `E`, we consider the type of bundled functions `f : E β†’ F` (where `F` is a normed vector space) such that: - `f` is `n`-times continuously differentiable: `ContDiff ℝ n f`. - `f` vanishes outside of a compact set: `EqOn f 0 Kᢜ`. The main reason this exists as a bundled type is to be endowed with its natural locally convex topology (namely, uniform convergence of `f` and its derivatives up to order `n`). Taking the locally convex inductive limit of these as `K` varies yields the natural topology on test functions, used to define distributions. While most of distribution theory cares only about `C^∞` functions, we also want to endow the space of `C^n` test functions with its natural topology. Indeed, distributions of order less than `n` are precisely those which extend continuously to this larger space of test functions. ## Main definitions - `ContDiffMapSupportedIn E F n K`: the type of bundled `n`-times continuously differentiable functions `E β†’ F` which vanish outside of `K`. - `ContDiffMapSupportedIn.iteratedFDerivWithOrderLM`: wrapper, as a `π•œ`-linear map, for `iteratedFDeriv` from `ContDiffMapSupportedIn E F n K` to `ContDiffMapSupportedIn E (E [Γ—i]β†’L[ℝ] F) k K`. - `ContDiffMapSupportedIn.iteratedFDerivLM`: specialization of the above, giving a `π•œ`-linear map from `ContDiffMapSupportedIn E F ⊀ K` to `ContDiffMapSupportedIn E (E [Γ—i]β†’L[ℝ] F) ⊀ K`. ## Main statements TODO: - `ContDiffMapSupportedIn.instIsUniformAddGroup` and `ContDiffMapSupportedIn.instLocallyConvexSpace`: `ContDiffMapSupportedIn` is a locally convex topological vector space. ## Notation - `𝓓^{n}_{K}(E, F)`: the space of `n`-times continuously differentiable functions `E β†’ F` which vanish outside of `K`. - `𝓓_{K}(E, F)`: the space of smooth (infinitely differentiable) functions `E β†’ F` which vanish outside of `K`, i.e. `𝓓^{⊀}_{K}(E, F)`. ## Implementation details * The technical choice of spelling `EqOn f 0 Kᢜ` in the definition, as opposed to `tsupport f βŠ† K` is to make rewriting `f x` to `0` easier when `x βˆ‰ K`. * Since the most common case is by far the smooth case, we often reserve the "expected" name of a result/definition to this case, and add `WithOrder` to the declaration applying to any regularity. * In `iteratedFDerivWithOrderLM`, we define the `i`-th iterated differentiation operator as a map from `𝓓^{n}_{K}` to `𝓓^{k}_{K}` without imposing relations on `n`, `k` and `i`. Of course this is defined as `0` if `k + i > n`. This creates some verbosity as all of these variables are explicit, but it allows the most flexibility while avoiding DTT hell. ## Tags distributions -/ open TopologicalSpace SeminormFamily Set Function Seminorm UniformSpace open scoped BoundedContinuousFunction Topology NNReal ContDiff variable (π•œ E F : Type*) [NontriviallyNormedField π•œ] [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedSpace π•œ F] [SMulCommClass ℝ π•œ F] {n k : β„•βˆž} {K : Compacts E} /-- The type of bundled `n`-times continuously differentiable maps which vanish outside of a fixed compact set `K`. -/ structure ContDiffMapSupportedIn (n : β„•βˆž) (K : Compacts E) : Type _ where /-- The underlying function. Use coercion instead. -/ protected toFun : E β†’ F protected contDiff' : ContDiff ℝ n toFun protected zero_on_compl' : EqOn toFun 0 Kᢜ /-- Notation for the space of bundled `n`-times continuously differentiable functions with support in a compact set `K`. -/ scoped[Distributions] notation "𝓓^{" n "}_{"K"}(" E ", " F ")" => ContDiffMapSupportedIn E F n K /-- Notation for the space of bundled smooth (infinitely differentiable) functions with support in a compact set `K`. -/ scoped[Distributions] notation "𝓓_{"K"}(" E ", " F ")" => ContDiffMapSupportedIn E F ⊀ K open Distributions /-- `ContDiffMapSupportedInClass B E F n K` states that `B` is a type of bundled `n`-times continuously differentiable functions with support in the compact set `K`. -/ class ContDiffMapSupportedInClass (B : Type*) (E F : outParam <| Type*) [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] (n : outParam β„•βˆž) (K : outParam <| Compacts E) extends FunLike B E F where map_contDiff (f : B) : ContDiff ℝ n f map_zero_on_compl (f : B) : EqOn f 0 Kᢜ open ContDiffMapSupportedInClass instance (B : Type*) (E F : outParam <| Type*) [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] (n : outParam β„•βˆž) (K : outParam <| Compacts E) [ContDiffMapSupportedInClass B E F n K] : ContinuousMapClass B E F where map_continuous f := (map_contDiff f).continuous instance (B : Type*) (E F : outParam <| Type*) [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] (n : outParam β„•βˆž) (K : outParam <| Compacts E) [ContDiffMapSupportedInClass B E F n K] : BoundedContinuousMapClass B E F where map_bounded f := by have := HasCompactSupport.intro K.isCompact (map_zero_on_compl f) rcases (map_continuous f).bounded_above_of_compact_support this with ⟨C, hC⟩ exact map_bounded (BoundedContinuousFunction.ofNormedAddCommGroup f (map_continuous f) C hC) namespace ContDiffMapSupportedIn instance toContDiffMapSupportedInClass : ContDiffMapSupportedInClass 𝓓^{n}_{K}(E, F) E F n K where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr map_contDiff f := f.contDiff' map_zero_on_compl f := f.zero_on_compl' variable {E F} protected theorem contDiff (f : 𝓓^{n}_{K}(E, F)) : ContDiff ℝ n f := map_contDiff f protected theorem zero_on_compl (f : 𝓓^{n}_{K}(E, F)) : EqOn f 0 Kᢜ := map_zero_on_compl f protected theorem compact_supp (f : 𝓓^{n}_{K}(E, F)) : HasCompactSupport f := .intro K.isCompact (map_zero_on_compl f) @[simp] theorem toFun_eq_coe {f : 𝓓^{n}_{K}(E, F)} : f.toFun = (f : E β†’ F) := rfl /-- See note [custom simps projection]. -/ def Simps.coe (f : 𝓓^{n}_{K}(E, F)) : E β†’ F := f initialize_simps_projections ContDiffMapSupportedIn (toFun β†’ coe, as_prefix coe) @[ext] theorem ext {f g : 𝓓^{n}_{K}(E, F)} (h : βˆ€ a, f a = g a) : f = g := DFunLike.ext _ _ h /-- Copy of a `ContDiffMapSupportedIn` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : 𝓓^{n}_{K}(E, F)) (f' : E β†’ F) (h : f' = f) : 𝓓^{n}_{K}(E, F) where toFun := f' contDiff' := h.symm β–Έ f.contDiff zero_on_compl' := h.symm β–Έ f.zero_on_compl @[simp] theorem coe_copy (f : 𝓓^{n}_{K}(E, F)) (f' : E β†’ F) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : 𝓓^{n}_{K}(E, F)) (f' : E β†’ F) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h @[simp] theorem coe_toBoundedContinuousFunction (f : 𝓓^{n}_{K}(E, F)) : (f : BoundedContinuousFunction E F) = (f : E β†’ F) := rfl section AddCommGroup @[simps -fullyApplied] instance : Zero 𝓓^{n}_{K}(E, F) where zero := .mk 0 contDiff_zero_fun fun _ _ ↦ rfl @[simps -fullyApplied] instance : Add 𝓓^{n}_{K}(E, F) where add f g := .mk (f + g) (f.contDiff.add g.contDiff) <| by rw [← add_zero 0] exact f.zero_on_compl.comp_leftβ‚‚ g.zero_on_compl @[simps -fullyApplied] instance : Neg 𝓓^{n}_{K}(E, F) where neg f := .mk (-f) (f.contDiff.neg) <| by rw [← neg_zero] exact f.zero_on_compl.comp_left @[simps -fullyApplied] instance instSub : Sub 𝓓^{n}_{K}(E, F) where sub f g := .mk (f - g) (f.contDiff.sub g.contDiff) <| by rw [← sub_zero 0] exact f.zero_on_compl.comp_leftβ‚‚ g.zero_on_compl @[simps -fullyApplied] instance instSMul {R} [Semiring R] [Module R F] [SMulCommClass ℝ R F] [ContinuousConstSMul R F] : SMul R 𝓓^{n}_{K}(E, F) where smul c f := .mk (c β€’ (f : E β†’ F)) (f.contDiff.const_smul c) <| by rw [← smul_zero c] exact f.zero_on_compl.comp_left instance : AddCommGroup 𝓓^{n}_{K}(E, F) := fast_instance% DFunLike.coe_injective.addCommGroup _ rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) fun _ _ ↦ rfl variable (E F K n) /-- Coercion as an additive homomorphism. -/ def coeHom : 𝓓^{n}_{K}(E, F) β†’+ E β†’ F where toFun f := f map_zero' := coe_zero map_add' _ _ := rfl variable {E F} theorem coe_coeHom : (coeHom E F n K : 𝓓^{n}_{K}(E, F) β†’ E β†’ F) = DFunLike.coe := rfl theorem coeHom_injective : Function.Injective (coeHom E F n K) := by rw [coe_coeHom] exact DFunLike.coe_injective end AddCommGroup section Module instance {R} [Semiring R] [Module R F] [SMulCommClass ℝ R F] [ContinuousConstSMul R F] : Module R 𝓓^{n}_{K}(E, F) := fast_instance% (coeHom_injective n K).module R (coeHom E F n K) fun _ _ ↦ rfl end Module protected theorem support_subset (f : 𝓓^{n}_{K}(E, F)) : support f βŠ† K := support_subset_iff'.mpr f.zero_on_compl protected theorem tsupport_subset (f : 𝓓^{n}_{K}(E, F)) : tsupport f βŠ† K := closure_minimal f.support_subset K.isCompact.isClosed protected theorem hasCompactSupport (f : 𝓓^{n}_{K}(E, F)) : HasCompactSupport f := HasCompactSupport.intro K.isCompact f.zero_on_compl /-- Inclusion of unbundled `n`-times continuously differentiable function with support included in a compact `K` into the space `𝓓^{n}_{K}`. -/ @[simps] protected def of_support_subset {f : E β†’ F} (hf : ContDiff ℝ n f) (hsupp : support f βŠ† K) : 𝓓^{n}_{K}(E, F) where toFun := f contDiff' := hf zero_on_compl' := support_subset_iff'.mp hsupp protected theorem bounded_iteratedFDeriv (f : 𝓓^{n}_{K}(E, F)) {i : β„•} (hi : i ≀ n) : βˆƒ C, βˆ€ x, β€–iteratedFDeriv ℝ i f xβ€– ≀ C := Continuous.bounded_above_of_compact_support (f.contDiff.continuous_iteratedFDeriv <| (WithTop.le_coe rfl).mpr hi) (f.hasCompactSupport.iteratedFDeriv i) /-- Inclusion of `𝓓^{n}_{K}(E, F)` into the space `E →ᡇ F` of bounded continuous maps as a `π•œ`-linear map. This is subsumed by `toBoundedContinuousFunctionCLM` (not yet in Mathlib), which also bundles the continuity. -/ @[simps -fullyApplied] noncomputable def toBoundedContinuousFunctionLM : 𝓓^{n}_{K}(E, F) β†’β‚—[π•œ] E →ᡇ F where toFun f := f map_add' _ _ := rfl map_smul' _ _ := rfl -- Workaround for simps' automatic name generation: manually specifying names is not supported yet. alias toBoundedContinuousFunctionLM_apply := toBoundedContinuousFunctionLM_apply_apply lemma toBoundedContinuousFunctionLM_eq_of_scalars (π•œ' : Type*) [NontriviallyNormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass ℝ π•œ' F] : (toBoundedContinuousFunctionLM π•œ : 𝓓^{n}_{K}(E, F) β†’ _) = toBoundedContinuousFunctionLM π•œ' := rfl variable (n k) in /-- `iteratedFDerivWithOrderLM π•œ n k i` is the `π•œ`-linear-map sending `f : 𝓓^{n}_{K}(E, F)` to its `i`-th iterated derivative as an element of `𝓓^{k}_{K}(E, E [Γ—i]β†’L[ℝ] F)`. This only makes mathematical sense if `k + i ≀ n`, otherwise we define it as the zero map. See `iteratedFDerivLM` for the very common case where everything is infinitely differentiable. This is subsumed by `iteratedFDerivWithOrderCLM` (not yet in Mathlib), which also bundles the continuity. -/ noncomputable def iteratedFDerivWithOrderLM (i : β„•) : 𝓓^{n}_{K}(E, F) β†’β‚—[π•œ] 𝓓^{k}_{K}(E, E [Γ—i]β†’L[ℝ] F) where /- Note: it is tempting to define this as some linear map if `k + i ≀ n`, and the zero map otherwise. However, we would lose the definitional equality between `iteratedFDerivWithOrderLM π•œ n k i f` and `iteratedFDerivWithOrderLM ℝ n k i f`. This is caused by the fact that the equality `f (if p then x else y) = if p then f x else f y` is not definitional. -/ toFun f := if hi : k + i ≀ n then .of_support_subset (f.contDiff.iteratedFDeriv_right <| by exact_mod_cast hi) ((support_iteratedFDeriv_subset i).trans f.tsupport_subset) else 0 map_add' f g := by split_ifs with hi Β· have hi' : (i : WithTop β„•βˆž) ≀ n := by exact_mod_cast le_of_add_le_right hi ext simp [iteratedFDeriv_add (f.contDiff.of_le hi') (g.contDiff.of_le hi')] Β· simp map_smul' c f := by split_ifs with hi Β· have hi' : (i : WithTop β„•βˆž) ≀ n := by exact_mod_cast le_of_add_le_right hi ext simp [iteratedFDeriv_const_smul_apply (f.contDiff.of_le hi').contDiffAt] Β· simp @[simp] lemma iteratedFDerivWithOrderLM_apply {i : β„•} (f : 𝓓^{n}_{K}(E, F)) : iteratedFDerivWithOrderLM π•œ n k i f = if k + i ≀ n then iteratedFDeriv ℝ i f else 0 := by rw [ContDiffMapSupportedIn.iteratedFDerivWithOrderLM] split_ifs <;> rfl lemma iteratedFDerivWithOrderLM_apply_of_le {i : β„•} (f : 𝓓^{n}_{K}(E, F)) (hin : k + i ≀ n) : iteratedFDerivWithOrderLM π•œ n k i f = iteratedFDeriv ℝ i f := by simp [hin] lemma iteratedFDerivWithOrderLM_apply_of_gt {i : β„•} (f : 𝓓^{n}_{K}(E, F)) (hin : Β¬ (k + i ≀ n)) : iteratedFDerivWithOrderLM π•œ n k i f = 0 := by ext : 1 simp [hin] lemma iteratedFDerivWithOrderLM_eq_of_scalars {i : β„•} (π•œ' : Type*) [NontriviallyNormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass ℝ π•œ' F] : (iteratedFDerivWithOrderLM π•œ n k i : 𝓓^{n}_{K}(E, F) β†’ _) = iteratedFDerivWithOrderLM π•œ' n k i := rfl /-- `iteratedFDerivLM π•œ i` is the `π•œ`-linear-map sending `f : 𝓓_{K}(E, F)` to its `i`-th iterated derivative as an element of `𝓓_{K}(E, E [Γ—i]β†’L[ℝ] F)`. See also `iteratedFDerivWithOrderLM` if you need more control on the regularities. This is subsumed by `iteratedFDerivCLM` (not yet in Mathlib), which also bundles the continuity. -/ noncomputable def iteratedFDerivLM (i : β„•) : 𝓓_{K}(E, F) β†’β‚—[π•œ] 𝓓_{K}(E, E [Γ—i]β†’L[ℝ] F) where toFun f := .of_support_subset (f.contDiff.iteratedFDeriv_right le_rfl) ((support_iteratedFDeriv_subset i).trans f.tsupport_subset) map_add' f g := by have hi : (i : WithTop β„•βˆž) ≀ ∞ := by exact_mod_cast le_top ext simp [iteratedFDeriv_add (f.contDiff.of_le hi) (g.contDiff.of_le hi)] map_smul' c f := by have hi : (i : WithTop β„•βˆž) ≀ ∞ := by exact_mod_cast le_top ext simp [iteratedFDeriv_const_smul_apply (f.contDiff.of_le hi).contDiffAt] @[simp] lemma iteratedFDerivLM_apply {i : β„•} (f : 𝓓_{K}(E, F)) : iteratedFDerivLM π•œ i f = iteratedFDeriv ℝ i f := rfl /-- Note: this turns out to be a definitional equality thanks to decidablity of the order on `β„•βˆž`. This means we could have *defined* `iteratedFDerivLM` this way, but we avoid it to make sure that `if`s won't appear in the smooth case. -/ lemma iteratedFDerivLM_eq_withOrder (i : β„•) : (iteratedFDerivLM π•œ i : 𝓓_{K}(E, F) β†’β‚—[π•œ] _) = iteratedFDerivWithOrderLM π•œ ⊀ ⊀ i := rfl lemma iteratedFDerivLM_eq_of_scalars {i : β„•} (π•œ' : Type*) [NontriviallyNormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass ℝ π•œ' F] : (iteratedFDerivLM π•œ i : 𝓓_{K}(E, F) β†’ _) = iteratedFDerivLM π•œ' i := rfl variable (n) in /-- `structureMapLM π•œ n i` is the `π•œ`-linear-map sending `f : 𝓓^{n}_{K}(E, F)` to its `i`-th iterated derivative as an element of `E →ᡇ (E [Γ—i]β†’L[ℝ] F)`. In other words, it is the composition of `toBoundedContinuousFunctionLM π•œ` and `iteratedFDerivWithOrderLM π•œ n 0 i`. This only makes mathematical sense if `i ≀ n`, otherwise we define it as the zero map. We call these "structure maps" because they define the topology on `𝓓^{n}_{K}(E, F)`. This is subsumed by `structureMapCLM` (not yet in Mathlib), which also bundles the continuity. -/ noncomputable def structureMapLM (i : β„•) : 𝓓^{n}_{K}(E, F) β†’β‚—[π•œ] E →ᡇ (E [Γ—i]β†’L[ℝ] F) := toBoundedContinuousFunctionLM π•œ βˆ˜β‚— iteratedFDerivWithOrderLM π•œ n 0 i lemma structureMapLM_eq {i : β„•} : (structureMapLM π•œ ⊀ i : 𝓓_{K}(E, F) β†’β‚—[π•œ] E →ᡇ (E [Γ—i]β†’L[ℝ] F)) = (toBoundedContinuousFunctionLM π•œ : 𝓓_{K}(E, E [Γ—i]β†’L[ℝ] F) β†’β‚—[π•œ] E →ᡇ (E [Γ—i]β†’L[ℝ] F)) βˆ˜β‚— (iteratedFDerivLM π•œ i : 𝓓_{K}(E, F) β†’β‚—[π•œ] 𝓓_{K}(E, E [Γ—i]β†’L[ℝ] F)) := rfl lemma structureMapLM_apply_withOrder {i : β„•} (f : 𝓓^{n}_{K}(E, F)) : structureMapLM π•œ n i f = if i ≀ n then iteratedFDeriv ℝ i f else 0 := by simp [structureMapLM] lemma structureMapLM_apply {i : β„•} (f : 𝓓_{K}(E, F)) : structureMapLM π•œ ⊀ i f = iteratedFDeriv ℝ i f := by simp [structureMapLM_eq] lemma structureMapLM_eq_of_scalars {i : β„•} (π•œ' : Type*) [NontriviallyNormedField π•œ'] [NormedSpace π•œ' F] [SMulCommClass ℝ π•œ' F] : (structureMapLM π•œ n i : 𝓓^{n}_{K}(E, F) β†’ _) = structureMapLM π•œ' n i := rfl end ContDiffMapSupportedIn
.lake/packages/mathlib/Mathlib/Analysis/Distribution/TemperateGrowth.lean
import Mathlib.Analysis.Calculus.ContDiff.Bounds import Mathlib.Analysis.SpecialFunctions.JapaneseBracket /-! # Functions and measures of temperate growth -/ noncomputable section open scoped Nat NNReal ContDiff open Asymptotics variable {π•œ R D E F G : Type*} namespace Function variable [NormedAddCommGroup E] [NormedSpace ℝ E] variable [NormedAddCommGroup F] [NormedSpace ℝ F] /-- A function is called of temperate growth if it is smooth and all iterated derivatives are polynomially bounded. -/ @[fun_prop] def HasTemperateGrowth (f : E β†’ F) : Prop := ContDiff ℝ ∞ f ∧ βˆ€ n : β„•, βˆƒ (k : β„•) (C : ℝ), βˆ€ x, β€–iteratedFDeriv ℝ n f xβ€– ≀ C * (1 + β€–xβ€–) ^ k /-- A function has temperate growth if and only if it is smooth and its `n`-th iterated derivative is `O((1 + β€–xβ€–) ^ k)` for some `k : β„•` (depending on `n`). Note that the `O` here is with respect to the `⊀` filter, meaning that the bound holds everywhere. TODO: when `E` is finite dimensional, this is equivalent to the derivatives being `O(β€–xβ€– ^ k)` as `β€–xβ€– β†’ ∞`. -/ theorem hasTemperateGrowth_iff_isBigO {f : E β†’ F} : f.HasTemperateGrowth ↔ ContDiff ℝ ∞ f ∧ βˆ€ n, βˆƒ k, iteratedFDeriv ℝ n f =O[⊀] (fun x ↦ (1 + β€–xβ€–) ^ k) := by simp_rw [Asymptotics.isBigO_top] congrm ContDiff ℝ ∞ f ∧ (βˆ€ n, βˆƒ k C, βˆ€ x, _ ≀ C * ?_) rw [norm_pow, Real.norm_of_nonneg (by positivity)] /-- If `f` has temperate growth, then its `n`-th iterated derivative is `O((1 + β€–xβ€–) ^ k)` for some `k : β„•` (depending on `n`). Note that the `O` here is with respect to the `⊀` filter, meaning that the bound holds everywhere. -/ theorem HasTemperateGrowth.isBigO {f : E β†’ F} (hf_temperate : f.HasTemperateGrowth) (n : β„•) : βˆƒ k, iteratedFDeriv ℝ n f =O[⊀] (fun x ↦ (1 + β€–xβ€–) ^ k) := Function.hasTemperateGrowth_iff_isBigO.mp hf_temperate |>.2 n /-- If `f` has temperate growth, then for any `N : β„•` one can find `k` such that *all* iterated derivatives of `f` of order `≀ N` are `O((1 + β€–xβ€–) ^ k)`. Note that the `O` here is with respect to the `⊀` filter, meaning that the bound holds everywhere. -/ theorem HasTemperateGrowth.isBigO_uniform {f : E β†’ F} (hf_temperate : f.HasTemperateGrowth) (N : β„•) : βˆƒ k, βˆ€ n ≀ N, iteratedFDeriv ℝ n f =O[⊀] (fun x ↦ (1 + β€–xβ€–) ^ k) := by choose k hk using hf_temperate.isBigO use (Finset.range (N + 1)).sup k intro n hn refine (hk n).trans (isBigO_of_le _ fun x ↦ ?_) rw [Real.norm_of_nonneg (by positivity), Real.norm_of_nonneg (by positivity)] gcongr Β· simp Β· exact Finset.le_sup (by simpa [← Finset.mem_range_succ_iff] using hn) theorem HasTemperateGrowth.norm_iteratedFDeriv_le_uniform {f : E β†’ F} (hf_temperate : f.HasTemperateGrowth) (n : β„•) : βˆƒ (k : β„•) (C : ℝ), 0 ≀ C ∧ βˆ€ N ≀ n, βˆ€ x : E, β€–iteratedFDeriv ℝ N f xβ€– ≀ C * (1 + β€–xβ€–) ^ k := by rcases hf_temperate.isBigO_uniform n with ⟨k, hk⟩ set F := fun x (N : Fin (n+1)) ↦ iteratedFDeriv ℝ N f x have : F =O[⊀] (fun x ↦ (1 + β€–xβ€–) ^ k) := by simp_rw [F, isBigO_pi, Fin.forall_iff, Nat.lt_succ] exact hk rcases this.exists_nonneg with ⟨C, C_nonneg, hC⟩ simp (discharger := positivity) only [isBigOWith_top, Real.norm_of_nonneg, pi_norm_le_iff_of_nonneg, Fin.forall_iff, Nat.lt_succ] at hC exact ⟨k, C, C_nonneg, fun N hN x ↦ hC x N hN⟩ @[deprecated (since := "2025-10-30")] alias HasTemperateGrowth.norm_iteratedFDeriv_le_uniform_aux := HasTemperateGrowth.norm_iteratedFDeriv_le_uniform lemma HasTemperateGrowth.of_fderiv {f : E β†’ F} (h'f : Function.HasTemperateGrowth (fderiv ℝ f)) (hf : Differentiable ℝ f) {k : β„•} {C : ℝ} (h : βˆ€ x, β€–f xβ€– ≀ C * (1 + β€–xβ€–) ^ k) : Function.HasTemperateGrowth f := by refine ⟨contDiff_succ_iff_fderiv.2 ⟨hf, by simp, h'f.1⟩, fun n ↦ ?_⟩ rcases n with rfl | m Β· exact ⟨k, C, fun x ↦ by simpa using h x⟩ Β· rcases h'f.2 m with ⟨k', C', h'⟩ refine ⟨k', C', ?_⟩ simpa [iteratedFDeriv_succ_eq_comp_right] using h' @[fun_prop] lemma HasTemperateGrowth.zero : Function.HasTemperateGrowth (fun _ : E ↦ (0 : F)) := by refine ⟨contDiff_const, fun n ↦ ⟨0, 0, fun x ↦ ?_⟩⟩ simp only [iteratedFDeriv_zero_fun, Pi.zero_apply, norm_zero] positivity @[fun_prop] lemma HasTemperateGrowth.const (c : F) : Function.HasTemperateGrowth (fun _ : E ↦ c) := .of_fderiv (by simpa using .zero) (differentiable_const c) (k := 0) (C := β€–cβ€–) (fun x ↦ by simp) section Addition variable {f g : E β†’ F} @[fun_prop] theorem HasTemperateGrowth.neg (hf : f.HasTemperateGrowth) : (-f).HasTemperateGrowth := by refine ⟨hf.1.neg, fun n ↦ ?_⟩ obtain ⟨k, C, h⟩ := hf.2 n exact ⟨k, C, fun x ↦ by simpa [iteratedFDeriv_neg_apply] using h x⟩ @[fun_prop] theorem HasTemperateGrowth.add (hf : f.HasTemperateGrowth) (hg : g.HasTemperateGrowth) : (f + g).HasTemperateGrowth := by rw [hasTemperateGrowth_iff_isBigO] at * refine ⟨hf.1.add hg.1, fun n ↦ ?_⟩ obtain ⟨k₁, hβ‚βŸ© := hf.2 n obtain ⟨kβ‚‚, hβ‚‚βŸ© := hg.2 n use max k₁ kβ‚‚ rw [iteratedFDeriv_add (hf.1.of_le (WithTop.coe_le_coe.mpr (le_of_lt (ENat.coe_lt_top _)))) (hg.1.of_le (WithTop.coe_le_coe.mpr (le_of_lt (ENat.coe_lt_top _))))] have : 1 ≀ᢠ[⊀] fun (x : E) ↦ 1 + β€–xβ€– := by filter_upwards with _ using (le_add_iff_nonneg_right _).mpr (by positivity) exact (h₁.trans (IsBigO.pow_of_le_right this (k₁.le_max_left kβ‚‚))).add (hβ‚‚.trans (IsBigO.pow_of_le_right this (k₁.le_max_right kβ‚‚))) @[fun_prop] theorem HasTemperateGrowth.sub (hf : f.HasTemperateGrowth) (hg : g.HasTemperateGrowth) : (f - g).HasTemperateGrowth := by convert hf.add hg.neg using 1 grind end Addition section Multiplication variable [NontriviallyNormedField π•œ] [NormedAlgebra ℝ π•œ] [NormedAddCommGroup D] [NormedSpace ℝ D] [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedSpace π•œ F] [NormedSpace π•œ G] /-- The product of two functions of temperate growth is again of temperate growth. Version for bilinear maps. -/ @[fun_prop] theorem _root_.ContinuousLinearMap.bilinear_hasTemperateGrowth [NormedSpace π•œ E] (B : E β†’L[π•œ] F β†’L[π•œ] G) {f : D β†’ E} {g : D β†’ F} (hf : f.HasTemperateGrowth) (hg : g.HasTemperateGrowth) : (fun x ↦ B (f x) (g x)).HasTemperateGrowth := by rw [Function.hasTemperateGrowth_iff_isBigO] constructor Β· apply (B.bilinearRestrictScalars ℝ).isBoundedBilinearMap.contDiff.comp (hf.1.prodMk hg.1) intro n rcases hf.isBigO_uniform n with ⟨k1, h1⟩ rcases hg.isBigO_uniform n with ⟨k2, h2⟩ use k1 + k2 have estimate (x : D) : β€–iteratedFDeriv ℝ n (fun x ↦ B (f x) (g x)) xβ€– ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n+1), (n.choose i) * β€–iteratedFDeriv ℝ i f xβ€– * β€–iteratedFDeriv ℝ (n-i) g xβ€– := by refine (B.bilinearRestrictScalars ℝ).norm_iteratedFDeriv_le_of_bilinear hf.1 hg.1 x ?_ exact WithTop.coe_le_coe.mpr le_top refine (IsBigO.of_norm_le estimate).trans (.const_mul_left (.sum fun i hi ↦ ?_) _) simp_rw [mul_assoc, pow_add] refine .const_mul_left (.mul (h1 i ?_).norm_left (h2 (n-i) ?_).norm_left) _ <;> grind /-- The product of two functions of temperate growth is again of temperate growth. Version for scalar multiplication. -/ @[fun_prop] theorem _root_.Function.HasTemperateGrowth.smul {f : E β†’ π•œ} {g : E β†’ F} (hf : f.HasTemperateGrowth) (hg : g.HasTemperateGrowth) : (f β€’ g).HasTemperateGrowth := (ContinuousLinearMap.lsmul ℝ π•œ).bilinear_hasTemperateGrowth hf hg variable [NormedRing R] [NormedAlgebra ℝ R] /-- The product of two functions of temperate growth is again of temperate growth. -/ @[fun_prop] theorem _root_.Function.HasTemperateGrowth.mul {f g : E β†’ R} (hf : f.HasTemperateGrowth) (hg : g.HasTemperateGrowth) : (f * g).HasTemperateGrowth := (ContinuousLinearMap.mul ℝ R).bilinear_hasTemperateGrowth hf hg end Multiplication @[fun_prop] lemma _root_.ContinuousLinearMap.hasTemperateGrowth (f : E β†’L[ℝ] F) : Function.HasTemperateGrowth f := by apply Function.HasTemperateGrowth.of_fderiv ?_ f.differentiable (k := 1) (C := β€–fβ€–) (fun x ↦ ?_) Β· have : fderiv ℝ f = fun _ ↦ f := by ext1 v; simp only [ContinuousLinearMap.fderiv] simpa [this] using .const _ Β· exact (f.le_opNorm x).trans (by simp [mul_add]) end Function namespace MeasureTheory.Measure variable [NormedAddCommGroup E] [MeasurableSpace E] open Module open scoped ENNReal /-- A measure `ΞΌ` has temperate growth if there is an `n : β„•` such that `(1 + β€–xβ€–) ^ (- n)` is `ΞΌ`-integrable. -/ class HasTemperateGrowth (ΞΌ : Measure E) : Prop where exists_integrable : βˆƒ (n : β„•), Integrable (fun x ↦ (1 + β€–xβ€–) ^ (- (n : ℝ))) ΞΌ open Classical in /-- An integer exponent `l` such that `(1 + β€–xβ€–) ^ (-l)` is integrable if `ΞΌ` has temperate growth. -/ def integrablePower (ΞΌ : Measure E) : β„• := if h : ΞΌ.HasTemperateGrowth then h.exists_integrable.choose else 0 lemma integrable_pow_neg_integrablePower (ΞΌ : Measure E) [h : ΞΌ.HasTemperateGrowth] : Integrable (fun x ↦ (1 + β€–xβ€–) ^ (- (ΞΌ.integrablePower : ℝ))) ΞΌ := by simpa [Measure.integrablePower, h] using h.exists_integrable.choose_spec instance _root_.MeasureTheory.IsFiniteMeasure.instHasTemperateGrowth {ΞΌ : Measure E} [h : IsFiniteMeasure ΞΌ] : ΞΌ.HasTemperateGrowth := ⟨⟨0, by simp⟩⟩ variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] [BorelSpace E] in instance IsAddHaarMeasure.instHasTemperateGrowth {ΞΌ : Measure E} [h : ΞΌ.IsAddHaarMeasure] : ΞΌ.HasTemperateGrowth := ⟨⟨finrank ℝ E + 1, by apply integrable_one_add_norm; norm_num⟩⟩ /-- Pointwise inequality to control `x ^ k * f` in terms of `1 / (1 + x) ^ l` if one controls both `f` (with a bound `C₁`) and `x ^ (k + l) * f` (with a bound `Cβ‚‚`). This will be used to check integrability of `x ^ k * f x` when `f` is a Schwartz function, and to control explicitly its integral in terms of suitable seminorms of `f`. -/ lemma _root_.pow_mul_le_of_le_of_pow_mul_le {C₁ Cβ‚‚ : ℝ} {k l : β„•} {x f : ℝ} (hx : 0 ≀ x) (hf : 0 ≀ f) (h₁ : f ≀ C₁) (hβ‚‚ : x ^ (k + l) * f ≀ Cβ‚‚) : x ^ k * f ≀ 2 ^ l * (C₁ + Cβ‚‚) * (1 + x) ^ (- (l : ℝ)) := by have : 0 ≀ Cβ‚‚ := le_trans (by positivity) hβ‚‚ have : 2 ^ l * (C₁ + Cβ‚‚) * (1 + x) ^ (- (l : ℝ)) = ((1 + x) / 2) ^ (-(l : ℝ)) * (C₁ + Cβ‚‚) := by rw [Real.div_rpow (by linarith) zero_le_two] simp [div_eq_inv_mul, ← Real.rpow_neg_one, ← Real.rpow_mul] ring rw [this] rcases le_total x 1 with h'x|h'x Β· gcongr Β· apply (pow_le_oneβ‚€ hx h'x).trans apply Real.one_le_rpow_of_pos_of_le_one_of_nonpos Β· linarith Β· linarith Β· simp Β· linarith Β· calc x ^ k * f = x ^ (-(l : ℝ)) * (x ^ (k + l) * f) := by rw [← Real.rpow_natCast, ← Real.rpow_natCast, ← mul_assoc, ← Real.rpow_add (by linarith)] simp _ ≀ ((1 + x) / 2) ^ (-(l : ℝ)) * (C₁ + Cβ‚‚) := by apply mul_le_mul _ _ (by positivity) (by positivity) Β· exact Real.rpow_le_rpow_of_nonpos (by linarith) (by linarith) (by simp) Β· exact hβ‚‚.trans (by linarith) variable [NormedAddCommGroup F] variable [BorelSpace E] [SecondCountableTopology E] in /-- Given a function such that `f` and `x ^ (k + l) * f` are bounded for a suitable `l`, then `x ^ k * f` is integrable. The bounds are not relevant for the integrability conclusion, but they are relevant for bounding the integral in `integral_pow_mul_le_of_le_of_pow_mul_le`. We formulate the two lemmas with the same set of assumptions for ease of applications. -/ lemma _root_.integrable_of_le_of_pow_mul_le {ΞΌ : Measure E} [ΞΌ.HasTemperateGrowth] {f : E β†’ F} {C₁ Cβ‚‚ : ℝ} {k : β„•} (hf : βˆ€ x, β€–f xβ€– ≀ C₁) (h'f : βˆ€ x, β€–xβ€– ^ (k + ΞΌ.integrablePower) * β€–f xβ€– ≀ Cβ‚‚) (h''f : AEStronglyMeasurable f ΞΌ) : Integrable (fun x ↦ β€–xβ€– ^ k * β€–f xβ€–) ΞΌ := by apply ((integrable_pow_neg_integrablePower ΞΌ).const_mul (2 ^ ΞΌ.integrablePower * (C₁ + Cβ‚‚))).mono' Β· exact AEStronglyMeasurable.mul (aestronglyMeasurable_id.norm.pow _) h''f.norm Β· filter_upwards with v simp only [norm_mul, norm_pow, norm_norm] apply pow_mul_le_of_le_of_pow_mul_le (norm_nonneg _) (norm_nonneg _) (hf v) (h'f v) /-- Given a function such that `f` and `x ^ (k + l) * f` are bounded for a suitable `l`, then one can bound explicitly the integral of `x ^ k * f`. -/ lemma _root_.integral_pow_mul_le_of_le_of_pow_mul_le {ΞΌ : Measure E} [ΞΌ.HasTemperateGrowth] {f : E β†’ F} {C₁ Cβ‚‚ : ℝ} {k : β„•} (hf : βˆ€ x, β€–f xβ€– ≀ C₁) (h'f : βˆ€ x, β€–xβ€– ^ (k + ΞΌ.integrablePower) * β€–f xβ€– ≀ Cβ‚‚) : ∫ x, β€–xβ€– ^ k * β€–f xβ€– βˆ‚ΞΌ ≀ 2 ^ ΞΌ.integrablePower * (∫ x, (1 + β€–xβ€–) ^ (- (ΞΌ.integrablePower : ℝ)) βˆ‚ΞΌ) * (C₁ + Cβ‚‚) := by rw [← integral_const_mul, ← integral_mul_const] apply integral_mono_of_nonneg Β· filter_upwards with v using by positivity Β· exact ((integrable_pow_neg_integrablePower ΞΌ).const_mul _).mul_const _ filter_upwards with v exact (pow_mul_le_of_le_of_pow_mul_le (norm_nonneg _) (norm_nonneg _) (hf v) (h'f v)).trans (le_of_eq (by ring)) /-- For any `HasTemperateGrowth` measure and `p`, there exists an integer power `k` such that `(1 + β€–xβ€–) ^ (-k)` is in `L^p`. -/ theorem HasTemperateGrowth.exists_eLpNorm_lt_top (p : ℝβ‰₯0∞) {ΞΌ : Measure E} (hΞΌ : ΞΌ.HasTemperateGrowth) : βˆƒ k : β„•, eLpNorm (fun x ↦ (1 + β€–xβ€–) ^ (-k : ℝ)) p ΞΌ < ⊀ := by cases p with | top => exact ⟨0, eLpNormEssSup_lt_top_of_ae_bound (C := 1) (by simp)⟩ | coe p => cases eq_or_ne (p : ℝβ‰₯0∞) 0 with | inl hp => exact ⟨0, by simp [hp]⟩ | inr hp => have h_one_add (x : E) : 0 < 1 + β€–xβ€– := lt_add_of_pos_of_le zero_lt_one (norm_nonneg x) have hp_pos : 0 < (p : ℝ) := by simpa [zero_lt_iff] using hp rcases hΞΌ.exists_integrable with ⟨l, hl⟩ let k := ⌈(l / p : ℝ)βŒ‰β‚Š have hlk : l ≀ k * (p : ℝ) := by simpa [div_le_iffβ‚€ hp_pos] using Nat.le_ceil (l / p : ℝ) use k suffices HasFiniteIntegral (fun x ↦ ((1 + β€–xβ€–) ^ (-(k * p) : ℝ))) ΞΌ by rw [hasFiniteIntegral_iff_enorm] at this rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top hp ENNReal.coe_ne_top] simp only [ENNReal.coe_toReal] refine Eq.subst (motive := (∫⁻ x, Β· x βˆ‚ΞΌ < ⊀)) (funext fun x ↦ ?_) this rw [← neg_mul, Real.rpow_mul (h_one_add x).le] exact Real.enorm_rpow_of_nonneg (by positivity) NNReal.zero_le_coe refine hl.hasFiniteIntegral.mono' (ae_of_all ΞΌ fun x ↦ ?_) rw [Real.norm_of_nonneg (Real.rpow_nonneg (h_one_add x).le _)] gcongr simp end MeasureTheory.Measure
.lake/packages/mathlib/Mathlib/Analysis/Convex/StoneSeparation.lean
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*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 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] linear_combination (au * bv - 1 * au) * habz + (-(1 * az * au) + au) * habv + az * av * habu 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 : Finset.univ.centerMass w z ∈ _) rw [Finset.centerMass, hw] trans (az * av + bz * au)⁻¹ β€’ ((az * av * bu) β€’ p + ((bz * au * bv) β€’ q + (au * av) β€’ (az β€’ x + bz β€’ y))) Β· module congr 3 simp [w, z] /-- **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, hsC, hmax⟩ := 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⟩ obtain hC : _ ∧ _ := hmax.prop 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 [hmax.eq_of_subset ⟨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]
.lake/packages/mathlib/Mathlib/Analysis/Convex/EGauge.lean
import Mathlib.Analysis.Seminorm import Mathlib.GroupTheory.GroupAction.Pointwise /-! # 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 Function 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 `ENorm` 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*) [ENorm π•œ] {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∞} lemma Set.MapsTo.egauge_le {E' F : Type*} [SMul π•œ E'] [FunLike F E E'] [MulActionHomClass F π•œ E E'] (f : F) {t : Set E'} (h : MapsTo f s t) (x : E) : egauge π•œ t (f x) ≀ egauge π•œ s x := iInf_mono fun c ↦ iInf_mono' fun hc ↦ ⟨h.smul_set c hc, le_rfl⟩ @[mono, gcongr] lemma egauge_anti (h : s βŠ† t) (x : E) : egauge π•œ t x ≀ egauge π•œ s x := MapsTo.egauge_le _ (MulActionHom.id ..) h _ @[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] lemma egauge_union (s t : Set E) (x : E) : egauge π•œ (s βˆͺ t) x = egauge π•œ s x βŠ“ egauge π•œ t x := by unfold egauge simp [smul_set_union, iInf_or, iInf_inf_eq] lemma le_egauge_inter (s t : Set E) (x : E) : egauge π•œ s x βŠ” egauge π•œ t x ≀ egauge π•œ (s ∩ t) x := max_le (egauge_anti _ inter_subset_left _) (egauge_anti _ inter_subset_right _) lemma le_egauge_pi {ΞΉ : Type*} {E : ΞΉ β†’ Type*} [βˆ€ i, SMul π•œ (E i)] {I : Set ΞΉ} {i : ΞΉ} (hi : i ∈ I) (s : βˆ€ i, Set (E i)) (x : βˆ€ i, E i) : egauge π•œ (s i) (x i) ≀ egauge π•œ (I.pi s) x := MapsTo.egauge_le _ (Pi.evalMulActionHom i) (fun x hx ↦ by exact hx i hi) _ variable {F : Type*} [SMul π•œ F] lemma le_egauge_prod (s : Set E) (t : Set F) (a : E) (b : F) : max (egauge π•œ s a) (egauge π•œ t b) ≀ egauge π•œ (s Γ—Λ’ t) (a, b) := max_le (mapsTo_fst_prod.egauge_le π•œ (MulActionHom.fst π•œ E F) (a, b)) (MapsTo.egauge_le π•œ (MulActionHom.snd π•œ E F) mapsTo_snd_prod (a, b)) end SMul section SMulZero variable (π•œ : Type*) [NNNorm π•œ] [Nonempty π•œ] {E : Type*} [Zero E] [SMulZeroClass π•œ E] {x : E} @[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 NormedDivisionRing variable {π•œ : Type*} [NormedDivisionRing π•œ] {E : Type*} [AddCommGroup E] [Module π•œ E] {c : π•œ} {s : Set E} {x : E} /-- If `c β€’ x ∈ s` and `c β‰  0`, then `egauge π•œ s x` is at most `(β€–cβ€–β‚Šβ»ΒΉ : ℝβ‰₯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‖ₑ⁻¹`. See also `egauge_le_of_smul_mem_of_ne`. -/ lemma egauge_le_of_smul_mem (h : c β€’ x ∈ s) : egauge π•œ s x ≀ β€–c‖ₑ⁻¹ := 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_smul_of_egauge_lt (hs : Balanced π•œ s) (hc : egauge π•œ s x < β€–cβ€–β‚‘) : x ∈ c β€’ s := let ⟨a, hxa, ha⟩ := egauge_lt_iff.1 hc hs.smul_mono (by simpa [enorm] using ha.le) hxa lemma mem_of_egauge_lt_one (hs : Balanced π•œ s) (hx : egauge π•œ s x < 1) : x ∈ s := one_smul π•œ s β–Έ mem_smul_of_egauge_lt hs (by simpa) lemma egauge_eq_zero_iff : egauge π•œ s x = 0 ↔ βˆƒαΆ  c : π•œ in 𝓝 0, x ∈ c β€’ s := by refine (iInfβ‚‚_eq_bot _).trans ?_ rw [(nhds_basis_uniformity uniformity_basis_edist).frequently_iff] simp [and_comm] @[simp] lemma egauge_univ [(𝓝[β‰ ] (0 : π•œ)).NeBot] : egauge π•œ univ x = 0 := by rw [egauge_eq_zero_iff] refine (frequently_iff_neBot.2 β€Ή_β€Ί).mono fun c hc ↦ ?_ simp_all [smul_set_univβ‚€] 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 lemma egauge_zero_zero : egauge π•œ (0 : Set E) 0 = 0 := by simp 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 [← enorm_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 [enorm_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 enorm_ne_top), ENNReal.div_eq_inv_mul, ← enorm_inv (by simpa)] refine (le_egauge_smul_right _ _ _).trans_eq ?_ rw [inv_smul_smulβ‚€ hc] /-- The extended gauge of a point `(a, b)` with respect to the product of balanced sets `U` and `V` is equal to the maximum of the extended gauges of `a` with respect to `U` and `b` with respect to `V`. -/ theorem egauge_prod_mk {F : Type*} [AddCommGroup F] [Module π•œ F] {U : Set E} {V : Set F} (hU : Balanced π•œ U) (hV : Balanced π•œ V) (a : E) (b : F) : egauge π•œ (U Γ—Λ’ V) (a, b) = max (egauge π•œ U a) (egauge π•œ V b) := by refine le_antisymm (le_of_forall_gt fun r hr ↦ ?_) (le_egauge_prod _ _ _ _) simp only [max_lt_iff, egauge_lt_iff, smul_set_prod] at hr ⊒ rcases hr with ⟨⟨x, hx, hxr⟩, ⟨y, hy, hyr⟩⟩ cases le_total β€–xβ€– β€–yβ€– with | inl hle => exact ⟨y, ⟨hU.smul_mono hle hx, hy⟩, hyr⟩ | inr hle => exact ⟨x, ⟨hx, hV.smul_mono hle hy⟩, hxr⟩ theorem egauge_add_add_le {U V : Set E} (hU : Balanced π•œ U) (hV : Balanced π•œ V) (a b : E) : egauge π•œ (U + V) (a + b) ≀ max (egauge π•œ U a) (egauge π•œ V b) := by rw [← egauge_prod_mk hU hV a b, ← add_image_prod] exact MapsTo.egauge_le π•œ (LinearMap.fst π•œ E E + LinearMap.snd π•œ E E) (mapsTo_image _ _) (a, b) end NormedDivisionRing section Pi variable {π•œ : Type*} {ΞΉ : Type*} {E : ΞΉ β†’ Type*} variable [NormedDivisionRing π•œ] [βˆ€ i, AddCommGroup (E i)] [βˆ€ i, Module π•œ (E i)] /-- The extended gauge of a point `x` in an indexed product with respect to a product of finitely many balanced sets `U i`, `i ∈ I`, (and the whole spaces for the other indices) is the supremum of the extended gauges of the components of `x` with respect to the corresponding balanced set. This version assumes the following technical condition: - either `I` is the universal set; - or one of `x i`, `i ∈ I`, is nonzero; - or `π•œ` is nontrivially normed. -/ theorem egauge_pi' {I : Set ΞΉ} (hI : I.Finite) {U : βˆ€ i, Set (E i)} (hU : βˆ€ i ∈ I, Balanced π•œ (U i)) (x : βˆ€ i, E i) (hIβ‚€ : I = univ ∨ (βˆƒ i ∈ I, x i β‰  0) ∨ (𝓝[β‰ ] (0 : π•œ)).NeBot) : egauge π•œ (I.pi U) x = ⨆ i ∈ I, egauge π•œ (U i) (x i) := by refine le_antisymm ?_ (iSupβ‚‚_le fun i hi ↦ le_egauge_pi hi _ _) refine le_of_forall_gt fun r hr ↦ ?_ have : βˆ€ i ∈ I, βˆƒ c : π•œ, x i ∈ c β€’ U i ∧ β€–cβ€–β‚‘ < r := fun i hi ↦ egauge_lt_iff.mp <| (le_iSupβ‚‚ i hi).trans_lt hr choose! c hc hcr using this obtain ⟨cβ‚€, hcβ‚€, hcβ‚€I, hcβ‚€r⟩ : βˆƒ cβ‚€ : π•œ, (cβ‚€ β‰  0 ∨ I = univ) ∧ (βˆ€ i ∈ I, β€–c iβ€– ≀ β€–cβ‚€β€–) ∧ β€–cβ‚€β€–β‚‘ < r := by have hrβ‚€ : 0 < r := hr.bot_lt rcases I.eq_empty_or_nonempty with rfl | hIne Β· obtain hΞΉ | hbot : IsEmpty ΞΉ ∨ (𝓝[β‰ ] (0 : π•œ)).NeBot := by simpa [@eq_comm _ βˆ…] using hIβ‚€ Β· use 0 simp [@eq_comm _ βˆ…, hΞΉ, hrβ‚€] Β· rcases exists_enorm_lt π•œ hrβ‚€.ne' with ⟨cβ‚€, hcβ‚€, hcβ‚€r⟩ exact ⟨cβ‚€, .inl hcβ‚€, by simp, hcβ‚€r⟩ Β· obtain ⟨iβ‚€, hiβ‚€I, hc_max⟩ : βˆƒ iβ‚€ ∈ I, IsMaxOn (β€–c Β·β€–β‚‘) I iβ‚€ := exists_max_image _ (β€–c Β·β€–β‚‘) hI hIne by_cases! H : c iβ‚€ β‰  0 ∨ I = univ Β· exact ⟨c iβ‚€, H, fun i hi ↦ by simpa [enorm] using hc_max hi, hcr _ hiβ‚€I⟩ Β· have hc0 (i : ΞΉ) (hi : i ∈ I) : c i = 0 := by simpa [H] using hc_max hi have heg0 (i : ΞΉ) (hi : i ∈ I) : x i = 0 := zero_smul_set_subset (Ξ± := π•œ) (U i) (hc0 i hi β–Έ hc i hi) have : (𝓝[β‰ ] (0 : π•œ)).NeBot := (hIβ‚€.resolve_left H.2).resolve_left (by simpa) rcases exists_enorm_lt π•œ hrβ‚€.ne' with ⟨c₁, hc₁, hc₁r⟩ refine ⟨c₁, .inl hc₁, fun i hi ↦ ?_, hc₁r⟩ simp [hc0 i hi] refine egauge_lt_iff.2 ⟨cβ‚€, ?_, hcβ‚€r⟩ rw [smul_set_piβ‚€' hcβ‚€] intro i hi exact (hU i hi).smul_mono (hcβ‚€I i hi) (hc i hi) /-- The extended gauge of a point `x` in an indexed product with finite index type with respect to a product of balanced sets `U i`, is the supremum of the extended gauges of the components of `x` with respect to the corresponding balanced set. -/ theorem egauge_univ_pi [Finite ΞΉ] {U : βˆ€ i, Set (E i)} (hU : βˆ€ i, Balanced π•œ (U i)) (x : βˆ€ i, E i) : egauge π•œ (univ.pi U) x = ⨆ i, egauge π•œ (U i) (x i) := egauge_pi' finite_univ (fun i _ ↦ hU i) x (.inl rfl) |>.trans <| by simp /-- The extended gauge of a point `x` in an indexed product with respect to a product of finitely many balanced sets `U i`, `i ∈ I`, (and the whole spaces for the other indices) is the supremum of the extended gauges of the components of `x` with respect to the corresponding balanced set. This version assumes that `π•œ` is a nontrivially normed division ring. See also `egauge_univ_pi` for when `s = univ`, and `egauge_pi'` for a version with more choices of the technical assumptions. -/ theorem egauge_pi [(𝓝[β‰ ] (0 : π•œ)).NeBot] {I : Set ΞΉ} {U : βˆ€ i, Set (E i)} (hI : I.Finite) (hU : βˆ€ i ∈ I, Balanced π•œ (U i)) (x : βˆ€ i, E i) : egauge π•œ (I.pi U) x = ⨆ i ∈ I, egauge π•œ (U i) (x i) := egauge_pi' hI hU x <| .inr <| .inr inferInstance end Pi section SeminormedAddCommGroup variable (π•œ : Type*) [NormedField π•œ] {E : Type*} [SeminormedAddCommGroup E] [NormedSpace π•œ 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 rw [enorm_smul] apply ENNReal.div_le_of_le_mul gcongr rwa [enorm_le_coe] 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 variable {π•œ} variable {c : π•œ} {x : 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 letI : NontriviallyNormedField π•œ := ⟨c, hc⟩ 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 [enorm, ← NNReal.coe_eq_zero] using hβ‚€ Β· rcases eq_or_ne β€–xβ€– 0 with hx | hx Β· have hx' : β€–xβ€–β‚‘ = 0 := by simpa [enorm, ← coe_nnnorm, NNReal.coe_eq_zero] using hx simp only [hx', mul_zero, ENNReal.zero_div, nonpos_iff_eq_zero, egauge_eq_zero_iff] refine (frequently_iff_neBot.2 (inferInstance : NeBot (𝓝[β‰ ] (0 : π•œ)))).mono fun c hc ↦ ?_ simp [mem_smul_set_iff_inv_smul_memβ‚€ hc, norm_smul, hx, hr] Β· rcases rescale_to_shell_semi_normed 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 simp [ENNReal.coe_mul, enorm] 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Side.lean
import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := βˆƒα΅‰ (p₁ ∈ s) (pβ‚‚ ∈ s), SameRay R (x -α΅₯ p₁) (y -α΅₯ pβ‚‚) /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x βˆ‰ s ∧ y βˆ‰ s /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := βˆƒα΅‰ (p₁ ∈ s) (pβ‚‚ ∈ s), SameRay R (x -α΅₯ p₁) (pβ‚‚ -α΅₯ y) /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x βˆ‰ s ∧ y βˆ‰ s theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᡃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f pβ‚‚, mem_map_of_mem f hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fpβ‚‚, hfpβ‚‚, h⟩ rw [mem_map] at hfp₁ hfpβ‚‚ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfpβ‚‚ with ⟨pβ‚‚, hpβ‚‚, rfl⟩ refine ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᡃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᡃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᡃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f pβ‚‚, mem_map_of_mem f hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fpβ‚‚, hfpβ‚‚, h⟩ rw [mem_map] at hfp₁ hfpβ‚‚ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfpβ‚‚ with ⟨pβ‚‚, hpβ‚‚, rfl⟩ refine ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, ?_⟩ 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_notMem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x βˆ‰ s := h.2.1 @[deprecated (since := "2025-05-23")] alias SSameSide.left_not_mem := SSameSide.left_notMem theorem SSameSide.right_notMem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y βˆ‰ s := h.2.2 @[deprecated (since := "2025-05-23")] alias SSameSide.right_not_mem := SSameSide.right_notMem theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 theorem SOppSide.left_notMem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x βˆ‰ s := h.2.1 @[deprecated (since := "2025-05-23")] alias SOppSide.left_not_mem := SOppSide.left_notMem theorem SOppSide.right_notMem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y βˆ‰ s := h.2.2 @[deprecated (since := "2025-05-23")] alias SOppSide.right_not_mem := SOppSide.right_notMem 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 Β· simp rcases ht0.lt_or_eq with (ht0' | rfl); swap Β· simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) rw [lineMap_apply, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← neg_vsub_eq_vsub_rev z, vsub_self] module 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 [Field R] [LinearOrder R] [IsStrictOrderedRing R] [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, ← vsub_sub_vsub_cancel_right x p₁ p₁'] linear_combination (norm := match_scalars <;> field) hr Β· 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 [← neg_vsub_eq_vsub_rev pβ‚‚ y] linear_combination (norm := match_scalars <;> field) (r₁ + rβ‚‚)⁻¹ β€’ h 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 _ ⟨by positivity, 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_notMem_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 @[deprecated (since := "2025-05-23")] alias _root_.Sbtw.sOppSide_of_not_mem_of_mem := _root_.Sbtw.sOppSide_of_notMem_of_mem 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_notMem_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, and_false] 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, and_false] exact isPreconnected_empty Β· exact (isConnected_setOf_sOppSide hx h).isPreconnected end Normed end AffineSubspace
.lake/packages/mathlib/Mathlib/Analysis/Convex/Birkhoff.lean
import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.Extreme import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Combinatorics.Hall.Basic import Mathlib.Analysis.Convex.DoublyStochasticMatrix import Mathlib.Tactic.Linarith /-! # Birkhoff's theorem ## Main statements * `doublyStochastic_eq_sum_perm`: If `M` is a doubly stochastic matrix, then it is a convex combination of permutation matrices. * `doublyStochastic_eq_convexHull_perm`: The set of doubly stochastic matrices is the convex hull of the permutation matrices. * `extremePoints_doublyStochastic`: The set of extreme points of the doubly stochastic matrices is the set of permutation matrices. ## TODO * Show that for `x y : n β†’ R`, `x` is majorized by `y` if and only if there is a doubly stochastic matrix `M` such that `M *α΅₯ y = x`. ## Tags Doubly stochastic, Birkhoff's theorem, Birkhoff-von Neumann theorem -/ open Finset Function Matrix variable {R n : Type*} [Fintype n] [DecidableEq n] section LinearOrderedSemifield variable [Semifield R] [LinearOrder R] [IsStrictOrderedRing R] {M : Matrix n n R} /-- If M is a positive scalar multiple of a doubly stochastic matrix, then there is a permutation matrix whose support is contained in the support of M. -/ private lemma exists_perm_eq_zero_implies_eq_zero [Nonempty n] {s : R} (hs : 0 < s) (hM : βˆƒ M' ∈ doublyStochastic R n, M = s β€’ M') : βˆƒ Οƒ : Equiv.Perm n, βˆ€ i j, M i j = 0 β†’ Οƒ.permMatrix R i j = 0 := by rw [exists_mem_doublyStochastic_eq_smul_iff hs.le] at hM let f (i : n) : Finset n := {j | M i j β‰  0} have hf (A : Finset n) : #A ≀ #(A.biUnion f) := by have (i : _) : βˆ‘ j ∈ f i, M i j = s := by simp [f, sum_subset (filter_subset _ _), hM.2.1] have h₁ : βˆ‘ i ∈ A, βˆ‘ j ∈ f i, M i j = #A * s := by simp [this] have hβ‚‚ : βˆ‘ i, βˆ‘ j ∈ A.biUnion f, M i j = #(A.biUnion f) * s := by simp [sum_comm (t := A.biUnion f), hM.2.2] suffices #A * s ≀ #(A.biUnion f) * s by exact_mod_cast le_of_mul_le_mul_right this hs rw [← h₁, ← hβ‚‚] trans βˆ‘ i ∈ A, βˆ‘ j ∈ A.biUnion f, M i j Β· refine sum_le_sum fun i hi => ?_ exact sum_le_sum_of_subset_of_nonneg (subset_biUnion_of_mem f hi) (by simp [*]) Β· exact sum_le_sum_of_subset_of_nonneg (by simp) fun _ _ _ => sum_nonneg fun j _ => hM.1 _ _ obtain ⟨g, hg, hg'⟩ := (all_card_le_biUnion_card_iff_exists_injective f).1 hf rw [Finite.injective_iff_bijective] at hg refine ⟨Equiv.ofBijective g hg, fun i j hij => ?_⟩ simp only [PEquiv.toMatrix_apply, Option.mem_def, ite_eq_right_iff, one_ne_zero, imp_false, Equiv.toPEquiv_apply, Equiv.ofBijective_apply, Option.some.injEq] rintro rfl simpa [f, hij] using hg' i end LinearOrderedSemifield section LinearOrderedField variable [Field R] [LinearOrder R] [IsStrictOrderedRing R] {M : Matrix n n R} /-- If M is a scalar multiple of a doubly stochastic matrix, then it is a conical combination of permutation matrices. This is most useful when M is a doubly stochastic matrix, in which case the combination is convex. This particular formulation is chosen to make the inductive step easier: we no longer need to rescale each time a permutation matrix is subtracted. -/ private lemma doublyStochastic_sum_perm_aux (M : Matrix n n R) (s : R) (hs : 0 ≀ s) (hM : βˆƒ M' ∈ doublyStochastic R n, M = s β€’ M') : βˆƒ w : Equiv.Perm n β†’ R, (βˆ€ Οƒ, 0 ≀ w Οƒ) ∧ βˆ‘ Οƒ, w Οƒ β€’ Οƒ.permMatrix R = M := by rcases isEmpty_or_nonempty n case inl => exact ⟨1, by simp, Subsingleton.elim _ _⟩ set d : β„• := #{i : n Γ— n | M i.1 i.2 β‰  0} with ← hd clear_value d induction d using Nat.strongRecOn generalizing M s case ind d ih => rcases eq_or_lt_of_le hs with rfl | hs' case inl => use 0 simp only [zero_smul, exists_and_right] at hM simp [hM] obtain βŸ¨Οƒ, hΟƒβŸ© := exists_perm_eq_zero_implies_eq_zero hs' hM obtain ⟨i, hi, hi'⟩ := exists_min_image _ (fun i => M i (Οƒ i)) univ_nonempty rw [exists_mem_doublyStochastic_eq_smul_iff hs] at hM let N : Matrix n n R := M - M i (Οƒ i) β€’ Οƒ.permMatrix R have hMi' : 0 < M i (Οƒ i) := (hM.1 _ _).lt_of_ne' fun h => by simpa [Equiv.toPEquiv_apply] using hΟƒ _ _ h let s' : R := s - M i (Οƒ i) have hs' : 0 ≀ s' := by simp only [s', sub_nonneg, ← hM.2.1 i] exact single_le_sum (fun j _ => hM.1 i j) (by simp) have : βˆƒ M' ∈ doublyStochastic R n, N = s' β€’ M' := by rw [exists_mem_doublyStochastic_eq_smul_iff hs'] simp only [sub_apply, smul_apply, PEquiv.toMatrix_apply, Equiv.toPEquiv_apply, Option.mem_def, Option.some.injEq, smul_eq_mul, mul_ite, mul_one, mul_zero, sub_nonneg, sum_sub_distrib, sum_ite_eq, mem_univ, ↓reduceIte, N] refine ⟨fun i' j => ?_, by simp [s', hM.2.1], by simp [s', ← Οƒ.eq_symm_apply, hM]⟩ split case isTrue h => exact (hi' i' (by simp)).trans_eq (by rw [h]) case isFalse h => exact hM.1 _ _ have hd' : #{i : n Γ— n | N i.1 i.2 β‰  0} < d := by rw [← hd] gcongr rw [ssubset_iff_of_subset (monotone_filter_right _ _)] Β· simp_rw [mem_filter_univ, not_not, Prod.exists] refine ⟨i, Οƒ i, hMi'.ne', ?_⟩ simp [N, Equiv.toPEquiv_apply] Β· rintro ⟨i', j'⟩ _ hN' hM' dsimp at hN' hM' simp only [sub_apply, hM', smul_apply, PEquiv.toMatrix_apply, Equiv.toPEquiv_apply, Option.mem_def, Option.some.injEq, smul_eq_mul, mul_ite, mul_one, mul_zero, zero_sub, neg_eq_zero, ite_eq_right_iff, Classical.not_imp, N] at hN' obtain ⟨rfl, _⟩ := hN' linarith [hi' i' (by simp)] obtain ⟨w, hw, hw'⟩ := ih _ hd' _ s' hs' this rfl refine ⟨w + fun Οƒ' => if Οƒ' = Οƒ then M i (Οƒ i) else 0, ?_⟩ simp only [Pi.add_apply, add_smul, sum_add_distrib, hw', ite_smul, zero_smul, sum_ite_eq', mem_univ, ↓reduceIte, N, sub_add_cancel, and_true] intro Οƒ' split <;> simp [add_nonneg, hw, hM.1] /-- If M is a doubly stochastic matrix, then it is an convex combination of permutation matrices. Note `doublyStochastic_eq_convexHull_permMatrix` shows `doublyStochastic n` is exactly the convex hull of the permutation matrices, and this lemma is instead most useful for accessing the coefficients of each permutation matrices directly. -/ lemma exists_eq_sum_perm_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) : βˆƒ w : Equiv.Perm n β†’ R, (βˆ€ Οƒ, 0 ≀ w Οƒ) ∧ βˆ‘ Οƒ, w Οƒ = 1 ∧ βˆ‘ Οƒ, w Οƒ β€’ Οƒ.permMatrix R = M := by rcases isEmpty_or_nonempty n case inl => exact ⟨fun _ => 1, by simp, by simp, Subsingleton.elim _ _⟩ obtain ⟨w, hw1, hw3⟩ := doublyStochastic_sum_perm_aux M 1 (by simp) ⟨M, hM, by simp⟩ refine ⟨w, hw1, ?_, hw3⟩ inhabit n have : βˆ‘ j, βˆ‘ Οƒ : Equiv.Perm n, w Οƒ β€’ Οƒ.permMatrix R default j = 1 := by simp only [← smul_apply (m := n), ← Finset.sum_apply, hw3] rw [sum_row_of_mem_doublyStochastic hM] simpa [sum_comm (Ξ³ := n), Equiv.toPEquiv_apply] using this /-- **Birkhoff's theorem** The set of doubly stochastic matrices is the convex hull of the permutation matrices. Note `exists_eq_sum_perm_of_mem_doublyStochastic` gives a convex weighting of each permutation matrix directly. To show `doublyStochastic n` is convex, use `convex_doublyStochastic`. -/ theorem doublyStochastic_eq_convexHull_permMatrix : doublyStochastic R n = convexHull R {Οƒ.permMatrix R | Οƒ : Equiv.Perm n} := by refine (convexHull_min ?g1 convex_doublyStochastic).antisymm' fun M hM => ?g2 case g1 => rintro x ⟨h, rfl⟩ exact permMatrix_mem_doublyStochastic case g2 => obtain ⟨w, hw1, hw2, hw3⟩ := exists_eq_sum_perm_of_mem_doublyStochastic hM exact mem_convexHull_of_exists_fintype w (Β·.permMatrix R) hw1 hw2 (by simp) hw3 /-- The set of extreme points of the doubly stochastic matrices is the set of permutation matrices. -/ theorem extremePoints_doublyStochastic : Set.extremePoints R (doublyStochastic R n) = {Οƒ.permMatrix R | Οƒ : Equiv.Perm n} := by refine subset_antisymm ?_ ?_ Β· rw [doublyStochastic_eq_convexHull_permMatrix] exact extremePoints_convexHull_subset rintro _ βŸ¨Οƒ, rfl⟩ refine ⟨permMatrix_mem_doublyStochastic, fun x₁ hx₁ xβ‚‚ hxβ‚‚ hΟƒ ↦ ?_⟩ suffices βˆ€ i j : n, x₁ i j = xβ‚‚ i j by obtain rfl : x₁ = xβ‚‚ := by simpa [← Matrix.ext_iff] simp_all intro i j have h₁ : Οƒ.permMatrix R i j ∈ openSegment R (x₁ i j) (xβ‚‚ i j) := image_openSegment _ (entryLinearMap R R i j).toAffineMap x₁ xβ‚‚ β–Έ ⟨_, hΟƒ, rfl⟩ by_contra! h have hβ‚‚ : openSegment R (x₁ i j) (xβ‚‚ i j) βŠ† Set.Ioo 0 1 := by rw [openSegment_eq_Ioo' h] apply Set.Ioo_subset_Ioo <;> simp_all [nonneg_of_mem_doublyStochastic, le_one_of_mem_doublyStochastic] specialize hβ‚‚ h₁ aesop end LinearOrderedField open scoped Matrix.Norms.L2Operator theorem Matrix.l2_opNorm_le_one_of_mem_doublyStochastic {M : Matrix n n ℝ} (hM : M ∈ doublyStochastic ℝ n) : β€–Mβ€– ≀ 1 := by rw [← SetLike.mem_coe, doublyStochastic_eq_convexHull_permMatrix] at hM have ⟨_, βŸ¨Οƒ, rfl⟩, hΟƒβŸ© := convexOn_univ_norm.exists_ge_of_mem_convexHull (by simp) hM exact hΟƒ.trans (permMatrix_l2_opNorm_le _)
.lake/packages/mathlib/Mathlib/Analysis/Convex/Caratheodory.lean
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} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 := {z ∈ t | 0 < g z} 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 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 (notMem_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] 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, 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} /-- 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 (hx : x ∈ convexHull π•œ s) : Finset E := Function.argminOn Finset.card { t | ↑t βŠ† s ∧ x ∈ convexHull π•œ (t : Set E) } <| by simpa only [convexHull_eq_union_convexHull_finite_subsets s, exists_prop, mem_iUnion] using hx variable (hx : x ∈ convexHull π•œ s) 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) ≀ #t := Function.argminOn_le _ _ (by exact ⟨ht₁, htβ‚‚βŸ©) theorem affineIndependent_minCardFinsetOfMemConvexHull : AffineIndependent π•œ ((↑) : minCardFinsetOfMemConvexHull hx β†’ E) := by let k := #(minCardFinsetOfMemConvexHull hx) - 1 have hk : #(minCardFinsetOfMemConvexHull hx) = 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 rw [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) (_ : ↑t βŠ† s) (_ : 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, Set.mem_setOf_eq] at ht₃ obtain ⟨w, hw₁, hwβ‚‚, hwβ‚ƒβŸ© := ht₃ let t' := {i ∈ t | 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 Β· simp only [univ_eq_attach, Function.comp_apply] rw [Finset.sum_attach, Finset.sum_filter_ne_zero, hwβ‚‚] Β· change (βˆ‘ i ∈ t'.attach, (fun e => w e β€’ e) ↑i) = x rw [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]
.lake/packages/mathlib/Mathlib/Analysis/Convex/GaugeRescale.lean
import Mathlib.Analysis.Convex.Gauge import Mathlib.Analysis.Normed.Module.Convex /-! # "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] 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_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 variable [TopologicalSpace E] section variable [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} (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 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 end variable [IsTopologicalAddGroup 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 variable [T1Space E] 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, Function.comp_def, 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 _ _ _)
.lake/packages/mathlib/Mathlib/Analysis/Convex/TotallyBounded.lean
import Mathlib.Topology.UniformSpace.Cauchy import Mathlib.Analysis.Convex.Hull import Mathlib.Topology.Algebra.IsUniformGroup.Basic import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Totally Bounded sets and Convex Hulls ## Main statements - `totallyBounded_convexHull`: The convex hull of a totally bounded set is totally bounded. ## References * [Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## Tags convex, totally bounded -/ open Set Pointwise variable (E : Type*) {s : Set E} variable [AddCommGroup E] [Module ℝ E] variable [UniformSpace E] [IsUniformAddGroup E] [lcs : LocallyConvexSpace ℝ E] [ContinuousSMul ℝ E] theorem totallyBounded_convexHull (hs : TotallyBounded s) : TotallyBounded (convexHull ℝ s) := by rw [totallyBounded_iff_subset_finite_iUnion_nhds_zero] intro U hU obtain ⟨W, hW₁, hWβ‚‚βŸ© := exists_nhds_zero_half hU obtain ⟨V, ⟨hV₁, hVβ‚‚, hVβ‚ƒβŸ©βŸ© := (locallyConvexSpace_iff_exists_convex_subset_zero ℝ E).mp lcs W hW₁ obtain ⟨t, ⟨htf, hts⟩⟩ := (totallyBounded_iff_subset_finite_iUnion_nhds_zero.mp hs) _ hV₁ obtain ⟨t', ⟨htf', hts'⟩⟩ := (totallyBounded_iff_subset_finite_iUnion_nhds_zero.mp (IsCompact.totallyBounded (Finite.isCompact_convexHull htf)) _ hV₁) use t', htf' simp only [iUnion_vadd_set, vadd_eq_add] at hts hts' ⊒ calc convexHull ℝ s _ βŠ† convexHull ℝ (t + V) := convexHull_mono hts _ βŠ† convexHull ℝ t + convexHull ℝ V := convexHull_add_subset _ = convexHull ℝ t + V := by rw [hVβ‚‚.convexHull_eq] _ βŠ† t' + V + V := add_subset_add_right hts' _ = t' + (V + V) := by rw [add_assoc] _ βŠ† t' + (W + W) := add_subset_add_left (add_subset_add hV₃ hV₃) _ βŠ† t' + U := add_subset_add_left (add_subset_iff.mpr hWβ‚‚)
.lake/packages/mathlib/Mathlib/Analysis/Convex/Radon.lean
import Mathlib.Analysis.Convex.Combination import Mathlib.Data.Set.Card import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Topology.Separation.Hausdorff /-! # 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 intersects nontrivially. For the infinite family of sets it is not true, as the 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*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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. In particular, any `d + 2` points in a `d`-dimensional space can be partitioned this way, since they are affinely dependent (see `finrank_vectorSpan_le_iff_not_affineIndependent`). -/ 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 ΞΉ := {i ∈ s | 0 ≀ w i} let J : Finset ΞΉ := {i ∈ s | 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_gt (mem_filter.mp hi).2 open Module omit [LinearOrder π•œ] [IsStrictOrderedRing π•œ] in /-- Corner case for `helly_theorem'`. -/ private lemma helly_theorem_corner {F : ΞΉ β†’ Set E} {s : Finset ΞΉ} (h_card_small : #s ≀ finrank π•œ E + 1) (h_inter : βˆ€ I βŠ† s, #I ≀ 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 ≀ finrank π•œ E + 1 β†’ (β‹‚ i ∈ I, F i).Nonempty) : (β‹‚ i ∈ s, F i).Nonempty := by classical obtain h_card | h_card := lt_or_ge #s (finrank π•œ E + 1) Β· exact helly_theorem_corner (le_of_lt h_card) h_inter generalize hn : #s = n rw [hn] at h_card induction n, h_card using Nat.le_induction generalizing ΞΉ with | base => 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`. -/ | succ k h_card hk => 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]; cutsat /- 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]; cutsat /- 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) (h_convex : βˆ€ i ∈ s, Convex π•œ (F i)) (h_inter : βˆ€ I βŠ† s, #I = 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 ≀ 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) (h_convex : βˆ€ X ∈ F, Convex π•œ X) (h_inter : βˆ€ G : Finset (Set E), G βŠ† F β†’ #G = 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 cutsat) /-- **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 ≀ finrank π•œ E + 1 β†’ (β‹‚ i ∈ I, F i).Nonempty) : (β‹‚ i, F i).Nonempty := by classical /- If `ΞΉ` is empty the statement is trivial. -/ rcases 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 ≀ ENat.card ΞΉ) (h_convex : βˆ€ i, Convex π•œ (F i)) (h_compact : βˆ€ i, IsCompact (F i)) (h_inter : βˆ€ I : Finset ΞΉ, #I = 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 = 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 [ENat.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 ≀ 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 = 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Quasiconvex.lean
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 Ξ² : Type*} section OrderedSemiring variable [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] 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 (Ξ² := Ξ²α΅’α΅ˆ) 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 : 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 (Ξ² := Ξ²α΅’α΅ˆ) 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 PosSMulMono variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π•œ E] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] {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 PosSMulMono section LinearOrder variable [LinearOrder E] [IsOrderedAddMonoid E] [PartialOrder Ξ²] [Module π•œ E] [PosSMulMono π•œ 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 LinearOrder end OrderedSemiring section LinearOrderedField variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] {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 [LinearOrder Ξ²] (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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Uniform.lean
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_gt β€–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_gt β€–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)).2 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 - Ξ΄ + Ξ΄' + Ξ΄' := by gcongr exacts [h (h₁ _ hx') (h₁ _ hy') hxy', hβ‚‚ _ hx hx'.le, hβ‚‚ _ hy hy'.le] _ ≀ 2 - Ξ΄' := by suffices Ξ΄' ≀ Ξ΄ / 3 by linarith 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_gt r 0 Β· exact ⟨1, one_pos, fun x hx y hy h => (hΞ΅.not_ge <| 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_iff_of_pos_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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Integral.lean
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 : Type*} {m0 : MeasurableSpace Ξ±} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {ΞΌ : 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 Β· simp_rw [measureReal_def] rw [← ENNReal.toReal_sum, (G n).sum_range_measure_preimage_singleton, measure_univ, ENNReal.toReal_one] finiteness Β· 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 := hs.integral_mem hsc (ae_mono' smul_absolutelyContinuous hfs) hfi.to_average /-- 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.prodMk 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, measureReal_def, hβ‚€, ENNReal.toReal_zero, zero_smul] by_cases hβ‚€' : ΞΌ tᢜ = 0 Β· rw [← ae_eq_univ] at hβ‚€' rw [restrict_congr_set hβ‚€', restrict_univ, measureReal_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 _ (by finiteness)] /-- 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 (by finiteness)] 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' (by finiteness) (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 (by finiteness) (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 (by finiteness) (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.prodMk 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] 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) βˆ‚ΞΌ := by gcongr exacts [(this hβ‚€).2, (this hβ‚€').2] /-- **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_gt 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] rcases (le_top : ΞΌ univ ≀ ∞).eq_or_lt with hΞΌt | hΞΌt Β· simp [average_eq, measureReal_def, 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_closedBall 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 `ΞΌ.real univ * 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 βˆ‚ΞΌβ€– < ΞΌ.real univ * C := by rcases eq_or_ne ΞΌ 0 with hβ‚€ | hβ‚€; Β· simp [hβ‚€, EventuallyEq] have hΞΌ : 0 < ΞΌ.real univ := by simp [measureReal_def, 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 `ΞΌ.real t * 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 βˆ‚ΞΌβ€– < ΞΌ.real t * C := by haveI := Fact.mk ht.lt_top rw [← measureReal_restrict_apply_univ] exact ae_eq_const_or_norm_integral_lt_of_norm_le_const h_le
.lake/packages/mathlib/Mathlib/Analysis/Convex/Body.lean
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, e.g. `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 simp] apply convex_iff_forall_pos.mp K.convex hx (h_symm x hx) all_goals linarith section ContinuousAdd instance : Zero (ConvexBody V) where zero := ⟨0, convex_singleton 0, isCompact_singleton, Set.singleton_nonempty 0⟩ @[simp, norm_cast] theorem coe_zero : (↑(0 : ConvexBody V) : Set V) = 0 := rfl instance : Inhabited (ConvexBody V) := ⟨0⟩ 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 : SMul β„• (ConvexBody V) where smul := nsmulRec @[simp, norm_cast] 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 noncomputable instance : AddMonoid (ConvexBody V) := SetLike.coe_injective.addMonoid _ rfl (fun _ _ ↦ rfl) fun _ _ ↦ coe_nsmul _ _ @[simp, norm_cast] theorem coe_add (K L : ConvexBody V) : (↑(K + L) : Set V) = (K : Set V) + L := rfl noncomputable 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, norm_cast] theorem coe_smul (c : ℝ) (K : ConvexBody V) : (↑(c β€’ K) : Set V) = c β€’ (K : Set V) := rfl variable [ContinuousAdd V] noncomputable instance : DistribMulAction ℝ (ConvexBody V) := SetLike.coe_injective.distribMulAction ⟨⟨_, coe_zero⟩, coe_add⟩ coe_smul @[simp, norm_cast] 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. -/ noncomputable 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'] obtain rfl | ha := eq_zero_or_pos a Β· rw [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.ne', smul_smul] refine Convex.mem_smul_of_zero_mem K.convex h_zero hy (?_ : 1 ≀ a⁻¹ * b) rwa [le_inv_mul_iffβ‚€ ha, mul_one] 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 _ _ _ := 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 [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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Piecewise.lean
import Mathlib.Analysis.Convex.Function /-! # Convex and concave piecewise functions This file proves convex and concave theorems for piecewise functions. ## Main statements * `convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici` is the proof that the piecewise function `(Set.Iic e).piecewise f g` of a function `f` decreasing and convex on `Set.Iic e` and a function `g` increasing and convex on `Set.Ici e`, such that `f e = g e`, is convex on the universal set. This version has the boundary point included in the left-hand function. See `convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic` for the version with the boundary point included in the right-hand function. See concave version(s) `concaveOn_univ_piecewise_Iic_of_monotoneOn_Iic_antitoneOn_Ici` and `concaveOn_univ_piecewise_Ici_of_antitoneOn_Ici_monotoneOn_Iic`. -/ variable {π•œ E Ξ² : Type*} [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [PosSMulMono π•œ E] [AddCommGroup Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] {e : E} {f g : E β†’ Ξ²} /-- The piecewise function `(Set.Iic e).piecewise f g` of a function `f` decreasing and convex on `Set.Iic e` and a function `g` increasing and convex on `Set.Ici e`, such that `f e = g e`, is convex on the universal set. -/ theorem convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici (hf : ConvexOn π•œ (Set.Iic e) f) (hg : ConvexOn π•œ (Set.Ici e) g) (h_anti : AntitoneOn f (Set.Iic e)) (h_mono : MonotoneOn g (Set.Ici e)) (h_eq : f e = g e) : ConvexOn π•œ Set.univ ((Set.Iic e).piecewise f g) := by refine ⟨convex_univ, fun x _ y _ a b ha hb hab ↦ ?_⟩ obtain hx | hx := le_or_gt x e <;> obtain hy | hy := le_or_gt y e Β· have hc : a β€’ x + b β€’ y ≀ e := (Convex.combo_le_max x y ha hb hab).trans (max_le hx hy) rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hx, Set.piecewise_eq_of_mem (Set.Iic e) f g hy, Set.piecewise_eq_of_mem (Set.Iic e) f g hc] exact hf.2 hx hy ha hb hab Β· rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hx, Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hy)] obtain hc | hc := le_or_gt (a β€’ x + b β€’ y) e Β· rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hc] have hc' : a β€’ x + b β€’ e ≀ a β€’ x + b β€’ y := by gcongr trans a β€’ f x + b β€’ f e Β· exact (h_anti (hc'.trans hc) hc hc').trans (hf.2 hx Set.right_mem_Iic ha hb hab) Β· rw [h_eq] gcongr exact h_mono Set.left_mem_Ici hy.le hy.le Β· rw [Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hc)] have hc' : a β€’ x + b β€’ y ≀ a β€’ e + b β€’ y := by gcongr trans a β€’ g e + b β€’ g y Β· exact (h_mono hc.le (hc.le.trans hc') hc').trans (hg.2 Set.left_mem_Ici hy.le ha hb hab) Β· rw [← h_eq] gcongr exact h_anti hx Set.right_mem_Iic hx Β· rw [Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hx), Set.piecewise_eq_of_mem (Set.Iic e) f g hy] obtain hc | hc := le_or_gt (a β€’ x + b β€’ y) e Β· rw [Set.piecewise_eq_of_mem (Set.Iic e) f g hc] have hc' : a β€’ e + b β€’ y ≀ a β€’ x + b β€’ y := by gcongr trans a β€’ f e + b β€’ f y Β· exact (h_anti (hc'.trans hc) hc hc').trans (hf.2 Set.right_mem_Iic hy ha hb hab) Β· rw [h_eq] gcongr exact h_mono Set.left_mem_Ici hx.le hx.le Β· rw [Set.piecewise_eq_of_notMem (Set.Iic e) f g (Set.notMem_Iic.mpr hc)] have hc' : a β€’ x + b β€’ y ≀ a β€’ x + b β€’ e := by gcongr trans a β€’ g x + b β€’ g e Β· exact (h_mono hc.le (hc.le.trans hc') hc').trans (hg.2 hx.le Set.left_mem_Ici ha hb hab) Β· rw [← h_eq] gcongr exact h_anti hy Set.right_mem_Iic hy Β· have hc : e < a β€’ x + b β€’ y := (lt_min hx hy).trans_le (Convex.min_le_combo x y ha hb hab) rw [(Set.Iic e).piecewise_eq_of_notMem f g (Set.notMem_Iic.mpr hx), (Set.Iic e).piecewise_eq_of_notMem f g (Set.notMem_Iic.mpr hy), (Set.Iic e).piecewise_eq_of_notMem f g (Set.notMem_Iic.mpr hc)] exact hg.2 hx.le hy.le ha hb hab /-- The piecewise function `(Set.Ici e).piecewise f g` of a function `f` increasing and convex on `Set.Ici e` and a function `g` decreasing and convex on `Set.Iic e`, such that `f e = g e`, is convex on the universal set. -/ theorem convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic (hf : ConvexOn π•œ (Set.Ici e) f) (hg : ConvexOn π•œ (Set.Iic e) g) (h_mono : MonotoneOn f (Set.Ici e)) (h_anti : AntitoneOn g (Set.Iic e)) (h_eq : f e = g e) : ConvexOn π•œ Set.univ ((Set.Ici e).piecewise f g) := by have h_piecewise_Ici_eq_piecewise_Iic : (Set.Ici e).piecewise f g = (Set.Iic e).piecewise g f := by ext x; by_cases hx : x = e <;> simp [Set.piecewise, @le_iff_lt_or_eq _ _ x e, ← @ite_not _ (e ≀ _), hx, h_eq] rw [h_piecewise_Ici_eq_piecewise_Iic] exact convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici hg hf h_anti h_mono h_eq.symm /-- The piecewise function `(Set.Iic e).piecewise f g` of a function `f` increasing and concave on `Set.Iic e` and a function `g` decreasing and concave on `Set.Ici e`, such that `f e = g e`, is concave on the universal set. -/ theorem concaveOn_univ_piecewise_Iic_of_monotoneOn_Iic_antitoneOn_Ici (hf : ConcaveOn π•œ (Set.Iic e) f) (hg : ConcaveOn π•œ (Set.Ici e) g) (h_mono : MonotoneOn f (Set.Iic e)) (h_anti : AntitoneOn g (Set.Ici e)) (h_eq : f e = g e) : ConcaveOn π•œ Set.univ ((Set.Iic e).piecewise f g) := by rw [← neg_convexOn_iff, ← Set.piecewise_neg] exact convexOn_univ_piecewise_Iic_of_antitoneOn_Iic_monotoneOn_Ici hf.neg hg.neg h_mono.neg h_anti.neg (neg_inj.mpr h_eq) /-- The piecewise function `(Set.Ici e).piecewise f g` of a function `f` decreasing and concave on `Set.Ici e` and a function `g` increasing and concave on `Set.Iic e`, such that `f e = g e`, is concave on the universal set. -/ theorem concaveOn_univ_piecewise_Ici_of_antitoneOn_Ici_monotoneOn_Iic (hf : ConcaveOn π•œ (Set.Ici e) f) (hg : ConcaveOn π•œ (Set.Iic e) g) (h_anti : AntitoneOn f (Set.Ici e)) (h_mono : MonotoneOn g (Set.Iic e)) (h_eq : f e = g e) : ConcaveOn π•œ Set.univ ((Set.Ici e).piecewise f g) := by rw [← neg_convexOn_iff, ← Set.piecewise_neg] exact convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic hf.neg hg.neg h_anti.neg h_mono.neg (neg_inj.mpr h_eq)
.lake/packages/mathlib/Mathlib/Analysis/Convex/Star.lean
import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set import Mathlib.Algebra.Module.LinearMap.Prod import Mathlib.Algebra.Order.Module.Synonym import Mathlib.Analysis.Convex.Segment import Mathlib.Tactic.GCongr import Mathlib.Tactic.Module /-! # Star-convex sets This file 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 [Semiring π•œ] [PartialOrder π•œ] 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 (π•œ : Type*) {E : Type*} [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [SMul π•œ E] (x : E) (s : Set E) : 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_iInterβ‚‚ {ΞΉ : Sort*} {ΞΊ : ΞΉ β†’ Sort*} {s : (i : ΞΉ) β†’ ΞΊ i β†’ Set E} (h : βˆ€ i j, StarConvex π•œ x (s i j)) : StarConvex π•œ x (β‹‚ (i) (j), s i j) := starConvex_iInter fun i => starConvex_iInter (h i) 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_iUnionβ‚‚ {ΞΉ : Sort*} {ΞΊ : ΞΉ β†’ Sort*} {s : (i : ΞΉ) β†’ ΞΊ i β†’ Set E} (h : βˆ€ i j, StarConvex π•œ x (s i j)) : StarConvex π•œ x (⋃ (i) (j), s i j) := starConvex_iUnion fun i => starConvex_iUnion (h i) 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 [ZeroLEOneClass π•œ] (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 [ZeroLEOneClass π•œ] (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, ?_⟩ match_scalars <;> simp [hab] 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, ?_⟩ match_scalars <;> simp [hab] /-- 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 [CommSemiring π•œ] [PartialOrder π•œ] 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.zero_smul (hs : StarConvex π•œ 0 s) (c : π•œ) : StarConvex π•œ 0 (c β€’ s) := by simpa using hs.smul 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 [Ring π•œ] [PartialOrder π•œ] section AddCommMonoid variable [AddRightMono π•œ] [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 section AddRightMono variable [AddRightMono π•œ] [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β‚βŸ© end AddRightMono variable [AddCommGroup E] [AddCommGroup F] [Module π•œ E] [Module π•œ F] {x y : E} {s t : Set E} /-- 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_eq_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 [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [IsStrictOrderedModule π•œ E] [PosSMulReflectLT π•œ 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_ge]).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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] 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_of_one_leβ‚€ 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 [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [PosSMulMono π•œ 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] {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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Deriv.lean
import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # 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 Β· 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 Β· 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*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] {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) (notMem_of_mem_diff hy :) (notMem_of_mem_diff hz :) hz' lemma ConvexOn.monotoneOn_slope_gt (hfc : ConvexOn π•œ s f) (hxs : x ∈ s) : MonotoneOn (slope f x) {y ∈ s | x < y} := (hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩ lemma ConvexOn.monotoneOn_slope_lt (hfc : ConvexOn π•œ s f) (hxs : x ∈ s) : MonotoneOn (slope f x) {y ∈ s | y < x} := (hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩ /-- 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 lemma ConcaveOn.antitoneOn_slope_gt (hfc : ConcaveOn π•œ s f) (hxs : x ∈ s) : AntitoneOn (slope f x) {y ∈ s | x < y} := (hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩ lemma ConcaveOn.antitoneOn_slope_lt (hfc : ConcaveOn π•œ s f) (hxs : x ∈ s) : AntitoneOn (slope f x) {y ∈ s | y < x} := (hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩ variable [TopologicalSpace π•œ] [OrderTopology π•œ] lemma bddBelow_slope_lt_of_mem_interior (hfc : ConvexOn π•œ s f) (hxs : x ∈ interior s) : BddBelow (slope f x '' {y ∈ s | x < y}) := by obtain ⟨y, hyx, hys⟩ : βˆƒ y, y < x ∧ y ∈ s := Eventually.exists_lt (mem_interior_iff_mem_nhds.mp hxs) refine bddBelow_iff_subset_Ici.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩ simp_rw [mem_Ici, ← hz'] refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hyx.trans hz.2).le Β· simp [hys, hyx.ne] Β· simp [hz.2.ne', hz.1] lemma bddAbove_slope_gt_of_mem_interior (hfc : ConvexOn π•œ s f) (hxs : x ∈ interior s) : BddAbove (slope f x '' {y ∈ s | y < x}) := by obtain ⟨y, hyx, hys⟩ : βˆƒ y, x < y ∧ y ∈ s := Eventually.exists_gt (mem_interior_iff_mem_nhds.mp hxs) refine bddAbove_iff_subset_Iic.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩ simp_rw [mem_Iic, ← hz'] refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hz.2.trans hyx).le Β· simp [hz.2.ne, hz.1] Β· simp [hys, hyx.ne'] end slope namespace ConvexOn variable {S : Set ℝ} {f : ℝ β†’ ℝ} {x y f' : ℝ} section Interior /-! ### Left and right derivative of a convex function in the interior of the set -/ lemma hasDerivWithinAt_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (sInf (slope f x '' {y ∈ S | x < y})) (Ioi x) x := by have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' simp_rw [hasDerivWithinAt_iff_tendsto_slope] simp only [mem_Ioi, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self] have h : Ioo x b βŠ† {y | y ∈ S ∧ x < y} := fun z hz ↦ ⟨habs ⟨hxab.1.trans hz.1, hz.2⟩, hz.1⟩ have h_Ioo : Tendsto (slope f x) (𝓝[>] x) (𝓝 (sInf (slope f x '' Ioo x b))) := ((monotoneOn_slope_gt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_right (by simpa using hxab.2) ((bddBelow_slope_lt_of_mem_interior hfc hxs).mono (image_mono h)) suffices sInf (slope f x '' Ioo x b) = sInf (slope f x '' {y ∈ S | x < y}) by rwa [← this] apply (monotoneOn_slope_gt hfc (habs hxab)).csInf_eq_of_subset_of_forall_exists_le (bddBelow_slope_lt_of_mem_interior hfc hxs) h ?_ rintro y ⟨hyS, hxy⟩ obtain ⟨z, hxz, hzy⟩ := exists_between (lt_min hxab.2 hxy) exact ⟨z, ⟨hxz, hzy.trans_le (min_le_left _ _)⟩, hzy.le.trans (min_le_right _ _)⟩ lemma hasDerivWithinAt_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (sSup (slope f x '' {y ∈ S | y < x})) (Iio x) x := by have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' simp_rw [hasDerivWithinAt_iff_tendsto_slope] simp only [mem_Iio, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self] have h : Ioo a x βŠ† {y | y ∈ S ∧ y < x} := fun z hz ↦ ⟨habs ⟨hz.1, hz.2.trans hxab.2⟩, hz.2⟩ have h_Ioo : Tendsto (slope f x) (𝓝[<] x) (𝓝 (sSup (slope f x '' Ioo a x))) := ((monotoneOn_slope_lt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_left (by simpa using hxab.1) ((bddAbove_slope_gt_of_mem_interior hfc hxs).mono (image_mono h)) suffices sSup (slope f x '' Ioo a x) = sSup (slope f x '' {y ∈ S | y < x}) by rwa [← this] apply (monotoneOn_slope_lt hfc (habs hxab)).csSup_eq_of_subset_of_forall_exists_le (bddAbove_slope_gt_of_mem_interior hfc hxs) h ?_ rintro y ⟨hyS, hyx⟩ obtain ⟨z, hyz, hzx⟩ := exists_between (max_lt hxab.1 hyx) exact ⟨z, ⟨(le_max_left _ _).trans_lt hyz, hzx⟩, (le_max_right _ _).trans hyz.le⟩ lemma differentiableWithinAt_Ioi_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : DifferentiableWithinAt ℝ f (Ioi x) x := (hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).differentiableWithinAt lemma differentiableWithinAt_Iio_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : DifferentiableWithinAt ℝ f (Iio x) x := (hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).differentiableWithinAt lemma hasDerivWithinAt_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (derivWithin f (Ioi x) x) (Ioi x) x := (hfc.differentiableWithinAt_Ioi_of_mem_interior hxs).hasDerivWithinAt lemma hasDerivWithinAt_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (derivWithin f (Iio x) x) (Iio x) x := (hfc.differentiableWithinAt_Iio_of_mem_interior hxs).hasDerivWithinAt lemma rightDeriv_eq_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : derivWithin f (Ioi x) x = sInf (slope f x '' {y | y ∈ S ∧ x < y}) := (hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Ioi x) lemma leftDeriv_eq_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : derivWithin f (Iio x) x = sSup (slope f x '' {y | y ∈ S ∧ y < x}) := (hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Iio x) lemma monotoneOn_rightDeriv (hfc : ConvexOn ℝ S f) : MonotoneOn (fun x ↦ derivWithin f (Ioi x) x) (interior S) := by intro x hxs y hys hxy rcases eq_or_lt_of_le hxy with rfl | hxy; Β· rfl simp_rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs, hfc.rightDeriv_eq_sInf_slope_of_mem_interior hys] refine csInf_le_of_le (b := slope f x y) (bddBelow_slope_lt_of_mem_interior hfc hxs) ⟨y, by simp only [mem_setOf_eq, hxy, and_true]; exact interior_subset hys⟩ (le_csInf ?_ ?_) Β· have hys' := hys rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hys' obtain ⟨a, b, hxab, habs⟩ := hys' rw [image_nonempty] obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2 exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩ Β· rintro _ ⟨z, ⟨hzs, hyz : y < z⟩, rfl⟩ rw [slope_comm] exact slope_mono hfc (interior_subset hys) ⟨interior_subset hxs, hxy.ne⟩ ⟨hzs, hyz.ne'⟩ (hxy.trans hyz).le lemma monotoneOn_leftDeriv (hfc : ConvexOn ℝ S f) : MonotoneOn (fun x ↦ derivWithin f (Iio x) x) (interior S) := by intro x hxs y hys hxy rcases eq_or_lt_of_le hxy with rfl | hxy; Β· rfl simp_rw [hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs, hfc.leftDeriv_eq_sSup_slope_of_mem_interior hys] refine le_csSup_of_le (b := slope f x y) (bddAbove_slope_gt_of_mem_interior hfc hys) ⟨x, by simp only [slope_comm, mem_setOf_eq, hxy, and_true]; exact interior_subset hxs⟩ (csSup_le ?_ ?_) Β· have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' rw [image_nonempty] obtain ⟨z, hxz, hzb⟩ := exists_between hxab.1 exact ⟨z, habs ⟨hxz, hzb.trans hxab.2⟩, hzb⟩ Β· rintro _ ⟨z, ⟨hzs, hyz : z < x⟩, rfl⟩ exact slope_mono hfc (interior_subset hxs) ⟨hzs, hyz.ne⟩ ⟨interior_subset hys, hxy.ne'⟩ (hyz.trans hxy).le lemma leftDeriv_le_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : derivWithin f (Iio x) x ≀ derivWithin f (Ioi x) x := by have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs, hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs] refine csSup_le ?_ ?_ Β· rw [image_nonempty] obtain ⟨z, haz, hzx⟩ := exists_between hxab.1 exact ⟨z, habs ⟨haz, hzx.trans hxab.2⟩, hzx⟩ rintro _ ⟨z, ⟨hzs, hzx⟩, rfl⟩ refine le_csInf ?_ ?_ Β· rw [image_nonempty] obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2 exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩ rintro _ ⟨y, ⟨hys, hxy⟩, rfl⟩ exact slope_mono hfc (interior_subset hxs) ⟨hzs, hzx.ne⟩ ⟨hys, hxy.ne'⟩ (hzx.trans hxy).le end Interior 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' notMem_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 rightDeriv_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 lemma rightDeriv_le_slope_of_mem_interior (hfc : ConvexOn ℝ S f) {y : ℝ} (hxs : x ∈ interior S) (hys : y ∈ S) (hxy : x < y) : derivWithin f (Ioi x) x ≀ slope f x y := rightDeriv_le_slope hfc (interior_subset hxs) hys hxy (differentiableWithinAt_Ioi_of_mem_interior hfc hxs) /-- 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 := hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy /-- 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' notMem_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_leftDeriv (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 lemma slope_le_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hys : x ∈ S) (hxs : y ∈ interior S) (hxy : x < y) : slope f x y ≀ derivWithin f (Iio y) y := slope_le_leftDeriv hfc hys (interior_subset hxs) hxy (differentiableWithinAt_Iio_of_mem_interior hfc hxs) /-- 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' := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy /-- 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)) lemma isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg (hf : ConvexOn ℝ S f) (hx : x ∈ interior S) (hf_ld : derivWithin f (Iio x) x ≀ 0) (hf_rd : 0 ≀ derivWithin f (Ioi x) x) : IsMinOn f S x := by intro y hy rcases lt_trichotomy x y with hxy | h_eq | hyx Β· suffices 0 ≀ slope f x y by simp only [slope_def_field, div_nonneg_iff, sub_nonneg, tsub_le_iff_right, zero_add, not_le.mpr hxy, and_false, or_false] at this exact this.1 exact hf_rd.trans <| rightDeriv_le_slope_of_mem_interior hf hx hy hxy Β· simp [h_eq] Β· suffices slope f x y ≀ 0 by simp only [slope_def_field, div_nonpos_iff, sub_nonneg, tsub_le_iff_right, zero_add, not_le.mpr hyx, and_false, or_false] at this exact this.1 rw [slope_comm] exact (slope_le_leftDeriv_of_mem_interior hf hy hx hyx).trans hf_ld lemma isMinOn_of_rightDeriv_eq_zero (hf : ConvexOn ℝ S f) (hx : x ∈ interior S) (hf_rd : derivWithin f (Ioi x) x = 0) : IsMinOn f S x := by refine hf.isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg hx ?_ hf_rd.symm.le exact (hf.leftDeriv_le_rightDeriv_of_mem_interior hx).trans_eq hf_rd lemma isMinOn_of_leftDeriv_eq_zero (hf : ConvexOn ℝ S f) (hx : x ∈ interior S) (hf_ld : derivWithin f (Iio x) x = 0) : IsMinOn f S x := by refine hf.isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg hx hf_ld.le ?_ exact hf_ld.symm.le.trans (hf.leftDeriv_le_rightDeriv_of_mem_interior hx) 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 rightDeriv_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 := hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy 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_leftDeriv (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' := hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy 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_rightDeriv (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' := hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy <| hfd.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy 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 leftDeriv_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 := hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy 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 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_rightDeriv (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 leftDeriv_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 using (hfc.neg.strictMonoOn_deriv (fun x hx ↦ (hfd x hx).neg)).neg end StrictConcaveOn end MirrorImage
.lake/packages/mathlib/Mathlib/Analysis/Convex/Combination.lean
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`. -/ assert_not_exists Cardinal open Set Function Pointwise universe u u' section variable {R R' E F ΞΉ ΞΉ' Ξ± : Type*} [Field R] [Field R'] [AddCommGroup E] [AddCommGroup F] [AddCommGroup Ξ±] [LinearOrder Ξ±] [Module R E] [Module R F] [Module 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 [DecidableEq ΞΉ] (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] module variable {w} theorem Finset.centerMass_insert [DecidableEq ΞΉ] (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] match_scalars field @[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_sumElim, Finset.centerMass_eq_of_sum_1] Β· congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul] Β· rw [sum_sumElim, ← 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, smul_sum, sum_add_distrib, add_smul, mul_smul, *] theorem Finset.centerMass_ite_eq [DecidableEq ΞΉ] (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 [βˆ€ i, Decidable (w i β‰  0)] : {i ∈ t | 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, Ne, Classical.not_not] using hit' namespace Finset variable [LinearOrder R] [IsOrderedAddMonoid Ξ±] [PosSMulMono R Ξ±] 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 (Ξ± := Ξ±α΅’α΅ˆ) hwβ‚€ hw₁ end Finset variable {z} lemma Finset.centerMass_const (hw : βˆ‘ j ∈ t, w j β‰  0) (c : E) : t.centerMass w (Function.const _ c) = c := by simp [centerMass, ← sum_smul, hw] lemma Finset.centerMass_congr [DecidableEq ΞΉ] {t' : Finset ΞΉ} {w' : ΞΉ β†’ R} {z' : ΞΉ β†’ E} (h : βˆ€ i, (i ∈ t ∧ w i β‰  0 ∨ i ∈ t' ∧ w' i β‰  0) β†’ i ∈ t ∩ t' ∧ w i = w' i ∧ z i = z' i) : t.centerMass w z = t'.centerMass w' z' := by classical rw [← centerMass_filter_ne_zero, centerMass, ← centerMass_filter_ne_zero, centerMass] congr 1 Β· congr 1 exact sum_congr (by grind) (by grind) Β· exact sum_congr (by grind) (by grind) lemma Finset.centerMass_congr_finset [DecidableEq ΞΉ] {t' : Finset ΞΉ} (h : βˆ€ i ∈ t βˆͺ t', w i β‰  0 β†’ i ∈ t ∩ t') : t.centerMass w z = t'.centerMass w z := centerMass_congr (by grind) lemma Finset.centerMass_congr_weights {w' : ΞΉ β†’ R} (h : βˆ€ i ∈ t, w i = w' i) : t.centerMass w z = t.centerMass w' z := by classical exact centerMass_congr (by grind) lemma Finset.centerMass_congr_fun {z' : ΞΉ β†’ E} (h : βˆ€ i ∈ t, w i β‰  0 β†’ z i = z' i) : t.centerMass w z = t.centerMass w z' := by classical exact centerMass_congr (by grind) 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] variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid Ξ±] [PosSMulMono R Ξ±] /-- 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 classical induction t using Finset.induction with | empty => simp | insert i t hi ht => 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 classical 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) _ _ _ Β· simp only [sum_pair h_cases, if_neg h_cases, if_pos trivial] Β· grind Β· 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 omit [LinearOrder R] [IsStrictOrderedRing R] in 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 : 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 classical 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 [W, 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 [← 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 classical 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) (_ : ↑t βŠ† s), convexHull R ↑t := by classical 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] noncomputable 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) _ _ /-- 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_notMem 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 classical 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' [DecidableEq E] (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 ΞΉ] [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [Ξ  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 classical 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] 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 +contextual [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
.lake/packages/mathlib/Mathlib/Analysis/Convex/ContinuousLinearEquiv.lean
import Mathlib.Analysis.Convex.Strict import Mathlib.Topology.Algebra.Module.Equiv /-! # (Pre)images of strict convex sets under continuous linear equivalences In this file we prove that the (pre)image of a strict convex set under a continuous linear equivalence is a strict convex set. -/ variable {π•œ E F : Type*} [Field π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ E] [TopologicalSpace E] [AddCommGroup F] [Module π•œ F] [TopologicalSpace F] namespace ContinuousLinearEquiv @[simp] lemma strictConvex_preimage {s : Set F} (e : E ≃L[π•œ] F) : StrictConvex π•œ (e ⁻¹' s) ↔ StrictConvex π•œ s := ⟨fun h ↦ Function.LeftInverse.preimage_preimage e.right_inv s β–Έ h.linear_preimage e.symm.toLinearMap e.symm.continuous e.symm.injective, fun h ↦ h.linear_preimage e.toLinearMap e.continuous e.injective⟩ @[simp] lemma strictConvex_image {s : Set E} (e : E ≃L[π•œ] F) : StrictConvex π•œ (e '' s) ↔ StrictConvex π•œ s := by rw [e.image_eq_preimage_symm, e.symm.strictConvex_preimage] end ContinuousLinearEquiv
.lake/packages/mathlib/Mathlib/Analysis/Convex/Gauge.lean
import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.Normed.Module.Ball.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r β€’ s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {π•œ E : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r β€’ s } variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r β€’ s }) := rfl /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ β€’ x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_memβ‚€ hr.ne' _ _ private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r β€’ s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r β€’ s }.Nonempty := let ⟨r, hr₁, hrβ‚‚βŸ© := (absorbs x).exists_pos ⟨r, hr₁, hrβ‚‚ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ theorem gauge_mono (hs : Absorbent ℝ s) (h : s βŠ† t) : gauge t ≀ gauge s := fun _ => by unfold gauge gcongr; exacts [gauge_set_bddBelow, hs.gauge_set_nonempty] 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, 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_notMem.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 Β· linarith [gauge_le_of_mem (by linarith) <| h (a + Ξ΅ / 2) (by linarith)] 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 gauge_sum_le {ΞΉ : Type*} (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (t : Finset ΞΉ) (f : ΞΉ β†’ E) : gauge s (βˆ‘ i ∈ t, f i) ≀ βˆ‘ i ∈ t, gauge s (f i) := Finset.le_sum_of_subadditive _ gauge_zero.le (gauge_add_le hs absorbs) _ _ theorem self_subset_gauge_le_one : s βŠ† { x | gauge s x ≀ 1 } := fun _ => gauge_le_one_of_mem theorem Convex.gauge_le (hs : Convex ℝ s) (hβ‚€ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≀ a } := by by_cases ha : 0 ≀ a Β· rw [gauge_le_eq hs hβ‚€ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ Β· convert convex_empty (π•œ := ℝ) exact eq_empty_iff_forall_notMem.2 fun x hx => ha <| (gauge_nonneg _).trans hx theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun _ hx a haβ‚€ ha₁ => hs _ (by rwa [Real.norm_of_nonneg haβ‚€]) (smul_mem_smul_set hx) theorem le_gauge_of_notMem (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'] @[deprecated (since := "2025-05-23")] alias le_gauge_of_not_mem := le_gauge_of_notMem theorem one_le_gauge_of_notMem (hs₁ : StarConvex ℝ 0 s) (hsβ‚‚ : Absorbs ℝ s {x}) (hx : x βˆ‰ s) : 1 ≀ gauge s x := le_gauge_of_notMem hs₁ hsβ‚‚ <| by rwa [one_smul] @[deprecated (since := "2025-05-23")] alias one_le_gauge_of_not_mem := one_le_gauge_of_notMem section LinearOrderedField variable {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [MulActionWithZero Ξ± ℝ] [IsStrictOrderedModule Ξ± ℝ] 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] congr ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy end LinearOrderedField section RCLike variable [RCLike π•œ] [Module π•œ E] [IsScalarTower ℝ π•œ E] theorem gauge_norm_smul (hs : Balanced π•œ s) (r : π•œ) (x : E) : gauge s (β€–rβ€– β€’ x) = gauge s (r β€’ x) := by unfold gauge congr with ΞΈ rw [@RCLike.real_smul_eq_coe_smul π•œ] refine and_congr_right fun hΞΈ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] /-- If `s` is balanced, then the Minkowski functional is β„‚-homogeneous. -/ theorem gauge_smul (hs : Balanced π•œ s) (r : π•œ) (x : E) : gauge s (r β€’ x) = β€–rβ€– * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≀ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hrβ‚€, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hrβ‚€))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hcβ‚€, hcr, y, hy, rfl⟩ have hrc := (lt_inv_commβ‚€ hrβ‚€ hcβ‚€).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smulβ‚€ hcβ‚€.ne'] variable [T1Space E] theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by refine ⟨fun hβ‚€ ↦ by_contra fun (hne : x β‰  0) ↦ ?_, fun h ↦ h.symm β–Έ gauge_zero⟩ have : {x}ᢜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hrβ‚€, hr⟩ exact hr (by simpa [hβ‚€]) rfl theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : 0 < gauge s x ↔ x β‰  0 := by simp only [(gauge_nonneg _).lt_iff_ne', Ne, gauge_eq_zero hs hb] end TopologicalSpace section ContinuousSMul variable [TopologicalSpace E] [ContinuousSMul ℝ E] open Filter in theorem interior_subset_gauge_lt_one (s : Set E) : interior s βŠ† { x | gauge s x < 1 } := by intro x hx have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ β€’ x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ β€’ x)) := ((tendsto_id.invβ‚€ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left rw [inv_one, one_smul] at H₁ have Hβ‚‚ : βˆ€αΆ  r in 𝓝[<] (1 : ℝ), x ∈ r β€’ s ∧ 0 < r ∧ r < 1 := by filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsLT one_pos] with r h₁ hβ‚‚ exact ⟨(mem_smul_set_iff_inv_smul_memβ‚€ hβ‚‚.1.ne' _ _).2 h₁, hβ‚‚βŸ© rcases Hβ‚‚.exists with ⟨r, hxr, hrβ‚€, hrβ‚βŸ© exact (gauge_le_of_mem hrβ‚€.le hxr).trans_lt hr₁ theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hsβ‚€ : (0 : E) ∈ s) (hsβ‚‚ : IsOpen s) : { x | gauge s x < 1 } = s := by refine (gauge_lt_one_subset_self hs₁ β€Ή_β€Ί <| absorbent_nhds_zero <| hsβ‚‚.mem_nhds hsβ‚€).antisymm ?_ convert interior_subset_gauge_lt_one s exact hsβ‚‚.interior_eq.symm theorem gauge_lt_one_of_mem_of_isOpen (hsβ‚‚ : IsOpen s) {x : E} (hx : x ∈ s) : gauge s x < 1 := interior_subset_gauge_lt_one s <| by rwa [hsβ‚‚.interior_eq] theorem gauge_lt_of_mem_smul (x : E) (Ξ΅ : ℝ) (hΞ΅ : 0 < Ξ΅) (hsβ‚‚ : IsOpen s) (hx : x ∈ Ξ΅ β€’ s) : gauge s x < Ξ΅ := by have : Ρ⁻¹ β€’ x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_memβ‚€ hΞ΅.ne'] have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hsβ‚‚ this rwa [gauge_smul_of_nonneg (inv_nonneg.2 hΞ΅.le), smul_eq_mul, inv_mul_lt_iffβ‚€ hΞ΅, mul_one] at h_gauge_lt theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hsβ‚€ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x ≀ 1) : x ∈ closure s := by have : βˆ€αΆ  r : ℝ in 𝓝[<] 1, r β€’ x ∈ s := by filter_upwards [Ico_mem_nhdsLT one_pos] with r ⟨hrβ‚€, hrβ‚βŸ© apply gauge_lt_one_subset_self hc hsβ‚€ ha rw [mem_setOf_eq, gauge_smul_of_nonneg hrβ‚€] exact mul_lt_one_of_nonneg_of_lt_one_left hrβ‚€ hr₁ h refine mem_closure_of_tendsto ?_ this exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _)) inf_le_left theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hsβ‚€ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x = 1) : x ∈ frontier s := ⟨mem_closure_of_gauge_le_one hc hsβ‚€ ha h.le, fun h' ↦ (interior_subset_gauge_lt_one s h').out.ne h⟩ theorem tendsto_gauge_nhds_zero_nhdsGE (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[β‰₯] 0) := by refine nhdsGE_basis_Icc.tendsto_right_iff.2 fun Ξ΅ hΞ΅ ↦ ?_ rw [← set_smul_mem_nhds_zero_iff hΞ΅.ne'] at hs filter_upwards [hs] with x hx exact ⟨gauge_nonneg _, gauge_le_of_mem hΞ΅.le hx⟩ theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) := (tendsto_gauge_nhds_zero_nhdsGE hs).mono_right inf_le_left /-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin. See also `continuousAt_gauge`. -/ theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by rw [ContinuousAt, gauge_zero] exact tendsto_gauge_nhds_zero hs theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (hβ‚€ : s ∈ 𝓝 0) : comap (gauge s) (𝓝 0) = 𝓝 0 := (comap_gauge_nhds_zero_le (absorbent_nhds_zero hβ‚€) hb).antisymm (tendsto_gauge_nhds_zero hβ‚€).le_comap end ContinuousSMul section TopologicalVectorSpace open Filter variable [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ theorem continuousAt_gauge (hc : Convex ℝ s) (hsβ‚€ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by have ha : Absorbent ℝ s := absorbent_nhds_zero hsβ‚€ refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun Ξ΅ hΞ΅β‚€ ↦ ?_ rw [← map_add_left_nhds_zero, eventually_map] have : Ξ΅ β€’ s ∩ -(Ξ΅ β€’ s) ∈ 𝓝 0 := inter_mem ((set_smul_mem_nhds_zero_iff hΞ΅β‚€.ne').2 hsβ‚€) (neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hΞ΅β‚€.ne').2 hsβ‚€)) filter_upwards [this] with y hy constructor Β· rw [sub_le_iff_le_add] calc gauge s x = gauge s (x + y + (-y)) := by simp _ ≀ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _ _ ≀ gauge s (x + y) + Ξ΅ := by grw [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 + Ξ΅ := by grw [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, fun_prop] theorem continuous_gauge (hc : Convex ℝ s) (hsβ‚€ : s ∈ 𝓝 0) : Continuous (gauge s) := continuous_iff_continuousAt.2 fun _ ↦ continuousAt_gauge hc hsβ‚€ theorem gauge_lt_one_eq_interior (hc : Convex ℝ s) (hsβ‚€ : s ∈ 𝓝 0) : { x | gauge s x < 1 } = interior s := by refine Subset.antisymm (fun x hx ↦ ?_) (interior_subset_gauge_lt_one s) rcases mem_openSegment_of_gauge_lt_one (absorbent_nhds_zero hsβ‚€) hx with ⟨y, hys, hxy⟩ exact hc.openSegment_interior_self_subset_interior (mem_interior_iff_mem_nhds.2 hsβ‚€) hys hxy theorem gauge_lt_one_iff_mem_interior (hc : Convex ℝ s) (hsβ‚€ : s ∈ 𝓝 0) : gauge s x < 1 ↔ x ∈ interior s := Set.ext_iff.1 (gauge_lt_one_eq_interior hc hsβ‚€) _ theorem gauge_le_one_iff_mem_closure (hc : Convex ℝ s) (hsβ‚€ : s ∈ 𝓝 0) : gauge s x ≀ 1 ↔ x ∈ closure s := ⟨mem_closure_of_gauge_le_one hc (mem_of_mem_nhds hsβ‚€) (absorbent_nhds_zero hsβ‚€), fun h ↦ le_on_closure (fun _ ↦ gauge_le_one_of_mem) (continuous_gauge hc hsβ‚€).continuousOn continuousOn_const h⟩ theorem gauge_eq_one_iff_mem_frontier (hc : Convex ℝ s) (hsβ‚€ : s ∈ 𝓝 0) : gauge s x = 1 ↔ x ∈ frontier s := by rw [eq_iff_le_not_lt, gauge_le_one_iff_mem_closure hc hsβ‚€, gauge_lt_one_iff_mem_interior hc hsβ‚€] rfl end TopologicalVectorSpace section RCLike variable [RCLike π•œ] [Module π•œ E] [IsScalarTower ℝ π•œ E] /-- `gauge s` as a seminorm when `s` is balanced, convex and absorbent. -/ @[simps!] def gaugeSeminorm (hsβ‚€ : Balanced π•œ s) (hs₁ : Convex ℝ s) (hsβ‚‚ : Absorbent ℝ s) : Seminorm π•œ E := Seminorm.of (gauge s) (gauge_add_le hs₁ hsβ‚‚) (gauge_smul hsβ‚€) variable {hsβ‚€ : Balanced π•œ s} {hs₁ : Convex ℝ s} {hsβ‚‚ : Absorbent ℝ s} [TopologicalSpace E] [ContinuousSMul ℝ E] theorem gaugeSeminorm_lt_one_of_isOpen (hs : IsOpen s) {x : E} (hx : x ∈ s) : gaugeSeminorm hsβ‚€ hs₁ hsβ‚‚ x < 1 := gauge_lt_one_of_mem_of_isOpen hs hx theorem gaugeSeminorm_ball_one (hs : IsOpen s) : (gaugeSeminorm hsβ‚€ hs₁ hsβ‚‚).ball 0 1 = s := by rw [Seminorm.ball_zero_eq] exact gauge_lt_one_eq_self_of_isOpen hs₁ hsβ‚‚.zero_mem hs end RCLike /-- Any seminorm arises as the gauge of its unit ball. -/ @[simp] protected theorem Seminorm.gauge_ball (p : Seminorm ℝ E) : gauge (p.ball 0 1) = p := by ext x obtain hp | hp := { r : ℝ | 0 < r ∧ x ∈ r β€’ p.ball 0 1 }.eq_empty_or_nonempty Β· rw [gauge, hp, Real.sInf_empty] by_contra h have hpx : 0 < p x := (apply_nonneg _ _).lt_of_ne h have hpxβ‚‚ : 0 < 2 * p x := mul_pos zero_lt_two hpx refine hp.subset ⟨hpxβ‚‚, (2 * p x)⁻¹ β€’ x, ?_, smul_inv_smulβ‚€ hpxβ‚‚.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpxβ‚‚), inv_mul_lt_iffβ‚€ hpxβ‚‚, mul_one] exact lt_mul_of_one_lt_left hpx one_lt_two refine IsGLB.csInf_eq ⟨fun r => ?_, fun r hr => le_of_forall_pos_le_add fun Ξ΅ hΞ΅ => ?_⟩ hp Β· rintro ⟨hr, y, hy, rfl⟩ rw [p.mem_ball_zero] at hy rw [map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos hr] exact mul_le_of_le_one_right hr.le hy.le Β· have hpΞ΅ : 0 < p x + Ξ΅ := by positivity refine hr ⟨hpΞ΅, (p x + Ξ΅)⁻¹ β€’ x, ?_, smul_inv_smulβ‚€ hpΞ΅.ne' _⟩ rw [p.mem_ball_zero, map_smul_eq_mul, Real.norm_eq_abs, abs_of_pos (inv_pos.2 hpΞ΅), inv_mul_lt_iffβ‚€ hpΞ΅, mul_one] exact lt_add_of_pos_right _ hΞ΅ theorem Seminorm.gaugeSeminorm_ball (p : Seminorm ℝ E) : gaugeSeminorm (p.balanced_ball_zero 1) (p.convex_ball 0 1) (p.absorbent_ball_zero zero_lt_one) = p := DFunLike.coe_injective p.gauge_ball end AddCommGroup section Seminormed variable [SeminormedAddCommGroup E] [NormedSpace ℝ E] {s : Set E} {r : ℝ} {x : E} open Metric theorem gauge_unit_ball (x : E) : gauge (ball (0 : E) 1) x = β€–xβ€– := by rw [← ball_normSeminorm ℝ, Seminorm.gauge_ball, coe_normSeminorm] theorem gauge_ball (hr : 0 ≀ r) (x : E) : gauge (ball (0 : E) r) x = β€–xβ€– / r := by rcases hr.eq_or_lt with rfl | hr Β· simp Β· rw [← smul_unitBall_of_pos hr, gauge_smul_left, Pi.smul_apply, gauge_unit_ball, smul_eq_mul, abs_of_nonneg hr.le, div_eq_inv_mul] simp_rw [mem_ball_zero_iff, norm_neg] exact fun _ => id @[simp] theorem gauge_closure_zero : gauge (closure (0 : Set E)) = 0 := funext fun x ↦ by simp only [← singleton_zero, gauge_def', mem_closure_zero_iff_norm, norm_smul, mul_eq_zero, norm_eq_zero, inv_eq_zero] rcases (norm_nonneg x).eq_or_lt' 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_notMem 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_gt 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 := by grw [gauge_mono this hs (x - y), gauge_ball]; positivity _ = 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Extreme.lean
import Mathlib.Analysis.Convex.Hull /-! # Extreme sets This file defines extreme sets and extreme points for sets in a module. An extreme set of `A` is a subset of `A` that is as far as it can get in any outward direction: If point `x` is in it and point `y ∈ A`, then the line passing through `x` and `y` leaves `A` at `x`. This is an analytic notion of "being on the side of". It is weaker than being exposed (see `IsExposed.isExtreme`). ## Main declarations * `IsExtreme π•œ A B`: States that `B` is an extreme set of `A` (in the literature, `A` is often implicit). * `Set.extremePoints π•œ A`: Set of extreme points of `A` (corresponding to extreme singletons). * `Convex.mem_extremePoints_iff_convex_diff`: A useful equivalent condition to being an extreme point: `x` is an extreme point iff `A \ {x}` is convex. ## Implementation notes The exact definition of extremeness has been carefully chosen so as to make as many lemmas unconditional (in particular, the Krein-Milman theorem doesn't need the set to be convex!). In practice, `A` is often assumed to be a convex set. ## References See chapter 8 of [Barry Simon, *Convexity*][simon2011] ## TODO Prove lemmas relating extreme sets and points to the intrinsic frontier. -/ open Function Set Affine variable {π•œ E F ΞΉ : Type*} {M : ΞΉ β†’ Type*} section SMul variable (π•œ) [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [SMul π•œ E] /-- A set `B` is an extreme subset of `A` if `B βŠ† A` and all points of `B` only belong to open segments whose ends are in `B`. Our definition only requires that the left endpoint of the segment lies in `B`, but by symmetry of open segments, the right endpoint must also lie in `B`. See `IsExtreme.right_mem_of_mem_openSegment`. -/ @[mk_iff] structure IsExtreme (A B : Set E) : Prop where subset : B βŠ† A left_mem_of_mem_openSegment : βˆ€ ⦃x⦄, x ∈ A β†’ βˆ€ ⦃y⦄, y ∈ A β†’ βˆ€ ⦃z⦄, z ∈ B β†’ z ∈ openSegment π•œ x y β†’ 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} @[refl] protected theorem IsExtreme.refl (A : Set E) : IsExtreme π•œ A A := ⟨Subset.rfl, fun _ hx₁A _ _ _ _ _ ↦ hx₁A⟩ variable {π•œ} {A B C : Set E} {x : E} protected theorem IsExtreme.rfl : IsExtreme π•œ A A := IsExtreme.refl π•œ A theorem IsExtreme.right_mem_of_mem_openSegment (h : IsExtreme π•œ A B) {y z : E} (hx : x ∈ A) (hy : y ∈ A) (hz : z ∈ B) (hzxy : z ∈ openSegment π•œ x y) : y ∈ B := h.left_mem_of_mem_openSegment hy hx hz <| by rwa [openSegment_symm] @[trans] protected theorem IsExtreme.trans (hAB : IsExtreme π•œ A B) (hBC : IsExtreme π•œ B C) : IsExtreme π•œ A C := by refine ⟨hBC.subset.trans hAB.subset, fun x₁ hx₁A xβ‚‚ hxβ‚‚A x hxC hx ↦ ?_⟩ exact hBC.left_mem_of_mem_openSegment (hAB.left_mem_of_mem_openSegment hx₁A hxβ‚‚A (hBC.subset hxC) hx) (hAB.right_mem_of_mem_openSegment hx₁A hxβ‚‚A (hBC.subset hxC) hx) 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 exact ⟨hAB.left_mem_of_mem_openSegment hx₁A hxβ‚‚A hxB hx, hAC.left_mem_of_mem_openSegment hx₁A hxβ‚‚A hxC hx⟩ 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 inhabit ΞΉ refine ⟨iInter_subset_of_subset default (hAF default).1, fun x₁ hx₁A xβ‚‚ hxβ‚‚A x hxF hx ↦ ?_⟩ rw [mem_iInter] at hxF ⊒ exact fun i ↦ (hAF i).2 hx₁A hxβ‚‚A (hxF i) hx 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 /-- A point `x` is an extreme point of a set `A` iff `x ∈ A` and for any `x₁`, `xβ‚‚` such that `x` belongs to the open segment `(x₁, xβ‚‚)`, we have `x₁ = x` and `xβ‚‚ = x`. We used to use the RHS as the definition of `extremePoints`. However, the conclusion `xβ‚‚ = x` is redundant, so we changed the definition to the RHS of `mem_extremePoints_iff_left`. -/ theorem mem_extremePoints : x ∈ A.extremePoints π•œ ↔ x ∈ A ∧ βˆ€α΅‰ (x₁ ∈ A) (xβ‚‚ ∈ A), x ∈ openSegment π•œ x₁ xβ‚‚ β†’ x₁ = x ∧ xβ‚‚ = x := by refine ⟨fun h ↦ ⟨h.1, fun x₁ hx₁ xβ‚‚ hxβ‚‚ hx ↦ ⟨h.2 hx₁ hxβ‚‚ hx, ?_⟩⟩, fun h ↦ ⟨h.1, fun x₁ hx₁ xβ‚‚ hxβ‚‚ hx ↦ (h.2 x₁ hx₁ xβ‚‚ hxβ‚‚ hx).1⟩⟩ apply h.2 hxβ‚‚ hx₁ rwa [openSegment_symm] /-- A point `x` is an extreme point of a set `A` iff `x ∈ A` and for any `x₁`, `xβ‚‚` such that `x` belongs to the open segment `(x₁, xβ‚‚)`, we have `x₁ = x`. -/ theorem mem_extremePoints_iff_left : x ∈ A.extremePoints π•œ ↔ x ∈ A ∧ βˆ€ x₁ ∈ A, βˆ€ xβ‚‚ ∈ A, x ∈ openSegment π•œ x₁ xβ‚‚ β†’ x₁ = x := .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 simp [isExtreme_iff, extremePoints] 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β‚βŸ© 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 [Semiring π•œ] [PartialOrder π•œ] [AddCommGroup E] [AddCommGroup F] [βˆ€ i, AddCommGroup (M i)] [Module π•œ E] [Module π•œ F] [βˆ€ i, Module π•œ (M i)] {A B : Set E} theorem IsExtreme.convex_diff [IsOrderedRing π•œ] (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)⟩ @[simp] theorem extremePoints_prod (s : Set E) (t : Set F) : (s Γ—Λ’ t).extremePoints π•œ = s.extremePoints π•œ Γ—Λ’ t.extremePoints π•œ := by ext ⟨x, y⟩ refine (and_congr_right fun hx ↦ ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ ?_⟩).trans and_and_and_comm Β· rintro x₁ hx₁ xβ‚‚ hxβ‚‚ ⟨a, b, ha, hb, hab, hx'⟩ ext Β· exact h.1 hx₁.1 hxβ‚‚.1 ⟨a, b, ha, hb, hab, congrArg Prod.fst hx'⟩ Β· exact h.2 hx₁.2 hxβ‚‚.2 ⟨a, b, ha, hb, hab, congrArg Prod.snd hx'⟩ Β· rintro x₁ hx₁ xβ‚‚ hxβ‚‚ hx_fst refine congrArg Prod.fst (h (mk_mem_prod hx₁ hx.2) (mk_mem_prod hxβ‚‚ hx.2) ?_) rw [← Prod.image_mk_openSegment_left] exact mem_image_of_mem _ hx_fst Β· rintro x₁ hx₁ xβ‚‚ hxβ‚‚ hx_snd refine congrArg Prod.snd (h (mk_mem_prod hx.1 hx₁) (mk_mem_prod hx.1 hxβ‚‚) ?_) rw [← Prod.image_mk_openSegment_right] exact mem_image_of_mem _ hx_snd @[simp] theorem extremePoints_pi (s : βˆ€ i, Set (M i)) : (univ.pi s).extremePoints π•œ = univ.pi fun i ↦ (s i).extremePoints π•œ := by classical ext x simp only [mem_extremePoints_iff_left, mem_univ_pi, @forall_and ΞΉ] refine and_congr_right fun hx ↦ ⟨fun h i ↦ ?_, fun h ↦ ?_⟩ Β· rintro x₁ hx₁ xβ‚‚ hxβ‚‚ hi rw [← update_self i x₁ x, h (update x i x₁) _ (update x i xβ‚‚)] Β· rintro j obtain rfl | hji := eq_or_ne j i <;> simp [*] Β· rw [← Pi.image_update_openSegment] exact ⟨_, hi, update_eq_self _ _⟩ Β· rintro j obtain rfl | hji := eq_or_ne j i <;> simp [*] Β· rintro x₁ hx₁ xβ‚‚ hxβ‚‚ ⟨a, b, ha, hb, hab, rfl⟩ ext i exact h _ _ (hx₁ _) _ (hxβ‚‚ _) ⟨a, b, ha, hb, hab, rfl⟩ end OrderedSemiring section OrderedRing variable {L : Type*} [Ring π•œ] [PartialOrder π•œ] [IsOrderedRing π•œ] [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 [Ring π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [Module π•œ E] variable [DenselyOrdered π•œ] [NoZeroSMulDivisors π•œ E] {A : 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 rw [mem_extremePoints] 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_notMem_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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Segment.lean
import Mathlib.LinearAlgebra.AffineSpace.Midpoint import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.LinearAlgebra.Ray /-! # 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`. ## Notation We provide the following notation: * `[x -[π•œ] y] = segment π•œ x y` in scope `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*} {M : ΞΉ β†’ Type*} open Function Set open Pointwise Convex section OrderedSemiring variable [Semiring π•œ] [PartialOrder π•œ] [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`. Denoted as `[x -[π•œ] y]` within the `Convex` namespace. -/ 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, 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, 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 [ZeroLEOneClass π•œ] [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 [ZeroLEOneClass π•œ] [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] rintro z ⟨a, b, ha, hb, hab, rfl⟩ refine hb.eq_or_lt.imp ?_ fun hb' => ha.eq_or_lt.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] section lift variable (R : Type*) [Semiring R] [PartialOrder R] [Module R E] variable [Module R π•œ] [IsScalarTower R π•œ E] theorem segment.lift [SMulPosMono R π•œ] (x y : E) : segment R x y βŠ† segment π•œ x y := by rintro z ⟨a, b, ha, hb, hab, hxy⟩ refine ⟨_, _, ?_, ?_, by simpa [add_smul] using congr($(hab) β€’ (1 : π•œ)), by simpa⟩ all_goals exact zero_smul R (1 : π•œ) β–Έ smul_le_smul_of_nonneg_right β€Ή_β€Ί zero_le_one theorem openSegment.lift [Nontrivial π•œ] [SMulPosStrictMono R π•œ] (x y : E) : openSegment R x y βŠ† openSegment π•œ x y := by rintro z ⟨a, b, ha, hb, hab, hxy⟩ refine ⟨_, _, ?_, ?_, by simpa [add_smul] using congr($(hab) β€’ (1 : π•œ)), by simpa⟩ all_goals exact zero_smul R (1 : π•œ) β–Έ smul_lt_smul_of_pos_right β€Ή_β€Ί zero_lt_one end lift end Module end OrderedSemiring open Convex section OrderedRing variable (π•œ) [Ring π•œ] [PartialOrder π•œ] [AddRightMono π•œ] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] [Module π•œ E] [Module π•œ F] section DenselyOrdered variable [ZeroLEOneClass π•œ] [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 _ => ⟨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 _ => ⟨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_subset_endpoint_of_linearIndependent_sub {c x y : E} (h : LinearIndependent π•œ ![x - c, y - c]) : [c -[π•œ] x] ∩ [c -[π•œ] y] βŠ† {c} := by 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 lemma segment_inter_eq_endpoint_of_linearIndependent_sub [ZeroLEOneClass π•œ] {c x y : E} (h : LinearIndependent π•œ ![x - c, y - c]) : [c -[π•œ] x] ∩ [c -[π•œ] y] = {c} := by refine (segment_inter_subset_endpoint_of_linearIndependent_sub π•œ h).antisymm ?_ simp [singleton_subset_iff, left_mem_segment] end OrderedRing theorem sameRay_of_mem_segment [CommRing π•œ] [PartialOrder π•œ] [IsStrictOrderedRing π•œ] [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 [CommRing π•œ] [PartialOrder π•œ] [IsOrderedRing π•œ] [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 nontriviality π•œ rw [LinearIndependent.pair_add_smul_add_smul_iff] aesop section LinearOrderedRing variable [Ring π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 [Semifield π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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_cancel] 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_cancel] 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_iff_image_subset] 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 [Semiring π•œ] [PartialOrder π•œ] section OrderedAddCommMonoid variable [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [PosSMulMono π•œ 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 [AddCommMonoid E] [PartialOrder E] [IsOrderedCancelAddMonoid E] [Module π•œ E] [PosSMulStrictMono π•œ 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 [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [PosSMulMono π•œ 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] {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 rcases hxy.lt_or_gt 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 [Semiring π•œ] [PartialOrder π•œ] [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 [Semiring π•œ] [PartialOrder π•œ] [βˆ€ i, AddCommMonoid (M i)] [βˆ€ i, Module π•œ (M i)] {s : Set ΞΉ} theorem segment_subset (x y : βˆ€ i, M 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, M 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β‚‚ : M i) (y : βˆ€ i, M 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β‚‚ : M i) (y : βˆ€ i, M 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Topology.lean
import Mathlib.Analysis.Convex.Strict import Mathlib.Analysis.Convex.StdSimplex 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; * `closedConvexHull_closure_eq_closedConvexHull` : the closed convex hull of the closure of a set is equal to the closed convex hull of the set; * `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 Cardinal Norm open Metric Bornology Set Pointwise Convex variable {ΞΉ π•œ E : Type*} namespace Real variable {s : Set ℝ} {r Ξ΅ : ℝ} lemma closedBall_eq_segment (hΞ΅ : 0 ≀ Ξ΅) : closedBall r Ξ΅ = segment ℝ (r - Ξ΅) (r + Ξ΅) := by rw [closedBall_eq_Icc, segment_eq_Icc ((sub_le_self _ hΞ΅).trans <| le_add_of_nonneg_right hΞ΅)] lemma ball_eq_openSegment (hΞ΅ : 0 < Ξ΅) : ball r Ξ΅ = openSegment ℝ (r - Ξ΅) (r + Ξ΅) := by rw [ball_eq_Ioo, openSegment_eq_Ioo ((sub_lt_self _ hΞ΅).trans <| lt_add_of_pos_right _ hΞ΅)] theorem convex_iff_isPreconnected : Convex ℝ s ↔ IsPreconnected s := convex_iff_ordConnected.trans isPreconnected_iff_ordConnected.symm end Real alias ⟨_, IsPreconnected.convex⟩ := Real.convex_iff_isPreconnected /-! ### Topological vector spaces -/ section TopologicalSpace variable [Ring π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 [Ring π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 [Field π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ E] [TopologicalSpace E] [IsTopologicalAddGroup 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_mono 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 section variable [AddRightMono π•œ] /-- 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 end /-- In a topological vector space, the interior of a convex set is convex. -/ protected theorem Convex.interior [ZeroLEOneClass π•œ] {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 end ContinuousConstSMul section ContinuousConstSMul variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [Module π•œ E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul π•œ E] 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [Module π•œ E] [TopologicalSpace E] [IsTopologicalAddGroup E] [TopologicalSpace π•œ] [OrderTopology π•œ] [ContinuousSMul π•œ E] theorem Convex.closure_interior_eq_closure_of_nonempty_interior {s : Set E} (hs : Convex π•œ s) (hs' : (interior s).Nonempty) : closure (interior s) = closure s := subset_antisymm (closure_mono interior_subset) fun _ h ↦ closure_mono (hs.openSegment_interior_closure_subset_interior hs'.choose_spec h) (segment_subset_closure_openSegment (right_mem_segment ..)) theorem Convex.interior_closure_eq_interior_of_nonempty_interior {s : Set E} (hs : Convex π•œ s) (hs' : (interior s).Nonempty) : interior (closure s) = interior s := by refine subset_antisymm ?_ (interior_mono subset_closure) intro y hy rcases hs' with ⟨x, hx⟩ have h := AffineMap.lineMap_apply_one (k := π•œ) x y obtain ⟨t, ht1, ht⟩ := AffineMap.lineMap_continuous.tendsto' _ _ h |>.eventually_mem (mem_interior_iff_mem_nhds.1 hy) |>.exists_gt apply hs.openSegment_interior_closure_subset_interior hx ht nth_rw 1 [← AffineMap.lineMap_apply_zero (k := π•œ) x y, ← image_openSegment] exact ⟨1, Ioo_subset_openSegment ⟨zero_lt_one, ht1⟩, h⟩ end ContinuousSMul section TopologicalSpace variable [Semiring π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ E] [TopologicalSpace E] theorem convex_closed_sInter {S : Set (Set E)} (h : βˆ€ s ∈ S, Convex π•œ s ∧ IsClosed s) : Convex π•œ (β‹‚β‚€ S) ∧ IsClosed (β‹‚β‚€ S) := ⟨fun _ hx => starConvex_sInter fun _ hs => (h _ hs).1 <| hx _ hs, isClosed_sInter fun _ hs => (h _ hs).2⟩ variable (π•œ) in /-- The convex closed hull of a set `s` is the minimal convex closed set that includes `s`. -/ @[simps! isClosed] def closedConvexHull : ClosureOperator (Set E) := .ofCompletePred (fun s => Convex π•œ s ∧ IsClosed s) fun _ ↦ convex_closed_sInter theorem convex_closedConvexHull {s : Set E} : Convex π•œ (closedConvexHull π•œ s) := ((closedConvexHull π•œ).isClosed_closure s).1 theorem isClosed_closedConvexHull {s : Set E} : IsClosed (closedConvexHull π•œ s) := ((closedConvexHull π•œ).isClosed_closure s).2 theorem subset_closedConvexHull {s : Set E} : s βŠ† closedConvexHull π•œ s := (closedConvexHull π•œ).le_closure s theorem closure_subset_closedConvexHull {s : Set E} : closure s βŠ† closedConvexHull π•œ s := closure_minimal subset_closedConvexHull isClosed_closedConvexHull theorem closedConvexHull_min {s t : Set E} (hst : s βŠ† t) (h_conv : Convex π•œ t) (h_closed : IsClosed t) : closedConvexHull π•œ s βŠ† t := (closedConvexHull π•œ).closure_min hst ⟨h_conv, h_closed⟩ theorem convexHull_subset_closedConvexHull {s : Set E} : (convexHull π•œ) s βŠ† (closedConvexHull π•œ) s := convexHull_min subset_closedConvexHull convex_closedConvexHull @[simp] theorem closedConvexHull_closure_eq_closedConvexHull {s : Set E} : closedConvexHull π•œ (closure s) = closedConvexHull π•œ s := subset_antisymm (by simpa using ((closedConvexHull π•œ).monotone (closure_subset_closedConvexHull (π•œ := π•œ) (E := E)))) ((closedConvexHull π•œ).monotone subset_closure) end TopologicalSpace section ContinuousConstSMul variable [Field π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ E] [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul π•œ E] theorem closedConvexHull_eq_closure_convexHull {s : Set E} : closedConvexHull π•œ s = closure (convexHull π•œ s) := subset_antisymm (closedConvexHull_min (subset_trans (subset_convexHull π•œ s) subset_closure) (Convex.closure (convex_convexHull π•œ s)) isClosed_closure) (closure_minimal convexHull_subset_closedConvexHull isClosed_closedConvexHull) end ContinuousConstSMul section ContinuousSMul variable [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [IsTopologicalAddGroup 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_eq_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 end ContinuousSMul section LinearOrderedField variable {π•œ : Type*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [TopologicalSpace π•œ] [OrderTopology π•œ] theorem Convex.nontrivial_iff_nonempty_interior {s : Set π•œ} (hs : Convex π•œ s) : s.Nontrivial ↔ (interior s).Nonempty := by constructor Β· rintro ⟨x, hx, y, hy, h⟩ have hs' := Nonempty.mono <| interior_mono <| hs.segment_subset hx hy rw [segment_eq_Icc', interior_Icc, nonempty_Ioo, inf_lt_sup] at hs' exact hs' h Β· rintro ⟨x, hx⟩ rcases eq_singleton_or_nontrivial (interior_subset hx) with rfl | h Β· rw [interior_singleton] at hx exact hx.elim Β· exact h end LinearOrderedField
.lake/packages/mathlib/Mathlib/Analysis/Convex/Strong.lean
import Mathlib.Analysis.Convex.Function 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} {m : ℝ} {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 positivity [hΟ† _ hxy.ne'] 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 positivity [hΟ† _ hxy.ne'] 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Independent.lean
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 Affine Finset Function variable {π•œ E ΞΉ : Type*} section OrderedSemiring variable (π•œ) [Semiring π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ 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_notMem_convexHull_diff` for the `Set` version. -/ theorem convexIndependent_iff_notMem_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 @[deprecated (since := "2025-05-23")] alias convexIndependent_iff_not_mem_convexHull_diff := convexIndependent_iff_notMem_convexHull_diff 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_notMem_convexHull_diff` for the indexed family version. -/ theorem convexIndependent_set_iff_notMem_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) @[deprecated (since := "2025-05-23")] alias convexIndependent_set_iff_not_mem_convexHull_diff := convexIndependent_set_iff_notMem_convexHull_diff end OrderedSemiring section LinearOrderedField variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [Module π•œ E] {s : Set E} open scoped Classical in /-- 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_notMem_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
.lake/packages/mathlib/Mathlib/Analysis/Convex/BetweenList.lean
import Mathlib.Analysis.Convex.Between import Mathlib.Data.List.Triplewise /-! # Betweenness for lists of points. This file defines notions of lists of points in an affine space being in order on a line. ## Main definitions * `List.Wbtw R l`: The points in list `l` are weakly in order on a line. * `List.Sbtw R l`: The points in list `l` are strictly in order on a line. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap namespace List section OrderedRing variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points in a list are weakly in that order on a line. -/ protected def Wbtw (l : List P) : Prop := l.Triplewise (Wbtw R) variable {R} lemma wbtw_cons {p : P} {l : List P} : (p :: l).Wbtw R ↔ l.Pairwise (Wbtw R p) ∧ l.Wbtw R := triplewise_cons variable (R) /-- The points in a list are strictly in that order on a line. -/ protected def Sbtw (l : List P) : Prop := l.Wbtw R ∧ l.Pairwise (Β· β‰  Β·) variable (P) @[simp] lemma wbtw_nil : ([] : List P).Wbtw R := by simp [List.Wbtw] @[simp] lemma sbtw_nil : ([] : List P).Sbtw R := by simp [List.Sbtw] variable {P} @[simp] lemma wbtw_singleton (p₁ : P) : [p₁].Wbtw R := by simp [List.Wbtw] @[simp] lemma sbtw_singleton (p₁ : P) : [p₁].Sbtw R := by simp [List.Sbtw] @[simp] lemma wbtw_pair (p₁ pβ‚‚ : P) : [p₁, pβ‚‚].Wbtw R := by simp [List.Wbtw] @[simp] lemma sbtw_pair {p₁ pβ‚‚ : P} : [p₁, pβ‚‚].Sbtw R ↔ p₁ β‰  pβ‚‚ := by simp [List.Sbtw] variable {R} @[simp] lemma wbtw_triple {p₁ pβ‚‚ p₃ : P} : [p₁, pβ‚‚, p₃].Wbtw R ↔ Wbtw R p₁ pβ‚‚ p₃ := by simp [List.Wbtw] @[simp] lemma sbtw_triple [IsOrderedRing R] {p₁ pβ‚‚ p₃ : P} : [p₁, pβ‚‚, p₃].Sbtw R ↔ Sbtw R p₁ pβ‚‚ p₃ := by simp only [List.Sbtw, wbtw_triple, ne_eq, pairwise_cons, mem_cons, not_mem_nil, or_false, forall_eq_or_imp, forall_eq, IsEmpty.forall_iff, implies_true, Pairwise.nil, and_self, and_true] exact ⟨fun ⟨hw, ⟨h₁₂, hβ‚β‚ƒβŸ©, hβ‚‚β‚ƒβŸ© ↦ ⟨hw, Ne.symm h₁₂, hβ‚‚β‚ƒβŸ©, fun h ↦ ⟨h.1, ⟨h.2.1.symm, h.left_ne_right⟩, h.2.2⟩⟩ lemma wbtw_four {p₁ pβ‚‚ p₃ pβ‚„ : P} : [p₁, pβ‚‚, p₃, pβ‚„].Wbtw R ↔ Wbtw R p₁ pβ‚‚ p₃ ∧ Wbtw R p₁ pβ‚‚ pβ‚„ ∧ Wbtw R p₁ p₃ pβ‚„ ∧ Wbtw R pβ‚‚ p₃ pβ‚„ := by simp [List.Wbtw, triplewise_cons, and_assoc] lemma sbtw_four [IsOrderedRing R] {p₁ pβ‚‚ p₃ pβ‚„ : P} : [p₁, pβ‚‚, p₃, pβ‚„].Sbtw R ↔ Sbtw R p₁ pβ‚‚ p₃ ∧ Sbtw R p₁ pβ‚‚ pβ‚„ ∧ Sbtw R p₁ p₃ pβ‚„ ∧ Sbtw R pβ‚‚ p₃ pβ‚„ := by simp [List.Sbtw, List.Wbtw, triplewise_cons, Sbtw] aesop protected lemma Sbtw.wbtw {l : List P} (h : l.Sbtw R) : l.Wbtw R := h.1 lemma Sbtw.pairwise_ne {l : List P} (h : l.Sbtw R) : l.Pairwise (Β· β‰  Β·) := h.2 lemma sbtw_iff_triplewise_and_ne_pair [IsOrderedRing R] {l : List P} : l.Sbtw R ↔ l.Triplewise (Sbtw R) ∧ βˆ€ a, l β‰  [a, a] := by rw [List.Sbtw] induction l with | nil => simp | cons head tail ih => rw [wbtw_cons, triplewise_cons] refine ⟨fun h ↦ ?_, fun ⟨⟨hp, ht⟩, ha⟩ ↦ ⟨⟨hp.imp _root_.Sbtw.wbtw, ht.imp _root_.Sbtw.wbtw⟩, ?_⟩⟩ Β· rcases h with ⟨⟨hp, ht⟩, hpne⟩ refine ⟨⟨?_, ?_⟩, ?_⟩ Β· clear ih induction tail with | nil => simp | cons head2 tail ih' => rw [pairwise_cons] at hp hpne hpne ⊒ refine ⟨fun a ha ↦ ⟨hp.1 a ha, ?_⟩, ?_⟩ Β· refine ⟨(hpne.1 head2 ?_).symm, hpne.2.1 a ha⟩ simp Β· rw [wbtw_cons] at ht grind [List.pairwise_iff_forall_sublist] Β· rw [pairwise_cons] at hpne exact (ih.1 ⟨ht, hpne.2⟩).1 Β· grind Β· have ht' : tail.Wbtw R := ht.imp _root_.Sbtw.wbtw simp only [ht', true_and, ht] at ih rw [pairwise_cons, ih] refine ⟨fun a ha' ↦ ?_, fun a ↦ ?_⟩ Β· rintro rfl cases tail with | nil => simp at ha' | cons head2 tail => rw [pairwise_cons] at hp rcases mem_cons.1 ha' with rfl | hat Β· cases tail with | nil => simp at ha | cons head3 tail => simpa using hp.1 head3 Β· simpa using hp.1 head hat Β· rintro rfl simp at hp lemma sbtw_cons [IsOrderedRing R] {p : P} {l : List P} : (p :: l).Sbtw R ↔ l.Pairwise (Sbtw R p) ∧ l.Sbtw R ∧ l β‰  [p] := by rw [sbtw_iff_triplewise_and_ne_pair, ← not_exists, triplewise_cons] simp only [cons.injEq, exists_eq_left', and_assoc, and_congr_right_iff, ne_eq, and_congr_left_iff] intro hp hne rw [sbtw_iff_triplewise_and_ne_pair, iff_self_and, ← not_exists] rintro hl ⟨a, rfl⟩ simp at hp protected nonrec lemma Wbtw.map {l : List P} (h : l.Wbtw R) (f : P →ᡃ[R] P') : (l.map f).Wbtw R := Triplewise.map (fun h ↦ Wbtw.map h f) h lemma _root_.Function.Injective.list_wbtw_map_iff {l : List P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (l.map f).Wbtw R ↔ l.Wbtw R := ⟨fun h ↦ h.of_map hf.wbtw_map_iff.1, fun h ↦ h.map f⟩ lemma _root_.Function.Injective.list_sbtw_map_iff {l : List P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (l.map f).Sbtw R ↔ l.Sbtw R := by rw [List.Sbtw, List.Sbtw, hf.list_wbtw_map_iff] refine ⟨fun ⟨hl, hp⟩ ↦ ⟨hl, hp.of_map _ ?_⟩, fun ⟨hl, hp⟩ ↦ ⟨hl, hp.map _ ?_⟩⟩ <;> simp [hf.ne_iff] lemma _root_.AffineEquiv.list_wbtw_map_iff {l : List P} (f : P ≃ᡃ[R] P') : (l.map f).Wbtw R ↔ l.Wbtw R := by have hf : Function.Injective f.toAffineMap := f.injective apply hf.list_wbtw_map_iff lemma _root_.AffineEquiv.list_sbtw_map_iff {l : List P} (f : P ≃ᡃ[R] P') : (l.map f).Sbtw R ↔ l.Sbtw R := by have hf : Function.Injective f.toAffineMap := f.injective apply hf.list_sbtw_map_iff end OrderedRing section LinearOrderedField variable [Field R] [LinearOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] {x y z : P} variable {R} lemma Sorted.wbtw {l : List R} (h : l.Sorted (Β· ≀ Β·)) : l.Wbtw R := by induction l with | nil => simp | cons head tail ih => rw [wbtw_cons] refine ⟨?_, ih h.of_cons⟩ clear ih induction tail with | nil => simp | cons head' tail' ih => rw [pairwise_cons] refine ⟨?_, ih (h.sublist ?_)⟩ Β· rw [sorted_cons_cons, sorted_cons] at h exact fun a ha ↦ .of_le_of_le h.1 (h.2.1 a ha) Β· simp lemma Sorted.sbtw {l : List R} (h : l.Sorted (Β· < Β·)) : l.Sbtw R := ⟨Sorted.wbtw (h.imp LT.lt.le), h.imp LT.lt.ne⟩ lemma exists_map_eq_of_sorted_nonempty_iff_wbtw {l : List P} (hl : l β‰  []) : (βˆƒ l' : List R, l'.Sorted (Β· ≀ Β·) ∧ l'.map (lineMap (l.head hl) (l.getLast hl)) = l) ↔ l.Wbtw R := by refine ⟨fun ⟨l', hl's, hl'l⟩ ↦ ?_, fun h ↦ ?_⟩ Β· rw [← hl'l] exact Wbtw.map hl's.wbtw _ Β· suffices βˆƒ l' : List R, (βˆ€ a ∈ l', 0 ≀ a) ∧ l'.Sorted (Β· ≀ Β·) ∧ l'.map (lineMap (l.head hl) (l.getLast hl)) = l by rcases this with ⟨l', -, hl'⟩ exact ⟨l', hl'⟩ induction l with | nil => simp at hl | cons head tail ih => by_cases ht : tail = [] Β· refine ⟨[0], ?_⟩ simp [ht] Β· rw [wbtw_cons] at h replace ih := ih ht h.2 rcases ih with ⟨l'', hl''0, hl''s, hl''⟩ simp only [head_cons, getLast_cons ht] cases tail with | nil => simp at ht | cons head2 tail => by_cases ht2 : tail = [] Β· exact ⟨[0, 1], by simp [ht2]⟩ Β· simp only [head_cons, getLast_cons ht2] at hl'' ⊒ rw [pairwise_cons] at h have hw := h.1.1 _ (getLast_mem ht2) rcases hw with ⟨r, ⟨hr0, hr1⟩, rfl⟩ refine ⟨0 :: l''.map fun x ↦ r + (1 - r) * x, ?_, ?_, ?_⟩ Β· simp only [mem_cons, mem_map, forall_eq_or_imp, le_refl, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚, true_and] intro a ha have := hl''0 a ha nlinarith Β· simp only [sorted_cons, mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] refine ⟨?_, ?_⟩ Β· intro a ha have := hl''0 a ha nlinarith Β· refine hl''s.map _ fun a b hab ↦ ?_ gcongr linarith Β· simp only [map_cons, lineMap_apply_zero, map_map, ← hl'', cons.injEq, map_inj_left, Function.comp_apply, lineMap_lineMap_left, lineMap_eq_lineMap_iff, true_and] ring_nf simp lemma exists_map_eq_of_sorted_iff_wbtw {l : List P} : (βˆƒ p₁ pβ‚‚ : P, βˆƒ l' : List R, l'.Sorted (Β· ≀ Β·) ∧ l'.map (lineMap p₁ pβ‚‚) = l) ↔ l.Wbtw R := by refine ⟨fun ⟨p₁, pβ‚‚, l', hl's, hl'l⟩ ↦ ?_, fun h ↦ ?_⟩ Β· subst hl'l exact Wbtw.map hl's.wbtw _ Β· by_cases hl : l = [] Β· exact ⟨AddTorsor.nonempty.some, AddTorsor.nonempty.some, [], by simp [hl]⟩ Β· exact ⟨l.head hl, l.getLast hl, (exists_map_eq_of_sorted_nonempty_iff_wbtw hl).2 h⟩ lemma exists_map_eq_of_sorted_nonempty_iff_sbtw {l : List P} (hl : l β‰  []) : (βˆƒ l' : List R, l'.Sorted (Β· < Β·) ∧ l'.map (lineMap (l.head hl) (l.getLast hl)) = l ∧ (l.length = 1 ∨ l.head hl β‰  l.getLast hl)) ↔ l.Sbtw R := by refine ⟨fun ⟨l', hl's, hl'l, hla⟩ ↦ ⟨(exists_map_eq_of_sorted_nonempty_iff_wbtw hl).1 ⟨l', (hl's.imp LT.lt.le), hl'l⟩, ?_⟩, fun h ↦ ?_⟩ Β· rw [← hl'l] rcases hla with hla | hla Β· grind [List.pairwise_iff_forall_sublist] Β· exact (hl's.imp LT.lt.ne).map _ fun _ _ ↦ (lineMap_injective _ hla).ne Β· rw [List.Sbtw, ← exists_map_eq_of_sorted_nonempty_iff_wbtw hl] at h rcases h with ⟨⟨l', hl's, hl'l⟩, hp⟩ refine ⟨l', ?_, hl'l, ?_⟩ Β· rw [← hl'l] at hp have hp' : l'.Pairwise (Β· β‰  Β·) := hp.of_map _ (by simp) exact (pairwise_and_iff.2 ⟨hl's, hp'⟩).imp lt_iff_le_and_ne.2 Β· cases l with | nil => simp at hl | cons head tail => simp only [length_cons, add_eq_right, length_eq_zero_iff, head_cons] cases tail with | nil => simp | cons head2 tail => simp only [reduceCtorEq, false_or] rw [pairwise_cons] at hp refine hp.1 ((head :: head2 :: tail).getLast hl) ?_ simp lemma exists_map_eq_of_sorted_iff_sbtw [Nontrivial P] {l : List P} : (βˆƒ p₁ pβ‚‚ : P, p₁ β‰  pβ‚‚ ∧ βˆƒ l' : List R, l'.Sorted (Β· < Β·) ∧ l'.map (lineMap p₁ pβ‚‚) = l) ↔ l.Sbtw R := by refine ⟨fun ⟨p₁, pβ‚‚, hp₁pβ‚‚, l', hl's, hl'l⟩ ↦ ?_, fun h ↦ ?_⟩ Β· subst hl'l rw [(lineMap_injective _ hp₁pβ‚‚).list_sbtw_map_iff] exact hl's.sbtw Β· by_cases hl : l = [] Β· rcases exists_pair_ne P with ⟨p₁, pβ‚‚, hp₁pβ‚‚βŸ© exact ⟨p₁, pβ‚‚, hp₁pβ‚‚, by simp [hl]⟩ Β· by_cases hlen : l.length = 1 Β· rw [length_eq_one_iff] at hlen rcases hlen with ⟨p₁, rfl⟩ rcases exists_ne p₁ with ⟨pβ‚‚, hpβ‚‚pβ‚βŸ© exact ⟨p₁, pβ‚‚, hpβ‚‚p₁.symm, [0], by simp⟩ Β· refine ⟨l.head hl, l.getLast hl, ?_⟩ rw [← exists_map_eq_of_sorted_nonempty_iff_sbtw hl] at h simp only [hlen, false_or] at h rcases h with ⟨l', hl's, hl'l, hl⟩ exact ⟨hl, l', hl's, hl'l⟩ end LinearOrderedField end List
.lake/packages/mathlib/Mathlib/Analysis/Convex/Mul.lean
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 G : Type*} section LinearOrderedCommRing variable [CommRing π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [CommRing E] [LinearOrder E] [IsStrictOrderedRing E] [AddCommGroup F] [LinearOrder F] [IsOrderedAddMonoid F] [AddCommGroup G] [Module π•œ G] [Module π•œ E] [Module π•œ F] [Module E F] [IsScalarTower π•œ E F] [SMulCommClass π•œ E F] [IsOrderedModule π•œ F] [IsStrictOrderedModule E F] {s : Set G} {f : G β†’ E} {g : 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 [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' [IsOrderedModule π•œ 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 [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'' [IsOrderedModule π•œ 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 [IsOrderedModule π•œ 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' [IsOrderedModule π•œ 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 [IsOrderedModule π•œ E] [IsScalarTower π•œ E E] [SMulCommClass π•œ E E] {f g : 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] 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 simp only [smul_eq_mul] field_simp have H : 0 ≀ a * b * (x - y) ^ 2 := by positivity linear_combination H - x * y * (a + b + 1) * hab end LinearOrderedField
.lake/packages/mathlib/Mathlib/Analysis/Convex/Join.lean
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 (π•œ) [Semiring π•œ] [PartialOrder π•œ] [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] 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 section variable [IsOrderedRing π•œ] 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 end 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [Module π•œ E] {s t : Set E} {x : 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₁, ?_⟩ linear_combination (norm := module) -habβ‚‚ β€’ (a₁ β€’ x + b₁ β€’ y) refine ⟨x, hx, (aβ‚‚ * b₁ / (aβ‚‚ * b₁ + bβ‚‚)) β€’ y + (bβ‚‚ / (aβ‚‚ * b₁ + bβ‚‚)) β€’ z, ⟨y, hy, z, hz, _, _, by positivity, by positivity, by field, rfl⟩, aβ‚‚ * a₁, aβ‚‚ * b₁ + bβ‚‚, by positivity, by positivity, ?_, ?_⟩ Β· linear_combination aβ‚‚ * hab₁ + habβ‚‚ Β· match_scalars <;> field 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] 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 Β· linear_combination p * hab₁ + q * habβ‚‚ + hpq Β· rw [hx, hy] module 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] end LinearOrderedField
.lake/packages/mathlib/Mathlib/Analysis/Convex/Basic.lean
import Mathlib.Algebra.Ring.Action.Pointwise.Set import Mathlib.Analysis.Convex.Star import Mathlib.Tactic.Field import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Defs /-! # Convex sets In a π•œ-vector space, we define the following property: * `Convex π•œ s`: A set `s` is convex if for any two points `x y ∈ s` it includes `segment π•œ x y`. We provide various equivalent versions, and 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 [Semiring π•œ] [PartialOrder π•œ] 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) theorem convex_iff_add_mem : Convex π•œ s ↔ βˆ€ ⦃x⦄, x ∈ s β†’ βˆ€ ⦃y⦄, y ∈ s β†’ βˆ€ ⦃a b : π•œβ¦„, 0 ≀ a β†’ 0 ≀ b β†’ a + b = 1 β†’ a β€’ x + b β€’ y ∈ s := by simp_rw [convex_iff_segment_subset, segment_subset_iff] /-- 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 _ hx _ hy _ _ 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 [ZeroLEOneClass π•œ] : 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 [ZeroLEOneClass π•œ] (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 _) @[simp] theorem convex_singleton (c : E) : Convex π•œ ({c} : Set E) := subsingleton_singleton.convex theorem convex_zero : Convex π•œ (0 : Set E) := convex_singleton _ theorem convex_segment [IsOrderedRing π•œ] (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] Β· match_scalars <;> noncomm_ring /-- See `Convex.semilinear_image` for a version for semilinar maps, but requiring that `π•œ` be a linear order, instead of just a partial order. -/ 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) := fun x hx y hy a b ha hb hab => by rw [mem_preimage, f.map_add, LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower] 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. -/ noncomputable 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 [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] 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 [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²] [Module π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] 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 [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] theorem convex_uIcc (r s : Ξ²) : Convex π•œ (uIcc r s) := convex_Icc _ _ end LinearOrderedAddCommMonoid end Module section IsScalarTower variable [ZeroLEOneClass π•œ] [Module π•œ E] variable (R : Type*) [Semiring R] [PartialOrder R] [Module R E] variable [Module R π•œ] [IsScalarTower R π•œ E] /-- Lift the convexity of a set up through a scalar tower. -/ theorem Convex.lift [SMulPosMono R π•œ] {s : Set E} (hs : Convex π•œ s) : Convex R s := by intro x hx y hy a b ha hb hab suffices (a β€’ (1 : π•œ)) β€’ x + (b β€’ (1 : π•œ)) β€’ y ∈ s by simpa using this refine hs hx hy ?_ ?_ (by simpa [add_smul] using congr($(hab) β€’ (1 : π•œ))) all_goals exact zero_smul R (1 : π•œ) β–Έ smul_le_smul_of_nonneg_right β€Ή_β€Ί zero_le_one end IsScalarTower end AddCommMonoid section LinearOrderedAddCommMonoid variable [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [PartialOrder Ξ²] [Module π•œ E] [PosSMulMono π•œ 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 [CommSemiring π•œ] [PartialOrder π•œ] 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 [CommSemiring π•œ] [PartialOrder π•œ] [IsStrictOrderedRing π•œ] [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, ?_, ?_⟩ Β· linear_combination (norm := noncomm_ring) a * habp + b * habq + hab Β· module end StrictOrderedCommSemiring section OrderedRing variable [Ring π•œ] [PartialOrder π•œ] 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 _⟩ /-- 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 variable [AddRightMono π•œ] 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 match_scalars <;> noncomm_ring 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_iff_image_subset, 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 end AddCommGroup end OrderedRing section LinearOrder variable [Semiring π•œ] [AddCommMonoid E] section SemilinearMap variable [PartialOrder π•œ] variable {π•œ' : Type*} [Semiring π•œ'] [PartialOrder π•œ'] variable {Οƒ : π•œ β†’+* π•œ'} [RingHomSurjective Οƒ] variable {F' : Type*} [AddCommMonoid F'] [Module π•œ' F'] [Module π•œ E] theorem Convex.semilinear_image {s : Set E} (hs : Convex π•œ s) (hΟƒ : βˆ€ {s t}, Οƒ s ≀ Οƒ t ↔ s ≀ t) (f : E β†’β‚›β‚—[Οƒ] F') : Convex π•œ' (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ a b ha hb hab obtain ⟨r, rfl⟩ : βˆƒ r : π•œ, Οƒ r = a := RingHomSurjective.is_surjective .. obtain ⟨t, rfl⟩ : βˆƒ t : π•œ, Οƒ t = b := RingHomSurjective.is_surjective .. refine ⟨r β€’ x + t β€’ y, hs hx hy (by simp_all [(@hΟƒ 0 r).mp]) (by simp_all [(@hΟƒ 0 t).mp]) ?_, by simp⟩ apply_fun Οƒ using injective_of_le_imp_le _ hΟƒ.mp simpa end SemilinearMap variable [LinearOrder π•œ] [IsOrderedRing π•œ] 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 := by gcongr <;> assumption _ ≀ B := by rw [← add_smul, hs, one_smul] end LinearOrder theorem Convex.midpoint_mem [Ring π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [Module π•œ E] [Invertible (2 : π•œ)] {s : Set E} {x y : E} (h : Convex π•œ s) (hx : x ∈ s) (hy : y ∈ s) : midpoint π•œ x y ∈ s := h.segment_subset hx hy <| midpoint_mem_segment x y section LinearOrderedField variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] 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_of_one_leβ‚€ 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_of_nonneg hp hq).1 hpq) refine ⟨_, convex_iff_div.1 h hx hy hp hq hpq, ?_⟩ match_scalars <;> field protected 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 [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [PosSMulMono π•œ 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 [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module π•œ E] [PosSMulMono π•œ E] {s : Set E} (hs : s.OrdConnected) : Convex π•œ s := hs.convex_of_chain <| isChain_of_trichotomous s theorem convex_iff_ordConnected [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] {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 [Semiring π•œ] [PartialOrder π•œ] [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 theorem Convex.semilinear_range {π•œ' : Type*} [Semiring π•œ'] {Οƒ : π•œ' β†’+* π•œ} [RingHomSurjective Οƒ] {F' : Type*} [AddCommMonoid F'] [Module π•œ' F'] (f : F' β†’β‚›β‚—[Οƒ] E) : Convex π•œ (LinearMap.range f : Set E) := Submodule.convex .. end Submodule section CommSemiring variable {R : Type*} [CommSemiring R] variable (A : Type*) [Semiring A] [Algebra R A] variable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M] variable [PartialOrder R] [PartialOrder A] lemma convex_of_nonneg_surjective_algebraMap [FaithfulSMul R A] {s : Set M} (halg : Set.Ici 0 βŠ† algebraMap R A '' Set.Ici 0) (hs : Convex R s) : Convex A s := by simp only [Convex, StarConvex] at hs ⊒ intro u hu v hv a b ha hb hab obtain ⟨c, hc1, hc2⟩ := halg ha obtain ⟨d, hd1, hd2⟩ := halg hb convert hs hu hv hc1 hd1 _ using 2 Β· rw [← hc2, algebraMap_smul] Β· rw [← hd2, algebraMap_smul] rw [← hc2, ← hd2, ← algebraMap.coe_add] at hab exact (FaithfulSMul.algebraMap_eq_one_iff R A).mp hab end CommSemiring
.lake/packages/mathlib/Mathlib/Analysis/Convex/Slope.lean
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*} [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] {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 have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity have key := hf.2 hx hz ha hb (by field) simp only [smul_eq_mul] at key ring_nf at key field_simp at key ⊒ linarith /-- 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 := ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz simp only [Pi.neg_apply] at this linear_combination 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 have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity have key := hf.2 hx hz hxz' ha hb (by field) simp only [smul_eq_mul] at key ring_nf at key field_simp at key ⊒ linarith /-- 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 := StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz simp only [Pi.neg_apply] at this linear_combination 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 simp only [smul_eq_mul] have hxy : x < a * x + b * z := by linear_combination b * hxz - x * hab have hyz : a * x + b * z < z := by linear_combination a * hxz + z * hab have key := hf hx hz hxy hyz field_simp [sub_pos.2 hxy, sub_pos.2 hyz] at key apply le_of_mul_le_mul_left ?_ (sub_pos.2 hxz) linear_combination key + (- f x * z + x * f z) * hab /-- 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 => ?_ simp only [Pi.neg_apply] linear_combination 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 simp only [smul_eq_mul] have hxy : x < a * x + b * z := by linear_combination b * hxz - x * hab have hyz : a * x + b * z < z := by linear_combination a * hxz + z * hab have key := hf hx hz hxy hyz field_simp [sub_pos.2 hxy, sub_pos.2 hyz] at key apply lt_of_mul_lt_mul_left ?_ (sub_pos.2 hxz).le linear_combination key + (- f x * z + x * f z) * hab /-- 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 => ?_ simp only [Pi.neg_apply] linear_combination 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 have ha : 0 ≀ (z - y) / (z - x) := by positivity have hb : 0 ≀ (y - x) / (z - x) := by positivity have key := hf.2 hx hz ha hb ?_ Β· simp only [smul_eq_mul] at key ring_nf at key field_simp at key linear_combination key Β· field 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 field_simp 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 field_simp 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 rcases lt_or_gt_of_ne hxa with hxa | hxa Β· rcases 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] <;> simp Β· convert hf.slope_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; 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 have ha : 0 < (z - y) / (z - x) := by positivity have hb : 0 < (y - x) / (z - x) := by positivity have key := hf.2 hx hz (by linarith) ha hb ?_ Β· simp only [smul_eq_mul] at key ring_nf at key field_simp at key linear_combination key Β· field 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 field_simp 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 field_simp 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 rcases lt_or_gt_of_ne hxa with hxa | hxa Β· rcases 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] <;> simp Β· convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1 rw [← neg_div_neg_eq]; 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 linear_combination key /-- 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.strictMonoOn (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 intro 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⟩ @[deprecated (since := "2025-11-11")] alias ConvexOn.strict_mono_of_lt := ConvexOn.strictMonoOn /-- If `f` is convex on a set `s` in a linearly ordered field, and `f y < f x` for two points `x < y` in `s`, then `f` is strictly antitone on `s ∩ (∞, x]`. -/ theorem ConvexOn.strictAntiOn (hf : ConvexOn π•œ s f) {x y : π•œ} (hy : y ∈ s) (hxy : x < y) (hxy' : f y < f x) : StrictAntiOn f (s ∩ .Iic x) := by have := hf.comp_affineMap (-.id ..) |>.strictMonoOn (by simpa) (neg_lt_neg hxy) (by simpa) simpa [Function.comp_def] using this.comp_strictAntiOn strictMonoOn_id.neg fun _ _ ↦ by simpa /-- If `f` is concave 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 ∩ (∞, x]`. -/ theorem ConcaveOn.strictMonoOn (hf : ConcaveOn π•œ s f) {x y : π•œ} (hy : y ∈ s) (hxy : x < y) (hxy' : f x < f y) : StrictMonoOn f (s ∩ .Iic x) := by simpa using (neg_convexOn_iff.mpr hf |>.strictAntiOn hy hxy <| neg_lt_neg hxy').neg /-- If `f` is concave on a set `s` in a linearly ordered field, and `f y < f x` for two points `x < y` in `s`, then `f` is strictly antitone on `s ∩ [y, ∞)`. -/ theorem ConcaveOn.strictAntiOn (hf : ConcaveOn π•œ s f) {x y : π•œ} (hx : x ∈ s) (hxy : x < y) (hxy' : f y < f x) : StrictAntiOn f (s ∩ .Ici y) := by simpa using (neg_convexOn_iff.mpr hf |>.strictMonoOn hx hxy <| neg_lt_neg hxy').neg
.lake/packages/mathlib/Mathlib/Analysis/Convex/Exposed.lean
import Mathlib.Analysis.Convex.Extreme import Mathlib.Analysis.Convex.Function import Mathlib.Topology.Algebra.Module.LinearMap 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 Affine 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 : StrongDual π•œ E, B = { x ∈ A | βˆ€ y ∈ A, l y ≀ l x } end PreorderSemiring section OrderedRing variable {π•œ : Type*} {E : Type*} [TopologicalSpace π•œ] [Ring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [TopologicalSpace E] [Module π•œ E] {l : StrongDual π•œ E} {A B C : Set E} {x : E} /-- A useful way to build exposed sets from intersecting `A` with half-spaces (modelled by an inequality with a functional). -/ def ContinuousLinearMap.toExposed (l : StrongDual π•œ E) (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 half-space. The converse is *not* true. It would require that the corresponding open half-space doesn't intersect `A`. -/ theorem eq_inter_halfSpace' {A B : Set E} (hAB : IsExposed π•œ A B) (hB : B.Nonempty) : βˆƒ l : StrongDual π•œ E, βˆƒ 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 half-space. The converse is *not* true. It would require that the corresponding open half-space doesn't intersect `A`. -/ theorem eq_inter_halfSpace [IsOrderedRing π•œ] [Nontrivial π•œ] {A B : Set E} (hAB : IsExposed π•œ A B) : βˆƒ l : StrongDual π•œ E, βˆƒ 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_notMem] rintro x ⟨-, h⟩ rw [ContinuousLinearMap.zero_apply] at h have : Β¬(1 : π•œ) ≀ 0 := not_le_of_gt zero_lt_one contradiction exact hAB.eq_inter_halfSpace' hB protected theorem inter [IsOrderedRing π•œ] [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 [IsOrderedRing π•œ] [ContinuousAdd π•œ] {F : Finset (Set E)} (hF : F.Nonempty) (hAF : βˆ€ B ∈ F, IsExposed π•œ A B) : IsExposed π•œ A (β‹‚β‚€ F) := by classical 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 (π•œ) in /-- 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 : StrongDual π•œ E, βˆ€ y ∈ A, l y ≀ l x ∧ (l x ≀ l y β†’ y = x) } theorem exposed_point_def : x ∈ A.exposedPoints π•œ ↔ x ∈ A ∧ βˆƒ l : StrongDual π•œ E, βˆ€ 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 π•œ] [Ring π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommMonoid E] [TopologicalSpace E] [Module π•œ E] {A B : 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 => ?_⟩ rw [hlx₁.antisymm (hl.le_left_of_right_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
.lake/packages/mathlib/Mathlib/Analysis/Convex/StrictConvexBetween.lean
import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.StrictConvexSpace import Mathlib.Analysis.Normed.Affine.AddTorsor import Mathlib.Analysis.Normed.Affine.Isometry /-! # 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] at hs' exact False.elim (hpβ‚‚.not_gt 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] at hs' exact False.elim (hpβ‚‚.not_gt 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 /-- The strict triangle inequality. -/ theorem dist_lt_dist_add_dist_iff {a b c : P} : dist a c < dist a b + dist b c ↔ Β¬ Wbtw ℝ a b c := by rw [← ne_iff_lt_iff_le.mpr (dist_triangle _ _ _), not_iff_not, eq_comm, dist_add_dist_eq_iff] 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, 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/README.md
# Convex analysis This subfolder is destined to contain convexity results that require a norm or an inner product. See the `Mathlib.Geometry.Convex` folder for the results that do not need a norm or an inner product. ## Topics The topics currently covered are: * Strongly convex functions, uniformly convex functions * The product of convex functions is convex * Continuity of convex functions * Functions with positive second derivative are convex * Null-measurability of convex sets * Minkowski functional, gauge * Strictly convex spaces * Uniformly convex spaces * Ample sets
.lake/packages/mathlib/Mathlib/Analysis/Convex/Visible.lean
import Mathlib.Algebra.BigOperators.Field import Mathlib.Algebra.Group.Pointwise.Set.Card import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Convex.Combination import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.MetricSpace.Pseudo.Lemmas import Mathlib.Topology.Order.Monotone /-! # Points in sight This file defines the relation of visibility with respect to a set, and lower bounds how many elements of a set a point sees in terms of the dimension of that set. ## TODO The art gallery problem can be stated using the visibility predicate: A set `A` (the art gallery) is guarded by a finite set `G` (the guards) iff `βˆ€ a ∈ A, βˆƒ g ∈ G, IsVisible ℝ sᢜ a g`. -/ open AffineMap Filter Finset Set open scoped Cardinal Pointwise Topology variable {π•œ V P : Type*} section AddTorsor variable [Field π•œ] [LinearOrder π•œ] [IsOrderedRing π•œ] [AddCommGroup V] [Module π•œ V] [AddTorsor V P] {s t : Set P} {x y z : P} omit [IsOrderedRing π•œ] in variable (π•œ) in /-- Two points are visible to each other through a set if no point of that set lies strictly between them. By convention, a point `x` sees itself through any set `s`, even when `x ∈ s`. -/ def IsVisible (s : Set P) (x y : P) : Prop := βˆ€ ⦃z⦄, z ∈ s β†’ Β¬ Sbtw π•œ x z y @[simp, refl] lemma IsVisible.rfl : IsVisible π•œ s x x := by simp [IsVisible] lemma isVisible_comm : IsVisible π•œ s x y ↔ IsVisible π•œ s y x := by simp [IsVisible, sbtw_comm] @[symm] alias ⟨IsVisible.symm, _⟩ := isVisible_comm omit [IsOrderedRing π•œ] in lemma IsVisible.mono (hst : s βŠ† t) (ht : IsVisible π•œ t x y) : IsVisible π•œ s x y := fun _z hz ↦ ht <| hst hz lemma isVisible_iff_lineMap (hxy : x β‰  y) : IsVisible π•œ s x y ↔ βˆ€ Ξ΄ ∈ Set.Ioo (0 : π•œ) 1, lineMap x y Ξ΄ βˆ‰ s := by simp [IsVisible, sbtw_iff_mem_image_Ioo_and_ne, hxy] aesop end AddTorsor section Module variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup V] [Module π•œ V] {s : Set V} {x y z : V} /-- If a point `x` sees a convex combination of points of a set `s` through `convexHull ℝ s ∌ x`, then it sees all terms of that combination. Note that the converse does not hold. -/ lemma IsVisible.of_convexHull_of_pos {ΞΉ : Type*} {t : Finset ΞΉ} {a : ΞΉ β†’ V} {w : ΞΉ β†’ π•œ} (hwβ‚€ : βˆ€ i ∈ t, 0 ≀ w i) (hw₁ : βˆ‘ i ∈ t, w i = 1) (ha : βˆ€ i ∈ t, a i ∈ s) (hx : x βˆ‰ convexHull π•œ s) (hw : IsVisible π•œ (convexHull π•œ s) x (βˆ‘ i ∈ t, w i β€’ a i)) {i : ΞΉ} (hi : i ∈ t) (hwi : 0 < w i) : IsVisible π•œ (convexHull π•œ s) x (a i) := by classical obtain hwi | hwi : w i = 1 ∨ w i < 1 := eq_or_lt_of_le <| (single_le_sum hwβ‚€ hi).trans_eq hw₁ Β· convert hw rw [← one_smul π•œ (a i), ← hwi, eq_comm] rw [← hwi, ← sub_eq_zero, ← sum_erase_eq_sub hi, sum_eq_zero_iff_of_nonneg fun j hj ↦ hwβ‚€ _ <| erase_subset _ _ hj] at hw₁ refine sum_eq_single _ (fun j hj hji ↦ ?_) (by simp [hi]) rw [hw₁ _ <| mem_erase.2 ⟨hji, hj⟩, zero_smul] rintro _ hΞ΅ ⟨⟨Ρ, ⟨hΞ΅β‚€, hΞ΅β‚βŸ©, rfl⟩, h⟩ replace hΞ΅β‚€ : 0 < Ξ΅ := hΞ΅β‚€.lt_of_ne <| by rintro rfl; simp at h replace hΡ₁ : Ξ΅ < 1 := hΡ₁.lt_of_ne <| by rintro rfl; simp at h have : 0 < 1 - Ξ΅ := by linarith have hwi : 0 < 1 - w i := by linarith refine hw (z := lineMap x (βˆ‘ j ∈ t, w j β€’ a j) ((w i)⁻¹ / ((1 - Ξ΅) / Ξ΅ + (w i)⁻¹))) ?_ <| sbtw_lineMap_iff.2 ⟨(ne_of_mem_of_not_mem ((convex_convexHull ..).sum_mem hwβ‚€ hw₁ fun i hi ↦ subset_convexHull _ _ <| ha _ hi) hx).symm, by positivity, (div_lt_one <| by positivity).2 ?_⟩ Β· have : Wbtw π•œ (lineMap x (a i) Ξ΅) (lineMap x (βˆ‘ j ∈ t, w j β€’ a j) ((w i)⁻¹ / ((1 - Ξ΅) / Ξ΅ + (w i)⁻¹))) (βˆ‘ j ∈ t.erase i, (w j / (1 - w i)) β€’ a j) := by refine ⟨((1 - w i) / w i) / ((1 - Ξ΅) / Ξ΅ + (1 - w i) / w i + 1), ⟨by positivity, ?_⟩, ?_⟩ Β· refine (div_le_one <| by positivity).2 ?_ calc (1 - w i) / w i = 0 + (1 - w i) / w i + 0 := by simp _ ≀ (1 - Ξ΅) / Ξ΅ + (1 - w i) / w i + 1 := by gcongr <;> positivity have : w i β€’ a i + (1 - w i) β€’ βˆ‘ j ∈ t.erase i, (w j / (1 - w i)) β€’ a j = βˆ‘ j ∈ t, w j β€’ a j := by rw [smul_sum] simp_rw [smul_smul, mul_div_cancelβ‚€ _ hwi.ne'] exact add_sum_erase _ (fun i ↦ w i β€’ a i) hi simp_rw [lineMap_apply_module, ← this] match_scalars <;> field refine (convex_convexHull _ _).mem_of_wbtw this hΞ΅ <| (convex_convexHull _ _).sum_mem ?_ ?_ ?_ Β· intro j hj positivity [hwβ‚€ j <| erase_subset _ _ hj] Β· rw [← sum_div, sum_erase_eq_sub hi, hw₁, div_self hwi.ne'] Β· exact fun j hj ↦ subset_convexHull _ _ <| ha _ <| erase_subset _ _ hj Β· exact lt_add_of_pos_left _ <| by positivity variable [TopologicalSpace π•œ] [OrderTopology π•œ] [TopologicalSpace V] [IsTopologicalAddGroup V] [ContinuousSMul π•œ V] /-- One cannot see any point in the interior of a set. -/ lemma IsVisible.eq_of_mem_interior (hsxy : IsVisible π•œ s x y) (hy : y ∈ interior s) : x = y := by by_contra! hxy suffices h : βˆ€αΆ  (_Ξ΄ : π•œ) in 𝓝[>] 0, False by obtain ⟨_, ⟨⟩⟩ := h.exists have hmem : βˆ€αΆ  (Ξ΄ : π•œ) in 𝓝[>] 0, lineMap y x Ξ΄ ∈ s := lineMap_continuous.continuousWithinAt.eventually_mem (by simpa using mem_interior_iff_mem_nhds.1 hy) filter_upwards [hmem, Ioo_mem_nhdsGT zero_lt_one] with Ξ΄ hmem hsbt using hsxy.symm hmem (by aesop) /-- One cannot see any point of an open set. -/ lemma IsOpen.eq_of_isVisible_of_left_mem (hs : IsOpen s) (hsxy : IsVisible π•œ s x y) (hy : y ∈ s) : x = y := hsxy.eq_of_mem_interior (by simpa [hs.interior_eq]) end Module section Real variable [AddCommGroup V] [Module ℝ V] {s : Set V} {x y z : V} /-- All points of the convex hull of a set `s` visible from a point `x βˆ‰ convexHull ℝ s` lie in the convex hull of such points that actually lie in `s`. Note that the converse does not hold. -/ lemma IsVisible.mem_convexHull_isVisible (hx : x βˆ‰ convexHull ℝ s) (hy : y ∈ convexHull ℝ s) (hxy : IsVisible ℝ (convexHull ℝ s) x y) : y ∈ convexHull ℝ {z ∈ s | IsVisible ℝ (convexHull ℝ s) x z} := by classical obtain ⟨ι, _, w, a, hwβ‚€, hw₁, ha, rfl⟩ := mem_convexHull_iff_exists_fintype.1 hy rw [← Fintype.sum_subset (s := {i | w i β‰  0}) fun i hi ↦ mem_filter.2 ⟨mem_univ _, left_ne_zero_of_smul hi⟩] exact (convex_convexHull ..).sum_mem (fun i _ ↦ hwβ‚€ _) (by rwa [sum_filter_ne_zero]) fun i hi ↦ subset_convexHull _ _ ⟨ha _, IsVisible.of_convexHull_of_pos (fun _ _ ↦ hwβ‚€ _) hw₁ (by simpa) hx hxy (mem_univ _) <| (hwβ‚€ _).lt_of_ne' (mem_filter.1 hi).2⟩ variable [TopologicalSpace V] [IsTopologicalAddGroup V] [ContinuousSMul ℝ V] /-- If `s` is a closed set, then any point `x` sees some point of `s` in any direction where there is something to see. -/ lemma IsClosed.exists_wbtw_isVisible (hs : IsClosed s) (hy : y ∈ s) (x : V) : βˆƒ z ∈ s, Wbtw ℝ x z y ∧ IsVisible ℝ s x z := by let t : Set ℝ := Ici 0 ∩ lineMap x y ⁻¹' s have ht₁ : 1 ∈ t := by simpa [t] have ht : BddBelow t := bddBelow_Ici.inter_of_left let Ξ΄ : ℝ := sInf t have hδ₁ : Ξ΄ ≀ 1 := csInf_le ht ht₁ obtain ⟨hΞ΄β‚€, hδ⟩ : 0 ≀ Ξ΄ ∧ lineMap x y Ξ΄ ∈ s := (isClosed_Ici.inter <| hs.preimage lineMap_continuous).csInf_mem ⟨1, htβ‚βŸ© ht refine ⟨lineMap x y Ξ΄, hΞ΄, wbtw_lineMap_iff.2 <| .inr ⟨hΞ΄β‚€, hΞ΄β‚βŸ©, ?_⟩ rintro _ hΞ΅ ⟨⟨Ρ, ⟨hΞ΅β‚€, hΞ΅β‚βŸ©, rfl⟩, -, h⟩ replace hΞ΄β‚€ : 0 < Ξ΄ := hΞ΄β‚€.lt_of_ne' <| by rintro hΞ΄β‚€; simp [hΞ΄β‚€] at h replace hΡ₁ : Ξ΅ < 1 := hΡ₁.lt_of_ne <| by rintro rfl; simp at h rw [lineMap_lineMap_right] at hΞ΅ exact (csInf_le ht ⟨mul_nonneg hΞ΅β‚€ hΞ΄β‚€.le, hΡ⟩).not_gt <| mul_lt_of_lt_one_left hΞ΄β‚€ hΡ₁ -- TODO: Once we have cone hulls, the RHS can be strengthened to -- `coneHull ℝ x {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y}` /-- A set whose convex hull is closed lies in the cone based at a point `x` generated by its points visible from `x` through its convex hull. -/ lemma IsClosed.convexHull_subset_affineSpan_isVisible (hs : IsClosed (convexHull ℝ s)) (hx : x βˆ‰ convexHull ℝ s) : convexHull ℝ s βŠ† affineSpan ℝ ({x} βˆͺ {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y}) := by rintro y hy obtain ⟨z, hz, hxzy, hxz⟩ := hs.exists_wbtw_isVisible hy x -- TODO: `calc` doesn't work with `∈` :( exact AffineSubspace.right_mem_of_wbtw hxzy (subset_affineSpan _ _ <| subset_union_left rfl) (affineSpan_mono _ subset_union_right <| convexHull_subset_affineSpan _ <| hxz.mem_convexHull_isVisible hx hz) (ne_of_mem_of_not_mem hz hx).symm open Submodule in /-- If `s` is a closed set of dimension `d` and `x` is a point outside of its convex hull, then `x` sees at least `d` points of the convex hull of `s` that actually lie in `s`. -/ lemma rank_le_card_isVisible (hs : IsClosed (convexHull ℝ s)) (hx : x βˆ‰ convexHull ℝ s) : Module.rank ℝ (span ℝ (-x +α΅₯ s)) ≀ #{y ∈ s | IsVisible ℝ (convexHull ℝ s) x y} := by calc Module.rank ℝ (span ℝ (-x +α΅₯ s)) ≀ Module.rank ℝ (span ℝ (-x +α΅₯ affineSpan ℝ ({x} βˆͺ {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y}) : Set V)) := by push_cast refine Submodule.rank_mono ?_ gcongr exact (subset_convexHull ..).trans <| hs.convexHull_subset_affineSpan_isVisible hx _ = Module.rank ℝ (span ℝ (-x +α΅₯ {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y})) := by suffices h : -x +α΅₯ (affineSpan ℝ ({x} βˆͺ {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y}) : Set V) = span ℝ (-x +α΅₯ {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y}) by rw [AffineSubspace.coe_pointwise_vadd, h, span_span] simp [← AffineSubspace.coe_pointwise_vadd, AffineSubspace.pointwise_vadd_span, vadd_set_insert, -coe_affineSpan, affineSpan_insert_zero] _ ≀ #(-x +α΅₯ {y ∈ s | IsVisible ℝ (convexHull ℝ s) x y}) := rank_span_le _ _ = #{y ∈ s | IsVisible ℝ (convexHull ℝ s) x y} := by simp end Real
.lake/packages/mathlib/Mathlib/Analysis/Convex/AmpleSet.lean
import Mathlib.Algebra.CharP.Invertible import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.NormedSpace.Connected import Mathlib.Topology.Algebra.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 ≃ᴬ[ℝ] 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 ≃ᴬ[ℝ] 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 ≃ᴬ[ℝ] 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 ≃ᴬ[ℝ] 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 [IsTopologicalAddGroup 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 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Hull.lean
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 [Semiring π•œ] [PartialOrder π•œ] 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_eq_empty : convexHull π•œ s = βˆ… ↔ s = βˆ… := by constructor Β· intro h rw [← Set.subset_empty_iff, ← h] exact subset_convexHull π•œ _ Β· rintro rfl exact convexHull_empty @[deprecated (since := "2025-08-09")] alias convexHull_empty_iff := convexHull_eq_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_eq_empty 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] lemma convexHull_eq_singleton : convexHull π•œ s = {x} ↔ s = {x} where mp hs := by rw [← Set.Nonempty.subset_singleton_iff, ← hs] Β· exact subset_convexHull .. Β· by_contra! hs simp_all [eq_comm (a := βˆ…)] mpr hs := by simp [hs] @[simp] theorem convexHull_zero : convexHull π•œ (0 : Set E) = 0 := convexHull_singleton 0 @[simp] lemma convexHull_eq_zero : convexHull π•œ s = 0 ↔ s = 0 := convexHull_eq_singleton @[simp] theorem convexHull_pair [IsOrderedRing π•œ] (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_notMem_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⟩ @[deprecated (since := "2025-05-23")] alias Convex.convex_remove_iff_not_mem_convexHull_remove := Convex.convex_remove_iff_notMem_convexHull_remove 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_mono (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 theorem convexHull_add_subset {s t : Set E} : convexHull π•œ (s + t) βŠ† convexHull π•œ s + convexHull π•œ t := convexHull_min (add_subset_add (subset_convexHull _ _) (subset_convexHull _ _)) (Convex.add (convex_convexHull π•œ s) (convex_convexHull π•œ t)) end AddCommMonoid end OrderedSemiring section CommSemiring variable [CommSemiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] [Module π•œ E] theorem convexHull_smul (a : π•œ) (s : Set E) : convexHull π•œ (a β€’ s) = a β€’ convexHull π•œ s := (LinearMap.lsmul _ _ a).image_convexHull _ |>.symm end CommSemiring section OrderedRing variable [Ring π•œ] [PartialOrder π•œ] 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_mono (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_eq_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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Between.lean
import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Basic 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 /-- 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 [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 variable [Ring R] [PartialOrder R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] variable {R} in @[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 @[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) section OrderedRing variable [IsOrderedRing R] 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] end OrderedRing /-- 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} section OrderedRing variable [IsOrderedRing 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] alias ⟨_, Wbtw.mem_segment⟩ := mem_segment_iff_wbtw lemma Convex.mem_of_wbtw {pβ‚€ p₁ pβ‚‚ : V} {s : Set V} (hs : Convex R s) (h₀₁₂ : Wbtw R pβ‚€ p₁ pβ‚‚) (hβ‚€ : pβ‚€ ∈ s) (hβ‚‚ : pβ‚‚ ∈ s) : p₁ ∈ s := hs.segment_subset hβ‚€ hβ‚‚ h₀₁₂.mem_segment 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 end OrderedRing lemma AffineSubspace.mem_of_wbtw {s : AffineSubspace R P} {x y z : P} (hxyz : Wbtw R x y z) (hx : x ∈ s) (hz : z ∈ s) : y ∈ s := by obtain ⟨Ρ, -, rfl⟩ := hxyz; exact lineMap_mem _ hx hz 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 have : Function.Injective f.toAffineMap := f.injective -- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing. apply this.wbtw_map_iff @[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 have : Function.Injective f.toAffineMap := f.injective -- `refine` or `exact` are very slow, `apply` is fast. Please check before golfing. apply this.sbtw_map_iff @[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 _ alias ⟨_, Wbtw.const_vadd⟩ := wbtw_const_vadd_iff @[simp] theorem wbtw_const_add_iff {x y z : V} (v : V) : Wbtw R (v + x) (v + y) (v + z) ↔ Wbtw R x y z := wbtw_const_vadd_iff v alias ⟨_, Wbtw.const_add⟩ := wbtw_const_add_iff @[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 _ alias ⟨_, Wbtw.vadd_const⟩ := wbtw_vadd_const_iff @[simp] theorem wbtw_add_const_iff {x y z : V} (v : V) : Wbtw R (x + v) (y + v) (z + v) ↔ Wbtw R x y z := wbtw_vadd_const_iff v alias ⟨_, Wbtw.add_const⟩ := wbtw_add_const_iff @[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 _ alias ⟨_, Wbtw.const_vsub⟩ := wbtw_const_vsub_iff @[simp] theorem wbtw_const_sub_iff {x y z : V} (v : V) : Wbtw R (v - x) (v - y) (v - z) ↔ Wbtw R x y z := wbtw_const_vsub_iff v alias ⟨_, Wbtw.const_sub⟩ := wbtw_const_sub_iff @[simp] theorem wbtw_neg_iff {x y z : V} : Wbtw R (-x) (-y) (-z) ↔ Wbtw R x y z := by simp only [← zero_sub, wbtw_const_sub_iff] alias ⟨_, Wbtw.neg⟩ := wbtw_neg_iff @[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 _ alias ⟨_, Wbtw.vsub_const⟩ := wbtw_vsub_const_iff @[simp] theorem wbtw_sub_const_iff {x y z : V} (v : V) : Wbtw R (x - v) (y - v) (z - v) ↔ Wbtw R x y z := wbtw_vsub_const_iff v alias ⟨_, Wbtw.sub_const⟩ := wbtw_sub_const_iff @[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] alias ⟨_, Sbtw.const_vadd⟩ := sbtw_const_vadd_iff @[simp] theorem sbtw_const_add_iff {x y z : V} (v : V) : Sbtw R (v + x) (v + y) (v + z) ↔ Sbtw R x y z := sbtw_const_vadd_iff v alias ⟨_, Sbtw.const_add⟩ := sbtw_const_add_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] alias ⟨_, Sbtw.vadd_const⟩ := sbtw_vadd_const_iff @[simp] theorem sbtw_add_const_iff {x y z : V} (v : V) : Sbtw R (x + v) (y + v) (z + v) ↔ Sbtw R x y z := sbtw_vadd_const_iff v alias ⟨_, Sbtw.add_const⟩ := sbtw_add_const_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] alias ⟨_, Sbtw.const_vsub⟩ := sbtw_const_vsub_iff @[simp] theorem sbtw_const_sub_iff {x y z : V} (v : V) : Sbtw R (v - x) (v - y) (v - z) ↔ Sbtw R x y z := sbtw_const_vsub_iff v alias ⟨_, Sbtw.const_sub⟩ := sbtw_const_sub_iff @[simp] theorem sbtw_neg_iff {x y z : V} : Sbtw R (-x) (-y) (-z) ↔ Sbtw R x y z := by simp only [← zero_sub, sbtw_const_sub_iff] alias ⟨_, Sbtw.neg⟩ := sbtw_neg_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] alias ⟨_, Sbtw.vsub_const⟩ := sbtw_vsub_const_iff @[simp] theorem sbtw_sub_const_iff {x y z : V} (v : V) : Sbtw R (x - v) (y - v) (z - v) ↔ Sbtw R x y z := sbtw_vsub_const_iff v alias ⟨_, Sbtw.sub_const⟩ := sbtw_sub_const_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 _ _ _ variable (R) section OrderedRing variable [IsOrderedRing 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 => ?_⟩ Β· simpa [Wbtw, affineSegment] using h Β· rw [h] exact wbtw_self_left R x x end OrderedRing section lift variable [ZeroLEOneClass R] variable (R' : Type*) [Ring R'] [PartialOrder R'] variable [Module R' V] [Module R' R] [IsScalarTower R' R V] [SMulPosMono R' R] theorem affineSegment.lift (x y : P) : affineSegment R' x y βŠ† affineSegment R x y := by rintro p ⟨a, ⟨⟨haβ‚€, haβ‚βŸ©, rfl⟩⟩ refine ⟨a β€’ 1, ⟨?_, ?_⟩, by simp [lineMap_apply]⟩ Β· rw [← zero_smul R' (1 : R)] exact smul_le_smul_of_nonneg_right haβ‚€ zero_le_one Β· nth_rw 2 [← one_smul R' 1] exact smul_le_smul_of_nonneg_right ha₁ zero_le_one variable {R'} in /-- Lift a `Wbtw` predicate from one ring to another along a scalar tower. -/ theorem Wbtw.lift {x y z : P} (h : Wbtw R' x y z) : Wbtw R x y z := affineSegment.lift R R' x z h variable {R'} in /-- Lift a `Sbtw` predicate from one ring to another along a scalar tower. -/ theorem Sbtw.lift {x y z : P} (h : Sbtw R' x y z) : Sbtw R x y z := ⟨h.wbtw.lift R, h.2⟩ end lift @[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} variable [IsOrderedRing 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 [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 omit [IsOrderedRing R] in @[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] omit [IsOrderedRing R] in @[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' namespace Affine namespace Simplex /-- The closed interior of a 1-simplex is a segment between its vertices. -/ lemma closedInterior_eq_affineSegment (s : Simplex R P 1) : s.closedInterior = affineSegment R (s.points 0) (s.points 1) := by ext p constructor Β· rintro ⟨w, hw, h01, rfl⟩ have h : w = Finset.affineCombinationLineMapWeights 0 1 (w 1) := by rw [Fin.sum_univ_two] at hw ext i fin_cases i <;> simp [← hw] rw [h, Finset.univ.affineCombination_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _)] exact Set.mem_image_of_mem _ (h01 _) Β· rintro ⟨r, ⟨h0, h1⟩, rfl⟩ rw [← Finset.univ.affineCombination_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _), affineCombination_mem_closedInterior_iff (Finset.sum_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _) _)] intro i fin_cases i <;> simp [h0, h1] /-- A point lies in the closed interior of a 1-simplex if and only if it lies weakly between its vertices. -/ lemma mem_closedInterior_iff_wbtw {s : Simplex R P 1} {p : P} : p ∈ s.closedInterior ↔ Wbtw R (s.points 0) p (s.points 1) := by rw [closedInterior_eq_affineSegment, Wbtw] /-- The closed interior of a 1-dimensional face of a simplex is a segment between its vertices. -/ lemma closedInterior_face_eq_affineSegment {n : β„•} (s : Simplex R P n) {i j : Fin (n + 1)} (h : i β‰  j) : (s.face (Finset.card_pair h)).closedInterior = affineSegment R (s.points i) (s.points j) := by have h' : affineSegment R (s.points i) (s.points j) = affineSegment R (s.points (min i j)) (s.points (max i j)) := by rcases h.lt_or_gt with hij | hji Β· simp [min_eq_left hij.le, max_eq_right hij.le] Β· nth_rw 2 [affineSegment_comm] simp [max_eq_left hji.le, min_eq_right hji.le] rw [h', (s.face (Finset.card_pair h)).closedInterior_eq_affineSegment, face_points, face_points] congr 2 Β· convert Finset.orderEmbOfFin_zero _ _ Β· exact (Finset.min'_pair i j).symm Β· omega Β· convert Finset.orderEmbOfFin_last _ _ Β· exact (Finset.max'_pair i j).symm Β· omega /-- A point lies in the closed interior of a 1-dimensional face of a simplex if and only if it lies weakly between its vertices. -/ lemma mem_closedInterior_face_iff_wbtw {n : β„•} (s : Simplex R P n) {p : P} {i j : Fin (n + 1)} (h : i β‰  j) : p ∈ (s.face (Finset.card_pair h)).closedInterior ↔ Wbtw R (s.points i) p (s.points j) := by rw [s.closedInterior_face_eq_affineSegment h, Wbtw] /-- The interior of a 1-simplex is a segment between its vertices. -/ lemma interior_eq_image_Ioo (s : Simplex R P 1) : s.interior = AffineMap.lineMap (s.points 0) (s.points 1) '' Set.Ioo (0 : R) 1 := by ext p constructor Β· rintro ⟨w, hw, h01, rfl⟩ have h : w = Finset.affineCombinationLineMapWeights 0 1 (w 1) := by rw [Fin.sum_univ_two] at hw ext i fin_cases i <;> simp [← hw] rw [h, Finset.univ.affineCombination_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _)] exact Set.mem_image_of_mem _ (h01 _) Β· rintro ⟨r, ⟨h0, h1⟩, rfl⟩ rw [← Finset.univ.affineCombination_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _), affineCombination_mem_interior_iff (Finset.sum_affineCombinationLineMapWeights _ (Finset.mem_univ _) (Finset.mem_univ _) _)] intro i fin_cases i <;> simp [h0, h1] /-- A point lies in the interior of a 1-simplex if and only if it lies strictly between its vertices. -/ lemma mem_interior_iff_sbtw [Nontrivial R] [NoZeroSMulDivisors R V] {s : Simplex R P 1} {p : P} : p ∈ s.interior ↔ Sbtw R (s.points 0) p (s.points 1) := by rw [interior_eq_image_Ioo, sbtw_iff_mem_image_Ioo_and_ne] simp [s.independent.injective.ne (by decide : (0 : Fin 2) β‰  1)] /-- A point lies in the interior of a 1-dimensional face of a simplex if and only if it lies strictly between its vertices. -/ lemma mem_interior_face_iff_sbtw [Nontrivial R] [NoZeroSMulDivisors R V] {n : β„•} (s : Simplex R P n) {p : P} {i j : Fin (n + 1)} (h : i β‰  j) : p ∈ (s.face (Finset.card_pair h)).interior ↔ Sbtw R (s.points i) p (s.points j) := by have h' : Sbtw R (s.points i) p (s.points j) ↔ Sbtw R (s.points (min i j)) p (s.points (max i j)) := by rcases h.lt_or_gt with hij | hji Β· simp [min_eq_left hij.le, max_eq_right hij.le] Β· nth_rw 2 [sbtw_comm] simp [max_eq_left hji.le, min_eq_right hji.le] rw [h', mem_interior_iff_sbtw, face_points, face_points] congr! 4 Β· convert Finset.orderEmbOfFin_zero _ _ Β· exact (Finset.min'_pair i j).symm Β· omega Β· convert Finset.orderEmbOfFin_last _ _ Β· exact (Finset.max'_pair i j).symm Β· omega end Simplex end Affine end OrderedRing section StrictOrderedCommRing variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing 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 [Ring R] [LinearOrder R] [IsStrictOrderedRing 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 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 omega have hu : (Finset.univ : Finset (Fin 3)) = {i₁, iβ‚‚, i₃} := by clear h₁ hβ‚‚ h₁' hβ‚‚' decide +revert 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 [Field R] [LinearOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] {x y z : P} variable {R} lemma wbtw_iff_of_le {x y z : R} (hxz : x ≀ z) : Wbtw R x y z ↔ x ≀ y ∧ y ≀ z := by cases hxz.eq_or_lt with | inl hxz => subst hxz rw [← le_antisymm_iff, wbtw_self_iff, eq_comm] | inr hxz => have hxz' : 0 < z - x := sub_pos.mpr hxz let r := (y - x) / (z - x) have hy : y = r * (z - x) + x := by simp [r, hxz'.ne'] simp [hy, wbtw_mul_sub_add_iff, mul_nonneg_iff_of_pos_right hxz', ← le_sub_iff_add_le, mul_le_iff_le_one_left hxz', hxz.ne] lemma Wbtw.of_le_of_le {x y z : R} (hxy : x ≀ y) (hyz : y ≀ z) : Wbtw R x y z := (wbtw_iff_of_le (hxy.trans hyz)).mpr ⟨hxy, hyz⟩ lemma Sbtw.of_lt_of_lt {x y z : R} (hxy : x < y) (hyz : y < z) : Sbtw R x y z := ⟨.of_le_of_le hxy.le hyz.le, hxy.ne', hyz.ne⟩ 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 .inr ⟨r⁻¹, (one_le_invβ‚€ hr0').2 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_of_one_leβ‚€ 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 Β· 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 omit [IsStrictOrderedRing R] in lemma AffineSubspace.right_mem_of_wbtw {s : AffineSubspace R P} (hxyz : Wbtw R x y z) (hx : x ∈ s) (hy : y ∈ s) (hxy : x β‰  y) : z ∈ s := by obtain ⟨Ρ, -, rfl⟩ := hxyz have hΞ΅ : Ξ΅ β‰  0 := by rintro rfl; simp at hxy simpa [hΞ΅] using lineMap_mem Ρ⁻¹ hx hy 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⟩ omit [IsStrictOrderedRing R] in 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 /-- If `T` is an affine independent family of points, then any 3 distinct points form a triangle. -/ theorem AffineIndependent.not_wbtw_of_injective {ΞΉ} (i j k : ΞΉ) (h : Function.Injective ![i, j, k]) {T : ΞΉ β†’ P} (hT : AffineIndependent R T) : Β¬ Wbtw R (T i) (T j) (T k) := by replace hT := hT.comp_embedding ⟨_, h⟩ rw [affineIndependent_iff_not_collinear] at hT contrapose! hT simp [Set.range_comp, Set.image_insert_eq, hT.symm.collinear] variable (R) theorem wbtw_pointReflection (x y : P) : Wbtw R y x (pointReflection R x y) := by refine ⟨2⁻¹, ⟨by simp, 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/PathConnected.lean
import Mathlib.Analysis.Convex.Basic import Mathlib.LinearAlgebra.Projection import Mathlib.Topology.Connected.PathConnected /-! # Segment between 2 points as a bundled path In this file we define `Path.segment a b : Path a b` to be the path going from `a` to `b` along the straight segment with constant velocity `b - a`. We also prove basic properties of this construction, then use it to show that a nonempty convex set is path connected. In particular, a topological vector space over `ℝ` is path connected. -/ open AffineMap Set open scoped Convex unitInterval variable {E : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousSMul ℝ E] namespace Path /-- The path from `a` to `b` going along a straight line segment -/ @[simps] protected def segment (a b : E) : Path a b where toFun t := lineMap a b (t : ℝ) source' := by simp target' := by simp @[simp] theorem range_segment (a b : E) : Set.range (Path.segment a b) = [a -[ℝ] b] := by rw [segment_eq_image_lineMap, image_eq_range] simp only [← segment_apply] @[simp] protected theorem segment_same (a : E) : Path.segment a a = .refl a := by ext; simp @[simp] protected theorem segment_symm (a b : E) : (Path.segment a b).symm = .segment b a := by ext; simp @[simp] theorem segment_add_segment (a b c d : E) : (Path.segment a b).add (.segment c d) = .segment (a + c) (b + d) := by ext simp [lineMap_apply_module, add_add_add_comm] @[simp] theorem cast_segment {a b c d : E} (hac : c = a) (hbd : d = b) : (Path.segment a b).cast hac hbd = .segment c d := by subst_vars; rfl theorem eqOn_extend_segment (a b : E) : EqOn (Path.segment a b).extend (AffineMap.lineMap a b) I := by intro t ht simp [ht] end Path theorem JoinedIn.of_segment_subset {x y : E} {s : Set E} (h : [x -[ℝ] y] βŠ† s) : JoinedIn s x y := by use .segment x y rwa [← range_subset_iff, Path.range_segment] protected theorem StarConvex.isPathConnected {s : Set E} {a : E} (h : StarConvex ℝ a s) (ha : a ∈ s) : IsPathConnected s := ⟨a, ha, fun _y hy ↦ .of_segment_subset <| h.segment_subset hy⟩ /-- A nonempty convex set is path connected. -/ protected theorem Convex.isPathConnected {s : Set E} (hconv : Convex ℝ s) (hne : s.Nonempty) : IsPathConnected s := let ⟨_a, ha⟩ := hne; (hconv ha).isPathConnected ha /-- 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 /-- A subspace in a topological vector space over `ℝ` is path connected. -/ theorem Submodule.isPathConnected (s : Submodule ℝ E) : IsPathConnected (s : Set E) := s.convex.isPathConnected s.nonempty /-- Every topological vector space over ℝ is path connected. Not an instance, because it creates enormous TC subproblems (turn on `pp.all`). -/ protected theorem IsTopologicalAddGroup.pathConnectedSpace : PathConnectedSpace E := pathConnectedSpace_iff_univ.mpr <| convex_univ.isPathConnected ⟨(0 : E), trivial⟩ /-- 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 {p q : Submodule ℝ E} (hpq : IsCompl p q) (hpc : IsPathConnected ({0}ᢜ : Set p)) : IsPathConnected (qᢜ : Set E) := by convert (hpc.image continuous_subtype_val).add q.isPathConnected using 1 trans Submodule.prodEquivOfIsCompl p q hpq '' ({0}ᢜ Γ—Λ’ univ) Β· rw [prod_univ, LinearEquiv.image_eq_preimage_symm] ext simp Β· ext simp [mem_add, and_assoc]
.lake/packages/mathlib/Mathlib/Analysis/Convex/Function.lean
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 LinearMap Set Convex Pointwise variable {π•œ E F Ξ± Ξ² ΞΉ : Type*} section OrderedSemiring variable [Semiring π•œ] [PartialOrder π•œ] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section OrderedAddCommMonoid variable [AddCommMonoid Ξ±] [PartialOrder Ξ±] [AddCommMonoid Ξ²] [PartialOrder Ξ²] 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 [IsOrderedAddMonoid Ξ²] [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 [IsOrderedAddMonoid Ξ²] (hf : ConvexOn π•œ s f) (b : Ξ²) : ConvexOn π•œ s (f + fun _ => b) := hf.add (convexOn_const _ hf.1) theorem ConcaveOn.add_const [IsOrderedAddMonoid Ξ²] (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 PosSMulMono variable [IsOrderedAddMonoid Ξ²] [SMul π•œ E] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] {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 PosSMulMono 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 PosSMulMono variable [IsOrderedAddMonoid Ξ²] [PosSMulMono π•œ Ξ²] {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 PosSMulMono 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 => ?_⟩ 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_gt.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 => ?_⟩ 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_gt.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 `f` is convex on `s`, so is `(f ∘ g)` on `g ⁻¹' s` for a linear `g`. -/ 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 `f` is concave on `s`, so is `(g ∘ f)` on `g ⁻¹' s` for a linear `g`. -/ 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 [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²] 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 β†’ Ξ³} [AddCommMonoid Ξ³] [PartialOrder Ξ³] [IsOrderedCancelAddMonoid Ξ³] [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 β†’ Ξ³} [AddCommMonoid Ξ³] [PartialOrder Ξ³] [IsOrderedCancelAddMonoid Ξ³] [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 π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] {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 [ZeroLEOneClass π•œ] (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 [ZeroLEOneClass π•œ] (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 [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedAddMonoid Ξ²] [SMul π•œ E] [Module π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] {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 [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²] section PosSMulStrictMono variable [SMul π•œ E] [Module π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] {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_gt 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 PosSMulStrictMono section Module variable [Module π•œ E] [Module π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] {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 [AddCommGroup Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [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 => ?_⟩ simpa [add_comm] using 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] [AddCommMonoid Ξ²] [PartialOrder Ξ²] [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 [CommSemiring π•œ] [PartialOrder π•œ] [AddCommMonoid E] section OrderedAddCommMonoid variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] section Module variable [SMul π•œ E] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] {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 [Field π•œ] [LinearOrder π•œ] [AddCommGroup E] [AddCommGroup F] section OrderedAddCommMonoid variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommMonoid E] section OrderedAddCommMonoid variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] 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 [Semiring π•œ] [PartialOrder π•œ] [AddCommMonoid Ξ±] [PartialOrder Ξ±] [SMul π•œ Ξ±] [AddCommMonoid Ξ²] [PartialOrder Ξ²] [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] 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] 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] section OrderedAddCommMonoid variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [AddCommMonoid E] [SMul π•œ E] [Module π•œ Ξ²] [PosSMulMono π•œ Ξ²] {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 simp) (by simp) <| by norm_num refine lt_irrefl (f z) ?_ calc f z < _ := hf.2 hx hy hxy (by simp) (by simp) <| 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 [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²] [Module π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] {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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Contractible.lean
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 _ Β· simp Β· 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/StrictConvexSpace.lean
import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.Normed.Module.Ray import Mathlib.Analysis.Normed.Module.Ball.Pointwise /-! # 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_unitClosedBall`: 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_unitClosedBall`. -/ @[mk_iff] class StrictConvexSpace (π•œ E : Type*) [NormedField π•œ] [PartialOrder π•œ] [NormedAddCommGroup E] [NormedSpace π•œ E] : Prop where strictConvex_closedBall : βˆ€ r : ℝ, 0 < r β†’ StrictConvex π•œ (closedBall (0 : E) r) variable (π•œ : Type*) {E : Type*} [NormedField π•œ] [PartialOrder π•œ] [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_gt 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_unitClosedBall [LinearMap.CompatibleSMul E E π•œ ℝ] (h : StrictConvex π•œ (closedBall (0 : E) 1)) : StrictConvexSpace π•œ E := ⟨fun r hr => by simpa only [smul_unitClosedBall_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_unitClosedBall ℝ ((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_unitClosedBall ℝ ((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_unitClosedBall x) (inv_norm_smul_mem_unitClosedBall 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]
.lake/packages/mathlib/Mathlib/Analysis/Convex/Jensen.lean
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 Convex Pointwise variable {π•œ E F Ξ² ΞΉ : Type*} /-! ### Jensen's inequality -/ section Jensen variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [AddCommGroup Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π•œ E] [Module π•œ Ξ²] [IsStrictOrderedModule π•œ Ξ²] {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 [u, 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 simp [field, c] 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 congrm f ?_ match_scalars <;> simp [field, c] _ ≀ 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 w.r.t. 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 match_scalars <;> simp [field, c] _ = 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_gt <| 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_gt <| 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 w.r.t. `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 w.r.t. `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 w.r.t. `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 simp_all have hw' (i) (_ : i ∈ t) : w i β€’ f (p i) β‰  0 β†’ w i β‰  0 := by simp_all rw [← sum_filter_of_ne hw, ← sum_filter_of_ne hw', hf.map_sum_eq_iff] Β· simp Β· simp +contextual [(hβ‚€ _ _).lt_iff_ne'] Β· rwa [sum_filter_ne_zero] Β· simp +contextual [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 w.r.t. `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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [AddCommGroup E] [AddCommGroup Ξ²] [LinearOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π•œ E] [Module π•œ Ξ²] [IsStrictOrderedModule π•œ Ξ²] {s : Set E} {f : E β†’ Ξ²} {w : ΞΉ β†’ π•œ} {p : ΞΉ β†’ E} {x y z : E} theorem ConvexOn.le_sup_of_mem_convexHull {t : Finset E} (hf : ConvexOn π•œ s f) (hts : ↑t βŠ† s) (hx : x ∈ convexHull π•œ (t : Set E)) : f x ≀ t.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) hts).trans (centerMass_le_sup hwβ‚€ <| by positivity) theorem ConvexOn.inf_le_of_mem_convexHull {t : Finset E} (hf : ConcaveOn π•œ s f) (hts : ↑t βŠ† s) (hx : x ∈ convexHull π•œ (t : Set E)) : t.inf' (coe_nonempty.1 <| convexHull_nonempty_iff.1 ⟨x, hx⟩) f ≀ f x := hf.dual.le_sup_of_mem_convexHull hts 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. -/ lemma ConvexOn.exists_ge_of_centerMass {t : Finset ΞΉ} (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 ∈ {i ∈ t | w i β‰  0}, w i β€’ f y ≀ w i β€’ (f ∘ p) i := by have hw' : (0 : π•œ) < βˆ‘ i ∈ t with w i β‰  0, 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. -/ lemma ConcaveOn.exists_le_of_centerMass {t : Finset ΞΉ} (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) := h.dual.exists_ge_of_centerMass 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`. -/ lemma ConvexOn.exists_ge_of_mem_convexHull {t : Set E} (hf : ConvexOn π•œ s f) (hts : t βŠ† s) (hx : x ∈ convexHull π•œ t) : βˆƒ y ∈ t, f x ≀ f y := by rw [_root_.convexHull_eq] at hx obtain ⟨α, t, w, p, hwβ‚€, hw₁, hp, rfl⟩ := hx obtain ⟨i, hit, Hi⟩ := hf.exists_ge_of_centerMass hwβ‚€ (hw₁.symm β–Έ zero_lt_one) fun i hi ↦ hts (hp i 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`. -/ lemma ConcaveOn.exists_le_of_mem_convexHull {t : Set E} (hf : ConcaveOn π•œ s f) (hts : t βŠ† s) (hx : x ∈ convexHull π•œ t) : βˆƒ y ∈ t, f y ≀ f x := hf.dual.exists_ge_of_mem_convexHull hts 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 π•œ s f) (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[π•œ] y]) : f z ≀ max (f x) (f y) := by rw [← convexHull_pair] at hz; simpa using hf.exists_ge_of_mem_convexHull (pair_subset hx hy) 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 π•œ s f) (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[π•œ] y]) : min (f x) (f y) ≀ f z := hf.dual.le_max_of_mem_segment hx hy 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 {s : Set π•œ} {f : π•œ β†’ Ξ²} {x y z : π•œ} (hf : ConvexOn π•œ s f) (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ Icc x y) : f z ≀ max (f x) (f y) := by rw [← segment_eq_Icc (hz.1.trans hz.2)] at hz; exact hf.le_max_of_mem_segment hx hy 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 {s : Set π•œ} {f : π•œ β†’ Ξ²} {x y z : π•œ} (hf : ConcaveOn π•œ s f) (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ Icc x y) : min (f x) (f y) ≀ f z := hf.dual.le_max_of_mem_Icc hx hy hz lemma ConvexOn.bddAbove_convexHull {s t : Set E} (hst : s βŠ† t) (hf : ConvexOn π•œ t f) : BddAbove (f '' s) β†’ BddAbove (f '' convexHull π•œ s) := by rintro ⟨b, hb⟩ refine ⟨b, ?_⟩ rintro _ ⟨x, hx, rfl⟩ obtain ⟨y, hy, hxy⟩ := hf.exists_ge_of_mem_convexHull hst hx exact hxy.trans <| hb <| mem_image_of_mem _ hy lemma ConcaveOn.bddBelow_convexHull {s t : Set E} (hst : s βŠ† t) (hf : ConcaveOn π•œ t f) : BddBelow (f '' s) β†’ BddBelow (f '' convexHull π•œ s) := hf.dual.bddAbove_convexHull hst end MaximumPrinciple
.lake/packages/mathlib/Mathlib/Analysis/Convex/Continuous.lean
import Mathlib.Analysis.Normed.Affine.Convex /-! # Convex functions are continuous This file proves that a convex function from a finite-dimensional real normed space to `ℝ` is continuous. -/ open FiniteDimensional Metric Set List Bornology open scoped Topology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {C : Set E} {f : E β†’ ℝ} {xβ‚€ : E} {Ξ΅ r r' M : ℝ} lemma ConvexOn.lipschitzOnWith_of_abs_le (hf : ConvexOn ℝ (ball xβ‚€ r) f) (hΞ΅ : 0 < Ξ΅) (hM : βˆ€ a, dist a xβ‚€ < r β†’ |f a| ≀ M) : LipschitzOnWith (2 * M / Ξ΅).toNNReal f (ball xβ‚€ (r - Ξ΅)) := by set K := 2 * M / Ξ΅ with hK have oneside {x y : E} (hx : x ∈ ball xβ‚€ (r - Ξ΅)) (hy : y ∈ ball xβ‚€ (r - Ξ΅)) : f x - f y ≀ K * β€–x - yβ€– := by obtain rfl | hxy := eq_or_ne x y Β· simp have hxβ‚€r : ball xβ‚€ (r - Ξ΅) βŠ† ball xβ‚€ r := ball_subset_ball <| by linarith have hx' : x ∈ ball xβ‚€ r := hxβ‚€r hx have hy' : y ∈ ball xβ‚€ r := hxβ‚€r hy let z := x + (Ξ΅ / β€–x - yβ€–) β€’ (x - y) replace hxy : 0 < β€–x - yβ€– := by rwa [norm_sub_pos_iff] have hz : z ∈ ball xβ‚€ r := mem_ball_iff_norm.2 <| by calc _ = β€–(x - xβ‚€) + (Ξ΅ / β€–x - yβ€–) β€’ (x - y)β€– := by simp only [z, add_sub_right_comm] _ ≀ β€–x - xβ‚€β€– + β€–(Ξ΅ / β€–x - yβ€–) β€’ (x - y)β€– := norm_add_le .. _ < r - Ξ΅ + Ξ΅ := add_lt_add_of_lt_of_le (mem_ball_iff_norm.1 hx) <| by simp [norm_smul, abs_of_nonneg, hΞ΅.le, hxy.ne'] _ = r := by simp let a := Ξ΅ / (Ξ΅ + β€–x - yβ€–) let b := β€–x - yβ€– / (Ξ΅ + β€–x - yβ€–) have hab : a + b = 1 := by simp [field, a, b] have hxyz : x = a β€’ y + b β€’ z := by calc x = a β€’ x + b β€’ x := by rw [Convex.combo_self hab] _ = a β€’ y + b β€’ z := by simp [z, a, b, smul_smul, hxy.ne', smul_sub]; abel rw [hK, mul_comm, ← mul_div_assoc, le_div_iffβ‚€' hΞ΅] calc Ξ΅ * (f x - f y) ≀ β€–x - yβ€– * (f z - f x) := by have h := hf.2 hy' hz (by positivity) (by positivity) hab simp only [← hxyz, smul_eq_mul, a, b] at h field_simp at h linear_combination h _ ≀ _ := by rw [sub_eq_add_neg (f _), two_mul] gcongr Β· exact (le_abs_self _).trans <| hM _ hz Β· exact (neg_le_abs _).trans <| hM _ hx' refine .of_dist_le' fun x hx y hy ↦ ?_ simp_rw [dist_eq_norm_sub, Real.norm_eq_abs, abs_sub_le_iff] exact ⟨oneside hx hy, norm_sub_rev x _ β–Έ oneside hy hx⟩ lemma ConcaveOn.lipschitzOnWith_of_abs_le (hf : ConcaveOn ℝ (ball xβ‚€ r) f) (hΞ΅ : 0 < Ξ΅) (hM : βˆ€ a, dist a xβ‚€ < r β†’ |f a| ≀ M) : LipschitzOnWith (2 * M / Ξ΅).toNNReal f (ball xβ‚€ (r - Ξ΅)) := by simpa using hf.neg.lipschitzOnWith_of_abs_le hΞ΅ <| by simpa using hM lemma ConvexOn.exists_lipschitzOnWith_of_isBounded (hf : ConvexOn ℝ (ball xβ‚€ r) f) (hr : r' < r) (hf' : IsBounded (f '' ball xβ‚€ r)) : βˆƒ K, LipschitzOnWith K f (ball xβ‚€ r') := by rw [isBounded_iff_subset_ball 0] at hf' simp only [Set.subset_def, mem_image, mem_ball, dist_zero_right, Real.norm_eq_abs, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] at hf' obtain ⟨M, hM⟩ := hf' rw [← sub_sub_cancel r r'] exact ⟨_, hf.lipschitzOnWith_of_abs_le (sub_pos.2 hr) fun a ha ↦ (hM a ha).le⟩ lemma ConcaveOn.exists_lipschitzOnWith_of_isBounded (hf : ConcaveOn ℝ (ball xβ‚€ r) f) (hr : r' < r) (hf' : IsBounded (f '' ball xβ‚€ r)) : βˆƒ K, LipschitzOnWith K f (ball xβ‚€ r') := by replace hf' : IsBounded ((-f) '' ball xβ‚€ r) := by convert hf'.neg; ext; simp [neg_eq_iff_eq_neg] simpa using hf.neg.exists_lipschitzOnWith_of_isBounded hr hf' lemma ConvexOn.isBoundedUnder_abs (hf : ConvexOn ℝ C f) {xβ‚€ : E} (hC : C ∈ 𝓝 xβ‚€) : (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) |f| ↔ (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) f := by refine ⟨fun h ↦ h.mono_le <| .of_forall fun x ↦ le_abs_self _, ?_⟩ rintro ⟨r, hr⟩ refine ⟨|r| + 2 * |f xβ‚€|, ?_⟩ have : (𝓝 xβ‚€).Tendsto (fun y => 2 β€’ xβ‚€ - y) (𝓝 xβ‚€) := tendsto_nhds_nhds.2 (⟨·, Β·, by simp [two_nsmul, dist_comm]⟩) simp only [Filter.eventually_map, Pi.abs_apply, abs_le'] at hr ⊒ filter_upwards [this.eventually_mem hC, hC, hr, this.eventually hr] with y hx hx' hfr hfr' refine ⟨hfr.trans <| (le_abs_self _).trans <| by simp, ?_⟩ rw [← sub_le_iff_le_add, neg_sub_comm, sub_le_iff_le_add', ← abs_two, ← abs_mul] calc -|2 * f xβ‚€| ≀ 2 * f xβ‚€ := neg_abs_le _ _ ≀ f y + f (2 β€’ xβ‚€ - y) := by have := hf.2 hx' hx (by positivity) (by positivity) (add_halves _) simp only [one_div, ← Nat.cast_smul_eq_nsmul ℝ, Nat.cast_ofNat, smul_sub, ne_eq, OfNat.ofNat_ne_zero, not_false_eq_true, inv_smul_smulβ‚€, add_sub_cancel, smul_eq_mul] at this cancel_denoms at this rwa [← Nat.cast_two, Nat.cast_smul_eq_nsmul] at this _ ≀ f y + |r| := by gcongr; exact hfr'.trans (le_abs_self _) lemma ConcaveOn.isBoundedUnder_abs (hf : ConcaveOn ℝ C f) {xβ‚€ : E} (hC : C ∈ 𝓝 xβ‚€) : (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) |f| ↔ (𝓝 xβ‚€).IsBoundedUnder (Β· β‰₯ Β·) f := by simpa [Pi.neg_def, Pi.abs_def] using hf.neg.isBoundedUnder_abs hC lemma ConvexOn.continuousOn_tfae (hC : IsOpen C) (hC' : C.Nonempty) (hf : ConvexOn ℝ C f) : TFAE [ LocallyLipschitzOn C f, ContinuousOn f C, βˆƒ xβ‚€ ∈ C, ContinuousAt f xβ‚€, βˆƒ xβ‚€ ∈ C, (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) f, βˆ€ ⦃x₀⦄, xβ‚€ ∈ C β†’ (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) f, βˆ€ ⦃x₀⦄, xβ‚€ ∈ C β†’ (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) |f|] := by tfae_have 1 β†’ 2 := LocallyLipschitzOn.continuousOn tfae_have 2 β†’ 3 := by obtain ⟨xβ‚€, hxβ‚€βŸ© := hC' exact fun h ↦ ⟨xβ‚€, hxβ‚€, h.continuousAt <| hC.mem_nhds hxβ‚€βŸ© tfae_have 3 β†’ 4 | ⟨xβ‚€, hxβ‚€, h⟩ => ⟨xβ‚€, hxβ‚€, f xβ‚€ + 1, by simpa using h.eventually (eventually_le_nhds (by simp))⟩ tfae_have 4 β†’ 5 | ⟨xβ‚€, hxβ‚€, r, hr⟩, x, hx => by have : βˆ€αΆ  Ξ΄ in 𝓝 (0 : ℝ), (1 - Ξ΄)⁻¹ β€’ x - (Ξ΄ / (1 - Ξ΄)) β€’ xβ‚€ ∈ C := by have h : ContinuousAt (fun Ξ΄ : ℝ ↦ (1 - Ξ΄)⁻¹ β€’ x - (Ξ΄ / (1 - Ξ΄)) β€’ xβ‚€) 0 := by fun_prop (disch := norm_num) exact h (by simpa using hC.mem_nhds hx) obtain ⟨δ, hΞ΄β‚€, hy, hΞ΄β‚βŸ© := (this.and <| eventually_lt_nhds zero_lt_one).exists_gt set y := (1 - Ξ΄)⁻¹ β€’ x - (Ξ΄ / (1 - Ξ΄)) β€’ xβ‚€ refine ⟨max r (f y), ?_⟩ simp only [Filter.eventually_map] at hr ⊒ obtain ⟨Ρ, hΞ΅, hr⟩ := Metric.eventually_nhds_iff.1 <| hr.and (hC.eventually_mem hxβ‚€) refine Metric.eventually_nhds_iff.2 ⟨Ρ * Ξ΄, by positivity, fun z hz ↦ ?_⟩ have hxβ‚€' : δ⁻¹ β€’ (x - y) + y = xβ‚€ := MulAction.injectiveβ‚€ (sub_ne_zero.2 hδ₁.ne') <| by simp [y, smul_sub, smul_smul, hΞ΄β‚€.ne', div_eq_mul_inv, sub_ne_zero.2 hδ₁.ne', mul_left_comm, sub_mul, sub_smul] let w := δ⁻¹ β€’ (z - y) + y have hwyz : Ξ΄ β€’ w + (1 - Ξ΄) β€’ y = z := by simp [w, hΞ΄β‚€.ne', sub_smul] have hw : dist w xβ‚€ < Ξ΅ := by simpa [w, ← hxβ‚€', dist_smulβ‚€, abs_of_nonneg, hΞ΄β‚€.le, inv_mul_lt_iffβ‚€', hΞ΄β‚€] calc f z ≀ max (f w) (f y) := hf.le_max_of_mem_segment (hr hw).2 hy ⟨_, _, hΞ΄β‚€.le, sub_nonneg.2 hδ₁.le, by simp, hwyz⟩ _ ≀ max r (f y) := by gcongr; exact (hr hw).1 tfae_have 6 ↔ 5 := forallβ‚‚_congr fun xβ‚€ hxβ‚€ ↦ hf.isBoundedUnder_abs (hC.mem_nhds hxβ‚€) tfae_have 6 β†’ 1 | h, x, hx => by obtain ⟨r, hr⟩ := h hx obtain ⟨Ρ, hΞ΅, hΞ΅D⟩ := Metric.mem_nhds_iff.1 <| Filter.inter_mem (hC.mem_nhds hx) hr simp only [preimage_setOf_eq, Pi.abs_apply, subset_inter_iff, hC.nhdsWithin_eq hx] at hΞ΅D ⊒ obtain ⟨K, hK⟩ := exists_lipschitzOnWith_of_isBounded (hf.subset hΞ΅D.1 (convex_ball ..)) (half_lt_self hΞ΅) <| isBounded_iff_forall_norm_le.2 ⟨r, by simpa using hΞ΅D.2⟩ exact ⟨K, _, ball_mem_nhds _ (by simpa), hK⟩ tfae_finish lemma ConcaveOn.continuousOn_tfae (hC : IsOpen C) (hC' : C.Nonempty) (hf : ConcaveOn ℝ C f) : TFAE [ LocallyLipschitzOn C f, ContinuousOn f C, βˆƒ xβ‚€ ∈ C, ContinuousAt f xβ‚€, βˆƒ xβ‚€ ∈ C, (𝓝 xβ‚€).IsBoundedUnder (Β· β‰₯ Β·) f, βˆ€ ⦃x₀⦄, xβ‚€ ∈ C β†’ (𝓝 xβ‚€).IsBoundedUnder (Β· β‰₯ Β·) f, βˆ€ ⦃x₀⦄, xβ‚€ ∈ C β†’ (𝓝 xβ‚€).IsBoundedUnder (Β· ≀ Β·) |f|] := by have := hf.neg.continuousOn_tfae hC hC' simp only [locallyLipschitzOn_neg_iff, continuousOn_neg_iff, continuousAt_neg_iff, abs_neg] at this convert this using 8 <;> exact (Equiv.neg ℝ).exists_congr (by simp) lemma ConvexOn.locallyLipschitzOn_iff_continuousOn (hC : IsOpen C) (hf : ConvexOn ℝ C f) : LocallyLipschitzOn C f ↔ ContinuousOn f C := by obtain rfl | hC' := C.eq_empty_or_nonempty Β· simp Β· exact (hf.continuousOn_tfae hC hC').out 0 1 lemma ConcaveOn.locallyLipschitzOn_iff_continuousOn (hC : IsOpen C) (hf : ConcaveOn ℝ C f) : LocallyLipschitzOn C f ↔ ContinuousOn f C := by simpa using hf.neg.locallyLipschitzOn_iff_continuousOn hC variable [FiniteDimensional ℝ E] protected lemma ConvexOn.locallyLipschitzOn (hC : IsOpen C) (hf : ConvexOn ℝ C f) : LocallyLipschitzOn C f := by obtain rfl | ⟨xβ‚€, hxβ‚€βŸ© := C.eq_empty_or_nonempty Β· simp Β· obtain ⟨b, hxβ‚€b, hbC⟩ := exists_mem_interior_convexHull_affineBasis (hC.mem_nhds hxβ‚€) refine ((hf.continuousOn_tfae hC ⟨xβ‚€, hxβ‚€βŸ©).out 3 0).mp ?_ refine ⟨xβ‚€, hxβ‚€, BddAbove.isBoundedUnder (IsOpen.mem_nhds isOpen_interior hxβ‚€b) ?_⟩ exact (hf.bddAbove_convexHull ((subset_convexHull ..).trans hbC) ((finite_range _).image _).bddAbove).mono (by gcongr; exact interior_subset) protected lemma ConcaveOn.locallyLipschitzOn (hC : IsOpen C) (hf : ConcaveOn ℝ C f) : LocallyLipschitzOn C f := by simpa using hf.neg.locallyLipschitzOn hC protected lemma ConvexOn.continuousOn (hC : IsOpen C) (hf : ConvexOn ℝ C f) : ContinuousOn f C := (hf.locallyLipschitzOn hC).continuousOn protected lemma ConcaveOn.continuousOn (hC : IsOpen C) (hf : ConcaveOn ℝ C f) : ContinuousOn f C := (hf.locallyLipschitzOn hC).continuousOn lemma ConvexOn.locallyLipschitzOn_interior (hf : ConvexOn ℝ C f) : LocallyLipschitzOn (interior C) f := (hf.subset interior_subset hf.1.interior).locallyLipschitzOn isOpen_interior lemma ConcaveOn.locallyLipschitzOn_interior (hf : ConcaveOn ℝ C f) : LocallyLipschitzOn (interior C) f := (hf.subset interior_subset hf.1.interior).locallyLipschitzOn isOpen_interior lemma ConvexOn.continuousOn_interior (hf : ConvexOn ℝ C f) : ContinuousOn f (interior C) := hf.locallyLipschitzOn_interior.continuousOn lemma ConcaveOn.continuousOn_interior (hf : ConcaveOn ℝ C f) : ContinuousOn f (interior C) := hf.locallyLipschitzOn_interior.continuousOn protected lemma ConvexOn.locallyLipschitz (hf : ConvexOn ℝ univ f) : LocallyLipschitz f := by simpa using hf.locallyLipschitzOn_interior protected lemma ConcaveOn.locallyLipschitz (hf : ConcaveOn ℝ univ f) : LocallyLipschitz f := by simpa using hf.locallyLipschitzOn_interior -- Commented out since `intrinsicInterior` is not imported (but should be once these are proved) -- proof_wanted ConvexOn.locallyLipschitzOn_intrinsicInterior (hf : ConvexOn ℝ C f) : -- ContinuousOn f (intrinsicInterior ℝ C) -- proof_wanted ConcaveOn.locallyLipschitzOn_intrinsicInterior (hf : ConcaveOn ℝ C f) : -- ContinuousOn f (intrinsicInterior ℝ C) -- proof_wanted ConvexOn.continuousOn_intrinsicInterior (hf : ConvexOn ℝ C f) : -- ContinuousOn f (intrinsicInterior ℝ C) -- proof_wanted ConcaveOn.continuousOn_intrinsicInterior (hf : ConcaveOn ℝ C f) : -- ContinuousOn f (intrinsicInterior ℝ C)
.lake/packages/mathlib/Mathlib/Analysis/Convex/Extrema.lean
import Mathlib.Analysis.Convex.Function import Mathlib.Topology.Algebra.Affine import Mathlib.Topology.Order.LocalExtr import Mathlib.Topology.MetricSpace.Pseudo.Lemmas /-! # 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] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [AddCommGroup Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module ℝ Ξ²] [IsOrderedModule ℝ Ξ²] [PosSMulReflectLE ℝ Ξ²] {s : Set E} open Set Filter Function 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_nhdsGE 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_nhdsGT 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_iff_image_subset, ← 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Measure.lean
import Mathlib.Analysis.Normed.Affine.AddTorsorBases import Mathlib.Analysis.Normed.Module.Convex 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 Module (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. -/ rcases 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.nullMeasurableSet 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 : β„• := Module.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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Intrinsic.lean
import Mathlib.Analysis.Normed.Affine.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 Topology 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_mono 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 @[simp] theorem intrinsicInterior_singleton (x : P) : intrinsicInterior π•œ ({x} : Set P) = {x} := by simp only [intrinsicInterior, preimage_coe_affineSpan_singleton, interior_univ, image_univ, Subtype.range_coe_subtype, mem_affineSpan_singleton, setOf_eq_eq_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 simp only [intrinsicClosure, preimage_coe_affineSpan_singleton, closure_univ, image_univ, Subtype.range_coe_subtype, mem_affineSpan_singleton, setOf_eq_eq_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) := hs.isClosedEmbedding_subtypeVal.isClosedMap _ isClosed_closure theorem isClosed_intrinsicFrontier (hs : IsClosed (affineSpan π•œ s : Set P)) : IsClosed (intrinsicFrontier π•œ s) := hs.isClosedEmbedding_subtypeVal.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 theorem intrinsicClosure_eq_closure_inter_affineSpan (s : Set P) : intrinsicClosure π•œ s = closure s ∩ affineSpan π•œ s := by have h : Topology.IsInducing ((↑) : affineSpan π•œ s β†’ P) := .subtypeVal rw [intrinsicClosure, h.closure_eq_preimage_closure_image, Set.image_preimage_eq_inter_range, Set.image_preimage_eq_of_subset ?_, Subtype.range_coe] rw [Subtype.range_coe] apply subset_affineSpan end AddTorsor namespace AffineIsometry variable [NormedField π•œ] [SeminormedAddCommGroup V] [SeminormedAddCommGroup W] [NormedSpace π•œ V] [NormedSpace π•œ W] [MetricSpace P] [PseudoMetricSpace Q] [NormedAddTorsor V P] [NormedAddTorsor W Q] @[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 section Convex variable [Field π•œ] [LinearOrder π•œ] [AddCommGroup V] [Module π•œ V] [TopologicalSpace V] [IsTopologicalAddGroup V] [ContinuousConstSMul π•œ V] {s : Set V} protected theorem Convex.intrinsicClosure (hs : Convex π•œ s) : Convex π•œ (intrinsicClosure π•œ s) := by rw [intrinsicClosure_eq_closure_inter_affineSpan] exact hs.closure.inter (affineSpan π•œ s).convex end Convex 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⟩
.lake/packages/mathlib/Mathlib/Analysis/Convex/PartitionOfUnity.lean
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⟩
.lake/packages/mathlib/Mathlib/Analysis/Convex/StdSimplex.lean
import Mathlib.Analysis.Convex.Combination import Mathlib.Analysis.Convex.PathConnected import Mathlib.Topology.Algebra.Monoid.FunOnFinite import Mathlib.Topology.MetricSpace.ProperSpace.Real import Mathlib.Topology.UnitInterval /-! # The standard simplex In this file, given an ordered semiring `π•œ` and a finite type `ΞΉ`, we define `stdSimplex : Set (ΞΉ β†’ π•œ)` as the set of vectors with non-negative coordinates with total sum `1`. When `f : X β†’ Y` is a map between finite types, we define the map `stdSimplex.map f : stdSimplex π•œ X β†’ stdSimplex π•œ Y`. -/ open Set Convex Bornology section OrderedSemiring variable (π•œ) (ΞΉ : Type*) [Semiring π•œ] [PartialOrder π•œ] [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 [IsOrderedRing π•œ] : 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] Β· simp_rw [Pi.add_apply, Pi.smul_apply] rwa [Finset.sum_add_distrib, ← Finset.smul_sum, ← Finset.smul_sum, hf.2, hg.2, smul_eq_mul, smul_eq_mul, mul_one, mul_one] @[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_notMem <| by rintro f ⟨-, hf⟩; simp at hf lemma stdSimplex_unique [ZeroLEOneClass π•œ] [Nonempty ΞΉ] [Subsingleton ΞΉ] : stdSimplex π•œ ΞΉ = {fun _ ↦ 1} := by cases nonempty_unique ΞΉ 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 {ΞΉ} variable {π•œ} in /-- All values of a function `f ∈ stdSimplex π•œ ΞΉ` belong to `[0, 1]`. -/ theorem mem_Icc_of_mem_stdSimplex [IsOrderedAddMonoid π•œ] {f : ΞΉ β†’ π•œ} (hf : f ∈ stdSimplex π•œ ΞΉ) (x) : f x ∈ Icc (0 : π•œ) 1 := ⟨hf.1 x, hf.2 β–Έ Finset.single_le_sum (fun y _ => hf.1 y) (Finset.mem_univ x)⟩ variable [DecidableEq ΞΉ] [ZeroLEOneClass π•œ] 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 variable [IsOrderedRing π•œ] #adaptation_note /-- 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 (π•œ) [Ring π•œ] [PartialOrder π•œ] [IsOrderedRing π•œ] /-- The standard one-dimensional simplex in `Fin 2 β†’ π•œ` is equivalent to the unit interval. This bijection sends the zeroth vertex `Pi.single 0 1` to `0` and the first vertex `Pi.single 1 1` to `1`. -/ @[simps -fullyApplied] def stdSimplexEquivIcc : stdSimplex π•œ (Fin 2) ≃ Icc (0 : π•œ) 1 where toFun f := ⟨f.1 1, f.2.1 _, f.2.2 β–Έ Finset.single_le_sum (fun i _ ↦ f.2.1 i) (Finset.mem_univ _)⟩ invFun x := ⟨![1 - x, x], Fin.forall_fin_two.2 ⟨sub_nonneg.2 x.2.2, x.2.1⟩, by simp⟩ left_inv f := Subtype.eq <| funext <| Fin.forall_fin_two.2 <| by simp [← (show f.1 0 + f.1 1 = 1 by simpa using f.2.2)] @[simp] lemma stdSimplexEquivIcc_zero : stdSimplexEquivIcc π•œ ⟨_, single_mem_stdSimplex π•œ 0⟩ = 0 := rfl @[simp] lemma stdSimplexEquivIcc_one : stdSimplexEquivIcc π•œ ⟨_, single_mem_stdSimplex π•œ 1⟩ = 1 := rfl end OrderedRing section Field variable (R : Type*) (ΞΉ : Type*) [Field R] [LinearOrder R] [IsStrictOrderedRing R] [Fintype ΞΉ] /-- `stdSimplex π•œ ΞΉ` is the convex hull of the canonical basis in `ΞΉ β†’ π•œ`. -/ theorem convexHull_basis_eq_stdSimplex [DecidableEq ΞΉ] : 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] rw [← 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 /-- `stdSimplex π•œ ΞΉ` is the convex hull of the points `Pi.single i 1` for `i : ΞΉ`. -/ theorem convexHull_rangle_single_eq_stdSimplex [DecidableEq ΞΉ] : convexHull R (range fun i : ΞΉ ↦ Pi.single i 1) = stdSimplex R ΞΉ := by convert convexHull_basis_eq_stdSimplex R ΞΉ aesop variable {ΞΉ R} /-- 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 {E : Type*} [AddCommGroup E] [Module R E] {s : Set E} (hs : s.Finite) : convexHull R s = haveI := hs.fintype (⇑(βˆ‘ x : s, (LinearMap.proj (R := R) x).smulRight x.1)) '' stdSimplex R s := by classical letI := hs.fintype rw [← convexHull_basis_eq_stdSimplex, LinearMap.image_convexHull, ← Set.range_comp] apply congr_arg aesop end Field section Topology variable {ΞΉ : Type*} [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 _ /-- `stdSimplex ℝ ΞΉ` is path connected. -/ theorem isPathConnected_stdSimplex [Nonempty ΞΉ] : IsPathConnected (stdSimplex ℝ ΞΉ) := (convex_stdSimplex ℝ ΞΉ).isPathConnected (by classical exact ⟨_, single_mem_stdSimplex ℝ (Classical.arbitrary ΞΉ)⟩) instance [Nonempty ΞΉ] : PathConnectedSpace (stdSimplex ℝ ΞΉ) := isPathConnected_iff_pathConnectedSpace.1 (isPathConnected_stdSimplex _) /-- The standard one-dimensional simplex in `ℝ² = Fin 2 β†’ ℝ` is homeomorphic to the unit interval. -/ @[simps! -fullyApplied] def stdSimplexHomeomorphUnitInterval : stdSimplex ℝ (Fin 2) β‰ƒβ‚œ unitInterval where toEquiv := stdSimplexEquivIcc ℝ continuous_toFun := .subtype_mk ((continuous_apply 1).comp continuous_subtype_val) _ continuous_invFun := by apply Continuous.subtype_mk exact (continuous_pi <| Fin.forall_fin_two.2 ⟨continuous_const.sub continuous_subtype_val, continuous_subtype_val⟩) @[simp] lemma stdSimplexHomeomorphUnitInterval_zero : stdSimplexHomeomorphUnitInterval ⟨_, single_mem_stdSimplex _ 0⟩ = 0 := rfl @[simp] lemma stdSimplexHomeomorphUnitInterval_one : stdSimplexHomeomorphUnitInterval ⟨_, single_mem_stdSimplex _ 1⟩ = 1 := rfl end Topology namespace stdSimplex variable {S : Type*} [Semiring S] [PartialOrder S] {X Y Z : Type*} [Fintype X] [Fintype Y] [Fintype Z] instance : FunLike (stdSimplex S X) X S where coe s := s.val coe_injective' := by aesop @[ext high] lemma ext {s t : stdSimplex S X} (h : (s : X β†’ S) = t) : s = t := by ext : 1 assumption @[simp] lemma zero_le (s : stdSimplex S X) (x : X) : 0 ≀ s x := s.2.1 x @[simp] lemma sum_eq_one (s : stdSimplex S X) : βˆ‘ x, s x = 1 := s.2.2 lemma add_eq_one (s : stdSimplex S (Fin 2)) : s 0 + s 1 = 1 := by simpa only [Fin.sum_univ_two] using sum_eq_one s section variable [IsOrderedRing S] @[simp] lemma le_one (s : stdSimplex S X) (x : X) : s x ≀ 1 := by rw [← sum_eq_one s] simpa only using Finset.single_le_sum (by simp) (by simp) lemma image_linearMap (f : X β†’ Y) : Set.image (FunOnFinite.linearMap S S f) (stdSimplex S X) βŠ† stdSimplex S Y := by classical rintro _ ⟨s, ⟨hsβ‚€, hsβ‚βŸ©, rfl⟩ refine ⟨fun y ↦ ?_, ?_⟩ Β· rw [FunOnFinite.linearMap_apply_apply] exact Finset.sum_nonneg (by aesop) Β· simp only [FunOnFinite.linearMap_apply_apply, ← hs₁] exact Finset.sum_fiberwise Finset.univ f s /-- The map `stdSimplex S X β†’ stdSimplex S Y` that is induced by a map `f : X β†’ Y`. -/ noncomputable def map (f : X β†’ Y) (s : stdSimplex S X) : stdSimplex S Y := ⟨FunOnFinite.linearMap S S f s, image_linearMap f (by aesop)⟩ @[simp] lemma map_coe (f : X β†’ Y) (s : stdSimplex S X) : ⇑(map f s) = FunOnFinite.linearMap S S f s := rfl @[simp] lemma map_id_apply (x : stdSimplex S X) : map id x = x := by aesop lemma map_comp_apply (f : X β†’ Y) (g : Y β†’ Z) (x : stdSimplex S X) : map g (map f x) = map (g.comp f) x := by ext simp [FunOnFinite.linearMap_comp] /-- The vertex corresponding to `x : X` in `stdSimplex S X`. -/ abbrev vertex [DecidableEq X] (x : X) : stdSimplex S X := ⟨Pi.single x 1, single_mem_stdSimplex S x⟩ @[simp] lemma vertex_coe [DecidableEq X] (x : X) : ⇑(vertex (S := S) x) = Pi.single x 1 := rfl @[simp] lemma map_vertex [DecidableEq X] [DecidableEq Y] (f : X β†’ Y) (x : X) : map (S := S) f (vertex x) = vertex (f x) := by aesop @[continuity] lemma continuous_map [TopologicalSpace S] [IsTopologicalSemiring S] (f : X β†’ Y) : Continuous (map (S := S) f) := Continuous.subtype_mk ((FunOnFinite.continuous_linearMap S S f).comp continuous_induced_dom) _ lemma vertex_injective [Nontrivial S] [DecidableEq X] : Function.Injective (vertex (S := S) (X := X)) := by intro x y h replace h := DFunLike.congr_fun h x by_contra! simp [Pi.single_eq_of_ne this] at h instance [Nonempty X] : Nonempty (stdSimplex S X) := by classical exact ⟨vertex (Classical.arbitrary _)⟩ instance [Nontrivial S] [Nontrivial X] : Nontrivial (stdSimplex S X) where exists_pair_ne := by classical obtain ⟨x, y, hxy⟩ := exists_pair_ne X exact ⟨vertex x, vertex y, fun h ↦ hxy (vertex_injective h)⟩ instance [Subsingleton X] : Subsingleton (stdSimplex S X) where allEq s t := by ext i have (u : stdSimplex S X) : u i = 1 := by rw [← sum_eq_one u, Finset.sum_eq_single i _ (by simp)] intro j _ hj exact (hj (Subsingleton.elim j i)).elim simp [this] instance [Unique X] : Unique (stdSimplex S X) where default := ⟨1, by simp, by simp⟩ uniq := by subsingleton @[simp] lemma eq_one_of_unique [Unique X] (s : stdSimplex S X) (x : X) : s x = 1 := by obtain rfl : s = default := by subsingleton rfl end end stdSimplex
.lake/packages/mathlib/Mathlib/Analysis/Convex/DoublyStochasticMatrix.lean
import Mathlib.Analysis.Convex.Basic import Mathlib.LinearAlgebra.Matrix.Permutation /-! # Doubly stochastic matrices ## Main definitions * `doublyStochastic`: a square matrix is doubly stochastic if all entries are nonnegative, and left or right multiplication by the vector of all 1s gives the vector of all 1s. Equivalently, all row and column sums are equal to 1. ## Main statements * `convex_doublyStochastic`: The set of doubly stochastic matrices is convex. * `permMatrix_mem_doublyStochastic`: Any permutation matrix is doubly stochastic. ## TODO Define the submonoids of row-stochastic and column-stochastic matrices. Show that the submonoid of doubly stochastic matrices is the meet of them, or redefine it as such. ## Tags Doubly stochastic, Birkhoff's theorem, Birkhoff-von Neumann theorem -/ open Finset Function Matrix variable {R n : Type*} [Fintype n] [DecidableEq n] section OrderedSemiring variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {M : Matrix n n R} /-- A square matrix is doubly stochastic iff all entries are nonnegative, and left or right multiplication by the vector of all 1s gives the vector of all 1s. -/ def doublyStochastic (R n : Type*) [Fintype n] [DecidableEq n] [Semiring R] [PartialOrder R] [IsOrderedRing R] : Submonoid (Matrix n n R) where carrier := {M | (βˆ€ i j, 0 ≀ M i j) ∧ M *α΅₯ 1 = 1 ∧ 1 α΅₯* M = 1 } mul_mem' {M N} hM hN := by refine ⟨fun i j => sum_nonneg fun i _ => mul_nonneg (hM.1 _ _) (hN.1 _ _), ?_, ?_⟩ next => rw [← mulVec_mulVec, hN.2.1, hM.2.1] next => rw [← vecMul_vecMul, hM.2.2, hN.2.2] one_mem' := by simp [zero_le_one_elem] lemma mem_doublyStochastic : M ∈ doublyStochastic R n ↔ (βˆ€ i j, 0 ≀ M i j) ∧ M *α΅₯ 1 = 1 ∧ 1 α΅₯* M = 1 := Iff.rfl lemma mem_doublyStochastic_iff_sum : M ∈ doublyStochastic R n ↔ (βˆ€ i j, 0 ≀ M i j) ∧ (βˆ€ i, βˆ‘ j, M i j = 1) ∧ βˆ€ j, βˆ‘ i, M i j = 1 := by simp [funext_iff, doublyStochastic, mulVec, vecMul, dotProduct] /-- Every entry of a doubly stochastic matrix is nonnegative. -/ lemma nonneg_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) {i j : n} : 0 ≀ M i j := hM.1 _ _ /-- Each row sum of a doubly stochastic matrix is 1. -/ lemma sum_row_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) (i : n) : βˆ‘ j, M i j = 1 := (mem_doublyStochastic_iff_sum.1 hM).2.1 _ /-- Each column sum of a doubly stochastic matrix is 1. -/ lemma sum_col_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) (j : n) : βˆ‘ i, M i j = 1 := (mem_doublyStochastic_iff_sum.1 hM).2.2 _ /-- A doubly stochastic matrix multiplied with the all-ones column vector is 1. -/ lemma mulVec_one_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) : M *α΅₯ 1 = 1 := (mem_doublyStochastic.1 hM).2.1 /-- The all-ones row vector multiplied with a doubly stochastic matrix is 1. -/ lemma one_vecMul_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) : 1 α΅₯* M = 1 := (mem_doublyStochastic.1 hM).2.2 /-- Every entry of a doubly stochastic matrix is less than or equal to 1. -/ lemma le_one_of_mem_doublyStochastic (hM : M ∈ doublyStochastic R n) {i j : n} : M i j ≀ 1 := by rw [← sum_row_of_mem_doublyStochastic hM i] exact single_le_sum (fun k _ => hM.1 _ k) (mem_univ j) /-- The set of doubly stochastic matrices is convex. -/ lemma convex_doublyStochastic : Convex R (doublyStochastic R n : Set (Matrix n n R)) := by intro x hx y hy a b ha hb h simp only [SetLike.mem_coe, mem_doublyStochastic_iff_sum] at hx hy ⊒ simp [add_nonneg, ha, hb, mul_nonneg, hx, hy, sum_add_distrib, ← mul_sum, h] /-- Any permutation matrix is doubly stochastic. -/ lemma permMatrix_mem_doublyStochastic {Οƒ : Equiv.Perm n} : Οƒ.permMatrix R ∈ doublyStochastic R n := by rw [mem_doublyStochastic_iff_sum] refine ⟨fun i j => ?g1, ?g2, ?g3⟩ case g1 => aesop case g2 => simp [Equiv.toPEquiv_apply] case g3 => simp [Equiv.toPEquiv_apply, ← Equiv.eq_symm_apply] end OrderedSemiring section LinearOrderedSemifield variable [Semifield R] [LinearOrder R] [IsStrictOrderedRing R] /-- A matrix is `s` times a doubly stochastic matrix iff all entries are nonnegative, and all row and column sums are equal to `s`. This lemma is useful for the proof of Birkhoff's theorem - in particular because it allows scaling by nonnegative factors rather than positive ones only. -/ lemma exists_mem_doublyStochastic_eq_smul_iff {M : Matrix n n R} {s : R} (hs : 0 ≀ s) : (βˆƒ M' ∈ doublyStochastic R n, M = s β€’ M') ↔ (βˆ€ i j, 0 ≀ M i j) ∧ (βˆ€ i, βˆ‘ j, M i j = s) ∧ (βˆ€ j, βˆ‘ i, M i j = s) := by classical constructor case mp => rintro ⟨M', hM', rfl⟩ rw [mem_doublyStochastic_iff_sum] at hM' simp only [smul_apply, smul_eq_mul, ← mul_sum] exact ⟨fun i j => mul_nonneg hs (hM'.1 _ _), by simp [hM']⟩ rcases eq_or_lt_of_le hs with rfl | hs case inl => simp only [zero_smul, exists_and_right, and_imp] intro h₁ hβ‚‚ _ refine ⟨⟨1, Submonoid.one_mem _⟩, ?_⟩ ext i j specialize hβ‚‚ i rw [sum_eq_zero_iff_of_nonneg (by simp [h₁ i])] at hβ‚‚ exact hβ‚‚ _ (by simp) rintro ⟨hM₁, hMβ‚‚, hMβ‚ƒβŸ© exact ⟨s⁻¹ β€’ M, by simp [mem_doublyStochastic_iff_sum, ← mul_sum, hs.ne', *]⟩ end LinearOrderedSemifield
.lake/packages/mathlib/Mathlib/Analysis/Convex/KreinMilman.lean
import Mathlib.Analysis.Convex.Exposed import Mathlib.Analysis.LocallyConvex.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 variable {E F : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [T2Space E] [IsTopologicalAddGroup 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, ht⟩ : βˆƒ t, Minimal (Β· ∈ S) t Β· obtain ⟨⟨x,hxt⟩, htclos, hst⟩ := ht.prop 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 [ht.eq_of_ge (y := ({ 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_ge (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 rw [mem_extremePoints] at hw 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Strict.lean
import Mathlib.Analysis.Convex.Basic import Mathlib.Topology.Algebra.Group.Pointwise 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 /-- 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 (π•œ : Type*) {E : Type*} [Semiring π•œ] [PartialOrder π•œ] [TopologicalSpace E] [AddCommMonoid E] [SMul π•œ E] (s : Set E) : Prop := s.Pairwise fun x y => βˆ€ ⦃a b : π•œβ¦„, 0 < a β†’ 0 < b β†’ a + b = 1 β†’ a β€’ x + b β€’ y ∈ interior s variable [Semiring π•œ] [PartialOrder π•œ] [TopologicalSpace E] [TopologicalSpace F] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section SMul variable [SMul π•œ E] [SMul π•œ F] (s : Set E) 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 Ξ²] [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²] [OrderTopology Ξ²] [Module π•œ Ξ²] [PosSMulStrictMono π•œ Ξ²] 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 => ?_ rcases hxy.lt_or_gt 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 [Field 𝕝] [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 CommSemiring variable [CommSemiring π•œ] [PartialOrder π•œ] [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 CommSemiring section OrderedRing variable [Ring π•œ] [PartialOrder π•œ] [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 [IsOrderedRing π•œ] [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 [AddRightStrictMono π•œ] (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 match_scalars <;> simp 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 [AddRightStrictMono π•œ] (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 [AddRightMono π•œ] (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 [IsTopologicalAddGroup 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 [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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 ↦ h hx hy hxy (by positivity) (by positivity) (by field), 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β‚€ (by positivity)] exact hs.smul_mem_of_zero_mem zero_mem hx hxβ‚€ (by positivity) (inv_lt_one_of_one_ltβ‚€ ht) end AddCommGroup end LinearOrderedField /-! #### Convex sets in an ordered space Relates `Convex` and `Set.OrdConnected`. -/ section variable [Field π•œ] [LinearOrder π•œ] [IsStrictOrderedRing π•œ] [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
.lake/packages/mathlib/Mathlib/Analysis/Convex/LinearIsometry.lean
import Mathlib.Analysis.Convex.ContinuousLinearEquiv import Mathlib.Analysis.Convex.StrictConvexSpace import Mathlib.Analysis.Normed.Operator.LinearIsometry /-! # (Strict) convexity and linear isometries In this file we prove some basic lemmas about (strict) convexity and linear isometries. -/ open Function Set Metric open scoped Convex section SeminormedAddCommGroup variable {π•œ E F : Type*} [NormedField π•œ] [PartialOrder π•œ] [SeminormedAddCommGroup E] [NormedSpace π•œ E] [SeminormedAddCommGroup F] [NormedSpace π•œ F] @[simp] lemma LinearIsometryEquiv.strictConvex_preimage {s : Set F} (e : E ≃ₗᡒ[π•œ] F) : StrictConvex π•œ (e ⁻¹' s) ↔ StrictConvex π•œ s := e.toContinuousLinearEquiv.strictConvex_preimage @[simp] lemma LinearIsometryEquiv.strictConvex_image {s : Set E} (e : E ≃ₗᡒ[π•œ] F) : StrictConvex π•œ (e '' s) ↔ StrictConvex π•œ s := e.toContinuousLinearEquiv.strictConvex_image end SeminormedAddCommGroup variable {π•œ E F : Type*} [NormedField π•œ] [PartialOrder π•œ] lemma StrictConvex.linearIsometry_preimage [NormedAddCommGroup E] [NormedSpace π•œ E] [SeminormedAddCommGroup F] [NormedSpace π•œ F] {s : Set F} (hs : StrictConvex π•œ s) (e : E β†’β‚—α΅’[π•œ] F) : StrictConvex π•œ (e ⁻¹' s) := hs.linear_preimage _ e.continuous e.injective variable [NormedAddCommGroup E] [NormedSpace π•œ E] [NormedAddCommGroup F] [NormedSpace π•œ F] protected lemma LinearIsometryEquiv.strictConvexSpace_iff (e : E ≃ₗᡒ[π•œ] F) : StrictConvexSpace π•œ E ↔ StrictConvexSpace π•œ F := by simp only [strictConvexSpace_iff, ← map_zero e, ← e.image_closedBall, e.strictConvex_image] lemma LinearIsometry.strictConvexSpace_range_iff (e : E β†’β‚—α΅’[π•œ] F) : StrictConvexSpace π•œ (LinearMap.range e) ↔ StrictConvexSpace π•œ E := e.equivRange.strictConvexSpace_iff.symm instance LinearIsometry.strictConvexSpace_range [StrictConvexSpace π•œ E] (e : E β†’β‚—α΅’[π•œ] F) : StrictConvexSpace π•œ (LinearMap.range e) := e.strictConvexSpace_range_iff.mpr β€Ή_β€Ί lemma LinearIsometry.strictConvexSpace [StrictConvexSpace π•œ F] (f : E β†’β‚—α΅’[π•œ] F) : StrictConvexSpace π•œ E where strictConvex_closedBall r hr := by rw [← f.isometry.preimage_closedBall] exact (strictConvex_closedBall _ _ _).linearIsometry_preimage _ /-- A vector subspace of a strict convex space is a strict convex space. This instance has priority 900 to make sure that instances like `LinearIsometry.strictConvexSpace_range` are tried before this one. -/ instance (priority := 900) Submodule.instStrictConvexSpace [StrictConvexSpace π•œ E] (p : Submodule π•œ E) : StrictConvexSpace π•œ p := p.subtypeβ‚—α΅’.strictConvexSpace
.lake/packages/mathlib/Mathlib/Analysis/Convex/Cone/InnerDual.lean
import Mathlib.Analysis.Convex.Cone.Dual import Mathlib.Analysis.InnerProductSpace.Adjoint /-! # Inner dual cone of a set We define the inner dual cone of a set `s` in an inner product space to be the proper cone consisting of all points `y` such that `0 ≀ βŸͺx, y⟫` for all `x ∈ s`. ## Main statements We prove the following theorems: * `ProperCone.innerDual_innerDual`: The double inner dual of a proper convex cone is itself. * `ProperCone.hyperplane_separation'`: This variant of the [hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem) states that given a nonempty, closed, convex cone `C` in a complete, real inner product space `E` 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). ## Implementation notes We do not provide `ConvexCone`- nor `PointedCone`-valued versions of `ProperCone.innerDual` since the inner dual cone of any set is always closed and contains `0`, i.e. is a proper cone. Furthermore, the strict version `{y | βˆ€ x ∈ s, 0 < βŸͺx, y⟫}` is a candidate to the name `ConvexCone.innerDual`. -/ open Set LinearMap Pointwise open scoped RealInnerProductSpace variable {R E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] [NormedAddCommGroup F] [InnerProductSpace ℝ F] [CompleteSpace F] {s t : Set E} {x xβ‚€ y : E} open Function namespace ProperCone /-- The dual cone of a set `s` is the cone consisting of all points `y` such that for all points `x ∈ s` we have `0 ≀ βŸͺx, y⟫`. -/ @[simps! toSubmodule] def innerDual (s : Set E) : ProperCone ℝ E := .dual (innerβ‚— E) s @[simp] lemma mem_innerDual : y ∈ innerDual s ↔ βˆ€ ⦃x⦄, x ∈ s β†’ 0 ≀ βŸͺx, y⟫ := .rfl @[simp] lemma innerDual_empty : innerDual (βˆ… : Set E) = ⊀ := by ext; simp /-- Dual cone of the convex cone `{0}` is the total space. -/ @[simp] lemma innerDual_zero : innerDual (0 : Set E) = ⊀ := by ext; simp /-- Dual cone of the total space is the convex cone `{0}`. -/ @[simp] lemma innerDual_univ : innerDual (univ : Set E) = βŠ₯ := le_antisymm (fun x hx ↦ by simpa using hx (mem_univ (-x))) (by simp) @[gcongr] lemma innerDual_le_innerDual (h : t βŠ† s) : innerDual s ≀ innerDual t := fun _y hy _x hx ↦ hy (h hx) /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `fun y ↦ βŸͺx, y⟫`. -/ lemma innerDual_singleton (x : E) : innerDual ({x} : Set E) = (positive ℝ ℝ).comap (innerSL ℝ x) := by ext; simp lemma innerDual_union (s t : Set E) : innerDual (s βˆͺ t) = innerDual s βŠ“ innerDual t := le_antisymm (le_inf (fun _ hx _ hy ↦ hx <| .inl hy) fun _ hx _ hy ↦ hx <| .inr hy) fun _ hx _ => Or.rec (fun h ↦ hx.1 h) (fun h ↦ hx.2 h) lemma innerDual_insert (x : E) (s : Set E) : innerDual (insert x s) = innerDual {x} βŠ“ innerDual s := by rw [insert_eq, innerDual_union] lemma innerDual_iUnion {ΞΉ : Sort*} (f : ΞΉ β†’ Set E) : innerDual (⋃ i, f i) = β¨… i, innerDual (f i) := by ext; simp [forall_swap (Ξ± := E)] lemma innerDual_sUnion (S : Set (Set E)) : innerDual (⋃₀ S) = sInf (innerDual '' S) := by ext; simp [forall_swap (Ξ± := E)] /-! ### Farkas' lemma and double dual of a cone in a Hilbert space -/ /-- Geometric interpretation of **Farkas' lemma**. Also stronger version of the **Hahn-Banach separation theorem** for proper cones. -/ theorem hyperplane_separation' (C : ProperCone ℝ E) (hxβ‚€ : xβ‚€ βˆ‰ C) : βˆƒ y, (βˆ€ x ∈ C, 0 ≀ βŸͺx, y⟫) ∧ βŸͺxβ‚€, y⟫ < 0 := by obtain ⟨f, hf, hfβ‚€βŸ© := C.hyperplane_separation_point hxβ‚€ refine ⟨(InnerProductSpace.toDual ℝ E).symm f, ?_⟩ simpa [← real_inner_comm _ ((InnerProductSpace.toDual ℝ E).symm f), *] /-- The inner dual of inner dual of a proper cone is itself. -/ @[simp] theorem innerDual_innerDual (C : ProperCone ℝ E) : innerDual (innerDual (C : Set E)) = C := by simpa using C.dual_flip_dual (innerβ‚— E) open scoped InnerProductSpace /-- Relative geometric interpretation of **Farkas' lemma**. Also stronger version of the **Hahn-Banach separation theorem** for proper cones. -/ theorem relative_hyperplane_separation {C : ProperCone ℝ E} {f : E β†’L[ℝ] F} {b : F} : b ∈ C.map f ↔ βˆ€ y : F, f.adjoint y ∈ innerDual C β†’ 0 ≀ βŸͺb, y⟫_ℝ where mp := by -- suppose `b ∈ C.map f` simp only [map, ClosedSubmodule.map, Submodule.closure, Submodule.topologicalClosure, AddSubmonoid.topologicalClosure, Submodule.coe_toAddSubmonoid, Submodule.map_coe, ContinuousLinearMap.coe_restrictScalars', ClosedSubmodule.coe_toSubmodule, ClosedSubmodule.mem_mk, Submodule.mem_mk, AddSubmonoid.mem_mk, AddSubsemigroup.mem_mk, mem_closure_iff_seq_limit, mem_image, SetLike.mem_coe, Classical.skolem, forall_and, mem_innerDual, ContinuousLinearMap.adjoint_inner_right, forall_exists_index, and_imp] -- there is a sequence `seq : β„• β†’ F` in the image of `f` that converges to `b` rintro x seq hmem hx htends y hinner obtain rfl : f ∘ seq = x := funext hx have h n : 0 ≀ βŸͺf (seq n), y⟫_ℝ := by simpa [real_inner_comm] using hinner (hmem n) exact ge_of_tendsto' ((continuous_id.inner continuous_const).seqContinuous htends) h mpr h := by -- By contradiction, suppose `b βˆ‰ C.map f`. contrapose! h -- as `b βˆ‰ C.map f`, there is a hyperplane `y` separating `b` from `C.map f` obtain ⟨y, hxy, hyb⟩ := (C.map f).hyperplane_separation' h -- the rest of the proof is a straightforward algebraic manipulation refine ⟨y, fun x hx ↦ ?_, hyb⟩ simpa [ContinuousLinearMap.adjoint_inner_right] using hxy (f x) (subset_closure <| mem_image_of_mem _ hx) theorem hyperplane_separation_of_notMem (K : ProperCone ℝ E) {f : E β†’L[ℝ] F} {b : F} (disj : b βˆ‰ K.map f) : βˆƒ y : F, ContinuousLinearMap.adjoint f y ∈ innerDual K ∧ βŸͺb, y⟫_ℝ < 0 := by contrapose! disj; rwa [K.relative_hyperplane_separation] @[deprecated (since := "2025-05-24")] alias hyperplane_separation_of_nmem := ProperCone.hyperplane_separation_of_notMem end ProperCone 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 ⟫`. -/ @[deprecated ProperCone.innerDual (since := "2025-07-06")] 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) set_option linter.deprecated false in @[deprecated ProperCone.mem_innerDual (since := "2025-07-06")] theorem mem_innerDualCone (y : H) (s : Set H) : y ∈ s.innerDualCone ↔ βˆ€ x ∈ s, 0 ≀ βŸͺx, y⟫ := Iff.rfl set_option linter.deprecated false in @[deprecated ProperCone.innerDual_empty (since := "2025-07-06")] theorem innerDualCone_empty : (βˆ… : Set H).innerDualCone = ⊀ := eq_top_iff.mpr fun _ _ _ => False.elim set_option linter.deprecated false in @[deprecated ProperCone.innerDual_zero (since := "2025-07-06")] theorem innerDualCone_zero : (0 : Set H).innerDualCone = ⊀ := eq_top_iff.mpr fun _ _ y (hy : y = 0) => hy.symm β–Έ (inner_zero_left _).ge set_option linter.deprecated false in /-- Dual cone of the total space is the convex cone {0}. -/ @[deprecated ProperCone.innerDual_univ (since := "2025-07-06")] 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 using hx (-x) (mem_univ _) variable {s t} in set_option linter.deprecated false in @[deprecated ProperCone.innerDual_le_innerDual (since := "2025-07-06")] theorem innerDualCone_le_innerDualCone (h : t βŠ† s) : s.innerDualCone ≀ t.innerDualCone := fun _ hy x hx => hy x (h hx) set_option linter.deprecated false in @[deprecated ProperCone.pointed_toConvexCone (since := "2025-07-06")] theorem pointed_innerDualCone : s.innerDualCone.Pointed := fun x _ => by rw [inner_zero_right] set_option linter.deprecated false in /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `fun y ↦ βŸͺx, y⟫`. -/ @[deprecated ProperCone.innerDual_singleton (since := "2025-07-06")] theorem innerDualCone_singleton (x : H) : ({x} : Set H).innerDualCone = (ConvexCone.positive ℝ ℝ).comap (innerβ‚›β‚— ℝ x) := ConvexCone.ext fun _ => forall_eq set_option linter.deprecated false in @[deprecated ProperCone.innerDual_union (since := "2025-07-06")] 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 _) set_option linter.deprecated false in @[deprecated ProperCone.innerDual_insert (since := "2025-07-06")] theorem innerDualCone_insert (x : H) (s : Set H) : (insert x s).innerDualCone = Set.innerDualCone {x} βŠ“ s.innerDualCone := by rw [insert_eq, innerDualCone_union] set_option linter.deprecated false in @[deprecated ProperCone.innerDual_iUnion (since := "2025-07-06")] 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 set_option linter.deprecated false in @[deprecated ProperCone.innerDual_sUnion (since := "2025-07-06")] theorem innerDualCone_sUnion (S : Set (Set H)) : (⋃₀ S).innerDualCone = sInf (Set.innerDualCone '' S) := by simp_rw [sInf_image, sUnion_eq_biUnion, innerDualCone_iUnion] set_option linter.deprecated false in /-- The dual cone of `s` equals the intersection of dual cones of the points in `s`. -/ @[deprecated "No replacement" (since := "2025-07-06")] 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] set_option linter.deprecated false in @[deprecated ProperCone.isClosed (since := "2025-07-06")] 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') namespace PointedCone set_option linter.deprecated false in @[deprecated "Now irrelevant" (since := "2025-07-06")] lemma toConvexCone_dual (C : PointedCone ℝ H) : (dual (innerβ‚— H) (C : Set H)).toConvexCone = (C : Set H).innerDualCone := rfl end PointedCone namespace ProperCone set_option linter.deprecated false in @[deprecated "Now irrelevant" (since := "2025-07-06")] lemma coe_dual [CompleteSpace H] (C : ProperCone ℝ H) : dual (innerβ‚— H) C = (C : Set H).innerDualCone := rfl end ProperCone section CompleteSpace variable [CompleteSpace H] open scoped InnerProductSpace in /-- 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_notMem (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 (ConvexCone.Pointed.of_nonempty_of_isClosed (C := K) 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_ge ((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] @[deprecated (since := "2025-05-24")] alias ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem := ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_notMem set_option linter.deprecated false in /-- The inner dual of inner dual of a non-empty, closed convex cone is itself. -/ @[deprecated ProperCone.innerDual_innerDual (since := "2025-07-06")] 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_notMem ne hc Β· rintro hxK y h specialize h x hxK rwa [real_inner_comm] namespace ProperCone variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] set_option linter.deprecated false in /-- The dual of the dual of a proper cone is itself. -/ @[deprecated ProperCone.innerDual_innerDual (since := "2025-07-06")] theorem dual_dual (K : ProperCone ℝ H) : innerDual (innerDual (K : Set H)) = K := ProperCone.toPointedCone_injective <| PointedCone.toConvexCone_injective <| (K : ConvexCone ℝ H).innerDualCone_of_innerDualCone_eq_self K.nonempty K.isClosed end ProperCone end CompleteSpace end Dual
.lake/packages/mathlib/Mathlib/Analysis/Convex/Cone/Closure.lean
import Mathlib.Geometry.Convex.Cone.Pointed import Mathlib.Topology.Algebra.ConstMulAction import Mathlib.Topology.Algebra.Monoid.Defs /-! # 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*} [Semiring π•œ] [PartialOrder π•œ] 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*} [Semiring π•œ] [PartialOrder π•œ] [IsOrderedRing π•œ] 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.pointed_toConvexCone _ /-- 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 := K.toConvexCone.closure.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
.lake/packages/mathlib/Mathlib/Analysis/Convex/Cone/Extension.lean
import Mathlib.Data.Real.Archimedean import Mathlib.Geometry.Convex.Cone.Basic 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 [Sp, Sn, 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 refine ⟨f.supSpanSingleton y (-c) hy, ?_, ?_⟩ Β· refine lt_iff_le_not_ge.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 at hzs rw [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] replace := le_c (r⁻¹ β€’ ⟨x, hx⟩) this rwa [← mul_le_mul_iff_rightβ‚€ (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] replace := c_le (r⁻¹ β€’ ⟨x, hx⟩) this rwa [← mul_le_mul_iff_rightβ‚€ 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, hpq, hqs, hq⟩ := zorn_le_nonemptyβ‚€ 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, fun hrq ↦ hqr.ne' <| hrq.antisymm hqr.le⟩ 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))
.lake/packages/mathlib/Mathlib/Analysis/Convex/Cone/Basic.lean
import Mathlib.Analysis.Convex.Cone.Closure import Mathlib.Geometry.Convex.Cone.Pointed import Mathlib.Topology.Algebra.Module.ClosedSubmodule import Mathlib.Topology.Algebra.Order.Module import Mathlib.Topology.Order.DenselyOrdered /-! # 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. One can turn `C : PointedCone R E` + `hC : IsClosed C` into `C : ProperCone R E` in a tactic block by doing `lift C to ProperCone R E using hC`. One can also turn `C : ConvexCone π•œ E` + `hC : Set.Nonempty C ∧ IsClosed C` into `C : ProperCone π•œ E` in a tactic block by doing `lift C to ProperCone π•œ E using hC`, assuming `π•œ` is a dense topological field. ## TODO The next steps are: - Add `ConvexConeClass` that extends `SetLike` 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 Function Set variable {π•œ R E F G : Type*} [Semiring R] [PartialOrder R] [IsOrderedRing R] variable [AddCommMonoid E] [TopologicalSpace E] [Module R E] variable [AddCommMonoid F] [TopologicalSpace F] [Module R F] variable [AddCommMonoid G] [TopologicalSpace G] [Module R G] local notation "Rβ‰₯0" => {r : R // 0 ≀ r} variable (R E) in /-- A proper cone is a pointed cone `C` 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. -/ abbrev ProperCone := ClosedSubmodule Rβ‰₯0 E namespace ProperCone section Module variable {C C₁ Cβ‚‚ : ProperCone R E} {r : R} {x : E} /-- Any proper cone can be seen as a pointed cone. This is an alias of `ClosedSubmodule.toSubmodule` for convenience and discoverability. -/ @[coe] abbrev toPointedCone (C : ProperCone R E) : PointedCone R E := C.toSubmodule instance : Coe (ProperCone R E) (PointedCone R E) := ⟨toPointedCone⟩ lemma toPointedCone_injective : Injective ((↑) : ProperCone R E β†’ PointedCone R E) := ClosedSubmodule.toSubmodule_injective -- TODO: add `ConvexConeClass` that extends `SetLike` and replace the below instance instance : SetLike (ProperCone R E) E where coe C := C.carrier coe_injective' _ _ h := ProperCone.toPointedCone_injective <| SetLike.coe_injective h @[ext] lemma ext (h : βˆ€ x, x ∈ C₁ ↔ x ∈ Cβ‚‚) : C₁ = Cβ‚‚ := SetLike.ext h @[simp] lemma mem_toPointedCone : x ∈ C.toPointedCone ↔ x ∈ C := .rfl @[deprecated (since := "2025-06-11")] alias mem_coe := mem_toPointedCone lemma pointed_toConvexCone (C : ProperCone R E) : (C : ConvexCone R E).Pointed := C.toPointedCone.pointed_toConvexCone @[deprecated (since := "2025-06-11")] protected alias pointed := pointed_toConvexCone protected lemma nonempty (C : ProperCone R E) : (C : Set E).Nonempty := C.toSubmodule.nonempty protected lemma isClosed (C : ProperCone R E) : IsClosed (C : Set E) := C.isClosed' protected lemma convex (C : ProperCone R E) : Convex R (C : Set E) := C.toPointedCone.convex protected nonrec lemma smul_mem (C : ProperCone R E) (hx : x ∈ C) (hr : 0 ≀ r) : r β€’ x ∈ C := C.smul_mem ⟨r, hr⟩ hx section T1Space variable [T1Space E] lemma mem_bot : x ∈ (βŠ₯ : ProperCone R E) ↔ x = 0 := .rfl @[simp, norm_cast] lemma coe_bot : (βŠ₯ : ProperCone R E) = ({0} : Set E) := rfl @[simp, norm_cast] lemma toPointedCone_bot : (βŠ₯ : ProperCone R E).toPointedCone = βŠ₯ := rfl @[deprecated (since := "2025-06-11")] alias mem_zero := mem_bot @[deprecated (since := "2025-06-11")] alias coe_zero := coe_bot @[deprecated (since := "2025-06-11")] alias pointed_zero := pointed_toConvexCone end T1Space /-- The closure of image of a proper cone under a `R`-linear map is a proper cone. We use continuous maps here so that the comap of f is also a map between proper cones. -/ abbrev comap (f : E β†’L[R] F) (C : ProperCone R F) : ProperCone R E := ClosedSubmodule.comap (f.restrictScalars Rβ‰₯0) C @[simp] lemma comap_id (C : ProperCone R F) : C.comap (.id _ _) = C := rfl @[simp] lemma coe_comap (f : E β†’L[R] F) (C : ProperCone R F) : (C.comap f : Set E) = f ⁻¹' C := rfl lemma comap_comap (g : F β†’L[R] G) (f : E β†’L[R] F) (C : ProperCone R G) : (C.comap g).comap f = C.comap (g.comp f) := rfl lemma mem_comap {C : ProperCone R F} {f : E β†’L[R] F} : x ∈ C.comap f ↔ f x ∈ C := .rfl variable [ContinuousAdd F] [ContinuousConstSMul R F] /-- The closure of image of a proper cone under a linear map is a proper cone. We use continuous maps here to match `ProperCone.comap`. -/ abbrev map (f : E β†’L[R] F) (C : ProperCone R E) : ProperCone R F := ClosedSubmodule.map (f.restrictScalars Rβ‰₯0) C @[simp] lemma map_id (C : ProperCone R F) : C.map (.id _ _) = C := ClosedSubmodule.map_id _ @[simp, norm_cast] lemma coe_map (f : E β†’L[R] F) (C : ProperCone R E) : C.map f = (C.toPointedCone.map (f : E β†’β‚—[R] F)).closure := rfl @[simp] lemma mem_map {f : E β†’L[R] F} {C : ProperCone R E} {y : F} : y ∈ C.map f ↔ y ∈ (C.toPointedCone.map (f : E β†’β‚—[R] F)).closure := .rfl end Module section PositiveCone variable [PartialOrder E] [IsOrderedAddMonoid E] [PosSMulMono R E] [OrderClosedTopology E] {x : E} variable (R E) in /-- The positive cone is the proper cone formed by the set of nonnegative elements in an ordered module. -/ @[simps!] def positive : ProperCone R E where toSubmodule := PointedCone.positive R E isClosed' := isClosed_Ici @[simp] lemma mem_positive : x ∈ positive R E ↔ 0 ≀ x := .rfl @[simp] lemma toPointedCone_positive : (positive R E).toPointedCone = .positive R E := rfl end PositiveCone end ProperCone /-! ### Topological properties of convex cones This section proves topological results about convex cones. #### TODO This result generalises to G-submodules. -/ namespace ConvexCone variable [Semifield π•œ] [LinearOrder π•œ] [Module π•œ E] {s : Set E} -- FIXME: This is necessary for the proof below but triggers the `unusedSectionVars` linter. -- variable [IsStrictOrderedRing π•œ] [IsTopologicalAddGroup M] in /-- This is true essentially by `Submodule.span_eq_iUnion_nat`, except that `Submodule` currently doesn't support that use case. See https://leanprover.zulipchat.com/#narrow/channel/116395-maths/topic/G-submodules/with/514426583 -/ proof_wanted isOpen_hull (hs : IsOpen s) : IsOpen (hull π•œ s : Set E) variable [TopologicalSpace π•œ] [OrderTopology π•œ] [DenselyOrdered π•œ] [NoMaxOrder π•œ] [ContinuousSMul π•œ E] {C : ConvexCone π•œ E} lemma Pointed.of_nonempty_of_isClosed (hC : (C : Set E).Nonempty) (hSclos : IsClosed (C : Set E)) : C.Pointed := by obtain ⟨x, hx⟩ := hC let f : π•œ β†’ E := (Β· β€’ x) -- The closure of `f (0, ∞)` is a subset of `C` have hfS : closure (f '' Set.Ioi 0) βŠ† C := hSclos.closure_subset_iff.2 <| by rintro _ ⟨_, h, rfl⟩; exact C.smul_mem h hx -- `f` is continuous at `0` from the right have fc : ContinuousWithinAt f (Set.Ioi (0 : π•œ)) 0 := (continuous_id.smul continuous_const).continuousWithinAt -- `0 ∈ closure f (0, ∞) βŠ† C, 0 ∈ C` simpa [f, Pointed, ← SetLike.mem_coe] using hfS <| fc.mem_closure_image <| by simp variable [IsOrderedRing π•œ] instance canLift : CanLift (ConvexCone π•œ E) (ProperCone π•œ E) (↑) fun C ↦ (C : Set E).Nonempty ∧ IsClosed (C : Set E) where prf C hC := ⟨⟨C.toPointedCone <| .of_nonempty_of_isClosed hC.1 hC.2, hC.2⟩, rfl⟩ end ConvexCone
.lake/packages/mathlib/Mathlib/Analysis/Convex/Cone/README.md
# Topological and analytic theory of convex cones This subfolder is destined to contain results about convex cones that require a topology, a norm or an inner product. See the `Mathlib.Geometry.Convex.Cone` folder for the purely algebraic theory of convex cones. ## Topics The convex cone topics currently covered are: * Proper cone * Dual cone along a continuous bilinear pairing * Inner dual cone * Farkas' lemma, Hahn-Banach separation, hyperplane separation, double dual of a proper cone * M. Riesz extension theorem
.lake/packages/mathlib/Mathlib/Analysis/Convex/Cone/Dual.lean
import Mathlib.Analysis.Convex.Cone.Basic import Mathlib.Analysis.LocallyConvex.Separation import Mathlib.Geometry.Convex.Cone.Dual import Mathlib.Topology.Algebra.Module.PerfectPairing /-! # The topological dual of a cone and Farkas' lemma Given a continuous bilinear pairing `p` between two `R`-modules `M` and `N` and a set `s` in `M`, we define `ProperCone.dual p C` to be the proper cone in `N` consisting of all points `y` such that `0 ≀ p x y` for all `x ∈ s`. When the pairing is perfect, this gives us the algebraic dual of a cone. See `Mathlib/Geometry/Convex/Cone/Dual.lean` for that case. When the pairing is continuous and perfect (as a continuous pairing), this gives us the topological dual instead. This is developed here. We prove Farkas' lemma, which says that a proper cone `C` in a locally convex topological real vector space `E` and a point `xβ‚€` not in `C` can be separated by a hyperplane. This is a geometric interpretation of the Hahn-Banach separation theorem. As a corollary, we prove that the double dual of a proper cone is itself. ## Main statements We prove the following theorems: * `ProperCone.hyperplane_separation`, `ProperCone.hyperplane_separation_point`: Farkas lemma. * `ProperCone.dual_dual_flip`, `ProperCone.dual_flip_dual`: The double dual of a proper cone. ## References * https://en.wikipedia.org/wiki/Hyperplane_separation_theorem * https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation -/ assert_not_exists InnerProductSpace open Set LinearMap Pointwise namespace PointedCone variable {R M N : Type*} [CommRing R] [PartialOrder R] [TopologicalSpace R] [ClosedIciTopology R] [IsOrderedRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] [TopologicalSpace N] {p : M β†’β‚—[R] N β†’β‚—[R] R} {s : Set M} lemma isClosed_dual (hp : βˆ€ x, Continuous (p x)) : IsClosed (dual p s : Set N) := by rw [← s.biUnion_of_singleton] simp_rw [dual_iUnion, Submodule.coe_iInf, dual_singleton] exact isClosed_biInter fun x hx ↦ isClosed_Ici.preimage <| hp _ end PointedCone namespace ProperCone variable {R M N : Type*} [CommRing R] [PartialOrder R] [IsOrderedRing R] [TopologicalSpace R] [ClosedIciTopology R] [AddCommGroup M] [Module R M] [TopologicalSpace M] [AddCommGroup N] [Module R N] [TopologicalSpace N] {p : M β†’β‚—[R] N β†’β‚—[R] R} [p.IsContPerfPair] {s t : Set M} {y : N} variable (p s) in /-- The dual cone of a set `s` with respect to a perfect pairing `p` is the cone consisting of all points `y` such that for all points `x ∈ s` we have `0 ≀ p x y`. -/ def dual (s : Set M) : ProperCone R N where toSubmodule := PointedCone.dual p s isClosed' := PointedCone.isClosed_dual fun _ ↦ p.continuous_of_isContPerfPair @[simp] lemma mem_dual : y ∈ dual p s ↔ βˆ€ ⦃x⦄, x ∈ s β†’ 0 ≀ p x y := .rfl @[simp] lemma dual_empty : dual p βˆ… = ⊀ := by ext; simp @[simp] lemma dual_zero : dual p 0 = ⊀ := by ext; simp @[simp] lemma dual_univ [IsTopologicalRing R] [T1Space N] : dual p univ = βŠ₯ := by refine le_antisymm (fun y hy ↦ (_root_.map_eq_zero_iff _ p.flip.toContPerfPair.injective).1 ?_) (by simp) ext x exact (hy <| mem_univ x).antisymm' <| by simpa using hy <| mem_univ (-x) @[gcongr] lemma dual_le_dual (h : t βŠ† s) : dual p s ≀ dual p t := fun _y hy _x hx ↦ hy (h hx) /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `p x`. -/ lemma dual_singleton [IsTopologicalRing R] [OrderClosedTopology R] (x : M) : dual p {x} = (positive R R).comap (p.toContPerfPair x) := by ext; simp lemma dual_union (s t : Set M) : dual p (s βˆͺ t) = dual p s βŠ“ dual p t := by aesop lemma dual_insert (x : M) (s : Set M) : dual p (insert x s) = dual p {x} βŠ“ dual p s := by rw [insert_eq, dual_union] lemma dual_iUnion {ΞΉ : Sort*} (f : ΞΉ β†’ Set M) : dual p (⋃ i, f i) = β¨… i, dual p (f i) := by ext; simp [forall_swap (Ξ± := M)] lemma dual_sUnion (S : Set (Set M)) : dual p (⋃₀ S) = sInf (dual p '' S) := by ext; simp [forall_swap (Ξ± := M)] /-- Any set is a subset of its double dual cone. -/ lemma subset_dual_dual : s βŠ† dual p.flip (dual p s) := fun _x hx _y hy ↦ hy hx end ProperCone namespace ProperCone variable {E F : Type*} [TopologicalSpace E] [AddCommGroup E] [IsTopologicalAddGroup E] [TopologicalSpace F] [AddCommGroup F] [Module ℝ E] [ContinuousSMul ℝ E] [LocallyConvexSpace ℝ E] [Module ℝ F] {K : Set E} {xβ‚€ : E} open ConvexCone in /-- Geometric interpretation of **Farkas' lemma**. Also stronger version of the **Hahn-Banach separation theorem** for proper cones. -/ theorem hyperplane_separation (C : ProperCone ℝ E) (hKconv : Convex ℝ K) (hKcomp : IsCompact K) (hKC : Disjoint K C) : βˆƒ f : StrongDual ℝ E, (βˆ€ x ∈ C, 0 ≀ f x) ∧ βˆ€ x ∈ K, f x < 0 := by obtain rfl | ⟨xβ‚€, hxβ‚€βŸ© := K.eq_empty_or_nonempty Β· exact ⟨0, by simp⟩ obtain ⟨f, u, v, hu, huv, hv⟩ := geometric_hahn_banach_compact_closed hKconv hKcomp C.convex C.isClosed hKC have hvβ‚€ : v < 0 := by simpa using hv 0 C.zero_mem refine ⟨f, fun x hx ↦ ?_, fun x hx ↦ (hu x hx).trans_le <| huv.le.trans hvβ‚€.le⟩ by_contra! hxβ‚€ simpa [hxβ‚€.ne] using hv ((v * (f x)⁻¹) β€’ x) (C.smul_mem hx <| le_of_lt <| mul_pos_of_neg_of_neg hvβ‚€ <| inv_neg''.2 hxβ‚€) open ConvexCone in /-- Geometric interpretation of **Farkas' lemma**. Also stronger version of the **Hahn-Banach separation theorem** for proper cones. -/ theorem hyperplane_separation_point (C : ProperCone ℝ E) (hxβ‚€ : xβ‚€ βˆ‰ C) : βˆƒ f : StrongDual ℝ E, (βˆ€ x ∈ C, 0 ≀ f x) ∧ f xβ‚€ < 0 := by simpa [*] using C.hyperplane_separation (convex_singleton xβ‚€) /-- The **double dual of a proper cone** is itself. -/ @[simp] theorem dual_flip_dual (p : E β†’β‚—[ℝ] F β†’β‚—[ℝ] ℝ) [p.IsContPerfPair] (C : ProperCone ℝ E) : dual p.flip (dual p (C : Set E)) = C := by refine le_antisymm (fun x ↦ ?_) subset_dual_dual simp only [mem_toPointedCone, mem_dual, SetLike.mem_coe] contrapose! simpa [p.flip.toContPerfPair.surjective.exists] using C.hyperplane_separation_point /-- The **double dual of a proper cone** is itself. -/ @[simp] theorem dual_dual_flip (p : F β†’β‚—[ℝ] E β†’β‚—[ℝ] ℝ) [p.IsContPerfPair] (C : ProperCone ℝ E) : dual p (dual p.flip (C : Set E)) = C := C.dual_flip_dual p.flip end ProperCone
.lake/packages/mathlib/Mathlib/Analysis/Convex/SpecificFunctions/Pow.lean
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
.lake/packages/mathlib/Mathlib/Analysis/Convex/SpecificFunctions/Deriv.lean
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 _) eta_expand simp_rw [deriv_pow_field, 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) eta_expand simp_rw [deriv_pow_field] 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*} [CommRing Ξ²] [LinearOrder Ξ²] [IsStrictOrderedRing Ξ²] {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] linarith _ = _ := 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 | zero => simp | succ n ihn => 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_gt 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 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 rcases lt_or_ge 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_gt 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] field 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]
.lake/packages/mathlib/Mathlib/Analysis/Convex/SpecificFunctions/Basic.lean
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.lean`. ## See also `Mathlib/Analysis/Convex/Mul.lean` 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 Β· 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 _ < -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_neg_cancel, 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_gt (1 + p * s) 0 with hs2 | hs2 Β· exact hs2.trans_lt (rpow_pos_of_pos hs1 _) have hs3 : 1 + s β‰  1 := hs' ∘ add_eq_left.mp have hs4 : 1 + p * s β‰  1 := by contrapose! hs'; rwa [add_eq_left, mul_eq_zero, eq_false_intro hp'.ne', false_or] at hs' rw [rpow_def_of_pos hs1, ← exp_log hs2] apply exp_strictMono rcases 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] Β· gcongr exact mul_lt_of_one_lt_left hs' hp Β· rw [← div_lt_iffβ‚€ hp', ← div_lt_div_iff_of_pos_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] Β· gcongr exact 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_neg_cancel, 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_eq_left.mp have hs4 : 1 + p * s β‰  1 := by contrapose! hs'; rwa [add_eq_left, mul_eq_zero, eq_false_intro hp1.ne', false_or] at hs' rw [rpow_def_of_pos hs1, ← exp_log hs2] apply exp_strictMono rcases 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] Β· gcongr exact lt_mul_of_lt_one_left hs' hp2 Β· rw [← lt_div_iffβ‚€ hp1, ← div_lt_div_iff_of_pos_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] Β· gcongr exact 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_iff_of_pos_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, neg_add_cancel, 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_iff_of_pos_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, neg_add_cancel, 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 convexOn_rpow_left {b : ℝ} (hb : 0 < b) : ConvexOn ℝ Set.univ (fun (x : ℝ) => b ^ x) := by convert convexOn_exp.comp_linearMap (LinearMap.mul ℝ ℝ (Real.log b)) using 1 ext x simp [Real.rpow_def_of_pos hb] 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
.lake/packages/mathlib/Mathlib/Analysis/Convex/SimplicialComplex/Basic.lean
import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Independent /-! # Simplicial complexes In this file, we define simplicial complexes in `π•œ`-modules. A simplicial complex is a collection of simplices closed by inclusion (of vertices) and intersection (of underlying sets). We model them by a downward-closed set of affine independent finite sets whose convex hulls "glue nicely", each finite set and its convex hull corresponding respectively to the vertices and the underlying set of a simplex. ## Main declarations * `SimplicialComplex π•œ E`: A simplicial complex in the `π•œ`-module `E`. * `SimplicialComplex.vertices`: The zero-dimensional faces of a simplicial complex. * `SimplicialComplex.facets`: The maximal faces of a simplicial complex. ## Notation `s ∈ K` means that `s` is a face of `K`. `K ≀ L` means that the faces of `K` are faces of `L`. ## Implementation notes "glue nicely" usually means that the intersection of two faces (as sets in the ambient space) is a face. Given that we store the vertices, not the faces, this would be a bit awkward to spell. Instead, `SimplicialComplex.inter_subset_convexHull` is an equivalent condition which works on the vertices. ## TODO Simplicial complexes can be generalized to affine spaces once `ConvexHull` has been ported. -/ open Finset Set variable (π•œ E : Type*) [Ring π•œ] [PartialOrder π•œ] [AddCommGroup E] [Module π•œ E] namespace Geometry -- TODO: update to new binder order? not sure what binder order is correct for `down_closed`. /-- A simplicial complex in a `π•œ`-module is a collection of simplices which glue nicely together. Note that the textbook meaning of "glue nicely" is given in `Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull`. It is mostly useless, as `Geometry.SimplicialComplex.convexHull_inter_convexHull` is enough for all purposes. -/ @[ext] structure SimplicialComplex where /-- the faces of this simplicial complex: currently, given by their spanning vertices -/ faces : Set (Finset E) /-- the empty set is not a face: hence, all faces are non-empty -/ empty_notMem : βˆ… βˆ‰ 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 @[deprecated (since := "2025-05-23")] alias not_empty_mem := empty_notMem variable {π•œ E} variable {K : SimplicialComplex π•œ E} {s t : Finset E} {x : E} /-- A `Finset` belongs to a `SimplicialComplex` if it's a face of it. -/ instance : Membership (Finset E) (SimplicialComplex π•œ E) := ⟨fun K s => s ∈ K.faces⟩ lemma nonempty_of_mem_faces (hs : s ∈ K.faces) : s.Nonempty := by rw [Finset.nonempty_iff_ne_empty]; rintro rfl; exact K.empty_notMem hs /-- 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) theorem mem_space_iff : x ∈ K.space ↔ βˆƒ s ∈ K.faces, x ∈ convexHull π•œ (s : Set E) := by simp [space] 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 \ {βˆ…} empty_notMem 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 empty_notMem := fun h => K.empty_notMem (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 π•œ (E := E) 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 : Min (SimplicialComplex π•œ E) := ⟨fun K L => { faces := K.faces ∩ L.faces empty_notMem := fun h => K.empty_notMem (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 := βˆ… empty_notMem := Set.notMem_empty βˆ… indep := fun hs => (Set.notMem_empty _ hs).elim down_closed := fun hs => (Set.notMem_empty _ hs).elim inter_subset_convexHull := fun hs => (Set.notMem_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
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/BinaryEntropy.lean
import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.Convex.SpecificFunctions.Basic /-! # Properties of Shannon q-ary entropy and binary entropy functions The [binary entropy function](https://en.wikipedia.org/wiki/Binary_entropy_function) `binEntropy p := - p * log p - (1 - p) * log (1 - p)` is the Shannon entropy of a Bernoulli random variable with success probability `p`. More generally, the q-ary entropy function is the Shannon entropy of the random variable with possible outcomes `{1, ..., q}`, where outcome `1` has probability `1 - p` and all other outcomes are equally likely. `qaryEntropy (q : β„•) (p : ℝ) := p * log (q - 1) - p * log p - (1 - p) * log (1 - p)` This file assumes that entropy is measured in Nats, hence the use of natural logarithms. Most lemmas are also valid using a logarithm in a different base. ## Main declarations * `Real.binEntropy`: the binary entropy function * `Real.qaryEntropy`: the `q`-ary entropy function ## Main results The functions are also defined outside the interval `Icc 0 1` due to `log x = log |x|`. * They are continuous everywhere (`binEntropy_continuous` and `qaryEntropy_continuous`). * They are differentiable everywhere except at points `0` or `1` (`hasDerivAt_binEntropy` and `hasDerivAt_qaryEntropy`). In addition, due to junk values, `deriv binEntropy p = log (1 - p) - log p` holds everywhere (`deriv_binEntropy`). * they are strictly increasing on `Icc 0 (1 - 1/q))` (`qaryEntropy_strictMonoOn`, `binEntropy_strictMonoOn`) and strictly decreasing on `Icc (1 - 1/q) 1` (`binEntropy_strictAntiOn` and `qaryEntropy_strictAntiOn`). * they are strictly concave on `Icc 0 1` (`strictConcaveOn_qaryEntropy` and `strictConcave_binEntropy`). ## Tags entropy, Shannon, binary, nit, nepit -/ namespace Real variable {q : β„•} {p : ℝ} /-! ### Binary entropy -/ /-- The [binary entropy function](https://en.wikipedia.org/wiki/Binary_entropy_function) `binEntropy p := - p * log p - (1-p) * log (1 - p)` is the Shannon entropy of a Bernoulli random variable with success probability `p`. -/ @[pp_nodot] noncomputable def binEntropy (p : ℝ) : ℝ := p * log p⁻¹ + (1 - p) * log (1 - p)⁻¹ @[simp] lemma binEntropy_zero : binEntropy 0 = 0 := by simp [binEntropy] @[simp] lemma binEntropy_one : binEntropy 1 = 0 := by simp [binEntropy] @[simp] lemma binEntropy_two_inv : binEntropy 2⁻¹ = log 2 := by norm_num [binEntropy]; simp; ring lemma binEntropy_eq_negMulLog_add_negMulLog_one_sub (p : ℝ) : binEntropy p = negMulLog p + negMulLog (1 - p) := by simp [binEntropy, negMulLog, ← neg_mul] lemma binEntropy_eq_negMulLog_add_negMulLog_one_sub' : binEntropy = fun p ↦ negMulLog p + negMulLog (1 - p) := funext binEntropy_eq_negMulLog_add_negMulLog_one_sub /-- `binEntropy` is symmetric about 1/2. -/ @[simp] lemma binEntropy_one_sub (p : ℝ) : binEntropy (1 - p) = binEntropy p := by simp [binEntropy, add_comm] /-- `binEntropy` is symmetric about 1/2. -/ lemma binEntropy_two_inv_add (p : ℝ) : binEntropy (2⁻¹ + p) = binEntropy (2⁻¹ - p) := by rw [← binEntropy_one_sub]; ring_nf lemma binEntropy_pos (hpβ‚€ : 0 < p) (hp₁ : p < 1) : 0 < binEntropy p := by unfold binEntropy have : 0 < 1 - p := sub_pos.2 hp₁ have : 0 < log p⁻¹ := log_pos <| (one_lt_invβ‚€ hpβ‚€).2 hp₁ have : 0 < log (1 - p)⁻¹ := log_pos <| (one_lt_invβ‚€ β€Ή_β€Ί).2 (sub_lt_self _ hpβ‚€) positivity lemma binEntropy_nonneg (hpβ‚€ : 0 ≀ p) (hp₁ : p ≀ 1) : 0 ≀ binEntropy p := by obtain rfl | hpβ‚€ := hpβ‚€.eq_or_lt Β· simp obtain rfl | hp₁ := hp₁.eq_or_lt Β· simp exact (binEntropy_pos hpβ‚€ hp₁).le /-- Outside the usual range of `binEntropy`, it is negative. This is due to `log p = log |p|`. -/ lemma binEntropy_neg_of_neg (hp : p < 0) : binEntropy p < 0 := by rw [binEntropy, log_inv, log_inv] suffices -p * log p < (1 - p) * log (1 - p) by linarith by_cases hp' : p < -1 Β· have : log p < log (1 - p) := by rw [← log_neg_eq_log] exact log_lt_log (Left.neg_pos_iff.mpr hp) (by linarith) nlinarith [log_pos_of_lt_neg_one hp'] Β· have : -p * log p ≀ 0 := by wlog h : -1 < p Β· simp only [show p = -1 by linarith, log_neg_eq_log, log_one, le_refl, mul_zero] Β· nlinarith [log_neg_of_lt_zero hp h] nlinarith [(log_pos (by linarith) : 0 < log (1 - p))] /-- Outside the usual range of `binEntropy`, it is negative. This is due to `log p = log |p|`. -/ lemma binEntropy_nonpos_of_nonpos (hp : p ≀ 0) : binEntropy p ≀ 0 := by obtain rfl | hp := hp.eq_or_lt Β· simp Β· exact (binEntropy_neg_of_neg hp).le /-- Outside the usual range of `binEntropy`, it is negative. This is due to `log p = log |p|` -/ lemma binEntropy_neg_of_one_lt (hp : 1 < p) : binEntropy p < 0 := by rw [← binEntropy_one_sub]; exact binEntropy_neg_of_neg (sub_neg.2 hp) /-- Outside the usual range of `binEntropy`, it is negative. This is due to `log p = log |p|` -/ lemma binEntropy_nonpos_of_one_le (hp : 1 ≀ p) : binEntropy p ≀ 0 := by rw [← binEntropy_one_sub]; exact binEntropy_nonpos_of_nonpos (sub_nonpos.2 hp) lemma binEntropy_eq_zero : binEntropy p = 0 ↔ p = 0 ∨ p = 1 := by refine ⟨fun h ↦ ?_, by rintro (rfl | rfl) <;> simp⟩ contrapose! h obtain hpβ‚€ | hpβ‚€ := h.1.lt_or_gt Β· exact (binEntropy_neg_of_neg hpβ‚€).ne obtain hp₁ | hp₁ := h.2.lt_or_gt.symm Β· exact (binEntropy_neg_of_one_lt hp₁).ne Β· exact (binEntropy_pos hpβ‚€ hp₁).ne' /-- For probability `p β‰  0.5`, `binEntropy p < log 2`. -/ lemma binEntropy_lt_log_two : binEntropy p < log 2 ↔ p β‰  2⁻¹ := by refine ⟨?_, fun h ↦ ?_⟩ Β· rintro h rfl simp at h wlog hp : p < 2⁻¹ Β· have hp : 1 - p < 2⁻¹ := by rw [sub_lt_comm]; norm_num at *; linarith +splitNe rw [← binEntropy_one_sub] exact this hp.ne hp obtain hpβ‚€ | hpβ‚€ := le_or_gt p 0 Β· exact (binEntropy_nonpos_of_nonpos hpβ‚€).trans_lt <| log_pos <| by simp have hp₁ : 0 < 1 - p := sub_pos.2 <| hp.trans <| by norm_num calc _ < log (p * p⁻¹ + (1 - p) * (1 - p)⁻¹) := strictConcaveOn_log_Ioi.2 (inv_pos.2 hpβ‚€) (inv_pos.2 hp₁) (by simpa [eq_sub_iff_add_eq, ← two_mul, mul_comm, mul_eq_one_iff_eq_invβ‚€]) hpβ‚€ hp₁ (by simp) _ = log 2 := by rw [mul_inv_cancelβ‚€, mul_inv_cancelβ‚€, one_add_one_eq_two] <;> positivity lemma binEntropy_le_log_two : binEntropy p ≀ log 2 := by obtain rfl | hp := eq_or_ne p 2⁻¹ Β· simp Β· exact (binEntropy_lt_log_two.2 hp).le lemma binEntropy_eq_log_two : binEntropy p = log 2 ↔ p = 2⁻¹ := by rw [← binEntropy_le_log_two.not_lt_iff_eq, binEntropy_lt_log_two, not_ne_iff] /-- Binary entropy is continuous everywhere. This is due to definition of `Real.log` for negative numbers. -/ @[fun_prop] lemma binEntropy_continuous : Continuous binEntropy := by rw [binEntropy_eq_negMulLog_add_negMulLog_one_sub']; fun_prop @[fun_prop] lemma differentiableAt_binEntropy (hpβ‚€ : p β‰  0) (hp₁ : p β‰  1) : DifferentiableAt ℝ binEntropy p := by rw [ne_comm, ← sub_ne_zero] at hp₁ unfold binEntropy simp only [log_inv, mul_neg] fun_prop (disch := assumption) lemma differentiableAt_binEntropy_iff_ne_zero_one : DifferentiableAt ℝ binEntropy p ↔ p β‰  0 ∧ p β‰  1 := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ differentiableAt_binEntropy h.1 h.2⟩ <;> rintro rfl <;> unfold binEntropy at h Β· rw [DifferentiableAt.fun_add_iff_left] at h Β· simp [log_inv, mul_neg, ← neg_mul, ← negMulLog_def, differentiableAt_negMulLog_iff] at h Β· fun_prop (disch := simp) Β· rw [DifferentiableAt.fun_add_iff_right, differentiableAt_iff_comp_const_sub (b := 1)] at h Β· simp [log_inv, mul_neg, ← neg_mul, ← negMulLog_def, differentiableAt_negMulLog_iff] at h Β· fun_prop (disch := simp) set_option push_neg.use_distrib true in /-- Binary entropy has derivative `log (1 - p) - log p`. It's not differentiable at `0` or `1` but the junk values of `deriv` and `log` coincide there. -/ lemma deriv_binEntropy (p : ℝ) : deriv binEntropy p = log (1 - p) - log p := by by_cases hp : p β‰  0 ∧ p β‰  1 Β· obtain ⟨hpβ‚€, hpβ‚βŸ© := hp rw [ne_comm, ← sub_ne_zero] at hp₁ rw [binEntropy_eq_negMulLog_add_negMulLog_one_sub', deriv_fun_add, deriv_comp_const_sub, deriv_negMulLog hpβ‚€, deriv_negMulLog hp₁] Β· ring all_goals fun_prop (disch := assumption) -- pathological case where `deriv = 0` since `binEntropy` is not differentiable there Β· rw [deriv_zero_of_not_differentiableAt (differentiableAt_binEntropy_iff_ne_zero_one.not.2 hp)] push_neg at hp obtain rfl | rfl := hp <;> simp /-! ### `q`-ary entropy -/ /-- Shannon q-ary Entropy function (measured in Nats, i.e., using natural logs). It's the Shannon entropy of a random variable with possible outcomes {1, ..., q} where outcome `1` has probability `1 - p` and all other outcomes are equally likely. The usual domain of definition is p ∈ [0,1], i.e., input is a probability. This is a generalization of the binary entropy function `binEntropy`. -/ @[pp_nodot] noncomputable def qaryEntropy (q : β„•) (p : ℝ) : ℝ := p * log (q - 1 : β„€) + binEntropy p @[simp] lemma qaryEntropy_zero (q : β„•) : qaryEntropy q 0 = 0 := by simp [qaryEntropy] @[simp] lemma qaryEntropy_one (q : β„•) : qaryEntropy q 1 = log (q - 1 : β„€) := by simp [qaryEntropy] @[simp] lemma qaryEntropy_two : qaryEntropy 2 = binEntropy := by ext; simp [qaryEntropy] lemma qaryEntropy_pos (hpβ‚€ : 0 < p) (hp₁ : p < 1) : 0 < qaryEntropy q p := by unfold qaryEntropy positivity [binEntropy_pos hpβ‚€ hp₁] lemma qaryEntropy_nonneg (hpβ‚€ : 0 ≀ p) (hp₁ : p ≀ 1) : 0 ≀ qaryEntropy q p := by obtain rfl | hpβ‚€ := hpβ‚€.eq_or_lt Β· simp obtain rfl | hp₁ := hp₁.eq_or_lt Β· simpa [qaryEntropy, -Int.cast_sub] using log_intCast_nonneg _ exact (qaryEntropy_pos hpβ‚€ hp₁).le /-- Outside the usual range of `qaryEntropy`, it is negative. This is due to `log p = log |p|`. -/ lemma qaryEntropy_neg_of_neg (hp : p < 0) : qaryEntropy q p < 0 := add_neg_of_nonpos_of_neg (mul_nonpos_of_nonpos_of_nonneg hp.le (log_intCast_nonneg _)) (binEntropy_neg_of_neg hp) /-- Outside the usual range of `qaryEntropy`, it is negative. This is due to `log p = log |p|`. -/ lemma qaryEntropy_nonpos_of_nonpos (hp : p ≀ 0) : qaryEntropy q p ≀ 0 := add_nonpos (mul_nonpos_of_nonpos_of_nonneg hp (log_intCast_nonneg _)) (binEntropy_nonpos_of_nonpos hp) /-- The q-ary entropy function is continuous everywhere. This is due to definition of `Real.log` for negative numbers. -/ @[fun_prop] lemma qaryEntropy_continuous : Continuous (qaryEntropy q) := by unfold qaryEntropy; fun_prop @[fun_prop] lemma differentiableAt_qaryEntropy (hpβ‚€ : p β‰  0) (hp₁ : p β‰  1) : DifferentiableAt ℝ (qaryEntropy q) p := by unfold qaryEntropy; fun_prop (disch := assumption) lemma deriv_qaryEntropy (hpβ‚€ : p β‰  0) (hp₁ : p β‰  1) : deriv (qaryEntropy q) p = log (q - 1) + log (1 - p) - log p := by unfold qaryEntropy rw [deriv_fun_add] Β· simp only [Int.cast_sub, Int.cast_natCast, Int.cast_one, differentiableAt_fun_id, deriv_mul_const, deriv_id'', one_mul, deriv_binEntropy, add_sub_assoc] all_goals fun_prop (disch := assumption) /-- Binary entropy has derivative `log (1 - p) - log p`. -/ lemma hasDerivAt_binEntropy (hpβ‚€ : p β‰  0) (hp₁ : p β‰  1) : HasDerivAt binEntropy (log (1 - p) - log p) p := deriv_binEntropy _ β–Έ (differentiableAt_binEntropy hpβ‚€ hp₁).hasDerivAt lemma hasDerivAt_qaryEntropy (hpβ‚€ : p β‰  0) (hp₁ : p β‰  1) : HasDerivAt (qaryEntropy q) (log (q - 1) + log (1 - p) - log p) p := deriv_qaryEntropy hpβ‚€ hp₁ β–Έ (differentiableAt_qaryEntropy hpβ‚€ hp₁).hasDerivAt open Filter Topology Set private lemma tendsto_log_one_sub_sub_log_nhdsGT_atAtop : Tendsto (fun p ↦ log (1 - p) - log p) (𝓝[>] 0) atTop := by apply Filter.tendsto_atTop_add_left_of_le' (𝓝[>] 0) (log (1/2) : ℝ) Β· have h₁ : (0 : ℝ) < 1 / 2 := by simp filter_upwards [Ioc_mem_nhdsGT h₁] with p hx gcongr linarith [hx.2] Β· apply tendsto_neg_atTop_iff.mpr tendsto_log_nhdsGT_zero private lemma tendsto_log_one_sub_sub_log_nhdsLT_one_atBot : Tendsto (fun p ↦ log (1 - p) - log p) (𝓝[<] 1) atBot := by apply Filter.tendsto_atBot_add_right_of_ge' (𝓝[<] 1) (-log (1 - 2⁻¹)) Β· have : Tendsto log (𝓝[>] 0) atBot := Real.tendsto_log_nhdsGT_zero apply Tendsto.comp (f := (1 - Β·)) (g := log) this have contF : Continuous ((1 : ℝ) - Β·) := continuous_sub_left 1 have : MapsTo ((1 : ℝ) - Β·) (Iio 1) (Ioi 0) := by intro p hx simp_all only [mem_Iio, mem_Ioi, sub_pos] convert ContinuousWithinAt.tendsto_nhdsWithin (x :=(1 : ℝ)) contF.continuousWithinAt this exact Eq.symm (sub_eq_zero_of_eq rfl) Β· have h₁ : (1 : ℝ) - (2 : ℝ)⁻¹ < 1 := by norm_num filter_upwards [Ico_mem_nhdsLT h₁] with p hx gcongr exact hx.1 lemma not_continuousAt_deriv_qaryEntropy_one : Β¬ContinuousAt (deriv (qaryEntropy q)) 1 := by have tendstoBot : Tendsto (fun p ↦ log (q - 1) + log (1 - p) - log p) (𝓝[<] 1) atBot := by have : (fun p ↦ log (q - 1) + log (1 - p) - log p) = (fun p ↦ log (q - 1) + (log (1 - p) - log p)) := by ext ring rw [this] apply tendsto_atBot_add_const_left exact tendsto_log_one_sub_sub_log_nhdsLT_one_atBot apply not_continuousAt_of_tendsto (Filter.Tendsto.congr' _ tendstoBot) nhdsWithin_le_nhds Β· simp only [disjoint_nhds_atBot_iff, not_isBot, not_false_eq_true] filter_upwards [Ioo_mem_nhdsLT (show 1 - 2⁻¹ < (1 : ℝ) by norm_num)] intros apply (deriv_qaryEntropy _ _).symm Β· simp_all only [mem_Ioo, ne_eq] linarith [show (1 : ℝ) = 2⁻¹ + 2⁻¹ by norm_num] Β· simp_all only [mem_Ioo, ne_eq] linarith [two_inv_lt_one (Ξ± := ℝ)] lemma not_continuousAt_deriv_qaryEntropy_zero : Β¬ContinuousAt (deriv (qaryEntropy q)) 0 := by have tendstoTop : Tendsto (fun p ↦ log (q - 1) + log (1 - p) - log p) (𝓝[>] 0) atTop := by have : (fun p ↦ log (q - 1) + log (1 - p) - log p) = (fun p ↦ log (q - 1) + (log (1 - p) - log p)) := by ext; ring rw [this] exact tendsto_atTop_add_const_left _ _ tendsto_log_one_sub_sub_log_nhdsGT_atAtop apply not_continuousAt_of_tendsto (Filter.Tendsto.congr' _ tendstoTop) nhdsWithin_le_nhds Β· simp only [disjoint_nhds_atTop_iff, not_isTop, not_false_eq_true] filter_upwards [Ioo_mem_nhdsGT (show (0 : ℝ) < 2⁻¹ by norm_num)] intros apply (deriv_qaryEntropy _ _).symm Β· simp_all only [mem_Ioo, ne_eq] linarith Β· simp_all only [mem_Ioo, ne_eq] linarith [two_inv_lt_one (Ξ± := ℝ)] /-- Second derivative of q-ary entropy. -/ lemma deriv2_qaryEntropy : deriv^[2] (qaryEntropy q) p = -1 / (p * (1 - p)) := by simp only [Function.iterate_succ, Function.iterate_zero, Function.id_comp, Function.comp_apply] by_cases is_x_where_nondiff : p β‰  0 ∧ p β‰  1 -- normal case Β· obtain ⟨xne0, xne1⟩ := is_x_where_nondiff suffices βˆ€αΆ  y in (𝓝 p), deriv (fun p ↦ (qaryEntropy q) p) y = log (q - 1) + log (1 - y) - log y by refine (Filter.EventuallyEq.deriv_eq this).trans ?_ rw [deriv_fun_sub ?_ (differentiableAt_log xne0)] Β· rw [deriv.log differentiableAt_fun_id xne0] simp only [deriv_id'', one_div] Β· have {q : ℝ} (p : ℝ) : DifferentiableAt ℝ (fun p => q - p) p := by fun_prop have d_oneminus (p : ℝ) : deriv (fun (y : ℝ) ↦ 1 - y) p = -1 := by rw [deriv_const_sub 1, deriv_id''] simp [field, sub_ne_zero_of_ne xne1.symm, this, d_oneminus] ring Β· apply DifferentiableAt.add Β· simp only [differentiableAt_const] exact DifferentiableAt.log (by fun_prop) (sub_ne_zero.mpr xne1.symm) filter_upwards [eventually_ne_nhds xne0, eventually_ne_nhds xne1] with y xne0 h2 using deriv_qaryEntropy xne0 h2 -- Pathological case where we use junk value (because function not differentiable) Β· have : p = 0 ∨ p = 1 := Decidable.or_iff_not_not_and_not.mpr is_x_where_nondiff rw [deriv_zero_of_not_differentiableAt] Β· simp_all only [ne_eq, not_and, Decidable.not_not] cases this <;> simp_all only [ mul_zero, one_ne_zero, zero_ne_one, sub_zero, mul_one, div_zero, sub_self] Β· intro h have contAt := h.continuousAt cases this <;> simp_all [ not_continuousAt_deriv_qaryEntropy_zero, not_continuousAt_deriv_qaryEntropy_one] lemma deriv2_binEntropy : deriv^[2] binEntropy p = -1 / (p * (1 - p)) := qaryEntropy_two β–Έ deriv2_qaryEntropy /-! ### Strict monotonicity of entropy -/ /-- Qary entropy is strictly increasing in the interval [0, 1 - q⁻¹]. -/ lemma qaryEntropy_strictMonoOn (qLe2 : 2 ≀ q) : StrictMonoOn (qaryEntropy q) (Icc 0 (1 - 1/q)) := by intro p1 hp1 p2 hp2 p1le2 apply strictMonoOn_of_deriv_pos (convex_Icc 0 (1 - 1/(q : ℝ))) _ _ hp1 hp2 p1le2 Β· exact qaryEntropy_continuous.continuousOn Β· intro p hp have : 2 ≀ (q : ℝ) := Nat.ofNat_le_cast.mpr qLe2 have zero_le_qinv : 0 < (q : ℝ)⁻¹ := by positivity have : 0 < 1 - p := by simp only [sub_pos] have p_lt_1_minus_qinv : p < 1 - (q : ℝ)⁻¹ := by simp_all only [inv_pos, interior_Icc, mem_Ioo, one_div] linarith simp only [one_div, interior_Icc, mem_Ioo] at hp rw [deriv_qaryEntropy (by linarith)] Β· simp only [sub_pos, gt_iff_lt] rw [← log_mul (by linarith) (by linarith)] apply Real.strictMonoOn_log (mem_Ioi.mpr hp.1) Β· simp_all only [mem_Ioi, mul_pos_iff_of_pos_left, show 0 < (q : ℝ) - 1 by linarith] Β· have qpos : 0 < (q : ℝ) := by positivity have : q * p < q - 1 := by convert mul_lt_mul_of_pos_left hp.2 qpos using 1 simp only [mul_sub, mul_one, isUnit_iff_ne_zero, ne_eq, ne_of_gt qpos, not_false_eq_true, IsUnit.mul_inv_cancel] linarith exact (ne_of_gt (lt_add_neg_iff_lt.mp this : p < 1)).symm /-- Qary entropy is strictly decreasing in the interval [1 - q⁻¹, 1]. -/ lemma qaryEntropy_strictAntiOn (qLe2 : 2 ≀ q) : StrictAntiOn (qaryEntropy q) (Icc (1 - 1/q) 1) := by intro p1 hp1 p2 hp2 p1le2 apply strictAntiOn_of_deriv_neg (convex_Icc (1 - 1/(q : ℝ)) 1) _ _ hp1 hp2 p1le2 Β· exact qaryEntropy_continuous.continuousOn Β· intro p hp have : 2 ≀ (q : ℝ) := Nat.ofNat_le_cast.mpr qLe2 have qinv_lt_1 : (q : ℝ)⁻¹ < 1 := inv_lt_one_of_one_ltβ‚€ (by linarith) have zero_lt_1_sub_p : 0 < 1 - p := by simp_all only [sub_pos, interior_Icc, mem_Ioo] simp only [one_div, interior_Icc, mem_Ioo] at hp rw [deriv_qaryEntropy (by linarith)] Β· simp only [sub_neg, gt_iff_lt] rw [← log_mul (by linarith) (by linarith)] apply Real.strictMonoOn_log (mem_Ioi.mpr (show 0 < (↑q - 1) * (1 - p) by nlinarith)) Β· simp_all only [mem_Ioi] linarith Β· have qpos : 0 < (q : ℝ) := by positivity ring_nf simp only [add_lt_iff_neg_right, neg_add_lt_iff_lt_add, add_zero, gt_iff_lt] have : (q : ℝ) - 1 < p * q := by have h1 := mul_lt_mul_of_pos_right hp.1 qpos have h2 : (1 - (q : ℝ)⁻¹) * ↑q = q - 1 := by calc (1 - (q : ℝ)⁻¹) * ↑q _ = q - (q : ℝ)⁻¹ * (q : ℝ) := by ring _ = q - 1 := by simp [qpos.ne'] rwa [h2] at h1 nlinarith exact (ne_of_gt (lt_add_neg_iff_lt.mp zero_lt_1_sub_p : p < 1)).symm /-- Binary entropy is strictly increasing in interval [0, 1/2]. -/ lemma binEntropy_strictMonoOn : StrictMonoOn binEntropy (Icc 0 2⁻¹) := by rw [show Icc (0 : ℝ) 2⁻¹ = Icc 0 (1 - 1/2) by norm_num, ← qaryEntropy_two] exact qaryEntropy_strictMonoOn (by rfl) /-- Binary entropy is strictly decreasing in interval [1/2, 1]. -/ lemma binEntropy_strictAntiOn : StrictAntiOn binEntropy (Icc 2⁻¹ 1) := by rw [show (Icc (2⁻¹ : ℝ) 1) = Icc (1/2) 1 by norm_num, ← qaryEntropy_two] convert qaryEntropy_strictAntiOn (by rfl) using 1 norm_num /-! ### Strict concavity of entropy -/ lemma strictConcaveOn_qaryEntropy : StrictConcaveOn ℝ (Icc 0 1) (qaryEntropy q) := by apply strictConcaveOn_of_deriv2_neg (convex_Icc 0 1) qaryEntropy_continuous.continuousOn intro p hp rw [deriv2_qaryEntropy] Β· simp_all only [interior_Icc, mem_Ioo] apply div_neg_of_neg_of_pos Β· norm_num [show 0 < log 2 by positivity] Β· simp_all only [mul_pos_iff_of_pos_left, sub_pos] lemma strictConcave_binEntropy : StrictConcaveOn ℝ (Icc 0 1) binEntropy := qaryEntropy_two β–Έ strictConcaveOn_qaryEntropy end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pochhammer.lean
import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Convex.Deriv import Mathlib.Analysis.Convex.Piecewise import Mathlib.Analysis.Convex.Jensen /-! # Pochhammer polynomials This file proves analysis theorems for Pochhammer polynomials. ## Main statements * `Differentiable.descPochhammer_eval` is the proof that the descending Pochhammer polynomial `descPochhammer ℝ n` is differentiable. * `ConvexOn.descPochhammer_eval` is the proof that the descending Pochhammer polynomial `descPochhammer ℝ n` is convex on `[n-1, ∞)`. * `descPochhammer_eval_le_sum_descFactorial` is a special case of **Jensen's inequality** for `Nat.descFactorial`. * `descPochhammer_eval_div_factorial_le_sum_choose` is a special case of **Jensen's inequality** for `Nat.choose`. -/ section DescPochhammer variable {n : β„•} {π•œ : Type*} {k : π•œ} [NontriviallyNormedField π•œ] /-- `descPochhammer π•œ n` is differentiable. -/ theorem differentiable_descPochhammer_eval : Differentiable π•œ (descPochhammer π•œ n).eval := by simp [descPochhammer_eval_eq_prod_range, Differentiable.fun_finset_prod] /-- `descPochhammer π•œ n` is continuous. -/ theorem continuous_descPochhammer_eval : Continuous (descPochhammer π•œ n).eval := by exact differentiable_descPochhammer_eval.continuous lemma deriv_descPochhammer_eval_eq_sum_prod_range_erase (n : β„•) (k : π•œ) : deriv (descPochhammer π•œ n).eval k = βˆ‘ i ∈ Finset.range n, ∏ j ∈ (Finset.range n).erase i, (k - j) := by simp [descPochhammer_eval_eq_prod_range, deriv_fun_finset_prod] /-- `deriv (descPochhammer ℝ n)` is monotone on `(n-1, ∞)`. -/ lemma monotoneOn_deriv_descPochhammer_eval (n : β„•) : MonotoneOn (deriv (descPochhammer ℝ n).eval) (Set.Ioi (n - 1 : ℝ)) := by induction n with | zero => simp [monotoneOn_const] | succ n ih => intro a ha b hb hab rw [Set.mem_Ioi, Nat.cast_add_one, add_sub_cancel_right] at ha hb simp_rw [deriv_descPochhammer_eval_eq_sum_prod_range_erase] apply Finset.sum_le_sum; intro i hi apply Finset.prod_le_prod Β· intro j hj rw [Finset.mem_erase, Finset.mem_range] at hj apply sub_nonneg_of_le exact ha.le.trans' (mod_cast Nat.le_pred_of_lt hj.2) Β· intro j hj rwa [← sub_le_sub_iff_right (j : ℝ)] at hab /-- `descPochhammer ℝ n` is convex on `[n-1, ∞)`. -/ theorem convexOn_descPochhammer_eval (n : β„•) : ConvexOn ℝ (Set.Ici (n - 1 : ℝ)) (descPochhammer ℝ n).eval := by rcases n.eq_zero_or_pos with h_eq | _ Β· simp [h_eq, convexOn_const, convex_Ici] Β· apply MonotoneOn.convexOn_of_deriv (convex_Ici (n - 1 : ℝ)) continuous_descPochhammer_eval.continuousOn differentiable_descPochhammer_eval.differentiableOn rw [interior_Ici] exact monotoneOn_deriv_descPochhammer_eval n private lemma piecewise_Ici_descPochhammer_eval_zero_eq_descFactorial (k n : β„•) : (Set.Ici (n - 1 : ℝ)).piecewise (descPochhammer ℝ n).eval 0 k = k.descFactorial n := by rw [Set.piecewise, descPochhammer_eval_eq_descFactorial, ite_eq_left_iff, Set.mem_Ici, not_le, eq_comm, Pi.zero_apply, Nat.cast_eq_zero, Nat.descFactorial_eq_zero_iff_lt, ← @Nat.cast_lt ℝ] exact (sub_lt_self (n : ℝ) zero_lt_one).trans' private lemma convexOn_piecewise_Ici_descPochhammer_eval_zero (hn : n β‰  0) : ConvexOn ℝ Set.univ ((Set.Ici (n - 1 : ℝ)).piecewise (descPochhammer ℝ n).eval 0) := by rw [← Nat.pos_iff_ne_zero] at hn apply convexOn_univ_piecewise_Ici_of_monotoneOn_Ici_antitoneOn_Iic (convexOn_descPochhammer_eval n) (convexOn_const 0 (convex_Iic (n - 1 : ℝ))) (monotoneOn_descPochhammer_eval n) antitoneOn_const simpa [← Nat.cast_pred hn] using descPochhammer_eval_coe_nat_of_lt (Nat.sub_one_lt_of_lt hn) /-- Special case of **Jensen's inequality** for `Nat.descFactorial`. -/ theorem descPochhammer_eval_le_sum_descFactorial (hn : n β‰  0) {ΞΉ : Type*} {t : Finset ΞΉ} (p : ΞΉ β†’ β„•) (w : ΞΉ β†’ ℝ) (hβ‚€ : βˆ€ i ∈ t, 0 ≀ w i) (h₁ : βˆ‘ i ∈ t, w i = 1) (h_avg : n - 1 ≀ βˆ‘ i ∈ t, w i * p i) : (descPochhammer ℝ n).eval (βˆ‘ i ∈ t, w i * p i) ≀ βˆ‘ i ∈ t, w i * (p i).descFactorial n := by let f : ℝ β†’ ℝ := (Set.Ici (n - 1 : ℝ)).piecewise (descPochhammer ℝ n).eval 0 suffices h_jensen : f (βˆ‘ i ∈ t, w i β€’ p i) ≀ βˆ‘ i ∈ t, w i β€’ f (p i) by simpa only [smul_eq_mul, f, Set.piecewise_eq_of_mem (Set.Ici (n - 1 : ℝ)) _ _ h_avg, piecewise_Ici_descPochhammer_eval_zero_eq_descFactorial] using h_jensen exact ConvexOn.map_sum_le (convexOn_piecewise_Ici_descPochhammer_eval_zero hn) hβ‚€ h₁ (by simp) /-- Special case of **Jensen's inequality** for `Nat.choose`. -/ theorem descPochhammer_eval_div_factorial_le_sum_choose (hn : n β‰  0) {ΞΉ : Type*} {t : Finset ΞΉ} (p : ΞΉ β†’ β„•) (w : ΞΉ β†’ ℝ) (hβ‚€ : βˆ€ i ∈ t, 0 ≀ w i) (h₁ : βˆ‘ i ∈ t, w i = 1) (h_avg : n - 1 ≀ βˆ‘ i ∈ t, w i * p i) : (descPochhammer ℝ n).eval (βˆ‘ i ∈ t, w i * p i) / n.factorial ≀ βˆ‘ i ∈ t, w i * (p i).choose n := by simp_rw [Nat.cast_choose_eq_descPochhammer_div, mul_div, ← Finset.sum_div, descPochhammer_eval_eq_descFactorial] apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n.factorial) exact descPochhammer_eval_le_sum_descFactorial hn p w hβ‚€ h₁ h_avg end DescPochhammer
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Exp.lean
import Mathlib.Analysis.Complex.Asymptotics import Mathlib.Analysis.Complex.Trigonometric import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Topology.Algebra.MetricSpace.Lipschitz /-! # Complex and real exponential In this file we prove continuity of `Complex.exp` and `Real.exp`. We also prove a few facts about limits of `Real.exp` at infinity. ## Tags exp -/ noncomputable section open Asymptotics Bornology Finset Filter Function Metric Set Topology open scoped Nat namespace Complex variable {z y x : ℝ} theorem exp_bound_sq (x z : β„‚) (hz : β€–zβ€– ≀ 1) : β€–exp (x + z) - exp x - z β€’ exp xβ€– ≀ β€–exp xβ€– * β€–zβ€– ^ 2 := calc β€–exp (x + z) - exp x - z * exp xβ€– = β€–exp x * (exp z - 1 - z)β€– := by congr rw [exp_add] ring _ = β€–exp xβ€– * β€–exp z - 1 - zβ€– := norm_mul _ _ _ ≀ β€–exp xβ€– * β€–zβ€– ^ 2 := mul_le_mul_of_nonneg_left (norm_exp_sub_one_sub_id_le hz) (norm_nonneg _) theorem locally_lipschitz_exp {r : ℝ} (hr_nonneg : 0 ≀ r) (hr_le : r ≀ 1) (x y : β„‚) (hyx : β€–y - xβ€– < r) : β€–exp y - exp xβ€– ≀ (1 + r) * β€–exp xβ€– * β€–y - xβ€– := by have hy_eq : y = x + (y - x) := by abel have hyx_sq_le : β€–y - xβ€– ^ 2 ≀ r * β€–y - xβ€– := by rw [pow_two] exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg have h_sq : βˆ€ z, β€–zβ€– ≀ 1 β†’ β€–exp (x + z) - exp xβ€– ≀ β€–zβ€– * β€–exp xβ€– + β€–exp xβ€– * β€–zβ€– ^ 2 := by intro z hz have : β€–exp (x + z) - exp x - z β€’ exp xβ€– ≀ β€–exp xβ€– * β€–zβ€– ^ 2 := exp_bound_sq x z hz rw [← sub_le_iff_le_add', ← norm_smul z] exact (norm_sub_norm_le _ _).trans this calc β€–exp y - exp xβ€– = β€–exp (x + (y - x)) - exp xβ€– := by nth_rw 1 [hy_eq] _ ≀ β€–y - xβ€– * β€–exp xβ€– + β€–exp xβ€– * β€–y - xβ€– ^ 2 := h_sq (y - x) (hyx.le.trans hr_le) _ ≀ β€–y - xβ€– * β€–exp xβ€– + β€–exp xβ€– * (r * β€–y - xβ€–) := by grw [hyx_sq_le] _ = (1 + r) * β€–exp xβ€– * β€–y - xβ€– := by ring -- Porting note: proof by term mode `locally_lipschitz_exp zero_le_one le_rfl x` -- doesn't work because `β€–y - xβ€–` and `dist y x` don't unify @[continuity] theorem continuous_exp : Continuous exp := continuous_iff_continuousAt.mpr fun x => continuousAt_of_locally_lipschitz zero_lt_one (2 * β€–exp xβ€–) (fun y ↦ by convert locally_lipschitz_exp zero_le_one le_rfl x y using 2 congr ring) theorem continuousOn_exp {s : Set β„‚} : ContinuousOn exp s := continuous_exp.continuousOn lemma exp_sub_sum_range_isBigO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (Β· ^ n) := by rcases (zero_le n).eq_or_lt with rfl | hn Β· simpa using continuous_exp.continuousAt.norm.isBoundedUnder_le Β· refine .of_bound (n.succ / (n ! * n)) ?_ rw [NormedAddCommGroup.nhds_zero_basis_norm_lt.eventually_iff] refine ⟨1, one_pos, fun x hx ↦ ?_⟩ convert exp_bound hx.out.le hn using 1 simp [field] lemma exp_sub_sum_range_succ_isLittleO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (Β· ^ n) := (exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self end Complex section ComplexContinuousExpComp variable {Ξ± : Type*} open Complex theorem Filter.Tendsto.cexp {l : Filter Ξ±} {f : Ξ± β†’ β„‚} {z : β„‚} (hf : Tendsto f l (𝓝 z)) : Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) := (continuous_exp.tendsto _).comp hf variable [TopologicalSpace Ξ±] {f : Ξ± β†’ β„‚} {s : Set Ξ±} {x : Ξ±} nonrec theorem ContinuousWithinAt.cexp (h : ContinuousWithinAt f s x) : ContinuousWithinAt (fun y => exp (f y)) s x := h.cexp @[fun_prop] nonrec theorem ContinuousAt.cexp (h : ContinuousAt f x) : ContinuousAt (fun y => exp (f y)) x := h.cexp @[fun_prop] theorem ContinuousOn.cexp (h : ContinuousOn f s) : ContinuousOn (fun y => exp (f y)) s := fun x hx => (h x hx).cexp @[fun_prop] theorem Continuous.cexp (h : Continuous f) : Continuous fun y => exp (f y) := continuous_iff_continuousAt.2 fun _ => h.continuousAt.cexp /-- The complex exponential function is uniformly continuous on left half planes. -/ lemma UniformContinuousOn.cexp (a : ℝ) : UniformContinuousOn exp {x : β„‚ | x.re ≀ a} := by have : Continuous (cexp - 1) := Continuous.sub (Continuous.cexp continuous_id') continuous_one rw [Metric.uniformContinuousOn_iff, Metric.continuous_iff'] at * intro Ξ΅ hΞ΅ simp only [gt_iff_lt, Pi.sub_apply, Pi.one_apply, dist_sub_eq_dist_add_right, sub_add_cancel] at this have ha : 0 < Ξ΅ / (2 * Real.exp a) := by positivity have H := this 0 (Ξ΅ / (2 * Real.exp a)) ha rw [Metric.eventually_nhds_iff] at H obtain ⟨δ, hδ⟩ := H refine ⟨δ, hΞ΄.1, ?_⟩ intro x _ y hy hxy have h3 := hΞ΄.2 (y := x - y) (by simpa only [dist_zero_right] using hxy) rw [dist_eq_norm, exp_zero] at * have : cexp x - cexp y = cexp y * (cexp (x - y) - 1) := by rw [mul_sub_one, ← exp_add] ring_nf rw [this, mul_comm] have hya : β€–cexp yβ€– ≀ Real.exp a := by simpa only [norm_exp, Real.exp_le_exp] simp only [gt_iff_lt, dist_zero_right, Set.mem_setOf_eq, norm_mul, Complex.norm_exp] at * apply lt_of_le_of_lt (mul_le_mul h3.le hya (Real.exp_nonneg y.re) ha.le) simp [field] end ComplexContinuousExpComp namespace Real @[continuity, fun_prop] theorem continuous_exp : Continuous exp := by unfold Real.exp; fun_prop theorem continuousOn_exp {s : Set ℝ} : ContinuousOn exp s := by fun_prop lemma exp_sub_sum_range_isBigO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (Β· ^ n) := by have := (Complex.exp_sub_sum_range_isBigO_pow n).comp_tendsto (Complex.continuous_ofReal.tendsto' 0 0 rfl) simp only [Function.comp_def] at this norm_cast at this lemma exp_sub_sum_range_succ_isLittleO_pow (n : β„•) : (fun x ↦ exp x - βˆ‘ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (Β· ^ n) := (exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self end Real section RealContinuousExpComp variable {Ξ± : Type*} open Real theorem Filter.Tendsto.rexp {l : Filter Ξ±} {f : Ξ± β†’ ℝ} {z : ℝ} (hf : Tendsto f l (𝓝 z)) : Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) := (continuous_exp.tendsto _).comp hf variable [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} {s : Set Ξ±} {x : Ξ±} nonrec theorem ContinuousWithinAt.rexp (h : ContinuousWithinAt f s x) : ContinuousWithinAt (fun y ↦ exp (f y)) s x := h.rexp @[fun_prop] nonrec theorem ContinuousAt.rexp (h : ContinuousAt f x) : ContinuousAt (fun y ↦ exp (f y)) x := h.rexp @[fun_prop] theorem ContinuousOn.rexp (h : ContinuousOn f s) : ContinuousOn (fun y ↦ exp (f y)) s := fun x hx ↦ (h x hx).rexp @[fun_prop] theorem Continuous.rexp (h : Continuous f) : Continuous fun y ↦ exp (f y) := continuous_iff_continuousAt.2 fun _ ↦ h.continuousAt.rexp end RealContinuousExpComp namespace Real variable {Ξ± : Type*} {x y z : ℝ} {l : Filter Ξ±} theorem exp_half (x : ℝ) : exp (x / 2) = √(exp x) := by rw [eq_comm, sqrt_eq_iff_eq_sq, sq, ← exp_add, add_halves] <;> exact (exp_pos _).le /-- The real exponential function tends to `+∞` at `+∞`. -/ theorem tendsto_exp_atTop : Tendsto exp atTop atTop := by have A : Tendsto (fun x : ℝ => x + 1) atTop atTop := tendsto_atTop_add_const_right atTop 1 tendsto_id have B : βˆ€αΆ  x in atTop, x + 1 ≀ exp x := eventually_atTop.2 ⟨0, fun x _ => add_one_le_exp x⟩ exact tendsto_atTop_mono' atTop B A /-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0` at `+∞` -/ theorem tendsto_exp_neg_atTop_nhds_zero : Tendsto (fun x => exp (-x)) atTop (𝓝 0) := (tendsto_inv_atTop_zero.comp tendsto_exp_atTop).congr fun x => (exp_neg x).symm /-- The real exponential function tends to `1` at `0`. -/ theorem tendsto_exp_nhds_zero_nhds_one : Tendsto exp (𝓝 0) (𝓝 1) := by convert continuous_exp.tendsto 0 simp theorem tendsto_exp_atBot : Tendsto exp atBot (𝓝 0) := (tendsto_exp_neg_atTop_nhds_zero.comp tendsto_neg_atBot_atTop).congr fun x => congr_arg exp <| neg_neg x theorem tendsto_exp_atBot_nhdsGT : Tendsto exp atBot (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_exp_atBot, tendsto_principal.2 <| Eventually.of_forall exp_pos⟩ @[simp] theorem isBoundedUnder_ge_exp_comp (l : Filter Ξ±) (f : Ξ± β†’ ℝ) : IsBoundedUnder (Β· β‰₯ Β·) l fun x => exp (f x) := isBoundedUnder_of ⟨0, fun _ => (exp_pos _).le⟩ @[simp] theorem isBoundedUnder_le_exp_comp {f : Ξ± β†’ ℝ} : (IsBoundedUnder (Β· ≀ Β·) l fun x => exp (f x)) ↔ IsBoundedUnder (Β· ≀ Β·) l f := exp_monotone.isBoundedUnder_le_comp_iff tendsto_exp_atTop /-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/ theorem tendsto_exp_div_pow_atTop (n : β„•) : Tendsto (fun x => exp x / x ^ n) atTop atTop := by refine (atTop_basis_Ioi.tendsto_iff (atTop_basis' 1)).2 fun C hC₁ => ?_ have hCβ‚€ : 0 < C := zero_lt_one.trans_le hC₁ have : 0 < (exp 1 * C)⁻¹ := inv_pos.2 (mul_pos (exp_pos _) hCβ‚€) obtain ⟨N, hN⟩ : βˆƒ N : β„•, βˆ€ k β‰₯ N, (↑k : ℝ) ^ n / exp 1 ^ k < (exp 1 * C)⁻¹ := eventually_atTop.1 ((tendsto_pow_const_div_const_pow_of_one_lt n (one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)) simp only [← exp_nat_mul, mul_one, div_lt_iffβ‚€, exp_pos, ← div_eq_inv_mul] at hN refine ⟨N, trivial, fun x hx => ?_⟩ rw [Set.mem_Ioi] at hx have hxβ‚€ : 0 < x := (Nat.cast_nonneg N).trans_lt hx rw [Set.mem_Ici, le_div_iffβ‚€ (pow_pos hxβ‚€ _), ← le_div_iffβ‚€' hCβ‚€] calc x ^ n ≀ ⌈xβŒ‰β‚Š ^ n := by gcongr; exact Nat.le_ceil _ _ ≀ exp ⌈xβŒ‰β‚Š / (exp 1 * C) := mod_cast (hN _ (Nat.lt_ceil.2 hx).le).le _ ≀ exp (x + 1) / (exp 1 * C) := by gcongr; exact (Nat.ceil_lt_add_one hxβ‚€.le).le _ = exp x / C := by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne'] /-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/ theorem tendsto_pow_mul_exp_neg_atTop_nhds_zero (n : β„•) : Tendsto (fun x => x ^ n * exp (-x)) atTop (𝓝 0) := (tendsto_inv_atTop_zero.comp (tendsto_exp_div_pow_atTop n)).congr fun x => by rw [comp_apply, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg] /-- The function `(b * exp x + c) / (x ^ n)` tends to `+∞` at `+∞`, for any natural number `n` and any real numbers `b` and `c` such that `b` is positive. -/ theorem tendsto_mul_exp_add_div_pow_atTop (b c : ℝ) (n : β„•) (hb : 0 < b) : Tendsto (fun x => (b * exp x + c) / x ^ n) atTop atTop := by rcases eq_or_ne n 0 with (rfl | hn) Β· simp only [pow_zero, div_one] exact (tendsto_exp_atTop.const_mul_atTop hb).atTop_add tendsto_const_nhds simp only [add_div, mul_div_assoc] exact ((tendsto_exp_div_pow_atTop n).const_mul_atTop hb).atTop_add (tendsto_const_nhds.div_atTop (tendsto_pow_atTop hn)) /-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+∞`, for any natural number `n` and any real numbers `b` and `c` such that `b` is nonzero. -/ theorem tendsto_div_pow_mul_exp_add_atTop (b c : ℝ) (n : β„•) (hb : 0 β‰  b) : Tendsto (fun x => x ^ n / (b * exp x + c)) atTop (𝓝 0) := by have H : βˆ€ d e, 0 < d β†’ Tendsto (fun x : ℝ => x ^ n / (d * exp x + e)) atTop (𝓝 0) := by intro b' c' h convert (tendsto_mul_exp_add_div_pow_atTop b' c' n h).inv_tendsto_atTop using 1 ext x simp rcases lt_or_gt_of_ne hb with h | h Β· exact H b c h Β· convert (H (-b) (-c) (neg_pos.mpr h)).neg using 1 Β· ext x field_simp rw [← neg_add (b * exp x) c, div_neg, neg_neg] Β· rw [neg_zero] /-- `Real.exp` as an order isomorphism between `ℝ` and `(0, +∞)`. -/ def expOrderIso : ℝ ≃o Ioi (0 : ℝ) := StrictMono.orderIsoOfSurjective _ (exp_strictMono.codRestrict exp_pos) <| (continuous_exp.subtype_mk _).surjective (by rw [tendsto_Ioi_atTop]; simp only [tendsto_exp_atTop]) (by rw [tendsto_Ioi_atBot]; simp only [tendsto_exp_atBot_nhdsGT]) @[simp] theorem coe_expOrderIso_apply (x : ℝ) : (expOrderIso x : ℝ) = exp x := rfl @[simp] theorem coe_comp_expOrderIso : (↑) ∘ expOrderIso = exp := rfl @[simp] theorem range_exp : range exp = Set.Ioi 0 := by rw [← coe_comp_expOrderIso, range_comp, expOrderIso.range_eq, image_univ, Subtype.range_coe] @[simp] theorem map_exp_atTop : map exp atTop = atTop := by rw [← coe_comp_expOrderIso, ← Filter.map_map, OrderIso.map_atTop, map_val_Ioi_atTop] @[simp] theorem comap_exp_atTop : comap exp atTop = atTop := by rw [← map_exp_atTop, comap_map exp_injective, map_exp_atTop] @[simp] theorem tendsto_exp_comp_atTop {f : Ξ± β†’ ℝ} : Tendsto (fun x => exp (f x)) l atTop ↔ Tendsto f l atTop := by simp_rw [← comp_apply (f := exp), ← tendsto_comap_iff, comap_exp_atTop] theorem tendsto_comp_exp_atTop {f : ℝ β†’ Ξ±} : Tendsto (fun x => f (exp x)) atTop l ↔ Tendsto f atTop l := by simp_rw [← comp_apply (g := exp), ← tendsto_map'_iff, map_exp_atTop] @[simp] theorem map_exp_atBot : map exp atBot = 𝓝[>] 0 := by rw [← coe_comp_expOrderIso, ← Filter.map_map, expOrderIso.map_atBot, ← map_coe_Ioi_atBot] @[simp] theorem comap_exp_nhdsGT_zero : comap exp (𝓝[>] 0) = atBot := by rw [← map_exp_atBot, comap_map exp_injective] theorem tendsto_comp_exp_atBot {f : ℝ β†’ Ξ±} : Tendsto (fun x => f (exp x)) atBot l ↔ Tendsto f (𝓝[>] 0) l := by rw [← map_exp_atBot, tendsto_map'_iff] rfl @[simp] theorem comap_exp_nhds_zero : comap exp (𝓝 0) = atBot := (comap_nhdsWithin_range exp 0).symm.trans <| by simp @[simp] theorem tendsto_exp_comp_nhds_zero {f : Ξ± β†’ ℝ} : Tendsto (fun x => exp (f x)) l (𝓝 0) ↔ Tendsto f l atBot := by simp_rw [← comp_apply (f := exp), ← tendsto_comap_iff, comap_exp_nhds_zero] @[fun_prop] theorem isOpenEmbedding_exp : IsOpenEmbedding exp := isOpen_Ioi.isOpenEmbedding_subtypeVal.comp expOrderIso.toHomeomorph.isOpenEmbedding @[simp] theorem map_exp_nhds (x : ℝ) : map exp (𝓝 x) = 𝓝 (exp x) := isOpenEmbedding_exp.map_nhds_eq x @[simp] theorem comap_exp_nhds_exp (x : ℝ) : comap exp (𝓝 (exp x)) = 𝓝 x := (isOpenEmbedding_exp.nhds_eq_comap x).symm theorem isLittleO_pow_exp_atTop {n : β„•} : (fun x : ℝ => x ^ n) =o[atTop] Real.exp := by simpa [isLittleO_iff_tendsto fun x hx => ((exp_pos x).ne' hx).elim] using tendsto_div_pow_mul_exp_add_atTop 1 0 n zero_ne_one @[simp] theorem isBigO_exp_comp_exp_comp {f g : Ξ± β†’ ℝ} : ((fun x => exp (f x)) =O[l] fun x => exp (g x)) ↔ IsBoundedUnder (Β· ≀ Β·) l (f - g) := Iff.trans (isBigO_iff_isBoundedUnder_le_div <| Eventually.of_forall fun _ => exp_ne_zero _) <| by simp only [norm_eq_abs, abs_exp, ← exp_sub, isBoundedUnder_le_exp_comp, Pi.sub_def] @[simp] theorem isTheta_exp_comp_exp_comp {f g : Ξ± β†’ ℝ} : ((fun x => exp (f x)) =Θ[l] fun x => exp (g x)) ↔ IsBoundedUnder (Β· ≀ Β·) l fun x => |f x - g x| := by simp only [isBoundedUnder_le_abs, ← isBoundedUnder_le_neg, neg_sub, IsTheta, isBigO_exp_comp_exp_comp, Pi.sub_def] @[simp] theorem isLittleO_exp_comp_exp_comp {f g : Ξ± β†’ ℝ} : ((fun x => exp (f x)) =o[l] fun x => exp (g x)) ↔ Tendsto (fun x => g x - f x) l atTop := by simp only [isLittleO_iff_tendsto, exp_ne_zero, ← exp_sub, ← tendsto_neg_atTop_iff, false_imp_iff, imp_true_iff, tendsto_exp_comp_nhds_zero, neg_sub] theorem isLittleO_one_exp_comp {f : Ξ± β†’ ℝ} : ((fun _ => 1 : Ξ± β†’ ℝ) =o[l] fun x => exp (f x)) ↔ Tendsto f l atTop := by simp only [← exp_zero, isLittleO_exp_comp_exp_comp, sub_zero] /-- `Real.exp (f x)` is bounded away from zero along a filter if and only if this filter is bounded from below under `f`. -/ @[simp] theorem isBigO_one_exp_comp {f : Ξ± β†’ ℝ} : ((fun _ => 1 : Ξ± β†’ ℝ) =O[l] fun x => exp (f x)) ↔ IsBoundedUnder (Β· β‰₯ Β·) l f := by simp only [← exp_zero, isBigO_exp_comp_exp_comp, Pi.sub_def, zero_sub, isBoundedUnder_le_neg] /-- `Real.exp (f x)` is bounded away from zero along a filter if and only if this filter is bounded from below under `f`. -/ theorem isBigO_exp_comp_one {f : Ξ± β†’ ℝ} : (fun x => exp (f x)) =O[l] (fun _ => 1 : Ξ± β†’ ℝ) ↔ IsBoundedUnder (Β· ≀ Β·) l f := by simp only [isBigO_one_iff, norm_eq_abs, abs_exp, isBoundedUnder_le_exp_comp] /-- `Real.exp (f x)` is bounded away from zero and infinity along a filter `l` if and only if `|f x|` is bounded from above along this filter. -/ @[simp] theorem isTheta_exp_comp_one {f : Ξ± β†’ ℝ} : (fun x => exp (f x)) =Θ[l] (fun _ => 1 : Ξ± β†’ ℝ) ↔ IsBoundedUnder (Β· ≀ Β·) l fun x => |f x| := by simp only [← exp_zero, isTheta_exp_comp_exp_comp, sub_zero] lemma summable_exp_nat_mul_iff {a : ℝ} : Summable (fun n : β„• ↦ exp (n * a)) ↔ a < 0 := by simp only [exp_nat_mul, summable_geometric_iff_norm_lt_one, norm_of_nonneg (exp_nonneg _), exp_lt_one_iff] lemma summable_exp_neg_nat : Summable fun n : β„• ↦ exp (-n) := by simpa only [mul_neg_one] using summable_exp_nat_mul_iff.mpr neg_one_lt_zero lemma summable_exp_nat_mul_of_ge {c : ℝ} (hc : c < 0) {f : β„• β†’ ℝ} (hf : βˆ€ i, i ≀ f i) : Summable fun i : β„• ↦ exp (c * f i) := by refine (Real.summable_exp_nat_mul_iff.mpr hc).of_nonneg_of_le (fun _ ↦ by positivity) fun i ↦ ?_ refine Real.exp_monotone ?_ conv_rhs => rw [mul_comm] exact mul_le_mul_of_nonpos_left (hf i) hc.le lemma summable_pow_mul_exp_neg_nat_mul (k : β„•) {r : ℝ} (hr : 0 < r) : Summable fun n : β„• ↦ n ^ k * exp (-r * n) := by simp_rw [mul_comm (-r), exp_nat_mul] apply summable_pow_mul_geometric_of_norm_lt_one rwa [norm_of_nonneg (exp_nonneg _), exp_lt_one_iff, neg_lt_zero] end Real open Real in /-- If `f` has sum `a`, then `exp ∘ f` has product `exp a`. -/ lemma HasSum.rexp {ΞΉ} {f : ΞΉ β†’ ℝ} {a : ℝ} (h : HasSum f a) : HasProd (rexp ∘ f) (rexp a) := Tendsto.congr (fun s ↦ exp_sum s f) <| Tendsto.rexp h namespace Complex @[simp] theorem comap_exp_cobounded : comap exp (cobounded β„‚) = comap re atTop := calc comap exp (cobounded β„‚) = comap re (comap Real.exp atTop) := by simp only [← comap_norm_atTop, comap_comap, comp_def, norm_exp] _ = comap re atTop := by rw [Real.comap_exp_atTop] @[simp] theorem comap_exp_nhds_zero : comap exp (𝓝 0) = comap re atBot := calc comap exp (𝓝 0) = comap re (comap Real.exp (𝓝 0)) := by rw [← comap_norm_nhds_zero, comap_comap, Function.comp_def] simp_rw [norm_exp, comap_comap, Function.comp_def] _ = comap re atBot := by rw [Real.comap_exp_nhds_zero] theorem comap_exp_nhdsNE : comap exp (𝓝[β‰ ] 0) = comap re atBot := by have : (exp ⁻¹' {0})ᢜ = Set.univ := eq_univ_of_forall exp_ne_zero simp [nhdsWithin, comap_exp_nhds_zero, this] theorem tendsto_exp_nhds_zero_iff {Ξ± : Type*} {l : Filter Ξ±} {f : Ξ± β†’ β„‚} : Tendsto (fun x => exp (f x)) l (𝓝 0) ↔ Tendsto (fun x => re (f x)) l atBot := by simp_rw [← comp_apply (f := exp), ← tendsto_comap_iff, comap_exp_nhds_zero, tendsto_comap_iff] rfl /-- `β€–Complex.exp zβ€– β†’ ∞` as `Complex.re z β†’ ∞`. -/ theorem tendsto_exp_comap_re_atTop : Tendsto exp (comap re atTop) (cobounded β„‚) := comap_exp_cobounded β–Έ tendsto_comap /-- `Complex.exp z β†’ 0` as `Complex.re z β†’ -∞`. -/ theorem tendsto_exp_comap_re_atBot : Tendsto exp (comap re atBot) (𝓝 0) := comap_exp_nhds_zero β–Έ tendsto_comap theorem tendsto_exp_comap_re_atBot_nhdsNE : Tendsto exp (comap re atBot) (𝓝[β‰ ] 0) := comap_exp_nhdsNE β–Έ tendsto_comap end Complex open Complex in /-- If `f` has sum `a`, then `exp ∘ f` has product `exp a`. -/ lemma HasSum.cexp {ΞΉ : Type*} {f : ΞΉ β†’ β„‚} {a : β„‚} (h : HasSum f a) : HasProd (cexp ∘ f) (cexp a) := Filter.Tendsto.congr (fun s ↦ exp_sum s f) <| Filter.Tendsto.cexp h
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/OrdinaryHypergeometric.lean
import Mathlib.Analysis.Analytic.OfScalars import Mathlib.Analysis.RCLike.Basic /-! # Ordinary hypergeometric function in a Banach algebra In this file, we define `ordinaryHypergeometric`, the _ordinary_ or _Gaussian_ hypergeometric function in a topological algebra `𝔸` over a field `𝕂` given by: $$ _2\mathrm{F}_1(a\ b\ c : \mathbb{K}, x : \mathbb{A}) = \sum_{n=0}^{\infty}\frac{(a)_n(b)_n}{(c)_n} \frac{x^n}{n!} \,, $$ with $(a)_n$ is the ascending Pochhammer symbol (see `ascPochhammer`). This file contains the basic definitions over a general field `𝕂` and notation for `β‚‚F₁`, as well as showing that terms of the series are zero if any of the `(a b c : 𝕂)` are sufficiently large non-positive integers, rendering the series finite. In this file "sufficiently large" means that `-n < a` for the `n`-th term, and similarly for `b` and `c`. - `ordinaryHypergeometricSeries` is the `FormalMultilinearSeries` given above for some `(a b c : 𝕂)` - `ordinaryHypergeometric` is the sum of the series for some `(x : 𝔸)` - `ordinaryHypergeometricSeries_eq_zero_of_nonpos_int` shows that the `n`-th term of the series is zero if any of the parameters are sufficiently large non-positive integers ## `[RCLike 𝕂]` If we have `[RCLike 𝕂]`, then we show that the latter result is an iff, and hence prove that the radius of convergence of the series is unity if the series is infinite, or `⊀` otherwise. - `ordinaryHypergeometricSeries_eq_zero_iff` is iff variant of `ordinaryHypergeometricSeries_eq_zero_of_nonpos_int` - `ordinaryHypergeometricSeries_radius_eq_one` proves that the radius of convergence of the `ordinaryHypergeometricSeries` is unity under non-trivial parameters ## Notation `β‚‚F₁` is notation for `ordinaryHypergeometric`. ## References See <https://en.wikipedia.org/wiki/Hypergeometric_function>. ## Tags hypergeometric, gaussian, ordinary -/ open Nat FormalMultilinearSeries section Field variable {𝕂 : Type*} (𝔸 : Type*) [Field 𝕂] [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸] /-- The coefficients in the ordinary hypergeometric sum. -/ noncomputable abbrev ordinaryHypergeometricCoefficient (a b c : 𝕂) (n : β„•) := ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹) /-- `ordinaryHypergeometricSeries 𝔸 (a b c : 𝕂)` is a `FormalMultilinearSeries`. Its sum is the `ordinaryHypergeometric` map. -/ noncomputable def ordinaryHypergeometricSeries (a b c : 𝕂) : FormalMultilinearSeries 𝕂 𝔸 𝔸 := ofScalars 𝔸 (ordinaryHypergeometricCoefficient a b c) variable {𝔸} (a b c : 𝕂) /-- `ordinaryHypergeometric (a b c : 𝕂) : 𝔸 β†’ 𝔸`, denoted `β‚‚F₁`, is the ordinary hypergeometric map, defined as the sum of the `FormalMultilinearSeries` `ordinaryHypergeometricSeries 𝔸 a b c`. Note that this takes the junk value `0` outside the radius of convergence. -/ noncomputable def ordinaryHypergeometric (x : 𝔸) : 𝔸 := (ordinaryHypergeometricSeries 𝔸 a b c).sum x @[inherit_doc] notation "β‚‚F₁" => ordinaryHypergeometric theorem ordinaryHypergeometricSeries_apply_eq (x : 𝔸) (n : β„•) : (ordinaryHypergeometricSeries 𝔸 a b c n fun _ => x) = ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) β€’ x ^ n := by rw [ordinaryHypergeometricSeries, ofScalars_apply_eq] /-- This naming follows the convention of `NormedSpace.expSeries_apply_eq'`. -/ theorem ordinaryHypergeometricSeries_apply_eq' (x : 𝔸) : (fun n => ordinaryHypergeometricSeries 𝔸 a b c n fun _ => x) = fun n => ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) β€’ x ^ n := by rw [ordinaryHypergeometricSeries, ofScalars_apply_eq'] theorem ordinaryHypergeometric_sum_eq (x : 𝔸) : (ordinaryHypergeometricSeries 𝔸 a b c).sum x = βˆ‘' n : β„•, ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) β€’ x ^ n := tsum_congr fun n => ordinaryHypergeometricSeries_apply_eq a b c x n theorem ordinaryHypergeometric_eq_tsum : β‚‚F₁ a b c = fun (x : 𝔸) => βˆ‘' n : β„•, ((n !⁻¹ : 𝕂) * (ascPochhammer 𝕂 n).eval a * (ascPochhammer 𝕂 n).eval b * ((ascPochhammer 𝕂 n).eval c)⁻¹ ) β€’ x ^ n := funext (ordinaryHypergeometric_sum_eq a b c) theorem ordinaryHypergeometricSeries_apply_zero (n : β„•) : ordinaryHypergeometricSeries 𝔸 a b c n (fun _ => 0) = Pi.single (M := fun _ => 𝔸) 0 1 n := by rw [ordinaryHypergeometricSeries, ofScalars_apply_eq, ordinaryHypergeometricCoefficient] cases n <;> simp @[simp] theorem ordinaryHypergeometric_zero : β‚‚F₁ a b c (0 : 𝔸) = 1 := by simp [ordinaryHypergeometric_eq_tsum, ← ordinaryHypergeometricSeries_apply_eq, ordinaryHypergeometricSeries_apply_zero] theorem ordinaryHypergeometricSeries_symm : ordinaryHypergeometricSeries 𝔸 a b c = ordinaryHypergeometricSeries 𝔸 b a c := by unfold ordinaryHypergeometricSeries ordinaryHypergeometricCoefficient simp [mul_assoc, mul_left_comm] /-- If any parameter to the series is a sufficiently large nonpositive integer, then the series term is zero. -/ lemma ordinaryHypergeometricSeries_eq_zero_of_neg_nat {n k : β„•} (habc : k = -a ∨ k = -b ∨ k = -c) (hk : k < n) : ordinaryHypergeometricSeries 𝔸 a b c n = 0 := by rw [ordinaryHypergeometricSeries, ofScalars] rcases habc with h | h | h all_goals ext simp [(ascPochhammer_eval_eq_zero_iff n _).2 ⟨k, hk, h⟩] end Field section RCLike open Asymptotics Filter Real Set Nat open scoped Topology variable {𝕂 : Type*} (𝔸 : Type*) [RCLike 𝕂] [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸] (a b c : 𝕂) theorem ordinaryHypergeometric_radius_top_of_neg_nat₁ {k : β„•} : (ordinaryHypergeometricSeries 𝔸 (-(k : 𝕂)) b c).radius = ⊀ := by refine FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero _ (1 + k) fun n ↦ ?_ exact ordinaryHypergeometricSeries_eq_zero_of_neg_nat (-(k : 𝕂)) b c (by aesop) (by cutsat) theorem ordinaryHypergeometric_radius_top_of_neg_natβ‚‚ {k : β„•} : (ordinaryHypergeometricSeries 𝔸 a (-(k : 𝕂)) c).radius = ⊀ := by rw [ordinaryHypergeometricSeries_symm] exact ordinaryHypergeometric_radius_top_of_neg_nat₁ 𝔸 a c theorem ordinaryHypergeometric_radius_top_of_neg_nat₃ {k : β„•} : (ordinaryHypergeometricSeries 𝔸 a b (-(k : 𝕂))).radius = ⊀ := by refine FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero _ (1 + k) fun n ↦ ?_ exact ordinaryHypergeometricSeries_eq_zero_of_neg_nat a b (-(k : 𝕂)) (by aesop) (by cutsat) /-- An iff variation on `ordinaryHypergeometricSeries_eq_zero_of_nonpos_int` for `[RCLike 𝕂]`. -/ lemma ordinaryHypergeometricSeries_eq_zero_iff (n : β„•) : ordinaryHypergeometricSeries 𝔸 a b c n = 0 ↔ βˆƒ k < n, k = -a ∨ k = -b ∨ k = -c := by refine ⟨fun h ↦ ?_, fun zero ↦ ?_⟩ Β· rw [ordinaryHypergeometricSeries, ofScalars_eq_zero] at h simp only [_root_.mul_eq_zero, inv_eq_zero] at h rcases h with ((hn | h) | h) | h Β· simp [Nat.factorial_ne_zero] at hn all_goals obtain ⟨kn, hkn, hn⟩ := (ascPochhammer_eval_eq_zero_iff _ _).1 h exact ⟨kn, hkn, by tauto⟩ Β· obtain ⟨_, h, hn⟩ := zero exact ordinaryHypergeometricSeries_eq_zero_of_neg_nat a b c hn h theorem ordinaryHypergeometricSeries_norm_div_succ_norm (n : β„•) (habc : βˆ€ kn < n, (↑kn β‰  -a ∧ ↑kn β‰  -b ∧ ↑kn β‰  -c)) : β€–ordinaryHypergeometricCoefficient a b c nβ€– / β€–ordinaryHypergeometricCoefficient a b c n.succβ€– = β€–a + n‖⁻¹ * β€–b + n‖⁻¹ * β€–c + nβ€– * β€–1 + (n : 𝕂)β€– := by simp only [mul_inv_rev, factorial_succ, cast_mul, cast_add, cast_one, ascPochhammer_succ_eval, norm_mul, norm_inv] calc _ = β€–Polynomial.eval a (ascPochhammer 𝕂 n)β€– * β€–Polynomial.eval a (ascPochhammer 𝕂 n)‖⁻¹ * β€–Polynomial.eval b (ascPochhammer 𝕂 n)β€– * β€–Polynomial.eval b (ascPochhammer 𝕂 n)‖⁻¹ * β€–Polynomial.eval c (ascPochhammer 𝕂 n)‖⁻¹⁻¹ * β€–Polynomial.eval c (ascPochhammer 𝕂 n)‖⁻¹ * β€–(n ! : 𝕂)‖⁻¹⁻¹ * β€–(n ! : 𝕂)‖⁻¹ * β€–a + n‖⁻¹ * β€–b + n‖⁻¹ * β€–c + n‖⁻¹⁻¹ * β€–1 + (n : 𝕂)‖⁻¹⁻¹ := by ring_nf _ = _ := by simp only [inv_inv] repeat rw [DivisionRing.mul_inv_cancel, one_mul] all_goals rw [norm_ne_zero_iff] any_goals apply (ascPochhammer_eval_eq_zero_iff n _).not.2 push_neg exact fun kn hkn ↦ by simp [habc kn hkn] exact cast_ne_zero.2 (factorial_ne_zero n) /-- The radius of convergence of `ordinaryHypergeometricSeries` is unity if none of the parameters are non-positive integers. -/ theorem ordinaryHypergeometricSeries_radius_eq_one (habc : βˆ€ kn : β„•, ↑kn β‰  -a ∧ ↑kn β‰  -b ∧ ↑kn β‰  -c) : (ordinaryHypergeometricSeries 𝔸 a b c).radius = 1 := by convert ofScalars_radius_eq_of_tendsto 𝔸 _ one_ne_zero ?_ suffices Tendsto (fun k : β„• ↦ (a + k)⁻¹ * (b + k)⁻¹ * (c + k) * ((1 : 𝕂) + k)) atTop (𝓝 1) by simp_rw [ordinaryHypergeometricSeries_norm_div_succ_norm a b c _ (fun n _ ↦ habc n)] simp only [← norm_inv, ← norm_mul, NNReal.coe_one] convert Filter.Tendsto.norm this exact norm_one.symm have (k : β„•) : (a + k)⁻¹ * (b + k)⁻¹ * (c + k) * ((1 : 𝕂) + k) = (c + k) / (a + k) * ((1 + k) / (b + k)) := by field simp_rw [this] apply (mul_one (1 : 𝕂)) β–Έ Filter.Tendsto.mul <;> convert tendsto_add_mul_div_add_mul_atTop_nhds _ _ (1 : 𝕂) one_ne_zero <;> simp end RCLike
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Sqrt.lean
import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Analysis.Calculus.Deriv.Pow /-! # Smoothness of `Real.sqrt` In this file we prove that `Real.sqrt` is infinitely smooth at all points `x β‰  0` and provide some dot-notation lemmas. ## Tags sqrt, differentiable -/ open Set open scoped Topology namespace Real /-- Local homeomorph between `(0, +∞)` and `(0, +∞)` with `toFun = (Β· ^ 2)` and `invFun = Real.sqrt`. -/ noncomputable def sqPartialHomeomorph : OpenPartialHomeomorph ℝ ℝ where toFun x := x ^ 2 invFun := (√·) source := Ioi 0 target := Ioi 0 map_source' _ h := mem_Ioi.2 (pow_pos (mem_Ioi.1 h) _) map_target' _ h := mem_Ioi.2 (sqrt_pos.2 h) left_inv' _ h := sqrt_sq (le_of_lt h) right_inv' _ h := sq_sqrt (le_of_lt h) open_source := isOpen_Ioi open_target := isOpen_Ioi continuousOn_toFun := (continuous_pow 2).continuousOn continuousOn_invFun := continuousOn_id.sqrt theorem deriv_sqrt_aux {x : ℝ} (hx : x β‰  0) : HasStrictDerivAt (√·) (1 / (2 * √x)) x ∧ βˆ€ n, ContDiffAt ℝ n (√·) x := by rcases hx.lt_or_gt with hx | hx Β· rw [sqrt_eq_zero_of_nonpos hx.le, mul_zero, div_zero] have : (√·) =αΆ [𝓝 x] fun _ => 0 := (gt_mem_nhds hx).mono fun x hx => sqrt_eq_zero_of_nonpos hx.le exact ⟨(hasStrictDerivAt_const x (0 : ℝ)).congr_of_eventuallyEq this.symm, fun n => contDiffAt_const.congr_of_eventuallyEq this⟩ Β· have : ↑2 * √x ^ (2 - 1) β‰  0 := by simp [(sqrt_pos.2 hx).ne', @two_ne_zero ℝ] constructor Β· simpa using sqPartialHomeomorph.hasStrictDerivAt_symm hx this (hasStrictDerivAt_pow 2 _) Β· exact fun n => sqPartialHomeomorph.contDiffAt_symm_deriv this hx (hasDerivAt_pow 2 (√x)) (contDiffAt_id.pow 2) theorem hasStrictDerivAt_sqrt {x : ℝ} (hx : x β‰  0) : HasStrictDerivAt (√·) (1 / (2 * √x)) x := (deriv_sqrt_aux hx).1 @[fun_prop] theorem contDiffAt_sqrt {x : ℝ} {n : WithTop β„•βˆž} (hx : x β‰  0) : ContDiffAt ℝ n (√·) x := (deriv_sqrt_aux hx).2 n theorem hasDerivAt_sqrt {x : ℝ} (hx : x β‰  0) : HasDerivAt (√·) (1 / (2 * √x)) x := (hasStrictDerivAt_sqrt hx).hasDerivAt end Real open Real section deriv variable {f : ℝ β†’ ℝ} {s : Set ℝ} {f' x : ℝ} theorem HasDerivWithinAt.sqrt (hf : HasDerivWithinAt f f' s x) (hx : f x β‰  0) : HasDerivWithinAt (fun y => √(f y)) (f' / (2 * √(f x))) s x := by simpa only [(Β· ∘ Β·), div_eq_inv_mul, mul_one] using (hasDerivAt_sqrt hx).comp_hasDerivWithinAt x hf theorem HasDerivAt.sqrt (hf : HasDerivAt f f' x) (hx : f x β‰  0) : HasDerivAt (fun y => √(f y)) (f' / (2 * √(f x))) x := by simpa only [(Β· ∘ Β·), div_eq_inv_mul, mul_one] using (hasDerivAt_sqrt hx).comp x hf theorem HasStrictDerivAt.sqrt (hf : HasStrictDerivAt f f' x) (hx : f x β‰  0) : HasStrictDerivAt (fun t => √(f t)) (f' / (2 * √(f x))) x := by simpa only [(Β· ∘ Β·), div_eq_inv_mul, mul_one] using (hasStrictDerivAt_sqrt hx).comp x hf theorem derivWithin_sqrt (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => √(f x)) s x = derivWithin f s x / (2 * √(f x)) := (hf.hasDerivWithinAt.sqrt hx).derivWithin hxs @[simp] theorem deriv_sqrt (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0) : deriv (fun x => √(f x)) x = deriv f x / (2 * √(f x)) := (hf.hasDerivAt.sqrt hx).deriv end deriv section fderiv variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {n : WithTop β„•βˆž} {s : Set E} {x : E} {f' : StrongDual ℝ E} theorem HasFDerivAt.sqrt (hf : HasFDerivAt f f' x) (hx : f x β‰  0) : HasFDerivAt (fun y => √(f y)) ((1 / (2 * √(f x))) β€’ f') x := (hasDerivAt_sqrt hx).comp_hasFDerivAt x hf theorem HasStrictFDerivAt.sqrt (hf : HasStrictFDerivAt f f' x) (hx : f x β‰  0) : HasStrictFDerivAt (fun y => √(f y)) ((1 / (2 * √(f x))) β€’ f') x := (hasStrictDerivAt_sqrt hx).comp_hasStrictFDerivAt x hf theorem HasFDerivWithinAt.sqrt (hf : HasFDerivWithinAt f f' s x) (hx : f x β‰  0) : HasFDerivWithinAt (fun y => √(f y)) ((1 / (2 * √(f x))) β€’ f') s x := (hasDerivAt_sqrt hx).comp_hasFDerivWithinAt x hf @[fun_prop] theorem DifferentiableWithinAt.sqrt (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0) : DifferentiableWithinAt ℝ (fun y => √(f y)) s x := (hf.hasFDerivWithinAt.sqrt hx).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.sqrt (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0) : DifferentiableAt ℝ (fun y => √(f y)) x := (hf.hasFDerivAt.sqrt hx).differentiableAt @[fun_prop] theorem DifferentiableOn.sqrt (hf : DifferentiableOn ℝ f s) (hs : βˆ€ x ∈ s, f x β‰  0) : DifferentiableOn ℝ (fun y => √(f y)) s := fun x hx => (hf x hx).sqrt (hs x hx) @[fun_prop] theorem Differentiable.sqrt (hf : Differentiable ℝ f) (hs : βˆ€ x, f x β‰  0) : Differentiable ℝ fun y => √(f y) := fun x => (hf x).sqrt (hs x) theorem fderivWithin_sqrt (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => √(f x)) s x = (1 / (2 * √(f x))) β€’ fderivWithin ℝ f s x := (hf.hasFDerivWithinAt.sqrt hx).fderivWithin hxs @[simp] theorem fderiv_sqrt (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0) : fderiv ℝ (fun x => √(f x)) x = (1 / (2 * √(f x))) β€’ fderiv ℝ f x := (hf.hasFDerivAt.sqrt hx).fderiv @[fun_prop] theorem ContDiffAt.sqrt (hf : ContDiffAt ℝ n f x) (hx : f x β‰  0) : ContDiffAt ℝ n (fun y => √(f y)) x := (contDiffAt_sqrt hx).comp x hf @[fun_prop] theorem ContDiffWithinAt.sqrt (hf : ContDiffWithinAt ℝ n f s x) (hx : f x β‰  0) : ContDiffWithinAt ℝ n (fun y => √(f y)) s x := (contDiffAt_sqrt hx).comp_contDiffWithinAt x hf @[fun_prop] theorem ContDiffOn.sqrt (hf : ContDiffOn ℝ n f s) (hs : βˆ€ x ∈ s, f x β‰  0) : ContDiffOn ℝ n (fun y => √(f y)) s := fun x hx => (hf x hx).sqrt (hs x hx) @[fun_prop] theorem ContDiff.sqrt (hf : ContDiff ℝ n f) (h : βˆ€ x, f x β‰  0) : ContDiff ℝ n fun y => √(f y) := contDiff_iff_contDiffAt.2 fun x => hf.contDiffAt.sqrt (h x) end fderiv
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/PolynomialExp.lean
import Mathlib.Analysis.SpecialFunctions.Exp /-! # Limits of `P(x) / e ^ x` for a polynomial `P` In this file we prove that $\lim_{x\to\infty}\frac{P(x)}{e^x}=0$ for any polynomial `P`. ## TODO Add more similar lemmas: limit at `-∞`, versions with $e^{cx}$ etc. ## Keywords polynomial, limit, exponential -/ open Filter Topology Real namespace Polynomial theorem tendsto_div_exp_atTop (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x / exp x) atTop (𝓝 0) := by induction p using Polynomial.induction_on' with | monomial n c => simpa [exp_neg, div_eq_mul_inv, mul_assoc] using tendsto_const_nhds.mul (tendsto_pow_mul_exp_neg_atTop_nhds_zero n) | add p q hp hq => simpa [add_div] using hp.add hq end Polynomial
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/MulExpNegMulSqIntegral.lean
import Mathlib.Analysis.SpecialFunctions.MulExpNegMulSq import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Measure.RegularityCompacts import Mathlib.Topology.ContinuousMap.StoneWeierstrass /-! # Properties of the integral of `mulExpNegMulSq` The mapping `mulExpNegMulSq` can be used to transform a function `g : E β†’ ℝ` into a bounded function `mulExpNegMulSq Ξ΅ ∘ g : E β†’ ℝ = fun x => g x * Real.exp (-Ξ΅ * g x * g x)`. This file contains results on the integral of `mulExpNegMulSq g Ξ΅` with respect to a finite measure `P`. ## Lemmas - `tendsto_integral_mulExpNegMulSq_comp`: By the dominated convergence theorem and `mulExpNegMulSq_abs_le_norm`, the integral of `mulExpNegMulSq Ξ΅ ∘ g` with respect to a finite measure `P` converges to the integral of `g`, as `Ξ΅ β†’ 0`; - `tendsto_integral_mul_one_add_inv_smul_sq_pow`: The integral of `mulExpNegMulSq Ξ΅ ∘ g` with respect to a finite measure `P` can be approximated by the integral of the sequence approximating the exponential function, `fun x => (g * (1 + (n : ℝ)⁻¹ β€’ -(Ξ΅ β€’ g * g)) ^ n) x`. This allows to transfer properties of a subalgebra of functions containing `g` to the function `mulExpNegMulSq Ξ΅ ∘ g`, see e.g. `integral_mulExpNegMulSq_comp_eq`. ## Main Result `dist_integral_mulExpNegMulSq_comp_le`: For a subalgebra of functions `A`, if for any `g ∈ A` the integral with respect to two finite measures `P, P'` coincide, then the difference of the integrals of `mulExpNegMulSq Ξ΅ ∘ g` with respect to `P, P'` is bounded by `6 * √Ρ`. This is a key ingredient in the proof of theorem `ext_of_forall_mem_subalgebra_integral_eq`, where it is shown that a subalgebra of functions that separates points separates finite measures. -/ open MeasureTheory Real NNReal ENNReal BoundedContinuousFunction Filter open scoped Topology variable {E : Type*} [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] {P : Measure E} [IsFiniteMeasure P] {Ξ΅ : ℝ} theorem integrable_mulExpNegMulSq_comp (f : C(E, ℝ)) (hΞ΅ : 0 < Ξ΅) : Integrable (fun x => mulExpNegMulSq Ξ΅ (f x)) P := by apply integrable P ⟨⟨fun x => mulExpNegMulSq Ξ΅ (f x), by fun_prop⟩, ⟨2 * (√Ρ)⁻¹, _⟩⟩ exact fun x y => dist_mulExpNegMulSq_le_two_mul_sqrt hΞ΅ (f x) (f y) theorem integrable_mulExpNegMulSq_comp_restrict_of_isCompact {K : Set E} (hK : IsCompact K) (hKmeas : MeasurableSet K) (g : C(E, ℝ)) : Integrable (fun x => mulExpNegMulSq Ξ΅ (g x)) (P.restrict K) := g.continuous.mulExpNegMulSq.continuousOn.integrableOn_compact' hK hKmeas /-- The integral of `mulExpNegMulSq Ξ΅ ∘ g` with respect to a finite measure `P` converges to the integral of `g`, as `Ξ΅ β†’ 0` from above. -/ theorem tendsto_integral_mulExpNegMulSq_comp (g : E →ᡇ ℝ) : Tendsto (fun Ξ΅ => ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P) (𝓝[>] 0) (𝓝 (∫ x, g x βˆ‚P)) := by apply tendsto_of_seq_tendsto intro u hu obtain ⟨N, hupos⟩ := eventually_atTop.mp (tendsto_nhdsWithin_iff.mp hu).2 apply tendsto_integral_filter_of_norm_le_const ?h_meas ?h_bound ?h_lim Β· exact Eventually.of_forall (fun n => g.continuous.mulExpNegMulSq.aestronglyMeasurable) Β· use norm g rw [eventually_atTop] use N intro n hn exact Eventually.of_forall (fun _ => abs_mulExpNegMulSq_comp_le_norm g (le_of_lt (Set.mem_Ioi.mp (hupos n hn)))) Β· exact Eventually.of_forall (fun _ => (tendsto_nhdsWithin_of_tendsto_nhds tendsto_mulExpNegMulSq).comp hu) /-- The integral of `mulExpNegMulSq Ξ΅ ∘ g` with respect to a finite measure `P` can be approximated by the integral of the sequence approximating the exponential function. -/ theorem tendsto_integral_mul_one_add_inv_smul_sq_pow (g : E →ᡇ ℝ) (hΞ΅ : 0 < Ξ΅) : Tendsto (fun (n : β„•) => ∫ x, (g * (1 + (n : ℝ)⁻¹ β€’ -(Ξ΅ β€’ g * g)) ^ n) x βˆ‚ P) atTop (𝓝 (∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P)) := by apply tendsto_integral_filter_of_norm_le_const ?h_meas ?h_bound ?h_lim Β· apply Eventually.of_forall exact fun n => StronglyMeasurable.aestronglyMeasurable (Continuous.stronglyMeasurable (Continuous.mul g.continuous ((1 + ((n : ℝ)⁻¹ β€’ -(Ξ΅ β€’ g * g))) ^ n).continuous)) Β· obtain ⟨N, hgN⟩ := exists_nat_gt (Ξ΅ * (norm g * norm g)) use norm g rw [eventually_atTop] use N intro n hn have hnpos : 0 < (n : ℝ) := by apply lt_of_lt_of_le (lt_of_le_of_lt _ hgN) (Nat.cast_le.mpr hn) exact (mul_nonneg (le_of_lt hΞ΅) (mul_self_nonneg (norm g))) apply Eventually.of_forall intro x simp only [smul_neg, BoundedContinuousFunction.coe_mul, Pi.mul_apply, pow_apply, BoundedContinuousFunction.coe_add, BoundedContinuousFunction.coe_one, coe_neg, BoundedContinuousFunction.coe_smul, smul_eq_mul, Pi.add_apply, Pi.one_apply, Pi.neg_apply, norm_mul, norm_eq_abs, norm_pow] refine (mul_le_mul_of_nonneg_right (norm_coe_le_norm g x) (pow_nonneg (abs_nonneg _) n)).trans <| mul_le_of_le_one_right (norm_nonneg _) ?_ apply pow_le_oneβ‚€ (abs_nonneg _) rw [mul_assoc, inv_mul_eq_div, abs_le] refine ⟨?_, (add_le_iff_nonpos_right 1).mpr (Left.neg_nonpos_iff.mpr (div_nonneg (mul_nonneg (le_of_lt hΞ΅) (mul_self_nonneg (g x))) (le_of_lt hnpos)))⟩ apply le_trans (by linarith) (sub_nonneg_of_le ((div_le_one hnpos).mpr _)) apply le_trans (le_trans _ (le_of_lt hgN)) (Nat.cast_le.mpr hn) apply mul_le_mul (Preorder.le_refl Ξ΅) _ (mul_self_nonneg (g x)) (le_of_lt hΞ΅) rw [← abs_le_iff_mul_self_le, abs_norm] exact norm_coe_le_norm g x Β· apply Eventually.of_forall intro x apply Tendsto.const_mul (g x) simpa [mul_assoc, inv_mul_eq_div, ← neg_div] using tendsto_one_add_div_pow_exp (-(Ξ΅ * (g x * g x))) @[deprecated (since := "2025-05-22")] alias tendsto_integral_mul_one_plus_inv_smul_sq_pow := tendsto_integral_mul_one_add_inv_smul_sq_pow theorem integral_mulExpNegMulSq_comp_eq {P' : Measure E} [IsFiniteMeasure P'] {A : Subalgebra ℝ (E →ᡇ ℝ)} (hΞ΅ : 0 < Ξ΅) (heq : βˆ€ g ∈ A, ∫ x, (g : E β†’ ℝ) x βˆ‚P = ∫ x, (g : E β†’ ℝ) x βˆ‚P') {g : E →ᡇ ℝ} (hgA : g ∈ A) : ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P = ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P' := by have one_add_inv_mul_mem (n : β„•) : g * (1 + (n : ℝ)⁻¹ β€’ -(Ξ΅ β€’ g * g)) ^ n ∈ A := by apply Subalgebra.mul_mem A hgA (Subalgebra.pow_mem A _ n) apply Subalgebra.add_mem A (Subalgebra.one_mem A) (Subalgebra.smul_mem A _ n⁻¹) exact Subalgebra.neg_mem A (Subalgebra.mul_mem A (Subalgebra.smul_mem A hgA Ξ΅) hgA) have limP : Tendsto (fun n : β„• => ∫ x, (g * (1 + (n : ℝ)⁻¹ β€’ -(Ξ΅ β€’ g * g)) ^ n) x βˆ‚P) atTop (𝓝 (∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P')) := by rw [funext fun n => heq _ (one_add_inv_mul_mem n)] exact tendsto_integral_mul_one_add_inv_smul_sq_pow g hΞ΅ exact tendsto_nhds_unique (tendsto_integral_mul_one_add_inv_smul_sq_pow g hΞ΅) limP theorem abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt (f : C(E, ℝ)) {K : Set E} (hK : MeasurableSet K) (hΞ΅ : 0 < Ξ΅) (hKP : P Kᢜ < Ξ΅.toNNReal) : |∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P| < √Ρ := by apply lt_of_le_of_lt (norm_integral_sub_setIntegral_le (Eventually.of_forall (fun _ => abs_mulExpNegMulSq_le hΞ΅)) hK (integrable_mulExpNegMulSq_comp f hΞ΅)) rw [mul_inv_lt_iffβ‚€ (sqrt_pos_of_pos hΞ΅), mul_self_sqrt (le_of_lt hΞ΅)] exact toReal_lt_of_lt_ofReal hKP theorem abs_setIntegral_mulExpNegMulSq_comp_sub_le_mul_measure {K : Set E} (hK : IsCompact K) (hKmeas : MeasurableSet K) (f g : C(E, ℝ)) {Ξ΄ : ℝ} (hΞ΅ : 0 < Ξ΅) (hfg : βˆ€ x ∈ K, |g x - f x| < Ξ΄) : |∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P - ∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P| ≀ Ξ΄ * (P K).toReal := by rw [← (integral_sub (integrable_mulExpNegMulSq_comp_restrict_of_isCompact hK hKmeas g) (integrable_mulExpNegMulSq_comp_restrict_of_isCompact hK hKmeas f)), ← norm_eq_abs] exact norm_setIntegral_le_of_norm_le_const hK.measure_lt_top (fun x hxK => le_trans (dist_mulExpNegMulSq_le_dist hΞ΅) (hfg x hxK).le) variable {E : Type*} [MeasurableSpace E] [PseudoEMetricSpace E] [BorelSpace E] [CompleteSpace E] [SecondCountableTopology E] {P P' : Measure E} [IsFiniteMeasure P] [IsFiniteMeasure P'] /-- If for any `g ∈ A` the integrals with respect to two finite measures `P, P'` coincide, then the difference of the integrals of `mulExpNegMulSq Ξ΅ ∘ g` with respect to `P, P'` is bounded by `6 * √Ρ`. -/ theorem dist_integral_mulExpNegMulSq_comp_le (f : E →ᡇ ℝ) {A : Subalgebra ℝ (E →ᡇ ℝ)} (hA : (A.map (toContinuousMapₐ ℝ)).SeparatesPoints) (heq : βˆ€ g ∈ A, ∫ x, (g : E β†’ ℝ) x βˆ‚P = ∫ x, (g : E β†’ ℝ) x βˆ‚P') (hΞ΅ : 0 < Ξ΅) : |∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P'| ≀ 6 * √Ρ := by -- if both measures are zero, the result is trivial by_cases hPP' : P = 0 ∧ P' = 0 Β· simp only [hPP', integral_zero_measure, sub_self, abs_zero, Nat.ofNat_pos, mul_nonneg_iff_of_pos_left, (le_of_lt (sqrt_pos_of_pos hΞ΅))] let const : ℝ := (max (P.real Set.univ) (P'.real Set.univ)) have pos_of_measure : 0 < const := by rw [not_and_or] at hPP' rcases hPP' with hP0 | hP'0 Β· exact lt_max_of_lt_left (toReal_pos ((Measure.measure_univ_ne_zero).mpr hP0) (by finiteness)) Β· exact lt_max_of_lt_right (toReal_pos ((Measure.measure_univ_ne_zero).mpr hP'0) (by finiteness)) -- obtain K, a compact and closed set, which covers E up to a small area of measure at most Ξ΅ -- w.r.t. both P and P' obtain ⟨KP, _, hKPco, hKPcl, hKP⟩ := MeasurableSet.exists_isCompact_isClosed_diff_lt (MeasurableSet.univ) (measure_ne_top P Set.univ) (ofReal_pos.mpr hΞ΅).ne' obtain ⟨KP', _, hKP'co, hKP'cl, hKP'⟩ := MeasurableSet.exists_isCompact_isClosed_diff_lt (MeasurableSet.univ) (measure_ne_top P' Set.univ) (ofReal_pos.mpr hΞ΅).ne' let K := KP βˆͺ KP' have hKco := IsCompact.union hKPco hKP'co have hKcl := IsClosed.union hKPcl hKP'cl simp only [← Set.compl_eq_univ_diff] at hKP hKP' have hKPbound : P (KP βˆͺ KP')ᢜ < Ξ΅.toNNReal := lt_of_le_of_lt (measure_mono (Set.compl_subset_compl_of_subset (Set.subset_union_left))) hKP have hKP'bound : P' (KP βˆͺ KP')ᢜ < Ξ΅.toNNReal := lt_of_le_of_lt (measure_mono (Set.compl_subset_compl_of_subset (Set.subset_union_right))) hKP' -- Stone-Weierstrass approximation of f on K obtain ⟨g', hg'A, hg'approx⟩ := ContinuousMap.exists_mem_subalgebra_near_continuous_of_isCompact_of_separatesPoints hA f hKco (Left.mul_pos (sqrt_pos_of_pos hΞ΅) (inv_pos_of_pos pos_of_measure)) simp only [Subalgebra.mem_map] at hg'A let g := hg'A.choose have hgA : g ∈ A := hg'A.choose_spec.1 have hgapprox : βˆ€ x ∈ K, β€–g x - f xβ€– < √Ρ * const⁻¹ := by rw [← coe_toContinuousMapₐ ℝ g, hg'A.choose_spec.2] exact hg'approx -- collect the results needed in the decomposition at the end of the proof have line1 : |∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P| < √Ρ := abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt f (IsClosed.measurableSet hKcl) hΞ΅ hKPbound have line3 : |∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P - ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P| < √Ρ := by rw [abs_sub_comm] exact (abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt g (IsClosed.measurableSet hKcl) hΞ΅ hKPbound) have line5 : |∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P' - ∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P'| < √Ρ := (abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt g (IsClosed.measurableSet hKcl) hΞ΅ hKP'bound) have line7 : |∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P' - ∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P'| < √Ρ := by rw [abs_sub_comm] exact (abs_integral_sub_setIntegral_mulExpNegMulSq_comp_lt f (IsClosed.measurableSet hKcl) hΞ΅ hKP'bound) have line2 : |∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P| ≀ √Ρ := by rw [abs_sub_comm] apply le_trans (abs_setIntegral_mulExpNegMulSq_comp_sub_le_mul_measure hKco (IsClosed.measurableSet hKcl) f g hΞ΅ hgapprox) rw [mul_assoc] apply mul_le_of_le_one_right (le_of_lt (sqrt_pos_of_pos hΞ΅)) apply inv_mul_le_one_of_leβ‚€ (le_max_of_le_left _) (le_of_lt pos_of_measure) exact (toReal_le_toReal (by finiteness) (by finiteness)).mpr (measure_mono (Set.subset_univ _)) have line6 : |∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P' - ∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P'| ≀ √Ρ := by apply le_trans (abs_setIntegral_mulExpNegMulSq_comp_sub_le_mul_measure hKco (IsClosed.measurableSet hKcl) f g hΞ΅ hgapprox) rw [mul_assoc] apply mul_le_of_le_one_right (le_of_lt (sqrt_pos_of_pos hΞ΅)) apply inv_mul_le_one_of_leβ‚€ (le_max_of_le_right _) (le_of_lt pos_of_measure) exact (toReal_le_toReal (by finiteness) (by finiteness)).mpr (measure_mono (Set.subset_univ _)) have line4 : |∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P - ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P'| = 0 := by rw [abs_eq_zero, sub_eq_zero] exact integral_mulExpNegMulSq_comp_eq hΞ΅ heq hgA calc |∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P'| ≀ |∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P| + |∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P - ∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P| + |∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P - ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P| + |∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P - ∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P'| + |∫ x, mulExpNegMulSq Ξ΅ (g x) βˆ‚P' - ∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P'| + |∫ x in K, mulExpNegMulSq Ξ΅ (g x) βˆ‚P' - ∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P'| + |∫ x in K, mulExpNegMulSq Ξ΅ (f x) βˆ‚P' - ∫ x, mulExpNegMulSq Ξ΅ (f x) βˆ‚P'| := @dist_triangle8 ℝ _ _ _ _ _ _ _ _ _ _ ≀ 6 * √Ρ := by linarith
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Exponential.lean
import Mathlib.Analysis.Normed.Algebra.Exponential import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Complex.Exponential import Mathlib.Topology.MetricSpace.CauSeqFilter /-! # Calculus results on exponential in a Banach algebra In this file, we prove basic properties about the derivative of the exponential map `exp 𝕂` in a Banach algebra `𝔸` over a field `𝕂`. We keep them separate from the main file `Analysis.Normed.Algebra.Exponential` in order to minimize dependencies. ## Main results We prove most results for an arbitrary field `𝕂`, and then specialize to `𝕂 = ℝ` or `𝕂 = β„‚`. ### General case - `hasStrictFDerivAt_exp_zero_of_radius_pos` : `NormedSpace.exp 𝕂` has strict FrΓ©chet derivative `1 : 𝔸 β†’L[𝕂] 𝔸` at zero, as long as it converges on a neighborhood of zero (see also `hasStrictDerivAt_exp_zero_of_radius_pos` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp_of_lt_radius` : if `𝕂` has characteristic zero and `𝔸` is commutative, then given a point `x` in the disk of convergence, `NormedSpace.exp 𝕂` has strict FrΓ©chet derivative `NormedSpace.exp 𝕂 x β€’ 1 : 𝔸 β†’L[𝕂] 𝔸` at x (see also `hasStrictDerivAt_exp_of_lt_radius` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp_smul_const_of_mem_ball`: even when `𝔸` is non-commutative, if we have an intermediate algebra `π•Š` which is commutative, the function `(u : π•Š) ↦ NormedSpace.exp 𝕂 (u β€’ x)`, still has strict FrΓ©chet derivative `NormedSpace.exp 𝕂 (t β€’ x) β€’ (1 : π•Š β†’L[𝕂] π•Š).smulRight x` at `t` if `t β€’ x` is in the radius of convergence. ### `𝕂 = ℝ` or `𝕂 = β„‚` - `hasStrictFDerivAt_exp_zero` : `NormedSpace.exp 𝕂` has strict FrΓ©chet derivative `1 : 𝔸 β†’L[𝕂] 𝔸` at zero (see also `hasStrictDerivAt_exp_zero` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp` : if `𝔸` is commutative, then given any point `x`, `NormedSpace.exp 𝕂` has strict FrΓ©chet derivative `NormedSpace.exp 𝕂 x β€’ 1 : 𝔸 β†’L[𝕂] 𝔸` at x (see also `hasStrictDerivAt_exp` for the case `𝔸 = 𝕂`) - `hasStrictFDerivAt_exp_smul_const`: even when `𝔸` is non-commutative, if we have an intermediate algebra `π•Š` which is commutative, the function `(u : π•Š) ↦ NormedSpace.exp 𝕂 (u β€’ x)` still has strict FrΓ©chet derivative `NormedSpace.exp 𝕂 (t β€’ x) β€’ (1 : 𝔸 β†’L[𝕂] 𝔸).smulRight x` at `t`. ### Compatibility with `Real.exp` and `Complex.exp` - `Complex.exp_eq_exp_β„‚` : `Complex.exp = NormedSpace.exp β„‚ β„‚` - `Real.exp_eq_exp_ℝ` : `Real.exp = NormedSpace.exp ℝ ℝ` -/ open Filter RCLike ContinuousMultilinearMap NormedField NormedSpace Asymptotics open scoped Nat Topology ENNReal section AnyFieldAnyAlgebra variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential in a Banach algebra `𝔸` over a normed field `𝕂` has strict FrΓ©chet derivative `1 : 𝔸 β†’L[𝕂] 𝔸` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasStrictFDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) : HasStrictFDerivAt (exp 𝕂) (1 : 𝔸 β†’L[𝕂] 𝔸) 0 := by convert (hasFPowerSeriesAt_exp_zero_of_radius_pos h).hasStrictFDerivAt ext x change x = expSeries 𝕂 𝔸 1 fun _ => x simp [expSeries_apply_eq, Nat.factorial] /-- The exponential in a Banach algebra `𝔸` over a normed field `𝕂` has FrΓ©chet derivative `1 : 𝔸 β†’L[𝕂] 𝔸` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasFDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) : HasFDerivAt (exp 𝕂) (1 : 𝔸 β†’L[𝕂] 𝔸) 0 := (hasStrictFDerivAt_exp_zero_of_radius_pos h).hasFDerivAt end AnyFieldAnyAlgebra section AnyFieldCommAlgebra variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential map in a commutative Banach algebra `𝔸` over a normed field `𝕂` of characteristic zero has FrΓ©chet derivative `NormedSpace.exp 𝕂 x β€’ 1 : 𝔸 β†’L[𝕂] 𝔸` at any point `x`in the disk of convergence. -/ theorem hasFDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasFDerivAt (exp 𝕂) (exp 𝕂 x β€’ (1 : 𝔸 β†’L[𝕂] 𝔸)) x := by have hpos : 0 < (expSeries 𝕂 𝔸).radius := (zero_le _).trans_lt hx rw [hasFDerivAt_iff_isLittleO_nhds_zero] suffices (fun h => exp 𝕂 x * (exp 𝕂 (0 + h) - exp 𝕂 0 - ContinuousLinearMap.id 𝕂 𝔸 h)) =αΆ [𝓝 0] fun h => exp 𝕂 (x + h) - exp 𝕂 x - exp 𝕂 x β€’ ContinuousLinearMap.id 𝕂 𝔸 h by refine (IsLittleO.const_mul_left ?_ _).congr' this (EventuallyEq.refl _ _) rw [← hasFDerivAt_iff_isLittleO_nhds_zero] exact hasFDerivAt_exp_zero_of_radius_pos hpos have : βˆ€αΆ  h in 𝓝 (0 : 𝔸), h ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := EMetric.ball_mem_nhds _ hpos filter_upwards [this] with _ hh rw [exp_add_of_mem_ball hx hh, exp_zero, zero_add, ContinuousLinearMap.id_apply, smul_eq_mul] ring /-- The exponential map in a commutative Banach algebra `𝔸` over a normed field `𝕂` of characteristic zero has strict FrΓ©chet derivative `NormedSpace.exp 𝕂 x β€’ 1 : 𝔸 β†’L[𝕂] 𝔸` at any point `x` in the disk of convergence. -/ theorem hasStrictFDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸} (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasStrictFDerivAt (exp 𝕂) (exp 𝕂 x β€’ (1 : 𝔸 β†’L[𝕂] 𝔸)) x := let ⟨_, hp⟩ := analyticAt_exp_of_mem_ball x hx hp.hasFDerivAt.unique (hasFDerivAt_exp_of_mem_ball hx) β–Έ hp.hasStrictFDerivAt end AnyFieldCommAlgebra section deriv variable {𝕂 : Type*} [NontriviallyNormedField 𝕂] [CompleteSpace 𝕂] /-- The exponential map in a complete normed field `𝕂` of characteristic zero has strict derivative `NormedSpace.exp 𝕂 x` at any point `x` in the disk of convergence. -/ theorem hasStrictDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝕂} (hx : x ∈ EMetric.ball (0 : 𝕂) (expSeries 𝕂 𝕂).radius) : HasStrictDerivAt (exp 𝕂) (exp 𝕂 x) x := by simpa using (hasStrictFDerivAt_exp_of_mem_ball hx).hasStrictDerivAt /-- The exponential map in a complete normed field `𝕂` of characteristic zero has derivative `NormedSpace.exp 𝕂 x` at any point `x` in the disk of convergence. -/ theorem hasDerivAt_exp_of_mem_ball [CharZero 𝕂] {x : 𝕂} (hx : x ∈ EMetric.ball (0 : 𝕂) (expSeries 𝕂 𝕂).radius) : HasDerivAt (exp 𝕂) (exp 𝕂 x) x := (hasStrictDerivAt_exp_of_mem_ball hx).hasDerivAt /-- The exponential map in a complete normed field `𝕂` of characteristic zero has strict derivative `1` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasStrictDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝕂).radius) : HasStrictDerivAt (exp 𝕂) (1 : 𝕂) 0 := (hasStrictFDerivAt_exp_zero_of_radius_pos h).hasStrictDerivAt /-- The exponential map in a complete normed field `𝕂` of characteristic zero has derivative `1` at zero, as long as it converges on a neighborhood of zero. -/ theorem hasDerivAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝕂).radius) : HasDerivAt (exp 𝕂) (1 : 𝕂) 0 := (hasStrictDerivAt_exp_zero_of_radius_pos h).hasDerivAt end deriv section RCLikeAnyAlgebra variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential in a Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = β„‚` has strict FrΓ©chet derivative `1 : 𝔸 β†’L[𝕂] 𝔸` at zero. -/ theorem hasStrictFDerivAt_exp_zero : HasStrictFDerivAt (exp 𝕂) (1 : 𝔸 β†’L[𝕂] 𝔸) 0 := hasStrictFDerivAt_exp_zero_of_radius_pos (expSeries_radius_pos 𝕂 𝔸) /-- The exponential in a Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = β„‚` has FrΓ©chet derivative `1 : 𝔸 β†’L[𝕂] 𝔸` at zero. -/ theorem hasFDerivAt_exp_zero : HasFDerivAt (exp 𝕂) (1 : 𝔸 β†’L[𝕂] 𝔸) 0 := hasStrictFDerivAt_exp_zero.hasFDerivAt end RCLikeAnyAlgebra section RCLikeCommAlgebra variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- The exponential map in a commutative Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = β„‚` has strict FrΓ©chet derivative `NormedSpace.exp 𝕂 x β€’ 1 : 𝔸 β†’L[𝕂] 𝔸` at any point `x`. -/ theorem hasStrictFDerivAt_exp {x : 𝔸} : HasStrictFDerivAt (exp 𝕂) (exp 𝕂 x β€’ (1 : 𝔸 β†’L[𝕂] 𝔸)) x := hasStrictFDerivAt_exp_of_mem_ball ((expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _) /-- The exponential map in a commutative Banach algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = β„‚` has FrΓ©chet derivative `NormedSpace.exp 𝕂 x β€’ 1 : 𝔸 β†’L[𝕂] 𝔸` at any point `x`. -/ theorem hasFDerivAt_exp {x : 𝔸} : HasFDerivAt (exp 𝕂) (exp 𝕂 x β€’ (1 : 𝔸 β†’L[𝕂] 𝔸)) x := hasStrictFDerivAt_exp.hasFDerivAt end RCLikeCommAlgebra section DerivRCLike variable {𝕂 : Type*} [RCLike 𝕂] /-- The exponential map in `𝕂 = ℝ` or `𝕂 = β„‚` has strict derivative `NormedSpace.exp 𝕂 x` at any point `x`. -/ theorem hasStrictDerivAt_exp {x : 𝕂} : HasStrictDerivAt (exp 𝕂) (exp 𝕂 x) x := hasStrictDerivAt_exp_of_mem_ball ((expSeries_radius_eq_top 𝕂 𝕂).symm β–Έ edist_lt_top _ _) /-- The exponential map in `𝕂 = ℝ` or `𝕂 = β„‚` has derivative `NormedSpace.exp 𝕂 x` at any point `x`. -/ theorem hasDerivAt_exp {x : 𝕂} : HasDerivAt (exp 𝕂) (exp 𝕂 x) x := hasStrictDerivAt_exp.hasDerivAt /-- The exponential map in `𝕂 = ℝ` or `𝕂 = β„‚` has strict derivative `1` at zero. -/ theorem hasStrictDerivAt_exp_zero : HasStrictDerivAt (exp 𝕂) (1 : 𝕂) 0 := hasStrictDerivAt_exp_zero_of_radius_pos (expSeries_radius_pos 𝕂 𝕂) /-- The exponential map in `𝕂 = ℝ` or `𝕂 = β„‚` has derivative `1` at zero. -/ theorem hasDerivAt_exp_zero : HasDerivAt (exp 𝕂) (1 : 𝕂) 0 := hasStrictDerivAt_exp_zero.hasDerivAt end DerivRCLike theorem Complex.exp_eq_exp_β„‚ : Complex.exp = NormedSpace.exp β„‚ := by refine funext fun x => ?_ rw [Complex.exp, exp_eq_tsum_div] exact tendsto_nhds_unique x.exp'.tendsto_limit (expSeries_div_summable ℝ x).hasSum.tendsto_sum_nat theorem Real.exp_eq_exp_ℝ : Real.exp = NormedSpace.exp ℝ := by ext x; exact mod_cast congr_fun Complex.exp_eq_exp_β„‚ x /-! ### Derivative of $\exp (ux)$ by $u$ Note that since for `x : 𝔸` we have `NormedRing 𝔸` not `NormedCommRing 𝔸`, we cannot deduce these results from `hasFDerivAt_exp_of_mem_ball` applied to the algebra `𝔸`. One possible solution for that would be to apply `hasFDerivAt_exp_of_mem_ball` to the commutative algebra `Algebra.elementalAlgebra π•Š x`. Unfortunately we don't have all the required API, so we leave that to a future refactor (see https://github.com/leanprover-community/mathlib3/pull/19062 for discussion). We could also go the other way around and deduce `hasFDerivAt_exp_of_mem_ball` from `hasFDerivAt_exp_smul_const_of_mem_ball` applied to `π•Š := 𝔸`, `x := (1 : 𝔸)`, and `t := x`. However, doing so would make the aforementioned `elementalAlgebra` refactor harder, so for now we just prove these two lemmas independently. A last strategy would be to deduce everything from the more general non-commutative case, $$\frac{d}{dt}e^{x(t)} = \int_0^1 e^{sx(t)} \left(\frac{d}{dt}e^{x(t)}\right) e^{(1-s)x(t)} ds$$ but this is harder to prove, and typically is shown by going via these results first. TODO: prove this result too! -/ section exp_smul variable {𝕂 π•Š 𝔸 : Type*} variable (𝕂) open scoped Topology open Asymptotics Filter section MemBall variable [NontriviallyNormedField 𝕂] [CharZero 𝕂] variable [NormedCommRing π•Š] [NormedRing 𝔸] variable [NormedSpace 𝕂 π•Š] [NormedAlgebra 𝕂 𝔸] [Algebra π•Š 𝔸] [ContinuousSMul π•Š 𝔸] variable [IsScalarTower 𝕂 π•Š 𝔸] variable [CompleteSpace 𝔸] theorem hasFDerivAt_exp_smul_const_of_mem_ball (x : 𝔸) (t : π•Š) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) β€’ (1 : π•Š β†’L[𝕂] π•Š).smulRight x) t := by -- TODO: prove this via `hasFDerivAt_exp_of_mem_ball` using the commutative ring -- `Algebra.elementalAlgebra π•Š x`. See https://github.com/leanprover-community/mathlib3/pull/19062 for discussion. have hpos : 0 < (expSeries 𝕂 𝔸).radius := (zero_le _).trans_lt htx rw [hasFDerivAt_iff_isLittleO_nhds_zero] suffices (fun (h : π•Š) => exp 𝕂 (t β€’ x) * (exp 𝕂 ((0 + h) β€’ x) - exp 𝕂 ((0 : π•Š) β€’ x) - ((1 : π•Š β†’L[𝕂] π•Š).smulRight x) h)) =αΆ [𝓝 0] fun h => exp 𝕂 ((t + h) β€’ x) - exp 𝕂 (t β€’ x) - (exp 𝕂 (t β€’ x) β€’ (1 : π•Š β†’L[𝕂] π•Š).smulRight x) h by apply (IsLittleO.const_mul_left _ _).congr' this (EventuallyEq.refl _ _) rw [← hasFDerivAt_iff_isLittleO_nhds_zero (f := fun u => exp 𝕂 (u β€’ x)) (f' := (1 : π•Š β†’L[𝕂] π•Š).smulRight x) (x := 0)] have : HasFDerivAt (exp 𝕂) (1 : 𝔸 β†’L[𝕂] 𝔸) ((1 : π•Š β†’L[𝕂] π•Š).smulRight x 0) := by rw [ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, zero_smul] exact hasFDerivAt_exp_zero_of_radius_pos hpos exact this.comp 0 ((1 : π•Š β†’L[𝕂] π•Š).smulRight x).hasFDerivAt have : Tendsto (fun h : π•Š => h β€’ x) (𝓝 0) (𝓝 0) := by rw [← zero_smul π•Š x] exact tendsto_id.smul_const x have : βˆ€αΆ  h in 𝓝 (0 : π•Š), h β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := this.eventually (EMetric.ball_mem_nhds _ hpos) filter_upwards [this] with h hh have : Commute (t β€’ x) (h β€’ x) := ((Commute.refl x).smul_left t).smul_right h rw [add_smul t h, exp_add_of_commute_of_mem_ball this htx hh, zero_add, zero_smul, exp_zero, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, smul_eq_mul, mul_sub_left_distrib, mul_sub_left_distrib, mul_one] theorem hasFDerivAt_exp_smul_const_of_mem_ball' (x : 𝔸) (t : π•Š) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (((1 : π•Š β†’L[𝕂] π•Š).smulRight x).smulRight (exp 𝕂 (t β€’ x))) t := by convert hasFDerivAt_exp_smul_const_of_mem_ball 𝕂 _ _ htx using 1 ext t' change Commute (t' β€’ x) (exp 𝕂 (t β€’ x)) exact (((Commute.refl x).smul_left t').smul_right t).exp_right 𝕂 theorem hasStrictFDerivAt_exp_smul_const_of_mem_ball (x : 𝔸) (t : π•Š) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasStrictFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) β€’ (1 : π•Š β†’L[𝕂] π•Š).smulRight x) t := let ⟨_, hp⟩ := analyticAt_exp_of_mem_ball (t β€’ x) htx have deriv₁ : HasStrictFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) _ t := hp.hasStrictFDerivAt.comp t ((ContinuousLinearMap.id 𝕂 π•Š).smulRight x).hasStrictFDerivAt have derivβ‚‚ : HasFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) _ t := hasFDerivAt_exp_smul_const_of_mem_ball 𝕂 x t htx deriv₁.hasFDerivAt.unique derivβ‚‚ β–Έ deriv₁ theorem hasStrictFDerivAt_exp_smul_const_of_mem_ball' (x : 𝔸) (t : π•Š) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasStrictFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (((1 : π•Š β†’L[𝕂] π•Š).smulRight x).smulRight (exp 𝕂 (t β€’ x))) t := by let ⟨_, _⟩ := analyticAt_exp_of_mem_ball (t β€’ x) htx convert hasStrictFDerivAt_exp_smul_const_of_mem_ball 𝕂 _ _ htx using 1 ext t' change Commute (t' β€’ x) (exp 𝕂 (t β€’ x)) exact (((Commute.refl x).smul_left t').smul_right t).exp_right 𝕂 variable {𝕂} theorem hasStrictDerivAt_exp_smul_const_of_mem_ball (x : 𝔸) (t : 𝕂) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasStrictDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) * x) t := by simpa using (hasStrictFDerivAt_exp_smul_const_of_mem_ball 𝕂 x t htx).hasStrictDerivAt theorem hasStrictDerivAt_exp_smul_const_of_mem_ball' (x : 𝔸) (t : 𝕂) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasStrictDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (x * exp 𝕂 (t β€’ x)) t := by simpa using (hasStrictFDerivAt_exp_smul_const_of_mem_ball' 𝕂 x t htx).hasStrictDerivAt theorem hasDerivAt_exp_smul_const_of_mem_ball (x : 𝔸) (t : 𝕂) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) * x) t := (hasStrictDerivAt_exp_smul_const_of_mem_ball x t htx).hasDerivAt theorem hasDerivAt_exp_smul_const_of_mem_ball' (x : 𝔸) (t : 𝕂) (htx : t β€’ x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : HasDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (x * exp 𝕂 (t β€’ x)) t := (hasStrictDerivAt_exp_smul_const_of_mem_ball' x t htx).hasDerivAt end MemBall section RCLike variable [RCLike 𝕂] variable [NormedCommRing π•Š] [NormedRing 𝔸] variable [NormedAlgebra 𝕂 π•Š] [NormedAlgebra 𝕂 𝔸] [Algebra π•Š 𝔸] [ContinuousSMul π•Š 𝔸] variable [IsScalarTower 𝕂 π•Š 𝔸] variable [CompleteSpace 𝔸] theorem hasFDerivAt_exp_smul_const (x : 𝔸) (t : π•Š) : HasFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) β€’ (1 : π•Š β†’L[𝕂] π•Š).smulRight x) t := hasFDerivAt_exp_smul_const_of_mem_ball 𝕂 _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ theorem hasFDerivAt_exp_smul_const' (x : 𝔸) (t : π•Š) : HasFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (((1 : π•Š β†’L[𝕂] π•Š).smulRight x).smulRight (exp 𝕂 (t β€’ x))) t := hasFDerivAt_exp_smul_const_of_mem_ball' 𝕂 _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ theorem hasStrictFDerivAt_exp_smul_const (x : 𝔸) (t : π•Š) : HasStrictFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) β€’ (1 : π•Š β†’L[𝕂] π•Š).smulRight x) t := hasStrictFDerivAt_exp_smul_const_of_mem_ball 𝕂 _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ theorem hasStrictFDerivAt_exp_smul_const' (x : 𝔸) (t : π•Š) : HasStrictFDerivAt (fun u : π•Š => exp 𝕂 (u β€’ x)) (((1 : π•Š β†’L[𝕂] π•Š).smulRight x).smulRight (exp 𝕂 (t β€’ x))) t := hasStrictFDerivAt_exp_smul_const_of_mem_ball' 𝕂 _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ variable {𝕂} theorem hasStrictDerivAt_exp_smul_const (x : 𝔸) (t : 𝕂) : HasStrictDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) * x) t := hasStrictDerivAt_exp_smul_const_of_mem_ball _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ theorem hasStrictDerivAt_exp_smul_const' (x : 𝔸) (t : 𝕂) : HasStrictDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (x * exp 𝕂 (t β€’ x)) t := hasStrictDerivAt_exp_smul_const_of_mem_ball' _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ theorem hasDerivAt_exp_smul_const (x : 𝔸) (t : 𝕂) : HasDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (exp 𝕂 (t β€’ x) * x) t := hasDerivAt_exp_smul_const_of_mem_ball _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ theorem hasDerivAt_exp_smul_const' (x : 𝔸) (t : 𝕂) : HasDerivAt (fun u : 𝕂 => exp 𝕂 (u β€’ x)) (x * exp 𝕂 (t β€’ x)) t := hasDerivAt_exp_smul_const_of_mem_ball' _ _ <| (expSeries_radius_eq_top 𝕂 𝔸).symm β–Έ edist_lt_top _ _ end RCLike end exp_smul section tsum_tprod variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸] /-- If `f` has sum `a`, then `NormedSpace.exp ∘ f` has product `NormedSpace.exp a`. -/ lemma HasSum.exp {ΞΉ : Type*} {f : ΞΉ β†’ 𝔸} {a : 𝔸} (h : HasSum f a) : HasProd (exp 𝕂 ∘ f) (exp 𝕂 a) := Tendsto.congr (fun s ↦ exp_sum s f) <| Tendsto.exp h end tsum_tprod
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/NonIntegrable.lean
import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus /-! # Non-integrable functions In this file we prove that the derivative of a function that tends to infinity is not interval integrable, see `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_filter` and `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured`. Then we apply the latter lemma to prove that the function `fun x => x⁻¹` is integrable on `a..b` if and only if `a = b` or `0 βˆ‰ [a, b]`. ## Main results * `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured`: if `f` tends to infinity along `𝓝[β‰ ] c` and `f' = O(g)` along the same filter, then `g` is not interval integrable on any nontrivial integral `a..b`, `c ∈ [a, b]`. * `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_filter`: a version of `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured` that works for one-sided neighborhoods; * `not_intervalIntegrable_of_sub_inv_isBigO_punctured`: if `1 / (x - c) = O(f)` as `x β†’ c`, `x β‰  c`, then `f` is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`; * `intervalIntegrable_sub_inv_iff`, `intervalIntegrable_inv_iff`: integrability conditions for `(x - c)⁻¹` and `x⁻¹`. ## Tags integrable function -/ open scoped MeasureTheory Topology Interval NNReal ENNReal open MeasureTheory TopologicalSpace Set Filter Asymptotics intervalIntegral variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] /-- If `f` is eventually differentiable along a nontrivial filter `l : Filter ℝ` that is generated by convex sets, the norm of `f` tends to infinity along `l`, and `f' = O(g)` along `l`, where `f'` is the derivative of `f`, then `g` is not integrable on any set `k` belonging to `l`. Auxiliary version assuming that `E` is complete. -/ theorem not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter_aux [CompleteSpace E] {f : ℝ β†’ E} {g : ℝ β†’ F} {k : Set ℝ} (l : Filter ℝ) [NeBot l] [TendstoIxxClass Icc l l] (hl : k ∈ l) (hd : βˆ€αΆ  x in l, DifferentiableAt ℝ f x) (hf : Tendsto (fun x => β€–f xβ€–) l atTop) (hfg : deriv f =O[l] g) : Β¬IntegrableOn g k := by intro hgi obtain ⟨C, hCβ‚€, s, hsl, hsub, hfd, hg⟩ : βˆƒ (C : ℝ) (_ : 0 ≀ C), βˆƒ s ∈ l, (βˆ€ x ∈ s, βˆ€ y ∈ s, [[x, y]] βŠ† k) ∧ (βˆ€ x ∈ s, βˆ€ y ∈ s, βˆ€ z ∈ [[x, y]], DifferentiableAt ℝ f z) ∧ βˆ€ x ∈ s, βˆ€ y ∈ s, βˆ€ z ∈ [[x, y]], β€–deriv f zβ€– ≀ C * β€–g zβ€– := by rcases hfg.exists_nonneg with ⟨C, Cβ‚€, hC⟩ have h : βˆ€αΆ  x : ℝ Γ— ℝ in l Γ—Λ’ l, βˆ€ y ∈ [[x.1, x.2]], (DifferentiableAt ℝ f y ∧ β€–deriv f yβ€– ≀ C * β€–g yβ€–) ∧ y ∈ k := (tendsto_fst.uIcc tendsto_snd).eventually ((hd.and hC.bound).and hl).smallSets rcases mem_prod_self_iff.1 h with ⟨s, hsl, hs⟩ simp only [prod_subset_iff, mem_setOf_eq] at hs exact ⟨C, Cβ‚€, s, hsl, fun x hx y hy z hz => (hs x hx y hy z hz).2, fun x hx y hy z hz => (hs x hx y hy z hz).1.1, fun x hx y hy z hz => (hs x hx y hy z hz).1.2⟩ replace hgi : IntegrableOn (fun x ↦ C * β€–g xβ€–) k := by exact hgi.norm.smul C obtain ⟨c, hc, d, hd, hlt⟩ : βˆƒ c ∈ s, βˆƒ d ∈ s, (β€–f cβ€– + ∫ y in k, C * β€–g yβ€–) < β€–f dβ€– := by rcases Filter.nonempty_of_mem hsl with ⟨c, hc⟩ have : βˆ€αΆ  x in l, (β€–f cβ€– + ∫ y in k, C * β€–g yβ€–) < β€–f xβ€– := hf.eventually (eventually_gt_atTop _) exact ⟨c, hc, (this.and hsl).exists.imp fun d hd => ⟨hd.2, hd.1⟩⟩ specialize hsub c hc d hd; specialize hfd c hc d hd replace hg : βˆ€ x ∈ Ξ™ c d, β€–deriv f xβ€– ≀ C * β€–g xβ€– := fun z hz => hg c hc d hd z ⟨hz.1.le, hz.2⟩ have hg_ae : βˆ€α΅ x βˆ‚volume.restrict (Ξ™ c d), β€–deriv f xβ€– ≀ C * β€–g xβ€– := (ae_restrict_mem measurableSet_uIoc).mono hg have hsub' : Ξ™ c d βŠ† k := Subset.trans Ioc_subset_Icc_self hsub have hfi : IntervalIntegrable (deriv f) volume c d := by rw [intervalIntegrable_iff] have : IntegrableOn (fun x ↦ C * β€–g xβ€–) (Ξ™ c d) := IntegrableOn.mono hgi hsub' le_rfl exact Integrable.mono' this (aestronglyMeasurable_deriv _ _) hg_ae refine hlt.not_ge (sub_le_iff_le_add'.1 ?_) calc β€–f dβ€– - β€–f cβ€– ≀ β€–f d - f cβ€– := norm_sub_norm_le _ _ _ = β€–βˆ« x in c..d, deriv f xβ€– := congr_arg _ (integral_deriv_eq_sub hfd hfi).symm _ = β€–βˆ« x in Ξ™ c d, deriv f xβ€– := norm_integral_eq_norm_integral_uIoc _ _ ≀ ∫ x in Ξ™ c d, β€–deriv f xβ€– := norm_integral_le_integral_norm _ _ ≀ ∫ x in Ξ™ c d, C * β€–g xβ€– := setIntegral_mono_on hfi.norm.def' (hgi.mono_set hsub') measurableSet_uIoc hg _ ≀ ∫ x in k, C * β€–g xβ€– := by apply setIntegral_mono_set hgi (ae_of_all _ fun x => mul_nonneg hCβ‚€ (norm_nonneg _)) hsub'.eventuallyLE theorem not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter {f : ℝ β†’ E} {g : ℝ β†’ F} {k : Set ℝ} (l : Filter ℝ) [NeBot l] [TendstoIxxClass Icc l l] (hl : k ∈ l) (hd : βˆ€αΆ  x in l, DifferentiableAt ℝ f x) (hf : Tendsto (fun x => β€–f xβ€–) l atTop) (hfg : deriv f =O[l] g) : Β¬IntegrableOn g k := by let a : E β†’β‚—α΅’[ℝ] UniformSpace.Completion E := UniformSpace.Completion.toComplβ‚—α΅’ let f' := a ∘ f have h'd : βˆ€αΆ  x in l, DifferentiableAt ℝ f' x := by filter_upwards [hd] with x hx using a.toContinuousLinearMap.differentiableAt.comp x hx have h'f : Tendsto (fun x => β€–f' xβ€–) l atTop := hf.congr (fun x ↦ by simp [f']) have h'fg : deriv f' =O[l] g := by apply IsBigO.trans _ hfg rw [← isBigO_norm_norm] suffices (fun x ↦ β€–deriv f' xβ€–) =αΆ [l] (fun x ↦ β€–deriv f xβ€–) by exact this.isBigO filter_upwards [hd] with x hx have : deriv f' x = a (deriv f x) := by rw [fderiv_comp_deriv x _ hx] Β· have : fderiv ℝ a (f x) = a.toContinuousLinearMap := a.toContinuousLinearMap.fderiv simp only [this] rfl Β· exact a.toContinuousLinearMap.differentiableAt simp only [this] simp exact not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter_aux l hl h'd h'f h'fg /-- If `f` is eventually differentiable along a nontrivial filter `l : Filter ℝ` that is generated by convex sets, the norm of `f` tends to infinity along `l`, and `f' = O(g)` along `l`, where `f'` is the derivative of `f`, then `g` is not integrable on any interval `a..b` such that `[a, b] ∈ l`. -/ theorem not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_filter {f : ℝ β†’ E} {g : ℝ β†’ F} {a b : ℝ} (l : Filter ℝ) [NeBot l] [TendstoIxxClass Icc l l] (hl : [[a, b]] ∈ l) (hd : βˆ€αΆ  x in l, DifferentiableAt ℝ f x) (hf : Tendsto (fun x => β€–f xβ€–) l atTop) (hfg : deriv f =O[l] g) : Β¬IntervalIntegrable g volume a b := by rw [intervalIntegrable_iff'] exact not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter _ hl hd hf hfg /-- If `a β‰  b`, `c ∈ [a, b]`, `f` is differentiable in the neighborhood of `c` within `[a, b] \ {c}`, `β€–f xβ€– β†’ ∞` as `x β†’ c` within `[a, b] \ {c}`, and `f' = O(g)` along `𝓝[[a, b] \ {c}] c`, where `f'` is the derivative of `f`, then `g` is not interval integrable on `a..b`. -/ theorem not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_within_diff_singleton {f : ℝ β†’ E} {g : ℝ β†’ F} {a b c : ℝ} (hne : a β‰  b) (hc : c ∈ [[a, b]]) (h_deriv : βˆ€αΆ  x in 𝓝[[[a, b]] \ {c}] c, DifferentiableAt ℝ f x) (h_infty : Tendsto (fun x => β€–f xβ€–) (𝓝[[[a, b]] \ {c}] c) atTop) (hg : deriv f =O[𝓝[[[a, b]] \ {c}] c] g) : Β¬IntervalIntegrable g volume a b := by obtain ⟨l, hl, hl', hle, hmem⟩ : βˆƒ l : Filter ℝ, TendstoIxxClass Icc l l ∧ l.NeBot ∧ l ≀ 𝓝 c ∧ [[a, b]] \ {c} ∈ l := by rcases (min_lt_max.2 hne).gt_or_lt c with hlt | hlt Β· refine βŸ¨π“[<] c, inferInstance, inferInstance, inf_le_left, ?_⟩ rw [← Iic_diff_right] exact diff_mem_nhdsWithin_diff (Icc_mem_nhdsLE_of_mem ⟨hlt, hc.2⟩) _ Β· refine βŸ¨π“[>] c, inferInstance, inferInstance, inf_le_left, ?_⟩ rw [← Ici_diff_left] exact diff_mem_nhdsWithin_diff (Icc_mem_nhdsGE_of_mem ⟨hc.1, hlt⟩) _ have : l ≀ 𝓝[[[a, b]] \ {c}] c := le_inf hle (le_principal_iff.2 hmem) exact not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_filter l (mem_of_superset hmem diff_subset) (h_deriv.filter_mono this) (h_infty.mono_left this) (hg.mono this) /-- If `f` is differentiable in a punctured neighborhood of `c`, `β€–f xβ€– β†’ ∞` as `x β†’ c` (more formally, along the filter `𝓝[β‰ ] c`), and `f' = O(g)` along `𝓝[β‰ ] c`, where `f'` is the derivative of `f`, then `g` is not interval integrable on any nontrivial interval `a..b` such that `c ∈ [a, b]`. -/ theorem not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured {f : ℝ β†’ E} {g : ℝ β†’ F} {a b c : ℝ} (h_deriv : βˆ€αΆ  x in 𝓝[β‰ ] c, DifferentiableAt ℝ f x) (h_infty : Tendsto (fun x => β€–f xβ€–) (𝓝[β‰ ] c) atTop) (hg : deriv f =O[𝓝[β‰ ] c] g) (hne : a β‰  b) (hc : c ∈ [[a, b]]) : Β¬IntervalIntegrable g volume a b := have : 𝓝[[[a, b]] \ {c}] c ≀ 𝓝[β‰ ] c := nhdsWithin_mono _ inter_subset_right not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_within_diff_singleton hne hc (h_deriv.filter_mono this) (h_infty.mono_left this) (hg.mono this) /-- If `f` grows in the punctured neighborhood of `c : ℝ` at least as fast as `1 / (x - c)`, then it is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`. -/ theorem not_intervalIntegrable_of_sub_inv_isBigO_punctured {f : ℝ β†’ F} {a b c : ℝ} (hf : (fun x => (x - c)⁻¹) =O[𝓝[β‰ ] c] f) (hne : a β‰  b) (hc : c ∈ [[a, b]]) : Β¬IntervalIntegrable f volume a b := by have A : βˆ€αΆ  x in 𝓝[β‰ ] c, HasDerivAt (fun x => Real.log (x - c)) (x - c)⁻¹ x := by filter_upwards [self_mem_nhdsWithin] with x hx simpa using ((hasDerivAt_id x).sub_const c).log (sub_ne_zero.2 hx) have B : Tendsto (fun x => β€–Real.log (x - c)β€–) (𝓝[β‰ ] c) atTop := by refine tendsto_abs_atBot_atTop.comp (Real.tendsto_log_nhdsNE_zero.comp ?_) rw [← sub_self c] exact ((hasDerivAt_id c).sub_const c).tendsto_nhdsNE one_ne_zero exact not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured (A.mono fun x hx => hx.differentiableAt) B (hf.congr' (A.mono fun x hx => hx.deriv.symm) EventuallyEq.rfl) hne hc /-- The function `fun x => (x - c)⁻¹` is integrable on `a..b` if and only if `a = b` or `c βˆ‰ [a, b]`. -/ @[simp] theorem intervalIntegrable_sub_inv_iff {a b c : ℝ} : IntervalIntegrable (fun x => (x - c)⁻¹) volume a b ↔ a = b ∨ c βˆ‰ [[a, b]] := by constructor Β· refine fun h => or_iff_not_imp_left.2 fun hne hc => ?_ exact not_intervalIntegrable_of_sub_inv_isBigO_punctured (isBigO_refl _ _) hne hc h Β· rintro (rfl | hβ‚€) Β· exact IntervalIntegrable.refl refine ((continuous_sub_right c).continuousOn.invβ‚€ ?_).intervalIntegrable exact fun x hx => sub_ne_zero.2 <| ne_of_mem_of_not_mem hx hβ‚€ /-- The function `fun x => x⁻¹` is integrable on `a..b` if and only if `a = b` or `0 βˆ‰ [a, b]`. -/ @[simp] theorem intervalIntegrable_inv_iff {a b : ℝ} : IntervalIntegrable (fun x => x⁻¹) volume a b ↔ a = b ∨ (0 : ℝ) βˆ‰ [[a, b]] := by simp only [← intervalIntegrable_sub_inv_iff, sub_zero] /-- The function `fun x ↦ x⁻¹` is not integrable on any interval `[a, +∞)`. -/ theorem not_IntegrableOn_Ici_inv {a : ℝ} : Β¬ IntegrableOn (fun x => x⁻¹) (Ici a) := by have A : βˆ€αΆ  x in atTop, HasDerivAt (fun x => Real.log x) x⁻¹ x := by filter_upwards [Ioi_mem_atTop 0] with x hx using Real.hasDerivAt_log (ne_of_gt hx) have B : Tendsto (fun x => β€–Real.log xβ€–) atTop atTop := tendsto_norm_atTop_atTop.comp Real.tendsto_log_atTop exact not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter atTop (Ici_mem_atTop a) (A.mono (fun x hx ↦ hx.differentiableAt)) B (Filter.EventuallyEq.isBigO (A.mono (fun x hx ↦ hx.deriv))) /-- The function `fun x ↦ x⁻¹` is not integrable on any interval `(a, +∞)`. -/ theorem not_IntegrableOn_Ioi_inv {a : ℝ} : Β¬ IntegrableOn (·⁻¹) (Ioi a) := by simpa only [IntegrableOn, restrict_Ioi_eq_restrict_Ici] using not_IntegrableOn_Ici_inv
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Bernstein.lean
import Mathlib.Algebra.BigOperators.Field import Mathlib.Analysis.Convex.Gauge import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.RingTheory.Polynomial.Bernstein import Mathlib.Topology.Algebra.Module.LocallyConvex import Mathlib.Topology.ContinuousMap.Polynomial /-! # Bernstein approximations and Weierstrass' theorem We prove that the Bernstein approximations ``` βˆ‘ k : Fin (n+1), (n.choose k * x^k * (1-x)^(n-k)) β€’ f (k/n : ℝ) ``` for a continuous function `f : C([0,1], E)` taking values in a locally convex vector space converge uniformly to `f` as `n` tends to infinity. This statement directly applies to the cases when the codomain is a (semi)normed space or, more generally, has a topology defined by a family of seminorms. Our proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], Β§7D. The original proof, due to [Bernstein](bernstein1912) in 1912, is probabilistic, and relies on Bernoulli's theorem, which gives bounds for how quickly the observed frequencies in a Bernoulli trial approach the underlying probability. The proof here does not directly rely on Bernoulli's theorem, but can also be given a probabilistic account. * Consider a weighted coin which with probability `x` produces heads, and with probability `1-x` produces tails. * The value of `bernstein n k x` is the probability that such a coin gives exactly `k` heads in a sequence of `n` tosses. * If such an appearance of `k` heads results in a payoff of `f(k / n)`, the `n`-th Bernstein approximation for `f` evaluated at `x` is the expected payoff. * The main estimate in the proof bounds the probability that the observed frequency of heads differs from `x` by more than some `Ξ΄`, obtaining a bound of `(4 * n * Ξ΄^2)⁻¹`, irrespective of `x`. * This ensures that for `n` large, the Bernstein approximation is (uniformly) close to the payoff function `f`. (You don't need to think in these terms to follow the proof below: it's a giant `calc` block!) This result proves Weierstrass' theorem that polynomials are dense in `C([0,1], ℝ)`, although we defer an abstract statement of this until later. -/ noncomputable section open Filter open scoped unitInterval Topology Uniformity /-- The Bernstein polynomials, as continuous functions on `[0,1]`. -/ def bernstein (n Ξ½ : β„•) : C(I, ℝ) := (bernsteinPolynomial ℝ n Ξ½).toContinuousMapOn I theorem bernstein_apply (n Ξ½ : β„•) (x : I) : bernstein n Ξ½ x = (n.choose Ξ½ : ℝ) * (x : ℝ) ^ Ξ½ * (1 - (x : ℝ)) ^ (n - Ξ½) := by dsimp [bernstein, Polynomial.toContinuousMapOn, Polynomial.toContinuousMap, bernsteinPolynomial] simp @[simp] theorem bernstein_nonneg {n Ξ½ : β„•} {x : I} : 0 ≀ bernstein n Ξ½ x := by simp only [bernstein_apply] have h₁ : (0 : ℝ) ≀ x := by unit_interval have hβ‚‚ : (0 : ℝ) ≀ 1 - x := by unit_interval positivity namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension of the `positivity` tactic for Bernstein polynomials: they are always non-negative. -/ @[positivity DFunLike.coe (bernstein _ _) _] def evalBernstein : PositivityExt where eval {_ _} _zΞ± _pΞ± e := do let .app (.app _coe (.app (.app _ n) Ξ½)) x ← whnfR e | throwError "not bernstein polynomial" let p ← mkAppOptM ``bernstein_nonneg #[n, Ξ½, x] pure (.nonnegative p) end Mathlib.Meta.Positivity /-! We now give a slight reformulation of `bernsteinPolynomial.variance`. -/ namespace bernstein /-- Send `k : Fin (n+1)` to the equally spaced points `k/n` in the unit interval. -/ def z {n : β„•} (k : Fin (n + 1)) : I := ⟨(k : ℝ) / n, by simp [div_nonneg, div_le_one_of_leβ‚€, k.is_le]⟩ local postfix:90 "/β‚™" => z @[simp] lemma z_zero {n : β„•} : (0 : Fin (n + 1))/β‚™ = 0 := by simp [z] @[simp] lemma z_last {n : β„•} (hn : n β‰  0) : .last n/β‚™ = 1 := by simp [z, hn] @[simp] theorem probability (n : β„•) (x : I) : (βˆ‘ k : Fin (n + 1), bernstein n k x) = 1 := by have := bernsteinPolynomial.sum ℝ n apply_fun fun p => Polynomial.aeval (x : ℝ) p at this simpa [Finset.sum_range] theorem variance {n : β„•} (hn : n β‰  0) (x : I) : (βˆ‘ k : Fin (n + 1), (x - k/β‚™ : ℝ) ^ 2 * bernstein n k x) = (x : ℝ) * (1 - x) / n := by convert congr(Polynomial.aeval (x : ℝ) $(bernsteinPolynomial.variance ℝ n) / n ^ 2) using 1 Β· simp only [z, bernstein_apply, nsmul_eq_mul, bernsteinPolynomial, Finset.sum_range, map_sum, Polynomial.coe_aeval_eq_eval, Polynomial.eval_mul, Polynomial.eval_pow, Polynomial.eval_sub, Polynomial.eval_natCast, Polynomial.eval_X, Polynomial.eval_one] field_simp rw [← Finset.sum_div] field Β· simp field end bernstein open bernstein local postfix:1024 "/β‚™" => z variable {E : Type*} [AddCommGroup E] [TopologicalSpace E] [IsTopologicalAddGroup E] [Module ℝ E] [ContinuousSMul ℝ E] /-- The `n`-th approximation of a continuous function on `[0,1]` by Bernstein polynomials, given by `βˆ‘ k, bernstein n k x β€’ f (k/n)`. -/ def bernsteinApproximation (n : β„•) (f : C(I, E)) : C(I, E) := βˆ‘ k : Fin (n + 1), bernstein n k β€’ .const _ (f k/β‚™) /-! We now set up some of the basic machinery of the proof that the Bernstein approximations converge uniformly. A key player is the set `S f Ξ΅ h n x`, for some function `f : C(I, E)`, `h : 0 < Ξ΅`, `n : β„•` and `x : I`. This is the set of points `k` in `Fin (n+1)` such that `k/n` is within `Ξ΄` of `x`, where `Ξ΄` is the modulus of uniform continuity for `f`, chosen so `β€–f x - f yβ€– < Ξ΅/2` when `|x - y| < Ξ΄`. We show that if `k βˆ‰ S`, then `1 ≀ Ξ΄^-2 * (x - k/n)^2`. -/ namespace bernsteinApproximation theorem apply (n : β„•) (f : C(I, E)) (x : I) : bernsteinApproximation n f x = βˆ‘ k : Fin (n + 1), bernstein n k x β€’ f k/β‚™ := by simp [bernsteinApproximation] @[simp] theorem apply_zero (n : β„•) (f : C(I, E)) : bernsteinApproximation n f 0 = f 0 := by simp [apply, Fin.sum_univ_succ, bernstein_apply, z] @[simp] theorem apply_one {n : β„•} (hn : n β‰  0) (f : C(I, E)) : bernsteinApproximation n f 1 = f 1 := by simp [apply, Fin.sum_univ_castSucc, bernstein_apply, hn, Nat.sub_eq_zero_iff_le] end bernsteinApproximation open bernsteinApproximation /-- The Bernstein approximations ``` βˆ‘ k : Fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k) ``` for a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity. This is the proof given in [Richard Beals' *Analysis, an introduction*][beals-analysis], Β§7D, and reproduced on wikipedia. -/ theorem bernsteinApproximation_uniform [LocallyConvexSpace ℝ E] (f : C(I, E)) : Tendsto (fun n : β„• => bernsteinApproximation n f) atTop (𝓝 f) := by letI : UniformSpace E := IsTopologicalAddGroup.rightUniformSpace E have : IsUniformAddGroup E := isUniformAddGroup_of_addCommGroup /- Topology on a locally convex TVS is given by a family of seminorms `β€–xβ€–_U = gauge U x`, where the open symmetric convex sets `U` form a basis of neighborhoods in this topology, and are the open unit balls for the corresponding seminorms. For technical reasons, we neither assume `U`s to be open, nor symmetric. -/ suffices βˆ€ U ∈ 𝓝 (0 : E), Convex ℝ U β†’ βˆ€αΆ  n in atTop, βˆ€ x : I, gauge U (bernsteinApproximation n f x - f x) < 1 by rw [(LocallyConvexSpace.convex_basis_zero ℝ E).uniformity_of_nhds_zero_swapped |>.compactConvergenceUniformity_of_compact |> nhds_basis_uniformity |>.tendsto_right_iff] rintro U ⟨hUβ‚€, hcU⟩ filter_upwards [this U hUβ‚€ hcU] with n hn x exact gauge_lt_one_subset_self hcU (mem_of_mem_nhds hUβ‚€) (absorbent_nhds_zero hUβ‚€) (hn x) intro U hUβ‚€ hUc /- Choose a constant `C` such that `β€–f x - f yβ€–_U ≀ C` for all `x`, `y`. For a normed space, this would be twice the norm of `f`. -/ obtain ⟨C, hC⟩ : βˆƒ C, βˆ€ x y, gauge U (f x - f y) ≀ C := by have : Continuous fun (x, y) ↦ gauge U (f x - f y) := by fun_prop (disch := assumption) simpa only [BddAbove, Set.Nonempty, mem_upperBounds, Set.forall_mem_range, Prod.forall] using isCompact_range this |>.bddAbove have hCβ‚€ : 0 ≀ C := le_trans (gauge_nonneg _) (hC 0 0) /- Use uniform continuity of `f` to hcoose `Ξ΄ > 0` such that `β€–f x - f yβ€–_U < 1 / 2` whenever `dist x y < Ξ΄`. -/ obtain ⟨δ, hΞ΄β‚€, hδ⟩ : βˆƒ Ξ΄ > 0, βˆ€ x y : I, dist x y < Ξ΄ β†’ gauge U (f x - f y) < 1 / 2 := by have := CompactSpace.uniformContinuous_of_continuous (map_continuous f) rw [Metric.uniformity_basis_dist.uniformContinuous_iff (basis_sets _).uniformity_of_nhds_zero_swapped] at this exact this {z | gauge U z < 1 / 2} <| tendsto_gauge_nhds_zero hUβ‚€ |>.eventually_lt_const <| by positivity -- Take `n β‰  0` such that `C / Ξ΄ ^ 2 / n < 1 / 2`. have nhds_zero := tendsto_const_div_atTop_nhds_zero_nat (C / Ξ΄ ^ 2) filter_upwards [nhds_zero.eventually_lt_const (half_pos one_pos), eventually_ne_atTop 0] with n nh hnβ‚€ x -- The idea is to split up the sum over `k` into two sets, -- `S`, where `x - k/n < Ξ΄`, and its complement. set S : Finset (Fin (n + 1)) := {k : Fin (n + 1) | dist k/β‚™ x < Ξ΄} calc gauge U (bernsteinApproximation n f x - f x) = gauge U (βˆ‘ k : Fin (n + 1), bernstein n k x β€’ (f k/β‚™ - f x)) := by simp [bernsteinApproximation.apply, smul_sub, ← Finset.sum_smul] _ ≀ βˆ‘ k : Fin (n + 1), gauge U (bernstein n k x β€’ (f k/β‚™ - f x)) := gauge_sum_le hUc (absorbent_nhds_zero hUβ‚€) _ _ _ = βˆ‘ k : Fin (n + 1), bernstein n k x * gauge U (f k/β‚™ - f x) := by simp only [gauge_smul_of_nonneg, bernstein_nonneg, smul_eq_mul] _ = (βˆ‘ k ∈ S, bernstein n k x * gauge U (f k/β‚™ - f x)) + βˆ‘ k ∈ Sᢜ, bernstein n k x * gauge U (f k/β‚™ - f x) := (S.sum_add_sum_compl _).symm -- We'll now deal with the terms in `S` and the terms in `Sᢜ` in separate calc blocks. _ < 1 / 2 + 1 / 2 := add_lt_add_of_le_of_lt ?_ ?_ _ = 1 := add_halves 1 Β· -- We now work on the terms in `S`: uniform continuity and `bernstein.probability` -- quickly give us a bound. calc βˆ‘ k ∈ S, bernstein n k x * gauge U (f k/β‚™ - f x) ≀ βˆ‘ k ∈ S, bernstein n k x * (1 / 2) := by gcongr with k hk refine (hΞ΄ _ _ ?_).le simpa [S] using hk _ = 1 / 2 * βˆ‘ k ∈ S, bernstein n k x := by rw [mul_comm, Finset.sum_mul] -- In this step we increase the sum over `S` back to a sum over all of `Fin (n+1)`, -- so that we can use `bernstein.probability`. _ ≀ 1 / 2 * βˆ‘ k : Fin (n + 1), bernstein n k x := by gcongr; exact S.subset_univ _ = 1 / 2 := by rw [bernstein.probability, mul_one] Β· -- We now turn to working on `Sᢜ`: we control the difference term just using `C`, -- and then insert a `(x - k/n)^2 / Ξ΄^2` factor -- (which is at least one because we are not in `S`). calc βˆ‘ k ∈ Sᢜ, bernstein n k x * gauge U (f k/β‚™ - f x) ≀ βˆ‘ k ∈ Sᢜ, C * bernstein n k x := by simp only [mul_comm (bernstein n _ x)] gcongr apply hC _ = C * βˆ‘ k ∈ Sᢜ, bernstein n k x := by rw [Finset.mul_sum] _ ≀ C * βˆ‘ k ∈ Sᢜ, ((x : ℝ) - k/β‚™) ^ 2 / Ξ΄ ^ 2 * bernstein n k x := by gcongr with k hk conv_lhs => rw [← one_mul (bernstein _ _ _)] gcongr simpa [one_le_divβ‚€, hΞ΄β‚€, sq_le_sq, S, abs_of_pos, ← Real.dist_eq, dist_comm (x : ℝ)] using hk -- Again enlarging the sum from `Sᢜ` to all of `Fin (n+1)` _ ≀ C * βˆ‘ k : Fin (n + 1), ((x : ℝ) - k/β‚™) ^ 2 / Ξ΄ ^ 2 * bernstein n k x := by gcongr; exact Sᢜ.subset_univ _ = C * (βˆ‘ k : Fin (n + 1), ((x : ℝ) - k/β‚™) ^ 2 * bernstein n k x) / Ξ΄ ^ 2 := by simp only [← mul_div_right_comm, ← mul_div_assoc, ← Finset.sum_div] -- `bernstein.variance` and `x ∈ [0,1]` gives the uniform bound _ = C / Ξ΄ ^ 2 * x * (1 - x) / n := by rw [variance hnβ‚€]; ring _ ≀ C / Ξ΄ ^ 2 * 1 * 1 / n := by gcongr <;> unit_interval _ < 1 / 2 := by simpa only [mul_one]
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/MulExpNegMulSq.lean
import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Log.Basic import Mathlib.Topology.ContinuousMap.Bounded.Normed /-! # Definition of `mulExpNegMulSq` and properties `mulExpNegMulSq` is the mapping `fun (Ξ΅ : ℝ) (x : ℝ) => x * Real.exp (- (Ξ΅ * x * x))`. By composition, it can be used to transform a function `g : E β†’ ℝ` into a bounded function `mulExpNegMulSq Ξ΅ ∘ g : E β†’ ℝ = fun x => g x * Real.exp (-Ξ΅ * g x * g x)` with useful boundedness and convergence properties. ## Main Properties - `abs_mulExpNegMulSq_le`: For fixed `Ξ΅ > 0`, the mapping `x ↦ mulExpNegMulSq Ξ΅ x` is bounded by `Real.sqrt Ρ⁻¹`; - `tendsto_mulExpNegMulSq`: For fixed `x : ℝ`, the mapping `mulExpNegMulSq Ξ΅ x` converges pointwise to `x` as `Ξ΅ β†’ 0`; - `lipschitzWith_one_mulExpNegMulSq`: For fixed `Ξ΅ > 0`, the mapping `mulExpNegMulSq Ξ΅` is Lipschitz with constant `1`; - `abs_mulExpNegMulSq_comp_le_norm`: For a fixed bounded continuous function `g`, the mapping `mulExpNegMulSq Ξ΅ ∘ g` is bounded by `norm g`, uniformly in `Ξ΅ β‰₯ 0`; -/ open NNReal ENNReal BoundedContinuousFunction Filter open scoped Topology namespace Real /-! ### Definition and properties of `fun x => x * Real.exp (- (Ξ΅ * x * x))` -/ /-- Mapping `fun Ξ΅ x => x * Real.exp (- (Ξ΅ * x * x))`. By composition, it can be used to transform functions into bounded functions. -/ noncomputable def mulExpNegMulSq (Ξ΅ x : ℝ) := x * exp (- (Ξ΅ * x * x)) theorem mulExpNegSq_apply (Ξ΅ x : ℝ) : mulExpNegMulSq Ξ΅ x = x * exp (- (Ξ΅ * x * x)) := rfl theorem neg_mulExpNegMulSq_neg (Ξ΅ x : ℝ) : - mulExpNegMulSq Ξ΅ (-x) = mulExpNegMulSq Ξ΅ x := by simp [mulExpNegMulSq] theorem mulExpNegMulSq_one_le_one (x : ℝ) : mulExpNegMulSq 1 x ≀ 1 := by simp only [mulExpNegMulSq, one_mul] rw [← le_div_iffβ‚€ (exp_pos (-(x * x))), exp_neg, div_inv_eq_mul, one_mul] apply le_trans _ (add_one_le_exp (x * x)) nlinarith theorem neg_one_le_mulExpNegMulSq_one (x : ℝ) : -1 ≀ mulExpNegMulSq 1 x := by rw [← neg_mulExpNegMulSq_neg, neg_le_neg_iff] exact mulExpNegMulSq_one_le_one (-x) theorem abs_mulExpNegMulSq_one_le_one (x : ℝ) : |mulExpNegMulSq 1 x| ≀ 1 := abs_le.mpr ⟨neg_one_le_mulExpNegMulSq_one x, mulExpNegMulSq_one_le_one x⟩ variable {Ξ΅ : ℝ} @[continuity, fun_prop] theorem continuous_mulExpNegMulSq : Continuous (fun x => mulExpNegMulSq Ξ΅ x) := Continuous.mul continuous_id (by fun_prop) @[continuity, fun_prop] theorem _root_.Continuous.mulExpNegMulSq {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} (hf : Continuous f) : Continuous (fun x => mulExpNegMulSq Ξ΅ (f x)) := continuous_mulExpNegMulSq.comp hf theorem differentiableAt_mulExpNegMulSq (y : ℝ) : DifferentiableAt ℝ (mulExpNegMulSq Ξ΅) y := DifferentiableAt.mul differentiableAt_fun_id (by fun_prop) @[fun_prop] theorem differentiable_mulExpNegMulSq : Differentiable ℝ (mulExpNegMulSq Ξ΅) := fun _ => differentiableAt_mulExpNegMulSq _ theorem hasDerivAt_mulExpNegMulSq (y : ℝ) : HasDerivAt (mulExpNegMulSq Ξ΅) (exp (- (Ξ΅ * y * y)) + y * (exp (- (Ξ΅ * y * y)) * (-2 * Ξ΅ * y))) y := by nth_rw 1 [← one_mul (exp (- (Ξ΅ * y * y)))] apply HasDerivAt.mul (hasDerivAt_id' y) apply HasDerivAt.exp (HasDerivAt.congr_deriv (HasDerivAt.neg (HasDerivAt.mul (HasDerivAt.const_mul Ξ΅ (hasDerivAt_id' y)) (hasDerivAt_id' y))) (by ring)) theorem deriv_mulExpNegMulSq (y : ℝ) : deriv (mulExpNegMulSq Ξ΅) y = exp (- (Ξ΅ * y * y)) + y * (exp (- (Ξ΅ * y * y)) * (-2 * Ξ΅ * y)) := HasDerivAt.deriv (hasDerivAt_mulExpNegMulSq y) theorem norm_deriv_mulExpNegMulSq_le_one (hΞ΅ : 0 < Ξ΅) (x : ℝ) : β€–deriv (mulExpNegMulSq Ξ΅) xβ€– ≀ 1 := by rw [norm_eq_abs, deriv_mulExpNegMulSq] have heq : exp (- (Ξ΅ * x * x)) + x * (exp (- (Ξ΅ * x * x)) * (-2 * Ξ΅ * x)) = exp (- (Ξ΅ * x * x)) * (1 -2 * (Ξ΅ * x * x)) := by ring rw [heq, abs_mul, abs_exp] set y := Ξ΅ * x * x with hy have hynonneg : 0 ≀ y := by rw [hy, mul_assoc] exact mul_nonneg hΞ΅.le (mul_self_nonneg x) apply mul_le_of_le_inv_mulβ‚€ (zero_le_one' ℝ) (exp_nonneg _) simp only [← exp_neg (-y), neg_neg, mul_one, abs_le, neg_le_sub_iff_le_add, tsub_le_iff_right] refine ⟨le_trans two_mul_le_exp ((le_add_iff_nonneg_left (exp y)).mpr zero_le_one), ?_⟩ exact le_trans (one_le_exp hynonneg) (le_add_of_nonneg_right (by simp [hynonneg])) theorem nnnorm_deriv_mulExpNegMulSq_le_one (hΞ΅ : 0 < Ξ΅) (x : ℝ) : β€–deriv (mulExpNegMulSq Ξ΅) xβ€–β‚Š ≀ 1 := by rw [← NNReal.coe_le_coe, coe_nnnorm] exact norm_deriv_mulExpNegMulSq_le_one hΞ΅ x /-- For fixed `Ξ΅ > 0`, the mapping `mulExpNegMulSq Ξ΅` is Lipschitz with constant `1` -/ theorem lipschitzWith_one_mulExpNegMulSq (hΞ΅ : 0 < Ξ΅) : LipschitzWith 1 (mulExpNegMulSq Ξ΅) := by apply lipschitzWith_of_nnnorm_deriv_le differentiable_mulExpNegMulSq exact nnnorm_deriv_mulExpNegMulSq_le_one hΞ΅ theorem mulExpNegMulSq_eq_sqrt_mul_mulExpNegMulSq_one (hΞ΅ : 0 < Ξ΅) (x : ℝ) : mulExpNegMulSq Ξ΅ x = (√Ρ)⁻¹ * mulExpNegMulSq 1 (sqrt Ξ΅ * x) := by grind [mulExpNegMulSq] /-- For fixed `Ξ΅ > 0`, the mapping `x ↦ mulExpNegMulSq Ξ΅ x` is bounded by `(√Ρ)⁻¹`. -/ theorem abs_mulExpNegMulSq_le (hΞ΅ : 0 < Ξ΅) {x : ℝ} : |mulExpNegMulSq Ξ΅ x| ≀ (√Ρ)⁻¹ := by rw [mulExpNegMulSq_eq_sqrt_mul_mulExpNegMulSq_one hΞ΅ x, abs_mul, abs_of_pos (by positivity)] apply mul_le_of_le_one_right Β· positivity Β· exact abs_mulExpNegMulSq_one_le_one (√Ρ * x) theorem dist_mulExpNegMulSq_le_two_mul_sqrt (hΞ΅ : 0 < Ξ΅) (x y : ℝ) : dist (mulExpNegMulSq Ξ΅ x) (mulExpNegMulSq Ξ΅ y) ≀ 2 * (√Ρ)⁻¹ := by apply le_trans (dist_triangle (mulExpNegMulSq Ξ΅ x) 0 (mulExpNegMulSq Ξ΅ y)) simp only [dist_zero_right, norm_eq_abs, dist_zero_left, two_mul] exact add_le_add (abs_mulExpNegMulSq_le hΞ΅) (abs_mulExpNegMulSq_le hΞ΅) theorem dist_mulExpNegMulSq_le_dist (hΞ΅ : 0 < Ξ΅) {x y : ℝ} : dist (mulExpNegMulSq Ξ΅ x) (mulExpNegMulSq Ξ΅ y) ≀ dist x y := by have h := lipschitzWith_one_mulExpNegMulSq hΞ΅ x y rwa [ENNReal.coe_one, one_mul, ← (toReal_le_toReal (edist_ne_top _ _) (edist_ne_top _ _))] at h /-- For fixed `x : ℝ`, the mapping `mulExpNegMulSq Ξ΅ x` converges pointwise to `x` as `Ξ΅ β†’ 0` -/ theorem tendsto_mulExpNegMulSq {x : ℝ} : Tendsto (fun Ξ΅ => mulExpNegMulSq Ξ΅ x) (𝓝 0) (𝓝 x) := by have : x = (fun Ξ΅ : ℝ => mulExpNegMulSq Ξ΅ x) 0 := by simp only [mulExpNegMulSq, zero_mul, neg_zero, exp_zero, mul_one] nth_rw 2 [this] apply Continuous.tendsto (Continuous.mul continuous_const (by fun_prop)) /-- For a fixed bounded function `g`, `mulExpNegMulSq Ξ΅ ∘ g` is bounded by `norm g`, uniformly in `Ξ΅ β‰₯ 0`. -/ theorem abs_mulExpNegMulSq_comp_le_norm {E : Type*} [TopologicalSpace E] {x : E} (g : BoundedContinuousFunction E ℝ) (hΞ΅ : 0 ≀ Ξ΅) : |(mulExpNegMulSq Ξ΅ ∘ g) x| ≀ β€–gβ€– := by simp only [Function.comp_apply, mulExpNegMulSq, abs_mul, abs_exp] apply le_trans (mul_le_of_le_one_right (abs_nonneg (g x)) _) (g.norm_coe_le_norm x) rw [exp_le_one_iff, Left.neg_nonpos_iff, mul_assoc] exact mul_nonneg hΞ΅ (mul_self_nonneg (g x)) end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Sigmoid.lean
import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Log.Basic import Mathlib.MeasureTheory.Constructions.Polish.EmbeddingReal import Mathlib.Topology.Algebra.Module.ModuleTopology /-! # Sigmoid function In this file we define the sigmoid function `x : ℝ ↦ (1 + exp (-x))⁻¹` and prove some of its analytic properties. We then show that the sigmoid function can be seen as an order embedding from `ℝ` to `I = [0, 1]` and that this embedding is both a topological embedding and a measurable embedding. We also prove that the composition of this embedding with the measurable embedding from a standard Borel space `Ξ±` to `ℝ` is a measurable embedding from `Ξ±` to `I`. ## Main definitions and results ### Sigmoid as a function from `ℝ` to `ℝ` * `Real.sigmoid` : the sigmoid function from `ℝ` to `ℝ`. * `Real.sigmoid_strictMono` : the sigmoid function is strictly monotone. * `Real.continuous_sigmoid` : the sigmoid function is continuous. * `Real.sigmoid_tendsto_nhds_1_atTop` : the sigmoid function tends to `1` at `+∞`. * `Real.sigmoid_tendsto_nhds_0_atBot` : the sigmoid function tends to `0` at `-∞`. * `Real.hasDerivAt_sigmoid` : the derivative of the sigmoid function. * `Real.analyticAt_sigmoid` : the sigmoid function is analytic at every point. ### Sigmoid as a function from `ℝ` to `I` * `unitInterval.sigmoid` : the sigmoid function from `ℝ` to `I`. * `unitInterval.sigmoid_strictMono` : the sigmoid function is strictly monotone. * `unitInterval.continuous_sigmoid` : the sigmoid function is continuous. * `unitInterval.sigmoid_tendsto_nhds_1_atTop` : the sigmoid function tends to `1` at `+∞`. * `unitInterval.sigmoid_tendsto_nhds_0_atBot` : the sigmoid function tends to `0` at `-∞`. ### Sigmoid as an `OrderEmbedding` from `ℝ` to `I` * `OrderEmbedding.sigmoid` : the sigmoid function as an `OrderEmbedding` from `ℝ` to `I`. * `OrderEmbedding.isEmbedding_sigmoid` : the sigmoid function from `ℝ` to `I` is a topological embedding. * `OrderEmbedding.measurableEmbedding_sigmoid` : the sigmoid function from `ℝ` to `I` is a measurable embedding. * `OrderEmbedding.measurableEmbedding_sigmoid_comp_embeddingReal` : the composition of the sigmoid function from `ℝ` to `I` with the measurable embedding from a standard Borel space `Ξ±` to `ℝ` is a measurable embedding from `Ξ±` to `I`. ## Tags sigmoid, embedding, measurable embedding, topological embedding -/ namespace Real /-- The sigmoid function from `ℝ` to `ℝ`. -/ noncomputable def sigmoid (x : ℝ) := (1 + exp (-x))⁻¹ lemma sigmoid_def (x : ℝ) : sigmoid x = (1 + exp (-x))⁻¹ := rfl @[simp] lemma sigmoid_zero : sigmoid 0 = 2⁻¹ := by norm_num [sigmoid] @[bound] lemma sigmoid_pos (x : ℝ) : 0 < sigmoid x := by change 0 < (1 + exp (-x))⁻¹ positivity @[bound] lemma sigmoid_nonneg (x : ℝ) : 0 ≀ sigmoid x := (sigmoid_pos x).le @[bound] lemma sigmoid_lt_one (x : ℝ) : sigmoid x < 1 := inv_lt_one_of_one_ltβ‚€ <| (lt_add_iff_pos_right 1).mpr <| exp_pos _ @[bound] lemma sigmoid_le_one (x : ℝ) : sigmoid x ≀ 1 := (sigmoid_lt_one x).le @[mono] lemma sigmoid_strictMono : StrictMono sigmoid := fun a b hab ↦ by simp only [sigmoid] gcongr lemma sigmoid_le_iff {a b : ℝ} : sigmoid a ≀ sigmoid b ↔ a ≀ b := sigmoid_strictMono.le_iff_le @[gcongr] lemma sigmoid_le {a b : ℝ} : a ≀ b β†’ sigmoid a ≀ sigmoid b := sigmoid_le_iff.mpr lemma sigmoid_lt_iff {a b : ℝ} : sigmoid a < sigmoid b ↔ a < b := sigmoid_strictMono.lt_iff_lt @[gcongr] lemma sigmoid_lt {a b : ℝ} : a < b β†’ sigmoid a < sigmoid b := sigmoid_lt_iff.mpr @[mono] lemma sigmoid_monotone : Monotone sigmoid := sigmoid_strictMono.monotone lemma sigmoid_injective : Function.Injective sigmoid := sigmoid_strictMono.injective @[simp] lemma sigmoid_inj {a b : ℝ} : sigmoid a = sigmoid b ↔ a = b := sigmoid_injective.eq_iff lemma sigmoid_neg (x : ℝ) : sigmoid (-x) = 1 - sigmoid x := by simp only [sigmoid_def] field_simp simp [add_mul, ← Real.exp_add, add_comm (1 : ℝ)] lemma sigmoid_mul_rexp_neg (x : ℝ) : sigmoid x * exp (-x) = sigmoid (-x) := by rw [sigmoid_neg, sigmoid_def] field open Set in lemma range_sigmoid : range Real.sigmoid = Ioo 0 1 := by refine subset_antisymm ?_ fun x hx ↦ ?_ Β· rintro - ⟨x, rfl⟩ simp only [mem_Ioo] bound Β· replace hx : 0 < x⁻¹ - 1 := by rwa [sub_pos, one_lt_inv_iffβ‚€] exact ⟨-(log (x⁻¹ - 1)), by simp [sigmoid_def, exp_log hx]⟩ open Topology Filter lemma tendsto_sigmoid_atTop : Tendsto sigmoid atTop (𝓝 1) := by simpa using Real.tendsto_exp_comp_nhds_zero.mpr tendsto_neg_atTop_atBot |>.const_add 1 |>.invβ‚€ <| by norm_num lemma tendsto_sigmoid_atBot : Tendsto sigmoid atBot (𝓝 0) := tendsto_const_nhds.add_atTop (tendsto_exp_comp_atTop.mpr tendsto_neg_atBot_atTop) |>.inv_tendsto_atTop lemma hasDerivAt_sigmoid (x : ℝ) : HasDerivAt sigmoid (sigmoid x * (1 - sigmoid x)) x := by convert (hasDerivAt_neg' x |>.exp.const_add 1 |>.inv <| by positivity) using 1 rw [← sigmoid_neg, ← sigmoid_mul_rexp_neg x, sigmoid_def] field [sq] lemma deriv_sigmoid : deriv sigmoid = fun x => sigmoid x * (1 - sigmoid x) := funext fun x => (hasDerivAt_sigmoid x).deriv end Real open Set Real variable {x : ℝ} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {s : Set E} @[fun_prop] lemma analyticAt_sigmoid : AnalyticAt ℝ sigmoid x := AnalyticAt.fun_inv (by fun_prop) (by positivity) @[fun_prop] lemma AnalyticAt.sigmoid {x : E} (fa : AnalyticAt ℝ f x) : AnalyticAt ℝ (sigmoid ∘ f) x := analyticAt_sigmoid.comp fa @[fun_prop] lemma AnalyticAt.sigmoid' {x : E} (fa : AnalyticAt ℝ f x) : AnalyticAt ℝ (fun z ↦ Real.sigmoid (f z)) x := fa.sigmoid lemma analyticOnNhd_sigmoid : AnalyticOnNhd ℝ sigmoid Set.univ := fun _ _ ↦ analyticAt_sigmoid lemma AnalyticOnNhd.sigmoid (fs : AnalyticOnNhd ℝ f s) : AnalyticOnNhd ℝ (sigmoid ∘ f) s := fun z n ↦ analyticAt_sigmoid.comp (fs z n) lemma analyticOn_sigmoid : AnalyticOn ℝ sigmoid Set.univ := analyticOnNhd_sigmoid.analyticOn lemma AnalyticOn.sigmoid (fs : AnalyticOn ℝ f s) : AnalyticOn ℝ (sigmoid ∘ f) s := analyticOnNhd_sigmoid.comp_analyticOn fs (mapsTo_univ _ _) lemma analyticWithinAt_sigmoid {s : Set ℝ} : AnalyticWithinAt ℝ sigmoid s x := analyticAt_sigmoid.analyticWithinAt lemma AnalyticWithinAt.sigmoid {x : E} (fa : AnalyticWithinAt ℝ f s x) : AnalyticWithinAt ℝ (sigmoid ∘ f) s x := analyticAt_sigmoid.comp_analyticWithinAt fa open ContDiff in @[fun_prop] lemma contDiff_sigmoid : ContDiff ℝ Ο‰ sigmoid := analyticOn_sigmoid.contDiff open ContDiff in @[fun_prop] lemma ContDiff.sigmoid (hf : ContDiff ℝ Ο‰ f) : ContDiff ℝ Ο‰ (sigmoid ∘ f) := contDiff_sigmoid.comp hf @[fun_prop] lemma differentiable_sigmoid : Differentiable ℝ sigmoid := contDiff_sigmoid.of_le le_top |>.differentiable_one @[fun_prop] lemma Differentiable.sigmoid (hf : Differentiable ℝ f) : Differentiable ℝ (sigmoid ∘ f) := differentiable_sigmoid.comp hf @[fun_prop] lemma differentiableAt_sigmoid : DifferentiableAt ℝ sigmoid x := differentiable_sigmoid x @[fun_prop] lemma DifferentiableAt.sigmoid {x : E} (hf : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (sigmoid ∘ f) x := differentiableAt_sigmoid.comp x hf @[fun_prop] lemma continuous_sigmoid : Continuous sigmoid := by fun_prop omit [NormedSpace ℝ E] in @[fun_prop] lemma Continuous.sigmoid (hf : Continuous f) : Continuous (sigmoid ∘ f) := continuous_sigmoid.comp hf namespace unitInterval /-- The sigmoid function from `ℝ` to `I`. -/ noncomputable def sigmoid : ℝ β†’ I := Subtype.coind Real.sigmoid (fun _ ↦ ⟨by bound, by bound⟩) @[bound] lemma sigmoid_pos (x : ℝ) : 0 < sigmoid x := Real.sigmoid_pos x @[bound] lemma sigmoid_lt_one (x : ℝ) : sigmoid x < 1 := Real.sigmoid_lt_one x @[mono] lemma sigmoid_strictMono : StrictMono sigmoid := Real.sigmoid_strictMono lemma sigmoid_le_iff {a b : ℝ} : sigmoid a ≀ sigmoid b ↔ a ≀ b := Real.sigmoid_le_iff @[gcongr] lemma sigmoid_le {a b : ℝ} : a ≀ b β†’ sigmoid a ≀ sigmoid b := sigmoid_le_iff.mpr lemma sigmoid_lt_iff {a b : ℝ} : sigmoid a < sigmoid b ↔ a < b := Real.sigmoid_lt_iff @[gcongr] lemma sigmoid_lt {a b : ℝ} : a < b β†’ sigmoid a < sigmoid b := sigmoid_lt_iff.mpr @[mono] lemma sigmoid_monotone : Monotone sigmoid := sigmoid_strictMono.monotone lemma sigmoid_injective : Function.Injective sigmoid := sigmoid_strictMono.injective @[simp] lemma sigmoid_inj {a b : ℝ} : sigmoid a = sigmoid b ↔ a = b := sigmoid_injective.eq_iff @[fun_prop] lemma continuous_sigmoid : Continuous sigmoid := _root_.continuous_sigmoid.subtype_mk _ lemma sigmoid_neg (x : ℝ) : sigmoid (-x) = Οƒ (sigmoid x) := by ext exact Real.sigmoid_neg x open Set in lemma range_sigmoid : range unitInterval.sigmoid = Ioo 0 1 := by rw [sigmoid, Subtype.range_coind, Real.range_sigmoid] ext simp open Topology Filter lemma tendsto_sigmoid_atTop : Tendsto sigmoid atTop (𝓝 1) := tendsto_subtype_rng.mpr Real.tendsto_sigmoid_atTop lemma tendsto_sigmoid_atBot : Tendsto sigmoid atBot (𝓝 0) := tendsto_subtype_rng.mpr Real.tendsto_sigmoid_atBot end unitInterval section Embedding open unitInterval Function Set /-- The Sigmoid function as an `OrderEmbedding` from `ℝ` to `I`. -/ noncomputable def OrderEmbedding.sigmoid : ℝ β†ͺo I := OrderEmbedding.ofStrictMono unitInterval.sigmoid unitInterval.sigmoid_strictMono lemma Topology.isEmbedding_sigmoid : IsEmbedding unitInterval.sigmoid := OrderEmbedding.sigmoid.isEmbedding_of_ordConnected (ordConnected_of_Ioo <| fun a _ b _ _ => unitInterval.range_sigmoid β–Έ Ioo_subset_Ioo a.2.1 b.2.2) lemma measurableEmbedding_sigmoid : MeasurableEmbedding unitInterval.sigmoid := Topology.isEmbedding_sigmoid.measurableEmbedding <| unitInterval.range_sigmoid β–Έ measurableSet_Ioo variable (Ξ± : Type*) [MeasurableSpace Ξ±] [StandardBorelSpace Ξ±] lemma measurableEmbedding_sigmoid_comp_embeddingReal : MeasurableEmbedding (unitInterval.sigmoid ∘ MeasureTheory.embeddingReal Ξ±) := measurableEmbedding_sigmoid.comp (MeasureTheory.measurableEmbedding_embeddingReal Ξ±) end Embedding
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/JapaneseBracket.lean
import Mathlib.Analysis.SpecialFunctions.Integrability.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.MeasureTheory.Integral.Layercake /-! # Japanese Bracket In this file, we show that Japanese bracket $(1 + \|x\|^2)^{1/2}$ can be estimated from above and below by $1 + \|x\|$. The functions $(1 + \|x\|^2)^{-r/2}$ and $(1 + |x|)^{-r}$ are integrable provided that `r` is larger than the dimension. ## Main statements * `integrable_one_add_norm`: the function $(1 + |x|)^{-r}$ is integrable * `integrable_jap` the Japanese bracket is integrable -/ noncomputable section open scoped NNReal Filter Topology ENNReal open Asymptotics Filter Set Real MeasureTheory Module variable {E : Type*} [NormedAddCommGroup E] theorem sqrt_one_add_norm_sq_le (x : E) : √((1 : ℝ) + β€–xβ€– ^ 2) ≀ 1 + β€–xβ€– := by rw [sqrt_le_left (by positivity)] simp [add_sq] theorem one_add_norm_le_sqrt_two_mul_sqrt (x : E) : (1 : ℝ) + β€–xβ€– ≀ √2 * √(1 + β€–xβ€– ^ 2) := by rw [← sqrt_mul zero_le_two] have := sq_nonneg (β€–xβ€– - 1) apply le_sqrt_of_sq_le linarith theorem rpow_neg_one_add_norm_sq_le {r : ℝ} (x : E) (hr : 0 < r) : ((1 : ℝ) + β€–xβ€– ^ 2) ^ (-r / 2) ≀ (2 : ℝ) ^ (r / 2) * (1 + β€–xβ€–) ^ (-r) := calc ((1 : ℝ) + β€–xβ€– ^ 2) ^ (-r / 2) = (2 : ℝ) ^ (r / 2) * ((√2 * √((1 : ℝ) + β€–xβ€– ^ 2)) ^ r)⁻¹ := by rw [rpow_div_two_eq_sqrt, rpow_div_two_eq_sqrt, mul_rpow, mul_inv, rpow_neg, mul_inv_cancel_leftβ‚€] <;> positivity _ ≀ (2 : ℝ) ^ (r / 2) * ((1 + β€–xβ€–) ^ r)⁻¹ := by gcongr apply one_add_norm_le_sqrt_two_mul_sqrt _ = (2 : ℝ) ^ (r / 2) * (1 + β€–xβ€–) ^ (-r) := by rw [rpow_neg]; positivity theorem le_rpow_one_add_norm_iff_norm_le {r t : ℝ} (hr : 0 < r) (ht : 0 < t) (x : E) : t ≀ (1 + β€–xβ€–) ^ (-r) ↔ β€–xβ€– ≀ t ^ (-r⁻¹) - 1 := by rw [le_sub_iff_add_le', neg_inv] exact (Real.le_rpow_inv_iff_of_neg (by positivity) ht (neg_lt_zero.mpr hr)).symm variable (E) theorem closedBall_rpow_sub_one_eq_empty_aux {r t : ℝ} (hr : 0 < r) (ht : 1 < t) : Metric.closedBall (0 : E) (t ^ (-r⁻¹) - 1) = βˆ… := by rw [Metric.closedBall_eq_empty, sub_neg] exact Real.rpow_lt_one_of_one_lt_of_neg ht (by simp only [hr, Right.neg_neg_iff, inv_pos]) variable [NormedSpace ℝ E] [FiniteDimensional ℝ E] variable {E} theorem finite_integral_rpow_sub_one_pow_aux {r : ℝ} (n : β„•) (hnr : (n : ℝ) < r) : (∫⁻ x : ℝ in Ioc 0 1, ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n)) < ∞ := by have hr : 0 < r := lt_of_le_of_lt n.cast_nonneg hnr have h_int x (hx : x ∈ Ioc (0 : ℝ) 1) := by calc ENNReal.ofReal ((x ^ (-r⁻¹) - 1) ^ n) ≀ .ofReal ((x ^ (-r⁻¹) - 0) ^ n) := by gcongr Β· rw [sub_nonneg] exact Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx.1 hx.2 (by simpa using hr.le) Β· simp _ = .ofReal (x ^ (-(r⁻¹ * n))) := by simp [rpow_mul hx.1.le, ← neg_mul] refine lt_of_le_of_lt (setLIntegral_mono' measurableSet_Ioc h_int) ?_ refine IntegrableOn.setLIntegral_lt_top ?_ rw [← intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] apply intervalIntegral.intervalIntegrable_rpow' rwa [neg_lt_neg_iff, inv_mul_lt_iffβ‚€' hr, one_mul] variable [MeasurableSpace E] [BorelSpace E] {ΞΌ : Measure E} [ΞΌ.IsAddHaarMeasure] theorem finite_integral_one_add_norm {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : (∫⁻ x : E, ENNReal.ofReal ((1 + β€–xβ€–) ^ (-r)) βˆ‚ΞΌ) < ∞ := by have hr : 0 < r := lt_of_le_of_lt (finrank ℝ E).cast_nonneg hnr -- We start by applying the layer cake formula have h_meas : Measurable fun Ο‰ : E => (1 + β€–Ο‰β€–) ^ (-r) := by fun_prop have h_pos : βˆ€ x : E, 0 ≀ (1 + β€–xβ€–) ^ (-r) := fun x ↦ by positivity rw [lintegral_eq_lintegral_meas_le ΞΌ (Eventually.of_forall h_pos) h_meas.aemeasurable] have h_int : βˆ€ t, 0 < t β†’ ΞΌ {a : E | t ≀ (1 + β€–aβ€–) ^ (-r)} = ΞΌ (Metric.closedBall (0 : E) (t ^ (-r⁻¹) - 1)) := fun t ht ↦ by congr 1 ext x simp only [mem_setOf_eq, mem_closedBall_zero_iff] exact le_rpow_one_add_norm_iff_norm_le hr (mem_Ioi.mp ht) x rw [setLIntegral_congr_fun measurableSet_Ioi h_int] set f := fun t : ℝ ↦ ΞΌ (Metric.closedBall (0 : E) (t ^ (-r⁻¹) - 1)) set mB := ΞΌ (Metric.ball (0 : E) 1) -- the next two inequalities are in fact equalities but we don't need that calc ∫⁻ t in Ioi 0, f t ≀ ∫⁻ t in Ioc 0 1 βˆͺ Ioi 1, f t := lintegral_mono_set Ioi_subset_Ioc_union_Ioi _ ≀ (∫⁻ t in Ioc 0 1, f t) + ∫⁻ t in Ioi 1, f t := lintegral_union_le _ _ _ _ < ∞ := ENNReal.add_lt_top.2 ⟨?_, ?_⟩ Β· -- We use estimates from auxiliary lemmas to deal with integral from `0` to `1` have h_int' : βˆ€ t ∈ Ioc (0 : ℝ) 1, f t = ENNReal.ofReal ((t ^ (-r⁻¹) - 1) ^ finrank ℝ E) * mB := fun t ht ↦ by refine ΞΌ.addHaar_closedBall (0 : E) ?_ rw [sub_nonneg] exact Real.one_le_rpow_of_pos_of_le_one_of_nonpos ht.1 ht.2 (by simp [hr.le]) rw [setLIntegral_congr_fun measurableSet_Ioc h_int', lintegral_mul_const' _ _ measure_ball_lt_top.ne] exact ENNReal.mul_lt_top (finite_integral_rpow_sub_one_pow_aux (finrank ℝ E) hnr) measure_ball_lt_top Β· -- The integral from 1 to ∞ is zero: have h_int'' : βˆ€ t ∈ Ioi (1 : ℝ), f t = 0 := fun t ht => by simp only [f, closedBall_rpow_sub_one_eq_empty_aux E hr ht, measure_empty] -- The integral over the constant zero function is finite: rw [setLIntegral_congr_fun measurableSet_Ioi h_int'', lintegral_const 0, zero_mul] exact WithTop.top_pos theorem integrable_one_add_norm {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : Integrable (fun x ↦ (1 + β€–xβ€–) ^ (-r)) ΞΌ := by constructor Β· apply Measurable.aestronglyMeasurable (by fun_prop) -- Lower Lebesgue integral have : (∫⁻ a : E, β€–(1 + β€–aβ€–) ^ (-r)β€–β‚‘ βˆ‚ΞΌ) = ∫⁻ a : E, ENNReal.ofReal ((1 + β€–aβ€–) ^ (-r)) βˆ‚ΞΌ := lintegral_enorm_of_nonneg fun _ => rpow_nonneg (by positivity) _ rw [hasFiniteIntegral_iff_enorm, this] exact finite_integral_one_add_norm hnr theorem integrable_rpow_neg_one_add_norm_sq {r : ℝ} (hnr : (finrank ℝ E : ℝ) < r) : Integrable (fun x ↦ ((1 : ℝ) + β€–xβ€– ^ 2) ^ (-r / 2)) ΞΌ := by have hr : 0 < r := lt_of_le_of_lt (finrank ℝ E).cast_nonneg hnr refine ((integrable_one_add_norm hnr).const_mul <| (2 : ℝ) ^ (r / 2)).mono' ?_ (Eventually.of_forall fun x => ?_) Β· apply Measurable.aestronglyMeasurable (by fun_prop) refine (abs_of_pos ?_).trans_le (rpow_neg_one_add_norm_sq_le x hr) positivity
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/PolarCoord.lean
import Mathlib.MeasureTheory.Function.Jacobian import Mathlib.MeasureTheory.Measure.Lebesgue.Complex import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # Polar coordinates We define polar coordinates, as an open partial homeomorphism in `ℝ^2` between `ℝ^2 - (-∞, 0]` and `(0, +∞) Γ— (-Ο€, Ο€)`. Its inverse is given by `(r, ΞΈ) ↦ (r cos ΞΈ, r sin ΞΈ)`. It satisfies the following change of variables formula (see `integral_comp_polarCoord_symm`): `∫ p in polarCoord.target, p.1 β€’ f (polarCoord.symm p) = ∫ p, f p` -/ noncomputable section Real open Real Set MeasureTheory open scoped ENNReal Real Topology /-- The polar coordinates open partial homeomorphism in `ℝ^2`, mapping `(r cos ΞΈ, r sin ΞΈ)` to `(r, ΞΈ)`. It is a homeomorphism between `ℝ^2 - (-∞, 0]` and `(0, +∞) Γ— (-Ο€, Ο€)`. -/ @[simps] def polarCoord : OpenPartialHomeomorph (ℝ Γ— ℝ) (ℝ Γ— ℝ) where toFun q := (√(q.1 ^ 2 + q.2 ^ 2), Complex.arg (Complex.equivRealProd.symm q)) invFun p := (p.1 * cos p.2, p.1 * sin p.2) source := {q | 0 < q.1} βˆͺ {q | q.2 β‰  0} target := Ioi (0 : ℝ) Γ—Λ’ Ioo (-Ο€) Ο€ map_target' := by rintro ⟨r, θ⟩ ⟨hr, hθ⟩ dsimp at hr hΞΈ rcases eq_or_ne ΞΈ 0 with (rfl | h'ΞΈ) Β· simpa using hr Β· right simp at hr simpa only [ne_of_gt hr, Ne, mem_setOf_eq, mul_eq_zero, false_or, sin_eq_zero_iff_of_lt_of_lt hΞΈ.1 hΞΈ.2] using h'ΞΈ map_source' := by rintro ⟨x, y⟩ hxy simp only [prodMk_mem_set_prod_eq, mem_Ioi, sqrt_pos, mem_Ioo, Complex.neg_pi_lt_arg, true_and, Complex.arg_lt_pi_iff] constructor Β· rcases hxy with hxy | hxy Β· dsimp at hxy; linarith [sq_pos_of_ne_zero hxy.ne', sq_nonneg y] Β· linarith [sq_nonneg x, sq_pos_of_ne_zero hxy] Β· rcases hxy with hxy | hxy Β· exact Or.inl (le_of_lt hxy) Β· exact Or.inr hxy right_inv' := by rintro ⟨r, θ⟩ ⟨hr, hθ⟩ ext <;> dsimp at hr hΞΈ ⊒ Β· conv_rhs => rw [← sqrt_sq (le_of_lt hr), ← one_mul (r ^ 2), ← sin_sq_add_cos_sq ΞΈ] congr 1 ring Β· convert Complex.arg_mul_cos_add_sin_mul_I hr ⟨hΞΈ.1, hΞΈ.2.le⟩ simp only [Complex.equivRealProd_symm_apply, Complex.ofReal_mul, Complex.ofReal_cos, Complex.ofReal_sin] ring left_inv' := by rintro ⟨x, y⟩ _ have A : √(x ^ 2 + y ^ 2) = β€–x + y * Complex.Iβ€– := by rw [Complex.norm_def, Complex.normSq_add_mul_I] have Z := Complex.norm_mul_cos_add_sin_mul_I (x + y * Complex.I) simp only [← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc] at Z simp [A] open_target := isOpen_Ioi.prod isOpen_Ioo open_source := (isOpen_lt continuous_const continuous_fst).union (isOpen_ne_fun continuous_snd continuous_const) continuousOn_invFun := by fun_prop continuousOn_toFun := by refine .prodMk (by fun_prop) ?_ have A : MapsTo Complex.equivRealProd.symm ({q : ℝ Γ— ℝ | 0 < q.1} βˆͺ {q : ℝ Γ— ℝ | q.2 β‰  0}) Complex.slitPlane := by rintro ⟨x, y⟩ hxy; simpa only using hxy refine ContinuousOn.comp (f := Complex.equivRealProd.symm) (g := Complex.arg) (fun z hz => ?_) ?_ A Β· exact (Complex.continuousAt_arg hz).continuousWithinAt Β· exact Complex.equivRealProdCLM.symm.continuous.continuousOn @[fun_prop] theorem continuous_polarCoord_symm : Continuous polarCoord.symm := .prodMk (by fun_prop) (by fun_prop) /-- The derivative of `polarCoord.symm`, see `hasFDerivAt_polarCoord_symm`. -/ def fderivPolarCoordSymm (p : ℝ Γ— ℝ) : ℝ Γ— ℝ β†’L[ℝ] ℝ Γ— ℝ := (Matrix.toLin (.finTwoProd ℝ) (.finTwoProd ℝ) !![cos p.2, -p.1 * sin p.2; sin p.2, p.1 * cos p.2]).toContinuousLinearMap theorem hasFDerivAt_polarCoord_symm (p : ℝ Γ— ℝ) : HasFDerivAt polarCoord.symm (fderivPolarCoordSymm p) p := by unfold fderivPolarCoordSymm rw [Matrix.toLin_finTwoProd_toContinuousLinearMap] convert HasFDerivAt.prodMk (π•œ := ℝ) (hasFDerivAt_fst.mul ((hasDerivAt_cos p.2).comp_hasFDerivAt p hasFDerivAt_snd)) (hasFDerivAt_fst.mul ((hasDerivAt_sin p.2).comp_hasFDerivAt p hasFDerivAt_snd)) using 2 <;> simp [smul_smul, add_comm, neg_mul, smul_neg, neg_smul _ (ContinuousLinearMap.snd ℝ ℝ ℝ)] theorem det_fderivPolarCoordSymm (p : ℝ Γ— ℝ) : (fderivPolarCoordSymm p).det = p.1 := by conv_rhs => rw [← one_mul p.1, ← cos_sq_add_sin_sq p.2] unfold fderivPolarCoordSymm simp only [neg_mul, LinearMap.det_toContinuousLinearMap, LinearMap.det_toLin, Matrix.det_fin_two_of, sub_neg_eq_add] ring /-- This instance is required to see through the defeq `volume = volume.prod volume`. -/ instance : Measure.IsAddHaarMeasure volume (G := ℝ Γ— ℝ) := Measure.prod.instIsAddHaarMeasure _ _ theorem polarCoord_source_ae_eq_univ : polarCoord.source =ᡐ[volume] univ := by have A : polarCoord.sourceᢜ βŠ† LinearMap.ker (LinearMap.snd ℝ ℝ ℝ) := by intro x hx simp only [polarCoord_source, compl_union, mem_inter_iff, mem_compl_iff, mem_setOf_eq, not_lt, Classical.not_not] at hx exact hx.2 have B : volume (LinearMap.ker (LinearMap.snd ℝ ℝ ℝ) : Set (ℝ Γ— ℝ)) = 0 := by apply Measure.addHaar_submodule rw [Ne, LinearMap.ker_eq_top] intro h have : (LinearMap.snd ℝ ℝ ℝ) (0, 1) = (0 : ℝ Γ— ℝ β†’β‚—[ℝ] ℝ) (0, 1) := by rw [h] simp at this simp only [ae_eq_univ] exact le_antisymm ((measure_mono A).trans (le_of_eq B)) bot_le theorem integral_comp_polarCoord_symm {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : ℝ Γ— ℝ β†’ E) : (∫ p in polarCoord.target, p.1 β€’ f (polarCoord.symm p)) = ∫ p, f p := by symm calc ∫ p, f p = ∫ p in polarCoord.source, f p := by rw [← setIntegral_univ] apply setIntegral_congr_set exact polarCoord_source_ae_eq_univ.symm _ = ∫ p in polarCoord.target, |p.1| β€’ f (polarCoord.symm p) := by rw [← OpenPartialHomeomorph.symm_target, integral_target_eq_integral_abs_det_fderiv_smul volume (fun p _ ↦ hasFDerivAt_polarCoord_symm p), OpenPartialHomeomorph.symm_source] simp_rw [det_fderivPolarCoordSymm] _ = ∫ p in polarCoord.target, p.1 β€’ f (polarCoord.symm p) := by apply setIntegral_congr_fun polarCoord.open_target.measurableSet fun x hx => ?_ rw [abs_of_pos hx.1] theorem lintegral_comp_polarCoord_symm (f : ℝ Γ— ℝ β†’ ℝβ‰₯0∞) : ∫⁻ (p : ℝ Γ— ℝ) in polarCoord.target, ENNReal.ofReal p.1 β€’ f (polarCoord.symm p) = ∫⁻ (p : ℝ Γ— ℝ), f p := by symm calc _ = ∫⁻ p in polarCoord.symm '' polarCoord.target, f p := by rw [← setLIntegral_univ, setLIntegral_congr polarCoord_source_ae_eq_univ.symm, polarCoord.symm_image_target_eq_source ] _ = ∫⁻ (p : ℝ Γ— ℝ) in polarCoord.target, ENNReal.ofReal |p.1| β€’ f (polarCoord.symm p) := by rw [lintegral_image_eq_lintegral_abs_det_fderiv_mul volume _ (fun p _ ↦ (hasFDerivAt_polarCoord_symm p).hasFDerivWithinAt)] Β· simp_rw [det_fderivPolarCoordSymm]; rfl exacts [polarCoord.symm.injOn, measurableSet_Ioi.prod measurableSet_Ioo] _ = ∫⁻ (p : ℝ Γ— ℝ) in polarCoord.target, ENNReal.ofReal p.1 β€’ f (polarCoord.symm p) := by refine setLIntegral_congr_fun polarCoord.open_target.measurableSet (fun x hx ↦ ?_) rw [abs_of_pos hx.1] end Real noncomputable section Complex namespace Complex open scoped Real ENNReal /-- The polar coordinates open partial homeomorphism in `β„‚`, mapping `r (cos ΞΈ + I * sin ΞΈ)` to `(r, ΞΈ)`. It is a homeomorphism between `β„‚ - ℝ≀0` and `(0, +∞) Γ— (-Ο€, Ο€)`. -/ protected noncomputable def polarCoord : OpenPartialHomeomorph β„‚ (ℝ Γ— ℝ) := equivRealProdCLM.toHomeomorph.transOpenPartialHomeomorph polarCoord protected theorem polarCoord_apply (a : β„‚) : Complex.polarCoord a = (β€–aβ€–, Complex.arg a) := by simp_rw [Complex.norm_def, Complex.normSq_apply, ← pow_two] rfl protected theorem polarCoord_source : Complex.polarCoord.source = slitPlane := rfl protected theorem polarCoord_target : Complex.polarCoord.target = Set.Ioi (0 : ℝ) Γ—Λ’ Set.Ioo (-Ο€) Ο€ := rfl @[simp] protected theorem polarCoord_symm_apply (p : ℝ Γ— ℝ) : Complex.polarCoord.symm p = p.1 * (Real.cos p.2 + Real.sin p.2 * Complex.I) := by simp [Complex.polarCoord, equivRealProdCLM_symm_apply, mul_add, mul_assoc] theorem measurableEquivRealProd_symm_polarCoord_symm_apply (p : ℝ Γ— ℝ) : (measurableEquivRealProd.symm (polarCoord.symm p)) = Complex.polarCoord.symm p := rfl theorem norm_polarCoord_symm (p : ℝ Γ— ℝ) : β€–Complex.polarCoord.symm pβ€– = |p.1| := by simp protected theorem integral_comp_polarCoord_symm {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : β„‚ β†’ E) : (∫ p in polarCoord.target, p.1 β€’ f (Complex.polarCoord.symm p)) = ∫ p, f p := by rw [← (Complex.volume_preserving_equiv_real_prod.symm).integral_comp measurableEquivRealProd.symm.measurableEmbedding, ← integral_comp_polarCoord_symm] simp_rw [measurableEquivRealProd_symm_polarCoord_symm_apply] protected theorem lintegral_comp_polarCoord_symm (f : β„‚ β†’ ℝβ‰₯0∞) : (∫⁻ p in polarCoord.target, ENNReal.ofReal p.1 β€’ f (Complex.polarCoord.symm p)) = ∫⁻ p, f p := by rw [← (volume_preserving_equiv_real_prod.symm).lintegral_comp_emb measurableEquivRealProd.symm.measurableEmbedding, ← lintegral_comp_polarCoord_symm] simp_rw [measurableEquivRealProd_symm_polarCoord_symm_apply] end Complex section Pi open ENNReal MeasureTheory MeasureTheory.Measure variable {ΞΉ : Type*} open ContinuousLinearMap in /-- The derivative of `polarCoord.symm` on `ΞΉ β†’ ℝ Γ— ℝ`, see `hasFDerivAt_pi_polarCoord_symm`. -/ noncomputable def fderivPiPolarCoordSymm (p : ΞΉ β†’ ℝ Γ— ℝ) : (ΞΉ β†’ ℝ Γ— ℝ) β†’L[ℝ] ΞΉ β†’ ℝ Γ— ℝ := pi fun i ↦ (fderivPolarCoordSymm (p i)).comp (proj i) theorem injOn_pi_polarCoord_symm : Set.InjOn (fun p (i : ΞΉ) ↦ polarCoord.symm (p i)) (Set.univ.pi fun _ ↦ polarCoord.target) := fun _ hx _ hy h ↦ funext fun i ↦ polarCoord.symm.injOn (hx i trivial) (hy i trivial) ((funext_iff.mp h) i) theorem abs_fst_of_mem_pi_polarCoord_target {p : ΞΉ β†’ ℝ Γ— ℝ} (hp : p ∈ (Set.univ.pi fun _ : ΞΉ ↦ polarCoord.target)) (i : ΞΉ) : |(p i).1| = (p i).1 := abs_of_pos ((Set.mem_univ_pi.mp hp) i).1 variable [Fintype ΞΉ] theorem hasFDerivAt_pi_polarCoord_symm (p : ΞΉ β†’ ℝ Γ— ℝ) : HasFDerivAt (fun x i ↦ polarCoord.symm (x i)) (fderivPiPolarCoordSymm p) p := by rw [fderivPiPolarCoordSymm, hasFDerivAt_pi] exact fun i ↦ HasFDerivAt.comp _ (hasFDerivAt_polarCoord_symm _) (hasFDerivAt_apply i _) theorem det_fderivPiPolarCoordSymm (p : ΞΉ β†’ ℝ Γ— ℝ) : (fderivPiPolarCoordSymm p).det = ∏ i, (p i).1 := by simp_rw [fderivPiPolarCoordSymm, ContinuousLinearMap.det_pi, det_fderivPolarCoordSymm] theorem pi_polarCoord_symm_target_ae_eq_univ : (Pi.map (fun _ : ΞΉ ↦ polarCoord.symm) '' Set.univ.pi fun _ ↦ polarCoord.target) =ᡐ[volume] Set.univ := by rw [Set.piMap_image_univ_pi, polarCoord.symm_image_target_eq_source, volume_pi, ← Set.pi_univ] exact ae_eq_set_pi fun _ _ ↦ polarCoord_source_ae_eq_univ theorem measurableSet_pi_polarCoord_target : MeasurableSet (Set.univ.pi fun _ : ΞΉ ↦ polarCoord.target) := MeasurableSet.univ_pi fun _ ↦ polarCoord.open_target.measurableSet theorem integral_comp_pi_polarCoord_symm {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : (ΞΉ β†’ ℝ Γ— ℝ) β†’ E) : (∫ p in (Set.univ.pi fun _ : ΞΉ ↦ polarCoord.target), (∏ i, (p i).1) β€’ f (fun i ↦ polarCoord.symm (p i))) = ∫ p, f p := by rw [← setIntegral_univ (f := f), ← setIntegral_congr_set pi_polarCoord_symm_target_ae_eq_univ] convert (integral_image_eq_integral_abs_det_fderiv_smul volume measurableSet_pi_polarCoord_target (fun p _ ↦ (hasFDerivAt_pi_polarCoord_symm p).hasFDerivWithinAt) injOn_pi_polarCoord_symm f).symm using 1 refine setIntegral_congr_fun measurableSet_pi_polarCoord_target fun x hx ↦ ?_ simp_rw [det_fderivPiPolarCoordSymm, Finset.abs_prod, abs_fst_of_mem_pi_polarCoord_target hx] protected theorem Complex.integral_comp_pi_polarCoord_symm {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] (f : (ΞΉ β†’ β„‚) β†’ E) : (∫ p in (Set.univ.pi fun _ : ΞΉ ↦ Complex.polarCoord.target), (∏ i, (p i).1) β€’ f (fun i ↦ Complex.polarCoord.symm (p i))) = ∫ p, f p := by let e := MeasurableEquiv.piCongrRight (fun _ : ΞΉ ↦ measurableEquivRealProd.symm) have := volume_preserving_pi (fun _ : ΞΉ ↦ Complex.volume_preserving_equiv_real_prod.symm) rw [← MeasurePreserving.integral_comp this e.measurableEmbedding f] exact integral_comp_pi_polarCoord_symm (f ∘ e) theorem lintegral_comp_pi_polarCoord_symm (f : (ΞΉ β†’ ℝ Γ— ℝ) β†’ ℝβ‰₯0∞) : ∫⁻ p in (Set.univ.pi fun _ : ΞΉ ↦ polarCoord.target), (∏ i, .ofReal (p i).1) * f (fun i ↦ polarCoord.symm (p i)) = ∫⁻ p, f p := by rw [← setLIntegral_univ f, ← setLIntegral_congr pi_polarCoord_symm_target_ae_eq_univ] convert (lintegral_image_eq_lintegral_abs_det_fderiv_mul volume measurableSet_pi_polarCoord_target (fun p _ ↦ (hasFDerivAt_pi_polarCoord_symm p).hasFDerivWithinAt) injOn_pi_polarCoord_symm f).symm using 1 refine setLIntegral_congr_fun measurableSet_pi_polarCoord_target (fun x hx ↦ ?_) simp_rw [det_fderivPiPolarCoordSymm, Finset.abs_prod, ENNReal.ofReal_prod_of_nonneg (fun _ _ ↦ abs_nonneg _), abs_fst_of_mem_pi_polarCoord_target hx] protected theorem Complex.lintegral_comp_pi_polarCoord_symm (f : (ΞΉ β†’ β„‚) β†’ ℝβ‰₯0∞) : ∫⁻ p in (Set.univ.pi fun _ : ΞΉ ↦ Complex.polarCoord.target), (∏ i, .ofReal (p i).1) * f (fun i ↦ Complex.polarCoord.symm (p i)) = ∫⁻ p, f p := by let e := MeasurableEquiv.piCongrRight (fun _ : ΞΉ ↦ measurableEquivRealProd.symm) have := volume_preserving_pi (fun _ : ΞΉ ↦ Complex.volume_preserving_equiv_real_prod.symm) rw [← MeasurePreserving.lintegral_comp_emb this e.measurableEmbedding] exact lintegral_comp_pi_polarCoord_symm (f ∘ e) end Pi
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/CompareExp.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Asymptotics import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.Asymptotics.SpecificAsymptotics /-! # Growth estimates on `x ^ y` for complex `x`, `y` Let `l` be a filter on `β„‚` such that `Complex.re` tends to infinity along `l` and `Complex.im z` grows at a subexponential rate compared to `Complex.re z`. Then - `Complex.isLittleO_log_abs_re`: `Real.log ∘ Complex.abs` is `o`-small of `Complex.re` along `l`; - `Complex.isLittleO_cpow_mul_exp`: $z^{a_1}e^{b_1 * z} = o\left(z^{a_1}e^{b_1 * z}\right)$ along `l` for any complex `a₁`, `aβ‚‚` and real `b₁ < bβ‚‚`. We use these assumptions on `l` for two reasons. First, these are the assumptions that naturally appear in the proof. Second, in some applications (e.g., in Ilyashenko's proof of the individual finiteness theorem for limit cycles of polynomial ODEs with hyperbolic singularities only) natural stronger assumptions (e.g., `im z` is bounded from below and from above) are not available. -/ open Asymptotics Filter Function open scoped Topology namespace Complex /-- We say that `l : Filter β„‚` is an *exponential comparison filter* if the real part tends to infinity along `l` and the imaginary part grows subexponentially compared to the real part. These properties guarantee that `(fun z ↦ z ^ a₁ * exp (b₁ * z)) =o[l] (fun z ↦ z ^ aβ‚‚ * exp (bβ‚‚ * z))` for any complex `a₁`, `aβ‚‚` and real `b₁ < bβ‚‚`. In particular, the second property is automatically satisfied if the imaginary part is bounded along `l`. -/ structure IsExpCmpFilter (l : Filter β„‚) : Prop where tendsto_re : Tendsto re l atTop isBigO_im_pow_re : βˆ€ n : β„•, (fun z : β„‚ => z.im ^ n) =O[l] fun z => Real.exp z.re namespace IsExpCmpFilter variable {l : Filter β„‚} /-! ### Alternative constructors -/ theorem of_isBigO_im_re_rpow (hre : Tendsto re l atTop) (r : ℝ) (hr : im =O[l] fun z => z.re ^ r) : IsExpCmpFilter l := ⟨hre, fun n => IsLittleO.isBigO <| calc (fun z : β„‚ => z.im ^ n) =O[l] fun z => (z.re ^ r) ^ n := hr.pow n _ =αΆ [l] fun z => z.re ^ (r * n) := ((hre.eventually_ge_atTop 0).mono fun z hz => by simp only [Real.rpow_mul hz r n, Real.rpow_natCast]) _ =o[l] fun z => Real.exp z.re := (isLittleO_rpow_exp_atTop _).comp_tendsto hre ⟩ theorem of_isBigO_im_re_pow (hre : Tendsto re l atTop) (n : β„•) (hr : im =O[l] fun z => z.re ^ n) : IsExpCmpFilter l := of_isBigO_im_re_rpow hre n <| mod_cast hr theorem of_boundedUnder_abs_im (hre : Tendsto re l atTop) (him : IsBoundedUnder (Β· ≀ Β·) l fun z => |z.im|) : IsExpCmpFilter l := of_isBigO_im_re_pow hre 0 <| by simpa only [pow_zero] using him.isBigO_const (f := im) one_ne_zero theorem of_boundedUnder_im (hre : Tendsto re l atTop) (him_le : IsBoundedUnder (Β· ≀ Β·) l im) (him_ge : IsBoundedUnder (Β· β‰₯ Β·) l im) : IsExpCmpFilter l := of_boundedUnder_abs_im hre <| isBoundedUnder_le_abs.2 ⟨him_le, him_ge⟩ /-! ### Preliminary lemmas -/ theorem eventually_ne (hl : IsExpCmpFilter l) : βˆ€αΆ  w : β„‚ in l, w β‰  0 := hl.tendsto_re.eventually_ne_atTop' _ theorem tendsto_abs_re (hl : IsExpCmpFilter l) : Tendsto (fun z : β„‚ => |z.re|) l atTop := tendsto_abs_atTop_atTop.comp hl.tendsto_re theorem tendsto_norm (hl : IsExpCmpFilter l) : Tendsto norm l atTop := tendsto_atTop_mono abs_re_le_norm hl.tendsto_abs_re theorem isLittleO_log_re_re (hl : IsExpCmpFilter l) : (fun z => Real.log z.re) =o[l] re := Real.isLittleO_log_id_atTop.comp_tendsto hl.tendsto_re theorem isLittleO_im_pow_exp_re (hl : IsExpCmpFilter l) (n : β„•) : (fun z : β„‚ => z.im ^ n) =o[l] fun z => Real.exp z.re := flip IsLittleO.of_pow two_ne_zero <| calc (fun z : β„‚ ↦ (z.im ^ n) ^ 2) = (fun z ↦ z.im ^ (2 * n)) := by simp only [pow_mul'] _ =O[l] fun z ↦ Real.exp z.re := hl.isBigO_im_pow_re _ _ = fun z ↦ (Real.exp z.re) ^ 1 := by simp only [pow_one] _ =o[l] fun z ↦ (Real.exp z.re) ^ 2 := (isLittleO_pow_pow_atTop_of_lt one_lt_two).comp_tendsto <| Real.tendsto_exp_atTop.comp hl.tendsto_re theorem abs_im_pow_eventuallyLE_exp_re (hl : IsExpCmpFilter l) (n : β„•) : (fun z : β„‚ => |z.im| ^ n) ≀ᢠ[l] fun z => Real.exp z.re := by simpa using (hl.isLittleO_im_pow_exp_re n).bound zero_lt_one /-- If `l : Filter β„‚` is an "exponential comparison filter", then $\log |z| =o(β„œ z)$ along `l`. This is the main lemma in the proof of `Complex.IsExpCmpFilter.isLittleO_cpow_exp` below. -/ theorem isLittleO_log_norm_re (hl : IsExpCmpFilter l) : (fun z => Real.log β€–zβ€–) =o[l] re := calc (fun z => Real.log β€–zβ€–) =O[l] fun z => Real.log (√2) + Real.log (max z.re |z.im|) := .of_norm_eventuallyLE <| (hl.tendsto_re.eventually_ge_atTop 1).mono fun z hz => by have h2 : 0 < √2 := by simp have hz' : 1 ≀ β€–zβ€– := hz.trans (re_le_norm z) have hmβ‚€ : 0 < max z.re |z.im| := lt_max_iff.2 (Or.inl <| one_pos.trans_le hz) simp only [Real.norm_of_nonneg (Real.log_nonneg hz')] rw [← Real.log_mul, Real.log_le_log_iff, ← abs_of_nonneg (le_trans zero_le_one hz)] exacts [norm_le_sqrt_two_mul_max z, one_pos.trans_le hz', mul_pos h2 hmβ‚€, h2.ne', hmβ‚€.ne'] _ =o[l] re := IsLittleO.add (isLittleO_const_left.2 <| Or.inr <| hl.tendsto_abs_re) <| isLittleO_iff_nat_mul_le.2 fun n => by filter_upwards [isLittleO_iff_nat_mul_le'.1 hl.isLittleO_log_re_re n, hl.abs_im_pow_eventuallyLE_exp_re n, hl.tendsto_re.eventually_gt_atTop 1] with z hre him h₁ rcases le_total |z.im| z.re with hle | hle Β· rwa [max_eq_left hle] Β· have H : 1 < |z.im| := h₁.trans_le hle norm_cast at * rwa [max_eq_right hle, Real.norm_eq_abs, Real.norm_eq_abs, abs_of_pos (Real.log_pos H), ← Real.log_pow, Real.log_le_iff_le_exp (pow_pos (one_pos.trans H) _), abs_of_pos (one_pos.trans h₁)] /-! ### Main results -/ lemma isTheta_cpow_exp_re_mul_log (hl : IsExpCmpFilter l) (a : β„‚) : (Β· ^ a) =Θ[l] fun z ↦ Real.exp (re a * Real.log β€–zβ€–) := calc (fun z => z ^ a) =Θ[l] (fun z : β„‚ => β€–zβ€– ^ re a) := isTheta_cpow_const_rpow fun _ _ => hl.eventually_ne _ =αΆ [l] fun z => Real.exp (re a * Real.log β€–zβ€–) := (hl.eventually_ne.mono fun z hz => by simp [Real.rpow_def_of_pos, norm_pos_iff.mpr hz, mul_comm]) /-- If `l : Filter β„‚` is an "exponential comparison filter", then for any complex `a` and any positive real `b`, we have `(fun z ↦ z ^ a) =o[l] (fun z ↦ exp (b * z))`. -/ theorem isLittleO_cpow_exp (hl : IsExpCmpFilter l) (a : β„‚) {b : ℝ} (hb : 0 < b) : (fun z => z ^ a) =o[l] fun z => exp (b * z) := calc (fun z => z ^ a) =Θ[l] fun z => Real.exp (re a * Real.log β€–zβ€–) := hl.isTheta_cpow_exp_re_mul_log a _ =o[l] fun z => exp (b * z) := IsLittleO.of_norm_right <| by simp only [norm_exp, re_ofReal_mul, Real.isLittleO_exp_comp_exp_comp] refine (IsEquivalent.refl.sub_isLittleO ?_).symm.tendsto_atTop (hl.tendsto_re.const_mul_atTop hb) exact (hl.isLittleO_log_norm_re.const_mul_left _).const_mul_right hb.ne' /-- If `l : Filter β„‚` is an "exponential comparison filter", then for any complex `a₁`, `aβ‚‚` and any real `b₁ < bβ‚‚`, we have `(fun z ↦ z ^ a₁ * exp (b₁ * z)) =o[l] (fun z ↦ z ^ aβ‚‚ * exp (bβ‚‚ * z))`. -/ theorem isLittleO_cpow_mul_exp {b₁ bβ‚‚ : ℝ} (hl : IsExpCmpFilter l) (hb : b₁ < bβ‚‚) (a₁ aβ‚‚ : β„‚) : (fun z => z ^ a₁ * exp (b₁ * z)) =o[l] fun z => z ^ aβ‚‚ * exp (bβ‚‚ * z) := calc (fun z => z ^ a₁ * exp (b₁ * z)) =αΆ [l] fun z => z ^ aβ‚‚ * exp (b₁ * z) * z ^ (a₁ - aβ‚‚) := hl.eventually_ne.mono fun z hz => by simp only rw [mul_right_comm, ← cpow_add _ _ hz, add_sub_cancel] _ =o[l] fun z => z ^ aβ‚‚ * exp (b₁ * z) * exp (↑(bβ‚‚ - b₁) * z) := ((isBigO_refl (fun z => z ^ aβ‚‚ * exp (b₁ * z)) l).mul_isLittleO <| hl.isLittleO_cpow_exp _ (sub_pos.2 hb)) _ =αΆ [l] fun z => z ^ aβ‚‚ * exp (bβ‚‚ * z) := by simp only [ofReal_sub, sub_mul, mul_assoc, ← exp_add, add_sub_cancel] norm_cast /-- If `l : Filter β„‚` is an "exponential comparison filter", then for any complex `a` and any negative real `b`, we have `(fun z ↦ exp (b * z)) =o[l] (fun z ↦ z ^ a)`. -/ theorem isLittleO_exp_cpow (hl : IsExpCmpFilter l) (a : β„‚) {b : ℝ} (hb : b < 0) : (fun z => exp (b * z)) =o[l] fun z => z ^ a := by simpa using hl.isLittleO_cpow_mul_exp hb 0 a /-- If `l : Filter β„‚` is an "exponential comparison filter", then for any complex `a₁`, `aβ‚‚` and any natural `b₁ < bβ‚‚`, we have `(fun z ↦ z ^ a₁ * exp (b₁ * z)) =o[l] (fun z ↦ z ^ aβ‚‚ * exp (bβ‚‚ * z))`. -/ theorem isLittleO_pow_mul_exp {b₁ bβ‚‚ : ℝ} (hl : IsExpCmpFilter l) (hb : b₁ < bβ‚‚) (m n : β„•) : (fun z => z ^ m * exp (b₁ * z)) =o[l] fun z => z ^ n * exp (bβ‚‚ * z) := by simpa only [cpow_natCast] using hl.isLittleO_cpow_mul_exp hb m n /-- If `l : Filter β„‚` is an "exponential comparison filter", then for any complex `a₁`, `aβ‚‚` and any integer `b₁ < bβ‚‚`, we have `(fun z ↦ z ^ a₁ * exp (b₁ * z)) =o[l] (fun z ↦ z ^ aβ‚‚ * exp (bβ‚‚ * z))`. -/ theorem isLittleO_zpow_mul_exp {b₁ bβ‚‚ : ℝ} (hl : IsExpCmpFilter l) (hb : b₁ < bβ‚‚) (m n : β„€) : (fun z => z ^ m * exp (b₁ * z)) =o[l] fun z => z ^ n * exp (bβ‚‚ * z) := by simpa only [cpow_intCast] using hl.isLittleO_cpow_mul_exp hb m n end IsExpCmpFilter end Complex
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ExpDeriv.lean
import Mathlib.Analysis.Calculus.ContDiff.RCLike import Mathlib.Analysis.Calculus.IteratedDeriv.Lemmas import Mathlib.Analysis.Complex.RealDeriv import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Analysis.SpecialFunctions.Exponential /-! # Complex and real exponential In this file we prove that `Complex.exp` and `Real.exp` are analytic functions. ## Tags exp, derivative -/ assert_not_exists IsConformalMap Conformal noncomputable section open Filter Asymptotics Set Function open scoped Topology /-! ## `Complex.exp` -/ section open Complex variable {E : Type} [NormedAddCommGroup E] [NormedSpace β„‚ E] variable {f g : E β†’ β„‚} {z : β„‚} {x : E} {s : Set E} /-- The function `Complex.exp` is complex analytic. -/ theorem analyticOnNhd_cexp : AnalyticOnNhd β„‚ exp univ := by rw [Complex.exp_eq_exp_β„‚] exact fun x _ ↦ NormedSpace.exp_analytic x /-- The function `Complex.exp` is complex analytic. -/ theorem analyticOn_cexp : AnalyticOn β„‚ exp univ := analyticOnNhd_cexp.analyticOn /-- The function `Complex.exp` is complex analytic. -/ @[fun_prop] theorem analyticAt_cexp : AnalyticAt β„‚ exp z := analyticOnNhd_cexp z (mem_univ _) /-- The function `Complex.exp` is complex analytic. -/ lemma analyticWithinAt_cexp {s : Set β„‚} {x : β„‚} : AnalyticWithinAt β„‚ Complex.exp s x := by exact analyticAt_cexp.analyticWithinAt /-- `exp ∘ f` is analytic -/ @[fun_prop] theorem AnalyticAt.cexp (fa : AnalyticAt β„‚ f x) : AnalyticAt β„‚ (exp ∘ f) x := analyticAt_cexp.comp fa /-- `exp ∘ f` is analytic -/ @[fun_prop] theorem AnalyticAt.cexp' (fa : AnalyticAt β„‚ f x) : AnalyticAt β„‚ (fun z ↦ exp (f z)) x := fa.cexp theorem AnalyticWithinAt.cexp (fa : AnalyticWithinAt β„‚ f s x) : AnalyticWithinAt β„‚ (fun z ↦ exp (f z)) s x := analyticAt_cexp.comp_analyticWithinAt fa /-- `exp ∘ f` is analytic -/ theorem AnalyticOnNhd.cexp (fs : AnalyticOnNhd β„‚ f s) : AnalyticOnNhd β„‚ (fun z ↦ exp (f z)) s := fun z n ↦ analyticAt_cexp.comp (fs z n) theorem AnalyticOn.cexp (fs : AnalyticOn β„‚ f s) : AnalyticOn β„‚ (fun z ↦ exp (f z)) s := analyticOnNhd_cexp.comp_analyticOn fs (mapsTo_univ _ _) end namespace Complex variable {π•œ : Type*} [NontriviallyNormedField π•œ] [NormedAlgebra π•œ β„‚] /-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/ theorem hasDerivAt_exp (x : β„‚) : HasDerivAt exp (exp x) x := by rw [hasDerivAt_iff_isLittleO_nhds_zero] have : (1 : β„•) < 2 := by simp refine (IsBigO.of_bound β€–exp xβ€– ?_).trans_isLittleO (isLittleO_pow_id this) filter_upwards [Metric.ball_mem_nhds (0 : β„‚) zero_lt_one] simp only [Metric.mem_ball, dist_zero_right, norm_pow] exact fun z hz => exp_bound_sq x z hz.le @[simp] theorem differentiable_exp : Differentiable π•œ exp := fun x => (hasDerivAt_exp x).differentiableAt.restrictScalars π•œ @[simp] theorem differentiableAt_exp {x : β„‚} : DifferentiableAt π•œ exp x := differentiable_exp x @[simp] theorem deriv_exp : deriv exp = exp := funext fun x => (hasDerivAt_exp x).deriv @[simp] theorem iter_deriv_exp : βˆ€ n : β„•, deriv^[n] exp = exp | 0 => rfl | n + 1 => by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n] @[fun_prop] theorem contDiff_exp {n : WithTop β„•βˆž} : ContDiff π•œ n exp := analyticOnNhd_cexp.restrictScalars.contDiff theorem hasStrictDerivAt_exp (x : β„‚) : HasStrictDerivAt exp (exp x) x := contDiff_exp.contDiffAt.hasStrictDerivAt' (hasDerivAt_exp x) le_rfl theorem hasStrictFDerivAt_exp_real (x : β„‚) : HasStrictFDerivAt exp (exp x β€’ (1 : β„‚ β†’L[ℝ] β„‚)) x := (hasStrictDerivAt_exp x).complexToReal_fderiv end Complex section variable {π•œ : Type*} [NontriviallyNormedField π•œ] [NormedAlgebra π•œ β„‚] {f : π•œ β†’ β„‚} {f' : β„‚} {x : π•œ} {s : Set π•œ} theorem HasStrictDerivAt.cexp (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) * f') x := (Complex.hasStrictDerivAt_exp (f x)).comp x hf theorem HasDerivAt.cexp (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) * f') x := (Complex.hasDerivAt_exp (f x)).comp x hf theorem HasDerivWithinAt.cexp (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.exp (f x)) (Complex.exp (f x) * f') s x := (Complex.hasDerivAt_exp (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_cexp (hf : DifferentiableWithinAt π•œ f s x) (hxs : UniqueDiffWithinAt π•œ s x) : derivWithin (fun x => Complex.exp (f x)) s x = Complex.exp (f x) * derivWithin f s x := hf.hasDerivWithinAt.cexp.derivWithin hxs @[simp] theorem deriv_cexp (hc : DifferentiableAt π•œ f x) : deriv (fun x => Complex.exp (f x)) x = Complex.exp (f x) * deriv f x := hc.hasDerivAt.cexp.deriv end section variable {π•œ : Type*} [NontriviallyNormedField π•œ] [NormedAlgebra π•œ β„‚] {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ β„‚} {f' : E β†’L[π•œ] β„‚} {x : E} {s : Set E} theorem HasStrictFDerivAt.cexp (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) β€’ f') x := (Complex.hasStrictDerivAt_exp (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivWithinAt.cexp (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.exp (f x)) (Complex.exp (f x) β€’ f') s x := (Complex.hasDerivAt_exp (f x)).comp_hasFDerivWithinAt x hf theorem HasFDerivAt.cexp (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) β€’ f') x := hasFDerivWithinAt_univ.1 <| hf.hasFDerivWithinAt.cexp theorem DifferentiableWithinAt.cexp (hf : DifferentiableWithinAt π•œ f s x) : DifferentiableWithinAt π•œ (fun x => Complex.exp (f x)) s x := hf.hasFDerivWithinAt.cexp.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.cexp (hc : DifferentiableAt π•œ f x) : DifferentiableAt π•œ (fun x => Complex.exp (f x)) x := hc.hasFDerivAt.cexp.differentiableAt theorem DifferentiableOn.cexp (hc : DifferentiableOn π•œ f s) : DifferentiableOn π•œ (fun x => Complex.exp (f x)) s := fun x h => (hc x h).cexp @[simp, fun_prop] theorem Differentiable.cexp (hc : Differentiable π•œ f) : Differentiable π•œ fun x => Complex.exp (f x) := fun x => (hc x).cexp @[fun_prop] theorem ContDiff.cexp {n} (h : ContDiff π•œ n f) : ContDiff π•œ n fun x => Complex.exp (f x) := Complex.contDiff_exp.comp h @[fun_prop] theorem ContDiffAt.cexp {n} (hf : ContDiffAt π•œ n f x) : ContDiffAt π•œ n (fun x => Complex.exp (f x)) x := Complex.contDiff_exp.contDiffAt.comp x hf @[fun_prop] theorem ContDiffOn.cexp {n} (hf : ContDiffOn π•œ n f s) : ContDiffOn π•œ n (fun x => Complex.exp (f x)) s := Complex.contDiff_exp.comp_contDiffOn hf @[fun_prop] theorem ContDiffWithinAt.cexp {n} (hf : ContDiffWithinAt π•œ n f s x) : ContDiffWithinAt π•œ n (fun x => Complex.exp (f x)) s x := Complex.contDiff_exp.contDiffAt.comp_contDiffWithinAt x hf end open Complex in @[simp] theorem iteratedDeriv_cexp_const_mul (n : β„•) (c : β„‚) : (iteratedDeriv n fun s : β„‚ => exp (c * s)) = fun s => c ^ n * exp (c * s) := by rw [iteratedDeriv_comp_const_mul contDiff_exp, iteratedDeriv_eq_iterate, iter_deriv_exp] /-! ## `Real.exp` -/ section open Real variable {x : ℝ} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {s : Set E} /-- The function `Real.exp` is real analytic. -/ theorem analyticOnNhd_rexp : AnalyticOnNhd ℝ exp univ := by rw [Real.exp_eq_exp_ℝ] exact fun x _ ↦ NormedSpace.exp_analytic x /-- The function `Real.exp` is real analytic. -/ theorem analyticOn_rexp : AnalyticOn ℝ exp univ := analyticOnNhd_rexp.analyticOn /-- The function `Real.exp` is real analytic. -/ @[fun_prop] theorem analyticAt_rexp : AnalyticAt ℝ exp x := analyticOnNhd_rexp x (mem_univ _) /-- The function `Real.exp` is real analytic. -/ lemma analyticWithinAt_rexp {s : Set ℝ} : AnalyticWithinAt ℝ Real.exp s x := analyticAt_rexp.analyticWithinAt /-- `exp ∘ f` is analytic -/ @[fun_prop] theorem AnalyticAt.rexp {x : E} (fa : AnalyticAt ℝ f x) : AnalyticAt ℝ (exp ∘ f) x := analyticAt_rexp.comp fa /-- `exp ∘ f` is analytic -/ @[fun_prop] theorem AnalyticAt.rexp' {x : E} (fa : AnalyticAt ℝ f x) : AnalyticAt ℝ (fun z ↦ exp (f z)) x := fa.rexp theorem AnalyticWithinAt.rexp {x : E} (fa : AnalyticWithinAt ℝ f s x) : AnalyticWithinAt ℝ (fun z ↦ exp (f z)) s x := analyticAt_rexp.comp_analyticWithinAt fa /-- `exp ∘ f` is analytic -/ theorem AnalyticOnNhd.rexp {s : Set E} (fs : AnalyticOnNhd ℝ f s) : AnalyticOnNhd ℝ (fun z ↦ exp (f z)) s := fun z n ↦ analyticAt_rexp.comp (fs z n) theorem AnalyticOn.rexp (fs : AnalyticOn ℝ f s) : AnalyticOn ℝ (fun z ↦ exp (f z)) s := analyticOnNhd_rexp.comp_analyticOn fs (mapsTo_univ _ _) end namespace Real theorem hasStrictDerivAt_exp (x : ℝ) : HasStrictDerivAt exp (exp x) x := (Complex.hasStrictDerivAt_exp x).real_of_complex theorem hasDerivAt_exp (x : ℝ) : HasDerivAt exp (exp x) x := (Complex.hasDerivAt_exp x).real_of_complex @[fun_prop] theorem contDiff_exp {n : WithTop β„•βˆž} : ContDiff ℝ n exp := Complex.contDiff_exp.real_of_complex @[simp] theorem differentiable_exp : Differentiable ℝ exp := fun x => (hasDerivAt_exp x).differentiableAt @[simp] theorem differentiableAt_exp {x : ℝ} : DifferentiableAt ℝ exp x := differentiable_exp x @[simp] theorem deriv_exp : deriv exp = exp := funext fun x => (hasDerivAt_exp x).deriv @[simp] theorem iter_deriv_exp : βˆ€ n : β„•, deriv^[n] exp = exp | 0 => rfl | n + 1 => by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n] end Real section /-! Register lemmas for the derivatives of the composition of `Real.exp` with a differentiable function, for standalone use and use with `simp`. -/ variable {f : ℝ β†’ ℝ} {f' x : ℝ} {s : Set ℝ} theorem HasStrictDerivAt.exp (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) * f') x := (Real.hasStrictDerivAt_exp (f x)).comp x hf theorem HasDerivAt.exp (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) * f') x := (Real.hasDerivAt_exp (f x)).comp x hf theorem HasDerivWithinAt.exp (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.exp (f x)) (Real.exp (f x) * f') s x := (Real.hasDerivAt_exp (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_exp (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.exp (f x)) s x = Real.exp (f x) * derivWithin f s x := hf.hasDerivWithinAt.exp.derivWithin hxs @[simp] theorem deriv_exp (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.exp (f x)) x = Real.exp (f x) * deriv f x := hc.hasDerivAt.exp.deriv end section /-! Register lemmas for the derivatives of the composition of `Real.exp` with a differentiable function, for standalone use and use with `simp`. -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {f' : StrongDual ℝ E} {x : E} {s : Set E} @[fun_prop] theorem ContDiff.exp {n} (hf : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.exp (f x) := Real.contDiff_exp.comp hf @[fun_prop] theorem ContDiffAt.exp {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.exp (f x)) x := Real.contDiff_exp.contDiffAt.comp x hf @[fun_prop] theorem ContDiffOn.exp {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.exp (f x)) s := Real.contDiff_exp.comp_contDiffOn hf @[fun_prop] theorem ContDiffWithinAt.exp {n} (hf : ContDiffWithinAt ℝ n f s x) : ContDiffWithinAt ℝ n (fun x => Real.exp (f x)) s x := Real.contDiff_exp.contDiffAt.comp_contDiffWithinAt x hf theorem HasFDerivWithinAt.exp (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Real.exp (f x)) (Real.exp (f x) β€’ f') s x := (Real.hasDerivAt_exp (f x)).comp_hasFDerivWithinAt x hf theorem HasFDerivAt.exp (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) β€’ f') x := (Real.hasDerivAt_exp (f x)).comp_hasFDerivAt x hf theorem HasStrictFDerivAt.exp (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) β€’ f') x := (Real.hasStrictDerivAt_exp (f x)).comp_hasStrictFDerivAt x hf theorem DifferentiableWithinAt.exp (hf : DifferentiableWithinAt ℝ f s x) : DifferentiableWithinAt ℝ (fun x => Real.exp (f x)) s x := hf.hasFDerivWithinAt.exp.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.exp (hc : DifferentiableAt ℝ f x) : DifferentiableAt ℝ (fun x => Real.exp (f x)) x := hc.hasFDerivAt.exp.differentiableAt @[fun_prop] theorem DifferentiableOn.exp (hc : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => Real.exp (f x)) s := fun x h => (hc x h).exp @[simp, fun_prop] theorem Differentiable.exp (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.exp (f x) := fun x => (hc x).exp theorem fderivWithin_exp (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : fderivWithin ℝ (fun x => Real.exp (f x)) s x = Real.exp (f x) β€’ fderivWithin ℝ f s x := hf.hasFDerivWithinAt.exp.fderivWithin hxs @[simp] theorem fderiv_exp (hc : DifferentiableAt ℝ f x) : fderiv ℝ (fun x => Real.exp (f x)) x = Real.exp (f x) β€’ fderiv ℝ f x := hc.hasFDerivAt.exp.fderiv end open Real in @[simp] theorem iteratedDeriv_exp_const_mul (n : β„•) (c : ℝ) : (iteratedDeriv n fun s => exp (c * s)) = fun s => c ^ n * exp (c * s) := by rw [iteratedDeriv_comp_const_mul contDiff_exp, iteratedDeriv_eq_iterate, iter_deriv_exp]
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/SmoothTransition.lean
import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.PolynomialExp /-! # Infinitely smooth transition function In this file we construct two infinitely smooth functions with properties that an analytic function cannot have: * `expNegInvGlue` is equal to zero for `x ≀ 0` and is strictly positive otherwise; it is given by `x ↦ exp (-1/x)` for `x > 0`; * `Real.smoothTransition` is equal to zero for `x ≀ 0` and is equal to one for `x β‰₯ 1`; it is given by `expNegInvGlue x / (expNegInvGlue x + expNegInvGlue (1 - x))`; -/ noncomputable section open scoped Topology open Polynomial Real Filter Set Function /-- `expNegInvGlue` is the real function given by `x ↦ exp (-1/x)` for `x > 0` and `0` for `x ≀ 0`. It is a basic building block to construct smooth partitions of unity. Its main property is that it vanishes for `x ≀ 0`, it is positive for `x > 0`, and the junction between the two behaviors is flat enough to retain smoothness. The fact that this function is `C^∞` is proved in `expNegInvGlue.contDiff`. -/ def expNegInvGlue (x : ℝ) : ℝ := if x ≀ 0 then 0 else exp (-x⁻¹) namespace expNegInvGlue /-- The function `expNegInvGlue` vanishes on `(-∞, 0]`. -/ theorem zero_of_nonpos {x : ℝ} (hx : x ≀ 0) : expNegInvGlue x = 0 := by simp [expNegInvGlue, hx] @[simp] protected theorem zero : expNegInvGlue 0 = 0 := zero_of_nonpos le_rfl /-- The function `expNegInvGlue` is positive on `(0, +∞)`. -/ theorem pos_of_pos {x : ℝ} (hx : 0 < x) : 0 < expNegInvGlue x := by simp [expNegInvGlue, not_le.2 hx, exp_pos] /-- The function `expNegInvGlue` is nonnegative. -/ theorem nonneg (x : ℝ) : 0 ≀ expNegInvGlue x := by cases le_or_gt x 0 with | inl h => exact ge_of_eq (zero_of_nonpos h) | inr h => exact le_of_lt (pos_of_pos h) @[simp] theorem zero_iff_nonpos {x : ℝ} : expNegInvGlue x = 0 ↔ x ≀ 0 := ⟨fun h ↦ not_lt.mp fun h' ↦ (pos_of_pos h').ne' h, zero_of_nonpos⟩ protected theorem monotone : Monotone expNegInvGlue := by intro x y hxy rcases le_or_gt x 0 with hx | hx Β· simp [zero_of_nonpos hx, nonneg] simp [expNegInvGlue, not_le.2 hx, not_le.2 (hx.trans_le hxy), inv_le_invβ‚€ (hx.trans_le hxy) hx, hxy] /-! ### Smoothness of `expNegInvGlue` In this section we prove that the function `f = expNegInvGlue` is infinitely smooth. To do this, we show that $g_p(x)=p(x^{-1})f(x)$ is infinitely smooth for any polynomial `p` with real coefficients. First we show that $g_p(x)$ tends to zero at zero, then we show that it is differentiable with derivative $g_p'=g_{x^2(p-p')}$. Finally, we prove smoothness of $g_p$ by induction, then deduce smoothness of $f$ by setting $p=1$. -/ /-- Our function tends to zero at zero faster than any $P(x^{-1})$, $Pβˆˆβ„[X]$, tends to infinity. -/ theorem tendsto_polynomial_inv_mul_zero (p : ℝ[X]) : Tendsto (fun x ↦ p.eval x⁻¹ * expNegInvGlue x) (𝓝 0) (𝓝 0) := by simp only [expNegInvGlue, mul_ite, mul_zero] refine tendsto_const_nhds.if ?_ simp only [not_le] have : Tendsto (fun x ↦ p.eval x⁻¹ / exp x⁻¹) (𝓝[>] 0) (𝓝 0) := p.tendsto_div_exp_atTop.comp tendsto_inv_nhdsGT_zero refine this.congr' <| mem_of_superset self_mem_nhdsWithin fun x hx ↦ ?_ simp [exp_neg, div_eq_mul_inv] theorem hasDerivAt_polynomial_eval_inv_mul (p : ℝ[X]) (x : ℝ) : HasDerivAt (fun x ↦ p.eval x⁻¹ * expNegInvGlue x) ((X ^ 2 * (p - derivative (R := ℝ) p)).eval x⁻¹ * expNegInvGlue x) x := by rcases lt_trichotomy x 0 with hx | rfl | hx Β· rw [zero_of_nonpos hx.le, mul_zero] refine (hasDerivAt_const _ 0).congr_of_eventuallyEq ?_ filter_upwards [gt_mem_nhds hx] with y hy rw [zero_of_nonpos hy.le, mul_zero] Β· rw [expNegInvGlue.zero, mul_zero, hasDerivAt_iff_tendsto_slope] refine ((tendsto_polynomial_inv_mul_zero (p * X)).mono_left inf_le_left).congr fun x ↦ ?_ simp [slope_def_field, div_eq_mul_inv, mul_right_comm] Β· have := ((p.hasDerivAt x⁻¹).mul (hasDerivAt_neg _).exp).comp x (hasDerivAt_inv hx.ne') convert this.congr_of_eventuallyEq _ using 1 Β· simp [expNegInvGlue, hx.not_ge] ring Β· filter_upwards [lt_mem_nhds hx] with y hy simp [expNegInvGlue, hy.not_ge] theorem differentiable_polynomial_eval_inv_mul (p : ℝ[X]) : Differentiable ℝ (fun x ↦ p.eval x⁻¹ * expNegInvGlue x) := fun x ↦ (hasDerivAt_polynomial_eval_inv_mul p x).differentiableAt theorem continuous_polynomial_eval_inv_mul (p : ℝ[X]) : Continuous (fun x ↦ p.eval x⁻¹ * expNegInvGlue x) := (differentiable_polynomial_eval_inv_mul p).continuous theorem contDiff_polynomial_eval_inv_mul {n : β„•βˆž} (p : ℝ[X]) : ContDiff ℝ n (fun x ↦ p.eval x⁻¹ * expNegInvGlue x) := by apply contDiff_all_iff_nat.2 (fun m => ?_) n induction m generalizing p with | zero => exact contDiff_zero.2 <| continuous_polynomial_eval_inv_mul _ | succ m ihm => rw [show ((m + 1 : β„•) : WithTop β„•βˆž) = m + 1 from rfl] refine contDiff_succ_iff_deriv.2 ⟨differentiable_polynomial_eval_inv_mul _, by simp, ?_⟩ convert ihm (X ^ 2 * (p - derivative (R := ℝ) p)) using 2 exact (hasDerivAt_polynomial_eval_inv_mul p _).deriv /-- The function `expNegInvGlue` is smooth. -/ @[fun_prop] protected theorem contDiff {n : β„•βˆž} : ContDiff ℝ n expNegInvGlue := by simpa using contDiff_polynomial_eval_inv_mul 1 end expNegInvGlue /-- An infinitely smooth function `f : ℝ β†’ ℝ` such that `f x = 0` for `x ≀ 0`, `f x = 1` for `1 ≀ x`, and `0 < f x < 1` for `0 < x < 1`. -/ def Real.smoothTransition (x : ℝ) : ℝ := expNegInvGlue x / (expNegInvGlue x + expNegInvGlue (1 - x)) namespace Real namespace smoothTransition variable {x : ℝ} open expNegInvGlue theorem pos_denom (x) : 0 < expNegInvGlue x + expNegInvGlue (1 - x) := (zero_lt_one.gt_or_lt x).elim (fun hx => add_pos_of_pos_of_nonneg (pos_of_pos hx) (nonneg _)) fun hx => add_pos_of_nonneg_of_pos (nonneg _) (pos_of_pos <| sub_pos.2 hx) theorem one_of_one_le (h : 1 ≀ x) : smoothTransition x = 1 := (div_eq_one_iff_eq <| (pos_denom x).ne').2 <| by rw [zero_of_nonpos (sub_nonpos.2 h), add_zero] @[simp] nonrec theorem zero_iff_nonpos : smoothTransition x = 0 ↔ x ≀ 0 := by simp only [smoothTransition, _root_.div_eq_zero_iff, (pos_denom x).ne', zero_iff_nonpos, or_false] theorem zero_of_nonpos (h : x ≀ 0) : smoothTransition x = 0 := zero_iff_nonpos.2 h @[simp] protected theorem zero : smoothTransition 0 = 0 := zero_of_nonpos le_rfl @[simp] protected theorem one : smoothTransition 1 = 1 := one_of_one_le le_rfl /-- Since `Real.smoothTransition` is constant on $(-∞, 0]$ and $[1, ∞)$, applying it to the projection of `x : ℝ` to $[0, 1]$ gives the same result as applying it to `x`. -/ @[simp] protected theorem projIcc : smoothTransition (projIcc (0 : ℝ) 1 zero_le_one x) = smoothTransition x := by refine congr_fun (IccExtend_eq_self zero_le_one smoothTransition (fun x hx => ?_) fun x hx => ?_) x Β· rw [smoothTransition.zero, zero_of_nonpos hx.le] Β· rw [smoothTransition.one, one_of_one_le hx.le] theorem le_one (x : ℝ) : smoothTransition x ≀ 1 := (div_le_one (pos_denom x)).2 <| le_add_of_nonneg_right (nonneg _) theorem nonneg (x : ℝ) : 0 ≀ smoothTransition x := div_nonneg (expNegInvGlue.nonneg _) (pos_denom x).le theorem lt_one_of_lt_one (h : x < 1) : smoothTransition x < 1 := (div_lt_one <| pos_denom x).2 <| lt_add_of_pos_right _ <| pos_of_pos <| sub_pos.2 h theorem pos_of_pos (h : 0 < x) : 0 < smoothTransition x := div_pos (expNegInvGlue.pos_of_pos h) (pos_denom x) @[simp] theorem eq_one_iff_one_le : smoothTransition x = 1 ↔ 1 ≀ x := by rcases le_or_gt 1 x with hx | hx Β· simp [hx, one_of_one_le] Β· simpa [(lt_one_of_lt_one hx).ne] using hx @[fun_prop] protected theorem contDiff {n : β„•βˆž} : ContDiff ℝ n smoothTransition := expNegInvGlue.contDiff.div (expNegInvGlue.contDiff.add <| expNegInvGlue.contDiff.comp <| contDiff_const.sub contDiff_id) fun x => (pos_denom x).ne' @[fun_prop] protected theorem contDiffAt {x : ℝ} {n : β„•βˆž} : ContDiffAt ℝ n smoothTransition x := smoothTransition.contDiff.contDiffAt @[fun_prop] protected theorem continuous : Continuous smoothTransition := (@smoothTransition.contDiff 0).continuous @[fun_prop] protected theorem continuousAt : ContinuousAt smoothTransition x := smoothTransition.continuous.continuousAt protected theorem monotone : Monotone smoothTransition := by intro x y hxy simp only [smoothTransition] rw [div_le_div_iffβ‚€ (pos_denom x) (pos_denom y)] simp only [mul_add, mul_comm (expNegInvGlue x) (expNegInvGlue y), add_le_add_iff_left] gcongr Β· exact expNegInvGlue.nonneg _ Β· exact expNegInvGlue.nonneg _ Β· apply expNegInvGlue.monotone hxy Β· apply expNegInvGlue.monotone (by linarith) end smoothTransition end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Arsinh.lean
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # Inverse of the sinh function In this file we prove that sinh is bijective and hence has an inverse, arsinh. ## Main definitions - `Real.arsinh`: The inverse function of `Real.sinh`. - `Real.sinhEquiv`, `Real.sinhOrderIso`, `Real.sinhHomeomorph`: `Real.sinh` as an `Equiv`, `OrderIso`, and `Homeomorph`, respectively. ## Main Results - `Real.sinh_surjective`, `Real.sinh_bijective`: `Real.sinh` is surjective and bijective; - `Real.arsinh_injective`, `Real.arsinh_surjective`, `Real.arsinh_bijective`: `Real.arsinh` is injective, surjective, and bijective; - `Real.continuous_arsinh`, `Real.differentiable_arsinh`, `Real.contDiff_arsinh`: `Real.arsinh` is continuous, differentiable, and continuously differentiable; we also provide dot notation convenience lemmas like `Filter.Tendsto.arsinh` and `ContDiffAt.arsinh`. ## Tags arsinh, arcsinh, argsinh, asinh, sinh injective, sinh bijective, sinh surjective -/ noncomputable section open Function Filter Set open scoped Topology namespace Real variable {x y : ℝ} /-- `arsinh` is defined using a logarithm, `arsinh x = log (x + sqrt(1 + x^2))`. -/ @[pp_nodot] def arsinh (x : ℝ) := log (x + √(1 + x ^ 2)) theorem exp_arsinh (x : ℝ) : exp (arsinh x) = x + √(1 + x ^ 2) := by apply exp_log rw [← neg_lt_iff_pos_add'] apply lt_sqrt_of_sq_lt simp @[simp] theorem arsinh_zero : arsinh 0 = 0 := by simp [arsinh] @[simp] theorem arsinh_neg (x : ℝ) : arsinh (-x) = -arsinh x := by rw [← exp_eq_exp, exp_arsinh, exp_neg, exp_arsinh] apply eq_inv_of_mul_eq_one_left rw [neg_sq, neg_add_eq_sub, add_comm x, mul_comm, ← sq_sub_sq, sq_sqrt, add_sub_cancel_right] exact add_nonneg zero_le_one (sq_nonneg _) /-- `arsinh` is the right inverse of `sinh`. -/ @[simp] theorem sinh_arsinh (x : ℝ) : sinh (arsinh x) = x := by rw [sinh_eq, ← arsinh_neg, exp_arsinh, exp_arsinh, neg_sq]; simp @[simp] theorem cosh_arsinh (x : ℝ) : cosh (arsinh x) = √(1 + x ^ 2) := by rw [← sqrt_sq (cosh_pos _).le, cosh_sq', sinh_arsinh] /-- `sinh` is surjective, `βˆ€ b, βˆƒ a, sinh a = b`. In this case, we use `a = arsinh b`. -/ theorem sinh_surjective : Surjective sinh := LeftInverse.surjective sinh_arsinh /-- `sinh` is bijective, both injective and surjective. -/ theorem sinh_bijective : Bijective sinh := ⟨sinh_injective, sinh_surjective⟩ /-- `arsinh` is the left inverse of `sinh`. -/ @[simp] theorem arsinh_sinh (x : ℝ) : arsinh (sinh x) = x := rightInverse_of_injective_of_leftInverse sinh_injective sinh_arsinh x /-- `Real.sinh` as an `Equiv`. -/ @[simps] def sinhEquiv : ℝ ≃ ℝ where toFun := sinh invFun := arsinh left_inv := arsinh_sinh right_inv := sinh_arsinh /-- `Real.sinh` as an `OrderIso`. -/ @[simps! -fullyApplied] def sinhOrderIso : ℝ ≃o ℝ where toEquiv := sinhEquiv map_rel_iff' := @sinh_le_sinh /-- `Real.sinh` as a `Homeomorph`. -/ @[simps! -fullyApplied] def sinhHomeomorph : ℝ β‰ƒβ‚œ ℝ := sinhOrderIso.toHomeomorph theorem arsinh_bijective : Bijective arsinh := sinhEquiv.symm.bijective theorem arsinh_injective : Injective arsinh := sinhEquiv.symm.injective theorem arsinh_surjective : Surjective arsinh := sinhEquiv.symm.surjective theorem arsinh_strictMono : StrictMono arsinh := sinhOrderIso.symm.strictMono @[simp] theorem arsinh_inj : arsinh x = arsinh y ↔ x = y := arsinh_injective.eq_iff @[simp] theorem arsinh_le_arsinh : arsinh x ≀ arsinh y ↔ x ≀ y := sinhOrderIso.symm.le_iff_le @[gcongr] protected alias ⟨_, GCongr.arsinh_le_arsinh⟩ := arsinh_le_arsinh @[simp] theorem arsinh_lt_arsinh : arsinh x < arsinh y ↔ x < y := sinhOrderIso.symm.lt_iff_lt @[simp] theorem arsinh_eq_zero_iff : arsinh x = 0 ↔ x = 0 := arsinh_injective.eq_iff' arsinh_zero @[simp] theorem arsinh_nonneg_iff : 0 ≀ arsinh x ↔ 0 ≀ x := by rw [← sinh_le_sinh, sinh_zero, sinh_arsinh] @[simp] theorem arsinh_nonpos_iff : arsinh x ≀ 0 ↔ x ≀ 0 := by rw [← sinh_le_sinh, sinh_zero, sinh_arsinh] @[simp] theorem arsinh_pos_iff : 0 < arsinh x ↔ 0 < x := lt_iff_lt_of_le_iff_le arsinh_nonpos_iff @[simp] theorem arsinh_neg_iff : arsinh x < 0 ↔ x < 0 := lt_iff_lt_of_le_iff_le arsinh_nonneg_iff theorem hasStrictDerivAt_arsinh (x : ℝ) : HasStrictDerivAt arsinh (√(1 + x ^ 2))⁻¹ x := by convert sinhHomeomorph.toOpenPartialHomeomorph.hasStrictDerivAt_symm (mem_univ x) (cosh_pos _).ne' (hasStrictDerivAt_sinh _) using 2 exact (cosh_arsinh _).symm theorem hasDerivAt_arsinh (x : ℝ) : HasDerivAt arsinh (√(1 + x ^ 2))⁻¹ x := (hasStrictDerivAt_arsinh x).hasDerivAt @[fun_prop] theorem differentiable_arsinh : Differentiable ℝ arsinh := fun x => (hasDerivAt_arsinh x).differentiableAt @[fun_prop] theorem contDiff_arsinh {n : β„•βˆž} : ContDiff ℝ n arsinh := sinhHomeomorph.contDiff_symm_deriv (fun x => (cosh_pos x).ne') hasDerivAt_sinh contDiff_sinh @[continuity] theorem continuous_arsinh : Continuous arsinh := sinhHomeomorph.symm.continuous end Real open Real theorem Filter.Tendsto.arsinh {Ξ± : Type*} {l : Filter Ξ±} {f : Ξ± β†’ ℝ} {a : ℝ} (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => arsinh (f x)) l (𝓝 (arsinh a)) := (continuous_arsinh.tendsto _).comp h section Continuous variable {X : Type*} [TopologicalSpace X] {f : X β†’ ℝ} {s : Set X} {a : X} nonrec theorem ContinuousAt.arsinh (h : ContinuousAt f a) : ContinuousAt (fun x => arsinh (f x)) a := h.arsinh nonrec theorem ContinuousWithinAt.arsinh (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => arsinh (f x)) s a := h.arsinh theorem ContinuousOn.arsinh (h : ContinuousOn f s) : ContinuousOn (fun x => arsinh (f x)) s := fun x hx => (h x hx).arsinh theorem Continuous.arsinh (h : Continuous f) : Continuous fun x => arsinh (f x) := continuous_arsinh.comp h end Continuous section fderiv variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E β†’ ℝ} {s : Set E} {a : E} {f' : StrongDual ℝ E} {n : β„•βˆž} theorem HasStrictFDerivAt.arsinh (hf : HasStrictFDerivAt f f' a) : HasStrictFDerivAt (fun x => arsinh (f x)) ((√(1 + f a ^ 2))⁻¹ β€’ f') a := (hasStrictDerivAt_arsinh _).comp_hasStrictFDerivAt a hf theorem HasFDerivAt.arsinh (hf : HasFDerivAt f f' a) : HasFDerivAt (fun x => arsinh (f x)) ((√(1 + f a ^ 2))⁻¹ β€’ f') a := (hasDerivAt_arsinh _).comp_hasFDerivAt a hf theorem HasFDerivWithinAt.arsinh (hf : HasFDerivWithinAt f f' s a) : HasFDerivWithinAt (fun x => arsinh (f x)) ((√(1 + f a ^ 2))⁻¹ β€’ f') s a := (hasDerivAt_arsinh _).comp_hasFDerivWithinAt a hf @[fun_prop] theorem DifferentiableAt.arsinh (h : DifferentiableAt ℝ f a) : DifferentiableAt ℝ (fun x => arsinh (f x)) a := (differentiable_arsinh _).comp a h @[fun_prop] theorem DifferentiableWithinAt.arsinh (h : DifferentiableWithinAt ℝ f s a) : DifferentiableWithinAt ℝ (fun x => arsinh (f x)) s a := (differentiable_arsinh _).comp_differentiableWithinAt a h @[fun_prop] theorem DifferentiableOn.arsinh (h : DifferentiableOn ℝ f s) : DifferentiableOn ℝ (fun x => arsinh (f x)) s := fun x hx => (h x hx).arsinh @[fun_prop] theorem Differentiable.arsinh (h : Differentiable ℝ f) : Differentiable ℝ fun x => arsinh (f x) := differentiable_arsinh.comp h @[fun_prop] theorem ContDiffAt.arsinh (h : ContDiffAt ℝ n f a) : ContDiffAt ℝ n (fun x => arsinh (f x)) a := contDiff_arsinh.contDiffAt.comp a h @[fun_prop] theorem ContDiffWithinAt.arsinh (h : ContDiffWithinAt ℝ n f s a) : ContDiffWithinAt ℝ n (fun x => arsinh (f x)) s a := contDiff_arsinh.contDiffAt.comp_contDiffWithinAt a h @[fun_prop] theorem ContDiff.arsinh (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => arsinh (f x) := contDiff_arsinh.comp h @[fun_prop] theorem ContDiffOn.arsinh (h : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => arsinh (f x)) s := fun x hx => (h x hx).arsinh end fderiv section deriv variable {f : ℝ β†’ ℝ} {s : Set ℝ} {a f' : ℝ} theorem HasStrictDerivAt.arsinh (hf : HasStrictDerivAt f f' a) : HasStrictDerivAt (fun x => arsinh (f x)) ((√(1 + f a ^ 2))⁻¹ β€’ f') a := (hasStrictDerivAt_arsinh _).comp a hf theorem HasDerivAt.arsinh (hf : HasDerivAt f f' a) : HasDerivAt (fun x => arsinh (f x)) ((√(1 + f a ^ 2))⁻¹ β€’ f') a := (hasDerivAt_arsinh _).comp a hf theorem HasDerivWithinAt.arsinh (hf : HasDerivWithinAt f f' s a) : HasDerivWithinAt (fun x => arsinh (f x)) ((√(1 + f a ^ 2))⁻¹ β€’ f') s a := (hasDerivAt_arsinh _).comp_hasDerivWithinAt a hf end deriv
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/ImproperIntegrals.lean
import Mathlib.Analysis.SpecialFunctions.JapaneseBracket import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.IntegralEqImproper import Mathlib.MeasureTheory.Measure.Lebesgue.Integral /-! # Evaluation of specific improper integrals This file contains some integrability results, and evaluations of integrals, over `ℝ` or over half-infinite intervals in `ℝ`. These lemmas are stated in terms of either `Iic` or `Ioi` (neglecting `Iio` and `Ici`) to match mathlib's conventions for integrals over finite intervals (see `intervalIntegral`). ## See also - `Mathlib/Analysis/SpecialFunctions/Integrals.lean` -- integrals over finite intervals - `Mathlib/Analysis/SpecialFunctions/Gaussian.lean` -- integral of `exp (-x ^ 2)` - `Mathlib/Analysis/SpecialFunctions/JapaneseBracket.lean`-- integrability of `(1+β€–xβ€–)^(-r)`. -/ open Real Set Filter MeasureTheory intervalIntegral open scoped Topology theorem integrableOn_exp_Iic (c : ℝ) : IntegrableOn exp (Iic c) := by refine integrableOn_Iic_of_intervalIntegral_norm_bounded (exp c) c (fun y => intervalIntegrable_exp.1) tendsto_id (eventually_of_mem (Iic_mem_atBot 0) fun y _ => ?_) simp_rw [norm_of_nonneg (exp_pos _).le, integral_exp, sub_le_self_iff] exact (exp_pos _).le theorem integrableOn_exp_neg_Ioi (c : ℝ) : IntegrableOn (fun (x : ℝ) => exp (-x)) (Ioi c) := Iff.mp integrableOn_Ici_iff_integrableOn_Ioi (integrableOn_exp_Iic (-c)).comp_neg_Ici theorem integral_exp_Iic (c : ℝ) : ∫ x : ℝ in Iic c, exp x = exp c := by refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Iic _ (integrableOn_exp_Iic _) tendsto_id) ?_ simp_rw [integral_exp, show 𝓝 (exp c) = 𝓝 (exp c - 0) by rw [sub_zero]] exact tendsto_exp_atBot.const_sub _ theorem integral_exp_Iic_zero : ∫ x : ℝ in Iic 0, exp x = 1 := exp_zero β–Έ integral_exp_Iic 0 theorem integral_exp_neg_Ioi (c : ℝ) : (∫ x : ℝ in Ioi c, exp (-x)) = exp (-c) := by simpa only [integral_comp_neg_Ioi] using integral_exp_Iic (-c) theorem integral_exp_neg_Ioi_zero : (∫ x : ℝ in Ioi 0, exp (-x)) = 1 := by simpa only [neg_zero, exp_zero] using integral_exp_neg_Ioi 0 theorem integrableOn_exp_mul_complex_Ioi {a : β„‚} (ha : a.re < 0) (c : ℝ) : IntegrableOn (fun x : ℝ => Complex.exp (a * x)) (Ioi c) := by refine (integrable_norm_iff ?_).mp ?_ Β· apply Continuous.aestronglyMeasurable fun_prop Β· simpa [Complex.norm_exp] using (integrableOn_Ioi_comp_mul_left_iff (fun x => exp (-x)) c (a := -a.re) (by simpa)).mpr <| integrableOn_exp_neg_Ioi _ theorem integrableOn_exp_mul_complex_Iic {a : β„‚} (ha : 0 < a.re) (c : ℝ) : IntegrableOn (fun x : ℝ => Complex.exp (a * x)) (Iic c) := by simpa using Iff.mpr integrableOn_Iic_iff_integrableOn_Iio (integrableOn_exp_mul_complex_Ioi (a := -a) (by simpa) (-c)).comp_neg_Iio theorem integrableOn_exp_mul_Ioi {a : ℝ} (ha : a < 0) (c : ℝ) : IntegrableOn (fun x : ℝ => Real.exp (a * x)) (Ioi c) := by have := Integrable.norm <| integrableOn_exp_mul_complex_Ioi (a := a) (by simpa using ha) c simpa [Complex.norm_exp] using this theorem integrableOn_exp_mul_Iic {a : ℝ} (ha : 0 < a) (c : ℝ) : IntegrableOn (fun x : ℝ => Real.exp (a * x)) (Iic c) := by have := Integrable.norm <| integrableOn_exp_mul_complex_Iic (a := a) (by simpa using ha) c simpa [Complex.norm_exp] using this theorem integral_exp_mul_complex_Ioi {a : β„‚} (ha : a.re < 0) (c : ℝ) : ∫ x : ℝ in Set.Ioi c, Complex.exp (a * x) = - Complex.exp (a * c) / a := by refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi c (integrableOn_exp_mul_complex_Ioi ha c) tendsto_id) ?_ simp_rw [integral_exp_mul_complex (c := a) (by aesop), id_eq] suffices Tendsto (fun x : ℝ ↦ Complex.exp (a * x)) atTop (𝓝 0) by simpa using this.sub_const _ |>.div_const _ simpa [Complex.tendsto_exp_nhds_zero_iff] using tendsto_const_nhds.neg_mul_atTop ha tendsto_id theorem integral_exp_mul_complex_Iic {a : β„‚} (ha : 0 < a.re) (c : ℝ) : ∫ x : ℝ in Set.Iic c, Complex.exp (a * x) = Complex.exp (a * c) / a := by simpa [neg_mul, ← mul_neg, ← Complex.ofReal_neg, integral_comp_neg_Ioi (f := fun x : ℝ ↦ Complex.exp (a * x))] using integral_exp_mul_complex_Ioi (a := -a) (by simpa) (-c) theorem integral_exp_mul_Ioi {a : ℝ} (ha : a < 0) (c : ℝ) : ∫ x : ℝ in Set.Ioi c, Real.exp (a * x) = - Real.exp (a * c) / a := by simp_rw [Real.exp, ← RCLike.re_to_complex, Complex.ofReal_mul] rw [integral_re, integral_exp_mul_complex_Ioi (by simpa using ha), RCLike.re_to_complex, RCLike.re_to_complex, Complex.div_ofReal_re, Complex.neg_re] exact integrableOn_exp_mul_complex_Ioi (by simpa using ha) _ theorem integral_exp_mul_Iic {a : ℝ} (ha : 0 < a) (c : ℝ) : ∫ x : ℝ in Set.Iic c, Real.exp (a * x) = Real.exp (a * c) / a := by simpa [neg_mul, ← mul_neg, integral_comp_neg_Ioi (f := fun x : ℝ ↦ Real.exp (a * x))] using integral_exp_mul_Ioi (a := -a) (by simpa) (-c) /-- If `-m < c`, then `(fun t : ℝ ↦ (t + m) ^ a)` is integrable on `(c, ∞)` for all `a < -1`. -/ theorem integrableOn_add_rpow_Ioi_of_lt {a c m : ℝ} (ha : a < -1) (hc : -m < c) : IntegrableOn (fun (x : ℝ) ↦ (x + m) ^ a) (Ioi c) := by have hd : βˆ€ x ∈ Ici c, HasDerivAt (fun t ↦ (t + m) ^ (a + 1) / (a + 1)) ((x + m) ^ a) x := by intro x hx convert (((hasDerivAt_id _).add_const _).rpow_const _).div_const _ using 1 Β· simp [show a + 1 β‰  0 by linarith] left; linarith [mem_Ici.mp hx, id_eq x] have ht : Tendsto (fun t ↦ ((t + m) ^ (a + 1)) / (a + 1)) atTop (nhds (0 / (a + 1))) := by rw [← neg_neg (a + 1)] exact (tendsto_rpow_neg_atTop (by linarith)).comp (tendsto_atTop_add_const_right _ m tendsto_id) |>.div_const _ exact integrableOn_Ioi_deriv_of_nonneg' hd (fun t ht ↦ rpow_nonneg (by linarith [mem_Ioi.mp ht]) a) ht /-- If `0 < c`, then `(fun t : ℝ ↦ t ^ a)` is integrable on `(c, ∞)` for all `a < -1`. -/ theorem integrableOn_Ioi_rpow_of_lt {a c : ℝ} (ha : a < -1) (hc : 0 < c) : IntegrableOn (fun t : ℝ ↦ t ^ a) (Ioi c) := by simpa using integrableOn_add_rpow_Ioi_of_lt ha (by simpa : -0 < c) theorem integrableOn_Ioi_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioi t) ↔ s < -1 := by refine ⟨fun h ↦ ?_, fun h ↦ integrableOn_Ioi_rpow_of_lt h ht⟩ contrapose! h intro H have H' : IntegrableOn (fun x ↦ x ^ s) (Ioi (max 1 t)) := H.mono (Set.Ioi_subset_Ioi (le_max_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioi (max 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx have x_one : 1 ≀ x := ((le_max_left _ _).trans_lt (mem_Ioi.1 hx)).le simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (zero_le_one.trans x_one)] rw [← Real.rpow_neg_one x] exact Real.rpow_le_rpow_of_exponent_le x_one h exact not_IntegrableOn_Ioi_inv this theorem integrableAtFilter_rpow_atTop_iff {s : ℝ} : IntegrableAtFilter (fun x : ℝ ↦ x ^ s) atTop ↔ s < -1 := by refine ⟨fun ⟨t, ht, hint⟩ ↦ ?_, fun h ↦ ⟨Set.Ioi 1, Ioi_mem_atTop 1, (integrableOn_Ioi_rpow_iff zero_lt_one).mpr h⟩⟩ obtain ⟨a, ha⟩ := mem_atTop_sets.mp ht refine (integrableOn_Ioi_rpow_iff (zero_lt_one.trans_le (le_max_right a 1))).mp ?_ exact hint.mono_set <| fun x hx ↦ ha _ <| (le_max_left a 1).trans hx.le /-- The real power function with any exponent is not integrable on `(0, +∞)`. -/ theorem not_integrableOn_Ioi_rpow (s : ℝ) : Β¬ IntegrableOn (fun x ↦ x ^ s) (Ioi (0 : ℝ)) := by intro h rcases le_or_gt s (-1) with hs|hs Β· have : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) 1) := h.mono Ioo_subset_Ioi_self le_rfl rw [integrableOn_Ioo_rpow_iff zero_lt_one] at this exact hs.not_gt this Β· have : IntegrableOn (fun x ↦ x ^ s) (Ioi (1 : ℝ)) := h.mono (Ioi_subset_Ioi zero_le_one) le_rfl rw [integrableOn_Ioi_rpow_iff zero_lt_one] at this exact hs.not_gt this theorem setIntegral_Ioi_zero_rpow (s : ℝ) : ∫ x in Ioi (0 : ℝ), x ^ s = 0 := MeasureTheory.integral_undef (not_integrableOn_Ioi_rpow s) theorem integral_Ioi_rpow_of_lt {a : ℝ} (ha : a < -1) {c : ℝ} (hc : 0 < c) : ∫ t : ℝ in Ioi c, t ^ a = -c ^ (a + 1) / (a + 1) := by have hd : βˆ€ x ∈ Ici c, HasDerivAt (fun t => t ^ (a + 1) / (a + 1)) (x ^ a) x := by intro x hx convert (hasDerivAt_rpow_const (p := a + 1) (Or.inl (hc.trans_le hx).ne')).div_const _ using 1 simp [show a + 1 β‰  0 from ne_of_lt (by linarith), mul_comm] have ht : Tendsto (fun t => t ^ (a + 1) / (a + 1)) atTop (𝓝 (0 / (a + 1))) := by apply Tendsto.div_const simpa only [neg_neg] using tendsto_rpow_neg_atTop (by linarith : 0 < -(a + 1)) convert integral_Ioi_of_hasDerivAt_of_tendsto' hd (integrableOn_Ioi_rpow_of_lt ha hc) ht using 1 simp only [neg_div, zero_div, zero_sub] theorem integrableOn_Ioi_norm_cpow_of_lt {a : β„‚} (ha : a.re < -1) {c : ℝ} (hc : 0 < c) : IntegrableOn (fun t : ℝ ↦ β€–(t : β„‚) ^ aβ€–) (Ioi c) := by refine (integrableOn_Ioi_rpow_of_lt ha hc).congr_fun (fun x hx => ?_) measurableSet_Ioi rw [Complex.norm_cpow_eq_rpow_re_of_pos (hc.trans hx)] theorem integrableOn_Ioi_cpow_of_lt {a : β„‚} (ha : a.re < -1) {c : ℝ} (hc : 0 < c) : IntegrableOn (fun t : ℝ => (t : β„‚) ^ a) (Ioi c) := by refine (integrable_norm_iff ?_).mp <| integrableOn_Ioi_norm_cpow_of_lt ha hc refine ContinuousOn.aestronglyMeasurable (fun t ht ↦ ?_) measurableSet_Ioi exact (Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr (hc.trans ht).ne')).continuousWithinAt theorem integrableOn_Ioi_norm_cpow_iff {s : β„‚} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ β€–(x : β„‚) ^ sβ€–) (Ioi t) ↔ s.re < -1 := by refine ⟨fun h ↦ ?_, fun h ↦ integrableOn_Ioi_norm_cpow_of_lt h ht⟩ refine (integrableOn_Ioi_rpow_iff ht).mp <| h.congr_fun (fun a ha ↦ ?_) measurableSet_Ioi rw [Complex.norm_cpow_eq_rpow_re_of_pos (ht.trans ha)] theorem integrableOn_Ioi_cpow_iff {s : β„‚} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioi t) ↔ s.re < -1 := ⟨fun h ↦ (integrableOn_Ioi_norm_cpow_iff ht).mp h.norm, fun h ↦ integrableOn_Ioi_cpow_of_lt h ht⟩ theorem integrableOn_Ioi_deriv_ofReal_cpow {s : β„‚} {t : ℝ} (ht : 0 < t) (hs : s.re < 0) : IntegrableOn (deriv fun x : ℝ ↦ (x : β„‚) ^ s) (Set.Ioi t) := by have h : IntegrableOn (fun x : ℝ ↦ s * x ^ (s - 1)) (Set.Ioi t) := by refine (integrableOn_Ioi_cpow_of_lt ?_ ht).const_mul _ rwa [Complex.sub_re, Complex.one_re, sub_lt_iff_lt_add, neg_add_cancel] refine h.congr_fun (fun x hx ↦ ?_) measurableSet_Ioi rw [Complex.deriv_ofReal_cpow_const (ht.trans hx).ne' (fun h ↦ (Complex.zero_re β–Έ h β–Έ hs).false)] theorem integrableOn_Ioi_deriv_norm_ofReal_cpow {s : β„‚} {t : ℝ} (ht : 0 < t) (hs : s.re ≀ 0) : IntegrableOn (deriv fun x : ℝ ↦ β€–(x : β„‚) ^ sβ€–) (Set.Ioi t) := by rw [integrableOn_congr_fun (fun x hx ↦ by rw [deriv_norm_ofReal_cpow _ (ht.trans hx)]) measurableSet_Ioi] obtain hs | hs := eq_or_lt_of_le hs Β· simp_rw [hs, zero_mul] exact integrableOn_zero Β· replace hs : s.re - 1 < - 1 := by rwa [sub_lt_iff_lt_add, neg_add_cancel] exact (integrableOn_Ioi_rpow_of_lt hs ht).const_mul s.re /-- The complex power function with any exponent is not integrable on `(0, +∞)`. -/ theorem not_integrableOn_Ioi_cpow (s : β„‚) : Β¬ IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioi (0 : ℝ)) := by intro h rcases le_or_gt s.re (-1) with hs|hs Β· have : IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioo (0 : ℝ) 1) := h.mono Ioo_subset_Ioi_self le_rfl rw [integrableOn_Ioo_cpow_iff zero_lt_one] at this exact hs.not_gt this Β· have : IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioi 1) := h.mono (Ioi_subset_Ioi zero_le_one) le_rfl rw [integrableOn_Ioi_cpow_iff zero_lt_one] at this exact hs.not_gt this theorem setIntegral_Ioi_zero_cpow (s : β„‚) : ∫ x in Ioi (0 : ℝ), (x : β„‚) ^ s = 0 := MeasureTheory.integral_undef (not_integrableOn_Ioi_cpow s) theorem integral_Ioi_cpow_of_lt {a : β„‚} (ha : a.re < -1) {c : ℝ} (hc : 0 < c) : (∫ t : ℝ in Ioi c, (t : β„‚) ^ a) = -(c : β„‚) ^ (a + 1) / (a + 1) := by refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi c (integrableOn_Ioi_cpow_of_lt ha hc) tendsto_id) ?_ suffices Tendsto (fun x : ℝ => ((x : β„‚) ^ (a + 1) - (c : β„‚) ^ (a + 1)) / (a + 1)) atTop (𝓝 <| -c ^ (a + 1) / (a + 1)) by refine this.congr' ((eventually_gt_atTop 0).mp (Eventually.of_forall fun x hx => ?_)) dsimp only rw [integral_cpow, id] refine Or.inr ⟨?_, notMem_uIcc_of_lt hc hx⟩ apply_fun Complex.re rw [Complex.neg_re, Complex.one_re] exact ha.ne simp_rw [← zero_sub, sub_div] refine (Tendsto.div_const ?_ _).sub_const _ rw [tendsto_zero_iff_norm_tendsto_zero] refine (tendsto_rpow_neg_atTop (by linarith : 0 < -(a.re + 1))).congr' ((eventually_gt_atTop 0).mp (Eventually.of_forall fun x hx => ?_)) simp_rw [neg_neg, Complex.norm_cpow_eq_rpow_re_of_pos hx, Complex.add_re, Complex.one_re] theorem integrable_inv_one_add_sq : Integrable fun (x : ℝ) ↦ (1 + x ^ 2)⁻¹ := by suffices Integrable fun (x : ℝ) ↦ (1 + β€–xβ€– ^ 2) ^ ((-2 : ℝ) / 2) by simpa [rpow_neg_one] exact integrable_rpow_neg_one_add_norm_sq (by simp) @[simp] theorem integral_Iic_inv_one_add_sq {i : ℝ} : ∫ (x : ℝ) in Set.Iic i, (1 + x ^ 2)⁻¹ = arctan i + (Ο€ / 2) := integral_Iic_of_hasDerivAt_of_tendsto' (fun x _ => hasDerivAt_arctan' x) integrable_inv_one_add_sq.integrableOn (tendsto_nhds_of_tendsto_nhdsWithin tendsto_arctan_atBot) |>.trans (sub_neg_eq_add _ _) @[simp] theorem integral_Ioi_inv_one_add_sq {i : ℝ} : ∫ (x : ℝ) in Set.Ioi i, (1 + x ^ 2)⁻¹ = (Ο€ / 2) - arctan i := integral_Ioi_of_hasDerivAt_of_tendsto' (fun x _ => hasDerivAt_arctan' x) integrable_inv_one_add_sq.integrableOn (tendsto_nhds_of_tendsto_nhdsWithin tendsto_arctan_atTop) @[simp] theorem integral_univ_inv_one_add_sq : ∫ (x : ℝ), (1 + x ^ 2)⁻¹ = Ο€ := (by ring : Ο€ = (Ο€ / 2) - (-(Ο€ / 2))) β–Έ integral_of_hasDerivAt_of_tendsto hasDerivAt_arctan' integrable_inv_one_add_sq (tendsto_nhds_of_tendsto_nhdsWithin tendsto_arctan_atBot) (tendsto_nhds_of_tendsto_nhdsWithin tendsto_arctan_atTop)
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Stirling.lean
import Mathlib.Analysis.PSeries import Mathlib.Analysis.Real.Pi.Wallis import Mathlib.Tactic.AdaptationNote /-! # Stirling's formula This file proves Stirling's formula for the factorial. It states that $n!$ grows asymptotically like $\sqrt{2\pi n}(\frac{n}{e})^n$. Also some _global_ bounds on the factorial function and the Stirling sequence are proved. ## Proof outline The proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>. We proceed in two parts. **Part 1**: We consider the sequence $a_n$ of fractions $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$ and prove that this sequence converges to a real, positive number $a$. For this the two main ingredients are - taking the logarithm of the sequence and - using the series expansion of $\log(1 + x)$. **Part 2**: We use the fact that the series defined in part 1 converges against a real number $a$ and prove that $a = \sqrt{\pi}$. Here the main ingredient is the convergence of Wallis' product formula for `Ο€`. -/ open scoped Topology Real Nat Asymptotics open Nat hiding log log_pow open Finset Filter Real namespace Stirling /-! ### Part 1 https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1 -/ /-- Define `stirlingSeq n` as $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$. Stirling's formula states that this sequence has limit $\sqrt(Ο€)$. -/ noncomputable def stirlingSeq (n : β„•) : ℝ := n ! / (√(2 * n : ℝ) * (n / exp 1) ^ n) @[simp] theorem stirlingSeq_zero : stirlingSeq 0 = 0 := by rw [stirlingSeq, cast_zero, mul_zero, Real.sqrt_zero, zero_mul, div_zero] @[simp] theorem stirlingSeq_one : stirlingSeq 1 = exp 1 / √2 := by rw [stirlingSeq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div] theorem log_stirlingSeq_formula (n : β„•) : log (stirlingSeq n) = Real.log n ! - 1 / 2 * Real.log (2 * n) - n * log (n / exp 1) := by cases n Β· simp Β· rw [stirlingSeq, log_div, log_mul, sqrt_eq_rpow, log_rpow, Real.log_pow, tsub_tsub] <;> positivity /-- The sequence `log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))` has the series expansion `βˆ‘ 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`. -/ theorem log_stirlingSeq_diff_hasSum (m : β„•) : HasSum (fun k : β„• => (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ ↑(k + 1)) (log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))) := by let f (k : β„•) := (1 : ℝ) / (2 * k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k change HasSum (fun k => f (k + 1)) _ rw [hasSum_nat_add_iff] convert (hasSum_log_one_add_inv m.cast_add_one_pos).mul_left ((↑(m + 1) : ℝ) + 1 / 2) using 1 Β· ext k dsimp only [f] rw [← pow_mul, pow_add] push_cast field Β· have h (x) (hx : x β‰  (0 : ℝ)) : 1 + x⁻¹ = (x + 1) / x := by field simp (disch := positivity) only [log_stirlingSeq_formula, log_div, log_mul, log_exp, factorial_succ, cast_mul, cast_succ, range_one, sum_singleton, h] ring /-- The sequence `log ∘ stirlingSeq ∘ succ` is monotone decreasing -/ theorem log_stirlingSeq'_antitone : Antitone (Real.log ∘ stirlingSeq ∘ succ) := antitone_nat_of_succ_le fun n => sub_nonneg.mp <| (log_stirlingSeq_diff_hasSum n).nonneg fun m => by positivity /-- We have a bound for successive elements in the sequence `log (stirlingSeq k)`. -/ theorem log_stirlingSeq_diff_le_geo_sum (n : β„•) : log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≀ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) := by have h_nonneg : (0 : ℝ) ≀ ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 := sq_nonneg _ have g : HasSum (fun k : β„• => (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1)) (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2 / (1 - ((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2)) := by have := (hasSum_geometric_of_lt_one h_nonneg ?_).mul_left (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) Β· simp_rw [← _root_.pow_succ'] at this exact this rw [one_div, inv_pow] exact inv_lt_one_of_one_ltβ‚€ (one_lt_powβ‚€ (lt_add_of_pos_left _ <| by positivity) two_ne_zero) have hab (k : β„•) : (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) ≀ (((1 : ℝ) / (2 * ↑(n + 1) + 1)) ^ 2) ^ ↑(k + 1) := by refine mul_le_of_le_one_left (pow_nonneg h_nonneg ↑(k + 1)) ?_ rw [one_div] exact inv_le_one_of_one_leβ‚€ (le_add_of_nonneg_left <| by positivity) exact hasSum_le hab (log_stirlingSeq_diff_hasSum n) g /-- We have the bound `log (stirlingSeq n) - log (stirlingSeq (n+1))` ≀ 1/(4 n^2) -/ theorem log_stirlingSeq_sub_log_stirlingSeq_succ (n : β„•) : log (stirlingSeq (n + 1)) - log (stirlingSeq (n + 2)) ≀ 1 / (4 * (↑(n + 1) : ℝ) ^ 2) := by have h₁ : (0 : ℝ) < ((n : ℝ) + 1) ^ 2 * 4 := by positivity have h₃ : (0 : ℝ) < (2 * ((n : ℝ) + 1) + 1) ^ 2 - 1 := by ring_nf positivity refine (log_stirlingSeq_diff_le_geo_sum n).trans ?_ push_cast field_simp ring_nf norm_cast cutsat /-- For any `n`, we have `log_stirlingSeq 1 - log_stirlingSeq n ≀ 1/4 * βˆ‘' 1/k^2` -/ theorem log_stirlingSeq_bounded_aux : βˆƒ c : ℝ, βˆ€ n : β„•, log (stirlingSeq 1) - log (stirlingSeq (n + 1)) ≀ c := by let d : ℝ := βˆ‘' k : β„•, (1 : ℝ) / (↑(k + 1) : ℝ) ^ 2 use 1 / 4 * d let log_stirlingSeq' : β„• β†’ ℝ := fun k => log (stirlingSeq (k + 1)) intro n have h₁ k : log_stirlingSeq' k - log_stirlingSeq' (k + 1) ≀ 1 / 4 * (1 / (↑(k + 1) : ℝ) ^ 2) := by convert log_stirlingSeq_sub_log_stirlingSeq_succ k using 1; field have hβ‚‚ : (βˆ‘ k ∈ range n, 1 / (↑(k + 1) : ℝ) ^ 2) ≀ d := by have := (summable_nat_add_iff 1).mpr <| Real.summable_one_div_nat_pow.mpr one_lt_two exact this.sum_le_tsum (range n) (fun k _ => by positivity) calc log (stirlingSeq 1) - log (stirlingSeq (n + 1)) = log_stirlingSeq' 0 - log_stirlingSeq' n := rfl _ = βˆ‘ k ∈ range n, (log_stirlingSeq' k - log_stirlingSeq' (k + 1)) := by rw [← sum_range_sub' log_stirlingSeq' n] _ ≀ βˆ‘ k ∈ range n, 1 / 4 * (1 / ↑((k + 1)) ^ 2) := sum_le_sum fun k _ => h₁ k _ = 1 / 4 * βˆ‘ k ∈ range n, 1 / ↑((k + 1)) ^ 2 := by rw [mul_sum] _ ≀ 1 / 4 * d := by gcongr /-- The sequence `log_stirlingSeq` is bounded below for `n β‰₯ 1`. -/ theorem log_stirlingSeq_bounded_by_constant : βˆƒ c, βˆ€ n : β„•, c ≀ log (stirlingSeq (n + 1)) := by obtain ⟨d, h⟩ := log_stirlingSeq_bounded_aux exact ⟨log (stirlingSeq 1) - d, fun n => sub_le_comm.mp (h n)⟩ /-- The sequence `stirlingSeq` is positive for `n > 0` -/ theorem stirlingSeq'_pos (n : β„•) : 0 < stirlingSeq (n + 1) := by unfold stirlingSeq; positivity /-- The sequence `stirlingSeq` has a positive lower bound. -/ theorem stirlingSeq'_bounded_by_pos_constant : βˆƒ a, 0 < a ∧ βˆ€ n : β„•, a ≀ stirlingSeq (n + 1) := by obtain ⟨c, h⟩ := log_stirlingSeq_bounded_by_constant refine ⟨exp c, exp_pos _, fun n => ?_⟩ rw [← le_log_iff_exp_le (stirlingSeq'_pos n)] exact h n /-- The sequence `stirlingSeq ∘ succ` is monotone decreasing -/ theorem stirlingSeq'_antitone : Antitone (stirlingSeq ∘ succ) := fun n m h => (log_le_log_iff (stirlingSeq'_pos m) (stirlingSeq'_pos n)).mp (log_stirlingSeq'_antitone h) /-- The limit `a` of the sequence `stirlingSeq` satisfies `0 < a` -/ theorem stirlingSeq_has_pos_limit_a : βˆƒ a : ℝ, 0 < a ∧ Tendsto stirlingSeq atTop (𝓝 a) := by obtain ⟨x, x_pos, hx⟩ := stirlingSeq'_bounded_by_pos_constant have hx' : x ∈ lowerBounds (Set.range (stirlingSeq ∘ succ)) := by simpa [lowerBounds] using hx refine ⟨_, lt_of_lt_of_le x_pos (le_csInf (Set.range_nonempty _) hx'), ?_⟩ rw [← Filter.tendsto_add_atTop_iff_nat 1] exact tendsto_atTop_ciInf stirlingSeq'_antitone ⟨x, hx'⟩ /-! ### Part 2 https://proofwiki.org/wiki/Stirling%27s_Formula#Part_2 -/ /-- The sequence `n / (2 * n + 1)` tends to `1/2` -/ theorem tendsto_self_div_two_mul_self_add_one : Tendsto (fun n : β„• => (n : ℝ) / (2 * n + 1)) atTop (𝓝 (1 / 2)) := by conv => congr Β· skip Β· skip rw [one_div, ← add_zero (2 : ℝ)] refine (((tendsto_const_div_atTop_nhds_zero_nat 1).const_add (2 : ℝ)).invβ‚€ ((add_zero (2 : ℝ)).symm β–Έ two_ne_zero)).congr' (eventually_atTop.mpr ⟨1, fun n hn => ?_⟩) rw [add_div' (1 : ℝ) 2 n (cast_ne_zero.mpr (one_le_iff_ne_zero.mp hn)), inv_div] /-- For any `n β‰  0`, we have the identity `(stirlingSeq n)^4 / (stirlingSeq (2*n))^2 * (n / (2 * n + 1)) = W n`, where `W n` is the `n`-th partial product of Wallis' formula for `Ο€ / 2`. -/ theorem stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq (n : β„•) (hn : n β‰  0) : stirlingSeq n ^ 4 / stirlingSeq (2 * n) ^ 2 * (n / (2 * n + 1)) = Wallis.W n := by have : 4 = 2 * 2 := by rfl rw [stirlingSeq, this, pow_mul, stirlingSeq, Wallis.W_eq_factorial_ratio] simp_rw [div_pow, mul_pow] rw [sq_sqrt, sq_sqrt] any_goals positivity simp [field, ← exp_nsmul] ring_nf /-- Suppose the sequence `stirlingSeq` (defined above) has the limit `a β‰  0`. Then the Wallis sequence `W n` has limit `a^2 / 2`. -/ theorem second_wallis_limit (a : ℝ) (hane : a β‰  0) (ha : Tendsto stirlingSeq atTop (𝓝 a)) : Tendsto Wallis.W atTop (𝓝 (a ^ 2 / 2)) := by refine Tendsto.congr' (eventually_atTop.mpr ⟨1, fun n hn => stirlingSeq_pow_four_div_stirlingSeq_pow_two_eq n (one_le_iff_ne_zero.mp hn)⟩) ?_ have h : a ^ 2 / 2 = a ^ 4 / a ^ 2 * (1 / 2) := by rw [mul_one_div, ← mul_one_div (a ^ 4) (a ^ 2), one_div, ← pow_sub_of_lt a] simp rw [h] exact ((ha.pow 4).div ((ha.comp (tendsto_id.const_mul_atTop' two_pos)).pow 2) (pow_ne_zero 2 hane)).mul tendsto_self_div_two_mul_self_add_one /-- **Stirling's Formula** -/ theorem tendsto_stirlingSeq_sqrt_pi : Tendsto stirlingSeq atTop (𝓝 (βˆšΟ€)) := by obtain ⟨a, hapos, halimit⟩ := stirlingSeq_has_pos_limit_a have hΟ€ : Ο€ / 2 = a ^ 2 / 2 := tendsto_nhds_unique Wallis.tendsto_W_nhds_pi_div_two (second_wallis_limit a hapos.ne' halimit) rwa [(div_left_inj' (two_ne_zero' ℝ)).mp hΟ€, sqrt_sq hapos.le] /-- **Stirling's Formula**, formulated in terms of `Asymptotics.IsEquivalent`. -/ lemma factorial_isEquivalent_stirling : (fun n ↦ n ! : β„• β†’ ℝ) ~[atTop] fun n ↦ Real.sqrt (2 * n * Ο€) * (n / exp 1) ^ n := by refine Asymptotics.isEquivalent_of_tendsto_one ?_ ?_ Β· filter_upwards [eventually_ne_atTop 0] with n hn h exact absurd h (by positivity) Β· have : sqrt Ο€ β‰  0 := by positivity nth_rewrite 2 [← div_self this] convert tendsto_stirlingSeq_sqrt_pi.div tendsto_const_nhds this using 1 ext n simp [field, stirlingSeq, mul_right_comm] /-! ### Global bounds -/ /-- The Stirling sequence is bounded below by `βˆšΟ€`, for all positive naturals. Note that this bound holds for all `n > 0`, rather than for sufficiently large `n`: it is effective. -/ theorem sqrt_pi_le_stirlingSeq {n : β„•} (hn : n β‰  0) : βˆšΟ€ ≀ stirlingSeq n := match n, hn with | n + 1, _ => stirlingSeq'_antitone.le_of_tendsto (b := n) <| tendsto_stirlingSeq_sqrt_pi.comp (tendsto_add_atTop_nat 1) /-- Stirling's approximation gives a lower bound for `n!` for all `n`. The left-hand side is formulated to mimic the usual informal description of the approximation. See also `factorial_isEquivalent_stirling` which says these are asymptotically equivalent. That statement gives an upper bound also, but requires sufficiently large `n`. In contrast, this one is only a lower bound, but holds for all `n`. Sharper bounds due to Robbins are available, but are not yet formalised. -/ theorem le_factorial_stirling (n : β„•) : √(2 * Ο€ * n) * (n / exp 1) ^ n ≀ n ! := by obtain rfl | hn := eq_or_ne n 0 Β· simp have : √(2 * Ο€ * n) * (n / exp 1) ^ n = βˆšΟ€ * (√(2 * n) * (n / exp 1) ^ n) := by simp [sqrt_mul']; ring rw [this, ← le_div_iffβ‚€ (by positivity)] exact sqrt_pi_le_stirlingSeq hn /-- Stirling's approximation gives a lower bound for `log n!` for all positive `n`. The left-hand side is formulated in decreasing order in `n`: the higher order terms are first. This is a consequence of `le_factorial_stirling`, but is stated separately since the logarithmic version is sometimes more practical, and having this version eases algebraic calculations for applications. Sharper bounds due to Robbins are available, but are not yet formalised. These would add lower order terms (beginning with `(12 * n)⁻¹`) to the left-hand side. -/ theorem le_log_factorial_stirling {n : β„•} (hn : n β‰  0) : n * log n - n + log n / 2 + log (2 * Ο€) / 2 ≀ log n ! := by calc _ = (log (2 * Ο€) + log n) / 2 + n * (log n - 1) := by ring _ = log (√(2 * Ο€ * n) * (n / rexp 1) ^ n) := by rw [log_mul (x := √_), log_sqrt, log_mul (x := 2 * Ο€), log_pow, log_div, log_exp] <;> positivity _ ≀ _ := log_le_log (by positivity) (le_factorial_stirling n) end Stirling
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Choose.lean
import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Data.Nat.Cast.Field /-! # Binomial coefficients and factorial variants This file proves asymptotic theorems for binomial coefficients and factorial variants. ## Main statements * `isEquivalent_descFactorial` is the proof that `n.descFactorial k ~ n^k` as `n β†’ ∞`. * `isEquivalent_choose` is the proof that `n.choose k ~ n^k / k!` as `n β†’ ∞`. * `isTheta_choose` is the proof that `n.choose k = Θ(n^k)` as `n β†’ ∞`. -/ open Asymptotics Filter Nat Topology /-- `n.descFactorial k` is asymptotically equivalent to `n^k`. -/ lemma isEquivalent_descFactorial (k : β„•) : (fun (n : β„•) ↦ (n.descFactorial k : ℝ)) ~[atTop] (fun (n : β„•) ↦ (n^k : ℝ)) := by induction k with | zero => simpa using IsEquivalent.refl | succ k h => simp_rw [descFactorial_succ, cast_mul, _root_.pow_succ'] refine IsEquivalent.mul ?_ h have hz : βˆ€αΆ  (x : β„•) in atTop, (x : ℝ) β‰  0 := eventually_atTop.mpr ⟨1, fun n hn ↦ ne_of_gt (mod_cast hn)⟩ rw [isEquivalent_iff_tendsto_one hz, ← tendsto_add_atTop_iff_nat k] simpa using tendsto_natCast_div_add_atTop (k : ℝ) /-- `n.choose k` is asymptotically equivalent to `n^k / k!`. -/ theorem isEquivalent_choose (k : β„•) : (fun (n : β„•) ↦ (n.choose k : ℝ)) ~[atTop] (fun (n : β„•) ↦ (n^k / k.factorial : ℝ)) := by conv_lhs => intro n rw [choose_eq_descFactorial_div_factorial, cast_div (n.factorial_dvd_descFactorial k) (mod_cast k.factorial_ne_zero)] exact (isEquivalent_descFactorial k).div IsEquivalent.refl /-- `n.choose k` is big-theta `n^k`. -/ theorem isTheta_choose (k : β„•) : (fun (n : β„•) ↦ (n.choose k : ℝ)) =Θ[atTop] (fun (n : β„•) ↦ (n^k : ℝ)) := by apply (isEquivalent_choose k).trans_isTheta simp_rw [div_eq_mul_inv, mul_comm _ (_⁻¹)] exact isTheta_rfl.const_mul_left <| inv_ne_zero (mod_cast k.factorial_ne_zero)
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gamma/Deriv.lean
import Mathlib.Analysis.MellinTransform import Mathlib.Analysis.SpecialFunctions.Gamma.Basic /-! # Derivative of the Gamma function This file shows that the (complex) `Ξ“` function is complex-differentiable at all `s : β„‚` with `s βˆ‰ {-n : n ∈ β„•}`, as well as the real counterpart. ## Main results * `Complex.differentiableAt_Gamma`: `Ξ“` is complex-differentiable at all `s : β„‚` with `s βˆ‰ {-n : n ∈ β„•}`. * `Real.differentiableAt_Gamma`: `Ξ“` is real-differentiable at all `s : ℝ` with `s βˆ‰ {-n : n ∈ β„•}`. ## Tags Gamma -/ noncomputable section open Filter Set Real Asymptotics open scoped Topology namespace Complex /-! Now check that the `Ξ“` function is differentiable, wherever this makes sense. -/ section GammaHasDeriv /-- Rewrite the Gamma integral as an example of a Mellin transform. -/ theorem GammaIntegral_eq_mellin : GammaIntegral = mellin fun x => ↑(Real.exp (-x)) := funext fun s => by simp only [mellin, GammaIntegral, smul_eq_mul, mul_comm] /-- The derivative of the `Ξ“` integral, at any `s ∈ β„‚` with `1 < re s`, is given by the Mellin transform of `log t * exp (-t)`. -/ theorem hasDerivAt_GammaIntegral {s : β„‚} (hs : 0 < s.re) : HasDerivAt GammaIntegral (∫ t : ℝ in Ioi 0, t ^ (s - 1) * (Real.log t * Real.exp (-t))) s := by rw [GammaIntegral_eq_mellin] convert (mellin_hasDerivAt_of_isBigO_rpow (E := β„‚) _ _ (lt_add_one _) _ hs).2 Β· refine (Continuous.continuousOn ?_).locallyIntegrableOn measurableSet_Ioi exact continuous_ofReal.comp (Real.continuous_exp.comp continuous_neg) Β· rw [← isBigO_norm_left] simp_rw [norm_real, isBigO_norm_left] simpa only [neg_one_mul] using (isLittleO_exp_neg_mul_rpow_atTop zero_lt_one _).isBigO Β· simp_rw [neg_zero, rpow_zero] refine isBigO_const_of_tendsto (?_ : Tendsto _ _ (𝓝 (1 : β„‚))) one_ne_zero rw [(by simp : (1 : β„‚) = Real.exp (-0))] exact (continuous_ofReal.comp (Real.continuous_exp.comp continuous_neg)).continuousWithinAt theorem differentiableAt_GammaAux (s : β„‚) (n : β„•) (h1 : 1 - s.re < n) (h2 : βˆ€ m : β„•, s β‰  -m) : DifferentiableAt β„‚ (GammaAux n) s := by induction n generalizing s with | zero => refine (hasDerivAt_GammaIntegral ?_).differentiableAt rw [Nat.cast_zero] at h1; linarith | succ n hn => dsimp only [GammaAux] specialize hn (s + 1) have a : 1 - (s + 1).re < ↑n := by rw [Nat.cast_succ] at h1; rw [Complex.add_re, Complex.one_re]; linarith have b : βˆ€ m : β„•, s + 1 β‰  -m := by intro m; have := h2 (1 + m) contrapose! this rw [← eq_sub_iff_add_eq] at this simpa using this refine DifferentiableAt.div (DifferentiableAt.comp _ (hn a b) ?_) ?_ ?_ Β· rw [differentiableAt_add_const_iff (1 : β„‚)]; exact differentiableAt_id Β· exact differentiableAt_id Β· simpa using h2 0 @[fun_prop] theorem differentiableAt_Gamma (s : β„‚) (hs : βˆ€ m : β„•, s β‰  -m) : DifferentiableAt β„‚ Gamma s := by let n := ⌊1 - s.reβŒ‹β‚Š + 1 have hn : 1 - s.re < n := mod_cast Nat.lt_floor_add_one (1 - s.re) apply (differentiableAt_GammaAux s n hn hs).congr_of_eventuallyEq let S := {t : β„‚ | 1 - t.re < n} have : S ∈ 𝓝 s := by rw [mem_nhds_iff]; use S refine ⟨Subset.rfl, ?_, hn⟩ have : S = re ⁻¹' Ioi (1 - n : ℝ) := by ext; rw [preimage, Ioi, mem_setOf_eq, mem_setOf_eq, mem_setOf_eq]; exact sub_lt_comm rw [this] exact Continuous.isOpen_preimage continuous_re _ isOpen_Ioi apply eventuallyEq_of_mem this intro t ht; rw [mem_setOf_eq] at ht apply Gamma_eq_GammaAux; linarith end GammaHasDeriv /-- At `s = 0`, the Gamma function has a simple pole with residue 1. -/ theorem tendsto_self_mul_Gamma_nhds_zero : Tendsto (fun z : β„‚ => z * Gamma z) (𝓝[β‰ ] 0) (𝓝 1) := by rw [show 𝓝 (1 : β„‚) = 𝓝 (Gamma (0 + 1)) by simp only [zero_add, Complex.Gamma_one]] convert (Tendsto.mono_left _ nhdsWithin_le_nhds).congr' (eventuallyEq_of_mem self_mem_nhdsWithin Complex.Gamma_add_one) using 1 refine ContinuousAt.comp (g := Gamma) ?_ (continuous_id.add continuous_const).continuousAt refine (Complex.differentiableAt_Gamma _ fun m => ?_).continuousAt rw [zero_add, ← ofReal_natCast, ← ofReal_neg, ← ofReal_one, Ne, ofReal_inj] refine (lt_of_le_of_lt ?_ zero_lt_one).ne' exact neg_nonpos.mpr (Nat.cast_nonneg _) end Complex namespace Real @[fun_prop] theorem differentiableAt_Gamma {s : ℝ} (hs : βˆ€ m : β„•, s β‰  -m) : DifferentiableAt ℝ Gamma s := by refine (Complex.differentiableAt_Gamma _ ?_).hasDerivAt.real_of_complex.differentiableAt simp_rw [← Complex.ofReal_natCast, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] exact hs end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gamma/Basic.lean
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals import Mathlib.MeasureTheory.Integral.ExpDecay /-! # The Gamma function This file defines the `Ξ“` function (of a real or complex variable `s`). We define this by Euler's integral `Ξ“(s) = ∫ x in Ioi 0, exp (-x) * x ^ (s - 1)` in the range where this integral converges (i.e., for `0 < s` in the real case, and `0 < re s` in the complex case). We show that this integral satisfies `Ξ“(1) = 1` and `Ξ“(s + 1) = s * Ξ“(s)`; hence we can define `Ξ“(s)` for all `s` as the unique function satisfying this recurrence and agreeing with Euler's integral in the convergence range. (If `s = -n` for `n ∈ β„•`, then the function is undefined, and we set it to be `0` by convention.) ## Gamma function: main statements (complex case) * `Complex.Gamma`: the `Ξ“` function (of a complex variable). * `Complex.Gamma_eq_integral`: for `0 < re s`, `Ξ“(s)` agrees with Euler's integral. * `Complex.Gamma_add_one`: for all `s : β„‚` with `s β‰  0`, we have `Ξ“ (s + 1) = s Ξ“(s)`. * `Complex.Gamma_nat_eq_factorial`: for all `n : β„•` we have `Ξ“ (n + 1) = n!`. ## Gamma function: main statements (real case) * `Real.Gamma`: the `Ξ“` function (of a real variable). * Real counterparts of all the properties of the complex Gamma function listed above: `Real.Gamma_eq_integral`, `Real.Gamma_add_one`, `Real.Gamma_nat_eq_factorial`. ## Tags Gamma -/ noncomputable section open Filter intervalIntegral Set Real MeasureTheory Asymptotics open scoped Nat Topology ComplexConjugate namespace Real /-- Asymptotic bound for the `Ξ“` function integrand. -/ theorem Gamma_integrand_isLittleO (s : ℝ) : (fun x : ℝ => exp (-x) * x ^ s) =o[atTop] fun x : ℝ => exp (-(1 / 2) * x) := by refine isLittleO_of_tendsto (fun x hx => ?_) ?_ Β· exfalso; exact (exp_pos (-(1 / 2) * x)).ne' hx have : (fun x : ℝ => exp (-x) * x ^ s / exp (-(1 / 2) * x)) = (fun x : ℝ => exp (1 / 2 * x) / x ^ s)⁻¹ := by ext1 x simp [field, ← exp_nsmul, exp_neg] rw [this] exact (tendsto_exp_mul_div_rpow_atTop s (1 / 2) one_half_pos).inv_tendsto_atTop /-- The Euler integral for the `Ξ“` function converges for positive real `s`. -/ theorem GammaIntegral_convergent {s : ℝ} (h : 0 < s) : IntegrableOn (fun x : ℝ => exp (-x) * x ^ (s - 1)) (Ioi 0) := by rw [← Ioc_union_Ioi_eq_Ioi (@zero_le_one ℝ _ _ _ _), integrableOn_union] constructor Β· rw [← integrableOn_Icc_iff_integrableOn_Ioc] refine IntegrableOn.continuousOn_mul continuousOn_id.neg.rexp ?_ isCompact_Icc refine (intervalIntegrable_iff_integrableOn_Icc_of_le zero_le_one).mp ?_ exact intervalIntegrable_rpow' (by linarith) Β· refine integrable_of_isBigO_exp_neg one_half_pos ?_ (Gamma_integrand_isLittleO _).isBigO refine continuousOn_id.neg.rexp.mul (continuousOn_id.rpow_const ?_) intro x hx exact Or.inl ((zero_lt_one : (0 : ℝ) < 1).trans_le hx).ne' end Real namespace Complex /- Technical note: In defining the Gamma integrand exp (-x) * x ^ (s - 1) for s complex, we have to make a choice between ↑(Real.exp (-x)), Complex.exp (↑(-x)), and Complex.exp (-↑x), all of which are equal but not definitionally so. We use the first of these throughout. -/ /-- The integral defining the `Ξ“` function converges for complex `s` with `0 < re s`. This is proved by reduction to the real case. -/ theorem GammaIntegral_convergent {s : β„‚} (hs : 0 < s.re) : IntegrableOn (fun x => (-x).exp * x ^ (s - 1) : ℝ β†’ β„‚) (Ioi 0) := by constructor Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi apply (continuous_ofReal.comp continuous_neg.rexp).continuousOn.mul apply continuousOn_of_forall_continuousAt intro x hx have : ContinuousAt (fun x : β„‚ => x ^ (s - 1)) ↑x := continuousAt_cpow_const <| ofReal_mem_slitPlane.2 hx exact ContinuousAt.comp this continuous_ofReal.continuousAt Β· rw [← hasFiniteIntegral_norm_iff] refine HasFiniteIntegral.congr (Real.GammaIntegral_convergent hs).2 ?_ apply (ae_restrict_iff' measurableSet_Ioi).mpr filter_upwards with x hx rw [norm_mul, Complex.norm_of_nonneg <| le_of_lt <| exp_pos <| -x, norm_cpow_eq_rpow_re_of_pos hx _] simp /-- Euler's integral for the `Ξ“` function (of a complex variable `s`), defined as `∫ x in Ioi 0, exp (-x) * x ^ (s - 1)`. See `Complex.GammaIntegral_convergent` for a proof of the convergence of the integral for `0 < re s`. -/ def GammaIntegral (s : β„‚) : β„‚ := ∫ x in Ioi (0 : ℝ), ↑(-x).exp * ↑x ^ (s - 1) theorem GammaIntegral_conj (s : β„‚) : GammaIntegral (conj s) = conj (GammaIntegral s) := by rw [GammaIntegral, GammaIntegral, ← integral_conj] refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ dsimp only rw [RingHom.map_mul, conj_ofReal, cpow_def_of_ne_zero (ofReal_ne_zero.mpr (ne_of_gt hx)), cpow_def_of_ne_zero (ofReal_ne_zero.mpr (ne_of_gt hx)), ← exp_conj, RingHom.map_mul, ← ofReal_log (le_of_lt hx), conj_ofReal, RingHom.map_sub, RingHom.map_one] theorem GammaIntegral_ofReal (s : ℝ) : GammaIntegral ↑s = ↑(∫ x : ℝ in Ioi 0, Real.exp (-x) * x ^ (s - 1)) := by have : βˆ€ r : ℝ, Complex.ofReal r = @RCLike.ofReal β„‚ _ r := fun r => rfl rw [GammaIntegral] conv_rhs => rw [this, ← _root_.integral_ofReal] refine setIntegral_congr_fun measurableSet_Ioi ?_ intro x hx; dsimp only conv_rhs => rw [← this] rw [ofReal_mul, ofReal_cpow (mem_Ioi.mp hx).le] simp @[simp] theorem GammaIntegral_one : GammaIntegral 1 = 1 := by simpa only [← ofReal_one, GammaIntegral_ofReal, ofReal_inj, sub_self, rpow_zero, mul_one] using integral_exp_neg_Ioi_zero end Complex /-! Now we establish the recurrence relation `Ξ“(s + 1) = s * Ξ“(s)` using integration by parts. -/ namespace Complex section GammaRecurrence /-- The indefinite version of the `Ξ“` function, `Ξ“(s, X) = ∫ x ∈ 0..X, exp(-x) x ^ (s - 1)`. -/ def partialGamma (s : β„‚) (X : ℝ) : β„‚ := ∫ x in 0..X, (-x).exp * x ^ (s - 1) theorem tendsto_partialGamma {s : β„‚} (hs : 0 < s.re) : Tendsto (fun X : ℝ => partialGamma s X) atTop (𝓝 <| GammaIntegral s) := intervalIntegral_tendsto_integral_Ioi 0 (GammaIntegral_convergent hs) tendsto_id private theorem Gamma_integrand_intervalIntegrable (s : β„‚) {X : ℝ} (hs : 0 < s.re) (hX : 0 ≀ X) : IntervalIntegrable (fun x => (-x).exp * x ^ (s - 1) : ℝ β†’ β„‚) volume 0 X := by rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hX] exact IntegrableOn.mono_set (GammaIntegral_convergent hs) Ioc_subset_Ioi_self private theorem Gamma_integrand_deriv_integrable_A {s : β„‚} (hs : 0 < s.re) {X : ℝ} (hX : 0 ≀ X) : IntervalIntegrable (fun x => -((-x).exp * x ^ s) : ℝ β†’ β„‚) volume 0 X := by convert (Gamma_integrand_intervalIntegrable (s + 1) _ hX).neg Β· simp only [ofReal_exp, ofReal_neg, add_sub_cancel_right]; rfl Β· simp only [add_re, one_re]; linarith private theorem Gamma_integrand_deriv_integrable_B {s : β„‚} (hs : 0 < s.re) {Y : ℝ} (hY : 0 ≀ Y) : IntervalIntegrable (fun x : ℝ => (-x).exp * (s * x ^ (s - 1)) : ℝ β†’ β„‚) volume 0 Y := by have : (fun x => (-x).exp * (s * x ^ (s - 1)) : ℝ β†’ β„‚) = (fun x => s * ((-x).exp * x ^ (s - 1)) : ℝ β†’ β„‚) := by ext1; ring rw [this, intervalIntegrable_iff_integrableOn_Ioc_of_le hY] constructor Β· refine (continuousOn_const.mul ?_).aestronglyMeasurable measurableSet_Ioc apply (continuous_ofReal.comp continuous_neg.rexp).continuousOn.mul apply continuousOn_of_forall_continuousAt intro x hx refine (?_ : ContinuousAt (fun x : β„‚ => x ^ (s - 1)) _).comp continuous_ofReal.continuousAt exact continuousAt_cpow_const <| ofReal_mem_slitPlane.2 hx.1 rw [← hasFiniteIntegral_norm_iff] simp_rw [norm_mul] refine (((Real.GammaIntegral_convergent hs).mono_set Ioc_subset_Ioi_self).hasFiniteIntegral.congr ?_).const_mul _ rw [EventuallyEq, ae_restrict_iff'] Β· filter_upwards with x hx rw [Complex.norm_of_nonneg (exp_pos _).le, norm_cpow_eq_rpow_re_of_pos hx.1] simp Β· exact measurableSet_Ioc /-- The recurrence relation for the indefinite version of the `Ξ“` function. -/ theorem partialGamma_add_one {s : β„‚} (hs : 0 < s.re) {X : ℝ} (hX : 0 ≀ X) : partialGamma (s + 1) X = s * partialGamma s X - (-X).exp * X ^ s := by rw [partialGamma, partialGamma, add_sub_cancel_right] have F_der_I : βˆ€ x : ℝ, x ∈ Ioo 0 X β†’ HasDerivAt (fun x => (-x).exp * x ^ s : ℝ β†’ β„‚) (-((-x).exp * x ^ s) + (-x).exp * (s * x ^ (s - 1))) x := by intro x hx have d1 : HasDerivAt (fun y : ℝ => (-y).exp) (-(-x).exp) x := by simpa using (hasDerivAt_neg x).exp have d2 : HasDerivAt (fun y : ℝ => (y : β„‚) ^ s) (s * x ^ (s - 1)) x := by have t := @HasDerivAt.cpow_const _ _ _ s (hasDerivAt_id ↑x) ?_ Β· simpa only [mul_one] using t.comp_ofReal Β· exact ofReal_mem_slitPlane.2 hx.1 simpa only [ofReal_neg, neg_mul] using d1.ofReal_comp.mul d2 have cont := (continuous_ofReal.comp continuous_neg.rexp).mul (continuous_ofReal_cpow_const hs) have der_ible := (Gamma_integrand_deriv_integrable_A hs hX).add (Gamma_integrand_deriv_integrable_B hs hX) have int_eval := integral_eq_sub_of_hasDerivAt_of_le hX cont.continuousOn F_der_I der_ible -- We are basically done here but manipulating the output into the right form is fiddly. apply_fun fun x : β„‚ => -x at int_eval rw [intervalIntegral.integral_add (Gamma_integrand_deriv_integrable_A hs hX) (Gamma_integrand_deriv_integrable_B hs hX), intervalIntegral.integral_neg, neg_add, neg_neg] at int_eval rw [eq_sub_of_add_eq int_eval, sub_neg_eq_add, neg_sub, add_comm, add_sub] have : (fun x => (-x).exp * (s * x ^ (s - 1)) : ℝ β†’ β„‚) = (fun x => s * (-x).exp * x ^ (s - 1) : ℝ β†’ β„‚) := by ext1; ring rw [this] rw [← intervalIntegral.integral_const_mul, ofReal_zero, zero_cpow] Β· rw [mul_zero, add_zero]; congr 2; ext1; ring Β· contrapose! hs; rw [hs, zero_re] /-- The recurrence relation for the `Ξ“` integral. -/ theorem GammaIntegral_add_one {s : β„‚} (hs : 0 < s.re) : GammaIntegral (s + 1) = s * GammaIntegral s := by suffices Tendsto (s + 1).partialGamma atTop (𝓝 <| s * GammaIntegral s) by refine tendsto_nhds_unique ?_ this apply tendsto_partialGamma; rw [add_re, one_re]; linarith have : (fun X : ℝ => s * partialGamma s X - X ^ s * (-X).exp) =αΆ [atTop] (s + 1).partialGamma := by apply eventuallyEq_of_mem (Ici_mem_atTop (0 : ℝ)) intro X hX rw [partialGamma_add_one hs (mem_Ici.mp hX)] ring_nf refine Tendsto.congr' this ?_ suffices Tendsto (fun X => -X ^ s * (-X).exp : ℝ β†’ β„‚) atTop (𝓝 0) by simpa using Tendsto.add (Tendsto.const_mul s (tendsto_partialGamma hs)) this rw [tendsto_zero_iff_norm_tendsto_zero] have : (fun e : ℝ => β€–-(e : β„‚) ^ s * (-e).expβ€–) =αΆ [atTop] fun e : ℝ => e ^ s.re * (-1 * e).exp := by refine eventuallyEq_of_mem (Ioi_mem_atTop 0) ?_ intro x hx; dsimp only rw [norm_mul, norm_neg, norm_cpow_eq_rpow_re_of_pos hx, Complex.norm_of_nonneg (exp_pos (-x)).le, neg_mul, one_mul] exact (tendsto_congr' this).mpr (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero _ _ zero_lt_one) end GammaRecurrence /-! Now we define `Ξ“(s)` on the whole complex plane, by recursion. -/ section GammaDef /-- The `n`th function in this family is `Ξ“(s)` if `-n < s.re`, and junk otherwise. -/ noncomputable def GammaAux : β„• β†’ β„‚ β†’ β„‚ | 0 => GammaIntegral | n + 1 => fun s : β„‚ => GammaAux n (s + 1) / s theorem GammaAux_recurrence1 (s : β„‚) (n : β„•) (h1 : -s.re < ↑n) : GammaAux n s = GammaAux n (s + 1) / s := by induction n generalizing s with | zero => simp only [CharP.cast_eq_zero, Left.neg_neg_iff] at h1 dsimp only [GammaAux]; rw [GammaIntegral_add_one h1] rw [mul_comm, mul_div_cancel_rightβ‚€]; contrapose! h1; rw [h1] simp | succ n hn => dsimp only [GammaAux] have hh1 : -(s + 1).re < n := by rw [Nat.cast_add, Nat.cast_one] at h1 rw [add_re, one_re]; linarith rw [← hn (s + 1) hh1] theorem GammaAux_recurrence2 (s : β„‚) (n : β„•) (h1 : -s.re < ↑n) : GammaAux n s = GammaAux (n + 1) s := by rcases n with - | n Β· simp only [CharP.cast_eq_zero, Left.neg_neg_iff] at h1 dsimp only [GammaAux] rw [GammaIntegral_add_one h1, mul_div_cancel_leftβ‚€] rintro rfl rw [zero_re] at h1 exact h1.false Β· dsimp only [GammaAux] have : GammaAux n (s + 1 + 1) / (s + 1) = GammaAux n (s + 1) := by have hh1 : -(s + 1).re < n := by rw [Nat.cast_add, Nat.cast_one] at h1 rw [add_re, one_re]; linarith rw [GammaAux_recurrence1 (s + 1) n hh1] rw [this] /-- The `Ξ“` function (of a complex variable `s`). -/ @[pp_nodot] irreducible_def Gamma (s : β„‚) : β„‚ := GammaAux ⌊1 - s.reβŒ‹β‚Š s theorem Gamma_eq_GammaAux (s : β„‚) (n : β„•) (h1 : -s.re < ↑n) : Gamma s = GammaAux n s := by have u : βˆ€ k : β„•, GammaAux (⌊1 - s.reβŒ‹β‚Š + k) s = Gamma s := fun k ↦ by induction k with | zero => simp [Gamma] | succ k hk => rw [← hk, ← add_assoc] refine (GammaAux_recurrence2 s (⌊1 - s.reβŒ‹β‚Š + k) ?_).symm rw [Nat.cast_add] have i0 := Nat.sub_one_lt_floor (1 - s.re) simp only [sub_sub_cancel_left] at i0 refine lt_add_of_lt_of_nonneg i0 ?_ rw [← Nat.cast_zero, Nat.cast_le]; exact Nat.zero_le k convert (u <| n - ⌊1 - s.reβŒ‹β‚Š).symm; rw [Nat.add_sub_of_le] by_cases h : 0 ≀ 1 - s.re Β· apply Nat.le_of_lt_succ exact_mod_cast lt_of_le_of_lt (Nat.floor_le h) (by linarith : 1 - s.re < n + 1) Β· rw [Nat.floor_of_nonpos] Β· cutsat Β· linarith /-- The recurrence relation for the `Ξ“` function. -/ theorem Gamma_add_one (s : β„‚) (h2 : s β‰  0) : Gamma (s + 1) = s * Gamma s := by let n := ⌊1 - s.reβŒ‹β‚Š have t1 : -s.re < n := by simpa only [sub_sub_cancel_left] using Nat.sub_one_lt_floor (1 - s.re) have t2 : -(s + 1).re < n := by rw [add_re, one_re]; linarith rw [Gamma_eq_GammaAux s n t1, Gamma_eq_GammaAux (s + 1) n t2, GammaAux_recurrence1 s n t1] field theorem Gamma_eq_integral {s : β„‚} (hs : 0 < s.re) : Gamma s = GammaIntegral s := Gamma_eq_GammaAux s 0 (by norm_cast; linarith) @[simp] theorem Gamma_one : Gamma 1 = 1 := by rw [Gamma_eq_integral] <;> simp theorem Gamma_nat_eq_factorial (n : β„•) : Gamma (n + 1) = n ! := by induction n with | zero => simp | succ n hn => rw [Gamma_add_one n.succ <| Nat.cast_ne_zero.mpr <| Nat.succ_ne_zero n] simp only [Nat.cast_succ, Nat.factorial_succ, Nat.cast_mul] congr @[simp] theorem Gamma_ofNat_eq_factorial (n : β„•) [(n + 1).AtLeastTwo] : Gamma (ofNat(n + 1) : β„‚) = n ! := mod_cast Gamma_nat_eq_factorial (n : β„•) /-- At `0` the Gamma function is undefined; by convention we assign it the value `0`. -/ @[simp] theorem Gamma_zero : Gamma 0 = 0 := by simp_rw [Gamma, zero_re, sub_zero, Nat.floor_one, GammaAux, div_zero] /-- At `-n` for `n ∈ β„•`, the Gamma function is undefined; by convention we assign it the value 0. -/ theorem Gamma_neg_nat_eq_zero (n : β„•) : Gamma (-n) = 0 := by induction n with | zero => rw [Nat.cast_zero, neg_zero, Gamma_zero] | succ n IH => have A : -(n.succ : β„‚) β‰  0 := by rw [neg_ne_zero, Nat.cast_ne_zero] apply Nat.succ_ne_zero have : -(n : β„‚) = -↑n.succ + 1 := by simp rw [this, Gamma_add_one _ A] at IH contrapose! IH exact mul_ne_zero A IH theorem Gamma_conj (s : β„‚) : Gamma (conj s) = conj (Gamma s) := by suffices βˆ€ (n : β„•) (s : β„‚), GammaAux n (conj s) = conj (GammaAux n s) by simp [Gamma, this] intro n induction n with | zero => rw [GammaAux]; exact GammaIntegral_conj | succ n IH => intro s rw [GammaAux] dsimp only rw [div_eq_mul_inv _ s, RingHom.map_mul, conj_inv, ← div_eq_mul_inv] suffices conj s + 1 = conj (s + 1) by rw [this, IH] rw [RingHom.map_add, RingHom.map_one] /-- Expresses the integral over `Ioi 0` of `t ^ (a - 1) * exp (-(r * t))` in terms of the Gamma function, for complex `a`. -/ lemma integral_cpow_mul_exp_neg_mul_Ioi {a : β„‚} {r : ℝ} (ha : 0 < a.re) (hr : 0 < r) : ∫ (t : ℝ) in Ioi 0, t ^ (a - 1) * exp (-(r * t)) = (1 / r) ^ a * Gamma a := by have aux : (1 / r : β„‚) ^ a = 1 / r * (1 / r) ^ (a - 1) := by nth_rewrite 2 [← cpow_one (1 / r : β„‚)] rw [← cpow_add _ _ (one_div_ne_zero <| ofReal_ne_zero.mpr hr.ne'), add_sub_cancel] calc _ = ∫ (t : ℝ) in Ioi 0, (1 / r) ^ (a - 1) * (r * t) ^ (a - 1) * exp (-(r * t)) := by refine MeasureTheory.setIntegral_congr_fun measurableSet_Ioi (fun x hx ↦ ?_) rw [mem_Ioi] at hx rw [mul_cpow_ofReal_nonneg hr.le hx.le, ← mul_assoc, one_div, ← ofReal_inv, ← mul_cpow_ofReal_nonneg (inv_pos.mpr hr).le hr.le, ← ofReal_mul r⁻¹, inv_mul_cancelβ‚€ hr.ne', ofReal_one, one_cpow, one_mul] _ = 1 / r * ∫ (t : ℝ) in Ioi 0, (1 / r) ^ (a - 1) * t ^ (a - 1) * exp (-t) := by simp_rw [← ofReal_mul] rw [integral_comp_mul_left_Ioi (fun x ↦ _ * x ^ (a - 1) * exp (-x)) _ hr, mul_zero, real_smul, ← one_div, ofReal_div, ofReal_one] _ = 1 / r * (1 / r : β„‚) ^ (a - 1) * (∫ (t : ℝ) in Ioi 0, t ^ (a - 1) * exp (-t)) := by simp_rw [← MeasureTheory.integral_const_mul, mul_assoc] _ = (1 / r) ^ a * Gamma a := by rw [aux, Gamma_eq_integral ha] congr 2 with x rw [ofReal_exp, ofReal_neg, mul_comm] end GammaDef end Complex namespace Real /-- The `Ξ“` function (of a real variable `s`). -/ @[pp_nodot] def Gamma (s : ℝ) : ℝ := (Complex.Gamma s).re theorem Gamma_eq_integral {s : ℝ} (hs : 0 < s) : Gamma s = ∫ x in Ioi 0, exp (-x) * x ^ (s - 1) := by rw [Gamma, Complex.Gamma_eq_integral (by rwa [Complex.ofReal_re] : 0 < Complex.re s)] dsimp only [Complex.GammaIntegral] simp_rw [← Complex.ofReal_one, ← Complex.ofReal_sub] suffices ∫ x : ℝ in Ioi 0, ↑(exp (-x)) * (x : β„‚) ^ ((s - 1 : ℝ) : β„‚) = ∫ x : ℝ in Ioi 0, ((exp (-x) * x ^ (s - 1) : ℝ) : β„‚) by have cc : βˆ€ r : ℝ, Complex.ofReal r = @RCLike.ofReal β„‚ _ r := fun r => rfl conv_lhs => rw [this]; enter [1, 2, x]; rw [cc] rw [_root_.integral_ofReal, ← cc, Complex.ofReal_re] refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ push_cast rw [Complex.ofReal_cpow (le_of_lt hx)] push_cast; rfl theorem Gamma_add_one {s : ℝ} (hs : s β‰  0) : Gamma (s + 1) = s * Gamma s := by simp_rw [Gamma] rw [Complex.ofReal_add, Complex.ofReal_one, Complex.Gamma_add_one, Complex.re_ofReal_mul] rwa [Complex.ofReal_ne_zero] @[simp] theorem Gamma_one : Gamma 1 = 1 := by rw [Gamma, Complex.ofReal_one, Complex.Gamma_one, Complex.one_re] theorem _root_.Complex.Gamma_ofReal (s : ℝ) : Complex.Gamma (s : β„‚) = Gamma s := by rw [Gamma, eq_comm, ← Complex.conj_eq_iff_re, ← Complex.Gamma_conj, Complex.conj_ofReal] theorem Gamma_nat_eq_factorial (n : β„•) : Gamma (n + 1) = n ! := by rw [Gamma, Complex.ofReal_add, Complex.ofReal_natCast, Complex.ofReal_one, Complex.Gamma_nat_eq_factorial, ← Complex.ofReal_natCast, Complex.ofReal_re] @[simp] theorem Gamma_ofNat_eq_factorial (n : β„•) [(n + 1).AtLeastTwo] : Gamma (ofNat(n + 1) : ℝ) = n ! := mod_cast Gamma_nat_eq_factorial (n : β„•) /-- At `0` the Gamma function is undefined; by convention we assign it the value `0`. -/ @[simp] theorem Gamma_zero : Gamma 0 = 0 := by simpa only [← Complex.ofReal_zero, Complex.Gamma_ofReal, Complex.ofReal_inj] using Complex.Gamma_zero /-- At `-n` for `n ∈ β„•`, the Gamma function is undefined; by convention we assign it the value `0`. -/ theorem Gamma_neg_nat_eq_zero (n : β„•) : Gamma (-n) = 0 := by simpa only [← Complex.ofReal_natCast, ← Complex.ofReal_neg, Complex.Gamma_ofReal, Complex.ofReal_eq_zero] using Complex.Gamma_neg_nat_eq_zero n theorem Gamma_pos_of_pos {s : ℝ} (hs : 0 < s) : 0 < Gamma s := by rw [Gamma_eq_integral hs] have : (Function.support fun x : ℝ => exp (-x) * x ^ (s - 1)) ∩ Ioi 0 = Ioi 0 := by rw [inter_eq_right] intro x hx rw [Function.mem_support] exact mul_ne_zero (exp_pos _).ne' (rpow_pos_of_pos hx _).ne' rw [setIntegral_pos_iff_support_of_nonneg_ae] Β· rw [this, volume_Ioi, ← ENNReal.ofReal_zero] exact ENNReal.ofReal_lt_top Β· refine eventually_of_mem (self_mem_ae_restrict measurableSet_Ioi) ?_ exact fun x hx => (mul_pos (exp_pos _) (rpow_pos_of_pos hx _)).le Β· exact GammaIntegral_convergent hs theorem Gamma_nonneg_of_nonneg {s : ℝ} (hs : 0 ≀ s) : 0 ≀ Gamma s := by obtain rfl | h := eq_or_lt_of_le hs Β· rw [Gamma_zero] Β· exact (Gamma_pos_of_pos h).le open Complex in /-- Expresses the integral over `Ioi 0` of `t ^ (a - 1) * exp (-(r * t))`, for positive real `r`, in terms of the Gamma function. -/ lemma integral_rpow_mul_exp_neg_mul_Ioi {a r : ℝ} (ha : 0 < a) (hr : 0 < r) : ∫ t : ℝ in Ioi 0, t ^ (a - 1) * exp (-(r * t)) = (1 / r) ^ a * Gamma a := by rw [← ofReal_inj, ofReal_mul, ← Gamma_ofReal, ofReal_cpow (by positivity), ofReal_div] convert integral_cpow_mul_exp_neg_mul_Ioi (by rwa [ofReal_re] : 0 < (a : β„‚).re) hr refine integral_ofReal.symm.trans <| setIntegral_congr_fun measurableSet_Ioi (fun t ht ↦ ?_) norm_cast simp_rw [← ofReal_cpow ht.le, RCLike.ofReal_mul, coe_algebraMap] open Lean.Meta Qq Mathlib.Meta.Positivity in /-- The `positivity` extension which identifies expressions of the form `Gamma a`. -/ @[positivity Gamma (_ : ℝ)] def _root_.Mathlib.Meta.Positivity.evalGamma : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(Gamma $a) => match ← core q(inferInstance) q(inferInstance) a with | .positive pa => assertInstancesCommute pure (.positive q(Gamma_pos_of_pos $pa)) | .nonnegative pa => assertInstancesCommute pure (.nonnegative q(Gamma_nonneg_of_nonneg $pa)) | _ => pure .none | _, _, _ => throwError "failed to match on Gamma application" /-- The Gamma function does not vanish on `ℝ` (except at non-positive integers, where the function is mathematically undefined and we set it to `0` by convention). -/ theorem Gamma_ne_zero {s : ℝ} (hs : βˆ€ m : β„•, s β‰  -m) : Gamma s β‰  0 := by suffices βˆ€ {n : β„•}, -(n : ℝ) < s β†’ Gamma s β‰  0 by apply this swap Β· exact ⌊-sβŒ‹β‚Š + 1 rw [neg_lt, Nat.cast_add, Nat.cast_one] exact Nat.lt_floor_add_one _ intro n induction n generalizing s with | zero => intro hs refine (Gamma_pos_of_pos ?_).ne' rwa [Nat.cast_zero, neg_zero] at hs | succ _ n_ih => intro hs' have : Gamma (s + 1) β‰  0 := by apply n_ih Β· intro m specialize hs (1 + m) contrapose! hs rw [← eq_sub_iff_add_eq] at hs rw [hs] push_cast ring Β· rw [Nat.cast_add, Nat.cast_one, neg_add] at hs' linarith rw [Gamma_add_one, mul_ne_zero_iff] at this Β· exact this.2 Β· simpa using hs 0 theorem Gamma_eq_zero_iff (s : ℝ) : Gamma s = 0 ↔ βˆƒ m : β„•, s = -m := ⟨by contrapose!; exact Gamma_ne_zero, by rintro ⟨m, rfl⟩; exact Gamma_neg_nat_eq_zero m⟩ end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gamma/BohrMollerup.lean
import Mathlib.Analysis.SpecialFunctions.Gamma.Deriv import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral /-! # Convexity properties of the Gamma function In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique* positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and `f 1 = 1`. The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler limit formula, `Real.BohrMollerup.tendsto_logGammaSeq`, stating that for positive real `x` the sequence `x * log n + log n! - βˆ‘ (m : β„•) ∈ Finset.range (n + 1), log (x + m)` tends to `log Ξ“(x)` as `n β†’ ∞`. We prove that any function satisfying the hypotheses of the Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one such function; then we show that `Ξ“` satisfies these conditions. Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the context of this proof, we place them in a separate namespace `Real.BohrMollerup` to avoid clutter. (This includes the logarithmic form of the Euler limit formula, since later we will prove a more general form of the Euler limit formula valid for any real or complex `x`; see `Real.Gamma_seq_tendsto_Gamma` and `Complex.Gamma_seq_tendsto_Gamma` in the file `Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean`.) As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a later file). TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up to a constant, and it should be possible to deduce the value of this constant using Stirling's formula). -/ noncomputable section open Filter Set MeasureTheory open scoped Nat ENNReal Topology Real namespace Real section Convexity /-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form), proved using the HΓΆlder inequality applied to Euler's integral. -/ theorem Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ} (hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : Gamma (a * s + b * t) ≀ Gamma s ^ a * Gamma t ^ b := by -- We will apply HΓΆlder's inequality, for the conjugate exponents `p = 1 / a` -- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows: let f : ℝ β†’ ℝ β†’ ℝ β†’ ℝ := fun c u x => exp (-c * x) * x ^ (c * (u - 1)) have e : HolderConjugate (1 / a) (1 / b) := Real.holderConjugate_one_div ha hb hab have hab' : b = 1 - a := by linarith have hst : 0 < a * s + b * t := by positivity -- some properties of f: have posf : βˆ€ c u x : ℝ, x ∈ Ioi (0 : ℝ) β†’ 0 ≀ f c u x := fun c u x hx => mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le have posf' : βˆ€ c u : ℝ, βˆ€α΅ x : ℝ βˆ‚volume.restrict (Ioi 0), 0 ≀ f c u x := fun c u => (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ (posf c u)) have fpow : βˆ€ {c x : ℝ} (_ : 0 < c) (u : ℝ) (_ : 0 < x), exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c) := by intro c x hc u hx dsimp only [f] rw [mul_rpow (exp_pos _).le ((rpow_nonneg hx.le) _), ← exp_mul, ← rpow_mul hx.le] congr 2 <;> field -- show `f c u` is in `β„’p` for `p = 1/c`: have f_mem_Lp : βˆ€ {c u : ℝ} (hc : 0 < c) (hu : 0 < u), MemLp (f c u) (ENNReal.ofReal (1 / c)) (volume.restrict (Ioi 0)) := by intro c u hc hu have A : ENNReal.ofReal (1 / c) β‰  0 := by rwa [Ne, ENNReal.ofReal_eq_zero, not_le, one_div_pos] have B : ENNReal.ofReal (1 / c) β‰  ∞ := ENNReal.ofReal_ne_top rw [← memLp_norm_rpow_iff _ A B, ENNReal.toReal_ofReal (one_div_nonneg.mpr hc.le), ENNReal.div_self A B, memLp_one_iff_integrable] Β· apply Integrable.congr (GammaIntegral_convergent hu) refine eventuallyEq_of_mem (self_mem_ae_restrict measurableSet_Ioi) fun x hx => ?_ dsimp only rw [fpow hc u hx] congr 1 exact (norm_of_nonneg (posf _ _ x hx)).symm Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi refine (Continuous.continuousOn ?_).mul (continuousOn_of_forall_continuousAt fun x hx => ?_) Β· exact continuous_exp.comp (continuous_const.mul continuous_id') Β· exact continuousAt_rpow_const _ _ (Or.inl (mem_Ioi.mp hx).ne') -- now apply HΓΆlder: rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst] convert MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t) (f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1 Β· refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ dsimp only have A : exp (-x) = exp (-a * x) * exp (-b * x) := by rw [← exp_add, ← add_mul, ← neg_add, hab, neg_one_mul] have B : x ^ (a * s + b * t - 1) = x ^ (a * (s - 1)) * x ^ (b * (t - 1)) := by rw [← rpow_add hx, hab']; congr 1; ring rw [A, B] ring Β· rw [one_div_one_div, one_div_one_div] congr 2 <;> exact setIntegral_congr_fun measurableSet_Ioi fun x hx => fpow (by assumption) _ hx theorem convexOn_log_Gamma : ConvexOn ℝ (Ioi 0) (log ∘ Gamma) := by refine convexOn_iff_forall_pos.mpr ⟨convex_Ioi _, fun x hx y hy a b ha hb hab => ?_⟩ have : b = 1 - a := by linarith subst this simp_rw [Function.comp_apply, smul_eq_mul] simp only [mem_Ioi] at hx hy rw [← log_rpow, ← log_rpow, ← log_mul] Β· gcongr exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab all_goals positivity theorem convexOn_Gamma : ConvexOn ℝ (Ioi 0) Gamma := by refine ((convexOn_exp.subset (subset_univ _) ?_).comp convexOn_log_Gamma (exp_monotone.monotoneOn _)).congr fun x hx => exp_log (Gamma_pos_of_pos hx) rw [convex_iff_isPreconnected] refine isPreconnected_Ioi.image _ fun x hx => ContinuousAt.continuousWithinAt ?_ refine (differentiableAt_Gamma fun m => ?_).continuousAt.log (Gamma_pos_of_pos hx).ne' exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg (mem_Ioi.mp hx) (Nat.cast_nonneg m))).ne' end Convexity section BohrMollerup namespace BohrMollerup /-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to `log (Gamma x)` as `n β†’ ∞`. -/ def logGammaSeq (x : ℝ) (n : β„•) : ℝ := x * log n + log n ! - βˆ‘ m ∈ Finset.range (n + 1), log (x + m) variable {f : ℝ β†’ ℝ} {x : ℝ} {n : β„•} theorem f_nat_eq (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hn : n β‰  0) : f n = f 1 + log (n - 1)! := by refine Nat.le_induction (by simp) (fun m hm IH => ?_) n (Nat.one_le_iff_ne_zero.2 hn) have A : 0 < (m : ℝ) := Nat.cast_pos.2 hm simp only [hf_feq A, Nat.cast_add, Nat.cast_one, Nat.add_succ_sub_one, add_zero] rw [IH, add_assoc, ← log_mul (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) A.ne', ← Nat.cast_mul] conv_rhs => rw [← Nat.succ_pred_eq_of_pos hm, Nat.factorial_succ, mul_comm] congr exact (Nat.succ_pred_eq_of_pos hm).symm theorem f_add_nat_eq (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hx : 0 < x) (n : β„•) : f (x + n) = f x + βˆ‘ m ∈ Finset.range n, log (x + m) := by induction n with | zero => simp | succ n hn => have : x + n.succ = x + n + 1 := by push_cast; ring rw [this, hf_feq, hn] Β· rw [Finset.range_add_one, Finset.sum_insert Finset.notMem_range_self] abel Β· linarith [(Nat.cast_nonneg n : 0 ≀ (n : ℝ))] /-- Linear upper bound for `f (x + n)` on unit interval -/ theorem f_add_nat_le (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hn : n β‰  0) (hx : 0 < x) (hx' : x ≀ 1) : f (n + x) ≀ f n + x * log n := by have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) have : f n + x * log n = (1 - x) * f n + x * f (n + 1) := by rw [hf_feq hn']; ring rw [this, (by ring : (n : ℝ) + x = (1 - x) * n + x * (n + 1))] simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ)) (by linarith : 0 ≀ 1 - x) hx.le (by linarith) /-- Linear lower bound for `f (x + n)` on unit interval -/ theorem f_add_nat_ge (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hn : 2 ≀ n) (hx : 0 < x) : f n + x * log (n - 1) ≀ f (n + x) := by have npos : 0 < (n : ℝ) - 1 := by rw [← Nat.cast_one, sub_pos, Nat.cast_lt]; omega have c := (convexOn_iff_slope_mono_adjacent.mp <| hf_conv).2 npos (by linarith : 0 < (n : ℝ) + x) (by linarith : (n : ℝ) - 1 < (n : ℝ)) (by linarith) rw [add_sub_cancel_left, sub_sub_cancel, div_one] at c have : f (↑n - 1) = f n - log (↑n - 1) := by rw [eq_sub_iff_add_eq, ← hf_feq npos, sub_add_cancel] rwa [this, le_div_iffβ‚€ hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c theorem logGammaSeq_add_one (x : ℝ) (n : β„•) : logGammaSeq (x + 1) n = logGammaSeq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) := by dsimp only [Nat.factorial_succ, logGammaSeq] conv_rhs => rw [Finset.sum_range_succ', Nat.cast_zero, add_zero] rw [Nat.cast_mul, log_mul]; rotate_left Β· rw [Nat.cast_ne_zero]; exact Nat.succ_ne_zero n Β· rw [Nat.cast_ne_zero]; exact Nat.factorial_ne_zero n have : βˆ‘ m ∈ Finset.range (n + 1), log (x + 1 + ↑m) = βˆ‘ k ∈ Finset.range (n + 1), log (x + ↑(k + 1)) := by congr! 2 with m push_cast abel rw [← this, Nat.cast_add_one n] ring theorem le_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≀ 1) (n : β„•) : f x ≀ f 1 + x * log (n + 1) - x * log n + logGammaSeq x n := by rw [logGammaSeq, ← add_sub_assoc, le_sub_iff_add_le, ← f_add_nat_eq (@hf_feq) hx, add_comm x] refine (f_add_nat_le hf_conv (@hf_feq) (Nat.add_one_ne_zero n) hx hx').trans (le_of_eq ?_) rw [f_nat_eq @hf_feq (by cutsat : n + 1 β‰  0), Nat.add_sub_cancel, Nat.cast_add_one] ring theorem ge_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hx : 0 < x) (hn : n β‰  0) : f 1 + logGammaSeq x n ≀ f x := by dsimp [logGammaSeq] rw [← add_sub_assoc, sub_le_iff_le_add, ← f_add_nat_eq (@hf_feq) hx, add_comm x _] refine le_trans (le_of_eq ?_) (f_add_nat_ge hf_conv @hf_feq ?_ hx) Β· rw [f_nat_eq @hf_feq, Nat.add_sub_cancel, Nat.cast_add_one, add_sub_cancel_right] Β· ring Β· exact Nat.succ_ne_zero _ Β· cutsat theorem tendsto_logGammaSeq_of_le_one (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≀ 1) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by refine tendsto_of_tendsto_of_tendsto_of_le_of_le' (f := logGammaSeq x) (g := fun n ↦ f x - f 1 - x * (log (n + 1) - log n)) ?_ tendsto_const_nhds ?_ ?_ Β· have : f x - f 1 = f x - f 1 - x * 0 := by ring nth_rw 2 [this] exact Tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _) Β· filter_upwards with n rw [sub_le_iff_le_add', sub_le_iff_le_add'] convert le_logGammaSeq hf_conv (@hf_feq) hx hx' n using 1 ring Β· change βˆ€αΆ  n : β„• in atTop, logGammaSeq x n ≀ f x - f 1 filter_upwards [eventually_ne_atTop 0] with n hn using le_sub_iff_add_le'.mpr (ge_logGammaSeq hf_conv hf_feq hx hn) theorem tendsto_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = f y + log y) (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by suffices βˆ€ m : β„•, ↑m < x β†’ x ≀ m + 1 β†’ Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) by refine this ⌈x - 1βŒ‰β‚Š ?_ ?_ Β· rcases lt_or_ge x 1 with ⟨⟩ Β· rwa [Nat.ceil_eq_zero.mpr (by linarith : x - 1 ≀ 0), Nat.cast_zero] Β· convert Nat.ceil_lt_add_one (by linarith : 0 ≀ x - 1) abel Β· rw [← sub_le_iff_le_add]; exact Nat.le_ceil _ intro m induction m generalizing x with | zero => rw [Nat.cast_zero, zero_add] exact fun _ hx' => tendsto_logGammaSeq_of_le_one hf_conv (@hf_feq) hx hx' | succ m hm => intro hy hy' rw [Nat.cast_succ, ← sub_le_iff_le_add] at hy' rw [Nat.cast_succ, ← lt_sub_iff_add_lt] at hy specialize hm ((Nat.cast_nonneg _).trans_lt hy) hy hy' -- now massage gauss_product n (x - 1) into gauss_product (n - 1) x have : βˆ€αΆ  n : β„• in atTop, logGammaSeq (x - 1) n = logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1) := by refine Eventually.mp (eventually_ge_atTop 1) (Eventually.of_forall fun n hn => ?_) have := logGammaSeq_add_one (x - 1) (n - 1) rw [sub_add_cancel, Nat.sub_add_cancel hn] at this rw [this] ring replace hm := ((Tendsto.congr' this hm).add (tendsto_const_nhds : Tendsto (fun _ => log (x - 1)) _ _)).comp (tendsto_add_atTop_nat 1) have : ((fun x_1 : β„• => (fun n : β„• => logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1)) x_1 + (fun b : β„• => log (x - 1)) x_1) ∘ fun a : β„• => a + 1) = fun n => logGammaSeq x n + x * (log (↑n + 1) - log ↑n) := by ext1 n dsimp only [Function.comp_apply] rw [sub_add_cancel, Nat.add_sub_cancel] rw [this] at hm convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2 Β· ring Β· have := hf_feq ((Nat.cast_nonneg m).trans_lt hy) rw [sub_add_cancel] at this rw [this] ring theorem tendsto_log_gamma {x : ℝ} (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| log (Gamma x)) := by have : log (Gamma x) = (log ∘ Gamma) x - (log ∘ Gamma) 1 := by simp_rw [Function.comp_apply, Gamma_one, log_one, sub_zero] rw [this] refine BohrMollerup.tendsto_logGammaSeq convexOn_log_Gamma (fun {y} hy => ?_) hx rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] end BohrMollerup -- (namespace) /-- The **Bohr-Mollerup theorem**: the Gamma function is the *unique* log-convex, positive-valued function on the positive reals which satisfies `f 1 = 1` and `f (x + 1) = x * f x` for all `x`. -/ theorem eq_Gamma_of_log_convex {f : ℝ β†’ ℝ} (hf_conv : ConvexOn ℝ (Ioi 0) (log ∘ f)) (hf_feq : βˆ€ {y : ℝ}, 0 < y β†’ f (y + 1) = y * f y) (hf_pos : βˆ€ {y : ℝ}, 0 < y β†’ 0 < f y) (hf_one : f 1 = 1) : EqOn f Gamma (Ioi (0 : ℝ)) := by suffices EqOn (log ∘ f) (log ∘ Gamma) (Ioi (0 : ℝ)) from fun x hx ↦ log_injOn_pos (hf_pos hx) (Gamma_pos_of_pos hx) (this hx) intro x hx have e1 := BohrMollerup.tendsto_logGammaSeq hf_conv ?_ hx Β· rw [Function.comp_apply (f := log) (g := f) (x := 1), hf_one, log_one, sub_zero] at e1 exact tendsto_nhds_unique e1 (BohrMollerup.tendsto_log_gamma hx) Β· intro y hy rw [Function.comp_apply, Function.comp_apply, hf_feq hy, log_mul hy.ne' (hf_pos hy).ne'] ring end BohrMollerup -- (section) section StrictMono theorem Gamma_two : Gamma 2 = 1 := by simp [Nat.factorial_one] theorem Gamma_three_div_two_lt_one : Gamma (3 / 2) < 1 := by -- This can also be proved using the closed-form evaluation of `Gamma (1 / 2)` in -- `Mathlib/Analysis/SpecialFunctions/Gaussian.lean`, but we give a self-contained proof using -- log-convexity to avoid unnecessary imports. have A : (0 : ℝ) < 3 / 2 := by simp have := BohrMollerup.f_add_nat_le convexOn_log_Gamma (fun {y} hy => ?_) two_ne_zero one_half_pos (by norm_num : 1 / 2 ≀ (1 : ℝ)) swap Β· rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] rw [Function.comp_apply, Function.comp_apply, Nat.cast_two, Gamma_two, log_one, zero_add, (by norm_num : (2 : ℝ) + 1 / 2 = 3 / 2 + 1), Gamma_add_one A.ne', log_mul A.ne' (Gamma_pos_of_pos A).ne', ← le_sub_iff_add_le', log_le_iff_le_exp (Gamma_pos_of_pos A)] at this refine this.trans_lt (exp_lt_one_iff.mpr ?_) rw [mul_comm, ← mul_div_assoc, div_sub' two_ne_zero] refine div_neg_of_neg_of_pos ?_ two_pos rw [sub_neg, mul_one, ← Nat.cast_two, ← log_pow, ← exp_lt_exp, Nat.cast_two, exp_log two_pos, exp_log] <;> norm_num theorem Gamma_strictMonoOn_Ici : StrictMonoOn Gamma (Ici 2) := by convert convexOn_Gamma.strictMonoOn (by simp : (0 : ℝ) < 3 / 2) (by norm_num : (3 / 2 : ℝ) < 2) (Gamma_two.symm β–Έ Gamma_three_div_two_lt_one) symm rw [inter_eq_right] exact fun x hx => two_pos.trans_le <| mem_Ici.mp hx end StrictMono section Doubling /-! ## The Gamma doubling formula As a fun application of the Bohr-Mollerup theorem, we prove the Gamma-function doubling formula (for positive real `s`). The idea is that `2 ^ s * Gamma (s / 2) * Gamma (s / 2 + 1 / 2)` is log-convex and satisfies the Gamma functional equation, so it must actually be a constant multiple of `Gamma`, and we can compute the constant by specialising at `s = 1`. -/ /-- Auxiliary definition for the doubling formula (we'll show this is equal to `Gamma s`) -/ def doublingGamma (s : ℝ) : ℝ := Gamma (s / 2) * Gamma (s / 2 + 1 / 2) * 2 ^ (s - 1) / βˆšΟ€ theorem doublingGamma_add_one (s : ℝ) (hs : s β‰  0) : doublingGamma (s + 1) = s * doublingGamma s := by rw [doublingGamma, doublingGamma, (by abel : s + 1 - 1 = s - 1 + 1), add_div, add_assoc, add_halves (1 : ℝ), Gamma_add_one (div_ne_zero hs two_ne_zero), rpow_add two_pos, rpow_one] ring theorem doublingGamma_one : doublingGamma 1 = 1 := by simp_rw [doublingGamma, Gamma_one_half_eq, add_halves (1 : ℝ), sub_self, Gamma_one, mul_one, rpow_zero, mul_one, div_self (sqrt_ne_zero'.mpr pi_pos)] theorem log_doublingGamma_eq : EqOn (log ∘ doublingGamma) (fun s => log (Gamma (s / 2)) + log (Gamma (s / 2 + 1 / 2)) + s * log 2 - log (2 * βˆšΟ€)) (Ioi 0) := by intro s hs have h1 : βˆšΟ€ β‰  0 := sqrt_ne_zero'.mpr pi_pos have h2 : Gamma (s / 2) β‰  0 := (Gamma_pos_of_pos <| div_pos hs two_pos).ne' have h3 : Gamma (s / 2 + 1 / 2) β‰  0 := (Gamma_pos_of_pos <| add_pos (div_pos hs two_pos) one_half_pos).ne' have h4 : (2 : ℝ) ^ (s - 1) β‰  0 := (rpow_pos_of_pos two_pos _).ne' rw [Function.comp_apply, doublingGamma, log_div (mul_ne_zero (mul_ne_zero h2 h3) h4) h1, log_mul (mul_ne_zero h2 h3) h4, log_mul h2 h3, log_rpow two_pos, log_mul two_ne_zero h1] ring_nf theorem doublingGamma_log_convex_Ioi : ConvexOn ℝ (Ioi (0 : ℝ)) (log ∘ doublingGamma) := by refine (((ConvexOn.add ?_ ?_).add ?_).add_const _).congr log_doublingGamma_eq.symm Β· convert convexOn_log_Gamma.comp_affineMap (DistribMulAction.toLinearMap ℝ ℝ (1 / 2 : ℝ)).toAffineMap using 1 Β· simpa only [zero_div] using (preimage_const_mul_Ioi (0 : ℝ) one_half_pos).symm Β· ext1 x simp only [LinearMap.coe_toAffineMap, Function.comp_apply, DistribMulAction.toLinearMap_apply] rw [smul_eq_mul, mul_comm, mul_one_div] Β· refine ConvexOn.subset ?_ (Ioi_subset_Ioi <| neg_one_lt_zero.le) (convex_Ioi _) convert convexOn_log_Gamma.comp_affineMap ((DistribMulAction.toLinearMap ℝ ℝ (1 / 2 : ℝ)).toAffineMap + AffineMap.const ℝ ℝ (1 / 2 : ℝ)) using 1 Β· change Ioi (-1 : ℝ) = ((fun x : ℝ => x + 1 / 2) ∘ fun x : ℝ => (1 / 2 : ℝ) * x) ⁻¹' Ioi 0 rw [preimage_comp, preimage_add_const_Ioi, zero_sub, preimage_const_mul_Ioi (_ : ℝ) one_half_pos, neg_div, div_self (@one_half_pos ℝ _).ne'] Β· ext1 x change log (Gamma (x / 2 + 1 / 2)) = log (Gamma ((1 / 2 : ℝ) β€’ x + 1 / 2)) rw [smul_eq_mul, mul_comm, mul_one_div] Β· simpa only [mul_comm _ (log _)] using (convexOn_id (convex_Ioi (0 : ℝ))).smul (log_pos one_lt_two).le theorem doublingGamma_eq_Gamma {s : ℝ} (hs : 0 < s) : doublingGamma s = Gamma s := by refine eq_Gamma_of_log_convex doublingGamma_log_convex_Ioi (fun {y} hy => doublingGamma_add_one y hy.ne') (fun {y} hy => ?_) doublingGamma_one hs apply_rules [mul_pos, Gamma_pos_of_pos, add_pos, inv_pos_of_pos, rpow_pos_of_pos, two_pos, one_pos, sqrt_pos_of_pos pi_pos] /-- Legendre's doubling formula for the Gamma function, for positive real arguments. Note that we shall later prove this for all `s` as `Real.Gamma_mul_Gamma_add_half` (superseding this result) but this result is needed as an intermediate step. -/ theorem Gamma_mul_Gamma_add_half_of_pos {s : ℝ} (hs : 0 < s) : Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * βˆšΟ€ := by rw [← doublingGamma_eq_Gamma (mul_pos two_pos hs), doublingGamma, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), (by abel : 1 - 2 * s = -(2 * s - 1)), rpow_neg zero_le_two] field end Doubling end Real
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gamma/Deligne.lean
import Mathlib.Analysis.SpecialFunctions.Gamma.Beta /-! # Deligne's archimedean Gamma-factors In the theory of L-series one frequently encounters the following functions (of a complex variable `s`) introduced in Deligne's landmark paper *Valeurs de fonctions L et periodes d'integrales*: $$ \Gamma_{\mathbb{R}}(s) = \pi ^ {-s / 2} \Gamma (s / 2) $$ and $$ \Gamma_{\mathbb{C}}(s) = 2 (2 \pi) ^ {-s} \Gamma (s). $$ These are the factors that need to be included in the Dedekind zeta function of a number field for each real, resp. complex, infinite place. (Note that these are *not* the same as Mathlib's `Real.Gamma` vs. `Complex.Gamma`; Deligne's functions both take a complex variable as input.) This file defines these functions, and proves some elementary properties, including a reflection formula which is an important input in functional equations of (un-completed) Dirichlet L-functions. -/ open Filter Topology Asymptotics Real Set MeasureTheory open Complex namespace Complex /-- Deligne's archimedean Gamma factor for a real infinite place. See "Valeurs de fonctions L et periodes d'integrales" Β§ 5.3. Note that this is not the same as `Real.Gamma`; in particular it is a function `β„‚ β†’ β„‚`. -/ noncomputable def Gammaℝ (s : β„‚) := Ο€ ^ (-s / 2) * Gamma (s / 2) lemma Gammaℝ_def (s : β„‚) : Gammaℝ s = Ο€ ^ (-s / 2) * Gamma (s / 2) := rfl /-- Deligne's archimedean Gamma factor for a complex infinite place. See "Valeurs de fonctions L et periodes d'integrales" Β§ 5.3. (Some authors omit the factor of 2). Note that this is not the same as `Complex.Gamma`. -/ noncomputable def Gammaβ„‚ (s : β„‚) := 2 * (2 * Ο€) ^ (-s) * Gamma s lemma Gammaβ„‚_def (s : β„‚) : Gammaβ„‚ s = 2 * (2 * Ο€) ^ (-s) * Gamma s := rfl lemma Gammaℝ_add_two {s : β„‚} (hs : s β‰  0) : Gammaℝ (s + 2) = Gammaℝ s * s / 2 / Ο€ := by rw [Gammaℝ_def, Gammaℝ_def, neg_div, add_div, neg_add, div_self two_ne_zero, Gamma_add_one _ (div_ne_zero hs two_ne_zero), cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), cpow_neg_one] field_simp lemma Gammaβ„‚_add_one {s : β„‚} (hs : s β‰  0) : Gammaβ„‚ (s + 1) = Gammaβ„‚ s * s / 2 / Ο€ := by rw [Gammaβ„‚_def, Gammaβ„‚_def, Gamma_add_one _ hs, neg_add, cpow_add _ _ (mul_ne_zero two_ne_zero (ofReal_ne_zero.mpr pi_ne_zero)), cpow_neg_one] ring lemma Gammaℝ_ne_zero_of_re_pos {s : β„‚} (hs : 0 < re s) : Gammaℝ s β‰  0 := by apply mul_ne_zero Β· simp [pi_ne_zero] Β· apply Gamma_ne_zero_of_re_pos rw [div_ofNat_re] exact div_pos hs two_pos lemma Gammaℝ_eq_zero_iff {s : β„‚} : Gammaℝ s = 0 ↔ βˆƒ n : β„•, s = -(2 * n) := by simp [Gammaℝ_def, Complex.Gamma_eq_zero_iff, pi_ne_zero, div_eq_iff (two_ne_zero' β„‚), mul_comm] @[simp] lemma Gammaℝ_one : Gammaℝ 1 = 1 := by rw [Gammaℝ_def, Complex.Gamma_one_half_eq] simp [neg_div, cpow_neg, pi_ne_zero] @[simp] lemma Gammaβ„‚_one : Gammaβ„‚ 1 = 1 / Ο€ := by rw [Gammaβ„‚_def, cpow_neg_one, Complex.Gamma_one] ring section analyticity lemma differentiable_Gammaℝ_inv : Differentiable β„‚ (fun s ↦ (Gammaℝ s)⁻¹) := by conv => enter [2, s]; rw [Gammaℝ, mul_inv] refine Differentiable.mul (fun s ↦ .inv ?_ (by simp [pi_ne_zero])) ?_ Β· refine ((differentiableAt_id.neg.div_const (2 : β„‚)).const_cpow ?_) exact Or.inl (ofReal_ne_zero.mpr pi_ne_zero) Β· exact differentiable_one_div_Gamma.comp (differentiable_id.div_const _) lemma Gammaℝ_residue_zero : Tendsto (fun s ↦ s * Gammaℝ s) (𝓝[β‰ ] 0) (𝓝 2) := by have h : Tendsto (fun z : β„‚ ↦ z / 2 * Gamma (z / 2)) (𝓝[β‰ ] 0) (𝓝 1) := by refine tendsto_self_mul_Gamma_nhds_zero.comp ?_ rw [tendsto_nhdsWithin_iff, (by simp : 𝓝 (0 : β„‚) = 𝓝 (0 / 2))] exact ⟨(tendsto_id.div_const _).mono_left nhdsWithin_le_nhds, eventually_of_mem self_mem_nhdsWithin fun x hx ↦ div_ne_zero hx two_ne_zero⟩ have h' : Tendsto (fun s : β„‚ ↦ 2 * (Ο€ : β„‚) ^ (-s / 2)) (𝓝[β‰ ] 0) (𝓝 2) := by rw [(by simp : 𝓝 2 = 𝓝 (2 * (Ο€ : β„‚) ^ (-(0 : β„‚) / 2)))] refine Tendsto.mono_left (ContinuousAt.tendsto ?_) nhdsWithin_le_nhds exact continuousAt_const.mul ((continuousAt_const_cpow (ofReal_ne_zero.mpr pi_ne_zero)).comp (continuousAt_id.neg.div_const _)) convert mul_one (2 : β„‚) β–Έ (h'.mul h) using 2 with z rw [Gammaℝ] ring_nf end analyticity section reflection /-- Reformulation of the doubling formula in terms of `Gammaℝ`. -/ lemma Gammaℝ_mul_Gammaℝ_add_one (s : β„‚) : Gammaℝ s * Gammaℝ (s + 1) = Gammaβ„‚ s := by simp only [Gammaℝ_def, Gammaβ„‚_def] calc _ = (Ο€ ^ (-s / 2) * Ο€ ^ (-(s + 1) / 2)) * (Gamma (s / 2) * Gamma (s / 2 + 1 / 2)) := by ring_nf _ = 2 ^ (1 - s) * (Ο€ ^ (-1 / 2 - s) * Ο€ ^ (1 / 2 : β„‚)) * Gamma s := by rw [← cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), Complex.Gamma_mul_Gamma_add_half, sqrt_eq_rpow, ofReal_cpow pi_pos.le, ofReal_div, ofReal_one, ofReal_ofNat] ring_nf _ = 2 * ((2 : ℝ) ^ (-s) * Ο€ ^ (-s)) * Gamma s := by rw [sub_eq_add_neg, cpow_add _ _ two_ne_zero, cpow_one, ← cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), ofReal_ofNat] ring_nf _ = 2 * (2 * Ο€) ^ (-s) * Gamma s := by rw [← mul_cpow_ofReal_nonneg two_pos.le pi_pos.le, ofReal_ofNat] /-- Reformulation of the reflection formula in terms of `Gammaℝ`. -/ lemma Gammaℝ_one_sub_mul_Gammaℝ_one_add (s : β„‚) : Gammaℝ (1 - s) * Gammaℝ (1 + s) = (cos (Ο€ * s / 2))⁻¹ := calc Gammaℝ (1 - s) * Gammaℝ (1 + s) _ = (Ο€ ^ ((s - 1) / 2) * Ο€ ^ ((-1 - s) / 2)) * (Gamma ((1 - s) / 2) * Gamma (1 - (1 - s) / 2)) := by simp only [Gammaℝ_def] ring_nf _ = (Ο€ ^ ((s - 1) / 2) * Ο€ ^ ((-1 - s) / 2) * Ο€ ^ (1 : β„‚)) / sin (Ο€ / 2 - Ο€ * s / 2) := by rw [Complex.Gamma_mul_Gamma_one_sub, cpow_one] ring_nf _ = _ := by simp_rw [← cpow_add _ _ (ofReal_ne_zero.mpr pi_ne_zero), Complex.sin_pi_div_two_sub] ring_nf rw [cpow_zero, one_mul] /-- Another formulation of the reflection formula in terms of `Gammaℝ`. -/ lemma Gammaℝ_div_Gammaℝ_one_sub {s : β„‚} (hs : βˆ€ (n : β„•), s β‰  -(2 * n + 1)) : Gammaℝ s / Gammaℝ (1 - s) = Gammaβ„‚ s * cos (Ο€ * s / 2) := by have : Gammaℝ (s + 1) β‰  0 := by simpa only [Ne, Gammaℝ_eq_zero_iff, not_exists, ← eq_sub_iff_add_eq, sub_eq_add_neg, ← neg_add] calc Gammaℝ s / Gammaℝ (1 - s) _ = (Gammaℝ s * Gammaℝ (s + 1)) / (Gammaℝ (1 - s) * Gammaℝ (1 + s)) := by rw [add_comm 1 s, mul_comm (Gammaℝ (1 - s)) (Gammaℝ (s + 1)), ← div_div, mul_div_cancel_rightβ‚€ _ this] _ = (2 * (2 * Ο€) ^ (-s) * Gamma s) / ((cos (Ο€ * s / 2))⁻¹) := by rw [Gammaℝ_one_sub_mul_Gammaℝ_one_add, Gammaℝ_mul_Gammaℝ_add_one, Gammaβ„‚_def] _ = _ := by rw [Gammaβ„‚_def, div_eq_mul_inv, inv_inv] /-- Formulation of reflection formula tailored to functional equations of L-functions of even Dirichlet characters (including Riemann zeta). -/ lemma inv_Gammaℝ_one_sub {s : β„‚} (hs : βˆ€ (n : β„•), s β‰  -n) : (Gammaℝ (1 - s))⁻¹ = Gammaβ„‚ s * cos (Ο€ * s / 2) * (Gammaℝ s)⁻¹ := by have h1 : Gammaℝ s β‰  0 := by rw [Ne, Gammaℝ_eq_zero_iff, not_exists] intro n h specialize hs (2 * n) simp_all have h2 : βˆ€ (n : β„•), s β‰  -(2 * ↑n + 1) := by intro n h specialize hs (2 * n + 1) simp_all rw [← Gammaℝ_div_Gammaℝ_one_sub h2, ← div_eq_mul_inv, div_right_comm, div_self h1, one_div] /-- Formulation of reflection formula tailored to functional equations of L-functions of odd Dirichlet characters. -/ lemma inv_Gammaℝ_two_sub {s : β„‚} (hs : βˆ€ (n : β„•), s β‰  -n) : (Gammaℝ (2 - s))⁻¹ = Gammaβ„‚ s * sin (Ο€ * s / 2) * (Gammaℝ (s + 1))⁻¹ := by by_cases h : s = 1 Β· rw [h, (by ring : 2 - 1 = (1 : β„‚)), Gammaℝ_one, Gammaℝ, neg_div, (by simp : (1 + 1) / 2 = (1 : β„‚)), Complex.Gamma_one, Gammaβ„‚_one, mul_one, Complex.sin_pi_div_two, mul_one, cpow_neg_one, mul_one, inv_inv, div_mul_cancelβ‚€ _ (ofReal_ne_zero.mpr pi_ne_zero), inv_one] rw [← Ne, ← sub_ne_zero] at h have h' (n : β„•) : s - 1 β‰  -n := by rcases n with - | m Β· rwa [Nat.cast_zero, neg_zero] Β· rw [Ne, sub_eq_iff_eq_add] convert hs m using 2 push_cast ring rw [(by ring : 2 - s = 1 - (s - 1)), inv_Gammaℝ_one_sub h', (by rw [sub_add_cancel] : Gammaβ„‚ s = Gammaβ„‚ (s - 1 + 1)), Gammaβ„‚_add_one h, (by ring : s + 1 = (s - 1) + 2), Gammaℝ_add_two h, mul_sub, sub_div, mul_one, Complex.cos_sub_pi_div_two] simp_rw [mul_div_assoc, mul_inv] generalize (Gammaℝ (s - 1))⁻¹ = A field end reflection end Complex
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean
import Mathlib.Analysis.Convolution import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds import Mathlib.Analysis.SpecialFunctions.Trigonometric.EulerSineProd import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Analysis.Complex.CauchyIntegral /-! # The Beta function, and further properties of the Gamma function In this file we define the Beta integral, relate Beta and Gamma functions, and prove some refined properties of the Gamma function using these relations. ## Results on the Beta function * `Complex.betaIntegral`: the Beta function `Ξ’(u, v)`, where `u`, `v` are complex with positive real part. * `Complex.Gamma_mul_Gamma_eq_betaIntegral`: the formula `Gamma u * Gamma v = Gamma (u + v) * betaIntegral u v`. ## Results on the Gamma function * `Complex.Gamma_ne_zero`: for all `s : β„‚` with `s βˆ‰ {-n : n ∈ β„•}` we have `Ξ“ s β‰  0`. * `Complex.GammaSeq_tendsto_Gamma`: for all `s`, the limit as `n β†’ ∞` of the sequence `n ↦ n ^ s * n! / (s * (s + 1) * ... * (s + n))` is `Ξ“(s)`. * `Complex.Gamma_mul_Gamma_one_sub`: Euler's reflection formula `Gamma s * Gamma (1 - s) = Ο€ / sin Ο€ s`. * `Complex.differentiable_one_div_Gamma`: the function `1 / Ξ“(s)` is differentiable everywhere. * `Complex.Gamma_mul_Gamma_add_half`: Legendre's duplication formula `Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * βˆšΟ€`. * `Real.Gamma_ne_zero`, `Real.GammaSeq_tendsto_Gamma`, `Real.Gamma_mul_Gamma_one_sub`, `Real.Gamma_mul_Gamma_add_half`: real versions of the above. -/ noncomputable section open Filter intervalIntegral Set Real MeasureTheory open scoped Nat Topology Real section BetaIntegral /-! ## The Beta function -/ namespace Complex /-- The Beta function `Ξ’ (u, v)`, defined as `∫ x:ℝ in 0..1, x ^ (u - 1) * (1 - x) ^ (v - 1)`. -/ noncomputable def betaIntegral (u v : β„‚) : β„‚ := ∫ x : ℝ in 0..1, (x : β„‚) ^ (u - 1) * (1 - (x : β„‚)) ^ (v - 1) /-- Auxiliary lemma for `betaIntegral_convergent`, showing convergence at the left endpoint. -/ theorem betaIntegral_convergent_left {u : β„‚} (hu : 0 < re u) (v : β„‚) : IntervalIntegrable (fun x => (x : β„‚) ^ (u - 1) * (1 - (x : β„‚)) ^ (v - 1) : ℝ β†’ β„‚) volume 0 (1 / 2) := by apply IntervalIntegrable.mul_continuousOn Β· refine intervalIntegral.intervalIntegrable_cpow' ?_ rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right] Β· apply continuousOn_of_forall_continuousAt intro x hx rw [uIcc_of_le (by positivity : (0 : ℝ) ≀ 1 / 2)] at hx apply ContinuousAt.cpow Β· exact (continuous_const.sub continuous_ofReal).continuousAt Β· exact continuousAt_const Β· norm_cast exact ofReal_mem_slitPlane.2 <| by linarith only [hx.2] /-- The Beta integral is convergent for all `u, v` of positive real part. -/ theorem betaIntegral_convergent {u v : β„‚} (hu : 0 < re u) (hv : 0 < re v) : IntervalIntegrable (fun x => (x : β„‚) ^ (u - 1) * (1 - (x : β„‚)) ^ (v - 1) : ℝ β†’ β„‚) volume 0 1 := by refine (betaIntegral_convergent_left hu v).trans ?_ rw [IntervalIntegrable.iff_comp_neg] convert ((betaIntegral_convergent_left hv u).comp_add_right 1).symm using 1 Β· ext1 x conv_lhs => rw [mul_comm] congr 2 <;> Β· push_cast; ring Β· norm_num Β· simp theorem betaIntegral_symm (u v : β„‚) : betaIntegral v u = betaIntegral u v := by simpa [betaIntegral, ← intervalIntegral.integral_symm, add_comm, mul_comm, sub_eq_add_neg] using intervalIntegral.integral_comp_mul_add (a := 0) (b := 1) (c := -1) (fun x : ℝ => (x : β„‚) ^ (u - 1) * (1 - (x : β„‚)) ^ (v - 1)) neg_one_lt_zero.ne 1 theorem betaIntegral_eval_one_right {u : β„‚} (hu : 0 < re u) : betaIntegral u 1 = 1 / u := by simp_rw [betaIntegral, sub_self, cpow_zero, mul_one] rw [integral_cpow (Or.inl _)] Β· rw [ofReal_zero, ofReal_one, one_cpow, zero_cpow, sub_zero, sub_add_cancel] rw [sub_add_cancel] contrapose! hu; rw [hu, zero_re] Β· rwa [sub_re, one_re, ← sub_pos, sub_neg_eq_add, sub_add_cancel] theorem betaIntegral_scaled (s t : β„‚) {a : ℝ} (ha : 0 < a) : ∫ x in 0..a, (x : β„‚) ^ (s - 1) * ((a : β„‚) - x) ^ (t - 1) = (a : β„‚) ^ (s + t - 1) * betaIntegral s t := by have ha' : (a : β„‚) β‰  0 := ofReal_ne_zero.mpr ha.ne' rw [betaIntegral] have A : (a : β„‚) ^ (s + t - 1) = a * ((a : β„‚) ^ (s - 1) * (a : β„‚) ^ (t - 1)) := by rw [(by abel : s + t - 1 = 1 + (s - 1) + (t - 1)), cpow_add _ _ ha', cpow_add 1 _ ha', cpow_one, mul_assoc] rw [A, mul_assoc, ← intervalIntegral.integral_const_mul, ← real_smul, ← zero_div a, ← div_self ha.ne', ← intervalIntegral.integral_comp_div _ ha.ne', zero_div] simp_rw [intervalIntegral.integral_of_le ha.le] refine setIntegral_congr_fun measurableSet_Ioc fun x hx => ?_ rw [mul_mul_mul_comm] congr 1 Β· rw [← mul_cpow_ofReal_nonneg ha.le (div_pos hx.1 ha).le, ofReal_div, mul_div_cancelβ‚€ _ ha'] Β· rw [(by norm_cast : (1 : β„‚) - ↑(x / a) = ↑(1 - x / a)), ← mul_cpow_ofReal_nonneg ha.le (sub_nonneg.mpr <| (div_le_one ha).mpr hx.2)] push_cast rw [mul_sub, mul_one, mul_div_cancelβ‚€ _ ha'] /-- Relation between Beta integral and Gamma function. -/ theorem Gamma_mul_Gamma_eq_betaIntegral {s t : β„‚} (hs : 0 < re s) (ht : 0 < re t) : Gamma s * Gamma t = Gamma (s + t) * betaIntegral s t := by -- Note that we haven't proved (yet) that the Gamma function has no zeroes, so we can't formulate -- this as a formula for the Beta function. have conv_int := integral_posConvolution (GammaIntegral_convergent hs) (GammaIntegral_convergent ht) (ContinuousLinearMap.mul ℝ β„‚) simp_rw [ContinuousLinearMap.mul_apply'] at conv_int have hst : 0 < re (s + t) := by rw [add_re]; exact add_pos hs ht rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst, GammaIntegral, GammaIntegral, GammaIntegral, ← conv_int, ← MeasureTheory.integral_mul_const (betaIntegral _ _)] refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ rw [mul_assoc, ← betaIntegral_scaled s t hx, ← intervalIntegral.integral_const_mul] congr 1 with y : 1 push_cast suffices Complex.exp (-x) = Complex.exp (-y) * Complex.exp (-(x - y)) by rw [this]; ring rw [← Complex.exp_add]; congr 1; abel /-- Recurrence formula for the Beta function. -/ theorem betaIntegral_recurrence {u v : β„‚} (hu : 0 < re u) (hv : 0 < re v) : u * betaIntegral u (v + 1) = v * betaIntegral (u + 1) v := by -- NB: If we knew `Gamma (u + v + 1) β‰  0` this would be an easy consequence of -- `Gamma_mul_Gamma_eq_betaIntegral`; but we don't know that yet. We will prove it later, but -- this lemma is needed in the proof. So we give a (somewhat laborious) direct argument. let F : ℝ β†’ β„‚ := fun x => (x : β„‚) ^ u * (1 - (x : β„‚)) ^ v have hu' : 0 < re (u + 1) := by rw [add_re, one_re]; positivity have hv' : 0 < re (v + 1) := by rw [add_re, one_re]; positivity have hc : ContinuousOn F (Icc 0 1) := by refine (continuousOn_of_forall_continuousAt fun x hx => ?_).mul (continuousOn_of_forall_continuousAt fun x hx => ?_) Β· refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hu).comp continuous_ofReal.continuousAt rw [ofReal_re]; exact hx.1 Β· refine (continuousAt_cpow_const_of_re_pos (Or.inl ?_) hv).comp (continuous_const.sub continuous_ofReal).continuousAt rw [sub_re, one_re, ofReal_re, sub_nonneg] exact hx.2 have hder : βˆ€ x : ℝ, x ∈ Ioo (0 : ℝ) 1 β†’ HasDerivAt F (u * ((x : β„‚) ^ (u - 1) * (1 - (x : β„‚)) ^ v) - v * ((x : β„‚) ^ u * (1 - (x : β„‚)) ^ (v - 1))) x := by intro x hx have U : HasDerivAt (fun y : β„‚ => y ^ u) (u * (x : β„‚) ^ (u - 1)) ↑x := by have := @HasDerivAt.cpow_const _ _ _ u (hasDerivAt_id (x : β„‚)) (Or.inl ?_) Β· simp only [id_eq, mul_one] at this exact this Β· rw [id_eq, ofReal_re]; exact hx.1 have V : HasDerivAt (fun y : β„‚ => (1 - y) ^ v) (-v * (1 - (x : β„‚)) ^ (v - 1)) ↑x := by have A := @HasDerivAt.cpow_const _ _ _ v (hasDerivAt_id (1 - (x : β„‚))) (Or.inl ?_) swap; Β· rw [id, sub_re, one_re, ofReal_re, sub_pos]; exact hx.2 simp_rw [id] at A have B : HasDerivAt (fun y : β„‚ => 1 - y) (-1) ↑x := by apply HasDerivAt.const_sub; apply hasDerivAt_id convert HasDerivAt.comp (↑x) A B using 1 ring convert (U.mul V).comp_ofReal using 1 ring have h_int := ((betaIntegral_convergent hu hv').const_mul u).sub ((betaIntegral_convergent hu' hv).const_mul v) rw [add_sub_cancel_right, add_sub_cancel_right] at h_int have int_ev := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le zero_le_one hc hder h_int have hF0 : F 0 = 0 := by simp only [F, mul_eq_zero, ofReal_zero, cpow_eq_zero_iff, Ne, true_and, sub_zero, one_cpow, one_ne_zero, or_false] contrapose! hu; rw [hu, zero_re] have hF1 : F 1 = 0 := by simp only [F, mul_eq_zero, ofReal_one, one_cpow, one_ne_zero, sub_self, cpow_eq_zero_iff, Ne, true_and, false_or] contrapose! hv; rw [hv, zero_re] rw [hF0, hF1, sub_zero, intervalIntegral.integral_sub, intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at int_ev Β· rw [betaIntegral, betaIntegral, ← sub_eq_zero] convert int_ev <;> ring Β· apply IntervalIntegrable.const_mul convert betaIntegral_convergent hu hv'; ring Β· apply IntervalIntegrable.const_mul convert betaIntegral_convergent hu' hv; ring /-- Explicit formula for the Beta function when second argument is a positive integer. -/ theorem betaIntegral_eval_nat_add_one_right {u : β„‚} (hu : 0 < re u) (n : β„•) : betaIntegral u (n + 1) = n ! / ∏ j ∈ Finset.range (n + 1), (u + j) := by induction n generalizing u with | zero => rw [Nat.cast_zero, zero_add, betaIntegral_eval_one_right hu, Nat.factorial_zero, Nat.cast_one] simp | succ n IH => have := betaIntegral_recurrence hu (?_ : 0 < re n.succ) swap; Β· rw [← ofReal_natCast, ofReal_re]; positivity rw [mul_comm u _, ← eq_div_iff] at this swap; Β· contrapose! hu; rw [hu, zero_re] rw [this, Finset.prod_range_succ', Nat.cast_succ, IH] swap; Β· rw [add_re, one_re]; positivity rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, Nat.cast_zero, add_zero, ← mul_div_assoc, ← div_div] congr 3 with j : 1 push_cast; abel end Complex end BetaIntegral section LimitFormula /-! ## The Euler limit formula -/ namespace Complex /-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for complex `s`. We will show that this tends to `Ξ“(s)` as `n β†’ ∞`. -/ noncomputable def GammaSeq (s : β„‚) (n : β„•) := (n : β„‚) ^ s * n ! / ∏ j ∈ Finset.range (n + 1), (s + j) theorem GammaSeq_eq_betaIntegral_of_re_pos {s : β„‚} (hs : 0 < re s) (n : β„•) : GammaSeq s n = (n : β„‚) ^ s * betaIntegral s (n + 1) := by rw [GammaSeq, betaIntegral_eval_nat_add_one_right hs n, ← mul_div_assoc] theorem GammaSeq_add_one_left (s : β„‚) {n : β„•} (hn : n β‰  0) : GammaSeq (s + 1) n / s = n / (n + 1 + s) * GammaSeq s n := by conv_lhs => rw [GammaSeq, Finset.prod_range_succ, div_div] conv_rhs => rw [GammaSeq, Finset.prod_range_succ', Nat.cast_zero, add_zero, div_mul_div_comm, ← mul_assoc, ← mul_assoc, mul_comm _ (Finset.prod _ _)] congr 3 Β· rw [cpow_add _ _ (Nat.cast_ne_zero.mpr hn), cpow_one, mul_comm] Β· refine Finset.prod_congr (by rfl) fun x _ => ?_ push_cast; ring Β· abel theorem GammaSeq_eq_approx_Gamma_integral {s : β„‚} (hs : 0 < re s) {n : β„•} (hn : n β‰  0) : GammaSeq s n = ∫ x : ℝ in 0..n, ↑((1 - x / n) ^ n) * (x : β„‚) ^ (s - 1) := by have : βˆ€ x : ℝ, x = x / n * n := by intro x; rw [div_mul_cancelβ‚€]; exact Nat.cast_ne_zero.mpr hn conv_rhs => enter [1, x, 2, 1]; rw [this x] rw [GammaSeq_eq_betaIntegral_of_re_pos hs] have := intervalIntegral.integral_comp_div (a := 0) (b := n) (fun x => ↑((1 - x) ^ n) * ↑(x * ↑n) ^ (s - 1) : ℝ β†’ β„‚) (Nat.cast_ne_zero.mpr hn) dsimp only at this rw [betaIntegral, this, real_smul, zero_div, div_self, add_sub_cancel_right, ← intervalIntegral.integral_const_mul, ← intervalIntegral.integral_const_mul] swap; Β· exact Nat.cast_ne_zero.mpr hn simp_rw [intervalIntegral.integral_of_le zero_le_one] refine setIntegral_congr_fun measurableSet_Ioc fun x hx => ?_ push_cast have hn' : (n : β„‚) β‰  0 := Nat.cast_ne_zero.mpr hn have A : (n : β„‚) ^ s = (n : β„‚) ^ (s - 1) * n := by conv_lhs => rw [(by ring : s = s - 1 + 1), cpow_add _ _ hn'] simp have B : ((x : β„‚) * ↑n) ^ (s - 1) = (x : β„‚) ^ (s - 1) * (n : β„‚) ^ (s - 1) := by rw [← ofReal_natCast, mul_cpow_ofReal_nonneg hx.1.le (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)).le] rw [A, B, cpow_natCast]; ring /-- The main technical lemma for `GammaSeq_tendsto_Gamma`, expressing the integral defining the Gamma function for `0 < re s` as the limit of a sequence of integrals over finite intervals. -/ theorem approx_Gamma_integral_tendsto_Gamma_integral {s : β„‚} (hs : 0 < re s) : Tendsto (fun n : β„• => ∫ x : ℝ in 0..n, ((1 - x / n) ^ n : ℝ) * (x : β„‚) ^ (s - 1)) atTop (𝓝 <| Gamma s) := by rw [Gamma_eq_integral hs] -- We apply dominated convergence to the following function, which we will show is uniformly -- bounded above by the Gamma integrand `exp (-x) * x ^ (re s - 1)`. let f : β„• β†’ ℝ β†’ β„‚ := fun n => indicator (Ioc 0 (n : ℝ)) fun x : ℝ => ((1 - x / n) ^ n : ℝ) * (x : β„‚) ^ (s - 1) -- integrability of f have f_ible : βˆ€ n : β„•, Integrable (f n) (volume.restrict (Ioi 0)) := by intro n rw [integrable_indicator_iff (measurableSet_Ioc : MeasurableSet (Ioc (_ : ℝ) _)), IntegrableOn, Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self, ← IntegrableOn, ← intervalIntegrable_iff_integrableOn_Ioc_of_le (by positivity : (0 : ℝ) ≀ n)] apply IntervalIntegrable.continuousOn_mul Β· refine intervalIntegral.intervalIntegrable_cpow' ?_ rwa [sub_re, one_re, ← zero_sub, sub_lt_sub_iff_right] Β· apply Continuous.continuousOn continuity -- pointwise limit of f have f_tends : βˆ€ x : ℝ, x ∈ Ioi (0 : ℝ) β†’ Tendsto (fun n : β„• => f n x) atTop (𝓝 <| ↑(Real.exp (-x)) * (x : β„‚) ^ (s - 1)) := by intro x hx apply Tendsto.congr' Β· change βˆ€αΆ  n : β„• in atTop, ↑((1 - x / n) ^ n) * (x : β„‚) ^ (s - 1) = f n x filter_upwards [eventually_ge_atTop ⌈xβŒ‰β‚Š] with n hn rw [Nat.ceil_le] at hn dsimp only [f] rw [indicator_of_mem] exact ⟨hx, hn⟩ Β· simp_rw [mul_comm] refine (Tendsto.comp (continuous_ofReal.tendsto _) ?_).const_mul _ convert Real.tendsto_one_add_div_pow_exp (-x) using 1 ext1 n rw [neg_div, ← sub_eq_add_neg] -- let `convert` identify the remaining goals convert tendsto_integral_of_dominated_convergence _ (fun n => (f_ible n).1) (Real.GammaIntegral_convergent hs) _ ((ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ f_tends)) using 1 -- limit of f is the integrand we want Β· ext1 n rw [MeasureTheory.integral_indicator (measurableSet_Ioc : MeasurableSet (Ioc (_ : ℝ) _)), intervalIntegral.integral_of_le (by positivity : 0 ≀ (n : ℝ)), Measure.restrict_restrict_of_subset Ioc_subset_Ioi_self] -- f is uniformly bounded by the Gamma integrand Β· intro n rw [ae_restrict_iff' measurableSet_Ioi] filter_upwards with x hx simp only [mem_Ioi, f] at hx ⊒ rcases lt_or_ge (n : ℝ) x with (hxn | hxn) Β· rw [indicator_of_notMem (notMem_Ioc_of_gt hxn), norm_zero, mul_nonneg_iff_right_nonneg_of_pos (exp_pos _)] exact rpow_nonneg (le_of_lt hx) _ Β· rw [indicator_of_mem (mem_Ioc.mpr ⟨mem_Ioi.mp hx, hxn⟩), norm_mul, Complex.norm_of_nonneg (pow_nonneg (sub_nonneg.mpr <| div_le_one_of_leβ‚€ hxn <| by positivity) _), norm_cpow_eq_rpow_re_of_pos hx, sub_re, one_re] gcongr exact one_sub_div_pow_le_exp_neg hxn /-- Euler's limit formula for the complex Gamma function. -/ theorem GammaSeq_tendsto_Gamma (s : β„‚) : Tendsto (GammaSeq s) atTop (𝓝 <| Gamma s) := by suffices βˆ€ m : β„•, -↑m < re s β†’ Tendsto (GammaSeq s) atTop (𝓝 <| GammaAux m s) by rw [Gamma] apply this rw [neg_lt] rcases lt_or_ge 0 (re s) with (hs | hs) Β· exact (neg_neg_of_pos hs).trans_le (Nat.cast_nonneg _) Β· refine (Nat.lt_floor_add_one _).trans_le ?_ rw [sub_eq_neg_add, Nat.floor_add_one (neg_nonneg.mpr hs), Nat.cast_add_one] intro m induction m generalizing s with intro hs | zero => -- Base case: `0 < re s`, so Gamma is given by the integral formula rw [Nat.cast_zero, neg_zero] at hs rw [← Gamma_eq_GammaAux] Β· refine Tendsto.congr' ?_ (approx_Gamma_integral_tendsto_Gamma_integral hs) refine (eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn => ?_) exact (GammaSeq_eq_approx_Gamma_integral hs hn).symm Β· rwa [Nat.cast_zero, neg_lt_zero] | succ m IH => -- Induction step: use recurrence formulae in `s` for Gamma and GammaSeq rw [Nat.cast_succ, neg_add, ← sub_eq_add_neg, sub_lt_iff_lt_add, ← one_re, ← add_re] at hs rw [GammaAux] have := @Tendsto.congr' _ _ _ ?_ _ _ ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn => ?_)) ((IH _ hs).div_const s) pick_goal 3; Β· exact GammaSeq_add_one_left s hn -- doesn't work if inlined? conv at this => arg 1; intro n; rw [mul_comm] rwa [← mul_one (GammaAux m (s + 1) / s), tendsto_mul_iff_of_ne_zero _ (one_ne_zero' β„‚)] at this simp_rw [add_assoc] exact tendsto_natCast_div_add_atTop (1 + s) end Complex end LimitFormula section GammaReflection /-! ## The reflection formula -/ namespace Complex theorem GammaSeq_mul (z : β„‚) {n : β„•} (hn : n β‰  0) : GammaSeq z n * GammaSeq (1 - z) n = n / (n + ↑1 - z) * (↑1 / (z * ∏ j ∈ Finset.range n, (↑1 - z ^ 2 / ((j : β„‚) + 1) ^ 2))) := by -- also true for n = 0 but we don't need it have aux : βˆ€ a b c d : β„‚, a * b * (c * d) = a * c * (b * d) := by intros; ring rw [GammaSeq, GammaSeq, div_mul_div_comm, aux, ← pow_two] have : (n : β„‚) ^ z * (n : β„‚) ^ (1 - z) = n := by rw [← cpow_add _ _ (Nat.cast_ne_zero.mpr hn), add_sub_cancel, cpow_one] rw [this, Finset.prod_range_succ', Finset.prod_range_succ, aux, ← Finset.prod_mul_distrib, Nat.cast_zero, add_zero, add_comm (1 - z) n, ← add_sub_assoc] have : βˆ€ j : β„•, (z + ↑(j + 1)) * (↑1 - z + ↑j) = ((j + 1) ^ 2 :) * (↑1 - z ^ 2 / ((j : β„‚) + 1) ^ 2) := by intro j push_cast have : (j : β„‚) + 1 β‰  0 := by rw [← Nat.cast_succ, Nat.cast_ne_zero]; exact Nat.succ_ne_zero j field simp_rw [this] rw [Finset.prod_mul_distrib, ← Nat.cast_prod, Finset.prod_pow, Finset.prod_range_add_one_eq_factorial, Nat.cast_pow, (by intros; ring : βˆ€ a b c d : β„‚, a * b * (c * d) = a * (d * (b * c))), ← div_div, mul_div_cancel_rightβ‚€, ← div_div, mul_comm z _, mul_one_div] exact pow_ne_zero 2 (Nat.cast_ne_zero.mpr <| by positivity) /-- Euler's reflection formula for the complex Gamma function. -/ theorem Gamma_mul_Gamma_one_sub (z : β„‚) : Gamma z * Gamma (1 - z) = Ο€ / sin (Ο€ * z) := by have pi_ne : (Ο€ : β„‚) β‰  0 := Complex.ofReal_ne_zero.mpr pi_ne_zero by_cases hs : sin (↑π * z) = 0 Β· -- first deal with silly case z = integer rw [hs, div_zero] rw [← neg_eq_zero, ← Complex.sin_neg, ← mul_neg, Complex.sin_eq_zero_iff, mul_comm] at hs obtain ⟨k, hk⟩ := hs rw [mul_eq_mul_right_iff, eq_false (ofReal_ne_zero.mpr pi_pos.ne'), or_false, neg_eq_iff_eq_neg] at hk rw [hk] cases k Β· rw [Int.ofNat_eq_coe, Int.cast_natCast, Complex.Gamma_neg_nat_eq_zero, zero_mul] Β· rw [Int.cast_negSucc, neg_neg, Nat.cast_add, Nat.cast_one, add_comm, sub_add_cancel_left, Complex.Gamma_neg_nat_eq_zero, mul_zero] refine tendsto_nhds_unique ((GammaSeq_tendsto_Gamma z).mul (GammaSeq_tendsto_Gamma <| 1 - z)) ?_ have : ↑π / sin (↑π * z) = 1 * (Ο€ / sin (Ο€ * z)) := by rw [one_mul] convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn => (GammaSeq_mul z hn).symm)) (Tendsto.mul _ _) Β· convert tendsto_natCast_div_add_atTop (1 - z) using 1; ext1 n; rw [add_sub_assoc] Β· have : ↑π / sin (↑π * z) = 1 / (sin (Ο€ * z) / Ο€) := by simp convert tendsto_const_nhds.div _ (div_ne_zero hs pi_ne) rw [← tendsto_mul_iff_of_ne_zero tendsto_const_nhds pi_ne, div_mul_cancelβ‚€ _ pi_ne] convert tendsto_euler_sin_prod z using 1 ext1 n; rw [mul_comm, ← mul_assoc] /-- The Gamma function does not vanish on `β„‚` (except at non-positive integers, where the function is mathematically undefined and we set it to `0` by convention). -/ theorem Gamma_ne_zero {s : β„‚} (hs : βˆ€ m : β„•, s β‰  -m) : Gamma s β‰  0 := by by_cases h_im : s.im = 0 Β· have : s = ↑s.re := by conv_lhs => rw [← Complex.re_add_im s] rw [h_im, ofReal_zero, zero_mul, add_zero] rw [this, Gamma_ofReal, ofReal_ne_zero] refine Real.Gamma_ne_zero fun n => ?_ specialize hs n contrapose! hs rwa [this, ← ofReal_natCast, ← ofReal_neg, ofReal_inj] Β· have : sin (↑π * s) β‰  0 := by rw [Complex.sin_ne_zero_iff] intro k apply_fun im rw [im_ofReal_mul, ← ofReal_intCast, ← ofReal_mul, ofReal_im] exact mul_ne_zero Real.pi_pos.ne' h_im have A := div_ne_zero (ofReal_ne_zero.mpr Real.pi_pos.ne') this rw [← Complex.Gamma_mul_Gamma_one_sub s, mul_ne_zero_iff] at A exact A.1 theorem Gamma_eq_zero_iff (s : β„‚) : Gamma s = 0 ↔ βˆƒ m : β„•, s = -m := by constructor Β· contrapose!; exact Gamma_ne_zero Β· rintro ⟨m, rfl⟩; exact Gamma_neg_nat_eq_zero m /-- A weaker, but easier-to-apply, version of `Complex.Gamma_ne_zero`. -/ theorem Gamma_ne_zero_of_re_pos {s : β„‚} (hs : 0 < re s) : Gamma s β‰  0 := by refine Gamma_ne_zero fun m => ?_ contrapose! hs simpa only [hs, neg_re, ← ofReal_natCast, ofReal_re, neg_nonpos] using Nat.cast_nonneg _ end Complex namespace Real /-- The sequence with `n`-th term `n ^ s * n! / (s * (s + 1) * ... * (s + n))`, for real `s`. We will show that this tends to `Ξ“(s)` as `n β†’ ∞`. -/ noncomputable def GammaSeq (s : ℝ) (n : β„•) := (n : ℝ) ^ s * n ! / ∏ j ∈ Finset.range (n + 1), (s + j) /-- Euler's limit formula for the real Gamma function. -/ theorem GammaSeq_tendsto_Gamma (s : ℝ) : Tendsto (GammaSeq s) atTop (𝓝 <| Gamma s) := by suffices Tendsto ((↑) ∘ GammaSeq s : β„• β†’ β„‚) atTop (𝓝 <| Complex.Gamma s) by exact (Complex.continuous_re.tendsto (Complex.Gamma ↑s)).comp this convert Complex.GammaSeq_tendsto_Gamma s ext1 n dsimp only [GammaSeq, Function.comp_apply, Complex.GammaSeq] push_cast rw [Complex.ofReal_cpow n.cast_nonneg, Complex.ofReal_natCast] /-- Euler's reflection formula for the real Gamma function. -/ theorem Gamma_mul_Gamma_one_sub (s : ℝ) : Gamma s * Gamma (1 - s) = Ο€ / sin (Ο€ * s) := by simp_rw [← Complex.ofReal_inj, Complex.ofReal_div, Complex.ofReal_sin, Complex.ofReal_mul, ← Complex.Gamma_ofReal, Complex.ofReal_sub, Complex.ofReal_one] exact Complex.Gamma_mul_Gamma_one_sub s end Real end GammaReflection section InvGamma open scoped Real namespace Complex /-! ## The reciprocal Gamma function We show that the reciprocal Gamma function `1 / Ξ“(s)` is entire. These lemmas show that (in this case at least) mathlib's conventions for division by zero do actually give a mathematically useful answer! (These results are useful in the theory of zeta and L-functions.) -/ /-- A reformulation of the Gamma recurrence relation which is true for `s = 0` as well. -/ theorem one_div_Gamma_eq_self_mul_one_div_Gamma_add_one (s : β„‚) : (Gamma s)⁻¹ = s * (Gamma (s + 1))⁻¹ := by rcases ne_or_eq s 0 with (h | rfl) Β· rw [Gamma_add_one s h, mul_inv, mul_inv_cancel_leftβ‚€ h] Β· rw [zero_add, Gamma_zero, inv_zero, zero_mul] /-- The reciprocal of the Gamma function is differentiable everywhere (including the points where Gamma itself is not). -/ theorem differentiable_one_div_Gamma : Differentiable β„‚ fun s : β„‚ => (Gamma s)⁻¹ := fun s ↦ by rcases exists_nat_gt (-s.re) with ⟨n, hs⟩ induction n generalizing s with | zero => rw [Nat.cast_zero, neg_lt_zero] at hs suffices βˆ€ m : β„•, s β‰  -↑m from (differentiableAt_Gamma _ this).inv (Gamma_ne_zero this) rintro m rfl apply hs.not_ge simp | succ n ihn => rw [funext one_div_Gamma_eq_self_mul_one_div_Gamma_add_one] specialize ihn (s + 1) (by rwa [add_re, one_re, neg_add', sub_lt_iff_lt_add, ← Nat.cast_succ]) exact differentiableAt_id.mul (ihn.comp s (f := fun s => s + 1) <| differentiableAt_id.add_const (1 : β„‚)) lemma betaIntegral_eq_Gamma_mul_div (u v : β„‚) (hu : 0 < u.re) (hv : 0 < v.re) : betaIntegral u v = Gamma u * Gamma v / Gamma (u + v) := by rw [Gamma_mul_Gamma_eq_betaIntegral hu hv, mul_div_cancel_leftβ‚€ _ (Gamma_ne_zero_of_re_pos (add_pos hu hv))] end Complex end InvGamma section Doubling /-! ## The doubling formula for Gamma We prove the doubling formula for arbitrary real or complex arguments, by analytic continuation from the positive real case. (Knowing that `Γ⁻¹` is analytic everywhere makes this much simpler, since we do not have to do any special-case handling for the poles of `Ξ“`.) -/ namespace Complex theorem Gamma_mul_Gamma_add_half (s : β„‚) : Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * (2 : β„‚) ^ (1 - 2 * s) * ↑(βˆšΟ€) := by suffices (fun z => (Gamma z)⁻¹ * (Gamma (z + 1 / 2))⁻¹) = fun z => (Gamma (2 * z))⁻¹ * (2 : β„‚) ^ (2 * z - 1) / ↑(βˆšΟ€) by convert congr_arg Inv.inv (congr_fun this s) using 1 Β· rw [mul_inv, inv_inv, inv_inv] Β· rw [div_eq_mul_inv, mul_inv, mul_inv, inv_inv, inv_inv, ← cpow_neg, neg_sub] have h1 : AnalyticOnNhd β„‚ (fun z : β„‚ => (Gamma z)⁻¹ * (Gamma (z + 1 / 2))⁻¹) univ := by refine DifferentiableOn.analyticOnNhd ?_ isOpen_univ refine (differentiable_one_div_Gamma.mul ?_).differentiableOn exact differentiable_one_div_Gamma.comp (differentiable_id.add (differentiable_const _)) have h2 : AnalyticOnNhd β„‚ (fun z => (Gamma (2 * z))⁻¹ * (2 : β„‚) ^ (2 * z - 1) / ↑(βˆšΟ€)) univ := by refine DifferentiableOn.analyticOnNhd ?_ isOpen_univ refine (Differentiable.mul ?_ (differentiable_const _)).differentiableOn apply Differentiable.mul Β· exact differentiable_one_div_Gamma.comp (differentiable_id.const_mul _) Β· refine fun t => DifferentiableAt.const_cpow ?_ (Or.inl two_ne_zero) exact DifferentiableAt.sub_const (differentiableAt_id.const_mul _) _ have h3 : Tendsto ((↑) : ℝ β†’ β„‚) (𝓝[β‰ ] 1) (𝓝[β‰ ] 1) := by rw [tendsto_nhdsWithin_iff]; constructor Β· exact tendsto_nhdsWithin_of_tendsto_nhds continuous_ofReal.continuousAt Β· exact eventually_nhdsWithin_iff.mpr (Eventually.of_forall fun t ht => ofReal_ne_one.mpr ht) refine AnalyticOnNhd.eq_of_frequently_eq h1 h2 (h3.frequently ?_) refine ((Eventually.filter_mono nhdsWithin_le_nhds) ?_).frequently refine (eventually_gt_nhds zero_lt_one).mp (Eventually.of_forall fun t ht => ?_) rw [← mul_inv, Gamma_ofReal, (by simp : (t : β„‚) + 1 / 2 = ↑(t + 1 / 2)), Gamma_ofReal, ← ofReal_mul, Gamma_mul_Gamma_add_half_of_pos ht, ofReal_mul, ofReal_mul, ← Gamma_ofReal, mul_inv, mul_inv, (by simp : 2 * (t : β„‚) = ↑(2 * t)), Gamma_ofReal, ofReal_cpow zero_le_two, show (2 : ℝ) = (2 : β„‚) by norm_cast, ← cpow_neg, ofReal_sub, ofReal_one, neg_sub, ← div_eq_mul_inv] end Complex namespace Real open Complex theorem Gamma_mul_Gamma_add_half (s : ℝ) : Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * (2 : ℝ) ^ (1 - 2 * s) * βˆšΟ€ := by rw [← ofReal_inj] simpa only [← Gamma_ofReal, ofReal_cpow zero_le_two, ofReal_mul, ofReal_add, ofReal_div, ofReal_sub] using Complex.Gamma_mul_Gamma_add_half ↑s end Real end Doubling
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/NthRootLemmas.lean
import Mathlib.Algebra.Order.Floor.Semifield import Mathlib.Analysis.MeanInequalities import Mathlib.Data.Nat.NthRoot.Defs import Mathlib.Tactic.Rify /-! # Lemmas about `Nat.nthRoot` In this file we prove that `Nat.nthRoot n a` is indeed the floor of `ⁿ√a`. ## TODO Rewrite the proof of `Nat.nthRoot.lt_pow_go_succ_aux` to avoid dependencies on real numbers, so that we can move this file to `Mathlib/Data/Nat/NthRoot`, then to Batteries. -/ namespace Nat variable {m n a b guess fuel : β„•} @[simp] theorem nthRoot_zero_left (a : β„•) : nthRoot 0 a = 1 := rfl @[simp] theorem nthRoot_one_left : nthRoot 1 = id := rfl @[simp] theorem nthRoot_zero_right (h : n β‰  0) : nthRoot n 0 = 0 := by rcases n with _|_|_ <;> grind [nthRoot, nthRoot.go] @[simp] theorem nthRoot_one_right : nthRoot n 1 = 1 := by rcases n with _|_|_ <;> simp [nthRoot, nthRoot.go, Nat.add_comm 1] private theorem nthRoot.pow_go_le (hle : guess ≀ fuel) (n a : β„•) : go n a fuel guess ^ (n + 2) ≀ a := by induction fuel generalizing guess with | zero => obtain rfl : guess = 0 := by grind simp [go] | succ fuel ih => rw [go] split_ifs with h case pos => grind case neg => have : guess ≀ a / guess ^ (n + 1) := by linarith only [Nat.mul_le_of_le_div _ _ _ (not_lt.1 h)] replace := Nat.mul_le_of_le_div _ _ _ this grind /-- `nthRoot n a ^ n ≀ a` unless both `n` and `a` are zeros. -/ @[simp] theorem pow_nthRoot_le_iff : nthRoot n a ^ n ≀ a ↔ n β‰  0 ∨ a β‰  0 := by rcases n with _|_|_ <;> first | grind | simp [nthRoot, nthRoot.pow_go_le] alias ⟨_, pow_nthRoot_le⟩ := pow_nthRoot_le_iff /-- An auxiliary lemma saying that if `b β‰  0`, then `(a / b ^ n + n * b) / (n + 1) + 1` is a strict upper estimate on `√[n + 1] a`. Currently, the proof relies on the weighted AM-GM inequality, which increases the dependency closure of this file by a lot. A PR proving this inequality by more elementary means is very welcome. -/ theorem nthRoot.lt_pow_go_succ_aux (hb : b β‰  0) : a < ((a / b ^ n + n * b) / (n + 1) + 1) ^ (n + 1) := by rcases Nat.eq_zero_or_pos n with rfl | hn; Β· simp rw [← Nat.add_mul_div_left a, Nat.div_div_eq_div_mul] <;> try positivity rify calc (a : ℝ) = ((a / b ^ n) ^ (1 / (n + 1) : ℝ) * b ^ (n / (n + 1) : ℝ)) ^ (n + 1) := by rw [mul_pow, ← Real.rpow_mul_natCast, ← Real.rpow_mul_natCast] <;> try positivity simp (disch := positivity) [div_mul_cancelβ‚€] _ ≀ ((1 / (n + 1)) * (a / b ^ n) + (n / (n + 1)) * b) ^ (n + 1) := by gcongr apply Real.geom_mean_le_arith_mean2_weighted <;> try positivity simp [field, add_comm] _ = ((a + b ^ n * (n * b)) / (b ^ n * (n + 1))) ^ (n + 1) := by congr 1 field _ < _ := by gcongr ?_ ^ _ convert lt_floor_add_one (R := ℝ) _ using 1 norm_cast rw [Nat.floor_div_natCast, Nat.floor_natCast] private theorem nthRoot.lt_pow_go_succ (hlt : a < (guess + 1) ^ (n + 2)) : a < (go n a fuel guess + 1) ^ (n + 2) := by induction fuel generalizing guess with | zero => simpa [go] | succ fuel ih => rw [go] split_ifs with h case pos => rcases eq_or_ne guess 0 with rfl | hguess Β· grind Β· exact ih <| Nat.nthRoot.lt_pow_go_succ_aux hguess case neg => assumption theorem lt_pow_nthRoot_add_one (hn : n β‰  0) (a : β„•) : a < (nthRoot n a + 1) ^ n := by match n, hn with | 1, _ => simp | n + 2, hn => simp only [nthRoot] apply nthRoot.lt_pow_go_succ exact a.lt_succ_self.trans_le (Nat.le_self_pow hn _) @[simp] theorem le_nthRoot_iff (hn : n β‰  0) : a ≀ nthRoot n b ↔ a ^ n ≀ b := by cases le_or_gt a (nthRoot n b) with | inl hle => simp only [hle, true_iff] refine le_trans ?_ (pow_nthRoot_le (.inl hn)) gcongr | inr hlt => simp only [hlt.not_ge, false_iff, not_le] refine (lt_pow_nthRoot_add_one hn b).trans_le ?_ gcongr assumption @[simp] theorem nthRoot_lt_iff (hn : n β‰  0) : nthRoot n a < b ↔ a < b ^ n := by simp only [← not_le, le_nthRoot_iff hn] @[simp] theorem nthRoot_pow (hn : n β‰  0) (a : β„•) : nthRoot n (a ^ n) = a := by refine eq_of_forall_le_iff fun b ↦ ?_ rw [le_nthRoot_iff hn] exact (Nat.pow_left_strictMono hn).le_iff_le /-- If `a ^ n ≀ b < (a + 1) ^ n`, then `n` root of `b` equals `a`. -/ theorem nthRoot_eq_of_le_of_lt (h₁ : a ^ n ≀ b) (hβ‚‚ : b < (a + 1) ^ n) : nthRoot n b = a := by rcases eq_or_ne n 0 with rfl | hn Β· grind simp only [← le_nthRoot_iff hn, ← nthRoot_lt_iff hn] at h₁ hβ‚‚ grind theorem exists_pow_eq_iff' (hn : n β‰  0) : (βˆƒ x, x ^ n = a) ↔ (nthRoot n a) ^ n = a := by constructor Β· rintro ⟨x, rfl⟩ rw [nthRoot_pow hn] Β· grind theorem exists_pow_eq_iff : (βˆƒ x, x ^ n = a) ↔ ((n = 0 ∧ a = 1) ∨ (n β‰  0 ∧ (nthRoot n a) ^ n = a)) := by rcases eq_or_ne n 0 with rfl | _ <;> grind [exists_pow_eq_iff'] instance instDecidableExistsPowEq : Decidable (βˆƒ x, x ^ n = a) := decidable_of_iff' _ exists_pow_eq_iff end Nat
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Limits and asymptotics of power functions at `+∞` This file contains results about the limiting behaviour of power functions at `+∞`. For convenience some results on asymptotics as `x β†’ 0` (those which are not just continuity statements) are also located here. -/ noncomputable section open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set /-! ## Limits at `+∞` -/ section Limits open Real Filter /-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by rw [(atTop_basis' 0).tendsto_right_iff] intro b hb filter_upwards [eventually_ge_atTop 0, eventually_ge_atTop (b ^ (1 / y))] with x hxβ‚€ hx simpa (disch := positivity) [Real.rpow_inv_le_iff_of_pos] using hx /-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_neg_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ (-y)) atTop (𝓝 0) := Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop 0) fun _ hx => (rpow_neg (le_of_lt hx) y).symm) (tendsto_rpow_atTop hy).inv_tendsto_atTop open Asymptotics in lemma tendsto_rpow_atTop_of_base_lt_one (b : ℝ) (hbβ‚€ : -1 < b) (hb₁ : b < 1) : Tendsto (b ^ Β· : ℝ β†’ ℝ) atTop (𝓝 (0 : ℝ)) := by rcases lt_trichotomy b 0 with hb | rfl | hb case inl => -- b < 0 simp_rw [Real.rpow_def_of_nonpos hb.le, hb.ne, ite_false] rw [← isLittleO_const_iff (c := (1 : ℝ)) one_ne_zero, (one_mul (1 : ℝ)).symm] refine IsLittleO.mul_isBigO ?exp ?cos case exp => rw [isLittleO_const_iff one_ne_zero] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id rw [← log_neg_eq_log, log_neg_iff (by linarith)] linarith case cos => rw [isBigO_iff] exact ⟨1, Eventually.of_forall fun x => by simp [Real.abs_cos_le_one]⟩ case inr.inl => -- b = 0 refine Tendsto.mono_right ?_ (Iff.mpr pure_le_nhds_iff rfl) rw [tendsto_pure] filter_upwards [eventually_ne_atTop 0] with _ hx simp [hx] case inr.inr => -- b > 0 simp_rw [Real.rpow_def_of_pos hb] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id exact (log_neg_iff hb).mpr hb₁ lemma tendsto_rpow_atBot_of_base_lt_one (b : ℝ) (hbβ‚€ : 0 < b) (hb₁ : b < 1) : Tendsto (b ^ Β· : ℝ β†’ ℝ) atBot atTop := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atTop.comp <| (tendsto_const_mul_atTop_iff_neg <| tendsto_id (Ξ± := ℝ)).mpr ?_ exact (log_neg_iff hbβ‚€).mpr hb₁ lemma tendsto_rpow_atBot_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ Β· : ℝ β†’ ℝ) atBot (𝓝 0) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_pos ?_).mpr tendsto_id exact (log_pos_iff (by positivity)).mpr <| by aesop @[deprecated (since := "2025-08-24")] alias tendsto_rpow_atTop_of_base_gt_one := tendsto_rpow_atBot_of_base_gt_one /-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and `c` such that `b` is nonzero. -/ theorem tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 β‰  b) : Tendsto (fun x => x ^ (a / (b * x + c))) atTop (𝓝 1) := by refine Tendsto.congr' ?_ ((tendsto_exp_nhds_zero_nhds_one.comp (by simpa only [mul_zero, pow_one] using (tendsto_const_nhds (x := a)).mul (tendsto_div_pow_mul_exp_add_atTop b c 1 hb))).comp tendsto_log_atTop) apply eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) intro x hx simp only [Set.mem_Ioi, Function.comp_apply] at hx ⊒ rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))] field_simp /-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_div : Tendsto (fun x => x ^ ((1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (1 : ℝ) _ (0 : ℝ) zero_ne_one ring /-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_neg_div : Tendsto (fun x => x ^ (-(1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (-(1 : ℝ)) _ (0 : ℝ) zero_ne_one ring /-- The function `exp(x) / x ^ s` tends to `+∞` at `+∞`, for any real number `s`. -/ theorem tendsto_exp_div_rpow_atTop (s : ℝ) : Tendsto (fun x : ℝ => exp x / x ^ s) atTop atTop := by obtain ⟨n, hn⟩ := archimedean_iff_nat_lt.1 Real.instArchimedean s refine tendsto_atTop_mono' _ ?_ (tendsto_exp_div_pow_atTop n) filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_ge_atTop (1 : ℝ)] with x hxβ‚€ hx₁ gcongr simpa using rpow_le_rpow_of_exponent_le hx₁ hn.le /-- The function `exp (b * x) / x ^ s` tends to `+∞` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_exp_mul_div_rpow_atTop (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => exp (b * x) / x ^ s) atTop atTop := by refine ((tendsto_rpow_atTop hb).comp (tendsto_exp_div_rpow_atTop (s / b))).congr' ?_ filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hxβ‚€ simp [Real.div_rpow, (exp_pos x).le, rpow_nonneg, ← Real.rpow_mul, ← exp_mul, mul_comm x, hb.ne', *] /-- The function `x ^ s * exp (-b * x)` tends to `0` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => x ^ s * exp (-b * x)) atTop (𝓝 0) := by refine (tendsto_exp_mul_div_rpow_atTop s b hb).inv_tendsto_atTop.congr' ?_ filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)] nonrec theorem NNReal.tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝβ‰₯0 => x ^ y) atTop atTop := by rw [Filter.tendsto_atTop_atTop] intro b obtain ⟨c, hc⟩ := tendsto_atTop_atTop.mp (tendsto_rpow_atTop hy) b use c.toNNReal intro a ha exact mod_cast hc a (Real.toNNReal_le_iff_le_coe.mp ha) theorem ENNReal.tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝβ‰₯0∞ => x ^ y) (𝓝 ⊀) (𝓝 ⊀) := by rw [ENNReal.tendsto_nhds_top_iff_nnreal] intro x obtain ⟨c, _, hc⟩ := (atTop_basis_Ioi.tendsto_iff atTop_basis_Ioi).mp (NNReal.tendsto_rpow_atTop hy) x trivial have hc' : Set.Ioi ↑c ∈ 𝓝 (⊀ : ℝβ‰₯0∞) := Ioi_mem_nhds ENNReal.coe_lt_top filter_upwards [hc'] with a ha by_cases ha' : a = ⊀ Β· simp [ha', hy] lift a to ℝβ‰₯0 using ha' simp only [Set.mem_Ioi, coe_lt_coe] at ha hc rw [← ENNReal.coe_rpow_of_nonneg _ hy.le] exact mod_cast hc a ha end Limits /-! ## Asymptotic results: `IsBigO`, `IsLittleO` and `IsTheta` -/ namespace Complex section variable {Ξ± : Type*} {l : Filter Ξ±} {f g : Ξ± β†’ β„‚} open Asymptotics theorem isTheta_exp_arg_mul_im (hl : IsBoundedUnder (Β· ≀ Β·) l fun x => |(g x).im|) : (fun x => Real.exp (arg (f x) * im (g x))) =Θ[l] fun _ => (1 : ℝ) := by rcases hl with ⟨b, hb⟩ refine Real.isTheta_exp_comp_one.2 βŸ¨Ο€ * b, ?_⟩ rw [eventually_map] at hb ⊒ refine hb.mono fun x hx => ?_ rw [abs_mul] exact mul_le_mul (abs_arg_le_pi _) hx (abs_nonneg _) Real.pi_pos.le theorem isBigO_cpow_rpow (hl : IsBoundedUnder (Β· ≀ Β·) l fun x => |(g x).im|) : (fun x => f x ^ g x) =O[l] fun x => β€–f xβ€– ^ (g x).re := calc (fun x => f x ^ g x) =O[l] (show Ξ± β†’ ℝ from fun x => β€–f xβ€– ^ (g x).re / Real.exp (arg (f x) * im (g x))) := isBigO_of_le _ fun _ => (norm_cpow_le _ _).trans (le_abs_self _) _ =Θ[l] (show Ξ± β†’ ℝ from fun x => β€–f xβ€– ^ (g x).re / (1 : ℝ)) := ((isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl)) _ =αΆ [l] (show Ξ± β†’ ℝ from fun x => β€–f xβ€– ^ (g x).re) := by simp only [div_one, EventuallyEq.rfl] theorem isTheta_cpow_rpow (hl_im : IsBoundedUnder (Β· ≀ Β·) l fun x => |(g x).im|) (hl : βˆ€αΆ  x in l, f x = 0 β†’ re (g x) = 0 β†’ g x = 0) : (fun x => f x ^ g x) =Θ[l] fun x => β€–f xβ€– ^ (g x).re := calc (fun x => f x ^ g x) =Θ[l] (fun x => β€–f xβ€– ^ (g x).re / Real.exp (arg (f x) * im (g x))) := .of_norm_eventuallyEq <| hl.mono fun _ => norm_cpow_of_imp _ =Θ[l] fun x => β€–f xβ€– ^ (g x).re / (1 : ℝ) := (isTheta_refl _ _).div (isTheta_exp_arg_mul_im hl_im) _ =αΆ [l] (fun x => β€–f xβ€– ^ (g x).re) := by simp only [div_one, EventuallyEq.rfl] theorem isTheta_cpow_const_rpow {b : β„‚} (hl : b.re = 0 β†’ b β‰  0 β†’ βˆ€αΆ  x in l, f x β‰  0) : (fun x => f x ^ b) =Θ[l] fun x => β€–f xβ€– ^ b.re := isTheta_cpow_rpow isBoundedUnder_const <| by simpa only [eventually_imp_distrib_right, not_imp_not, Imp.swap (a := b.re = 0)] using hl end end Complex open Real namespace Asymptotics variable {Ξ± : Type*} {r c : ℝ} {l : Filter Ξ±} {f g : Ξ± β†’ ℝ} theorem IsBigOWith.rpow (h : IsBigOWith c l f g) (hc : 0 ≀ c) (hr : 0 ≀ r) (hg : 0 ≀ᢠ[l] g) : IsBigOWith (c ^ r) l (fun x => f x ^ r) fun x => g x ^ r := by apply IsBigOWith.of_bound filter_upwards [hg, h.bound] with x hgx hx calc |f x ^ r| ≀ |f x| ^ r := abs_rpow_le_abs_rpow _ _ _ ≀ (c * |g x|) ^ r := by gcongr; assumption _ = c ^ r * |g x ^ r| := by rw [mul_rpow hc (abs_nonneg _), abs_rpow_of_nonneg hgx] theorem IsBigO.rpow (hr : 0 ≀ r) (hg : 0 ≀ᢠ[l] g) (h : f =O[l] g) : (fun x => f x ^ r) =O[l] fun x => g x ^ r := let ⟨_, hc, h'⟩ := h.exists_nonneg (h'.rpow hc hr hg).isBigO theorem IsTheta.rpow (hr : 0 ≀ r) (hf : 0 ≀ᢠ[l] f) (hg : 0 ≀ᢠ[l] g) (h : f =Θ[l] g) : (fun x => f x ^ r) =Θ[l] fun x => g x ^ r := ⟨h.1.rpow hr hg, h.2.rpow hr hf⟩ theorem IsLittleO.rpow (hr : 0 < r) (hg : 0 ≀ᢠ[l] g) (h : f =o[l] g) : (fun x => f x ^ r) =o[l] fun x => g x ^ r := by refine .of_isBigOWith fun c hc ↦ ?_ rw [← rpow_inv_rpow hc.le hr.ne'] refine (h.forall_isBigOWith ?_).rpow ?_ ?_ hg <;> positivity protected lemma IsBigO.sqrt (hfg : f =O[l] g) (hg : 0 ≀ᢠ[l] g) : (fun x ↦ √(f x)) =O[l] (fun x ↦ √(g x)) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos.le hg protected lemma IsLittleO.sqrt (hfg : f =o[l] g) (hg : 0 ≀ᢠ[l] g) : (fun x ↦ √(f x)) =o[l] (fun x ↦ √(g x)) := by simpa [Real.sqrt_eq_rpow] using hfg.rpow one_half_pos hg protected lemma IsTheta.sqrt (hfg : f =Θ[l] g) (hf : 0 ≀ᢠ[l] f) (hg : 0 ≀ᢠ[l] g) : (Real.sqrt <| f Β·) =Θ[l] (Real.sqrt <| g Β·) := ⟨hfg.1.sqrt hg, hfg.2.sqrt hf⟩ theorem isBigO_atTop_natCast_rpow_of_tendsto_div_rpow {π•œ : Type*} [RCLike π•œ] {g : β„• β†’ π•œ} {a : π•œ} {r : ℝ} (hlim : Tendsto (fun n ↦ g n / (n ^ r : ℝ)) atTop (𝓝 a)) : g =O[atTop] fun n ↦ (n : ℝ) ^ r := by refine (isBigO_of_div_tendsto_nhds ?_ β€–aβ€– ?_).of_norm_left Β· filter_upwards [eventually_ne_atTop 0] with _ h simp [Real.rpow_eq_zero_iff_of_nonneg, h] Β· exact hlim.norm.congr fun n ↦ by simp [abs_of_nonneg, show 0 ≀ (n : ℝ) ^ r by positivity] variable {E : Type*} [SeminormedRing E] (a b c : ℝ) theorem IsBigO.mul_atTop_rpow_of_isBigO_rpow {f g : ℝ β†’ E} (hf : f =O[atTop] fun t ↦ (t : ℝ) ^ a) (hg : g =O[atTop] fun t ↦ (t : ℝ) ^ b) (h : a + b ≀ c) : (f * g) =O[atTop] fun t ↦ (t : ℝ) ^ c := by refine (hf.mul hg).trans (Eventually.isBigO ?_) filter_upwards [eventually_ge_atTop 1] with t ht rw [← Real.rpow_add (zero_lt_one.trans_le ht), Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans ht) (a + b))] exact Real.rpow_le_rpow_of_exponent_le ht h theorem IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow {f g : β„• β†’ E} (hf : f =O[atTop] fun n ↦ (n : ℝ) ^ a) (hg : g =O[atTop] fun n ↦ (n : ℝ) ^ b) (h : a + b ≀ c) : (f * g) =O[atTop] fun n ↦ (n : ℝ) ^ c := by refine (hf.mul hg).trans (Eventually.isBigO ?_) filter_upwards [eventually_ge_atTop 1] with t ht replace ht : 1 ≀ (t : ℝ) := Nat.one_le_cast.mpr ht rw [← Real.rpow_add (zero_lt_one.trans_le ht), Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans ht) (a + b))] exact Real.rpow_le_rpow_of_exponent_le ht h end Asymptotics open Asymptotics /-- `x ^ s = o(exp(b * x))` as `x β†’ ∞` for any real `s` and positive `b`. -/ theorem isLittleO_rpow_exp_pos_mul_atTop (s : ℝ) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ s) =o[atTop] fun x => exp (b * x) := isLittleO_of_tendsto (fun _ h => absurd h (exp_pos _).ne') <| by simpa only [div_eq_mul_inv, exp_neg, neg_mul] using tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero s b hb /-- `x ^ k = o(exp(b * x))` as `x β†’ ∞` for any integer `k` and positive `b`. -/ theorem isLittleO_zpow_exp_pos_mul_atTop (k : β„€) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ k) =o[atTop] fun x => exp (b * x) := by simpa only [Real.rpow_intCast] using isLittleO_rpow_exp_pos_mul_atTop k hb /-- `x ^ k = o(exp(b * x))` as `x β†’ ∞` for any natural `k` and positive `b`. -/ theorem isLittleO_pow_exp_pos_mul_atTop (k : β„•) {b : ℝ} (hb : 0 < b) : (fun x : ℝ => x ^ k) =o[atTop] fun x => exp (b * x) := by simpa using isLittleO_zpow_exp_pos_mul_atTop k hb /-- `x ^ s = o(exp x)` as `x β†’ ∞` for any real `s`. -/ theorem isLittleO_rpow_exp_atTop (s : ℝ) : (fun x : ℝ => x ^ s) =o[atTop] exp := by simpa only [one_mul] using isLittleO_rpow_exp_pos_mul_atTop s one_pos /-- `exp (-a * x) = o(x ^ s)` as `x β†’ ∞`, for any positive `a` and real `s`. -/ theorem isLittleO_exp_neg_mul_rpow_atTop {a : ℝ} (ha : 0 < a) (b : ℝ) : IsLittleO atTop (fun x : ℝ => exp (-a * x)) fun x : ℝ => x ^ b := by apply isLittleO_of_tendsto' Β· refine (eventually_gt_atTop 0).mono fun t ht h => ?_ rw [rpow_eq_zero_iff_of_nonneg ht.le] at h exact (ht.ne' h.1).elim Β· refine (tendsto_exp_mul_div_rpow_atTop (-b) a ha).inv_tendsto_atTop.congr' ?_ refine (eventually_ge_atTop 0).mono fun t ht => ?_ simp [field, Real.exp_neg, rpow_neg ht] theorem isLittleO_log_rpow_atTop {r : ℝ} (hr : 0 < r) : log =o[atTop] fun x => x ^ r := calc log =O[atTop] fun x => r * log x := isBigO_self_const_mul hr.ne' _ _ _ =αΆ [atTop] fun x => log (x ^ r) := ((eventually_gt_atTop 0).mono fun _ hx => (log_rpow hx _).symm) _ =o[atTop] fun x => x ^ r := isLittleO_log_id_atTop.comp_tendsto (tendsto_rpow_atTop hr) theorem isLittleO_log_rpow_rpow_atTop {s : ℝ} (r : ℝ) (hs : 0 < s) : (fun x => log x ^ r) =o[atTop] fun x => x ^ s := let r' := max r 1 have hr : 0 < r' := lt_max_iff.2 <| Or.inr one_pos have H : 0 < s / r' := div_pos hs hr calc (fun x => log x ^ r) =O[atTop] fun x => log x ^ r' := .of_norm_eventuallyLE <| by filter_upwards [tendsto_log_atTop.eventually_ge_atTop 1] with x hx rw [Real.norm_of_nonneg (by positivity)] gcongr exacts [hx, le_max_left _ _] _ =o[atTop] fun x => (x ^ (s / r')) ^ r' := ((isLittleO_log_rpow_atTop H).rpow hr <| (_root_.tendsto_rpow_atTop H).eventually <| eventually_ge_atTop 0) _ =αΆ [atTop] fun x => x ^ s := (eventually_ge_atTop 0).mono fun x hx ↦ by simp only [← rpow_mul hx, div_mul_cancelβ‚€ _ hr.ne'] theorem isLittleO_abs_log_rpow_rpow_nhdsGT_zero {s : ℝ} (r : ℝ) (hs : s < 0) : (fun x => |log x| ^ r) =o[𝓝[>] 0] fun x => x ^ s := ((isLittleO_log_rpow_rpow_atTop r (neg_pos.2 hs)).comp_tendsto tendsto_inv_nhdsGT_zero).congr' (mem_of_superset (Icc_mem_nhdsGT one_pos) fun x hx => by simp [abs_of_nonpos, log_nonpos hx.1 hx.2]) (eventually_mem_nhdsWithin.mono fun x hx => by rw [Function.comp_apply, inv_rpow hx.out.le, rpow_neg hx.out.le, inv_inv]) theorem isLittleO_log_rpow_nhdsGT_zero {r : ℝ} (hr : r < 0) : log =o[𝓝[>] 0] fun x => x ^ r := (isLittleO_abs_log_rpow_rpow_nhdsGT_zero 1 hr).neg_left.congr' (mem_of_superset (Icc_mem_nhdsGT one_pos) fun x hx => by simp [abs_of_nonpos (log_nonpos hx.1 hx.2)]) .rfl theorem tendsto_log_div_rpow_nhdsGT_zero {r : ℝ} (hr : r < 0) : Tendsto (fun x => log x / x ^ r) (𝓝[>] 0) (𝓝 0) := (isLittleO_log_rpow_nhdsGT_zero hr).tendsto_div_nhds_zero theorem tendsto_log_mul_rpow_nhdsGT_zero {r : ℝ} (hr : 0 < r) : Tendsto (fun x => log x * x ^ r) (𝓝[>] 0) (𝓝 0) := (tendsto_log_div_rpow_nhdsGT_zero <| neg_lt_zero.2 hr).congr' <| eventually_mem_nhdsWithin.mono fun x hx => by rw [rpow_neg hx.out.le, div_inv_eq_mul] lemma tendsto_log_mul_self_nhdsLT_zero : Filter.Tendsto (fun x ↦ log x * x) (𝓝[<] 0) (𝓝 0) := by have h := tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one simp only [Real.rpow_one] at h have h_eq : βˆ€ x ∈ Set.Iio 0, (-(fun x ↦ log x * x) ∘ (fun x ↦ |x|)) x = log x * x := by simp only [Set.mem_Iio, Pi.neg_apply, Function.comp_apply, log_abs] intro x hx simp only [abs_of_nonpos hx.le, mul_neg, neg_neg] refine tendsto_nhdsWithin_congr h_eq ?_ nth_rewrite 3 [← neg_zero] refine (h.comp (tendsto_abs_nhdsNE_zero.mono_left ?_)).neg refine nhdsWithin_mono 0 (fun x hx ↦ ?_) simp only [Set.mem_Iio] at hx simp only [Set.mem_compl_iff, Set.mem_singleton_iff, hx.ne, not_false_eq_true]
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/Integral.lean
import Mathlib.Analysis.SpecialFunctions.Integrals.Basic import Mathlib.MeasureTheory.Integral.Layercake /-! # The integral of the real power of a nonnegative function In this file, we give a common application of the layer cake formula --- a representation of the integral of the p:th power of a nonnegative function `f`: `∫ f(Ο‰)^p βˆ‚ΞΌ(Ο‰) = p * ∫ t^(p-1) * ΞΌ {Ο‰ | f(Ο‰) β‰₯ t} dt`. A variant of the formula with measures of sets of the form `{Ο‰ | f(Ο‰) > t}` instead of `{Ο‰ | f(Ο‰) β‰₯ t}` is also included. ## Main results * `MeasureTheory.lintegral_rpow_eq_lintegral_meas_le_mul` and `MeasureTheory.lintegral_rpow_eq_lintegral_meas_lt_mul`: other common special cases of the layer cake formulas, stating that for a nonnegative function `f` and `p > 0`, we have `∫ f(Ο‰)α΅– βˆ‚ΞΌ(Ο‰) = p * ∫ ΞΌ {Ο‰ | f(Ο‰) β‰₯ t} * tᡖ⁻¹ dt` and `∫ f(Ο‰)α΅– βˆ‚ΞΌ(Ο‰) = p * ∫ ΞΌ {Ο‰ | f(Ο‰) > t} * tᡖ⁻¹ dt`, respectively. ## Tags layer cake representation, Cavalieri's principle, tail probability formula -/ open Set namespace MeasureTheory variable {Ξ± : Type*} [MeasurableSpace Ξ±] (ΞΌ : Measure Ξ±) section Layercake /-- An application of the layer cake formula / Cavalieri's principle / tail probability formula: For a nonnegative function `f` on a measure space, the Lebesgue integral of `f` can be written (roughly speaking) as: `∫⁻ f^p βˆ‚ΞΌ = p * ∫⁻ t in 0..∞, t^(p-1) * ΞΌ {Ο‰ | f(Ο‰) β‰₯ t}`. See `MeasureTheory.lintegral_rpow_eq_lintegral_meas_lt_mul` for a version with sets of the form `{Ο‰ | f(Ο‰) > t}` instead. -/ theorem lintegral_rpow_eq_lintegral_meas_le_mul {f : Ξ± β†’ ℝ} (f_nn : 0 ≀ᡐ[ΞΌ] f) (f_mble : AEMeasurable f ΞΌ) {p : ℝ} (p_pos : 0 < p) : ∫⁻ Ο‰, ENNReal.ofReal (f Ο‰ ^ p) βˆ‚ΞΌ = ENNReal.ofReal p * ∫⁻ t in Ioi 0, ΞΌ {a : Ξ± | t ≀ f a} * ENNReal.ofReal (t ^ (p - 1)) := by have one_lt_p : -1 < p - 1 := by linarith have obs : βˆ€ x : ℝ, ∫ t : ℝ in 0..x, t ^ (p - 1) = x ^ p / p := by intro x rw [integral_rpow (Or.inl one_lt_p)] simp [Real.zero_rpow p_pos.ne.symm] set g := fun t : ℝ => t ^ (p - 1) have g_nn : βˆ€α΅ t βˆ‚volume.restrict (Ioi (0 : ℝ)), 0 ≀ g t := by filter_upwards [self_mem_ae_restrict (measurableSet_Ioi : MeasurableSet (Ioi (0 : ℝ)))] intro t t_pos exact Real.rpow_nonneg (mem_Ioi.mp t_pos).le (p - 1) have g_intble (t) (ht : 0 < t) : IntervalIntegrable g volume 0 t := intervalIntegral.intervalIntegrable_rpow' one_lt_p have key := lintegral_comp_eq_lintegral_meas_le_mul ΞΌ f_nn f_mble g_intble g_nn rw [← key, ← lintegral_const_mul'' (ENNReal.ofReal p)] <;> simp_rw [obs] Β· congr with Ο‰ rw [← ENNReal.ofReal_mul p_pos.le, mul_div_cancelβ‚€ (f Ο‰ ^ p) p_pos.ne.symm] Β· have aux := (measurable_const (a := p)).aemeasurable (ΞΌ := ΞΌ) exact measurable_id.ennreal_ofReal.comp_aemeasurable <| (f_mble.pow aux).div_const p end Layercake section LayercakeLT /-- An application of the layer cake formula / Cavalieri's principle / tail probability formula: For a nonnegative function `f` on a measure space, the Lebesgue integral of `f` can be written (roughly speaking) as: `∫⁻ f^p βˆ‚ΞΌ = p * ∫⁻ t in 0..∞, t^(p-1) * ΞΌ {Ο‰ | f(Ο‰) > t}`. See `MeasureTheory.lintegral_rpow_eq_lintegral_meas_le_mul` for a version with sets of the form `{Ο‰ | f(Ο‰) β‰₯ t}` instead. -/ theorem lintegral_rpow_eq_lintegral_meas_lt_mul {f : Ξ± β†’ ℝ} (f_nn : 0 ≀ᡐ[ΞΌ] f) (f_mble : AEMeasurable f ΞΌ) {p : ℝ} (p_pos : 0 < p) : ∫⁻ Ο‰, ENNReal.ofReal (f Ο‰ ^ p) βˆ‚ΞΌ = ENNReal.ofReal p * ∫⁻ t in Ioi 0, ΞΌ {a : Ξ± | t < f a} * ENNReal.ofReal (t ^ (p - 1)) := by rw [lintegral_rpow_eq_lintegral_meas_le_mul ΞΌ f_nn f_mble p_pos] apply congr_arg fun z => ENNReal.ofReal p * z apply lintegral_congr_ae filter_upwards [meas_le_ae_eq_meas_lt ΞΌ (volume.restrict (Ioi 0)) f] with t ht rw [ht] end LayercakeLT end MeasureTheory
.lake/packages/mathlib/Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv import Mathlib.Analysis.Calculus.FDeriv.Extend import Mathlib.Analysis.Calculus.Deriv.Prod import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # Derivatives of power function on `β„‚`, `ℝ`, `ℝβ‰₯0`, and `ℝβ‰₯0∞` We also prove differentiability and provide derivatives for the power functions `x ^ y`. -/ noncomputable section open scoped Real Topology NNReal ENNReal open Filter namespace Complex theorem hasStrictFDerivAt_cpow {p : β„‚ Γ— β„‚} (hp : p.1 ∈ slitPlane) : HasStrictFDerivAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst β„‚ β„‚ β„‚ + (p.1 ^ p.2 * log p.1) β€’ ContinuousLinearMap.snd β„‚ β„‚ β„‚) p := by have A : p.1 β‰  0 := slitPlane_ne_zero hp have : (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) := ((isOpen_ne.preimage continuous_fst).eventually_mem A).mono fun p hp => cpow_def_of_ne_zero hp _ rw [cpow_sub _ _ A, cpow_one, mul_div_left_comm, mul_smul, mul_smul] refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, mul_smul, add_comm, smul_add] using ((hasStrictFDerivAt_fst.clog hp).mul hasStrictFDerivAt_snd).cexp theorem hasStrictFDerivAt_cpow' {x y : β„‚} (hp : x ∈ slitPlane) : HasStrictFDerivAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) ((y * x ^ (y - 1)) β€’ ContinuousLinearMap.fst β„‚ β„‚ β„‚ + (x ^ y * log x) β€’ ContinuousLinearMap.snd β„‚ β„‚ β„‚) (x, y) := @hasStrictFDerivAt_cpow (x, y) hp theorem hasStrictDerivAt_const_cpow {x y : β„‚} (h : x β‰  0 ∨ y β‰  0) : HasStrictDerivAt (fun y => x ^ y) (x ^ y * log x) y := by rcases em (x = 0) with (rfl | hx) Β· replace h := h.neg_resolve_left rfl rw [log_zero, mul_zero] refine (hasStrictDerivAt_const y 0).congr_of_eventuallyEq ?_ exact (isOpen_ne.eventually_mem h).mono fun y hy => (zero_cpow hy).symm Β· simpa only [cpow_def_of_ne_zero hx, mul_one] using ((hasStrictDerivAt_id y).const_mul (log x)).cexp theorem hasFDerivAt_cpow {p : β„‚ Γ— β„‚} (hp : p.1 ∈ slitPlane) : HasFDerivAt (fun x : β„‚ Γ— β„‚ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst β„‚ β„‚ β„‚ + (p.1 ^ p.2 * log p.1) β€’ ContinuousLinearMap.snd β„‚ β„‚ β„‚) p := (hasStrictFDerivAt_cpow hp).hasFDerivAt end Complex section fderiv open Complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] {f g : E β†’ β„‚} {f' g' : StrongDual β„‚ E} {x : E} {s : Set E} {c : β„‚} theorem HasStrictFDerivAt.cpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Complex.log (f x)) β€’ g') x := (hasStrictFDerivAt_cpow (p := (f x, g x)) h0).comp x (hf.prodMk hg) theorem HasStrictFDerivAt.const_cpow (hf : HasStrictFDerivAt f f' x) (h0 : c β‰  0 ∨ f x β‰  0) : HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) β€’ f') x := (hasStrictDerivAt_const_cpow h0).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.cpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Complex.log (f x)) β€’ g') x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prodMk hg) theorem HasFDerivAt.const_cpow (hf : HasFDerivAt f f' x) (h0 : c β‰  0 ∨ f x β‰  0) : HasFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) β€’ f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivAt x hf theorem HasFDerivWithinAt.cpow (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasFDerivWithinAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Complex.log (f x)) β€’ g') s x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasFDerivWithinAt.const_cpow (hf : HasFDerivWithinAt f f' s x) (h0 : c β‰  0 ∨ f x β‰  0) : HasFDerivWithinAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) β€’ f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivWithinAt x hf @[fun_prop] theorem DifferentiableAt.cpow (hf : DifferentiableAt β„‚ f x) (hg : DifferentiableAt β„‚ g x) (h0 : f x ∈ slitPlane) : DifferentiableAt β„‚ (fun x => f x ^ g x) x := (hf.hasFDerivAt.cpow hg.hasFDerivAt h0).differentiableAt @[fun_prop] theorem DifferentiableAt.const_cpow (hf : DifferentiableAt β„‚ f x) (h0 : c β‰  0 ∨ f x β‰  0) : DifferentiableAt β„‚ (fun x => c ^ f x) x := (hf.hasFDerivAt.const_cpow h0).differentiableAt @[fun_prop] theorem DifferentiableAt.cpow_const (hf : DifferentiableAt β„‚ f x) (h0 : f x ∈ slitPlane) : DifferentiableAt β„‚ (fun x => f x ^ c) x := hf.cpow (differentiableAt_const c) h0 @[fun_prop] theorem DifferentiableWithinAt.cpow (hf : DifferentiableWithinAt β„‚ f s x) (hg : DifferentiableWithinAt β„‚ g s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt β„‚ (fun x => f x ^ g x) s x := (hf.hasFDerivWithinAt.cpow hg.hasFDerivWithinAt h0).differentiableWithinAt @[fun_prop] theorem DifferentiableWithinAt.const_cpow (hf : DifferentiableWithinAt β„‚ f s x) (h0 : c β‰  0 ∨ f x β‰  0) : DifferentiableWithinAt β„‚ (fun x => c ^ f x) s x := (hf.hasFDerivWithinAt.const_cpow h0).differentiableWithinAt @[fun_prop] theorem DifferentiableWithinAt.cpow_const (hf : DifferentiableWithinAt β„‚ f s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt β„‚ (fun x => f x ^ c) s x := hf.cpow (differentiableWithinAt_const c) h0 @[fun_prop] theorem DifferentiableOn.cpow (hf : DifferentiableOn β„‚ f s) (hg : DifferentiableOn β„‚ g s) (h0 : Set.MapsTo f s slitPlane) : DifferentiableOn β„‚ (fun x ↦ f x ^ g x) s := fun x hx ↦ (hf x hx).cpow (hg x hx) (h0 hx) @[fun_prop] theorem DifferentiableOn.const_cpow (hf : DifferentiableOn β„‚ f s) (h0 : c β‰  0 ∨ βˆ€ x ∈ s, f x β‰  0) : DifferentiableOn β„‚ (fun x ↦ c ^ f x) s := fun x hx ↦ (hf x hx).const_cpow (h0.imp_right fun h ↦ h x hx) @[fun_prop] theorem DifferentiableOn.cpow_const (hf : DifferentiableOn β„‚ f s) (h0 : βˆ€ x ∈ s, f x ∈ slitPlane) : DifferentiableOn β„‚ (fun x => f x ^ c) s := hf.cpow (differentiableOn_const c) h0 @[fun_prop] theorem Differentiable.cpow (hf : Differentiable β„‚ f) (hg : Differentiable β„‚ g) (h0 : βˆ€ x, f x ∈ slitPlane) : Differentiable β„‚ (fun x ↦ f x ^ g x) := fun x ↦ (hf x).cpow (hg x) (h0 x) @[fun_prop] theorem Differentiable.const_cpow (hf : Differentiable β„‚ f) (h0 : c β‰  0 ∨ βˆ€ x, f x β‰  0) : Differentiable β„‚ (fun x ↦ c ^ f x) := fun x ↦ (hf x).const_cpow (h0.imp_right fun h ↦ h x) @[fun_prop] lemma differentiable_const_cpow_of_neZero (z : β„‚) [NeZero z] : Differentiable β„‚ fun s : β„‚ ↦ z ^ s := differentiable_id.const_cpow (.inl <| NeZero.ne z) @[fun_prop] lemma differentiableAt_const_cpow_of_neZero (z : β„‚) [NeZero z] (t : β„‚) : DifferentiableAt β„‚ (fun s : β„‚ ↦ z ^ s) t := differentiableAt_id.const_cpow (.inl <| NeZero.ne z) end fderiv section deriv open Complex variable {f g : β„‚ β†’ β„‚} {s : Set β„‚} {f' g' x c : β„‚} /-- A private lemma that rewrites the output of lemmas like `HasFDerivAt.cpow` to the form expected by lemmas like `HasDerivAt.cpow`. -/ private theorem aux : ((g x * f x ^ (g x - 1)) β€’ (1 : β„‚ β†’L[β„‚] β„‚).smulRight f' + (f x ^ g x * log (f x)) β€’ (1 : β„‚ β†’L[β„‚] β„‚).smulRight g') 1 = g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' := by simp only [Algebra.id.smul_eq_mul, one_mul, ContinuousLinearMap.one_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul'] nonrec theorem HasStrictDerivAt.cpow (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa using (hf.cpow hg h0).hasStrictDerivAt theorem HasStrictDerivAt.const_cpow (hf : HasStrictDerivAt f f' x) (h : c β‰  0 ∨ f x β‰  0) : HasStrictDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h).comp x hf theorem Complex.hasStrictDerivAt_cpow_const (h : x ∈ slitPlane) : HasStrictDerivAt (fun z : β„‚ => z ^ c) (c * x ^ (c - 1)) x := by simpa only [mul_zero, add_zero, mul_one] using (hasStrictDerivAt_id x).cpow (hasStrictDerivAt_const x c) h theorem HasStrictDerivAt.cpow_const (hf : HasStrictDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).comp x hf theorem HasDerivAt.cpow (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa only [aux] using (hf.hasFDerivAt.cpow hg h0).hasDerivAt theorem HasDerivAt.const_cpow (hf : HasDerivAt f f' x) (h0 : c β‰  0 ∨ f x β‰  0) : HasDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp x hf theorem HasDerivAt.cpow_const (hf : HasDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp x hf theorem HasDerivWithinAt.cpow (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') s x := by simpa only [aux] using (hf.hasFDerivWithinAt.cpow hg h0).hasDerivWithinAt theorem HasDerivWithinAt.const_cpow (hf : HasDerivWithinAt f f' s x) (h0 : c β‰  0 ∨ f x β‰  0) : HasDerivWithinAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasDerivWithinAt x hf theorem HasDerivWithinAt.cpow_const (hf : HasDerivWithinAt f f' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') s x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp_hasDerivWithinAt x hf /-- Although `fun x => x ^ r` for fixed `r` is *not* complex-differentiable along the negative real line, it is still real-differentiable, and the derivative is what one would formally expect. See `hasDerivAt_ofReal_cpow_const` for an alternate formulation. -/ theorem hasDerivAt_ofReal_cpow_const' {x : ℝ} (hx : x β‰  0) {r : β„‚} (hr : r β‰  -1) : HasDerivAt (fun y : ℝ => (y : β„‚) ^ (r + 1) / (r + 1)) (x ^ r) x := by rw [Ne, ← add_eq_zero_iff_eq_neg, ← Ne] at hr rcases lt_or_gt_of_ne hx.symm with (hx | hx) Β· -- easy case : `0 < x` apply HasDerivAt.comp_ofReal (e := fun y => (y : β„‚) ^ (r + 1) / (r + 1)) convert HasDerivAt.div_const (π•œ := β„‚) ?_ (r + 1) using 1 Β· exact (mul_div_cancel_rightβ‚€ _ hr).symm Β· convert HasDerivAt.cpow_const ?_ ?_ using 1 Β· rw [add_sub_cancel_right, mul_comm]; exact (mul_one _).symm Β· exact hasDerivAt_id (x : β„‚) Β· simp [hx] Β· -- harder case : `x < 0` have : βˆ€αΆ  y : ℝ in 𝓝 x, (y : β„‚) ^ (r + 1) / (r + 1) = (-y : β„‚) ^ (r + 1) * exp (Ο€ * I * (r + 1)) / (r + 1) := by refine Filter.eventually_of_mem (Iio_mem_nhds hx) fun y hy => ?_ rw [ofReal_cpow_of_nonpos (le_of_lt hy)] refine HasDerivAt.congr_of_eventuallyEq ?_ this rw [ofReal_cpow_of_nonpos (le_of_lt hx)] suffices HasDerivAt (fun y : ℝ => (-↑y) ^ (r + 1) * exp (↑π * I * (r + 1))) ((r + 1) * (-↑x) ^ r * exp (↑π * I * r)) x by convert this.div_const (r + 1) using 1 conv_rhs => rw [mul_assoc, mul_comm, mul_div_cancel_rightβ‚€ _ hr] rw [mul_add ((Ο€ : β„‚) * _), mul_one, exp_add, exp_pi_mul_I, mul_comm (_ : β„‚) (-1 : β„‚), neg_one_mul] simp_rw [mul_neg, ← neg_mul, ← ofReal_neg] suffices HasDerivAt (fun y : ℝ => (↑(-y) : β„‚) ^ (r + 1)) (-(r + 1) * ↑(-x) ^ r) x by convert this.neg.mul_const _ using 1; ring suffices HasDerivAt (fun y : ℝ => (y : β„‚) ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) (-x) by convert @HasDerivAt.scomp ℝ _ β„‚ _ _ x ℝ _ _ _ _ _ _ _ _ this (hasDerivAt_neg x) using 1 rw [real_smul, ofReal_neg 1, ofReal_one]; ring suffices HasDerivAt (fun y : β„‚ => y ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) ↑(-x) by exact this.comp_ofReal conv in ↑_ ^ _ => rw [(by ring : r = r + 1 - 1)] convert HasDerivAt.cpow_const ?_ ?_ using 1 Β· rw [add_sub_cancel_right, add_sub_cancel_right]; exact (mul_one _).symm Β· exact hasDerivAt_id ((-x : ℝ) : β„‚) Β· simp [hx] /-- An alternate formulation of `hasDerivAt_ofReal_cpow_const'`. -/ theorem hasDerivAt_ofReal_cpow_const {x : ℝ} (hx : x β‰  0) {r : β„‚} (hr : r β‰  0) : HasDerivAt (fun y : ℝ => (y : β„‚) ^ r) (r * x ^ (r - 1)) x := by have := HasDerivAt.const_mul r <| hasDerivAt_ofReal_cpow_const' hx (by rwa [ne_eq, sub_eq_neg_self]) simpa [sub_add_cancel, mul_div_cancelβ‚€ _ hr] using this /-- A version of `DifferentiableAt.cpow_const` for a real function. -/ theorem DifferentiableAt.ofReal_cpow_const {f : ℝ β†’ ℝ} {x : ℝ} (hf : DifferentiableAt ℝ f x) (h0 : f x β‰  0) (h1 : c β‰  0) : DifferentiableAt ℝ (fun (y : ℝ) => (f y : β„‚) ^ c) x := (hasDerivAt_ofReal_cpow_const h0 h1).differentiableAt.comp x hf theorem Complex.deriv_cpow_const (hx : x ∈ Complex.slitPlane) : deriv (fun (x : β„‚) ↦ x ^ c) x = c * x ^ (c - 1) := (hasStrictDerivAt_cpow_const hx).hasDerivAt.deriv /-- A version of `Complex.deriv_cpow_const` for a real variable. -/ theorem Complex.deriv_ofReal_cpow_const {x : ℝ} (hx : x β‰  0) (hc : c β‰  0) : deriv (fun x : ℝ ↦ (x : β„‚) ^ c) x = c * x ^ (c - 1) := (hasDerivAt_ofReal_cpow_const hx hc).deriv theorem deriv_cpow_const (hf : DifferentiableAt β„‚ f x) (hx : f x ∈ Complex.slitPlane) : deriv (fun (x : β„‚) ↦ f x ^ c) x = c * f x ^ (c - 1) * deriv f x := (hf.hasDerivAt.cpow_const hx).deriv theorem isTheta_deriv_ofReal_cpow_const_atTop {c : β„‚} (hc : c β‰  0) : deriv (fun (x : ℝ) => (x : β„‚) ^ c) =Θ[atTop] fun x => x ^ (c.re - 1) := by calc _ =αΆ [atTop] fun x : ℝ ↦ c * x ^ (c - 1) := by filter_upwards [eventually_ne_atTop 0] with x hx using by rw [deriv_ofReal_cpow_const hx hc] _ =Θ[atTop] fun x : ℝ ↦ β€–(x : β„‚) ^ (c - 1)β€– := (Asymptotics.IsTheta.of_norm_eventuallyEq EventuallyEq.rfl).const_mul_left hc _ =αΆ [atTop] fun x ↦ x ^ (c.re - 1) := by filter_upwards [eventually_gt_atTop 0] with x hx rw [norm_cpow_eq_rpow_re_of_pos hx, sub_re, one_re] theorem isBigO_deriv_ofReal_cpow_const_atTop (c : β„‚) : deriv (fun (x : ℝ) => (x : β„‚) ^ c) =O[atTop] fun x => x ^ (c.re - 1) := by obtain rfl | hc := eq_or_ne c 0 Β· simp_rw [cpow_zero, deriv_const', Asymptotics.isBigO_zero] Β· exact (isTheta_deriv_ofReal_cpow_const_atTop hc).1 end deriv namespace Real variable {x y z : ℝ} /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ Γ— ℝ` such that `0 < p.fst`. -/ theorem hasStrictFDerivAt_rpow_of_pos (p : ℝ Γ— ℝ) (hp : 0 < p.1) : HasStrictFDerivAt (fun x : ℝ Γ— ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1) β€’ ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ Γ— ℝ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) := (continuousAt_fst.eventually (lt_mem_nhds hp)).mono fun p hp => rpow_def_of_pos hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne').fun_mul hasStrictFDerivAt_snd).exp using 1 rw [rpow_sub_one hp.ne', ← rpow_def_of_pos hp, smul_add, smul_smul, mul_div_left_comm, div_eq_mul_inv, smul_smul, smul_smul, mul_assoc, add_comm] /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ Γ— ℝ` such that `p.fst < 0`. -/ theorem hasStrictFDerivAt_rpow_of_neg (p : ℝ Γ— ℝ) (hp : p.1 < 0) : HasStrictFDerivAt (fun x : ℝ Γ— ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) β€’ ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1 - exp (log p.1 * p.2) * sin (p.2 * Ο€) * Ο€) β€’ ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ Γ— ℝ => x.1 ^ x.2) =αΆ [𝓝 p] fun x => exp (log x.1 * x.2) * cos (x.2 * Ο€) := (continuousAt_fst.eventually (gt_mem_nhds hp)).mono fun p hp => rpow_def_of_neg hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne).fun_mul hasStrictFDerivAt_snd).exp.fun_mul (hasStrictFDerivAt_snd.mul_const Ο€).cos using 1 simp_rw [rpow_sub_one hp.ne, smul_add, ← add_assoc, smul_smul, ← add_smul, ← mul_assoc, mul_comm (cos _), ← rpow_def_of_neg hp] rw [div_eq_mul_inv, add_comm]; congr 2 <;> ring /-- The function `fun (x, y) => x ^ y` is infinitely smooth at `(x, y)` unless `x = 0`. -/ theorem contDiffAt_rpow_of_ne (p : ℝ Γ— ℝ) (hp : p.1 β‰  0) {n : WithTop β„•βˆž} : ContDiffAt ℝ n (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := by rcases hp.lt_or_gt with hneg | hpos exacts [(((contDiffAt_fst.log hneg.ne).mul contDiffAt_snd).exp.mul (contDiffAt_snd.mul contDiffAt_const).cos).congr_of_eventuallyEq ((continuousAt_fst.eventually (gt_mem_nhds hneg)).mono fun p hp => rpow_def_of_neg hp _), ((contDiffAt_fst.log hpos.ne').mul contDiffAt_snd).exp.congr_of_eventuallyEq ((continuousAt_fst.eventually (lt_mem_nhds hpos)).mono fun p hp => rpow_def_of_pos hp _)] theorem differentiableAt_rpow_of_ne (p : ℝ Γ— ℝ) (hp : p.1 β‰  0) : DifferentiableAt ℝ (fun p : ℝ Γ— ℝ => p.1 ^ p.2) p := (contDiffAt_rpow_of_ne p hp).differentiableAt le_rfl theorem _root_.HasStrictDerivAt.rpow {f g : ℝ β†’ ℝ} {f' g' : ℝ} (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h : 0 < f x) : HasStrictDerivAt (fun x => f x ^ g x) (f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) x := by convert (hasStrictFDerivAt_rpow_of_pos ((fun x => (f x, g x)) x) h).comp_hasStrictDerivAt x (hf.prodMk hg) using 1 simp [mul_assoc, mul_comm] theorem hasStrictDerivAt_rpow_const_of_ne {x : ℝ} (hx : x β‰  0) (p : ℝ) : HasStrictDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by rcases hx.lt_or_gt with hx | hx Β· have := (hasStrictFDerivAt_rpow_of_neg (x, p) hx).comp_hasStrictDerivAt x ((hasStrictDerivAt_id x).prodMk (hasStrictDerivAt_const x p)) convert this using 1; simp Β· simpa using (hasStrictDerivAt_id x).rpow (hasStrictDerivAt_const x p) hx theorem hasStrictDerivAt_const_rpow {a : ℝ} (ha : 0 < a) (x : ℝ) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a) x := by simpa using (hasStrictDerivAt_const _ _).rpow (hasStrictDerivAt_id x) ha lemma differentiableAt_rpow_const_of_ne (p : ℝ) {x : ℝ} (hx : x β‰  0) : DifferentiableAt ℝ (fun x => x ^ p) x := (hasStrictDerivAt_rpow_const_of_ne hx p).differentiableAt lemma differentiableOn_rpow_const (p : ℝ) : DifferentiableOn ℝ (fun x => (x : ℝ) ^ p) {0}ᢜ := fun _ hx => (Real.differentiableAt_rpow_const_of_ne p hx).differentiableWithinAt /-- This lemma says that `fun x => a ^ x` is strictly differentiable for `a < 0`. Note that these values of `a` are outside of the "official" domain of `a ^ x`, and we may redefine `a ^ x` for negative `a` if some other definition will be more convenient. -/ theorem hasStrictDerivAt_const_rpow_of_neg {a x : ℝ} (ha : a < 0) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a - exp (log a * x) * sin (x * Ο€) * Ο€) x := by simpa using (hasStrictFDerivAt_rpow_of_neg (a, x) ha).comp_hasStrictDerivAt x ((hasStrictDerivAt_const _ _).prodMk (hasStrictDerivAt_id _)) end Real namespace Real variable {z x y : ℝ} theorem hasDerivAt_rpow_const {x p : ℝ} (h : x β‰  0 ∨ 1 ≀ p) : HasDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by rcases ne_or_eq x 0 with (hx | rfl) Β· exact (hasStrictDerivAt_rpow_const_of_ne hx _).hasDerivAt replace h : 1 ≀ p := h.neg_resolve_left rfl apply hasDerivAt_of_hasDerivAt_of_ne fun x hx => (hasStrictDerivAt_rpow_const_of_ne hx p).hasDerivAt exacts [continuousAt_id.rpow_const (Or.inr (zero_le_one.trans h)), continuousAt_const.mul (continuousAt_id.rpow_const (Or.inr (sub_nonneg.2 h)))] theorem differentiable_rpow_const {p : ℝ} (hp : 1 ≀ p) : Differentiable ℝ fun x : ℝ => x ^ p := fun _ => (hasDerivAt_rpow_const (Or.inr hp)).differentiableAt theorem deriv_rpow_const {x p : ℝ} (h : x β‰  0 ∨ 1 ≀ p) : deriv (fun x : ℝ => x ^ p) x = p * x ^ (p - 1) := (hasDerivAt_rpow_const h).deriv theorem deriv_rpow_const' {p : ℝ} (h : 1 ≀ p) : (deriv fun x : ℝ => x ^ p) = fun x => p * x ^ (p - 1) := funext fun _ => deriv_rpow_const (Or.inr h) theorem contDiffAt_rpow_const_of_ne {x p : ℝ} {n : WithTop β„•βˆž} (h : x β‰  0) : ContDiffAt ℝ n (fun x => x ^ p) x := (contDiffAt_rpow_of_ne (x, p) h).comp x (contDiffAt_id.prodMk contDiffAt_const) theorem contDiff_rpow_const_of_le {p : ℝ} {n : β„•} (h : ↑n ≀ p) : ContDiff ℝ n fun x : ℝ => x ^ p := by induction n generalizing p with | zero => exact contDiff_zero.2 (continuous_id.rpow_const fun x => Or.inr <| by simpa using h) | succ n ihn => have h1 : 1 ≀ p := le_trans (by simp) h rw [Nat.cast_succ, ← le_sub_iff_add_le] at h rw [show ((n + 1 : β„•) : WithTop β„•βˆž) = n + 1 from rfl, contDiff_succ_iff_deriv, deriv_rpow_const' h1] simp only [WithTop.natCast_ne_top, analyticOn_univ, IsEmpty.forall_iff, true_and] exact ⟨differentiable_rpow_const h1, contDiff_const.mul (ihn h)⟩ theorem contDiffAt_rpow_const_of_le {x p : ℝ} {n : β„•} (h : ↑n ≀ p) : ContDiffAt ℝ n (fun x : ℝ => x ^ p) x := (contDiff_rpow_const_of_le h).contDiffAt theorem contDiffAt_rpow_const {x p : ℝ} {n : β„•} (h : x β‰  0 ∨ ↑n ≀ p) : ContDiffAt ℝ n (fun x : ℝ => x ^ p) x := h.elim contDiffAt_rpow_const_of_ne contDiffAt_rpow_const_of_le theorem hasStrictDerivAt_rpow_const {x p : ℝ} (hx : x β‰  0 ∨ 1 ≀ p) : HasStrictDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := ContDiffAt.hasStrictDerivAt' (contDiffAt_rpow_const (by rwa [← Nat.cast_one] at hx)) (hasDerivAt_rpow_const hx) le_rfl end Real section Differentiability open Real section fderiv variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f g : E β†’ ℝ} {f' g' : StrongDual ℝ E} {x : E} {s : Set E} {c p : ℝ} {n : WithTop β„•βˆž} theorem HasFDerivWithinAt.rpow (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) (h : 0 < f x) : HasFDerivWithinAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Real.log (f x)) β€’ g') s x := by -- `by exact` to deal with tricky unification. exact (hasStrictFDerivAt_rpow_of_pos (f x, g x) h).hasFDerivAt.comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasFDerivAt.rpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) (h : 0 < f x) : HasFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Real.log (f x)) β€’ g') x := by exact (hasStrictFDerivAt_rpow_of_pos (f x, g x) h).hasFDerivAt.comp x (hf.prodMk hg) theorem HasStrictFDerivAt.rpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) (h : 0 < f x) : HasStrictFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) β€’ f' + (f x ^ g x * Real.log (f x)) β€’ g') x := (hasStrictFDerivAt_rpow_of_pos (f x, g x) h).comp x (hf.prodMk hg) @[fun_prop] theorem DifferentiableWithinAt.rpow (hf : DifferentiableWithinAt ℝ f s x) (hg : DifferentiableWithinAt ℝ g s x) (h : f x β‰  0) : DifferentiableWithinAt ℝ (fun x => f x ^ g x) s x := by -- `by exact` to deal with tricky unification. exact (differentiableAt_rpow_of_ne (f x, g x) h).comp_differentiableWithinAt x (hf.prodMk hg) @[fun_prop] theorem DifferentiableAt.rpow (hf : DifferentiableAt ℝ f x) (hg : DifferentiableAt ℝ g x) (h : f x β‰  0) : DifferentiableAt ℝ (fun x => f x ^ g x) x := by -- `by exact` to deal with tricky unification. exact (differentiableAt_rpow_of_ne (f x, g x) h).comp x (hf.prodMk hg) @[fun_prop] theorem DifferentiableOn.rpow (hf : DifferentiableOn ℝ f s) (hg : DifferentiableOn ℝ g s) (h : βˆ€ x ∈ s, f x β‰  0) : DifferentiableOn ℝ (fun x => f x ^ g x) s := fun x hx => (hf x hx).rpow (hg x hx) (h x hx) @[fun_prop] theorem Differentiable.rpow (hf : Differentiable ℝ f) (hg : Differentiable ℝ g) (h : βˆ€ x, f x β‰  0) : Differentiable ℝ fun x => f x ^ g x := fun x => (hf x).rpow (hg x) (h x) @[fun_prop] theorem HasFDerivWithinAt.rpow_const (hf : HasFDerivWithinAt f f' s x) (h : f x β‰  0 ∨ 1 ≀ p) : HasFDerivWithinAt (fun x => f x ^ p) ((p * f x ^ (p - 1)) β€’ f') s x := (hasDerivAt_rpow_const h).comp_hasFDerivWithinAt x hf @[fun_prop] theorem HasFDerivAt.rpow_const (hf : HasFDerivAt f f' x) (h : f x β‰  0 ∨ 1 ≀ p) : HasFDerivAt (fun x => f x ^ p) ((p * f x ^ (p - 1)) β€’ f') x := (hasDerivAt_rpow_const h).comp_hasFDerivAt x hf theorem HasStrictFDerivAt.rpow_const (hf : HasStrictFDerivAt f f' x) (h : f x β‰  0 ∨ 1 ≀ p) : HasStrictFDerivAt (fun x => f x ^ p) ((p * f x ^ (p - 1)) β€’ f') x := (hasStrictDerivAt_rpow_const h).comp_hasStrictFDerivAt x hf @[fun_prop] theorem DifferentiableWithinAt.rpow_const (hf : DifferentiableWithinAt ℝ f s x) (h : f x β‰  0 ∨ 1 ≀ p) : DifferentiableWithinAt ℝ (fun x => f x ^ p) s x := (hf.hasFDerivWithinAt.rpow_const h).differentiableWithinAt @[simp] theorem DifferentiableAt.rpow_const (hf : DifferentiableAt ℝ f x) (h : f x β‰  0 ∨ 1 ≀ p) : DifferentiableAt ℝ (fun x => f x ^ p) x := (hf.hasFDerivAt.rpow_const h).differentiableAt @[fun_prop] theorem DifferentiableOn.rpow_const (hf : DifferentiableOn ℝ f s) (h : βˆ€ x ∈ s, f x β‰  0 ∨ 1 ≀ p) : DifferentiableOn ℝ (fun x => f x ^ p) s := fun x hx => (hf x hx).rpow_const (h x hx) @[fun_prop] theorem Differentiable.rpow_const (hf : Differentiable ℝ f) (h : βˆ€ x, f x β‰  0 ∨ 1 ≀ p) : Differentiable ℝ fun x => f x ^ p := fun x => (hf x).rpow_const (h x) theorem HasFDerivWithinAt.const_rpow (hf : HasFDerivWithinAt f f' s x) (hc : 0 < c) : HasFDerivWithinAt (fun x => c ^ f x) ((c ^ f x * Real.log c) β€’ f') s x := (hasStrictDerivAt_const_rpow hc (f x)).hasDerivAt.comp_hasFDerivWithinAt x hf theorem HasFDerivAt.const_rpow (hf : HasFDerivAt f f' x) (hc : 0 < c) : HasFDerivAt (fun x => c ^ f x) ((c ^ f x * Real.log c) β€’ f') x := (hasStrictDerivAt_const_rpow hc (f x)).hasDerivAt.comp_hasFDerivAt x hf theorem HasStrictFDerivAt.const_rpow (hf : HasStrictFDerivAt f f' x) (hc : 0 < c) : HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Real.log c) β€’ f') x := (hasStrictDerivAt_const_rpow hc (f x)).comp_hasStrictFDerivAt x hf @[fun_prop] theorem ContDiffWithinAt.rpow (hf : ContDiffWithinAt ℝ n f s x) (hg : ContDiffWithinAt ℝ n g s x) (h : f x β‰  0) : ContDiffWithinAt ℝ n (fun x => f x ^ g x) s x := by -- `by exact` to deal with tricky unification. exact (contDiffAt_rpow_of_ne (f x, g x) h).comp_contDiffWithinAt x (hf.prodMk hg) @[fun_prop] theorem ContDiffAt.rpow (hf : ContDiffAt ℝ n f x) (hg : ContDiffAt ℝ n g x) (h : f x β‰  0) : ContDiffAt ℝ n (fun x => f x ^ g x) x := by -- `by exact` to deal with tricky unification. exact (contDiffAt_rpow_of_ne (f x, g x) h).comp x (hf.prodMk hg) @[fun_prop] theorem ContDiffOn.rpow (hf : ContDiffOn ℝ n f s) (hg : ContDiffOn ℝ n g s) (h : βˆ€ x ∈ s, f x β‰  0) : ContDiffOn ℝ n (fun x => f x ^ g x) s := fun x hx => (hf x hx).rpow (hg x hx) (h x hx) @[fun_prop] theorem ContDiff.rpow (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) (h : βˆ€ x, f x β‰  0) : ContDiff ℝ n fun x => f x ^ g x := contDiff_iff_contDiffAt.mpr fun x => hf.contDiffAt.rpow hg.contDiffAt (h x) @[fun_prop] theorem ContDiffWithinAt.rpow_const_of_ne (hf : ContDiffWithinAt ℝ n f s x) (h : f x β‰  0) : ContDiffWithinAt ℝ n (fun x => f x ^ p) s x := hf.rpow contDiffWithinAt_const h @[fun_prop] theorem ContDiffAt.rpow_const_of_ne (hf : ContDiffAt ℝ n f x) (h : f x β‰  0) : ContDiffAt ℝ n (fun x => f x ^ p) x := hf.rpow contDiffAt_const h @[fun_prop] theorem ContDiffOn.rpow_const_of_ne (hf : ContDiffOn ℝ n f s) (h : βˆ€ x ∈ s, f x β‰  0) : ContDiffOn ℝ n (fun x => f x ^ p) s := fun x hx => (hf x hx).rpow_const_of_ne (h x hx) @[fun_prop] theorem ContDiff.rpow_const_of_ne (hf : ContDiff ℝ n f) (h : βˆ€ x, f x β‰  0) : ContDiff ℝ n fun x => f x ^ p := hf.rpow contDiff_const h variable {m : β„•} @[fun_prop] theorem ContDiffWithinAt.rpow_const_of_le (hf : ContDiffWithinAt ℝ m f s x) (h : ↑m ≀ p) : ContDiffWithinAt ℝ m (fun x => f x ^ p) s x := (contDiffAt_rpow_const_of_le h).comp_contDiffWithinAt x hf @[fun_prop] theorem ContDiffAt.rpow_const_of_le (hf : ContDiffAt ℝ m f x) (h : ↑m ≀ p) : ContDiffAt ℝ m (fun x => f x ^ p) x := by rw [← contDiffWithinAt_univ] at *; exact hf.rpow_const_of_le h @[fun_prop] theorem ContDiffOn.rpow_const_of_le (hf : ContDiffOn ℝ m f s) (h : ↑m ≀ p) : ContDiffOn ℝ m (fun x => f x ^ p) s := fun x hx => (hf x hx).rpow_const_of_le h @[fun_prop] theorem ContDiff.rpow_const_of_le (hf : ContDiff ℝ m f) (h : ↑m ≀ p) : ContDiff ℝ m fun x => f x ^ p := contDiff_iff_contDiffAt.mpr fun _ => hf.contDiffAt.rpow_const_of_le h end fderiv section deriv variable {f g : ℝ β†’ ℝ} {f' g' x y p : ℝ} {s : Set ℝ} theorem HasDerivWithinAt.rpow (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) (h : 0 < f x) : HasDerivWithinAt (fun x => f x ^ g x) (f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) s x := by convert (hf.hasFDerivWithinAt.rpow hg.hasFDerivWithinAt h).hasDerivWithinAt using 1 dsimp; ring theorem HasDerivAt.rpow (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) (h : 0 < f x) : HasDerivAt (fun x => f x ^ g x) (f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) x := by rw [← hasDerivWithinAt_univ] at * exact hf.rpow hg h theorem HasDerivWithinAt.rpow_const (hf : HasDerivWithinAt f f' s x) (hx : f x β‰  0 ∨ 1 ≀ p) : HasDerivWithinAt (fun y => f y ^ p) (f' * p * f x ^ (p - 1)) s x := by convert (hasDerivAt_rpow_const hx).comp_hasDerivWithinAt x hf using 1 ring theorem HasDerivAt.rpow_const (hf : HasDerivAt f f' x) (hx : f x β‰  0 ∨ 1 ≀ p) : HasDerivAt (fun y => f y ^ p) (f' * p * f x ^ (p - 1)) x := by rw [← hasDerivWithinAt_univ] at * exact hf.rpow_const hx theorem derivWithin_rpow_const (hf : DifferentiableWithinAt ℝ f s x) (hx : f x β‰  0 ∨ 1 ≀ p) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => f x ^ p) s x = derivWithin f s x * p * f x ^ (p - 1) := (hf.hasDerivWithinAt.rpow_const hx).derivWithin hxs @[simp] theorem deriv_rpow_const (hf : DifferentiableAt ℝ f x) (hx : f x β‰  0 ∨ 1 ≀ p) : deriv (fun x => f x ^ p) x = deriv f x * p * f x ^ (p - 1) := (hf.hasDerivAt.rpow_const hx).deriv theorem deriv_norm_ofReal_cpow (c : β„‚) {t : ℝ} (ht : 0 < t) : (deriv fun x : ℝ ↦ β€–(x : β„‚) ^ cβ€–) t = c.re * t ^ (c.re - 1) := by rw [EventuallyEq.deriv_eq (f := fun x ↦ x ^ c.re)] Β· rw [Real.deriv_rpow_const (Or.inl ht.ne')] Β· filter_upwards [eventually_gt_nhds ht] with x hx rw [Complex.norm_cpow_eq_rpow_re_of_pos hx] lemma isTheta_deriv_rpow_const_atTop {p : ℝ} (hp : p β‰  0) : deriv (fun (x : ℝ) => x ^ p) =Θ[atTop] fun x => x ^ (p-1) := by calc deriv (fun (x : ℝ) => x ^ p) =αΆ [atTop] fun x => p * x ^ (p - 1) := by filter_upwards [eventually_ne_atTop 0] with x hx rw [Real.deriv_rpow_const (Or.inl hx)] _ =Θ[atTop] fun x => x ^ (p-1) := Asymptotics.IsTheta.const_mul_left hp Asymptotics.isTheta_rfl lemma isBigO_deriv_rpow_const_atTop (p : ℝ) : deriv (fun (x : ℝ) => x ^ p) =O[atTop] fun x => x ^ (p-1) := by rcases eq_or_ne p 0 with rfl | hp case inl => simp [zero_sub, Real.rpow_neg_one, Real.rpow_zero, deriv_const', Asymptotics.isBigO_zero] case inr => exact (isTheta_deriv_rpow_const_atTop hp).1 variable {a : ℝ} theorem HasDerivWithinAt.const_rpow (ha : 0 < a) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (a ^ f Β·) (Real.log a * f' * a ^ f x) s x := by convert (hasDerivWithinAt_const x s a).rpow hf ha using 1 ring theorem HasDerivAt.const_rpow (ha : 0 < a) (hf : HasDerivAt f f' x) : HasDerivAt (a ^ f Β·) (Real.log a * f' * a ^ f x) x := by rw [← hasDerivWithinAt_univ] at * exact hf.const_rpow ha theorem derivWithin_const_rpow (ha : 0 < a) (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (a ^ f Β·) s x = Real.log a * derivWithin f s x * a ^ f x := (hf.hasDerivWithinAt.const_rpow ha).derivWithin hxs @[simp] theorem deriv_const_rpow (ha : 0 < a) (hf : DifferentiableAt ℝ f x) : deriv (a ^ f Β·) x = Real.log a * deriv f x * a ^ f x := (hf.hasDerivAt.const_rpow ha).deriv end deriv end Differentiability