src/HOL/Tools/Sledgehammer/metis_clauses.ML
author blanchet
Mon, 28 Jun 2010 18:02:36 +0200
changeset 37618 fa57a87f92a0
parent 37616 c8d2d84d6011
child 37620 537beae999d7
permissions -rw-r--r--
get rid of Skolem cache by performing CNF-conversion after fact selection
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37578
9367cb36b1c4 renamed "Sledgehammer_FOL_Clauses" to "Metis_Clauses", so that Metis doesn't depend on Sledgehammer
blanchet
parents: 37577
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/metis_clauses.ML
33311
49cd8abb2863 proper header;
wenzelm
parents: 33043
diff changeset
     2
    Author:     Jia Meng, Cambridge University Computer Laboratory
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36378
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     4
33311
49cd8abb2863 proper header;
wenzelm
parents: 33043
diff changeset
     5
Storing/printing FOL clauses and arity clauses.  Typed equality is
49cd8abb2863 proper header;
wenzelm
parents: 33043
diff changeset
     6
treated differently.
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     7
*)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     8
37578
9367cb36b1c4 renamed "Sledgehammer_FOL_Clauses" to "Metis_Clauses", so that Metis doesn't depend on Sledgehammer
blanchet
parents: 37577
diff changeset
     9
signature METIS_CLAUSES =
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    10
sig
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    11
  type cnf_thm = Clausifier.cnf_thm
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    12
  type name = string * string
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    13
  type name_pool = string Symtab.table * string Symtab.table
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    14
  datatype kind = Axiom | Conjecture
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    15
  datatype type_literal =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    16
    TyLitVar of string * name |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    17
    TyLitFree of string * name
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    18
  datatype arLit =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    19
      TConsLit of class * string * string list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    20
    | TVarLit of class * string
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    21
  datatype arity_clause = ArityClause of
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    22
   {axiom_name: string, conclLit: arLit, premLits: arLit list}
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    23
  datatype classrel_clause = ClassrelClause of
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    24
   {axiom_name: string, subclass: class, superclass: class}
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    25
  datatype combtyp =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    26
    TyVar of name |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    27
    TyFree of name |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    28
    TyConstr of name * combtyp list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    29
  datatype combterm =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    30
    CombConst of name * combtyp * combtyp list (* Const and Free *) |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    31
    CombVar of name * combtyp |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    32
    CombApp of combterm * combterm
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    33
  datatype literal = Literal of bool * combterm
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    34
  datatype hol_clause =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    35
    HOLClause of {clause_id: int, axiom_name: string, th: thm, kind: kind,
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    36
                  literals: literal list, ctypes_sorts: typ list}
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    37
  exception TRIVIAL of unit
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    38
37616
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37578
diff changeset
    39
  val trace : bool Unsynchronized.ref
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
    40
  val type_wrapper_name : string
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    41
  val schematic_var_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    42
  val fixed_var_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    43
  val tvar_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    44
  val tfree_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    45
  val const_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    46
  val tconst_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    47
  val class_prefix: string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    48
  val union_all: ''a list list -> ''a list
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
    49
  val invert_const: string -> string
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    50
  val ascii_of: string -> string
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    51
  val undo_ascii_of: string -> string
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
    52
  val strip_prefix: string -> string -> string option
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    53
  val make_schematic_var : string * int -> string
18868
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
    54
  val make_fixed_var : string -> string
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
    55
  val make_schematic_type_var : string * int -> string
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    56
  val make_fixed_type_var : string -> string
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
    57
  val make_fixed_const : string -> string
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
    58
  val make_fixed_type_const : string -> string
18868
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
    59
  val make_type_class : string -> string
37618
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
    60
  val skolem_theory_name: string
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
    61
  val skolem_prefix: string
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
    62
  val skolem_infix: string
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
    63
  val is_skolem_const_name: string -> bool
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
    64
  val num_type_args: theory -> string -> int
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
    65
  val empty_name_pool : bool -> name_pool option
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
    66
  val pool_map : ('a -> 'b -> 'c * 'b) -> 'a list -> 'b -> 'c list * 'b
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
    67
  val nice_name : name -> name_pool option -> string * name_pool option
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36692
diff changeset
    68
  val type_literals_for_types : typ list -> type_literal list
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    69
  val make_classrel_clauses: theory -> class list -> class list -> classrel_clause list
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
    70
  val make_arity_clauses: theory -> string list -> class list -> class list * arity_clause list
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    71
  val type_of_combterm : combterm -> combtyp
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    72
  val strip_combterm_comb : combterm -> combterm * combterm list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    73
  val literals_of_term : theory -> term -> literal list * typ list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    74
  val conceal_skolem_somes :
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    75
    int -> (string * term) list -> term -> (string * term) list * term
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    76
  val is_quasi_fol_theorem : theory -> thm -> bool
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    77
  val tfree_classes_of_terms : term list -> string list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    78
  val tvar_classes_of_terms : term list -> string list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    79
  val type_consts_of_terms : theory -> term list -> string list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    80
  val prepare_clauses :
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    81
    bool -> thm list -> cnf_thm list -> cnf_thm list -> theory
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    82
    -> string vector
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    83
       * (hol_clause list * hol_clause list * hol_clause list * hol_clause list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    84
          * classrel_clause list * arity_clause list)
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    85
end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    86
37578
9367cb36b1c4 renamed "Sledgehammer_FOL_Clauses" to "Metis_Clauses", so that Metis doesn't depend on Sledgehammer
blanchet
parents: 37577
diff changeset
    87
