author  wenzelm 
Fri, 17 Aug 2007 23:10:41 +0200  
changeset 24310  af4af9993922 
parent 24183  a46b758941a4 
child 24322  dc7336b8c54c 
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 
val name_of_kind : kind > string 

36 
type axiom_name = string 

37 
datatype typ_var = FOLTVar of indexname  FOLTFree of string 

38 
datatype fol_type = 

39 
AtomV of string 

40 
 AtomF of string 

41 
 Comp of string * fol_type list 

18868  42 
val string_of_fol_type : fol_type > string 
24310  43 
datatype type_literal = LTVar of string * string  LTFree of string * string 
44 
val mk_typ_var_sort: typ > typ_var * sort 

45 
exception CLAUSE of string * term 

46 
val init : theory > unit 

47 
val isMeta : string > bool 

48 
val add_typs_aux : (typ_var * string list) list > type_literal list * type_literal list 

49 
val get_tvar_strs: (typ_var * sort) list > string list 

50 
datatype arLit = 

51 
TConsLit of class * string * string list 

52 
 TVarLit of class * string 

53 
datatype arityClause = ArityClause of 

54 
{axiom_name: axiom_name, 

55 
kind: kind, 

56 
conclLit: arLit, 

57 
premLits: arLit list} 

58 
datatype classrelClause = ClassrelClause of 

59 
{axiom_name: axiom_name, 

60 
subclass: class, 

61 
superclass: class} 

62 
val make_classrel_clauses: theory > class list > class list > classrelClause list 

63 
val make_arity_clauses: theory > string list > class list > class list * arityClause list 

64 
val add_type_sort_preds: (typ_var * string list) * int Symtab.table > int Symtab.table 

65 
val add_classrelClause_preds : classrelClause * int Symtab.table > int Symtab.table 

66 
val class_of_arityLit: arLit > class 

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

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

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

70 
val init_functab: int Symtab.table 

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

19719  72 
val dfg_sign: bool > string > string 
73 
val dfg_of_typeLit: type_literal > string 

74 
val gen_dfg_cls: int * string * string * string * string list > string 

24310  75 
val string_of_preds: (string * Int.int) list > string 
76 
val string_of_funcs: (string * int) list > string 

77 
val string_of_symbols: string > string > string 

19719  78 
val string_of_start: string > string 
79 
val string_of_descrip : string > string 

24310  80 
val dfg_tfree_clause : string > string 
19719  81 
val dfg_classrelClause: classrelClause > string 
82 
val dfg_arity_clause: arityClause > string 

24310  83 
val tptp_sign: bool > string > string 
84 
val tptp_of_typeLit : type_literal > string 

85 
val gen_tptp_cls : int * string * kind * string list > string 

86 
val tptp_tfree_clause : string > string 

87 
val tptp_arity_clause : arityClause > string 

88 
val tptp_classrelClause : classrelClause > string 

89 
end 

15347  90 

24310  91 
structure ResClause: RES_CLAUSE = 
15347  92 
struct 
93 

94 
val schematic_var_prefix = "V_"; 

95 
val fixed_var_prefix = "v_"; 

96 

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

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

98 
val tfree_prefix = "t_"; 
15347  99 

24310  100 
val clause_prefix = "cls_"; 
101 
val arclause_prefix = "clsarity_" 

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

102 
val clrelclause_prefix = "clsrel_"; 
15347  103 

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

104 
val const_prefix = "c_"; 
24310  105 
val tconst_prefix = "tc_"; 
106 
val class_prefix = "class_"; 

15347  107 

17775  108 
fun union_all xss = foldl (op union) [] xss; 
109 

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

