src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML
changeset 54432 68f8bd1641da
parent 54143 18def1c73c79
child 54503 b490e15a5e19
equal deleted inserted replaced
54431:e98996c2a32c 54432:68f8bd1641da
   214 val encode_strs = map encode_str #> space_implode " "
   214 val encode_strs = map encode_str #> space_implode " "
   215 val unencode_str = String.explode #> unmeta_chars []
   215 val unencode_str = String.explode #> unmeta_chars []
   216 val unencode_strs =
   216 val unencode_strs =
   217   space_explode " " #> filter_out (curry (op =) "") #> map unencode_str
   217   space_explode " " #> filter_out (curry (op =) "") #> map unencode_str
   218 
   218 
   219 fun freshish_name () =
       
   220   Date.fmt ".%Y%m%d_%H%M%S__" (Date.fromTimeLocal (Time.now ())) ^
       
   221   serial_string ()
       
   222 
       
   223 (* Avoid scientific notation *)
   219 (* Avoid scientific notation *)
   224 fun safe_str_of_real r =
   220 fun safe_str_of_real r =
   225   if r < 0.00001 then "0.00001"
   221   if r < 0.00001 then "0.00001"
   226   else if r >= 1000000.0 then "1000000"
   222   else if r >= 1000000.0 then "1000000"
   227   else Markup.print_real r
   223   else Markup.print_real r
   280     ()
   276     ()
   281   end
   277   end
   282 
   278 
   283 fun learn _ _ _ [] = ()
   279 fun learn _ _ _ [] = ()
   284   | learn ctxt overlord save learns =
   280   | learn ctxt overlord save learns =
   285     (trace_msg ctxt (fn () => "MaSh learn " ^
   281     let val names = elide_string 1000 (space_implode " " (map #1 learns)) in
   286          elide_string 1000 (space_implode " " (map #1 learns)));
   282       (trace_msg ctxt (fn () => "MaSh learn" ^ (if names = "" then "" else " " ^ names));
   287      run_mash_tool ctxt overlord ([] |> save ? cons save_models_arg) false
   283        run_mash_tool ctxt overlord ([] |> save ? cons save_models_arg) false
   288                    (learns, str_of_learn) (K ()))
   284                      (learns, str_of_learn) (K ()))
       
   285     end
   289 
   286 
   290 fun relearn _ _ _ [] = ()
   287 fun relearn _ _ _ [] = ()
   291   | relearn ctxt overlord save relearns =
   288   | relearn ctxt overlord save relearns =
   292     (trace_msg ctxt (fn () => "MaSh relearn " ^
   289     (trace_msg ctxt (fn () => "MaSh relearn " ^
   293          elide_string 1000 (space_implode " " (map #1 relearns)));
   290          elide_string 1000 (space_implode " " (map #1 relearns)));
  1024                      used_ths =
  1021                      used_ths =
  1025   if is_mash_enabled () then
  1022   if is_mash_enabled () then
  1026     launch_thread (timeout |> the_default one_day) (fn () =>
  1023     launch_thread (timeout |> the_default one_day) (fn () =>
  1027         let
  1024         let
  1028           val thy = Proof_Context.theory_of ctxt
  1025           val thy = Proof_Context.theory_of ctxt
  1029           val name = freshish_name ()
       
  1030           val feats = features_of ctxt thy 0 Symtab.empty (Local, General) [t] |> map fst
  1026           val feats = features_of ctxt thy 0 Symtab.empty (Local, General) [t] |> map fst
  1031         in
  1027         in
  1032           peek_state ctxt overlord (fn {access_G, ...} =>
  1028           peek_state ctxt overlord (fn {access_G, ...} =>
  1033               let
  1029               let
  1034                 val parents = maximal_wrt_access_graph access_G facts
  1030                 val parents = maximal_wrt_access_graph access_G facts
  1035                 val deps =
  1031                 val deps =
  1036                   used_ths |> filter (is_fact_in_graph access_G)
  1032                   used_ths |> filter (is_fact_in_graph access_G)
  1037                            |> map nickname_of_thm
  1033                            |> map nickname_of_thm
  1038               in
  1034               in
  1039                 MaSh.learn ctxt overlord true [(name, parents, feats, deps)]
  1035                 MaSh.learn ctxt overlord true [("", parents, feats, deps)]
  1040               end);
  1036               end);
  1041           (true, "")
  1037           (true, "")
  1042         end)
  1038         end)
  1043   else
  1039   else
  1044     ()
  1040     ()