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