15347  111 
val const_trans_table = 
112 
Symtab.make [("op =", "equal"), 

24310  113 
(@{const_name HOL.less_eq}, "lessequals"), 
114 
(@{const_name HOL.less}, "less"), 

115 
("op &", "and"), 

116 
("op ", "or"), 

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

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

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

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

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

122 
("op >", "implies"), 

123 
("{}", "emptyset"), 

124 
("op :", "in"), 

125 
("op Un", "union"), 

126 
("op Int", "inter"), 

127 
("List.append", "append"), 

128 
("ATP_Linkup.fequal", "fequal"), 

129 
("ATP_Linkup.COMBI", "COMBI"), 

130 
("ATP_Linkup.COMBK", "COMBK"), 

131 
("ATP_Linkup.COMBB", "COMBB"), 

132 
("ATP_Linkup.COMBC", "COMBC"), 

133 
("ATP_Linkup.COMBS", "COMBS"), 

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

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

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

15347  137 

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

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

139 
Symtab.make [("*", "prod"), 
24310  140 
("+", "sum"), 
141 
("~=>", "map")]; 

15347  142 

15610  143 
(*Escaping of special characters. 
144 
Alphanumeric characters are left unchanged. 

145 
The character _ goes to __ 

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

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

15610  149 

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

15610  152 

15347  153 
fun ascii_of_c c = 
15610  154 
if Char.isAlphaNum c then String.str c 
155 
else if c = #"_" then "__" 

24310  156 
else if #" " <= c andalso c <= #"/" 
15610  157 
then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) 
24310  158 
else if Char.isPrint c 
24183  159 
then ("_" ^ stringN_of_int 3 (Char.ord c)) (*fixed width, in case more digits follow*) 
15610  160 
else "" 
15347  161 

15610  162 
val ascii_of = String.translate ascii_of_c; 
163 

24183  164 
(** Remove ASCII armouring from names in proof files **) 
165 

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

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

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

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

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

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

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

24310  175 
else 
24183  176 
let val digits = List.take (c::cs, 3) handle Subscript => [] 
24310  177 
in 
24183  178 
case Int.fromString (String.implode digits) of 
179 
NONE => undo_ascii_aux (c:: #"_"::rcs) cs (*ERROR*) 

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

181 
end 

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

183 

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

15347  185 

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

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

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

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

189 

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

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

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

192 

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

193 

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

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

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

196 
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

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

198 

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

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

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

202 
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v); 
15347  203 
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x); 
204 

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

206 
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

207 
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); 
15347  208 

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

211 

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

213 
fun controlled_length s = 

24310  214 
if size s > 60 andalso !dfg_format 
23075  215 
then Word.toString (Polyhash.hashw_string(s,0w0)) 
216 
else s; 

217 

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

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

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

222 

24310  223 
fun lookup_type_const c = 
17412  224 
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

225 
SOME c' => c' 
23075  226 
 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

227 

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

228 
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

229 
 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

230 

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

231 
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

232 

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

234 

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

235 

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

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

238 
datatype kind = Axiom  Conjecture; 
23385  239 

15347  240 
fun name_of_kind Axiom = "axiom" 
21509
6c5755ad9cae
ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents:
21470
diff
changeset

241 
 name_of_kind Conjecture = "negated_conjecture"; 
15347  242 

243 
type axiom_name = string; 

244 

245 
(**** Isabelle FOL clauses ****) 

246 

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

247 
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

248 

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

250 
datatype fol_type = AtomV of string 
24310  251 
 AtomF of string 
252 
 Comp of string * fol_type list; 

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

253 

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

254 
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

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

257 
tcon ^ (paren_pack (map string_of_fol_type tps)); 
24310  258 

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

15347  261 

17999  262 
fun mk_typ_var_sort (TFree(a,s)) = (FOLTFree a,s) 
263 
 mk_typ_var_sort (TVar(v,s)) = (FOLTVar v,s); 

264 

265 

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

266 
exception CLAUSE of string * term; 
15347  267 

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

268 

18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset

269 
(*Declarations of the current theoryto allow suppressing types.*) 
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset

270 
val const_typargs = ref (Library.K [] : (string*typ > typ list)); 
17317
3f12de2e2e6e
IsabelleATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17312
diff
changeset

271 

21790
9d2761d09d91
Removal of the "keep_types" flag: we always keep types!
paulson
parents:
21564
diff
changeset

272 
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

273 

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

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

275 
producing any clauses!*) 
18218
9a7ffce389c3
new treatment of polymorphic types, using Sign.const_typargs
paulson
parents:
18199
diff
changeset

276 
fun init thy = (const_typargs := Sign.const_typargs thy); 
24310  277 

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

278 

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

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

282 
let val (folTyps, ts) = types_of Ts 

283 
val t = make_fixed_type_const a 

18798  284 
in (Comp(t,folTyps), ts) end 
24310  285 
 type_of (TFree (a,s)) = (AtomF(make_fixed_type_var a), [(FOLTFree a, s)]) 
