src/HOL/Tools/Sledgehammer/sledgehammer_hol_clause.ML
author blanchet
Tue, 22 Jun 2010 23:54:02 +0200
changeset 37509 f39464d971c4
parent 37506 32a1ee39c49b
child 37512 ff72d3ddc898
permissions -rw-r--r--
factor out TPTP format output into file of its own, to facilitate further changes
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
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
     5
FOL clauses translated from HOL formulas.
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
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    10
  type cnf_thm = Sledgehammer_Fact_Preprocessor.cnf_thm
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
    11
  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
    12
  type name_pool = Sledgehammer_FOL_Clause.name_pool
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    13
  type kind = Sledgehammer_FOL_Clause.kind
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 polarity = bool
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    17
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    18
  datatype combtyp =
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    19
    TyVar of name |
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    20
    TyFree of name |
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    21
    TyConstr of name * combtyp list
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    22
  datatype combterm =
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    23
    CombConst of name * combtyp * combtyp list (* Const and Free *) |
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    24
    CombVar of name * combtyp |
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    25
    CombApp of combterm * combterm
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    26
  datatype literal = Literal of polarity * combterm
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    27
  datatype hol_clause =
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    28
    HOLClause of {clause_id: int, axiom_name: string, th: thm, kind: kind,
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    29
                  literals: literal list, ctypes_sorts: typ list}
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    30
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    31
  val type_of_combterm : combterm -> combtyp
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    32
  val strip_combterm_comb : combterm -> combterm * combterm list
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    33
  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
    34
  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
    35
    int -> (string * term) list -> term -> (string * term) list * term
37506
32a1ee39c49b missing "Unsynchronized" + make exception take a unit
blanchet
parents: 37500
diff changeset
    36
  exception TRIVIAL of unit
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
    37
  val make_conjecture_clauses : theory -> thm list -> hol_clause list
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    38
  val make_axiom_clauses : theory -> cnf_thm list -> (string * hol_clause) list
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    39
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
    40
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
    41
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
    42
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
    43
36167
c1a35be8e476 make Sledgehammer's output more debugging friendly
blanchet
parents: 35963
diff changeset
    44
open Sledgehammer_Util
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    45
open Sledgehammer_FOL_Clause
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    46
open Sledgehammer_Fact_Preprocessor
22825
bd774e01d6d5 Fixing bugs in the partial-typed and fully-typed translations
paulson
parents: 22130
diff changeset
    47
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
    48
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* 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
    50
(******************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    52
type polarity = bool
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
    53
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    54
datatype combtyp =
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    55
  TyVar of name |
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    56
  TyFree of name |
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    57
  TyConstr of name * combtyp list
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    58
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    59
datatype combterm =
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    60
  CombConst of name * combtyp * combtyp list (* Const and Free *) |
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    61
  CombVar of name * combtyp |
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    62
  CombApp of combterm * combterm
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    63
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
    64
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
    65
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    66
datatype hol_clause =
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    67
  HOLClause of {clause_id: int, axiom_name: string, th: thm, kind: kind,
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
    68
                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
    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
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* 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
    72
(*********************************************************************)
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    74
(*Result of a function type; no need to check that the argument type matches.*)
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    75
fun result_type (TyConstr (_, [_, tp2])) = tp2
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    76
  | result_type _ = raise Fail "non-function type"
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    77
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    78
fun type_of_combterm (CombConst (_, tp, _)) = tp
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    79
  | type_of_combterm (CombVar (_, tp)) = tp
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    80
  | type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1)
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    81
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    82
(*gets the head of a combinator application, along with the list of arguments*)
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    83
fun strip_combterm_comb u =
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    84
    let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts)
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    85
        |   stripc  x =  x
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    86
    in stripc(u,[]) end
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37506
diff changeset
    87
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
    88
