renamed example theory to "ATP_Export", for consistency with its underlying "ATP_" modules
1 (* Title: HOL/ex/atp_export.ML
2 Author: Jasmin Blanchette, TU Muenchen
5 Export Isabelle theories as first-order TPTP inferences, exploiting
6 Sledgehammer's translation.
11 val generate_tptp_graph_file_for_theory :
12 Proof.context -> theory -> string -> unit
13 val generate_tptp_inference_file_for_theory :
14 Proof.context -> theory -> bool -> string -> unit
17 structure ATP_Export : ATP_EXPORT =
20 val ascii_of = ATP_Translate.ascii_of
22 val fact_name_of = prefix ATP_Translate.fact_prefix o ascii_of
25 Sledgehammer_Filter.all_facts (ProofContext.init_global thy) Symtab.empty
28 fun fold_body_thms f =
30 fun app n (PBody {thms, ...}) = thms |> fold (fn (i, (name, prop, body)) => fn (x, seen) =>
31 if Inttab.defined seen i then (x, seen)
34 val body' = Future.join body;
35 val (x', seen') = app (n + (if name = "" then 0 else 1)) body' (x, Inttab.update (i, ()) seen);
36 in (x' |> n = 1 ? f (name, prop, body'), seen') end);
37 in fn bodies => fn x => #1 (fold (app 0) bodies (x, Inttab.empty)) end;
39 fun theorems_mentioned_in_proof_term thm =
41 fun collect (s, _, _) = if s <> "" then insert (op =) s else I
43 [] |> fold_body_thms collect [Thm.proof_body_of thm] |> map fact_name_of
46 fun interesting_const_names ctxt =
47 let val thy = ProofContext.theory_of ctxt in
48 Sledgehammer_Filter.const_names_in_fact thy
49 (Sledgehammer_Provers.is_built_in_const_for_prover ctxt ATP_Systems.eN)
52 fun generate_tptp_graph_file_for_theory ctxt thy file_name =
54 val path = file_name |> Path.explode
55 val _ = File.write path ""
56 val axioms = Theory.all_axioms_of thy |> map fst
59 val name = Thm.get_name_hint thm
61 "[" ^ Thm.legacy_get_kind thm ^ "] " ^
62 (if member (op =) axioms name then "A" else "T") ^ " " ^
63 prefix ATP_Translate.fact_prefix (ascii_of name) ^ ": " ^
64 commas (theorems_mentioned_in_proof_term thm) ^ "; " ^
65 commas (map (prefix ATP_Translate.const_prefix o ascii_of)
66 (interesting_const_names ctxt (Thm.prop_of thm))) ^ " \n"
67 in File.append path s end
68 val thms = facts_of thy |> map (snd o snd)
69 val _ = map do_thm thms
72 fun inference_term [] = NONE
74 ATP_Problem.ATerm ("inference",
75 [ATP_Problem.ATerm ("isabelle", []),
76 ATP_Problem.ATerm ("[]", []),
77 ATP_Problem.ATerm ("[]",
78 map (fn s => ATP_Problem.ATerm (s, [])) ss)])
80 fun inference infers ident =
81 these (AList.lookup (op =) infers ident) |> inference_term
82 fun add_inferences_to_problem_line infers
83 (ATP_Problem.Formula (ident, ATP_Problem.Axiom, phi, NONE, NONE)) =
84 ATP_Problem.Formula (ident, ATP_Problem.Lemma, phi, inference infers ident,
86 | add_inferences_to_problem_line _ line = line
87 val add_inferences_to_problem =
88 map o apsnd o map o add_inferences_to_problem_line
90 fun generate_tptp_inference_file_for_theory ctxt thy full_types file_name =
92 val format = ATP_Problem.FOF
95 (ATP_Translate.Polymorphic,
96 if full_types then ATP_Translate.All_Types
97 else ATP_Translate.Const_Arg_Types,
98 ATP_Translate.Heavyweight)
99 val path = file_name |> Path.explode
100 val _ = File.write path ""
101 val facts0 = facts_of thy
103 facts0 |> map (fn ((_, loc), (_, th)) =>
104 ((Thm.get_name_hint th, loc), prop_of th))
105 val explicit_apply = NONE
106 val (atp_problem, _, _, _, _, _, _) =
107 ATP_Translate.prepare_atp_problem ctxt format
108 ATP_Problem.Axiom ATP_Problem.Axiom type_sys explicit_apply false true
109 [] @{prop False} facts
111 facts0 |> map (fn (_, (_, th)) =>
112 (fact_name_of (Thm.get_name_hint th),
113 theorems_mentioned_in_proof_term th))
115 infers |> map (apsnd (filter (member (op = o apsnd fst) infers)))
116 val atp_problem = atp_problem |> add_inferences_to_problem infers
118 ATP_Problem.tptp_strings_for_atp_problem ATP_Problem.FOF atp_problem
119 val _ = app (File.append path) ss