structure Metis_Clauses : METIS_CLAUSES =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    88
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    89
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    90
open Clausifier
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    91
37616
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37578
diff changeset
    92
val trace = Unsynchronized.ref false
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37578
diff changeset
    93
fun trace_msg msg = if !trace then tracing (msg ()) else ()
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37578
diff changeset
    94
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
    95
val type_wrapper_name = "ti"
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
    96
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    97
val schematic_var_prefix = "V_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    98
val fixed_var_prefix = "v_";
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    99
17230
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
   100
val tvar_prefix = "T_";
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
   101
val tfree_prefix = "t_";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   102
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
   103
val classrel_clause_prefix = "clsrel_";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   104
17230
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
   105
val const_prefix = "c_";
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   106
val tconst_prefix = "tc_";
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   107
val class_prefix = "class_";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   108
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   109
fun union_all xss = fold (union (op =)) xss []
17775
2679ba74411f minor code tidyig
paulson
parents: 17764
diff changeset
   110
36493
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   111
(* Readable names for the more common symbolic functions. Do not mess with the
37479
f6b1ee5b420b try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents: 37414
diff changeset
   112
   last nine entries of the table unless you know what you are doing. *)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   113
val const_trans_table =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   114
  Symtab.make [(@{const_name "op ="}, "equal"),
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   115
               (@{const_name "op &"}, "and"),
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   116
               (@{const_name "op |"}, "or"),
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   117
               (@{const_name "op -->"}, "implies"),
36493
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   118
               (@{const_name "op :"}, "in"),
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   119
               (@{const_name fequal}, "fequal"),
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   120
               (@{const_name COMBI}, "COMBI"),
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   121
               (@{const_name COMBK}, "COMBK"),
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   122
               (@{const_name COMBB}, "COMBB"),
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   123
               (@{const_name COMBC}, "COMBC"),
37479
f6b1ee5b420b try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents: 37414
diff changeset
   124
               (@{const_name COMBS}, "COMBS"),
f6b1ee5b420b try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents: 37414
diff changeset
   125
               (@{const_name True}, "True"),
f6b1ee5b420b try to improve Sledgehammer/Metis's behavior in full_types mode, e.g. by handing True, False, and If better
blanchet
parents: 37414
diff changeset
   126
               (@{const_name False}, "False"),
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   127
               (@{const_name If}, "If"),
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   128
               (@{type_name "*"}, "prod"),
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   129
               (@{type_name "+"}, "sum")]
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   130
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   131
(* Invert the table of translations between Isabelle and ATPs. *)
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   132
val const_trans_table_inv =
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   133
  Symtab.update ("fequal", @{const_name "op ="})
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   134
                (Symtab.make (map swap (Symtab.dest const_trans_table)))
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   135
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   136
val invert_const = perhaps (Symtab.lookup const_trans_table_inv)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   137
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   138
(*Escaping of special characters.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   139
  Alphanumeric characters are left unchanged.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   140
  The character _ goes to __
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   141
  Characters in the range ASCII space to / go to _A to _P, respectively.
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   142
  Other printing characters go to _nnn where nnn is the decimal ASCII code.*)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   143
val A_minus_space = Char.ord #"A" - Char.ord #" ";
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   144
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   145
fun stringN_of_int 0 _ = ""
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   146
  | stringN_of_int k n = stringN_of_int (k-1) (n div 10) ^ Int.toString (n mod 10);
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   147
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   148
fun ascii_of_c c =
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   149
  if Char.isAlphaNum c then String.str c
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   150
  else if c = #"_" then "__"
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   151
  else if #" " <= c andalso c <= #"/"
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   152
       then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space))
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   153
  else if Char.isPrint c
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   154
       then ("_" ^ stringN_of_int 3 (Char.ord c))  (*fixed width, in case more digits follow*)
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   155
  else ""
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   156
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   157
val ascii_of = String.translate ascii_of_c;
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   158
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   159
(** Remove ASCII armouring from names in proof files **)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   160
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   161
(*We don't raise error exceptions because this code can run inside the watcher.
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   162
  Also, the errors are "impossible" (hah!)*)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   163
