src/HOL/Tools/Sledgehammer/sledgehammer_reconstruct.ML
changeset 50905 db99fcf69761
parent 50705 0e943b33d907
child 50924 beb95bf66b21
equal deleted inserted replaced
50904:3d2d62d29302 50905:db99fcf69761
   363 
   363 
   364 (* No "real" literals means only type information (tfree_tcs, clsrel, or
   364 (* No "real" literals means only type information (tfree_tcs, clsrel, or
   365    clsarity). *)
   365    clsarity). *)
   366 fun is_only_type_information t = t aconv @{term True}
   366 fun is_only_type_information t = t aconv @{term True}
   367 
   367 
       
   368 fun s_maybe_not role = role <> Conjecture ? s_not
       
   369 
   368 fun is_same_inference _ (Definition_Step _) = false
   370 fun is_same_inference _ (Definition_Step _) = false
   369   | is_same_inference t (Inference_Step (_, _, t', _, _)) = t aconv t'
   371   | is_same_inference (role, t) (Inference_Step (_, role', t', _, _)) =
       
   372     s_maybe_not role t aconv s_maybe_not role' t'
   370 
   373 
   371 (* Discard facts; consolidate adjacent lines that prove the same formula, since
   374 (* Discard facts; consolidate adjacent lines that prove the same formula, since
   372    they differ only in type information.*)
   375    they differ only in type information.*)
   373 fun add_line _ (line as Definition_Step _) lines = line :: lines
   376 fun add_line _ (line as Definition_Step _) lines = line :: lines
   374   | add_line fact_names (Inference_Step (name as (_, ss), role, t, rule, []))
   377   | add_line fact_names (Inference_Step (name as (_, ss), role, t, rule, []))
   375              lines =
   378              lines =
   376     (* No dependencies: fact, conjecture, or (for Vampire) internal facts or
   379     (* No dependencies: fact, conjecture, or (for Vampire) internal facts or
   377        definitions. *)
   380        definitions. *)
   378     if is_fact fact_names ss then
   381     if is_conjecture ss then
       
   382       Inference_Step (name, role, t, rule, []) :: lines
       
   383     else if is_fact fact_names ss then
   379       (* Facts are not proof lines. *)
   384       (* Facts are not proof lines. *)
   380       if is_only_type_information t then
   385       if is_only_type_information t then
   381         map (replace_dependencies_in_line (name, [])) lines
   386         map (replace_dependencies_in_line (name, [])) lines
   382       (* Is there a repetition? If so, replace later line by earlier one. *)
   387       else
   383       else case take_prefix (not o is_same_inference t) lines of
   388         lines
   384         (_, []) => lines (* no repetition of proof line *)
       
   385       | (pre, Inference_Step (name', _, _, _, _) :: post) =>
       
   386         pre @ map (replace_dependencies_in_line (name', [name])) post
       
   387       | _ => raise Fail "unexpected inference"
       
   388     else if is_conjecture ss then
       
   389       Inference_Step (name, role, t, rule, []) :: lines
       
   390     else
   389     else
   391       map (replace_dependencies_in_line (name, [])) lines
   390       map (replace_dependencies_in_line (name, [])) lines
   392   | add_line _ (line as Inference_Step (name, role, t, rule, deps)) lines =
   391   | add_line _ (line as Inference_Step (name, role, t, rule, deps)) lines =
   393     (* Type information will be deleted later; skip repetition test. *)
   392     (* Type information will be deleted later; skip repetition test. *)
   394     if is_only_type_information t then
   393     if is_only_type_information t then
   395       line :: lines
   394       line :: lines
   396     (* Is there a repetition? If so, replace later line by earlier one. *)
   395     (* Is there a repetition? If so, replace later line by earlier one. *)
   397     else case take_prefix (not o is_same_inference t) lines of
   396     else case take_prefix (not o is_same_inference (role, t)) lines of
   398       (* FIXME: Doesn't this code risk conflating proofs involving different
   397       (* FIXME: Doesn't this code risk conflating proofs involving different
   399          types? *)
   398          types? *)
   400       (_, []) => line :: lines
   399       (_, []) => line :: lines
   401     | (pre, Inference_Step (name', _, _, _, _) :: post) =>
   400     | (pre, Inference_Step (name', _, _, _, _) :: post) =>
   402       line :: pre @ map (replace_dependencies_in_line (name', [name])) post
   401       line :: pre @ map (replace_dependencies_in_line (name', [name])) post
   404 
   403 
   405 val waldmeister_conjecture_num = "1.0.0.0"
   404 val waldmeister_conjecture_num = "1.0.0.0"
   406 
   405 
   407 val repair_waldmeister_endgame =
   406 val repair_waldmeister_endgame =
   408   let
   407   let
   409     fun do_tail (Inference_Step (name, role, t, rule, deps)) =
   408     fun do_tail (Inference_Step (name, _, t, rule, deps)) =
   410         Inference_Step (name, role, s_not t, rule, deps)
   409         Inference_Step (name, Negated_Conjecture, s_not t, rule, deps)
   411       | do_tail line = line
   410       | do_tail line = line
   412     fun do_body [] = []
   411     fun do_body [] = []
   413       | do_body ((line as Inference_Step ((num, _), _, _, _, _)) :: lines) =
   412       | do_body ((line as Inference_Step ((num, _), _, _, _, _)) :: lines) =
   414         if num = waldmeister_conjecture_num then map do_tail (line :: lines)
   413         if num = waldmeister_conjecture_num then map do_tail (line :: lines)
   415         else line :: do_body lines
   414         else line :: do_body lines
   650           atp_proof
   649           atp_proof
   651           |> clean_up_atp_proof_dependencies
   650           |> clean_up_atp_proof_dependencies
   652           |> nasty_atp_proof pool
   651           |> nasty_atp_proof pool
   653           |> map_term_names_in_atp_proof repair_name
   652           |> map_term_names_in_atp_proof repair_name
   654           |> decode_lines ctxt sym_tab
   653           |> decode_lines ctxt sym_tab
       
   654           |> repair_waldmeister_endgame
   655           |> rpair [] |-> fold_rev (add_line fact_names)
   655           |> rpair [] |-> fold_rev (add_line fact_names)
   656           |> repair_waldmeister_endgame
       
   657           |> rpair [] |-> fold_rev add_nontrivial_line
   656           |> rpair [] |-> fold_rev add_nontrivial_line
   658           |> rpair (0, [])
   657           |> rpair (0, [])
   659           |-> fold_rev (add_desired_line fact_names frees)
   658           |-> fold_rev (add_desired_line fact_names frees)
   660           |> snd
   659           |> snd
   661         val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts)
   660         val conj_name = conjecture_prefix ^ string_of_int (length hyp_ts)
   683           Symtab.empty
   682           Symtab.empty
   684           |> fold (fn Definition_Step _ => I (* FIXME *)
   683           |> fold (fn Definition_Step _ => I (* FIXME *)
   685                     | Inference_Step (name as (s, ss), role, t, rule, _) =>
   684                     | Inference_Step (name as (s, ss), role, t, rule, _) =>
   686                       Symtab.update_new (s, (rule,
   685                       Symtab.update_new (s, (rule,
   687                         t |> (if member (op = o apsnd fst) tainted s then
   686                         t |> (if member (op = o apsnd fst) tainted s then
   688                                 (role <> Conjecture ? s_not)
   687                                 s_maybe_not role
   689                                 #> fold exists_of (map Var (Term.add_vars t []))
   688                                 #> fold exists_of (map Var (Term.add_vars t []))
   690                               else
   689                               else
   691                                 I))))
   690                                 I))))
   692                   atp_proof
   691                   atp_proof
   693         fun is_clause_skolemize_rule [(s, _)] =
   692         fun is_clause_skolemize_rule [(s, _)] =
   724                 By_Metis (fold (add_fact_from_dependencies fact_names) gamma
   723                 By_Metis (fold (add_fact_from_dependencies fact_names) gamma
   725                                ([], []))
   724                                ([], []))
   726             in
   725             in
   727               if is_clause_skolemize_rule c then
   726               if is_clause_skolemize_rule c then
   728                 let
   727                 let
   729                   val xs =
   728                   val is_fixed =
   730                     Term.add_frees t []
   729                     Variable.is_declared ctxt orf can Name.dest_skolem
   731                     |> filter_out (Variable.is_declared ctxt o fst)
   730                   val xs = Term.add_frees t [] |> filter_out (is_fixed o fst)
   732                 in Obtain ([], xs, l, t, by) end
   731                 in Obtain ([], xs, l, t, by) end
   733               else
   732               else
   734                 Prove (maybe_show outer c [], l, t, by)
   733                 Prove (maybe_show outer c [], l, t, by)
   735             end
   734             end
   736           | isar_step_of_direct_inf outer (Cases cases) =
   735           | isar_step_of_direct_inf outer (Cases cases) =