(* 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 :  seq\_equality\_facts.v }%*)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export seq_equality.
Require Export concat_facts.
Require Export omit.
Require Export Classical_Prop.
(** - Some useful lemmas concerning seq_equal *)
intros.
red in H.
apply NNPP; intro.
assert (n < m \/ m < n).
apply nat_total_order; auto with algebra.
inversion_clear H1.
generalize (H n); clear H; intro.
inversion_clear H.
inversion_clear H1.
apply (lt_irrefl n); auto with algebra.
inversion_clear H1.
apply (lt_not_le n m); auto with algebra.
generalize (H m); clear H; intro.
inversion_clear H.
inversion_clear H1.
inversion_clear H.
apply (lt_irrefl m); auto with algebra.
inversion_clear H1.
apply (le_not_lt n m); auto with algebra.
Qed.
Hint Resolve seq_equal_length_equal: algebra.
intros.
red in H.
destruct i.
rename index into i.
destruct j.
rename index into j.
simpl in H0.
case (H i); clear H; intros.
inversion_clear H.
inversion_clear H1.
apply Trans with (v (Build_finiteT x)); auto with algebra.
apply Trans with (w (Build_finiteT x0)); auto with algebra.
inversion_clear H.
apply False_ind.
apply (le_not_lt n i); auto with algebra.
Qed.
Hint Resolve seq_equal_equal_elements: algebra.
intros.
red in H.
case (H 0); clear H; intros.
inversion_clear H; inversion_clear H0.
apply Trans with (v (Build_finiteT x)); auto with algebra.
apply Trans with (w (Build_finiteT x0)); auto with algebra.
inversion_clear H; inversion_clear H0.
Qed.
Hint Resolve seq_equal_head: algebra.
intros.
destruct n.
red in |- *.
intro.
right.
split; simpl in |- *; auto with arith.
assert (0 = m).
apply seq_equal_length_equal with A v w; auto with algebra.
rewrite <- H0.
simpl in |- *; auto with arith.
destruct m as [| n0].
assert (S n = 0).
apply seq_equal_length_equal with A v w; auto with algebra.
inversion_clear H0.
red in H.
red in |- *.
simpl in |- *.
intro; case (H (S i)); clear H; intros.
inversion_clear H; inversion_clear H0.
left.
exists (lt_S_n _ _ x).
exists (lt_S_n _ _ x0).
apply Trans with (v (Build_finiteT x)); auto with algebra.
apply Trans with (w (Build_finiteT x0)); auto with algebra.
right.
inversion_clear H.
split; auto with arith.
Qed.
Hint Resolve seq_equal_seqtl: algebra.
intros.
assert (n =' m in _).
apply (seq_equal_length_equal (v:=v) (w:=w)); auto with algebra.
red in |- *.
intro.
destruct i as [| n0].
left.
exists (lt_O_Sn n).
exists (lt_O_Sn m).
simpl in |- *.
auto.
case (le_or_lt (S n) (S n0)).
intro.
right.
split; auto.
rewrite <- H1.
auto.
left.
exists H2.
assert (S n0 < S m).
rewrite <- H1.
auto.
exists H3.
simpl in |- *.
apply seq_equal_equal_elements; auto with algebra.
Qed.
Hint Resolve seq_equal_cons: algebra.

Lemma seq_equal_concat :
forall (A : Setoid) (n m p q : Nat) (v : seq n A)
(w : seq m A) (a : seq p A) (b : seq q A),
seq_equal v w -> seq_equal a b -> seq_equal (v ++ a) (w ++ b).