(* 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.
intros.
induction  n as [| n Hrecn].
simpl in |- *.
apply Refl.
unfold sum at 1 in |- *.
apply SGROUP_comp; auto with algebra.
apply sum_comp.
generalize dependent (Seqtl_cons_inv m f); intro p.
apply p.
Qed.
Hint Resolve sum_cons: algebra.

Lemma sum_concat :
forall (n m : Nat) (G : monoid) (a : seq n G) (b : seq m G),
sum (a ++ b) =' sum a +' sum b in _.