src/HOL/Tools/Sledgehammer/metis_clauses.ML
author blanchet
Tue Jun 29 10:25:53 2010 +0200 (2010-06-29)
changeset 37626 1146291fe718
parent 37625 35eeb95c5bee
child 37632 df12f798df99
permissions -rw-r--r--
move blacklisting completely out of the clausifier;
the only reason it was in the clausifier as well was the Skolem cache
     1 (*  Title:      HOL/Tools/Sledgehammer/metis_clauses.ML
     2     Author:     Jia Meng, Cambridge University Computer Laboratory
     3     Author:     Jasmin Blanchette, TU Muenchen
     4 
     5 Storing/printing FOL clauses and arity clauses.  Typed equality is
     6 treated differently.
     7 *)
     8 
     9 signature METIS_CLAUSES =
    10 sig
    11   type name = string * string
    12   datatype kind = Axiom | Conjecture
    13   datatype type_literal =
    14     TyLitVar of string * name |
    15     TyLitFree of string * name
    16   datatype arLit =
    17       TConsLit of class * string * string list
    18     | TVarLit of class * string
    19   datatype arity_clause = ArityClause of
    20    {axiom_name: string, conclLit: arLit, premLits: arLit list}
    21   datatype classrel_clause = ClassrelClause of
    22    {axiom_name: string, subclass: class, superclass: class}
    23   datatype combtyp =
    24     TyVar of name |
    25     TyFree of name |
    26     TyConstr of name * combtyp list
    27   datatype combterm =
    28     CombConst of name * combtyp * combtyp list (* Const and Free *) |
    29     CombVar of name * combtyp |
    30     CombApp of combterm * combterm
    31   datatype literal = Literal of bool * combterm
    32   datatype hol_clause =
    33     HOLClause of {clause_id: int, axiom_name: string, th: thm, kind: kind,
    34                   literals: literal list, ctypes_sorts: typ list}
    35 
    36   val type_wrapper_name : string
    37   val schematic_var_prefix: string
    38   val fixed_var_prefix: string
    39   val tvar_prefix: string
    40   val tfree_prefix: string
    41   val const_prefix: string
    42   val tconst_prefix: string
    43   val class_prefix: string
    44   val union_all: ''a list list -> ''a list
    45   val invert_const: string -> string
    46   val ascii_of: string -> string
    47   val undo_ascii_of: string -> string
    48   val strip_prefix: string -> string -> string option
    49   val make_schematic_var : string * int -> string
    50   val make_fixed_var : string -> string
    51   val make_schematic_type_var : string * int -> string
    52   val make_fixed_type_var : string -> string
    53   val make_fixed_const : string -> string
    54   val make_fixed_type_const : string -> string
    55   val make_type_class : string -> string
    56   val skolem_theory_name: string
    57   val skolem_prefix: string
    58   val skolem_infix: string
    59   val is_skolem_const_name: string -> bool
    60   val num_type_args: theory -> string -> int
    61   val type_literals_for_types : typ list -> type_literal list
    62   val make_classrel_clauses: theory -> class list -> class list -> classrel_clause list
    63   val make_arity_clauses: theory -> string list -> class list -> class list * arity_clause list
    64   val type_of_combterm : combterm -> combtyp
    65   val strip_combterm_comb : combterm -> combterm * combterm list
    66   val literals_of_term : theory -> term -> literal list * typ list
    67   val conceal_skolem_terms :
    68     int -> (string * term) list -> term -> (string * term) list * term
    69   val tfree_classes_of_terms : term list -> string list
    70   val tvar_classes_of_terms : term list -> string list
    71   val type_consts_of_terms : theory -> term list -> string list
    72 end
    73 
    74 structure Metis_Clauses : METIS_CLAUSES =
    75 struct
    76 
    77 open Clausifier
    78 
    79 val type_wrapper_name = "ti"
    80 
    81 val schematic_var_prefix = "V_";
    82 val fixed_var_prefix = "v_";
    83 
    84 val tvar_prefix = "T_";
    85 val tfree_prefix = "t_";
    86 
    87 val classrel_clause_prefix = "clsrel_";
    88 
    89 val const_prefix = "c_";
    90 val tconst_prefix = "tc_";
    91 val class_prefix = "class_";
    92 
    93 fun union_all xss = fold (union (op =)) xss []
    94 
    95 (* Readable names for the more common symbolic functions. Do not mess with the
    96    last nine entries of the table unless you know what you are doing. *)
    97 val const_trans_table =
    98   Symtab.make [(@{const_name "op ="}, "equal"),
    99                (@{const_name "op &"}, "and"),
   100                (@{const_name "op |"}, "or"),
   101                (@{const_name "op -->"}, "implies"),
   102                (@{const_name "op :"}, "in"),
   103                (@{const_name fequal}, "fequal"),
   104                (@{const_name COMBI}, "COMBI"),
   105                (@{const_name COMBK}, "COMBK"),
   106                (@{const_name COMBB}, "COMBB"),
   107                (@{const_name COMBC}, "COMBC"),
   108                (@{const_name COMBS}, "COMBS"),
   109                (@{const_name True}, "True"),
   110                (@{const_name False}, "False"),
   111                (@{const_name If}, "If"),
   112                (@{type_name "*"}, "prod"),
   113                (@{type_name "+"}, "sum")]
   114 
   115 (* Invert the table of translations between Isabelle and ATPs. *)
   116 val const_trans_table_inv =
   117   Symtab.update ("fequal", @{const_name "op ="})
   118                 (Symtab.make (map swap (Symtab.dest const_trans_table)))
   119 
   120 val invert_const = perhaps (Symtab.lookup const_trans_table_inv)
   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 val A_minus_space = Char.ord #"A" - Char.ord #" ";
   128 
   129 fun stringN_of_int 0 _ = ""
   130   | stringN_of_int k n = stringN_of_int (k-1) (n div 10) ^ Int.toString (n mod 10);
   131 
   132 fun ascii_of_c c =
   133   if Char.isAlphaNum c then String.str c
   134   else if c = #"_" then "__"
   135   else if #" " <= c andalso c <= #"/"
   136        then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space))
   137   else if Char.isPrint c
   138        then ("_" ^ stringN_of_int 3 (Char.ord c))  (*fixed width, in case more digits follow*)
   139   else ""
   140 
   141 val ascii_of = String.translate ascii_of_c;
   142 
   143 (** Remove ASCII armouring from names in proof files **)
   144 
   145 (*We don't raise error exceptions because this code can run inside the watcher.
   146   Also, the errors are "impossible" (hah!)*)
   147 fun undo_ascii_aux rcs [] = String.implode(rev rcs)
   148   | undo_ascii_aux rcs [#"_"] = undo_ascii_aux (#"_"::rcs) []  (*ERROR*)
   149       (*Three types of _ escapes: __, _A to _P, _nnn*)
   150   | undo_ascii_aux rcs (#"_" :: #"_" :: cs) = undo_ascii_aux (#"_"::rcs) cs
   151   | undo_ascii_aux rcs (#"_" :: c :: cs) =
   152       if #"A" <= c andalso c<= #"P"  (*translation of #" " to #"/"*)
   153       then undo_ascii_aux (Char.chr(Char.ord c - A_minus_space) :: rcs) cs
   154       else
   155         let val digits = List.take (c::cs, 3) handle Subscript => []
   156         in
   157             case Int.fromString (String.implode digits) of
   158                 NONE => undo_ascii_aux (c:: #"_"::rcs) cs  (*ERROR*)
   159               | SOME n => undo_ascii_aux (Char.chr n :: rcs) (List.drop (cs, 2))
   160         end
   161   | undo_ascii_aux rcs (c::cs) = undo_ascii_aux (c::rcs) cs;
   162 
   163 val undo_ascii_of = undo_ascii_aux [] o String.explode;
   164 
   165 (* If string s has the prefix s1, return the result of deleting it,
   166    un-ASCII'd. *)
   167 fun strip_prefix s1 s =
   168   if String.isPrefix s1 s then
   169     SOME (undo_ascii_of (String.extract (s, size s1, NONE)))
   170   else
   171     NONE
   172 
   173 (*Remove the initial ' character from a type variable, if it is present*)
   174 fun trim_type_var s =
   175   if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE)
   176   else error ("trim_type: Malformed type variable encountered: " ^ s);
   177 
   178 fun ascii_of_indexname (v,0) = ascii_of v
   179   | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i;
   180 
   181 fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v);
   182 fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x);
   183 
   184 fun make_schematic_type_var (x,i) =
   185       tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i));
   186 fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x));
   187 
   188 fun lookup_const c =
   189   case Symtab.lookup const_trans_table c of
   190     SOME c' => c'
   191   | NONE => ascii_of c
   192 
   193 (* "op =" MUST BE "equal" because it's built into ATPs. *)
   194 fun make_fixed_const @{const_name "op ="} = "equal"
   195   | make_fixed_const c = const_prefix ^ lookup_const c
   196 
   197 fun make_fixed_type_const c = tconst_prefix ^ lookup_const c
   198 
   199 fun make_type_class clas = class_prefix ^ ascii_of clas;
   200 
   201 val skolem_theory_name = "Sledgehammer" ^ Long_Name.separator ^ "Sko"
   202 val skolem_prefix = "sko_"
   203 val skolem_infix = "$"
   204 
   205 (* Hack: Could return false positives (e.g., a user happens to declare a
   206    constant called "SomeTheory.sko_means_shoe_in_$wedish". *)
   207 val is_skolem_const_name =
   208   Long_Name.base_name
   209   #> String.isPrefix skolem_prefix andf String.isSubstring skolem_infix
   210 
   211 (* The number of type arguments of a constant, zero if it's monomorphic. For
   212    (instances of) Skolem pseudoconstants, this information is encoded in the
   213    constant name. *)
   214 fun num_type_args thy s =
   215   if String.isPrefix skolem_theory_name s then
   216     s |> unprefix skolem_theory_name
   217       |> space_explode skolem_infix |> hd
   218       |> space_explode "_" |> List.last |> Int.fromString |> the
   219   else
   220     (s, Sign.the_const_type thy s) |> Sign.const_typargs thy |> length
   221 
   222 (**** Definitions and functions for FOL clauses for TPTP format output ****)
   223 
   224 type name = string * string
   225 
   226 datatype kind = Axiom | Conjecture
   227 
   228 (**** Isabelle FOL clauses ****)
   229 
   230 (* The first component is the type class; the second is a TVar or TFree. *)
   231 datatype type_literal =
   232   TyLitVar of string * name |
   233   TyLitFree of string * name
   234 
   235 exception CLAUSE of string * term;
   236 
   237 (*Make literals for sorted type variables*)
   238 fun sorts_on_typs_aux (_, [])   = []
   239   | sorts_on_typs_aux ((x,i),  s::ss) =
   240       let val sorts = sorts_on_typs_aux ((x,i), ss)
   241       in
   242           if s = "HOL.type" then sorts
   243           else if i = ~1 then TyLitFree (make_type_class s, `make_fixed_type_var x) :: sorts
   244           else TyLitVar (make_type_class s, (make_schematic_type_var (x,i), x)) :: sorts
   245       end;
   246 
   247 fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s)
   248   | sorts_on_typs (TVar (v,s))  = sorts_on_typs_aux (v,s);
   249 
   250 (*Given a list of sorted type variables, return a list of type literals.*)
   251 fun type_literals_for_types Ts =
   252   fold (union (op =)) (map sorts_on_typs Ts) []
   253 
   254 (** make axiom and conjecture clauses. **)
   255 
   256 (**** Isabelle arities ****)
   257 
   258 datatype arLit = TConsLit of class * string * string list
   259                | TVarLit of class * string;
   260 
   261 datatype arity_clause =
   262   ArityClause of {axiom_name: string, conclLit: arLit, premLits: arLit list}
   263 
   264 
   265 fun gen_TVars 0 = []
   266   | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1);
   267 
   268 fun pack_sort(_,[])  = []
   269   | pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt)   (*IGNORE sort "type"*)
   270   | pack_sort(tvar, cls::srt) =  (cls, tvar) :: pack_sort(tvar, srt);
   271 
   272 (*Arity of type constructor tcon :: (arg1,...,argN)res*)
   273 fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) =
   274    let val tvars = gen_TVars (length args)
   275        val tvars_srts = ListPair.zip (tvars,args)
   276    in
   277      ArityClause {axiom_name = axiom_name, 
   278                   conclLit = TConsLit (cls, make_fixed_type_const tcons, tvars),
   279                   premLits = map TVarLit (union_all(map pack_sort tvars_srts))}
   280    end;
   281 
   282 
   283 (**** Isabelle class relations ****)
   284 
   285 datatype classrel_clause =
   286   ClassrelClause of {axiom_name: string, subclass: class, superclass: class}
   287 
   288 (*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*)
   289 fun class_pairs _ [] _ = []
   290   | class_pairs thy subs supers =
   291       let
   292         val class_less = Sorts.class_less (Sign.classes_of thy)
   293         fun add_super sub super = class_less (sub, super) ? cons (sub, super)
   294         fun add_supers sub = fold (add_super sub) supers
   295       in fold add_supers subs [] end
   296 
   297 fun make_classrel_clause (sub,super) =
   298   ClassrelClause {axiom_name = classrel_clause_prefix ^ ascii_of sub ^ "_" ^
   299                                ascii_of super,
   300                   subclass = make_type_class sub,
   301                   superclass = make_type_class super};
   302 
   303 fun make_classrel_clauses thy subs supers =
   304   map make_classrel_clause (class_pairs thy subs supers);
   305 
   306 
   307 (** Isabelle arities **)
   308 
   309 fun arity_clause _ _ (_, []) = []
   310   | arity_clause seen n (tcons, ("HOL.type",_)::ars) =  (*ignore*)
   311       arity_clause seen n (tcons,ars)
   312   | arity_clause seen n (tcons, (ar as (class,_)) :: ars) =
   313       if member (op =) seen class then (*multiple arities for the same tycon, class pair*)
   314           make_axiom_arity_clause (tcons, lookup_const tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) ::
   315           arity_clause seen (n+1) (tcons,ars)
   316       else
   317           make_axiom_arity_clause (tcons, lookup_const tcons ^ "_" ^ class, ar) ::
   318           arity_clause (class::seen) n (tcons,ars)
   319 
   320 fun multi_arity_clause [] = []
   321   | multi_arity_clause ((tcons, ars) :: tc_arlists) =
   322       arity_clause [] 1 (tcons, ars) @ multi_arity_clause tc_arlists
   323 
   324 (*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy
   325   provided its arguments have the corresponding sorts.*)
   326 fun type_class_pairs thy tycons classes =
   327   let val alg = Sign.classes_of thy
   328       fun domain_sorts tycon = Sorts.mg_domain alg tycon o single
   329       fun add_class tycon class =
   330         cons (class, domain_sorts tycon class)
   331         handle Sorts.CLASS_ERROR _ => I
   332       fun try_classes tycon = (tycon, fold (add_class tycon) classes [])
   333   in  map try_classes tycons  end;
   334 
   335 (*Proving one (tycon, class) membership may require proving others, so iterate.*)
   336 fun iter_type_class_pairs _ _ [] = ([], [])
   337   | iter_type_class_pairs thy tycons classes =
   338       let val cpairs = type_class_pairs thy tycons classes
   339           val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs)))
   340             |> subtract (op =) classes |> subtract (op =) HOLogic.typeS
   341           val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses
   342       in (union (op =) classes' classes, union (op =) cpairs' cpairs) end;
   343 
   344 fun make_arity_clauses thy tycons classes =
   345   let val (classes', cpairs) = iter_type_class_pairs thy tycons classes
   346   in  (classes', multi_arity_clause cpairs)  end;
   347 
   348 datatype combtyp =
   349   TyVar of name |
   350   TyFree of name |
   351   TyConstr of name * combtyp list
   352 
   353 datatype combterm =
   354   CombConst of name * combtyp * combtyp list (* Const and Free *) |
   355   CombVar of name * combtyp |
   356   CombApp of combterm * combterm
   357 
   358 datatype literal = Literal of bool * combterm
   359 
   360 datatype hol_clause =
   361   HOLClause of {clause_id: int, axiom_name: string, th: thm, kind: kind,
   362                 literals: literal list, ctypes_sorts: typ list}
   363 
   364 (*********************************************************************)
   365 (* convert a clause with type Term.term to a clause with type clause *)
   366 (*********************************************************************)
   367 
   368 (*Result of a function type; no need to check that the argument type matches.*)
   369 fun result_type (TyConstr (_, [_, tp2])) = tp2
   370   | result_type _ = raise Fail "non-function type"
   371 
   372 fun type_of_combterm (CombConst (_, tp, _)) = tp
   373   | type_of_combterm (CombVar (_, tp)) = tp
   374   | type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1)
   375 
   376 (*gets the head of a combinator application, along with the list of arguments*)
   377 fun strip_combterm_comb u =
   378     let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts)
   379         |   stripc  x =  x
   380     in stripc(u,[]) end
   381 
   382 fun type_of (Type (a, Ts)) =
   383     let val (folTypes,ts) = types_of Ts in
   384       (TyConstr (`make_fixed_type_const a, folTypes), ts)
   385     end
   386   | type_of (tp as TFree (a, _)) = (TyFree (`make_fixed_type_var a), [tp])
   387   | type_of (tp as TVar (x, _)) =
   388     (TyVar (make_schematic_type_var x, string_of_indexname x), [tp])
   389 and types_of Ts =
   390     let val (folTyps, ts) = ListPair.unzip (map type_of Ts) in
   391       (folTyps, union_all ts)
   392     end
   393 
   394 (* same as above, but no gathering of sort information *)
   395 fun simp_type_of (Type (a, Ts)) =
   396       TyConstr (`make_fixed_type_const a, map simp_type_of Ts)
   397   | simp_type_of (TFree (a, _)) = TyFree (`make_fixed_type_var a)
   398   | simp_type_of (TVar (x, _)) =
   399     TyVar (make_schematic_type_var x, string_of_indexname x)
   400 
   401 (* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
   402 fun combterm_of thy (Const (c, T)) =
   403       let
   404         val (tp, ts) = type_of T
   405         val tvar_list =
   406           (if String.isPrefix skolem_theory_name c then
   407              [] |> Term.add_tvarsT T |> map TVar
   408            else
   409              (c, T) |> Sign.const_typargs thy)
   410           |> map simp_type_of
   411         val c' = CombConst (`make_fixed_const c, tp, tvar_list)
   412       in  (c',ts)  end
   413   | combterm_of _ (Free(v, T)) =
   414       let val (tp,ts) = type_of T
   415           val v' = CombConst (`make_fixed_var v, tp, [])
   416       in  (v',ts)  end
   417   | combterm_of _ (Var(v, T)) =
   418       let val (tp,ts) = type_of T
   419           val v' = CombVar ((make_schematic_var v, string_of_indexname v), tp)
   420       in  (v',ts)  end
   421   | combterm_of thy (P $ Q) =
   422       let val (P', tsP) = combterm_of thy P
   423           val (Q', tsQ) = combterm_of thy Q
   424       in  (CombApp (P', Q'), union (op =) tsP tsQ)  end
   425   | combterm_of _ (Abs _) = raise Fail "HOL clause: Abs"
   426 
   427 fun predicate_of thy ((@{const Not} $ P), pos) = predicate_of thy (P, not pos)
   428   | predicate_of thy (t, pos) = (combterm_of thy (Envir.eta_contract t), pos)
   429 
   430 fun literals_of_term1 args thy (@{const Trueprop} $ P) =
   431     literals_of_term1 args thy P
   432   | literals_of_term1 args thy (@{const "op |"} $ P $ Q) =
   433     literals_of_term1 (literals_of_term1 args thy P) thy Q
   434   | literals_of_term1 (lits, ts) thy P =
   435     let val ((pred, ts'), pol) = predicate_of thy (P, true) in
   436       (Literal (pol, pred) :: lits, union (op =) ts ts')
   437     end
   438 val literals_of_term = literals_of_term1 ([], [])
   439 
   440 fun skolem_name i j num_T_args =
   441   skolem_prefix ^ (space_implode "_" (map Int.toString [i, j, num_T_args])) ^
   442   skolem_infix ^ "g"
   443 
   444 fun conceal_skolem_terms i skolems t =
   445   if exists_Const (curry (op =) @{const_name skolem_id} o fst) t then
   446     let
   447       fun aux skolems
   448               (t as (Const (@{const_name skolem_id}, Type (_, [_, T])) $ _)) =
   449           let
   450             val (skolems, s) =
   451               if i = ~1 then
   452                 (skolems, @{const_name undefined})
   453               else case AList.find (op aconv) skolems t of
   454                 s :: _ => (skolems, s)
   455               | [] =>
   456                 let
   457                   val s = skolem_theory_name ^ "." ^
   458                           skolem_name i (length skolems)
   459                                         (length (Term.add_tvarsT T []))
   460                 in ((s, t) :: skolems, s) end
   461           in (skolems, Const (s, T)) end
   462         | aux skolems (t1 $ t2) =
   463           let
   464             val (skolems, t1) = aux skolems t1
   465             val (skolems, t2) = aux skolems t2
   466           in (skolems, t1 $ t2) end
   467         | aux skolems (Abs (s, T, t')) =
   468           let val (skolems, t') = aux skolems t' in
   469             (skolems, Abs (s, T, t'))
   470           end
   471         | aux skolems t = (skolems, t)
   472     in aux skolems t end
   473   else
   474     (skolems, t)
   475 
   476 
   477 (***************************************************************)
   478 (* Type Classes Present in the Axiom or Conjecture Clauses     *)
   479 (***************************************************************)
   480 
   481 fun set_insert (x, s) = Symtab.update (x, ()) s
   482 
   483 fun add_classes (sorts, cset) = List.foldl set_insert cset (flat sorts)
   484 
   485 (*Remove this trivial type class*)
   486 fun delete_type cset = Symtab.delete_safe (the_single @{sort HOL.type}) cset;
   487 
   488 fun tfree_classes_of_terms ts =
   489   let val sorts_list = map (map #2 o OldTerm.term_tfrees) ts
   490   in  Symtab.keys (delete_type (List.foldl add_classes Symtab.empty sorts_list))  end;
   491 
   492 fun tvar_classes_of_terms ts =
   493   let val sorts_list = map (map #2 o OldTerm.term_tvars) ts
   494   in  Symtab.keys (delete_type (List.foldl add_classes Symtab.empty sorts_list))  end;
   495 
   496 (*fold type constructors*)
   497 fun fold_type_consts f (Type (a, Ts)) x = fold (fold_type_consts f) Ts (f (a,x))
   498   | fold_type_consts _ _ x = x;
   499 
   500 (*Type constructors used to instantiate overloaded constants are the only ones needed.*)
   501 fun add_type_consts_in_term thy =
   502   let
   503     val const_typargs = Sign.const_typargs thy
   504     fun aux (Const x) = fold (fold_type_consts set_insert) (const_typargs x)
   505       | aux (Abs (_, _, u)) = aux u
   506       | aux (Const (@{const_name skolem_id}, _) $ _) = I
   507       | aux (t $ u) = aux t #> aux u
   508       | aux _ = I
   509   in aux end
   510 
   511 fun type_consts_of_terms thy ts =
   512   Symtab.keys (fold (add_type_consts_in_term thy) ts Symtab.empty);
   513 
   514 end;