src/HOL/Induct/SList.thy
changeset 23746 a455e69c31cc
parent 23281 e26ec695c9b3
child 30166 f47c812de07c
equal deleted inserted replaced
23745:28df61d931e2 23746:a455e69c31cc
    44 
    44 
    45 definition
    45 definition
    46   CONS :: "['a item, 'a item] => 'a item" where
    46   CONS :: "['a item, 'a item] => 'a item" where
    47   "CONS M N = In1(Scons M N)"
    47   "CONS M N = In1(Scons M N)"
    48 
    48 
    49 consts
    49 inductive_set
    50   list      :: "'a item set => 'a item set"
    50   list :: "'a item set => 'a item set"
    51 inductive "list(A)"
    51   for A :: "'a item set"
    52   intros
    52   where
    53     NIL_I:  "NIL: list A"
    53     NIL_I:  "NIL: list A"
    54     CONS_I: "[| a: A;  M: list A |] ==> CONS a M : list A"
    54   | CONS_I: "[| a: A;  M: list A |] ==> CONS a M : list A"
    55 
    55 
    56 
    56 
    57 typedef (List)
    57 typedef (List)
    58     'a list = "list(range Leaf) :: 'a item set" 
    58     'a list = "list(range Leaf) :: 'a item set" 
    59   by (blast intro: list.NIL_I)
    59   by (blast intro: list.NIL_I)
   147 definition
   147 definition
   148   (* a total version of tl: *)
   148   (* a total version of tl: *)
   149   ttl       :: "'a list => 'a list" where
   149   ttl       :: "'a list => 'a list" where
   150   "ttl xs   = list_rec xs [] (%x xs r. xs)"
   150   "ttl xs   = list_rec xs [] (%x xs r. xs)"
   151 
   151 
       
   152 (*<*)no_syntax
       
   153     member :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infixl "mem" 55)(*>*)
   152 definition
   154 definition
   153   member :: "['a, 'a list] => bool"    (infixl "mem" 55) where
   155   member :: "['a, 'a list] => bool"    (infixl "mem" 55) where
   154   "x mem xs = list_rec xs False (%y ys r. if y=x then True else r)"
   156   "x mem xs = list_rec xs False (%y ys r. if y=x then True else r)"
   155 
   157 
   156 definition
   158 definition
   252   by (fast intro!: list.intros [unfolded NIL_def CONS_def]
   254   by (fast intro!: list.intros [unfolded NIL_def CONS_def]
   253            elim: list.cases [unfolded NIL_def CONS_def])
   255            elim: list.cases [unfolded NIL_def CONS_def])
   254 
   256 
   255 (*This justifies using list in other recursive type definitions*)
   257 (*This justifies using list in other recursive type definitions*)
   256 lemma list_mono: "A<=B ==> list(A) <= list(B)"
   258 lemma list_mono: "A<=B ==> list(A) <= list(B)"
   257 apply (unfold list.defs )
   259 apply (rule subsetI)
   258 apply (rule lfp_mono)
   260 apply (erule list.induct)
   259 apply (assumption | rule basic_monos)+
   261 apply (auto intro!: list.intros)
   260 done
   262 done
   261 
   263 
   262 (*Type checking -- list creates well-founded sets*)
   264 (*Type checking -- list creates well-founded sets*)
   263 lemma list_sexp: "list(sexp) <= sexp"
   265 lemma list_sexp: "list(sexp) <= sexp"
   264 apply (unfold NIL_def CONS_def list.defs)
   266 apply (rule subsetI)
   265 apply (rule lfp_lowerbound)
   267 apply (erule list.induct)
   266 apply (fast intro: sexp.intros sexp_In0I sexp_In1I)
   268 apply (unfold NIL_def CONS_def)
       
   269 apply (auto intro: sexp.intros sexp_In0I sexp_In1I)
   267 done
   270 done
   268 
   271 
   269 (* A <= sexp ==> list(A) <= sexp *)
   272 (* A <= sexp ==> list(A) <= sexp *)
   270 lemmas list_subset_sexp = subset_trans [OF list_mono list_sexp] 
   273 lemmas list_subset_sexp = subset_trans [OF list_mono list_sexp] 
   271 
   274