src/HOL/Tools/res_clause.ML
author paulson
Thu Jun 14 13:18:24 2007 +0200 (2007-06-14)
changeset 23385 0ef4f9fc0d09
parent 23075 69e30a7e8880
child 23881 851c74f1bb69
permissions -rw-r--r--
Deleted unused code
     1 (*  Author: Jia Meng, Cambridge University Computer Laboratory
     2     ID: $Id$
     3     Copyright 2004 University of Cambridge
     4 
     5 ML data structure for storing/printing FOL clauses and arity clauses.
     6 Typed equality is treated differently.
     7 *)
     8 
     9 (*FIXME: is this signature necessary? Or maybe define and open a Basic_ResClause?*)
    10 (*FIXME: combine with res_hol_clause!*)
    11 signature RES_CLAUSE =
    12   sig
    13   exception CLAUSE of string * term
    14   type arityClause and classrelClause
    15   datatype fol_type = AtomV of string
    16                     | AtomF of string
    17                     | Comp of string * fol_type list;
    18   datatype kind = Axiom | Conjecture;
    19   val name_of_kind : kind -> string
    20   type typ_var and type_literal 
    21   val add_typs_aux : (typ_var * string list) list -> type_literal list * type_literal list
    22   val ascii_of : string -> string
    23   val tptp_pack : string list -> string
    24   val make_arity_clauses: theory -> (class list * arityClause list)
    25   val make_classrel_clauses: theory -> class list -> class list -> classrelClause list 
    26   val clause_prefix : string 
    27   val const_prefix : string
    28   val fixed_var_prefix : string
    29   val gen_tptp_cls : int * string * string * string list -> string
    30   val init : theory -> unit
    31   val isMeta : string -> bool
    32   val make_fixed_const : string -> string		
    33   val make_fixed_type_const : string -> string   
    34   val make_fixed_type_var : string -> string
    35   val make_fixed_var : string -> string
    36   val make_schematic_type_var : string * int -> string
    37   val make_schematic_var : string * int -> string
    38   val make_type_class : string -> string
    39   val mk_typ_var_sort : Term.typ -> typ_var * sort
    40   val paren_pack : string list -> string
    41   val schematic_var_prefix : string
    42   val string_of_fol_type : fol_type -> string
    43   val tconst_prefix : string 
    44   val tfree_prefix : string
    45   val tvar_prefix : string
    46   val tptp_arity_clause : arityClause -> string
    47   val tptp_classrelClause : classrelClause -> string
    48   val tptp_of_typeLit : type_literal -> string
    49   val tptp_tfree_clause : string -> string
    50   val union_all : ''a list list -> ''a list
    51   val writeln_strs: TextIO.outstream -> TextIO.vector list -> unit
    52   val dfg_sign: bool -> string -> string
    53   val dfg_of_typeLit: type_literal -> string
    54   val get_tvar_strs: (typ_var * sort) list -> string list
    55   val gen_dfg_cls: int * string * string * string * string list -> string
    56   val add_foltype_funcs: fol_type * int Symtab.table -> int Symtab.table
    57   val add_arityClause_funcs: arityClause * int Symtab.table -> int Symtab.table
    58   val add_arityClause_preds: arityClause * int Symtab.table -> int Symtab.table
    59   val add_classrelClause_preds : classrelClause * int Symtab.table -> int Symtab.table
    60   val dfg_tfree_clause : string -> string
    61   val string_of_start: string -> string
    62   val string_of_descrip : string -> string
    63   val string_of_symbols: string -> string -> string
    64   val string_of_funcs: (string * int) list -> string
    65   val string_of_preds: (string * Int.int) list -> string
    66   val dfg_classrelClause: classrelClause -> string
    67   val dfg_arity_clause: arityClause -> string
    68 end;
    69 
    70 structure ResClause =
    71 struct
    72 
    73 val schematic_var_prefix = "V_";
    74 val fixed_var_prefix = "v_";
    75 
    76 val tvar_prefix = "T_";
    77 val tfree_prefix = "t_";
    78 
    79 val clause_prefix = "cls_"; 
    80 val arclause_prefix = "clsarity_" 
    81 val clrelclause_prefix = "clsrel_";
    82 
    83 val const_prefix = "c_";
    84 val tconst_prefix = "tc_"; 
    85 val class_prefix = "class_"; 
    86 
    87 fun union_all xss = foldl (op union) [] xss;
    88 
    89 (*Provide readable names for the more common symbolic functions*)
    90 val const_trans_table =
    91       Symtab.make [("op =", "equal"),
    92 	  	   (@{const_name Orderings.less_eq}, "lessequals"),
    93 		   (@{const_name Orderings.less}, "less"),
    94 		   ("op &", "and"),
    95 		   ("op |", "or"),
    96 		   (@{const_name HOL.plus}, "plus"),
    97 		   (@{const_name HOL.minus}, "minus"),
    98 		   (@{const_name HOL.times}, "times"),
    99 		   (@{const_name Divides.div}, "div"),
   100 		   (@{const_name HOL.divide}, "divide"),
   101 		   ("op -->", "implies"),
   102 		   ("{}", "emptyset"),
   103 		   ("op :", "in"),
   104 		   ("op Un", "union"),
   105 		   ("op Int", "inter"),
   106 		   ("List.append", "append"),
   107 		   ("ATP_Linkup.fequal", "fequal"),
   108 		   ("ATP_Linkup.COMBI", "COMBI"),
   109 		   ("ATP_Linkup.COMBK", "COMBK"),
   110 		   ("ATP_Linkup.COMBB", "COMBB"),
   111 		   ("ATP_Linkup.COMBC", "COMBC"),
   112 		   ("ATP_Linkup.COMBS", "COMBS"),
   113 		   ("ATP_Linkup.COMBB'", "COMBB_e"),
   114 		   ("ATP_Linkup.COMBC'", "COMBC_e"),
   115 		   ("ATP_Linkup.COMBS'", "COMBS_e")];
   116 
   117 val type_const_trans_table =
   118       Symtab.make [("*", "prod"),
   119 	  	   ("+", "sum"),
   120 		   ("~=>", "map")];
   121 
   122 (*Escaping of special characters.
   123   Alphanumeric characters are left unchanged.
   124   The character _ goes to __
   125   Characters in the range ASCII space to / go to _A to _P, respectively.
   126   Other printing characters go to _NNN where NNN is the decimal ASCII code.*)
   127 local
   128 
   129 val A_minus_space = Char.ord #"A" - Char.ord #" ";
   130 
   131 fun ascii_of_c c =
   132   if Char.isAlphaNum c then String.str c
   133   else if c = #"_" then "__"
   134   else if #" " <= c andalso c <= #"/" 
   135        then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space))
   136   else if Char.isPrint c then ("_" ^ Int.toString (Char.ord c))
   137   else ""
   138 
   139 in
   140 
   141 val ascii_of = String.translate ascii_of_c;
   142 
   143 end;
   144 
   145 (* convert a list of strings into one single string; surrounded by brackets *)
   146 fun paren_pack [] = ""   (*empty argument list*)
   147   | paren_pack strings = "(" ^ commas strings ^ ")";
   148 
   149 (*TSTP format uses (...) rather than the old [...]*)
   150 fun tptp_pack strings = "(" ^ space_implode " | " strings ^ ")";
   151 
   152 
   153 (*Remove the initial ' character from a type variable, if it is present*)
   154 fun trim_type_var s =
   155   if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE)
   156   else error ("trim_type: Malformed type variable encountered: " ^ s);
   157 
   158 fun ascii_of_indexname (v,0) = ascii_of v
   159   | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i;
   160 
   161 fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v);
   162 fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x);
   163 
   164 fun make_schematic_type_var (x,i) = 
   165       tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i));
   166 fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x));
   167 
   168 (*HACK because SPASS truncates identifiers to 63 characters :-(( *)
   169 val dfg_format = ref false;
   170 
   171 (*32-bit hash,so we expect no collisions unless there are around 65536 long identifiers...*)
   172 fun controlled_length s =
   173   if size s > 60 andalso !dfg_format   
   174   then Word.toString (Polyhash.hashw_string(s,0w0))
   175   else s;
   176 
   177 fun lookup_const c =
   178     case Symtab.lookup const_trans_table c of
   179         SOME c' => c'
   180       | NONE => controlled_length (ascii_of c);
   181 
   182 fun lookup_type_const c = 
   183     case Symtab.lookup type_const_trans_table c of
   184         SOME c' => c'
   185       | NONE => controlled_length (ascii_of c);
   186 
   187 fun make_fixed_const "op =" = "equal"   (*MUST BE "equal" because it's built-in to ATPs*)
   188   | make_fixed_const c      = const_prefix ^ lookup_const c;
   189 
   190 fun make_fixed_type_const c = tconst_prefix ^ lookup_type_const c;
   191 
   192 fun make_type_class clas = class_prefix ^ ascii_of clas;
   193 
   194 
   195 (***** definitions and functions for FOL clauses, for conversion to TPTP or DFG format. *****)
   196 
   197 datatype kind = Axiom | Conjecture;
   198 
   199 fun name_of_kind Axiom = "axiom"
   200   | name_of_kind Conjecture = "negated_conjecture";
   201 
   202 type axiom_name = string;
   203 
   204 (**** Isabelle FOL clauses ****)
   205 
   206 datatype typ_var = FOLTVar of indexname | FOLTFree of string;
   207 
   208 (*FIXME: give the constructors more sensible names*)
   209 datatype fol_type = AtomV of string
   210 		  | AtomF of string
   211 		  | Comp of string * fol_type list;
   212 
   213 fun string_of_fol_type (AtomV x) = x
   214   | string_of_fol_type (AtomF x) = x
   215   | string_of_fol_type (Comp(tcon,tps)) = 
   216       tcon ^ (paren_pack (map string_of_fol_type tps));
   217       
   218 (*First string is the type class; the second is a TVar or TFfree*)
   219 datatype type_literal = LTVar of string * string | LTFree of string * string;
   220 
   221 fun mk_typ_var_sort (TFree(a,s)) = (FOLTFree a,s)
   222   | mk_typ_var_sort (TVar(v,s)) = (FOLTVar v,s);
   223 
   224 
   225 exception CLAUSE of string * term;
   226 
   227 
   228 (*Declarations of the current theory--to allow suppressing types.*)
   229 val const_typargs = ref (Library.K [] : (string*typ -> typ list));
   230 
   231 fun num_typargs(s,T) = length (!const_typargs (s,T));
   232 
   233 (*Initialize the type suppression mechanism with the current theory before
   234     producing any clauses!*)
   235 fun init thy = (const_typargs := Sign.const_typargs thy);
   236     
   237 
   238 (*Flatten a type to a fol_type while accumulating sort constraints on the TFrees and
   239   TVars it contains.*)    
   240 fun type_of (Type (a, Ts)) = 
   241       let val (folTyps, ts) = types_of Ts 
   242 	  val t = make_fixed_type_const a
   243       in (Comp(t,folTyps), ts) end
   244   | type_of (TFree (a,s)) = (AtomF(make_fixed_type_var a), [(FOLTFree a, s)]) 
   245   | type_of (TVar (v, s)) = (AtomV(make_schematic_type_var v), [(FOLTVar v, s)])
   246 and types_of Ts =
   247       let val (folTyps,ts) = ListPair.unzip (map type_of Ts)
   248       in (folTyps, union_all ts) end;
   249 
   250 
   251 fun const_types_of (c,T) = types_of (!const_typargs (c,T));
   252 
   253 (* Any variables created via the METAHYPS tactical should be treated as
   254    universal vars, although it is represented as "Free(...)" by Isabelle *)
   255 val isMeta = String.isPrefix "METAHYP1_"
   256 
   257 (*Make literals for sorted type variables*) 
   258 fun sorts_on_typs (_, [])   = []
   259   | sorts_on_typs (v,  s::ss) = 
   260       let val sorts = sorts_on_typs (v, ss)
   261       in
   262           if s = "HOL.type" then sorts
   263           else case v of
   264               FOLTVar indx => LTVar(make_type_class s, make_schematic_type_var indx) :: sorts
   265             | FOLTFree x => LTFree(make_type_class s, make_fixed_type_var x) :: sorts
   266       end;
   267 
   268 fun pred_of_sort (LTVar (s,ty)) = (s,1)
   269   | pred_of_sort (LTFree (s,ty)) = (s,1)
   270 
   271 (*Given a list of sorted type variables, return two separate lists.
   272   The first is for TVars, the second for TFrees.*)
   273 fun add_typs_aux [] = ([],[])
   274   | add_typs_aux ((FOLTVar indx, s) :: tss) = 
   275       let val vs = sorts_on_typs (FOLTVar indx, s)
   276 	  val (vss,fss) = add_typs_aux tss
   277       in  (vs union vss, fss)  end
   278   | add_typs_aux ((FOLTFree x, s) :: tss) =
   279       let val fs = sorts_on_typs (FOLTFree x, s)
   280 	  val (vss,fss) = add_typs_aux tss
   281       in  (vss, fs union fss)  end;
   282 
   283 
   284 (** make axiom and conjecture clauses. **)
   285 
   286 fun get_tvar_strs [] = []
   287   | get_tvar_strs ((FOLTVar indx,s)::tss) = 
   288       insert (op =) (make_schematic_type_var indx) (get_tvar_strs tss)
   289   | get_tvar_strs((FOLTFree x,s)::tss) = get_tvar_strs tss
   290 
   291     
   292 
   293 (**** Isabelle arities ****)
   294 
   295 exception ARCLAUSE of string;
   296  
   297 type class = string; 
   298 type tcons = string; 
   299 
   300 datatype arLit = TConsLit of class * tcons * string list
   301                | TVarLit of class * string;
   302  
   303 datatype arityClause =  
   304 	 ArityClause of {axiom_name: axiom_name,
   305 			 kind: kind,
   306 			 conclLit: arLit,
   307 			 premLits: arLit list};
   308 
   309 
   310 fun gen_TVars 0 = []
   311   | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1);
   312 
   313 fun pack_sort(_,[])  = []
   314   | pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt)   (*IGNORE sort "type"*)
   315   | pack_sort(tvar, cls::srt) =  (cls, tvar) :: pack_sort(tvar, srt);
   316     
   317 (*Arity of type constructor tcon :: (arg1,...,argN)res*)
   318 fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) =
   319    let val tvars = gen_TVars (length args)
   320        val tvars_srts = ListPair.zip (tvars,args)
   321    in
   322       ArityClause {axiom_name = axiom_name, kind = Axiom, 
   323                    conclLit = TConsLit (cls, make_fixed_type_const tcons, tvars), 
   324                    premLits = map TVarLit (union_all(map pack_sort tvars_srts))}
   325    end;
   326 
   327 
   328 (**** Isabelle class relations ****)
   329 
   330 datatype classrelClause = 
   331 	 ClassrelClause of {axiom_name: axiom_name,
   332 			    subclass: class,
   333 			    superclass: class};
   334  
   335 (*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*)
   336 fun class_pairs thy [] supers = []
   337   | class_pairs thy subs supers =
   338       let val class_less = Sorts.class_less(Sign.classes_of thy)
   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
   342       in  foldl add_supers [] subs  end;
   343 
   344 fun make_classrelClause (sub,super) =
   345   ClassrelClause {axiom_name = clrelclause_prefix ^ ascii_of sub ^ "_" ^ ascii_of super,
   346                   subclass = make_type_class sub, 
   347                   superclass = make_type_class super};
   348 
   349 fun make_classrel_clauses thy subs supers =
   350   map make_classrelClause (class_pairs thy subs supers);
   351 
   352 
   353 (** Isabelle arities **)
   354 
   355 fun arity_clause _ _ (tcons, []) = []
   356   | arity_clause seen n (tcons, ("HOL.type",_)::ars) =  (*ignore*)
   357       arity_clause seen n (tcons,ars)
   358   | arity_clause seen n (tcons, (ar as (class,_)) :: ars) =
   359       if class mem_string seen then (*multiple arities for the same tycon, class pair*)
   360 	  make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) :: 
   361 	  arity_clause seen (n+1) (tcons,ars)
   362       else
   363 	  make_axiom_arity_clause (tcons, lookup_type_const tcons ^ "_" ^ class, ar) :: 
   364 	  arity_clause (class::seen) n (tcons,ars)
   365 
   366 fun multi_arity_clause [] = []
   367   | multi_arity_clause ((tcons,ars) :: tc_arlists) =
   368       arity_clause [] 1 (tcons, ars)  @  multi_arity_clause tc_arlists 
   369 
   370 (*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy
   371   provided its arguments have the corresponding sorts.*)
   372 fun type_class_pairs thy tycons classes =
   373   let val alg = Sign.classes_of thy
   374       fun domain_sorts (tycon,class) = Sorts.mg_domain alg tycon [class]
   375       fun add_class tycon (class,pairs) = 
   376             (class, domain_sorts(tycon,class))::pairs 
   377             handle Sorts.CLASS_ERROR _ => pairs
   378       fun try_classes tycon = (tycon, foldl (add_class tycon) [] classes)
   379   in  map try_classes tycons  end;
   380 
   381 (*Proving one (tycon, class) membership may require proving others, so iterate.*)
   382 fun iter_type_class_pairs thy tycons [] = ([], [])
   383   | iter_type_class_pairs thy tycons classes =
   384       let val cpairs = type_class_pairs thy tycons classes
   385           val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs))) \\ classes \\ HOLogic.typeS
   386           val _ = if null newclasses then () 
   387                   else Output.debug (fn _ => "New classes: " ^ space_implode ", " newclasses)
   388           val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses  
   389       in  (classes' union classes, cpairs' union cpairs)  end;
   390       
   391 fun make_arity_clauses thy tycons classes =
   392   let val (classes', cpairs) = iter_type_class_pairs thy tycons classes  
   393   in  (classes', multi_arity_clause cpairs)  end;
   394 
   395 
   396 (**** Find occurrences of predicates in clauses ****)
   397 
   398 (*FIXME: multiple-arity checking doesn't work, as update_new is the wrong 
   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 
   403 fun add_type_sort_preds ((FOLTVar indx,s), preds) = 
   404       update_many (preds, map pred_of_sort (sorts_on_typs (FOLTVar indx, s)))
   405   | add_type_sort_preds ((FOLTFree x,s), preds) =
   406       update_many (preds, map pred_of_sort (sorts_on_typs (FOLTFree x, s)));
   407 
   408 fun add_classrelClause_preds (ClassrelClause {subclass,superclass,...}, preds) =
   409   Symtab.update (subclass,1) (Symtab.update (superclass,1) preds);
   410 
   411 fun class_of_arityLit (TConsLit (tclass, _, _)) = tclass
   412   | class_of_arityLit (TVarLit (tclass, _)) = tclass;
   413 
   414 fun add_arityClause_preds (ArityClause {conclLit,premLits,...}, preds) =
   415   let val classes = map (make_type_class o class_of_arityLit) (conclLit::premLits)
   416       fun upd (class,preds) = Symtab.update (class,1) preds
   417   in  foldl upd preds classes  end;
   418 
   419 (*** Find occurrences of functions in clauses ***)
   420 
   421 fun add_foltype_funcs (AtomV _, funcs) = funcs
   422   | add_foltype_funcs (AtomF a, funcs) = Symtab.update (a,0) funcs
   423   | add_foltype_funcs (Comp(a,tys), funcs) = 
   424       foldl add_foltype_funcs (Symtab.update (a, length tys) funcs) tys;
   425 
   426 (*TFrees are recorded as constants*)
   427 fun add_type_sort_funcs ((FOLTVar _, _), funcs) = funcs
   428   | add_type_sort_funcs ((FOLTFree a, _), funcs) = 
   429       Symtab.update (make_fixed_type_var a, 0) funcs
   430 
   431 fun add_arityClause_funcs (ArityClause {conclLit,...}, funcs) =
   432   let val TConsLit (_, tcons, tvars) = conclLit
   433   in  Symtab.update (tcons, length tvars) funcs  end;
   434 
   435 (*This type can be overlooked because it is built-in...*)
   436 val init_functab = Symtab.update ("tc_itself", 1) Symtab.empty;
   437 
   438 
   439 (**** String-oriented operations ****)
   440 
   441 fun string_of_clausename (cls_id,ax_name) = 
   442     clause_prefix ^ ascii_of ax_name ^ "_" ^ Int.toString cls_id;
   443 
   444 fun string_of_type_clsname (cls_id,ax_name,idx) = 
   445     string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
   446 
   447 (*Write a list of strings to a file*)
   448 fun writeln_strs os = List.app (fn s => TextIO.output (os,s));
   449 
   450     
   451 (**** Producing DFG files ****)
   452 
   453 (*Attach sign in DFG syntax: false means negate.*)
   454 fun dfg_sign true s = s
   455   | dfg_sign false s = "not(" ^ s ^ ")"  
   456 
   457 fun dfg_of_typeLit (LTVar (s,ty)) = "not(" ^ s ^ "(" ^ ty ^ "))"
   458   | dfg_of_typeLit (LTFree (s,ty)) = s ^ "(" ^ ty ^ ")";
   459  
   460 (*Enclose the clause body by quantifiers, if necessary*)
   461 fun dfg_forall [] body = body  
   462   | dfg_forall vars body = "forall([" ^ commas vars ^ "],\n" ^ body ^ ")"
   463 
   464 fun gen_dfg_cls (cls_id, ax_name, knd, lits, vars) = 
   465     "clause( %(" ^ knd ^ ")\n" ^ 
   466     dfg_forall vars ("or(" ^ lits ^ ")") ^ ",\n" ^ 
   467     string_of_clausename (cls_id,ax_name) ^  ").\n\n";
   468 
   469 fun string_of_arity (name, num) =  "(" ^ name ^ "," ^ Int.toString num ^ ")"
   470 
   471 fun string_of_preds [] = ""
   472   | string_of_preds preds = "predicates[" ^ commas(map string_of_arity preds) ^ "].\n";
   473 
   474 fun string_of_funcs [] = ""
   475   | string_of_funcs funcs = "functions[" ^ commas(map string_of_arity funcs) ^ "].\n" ;
   476 
   477 fun string_of_symbols predstr funcstr = 
   478   "list_of_symbols.\n" ^ predstr  ^ funcstr  ^ "end_of_list.\n\n";
   479 
   480 fun string_of_start name = "begin_problem(" ^ name ^ ").\n\n";
   481 
   482 fun string_of_descrip name = 
   483   "list_of_descriptions.\nname({*" ^ name ^ 
   484   "*}).\nauthor({*Isabelle*}).\nstatus(unknown).\ndescription({*auto-generated*}).\nend_of_list.\n\n"
   485 
   486 fun dfg_tfree_clause tfree_lit =
   487   "clause( %(negated_conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ").\n\n"
   488 
   489 fun dfg_of_arLit (TConsLit (c,t,args)) =
   490       dfg_sign true (make_type_class c ^ "(" ^ t ^ paren_pack args ^ ")")
   491   | dfg_of_arLit (TVarLit (c,str)) =
   492       dfg_sign false (make_type_class c ^ "(" ^ str ^ ")")
   493     
   494 fun dfg_classrelLits sub sup =  "not(" ^ sub ^ "(T)), " ^ sup ^ "(T)";
   495 
   496 fun dfg_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) =
   497   "clause(forall([T],\nor( " ^ dfg_classrelLits subclass superclass ^ ")),\n" ^
   498   axiom_name ^ ").\n\n";
   499       
   500 fun string_of_ar axiom_name = arclause_prefix ^ ascii_of axiom_name;
   501 
   502 fun dfg_arity_clause (ArityClause{axiom_name,kind,conclLit,premLits,...}) = 
   503   let val TConsLit (_,_,tvars) = conclLit
   504       val lits = map dfg_of_arLit (conclLit :: premLits)
   505   in
   506       "clause( %(" ^ name_of_kind kind ^ ")\n" ^ 
   507       dfg_forall tvars ("or( " ^ commas lits ^ ")") ^ ",\n" ^
   508       string_of_ar axiom_name ^ ").\n\n"
   509   end;
   510 
   511 
   512 (**** Produce TPTP files ****)
   513 
   514 (*Attach sign in TPTP syntax: false means negate.*)
   515 fun tptp_sign true s = s
   516   | tptp_sign false s = "~ " ^ s
   517 
   518 fun tptp_of_typeLit (LTVar (s,ty))  = tptp_sign false (s ^ "(" ^ ty ^ ")")
   519   | tptp_of_typeLit (LTFree (s,ty)) = tptp_sign true  (s ^ "(" ^ ty ^ ")");
   520  
   521 fun gen_tptp_cls (cls_id,ax_name,knd,lits) = 
   522     "cnf(" ^ string_of_clausename (cls_id,ax_name) ^ "," ^ 
   523     name_of_kind knd ^ "," ^ tptp_pack lits ^ ").\n";
   524 
   525 fun tptp_tfree_clause tfree_lit =
   526     "cnf(" ^ "tfree_tcs," ^ "negated_conjecture" ^ "," ^ tptp_pack[tfree_lit] ^ ").\n";
   527     
   528 fun tptp_of_arLit (TConsLit (c,t,args)) =
   529       tptp_sign true (make_type_class c ^ "(" ^ t ^ paren_pack args ^ ")")
   530   | tptp_of_arLit (TVarLit (c,str)) =
   531       tptp_sign false (make_type_class c ^ "(" ^ str ^ ")")
   532     
   533 fun tptp_arity_clause (ArityClause{axiom_name,kind,conclLit,premLits,...}) = 
   534   "cnf(" ^ string_of_ar axiom_name ^ "," ^ name_of_kind kind ^ "," ^ 
   535   tptp_pack (map tptp_of_arLit (conclLit :: premLits)) ^ ").\n";
   536 
   537 fun tptp_classrelLits sub sup = 
   538   let val tvar = "(T)"
   539   in  tptp_pack [tptp_sign false (sub^tvar), tptp_sign true (sup^tvar)]  end;
   540 
   541 fun tptp_classrelClause (ClassrelClause {axiom_name,subclass,superclass,...}) =
   542   "cnf(" ^ axiom_name ^ ",axiom," ^ tptp_classrelLits subclass superclass ^ ").\n" 
   543 
   544 end;