src/HOL/Tools/res_hol_clause.ML
author wenzelm
Mon, 22 Jun 2009 22:49:44 +0200
changeset 31756 178621145f98
parent 31752 19a5f1c8a844
child 31791 c9a1caf218c8
permissions -rw-r--r--
eval: tuned input buffer and get_offset (which ran very hot, up to the point where AFP/FlyspeckTame would seemingly take forever);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
     1
(*
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
     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
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
     4
FOL clauses translated from HOL formulae.
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
     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
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
     7
signature RES_HOL_CLAUSE =
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
     8
sig
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
     9
  val ext: thm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    10
  val comb_I: thm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    11
  val comb_K: thm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    12
  val comb_B: thm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    13
  val comb_C: thm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    14
  val comb_S: thm
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
    15
  datatype type_level = T_FULL | T_CONST
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
    16
  val typ_level: type_level
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
    17
  val minimize_applies: bool
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    18
  type axiom_name = string
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    19
  type polarity = bool
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    20
  type clause_id = int
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    21
  datatype combterm =
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    22
      CombConst of string * ResClause.fol_type * ResClause.fol_type list (*Const and Free*)
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    23
    | CombVar of string * ResClause.fol_type
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    24
    | CombApp of combterm * combterm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    25
  datatype literal = Literal of polarity * combterm
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
    26
  datatype clause = Clause of {clause_id: clause_id, axiom_name: axiom_name, th: thm,
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
    27
                    kind: ResClause.kind,literals: literal list, ctypes_sorts: typ list}
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    28
  val strip_comb: combterm -> combterm * combterm list
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
    29
  val literals_of_term: theory -> term -> literal list * typ list
28835
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
    30
  exception TOO_TRIVIAL
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    31
  val make_conjecture_clauses:  bool -> theory -> thm list -> clause list (* dfg thy ccls *)
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    32
  val make_axiom_clauses: bool ->
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    33
       theory ->
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    34
       (thm * (axiom_name * clause_id)) list -> (axiom_name * clause) list (* dfg thy axcls *)
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    35
  val get_helper_clauses: bool ->
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    36
       theory ->
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    37
       bool ->
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    38
       clause list * (thm * (axiom_name * clause_id)) list * string list ->
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    39
       clause list
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    40
  val tptp_write_file: string ->
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
    41
    clause list * clause list * clause list * ResClause.classrelClause list * ResClause.arityClause list -> unit
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
    42
  val dfg_write_file: string -> 
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
    43
    clause list * clause list * clause list * ResClause.classrelClause list * ResClause.arityClause list -> unit
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    44
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
    45
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    46
structure ResHolClause: RES_HOL_CLAUSE =
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
    47
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
    48
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
    49
structure RC = ResClause;
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
    50
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
    51
(* 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
    52
val ext = thm "HOL.ext";
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    53
val comb_I = thm "ATP_Linkup.COMBI_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    54
val comb_K = thm "ATP_Linkup.COMBK_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    55
val comb_B = thm "ATP_Linkup.COMBB_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    56
val comb_C = thm "ATP_Linkup.COMBC_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    57
val comb_S = thm "ATP_Linkup.COMBS_def";
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
    58
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
    59
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
    60
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    61
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    62
(*The different translations of types*)
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
    63
datatype type_level = T_FULL | T_CONST;
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    64
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
    65
val typ_level = T_CONST;
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    66
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
    67
(*If true, each function will be directly applied to as many arguments as possible, avoiding
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
    68
  use of the "apply" operator. Use of hBOOL is also minimized.*)
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
    69
val minimize_applies = true;
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
    70
30149
6b7ad52c5770 removed local ref const_min_arity
immler@in.tum.de
parents: 28835
diff changeset
    71
fun min_arity_of const_min_arity c = getOpt (Symtab.lookup const_min_arity c, 0);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
    72
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    73
(*True if the constant ever appears outside of the top-level position in literals.
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    74
  If false, the constant always receives all of its arguments and is used as a predicate.*)
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
    75
fun needs_hBOOL const_needs_hBOOL c = not minimize_applies orelse
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
    76
                    getOpt (Symtab.lookup const_needs_hBOOL c, false);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
    77
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
    78
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
    79
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* 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
    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
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
    84
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
    85
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
    86
23386
9255c1a75ba9 Now also handles FO problems
paulson
parents: 22851
diff changeset
    87
datatype combterm = CombConst of string * RC.fol_type * RC.fol_type list (*Const and Free*)
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    88
                  | CombVar of string * RC.fol_type
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    89
                  | CombApp of combterm * combterm
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    90
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
    91
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
    92
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    93
datatype clause =
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    94
         Clause of {clause_id: clause_id,
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    95
                    axiom_name: axiom_name,
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    96
                    th: thm,
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    97
                    kind: RC.kind,
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    98
                    literals: literal list,
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
    99
                    ctypes_sorts: typ 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
   100
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   101
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   102
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   103
(* 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
   104
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   105
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   106
fun isFalse (Literal(pol, CombConst(c,_,_))) =
20360
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   107
      (pol andalso c = "c_False") orelse
8c8c824dccdc tidying
paulson
parents: 20281
diff changeset
   108
      (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
   109
  | 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
   110
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   111
fun isTrue (Literal (pol, CombConst(c,_,_))) =
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   112
      (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
   113
      (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
   114
  | isTrue _ = false;
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   115
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   116
fun isTaut (Clause {literals,...}) = exists isTrue literals;
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
   117
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   118
fun type_of dfg (Type (a, Ts)) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   119
      let val (folTypes,ts) = types_of dfg Ts
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   120
      in  (RC.Comp(RC.make_fixed_type_const dfg a, folTypes), ts)  end
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   121
  | type_of dfg (tp as (TFree(a,s))) =
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   122
      (RC.AtomF (RC.make_fixed_type_var a), [tp])
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   123
  | type_of dfg (tp as (TVar(v,s))) =
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   124
      (RC.AtomV (RC.make_schematic_type_var v), [tp])
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   125
and types_of dfg Ts =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   126
      let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts)
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   127
      in  (folTyps, RC.union_all ts)  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
   128
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   129
(* same as above, but no gathering of sort information *)
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   130
fun simp_type_of dfg (Type (a, Ts)) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   131
      RC.Comp(RC.make_fixed_type_const dfg a, map (simp_type_of dfg) Ts)
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   132
  | simp_type_of dfg (TFree (a,s)) = RC.AtomF(RC.make_fixed_type_var a)
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   133
  | simp_type_of dfg (TVar (v,s)) = RC.AtomV(RC.make_schematic_type_var v);
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   134
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   135
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   136
fun const_type_of dfg thy (c,t) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   137
      let val (tp,ts) = type_of dfg t
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   138
      in  (tp, ts, map (simp_type_of dfg) (Sign.const_typargs thy (c,t))) end;
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   139
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
   140
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   141
fun combterm_of dfg thy (Const(c,t)) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   142
      let val (tp,ts,tvar_list) = const_type_of dfg thy (c,t)
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   143
          val c' = CombConst(RC.make_fixed_const dfg c, tp, tvar_list)
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   144
      in  (c',ts)  end
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   145
  | combterm_of dfg thy (Free(v,t)) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   146
      let val (tp,ts) = type_of dfg t
25243
78f8aaa27493 bugfixes concerning strange theorems
paulson
parents: 25008
diff changeset
   147
          val v' = CombConst(RC.make_fixed_var v, tp, [])
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   148
      in  (v',ts)  end
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   149
  | combterm_of dfg thy (Var(v,t)) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   150
      let val (tp,ts) = type_of dfg t
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   151
          val v' = CombVar(RC.make_schematic_var v,tp)
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   152
      in  (v',ts)  end
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   153
  | combterm_of dfg thy (P $ Q) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   154
      let val (P',tsP) = combterm_of dfg thy P
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   155
          val (Q',tsQ) = combterm_of dfg thy Q
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
   156
      in  (CombApp(P',Q'), tsP union tsQ)  end
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   157
  | combterm_of _ thy (t as Abs _) = raise RC.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
   158
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   159
fun predicate_of dfg thy ((Const("Not",_) $ P), polarity) = predicate_of dfg thy (P, not polarity)
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   160
  | predicate_of dfg thy (t,polarity) = (combterm_of dfg thy (Envir.eta_contract t), polarity);
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   161
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   162
fun literals_of_term1 dfg thy args (Const("Trueprop",_) $ P) = literals_of_term1 dfg thy args P
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   163
  | literals_of_term1 dfg thy args (Const("op |",_) $ P $ Q) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   164
      literals_of_term1 dfg thy (literals_of_term1 dfg thy args P) Q
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   165
  | literals_of_term1 dfg thy (lits,ts) P =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   166
      let val ((pred,ts'),pol) = predicate_of dfg thy (P,true)
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   167
      in
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   168
          (Literal(pol,pred)::lits, ts union ts')
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   169
      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
   170
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   171
fun literals_of_term_dfg dfg thy P = literals_of_term1 dfg thy ([],[]) P;
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   172
val literals_of_term = literals_of_term_dfg 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
   173
28835
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
   174
(* Problem too trivial for resolution (empty clause) *)
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
   175
exception TOO_TRIVIAL;
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
   176
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   177
(* making axiom and conjecture clauses *)
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   178
fun make_clause dfg thy (clause_id,axiom_name,kind,th) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   179
    let val (lits,ctypes_sorts) = literals_of_term_dfg dfg thy (prop_of th)
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   180
    in
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   181
        if forall isFalse lits
28835
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
   182
        then raise TOO_TRIVIAL
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   183
        else
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   184
            Clause {clause_id = clause_id, axiom_name = axiom_name, th = th, kind = kind,
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   185
                    literals = lits, ctypes_sorts = 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
   186
    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
   187
20016
9a005f7d95e6 Literals aren't sorted any more.
mengj
parents: 19964
diff changeset
   188
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   189
fun add_axiom_clause dfg thy ((th,(name,id)), pairs) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   190
  let val cls = make_clause dfg thy (id, name, RC.Axiom, th)
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   191
  in
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   192
      if isTaut cls then pairs else (name,cls)::pairs
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   193
  end;
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   194
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   195
fun make_axiom_clauses dfg thy = List.foldl (add_axiom_clause dfg thy) [];
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   196
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   197
fun make_conjecture_clauses_aux dfg _ _ [] = []
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   198
  | make_conjecture_clauses_aux dfg thy n (th::ths) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   199
      make_clause dfg thy (n,"conjecture", RC.Conjecture, th) ::
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   200
      make_conjecture_clauses_aux dfg thy (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
   201
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   202
fun make_conjecture_clauses dfg thy = make_conjecture_clauses_aux dfg thy 0;
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   203
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   204
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   205
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   206
(* 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
   207
(* TPTP used by Vampire and E                                         *)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   208
(* 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
   209
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   210
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   211
(*Result of a function type; no need to check that the argument type matches.*)
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   212
fun result_type (RC.Comp ("tc_fun", [_, tp2])) = tp2
27187
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   213
  | result_type _ = error "result_type"
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   214
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   215
fun type_of_combterm (CombConst(c,tp,_)) = tp
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   216
  | type_of_combterm (CombVar(v,tp)) = tp
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   217
  | type_of_combterm (CombApp(t1,t2)) = result_type (type_of_combterm t1);
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   218
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   219
(*gets the head of a combinator application, along with the list of arguments*)
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   220
fun strip_comb u =
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   221
    let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   222
        |   stripc  x =  x
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   223
    in  stripc(u,[])  end;
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   224
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   225
val type_wrapper = "ti";
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   226
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   227
fun head_needs_hBOOL const_needs_hBOOL (CombConst(c,_,_)) = needs_hBOOL const_needs_hBOOL c
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   228
  | head_needs_hBOOL const_needs_hBOOL _ = true;
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   229
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   230
fun wrap_type (s, tp) =
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
   231
  if typ_level=T_FULL then
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   232
      type_wrapper ^ RC.paren_pack [s, RC.string_of_fol_type tp]
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   233
  else s;
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   234
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   235
fun apply ss = "hAPP" ^ RC.paren_pack ss;
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   236
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   237
fun rev_apply (v, []) = v
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   238
  | rev_apply (v, arg::args) = apply [rev_apply (v, args), arg];
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   239
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   240
fun string_apply (v, args) = rev_apply (v, rev args);
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   241
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   242
(*Apply an operator to the argument strings, using either the "apply" operator or
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   243
  direct function application.*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   244
fun string_of_applic cma (CombConst(c,tp,tvars), args) =
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   245
      let val c = if c = "equal" then "c_fequal" else c
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   246
          val nargs = min_arity_of cma c
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   247
          val args1 = List.take(args, nargs)
27187
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   248
            handle Subscript => error ("string_of_applic: " ^ c ^ " has arity " ^
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   249
                                         Int.toString nargs ^ " but is applied to " ^
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   250
                                         space_implode ", " args)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   251
          val args2 = List.drop(args, nargs)
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
   252
          val targs = if typ_level = T_CONST then map RC.string_of_fol_type tvars
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   253
                      else []
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   254
      in
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   255
          string_apply (c ^ RC.paren_pack (args1@targs), args2)
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   256
      end
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   257
  | string_of_applic cma (CombVar(v,tp), args) = string_apply (v, args)
30149
6b7ad52c5770 removed local ref const_min_arity
immler@in.tum.de
parents: 28835
diff changeset
   258
  | string_of_applic _ _ = error "string_of_applic";
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   259
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   260
fun wrap_type_if cnh (head, s, tp) = if head_needs_hBOOL cnh head then wrap_type (s, tp) else s;
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   261
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   262
fun string_of_combterm cma cnh t =
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   263
  let val (head, args) = strip_comb t
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   264
  in  wrap_type_if cnh (head,
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   265
                    string_of_applic cma (head, map (string_of_combterm cma cnh) args),
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   266
                    type_of_combterm t)
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   267
  end;
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   268
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   269
(*Boolean-valued terms are here converted to literals.*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   270
fun boolify cma cnh t = "hBOOL" ^ RC.paren_pack [string_of_combterm cma cnh t];
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   271
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   272
fun string_of_predicate cma cnh t =
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   273
  case t of
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   274
      (CombApp(CombApp(CombConst("equal",_,_), t1), t2)) =>
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   275
          (*DFG only: new TPTP prefers infix equality*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   276
          ("equal" ^ RC.paren_pack [string_of_combterm cma cnh t1, string_of_combterm cma cnh t2])
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   277
    | _ =>
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   278
          case #1 (strip_comb t) of
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   279
              CombConst(c,_,_) => if needs_hBOOL cnh c then boolify cma cnh t else string_of_combterm cma cnh t
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   280
            | _ => boolify cma cnh t;
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   281
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   282
fun string_of_clausename (cls_id,ax_name) =
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   283
    RC.clause_prefix ^ RC.ascii_of ax_name ^ "_" ^ Int.toString cls_id;
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
   284
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   285
fun string_of_type_clsname (cls_id,ax_name,idx) =
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
   286
    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
   287
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   289
(*** tptp format ***)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   290
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   291
fun tptp_of_equality cma cnh pol (t1,t2) =
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   292
  let val eqop = if pol then " = " else " != "
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   293
  in  string_of_combterm cma cnh t1 ^ eqop ^ string_of_combterm cma cnh t2  end;
21513
9e9fff87dc6c Conversion of "equal" to "=" for TSTP format; big tidy-up
paulson
parents: 21509
diff changeset
   294
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   295
fun tptp_literal cma cnh (Literal(pol, CombApp(CombApp(CombConst("equal",_,_), t1), t2))) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   296
      tptp_of_equality cma cnh pol (t1,t2)
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   297
  | tptp_literal cma cnh (Literal(pol,pred)) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   298
      RC.tptp_sign pol (string_of_predicate cma cnh pred);
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   299
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   300
(*Given a clause, returns its literals paired with a list of literals concerning TFrees;
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   301
  the latter should only occur in conjecture clauses.*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   302
fun tptp_type_lits cma cnh pos (Clause{literals, ctypes_sorts, ...}) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   303
      (map (tptp_literal cma cnh) literals, 
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   304
       map (RC.tptp_of_typeLit pos) (RC.add_typs ctypes_sorts));
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   305
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   306
fun clause2tptp (cma, cnh) (cls as Clause{axiom_name,clause_id,kind,ctypes_sorts,...}) =
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   307
  let val (lits,tylits) = tptp_type_lits cma cnh (kind = RC.Conjecture) cls
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   308
  in
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   309
      (RC.gen_tptp_cls(clause_id,axiom_name,kind,lits,tylits), tylits)
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   310
  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
   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
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   313
(*** dfg format ***)
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   314
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   315
fun dfg_literal cma cnh (Literal(pol,pred)) = RC.dfg_sign pol (string_of_predicate cma cnh pred);
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   316
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   317
fun dfg_type_lits cma cnh pos (Clause{literals, ctypes_sorts, ...}) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   318
      (map (dfg_literal cma cnh) literals, 
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   319
       map (RC.dfg_of_typeLit pos) (RC.add_typs ctypes_sorts));
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   320
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   321
fun get_uvars (CombConst _) vars = vars
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   322
  | get_uvars (CombVar(v,_)) vars = (v::vars)
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   323
  | get_uvars (CombApp(P,Q)) vars = get_uvars P (get_uvars Q vars);
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   324
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   325
fun get_uvars_l (Literal(_,c)) = get_uvars c [];
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   326
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   327
fun dfg_vars (Clause {literals,...}) = RC.union_all (map get_uvars_l literals);
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   328
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   329
fun clause2dfg (cma, cnh) (cls as Clause{axiom_name,clause_id,kind,ctypes_sorts,...}) =
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   330
  let val (lits,tylits) = dfg_type_lits cma cnh (kind = RC.Conjecture) cls
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   331
      val vars = dfg_vars cls
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   332
      val tvars = RC.get_tvar_strs ctypes_sorts
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   333
  in
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   334
      (RC.gen_dfg_cls(clause_id, axiom_name, kind, lits, tylits, tvars@vars), tylits)
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   335
  end;
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   336
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   337
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   338
(** For DFG format: accumulate function and predicate declarations **)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   339
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   340
fun addtypes tvars tab = List.foldl RC.add_foltype_funcs tab tvars;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   341
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   342
fun add_decls cma cnh (CombConst(c,tp,tvars), (funcs,preds)) =
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   343
      if c = "equal" then (addtypes tvars funcs, preds)
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   344
      else
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   345
	let val arity = min_arity_of cma c
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
   346
	    val ntys = if typ_level = T_CONST then length tvars else 0
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
   347
	    val addit = Symtab.update(c, arity+ntys)
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
   348
	in
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   349
	    if needs_hBOOL cnh c then (addtypes tvars (addit funcs), preds)
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
   350
	    else (addtypes tvars funcs, addit preds)
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
   351
	end
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   352
  | add_decls _ _ (CombVar(_,ctp), (funcs,preds)) =
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   353
      (RC.add_foltype_funcs (ctp,funcs), preds)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   354
  | add_decls cma cnh (CombApp(P,Q),decls) = add_decls cma cnh (P,add_decls cma cnh (Q,decls));
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   355
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   356
fun add_literal_decls cma cnh (Literal(_,c), decls) = add_decls cma cnh (c,decls);
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   357
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   358
fun add_clause_decls cma cnh (Clause {literals, ...}, decls) =
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   359
    List.foldl (add_literal_decls cma cnh) decls literals
27187
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   360
    handle Symtab.DUP a => error ("function " ^ a ^ " has multiple arities")
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   361
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   362
fun decls_of_clauses (cma, cnh) clauses arity_clauses =
24385
ab62948281a9 Deleted the partially-typed translation and the combinator code.
paulson
parents: 24323
diff changeset
   363
  let val init_functab = Symtab.update (type_wrapper,2) (Symtab.update ("hAPP",2) RC.init_functab)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   364
      val init_predtab = Symtab.update ("hBOOL",1) Symtab.empty
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   365
      val (functab,predtab) = (List.foldl (add_clause_decls cma cnh) (init_functab, init_predtab) clauses)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   366
  in
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   367
      (Symtab.dest (List.foldl RC.add_arityClause_funcs functab arity_clauses),
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   368
       Symtab.dest predtab)
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   369
  end;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   370
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   371
fun add_clause_preds (Clause {ctypes_sorts, ...}, preds) =
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   372
  List.foldl RC.add_type_sort_preds preds ctypes_sorts
27187
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   373
  handle Symtab.DUP a => error ("predicate " ^ a ^ " has multiple arities")
21398
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   374
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   375
(*Higher-order clauses have only the predicates hBOOL and type classes.*)
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   376
fun preds_of_clauses clauses clsrel_clauses arity_clauses =
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   377
    Symtab.dest
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   378
        (List.foldl RC.add_classrelClause_preds
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   379
               (List.foldl RC.add_arityClause_preds
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   380
                      (List.foldl add_clause_preds Symtab.empty clauses)
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   381
                      arity_clauses)
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   382
               clsrel_clauses)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   383
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   384
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   385
(**********************************************************************)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   386
(* write clauses to files                                             *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   387
(**********************************************************************)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   388
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   389
val init_counters =
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   390
    Symtab.make [("c_COMBI", 0), ("c_COMBK", 0),
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   391
                 ("c_COMBB", 0), ("c_COMBC", 0),
24943
5f5679e2ec2f removed dead code
paulson
parents: 24940
diff changeset
   392
                 ("c_COMBS", 0)];
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   393
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   394
fun count_combterm (CombConst(c,tp,_), ct) =
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   395
     (case Symtab.lookup ct c of NONE => ct  (*no counter*)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   396
                               | SOME n => Symtab.update (c,n+1) ct)
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   397
  | count_combterm (CombVar(v,tp), ct) = ct
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   398
  | count_combterm (CombApp(t1,t2), ct) = count_combterm(t1, count_combterm(t2, ct));
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   399
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   400
fun count_literal (Literal(_,t), ct) = count_combterm(t,ct);
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   401
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   402
fun count_clause (Clause{literals,...}, ct) = List.foldl count_literal ct literals;
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   403
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   404
fun count_user_clause user_lemmas (Clause{axiom_name,literals,...}, ct) =
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   405
  if axiom_name mem_string user_lemmas then List.foldl count_literal ct literals
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   406
  else ct;
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   407
27178
c8ddb3000743 ResAxioms.cnf_axiom/cnf_rules_pairs: pass explicit theory context;
wenzelm
parents: 25243
diff changeset
   408
fun cnf_helper_thms thy =
c8ddb3000743 ResAxioms.cnf_axiom/cnf_rules_pairs: pass explicit theory context;
wenzelm
parents: 25243
diff changeset
   409
  ResAxioms.cnf_rules_pairs thy o map ResAxioms.pairname
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   410
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   411
fun get_helper_clauses dfg thy isFO (conjectures, axcls, user_lemmas) =
23386
9255c1a75ba9 Now also handles FO problems
paulson
parents: 22851
diff changeset
   412
  if isFO then []  (*first-order*)
9255c1a75ba9 Now also handles FO problems
paulson
parents: 22851
diff changeset
   413
  else
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   414
    let
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   415
        val axclauses = map #2 (make_axiom_clauses dfg thy axcls)
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   416
        val ct0 = List.foldl count_clause init_counters conjectures
30190
479806475f3c use long names for old-style fold combinators;
wenzelm
parents: 30153
diff changeset
   417
        val ct = List.foldl (count_user_clause user_lemmas) ct0 axclauses
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   418
        fun needed c = valOf (Symtab.lookup ct c) > 0
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   419
        val IK = if needed "c_COMBI" orelse needed "c_COMBK"
27178
c8ddb3000743 ResAxioms.cnf_axiom/cnf_rules_pairs: pass explicit theory context;
wenzelm
parents: 25243
diff changeset
   420
                 then (Output.debug (fn () => "Include combinator I K"); cnf_helper_thms thy [comb_I,comb_K])
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   421
                 else []
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   422
        val BC = if needed "c_COMBB" orelse needed "c_COMBC"
27178
c8ddb3000743 ResAxioms.cnf_axiom/cnf_rules_pairs: pass explicit theory context;
wenzelm
parents: 25243
diff changeset
   423
                 then (Output.debug (fn () => "Include combinator B C"); cnf_helper_thms thy [comb_B,comb_C])
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   424
                 else []
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   425
        val S = if needed "c_COMBS"
27178
c8ddb3000743 ResAxioms.cnf_axiom/cnf_rules_pairs: pass explicit theory context;
wenzelm
parents: 25243
diff changeset
   426
                then (Output.debug (fn () => "Include combinator S"); cnf_helper_thms thy [comb_S])
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   427
                else []
27178
c8ddb3000743 ResAxioms.cnf_axiom/cnf_rules_pairs: pass explicit theory context;
wenzelm
parents: 25243
diff changeset
   428
        val other = cnf_helper_thms thy [ext,fequal_imp_equal,equal_imp_fequal]
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   429
    in
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   430
        map #2 (make_axiom_clauses dfg thy (other @ IK @ BC @ S))
23386
9255c1a75ba9 Now also handles FO problems
paulson
parents: 22851
diff changeset
   431
    end;
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   432
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   433
(*Find the minimal arity of each function mentioned in the term. Also, note which uses
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   434
  are not at top level, to see if hBOOL is needed.*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   435
fun count_constants_term toplev t (const_min_arity, const_needs_hBOOL) =
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   436
  let val (head, args) = strip_comb t
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   437
      val n = length args
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   438
      val (const_min_arity, const_needs_hBOOL) = fold (count_constants_term false) args (const_min_arity, const_needs_hBOOL)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   439
  in
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   440
      case head of
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   441
          CombConst (a,_,_) => (*predicate or function version of "equal"?*)
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   442
            let val a = if a="equal" andalso not toplev then "c_fequal" else a
30149
6b7ad52c5770 removed local ref const_min_arity
immler@in.tum.de
parents: 28835
diff changeset
   443
            val const_min_arity = Symtab.map_default (a,n) (curry Int.min n) const_min_arity
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   444
            in
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   445
              if toplev then (const_min_arity, const_needs_hBOOL)
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   446
              else (const_min_arity, Symtab.update (a,true) (const_needs_hBOOL))
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   447
            end
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   448
        | ts => (const_min_arity, const_needs_hBOOL)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   449
  end;
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   450
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   451
(*A literal is a top-level term*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   452
fun count_constants_lit (Literal (_,t)) (const_min_arity, const_needs_hBOOL) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   453
  count_constants_term true t (const_min_arity, const_needs_hBOOL);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   454
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   455
fun count_constants_clause (Clause{literals,...}) (const_min_arity, const_needs_hBOOL) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   456
  fold count_constants_lit literals (const_min_arity, const_needs_hBOOL);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   457
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   458
fun display_arity const_needs_hBOOL (c,n) =
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   459
  Output.debug (fn () => "Constant: " ^ c ^ " arity:\t" ^ Int.toString n ^
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   460
                (if needs_hBOOL const_needs_hBOOL c then " needs hBOOL" else ""));
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   461
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   462
fun count_constants (conjectures, axclauses, helper_clauses, _, _) =
30153
051d3825a15d turned "read-only refs" typ_level and minimize_applies into constant values;
wenzelm
parents: 30151
diff changeset
   463
  if minimize_applies then
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   464
     let val (const_min_arity, const_needs_hBOOL) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   465
          fold count_constants_clause conjectures (Symtab.empty, Symtab.empty)
30149
6b7ad52c5770 removed local ref const_min_arity
immler@in.tum.de
parents: 28835
diff changeset
   466
       |> fold count_constants_clause axclauses
6b7ad52c5770 removed local ref const_min_arity
immler@in.tum.de
parents: 28835
diff changeset
   467
       |> fold count_constants_clause helper_clauses
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   468
     val _ = List.app (display_arity const_needs_hBOOL) (Symtab.dest (const_min_arity))
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   469
     in (const_min_arity, const_needs_hBOOL) end
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   470
  else (Symtab.empty, Symtab.empty);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   471
31749
8ee34e3ceb5a corrected comments
immler@in.tum.de
parents: 31409
diff changeset
   472
(* tptp format *)
8ee34e3ceb5a corrected comments
immler@in.tum.de
parents: 31409
diff changeset
   473
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   474
fun tptp_write_file filename clauses =
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   475
  let
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   476
    val (conjectures, axclauses, helper_clauses, classrel_clauses, arity_clauses) = clauses
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   477
    val const_counts = count_constants clauses
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   478
    val (tptp_clss,tfree_litss) = ListPair.unzip (map (clause2tptp const_counts) conjectures)
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   479
    val tfree_clss = map RC.tptp_tfree_clause (List.foldl (op union_string) [] tfree_litss)
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   480
    val out = TextIO.openOut filename
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   481
  in
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   482
    List.app (curry TextIO.output out o #1 o (clause2tptp const_counts)) axclauses;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   483
    RC.writeln_strs out tfree_clss;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   484
    RC.writeln_strs out tptp_clss;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   485
    List.app (curry TextIO.output out o RC.tptp_classrelClause) classrel_clauses;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   486
    List.app (curry TextIO.output out o RC.tptp_arity_clause) arity_clauses;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   487
    List.app (curry TextIO.output out o #1 o (clause2tptp const_counts)) helper_clauses;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   488
    TextIO.closeOut out
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   489
  end;
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   490
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   491
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   492
(* dfg format *)
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   493
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   494
fun dfg_write_file filename clauses =
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   495
  let
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   496
    val (conjectures, axclauses, helper_clauses, classrel_clauses, arity_clauses) = clauses
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   497
    val const_counts = count_constants clauses
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   498
    val (dfg_clss, tfree_litss) = ListPair.unzip (map (clause2dfg const_counts) conjectures)
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   499
    and probname = Path.implode (Path.base (Path.explode filename))
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   500
    val axstrs = map (#1 o (clause2dfg const_counts)) axclauses
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   501
    val tfree_clss = map RC.dfg_tfree_clause (RC.union_all tfree_litss)
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   502
    val out = TextIO.openOut filename
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   503
    val helper_clauses_strs = map (#1 o (clause2dfg const_counts)) helper_clauses
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   504
    val (funcs,cl_preds) = decls_of_clauses const_counts (helper_clauses @ conjectures @ axclauses) arity_clauses
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   505
    and ty_preds = preds_of_clauses axclauses classrel_clauses arity_clauses
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   506
  in
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   507
    TextIO.output (out, RC.string_of_start probname);
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   508
    TextIO.output (out, RC.string_of_descrip probname);
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   509
    TextIO.output (out, RC.string_of_symbols
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   510
                          (RC.string_of_funcs funcs)
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   511
                          (RC.string_of_preds (cl_preds @ ty_preds)));
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   512
    TextIO.output (out, "list_of_clauses(axioms,cnf).\n");
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   513
    RC.writeln_strs out axstrs;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   514
    List.app (curry TextIO.output out o RC.dfg_classrelClause) classrel_clauses;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   515
    List.app (curry TextIO.output out o RC.dfg_arity_clause) arity_clauses;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   516
    RC.writeln_strs out helper_clauses_strs;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   517
    TextIO.output (out, "end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n");
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   518
    RC.writeln_strs out tfree_clss;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   519
    RC.writeln_strs out dfg_clss;
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   520
    TextIO.output (out, "end_of_list.\n\n");
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   521
    (*VarWeight=3 helps the HO problems, probably by counteracting the presence of hAPP*)
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   522
    TextIO.output (out, "list_of_settings(SPASS).\n{*\nset_flag(VarWeight,3).\n*}\nend_of_list.\n\n");
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   523
    TextIO.output (out, "end_problem.\n");
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   524
    TextIO.closeOut out
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   525
  end;
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   526
21254
d53f76357f41 incorporated former theories Reconstruction and ResAtpMethods into ATP_Linkup;
wenzelm
parents: 21135
diff changeset
   527
end