18798  286 
 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

287 
and types_of Ts = 
18798  288 
let val (folTyps,ts) = ListPair.unzip (map type_of Ts) 
289 
in (folTyps, union_all ts) end; 

15390  290 

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

291 

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

294 
val isMeta = String.isPrefix "METAHYP1_" 

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

295 

24310  296 
(*Make literals for sorted type variables*) 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

297 
fun sorts_on_typs (_, []) = [] 
24310  298 
 sorts_on_typs (v, s::ss) = 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

299 
let val sorts = sorts_on_typs (v, ss) 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

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

301 
if s = "HOL.type" then sorts 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

302 
else case v of 
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

303 
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

304 
 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

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

306 

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

308 
 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

309 

16199
ee95ab217fee
no longer emits literals for type class HOL.type; also minor tidying
paulson
parents:
16039
diff
changeset

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

311 
The first is for TVars, the second for TFrees.*) 
18856
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

312 
fun add_typs_aux [] = ([],[]) 
24310  313 
 add_typs_aux ((FOLTVar indx, s) :: tss) = 
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

314 
let val vs = sorts_on_typs (FOLTVar indx, s) 
24310  315 
val (vss,fss) = add_typs_aux tss 
23385  316 
in (vs union vss, fss) end 
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset

317 
 add_typs_aux ((FOLTFree x, s) :: tss) = 
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset

318 
let val fs = sorts_on_typs (FOLTFree x, s) 
24310  319 
val (vss,fss) = add_typs_aux tss 
23385  320 
in (vss, fs union fss) end; 
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset

321 

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

322 

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

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

324 

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

325 
fun get_tvar_strs [] = [] 
24310  326 
 get_tvar_strs ((FOLTVar indx,s)::tss) = 
20854  327 
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

328 
 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

329 

24310  330 

19354  331 

15347  332 
(**** Isabelle arities ****) 
333 

334 
exception ARCLAUSE of string; 

335 

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

337 
 TVarLit of class * string; 
24310  338 

339 
datatype arityClause = 

340 
ArityClause of {axiom_name: axiom_name, 

341 
kind: kind, 

342 
conclLit: arLit, 

343 
premLits: arLit list}; 

15347  344 

345 

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

15347  348 

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

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

350 
 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

351 
 pack_sort(tvar, cls::srt) = (cls, tvar) :: pack_sort(tvar, srt); 
24310  352 

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

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

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

356 
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

357 
in 
24310  358 
ArityClause {axiom_name = axiom_name, kind = Axiom, 
359 
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

360 
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

361 
end; 
15347  362 

363 

364 
(**** Isabelle class relations ****) 

365 

24310  366 
datatype classrelClause = 
367 
ClassrelClause of {axiom_name: axiom_name, 

368 
subclass: class, 

369 
superclass: class}; 

370 

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

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

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

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

374 
let val class_less = Sorts.class_less(Sign.classes_of thy) 
24310  375 
fun add_super sub (super,pairs) = 
376 
if class_less (sub,super) then (sub,super)::pairs else pairs 

377 
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

378 
in foldl add_supers [] subs end; 
15347  379 

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

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

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

383 
superclass = make_type_class super}; 
15347  384 

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

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

386 
map make_classrelClause (class_pairs thy subs supers); 
18868  387 

388 

389 
(** Isabelle arities **) 

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

390 

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

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

392 
 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

393 
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

394 
 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

395 
if class mem_string seen then (*multiple arities for the same tycon, class pair*) 
24310  396 
make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) :: 
397 
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

398 
else 
24310  399 
make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class, ar) :: 
400 
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

401 

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

402 
fun multi_arity_clause [] = [] 
19155  403 
 multi_arity_clause ((tcons,ars) :: tc_arlists) = 
24310  404 
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

405 

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

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

407 
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

408 
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

409 
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