fun isFalse (Literal (pol, CombConst ((c, _), _, _))) =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    89
      (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
    90
  | 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
    91
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
    92
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
    93
      (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
    94
      (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
    95
  | isTrue _ = false;
24311
d6864b34eecd proper signature;
wenzelm
parents: 24215
diff changeset
    96
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    97
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
    98
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
    99
fun type_of (Type (a, Ts)) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   100
    let val (folTypes,ts) = types_of Ts in
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   101
      (TyConstr (`make_fixed_type_const a, folTypes), ts)
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   102
    end
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   103
  | type_of (tp as TFree (a, _)) = (TyFree (`make_fixed_type_var a), [tp])
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   104
  | type_of (tp as TVar (x, _)) =
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   105
    (TyVar (make_schematic_type_var x, string_of_indexname x), [tp])
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   106
and types_of Ts =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   107
    let val (folTyps, ts) = ListPair.unzip (map type_of Ts) in
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   108
      (folTyps, union_all ts)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   109
    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
   110
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. 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
(* same as above, but no gathering of sort information *)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   112
fun simp_type_of (Type (a, Ts)) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   113
      TyConstr (`make_fixed_type_const a, map simp_type_of Ts)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   114
  | simp_type_of (TFree (a, _)) = TyFree (`make_fixed_type_var a)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   115
  | simp_type_of (TVar (x, _)) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   116
    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
   117
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
   118
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   119
fun combterm_of thy (Const (c, T)) =
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   120
      let
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   121
        val (tp, ts) = type_of T
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   122
        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
   123
          (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
   124
             [] |> Term.add_tvarsT T |> map TVar
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   125
           else
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   126
             (c, T) |> Sign.const_typargs thy)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   127
          |> map simp_type_of
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   128
        val c' = CombConst (`make_fixed_const c, tp, tvar_list)
22078
5084f53cef39 Streamlining: removing the type argument of CombApp; abbreviating ResClause as RC
paulson
parents: 22064
diff changeset
   129
      in  (c',ts)  end
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   130
  | combterm_of _ (Free(v, T)) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   131
      let val (tp,ts) = type_of 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
   132
          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
   133
      in  (v',ts)  end
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   134
  | combterm_of _ (Var(v, T)) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   135
      let val (tp,ts) = type_of 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
   136
          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
   137
      in  (v',ts)  end
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   138
  | combterm_of thy (P $ Q) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   139
      let val (P', tsP) = combterm_of thy P
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   140
          val (Q', tsQ) = combterm_of thy Q
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   141
      in  (CombApp (P', Q'), union (op =) tsP tsQ)  end
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   142
  | 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
   143
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   144
fun predicate_of thy ((@{const Not} $ P), polarity) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   145
    predicate_of thy (P, not polarity)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   146
  | predicate_of thy (t, polarity) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   147
    (combterm_of 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
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   149
fun literals_of_term1 args thy (@{const Trueprop} $ P) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   150
    literals_of_term1 args thy P
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   151
  | literals_of_term1 args thy (@{const "op |"} $ P $ Q) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   152
    literals_of_term1 (literals_of_term1 args thy P) thy Q
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   153
  | literals_of_term1 (lits, ts) thy P =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   154
    let val ((pred, ts'), pol) = predicate_of thy (P, true) in
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   155
      (Literal (pol, pred) :: lits, union (op =) ts ts')
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   156
    end
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   157
val literals_of_term = literals_of_term1 ([], [])
17998
0a869029ca58 A new file that defines datatypes representing FOL clauses that are derived from HOL formulae. This file also has functions that convert lambda terms to combinator expressions, and functions that convert clauses to TPTP format.
mengj
parents:
diff changeset
   158
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   159
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
   160
  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
   161
  skolem_infix ^ "g"
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   162
37410
2bf7e6136047 adjusted the polymorphism handling of Skolem constants so that proof reconstruction doesn't fail in "equality_inf"
blanchet
parents: 37399
diff changeset
   163
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
   164
  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
   165
    let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   166
      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
   167
              (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
   168
          let
37496
9ae78e12e126 reintroduce new Sledgehammer polymorphic handling code;
blanchet
parents: 37479
diff changeset
   169
            val t = Envir.beta_eta_contract t
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   170
            val (skolem_somes, s) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   171
              if i = ~1 then
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   172
                (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
   173
              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
   174
                s :: _ => (skolem_somes, s)
37436
2d76997730a6 found missing beta-eta-contraction
blanchet
parents: 37414
diff changeset
   175
              | [] =>
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   176
                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
   177
                  val s = skolem_theory_name ^ "." ^
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   178
                          skolem_name i (length skolem_somes)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   179
                                        (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
   180
                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
   181
          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
   182
        | aux skolem_somes (t1 $ t2) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   183
          let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   184
            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
   185
            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
   186
          in (skolem_somes, t1 $ t2) end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   187
        | 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
   188
          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
   189
            (skolem_somes, Abs (s, T, t'))
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   190
          end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   191
        | 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
   192
    in aux skolem_somes t end
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   193
  else
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   194
    (skolem_somes, t)
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   195
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   196
(* Trivial problem, which resolution cannot handle (empty clause) *)
37506
32a1ee39c49b missing "Unsynchronized" + make exception take a unit
blanchet
parents: 37500
diff changeset
   197
exception TRIVIAL of unit
28835
d4d8eba5f781 changes by Fabian Immler:
wenzelm
parents: 27187
diff changeset
   198
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
   199
(* making axiom and conjecture clauses *)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   200
fun make_clause thy (clause_id, axiom_name, kind, th) skolem_somes =
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   201
  let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   202
    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
   203
      th |> prop_of |> conceal_skolem_somes clause_id skolem_somes
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   204
    val (lits, ctypes_sorts) = literals_of_term thy t
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   205
  in
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   206
    if forall isFalse lits then
37506
32a1ee39c49b missing "Unsynchronized" + make exception take a unit
blanchet
parents: 37500
diff changeset
   207
      raise TRIVIAL ()
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   208
    else
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   209
      (skolem_somes,
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   210
       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
   211
                  kind = kind, literals = lits, ctypes_sorts = ctypes_sorts})
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36186
diff changeset
   212
  end
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   213
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
   214
fun add_axiom_clause thy (th, ((name, id), _ : thm)) (skolem_somes, clss) =
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   215
  let
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   216
    val (skolem_somes, cls) = make_clause thy (id, name, Axiom, th) skolem_somes
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   217
  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
   218
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   219
fun make_axiom_clauses thy clauses =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   220
  ([], []) |> fold (add_axiom_clause thy) clauses |> snd
19354
aebf9dddccd7 tptp_write_file accepts axioms as thm.
mengj
parents: 19198
diff changeset
   221
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   222
fun make_conjecture_clauses thy =
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   223
  let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   224
    fun aux _ _ [] = []
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   225
      | aux n skolem_somes (th :: ths) =
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   226
        let
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   227
          val (skolem_somes, cls) =
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37496
diff changeset
   228
            make_clause thy (n, "conjecture", Conjecture, th) skolem_somes
37399
34f080a12063 proper polymorphic Skolemization of uncached facts + synchronization of caching and relevance filter
blanchet
parents: 36966
diff changeset
   229
        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
   230
  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
   231
33311
49cd8abb2863 proper header;
wenzelm
parents: 33042
diff changeset
   232
end;