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