author  paulson 
Wed, 10 Oct 2007 10:50:11 +0200  
changeset 24940  8f9dea697b8d 
parent 24937  340523598914 
child 25243  78f8aaa27493 
permissions  rwrr 
15347  1 
(* Author: Jia Meng, Cambridge University Computer Laboratory 
2 
ID: $Id$ 

3 
Copyright 2004 University of Cambridge 

4 

24310  5 
Storing/printing FOL clauses and arity clauses. 
15347  6 
Typed equality is treated differently. 
7 
*) 

8 

23385  9 
(*FIXME: combine with res_hol_clause!*) 
15347  10 
signature RES_CLAUSE = 
24310  11 
sig 
12 
val schematic_var_prefix: string 

13 
val fixed_var_prefix: string 

14 
val tvar_prefix: string 

15 
val tfree_prefix: string 

16 
val clause_prefix: string 

17 
val const_prefix: string 

18 
val tconst_prefix: string 

19 
val class_prefix: string 

20 
val union_all: ''a list list > ''a list 

21 
val const_trans_table: string Symtab.table 

22 
val type_const_trans_table: string Symtab.table 

23 
val ascii_of: string > string 

24 
val undo_ascii_of: string > string 

25 
val paren_pack : string list > string 

26 
val make_schematic_var : string * int > string 

18868  27 
val make_fixed_var : string > string 
28 
val make_schematic_type_var : string * int > string 

24310  29 
val make_fixed_type_var : string > string 
30 
val dfg_format: bool ref 

31 
val make_fixed_const : string > string 

32 
val make_fixed_type_const : string > string 

18868  33 
val make_type_class : string > string 
24310  34 
datatype kind = Axiom  Conjecture 
35 
type axiom_name = string 

36 
datatype fol_type = 

37 
AtomV of string 

38 
 AtomF of string 

39 
 Comp of string * fol_type list 

18868  40 
val string_of_fol_type : fol_type > string 
24310  41 
datatype type_literal = LTVar of string * string  LTFree of string * string 
42 
exception CLAUSE of string * term 

43 
val isMeta : string > bool 

24940  44 
val add_typs : typ list > type_literal list 
45 
val get_tvar_strs: typ list > string list 

24310  46 
datatype arLit = 
47 
TConsLit of class * string * string list 

48 
 TVarLit of class * string 

49 
datatype arityClause = ArityClause of 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

50 
{axiom_name: axiom_name, conclLit: arLit, premLits: arLit list} 
24310  51 
datatype classrelClause = ClassrelClause of 
24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

52 
{axiom_name: axiom_name, subclass: class, superclass: class} 
24310  53 
val make_classrel_clauses: theory > class list > class list > classrelClause list 
54 
val make_arity_clauses: theory > string list > class list > class list * arityClause list 

24940  55 
val add_type_sort_preds: typ * int Symtab.table > int Symtab.table 
24310  56 
val add_classrelClause_preds : classrelClause * int Symtab.table > int Symtab.table 
57 
val class_of_arityLit: arLit > class 

58 
val add_arityClause_preds: arityClause * int Symtab.table > int Symtab.table 

59 
val add_foltype_funcs: fol_type * int Symtab.table > int Symtab.table 

60 
val add_arityClause_funcs: arityClause * int Symtab.table > int Symtab.table 

61 
val init_functab: int Symtab.table 

62 
val writeln_strs: TextIO.outstream > string list > unit 

19719  63 
val dfg_sign: bool > string > string 
24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

64 
val dfg_of_typeLit: bool > type_literal > string 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

65 
val gen_dfg_cls: int * string * kind * string list * string list * string list > string 
24310  66 
val string_of_preds: (string * Int.int) list > string 
67 
val string_of_funcs: (string * int) list > string 

68 
val string_of_symbols: string > string > string 

19719  69 
val string_of_start: string > string 
70 
val string_of_descrip : string > string 

24310  71 
val dfg_tfree_clause : string > string 
19719  72 
val dfg_classrelClause: classrelClause > string 
73 
val dfg_arity_clause: arityClause > string 

