src/HOL/Tools/res_hol_clause.ML
author paulson
Thu Jul 13 17:39:56 2006 +0200 (2006-07-13)
changeset 20125 20229342ca76
parent 20022 b07a138b4e7d
child 20130 5303e5928285
permissions -rw-r--r--
"conjecture" must be lower case
mengj@17998
     1
(* ID: $Id$ 
mengj@17998
     2
   Author: Jia Meng, NICTA
mengj@17998
     3
mengj@17998
     4
FOL clauses translated from HOL formulae.  Combinators are used to represent lambda terms.
mengj@17998
     5
mengj@17998
     6
*)
mengj@17998
     7
mengj@17998
     8
structure ResHolClause =
mengj@17998
     9
mengj@17998
    10
struct
mengj@17998
    11
mengj@17998
    12
mengj@18276
    13
val include_combS = ref false;
mengj@18276
    14
val include_min_comb = ref false;
mengj@17998
    15
mengj@18356
    16
val const_typargs = ref (Library.K [] : (string*typ -> typ list));
mengj@18356
    17
paulson@20022
    18
fun init thy = (include_combS:=false; include_min_comb:=false;
paulson@20022
    19
                const_typargs := Sign.const_typargs thy);
mengj@19198
    20
mengj@17998
    21
(**********************************************************************)
mengj@17998
    22
(* convert a Term.term with lambdas into a Term.term with combinators *) 
mengj@17998
    23
(**********************************************************************)
mengj@17998
    24
mengj@17998
    25
fun is_free (Bound(a)) n = (a = n)
mengj@17998
    26
  | is_free (Abs(x,_,b)) n = (is_free b (n+1))
mengj@17998
    27
  | is_free (P $ Q) n = ((is_free P n) orelse (is_free Q n))
mengj@17998
    28
  | is_free _ _ = false;
mengj@17998
    29
mengj@17998
    30
mengj@17998
    31
exception LAM2COMB of term;
mengj@17998
    32
mengj@17998
    33
exception BND of term;
mengj@17998
    34
mengj@17998
    35
fun decre_bndVar (Bound n) = Bound (n-1)
mengj@17998
    36
  | decre_bndVar (P $ Q) = (decre_bndVar P) $ (decre_bndVar Q)
mengj@17998
    37
  | decre_bndVar t =
mengj@17998
    38
    case t of Const(_,_) => t
mengj@17998
    39
	    | Free(_,_) => t
mengj@17998
    40
	    | Var(_,_) => t
mengj@17998
    41
	    | Abs(_,_,_) => raise BND(t); (*should not occur*)
mengj@17998
    42
mengj@17998
    43
mengj@17998
    44
(*******************************************)
mengj@17998
    45
fun lam2comb (Abs(x,tp,Bound 0)) _ = 
mengj@17998
    46
    let val tpI = Type("fun",[tp,tp])
mengj@17998
    47
    in 
mengj@18276
    48
	include_min_comb:=true;
mengj@17998
    49
	Const("COMBI",tpI) 
mengj@17998
    50
    end
mengj@18356
    51
  | lam2comb (Abs(x,tp,Bound n)) Bnds = 
mengj@18356
    52
    let val (Bound n') = decre_bndVar (Bound n)
mengj@18356
    53
	val tb = List.nth(Bnds,n')
mengj@18356
    54
	val tK = Type("fun",[tb,Type("fun",[tp,tb])])
mengj@18356
    55
    in
mengj@18356
    56
	include_min_comb:=true;
mengj@18356
    57
	Const("COMBK",tK) $ (Bound n')
mengj@18356
    58
    end
mengj@17998
    59
  | lam2comb (Abs(x,t1,Const(c,t2))) _ = 
mengj@17998
    60
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
mengj@17998
    61
    in 
mengj@18276
    62
	include_min_comb:=true;
mengj@17998
    63
	Const("COMBK",tK) $ Const(c,t2) 
mengj@17998
    64
    end
mengj@17998
    65
  | lam2comb (Abs(x,t1,Free(v,t2))) _ =
mengj@17998
    66
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
mengj@17998
    67
    in
mengj@18276
    68
	include_min_comb:=true;
mengj@17998
    69
	Const("COMBK",tK) $ Free(v,t2)
mengj@17998
    70
    end
mengj@17998
    71
  | lam2comb (Abs(x,t1,Var(ind,t2))) _=
mengj@17998
    72
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
mengj@17998
    73
    in
mengj@18276
    74
	include_min_comb:=true;
mengj@17998
    75
	Const("COMBK",tK) $ Var(ind,t2)
mengj@17998
    76
    end
mengj@17998
    77
  | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds =
mengj@17998
    78
    let val nfreeP = not(is_free P 0)
mengj@17998
    79
	val tr = Term.type_of1(t1::Bnds,P)
mengj@17998
    80
    in
mengj@17998
    81
	if nfreeP then (decre_bndVar P)
mengj@17998
    82
	else (
mengj@17998
    83
	      let val tI = Type("fun",[t1,t1])
mengj@17998
    84
		  val P' = lam2comb (Abs(x,t1,P)) Bnds
mengj@17998
    85
		  val tp' = Term.type_of1(Bnds,P')
mengj@17998
    86
		  val tS = Type("fun",[tp',Type("fun",[tI,tr])])
mengj@17998
    87
	      in
mengj@18276
    88
		  include_min_comb:=true;
mengj@18276
    89
		  include_combS:=true;
mengj@17998
    90
		  Const("COMBS",tS) $ P' $ Const("COMBI",tI)
mengj@17998
    91
	      end)
mengj@17998
    92
    end
mengj@17998
    93
	    
mengj@17998
    94
  | lam2comb (t as (Abs(x,t1,P$Q))) Bnds =
mengj@17998
    95
    let val (nfreeP,nfreeQ) = (not(is_free P 0),not(is_free Q 0))
mengj@17998
    96
	val tpq = Term.type_of1(t1::Bnds, P$Q) 
mengj@17998
    97
    in
mengj@17998
    98
	if(nfreeP andalso nfreeQ) then (
mengj@17998
    99
	    let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])])
mengj@17998
   100
		val PQ' = decre_bndVar(P $ Q)
mengj@17998
   101
	    in 
mengj@18276
   102
		include_min_comb:=true;
mengj@17998
   103
		Const("COMBK",tK) $ PQ'
mengj@17998
   104
	    end)
