fun target_of_update raw_updt = case raw_updt of
AddItems {id, ...} => id
| AddBoxes {id, ...} => id
| ResolveBox {id, ...} => id
| ShadowItem {id, ...} => id
fun replace_id_of_update raw_updt = let val id = target_of_update raw_updt val _ = assert (BoxID.has_incr_id id) "replace_id_of_update" val id' = BoxID.replace_incr_id id in case raw_updt of
AddItems {sc, raw_items, ...} =>
AddItems {id = id', sc = sc, raw_items = raw_items}
| AddBoxes {sc, init_assum, ...} =>
AddBoxes {id = id', sc = sc, init_assum = init_assum}
| ResolveBox {th, ...} => ResolveBox {id = id', th = th}
| ShadowItem {item, ...} => ShadowItem {id = id', item = item} end
(* Create raw_item from theorem. *) fun thm_to_ritem th = let val prop = Thm.prop_of th val _ = assert (UtilLogic.is_Trueprop prop) "thm_update: prop is not Trueprop." val _ = assert (not (Util.has_vars prop)) "thm_to_ritem: prop contains schematic variables." in
Fact (TY_PROP, [UtilLogic.dest_Trueprop prop], th) end
(* Create raw_update from id and theorem. *) fun thm_update (id, th) = if Thm.prop_of th aconv UtilLogic.pFalse then
ResolveBox {id = id, th = th} else
AddItems {id = id, sc = NONE, raw_items = [thm_to_ritem th]}
fun thm_update_sc sc (id, th) = if Thm.prop_of th aconv UtilLogic.pFalse then
ResolveBox {id = id, th = th} else
AddItems {id = id, sc = SOME sc, raw_items = [thm_to_ritem th]}
(* Apply the given existence theorem. Return a pair (ritems, th), ritemscontainthenewvariablesandthenewhandler,andthisthe instantiatedpropertyofthenewvariables,whichcaneitherbe processedfurther,ormadeintoanritemusingthm_update.
*) fun apply_exists_ritems ctxt ex_th = let val (vars, body) = (UtilLogic.strip_exists (UtilLogic.prop_of' ex_th))
|> Util.to_internal_vars ctxt
|> apsnd UtilLogic.mk_Trueprop in if null vars then ([], ex_th) else (map (BoxItem.var_to_fact) vars @ [Handler (vars, body, ex_th)],
Thm.assume (Thm.cterm_of ctxt body)) end
(* Print a list of raw items. *) fun update_info ctxt id ritems =
(Util.string_of_list' (ItemIO.string_of_raw_item ctxt)
(filter (not o BoxItem.is_handler_raw) ritems)) ^ " at box " ^ (BoxID.string_of_box_id id)
(* Print the source of the update. *) fun source_info {prfstep_name, source, ...} =
prfstep_name ^ " on " ^
(Util.string_of_list'
(fn {uid, ...} => "(" ^ string_of_int uid ^ ")") source)
type status = {
assums: term list,
handlers: (box_id * (term list * term * thm)) list,
items: (box_item * box_id list) Inttab.table,
queue: Updates_Heap.T,
resolve_th: thm option,
ctxt: Proof.context
}
signature STATUS = sig val empty_status: Proof.context -> status
val map_context: (Proof.context -> Proof.context) -> status -> status val add_handler: box_id * (term list * term * thm) -> status -> status val get_handlers: status -> (box_id * (term list * term * thm)) list val add_item: box_item -> status -> status val get_items: status -> box_item list val get_all_items_at_id: status -> box_id -> box_item list val get_num_items: status -> int val set_resolve_th: thm -> status -> status val get_resolve_th: status -> thm val add_prim_box: box_id -> term -> status -> int * status val add_resolved: box_id -> status -> status val get_init_assums: status -> box_id -> term list val get_init_assum: status -> int -> term
val lookup_item: status -> int -> (box_item * box_id list) option val clear_incr: status -> status val add_shadowed: box_id * box_item -> status -> status val query_shadowed: status -> box_id -> box_item -> bool val query_removed: status -> box_item -> bool
val find_fact: status -> box_id -> term -> thm option val find_ritem_exact: status -> box_id -> raw_item -> bool val invoke_handler: Proof.context -> term list * term * thm -> thm -> thm val get_on_resolve: status -> box_id -> int -> thm -> thm val find_prim_box: status -> box_id -> term -> int option
val map_queue: (Updates_Heap.T -> Updates_Heap.T) -> status -> status val add_to_queue: update -> status -> status val delmin_from_queue: status -> status end;
fun get_resolve_th {resolve_th, ...} = case resolve_th of
NONE => raise Fail "get_resolve_th: not resolved."
| SOME th => th
fun add_prim_box parent_id assum
{assums, handlers, items, queue, ctxt, resolve_th} = let val (id, ctxt') = BoxID.add_prim_id parent_id ctxt in
(id, {assums = assums @ [assum],
handlers = handlers, items = items, queue = queue,
ctxt = ctxt', resolve_th = resolve_th}) end
fun add_resolved id {assums, handlers, items, queue, ctxt, resolve_th} = let val ctxt' = BoxID.add_resolved id ctxt in
{assums = assums, handlers = handlers, items = items, queue = queue,
ctxt = ctxt' |> RewriteTable.clean_resolved id
|> PropertyData.clean_resolved id
|> WellformData.clean_resolved id,
resolve_th = resolve_th} end
fun get_init_assums {assums, ctxt, ...} id = let val parents = BoxID.get_ancestors_prim ctxt id in map (nth assums) parents end
fun get_init_assum {assums, ...} prim_id =
nth assums prim_id
fun lookup_item {items, ...} uid =
Inttab.lookup items uid
fun clear_incr st =
st |> map_items (
Inttab.map (fn _ => fn (item, ids) => (BoxItem.item_replace_incr item, ids)))
fun add_shadowed (shadow_id, {uid, ...}) (st as {ctxt, ...}) = case lookup_item st uid of
NONE => raise Fail "add_shadowed: item not found."
| SOME (item, shadow_ids) => let val shadow_ids' = (shadow_id :: shadow_ids)
|> Util.max_partial (BoxID.is_eq_ancestor ctxt) in
st |> map_items (Inttab.update (uid, (item, shadow_ids'))) end
fun query_shadowed (st as {ctxt, ...}) shadow_id {uid, ...} = case lookup_item st uid of
NONE => raise Fail "query_shadowed: item not found."
| SOME (_, shadow_ids) => exists (BoxID.is_eq_descendent ctxt shadow_id) shadow_ids
fun query_removed st (item as {id, ...}) = query_shadowed st id item
(* Try to find fact at id or above with the proposition t. Return SOME thiffound.
*) fun find_fact (st as {ctxt, ...}) id t = let val ct = Thm.cterm_of ctxt t val items = get_items_at_id st id val res = (WellformData.find_fact ctxt items (id, ct))
|> filter (fn (id', _) => id' = id) in case res of
[] => NONE
| (_, th) :: _ => SOME th end
(* Find item with the exact ty_str and tname, whose id is an eq-ancestorofthegivenid.
Therearetwospecialcases:iftheriteminquestionisoftypeEQ andPROPERTY,inwhichcasewetrytofinditintherewritetable.
*) fun find_ritem_exact (st as {ctxt, ...}) id ritem = case ritem of
Handler _ => false
| Fact (ty_str, tname, _) => if ty_str = TY_EQ then let val (lhs, rhs) = the_pair (BoxItem.get_tname_raw ritem) in
RewriteTable.is_equiv_t id ctxt (lhs, rhs) end elseif ty_str = TY_PROPERTY then let val prop = the_single tname val infos =
(PropertyData.get_property_t ctxt (id, prop))
|> filter (fn (id', _) => BoxID.is_eq_ancestor ctxt id' id) in not (null infos) end else let val thy = Proof_Context.theory_of ctxt val {shadow_fn, ...} = ItemIO.get_io_info thy ty_str
fun eq_item {ty_str = ty_str2, tname = tname2, ...} = if ty_str <> ty_str2 thenfalseelse case shadow_fn of
NONE => eq_list (op aconv) (tname, map Thm.term_of tname2)
| SOME (f, _) => f ctxt id (tname, tname2) in exists eq_item (get_all_items_at_id st id) end
(* Invoke a single handler (vars, t, ex_th) on the theorem th. *) fun invoke_handler ctxt (vars, t, ex_th) th = if member (op aconv) (Thm.hyps_of th) t then
th |> Thm.implies_intr (Thm.cterm_of ctxt t)
|> fold (UtilLogic.ex_elim ctxt) (rev vars)
|> Thm.elim_implies ex_th else th
(* Derive the consequence if box id is resolved, to the parent id formedbygettingparentatindexi.
*) fun get_on_resolve (st as {ctxt, ...}) id i th = let (* First get list of handlers to invoke. *) val prim_id = nth id i val handlers =
st |> get_handlers
|> filter (fn (id', _) =>
BoxID.is_eq_ancestor ctxt [prim_id] id' andalso
BoxID.is_eq_descendent ctxt id id')
|> map snd val init_assum = get_init_assum st prim_id val th' = th |> fold (invoke_handler ctxt) handlers
|> Thm.implies_intr (Thm.cterm_of ctxt init_assum)
|> apply_to_thm UtilLogic.rewrite_from_contra_form val _ = assert (prim_id <> BoxID.home_id orelse null (Thm.hyps_of th')) "get_on_resolve: did not remove all hypothesis at box 0." in
th' end
(* Find a primitive box (if there is any) whose initial facts agree exactlywiththegiveninitialfacts.Notewecannotyethandlenew variables.
*) fun find_prim_box {assums, ctxt, ...} id init_assum = let fun agree_at_id prim_id' = let val parent = BoxID.get_parent_prim ctxt prim_id' val is_equiv_t = RewriteTable.is_equiv_t parent ctxt in
is_equiv_t (init_assum, nth assums prim_id') end
fun can_test_id prim_id' =
BoxID.is_eq_ancestor ctxt (BoxID.get_parent_prim ctxt prim_id') id
val ids_to_test = filter can_test_id (0 upto (length assums - 1)) in
find_first agree_at_id ids_to_test end
fun map_queue f {assums, handlers, items, queue, ctxt, resolve_th} =
{assums = assums, handlers = handlers, items = items, queue = f queue,
ctxt = ctxt, resolve_th = resolve_th}
fun add_to_queue updt = map_queue (Updates_Heap.insert updt) val delmin_from_queue = map_queue Updates_Heap.delete_min
end(* structure Status *)
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.