doc-src/IsarAdvanced/Codegen/Thy/Codegen.thy
changeset 21341 3844037a8e2d
parent 21323 74ab7c0980c7
child 21452 f825e0b4d566
equal deleted inserted replaced
21340:51d9bf0b821f 21341:3844037a8e2d
   544 *}
   544 *}
   545 
   545 
   546 fun
   546 fun
   547   in_interval :: "nat \<times> nat \<Rightarrow> nat \<Rightarrow> bool" where
   547   in_interval :: "nat \<times> nat \<Rightarrow> nat \<Rightarrow> bool" where
   548   "in_interval (k, l) n \<longleftrightarrow> k \<le> n \<and> n \<le> l"
   548   "in_interval (k, l) n \<longleftrightarrow> k \<le> n \<and> n \<le> l"
   549 termination by (auto_term "{}")
       
   550 (*<*)
   549 (*<*)
   551 declare in_interval.simps [code func]
   550 declare in_interval.simps [code func]
   552 (*>*)
   551 (*>*)
   553 
   552 
   554 (*<*)
   553 (*<*)
   716   "collect_duplicates xs ys (z#zs) = (if z \<in> set xs
   715   "collect_duplicates xs ys (z#zs) = (if z \<in> set xs
   717     then if z \<in> set ys
   716     then if z \<in> set ys
   718       then collect_duplicates xs ys zs
   717       then collect_duplicates xs ys zs
   719       else collect_duplicates xs (z#ys) zs
   718       else collect_duplicates xs (z#ys) zs
   720     else collect_duplicates (z#xs) (z#ys) zs)"
   719     else collect_duplicates (z#xs) (z#ys) zs)"
   721 termination by (auto_term "measure (length o snd o snd)")
       
   722 (*<*)
   720 (*<*)
   723 lemmas [code func] = collect_duplicates.simps
   721 lemmas [code func] = collect_duplicates.simps
   724 (*>*)
   722 (*>*)
   725 
   723 
   726 text {*
   724 text {*
   807 
   805 
   808 fun
   806 fun
   809   lookup :: "(key \<times> 'a) list \<Rightarrow> key \<Rightarrow> 'a option" where
   807   lookup :: "(key \<times> 'a) list \<Rightarrow> key \<Rightarrow> 'a option" where
   810   "lookup [] l = None"
   808   "lookup [] l = None"
   811   "lookup ((k, v) # xs) l = (if k = l then Some v else lookup xs l)"
   809   "lookup ((k, v) # xs) l = (if k = l then Some v else lookup xs l)"
   812 termination by (auto_term "measure (length o fst)")
       
   813 (*<*)
   810 (*<*)
   814 lemmas [code func] = lookup.simps
   811 lemmas [code func] = lookup.simps
   815 (*>*)
   812 (*>*)
   816 
   813 
   817 code_type %tt key
   814 code_type %tt key
  1113 
  1110 
  1114 fun
  1111 fun
  1115   dummy_option :: "'a list \<Rightarrow> 'a option" where
  1112   dummy_option :: "'a list \<Rightarrow> 'a option" where
  1116   "dummy_option (x#xs) = Some x"
  1113   "dummy_option (x#xs) = Some x"
  1117   "dummy_option [] = arbitrary"
  1114   "dummy_option [] = arbitrary"
  1118 termination by (auto_term "{}")
       
  1119 (*<*)
  1115 (*<*)
  1120 declare dummy_option.simps [code func]
  1116 declare dummy_option.simps [code func]
  1121 (*>*)
  1117 (*>*)
  1122 
  1118 
  1123 code_gen dummy_option (SML "examples/arbitrary.ML")
  1119 code_gen dummy_option (SML "examples/arbitrary.ML")
  1182 
  1178 
  1183 subsubsection {* Suspended theorems *}
  1179 subsubsection {* Suspended theorems *}
  1184 
  1180 
  1185 text %mlref {*
  1181 text %mlref {*
  1186   \begin{mldecls}
  1182   \begin{mldecls}
  1187   @{index_ML CodegenData.lazy: "(unit -> thm list) -> CodegenData.lthms"}
  1183   @{index_ML CodegenData.lazy: "(unit -> thm list) -> thm list Susp.T"}
  1188   \end{mldecls}
  1184   \end{mldecls}
  1189 
  1185 
  1190   \begin{description}
  1186   \begin{description}
  1191 
  1187 
  1192   \item @{ML CodegenData.lazy}~@{text f} turns an abstract
  1188   \item @{ML CodegenData.lazy}~@{text f} turns an abstract
  1199 
  1195 
  1200 text %mlref {*
  1196 text %mlref {*
  1201   \begin{mldecls}
  1197   \begin{mldecls}
  1202   @{index_ML CodegenData.add_func: "thm -> theory -> theory"} \\
  1198   @{index_ML CodegenData.add_func: "thm -> theory -> theory"} \\
  1203   @{index_ML CodegenData.del_func: "thm -> theory -> theory"} \\
  1199   @{index_ML CodegenData.del_func: "thm -> theory -> theory"} \\
  1204   @{index_ML CodegenData.add_funcl: "CodegenConsts.const * CodegenData.lthms -> theory -> theory"} \\
  1200   @{index_ML CodegenData.add_funcl: "CodegenConsts.const * thm list Susp.T -> theory -> theory"} \\
  1205   @{index_ML CodegenData.add_inline: "thm -> theory -> theory"} \\
  1201   @{index_ML CodegenData.add_inline: "thm -> theory -> theory"} \\
  1206   @{index_ML CodegenData.del_inline: "thm -> theory -> theory"} \\
  1202   @{index_ML CodegenData.del_inline: "thm -> theory -> theory"} \\
  1207   @{index_ML CodegenData.add_inline_proc: "(theory -> cterm list -> thm list)
  1203   @{index_ML CodegenData.add_inline_proc: "(theory -> cterm list -> thm list)
  1208     -> theory -> theory"} \\
  1204     -> theory -> theory"} \\
  1209   @{index_ML CodegenData.add_preproc: "(theory -> thm list -> thm list)
  1205   @{index_ML CodegenData.add_preproc: "(theory -> thm list -> thm list)
  1210     -> theory -> theory"} \\
  1206     -> theory -> theory"} \\
  1211   @{index_ML CodegenData.add_datatype: "string * (((string * sort) list * (string * typ list) list)
  1207   @{index_ML CodegenData.add_datatype: "string * (((string * sort) list * (string * typ list) list)
  1212     * CodegenData.lthms) -> theory -> theory"} \\
  1208     * thm list Susp.T) -> theory -> theory"} \\
  1213   @{index_ML CodegenData.del_datatype: "string -> theory -> theory"} \\
  1209   @{index_ML CodegenData.del_datatype: "string -> theory -> theory"} \\
  1214   @{index_ML CodegenData.get_datatype: "theory -> string
  1210   @{index_ML CodegenData.get_datatype: "theory -> string
  1215     -> ((string * sort) list * (string * typ list) list) option"} \\
  1211     -> ((string * sort) list * (string * typ list) list) option"} \\
  1216   @{index_ML CodegenData.get_datatype_of_constr: "theory -> CodegenConsts.const -> string option"}
  1212   @{index_ML CodegenData.get_datatype_of_constr: "theory -> CodegenConsts.const -> string option"}
  1217   \end{mldecls}
  1213   \end{mldecls}