fun undo_ascii_aux rcs [] = String.implode(rev rcs)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   164
  | undo_ascii_aux rcs [#"_"] = undo_ascii_aux (#"_"::rcs) []  (*ERROR*)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   165
      (*Three types of _ escapes: __, _A to _P, _nnn*)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   166
  | undo_ascii_aux rcs (#"_" :: #"_" :: cs) = undo_ascii_aux (#"_"::rcs) cs
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   167
  | undo_ascii_aux rcs (#"_" :: c :: cs) =
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   168
      if #"A" <= c andalso c<= #"P"  (*translation of #" " to #"/"*)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   169
      then undo_ascii_aux (Char.chr(Char.ord c - A_minus_space) :: rcs) cs
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   170
      else
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   171
        let val digits = List.take (c::cs, 3) handle Subscript => []
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   172
        in
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   173
            case Int.fromString (String.implode digits) of
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   174
                NONE => undo_ascii_aux (c:: #"_"::rcs) cs  (*ERROR*)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   175
              | SOME n => undo_ascii_aux (Char.chr n :: rcs) (List.drop (cs, 2))
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   176
        end
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   177
  | undo_ascii_aux rcs (c::cs) = undo_ascii_aux (c::rcs) cs;
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   178
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   179
val undo_ascii_of = undo_ascii_aux [] o String.explode;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   180
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   181
(* If string s has the prefix s1, return the result of deleting it,
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   182
   un-ASCII'd. *)
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   183
fun strip_prefix s1 s =
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   184
  if String.isPrefix s1 s then
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   185
    SOME (undo_ascii_of (String.extract (s, size s1, NONE)))
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   186
  else
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   187
    NONE
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   188
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   189
(*Remove the initial ' character from a type variable, if it is present*)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   190
fun trim_type_var s =
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   191
  if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE)
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   192
  else error ("trim_type: Malformed type variable encountered: " ^ s);
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   193
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   194
fun ascii_of_indexname (v,0) = ascii_of v
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17422
diff changeset
   195
  | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   196
17230
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
   197
fun make_schematic_var v = schematic_var_prefix ^ (ascii_of_indexname v);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   198
fun make_fixed_var x = fixed_var_prefix ^ (ascii_of x);
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   199
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   200
fun make_schematic_type_var (x,i) =
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   201
      tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i));
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   202
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x));
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   203
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   204
fun lookup_const c =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   205
  case Symtab.lookup const_trans_table c of
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   206
    SOME c' => c'
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   207
  | NONE => ascii_of c
23075
69e30a7e8880 Some hacks for SPASS format
paulson
parents: 23029
diff changeset
   208
36062
194cb6e3c13f get rid of Polyhash, since it's no longer used
blanchet
parents: 35865
diff changeset
   209
(* "op =" MUST BE "equal" because it's built into ATPs. *)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   210
fun make_fixed_const @{const_name "op ="} = "equal"
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   211
  | make_fixed_const c = const_prefix ^ lookup_const c
18411
2d3165a0fb40 No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents: 18409
diff changeset
   212
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   213
fun make_fixed_type_const c = tconst_prefix ^ lookup_const c
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 16976
diff changeset
   214
17261
193b84a70ca4 curried_lookup/update;
wenzelm
parents: 17234
diff changeset
   215
fun make_type_class clas = class_prefix ^ ascii_of clas;
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 16976
diff changeset
   216
37618
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   217
val skolem_theory_name = "Sledgehammer" ^ Long_Name.separator ^ "Sko"
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   218
val skolem_prefix = "sko_"
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   219
val skolem_infix = "$"
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   220
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   221
(*Keep the full complexity of the original name*)
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   222
fun flatten_name s = space_implode "_X" (Long_Name.explode s);
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   223
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   224
(* Hack: Could return false positives (e.g., a user happens to declare a
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   225
   constant called "SomeTheory.sko_means_shoe_in_$wedish". *)
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   226
val is_skolem_const_name =
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   227
  Long_Name.base_name
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   228
  #> String.isPrefix skolem_prefix andf String.isSubstring skolem_infix
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   229
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   230
(* The number of type arguments of a constant, zero if it's monomorphic. For
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   231
   (instances of) Skolem pseudoconstants, this information is encoded in the
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   232
   constant name. *)
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   233
fun num_type_args thy s =
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   234
  if String.isPrefix skolem_theory_name s then
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   235
    s |> unprefix skolem_theory_name
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   236
      |> space_explode skolem_infix |> hd
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   237
      |> space_explode "_" |> List.last |> Int.fromString |> the
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   238
  else
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   239
    (s, Sign.the_const_type thy s) |> Sign.const_typargs thy |> length
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 16976
diff changeset
   240
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   241
(**** name pool ****)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   242
 
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   243
type name = string * string
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   244
type name_pool = string Symtab.table * string Symtab.table
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   245
36222
0e3e49bd658d don't use readable names if proof reconstruction is needed, because it uses the structure of names
blanchet
parents: 36221
diff changeset
   246
fun empty_name_pool readable_names =
0e3e49bd658d don't use readable names if proof reconstruction is needed, because it uses the structure of names
blanchet
parents: 36221
diff changeset
   247
  if readable_names then SOME (`I Symtab.empty) else NONE
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   248
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: 36493
diff changeset
   249
fun pool_fold f xs z = pair z #> fold_rev (fn x => uncurry (f x)) xs
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   250
fun pool_map f xs =
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: 36493
diff changeset
   251
  pool_fold (fn x => fn ys => fn pool => f x pool |>> (fn y => y :: ys)) xs []
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   252
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   253
fun add_nice_name full_name nice_prefix j the_pool =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   254
  let
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   255
    val nice_name = nice_prefix ^ (if j = 0 then "" else "_" ^ Int.toString j)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   256
  in
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   257
    case Symtab.lookup (snd the_pool) nice_name of
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   258
      SOME full_name' =>
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   259
      if full_name = full_name' then (nice_name, the_pool)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   260
      else add_nice_name full_name nice_prefix (j + 1) the_pool
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   261
    | NONE =>
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   262
      (nice_name, (Symtab.update_new (full_name, nice_name) (fst the_pool),
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   263
                   Symtab.update_new (nice_name, full_name) (snd the_pool)))
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   264
  end
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   265
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   266
fun translate_first_char f s =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   267
  String.str (f (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   268
36222
0e3e49bd658d don't use readable names if proof reconstruction is needed, because it uses the structure of names
blanchet
parents: 36221
diff changeset
   269
fun readable_name full_name s =
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   270
  let
37575
cfc5e281740f exploit "Name.desymbolize" to remove some dependencies
blanchet
parents: 37572
diff changeset
   271
    val s = s |> Long_Name.base_name |> Name.desymbolize false
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   272
    val s' = s |> explode |> rev |> dropwhile (curry (op =) "'")
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   273
    val s' =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   274
      (s' |> rev
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   275
          |> implode
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   276
          |> String.translate
36221
3abbae8a10cd allow "_" in TPTP names in debug mode
blanchet
parents: 36218
diff changeset
   277
                 (fn c => if Char.isAlphaNum c orelse c = #"_" then String.str c
3abbae8a10cd allow "_" in TPTP names in debug mode
blanchet
parents: 36218
diff changeset
   278
                          else ""))
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   279
      ^ replicate_string (String.size s - length s') "_"
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   280
    val s' =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   281
      if s' = "" orelse not (Char.isAlpha (String.sub (s', 0))) then "X" ^ s'
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   282
      else s'
36476
a04cf4704668 in Sledgehammer "debug" mode, the names of most variables are already short and sweet, so most of the entries of the "const_trans_table" don't have a raison d'etre anymore
blanchet
parents: 36393
diff changeset
   283
    (* Avoid "equal", since it's built into ATPs; and "op" is very ambiguous
a04cf4704668 in Sledgehammer "debug" mode, the names of most variables are already short and sweet, so most of the entries of the "const_trans_table" don't have a raison d'etre anymore
blanchet
parents: 36393
diff changeset
   284
       ("op &", "op |", etc.). *)
a04cf4704668 in Sledgehammer "debug" mode, the names of most variables are already short and sweet, so most of the entries of the "const_trans_table" don't have a raison d'etre anymore
blanchet
parents: 36393
diff changeset
   285
    val s' = if s' = "equal" orelse s' = "op" then full_name else s'
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   286
  in
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   287
    case (Char.isLower (String.sub (full_name, 0)),
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   288
          Char.isLower (String.sub (s', 0))) of
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   289
      (true, false) => translate_first_char Char.toLower s'
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   290
    | (false, true) => translate_first_char Char.toUpper s'
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   291
    | _ => s'
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   292
  end
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   293
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   294
fun nice_name (full_name, _) NONE = (full_name, NONE)
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   295
  | nice_name (full_name, desired_name) (SOME the_pool) =
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   296
    case Symtab.lookup (fst the_pool) full_name of
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   297
      SOME nice_name => (nice_name, SOME the_pool)
36222
0e3e49bd658d don't use readable names if proof reconstruction is needed, because it uses the structure of names
blanchet
parents: 36221
diff changeset
   298
    | NONE => add_nice_name full_name (readable_name full_name desired_name) 0
0e3e49bd658d don't use readable names if proof reconstruction is needed, because it uses the structure of names
blanchet
parents: 36221
diff changeset
   299
                            the_pool
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   300
              |> apsnd SOME
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   301
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   302
(**** Definitions and functions for FOL clauses for TPTP format output ****)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   303
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   304
datatype kind = Axiom | Conjecture
23385
0ef4f9fc0d09 Deleted unused code
paulson
parents: 23075
diff changeset
   305
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   306
(**** Isabelle FOL clauses ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   307
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: 36493
diff changeset
   308
(* The first component is the type class; the second is a TVar or TFree. *)
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: 36493
diff changeset
   309
datatype type_literal =
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: 36493
diff changeset
   310
  TyLitVar of string * name |
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: 36493
diff changeset
   311
  TyLitFree of string * name
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   312
17404
d16c3a62c396 the experimental tagging system, and the usual tidying
paulson
parents: 17375
diff changeset
   313
exception CLAUSE of string * term;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   314
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   315
(*Make literals for sorted type variables*)
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   316
fun sorts_on_typs_aux (_, [])   = []
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   317
  | sorts_on_typs_aux ((x,i),  s::ss) =
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   318
      let val sorts = sorts_on_typs_aux ((x,i), ss)
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   319
      in
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   320
          if s = "HOL.type" then sorts
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: 36493
diff changeset
   321
          else if i = ~1 then TyLitFree (make_type_class s, `make_fixed_type_var x) :: 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: 36493
diff changeset
   322
          else TyLitVar (make_type_class s, (make_schematic_type_var (x,i), x)) :: sorts
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   323
      end;
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 16976
diff changeset
   324
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   325
fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s)
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   326
  | sorts_on_typs (TVar (v,s))  = sorts_on_typs_aux (v,s);
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   327
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24322
diff changeset
   328
(*Given a list of sorted type variables, return a list of type literals.*)
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36692
diff changeset
   329
fun type_literals_for_types Ts =
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36692
diff changeset
   330
  fold (union (op =)) (map sorts_on_typs Ts) []
20015
1ffcf4802802 Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents: 19719
diff changeset
   331
1ffcf4802802 Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents: 19719
diff changeset
   332
(** make axiom and conjecture clauses. **)
1ffcf4802802 Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents: 19719
diff changeset
   333
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   334
(**** Isabelle arities ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   335
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   336
datatype arLit = TConsLit of class * string * string list
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   337
               | TVarLit of class * string;
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   338
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   339
datatype arity_clause =
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
   340
  ArityClause of {axiom_name: string, conclLit: arLit, premLits: arLit list}
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   341
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   342
18798
ca02a2077955 tidying up SPASS output
paulson
parents: 18676
diff changeset
   343
fun gen_TVars 0 = []
ca02a2077955 tidying up SPASS output
paulson
parents: 18676
diff changeset
   344
  | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   345
18411
2d3165a0fb40 No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents: 18409
diff changeset
   346
fun pack_sort(_,[])  = []
2d3165a0fb40 No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents: 18409
diff changeset
   347
  | pack_sort(tvar, "HOL.type"::srt) = pack_sort(tvar, srt)   (*IGNORE sort "type"*)
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   348
  | pack_sort(tvar, cls::srt) =  (cls, tvar) :: pack_sort(tvar, srt);
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   349
18411
2d3165a0fb40 No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents: 18409
diff changeset
   350
(*Arity of type constructor tcon :: (arg1,...,argN)res*)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   351
fun make_axiom_arity_clause (tcons, axiom_name, (cls,args)) =
21560
d92389321fa7 tidied code
paulson
parents: 21509
diff changeset
   352
   let val tvars = gen_TVars (length args)
17845
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   353
       val tvars_srts = ListPair.zip (tvars,args)
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   354
   in
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   355
     ArityClause {axiom_name = axiom_name, 
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   356
                  conclLit = TConsLit (cls, make_fixed_type_const tcons, tvars),
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   357
                  premLits = map TVarLit (union_all(map pack_sort tvars_srts))}
17845
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   358
   end;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   359
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   360
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   361
(**** Isabelle class relations ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   362
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   363
datatype classrel_clause =
37500
7587b6e63454 thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents: 37498
diff changeset
   364
  ClassrelClause of {axiom_name: string, subclass: class, superclass: class}
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   365
21290
33b6bb5d6ab8 Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents: 21254
diff changeset
   366
(*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   367
fun class_pairs _ [] _ = []
21432
625797c592b2 Optimized class_pairs for the common case of no subclasses
paulson
parents: 21416
diff changeset
   368
  | class_pairs thy subs supers =
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   369
      let
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   370
        val class_less = Sorts.class_less (Sign.classes_of thy)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   371
        fun add_super sub super = class_less (sub, super) ? cons (sub, super)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   372
        fun add_supers sub = fold (add_super sub) supers
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   373
      in fold add_supers subs [] end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   374
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   375
fun make_classrel_clause (sub,super) =
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
   376
  ClassrelClause {axiom_name = classrel_clause_prefix ^ ascii_of sub ^ "_" ^
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
   377
                               ascii_of super,
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   378
                  subclass = make_type_class sub,
21290
33b6bb5d6ab8 Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents: 21254
diff changeset
   379
                  superclass = make_type_class super};
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   380
21290
33b6bb5d6ab8 Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents: 21254
diff changeset
   381
fun make_classrel_clauses thy subs supers =
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   382
  map make_classrel_clause (class_pairs thy subs supers);
18868
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
   383
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
   384
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
   385
(** Isabelle arities **)
17845
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   386
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   387
fun arity_clause _ _ (_, []) = []
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   388
  | arity_clause seen n (tcons, ("HOL.type",_)::ars) =  (*ignore*)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   389
      arity_clause seen n (tcons,ars)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   390
  | arity_clause seen n (tcons, (ar as (class,_)) :: ars) =
36692
54b64d4ad524 farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents: 36556
diff changeset
   391
      if member (op =) seen class then (*multiple arities for the same tycon, class pair*)
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   392
          make_axiom_arity_clause (tcons, lookup_const tcons ^ "_" ^ class ^ "_" ^ Int.toString n, ar) ::
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   393
          arity_clause seen (n+1) (tcons,ars)
21373
18f519614978 Arity clauses are now produced only for types and type classes actually used.
paulson
parents: 21290
diff changeset
   394
      else
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   395
          make_axiom_arity_clause (tcons, lookup_const tcons ^ "_" ^ class, ar) ::
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   396
          arity_clause (class::seen) n (tcons,ars)
17845
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   397
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   398
fun multi_arity_clause [] = []
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   399
  | multi_arity_clause ((tcons, ars) :: tc_arlists) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   400
      arity_clause [] 1 (tcons, ars) @ multi_arity_clause tc_arlists
17845
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   401
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   402
(*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   403
  provided its arguments have the corresponding sorts.*)
21373
18f519614978 Arity clauses are now produced only for types and type classes actually used.
paulson
parents: 21290
diff changeset
   404
fun type_class_pairs thy tycons classes =
18f519614978 Arity clauses are now produced only for types and type classes actually used.
paulson
parents: 21290
diff changeset
   405
  let val alg = Sign.classes_of thy
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   406
      fun domain_sorts tycon = Sorts.mg_domain alg tycon o single
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   407
      fun add_class tycon class =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   408
        cons (class, domain_sorts tycon class)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   409
        handle Sorts.CLASS_ERROR _ => I
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   410
      fun try_classes tycon = (tycon, fold (add_class tycon) classes [])
21373
18f519614978 Arity clauses are now produced only for types and type classes actually used.
paulson
parents: 21290
diff changeset
   411
  in  map try_classes tycons  end;
18f519614978 Arity clauses are now produced only for types and type classes actually used.
paulson
parents: 21290
diff changeset
   412
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   413
(*Proving one (tycon, class) membership may require proving others, so iterate.*)
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   414
fun iter_type_class_pairs _ _ [] = ([], [])
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   415
  | iter_type_class_pairs thy tycons classes =
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   416
      let val cpairs = type_class_pairs thy tycons classes
33040
cffdb7b28498 removed old-style \ and \\ infixes
haftmann
parents: 33038
diff changeset
   417
          val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs)))
cffdb7b28498 removed old-style \ and \\ infixes
haftmann
parents: 33038
diff changeset
   418
            |> subtract (op =) classes |> subtract (op =) HOLogic.typeS
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   419
          val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses
33042
ddf1f03a9ad9 curried union as canonical list operation
haftmann
parents: 33038
diff changeset
   420
      in (union (op =) classes' classes, union (op =) cpairs' cpairs) end;
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   421
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   422
fun make_arity_clauses thy tycons classes =
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   423
  let val (classes', cpairs) = iter_type_class_pairs thy tycons classes
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   424
  in  (classes', multi_arity_clause cpairs)  end;
18863
a113b6839df1 reorganization of code to support DFG otuput
paulson
parents: 18856
diff changeset
   425
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   426
datatype combtyp =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   427
  TyVar of name |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   428
  TyFree of name |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   429
  TyConstr of name * combtyp list
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   430
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   431
datatype combterm =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   432
  CombConst of name * combtyp * combtyp list (* Const and Free *) |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   433
  CombVar of name * combtyp |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   434
  CombApp of combterm * combterm
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   435
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   436
datatype literal = Literal of bool * combterm
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   437
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   438
datatype hol_clause =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   439
  HOLClause of {clause_id: int, axiom_name: string, th: thm, kind: kind,
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   440
                literals: literal list, ctypes_sorts: typ list}
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   441
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   442
(*********************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   443
(* convert a clause with type Term.term to a clause with type clause *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   444
(*********************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   445
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   446
(*Result of a function type; no need to check that the argument type matches.*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   447
fun result_type (TyConstr (_, [_, tp2])) = tp2
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   448
  | result_type _ = raise Fail "non-function type"
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   449
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   450
fun type_of_combterm (CombConst (_, tp, _)) = tp
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   451
  | type_of_combterm (CombVar (_, tp)) = tp
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   452
  | type_of_combterm (CombApp (t1, _)) = result_type (type_of_combterm t1)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   453
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   454
(*gets the head of a combinator application, along with the list of arguments*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   455
fun strip_combterm_comb u =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   456
    let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   457
        |   stripc  x =  x
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   458
    in stripc(u,[]) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   459
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   460
fun isFalse (Literal (pol, CombConst ((c, _), _, _))) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   461
      (pol andalso c = "c_False") orelse (not pol andalso c = "c_True")
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   462
  | isFalse _ = false;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   463
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   464
fun isTrue (Literal (pol, CombConst ((c, _), _, _))) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   465
      (pol andalso c = "c_True") orelse
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   466
      (not pol andalso c = "c_False")
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   467
  | isTrue _ = false;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   468
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   469
fun isTaut (HOLClause {literals,...}) = exists isTrue literals;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   470
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   471
fun type_of (Type (a, Ts)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   472
    let val (folTypes,ts) = types_of Ts in
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   473
      (TyConstr (`make_fixed_type_const a, folTypes), ts)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   474
    end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   475
  | type_of (tp as TFree (a, _)) = (TyFree (`make_fixed_type_var a), [tp])
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   476
  | type_of (tp as TVar (x, _)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   477
    (TyVar (make_schematic_type_var x, string_of_indexname x), [tp])
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   478
and types_of Ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   479
    let val (folTyps, ts) = ListPair.unzip (map type_of Ts) in
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   480
      (folTyps, union_all ts)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   481
    end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   482
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   483
(* same as above, but no gathering of sort information *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   484
fun simp_type_of (Type (a, Ts)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   485
      TyConstr (`make_fixed_type_const a, map simp_type_of Ts)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   486
  | simp_type_of (TFree (a, _)) = TyFree (`make_fixed_type_var a)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   487
  | simp_type_of (TVar (x, _)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   488
    TyVar (make_schematic_type_var x, string_of_indexname x)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   489
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   490
(* convert a Term.term (with combinators) into a combterm, also accummulate sort info *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   491
fun combterm_of thy (Const (c, T)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   492
      let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   493
        val (tp, ts) = type_of T
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   494
        val tvar_list =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   495
          (if String.isPrefix skolem_theory_name c then
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   496
             [] |> Term.add_tvarsT T |> map TVar
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   497
           else
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   498
             (c, T) |> Sign.const_typargs thy)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   499
          |> map simp_type_of
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   500
        val c' = CombConst (`make_fixed_const c, tp, tvar_list)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   501
      in  (c',ts)  end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   502
  | combterm_of _ (Free(v, T)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   503
      let val (tp,ts) = type_of T
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   504
          val v' = CombConst (`make_fixed_var v, tp, [])
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   505
      in  (v',ts)  end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   506
  | combterm_of _ (Var(v, T)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   507
      let val (tp,ts) = type_of T
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   508
          val v' = CombVar ((make_schematic_var v, string_of_indexname v), tp)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   509
      in  (v',ts)  end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   510
  | combterm_of thy (P $ Q) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   511
      let val (P', tsP) = combterm_of thy P
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   512
          val (Q', tsQ) = combterm_of thy Q
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   513
      in  (CombApp (P', Q'), union (op =) tsP tsQ)  end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   514
  | combterm_of _ (t as Abs _) = raise Fail "HOL clause: Abs"
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   515
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   516
fun predicate_of thy ((@{const Not} $ P), pos) = predicate_of thy (P, not pos)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   517
  | predicate_of thy (t, pos) = (combterm_of thy (Envir.eta_contract t), pos)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   518
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   519
fun literals_of_term1 args thy (@{const Trueprop} $ P) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   520
    literals_of_term1 args thy P
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   521
  | literals_of_term1 args thy (@{const "op |"} $ P $ Q) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   522
    literals_of_term1 (literals_of_term1 args thy P) thy Q
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   523
  | literals_of_term1 (lits, ts) thy P =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   524
    let val ((pred, ts'), pol) = predicate_of thy (P, true) in
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   525
      (Literal (pol, pred) :: lits, union (op =) ts ts')
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   526
    end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   527
val literals_of_term = literals_of_term1 ([], [])
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   528
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   529
fun skolem_name i j num_T_args =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   530
  skolem_prefix ^ (space_implode "_" (map Int.toString [i, j, num_T_args])) ^
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   531
  skolem_infix ^ "g"
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   532
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   533
fun conceal_skolem_somes i skolem_somes t =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   534
  if exists_Const (curry (op =) @{const_name skolem_id} o fst) t then
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   535
    let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   536
      fun aux skolem_somes
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   537
              (t as (Const (@{const_name skolem_id}, Type (_, [_, T])) $ _)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   538
          let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   539
            val (skolem_somes, s) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   540
              if i = ~1 then
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   541
                (skolem_somes, @{const_name undefined})
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   542
              else case AList.find (op aconv) skolem_somes t of
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   543
                s :: _ => (skolem_somes, s)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   544
              | [] =>
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   545
                let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   546
                  val s = skolem_theory_name ^ "." ^
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   547
                          skolem_name i (length skolem_somes)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   548
                                        (length (Term.add_tvarsT T []))
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   549
                in ((s, t) :: skolem_somes, s) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   550
          in (skolem_somes, Const (s, T)) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   551
        | aux skolem_somes (t1 $ t2) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   552
          let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   553
            val (skolem_somes, t1) = aux skolem_somes t1
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   554
            val (skolem_somes, t2) = aux skolem_somes t2
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   555
          in (skolem_somes, t1 $ t2) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   556
        | aux skolem_somes (Abs (s, T, t')) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   557
          let val (skolem_somes, t') = aux skolem_somes t' in
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   558
            (skolem_somes, Abs (s, T, t'))
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   559
          end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   560
        | aux skolem_somes t = (skolem_somes, t)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   561
    in aux skolem_somes t end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   562
  else
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   563
    (skolem_somes, t)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   564
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   565
fun is_quasi_fol_theorem thy =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   566
  Meson.is_fol_term thy o snd o conceal_skolem_somes ~1 [] o prop_of
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   567
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   568
(* Trivial problem, which resolution cannot handle (empty clause) *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   569
exception TRIVIAL of unit
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   570
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   571
(* making axiom and conjecture clauses *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   572
fun make_clause thy (clause_id, axiom_name, kind, th) skolem_somes =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   573
  let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   574
    val (skolem_somes, t) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   575
      th |> prop_of |> conceal_skolem_somes clause_id skolem_somes
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   576
    val (lits, ctypes_sorts) = literals_of_term thy t
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   577
  in
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   578
    if forall isFalse lits then
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   579
      raise TRIVIAL ()
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   580
    else
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   581
      (skolem_somes,
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   582
       HOLClause {clause_id = clause_id, axiom_name = axiom_name, th = th,
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   583
                  kind = kind, literals = lits, ctypes_sorts = ctypes_sorts})
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   584
  end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   585
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   586
fun add_axiom_clause thy (th, ((name, id), _ : thm)) (skolem_somes, clss) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   587
  let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   588
    val (skolem_somes, cls) = make_clause thy (id, name, Axiom, th) skolem_somes
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   589
  in (skolem_somes, clss |> not (isTaut cls) ? cons (name, cls)) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   590
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   591
fun make_axiom_clauses thy clauses =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   592
  ([], []) |> fold_rev (add_axiom_clause thy) clauses |> snd
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   593
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   594
fun make_conjecture_clauses thy =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   595
  let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   596
    fun aux _ _ [] = []
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   597
      | aux n skolem_somes (th :: ths) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   598
        let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   599
          val (skolem_somes, cls) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   600
            make_clause thy (n, "conjecture", Conjecture, th) skolem_somes
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   601
        in cls :: aux (n + 1) skolem_somes ths end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   602
  in aux 0 [] end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   603
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   604
(** Helper clauses **)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   605
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   606
fun count_combterm (CombConst ((c, _), _, _)) =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   607
    Symtab.map_entry c (Integer.add 1)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   608
  | count_combterm (CombVar _) = I
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   609
  | count_combterm (CombApp (t1, t2)) = count_combterm t1 #> count_combterm t2
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   610
fun count_literal (Literal (_, t)) = count_combterm t
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   611
fun count_clause (HOLClause {literals, ...}) = fold count_literal literals
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   612
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   613
fun raw_cnf_rules_pairs ps = map (fn (name, thm) => (thm, ((name, 0), thm))) ps
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   614
fun cnf_helper_thms thy raw =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   615
  map (`Thm.get_name_hint)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   616
  #> (if raw then raw_cnf_rules_pairs else cnf_rules_pairs thy)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   617
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   618
val optional_helpers =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   619
  [(["c_COMBI", "c_COMBK"], (false, @{thms COMBI_def COMBK_def})),
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   620
   (["c_COMBB", "c_COMBC"], (false, @{thms COMBB_def COMBC_def})),
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   621
   (["c_COMBS"], (false, @{thms COMBS_def}))]
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   622
val optional_typed_helpers =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   623
  [(["c_True", "c_False"], (true, @{thms True_or_False})),
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   624
   (["c_If"], (true, @{thms if_True if_False True_or_False}))]
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   625
val mandatory_helpers = @{thms fequal_imp_equal equal_imp_fequal}
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   626
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   627
val init_counters =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   628
  Symtab.make (maps (maps (map (rpair 0) o fst))
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   629
                    [optional_helpers, optional_typed_helpers])
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   630
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   631
fun get_helper_clauses thy is_FO full_types conjectures axcls =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   632
  let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   633
    val axclauses = map snd (make_axiom_clauses thy axcls)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   634
    val ct = fold (fold count_clause) [conjectures, axclauses] init_counters
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   635
    fun is_needed c = the (Symtab.lookup ct c) > 0
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   636
    val cnfs =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   637
      (optional_helpers
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   638
       |> full_types ? append optional_typed_helpers
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   639
       |> maps (fn (ss, (raw, ths)) =>
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   640
                   if exists is_needed ss then cnf_helper_thms thy raw ths
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   641
                   else []))
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   642
      @ (if is_FO then [] else cnf_helper_thms thy false mandatory_helpers)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   643
  in map snd (make_axiom_clauses thy cnfs) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   644
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   645
fun make_clause_table xs =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   646
  fold (Termtab.update o `(prop_of o fst)) xs Termtab.empty
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   647
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   648
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   649
(***************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   650
(* Type Classes Present in the Axiom or Conjecture Clauses     *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   651
(***************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   652
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   653
fun set_insert (x, s) = Symtab.update (x, ()) s
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   654
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   655
fun add_classes (sorts, cset) = List.foldl set_insert cset (flat sorts)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   656
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   657
(*Remove this trivial type class*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   658
fun delete_type cset = Symtab.delete_safe (the_single @{sort HOL.type}) cset;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   659
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   660
fun tfree_classes_of_terms ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   661
  let val sorts_list = map (map #2 o OldTerm.term_tfrees) ts
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   662
  in  Symtab.keys (delete_type (List.foldl add_classes Symtab.empty sorts_list))  end;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   663
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   664
fun tvar_classes_of_terms ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   665
  let val sorts_list = map (map #2 o OldTerm.term_tvars) ts
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   666
  in  Symtab.keys (delete_type (List.foldl add_classes Symtab.empty sorts_list))  end;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   667
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   668
(*fold type constructors*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   669
fun fold_type_consts f (Type (a, Ts)) x = fold (fold_type_consts f) Ts (f (a,x))
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   670
  | fold_type_consts _ _ x = x;
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   671
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   672
(*Type constructors used to instantiate overloaded constants are the only ones needed.*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   673
fun add_type_consts_in_term thy =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   674
  let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   675
    val const_typargs = Sign.const_typargs thy
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   676
    fun aux (Const x) = fold (fold_type_consts set_insert) (const_typargs x)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   677
      | aux (Abs (_, _, u)) = aux u
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   678
      | aux (Const (@{const_name skolem_id}, _) $ _) = I
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   679
      | aux (t $ u) = aux t #> aux u
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   680
      | aux _ = I
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   681
  in aux end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   682
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   683
fun type_consts_of_terms thy ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   684
  Symtab.keys (fold (add_type_consts_in_term thy) ts Symtab.empty);
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   685
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   686
(* Remove existing axiom clauses from the conjecture clauses, as this can
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   687
   dramatically boost an ATP's performance (for some reason). *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   688
fun subtract_cls ax_clauses =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   689
  filter_out (Termtab.defined (make_clause_table ax_clauses) o prop_of)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   690
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   691
(* prepare for passing to writer,
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   692
   create additional clauses based on the information from extra_cls *)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   693
fun prepare_clauses full_types goal_cls axcls extra_cls thy =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   694
  let
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   695
    val is_FO = forall (Meson.is_fol_term thy o prop_of) goal_cls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   696
    val ccls = subtract_cls extra_cls goal_cls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   697
    val _ = app (fn th => trace_msg (fn _ => Display.string_of_thm_global thy th)) ccls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   698
    val ccltms = map prop_of ccls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   699
    and axtms = map (prop_of o #1) extra_cls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   700
    val subs = tfree_classes_of_terms ccltms
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   701
    and supers = tvar_classes_of_terms axtms
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   702
    and tycons = type_consts_of_terms thy (ccltms @ axtms)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   703
    (*TFrees in conjecture clauses; TVars in axiom clauses*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   704
    val conjectures = make_conjecture_clauses thy ccls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   705
    val (_, extra_clauses) = ListPair.unzip (make_axiom_clauses thy extra_cls)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   706
    val (clnames, axiom_clauses) = ListPair.unzip (make_axiom_clauses thy axcls)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   707
    val helper_clauses =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   708
      get_helper_clauses thy is_FO full_types conjectures extra_cls
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   709
    val (supers', arity_clauses) = make_arity_clauses thy tycons supers
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   710
    val classrel_clauses = make_classrel_clauses thy subs supers'
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   711
  in
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   712
    (Vector.fromList clnames,
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   713
      (conjectures, axiom_clauses, extra_clauses, helper_clauses, classrel_clauses, arity_clauses))
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   714
  end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   715
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   716
end;