(* 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                                                     *)
(* une relation de compatibilité entre automates *)
Definition pl_compat (pl0 pl1 : prec_list) : Prop :=
pl0 = prec_empty /\ pl1 = prec_empty \/
pl0 <> prec_empty /\ pl1 <> prec_empty.
Definition mpl_compat (s0 s1 : state) : Prop :=
forall (c : ad) (p0 p1 : prec_list),
MapGet prec_list s0 c = Some p0 ->
MapGet prec_list s1 c = Some p1 -> pl_compat p0 p1.
Definition dta_correct (d : preDTA) : Prop :=
forall (s0 s1 : state) (a0 a1 : ad),
MapGet state d a0 = Some s0 ->
MapGet state d a1 = Some s1 -> mpl_compat s0 s1.
Definition dta_compat (d0 d1 : preDTA) : Prop :=
forall (s0 s1 : state) (a0 a1 : ad),
MapGet state d0 a0 = Some s0 ->
MapGet state d1 a1 = Some s1 -> mpl_compat s0 s1.
Definition DTA_compat (d0 d1 : DTA) : Prop :=
match d0, d1 with
| dta p0 a0, dta p1 a1 => dta_compat p0 p1
end.
(* débuts des lemmes mpl_compat, suite dans le fichier union.v *)
(* relation de compatibilité symètrique... *)
(* longueur des termes pouvant etre reconnus par une prec_list donnée *)
Inductive pl_tl_length : prec_list -> nat -> Prop :=
| pl_tl_O : pl_tl_length prec_empty 0
| pl_tl_S :
forall (a : ad) (pl : prec_list) (n : nat),
pl_tl_length pl n -> pl_tl_length (prec_cons a pl prec_empty) (S n)
| pl_tl_propag :
forall (a : ad) (la ls : prec_list) (n : nat),
pl_tl_length la n ->
pl_tl_length ls (S n) -> pl_tl_length (prec_cons a la ls) (S n).
Definition pl_tl_length_rec_def_0 (n : nat) :=
forall (d : preDTA) (pl : prec_list) (tl : term_list),
pl_tl_length pl n -> liste_reconnait d pl tl -> n = lst_length tl.
Definition pl_tl_length_rec_def_1 (d : preDTA) (pl : prec_list)
(tl : term_list) :=
forall n : nat,
pl_tl_length_rec_def_0 n ->
pl_tl_length pl (S n) -> liste_reconnait d pl tl -> S n = lst_length tl.
(* nouvelles définitions (plus stricte) de compatibilité entre automates, états... *)
Definition pl_compatible (pl0 pl1 : prec_list) : Prop :=
exists n : nat, pl_tl_length pl0 n /\ pl_tl_length pl1 n.
Definition st_compatible (s0 s1 : state) : Prop :=
forall (c : ad) (pl0 pl1 : prec_list),
MapGet prec_list s0 c = Some pl0 ->
MapGet prec_list s1 c = Some pl1 -> pl_compatible pl0 pl1.
Definition predta_compatible (d0 d1 : preDTA) : Prop :=
forall s0 s1 : state,
state_in_dta d0 s0 -> state_in_dta d1 s1 -> st_compatible s0 s1.
Definition dta_compatible (d0 d1 : DTA) : Prop :=
match d0, d1 with
| dta p0 a0, dta p1 a1 => predta_compatible p0 p1
end.

Lemma pl_compatible_cons_r :
forall (p : prec_list) (a : ad) (la ls : prec_list),
pl_compatible p (prec_cons a la ls) ->
exists a0 : ad,
(exists la0 : prec_list,
(exists ls0 : prec_list, p = prec_cons a0 la0 ls0)).