src/HOL/Tools/SMT2/z3_new_replay.ML
changeset 56104 fd6e132ee4fb
parent 56099 bc036c1cf111
child 56245 84fc7dfa3cd4
equal deleted inserted replaced
56103:6689512f3710 56104:fd6e132ee4fb
     6 *)
     6 *)
     7 
     7 
     8 signature Z3_NEW_REPLAY =
     8 signature Z3_NEW_REPLAY =
     9 sig
     9 sig
    10   val replay: Proof.context -> SMT2_Translate.replay_data -> string list ->
    10   val replay: Proof.context -> SMT2_Translate.replay_data -> string list ->
    11     ((int * int) list * Z3_New_Proof.z3_step list) * thm
    11     ((int * (int * thm)) list * Z3_New_Proof.z3_step list) * thm
    12 end
    12 end
    13 
    13 
    14 structure Z3_New_Replay: Z3_NEW_REPLAY =
    14 structure Z3_New_Replay: Z3_NEW_REPLAY =
    15 struct
    15 struct
    16 
    16 
   104       let
   104       let
   105         val ct = Thm.cprem_of thm 1
   105         val ct = Thm.cprem_of thm 1
   106         val (thm', ctxt') = yield_singleton Assumption.add_assumes ct ctxt
   106         val (thm', ctxt') = yield_singleton Assumption.add_assumes ct ctxt
   107       in (thm' RS thm, ctxt') end
   107       in (thm' RS thm, ctxt') end
   108 
   108 
   109     fun add1 id fixes thm1 ((i, th), exact) ((idis, thms), (ctxt, ptab)) =
   109     fun add1 id fixes thm1 ((i, th), exact) ((iidths, thms), (ctxt, ptab)) =
   110       let
   110       let
   111         val (thm, ctxt') = if exact then (Thm.implies_elim thm1 th, ctxt) else assume thm1 ctxt
   111         val (thm, ctxt') = if exact then (Thm.implies_elim thm1 th, ctxt) else assume thm1 ctxt
   112         val thms' = if exact then thms else th :: thms
   112         val thms' = if exact then thms else th :: thms
   113       in (((id, i) :: idis, thms'), (ctxt', Inttab.update (id, (fixes, thm)) ptab)) end
   113       in (((i, (id, th)) :: iidths, thms'), (ctxt', Inttab.update (id, (fixes, thm)) ptab)) end
   114 
   114 
   115     fun add (Z3_New_Proof.Z3_Step {id, rule, concl, fixes, ...})
   115     fun add (Z3_New_Proof.Z3_Step {id, rule, concl, fixes, ...})
   116         (cx as ((idis, thms), (ctxt, ptab))) =
   116         (cx as ((iidths, thms), (ctxt, ptab))) =
   117       if Z3_New_Replay_Methods.is_assumption rule andalso rule <> Z3_New_Proof.Hypothesis then
   117       if Z3_New_Replay_Methods.is_assumption rule andalso rule <> Z3_New_Proof.Hypothesis then
   118         let
   118         let
   119           val ct = SMT2_Util.certify ctxt concl
   119           val ct = SMT2_Util.certify ctxt concl
   120           val thm1 = Thm.trivial ct |> Conv.fconv_rule (Conv.arg1_conv (revert_conv outer_ctxt))
   120           val thm1 = Thm.trivial ct |> Conv.fconv_rule (Conv.arg1_conv (revert_conv outer_ctxt))
   121           val thm2 = singleton (Variable.export ctxt outer_ctxt) thm1
   121           val thm2 = singleton (Variable.export ctxt outer_ctxt) thm1
   122         in
   122         in
   123           (case lookup_assm assms_net (Thm.cprem_of thm2 1) of
   123           (case lookup_assm assms_net (Thm.cprem_of thm2 1) of
   124             [] =>
   124             [] =>
   125               let val (thm, ctxt') = assume thm1 ctxt
   125               let val (thm, ctxt') = assume thm1 ctxt
   126               in ((idis, thms), (ctxt', Inttab.update (id, (fixes, thm)) ptab)) end
   126               in ((iidths, thms), (ctxt', Inttab.update (id, (fixes, thm)) ptab)) end
   127           | ithms => fold (add1 id fixes thm1) ithms cx)
   127           | ithms => fold (add1 id fixes thm1) ithms cx)
   128         end
   128         end
   129       else
   129       else
   130         cx
   130         cx
   131   in fold add steps (([], []), (ctxt, Inttab.empty)) end
   131   in fold add steps (([], []), (ctxt, Inttab.empty)) end
   174 
   174 
   175 fun replay outer_ctxt
   175 fun replay outer_ctxt
   176     ({context=ctxt, typs, terms, rewrite_rules, assms} : SMT2_Translate.replay_data) output =
   176     ({context=ctxt, typs, terms, rewrite_rules, assms} : SMT2_Translate.replay_data) output =
   177   let
   177   let
   178     val (steps, ctxt2) = Z3_New_Proof.parse typs terms output ctxt
   178     val (steps, ctxt2) = Z3_New_Proof.parse typs terms output ctxt
   179     val ((idis, rules), (ctxt3, assumed)) = add_asserted outer_ctxt rewrite_rules assms steps ctxt2
   179     val ((iidths, rules), (ctxt3, assumed)) = add_asserted outer_ctxt rewrite_rules assms steps ctxt2
   180   in
   180   in
   181     if Config.get ctxt3 SMT2_Config.filter_only_facts then
   181     if Config.get ctxt3 SMT2_Config.filter_only_facts then
   182       ((idis, steps), TrueI)
   182       ((iidths, steps), TrueI)
   183     else
   183     else
   184       let
   184       let
   185         val ctxt4 = put_simpset (Z3_New_Replay_Util.make_simpset ctxt3 []) ctxt3
   185         val ctxt4 = put_simpset (Z3_New_Replay_Util.make_simpset ctxt3 []) ctxt3
   186         val proofs = fold (replay_step ctxt4 assumed) steps assumed
   186         val proofs = fold (replay_step ctxt4 assumed) steps assumed
   187         val (_, Z3_New_Proof.Z3_Step {id, ...}) = split_last steps
   187         val (_, Z3_New_Proof.Z3_Step {id, ...}) = split_last steps