24310  74 
val tptp_sign: bool > string > string 
24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

75 
val tptp_of_typeLit : bool > type_literal > string 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

76 
val gen_tptp_cls : int * string * kind * string list * string list > string 
24310  77 
val tptp_tfree_clause : string > string 
78 
val tptp_arity_clause : arityClause > string 

79 
val tptp_classrelClause : classrelClause > string 

80 
end 

15347  81 

24310  82 
structure ResClause: RES_CLAUSE = 
15347  83 
struct 
84 

85 
val schematic_var_prefix = "V_"; 

86 
val fixed_var_prefix = "v_"; 

87 

17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

88 
val tvar_prefix = "T_"; 
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

89 
val tfree_prefix = "t_"; 
15347  90 

24310  91 
val clause_prefix = "cls_"; 
92 
val arclause_prefix = "clsarity_" 

17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

93 
val clrelclause_prefix = "clsrel_"; 
15347  94 

17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

95 
val const_prefix = "c_"; 
24310  96 
val tconst_prefix = "tc_"; 
97 
val class_prefix = "class_"; 

15347  98 

17775  99 
fun union_all xss = foldl (op union) [] xss; 
100 

101 
(*Provide readable names for the more common symbolic functions*) 

15347  102 
val const_trans_table = 
103 
Symtab.make [("op =", "equal"), 

24310  104 
(@{const_name HOL.less_eq}, "lessequals"), 
105 
(@{const_name HOL.less}, "less"), 

106 
("op &", "and"), 

107 
("op ", "or"), 

108 
(@{const_name HOL.plus}, "plus"), 

109 
(@{const_name HOL.minus}, "minus"), 

110 
(@{const_name HOL.times}, "times"), 

111 
(@{const_name Divides.div}, "div"), 

112 
(@{const_name HOL.divide}, "divide"), 

113 
("op >", "implies"), 

114 
("{}", "emptyset"), 

115 
("op :", "in"), 

116 
("op Un", "union"), 

117 
("op Int", "inter"), 

118 
("List.append", "append"), 

119 
("ATP_Linkup.fequal", "fequal"), 

120 
("ATP_Linkup.COMBI", "COMBI"), 

121 
("ATP_Linkup.COMBK", "COMBK"), 

122 
("ATP_Linkup.COMBB", "COMBB"), 

123 
("ATP_Linkup.COMBC", "COMBC"), 

124 
("ATP_Linkup.COMBS", "COMBS"), 

125 
("ATP_Linkup.COMBB'", "COMBB_e"), 

126 
("ATP_Linkup.COMBC'", "COMBC_e"), 

127 
("ATP_Linkup.COMBS'", "COMBS_e")]; 

15347  128 

17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

129 
val type_const_trans_table = 
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

130 
Symtab.make [("*", "prod"), 
24310  131 
("+", "sum"), 
132 
("~=>", "map")]; 

15347  133 

15610  134 
(*Escaping of special characters. 
135 
Alphanumeric characters are left unchanged. 

136 
The character _ goes to __ 

137 
Characters in the range ASCII space to / go to _A to _P, respectively. 

24183  138 
Other printing characters go to _nnn where nnn is the decimal ASCII code.*) 
139 
val A_minus_space = Char.ord #"A"  Char.ord #" "; 

15610  140 

24183  141 
fun stringN_of_int 0 _ = "" 
142 
 stringN_of_int k n = stringN_of_int (k1) (n div 10) ^ Int.toString (n mod 10); 

15610  143 

15347  144 
fun ascii_of_c c = 
15610  145 
if Char.isAlphaNum c then String.str c 
146 
else if c = #"_" then "__" 

24310  147 
else if #" " <= c andalso c <= #"/" 
15610  148 
then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) 
24310  149 
else if Char.isPrint c 
24183  150 
then ("_" ^ stringN_of_int 3 (Char.ord c)) (*fixed width, in case more digits follow*) 
15610  151 
else "" 
15347  152 

15610  153 
val ascii_of = String.translate ascii_of_c; 
154 

