(* Pollutes the global namespace, but we use them everywhere *) fun ss_only thms ctxt = clear_simpset (put_simpset HOL_basic_ss ctxt) addsimps thms; fun HOL_ss_only thms ctxt = clear_simpset (put_simpset HOL_ss ctxt) addsimps thms;
signature CIMP = sig val com_locs_fold : (term * 'b -> 'b) -> 'b -> term -> 'b val com_locs_map : (term -> 'b) -> term -> 'b list val com_locs_fold_no_response : (term * 'b -> 'b) -> 'b -> term -> 'b val com_locs_map_no_response : (term -> 'b) -> term -> 'b list val intern_com : Facts.ref -> local_theory -> local_theory val def_locset : thm -> local_theory -> local_theory end;
structure Cimp : CIMP = struct
fun com_locs_fold f x (Const (@{const_name Request}, _) $ l $ _ $ _ ) = f (l, x)
| com_locs_fold f x (Const (@{const_name Response}, _) $ l $ _) = f (l, x)
| com_locs_fold f x (Const (@{const_name LocalOp}, _) $ l $ _) = f (l, x)
| com_locs_fold f x (Const (@{const_name Cond1}, _) $ l $ _ $ c) = com_locs_fold f (f (l, x)) c
| com_locs_fold f x (Const (@{const_name Cond2}, _) $ l $ _ $ c1 $ c2) = com_locs_fold f (com_locs_fold f (f (l, x)) c1) c2
| com_locs_fold f x (Const (@{const_name Loop}, _) $ c) = com_locs_fold f x c
| com_locs_fold f x (Const (@{const_name While}, _) $ l $ _ $ c) = com_locs_fold f (f (l, x)) c
| com_locs_fold f x (Const (@{const_name Seq}, _) $ c1 $ c2) = com_locs_fold f (com_locs_fold f x c1) c2
| com_locs_fold f x (Const (@{const_name Choose}, _) $ c1 $ c2) = com_locs_fold f (com_locs_fold f x c1) c2
| com_locs_fold _ x _ = x;
fun com_locs_map f com = com_locs_fold (fn (l, acc) => f l :: acc) [] com
fun com_locs_fold_no_response f x (Const (@{const_name Request}, _) $ l $ _ $ _ ) = f (l, x)
| com_locs_fold_no_response _ x (Const (@{const_name Response}, _) $ _ $ _) = x (* can often ignore \<open>Response\<close> *)
| com_locs_fold_no_response f x (Const (@{const_name LocalOp}, _) $ l $ _) = f (l, x)
| com_locs_fold_no_response f x (Const (@{const_name Cond1}, _) $ l $ _ $ c) = com_locs_fold_no_response f (f (l, x)) c
| com_locs_fold_no_response f x (Const (@{const_name Cond2}, _) $ l $ _ $ c1 $ c2) = com_locs_fold_no_response f (com_locs_fold_no_response f (f (l, x)) c1) c2
| com_locs_fold_no_response f x (Const (@{const_name Loop}, _) $ c) = com_locs_fold_no_response f x c
| com_locs_fold_no_response f x (Const (@{const_name While}, _) $ l $ _ $ c) = com_locs_fold_no_response f (f (l, x)) c
| com_locs_fold_no_response f x (Const (@{const_name Seq}, _) $ c1 $ c2) = com_locs_fold_no_response f (com_locs_fold_no_response f x c1) c2
| com_locs_fold_no_response f x (Const (@{const_name Choose}, _) $ c1 $ c2) = com_locs_fold_no_response f (com_locs_fold_no_response f x c1) c2
| com_locs_fold_no_response _ x _ = x;
fun com_locs_map_no_response f com = com_locs_fold_no_response (fn (l, acc) => f l :: acc) [] com
fun cprop_of_equality ctxt : thm -> cterm =
Local_Defs.meta_rewrite_rule ctxt (* handle `=` or `\<equiv>` *)
#> Thm.cprop_of
fun equality_lhs ctxt : thm -> term =
cprop_of_equality ctxt #> Thm.dest_equals_lhs #> Thm.term_of
fun equality_rhs ctxt : thm -> term =
cprop_of_equality ctxt #> Thm.dest_equals_rhs #> Thm.term_of
(* Intern all labels mentioned in CIMP programs \<open>facts\<close>
FIXMEcanonlyuse\<open>com_intern\<close>onceperlocale FIXMEforcesalllabelstobeuniqueanddistinctfromotherconstantsinthelocale. FIXMEassumesthelabelsarecharacterstrings
*) fun intern_com facts ctxt : local_theory = let val thms = Proof_Context.get_fact ctxt facts (* Define constants with defs of the form loc.XXX_def: "XXX \<equiv> ''XXX''. *) val attrs = [] fun add_literal_def (literal, (loc_defs, ctxt)) : thm list * local_theory = let val literal_name = HOLogic.dest_string literal (* FIXME might not be a nice name, but the error is readable so shrug. FIXME generalise to other label types *) val literal_def_binding = Binding.empty (* Binding.qualify true "loc" (Binding.name (Thm.def_name literal_name)) No need to name individual defs *) val ((_, (_, loc_def)), ctxt) = Local_Theory.define ((Binding.name literal_name, Mixfix.NoSyn), ((literal_def_binding, attrs), literal)) ctxt in
(loc_def :: loc_defs, ctxt) end; val (loc_defs, ctxt) = List.foldl (fn (com, acc) => com_locs_fold add_literal_def acc (equality_rhs ctxt com)) ([], ctxt) thms
val coms_interned = List.map (Local_Defs.fold ctxt loc_defs) thms val attrs = [] val (_, ctxt) = Local_Theory.note ((@{binding "loc_defs"}, attrs), loc_defs) ctxt val (_, ctxt) = Local_Theory.note ((@{binding "com_interned"}, attrs), coms_interned) ctxt in
ctxt end;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.