mengj@17998
   105
	else (
mengj@17998
   106
	      if nfreeP then (
mengj@17998
   107
			       let val Q' = lam2comb (Abs(x,t1,Q)) Bnds
mengj@17998
   108
				   val P' = decre_bndVar P
mengj@17998
   109
				   val tp = Term.type_of1(Bnds,P')
mengj@17998
   110
				   val tq' = Term.type_of1(Bnds, Q')
mengj@17998
   111
				   val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])])
mengj@17998
   112
			       in
mengj@18276
   113
				   include_min_comb:=true;
mengj@17998
   114
				   Const("COMBB",tB) $ P' $ Q' 
mengj@17998
   115
			       end)
mengj@17998
   116
	      else (
mengj@17998
   117
		    if nfreeQ then (
mengj@17998
   118
				    let val P' = lam2comb (Abs(x,t1,P)) Bnds
mengj@17998
   119
					val Q' = decre_bndVar Q
mengj@17998
   120
					val tq = Term.type_of1(Bnds,Q')
mengj@17998
   121
					val tp' = Term.type_of1(Bnds, P')
mengj@17998
   122
					val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])])
mengj@17998
   123
				    in
mengj@18276
   124
					include_min_comb:=true;
mengj@17998
   125
					Const("COMBC",tC) $ P' $ Q'
mengj@17998
   126
				    end)
mengj@17998
   127
		    else(
mengj@17998
   128
			 let val P' = lam2comb (Abs(x,t1,P)) Bnds
mengj@17998
   129
			     val Q' = lam2comb (Abs(x,t1,Q)) Bnds
mengj@17998
   130
			     val tp' = Term.type_of1(Bnds,P')
mengj@17998
   131
			     val tq' = Term.type_of1(Bnds,Q')
mengj@17998
   132
			     val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])])
mengj@17998
   133
			 in
mengj@18276
   134
			     include_min_comb:=true;
mengj@18276
   135
			     include_combS:=true;
mengj@17998
   136
			     Const("COMBS",tS) $ P' $ Q'
mengj@17998
   137
			 end)))
mengj@17998
   138
    end
mengj@17998
   139
  | lam2comb (t as (Abs(x,t1,_))) _ = raise LAM2COMB (t);
mengj@17998
   140
mengj@17998
   141
	     
mengj@17998
   142
mengj@17998
   143
(*********************)
mengj@17998
   144
mengj@17998
   145
fun to_comb (Abs(x,tp,b)) Bnds =
mengj@17998
   146
    let val b' = to_comb b (tp::Bnds)
