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 |
*)
|
|
7 |
signature RES_ATP =
|
|
8 |
sig
|
|
9 |
|
|
10 |
val trace_res : bool ref
|
|
11 |
val axiom_file : Path.T
|
|
12 |
val hyps_file : Path.T
|
|
13 |
val isar_atp : Thm.thm list * Thm.thm -> unit
|
|
14 |
val prob_file : Path.T
|
|
15 |
val atp_ax_tac : Thm.thm list -> int -> Tactical.tactic
|
|
16 |
val atp_tac : int -> Tactical.tactic
|
|
17 |
|
|
18 |
end;
|
|
19 |
|
|
20 |
structure ResAtp : RES_ATP =
|
|
21 |
|
|
22 |
struct
|
|
23 |
|
|
24 |
(* default value is false *)
|
|
25 |
|
|
26 |
val trace_res = ref false;
|
|
27 |
|
|
28 |
val skolem_tac = skolemize_tac;
|
|
29 |
|
|
30 |
|
|
31 |
val atomize_tac =
|
|
32 |
SUBGOAL
|
|
33 |
(fn (prop,_) =>
|
|
34 |
let val ts = Logic.strip_assums_hyp prop
|
|
35 |
in EVERY1
|
|
36 |
[METAHYPS
|
|
37 |
(fn hyps => (cut_facts_tac (map (ObjectLogic.atomize_thm o forall_intr_vars) hyps) 1)),
|
|
38 |
REPEAT_DETERM_N (length ts) o (etac thin_rl)]
|
|
39 |
end);
|
|
40 |
|
|
41 |
(* temporarily use these files, which will be loaded by Vampire *)
|
|
42 |
val prob_file = File.tmp_path (Path.basic "prob");
|
|
43 |
val axiom_file = File.tmp_path (Path.basic "axioms");
|
|
44 |
val hyps_file = File.tmp_path (Path.basic "hyps");
|
|
45 |
val dummy_tac = PRIMITIVE(fn thm => thm );
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
fun tptp_inputs thms =
|
|
50 |
let val clss = map (ResClause.make_conjecture_clause_thm) thms
|
|
51 |
val tptp_clss = ResLib.flat_noDup(map ResClause.tptp_clause clss)
|
|
52 |
val probfile = File.sysify_path prob_file
|
|
53 |
val out = TextIO.openOut(probfile)
|
|
54 |
in
|
|
55 |
(ResLib.writeln_strs out tptp_clss; TextIO.closeOut out; (if !trace_res then (warning probfile) else ()))
|
|
56 |
end;
|
|
57 |
|
|
58 |
|
|
59 |
(**** for Isabelle/ML interface ****)
|
|
60 |
|
|
61 |
fun call_atp_tac thms = (tptp_inputs thms; dummy_tac);
|
|
62 |
|
|
63 |
|
|
64 |
val atp_tac = SELECT_GOAL
|
|
65 |
(EVERY1 [rtac ccontr, atomize_tac, skolemize_tac,
|
|
66 |
METAHYPS(fn negs => (call_atp_tac(make_clauses negs)))]);
|
|
67 |
|
|
68 |
|
|
69 |
fun atp_ax_tac axioms n =
|
|
70 |
let val axcls = ResLib.flat_noDup(map ResAxioms.clausify_axiom axioms)
|
|
71 |
val axcls_str = ResClause.tptp_clauses2str (ResLib.flat_noDup(map ResClause.tptp_clause axcls))
|
|
72 |
val axiomfile = File.sysify_path axiom_file
|
|
73 |
val out = TextIO.openOut (axiomfile)
|
|
74 |
in
|
|
75 |
(TextIO.output(out,axcls_str);TextIO.closeOut out; if !trace_res then (warning axiomfile) else (); atp_tac n)
|
|
76 |
end;
|
|
77 |
|
|
78 |
|
|
79 |
fun atp thm =
|
|
80 |
let val prems = prems_of thm
|
|
81 |
in
|
|
82 |
case prems of [] => ()
|
|
83 |
| _ => (atp_tac 1 thm; ())
|
|
84 |
end;
|
|
85 |
|
|
86 |
|
|
87 |
(**** For running in Isar ****)
|
|
88 |
|
|
89 |
(* same function as that in res_axioms.ML *)
|
|
90 |
fun repeat_RS thm1 thm2 =
|
|
91 |
let val thm1' = thm1 RS thm2 handle THM _ => thm1
|
|
92 |
in
|
|
93 |
if eq_thm(thm1,thm1') then thm1' else (repeat_RS thm1' thm2)
|
|
94 |
end;
|
|
95 |
|
|
96 |
(* a special version of repeat_RS *)
|
|
97 |
fun repeat_someI_ex thm = repeat_RS thm someI_ex;
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
fun isar_atp_h thms =
|
|
102 |
let val prems = map (skolemize o make_nnf o ObjectLogic.atomize_thm) thms
|
|
103 |
val prems' = map repeat_someI_ex prems
|
|
104 |
val prems'' = make_clauses prems'
|
|
105 |
val prems''' = ResAxioms.rm_Eps [] prems''
|
|
106 |
val clss = map ResClause.make_hypothesis_clause prems'''
|
|
107 |
val tptp_clss = ResLib.flat_noDup (map ResClause.tptp_clause clss)
|
|
108 |
val hypsfile = File.sysify_path hyps_file
|
|
109 |
val out = TextIO.openOut(hypsfile)
|
|
110 |
in
|
|
111 |
(ResLib.writeln_strs out tptp_clss; TextIO.closeOut out; if !trace_res then (warning hypsfile) else ())
|
|
112 |
end;
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
val isar_atp_g = atp_tac;
|
|
118 |
|
|
119 |
fun isar_atp_aux thms thm =
|
|
120 |
(isar_atp_h thms; isar_atp_g 1 thm;());
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
(* called in Isar automatically *)
|
|
127 |
fun isar_atp (thms, thm) =
|
|
128 |
let val prems = prems_of thm
|
|
129 |
in
|
|
130 |
case prems of [] => ()
|
|
131 |
| _ => (isar_atp_aux thms thm)
|
|
132 |
end;
|
|
133 |
|
|
134 |
end;
|
|
135 |
|
|
136 |
Proof.atp_hook := ResAtp.isar_atp;
|
|
137 |
|
|
138 |
|