src/HOL/Tools/Sledgehammer/metis_translate.ML
author blanchet
Thu, 30 Sep 2010 20:44:53 +0200
changeset 39896 13b3a2ba9ea7
parent 39890 a1695e2169d0
permissions -rw-r--r--
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39494
bf7dd4902321 rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents: 39355
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/metis_translate.ML
38027
505657ddb047 standardize "Author" tags
blanchet
parents: 38024
diff changeset
     2
    Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
     3
    Author:     Kong W. Susanto, Cambridge University Computer Laboratory
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
     4
    Author:     Lawrence C. Paulson, Cambridge University Computer Laboratory
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36378
diff changeset
     5
    Author:     Jasmin Blanchette, TU Muenchen
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     6
39494
bf7dd4902321 rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents: 39355
diff changeset
     7
Translation of HOL to FOL for Metis.
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     8
*)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
     9
39494
bf7dd4902321 rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents: 39355
diff changeset
    10
signature METIS_TRANSLATE =
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    11
sig
37577
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
  datatype type_literal =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
    14
    TyLitVar of name * name |
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
    15
    TyLitFree of name * name
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    16
  datatype arLit =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
    17
    TConsLit of name * name * name list |
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
    18
    TVarLit of name * name
38028
22dcaec5fa77 minor refactoring
blanchet
parents: 38027
diff changeset
    19
  datatype arity_clause =
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
    20
    ArityClause of {name: string, conclLit: arLit, premLits: arLit list}
38028
22dcaec5fa77 minor refactoring
blanchet
parents: 38027
diff changeset
    21
  datatype class_rel_clause =
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
    22
    ClassRelClause of {name: string, subclass: name, superclass: name}
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    23
  datatype combtyp =
37924
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
    24
    CombTVar of name |
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
    25
    CombTFree of name |
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
    26
    CombType of name * combtyp list
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    27
  datatype combterm =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    28
    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
    29
    CombVar of name * combtyp |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    30
    CombApp of combterm * combterm
37923
8edbaf6ba405 renamed "Literal" to "FOLLiteral"
blanchet
parents: 37922
diff changeset
    31
  datatype fol_literal = FOLLiteral of bool * combterm
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    32
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    33
  datatype mode = FO | HO | FT
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    34
  type logic_map =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    35
    {axioms: (Metis_Thm.thm * thm) list,
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    36
     tfrees: type_literal list,
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
    37
     old_skolems: (string * term) list}
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    38
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
    39
  val type_wrapper_name : string
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
    40
  val bound_var_prefix : 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
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
    46
  val type_const_prefix: string
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    47
  val class_prefix: string
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
    48
  val new_skolem_const_prefix : string
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
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
    51
  val unascii_of: string -> string
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
    52
  val strip_prefix_and_unascii: string -> string -> string option
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
    53
  val make_bound_var : string -> string
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    54
  val make_schematic_var : string * int -> string
18868
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
    55
  val make_fixed_var : string -> string
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
    56
  val make_schematic_type_var : string * int -> string
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    57
  val make_fixed_type_var : string -> string
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
    58
  val make_fixed_const : string -> string
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
    59
  val make_fixed_type_const : string -> string
18868
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
    60
  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
    61
  val num_type_args: theory -> string -> int
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
    62
  val new_skolem_var_from_const: string -> indexname
36966
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36692
diff changeset
    63
  val type_literals_for_types : typ list -> type_literal list
39499
40bf0f66b994 simplify Skolem handling;
blanchet
parents: 39497
diff changeset
    64
  val make_class_rel_clauses :
40bf0f66b994 simplify Skolem handling;
blanchet
parents: 39497
diff changeset
    65
    theory -> class list -> class list -> class_rel_clause list
40bf0f66b994 simplify Skolem handling;
blanchet
parents: 39497
diff changeset
    66
  val make_arity_clauses :
40bf0f66b994 simplify Skolem handling;
blanchet
parents: 39497
diff changeset
    67
    theory -> string list -> class list -> class list * arity_clause list
37994
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37992
diff changeset
    68
  val combtyp_of : combterm -> combtyp
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    69
  val strip_combterm_comb : combterm -> combterm * combterm list
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
    70
  val combterm_from_term :
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
    71
    theory -> int -> (string * typ) list -> term -> combterm * typ list
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
    72
  val reveal_old_skolem_terms : (string * term) list -> term -> term
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
    73
  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
    74
  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
    75
  val type_consts_of_terms : theory -> term list -> string list
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    76
  val string_of_mode : mode -> string
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    77
  val build_logic_map :
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
    78
    mode -> Proof.context -> bool -> thm list -> thm list list
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
    79
    -> mode * logic_map
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    80
end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    81
39494
bf7dd4902321 rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents: 39355
diff changeset
    82
structure Metis_Translate : METIS_TRANSLATE =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    83
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    84
37509
f39464d971c4 factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents: 37500
diff changeset
    85
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
    86
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
    87
val bound_var_prefix = "B_"
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
    88
val schematic_var_prefix = "V_"
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
    89
val fixed_var_prefix = "v_"
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    90
17230
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
    91
val tvar_prefix = "T_";
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
    92
val tfree_prefix = "t_";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    93
17230
77e93bf303a5 fixed arities and restored changes that had gone missing
paulson
parents: 17150
diff changeset
    94
val const_prefix = "c_";
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
    95
val type_const_prefix = "tc_";
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
    96
val class_prefix = "class_";
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    97
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
    98
val skolem_const_prefix = "Sledgehammer" ^ Long_Name.separator ^ "Sko"
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
    99
