Section MAIN.
Variable A : Setoid.
Variable n m : Nat.
Variable v : seq n A.
Variable w : seq m A.
(** - More facts about concatenation *)
induction n.
intros.
inversion Hi.
intro.
case i.
unfold concat in |- *.
unfold nat_rect in |- *.
simpl in |- *.
intros.
apply Ap_comp; auto with algebra.
intros.
apply Trans with (hdtl v (Build_finiteT Hi)).
apply Trans with ((hdtl v ++ w) (Build_finiteT Hi')).
apply concat_comp; auto with algebra.
2: apply Ap_comp; auto with algebra.
unfold hdtl in |- *.
apply Trans with ((head v;; Seqtl v ++ w) (Build_finiteT Hi'));
auto with algebra.
apply Trans with (Seqtl v (Build_finiteT (lt_S_n _ _ Hi))); auto with algebra.
apply Trans with ((Seqtl v ++ w) (Build_finiteT (lt_S_n _ _ Hi')));
auto with algebra.
Qed.
Hint Resolve concat_first_part: algebra.
induction n.
intros.
unfold concat in |- *.
unfold nat_rect in |- *.
apply Ap_comp; auto with algebra.
intros.
apply Trans with ((hdtl v ++ w) (Build_finiteT Hi')); auto with algebra.
unfold hdtl in |- *.
apply Trans with ((head v;; Seqtl v ++ w) (Build_finiteT Hi'));
auto with algebra.
cut (S (c + i) < S (c + m)).
intro.
apply Trans with ((Seqtl v ++ w) (Build_finiteT (lt_S_n _ _ H)));
auto with algebra.
apply Trans with ((head v;; Seqtl v ++ w) (Build_finiteT H));
auto with algebra.
replace (S (c + i)) with (S c + i).
assumption.
auto.
Qed.
Hint Resolve concat_second_part: algebra.
induction n.
intros.
unfold concat in |- *; unfold nat_rect in |- *.
apply H0.
intros.
generalize Hk; clear Hk; case k; [ intro Hk | intros k0 Hk0 ].
generalize (lt_O_Sn c); intro Hk'.
apply (Pred_compatible_prf (p:=P)) with (v (Build_finiteT Hk'));
auto with algebra.
simpl in |- *.
apply Ap_comp; auto with algebra.
generalize (lt_S_n _ _ Hk0); intro Hk0'.
fold (c + m) in Hk0'.
apply (Pred_compatible_prf (p:=P)) with ((Seqtl v ++ w) (Build_finiteT Hk0')).
apply IHc; auto with algebra.
clear Hk0' Hk0 k0 k.
intros.
apply (Pred_compatible_prf (p:=P)) with (v (Build_finiteT (lt_n_S _ _ Hi)));
auto with algebra.
apply Trans with (Seqtl (v ++ w) (Build_finiteT Hk0')).
apply Sym.
generalize Seqtl_to_seq.
intros.
apply (H1 _ _ (v ++ w) _ Hk0' Hk0).
generalize Seqtl_concat.
intro p.
apply Ap_comp; auto with algebra.
Qed.

Lemma concat_prop_per_element :
forall P : Predicate A,
(forall (i : Nat) (Hi : i < n) (Hi' : i < n + m),
Pred_fun P ((v ++ w) (Build_finiteT Hi'))) ->
(forall (j : Nat) (Hj : j < m) (Hj' : n + j < n + m),
Pred_fun P ((v ++ w) (Build_finiteT Hj'))) ->
forall (k : Nat) (Hk : k < n + m), Pred_fun P ((v ++ w) (Build_finiteT Hk)).