(* 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                                                     *)
Unset Standard Proposition Elimination Names.
(* fonction définissant la sémantique : reconnaissance d'un terme par un automate *)
Fixpoint rec_term (d : preDTA) (a : ad) (t : term)
(n : nat) {struct n} : bool :=
match n with
| O => false
| S k =>
match t with
| app c l =>
match MapGet _ d a with
| None => false
| Some lts =>
match MapGet _ lts c with
| None => false
| Some pre => rec_list_terms d pre l k
end
end
end
end
with rec_list_terms (d : preDTA) (pre : prec_list)
(l : term_list) (n : nat) {struct n} : bool :=
match n with
| O => false
| S k =>
match pre with
| prec_empty => match l with
| tnil => true
| _ => false
end
| prec_cons st stp pre' =>
match l with
| tnil => false
| tcons hd tl =>
rec_list_terms d pre' l k
|| rec_term d st hd k && rec_list_terms d stp tl k
end
end
end.
(* bornes sur l'entier décroissant (terminaison de la fonction reconnaissance *)
(* définition de la quantité d'essence (Astuce de Boyer, définition de *)
(* la reconnaissance par fixpoint...) *)
Definition essence (t : term) (d : preDTA) : nat :=
S (term_high t) * S (DTA_taille d).
(* "hauteur" d'une liste : term_high_0 *)
Definition essence_list (l : term_list) (d : preDTA)
(pl : prec_list) : nat :=
match l, pl with
| tnil, _ => 1
| _, prec_empty => 1
| _, prec_cons a la ls =>
taille_0 pl + S (term_high_0 l) * S (DTA_taille d)
end.
(* lemmes concernant la gestion de la diminution de la quantité d'essence *)

Lemma conservation_3 :
forall (d : preDTA) (hd : term) (tl : term_list) (a : ad)
(la ls : prec_list),
S (essence_list (tcons hd tl) d ls) <=
essence_list (tcons hd tl) d (prec_cons a la ls).