src/HOL/Tools/res_hol_clause.ML
author huffman
Thu, 14 Dec 2006 18:10:38 +0100
changeset 21847 59a68ed9f2f2
parent 21617 4664489469fc
child 21858 05f57309170c
permissions -rw-r--r--
redefine hSuc as *f* Suc, and move to HyperNat.thy
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
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
     8
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
    10
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
    11
(* theorems for combinators and function extensionality *)
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
    12
val ext = thm "HOL.ext";
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    13
val comb_I = thm "ATP_Linkup.COMBI_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    14
val comb_K = thm "ATP_Linkup.COMBK_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    15
val comb_B = thm "ATP_Linkup.COMBB_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    16
val comb_C = thm "ATP_Linkup.COMBC_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    17
val comb_S = thm "ATP_Linkup.COMBS_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    18
val comb_B' = thm "ATP_Linkup.COMBB'_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    19
val comb_C' = thm "ATP_Linkup.COMBC'_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    20
val comb_S' = thm "ATP_Linkup.COMBS'_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    21
val fequal_imp_equal = thm "ATP_Linkup.fequal_imp_equal";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    22
val equal_imp_fequal = thm "ATP_Linkup.equal_imp_fequal";
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
    23
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    24
(*A flag to set if we use the Turner optimizations. Currently FALSE, as the 5 standard
20997
4b500d78cb4f Extended combinators now disabled
paulson
parents: 20953
diff changeset
    25
  combinators appear to work best.*)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    26
