author | blanchet |
Mon, 06 Jun 2011 20:36:35 +0200 | |
changeset 43184 | b16693484c5d |
parent 43169 | b02749a3b0ac |
child 43194 | ef3ff8856245 |
permissions | -rw-r--r-- |
39958 | 1 |
(* Title: HOL/Tools/Metis/metis_tactics.ML |
38027 | 2 |
Author: Kong W. Susanto, Cambridge University Computer Laboratory |
3 |
Author: Lawrence C. Paulson, Cambridge University Computer Laboratory |
|
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 | 6 |
|
29266 | 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 |
|
35826 | 10 |
signature METIS_TACTICS = |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
11 |
sig |
43102 | 12 |
type type_sys = ATP_Translate.type_sys |
43100 | 13 |
|
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
14 |
val metisN : string |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
15 |
val metisF_N : string |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
16 |
val metisFT_N : string |
43089 | 17 |
val metisX_N : string |
39979
b13515940b53
added "trace_meson" configuration option, replacing old-fashioned reference
blanchet
parents:
39978
diff
changeset
|
18 |
val trace : bool Config.T |
40665
1a65f0c74827
added "verbose" option to Metis to shut up its warnings if necessary
blanchet
parents:
40262
diff
changeset
|
19 |
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
|
20 |
val new_skolemizer : bool Config.T |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
21 |
val metis_tac : Proof.context -> thm list -> int -> tactic |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
22 |
val metisF_tac : Proof.context -> thm list -> int -> tactic |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
23 |
val metisFT_tac : Proof.context -> thm list -> int -> tactic |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
24 |
val metisHO_tac : Proof.context -> thm list -> int -> tactic |
43102 | 25 |
val metisX_tac : Proof.context -> type_sys option -> thm list -> int -> tactic |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
26 |
val setup : theory -> theory |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
27 |
end |
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
28 |
|
35826 | 29 |
structure Metis_Tactics : METIS_TACTICS = |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
30 |
struct |
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
31 |
|
43085
0a2f5b86bdd7
first step in sharing more code between ATP and Metis translation
blanchet
parents:
43050
diff
changeset
|
32 |
open ATP_Translate |
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39450
diff
changeset
|
33 |
open Metis_Translate |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
34 |
open Metis_Reconstruct |
35826 | 35 |
|
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
36 |
fun method_binding_for_mode HO = @{binding metis} |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
37 |
| method_binding_for_mode FO = @{binding metisF} |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
38 |
| method_binding_for_mode FT = @{binding metisFT} |
43103 | 39 |
| method_binding_for_mode MX = @{binding metisX} |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
40 |
|
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
41 |
val metisN = Binding.qualified_name_of (method_binding_for_mode HO) |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
42 |
val metisF_N = Binding.qualified_name_of (method_binding_for_mode FO) |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
43 |
val metisFT_N = Binding.qualified_name_of (method_binding_for_mode FT) |
43103 | 44 |
val metisX_N = Binding.qualified_name_of (method_binding_for_mode MX) |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
45 |
|
43089 | 46 |
val new_skolemizer = |
47 |
Attrib.setup_config_bool @{binding metis_new_skolemizer} (K false) |
|
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
48 |
|
43134
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
49 |
(* 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
|
50 |
fun have_common_thm ths1 ths2 = |
43134
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
51 |
exists (member (untyped_aconv o pairself prop_of) ths1) |
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
52 |
(map Meson.make_meta_clause ths2) |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
53 |
|
32956 | 54 |
(*Determining which axiom clauses are actually used*) |
39419
c9accfd621a5
"Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents:
39376
diff
changeset
|
55 |
fun used_axioms axioms (th, Metis_Proof.Axiom _) = SOME (lookth axioms th) |
43128 | 56 |
| used_axioms _ _ = NONE |
24855 | 57 |
|
43129 | 58 |
(* Lightweight predicate type information comes in two flavors, "t = t'" and |
59 |
"t => t'", where "t" and "t'" are the same term modulo type tags. |
|
60 |
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
|
61 |
"t => t". Type tag idempotence is also handled this way. *) |
43184 | 62 |
fun reflexive_or_trivial_from_metis ctxt sym_tab old_skolems mth = |
43136
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
63 |
let val thy = Proof_Context.theory_of ctxt in |
43184 | 64 |
case hol_clause_from_metis ctxt sym_tab old_skolems mth of |
43136
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
65 |
Const (@{const_name HOL.eq}, _) $ _ $ t => |
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
66 |
t |> cterm_of thy |> Thm.reflexive RS @{thm meta_eq_to_obj_eq} |
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
67 |
| 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
|
68 |
(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
|
69 |
|> HOLogic.mk_Trueprop |> cterm_of thy |> Thm.trivial |
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
70 |
| _ => raise Fail "unexpected tags sym clause" |
cf5cda219058
handle lightweight tags sym theorems gracefully in the presence of TVars with interesting type classes
blanchet
parents:
43135
diff
changeset
|
71 |
end |
43129 | 72 |
|> Meson.make_meta_clause |
73 |
||
39450
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
74 |
val clause_params = |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
75 |
{ordering = Metis_KnuthBendixOrder.default, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
76 |
orderLiterals = Metis_Clause.UnsignedLiteralOrder, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
77 |
orderTerms = true} |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
78 |
val active_params = |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
79 |
{clause = clause_params, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
80 |
prefactor = #prefactor Metis_Active.default, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
81 |
postfactor = #postfactor Metis_Active.default} |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
82 |
val waiting_params = |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
83 |
{symbolsWeight = 1.0, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
84 |
variablesWeight = 0.0, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
85 |
literalsWeight = 0.0, |
7e9879fbb7c5
supply the Metis parameter defaults as argument, instead of patching the Metis sources;
blanchet
parents:
39419
diff
changeset
|
86 |
models = []} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
87 |
val resolution_params = {active = active_params, waiting = waiting_params} |
37573 | 88 |
|
37516
c81c86bfc18a
have "metis" method and "metis_tac" fall back on "metisFT" upon failure, following a suggestion by Larry
blanchet
parents:
37509
diff
changeset
|
89 |
(* Main function to start Metis proof and reconstruction *) |
43100 | 90 |
fun FOL_SOLVE type_sys (mode :: fallback_modes) ctxt cls ths0 = |
42361 | 91 |
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
|
92 |
val new_skolemizer = |
39950 | 93 |
Config.get ctxt new_skolemizer orelse null (Meson.choice_theorems thy) |
35826 | 94 |
val th_cls_pairs = |
39894
35ae5cf8c96a
encode number of skolem assumptions in them, for more efficient retrieval later
blanchet
parents:
39892
diff
changeset
|
95 |
map2 (fn j => fn th => |
35ae5cf8c96a
encode number of skolem assumptions in them, for more efficient retrieval later
blanchet
parents:
39892
diff
changeset
|
96 |
(Thm.get_name_hint th, |
39901
75d792edf634
make "cnf_axiom" work (after a fashion) in the absence of the axiom of choice
blanchet
parents:
39899
diff
changeset
|
97 |
Meson_Clausify.cnf_axiom ctxt new_skolemizer j th)) |
39894
35ae5cf8c96a
encode number of skolem assumptions in them, for more efficient retrieval later
blanchet
parents:
39892
diff
changeset
|
98 |
(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
|
99 |
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
|
100 |
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
|
101 |
val _ = trace_msg ctxt (fn () => "FOL_SOLVE: CONJECTURE CLAUSES") |
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
102 |
val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) cls |
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
103 |
val _ = trace_msg ctxt (fn () => "THEOREM CLAUSES") |
43092
93ec303e1917
more work on new metis that exploits the powerful new type encodings
blanchet
parents:
43091
diff
changeset
|
104 |
val _ = app (fn th => trace_msg ctxt (fn () => Display.string_of_thm ctxt th)) ths |
43094 | 105 |
val (mode, sym_tab, {axioms, old_skolems, ...}) = |
43100 | 106 |
prepare_metis_problem ctxt mode type_sys cls ths |
43159
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43136
diff
changeset
|
107 |
fun get_isa_thm mth Isa_Reflexive_or_Trivial = |
43184 | 108 |
reflexive_or_trivial_from_metis ctxt sym_tab old_skolems mth |
43159
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43136
diff
changeset
|
109 |
| get_isa_thm _ (Isa_Raw ith) = ith |
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43136
diff
changeset
|
110 |
val axioms = axioms |> map (fn (mth, ith) => (mth, get_isa_thm mth ith)) |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
111 |
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
|
112 |
val thms = axioms |> map fst |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
113 |
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
|
114 |
val _ = trace_msg ctxt (fn () => "mode = " ^ string_of_mode mode) |
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
115 |
val _ = trace_msg ctxt (fn () => "START METIS PROVE PROCESS") |
32956 | 116 |
in |
43159
29b55f292e0b
added support for helpers in new Metis, so far only for polymorphic type encodings
blanchet
parents:
43136
diff
changeset
|
117 |
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
|
118 |
false_th :: _ => [false_th RS @{thm FalseE}] |
32956 | 119 |
| [] => |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
120 |
case Metis_Resolution.new resolution_params {axioms = thms, conjecture = []} |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
121 |
|> Metis_Resolution.loop of |
39419
c9accfd621a5
"Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents:
39376
diff
changeset
|
122 |
Metis_Resolution.Contradiction mth => |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
123 |
let val _ = trace_msg ctxt (fn () => "METIS RECONSTRUCTION START: " ^ |
39419
c9accfd621a5
"Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents:
39376
diff
changeset
|
124 |
Metis_Thm.toString mth) |
32956 | 125 |
val ctxt' = fold Variable.declare_constraints (map prop_of cls) ctxt |
126 |
(*add constraints arising from converting goal to clause form*) |
|
39419
c9accfd621a5
"Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents:
39376
diff
changeset
|
127 |
val proof = Metis_Proof.proof mth |
43094 | 128 |
val result = |
129 |
fold (replay_one_inference ctxt' mode old_skolems sym_tab) |
|
130 |
proof axioms |
|
43134
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
131 |
val used = map_filter (used_axioms axioms) proof |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
val used_names = |
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
136 |
th_cls_pairs |
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
137 |
|> 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
|
138 |
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
|
139 |
else NONE) |
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
140 |
val unused_names = names |> subtract (op =) used_names |
32956 | 141 |
in |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
142 |
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
|
143 |
verbose_warning ctxt "The assumptions are inconsistent" |
36383 | 144 |
else |
145 |
(); |
|
43134
0c82e00ba63e
make sure no warnings are given for polymorphic facts where we use a monomorphic instance
blanchet
parents:
43133
diff
changeset
|
146 |
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
|
147 |
"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
|
148 |
|> verbose_warning ctxt |
36230
43d10a494c91
added warning about inconsistent context to Metis;
blanchet
parents:
36170
diff
changeset
|
149 |
else |
43d10a494c91
added warning about inconsistent context to Metis;
blanchet
parents:
36170
diff
changeset
|
150 |
(); |
32956 | 151 |
case result of |
152 |
(_,ith)::_ => |
|
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
153 |
(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
|
154 |
[discharge_skolem_premises ctxt dischargers ith]) |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
155 |
| _ => (trace_msg ctxt (fn () => "Metis: No result"); []) |
32956 | 156 |
end |
39419
c9accfd621a5
"Metis." -> "Metis_" to reflect change in "metis.ML"
blanchet
parents:
39376
diff
changeset
|
157 |
| Metis_Resolution.Satisfiable _ => |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
158 |
(trace_msg ctxt (fn () => "Metis: No first-order proof with the lemmas supplied"); |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
159 |
if null fallback_modes then |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
160 |
() |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
161 |
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
|
162 |
raise METIS ("FOL_SOLVE", |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
163 |
"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
|
164 |
[]) |
42733
01ef1c3d9cfd
more robust exception handling in Metis (also works if there are several subgoals)
blanchet
parents:
42650
diff
changeset
|
165 |
end |
01ef1c3d9cfd
more robust exception handling in Metis (also works if there are several subgoals)
blanchet
parents:
42650
diff
changeset
|
166 |
handle METIS (loc, msg) => |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
167 |
case fallback_modes of |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
168 |
[] => error ("Failed to replay Metis proof in Isabelle." ^ |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
169 |
(if Config.get ctxt verbose then "\n" ^ loc ^ ": " ^ msg |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
170 |
else "")) |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
171 |
| mode :: _ => |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
172 |
(verbose_warning ctxt |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
173 |
("Falling back on " ^ |
43050
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
174 |
quote (Binding.qualified_name_of |
59284a13abc4
support "metis" and "metisFT" as provers in the architecture, so they can be used for minimizing
blanchet
parents:
43034
diff
changeset
|
175 |
(method_binding_for_mode mode)) ^ "..."); |
43100 | 176 |
FOL_SOLVE type_sys fallback_modes ctxt cls ths0) |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
177 |
|
42847 | 178 |
val neg_clausify = |
38028 | 179 |
single |
180 |
#> Meson.make_clauses_unsorted |
|
39890 | 181 |
#> map Meson_Clausify.introduce_combinators_in_theorem |
38028 | 182 |
#> Meson.finish_cnf |
183 |
||
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
|
184 |
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
|
185 |
(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
|
186 |
(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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
|
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38632
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
|
43100 | 195 |
fun generic_metis_tac modes type_sys ctxt ths i st0 = |
37926
e6ff246c0cdb
renamings + only need second component of name pool to reconstruct proofs
blanchet
parents:
37925
diff
changeset
|
196 |
let |
39978
11bfb7e7cc86
added "trace_metis" configuration option, replacing old-fashioned references
blanchet
parents:
39964
diff
changeset
|
197 |
val _ = trace_msg ctxt (fn () => |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
198 |
"Metis called with theorems " ^ |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
199 |
cat_lines (map (Display.string_of_thm ctxt) ths)) |
43100 | 200 |
fun tac clause = resolve_tac (FOL_SOLVE type_sys modes ctxt clause ths) 1 |
32956 | 201 |
in |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37625
diff
changeset
|
202 |
if exists_type type_has_top_sort (prop_of st0) 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
|
203 |
(verbose_warning ctxt "Proof state contains the universal sort {}"; |
40665
1a65f0c74827
added "verbose" option to Metis to shut up its warnings if necessary
blanchet
parents:
40262
diff
changeset
|
204 |
Seq.empty) |
35568
8fbbfc39508f
renamed type_has_empty_sort to type_has_topsort -- {} is the full universal sort;
wenzelm
parents:
34087
diff
changeset
|
205 |
else |
43100 | 206 |
Meson.MESON (preskolem_tac ctxt) (maps neg_clausify) tac ctxt i st0 |
32956 | 207 |
end |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
208 |
|
43169
b02749a3b0ac
use "metisX" as fallback, since it's much faster than "metisFT"
blanchet
parents:
43160
diff
changeset
|
209 |
val metis_modes = [HO, MX] |
b02749a3b0ac
use "metisX" as fallback, since it's much faster than "metisFT"
blanchet
parents:
43160
diff
changeset
|
210 |
val metisF_modes = [FO, MX] |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
211 |
val metisFT_modes = [FT] |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
212 |
val metisHO_modes = [HO] |
43103 | 213 |
val metisX_modes = [MX] |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
214 |
|
43100 | 215 |
val metis_tac = generic_metis_tac metis_modes NONE |
216 |
val metisF_tac = generic_metis_tac metisF_modes NONE |
|
217 |
val metisFT_tac = generic_metis_tac metisFT_modes NONE |
|
218 |
val metisHO_tac = generic_metis_tac metisHO_modes NONE |
|
219 |
fun metisX_tac ctxt type_sys = generic_metis_tac metisX_modes type_sys ctxt |
|
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
220 |
|
38632
9cde57cdd0e3
treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents:
38614
diff
changeset
|
221 |
(* Whenever "X" has schematic type variables, we treat "using X by metis" as |
43100 | 222 |
"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
|
223 |
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
|
224 |
(in the rare and subtle case where a proof relied on extensionality not being |
38994 | 225 |
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
|
226 |
val has_tvar = |
9cde57cdd0e3
treat "using X by metis" (more or less) the same as "by (metis X)"
blanchet
parents:
38614
diff
changeset
|
227 |
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
|
228 |
|
43100 | 229 |
fun method modes (type_sys, ths) ctxt facts = |
230 |
let |
|
231 |
val (schem_facts, nonschem_facts) = List.partition has_tvar facts |
|
232 |
val type_sys = type_sys |> Option.map type_sys_from_string |
|
233 |
in |
|
43099 | 234 |
HEADGOAL (Method.insert_tac nonschem_facts THEN' |
43100 | 235 |
CHANGED_PROP |
236 |
o generic_metis_tac modes type_sys ctxt (schem_facts @ ths)) |
|
43099 | 237 |
end |
43100 | 238 |
|
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
239 |
fun setup_method (modes as mode :: _) = |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
240 |
Method.setup (method_binding_for_mode mode) |
43103 | 241 |
((if mode = MX then |
43100 | 242 |
Scan.lift (Scan.option (Args.parens Parse.short_ident)) |
243 |
else |
|
244 |
Scan.succeed NONE) |
|
245 |
-- Attrib.thms >> (METHOD oo method modes)) |
|
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
246 |
|
32956 | 247 |
val setup = |
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
248 |
[(metis_modes, "Metis for FOL and HOL problems"), |
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
249 |
(metisF_modes, "Metis for FOL problems"), |
43089 | 250 |
(metisFT_modes, "Metis for FOL/HOL problems with fully-typed translation"), |
251 |
(metisX_modes, "Metis for FOL and HOL problems (experimental)")] |
|
43034
18259246abb5
try both "metis" and (on failure) "metisFT" in replay
blanchet
parents:
42847
diff
changeset
|
252 |
|> fold (uncurry setup_method) |
23442
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
253 |
|
028e39e5e8f3
The Metis prover (slightly modified version from Larry);
wenzelm
parents:
diff
changeset
|
254 |
end; |