(* Title: HOL/Tools/choice_specification.ML Author: Sebastian Skalberg, TU Muenchen
Package for defining constants by specification.
*)
signature CHOICE_SPECIFICATION = sig val close_form : term -> term val add_specification: (bstring * xstring * bool) list -> theory * thm -> theory * thm end
fun unvarify_global t fmap = let val fmap' = map Library.swap fmap fun unthaw v =
(case AList.lookup (op =) fmap' v of
NONE => raise Same.SAME
| SOME w => TFree w) in map_types (map_type_tvar unthaw) t end
(* The syntactic meddling needed to setup add_specification for work *)
fun close_form t =
fold_rev (fn (s, T) => fn t => HOLogic.mk_all (s, T, t))
(map dest_Free (Misc_Legacy.term_frees t)) t
fun process_spec cos alt_props thy = let val ctxt = Proof_Context.init_global thy
val rew_imps = alt_props |> map (Object_Logic.atomize ctxt o Thm.cterm_of ctxt o Syntax.read_prop_global thy o snd) val props' = rew_imps |> map (HOLogic.dest_Trueprop o Thm.term_of o snd o Thm.dest_equals o Thm.cprop_of)
fun close_prop prop = let val frees = Misc_Legacy.term_frees prop val _ =
frees |> List.app (fn x => if Sign.of_sort thy (fastype_of x, \<^sort>\<open>type\<close>) then () else
error ("Specification: Existential variable " ^
Syntax.string_of_term (Config.put show_sorts true ctxt) x ^ " has non-HOL type")); in (frees, close_form prop) end
val (all_frees, all_props) = split_list (map close_prop props') val conj_prop = foldr1 HOLogic.mk_conj all_props
val (vmap, prop_thawed) = Type.varify_global TFrees.empty conj_prop val thawed_prop_consts = collect_consts (prop_thawed, []) val (altcos, overloaded) = split_list cos val (names, sconsts) = split_list altcos val consts = map (Syntax.read_term_global thy) sconsts val _ = not (Library.exists (not o Term.is_Const) consts)
orelse error "Specification: Non-constant found as parameter"
fun proc_const c = let val (_, c') = Type.varify_global TFrees.empty c val (cname,ctyp) = dest_Const c' in
(casefilter (fn t => letval (name, typ) = dest_Const t in name = cname andalso Sign.typ_equiv thy (typ, ctyp) end) thawed_prop_consts of
[] =>
error ("Specification: No suitable instances of constant \"" ^
Syntax.string_of_term_global thy c ^ "\" found")
| [cf] => unvarify_global cf vmap
| _ => error ("Specification: Several variations of \"" ^
Syntax.string_of_term_global thy c ^ "\" found (try applying explicit type constraints)")) end val proc_consts = map proc_const consts fun mk_exist c prop = let val T = type_of c val cname = Long_Name.base_name (dest_Const_name c) val vname = if Symbol_Pos.is_identifier cname then cname else"x" in HOLogic.exists_const T $ Abs(vname,T,Term.abstract_over (c, prop)) end val ex_prop = fold_rev mk_exist proc_consts conj_prop val cnames = map dest_Const_name proc_consts fun post_process (arg as (thy,thm)) = let fun inst_all thy v thm = let val cv = Thm.global_cterm_of thy v val cT = Thm.ctyp_of_cterm cv val spec' = Thm.instantiate' [SOME cT] [NONE, SOME cv] spec in thm RS spec' end fun remove_alls frees (thm, thy) = (fold (inst_all thy) frees thm, thy) fun process_single ((name, atts), rew_imp, frees) args = let fun undo_imps thm = Thm.equal_elim (Thm.symmetric rew_imp) thm
fun add_final (thm, thy) = if name = "" then (thm, thy) else (writeln (" " ^ name ^ ": " ^ Thm.string_of_thm_global thy thm);
Global_Theory.store_thm (Binding.name name, thm) thy) in
swap args
|> remove_alls frees
|> apfst undo_imps
|> apfst Drule.export_without_context
|-> Thm.theory_attributes
(map (Attrib.attribute_cmd_global thy)
(@{attributes [nitpick_choice_spec]} @ atts))
|> add_final
|> swap end
fun process_all [proc_arg] args =
process_single proc_arg args
| process_all (proc_arg::rest) (thy,thm) = let val single_th = thm RS conjunct1 val rest_th = thm RS conjunct2 val (thy', _) = process_single proc_arg (thy, single_th) in process_all rest (thy', rest_th) end
| process_all [] _ = raise Fail "Choice_Specification.process_spec internal error" val alt_names = map fst alt_props val _ = ifexists (fn (name, _) => name <> "") alt_names then writeln "specification" else () in
arg
|> apsnd (Thm.unvarify_global thy)
|> process_all (zip3 alt_names rew_imps all_frees) 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 ist noch experimentell.