(* 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.v }%*)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export cast_seq_lengths.
(** - We cannot compare v++w and w++v using =' since they have non-convertible lengths (n+k $v.$ k+n) and hence are judged to stem from different setoids. We have two complementing ways of dealing with sequences of equal but non-convertible lengths: one is using casting functions (see cast_seq_lengths.v), the other is defining a different equality predicate for sequences: seq_equal. Two sequences v:(seq n A) and w:(seq k A) are seq_equal if every i:nat is either out of both sequences' bounds (ie. $i\geq n$ and $i\geq k$), or there exist proofs that we can use to turn i into a (fin n) and (fin k), so that "v(i)=w(i)"  %\label{seqequal}% *)
Definition seq_equal (A : Setoid) (n m : Nat) (v : seq n A)
(w : seq m A) :=
forall i : Nat,
(exists p : i < n,
(exists q : i < m, v (Build_finiteT p) =' w (Build_finiteT q) in _)) \/
n <= i /\ m <= i.
intros.
red in |- *.
intro.
generalize (le_or_lt n i).
intro p; inversion_clear p.
right; split; auto.
left.
repeat exists H0.
simpl in H; red in H; simpl in H; apply H.
Qed.
(** - And the other way around, if v and w happen to have the same type *)

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