(* 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                                                     *)
(* définition inductive du type des termes : *)
Inductive term : Set :=
app : ad -> term_list -> term
with term_list : Set :=
| tnil : term_list
| tcons : term -> term_list -> term_list.
(* les principes d'induction *)
Scheme term_term_list_rec := Induction for term
Sort Set
with term_list_term_rec := Induction for term_list
Sort Set.
Scheme term_term_list_ind := Induction for term
Sort Prop
with term_list_term_ind := Induction for term_list
Sort Prop.
Fixpoint lst_length (l : term_list) : nat :=
match l with
| tnil => 0
| tcons _ l' => S (lst_length l')
end.
Fixpoint term_high (t : term) : nat :=
match t with
| app a l => S (term_high_0 l)
end
with term_high_0 (l : term_list) : nat :=
match l with
| tnil => 0
| tcons hd tl => max (term_high hd) (term_high_0 tl)
end.
(* taille des termes : *)
Fixpoint taille_term (t : term) : nat :=
match t with
| app c l => S (mtaille_term_list l)
end
with mtaille_term_list (l : term_list) : nat :=
match l with
| tnil => 0
| tcons hd tl => max (taille_term hd) (mtaille_term_list tl)
end.
(* définition des structures prec_list : adjacence des états de l'automate *)
Inductive prec_list : Set :=
| prec_cons : ad -> prec_list -> prec_list -> prec_list
| prec_empty : prec_list.
(* définition des états *)
Definition state := Map prec_list.
(* définition des automates *)
Definition preDTA := Map state.
Inductive DTA : Set :=
dta : preDTA -> ad -> DTA.
(* calcul de la taille de l'automate : *)
Fixpoint taille_0 (l : prec_list) : nat :=
match l with
| prec_empty => 0
| prec_cons x y z => S (taille_0 y + taille_0 z)
end.
Fixpoint taille_1 (s : state) : nat :=
match s with
| M0 => 0
| M1 x y => taille_0 y
| M2 x y => max (taille_1 x) (taille_1 y)
end.
Fixpoint DTA_taille (d : preDTA) : nat :=
match d with
| M0 => 0
| M1 x y => taille_1 y
| M2 x y => max (DTA_taille x) (DTA_taille y)
end.
(* relation d'une adresse d'occurence dans les prec_list *)
Inductive prec_occur : prec_list -> ad -> Prop :=
| prec_hd :
forall (a : ad) (pl0 pl1 : prec_list),
prec_occur (prec_cons a pl0 pl1) a
| prec_int0 :
forall (a b : ad) (pl0 pl1 : prec_list),
prec_occur pl0 b -> prec_occur (prec_cons a pl0 pl1) b
| prec_int1 :
forall (a b : ad) (pl0 pl1 : prec_list),
prec_occur pl1 b -> prec_occur (prec_cons a pl0 pl1) b.
(* relation de "contenu" pour les prec_list *)
Inductive prec_contained : prec_list -> prec_list -> Prop :=
| prec_id : forall p : prec_list, prec_contained p p
| prec_c_int0 :
forall (p p0 p1 : prec_list) (a : ad),
prec_contained p p0 -> prec_contained p (prec_cons a p0 p1)
| prec_c_int1 :
forall (p p0 p1 : prec_list) (a : ad),
prec_contained p p1 -> prec_contained p (prec_cons a p0 p1).
(* définition de l'appartenance d'un état à un pre dta *)
Definition state_in_dta (d : preDTA) (s : state) : Prop :=
exists a : ad, MapGet state d a = Some s.
Definition state_in_dta_diff (d : preDTA) (s : state)
(a : ad) : Prop := exists b : ad, MapGet state d b = Some s /\ a <> b.
(* définition de l'appartenance d'une adjacence à un pre dta *)
Definition prec_in_dta (d : preDTA) (p : prec_list) : Prop :=
exists s : state,
(exists a : ad,
(exists c : ad,
MapGet state d a = Some s /\
MapGet prec_list s c = Some p)).
Definition prec_in_dta_cont (d : preDTA) (p : prec_list) : Prop :=
exists s : state,
(exists b : ad,
(exists c : ad,
(exists p0 : prec_list,
MapGet state d b = Some s /\
MapGet prec_list s c = Some p0 /\ prec_contained p p0))).
Definition prec_in_dta_diff (d : preDTA) (p : prec_list)
(a : ad) : Prop :=
exists s : state,
(exists b : ad,
(exists c : ad,
MapGet state d b = Some s /\
MapGet prec_list s c = Some p /\ a <> b)).
Definition prec_in_dta_diff_cont (d : preDTA) (p : prec_list)
(a : ad) : Prop :=
exists s : state,
(exists b : ad,
(exists c : ad,
(exists p0 : prec_list,
MapGet state d b = Some s /\
MapGet prec_list s c = Some p0 /\
prec_contained p p0 /\ a <> b))).
(* définition de l'appartenance d'une adjacence à un etat *)
Definition prec_in_state (s : state) (p : prec_list) : Prop :=
exists c : ad, MapGet prec_list s c = Some p.
(* lemmes sur prec_occur, contained : *)

Lemma prec_contained_1 :
forall (a : ad) (p0 p1 p2 : prec_list),
prec_contained (prec_cons a p0 p1) p2 -> prec_contained p1 p2.