553 |
553 |
554 fun add_node kind name parents feats deps (access_G, (fact_xtab, feat_xtab), learns) = |
554 fun add_node kind name parents feats deps (access_G, (fact_xtab, feat_xtab), learns) = |
555 ((Graph.new_node (name, (kind, feats, deps)) access_G |
555 ((Graph.new_node (name, (kind, feats, deps)) access_G |
556 handle Graph.DUP _ => Graph.map_node name (K (kind, feats, deps)) access_G) |
556 handle Graph.DUP _ => Graph.map_node name (K (kind, feats, deps)) access_G) |
557 |> fold (add_edge_to name) parents, |
557 |> fold (add_edge_to name) parents, |
558 (add_to_xtab name fact_xtab, fold maybe_add_to_xtab feats feat_xtab), |
558 (maybe_add_to_xtab name fact_xtab, fold maybe_add_to_xtab feats feat_xtab), |
559 (name, feats, deps) :: learns) |
559 (name, feats, deps) :: learns) |
560 |
560 |
561 fun try_graph ctxt when def f = |
561 fun try_graph ctxt when def f = |
562 f () |
562 f () |
563 handle |
563 handle |
1219 |
1219 |
1220 val access_G = access_G |> Graph.default_node (name, (Isar_Proof, feats, deps)) |
1220 val access_G = access_G |> Graph.default_node (name, (Isar_Proof, feats, deps)) |
1221 val (parents, access_G) = ([], access_G) |> fold maybe_learn_from parents |
1221 val (parents, access_G) = ([], access_G) |> fold maybe_learn_from parents |
1222 val (deps, _) = ([], access_G) |> fold maybe_learn_from deps |
1222 val (deps, _) = ([], access_G) |> fold maybe_learn_from deps |
1223 |
1223 |
1224 val fact_xtab = add_to_xtab name fact_xtab |
1224 val fact_xtab = maybe_add_to_xtab name fact_xtab |
1225 val feat_xtab = fold maybe_add_to_xtab feats feat_xtab |
1225 val feat_xtab = fold maybe_add_to_xtab feats feat_xtab |
1226 in |
1226 in |
1227 ((name, parents, feats, deps), (access_G, (fact_xtab, feat_xtab))) |
1227 ((name, parents, feats, deps), (access_G, (fact_xtab, feat_xtab))) |
1228 end |
1228 end |
1229 |
1229 |
1329 | do_commit learns relearns flops |
1329 | do_commit learns relearns flops |
1330 {access_G, xtabs as ((num_facts0, _), _), ffds, freqs, dirty_facts} = |
1330 {access_G, xtabs as ((num_facts0, _), _), ffds, freqs, dirty_facts} = |
1331 let |
1331 let |
1332 val was_empty = Graph.is_empty access_G |
1332 val was_empty = Graph.is_empty access_G |
1333 |
1333 |
1334 val (learns, (access_G, xtabs)) = |
1334 val (learns, (access_G', xtabs')) = |
1335 fold_map (learn_wrt_access_graph ctxt) learns (access_G, xtabs) |
1335 fold_map (learn_wrt_access_graph ctxt) learns (access_G, xtabs) |
1336 val (relearns, access_G) = |
1336 val (relearns, access_G'') = |
1337 fold_map (relearn_wrt_access_graph ctxt) relearns access_G |
1337 fold_map (relearn_wrt_access_graph ctxt) relearns access_G' |
1338 |
1338 |
1339 val access_G = access_G |> fold flop_wrt_access_graph flops |
1339 val access_G''' = access_G'' |> fold flop_wrt_access_graph flops |
1340 val dirty_facts = |
1340 val dirty_facts' = |
1341 (case (was_empty, dirty_facts) of |
1341 (case (was_empty, dirty_facts) of |
1342 (false, SOME names) => SOME (map #1 learns @ map #1 relearns @ names) |
1342 (false, SOME names) => SOME (map #1 learns @ map #1 relearns @ names) |
1343 | _ => NONE) |
1343 | _ => NONE) |
1344 |
1344 |
1345 val (ffds', freqs') = |
1345 val (ffds', freqs') = |
1346 if null relearns then |
1346 if null relearns then |
1347 recompute_ffds_freqs_from_learns |
1347 recompute_ffds_freqs_from_learns |
1348 (map (fn (name, _, feats, deps) => (name, feats, deps)) learns) xtabs num_facts0 |
1348 (map (fn (name, _, feats, deps) => (name, feats, deps)) learns) xtabs' num_facts0 |
1349 ffds freqs |
1349 ffds freqs |
1350 else |
1350 else |
1351 recompute_ffds_freqs_from_access_G access_G xtabs |
1351 recompute_ffds_freqs_from_access_G access_G''' xtabs' |
1352 in |
1352 in |
1353 {access_G = access_G, xtabs = xtabs, ffds = ffds', freqs = freqs', |
1353 {access_G = access_G''', xtabs = xtabs', ffds = ffds', freqs = freqs', |
1354 dirty_facts = dirty_facts} |
1354 dirty_facts = dirty_facts'} |
1355 end |
1355 end |
1356 |
1356 |
1357 fun commit last learns relearns flops = |
1357 fun commit last learns relearns flops = |
1358 (if debug andalso auto_level = 0 then Output.urgent_message "Committing..." else (); |
1358 (if debug andalso auto_level = 0 then Output.urgent_message "Committing..." else (); |
1359 map_state ctxt (do_commit (rev learns) relearns flops); |
1359 map_state ctxt (do_commit (rev learns) relearns flops); |
1583 |> Par_List.map (apsnd (fn f => f ())) |
1583 |> Par_List.map (apsnd (fn f => f ())) |
1584 val mesh = mesh_facts (eq_snd (gen_eq_thm ctxt)) max_facts mess |> add_and_take |
1584 val mesh = mesh_facts (eq_snd (gen_eq_thm ctxt)) max_facts mess |> add_and_take |
1585 in |
1585 in |
1586 (case (fact_filter, mess) of |
1586 (case (fact_filter, mess) of |
1587 (NONE, [(_, (mepo, _)), (_, (mash, _))]) => |
1587 (NONE, [(_, (mepo, _)), (_, (mash, _))]) => |
1588 [(meshN, mesh), (mepoN, mepo |> map fst |> add_and_take), |
1588 [(meshN, mesh), |
|
1589 (mepoN, mepo |> map fst |> add_and_take), |
1589 (mashN, mash |> map fst |> add_and_take)] |
1590 (mashN, mash |> map fst |> add_and_take)] |
1590 | _ => [(effective_fact_filter, mesh)]) |
1591 | _ => [(effective_fact_filter, mesh)]) |
1591 end |
1592 end |
1592 |
1593 |
1593 fun kill_learners () = Async_Manager.kill_threads MaShN "learner" |
1594 fun kill_learners () = Async_Manager.kill_threads MaShN "learner" |