author | blanchet |
Mon, 23 Aug 2010 23:00:57 +0200 | |
changeset 38687 | 97509445c569 |
parent 38686 | 45eeee8d6b12 |
child 38688 | b2ae937a134b |
permissions | -rw-r--r-- |
35826 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_fact_filter.ML |
38027 | 2 |
Author: Jia Meng, Cambridge University Computer Laboratory and NICTA |
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents:
36227
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
33309 | 4 |
*) |
15452 | 5 |
|
35826 | 6 |
signature SLEDGEHAMMER_FACT_FILTER = |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
7 |
sig |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
8 |
type relevance_override = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
9 |
{add: Facts.ref list, |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
10 |
del: Facts.ref list, |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
11 |
only: bool} |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
12 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
13 |
val trace : bool Unsynchronized.ref |
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
14 |
val chained_prefix : string |
38617 | 15 |
val name_thms_pair_from_ref : |
16 |
Proof.context -> thm list -> Facts.ref -> string * thm list |
|
37347
635425a442e8
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents:
37345
diff
changeset
|
17 |
val relevant_facts : |
37580
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset
|
18 |
bool -> real -> real -> bool -> int -> bool -> relevance_override |
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37626
diff
changeset
|
19 |
-> Proof.context * (thm list * 'a) -> term list -> term |
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37626
diff
changeset
|
20 |
-> (string * thm) list |
15347 | 21 |
end; |
22 |
||
35826 | 23 |
structure Sledgehammer_Fact_Filter : SLEDGEHAMMER_FACT_FILTER = |
15347 | 24 |
struct |
25 |
||
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
26 |
open Sledgehammer_Util |
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
27 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
28 |
val trace = Unsynchronized.ref false |
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
29 |
fun trace_msg msg = if !trace then tracing (msg ()) else () |
35826 | 30 |
|
37580
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset
|
31 |
val respect_no_atp = true |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
32 |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
33 |
type relevance_override = |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
34 |
{add: Facts.ref list, |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
35 |
del: Facts.ref list, |
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
36 |
only: bool} |
21070 | 37 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
38 |
val sledgehammer_prefix = "Sledgehammer" ^ Long_Name.separator |
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
39 |
(* Used to label theorems chained into the goal. *) |
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
40 |
val chained_prefix = sledgehammer_prefix ^ "chained_" |
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
41 |
|
38617 | 42 |
fun name_thms_pair_from_ref ctxt chained_ths xref = |
43 |
let |
|
44 |
val ths = ProofContext.get_fact ctxt xref |
|
45 |
val name = Facts.string_of_ref xref |
|
46 |
|> forall (member Thm.eq_thm chained_ths) ths |
|
47 |
? prefix chained_prefix |
|
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
48 |
in (name, ths) end |
38617 | 49 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
50 |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
28065
diff
changeset
|
51 |
(***************************************************************) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
28065
diff
changeset
|
52 |
(* Relevance Filtering *) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
28065
diff
changeset
|
53 |
(***************************************************************) |
19194 | 54 |
|
24287 | 55 |
(*** constants with types ***) |
56 |
||
57 |
(*An abstraction of Isabelle types*) |
|
58 |
datatype const_typ = CTVar | CType of string * const_typ list |
|
59 |
||
60 |
(*Is the second type an instance of the first one?*) |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
61 |
fun match_type (CType(con1,args1)) (CType(con2,args2)) = |
24287 | 62 |
con1=con2 andalso match_types args1 args2 |
63 |
| match_type CTVar _ = true |
|
64 |
| match_type _ CTVar = false |
|
65 |
and match_types [] [] = true |
|
66 |
| match_types (a1::as1) (a2::as2) = match_type a1 a2 andalso match_types as1 as2; |
|
67 |
||
68 |
(*Is there a unifiable constant?*) |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
69 |
fun const_mem const_tab (c, c_typ) = |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
70 |
exists (match_types c_typ) (these (Symtab.lookup const_tab c)) |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
71 |
|
24287 | 72 |
(*Maps a "real" type to a const_typ*) |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
73 |
fun const_typ_of (Type (c,typs)) = CType (c, map const_typ_of typs) |
24287 | 74 |
| const_typ_of (TFree _) = CTVar |
75 |
| const_typ_of (TVar _) = CTVar |
|
76 |
||
77 |
(*Pairs a constant with the list of its type instantiations (using const_typ)*) |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
78 |
fun const_with_typ thy (c,typ) = |
38606
3003ddbd46d9
encode "fequal" reasoning rules in Metis problem, just as is done for Sledgehammer -- otherwise any proof that relies on "fequal" found by Sledgehammer can't be reconstructed
blanchet
parents:
38595
diff
changeset
|
79 |
let val tvars = Sign.const_typargs thy (c,typ) in |
3003ddbd46d9
encode "fequal" reasoning rules in Metis problem, just as is done for Sledgehammer -- otherwise any proof that relies on "fequal" found by Sledgehammer can't be reconstructed
blanchet
parents:
38595
diff
changeset
|
80 |
(c, map const_typ_of tvars) end |
3003ddbd46d9
encode "fequal" reasoning rules in Metis problem, just as is done for Sledgehammer -- otherwise any proof that relies on "fequal" found by Sledgehammer can't be reconstructed
blanchet
parents:
38595
diff
changeset
|
81 |
handle TYPE _ => (c, []) (*Variable (locale constant): monomorphic*) |
24287 | 82 |
|
83 |
(*Add a const/type pair to the table, but a [] entry means a standard connective, |
|
84 |
which we ignore.*) |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
85 |
fun add_const_to_table (c, ctyps) = |
37502 | 86 |
Symtab.map_default (c, [ctyps]) |
87 |
(fn [] => [] | ctypss => insert (op =) ctyps ctypss) |
|
24287 | 88 |
|
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
89 |
val fresh_prefix = "Sledgehammer.FRESH." |
37537 | 90 |
val flip = Option.map not |
38091 | 91 |
(* These are typically simplified away by "Meson.presimplify". *) |
38682 | 92 |
val boring_consts = |
93 |
[@{const_name False}, @{const_name True}, @{const_name If}, @{const_name Let}] |
|
37537 | 94 |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
95 |
fun get_consts thy pos ts = |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
96 |
let |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
97 |
(* We include free variables, as well as constants, to handle locales. For |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
98 |
each quantifiers that must necessarily be skolemized by the ATP, we |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
99 |
introduce a fresh constant to simulate the effect of Skolemization. *) |
37537 | 100 |
fun do_term t = |
101 |
case t of |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
102 |
Const x => add_const_to_table (const_with_typ thy x) |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
103 |
| Free (s, _) => add_const_to_table (s, []) |
37537 | 104 |
| t1 $ t2 => do_term t1 #> do_term t2 |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
105 |
| Abs (_, _, t') => do_term t' |
37537 | 106 |
| _ => I |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
107 |
fun do_quantifier will_surely_be_skolemized body_t = |
37537 | 108 |
do_formula pos body_t |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
109 |
#> (if will_surely_be_skolemized then |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
110 |
add_const_to_table (gensym fresh_prefix, []) |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
111 |
else |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
112 |
I) |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
113 |
and do_term_or_formula T = |
38592
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
114 |
if T = @{typ bool} orelse T = @{typ prop} then do_formula NONE |
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
115 |
else do_term |
37537 | 116 |
and do_formula pos t = |
117 |
case t of |
|
118 |
Const (@{const_name all}, _) $ Abs (_, _, body_t) => |
|
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
119 |
do_quantifier (pos = SOME false) body_t |
37537 | 120 |
| @{const "==>"} $ t1 $ t2 => |
121 |
do_formula (flip pos) t1 #> do_formula pos t2 |
|
122 |
| Const (@{const_name "=="}, Type (_, [T, _])) $ t1 $ t2 => |
|
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
123 |
fold (do_term_or_formula T) [t1, t2] |
37537 | 124 |
| @{const Trueprop} $ t1 => do_formula pos t1 |
125 |
| @{const Not} $ t1 => do_formula (flip pos) t1 |
|
126 |
| Const (@{const_name All}, _) $ Abs (_, _, body_t) => |
|
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
127 |
do_quantifier (pos = SOME false) body_t |
37537 | 128 |
| Const (@{const_name Ex}, _) $ Abs (_, _, body_t) => |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
129 |
do_quantifier (pos = SOME true) body_t |
37537 | 130 |
| @{const "op &"} $ t1 $ t2 => fold (do_formula pos) [t1, t2] |
131 |
| @{const "op |"} $ t1 $ t2 => fold (do_formula pos) [t1, t2] |
|
132 |
| @{const "op -->"} $ t1 $ t2 => |
|
133 |
do_formula (flip pos) t1 #> do_formula pos t2 |
|
134 |
| Const (@{const_name "op ="}, Type (_, [T, _])) $ t1 $ t2 => |
|
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
135 |
fold (do_term_or_formula T) [t1, t2] |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
136 |
| Const (@{const_name If}, Type (_, [_, Type (_, [T, _])])) |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
137 |
$ t1 $ t2 $ t3 => |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
138 |
do_formula NONE t1 #> fold (do_term_or_formula T) [t2, t3] |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
139 |
| Const (@{const_name Ex1}, _) $ Abs (_, _, body_t) => |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
140 |
do_quantifier (is_some pos) body_t |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
141 |
| Const (@{const_name Ball}, _) $ t1 $ Abs (_, _, body_t) => |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
142 |
do_quantifier (pos = SOME false) |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
143 |
(HOLogic.mk_imp (incr_boundvars 1 t1 $ Bound 0, body_t)) |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
144 |
| Const (@{const_name Bex}, _) $ t1 $ Abs (_, _, body_t) => |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
145 |
do_quantifier (pos = SOME true) |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
146 |
(HOLogic.mk_conj (incr_boundvars 1 t1 $ Bound 0, body_t)) |
37537 | 147 |
| (t0 as Const (_, @{typ bool})) $ t1 => |
148 |
do_term t0 #> do_formula pos t1 (* theory constant *) |
|
149 |
| _ => do_term t |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
150 |
in |
38091 | 151 |
Symtab.empty |> fold (Symtab.update o rpair []) boring_consts |
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37626
diff
changeset
|
152 |
|> fold (do_formula pos) ts |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
153 |
end |
24287 | 154 |
|
155 |
(*Inserts a dummy "constant" referring to the theory name, so that relevance |
|
156 |
takes the given theory into account.*) |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
157 |
fun theory_const_prop_of theory_relevant th = |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
158 |
if theory_relevant then |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
159 |
let |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
160 |
val name = Context.theory_name (theory_of_thm th) |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
161 |
val t = Const (name ^ ". 1", @{typ bool}) |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
162 |
in t $ prop_of th end |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
163 |
else |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
164 |
prop_of th |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
165 |
|
24287 | 166 |
(**** Constant / Type Frequencies ****) |
167 |
||
168 |
(*A two-dimensional symbol table counts frequencies of constants. It's keyed first by |
|
169 |
constant name and second by its list of type instantiations. For the latter, we need |
|
170 |
a linear ordering on type const_typ list.*) |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
171 |
|
24287 | 172 |
local |
173 |
||
174 |
fun cons_nr CTVar = 0 |
|
175 |
| cons_nr (CType _) = 1; |
|
176 |
||
177 |
in |
|
178 |
||
179 |
fun const_typ_ord TU = |
|
180 |
case TU of |
|
181 |
(CType (a, Ts), CType (b, Us)) => |
|
182 |
(case fast_string_ord(a,b) of EQUAL => dict_ord const_typ_ord (Ts,Us) | ord => ord) |
|
183 |
| (T, U) => int_ord (cons_nr T, cons_nr U); |
|
184 |
||
185 |
end; |
|
186 |
||
31971
8c1b845ed105
renamed functor TableFun to Table, and GraphFun to Graph;
wenzelm
parents:
31910
diff
changeset
|
187 |
structure CTtab = Table(type key = const_typ list val ord = dict_ord const_typ_ord); |
24287 | 188 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
189 |
fun count_axiom_consts theory_relevant thy (_, th) = |
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
190 |
let |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
191 |
fun do_const (a, T) = |
38606
3003ddbd46d9
encode "fequal" reasoning rules in Metis problem, just as is done for Sledgehammer -- otherwise any proof that relies on "fequal" found by Sledgehammer can't be reconstructed
blanchet
parents:
38595
diff
changeset
|
192 |
let val (c, cts) = const_with_typ thy (a, T) in |
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
193 |
(* Two-dimensional table update. Constant maps to types maps to |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
194 |
count. *) |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
195 |
CTtab.map_default (cts, 0) (Integer.add 1) |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
196 |
|> Symtab.map_default (c, CTtab.empty) |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
197 |
end |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
198 |
fun do_term (Const x) = do_const x |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
199 |
| do_term (Free x) = do_const x |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
200 |
| do_term (t $ u) = do_term t #> do_term u |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
201 |
| do_term (Abs (_, _, t)) = do_term t |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
202 |
| do_term _ = I |
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
203 |
in th |> theory_const_prop_of theory_relevant |> do_term end |
24287 | 204 |
|
205 |
||
206 |
(**** Actual Filtering Code ****) |
|
207 |
||
208 |
(*The frequency of a constant is the sum of those of all instances of its type.*) |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
209 |
fun const_frequency const_tab (c, cts) = |
36185
0ee736f08ed0
optimize relevance filter by doing a Table.fold directly rather than destroying the datastructure each time;
blanchet
parents:
36182
diff
changeset
|
210 |
CTtab.fold (fn (cts', m) => match_types cts cts' ? Integer.add m) |
38686 | 211 |
(the (Symtab.lookup const_tab c)) 0 |
212 |
handle Option.Option => 0 |
|
213 |
||
24287 | 214 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
215 |
(* A surprising number of theorems contain only a few significant constants. |
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
216 |
These include all induction rules, and other general theorems. *) |
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
217 |
|
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
218 |
(* "log" seems best in practice. A constant function of one ignores the constant |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
219 |
frequencies. *) |
38686 | 220 |
fun rel_log (x : real) = 1.0 + 2.0 / Math.ln (x + 1.0) |
221 |
fun irrel_log (x : real) = Math.ln (x + 19.0) / 6.4 |
|
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
222 |
|
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
223 |
(* Computes a constant's weight, as determined by its frequency. *) |
38686 | 224 |
val rel_const_weight = rel_log o real oo const_frequency |
225 |
val irrel_const_weight = irrel_log o real oo const_frequency |
|
24287 | 226 |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
227 |
fun axiom_weight const_tab relevant_consts axiom_consts = |
38686 | 228 |
let |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
229 |
val (rel, irrel) = List.partition (const_mem relevant_consts) axiom_consts |
38686 | 230 |
val rel_weight = fold (curry Real.+ o rel_const_weight const_tab) rel 0.0 |
231 |
val irrel_weight = fold (curry Real.+ o irrel_const_weight const_tab) irrel 0.0 |
|
232 |
val res = rel_weight / (rel_weight + irrel_weight) |
|
233 |
in if Real.isFinite res then res else 0.0 end |
|
234 |
||
235 |
(* OLD CODE: |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
236 |
(*Relevant constants are weighted according to frequency, |
24287 | 237 |
but irrelevant constants are simply counted. Otherwise, Skolem functions, |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
238 |
which are rare, would harm a formula's chances of being picked.*) |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
239 |
fun axiom_weight const_tab relevant_consts axiom_consts = |
38101
34b75b71235d
handle division by zero gracefully (used to raise Unordered later on)
blanchet
parents:
38095
diff
changeset
|
240 |
let |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
241 |
val rel = filter (const_mem relevant_consts) axiom_consts |
38686 | 242 |
val rel_weight = fold (curry Real.+ o rel_const_weight const_tab) rel 0.0 |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
243 |
val res = rel_weight / (rel_weight + real (length axiom_consts - length rel)) |
38101
34b75b71235d
handle division by zero gracefully (used to raise Unordered later on)
blanchet
parents:
38095
diff
changeset
|
244 |
in if Real.isFinite res then res else 0.0 end |
38686 | 245 |
*) |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
246 |
|
24287 | 247 |
(*Multiplies out to a list of pairs: 'a * 'b list -> ('a * 'b) list -> ('a * 'b) list*) |
38679
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
248 |
fun add_expand_pairs (x, ys) xys = List.foldl (fn (y,acc) => (x,y)::acc) xys ys |
24287 | 249 |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
250 |
fun consts_of_term thy t = |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
251 |
Symtab.fold add_expand_pairs (get_consts thy (SOME true) [t]) [] |
24287 | 252 |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
253 |
fun pair_consts_axiom theory_relevant thy axiom = |
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
254 |
(axiom, axiom |> snd |> theory_const_prop_of theory_relevant |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
255 |
|> consts_of_term thy) |
24287 | 256 |
|
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
257 |
exception CONST_OR_FREE of unit |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
258 |
|
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
259 |
fun dest_Const_or_Free (Const x) = x |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
260 |
| dest_Const_or_Free (Free x) = x |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
261 |
| dest_Const_or_Free _ = raise CONST_OR_FREE () |
24287 | 262 |
|
263 |
(*Look for definitions of the form f ?x1 ... ?xn = t, but not reversed.*) |
|
32994 | 264 |
fun defines thy thm gctypes = |
24287 | 265 |
let val tm = prop_of thm |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32955
diff
changeset
|
266 |
fun defs lhs rhs = |
24287 | 267 |
let val (rator,args) = strip_comb lhs |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
268 |
val ct = const_with_typ thy (dest_Const_or_Free rator) |
33037
b22e44496dc2
replaced old_style infixes eq_set, subset, union, inter and variants by generic versions
haftmann
parents:
32994
diff
changeset
|
269 |
in |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
270 |
forall is_Var args andalso const_mem gctypes ct andalso |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
271 |
subset (op =) (Term.add_vars rhs [], Term.add_vars lhs []) |
24287 | 272 |
end |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
273 |
handle CONST_OR_FREE () => false |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
274 |
in |
35963 | 275 |
case tm of |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
276 |
@{const Trueprop} $ (Const (@{const_name "op ="}, _) $ lhs $ rhs) => |
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
277 |
defs lhs rhs |
35963 | 278 |
| _ => false |
24287 | 279 |
end; |
280 |
||
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
281 |
type annotated_thm = (string * thm) * (string * const_typ list) list |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
282 |
|
24287 | 283 |
(*For a reverse sort, putting the largest values first.*) |
37500
7587b6e63454
thread original theorem along with CNF theorem, as a step toward killing the Skolem cache
blanchet
parents:
37498
diff
changeset
|
284 |
fun compare_pairs ((_, w1), (_, w2)) = Real.compare (w2, w1) |
24287 | 285 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
286 |
(* Limit the number of new facts, to prevent runaway acceptance. *) |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
287 |
fun take_best max_new (new_pairs : (annotated_thm * real) list) = |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
288 |
let val nnew = length new_pairs in |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
289 |
if nnew <= max_new then |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
290 |
(map #1 new_pairs, []) |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
291 |
else |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
292 |
let |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
293 |
val new_pairs = sort compare_pairs new_pairs |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
294 |
val accepted = List.take (new_pairs, max_new) |
24287 | 295 |
in |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
296 |
trace_msg (fn () => ("Number of candidates, " ^ Int.toString nnew ^ |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
297 |
", exceeds the limit of " ^ Int.toString max_new)); |
35865 | 298 |
trace_msg (fn () => ("Effective pass mark: " ^ Real.toString (#2 (List.last accepted)))); |
299 |
trace_msg (fn () => "Actually passed: " ^ |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
300 |
space_implode ", " (map (fst o fst o fst) accepted)); |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
301 |
(map #1 accepted, List.drop (new_pairs, max_new)) |
24287 | 302 |
end |
303 |
end; |
|
304 |
||
38683
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
305 |
val threshold_divisor = 2.0 |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
306 |
val ridiculous_threshold = 0.1 |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
307 |
|
36922 | 308 |
fun relevance_filter ctxt relevance_threshold relevance_convergence |
38594 | 309 |
defs_relevant max_new theory_relevant |
310 |
({add, del, ...} : relevance_override) axioms goal_ts = |
|
37538
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
311 |
if relevance_threshold > 1.0 then |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
312 |
[] |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
313 |
else if relevance_threshold < 0.0 then |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
314 |
axioms |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
315 |
else |
35963 | 316 |
let |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
317 |
val thy = ProofContext.theory_of ctxt |
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
318 |
val const_tab = fold (count_axiom_consts theory_relevant thy) axioms |
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
319 |
Symtab.empty |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
320 |
val goal_const_tab = get_consts thy (SOME false) goal_ts |
35963 | 321 |
val _ = |
322 |
trace_msg (fn () => "Initial constants: " ^ |
|
37551
2dc53a9f69c9
improve the natural formula relevance filter code, so that it behaves more like the CNF one
blanchet
parents:
37543
diff
changeset
|
323 |
commas (goal_const_tab |
2dc53a9f69c9
improve the natural formula relevance filter code, so that it behaves more like the CNF one
blanchet
parents:
37543
diff
changeset
|
324 |
|> Symtab.dest |
2dc53a9f69c9
improve the natural formula relevance filter code, so that it behaves more like the CNF one
blanchet
parents:
37543
diff
changeset
|
325 |
|> filter (curry (op <>) [] o snd) |
2dc53a9f69c9
improve the natural formula relevance filter code, so that it behaves more like the CNF one
blanchet
parents:
37543
diff
changeset
|
326 |
|> map fst)) |
38594 | 327 |
val add_thms = maps (ProofContext.get_fact ctxt) add |
328 |
val del_thms = maps (ProofContext.get_fact ctxt) del |
|
38683
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
329 |
fun iter j threshold rel_const_tab = |
38594 | 330 |
let |
331 |
fun relevant ([], rejects) [] = |
|
38683
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
332 |
(* Nothing was added this iteration. *) |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
333 |
if j = 0 andalso threshold >= ridiculous_threshold then |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
334 |
(* First iteration? Try again. *) |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
335 |
iter 0 (threshold / threshold_divisor) rel_const_tab |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
336 |
(map (apsnd SOME) rejects) |
38594 | 337 |
else |
38683
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
338 |
(* Add "add:" facts. *) |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
339 |
if null add_thms then |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
340 |
[] |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
341 |
else |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
342 |
map_filter (fn ((p as (name, th), _), _) => |
38683
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
343 |
if member Thm.eq_thm add_thms th then SOME p |
23266607cb81
if no facts were selected on first iteration, try again with a lower threshold
blanchet
parents:
38682
diff
changeset
|
344 |
else NONE) rejects |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
345 |
| relevant (new_pairs, rejects) [] = |
38594 | 346 |
let |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
347 |
val (new_rels, more_rejects) = take_best max_new new_pairs |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
348 |
val new_consts = new_rels |> maps snd |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
349 |
val rel_const_tab' = |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
350 |
rel_const_tab |> fold add_const_to_table new_consts |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
351 |
fun is_dirty c = |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
352 |
const_mem rel_const_tab' c andalso |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
353 |
not (const_mem rel_const_tab c) |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
354 |
val rejects = |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
355 |
more_rejects @ rejects |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
356 |
|> map (fn (ax as (_, consts), old_weight) => |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
357 |
(ax, if exists is_dirty consts then NONE |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
358 |
else SOME old_weight)) |
38594 | 359 |
val threshold = |
38684
e2c04af9469b
invert semantics of "relevance_convergence", to make it more intuitive
blanchet
parents:
38683
diff
changeset
|
360 |
threshold + (1.0 - threshold) * relevance_convergence |
38594 | 361 |
in |
362 |
trace_msg (fn () => "relevant this iteration: " ^ |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
363 |
Int.toString (length new_rels)); |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
364 |
map #1 new_rels @ iter (j + 1) threshold rel_const_tab' rejects |
38594 | 365 |
end |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
366 |
| relevant (new_rels, rejects) |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
367 |
(((ax as ((name, th), axiom_consts)), cached_weight) |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
368 |
:: rest) = |
38594 | 369 |
let |
370 |
val weight = |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
371 |
case cached_weight of |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
372 |
SOME w => w |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
373 |
| NONE => axiom_weight const_tab rel_const_tab axiom_consts |
38594 | 374 |
in |
375 |
if weight >= threshold orelse |
|
376 |
(defs_relevant andalso defines thy th rel_const_tab) then |
|
377 |
(trace_msg (fn () => |
|
378 |
name ^ " passes: " ^ Real.toString weight |
|
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
379 |
^ " consts: " ^ commas (map fst axiom_consts)); |
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
380 |
relevant ((ax, weight) :: new_rels, rejects) rest) |
38594 | 381 |
else |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
382 |
relevant (new_rels, (ax, weight) :: rejects) rest |
38594 | 383 |
end |
384 |
in |
|
385 |
trace_msg (fn () => "relevant_facts, current threshold: " ^ |
|
386 |
Real.toString threshold); |
|
387 |
relevant ([], []) |
|
388 |
end |
|
35963 | 389 |
in |
38686 | 390 |
axioms |> filter_out (member Thm.eq_thm del_thms o snd) |
38687
97509445c569
cache previous iteration's weights, and keep track of what's dirty and what's clean;
blanchet
parents:
38686
diff
changeset
|
391 |
|> map (rpair NONE o pair_consts_axiom theory_relevant thy) |
38686 | 392 |
|> iter 0 relevance_threshold goal_const_tab |
393 |
|> tap (fn res => trace_msg (fn () => |
|
394 |
"Total relevant: " ^ Int.toString (length res))) |
|
35963 | 395 |
end |
24287 | 396 |
|
397 |
(***************************************************************) |
|
19768
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
398 |
(* Retrieving and filtering lemmas *) |
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
399 |
(***************************************************************) |
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
400 |
|
33022
c95102496490
Removal of the unused atpset concept, the atp attribute and some related code.
paulson
parents:
32994
diff
changeset
|
401 |
(*** retrieve lemmas and filter them ***) |
19768
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
402 |
|
20757
fe84fe0dfd30
Definitions produced by packages are now blacklisted.
paulson
parents:
20661
diff
changeset
|
403 |
(*Reject theorems with names like "List.filter.filter_list_def" or |
21690
552d20ff9a95
Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents:
21588
diff
changeset
|
404 |
"Accessible_Part.acc.defs", as these are definitions arising from packages.*) |
20757
fe84fe0dfd30
Definitions produced by packages are now blacklisted.
paulson
parents:
20661
diff
changeset
|
405 |
fun is_package_def a = |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30291
diff
changeset
|
406 |
let val names = Long_Name.explode a |
21690
552d20ff9a95
Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents:
21588
diff
changeset
|
407 |
in |
552d20ff9a95
Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents:
21588
diff
changeset
|
408 |
length names > 2 andalso |
552d20ff9a95
Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents:
21588
diff
changeset
|
409 |
not (hd names = "local") andalso |
552d20ff9a95
Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents:
21588
diff
changeset
|
410 |
String.isSuffix "_def" a orelse String.isSuffix "_defs" a |
552d20ff9a95
Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents:
21588
diff
changeset
|
411 |
end; |
20757
fe84fe0dfd30
Definitions produced by packages are now blacklisted.
paulson
parents:
20661
diff
changeset
|
412 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
413 |
fun make_fact_table xs = |
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
414 |
fold (Termtab.update o `(prop_of o snd)) xs Termtab.empty |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
415 |
fun make_unique xs = Termtab.fold (cons o snd) (make_fact_table xs) [] |
19768
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
416 |
|
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
417 |
(* FIXME: put other record thms here, or declare as "no_atp" *) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
418 |
val multi_base_blacklist = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
419 |
["defs", "select_defs", "update_defs", "induct", "inducts", "split", "splits", |
38682 | 420 |
"split_asm", "cases", "ext_cases", "eq.simps", "eq.refl", "nchotomy", |
421 |
"case_cong", "weak_case_cong"] |
|
422 |
|> map (prefix ".") |
|
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
423 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
424 |
val max_lambda_nesting = 3 |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
425 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
426 |
fun term_has_too_many_lambdas max (t1 $ t2) = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
427 |
exists (term_has_too_many_lambdas max) [t1, t2] |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
428 |
| term_has_too_many_lambdas max (Abs (_, _, t)) = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
429 |
max = 0 orelse term_has_too_many_lambdas (max - 1) t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
430 |
| term_has_too_many_lambdas _ _ = false |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
431 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
432 |
fun is_formula_type T = (T = HOLogic.boolT orelse T = propT) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
433 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
434 |
(* Don't count nested lambdas at the level of formulas, since they are |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
435 |
quantifiers. *) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
436 |
fun formula_has_too_many_lambdas Ts (Abs (_, T, t)) = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
437 |
formula_has_too_many_lambdas (T :: Ts) t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
438 |
| formula_has_too_many_lambdas Ts t = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
439 |
if is_formula_type (fastype_of1 (Ts, t)) then |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
440 |
exists (formula_has_too_many_lambdas Ts) (#2 (strip_comb t)) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
441 |
else |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
442 |
term_has_too_many_lambdas max_lambda_nesting t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
443 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
444 |
(* The max apply depth of any "metis" call in "Metis_Examples" (on 31-10-2007) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
445 |
was 11. *) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
446 |
val max_apply_depth = 15 |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
447 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
448 |
fun apply_depth (f $ t) = Int.max (apply_depth f, apply_depth t + 1) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
449 |
| apply_depth (Abs (_, _, t)) = apply_depth t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
450 |
| apply_depth _ = 0 |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
451 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
452 |
fun is_formula_too_complex t = |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
453 |
apply_depth t > max_apply_depth orelse formula_has_too_many_lambdas [] t |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
454 |
|
37543 | 455 |
val exists_sledgehammer_const = |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
456 |
exists_Const (fn (s, _) => String.isPrefix sledgehammer_prefix s) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
457 |
|
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
458 |
fun is_strange_theorem th = |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
459 |
case head_of (concl_of th) of |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
460 |
Const (a, _) => (a <> @{const_name Trueprop} andalso |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
461 |
a <> @{const_name "=="}) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
462 |
| _ => false |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
463 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
464 |
val type_has_top_sort = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
465 |
exists_subtype (fn TFree (_, []) => true | TVar (_, []) => true | _ => false) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
466 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
467 |
(**** Predicates to detect unwanted facts (prolific or likely to cause |
37347
635425a442e8
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents:
37345
diff
changeset
|
468 |
unsoundness) ****) |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21431
diff
changeset
|
469 |
|
38289
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
470 |
(* Too general means, positive equality literal with a variable X as one |
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
471 |
operand, when X does not occur properly in the other operand. This rules out |
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
472 |
clearly inconsistent facts such as X = a | X = b, though it by no means |
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
473 |
guarantees soundness. *) |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21431
diff
changeset
|
474 |
|
38289
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
475 |
(* Unwanted equalities are those between a (bound or schematic) variable that |
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
476 |
does not properly occur in the second operand. *) |
38607
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
477 |
val is_exhaustive_finite = |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
478 |
let |
38629 | 479 |
fun is_bad_equal (Var z) t = |
480 |
not (exists_subterm (fn Var z' => z = z' | _ => false) t) |
|
481 |
| is_bad_equal (Bound j) t = not (loose_bvar1 (t, j)) |
|
482 |
| is_bad_equal _ _ = false |
|
483 |
fun do_equals t1 t2 = is_bad_equal t1 t2 orelse is_bad_equal t2 t1 |
|
38607
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
484 |
fun do_formula pos t = |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
485 |
case (pos, t) of |
38615
4e1d828ee514
improve "x = A | x = B | x = C"-style axiom detection
blanchet
parents:
38611
diff
changeset
|
486 |
(_, @{const Trueprop} $ t1) => do_formula pos t1 |
38607
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
487 |
| (true, Const (@{const_name all}, _) $ Abs (_, _, t')) => |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
488 |
do_formula pos t' |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
489 |
| (true, Const (@{const_name All}, _) $ Abs (_, _, t')) => |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
490 |
do_formula pos t' |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
491 |
| (false, Const (@{const_name Ex}, _) $ Abs (_, _, t')) => |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
492 |
do_formula pos t' |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
493 |
| (_, @{const "==>"} $ t1 $ t2) => |
38629 | 494 |
do_formula (not pos) t1 andalso |
495 |
(t2 = @{prop False} orelse do_formula pos t2) |
|
38607
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
496 |
| (_, @{const "op -->"} $ t1 $ t2) => |
38629 | 497 |
do_formula (not pos) t1 andalso |
498 |
(t2 = @{const False} orelse do_formula pos t2) |
|
38607
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
499 |
| (_, @{const Not} $ t1) => do_formula (not pos) t1 |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
500 |
| (true, @{const "op |"} $ t1 $ t2) => forall (do_formula pos) [t1, t2] |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
501 |
| (false, @{const "op &"} $ t1 $ t2) => forall (do_formula pos) [t1, t2] |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
502 |
| (true, Const (@{const_name "op ="}, _) $ t1 $ t2) => do_equals t1 t2 |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
503 |
| (true, Const (@{const_name "=="}, _) $ t1 $ t2) => do_equals t1 t2 |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
504 |
| _ => false |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
505 |
in do_formula true end |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
506 |
|
38592
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
507 |
fun has_bound_or_var_of_type tycons = |
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
508 |
exists_subterm (fn Var (_, Type (s, _)) => member (op =) tycons s |
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
509 |
| Abs (_, Type (s, _), _) => member (op =) tycons s |
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
510 |
| _ => false) |
21431
ef9080e7dbbc
Outputs a minimal number of arity clauses. Tidying of blacklist, fixing the blacklisting of thm lists
paulson
parents:
21397
diff
changeset
|
511 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
512 |
(* Facts are forbidden to contain variables of these types. The typical reason |
37347
635425a442e8
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents:
37345
diff
changeset
|
513 |
is that they lead to unsoundness. Note that "unit" satisfies numerous |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
514 |
equations like "?x = ()". The resulting clauses will have no type constraint, |
37347
635425a442e8
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents:
37345
diff
changeset
|
515 |
yielding false proofs. Even "bool" leads to many unsound proofs, though only |
635425a442e8
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents:
37345
diff
changeset
|
516 |
for higher-order problems. *) |
38592
ae6bb801e583
bound variables can be just as evil as schematic variables and lead to unsound proofs (e.g. "all_bool_eq")
blanchet
parents:
38587
diff
changeset
|
517 |
val dangerous_types = [@{type_name unit}, @{type_name bool}, @{type_name prop}]; |
22217
a5d983f7113f
Tidying; more debugging information. New reference unwanted_types.
paulson
parents:
22193
diff
changeset
|
518 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
519 |
(* Facts containing variables of type "unit" or "bool" or of the form |
38290
581a402a80f0
prevent ATP thread for staying around for 1 minute if an exception occurred earlier;
blanchet
parents:
38289
diff
changeset
|
520 |
"ALL x. x = A | x = B | x = C" are likely to lead to unsound proofs if types |
581a402a80f0
prevent ATP thread for staying around for 1 minute if an exception occurred earlier;
blanchet
parents:
38289
diff
changeset
|
521 |
are omitted. *) |
38593 | 522 |
fun is_dangerous_term full_types t = |
38609 | 523 |
not full_types andalso |
38679
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
524 |
let val t = transform_elim_term t in |
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
525 |
has_bound_or_var_of_type dangerous_types t orelse |
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
526 |
is_exhaustive_finite t |
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
527 |
end |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21431
diff
changeset
|
528 |
|
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
529 |
fun is_theorem_bad_for_atps full_types thm = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
530 |
let val t = prop_of thm in |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
531 |
is_formula_too_complex t orelse exists_type type_has_top_sort t orelse |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
532 |
is_dangerous_term full_types t orelse exists_sledgehammer_const t orelse |
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
533 |
is_strange_theorem thm |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
534 |
end |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
535 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
536 |
fun all_name_thms_pairs ctxt full_types add_thms chained_ths = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
537 |
let |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
538 |
val global_facts = PureThy.facts_of (ProofContext.theory_of ctxt); |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
539 |
val local_facts = ProofContext.facts_of ctxt |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
540 |
val named_locals = local_facts |> Facts.dest_static [] |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
541 |
val unnamed_locals = |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
542 |
local_facts |> Facts.props |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
543 |
|> filter_out (fn th => exists (fn (_, ths) => member Thm.eq_thm ths th) |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
544 |
named_locals) |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
545 |
|> map (pair "" o single) |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
546 |
val full_space = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
547 |
Name_Space.merge (Facts.space_of global_facts, Facts.space_of local_facts); |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
548 |
fun valid_facts facts pairs = |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
549 |
(pairs, []) |-> fold (fn (name, ths0) => |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
550 |
if name <> "" andalso |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
551 |
forall (not o member Thm.eq_thm add_thms) ths0 andalso |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
552 |
(Facts.is_concealed facts name orelse |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
553 |
(respect_no_atp andalso is_package_def name) orelse |
38682 | 554 |
exists (fn s => String.isSuffix s name) multi_base_blacklist orelse |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
555 |
String.isSuffix "_def_raw" (* FIXME: crude hack *) name) then |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
556 |
I |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
557 |
else |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
558 |
let |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
559 |
fun check_thms a = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
560 |
(case try (ProofContext.get_thms ctxt) a of |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
561 |
NONE => false |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
562 |
| SOME ths1 => Thm.eq_thms (ths0, ths1)) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
563 |
val name1 = Facts.extern facts name; |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
564 |
val name2 = Name_Space.extern full_space name; |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
565 |
val ths = |
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
566 |
ths0 |> filter ((not o is_theorem_bad_for_atps full_types) orf |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
567 |
member Thm.eq_thm add_thms) |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
568 |
val name' = |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
569 |
case find_first check_thms [name1, name2, name] of |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
570 |
SOME name' => name' |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
571 |
| NONE => |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
572 |
ths |> map (fn th => |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
573 |
"`" ^ Print_Mode.setmp [Print_Mode.input] |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
574 |
(Syntax.string_of_term ctxt) |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
575 |
(prop_of th) ^ "`") |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
576 |
|> space_implode " " |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
577 |
in |
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
578 |
cons (name' |> forall (member Thm.eq_thm chained_ths) ths0 |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
579 |
? prefix chained_prefix, ths) |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
580 |
end) |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
581 |
in |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
582 |
valid_facts local_facts (unnamed_locals @ named_locals) @ |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
583 |
valid_facts global_facts (Facts.dest_static [] global_facts) |
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
584 |
end |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
585 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
586 |
fun multi_name a th (n, pairs) = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
587 |
(n + 1, (a ^ "(" ^ Int.toString n ^ ")", th) :: pairs); |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
588 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
589 |
fun add_names (_, []) pairs = pairs |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
590 |
| add_names (a, [th]) pairs = (a, th) :: pairs |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
591 |
| add_names (a, ths) pairs = #2 (fold (multi_name a) ths (1, pairs)) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
592 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
593 |
fun is_multi (a, ths) = length ths > 1 orelse String.isSuffix ".axioms" a; |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
594 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
595 |
(* The single-name theorems go after the multiple-name ones, so that single |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
596 |
names are preferred when both are available. *) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
597 |
fun name_thm_pairs ctxt respect_no_atp name_thms_pairs = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
598 |
let |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
599 |
val (mults, singles) = List.partition is_multi name_thms_pairs |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
600 |
val ps = [] |> fold add_names singles |> fold add_names mults |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
601 |
in ps |> respect_no_atp ? filter_out (No_ATPs.member ctxt o snd) end; |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
602 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
603 |
fun is_named ("", th) = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
604 |
(warning ("No name for theorem " ^ |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
605 |
Display.string_of_thm_without_context th); false) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
606 |
| is_named _ = true |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
607 |
fun checked_name_thm_pairs respect_no_atp ctxt = |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
608 |
name_thm_pairs ctxt respect_no_atp |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
609 |
#> tap (fn ps => trace_msg |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
610 |
(fn () => ("Considering " ^ Int.toString (length ps) ^ |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
611 |
" theorems"))) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
612 |
#> filter is_named |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
613 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
614 |
(***************************************************************) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
615 |
(* ATP invocation methods setup *) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
616 |
(***************************************************************) |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
617 |
|
37580
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset
|
618 |
fun relevant_facts full_types relevance_threshold relevance_convergence |
c2c1caff5dea
got rid of "respect_no_atp" option, which even I don't use
blanchet
parents:
37578
diff
changeset
|
619 |
defs_relevant max_new theory_relevant |
37347
635425a442e8
show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents:
37345
diff
changeset
|
620 |
(relevance_override as {add, del, only}) |
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37626
diff
changeset
|
621 |
(ctxt, (chained_ths, _)) hyp_ts concl_t = |
37538
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
622 |
let |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
623 |
val add_thms = maps (ProofContext.get_fact ctxt) add |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
624 |
val axioms = |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
625 |
checked_name_thm_pairs (respect_no_atp andalso not only) ctxt |
38617 | 626 |
(if only then map (name_thms_pair_from_ref ctxt chained_ths) add |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
627 |
else all_name_thms_pairs ctxt full_types add_thms chained_ths) |
38595
bbb0982656eb
make sure that "add:" doesn't influence the relevance filter too much
blanchet
parents:
38594
diff
changeset
|
628 |
|> make_unique |
37538
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
629 |
in |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
630 |
relevance_filter ctxt relevance_threshold relevance_convergence |
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
631 |
defs_relevant max_new theory_relevant relevance_override |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
632 |
axioms (concl_t :: hyp_ts) |
38595
bbb0982656eb
make sure that "add:" doesn't influence the relevance filter too much
blanchet
parents:
38594
diff
changeset
|
633 |
|> sort_wrt fst |
37538
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
634 |
end |
30536
07b4f050e4df
split relevance-filter and writing of problem-files;
immler@in.tum.de
parents:
30364
diff
changeset
|
635 |
|
15347 | 636 |
end; |