(* 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                                                     *)
(* Contribution to the Coq Library   V6.3 (July 1999)                    *)
(****************************************************************************)
(*                 The Calculus of Inductive Constructions                  *)
(*                                                                          *)
(*                                Projet Coq                                *)
(*                                                                          *)
(*                     INRIA                        ENS-CNRS                *)
(*              Rocquencourt                        Lyon                    *)
(*                                                                          *)
(*                                Coq V5.10                                 *)
(*                              Nov 25th 1994                               *)
(*                                                                          *)
(****************************************************************************)
(*                                 Words.v                                  *)
(****************************************************************************)
(*              Formal Language Theory                                      *)
(*                                                                          *)
(*              Judicael Courant - Jean-Christophe Filliatre                *)
(*                                                                          *)
(*              Developped in V5.8  June-July 1993                          *)
(*              Ported     to V5.10 October 1994                            *)
(****************************************************************************)
Parameter alph : Ensf.
Parameter epsilon : Elt.
(*  On definit le predicat (inmonoid X w) qui signifie que le mot w	*)
(*  est dans le monoide libre engendre par X.				*)
Inductive inmonoid (X : Ensf) : Word -> Prop :=
| inmonoid_nil : inmonoid X nil
| inmonoid_cons :
forall (w : Word) (e : Elt),
inmonoid X w -> dans e X -> inmonoid X (cons e w).
Hint Resolve inmonoid_nil.
Hint Resolve inmonoid_cons.
(*  Inversion de la definition 						*)
(* Fixpoint Inmonoid [X:Ensf; w:Word] : Prop := (<Prop>Case w of (* nil  *) True (* cons *) [a:Elt][w':Word]( (dans a X) /\ (Inmonoid X w') ) end ). *)
Fixpoint Inmonoid (X : Ensf) (w : Word) {struct w} : Prop :=
match w with
| nil => True
| cons a w' => dans a X /\ Inmonoid X w'
end.
intros X w H.
elim H.
red in |- *; simpl in |- *; exact I.
intros.
change (dans e X /\ Inmonoid X w0) in |- *.
auto.
Qed.
Hint Resolve i_I.
intros X.
simple induction w.
auto.
intros x w0 H H0.
cut (dans x X /\ Inmonoid X w0); auto.
intro H1; elim H1; clear H1.
auto.
Qed.
Hint Resolve I_i.
intros.
cut (Inmonoid X w); auto.
cut (Inmonoid X (cons a w)); auto.
intro H0.
cut (dans a X /\ Inmonoid X w); auto.
intro H1; elim H1; clear H1.
auto.
Qed.
intros.
cut (Inmonoid X (cons a w)); auto.
intro.
cut (dans a X /\ Inmonoid X w); auto.
intro H1; elim H1; clear H1.
auto.
Qed.
intros E F x inclus_E_F inmonoid_E_x.
elim inmonoid_E_x.
trivial.
intros w e inmonoid_E_w inmonoid_F_w dans_e_E.
apply inmonoid_cons; [ assumption | apply inclus_E_F; assumption ].
Qed.
(*									*)
(*  Concatenation de 2 mots : 						*)
(*    (Append w1 w2) est la concatenation de w1 et w2			*)
(*    (append w1 w2 w3) est la proposition "w3 est la conc.de w1 et w2"	*)
(*									*)
(* Fixpoint Append [w1:Word] : Word -> Word := [w2:Word] (<Word>Case w1 of (* nil  *) w2 (* cons *) [a:Elt][w3:Word](cons a (Append w3 w2)) end ). *)
Fixpoint Append (w1 : Word) : Word -> Word :=
fun w2 : Word =>
match w1 with
| nil => w2
| cons a w3 => cons a (Append w3 w2)
end.
simple induction w.
auto.
intros x w0 H.
replace (Append (cons x w0) nil) with (cons x (Append w0 nil)); auto.
rewrite H; auto.
Qed.
Inductive append : Word -> Word -> Word -> Prop :=
| append_nil : forall w : Word, append nil w w
| append_cons :
forall (w1 w2 w3 : Word) (a : Elt),
append w1 w2 w3 -> append (cons a w1) w2 (cons a w3).
(*  Lemmes sur inmonoid et Append...					*)
intros X.
simple induction w1.
auto.
intros x w H w2.
replace (Append (cons x w) w2) with (cons x (Append w w2)); auto.
intro.
apply inmonoid_cons.
apply (H w2).
apply inmonoid_cons_inv with x; auto.
apply inmonoid_cons_inv2 with (Append w w2); auto.
Qed.
intros X.
simple induction w1.
auto.
intros x w H w2.
replace (Append (cons x w) w2) with (cons x (Append w w2)); auto.
intro.
apply (H w2).
apply inmonoid_cons_inv with x; auto.
Qed.

Lemma inmonoid_Append :
forall (X : Ensf) (w1 w2 : Word),
inmonoid X w1 -> inmonoid X w2 -> inmonoid X (Append w1 w2).