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