15347
|
1 |
(* Author: Jia Meng, Cambridge University Computer Laboratory
|
|
2 |
ID: $Id$
|
|
3 |
Copyright 2004 University of Cambridge
|
|
4 |
|
|
5 |
ATPs with TPTP format input.
|
|
6 |
*)
|
15452
|
7 |
|
|
8 |
(*Jia: changed: isar_atp now processes entire proof context. fetch thms from delta simpset/claset*)
|
|
9 |
|
15347
|
10 |
signature RES_ATP =
|
|
11 |
sig
|
|
12 |
|
|
13 |
val trace_res : bool ref
|
|
14 |
val axiom_file : Path.T
|
|
15 |
val hyps_file : Path.T
|
15452
|
16 |
val isar_atp : ProofContext.context * Thm.thm -> unit
|
15347
|
17 |
val prob_file : Path.T
|
|
18 |
val atp_ax_tac : Thm.thm list -> int -> Tactical.tactic
|
|
19 |
val atp_tac : int -> Tactical.tactic
|
15452
|
20 |
val debug: bool ref
|
15347
|
21 |
|
|
22 |
end;
|
|
23 |
|
|
24 |
structure ResAtp : RES_ATP =
|
|
25 |
|
|
26 |
struct
|
|
27 |
|
15452
|
28 |
(* used for debug *)
|
|
29 |
val debug = ref false;
|
|
30 |
|
|
31 |
fun debug_tac tac = (warning "testing";tac);
|
15347
|
32 |
(* default value is false *)
|
|
33 |
|
|
34 |
val trace_res = ref false;
|
|
35 |
|
|
36 |
val skolem_tac = skolemize_tac;
|
|
37 |
|
|
38 |
|
|
39 |
val atomize_tac =
|
|
40 |
SUBGOAL
|
|
41 |
(fn (prop,_) =>
|
|
42 |
let val ts = Logic.strip_assums_hyp prop
|
|
43 |
in EVERY1
|
|
44 |
[METAHYPS
|
|
45 |
(fn hyps => (cut_facts_tac (map (ObjectLogic.atomize_thm o forall_intr_vars) hyps) 1)),
|
|
46 |
REPEAT_DETERM_N (length ts) o (etac thin_rl)]
|
|
47 |
end);
|
|
48 |
|
|
49 |
(* temporarily use these files, which will be loaded by Vampire *)
|
|
50 |
val prob_file = File.tmp_path (Path.basic "prob");
|
|
51 |
val axiom_file = File.tmp_path (Path.basic "axioms");
|
|
52 |
val hyps_file = File.tmp_path (Path.basic "hyps");
|
|
53 |
val dummy_tac = PRIMITIVE(fn thm => thm );
|
|
54 |
|
|
55 |
|
|
56 |
|
15452
|
57 |
fun tptp_inputs thms n =
|
15347
|
58 |
let val clss = map (ResClause.make_conjecture_clause_thm) thms
|
|
59 |
val tptp_clss = ResLib.flat_noDup(map ResClause.tptp_clause clss)
|
15452
|
60 |
val probfile = (File.sysify_path prob_file) ^ "_" ^ (string_of_int n)
|
15347
|
61 |
val out = TextIO.openOut(probfile)
|
|
62 |
in
|
|
63 |
(ResLib.writeln_strs out tptp_clss; TextIO.closeOut out; (if !trace_res then (warning probfile) else ()))
|
|
64 |
end;
|
|
65 |
|
|
66 |
|
|
67 |
(**** for Isabelle/ML interface ****)
|
|
68 |
|
15452
|
69 |
fun call_atp_tac thms n = (tptp_inputs thms n; dummy_tac);
|
|
70 |
|
15347
|
71 |
|
|
72 |
|
15452
|
73 |
|
|
74 |
fun atp_tac n = SELECT_GOAL
|
|
75 |
(EVERY1 [rtac ccontr,atomize_tac, skolemize_tac,
|
|
76 |
METAHYPS(fn negs => (call_atp_tac (make_clauses negs) n))]) n;
|
15347
|
77 |
|
|
78 |
|
|
79 |
fun atp_ax_tac axioms n =
|
|
80 |
let val axcls = ResLib.flat_noDup(map ResAxioms.clausify_axiom axioms)
|
|
81 |
val axcls_str = ResClause.tptp_clauses2str (ResLib.flat_noDup(map ResClause.tptp_clause axcls))
|
|
82 |
val axiomfile = File.sysify_path axiom_file
|
|
83 |
val out = TextIO.openOut (axiomfile)
|
|
84 |
in
|
|
85 |
(TextIO.output(out,axcls_str);TextIO.closeOut out; if !trace_res then (warning axiomfile) else (); atp_tac n)
|
|
86 |
end;
|
|
87 |
|
|
88 |
|
|
89 |
fun atp thm =
|
|
90 |
let val prems = prems_of thm
|
|
91 |
in
|
|
92 |
case prems of [] => ()
|
|
93 |
| _ => (atp_tac 1 thm; ())
|
|
94 |
end;
|
|
95 |
|
|
96 |
|
|
97 |
(**** For running in Isar ****)
|
|
98 |
|
|
99 |
(* same function as that in res_axioms.ML *)
|
|
100 |
fun repeat_RS thm1 thm2 =
|
|
101 |
let val thm1' = thm1 RS thm2 handle THM _ => thm1
|
|
102 |
in
|
|
103 |
if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
|
|
104 |
end;
|
|
105 |
|
|
106 |
(* a special version of repeat_RS *)
|
|
107 |
fun repeat_someI_ex thm = repeat_RS thm someI_ex;
|
|
108 |
|
|
109 |
|
15452
|
110 |
(* convert clauses from "assume" to conjecture. write to file "hyps" *)
|
15347
|
111 |
fun isar_atp_h thms =
|
|
112 |
let val prems = map (skolemize o make_nnf o ObjectLogic.atomize_thm) thms
|
|
113 |
val prems' = map repeat_someI_ex prems
|
|
114 |
val prems'' = make_clauses prems'
|
|
115 |
val prems''' = ResAxioms.rm_Eps [] prems''
|
15452
|
116 |
val clss = map ResClause.make_conjecture_clause prems'''
|
15347
|
117 |
val tptp_clss = ResLib.flat_noDup (map ResClause.tptp_clause clss)
|
|
118 |
val hypsfile = File.sysify_path hyps_file
|
|
119 |
val out = TextIO.openOut(hypsfile)
|
|
120 |
in
|
|
121 |
(ResLib.writeln_strs out tptp_clss; TextIO.closeOut out; if !trace_res then (warning hypsfile) else ())
|
|
122 |
end;
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
val isar_atp_g = atp_tac;
|
|
128 |
|
15452
|
129 |
|
|
130 |
fun isar_atp_goal' thm k n =
|
|
131 |
if (k > n) then () else (isar_atp_g k thm; isar_atp_goal' thm (k+1) n);
|
|
132 |
|
|
133 |
|
|
134 |
fun isar_atp_goal thm n_subgoals = (if (!debug) then warning (string_of_thm thm) else (isar_atp_goal' thm 1 n_subgoals));
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
fun isar_atp_aux thms thm n_subgoals =
|
|
139 |
(isar_atp_h thms; isar_atp_goal thm n_subgoals); (* convert both to conjecture clauses, but write to different files *)
|
|
140 |
|
|
141 |
|
|
142 |
fun isar_atp' (thms, thm) =
|
|
143 |
let val prems = prems_of thm
|
|
144 |
in
|
|
145 |
case prems of [] => (if (!debug) then warning "entering forward, no goal" else ())
|
|
146 |
| _ => (isar_atp_aux thms thm (length prems))
|
|
147 |
end;
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
local
|
|
153 |
|
|
154 |
fun get_thms_cs claset =
|
|
155 |
let val clsset = rep_cs claset
|
|
156 |
val safeEs = #safeEs clsset
|
|
157 |
val safeIs = #safeIs clsset
|
|
158 |
val hazEs = #hazEs clsset
|
|
159 |
val hazIs = #hazIs clsset
|
|
160 |
in
|
|
161 |
safeEs @ safeIs @ hazEs @ hazIs
|
|
162 |
end;
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
fun append_name name [] _ = []
|
|
167 |
| append_name name (thm::thms) k = (Thm.name_thm ((name ^ "_" ^ (string_of_int k)),thm)) :: (append_name name thms (k+1));
|
|
168 |
|
|
169 |
fun append_names (name::names) (thms::thmss) =
|
|
170 |
let val thms' = append_name name thms 0
|
|
171 |
in
|
|
172 |
thms'::(append_names names thmss)
|
|
173 |
end;
|
|
174 |
|
|
175 |
|
|
176 |
fun get_thms_ss [] = []
|
|
177 |
| get_thms_ss thms =
|
|
178 |
let val names = map Thm.name_of_thm thms
|
|
179 |
val thms' = map (mksimps mksimps_pairs) thms
|
|
180 |
val thms'' = append_names names thms'
|
|
181 |
in
|
|
182 |
ResLib.flat_noDup thms''
|
|
183 |
end;
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
in
|
|
189 |
|
|
190 |
|
|
191 |
(* convert locally declared rules to axiom clauses *)
|
|
192 |
(* write axiom clauses to ax_file *)
|
|
193 |
fun isar_local_thms (delta_cs, delta_ss_thms) =
|
|
194 |
let val thms_cs = get_thms_cs delta_cs
|
|
195 |
val thms_ss = get_thms_ss delta_ss_thms
|
|
196 |
val thms_clauses = ResLib.flat_noDup (map ResAxioms.clausify_axiom (thms_cs @ thms_ss))
|
|
197 |
val clauses_strs = ResLib.flat_noDup (map ResClause.tptp_clause thms_clauses) (*string list*)
|
|
198 |
val ax_file = File.sysify_path axiom_file
|
|
199 |
val out = TextIO.openOut ax_file
|
|
200 |
in
|
|
201 |
(ResLib.writeln_strs out clauses_strs; TextIO.closeOut out)
|
|
202 |
end;
|
15347
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
(* called in Isar automatically *)
|
15452
|
209 |
fun isar_atp (ctxt,thm) =
|
|
210 |
let val prems = ProofContext.prems_of ctxt
|
|
211 |
val d_cs = Classical.get_delta_claset ctxt
|
|
212 |
val d_ss_thms = Simplifier.get_delta_simpset ctxt
|
15347
|
213 |
in
|
15452
|
214 |
(isar_local_thms (d_cs,d_ss_thms); isar_atp' (prems, thm))
|
15347
|
215 |
end;
|
|
216 |
|
15452
|
217 |
end
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
15347
|
222 |
end;
|
|
223 |
|
|
224 |
Proof.atp_hook := ResAtp.isar_atp;
|
|
225 |
|
|
226 |
|