src/HOL/Tools/res_hol_clause.ML
author paulson
Thu, 21 Sep 2006 17:31:10 +0200
changeset 20660 8606ddd42554
parent 20644 ff938c7b15e8
child 20791 497e1c9d4a9f
permissions -rw-r--r--
corrected for the translation from _ to __ in c_COMBx_e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     1
(* ID: $Id$ 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     2
   Author: Jia Meng, NICTA
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     3
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     4
FOL clauses translated from HOL formulae.  Combinators are used to represent lambda terms.
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     5
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     6
*)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     7
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     8
structure ResHolClause =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     9
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    10
struct
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    11
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    12
(* a flag to set if we use extra combinators B',C',S' *)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    13
val use_combB'C'S' = ref true;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    14
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    15
val combI_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    16
val combK_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    17
val combB_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    18
val combC_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    19
val combS_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    20
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    21
val combB'_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    22
val combC'_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    23
val combS'_count = ref 0; 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    24
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    25
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    26
fun increI count_comb =  if count_comb then combI_count := !combI_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    27
fun increK count_comb =  if count_comb then combK_count := !combK_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    28
fun increB count_comb =  if count_comb then combB_count := !combB_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    29
fun increC count_comb =  if count_comb then combC_count := !combC_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    30
fun increS count_comb =  if count_comb then combS_count := !combS_count + 1 else (); 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    31
fun increB' count_comb =  if count_comb then combB'_count := !combB'_count + 1 else (); 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    32
fun increC' count_comb =  if count_comb then combC'_count := !combC'_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    33
fun increS' count_comb =  if count_comb then combS'_count := !combS'_count + 1 else (); 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    34
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    35
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    36
exception DECRE_COMB of string;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    37
fun decreB count_comb n = if count_comb then (if !combB_count >= n then combB_count := !combB_count - n else raise (DECRE_COMB "COMBB")) else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    38
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    39
fun decreC count_comb n = if count_comb then (if !combC_count >= n then combC_count := !combC_count - n else raise (DECRE_COMB "COMBC")) else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    40
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    41
fun decreS count_comb n = if count_comb then (if !combS_count >= n then combS_count := !combS_count - n else raise (DECRE_COMB "COMBS")) else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    42
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
    43
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
    44
val const_typargs = ref (Library.K [] : (string*typ -> typ list));
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
    45
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    46
fun init thy = (combI_count:=0; combK_count:=0;combB_count:=0;combC_count:=0;combS_count:=0;combB'_count:=0;combC'_count:=0;combS'_count:=0;
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
    47
                const_typargs := Sign.const_typargs thy);
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
    48
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    49
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    50
(* convert a Term.term with lambdas into a Term.term with combinators *) 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    51
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    52
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    53
fun is_free (Bound(a)) n = (a = n)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    54
  | is_free (Abs(x,_,b)) n = (is_free b (n+1))
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    55
  | is_free (P $ Q) n = ((is_free P n) orelse (is_free Q n))
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    56
  | is_free _ _ = false;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    57
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    58
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    59
exception LAM2COMB of term;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    60
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    61
exception BND of term;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    62
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    63
fun decre_bndVar (Bound n) = Bound (n-1)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    64
  | decre_bndVar (P $ Q) = (decre_bndVar P) $ (decre_bndVar Q)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    65
  | decre_bndVar t =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    66
    case t of Const(_,_) => t
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    67
	    | Free(_,_) => t
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    68
	    | Var(_,_) => t
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    69
	    | Abs(_,_,_) => raise BND(t); (*should not occur*)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    70
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    71
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    72
(*******************************************)
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    73
fun mk_compact_comb (tm as (Const("COMBB",_)$p) $ (Const("COMBB",_)$q$r)) Bnds count_comb =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    74
    let val tp_p = Term.type_of1(Bnds,p)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    75
	val tp_q = Term.type_of1(Bnds,q)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    76
	val tp_r = Term.type_of1(Bnds,r)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    77
	val typ = Term.type_of1(Bnds,tm)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    78
	val typ_B' = [tp_p,tp_q,tp_r] ---> typ
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    79
	val _ = increB' count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    80
	val _ = decreB count_comb 2
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    81
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    82
	Const("COMBB_e",typ_B') $ p $ q $ r
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    83
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    84
  | mk_compact_comb (tm as (Const("COMBC",_) $ (Const("COMBB",_)$p$q) $ r)) Bnds count_comb =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    85
    let val tp_p = Term.type_of1(Bnds,p)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    86
	val tp_q = Term.type_of1(Bnds,q)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    87
	val tp_r = Term.type_of1(Bnds,r)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    88
	val typ = Term.type_of1(Bnds,tm)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    89
	val typ_C' = [tp_p,tp_q,tp_r] ---> typ
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    90
	val _ = increC' count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    91
	val _ = decreC count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    92
	val _ = decreB count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    93
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    94
	Const("COMBC_e",typ_C') $ p $ q $ r
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    95
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    96
  | mk_compact_comb (tm as (Const("COMBS",_) $ (Const("COMBB",_)$p$q) $ r)) Bnds count_comb =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    97
    let val tp_p = Term.type_of1(Bnds,p)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    98
	val tp_q = Term.type_of1(Bnds,q)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    99
	val tp_r = Term.type_of1(Bnds,r)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   100
	val typ = Term.type_of1(Bnds,tm)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   101
	val typ_S' = [tp_p,tp_q,tp_r] ---> typ
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   102
	val _ = increS' count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   103
	val _ = decreS count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   104
	val _ = decreB count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   105
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   106
	Const("COMBS_e",typ_S') $ p $ q $ r
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   107
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   108
  | mk_compact_comb tm _ _ = tm;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   109
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   110
fun compact_comb t Bnds count_comb = if !use_combB'C'S' then mk_compact_comb t Bnds count_comb else t;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   111
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   112
fun lam2comb (Abs(x,tp,Bound 0)) _ count_comb = 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   113
    let val tpI = Type("fun",[tp,tp])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   114
	val _ = increI count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   115
    in 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   116
	Const("COMBI",tpI) 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   117
    end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   118
  | lam2comb (Abs(x,tp,Bound n)) Bnds count_comb = 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   119
    let val (Bound n') = decre_bndVar (Bound n)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   120
	val tb = List.nth(Bnds,n')
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   121
	val tK = Type("fun",[tb,Type("fun",[tp,tb])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   122
	val _ = increK count_comb 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   123
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   124
	Const("COMBK",tK) $ (Bound n')
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   125
    end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   126
  | lam2comb (Abs(x,t1,Const(c,t2))) _ count_comb = 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   127
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   128
	val _ = increK count_comb 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   129
    in 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   130
	Const("COMBK",tK) $ Const(c,t2) 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   131
    end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   132
  | lam2comb (Abs(x,t1,Free(v,t2))) _ count_comb =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   133
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   134
	val _ = increK count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   135
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   136
	Const("COMBK",tK) $ Free(v,t2)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   137
    end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   138
  | lam2comb (Abs(x,t1,Var(ind,t2))) _ count_comb =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   139
    let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   140
	val _ = increK count_comb 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   141
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   142
	Const("COMBK",tK) $ Var(ind,t2)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   143
    end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   144
  | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds count_comb =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   145
    let val nfreeP = not(is_free P 0)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   146
	val tr = Term.type_of1(t1::Bnds,P)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   147
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   148
	if nfreeP then (decre_bndVar P)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   149
	else (
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   150
	      let val tI = Type("fun",[t1,t1])
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   151
		  val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   152
		  val tp' = Term.type_of1(Bnds,P')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   153
		  val tS = Type("fun",[tp',Type("fun",[tI,tr])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   154
		  val _ = increI count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   155
		  val _ = increS count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   156
	      in
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   157
		  compact_comb (Const("COMBS",tS) $ P' $ Const("COMBI",tI)) Bnds count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   158
	      end)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   159
    end
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   160
	    
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   161
  | lam2comb (t as (Abs(x,t1,P$Q))) Bnds count_comb =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   162
    let val (nfreeP,nfreeQ) = (not(is_free P 0),not(is_free Q 0))
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   163
	val tpq = Term.type_of1(t1::Bnds, P$Q) 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   164
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   165
	if(nfreeP andalso nfreeQ) then (
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   166
	    let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])])
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   167
		val PQ' = decre_bndVar(P $ Q)
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   168
		val _ = increK count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   169
	    in 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   170
		Const("COMBK",tK) $ PQ'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   171
	    end)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   172
	else (
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   173
	      if nfreeP then (
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   174
			       let val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   175
				   val P' = decre_bndVar P
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   176
				   val tp = Term.type_of1(Bnds,P')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   177
				   val tq' = Term.type_of1(Bnds, Q')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   178
				   val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   179
				   val _ = increB count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   180
			       in
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   181
				   compact_comb (Const("COMBB",tB) $ P' $ Q') Bnds count_comb 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   182
			       end)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   183
	      else (
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   184
		    if nfreeQ then (
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   185
				    let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   186
					val Q' = decre_bndVar Q
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   187
					val tq = Term.type_of1(Bnds,Q')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   188
					val tp' = Term.type_of1(Bnds, P')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   189
					val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   190
					val _ = increC count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   191
				    in
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   192
					compact_comb (Const("COMBC",tC) $ P' $ Q') Bnds count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   193
				    end)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   194
		    else(
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   195
			 let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   196
			     val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   197
			     val tp' = Term.type_of1(Bnds,P')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   198
			     val tq' = Term.type_of1(Bnds,Q')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   199
			     val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])])
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   200
			     val _ = increS count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   201
			 in
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   202
			     compact_comb (Const("COMBS",tS) $ P' $ Q') Bnds count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   203
			 end)))
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   204
    end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   205
  | lam2comb (t as (Abs(x,t1,_))) _ _ = raise LAM2COMB (t);
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   206
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   207
(*********************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   208
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   209
fun to_comb (Abs(x,tp,b)) Bnds count_comb =
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   210
    let val b' = to_comb b (tp::Bnds) count_comb
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   211
    in lam2comb (Abs(x,tp,b')) Bnds count_comb end
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   212
  | to_comb (P $ Q) Bnds count_comb = ((to_comb P Bnds count_comb) $ (to_comb Q Bnds count_comb))
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   213
  | to_comb t _ _ = t;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   214
 
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   215
   
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   216
fun comb_of t count_comb = to_comb t [] count_comb;
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   217
 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   218
(* print a term containing combinators, used for debugging *)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   219
exception TERM_COMB of term;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   220
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   221
fun string_of_term (Const(c,t)) = c
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   222
  | string_of_term (Free(v,t)) = v
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   223
  | string_of_term (Var((x,n),t)) = x ^ "_" ^ (string_of_int n)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   224
  | string_of_term (P $ Q) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   225
      "(" ^ string_of_term P ^ " " ^ string_of_term Q ^ ")" 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   226
  | string_of_term t =  raise TERM_COMB (t);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   227
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   228
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   229
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   230
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   231
(* data types for typed combinator expressions        *)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   232
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   233
20281
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   234
datatype type_level = T_FULL | T_PARTIAL | T_CONST | T_NONE;
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   235
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   236
val typ_level = ref T_CONST;
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   237
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   238
fun full_types () = (typ_level:=T_FULL);
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   239
fun partial_types () = (typ_level:=T_PARTIAL);
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   240
fun const_types_only () = (typ_level:=T_CONST);
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   241
fun no_types () = (typ_level:=T_NONE);
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   242
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   243
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   244
fun find_typ_level () = !typ_level;
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   245
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   246
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   247
type axiom_name = string;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   248
datatype kind = Axiom | Conjecture;
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   249
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   250
fun name_of_kind Axiom = "axiom"
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   251
  | name_of_kind Conjecture = "conjecture";
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   252
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   253
type polarity = bool;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   254
type indexname = Term.indexname;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   255
type clause_id = int;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   256
type csort = Term.sort;
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   257
type ctyp = ResClause.fol_type;
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   258
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   259
val string_of_ctyp = ResClause.string_of_fol_type;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   260
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   261
type ctyp_var = ResClause.typ_var;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   262
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   263
type ctype_literal = ResClause.type_literal;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   264
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   265
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   266
datatype combterm = CombConst of string * ctyp * ctyp list
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   267
		  | CombFree of string * ctyp
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   268
		  | CombVar of string * ctyp
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   269
		  | CombApp of combterm * combterm * ctyp
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   270
		  | Bool of combterm;
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   271
		  
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   272
datatype literal = Literal of polarity * combterm;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   273
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   274
datatype clause = 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   275
	 Clause of {clause_id: clause_id,
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   276
		    axiom_name: axiom_name,
19964
73704ba4bed1 added the "th" field to datatype Clause
paulson
parents: 19745
diff changeset
   277
		    th: thm,
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   278
		    kind: kind,
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   279
		    literals: literal list,
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   280
		    ctypes_sorts: (ctyp_var * csort) list, 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   281
                    ctvar_type_literals: ctype_literal list, 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   282
                    ctfree_type_literals: ctype_literal list};
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   283
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   284
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   285
fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   286
fun get_axiomName (Clause cls) = #axiom_name cls;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   287
fun get_clause_id (Clause cls) = #clause_id cls;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   288
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   289
fun get_literals (c as Clause(cls)) = #literals cls;
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   290
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   291
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   292
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   293
(* convert a clause with type Term.term to a clause with type clause *)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   294
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   295
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   296
fun isFalse (Literal(pol,Bool(CombConst(c,_,_)))) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   297
      (pol andalso c = "c_False") orelse
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   298
      (not pol andalso c = "c_True")
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   299
  | isFalse _ = false;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   300
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   301
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   302
fun isTrue (Literal (pol,Bool(CombConst(c,_,_)))) =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   303
      (pol andalso c = "c_True") orelse
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   304
      (not pol andalso c = "c_False")
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   305
  | isTrue _ = false;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   306
  
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   307
fun isTaut (Clause {literals,...}) = exists isTrue literals;  
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   308
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   309
fun type_of (Type (a, Ts)) =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   310
    let val (folTypes,ts) = types_of Ts
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   311
	val t = ResClause.make_fixed_type_const a
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   312
    in
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   313
	(ResClause.mk_fol_type("Comp",t,folTypes),ts)
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   314
    end
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   315
  | type_of (tp as (TFree(a,s))) =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   316
    let val t = ResClause.make_fixed_type_var a
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   317
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   318
	(ResClause.mk_fol_type("Fixed",t,[]),[ResClause.mk_typ_var_sort tp])
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   319
    end
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   320
  | type_of (tp as (TVar(v,s))) =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   321
    let val t = ResClause.make_schematic_type_var v
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   322
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   323
	(ResClause.mk_fol_type("Var",t,[]),[ResClause.mk_typ_var_sort tp])
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   324
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   325
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   326
and types_of Ts =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   327
    let val foltyps_ts = map type_of Ts
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   328
	val (folTyps,ts) = ListPair.unzip foltyps_ts
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   329
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   330
	(folTyps,ResClause.union_all ts)
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   331
    end;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   332
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   333
(* same as above, but no gathering of sort information *)
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   334
fun simp_type_of (Type (a, Ts)) = 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   335
    let val typs = map simp_type_of Ts
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   336
	val t = ResClause.make_fixed_type_const a
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   337
    in
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   338
	ResClause.mk_fol_type("Comp",t,typs)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   339
    end
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   340
  | simp_type_of (TFree (a,s)) = ResClause.mk_fol_type("Fixed",ResClause.make_fixed_type_var a,[])
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   341
  | simp_type_of (TVar (v,s)) = ResClause.mk_fol_type("Var",ResClause.make_schematic_type_var v,[]);
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   342
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   343
fun comb_typ ("COMBI",t) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   344
    let val t' = domain_type t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   345
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   346
	[simp_type_of t']
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   347
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   348
  | comb_typ ("COMBK",t) = 
18725
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   349
    let val a = domain_type t
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   350
	val b = domain_type (range_type t)
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   351
    in
18725
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   352
	map simp_type_of [a,b]
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   353
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   354
  | comb_typ ("COMBS",t) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   355
    let val t' = domain_type t
18725
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   356
	val a = domain_type t'
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   357
	val b = domain_type (range_type t')
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   358
	val c = range_type (range_type t')
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   359
    in 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   360
	map simp_type_of [a,b,c]
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   361
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   362
  | comb_typ ("COMBB",t) = 
18725
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   363
    let val ab = domain_type t
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   364
	val ca = domain_type (range_type t)
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   365
	val a = domain_type ab
18725
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   366
	val b = range_type ab
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   367
	val c = domain_type ca
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   368
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   369
	map simp_type_of [a,b,c]
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   370
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   371
  | comb_typ ("COMBC",t) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   372
    let val t1 = domain_type t
18725
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   373
	val a = domain_type t1
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   374
	val b = domain_type (range_type t1)
2d0af0574588 fixed a bug
mengj
parents: 18449
diff changeset
   375
	val c = range_type (range_type t1)
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   376
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   377
	map simp_type_of [a,b,c]
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   378
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   379
  | comb_typ ("COMBB_e",t) =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   380
    let val t1 = domain_type t
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   381
	val a = domain_type t1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   382
	val b = range_type t1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   383
	val t2 = domain_type (range_type(range_type t))
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   384
	val c = domain_type t2
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   385
	val d = range_type t2
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   386
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   387
	map simp_type_of [a,b,c,d]
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   388
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   389
  | comb_typ ("COMBC_e",t) =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   390
    let val t1 = domain_type t
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   391
	val a = domain_type t1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   392
	val b = domain_type (range_type t1)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   393
	val c = range_type (range_type t1)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   394
	val d = domain_type (domain_type (range_type t))
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   395
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   396
	map simp_type_of [a,b,c,d]
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   397
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   398
  | comb_typ ("COMBS_e",t) = 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   399
    let val t1 = domain_type t
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   400
	val a = domain_type t1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   401
	val b = domain_type (range_type t1)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   402
	val c = range_type (range_type t1)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   403
	val d = domain_type (domain_type (range_type t))
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   404
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   405
	map simp_type_of [a,b,c,d]
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   406
    end;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   407
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   408
fun const_type_of ("COMBI",t) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   409
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   410
	val I_var = comb_typ ("COMBI",t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   411
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   412
	(tp,ts,I_var)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   413
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   414
  | const_type_of ("COMBK",t) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   415
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   416
	val K_var = comb_typ ("COMBK",t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   417
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   418
	(tp,ts,K_var)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   419
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   420
  | const_type_of ("COMBS",t) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   421
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   422
	val S_var = comb_typ ("COMBS",t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   423
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   424
	(tp,ts,S_var)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   425
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   426
  | const_type_of ("COMBB",t) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   427
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   428
	val B_var = comb_typ ("COMBB",t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   429
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   430
	(tp,ts,B_var)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   431
    end
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   432
  | const_type_of ("COMBC",t) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   433
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   434
	val C_var = comb_typ ("COMBC",t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   435
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   436
	(tp,ts,C_var)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   437
    end
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   438
  | const_type_of ("COMBB_e",t) =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   439
    let val (tp,ts) = type_of t
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   440
	val B'_var = comb_typ ("COMBB_e",t)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   441
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   442
	(tp,ts,B'_var)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   443
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   444
  | const_type_of ("COMBC_e",t) =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   445
    let val (tp,ts) = type_of t
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   446
	val C'_var = comb_typ ("COMBC_e",t)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   447
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   448
	(tp,ts,C'_var)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   449
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   450
  | const_type_of ("COMBS_e",t) =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   451
    let val (tp,ts) = type_of t
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   452
	val S'_var = comb_typ ("COMBS_e",t)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   453
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   454
	(tp,ts,S'_var)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   455
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   456
  | const_type_of (c,t) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   457
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   458
	val tvars = !const_typargs(c,t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   459
	val tvars' = map simp_type_of tvars
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   460
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   461
	(tp,ts,tvars')
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   462
    end;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   463
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   464
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   465
fun is_bool_type (Type("bool",[])) = true
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   466
  | is_bool_type _ = false;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   467
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   468
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   469
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   470
fun combterm_of (Const(c,t)) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   471
    let val (tp,ts,tvar_list) = const_type_of (c,t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   472
	val is_bool = is_bool_type t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   473
	val c' = CombConst(ResClause.make_fixed_const c,tp,tvar_list)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   474
	val c'' = if is_bool then Bool(c') else c'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   475
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   476
	(c'',ts)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   477
    end
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   478
  | combterm_of (Free(v,t)) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   479
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   480
	val is_bool = is_bool_type t
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   481
	val v' = if ResClause.isMeta v then CombVar(ResClause.make_schematic_var(v,0),tp)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   482
		 else CombFree(ResClause.make_fixed_var v,tp)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   483
	val v'' = if is_bool then Bool(v') else v'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   484
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   485
	(v'',ts)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   486
    end
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   487
  | combterm_of (Var(v,t)) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   488
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   489
	val is_bool = is_bool_type t
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   490
	val v' = CombVar(ResClause.make_schematic_var v,tp)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   491
	val v'' = if is_bool then Bool(v') else v'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   492
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   493
	(v'',ts)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   494
    end
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   495
  | combterm_of (t as (P $ Q)) =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   496
    let val (P',tsP) = combterm_of P
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   497
	val (Q',tsQ) = combterm_of Q
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   498
	val tp = Term.type_of t
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   499
	val tp' = simp_type_of tp
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   500
	val is_bool = is_bool_type tp
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   501
	val t' = CombApp(P',Q',tp')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   502
	val t'' = if is_bool then Bool(t') else t'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   503
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   504
	(t'',tsP union tsQ)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   505
    end;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   506
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   507
fun predicate_of ((Const("Not",_) $ P), polarity) =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   508
    predicate_of (P, not polarity)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   509
  | predicate_of (term,polarity) = (combterm_of term,polarity);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   510
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   511
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   512
fun literals_of_term1 args (Const("Trueprop",_) $ P) = literals_of_term1 args P
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   513
  | literals_of_term1 args (Const("op |",_) $ P $ Q) = 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   514
    let val args' = literals_of_term1 args P
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   515
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   516
	literals_of_term1 args' Q
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   517
    end
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   518
  | literals_of_term1 (lits,ts) P =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   519
    let val ((pred,ts'),pol) = predicate_of (P,true)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   520
	val lits' = Literal(pol,pred)::lits
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   521
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   522
	(lits',ts union ts')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   523
    end;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   524
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   525
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   526
fun literals_of_term P = literals_of_term1 ([],[]) P;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   527
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   528
fun occurs a (CombVar(b,_)) = a = b
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   529
  | occurs a (CombApp(t1,t2,_)) = (occurs a t1) orelse (occurs a t2)
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   530
  | occurs _ _ = false
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   531
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   532
fun too_general_terms (CombVar(v,_), t) = not (occurs v t)
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   533
  | too_general_terms _ = false;
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   534
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   535
fun too_general_lit (Literal(true,(Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))))) =
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   536
      too_general_terms (t1,t2) orelse too_general_terms (t2,t1)
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   537
  | too_general_lit _ = false;
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   538
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   539
(* forbid a clause that contains hBOOL(V) *)
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   540
fun too_general [] = false
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   541
  | too_general (lit::lits) = 
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   542
    case lit of Literal(_,Bool(CombVar(_,_))) => true
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   543
	      | _ => too_general lits;
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   544
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   545
(* making axiom and conjecture clauses *)
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   546
exception MAKE_CLAUSE
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   547
fun make_clause(clause_id,axiom_name,kind,thm,is_user) =
19444
085568445283 Take conjectures and axioms as thms when convert them to ResHolClause.clause format.
mengj
parents: 19354
diff changeset
   548
    let val term = prop_of thm
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   549
	val term' = comb_of term is_user
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   550
	val (lits,ctypes_sorts) = literals_of_term term'
18856
4669dec681f4 tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents: 18725
diff changeset
   551
	val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux ctypes_sorts
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   552
    in
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   553
	if forall isFalse lits
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   554
	then error "Problem too trivial for resolution (empty clause)"
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   555
	else if too_general lits 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   556
	then (Output.debug ("Omitting " ^ axiom_name ^ ": clause contains universal predicates"); 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   557
	     raise MAKE_CLAUSE)
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   558
	else
20281
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   559
	    if (!typ_level <> T_FULL) andalso kind=Axiom andalso forall too_general_lit lits 
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   560
	    then (Output.debug ("Omitting " ^ axiom_name ^ ": equalities are too general"); 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   561
	          raise MAKE_CLAUSE) 
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   562
	else
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   563
	    Clause {clause_id = clause_id, axiom_name = axiom_name, th = thm, kind = kind,
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   564
		    literals = lits, ctypes_sorts = ctypes_sorts, 
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   565
		    ctvar_type_literals = ctvar_lits,
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   566
		    ctfree_type_literals = ctfree_lits}
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   567
    end;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   568
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   569
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   570
fun make_axiom_clause thm (ax_name,cls_id,is_user) = 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   571
      make_clause(cls_id,ax_name,Axiom,thm,is_user);
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   572
 
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   573
fun make_axiom_clauses [] user_lemmas = []
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   574
  | make_axiom_clauses ((thm,(name,id))::thms) user_lemmas =
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   575
    let val is_user = name mem user_lemmas
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   576
	val cls = SOME (make_axiom_clause thm (name,id,is_user)) 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   577
	          handle MAKE_CLAUSE => NONE
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   578
	val clss = make_axiom_clauses thms user_lemmas
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   579
    in
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   580
	case cls of NONE => clss
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   581
		  | SOME(cls') => if isTaut cls' then clss 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   582
		                  else (name,cls')::clss
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   583
    end;
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   584
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   585
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   586
fun make_conjecture_clauses_aux _ [] = []
20421
paulson
parents: 20360
diff changeset
   587
  | make_conjecture_clauses_aux n (th::ths) =
paulson
parents: 20360
diff changeset
   588
      make_clause(n,"conjecture",Conjecture,th,true) ::
paulson
parents: 20360
diff changeset
   589
      make_conjecture_clauses_aux (n+1) ths;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   590
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   591
val make_conjecture_clauses = make_conjecture_clauses_aux 0;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   592
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   593
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   594
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   595
(* convert clause into ATP specific formats:                          *)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   596
(* TPTP used by Vampire and E                                         *)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   597
(* DFG used by SPASS                                                  *)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   598
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   599
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   600
val type_wrapper = "typeinfo";
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   601
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   602
fun wrap_type (c,t) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   603
    case !typ_level of T_FULL => type_wrapper ^ (ResClause.paren_pack [c,t])
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   604
		     | _ => c;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   605
    
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   606
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   607
val bool_tp = ResClause.make_fixed_type_const "bool";
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   608
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   609
val app_str = "hAPP";
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   610
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   611
val bool_str = "hBOOL";
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   612
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   613
exception STRING_OF_COMBTERM of int;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   614
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   615
(* convert literals of clauses into strings *)
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   616
fun string_of_combterm1_aux _ (CombConst(c,tp,_)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   617
    let val tp' = string_of_ctyp tp
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   618
	val c' = if c = "equal" then "fequal" else c
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   619
    in
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   620
	(wrap_type (c',tp'),tp')
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   621
    end
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   622
  | string_of_combterm1_aux _ (CombFree(v,tp)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   623
    let val tp' = string_of_ctyp tp
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   624
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   625
	(wrap_type (v,tp'),tp')
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   626
    end
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   627
  | string_of_combterm1_aux _ (CombVar(v,tp)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   628
    let val tp' = string_of_ctyp tp
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   629
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   630
	(wrap_type (v,tp'),tp')
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   631
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   632
  | string_of_combterm1_aux is_pred (CombApp(t1,t2,tp)) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   633
    let val (s1,tp1) = string_of_combterm1_aux is_pred t1
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   634
	val (s2,tp2) = string_of_combterm1_aux is_pred t2
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   635
	val tp' = ResClause.string_of_fol_type tp
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   636
	val r =	case !typ_level of T_FULL => type_wrapper ^  (ResClause.paren_pack [(app_str ^ (ResClause.paren_pack [s1,s2])),tp'])
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   637
				 | T_PARTIAL => app_str ^ (ResClause.paren_pack [s1,s2,tp1])
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   638
				 | T_NONE => app_str ^ (ResClause.paren_pack [s1,s2])
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   639
				 | T_CONST => raise STRING_OF_COMBTERM (1) (*should not happen, if happened may be a bug*)
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   640
    in	(r,tp')
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   641
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   642
    end
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   643
  | string_of_combterm1_aux is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) =
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   644
    if is_pred then 
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   645
	let val (s1,_) = string_of_combterm1_aux false t1
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   646
	    val (s2,_) = string_of_combterm1_aux false t2
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   647
	in
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   648
	    ("equal" ^ (ResClause.paren_pack [s1,s2]),bool_tp)
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   649
	end
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   650
    else
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   651
	let val (t,_) = string_of_combterm1_aux false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   652
	in
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   653
	    (t,bool_tp)
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   654
	end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   655
  | string_of_combterm1_aux is_pred (Bool(t)) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   656
    let val (t',_) = string_of_combterm1_aux false t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   657
	val r = if is_pred then bool_str ^ (ResClause.paren_pack [t'])
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   658
		else t'
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   659
    in
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   660
	(r,bool_tp)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   661
    end;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   662
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   663
fun string_of_combterm1 is_pred term = fst (string_of_combterm1_aux is_pred term);
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   664
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   665
fun string_of_combterm2 _ (CombConst(c,tp,tvars)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   666
    let val tvars' = map string_of_ctyp tvars
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   667
	val c' = if c = "equal" then "fequal" else c
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   668
    in
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   669
	c' ^ (ResClause.paren_pack tvars')
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   670
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   671
  | string_of_combterm2 _ (CombFree(v,tp)) = v
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   672
  | string_of_combterm2 _ (CombVar(v,tp)) = v
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   673
  | string_of_combterm2 is_pred (CombApp(t1,t2,tp)) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   674
    let val s1 = string_of_combterm2 is_pred t1
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   675
	val s2 = string_of_combterm2 is_pred t2
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   676
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   677
	app_str ^ (ResClause.paren_pack [s1,s2])
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   678
    end
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   679
  | string_of_combterm2 is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) =
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   680
    if is_pred then 
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   681
	let val s1 = string_of_combterm2 false t1
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   682
	    val s2 = string_of_combterm2 false t2
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   683
	in
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   684
	    ("equal" ^ (ResClause.paren_pack [s1,s2]))
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   685
	end
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   686
    else
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   687
	string_of_combterm2 false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   688
 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   689
  | string_of_combterm2 is_pred (Bool(t)) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   690
    let val t' = string_of_combterm2 false t
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   691
    in
18200
9d476d1054d7 -- terms are fully typed.
mengj
parents: 17998
diff changeset
   692
	if is_pred then bool_str ^ (ResClause.paren_pack [t'])
9d476d1054d7 -- terms are fully typed.
mengj
parents: 17998
diff changeset
   693
	else t'
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   694
    end;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   695
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   696
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   697
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   698
fun string_of_combterm is_pred term = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   699
    case !typ_level of T_CONST => string_of_combterm2 is_pred term
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   700
		     | _ => string_of_combterm1 is_pred term;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   701
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   702
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   703
fun string_of_clausename (cls_id,ax_name) = 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   704
    ResClause.clause_prefix ^ ResClause.ascii_of ax_name ^ "_" ^ Int.toString cls_id;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   705
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   706
fun string_of_type_clsname (cls_id,ax_name,idx) = 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   707
    string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   708
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   709
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   710
(* tptp format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   711
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   712
fun tptp_literal (Literal(pol,pred)) =
18200
9d476d1054d7 -- terms are fully typed.
mengj
parents: 17998
diff changeset
   713
    let val pred_string = string_of_combterm true pred
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   714
	val pol_str = if pol then "++" else "--"
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   715
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   716
	pol_str ^ pred_string
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   717
    end;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   718
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   719
 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   720
fun tptp_type_lits (Clause cls) = 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   721
    let val lits = map tptp_literal (#literals cls)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   722
	val ctvar_lits_strs =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   723
	    case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   724
	      | _ => map ResClause.tptp_of_typeLit (#ctvar_type_literals cls)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   725
	val ctfree_lits = 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   726
	    case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   727
	      | _ => map ResClause.tptp_of_typeLit (#ctfree_type_literals cls)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   728
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   729
	(ctvar_lits_strs @ lits, ctfree_lits)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   730
    end; 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   731
    
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   732
    
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   733
fun clause2tptp cls =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   734
    let val (lits,ctfree_lits) = tptp_type_lits cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   735
	val cls_id = get_clause_id cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   736
	val ax_name = get_axiomName cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   737
	val knd = string_of_kind cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   738
	val lits_str = ResClause.bracket_pack lits
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   739
	val cls_str = ResClause.gen_tptp_cls(cls_id,ax_name,knd,lits_str)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   740
    in
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   741
	(cls_str,ctfree_lits)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   742
    end;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   743
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   744
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   745
(* dfg format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   746
fun dfg_literal (Literal(pol,pred)) = ResClause.dfg_sign pol (string_of_combterm true pred);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   747
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   748
fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   749
  let val lits = map dfg_literal literals
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   750
      val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   751
      val tvar_lits_strs = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   752
	  case !typ_level of T_NONE => [] 
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   753
	      | _ => map ResClause.dfg_of_typeLit tvar_lits
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   754
      val tfree_lits =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   755
          case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   756
	      | _ => map ResClause.dfg_of_typeLit tfree_lits 
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   757
  in
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   758
      (tvar_lits_strs @ lits, tfree_lits)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   759
  end; 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   760
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   761
fun get_uvars (CombConst(_,_,_)) vars = vars
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   762
  | get_uvars (CombFree(_,_)) vars = vars
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   763
  | get_uvars (CombVar(v,tp)) vars = (v::vars)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   764
  | get_uvars (CombApp(P,Q,tp)) vars = get_uvars P (get_uvars Q vars)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   765
  | get_uvars (Bool(c)) vars = get_uvars c vars;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   766
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   767
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   768
fun get_uvars_l (Literal(_,c)) = get_uvars c [];
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   769
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   770
fun dfg_vars (Clause {literals,...}) = ResClause.union_all (map get_uvars_l literals);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   771
 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   772
fun clause2dfg (cls as Clause{axiom_name,clause_id,kind,ctypes_sorts,...}) =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   773
    let val (lits,tfree_lits) = dfg_clause_aux cls 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   774
        val vars = dfg_vars cls
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   775
        val tvars = ResClause.get_tvar_strs ctypes_sorts
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   776
	val knd = name_of_kind kind
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   777
	val lits_str = commas lits
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   778
	val cls_str = ResClause.gen_dfg_cls(clause_id, axiom_name, knd, lits_str, tvars@vars) 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   779
    in (cls_str, tfree_lits) end;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   780
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   781
19725
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   782
fun init_combs (comb,funcs) =
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   783
    case !typ_level of T_CONST => 
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   784
	    (case comb of "c_COMBK" => Symtab.update (comb,2) funcs
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   785
			| "c_COMBS" => Symtab.update (comb,3) funcs
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   786
			| "c_COMBI" => Symtab.update (comb,1) funcs
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   787
			| "c_COMBB" => Symtab.update (comb,3) funcs
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   788
			| "c_COMBC" => Symtab.update (comb,3) funcs
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   789
			| "c_COMBB_e" => Symtab.update (comb,4) funcs
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   790
			| "c_COMBC_e" => Symtab.update (comb,4) funcs
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   791
			| "c_COMBS_e" => Symtab.update (comb,4) funcs
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   792
			| _ => funcs)
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   793
	  | _ => Symtab.update (comb,0) funcs;
19725
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   794
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   795
fun init_funcs_tab funcs = 
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   796
    let val tp = !typ_level
20660
8606ddd42554 corrected for the translation from _ to __ in c_COMBx_e
paulson
parents: 20644
diff changeset
   797
	val funcs0 = foldl init_combs funcs ["c_COMBK","c_COMBS","c_COMBI","c_COMBB","c_COMBC",
8606ddd42554 corrected for the translation from _ to __ in c_COMBx_e
paulson
parents: 20644
diff changeset
   798
	                                     "c_COMBB__e","c_COMBC__e","c_COMBS__e"]
19725
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   799
	val funcs1 = case tp of T_PARTIAL => Symtab.update ("hAPP",3) funcs0
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   800
				      | _ => Symtab.update ("hAPP",2) funcs0
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   801
	val funcs2 = case tp of T_FULL => Symtab.update ("typeinfo",2) funcs1
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   802
				      | _ => funcs1
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   803
    in
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   804
	case tp of T_CONST => Symtab.update ("fequal",1) (Symtab.update ("hEXTENT",2) funcs2)
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   805
			 | _ => Symtab.update ("fequal",0) (Symtab.update ("hEXTENT",0) funcs2)
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   806
    end;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   807
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   808
19725
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   809
fun add_funcs (CombConst(c,_,tvars),funcs) =
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   810
    if c = "equal" then foldl ResClause.add_foltype_funcs funcs tvars
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   811
    else
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   812
	(case !typ_level of T_CONST => foldl ResClause.add_foltype_funcs (Symtab.update(c,length tvars) funcs) tvars
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   813
			  | _ => foldl ResClause.add_foltype_funcs (Symtab.update(c,0) funcs) tvars)
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   814
  | add_funcs (CombFree(v,ctp),funcs) = ResClause.add_foltype_funcs (ctp,Symtab.update (v,0) funcs) 
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   815
  | add_funcs (CombVar(_,ctp),funcs) = ResClause.add_foltype_funcs (ctp,funcs)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   816
  | add_funcs (CombApp(P,Q,_),funcs) = add_funcs(P,add_funcs (Q,funcs))
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   817
  | add_funcs (Bool(t),funcs) = add_funcs (t,funcs);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   818
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   819
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   820
fun add_literal_funcs (Literal(_,c), funcs) = add_funcs (c,funcs);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   821
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   822
fun add_clause_funcs (Clause {literals, ...}, funcs) =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   823
    foldl add_literal_funcs funcs literals
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   824
    handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities")
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   825
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   826
fun funcs_of_clauses clauses arity_clauses =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   827
    Symtab.dest (foldl ResClause.add_arityClause_funcs 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   828
                       (foldl add_clause_funcs (init_funcs_tab Symtab.empty) clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   829
                       arity_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   830
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   831
fun preds_of clsrel_clauses arity_clauses = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   832
    Symtab.dest
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   833
	(foldl ResClause.add_classrelClause_preds 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   834
	       (foldl ResClause.add_arityClause_preds
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   835
		      (Symtab.update ("hBOOL",1) Symtab.empty)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   836
		      arity_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   837
	       clsrel_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   838
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   839
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   840
(**********************************************************************)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   841
(* write clauses to files                                             *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   842
(**********************************************************************)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   843
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   844
(* tptp format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   845
19491
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   846
fun read_in fs = map (File.read o File.unpack_platform_path) fs; 
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   847
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   848
fun get_helper_tptp () =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   849
    let val IK = if !combI_count > 0 orelse !combK_count > 0 then (Output.debug "Include combinator I K";["combIK.tptp"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   850
	val BC = if !combB_count > 0 orelse !combC_count > 0 then (Output.debug "Include combinator B C";["combBC.tptp"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   851
	val S = if !combS_count > 0 then (Output.debug "Include combinator S";["combS.tptp"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   852
	val B'C' = if !combB'_count > 0 orelse !combC'_count > 0 then (Output.debug "Include combinator B' C'"; ["combBC_e.tptp"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   853
	val S' = if !combS'_count > 0 then (Output.debug "Include combinator S'";["combS_e.tptp"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   854
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   855
	("helper1.tptp") :: (IK @ BC @ S @ B'C' @ S')
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   856
    end;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   857
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   858
19491
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   859
fun get_helper_clauses_tptp () =
19745
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   860
  let val tlevel = case !typ_level of 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   861
		       T_FULL => (Output.debug "Fully-typed HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   862
				  "~~/src/HOL/Tools/atp-inputs/full_")
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   863
		     | T_PARTIAL => (Output.debug "Partially-typed HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   864
				     "~~/src/HOL/Tools/atp-inputs/par_")
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   865
		     | T_CONST => (Output.debug "Const-only-typed HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   866
				   "~~/src/HOL/Tools/atp-inputs/const_")
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   867
		     | T_NONE => (Output.debug "Untyped HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   868
				  "~~/src/HOL/Tools/atp-inputs/u_")
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   869
      val helpers = get_helper_tptp ()
19745
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   870
      val t_helpers = map (curry (op ^) tlevel) helpers
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   871
  in
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   872
      read_in t_helpers
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   873
  end;
19491
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   874
	
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   875
						  
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   876
(* write TPTP format to a single file *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   877
(* when "get_helper_clauses" is called, "include_combS" and "include_min_comb" should have correct values already *)
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   878
fun tptp_write_file thms filename (axclauses,classrel_clauses,arity_clauses) user_lemmas=
19444
085568445283 Take conjectures and axioms as thms when convert them to ResHolClause.clause format.
mengj
parents: 19354
diff changeset
   879
    let val clss = make_conjecture_clauses thms
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   880
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses user_lemmas)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   881
	val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp clss)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   882
	val tfree_clss = map ResClause.tptp_tfree_clause (foldl (op union_string) [] tfree_litss)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   883
	val out = TextIO.openOut filename
19491
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   884
	val helper_clauses = get_helper_clauses_tptp ()
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   885
    in
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   886
	List.app (curry TextIO.output out o #1 o clause2tptp) axclauses';
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   887
	ResClause.writeln_strs out tfree_clss;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   888
	ResClause.writeln_strs out tptp_clss;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   889
	List.app (curry TextIO.output out o ResClause.tptp_classrelClause) classrel_clauses;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   890
	List.app (curry TextIO.output out o ResClause.tptp_arity_clause) arity_clauses;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   891
	List.app (curry TextIO.output out) helper_clauses;
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   892
	TextIO.closeOut out;
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   893
	clnames
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   894
    end;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   895
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   896
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   897
fun get_helper_dfg () =
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   898
    let val IK = if !combI_count > 0 orelse !combK_count > 0 then (Output.debug "Include combinator I K";["combIK.dfg"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   899
	val BC = if !combB_count > 0 orelse !combC_count > 0 then (Output.debug "Include combinator B C";["combBC.dfg"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   900
	val S = if !combS_count > 0 then (Output.debug "Include combinator S";["combS.dfg"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   901
	val B'C' = if !combB'_count > 0 orelse !combC'_count > 0 then (Output.debug "Include combinator B' C'"; ["combBC_e.dfg"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   902
	val S' = if !combS'_count > 0 then (Output.debug "Include combinator S'";["combS_e.dfg"]) else []
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   903
    in
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   904
	("helper1.dfg") :: (IK @ BC @ S @ B'C' @ S')
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   905
    end;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   906
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   907
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   908
(* dfg format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   909
fun get_helper_clauses_dfg () = 
19745
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   910
 let val tlevel = case !typ_level of 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   911
                      T_FULL => (Output.debug "Fully-typed HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   912
                                 "~~/src/HOL/Tools/atp-inputs/full_")
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   913
		    | T_PARTIAL => (Output.debug "Partially-typed HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   914
		                    "~~/src/HOL/Tools/atp-inputs/par_")
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   915
		    | T_CONST => (Output.debug "Const-only-typed HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   916
		                  "~~/src/HOL/Tools/atp-inputs/const_")
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   917
		    | T_NONE => (Output.debug "Untyped HOL"; 
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   918
		                 "~~/src/HOL/Tools/atp-inputs/u_")
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   919
     val helpers = get_helper_dfg ()
19745
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   920
     val t_helpers = map (curry (op ^) tlevel) helpers
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   921
 in
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   922
     read_in t_helpers
df6fd56d63a9 warnings to debug outputs; default translation to const-typed
paulson
parents: 19725
diff changeset
   923
 end;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   924
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   925
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   926
fun dfg_write_file  thms filename (axclauses,classrel_clauses,arity_clauses) user_lemmas =
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   927
    let val _ = Output.debug ("Preparing to write the DFG file " ^ filename) 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   928
	val conjectures = make_conjecture_clauses thms
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   929
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses user_lemmas)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   930
	val (dfg_clss,tfree_litss) = ListPair.unzip (map clause2dfg conjectures)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   931
	val clss = conjectures @ axclauses'
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   932
	val funcs = funcs_of_clauses clss arity_clauses
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   933
	and preds = preds_of classrel_clauses arity_clauses
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   934
	and probname = Path.pack (Path.base (Path.unpack filename))
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   935
	val (axstrs,_) =  ListPair.unzip (map clause2dfg axclauses')
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   936
	val tfree_clss = map ResClause.dfg_tfree_clause (ResClause.union_all tfree_litss)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   937
	val out = TextIO.openOut filename
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   938
	val helper_clauses = get_helper_clauses_dfg ()
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   939
    in
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   940
	TextIO.output (out, ResClause.string_of_start probname); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   941
	TextIO.output (out, ResClause.string_of_descrip probname); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   942
	TextIO.output (out, ResClause.string_of_symbols (ResClause.string_of_funcs funcs) (ResClause.string_of_preds preds)); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   943
	TextIO.output (out, "list_of_clauses(axioms,cnf).\n");
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   944
	ResClause.writeln_strs out axstrs;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   945
	List.app (curry TextIO.output out o ResClause.dfg_classrelClause) classrel_clauses;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   946
	List.app (curry TextIO.output out o ResClause.dfg_arity_clause) arity_clauses;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   947
	ResClause.writeln_strs out helper_clauses;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   948
	TextIO.output (out, "end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n");
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   949
	ResClause.writeln_strs out tfree_clss;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   950
	ResClause.writeln_strs out dfg_clss;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   951
	TextIO.output (out, "end_of_list.\n\nend_problem.\n");
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   952
	TextIO.closeOut out;
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   953
	clnames
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   954
    end;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   955
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   956
end