(* 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 des fonctions de modification des adresses *)
Definition uad_conv_0 (a : ad) : ad :=
match a with
| N0 => N0
| Npos p => Npos (xO p)
end.
Definition uad_conv_1 (a : ad) : ad :=
match a with
| N0 => Npos 1
| Npos p => Npos (xI p)
end.
(* calcul des automates modifiés *)
Fixpoint upl_conv_0 (p : prec_list) : prec_list :=
match p with
| prec_empty => prec_empty
| prec_cons a p0 p1 =>
prec_cons (uad_conv_0 a) (upl_conv_0 p0) (upl_conv_0 p1)
end.
Fixpoint upl_conv_1 (p : prec_list) : prec_list :=
match p with
| prec_empty => prec_empty
| prec_cons a p0 p1 =>
prec_cons (uad_conv_1 a) (upl_conv_1 p0) (upl_conv_1 p1)
end.
Fixpoint umpl_conv_0 (s : state) : state :=
match s with
| M0 => M0 prec_list
| M1 a p => M1 prec_list a (upl_conv_0 p)
| M2 p0 p1 => M2 prec_list (umpl_conv_0 p0) (umpl_conv_0 p1)
end.
Fixpoint umpl_conv_1 (s : state) : state :=
match s with
| M0 => M0 prec_list
| M1 a p => M1 prec_list a (upl_conv_1 p)
| M2 p0 p1 => M2 prec_list (umpl_conv_1 p0) (umpl_conv_1 p1)
end.
Fixpoint udta_conv_0_aux (d : preDTA) : preDTA :=
match d with
| M0 => M0 state
| M1 a s => M1 state a (umpl_conv_0 s)
| M2 s0 s1 => M2 state (udta_conv_0_aux s0) (udta_conv_0_aux s1)
end.
Fixpoint udta_conv_1_aux (d : preDTA) : preDTA :=
match d with
| M0 => M0 state
| M1 a s => M1 state a (umpl_conv_1 s)
| M2 s0 s1 => M2 state (udta_conv_1_aux s0) (udta_conv_1_aux s1)
end.
Definition udta_conv_0 (d : preDTA) : preDTA :=
M2 state (udta_conv_0_aux d) (M0 state).
Definition udta_conv_1 (d : preDTA) : preDTA :=
M2 state (M0 state) (udta_conv_1_aux d).
(* lemmes d'injectivité *)
(* lemmes sur les images des applications précédentes *)
(* invariants sur les MapGet pour conv_0 *)
(* invariant de reconnaissance sur conv_0 : sens direct *)
Definition u_conv_rec_0 (p : preDTA) (a : ad) (t : term)
(pr : reconnaissance p a t) :=
reconnaissance (udta_conv_0 p) (uad_conv_0 a) t.
Definition u_conv_str_0 (p : preDTA) (s : state) (t : term)
(pr : state_reconnait p s t) :=
state_reconnait (udta_conv_0 p) (umpl_conv_0 s) t.
Definition u_conv_lr_0 (p : preDTA) (p0 : prec_list)
(t : term_list) (pr : liste_reconnait p p0 t) :=
liste_reconnait (udta_conv_0 p) (upl_conv_0 p0) t.
(* invariant de reconnaissance sur conv_0 : sens reciproque *)
Definition u_conv_rec_0_r (p0 : preDTA) (a0 : ad) (t : term)
(pr0 : reconnaissance p0 a0 t) :=
forall (p : preDTA) (a : ad),
p0 = udta_conv_0 p -> a0 = uad_conv_0 a -> reconnaissance p a t.
Definition u_conv_str_0_r (p0 : preDTA) (s0 : state)
(t : term) (pr : state_reconnait p0 s0 t) :=
forall (p : preDTA) (s : state),
p0 = udta_conv_0 p -> s0 = umpl_conv_0 s -> state_reconnait p s t.
Definition u_conv_lr_0_r (p0 : preDTA) (pl0 : prec_list)
(t : term_list) (pr : liste_reconnait p0 pl0 t) :=
forall (p : preDTA) (pl : prec_list),
p0 = udta_conv_0 p -> pl0 = upl_conv_0 pl -> liste_reconnait p pl t.
(* invariants sur les MapGet : conv_1 *)
(* invariant de reconnaissance de conv_1 *)
Definition u_conv_rec_1 (p : preDTA) (a : ad) (t : term)
(pr : reconnaissance p a t) :=
reconnaissance (udta_conv_1 p) (uad_conv_1 a) t.
Definition u_conv_str_1 (p : preDTA) (s : state) (t : term)
(pr : state_reconnait p s t) :=
state_reconnait (udta_conv_1 p) (umpl_conv_1 s) t.
Definition u_conv_lr_1 (p : preDTA) (p0 : prec_list)
(t : term_list) (pr : liste_reconnait p p0 t) :=
liste_reconnait (udta_conv_1 p) (upl_conv_1 p0) t.
(* invariant de reconnaissance sur conv_1 : sens reciproque *)
Definition u_conv_rec_1_r (p0 : preDTA) (a0 : ad) (t : term)
(pr0 : reconnaissance p0 a0 t) :=
forall (p : preDTA) (a : ad),
p0 = udta_conv_1 p -> a0 = uad_conv_1 a -> reconnaissance p a t.
Definition u_conv_str_1_r (p0 : preDTA) (s0 : state)
(t : term) (pr : state_reconnait p0 s0 t) :=
forall (p : preDTA) (s : state),
p0 = udta_conv_1 p -> s0 = umpl_conv_1 s -> state_reconnait p s t.
Definition u_conv_lr_1_r (p0 : preDTA) (pl0 : prec_list)
(t : term_list) (pr : liste_reconnait p0 pl0 t) :=
forall (p : preDTA) (pl : prec_list),
p0 = udta_conv_1 p -> pl0 = upl_conv_1 pl -> liste_reconnait p pl t.
(* udta_conv_0 et udta_conv_1 ont des images disjointes *)
(* définition de l'union des supports de deux automates *)
Definition u_merge (p0 p1 : preDTA) : preDTA :=
MapMerge state (udta_conv_0 p0) (udta_conv_1 p1).
(* invariants des MapGet au travers de u_merge *)
(* invariant de reconnaissance pour conv_0 au travers de u_merge *)
Definition u_merge_inv_0_dta (p0 : preDTA) (a : ad)
(t : term) (pr : reconnaissance p0 a t) :=
forall p1 : preDTA, reconnaissance (u_merge p0 p1) (uad_conv_0 a) t.
Definition u_merge_inv_0_st (p0 : preDTA) (s : state)
(t : term) (pr : state_reconnait p0 s t) :=
forall p1 : preDTA, state_reconnait (u_merge p0 p1) (umpl_conv_0 s) t.
Definition u_merge_inv_0_lst (p0 : preDTA) (pl : prec_list)
(lt : term_list) (pr : liste_reconnait p0 pl lt) :=
forall p1 : preDTA, liste_reconnait (u_merge p0 p1) (upl_conv_0 pl) lt.
(* invariant de reconnaissance pour conv_1 au travers de u_merge *)
Definition u_merge_inv_1_dta (p1 : preDTA) (a : ad)
(t : term) (pr : reconnaissance p1 a t) :=
forall p0 : preDTA, reconnaissance (u_merge p0 p1) (uad_conv_1 a) t.
Definition u_merge_inv_1_st (p1 : preDTA) (s : state)
(t : term) (pr : state_reconnait p1 s t) :=
forall p0 : preDTA, state_reconnait (u_merge p0 p1) (umpl_conv_1 s) t.
Definition u_merge_inv_1_lst (p1 : preDTA) (pl : prec_list)
(lt : term_list) (pr : liste_reconnait p1 pl lt) :=
forall p0 : preDTA, liste_reconnait (u_merge p0 p1) (upl_conv_1 pl) lt.
(* invariant pour u_merge : sens réciproque pour u_conv_0 *)
Definition u_merge_invr_0_dta (p : preDTA) (a : ad)
(t : term) (pr : reconnaissance p a t) :=
forall p0 p1 : preDTA,
p = u_merge p0 p1 ->
forall a0 : ad, a = uad_conv_0 a0 -> reconnaissance (udta_conv_0 p0) a t.
Definition u_merge_invr_0_st (p : preDTA) (s : state)
(t : term) (pr : state_reconnait p s t) :=
forall p0 p1 : preDTA,
p = u_merge p0 p1 ->
forall s0 : state,
s = umpl_conv_0 s0 -> state_reconnait (udta_conv_0 p0) s t.
Definition u_merge_invr_0_lst (p : preDTA) (pl : prec_list)
(lt : term_list) (pr : liste_reconnait p pl lt) :=
forall p0 p1 : preDTA,
p = u_merge p0 p1 ->
forall pl0 : prec_list,
pl = upl_conv_0 pl0 -> liste_reconnait (udta_conv_0 p0) pl lt.
(* invariant pour u_merge : sens réciproque pour u_conv_1 *)
Definition u_merge_invr_1_dta (p : preDTA) (a : ad)
(t : term) (pr : reconnaissance p a t) :=
forall p0 p1 : preDTA,
p = u_merge p0 p1 ->
forall a0 : ad, a = uad_conv_1 a0 -> reconnaissance (udta_conv_1 p1) a t.
Definition u_merge_invr_1_st (p : preDTA) (s : state)
(t : term) (pr : state_reconnait p s t) :=
forall p0 p1 : preDTA,
p = u_merge p0 p1 ->
forall s0 : state,
s = umpl_conv_1 s0 -> state_reconnait (udta_conv_1 p1) s t.
Definition u_merge_invr_1_lst (p : preDTA) (pl : prec_list)
(lt : term_list) (pr : liste_reconnait p pl lt) :=
forall p0 p1 : preDTA,
p = u_merge p0 p1 ->
forall pl0 : prec_list,
pl = upl_conv_1 pl0 -> liste_reconnait (udta_conv_1 p1) pl lt.
(* union de deux états dans un meme preDTA *)
(* définition d'un état *)
Fixpoint union_pl (pl0 : prec_list) : prec_list -> prec_list :=
fun pl1 : prec_list =>
match pl0 with
| prec_empty => pl1
| prec_cons a pl00 pl01 => prec_cons a pl00 (union_pl pl01 pl1)
end.
Fixpoint union_mpl_0 (c : ad) (pl : prec_list) (s : state) {struct s} :
state :=
match s with
| M0 => M1 prec_list c pl
| M1 c0 pl0 =>
if N.eqb c c0
then M1 prec_list c (union_pl pl pl0)
else MapMerge prec_list (M1 prec_list c pl) (M1 prec_list c0 pl0)
| M2 s0 s1 =>
match c with
| N0 => M2 prec_list (union_mpl_0 N0 pl s0) s1
| Npos p =>
match p with
| xH => M2 prec_list s0 (union_mpl_0 N0 pl s1)
| xO p' => M2 prec_list (union_mpl_0 (Npos p') pl s0) s1
| xI p' => M2 prec_list s0 (union_mpl_0 (Npos p') pl s1)
end
end
end.
Fixpoint union_mpl (s0 : state) : state -> state :=
fun s1 : state =>
match s0, s1 with
| M0, M0 => M0 prec_list
| M0, M2 s10 s11 => M2 prec_list s10 s11
| _, M1 c1 pl1 => union_mpl_0 c1 pl1 s0
| M1 c0 pl0, _ => union_mpl_0 c0 pl0 s1
| M2 s00 s01, M0 => M2 prec_list s00 s01
| M2 s00 s01, M2 s10 s11 =>
M2 prec_list (union_mpl s00 s10) (union_mpl s01 s11)
end.
(* conservation des relation compat par union d'état *)
Definition mpl_compat_7_def (s : state) : Prop :=
forall (c : ad) (pl l : prec_list),
MapGet prec_list s c = Some l ->
MapGet prec_list (union_mpl_0 c pl s) c = Some (union_pl pl l).
Definition mpl_compat_8_def (s : state) : Prop :=
forall (a c : ad) (pl l : prec_list),
MapGet prec_list s c = Some l ->
a <> c -> MapGet prec_list (union_mpl_0 a pl s) c = Some l.
(* invariant sur union_mpl_0, sens direct, 0 *)

Lemma union_s0d_2_1 :
forall (d : preDTA) (pl : prec_list) (s0 s1 : state) (tl : term_list),
mpl_compat (M1 prec_list (Npos 1) pl) (M2 prec_list s0 s1) ->
state_reconnait d (M1 prec_list (Npos 1) pl) (app (Npos 1) tl) ->
state_reconnait d (union_mpl_0 (Npos 1) pl (M2 prec_list s0 s1))
(app (Npos 1) tl).