(* 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                                                     *)
(* correction d'un preDTA : pas de référence à des adresses extérieures à l'automate *)
Definition prec_list_ref_ok (p : prec_list) (d : preDTA) : Prop :=
forall a : ad,
prec_occur p a -> exists s : state, MapGet state d a = Some s.
Definition state_ref_ok (s : state) (d : preDTA) : Prop :=
forall (a : ad) (p : prec_list),
MapGet prec_list s a = Some p -> prec_list_ref_ok p d.
Definition preDTA_ref_ok (d : preDTA) : Prop :=
forall (a : ad) (s : state) (c : ad) (pl : prec_list) (b : ad),
MapGet state d a = Some s ->
MapGet prec_list s c = Some pl ->
prec_occur pl b -> exists s0 : state, MapGet state d b = Some s0.
Definition preDTA_ref_ok_distinct (d d' : preDTA) : Prop :=
forall (a : ad) (s : state),
MapGet state d a = Some s -> state_ref_ok s d'.
Definition DTA_ref_ok (d : DTA) : Prop :=
match d with
| dta p a => preDTA_ref_ok p
end.
(* une fonction permettant de décider la propriété preDTA_ref_ok *)
Definition addr_in_dta_check (d : preDTA) (a : ad) : bool :=
match MapGet state d a with
| None => false
| Some _ => true
end.
Fixpoint prec_list_ref_ok_check (p : prec_list) : preDTA -> bool :=
fun d : preDTA =>
match p with
| prec_empty => true
| prec_cons a la ls =>
addr_in_dta_check d a &&
(prec_list_ref_ok_check la d && prec_list_ref_ok_check ls d)
end.
Fixpoint state_ref_ok_check (s : state) : preDTA -> bool :=
fun d : preDTA =>
match s with
| M0 => true
| M1 a p => prec_list_ref_ok_check p d
| M2 x y => state_ref_ok_check x d && state_ref_ok_check y d
end.

Lemma state_ref_ok_check_complete :
forall (s : state) (d : preDTA),
state_ref_ok_check s d = true -> state_ref_ok s d.