intros. induction n. elimtype False; intuition.
unfold nsum in |- *. fold nsum in |- *.
elim (classic (i =' Build_finiteT (lt_O_Sn n) in _)).
intro I_ZERO.
assert (P1 : head (modify_seq v i a) =' a in _).
apply Trans with (head (modify_seq v (Build_finiteT (lt_O_Sn n)) a)).
apply head_comp. apply modify_comp. apply Refl. apply Refl. exact I_ZERO.
apply modify_hd_hd.
rewrite P1.
assert (P2 : nsum n (Seqtl (modify_seq v i a)) =' nsum n (Seqtl v) in _).
apply nsum_comp.
apply Trans with (Seqtl (modify_seq v (Build_finiteT (lt_O_Sn n)) a)).
change (Seqtl (modify_seq v i a)
=' Seqtl (modify_seq v (Build_finiteT (lt_O_Sn n)) a) in _) in |- *.
apply Seqtl_comp. apply modify_comp. apply Refl. apply Refl. exact I_ZERO.
change (Seqtl (modify_seq v (Build_finiteT (lt_O_Sn n)) a)
=' Seqtl v in _) in |- *. apply modify_hd_tl.
rewrite P2.
rewrite H.
assert (P3 : v i =' head v in _).
unfold head in |- *. apply Map_compatible_prf. exact I_ZERO.
rewrite P3.
rewrite plus_comm. rewrite plus_permute. rewrite plus_assoc. apply Refl.
intro I_NZ.
assert (P4 : head (modify_seq v i a) =' head v in _).
destruct i.
assert (H''' : S (pred index) < S n).
induction index. elimtype False; intuition. auto.
apply Trans with (head (modify_seq v (Build_finiteT H''') a)).
apply head_comp. apply modify_comp. apply Refl. apply Refl. simpl in |- *.
induction index. elimtype False; intuition. auto.
apply modify_tl_hd.
rewrite P4.
assert(P10:nsum n (Seqtl(modify_seq v i a)) =' nsum n (Seqtl v)+1 in _).
destruct i.
assert (H' : pred index < n).
induction index. elimtype False; intuition.
simpl in |- *. apply lt_S_n. exact in_range_prf.
assert (H'' : S (pred index) < S n).
apply lt_n_S. exact H'.
apply Trans with (nsum n (Seqtl (modify_seq v (Build_finiteT H'') a))).
apply nsum_comp.
change (Seqtl (modify_seq v (Build_finiteT in_range_prf) a)
=' Seqtl (modify_seq v (Build_finiteT H'') a) in _) in |- *.
apply Seqtl_comp. apply modify_comp. apply Refl. apply Refl. simpl in |- *.
induction index. elimtype False; intuition. auto.
apply Trans with (nsum n (modify_seq (Seqtl v) (Build_finiteT H') a)).
apply nsum_comp. apply modify_tl_tl with (v := v).
apply IHn.
rewrite H. apply pluscomp2. apply Trans with (v (Build_finiteT H'')).
apply Map_compatible_prf. simpl in |- *.
induction index. elimtype False; intuition. auto.
apply Sym.
change (Seqtl v (Build_finiteT H') =' v (Build_finiteT H'') in _) in |- *.
apply Seqtl_to_seq.
rewrite P10. rewrite plus_assoc. apply Refl. Qed.

(* Specifications: *)
Lemma nsum_of_zeros:forall(n:Nat)(v:seq n Nat)
(Z:forall i:fin n,v i =' 0),nsum n v =' 0.