val _ = length args > 0 orelse input_error "Function has no arguments:"
fun add_bvs t is = add_loose_bnos (t, 0, is) val rvs = (subtract (op =) (fold add_bvs args []) (add_bvs rhs []))
|> map (fst o nth (rev qs))
val _ = null rvs orelse input_error
("Variable" ^ plural " ""s " rvs ^ commas_quote rvs ^ " occur" ^ plural "s""" rvs ^ " on right hand side only:")
val _ = forall (not o Term.exists_subterm
(fn Free (n, _) => member (op =) fnames n | _ => false)) (gs @ args)
orelse input_error "Defined function may not occur in premises or arguments"
val freeargs = map (fn t => subst_bounds (rev (map Free qs), t)) args val funvars = filter
(fn q => exists (exists_subterm (fn (Free q') $ _ => q = q' | _ => false)) freeargs) qs val _ = null funvars orelse (warning (cat_lines
["Bound variable" ^ plural " ""s " funvars ^
commas_quote (map fst funvars) ^ " occur" ^ plural "s""" funvars ^ " in function position.", "Misspelled constructor???"]); true) in
(fname, length args) end
val grouped_args = AList.group (op =) (map check eqs) val _ = grouped_args
|> map (fn (fname, ars) =>
length (distinct (op =) ars) = 1 orelse
error ("Function " ^ quote fname ^ " has different numbers of arguments in different equations"))
val not_defined = subtract (op =) (map fst grouped_args) fnames val _ = null not_defined
orelse error ("No defining equations for function" ^
plural " ""s " not_defined ^ commas_quote not_defined) in () end
(* preprocessors *)
type fixes = ((string * typ) * mixfix) list type'a spec = (Attrib.binding * 'a list) list
type preproc = function_config -> Proof.context -> fixes -> term spec ->
term list * (thm list -> thm spec) * (thm list -> thm listlist) * stringlist
val fname_of = fst o dest_Free o fst o strip_comb o fst o HOLogic.dest_eq o
HOLogic.dest_Trueprop o Logic.strip_imp_concl o snd o dest_all_all
fun mk_case_names i "" k = mk_case_names i (string_of_int (i + 1)) k
| mk_case_names _ _ 0 = []
| mk_case_names _ n 1 = [n]
| mk_case_names _ n k = map (fn i => n ^ "_" ^ string_of_int i) (1 upto k)
fun empty_preproc check (_: function_config) (ctxt: Proof.context) (fixes: fixes) spec = let val (bnds, tss) = split_list spec val ts = flat tss val _ = check ctxt fixes ts val fnames = map (fst o fst) fixes val indices = map (fn eq => find_index (curry op = (fname_of eq)) fnames) ts
fun sort xs = partition_list (fn i => fn (j,_) => i = j) 0 (length fnames - 1)
(indices ~~ xs) |> map (map snd)
(* using theorem names for case name currently disabled *) val cnames = map_index (fn (i, _) => mk_case_names i "" 1) bnds |> flat in
(ts, curry op ~~ bnds o Library.unflat tss, sort, cnames) end
(* context data *)
structure Data = Generic_Data
( type T =
thm list *
(term * info) Item_Net.T *
(bool -> Proof.context -> tactic) *
preproc val empty: T =
([],
Item_Net.init (op aconv o apply2 fst) (single o fst),
fn _ => error "Termination prover not configured",
empty_preproc check_defs) fun merge
((termination_rules1, functions1, termination_prover1, preproc1),
(termination_rules2, functions2, _, _)) : T =
(Thm.merge_thms (termination_rules1, termination_rules2),
Item_Net.merge (functions1, functions2),
termination_prover1,
preproc1)
)
fun termination_rule_tac ctxt = resolve_tac ctxt (#1 (Data.get (Context.Proof ctxt)))
val store_termination_rule = Data.map o @{apply 4(1)} o cons o Thm.trim_context
val get_functions = #2 o Data.get o Context.Proof
fun retrieve_function_data ctxt t =
Item_Net.retrieve (get_functions ctxt) t
|> (map o apsnd) (transform_function_data (Morphism.transfer_morphism' ctxt));
val add_function_data =
transform_function_data Morphism.trim_context_morphism #>
(fn info as {fs, termination, ...} =>
(Data.map o @{apply 4(2)}) (fold (fn f => Item_Net.update (f, info)) fs)
#> store_termination_rule termination)
fun termination_prover_tac quiet ctxt = #3 (Data.get (Context.Proof ctxt)) quiet ctxt val set_termination_prover = Data.map o @{apply 4(3)} o K
val get_preproc = #4 o Data.get o Context.Proof val set_preproc = Data.map o @{apply 4(4)} o K
fun import_function_data t ctxt = let val ct = Thm.cterm_of ctxt t fun inst_morph u =
Morphism.instantiate_morphism (Thm.match (Thm.cterm_of ctxt u, ct)) funmatch (u, data) =
SOME (transform_function_data (inst_morph u) data) handle Pattern.MATCH => NONE in
get_first match (retrieve_function_data ctxt t)
|> Option.map (transform_function_data (Morphism.transfer_morphism' ctxt)) end
fun import_last_function ctxt =
(case Item_Net.content (get_functions ctxt) of
[] => NONE
| (t, _) :: _ => letval (t', ctxt') = yield_singleton (Variable.import_terms true) t ctxt in import_function_data t' 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 ist noch experimentell.