src/HOL/Tools/res_hol_clause.ML
author mengj
Mon, 28 Nov 2005 07:17:07 +0100
changeset 18276 c62ec94e326e
parent 18200 9d476d1054d7
child 18356 443717b3a9ad
permissions -rw-r--r--
Added flags for setting and detecting whether a problem needs combinators.
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@17998
    16
mengj@17998
    17
(**********************************************************************)
mengj@17998
    18
(* convert a Term.term with lambdas into a Term.term with combinators *) 
mengj@17998
    19
(**********************************************************************)
mengj@17998
    20
mengj@17998
    21
fun is_free (Bound(a)) n = (a = n)
mengj@17998
    22
  | is_free (Abs(x,_,b)) n = (is_free b (n+1))
mengj@17998
    23
  | is_free (P $ Q) n = ((is_free P n) orelse (is_free Q n))
mengj@17998
    24
  | is_free _ _ = false;
mengj@17998
    25
mengj@17998
    26
mengj@17998
    27
exception LAM2COMB of term;
mengj@17998
    28
mengj@17998
    29
exception BND of term;
mengj@17998
    30
mengj@17998
    31
fun decre_bndVar (Bound n) = Bound (n-1)
mengj@17998
    32
  | decre_bndVar (P $ Q) = (decre_bndVar P) $ (decre_bndVar Q)
mengj@17998
    33
  | decre_bndVar t =
mengj@17998
    34
    case t of Const(_,_) => t
mengj@17998
    35
	    | Free(_,_) => t
mengj@17998
    36
	    | Var(_,_) => t
mengj@17998
    37
	    | Abs(_,_,_) => raise BND(t); (*should not occur*)
mengj@17998
    38
mengj@17998
    39
mengj@17998
    40
(*******************************************)
mengj@17998
    41
fun lam2comb (Abs(x,tp,Bound 0)) _ = 
mengj@17998
    42
    let val tpI = Type("fun",[tp,tp])
mengj@17998
    43
    in 
mengj@18276
    44
	include_min_comb:=true;
mengj@17998
    45
	Const("COMBI",tpI) 
mengj@17998
    46
    end
mengj@17998
    47
  | lam2comb (Abs(x,t1,Const(c,t2))) _ = 
mengj@17998
    48
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
mengj@17998
    49
    in 
mengj@18276
    50
	include_min_comb:=true;
mengj@17998
    51
	Const("COMBK",tK) $ Const(c,t2) 
mengj@17998
    52
    end
mengj@17998
    53
  | lam2comb (Abs(x,t1,Free(v,t2))) _ =
mengj@17998
    54
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
mengj@17998
    55
    in
mengj@18276
    56
	include_min_comb:=true;
mengj@17998
    57
	Const("COMBK",tK) $ Free(v,t2)
mengj@17998
    58
    end
mengj@17998
    59
  | lam2comb (Abs(x,t1,Var(ind,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) $ Var(ind,t2)
mengj@17998
    64
    end
mengj@17998
    65
  | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds =
mengj@17998
    66
    let val nfreeP = not(is_free P 0)
mengj@17998
    67
	val tr = Term.type_of1(t1::Bnds,P)
mengj@17998
    68
    in
mengj@17998
    69
	if nfreeP then (decre_bndVar P)
mengj@17998
    70
	else (
mengj@17998
    71
	      let val tI = Type("fun",[t1,t1])
mengj@17998
    72
		  val P' = lam2comb (Abs(x,t1,P)) Bnds
mengj@17998
    73
		  val tp' = Term.type_of1(Bnds,P')
mengj@17998
    74
		  val tS = Type("fun",[tp',Type("fun",[tI,tr])])
mengj@17998
    75
	      in
mengj@18276
    76
		  include_min_comb:=true;
mengj@18276
    77
		  include_combS:=true;
mengj@17998
    78
		  Const("COMBS",tS) $ P' $ Const("COMBI",tI)
mengj@17998
    79
	      end)
mengj@17998
    80
    end
mengj@17998
    81
	    
mengj@17998
    82
  | lam2comb (t as (Abs(x,t1,P$Q))) Bnds =
mengj@17998
    83
    let val (nfreeP,nfreeQ) = (not(is_free P 0),not(is_free Q 0))
mengj@17998
    84
	val tpq = Term.type_of1(t1::Bnds, P$Q) 
mengj@17998
    85
    in
mengj@17998
    86
	if(nfreeP andalso nfreeQ) then (
mengj@17998
    87
	    let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])])
