src/HOL/Tools/Sledgehammer/sledgehammer_hol_clause.ML
author blanchet
Mon, 14 Jun 2010 10:36:01 +0200
changeset 37410 2bf7e6136047
parent 37399 34f080a12063
child 37414 d0cea0796295
permissions -rw-r--r--
adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36375
2482446a604c move the minimizer to the Sledgehammer directory
blanchet
parents: 36237
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_hol_clause.ML
33311
49cd8abb2863 proper header;
wenzelm
parents: 33042
diff changeset
     2
    Author:     Jia Meng, NICTA
36375
2482446a604c move the minimizer to the Sledgehammer directory
blanchet
parents: 36237
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
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
     4
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
     5
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
     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
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
     8
signature SLEDGEHAMMER_HOL_CLAUSE =
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
     9
sig
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    10
  type name = Sledgehammer_FOL_Clause.name
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
    11
  type name_pool = Sledgehammer_FOL_Clause.name_pool
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    12
  type kind = Sledgehammer_FOL_Clause.kind
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    13
  type fol_type = Sledgehammer_FOL_Clause.fol_type
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    14
  type classrel_clause = Sledgehammer_FOL_Clause.classrel_clause
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    15
  type arity_clause = Sledgehammer_FOL_Clause.arity_clause
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    16
  type axiom_name = string
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    17
  type polarity = bool
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    18
  type hol_clause_id = int
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    19
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    20
  datatype combterm =
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    21
    CombConst of name * fol_type * fol_type list (* Const and Free *) |
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    22
    CombVar of name * fol_type |
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    23
    CombApp of combterm * combterm
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    24
  datatype literal = Literal of polarity * combterm
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    25
  datatype hol_clause =
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    26
    HOLClause of {clause_id: hol_clause_id, axiom_name: axiom_name, th: thm,
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    27
                  kind: kind, literals: literal list, ctypes_sorts: typ list}
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    28
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    29
  val type_of_combterm : combterm -> fol_type
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    30
  val strip_combterm_comb : combterm -> combterm * combterm list
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    31
  val literals_of_term : theory -> term -> literal list * typ list
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
    32
  val conceal_skolem_somes :
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
    33
    int -> (string * term) list -> term -> (string * term) list * term
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    34
  exception TRIVIAL
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    35
  val make_conjecture_clauses : bool -> theory -> thm list -> hol_clause list
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    36
  val make_axiom_clauses : bool -> theory ->
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    37
       (thm * (axiom_name * hol_clause_id)) list -> (axiom_name * hol_clause) list
36909
7d5587f6d5f7 made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents: 36565
diff changeset
    38
  val type_wrapper_name : string
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
    39
  val get_helper_clauses :
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
    40
    bool -> theory -> bool -> hol_clause list
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
    41
      -> (thm * (axiom_name * hol_clause_id)) list -> hol_clause list
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
    42
  val write_tptp_file : bool -> bool -> bool -> Path.T ->
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    43
    hol_clause list * hol_clause list * hol_clause list * hol_clause list *
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
    44
    classrel_clause list * arity_clause list -> name_pool option * int
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
    45
  val write_dfg_file : bool -> bool -> Path.T ->
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    46
    hol_clause list * hol_clause list * hol_clause list * hol_clause list *
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
    47
    classrel_clause list * arity_clause list -> name_pool option * int
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    48
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
    49
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
    50
structure Sledgehammer_HOL_Clause : SLEDGEHAMMER_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
    51
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
    52
36167
c1a35be8e476 make Sledgehammer's output more debugging friendly
blanchet
parents: 35963
diff changeset
    53
open Sledgehammer_Util
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    54
open Sledgehammer_FOL_Clause
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    55
open Sledgehammer_Fact_Preprocessor
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    56
33035
15eab423e573 standardized basic operations on type option;
wenzelm
parents: 33029
diff changeset
    57
fun min_arity_of const_min_arity c = the_default 0 (Symtab.lookup const_min_arity c);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
    58
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    59
(*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
    60
  If false, the constant always receives all of its arguments and is used as a predicate.*)
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
    61
fun needs_hBOOL explicit_apply const_needs_hBOOL c =
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
    62
  explicit_apply orelse
