Section contents.
Variables (m: Monoid) (ms: m -> nat).
About MonoidMonadTrans.M .
Definition monoid_expec {A: Set}:
MonoidMonadTrans.M m ne_tree_monad.ext A -> R
:= expec (ms ∘ (fst (B:=_:Set))).
Hypothesis mh: monoidHomo m NatAddMonoid ms.
Definition monoid_expec_sum (T U: Set)
(g: T -> MonoidMonadTrans.M m ne_tree_monad.ext U): list T -> R
:= Rsum ∘ map (monoid_expec ∘ g).
Proof with auto.
unfold monoid_expec_sum.
intros.
intro.
unfold compose.
f_equal.
apply map_ext.
intro.
f_equal.
apply H.
Qed.
Proof with auto.
unfold monoid_expec, monoid_expec_sum.
intros.
rewrite expec_Node.
rewrite ne_list.map_map.
unfold Ravg.
rewrite ne_list.map_length.
unfold monoid_expec.
rewrite ne_list.plain_map...
Qed.
Proof with auto.
intros.
simpl.
unfold monoid_expec.
unfold expec, compose.
simpl.
rewrite (monoidHomo_zero mh)...
Qed.
Proof with auto.
intros.
rewrite monoid_expec_bind_leaf.
unfold monoid_expec.
rewrite (@expec_ext _ (ms ∘ monoid_mult m (fst n) ∘ fst (A:=m) (B:=Y)) (plus (ms (fst n)) ∘ ms ∘ fst)).
rewrite <- comp_ass.
rewrite (ext_eq_rw (expec_plus_c (ms ∘ fst (A:=m) (B:=Y)) (ms (fst n)))).
reflexivity.
intro.
repeat rewrite comp_apply.
apply (monoidHomo_mult mh).
Qed.
Proof with auto with real.
intros.
rewrite H.
rewrite monoid_expec_bind_leaf_plus.
unfold monoid_expec.
rewrite expec_Leaf.
reflexivity.
Qed.
Hint Resolve ne_tree.In_head.

Lemma monoid_expec_plus (A B: Set)
(f: MonoidMonadTrans.M m ne_tree_monad.ext A)
(g: A -> MonoidMonadTrans.M m ne_tree_monad.ext B) :
forall (gc: forall x y, ne_tree.In x f -> ne_tree.In y f ->
monoid_expec (g (snd x)) = monoid_expec (g (snd y))),
monoid_expec (f >>= g) = monoid_expec f + monoid_expec (g (snd (ne_tree.head f))).