author | blanchet |
Wed, 04 Mar 2009 10:45:52 +0100 | |
changeset 30240 | 5b25fee0362c |
parent 29676 | cfa3378decf7 |
child 30242 | aea5d7fa7ef5 |
permissions | -rw-r--r-- |
15347 | 1 |
(* Author: Jia Meng, Cambridge University Computer Laboratory |
2 |
Copyright 2004 University of Cambridge |
|
3 |
||
24310 | 4 |
Storing/printing FOL clauses and arity clauses. |
15347 | 5 |
Typed equality is treated differently. |
6 |
*) |
|
7 |
||
23385 | 8 |
(*FIXME: combine with res_hol_clause!*) |
15347 | 9 |
signature RES_CLAUSE = |
24310 | 10 |
sig |
11 |
val schematic_var_prefix: string |
|
12 |
val fixed_var_prefix: string |
|
13 |
val tvar_prefix: string |
|
14 |
val tfree_prefix: string |
|
15 |
val clause_prefix: string |
|
16 |
val const_prefix: string |
|
17 |
val tconst_prefix: string |
|
18 |
val class_prefix: string |
|
19 |
val union_all: ''a list list -> ''a list |
|
20 |
val const_trans_table: string Symtab.table |
|
21 |
val type_const_trans_table: string Symtab.table |
|
22 |
val ascii_of: string -> string |
|
23 |
val undo_ascii_of: string -> string |
|
24 |
val paren_pack : string list -> string |
|
25 |
val make_schematic_var : string * int -> string |
|
18868 | 26 |
val make_fixed_var : string -> string |
27 |
val make_schematic_type_var : string * int -> string |
|
24310 | 28 |
val make_fixed_type_var : string -> string |
30240 | 29 |
val make_fixed_const : bool -> string -> string |
30 |
val make_fixed_type_const : bool -> string -> string |
|
18868 | 31 |
val make_type_class : string -> string |
24310 | 32 |
datatype kind = Axiom | Conjecture |
33 |
type axiom_name = string |
|
34 |
datatype fol_type = |
|
35 |
AtomV of string |
|
36 |
| AtomF of string |
|
37 |
| Comp of string * fol_type list |
|
18868 | 38 |
val string_of_fol_type : fol_type -> string |
24310 | 39 |
datatype type_literal = LTVar of string * string | LTFree of string * string |
40 |
exception CLAUSE of string * term |
|
24940 | 41 |
val add_typs : typ list -> type_literal list |
42 |
val get_tvar_strs: typ list -> string list |
|
24310 | 43 |
datatype arLit = |
44 |
TConsLit of class * string * string list |
|
45 |
| TVarLit of class * string |
|
46 |
datatype arityClause = ArityClause of |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
47 |
{axiom_name: axiom_name, conclLit: arLit, premLits: arLit list} |
24310 | 48 |
datatype classrelClause = ClassrelClause of |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
49 |
{axiom_name: axiom_name, subclass: class, superclass: class} |
24310 | 50 |
val make_classrel_clauses: theory -> class list -> class list -> classrelClause list |
30240 | 51 |
val make_arity_clauses_dfg: bool -> theory -> string list -> class list -> class list * arityClause list |
24310 | 52 |
val make_arity_clauses: theory -> string list -> class list -> class list * arityClause list |
24940 | 53 |
val add_type_sort_preds: typ * int Symtab.table -> int Symtab.table |
24310 | 54 |
val add_classrelClause_preds : classrelClause * int Symtab.table -> int Symtab.table |
55 |
val class_of_arityLit: arLit -> class |
|
56 |
val add_arityClause_preds: arityClause * int Symtab.table -> int Symtab.table |
|
57 |
val add_foltype_funcs: fol_type * int Symtab.table -> int Symtab.table |
|
58 |
val add_arityClause_funcs: arityClause * int Symtab.table -> int Symtab.table |
|
59 |
val init_functab: int Symtab.table |
|
60 |
val writeln_strs: TextIO.outstream -> string list -> unit |
|
19719 | 61 |
val dfg_sign: bool -> string -> string |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
62 |
val dfg_of_typeLit: bool -> type_literal -> string |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
63 |
val gen_dfg_cls: int * string * kind * string list * string list * string list -> string |
24310 | 64 |
val string_of_preds: (string * Int.int) list -> string |
65 |
val string_of_funcs: (string * int) list -> string |
|
66 |
val string_of_symbols: string -> string -> string |
|
19719 | 67 |
val string_of_start: string -> string |
68 |
val string_of_descrip : string -> string |
|
24310 | 69 |
val dfg_tfree_clause : string -> string |
19719 | 70 |
val dfg_classrelClause: classrelClause -> string |
71 |
val dfg_arity_clause: arityClause -> string |
|
24310 | 72 |
val tptp_sign: bool -> string -> string |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
73 |
val tptp_of_typeLit : bool -> type_literal -> string |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
74 |
val gen_tptp_cls : int * string * kind * string list * string list -> string |
24310 | 75 |
val tptp_tfree_clause : string -> string |
76 |
val tptp_arity_clause : arityClause -> string |
|
77 |
val tptp_classrelClause : classrelClause -> string |
|
78 |
end |
|
15347 | 79 |
|
24310 | 80 |
structure ResClause: RES_CLAUSE = |
15347 | 81 |
struct |
82 |
||
83 |
val schematic_var_prefix = "V_"; |
|
84 |
val fixed_var_prefix = "v_"; |
|
85 |
||
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
86 |
val tvar_prefix = "T_"; |
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
87 |
val tfree_prefix = "t_"; |
15347 | 88 |
|
24310 | 89 |
val clause_prefix = "cls_"; |
90 |
val arclause_prefix = "clsarity_" |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
91 |
val clrelclause_prefix = "clsrel_"; |
15347 | 92 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
93 |
val const_prefix = "c_"; |
24310 | 94 |
val tconst_prefix = "tc_"; |
95 |
val class_prefix = "class_"; |
|
15347 | 96 |
|
30240 | 97 |
fun union_all xss = List.foldl (op union) [] xss; |
17775 | 98 |
|
99 |
(*Provide readable names for the more common symbolic functions*) |
|
15347 | 100 |
val const_trans_table = |
101 |
Symtab.make [("op =", "equal"), |
|
24310 | 102 |
(@{const_name HOL.less_eq}, "lessequals"), |
103 |
(@{const_name HOL.less}, "less"), |
|
104 |
("op &", "and"), |
|
105 |
("op |", "or"), |
|
106 |
(@{const_name HOL.plus}, "plus"), |
|
107 |
(@{const_name HOL.minus}, "minus"), |
|
108 |
(@{const_name HOL.times}, "times"), |
|
109 |
(@{const_name Divides.div}, "div"), |
|
110 |
(@{const_name HOL.divide}, "divide"), |
|
111 |
("op -->", "implies"), |
|
112 |
("{}", "emptyset"), |
|
113 |
("op :", "in"), |
|
114 |
("op Un", "union"), |
|
115 |
("op Int", "inter"), |
|
116 |
("List.append", "append"), |
|
117 |
("ATP_Linkup.fequal", "fequal"), |
|
118 |
("ATP_Linkup.COMBI", "COMBI"), |
|
119 |
("ATP_Linkup.COMBK", "COMBK"), |
|
120 |
("ATP_Linkup.COMBB", "COMBB"), |
|
121 |
("ATP_Linkup.COMBC", "COMBC"), |
|
122 |
("ATP_Linkup.COMBS", "COMBS"), |
|
123 |
("ATP_Linkup.COMBB'", "COMBB_e"), |
|
124 |
("ATP_Linkup.COMBC'", "COMBC_e"), |
|
125 |
("ATP_Linkup.COMBS'", "COMBS_e")]; |
|
15347 | 126 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
127 |
val type_const_trans_table = |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
128 |
Symtab.make [("*", "prod"), |
24310 | 129 |
("+", "sum"), |
130 |
("~=>", "map")]; |
|
15347 | 131 |
|
15610 | 132 |
(*Escaping of special characters. |
133 |
Alphanumeric characters are left unchanged. |
|
134 |
The character _ goes to __ |
|
135 |
Characters in the range ASCII space to / go to _A to _P, respectively. |
|
24183 | 136 |
Other printing characters go to _nnn where nnn is the decimal ASCII code.*) |
137 |
val A_minus_space = Char.ord #"A" - Char.ord #" "; |
|
15610 | 138 |
|
24183 | 139 |
fun stringN_of_int 0 _ = "" |
140 |
| stringN_of_int k n = stringN_of_int (k-1) (n div 10) ^ Int.toString (n mod 10); |
|
15610 | 141 |
|
15347 | 142 |
fun ascii_of_c c = |
15610 | 143 |
if Char.isAlphaNum c then String.str c |
144 |
else if c = #"_" then "__" |
|
24310 | 145 |
else if #" " <= c andalso c <= #"/" |
15610 | 146 |
then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) |
24310 | 147 |
else if Char.isPrint c |
24183 | 148 |
then ("_" ^ stringN_of_int 3 (Char.ord c)) (*fixed width, in case more digits follow*) |
15610 | 149 |
else "" |
15347 | 150 |
|
15610 | 151 |
val ascii_of = String.translate ascii_of_c; |
152 |
||
24183 | 153 |
(** Remove ASCII armouring from names in proof files **) |
154 |
||
155 |
(*We don't raise error exceptions because this code can run inside the watcher. |
|
156 |
Also, the errors are "impossible" (hah!)*) |
|
157 |
fun undo_ascii_aux rcs [] = String.implode(rev rcs) |
|
158 |
| undo_ascii_aux rcs [#"_"] = undo_ascii_aux (#"_"::rcs) [] (*ERROR*) |
|
159 |
(*Three types of _ escapes: __, _A to _P, _nnn*) |
|
160 |
| undo_ascii_aux rcs (#"_" :: #"_" :: cs) = undo_ascii_aux (#"_"::rcs) cs |
|
24310 | 161 |
| undo_ascii_aux rcs (#"_" :: c :: cs) = |
24183 | 162 |
if #"A" <= c andalso c<= #"P" (*translation of #" " to #"/"*) |
163 |
then undo_ascii_aux (Char.chr(Char.ord c - A_minus_space) :: rcs) cs |
|
24310 | 164 |
else |
24183 | 165 |
let val digits = List.take (c::cs, 3) handle Subscript => [] |
24310 | 166 |
in |
24183 | 167 |
case Int.fromString (String.implode digits) of |
168 |
NONE => undo_ascii_aux (c:: #"_"::rcs) cs (*ERROR*) |
|
169 |
| SOME n => undo_ascii_aux (Char.chr n :: rcs) (List.drop (cs, 2)) |
|
170 |
end |
|
171 |
| undo_ascii_aux rcs (c::cs) = undo_ascii_aux (c::rcs) cs; |
|
172 |
||
173 |
val undo_ascii_of = undo_ascii_aux [] o String.explode; |
|
15347 | 174 |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
175 |
(* convert a list of strings into one single string; surrounded by brackets *) |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
176 |
fun paren_pack [] = "" (*empty argument list*) |
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
177 |
| paren_pack strings = "(" ^ commas strings ^ ")"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
178 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
179 |
(*TSTP format uses (...) rather than the old [...]*) |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
180 |
fun tptp_pack strings = "(" ^ space_implode " | " strings ^ ")"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
181 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
182 |
|
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
183 |
(*Remove the initial ' character from a type variable, if it is present*) |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
184 |
fun trim_type_var s = |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
185 |
if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE) |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
186 |
else error ("trim_type: Malformed type variable encountered: " ^ s); |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
187 |
|
16903 | 188 |
fun ascii_of_indexname (v,0) = ascii_of v |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
189 |
| ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i; |
15347 | 190 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
191 |
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v); |
15347 | 192 |
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x); |
193 |
||
24310 | 194 |
fun make_schematic_type_var (x,i) = |
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
195 |
tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i)); |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
196 |
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); |
15347 | 197 |
|
23075 | 198 |
(*HACK because SPASS truncates identifiers to 63 characters :-(( *) |
199 |
(*32-bit hash,so we expect no collisions unless there are around 65536 long identifiers...*) |
|
30240 | 200 |
fun controlled_length dfg_format s = |
201 |
if size s > 60 andalso dfg_format |
|
23075 | 202 |
then Word.toString (Polyhash.hashw_string(s,0w0)) |
203 |
else s; |
|
204 |
||
30240 | 205 |
fun lookup_const dfg c = |
17412 | 206 |
case Symtab.lookup const_trans_table c of |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
207 |
SOME c' => c' |
30240 | 208 |
| NONE => controlled_length dfg (ascii_of c); |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
209 |
|
30240 | 210 |
fun lookup_type_const dfg c = |
17412 | 211 |
case Symtab.lookup type_const_trans_table c of |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
212 |
SOME c' => c' |
30240 | 213 |
| NONE => controlled_length dfg (ascii_of c); |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
214 |
|
30240 | 215 |
fun make_fixed_const _ "op =" = "equal" (*MUST BE "equal" because it's built-in to ATPs*) |
216 |
| make_fixed_const dfg c = const_prefix ^ lookup_const dfg c; |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
217 |
|
30240 | 218 |
fun make_fixed_type_const dfg c = tconst_prefix ^ lookup_type_const dfg c; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
219 |
|
17261 | 220 |
fun make_type_class clas = class_prefix ^ ascii_of clas; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
221 |
|
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
222 |
|
18798 | 223 |
(***** definitions and functions for FOL clauses, for conversion to TPTP or DFG format. *****) |
15347 | 224 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
225 |
datatype kind = Axiom | Conjecture; |
23385 | 226 |
|
15347 | 227 |
type axiom_name = string; |
228 |
||
229 |
(**** Isabelle FOL clauses ****) |
|
230 |
||
18798 | 231 |
(*FIXME: give the constructors more sensible names*) |
18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
232 |
datatype fol_type = AtomV of string |
24310 | 233 |
| AtomF of string |
234 |
| Comp of string * fol_type list; |
|
18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
235 |
|
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
236 |
fun string_of_fol_type (AtomV x) = x |
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
237 |
| string_of_fol_type (AtomF x) = x |
24310 | 238 |
| string_of_fol_type (Comp(tcon,tps)) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
239 |
tcon ^ (paren_pack (map string_of_fol_type tps)); |
24310 | 240 |
|
18798 | 241 |
(*First string is the type class; the second is a TVar or TFfree*) |
242 |
datatype type_literal = LTVar of string * string | LTFree of string * string; |
|
15347 | 243 |
|
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
244 |
exception CLAUSE of string * term; |
15347 | 245 |
|
24940 | 246 |
fun atomic_type (TFree (a,_)) = AtomF(make_fixed_type_var a) |
247 |
| atomic_type (TVar (v,_)) = AtomV(make_schematic_type_var v); |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
248 |
|
18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
249 |
(*Flatten a type to a fol_type while accumulating sort constraints on the TFrees and |
24310 | 250 |
TVars it contains.*) |
30240 | 251 |
fun type_of dfg (Type (a, Ts)) = |
252 |
let val (folTyps, ts) = types_of dfg Ts |
|
253 |
val t = make_fixed_type_const dfg a |
|
18798 | 254 |
in (Comp(t,folTyps), ts) end |
30240 | 255 |
| type_of dfg T = (atomic_type T, [T]) |
256 |
and types_of dfg Ts = |
|
257 |
let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts) |
|
18798 | 258 |
in (folTyps, union_all ts) end; |
15390 | 259 |
|
24310 | 260 |
(*Make literals for sorted type variables*) |
24940 | 261 |
fun sorts_on_typs_aux (_, []) = [] |
262 |
| sorts_on_typs_aux ((x,i), s::ss) = |
|
263 |
let val sorts = sorts_on_typs_aux ((x,i), ss) |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
264 |
in |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
265 |
if s = "HOL.type" then sorts |
24940 | 266 |
else if i = ~1 then LTFree(make_type_class s, make_fixed_type_var x) :: sorts |
267 |
else LTVar(make_type_class s, make_schematic_type_var (x,i)) :: sorts |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
268 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
269 |
|
24940 | 270 |
fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s) |
271 |
| sorts_on_typs (TVar (v,s)) = sorts_on_typs_aux (v,s); |
|
272 |
||
18798 | 273 |
fun pred_of_sort (LTVar (s,ty)) = (s,1) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
274 |
| pred_of_sort (LTFree (s,ty)) = (s,1) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
275 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
276 |
(*Given a list of sorted type variables, return a list of type literals.*) |
30240 | 277 |
fun add_typs Ts = List.foldl (op union) [] (map sorts_on_typs Ts); |
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
278 |
|
29676 | 279 |
(*The correct treatment of TFrees like 'a in lemmas (axiom clauses) is not clear. |
280 |
* Ignoring them leads to unsound proofs, since we do nothing to ensure that 'a |
|
281 |
in a lemma has the same sort as 'a in the conjecture. |
|
282 |
* Deleting such clauses will lead to problems with locales in other use of local results |
|
283 |
where 'a is fixed. Probably we should delete clauses unless the sorts agree. |
|
284 |
* Currently we include a class constraint in the clause, exactly as with TVars. |
|
285 |
*) |
|
286 |
||
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
287 |
(** make axiom and conjecture clauses. **) |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
288 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
289 |
fun get_tvar_strs [] = [] |
24940 | 290 |
| get_tvar_strs ((TVar (indx,s))::Ts) = |
291 |
insert (op =) (make_schematic_type_var indx) (get_tvar_strs Ts) |
|
292 |
| get_tvar_strs((TFree _)::Ts) = get_tvar_strs Ts |
|
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
293 |
|
24310 | 294 |
|
19354 | 295 |
|
15347 | 296 |
(**** Isabelle arities ****) |
297 |
||
298 |
exception ARCLAUSE of string; |
|
299 |
||
24310 | 300 |
datatype arLit = TConsLit of class * string * string list |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
301 |
| TVarLit of class * string; |
24310 | 302 |
|
303 |
datatype arityClause = |
|
304 |
ArityClause of {axiom_name: axiom_name, |
|
305 |
conclLit: arLit, |
|
306 |
premLits: arLit list}; |
|
15347 | 307 |
|
308 |
||
18798 | 309 |
fun gen_TVars 0 = [] |
310 |
| gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1); |
|
15347 | 311 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
312 |
fun pack_sort(_,[]) = [] |
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
313 |
| pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt) (*IGNORE sort "type"*) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
314 |
| pack_sort(tvar, cls::srt) = (cls, tvar) :: pack_sort(tvar, srt); |
24310 | 315 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
316 |
(*Arity of type constructor tcon :: (arg1,...,argN)res*) |
30240 | 317 |
fun make_axiom_arity_clause dfg (tcons, axiom_name, (cls,args)) = |
21560 | 318 |
let val tvars = gen_TVars (length args) |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
319 |
val tvars_srts = ListPair.zip (tvars,args) |
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
320 |
in |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
321 |
ArityClause {axiom_name = axiom_name, |
30240 | 322 |
conclLit = TConsLit (cls, make_fixed_type_const dfg tcons, tvars), |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
323 |
premLits = map TVarLit (union_all(map pack_sort tvars_srts))} |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
324 |
end; |
15347 | 325 |
|
326 |
||
327 |
(**** Isabelle class relations ****) |
|
328 |
||
24310 | 329 |
datatype classrelClause = |
330 |
ClassrelClause of {axiom_name: axiom_name, |
|
331 |
subclass: class, |
|
332 |
superclass: class}; |
|
333 |
||
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
334 |
(*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
21432
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
335 |
fun class_pairs thy [] supers = [] |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
336 |
| class_pairs thy subs supers = |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
337 |
let val class_less = Sorts.class_less(Sign.classes_of thy) |
24310 | 338 |
fun add_super sub (super,pairs) = |
339 |
if class_less (sub,super) then (sub,super)::pairs else pairs |
|
30240 | 340 |
fun add_supers (sub,pairs) = List.foldl (add_super sub) pairs supers |
341 |
in List.foldl add_supers [] subs end; |
|
15347 | 342 |
|
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
343 |
fun make_classrelClause (sub,super) = |
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
344 |
ClassrelClause {axiom_name = clrelclause_prefix ^ ascii_of sub ^ "_" ^ ascii_of super, |
24310 | 345 |
subclass = make_type_class sub, |
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
346 |
superclass = make_type_class super}; |
15347 | 347 |
|
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
348 |
fun make_classrel_clauses thy subs supers = |
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
349 |
map make_classrelClause (class_pairs thy subs supers); |
18868 | 350 |
|
351 |
||
352 |
(** Isabelle arities **) |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
353 |
|
30240 | 354 |
fun arity_clause dfg _ _ (tcons, []) = [] |
355 |
| arity_clause dfg seen n (tcons, ("HOL.type",_)::ars) = (*ignore*) |
|
356 |
arity_clause dfg seen n (tcons,ars) |
|
357 |
| arity_clause dfg seen n (tcons, (ar as (class,_)) :: ars) = |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
358 |
if class mem_string seen then (*multiple arities for the same tycon, class pair*) |
30240 | 359 |
make_axiom_arity_clause dfg (tcons, lookup_type_const dfg tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) :: |
360 |
arity_clause dfg seen (n+1) (tcons,ars) |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
361 |
else |
30240 | 362 |
make_axiom_arity_clause dfg (tcons, lookup_type_const dfg tcons ^ "_" ^ class, ar) :: |
363 |
arity_clause dfg (class::seen) n (tcons,ars) |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
364 |
|
30240 | 365 |
fun multi_arity_clause dfg [] = [] |
366 |
| multi_arity_clause dfg ((tcons,ars) :: tc_arlists) = |
|
367 |
arity_clause dfg [] 1 (tcons, ars) @ multi_arity_clause dfg tc_arlists |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
368 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
369 |
(*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
370 |
provided its arguments have the corresponding sorts.*) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
371 |
fun type_class_pairs thy tycons classes = |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
372 |
let val alg = Sign.classes_of thy |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
373 |
fun domain_sorts (tycon,class) = Sorts.mg_domain alg tycon [class] |
24310 | 374 |
fun add_class tycon (class,pairs) = |
375 |
(class, domain_sorts(tycon,class))::pairs |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
376 |
handle Sorts.CLASS_ERROR _ => pairs |
30240 | 377 |
fun try_classes tycon = (tycon, List.foldl (add_class tycon) [] classes) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
378 |
in map try_classes tycons end; |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
379 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
380 |
(*Proving one (tycon, class) membership may require proving others, so iterate.*) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
381 |
fun iter_type_class_pairs thy tycons [] = ([], []) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
382 |
| iter_type_class_pairs thy tycons classes = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
383 |
let val cpairs = type_class_pairs thy tycons classes |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
384 |
val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs))) \\ classes \\ HOLogic.typeS |
24310 | 385 |
val _ = if null newclasses then () |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
386 |
else Output.debug (fn _ => "New classes: " ^ space_implode ", " newclasses) |
24310 | 387 |
val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
388 |
in (classes' union classes, cpairs' union cpairs) end; |
24310 | 389 |
|
30240 | 390 |
fun make_arity_clauses_dfg dfg thy tycons classes = |
24310 | 391 |
let val (classes', cpairs) = iter_type_class_pairs thy tycons classes |
30240 | 392 |
in (classes', multi_arity_clause dfg cpairs) end; |
393 |
val make_arity_clauses = make_arity_clauses_dfg false; |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
394 |
|
18868 | 395 |
(**** Find occurrences of predicates in clauses ****) |
396 |
||
24310 | 397 |
(*FIXME: multiple-arity checking doesn't work, as update_new is the wrong |
18868 | 398 |
function (it flags repeated declarations of a function, even with the same arity)*) |
399 |
||
30240 | 400 |
fun update_many (tab, keypairs) = List.foldl (uncurry Symtab.update) tab keypairs; |
18868 | 401 |
|
24940 | 402 |
fun add_type_sort_preds (T, preds) = |
403 |
update_many (preds, map pred_of_sort (sorts_on_typs T)); |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
404 |
|
18868 | 405 |
fun add_classrelClause_preds (ClassrelClause {subclass,superclass,...}, preds) = |
406 |
Symtab.update (subclass,1) (Symtab.update (superclass,1) preds); |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
407 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
408 |
fun class_of_arityLit (TConsLit (tclass, _, _)) = tclass |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
409 |
| class_of_arityLit (TVarLit (tclass, _)) = tclass; |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
410 |
|
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
411 |
fun add_arityClause_preds (ArityClause {conclLit,premLits,...}, preds) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
412 |
let val classes = map (make_type_class o class_of_arityLit) (conclLit::premLits) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
413 |
fun upd (class,preds) = Symtab.update (class,1) preds |
30240 | 414 |
in List.foldl upd preds classes end; |
18868 | 415 |
|
416 |
(*** Find occurrences of functions in clauses ***) |
|
417 |
||
418 |
fun add_foltype_funcs (AtomV _, funcs) = funcs |
|
419 |
| add_foltype_funcs (AtomF a, funcs) = Symtab.update (a,0) funcs |
|
24310 | 420 |
| add_foltype_funcs (Comp(a,tys), funcs) = |
30240 | 421 |
List.foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys; |
18868 | 422 |
|
20038 | 423 |
(*TFrees are recorded as constants*) |
24940 | 424 |
fun add_type_sort_funcs (TVar _, funcs) = funcs |
425 |
| add_type_sort_funcs (TFree (a, _), funcs) = |
|
20038 | 426 |
Symtab.update (make_fixed_type_var a, 0) funcs |
427 |
||
18868 | 428 |
fun add_arityClause_funcs (ArityClause {conclLit,...}, funcs) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
429 |
let val TConsLit (_, tcons, tvars) = conclLit |
18868 | 430 |
in Symtab.update (tcons, length tvars) funcs end; |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
431 |
|
23075 | 432 |
(*This type can be overlooked because it is built-in...*) |
433 |
val init_functab = Symtab.update ("tc_itself", 1) Symtab.empty; |
|
434 |
||
18868 | 435 |
|
436 |
(**** String-oriented operations ****) |
|
15347 | 437 |
|
24310 | 438 |
fun string_of_clausename (cls_id,ax_name) = |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
439 |
clause_prefix ^ ascii_of ax_name ^ "_" ^ Int.toString cls_id; |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
440 |
|
24310 | 441 |
fun string_of_type_clsname (cls_id,ax_name,idx) = |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
442 |
string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx); |
18863 | 443 |
|
24310 | 444 |
fun writeln_strs os = List.app (fn s => TextIO.output (os, s)); |
18863 | 445 |
|
24310 | 446 |
|
18868 | 447 |
(**** Producing DFG files ****) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
448 |
|
18863 | 449 |
(*Attach sign in DFG syntax: false means negate.*) |
450 |
fun dfg_sign true s = s |
|
24310 | 451 |
| dfg_sign false s = "not(" ^ s ^ ")" |
18863 | 452 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
453 |
fun dfg_of_typeLit pos (LTVar (s,ty)) = dfg_sign pos (s ^ "(" ^ ty ^ ")") |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
454 |
| dfg_of_typeLit pos (LTFree (s,ty)) = dfg_sign pos (s ^ "(" ^ ty ^ ")"); |
24310 | 455 |
|
18868 | 456 |
(*Enclose the clause body by quantifiers, if necessary*) |
24310 | 457 |
fun dfg_forall [] body = body |
18868 | 458 |
| dfg_forall vars body = "forall([" ^ commas vars ^ "],\n" ^ body ^ ")" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
459 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
460 |
fun gen_dfg_cls (cls_id, ax_name, Axiom, lits, tylits, vars) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
461 |
"clause( %(axiom)\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
462 |
dfg_forall vars ("or(" ^ commas (tylits@lits) ^ ")") ^ ",\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
463 |
string_of_clausename (cls_id,ax_name) ^ ").\n\n" |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
464 |
| gen_dfg_cls (cls_id, ax_name, Conjecture, lits, _, vars) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
465 |
"clause( %(negated_conjecture)\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
466 |
dfg_forall vars ("or(" ^ commas lits ^ ")") ^ ",\n" ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
467 |
string_of_clausename (cls_id,ax_name) ^ ").\n\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
468 |
|
18798 | 469 |
fun string_of_arity (name, num) = "(" ^ name ^ "," ^ Int.toString num ^ ")" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
470 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
471 |
fun string_of_preds [] = "" |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
472 |
| string_of_preds preds = "predicates[" ^ commas(map string_of_arity preds) ^ "].\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
473 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
474 |
fun string_of_funcs [] = "" |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
475 |
| string_of_funcs funcs = "functions[" ^ commas(map string_of_arity funcs) ^ "].\n" ; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
476 |
|
24310 | 477 |
fun string_of_symbols predstr funcstr = |
17234 | 478 |
"list_of_symbols.\n" ^ predstr ^ funcstr ^ "end_of_list.\n\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
479 |
|
18798 | 480 |
fun string_of_start name = "begin_problem(" ^ name ^ ").\n\n"; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
481 |
|
24310 | 482 |
fun string_of_descrip name = |
483 |
"list_of_descriptions.\nname({*" ^ name ^ |
|
18868 | 484 |
"*}).\nauthor({*Isabelle*}).\nstatus(unknown).\ndescription({*auto-generated*}).\nend_of_list.\n\n" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
485 |
|
18863 | 486 |
fun dfg_tfree_clause tfree_lit = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
487 |
"clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n" |
18863 | 488 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
489 |
fun dfg_of_arLit (TConsLit (c,t,args)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
490 |
dfg_sign true (make_type_class c ^ "(" ^ t ^ paren_pack args ^ ")") |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
491 |
| dfg_of_arLit (TVarLit (c,str)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
492 |
dfg_sign false (make_type_class c ^ "(" ^ str ^ ")") |
24310 | 493 |
|
20038 | 494 |
fun dfg_classrelLits sub sup = "not(" ^ sub ^ "(T)), " ^ sup ^ "(T)"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
495 |
|
18868 | 496 |
fun dfg_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) = |
497 |
"clause(forall([T],\nor( " ^ dfg_classrelLits subclass superclass ^ ")),\n" ^ |
|
498 |
axiom_name ^ ").\n\n"; |
|
24310 | 499 |
|
21560 | 500 |
fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name; |
501 |
||
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
502 |
fun dfg_arity_clause (ArityClause{axiom_name,conclLit,premLits,...}) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
503 |
let val TConsLit (_,_,tvars) = conclLit |
18868 | 504 |
val lits = map dfg_of_arLit (conclLit :: premLits) |
18863 | 505 |
in |
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
506 |
"clause( %(axiom)\n" ^ |
18868 | 507 |
dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^ |
21560 | 508 |
string_of_ar axiom_name ^ ").\n\n" |
18863 | 509 |
end; |
510 |
||
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
511 |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
512 |
(**** Produce TPTP files ****) |
18868 | 513 |
|
514 |
(*Attach sign in TPTP syntax: false means negate.*) |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
515 |
fun tptp_sign true s = s |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
516 |
| tptp_sign false s = "~ " ^ s |
18868 | 517 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
518 |
fun tptp_of_typeLit pos (LTVar (s,ty)) = tptp_sign pos (s ^ "(" ^ ty ^ ")") |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
519 |
| tptp_of_typeLit pos (LTFree (s,ty)) = tptp_sign pos (s ^ "(" ^ ty ^ ")"); |
24310 | 520 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
521 |
fun gen_tptp_cls (cls_id,ax_name,Axiom,lits,tylits) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
522 |
"cnf(" ^ string_of_clausename (cls_id,ax_name) ^ ",axiom," ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
523 |
tptp_pack (tylits@lits) ^ ").\n" |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
524 |
| gen_tptp_cls (cls_id,ax_name,Conjecture,lits,_) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
525 |
"cnf(" ^ string_of_clausename (cls_id,ax_name) ^ ",negated_conjecture," ^ |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
526 |
tptp_pack lits ^ ").\n"; |
15347 | 527 |
|
18863 | 528 |
fun tptp_tfree_clause tfree_lit = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
529 |
"cnf(" ^ "tfree_tcs," ^ "negated_conjecture" ^ "," ^ tptp_pack[tfree_lit] ^ ").\n"; |
24310 | 530 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
531 |
fun tptp_of_arLit (TConsLit (c,t,args)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
532 |
tptp_sign true (make_type_class c ^ "(" ^ t ^ paren_pack args ^ ")") |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
533 |
| tptp_of_arLit (TVarLit (c,str)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
534 |
tptp_sign false (make_type_class c ^ "(" ^ str ^ ")") |
24310 | 535 |
|
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
536 |
fun tptp_arity_clause (ArityClause{axiom_name,conclLit,premLits,...}) = |
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
537 |
"cnf(" ^ string_of_ar axiom_name ^ ",axiom," ^ |
21560 | 538 |
tptp_pack (map tptp_of_arLit (conclLit :: premLits)) ^ ").\n"; |
15347 | 539 |
|
24310 | 540 |
fun tptp_classrelLits sub sup = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
541 |
let val tvar = "(T)" |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
542 |
in tptp_pack [tptp_sign false (sub^tvar), tptp_sign true (sup^tvar)] end; |
15347 | 543 |
|
18868 | 544 |
fun tptp_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) = |
24310 | 545 |
"cnf(" ^ axiom_name ^ ",axiom," ^ tptp_classrelLits subclass superclass ^ ").\n" |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
546 |
|
15347 | 547 |
end; |