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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.