mengj@17998
   147
    in lam2comb (Abs(x,tp,b')) Bnds end
mengj@17998
   148
  | to_comb (P $ Q) Bnds = ((to_comb P Bnds) $ (to_comb Q Bnds))
mengj@17998
   149
  | to_comb t _ = t;
mengj@17998
   150
 
mengj@17998
   151
    
mengj@17998
   152
fun comb_of t = to_comb t [];
mengj@17998
   153
mengj@17998
   154
mengj@17998
   155
(* print a term containing combinators, used for debugging *)
mengj@17998
   156
exception TERM_COMB of term;
mengj@17998
   157
mengj@17998
   158
fun string_of_term (Const(c,t)) = c
mengj@17998
   159
  | string_of_term (Free(v,t)) = v
mengj@17998
   160
  | string_of_term (Var((x,n),t)) =
mengj@17998
   161
    let val xn = x ^ "_" ^ (string_of_int n)
mengj@17998
   162
    in xn end
mengj@17998
   163
  | string_of_term (P $ Q) =
mengj@17998
   164
    let val P' = string_of_term P
mengj@17998
   165
	val Q' = string_of_term Q
mengj@17998
   166
    in
mengj@17998
   167
	"(" ^ P' ^ " " ^ Q' ^ ")" end
mengj@17998
   168
  | string_of_term t =  raise TERM_COMB (t);
mengj@17998
   169
mengj@17998
   170
mengj@17998
   171
mengj@17998
   172
(******************************************************)
mengj@17998
   173
(* data types for typed combinator expressions        *)
mengj@17998
   174
(******************************************************)
mengj@17998
   175
mengj@17998
   176
type axiom_name = string;
mengj@17998
   177
datatype kind = Axiom | Conjecture;
mengj@17998
   178
fun name_of_kind Axiom = "axiom"
mengj@17998
   179
  | name_of_kind Conjecture = "conjecture";
mengj@17998
   180
mengj@17998
   181
type polarity = bool;
mengj@17998
   182
type indexname = Term.indexname;
mengj@17998
   183
type clause_id = int;
mengj@17998
   184
type csort = Term.sort;
mengj@18440
   185
type ctyp = ResClause.fol_type;
mengj@18440
   186
mengj@18440
   187
val string_of_ctyp = ResClause.string_of_fol_type;
mengj@17998
   188
mengj@17998
   189
type ctyp_var = ResClause.typ_var;
mengj@17998
   190
mengj@17998
   191
type ctype_literal = ResClause.type_literal;
mengj@17998
   192
mengj@17998
   193
mengj@18356
   194
datatype combterm = CombConst of string * ctyp * ctyp list
mengj@17998
   195
		  | CombFree of string * ctyp
mengj@17998
   196
		  | CombVar of string * ctyp
mengj@17998
   197
		  | CombApp of combterm * combterm * ctyp
mengj@19452
   198
		  | Bool of combterm;
mengj@17998
   199
datatype literal = Literal of polarity * combterm;
mengj@17998
   200
mengj@17998
   201
mengj@17998
   202
mengj@17998
   203
datatype clause = 
mengj@17998
   204
	 Clause of {clause_id: clause_id,
mengj@17998
   205
		    axiom_name: axiom_name,
paulson@19964
   206
		    th: thm,
mengj@17998
   207
		    kind: kind,
mengj@17998
   208
		    literals: literal list,
mengj@17998
   209
		    ctypes_sorts: (ctyp_var * csort) list, 
mengj@17998
   210
                    ctvar_type_literals: ctype_literal list, 
mengj@17998
   211
                    ctfree_type_literals: ctype_literal list};
mengj@17998
   212
mengj@17998
   213
mengj@17998
   214
mengj@17998
   215
fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
mengj@17998
   216
fun get_axiomName (Clause cls) = #axiom_name cls;
mengj@17998
   217
fun get_clause_id (Clause cls) = #clause_id cls;
mengj@17998
   218
mengj@18440
   219
fun get_literals (c as Clause(cls)) = #literals cls;
mengj@18440
   220
mengj@17998
   221
mengj@17998
   222
(*********************************************************************)
mengj@17998
   223
(* convert a clause with type Term.term to a clause with type clause *)
mengj@17998
   224
(*********************************************************************)
mengj@17998
   225
mengj@18356
   226
fun isFalse (Literal(pol,Bool(CombConst(c,_,_)))) =
mengj@17998
   227
    (pol andalso c = "c_False") orelse
mengj@17998
   228
    (not pol andalso c = "c_True")
mengj@17998
   229
  | isFalse _ = false;
mengj@17998
   230
mengj@17998
   231
mengj@18356
   232
fun isTrue (Literal (pol,Bool(CombConst(c,_,_)))) =
mengj@17998
   233
      (pol andalso c = "c_True") orelse
mengj@17998
   234
      (not pol andalso c = "c_False")
mengj@17998
   235
  | isTrue _ = false;
mengj@17998
   236
  
mengj@17998
   237
fun isTaut (Clause {literals,...}) = exists isTrue literals;  
mengj@17998
   238
mengj@18440
   239
fun type_of (Type (a, Ts)) =
mengj@18440
   240
    let val (folTypes,ts) = types_of Ts
mengj@17998
   241
	val t = ResClause.make_fixed_type_const a
mengj@17998
   242
    in
mengj@18440
   243
	(ResClause.mk_fol_type("Comp",t,folTypes),ts)
mengj@18440
   244
    end
mengj@18440
   245
  | type_of (tp as (TFree(a,s))) =
mengj@18440
   246
    let val t = ResClause.make_fixed_type_var a
mengj@18440
   247
    in
mengj@18440
   248
	(ResClause.mk_fol_type("Fixed",t,[]),[ResClause.mk_typ_var_sort tp])
mengj@17998
   249
    end
mengj@18440
   250
  | type_of (tp as (TVar(v,s))) =
mengj@18440
   251
    let val t = ResClause.make_schematic_type_var v
mengj@18440
   252
    in
mengj@18440
   253
	(ResClause.mk_fol_type("Var",t,[]),[ResClause.mk_typ_var_sort tp])
mengj@18440
   254
    end
mengj@18356
   255
mengj@18440
   256
and types_of Ts =
mengj@18440
   257
    let val foltyps_ts = map type_of Ts
mengj@18440
   258
	val (folTyps,ts) = ListPair.unzip foltyps_ts
mengj@18440
   259
    in
mengj@18440
   260
	(folTyps,ResClause.union_all ts)
mengj@18440
   261
    end;
mengj@17998
   262
mengj@17998
   263
(* same as above, but no gathering of sort information *)
mengj@18440
   264
fun simp_type_of (Type (a, Ts)) = 
mengj@18356
   265
    let val typs = map simp_type_of Ts
mengj@17998
   266
	val t = ResClause.make_fixed_type_const a
mengj@17998
   267
    in
mengj@18440
   268
	ResClause.mk_fol_type("Comp",t,typs)
mengj@17998
   269
    end
mengj@18440
   270
  | simp_type_of (TFree (a,s)) = ResClause.mk_fol_type("Fixed",ResClause.make_fixed_type_var a,[])
mengj@18440
   271
  | simp_type_of (TVar (v,s)) = ResClause.mk_fol_type("Var",ResClause.make_schematic_type_var v,[]);
mengj@18440
   272
mengj@18356
   273
fun comb_typ ("COMBI",t) = 
mengj@18356
   274
    let val t' = domain_type t
mengj@18356
   275
    in
mengj@18356
   276
	[simp_type_of t']
mengj@18356
   277
    end
mengj@18356
   278
  | comb_typ ("COMBK",t) = 
mengj@18725
   279
    let val a = domain_type t
mengj@18725
   280
	val b = domain_type (range_type t)
mengj@18356
   281
    in
mengj@18725
   282
	map simp_type_of [a,b]
mengj@18356
   283
    end
mengj@18356
   284
  | comb_typ ("COMBS",t) = 
mengj@18356
   285
    let val t' = domain_type t
mengj@18725
   286
	val a = domain_type t'
mengj@18725
   287
	val b = domain_type (range_type t')
mengj@18725
   288
	val c = range_type (range_type t')
mengj@18356
   289
    in 
mengj@18356
   290
	map simp_type_of [a,b,c]
mengj@18356
   291
    end
mengj@18356
   292
  | comb_typ ("COMBB",t) = 
mengj@18725
   293
    let val ab = domain_type t
mengj@18725
   294
	val ca = domain_type (range_type t)
mengj@18356
   295
	val a = domain_type ab
mengj@18725
   296
	val b = range_type ab
mengj@18725
   297
	val c = domain_type ca
mengj@18356
   298
    in
mengj@18356
   299
	map simp_type_of [a,b,c]
mengj@18356
   300
    end
mengj@18356
   301
  | comb_typ ("COMBC",t) =
mengj@18356
   302
    let val t1 = domain_type t
mengj@18725
   303
	val a = domain_type t1
mengj@18725
   304
	val b = domain_type (range_type t1)
mengj@18725
   305
	val c = range_type (range_type t1)
mengj@18356
   306
    in
mengj@18356
   307
	map simp_type_of [a,b,c]
mengj@18356
   308
    end;
mengj@18356
   309
mengj@18356
   310
fun const_type_of ("COMBI",t) = 
mengj@18356
   311
    let val (tp,ts) = type_of t
mengj@18356
   312
	val I_var = comb_typ ("COMBI",t)
mengj@18356
   313
    in
mengj@18356
   314
	(tp,ts,I_var)
mengj@18356
   315
    end
mengj@18356
   316
  | const_type_of ("COMBK",t) =
mengj@18356
   317
    let val (tp,ts) = type_of t
mengj@18356
   318
	val K_var = comb_typ ("COMBK",t)
mengj@18356
   319
    in
mengj@18356
   320
	(tp,ts,K_var)
mengj@18356
   321
    end
mengj@18356
   322
  | const_type_of ("COMBS",t) =
mengj@18356
   323
    let val (tp,ts) = type_of t
mengj@18356
   324
	val S_var = comb_typ ("COMBS",t)
mengj@18356
   325
    in
mengj@18356
   326
	(tp,ts,S_var)
mengj@18356
   327
    end
mengj@18356
   328
  | const_type_of ("COMBB",t) =
mengj@18356
   329
    let val (tp,ts) = type_of t
mengj@18356
   330
	val B_var = comb_typ ("COMBB",t)
mengj@18356
   331
    in
mengj@18356
   332
	(tp,ts,B_var)
mengj@18356
   333
    end
mengj@18356
   334
  | const_type_of ("COMBC",t) =
mengj@18356
   335
    let val (tp,ts) = type_of t
mengj@18356
   336
	val C_var = comb_typ ("COMBC",t)
mengj@18356
   337
    in
mengj@18356
   338
	(tp,ts,C_var)
mengj@18356
   339
    end
mengj@18356
   340
  | const_type_of (c,t) =
mengj@18356
   341
    let val (tp,ts) = type_of t
mengj@18356
   342
	val tvars = !const_typargs(c,t)
mengj@18356
   343
	val tvars' = map simp_type_of tvars
mengj@18356
   344
    in
mengj@18356
   345
	(tp,ts,tvars')
mengj@18356
   346
    end;
mengj@18356
   347
mengj@18356
   348
fun is_bool_type (Type("bool",[])) = true
mengj@18356
   349
  | is_bool_type _ = false;
mengj@17998
   350
mengj@17998
   351
mengj@17998
   352
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
mengj@17998
   353
fun combterm_of (Const(c,t)) =
mengj@18356
   354
    let val (tp,ts,tvar_list) = const_type_of (c,t)
mengj@18356
   355
	val is_bool = is_bool_type t
mengj@18356
   356
	val c' = CombConst(ResClause.make_fixed_const c,tp,tvar_list)
mengj@17998
   357
	val c'' = if is_bool then Bool(c') else c'
mengj@17998
   358
    in
mengj@17998
   359
	(c'',ts)
mengj@17998
   360
    end
mengj@17998
   361
  | combterm_of (Free(v,t)) =
mengj@18356
   362
    let val (tp,ts) = type_of t
mengj@18356
   363
	val is_bool = is_bool_type t
mengj@17998
   364
	val v' = if ResClause.isMeta v then CombVar(ResClause.make_schematic_var(v,0),tp)
mengj@17998
   365
		 else CombFree(ResClause.make_fixed_var v,tp)
mengj@17998
   366
	val v'' = if is_bool then Bool(v') else v'
mengj@17998
   367
    in
mengj@17998
   368
	(v'',ts)
mengj@17998
   369
    end
mengj@17998
   370
  | combterm_of (Var(v,t)) =
mengj@18356
   371
    let val (tp,ts) = type_of t
mengj@18356
   372
	val is_bool = is_bool_type t
mengj@17998
   373
	val v' = CombVar(ResClause.make_schematic_var v,tp)
mengj@17998
   374
	val v'' = if is_bool then Bool(v') else v'
mengj@17998
   375
    in
mengj@17998
   376
	(v'',ts)
mengj@17998
   377
    end
mengj@17998
   378
  | combterm_of (t as (P $ Q)) =
mengj@17998
   379
    let val (P',tsP) = combterm_of P
mengj@17998
   380
	val (Q',tsQ) = combterm_of Q
mengj@17998
   381
	val tp = Term.type_of t
mengj@18356
   382
	val tp' = simp_type_of tp
mengj@18356
   383
	val is_bool = is_bool_type tp
mengj@17998
   384
	val t' = CombApp(P',Q',tp')
mengj@17998
   385
	val t'' = if is_bool then Bool(t') else t'
mengj@17998
   386
    in
mengj@17998
   387
	(t'',tsP union tsQ)
mengj@17998
   388
    end;
mengj@17998
   389
mengj@17998
   390
fun predicate_of ((Const("Not",_) $ P), polarity) =
mengj@17998
   391
    predicate_of (P, not polarity)
mengj@17998
   392
  | predicate_of (term,polarity) = (combterm_of term,polarity);
mengj@17998
   393
mengj@17998
   394
mengj@17998
   395
fun literals_of_term1 args (Const("Trueprop",_) $ P) = literals_of_term1 args P
mengj@17998
   396
  | literals_of_term1 args (Const("op |",_) $ P $ Q) = 
mengj@17998
   397
    let val args' = literals_of_term1 args P
mengj@17998
   398
    in
mengj@17998
   399
	literals_of_term1 args' Q
mengj@17998
   400
    end
mengj@17998
   401
  | literals_of_term1 (lits,ts) P =
mengj@17998
   402
    let val ((pred,ts'),pol) = predicate_of (P,true)
mengj@17998
   403
	val lits' = Literal(pol,pred)::lits
mengj@17998
   404
    in
mengj@17998
   405
	(lits',ts union ts')
mengj@17998
   406
    end;
mengj@17998
   407
mengj@17998
   408
mengj@17998
   409
fun literals_of_term P = literals_of_term1 ([],[]) P;
mengj@17998
   410
mengj@17998
   411
mengj@17998
   412
(* making axiom and conjecture clauses *)
mengj@20016
   413
fun make_clause(clause_id,axiom_name,kind,thm) =
mengj@19444
   414
    let val term = prop_of thm
mengj@20016
   415
	val term' = comb_of term
mengj@20016
   416
	val (lits,ctypes_sorts) = literals_of_term term'
paulson@18856
   417
	val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux ctypes_sorts
mengj@17998
   418
    in
mengj@20016
   419
	if forall isFalse lits
mengj@20016
   420
	then error "Problem too trivial for resolution (empty clause)"
mengj@20016
   421
	else
mengj@20016
   422
	    Clause {clause_id = clause_id, axiom_name = axiom_name, th = thm, kind = kind,
mengj@20016
   423
		    literals = lits, ctypes_sorts = ctypes_sorts, 
mengj@20016
   424
		    ctvar_type_literals = ctvar_lits,
mengj@20016
   425
		    ctfree_type_literals = ctfree_lits}
mengj@17998
   426
    end;
mengj@17998
   427
mengj@20016
   428
mengj@20016
   429
fun make_axiom_clause thm (ax_name,cls_id) = make_clause(cls_id,ax_name,Axiom,thm);
mengj@20016
   430
 
mengj@19444
   431
fun make_axiom_clauses [] = []
mengj@19444
   432
  | make_axiom_clauses ((thm,(name,id))::thms) =
mengj@19444
   433
    let val cls = make_axiom_clause thm (name,id)
mengj@19444
   434
	val clss = make_axiom_clauses thms
mengj@19354
   435
    in
paulson@20022
   436
	if isTaut cls then clss else (name,cls)::clss
mengj@19354
   437
    end;
mengj@19354
   438
mengj@19354
   439
paulson@20125
   440
fun make_conjecture_clause n thm = make_clause(n,"conjecture",Conjecture,thm);
mengj@20016
   441
 
mengj@17998
   442
mengj@17998
   443
fun make_conjecture_clauses_aux _ [] = []
mengj@17998
   444
  | make_conjecture_clauses_aux n (t::ts) =
mengj@17998
   445
    make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts;
mengj@17998
   446
mengj@17998
   447
val make_conjecture_clauses = make_conjecture_clauses_aux 0;
mengj@17998
   448
mengj@17998
   449
mengj@17998
   450
(**********************************************************************)
mengj@17998
   451
(* convert clause into ATP specific formats:                          *)
mengj@17998
   452
(* TPTP used by Vampire and E                                         *)
mengj@19720
   453
(* DFG used by SPASS                                                  *)
mengj@17998
   454
(**********************************************************************)
mengj@17998
   455
mengj@17998
   456
val type_wrapper = "typeinfo";
mengj@17998
   457
mengj@18356
   458
datatype type_level = T_FULL | T_PARTIAL | T_CONST | T_NONE;
mengj@18356
   459
paulson@19745
   460
val typ_level = ref T_CONST;
mengj@17998
   461
mengj@18356
   462
fun full_types () = (typ_level:=T_FULL);
mengj@18356
   463
fun partial_types () = (typ_level:=T_PARTIAL);
mengj@18356
   464
fun const_types_only () = (typ_level:=T_CONST);
mengj@18356
   465
fun no_types () = (typ_level:=T_NONE);
mengj@18356
   466
mengj@18356
   467
mengj@18356
   468
fun find_typ_level () = !typ_level;
mengj@18356
   469
mengj@18356
   470
fun wrap_type (c,t) = 
mengj@18356
   471
    case !typ_level of T_FULL => type_wrapper ^ (ResClause.paren_pack [c,t])
mengj@18356
   472
		     | _ => c;
mengj@18356
   473
    
mengj@17998
   474
mengj@17998
   475
val bool_tp = ResClause.make_fixed_type_const "bool";
mengj@17998
   476
mengj@17998
   477
val app_str = "hAPP";
mengj@17998
   478
mengj@17998
   479
val bool_str = "hBOOL";
mengj@17998
   480
mengj@18356
   481
exception STRING_OF_COMBTERM of int;
mengj@17998
   482
mengj@17998
   483
(* convert literals of clauses into strings *)
mengj@18440
   484
fun string_of_combterm1_aux _ (CombConst(c,tp,_)) = 
mengj@18440
   485
    let val tp' = string_of_ctyp tp
mengj@19452
   486
	val c' = if c = "equal" then "fequal" else c
mengj@18440
   487
    in
mengj@19452
   488
	(wrap_type (c',tp'),tp')
mengj@18440
   489
    end
mengj@18440
   490
  | string_of_combterm1_aux _ (CombFree(v,tp)) = 
mengj@18440
   491
    let val tp' = string_of_ctyp tp
mengj@18440
   492
    in
mengj@18440
   493
	(wrap_type (v,tp'),tp')
mengj@18440
   494
    end
mengj@18440
   495
  | string_of_combterm1_aux _ (CombVar(v,tp)) = 
mengj@18440
   496
    let val tp' = string_of_ctyp tp
mengj@18440
   497
    in
mengj@18440
   498
	(wrap_type (v,tp'),tp')
mengj@18440
   499
    end
mengj@18356
   500
  | string_of_combterm1_aux is_pred (CombApp(t1,t2,tp)) =
mengj@18356
   501
    let val (s1,tp1) = string_of_combterm1_aux is_pred t1
mengj@18356
   502
	val (s2,tp2) = string_of_combterm1_aux is_pred t2
mengj@18440
   503
	val tp' = ResClause.string_of_fol_type tp
mengj@18440
   504
	val r =	case !typ_level of T_FULL => type_wrapper ^  (ResClause.paren_pack [(app_str ^ (ResClause.paren_pack [s1,s2])),tp'])
mengj@18356
   505
				 | T_PARTIAL => app_str ^ (ResClause.paren_pack [s1,s2,tp1])
mengj@18356
   506
				 | T_NONE => app_str ^ (ResClause.paren_pack [s1,s2])
mengj@18356
   507
				 | T_CONST => raise STRING_OF_COMBTERM (1) (*should not happen, if happened may be a bug*)
mengj@18440
   508
    in	(r,tp')
mengj@18356
   509
mengj@18356
   510
    end
mengj@19452
   511
  | string_of_combterm1_aux is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) =
mengj@19452
   512
    if is_pred then 
mengj@19452
   513
	let val (s1,_) = string_of_combterm1_aux false t1
mengj@19452
   514
	    val (s2,_) = string_of_combterm1_aux false t2
mengj@19452
   515
	in
mengj@19452
   516
	    ("equal" ^ (ResClause.paren_pack [s1,s2]),bool_tp)
mengj@19452
   517
	end
mengj@19452
   518
    else
mengj@19452
   519
	let val (t,_) = string_of_combterm1_aux false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))
mengj@19452
   520
	in
mengj@19452
   521
	    (t,bool_tp)
mengj@19452
   522
	end
mengj@18356
   523
  | string_of_combterm1_aux is_pred (Bool(t)) = 
mengj@18356
   524
    let val (t',_) = string_of_combterm1_aux false t
mengj@18356
   525
	val r = if is_pred then bool_str ^ (ResClause.paren_pack [t'])
mengj@18356
   526
		else t'
mengj@17998
   527
    in
mengj@18356
   528
	(r,bool_tp)
mengj@18356
   529
    end;
mengj@18356
   530
mengj@18356
   531
fun string_of_combterm1 is_pred term = fst (string_of_combterm1_aux is_pred term);
mengj@18356
   532
mengj@18440
   533
fun string_of_combterm2 _ (CombConst(c,tp,tvars)) = 
mengj@18440
   534
    let val tvars' = map string_of_ctyp tvars
mengj@19452
   535
	val c' = if c = "equal" then "fequal" else c
mengj@18440
   536
    in
mengj@19452
   537
	c' ^ (ResClause.paren_pack tvars')
mengj@18440
   538
    end
mengj@18356
   539
  | string_of_combterm2 _ (CombFree(v,tp)) = v
mengj@18356
   540
  | string_of_combterm2 _ (CombVar(v,tp)) = v
mengj@18356
   541
  | string_of_combterm2 is_pred (CombApp(t1,t2,tp)) =
mengj@18356
   542
    let val s1 = string_of_combterm2 is_pred t1
mengj@18356
   543
	val s2 = string_of_combterm2 is_pred t2
mengj@18356
   544
    in
mengj@18356
   545
	app_str ^ (ResClause.paren_pack [s1,s2])
mengj@18356
   546
    end
mengj@19452
   547
  | string_of_combterm2 is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) =
mengj@19452
   548
    if is_pred then 
mengj@19452
   549
	let val s1 = string_of_combterm2 false t1
mengj@19452
   550
	    val s2 = string_of_combterm2 false t2
mengj@19452
   551
	in
mengj@19452
   552
	    ("equal" ^ (ResClause.paren_pack [s1,s2]))
mengj@19452
   553
	end
mengj@19452
   554
    else
mengj@19452
   555
	string_of_combterm2 false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))
mengj@19452
   556
 
mengj@18356
   557
  | string_of_combterm2 is_pred (Bool(t)) = 
mengj@18356
   558
    let val t' = string_of_combterm2 false t
mengj@17998
   559
    in
mengj@18200
   560
	if is_pred then bool_str ^ (ResClause.paren_pack [t'])
mengj@18200
   561
	else t'
mengj@17998
   562
    end;
mengj@17998
   563
mengj@18356
   564
mengj@18356
   565
mengj@18356
   566
fun string_of_combterm is_pred term = 
mengj@18356
   567
    case !typ_level of T_CONST => string_of_combterm2 is_pred term
mengj@18356
   568
		     | _ => string_of_combterm1 is_pred term;
mengj@18356
   569
mengj@18356
   570
mengj@17998
   571
fun string_of_clausename (cls_id,ax_name) = 
mengj@17998
   572
    ResClause.clause_prefix ^ ResClause.ascii_of ax_name ^ "_" ^ Int.toString cls_id;
mengj@17998
   573
mengj@17998
   574
fun string_of_type_clsname (cls_id,ax_name,idx) = 
mengj@17998
   575
    string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
mengj@17998
   576
mengj@17998
   577
mengj@19720
   578
(* tptp format *)
mengj@19720
   579
mengj@17998
   580
fun tptp_literal (Literal(pol,pred)) =
mengj@18200
   581
    let val pred_string = string_of_combterm true pred
mengj@17998
   582
	val pol_str = if pol then "++" else "--"
mengj@17998
   583
    in
mengj@17998
   584
	pol_str ^ pred_string
mengj@17998
   585
    end;
mengj@17998
   586
mengj@17998
   587
 
mengj@17998
   588
fun tptp_type_lits (Clause cls) = 
mengj@17998
   589
    let val lits = map tptp_literal (#literals cls)
mengj@17998
   590
	val ctvar_lits_strs =
mengj@18356
   591
	    case !typ_level of T_NONE => []
mengj@18356
   592
			     | _ => (map ResClause.tptp_of_typeLit (#ctvar_type_literals cls)) 
mengj@17998
   593
	val ctfree_lits = 
mengj@18356
   594
	    case !typ_level of T_NONE => []
mengj@18356
   595
			     | _ => (map ResClause.tptp_of_typeLit (#ctfree_type_literals cls)) 
mengj@17998
   596
    in
mengj@17998
   597
	(ctvar_lits_strs @ lits, ctfree_lits)
mengj@17998
   598
    end; 
mengj@18356
   599
    
mengj@18356
   600
    
mengj@17998
   601
fun clause2tptp cls =
mengj@17998
   602
    let val (lits,ctfree_lits) = tptp_type_lits cls
mengj@17998
   603
	val cls_id = get_clause_id cls
mengj@17998
   604
	val ax_name = get_axiomName cls
mengj@17998
   605
	val knd = string_of_kind cls
mengj@17998
   606
	val lits_str = ResClause.bracket_pack lits
mengj@17998
   607
	val cls_str = ResClause.gen_tptp_cls(cls_id,ax_name,knd,lits_str)
mengj@17998
   608
    in
mengj@17998
   609
	(cls_str,ctfree_lits)
mengj@17998
   610
    end;
mengj@17998
   611
mengj@17998
   612
mengj@19720
   613
(* dfg format *)
mengj@19720
   614
fun dfg_literal (Literal(pol,pred)) = ResClause.dfg_sign pol (string_of_combterm true pred);
mengj@19720
   615
mengj@19720
   616
fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = 
mengj@19720
   617
  let val lits = map dfg_literal literals
mengj@19720
   618
      val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts
mengj@19720
   619
      val tvar_lits_strs = 
mengj@19720
   620
	  case !typ_level of T_NONE => [] 
mengj@19720
   621
			    | _ => map ResClause.dfg_of_typeLit tvar_lits
mengj@19720
   622
      val tfree_lits =
mengj@19720
   623
          case !typ_level of T_NONE => []
mengj@19720
   624
			    | _ => map ResClause.dfg_of_typeLit tfree_lits 
mengj@19720
   625
  in
mengj@19720
   626
      (tvar_lits_strs @ lits, tfree_lits)
mengj@19720
   627
  end; 
mengj@19720
   628
mengj@19720
   629
fun get_uvars (CombConst(_,_,_)) vars = vars
mengj@19720
   630
  | get_uvars (CombFree(_,_)) vars = vars
mengj@19720
   631
  | get_uvars (CombVar(v,tp)) vars = (v::vars)
mengj@19720
   632
  | get_uvars (CombApp(P,Q,tp)) vars = get_uvars P (get_uvars Q vars)
mengj@19720
   633
  | get_uvars (Bool(c)) vars = get_uvars c vars;
mengj@19720
   634
mengj@19720
   635
mengj@19720
   636
fun get_uvars_l (Literal(_,c)) = get_uvars c [];
mengj@19720
   637
mengj@19720
   638
fun dfg_vars (Clause {literals,...}) = ResClause.union_all (map get_uvars_l literals);
mengj@19720
   639
 
mengj@19720
   640
fun clause2dfg (cls as Clause{axiom_name,clause_id,kind,ctypes_sorts,...}) =
mengj@19720
   641
    let val (lits,tfree_lits) = dfg_clause_aux cls 
mengj@19720
   642
        val vars = dfg_vars cls
mengj@19720
   643
        val tvars = ResClause.get_tvar_strs ctypes_sorts
mengj@19720
   644
	val knd = name_of_kind kind
mengj@19720
   645
	val lits_str = commas lits
mengj@19720
   646
	val cls_str = ResClause.gen_dfg_cls(clause_id, axiom_name, knd, lits_str, tvars@vars) 
mengj@19720
   647
    in (cls_str, tfree_lits) end;
mengj@19720
   648
mengj@19720
   649
mengj@19725
   650
fun init_combs (comb,funcs) =
mengj@19725
   651
    case !typ_level of T_CONST => 
mengj@19725
   652
		       (case comb of "c_COMBK" => Symtab.update (comb,2) funcs
mengj@19725
   653
				   | "c_COMBS" => Symtab.update (comb,3) funcs
mengj@19725
   654
				   | "c_COMBI" => Symtab.update (comb,1) funcs
mengj@19725
   655
				   | "c_COMBB" => Symtab.update (comb,3) funcs
mengj@19725
   656
				   | "c_COMBC" => Symtab.update (comb,3) funcs
mengj@19725
   657
				   | _ => funcs)
mengj@19725
   658
		     | _ => Symtab.update (comb,0) funcs;
mengj@19725
   659
mengj@19720
   660
fun init_funcs_tab funcs = 
mengj@19724
   661
    let val tp = !typ_level
mengj@19725
   662
	val funcs0 = foldl init_combs funcs ["c_COMBK","c_COMBS","c_COMBI","c_COMBB","c_COMBC"]
mengj@19725
   663
	val funcs1 = case tp of T_PARTIAL => Symtab.update ("hAPP",3) funcs0
mengj@19725
   664
				      | _ => Symtab.update ("hAPP",2) funcs0
mengj@19724
   665
	val funcs2 = case tp of T_FULL => Symtab.update ("typeinfo",2) funcs1
mengj@19724
   666
				      | _ => funcs1
mengj@19724
   667
    in
mengj@19724
   668
	case tp of T_CONST => Symtab.update ("fequal",1) (Symtab.update ("hEXTENT",2) funcs2)
mengj@19724
   669
			 | _ => Symtab.update ("fequal",0) (Symtab.update ("hEXTENT",0) funcs2)
mengj@19724
   670
    end;
mengj@19720
   671
mengj@19720
   672
mengj@19725
   673
fun add_funcs (CombConst(c,_,tvars),funcs) =
mengj@19725
   674
    if c = "equal" then foldl ResClause.add_foltype_funcs funcs tvars
mengj@19725
   675
    else
mengj@19725
   676
	(case !typ_level of T_CONST => foldl ResClause.add_foltype_funcs (Symtab.update(c,length tvars) funcs) tvars
mengj@19725
   677
			  | _ => foldl ResClause.add_foltype_funcs (Symtab.update(c,0) funcs) tvars)
mengj@19724
   678
  | add_funcs (CombFree(v,ctp),funcs) = ResClause.add_foltype_funcs (ctp,Symtab.update (v,0) funcs) 
mengj@19720
   679
  | add_funcs (CombVar(_,ctp),funcs) = ResClause.add_foltype_funcs (ctp,funcs)
mengj@19720
   680
  | add_funcs (CombApp(P,Q,_),funcs) = add_funcs(P,add_funcs (Q,funcs))
mengj@19720
   681
  | add_funcs (Bool(t),funcs) = add_funcs (t,funcs);
mengj@19720
   682
mengj@19720
   683
mengj@19720
   684
fun add_literal_funcs (Literal(_,c), funcs) = add_funcs (c,funcs);
mengj@19720
   685
mengj@19720
   686
fun add_clause_funcs (Clause {literals, ...}, funcs) =
mengj@19720
   687
    foldl add_literal_funcs funcs literals
mengj@19720
   688
    handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities")
mengj@19720
   689
mengj@19720
   690
fun funcs_of_clauses clauses arity_clauses =
mengj@19720
   691
    Symtab.dest (foldl ResClause.add_arityClause_funcs 
mengj@19720
   692
                       (foldl add_clause_funcs (init_funcs_tab Symtab.empty) clauses)
mengj@19720
   693
                       arity_clauses)
mengj@19720
   694
mengj@19720
   695
fun preds_of clsrel_clauses arity_clauses = 
mengj@19720
   696
    Symtab.dest
mengj@19720
   697
	(foldl ResClause.add_classrelClause_preds 
mengj@19720
   698
	       (foldl ResClause.add_arityClause_preds
mengj@19720
   699
		      (Symtab.update ("hBOOL",1) Symtab.empty)
mengj@19720
   700
		      arity_clauses)
mengj@19720
   701
	       clsrel_clauses)
mengj@19720
   702
mengj@18440
   703
mengj@18440
   704
(**********************************************************************)
mengj@19198
   705
(* write clauses to files                                             *)
mengj@19198
   706
(**********************************************************************)
mengj@19198
   707
mengj@19720
   708
(* tptp format *)
mengj@19720
   709
mengj@19491
   710
fun read_in fs = map (File.read o File.unpack_platform_path) fs; 
mengj@19198
   711
mengj@19491
   712
fun get_helper_clauses_tptp () =
paulson@19745
   713
  let val tlevel = case !typ_level of 
paulson@19745
   714
		       T_FULL => (Output.debug "Fully-typed HOL"; 
paulson@19745
   715
				  "~~/src/HOL/Tools/atp-inputs/full_")
paulson@19745
   716
		     | T_PARTIAL => (Output.debug "Partially-typed HOL"; 
paulson@19745
   717
				     "~~/src/HOL/Tools/atp-inputs/par_")
paulson@19745
   718
		     | T_CONST => (Output.debug "Const-only-typed HOL"; 
paulson@19745
   719
				   "~~/src/HOL/Tools/atp-inputs/const_")
paulson@19745
   720
		     | T_NONE => (Output.debug "Untyped HOL"; 
paulson@19745
   721
				  "~~/src/HOL/Tools/atp-inputs/u_")
paulson@19745
   722
      val helpers = if !include_combS 
paulson@19745
   723
                    then (Output.debug "Include combinator S"; 
paulson@19745
   724
                          ["helper1.tptp","comb_inclS.tptp"]) 
paulson@19745
   725
                    else if !include_min_comb 
paulson@19745
   726
                    then (Output.debug "Include min combinators"; 
paulson@19745
   727
                          ["helper1.tptp","comb_noS.tptp"])
paulson@19745
   728
		    else (Output.debug "No combinator is used"; ["helper1.tptp"])
paulson@19745
   729
      val t_helpers = map (curry (op ^) tlevel) helpers
paulson@19745
   730
  in
paulson@19745
   731
      read_in t_helpers
paulson@19745
   732
  end;
mengj@19491
   733
	
mengj@19491
   734
						  
mengj@19198
   735
(* write TPTP format to a single file *)
mengj@19198
   736
(* when "get_helper_clauses" is called, "include_combS" and "include_min_comb" should have correct values already *)
mengj@19491
   737
fun tptp_write_file thms filename (axclauses,classrel_clauses,arity_clauses) =
mengj@19444
   738
    let val clss = make_conjecture_clauses thms
paulson@20022
   739
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses)
mengj@19198
   740
	val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp clss)
mengj@19198
   741
	val tfree_clss = map ResClause.tptp_tfree_clause (foldl (op union_string) [] tfree_litss)
mengj@19198
   742
	val out = TextIO.openOut filename
mengj@19491
   743
	val helper_clauses = get_helper_clauses_tptp ()
mengj@19198
   744
    in
mengj@19198
   745
	List.app (curry TextIO.output out o #1 o clause2tptp) axclauses';
mengj@19198
   746
	ResClause.writeln_strs out tfree_clss;
mengj@19198
   747
	ResClause.writeln_strs out tptp_clss;
mengj@19198
   748
	List.app (curry TextIO.output out o ResClause.tptp_classrelClause) classrel_clauses;
mengj@19198
   749
	List.app (curry TextIO.output out o ResClause.tptp_arity_clause) arity_clauses;
mengj@19198
   750
	List.app (curry TextIO.output out) helper_clauses;
paulson@20022
   751
	TextIO.closeOut out;
paulson@20022
   752
	clnames
mengj@19198
   753
    end;
mengj@19198
   754
mengj@19720
   755
mengj@19720
   756
(* dfg format *)
mengj@19720
   757
fun get_helper_clauses_dfg () = 
paulson@19745
   758
 let val tlevel = case !typ_level of 
paulson@19745
   759
                      T_FULL => (Output.debug "Fully-typed HOL"; 
paulson@19745
   760
                                 "~~/src/HOL/Tools/atp-inputs/full_")
paulson@19745
   761
		    | T_PARTIAL => (Output.debug "Partially-typed HOL"; 
paulson@19745
   762
		                    "~~/src/HOL/Tools/atp-inputs/par_")
paulson@19745
   763
		    | T_CONST => (Output.debug "Const-only-typed HOL"; 
paulson@19745
   764
		                  "~~/src/HOL/Tools/atp-inputs/const_")
paulson@19745
   765
		    | T_NONE => (Output.debug "Untyped HOL"; 
paulson@19745
   766
		                 "~~/src/HOL/Tools/atp-inputs/u_")
paulson@19745
   767
     val helpers = if !include_combS 
paulson@19745
   768
                   then (Output.debug "Include combinator S"; 
paulson@19745
   769
                         ["helper1.dfg","comb_inclS.dfg"]) else
paulson@19745
   770
		   if !include_min_comb 
paulson@19745
   771
		   then (Output.debug "Include min combinators"; 
paulson@19745
   772
		         ["helper1.dfg","comb_noS.dfg"])
paulson@19745
   773
		   else (Output.debug "No combinator is used"; ["helper1.dfg"])
paulson@19745
   774
     val t_helpers = map (curry (op ^) tlevel) helpers
paulson@19745
   775
 in
paulson@19745
   776
     read_in t_helpers
paulson@19745
   777
 end;
mengj@19720
   778
mengj@19720
   779
mengj@19720
   780
fun dfg_write_file  thms filename (axclauses,classrel_clauses,arity_clauses) =
mengj@19720
   781
    let val _ = Output.debug ("Preparing to write the DFG file " ^ filename) 
mengj@19720
   782
	val conjectures = make_conjecture_clauses thms
paulson@20022
   783
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses)
mengj@19720
   784
	val (dfg_clss,tfree_litss) = ListPair.unzip (map clause2dfg conjectures)
mengj@19720
   785
	val clss = conjectures @ axclauses'
mengj@19720
   786
	val funcs = funcs_of_clauses clss arity_clauses
mengj@19720
   787
	and preds = preds_of classrel_clauses arity_clauses
mengj@19720
   788
	and probname = Path.pack (Path.base (Path.unpack filename))
mengj@19720
   789
	val (axstrs,_) =  ListPair.unzip (map clause2dfg axclauses')
mengj@19720
   790
	val tfree_clss = map ResClause.dfg_tfree_clause (ResClause.union_all tfree_litss)
mengj@19720
   791
	val out = TextIO.openOut filename
mengj@19720
   792
	val helper_clauses = get_helper_clauses_dfg ()
mengj@19720
   793
    in
mengj@19720
   794
	TextIO.output (out, ResClause.string_of_start probname); 
mengj@19720
   795
	TextIO.output (out, ResClause.string_of_descrip probname); 
mengj@19720
   796
	TextIO.output (out, ResClause.string_of_symbols (ResClause.string_of_funcs funcs) (ResClause.string_of_preds preds)); 
mengj@19720
   797
	TextIO.output (out, "list_of_clauses(axioms,cnf).\n");
mengj@19720
   798
	ResClause.writeln_strs out axstrs;
mengj@19720
   799
	List.app (curry TextIO.output out o ResClause.dfg_classrelClause) classrel_clauses;
mengj@19720
   800
	List.app (curry TextIO.output out o ResClause.dfg_arity_clause) arity_clauses;
mengj@19720
   801
	ResClause.writeln_strs out helper_clauses;
mengj@19720
   802
	TextIO.output (out, "end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n");
mengj@19720
   803
	ResClause.writeln_strs out tfree_clss;
mengj@19720
   804
	ResClause.writeln_strs out dfg_clss;
mengj@19720
   805
	TextIO.output (out, "end_of_list.\n\nend_problem.\n");
paulson@20022
   806
	TextIO.closeOut out;
paulson@20022
   807
	clnames
mengj@19720
   808
    end;
mengj@19720
   809
mengj@17998
   810
end