(* 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.

Lemma u_conv0_0r :
forall (d : preDTA) (a : ad) (t : term) (ladj : state)
(e : MapGet state d a = Some ladj) (s : state_reconnait d ladj t),
u_conv_str_0_r d ladj t s -> u_conv_rec_0_r d a t (rec_dta d a t ladj e s).