Set Implicit Arguments.
Plus List Permutation Arith Relations RelationClasses Morphisms
arith_lems util list_utils nat_seqs Omega.
(* sum *)
Fixpoint sum (l: list nat): nat :=
match l with
| nil => 0
| h :: t => h + sum t
end.
Open Scope R_scope.
(* Rsum *)
Definition Rsum: list R -> R := fold_right Rplus 0.
Proof with auto.
induction l...
simpl.
intros.
rewrite plus_INR.
rewrite H...
rewrite IHl...
Qed.
Instance Rsum_Permutation: Proper (Permutation ==> eq) Rsum.
Proof with auto.
intros x y p.
induction p...
simpl.
rewrite IHp...
simpl.
do 2 rewrite <- Rplus_assoc.
rewrite (Rplus_comm y)...
rewrite IHp1...
Qed.
Proof with auto with real.
induction x...
simpl.
intros.
rewrite IHx...
Qed.
Proof with auto.
induction l; intros.
simpl.
field.
simpl Rsum.
simpl @length.
rewrite IHl.
rewrite (H a).
rewrite S_INR.
field.
left...
intros.
apply H.
right...
Qed.
Proof with auto with real.
induction l...
simpl @length.
intros.
simpl Rsum.
apply Rle_trans with (a + INR (length l) * r).
apply Rplus_le_compat_l.
apply IHl.
intros.
apply H.
right...
apply Rle_trans with (r + INR (length l) * r).
apply Rplus_le_compat_r.
firstorder.
simpl @length.
rewrite S_INR.
rewrite Rmult_plus_distr_r.
rewrite Rmult_1_l...
Qed.
Proof with auto with real.
induction l; intros.
simpl.
rewrite Rmult_0_l...
simpl @length.
simpl Rsum.
rewrite S_INR.
rewrite Rmult_plus_distr_r.
rewrite Rmult_1_l.
rewrite Rplus_comm.
apply Rplus_le_compat.
apply H.
left...
apply IHl.
intros.
apply H.
right...
Qed.
Proof with try field.
induction l; simpl...
rewrite IHl...
Qed.
Proof with auto with real.
intros.
rewrite map_app.
rewrite Rsum_app.
rewrite Rsum_map_plus.
do 2 rewrite map_map.
reflexivity.
Qed.
Instance elemsR_le_Rsum: Proper (elemsR Rle ==> Rle) Rsum.
Proof with auto with real.
repeat intro.
induction H...
simpl...
Qed.
Proof with field.
unfold ext_eq, Basics.compose.
induction n; intros.
simpl...
simpl Rsum.
rewrite S_INR.
rewrite IHn...
Qed.
Proof with auto with real.
induction l...
simpl.
rewrite Rsum_app.
congruence.
Qed.
(* Things like the three lemmas above are more elegantly stated as extensional equalities on function compositions, but stated that way they cannot be easily rewritten with.. *)
Proof with auto with real.
induction l...
intros.
simpl.
apply Rplus_le_le_0_compat; intuition.
Qed.
Proof with auto.
unfold RsumOver.
intros.
rewrite <- (map_length f l).
apply Rsum_le...
intros.
destruct (In_map_inv H0).
destruct H1.
subst...
Qed.

Lemma nats_plusb b b' w: nats (b + b') w = map (plus b) (nats b' w).