src/HOL/Tools/Sledgehammer/sledgehammer_reconstruct.ML
changeset 50010 17488e45eb5a
parent 50005 e9a9bff107da
child 50012 01cb92151a53
equal deleted inserted replaced
50009:e48de0410307 50010:17488e45eb5a
   292   Prove of isar_qualifier list * label * term * byline
   292   Prove of isar_qualifier list * label * term * byline
   293 and byline =
   293 and byline =
   294   By_Metis of facts |
   294   By_Metis of facts |
   295   Case_Split of isar_step list list * facts
   295   Case_Split of isar_step list list * facts
   296 
   296 
   297 val assum_prefix = "a"
       
   298 val have_prefix = "f"
   297 val have_prefix = "f"
   299 val raw_prefix = "x"
   298 val raw_prefix = "x"
   300 
   299 
   301 fun raw_label_for_name (num, ss) =
   300 fun raw_label_for_name (num, ss) =
   302   case resolve_conjecture ss of
   301   case resolve_conjecture ss of
   675         (if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^
   674         (if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^
   676         do_indent 0 ^ "proof -\n" ^ do_steps "" "" 1 proof ^ do_indent 0 ^
   675         do_indent 0 ^ "proof -\n" ^ do_steps "" "" 1 proof ^ do_indent 0 ^
   677         (if n <> 1 then "next" else "qed")
   676         (if n <> 1 then "next" else "qed")
   678   in do_proof end
   677   in do_proof end
   679 
   678 
   680 (* FIXME: Still needed? Try with SPASS proofs perhaps. *)
       
   681 val kill_duplicate_assumptions_in_proof =
       
   682   let
       
   683     fun relabel_facts subst =
       
   684       apfst (map (fn l => AList.lookup (op =) subst l |> the_default l))
       
   685     fun do_step (step as Assume (l, t)) (proof, subst, assums) =
       
   686         (case AList.lookup (op aconv) assums t of
       
   687            SOME l' => (proof, (l, l') :: subst, assums)
       
   688          | NONE => (step :: proof, subst, (t, l) :: assums))
       
   689       | do_step (Prove (qs, l, t, by)) (proof, subst, assums) =
       
   690         (Prove (qs, l, t,
       
   691                 case by of
       
   692                   By_Metis facts => By_Metis (relabel_facts subst facts)
       
   693                 | Case_Split (proofs, facts) =>
       
   694                   Case_Split (map do_proof proofs,
       
   695                               relabel_facts subst facts)) ::
       
   696          proof, subst, assums)
       
   697       | do_step step (proof, subst, assums) = (step :: proof, subst, assums)
       
   698     and do_proof proof = fold do_step proof ([], [], []) |> #1 |> rev
       
   699   in do_proof end
       
   700 
       
   701 fun used_labels_of_step (Prove (_, _, _, by)) =
   679 fun used_labels_of_step (Prove (_, _, _, by)) =
   702     (case by of
   680     (case by of
   703        By_Metis (ls, _) => ls
   681        By_Metis (ls, _) => ls
   704      | Case_Split (proofs, (ls, _)) =>
   682      | Case_Split (proofs, (ls, _)) =>
   705        fold (union (op =) o used_labels_of) proofs ls)
   683        fold (union (op =) o used_labels_of) proofs ls)
   727     fun aux _ _ _ [] = []
   705     fun aux _ _ _ [] = []
   728       | aux subst depth (next_assum, next_fact) (Assume (l, t) :: proof) =
   706       | aux subst depth (next_assum, next_fact) (Assume (l, t) :: proof) =
   729         if l = no_label then
   707         if l = no_label then
   730           Assume (l, t) :: aux subst depth (next_assum, next_fact) proof
   708           Assume (l, t) :: aux subst depth (next_assum, next_fact) proof
   731         else
   709         else
   732           let val l' = (prefix_for_depth depth assum_prefix, next_assum) in
   710           let val l' = (prefix_for_depth depth have_prefix, next_assum) in
   733             Assume (l', t) ::
   711             Assume (l', t) ::
   734             aux ((l, l') :: subst) depth (next_assum + 1, next_fact) proof
   712             aux ((l, l') :: subst) depth (next_assum + 1, next_fact) proof
   735           end
   713           end
   736       | aux subst depth (next_assum, next_fact)
   714       | aux subst depth (next_assum, next_fact)
   737             (Prove (qs, l, t, by) :: proof) =
   715             (Prove (qs, l, t, by) :: proof) =
   979           |> rpair (0, [])
   957           |> rpair (0, [])
   980           |-> fold_rev (add_desired_line fact_names frees)
   958           |-> fold_rev (add_desired_line fact_names frees)
   981           |> snd
   959           |> snd
   982         val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts)
   960         val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts)
   983         val conjs =
   961         val conjs =
   984           atp_proof
   962           atp_proof |> map_filter
   985           |> map_filter (fn Inference_Step (name as (_, ss), _, _, []) =>
   963             (fn Inference_Step (name as (_, ss), _, _, []) =>
   986                             if member (op =) ss conj_name then SOME name else NONE
   964                 if member (op =) ss conj_name then SOME name else NONE
   987                           | _ => NONE)
   965               | _ => NONE)
       
   966         val assms =
       
   967           atp_proof |> map_filter
       
   968             (fn Inference_Step (name as (_, ss), t, _, []) =>
       
   969                 if exists (String.isPrefix conjecture_prefix) ss andalso
       
   970                    not (member (op =) conjs name) then
       
   971                   SOME (Assume (raw_label_for_name name, t))
       
   972                 else
       
   973                   NONE
       
   974               | _ => NONE)
   988         fun dep_of_step (Definition_Step _) = NONE
   975         fun dep_of_step (Definition_Step _) = NONE
   989           | dep_of_step (Inference_Step (name, _, _, from)) = SOME (from, name)
   976           | dep_of_step (Inference_Step (name, _, _, from)) = SOME (from, name)
   990         val ref_graph = atp_proof |> map_filter dep_of_step |> make_ref_graph
   977         val ref_graph = atp_proof |> map_filter dep_of_step |> make_ref_graph
   991         val axioms = axioms_of_ref_graph ref_graph conjs
   978         val axioms = axioms_of_ref_graph ref_graph conjs
   992         val tainted = tainted_atoms_of_ref_graph ref_graph conjs
   979         val tainted = tainted_atoms_of_ref_graph ref_graph conjs
  1025           map (do_inf outer) infs
  1012           map (do_inf outer) infs
  1026         val (ext_time, isar_proof) =
  1013         val (ext_time, isar_proof) =
  1027           ref_graph
  1014           ref_graph
  1028           |> redirect_graph axioms tainted
  1015           |> redirect_graph axioms tainted
  1029           |> map (do_inf true)
  1016           |> map (do_inf true)
  1030           |> kill_duplicate_assumptions_in_proof
  1017           |> append assms
  1031           |> (if isar_shrinkage <= 1.0 andalso isar_proofs then
  1018           |> (if isar_shrinkage <= 1.0 andalso isar_proofs then
  1032                 pair (true, seconds 0.0)
  1019                 pair (true, seconds 0.0)
  1033               else
  1020               else
  1034                 shrink_proof debug ctxt type_enc lam_trans preplay
  1021                 shrink_proof debug ctxt type_enc lam_trans preplay
  1035                      preplay_timeout
  1022                      preplay_timeout