(* 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.
intros.
generalize (seq_equal_length_equal H).
generalize (seq_equal_length_equal H0).
intros.
red in |- *.
intro.
generalize (le_or_lt (n + p) i).
intro.
case H3.
right.
split; try tauto.
rewrite <- H1.
rewrite <- H2.
tauto.
intro.
left.
exists H4.
assert (i < m + q).
rewrite <- H1.
rewrite <- H2.
tauto.
exists H5.
generalize (le_or_lt n i).
intro.
case H6; clear H6; intro.
2: assert (i < m).
2: rewrite <- H2.
2: auto.
2: apply Trans with (v (Build_finiteT H6)); auto with algebra.
2: apply Trans with (w (Build_finiteT H7)); auto with algebra.
assert (exists k : Nat, i =' n + k in _).
exists (i - n).
simpl in |- *; symmetry  in |- *.
auto with arith.
inversion_clear H7.
assert (n + x < n + p).
rewrite <- H8.
auto.
assert (m + x < m + q).
rewrite <- H2.
rewrite <- H1.
auto.
apply Trans with ((v ++ a) (Build_finiteT H7)); auto with algebra.
apply Trans with ((w ++ b) (Build_finiteT H9)).
2: apply Ap_comp; auto with algebra.
2: simpl in |- *.
2: symmetry  in |- *.
2: rewrite <- H2.
2: auto.
assert (x < p).
apply plus_lt_reg_l with n; auto with algebra.
apply Trans with (a (Build_finiteT H10)); auto with algebra.
assert (x < q).
rewrite <- H1.
auto.
apply Trans with (b (Build_finiteT H11)); auto with algebra.
Qed.
Hint Resolve seq_equal_concat: algebra.

Lemma seq_equal_seq_set :
forall (A : Setoid) (n m : Nat) (v : seq n A) (w : seq m A),
seq_equal v w -> seq_set v =' seq_set w in _.