@@ -7,6 +7,8 @@ import data.set.intervals.ord_connected
7
7
import data.set.intervals.image_preimage
8
8
import data.complex.module
9
9
import linear_algebra.affine_space.basic
10
+ import algebra.module.ordered
11
+
10
12
11
13
/-!
12
14
# Convex sets and functions on real vector spaces
@@ -15,10 +17,10 @@ In a real vector space, we define the following objects and properties.
15
17
16
18
* `segment x y` is the closed segment joining `x` and `y`.
17
19
* A set `s` is `convex` if for any two points `x y ∈ s` it includes `segment x y`;
18
- * A function `f` is `convex_on` a set `s` if `s` is itself a convex set, and for any two points
19
- `x y ∈ s` the segment joining `(x, f x)` to `(y, f y)` is (non-strictly) above the graph of `f`;
20
- equivalently, `convex_on f s` means that the epigraph `{p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2}`
21
- is a convex set;
20
+ * A function `f : E → β ` is `convex_on` a set `s` if `s` is itself a convex set, and for any two
21
+ points `x y ∈ s` the segment joining `(x, f x)` to `(y, f y)` is (non-strictly) above the graph
22
+ of `f`; equivalently, `convex_on f s` means that the epigraph
23
+ `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set;
22
24
* Center mass of a finite set of points with prescribed weights.
23
25
* Convex hull of a set `s` is the minimal convex set that includes `s`.
24
26
* Standard simplex `std_simplex ι [fintype ι]` is the intersection of the positive quadrant with
@@ -27,6 +29,9 @@ In a real vector space, we define the following objects and properties.
27
29
We also provide various equivalent versions of the definitions above, prove that some specific sets
28
30
are convex, and prove Jensen's inequality.
29
31
32
+ Note: To define convexity for functions `f : E → β`, we need `β` to be an ordered vector space,
33
+ defined using the instance `ordered_semimodule ℝ β`.
34
+
30
35
## Notations
31
36
32
37
We use the following local notations:
@@ -462,26 +467,28 @@ end sets
462
467
463
468
section functions
464
469
470
+ variables {β : Type *} [ordered_add_comm_monoid β] [ordered_semimodule ℝ β]
471
+
465
472
local notation `[`x `, ` y `]` := segment x y
466
473
467
474
/-! ### Convex functions -/
468
475
469
476
/-- Convexity of functions -/
470
- def convex_on (s : set E) (f : E → ℝ ) : Prop :=
477
+ def convex_on (s : set E) (f : E → β ) : Prop :=
471
478
convex s ∧
472
479
∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → a + b = 1 →
473
- f (a • x + b • y) ≤ a * f x + b * f y
480
+ f (a • x + b • y) ≤ a • f x + b • f y
474
481
475
482
lemma convex_on_id {s : set ℝ} (hs : convex s) : convex_on s id := ⟨hs, by { intros, refl }⟩
476
483
477
- lemma convex_on_const (c : ℝ ) (hs : convex s) : convex_on s (λ x:E, c) :=
478
- ⟨hs, by { intros, simp only [← add_mul , *, one_mul ] }⟩
484
+ lemma convex_on_const (c : β ) (hs : convex s) : convex_on s (λ x:E, c) :=
485
+ ⟨hs, by { intros, simp only [← add_smul , *, one_smul ] }⟩
479
486
480
- variables {t : set E} {f g : E → ℝ}
487
+ variables {t : set E}
481
488
482
- lemma convex_on_iff_div :
489
+ lemma convex_on_iff_div {f : E → β} :
483
490
convex_on s f ↔ convex s ∧ ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → ∀ ⦃a b : ℝ⦄, 0 ≤ a → 0 ≤ b → 0 < a + b →
484
- f ((a/(a+b)) • x + (b/(a+b)) • y) ≤ (a/(a+b)) * f x + (b/(a+b)) * f y :=
491
+ f ((a/(a+b)) • x + (b/(a+b)) • y) ≤ (a/(a+b)) • f x + (b/(a+b)) • f y :=
485
492
and_congr iff.rfl
486
493
⟨begin
487
494
intros h x y hx hy a b ha hb hab,
@@ -495,19 +502,19 @@ begin
495
502
end ⟩
496
503
497
504
/-- For a function on a convex set in a linear ordered space, in order to prove that it is convex
498
- it suffices to verify the inequality `f (a • x + b • y) ≤ a * f x + b * f y` only for `x < y`
505
+ it suffices to verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y`
499
506
and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with
500
507
lexicographic order. -/
501
- lemma linear_order.convex_on_of_lt [linear_order E] (hs : convex s)
508
+ lemma linear_order.convex_on_of_lt {f : E → β} [linear_order E] (hs : convex s)
502
509
(hf : ∀ ⦃x y : E⦄, x ∈ s → y ∈ s → x < y → ∀ ⦃a b : ℝ⦄, 0 < a → 0 < b → a + b = 1 →
503
- f (a • x + b • y) ≤ a * f x + b * f y) : convex_on s f :=
510
+ f (a • x + b • y) ≤ a • f x + b • f y) : convex_on s f :=
504
511
begin
505
512
use hs,
506
513
intros x y hx hy a b ha hb hab,
507
514
wlog hxy : x<=y using [x y a b, y x b a],
508
515
{ exact le_total _ _ },
509
516
{ cases eq_or_lt_of_le hxy with hxy hxy,
510
- by { subst y, rw [← add_smul, ← add_mul , hab, one_smul, one_mul ] },
517
+ by { subst y, rw [← add_smul, ← add_smul , hab, one_smul, one_smul ] },
511
518
cases eq_or_lt_of_le ha with ha ha,
512
519
by { subst a, rw [zero_add] at hab, subst b, simp },
513
520
cases eq_or_lt_of_le hb with hb hb,
@@ -544,36 +551,42 @@ begin
544
551
convert this ; symmetry; simp only [div_eq_iff (ne_of_gt B), y]; ring
545
552
end
546
553
547
- lemma convex_on.subset (h_convex_on : convex_on t f) (h_subset : s ⊆ t) (h_convex : convex s) :
548
- convex_on s f :=
554
+ lemma convex_on.subset {f : E → β} (h_convex_on : convex_on t f)
555
+ (h_subset : s ⊆ t) (h_convex : convex s) : convex_on s f :=
549
556
begin
550
557
apply and.intro h_convex,
551
558
intros x y hx hy,
552
559
exact h_convex_on.2 (h_subset hx) (h_subset hy),
553
560
end
554
561
555
- lemma convex_on.add (hf : convex_on s f) (hg : convex_on s g) : convex_on s (λx, f x + g x) :=
562
+ lemma convex_on.add {f g : E → β} (hf : convex_on s f) (hg : convex_on s g) :
563
+ convex_on s (λx, f x + g x) :=
556
564
begin
557
565
apply and.intro hf.1 ,
558
566
intros x y hx hy a b ha hb hab,
559
567
calc
560
- f (a • x + b • y) + g (a • x + b • y) ≤ (a * f x + b * f y) + (a * g x + b * g y)
568
+ f (a • x + b • y) + g (a • x + b • y) ≤ (a • f x + b • f y) + (a • g x + b • g y)
561
569
: add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
562
- ... = a * f x + a * g x + b * f y + b * g y : by linarith
563
- ... = a * (f x + g x) + b * (f y + g y) : by simp [mul_add , add_assoc]
570
+ ... = a • f x + a • g x + b • f y + b • g y : by abel
571
+ ... = a • (f x + g x) + b • (f y + g y) : by simp [smul_add , add_assoc]
564
572
end
565
573
566
- lemma convex_on.smul {c : ℝ} (hc : 0 ≤ c) (hf : convex_on s f) : convex_on s (λx, c * f x) :=
574
+ lemma convex_on.smul {f : E → β} {c : ℝ} (hc : 0 ≤ c) (hf : convex_on s f) :
575
+ convex_on s (λx, c • f x) :=
567
576
begin
568
577
apply and.intro hf.1 ,
569
578
intros x y hx hy a b ha hb hab,
570
579
calc
571
- c * f (a • x + b • y) ≤ c * (a * f x + b * f y)
572
- : mul_le_mul_of_nonneg_left (hf.2 hx hy ha hb hab) hc
573
- ... = a * (c * f x) + b * (c * f y) : by rw mul_add; ac_refl
580
+ c • f (a • x + b • y) ≤ c • (a • f x + b • f y)
581
+ : smul_le_smul_of_nonneg (hf.2 hx hy ha hb hab) hc
582
+ ... = a • (c • f x) + b • (c • f y) : by simp only [smul_add, smul_comm]
574
583
end
575
584
576
- lemma convex_on.le_on_segment' {x y : E} {a b : ℝ}
585
+ /--
586
+ A convex function on a segment is upper-bounded by the max of its endpoints.
587
+ Note: This cannot be generalized to E → β because it needs a linear order.
588
+ -/
589
+ lemma convex_on.le_on_segment' {f : E → ℝ} {x y : E} {a b : ℝ}
577
590
(hf : convex_on s f) (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1 ) :
578
591
f (a • x + b • y) ≤ max (f x) (f y) :=
579
592
calc
@@ -582,32 +595,66 @@ calc
582
595
add_le_add (mul_le_mul_of_nonneg_left (le_max_left _ _) ha) (mul_le_mul_of_nonneg_left (le_max_right _ _) hb)
583
596
... ≤ max (f x) (f y) : by rw [←add_mul, hab, one_mul]
584
597
585
- lemma convex_on.le_on_segment (hf : convex_on s f) {x y z : E}
598
+ /--
599
+ A convex function on a segment is upper-bounded by the max of its endpoints.
600
+ Note: This cannot be generalized to E → β because it needs a linear order.
601
+ -/
602
+ lemma convex_on.le_on_segment {f : E → ℝ} (hf : convex_on s f) {x y z : E}
586
603
(hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x, y]) :
587
604
f z ≤ max (f x) (f y) :=
588
605
let ⟨a, b, ha, hb, hab, hz⟩ := hz in hz ▸ hf.le_on_segment' hx hy ha hb hab
589
606
590
- lemma convex_on.convex_le (hf : convex_on s f) (r : ℝ ) : convex {x ∈ s | f x ≤ r} :=
607
+ lemma convex_on.convex_le {f : E → β} (hf : convex_on s f) (r : β ) : convex {x ∈ s | f x ≤ r} :=
591
608
convex_iff_segment_subset.2 $ λ x y hx hy z hz,
592
- ⟨hf.1 .segment_subset hx.1 hy.1 hz,
593
- le_trans (hf.le_on_segment hx.1 hy.1 hz) $ max_le hx.2 hy.2 ⟩
609
+ begin
610
+ refine ⟨hf.1 .segment_subset hx.1 hy.1 hz,_⟩,
611
+ rcases hz with ⟨za,zb,hza,hzb,hzazb,H⟩,
612
+ rw ←H,
613
+ calc
614
+ f (za • x + zb • y) ≤ za • (f x) + zb • (f y) : hf.2 hx.1 hy.1 hza hzb hzazb
615
+ ... ≤ za • r + zb • r
616
+ : add_le_add (smul_le_smul_of_nonneg hx.2 hza)
617
+ (smul_le_smul_of_nonneg hy.2 hzb)
618
+ ... ≤ r : by simp [←add_smul, hzazb]
619
+ end
594
620
595
- lemma convex_on.convex_lt (hf : convex_on s f) (r : ℝ) : convex {x ∈ s | f x < r} :=
596
- convex_iff_segment_subset.2 $ λ x y hx hy z hz,
597
- ⟨hf.1 .segment_subset hx.1 hy.1 hz,
598
- lt_of_le_of_lt (hf.le_on_segment hx.1 hy.1 hz) $ max_lt hx.2 hy.2 ⟩
621
+ lemma convex_on.convex_lt {γ : Type *} [ordered_cancel_add_comm_monoid γ] [ordered_semimodule ℝ γ]
622
+ {f : E → γ} (hf : convex_on s f) (r : γ) : convex {x ∈ s | f x < r} :=
623
+ begin
624
+ intros a b as bs xa xb hxa hxb hxaxb,
625
+ refine ⟨hf.1 as.1 bs.1 hxa hxb hxaxb,_⟩,
626
+ dsimp,
627
+ by_cases H : xa = 0 ,
628
+ { have H' : xb = 1 := by rwa [H, zero_add] at hxaxb,
629
+ rw [H, H', zero_smul, one_smul, zero_add],
630
+ exact bs.2 },
631
+ { calc
632
+ f (xa • a + xb • b) ≤ xa • (f a) + xb • (f b) : hf.2 as.1 bs.1 hxa hxb hxaxb
633
+ ... < xa • r + xb • (f b)
634
+ : (add_lt_add_iff_right (xb • (f b))).mpr
635
+ (smul_lt_smul_of_pos as.2
636
+ (lt_of_le_of_ne hxa (ne.symm H)))
637
+ ... ≤ xa • r + xb • r
638
+ : (add_le_add_iff_left (xa • r)).mpr
639
+ (smul_le_smul_of_nonneg (le_of_lt bs.2 ) hxb)
640
+ ... = r
641
+ : by simp only [←add_smul, hxaxb, one_smul] }
642
+ end
599
643
600
- lemma convex_on.convex_epigraph (hf : convex_on s f) :
601
- convex {p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
644
+ lemma convex_on.convex_epigraph {γ : Type *} [ordered_add_comm_group γ] [ordered_semimodule ℝ γ]
645
+ {f : E → γ} (hf : convex_on s f) :
646
+ convex {p : E × γ | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
602
647
begin
603
648
rintros ⟨x, r⟩ ⟨y, t⟩ ⟨hx, hr⟩ ⟨hy, ht⟩ a b ha hb hab,
604
649
refine ⟨hf.1 hx hy ha hb hab, _⟩,
605
- calc f (a • x + b • y) ≤ a * f x + b * f y : hf.2 hx hy ha hb hab
606
- ... ≤ a * r + b * t : add_le_add (mul_le_mul_of_nonneg_left hr ha)
607
- (mul_le_mul_of_nonneg_left ht hb)
650
+ calc f (a • x + b • y) ≤ a • f x + b • f y : hf.2 hx hy ha hb hab
651
+ ... ≤ a • r + b • t : add_le_add (smul_le_smul_of_nonneg hr ha)
652
+ (smul_le_smul_of_nonneg ht hb)
608
653
end
609
654
610
- lemma convex_on_iff_convex_epigraph : convex_on s f ↔ convex {p : E × ℝ | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
655
+ lemma convex_on_iff_convex_epigraph {γ : Type *} [ordered_add_comm_group γ] [ordered_semimodule ℝ γ]
656
+ {f : E → γ} :
657
+ convex_on s f ↔ convex {p : E × γ | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
611
658
begin
612
659
refine ⟨convex_on.convex_epigraph, λ h, ⟨_, _⟩⟩,
613
660
{ assume x y hx hy a b ha hb hab,
@@ -617,30 +664,30 @@ begin
617
664
end
618
665
619
666
/-- If a function is convex on s, it remains convex when precomposed by an affine map -/
620
- lemma convex_on.comp_affine_map {f : F → ℝ } (g : affine_map ℝ E F) {s : set F}
667
+ lemma convex_on.comp_affine_map {f : F → β } (g : affine_map ℝ E F) {s : set F}
621
668
(hf : convex_on s f) : convex_on (g ⁻¹' s) (f ∘ g) :=
622
669
begin
623
670
refine ⟨hf.1 .affine_preimage _,_⟩,
624
671
intros x y xs ys a b ha hb hab,
625
672
calc
626
673
(f ∘ g) (a • x + b • y) = f (g (a • x + b • y)) : rfl
627
674
... = f (a • (g x) + b • (g y)) : by rw [convex.combo_affine_apply hab]
628
- ... ≤ a * f (g x) + b * f (g y) : hf.2 xs ys ha hb hab
629
- ... = a * (f ∘ g) x + b * (f ∘ g) y : rfl
675
+ ... ≤ a • f (g x) + b • f (g y) : hf.2 xs ys ha hb hab
676
+ ... = a • (f ∘ g) x + b • (f ∘ g) y : rfl
630
677
end
631
678
632
679
/-- If g is convex on s, so is (g ∘ f) on f ⁻¹' s for a linear f. -/
633
- lemma convex_on.comp_linear_map {g : F → ℝ } {s : set F} (hg : convex_on s g) (f : E →ₗ[ℝ] F) :
680
+ lemma convex_on.comp_linear_map {g : F → β } {s : set F} (hg : convex_on s g) (f : E →ₗ[ℝ] F) :
634
681
convex_on (f ⁻¹' s) (g ∘ f) :=
635
682
hg.comp_affine_map f.to_affine_map
636
683
637
684
/-- If a function is convex on s, it remains convex after a translation. -/
638
- lemma convex_on.translate_right {f : E → ℝ } {s : set E} {a : E} (hf : convex_on s f) :
685
+ lemma convex_on.translate_right {f : E → β } {s : set E} {a : E} (hf : convex_on s f) :
639
686
convex_on ((λ z, a + z) ⁻¹' s) (f ∘ (λ z, a + z)) :=
640
687
hf.comp_affine_map $ affine_map.const ℝ E a +ᵥ affine_map.id ℝ E
641
688
642
689
/-- If a function is convex on s, it remains convex after a translation. -/
643
- lemma convex_on.translate_left {f : E → ℝ } {s : set E} {a : E} (hf : convex_on s f) :
690
+ lemma convex_on.translate_left {f : E → β } {s : set E} {a : E} (hf : convex_on s f) :
644
691
convex_on ((λ z, a + z) ⁻¹' s) (f ∘ (λ z, z + a)) :=
645
692
by simpa only [add_comm] using hf.translate_right
646
693
0 commit comments