src/HOL/Tools/Sledgehammer/sledgehammer_hol_clause.ML
author blanchet
Tue Mar 23 11:39:21 2010 +0100 (2010-03-23)
changeset 35963 943e2582dc87
parent 35865 2f8fb5242799
child 36167 c1a35be8e476
permissions -rw-r--r--
added options to Sledgehammer;
syntax: sledgehammer [options] goal_no, where "[options]" and "goal_no" are optional
     1 (*  Title:      HOL/Sledgehammer/sledgehammer_hol_clause.ML
     2     Author:     Jia Meng, NICTA
     3 
     4 FOL clauses translated from HOL formulae.
     5 *)
     6 
     7 signature SLEDGEHAMMER_HOL_CLAUSE =
     8 sig
     9   type kind = Sledgehammer_FOL_Clause.kind
    10   type fol_type = Sledgehammer_FOL_Clause.fol_type
    11   type classrel_clause = Sledgehammer_FOL_Clause.classrel_clause
    12   type arity_clause = Sledgehammer_FOL_Clause.arity_clause
    13   type axiom_name = string
    14   type polarity = bool
    15   type hol_clause_id = int
    16 
    17   datatype combterm =
    18     CombConst of string * fol_type * fol_type list (* Const and Free *) |
    19     CombVar of string * fol_type |
    20     CombApp of combterm * combterm
    21   datatype literal = Literal of polarity * combterm
    22   datatype hol_clause =
    23     HOLClause of {clause_id: hol_clause_id, axiom_name: axiom_name, th: thm,
    24                   kind: kind, literals: literal list, ctypes_sorts: typ list}
    25 
    26   val type_of_combterm : combterm -> fol_type
    27   val strip_combterm_comb : combterm -> combterm * combterm list
    28   val literals_of_term : theory -> term -> literal list * typ list
    29   exception TRIVIAL
    30   val make_conjecture_clauses : bool -> theory -> thm list -> hol_clause list
    31   val make_axiom_clauses : bool -> theory ->
    32        (thm * (axiom_name * hol_clause_id)) list -> (axiom_name * hol_clause) list
    33   val get_helper_clauses : bool -> theory -> bool ->
    34        hol_clause list * (thm * (axiom_name * hol_clause_id)) list * string list ->
    35        hol_clause list
    36   val write_tptp_file : bool -> Path.T ->
    37     hol_clause list * hol_clause list * hol_clause list * hol_clause list *
    38     classrel_clause list * arity_clause list ->
    39     int * int
    40   val write_dfg_file : bool -> Path.T ->
    41     hol_clause list * hol_clause list * hol_clause list * hol_clause list *
    42     classrel_clause list * arity_clause list -> int * int
    43 end
    44 
    45 structure Sledgehammer_HOL_Clause : SLEDGEHAMMER_HOL_CLAUSE =
    46 struct
    47 
    48 open Sledgehammer_FOL_Clause
    49 open Sledgehammer_Fact_Preprocessor
    50 
    51 (* Parameter "full_types" below indicates that full type information is to be
    52 exported *)
    53 
    54 (* If true, each function will be directly applied to as many arguments as
    55    possible, avoiding use of the "apply" operator. Use of hBOOL is also
    56    minimized. *)
    57 val minimize_applies = true;
    58 
    59 fun min_arity_of const_min_arity c = the_default 0 (Symtab.lookup const_min_arity c);
    60 
    61 (*True if the constant ever appears outside of the top-level position in literals.
    62   If false, the constant always receives all of its arguments and is used as a predicate.*)
    63 fun needs_hBOOL const_needs_hBOOL c =
    64   not minimize_applies orelse
    65     the_default false (Symtab.lookup const_needs_hBOOL c);
    66 
    67 
    68 (******************************************************)
    69 (* data types for typed combinator expressions        *)
    70 (******************************************************)
    71 
    72 type axiom_name = string;
    73 type polarity = bool;
    74 type hol_clause_id = int;
    75 
    76 datatype combterm =
    77   CombConst of string * fol_type * fol_type list (* Const and Free *) |
    78   CombVar of string * fol_type |
    79   CombApp of combterm * combterm
    80 
    81 datatype literal = Literal of polarity * combterm;
    82 
    83 datatype hol_clause =
    84   HOLClause of {clause_id: hol_clause_id, axiom_name: axiom_name, th: thm,
    85                 kind: kind, literals: literal list, ctypes_sorts: typ list};
    86 
    87 
    88 (*********************************************************************)
    89 (* convert a clause with type Term.term to a clause with type clause *)
    90 (*********************************************************************)
    91 
    92 fun isFalse (Literal(pol, CombConst(c,_,_))) =
    93       (pol andalso c = "c_False") orelse (not pol andalso c = "c_True")
    94   | isFalse _ = false;
    95 
    96 fun isTrue (Literal (pol, CombConst(c,_,_))) =
    97       (pol andalso c = "c_True") orelse
    98       (not pol andalso c = "c_False")
    99   | isTrue _ = false;
   100 
   101 fun isTaut (HOLClause {literals,...}) = exists isTrue literals;
   102 
   103 fun type_of dfg (Type (a, Ts)) =
   104       let val (folTypes,ts) = types_of dfg Ts
   105       in  (Comp(make_fixed_type_const dfg a, folTypes), ts)  end
   106   | type_of _ (tp as TFree (a, _)) = (AtomF (make_fixed_type_var a), [tp])
   107   | type_of _ (tp as TVar (v, _)) = (AtomV (make_schematic_type_var v), [tp])
   108 and types_of dfg Ts =
   109       let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts)
   110       in  (folTyps, union_all ts)  end;
   111 
   112 (* same as above, but no gathering of sort information *)
   113 fun simp_type_of dfg (Type (a, Ts)) =
   114       Comp(make_fixed_type_const dfg a, map (simp_type_of dfg) Ts)
   115   | simp_type_of _ (TFree (a, _)) = AtomF (make_fixed_type_var a)
   116   | simp_type_of _ (TVar (v, _)) = AtomV (make_schematic_type_var v);
   117 
   118 
   119 fun const_type_of dfg thy (c,t) =
   120       let val (tp,ts) = type_of dfg t
   121       in  (tp, ts, map (simp_type_of dfg) (Sign.const_typargs thy (c,t))) end;
   122 
   123 (* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
   124 fun combterm_of dfg thy (Const(c,t)) =
   125       let val (tp,ts,tvar_list) = const_type_of dfg thy (c,t)
   126           val c' = CombConst(make_fixed_const dfg c, tp, tvar_list)
   127       in  (c',ts)  end
   128   | combterm_of dfg _ (Free(v,t)) =
   129       let val (tp,ts) = type_of dfg t
   130           val v' = CombConst(make_fixed_var v, tp, [])
   131       in  (v',ts)  end
   132   | combterm_of dfg _ (Var(v,t)) =
   133       let val (tp,ts) = type_of dfg t
   134           val v' = CombVar(make_schematic_var v,tp)
   135       in  (v',ts)  end
   136   | combterm_of dfg thy (P $ Q) =
   137       let val (P',tsP) = combterm_of dfg thy P
   138           val (Q',tsQ) = combterm_of dfg thy Q
   139       in  (CombApp(P',Q'), union (op =) tsP tsQ)  end
   140   | combterm_of _ _ (t as Abs _) = raise CLAUSE ("HOL CLAUSE", t);
   141 
   142 fun predicate_of dfg thy ((@{const Not} $ P), polarity) = predicate_of dfg thy (P, not polarity)
   143   | predicate_of dfg thy (t,polarity) = (combterm_of dfg thy (Envir.eta_contract t), polarity);
   144 
   145 fun literals_of_term1 dfg thy args (@{const Trueprop} $ P) = literals_of_term1 dfg thy args P
   146   | literals_of_term1 dfg thy args (@{const "op |"} $ P $ Q) =
   147       literals_of_term1 dfg thy (literals_of_term1 dfg thy args P) Q
   148   | literals_of_term1 dfg thy (lits,ts) P =
   149       let val ((pred,ts'),pol) = predicate_of dfg thy (P,true)
   150       in
   151           (Literal(pol,pred)::lits, union (op =) ts ts')
   152       end;
   153 
   154 fun literals_of_term_dfg dfg thy P = literals_of_term1 dfg thy ([],[]) P;
   155 val literals_of_term = literals_of_term_dfg false;
   156 
   157 (* Trivial problem, which resolution cannot handle (empty clause) *)
   158 exception TRIVIAL;
   159 
   160 (* making axiom and conjecture clauses *)
   161 fun make_clause dfg thy (clause_id, axiom_name, kind, th) =
   162     let val (lits,ctypes_sorts) = literals_of_term_dfg dfg thy (prop_of th)
   163     in
   164         if forall isFalse lits then
   165             raise TRIVIAL
   166         else
   167             HOLClause {clause_id = clause_id, axiom_name = axiom_name, th = th,
   168                        kind = kind, literals = lits, ctypes_sorts = ctypes_sorts}
   169     end;
   170 
   171 
   172 fun add_axiom_clause dfg thy ((th,(name,id)), pairs) =
   173   let val cls = make_clause dfg thy (id, name, Axiom, th)
   174   in
   175       if isTaut cls then pairs else (name,cls)::pairs
   176   end;
   177 
   178 fun make_axiom_clauses dfg thy = List.foldl (add_axiom_clause dfg thy) [];
   179 
   180 fun make_conjecture_clauses_aux _ _ _ [] = []
   181   | make_conjecture_clauses_aux dfg thy n (th::ths) =
   182       make_clause dfg thy (n,"conjecture", Conjecture, th) ::
   183       make_conjecture_clauses_aux dfg thy (n+1) ths;
   184 
   185 fun make_conjecture_clauses dfg thy = make_conjecture_clauses_aux dfg thy 0;
   186 
   187 
   188 (**********************************************************************)
   189 (* convert clause into ATP specific formats:                          *)
   190 (* TPTP used by Vampire and E                                         *)
   191 (* DFG used by SPASS                                                  *)
   192 (**********************************************************************)
   193 
   194 (*Result of a function type; no need to check that the argument type matches.*)
   195 fun result_type (Comp ("tc_fun", [_, tp2])) = tp2
   196   | result_type _ = error "result_type"
   197 
   198 fun type_of_combterm (CombConst (_, tp, _)) = tp
   199   | type_of_combterm (CombVar (_, tp)) = tp
   200   | type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1);
   201 
   202 (*gets the head of a combinator application, along with the list of arguments*)
   203 fun strip_combterm_comb u =
   204     let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts)
   205         |   stripc  x =  x
   206     in  stripc(u,[])  end;
   207 
   208 val type_wrapper = "ti";
   209 
   210 fun head_needs_hBOOL const_needs_hBOOL (CombConst(c,_,_)) = needs_hBOOL const_needs_hBOOL c
   211   | head_needs_hBOOL _ _ = true;
   212 
   213 fun wrap_type full_types (s, tp) =
   214   if full_types then type_wrapper ^ paren_pack [s, string_of_fol_type tp] else s;
   215 
   216 fun apply ss = "hAPP" ^ paren_pack ss;
   217 
   218 fun rev_apply (v, []) = v
   219   | rev_apply (v, arg::args) = apply [rev_apply (v, args), arg];
   220 
   221 fun string_apply (v, args) = rev_apply (v, rev args);
   222 
   223 (*Apply an operator to the argument strings, using either the "apply" operator or
   224   direct function application.*)
   225 fun string_of_applic full_types cma (CombConst (c, _, tvars), args) =
   226       let val c = if c = "equal" then "c_fequal" else c
   227           val nargs = min_arity_of cma c
   228           val args1 = List.take(args, nargs)
   229             handle Subscript => error ("string_of_applic: " ^ c ^ " has arity " ^
   230                                          Int.toString nargs ^ " but is applied to " ^
   231                                          space_implode ", " args)
   232           val args2 = List.drop(args, nargs)
   233           val targs = if full_types then [] else map string_of_fol_type tvars
   234       in
   235           string_apply (c ^ paren_pack (args1@targs), args2)
   236       end
   237   | string_of_applic _ _ (CombVar (v, _), args) = string_apply (v, args)
   238   | string_of_applic _ _ _ = error "string_of_applic";
   239 
   240 fun wrap_type_if full_types cnh (head, s, tp) =
   241   if head_needs_hBOOL cnh head then wrap_type full_types (s, tp) else s;
   242 
   243 fun string_of_combterm (params as (full_types, cma, cnh)) t =
   244   let val (head, args) = strip_combterm_comb t
   245   in  wrap_type_if full_types cnh (head,
   246           string_of_applic full_types cma
   247                            (head, map (string_of_combterm (params)) args),
   248           type_of_combterm t)
   249   end;
   250 
   251 (*Boolean-valued terms are here converted to literals.*)
   252 fun boolify params t =
   253   "hBOOL" ^ paren_pack [string_of_combterm params t];
   254 
   255 fun string_of_predicate (params as (_,_,cnh)) t =
   256   case t of
   257       (CombApp(CombApp(CombConst("equal",_,_), t1), t2)) =>
   258           (*DFG only: new TPTP prefers infix equality*)
   259           ("equal" ^ paren_pack [string_of_combterm params t1, string_of_combterm params t2])
   260     | _ =>
   261           case #1 (strip_combterm_comb t) of
   262               CombConst(c,_,_) => if needs_hBOOL cnh c then boolify params t else string_of_combterm params t
   263             | _ => boolify params t;
   264 
   265 
   266 (*** tptp format ***)
   267 
   268 fun tptp_of_equality params pol (t1,t2) =
   269   let val eqop = if pol then " = " else " != "
   270   in  string_of_combterm params t1 ^ eqop ^ string_of_combterm params t2  end;
   271 
   272 fun tptp_literal params (Literal(pol, CombApp(CombApp(CombConst("equal", _, _), t1), t2))) =
   273       tptp_of_equality params pol (t1,t2)
   274   | tptp_literal params (Literal(pol,pred)) =
   275       tptp_sign pol (string_of_predicate params pred);
   276 
   277 (*Given a clause, returns its literals paired with a list of literals concerning TFrees;
   278   the latter should only occur in conjecture clauses.*)
   279 fun tptp_type_lits params pos (HOLClause {literals, ctypes_sorts, ...}) =
   280       (map (tptp_literal params) literals, 
   281        map (tptp_of_typeLit pos) (add_typs ctypes_sorts));
   282 
   283 fun clause2tptp params (cls as HOLClause {axiom_name, clause_id, kind, ...}) =
   284   let val (lits,tylits) = tptp_type_lits params (kind = Conjecture) cls
   285   in
   286       (gen_tptp_cls (clause_id, axiom_name, kind, lits, tylits), tylits)
   287   end;
   288 
   289 
   290 (*** dfg format ***)
   291 
   292 fun dfg_literal params (Literal(pol,pred)) = dfg_sign pol (string_of_predicate params pred);
   293 
   294 fun dfg_type_lits params pos (HOLClause {literals, ctypes_sorts, ...}) =
   295       (map (dfg_literal params) literals, 
   296        map (dfg_of_typeLit pos) (add_typs ctypes_sorts));
   297 
   298 fun get_uvars (CombConst _) vars = vars
   299   | get_uvars (CombVar(v,_)) vars = (v::vars)
   300   | get_uvars (CombApp(P,Q)) vars = get_uvars P (get_uvars Q vars);
   301 
   302 fun get_uvars_l (Literal(_,c)) = get_uvars c [];
   303 
   304 fun dfg_vars (HOLClause {literals,...}) = union_all (map get_uvars_l literals);
   305 
   306 fun clause2dfg params (cls as HOLClause {axiom_name, clause_id, kind,
   307                                          ctypes_sorts, ...}) =
   308   let val (lits,tylits) = dfg_type_lits params (kind = Conjecture) cls
   309       val vars = dfg_vars cls
   310       val tvars = get_tvar_strs ctypes_sorts
   311   in
   312       (gen_dfg_cls (clause_id, axiom_name, kind, lits, tylits, tvars@vars), tylits)
   313   end;
   314 
   315 
   316 (** For DFG format: accumulate function and predicate declarations **)
   317 
   318 fun addtypes tvars tab = List.foldl add_foltype_funcs tab tvars;
   319 
   320 fun add_decls (full_types, cma, cnh) (CombConst (c, _, tvars), (funcs, preds)) =
   321       if c = "equal" then (addtypes tvars funcs, preds)
   322       else
   323         let val arity = min_arity_of cma c
   324             val ntys = if not full_types then length tvars else 0
   325             val addit = Symtab.update(c, arity+ntys)
   326         in
   327             if needs_hBOOL cnh c then (addtypes tvars (addit funcs), preds)
   328             else (addtypes tvars funcs, addit preds)
   329         end
   330   | add_decls _ (CombVar(_,ctp), (funcs,preds)) =
   331       (add_foltype_funcs (ctp,funcs), preds)
   332   | add_decls params (CombApp(P,Q),decls) = add_decls params (P,add_decls params (Q,decls));
   333 
   334 fun add_literal_decls params (Literal (_,c), decls) = add_decls params (c,decls);
   335 
   336 fun add_clause_decls params (HOLClause {literals, ...}, decls) =
   337     List.foldl (add_literal_decls params) decls literals
   338     handle Symtab.DUP a => error ("function " ^ a ^ " has multiple arities")
   339 
   340 fun decls_of_clauses params clauses arity_clauses =
   341   let val init_functab = Symtab.update (type_wrapper,2) (Symtab.update ("hAPP",2) init_functab)
   342       val init_predtab = Symtab.update ("hBOOL",1) Symtab.empty
   343       val (functab,predtab) = (List.foldl (add_clause_decls params) (init_functab, init_predtab) clauses)
   344   in
   345       (Symtab.dest (List.foldl add_arity_clause_funcs functab arity_clauses),
   346        Symtab.dest predtab)
   347   end;
   348 
   349 fun add_clause_preds (HOLClause {ctypes_sorts, ...}, preds) =
   350   List.foldl add_type_sort_preds preds ctypes_sorts
   351   handle Symtab.DUP a => error ("predicate " ^ a ^ " has multiple arities")
   352 
   353 (*Higher-order clauses have only the predicates hBOOL and type classes.*)
   354 fun preds_of_clauses clauses clsrel_clauses arity_clauses =
   355     Symtab.dest
   356         (List.foldl add_classrel_clause_preds
   357                (List.foldl add_arity_clause_preds
   358                       (List.foldl add_clause_preds Symtab.empty clauses)
   359                       arity_clauses)
   360                clsrel_clauses)
   361 
   362 
   363 (**********************************************************************)
   364 (* write clauses to files                                             *)
   365 (**********************************************************************)
   366 
   367 val init_counters =
   368   Symtab.make [("c_COMBI", 0), ("c_COMBK", 0), ("c_COMBB", 0), ("c_COMBC", 0),
   369                ("c_COMBS", 0)];
   370 
   371 fun count_combterm (CombConst (c, _, _), ct) =
   372      (case Symtab.lookup ct c of NONE => ct  (*no counter*)
   373                                | SOME n => Symtab.update (c,n+1) ct)
   374   | count_combterm (CombVar _, ct) = ct
   375   | count_combterm (CombApp(t1,t2), ct) = count_combterm(t1, count_combterm(t2, ct));
   376 
   377 fun count_literal (Literal(_,t), ct) = count_combterm(t,ct);
   378 
   379 fun count_clause (HOLClause {literals, ...}, ct) =
   380   List.foldl count_literal ct literals;
   381 
   382 fun count_user_clause user_lemmas (HOLClause {axiom_name, literals, ...}, ct) =
   383   if axiom_name mem_string user_lemmas then List.foldl count_literal ct literals
   384   else ct;
   385 
   386 fun cnf_helper_thms thy = cnf_rules_pairs thy o map pairname
   387 
   388 fun get_helper_clauses dfg thy isFO (conjectures, axcls, user_lemmas) =
   389   if isFO then
   390     []
   391   else
   392     let
   393         val axclauses = map #2 (make_axiom_clauses dfg thy axcls)
   394         val ct0 = List.foldl count_clause init_counters conjectures
   395         val ct = List.foldl (count_user_clause user_lemmas) ct0 axclauses
   396         fun needed c = the (Symtab.lookup ct c) > 0
   397         val IK = if needed "c_COMBI" orelse needed "c_COMBK"
   398                  then cnf_helper_thms thy [@{thm COMBI_def}, @{thm COMBK_def}]
   399                  else []
   400         val BC = if needed "c_COMBB" orelse needed "c_COMBC"
   401                  then cnf_helper_thms thy [@{thm COMBB_def}, @{thm COMBC_def}]
   402                  else []
   403         val S = if needed "c_COMBS" then cnf_helper_thms thy [@{thm COMBS_def}]
   404                 else []
   405         val other = cnf_helper_thms thy [@{thm fequal_imp_equal},
   406                                          @{thm equal_imp_fequal}]
   407     in
   408         map #2 (make_axiom_clauses dfg thy (other @ IK @ BC @ S))
   409     end;
   410 
   411 (*Find the minimal arity of each function mentioned in the term. Also, note which uses
   412   are not at top level, to see if hBOOL is needed.*)
   413 fun count_constants_term toplev t (const_min_arity, const_needs_hBOOL) =
   414   let val (head, args) = strip_combterm_comb t
   415       val n = length args
   416       val (const_min_arity, const_needs_hBOOL) = fold (count_constants_term false) args (const_min_arity, const_needs_hBOOL)
   417   in
   418       case head of
   419           CombConst (a,_,_) => (*predicate or function version of "equal"?*)
   420             let val a = if a="equal" andalso not toplev then "c_fequal" else a
   421             val const_min_arity = Symtab.map_default (a, n) (Integer.min n) const_min_arity
   422             in
   423               if toplev then (const_min_arity, const_needs_hBOOL)
   424               else (const_min_arity, Symtab.update (a,true) (const_needs_hBOOL))
   425             end
   426         | _ => (const_min_arity, const_needs_hBOOL)
   427   end;
   428 
   429 (*A literal is a top-level term*)
   430 fun count_constants_lit (Literal (_,t)) (const_min_arity, const_needs_hBOOL) =
   431   count_constants_term true t (const_min_arity, const_needs_hBOOL);
   432 
   433 fun count_constants_clause (HOLClause {literals, ...})
   434                            (const_min_arity, const_needs_hBOOL) =
   435   fold count_constants_lit literals (const_min_arity, const_needs_hBOOL);
   436 
   437 fun display_arity const_needs_hBOOL (c,n) =
   438   trace_msg (fn () => "Constant: " ^ c ^
   439                 " arity:\t" ^ Int.toString n ^
   440                 (if needs_hBOOL const_needs_hBOOL c then " needs hBOOL" else ""));
   441 
   442 fun count_constants (conjectures, _, extra_clauses, helper_clauses, _, _) =
   443   if minimize_applies then
   444      let val (const_min_arity, const_needs_hBOOL) =
   445           fold count_constants_clause conjectures (Symtab.empty, Symtab.empty)
   446        |> fold count_constants_clause extra_clauses
   447        |> fold count_constants_clause helper_clauses
   448      val _ = List.app (display_arity const_needs_hBOOL) (Symtab.dest (const_min_arity))
   449      in (const_min_arity, const_needs_hBOOL) end
   450   else (Symtab.empty, Symtab.empty);
   451 
   452 (* TPTP format *)
   453 
   454 fun write_tptp_file full_types file clauses =
   455   let
   456     val (conjectures, axclauses, _, helper_clauses,
   457       classrel_clauses, arity_clauses) = clauses
   458     val (cma, cnh) = count_constants clauses
   459     val params = (full_types, cma, cnh)
   460     val (tptp_clss,tfree_litss) = ListPair.unzip (map (clause2tptp params) conjectures)
   461     val tfree_clss = map tptp_tfree_clause (List.foldl (uncurry (union (op =))) [] tfree_litss)
   462     val _ =
   463       File.write_list file (
   464         map (#1 o (clause2tptp params)) axclauses @
   465         tfree_clss @
   466         tptp_clss @
   467         map tptp_classrel_clause classrel_clauses @
   468         map tptp_arity_clause arity_clauses @
   469         map (#1 o (clause2tptp params)) helper_clauses)
   470     in (length axclauses + 1, length tfree_clss + length tptp_clss)
   471   end;
   472 
   473 
   474 (* DFG format *)
   475 
   476 fun write_dfg_file full_types file clauses =
   477   let
   478     val (conjectures, axclauses, _, helper_clauses,
   479       classrel_clauses, arity_clauses) = clauses
   480     val (cma, cnh) = count_constants clauses
   481     val params = (full_types, cma, cnh)
   482     val (dfg_clss, tfree_litss) = ListPair.unzip (map (clause2dfg params) conjectures)
   483     and probname = Path.implode (Path.base file)
   484     val axstrs = map (#1 o (clause2dfg params)) axclauses
   485     val tfree_clss = map dfg_tfree_clause (union_all tfree_litss)
   486     val helper_clauses_strs = map (#1 o (clause2dfg params)) helper_clauses
   487     val (funcs,cl_preds) = decls_of_clauses params (helper_clauses @ conjectures @ axclauses) arity_clauses
   488     and ty_preds = preds_of_clauses axclauses classrel_clauses arity_clauses
   489     val _ =
   490       File.write_list file (
   491         string_of_start probname ::
   492         string_of_descrip probname ::
   493         string_of_symbols (string_of_funcs funcs)
   494           (string_of_preds (cl_preds @ ty_preds)) ::
   495         "list_of_clauses(axioms,cnf).\n" ::
   496         axstrs @
   497         map dfg_classrel_clause classrel_clauses @
   498         map dfg_arity_clause arity_clauses @
   499         helper_clauses_strs @
   500         ["end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n"] @
   501         tfree_clss @
   502         dfg_clss @
   503         ["end_of_list.\n\n",
   504         (*VarWeight=3 helps the HO problems, probably by counteracting the presence of hAPP*)
   505          "list_of_settings(SPASS).\n{*\nset_flag(VarWeight,3).\n*}\nend_of_list.\n\n",
   506          "end_problem.\n"])
   507 
   508     in (length axclauses + length classrel_clauses + length arity_clauses +
   509       length helper_clauses + 1, length tfree_clss + length dfg_clss)
   510   end;
   511 
   512 end;