Module FormalML.utils.RbarAdd
Require Import Coquelicot.Coquelicot.
Require Import Reals.
Require Import LibUtils List Permutation RealAdd ClassicUtils ELim_Seq ListAdd Sums CoquelicotAdd Isomorphism PairEncoding.
Require Import Reals Psatz Morphisms.
Require Import Classical_Prop Classical_Pred_Type.
Set Bullet Behavior "
Strict Subproofs".
Local Open Scope R_scope.
Section sums.
Local Existing Instance Rbar_le_pre.
Local Existing Instance Rbar_le_part.
Definition list_Rbar_sum (
l :
list Rbar) :
Rbar
:=
fold_right Rbar_plus (
Finite 0)
l.
Lemma list_Rbar_sum_const_mulR {
A :
Type}
f (
l :
list A) :
forall (
r:
R),
list_Rbar_sum (
map (
fun x =>
Rbar_mult r (
f x))
l) =
Rbar_mult r (
list_Rbar_sum (
map (
fun x =>
f x)
l)).
Proof.
Definition sum_Rbar_n (
f:
nat->
Rbar) (
n:
nat) :
Rbar
:=
list_Rbar_sum (
map f (
seq 0
n)).
Global Instance sum_Rbar_n_proper :
Proper (
pointwise_relation _ eq ==>
eq ==>
eq)
sum_Rbar_n.
Proof.
Instance fold_right_plus_le_proper :
Proper (
Rbar_le ==>
Forall2 Rbar_le ==>
Rbar_le) (
fold_right Rbar_plus).
Proof.
intros a b eqq1 x y eqq2.
revert a b eqq1.
induction eqq2;
simpl;
trivial;
intros.
apply Rbar_plus_le_compat;
trivial.
now apply IHeqq2.
Qed.
Lemma Rbar_plus_nneg_compat (
a b :
Rbar) :
Rbar_le 0
a ->
Rbar_le 0
b ->
Rbar_le 0 (
Rbar_plus a b).
Proof.
Lemma Rbar_mult_nneg_compat (
a b :
Rbar) :
Rbar_le 0
a ->
Rbar_le 0
b ->
Rbar_le 0 (
Rbar_mult a b).
Proof.
destruct a;
destruct b;
simpl;
rbar_prover.
intros.
generalize (
Rmult_le_compat 0
r 0
r0);
intros HH.
rewrite Rmult_0_r in HH.
apply HH;
lra.
Qed.
Lemma sum_Rbar_n_pos_incr (
f :
nat ->
Rbar) :
(
forall i :
nat,
Rbar_le 0 (
f i)) ->
forall n :
nat,
Rbar_le (
sum_Rbar_n f n) (
sum_Rbar_n f (
S n)).
Proof.
Lemma list_Rbar_sum_nneg_nneg (
l:
list Rbar) :
(
forall x,
In x l ->
Rbar_le 0
x) ->
Rbar_le 0 (
list_Rbar_sum l).
Proof.
intros.
induction l; [
reflexivity |].
simpl list_Rbar_sum.
apply Rbar_plus_nneg_compat.
-
apply H;
simpl;
tauto.
-
apply IHl;
intros.
apply H;
simpl;
tauto.
Qed.
Lemma sum_Rbar_n_nneg_nneg (
f :
nat ->
Rbar)
n :
(
forall i :
nat, (
i <=
n)%
nat ->
Rbar_le 0 (
f i)) ->
Rbar_le 0 (
sum_Rbar_n f n).
Proof.
Lemma nneg_fold_right_Rbar_plus_nneg l :
Forall (
Rbar_le 0)
l ->
Rbar_le 0 (
fold_right Rbar_plus 0
l).
Proof.
induction l.
-
simpl;
reflexivity.
-
simpl map;
simpl fold_right.
intros HH;
invcs HH.
apply Rbar_plus_nneg_compat;
auto.
Qed.
Lemma list_Rbar_sum_nneg_perm (
l1 l2:
list Rbar) :
Forall (
Rbar_le 0)
l1 ->
Forall (
Rbar_le 0)
l2 ->
Permutation l1 l2 ->
list_Rbar_sum l1 =
list_Rbar_sum l2.
Proof.
Lemma nneg_fold_right_Rbar_plus_acc l acc :
Rbar_le 0
acc ->
Forall (
Rbar_le 0)
l ->
fold_right Rbar_plus acc l =
Rbar_plus acc (
fold_right Rbar_plus (
Finite 0)
l).
Proof.
Lemma list_Rbar_sum_nneg_plus (
l1 l2 :
list Rbar) :
Forall (
Rbar_le 0)
l1 ->
Forall (
Rbar_le 0)
l2 ->
list_Rbar_sum (
l1 ++
l2) =
Rbar_plus (
list_Rbar_sum l1) (
list_Rbar_sum l2).
Proof.
Lemma sum_Rbar_n_nneg_plus (
f g:
nat->
Rbar) (
n:
nat) :
(
forall x, (
x <
n)%
nat ->
Rbar_le 0 (
f x)) ->
(
forall x, (
x <
n)%
nat ->
Rbar_le 0 (
g x)) ->
sum_Rbar_n (
fun x =>
Rbar_plus (
f x) (
g x))
n =
Rbar_plus (
sum_Rbar_n f n) (
sum_Rbar_n g n).
Proof.
Lemma fold_right_Rbar_plus_const {
A}
c (
l:
list A) :
fold_right Rbar_plus 0 (
map (
fun _ =>
c)
l) = (
Rbar_mult (
INR (
length l))
c).
Proof.
induction l;
intros.
-
simpl.
now rewrite Rbar_mult_0_l.
-
simpl length.
rewrite S_INR;
simpl.
rewrite IHl.
generalize (
pos_INR (
length l));
intros HH.
destruct c;
simpl;
rbar_prover.
Qed.
Lemma seq_sum_list_sum {
T}
(
f:
T ->
Rbar) (
B:
list T)
d :
f d = 0 ->
ELim_seq (
fun i :
nat =>
sum_Rbar_n (
fun n :
nat =>
f (
nth n B d))
i) =
list_Rbar_sum (
map f B).
Proof.
Global Instance list_Rbar_sum_monotone :
Proper (
Forall2 Rbar_le ==>
Rbar_le)
list_Rbar_sum.
Proof.
Global Instance sum_Rbar_n_monotone :
Proper (
pointwise_relation _ Rbar_le ==>
eq ==>
Rbar_le)
sum_Rbar_n.
Proof.
Lemma list_Rbar_sum_map_finite (
l:
list R) :
list_Rbar_sum (
map Finite l) =
list_sum l.
Proof.
unfold list_Rbar_sum.
induction l;
simpl;
trivial.
now rewrite IHl;
simpl.
Qed.
End sums.
Section rbar_empty_props.
Local Existing Instance Rbar_le_pre.
Local Existing Instance Rbar_le_part.
Extended Emptiness is decidable
Definition Rbar_Empty (
E :
Rbar ->
Prop) :=
Rbar_glb (
fun x =>
x = 0 \/
E x) =
Rbar_lub (
fun x =>
x = 0 \/
E x)
/\
Rbar_glb (
fun x =>
x = 1 \/
E x) =
Rbar_lub (
fun x =>
x = 1 \/
E x).
Lemma Rbar_Empty_correct_1 (
E :
Rbar ->
Prop) :
Rbar_Empty E ->
forall x, ~
E x.
Proof.
Lemma Rbar_Empty_correct_2 (
E :
Rbar ->
Prop) :
(
forall x, ~
E x) ->
Rbar_Empty E.
Proof.
Lemma Rbar_Empty_dec (
E :
Rbar ->
Prop) :
{~
Rbar_Empty E}+{
Rbar_Empty E}.
Proof.
Lemma not_Rbar_Empty_dec (
E :
Rbar ->
Prop) : (
Decidable.decidable (
exists x,
E x)) ->
{(
exists x,
E x)} + {(
forall x, ~
E x)}.
Proof.
Lemma Rbar_uniqueness_dec P : (
exists !
x :
Rbar,
P x) -> {
x :
Rbar |
P x}.
Proof.
End rbar_empty_props.
Section rbar_props.
Lemma is_finite_dec (
a:
Rbar) : {
is_finite a} + {~
is_finite a}.
Proof.
unfold is_finite;
destruct a;
simpl;
intuition congruence.
Qed.
Lemma Rbar_glb_ge (
E:
Rbar->
Prop)
c :
(
forall x,
E x ->
Rbar_le c x) ->
Rbar_le c (
Rbar_glb E).
Proof.
unfold Rbar_glb,
proj1_sig;
match_destr;
intros.
apply r;
intros ??.
now apply H.
Qed.
End rbar_props.
Section glb_props.
Lemma Rbar_is_glb_fin_close_classic {
E a} (
eps:
posreal):
Rbar_is_glb E (
Finite a) ->
exists x,
E x /\
Rbar_le x (
a +
eps).
Proof.
End glb_props.
Section elim_seq_props.
Local Existing Instance Rbar_le_pre.
Local Existing Instance Rbar_le_part.
Lemma ELim_seq_nneg (
f :
nat ->
Rbar) :
(
forall n,
Rbar_le 0 (
f n)) ->
Rbar_le 0 (
ELim_seq f).
Proof.
Lemma Elim_seq_sum_pos_fin_n_fin f r :
(
forall n,
Rbar_le 0 (
f n)) ->
ELim_seq
(
fun i :
nat =>
sum_Rbar_n f i) =
Finite r ->
forall n,
is_finite (
f n).
Proof.
Lemma Lim_seq_sum_2n2 :
Lim_seq (
fun n :
nat =>
list_sum (
map (
fun x :
nat => / 2 ^
x) (
seq 0
n))) = 2.
Proof.
Lemma Lim_seq_sum_2n :
Lim_seq (
fun n :
nat =>
list_sum (
map (
fun x :
nat => / 2 ^ (
S x)) (
seq 0
n))) = 1.
Proof.
Lemma ELim_seq_sum_2n :
ELim_seq (
fun n :
nat =>
list_sum (
map (
fun x :
nat => / 2 ^ (
S x)) (
seq 0
n))) = 1.
Proof.
Lemma ELim_seq_Rbar_sum_2n :
ELim_seq (
sum_Rbar_n (
fun x :
nat =>
Finite (/ 2 ^ (
S x)))) = 1.
Proof.
Lemma ELim_seq_sum_eps2n f eps :
(0 <=
eps) ->
(
forall x,
Rbar_le 0 (
f x)) ->
ELim_seq (
fun i =>
sum_Rbar_n (
fun a =>
Rbar_plus (
f a) (
eps / 2 ^ (
S a)))
i) =
Rbar_plus (
ELim_seq (
fun i =>
sum_Rbar_n f i))
eps.
Proof.
Lemma ELim_seq_sup_incr (
f :
nat ->
Rbar) :
(
forall n,
Rbar_le (
f n) (
f (
S n))) ->
ELim_seq f =
ELimSup_seq f.
Proof.
Lemma Elim_seq_le_bound (
f :
nat ->
Rbar) (
B:
Rbar) :
(
forall n,
Rbar_le (
f n)
B) ->
Rbar_le (
ELim_seq f)
B.
Proof.
Lemma sum_Rbar_n_Sn (
f :
nat ->
Rbar) (
n :
nat) :
(
forall n,
Rbar_le 0 (
f n)) ->
sum_Rbar_n f (
S n) =
Rbar_plus (
sum_Rbar_n f n) (
f n).
Proof.
Lemma sum_Rbar_n_pos_Sn (
f :
nat ->
Rbar) (
n :
nat) :
(
forall n,
Rbar_le 0 (
f n)) ->
Rbar_le (
sum_Rbar_n f n) (
sum_Rbar_n f (
S n)).
Proof.
End elim_seq_props.
Section lim_sum.
Lemma list_Rbar_sum_cat (
l1 l2 :
list Rbar) :
(
forall x1,
In x1 l1 ->
Rbar_le 0
x1) ->
(
forall x2,
In x2 l2 ->
Rbar_le 0
x2) ->
list_Rbar_sum (
l1 ++
l2) =
Rbar_plus (
list_Rbar_sum l1) (
list_Rbar_sum l2).
Proof.
Lemma list_Rbar_sum_nneg_nested_prod {
A B:
Type} (
X:
list A) (
Y:
list B) (
f:
A->
B->
Rbar) :
(
forall x y,
In x X ->
In y Y ->
Rbar_le 0 (
f x y)) ->
list_Rbar_sum (
map (
fun x =>
list_Rbar_sum (
map (
fun y =>
f x y)
Y))
X) =
list_Rbar_sum (
map (
fun xy =>
f (
fst xy) (
snd xy)) (
list_prod X Y)).
Proof.
intros.
induction X.
-
simpl.
induction Y.
+
now simpl.
+
reflexivity.
-
simpl.
rewrite IHX,
map_app,
list_Rbar_sum_cat.
+
f_equal.
now rewrite map_map.
+
intros.
rewrite in_map_iff in H0.
destruct H0 as [[? ?] [? ?]].
rewrite <-
H0.
apply in_map_iff in H1.
destruct H1 as [? [? ?]].
inversion H1.
apply H.
*
simpl;
now left.
*
now rewrite <-
H5.
+
intros.
rewrite in_map_iff in H0.
destruct H0 as [[? ?] [? ?]].
rewrite <-
H0.
rewrite in_prod_iff in H1.
apply H.
*
now apply in_cons.
*
easy.
+
intros.
apply H;
trivial.
now apply in_cons.
Qed.
Lemma list_Rbar_sum_nest_prod (
f :
nat ->
nat ->
Rbar ) (
l1 l2 :
list nat) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
list_Rbar_sum
(
map (
fun i :
nat =>
list_Rbar_sum (
map (
fun j :
nat =>
f i j)
l2))
l1) =
list_Rbar_sum (
map (
fun '(
a,
b) =>
f a b) (
list_prod l1 l2)).
Proof.
intros.
induction l1.
-
simpl.
induction l2.
+
now simpl.
+
reflexivity.
-
simpl.
rewrite IHl1,
map_app,
list_Rbar_sum_cat.
+
f_equal.
now rewrite map_map.
+
intros.
rewrite in_map_iff in H0.
destruct H0 as [[? ?] [? ?]].
now rewrite <-
H0.
+
intros.
rewrite in_map_iff in H0.
destruct H0 as [[? ?] [? ?]].
now rewrite <-
H0.
Qed.
Lemma sum_Rbar_n_pair_list_sum (
f :
nat ->
nat ->
Rbar ) (
n m :
nat) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
sum_Rbar_n (
fun x0 =>
sum_Rbar_n (
fun n1 =>
f x0 n1)
m)
n =
list_Rbar_sum (
map (
fun '(
a,
b) =>
f a b) (
list_prod (
seq 0
n) (
seq 0
m))).
Proof.
Lemma list_Rbar_sum_pos_sublist_le (
l1 l2 :
list Rbar) :
(
forall x,
In x l2 ->
Rbar_le 0
x) ->
sublist l1 l2 ->
Rbar_le (
list_Rbar_sum l1) (
list_Rbar_sum l2).
Proof.
Lemma bound_iso_f_pairs_sum_Rbar (
f :
nat ->
nat ->
Rbar) (
n0 n :
nat) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
exists (
x :
nat),
Rbar_le (
sum_Rbar_n (
fun x0 :
nat =>
sum_Rbar_n (
fun n1 :
nat =>
f x0 n1)
n0)
n)
(
sum_Rbar_n (
fun n1 :
nat =>
let '(
a,
b) :=
iso_b n1 in f a b)
x).
Proof.
Lemma bound_pair_iso_b_sum_Rbar (
f :
nat ->
nat ->
Rbar) (
x :
nat) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
exists (
n :
nat),
Rbar_le (
sum_Rbar_n (
fun n1 :
nat =>
let '(
a,
b) :=
iso_b n1 in f a b)
x)
(
sum_Rbar_n (
fun x0 :
nat =>
sum_Rbar_n (
fun n1 :
nat =>
f x0 n1)
n)
n).
Proof.
Lemma Elim_seq_incr_elem (
f :
nat ->
Rbar) :
(
forall n,
Rbar_le (
f n) (
f (
S n))) ->
forall n,
Rbar_le (
f n) (
ELim_seq f).
Proof.
intros.
replace (
f n)
with (
ELim_seq (
fun _ =>
f n))
by now rewrite ELim_seq_const.
apply ELim_seq_le_loc.
exists n.
intros.
pose (
h := (
n0-
n)%
nat).
replace (
n0)
with (
h +
n)%
nat by lia.
induction h.
-
replace (0 +
n)%
nat with n by lia.
apply Rbar_le_refl.
-
eapply Rbar_le_trans.
+
apply IHh.
+
replace (
S h +
n)%
nat with (
S (
h+
n))%
nat by lia.
apply H.
Qed.
Lemma ELim_seq_Elim_seq_pair (
f:
nat->
nat->
Rbar) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
ELim_seq
(
fun i :
nat =>
sum_Rbar_n (
fun x0 :
nat =>
ELim_seq (
fun i0 :
nat =>
sum_Rbar_n (
fun n :
nat => (
f x0 n))
i0))
i) =
ELim_seq (
fun i :
nat =>
sum_Rbar_n (
fun n :
nat =>
let '(
a,
b) :=
iso_b (
Isomorphism:=
nat_pair_encoder)
n in (
f a b))
i).
Proof.
Lemma list_Rbar_sum_nneg_nested_prod_swap {
A B:
Type} (
X:
list A) (
Y:
list B) (
f:
A->
B->
Rbar) :
(
forall x y,
In x X ->
In y Y ->
Rbar_le 0 (
f x y)) ->
list_Rbar_sum (
map (
fun xy =>
f (
fst xy) (
snd xy)) (
list_prod X Y)) =
list_Rbar_sum (
map (
fun yx =>
f (
snd yx) (
fst yx)) (
list_prod Y X)).
Proof.
Lemma list_Rbar_sum_nneg_nested_swap {
A B:
Type} (
X:
list A) (
Y:
list B) (
f:
A->
B->
Rbar) :
(
forall x y,
In x X ->
In y Y ->
Rbar_le 0 (
f x y)) ->
list_Rbar_sum (
map (
fun x =>
list_Rbar_sum (
map (
fun y =>
f x y)
Y))
X) =
list_Rbar_sum (
map (
fun y =>
list_Rbar_sum (
map (
fun x =>
f x y)
X))
Y).
Proof.
Lemma list_Rbar_sum_const c l :
list_Rbar_sum (
map (
fun _ :
nat =>
c)
l) =
Rbar_mult c (
INR (
length l)).
Proof.
Lemma sum_Rbar_n0 n :
sum_Rbar_n (
fun _ :
nat => 0)
n = 0.
Proof.
Lemma Elim_seq_sum0 :
ELim_seq (
sum_Rbar_n (
fun _ :
nat => 0)) = 0.
Proof.
Lemma list_Rbar_ELim_seq_nneg_nested_swap {
A:
Type} (
X:
list A) (
f:
A->
nat->
Rbar) :
(
forall a b,
In a X ->
Rbar_le 0 (
f a b)) ->
list_Rbar_sum (
map (
fun x => (
ELim_seq (
sum_Rbar_n (
fun j :
nat => (
f x j)))))
X) =
ELim_seq
(
sum_Rbar_n (
fun i :
nat =>
list_Rbar_sum (
map (
fun x =>
f x i)
X))).
Proof.
Definition swap_num_as_pair (
n:
nat) :=
let '(
a,
b) :=
iso_b (
Isomorphism:=
nat_pair_encoder)
n in
iso_f (
b,
a).
Lemma sum_Rbar_n_iso_swap (
f:
nat->
nat->
Rbar) (
n :
nat) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
exists (
m :
nat),
Rbar_le
(
sum_Rbar_n (
fun n0 :
nat =>
let '(
a,
b) :=
iso_b n0 in f a b)
n)
(
sum_Rbar_n (
fun n0 :
nat =>
let '(
a,
b) :=
iso_b n0 in f b a)
m).
Proof.
intros.
exists (
S (
list_max (
map swap_num_as_pair (
seq 0
n)))).
unfold sum_Rbar_n.
assert (
subl:
exists l,
Permutation (
map iso_b (
seq 0
n))
l /\
sublist l
(
map swap (
map iso_b
(
seq 0 (
S (
list_max
(
map swap_num_as_pair (
seq 0
n)))))))).
{
apply incl_NoDup_sublist_perm.
-
apply iso_b_nodup.
apply seq_NoDup.
-
intros [??] ?.
apply in_map_iff in H0.
destruct H0 as [?[??]].
rewrite in_map_iff.
exists (
n1,
n0).
split.
+
now unfold swap;
simpl.
+
rewrite in_map_iff.
exists (
iso_f (
n1,
n0)).
split.
*
now rewrite iso_b_f.
*
rewrite in_seq.
split.
--
lia.
--
unfold swap_num_as_pair.
assert (
iso_f (
n1,
n0) <=
(
list_max
(
map (
fun n2 :
nat =>
let '(
a,
b) :=
iso_b n2 in iso_f (
b,
a)) (
seq 0
n))))%
nat.
{
generalize (
list_max_upper
(
map (
fun n2 :
nat =>
let '(
a,
b) :=
iso_b n2 in iso_f (
b,
a)) (
seq 0
n)))%
nat;
intros.
rewrite Forall_forall in H2.
apply H2.
rewrite in_map_iff.
exists x.
split;
trivial.
destruct (
iso_b x).
now inversion H0.
}
lia.
}
destruct subl as [? [? ?]].
apply (
Permutation_map (
fun '(
a,
b) =>
f a b))
in H0.
apply (
sublist_map (
fun '(
a,
b) =>
f a b))
in H1.
rewrite (
list_Rbar_sum_nneg_perm
(
map (
fun n1 :
nat =>
let '(
a,
b) :=
iso_b n1 in f a b) (
seq 0
n))
(
map (
fun '(
a,
b) =>
f a b)
x)
);
trivial.
-
apply list_Rbar_sum_pos_sublist_le;
trivial.
+
intros.
rewrite in_map_iff in H2.
destruct H2 as [? [? ?]].
rewrite <-
H2.
now destruct (
iso_b x1).
+
unfold swap in H1.
rewrite map_map,
map_map in H1.
rewrite map_ext with
(
g := (
fun x :
nat =>
f (
snd (
iso_b x)) (
fst (
iso_b x)))).
*
apply H1.
*
intros.
destruct (
iso_b a).
now simpl.
-
rewrite Forall_map,
Forall_forall.
intros.
now destruct (
iso_b x0).
-
rewrite Forall_map,
Forall_forall.
intros.
now destruct x0.
-
now rewrite map_map in H0.
Qed.
Lemma ELim_seq_sum_nneg_nested_swap (
f:
nat->
nat->
Rbar) :
(
forall a b,
Rbar_le 0 (
f a b)) ->
ELim_seq
(
sum_Rbar_n (
fun i :
nat =>
ELim_seq (
sum_Rbar_n (
fun j :
nat => (
f i j))))) =
ELim_seq
(
sum_Rbar_n (
fun i :
nat =>
ELim_seq (
sum_Rbar_n (
fun j :
nat => (
f j i))))).
Proof.
Lemma is_finite_witness (
x :
Rbar) :
is_finite x ->
exists (
r:
R),
x =
Finite r.
Proof.
Lemma is_finite_Elim_seq_nneg_nested (
f:
nat->
nat->
Rbar) :
(
forall a b,
Rbar_le 0(
f a b)) ->
is_finite (
ELim_seq
(
sum_Rbar_n (
fun i :
nat =>
ELim_seq (
sum_Rbar_n (
fun j :
nat => (
f i j)))))) ->
forall i,
is_finite (
ELim_seq (
sum_Rbar_n (
fun j :
nat => (
f i j)))).
Proof.
Lemma ELim_seq_Lim_seq_Rbar (
f :
nat ->
Rbar) :
(
forall n,
is_finite (
f n)) ->
ELim_seq f =
Lim_seq f.
Proof.
Lemma sum_Rbar_n_finite_sum_n f n:
sum_Rbar_n (
fun x =>
Finite (
f x)) (
S n) =
Finite (
sum_n f n).
Proof.
Lemma Lim_seq_sum_Elim f :
Lim_seq (
sum_n f) =
ELim_seq (
sum_Rbar_n (
fun x =>
Finite (
f x))).
Proof.
Lemma Series_nneg_nested_swap (
f:
nat->
nat->
R) :
(
forall a b, 0 <= (
f a b)) ->
is_finite (
ELim_seq
(
sum_Rbar_n (
fun i :
nat =>
ELim_seq (
sum_Rbar_n (
fun j :
nat => (
f i j)))))) ->
Series (
fun i :
nat =>
Series (
fun j :
nat => (
f i j))) =
Series (
fun i :
nat =>
Series (
fun j :
nat => (
f j i))).
Proof.
Lemma lim_seq_sum_singleton_is_one f :
(
forall n1 n2,
n1 <>
n2 ->
f n1 = 0 \/
f n2 = 0) ->
exists n,
Lim_seq (
sum_n f) =
f n.
Proof.
intros.
destruct (
classic (
exists m,
f m <> 0)%
type)
as [[
n ?]|].
-
rewrite <- (
Lim_seq_incr_n _ n).
assert (
eqq:
forall x,
sum_n f (
x +
n) =
f n).
{
intros.
induction x;
simpl.
-
destruct n.
+
now rewrite sum_O.
+
rewrite sum_Sn.
erewrite sum_n_ext_loc;
try rewrite sum_n_zero.
*
unfold plus;
simpl;
lra.
*
intros ??;
simpl.
destruct (
H (
S n)
n0);
try lra.
lia.
-
rewrite sum_Sn,
IHx.
unfold plus;
simpl.
destruct (
H n (
S (
x +
n)));
try lra.
lia.
}
rewrite (
Lim_seq_ext _ _ eqq).
rewrite Lim_seq_const.
eauto.
-
assert (
eqq:
forall x,
sum_n f x = 0).
{
intros.
erewrite sum_n_ext;
try eapply sum_n_zero.
intros ?;
simpl.
destruct (
Req_EM_T (
f n) 0);
trivial.
elim H0;
eauto.
}
rewrite (
Lim_seq_ext _ _ eqq).
rewrite Lim_seq_const.
exists (0%
nat).
f_equal;
symmetry.
destruct (
Req_EM_T (
f 0%
nat) 0);
trivial.
elim H0;
eauto.
Qed.
Lemma lim_seq_sum_singleton_finite f :
(
forall n1 n2,
n1 <>
n2 ->
f n1 = 0 \/
f n2 = 0) ->
is_finite (
Lim_seq (
sum_n f)).
Proof.
End lim_sum.
Section Rmax_list.
Lemma Rmax_list_lim_Sup_seq (
a :
nat ->
R) (
N :
nat) :
Lim_seq (
fun M =>
Rmax_list (
map a (
seq N M))) =
Sup_seq (
fun n0 :
nat =>
a (
n0 +
N)%
nat).
Proof.
Lemma Rmax_list_Sup_seq (
a :
nat ->
R) (
N M :
nat) :
Rbar_le (
Rmax_list (
map a (
seq N (
S M)))) (
Sup_seq (
fun n0 :
nat =>
a (
n0 +
N)%
nat)).
Proof.
End Rmax_list.
Section zeroprop.
Definition zerotails_prop a ϵ
n :
Prop :=
forall N, (
n <=
N)%
nat ->
Rabs (
Series (
fun k =>
a (
S (
N+
k)%
nat))) < ϵ.
Lemma zerotails_witness_pack (
a :
nat ->
R) :
ex_series a ->
forall (ϵ:
posreal), {
n :
nat |
zerotails_prop a ϵ
n /\
forall n',
zerotails_prop a ϵ
n' -> (
n <=
n')%
nat }.
Proof.
Definition zerotails_witness (
a :
nat ->
R)
(
pf:
ex_series a) (ϵ:
posreal) :
nat
:=
proj1_sig (
zerotails_witness_pack a pf ϵ).
Lemma zerotails_witness_prop (
a :
nat ->
R) (
pf:
ex_series a) (ϵ:
posreal) :
forall N, ((
zerotails_witness a pf ϵ) <=
N)%
nat ->
Rabs (
Series (
fun k =>
a (
S N +
k)%
nat)) < ϵ.
Proof.
Lemma zerotails_prop_nondecr a ϵ1 ϵ2
n :
ϵ1 <= ϵ2 ->
zerotails_prop a ϵ1
n ->
zerotails_prop a ϵ2
n.
Proof.
Lemma zerotails_witness_min (
a :
nat ->
R) (
pf:
ex_series a) (ϵ:
posreal) :
forall n', (
forall N, (
n' <=
N)%
nat ->
Rabs (
Series (
fun k =>
a (
S N +
k)%
nat)) < ϵ) ->
((
zerotails_witness a pf ϵ) <=
n')%
nat.
Proof.
Lemma zerotails_witness_nondecr (
a :
nat ->
R) (
pf:
ex_series a) (ϵ1 ϵ2:
posreal) :
ϵ2 <= ϵ1 ->
(
zerotails_witness a pf ϵ1 <=
zerotails_witness a pf ϵ2)%
nat.
Proof.
Definition zerotails_eps2k_fun' (
a :
nat ->
R) (
pf:
ex_series a) (
k:
nat) :
nat
:=
zerotails_witness a pf (
inv_2_pow_posreal k).
Definition zerotails_eps2k_fun (
a :
nat ->
R) (
pf:
ex_series a) (
k:
nat) :
nat
:=
zerotails_eps2k_fun'
a pf k +
k.
Lemma zerotails_eps2k_fun_shifted_bound (
a :
nat ->
R) (
pf:
ex_series a) (
k:
nat)
:
Rabs (
Series (
fun x =>
a (
S (
x+ (
zerotails_eps2k_fun a pf k)%
nat)))) < (/ (2 ^
k)).
Proof.
Lemma zerotails_eps2k_double_sum_ex (
a :
nat ->
R) (
pf:
ex_series a) :
ex_series (
fun k =>
Series (
fun x =>
a (
S (
x+ (
zerotails_eps2k_fun a pf k)%
nat)))).
Proof.
Lemma zerotails_eps2k_fun'
_nondecr a pf n :
((
zerotails_eps2k_fun'
a pf n) <= (
zerotails_eps2k_fun'
a pf (
S n)))%
nat.
Proof.
Lemma zerotails_incr_mult_strict_incr a pf n :
((
zerotails_eps2k_fun a pf n) < (
zerotails_eps2k_fun a pf (
S n)))%
nat.
Proof.
Lemma zerotails_incr_mult_strict_incr_lt a pf m n :
(
m <
n)%
nat ->
((
zerotails_eps2k_fun a pf m) < (
zerotails_eps2k_fun a pf n))%
nat.
Proof.
Definition zerotails_incr_mult (
a :
nat ->
R) (
pf:
ex_series a)
n :
R
:=
Series (
fun n0 :
nat =>
if le_dec (
S (
zerotails_eps2k_fun a pf n0))
n then 1
else 0).
Lemma zerotails_incr_mult_ex (
a :
nat ->
R) (
pf:
ex_series a)
n :
ex_series (
fun n0 :
nat =>
if le_dec (
S (
zerotails_eps2k_fun a pf n0))
n then 1
else 0).
Proof.
Lemma zerotails_incr_mult_trunc (
a :
nat ->
R) (
pf:
ex_series a)
n :
zerotails_incr_mult a pf n =
sum_n (
fun n0 :
nat =>
if le_dec (
S (
zerotails_eps2k_fun a pf n0))
n then 1
else 0)
n.
Proof.
Lemma zerotails_eps2k_fun_unbounded a pf :
forall m,
exists k, (
m < (
zerotails_eps2k_fun a pf k))%
nat.
Proof.
Lemma zerotails_incr_mult_incr a pf n :
exists m, (
n <
m)%
nat /\
zerotails_incr_mult a pf n + 1 <=
zerotails_incr_mult a pf m.
Proof.
Lemma zerotails_incr_mult_unbounded_nat a pf M :
exists m, (
INR M <=
zerotails_incr_mult a pf m).
Proof.
Lemma zerotails_incr_mult_incr_incr a pf x n :
(
x <=
n)%
nat ->
((
zerotails_incr_mult a pf x) <= (
zerotails_incr_mult a pf n)).
Proof.
Lemma zerotails_incr_mult_unbounded (
a :
nat ->
R) (
pf:
ex_series a) :
is_lim_seq (
zerotails_incr_mult a pf)
p_infty.
Proof.
Lemma zerotails_eps2k_double_sum_finite (
a :
nat ->
R) (
pf:
ex_series a) {
anneg:
forall x, 0 <=
a x}:
is_finite
(
ELim_seq
(
sum_Rbar_n
(
fun i :
nat =>
ELim_seq
(
sum_Rbar_n
(
fun x :
nat =>
a (
S (
x+ (
zerotails_eps2k_fun a pf i)%
nat))))))).
Proof.
Lemma zerotails_eps2k_double_sum_eq (
a :
nat ->
R) (
pf:
ex_series a) {
anneg:
forall x, 0 <=
a x}:
Series (
fun k =>
Series (
fun x =>
a (
S (
x+ (
zerotails_eps2k_fun a pf k)%
nat)))) =
Series (
fun n =>
zerotails_incr_mult a pf n * (
a n)).
Proof.
End zeroprop.
Lemma ELimSup_ELim_seq_le f :
Rbar_le (
ELim_seq f) (
ELimSup_seq f).
Proof.
Lemma ELimInf_ELim_seq_le f :
Rbar_le (
ELimInf_seq f) (
ELim_seq f).
Proof.