24183  155 
(** Remove ASCII armouring from names in proof files **) 
156 

157 
(*We don't raise error exceptions because this code can run inside the watcher. 

158 
Also, the errors are "impossible" (hah!)*) 

159 
fun undo_ascii_aux rcs [] = String.implode(rev rcs) 

160 
 undo_ascii_aux rcs [#"_"] = undo_ascii_aux (#"_"::rcs) [] (*ERROR*) 

161 
(*Three types of _ escapes: __, _A to _P, _nnn*) 

162 
 undo_ascii_aux rcs (#"_" :: #"_" :: cs) = undo_ascii_aux (#"_"::rcs) cs 

24310  163 
 undo_ascii_aux rcs (#"_" :: c :: cs) = 
24183  164 
if #"A" <= c andalso c<= #"P" (*translation of #" " to #"/"*) 
165 
then undo_ascii_aux (Char.chr(Char.ord c  A_minus_space) :: rcs) cs 

24310  166 
else 
24183  167 
let val digits = List.take (c::cs, 3) handle Subscript => [] 
24310  168 
in 
24183  169 
case Int.fromString (String.implode digits) of 
170 
NONE => undo_ascii_aux (c:: #"_"::rcs) cs (*ERROR*) 

171 
 SOME n => undo_ascii_aux (Char.chr n :: rcs) (List.drop (cs, 2)) 

172 
end 

173 
 undo_ascii_aux rcs (c::cs) = undo_ascii_aux (c::rcs) cs; 

174 

175 
val undo_ascii_of = undo_ascii_aux [] o String.explode; 

15347  176 

17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

177 
(* 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

178 
fun paren_pack [] = "" (*empty argument list*) 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset

179 
 paren_pack strings = "(" ^ commas strings ^ ")"; 
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

180 

21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

181 
(*TSTP format uses (...) rather than the old [...]*) 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

182 
fun tptp_pack strings = "(" ^ space_implode "  " strings ^ ")"; 
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

183 

ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

184 

16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset

185 
(*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

186 
fun trim_type_var s = 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset

187 
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

188 
else error ("trim_type: Malformed type variable encountered: " ^ s); 
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset

189 

16903  190 
fun ascii_of_indexname (v,0) = ascii_of v 
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

191 
 ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i; 
15347  192 

17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

193 
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v); 
15347  194 
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x); 
195 

24310  196 
fun make_schematic_type_var (x,i) = 
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset

197 
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

198 
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); 
15347  199 

23075  200 
(*HACK because SPASS truncates identifiers to 63 characters :(( *) 
201 
val dfg_format = ref false; 

202 

203 
(*32bit hash,so we expect no collisions unless there are around 65536 long identifiers...*) 

204 
fun controlled_length s = 

24310  205 
if size s > 60 andalso !dfg_format 
23075  206 
then Word.toString (Polyhash.hashw_string(s,0w0)) 
207 
else s; 

208 

18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

209 
fun lookup_const c = 
17412  210 
case Symtab.lookup const_trans_table c of 
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

211 
SOME c' => c' 
23075  212 
 NONE => controlled_length (ascii_of c); 
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

213 

24310  214 
fun lookup_type_const c = 
17412  215 
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

216 
SOME c' => c' 
23075  217 
 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

218 

2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

219 
fun make_fixed_const "op =" = "equal" (*MUST BE "equal" because it's builtin to ATPs*) 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

220 
 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

221 

2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

222 
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

223 

17261  224 
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

225 

ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

226 

18798  227 
(***** definitions and functions for FOL clauses, for conversion to TPTP or DFG format. *****) 
15347  228 

21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

229 
datatype kind = Axiom  Conjecture; 
23385  230 

15347  231 
type axiom_name = string; 
232 

233 
(**** Isabelle FOL clauses ****) 

234 

18798  235 
(*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

236 
datatype fol_type = AtomV of string 
24310  237 
 AtomF of string 
238 
 Comp of string * fol_type list; 

18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset

239 

aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset

240 
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

241 
 string_of_fol_type (AtomF x) = x 
24310  242 
 string_of_fol_type (Comp(tcon,tps)) = 
18856
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

243 
tcon ^ (paren_pack (map string_of_fol_type tps)); 
24310  244 

18798  245 
(*First string is the type class; the second is a TVar or TFfree*) 
246 
datatype type_literal = LTVar of string * string  LTFree of string * string; 

15347  247 

17404
d16c3a62c396
the experimental tagging system, and the usual tidying
paulson
parents:
17375
diff
changeset

248 
exception CLAUSE of string * term; 
15347  249 

24940  250 
fun atomic_type (TFree (a,_)) = AtomF(make_fixed_type_var a) 
251 
 atomic_type (TVar (v,_)) = AtomV(make_schematic_type_var v); 

17317
3f12de2e2e6e
IsabelleATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset

252 

18402
aaba095cf62b
1. changed fol_type, it's not a string type anymore.
mengj
parents:
18390
diff
changeset

253 
(*Flatten a type to a fol_type while accumulating sort constraints on the TFrees and 
24310  254 
TVars it contains.*) 
255 
fun type_of (Type (a, Ts)) = 

256 
let val (folTyps, ts) = types_of Ts 

257 
val t = make_fixed_type_const a 

18798  258 
in (Comp(t,folTyps), ts) end 
24940  259 
 type_of T = (atomic_type T, [T]) 
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset

260 
and types_of Ts = 
18798  261 
let val (folTyps,ts) = ListPair.unzip (map type_of Ts) 
262 
in (folTyps, union_all ts) end; 

15390  263 

18439
4b517881ac7e
Added functions for fol_type; also put some functions to the signature, used by ResHolClause.
mengj
parents:
18420
diff
changeset

264 

16903  265 
(* Any variables created via the METAHYPS tactical should be treated as 
266 
universal vars, although it is represented as "Free(...)" by Isabelle *) 

267 
val isMeta = String.isPrefix "METAHYP1_" 

17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

268 

24310  269 
(*Make literals for sorted type variables*) 
24940  270 
fun sorts_on_typs_aux (_, []) = [] 
271 
 sorts_on_typs_aux ((x,i), s::ss) = 

272 
let val sorts = sorts_on_typs_aux ((x,i), ss) 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

273 
in 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

274 
if s = "HOL.type" then sorts 
24940  275 
else if i = ~1 then LTFree(make_type_class s, make_fixed_type_var x) :: sorts 
276 
else LTVar(make_type_class s, make_schematic_type_var (x,i)) :: sorts 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

277 
end; 
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

278 

24940  279 
fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s) 
280 
 sorts_on_typs (TVar (v,s)) = sorts_on_typs_aux (v,s); 

281 

18798  282 
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

283 
 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

284 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

285 
(*Given a list of sorted type variables, return a list of type literals.*) 
24940  286 
fun add_typs Ts = foldl (op union) [] (map sorts_on_typs Ts); 
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset

287 

1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset

288 
(** make axiom and conjecture clauses. **) 
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset

289 

1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset

290 
fun get_tvar_strs [] = [] 
24940  291 
 get_tvar_strs ((TVar (indx,s))::Ts) = 
292 
insert (op =) (make_schematic_type_var indx) (get_tvar_strs Ts) 

293 
 get_tvar_strs((TFree _)::Ts) = get_tvar_strs Ts 

20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset

294 

24310  295 

19354  296 

15347  297 
(**** Isabelle arities ****) 
298 

299 
exception ARCLAUSE of string; 

300 

24310  301 
datatype arLit = TConsLit of class * string * string list 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

302 
 TVarLit of class * string; 
24310  303 

304 
datatype arityClause = 

305 
ArityClause of {axiom_name: axiom_name, 

306 
conclLit: arLit, 

307 
premLits: arLit list}; 

15347  308 

309 

18798  310 
fun gen_TVars 0 = [] 
311 
 gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n1); 

15347  312 

18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

313 
fun pack_sort(_,[]) = [] 
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

314 
 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

315 
 pack_sort(tvar, cls::srt) = (cls, tvar) :: pack_sort(tvar, srt); 
24310  316 

18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset

317 
(*Arity of type constructor tcon :: (arg1,...,argN)res*) 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

318 
fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) = 
21560  319 
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

320 
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

321 
in 
24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

322 
ArityClause {axiom_name = axiom_name, 
24310  323 
conclLit = TConsLit (cls, make_fixed_type_const tcons, tvars), 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

324 
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

325 
end; 
15347  326 

327 

328 
(**** Isabelle class relations ****) 

329 

24310  330 
datatype classrelClause = 
331 
ClassrelClause of {axiom_name: axiom_name, 

332 
subclass: class, 

333 
superclass: class}; 

334 

21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset

335 
(*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

336 
fun class_pairs thy [] supers = [] 
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset

337 
 class_pairs thy subs supers = 
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset

338 
let val class_less = Sorts.class_less(Sign.classes_of thy) 
24310  339 
fun add_super sub (super,pairs) = 
340 
if class_less (sub,super) then (sub,super)::pairs else pairs 

341 
fun add_supers (sub,pairs) = foldl (add_super sub) pairs supers 

21432
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset

342 
in foldl add_supers [] subs end; 
15347  343 

21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset

344 
fun make_classrelClause (sub,super) = 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset

345 
ClassrelClause {axiom_name = clrelclause_prefix ^ ascii_of sub ^ "_" ^ ascii_of super, 
24310  346 
subclass = make_type_class sub, 
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset

347 
superclass = make_type_class super}; 
15347  348 

21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset

349 
fun make_classrel_clauses thy subs supers = 
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset

350 
map make_classrelClause (class_pairs thy subs supers); 
18868  351 

352 

353 
(** Isabelle arities **) 

17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset

354 

21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset

355 
fun arity_clause _ _ (tcons, []) = [] 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset

356 
 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

357 
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

358 
 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

359 
if class mem_string seen then (*multiple arities for the same tycon, class pair*) 
24310  360 
make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) :: 
361 
arity_clause seen (n+1) (tcons,ars) 

21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset

362 
else 
24310  363 
make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class, ar) :: 
364 
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

365 

1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset

366 
fun multi_arity_clause [] = [] 
19155  367 
 multi_arity_clause ((tcons,ars) :: tc_arlists) = 
24310  368 
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

369 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

370 
(*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

371 
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

372 
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

373 
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

374 
fun domain_sorts (tycon,class) = Sorts.mg_domain alg tycon [class] 
24310  375 
fun add_class tycon (class,pairs) = 
376 
(class, domain_sorts(tycon,class))::pairs 

21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset

377 
handle Sorts.CLASS_ERROR _ => pairs 
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset

378 
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

379 
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

380 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

381 
(*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

382 
fun iter_type_class_pairs thy tycons [] = ([], []) 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

383 
 iter_type_class_pairs thy tycons classes = 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

384 
let val cpairs = type_class_pairs thy tycons classes 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

385 
val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs))) \\ classes \\ HOLogic.typeS 
24310  386 
val _ = if null newclasses then () 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

387 
else Output.debug (fn _ => "New classes: " ^ space_implode ", " newclasses) 
24310  388 
val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

389 
in (classes' union classes, cpairs' union cpairs) end; 
24310  390 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

391 
fun make_arity_clauses thy tycons classes = 
24310  392 
let val (classes', cpairs) = iter_type_class_pairs thy tycons classes 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

393 
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

394 

1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset

395 

18868  396 
(**** Find occurrences of predicates in clauses ****) 
397 

24310  398 
(*FIXME: multiplearity checking doesn't work, as update_new is the wrong 
18868  399 
function (it flags repeated declarations of a function, even with the same arity)*) 
400 

401 
fun update_many (tab, keypairs) = foldl (uncurry Symtab.update) tab keypairs; 

402 

24940  403 
fun add_type_sort_preds (T, preds) = 
404 
update_many (preds, map pred_of_sort (sorts_on_typs T)); 

17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset

405 

18868  406 
fun add_classrelClause_preds (ClassrelClause {subclass,superclass,...}, preds) = 
407 
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

408 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

409 
fun class_of_arityLit (TConsLit (tclass, _, _)) = tclass 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

410 
 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

411 

18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset

412 
fun add_arityClause_preds (ArityClause {conclLit,premLits,...}, preds) = 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

413 
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

414 
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

415 
in foldl upd preds classes end; 
18868  416 

417 
(*** Find occurrences of functions in clauses ***) 

418 

419 
fun add_foltype_funcs (AtomV _, funcs) = funcs 

420 
 add_foltype_funcs (AtomF a, funcs) = Symtab.update (a,0) funcs 

24310  421 
 add_foltype_funcs (Comp(a,tys), funcs) = 
18868  422 
foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys; 
423 

20038  424 
(*TFrees are recorded as constants*) 
24940  425 
fun add_type_sort_funcs (TVar _, funcs) = funcs 
426 
 add_type_sort_funcs (TFree (a, _), funcs) = 

20038  427 
Symtab.update (make_fixed_type_var a, 0) funcs 
428 

18868  429 
fun add_arityClause_funcs (ArityClause {conclLit,...}, funcs) = 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

430 
let val TConsLit (_, tcons, tvars) = conclLit 
18868  431 
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

432 

23075  433 
(*This type can be overlooked because it is builtin...*) 
434 
val init_functab = Symtab.update ("tc_itself", 1) Symtab.empty; 

435 

18868  436 

437 
(**** Stringoriented operations ****) 

15347  438 

24310  439 
fun string_of_clausename (cls_id,ax_name) = 
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

440 
clause_prefix ^ ascii_of ax_name ^ "_" ^ Int.toString cls_id; 
17317
3f12de2e2e6e
IsabelleATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset

441 

24310  442 
fun string_of_type_clsname (cls_id,ax_name,idx) = 
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

443 
string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx); 
18863  444 

24310  445 
fun writeln_strs os = List.app (fn s => TextIO.output (os, s)); 
18863  446 

24310  447 

18868  448 
(**** Producing DFG files ****) 
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

449 

18863  450 
(*Attach sign in DFG syntax: false means negate.*) 
451 
fun dfg_sign true s = s 

24310  452 
 dfg_sign false s = "not(" ^ s ^ ")" 
18863  453 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

454 
fun dfg_of_typeLit pos (LTVar (s,ty)) = dfg_sign pos (s ^ "(" ^ ty ^ ")") 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

455 
 dfg_of_typeLit pos (LTFree (s,ty)) = dfg_sign pos (s ^ "(" ^ ty ^ ")"); 
24310  456 

18868  457 
(*Enclose the clause body by quantifiers, if necessary*) 
24310  458 
fun dfg_forall [] body = body 
18868  459 
 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

460 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

461 
fun gen_dfg_cls (cls_id, ax_name, Axiom, lits, tylits, vars) = 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

462 
"clause( %(axiom)\n" ^ 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

463 
dfg_forall vars ("or(" ^ commas (tylits@lits) ^ ")") ^ ",\n" ^ 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

464 
string_of_clausename (cls_id,ax_name) ^ ").\n\n" 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

465 
 gen_dfg_cls (cls_id, ax_name, Conjecture, lits, _, vars) = 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

466 
"clause( %(negated_conjecture)\n" ^ 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

467 
dfg_forall vars ("or(" ^ commas lits ^ ")") ^ ",\n" ^ 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

468 
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

469 

18798  470 
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

471 

18856
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

472 
fun string_of_preds [] = "" 
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

473 
 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

474 

18856
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

475 
fun string_of_funcs [] = "" 
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

476 
 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

477 

24310  478 
fun string_of_symbols predstr funcstr = 
17234  479 
"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

480 

18798  481 
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

482 

24310  483 
fun string_of_descrip name = 
484 
"list_of_descriptions.\nname({*" ^ name ^ 

18868  485 
"*}).\nauthor({*Isabelle*}).\nstatus(unknown).\ndescription({*autogenerated*}).\nend_of_list.\n\n" 
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

486 

18863  487 
fun dfg_tfree_clause tfree_lit = 
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

488 
"clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n" 
18863  489 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

490 
fun dfg_of_arLit (TConsLit (c,t,args)) = 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

491 
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

492 
 dfg_of_arLit (TVarLit (c,str)) = 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

493 
dfg_sign false (make_type_class c ^ "(" ^ str ^ ")") 
24310  494 

20038  495 
fun dfg_classrelLits sub sup = "not(" ^ sub ^ "(T)), " ^ sup ^ "(T)"; 
17525
ae5bb6001afb
tidying, and support for axclass/classrel clauses
paulson
parents:
17422
diff
changeset

496 

18868  497 
fun dfg_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) = 
498 
"clause(forall([T],\nor( " ^ dfg_classrelLits subclass superclass ^ ")),\n" ^ 

499 
axiom_name ^ ").\n\n"; 

24310  500 

21560  501 
fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name; 
502 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

503 
fun dfg_arity_clause (ArityClause{axiom_name,conclLit,premLits,...}) = 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

504 
let val TConsLit (_,_,tvars) = conclLit 
18868  505 
val lits = map dfg_of_arLit (conclLit :: premLits) 
18863  506 
in 
24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

507 
"clause( %(axiom)\n" ^ 
18868  508 
dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^ 
21560  509 
string_of_ar axiom_name ^ ").\n\n" 
18863  510 
end; 
511 

17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

512 

18869
00741f7280f7
removal of ResClause.num_of_clauses and other simplifications
paulson
parents:
18868
diff
changeset

513 
(**** Produce TPTP files ****) 
18868  514 

515 
(*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

516 
fun tptp_sign true s = s 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

517 
 tptp_sign false s = "~ " ^ s 
18868  518 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

519 
fun tptp_of_typeLit pos (LTVar (s,ty)) = tptp_sign pos (s ^ "(" ^ ty ^ ")") 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

520 
 tptp_of_typeLit pos (LTFree (s,ty)) = tptp_sign pos (s ^ "(" ^ ty ^ ")"); 
24310  521 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

522 
fun gen_tptp_cls (cls_id,ax_name,Axiom,lits,tylits) = 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

523 
"cnf(" ^ string_of_clausename (cls_id,ax_name) ^ ",axiom," ^ 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

524 
tptp_pack (tylits@lits) ^ ").\n" 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

525 
 gen_tptp_cls (cls_id,ax_name,Conjecture,lits,_) = 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

526 
"cnf(" ^ string_of_clausename (cls_id,ax_name) ^ ",negated_conjecture," ^ 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

527 
tptp_pack lits ^ ").\n"; 
15347  528 

18863  529 
fun tptp_tfree_clause tfree_lit = 
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

530 
"cnf(" ^ "tfree_tcs," ^ "negated_conjecture" ^ "," ^ tptp_pack[tfree_lit] ^ ").\n"; 
24310  531 

22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

532 
fun tptp_of_arLit (TConsLit (c,t,args)) = 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

533 
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

534 
 tptp_of_arLit (TVarLit (c,str)) = 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

535 
tptp_sign false (make_type_class c ^ "(" ^ str ^ ")") 
24310  536 

24937
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

537 
fun tptp_arity_clause (ArityClause{axiom_name,conclLit,premLits,...}) = 
340523598914
contextbased treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset

538 
"cnf(" ^ string_of_ar axiom_name ^ ",axiom," ^ 
21560  539 
tptp_pack (map tptp_of_arLit (conclLit :: premLits)) ^ ").\n"; 
15347  540 

24310  541 
fun tptp_classrelLits sub sup = 
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

542 
let val tvar = "(T)" 
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

543 
in tptp_pack [tptp_sign false (sub^tvar), tptp_sign true (sup^tvar)] end; 
15347  544 

18868  545 
fun tptp_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) = 
24310  546 
"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

547 

15347  548 
end; 