Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 2d6556d

Browse files
urkudsgouezeljcommelinmergify[bot]
authored
feat(analysis/mean_inequalities) : Prove AM-GM (#1836)
* feat(analysis/mean_inequalities) : Prove AM-GM * Update, add more inequalities * Update src/analysis/convex/specific_functions.lean Co-Authored-By: sgouezel <sebastien.gouezel@univ-rennes1.fr> * Update src/analysis/mean_inequalities.lean Co-Authored-By: sgouezel <sebastien.gouezel@univ-rennes1.fr> * Update src/analysis/mean_inequalities.lean * Small fixes, thanks @sgouezel * Update src/analysis/mean_inequalities.lean Co-Authored-By: Johan Commelin <johan@commelin.net> Co-authored-by: sgouezel <sebastien.gouezel@univ-rennes1.fr> Co-authored-by: Johan Commelin <johan@commelin.net> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 5b77b64 commit 2d6556d

File tree

7 files changed

+373
-4
lines changed

7 files changed

+373
-4
lines changed

src/analysis/calculus/deriv.lean

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,10 +1217,89 @@ funext $ λ x, deriv_pow
12171217

12181218
lemma deriv_within_pow (hxs : unique_diff_within_at 𝕜 s x) :
12191219
deriv_within (λx, x^n) s x = (n : 𝕜) * x^(n-1) :=
1220-
by rw [differentiable_at_pow.deriv_within hxs, deriv_pow]
1220+
(has_deriv_within_at_pow n x s).deriv_within hxs
1221+
1222+
lemma iter_deriv_pow' {k : ℕ} :
1223+
deriv^[k] (λx:𝕜, x^n) = λ x, ((finset.range k).prod (λ i, n - i):ℕ) * x^(n-k) :=
1224+
begin
1225+
induction k with k ihk,
1226+
{ simp only [one_mul, finset.prod_range_zero, nat.iterate_zero, nat.sub_zero, nat.cast_one] },
1227+
{ simp only [nat.iterate_succ', ihk, finset.prod_range_succ],
1228+
ext x,
1229+
rw [((has_deriv_at_pow (n - k) x).const_mul _).deriv, nat.cast_mul, mul_left_comm, mul_assoc,
1230+
nat.succ_eq_add_one, nat.sub_sub] }
1231+
end
1232+
1233+
lemma iter_deriv_pow {k : ℕ} :
1234+
deriv^[k] (λx:𝕜, x^n) x = ((finset.range k).prod (λ i, n - i):ℕ) * x^(n-k) :=
1235+
congr_fun iter_deriv_pow' x
12211236

12221237
end pow
12231238

1239+
section fpow
1240+
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
1241+
variables {x : 𝕜} {s : set 𝕜}
1242+
variable {m : ℤ}
1243+
1244+
lemma has_deriv_at_fpow (m : ℤ) (hx : x ≠ 0) :
1245+
has_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
1246+
begin
1247+
have : ∀ m : ℤ, 0 < m → has_deriv_at (λx, x^m) ((m:𝕜) * x^(m-1)) x,
1248+
{ assume m hm,
1249+
lift m to ℕ using (le_of_lt hm),
1250+
simp only [fpow_of_nat, int.cast_coe_nat],
1251+
convert has_deriv_at_pow _ _ using 2,
1252+
rw [← int.coe_nat_one, ← int.coe_nat_sub, fpow_of_nat],
1253+
norm_cast at hm,
1254+
exact nat.succ_le_of_lt hm },
1255+
rcases lt_trichotomy m 0 with hm|hm|hm,
1256+
{ have := (has_deriv_at_inv _).comp _ (this (-m) (neg_pos.2 hm));
1257+
[skip, exact fpow_ne_zero_of_ne_zero hx _],
1258+
simp only [(∘), fpow_neg, one_div_eq_inv, inv_inv', smul_eq_mul] at this,
1259+
convert this using 1,
1260+
rw [pow_two, mul_inv', inv_inv', int.cast_neg, ← neg_mul_eq_neg_mul, neg_mul_neg,
1261+
← fpow_add hx, mul_assoc, ← fpow_add hx], congr, abel },
1262+
{ simp only [hm, fpow_zero, int.cast_zero, zero_mul, has_deriv_at_const] },
1263+
{ exact this m hm }
1264+
end
1265+
1266+
theorem has_deriv_within_at_fpow (m : ℤ) (hx : x ≠ 0) (s : set 𝕜) :
1267+
has_deriv_within_at (λx, x^m) ((m : 𝕜) * x^(m-1)) s x :=
1268+
(has_deriv_at_fpow m hx).has_deriv_within_at
1269+
1270+
lemma differentiable_at_fpow (hx : x ≠ 0) : differentiable_at 𝕜 (λx, x^m) x :=
1271+
(has_deriv_at_fpow m hx).differentiable_at
1272+
1273+
lemma differentiable_within_at_fpow (hx : x ≠ 0) :
1274+
differentiable_within_at 𝕜 (λx, x^m) s x :=
1275+
(differentiable_at_fpow hx).differentiable_within_at
1276+
1277+
lemma differentiable_on_fpow (hs : (0:𝕜) ∉ s) : differentiable_on 𝕜 (λx, x^m) s :=
1278+
λ x hxs, differentiable_within_at_fpow (λ hx, hs $ hx ▸ hxs)
1279+
1280+
-- TODO : this is true at `x=0` as well
1281+
lemma deriv_fpow (hx : x ≠ 0) : deriv (λx, x^m) x = (m : 𝕜) * x^(m-1) :=
1282+
(has_deriv_at_fpow m hx).deriv
1283+
1284+
lemma deriv_within_fpow (hxs : unique_diff_within_at 𝕜 s x) (hx : x ≠ 0) :
1285+
deriv_within (λx, x^m) s x = (m : 𝕜) * x^(m-1) :=
1286+
(has_deriv_within_at_fpow m hx s).deriv_within hxs
1287+
1288+
lemma iter_deriv_fpow {k : ℕ} (hx : x ≠ 0) :
1289+
deriv^[k] (λx:𝕜, x^m) x = ((finset.range k).prod (λ i, m - i):ℤ) * x^(m-k) :=
1290+
begin
1291+
induction k with k ihk generalizing x hx,
1292+
{ simp only [one_mul, finset.prod_range_zero, nat.iterate_zero, int.coe_nat_zero, sub_zero,
1293+
int.cast_one] },
1294+
{ rw [nat.iterate_succ', finset.prod_range_succ, int.cast_mul, mul_assoc, mul_left_comm, int.coe_nat_succ,
1295+
← sub_sub, ← ((has_deriv_at_fpow _ hx).const_mul _).deriv],
1296+
apply deriv_congr_of_mem_nhds,
1297+
apply eventually.mono _ @ihk,
1298+
exact mem_nhds_sets (is_open_neg $ is_closed_eq continuous_id continuous_const) hx }
1299+
end
1300+
1301+
end fpow
1302+
12241303
/-! ### Upper estimates on liminf and limsup -/
12251304

12261305
section real
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/-
2+
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yury Kudryashov
5+
-/
6+
import analysis.calculus.mean_value data.nat.parity analysis.complex.exponential
7+
8+
/-!
9+
# Collection of convex functions
10+
11+
In this file we prove that the following functions are convex:
12+
13+
* `convex_on_exp` : the exponential function is convex on $(-∞, +∞)$;
14+
* `convex_on_pow_of_even` : given an even natural number $n$, the function $f(x)=x^n$
15+
is convex on $(-∞, +∞)$;
16+
* `convex_on_pow` : for a natural $n$, the function $f(x)=x^n$ is convex on $[0, +∞)$;
17+
* `convex_on_fpow` : for an integer $m$, the function $f(x)=x^m$ is convex on $(0, +∞)$.
18+
19+
## TODO
20+
21+
* `convex_on_rpow : ∀ r : ℝ, (r ≤ 0 ∨ 1 ≤ r) → convex_on (Ioi 0) (λ x, x ^ r)`
22+
-/
23+
24+
open real set
25+
26+
/-- `exp` is convex on the whole real line -/
27+
lemma convex_on_exp : convex_on univ exp :=
28+
convex_on_univ_of_deriv2_nonneg differentiable_exp
29+
(deriv_exp.symm ▸ differentiable_exp)
30+
(assume x, (iter_deriv_exp 2).symm ▸ le_of_lt (exp_pos x))
31+
32+
/-- `x^n`, `n : ℕ` is convex on the whole real line whenever `n` is even -/
33+
lemma convex_on_pow_of_even {n : ℕ} (hn : n.even) : convex_on set.univ (λ x, x^n) :=
34+
begin
35+
apply convex_on_univ_of_deriv2_nonneg differentiable_pow,
36+
{ simp only [deriv_pow', differentiable.mul, differentiable_const, differentiable_pow] },
37+
{ intro x,
38+
rcases hn.sub (nat.even_bit0 1) with ⟨k, hk⟩,
39+
simp only [iter_deriv_pow, finset.prod_range_succ, finset.prod_range_zero, nat.sub_zero,
40+
mul_one, hk, pow_mul', pow_two],
41+
exact mul_nonneg (nat.cast_nonneg _) (mul_self_nonneg _) }
42+
end
43+
44+
/-- `x^n`, `n : ℕ` is convex on `[0, +∞)` for all `n` -/
45+
lemma convex_on_pow (n : ℕ) : convex_on (Ici 0) (λ x, x^n) :=
46+
begin
47+
apply convex_on_of_deriv2_nonneg (convex_Ici _) (continuous_pow n).continuous_on;
48+
simp only [interior_Ici, differentiable_on_pow, deriv_pow',
49+
differentiable_on_const, differentiable_on.mul, iter_deriv_pow],
50+
intros x hx,
51+
exact mul_nonneg (nat.cast_nonneg _) (pow_nonneg (le_of_lt hx) _)
52+
end
53+
54+
lemma finset.prod_nonneg_of_card_nonpos_even
55+
{α β : Type*} [decidable_eq α] [linear_ordered_comm_ring β]
56+
{f : α → β} [decidable_pred (λ x, f x ≤ 0)]
57+
{s : finset α} (h0 : (s.filter (λ x, f x ≤ 0)).card.even) :
58+
0 ≤ s.prod f :=
59+
calc 0 ≤ s.prod (λ x, (if f x ≤ 0 then (-1:β) else 1) * f x) :
60+
finset.prod_nonneg (λ x _, by
61+
{ split_ifs with hx hx, by simp [hx], simp at hx ⊢, exact le_of_lt hx })
62+
... = _ : by rw [finset.prod_mul_distrib, finset.prod_ite _ _ (λx,x), finset.prod_const_one,
63+
mul_one, finset.prod_const, neg_one_pow_eq_pow_mod_two, nat.even_iff.1 h0, pow_zero, one_mul];
64+
-- TODO: why Lean fails to find this instance in `prod_ite`?
65+
apply_instance
66+
67+
lemma int_prod_range_nonneg (m : ℤ) (n : ℕ) (hn : n.even) :
68+
0 ≤ (finset.range n).prod (λ k, m - k) :=
69+
begin
70+
cases (le_or_lt ↑n m) with hnm hmn,
71+
{ exact finset.prod_nonneg (λ k hk, sub_nonneg.2 (le_trans
72+
(int.coe_nat_le.2 $ le_of_lt $ finset.mem_range.1 hk) hnm)) },
73+
cases le_or_lt 0 m with hm hm,
74+
{ lift m to ℕ using hm,
75+
exact le_of_eq (eq.symm $ finset.prod_eq_zero
76+
(finset.mem_range.2 $ int.coe_nat_lt.1 hmn) (sub_self _)) },
77+
clear hmn,
78+
apply finset.prod_nonneg_of_card_nonpos_even,
79+
convert hn,
80+
convert finset.card_range n,
81+
ext k,
82+
simp only [finset.mem_filter, finset.mem_range],
83+
refine ⟨and.left, λ hk, ⟨hk, sub_nonpos.2 $ le_trans (le_of_lt hm) _⟩⟩,
84+
exact int.coe_nat_nonneg k
85+
end
86+
87+
/-- `x^m`, `m : ℤ` is convex on `(0, +∞)` for all `m` -/
88+
lemma convex_on_fpow (m : ℤ) : convex_on (Ioi 0) (λ x, x^m) :=
89+
begin
90+
apply convex_on_of_deriv2_nonneg (convex_Ioi 0); try { rw [interior_Ioi] },
91+
{ exact (differentiable_on_fpow $ lt_irrefl _).continuous_on },
92+
{ exact differentiable_on_fpow (lt_irrefl _) },
93+
{ have : eq_on (deriv (λx:ℝ, x^m)) (λx, ↑m * x^(m-1)) (Ioi 0),
94+
from λ x hx, deriv_fpow (ne_of_gt hx),
95+
refine (differentiable_on_congr this).2 _,
96+
exact (differentiable_on_fpow (lt_irrefl _)).const_mul _ },
97+
{ intros x hx,
98+
simp only [iter_deriv_fpow (ne_of_gt hx)],
99+
refine mul_nonneg (int.cast_nonneg.2 _) (fpow_nonneg_of_nonneg (le_of_lt hx) _),
100+
exact int_prod_range_nonneg _ _ (nat.even_bit0 1) }
101+
end

src/analysis/mean_inequalities.lean

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/-
2+
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Yury Kudryashov
5+
-/
6+
import analysis.calculus.mean_value data.nat.parity analysis.complex.exponential
7+
analysis.convex.specific_functions
8+
9+
/-!
10+
# Mean value inequalities
11+
12+
In this file we prove various inequalities between mean values:
13+
arithmetic mean, geometric mean, generalized mean (natural and integer
14+
cases).
15+
16+
For generalized means we only prove
17+
$\left( ∑_j w_j z_j \right)^n ≤ ∑_j w_j z_j^n$ because standard versions would
18+
require $\sqrt[n]{x}$ which is not implemented in `mathlib` yet.
19+
20+
Probably a better approach to the generalized means inequality is to
21+
prove `convex_on_rpow` in `analysis/convex/specific_functions` first,
22+
then apply it.
23+
24+
It is not yet clear which versions will be useful in the future, so we
25+
provide two different forms of most inequalities : for `ℝ` and for
26+
`ℝ≥0`. For the AM-GM inequality we also prove special cases for `n=2`
27+
and `n=3`.
28+
-/
29+
30+
universes u v
31+
32+
open real finset
33+
open_locale classical nnreal
34+
35+
variables {ι : Type u} (s : finset ι)
36+
37+
/-- Geometric mean is less than or equal to the arithmetic mean, weighted version
38+
for functions on `finset`s. -/
39+
theorem real.am_gm_weighted (w z : ι → ℝ)
40+
(hw : ∀ i ∈ s, 0 ≤ w i) (hw' : s.sum w = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
41+
s.prod (λ i, (z i) ^ (w i)) ≤ s.sum (λ i, w i * z i) :=
42+
begin
43+
let s' := s.filter (λ i, w i ≠ 0),
44+
rw [← sum_filter_ne_zero] at hw',
45+
suffices : s'.prod (λ i, (z i) ^ (w i)) ≤ s'.sum (λ i, w i * z i),
46+
{ have A : ∀ i ∈ s, i ∉ s' → w i = 0,
47+
{ intros i hi hi',
48+
simpa only [hi, mem_filter, ne.def, true_and, not_not] using hi' },
49+
have B : ∀ i ∈ s, i ∉ s' → (z i) ^ (w i) = 1,
50+
from λ i hi hi', by rw [A i hi hi', rpow_zero],
51+
have C : ∀ i ∈ s, i ∉ s' → w i * z i = 0,
52+
from λ i hi hi', by rw [A i hi hi', zero_mul],
53+
rwa [← prod_subset s.filter_subset B, ← sum_subset s.filter_subset C] },
54+
have A : ∀ i ∈ s', i ∈ s ∧ w i ≠ 0, from λ i hi, mem_filter.1 hi,
55+
replace hz : ∀ i ∈ s', 0 ≤ z i := λ i hi, hz i (A i hi).1,
56+
replace hw : ∀ i ∈ s', 0 ≤ w i := λ i hi, hw i (A i hi).1,
57+
by_cases B : ∃ i ∈ s', z i = 0,
58+
{ rcases B with ⟨i, imem, hzi⟩,
59+
rw [prod_eq_zero imem],
60+
{ exact sum_nonneg (λ j hj, mul_nonneg (hw j hj) (hz j hj)) },
61+
{ rw hzi, exact zero_rpow (A i imem).2 } },
62+
{ replace hz : ∀ i ∈ s', 0 < z i,
63+
from λ i hi, lt_of_le_of_ne (hz _ hi) (λ h, B ⟨i, hi, h.symm⟩),
64+
have := convex_on_exp.map_sum_le hw hw' (λ i _, set.mem_univ $ log (z i)),
65+
simp only [exp_sum, (∘), smul_eq_mul, mul_comm (w _) (log _)] at this,
66+
convert this using 1,
67+
{ exact prod_congr rfl (λ i hi, rpow_def_of_pos (hz i hi) _) },
68+
{ exact sum_congr rfl (λ i hi, congr_arg _ (exp_log $ hz i hi).symm) } }
69+
end
70+
71+
theorem nnreal.am_gm_weighted (w z : ι → ℝ≥0) (hw' : s.sum w = 1) :
72+
s.prod (λ i, (z i:ℝ) ^ (w i:ℝ)) ≤ s.sum (λ i, w i * z i) :=
73+
begin
74+
refine real.am_gm_weighted _ _ _ (λ i _, (w i).coe_nonneg) _ (λ i _, (z i).coe_nonneg),
75+
assumption_mod_cast
76+
end
77+
78+
theorem nnreal.am_gm2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) (hw : w₁ + w₂ = 1) :
79+
(p₁:ℝ) ^ (w₁:ℝ) * p₂ ^ (w₂:ℝ) ≤ w₁ * p₁ + w₂ * p₂ :=
80+
begin
81+
have := nnreal.am_gm_weighted (univ : finset (fin 2)) (fin.cons w₁ $ fin.cons w₂ fin_zero_elim)
82+
(fin.cons p₁ $ fin.cons p₂ $ fin_zero_elim),
83+
simp only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
84+
fin.cons_succ, fin.cons_zero, add_zero, mul_one] at this,
85+
exact this hw
86+
end
87+
88+
theorem real.am_gm2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)
89+
(hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) :
90+
p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ :=
91+
nnreal.am_gm2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ $ nnreal.coe_eq.1 $ by assumption
92+
93+
theorem nnreal.am_gm3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) (hw : w₁ + w₂ + w₃ = 1) :
94+
(p₁:ℝ) ^ (w₁:ℝ) * p₂ ^ (w₂:ℝ) * p₃ ^ (w₃:ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃:=
95+
begin
96+
have := nnreal.am_gm_weighted (univ : finset (fin 3))
97+
(fin.cons w₁ $ fin.cons w₂ $ fin.cons w₃ fin_zero_elim)
98+
(fin.cons p₁ $ fin.cons p₂ $ fin.cons p₃ fin_zero_elim),
99+
simp only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero,
100+
fin.cons_succ, fin.cons_zero, add_zero, mul_one, (add_assoc _ _ _).symm,
101+
(mul_assoc _ _ _).symm] at this,
102+
exact this hw
103+
end
104+
105+
/-- Young's inequality, `ℝ≥0` version -/
106+
theorem nnreal.young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hp : 1 < p) (hq : 1 < q)
107+
(hpq : 1/p + 1/q = 1) :
108+
(a * b:ℝ) ≤ (a:ℝ)^(p:ℝ) / p + (b:ℝ)^(q:ℝ) / q :=
109+
begin
110+
have := nnreal.am_gm2_weighted (1/p) (1/q) ⟨(a:ℝ)^(p:ℝ), rpow_nonneg_of_nonneg a.coe_nonneg _⟩
111+
⟨(b:ℝ)^(q:ℝ), rpow_nonneg_of_nonneg b.coe_nonneg _⟩ hpq,
112+
simp only [nnreal.coe_mk, nnreal.coe_div, nnreal.coe_one, one_div_eq_inv,
113+
(rpow_mul (nnreal.coe_nonneg _) _ _).symm, div_eq_inv_mul.symm] at this,
114+
rwa [mul_inv_cancel, mul_inv_cancel, rpow_one, rpow_one] at this;
115+
refine ne_of_gt (lt_trans zero_lt_one _); assumption
116+
end
117+
118+
/-- Young's inequality, `ℝ` version -/
119+
theorem real.young_inequality {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b)
120+
{p q : ℝ} (hp : 1 < p) (hq : 1 < q) (hpq : 1/p + 1/q = 1) :
121+
a * b ≤ a^p / p + b^q / q :=
122+
@nnreal.young_inequality ⟨a, ha⟩ ⟨b, hb⟩ ⟨p, le_trans zero_le_one (le_of_lt hp)⟩
123+
⟨q, le_trans zero_le_one (le_of_lt hq)⟩ hp hq (nnreal.coe_eq.1 hpq)
124+
125+
theorem real.pow_am_le_am_pow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
126+
(hw' : s.sum w = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (n : ℕ) :
127+
(s.sum (λ i, w i * z i)) ^ n ≤ s.sum (λ i, w i * z i ^ n) :=
128+
(convex_on_pow n).map_sum_le hw hw' hz
129+
130+
theorem nnreal.pow_am_le_am_pow (w z : ι → ℝ≥0) (hw' : s.sum w = 1) (n : ℕ) :
131+
(s.sum (λ i, w i * z i)) ^ n ≤ s.sum (λ i, w i * z i ^ n) :=
132+
begin
133+
rw [← nnreal.coe_le],
134+
push_cast,
135+
refine (convex_on_pow n).map_sum_le (λ i _, (w i).coe_nonneg) _ (λ i _, (z i).coe_nonneg),
136+
assumption_mod_cast
137+
end
138+
139+
theorem real.pow_am_le_am_pow_of_even (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
140+
(hw' : s.sum w = 1) {n : ℕ} (hn : n.even) :
141+
(s.sum (λ i, w i * z i)) ^ n ≤ s.sum (λ i, w i * z i ^ n) :=
142+
(convex_on_pow_of_even hn).map_sum_le hw hw' (λ _ _, trivial)
143+
144+
theorem real.fpow_am_le_am_fpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
145+
(hw' : s.sum w = 1) (hz : ∀ i ∈ s, 0 < z i) (m : ℤ) :
146+
(s.sum (λ i, w i * z i)) ^ m ≤ s.sum (λ i, w i * z i ^ m) :=
147+
(convex_on_fpow m).map_sum_le hw hw' hz

src/data/nat/parity.lean

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ by cases mod_two_eq_zero_or_one n with h h; simp [h]
1515
@[simp] theorem mod_two_ne_zero {n : nat} : ¬ n % 2 = 0 ↔ n % 2 = 1 :=
1616
by cases mod_two_eq_zero_or_one n with h h; simp [h]
1717

18+
/-- A natural number `n` is `even` if `2 | n`. -/
1819
def even (n : nat) : Prop := 2 ∣ n
1920

2021
theorem even_iff {n : nat} : even n ↔ n % 2 = 0 :=
@@ -46,6 +47,9 @@ begin
4647
exact @modeq.modeq_add _ _ 1 _ 1 h₁ h₂
4748
end
4849

50+
theorem even.add {m n : ℕ} (hm : m.even) (hn : n.even) : (m + n).even :=
51+
even_add.2 $ by simp only [*]
52+
4953
@[simp] theorem not_even_bit1 (n : nat) : ¬ even (bit1 n) :=
5054
by simp [bit1] with parity_simps
5155

@@ -55,6 +59,11 @@ begin
5559
by_cases h : even n; simp [h]
5660
end
5761

62+
theorem even.sub {m n : ℕ} (hm : m.even) (hn : n.even) : (m - n).even :=
63+
(le_total n m).elim
64+
(λ h, by simp only [even_sub h, *])
65+
(λ h, by simp only [sub_eq_zero_of_le h, even_zero])
66+
5867
@[parity_simps] theorem even_succ {n : nat} : even (succ n) ↔ ¬ even n :=
5968
by rw [succ_eq_add_one, even_add]; simp [not_even_one]
6069

src/data/real/nnreal.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lemma le_coe_of_real (r : ℝ) : r ≤ nnreal.of_real r :=
3838
le_max_left r 0
3939

4040
lemma coe_nonneg (r : nnreal) : (0 : ℝ) ≤ r := r.2
41+
@[elim_cast, simp] theorem coe_mk (a : ℝ) (ha) : ((⟨a, ha⟩ : ℝ≥0) : ℝ) = a := rfl
4142

4243
instance : has_zero ℝ≥0 := ⟨⟨0, le_refl 0⟩⟩
4344
instance : has_one ℝ≥0 := ⟨⟨1, zero_le_one⟩⟩

src/data/set/intervals/basic.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ end partial_order
318318
section linear_order
319319
variables {α : Type u} [linear_order α] {a a₁ a₂ b b₁ b₂ : α}
320320

321+
lemma compl_Iic : -(Iic a) = Ioi a := ext $ λ _, not_le
322+
lemma compl_Ici : -(Ici a) = Iio a := ext $ λ _, not_le
323+
lemma compl_Iio : -(Iio a) = Ici a := ext $ λ _, not_lt
324+
lemma compl_Ioi : -(Ioi a) = Iic a := ext $ λ _, not_lt
325+
321326
lemma Ioo_eq_empty_iff [densely_ordered α] : Ioo a b = ∅ ↔ b ≤ a :=
322327
⟨λ eq, le_of_not_lt $ λ h,
323328
let ⟨x, h₁, h₂⟩ := dense h in

0 commit comments

Comments
 (0)