(* Ravg *)

Definition Ravg (l: list R): R := Rsum l / INR (length l).

(* Specifications: *)
Lemma Ravg_nil: Ravg nil = 0.
Lemma Ravg_one h: Ravg (h :: nil) = h.
Lemma Ravg_cons h t: Ravg (h :: t) = (h + Ravg t * INR (length t)) / INR (S (length t)).
Lemma Ravg_0_le l: (forall x, In x l -> 0 <= x) -> 0 <= Ravg l.
Lemma Ravg_0 (l: list R): (forall x, In x l -> x = 0) -> Ravg l = 0.
Lemma Ravg_app x y: Ravg (x ++ y) = / INR (length x + length y) * (Ravg x * INR (length x) + Ravg y * INR (length y)).
Lemma Ravg_0_inv (l: list R): Ravg l = 0 -> (forall x, In x l -> 0 <= x) -> forall x, In x l -> x = 0.
Lemma Ravg_comp_map X (f: X -> R) (m: list X -> R) (g: R -> R): (forall a b, g (a * b) = g a * b) -> (forall l, g (Rsum l) = Rsum (map g l)) -> (forall l: list X, Ravg (map f l) = g (m l)) -> forall u, Ravg (map (fun l => Ravg (map f l)) u) = g (Ravg (map m u)).
Lemma Ravg_concat v x: (forall l, In l x -> length l = v) -> Ravg (concat x) = Ravg (map Ravg x).
Lemma Ravg_map_plus X f g (l: list X): Ravg (map (fun x => f x + g x) l) = Ravg (map f l) + Ravg (map g l).
Lemma Ravg_constant l: l <> nil -> forall v, (forall x, In x l -> x = v) -> Ravg l = v.
Lemma Ravg_map_le X (f g: X -> R) (l: list X): (forall x, In x l -> f x <= g x) -> Ravg (map f l) <= Ravg (map g l).
Lemma Ravg_single x: Ravg (x :: nil) = x.