33035
15eab423e573 standardized basic operations on type option;
wenzelm
parents: 33029
diff changeset
    63
    the_default false (Symtab.lookup const_needs_hBOOL c);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
    64
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
    65
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
    66
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    67
(* 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
    68
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    69
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    70
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
    71
type polarity = bool;
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    72
type hol_clause_id = 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
    73
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    74
datatype combterm =
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    75
  CombConst of name * fol_type * fol_type list (* Const and Free *) |
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    76
  CombVar of name * fol_type |
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    77
  CombApp of combterm * combterm
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
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
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
    80
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    81
datatype hol_clause =
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    82
  HOLClause of {clause_id: hol_clause_id, axiom_name: axiom_name, th: thm,
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    83
                kind: kind, literals: literal list, 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
    84
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    87
(* 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
    88
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
    89
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    90
fun isFalse (Literal (pol, CombConst ((c, _), _, _))) =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    91
      (pol andalso c = "c_False") orelse (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
    92
  | 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
    93
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
    94
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
    95
      (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
    96
      (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
    97
  | isTrue _ = false;
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    98
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    99
fun isTaut (HOLClause {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
   100
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   101
fun type_of dfg (Type (a, Ts)) =
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   102
    let val (folTypes,ts) = types_of dfg Ts in
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   103
      (TyConstr (`(make_fixed_type_const dfg) a, folTypes), ts)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   104
    end
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   105
  | type_of _ (tp as TFree (a, _)) = (TyFree (`make_fixed_type_var a), [tp])
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   106
  | type_of _ (tp as TVar (x, _)) =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   107
    (TyVar (make_schematic_type_var x, string_of_indexname x), [tp])
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   108
and types_of dfg Ts =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   109
      let val (folTyps,ts) = ListPair.unzip (map (type_of dfg) Ts)
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   110
      in  (folTyps, 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
   111
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* same as above, but no gathering of sort information *)
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   113
fun simp_type_of dfg (Type (a, Ts)) =
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   114
      TyConstr (`(make_fixed_type_const dfg) a, map (simp_type_of dfg) Ts)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   115
  | simp_type_of _ (TFree (a, _)) = TyFree (`make_fixed_type_var a)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   116
  | simp_type_of _ (TVar (x, _)) =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   117
    TyVar (make_schematic_type_var x, string_of_indexname x);
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   118
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   119
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
   120
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   121
fun combterm_of dfg thy (Const (c, T)) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   122
      let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   123
        val (tp, ts) = type_of dfg T
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   124
        val tvar_list =
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   125
          (if String.isPrefix skolem_theory_name c then
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   126
             [] |> Term.add_tvarsT T |> map TVar
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   127
           else
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   128
             (c, T) |> Sign.const_typargs thy)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   129
          |> map (simp_type_of dfg)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   130
        val c' = CombConst (`(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
   131
      in  (c',ts)  end
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   132
  | combterm_of dfg _ (Free(v, T)) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   133
      let val (tp,ts) = type_of dfg T
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   134
          val v' = CombConst (`make_fixed_var v, tp, [])
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   135
      in  (v',ts)  end
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   136
  | combterm_of dfg _ (Var(v, T)) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   137
      let val (tp,ts) = type_of dfg T
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   138
          val v' = CombVar ((make_schematic_var v, string_of_indexname v), tp)
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   139
      in  (v',ts)  end
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   140
  | combterm_of dfg thy (P $ Q) =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   141
      let val (P',tsP) = combterm_of dfg thy P
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   142
          val (Q',tsQ) = combterm_of dfg thy Q
33042
ddf1f03a9ad9 curried union as canonical list operation
haftmann
parents: 33039
diff changeset
   143
      in  (CombApp(P',Q'), union (op =) tsP tsQ)  end
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   144
  | combterm_of _ _ (t as Abs _) = raise 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
   145
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   146
fun predicate_of dfg thy ((@{const Not} $ P), polarity) = predicate_of dfg thy (P, not polarity)
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   147
  | 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
   148
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   149
fun literals_of_term1 dfg thy args (@{const Trueprop} $ P) = literals_of_term1 dfg thy args P
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   150
  | literals_of_term1 dfg thy args (@{const "op |"} $ P $ Q) =
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   151
      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
   152
  | literals_of_term1 dfg thy (lits,ts) P =
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   153
      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
   154
      in
33042
ddf1f03a9ad9 curried union as canonical list operation
haftmann
parents: 33039
diff changeset
   155
          (Literal(pol,pred)::lits, union (op =) ts ts')
21509
6c5755ad9cae ATP linkup now generates "new TPTP" rather than "old TPTP"
paulson
parents: 21470
diff changeset
   156
      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
   157
30151
629f3a92863e removed global ref dfg_format
immler@in.tum.de
parents: 30150
diff changeset
   158
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
   159
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
   160
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   161
fun skolem_name i j num_T_args =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   162
  skolem_prefix ^ (space_implode "_" (map Int.toString [i, j, num_T_args])) ^
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   163
  skolem_infix ^ "g"
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   164
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   165
fun conceal_skolem_somes i skolem_somes t =
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   166
  if exists_Const (curry (op =) @{const_name skolem_id} o fst) t then
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   167
    let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   168
      fun aux skolem_somes
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   169
              (t as (Const (@{const_name skolem_id}, Type (_, [_, T])) $ _)) =
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   170
          let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   171
            val (skolem_somes, s) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   172
              if i = ~1 then
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   173
                (skolem_somes, @{const_name undefined})
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   174
              else case AList.find (op aconv) skolem_somes t of
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   175
                s :: _ => (skolem_somes, s)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   176
              | _ =>
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   177
                let
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   178
                  val s = skolem_theory_name ^ "." ^
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   179
                          skolem_name i (length skolem_somes)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   180
                                        (length (Term.add_tvarsT T []))
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   181
                in ((s, t) :: skolem_somes, s) end
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   182
          in (skolem_somes, Const (s, T)) end
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   183
        | aux skolem_somes (t1 $ t2) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   184
          let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   185
            val (skolem_somes, t1) = aux skolem_somes t1
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   186
            val (skolem_somes, t2) = aux skolem_somes t2
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   187
          in (skolem_somes, t1 $ t2) end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   188
        | aux skolem_somes (Abs (s, T, t')) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   189
          let val (skolem_somes, t') = aux skolem_somes t' in
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   190
            (skolem_somes, Abs (s, T, t'))
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   191
          end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   192
        | aux skolem_somes t = (skolem_somes, t)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   193
    in aux skolem_somes t end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   194
  else
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   195
    (skolem_somes, t)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   196
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   197
(* Trivial problem, which resolution cannot handle (empty clause) *)
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   198
exception TRIVIAL;
28835
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
   199
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
   200
(* making axiom and conjecture clauses *)
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   201
fun make_clause dfg thy (clause_id, axiom_name, kind, th) skolem_somes =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   202
  let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   203
    val (skolem_somes, t) =
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   204
      th |> prop_of |> conceal_skolem_somes clause_id skolem_somes
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   205
    val (lits, ctypes_sorts) = literals_of_term_dfg dfg thy t
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   206
  in
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   207
    if forall isFalse lits then
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   208
      raise TRIVIAL
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   209
    else
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   210
      (skolem_somes,
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   211
       HOLClause {clause_id = clause_id, axiom_name = axiom_name, th = th,
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   212
                  kind = kind, literals = lits, ctypes_sorts = ctypes_sorts})
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   213
  end
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   214
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   215
fun add_axiom_clause dfg thy (th, (name, id)) (skolem_somes, clss) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   216
  let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   217
    val (skolem_somes, cls) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   218
      make_clause dfg thy (id, name, Axiom, th) skolem_somes
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   219
  in (skolem_somes, clss |> not (isTaut cls) ? cons (name, cls)) end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   220
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   221
fun make_axiom_clauses dfg thy clauses =
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   222
  ([], []) |> fold (add_axiom_clause dfg thy) clauses |> snd
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   223
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   224
fun make_conjecture_clauses dfg thy =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   225
  let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   226
    fun aux _ _ [] = []
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   227
      | aux n skolem_somes (th :: ths) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   228
        let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   229
          val (skolem_somes, cls) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   230
            make_clause dfg thy (n, "conjecture", Conjecture, th) skolem_somes
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   231
        in cls :: aux (n + 1) skolem_somes ths end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   232
  in aux 0 [] 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
   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
(* 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
   236
(* TPTP used by Vampire and E                                         *)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   237
(* 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
   238
(**********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   239
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   240
(*Result of a function type; no need to check that the argument type matches.*)
36909
7d5587f6d5f7 made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents: 36565
diff changeset
   241
fun result_type (TyConstr (_, [_, tp2])) = tp2
7d5587f6d5f7 made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents: 36565
diff changeset
   242
  | result_type _ = raise Fail "non-function type"
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   243
32994
ccc07fbbfefd removed some unreferenced material;
wenzelm
parents: 32960
diff changeset
   244
fun type_of_combterm (CombConst (_, tp, _)) = tp
ccc07fbbfefd removed some unreferenced material;
wenzelm
parents: 32960
diff changeset
   245
  | type_of_combterm (CombVar (_, tp)) = tp
ccc07fbbfefd removed some unreferenced material;
wenzelm
parents: 32960
diff changeset
   246
  | type_of_combterm (CombApp (t1, _)) = 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
   247
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   248
(*gets the head of a combinator application, along with the list of arguments*)
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   249
fun strip_combterm_comb u =
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   250
    let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   251
        |   stripc  x =  x
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   252
    in  stripc(u,[])  end;
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   253
36909
7d5587f6d5f7 made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents: 36565
diff changeset
   254
val type_wrapper_name = "ti"
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   255
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   256
fun head_needs_hBOOL explicit_apply const_needs_hBOOL
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   257
                     (CombConst ((c, _), _, _)) =
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   258
    needs_hBOOL explicit_apply const_needs_hBOOL c
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   259
  | head_needs_hBOOL _ _ _ = true
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   260
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   261
fun wrap_type full_types (s, ty) pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   262
  if full_types then
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   263
    let val (s', pool) = string_of_fol_type ty pool in
36909
7d5587f6d5f7 made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents: 36565
diff changeset
   264
      (type_wrapper_name ^ paren_pack [s, s'], pool)
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   265
    end
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   266
  else
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   267
    (s, pool)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   268
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   269
fun wrap_type_if full_types explicit_apply cnh (head, s, tp) =
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   270
  if head_needs_hBOOL explicit_apply cnh head then
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   271
    wrap_type full_types (s, tp)
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   272
  else
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   273
    pair s
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   274
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   275
fun apply ss = "hAPP" ^ paren_pack ss;
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   276
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   277
fun rev_apply (v, []) = v
22851
7b7d6e1c70b6 First-order variant of the fully-typed translation
paulson
parents: 22825
diff changeset
   278
  | rev_apply (v, arg::args) = apply [rev_apply (v, args), arg];
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   279
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   280
fun string_apply (v, args) = rev_apply (v, rev args);
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   281
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   282
(* Apply an operator to the argument strings, using either the "apply" operator
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   283
   or direct function application. *)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   284
fun string_of_application full_types cma (CombConst ((s, s'), _, tvars), args)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   285
                          pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   286
    let
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   287
      val s = if s = "equal" then "c_fequal" else s
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   288
      val nargs = min_arity_of cma s
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   289
      val args1 = List.take (args, nargs)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   290
        handle Subscript =>
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   291
               raise Fail (quote s ^ " has arity " ^ Int.toString nargs ^
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   292
                           " but is applied to " ^ commas (map quote args))
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   293
      val args2 = List.drop (args, nargs)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   294
      val (targs, pool) = if full_types then ([], pool)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   295
                          else pool_map string_of_fol_type tvars pool
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   296
      val (s, pool) = nice_name (s, s') pool
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   297
    in (string_apply (s ^ paren_pack (args1 @ targs), args2), pool) end
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   298
  | string_of_application _ _ (CombVar (name, _), args) pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   299
    nice_name name pool |>> (fn s => string_apply (s, args))
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   300
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   301
fun string_of_combterm (params as (full_types, explicit_apply, cma, cnh)) t
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   302
                       pool =
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   303
  let
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   304
    val (head, args) = strip_combterm_comb t
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   305
    val (ss, pool) = pool_map (string_of_combterm params) args pool
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   306
    val (s, pool) = string_of_application full_types cma (head, ss) pool
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   307
  in
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   308
    wrap_type_if full_types explicit_apply cnh (head, s, type_of_combterm t)
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   309
                 pool
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   310
  end
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   311
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   312
(*Boolean-valued terms are here converted to literals.*)
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   313
fun boolify params c =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   314
  string_of_combterm params c #>> prefix "hBOOL" o paren_pack o single
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   315
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   316
fun string_of_predicate (params as (_, explicit_apply, _, cnh)) t =
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   317
  case t of
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   318
    (CombApp (CombApp (CombConst (("equal", _), _, _), t1), t2)) =>
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   319
    (* DFG only: new TPTP prefers infix equality *)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   320
    pool_map (string_of_combterm params) [t1, t2]
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   321
    #>> prefix "equal" o paren_pack
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   322
  | _ =>
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   323
    case #1 (strip_combterm_comb t) of
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   324
      CombConst ((s, _), _, _) =>
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   325
      (if needs_hBOOL explicit_apply cnh s then boolify else string_of_combterm)
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   326
          params t
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   327
    | _ => boolify params t
18356
443717b3a9ad Added new type embedding methods for translating HOL clauses.
mengj
parents: 18276
diff changeset
   328
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
   329
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   330
(*** TPTP format ***)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   331
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   332
fun tptp_of_equality params pos (t1, t2) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   333
  pool_map (string_of_combterm params) [t1, t2]
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   334
  #>> space_implode (if pos then " = " else " != ")
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   335
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   336
fun tptp_literal params
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   337
        (Literal (pos, CombApp (CombApp (CombConst (("equal", _), _, _), t1),
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   338
                                         t2))) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   339
    tptp_of_equality params pos (t1, t2)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   340
  | tptp_literal params (Literal (pos, pred)) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   341
    string_of_predicate params pred #>> tptp_sign pos
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   342
 
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   343
(* Given a clause, returns its literals paired with a list of literals
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   344
   concerning TFrees; the latter should only occur in conjecture clauses. *)
36556
81dc2c20f052 use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents: 36481
diff changeset
   345
fun tptp_type_literals params pos (HOLClause {literals, ctypes_sorts, ...})
81dc2c20f052 use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents: 36481
diff changeset
   346
                       pool =
81dc2c20f052 use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents: 36481
diff changeset
   347
  let
81dc2c20f052 use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents: 36481
diff changeset
   348
    val (lits, pool) = pool_map (tptp_literal params) literals pool
81dc2c20f052 use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents: 36481
diff changeset
   349
    val (tylits, pool) = pool_map (tptp_of_type_literal pos)
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   350
                                  (type_literals_for_types ctypes_sorts) pool
36556
81dc2c20f052 use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents: 36481
diff changeset
   351
  in ((lits, tylits), pool) end
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   352
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   353
fun tptp_clause params (cls as HOLClause {axiom_name, clause_id, kind, ...})
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   354
                pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   355
let
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   356
    val ((lits, tylits), pool) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   357
      tptp_type_literals params (kind = Conjecture) cls pool
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   358
  in
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   359
    ((gen_tptp_cls (clause_id, axiom_name, kind, lits, tylits), tylits), pool)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   360
  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
   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
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   363
(*** DFG format ***)
21561
cfd2258f0b23 Tidied code. Bool constructor is not needed.
paulson
parents: 21513
diff changeset
   364
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   365
fun dfg_literal params (Literal (pos, pred)) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   366
  string_of_predicate params pred #>> dfg_sign pos
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   367
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   368
fun dfg_type_literals params pos (HOLClause {literals, ctypes_sorts, ...}) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   369
  pool_map (dfg_literal params) literals
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   370
  #>> rpair (map (dfg_of_type_literal pos)
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   371
                 (type_literals_for_types ctypes_sorts))
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   372
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   373
fun get_uvars (CombConst _) vars pool = (vars, pool)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   374
  | get_uvars (CombVar (name, _)) vars pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   375
    nice_name name pool |>> (fn var => var :: vars)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   376
  | get_uvars (CombApp (P, Q)) vars pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   377
    let val (vars, pool) = get_uvars P vars pool in get_uvars Q vars pool end
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   378
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   379
fun get_uvars_l (Literal (_, c)) = get_uvars c [];
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   380
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   381
fun dfg_vars (HOLClause {literals, ...}) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   382
  pool_map get_uvars_l literals #>> union_all
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   383
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   384
fun dfg_clause params (cls as HOLClause {axiom_name, clause_id, kind,
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   385
                                         ctypes_sorts, ...}) pool =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   386
  let
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   387
    val ((lits, tylits), pool) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   388
      dfg_type_literals params (kind = Conjecture) cls pool
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   389
    val (vars, pool) = dfg_vars cls pool
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   390
    val tvars = get_tvar_strs ctypes_sorts
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   391
  in
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   392
    ((gen_dfg_cls (clause_id, axiom_name, kind, lits, tylits, tvars @ vars),
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   393
      tylits), pool)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   394
  end
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24385
diff changeset
   395
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   396
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   397
(** For DFG format: accumulate function and predicate declarations **)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   398
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   399
fun add_types tvars = fold add_fol_type_funcs tvars
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   400
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   401
fun add_decls (full_types, explicit_apply, cma, cnh)
36565
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   402
              (CombConst ((c, _), ctp, tvars)) (funcs, preds) =
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   403
      (if c = "equal" then
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   404
         (add_types tvars funcs, preds)
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   405
       else
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   406
         let val arity = min_arity_of cma c
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   407
             val ntys = if not full_types then length tvars else 0
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   408
             val addit = Symtab.update(c, arity + ntys)
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   409
         in
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   410
             if needs_hBOOL explicit_apply cnh c then
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   411
               (add_types tvars (addit funcs), preds)
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   412
             else
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   413
               (add_types tvars funcs, addit preds)
061475351a09 fix more "undeclared symbol" errors related to SPASS's DFG format
blanchet
parents: 36556
diff changeset
   414
         end) |>> full_types ? add_fol_type_funcs ctp
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   415
  | add_decls _ (CombVar (_, ctp)) (funcs, preds) =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   416
      (add_fol_type_funcs ctp funcs, preds)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   417
  | add_decls params (CombApp (P, Q)) decls =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   418
      decls |> add_decls params P |> add_decls params Q
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   419
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   420
fun add_literal_decls params (Literal (_, c)) = add_decls params c
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   421
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   422
fun add_clause_decls params (HOLClause {literals, ...}) decls =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   423
    fold (add_literal_decls params) literals decls
27187
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   424
    handle Symtab.DUP a => error ("function " ^ a ^ " has multiple arities")
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   425
31800
477f2abf90a4 Streamlined code
nipkow
parents: 31791
diff changeset
   426
fun decls_of_clauses params clauses arity_clauses =
36237
86e62a98deea fix bug in SPASS's DFG output files, where "tc_bool" wasn't declared;
blanchet
parents: 36235
diff changeset
   427
  let val functab =
36909
7d5587f6d5f7 made Sledgehammer's full-typed proof reconstruction work for the first time;
blanchet
parents: 36565
diff changeset
   428
        init_functab |> fold Symtab.update [(type_wrapper_name, 2), ("hAPP", 2),
36237
86e62a98deea fix bug in SPASS's DFG output files, where "tc_bool" wasn't declared;
blanchet
parents: 36235
diff changeset
   429
                                            ("tc_bool", 0)]
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   430
      val predtab = Symtab.empty |> Symtab.update ("hBOOL", 1)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   431
      val (functab, predtab) =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   432
        (functab, predtab) |> fold (add_clause_decls params) clauses
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   433
                           |>> fold add_arity_clause_funcs arity_clauses
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   434
  in (Symtab.dest functab, Symtab.dest predtab) end
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   435
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   436
fun add_clause_preds (HOLClause {ctypes_sorts, ...}) preds =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   437
  fold add_type_sort_preds ctypes_sorts preds
27187
17b63e145986 use regular error function;
wenzelm
parents: 27178
diff changeset
   438
  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
   439
11996e938dfe Includes type:sort constraints in its code to collect predicates in axiom clauses.
paulson
parents: 21254
diff changeset
   440
(*Higher-order clauses have only the predicates hBOOL and type classes.*)
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   441
fun preds_of_clauses clauses clsrel_clauses arity_clauses =
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   442
  Symtab.empty
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   443
  |> fold add_clause_preds clauses
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   444
  |> fold add_arity_clause_preds arity_clauses
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   445
  |> fold add_classrel_clause_preds clsrel_clauses
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   446
  |> Symtab.dest
18440
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   447
72ee07f4b56b Literals in clauses are sorted now. Added functions for clause equivalence tests and hashing clauses to words.
mengj
parents: 18356
diff changeset
   448
(**********************************************************************)
19198
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   449
(* write clauses to files                                             *)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   450
(**********************************************************************)
e6f1ff40ba99 Added tptp_write_file to write all necessary ATP input clauses to one file.
mengj
parents: 19130
diff changeset
   451
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   452
val init_counters =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   453
  Symtab.make [("c_COMBI", 0), ("c_COMBK", 0), ("c_COMBB", 0), ("c_COMBC", 0),
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   454
               ("c_COMBS", 0)];
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   455
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   456
fun count_combterm (CombConst ((c, _), _, _)) =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   457
    Symtab.map_entry c (Integer.add 1)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   458
  | count_combterm (CombVar _) = I
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   459
  | count_combterm (CombApp (t1, t2)) = count_combterm t1 #> count_combterm t2
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   460
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   461
fun count_literal (Literal (_, t)) = count_combterm t
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   462
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   463
fun count_clause (HOLClause {literals, ...}) = fold count_literal literals
21573
8a7a68c0096c Removed the references for counting combinators. Instead they are counted in actual clauses.
paulson
parents: 21561
diff changeset
   464
36228
df47dc6c0e03 got rid of somewhat pointless "pairname" function in Sledgehammer
blanchet
parents: 36222
diff changeset
   465
fun cnf_helper_thms thy = cnf_rules_pairs thy o map (`Thm.get_name_hint)
20644
ff938c7b15e8 Introduced combinators B', C' and S'.
mengj
parents: 20421
diff changeset
   466
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   467
fun get_helper_clauses dfg thy isFO conjectures axcls =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   468
  if isFO then
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   469
    []
23386
9255c1a75ba9 Now also handles FO problems
paulson
parents: 22851
diff changeset
   470
  else
31752
19a5f1c8a844 use results of relevance-filter to determine additional clauses;
immler@in.tum.de
parents: 31749
diff changeset
   471
    let
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   472
        val axclauses = map snd (make_axiom_clauses dfg thy axcls)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   473
        val ct = init_counters
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   474
                 |> fold (fold count_clause) [conjectures, axclauses]
33035
15eab423e573 standardized basic operations on type option;
wenzelm
parents: 33029
diff changeset
   475
        fun needed c = the (Symtab.lookup ct c) > 0
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   476
        val IK = if needed "c_COMBI" orelse needed "c_COMBK"
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   477
                 then cnf_helper_thms thy [@{thm COMBI_def}, @{thm COMBK_def}]
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   478
                 else []
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   479
        val BC = if needed "c_COMBB" orelse needed "c_COMBC"
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   480
                 then cnf_helper_thms thy [@{thm COMBB_def}, @{thm COMBC_def}]
21135
07549f79d19c Numerous cosmetic changes.
paulson
parents: 21108
diff changeset
   481
                 else []
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   482
        val S = if needed "c_COMBS" then cnf_helper_thms thy [@{thm COMBS_def}]
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   483
                else []
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   484
        val other = cnf_helper_thms thy [@{thm fequal_imp_equal},
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   485
                                         @{thm equal_imp_fequal}]
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   486
    in map snd (make_axiom_clauses dfg thy (other @ IK @ BC @ S)) end
20791
497e1c9d4a9f Combinator axioms are now from Isabelle theorems, no need to use helper files.
mengj
parents: 20660
diff changeset
   487
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   488
(*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
   489
  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
   490
fun count_constants_term toplev t (const_min_arity, const_needs_hBOOL) =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   491
  let val (head, args) = strip_combterm_comb t
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   492
      val n = length args
36233
1263bef003b3 cosmetics
blanchet
parents: 36231
diff changeset
   493
      val (const_min_arity, const_needs_hBOOL) =
1263bef003b3 cosmetics
blanchet
parents: 36231
diff changeset
   494
        (const_min_arity, const_needs_hBOOL)
1263bef003b3 cosmetics
blanchet
parents: 36231
diff changeset
   495
        |> fold (count_constants_term false) args
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   496
  in
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   497
      case head of
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   498
          CombConst ((a, _),_,_) => (*predicate or function version of "equal"?*)
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   499
            let val a = if a="equal" andalso not toplev then "c_fequal" else a
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   500
            in
36233
1263bef003b3 cosmetics
blanchet
parents: 36231
diff changeset
   501
              (const_min_arity |> Symtab.map_default (a, n) (Integer.min n),
1263bef003b3 cosmetics
blanchet
parents: 36231
diff changeset
   502
               const_needs_hBOOL |> not toplev ? Symtab.update (a, true))
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
   503
            end
32994
ccc07fbbfefd removed some unreferenced material;
wenzelm
parents: 32960
diff changeset
   504
        | _ => (const_min_arity, const_needs_hBOOL)
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   505
  end;
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   506
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   507
(*A literal is a top-level term*)
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   508
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
   509
  count_constants_term true t (const_min_arity, const_needs_hBOOL);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   510
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   511
fun count_constants_clause (HOLClause {literals, ...})
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   512
                           (const_min_arity, const_needs_hBOOL) =
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   513
  fold count_constants_lit literals (const_min_arity, const_needs_hBOOL);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   514
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   515
fun display_arity explicit_apply const_needs_hBOOL (c,n) =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   516
  trace_msg (fn () => "Constant: " ^ c ^
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
   517
                " arity:\t" ^ Int.toString n ^
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   518
                (if needs_hBOOL explicit_apply const_needs_hBOOL c then
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   519
                   " needs hBOOL"
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   520
                 else
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   521
                   ""))
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   522
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   523
fun count_constants explicit_apply
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   524
                    (conjectures, _, extra_clauses, helper_clauses, _, _) =
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   525
  if not explicit_apply then
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   526
     let val (const_min_arity, const_needs_hBOOL) =
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   527
          fold count_constants_clause conjectures (Symtab.empty, Symtab.empty)
31865
5e97c4abd18e fixed: count constants with supplementary lemmas
immler@in.tum.de
parents: 31839
diff changeset
   528
       |> fold count_constants_clause extra_clauses
30149
6b7ad52c5770 removed local ref const_min_arity
immler@in.tum.de
parents: 28835
diff changeset
   529
       |> fold count_constants_clause helper_clauses
36481
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36402
diff changeset
   530
     val _ = app (display_arity explicit_apply const_needs_hBOOL)
af99c98121d6 make Sledgehammer more friendly if no subgoal is left
blanchet
parents: 36402
diff changeset
   531
                 (Symtab.dest (const_min_arity))
30150
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   532
     in (const_min_arity, const_needs_hBOOL) end
4d5a98cebb24 removed local ref const_needs_hBOOL;
immler@in.tum.de
parents: 30149
diff changeset
   533
  else (Symtab.empty, Symtab.empty);
22064
3d716cc9bd7a optimized translation of HO problems
paulson
parents: 21858
diff changeset
   534
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   535
fun header () =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   536
  "% This file was generated by Isabelle (most likely Sledgehammer)\n" ^
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   537
  "% " ^ timestamp () ^ "\n"
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   538
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   539
(* TPTP format *)
31749
8ee34e3ceb5a corrected comments
immler@in.tum.de
parents: 31409
diff changeset
   540
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   541
fun write_tptp_file readable_names full_types explicit_apply file clauses =
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   542
  let
36167
c1a35be8e476 make Sledgehammer's output more debugging friendly
blanchet
parents: 35963
diff changeset
   543
    fun section _ [] = []
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   544
      | section name ss =
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   545
        "\n% " ^ name ^ plural_s (length ss) ^ " (" ^ Int.toString (length ss) ^
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   546
        ")\n" :: ss
36222
0e3e49bd658d don't use readable names if proof reconstruction is needed, because it uses the structure of names
blanchet
parents: 36219
diff changeset
   547
    val pool = empty_name_pool readable_names
31865
5e97c4abd18e fixed: count constants with supplementary lemmas
immler@in.tum.de
parents: 31839
diff changeset
   548
    val (conjectures, axclauses, _, helper_clauses,
5e97c4abd18e fixed: count constants with supplementary lemmas
immler@in.tum.de
parents: 31839
diff changeset
   549
      classrel_clauses, arity_clauses) = clauses
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   550
    val (cma, cnh) = count_constants explicit_apply clauses
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   551
    val params = (full_types, explicit_apply, cma, cnh)
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   552
    val ((conjecture_clss, tfree_litss), pool) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   553
      pool_map (tptp_clause params) conjectures pool |>> ListPair.unzip
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   554
    val tfree_clss = map tptp_tfree_clause (fold (union (op =)) tfree_litss [])
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   555
    val (ax_clss, pool) = pool_map (apfst fst oo tptp_clause params) axclauses
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   556
                                   pool
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   557
    val classrel_clss = map tptp_classrel_clause classrel_clauses
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   558
    val arity_clss = map tptp_arity_clause arity_clauses
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   559
    val (helper_clss, pool) = pool_map (apfst fst oo tptp_clause params)
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   560
                                       helper_clauses pool
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   561
    val conjecture_offset =
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   562
      length ax_clss + length classrel_clss + length arity_clss
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   563
      + length helper_clss
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   564
    val _ =
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   565
      File.write_list file
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   566
          (header () ::
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   567
           section "Relevant fact" ax_clss @
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   568
           section "Class relationship" classrel_clss @
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   569
           section "Arity declaration" arity_clss @
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   570
           section "Helper fact" helper_clss @
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   571
           section "Conjecture" conjecture_clss @
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   572
           section "Type variable" tfree_clss)
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   573
  in (pool, conjecture_offset) end
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   574
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   575
(* DFG format *)
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   576
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   577
fun dfg_tfree_predicate s = (first_field "(" s |> the |> fst, 1)
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   578
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   579
fun write_dfg_file full_types explicit_apply file clauses =
31409
d8537ba165b5 split preparing clauses and writing problemfile;
immler@in.tum.de
parents: 30242
diff changeset
   580
  let
36219
16670b4f0baa set SPASS option on the command-line, so that it doesn't vanish when moving to TPTP format
blanchet
parents: 36218
diff changeset
   581
    (* Some of the helper functions below are not name-pool-aware. However,
16670b4f0baa set SPASS option on the command-line, so that it doesn't vanish when moving to TPTP format
blanchet
parents: 36218
diff changeset
   582
       there's no point in adding name pool support if the DFG format is on its
16670b4f0baa set SPASS option on the command-line, so that it doesn't vanish when moving to TPTP format
blanchet
parents: 36218
diff changeset
   583
       way out anyway. *)
16670b4f0baa set SPASS option on the command-line, so that it doesn't vanish when moving to TPTP format
blanchet
parents: 36218
diff changeset
   584
    val pool = NONE
31865
5e97c4abd18e fixed: count constants with supplementary lemmas
immler@in.tum.de
parents: 31839
diff changeset
   585
    val (conjectures, axclauses, _, helper_clauses,
5e97c4abd18e fixed: count constants with supplementary lemmas
immler@in.tum.de
parents: 31839
diff changeset
   586
      classrel_clauses, arity_clauses) = clauses
36235
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   587
    val (cma, cnh) = count_constants explicit_apply clauses
61159615a0c5 added "explicit_apply" option to Sledgehammer, to control whether an explicit apply function should be used as much or as little as possible (replaces a previous global variable)
blanchet
parents: 36233
diff changeset
   588
    val params = (full_types, explicit_apply, cma, cnh)
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   589
    val ((conjecture_clss, tfree_litss), pool) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   590
      pool_map (dfg_clause params) conjectures pool |>> ListPair.unzip
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   591
    val tfree_lits = union_all tfree_litss
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   592
    val problem_name = Path.implode (Path.base file)
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   593
    val (axstrs, pool) = pool_map (apfst fst oo dfg_clause params) axclauses pool
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   594
    val tfree_clss = map dfg_tfree_clause tfree_lits
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   595
    val tfree_preds = map dfg_tfree_predicate tfree_lits
36170
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   596
    val (helper_clauses_strs, pool) =
0cdb76723c88 added original constant names to Sledgehammer internal terms + output short names if "debug" is set (for increased readability)
blanchet
parents: 36169
diff changeset
   597
      pool_map (apfst fst oo dfg_clause params) helper_clauses pool
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   598
    val (funcs, cl_preds) = decls_of_clauses params (helper_clauses @ conjectures @ axclauses) arity_clauses
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   599
    val ty_preds = preds_of_clauses axclauses classrel_clauses arity_clauses
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   600
    val preds = tfree_preds @ cl_preds @ ty_preds
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   601
    val conjecture_offset =
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   602
      length axclauses + length classrel_clauses + length arity_clauses
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   603
      + length helper_clauses
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   604
    val _ =
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   605
      File.write_list file
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   606
          (header () ::
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   607
           string_of_start problem_name ::
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   608
           string_of_descrip problem_name ::
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   609
           string_of_symbols (string_of_funcs funcs)
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36922
diff changeset
   610
                             (string_of_preds preds) ::
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   611
           "list_of_clauses(axioms, cnf).\n" ::
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   612
           axstrs @
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   613
           map dfg_classrel_clause classrel_clauses @
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   614
           map dfg_arity_clause arity_clauses @
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   615
           helper_clauses_strs @
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   616
           ["end_of_list.\n\nlist_of_clauses(conjectures, cnf).\n"] @
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   617
           conjecture_clss @
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   618
           tfree_clss @
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   619
           ["end_of_list.\n\n",
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36375
diff changeset
   620
            "end_problem.\n"])
36402
1b20805974c7 introduced direct proof reconstruction code, eliminating the need for the "neg_clausify" method;
blanchet
parents: 36393
diff changeset
   621
  in (pool, conjecture_offset) end
19720
f68f6f958a1d HOL problems now have DFG output format.
mengj
parents: 19491
diff changeset
   622
33311
49cd8abb2863 proper header;
wenzelm
parents: 33042
diff changeset
   623
end;