src/HOL/Tools/ATP/atp_proof.ML
changeset 57707 0242e9578828
parent 57697 44341963ade3
child 57709 9cda0c64c37a
equal deleted inserted replaced
57706:94476c92f892 57707:0242e9578828
    66   val z3_tptpN : string
    66   val z3_tptpN : string
    67   val zipperpositionN : string
    67   val zipperpositionN : string
    68   val remote_prefix : string
    68   val remote_prefix : string
    69 
    69 
    70   val agsyhol_core_rule : string
    70   val agsyhol_core_rule : string
    71   val satallax_core_rule : string
       
    72   val spass_input_rule : string
    71   val spass_input_rule : string
    73   val spass_pre_skolemize_rule : string
    72   val spass_pre_skolemize_rule : string
    74   val spass_skolemize_rule : string
    73   val spass_skolemize_rule : string
    75   val z3_tptp_core_rule : string
    74   val z3_tptp_core_rule : string
    76 
    75 
    83     -> string * atp_failure option
    82     -> string * atp_failure option
    84   val is_same_atp_step : atp_step_name -> atp_step_name -> bool
    83   val is_same_atp_step : atp_step_name -> atp_step_name -> bool
    85   val scan_general_id : string list -> string * string list
    84   val scan_general_id : string list -> string * string list
    86   val parse_formula : string list ->
    85   val parse_formula : string list ->
    87     (string, string atp_type, (string, string atp_type) atp_term, string) atp_formula * string list
    86     (string, string atp_type, (string, string atp_type) atp_term, string) atp_formula * string list
    88   val atp_proof_of_tstplike_proof : string -> string atp_problem -> string -> string atp_proof
       
    89   val clean_up_atp_proof_dependencies : string atp_proof -> string atp_proof
    87   val clean_up_atp_proof_dependencies : string atp_proof -> string atp_proof
    90   val map_term_names_in_atp_proof : (string -> string) -> string atp_proof -> string atp_proof
    88   val map_term_names_in_atp_proof : (string -> string) -> string atp_proof -> string atp_proof
    91   val nasty_atp_proof : string Symtab.table -> string atp_proof -> string atp_proof
    89   val nasty_atp_proof : string Symtab.table -> string atp_proof -> string atp_proof
       
    90 
       
    91   val skip_term: string list -> string * string list
       
    92   val parse_thf0_formula :string list ->
       
    93       ('a, 'b, (string, string ATP_Problem.atp_type) ATP_Problem.atp_term,
       
    94        'c) ATP_Problem.atp_formula *
       
    95       string list
       
    96   val dummy_atype :  string ATP_Problem.atp_type
       
    97   val role_of_tptp_string:  string -> ATP_Problem.atp_formula_role
       
    98   val parse_line: string -> ('a * string ATP_Problem.atp_problem_line list) list ->
       
    99               string list -> ((string * string list) * ATP_Problem.atp_formula_role *
       
   100                (string, 'b, (string, string ATP_Problem.atp_type) ATP_Problem.atp_term,
       
   101                 'c) ATP_Problem.atp_formula
       
   102                * string * (string * 'd list) list) list * string list
       
   103   val core_inference :   'a -> 'b -> ('b * 'b list) * ATP_Problem.atp_formula_role *
       
   104               ('c, 'd, (string, 'e) ATP_Problem.atp_term, 'f) ATP_Problem.atp_formula * 'a * 'g list
       
   105   val vampire_step_name_ord : (string * 'a) * (string * 'a) -> order
       
   106   val core_of_agsyhol_proof :  string -> string list option
    92 end;
   107 end;
    93 
   108 
    94 structure ATP_Proof : ATP_PROOF =
   109 structure ATP_Proof : ATP_PROOF =
    95 struct
   110 struct
    96 
   111 
   121 val z3_tptpN = "z3_tptp"
   136 val z3_tptpN = "z3_tptp"
   122 val zipperpositionN = "zipperposition"
   137 val zipperpositionN = "zipperposition"
   123 val remote_prefix = "remote_"
   138 val remote_prefix = "remote_"
   124 
   139 
   125 val agsyhol_core_rule = "__agsyhol_core" (* arbitrary *)
   140 val agsyhol_core_rule = "__agsyhol_core" (* arbitrary *)
   126 val satallax_core_rule = "__satallax_core" (* arbitrary *)
       
   127 val spass_input_rule = "Inp"
   141 val spass_input_rule = "Inp"
   128 val spass_pre_skolemize_rule = "__Sko0" (* arbitrary *)
   142 val spass_pre_skolemize_rule = "__Sko0" (* arbitrary *)
   129 val spass_skolemize_rule = "__Sko" (* arbitrary *)
   143 val spass_skolemize_rule = "__Sko" (* arbitrary *)
   130 val z3_tptp_core_rule = "__z3_tptp_core" (* arbitrary *)
   144 val z3_tptp_core_rule = "__z3_tptp_core" (* arbitrary *)
   131 
   145 
   276 
   290 
   277 val skip_term =
   291 val skip_term =
   278   let
   292   let
   279     fun skip _ accum [] = (accum, [])
   293     fun skip _ accum [] = (accum, [])
   280       | skip n accum (ss as s :: ss') =
   294       | skip n accum (ss as s :: ss') =
   281         if s = "," andalso n = 0 then
   295         if (s = "," orelse s = ".") andalso n = 0 then
   282           (accum, ss)
   296           (accum, ss)
   283         else if member (op =) [")", "]"] s then
   297         else if member (op =) [")", "]"] s then
   284           if n = 0 then (accum, ss) else skip (n - 1) (s :: accum) ss'
   298           if n = 0 then (accum, ss) else skip (n - 1) (s :: accum) ss'
   285         else if member (op =) ["(", "["] s then
   299         else if member (op =) ["(", "["] s then
   286           skip (n + 1) (s :: accum) ss'
   300           skip (n + 1) (s :: accum) ss'
   647        [((num, names), Unknown, u, rule, map (rpair []) deps)]
   661        [((num, names), Unknown, u, rule, map (rpair []) deps)]
   648      end)) x
   662      end)) x
   649 
   663 
   650 fun core_inference inf fact = ((fact, [fact]), Unknown, dummy_phi, inf, [])
   664 fun core_inference inf fact = ((fact, [fact]), Unknown, dummy_phi, inf, [])
   651 
   665 
   652 (* Syntax: <name> *)
       
   653 fun parse_satallax_core_line x =
       
   654   (scan_general_id --| Scan.option ($$ " ") >> (single o core_inference satallax_core_rule)) x
       
   655 
       
   656 (* Syntax: SZS core <name> ... <name> *)
   666 (* Syntax: SZS core <name> ... <name> *)
   657 fun parse_z3_tptp_core_line x =
   667 fun parse_z3_tptp_core_line x =
   658   (Scan.this_string "SZS core" |-- Scan.repeat ($$ " " |-- scan_general_id)
   668   (Scan.this_string "SZS core" |-- Scan.repeat ($$ " " |-- scan_general_id)
   659    >> map (core_inference z3_tptp_core_rule)) x
   669    >> map (core_inference z3_tptp_core_rule)) x
   660 
   670 
   661 fun parse_line local_name problem =
   671 fun parse_line local_name problem =
   662   if local_name = leo2N then parse_tstp_thf0_line problem
   672   if local_name = leo2N then parse_tstp_thf0_line problem
   663   else if local_name = satallaxN then parse_satallax_core_line
       
   664   else if local_name = spassN then parse_spass_line
   673   else if local_name = spassN then parse_spass_line
   665   else if local_name = spass_pirateN then parse_spass_pirate_line
   674   else if local_name = spass_pirateN then parse_spass_pirate_line
   666   else if local_name = z3_tptpN then parse_z3_tptp_core_line
   675   else if local_name = z3_tptpN then parse_z3_tptp_core_line
   667   else parse_tstp_line problem
   676   else parse_tstp_line problem
   668 
       
   669 fun parse_proof local_name problem =
       
   670   strip_spaces_except_between_idents
       
   671   #> raw_explode
       
   672   #> Scan.error (!! (fn _ => raise UNRECOGNIZED_ATP_PROOF ())
       
   673        (Scan.finite Symbol.stopper (Scan.repeat1 (parse_line local_name problem) >> flat)))
       
   674   #> fst
       
   675 
   677 
   676 fun core_of_agsyhol_proof s =
   678 fun core_of_agsyhol_proof s =
   677   (case split_lines s of
   679   (case split_lines s of
   678     "The transformed problem consists of the following conjectures:" :: conj ::
   680     "The transformed problem consists of the following conjectures:" :: conj ::
   679     _ :: proof_term :: _ => SOME (unprefix " " conj :: find_enclosed "<<" ">>" proof_term)
   681     _ :: proof_term :: _ => SOME (unprefix " " conj :: find_enclosed "<<" ">>" proof_term)
   680   | _ => NONE)
   682   | _ => NONE)
   681 
   683 
   682 fun atp_proof_of_tstplike_proof _ _ "" = []
       
   683   | atp_proof_of_tstplike_proof local_prover problem tstp =
       
   684     (case core_of_agsyhol_proof tstp of
       
   685       SOME facts => facts |> map (core_inference agsyhol_core_rule)
       
   686     | NONE =>
       
   687       tstp ^ "$" (* the $ sign acts as a sentinel (FIXME: needed?) *)
       
   688       |> parse_proof local_prover problem
       
   689       |> local_prover = vampireN ? perhaps (try (sort (vampire_step_name_ord o pairself #1)))
       
   690       |> local_prover = zipperpositionN ? rev)
       
   691 
       
   692 fun clean_up_dependencies _ [] = []
   684 fun clean_up_dependencies _ [] = []
   693   | clean_up_dependencies seen ((name, role, u, rule, deps) :: steps) =
   685   | clean_up_dependencies seen ((name, role, u, rule, deps) :: steps) =
   694     (name, role, u, rule, map_filter (fn dep => find_first (is_same_atp_step dep) seen) deps) ::
   686     (name, role, u, rule, map_filter (fn dep => find_first (is_same_atp_step dep) seen) deps) ::
   695     clean_up_dependencies (name :: seen) steps
   687     clean_up_dependencies (name :: seen) steps
   696 
   688