410 
fun domain_sorts (tycon,class) = Sorts.mg_domain alg tycon [class] 
24310  411 
fun add_class tycon (class,pairs) = 
412 
(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

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

414 
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

415 
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

416 

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

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

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

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

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

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

423 
else Output.debug (fn _ => "New classes: " ^ space_implode ", " newclasses) 
24310  424 
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

425 
in (classes' union classes, cpairs' union cpairs) end; 
24310  426 

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

427 
fun make_arity_clauses thy tycons classes = 
24310  428 
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

429 
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

430 

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

431 

18868  432 
(**** Find occurrences of predicates in clauses ****) 
433 

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

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

438 

24310  439 
fun add_type_sort_preds ((FOLTVar indx,s), preds) = 
18868  440 
update_many (preds, map pred_of_sort (sorts_on_typs (FOLTVar indx, s))) 
441 
 add_type_sort_preds ((FOLTFree x,s), preds) = 

442 
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

443 

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

446 

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

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

448 
 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

449 

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

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

451 
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

452 
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

453 
in foldl upd preds classes end; 
18868  454 

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

456 

457 
fun add_foltype_funcs (AtomV _, funcs) = funcs 

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

24310  459 
 add_foltype_funcs (Comp(a,tys), funcs) = 
18868  460 
foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys; 
461 

20038  462 
(*TFrees are recorded as constants*) 
463 
fun add_type_sort_funcs ((FOLTVar _, _), funcs) = funcs 

24310  464 
 add_type_sort_funcs ((FOLTFree a, _), funcs) = 
20038  465 
Symtab.update (make_fixed_type_var a, 0) funcs 
466 

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

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

470 

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

473 

18868  474 

475 
(**** Stringoriented operations ****) 

15347  476 

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

478 
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

479 

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

481 
string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx); 
18863  482 

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

24310  485 

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

487 

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

24310  490 
 dfg_sign false s = "not(" ^ s ^ ")" 
18863  491 

18798  492 
fun dfg_of_typeLit (LTVar (s,ty)) = "not(" ^ s ^ "(" ^ ty ^ "))" 
18856
4669dec681f4
tidyup of res_clause.ML, removing the "predicates" field
paulson
parents:
18798
diff
changeset

493 
 dfg_of_typeLit (LTFree (s,ty)) = s ^ "(" ^ ty ^ ")"; 
24310  494 

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

498 

24310  499 
fun gen_dfg_cls (cls_id, ax_name, knd, lits, vars) = 
500 
"clause( %(" ^ knd ^ ")\n" ^ 

501 
dfg_forall vars ("or(" ^ lits ^ ")") ^ ",\n" ^ 

18863  502 
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

503 

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

505 

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

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

507 
 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

508 

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

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

510 
 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

511 

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

514 

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

516 

24310  517 
fun string_of_descrip name = 
518 
"list_of_descriptions.\nname({*" ^ name ^ 

18868  519 
"*}).\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

520 

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

522 
"clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n" 
18863  523 

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

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

525 
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

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

527 
dfg_sign false (make_type_class c ^ "(" ^ str ^ ")") 
24310  528 

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

530 

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

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

24310  534 

21560  535 
fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name; 
536 

24310  537 
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

538 
let val TConsLit (_,_,tvars) = conclLit 
18868  539 
val lits = map dfg_of_arLit (conclLit :: premLits) 
18863  540 
in 
24310  541 
"clause( %(" ^ name_of_kind kind ^ ")\n" ^ 
18868  542 
dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^ 
21560  543 
string_of_ar axiom_name ^ ").\n\n" 
18863  544 
end; 
545 

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

546 

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

547 
(**** Produce TPTP files ****) 
18868  548 

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

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

551 
 tptp_sign false s = "~ " ^ s 
18868  552 

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

553 
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

554 
 tptp_of_typeLit (LTFree (s,ty)) = tptp_sign true (s ^ "(" ^ ty ^ ")"); 
24310  555 

556 
fun gen_tptp_cls (cls_id,ax_name,knd,lits) = 

557 
"cnf(" ^ string_of_clausename (cls_id,ax_name) ^ "," ^ 

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

558 
name_of_kind knd ^ "," ^ tptp_pack lits ^ ").\n"; 
15347  559 

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

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

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

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

564 
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

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

566 
tptp_sign false (make_type_class c ^ "(" ^ str ^ ")") 
24310  567 

568 
fun tptp_arity_clause (ArityClause{axiom_name,kind,conclLit,premLits,...}) = 

569 
"cnf(" ^ string_of_ar axiom_name ^ "," ^ name_of_kind kind ^ "," ^ 

21560  570 
tptp_pack (map tptp_of_arLit (conclLit :: premLits)) ^ ").\n"; 
15347  571 

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

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

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

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

578 

15347  579 
end; 