author | haftmann |
Thu, 17 May 2007 19:49:40 +0200 | |
changeset 22997 | d4f3b015b50b |
parent 22643 | bc3bb8e9594a |
child 23029 | 79ee75dc1e59 |
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?*) |
15347 | 10 |
signature RES_CLAUSE = |
11 |
sig |
|
18868 | 12 |
exception CLAUSE of string * term |
13 |
type clause and arityClause and classrelClause |
|
20824 | 14 |
datatype fol_type = AtomV of string |
15 |
| AtomF of string |
|
16 |
| Comp of string * fol_type list; |
|
21813 | 17 |
datatype fol_term = UVar of string |
20824 | 18 |
| Fun of string * fol_type list * fol_term list; |
19 |
datatype predicate = Predicate of string * fol_type list * fol_term list; |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
20 |
datatype kind = Axiom | Conjecture; |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
21 |
val name_of_kind : kind -> string |
20824 | 22 |
type typ_var and type_literal and literal |
23 |
val literals_of_term: Term.term -> literal list * (typ_var * Term.sort) list |
|
18868 | 24 |
val add_typs_aux : (typ_var * string list) list -> type_literal list * type_literal list |
25 |
val ascii_of : string -> string |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
26 |
val tptp_pack : string list -> string |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
27 |
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
|
28 |
val make_classrel_clauses: theory -> class list -> class list -> classrelClause list |
18868 | 29 |
val clause_prefix : string |
30 |
val clause2tptp : clause -> string * string list |
|
31 |
val const_prefix : string |
|
20022 | 32 |
val dfg_write_file: thm list -> string -> |
33 |
((thm * (string * int)) list * classrelClause list * arityClause list) -> string list |
|
18868 | 34 |
val fixed_var_prefix : string |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
35 |
val gen_tptp_cls : int * string * string * string list -> string |
18868 | 36 |
val get_axiomName : clause -> string |
20824 | 37 |
val get_literals : clause -> literal list |
18868 | 38 |
val init : theory -> unit |
39 |
val isMeta : string -> bool |
|
40 |
val isTaut : clause -> bool |
|
41 |
val list_ord : ('a * 'b -> order) -> 'a list * 'b list -> order |
|
19443
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
mengj
parents:
19354
diff
changeset
|
42 |
val make_axiom_clause : thm -> string * int -> clause option |
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
mengj
parents:
19354
diff
changeset
|
43 |
val make_conjecture_clauses : thm list -> clause list |
18868 | 44 |
val make_fixed_const : string -> string |
45 |
val make_fixed_type_const : string -> string |
|
46 |
val make_fixed_type_var : string -> string |
|
47 |
val make_fixed_var : string -> string |
|
48 |
val make_schematic_type_var : string * int -> string |
|
49 |
val make_schematic_var : string * int -> string |
|
50 |
val make_type_class : string -> string |
|
51 |
val mk_typ_var_sort : Term.typ -> typ_var * sort |
|
52 |
val paren_pack : string list -> string |
|
53 |
val schematic_var_prefix : string |
|
54 |
val string_of_fol_type : fol_type -> string |
|
55 |
val tconst_prefix : string |
|
56 |
val tfree_prefix : string |
|
21813 | 57 |
val tvar_prefix : string |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
58 |
val tptp_arity_clause : arityClause -> string |
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
59 |
val tptp_classrelClause : classrelClause -> string |
18868 | 60 |
val tptp_of_typeLit : type_literal -> string |
18863 | 61 |
val tptp_tfree_clause : string -> string |
20022 | 62 |
val tptp_write_file: thm list -> string -> |
63 |
((thm * (string * int)) list * classrelClause list * arityClause list) -> string list |
|
17908
ac97527724ba
More functions are added to the signature of ResClause
mengj
parents:
17888
diff
changeset
|
64 |
val union_all : ''a list list -> ''a list |
18863 | 65 |
val writeln_strs: TextIO.outstream -> TextIO.vector list -> unit |
19719 | 66 |
val dfg_sign: bool -> string -> string |
67 |
val dfg_of_typeLit: type_literal -> string |
|
68 |
val get_tvar_strs: (typ_var * sort) list -> string list |
|
69 |
val gen_dfg_cls: int * string * string * string * string list -> string |
|
70 |
val add_foltype_funcs: fol_type * int Symtab.table -> int Symtab.table |
|
71 |
val add_arityClause_funcs: arityClause * int Symtab.table -> int Symtab.table |
|
72 |
val add_arityClause_preds: arityClause * int Symtab.table -> int Symtab.table |
|
73 |
val add_classrelClause_preds : classrelClause * int Symtab.table -> int Symtab.table |
|
74 |
val dfg_tfree_clause : string -> string |
|
75 |
val string_of_start: string -> string |
|
76 |
val string_of_descrip : string -> string |
|
77 |
val string_of_symbols: string -> string -> string |
|
78 |
val string_of_funcs: (string * int) list -> string |
|
79 |
val string_of_preds: (string * Int.int) list -> string |
|
80 |
val dfg_classrelClause: classrelClause -> string |
|
81 |
val dfg_arity_clause: arityClause -> string |
|
82 |
end; |
|
15347 | 83 |
|
20422
35a6a4c863f1
removed the (apparently pointless) signature constraint
paulson
parents:
20418
diff
changeset
|
84 |
structure ResClause = |
15347 | 85 |
struct |
86 |
||
87 |
val schematic_var_prefix = "V_"; |
|
88 |
val fixed_var_prefix = "v_"; |
|
89 |
||
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
90 |
val tvar_prefix = "T_"; |
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
91 |
val tfree_prefix = "t_"; |
15347 | 92 |
|
93 |
val clause_prefix = "cls_"; |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
94 |
val arclause_prefix = "clsarity_" |
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
95 |
val clrelclause_prefix = "clsrel_"; |
15347 | 96 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
97 |
val const_prefix = "c_"; |
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
98 |
val tconst_prefix = "tc_"; |
16199
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
paulson
parents:
16039
diff
changeset
|
99 |
val class_prefix = "class_"; |
15347 | 100 |
|
17775 | 101 |
fun union_all xss = foldl (op union) [] xss; |
102 |
||
103 |
(*Provide readable names for the more common symbolic functions*) |
|
15347 | 104 |
val const_trans_table = |
105 |
Symtab.make [("op =", "equal"), |
|
22997 | 106 |
(@{const_name Orderings.less_eq}, "lessequals"), |
107 |
(@{const_name Orderings.less}, "less"), |
|
15347 | 108 |
("op &", "and"), |
109 |
("op |", "or"), |
|
22997 | 110 |
(@{const_name HOL.plus}, "plus"), |
111 |
(@{const_name HOL.minus}, "minus"), |
|
112 |
(@{const_name HOL.times}, "times"), |
|
113 |
(@{const_name Divides.div}, "div"), |
|
114 |
(@{const_name HOL.divide}, "divide"), |
|
15347 | 115 |
("op -->", "implies"), |
17375 | 116 |
("{}", "emptyset"), |
15347 | 117 |
("op :", "in"), |
118 |
("op Un", "union"), |
|
18390 | 119 |
("op Int", "inter"), |
20790
a9595fdc02b1
Added the combinator constants to the constants table.
mengj
parents:
20422
diff
changeset
|
120 |
("List.op @", "append"), |
21254
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
121 |
("ATP_Linkup.fequal", "fequal"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
122 |
("ATP_Linkup.COMBI", "COMBI"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
123 |
("ATP_Linkup.COMBK", "COMBK"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
124 |
("ATP_Linkup.COMBB", "COMBB"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
125 |
("ATP_Linkup.COMBC", "COMBC"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
126 |
("ATP_Linkup.COMBS", "COMBS"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
127 |
("ATP_Linkup.COMBB'", "COMBB_e"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
128 |
("ATP_Linkup.COMBC'", "COMBC_e"), |
d53f76357f41
incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents:
20854
diff
changeset
|
129 |
("ATP_Linkup.COMBS'", "COMBS_e")]; |
15347 | 130 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
131 |
val type_const_trans_table = |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
132 |
Symtab.make [("*", "prod"), |
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
133 |
("+", "sum"), |
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
134 |
("~=>", "map")]; |
15347 | 135 |
|
15610 | 136 |
(*Escaping of special characters. |
137 |
Alphanumeric characters are left unchanged. |
|
138 |
The character _ goes to __ |
|
139 |
Characters in the range ASCII space to / go to _A to _P, respectively. |
|
140 |
Other printing characters go to _NNN where NNN is the decimal ASCII code.*) |
|
141 |
local |
|
142 |
||
143 |
val A_minus_space = Char.ord #"A" - Char.ord #" "; |
|
144 |
||
15347 | 145 |
fun ascii_of_c c = |
15610 | 146 |
if Char.isAlphaNum c then String.str c |
147 |
else if c = #"_" then "__" |
|
148 |
else if #" " <= c andalso c <= #"/" |
|
149 |
then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) |
|
150 |
else if Char.isPrint c then ("_" ^ Int.toString (Char.ord c)) |
|
151 |
else "" |
|
15347 | 152 |
|
15610 | 153 |
in |
154 |
||
155 |
val ascii_of = String.translate ascii_of_c; |
|
156 |
||
157 |
end; |
|
15347 | 158 |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
159 |
(* 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
|
160 |
fun paren_pack [] = "" (*empty argument list*) |
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
161 |
| paren_pack strings = "(" ^ commas strings ^ ")"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
162 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
163 |
(*TSTP format uses (...) rather than the old [...]*) |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
164 |
fun tptp_pack strings = "(" ^ space_implode " | " strings ^ ")"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
165 |
|
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
166 |
|
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
167 |
(*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
|
168 |
fun trim_type_var s = |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
169 |
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
|
170 |
else error ("trim_type: Malformed type variable encountered: " ^ s); |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
171 |
|
16903 | 172 |
fun ascii_of_indexname (v,0) = ascii_of v |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
173 |
| ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i; |
15347 | 174 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
175 |
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v); |
15347 | 176 |
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x); |
177 |
||
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
178 |
fun make_schematic_type_var (x,i) = |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
179 |
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
|
180 |
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); |
15347 | 181 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
182 |
fun lookup_const c = |
17412 | 183 |
case Symtab.lookup const_trans_table c of |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
184 |
SOME c' => c' |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
185 |
| NONE => ascii_of c; |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
186 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
187 |
fun lookup_type_const c = |
17412 | 188 |
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
|
189 |
SOME c' => c' |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
190 |
| NONE => ascii_of c; |
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
191 |
|
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
192 |
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
|
193 |
| 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
|
194 |
|
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
195 |
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
|
196 |
|
17261 | 197 |
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
|
198 |
|
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
199 |
|
18798 | 200 |
(***** definitions and functions for FOL clauses, for conversion to TPTP or DFG format. *****) |
15347 | 201 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
202 |
datatype kind = Axiom | Conjecture; |
15347 | 203 |
fun name_of_kind Axiom = "axiom" |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
204 |
| name_of_kind Conjecture = "negated_conjecture"; |
15347 | 205 |
|
206 |
type clause_id = int; |
|
207 |
type axiom_name = string; |
|
208 |
type polarity = bool; |
|
209 |
||
210 |
(**** Isabelle FOL clauses ****) |
|
211 |
||
18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
212 |
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
|
213 |
|
18798 | 214 |
(*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
|
215 |
datatype fol_type = AtomV of string |
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
216 |
| AtomF of string |
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
217 |
| Comp of string * fol_type list; |
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
218 |
|
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
219 |
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
|
220 |
| string_of_fol_type (AtomF x) = x |
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
221 |
| string_of_fol_type (Comp(tcon,tps)) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
222 |
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
|
223 |
|
18798 | 224 |
(*First string is the type class; the second is a TVar or TFfree*) |
225 |
datatype type_literal = LTVar of string * string | LTFree of string * string; |
|
15347 | 226 |
|
21813 | 227 |
datatype fol_term = UVar of string |
20038 | 228 |
| Fun of string * fol_type list * fol_term list; |
20824 | 229 |
datatype predicate = Predicate of string * fol_type list * fol_term list; |
15347 | 230 |
|
20018 | 231 |
datatype literal = Literal of polarity * predicate; |
15347 | 232 |
|
17999 | 233 |
fun mk_typ_var_sort (TFree(a,s)) = (FOLTFree a,s) |
234 |
| mk_typ_var_sort (TVar(v,s)) = (FOLTVar v,s); |
|
235 |
||
236 |
||
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
237 |
(*A clause has first-order literals and other, type-related literals*) |
15347 | 238 |
datatype clause = |
239 |
Clause of {clause_id: clause_id, |
|
240 |
axiom_name: axiom_name, |
|
19447 | 241 |
th: thm, |
15347 | 242 |
kind: kind, |
243 |
literals: literal list, |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
244 |
types_sorts: (typ_var * sort) list}; |
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
245 |
|
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
246 |
fun get_axiomName (Clause cls) = #axiom_name cls; |
15347 | 247 |
|
20824 | 248 |
fun get_literals (Clause cls) = #literals cls; |
249 |
||
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
250 |
exception CLAUSE of string * term; |
15347 | 251 |
|
20018 | 252 |
fun isFalse (Literal (pol, Predicate(pname,_,[]))) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
253 |
(pol andalso pname = "c_False") orelse |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
254 |
(not pol andalso pname = "c_True") |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
255 |
| isFalse _ = false; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
256 |
|
20018 | 257 |
fun isTrue (Literal (pol, Predicate(pname,_,[]))) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
258 |
(pol andalso pname = "c_True") orelse |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
259 |
(not pol andalso pname = "c_False") |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
260 |
| isTrue _ = false; |
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
261 |
|
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
262 |
fun isTaut (Clause {literals,...}) = exists isTrue literals; |
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
263 |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
264 |
|
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
265 |
(*Declarations of the current theory--to allow suppressing types.*) |
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
266 |
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
|
267 |
|
21790
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
268 |
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
|
269 |
|
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
270 |
(*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
|
271 |
producing any clauses!*) |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
272 |
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
|
273 |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
274 |
|
18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset
|
275 |
(*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
|
276 |
TVars it contains.*) |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
277 |
fun type_of (Type (a, Ts)) = |
18798 | 278 |
let val (folTyps, ts) = types_of Ts |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
279 |
val t = make_fixed_type_const a |
18798 | 280 |
in (Comp(t,folTyps), ts) end |
281 |
| type_of (TFree (a,s)) = (AtomF(make_fixed_type_var a), [(FOLTFree a, s)]) |
|
282 |
| 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
|
283 |
and types_of Ts = |
18798 | 284 |
let val (folTyps,ts) = ListPair.unzip (map type_of Ts) |
285 |
in (folTyps, union_all ts) end; |
|
15390 | 286 |
|
18439
4b517881ac7e
Added functions for fol_type; also put some functions to the signature, used by ResHolClause.
mengj
parents:
18420
diff
changeset
|
287 |
|
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
288 |
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
|
289 |
|
16903 | 290 |
(* Any variables created via the METAHYPS tactical should be treated as |
291 |
universal vars, although it is represented as "Free(...)" by Isabelle *) |
|
292 |
val isMeta = String.isPrefix "METAHYP1_" |
|
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
293 |
|
18798 | 294 |
fun pred_name_type (Const(c,T)) = (make_fixed_const c, const_types_of (c,T)) |
15390 | 295 |
| pred_name_type (Free(x,T)) = |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
296 |
if isMeta x then raise CLAUSE("Predicate Not First Order 1", Free(x,T)) |
18798 | 297 |
else (make_fixed_var x, ([],[])) |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
298 |
| pred_name_type (v as Var _) = raise CLAUSE("Predicate Not First Order 2", v) |
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
299 |
| pred_name_type t = raise CLAUSE("Predicate input unexpected", t); |
15347 | 300 |
|
18798 | 301 |
fun fun_name_type (Const(c,T)) args = (make_fixed_const c, const_types_of (c,T)) |
302 |
| fun_name_type (Free(x,T)) args = |
|
303 |
if isMeta x then raise CLAUSE("Function Not First Order", Free(x,T)) |
|
304 |
else (make_fixed_var x, ([],[])) |
|
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
305 |
| fun_name_type f args = raise CLAUSE("Function Not First Order 1", f); |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
306 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
307 |
(*Convert a term to a fol_term while accumulating sort constraints on the TFrees and |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
308 |
TVars it contains.*) |
15347 | 309 |
fun term_of (Var(ind_nm,T)) = |
21813 | 310 |
let val (_,ts) = type_of T |
311 |
in (UVar(make_schematic_var ind_nm), ts) end |
|
15347 | 312 |
| term_of (Free(x,T)) = |
21813 | 313 |
let val (_,ts) = type_of T |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
314 |
in |
21813 | 315 |
if isMeta x then (UVar(make_schematic_var(x,0)), ts) |
316 |
else (Fun(make_fixed_var x, [], []), ts) |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
317 |
end |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
318 |
| term_of app = |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
319 |
let val (f,args) = strip_comb app |
18798 | 320 |
val (funName,(contys,ts1)) = fun_name_type f args |
321 |
val (args',ts2) = terms_of args |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
322 |
in |
18868 | 323 |
(Fun(funName,contys,args'), union_all (ts1::ts2)) |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
324 |
end |
18798 | 325 |
and terms_of ts = ListPair.unzip (map term_of ts) |
15390 | 326 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
327 |
(*Create a predicate value, again accumulating sort constraints.*) |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
328 |
fun pred_of (Const("op =", typ), args) = |
21813 | 329 |
let val (args',ts) = terms_of args |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
330 |
in |
21813 | 331 |
(Predicate(make_fixed_const "op =", [], args'), |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
332 |
union_all ts) |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
333 |
end |
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
334 |
| pred_of (pred,args) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
335 |
let val (pname, (predType,ts1)) = pred_name_type pred |
18798 | 336 |
val (args',ts2) = terms_of args |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
337 |
in |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
338 |
(Predicate(pname,predType,args'), union_all (ts1::ts2)) |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
339 |
end; |
15347 | 340 |
|
20018 | 341 |
(*Treatment of literals, possibly negated*) |
342 |
fun predicate_of ((Const("Not",_) $ P), polarity) = predicate_of (P, not polarity) |
|
343 |
| predicate_of (term,polarity) = (pred_of (strip_comb term), polarity); |
|
15347 | 344 |
|
17888 | 345 |
fun literals_of_term1 args (Const("Trueprop",_) $ P) = literals_of_term1 args P |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
346 |
| literals_of_term1 args (Const("op |",_) $ P $ Q) = |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
347 |
literals_of_term1 (literals_of_term1 args P) Q |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
348 |
| literals_of_term1 (lits, ts) P = |
20018 | 349 |
let val ((pred, ts'), polarity) = predicate_of (P,true) |
350 |
val lits' = Literal(polarity,pred) :: lits |
|
17234 | 351 |
in |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
352 |
(lits', ts union ts') |
17234 | 353 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
354 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
355 |
val literals_of_term = literals_of_term1 ([],[]); |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
356 |
|
18403
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
mengj
parents:
18402
diff
changeset
|
357 |
|
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
mengj
parents:
18402
diff
changeset
|
358 |
fun list_ord _ ([],[]) = EQUAL |
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
mengj
parents:
18402
diff
changeset
|
359 |
| list_ord _ ([],_) = LESS |
df0c0f35c897
Changed literals' ordering and the functions for sorting literals.
mengj
parents:
18402
diff
changeset
|
360 |
| list_ord _ (_,[]) = GREATER |
19207
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
paulson
parents:
19197
diff
changeset
|
361 |
| list_ord ord (x::xs, y::ys) = |
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
paulson
parents:
19197
diff
changeset
|
362 |
(case ord(x,y) of EQUAL => list_ord ord (xs,ys) |
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
paulson
parents:
19197
diff
changeset
|
363 |
| xy_ord => xy_ord); |
33f1b4515ce4
Tidying and tracing. Handling exn CLAUSE so that errors don't reach top-level.
paulson
parents:
19197
diff
changeset
|
364 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
365 |
(*Make literals for sorted type variables*) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
366 |
fun sorts_on_typs (_, []) = [] |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
367 |
| sorts_on_typs (v, s::ss) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
368 |
let val sorts = sorts_on_typs (v, ss) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
369 |
in |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
370 |
if s = "HOL.type" then sorts |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
371 |
else case v of |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
372 |
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
|
373 |
| 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
|
374 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
375 |
|
18798 | 376 |
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
|
377 |
| 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
|
378 |
|
16199
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
paulson
parents:
16039
diff
changeset
|
379 |
(*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
|
380 |
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
|
381 |
fun add_typs_aux [] = ([],[]) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
382 |
| add_typs_aux ((FOLTVar indx, s) :: tss) = |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
383 |
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
|
384 |
val (vss,fss) = add_typs_aux tss |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
385 |
in |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
386 |
(vs union vss, fss) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
387 |
end |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
388 |
| add_typs_aux ((FOLTFree x, s) :: tss) = |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
389 |
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
|
390 |
val (vss,fss) = add_typs_aux tss |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
391 |
in |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
392 |
(vss, fs union fss) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
393 |
end; |
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
394 |
|
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
395 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
396 |
(** make axiom and conjecture clauses. **) |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
397 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
398 |
exception MAKE_CLAUSE; |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
399 |
fun make_clause (clause_id, axiom_name, th, kind) = |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21432
diff
changeset
|
400 |
let val (lits,types_sorts) = literals_of_term (prop_of th) |
20018 | 401 |
in if forall isFalse lits |
402 |
then error "Problem too trivial for resolution (empty clause)" |
|
403 |
else Clause {clause_id = clause_id, axiom_name = axiom_name, th = th, |
|
404 |
kind = kind, literals = lits, types_sorts = types_sorts} |
|
405 |
end; |
|
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
406 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
407 |
fun get_tvar_strs [] = [] |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
408 |
| get_tvar_strs ((FOLTVar indx,s)::tss) = |
20854 | 409 |
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
|
410 |
| 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
|
411 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
412 |
(* check if a clause is first-order before making a conjecture clause*) |
20418 | 413 |
fun make_conjecture_clause n th = |
22383
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
414 |
if Meson.is_fol_term (theory_of_thm th) (prop_of th) |
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
415 |
then make_clause(n, "conjecture", th, Conjecture) |
20418 | 416 |
else raise CLAUSE("Goal is not FOL", prop_of th); |
417 |
||
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
418 |
fun make_conjecture_clauses_aux _ [] = [] |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
419 |
| make_conjecture_clauses_aux n (t::ts) = |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
420 |
make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
421 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
422 |
val make_conjecture_clauses = make_conjecture_clauses_aux 0 |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
423 |
|
18199
d236379ea408
-- before converting axiom and conjecture clauses into ResClause.clause format, perform "check_is_fol_term" first.
mengj
parents:
18056
diff
changeset
|
424 |
(*before converting an axiom clause to "clause" format, check if it is FOL*) |
22383
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
425 |
fun make_axiom_clause th (ax_name,cls_id) = |
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
426 |
if Meson.is_fol_term (theory_of_thm th) (prop_of th) |
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
427 |
then (SOME (make_clause(cls_id, ax_name, th, Axiom)) handle MAKE_CLAUSE => NONE) |
22130 | 428 |
else (Output.debug (fn () => ("Omitting " ^ ax_name ^ ": Axiom is not FOL")); NONE) |
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
429 |
|
19443
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
mengj
parents:
19354
diff
changeset
|
430 |
fun make_axiom_clauses [] = [] |
22383
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
431 |
| make_axiom_clauses ((th,(name,id))::thms) = |
01e90256550d
Meson.is_fol_term now takes a theory as argument. Minor tidying.
paulson
parents:
22130
diff
changeset
|
432 |
case make_axiom_clause th (name,id) of |
20022 | 433 |
SOME cls => if isTaut cls then make_axiom_clauses thms |
434 |
else (name,cls) :: make_axiom_clauses thms |
|
435 |
| NONE => make_axiom_clauses thms; |
|
19354 | 436 |
|
15347 | 437 |
(**** Isabelle arities ****) |
438 |
||
439 |
exception ARCLAUSE of string; |
|
440 |
||
441 |
type class = string; |
|
442 |
type tcons = string; |
|
443 |
||
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
444 |
datatype arLit = TConsLit of class * tcons * string list |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
445 |
| TVarLit of class * string; |
15347 | 446 |
|
447 |
datatype arityClause = |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
448 |
ArityClause of {axiom_name: axiom_name, |
15347 | 449 |
kind: kind, |
450 |
conclLit: arLit, |
|
451 |
premLits: arLit list}; |
|
452 |
||
453 |
||
18798 | 454 |
fun gen_TVars 0 = [] |
455 |
| gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1); |
|
15347 | 456 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
457 |
fun pack_sort(_,[]) = [] |
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
458 |
| 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
|
459 |
| pack_sort(tvar, cls::srt) = (cls, tvar) :: pack_sort(tvar, srt); |
15347 | 460 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
461 |
(*Arity of type constructor tcon :: (arg1,...,argN)res*) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
462 |
fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) = |
21560 | 463 |
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
|
464 |
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
|
465 |
in |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
466 |
ArityClause {axiom_name = axiom_name, kind = Axiom, |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
467 |
conclLit = TConsLit (cls, make_fixed_type_const tcons, tvars), |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
468 |
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
|
469 |
end; |
15347 | 470 |
|
471 |
||
472 |
(**** Isabelle class relations ****) |
|
473 |
||
474 |
datatype classrelClause = |
|
18868 | 475 |
ClassrelClause of {axiom_name: axiom_name, |
15347 | 476 |
subclass: class, |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
477 |
superclass: class}; |
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
478 |
|
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
479 |
(*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
|
480 |
fun class_pairs thy [] supers = [] |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
481 |
| class_pairs thy subs supers = |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
482 |
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
|
483 |
fun add_super sub (super,pairs) = |
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
484 |
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
|
485 |
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
|
486 |
in foldl add_supers [] subs end; |
15347 | 487 |
|
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
488 |
fun make_classrelClause (sub,super) = |
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
489 |
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
|
490 |
subclass = make_type_class sub, |
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
491 |
superclass = make_type_class super}; |
15347 | 492 |
|
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
493 |
fun make_classrel_clauses thy subs supers = |
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
494 |
map make_classrelClause (class_pairs thy subs supers); |
18868 | 495 |
|
496 |
||
497 |
(** Isabelle arities **) |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
498 |
|
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
499 |
fun arity_clause _ _ (tcons, []) = [] |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
500 |
| 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
|
501 |
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
|
502 |
| 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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
else |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
507 |
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
|
508 |
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
|
509 |
|
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
510 |
fun multi_arity_clause [] = [] |
19155 | 511 |
| multi_arity_clause ((tcons,ars) :: tc_arlists) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
512 |
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
|
513 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
514 |
(*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
|
515 |
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
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
(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
|
521 |
handle Sorts.CLASS_ERROR _ => pairs |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
525 |
(*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
|
526 |
fun iter_type_class_pairs thy tycons [] = ([], []) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
527 |
| iter_type_class_pairs thy tycons classes = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
528 |
let val cpairs = type_class_pairs thy tycons classes |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
529 |
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
|
530 |
val _ = if null newclasses then () |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
531 |
else Output.debug (fn _ => "New classes: " ^ space_implode ", " newclasses) |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
532 |
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
|
533 |
in (classes' union classes, cpairs' union cpairs) end; |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
534 |
|
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
535 |
fun make_arity_clauses thy tycons classes = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
536 |
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
|
537 |
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
|
538 |
|
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
539 |
|
18868 | 540 |
(**** Find occurrences of predicates in clauses ****) |
541 |
||
542 |
(*FIXME: multiple-arity checking doesn't work, as update_new is the wrong |
|
543 |
function (it flags repeated declarations of a function, even with the same arity)*) |
|
544 |
||
545 |
fun update_many (tab, keypairs) = foldl (uncurry Symtab.update) tab keypairs; |
|
546 |
||
547 |
fun add_predicate_preds (Predicate(pname,tys,tms), preds) = |
|
548 |
if pname = "equal" then preds (*equality is built-in and requires no declaration*) |
|
549 |
else Symtab.update (pname, length tys + length tms) preds |
|
550 |
||
20018 | 551 |
fun add_literal_preds (Literal(_,pred), preds) = add_predicate_preds (pred,preds) |
18868 | 552 |
|
553 |
fun add_type_sort_preds ((FOLTVar indx,s), preds) = |
|
554 |
update_many (preds, map pred_of_sort (sorts_on_typs (FOLTVar indx, s))) |
|
555 |
| add_type_sort_preds ((FOLTFree x,s), preds) = |
|
556 |
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
|
557 |
|
18868 | 558 |
fun add_clause_preds (Clause {literals, types_sorts, ...}, preds) = |
559 |
foldl add_literal_preds (foldl add_type_sort_preds preds types_sorts) literals |
|
560 |
handle Symtab.DUP a => raise ERROR ("predicate " ^ a ^ " has multiple arities") |
|
561 |
||
562 |
fun add_classrelClause_preds (ClassrelClause {subclass,superclass,...}, preds) = |
|
563 |
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
|
564 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
565 |
fun class_of_arityLit (TConsLit (tclass, _, _)) = tclass |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
566 |
| 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
|
567 |
|
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
568 |
fun add_arityClause_preds (ArityClause {conclLit,premLits,...}, preds) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
569 |
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
|
570 |
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
|
571 |
in foldl upd preds classes end; |
18868 | 572 |
|
573 |
fun preds_of_clauses clauses clsrel_clauses arity_clauses = |
|
574 |
Symtab.dest |
|
575 |
(foldl add_classrelClause_preds |
|
576 |
(foldl add_arityClause_preds |
|
577 |
(foldl add_clause_preds Symtab.empty clauses) |
|
578 |
arity_clauses) |
|
579 |
clsrel_clauses) |
|
18798 | 580 |
|
18868 | 581 |
(*** Find occurrences of functions in clauses ***) |
582 |
||
583 |
fun add_foltype_funcs (AtomV _, funcs) = funcs |
|
584 |
| add_foltype_funcs (AtomF a, funcs) = Symtab.update (a,0) funcs |
|
585 |
| add_foltype_funcs (Comp(a,tys), funcs) = |
|
586 |
foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys; |
|
587 |
||
21813 | 588 |
fun add_folterm_funcs (UVar _, funcs) = funcs |
18868 | 589 |
| add_folterm_funcs (Fun(a,tys,tms), funcs) = |
590 |
foldl add_foltype_funcs |
|
591 |
(foldl add_folterm_funcs (Symtab.update (a, length tys + length tms) funcs) |
|
592 |
tms) |
|
593 |
tys |
|
18798 | 594 |
|
18868 | 595 |
fun add_predicate_funcs (Predicate(_,tys,tms), funcs) = |
596 |
foldl add_foltype_funcs (foldl add_folterm_funcs funcs tms) tys; |
|
597 |
||
20018 | 598 |
fun add_literal_funcs (Literal(_,pred), funcs) = add_predicate_funcs (pred,funcs) |
18868 | 599 |
|
20038 | 600 |
(*TFrees are recorded as constants*) |
601 |
fun add_type_sort_funcs ((FOLTVar _, _), funcs) = funcs |
|
602 |
| add_type_sort_funcs ((FOLTFree a, _), funcs) = |
|
603 |
Symtab.update (make_fixed_type_var a, 0) funcs |
|
604 |
||
18868 | 605 |
fun add_arityClause_funcs (ArityClause {conclLit,...}, funcs) = |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
606 |
let val TConsLit (_, tcons, tvars) = conclLit |
18868 | 607 |
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
|
608 |
|
20038 | 609 |
fun add_clause_funcs (Clause {literals, types_sorts, ...}, funcs) = |
610 |
foldl add_literal_funcs (foldl add_type_sort_funcs funcs types_sorts) |
|
611 |
literals |
|
18868 | 612 |
handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities") |
613 |
||
614 |
fun funcs_of_clauses clauses arity_clauses = |
|
615 |
Symtab.dest (foldl add_arityClause_funcs |
|
616 |
(foldl add_clause_funcs Symtab.empty clauses) |
|
617 |
arity_clauses) |
|
618 |
||
619 |
||
620 |
(**** String-oriented operations ****) |
|
15347 | 621 |
|
21813 | 622 |
fun string_of_term (UVar x) = x |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
623 |
| string_of_term (Fun (name,typs,terms)) = |
21790
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
624 |
name ^ (paren_pack (map string_of_term terms @ map string_of_fol_type typs)); |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
625 |
|
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
626 |
fun string_of_pair [t1,t2] = (string_of_term t1, string_of_term t2) |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
627 |
| string_of_pair _ = raise ERROR ("equality predicate requires two arguments"); |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
628 |
|
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
629 |
fun string_of_equality ts = |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
630 |
let val (s1,s2) = string_of_pair ts |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
631 |
in "equal(" ^ s1 ^ "," ^ s2 ^ ")" end; |
15347 | 632 |
|
633 |
(* before output the string of the predicate, check if the predicate corresponds to an equality or not. *) |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
634 |
fun string_of_predicate (Predicate("equal",_,ts)) = string_of_equality ts |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
635 |
| string_of_predicate (Predicate(name,typs,ts)) = |
21790
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
636 |
name ^ (paren_pack (map string_of_term ts @ map string_of_fol_type typs)); |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
637 |
|
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
638 |
fun string_of_clausename (cls_id,ax_name) = |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
639 |
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
|
640 |
|
21564 | 641 |
fun clause_name_of (cls_id,ax_name) = |
642 |
ascii_of ax_name ^ "_" ^ Int.toString cls_id; |
|
643 |
||
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset
|
644 |
fun string_of_type_clsname (cls_id,ax_name,idx) = |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
645 |
string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx); |
18863 | 646 |
|
647 |
(*Write a list of strings to a file*) |
|
648 |
fun writeln_strs os = List.app (fn s => TextIO.output (os,s)); |
|
649 |
||
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
650 |
|
18868 | 651 |
(**** Producing DFG files ****) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
652 |
|
18863 | 653 |
(*Attach sign in DFG syntax: false means negate.*) |
654 |
fun dfg_sign true s = s |
|
655 |
| dfg_sign false s = "not(" ^ s ^ ")" |
|
656 |
||
20018 | 657 |
fun dfg_literal (Literal(pol,pred)) = dfg_sign pol (string_of_predicate pred) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
658 |
|
18798 | 659 |
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
|
660 |
| 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
|
661 |
|
18868 | 662 |
(*Enclose the clause body by quantifiers, if necessary*) |
663 |
fun dfg_forall [] body = body |
|
664 |
| 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
|
665 |
|
18868 | 666 |
fun gen_dfg_cls (cls_id, ax_name, knd, lits, vars) = |
667 |
"clause( %(" ^ knd ^ ")\n" ^ |
|
668 |
dfg_forall vars ("or(" ^ lits ^ ")") ^ ",\n" ^ |
|
18863 | 669 |
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
|
670 |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
671 |
fun dfg_clause_aux (Clause{literals, types_sorts, ...}) = |
21790
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
672 |
let val (tvar_lits,tfree_lits) = add_typs_aux types_sorts |
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
673 |
in (map dfg_of_typeLit tvar_lits @ map dfg_literal literals, |
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
674 |
map dfg_of_typeLit tfree_lits) |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
675 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
676 |
|
20018 | 677 |
fun dfg_folterms (Literal(pol,pred)) = |
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
678 |
let val Predicate (_, _, folterms) = pred |
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset
|
679 |
in folterms end |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
680 |
|
21813 | 681 |
fun get_uvars (UVar a) = [a] |
18868 | 682 |
| get_uvars (Fun (_,typ,tlist)) = union_all(map get_uvars tlist) |
17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset
|
683 |
|
18868 | 684 |
fun dfg_vars (Clause {literals,...}) = |
18920 | 685 |
union_all (map get_uvars (List.concat (map dfg_folterms literals))) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
686 |
|
18798 | 687 |
fun clause2dfg (cls as Clause{axiom_name,clause_id,kind,types_sorts,...}) = |
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
688 |
let val (lits,tfree_lits) = dfg_clause_aux cls |
18798 | 689 |
(*"lits" includes the typing assumptions (TVars)*) |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
690 |
val vars = dfg_vars cls |
18798 | 691 |
val tvars = get_tvar_strs types_sorts |
20038 | 692 |
val cls_str = gen_dfg_cls(clause_id, axiom_name, name_of_kind kind, |
693 |
commas lits, tvars@vars) |
|
18798 | 694 |
in (cls_str, tfree_lits) end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
695 |
|
18798 | 696 |
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
|
697 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
698 |
fun string_of_preds [] = "" |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
699 |
| 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
|
700 |
|
18856
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
701 |
fun string_of_funcs [] = "" |
4669dec681f4
tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset
|
702 |
| 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
|
703 |
|
17234 | 704 |
fun string_of_symbols predstr funcstr = |
705 |
"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
|
706 |
|
18798 | 707 |
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
|
708 |
|
18863 | 709 |
fun string_of_descrip name = |
18868 | 710 |
"list_of_descriptions.\nname({*" ^ name ^ |
711 |
"*}).\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
|
712 |
|
18863 | 713 |
fun dfg_tfree_clause tfree_lit = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
714 |
"clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n" |
18863 | 715 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
716 |
fun dfg_of_arLit (TConsLit (c,t,args)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
717 |
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
|
718 |
| dfg_of_arLit (TVarLit (c,str)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
719 |
dfg_sign false (make_type_class c ^ "(" ^ str ^ ")") |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
720 |
|
20038 | 721 |
fun dfg_classrelLits sub sup = "not(" ^ sub ^ "(T)), " ^ sup ^ "(T)"; |
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
722 |
|
18868 | 723 |
fun dfg_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) = |
724 |
"clause(forall([T],\nor( " ^ dfg_classrelLits subclass superclass ^ ")),\n" ^ |
|
725 |
axiom_name ^ ").\n\n"; |
|
726 |
||
21560 | 727 |
fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name; |
728 |
||
729 |
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
|
730 |
let val TConsLit (_,_,tvars) = conclLit |
18868 | 731 |
val lits = map dfg_of_arLit (conclLit :: premLits) |
18863 | 732 |
in |
21560 | 733 |
"clause( %(" ^ name_of_kind kind ^ ")\n" ^ |
18868 | 734 |
dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^ |
21560 | 735 |
string_of_ar axiom_name ^ ").\n\n" |
18863 | 736 |
end; |
737 |
||
738 |
(* write out a subgoal in DFG format to the file "xxxx_N"*) |
|
20038 | 739 |
fun dfg_write_file thms filename (ax_tuples,classrel_clauses,arity_clauses) = |
18863 | 740 |
let |
22130 | 741 |
val _ = Output.debug (fn () => ("Preparing to write the DFG file " ^ filename)) |
19719 | 742 |
val conjectures = make_conjecture_clauses thms |
20038 | 743 |
val (clnames,axclauses) = ListPair.unzip (make_axiom_clauses ax_tuples) |
18868 | 744 |
val (dfg_clss, tfree_litss) = ListPair.unzip (map clause2dfg conjectures) |
20038 | 745 |
val clss = conjectures @ axclauses |
18868 | 746 |
val funcs = funcs_of_clauses clss arity_clauses |
747 |
and preds = preds_of_clauses clss classrel_clauses arity_clauses |
|
21858
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents:
21813
diff
changeset
|
748 |
and probname = Path.implode (Path.base (Path.explode filename)) |
20038 | 749 |
val (axstrs, _) = ListPair.unzip (map clause2dfg axclauses) |
18863 | 750 |
val tfree_clss = map dfg_tfree_clause (union_all tfree_litss) |
19155 | 751 |
val out = TextIO.openOut filename |
18863 | 752 |
in |
18868 | 753 |
TextIO.output (out, string_of_start probname); |
754 |
TextIO.output (out, string_of_descrip probname); |
|
755 |
TextIO.output (out, string_of_symbols (string_of_funcs funcs) (string_of_preds preds)); |
|
756 |
TextIO.output (out, "list_of_clauses(axioms,cnf).\n"); |
|
757 |
writeln_strs out axstrs; |
|
758 |
List.app (curry TextIO.output out o dfg_classrelClause) classrel_clauses; |
|
759 |
List.app (curry TextIO.output out o dfg_arity_clause) arity_clauses; |
|
760 |
TextIO.output (out, "end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n"); |
|
761 |
writeln_strs out tfree_clss; |
|
762 |
writeln_strs out dfg_clss; |
|
763 |
TextIO.output (out, "end_of_list.\n\nend_problem.\n"); |
|
20022 | 764 |
TextIO.closeOut out; |
765 |
clnames |
|
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset
|
766 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
767 |
|
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
768 |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
769 |
(**** Produce TPTP files ****) |
18868 | 770 |
|
771 |
(*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
|
772 |
fun tptp_sign true s = s |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
773 |
| tptp_sign false s = "~ " ^ s |
18868 | 774 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
775 |
fun tptp_of_equality pol ts = |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
776 |
let val (s1,s2) = string_of_pair ts |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
777 |
val eqop = if pol then " = " else " != " |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
778 |
in s1 ^ eqop ^ s2 end; |
15347 | 779 |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
780 |
fun tptp_literal (Literal(pol,Predicate("equal",_,ts))) = tptp_of_equality pol ts |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
781 |
| tptp_literal (Literal(pol,pred)) = tptp_sign pol (string_of_predicate pred); |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
782 |
|
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
783 |
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
|
784 |
| tptp_of_typeLit (LTFree (s,ty)) = tptp_sign true (s ^ "(" ^ ty ^ ")"); |
15347 | 785 |
|
786 |
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
|
787 |
"cnf(" ^ string_of_clausename (cls_id,ax_name) ^ "," ^ |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
788 |
name_of_kind knd ^ "," ^ tptp_pack lits ^ ").\n"; |
15347 | 789 |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
790 |
fun tptp_type_lits (Clause {literals, types_sorts, ...}) = |
21790
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
791 |
let val (tvar_lits,tfree_lits) = add_typs_aux types_sorts |
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
792 |
in |
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
793 |
(map tptp_of_typeLit tvar_lits @ map tptp_literal literals, |
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
794 |
map tptp_of_typeLit tfree_lits) |
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset
|
795 |
end; |
15347 | 796 |
|
18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset
|
797 |
fun clause2tptp (cls as Clause {clause_id, axiom_name, kind, ...}) = |
17422 | 798 |
let val (lits,tfree_lits) = tptp_type_lits cls |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17261
diff
changeset
|
799 |
(*"lits" includes the typing assumptions (TVars)*) |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
800 |
val cls_str = gen_tptp_cls(clause_id, axiom_name, kind, lits) |
15608 | 801 |
in |
802 |
(cls_str,tfree_lits) |
|
803 |
end; |
|
804 |
||
18863 | 805 |
fun tptp_tfree_clause tfree_lit = |
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
806 |
"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
|
807 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
808 |
fun tptp_of_arLit (TConsLit (c,t,args)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
809 |
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
|
810 |
| tptp_of_arLit (TVarLit (c,str)) = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
811 |
tptp_sign false (make_type_class c ^ "(" ^ str ^ ")") |
15347 | 812 |
|
21560 | 813 |
fun tptp_arity_clause (ArityClause{axiom_name,kind,conclLit,premLits,...}) = |
814 |
"cnf(" ^ string_of_ar axiom_name ^ "," ^ name_of_kind kind ^ "," ^ |
|
815 |
tptp_pack (map tptp_of_arLit (conclLit :: premLits)) ^ ").\n"; |
|
15347 | 816 |
|
817 |
fun tptp_classrelLits sub sup = |
|
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
818 |
let val tvar = "(T)" |
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset
|
819 |
in tptp_pack [tptp_sign false (sub^tvar), tptp_sign true (sup^tvar)] end; |
15347 | 820 |
|
18868 | 821 |
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
|
822 |
"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
|
823 |
|
18863 | 824 |
(* write out a subgoal as tptp clauses to the file "xxxx_N"*) |
20038 | 825 |
fun tptp_write_file thms filename (ax_tuples,classrel_clauses,arity_clauses) = |
18863 | 826 |
let |
22130 | 827 |
val _ = Output.debug (fn () => ("Preparing to write the TPTP file " ^ filename)) |
19443
e32a4703d834
Take conjectures and axioms as thms when convert them to ResClause.clause format.
mengj
parents:
19354
diff
changeset
|
828 |
val clss = make_conjecture_clauses thms |
20038 | 829 |
val (clnames,axclauses) = ListPair.unzip (make_axiom_clauses ax_tuples) |
18863 | 830 |
val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp clss) |
831 |
val tfree_clss = map tptp_tfree_clause (foldl (op union_string) [] tfree_litss) |
|
832 |
val out = TextIO.openOut filename |
|
833 |
in |
|
20038 | 834 |
List.app (curry TextIO.output out o #1 o clause2tptp) axclauses; |
18863 | 835 |
writeln_strs out tfree_clss; |
836 |
writeln_strs out tptp_clss; |
|
18868 | 837 |
List.app (curry TextIO.output out o tptp_classrelClause) classrel_clauses; |
838 |
List.app (curry TextIO.output out o tptp_arity_clause) arity_clauses; |
|
20022 | 839 |
TextIO.closeOut out; |
840 |
clnames |
|
18863 | 841 |
end; |
842 |
||
15347 | 843 |
end; |