src/HOL/Tools/res_hol_clause.ML
author wenzelm
Fri, 17 Nov 2006 02:20:03 +0100
changeset 21404 eb85850d3eb7
parent 21398 11996e938dfe
child 21470 7c1b59ddcd56
permissions -rw-r--r--
more robust syntax for definition/abbreviation/notation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     1
(* ID: $Id$ 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     2
   Author: Jia Meng, NICTA
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     3
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     4
FOL clauses translated from HOL formulae.  Combinators are used to represent lambda terms.
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     5
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     6
*)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     7
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     8
structure ResHolClause =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
     9
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    10
struct
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    11
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
    12
(* 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
    13
val ext = thm "HOL.ext";
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    14
val comb_I = thm "ATP_Linkup.COMBI_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    15
val comb_K = thm "ATP_Linkup.COMBK_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    16
val comb_B = thm "ATP_Linkup.COMBB_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    17
val comb_C = thm "ATP_Linkup.COMBC_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    18
val comb_S = thm "ATP_Linkup.COMBS_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    19
val comb_B' = thm "ATP_Linkup.COMBB'_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    20
val comb_C' = thm "ATP_Linkup.COMBC'_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    21
val comb_S' = thm "ATP_Linkup.COMBS'_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    22
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
    23
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
    24
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    25
(*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
    26
  combinators appear to work best.*)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    27
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
    28
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    29
(*FIXME: these refs should probaby replaced by code to count the combinators in the 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
    30
  translated form of the term.*)
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    31
val combI_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    32
val combK_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    33
val combB_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    34
val combC_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    35
val combS_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    36
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    37
val combB'_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    38
val combC'_count = ref 0;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    39
val combS'_count = ref 0; 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    40
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
    41
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    42
fun increI count_comb =  if count_comb then combI_count := !combI_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    43
fun increK count_comb =  if count_comb then combK_count := !combK_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    44
fun increB count_comb =  if count_comb then combB_count := !combB_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    45
fun increC count_comb =  if count_comb then combC_count := !combC_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    46
fun increS count_comb =  if count_comb then combS_count := !combS_count + 1 else (); 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    47
fun increB' count_comb =  if count_comb then combB'_count := !combB'_count + 1 else (); 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    48
fun increC' count_comb =  if count_comb then combC'_count := !combC'_count + 1 else ();
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    49
fun increS' count_comb =  if count_comb then combS'_count := !combS'_count + 1 else (); 
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    50
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    51
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    52
exception DECRE_COMB of string;
20953
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    53
fun decreB count_comb n = 
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    54
  if count_comb then 
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    55
    if !combB_count >= n then combB_count := !combB_count - n else raise DECRE_COMB "COMBB"
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    56
  else ();
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    57
20953
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    58
fun decreC count_comb n =
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    59
  if count_comb then 
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    60
    if !combC_count >= n then combC_count := !combC_count - n else raise DECRE_COMB "COMBC"
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    61
  else ();
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    62
20953
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    63
fun decreS count_comb n = 
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    64
  if count_comb then 
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    65
    if !combS_count >= n then combS_count := !combS_count - n else raise DECRE_COMB "COMBS"
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
    66
  else ();
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
    67
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
    68
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
    69
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    70
fun init thy = (combI_count:=0; combK_count:=0;combB_count:=0;combC_count:=0;combS_count:=0;combB'_count:=0;combC'_count:=0;combS'_count:=0;
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
    71
                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
    72
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
    73
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    74
(* 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
    75
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    76
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    77
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
    78
  | 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
    79
  | 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
    80
  | 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
    81
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    82
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    83
(*******************************************)
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    84
fun mk_compact_comb (tm as (Const("ATP_Linkup.COMBB",_)$p) $ (Const("ATP_Linkup.COMBB",_)$q$r)) Bnds count_comb =
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    85
    let val tp_p = Term.type_of1(Bnds,p)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    86
	val tp_q = Term.type_of1(Bnds,q)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    87
	val tp_r = Term.type_of1(Bnds,r)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    88
	val typ = Term.type_of1(Bnds,tm)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    89
	val typ_B' = [tp_p,tp_q,tp_r] ---> typ
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    90
	val _ = increB' count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    91
	val _ = decreB count_comb 2
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    92
    in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    93
	Const("ATP_Linkup.COMBB'",typ_B') $ p $ q $ r
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    94
    end
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    95
  | mk_compact_comb (tm as (Const("ATP_Linkup.COMBC",_) $ (Const("ATP_Linkup.COMBB",_)$p$q) $ r)) Bnds count_comb =
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    96
    let val tp_p = Term.type_of1(Bnds,p)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    97
	val tp_q = Term.type_of1(Bnds,q)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    98
	val tp_r = Term.type_of1(Bnds,r)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
    99
	val typ = Term.type_of1(Bnds,tm)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   100
	val typ_C' = [tp_p,tp_q,tp_r] ---> typ
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   101
	val _ = increC' count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   102
	val _ = decreC count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   103
	val _ = decreB count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   104
    in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   105
	Const("ATP_Linkup.COMBC'",typ_C') $ p $ q $ r
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   106
    end
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   107
  | mk_compact_comb (tm as (Const("ATP_Linkup.COMBS",_) $ (Const("ATP_Linkup.COMBB",_)$p$q) $ r)) Bnds count_comb =
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   108
    let val tp_p = Term.type_of1(Bnds,p)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   109
	val tp_q = Term.type_of1(Bnds,q)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   110
	val tp_r = Term.type_of1(Bnds,r)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   111
	val typ = Term.type_of1(Bnds,tm)
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   112
	val typ_S' = [tp_p,tp_q,tp_r] ---> typ
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   113
	val _ = increS' count_comb
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   114
	val _ = decreS count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   115
	val _ = decreB count_comb 1
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   116
    in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   117
	Const("ATP_Linkup.COMBS'",typ_S') $ p $ q $ r
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   118
    end
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   119
  | mk_compact_comb tm _ _ = tm;
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   120
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   121
fun compact_comb t Bnds count_comb = 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   122
  if !use_Turner then mk_compact_comb t Bnds count_comb else t;
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   123
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   124
fun lam2comb (Abs(x,tp,Bound 0)) _ count_comb = 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   125
      let val _ = increI count_comb
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   126
      in 
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   127
	  Const("ATP_Linkup.COMBI",tp-->tp) 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   128
      end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   129
  | lam2comb (Abs(x,tp,Bound n)) Bnds count_comb = 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   130
      let val tb = List.nth(Bnds,n-1)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   131
	  val _ = increK count_comb 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   132
      in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   133
	  Const("ATP_Linkup.COMBK", [tb,tp] ---> tb) $ (Bound (n-1))
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   134
      end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   135
  | lam2comb (Abs(x,t1,Const(c,t2))) _ count_comb = 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   136
      let val _ = increK count_comb 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   137
      in 
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   138
	  Const("ATP_Linkup.COMBK",[t2,t1] ---> t2) $ Const(c,t2) 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   139
      end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   140
  | lam2comb (Abs(x,t1,Free(v,t2))) _ count_comb =
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   141
      let val _ = increK count_comb
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   142
      in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   143
	  Const("ATP_Linkup.COMBK",[t2,t1] ---> t2) $ Free(v,t2)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   144
      end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   145
  | lam2comb (Abs(x,t1,Var(ind,t2))) _ count_comb =
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   146
      let val _ = increK count_comb 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   147
      in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   148
	  Const("ATP_Linkup.COMBK", [t2,t1] ---> t2) $ Var(ind,t2)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   149
      end
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   150
  | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds count_comb =
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   151
      let val tr = Term.type_of1(t1::Bnds,P)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   152
      in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   153
	  if not(is_free P 0) then (incr_boundvars ~1 P)
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   154
	  else 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   155
	  let val tI = [t1] ---> t1
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   156
	      val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   157
	      val tp' = Term.type_of1(Bnds,P')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   158
	      val tS = [tp',tI] ---> tr
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   159
	      val _ = increI count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   160
	      val _ = increS count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   161
	  in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   162
	      compact_comb (Const("ATP_Linkup.COMBS",tS) $ P' $ 
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   163
	                     Const("ATP_Linkup.COMBI",tI)) Bnds count_comb
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   164
	  end
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   165
      end	    
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   166
  | lam2comb (t as (Abs(x,t1,P$Q))) Bnds count_comb =
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   167
      let val nfreeP = not(is_free P 0)
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   168
	  and nfreeQ = not(is_free Q 0)
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   169
	  val tpq = Term.type_of1(t1::Bnds, P$Q) 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   170
      in
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   171
	  if nfreeP andalso nfreeQ 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   172
	  then 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   173
	    let val tK = [tpq,t1] ---> tpq
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   174
		val PQ' = incr_boundvars ~1(P $ Q)
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   175
		val _ = increK count_comb
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   176
	    in 
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   177
		Const("ATP_Linkup.COMBK",tK) $ PQ'
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   178
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   179
	  else if nfreeP then 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   180
	    let val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   181
		val P' = incr_boundvars ~1 P
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   182
		val tp = Term.type_of1(Bnds,P')
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   183
		val tq' = Term.type_of1(Bnds, Q')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   184
		val tB = [tp,tq',t1] ---> tpq
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   185
		val _ = increB count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   186
	    in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   187
		compact_comb (Const("ATP_Linkup.COMBB",tB) $ P' $ Q') Bnds count_comb 
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   188
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   189
	  else if nfreeQ then 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   190
	    let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   191
		val Q' = incr_boundvars ~1 Q
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   192
		val tq = Term.type_of1(Bnds,Q')
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   193
		val tp' = Term.type_of1(Bnds, P')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   194
		val tC = [tp',tq,t1] ---> tpq
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   195
		val _ = increC count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   196
	    in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   197
		compact_comb (Const("ATP_Linkup.COMBC",tC) $ P' $ Q') Bnds count_comb
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   198
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   199
          else
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   200
	    let val P' = lam2comb (Abs(x,t1,P)) Bnds count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   201
		val Q' = lam2comb (Abs(x,t1,Q)) Bnds count_comb 
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   202
		val tp' = Term.type_of1(Bnds,P')
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   203
		val tq' = Term.type_of1(Bnds,Q')
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   204
		val tS = [tp',tq',t1] ---> tpq
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   205
		val _ = increS count_comb
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   206
	    in
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   207
		compact_comb (Const("ATP_Linkup.COMBS",tS) $ P' $ Q') Bnds count_comb
21108
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   208
	    end
04d8e6eb9a2e Purely cosmetic
paulson
parents: 20997
diff changeset
   209
      end
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   210
  | 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
   211
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   212
(*********************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   213
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   214
fun to_comb (Abs(x,tp,b)) Bnds count_comb =
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   215
    let val b' = to_comb b (tp::Bnds) count_comb
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   216
    in lam2comb (Abs(x,tp,b')) Bnds count_comb end
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   217
  | to_comb (P $ Q) Bnds count_comb = ((to_comb P Bnds count_comb) $ (to_comb Q Bnds count_comb))
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   218
  | 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
   219
 
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   220
   
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   221
fun comb_of t count_comb = to_comb t [] count_comb;
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   222
 
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
   223
(* print a term containing combinators, used for debugging *)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   224
exception TERM_COMB of term;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   225
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   226
fun string_of_term (Const(c,t)) = c
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   227
  | string_of_term (Free(v,t)) = v
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   228
  | string_of_term (Var((x,n),t)) = x ^ "_" ^ (string_of_int n)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   229
  | string_of_term (P $ Q) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   230
      "(" ^ string_of_term P ^ " " ^ string_of_term Q ^ ")" 
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   231
  | string_of_term t =  raise TERM_COMB (t);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   232
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   233
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   234
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   235
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   236
(* 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
   237
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   238
20281
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   239
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
   240
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   241
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
   242
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   243
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
   244
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
   245
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
   246
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
   247
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   248
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   249
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
   250
16733b31e1cf Only ignore too general axiom clauses, if the translation is partial- or constant-typed.
mengj
parents: 20274
diff changeset
   251
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
   252
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
   253
datatype kind = Axiom | Conjecture;
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   254
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
   255
fun name_of_kind Axiom = "axiom"
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   256
  | name_of_kind Conjecture = "conjecture";
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   257
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   258
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
   259
type indexname = Term.indexname;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   260
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
   261
type csort = Term.sort;
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   262
type ctyp = ResClause.fol_type;
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   263
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   264
val string_of_ctyp = ResClause.string_of_fol_type;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   265
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   266
type ctyp_var = ResClause.typ_var;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   267
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
type ctype_literal = ResClause.type_literal;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   269
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   270
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   271
datatype combterm = CombConst of string * ctyp * ctyp list
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   272
		  | CombFree of string * ctyp
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   273
		  | CombVar of string * ctyp
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   274
		  | CombApp of combterm * combterm * ctyp
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   275
		  | Bool of combterm;
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   276
		  
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
   277
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
   278
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   279
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
   280
	 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
   281
		    axiom_name: axiom_name,
19964
73704ba4bed1 added the "th" field to datatype Clause
paulson
parents: 19745
diff changeset
   282
		    th: thm,
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   283
		    kind: kind,
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   284
		    literals: literal list,
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   285
		    ctypes_sorts: (ctyp_var * csort) list, 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   286
                    ctvar_type_literals: ctype_literal list, 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   287
                    ctfree_type_literals: ctype_literal list};
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   288
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   289
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   290
fun string_of_kind (Clause cls) = name_of_kind (#kind cls);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   291
fun get_axiomName (Clause cls) = #axiom_name cls;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   292
fun get_clause_id (Clause cls) = #clause_id cls;
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   293
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   294
fun get_literals (c as Clause(cls)) = #literals cls;
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   295
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
   296
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   297
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   298
(* 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
   299
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   300
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   301
fun isFalse (Literal(pol,Bool(CombConst(c,_,_)))) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   302
      (pol andalso c = "c_False") orelse
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   303
      (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
   304
  | 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
   305
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   307
fun isTrue (Literal (pol,Bool(CombConst(c,_,_)))) =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   308
      (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
   309
      (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
   310
  | 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
   311
  
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
   313
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   314
fun type_of (Type (a, Ts)) =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   315
    let val (folTypes,ts) = types_of Ts
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   316
	val t = ResClause.make_fixed_type_const a
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   317
    in
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   318
	(ResClause.mk_fol_type("Comp",t,folTypes),ts)
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   319
    end
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   320
  | type_of (tp as (TFree(a,s))) =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   321
    let val t = ResClause.make_fixed_type_var a
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   322
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   323
	(ResClause.mk_fol_type("Fixed",t,[]),[ResClause.mk_typ_var_sort tp])
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   324
    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
   325
  | type_of (tp as (TVar(v,s))) =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   326
    let val t = ResClause.make_schematic_type_var v
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   327
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   328
	(ResClause.mk_fol_type("Var",t,[]),[ResClause.mk_typ_var_sort tp])
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   329
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   330
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   331
and types_of Ts =
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   332
    let val foltyps_ts = map type_of Ts
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   333
	val (folTyps,ts) = ListPair.unzip foltyps_ts
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   334
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   335
	(folTyps,ResClause.union_all ts)
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   336
    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
   337
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   338
(* 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
   339
fun simp_type_of (Type (a, Ts)) = 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   340
    let val typs = map simp_type_of Ts
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   341
	val t = ResClause.make_fixed_type_const a
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   342
    in
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   343
	ResClause.mk_fol_type("Comp",t,typs)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   344
    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
   345
  | 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
   346
  | 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
   347
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   348
20865
2cfa020109c1 Changed and removed some functions related to combinators, since they are Isabelle constants now.
mengj
parents: 20864
diff changeset
   349
fun const_type_of (c,t) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   350
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   351
	val tvars = !const_typargs(c,t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   352
	val tvars' = map simp_type_of tvars
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   353
    in
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   354
	(tp,ts,tvars')
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   355
    end;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   356
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   357
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   358
fun is_bool_type (Type("bool",[])) = true
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   359
  | is_bool_type _ = false;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   360
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   361
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   362
(* 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
   363
fun combterm_of (Const(c,t)) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   364
    let val (tp,ts,tvar_list) = const_type_of (c,t)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   365
	val is_bool = is_bool_type t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   366
	val c' = CombConst(ResClause.make_fixed_const c,tp,tvar_list)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   367
	val c'' = if is_bool then Bool(c') else c'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   368
    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
   369
	(c'',ts)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   370
    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
   371
  | combterm_of (Free(v,t)) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   372
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   373
	val is_bool = is_bool_type t
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   374
	val v' = if ResClause.isMeta v then CombVar(ResClause.make_schematic_var(v,0),tp)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   375
		 else CombFree(ResClause.make_fixed_var v,tp)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   376
	val v'' = if is_bool then Bool(v') else v'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   377
    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
   378
	(v'',ts)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   379
    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
   380
  | combterm_of (Var(v,t)) =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   381
    let val (tp,ts) = type_of t
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   382
	val is_bool = is_bool_type t
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   383
	val v' = CombVar(ResClause.make_schematic_var v,tp)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   384
	val v'' = if is_bool then Bool(v') else v'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   385
    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
   386
	(v'',ts)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   387
    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
   388
  | combterm_of (t as (P $ Q)) =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   389
    let val (P',tsP) = combterm_of P
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   390
	val (Q',tsQ) = combterm_of Q
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   391
	val tp = Term.type_of t
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   392
	val tp' = simp_type_of tp
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   393
	val is_bool = is_bool_type tp
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   394
	val t' = CombApp(P',Q',tp')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   395
	val t'' = if is_bool then Bool(t') else t'
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   396
    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
   397
	(t'',tsP union tsQ)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   398
    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
   399
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   400
fun predicate_of ((Const("Not",_) $ P), polarity) =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   401
    predicate_of (P, not polarity)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   402
  | predicate_of (term,polarity) = (combterm_of term,polarity);
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   403
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
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
   406
  | literals_of_term1 args (Const("op |",_) $ P $ Q) = 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   407
    let val args' = literals_of_term1 args P
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   408
    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
   409
	literals_of_term1 args' Q
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   410
    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
   411
  | literals_of_term1 (lits,ts) P =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   412
    let val ((pred,ts'),pol) = predicate_of (P,true)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   413
	val lits' = Literal(pol,pred)::lits
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   414
    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
   415
	(lits',ts union ts')
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   416
    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
   417
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   418
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   419
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
   420
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   421
fun occurs a (CombVar(b,_)) = a = b
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   422
  | occurs a (CombApp(t1,t2,_)) = (occurs a t1) orelse (occurs a t2)
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   423
  | occurs _ _ = false
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   424
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   425
fun too_general_terms (CombVar(v,_), t) = not (occurs v t)
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   426
  | too_general_terms _ = false;
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   427
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   428
fun too_general_equality (Literal(true,(Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))))) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   429
      too_general_terms (t1,t2) orelse too_general_terms (t2,t1)
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   430
  | too_general_equality _ = false;
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   431
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   432
(* forbid the literal hBOOL(V) *)
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   433
fun too_general_bool (Literal(_,Bool(CombVar _))) = true
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   434
  | too_general_bool _ = false;
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   435
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
   436
(* making axiom and conjecture clauses *)
20274
2d60a6ed67f1 Added in code to check too general axiom clauses.
mengj
parents: 20130
diff changeset
   437
exception MAKE_CLAUSE
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   438
fun make_clause(clause_id,axiom_name,kind,thm,is_user) =
19444
085568445283 Take conjectures and axioms as thms when convert them to ResHolClause.clause format.
mengj
parents: 19354
diff changeset
   439
    let val term = prop_of thm
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   440
	val term' = comb_of term is_user
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   441
	val (lits,ctypes_sorts) = literals_of_term term'
18856
4669dec681f4 tidy-up of res_clause.ML, removing the "predicates" field
paulson
parents: 18725
diff changeset
   442
	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
   443
    in
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   444
	if forall isFalse lits
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   445
	then error "Problem too trivial for resolution (empty clause)"
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   446
	else if (!typ_level <> T_FULL) andalso kind=Axiom andalso 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   447
	        (forall too_general_equality lits orelse exists too_general_bool lits)
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   448
	    then (Output.debug ("Omitting " ^ axiom_name ^ ": clause is too prolific"); 
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   449
	          raise MAKE_CLAUSE) 
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   450
	else
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   451
	    Clause {clause_id = clause_id, axiom_name = axiom_name, th = thm, kind = kind,
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   452
		    literals = lits, ctypes_sorts = ctypes_sorts, 
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   453
		    ctvar_type_literals = ctvar_lits,
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   454
		    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
   455
    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
   456
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   457
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   458
fun make_axiom_clause thm (ax_name,cls_id,is_user) = 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   459
      make_clause(cls_id,ax_name,Axiom,thm,is_user);
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   460
 
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   461
fun make_axiom_clauses [] user_lemmas = []
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   462
  | make_axiom_clauses ((thm,(name,id))::thms) user_lemmas =
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   463
    let val is_user = name mem user_lemmas
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   464
	val cls = SOME (make_axiom_clause thm (name,id,is_user)) 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   465
	          handle MAKE_CLAUSE => NONE
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   466
	val clss = make_axiom_clauses thms user_lemmas
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   467
    in
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   468
	case cls of NONE => clss
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   469
		  | SOME(cls') => if isTaut cls' then clss 
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   470
		                  else (name,cls')::clss
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   471
    end;
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   472
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   473
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   474
fun make_conjecture_clauses_aux _ [] = []
20421
paulson
parents: 20360
diff changeset
   475
  | make_conjecture_clauses_aux n (th::ths) =
paulson
parents: 20360
diff changeset
   476
      make_clause(n,"conjecture",Conjecture,th,true) ::
paulson
parents: 20360
diff changeset
   477
      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
   478
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   479
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
   480
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   481
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   482
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   483
(* 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
   484
(* TPTP used by Vampire and E                                         *)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   485
(* 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
   486
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   487
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   488
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
   489
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   490
fun wrap_type (c,t) = 
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   491
    case !typ_level of T_FULL => type_wrapper ^ ResClause.paren_pack [c,t]
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   492
		     | _ => c;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   493
    
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
   494
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   495
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
   496
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   497
val 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
   498
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   499
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
   500
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   501
exception STRING_OF_COMBTERM of int;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   502
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   503
(* convert literals of clauses into strings *)
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   504
fun string_of_combterm1_aux _ (CombConst(c,tp,_)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   505
    let val tp' = string_of_ctyp tp
20864
bb75b876b260 Now the DFG output includes correct declarations of c_fequal, but not hEXTENT
paulson
parents: 20791
diff changeset
   506
	val c' = if c = "equal" then "c_fequal" else c
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   507
    in
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   508
	(wrap_type (c',tp'),tp')
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   509
    end
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   510
  | string_of_combterm1_aux _ (CombFree(v,tp)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   511
    let val tp' = string_of_ctyp tp
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   512
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   513
	(wrap_type (v,tp'),tp')
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   514
    end
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   515
  | string_of_combterm1_aux _ (CombVar(v,tp)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   516
    let val tp' = string_of_ctyp tp
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   517
    in
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   518
	(wrap_type (v,tp'),tp')
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   519
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   520
  | string_of_combterm1_aux is_pred (CombApp(t1,t2,tp)) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   521
    let val (s1,tp1) = string_of_combterm1_aux is_pred t1
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   522
	val (s2,tp2) = string_of_combterm1_aux is_pred t2
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   523
	val tp' = ResClause.string_of_fol_type tp
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   524
	val r =	case !typ_level of
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   525
	            T_FULL => type_wrapper ^ ResClause.paren_pack [(app_str ^ ResClause.paren_pack [s1,s2]),tp']
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   526
		  | T_PARTIAL => app_str ^ ResClause.paren_pack [s1,s2,tp1]
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   527
		  | T_NONE => app_str ^ ResClause.paren_pack [s1,s2]
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   528
		  | T_CONST => raise STRING_OF_COMBTERM 1 (*should not happen, if happened may be a bug*)
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   529
    in	(r,tp')   end
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   530
  | string_of_combterm1_aux is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) =
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   531
    if is_pred then 
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   532
	let val (s1,_) = string_of_combterm1_aux false t1
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   533
	    val (s2,_) = string_of_combterm1_aux false t2
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   534
	in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   535
	    ("equal" ^ ResClause.paren_pack [s1,s2], bool_tp)
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   536
	end
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   537
    else
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   538
	let val (t,_) = string_of_combterm1_aux false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   539
	in
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   540
	    (t,bool_tp)
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   541
	end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   542
  | string_of_combterm1_aux is_pred (Bool(t)) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   543
    let val (t',_) = string_of_combterm1_aux false t
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   544
	val r = if is_pred then bool_str ^ ResClause.paren_pack [t']
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   545
		else t'
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   546
    in
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   547
	(r,bool_tp)
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   548
    end;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   549
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   550
fun string_of_combterm1 is_pred term = fst (string_of_combterm1_aux is_pred term);
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   551
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   552
fun string_of_combterm2 _ (CombConst(c,tp,tvars)) = 
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   553
    let val tvars' = map string_of_ctyp tvars
20864
bb75b876b260 Now the DFG output includes correct declarations of c_fequal, but not hEXTENT
paulson
parents: 20791
diff changeset
   554
	val c' = if c = "equal" then "c_fequal" else c
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   555
    in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   556
	c' ^ ResClause.paren_pack tvars'
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   557
    end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   558
  | string_of_combterm2 _ (CombFree(v,tp)) = v
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   559
  | string_of_combterm2 _ (CombVar(v,tp)) = v
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   560
  | string_of_combterm2 is_pred (CombApp(t1,t2,tp)) =
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   561
    let val s1 = string_of_combterm2 is_pred t1
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   562
	val s2 = string_of_combterm2 is_pred t2
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   563
    in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   564
	app_str ^ ResClause.paren_pack [s1,s2]
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   565
    end
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   566
  | string_of_combterm2 is_pred (Bool(CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))) =
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   567
    if is_pred then 
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   568
	let val s1 = string_of_combterm2 false t1
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   569
	    val s2 = string_of_combterm2 false t2
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   570
	in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   571
	    ("equal" ^ ResClause.paren_pack [s1,s2])
19452
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   572
	end
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   573
    else
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   574
	string_of_combterm2 false (CombApp(CombApp(CombConst("equal",tp,tps),t1,tp1),t2,tp2))
ef0ed2fe7bf2 Changed the treatment of equalities.
mengj
parents: 19444
diff changeset
   575
 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   576
  | string_of_combterm2 is_pred (Bool(t)) = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   577
    let val t' = string_of_combterm2 false t
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   578
    in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   579
	if is_pred then bool_str ^ ResClause.paren_pack [t']
18200
9d476d1054d7 -- terms are fully typed.
mengj
parents: 17998
diff changeset
   580
	else t'
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   581
    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
   582
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   583
fun string_of_combterm is_pred term = 
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   584
    case !typ_level of T_CONST => string_of_combterm2 is_pred term
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   585
		     | _ => string_of_combterm1 is_pred term;
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   586
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
   587
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
   588
    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
   589
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   590
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
   591
    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
   592
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   593
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   594
(* tptp format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   595
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
   596
fun tptp_literal (Literal(pol,pred)) =
18200
9d476d1054d7 -- terms are fully typed.
mengj
parents: 17998
diff changeset
   597
    let val pred_string = string_of_combterm true pred
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   598
	val pol_str = if pol then "++" else "--"
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   599
    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
   600
	pol_str ^ pred_string
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   601
    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
   602
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   603
 
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   604
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
   605
    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
   606
	val ctvar_lits_strs =
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   607
	    case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   608
	      | _ => 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
   609
	val ctfree_lits = 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   610
	    case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   611
	      | _ => 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
   612
    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
   613
	(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
   614
    end; 
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   615
    
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   616
    
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
   617
fun clause2tptp cls =
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   618
    let val (lits,ctfree_lits) = tptp_type_lits cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   619
	val cls_id = get_clause_id cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   620
	val ax_name = get_axiomName cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   621
	val knd = string_of_kind cls
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   622
	val lits_str = ResClause.bracket_pack lits
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   623
	val cls_str = ResClause.gen_tptp_cls(cls_id,ax_name,knd,lits_str)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   624
    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
   625
	(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
   626
    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
   627
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   628
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   629
(* dfg format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   630
fun dfg_literal (Literal(pol,pred)) = ResClause.dfg_sign pol (string_of_combterm true pred);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   631
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   632
fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   633
  let val lits = map dfg_literal literals
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   634
      val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   635
      val tvar_lits_strs = 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   636
	  case !typ_level of T_NONE => [] 
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   637
	      | _ => map ResClause.dfg_of_typeLit tvar_lits
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   638
      val tfree_lits =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   639
          case !typ_level of T_NONE => []
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   640
	      | _ => map ResClause.dfg_of_typeLit tfree_lits 
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   641
  in
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   642
      (tvar_lits_strs @ lits, tfree_lits)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   643
  end; 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   644
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   645
fun get_uvars (CombConst(_,_,_)) vars = vars
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   646
  | get_uvars (CombFree(_,_)) vars = vars
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   647
  | get_uvars (CombVar(v,tp)) vars = (v::vars)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   648
  | get_uvars (CombApp(P,Q,tp)) vars = get_uvars P (get_uvars Q vars)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   649
  | get_uvars (Bool(c)) vars = get_uvars c vars;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   650
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   651
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   652
fun get_uvars_l (Literal(_,c)) = get_uvars c [];
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   653
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   654
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
   655
 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   656
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
   657
    let val (lits,tfree_lits) = dfg_clause_aux cls 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   658
        val vars = dfg_vars cls
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   659
        val tvars = ResClause.get_tvar_strs ctypes_sorts
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   660
	val knd = name_of_kind kind
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   661
	val lits_str = commas lits
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   662
	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
   663
    in (cls_str, tfree_lits) end;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   664
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   665
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   666
fun init_funcs_tab funcs = 
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   667
    let val tp = !typ_level
20865
2cfa020109c1 Changed and removed some functions related to combinators, since they are Isabelle constants now.
mengj
parents: 20864
diff changeset
   668
	val funcs1 = case tp of T_PARTIAL => Symtab.update ("hAPP",3) funcs
2cfa020109c1 Changed and removed some functions related to combinators, since they are Isabelle constants now.
mengj
parents: 20864
diff changeset
   669
				      | _ => Symtab.update ("hAPP",2) funcs
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   670
	val funcs2 = case tp of T_FULL => Symtab.update ("typeinfo",2) funcs1
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   671
				      | _ => funcs1
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   672
    in
20865
2cfa020109c1 Changed and removed some functions related to combinators, since they are Isabelle constants now.
mengj
parents: 20864
diff changeset
   673
	funcs2
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   674
    end;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   675
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   676
19725
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   677
fun add_funcs (CombConst(c,_,tvars),funcs) =
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   678
    if c = "equal" then foldl ResClause.add_foltype_funcs funcs tvars
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   679
    else
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   680
	(case !typ_level of T_CONST => foldl ResClause.add_foltype_funcs (Symtab.update(c,length tvars) funcs) tvars
ada9bb1faba5 Changed the DFG format's functions' declaration procedure.
mengj
parents: 19724
diff changeset
   681
			  | _ => foldl ResClause.add_foltype_funcs (Symtab.update(c,0) funcs) tvars)
19724
20d76a40e362 Fixed a bug.
mengj
parents: 19720
diff changeset
   682
  | 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
   683
  | add_funcs (CombVar(_,ctp),funcs) = ResClause.add_foltype_funcs (ctp,funcs)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   684
  | add_funcs (CombApp(P,Q,_),funcs) = add_funcs(P,add_funcs (Q,funcs))
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   685
  | add_funcs (Bool(t),funcs) = add_funcs (t,funcs);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   686
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   687
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   688
fun add_literal_funcs (Literal(_,c), funcs) = add_funcs (c,funcs);
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   689
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   690
fun add_clause_funcs (Clause {literals, ...}, funcs) =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   691
    foldl add_literal_funcs funcs literals
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   692
    handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities")
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   693
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   694
fun funcs_of_clauses clauses arity_clauses =
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   695
    Symtab.dest (foldl ResClause.add_arityClause_funcs 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   696
                       (foldl add_clause_funcs (init_funcs_tab Symtab.empty) clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   697
                       arity_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   698
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   699
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
   700
  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
   701
  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
   702
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   703
(*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
   704
fun preds_of_clauses clauses clsrel_clauses arity_clauses = 
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   705
    Symtab.dest
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   706
	(foldl ResClause.add_classrelClause_preds 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   707
	       (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
   708
		      (Symtab.update ("hBOOL",1) 
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   709
		        (foldl add_clause_preds Symtab.empty clauses))
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   710
		      arity_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   711
	       clsrel_clauses)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   712
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   713
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   714
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   715
(**********************************************************************)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   716
(* write clauses to files                                             *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   717
(**********************************************************************)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   718
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   719
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
   720
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   721
(*Simulate the result of conversion to CNF*)
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   722
fun pretend_cnf s = (thm s, (s,0));
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   723
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   724
(*These theorems allow the proof of P=Q from P-->Q and Q-->P, so they are necessary for
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   725
  completeness. Unfortunately, they are very prolific, causing greatly increased runtimes.
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   726
  They also lead to many unsound proofs. Thus it is well that the "exists too_general_bool"
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   727
  test deletes them except with the full-typed translation.*)
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   728
val iff_thms = [pretend_cnf "ATP_Linkup.iff_positive", 
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   729
                pretend_cnf "ATP_Linkup.iff_negative"];
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   730
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   731
fun get_helper_clauses () =
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   732
    let val IK = if !combI_count > 0 orelse !combK_count > 0 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   733
                 then (Output.debug "Include combinator I K"; cnf_helper_thms [comb_I,comb_K]) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   734
                 else []
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   735
	val BC = if !combB_count > 0 orelse !combC_count > 0 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   736
	         then (Output.debug "Include combinator B C"; cnf_helper_thms [comb_B,comb_C]) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   737
	         else []
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   738
	val S = if !combS_count > 0 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   739
	        then (Output.debug "Include combinator S"; cnf_helper_thms [comb_S]) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   740
	        else []
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   741
	val B'C' = if !combB'_count > 0 orelse !combC'_count > 0 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   742
	           then (Output.debug "Include combinator B' C'"; cnf_helper_thms [comb_B', comb_C']) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   743
	           else []
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   744
	val S' = if !combS'_count > 0 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   745
	         then (Output.debug "Include combinator S'"; cnf_helper_thms [comb_S']) 
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   746
	         else []
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   747
	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
   748
    in
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   749
	make_axiom_clauses (iff_thms @ 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
   750
    end
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   751
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   752
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   753
(* tptp format *)
19491
cd6c71c57f53 changed the functions for getting HOL helper clauses.
mengj
parents: 19452
diff changeset
   754
						  
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   755
(* write TPTP format to a single file *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   756
(* when "get_helper_clauses" is called, "include_combS" and "include_min_comb" should have correct values already *)
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   757
fun tptp_write_file thms filename (axclauses,classrel_clauses,arity_clauses) user_lemmas=
19444
085568445283 Take conjectures and axioms as thms when convert them to ResHolClause.clause format.
mengj
parents: 19354
diff changeset
   758
    let val clss = make_conjecture_clauses thms
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   759
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses user_lemmas)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   760
	val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp clss)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   761
	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
   762
	val out = TextIO.openOut filename
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   763
	val helper_clauses = (#2 o ListPair.unzip o get_helper_clauses) ()
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   764
    in
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   765
	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
   766
	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
   767
	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
   768
	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
   769
	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
   770
	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
   771
	TextIO.closeOut out;
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   772
	clnames
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   773
    end;
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   774
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   775
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   776
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   777
(* dfg format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   778
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   779
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
   780
    let val _ = Output.debug ("Preparing to write the DFG file " ^ filename) 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   781
	val conjectures = make_conjecture_clauses thms
20130
5303e5928285 Only include combinators if required by goals and user specified lemmas.
mengj
parents: 20125
diff changeset
   782
        val (clnames,axclauses') = ListPair.unzip (make_axiom_clauses axclauses user_lemmas)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   783
	val (dfg_clss,tfree_litss) = ListPair.unzip (map clause2dfg conjectures)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   784
	and probname = Path.pack (Path.base (Path.unpack filename))
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   785
	val (axstrs,_) =  ListPair.unzip (map clause2dfg axclauses')
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   786
	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
   787
	val out = TextIO.openOut filename
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   788
	val helper_clauses = (#2 o ListPair.unzip o get_helper_clauses) ()
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   789
	val helper_clauses_strs = (#1 o ListPair.unzip o (map clause2dfg)) helper_clauses
20864
bb75b876b260 Now the DFG output includes correct declarations of c_fequal, but not hEXTENT
paulson
parents: 20791
diff changeset
   790
	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
   791
	and preds = preds_of_clauses axclauses' classrel_clauses arity_clauses
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   792
    in
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   793
	TextIO.output (out, ResClause.string_of_start probname); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   794
	TextIO.output (out, ResClause.string_of_descrip probname); 
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   795
	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
   796
	TextIO.output (out, "list_of_clauses(axioms,cnf).\n");
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   797
	ResClause.writeln_strs out axstrs;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   798
	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
   799
	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
   800
	ResClause.writeln_strs out helper_clauses_strs;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   801
	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
   802
	ResClause.writeln_strs out tfree_clss;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   803
	ResClause.writeln_strs out dfg_clss;
20953
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
   804
	TextIO.output (out, "end_of_list.\n\n");
1ea394dc2a0f Combinators require the theory name; added settings for SPASS
paulson
parents: 20865
diff changeset
   805
	(*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
   806
	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
   807
	TextIO.output (out, "end_problem.\n");
20022
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   808
	TextIO.closeOut out;
b07a138b4e7d some tidying; fixed the output of theorem names
paulson
parents: 20016
diff changeset
   809
	clnames
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   810
    end;
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   811
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   812
end