(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
(** %\subsection*{ support :  sums.v }%*)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export Map_embed.
Require Export algebra_omissions.
From Algebra Require Export Sub_monoid.
Require Export more_syntax.
(** - A sequence of v1...vn of elements in a monoid V is a map (fin n)->V. We define the sum of a sequence of these elements. Of course we take the sum of an empty sequence to be zero  %\label{sum}% *)
Fixpoint sum (V : monoid) (n : Nat) {struct n} : seq n V -> V :=
match n return (seq n V -> V) with
| O => fun x : seq 0 V => zero V
| S m => fun x : seq (S m) V => head x +' sum (Seqtl x)
end.
induction n.
intros.
simpl in |- *.
apply Refl.
intros.
unfold sum in |- *.
apply SGROUP_comp; auto with algebra.
apply IHn.
change (Seqtl f =' Seqtl f' in _) in |- *.
apply Seqtl_comp; auto with algebra.
Qed.
Hint Resolve sum_comp: algebra.

Lemma sum_cons :
forall (M : monoid) (m : M) (n : Nat) (f : seq n M),
sum (m;; f) =' m +' sum f in _.