src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML
changeset 48442 3c9890c19e90
parent 48441 2d2f009ca8eb
child 48531 7da5d3b8aef4
equal deleted inserted replaced
48441:2d2f009ca8eb 48442:3c9890c19e90
   622 fun max_suggs_of max_facts = max_facts + Int.min (50, max_facts)
   622 fun max_suggs_of max_facts = max_facts + Int.min (50, max_facts)
   623 
   623 
   624 fun is_fact_in_graph fact_G (_, th) =
   624 fun is_fact_in_graph fact_G (_, th) =
   625   can (Graph.get_node fact_G) (nickname_of th)
   625   can (Graph.get_node fact_G) (nickname_of th)
   626 
   626 
   627 fun interleave [] ys = ys
   627 fun interleave 0 _ _ = []
   628   | interleave xs [] = xs
   628   | interleave n [] ys = take n ys
   629   | interleave (x :: xs) (y :: ys) = x :: y :: interleave xs ys
   629   | interleave n xs [] = take n xs
       
   630   | interleave 1 (x :: _) _ = [x]
       
   631   | interleave n (x :: xs) (y :: ys) = x :: y :: interleave (n - 2) xs ys
   630 
   632 
   631 fun mash_suggested_facts ctxt ({overlord, ...} : params) prover max_facts hyp_ts
   633 fun mash_suggested_facts ctxt ({overlord, ...} : params) prover max_facts hyp_ts
   632                          concl_t facts =
   634                          concl_t facts =
   633   let
   635   let
   634     val thy = Proof_Context.theory_of ctxt
   636     val thy = Proof_Context.theory_of ctxt
   650             (* The weights currently returned by "mash.py" are too extreme to
   652             (* The weights currently returned by "mash.py" are too extreme to
   651                make any sense. *)
   653                make any sense. *)
   652             |> map fst
   654             |> map fst
   653     val (unk_global, unk_local) =
   655     val (unk_global, unk_local) =
   654       facts |> filter_out (is_fact_in_graph fact_G)
   656       facts |> filter_out (is_fact_in_graph fact_G)
   655             |> List.partition (fn ((_, (loc, _)), _) => loc = Global)
   657             |> List.partition (fn ((_, (scope, _)), _) => scope = Global)
   656   in (interleave unk_local sels |> weight_mepo_facts, unk_global) end
   658   in (interleave max_facts unk_local sels |> weight_mepo_facts, unk_global) end
   657 
   659 
   658 fun add_to_fact_graph ctxt (name, parents, feats, deps) (adds, graph) =
   660 fun add_to_fact_graph ctxt (name, parents, feats, deps) (adds, graph) =
   659   let
   661   let
   660     fun maybe_add_from from (accum as (parents, graph)) =
   662     fun maybe_add_from from (accum as (parents, graph)) =
   661       try_graph ctxt "updating graph" accum (fn () =>
   663       try_graph ctxt "updating graph" accum (fn () =>
   670 fun launch_thread timeout task =
   672 fun launch_thread timeout task =
   671   let
   673   let
   672     val hard_timeout = time_mult learn_timeout_slack timeout
   674     val hard_timeout = time_mult learn_timeout_slack timeout
   673     val birth_time = Time.now ()
   675     val birth_time = Time.now ()
   674     val death_time = Time.+ (birth_time, hard_timeout)
   676     val death_time = Time.+ (birth_time, hard_timeout)
   675     val desc = ("machine learner for Sledgehammer", "")
   677     val desc = ("Machine learner for Sledgehammer", "")
   676   in Async_Manager.launch MaShN birth_time death_time desc task end
   678   in Async_Manager.launch MaShN birth_time death_time desc task end
   677 
   679 
   678 fun freshish_name () =
   680 fun freshish_name () =
   679   Date.fmt ".%Y_%m_%d_%H_%M_%S__" (Date.fromTimeLocal (Time.now ())) ^
   681   Date.fmt ".%Y_%m_%d_%H_%M_%S__" (Date.fromTimeLocal (Time.now ())) ^
   680   serial_string ()
   682   serial_string ()