src/HOL/Induct/QuoNestedDataType.thy
changeset 19736 d8d0f8f51d69
parent 18460 9a1458cb2956
child 20523 36a59e5d0039
equal deleted inserted replaced
19735:ff13585fbdab 19736:d8d0f8f51d69
    18 	     | FNCALL  nat "freeExp list"
    18 	     | FNCALL  nat "freeExp list"
    19 
    19 
    20 text{*The equivalence relation, which makes PLUS associative.*}
    20 text{*The equivalence relation, which makes PLUS associative.*}
    21 consts  exprel :: "(freeExp * freeExp) set"
    21 consts  exprel :: "(freeExp * freeExp) set"
    22 
    22 
    23 syntax
    23 abbreviation
    24   "_exprel" :: "[freeExp, freeExp] => bool"  (infixl "~~" 50)
    24   exp_rel :: "[freeExp, freeExp] => bool"  (infixl "~~" 50)
    25 syntax (xsymbols)
    25   "X ~~ Y == (X,Y) \<in> exprel"
    26   "_exprel" :: "[freeExp, freeExp] => bool"  (infixl "\<sim>" 50)
    26 
    27 syntax (HTML output)
    27 const_syntax (xsymbols)
    28   "_exprel" :: "[freeExp, freeExp] => bool"  (infixl "\<sim>" 50)
    28   exp_rel  (infixl "\<sim>" 50)
    29 translations
    29 const_syntax (HTML output)
    30   "X \<sim> Y" == "(X,Y) \<in> exprel"
    30   exp_rel  (infixl "\<sim>" 50)
    31 
    31 
    32 text{*The first rule is the desired equation. The next three rules
    32 text{*The first rule is the desired equation. The next three rules
    33 make the equations applicable to subterms. The last two rules are symmetry
    33 make the equations applicable to subterms. The last two rules are symmetry
    34 and transitivity.*}
    34 and transitivity.*}
    35 inductive "exprel"
    35 inductive "exprel"
   157 typedef (Exp)  exp = "UNIV//exprel"
   157 typedef (Exp)  exp = "UNIV//exprel"
   158     by (auto simp add: quotient_def)
   158     by (auto simp add: quotient_def)
   159 
   159 
   160 text{*The abstract message constructors*}
   160 text{*The abstract message constructors*}
   161 
   161 
   162 constdefs
   162 definition
   163   Var :: "nat \<Rightarrow> exp"
   163   Var :: "nat \<Rightarrow> exp"
   164   "Var N == Abs_Exp(exprel``{VAR N})"
   164   "Var N = Abs_Exp(exprel``{VAR N})"
   165 
   165 
   166   Plus :: "[exp,exp] \<Rightarrow> exp"
   166   Plus :: "[exp,exp] \<Rightarrow> exp"
   167    "Plus X Y ==
   167    "Plus X Y =
   168        Abs_Exp (\<Union>U \<in> Rep_Exp X. \<Union>V \<in> Rep_Exp Y. exprel``{PLUS U V})"
   168        Abs_Exp (\<Union>U \<in> Rep_Exp X. \<Union>V \<in> Rep_Exp Y. exprel``{PLUS U V})"
   169 
   169 
   170   FnCall :: "[nat, exp list] \<Rightarrow> exp"
   170   FnCall :: "[nat, exp list] \<Rightarrow> exp"
   171    "FnCall F Xs ==
   171    "FnCall F Xs =
   172        Abs_Exp (\<Union>Us \<in> listset (map Rep_Exp Xs). exprel `` {FNCALL F Us})"
   172        Abs_Exp (\<Union>Us \<in> listset (map Rep_Exp Xs). exprel `` {FNCALL F Us})"
   173 
   173 
   174 
   174 
   175 text{*Reduces equality of equivalence classes to the @{term exprel} relation:
   175 text{*Reduces equality of equivalence classes to the @{term exprel} relation:
   176   @{term "(exprel `` {x} = exprel `` {y}) = ((x,y) \<in> exprel)"} *}
   176   @{term "(exprel `` {x} = exprel `` {y}) = ((x,y) \<in> exprel)"} *}
   204 
   204 
   205 
   205 
   206 subsection{*Every list of abstract expressions can be expressed in terms of a
   206 subsection{*Every list of abstract expressions can be expressed in terms of a
   207   list of concrete expressions*}
   207   list of concrete expressions*}
   208 
   208 
   209 constdefs Abs_ExpList :: "freeExp list => exp list"
   209 definition
   210     "Abs_ExpList Xs == map (%U. Abs_Exp(exprel``{U})) Xs"
   210   Abs_ExpList :: "freeExp list => exp list"
       
   211   "Abs_ExpList Xs = map (%U. Abs_Exp(exprel``{U})) Xs"
   211 
   212 
   212 lemma Abs_ExpList_Nil [simp]: "Abs_ExpList [] == []"
   213 lemma Abs_ExpList_Nil [simp]: "Abs_ExpList [] == []"
   213 by (simp add: Abs_ExpList_def)
   214 by (simp add: Abs_ExpList_def)
   214 
   215 
   215 lemma Abs_ExpList_Cons [simp]:
   216 lemma Abs_ExpList_Cons [simp]:
   281 
   282 
   282 
   283 
   283 
   284 
   284 subsection{*The Abstract Function to Return the Set of Variables*}
   285 subsection{*The Abstract Function to Return the Set of Variables*}
   285 
   286 
   286 constdefs
   287 definition
   287   vars :: "exp \<Rightarrow> nat set"
   288   vars :: "exp \<Rightarrow> nat set"
   288    "vars X == \<Union>U \<in> Rep_Exp X. freevars U"
   289   "vars X = (\<Union>U \<in> Rep_Exp X. freevars U)"
   289 
   290 
   290 lemma vars_respects: "freevars respects exprel"
   291 lemma vars_respects: "freevars respects exprel"
   291 by (simp add: congruent_def exprel_imp_eq_freevars) 
   292 by (simp add: congruent_def exprel_imp_eq_freevars) 
   292 
   293 
   293 text{*The extension of the function @{term vars} to lists*}
   294 text{*The extension of the function @{term vars} to lists*}
   347 apply (drule exprel_imp_eq_freediscrim, simp)
   348 apply (drule exprel_imp_eq_freediscrim, simp)
   348 done
   349 done
   349 
   350 
   350 subsection{*Injectivity of @{term FnCall}*}
   351 subsection{*Injectivity of @{term FnCall}*}
   351 
   352 
   352 constdefs
   353 definition
   353   fun :: "exp \<Rightarrow> nat"
   354   fun :: "exp \<Rightarrow> nat"
   354    "fun X == contents (\<Union>U \<in> Rep_Exp X. {freefun U})"
   355   "fun X = contents (\<Union>U \<in> Rep_Exp X. {freefun U})"
   355 
   356 
   356 lemma fun_respects: "(%U. {freefun U}) respects exprel"
   357 lemma fun_respects: "(%U. {freefun U}) respects exprel"
   357 by (simp add: congruent_def exprel_imp_eq_freefun) 
   358 by (simp add: congruent_def exprel_imp_eq_freefun) 
   358 
   359 
   359 lemma fun_FnCall [simp]: "fun (FnCall F Xs) = F"
   360 lemma fun_FnCall [simp]: "fun (FnCall F Xs) = F"
   360 apply (cases Xs rule: eq_Abs_ExpList) 
   361 apply (cases Xs rule: eq_Abs_ExpList) 
   361 apply (simp add: FnCall fun_def UN_equiv_class [OF equiv_exprel fun_respects])
   362 apply (simp add: FnCall fun_def UN_equiv_class [OF equiv_exprel fun_respects])
   362 done
   363 done
   363 
   364 
   364 constdefs
   365 definition
   365   args :: "exp \<Rightarrow> exp list"
   366   args :: "exp \<Rightarrow> exp list"
   366    "args X == contents (\<Union>U \<in> Rep_Exp X. {Abs_ExpList (freeargs U)})"
   367   "args X = contents (\<Union>U \<in> Rep_Exp X. {Abs_ExpList (freeargs U)})"
   367 
   368 
   368 text{*This result can probably be generalized to arbitrary equivalence
   369 text{*This result can probably be generalized to arbitrary equivalence
   369 relations, but with little benefit here.*}
   370 relations, but with little benefit here.*}
   370 lemma Abs_ExpList_eq:
   371 lemma Abs_ExpList_eq:
   371      "(y, z) \<in> listrel exprel \<Longrightarrow> Abs_ExpList (y) = Abs_ExpList (z)"
   372      "(y, z) \<in> listrel exprel \<Longrightarrow> Abs_ExpList (y) = Abs_ExpList (z)"
   394 
   395 
   395 subsection{*The Abstract Discriminator*}
   396 subsection{*The Abstract Discriminator*}
   396 text{*However, as @{text FnCall_Var_neq_Var} illustrates, we don't need this
   397 text{*However, as @{text FnCall_Var_neq_Var} illustrates, we don't need this
   397 function in order to prove discrimination theorems.*}
   398 function in order to prove discrimination theorems.*}
   398 
   399 
   399 constdefs
   400 definition
   400   discrim :: "exp \<Rightarrow> int"
   401   discrim :: "exp \<Rightarrow> int"
   401    "discrim X == contents (\<Union>U \<in> Rep_Exp X. {freediscrim U})"
   402   "discrim X = contents (\<Union>U \<in> Rep_Exp X. {freediscrim U})"
   402 
   403 
   403 lemma discrim_respects: "(\<lambda>U. {freediscrim U}) respects exprel"
   404 lemma discrim_respects: "(\<lambda>U. {freediscrim U}) respects exprel"
   404 by (simp add: congruent_def exprel_imp_eq_freediscrim) 
   405 by (simp add: congruent_def exprel_imp_eq_freediscrim) 
   405 
   406 
   406 text{*Now prove the four equations for @{term discrim}*}
   407 text{*Now prove the four equations for @{term discrim}*}