src/HOL/Tools/Metis/metis_tactic.ML
author blanchet
Tue, 15 Nov 2011 22:13:39 +0100
changeset 45511 9b0f8ca4388e
parent 45508 b216dc1b3630
child 45512 a6cce8032fff
permissions -rw-r--r--
continued implementation of lambda-lifting in Metis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44651
5d6a11e166cf renamed "Metis_Tactics" to "Metis_Tactic", now that there is only one Metis tactic ("metisFT" is legacy)
blanchet
parents: 44634
diff changeset
     1
(*  Title:      HOL/Tools/Metis/metis_tactic.ML
38027
505657ddb047 standardize "Author" tags
blanchet
parents: 38016
diff changeset
     2
    Author:     Kong W. Susanto, Cambridge University Computer Laboratory
505657ddb047 standardize "Author" tags
blanchet
parents: 38016
diff changeset
     3
    Author:     Lawrence C. Paulson, Cambridge University Computer Laboratory
505657ddb047 standardize "Author" tags
blanchet
parents: 38016
diff changeset
     4
    Author:     Jasmin Blanchette, TU Muenchen
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
     5
    Copyright   Cambridge University 2007
23447
1f16190e3836 tuned comments;
wenzelm
parents: 23442
diff changeset
     6
29266
4a478f9d2847 use regular Term.add_vars, Term.add_frees etc.;
wenzelm
parents: 28700
diff changeset
     7
HOL setup for the Metis prover.
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
     8
*)
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
     9
44651
5d6a11e166cf renamed "Metis_Tactics" to "Metis_Tactic", now that there is only one Metis tactic ("metisFT" is legacy)
blanchet
parents: 44634
diff changeset
    10
signature METIS_TACTIC =
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    11
sig
43050
59284a13abc4 support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents: 43034
diff changeset
    12
  val metisN : string
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    13
  val full_typesN : string
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    14
  val partial_typesN : string
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    15
  val no_typesN : string
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    16
  val really_full_type_enc : string
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    17
  val full_type_enc : string
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    18
  val partial_type_enc : string
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    19
  val no_type_enc : string
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
    20
  val full_type_syss : string list
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
    21
  val partial_type_syss : string list
39979
b13515940b53 added "trace_meson" configuration option, replacing old-fashioned reference
blanchet
parents: 39978
diff changeset
    22
  val trace : bool Config.T
40665
1a65f0c74827 added "verbose" option to Metis to shut up its warnings if necessary
blanchet
parents: 40262
diff changeset
    23
  val verbose : bool Config.T
