Require Import Qreals.
Require Import Program.Basics.
Require Import Classical.
Require Import QArith Coq.Reals.Rbase Coq.Reals.RList.
Require Import Coq.Reals.Rfunctions.
Require Import Coq.Reals.Rprod Coq.Reals.ROrderedType.
Require Import Ranalysis_reg utils.Finite.
Require Import Coquelicot.Coquelicot.
Require Import Lia Lra.
Require Import Reals.Integration.
Require Import Coq.Reals.SeqProp.
Require Import Rtrigo_def.
Require Import List.
Require Finite.
Require Import Morphisms Permutation.
Require Import EquivDec.
Require Import PushNeg.
Require Import LibUtils ListAdd.
Require Import Relation_Definitions Sorted.
Require Import Isomorphism NumberIso.
Set Bullet Behavior "
Strict Subproofs".
Import ListNotations.
Local Open Scope R.
Global Instance EqDecR :
EqDec R eq :=
Req_EM_T.
Global Instance Rle_pre :
PreOrder Rle.
Proof.
Local Instance Rge_pre :
PreOrder Rge.
Proof.
Global Instance Rle_part :
PartialOrder eq Rle.
Proof.
split;
intros;
repeat red;
unfold flip.
-
subst.
split;
reflexivity.
-
destruct H.
apply Rle_antisym;
trivial.
Qed.
Local Instance Rge_part :
PartialOrder eq Rge.
Proof.
split;
intros;
repeat red;
unfold flip.
-
subst.
split;
reflexivity.
-
destruct H.
apply Rge_antisym;
trivial.
Qed.
Global Instance Rlt_strict :
StrictOrder Rlt.
Proof.
Global Instance Rgt_strict :
StrictOrder Rgt.
Proof.
Global Instance Rlt_le_subr :
subrelation Rlt Rle.
Proof.
intros ???.
now apply Rlt_le.
Qed.
Global Instance Rgt_ge_subr :
subrelation Rgt Rge.
Proof.
intros ???.
now apply Rgt_ge.
Qed.
Local Instance Rbar_le_pre :
PreOrder Rbar_le.
Proof.
Local Instance Rbar_le_part :
PartialOrder eq Rbar_le.
Proof.
split;
intros;
repeat red;
unfold flip.
-
subst.
split;
reflexivity.
-
destruct H.
apply Rbar_le_antisym;
trivial.
Qed.
Local Instance Rbar_lt_strict :
StrictOrder Rbar_lt.
Proof.
constructor.
-
intros ?.
red.
destruct x;
simpl;
trivial.
apply Rlt_irrefl.
-
intros ???.
apply Rbar_lt_trans.
Qed.
Local Instance Rbar_lt_le_subr :
subrelation Rbar_lt Rbar_le.
Proof.
Global Instance Rbar_eqdec :
EqDec Rbar eq :=
Rbar_eq_dec.
Lemma rbar_nneg_nneg x :
Rbar_le 0
x ->
0 <=
x.
Proof.
destruct x; simpl; try lra.
Qed.
Lemma INR_nzero {
n} :
(
n > 0)%
nat ->
INR n <> 0.
Proof.
destruct n.
-
lia.
-
rewrite S_INR.
generalize (
pos_INR n);
intros.
lra.
Qed.
Lemma INR_nzero_eq {
n} :
(~
n = 0)%
nat ->
INR n <> 0.
Proof.
destruct n.
-
lia.
-
rewrite S_INR.
generalize (
pos_INR n);
intros.
lra.
Qed.
Lemma INR_zero_lt {
n} :
(
n > 0)%
nat -> 0 <
INR n.
Proof.
destruct n.
-
lia.
-
rewrite S_INR.
generalize (
pos_INR n);
intros.
lra.
Qed.
Lemma Rinv_pos n :
0 <
n ->
0 < /
n.
Proof.
Lemma pos_Rl_nth (
l:
list R)
n :
pos_Rl l n =
nth n l 0.
Proof.
revert n.
induction l; destruct n; simpl in *; trivial.
Qed.
Hint Rewrite pos_Rl_nth :
R_iso.
Lemma Rlt_le_sub :
subrelation Rlt Rle.
Proof.
repeat red; intuition.
Qed.
Lemma find_bucket_nth_finds_Rle needle l idx d1 d2:
StronglySorted Rle l ->
(
S idx <
length l)%
nat ->
nth idx l d1 <
needle ->
needle <=
nth (
S idx)
l d2 ->
find_bucket Rle_dec needle l =
Some (
nth idx l d1,
nth (
S idx)
l d2).
Proof.
Lemma find_bucket_bounded_Rle_exists {
a b needle} :
a <=
needle <=
b ->
forall l,
exists lower upper,
find_bucket Rle_dec needle (
a::
l++[
b]) =
Some (
lower,
upper).
Proof.
Lemma telescope_plus_fold_right_sub_seq f s n :
fold_right Rplus 0 (
map (
fun x => (
f (
INR x)) - (
f (
INR (
x+1)))) (
seq s n)) = (
f (
INR s)) - (
f (
INR (
s+
n))).
Proof.
Opaque INR.
revert s.
induction n;
simpl;
intros s.
-
replace (
s+0)%
nat with s by lia.
lra.
-
specialize (
IHn (
S s)).
unfold Rminus in *.
rewrite Rplus_assoc in *.
f_equal.
simpl in IHn.
replace (
S (
s +
n))%
nat with (
s + (
S n))%
nat in IHn by lia.
rewrite IHn.
replace (
s+1)%
nat with (
S s)
by lia.
lra.
Transparent INR.
Qed.
Lemma fold_right_Rplus_mult_const {
A:
Type} (
f:
A->
R)
c l :
fold_right Rplus 0 (
map (
fun x :
A =>
f x *
c)
l) =
(
fold_right Rplus 0 (
map (
fun x :
A =>
f x)
l))*
c.
Proof.
induction l; simpl; lra.
Qed.
Lemma bounded_dist_le x lower upper :
lower <=
x <=
upper ->
R_dist x upper <=
R_dist lower upper.
Proof.
Lemma bounded_dist_le_P2 x lower upper :
lower <=
x <=
upper ->
R_dist x lower <=
R_dist upper lower.
Proof.
Definition interval_increasing f (
a b:
R) :
Prop :=
forall x y :
R,
a <=
x ->
y <=
b ->
x<=
y ->
f x <=
f y.
Definition interval_decreasing f (
a b:
R) :
Prop :=
forall x y :
R,
a <=
x ->
y <=
b ->
x<=
y ->
f y <=
f x.
Lemma bounded_increasing_dist_le (
f :
R ->
R)
x lower upper :
interval_increasing f lower upper ->
lower <=
x <=
upper ->
R_dist (
f x) (
f upper) <=
R_dist (
f lower) (
f upper).
Proof.
Lemma bounded_decreasing_dist_le (
f :
R ->
R)
x lower upper :
interval_decreasing f lower upper ->
lower <=
x <=
upper ->
R_dist (
f x) (
f upper) <=
R_dist (
f lower) (
f upper).
Proof.
Lemma subinterval_increasing (
f :
R ->
R) (
a b x y :
R) :
a <=
x ->
x <=
y ->
y <=
b ->
interval_increasing f a b ->
interval_increasing f x y.
Proof.
intros.
red in H2.
red.
intros.
cut (y0 <= b).
cut (a <= x0).
intuition.
lra.
lra.
Qed.
Lemma subinterval_decreasing (
f :
R ->
R) (
a b x y :
R) :
a <=
x ->
x <=
y ->
y <=
b ->
interval_decreasing f a b ->
interval_decreasing f x y.
Proof.
intros.
red in H2.
red.
intros.
cut (y0 <= b).
cut (a <= x0).
intuition.
lra.
lra.
Qed.
Lemma increasing_decreasing_opp (
f :
R ->
R) (
a b:
R) :
a <=
b ->
interval_increasing f a b ->
interval_decreasing (
fun x => -
f x)
a b.
Proof.
Definition Int_SF_alt l k
:=
fold_right Rplus 0
(
map (
fun '(
x,
y) =>
x *
y)
(
combine l
(
map (
fun '(
x,
y) =>
y -
x) (
adjacent_pairs k)))).
Lemma Int_SF_alt_eq l k :
Int_SF l k =
Int_SF_alt l k.
Proof.
unfold Int_SF_alt.
revert k.
induction l;
simpl;
trivial.
destruct k;
simpl;
trivial.
destruct k;
simpl;
trivial.
rewrite IHl;
trivial.
Qed.
Lemma up_IZR n :
up (
IZR n) = (
Z.succ n)%
Z.
Proof.
Lemma up0 :
up 0 = 1%
Z.
Proof.
Lemma up_pos (
r:
R) :
r>0 -> ((
up r) > 0)%
Z.
Proof.
intros.
destruct (
archimed r)
as [
lb ub].
assert (
IZR (
up r) > 0)
by lra.
apply lt_IZR in H0.
lia.
Qed.
Lemma up_nonneg (
r:
R) :
r>=0 -> ((
up r) >= 0)%
Z.
Proof.
inversion 1.
-
unfold Z.ge;
rewrite up_pos;
congruence.
-
subst.
rewrite up0.
lia.
Qed.
Lemma INR_up_pos r :
r >= 0 ->
INR (
Z.to_nat (
up r)) =
IZR (
up r).
Proof.
Section extra.
Lemma Rmult_four_assoc (
a b c d :
R) :
a *
b * (
c *
d) =
a * (
b*
c) *
d.
Proof.
ring.
Qed.
Lemma Radd_minus (
r1 r2 r3 :
R) :
r1 =
r2 +
r3 <->
r1 -
r2 =
r3.
Proof.
split; intros; try lra.
Qed.
Lemma Radd_radd_minus (
r1 r2 r3 r4 :
R):
r1 +
r2 =
r3 +
r4 <->
r3 -
r1 =
r2 -
r4.
Proof.
split; intros; try lra.
Qed.
Lemma Rmult_bigpos_le_l a b :
0 <=
a ->
1 <=
b ->
a <=
b *
a.
Proof.
Lemma Rmult_le_compat2 (
r1 r2 r3 r4 :
R) :
0 <=
r1 -> 0 <=
r2 -> 0 <=
r4 ->
r1 <=
r2 ->
r3 <=
r4 ->
r1 *
r3 <=
r2 *
r4.
Proof.
Lemma Rmult_lt_1 (
a b :
R) :
0 <=
a <= 1 ->
b < 1 ->
a*
b < 1.
Proof.
Lemma Rmult_le_1 (
a b :
R) :
0 <=
a <= 1 ->
0 <=
b <= 1 ->
0 <=
a*
b <= 1.
Proof.
Lemma Rplus_minus_cancel1 :
forall a b,
a +
b -
a =
b.
Proof.
intros; ring. Qed.
Lemma Rplus_le_pos_l (
f g :
R) :
0 <=
g ->
f <=
f +
g.
Proof.
Lemma Rsqrt_ext x y :
nonneg x =
nonneg y ->
Rsqrt x =
Rsqrt y.
Proof.
intros.
destruct x;
destruct y;
simpl in *.
subst.
unfold Rsqrt.
repeat match_destr.
simpl in *.
destruct a as [??].
destruct a0 as [??].
subst.
apply Rsqr_eq_abs_0 in H2.
now repeat rewrite Rabs_pos_eq in H2 by trivial.
Qed.
Lemma Rabs_sqr (
x :
R) :
x² =
Rabs (
x²).
Proof.
Lemma Rsqrt_le_to_Rsqr:
forall r x :
nonnegreal,
x <=
r² <->
Rsqrt x <=
r.
Proof.
intros.
unfold Rsqrt.
match_destr.
destruct a as [?
eqq].
rewrite eqq.
split;
intros HH.
-
apply Rsqr_le_abs_0 in HH.
destruct r;
destruct x;
simpl in *.
now repeat (
rewrite Rabs_pos_eq in HH by lra).
-
apply Rsqr_le_abs_1.
destruct r;
destruct x;
simpl in *.
now repeat (
rewrite Rabs_pos_eq by lra).
Qed.
Lemma Rsqrt_lt_to_Rsqr:
forall r x :
nonnegreal,
x <
r² <->
Rsqrt x <
r.
Proof.
intros.
unfold Rsqrt.
match_destr.
destruct a as [?
eqq].
rewrite eqq.
split;
intros HH.
-
apply Rsqr_lt_abs_0 in HH.
destruct r;
destruct x;
simpl in *.
now repeat (
rewrite Rabs_pos_eq in HH by lra).
-
apply Rsqr_lt_abs_1.
destruct r;
destruct x;
simpl in *.
now repeat (
rewrite Rabs_pos_eq by lra).
Qed.
Lemma Rsqr_pos (
a :
posreal) :
0 <
Rsqr a.
Proof.
generalize (
Rle_0_sqr a);
intros.
destruct H;
trivial.
generalize (
cond_pos a);
intros.
symmetry in H;
apply Rsqr_eq_0 in H.
lra.
Qed.
Lemma mkpos_Rsqr (
a :
posreal) :
Rsqr a =
mkposreal _ (
Rsqr_pos a).
Proof.
now simpl.
Qed.
Lemma Rplus_le_compat1_l (
a b :
R) :
0 <=
b ->
a <=
a +
b.
Proof.
Lemma Rmult_pos_parts {
x y}: (0 <
x *
y) ->
(0 <
x /\ 0 <
y) \/ (
x < 0 /\
y < 0).
Proof.
Lemma Rmult_le_pos_from_neg:
forall r1 r2 :
R,
r1 <= 0 ->
r2 <= 0 -> 0 <=
r1 *
r2.
Proof.
intros.
assert (0 <= (-
r1) * (-
r2)).
{
apply Rmult_le_pos;
lra.
}
lra.
Qed.
Lemma Rmult_nnneg_neg {
x y:
R} :
(~ 0 <=
x *
y) ->
x < 0 \/
y < 0.
Proof.
End extra.
Section list_sum.
Fixpoint list_sum (
l :
list R) :
R :=
match l with
|
nil => 0
|
x ::
xs =>
x +
list_sum xs
end.
Lemma list_sum_cat (
l1 l2 :
list R) :
list_sum (
l1 ++
l2) = (
list_sum l1) + (
list_sum l2).
Proof.
induction l1.
* simpl ; nra.
* simpl. nra.
Qed.
Lemma list_sum_map_concat (
l :
list(
list R)) :
list_sum (
concat l) =
list_sum (
map list_sum l).
Proof.
induction l.
-
simpl ;
reflexivity.
-
simpl ;
rewrite list_sum_cat.
now rewrite IHl.
Qed.
Global Instance list_sum_Proper :
Proper (@
Permutation R ==>
eq)
list_sum.
Proof.
unfold Proper.
intros x y H.
apply (@
Permutation_ind_bis R (
fun a b =>
list_sum a =
list_sum b)).
-
simpl ;
lra.
-
intros x0 l l'
Hpll'
Hll'.
simpl ;
f_equal.
assumption.
-
intros x0 y0 l l'
H0 H1.
simpl.
rewrite H1 ;
lra.
-
intros l l'
l''
H0 H1 H2 H3.
rewrite H1.
rewrite <-
H3.
reflexivity.
-
assumption.
Qed.
Lemma list_sum_perm_eq (
l1 l2 :
list R) :
Permutation l1 l2 ->
list_sum l1 =
list_sum l2.
Proof.
intro H.
now rewrite H.
Qed.
Lemma list_sum_map_ext {
A :
Type} (
f g :
A ->
R) (
l :
list A):
(
forall x,
f x =
g x) ->
list_sum (
map f l) =
list_sum (
map g l).
Proof.
Lemma list_sum_const_mul {
A :
Type}
f (
l :
list A) :
forall r,
list_sum (
map (
fun x =>
r*
f x)
l) =
r*
list_sum (
map (
fun x =>
f x)
l).
Proof.
intro r.
induction l.
simpl; lra.
simpl. rewrite IHl ; lra.
Qed.
Lemma list_sum_map_const {
A} (
l :
list A) (
a :
A) (
f :
A ->
R) :
list_sum (
map (
fun x =>
f a)
l) =
INR(
length l)* (
f a).
Proof.
induction l.
-
simpl ;
lra.
-
simpl.
rewrite IHl.
enough (
match length l with
| 0%
nat => 1
|
S _ =>
INR (
length l) + 1
end =
INR(
length l) + 1).
rewrite H ;
lra.
generalize (
length l)
as n.
intro n.
induction n.
+
simpl ;
lra.
+
lra.
Qed.
Lemma list_sum_map_zero {
A} (
s :
list A) :
list_sum (
List.map (
fun _ => 0)
s) = 0.
Proof.
induction s.
- simpl; reflexivity.
- simpl. rewrite IHs ; lra.
Qed.
Lemma list_sum_le {
A} (
l :
list A) (
f g :
A ->
R) :
(
forall a,
f a <=
g a) ->
list_sum (
List.map f l) <=
list_sum (
List.map g l).
Proof.
intros Hfg.
induction l.
-
simpl ;
right ;
trivial.
-
simpl.
specialize (
Hfg a).
apply Rplus_le_compat ;
trivial.
Qed.
Lemma list_sum_mult_const (
c :
R) (
l :
list R) :
list_sum (
List.map (
fun z =>
c*
z)
l) =
c*
list_sum (
List.map (
fun z =>
z)
l).
Proof.
induction l.
simpl; lra.
simpl in *. rewrite IHl.
lra.
Qed.
Lemma list_sum_const_mult_le {
x y :
R} (
l :
list R) (
hl :
list_sum l =
R1) (
hxy :
x <=
y) :
list_sum (
List.map (
fun z =>
x*
z)
l) <=
y.
Proof.
Lemma list_sum_fun_mult_le {
x y D :
R} {
f g :
R ->
R}(
l :
list R)(
hf :
forall z,
f z <=
D) (
hg :
forall z , 0 <=
g z) :
list_sum (
List.map (
fun z => (
f z)*(
g z))
l) <=
D*
list_sum (
List.map (
fun z =>
g z)
l).
Proof.
Lemma list_sum_map_add {
A:
Type} (
f g :
A ->
R) (
l :
list A) :
list_sum (
map (
fun x =>
f x +
g x)
l) =
list_sum (
map f l) +
list_sum (
map g l).
Proof.
induction l; simpl; lra.
Qed.
Lemma list_sum_map_sub {
A:
Type} (
f g :
A ->
R) (
l :
list A) :
list_sum (
map (
fun x =>
f x -
g x)
l) =
list_sum (
map f l) -
list_sum (
map g l).
Proof.
induction l; simpl; lra.
Qed.
Lemma list_sum_fold_right l :
list_sum l =
fold_right Rplus 0
l.
Proof.
induction l; firstorder.
Qed.
Lemma list_sum_pos_pos l :
Forall (
fun x =>
x >= 0)
l ->
list_sum l >= 0.
Proof.
induction l; simpl; try lra.
intros HH; invcs HH.
specialize (IHl H2).
lra.
Qed.
Lemma list_sum_pos_pos'
l :
Forall (
fun x => 0 <=
x)
l ->
0 <=
list_sum l.
Proof.
induction l; simpl; try lra.
intros HH; invcs HH.
specialize (IHl H2).
lra.
Qed.
Lemma list_sum_all_pos_zero_all_zero l :
list_sum l = 0 ->
Forall (
fun x =>
x >= 0)
l ->
Forall (
fun x =>
x = 0)
l.
Proof.
induction l;
intros.
-
constructor.
-
invcs H0.
simpl in H.
generalize (
list_sum_pos_pos _ H4);
intros HH.
assert (
a = 0)
by lra.
subst.
field_simplify in H.
auto.
Qed.
End list_sum.
Lemma Rsqrt_le (
x y :
nonnegreal) :
x <=
y <->
Rsqrt x <=
Rsqrt y.
Proof.
Lemma Rsqrt_lt (
x y :
nonnegreal) :
x <
y <->
Rsqrt x <
Rsqrt y.
Proof.
Lemma Rsqrt_sqr (
x:
nonnegreal) :
Rsqrt {|
nonneg :=
x²;
cond_nonneg :=
Rle_0_sqr x |} =
x.
Proof.
Lemma Rsqr_lt_to_Rsqrt (
x r:
nonnegreal) :
r <
x² <->
Rsqrt r <
x.
Proof.
Lemma Rsqr_le_to_Rsqrt (
r x:
nonnegreal):
x² <=
r <->
x <=
Rsqrt r.
Proof.
Lemma Rsqr_continuous :
continuity Rsqr.
Proof.
Section sum_n.
Lemma sum_n_pos {
a :
nat ->
R} (
N:
nat) :
(
forall n, (
n <=
N)%
nat -> 0 <
a n) ->
0 <
sum_n a N.
Proof.
Lemma sum_n_nneg {
a :
nat ->
R} (
N:
nat) :
(
forall n, (
n <=
N)%
nat -> 0 <=
a n) ->
0 <=
sum_n a N.
Proof.
Lemma sum_n_zero (
n :
nat):
sum_n (
fun _ => 0)
n = 0.
Proof.
Lemma pos_ind_sum (
gamma :
nat ->
R) (
N :
nat) :
0 <
sum_n gamma N ->
exists M :
nat, 0 <
gamma M.
Proof.
induction N.
+
rewrite sum_O;
eauto.
+
rewrite sum_Sn;
intros Hpos.
destruct (
Rlt_dec 0 (
sum_n gamma N)); [
eauto|].
destruct (
Rlt_dec 0 (
gamma (
S N))); [
eauto|].
unfold plus in *;
simpl in *;
lra.
Qed.
Lemma Series_nonneg {
a :
nat ->
R} : (
forall n, 0 <=
a n) -> 0 <=
Series a.
Proof.
Lemma Series_pos {
a :
nat ->
R} :
ex_series a -> (
forall n, 0 <
a n) -> 0 <
Series a.
Proof.
End sum_n.
Section expprops.
Lemma ex_series_exp_even (
x:
R):
ex_series (
fun k :
nat => /
INR(
fact(2*
k))*(
x^2)^
k).
Proof.
Lemma ex_series_exp_odd (
x:
R):
ex_series (
fun k :
nat => /
INR(
fact(2*
k + 1)) * (
x^2)^
k).
Proof.
Lemma exp_even_odd (
x :
R) :
exp x = (
Series (
fun n => (
x^(2*
n)/
INR(
fact (2*
n)) +
x^(2*
n + 1)/
INR(
fact (2*
n + 1))))).
Proof.
Lemma ex_series_even_odd (
x:
R) :
ex_series (
fun n :
nat =>
x ^ (2 *
n) /
INR (
fact (2 *
n)) +
x ^ (2 *
n + 1) /
INR (
fact (2 *
n + 1))).
Proof.
Lemma exp_even_odd_incr_1 (
x :
R) :
exp x = (1 +
x) + (
Series (
fun n =>
(
x^(2*(
S n)))/
INR(
fact (2*(
S n)))
+
x^(2*(
S n) + 1)/
INR(
fact (2*(
S n) + 1)))).
Proof.
Lemma exp_ineq2 :
forall x :
R,
x <= -1 -> (1 +
x <
exp x).
Proof.
Lemma exp_ineq3_aux (
n :
nat) {
x :
R}:
(-1 <
x < 0) -> 0 < (
x^(2*
n)/
INR(
fact (2*
n)) +
x^(2*
n + 1)/
INR(
fact (2*
n + 1))).
Proof.
Lemma exp_ineq3 {
x :
R} : -1 <
x < 0 -> 1+
x <
exp x.
Proof.
Lemma exp_ineq (
x :
R) : 1+
x <=
exp x.
Proof.
Lemma exp_increasing_le (
x y :
R) :
x <=
y ->
exp x <=
exp y.
Proof.
intros.
destruct (
Rlt_dec x y).
-
left.
now apply exp_increasing.
-
assert (
x =
y)
by lra.
rewrite H0.
now right.
Qed.
Lemma exp_ineq1 :
forall x :
R,
x <> 0 -> 1 +
x <
exp x.
Proof.
Lemma exp_ineq1_le (
x :
R) : 1 +
x <=
exp x.
Proof.
End expprops.
Section ln.
Lemma ln_lt_0 (
a :
R) :
0 <
a < 1 ->
ln a < 0.
Proof.
Lemma ln_le_0 (
a :
R) :
0 <
a <= 1 ->
ln a <= 0.
Proof.
intros.
destruct (
Rlt_dec a 1).
-
left.
apply ln_lt_0;
lra.
-
assert (
a = 1)
by lra.
rewrite H0.
rewrite ln_1;
lra.
Qed.
End ln.
Section convex.
Definition convex (
f :
R ->
R) (
a x y :
R) :=
0<=
a<=1 ->
f (
a *
x + (1-
a) *
y) <=
a *
f x + (1-
a)*
f y.
Lemma compose_convex (
f g :
R ->
R) (
a x y :
R) :
(
forall (
x y :
R),
convex f a x y) ->
convex g a x y ->
increasing f ->
convex (
fun z =>
f (
g z))
a x y.
Proof.
unfold convex,
increasing.
intros.
apply Rle_trans with (
r2 :=
f (
a *
g x + (1 -
a) *
g y)).
apply H1.
now apply H0.
now apply H.
Qed.
Lemma compose_convex_pos (
f g :
R ->
R) (
a x y :
R) :
(
forall x, 0 <=
g x) ->
(
forall (
x y :
R), 0 <=
x -> 0 <=
y ->
convex f a x y) ->
convex g a x y ->
increasing f ->
convex (
fun z =>
f (
g z))
a x y.
Proof.
unfold convex,
increasing.
intros.
apply Rle_trans with (
r2 :=
f (
a *
g x + (1 -
a) *
g y)).
apply H2.
now apply H1.
now apply H0.
Qed.
Lemma abs_convex :
forall (
a x y :
R),
convex Rabs a x y.
Proof.
Lemma convex_deriv (
f f' :
R ->
R) :
(
forall c :
R,
derivable_pt_lim f c (
f'
c)) ->
(
forall x y :
R,
f y >=
f x +
f'
x * (
y -
x)) ->
forall x y c :
R,
convex f c x y.
Proof.
unfold convex.
intros.
generalize (
H0 (
c *
x + (1-
c)*
y)
x);
intros.
generalize (
H0 (
c *
x + (1-
c)*
y)
y);
intros.
apply Rge_le in H2.
apply Rge_le in H3.
apply Rmult_le_compat_l with (
r :=
c)
in H2;
try lra.
apply Rmult_le_compat_l with (
r := 1-
c)
in H3;
try lra.
Qed.
Lemma pos_convex_deriv (
f f' :
R ->
R) :
(
forall c :
R, 0 <=
c ->
derivable_pt_lim f c (
f'
c)) ->
(
forall x y :
R, 0 <=
x -> 0 <=
y ->
f y >=
f x +
f'
x * (
y -
x)) ->
forall x y c :
R, 0 <=
x -> 0 <=
y ->
convex f c x y.
Proof.
Lemma ppos_convex_deriv (
f f' :
R ->
R) :
(
forall c :
R, 0 <
c ->
derivable_pt_lim f c (
f'
c)) ->
(
forall x y :
R, 0 <
x -> 0 <
y ->
f y >=
f x +
f'
x * (
y -
x)) ->
forall x y c :
R, 0 <
x -> 0 <
y ->
convex f c x y.
Proof.
Lemma deriv_incr_convex (
f f' :
R ->
R) :
(
forall c :
R,
derivable_pt_lim f c (
f'
c)) ->
(
forall (
x y :
R),
x <=
y ->
f'
x <=
f'
y) ->
forall (
x y :
R),
f y >=
f x +
f'
x * (
y-
x).
Proof.
intros.
generalize (
MVT_cor3 f f');
intros.
destruct (
Rtotal_order x y).
-
specialize (
H1 x y H2).
cut_to H1.
+
destruct H1 as [
x0 [? [? ?]]].
assert (
f'
x <=
f'
x0)
by (
apply H0;
lra).
apply Rmult_le_compat_r with (
r := (
y-
x))
in H5;
lra.
+
intros;
apply H;
lra.
-
destruct H2; [
subst;
lra| ].
specialize (
H1 y x H2).
cut_to H1.
+
destruct H1 as [
x0 [? [? ?]]].
assert (
f'
x0 <=
f'
x)
by (
apply H0;
lra).
apply Rmult_le_compat_r with (
r := (
x-
y))
in H5;
lra.
+
intros;
apply H;
lra.
Qed.
Lemma pos_deriv_incr_convex (
f f' :
R ->
R) :
(
forall c :
R, 0 <=
c ->
derivable_pt_lim f c (
f'
c)) ->
(
forall (
x y :
R), 0<=
x -> 0 <=
y ->
x <=
y ->
f'
x <=
f'
y) ->
forall (
x y :
R), 0 <=
x -> 0 <=
y ->
f y >=
f x +
f'
x * (
y-
x).
Proof.
intros.
generalize (
MVT_cor3 f f');
intros.
destruct (
Rtotal_order x y).
-
specialize (
H3 x y H4).
cut_to H3.
+
destruct H3 as [
x0 [? [? ?]]].
assert (
f'
x <=
f'
x0)
by (
apply H0;
lra).
apply Rmult_le_compat_r with (
r := (
y-
x))
in H7;
lra.
+
intros;
apply H;
lra.
-
destruct H4; [
subst;
lra| ].
specialize (
H3 y x H4).
cut_to H3.
+
destruct H3 as [
x0 [? [? ?]]].
assert (
f'
x0 <=
f'
x)
by (
apply H0;
lra).
apply Rmult_le_compat_r with (
r := (
x-
y))
in H7;
lra.
+
intros;
apply H;
lra.
Qed.
Lemma ppos_deriv_incr_convex (
f f' :
R ->
R) :
(
forall c :
R, 0 <
c ->
derivable_pt_lim f c (
f'
c)) ->
(
forall (
x y :
R), 0<
x -> 0 <
y ->
x <=
y ->
f'
x <=
f'
y) ->
forall (
x y :
R), 0 <
x -> 0 <
y ->
f y >=
f x +
f'
x * (
y-
x).
Proof.
intros.
generalize (
MVT_cor3 f f');
intros.
destruct (
Rtotal_order x y).
-
specialize (
H3 x y H4).
cut_to H3.
+
destruct H3 as [
x0 [? [? ?]]].
assert (
f'
x <=
f'
x0)
by (
apply H0;
lra).
apply Rmult_le_compat_r with (
r := (
y-
x))
in H7;
lra.
+
intros;
apply H;
lra.
-
destruct H4; [
subst;
lra| ].
specialize (
H3 y x H4).
cut_to H3.
+
destruct H3 as [
x0 [? [? ?]]].
assert (
f'
x0 <=
f'
x)
by (
apply H0;
lra).
apply Rmult_le_compat_r with (
r := (
x-
y))
in H7;
lra.
+
intros;
apply H;
lra.
Qed.
Lemma pow_convex (
n :
nat) :
forall (
a x y :
R), 0<=
x -> 0<=
y ->
convex (
fun z =>
pow z n)
a x y.
Proof.
Lemma exp_convex (
r :
R):
forall (
x y :
R),
convex exp r x y.
Proof.
End convex.
Section Rpower.
Lemma Rpower_pos b e : 0 <
Rpower b e.
Proof.
Lemma Rpower_nzero b e : ~ (
Rpower b e = 0).
Proof.
Lemma Rpower_inv_cancel x n :
0 <
x ->
n <> 0 ->
Rpower (
Rpower x n) (
Rinv n) =
x.
Proof.
Lemma pow0_Sbase n :
pow 0 (
S n) = 0.
Proof.
simpl; field.
Qed.
Lemma pow_integral n y :
y ^
S n = 0 ->
y = 0.
Proof.
intros.
induction n;
simpl in *.
-
lra.
-
apply Rmult_integral in H.
destruct H;
lra.
Qed.
Lemma Rabs_pow_eq_inv x y n :
Rabs x ^
S n =
Rabs y ^
S n ->
Rabs x =
Rabs y.
Proof.
Lemma Rpower_ln :
forall x y :
R,
ln (
Rpower x y) =
y*
ln x.
Proof.
Lemma Rpower_base_1 :
forall x :
R,
Rpower 1
x = 1.
Proof.
intros.
unfold Rpower.
rewrite ln_1.
replace (
x*0)
with 0
by lra.
apply exp_0.
Qed.
Lemma log_power_base (
e b :
R ) :
0 <
e -> 0 <
b ->
b <> 1 ->
Rpower b (
ln e /
ln b) =
e.
Proof.
Lemma Rpower_lt1 (
b y z :
R ) :
0 <
b < 1 ->
y <
z ->
Rpower b y >
Rpower b z.
Proof.
Lemma Rpower_neg1 b e :
b < 0 ->
Rpower b e = 1.
Proof.
Lemma Rpower_convex_pos (
e:
R) :
1 <=
e ->
forall (
x y a :
R), 0<
x -> 0<
y ->
convex (
fun z =>
Rpower z e)
a x y.
Proof.
Lemma Rpower_base_0 e :
Rpower 0
e = 1.
Proof.
End Rpower.
Section power.
Definition power (
b e :
R)
:=
if Rle_dec b 0
then 0
else Rpower b e.
Lemma power_Rpower (
b e :
R) :
0 <
b ->
power b e =
Rpower b e.
Proof.
unfold power.
match_destr;
lra.
Qed.
Lemma power_nonneg (
b e :
R) :
0 <=
power b e .
Proof.
Lemma power_base_1 e :
power 1
e = 1.
Proof.
Lemma power_pos (
b e :
R) :
0 <
b ->
0 <
power b e .
Proof.
Lemma power_Ropp (
x y :
R) :
0 <
x ->
power x (-
y) = /
power x y.
Proof.
Lemma power_integral b e :
power b e = 0 ->
b <= 0.
Proof.
Lemma power_le_0 b e :
power b e <= 0 ->
b <= 0.
Proof.
Lemma power_mult (
x y z :
R) :
power (
power x y)
z =
power x (
y *
z).
Proof.
Lemma power_plus (
x y z :
R) :
power z (
x +
y) =
power z x *
power z y.
Proof.
Lemma power_1 (
x :
R) :
0 <=
x ->
power x 1 =
x.
Proof.
unfold power;
intros.
match_destr; [
lra |].
apply Rpower_1;
lra.
Qed.
Lemma power_O (
x :
R) :
0 <
x ->
power x 0 = 1.
Proof.
unfold power;
intros.
match_destr; [
lra |].
now apply Rpower_O.
Qed.
Lemma powerRZ_power (
x :
R) (
z :
Z) :
0 <
x ->
powerRZ x z =
power x (
IZR z).
Proof.
Lemma power_minus1 b e :
0 <=
b ->
power b e =
b *
power b (
e-1).
Proof.
intros.
replace e with ((
e-1)+1)
at 1
by lra.
rewrite power_plus.
rewrite power_1;
trivial.
lra.
Qed.
Lemma Rle_power (
e n m :
R) :
1 <=
e ->
n <=
m ->
power e n <=
power e m.
Proof.
Lemma power_big_big a e :
0 <=
e ->
1 <=
a ->
1 <=
power a e.
Proof.
intros nne pbig.
generalize (
Rle_power a 0
e pbig nne).
rewrite power_O;
lra.
Qed.
Lemma power_lt (
x y z :
R) :
1 <
x ->
y <
z ->
power x y <
power x z.
Proof.
Lemma power0_Sbase e :
power 0
e = 0.
Proof.
unfold power.
match_destr.
lra.
Qed.
Lemma power_inv_cancel b e :
0 <=
b ->
e <> 0 ->
power (
power b (/
e))
e =
b.
Proof.
Lemma inv_power_cancel b e :
0 <=
b ->
e <> 0 ->
power (
power b e) (/
e) =
b.
Proof.
Lemma power_eq_inv x y n :
0 <>
n ->
0 <=
x ->
0 <=
y ->
power x n =
power y n ->
x =
y.
Proof.
Lemma power_pow (
n :
nat) (
x :
R) :
0 <
x ->
power x (
INR n) =
x ^
n.
Proof.
Lemma power_Spow (
n :
nat) (
x :
R) :
0 <=
x ->
power x (
INR (
S n)) =
x ^ (
S n).
Proof.
Lemma power2_sqr (
x :
R) :
0 <=
x ->
power x 2 =
Rsqr x.
Proof.
Lemma power_abs2_sqr (
x :
R) :
power (
Rabs x) 2 =
Rsqr x.
Proof.
Lemma power_2_sqrt (
x :
nonnegreal) :
power x (/2) =
Rsqrt x.
Proof.
Lemma Rlt_power_l (
a b c :
R) :
0 <
c ->
0 <=
a <
b ->
power a c <
power b c.
Proof.
Lemma Rle_power_l (
a b c :
R) :
0 <=
c ->
0 <=
a <=
b ->
power a c <=
power b c.
Proof.
Lemma power_sqrt (
x :
R) :
0 <=
x ->
power x (/ 2) =
sqrt x.
Proof.
Lemma power_mult_distr (
x y z :
R) :
0 <=
x ->
0 <=
y ->
power x z *
power y z =
power (
x *
y)
z.
Proof.
unfold power;
intros.
repeat match_destr;
subst;
try lra.
-
assert (
x = 0)
by lra;
subst;
lra.
-
assert (
x = 0)
by lra;
subst;
lra.
-
assert (
y = 0)
by lra;
subst;
lra.
-
assert (0 <
x)
by lra.
assert (0 <
y)
by lra.
generalize (
Rmult_lt_0_compat _ _ H1 H2);
intros.
lra.
-
apply Rpower_mult_distr;
lra.
Qed.
Lemma power_incr_inv (
x y:
R) (
n :
R) :
0 <
n ->
0 <=
x ->
0 <=
y ->
power x n <=
power y n ->
x <=
y.
Proof.
Lemma derivable_pt_lim_power' (
x y :
R) :
0 <
x ->
derivable_pt_lim (
fun x0 :
R =>
power x0 y)
x (
y *
power x (
y - 1)).
Proof.
Lemma Dpower' (
y z :
R) :
0 <
y ->
D_in (
fun x :
R =>
power x z) (
fun x :
R =>
z *
power x (
z - 1))
(
fun x :
R => 0 <
x)
y.
Proof.
Lemma derivable_pt_lim_abs_power2' (
x y :
R) :
0 <=
x ->
1 <
y ->
derivable_pt_lim (
fun x0 :
R =>
power (
Rabs x0)
y)
x (
y *
power x (
y - 1)).
Proof.
Lemma power_convex_pos (
e:
R) :
1 <=
e ->
forall (
x y a :
R), 0<
x -> 0<
y ->
convex (
fun z =>
power z e)
a x y.
Proof.
Lemma power_scale_le (
e a x:
R) :
1 <=
e ->
0 <
x ->
0 <=
a <= 1 ->
power (
a *
x)
e <=
a *
power x e.
Proof.
Lemma power_increasing (
e :
R) :
0 <=
e ->
increasing (
fun z =>
power z e).
Proof.
Lemma power_convex (
e:
R) :
1 <=
e ->
forall (
x y a :
R),
convex (
fun z =>
power z e)
a x y.
Proof.
Lemma convex_power_abs (
e:
R): 1 <=
e ->
forall c x y :
R,
convex (
fun a :
R =>
power (
Rabs a)
e)
c x y.
Proof.
Lemma power_ineq_convex p :
1 <=
p ->
forall (
x y :
R), 0 <
x -> 0 <
y ->
power (
x +
y)
p <= (
power 2 (
p-1))*(
power x p +
power y p).
Proof.
Lemma power_abs_ineq (
p :
R) (
x y :
R) :
0 <=
p ->
power (
Rabs (
x +
y))
p <= (
power 2
p)*(
power (
Rabs x)
p +
power (
Rabs y)
p).
Proof.
Lemma Rinv_power (
x :
R) (
n :
R) : 0 <
x -> /
power x n =
power (/
x)
n.
Proof.
End power.
Section ineqs.
Lemma frac_max_frac_le (
x y:
R) :
1 <=
x ->
x <=
y ->
x / (
x + 1) <=
y / (
y + 1).
Proof.
Lemma sum_one_le :
forall x y :
R, 0 <=
x -> 0 <=
y ->
x +
y = 1 ->
x <= 1.
Proof.
intros.
rewrite <-
H1.
replace (
x)
with (
x+0)
by lra.
replace (
x+0+
y)
with (
x+
y)
by lra.
apply Rplus_le_compat_l ;
trivial.
Qed.
Theorem Rpower_youngs_ineq {
p q :
posreal} {
a b :
R} (
Hpq : 1/
p + 1/
q = 1) :
0 <
a -> 0 <
b ->
a*
b <= (
Rpower a p)/
p + (
Rpower b q)/
q.
Proof.
Theorem youngs_ineq {
p q :
posreal} {
a b :
R} (
Hpq : 1/
p + 1/
q = 1) :
0 <=
a -> 0 <=
b ->
a*
b <= (
power a p)/
p + (
power b q)/
q.
Proof.
Theorem youngs_ineq_2 {
p q :
posreal} (
Hpq : 1/
p + 1/
q = 1):
forall (
t a b :
R), 0 <=
a -> 0 <=
b -> 0 <
t ->
(
power a (1/
p))*(
power b (1/
q)) <= (
power t (-1/
q))*
a/
p + (
power t (1/
p))*
b/
q.
Proof.
Theorem Rpower_youngs_ineq_2 {
p q :
posreal} (
Hpq : 1/
p + 1/
q = 1):
forall (
t a b :
R), 0 <
a -> 0 <
b -> 0 <
t ->
(
Rpower a (1/
p))*(
Rpower b (1/
q)) <= (
Rpower t (-1/
q))*
a/
p + (
Rpower t (1/
p))*
b/
q.
Proof.
intros.
generalize (
youngs_ineq_2 Hpq t a b) ;
intros HH.
cut_to HH;
try lra.
now repeat rewrite power_Rpower in HH by lra.
Qed.
Corollary ag_ineq (
a b :
R):
0 <=
a -> 0 <=
b ->
sqrt (
a*
b) <= (
a+
b)/2.
Proof.
Lemma pow_minkowski_helper_aux (
p:
nat) (
a t :
R) : 0 <
t ->
t*(
pow(
a/
t) (
S p)) = (
pow a (
S p))*(
pow (/
t)
p).
Proof.
Lemma pow_minkowski_helper (
p :
nat) {
a b t :
R}:
(0 <=
a) -> (0 <=
b) -> 0<
t<1 ->
(
pow (
a+
b) (
S p)) <= (
pow (/
t)
p)*(
pow a (
S p)) + (
pow (/(1-
t))
p)*(
pow b (
S p)).
Proof.
intros Ha Hb Ht.
assert (
Ht1 :
t <> 0)
by (
intro not;
destruct Ht as [
h1 h2] ;
subst ;
lra).
assert (
Ht2 : 1-
t <> 0)
by (
intro not;
destruct Ht as [
h1 h2] ;
subst ;
lra).
assert (
Hat : 0 <=
a/
t)
by (
apply Rcomplements.Rdiv_le_0_compat ;
lra).
assert (
Hbt : 0 <=
b/(1-
t))
by (
apply Rcomplements.Rdiv_le_0_compat ;
lra).
assert (
Ht' : 0 <=
t <= 1)
by lra.
replace (
a+
b)
with (
t*(
a/
t) + (1-
t)*(
b/(1-
t)))
by (
field ;
split ;
trivial).
generalize (
pow_convex (
S p)
t (
a/
t) (
b/(1-
t))
Hat Hbt Ht');
intros.
eapply Rle_trans.
apply H.
repeat (
rewrite pow_minkowski_helper_aux ;
try lra).
Qed.
Lemma pow_minkowski_subst (
p :
nat) {
a b :
R} :
(0 <
a) -> (0 <
b) ->
(
pow (/(
a / (
a +
b)))
p)*(
pow a (
S p)) +
(
pow (/(1-(
a / (
a +
b))))
p)*(
pow b (
S p)) = (
pow (
a +
b) (
S p)).
Proof.
Lemma minkowski_range (
a b :
R) :
(0 <
a) -> (0 <
b) ->
0 <
a / (
a +
b) < 1.
split.
-
apply Rdiv_lt_0_compat;
trivial.
now apply Rplus_lt_0_compat.
-
apply Rmult_lt_reg_r with (
r :=
a+
b).
now apply Rplus_lt_0_compat.
unfold Rdiv.
rewrite Rmult_assoc,
Rinv_l.
+
rewrite Rmult_1_r,
Rmult_1_l.
replace (
a)
with (
a + 0)
at 1
by lra.
now apply Rplus_lt_compat_l.
+
apply Rgt_not_eq.
now apply Rplus_lt_0_compat.
Qed.