mengj@17998
    88
		val PQ' = decre_bndVar(P $ Q)
mengj@17998
    89
	    in 
mengj@18276
    90
		include_min_comb:=true;
mengj@17998
    91
		Const("COMBK",tK) $ PQ'
mengj@17998
    92
	    end)
mengj@17998
    93
	else (
mengj@17998
    94
	      if nfreeP then (
mengj@17998
    95
			       let val Q' = lam2comb (Abs(x,t1,Q)) Bnds
mengj@17998
    96
				   val P' = decre_bndVar P
mengj@17998
    97
				   val tp = Term.type_of1(Bnds,P')
mengj@17998
    98
				   val tq' = Term.type_of1(Bnds, Q')
mengj@17998
    99
				   val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])])
mengj@17998
   100
			       in
mengj@18276
   101
				   include_min_comb:=true;
mengj@17998
   102
				   Const("COMBB",tB) $ P' $ Q' 
mengj@17998
   103
			       end)
mengj@17998
   104
	      else (
mengj@17998
   105
		    if nfreeQ then (
mengj@17998
   106
				    let val P' = lam2comb (Abs(x,t1,P)) Bnds
mengj@17998
   107
					val Q' = decre_bndVar Q
mengj@17998
   108
					val tq = Term.type_of1(Bnds,Q')
mengj@17998
   109
					val tp' = Term.type_of1(Bnds, P')
mengj@17998
   110
					val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])])
mengj@17998
   111
				    in
mengj@18276
   112
					include_min_comb:=true;
mengj@17998
   113
					Const("COMBC",tC) $ P' $ Q'
mengj@17998
   114
				    end)
mengj@17998
   115
		    else(
mengj@17998
   116
			 let val P' = lam2comb (Abs(x,t1,P)) Bnds
mengj@17998
   117
			     val Q' = lam2comb (Abs(x,t1,Q)) Bnds
mengj@17998
   118
			     val tp' = Term.type_of1(Bnds,P')
mengj@17998
   119
			     val tq' = Term.type_of1(Bnds,Q')
mengj@17998
   120
			     val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])])
mengj@17998
   121
			 in
mengj@18276
   122
			     include_min_comb:=true;
mengj@18276
   123
			     include_combS:=true;
mengj@17998
   124
			     Const("COMBS",tS) $ P' $ Q'
mengj@17998
   125
			 end)))
mengj@17998
   126
    end
mengj@17998
   127
  | lam2comb (t as (Abs(x,t1,_))) _ = raise LAM2COMB (t);
mengj@17998
   128
mengj@17998
   129
	     
mengj@17998
   130
mengj@17998
   131
(*********************)
mengj@17998
   132
mengj@17998
   133
fun to_comb (Abs(x,tp,b)) Bnds =
mengj@17998
   134
    let val b' = to_comb b (tp::Bnds)
