src/HOL/Tools/Sledgehammer/sledgehammer_minimize_isar.ML
changeset 52626 79a4e7f8d758
parent 52611 831f7479c74f
child 52632 23393c31c7fe
equal deleted inserted replaced
52625:b74bf6c0e5a1 52626:79a4e7f8d758
    22 open Sledgehammer_Preplay
    22 open Sledgehammer_Preplay
    23 
    23 
    24 val slack = 1.3
    24 val slack = 1.3
    25 
    25 
    26 fun min_deps_of_step (_ : preplay_interface) (step as Let _) = step
    26 fun min_deps_of_step (_ : preplay_interface) (step as Let _) = step
    27   | min_deps_of_step {get_time, set_time, preplay_quietly, set_preplay_fail, ...}
    27   | min_deps_of_step {get_preplay_time, set_preplay_time, preplay_quietly, ...}
    28       (step as Prove (qs, xs, l, t, subproofs, By ((lfs, gfs), method))) =
    28       (step as Prove (qs, xs, l, t, subproofs, By ((lfs, gfs), method))) =
    29   (case get_time l of
    29   (case get_preplay_time l of
    30     (* don't touch steps that time out *)
    30     (* don't touch steps that time out or fail; minimizing won't help *)
    31     (true, _) => (set_preplay_fail true; step)
    31     (true, _) => step
    32   | (false, time) =>
    32   | (false, time) =>
    33     let
    33     let
    34       fun mk_step_lfs_gfs lfs gfs =
    34       fun mk_step_lfs_gfs lfs gfs =
    35         Prove (qs, xs, l, t, subproofs, By ((lfs, gfs), method))
    35         Prove (qs, xs, l, t, subproofs, By ((lfs, gfs), method))
    36       val mk_step_gfs_lfs = curry (swap #> uncurry mk_step_lfs_gfs)
    36       val mk_step_gfs_lfs = curry (swap #> uncurry mk_step_lfs_gfs)
    44 
    44 
    45       val (time, min_lfs) = minimize_facts (mk_step_gfs_lfs gfs) time [] lfs
    45       val (time, min_lfs) = minimize_facts (mk_step_gfs_lfs gfs) time [] lfs
    46       val (time, min_gfs) = minimize_facts (mk_step_lfs_gfs min_lfs) time [] gfs
    46       val (time, min_gfs) = minimize_facts (mk_step_lfs_gfs min_lfs) time [] gfs
    47 
    47 
    48     in
    48     in
    49       set_time l (false, time);
    49       set_preplay_time l (false, time);
    50       mk_step_lfs_gfs min_lfs min_gfs
    50       mk_step_lfs_gfs min_lfs min_gfs
    51     end)
    51     end)
    52 
    52 
    53 fun minimize_dependencies_and_remove_unrefed_steps (preplay_interface as
    53 fun minimize_dependencies_and_remove_unrefed_steps preplay_interface proof =
    54   {set_time, set_preplay_fail, ...} : preplay_interface) proof =
       
    55   let
    54   let
    56     fun cons_to xs x = x :: xs
    55     fun cons_to xs x = x :: xs
    57 
    56 
    58     val add_lfs = fold (Ord_List.insert label_ord)
    57     val add_lfs = fold (Ord_List.insert label_ord)
    59 
    58 
    81           if Ord_List.member label_ord refed l then
    80           if Ord_List.member label_ord refed l then
    82             do_refed_step step
    81             do_refed_step step
    83             |>> Ord_List.union label_ord refed
    82             |>> Ord_List.union label_ord refed
    84             ||> cons_to accu
    83             ||> cons_to accu
    85           else
    84           else
    86             (set_time l zero_preplay_time; (* remove unrefed step! *)
    85             (refed, accu)
    87              (refed, accu))
       
    88 
    86 
    89     and do_refed_step step =
    87     and do_refed_step step =
    90       min_deps_of_step preplay_interface step
    88       min_deps_of_step preplay_interface step
    91       |> do_refed_step'
    89       |> do_refed_step'
    92 
    90 
   102         in
   100         in
   103           (refed, step)
   101           (refed, step)
   104         end
   102         end
   105 
   103 
   106   in
   104   in
   107     set_preplay_fail false; (* step(s) causing the failure may be removed *)
       
   108     snd (do_proof proof)
   105     snd (do_proof proof)
   109   end
   106   end
   110 
   107 
   111 
   108 
   112 end
   109 end