val use_Turner = ref 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
    27
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
    28
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
    29
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    30
fun init thy = (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
    31
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
    32
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    33
(* 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
    34
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    35
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    36
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
    37
  | 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
    38
  | 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
    39
  | 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
    40
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    41
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    42
(*******************************************)
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    43
fun mk_compact_comb (tm as (Const("ATP_Linkup.COMBB",_)$p) $ (Const("ATP_Linkup.COMBB",_)$q$r)) bnds =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    44
      let val tp_p = Term.type_of1(bnds,p)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    45
	  val tp_q = Term.type_of1(bnds,q)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    46
	  val tp_r = Term.type_of1(bnds,r)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    47
	  val typ = Term.type_of1(bnds,tm)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    48
	  val typ_B' = [tp_p,tp_q,tp_r] ---> typ
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    49
      in
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    50
	  Const("ATP_Linkup.COMBB'",typ_B') $ p $ q $ r
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    51
      end
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    52
  | mk_compact_comb (tm as (Const("ATP_Linkup.COMBC",_) $ (Const("ATP_Linkup.COMBB",_)$p$q) $ r)) bnds =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    53
      let val tp_p = Term.type_of1(bnds,p)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    54
	  val tp_q = Term.type_of1(bnds,q)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    55
	  val tp_r = Term.type_of1(bnds,r)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    56
	  val typ = Term.type_of1(bnds,tm)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    57
	  val typ_C' = [tp_p,tp_q,tp_r] ---> typ
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    58
      in
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    59
	  Const("ATP_Linkup.COMBC'",typ_C') $ p $ q $ r
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    60
      end
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    61
  | mk_compact_comb (tm as (Const("ATP_Linkup.COMBS",_) $ (Const("ATP_Linkup.COMBB",_)$p$q) $ r)) bnds =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    62
      let val tp_p = Term.type_of1(bnds,p)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    63
	  val tp_q = Term.type_of1(bnds,q)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    64
	  val tp_r = Term.type_of1(bnds,r)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    65
	  val typ = Term.type_of1(bnds,tm)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    66
	  val typ_S' = [tp_p,tp_q,tp_r] ---> typ
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    67
      in
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    68
	  Const("ATP_Linkup.COMBS'",typ_S') $ p $ q $ r
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    69
      end
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    70
  | mk_compact_comb tm _ = tm;
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    71
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    72
fun compact_comb t bnds = 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    73
  if !use_Turner then mk_compact_comb t bnds else t;
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    74
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    75
fun lam2comb (Abs(x,tp,Bound 0)) _ = Const("ATP_Linkup.COMBI",tp-->tp) 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    76
  | lam2comb (Abs(x,tp,Bound n)) bnds = 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    77
      let val tb = List.nth(bnds,n-1)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    78
      in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    79
	  Const("ATP_Linkup.COMBK", [tb,tp] ---> tb) $ Bound (n-1)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    80
      end
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    81
  | lam2comb (Abs(x,t1,Const(c,t2))) _ = Const("ATP_Linkup.COMBK",[t2,t1] ---> t2) $ Const(c,t2) 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    82
  | lam2comb (Abs(x,t1,Free(v,t2))) _ = Const("ATP_Linkup.COMBK",[t2,t1] ---> t2) $ Free(v,t2)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    83
  | lam2comb (Abs(x,t1,Var(ind,t2))) _ = Const("ATP_Linkup.COMBK", [t2,t1] ---> t2) $ Var(ind,t2)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    84
  | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) bnds =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    85
      if is_free P 0 then 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
    86
	  let val tI = [t1] ---> t1
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    87
	      val P' = lam2comb (Abs(x,t1,P)) bnds
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    88
	      val tp' = Term.type_of1(bnds,P')
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    89
	      val tr = Term.type_of1(t1::bnds,P)
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
    90
	      val tS = [tp',tI] ---> tr
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    91
	  in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    92
	      compact_comb (Const("ATP_Linkup.COMBS",tS) $ P' $ 
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    93
	                     Const("ATP_Linkup.COMBI",tI)) bnds
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    94
	  end
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    95
      else incr_boundvars ~1 P
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    96
  | lam2comb (t as (Abs(x,t1,P$Q))) bnds =
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    97
      let val nfreeP = not(is_free P 0)
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    98
	  and nfreeQ = not(is_free Q 0)
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
    99
	  val tpq = Term.type_of1(t1::bnds, P$Q) 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   100
      in
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   101
	  if nfreeP andalso nfreeQ 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   102
	  then 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   103
	    let val tK = [tpq,t1] ---> tpq
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   104
		val PQ' = incr_boundvars ~1 (P $ 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
   105
	    in 
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   106
		Const("ATP_Linkup.COMBK",tK) $ PQ'
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   107
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   108
	  else if nfreeP then 
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   109
	    let val Q' = lam2comb (Abs(x,t1,Q)) bnds
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   110
		val P' = incr_boundvars ~1 P
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   111
		val tp = Term.type_of1(bnds,P')
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   112
		val tq' = Term.type_of1(bnds, Q')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   113
		val tB = [tp,tq',t1] ---> tpq
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   114
	    in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   115
		compact_comb (Const("ATP_Linkup.COMBB",tB) $ P' $ Q') bnds 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   116
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   117
	  else if nfreeQ then 
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   118
	    let val P' = lam2comb (Abs(x,t1,P)) bnds
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   119
		val Q' = incr_boundvars ~1 Q
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   120
		val tq = Term.type_of1(bnds,Q')
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   121
		val tp' = Term.type_of1(bnds, P')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   122
		val tC = [tp',tq,t1] ---> tpq
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   123
	    in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   124
		compact_comb (Const("ATP_Linkup.COMBC",tC) $ P' $ Q') bnds
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   125
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   126
          else
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   127
	    let val P' = lam2comb (Abs(x,t1,P)) bnds
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   128
		val Q' = lam2comb (Abs(x,t1,Q)) bnds 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   129
		val tp' = Term.type_of1(bnds,P')
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   130
		val tq' = Term.type_of1(bnds,Q')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   131
		val tS = [tp',tq',t1] ---> tpq
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   132
	    in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   133
		compact_comb (Const("ATP_Linkup.COMBS",tS) $ P' $ Q') bnds
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   134
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   135
      end
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   136
  | lam2comb (t as (Abs(x,t1,_))) _ = raise ResClause.CLAUSE("HOL CLAUSE",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
   137
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   138
(*********************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   140
fun to_comb (Abs(x,tp,b)) bnds =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   141
      lam2comb (Abs(x, tp, to_comb b (tp::bnds))) bnds 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   142
  | to_comb (P $ Q) bnds = (to_comb P bnds) $ (to_comb Q bnds)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   143
  | 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
   144
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* 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
   148
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
20281
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   150
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
   151
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   152
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
   153
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   154
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
   155
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
   156
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
   157
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
   158
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   159
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
   160
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
   161
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
   162
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
   163
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
   164
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   165
datatype combterm = CombConst of string * ResClause.fol_type * ResClause.fol_type list
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   166
		  | CombFree of string * ResClause.fol_type
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   167
		  | CombVar of string * ResClause.fol_type
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   168
		  | CombApp of combterm * combterm * ResClause.fol_type
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   169
		  
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
   170
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
   171
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
   173
	 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
   174
		    axiom_name: axiom_name,
19964
73704ba4bed1 added the "th" field to datatype Clause
paulson
parents: 19745
diff changeset
   175
		    th: thm,
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   176
		    kind: ResClause.kind,
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
   177
		    literals: literal list,
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   178
		    ctypes_sorts: (ResClause.typ_var * Term.sort) list, 
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   179
                    ctvar_type_literals: ResClause.type_literal list, 
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   180
                    ctfree_type_literals: ResClause.type_literal 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
   181
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* 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
   185
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   187
fun isFalse (Literal(pol, CombConst(c,_,_))) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   188
      (pol andalso c = "c_False") orelse
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   189
      (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
   190
  | 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
   191
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   192
fun isTrue (Literal (pol, 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
   193
      (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
   194
      (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
   195
  | 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
   196
  
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
   198
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   199
fun type_of (Type (a, Ts)) =
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   200
      let val (folTypes,ts) = types_of Ts
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   201
	  val t = ResClause.make_fixed_type_const a
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   202
      in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   203
	  (ResClause.mk_fol_type("Comp",t,folTypes), ts)
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   204
      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
   205
  | type_of (tp as (TFree(a,s))) =
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   206
      let val t = ResClause.make_fixed_type_var a
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   207
      in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   208
	  (ResClause.mk_fol_type("Fixed",t,[]), [ResClause.mk_typ_var_sort tp])
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   209
      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
   210
  | type_of (tp as (TVar(v,s))) =
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   211
      let val t = ResClause.make_schematic_type_var v
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   212
      in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   213
	  (ResClause.mk_fol_type("Var",t,[]), [ResClause.mk_typ_var_sort tp])
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   214
      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
   215
and types_of Ts =
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   216
      let val foltyps_ts = map type_of Ts
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   217
	  val (folTyps,ts) = ListPair.unzip foltyps_ts
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   218
      in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   219
	  (folTyps, ResClause.union_all ts)
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   220
      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
   221
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* 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
   223
fun simp_type_of (Type (a, Ts)) = 
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   224
      let val typs = map simp_type_of Ts
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   225
	  val t = ResClause.make_fixed_type_const a
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   226
      in
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   227
	  ResClause.mk_fol_type("Comp",t,typs)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   228
      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
   229
  | 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
   230
  | 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
   231
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   232
20865
2cfa020109c1 Changed and removed some functions related to combinators, since they are Isabelle constants now.
mengj
parents: 20864
diff changeset
   233
fun const_type_of (c,t) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   234
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   235
	val tvars = !const_typargs(c,t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   236
    in
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   237
	(tp, ts, map simp_type_of tvars)
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   238
    end;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   239
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
   240
(* 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
   241
fun combterm_of (Const(c,t)) =
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   242
      let val (tp,ts,tvar_list) = const_type_of (c,t)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   243
	  val c' = CombConst(ResClause.make_fixed_const c,tp,tvar_list)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   244
      in
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   245
	  (c',ts)
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   246
      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
   247
  | combterm_of (Free(v,t)) =
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   248
      let val (tp,ts) = type_of t
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   249
	  val v' = if ResClause.isMeta v then CombVar(ResClause.make_schematic_var(v,0),tp)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   250
		   else CombFree(ResClause.make_fixed_var v,tp)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   251
      in
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   252
	  (v',ts)
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   253
      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
   254
  | combterm_of (Var(v,t)) =
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   255
      let val (tp,ts) = type_of t
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   256
	  val v' = CombVar(ResClause.make_schematic_var v,tp)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   257
      in
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   258
	  (v',ts)
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   259
      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
   260
  | combterm_of (t as (P $ Q)) =
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   261
      let val (P',tsP) = combterm_of P
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   262
	  val (Q',tsQ) = combterm_of Q
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   263
	  val tp = Term.type_of t
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   264
	  val t' = CombApp(P',Q', simp_type_of tp)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   265
      in
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   266
	  (t',tsP union tsQ)
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   267
      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
   268
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   269
fun predicate_of ((Const("Not",_) $ P), polarity) = predicate_of (P, not polarity)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   270
  | predicate_of (t,polarity) = (combterm_of t, polarity);
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
   271
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
   273
  | literals_of_term1 args (Const("op |",_) $ P $ Q) = 
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   274
      literals_of_term1 (literals_of_term1 args P) 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
   275
  | literals_of_term1 (lits,ts) P =
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   276
      let val ((pred,ts'),pol) = predicate_of (P,true)
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   277
      in
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   278
	  (Literal(pol,pred)::lits, ts union ts')
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   279
      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
   280
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
   282
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* making axiom and conjecture clauses *)
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   284
fun make_clause(clause_id,axiom_name,kind,th) =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   285
    let val (lits,ctypes_sorts) = literals_of_term (to_comb (prop_of th) [])
18856
4669dec681f4 tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents: 18725
diff changeset
   286
	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
   287
    in
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   288
	if forall isFalse lits
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   289
	then error "Problem too trivial for resolution (empty clause)"
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   290
	else
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   291
	    Clause {clause_id = clause_id, axiom_name = axiom_name, th = th, kind = kind,
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   292
		    literals = lits, ctypes_sorts = ctypes_sorts, 
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   293
		    ctvar_type_literals = ctvar_lits,
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   294
		    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
   295
    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
   296
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   297
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   298
fun add_axiom_clause ((th,(name,id)), pairs) =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   299
  let val cls = make_clause(id, name, ResClause.Axiom, th)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   300
  in
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   301
      if isTaut cls then pairs else (name,cls)::pairs
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   302
  end;
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   303
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   304
val make_axiom_clauses = foldl add_axiom_clause [];
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   305
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
   306
fun make_conjecture_clauses_aux _ [] = []
20421
paulson
parents: 20360
diff changeset
   307
  | make_conjecture_clauses_aux n (th::ths) =
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   308
      make_clause(n,"conjecture", ResClause.Conjecture, th) ::
20421
paulson
parents: 20360
diff changeset
   309
      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
   310
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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 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
   312
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   313
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   314
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   315
(* 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
   316
(* TPTP used by Vampire and E                                         *)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   317
(* 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
   318
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   320
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
   321
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   322
fun wrap_type (c,tp) = case !typ_level of
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   323
	T_FULL => type_wrapper ^ ResClause.paren_pack [c, ResClause.string_of_fol_type tp]
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   324
      | _ => c;
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   325
    
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
   326
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   327
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
   328
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   329
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
   330
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   331
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
   332
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   333
fun type_of_combterm (CombConst(c,tp,_)) = tp
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   334
  | type_of_combterm (CombFree(v,tp)) = tp
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   335
  | type_of_combterm (CombVar(v,tp)) = tp
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   336
  | type_of_combterm (CombApp(t1,t2,tp)) = 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
   337
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   338
fun string_of_combterm1 (CombConst(c,tp,_)) = 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   339
      let val c' = if c = "equal" then "c_fequal" else c
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   340
      in  wrap_type (c',tp)  end
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   341
  | string_of_combterm1 (CombFree(v,tp)) = wrap_type (v,tp)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   342
  | string_of_combterm1 (CombVar(v,tp)) = wrap_type (v,tp)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   343
  | string_of_combterm1 (CombApp(t1,t2,tp)) =
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   344
      let val s1 = string_of_combterm1 t1
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   345
	  val s2 = string_of_combterm1 t2
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   346
      in
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   347
	  case !typ_level of
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   348
	      T_FULL => type_wrapper ^ 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   349
	                ResClause.paren_pack 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   350
	                  [app_str ^ ResClause.paren_pack [s1,s2], 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   351
	                   ResClause.string_of_fol_type tp]
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   352
	    | T_PARTIAL => app_str ^ ResClause.paren_pack 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   353
	                     [s1,s2, ResClause.string_of_fol_type (type_of_combterm t1)]
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   354
	    | T_NONE => app_str ^ ResClause.paren_pack [s1,s2]
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   355
	    | T_CONST => raise ERROR "string_of_combterm1"
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   356
      end;
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   357
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   358
fun string_of_combterm2 (CombConst(c,tp,tvars)) = 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   359
      let val tvars' = map ResClause.string_of_fol_type tvars
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   360
	  val c' = if c = "equal" then "c_fequal" else c
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   361
      in
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   362
	  c' ^ ResClause.paren_pack tvars'
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   363
      end
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   364
  | string_of_combterm2 (CombFree(v,tp)) = v
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   365
  | string_of_combterm2 (CombVar(v,tp)) = v
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   366
  | string_of_combterm2 (CombApp(t1,t2,_)) =
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   367
      app_str ^ ResClause.paren_pack [string_of_combterm2 t1, string_of_combterm2 t2];
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   368
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   369
fun string_of_combterm t = 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   370
    case !typ_level of T_CONST => string_of_combterm2 t
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   371
		           | _ => string_of_combterm1 t;
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   372
		           
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   373
fun string_of_predicate (CombApp(CombApp(CombConst("equal",_,_),t1,_),t2,_)) =
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   374
      ("equal" ^ ResClause.paren_pack [string_of_combterm t1, string_of_combterm t2])
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   375
  | string_of_predicate t = 
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   376
      bool_str ^ ResClause.paren_pack [string_of_combterm t]
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   377
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
   378
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
   379
    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
   380
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   381
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
   382
    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
   383
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   384
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   385
(*** tptp format ***)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   386
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   387
fun tptp_of_equality pol (t1,t2) =
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   388
  let val eqop = if pol then " = " else " != "
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   389
  in  string_of_combterm t1 ^ eqop ^ string_of_combterm t2  end;
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   390
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   391
fun tptp_literal (Literal(pol, CombApp(CombApp(CombConst("equal",_,_),t1,_),t2,_))) = 
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   392
      tptp_of_equality pol (t1,t2)
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   393
  | tptp_literal (Literal(pol,pred)) = 
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   394
      ResClause.tptp_sign pol (string_of_predicate 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
   395
 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   396
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
   397
    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
   398
	val ctvar_lits_strs =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   399
	    case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   400
	      | _ => 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
   401
	val ctfree_lits = 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   402
	    case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   403
	      | _ => 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
   404
    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
   405
	(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
   406
    end; 
18356
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
    
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   409
fun clause2tptp (cls as Clause{axiom_name,clause_id,kind,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
   410
    let val (lits,ctfree_lits) = tptp_type_lits cls
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   411
	val cls_str = ResClause.gen_tptp_cls(clause_id,axiom_name,kind,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
   412
    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
   413
	(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
   414
    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
   415
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   416
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   417
(*** dfg format ***)
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   418
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   419
fun dfg_literal (Literal(pol,pred)) = ResClause.dfg_sign pol (string_of_predicate pred);
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   420
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   421
fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   422
  let val lits = map dfg_literal literals
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   423
      val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   424
      val tvar_lits_strs = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   425
	  case !typ_level of T_NONE => [] 
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   426
	      | _ => map ResClause.dfg_of_typeLit tvar_lits
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   427
      val tfree_lits =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   428
          case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   429
	      | _ => map ResClause.dfg_of_typeLit tfree_lits 
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   430
  in
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   431
      (tvar_lits_strs @ lits, tfree_lits)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   432
  end; 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   433
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   434
fun get_uvars (CombConst(_,_,_)) vars = vars
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   435
  | get_uvars (CombFree(_,_)) vars = vars
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   436
  | get_uvars (CombVar(v,tp)) vars = (v::vars)
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   437
  | get_uvars (CombApp(P,Q,tp)) vars = get_uvars P (get_uvars Q vars);
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   438
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   439
fun get_uvars_l (Literal(_,c)) = get_uvars c [];
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   440
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   441
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
   442
 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   443
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
   444
    let val (lits,tfree_lits) = dfg_clause_aux cls 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   445
        val vars = dfg_vars cls
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   446
        val tvars = ResClause.get_tvar_strs ctypes_sorts
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   447
	val knd = ResClause.name_of_kind kind
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   448
	val lits_str = commas lits
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   449
	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
   450
    in (cls_str, tfree_lits) end;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   451
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   452
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   453
fun init_funcs_tab funcs = 
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   454
    let val funcs1 = case !typ_level of T_PARTIAL => Symtab.update ("hAPP",3) funcs
20865
2cfa020109c1 Changed and removed some functions related to combinators, since they are Isabelle constants now.
mengj
parents: 20864
diff changeset
   455
				      | _ => Symtab.update ("hAPP",2) funcs
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   456
    in
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   457
	Symtab.update ("typeinfo",2) funcs1
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   458
    end;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   459
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   460
19725
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   461
fun add_funcs (CombConst(c,_,tvars),funcs) =
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   462
      if c = "equal" then foldl ResClause.add_foltype_funcs funcs tvars
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   463
      else
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   464
	(case !typ_level of
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   465
	     T_CONST => foldl ResClause.add_foltype_funcs (Symtab.update(c,length tvars) funcs) tvars
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   466
           | _ => foldl ResClause.add_foltype_funcs (Symtab.update(c,0) funcs) tvars)
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   467
  | 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
   468
  | add_funcs (CombVar(_,ctp),funcs) = ResClause.add_foltype_funcs (ctp,funcs)
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   469
  | add_funcs (CombApp(P,Q,_),funcs) = add_funcs(P,add_funcs (Q,funcs));
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   470
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   471
fun add_literal_funcs (Literal(_,c), funcs) = add_funcs (c,funcs);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   472
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   473
fun add_clause_funcs (Clause {literals, ...}, funcs) =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   474
    foldl add_literal_funcs funcs literals
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   475
    handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities")
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   476
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   477
fun funcs_of_clauses clauses arity_clauses =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   478
    Symtab.dest (foldl ResClause.add_arityClause_funcs 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   479
                       (foldl add_clause_funcs (init_funcs_tab Symtab.empty) clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   480
                       arity_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   481
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   482
fun add_clause_preds (Clause {ctypes_sorts, ...}, preds) =
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   483
  foldl ResClause.add_type_sort_preds preds ctypes_sorts
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   484
  handle Symtab.DUP a => raise ERROR ("predicate " ^ a ^ " has multiple arities")
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   485
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   486
(*Higher-order clauses have only the predicates hBOOL and type classes.*)
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   487
fun preds_of_clauses clauses clsrel_clauses arity_clauses = 
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   488
    Symtab.dest
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   489
	(foldl ResClause.add_classrelClause_preds 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   490
	       (foldl ResClause.add_arityClause_preds
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   491
		      (Symtab.update ("hBOOL",1) 
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   492
		        (foldl add_clause_preds Symtab.empty clauses))
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   493
		      arity_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   494
	       clsrel_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   495
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   496
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   497
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   498
(**********************************************************************)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   499
(* write clauses to files                                             *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   500
(**********************************************************************)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   501
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   502
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   503
val init_counters =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   504
    Symtab.make [("c_COMBI", 0), ("c_COMBK", 0),
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   505
		 ("c_COMBB", 0), ("c_COMBC", 0),
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   506
		 ("c_COMBS", 0), ("c_COMBB_e", 0),
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   507
		 ("c_COMBC_e", 0), ("c_COMBS_e", 0)];
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   508
                
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   509
fun count_combterm (CombConst(c,tp,_), ct) = 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   510
     (case Symtab.lookup ct c of NONE => ct  (*no counter*)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   511
                               | SOME n => Symtab.update (c,n+1) ct)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   512
  | count_combterm (CombFree(v,tp), ct) = ct
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   513
  | count_combterm (CombVar(v,tp), ct) = ct
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   514
  | count_combterm (CombApp(t1,t2,tp), ct) = count_combterm(t1, count_combterm(t2, ct));
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   515
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   516
fun count_literal (Literal(_,t), ct) = count_combterm(t,ct);
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   517
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   518
fun count_clause (Clause{literals,...}, ct) = foldl count_literal ct literals;
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   519
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   520
fun count_user_clause user_lemmas (Clause{axiom_name,literals,...}, ct) = 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   521
  if axiom_name mem_string user_lemmas then foldl count_literal ct literals
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   522
  else ct;
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   523
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   524
val cnf_helper_thms = ResAxioms.cnf_rules_pairs o (map ResAxioms.pairname)
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   525
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   526
fun get_helper_clauses ct =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   527
    let fun needed c = valOf (Symtab.lookup ct c) > 0
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   528
        val IK = if needed "c_COMBI" orelse needed "c_COMBK" 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   529
                 then (Output.debug "Include combinator I K"; cnf_helper_thms [comb_I,comb_K]) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   530
                 else []
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   531
	val BC = if needed "c_COMBB" orelse needed "c_COMBC" 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   532
	         then (Output.debug "Include combinator B C"; cnf_helper_thms [comb_B,comb_C]) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   533
	         else []
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   534
	val S = if needed "c_COMBS" 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   535
	        then (Output.debug "Include combinator S"; cnf_helper_thms [comb_S]) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   536
	        else []
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   537
	val B'C' = if needed "c_COMBB_e" orelse needed "c_COMBC_e" 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   538
	           then (Output.debug "Include combinator B' C'"; cnf_helper_thms [comb_B', comb_C']) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   539
	           else []
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   540
	val S' = if needed "c_COMBS_e" 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   541
	         then (Output.debug "Include combinator S'"; cnf_helper_thms [comb_S']) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   542
	         else []
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   543
	val other = cnf_helper_thms [ext,fequal_imp_equal,equal_imp_fequal]
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   544
    in
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   545
	make_axiom_clauses (other @ IK @ BC @ S @ B'C' @ S')
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   546
    end
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   547
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   548
(* tptp format *)
19491
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   549
						  
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   550
(* write TPTP format to a single file *)
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   551
fun tptp_write_file thms filename (axclauses,classrel_clauses,arity_clauses) user_lemmas =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   552
    let val conjectures = make_conjecture_clauses thms
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   553
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   554
	val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp conjectures)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   555
	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
   556
	val out = TextIO.openOut filename
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   557
	val ct = foldl (count_user_clause user_lemmas) 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   558
	            (foldl count_clause init_counters conjectures)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   559
	            axclauses'
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   560
	val helper_clauses = map #2 (get_helper_clauses ct)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   561
    in
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   562
	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
   563
	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
   564
	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
   565
	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
   566
	List.app (curry TextIO.output out o ResClause.tptp_arity_clause) arity_clauses;
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   567
	List.app (curry TextIO.output out o #1 o clause2tptp) helper_clauses;
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   568
	TextIO.closeOut out;
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   569
	clnames
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   570
    end;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   571
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   572
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   573
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   574
(* dfg format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   575
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   576
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
   577
    let val _ = Output.debug ("Preparing to write the DFG file " ^ filename) 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   578
	val conjectures = make_conjecture_clauses thms
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   579
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   580
	val (dfg_clss,tfree_litss) = ListPair.unzip (map clause2dfg conjectures)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   581
	and probname = Path.pack (Path.base (Path.unpack filename))
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   582
	val axstrs = map (#1 o clause2dfg) axclauses'
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   583
	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
   584
	val out = TextIO.openOut filename
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   585
	val ct = foldl (count_user_clause user_lemmas) 
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   586
	            (foldl count_clause init_counters conjectures)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   587
	            axclauses'
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   588
	val helper_clauses = map #2 (get_helper_clauses ct)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   589
	val helper_clauses_strs = map (#1 o clause2dfg) helper_clauses
20864
bb75b876b260 Now the DFG output includes correct declarations of c_fequal, but not hEXTENT
paulson
parents: 20791
diff changeset
   590
	val funcs = funcs_of_clauses (helper_clauses @ conjectures @ axclauses') arity_clauses
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   591
	and preds = preds_of_clauses axclauses' classrel_clauses arity_clauses
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   592
    in
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   593
	TextIO.output (out, ResClause.string_of_start probname); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   594
	TextIO.output (out, ResClause.string_of_descrip probname); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   595
	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
   596
	TextIO.output (out, "list_of_clauses(axioms,cnf).\n");
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   597
	ResClause.writeln_strs out axstrs;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   598
	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
   599
	List.app (curry TextIO.output out o ResClause.dfg_arity_clause) arity_clauses;
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   600
	ResClause.writeln_strs out helper_clauses_strs;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   601
	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
   602
	ResClause.writeln_strs out tfree_clss;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   603
	ResClause.writeln_strs out dfg_clss;
20953
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
   604
	TextIO.output (out, "end_of_list.\n\n");
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
   605
	(*VarWeight=3 helps the HO problems, probably by counteracting the presence of hAPP*)
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
   606
	TextIO.output (out, "list_of_settings(SPASS).\n{*\nset_flag(VarWeight,3).\n*}\nend_of_list.\n\n");
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
   607
	TextIO.output (out, "end_problem.\n");
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   608
	TextIO.closeOut out;
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   609
	clnames
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   610
    end;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   611
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   612
end