mengj@17998
   135
    in lam2comb (Abs(x,tp,b')) Bnds end
mengj@17998
   136
  | to_comb (P $ Q) Bnds = ((to_comb P Bnds) $ (to_comb Q Bnds))
mengj@17998
   137
  | to_comb t _ = t;
mengj@17998
   138
 
mengj@17998
   139
    
mengj@17998
   140
fun comb_of t = to_comb t [];
mengj@17998
   141
mengj@17998
   142
mengj@17998
   143
(* print a term containing combinators, used for debugging *)
mengj@17998
   144
exception TERM_COMB of term;
mengj@17998
   145
mengj@17998
   146
fun string_of_term (Const(c,t)) = c
mengj@17998
   147
  | string_of_term (Free(v,t)) = v
mengj@17998
   148
  | string_of_term (Var((x,n),t)) =
mengj@17998
   149
    let val xn = x ^ "_" ^ (string_of_int n)
mengj@17998
   150
    in xn end
mengj@17998
   151
  | string_of_term (P $ Q) =
mengj@17998
   152
    let val P' = string_of_term P
mengj@17998
   153
	val Q' = string_of_term Q
mengj@17998
   154
    in
mengj@17998
   155
	"(" ^ P' ^ " " ^ Q' ^ ")" end
mengj@17998
   156
  | string_of_term t =  raise TERM_COMB (t);
mengj@17998
   157
mengj@17998
   158
mengj@17998
   159
mengj@17998
   160
(******************************************************)
mengj@17998
   161
(* data types for typed combinator expressions        *)
mengj@17998
   162
(******************************************************)
mengj@17998
   163
mengj@17998
   164
type axiom_name = string;
mengj@17998
   165
datatype kind = Axiom | Conjecture;
mengj@17998
   166
fun name_of_kind Axiom = "axiom"
mengj@17998
   167
  | name_of_kind Conjecture = "conjecture";
mengj@17998
   168
mengj@17998
   169
type polarity = bool;
mengj@17998
   170
type indexname = Term.indexname;
mengj@17998
   171
type clause_id = int;
mengj@17998
   172
type csort = Term.sort;
mengj@17998
   173
type ctyp = string;
mengj@17998
   174
mengj@17998
   175
type ctyp_var = ResClause.typ_var;
mengj@17998
   176
mengj@17998
   177
type ctype_literal = ResClause.type_literal;
mengj@17998
   178
mengj@17998
   179
mengj@17998
   180
datatype combterm = CombConst of string * ctyp
mengj@17998
   181
		  | CombFree of string * ctyp
mengj@17998
   182
		  | CombVar of string * ctyp
mengj@17998
   183
		  | CombApp of combterm * combterm * ctyp
mengj@17998
   184
		  | Bool of combterm
mengj@17998
   185
		  | Equal of combterm * combterm;
mengj@17998
   186
datatype literal = Literal of polarity * combterm;
mengj@17998
   187
mengj@17998
   188
mengj@17998
   189
mengj@17998
   190
datatype clause = 
mengj@17998
   191
	 Clause of {clause_id: clause_id,
mengj@17998
   192
		    axiom_name: axiom_name,
mengj@17998
   193
		    kind: kind,
mengj@17998
   194
		    literals: literal list,
mengj@17998
   195
		    ctypes_sorts: (ctyp_var * csort) list, 
mengj@17998
   196
                    ctvar_type_literals: ctype_literal list, 
mengj@17998
   197
                    ctfree_type_literals: ctype_literal list};
mengj@17998
   198
mengj@17998
   199
mengj@17998
   200
mengj@17998
   201
fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
mengj@17998
   202
fun get_axiomName (Clause cls) = #axiom_name cls;
mengj@17998
   203
fun get_clause_id (Clause cls) = #clause_id cls;
mengj@17998
   204
mengj@17998
   205
mengj@17998
   206
mengj@17998
   207
mengj@17998
   208
(*********************************************************************)
mengj@17998
   209
(* convert a clause with type Term.term to a clause with type clause *)
mengj@17998
   210
(*********************************************************************)
mengj@17998
   211
mengj@17998
   212
fun isFalse (Literal(pol,Bool(CombConst(c,_)))) =
mengj@17998
   213
    (pol andalso c = "c_False") orelse
mengj@17998
   214
    (not pol andalso c = "c_True")
mengj@17998
   215
  | isFalse _ = false;
mengj@17998
   216
mengj@17998
   217
mengj@17998
   218
fun isTrue (Literal (pol,Bool(CombConst(c,_)))) =
mengj@17998
   219
      (pol andalso c = "c_True") orelse
mengj@17998
   220
      (not pol andalso c = "c_False")
mengj@17998
   221
  | isTrue _ = false;
mengj@17998
   222
  
mengj@17998
   223
fun isTaut (Clause {literals,...}) = exists isTrue literals;  
mengj@17998
   224
mengj@17998
   225
mengj@17998
   226
mengj@17998
   227
fun make_clause(clause_id,axiom_name,kind,literals,ctypes_sorts,ctvar_type_literals,ctfree_type_literals) =
mengj@17998
   228
    if forall isFalse literals
mengj@17998
   229
    then error "Problem too trivial for resolution (empty clause)"
mengj@17998
   230
    else
mengj@17998
   231
	Clause {clause_id = clause_id, axiom_name = axiom_name, kind = kind,
mengj@17998
   232
		literals = literals, ctypes_sorts = ctypes_sorts, 
mengj@17998
   233
		ctvar_type_literals = ctvar_type_literals,
mengj@17998
   234
		ctfree_type_literals = ctfree_type_literals};
mengj@17998
   235
mengj@17998
   236
mengj@17998
   237
(* convert a Term.type to a string; gather sort information of type variables; also check if the type is a bool type *)
mengj@17998
   238
mengj@17998
   239
fun type_of (Type (a, [])) = ((ResClause.make_fixed_type_const a,[]),a ="bool")
mengj@17998
   240
  | type_of (Type (a, Ts)) = 
mengj@17998
   241
    let val typbs = map type_of Ts
mengj@17998
   242
	val (types,_) = ListPair.unzip typbs
mengj@17998
   243
	val (ctyps,tvarSorts) = ListPair.unzip types
mengj@17998
   244
	val ts = ResClause.union_all tvarSorts
mengj@17998
   245
	val t = ResClause.make_fixed_type_const a
mengj@17998
   246
    in
mengj@17998
   247
	(((t ^ ResClause.paren_pack ctyps),ts),false)
mengj@17998
   248
    end
mengj@17998
   249
  | type_of (tp as (TFree (a,s))) = ((ResClause.make_fixed_type_var a,[ResClause.mk_typ_var_sort tp]),false)
mengj@17998
   250
  | type_of (tp as (TVar (v,s))) = ((ResClause.make_schematic_type_var v,[ResClause.mk_typ_var_sort tp]),false);
mengj@17998
   251
mengj@17998
   252
mengj@17998
   253
(* same as above, but no gathering of sort information *)
mengj@17998
   254
fun simp_type_of (Type (a, [])) = (ResClause.make_fixed_type_const a,a ="bool")
mengj@17998
   255
  | simp_type_of (Type (a, Ts)) = 
mengj@17998
   256
    let val typbs = map simp_type_of Ts
mengj@17998
   257
	val (types,_) = ListPair.unzip typbs
mengj@17998
   258
	val t = ResClause.make_fixed_type_const a
mengj@17998
   259
    in
mengj@17998
   260
	((t ^ ResClause.paren_pack types),false)
mengj@17998
   261
    end
mengj@17998
   262
  | simp_type_of (TFree (a,s)) = (ResClause.make_fixed_type_var a,false)
mengj@17998
   263
  | simp_type_of (TVar (v,s)) = (ResClause.make_schematic_type_var v,false);
mengj@17998
   264
mengj@17998
   265
mengj@17998
   266
mengj@17998
   267
mengj@17998
   268
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
mengj@17998
   269
fun combterm_of (Const(c,t)) =
mengj@17998
   270
    let val ((tp,ts),is_bool) = type_of t
mengj@17998
   271
	val c' = CombConst(ResClause.make_fixed_const c,tp)
mengj@17998
   272
	val c'' = if is_bool then Bool(c') else c'
mengj@17998
   273
    in
mengj@17998
   274
	(c'',ts)
mengj@17998
   275
    end
mengj@17998
   276
  | combterm_of (Free(v,t)) =
mengj@17998
   277
    let val ((tp,ts),is_bool) = type_of t
mengj@17998
   278
	val v' = if ResClause.isMeta v then CombVar(ResClause.make_schematic_var(v,0),tp)
mengj@17998
   279
		 else CombFree(ResClause.make_fixed_var v,tp)
mengj@17998
   280
	val v'' = if is_bool then Bool(v') else v'
mengj@17998
   281
    in
mengj@17998
   282
	(v'',ts)
mengj@17998
   283
    end
mengj@17998
   284
  | combterm_of (Var(v,t)) =
mengj@17998
   285
    let val ((tp,ts),is_bool) = type_of t
mengj@17998
   286
	val v' = CombVar(ResClause.make_schematic_var v,tp)
mengj@17998
   287
	val v'' = if is_bool then Bool(v') else v'
mengj@17998
   288
    in
mengj@17998
   289
	(v'',ts)
mengj@17998
   290
    end
mengj@17998
   291
  | combterm_of (Const("op =",T) $ P $ Q) = (*FIXME: allow equal between bools?*)
mengj@17998
   292
    let val (P',tsP) = combterm_of P        
mengj@17998
   293
	val (Q',tsQ) = combterm_of Q
mengj@17998
   294
    in
mengj@17998
   295
	(Equal(P',Q'),tsP union tsQ)
mengj@17998
   296
    end
mengj@17998
   297
  | combterm_of (t as (P $ Q)) =
mengj@17998
   298
    let val (P',tsP) = combterm_of P
mengj@17998
   299
	val (Q',tsQ) = combterm_of Q
mengj@17998
   300
	val tp = Term.type_of t
mengj@17998
   301
	val (tp',is_bool) = simp_type_of tp
mengj@17998
   302
	val t' = CombApp(P',Q',tp')
mengj@17998
   303
	val t'' = if is_bool then Bool(t') else t'
mengj@17998
   304
    in
mengj@17998
   305
	(t'',tsP union tsQ)
mengj@17998
   306
    end;
mengj@17998
   307
mengj@17998
   308
fun predicate_of ((Const("Not",_) $ P), polarity) =
mengj@17998
   309
    predicate_of (P, not polarity)
mengj@17998
   310
  | predicate_of (term,polarity) = (combterm_of term,polarity);
mengj@17998
   311
mengj@17998
   312
mengj@17998
   313
fun literals_of_term1 args (Const("Trueprop",_) $ P) = literals_of_term1 args P
mengj@17998
   314
  | literals_of_term1 args (Const("op |",_) $ P $ Q) = 
mengj@17998
   315
    let val args' = literals_of_term1 args P
mengj@17998
   316
    in
mengj@17998
   317
	literals_of_term1 args' Q
mengj@17998
   318
    end
mengj@17998
   319
  | literals_of_term1 (lits,ts) P =
mengj@17998
   320
    let val ((pred,ts'),pol) = predicate_of (P,true)
mengj@17998
   321
	val lits' = Literal(pol,pred)::lits
mengj@17998
   322
    in
mengj@17998
   323
	(lits',ts union ts')
mengj@17998
   324
    end;
mengj@17998
   325
mengj@17998
   326
mengj@17998
   327
fun literals_of_term P = literals_of_term1 ([],[]) P;
mengj@17998
   328
mengj@17998
   329
mengj@17998
   330
(* making axiom and conjecture clauses *)
mengj@17998
   331
fun make_axiom_clause term (ax_name,cls_id) =
mengj@17998
   332
    let val term' = comb_of term
mengj@17998
   333
	val (lits,ctypes_sorts) = literals_of_term term'
mengj@17998
   334
	val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux2 ctypes_sorts
mengj@17998
   335
    in
mengj@17998
   336
	make_clause(cls_id,ax_name,Axiom,
mengj@17998
   337
		    lits,ctypes_sorts,ctvar_lits,ctfree_lits)
mengj@17998
   338
    end;
mengj@17998
   339
mengj@17998
   340
mengj@17998
   341
fun make_conjecture_clause n t =
mengj@17998
   342
    let val t' = comb_of t
mengj@17998
   343
	val (lits,ctypes_sorts) = literals_of_term t'
mengj@17998
   344
	val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux2 ctypes_sorts
mengj@17998
   345
    in
mengj@17998
   346
	make_clause(n,"conjecture",Conjecture,lits,ctypes_sorts,ctvar_lits,ctfree_lits)
mengj@17998
   347
    end;
mengj@17998
   348
mengj@17998
   349
mengj@17998
   350
mengj@17998
   351
fun make_conjecture_clauses_aux _ [] = []
mengj@17998
   352
  | make_conjecture_clauses_aux n (t::ts) =
mengj@17998
   353
    make_conjecture_clause n t :: make_conjecture_clauses_aux (n+1) ts;
mengj@17998
   354
mengj@17998
   355
val make_conjecture_clauses = make_conjecture_clauses_aux 0;
mengj@17998
   356
mengj@17998
   357
mengj@17998
   358
(**********************************************************************)
mengj@17998
   359
(* convert clause into ATP specific formats:                          *)
mengj@17998
   360
(* TPTP used by Vampire and E                                         *)
mengj@17998
   361
(**********************************************************************)
mengj@17998
   362
mengj@17998
   363
val keep_types = ref true;
mengj@17998
   364
mengj@17998
   365
val type_wrapper = "typeinfo";
mengj@17998
   366
mengj@17998
   367
fun put_type (c,t) = 
mengj@17998
   368
    if !keep_types then type_wrapper ^ (ResClause.paren_pack [c,t])
mengj@17998
   369
    else c;
mengj@17998
   370
mengj@17998
   371
mengj@17998
   372
val bool_tp = ResClause.make_fixed_type_const "bool";
mengj@17998
   373
mengj@17998
   374
val app_str = "hAPP";
mengj@17998
   375
mengj@17998
   376
val bool_str = "hBOOL";
mengj@17998
   377
mengj@17998
   378
mengj@17998
   379
(* convert literals of clauses into strings *)
mengj@18200
   380
fun string_of_combterm _ (CombConst(c,tp)) = put_type(c,tp)
mengj@18200
   381
  | string_of_combterm _ (CombFree(v,tp)) = put_type(v,tp)
mengj@18200
   382
  | string_of_combterm _ (CombVar(v,tp)) = put_type(v,tp)
mengj@18200
   383
  | string_of_combterm is_pred (CombApp(t1,t2,tp)) = 
mengj@18200
   384
    let val s1 = string_of_combterm is_pred t1
mengj@18200
   385
	val s2 = string_of_combterm is_pred t2
mengj@17998
   386
	val app = app_str ^ (ResClause.paren_pack [s1,s2])
mengj@17998
   387
    in
mengj@18200
   388
	put_type(app,tp)
mengj@17998
   389
    end
mengj@18200
   390
  | string_of_combterm is_pred (Bool(t)) = 
mengj@18200
   391
    let val t' = string_of_combterm false t
mengj@17998
   392
    in
mengj@18200
   393
	if is_pred then bool_str ^ (ResClause.paren_pack [t'])
mengj@18200
   394
	else t'
mengj@17998
   395
    end
mengj@18200
   396
  | string_of_combterm _ (Equal(t1,t2)) =
mengj@18200
   397
    let val s1 = string_of_combterm false t1
mengj@18200
   398
	val s2 = string_of_combterm false t2
mengj@17998
   399
    in
mengj@17998
   400
	"equal" ^ (ResClause.paren_pack [s1,s2]) 
mengj@17998
   401
    end;
mengj@17998
   402
mengj@17998
   403
fun string_of_clausename (cls_id,ax_name) = 
mengj@17998
   404
    ResClause.clause_prefix ^ ResClause.ascii_of ax_name ^ "_" ^ Int.toString cls_id;
mengj@17998
   405
mengj@17998
   406
fun string_of_type_clsname (cls_id,ax_name,idx) = 
mengj@17998
   407
    string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
mengj@17998
   408
mengj@17998
   409
mengj@17998
   410
fun tptp_literal (Literal(pol,pred)) =
mengj@18200
   411
    let val pred_string = string_of_combterm true pred
mengj@17998
   412
	val pol_str = if pol then "++" else "--"
mengj@17998
   413
    in
mengj@17998
   414
	pol_str ^ pred_string
mengj@17998
   415
    end;
mengj@17998
   416
mengj@17998
   417
 
mengj@17998
   418
fun tptp_type_lits (Clause cls) = 
mengj@17998
   419
    let val lits = map tptp_literal (#literals cls)
mengj@17998
   420
	val ctvar_lits_strs =
mengj@17998
   421
	      if !keep_types 
mengj@17998
   422
	      then (map ResClause.tptp_of_typeLit (#ctvar_type_literals cls)) 
mengj@17998
   423
	      else []
mengj@17998
   424
	val ctfree_lits = 
mengj@17998
   425
	      if !keep_types
mengj@17998
   426
	      then (map ResClause.tptp_of_typeLit (#ctfree_type_literals cls)) 
mengj@17998
   427
	      else []
mengj@17998
   428
    in
mengj@17998
   429
	(ctvar_lits_strs @ lits, ctfree_lits)
mengj@17998
   430
    end; 
mengj@17998
   431
mengj@17998
   432
mengj@17998
   433
fun clause2tptp cls =
mengj@17998
   434
    let val (lits,ctfree_lits) = tptp_type_lits cls
mengj@17998
   435
	val cls_id = get_clause_id cls
mengj@17998
   436
	val ax_name = get_axiomName cls
mengj@17998
   437
	val knd = string_of_kind cls
mengj@17998
   438
	val lits_str = ResClause.bracket_pack lits
mengj@17998
   439
	val cls_str = ResClause.gen_tptp_cls(cls_id,ax_name,knd,lits_str)
mengj@17998
   440
    in
mengj@17998
   441
	(cls_str,ctfree_lits)
mengj@17998
   442
    end;
mengj@17998
   443
mengj@17998
   444
mengj@17998
   445
end