author | blanchet |
Fri, 16 Apr 2010 14:48:34 +0200 | |
changeset 36169 | 27b1cc58715e |
parent 36168 | 0a6ed065683d |
child 36170 | 0cdb76723c88 |
permissions | -rw-r--r-- |
35826 | 1 |
(* Title: HOL/Sledgehammer/sledgehammer_hol_clause.ML |
33311 | 2 |
Author: Jia Meng, NICTA |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
3 |
|
24311 | 4 |
FOL clauses translated from HOL formulae. |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
5 |
*) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
6 |
|
35826 | 7 |
signature SLEDGEHAMMER_HOL_CLAUSE = |
24311 | 8 |
sig |
35865 | 9 |
type kind = Sledgehammer_FOL_Clause.kind |
10 |
type fol_type = Sledgehammer_FOL_Clause.fol_type |
|
11 |
type classrel_clause = Sledgehammer_FOL_Clause.classrel_clause |
|
12 |
type arity_clause = Sledgehammer_FOL_Clause.arity_clause |
|
24311 | 13 |
type axiom_name = string |
14 |
type polarity = bool |
|
35865 | 15 |
type hol_clause_id = int |
16 |
||
24311 | 17 |
datatype combterm = |
35865 | 18 |
CombConst of string * fol_type * fol_type list (* Const and Free *) | |
19 |
CombVar of string * fol_type | |
|
20 |
CombApp of combterm * combterm |
|
24311 | 21 |
datatype literal = Literal of polarity * combterm |
35865 | 22 |
datatype hol_clause = |
23 |
HOLClause of {clause_id: hol_clause_id, axiom_name: axiom_name, th: thm, |
|
24 |
kind: kind, literals: literal list, ctypes_sorts: typ list} |
|
25 |
||
26 |
val type_of_combterm : combterm -> fol_type |
|
27 |
val strip_combterm_comb : combterm -> combterm * combterm list |
|
28 |
val literals_of_term : theory -> term -> literal list * typ list |
|
29 |
exception TRIVIAL |
|
30 |
val make_conjecture_clauses : bool -> theory -> thm list -> hol_clause list |
|
31 |
val make_axiom_clauses : bool -> theory -> |
|
32 |
(thm * (axiom_name * hol_clause_id)) list -> (axiom_name * hol_clause) list |
|
33 |
val get_helper_clauses : bool -> theory -> bool -> |
|
34 |
hol_clause list * (thm * (axiom_name * hol_clause_id)) list * string list -> |
|
35 |
hol_clause list |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
36 |
val write_tptp_file : bool -> bool -> Path.T -> |
35865 | 37 |
hol_clause list * hol_clause list * hol_clause list * hol_clause list * |
38 |
classrel_clause list * arity_clause list -> |
|
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
39 |
int * int |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
40 |
val write_dfg_file : bool -> bool -> Path.T -> |
35865 | 41 |
hol_clause list * hol_clause list * hol_clause list * hol_clause list * |
42 |
classrel_clause list * arity_clause list -> int * int |
|
24311 | 43 |
end |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
44 |
|
35826 | 45 |
structure Sledgehammer_HOL_Clause : SLEDGEHAMMER_HOL_CLAUSE = |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
46 |
struct |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
47 |
|
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
48 |
open Sledgehammer_Util |
35865 | 49 |
open Sledgehammer_FOL_Clause |
50 |
open Sledgehammer_Fact_Preprocessor |
|
22825
bd774e01d6d5
Fixing bugs in the partial-typed and fully-typed translations
paulson
parents:
22130
diff
changeset
|
51 |
|
35963 | 52 |
(* Parameter "full_types" below indicates that full type information is to be |
31800 | 53 |
exported *) |
22825
bd774e01d6d5
Fixing bugs in the partial-typed and fully-typed translations
paulson
parents:
22130
diff
changeset
|
54 |
|
35865 | 55 |
(* If true, each function will be directly applied to as many arguments as |
56 |
possible, avoiding use of the "apply" operator. Use of hBOOL is also |
|
57 |
minimized. *) |
|
30153
051d3825a15d
turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents:
30151
diff
changeset
|
58 |
val minimize_applies = true; |
22064 | 59 |
|
33035 | 60 |
fun min_arity_of const_min_arity c = the_default 0 (Symtab.lookup const_min_arity c); |
22064 | 61 |
|
22825
bd774e01d6d5
Fixing bugs in the partial-typed and fully-typed translations
paulson
parents:
22130
diff
changeset
|
62 |
(*True if the constant ever appears outside of the top-level position in literals. |
bd774e01d6d5
Fixing bugs in the partial-typed and fully-typed translations
paulson
parents:
22130
diff
changeset
|
63 |
If false, the constant always receives all of its arguments and is used as a predicate.*) |
33035 | 64 |
fun needs_hBOOL const_needs_hBOOL c = |
65 |
not minimize_applies orelse |
|
66 |
the_default false (Symtab.lookup const_needs_hBOOL c); |
|
22064 | 67 |
|
19198
e6f1ff40ba99
Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents:
19130
diff
changeset
|
68 |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
69 |
(******************************************************) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
70 |
(* data types for typed combinator expressions *) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
71 |
(******************************************************) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
72 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
73 |
type axiom_name = string; |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
74 |
type polarity = bool; |
35865 | 75 |
type hol_clause_id = int; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
76 |
|
35865 | 77 |
datatype combterm = |
78 |
CombConst of string * fol_type * fol_type list (* Const and Free *) | |
|
79 |
CombVar of string * fol_type | |
|
80 |
CombApp of combterm * combterm |
|
24311 | 81 |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
82 |
datatype literal = Literal of polarity * combterm; |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
83 |
|
35865 | 84 |
datatype hol_clause = |
85 |
HOLClause of {clause_id: hol_clause_id, axiom_name: axiom_name, th: thm, |
|
86 |
kind: kind, literals: literal list, ctypes_sorts: typ list}; |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
87 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
88 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
89 |
(*********************************************************************) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
90 |
(* convert a clause with type Term.term to a clause with type clause *) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
91 |
(*********************************************************************) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
92 |
|
21561 | 93 |
fun isFalse (Literal(pol, CombConst(c,_,_))) = |
35865 | 94 |
(pol andalso c = "c_False") orelse (not pol andalso c = "c_True") |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
95 |
| isFalse _ = false; |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
96 |
|
21561 | 97 |
fun isTrue (Literal (pol, CombConst(c,_,_))) = |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
98 |
(pol andalso c = "c_True") orelse |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
99 |
(not pol andalso c = "c_False") |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
100 |
| isTrue _ = false; |
24311 | 101 |
|
35865 | 102 |
fun isTaut (HOLClause {literals,...}) = exists isTrue literals; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
103 |
|
30151 | 104 |
fun type_of dfg (Type (a, Ts)) = |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
105 |
let val (folTypes,ts) = types_of dfg Ts in |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
106 |
(TyConstr (`(make_fixed_type_const dfg) a, folTypes), ts) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
107 |
end |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
108 |
| type_of _ (tp as TFree (a, _)) = (TyFree (`make_fixed_type_var a), [tp]) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
109 |
| type_of _ (tp as TVar (x, _)) = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
110 |
(TyVar (make_schematic_type_var x, string_of_indexname x), [tp]) |
30151 | 111 |
and types_of dfg Ts = |
112 |
let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts) |
|
35865 | 113 |
in (folTyps, union_all ts) end; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
114 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
115 |
(* same as above, but no gathering of sort information *) |
30151 | 116 |
fun simp_type_of dfg (Type (a, Ts)) = |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
117 |
TyConstr (`(make_fixed_type_const dfg) a, map (simp_type_of dfg) Ts) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
118 |
| simp_type_of _ (TFree (a, _)) = TyFree (`make_fixed_type_var a) |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
119 |
| simp_type_of _ (TVar (x, _)) = |
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
120 |
TyVar (make_schematic_type_var x, string_of_indexname x); |
18440
72ee07f4b56b
Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents:
18356
diff
changeset
|
121 |
|
18356
443717b3a9ad
Added new type embedding methods for translating HOL clauses.
mengj
parents:
18276
diff
changeset
|
122 |
|
30151 | 123 |
fun const_type_of dfg thy (c,t) = |
124 |
let val (tp,ts) = type_of dfg t |
|
125 |
in (tp, ts, map (simp_type_of dfg) (Sign.const_typargs thy (c,t))) end; |
|
18356
443717b3a9ad
Added new type embedding methods for translating HOL clauses.
mengj
parents:
18276
diff
changeset
|
126 |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
127 |
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *) |
30151 | 128 |
fun combterm_of dfg thy (Const(c,t)) = |
129 |
let val (tp,ts,tvar_list) = const_type_of dfg thy (c,t) |
|
35865 | 130 |
val c' = CombConst(make_fixed_const dfg c, tp, tvar_list) |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
131 |
in (c',ts) end |
32994 | 132 |
| combterm_of dfg _ (Free(v,t)) = |
30151 | 133 |
let val (tp,ts) = type_of dfg t |
35865 | 134 |
val v' = CombConst(make_fixed_var v, tp, []) |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
135 |
in (v',ts) end |
32994 | 136 |
| combterm_of dfg _ (Var(v,t)) = |
30151 | 137 |
let val (tp,ts) = type_of dfg t |
35865 | 138 |
val v' = CombVar(make_schematic_var v,tp) |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
139 |
in (v',ts) end |
30151 | 140 |
| combterm_of dfg thy (P $ Q) = |
141 |
let val (P',tsP) = combterm_of dfg thy P |
|
142 |
val (Q',tsQ) = combterm_of dfg thy Q |
|
33042 | 143 |
in (CombApp(P',Q'), union (op =) tsP tsQ) end |
35865 | 144 |
| combterm_of _ _ (t as Abs _) = raise CLAUSE ("HOL CLAUSE", t); |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
145 |
|
35865 | 146 |
fun predicate_of dfg thy ((@{const Not} $ P), polarity) = predicate_of dfg thy (P, not polarity) |
30151 | 147 |
| predicate_of dfg thy (t,polarity) = (combterm_of dfg thy (Envir.eta_contract t), polarity); |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
148 |
|
35865 | 149 |
fun literals_of_term1 dfg thy args (@{const Trueprop} $ P) = literals_of_term1 dfg thy args P |
150 |
| literals_of_term1 dfg thy args (@{const "op |"} $ P $ Q) = |
|
30151 | 151 |
literals_of_term1 dfg thy (literals_of_term1 dfg thy args P) Q |
152 |
| literals_of_term1 dfg thy (lits,ts) P = |
|
153 |
let val ((pred,ts'),pol) = predicate_of dfg thy (P,true) |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
154 |
in |
33042 | 155 |
(Literal(pol,pred)::lits, union (op =) ts ts') |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
156 |
end; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
157 |
|
30151 | 158 |
fun literals_of_term_dfg dfg thy P = literals_of_term1 dfg thy ([],[]) P; |
159 |
val literals_of_term = literals_of_term_dfg false; |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
160 |
|
35865 | 161 |
(* Trivial problem, which resolution cannot handle (empty clause) *) |
162 |
exception TRIVIAL; |
|
28835 | 163 |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
164 |
(* making axiom and conjecture clauses *) |
35865 | 165 |
fun make_clause dfg thy (clause_id, axiom_name, kind, th) = |
30151 | 166 |
let val (lits,ctypes_sorts) = literals_of_term_dfg dfg thy (prop_of th) |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
167 |
in |
35865 | 168 |
if forall isFalse lits then |
169 |
raise TRIVIAL |
|
24311 | 170 |
else |
35865 | 171 |
HOLClause {clause_id = clause_id, axiom_name = axiom_name, th = th, |
172 |
kind = kind, literals = lits, ctypes_sorts = ctypes_sorts} |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
173 |
end; |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
174 |
|
20016 | 175 |
|
30151 | 176 |
fun add_axiom_clause dfg thy ((th,(name,id)), pairs) = |
35865 | 177 |
let val cls = make_clause dfg thy (id, name, Axiom, th) |
21573
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
178 |
in |
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
179 |
if isTaut cls then pairs else (name,cls)::pairs |
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
180 |
end; |
19354 | 181 |
|
30190 | 182 |
fun make_axiom_clauses dfg thy = List.foldl (add_axiom_clause dfg thy) []; |
19354 | 183 |
|
32994 | 184 |
fun make_conjecture_clauses_aux _ _ _ [] = [] |
30151 | 185 |
| make_conjecture_clauses_aux dfg thy n (th::ths) = |
35865 | 186 |
make_clause dfg thy (n,"conjecture", Conjecture, th) :: |
30151 | 187 |
make_conjecture_clauses_aux dfg thy (n+1) ths; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
188 |
|
30151 | 189 |
fun make_conjecture_clauses dfg thy = make_conjecture_clauses_aux dfg thy 0; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
190 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
191 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
192 |
(**********************************************************************) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
193 |
(* convert clause into ATP specific formats: *) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
194 |
(* TPTP used by Vampire and E *) |
19720 | 195 |
(* DFG used by SPASS *) |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
196 |
(**********************************************************************) |
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
197 |
|
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
198 |
(*Result of a function type; no need to check that the argument type matches.*) |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
199 |
fun result_type (TyConstr (("tc_fun", _), [_, tp2])) = tp2 |
36168
0a6ed065683d
give more sensible names to "fol_type" constructors, as requested by a FIXME comment
blanchet
parents:
36167
diff
changeset
|
200 |
| result_type _ = raise Fail "Non-function type" |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
201 |
|
32994 | 202 |
fun type_of_combterm (CombConst (_, tp, _)) = tp |
203 |
| type_of_combterm (CombVar (_, tp)) = tp |
|
204 |
| type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1); |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
205 |
|
22064 | 206 |
(*gets the head of a combinator application, along with the list of arguments*) |
35865 | 207 |
fun strip_combterm_comb u = |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
208 |
let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts) |
22064 | 209 |
| stripc x = x |
210 |
in stripc(u,[]) end; |
|
211 |
||
22851
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
212 |
val type_wrapper = "ti"; |
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
213 |
|
30150 | 214 |
fun head_needs_hBOOL const_needs_hBOOL (CombConst(c,_,_)) = needs_hBOOL const_needs_hBOOL c |
32994 | 215 |
| head_needs_hBOOL _ _ = true; |
22851
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
216 |
|
35963 | 217 |
fun wrap_type full_types (s, tp) = |
218 |
if full_types then type_wrapper ^ paren_pack [s, string_of_fol_type tp] else s; |
|
24311 | 219 |
|
35865 | 220 |
fun apply ss = "hAPP" ^ paren_pack ss; |
22851
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
221 |
|
22064 | 222 |
fun rev_apply (v, []) = v |
22851
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
223 |
| rev_apply (v, arg::args) = apply [rev_apply (v, args), arg]; |
22064 | 224 |
|
225 |
fun string_apply (v, args) = rev_apply (v, rev args); |
|
226 |
||
227 |
(*Apply an operator to the argument strings, using either the "apply" operator or |
|
228 |
direct function application.*) |
|
35963 | 229 |
fun string_of_applic full_types cma (CombConst (c, _, tvars), args) = |
22064 | 230 |
let val c = if c = "equal" then "c_fequal" else c |
30150 | 231 |
val nargs = min_arity_of cma c |
22851
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
232 |
val args1 = List.take(args, nargs) |
27187 | 233 |
handle Subscript => error ("string_of_applic: " ^ c ^ " has arity " ^ |
234 |
Int.toString nargs ^ " but is applied to " ^ |
|
235 |
space_implode ", " args) |
|
22064 | 236 |
val args2 = List.drop(args, nargs) |
35963 | 237 |
val targs = if full_types then [] else map string_of_fol_type tvars |
21513
9e9fff87dc6c
Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents:
21509
diff
changeset
|
238 |
in |
35865 | 239 |
string_apply (c ^ paren_pack (args1@targs), args2) |
21513
9e9fff87dc6c
Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents:
21509
diff
changeset
|
240 |
end |
32994 | 241 |
| string_of_applic _ _ (CombVar (v, _), args) = string_apply (v, args) |
31791 | 242 |
| string_of_applic _ _ _ = error "string_of_applic"; |
24311 | 243 |
|
35963 | 244 |
fun wrap_type_if full_types cnh (head, s, tp) = |
245 |
if head_needs_hBOOL cnh head then wrap_type full_types (s, tp) else s; |
|
31791 | 246 |
|
35963 | 247 |
fun string_of_combterm (params as (full_types, cma, cnh)) t = |
35865 | 248 |
let val (head, args) = strip_combterm_comb t |
35963 | 249 |
in wrap_type_if full_types cnh (head, |
250 |
string_of_applic full_types cma |
|
251 |
(head, map (string_of_combterm (params)) args), |
|
252 |
type_of_combterm t) |
|
22851
7b7d6e1c70b6
First-order variant of the fully-typed translation
paulson
parents:
22825
diff
changeset
|
253 |
end; |
18356
443717b3a9ad
Added new type embedding methods for translating HOL clauses.
mengj
parents:
18276
diff
changeset
|
254 |
|
22064 | 255 |
(*Boolean-valued terms are here converted to literals.*) |
31800 | 256 |
fun boolify params t = |
35865 | 257 |
"hBOOL" ^ paren_pack [string_of_combterm params t]; |
22064 | 258 |
|
31800 | 259 |
fun string_of_predicate (params as (_,_,cnh)) t = |
22064 | 260 |
case t of |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
261 |
(CombApp(CombApp(CombConst("equal",_,_), t1), t2)) => |
24311 | 262 |
(*DFG only: new TPTP prefers infix equality*) |
35865 | 263 |
("equal" ^ paren_pack [string_of_combterm params t1, string_of_combterm params t2]) |
24311 | 264 |
| _ => |
35865 | 265 |
case #1 (strip_combterm_comb t) of |
31800 | 266 |
CombConst(c,_,_) => if needs_hBOOL cnh c then boolify params t else string_of_combterm params t |
267 |
| _ => boolify params t; |
|
18356
443717b3a9ad
Added new type embedding methods for translating HOL clauses.
mengj
parents:
18276
diff
changeset
|
268 |
|
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
269 |
|
21561 | 270 |
(*** tptp format ***) |
19720 | 271 |
|
31800 | 272 |
fun tptp_of_equality params pol (t1,t2) = |
21513
9e9fff87dc6c
Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents:
21509
diff
changeset
|
273 |
let val eqop = if pol then " = " else " != " |
31800 | 274 |
in string_of_combterm params t1 ^ eqop ^ string_of_combterm params t2 end; |
21513
9e9fff87dc6c
Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents:
21509
diff
changeset
|
275 |
|
35865 | 276 |
fun tptp_literal params (Literal(pol, CombApp(CombApp(CombConst("equal", _, _), t1), t2))) = |
31800 | 277 |
tptp_of_equality params pol (t1,t2) |
278 |
| tptp_literal params (Literal(pol,pred)) = |
|
35865 | 279 |
tptp_sign pol (string_of_predicate params pred); |
24311 | 280 |
|
22064 | 281 |
(*Given a clause, returns its literals paired with a list of literals concerning TFrees; |
282 |
the latter should only occur in conjecture clauses.*) |
|
35865 | 283 |
fun tptp_type_lits params pos (HOLClause {literals, ctypes_sorts, ...}) = |
31800 | 284 |
(map (tptp_literal params) literals, |
35865 | 285 |
map (tptp_of_typeLit pos) (add_typs ctypes_sorts)); |
24311 | 286 |
|
35865 | 287 |
fun clause2tptp params (cls as HOLClause {axiom_name, clause_id, kind, ...}) = |
288 |
let val (lits,tylits) = tptp_type_lits params (kind = Conjecture) cls |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24385
diff
changeset
|
289 |
in |
35865 | 290 |
(gen_tptp_cls (clause_id, axiom_name, kind, lits, tylits), tylits) |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24385
diff
changeset
|
291 |
end; |
17998
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
292 |
|
0a869029ca58
A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff
changeset
|
293 |
|
21561 | 294 |
(*** dfg format ***) |
295 |
||
35865 | 296 |
fun dfg_literal params (Literal(pol,pred)) = dfg_sign pol (string_of_predicate params pred); |
19720 | 297 |
|
35865 | 298 |
fun dfg_type_lits params pos (HOLClause {literals, ctypes_sorts, ...}) = |
31800 | 299 |
(map (dfg_literal params) literals, |
35865 | 300 |
map (dfg_of_typeLit pos) (add_typs ctypes_sorts)); |
19720 | 301 |
|
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
302 |
fun get_uvars (CombConst _) vars = vars |
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
303 |
| get_uvars (CombVar(v,_)) vars = (v::vars) |
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
304 |
| get_uvars (CombApp(P,Q)) vars = get_uvars P (get_uvars Q vars); |
19720 | 305 |
|
306 |
fun get_uvars_l (Literal(_,c)) = get_uvars c []; |
|
307 |
||
35865 | 308 |
fun dfg_vars (HOLClause {literals,...}) = union_all (map get_uvars_l literals); |
24311 | 309 |
|
35865 | 310 |
fun clause2dfg params (cls as HOLClause {axiom_name, clause_id, kind, |
311 |
ctypes_sorts, ...}) = |
|
312 |
let val (lits,tylits) = dfg_type_lits params (kind = Conjecture) cls |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24385
diff
changeset
|
313 |
val vars = dfg_vars cls |
35865 | 314 |
val tvars = get_tvar_strs ctypes_sorts |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24385
diff
changeset
|
315 |
in |
35865 | 316 |
(gen_dfg_cls (clause_id, axiom_name, kind, lits, tylits, tvars@vars), tylits) |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24385
diff
changeset
|
317 |
end; |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24385
diff
changeset
|
318 |
|
19720 | 319 |
|
22064 | 320 |
(** For DFG format: accumulate function and predicate declarations **) |
19720 | 321 |
|
35865 | 322 |
fun addtypes tvars tab = List.foldl add_foltype_funcs tab tvars; |
19720 | 323 |
|
35963 | 324 |
fun add_decls (full_types, cma, cnh) (CombConst (c, _, tvars), (funcs, preds)) = |
22064 | 325 |
if c = "equal" then (addtypes tvars funcs, preds) |
21561 | 326 |
else |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
327 |
let val arity = min_arity_of cma c |
35963 | 328 |
val ntys = if not full_types then length tvars else 0 |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
329 |
val addit = Symtab.update(c, arity+ntys) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
330 |
in |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
331 |
if needs_hBOOL cnh c then (addtypes tvars (addit funcs), preds) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
332 |
else (addtypes tvars funcs, addit preds) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
333 |
end |
31800 | 334 |
| add_decls _ (CombVar(_,ctp), (funcs,preds)) = |
35865 | 335 |
(add_foltype_funcs (ctp,funcs), preds) |
31800 | 336 |
| add_decls params (CombApp(P,Q),decls) = add_decls params (P,add_decls params (Q,decls)); |
19720 | 337 |
|
35865 | 338 |
fun add_literal_decls params (Literal (_,c), decls) = add_decls params (c,decls); |
19720 | 339 |
|
35865 | 340 |
fun add_clause_decls params (HOLClause {literals, ...}, decls) = |
31800 | 341 |
List.foldl (add_literal_decls params) decls literals |
27187 | 342 |
handle Symtab.DUP a => error ("function " ^ a ^ " has multiple arities") |
19720 | 343 |
|
31800 | 344 |
fun decls_of_clauses params clauses arity_clauses = |
35865 | 345 |
let val init_functab = Symtab.update (type_wrapper,2) (Symtab.update ("hAPP",2) init_functab) |
22064 | 346 |
val init_predtab = Symtab.update ("hBOOL",1) Symtab.empty |
31800 | 347 |
val (functab,predtab) = (List.foldl (add_clause_decls params) (init_functab, init_predtab) clauses) |
22064 | 348 |
in |
35865 | 349 |
(Symtab.dest (List.foldl add_arity_clause_funcs functab arity_clauses), |
22064 | 350 |
Symtab.dest predtab) |
351 |
end; |
|
19720 | 352 |
|
35865 | 353 |
fun add_clause_preds (HOLClause {ctypes_sorts, ...}, preds) = |
354 |
List.foldl add_type_sort_preds preds ctypes_sorts |
|
27187 | 355 |
handle Symtab.DUP a => error ("predicate " ^ a ^ " has multiple arities") |
21398
11996e938dfe
Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents:
21254
diff
changeset
|
356 |
|
11996e938dfe
Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents:
21254
diff
changeset
|
357 |
(*Higher-order clauses have only the predicates hBOOL and type classes.*) |
24311 | 358 |
fun preds_of_clauses clauses clsrel_clauses arity_clauses = |
19720 | 359 |
Symtab.dest |
35865 | 360 |
(List.foldl add_classrel_clause_preds |
361 |
(List.foldl add_arity_clause_preds |
|
30190 | 362 |
(List.foldl add_clause_preds Symtab.empty clauses) |
24311 | 363 |
arity_clauses) |
364 |
clsrel_clauses) |
|
19720 | 365 |
|
18440
72ee07f4b56b
Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents:
18356
diff
changeset
|
366 |
|
72ee07f4b56b
Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents:
18356
diff
changeset
|
367 |
(**********************************************************************) |
19198
e6f1ff40ba99
Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents:
19130
diff
changeset
|
368 |
(* write clauses to files *) |
e6f1ff40ba99
Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents:
19130
diff
changeset
|
369 |
(**********************************************************************) |
e6f1ff40ba99
Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents:
19130
diff
changeset
|
370 |
|
21573
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
371 |
val init_counters = |
35865 | 372 |
Symtab.make [("c_COMBI", 0), ("c_COMBK", 0), ("c_COMBB", 0), ("c_COMBC", 0), |
373 |
("c_COMBS", 0)]; |
|
24311 | 374 |
|
32994 | 375 |
fun count_combterm (CombConst (c, _, _), ct) = |
21573
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
376 |
(case Symtab.lookup ct c of NONE => ct (*no counter*) |
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
377 |
| SOME n => Symtab.update (c,n+1) ct) |
32994 | 378 |
| count_combterm (CombVar _, ct) = ct |
22078
5084f53cef39
Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents:
22064
diff
changeset
|
379 |
| count_combterm (CombApp(t1,t2), ct) = count_combterm(t1, count_combterm(t2, ct)); |
21573
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
380 |
|
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
381 |
fun count_literal (Literal(_,t), ct) = count_combterm(t,ct); |
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
382 |
|
35865 | 383 |
fun count_clause (HOLClause {literals, ...}, ct) = |
384 |
List.foldl count_literal ct literals; |
|
21573
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
385 |
|
35865 | 386 |
fun count_user_clause user_lemmas (HOLClause {axiom_name, literals, ...}, ct) = |
30190 | 387 |
if axiom_name mem_string user_lemmas then List.foldl count_literal ct literals |
21573
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
388 |
else ct; |
8a7a68c0096c
Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents:
21561
diff
changeset
|
389 |
|
35865 | 390 |
fun cnf_helper_thms thy = cnf_rules_pairs thy o map pairname |
20644 | 391 |
|
31752
19a5f1c8a844
use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents:
31749
diff
changeset
|
392 |
fun get_helper_clauses dfg thy isFO (conjectures, axcls, user_lemmas) = |
35865 | 393 |
if isFO then |
394 |
[] |
|
23386 | 395 |
else |
31752
19a5f1c8a844
use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents:
31749
diff
changeset
|
396 |
let |
19a5f1c8a844
use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents:
31749
diff
changeset
|
397 |
val axclauses = map #2 (make_axiom_clauses dfg thy axcls) |
19a5f1c8a844
use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents:
31749
diff
changeset
|
398 |
val ct0 = List.foldl count_clause init_counters conjectures |
30190 | 399 |
val ct = List.foldl (count_user_clause user_lemmas) ct0 axclauses |
33035 | 400 |
fun needed c = the (Symtab.lookup ct c) > 0 |
24311 | 401 |
val IK = if needed "c_COMBI" orelse needed "c_COMBK" |
35865 | 402 |
then cnf_helper_thms thy [@{thm COMBI_def}, @{thm COMBK_def}] |
24311 | 403 |
else [] |
404 |
val BC = if needed "c_COMBB" orelse needed "c_COMBC" |
|
35865 | 405 |
then cnf_helper_thms thy [@{thm COMBB_def}, @{thm COMBC_def}] |
21135 | 406 |
else [] |
35865 | 407 |
val S = if needed "c_COMBS" then cnf_helper_thms thy [@{thm COMBS_def}] |
24311 | 408 |
else [] |
35865 | 409 |
val other = cnf_helper_thms thy [@{thm fequal_imp_equal}, |
410 |
@{thm equal_imp_fequal}] |
|
20791
497e1c9d4a9f
Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents:
20660
diff
changeset
|
411 |
in |
30151 | 412 |
map #2 (make_axiom_clauses dfg thy (other @ IK @ BC @ S)) |
23386 | 413 |
end; |
20791
497e1c9d4a9f
Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents:
20660
diff
changeset
|
414 |
|
22064 | 415 |
(*Find the minimal arity of each function mentioned in the term. Also, note which uses |
416 |
are not at top level, to see if hBOOL is needed.*) |
|
30150 | 417 |
fun count_constants_term toplev t (const_min_arity, const_needs_hBOOL) = |
35865 | 418 |
let val (head, args) = strip_combterm_comb t |
22064 | 419 |
val n = length args |
30150 | 420 |
val (const_min_arity, const_needs_hBOOL) = fold (count_constants_term false) args (const_min_arity, const_needs_hBOOL) |
22064 | 421 |
in |
422 |
case head of |
|
24311 | 423 |
CombConst (a,_,_) => (*predicate or function version of "equal"?*) |
424 |
let val a = if a="equal" andalso not toplev then "c_fequal" else a |
|
33029 | 425 |
val const_min_arity = Symtab.map_default (a, n) (Integer.min n) const_min_arity |
24311 | 426 |
in |
30150 | 427 |
if toplev then (const_min_arity, const_needs_hBOOL) |
428 |
else (const_min_arity, Symtab.update (a,true) (const_needs_hBOOL)) |
|
24311 | 429 |
end |
32994 | 430 |
| _ => (const_min_arity, const_needs_hBOOL) |
22064 | 431 |
end; |
432 |
||
433 |
(*A literal is a top-level term*) |
|
30150 | 434 |
fun count_constants_lit (Literal (_,t)) (const_min_arity, const_needs_hBOOL) = |
435 |
count_constants_term true t (const_min_arity, const_needs_hBOOL); |
|
22064 | 436 |
|
35865 | 437 |
fun count_constants_clause (HOLClause {literals, ...}) |
438 |
(const_min_arity, const_needs_hBOOL) = |
|
30150 | 439 |
fold count_constants_lit literals (const_min_arity, const_needs_hBOOL); |
22064 | 440 |
|
30150 | 441 |
fun display_arity const_needs_hBOOL (c,n) = |
35865 | 442 |
trace_msg (fn () => "Constant: " ^ c ^ |
35826 | 443 |
" arity:\t" ^ Int.toString n ^ |
30150 | 444 |
(if needs_hBOOL const_needs_hBOOL c then " needs hBOOL" else "")); |
22064 | 445 |
|
31865
5e97c4abd18e
fixed: count constants with supplementary lemmas
immler@in.tum.de
parents:
31839
diff
changeset
|
446 |
fun count_constants (conjectures, _, extra_clauses, helper_clauses, _, _) = |
30153
051d3825a15d
turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents:
30151
diff
changeset
|
447 |
if minimize_applies then |
30150 | 448 |
let val (const_min_arity, const_needs_hBOOL) = |
449 |
fold count_constants_clause conjectures (Symtab.empty, Symtab.empty) |
|
31865
5e97c4abd18e
fixed: count constants with supplementary lemmas
immler@in.tum.de
parents:
31839
diff
changeset
|
450 |
|> fold count_constants_clause extra_clauses |
30149 | 451 |
|> fold count_constants_clause helper_clauses |
30150 | 452 |
val _ = List.app (display_arity const_needs_hBOOL) (Symtab.dest (const_min_arity)) |
453 |
in (const_min_arity, const_needs_hBOOL) end |
|
454 |
else (Symtab.empty, Symtab.empty); |
|
22064 | 455 |
|
35865 | 456 |
(* TPTP format *) |
31749 | 457 |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
458 |
fun write_tptp_file debug full_types file clauses = |
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
30242
diff
changeset
|
459 |
let |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
460 |
fun section _ [] = [] |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
461 |
| section name ss = "\n% " ^ name ^ plural_s (length ss) ^ "\n" :: ss |
31865
5e97c4abd18e
fixed: count constants with supplementary lemmas
immler@in.tum.de
parents:
31839
diff
changeset
|
462 |
val (conjectures, axclauses, _, helper_clauses, |
5e97c4abd18e
fixed: count constants with supplementary lemmas
immler@in.tum.de
parents:
31839
diff
changeset
|
463 |
classrel_clauses, arity_clauses) = clauses |
31791 | 464 |
val (cma, cnh) = count_constants clauses |
35963 | 465 |
val params = (full_types, cma, cnh) |
31791 | 466 |
val (tptp_clss,tfree_litss) = ListPair.unzip (map (clause2tptp params) conjectures) |
35865 | 467 |
val tfree_clss = map tptp_tfree_clause (List.foldl (uncurry (union (op =))) [] tfree_litss) |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
468 |
val timestamp = Date.fmt "%Y-%m-%d %H:%M:%S" (Date.fromTimeLocal (Time.now ())) |
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
469 |
val _ = |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
470 |
File.write_list file ( |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
471 |
"% This file was generated by Isabelle (most likely Sledgehammer)\n" ^ |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
472 |
"% " ^ timestamp ^ "\n" :: |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
473 |
section "Relevant fact" (map (#1 o (clause2tptp params)) axclauses) @ |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
474 |
section "Type variable" tfree_clss @ |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
475 |
section "Class relationship" |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
476 |
(map tptp_classrel_clause classrel_clauses) @ |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
477 |
section "Arity declaration" (map tptp_arity_clause arity_clauses) @ |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
478 |
section "Helper fact" (map (#1 o (clause2tptp params)) helper_clauses) @ |
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
479 |
section "Conjecture" tptp_clss) |
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
480 |
in (length axclauses + 1, length tfree_clss + length tptp_clss) |
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
30242
diff
changeset
|
481 |
end; |
19198
e6f1ff40ba99
Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents:
19130
diff
changeset
|
482 |
|
19720 | 483 |
|
35865 | 484 |
(* DFG format *) |
19720 | 485 |
|
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
486 |
fun write_dfg_file debug full_types file clauses = |
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
30242
diff
changeset
|
487 |
let |
31865
5e97c4abd18e
fixed: count constants with supplementary lemmas
immler@in.tum.de
parents:
31839
diff
changeset
|
488 |
val (conjectures, axclauses, _, helper_clauses, |
5e97c4abd18e
fixed: count constants with supplementary lemmas
immler@in.tum.de
parents:
31839
diff
changeset
|
489 |
classrel_clauses, arity_clauses) = clauses |
31791 | 490 |
val (cma, cnh) = count_constants clauses |
35963 | 491 |
val params = (full_types, cma, cnh) |
31791 | 492 |
val (dfg_clss, tfree_litss) = ListPair.unzip (map (clause2dfg params) conjectures) |
31838 | 493 |
and probname = Path.implode (Path.base file) |
31791 | 494 |
val axstrs = map (#1 o (clause2dfg params)) axclauses |
35865 | 495 |
val tfree_clss = map dfg_tfree_clause (union_all tfree_litss) |
31791 | 496 |
val helper_clauses_strs = map (#1 o (clause2dfg params)) helper_clauses |
497 |
val (funcs,cl_preds) = decls_of_clauses params (helper_clauses @ conjectures @ axclauses) arity_clauses |
|
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
30242
diff
changeset
|
498 |
and ty_preds = preds_of_clauses axclauses classrel_clauses arity_clauses |
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
499 |
val _ = |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
500 |
File.write_list file ( |
35865 | 501 |
string_of_start probname :: |
502 |
string_of_descrip probname :: |
|
503 |
string_of_symbols (string_of_funcs funcs) |
|
504 |
(string_of_preds (cl_preds @ ty_preds)) :: |
|
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
505 |
"list_of_clauses(axioms, cnf).\n" :: |
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
506 |
axstrs @ |
35865 | 507 |
map dfg_classrel_clause classrel_clauses @ |
508 |
map dfg_arity_clause arity_clauses @ |
|
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
509 |
helper_clauses_strs @ |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
510 |
["end_of_list.\n\nlist_of_clauses(conjectures, cnf).\n"] @ |
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
511 |
tfree_clss @ |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
512 |
dfg_clss @ |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
513 |
["end_of_list.\n\n", |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
514 |
(*VarWeight=3 helps the HO problems, probably by counteracting the presence of hAPP*) |
36167
c1a35be8e476
make Sledgehammer's output more debugging friendly
blanchet
parents:
35963
diff
changeset
|
515 |
"list_of_settings(SPASS).\n{*\nset_flag(VarWeight, 3).\n*}\nend_of_list.\n\n", |
31839
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
516 |
"end_problem.\n"]) |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
517 |
|
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
518 |
in (length axclauses + length classrel_clauses + length arity_clauses + |
26f18ec0e293
return number of first conjecture-clause and number of conjecture-clauses;
immler@in.tum.de
parents:
31838
diff
changeset
|
519 |
length helper_clauses + 1, length tfree_clss + length dfg_clss) |
31409
d8537ba165b5
split preparing clauses and writing problemfile;
immler@in.tum.de
parents:
30242
diff
changeset
|
520 |
end; |
19720 | 521 |
|
33311 | 522 |
end; |