39891
8e12f1956fcd "meson_new_skolemizer" -> "metis_new_skolemizer" option (since Meson doesn't support the new skolemizer (yet))
blanchet
parents: 39890
diff changeset
    24
  val new_skolemizer : bool Config.T
44934
blanchet
parents: 44768
diff changeset
    25
  val type_has_top_sort : typ -> bool
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
    26
  val metis_tac : string list -> Proof.context -> thm list -> int -> tactic
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    27
  val setup : theory -> theory
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    28
end
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    29
44651
5d6a11e166cf renamed "Metis_Tactics" to "Metis_Tactic", now that there is only one Metis tactic ("metisFT" is legacy)
blanchet
parents: 44634
diff changeset
    30
structure Metis_Tactic : METIS_TACTIC =
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    31
struct
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    32
43085
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43050
diff changeset
    33
open ATP_Translate
39494
bf7dd4902321 rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents: 39450
diff changeset
    34
open Metis_Translate
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    35
open Metis_Reconstruct
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
    36
43545
1cf2256f1b07 produce string constant directly;
wenzelm
parents: 43303
diff changeset
    37
val metisN = "metis"
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    38
43205
23b81469499f more preparations towards hijacking Metis
blanchet
parents: 43204
diff changeset
    39
val full_typesN = "full_types"
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    40
val partial_typesN = "partial_types"
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    41
val no_typesN = "no_types"
43050
59284a13abc4 support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents: 43034
diff changeset
    42
44768
a7bc1bdb8bb4 rationalize uniform encodings
blanchet
parents: 44651
diff changeset
    43
val really_full_type_enc = "mono_tags"
a7bc1bdb8bb4 rationalize uniform encodings
blanchet
parents: 44651
diff changeset
    44
val full_type_enc = "poly_guards_query"
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    45
val partial_type_enc = "poly_args"
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    46
val no_type_enc = "erased"
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    47
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    48
val full_type_syss = [full_type_enc, really_full_type_enc]
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    49
val partial_type_syss = partial_type_enc :: full_type_syss
43211
77c432fe28ff enable new Metis
blanchet
parents: 43206
diff changeset
    50
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    51
val type_enc_aliases =
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
    52
  [(full_typesN, full_type_syss),
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
    53
   (partial_typesN, partial_type_syss),
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    54
   (no_typesN, [no_type_enc])]
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
    55
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    56
fun method_call_for_type_enc type_syss =
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    57
  metisN ^ " (" ^
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
    58
  (case AList.find (op =) type_enc_aliases type_syss of
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
    59
     [alias] => alias
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
    60
   | _ => hd type_syss) ^ ")"
43205
23b81469499f more preparations towards hijacking Metis
blanchet
parents: 43204
diff changeset
    61
43089
c2ec08b0d217 added "metisX" syntax (temporary)
blanchet
parents: 43085
diff changeset
    62
val new_skolemizer =
c2ec08b0d217 added "metisX" syntax (temporary)
blanchet
parents: 43085
diff changeset
    63
  Attrib.setup_config_bool @{binding metis_new_skolemizer} (K false)
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    64
43134
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
    65
(* Designed to work also with monomorphic instances of polymorphic theorems. *)
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
    66
fun have_common_thm ths1 ths2 =
43301
8d7fc4a5b502 removed needless function that duplicated standard functionality, with a little unnecessary twist
blanchet
parents: 43299
diff changeset
    67
  exists (member (Term.aconv_untyped o pairself prop_of) ths1)
43134
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
    68
         (map Meson.make_meta_clause ths2)
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
    69
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
    70
(*Determining which axiom clauses are actually used*)
39419
c9accfd621a5 "Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents: 39376
diff changeset
    71
fun used_axioms axioms (th, Metis_Proof.Axiom _) = SOME (lookth axioms th)
43128
a19826080596 tuned names
blanchet
parents: 43103
diff changeset
    72
  | used_axioms _ _ = NONE
24855
161eb8381b49 metis method: used theorems
paulson
parents: 24827
diff changeset
    73
43129
4301f1c123d6 support lightweight tags in new Metis
blanchet
parents: 43128
diff changeset
    74
(* Lightweight predicate type information comes in two flavors, "t = t'" and
4301f1c123d6 support lightweight tags in new Metis
blanchet
parents: 43128
diff changeset
    75
   "t => t'", where "t" and "t'" are the same term modulo type tags.
4301f1c123d6 support lightweight tags in new Metis
blanchet
parents: 43128
diff changeset
    76
   In Isabelle, type tags are stripped away, so we are left with "t = t" or
43159
29b55f292e0b added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents: 43136
diff changeset
    77
   "t => t". Type tag idempotence is also handled this way. *)
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
    78
fun reflexive_or_trivial_from_metis ctxt type_enc sym_tab concealed mth =
43136
cf5cda219058 handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents: 43135
diff changeset
    79
  let val thy = Proof_Context.theory_of ctxt in
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
    80
    case hol_clause_from_metis ctxt type_enc sym_tab concealed mth of
43136
cf5cda219058 handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents: 43135
diff changeset
    81
      Const (@{const_name HOL.eq}, _) $ _ $ t =>
44408
30ea62ab4f16 made reconstruction of type tag equalities "\?x = \?x" reliable
blanchet
parents: 44402
diff changeset
    82
      let
30ea62ab4f16 made reconstruction of type tag equalities "\?x = \?x" reliable
blanchet
parents: 44402
diff changeset
    83
        val ct = cterm_of thy t
30ea62ab4f16 made reconstruction of type tag equalities "\?x = \?x" reliable
blanchet
parents: 44402
diff changeset
    84
        val cT = ctyp_of_term ct
30ea62ab4f16 made reconstruction of type tag equalities "\?x = \?x" reliable
blanchet
parents: 44402
diff changeset
    85
      in refl |> Drule.instantiate' [SOME cT] [SOME ct] end
43136
cf5cda219058 handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents: 43135
diff changeset
    86
    | Const (@{const_name disj}, _) $ t1 $ t2 =>
cf5cda219058 handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents: 43135
diff changeset
    87
      (if can HOLogic.dest_not t1 then t2 else t1)
cf5cda219058 handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents: 43135
diff changeset
    88
      |> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial
45511
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    89
    | _ => raise Fail "expected reflexive or trivial clause"
43136
cf5cda219058 handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents: 43135
diff changeset
    90
  end
43129
4301f1c123d6 support lightweight tags in new Metis
blanchet
parents: 43128
diff changeset
    91
  |> Meson.make_meta_clause
4301f1c123d6 support lightweight tags in new Metis
blanchet
parents: 43128
diff changeset
    92
45511
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    93
fun lambda_lifted_from_metis ctxt type_enc sym_tab concealed mth =
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    94
  let
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    95
    val thy = Proof_Context.theory_of ctxt
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    96
    val tac = rewrite_goals_tac @{thms lambda_def_raw} THEN rtac refl 1
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    97
    val t = hol_clause_from_metis ctxt type_enc sym_tab concealed mth
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    98
    val ct = cterm_of thy (HOLogic.mk_Trueprop t)
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
    99
  in Goal.prove_internal [] ct (K tac) |> Meson.make_meta_clause end
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   100
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   101
fun introduce_lambda_wrappers_in_theorem ctxt th =
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   102
  if Meson_Clausify.is_quasi_lambda_free (prop_of th) then
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   103
    th
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   104
  else
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   105
    let
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   106
      fun conv wrap ctxt ct =
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   107
        if Meson_Clausify.is_quasi_lambda_free (term_of ct) then
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   108
          Thm.reflexive ct
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   109
        else case term_of ct of
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   110
          Abs _ =>
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   111
          Conv.abs_conv (conv false o snd) ctxt ct
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   112
          |> wrap ? (fn th => th RS @{thm Metis.eq_lambdaI})
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   113
        | _ => Conv.comb_conv (conv true ctxt) ct
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   114
      val eqth = conv true ctxt (cprop_of th)
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   115
    in Thm.equal_elim eqth th end
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   116
44588
blanchet
parents: 44494
diff changeset
   117
val clause_params =
39450
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   118
  {ordering = Metis_KnuthBendixOrder.default,
44492
a330c0608da8 avoid using ":" for anything but systematic type tag annotations, because Hurd's Metis gives it that special semantics
blanchet
parents: 44411
diff changeset
   119
   orderLiterals = Metis_Clause.UnsignedLiteralOrder,
39450
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   120
   orderTerms = true}
44588
blanchet
parents: 44494
diff changeset
   121
val active_params =
blanchet
parents: 44494
diff changeset
   122
  {clause = clause_params,
39450
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   123
   prefactor = #prefactor Metis_Active.default,
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   124
   postfactor = #postfactor Metis_Active.default}
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   125
val waiting_params =
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   126
  {symbolsWeight = 1.0,
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   127
   variablesWeight = 0.0,
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   128
   literalsWeight = 0.0,
7e9879fbb7c5 supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents: 39419
diff changeset
   129
   models = []}
44588
blanchet
parents: 44494
diff changeset
   130
val resolution_params = {active = active_params, waiting = waiting_params}
37573
7f987e8582a7 fewer dependencies
blanchet
parents: 37572
diff changeset
   131
37516
c81c86bfc18a have "metis" method and "metis_tac" fall back on "metisFT" upon failure, following a suggestion by Larry
blanchet
parents: 37509
diff changeset
   132
(* Main function to start Metis proof and reconstruction *)
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   133
fun FOL_SOLVE (type_enc :: fallback_type_syss) lambda_trans ctxt cls ths0 =
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42341
diff changeset
   134
  let val thy = Proof_Context.theory_of ctxt
39901
75d792edf634 make "cnf_axiom" work (after a fashion) in the absence of the axiom of choice
blanchet
parents: 39899
diff changeset
   135
      val new_skolemizer =
39950
f3c4849868b8 got rid of overkill "meson_choice" attribute;
blanchet
parents: 39946
diff changeset
   136
        Config.get ctxt new_skolemizer orelse null (Meson.choice_theorems thy)
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
   137
      val th_cls_pairs =
39894
35ae5cf8c96a encode number of skolem assumptions in them, for more efficient retrieval later
blanchet
parents: 39892
diff changeset
   138
        map2 (fn j => fn th =>
35ae5cf8c96a encode number of skolem assumptions in them, for more efficient retrieval later
blanchet
parents: 39892
diff changeset
   139
                (Thm.get_name_hint th,
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   140
                 Meson_Clausify.cnf_axiom ctxt new_skolemizer
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   141
                                          (lambda_trans = combinatorsN) j th))
39894
35ae5cf8c96a encode number of skolem assumptions in them, for more efficient retrieval later
blanchet
parents: 39892
diff changeset
   142
             (0 upto length ths0 - 1) ths0
43092
93ec303e1917 more work on new metis that exploits the powerful new type encodings
blanchet
parents: 43091
diff changeset
   143
      val ths = maps (snd o snd) th_cls_pairs
39938
0a2091f86eb4 fixed two bugs in new skolemizer: instantiations now take types into consideration, and rotate_tac is given the proper offset
blanchet
parents: 39937
diff changeset
   144
      val dischargers = map (fst o snd) th_cls_pairs
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   145
      val _ = trace_msg ctxt (fn () => "FOL_SOLVE: CONJECTURE CLAUSES")
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   146
      val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) cls
44411
e3629929b171 change Metis's default settings if type information axioms are generated
blanchet
parents: 44408
diff changeset
   147
      val _ = trace_msg ctxt (fn () => "type_enc = " ^ type_enc)
44634
2ac4ff398bc3 make "sound" sound and "unsound" more sound, based on evaluation
blanchet
parents: 44588
diff changeset
   148
      val type_enc = type_enc_from_string Sound type_enc
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   149
      val (sym_tab, axioms, concealed) =
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   150
        prepare_metis_problem ctxt type_enc lambda_trans cls ths
43159
29b55f292e0b added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents: 43136
diff changeset
   151
      fun get_isa_thm mth Isa_Reflexive_or_Trivial =
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   152
          reflexive_or_trivial_from_metis ctxt type_enc sym_tab concealed mth
45511
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   153
        | get_isa_thm mth Isa_Lambda_Lifted =
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   154
          lambda_lifted_from_metis ctxt type_enc sym_tab concealed mth
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   155
        | get_isa_thm _ (Isa_Raw ith) =
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   156
          ith |> lambda_trans = liftingN
9b0f8ca4388e continued implementation of lambda-lifting in Metis
blanchet
parents: 45508
diff changeset
   157
                 ? introduce_lambda_wrappers_in_theorem ctxt
43159
29b55f292e0b added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents: 43136
diff changeset
   158
      val axioms = axioms |> map (fn (mth, ith) => (mth, get_isa_thm mth ith))
45042
89341b897412 better type reconstruction -- prevents ill-instantiations in proof replay
blanchet
parents: 44934
diff changeset
   159
      val _ = trace_msg ctxt (fn () => "THEOREM CLAUSES")
89341b897412 better type reconstruction -- prevents ill-instantiations in proof replay
blanchet
parents: 44934
diff changeset
   160
      val _ = app (fn (_, th) => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) axioms
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   161
      val _ = trace_msg ctxt (fn () => "CLAUSES GIVEN TO METIS")
43159
29b55f292e0b added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents: 43136
diff changeset
   162
      val thms = axioms |> map fst
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   163
      val _ = app (fn th => trace_msg ctxt (fn () => Metis_Thm.toString th)) thms
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   164
      val _ = trace_msg ctxt (fn () => "START METIS PROVE PROCESS")
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   165
  in
43159
29b55f292e0b added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents: 43136
diff changeset
   166
      case filter (fn t => prop_of t aconv @{prop False}) cls of
29b55f292e0b added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents: 43136
diff changeset
   167
          false_th :: _ => [false_th RS @{thm FalseE}]
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   168
        | [] =>
44588
blanchet
parents: 44494
diff changeset
   169
      case Metis_Resolution.new resolution_params
44411
e3629929b171 change Metis's default settings if type information axioms are generated
blanchet
parents: 44408
diff changeset
   170
                                {axioms = thms, conjecture = []}
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   171
           |> Metis_Resolution.loop of
39419
c9accfd621a5 "Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents: 39376
diff changeset
   172
          Metis_Resolution.Contradiction mth =>
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   173
            let val _ = trace_msg ctxt (fn () => "METIS RECONSTRUCTION START: " ^
39419
c9accfd621a5 "Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents: 39376
diff changeset
   174
                          Metis_Thm.toString mth)
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   175
                val ctxt' = fold Variable.declare_constraints (map prop_of cls) ctxt
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   176
                             (*add constraints arising from converting goal to clause form*)
39419
c9accfd621a5 "Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents: 39376
diff changeset
   177
                val proof = Metis_Proof.proof mth
43094
269300fb83d0 more work on new Metis
blanchet
parents: 43092
diff changeset
   178
                val result =
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   179
                  axioms
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   180
                  |> fold (replay_one_inference ctxt' type_enc concealed sym_tab) proof
43134
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   181
                val used = map_filter (used_axioms axioms) proof
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   182
                val _ = trace_msg ctxt (fn () => "METIS COMPLETED...clauses actually used:")
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   183
                val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) used
43134
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   184
                val names = th_cls_pairs |> map fst
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   185
                val used_names =
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   186
                  th_cls_pairs
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   187
                  |> map_filter (fn (name, (_, cls)) =>
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   188
                                    if have_common_thm used cls then SOME name
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   189
                                    else NONE)
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   190
                val unused_names = names |> subtract (op =) used_names
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   191
            in
39497
fa16349939b7 complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents: 39494
diff changeset
   192
                if not (null cls) andalso not (have_common_thm used cls) then
42650
552eae49f97d reintroduce this idea of running "metisFT" after a failed "metis" -- I took it out in e85ce10cef1a because I couldn't think of a reasonable use case, but now that ATPs use sound encodings and include dangerous facts (e.g. True_or_False) it makes more sense than ever to run "metisFT" after "metis"
blanchet
parents: 42616
diff changeset
   193
                  verbose_warning ctxt "The assumptions are inconsistent"
36383
6adf1068ac0f better error reporting;
blanchet
parents: 36230
diff changeset
   194
                else
6adf1068ac0f better error reporting;
blanchet
parents: 36230
diff changeset
   195
                  ();
43134
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   196
                if not (null unused_names) then
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   197
                  "Unused theorems: " ^ commas_quote unused_names
0c82e00ba63e make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents: 43133
diff changeset
   198
                  |> verbose_warning ctxt
36230
43d10a494c91 added warning about inconsistent context to Metis;
blanchet
parents: 36170
diff changeset
   199
                else
43d10a494c91 added warning about inconsistent context to Metis;
blanchet
parents: 36170
diff changeset
   200
                  ();
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   201
                case result of
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   202
                    (_,ith)::_ =>
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   203
                        (trace_msg ctxt (fn () => "Success: " ^ Display.string_of_thm ctxt ith);
39887
74939e2afb95 second step in introducing the new Skolemizer -- notably, added procedure for discharging Skolem assumptions
blanchet
parents: 39886
diff changeset
   204
                         [discharge_skolem_premises ctxt dischargers ith])
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   205
                  | _ => (trace_msg ctxt (fn () => "Metis: No result"); [])
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   206
            end
39419
c9accfd621a5 "Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents: 39376
diff changeset
   207
        | Metis_Resolution.Satisfiable _ =>
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   208
            (trace_msg ctxt (fn () => "Metis: No first-order proof with the lemmas supplied");
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   209
             if null fallback_type_syss then
43034
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   210
               ()
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   211
             else
42650
552eae49f97d reintroduce this idea of running "metisFT" after a failed "metis" -- I took it out in e85ce10cef1a because I couldn't think of a reasonable use case, but now that ATPs use sound encodings and include dangerous facts (e.g. True_or_False) it makes more sense than ever to run "metisFT" after "metis"
blanchet
parents: 42616
diff changeset
   212
               raise METIS ("FOL_SOLVE",
43034
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   213
                            "No first-order proof with the lemmas supplied");
38097
5e4ad2df09f3 revert exception throwing in FOL_SOLVE, since they're not caught anyway
blanchet
parents: 38028
diff changeset
   214
             [])
42733
01ef1c3d9cfd more robust exception handling in Metis (also works if there are several subgoals)
blanchet
parents: 42650
diff changeset
   215
  end
01ef1c3d9cfd more robust exception handling in Metis (also works if there are several subgoals)
blanchet
parents: 42650
diff changeset
   216
  handle METIS (loc, msg) =>
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   217
         case fallback_type_syss of
43034
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   218
           [] => error ("Failed to replay Metis proof in Isabelle." ^
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   219
                        (if Config.get ctxt verbose then "\n" ^ loc ^ ": " ^ msg
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   220
                         else ""))
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   221
         | _ =>
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   222
           (verbose_warning ctxt
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   223
                ("Falling back on " ^
43626
a867ebb12209 renamed "type_sys" to "type_enc", which is more accurate
blanchet
parents: 43545
diff changeset
   224
                 quote (method_call_for_type_enc fallback_type_syss) ^ "...");
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   225
            FOL_SOLVE fallback_type_syss lambda_trans ctxt cls ths0)
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
   226
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   227
fun neg_clausify ctxt combinators =
38028
22dcaec5fa77 minor refactoring
blanchet
parents: 38027
diff changeset
   228
  single
43964
9338aa218f09 thread proper context through, to make sure that "using [[meson_max_clauses = 200]]" is not ignored when clausifying the conjecture
blanchet
parents: 43963
diff changeset
   229
  #> Meson.make_clauses_unsorted ctxt
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   230
  #> combinators ? map Meson_Clausify.introduce_combinators_in_theorem
38028
22dcaec5fa77 minor refactoring
blanchet
parents: 38027
diff changeset
   231
  #> Meson.finish_cnf
22dcaec5fa77 minor refactoring
blanchet
parents: 38027
diff changeset
   232
39269
c2795d8a2461 use definitional CNF for the goal if at least one of the premisses would lead to too many clauses in Meson
blanchet
parents: 39267
diff changeset
   233
fun preskolem_tac ctxt st0 =
c2795d8a2461 use definitional CNF for the goal if at least one of the premisses would lead to too many clauses in Meson
blanchet
parents: 39267
diff changeset
   234
  (if exists (Meson.has_too_many_clauses ctxt)
c2795d8a2461 use definitional CNF for the goal if at least one of the premisses would lead to too many clauses in Meson
blanchet
parents: 39267
diff changeset
   235
             (Logic.prems_of_goal (prop_of st0) 1) then
42336
d63d43e85879 improve definitional CNF on goal by moving "not" past the quantifiers
blanchet
parents: 40665
diff changeset
   236
     Simplifier.full_simp_tac (Meson_Clausify.ss_only @{thms not_all not_ex}) 1
d63d43e85879 improve definitional CNF on goal by moving "not" past the quantifiers
blanchet
parents: 40665
diff changeset
   237
     THEN cnf.cnfx_rewrite_tac ctxt 1
39269
c2795d8a2461 use definitional CNF for the goal if at least one of the premisses would lead to too many clauses in Meson
blanchet
parents: 39267
diff changeset
   238
   else
c2795d8a2461 use definitional CNF for the goal if at least one of the premisses would lead to too many clauses in Meson
blanchet
parents: 39267
diff changeset
   239
     all_tac) st0
c2795d8a2461 use definitional CNF for the goal if at least one of the premisses would lead to too many clauses in Meson
blanchet
parents: 39267
diff changeset
   240
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38632
diff changeset
   241
val type_has_top_sort =
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38632
diff changeset
   242
  exists_subtype (fn TFree (_, []) => true | TVar (_, []) => true | _ => false)
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38632
diff changeset
   243
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   244
fun generic_metis_tac type_syss ctxt ths i st0 =
37926
e6ff246c0cdb renamings + only need second component of name pool to reconstruct proofs
blanchet
parents: 37925
diff changeset
   245
  let
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   246
    val lambda_trans = Config.get ctxt lambda_translation
39978
11bfb7e7cc86 added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents: 39964
diff changeset
   247
    val _ = trace_msg ctxt (fn () =>
43194
ef3ff8856245 fixed type helper indices in new Metis
blanchet
parents: 43184
diff changeset
   248
        "Metis called with theorems\n" ^
43034
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   249
        cat_lines (map (Display.string_of_thm ctxt) ths))
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   250
    fun tac clause =
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   251
      resolve_tac (FOL_SOLVE type_syss lambda_trans ctxt clause ths) 1
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   252
  in
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37625
diff changeset
   253
    if exists_type type_has_top_sort (prop_of st0) then
43299
f78d5f0818a0 be a bit more liberal with respect to the universal sort -- it sometimes help
blanchet
parents: 43298
diff changeset
   254
      verbose_warning ctxt "Proof state contains the universal sort {}"
35568
8fbbfc39508f renamed type_has_empty_sort to type_has_topsort -- {} is the full universal sort;
wenzelm
parents: 34087
diff changeset
   255
    else
43299
f78d5f0818a0 be a bit more liberal with respect to the universal sort -- it sometimes help
blanchet
parents: 43298
diff changeset
   256
      ();
45508
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   257
    Meson.MESON (preskolem_tac ctxt)
b216dc1b3630 started implementing lambda-lifting in Metis
blanchet
parents: 45042
diff changeset
   258
        (maps (neg_clausify ctxt (lambda_trans = combinatorsN))) tac ctxt i st0
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   259
  end
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
   260
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   261
fun metis_tac [] = generic_metis_tac partial_type_syss
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   262
  | metis_tac type_syss = generic_metis_tac type_syss
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
   263
38632
9cde57cdd0e3 treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents: 38614
diff changeset
   264
(* Whenever "X" has schematic type variables, we treat "using X by metis" as
43100
49347c6354b5 parse optional type system specification
blanchet
parents: 43099
diff changeset
   265
   "by (metis X)" to prevent "Subgoal.FOCUS" from freezing the type variables.
38632
9cde57cdd0e3 treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents: 38614
diff changeset
   266
   We don't do it for nonschematic facts "X" because this breaks a few proofs
9cde57cdd0e3 treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents: 38614
diff changeset
   267
   (in the rare and subtle case where a proof relied on extensionality not being
38994
7c655a491bce fiddled with fudge factor (based on Mirabelle)
blanchet
parents: 38864
diff changeset
   268
   applied) and brings few benefits. *)
38632
9cde57cdd0e3 treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents: 38614
diff changeset
   269
val has_tvar =
9cde57cdd0e3 treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents: 38614
diff changeset
   270
  exists_type (exists_subtype (fn TVar _ => true | _ => false)) o prop_of
43034
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   271
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   272
fun method default_type_syss (override_type_syss, ths) ctxt facts =
43100
49347c6354b5 parse optional type system specification
blanchet
parents: 43099
diff changeset
   273
  let
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   274
    val _ =
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   275
      if default_type_syss = full_type_syss then
44052
00f0c8782a51 slightly more uniform messages;
wenzelm
parents: 43989
diff changeset
   276
        legacy_feature "Old \"metisFT\" method -- use \"metis (full_types)\" instead"
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   277
      else
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   278
        ()
43100
49347c6354b5 parse optional type system specification
blanchet
parents: 43099
diff changeset
   279
    val (schem_facts, nonschem_facts) = List.partition has_tvar facts
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   280
    val type_syss = override_type_syss |> the_default default_type_syss
43100
49347c6354b5 parse optional type system specification
blanchet
parents: 43099
diff changeset
   281
  in
43099
blanchet
parents: 43094
diff changeset
   282
    HEADGOAL (Method.insert_tac nonschem_facts THEN'
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   283
              CHANGED_PROP
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   284
              o generic_metis_tac type_syss ctxt (schem_facts @ ths))
43099
blanchet
parents: 43094
diff changeset
   285
  end
43100
49347c6354b5 parse optional type system specification
blanchet
parents: 43099
diff changeset
   286
43235
blanchet
parents: 43228
diff changeset
   287
fun setup_method (binding, type_syss) =
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   288
  ((Args.parens (Scan.repeat Parse.short_ident)
43963
blanchet
parents: 43825
diff changeset
   289
    >> maps (fn s => AList.lookup (op =) type_enc_aliases s |> the_default [s]))
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   290
    |> Scan.option |> Scan.lift)
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   291
  -- Attrib.thms >> (METHOD oo method type_syss)
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   292
  |> Method.setup binding
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
   293
32956
c39860141415 tuned white space;
wenzelm
parents: 32955
diff changeset
   294
val setup =
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   295
  [((@{binding metis}, partial_type_syss),
43228
2ed2f092e990 obsoleted "metisFT", and added "no_types" version of Metis as fallback to Sledgehammer after noticing how useful it can be
blanchet
parents: 43212
diff changeset
   296
    "Metis for FOL and HOL problems"),
43303
c4ea897a5326 added a really fully typed translation as a fallback for Metis, in rare cases where Metis correctly proves a theorem but has type-unsound steps in it (which is likelier to happen with some of the lighter translations)
blanchet
parents: 43301
diff changeset
   297
   ((@{binding metisFT}, full_type_syss),
43212
050a03afe024 Metis code cleanup
blanchet
parents: 43211
diff changeset
   298
    "Metis for FOL/HOL problems with fully-typed translation")]
43034
18259246abb5 try both "metis" and (on failure) "metisFT" in replay
blanchet
parents: 42847
diff changeset
   299
  |> fold (uncurry setup_method)
23442
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
   300
028e39e5e8f3 The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff changeset
   301
end;