src/HOL/Tools/res_clause.ML
author mengj
Fri Oct 28 02:24:58 2005 +0200 (2005-10-28)
changeset 17999 6fe9cb1da9ed
parent 17993 e6e5b28740ec
child 18056 397b39b06ec8
permissions -rw-r--r--
Added several functions to the signature.
Added two new functions, which are used by res_hol_clause.ML programs.
     1 (*  Author: Jia Meng, Cambridge University Computer Laboratory
     2 
     3     ID: $Id$
     4     Copyright 2004 University of Cambridge
     5 
     6 ML data structure for storing/printing FOL clauses and arity clauses.
     7 Typed equality is treated differently.
     8 *)
     9 
    10 (* works for writeoutclasimp on typed *)
    11 signature RES_CLAUSE =
    12   sig
    13   val keep_types : bool ref
    14   val special_equal : bool ref
    15   val tagged : bool ref
    16 
    17   exception ARCLAUSE of string
    18   exception CLAUSE of string * term
    19   type arityClause 
    20   type classrelClause
    21   type clause
    22   val init : theory -> unit
    23   val make_axiom_clause : Term.term -> string * int -> clause
    24   val make_conjecture_clauses : term list -> clause list
    25   val get_axiomName : clause ->  string
    26   val isTaut : clause -> bool
    27   val num_of_clauses : clause -> int
    28 
    29   val clause2dfg : clause -> string * string list
    30   val clauses2dfg : clause list -> string -> clause list -> clause list ->
    31 	   (string * int) list -> (string * int) list -> string
    32   val tfree_dfg_clause : string -> string
    33 
    34   val arity_clause_thy: theory -> arityClause list 
    35   val classrel_clauses_thy: theory -> classrelClause list 
    36 
    37   val tptp_arity_clause : arityClause -> string
    38   val tptp_classrelClause : classrelClause -> string
    39   val tptp_clause : clause -> string list
    40   val clause2tptp : clause -> string * string list
    41   val tfree_clause : string -> string
    42   val schematic_var_prefix : string
    43   val fixed_var_prefix : string
    44   val tvar_prefix : string
    45   val tfree_prefix : string
    46   val clause_prefix : string 
    47   val arclause_prefix : string
    48   val const_prefix : string
    49   val tconst_prefix : string 
    50   val class_prefix : string 
    51 
    52   val union_all : ''a list list -> ''a list
    53   val ascii_of : String.string -> String.string
    54   val paren_pack : string list -> string
    55   val bracket_pack : string list -> string
    56   val make_schematic_var : String.string * int -> string
    57   val make_fixed_var : String.string -> string
    58   val make_schematic_type_var : string * int -> string
    59   val make_fixed_type_var : string -> string
    60   val make_fixed_const : String.string -> string		
    61   val make_fixed_type_const : String.string -> string   
    62   val make_type_class : String.string -> string
    63   val isMeta : String.string -> bool
    64   
    65   type typ_var
    66   val mk_typ_var_sort : Term.typ -> typ_var * sort
    67   type type_literal
    68   val add_typs_aux2 : (typ_var * string list) list -> type_literal list * type_literal list
    69   val gen_tptp_cls : int * string * string * string -> string
    70   val gen_tptp_type_cls : int * string * string * string * int -> string
    71   val tptp_of_typeLit : type_literal -> string
    72   end;
    73 
    74 structure ResClause: RES_CLAUSE =
    75 struct
    76 
    77 (* Added for typed equality *)
    78 val special_equal = ref false; (* by default,equality does not carry type information *)
    79 val eq_typ_wrapper = "typeinfo"; (* default string *)
    80 
    81 
    82 val schematic_var_prefix = "V_";
    83 val fixed_var_prefix = "v_";
    84 
    85 val tvar_prefix = "T_";
    86 val tfree_prefix = "t_";
    87 
    88 val clause_prefix = "cls_"; 
    89 val arclause_prefix = "clsarity_" 
    90 val clrelclause_prefix = "clsrel_";
    91 
    92 val const_prefix = "c_";
    93 val tconst_prefix = "tc_"; 
    94 
    95 val class_prefix = "class_"; 
    96 
    97 
    98 fun union_all xss = foldl (op union) [] xss;
    99 
   100  
   101 (*Provide readable names for the more common symbolic functions*)
   102 val const_trans_table =
   103       Symtab.make [("op =", "equal"),
   104 	  	   ("op <=", "lessequals"),
   105 		   ("op <", "less"),
   106 		   ("op &", "and"),
   107 		   ("op |", "or"),
   108 		   ("op +", "plus"),
   109 		   ("op -", "minus"),
   110 		   ("op *", "times"),
   111 		   ("op -->", "implies"),
   112 		   ("{}", "emptyset"),
   113 		   ("op :", "in"),
   114 		   ("op Un", "union"),
   115 		   ("op Int", "inter")];
   116 
   117 val type_const_trans_table =
   118       Symtab.make [("*", "t_prod"),
   119 	  	   ("+", "t_sum"),
   120 		   ("~=>", "t_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 strings = "(" ^ commas strings ^ ")";
   147 
   148 fun bracket_pack strings = "[" ^ commas strings ^ "]";
   149 
   150 
   151 (*Remove the initial ' character from a type variable, if it is present*)
   152 fun trim_type_var s =
   153   if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE)
   154   else error ("trim_type: Malformed type variable encountered: " ^ s);
   155 
   156 fun ascii_of_indexname (v,0) = ascii_of v
   157   | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i;
   158 
   159 fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v);
   160 fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x);
   161 
   162 (*Type variables contain _H because the character ' translates to that.*)
   163 fun make_schematic_type_var (x,i) = 
   164       tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i));
   165 fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x));
   166 
   167 fun make_fixed_const c =
   168     case Symtab.lookup const_trans_table c of
   169         SOME c' => c'
   170       | NONE =>  const_prefix ^ ascii_of c;
   171 
   172 fun make_fixed_type_const c = 
   173     case Symtab.lookup type_const_trans_table c of
   174         SOME c' => c'
   175       | NONE =>  tconst_prefix ^ ascii_of c;
   176 
   177 fun make_type_class clas = class_prefix ^ ascii_of clas;
   178 
   179 
   180 
   181 (***** definitions and functions for FOL clauses, prepared for conversion into TPTP format or SPASS format. *****)
   182 
   183 val keep_types = ref true;
   184 
   185 datatype kind = Axiom | Hypothesis | Conjecture;
   186 fun name_of_kind Axiom = "axiom"
   187   | name_of_kind Hypothesis = "hypothesis"
   188   | name_of_kind Conjecture = "conjecture";
   189 
   190 type clause_id = int;
   191 type axiom_name = string;
   192 
   193 
   194 type polarity = bool;
   195 
   196 type indexname = Term.indexname;
   197 
   198 
   199 (* "tag" is used for vampire specific syntax  *)
   200 type tag = bool; 
   201 
   202 
   203 (**** Isabelle FOL clauses ****)
   204 
   205 val tagged = ref false;
   206 
   207 type pred_name = string;
   208 type sort = Term.sort;
   209 type fol_type = string;
   210 
   211 
   212 datatype type_literal = LTVar of string | LTFree of string;
   213 
   214 
   215 datatype folTerm = UVar of string * fol_type
   216                  | Fun of string * fol_type * folTerm list;
   217 datatype predicate = Predicate of pred_name * fol_type * folTerm list;
   218 
   219 datatype literal = Literal of polarity * predicate * tag;
   220 
   221 datatype typ_var = FOLTVar of indexname | FOLTFree of string;
   222 
   223 fun mk_typ_var_sort (TFree(a,s)) = (FOLTFree a,s)
   224   | mk_typ_var_sort (TVar(v,s)) = (FOLTVar v,s);
   225 
   226 
   227 
   228 (* ML datatype used to repsent one single clause: disjunction of literals. *)
   229 datatype clause = 
   230 	 Clause of {clause_id: clause_id,
   231 		    axiom_name: axiom_name,
   232 		    kind: kind,
   233 		    literals: literal list,
   234 		    types_sorts: (typ_var * sort) list, 
   235                     tvar_type_literals: type_literal list, 
   236                     tfree_type_literals: type_literal list ,
   237                     tvars: string list,
   238                     predicates: (string*int) list,
   239                     functions: (string*int) list};
   240 
   241 
   242 exception CLAUSE of string * term;
   243 
   244 
   245 (*** make clauses ***)
   246 
   247 fun isFalse (Literal (pol,Predicate(a,_,[]),_)) =
   248       (pol andalso a = "c_False") orelse
   249       (not pol andalso a = "c_True")
   250   | isFalse _ = false;
   251 
   252 fun isTrue (Literal (pol,Predicate(a,_,[]),_)) =
   253       (pol andalso a = "c_True") orelse
   254       (not pol andalso a = "c_False")
   255   | isTrue _ = false;
   256   
   257 fun isTaut (Clause {literals,...}) = exists isTrue literals;  
   258 
   259 fun make_clause (clause_id,axiom_name,kind,literals,
   260                  types_sorts,tvar_type_literals,
   261                  tfree_type_literals,tvars, predicates, functions) =
   262   if forall isFalse literals 
   263   then error "Problem too trivial for resolution (empty clause)"
   264   else
   265      Clause {clause_id = clause_id, axiom_name = axiom_name, kind = kind, 
   266              literals = literals, types_sorts = types_sorts,
   267              tvar_type_literals = tvar_type_literals,
   268              tfree_type_literals = tfree_type_literals,
   269              tvars = tvars, predicates = predicates, 
   270              functions = functions};
   271 
   272 
   273 (** Some Clause destructor functions **)
   274 
   275 fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
   276 
   277 fun get_axiomName (Clause cls) = #axiom_name cls;
   278 
   279 fun get_clause_id (Clause cls) = #clause_id cls;
   280 
   281 fun funcs_of_cls (Clause cls) = #functions cls;
   282 
   283 fun preds_of_cls (Clause cls) = #predicates cls;
   284 
   285 
   286 
   287 (*Declarations of the current theory--to allow suppressing types.*)
   288 val monomorphic = ref (fn (_: string) => false);
   289 fun no_types_needed s = ! monomorphic s;
   290 
   291 (*Initialize the type suppression mechanism with the current theory before
   292     producing any clauses!*)
   293 fun init thy = (monomorphic := Sign.monomorphic thy);
   294     
   295 
   296 (*Flatten a type to a string while accumulating sort constraints on the TFress and
   297   TVars it contains.*)    
   298 fun type_of (Type (a, [])) = 
   299       let val t = make_fixed_type_const a
   300       in (t,([],[(t,0)]))  end
   301   | type_of (Type (a, Ts)) = 
   302       let val foltyps_ts = map type_of Ts 
   303 	  val (folTyps,ts_funcs) = ListPair.unzip foltyps_ts
   304 	  val (ts, funcslist) = ListPair.unzip ts_funcs
   305 	  val ts' = union_all ts
   306 	  val funcs' = union_all funcslist
   307 	  val t = make_fixed_type_const a
   308       in    
   309 	  ((t ^ paren_pack folTyps), (ts', (t, length Ts)::funcs'))
   310       end
   311   | type_of (TFree (a, s)) = 
   312       let val t = make_fixed_type_var a
   313       in (t, ([((FOLTFree a),s)],[(t,0)])) end
   314   | type_of (TVar (v, s)) = (make_schematic_type_var v, ([((FOLTVar v),s)], []))
   315 
   316 
   317 fun maybe_type_of c T =
   318  if no_types_needed c then ("",([],[])) else type_of T;
   319 
   320 (* Any variables created via the METAHYPS tactical should be treated as
   321    universal vars, although it is represented as "Free(...)" by Isabelle *)
   322 val isMeta = String.isPrefix "METAHYP1_"
   323 
   324 fun pred_name_type (Const(c,T)) = 
   325       let val (typof,(folTyps,funcs)) = maybe_type_of c T
   326       in (make_fixed_const c, (typof,folTyps), funcs) end
   327   | pred_name_type (Free(x,T))  = 
   328       if isMeta x then raise CLAUSE("Predicate Not First Order 1", Free(x,T)) 
   329       else (make_fixed_var x, ("",[]), [])
   330   | pred_name_type (v as Var _) = raise CLAUSE("Predicate Not First Order 2", v)
   331   | pred_name_type t        = raise CLAUSE("Predicate input unexpected", t);
   332 
   333 
   334 (* For type equality *)
   335 (* here "arg_typ" is the type of "="'s argument's type, not the type of the equality *)
   336 (* Find type of equality arg *)
   337 fun eq_arg_type (Type("fun",[T,_])) = 
   338     let val (folT,_) = type_of T;
   339     in  folT  end;
   340 
   341 fun fun_name_type (Const(c,T)) args = 
   342       let val t = make_fixed_const c
   343 	val (typof, (folTyps,funcs)) = maybe_type_of c T
   344 	val arity = if !keep_types andalso not (no_types_needed c)
   345 	            then 1 + length args
   346 	            else length args
   347       in
   348 	  (t, (typof,folTyps), ((t,arity)::funcs))
   349       end
   350  | fun_name_type (Free(x,T)) args  = 
   351       let val t = make_fixed_var x
   352       in
   353 	    (t, ("",[]), [(t, length args)])
   354       end
   355   | fun_name_type f args = raise CLAUSE("Function Not First Order 1", f);
   356 
   357 
   358 fun term_of (Var(ind_nm,T)) = 
   359       let val (folType,(ts,funcs)) = type_of T
   360       in
   361 	  (UVar(make_schematic_var ind_nm, folType), (ts, funcs))
   362       end
   363   | term_of (Free(x,T)) = 
   364       let val (folType, (ts,funcs)) = type_of T
   365       in
   366 	  if isMeta x then (UVar(make_schematic_var(x,0),folType),
   367 			    (ts, ((make_schematic_var(x,0)),0)::funcs))
   368 	  else
   369 	      (Fun(make_fixed_var x, folType, []), 
   370 	       (ts, ((make_fixed_var x),0)::funcs))
   371       end
   372   | term_of (Const(c,T)) =  (* impossible to be equality *)
   373       let val (folType,(ts,funcs)) = type_of T
   374       in
   375 	  (Fun(make_fixed_const c, folType, []),
   376 	   (ts, ((make_fixed_const c),0)::funcs))
   377       end    
   378   | term_of (app as (t $ a)) = 
   379       let val (f,args) = strip_comb app
   380 	  fun term_of_aux () = 
   381 	      let val (funName,(funType,ts1),funcs) = fun_name_type f args
   382 		  val (args',ts_funcs) = ListPair.unzip (map term_of args)
   383 		  val (ts2,funcs') = ListPair.unzip ts_funcs
   384 		  val ts3 = union_all (ts1::ts2)
   385 		  val funcs'' = union_all(funcs::funcs')
   386 	      in
   387 		  (Fun(funName,funType,args'), (ts3,funcs''))
   388 	      end
   389 	  fun term_of_eq ((Const ("op =", typ)),args) =
   390 	      let val arg_typ = eq_arg_type typ
   391 		  val (args',ts_funcs) = ListPair.unzip (map term_of args)
   392 		  val (ts,funcs) = ListPair.unzip ts_funcs
   393 		  val equal_name = make_fixed_const ("op =")
   394 	      in
   395 		  (Fun(equal_name,arg_typ,args'),
   396 		   (union_all ts, 
   397 		    (make_fixed_var equal_name, 2):: union_all funcs))
   398 	      end
   399       in
   400 	 case f of Const ("op =", typ) => term_of_eq (f,args)
   401 		 | Const(_,_) => term_of_aux ()
   402 		 | Free(s,_)  => 
   403 		     if isMeta s 
   404 		     then raise CLAUSE("Function Not First Order 2", f)
   405 		     else term_of_aux()
   406 		 | _ => raise CLAUSE("Function Not First Order 3", f)
   407       end
   408   | term_of t = raise CLAUSE("Function Not First Order 4", t); 
   409 
   410 
   411 fun pred_of (Const("op =", typ), args) =
   412       let val arg_typ = eq_arg_type typ 
   413 	  val (args',ts_funcs) = ListPair.unzip (map term_of args)
   414 	  val (ts,funcs) = ListPair.unzip ts_funcs
   415 	  val equal_name = make_fixed_const "op ="
   416       in
   417 	  (Predicate(equal_name,arg_typ,args'),
   418 	   union_all ts, 
   419 	   [((make_fixed_var equal_name), 2)], 
   420 	   union_all funcs)
   421       end
   422   | pred_of (pred,args) = 
   423       let val (predName,(predType,ts1), pfuncs) = pred_name_type pred
   424 	  val (args',ts_funcs) = ListPair.unzip (map term_of args)
   425 	  val (ts2,ffuncs) = ListPair.unzip ts_funcs
   426 	  val ts3 = union_all (ts1::ts2)
   427 	  val ffuncs' = union_all ffuncs
   428 	  val newfuncs = pfuncs union ffuncs'
   429 	  val arity = 
   430 	    case pred of
   431 		Const (c,_) => 
   432 		      if !keep_types andalso not (no_types_needed c)
   433 		      then 1 + length args
   434 		      else length args
   435 	      | _ => length args
   436       in
   437 	  (Predicate(predName,predType,args'), ts3, 
   438 	   [(predName, arity)], newfuncs)
   439       end;
   440 
   441 
   442 (*Treatment of literals, possibly negated or tagged*)
   443 fun predicate_of ((Const("Not",_) $ P), polarity, tag) =
   444       predicate_of (P, not polarity, tag)
   445   | predicate_of ((Const("HOL.tag",_) $ P), polarity, tag) =
   446       predicate_of (P, polarity, true)
   447   | predicate_of (term,polarity,tag) =
   448         (pred_of (strip_comb term), polarity, tag);
   449 
   450 fun literals_of_term1 args (Const("Trueprop",_) $ P) = literals_of_term1 args P
   451   | literals_of_term1 (args as (lits, ts, preds, funcs)) (Const("op |",_) $ P $ Q) = 
   452       let val (lits', ts', preds', funcs') = literals_of_term1 args P
   453       in
   454 	  literals_of_term1 (lits', ts', preds' union preds, funcs' union funcs) Q
   455       end
   456   | literals_of_term1 (lits, ts, preds, funcs) P =
   457       let val ((pred, ts', preds', funcs'), pol, tag) = predicate_of (P,true,false)
   458 	  val lits' = Literal(pol,pred,tag) :: lits
   459       in
   460 	  (lits', ts union ts', preds' union preds, funcs' union funcs)
   461       end;
   462 
   463 
   464 val literals_of_term = literals_of_term1 ([],[],[],[]);
   465 
   466 
   467 (* FIX: not sure what to do with these funcs *)
   468 
   469 (*Make literals for sorted type variables*) 
   470 fun sorts_on_typs (_, [])   = ([]) 
   471   | sorts_on_typs (v, "HOL.type" :: s) =
   472       sorts_on_typs (v,s)   (*Ignore sort "type"*)
   473   | sorts_on_typs ((FOLTVar indx), (s::ss)) =
   474       LTVar((make_type_class s) ^ 
   475         "(" ^ (make_schematic_type_var indx) ^ ")") :: 
   476       (sorts_on_typs ((FOLTVar indx), ss))
   477   | sorts_on_typs ((FOLTFree x), (s::ss)) =
   478       LTFree((make_type_class s) ^ "(" ^ (make_fixed_type_var x) ^ ")") :: 
   479       (sorts_on_typs ((FOLTFree x), ss));
   480 
   481 
   482 (*UGLY: seems to be parsing the "show sorts" output, removing anything that
   483   starts with a left parenthesis.*)
   484 fun remove_type str = hd (String.fields (fn c => c = #"(") str);
   485 
   486 fun pred_of_sort (LTVar x) = ((remove_type x),1)
   487 |   pred_of_sort (LTFree x) = ((remove_type x),1)
   488 
   489 
   490 
   491 
   492 (*Given a list of sorted type variables, return two separate lists.
   493   The first is for TVars, the second for TFrees.*)
   494 fun add_typs_aux [] preds  = ([],[], preds)
   495   | add_typs_aux ((FOLTVar indx,s)::tss) preds = 
   496       let val vs = sorts_on_typs (FOLTVar indx, s)
   497           val preds' = (map pred_of_sort vs)@preds
   498 	  val (vss,fss, preds'') = add_typs_aux tss preds'
   499       in
   500 	  (vs union vss, fss, preds'')
   501       end
   502   | add_typs_aux ((FOLTFree x,s)::tss) preds  =
   503       let val fs = sorts_on_typs (FOLTFree x, s)
   504           val preds' = (map pred_of_sort fs)@preds
   505 	  val (vss,fss, preds'') = add_typs_aux tss preds'
   506       in
   507 	  (vss, fs union fss, preds'')
   508       end;
   509 
   510 fun add_typs_aux2 [] = ([],[])
   511   | add_typs_aux2 ((FOLTVar indx,s)::tss) =
   512     let val vs = sorts_on_typs (FOLTVar indx,s)
   513 	val (vss,fss) = add_typs_aux2 tss
   514     in
   515 	(vs union vss,fss)
   516     end
   517   | add_typs_aux2 ((FOLTFree x,s)::tss) =
   518     let val fs = sorts_on_typs (FOLTFree x,s)
   519 	val (vss,fss) = add_typs_aux2 tss
   520     in
   521 	(vss,fs union fss)
   522     end;
   523 
   524 
   525 fun add_typs (Clause cls) preds  = add_typs_aux (#types_sorts cls) preds 
   526 
   527 
   528 (** make axiom clauses, hypothesis clauses and conjecture clauses. **)
   529 
   530 fun get_tvar_strs [] = []
   531   | get_tvar_strs ((FOLTVar indx,s)::tss) = 
   532       let val vstr = make_schematic_type_var indx
   533       in
   534 	  vstr ins (get_tvar_strs tss)
   535       end
   536   | get_tvar_strs((FOLTFree x,s)::tss) = distinct (get_tvar_strs tss)
   537 
   538 (* FIX add preds and funcs to add typs aux here *)
   539 
   540 fun make_axiom_clause_thm thm (ax_name,cls_id) =
   541     let val (lits,types_sorts, preds, funcs) = literals_of_term (prop_of thm)
   542 	val (tvar_lits,tfree_lits, preds) = add_typs_aux types_sorts preds 
   543         val tvars = get_tvar_strs types_sorts
   544     in 
   545 	make_clause(cls_id,ax_name,Axiom,
   546 	            lits,types_sorts,tvar_lits,tfree_lits,
   547 	            tvars, preds, funcs)
   548     end;
   549 
   550 
   551 
   552 fun make_conjecture_clause n t =
   553     let val (lits,types_sorts, preds, funcs) = literals_of_term t
   554 	val (tvar_lits,tfree_lits, preds) = add_typs_aux types_sorts preds 
   555         val tvars = get_tvar_strs types_sorts
   556     in
   557 	make_clause(n,"conjecture",Conjecture,
   558 	            lits,types_sorts,tvar_lits,tfree_lits,
   559 	            tvars, preds, funcs)
   560     end;
   561     
   562 fun make_conjecture_clauses_aux _ [] = []
   563   | make_conjecture_clauses_aux n (t::ts) =
   564       make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts
   565 
   566 val make_conjecture_clauses = make_conjecture_clauses_aux 0
   567 
   568 
   569 fun make_axiom_clause term (ax_name,cls_id) =
   570     let val (lits,types_sorts, preds,funcs) = literals_of_term term
   571 	val (tvar_lits,tfree_lits, preds) = add_typs_aux types_sorts preds
   572         val tvars = get_tvar_strs types_sorts	
   573     in 
   574 	make_clause(cls_id,ax_name,Axiom,
   575 	            lits,types_sorts,tvar_lits,tfree_lits,
   576 	            tvars, preds,funcs)
   577     end;
   578 
   579 
   580 
   581  
   582 (**** Isabelle arities ****)
   583 
   584 exception ARCLAUSE of string;
   585  
   586 
   587 type class = string; 
   588 type tcons = string; 
   589 
   590 
   591 datatype arLit = TConsLit of bool * (class * tcons * string list) | TVarLit of bool * (class * string);
   592  
   593 datatype arityClause =  
   594 	 ArityClause of {clause_id: clause_id,
   595 	  	         axiom_name: axiom_name,
   596 			 kind: kind,
   597 			 conclLit: arLit,
   598 			 premLits: arLit list};
   599 
   600 
   601 fun get_TVars 0 = []
   602   | get_TVars n = ("T_" ^ (Int.toString n)) :: get_TVars (n-1);
   603 
   604 
   605 
   606 fun pack_sort(_,[])  = raise ARCLAUSE("Empty Sort Found") 
   607   | pack_sort(tvar, [cls]) = [(make_type_class cls, tvar)] 
   608   | pack_sort(tvar, cls::srt) =  (make_type_class cls,tvar) :: (pack_sort(tvar, srt));
   609     
   610     
   611 fun make_TVarLit (b,(cls,str)) = TVarLit(b,(cls,str));
   612 fun make_TConsLit (b,(cls,tcons,tvars)) = TConsLit(b,(make_type_class cls,make_fixed_type_const tcons,tvars));
   613 
   614 fun make_axiom_arity_clause (tcons,n,(res,args)) =
   615    let val nargs = length args
   616        val tvars = get_TVars nargs
   617        val tvars_srts = ListPair.zip (tvars,args)
   618        val tvars_srts' = union_all(map pack_sort tvars_srts)
   619        val false_tvars_srts' = map (pair false) tvars_srts'
   620    in
   621       ArityClause {clause_id = n, kind = Axiom, 
   622                    axiom_name = tcons,
   623                    conclLit = make_TConsLit(true,(res,tcons,tvars)), 
   624                    premLits = map make_TVarLit false_tvars_srts'}
   625    end;
   626     
   627 (*The number of clauses generated from cls, including type clauses*)
   628 fun num_of_clauses (Clause cls) =
   629     let val num_tfree_lits = 
   630 	      if !keep_types then length (#tfree_type_literals cls)
   631 	      else 0
   632     in 	1 + num_tfree_lits  end;
   633 
   634 
   635 (**** Isabelle class relations ****)
   636 
   637 
   638 datatype classrelClause = 
   639 	 ClassrelClause of {clause_id: clause_id,
   640 			    subclass: class,
   641 			    superclass: class option};
   642 
   643 
   644 fun make_axiom_classrelClause n subclass superclass =
   645   ClassrelClause {clause_id = n,
   646                   subclass = subclass, superclass = superclass};
   647 
   648 
   649 fun classrelClauses_of_aux n sub [] = []
   650   | classrelClauses_of_aux n sub (sup::sups) =
   651       make_axiom_classrelClause n sub (SOME sup) :: classrelClauses_of_aux (n+1) sub sups;
   652 
   653 
   654 fun classrelClauses_of (sub,sups) = 
   655     case sups of [] => [make_axiom_classrelClause 0 sub NONE]
   656 	       | _ => classrelClauses_of_aux 0 sub sups;
   657 
   658 
   659 (***** Isabelle arities *****)
   660 
   661 
   662 fun arity_clause _ (tcons, []) = []
   663   | arity_clause n (tcons, ar::ars) =
   664       make_axiom_arity_clause (tcons,n,ar) :: 
   665       arity_clause (n+1) (tcons,ars);
   666 
   667 fun multi_arity_clause [] = []
   668   | multi_arity_clause (tcon_ar :: tcons_ars)  =
   669       arity_clause 0 tcon_ar  @  multi_arity_clause tcons_ars 
   670 
   671 fun arity_clause_thy thy =
   672   let val arities = #arities (Type.rep_tsig (Sign.tsig_of thy))
   673   in multi_arity_clause (Symtab.dest arities) end;
   674 
   675 
   676 (* Isabelle classes *)
   677 
   678 type classrelClauses = classrelClause list Symtab.table;
   679 
   680 val classrel_of = #2 o #classes o Type.rep_tsig o Sign.tsig_of;
   681 fun classrel_clauses_classrel (C: Sorts.classes) = map classrelClauses_of (Graph.dest C);
   682 val classrel_clauses_thy = List.concat o classrel_clauses_classrel o classrel_of;
   683 
   684 
   685 
   686 (****!!!! Changed for typed equality !!!!****)
   687 
   688 fun wrap_eq_type typ t = eq_typ_wrapper ^"(" ^ t ^ "," ^ typ ^ ")";
   689 
   690 (* Only need to wrap equality's arguments with "typeinfo" if the output clauses are typed && if we specifically ask for types to be included.   *)
   691 fun string_of_equality (typ,terms) =
   692       let val [tstr1,tstr2] = map string_of_term terms
   693       in
   694 	  if !keep_types andalso !special_equal 
   695 	  then "equal(" ^ (wrap_eq_type typ tstr1) ^ "," ^ 
   696 		 	  (wrap_eq_type typ tstr2) ^ ")"
   697 	  else "equal(" ^ tstr1 ^ "," ^ tstr2 ^ ")"
   698       end
   699 and string_of_term (UVar(x,_)) = x
   700   | string_of_term (Fun("equal",typ,terms)) = string_of_equality(typ,terms)
   701   | string_of_term (Fun (name,typ,[])) = name
   702   | string_of_term (Fun (name,typ,terms)) = 
   703       let val terms' = map string_of_term terms
   704       in
   705 	  if !keep_types andalso typ<>"" 
   706 	  then name ^ (paren_pack (terms' @ [typ]))
   707 	  else name ^ (paren_pack terms')
   708       end;
   709 
   710 (* before output the string of the predicate, check if the predicate corresponds to an equality or not. *)
   711 fun string_of_predicate (Predicate("equal",typ,terms)) = 
   712       string_of_equality(typ,terms)
   713   | string_of_predicate (Predicate(name,_,[])) = name 
   714   | string_of_predicate (Predicate(name,typ,terms)) = 
   715       let val terms_as_strings = map string_of_term terms
   716       in
   717 	  if !keep_types andalso typ<>""
   718 	  then name ^ (paren_pack (terms_as_strings @ [typ]))
   719 	  else name ^ (paren_pack terms_as_strings) 
   720       end;
   721 
   722 
   723 fun string_of_clausename (cls_id,ax_name) = 
   724     clause_prefix ^ ascii_of ax_name ^ "_" ^ Int.toString cls_id;
   725 
   726 fun string_of_type_clsname (cls_id,ax_name,idx) = 
   727     string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
   728     
   729 
   730 (********************************)
   731 (* Code for producing DFG files *)
   732 (********************************)
   733 
   734 fun dfg_literal (Literal(pol,pred,tag)) =
   735     let val pred_string = string_of_predicate pred
   736     in
   737 	if pol then pred_string else "not(" ^pred_string ^ ")"  
   738     end;
   739 
   740 
   741 (* FIX: what does this mean? *)
   742 (*fun dfg_of_typeLit (LTVar x) = "not(" ^ x ^ ")"
   743   | dfg_of_typeLit (LTFree x) = "(" ^ x ^ ")";*)
   744 
   745 fun dfg_of_typeLit (LTVar x) =  x 
   746   | dfg_of_typeLit (LTFree x) = x ;
   747  
   748 (*Make the string of universal quantifiers for a clause*)
   749 fun forall_open ([],[]) = ""
   750   | forall_open (vars,tvars) = "forall([" ^ (commas (tvars@vars))^ "],\n"
   751 
   752 fun forall_close ([],[]) = ""
   753   | forall_close (vars,tvars) = ")"
   754 
   755 fun gen_dfg_cls (cls_id,ax_name,knd,lits,tvars,vars) = 
   756     "clause( %(" ^ knd ^ ")\n" ^ forall_open(vars,tvars) ^ 
   757     "or(" ^ lits ^ ")" ^ forall_close(vars,tvars) ^ ",\n" ^ 
   758     string_of_clausename (cls_id,ax_name) ^  ").";
   759 
   760 fun gen_dfg_type_cls (cls_id,ax_name,knd,tfree_lit,idx,tvars,vars) = 
   761     "clause( %(" ^ knd ^ ")\n" ^ forall_open(vars,tvars) ^ 
   762     "or( " ^ tfree_lit ^ ")" ^ forall_close(vars,tvars) ^ ",\n" ^ 
   763     string_of_type_clsname (cls_id,ax_name,idx) ^  ").";
   764 
   765 fun dfg_clause_aux (Clause cls) = 
   766   let val lits = map dfg_literal (#literals cls)
   767       val tvar_lits_strs = 
   768 	  if !keep_types then map dfg_of_typeLit (#tvar_type_literals cls) 
   769 	  else []
   770       val tfree_lits =
   771           if !keep_types then map dfg_of_typeLit (#tfree_type_literals cls)
   772           else []
   773   in
   774       (tvar_lits_strs @ lits, tfree_lits)
   775   end; 
   776 
   777 
   778 fun dfg_folterms (Literal(pol,pred,tag)) = 
   779   let val Predicate (predname, foltype, folterms) = pred
   780   in
   781       folterms
   782   end
   783 
   784  
   785 fun get_uvars (UVar(a,typ)) = [a] 
   786 |   get_uvars (Fun (_,typ,tlist)) = union_all(map get_uvars tlist)
   787 
   788 
   789 fun is_uvar (UVar _) = true
   790 |   is_uvar (Fun _) = false;
   791 
   792 fun uvar_name (UVar(a,_)) = a
   793 |   uvar_name (Fun (a,_,_)) = raise CLAUSE("Not a variable", Const(a,dummyT));
   794 
   795 fun mergelist [] = []
   796 |   mergelist (x::xs) = x @ mergelist xs
   797 
   798 fun dfg_vars (Clause cls) =
   799     let val lits = #literals cls
   800         val folterms = mergelist(map dfg_folterms lits)
   801     in 
   802         union_all(map get_uvars folterms)
   803     end
   804 
   805 
   806 fun dfg_tvars (Clause cls) =(#tvars cls)
   807 
   808 
   809 	
   810 (* make this return funcs and preds too? *)
   811 fun string_of_predname (Predicate("equal",typ,terms)) = "EQUALITY"
   812   | string_of_predname (Predicate(name,_,[])) = name 
   813   | string_of_predname (Predicate(name,typ,terms)) = name
   814     
   815 	
   816 (* make this return funcs and preds too? *)
   817 
   818 fun string_of_predicate (Predicate("equal",typ,terms)) =  
   819       string_of_equality(typ,terms)
   820   | string_of_predicate (Predicate(name,_,[])) = name 
   821   | string_of_predicate (Predicate(name,typ,terms)) = 
   822       let val terms_as_strings = map string_of_term terms
   823       in
   824 	  if !keep_types andalso typ<>""
   825 	  then name ^ (paren_pack  (terms_as_strings @ [typ]))
   826 	  else name ^ (paren_pack terms_as_strings) 
   827       end;
   828 
   829 
   830 fun concat_with sep []  = ""
   831   | concat_with sep [x] = "(" ^ x ^ ")"
   832   | concat_with sep (x::xs) = "(" ^ x ^ ")" ^  sep ^ (concat_with sep xs);
   833 
   834 fun dfg_pred (Literal(pol,pred,tag)) ax_name = 
   835     (string_of_predname pred) ^ " " ^ ax_name
   836 
   837 fun dfg_clause cls =
   838     let val (lits,tfree_lits) = dfg_clause_aux cls 
   839              (*"lits" includes the typing assumptions (TVars)*)
   840         val vars = dfg_vars cls
   841         val tvars = dfg_tvars cls
   842 	val knd = string_of_kind cls
   843 	val lits_str = commas lits
   844 	val cls_id = get_clause_id cls
   845 	val axname = get_axiomName cls
   846 	val cls_str = gen_dfg_cls(cls_id,axname,knd,lits_str,tvars, vars) 			
   847         fun typ_clss k [] = []
   848           | typ_clss k (tfree :: tfrees) = 
   849               (gen_dfg_type_cls(cls_id,axname,knd,tfree,k, tvars,vars)) :: 
   850               (typ_clss (k+1) tfrees)
   851     in 
   852 	cls_str :: (typ_clss 0 tfree_lits)
   853     end;
   854 
   855 fun string_of_arity (name, num) =  name ^ "," ^ (Int.toString num) 
   856 
   857 fun string_of_preds preds = 
   858   "predicates[" ^ (concat_with ", " (map string_of_arity preds)) ^ "].\n";
   859 
   860 fun string_of_funcs funcs =
   861   "functions[" ^ (concat_with ", " (map string_of_arity funcs)) ^ "].\n" ;
   862 
   863 
   864 fun string_of_symbols predstr funcstr = 
   865   "list_of_symbols.\n" ^ predstr  ^ funcstr  ^ "end_of_list.\n\n";
   866 
   867 
   868 fun string_of_axioms axstr = 
   869   "list_of_clauses(axioms,cnf).\n" ^ axstr ^ "end_of_list.\n\n";
   870 
   871 
   872 fun string_of_conjectures conjstr = 
   873   "list_of_clauses(conjectures,cnf).\n" ^ conjstr ^ "end_of_list.\n\n";
   874 
   875 fun string_of_descrip () = 
   876   "list_of_descriptions.\nname({*[ File     : ],[ Names    :]*}).\nauthor({*[ Source   :]*}).\nstatus(unknown).\ndescription({*[ Refs     :]*}).\nend_of_list.\n\n"
   877 
   878 
   879 fun string_of_start name = "%------------------------------------------------------------------------------\nbegin_problem(" ^ name ^ ").\n\n";
   880 
   881 
   882 fun string_of_end () = "end_problem.\n%------------------------------------------------------------------------------";
   883 
   884 
   885 fun clause2dfg cls =
   886     let val (lits,tfree_lits) = dfg_clause_aux cls 
   887             (*"lits" includes the typing assumptions (TVars)*)
   888 	val cls_id = get_clause_id cls
   889 	val ax_name = get_axiomName cls
   890         val vars = dfg_vars cls
   891         val tvars = dfg_tvars cls
   892         val funcs = funcs_of_cls cls
   893         val preds = preds_of_cls cls
   894 	val knd = string_of_kind cls
   895 	val lits_str = commas lits
   896 	val cls_str = gen_dfg_cls(cls_id,ax_name,knd,lits_str,tvars,vars) 
   897     in
   898 	(cls_str,tfree_lits) 
   899     end;
   900 
   901 
   902 
   903 fun tfree_dfg_clause tfree_lit =
   904   "clause( %(conjecture)\n" ^ "or( " ^ tfree_lit ^ "),\n" ^ "tfree_tcs" ^ ")."
   905 
   906 
   907 fun gen_dfg_file probname axioms conjectures funcs preds = 
   908     let val axstrs_tfrees = (map clause2dfg axioms)
   909 	val (axstrs, atfrees) = ListPair.unzip axstrs_tfrees
   910         val axstr = (space_implode "\n" axstrs) ^ "\n\n"
   911         val conjstrs_tfrees = (map clause2dfg conjectures)
   912 	val (conjstrs, atfrees) = ListPair.unzip conjstrs_tfrees
   913         val tfree_clss = map tfree_dfg_clause (union_all atfrees) 
   914         val conjstr = (space_implode "\n" (tfree_clss@conjstrs)) ^ "\n\n"
   915         val funcstr = string_of_funcs funcs
   916         val predstr = string_of_preds preds
   917     in
   918        (string_of_start probname) ^ (string_of_descrip ()) ^ 
   919        (string_of_symbols funcstr predstr) ^  
   920        (string_of_axioms axstr) ^
   921        (string_of_conjectures conjstr) ^ (string_of_end ())
   922     end;
   923    
   924 fun clauses2dfg [] probname axioms conjectures funcs preds = 
   925       let val funcs' = (union_all(map funcs_of_cls axioms)) @ funcs
   926 	  val preds' = (union_all(map preds_of_cls axioms)) @ preds
   927       in
   928 	 gen_dfg_file probname axioms conjectures funcs' preds' 
   929       end
   930  | clauses2dfg (cls::clss) probname axioms conjectures funcs preds = 
   931      let val (lits,tfree_lits) = dfg_clause_aux cls
   932 	       (*"lits" includes the typing assumptions (TVars)*)
   933 	 val cls_id = get_clause_id cls
   934 	 val ax_name = get_axiomName cls
   935 	 val vars = dfg_vars cls
   936 	 val tvars = dfg_tvars cls
   937 	 val funcs' = (funcs_of_cls cls) union funcs
   938 	 val preds' = (preds_of_cls cls) union preds
   939 	 val knd = string_of_kind cls
   940 	 val lits_str = concat_with ", " lits
   941 	 val axioms' = if knd = "axiom" then (cls::axioms) else axioms
   942 	 val conjectures' = 
   943 	     if knd = "conjecture" then (cls::conjectures) else conjectures
   944      in
   945 	 clauses2dfg clss probname axioms' conjectures' funcs' preds' 
   946      end;
   947 
   948 
   949 fun string_of_arClauseID (ArityClause {clause_id,axiom_name,...}) =
   950     arclause_prefix ^ ascii_of axiom_name ^ "_" ^ Int.toString clause_id;
   951 
   952 fun string_of_arKind (ArityClause arcls) = name_of_kind(#kind arcls);
   953 
   954 (*FIXME!!! currently is TPTP format!*)
   955 fun dfg_of_arLit (TConsLit(b,(c,t,args))) =
   956       let val pol = if b then "++" else "--"
   957 	  val arg_strs = (case args of [] => "" | _ => paren_pack args)
   958       in 
   959 	  pol ^ c ^ "(" ^ t ^ arg_strs ^ ")"
   960       end
   961   | dfg_of_arLit (TVarLit(b,(c,str))) =
   962       let val pol = if b then "++" else "--"
   963       in
   964 	  pol ^ c ^ "(" ^ str ^ ")"
   965       end;
   966     
   967 
   968 fun dfg_of_conclLit (ArityClause arcls) = dfg_of_arLit (#conclLit arcls);
   969      
   970 
   971 fun dfg_of_premLits (ArityClause arcls) = map dfg_of_arLit (#premLits arcls);
   972 		
   973 
   974 
   975 (*FIXME: would this have variables in a forall? *)
   976 
   977 fun dfg_arity_clause arcls = 
   978   let val arcls_id = string_of_arClauseID arcls
   979       val concl_lit = dfg_of_conclLit arcls
   980       val prems_lits = dfg_of_premLits arcls
   981       val knd = string_of_arKind arcls
   982       val all_lits = concl_lit :: prems_lits
   983   in
   984       "clause( %(" ^ knd ^ ")\n" ^  "or( " ^ (bracket_pack all_lits) ^ ")),\n" ^
   985        arcls_id ^  ")."
   986   end;
   987 
   988 
   989 (********************************)
   990 (* code to produce TPTP files   *)
   991 (********************************)
   992 
   993 fun tptp_literal (Literal(pol,pred,tag)) =
   994     let val pred_string = string_of_predicate pred
   995 	val tagged_pol = 
   996 	      if (tag andalso !tagged) then (if pol then "+++" else "---")
   997 	      else (if pol then "++" else "--")
   998      in
   999 	tagged_pol ^ pred_string
  1000     end;
  1001 
  1002 
  1003 
  1004 fun tptp_of_typeLit (LTVar x) = "--" ^ x
  1005   | tptp_of_typeLit (LTFree x) = "++" ^ x;
  1006  
  1007 
  1008 fun gen_tptp_cls (cls_id,ax_name,knd,lits) = 
  1009     "input_clause(" ^ string_of_clausename (cls_id,ax_name) ^ "," ^ 
  1010     knd ^ "," ^ lits ^ ").";
  1011 
  1012 fun gen_tptp_type_cls (cls_id,ax_name,knd,tfree_lit,idx) = 
  1013     "input_clause(" ^ string_of_type_clsname (cls_id,ax_name,idx) ^ "," ^ 
  1014     knd ^ ",[" ^ tfree_lit ^ "]).";
  1015 
  1016 fun tptp_type_lits (Clause cls) = 
  1017     let val lits = map tptp_literal (#literals cls)
  1018 	val tvar_lits_strs =
  1019 	      if !keep_types 
  1020 	      then (map tptp_of_typeLit (#tvar_type_literals cls)) 
  1021 	      else []
  1022 	val tfree_lits = 
  1023 	      if !keep_types
  1024 	      then (map tptp_of_typeLit (#tfree_type_literals cls)) 
  1025 	      else []
  1026     in
  1027 	(tvar_lits_strs @ lits, tfree_lits)
  1028     end; 
  1029 
  1030 fun tptp_clause cls =
  1031     let val (lits,tfree_lits) = tptp_type_lits cls 
  1032             (*"lits" includes the typing assumptions (TVars)*)
  1033 	val cls_id = get_clause_id cls
  1034 	val ax_name = get_axiomName cls
  1035 	val knd = string_of_kind cls
  1036 	val lits_str = bracket_pack lits
  1037 	val cls_str = gen_tptp_cls(cls_id,ax_name,knd,lits_str) 			 
  1038 	fun typ_clss k [] = []
  1039           | typ_clss k (tfree :: tfrees) = 
  1040               gen_tptp_type_cls(cls_id,ax_name,knd,tfree,k) :: 
  1041               typ_clss (k+1) tfrees
  1042     in 
  1043 	cls_str :: (typ_clss 0 tfree_lits)
  1044     end;
  1045 
  1046 fun clause2tptp cls =
  1047     let val (lits,tfree_lits) = tptp_type_lits cls 
  1048             (*"lits" includes the typing assumptions (TVars)*)
  1049 	val cls_id = get_clause_id cls
  1050 	val ax_name = get_axiomName cls
  1051 	val knd = string_of_kind cls
  1052 	val lits_str = bracket_pack lits
  1053 	val cls_str = gen_tptp_cls(cls_id,ax_name,knd,lits_str) 
  1054     in
  1055 	(cls_str,tfree_lits) 
  1056     end;
  1057 
  1058 
  1059 fun tfree_clause tfree_lit =
  1060     "input_clause(" ^ "tfree_tcs," ^ "conjecture" ^ ",[" ^ tfree_lit ^ "]).";
  1061 
  1062 
  1063 fun tptp_of_arLit (TConsLit(b,(c,t,args))) =
  1064       let val pol = if b then "++" else "--"
  1065 	  val  arg_strs = (case args of [] => "" | _ => paren_pack args)
  1066       in 
  1067 	  pol ^ c ^ "(" ^ t ^ arg_strs ^ ")"
  1068       end
  1069   | tptp_of_arLit (TVarLit(b,(c,str))) =
  1070       let val pol = if b then "++" else "--"
  1071       in
  1072 	  pol ^ c ^ "(" ^ str ^ ")"
  1073       end;
  1074     
  1075 
  1076 fun tptp_of_conclLit (ArityClause arcls) = tptp_of_arLit (#conclLit arcls);
  1077      
  1078 fun tptp_of_premLits (ArityClause arcls) = map tptp_of_arLit (#premLits arcls);
  1079 		
  1080 fun tptp_arity_clause arcls = 
  1081     let val arcls_id = string_of_arClauseID arcls
  1082 	val concl_lit = tptp_of_conclLit arcls
  1083 	val prems_lits = tptp_of_premLits arcls
  1084 	val knd = string_of_arKind arcls
  1085 	val all_lits = concl_lit :: prems_lits
  1086     in
  1087 	"input_clause(" ^ arcls_id ^ "," ^ knd ^ "," ^ 
  1088 	(bracket_pack all_lits) ^ ")."
  1089     end;
  1090 
  1091 fun tptp_classrelLits sub sup = 
  1092     let val tvar = "(T)"
  1093     in 
  1094 	case sup of NONE => "[++" ^ sub ^ tvar ^ "]"
  1095 		  | (SOME supcls) =>  "[--" ^ sub ^ tvar ^ ",++" ^ supcls ^ tvar ^ "]"
  1096     end;
  1097 
  1098 
  1099 fun tptp_classrelClause (ClassrelClause {clause_id,subclass,superclass,...}) =
  1100     let val relcls_id = clrelclause_prefix ^ ascii_of subclass ^ "_" ^ 
  1101                         Int.toString clause_id
  1102 	val lits = tptp_classrelLits (make_type_class subclass) 
  1103 	                (Option.map make_type_class superclass)
  1104     in
  1105 	"input_clause(" ^ relcls_id ^ ",axiom," ^ lits ^ ")."
  1106     end; 
  1107 
  1108 
  1109 
  1110 end;