val old_skolem_const_prefix = skolem_const_prefix ^ "o"
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   100
val new_skolem_const_prefix = skolem_const_prefix ^ "n"
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   101
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   102
fun union_all xss = fold (union (op =)) xss []
17775
2679ba74411f minor code tidyig
paulson
parents: 17764
diff changeset
   103
36493
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   104
(* 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
   105
   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
   106
val const_trans_table =
37678
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37643
diff changeset
   107
  Symtab.make [(@{type_name Product_Type.prod}, "prod"),
0040bafffdef "prod" and "sum" replace "*" and "+" respectively
haftmann
parents: 37643
diff changeset
   108
               (@{type_name Sum_Type.sum}, "sum"),
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
   109
               (@{const_name HOL.eq}, "equal"),
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   110
               (@{const_name HOL.conj}, "and"),
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   111
               (@{const_name HOL.disj}, "or"),
38786
e46e7a9cb622 formerly unnamed infix impliciation now named HOL.implies
haftmann
parents: 38748
diff changeset
   112
               (@{const_name HOL.implies}, "implies"),
38653
78d0f18d5b36 use different name for debugging purposes
blanchet
parents: 38105
diff changeset
   113
               (@{const_name Set.member}, "member"),
36493
a3357a631b96 reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents: 36491
diff changeset
   114
               (@{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
   115
               (@{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
   116
               (@{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
   117
               (@{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
   118
               (@{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
   119
               (@{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
   120
               (@{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
   121
               (@{const_name False}, "False"),
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   122
               (@{const_name If}, "If")]
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   123
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   124
(* 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
   125
val const_trans_table_inv =
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
   126
  Symtab.update ("fequal", @{const_name HOL.eq})
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   127
                (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
   128
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   129
val invert_const = perhaps (Symtab.lookup const_trans_table_inv)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   130
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   131
(*Escaping of special characters.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   132
  Alphanumeric characters are left unchanged.
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   133
  The character _ goes to __
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   134
  Characters in the range ASCII space to / go to _A to _P, respectively.
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38653
diff changeset
   135
  Other characters go to _nnn where nnn is the decimal ASCII code.*)
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   136
val A_minus_space = Char.ord #"A" - Char.ord #" ";
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   137
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   138
fun stringN_of_int 0 _ = ""
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   139
  | 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
   140
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   141
fun ascii_of_c c =
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   142
  if Char.isAlphaNum c then String.str c
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   143
  else if c = #"_" then "__"
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   144
  else if #" " <= c andalso c <= #"/"
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   145
       then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space))
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38653
diff changeset
   146
  else ("_" ^ stringN_of_int 3 (Char.ord c))  (*fixed width, in case more digits follow*)
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   147
15610
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   148
val ascii_of = String.translate ascii_of_c;
f855fd163b62 more concise ASCII escaping
paulson
parents: 15608
diff changeset
   149
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   150
(** Remove ASCII armouring from names in proof files **)
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   151
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   152
(*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
   153
  Also, the errors are "impossible" (hah!)*)
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   154
fun unascii_aux rcs [] = String.implode(rev rcs)
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   155
  | unascii_aux rcs [#"_"] = unascii_aux (#"_"::rcs) []  (*ERROR*)
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   156
      (*Three types of _ escapes: __, _A to _P, _nnn*)
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   157
  | unascii_aux rcs (#"_" :: #"_" :: cs) = unascii_aux (#"_"::rcs) cs
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   158
  | unascii_aux rcs (#"_" :: c :: cs) =
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   159
      if #"A" <= c andalso c<= #"P"  (*translation of #" " to #"/"*)
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   160
      then unascii_aux (Char.chr(Char.ord c - A_minus_space) :: rcs) cs
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   161
      else
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   162
        let val digits = List.take (c::cs, 3) handle Subscript => []
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   163
        in
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   164
            case Int.fromString (String.implode digits) of
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   165
                NONE => unascii_aux (c:: #"_"::rcs) cs  (*ERROR*)
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   166
              | SOME n => unascii_aux (Char.chr n :: rcs) (List.drop (cs, 2))
24183
a46b758941a4 Code to undo the function ascii_of
paulson
parents: 23881
diff changeset
   167
        end
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   168
  | unascii_aux rcs (c::cs) = unascii_aux (c::rcs) cs
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   169
val unascii_of = unascii_aux [] o String.explode
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   170
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   171
(* 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
   172
   un-ASCII'd. *)
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   173
fun strip_prefix_and_unascii s1 s =
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   174
  if String.isPrefix s1 s then
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   175
    SOME (unascii_of (String.extract (s, size s1, NONE)))
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   176
  else
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   177
    NONE
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   178
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   179
(*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
   180
fun trim_type_var s =
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   181
  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
   182
  else error ("trim_type: Malformed type variable encountered: " ^ s);
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   183
16903
bf42a9071ad1 streamlined the tptp output
paulson
parents: 16794
diff changeset
   184
fun ascii_of_indexname (v,0) = ascii_of v
17525
ae5bb6001afb tidying, and support for axclass/classrel clauses
paulson
parents: 17422
diff changeset
   185
  | ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ Int.toString i;
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   186
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   187
fun make_bound_var x = bound_var_prefix ^ ascii_of x
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   188
fun make_schematic_var v = schematic_var_prefix ^ ascii_of_indexname v
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   189
fun make_fixed_var x = fixed_var_prefix ^ ascii_of x
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   190
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   191
fun make_schematic_type_var (x,i) =
16925
0fd7b1438d28 simpler variable names, and no types for monomorphic constants
paulson
parents: 16903
diff changeset
   192
      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
   193
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
   194
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   195
fun lookup_const c =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   196
  case Symtab.lookup const_trans_table c of
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   197
    SOME c' => c'
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   198
  | NONE => ascii_of c
23075
69e30a7e8880 Some hacks for SPASS format
paulson
parents: 23029
diff changeset
   199
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
   200
(* HOL.eq MUST BE "equal" because it's built into ATPs. *)
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38795
diff changeset
   201
fun make_fixed_const @{const_name HOL.eq} = "equal"
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   202
  | 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
   203
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   204
fun make_fixed_type_const c = type_const_prefix ^ lookup_const c
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 16976
diff changeset
   205
17261
193b84a70ca4 curried_lookup/update;
wenzelm
parents: 17234
diff changeset
   206
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
   207
37618
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   208
(* 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
   209
   (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
   210
   constant name. *)
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   211
fun num_type_args thy s =
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   212
  if String.isPrefix skolem_const_prefix s then
39499
40bf0f66b994 simplify Skolem handling;
blanchet
parents: 39497
diff changeset
   213
    s |> space_explode Long_Name.separator |> List.last |> Int.fromString |> the
37618
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   214
  else
fa57a87f92a0 get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents: 37616
diff changeset
   215
    (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
   216
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   217
fun new_skolem_var_from_const s =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   218
  let
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   219
    val ss = s |> space_explode Long_Name.separator
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   220
    val n = length ss
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   221
  in (nth ss (n - 2), nth ss (n - 3) |> Int.fromString |> the) end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   222
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   223
37624
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37623
diff changeset
   224
(**** Definitions and functions for FOL clauses for TPTP format output ****)
36169
27b1cc58715e store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents: 36168
diff changeset
   225
37624
3ee568334813 move "nice names" from Metis to TPTP format
blanchet
parents: 37623
diff changeset
   226
type name = string * string
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   227
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   228
(**** Isabelle FOL clauses ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   229
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
   230
(* 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
   231
datatype type_literal =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   232
  TyLitVar of name * name |
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   233
  TyLitFree of name * name
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   234
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   235
(*Make literals for sorted type variables*)
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   236
fun sorts_on_typs_aux (_, [])   = []
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   237
  | sorts_on_typs_aux ((x,i),  s::ss) =
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   238
      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
   239
      in
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   240
          if s = "HOL.type" then sorts
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   241
          else if i = ~1 then TyLitFree (`make_type_class s, `make_fixed_type_var x) :: sorts
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   242
          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
   243
      end;
17150
ce2a1aeb42aa DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents: 16976
diff changeset
   244
24940
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   245
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
   246
  | sorts_on_typs (TVar (v,s))  = sorts_on_typs_aux (v,s);
8f9dea697b8d getting rid of type typ_var
paulson
parents: 24937
diff changeset
   247
24937
340523598914 context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents: 24322
diff changeset
   248
(*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
   249
fun type_literals_for_types Ts =
adc11fb3f3aa generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents: 36692
diff changeset
   250
  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
   251
1ffcf4802802 Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents: 19719
diff changeset
   252
(** make axiom and conjecture clauses. **)
1ffcf4802802 Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents: 19719
diff changeset
   253
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   254
(**** Isabelle arities ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   255
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   256
datatype arLit =
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   257
  TConsLit of name * name * name list |
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   258
  TVarLit of name * name
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   259
35865
2f8fb5242799 more Sledgehammer refactoring
blanchet
parents: 35827
diff changeset
   260
datatype arity_clause =
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
   261
  ArityClause of {name: string, conclLit: arLit, premLits: arLit list}
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   262
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   263
18798
ca02a2077955 tidying up SPASS output
paulson
parents: 18676
diff changeset
   264
fun gen_TVars 0 = []
ca02a2077955 tidying up SPASS output
paulson
parents: 18676
diff changeset
   265
  | gen_TVars n = ("T_" ^ Int.toString n) :: gen_TVars (n-1);
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   266
18411
2d3165a0fb40 No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents: 18409
diff changeset
   267
fun pack_sort(_,[])  = []
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   268
  | pack_sort(tvar, "HOL.type"::srt) = pack_sort (tvar, srt)   (*IGNORE sort "type"*)
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   269
  | pack_sort(tvar, cls::srt) =
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   270
    (`make_type_class cls, (tvar, tvar)) :: pack_sort (tvar, srt)
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   271
18411
2d3165a0fb40 No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents: 18409
diff changeset
   272
(*Arity of type constructor tcon :: (arg1,...,argN)res*)
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
   273
fun make_axiom_arity_clause (tcons, name, (cls,args)) =
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   274
  let
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   275
    val tvars = gen_TVars (length args)
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   276
    val tvars_srts = ListPair.zip (tvars, args)
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   277
  in
39318
ad9a1f9b0558 implemented Auto Sledgehammer
blanchet
parents: 38864
diff changeset
   278
    ArityClause {name = name,
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   279
                 conclLit = TConsLit (`make_type_class cls,
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   280
                                      `make_fixed_type_const tcons,
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   281
                                      tvars ~~ tvars),
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   282
                 premLits = map TVarLit (union_all (map pack_sort tvars_srts))}
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   283
  end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   284
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   285
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   286
(**** Isabelle class relations ****)
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   287
37925
1188e6bff48d rename "classrel" to "class_rel"
blanchet
parents: 37924
diff changeset
   288
datatype class_rel_clause =
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
   289
  ClassRelClause of {name: string, subclass: name, superclass: name}
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   290
21290
33b6bb5d6ab8 Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents: 21254
diff changeset
   291
(*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
   292
fun class_pairs _ [] _ = []
21432
625797c592b2 Optimized class_pairs for the common case of no subclasses
paulson
parents: 21416
diff changeset
   293
  | class_pairs thy subs supers =
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   294
      let
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   295
        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
   296
        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
   297
        fun add_supers sub = fold (add_super sub) supers
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   298
      in fold add_supers subs [] end
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   299
37925
1188e6bff48d rename "classrel" to "class_rel"
blanchet
parents: 37924
diff changeset
   300
fun make_class_rel_clause (sub,super) =
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
   301
  ClassRelClause {name = sub ^ "_" ^ super,
37643
f576af716aa6 rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents: 37632
diff changeset
   302
                  subclass = `make_type_class sub,
38105
373351f5f834 don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents: 38028
diff changeset
   303
                  superclass = `make_type_class super}
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   304
37925
1188e6bff48d rename "classrel" to "class_rel"
blanchet
parents: 37924
diff changeset
   305
fun make_class_rel_clauses thy subs supers =
1188e6bff48d rename "classrel" to "class_rel"
blanchet
parents: 37924
diff changeset
   306
  map make_class_rel_clause (class_pairs thy subs supers);
18868
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
   307
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
   308
7cfc21ee0370 working SPASS support; much tidying
paulson
parents: 18863
diff changeset
   309
(** Isabelle arities **)
17845
1438291d57f0 deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents: 17775
diff changeset
   310
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   311
fun arity_clause _ _ (_, []) = []
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   312
  | arity_clause seen n (tcons, ("HOL.type",_)::ars) =  (*ignore*)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   313
      arity_clause seen n (tcons,ars)
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   314
  | 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
   315
      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
   316
          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
   317
          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
   318
      else
37572
a899f9506f39 more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents: 37570
diff changeset
   319
          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
   320
          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
   321
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   322
fun multi_arity_clause [] = []
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   323
  | multi_arity_clause ((tcons, ars) :: tc_arlists) =
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   324
      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
   325
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   326
(*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
   327
  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
   328
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
   329
  let val alg = Sign.classes_of thy
36218
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   330
      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
   331
      fun add_class tycon class =
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   332
        cons (class, domain_sorts tycon class)
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   333
        handle Sorts.CLASS_ERROR _ => I
0e4a01f3e7d3 get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents: 36170
diff changeset
   334
      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
   335
  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
   336
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   337
(*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
   338
fun iter_type_class_pairs _ _ [] = ([], [])
22643
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   339
  | iter_type_class_pairs thy tycons classes =
bc3bb8e9594a Improved and simplified the treatment of classrel/arity clauses
paulson
parents: 22383
diff changeset
   340
      let val cpairs = type_class_pairs thy tycons classes
33040
cffdb7b28498 removed old-style \ and \\ infixes
haftmann
parents: 33038
diff changeset
   341
          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
   342
            |> subtract (op =) classes |> subtract (op =) HOLogic.typeS
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   343
          val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses
33042
ddf1f03a9ad9 curried union as canonical list operation
haftmann
parents: 33038
diff changeset
   344
      in (union (op =) classes' classes, union (op =) cpairs' cpairs) end;
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   345
37498
b426cbdb5a23 removed Sledgehammer's support for the DFG syntax;
blanchet
parents: 37479
diff changeset
   346
fun make_arity_clauses thy tycons classes =
24310
af4af9993922 proper signature;
wenzelm
parents: 24183
diff changeset
   347
  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
   348
  in  (classes', multi_arity_clause cpairs)  end;
18863
a113b6839df1 reorganization of code to support DFG otuput
paulson
parents: 18856
diff changeset
   349
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   350
datatype combtyp =
37924
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   351
  CombTVar of name |
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   352
  CombTFree of name |
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   353
  CombType of name * combtyp list
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   354
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   355
datatype combterm =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   356
  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
   357
  CombVar of name * combtyp |
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   358
  CombApp of combterm * combterm
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   359
37923
8edbaf6ba405 renamed "Literal" to "FOLLiteral"
blanchet
parents: 37922
diff changeset
   360
datatype fol_literal = FOLLiteral of bool * combterm
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   361
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   362
(*********************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   363
(* 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
   364
(*********************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   365
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   366
(*Result of a function type; no need to check that the argument type matches.*)
37924
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   367
fun result_type (CombType (_, [_, tp2])) = tp2
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   368
  | result_type _ = raise Fail "non-function type"
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   369
37994
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37992
diff changeset
   370
fun combtyp_of (CombConst (_, tp, _)) = tp
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37992
diff changeset
   371
  | combtyp_of (CombVar (_, tp)) = tp
b04307085a09 make TPTP generator accept full first-order formulas
blanchet
parents: 37992
diff changeset
   372
  | combtyp_of (CombApp (t1, _)) = result_type (combtyp_of t1)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   373
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   374
(*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
   375
fun strip_combterm_comb u =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   376
    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
   377
        |   stripc  x =  x
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   378
    in stripc(u,[]) end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   379
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   380
fun combtype_of (Type (a, Ts)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   381
    let val (folTypes, ts) = combtypes_of Ts in
37924
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   382
      (CombType (`make_fixed_type_const a, folTypes), ts)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   383
    end
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   384
  | combtype_of (tp as TFree (a, _)) = (CombTFree (`make_fixed_type_var a), [tp])
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   385
  | combtype_of (tp as TVar (x, _)) =
37924
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   386
    (CombTVar (make_schematic_type_var x, string_of_indexname x), [tp])
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   387
and combtypes_of Ts =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   388
  let val (folTyps, ts) = ListPair.unzip (map combtype_of Ts) in
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   389
    (folTyps, union_all ts)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   390
  end
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   391
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   392
(* same as above, but no gathering of sort information *)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   393
fun simple_combtype_of (Type (a, Ts)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   394
    CombType (`make_fixed_type_const a, map simple_combtype_of Ts)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   395
  | simple_combtype_of (TFree (a, _)) = CombTFree (`make_fixed_type_var a)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   396
  | simple_combtype_of (TVar (x, _)) =
37924
17f36ad210d6 rename "combtyp" constructors
blanchet
parents: 37923
diff changeset
   397
    CombTVar (make_schematic_type_var x, string_of_indexname x)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   398
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   399
fun new_skolem_const_name th_no s num_T_args =
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   400
  [new_skolem_const_prefix, string_of_int th_no, s, string_of_int num_T_args]
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   401
  |> space_implode Long_Name.separator
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   402
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   403
(* Converts a term (with combinators) into a combterm. Also accummulates sort
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   404
   infomation. *)
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   405
fun combterm_from_term thy th_no bs (P $ Q) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   406
      let val (P', tsP) = combterm_from_term thy th_no bs P
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   407
          val (Q', tsQ) = combterm_from_term thy th_no bs Q
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   408
      in  (CombApp (P', Q'), union (op =) tsP tsQ)  end
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   409
  | combterm_from_term thy _ _ (Const (c, T)) =
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   410
      let
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   411
        val (tp, ts) = combtype_of T
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   412
        val tvar_list =
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   413
          (if String.isPrefix old_skolem_const_prefix c then
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   414
             [] |> Term.add_tvarsT T |> map TVar
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   415
           else
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   416
             (c, T) |> Sign.const_typargs thy)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   417
          |> map simple_combtype_of
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   418
        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
   419
      in  (c',ts)  end
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   420
  | combterm_from_term _ _ _ (Free (v, T)) =
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   421
      let val (tp, ts) = combtype_of T
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   422
          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
   423
      in  (v',ts)  end
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   424
  | combterm_from_term _ th_no _ (Var (v as (s, _), T)) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   425
    let
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   426
      val (tp, ts) = combtype_of T
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   427
      val v' =
39890
a1695e2169d0 finished renaming file and module
blanchet
parents: 39888
diff changeset
   428
        if String.isPrefix Meson_Clausify.new_skolem_var_prefix s then
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   429
          let
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   430
            val tys = T |> strip_type |> swap |> op ::
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   431
            val s' = new_skolem_const_name th_no s (length tys)
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   432
          in
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   433
            CombConst (`make_fixed_const s', tp, map simple_combtype_of tys)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   434
          end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   435
        else
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   436
          CombVar ((make_schematic_var v, string_of_indexname v), tp)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   437
    in (v', ts) end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   438
  | combterm_from_term _ _ bs (Bound j) =
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   439
      let
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   440
        val (s, T) = nth bs j
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   441
        val (tp, ts) = combtype_of T
37995
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   442
        val v' = CombConst (`make_bound_var s, tp, [])
06f02b15ef8a generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents: 37994
diff changeset
   443
      in (v', ts) end
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   444
  | combterm_from_term _ _ _ (Abs _) = raise Fail "HOL clause: Abs"
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   445
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   446
fun predicate_of thy th_no ((@{const Not} $ P), pos) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   447
    predicate_of thy th_no (P, not pos)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   448
  | predicate_of thy th_no (t, pos) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   449
    (combterm_from_term thy th_no [] (Envir.eta_contract t), pos)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   450
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   451
fun literals_of_term1 args thy th_no (@{const Trueprop} $ P) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   452
    literals_of_term1 args thy th_no P
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   453
  | literals_of_term1 args thy th_no (@{const HOL.disj} $ P $ Q) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   454
    literals_of_term1 (literals_of_term1 args thy th_no P) thy th_no Q
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   455
  | literals_of_term1 (lits, ts) thy th_no P =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   456
    let val ((pred, ts'), pol) = predicate_of thy th_no (P, true) in
37923
8edbaf6ba405 renamed "Literal" to "FOLLiteral"
blanchet
parents: 37922
diff changeset
   457
      (FOLLiteral (pol, pred) :: lits, union (op =) ts ts')
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   458
    end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   459
val literals_of_term = literals_of_term1 ([], [])
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   460
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   461
fun old_skolem_const_name i j num_T_args =
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   462
  old_skolem_const_prefix ^ Long_Name.separator ^
39499
40bf0f66b994 simplify Skolem handling;
blanchet
parents: 39497
diff changeset
   463
  (space_implode Long_Name.separator (map Int.toString [i, j, num_T_args]))
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   464
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   465
fun conceal_old_skolem_terms i old_skolems t =
39355
104a6d9e493e rename internal Sledgehammer constant
blanchet
parents: 39318
diff changeset
   466
  if exists_Const (curry (op =) @{const_name skolem} o fst) t then
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   467
    let
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   468
      fun aux old_skolems
39355
104a6d9e493e rename internal Sledgehammer constant
blanchet
parents: 39318
diff changeset
   469
              (t as (Const (@{const_name skolem}, Type (_, [_, T])) $ _)) =
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   470
          let
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   471
            val (old_skolems, s) =
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   472
              if i = ~1 then
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   473
                (old_skolems, @{const_name undefined})
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   474
              else case AList.find (op aconv) old_skolems t of
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   475
                s :: _ => (old_skolems, s)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   476
              | [] =>
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   477
                let
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   478
                  val s = old_skolem_const_name i (length old_skolems)
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   479
                                                (length (Term.add_tvarsT T []))
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   480
                in ((s, t) :: old_skolems, s) end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   481
          in (old_skolems, Const (s, T)) end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   482
        | aux old_skolems (t1 $ t2) =
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   483
          let
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   484
            val (old_skolems, t1) = aux old_skolems t1
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   485
            val (old_skolems, t2) = aux old_skolems t2
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   486
          in (old_skolems, t1 $ t2) end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   487
        | aux old_skolems (Abs (s, T, t')) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   488
          let val (old_skolems, t') = aux old_skolems t' in
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   489
            (old_skolems, Abs (s, T, t'))
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   490
          end
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   491
        | aux old_skolems t = (old_skolems, t)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   492
    in aux old_skolems t end
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   493
  else
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   494
    (old_skolems, t)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   495
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   496
fun reveal_old_skolem_terms old_skolems =
37632
df12f798df99 move function
blanchet
parents: 37625
diff changeset
   497
  map_aterms (fn t as Const (s, _) =>
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39890
diff changeset
   498
                 if String.isPrefix old_skolem_const_prefix s then
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   499
                   AList.lookup (op =) old_skolems s |> the
37632
df12f798df99 move function
blanchet
parents: 37625
diff changeset
   500
                   |> map_types Type_Infer.paramify_vars
df12f798df99 move function
blanchet
parents: 37625
diff changeset
   501
                 else
df12f798df99 move function
blanchet
parents: 37625
diff changeset
   502
                   t
df12f798df99 move function
blanchet
parents: 37625
diff changeset
   503
               | t => t)
df12f798df99 move function
blanchet
parents: 37625
diff changeset
   504
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   505
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   506
(***************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   507
(* 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
   508
(***************************************************************)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   509
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   510
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
   511
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   512
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
   513
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   514
(*Remove this trivial type class*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   515
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
   516
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   517
fun tfree_classes_of_terms ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   518
  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
   519
  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
   520
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   521
fun tvar_classes_of_terms ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   522
  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
   523
  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
   524
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   525
(*fold type constructors*)
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   526
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
   527
  | fold_type_consts _ _ x = x;
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
(*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
   530
fun add_type_consts_in_term thy =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   531
  let
38748
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   532
    fun aux (Const x) =
69fea359d3f8 renaming
blanchet
parents: 38738
diff changeset
   533
        fold (fold_type_consts set_insert) (Sign.const_typargs thy x)
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   534
      | aux (Abs (_, _, u)) = aux u
39355
104a6d9e493e rename internal Sledgehammer constant
blanchet
parents: 39318
diff changeset
   535
      | aux (Const (@{const_name skolem}, _) $ _) = I
37577
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   536
      | aux (t $ u) = aux t #> aux u
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   537
      | aux _ = I
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   538
  in aux end
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   539
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   540
fun type_consts_of_terms thy ts =
5379f41a1322 merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents: 37575
diff changeset
   541
  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
   542
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   543
(* ------------------------------------------------------------------------- *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   544
(* HOL to FOL  (Isabelle to Metis)                                           *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   545
(* ------------------------------------------------------------------------- *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   546
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   547
datatype mode = FO | HO | FT  (* first-order, higher-order, fully-typed *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   548
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   549
fun string_of_mode FO = "FO"
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   550
  | string_of_mode HO = "HO"
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   551
  | string_of_mode FT = "FT"
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   552
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   553
fun fn_isa_to_met_sublevel "equal" = "=" (* FIXME: "c_fequal" *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   554
  | fn_isa_to_met_sublevel x = x
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   555
fun fn_isa_to_met_toplevel "equal" = "="
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   556
  | fn_isa_to_met_toplevel x = x
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   557
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   558
fun metis_lit b c args = (b, (c, args));
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   559
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   560
fun metis_term_from_combtyp (CombTVar (s, _)) = Metis_Term.Var s
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   561
  | metis_term_from_combtyp (CombTFree (s, _)) = Metis_Term.Fn (s, [])
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   562
  | metis_term_from_combtyp (CombType ((s, _), tps)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   563
    Metis_Term.Fn (s, map metis_term_from_combtyp tps);
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   564
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   565
(*These two functions insert type literals before the real literals. That is the
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   566
  opposite order from TPTP linkup, but maybe OK.*)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   567
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   568
fun hol_term_to_fol_FO tm =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   569
  case strip_combterm_comb tm of
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   570
      (CombConst ((c, _), _, tys), tms) =>
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   571
        let val tyargs = map metis_term_from_combtyp tys
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   572
            val args   = map hol_term_to_fol_FO tms
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   573
        in Metis_Term.Fn (c, tyargs @ args) end
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   574
    | (CombVar ((v, _), _), []) => Metis_Term.Var v
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   575
    | _ => raise Fail "non-first-order combterm"
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   576
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   577
fun hol_term_to_fol_HO (CombConst ((a, _), _, tylist)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   578
      Metis_Term.Fn (fn_isa_to_met_sublevel a, map metis_term_from_combtyp tylist)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   579
  | hol_term_to_fol_HO (CombVar ((s, _), _)) = Metis_Term.Var s
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   580
  | hol_term_to_fol_HO (CombApp (tm1, tm2)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   581
       Metis_Term.Fn (".", map hol_term_to_fol_HO [tm1, tm2]);
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   582
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   583
(*The fully-typed translation, to avoid type errors*)
39720
0b93a954da4f rename "Clausifier" to "Meson_Clausifier" and merge with "Meson_Tactic"
blanchet
parents: 39499
diff changeset
   584
fun wrap_type (tm, ty) =
0b93a954da4f rename "Clausifier" to "Meson_Clausifier" and merge with "Meson_Tactic"
blanchet
parents: 39499
diff changeset
   585
  Metis_Term.Fn (type_wrapper_name, [tm, metis_term_from_combtyp ty])
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   586
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   587
fun hol_term_to_fol_FT (CombVar ((s, _), ty)) = wrap_type (Metis_Term.Var s, ty)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   588
  | hol_term_to_fol_FT (CombConst((a, _), ty, _)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   589
      wrap_type (Metis_Term.Fn(fn_isa_to_met_sublevel a, []), ty)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   590
  | hol_term_to_fol_FT (tm as CombApp(tm1,tm2)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   591
       wrap_type (Metis_Term.Fn(".", map hol_term_to_fol_FT [tm1,tm2]),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   592
                  combtyp_of tm)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   593
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   594
fun hol_literal_to_fol FO (FOLLiteral (pos, tm)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   595
      let val (CombConst((p, _), _, tys), tms) = strip_combterm_comb tm
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   596
          val tylits = if p = "equal" then [] else map metis_term_from_combtyp tys
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   597
          val lits = map hol_term_to_fol_FO tms
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   598
      in metis_lit pos (fn_isa_to_met_toplevel p) (tylits @ lits) end
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   599
  | hol_literal_to_fol HO (FOLLiteral (pos, tm)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   600
     (case strip_combterm_comb tm of
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   601
          (CombConst(("equal", _), _, _), tms) =>
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   602
            metis_lit pos "=" (map hol_term_to_fol_HO tms)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   603
        | _ => metis_lit pos "{}" [hol_term_to_fol_HO tm])   (*hBOOL*)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   604
  | hol_literal_to_fol FT (FOLLiteral (pos, tm)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   605
     (case strip_combterm_comb tm of
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   606
          (CombConst(("equal", _), _, _), tms) =>
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   607
            metis_lit pos "=" (map hol_term_to_fol_FT tms)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   608
        | _ => metis_lit pos "{}" [hol_term_to_fol_FT tm])   (*hBOOL*);
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   609
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   610
fun literals_of_hol_term thy th_no mode t =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   611
      let val (lits, types_sorts) = literals_of_term thy th_no t
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   612
      in  (map (hol_literal_to_fol mode) lits, types_sorts) end;
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   613
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   614
(*Sign should be "true" for conjecture type constraints, "false" for type lits in clauses.*)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   615
fun metis_of_type_literals pos (TyLitVar ((s, _), (s', _))) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   616
    metis_lit pos s [Metis_Term.Var s']
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   617
  | metis_of_type_literals pos (TyLitFree ((s, _), (s', _))) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   618
    metis_lit pos s [Metis_Term.Fn (s',[])]
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   619
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   620
fun default_sort _ (TVar _) = false
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   621
  | default_sort ctxt (TFree (x, s)) = (s = the_default [] (Variable.def_sort ctxt (x, ~1)));
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   622
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   623
fun metis_of_tfree tf =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   624
  Metis_Thm.axiom (Metis_LiteralSet.singleton (metis_of_type_literals true tf));
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   625
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   626
fun hol_thm_to_fol is_conjecture th_no ctxt type_lits mode j old_skolems th =
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   627
  let
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   628
    val thy = ProofContext.theory_of ctxt
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   629
    val (old_skolems, (mlits, types_sorts)) =
39888
40ef95149770 ignore Skolem assumption (if any)
blanchet
parents: 39887
diff changeset
   630
     th |> prop_of |> Logic.strip_imp_concl
40ef95149770 ignore Skolem assumption (if any)
blanchet
parents: 39887
diff changeset
   631
        |> conceal_old_skolem_terms j old_skolems
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   632
        ||> (HOLogic.dest_Trueprop #> literals_of_hol_term thy th_no mode)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   633
  in
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   634
    if is_conjecture then
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   635
      (Metis_Thm.axiom (Metis_LiteralSet.fromList mlits),
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   636
       type_literals_for_types types_sorts, old_skolems)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   637
    else
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   638
      let
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   639
        val tylits = filter_out (default_sort ctxt) types_sorts
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   640
                     |> type_literals_for_types
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   641
        val mtylits =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   642
          if type_lits then map (metis_of_type_literals false) tylits else []
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   643
      in
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   644
        (Metis_Thm.axiom (Metis_LiteralSet.fromList(mtylits @ mlits)), [],
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   645
         old_skolems)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   646
      end
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   647
  end;
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   648
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   649
val helpers =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   650
  [("c_COMBI", (false, map (`I) @{thms COMBI_def})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   651
   ("c_COMBK", (false, map (`I) @{thms COMBK_def})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   652
   ("c_COMBB", (false, map (`I) @{thms COMBB_def})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   653
   ("c_COMBC", (false, map (`I) @{thms COMBC_def})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   654
   ("c_COMBS", (false, map (`I) @{thms COMBS_def})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   655
   ("c_fequal", (false, map (rpair @{thm equal_imp_equal})
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   656
                            @{thms fequal_imp_equal equal_imp_fequal})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   657
   ("c_True", (true, map (`I) @{thms True_or_False})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   658
   ("c_False", (true, map (`I) @{thms True_or_False})),
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   659
   ("c_If", (true, map (`I) @{thms if_True if_False True_or_False}))]
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   660
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   661
(* ------------------------------------------------------------------------- *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   662
(* Logic maps manage the interface between HOL and first-order logic.        *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   663
(* ------------------------------------------------------------------------- *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   664
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   665
type logic_map =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   666
  {axioms: (Metis_Thm.thm * thm) list,
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   667
   tfrees: type_literal list,
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   668
   old_skolems: (string * term) list}
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   669
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   670
fun is_quasi_fol_clause thy =
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   671
  Meson.is_fol_term thy o snd o conceal_old_skolem_terms ~1 [] o prop_of
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   672
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   673
(*Extract TFree constraints from context to include as conjecture clauses*)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   674
fun init_tfrees ctxt =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   675
  let fun add ((a,i),s) Ts = if i = ~1 then TFree(a,s) :: Ts else Ts in
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   676
    Vartab.fold add (#2 (Variable.constraints_of ctxt)) []
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   677
    |> type_literals_for_types
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   678
  end;
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   679
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   680
(*Insert non-logical axioms corresponding to all accumulated TFrees*)
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   681
fun add_tfrees {axioms, tfrees, old_skolems} : logic_map =
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   682
     {axioms = map (rpair TrueI o metis_of_tfree) (distinct (op =) tfrees) @
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   683
               axioms,
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   684
      tfrees = tfrees, old_skolems = old_skolems}
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   685
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   686
(*transform isabelle type / arity clause to metis clause *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   687
fun add_type_thm [] lmap = lmap
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   688
  | add_type_thm ((ith, mth) :: cls) {axioms, tfrees, old_skolems} =
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   689
      add_type_thm cls {axioms = (mth, ith) :: axioms, tfrees = tfrees,
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   690
                        old_skolems = old_skolems}
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   691
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   692
fun const_in_metis c (pred, tm_list) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   693
  let
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   694
    fun in_mterm (Metis_Term.Var _) = false
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   695
      | in_mterm (Metis_Term.Fn (".", tm_list)) = exists in_mterm tm_list
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   696
      | in_mterm (Metis_Term.Fn (nm, tm_list)) = c=nm orelse exists in_mterm tm_list
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   697
  in  c = pred orelse exists in_mterm tm_list  end;
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   698
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   699
(* ARITY CLAUSE *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   700
fun m_arity_cls (TConsLit ((c, _), (t, _), args)) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   701
    metis_lit true c [Metis_Term.Fn(t, map (Metis_Term.Var o fst) args)]
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   702
  | m_arity_cls (TVarLit ((c, _), (s, _))) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   703
    metis_lit false c [Metis_Term.Var s]
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   704
(*TrueI is returned as the Isabelle counterpart because there isn't any.*)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   705
fun arity_cls (ArityClause {conclLit, premLits, ...}) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   706
  (TrueI,
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   707
   Metis_Thm.axiom (Metis_LiteralSet.fromList (map m_arity_cls (conclLit :: premLits))));
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   708
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   709
(* CLASSREL CLAUSE *)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   710
fun m_class_rel_cls (subclass, _) (superclass, _) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   711
  [metis_lit false subclass [Metis_Term.Var "T"], metis_lit true superclass [Metis_Term.Var "T"]];
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   712
fun class_rel_cls (ClassRelClause {subclass, superclass, ...}) =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   713
  (TrueI, Metis_Thm.axiom (Metis_LiteralSet.fromList (m_class_rel_cls subclass superclass)));
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   714
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   715
fun type_ext thy tms =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   716
  let val subs = tfree_classes_of_terms tms
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   717
      val supers = tvar_classes_of_terms tms
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   718
      and tycons = type_consts_of_terms thy tms
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   719
      val (supers', arity_clauses) = make_arity_clauses thy tycons supers
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   720
      val class_rel_clauses = make_class_rel_clauses thy subs supers'
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   721
  in  map class_rel_cls class_rel_clauses @ map arity_cls arity_clauses
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   722
  end;
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   723
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   724
(* Function to generate metis clauses, including comb and type clauses *)
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   725
fun build_logic_map mode0 ctxt type_lits cls thss =
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   726
  let val thy = ProofContext.theory_of ctxt
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   727
      (*The modes FO and FT are sticky. HO can be downgraded to FO.*)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   728
      fun set_mode FO = FO
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   729
        | set_mode HO =
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   730
          if forall (forall (is_quasi_fol_clause thy)) (cls :: thss) then FO
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   731
          else HO
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   732
        | set_mode FT = FT
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   733
      val mode = set_mode mode0
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   734
      (*transform isabelle clause to metis clause *)
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   735
      fun add_thm th_no is_conjecture (metis_ith, isa_ith)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   736
                  {axioms, tfrees, old_skolems} : logic_map =
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   737
        let
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   738
          val (mth, tfree_lits, old_skolems) =
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   739
            hol_thm_to_fol is_conjecture th_no ctxt type_lits mode (length axioms)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   740
                           old_skolems metis_ith
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   741
        in
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   742
           {axioms = (mth, Meson.make_meta_clause isa_ith) :: axioms,
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   743
            tfrees = union (op =) tfree_lits tfrees, old_skolems = old_skolems}
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   744
        end;
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   745
      val lmap = {axioms = [], tfrees = init_tfrees ctxt, old_skolems = []}
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   746
                 |> fold (add_thm 0 true o `I) cls
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   747
                 |> add_tfrees
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   748
                 |> fold (fn (th_no, ths) => fold (add_thm th_no false o `I) ths)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   749
                         (1 upto length thss ~~ thss)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   750
      val clause_lists = map (Metis_Thm.clause o #1) (#axioms lmap)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   751
      fun is_used c =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   752
        exists (Metis_LiteralSet.exists (const_in_metis c o #2)) clause_lists
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   753
      val lmap =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   754
        if mode = FO then
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   755
          lmap
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   756
        else
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   757
          let
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   758
            val helper_ths =
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   759
              helpers |> filter (is_used o fst)
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   760
                      |> maps (fn (c, (needs_full_types, thms)) =>
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   761
                                  if not (is_used c) orelse
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   762
                                     needs_full_types andalso mode <> FT then
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   763
                                    []
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   764
                                  else
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   765
                                    thms)
39886
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   766
          in lmap |> fold (add_thm ~1 false) helper_ths end
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   767
  in
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   768
    (mode, add_type_thm (type_ext thy (maps (map prop_of) (cls :: thss))) lmap)
8a9f0c97d550 first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents: 39720
diff changeset
   769
  end
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   770
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   771
end;