src/HOL/Tools/Sledgehammer/sledgehammer_isar_preplay.ML
changeset 55280 f0187a12b8f2
parent 55279 df41d34d1324
child 55284 bd27ac6ad1c3
equal deleted inserted replaced
55279:df41d34d1324 55280:f0187a12b8f2
    51     val enrich_with_assms = fold (uncurry enrich_with_fact)
    51     val enrich_with_assms = fold (uncurry enrich_with_fact)
    52 
    52 
    53     fun enrich_with_proof (Proof (_, assms, isar_steps)) =
    53     fun enrich_with_proof (Proof (_, assms, isar_steps)) =
    54       enrich_with_assms assms #> fold enrich_with_step isar_steps
    54       enrich_with_assms assms #> fold enrich_with_step isar_steps
    55     and enrich_with_step (Let _) = I
    55     and enrich_with_step (Let _) = I
    56       | enrich_with_step (Prove (_, _, l, t, subproofs, _)) =
    56       | enrich_with_step (Prove (_, _, l, t, subproofs, _, _)) =
    57         enrich_with_fact l t #> fold enrich_with_proof subproofs
    57         enrich_with_fact l t #> fold enrich_with_proof subproofs
    58   in
    58   in
    59     enrich_with_proof proof ctxt
    59     enrich_with_proof proof ctxt
    60   end
    60   end
    61 
    61 
    86   let
    86   let
    87     val thy = Proof_Context.theory_of ctxt
    87     val thy = Proof_Context.theory_of ctxt
    88 
    88 
    89     val concl = 
    89     val concl = 
    90       (case try List.last steps of
    90       (case try List.last steps of
    91         SOME (Prove (_, [], _, t, _, _)) => t
    91         SOME (Prove (_, [], _, t, _, _, _)) => t
    92       | _ => raise Fail "preplay error: malformed subproof")
    92       | _ => raise Fail "preplay error: malformed subproof")
    93 
    93 
    94     val var_idx = maxidx_of_term concl + 1
    94     val var_idx = maxidx_of_term concl + 1
    95     fun var_of_free (x, T) = Var ((x, var_idx), T)
    95     fun var_of_free (x, T) = Var ((x, var_idx), T)
    96     val subst = map (`var_of_free #> swap #> apfst Free) fixed_frees
    96     val subst = map (`var_of_free #> swap #> apfst Free) fixed_frees
   120     | Blast_Method => blast_tac ctxt
   120     | Blast_Method => blast_tac ctxt
   121     | Algebra_Method => Groebner.algebra_tac [] [] ctxt
   121     | Algebra_Method => Groebner.algebra_tac [] [] ctxt
   122     | _ => raise Fail "Sledgehammer_Isar_Preplay: tac_of_method"))
   122     | _ => raise Fail "Sledgehammer_Isar_Preplay: tac_of_method"))
   123 
   123 
   124 (* main function for preplaying Isar steps; may throw exceptions *)
   124 (* main function for preplaying Isar steps; may throw exceptions *)
   125 fun raw_preplay_step_for_method ctxt timeout meth
   125 fun raw_preplay_step_for_method ctxt timeout meth (Prove (_, xs, _, t, subproofs, fact_names, _)) =
   126     (Prove (_, xs, _, t, subproofs, (fact_names, _))) =
       
   127   let
   126   let
   128     val goal =
   127     val goal =
   129       (case xs of
   128       (case xs of
   130         [] => t
   129         [] => t
   131       | _ =>
   130       | _ =>
   184   | add_preplay_outcomes (Played time1) (Played time2) = Played (Time.+ (time1, time2))
   183   | add_preplay_outcomes (Played time1) (Played time2) = Played (Time.+ (time1, time2))
   185   | add_preplay_outcomes play1 play2 =
   184   | add_preplay_outcomes play1 play2 =
   186     Play_Timed_Out (Time.+ (pairself time_of_play (play1, play2)))
   185     Play_Timed_Out (Time.+ (pairself time_of_play (play1, play2)))
   187 
   186 
   188 fun set_preplay_outcomes_of_isar_step ctxt timeout preplay_data
   187 fun set_preplay_outcomes_of_isar_step ctxt timeout preplay_data
   189       (step as Prove (_, _, l, _, _, (_, meths))) meths_outcomes0 =
   188       (step as Prove (_, _, l, _, _, _, meths)) meths_outcomes0 =
   190     let
   189     let
   191       fun lazy_preplay meth =
   190       fun lazy_preplay meth =
   192         Lazy.lazy (fn () => preplay_isar_step_for_method ctxt timeout meth step)
   191         Lazy.lazy (fn () => preplay_isar_step_for_method ctxt timeout meth step)
   193       val meths_outcomes = meths_outcomes0
   192       val meths_outcomes = meths_outcomes0
   194         |> map (apsnd Lazy.value)
   193         |> map (apsnd Lazy.value)
   227 fun fastest_method_of_isar_step preplay_data =
   226 fun fastest_method_of_isar_step preplay_data =
   228   the o Canonical_Label_Tab.lookup preplay_data
   227   the o Canonical_Label_Tab.lookup preplay_data
   229   #> get_best_method_outcome Lazy.force
   228   #> get_best_method_outcome Lazy.force
   230   #> fst
   229   #> fst
   231 
   230 
   232 fun forced_outcome_of_step preplay_data (Prove (_, _, l, _, _, (_, meths))) =
   231 fun forced_outcome_of_step preplay_data (Prove (_, _, l, _, _, _, meths)) =
   233     Lazy.force (preplay_outcome_of_isar_step_for_method preplay_data l (the_single meths))
   232     Lazy.force (preplay_outcome_of_isar_step_for_method preplay_data l (the_single meths))
   234   | forced_outcome_of_step _ _ = Played Time.zeroTime
   233   | forced_outcome_of_step _ _ = Played Time.zeroTime
   235 
   234 
   236 fun preplay_outcome_of_isar_proof preplay_data (Proof (_, _, steps)) =
   235 fun preplay_outcome_of_isar_proof preplay_data (Proof (_, _, steps)) =
   237   fold_isar_steps (add_preplay_outcomes o forced_outcome_of_step preplay_data) steps
   236   fold_isar_steps (add_preplay_outcomes o forced_outcome_of_step preplay_data) steps