author | blanchet |
Thu, 16 Dec 2010 15:12:17 +0100 | |
changeset 41207 | f9c7bdc75dd0 |
parent 41205 | 209546e0af2c |
child 41211 | 1e2e16bc0077 |
permissions | -rw-r--r-- |
38988 | 1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_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 |
39958 | 4 |
|
5 |
Sledgehammer's relevance filter. |
|
33309 | 6 |
*) |
15452 | 7 |
|
38988 | 8 |
signature SLEDGEHAMMER_FILTER = |
16802
6eeee59dac4c
use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents:
16767
diff
changeset
|
9 |
sig |
38993
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
10 |
datatype locality = General | Intro | Elim | Simp | Local | Assum | Chained |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
11 |
|
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
12 |
type relevance_fudge = |
41159
1e12d6495423
honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents:
41158
diff
changeset
|
13 |
{allow_ext : bool, |
1e12d6495423
honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents:
41158
diff
changeset
|
14 |
worse_irrel_freq : real, |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
15 |
higher_order_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
16 |
abs_rel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
17 |
abs_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
18 |
skolem_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
19 |
theory_const_rel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
20 |
theory_const_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
21 |
intro_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
22 |
elim_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
23 |
simp_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
24 |
local_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
25 |
assum_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
26 |
chained_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
27 |
max_imperfect : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
28 |
max_imperfect_exp : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
29 |
threshold_divisor : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
30 |
ridiculous_threshold : real} |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
31 |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
32 |
type relevance_override = |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
33 |
{add : (Facts.ref * Attrib.src list) list, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
34 |
del : (Facts.ref * Attrib.src list) list, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
35 |
only : bool} |
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
36 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
37 |
val trace : bool Unsynchronized.ref |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
38 |
val fact_from_ref : |
38996 | 39 |
Proof.context -> unit Symtab.table -> thm list |
40 |
-> Facts.ref * Attrib.src list -> ((string * locality) * 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
|
41 |
val relevant_facts : |
41066
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
42 |
Proof.context -> bool -> real * real -> int |
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
43 |
-> (string * typ -> term list -> bool) -> relevance_fudge |
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
44 |
-> relevance_override -> thm list -> term list -> term |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
45 |
-> ((string * locality) * thm) list |
15347 | 46 |
end; |
47 |
||
38988 | 48 |
structure Sledgehammer_Filter : SLEDGEHAMMER_FILTER = |
15347 | 49 |
struct |
50 |
||
38652
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
51 |
open Sledgehammer_Util |
e063be321438
perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents:
38644
diff
changeset
|
52 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
53 |
val trace = Unsynchronized.ref false |
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
54 |
fun trace_msg msg = if !trace then tracing (msg ()) else () |
35826 | 55 |
|
41204
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
56 |
(* experimental feature *) |
38997 | 57 |
val respect_no_atp = true |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
58 |
|
38993
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
59 |
datatype locality = General | Intro | Elim | Simp | Local | Assum | Chained |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
60 |
|
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
61 |
type relevance_fudge = |
41159
1e12d6495423
honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents:
41158
diff
changeset
|
62 |
{allow_ext : bool, |
1e12d6495423
honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents:
41158
diff
changeset
|
63 |
worse_irrel_freq : real, |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
64 |
higher_order_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
65 |
abs_rel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
66 |
abs_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
67 |
skolem_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
68 |
theory_const_rel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
69 |
theory_const_irrel_weight : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
70 |
intro_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
71 |
elim_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
72 |
simp_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
73 |
local_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
74 |
assum_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
75 |
chained_bonus : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
76 |
max_imperfect : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
77 |
max_imperfect_exp : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
78 |
threshold_divisor : real, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
79 |
ridiculous_threshold : real} |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
80 |
|
35966
f8c738abaed8
honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents:
35963
diff
changeset
|
81 |
type relevance_override = |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
82 |
{add : (Facts.ref * Attrib.src list) list, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
83 |
del : (Facts.ref * Attrib.src list) list, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
84 |
only : bool} |
21070 | 85 |
|
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
86 |
val sledgehammer_prefix = "Sledgehammer" ^ Long_Name.separator |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39718
diff
changeset
|
87 |
val abs_name = sledgehammer_prefix ^ "abs" |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39718
diff
changeset
|
88 |
val skolem_prefix = sledgehammer_prefix ^ "sko" |
38992
542474156c66
introduce fudge factors to deal with "theory const"
blanchet
parents:
38988
diff
changeset
|
89 |
val theory_const_suffix = Long_Name.separator ^ " 1" |
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
90 |
|
40227
e31e3f0071d4
support non-identifier-like fact names in Sledgehammer (e.g., "my lemma") by quoting them
blanchet
parents:
40205
diff
changeset
|
91 |
fun needs_quoting reserved s = |
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
92 |
Symtab.defined reserved s orelse |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
93 |
exists (not o Syntax.is_identifier) (Long_Name.explode s) |
40227
e31e3f0071d4
support non-identifier-like fact names in Sledgehammer (e.g., "my lemma") by quoting them
blanchet
parents:
40205
diff
changeset
|
94 |
|
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
95 |
fun make_name reserved multi j name = |
40227
e31e3f0071d4
support non-identifier-like fact names in Sledgehammer (e.g., "my lemma") by quoting them
blanchet
parents:
40205
diff
changeset
|
96 |
(name |> needs_quoting reserved name ? quote) ^ |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
97 |
(if multi then "(" ^ Int.toString j ^ ")" else "") |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
98 |
|
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
99 |
fun explode_interval _ (Facts.FromTo (i, j)) = i upto j |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
100 |
| explode_interval max (Facts.From i) = i upto i + max - 1 |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
101 |
| explode_interval _ (Facts.Single i) = [i] |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
102 |
|
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
103 |
fun fact_from_ref ctxt reserved chained_ths (xthm as (xref, args)) = |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
104 |
let |
38996 | 105 |
val ths = Attrib.eval_thms ctxt [xthm] |
106 |
val bracket = |
|
107 |
implode (map (fn arg => "[" ^ Pretty.str_of (Args.pretty_src ctxt arg) |
|
108 |
^ "]") args) |
|
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
109 |
fun nth_name j = |
38996 | 110 |
case xref of |
39264 | 111 |
Facts.Fact s => "`" ^ s ^ "`" ^ bracket |
38996 | 112 |
| Facts.Named (("", _), _) => "[" ^ bracket ^ "]" |
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
113 |
| Facts.Named ((name, _), NONE) => |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
114 |
make_name reserved (length ths > 1) (j + 1) name ^ bracket |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
115 |
| Facts.Named ((name, _), SOME intervals) => |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
116 |
make_name reserved true |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
117 |
(nth (maps (explode_interval (length ths)) intervals) j) name ^ |
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
118 |
bracket |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
119 |
in |
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
120 |
(ths, (0, [])) |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
121 |
|-> fold (fn th => fn (j, rest) => |
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
122 |
(j + 1, ((nth_name j, |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
123 |
if member Thm.eq_thm chained_ths th then Chained |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
124 |
else General), th) :: rest)) |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
125 |
|> snd |
38699 | 126 |
end |
37616
c8d2d84d6011
always perform relevance filtering on original formulas
blanchet
parents:
37580
diff
changeset
|
127 |
|
41199 | 128 |
(* This is a terrible hack. Free variables are sometimes code as "M__" when they |
129 |
are displayed as "M" and we want to avoid clashes with these. But sometimes |
|
130 |
it's even worse: "Ma__" encodes "M". So we simply reserve all prefixes of all |
|
131 |
free variables. In the worse case scenario, where the fact won't be resolved |
|
132 |
correctly, the user can fix it manually, e.g., by naming the fact in |
|
133 |
question. Ideally we would need nothing of it, but backticks just don't work |
|
134 |
with schematic variables. *) |
|
135 |
fun all_prefixes_of s = |
|
136 |
map (fn i => String.extract (s, 0, SOME i)) (1 upto size s - 1) |
|
137 |
fun close_form t = |
|
138 |
(t, [] |> Term.add_free_names t |> maps all_prefixes_of) |
|
139 |
|> fold (fn ((s, i), T) => fn (t', taken) => |
|
140 |
let val s' = Name.variant taken s in |
|
141 |
((if fastype_of t' = HOLogic.boolT then HOLogic.all_const |
|
142 |
else Term.all) T |
|
143 |
$ Abs (s', T, abstract_over (Var ((s, i), T), t')), |
|
144 |
s' :: taken) |
|
145 |
end) |
|
146 |
(Term.add_vars t [] |> sort_wrt (fst o fst)) |
|
147 |
|> fst |
|
148 |
||
149 |
fun string_for_term ctxt t = |
|
150 |
Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN) |
|
151 |
(print_mode_value ())) (Syntax.string_of_term ctxt) t |
|
152 |
|> String.translate (fn c => if Char.isPrint c then str c else "") |
|
153 |
|> simplify_spaces |
|
154 |
||
155 |
(** Structural induction rules **) |
|
156 |
||
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
157 |
fun struct_induct_rule_on th = |
41199 | 158 |
case Logic.strip_horn (prop_of th) of |
159 |
(prems, @{const Trueprop} |
|
160 |
$ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) => |
|
161 |
if not (is_TVar ind_T) andalso length prems > 1 andalso |
|
162 |
exists (exists_subterm (curry (op aconv) p)) prems andalso |
|
163 |
not (exists (exists_subterm (curry (op aconv) a)) prems) then |
|
164 |
SOME (p_name, ind_T) |
|
165 |
else |
|
166 |
NONE |
|
167 |
| _ => NONE |
|
168 |
||
41207 | 169 |
fun instantiate_induct_rule ctxt concl_prop p_name ((name, loc), (multi, th)) |
41199 | 170 |
ind_x = |
171 |
let |
|
172 |
fun varify_noninducts (t as Free (s, T)) = |
|
173 |
if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T) |
|
174 |
| varify_noninducts t = t |
|
175 |
val p_inst = |
|
176 |
concl_prop |> map_aterms varify_noninducts |> close_form |
|
177 |
|> lambda (Free ind_x) |
|
178 |
|> string_for_term ctxt |
|
179 |
in |
|
41207 | 180 |
((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]", loc), |
41199 | 181 |
(multi, th |> read_instantiate ctxt [((p_name, 0), p_inst)])) |
182 |
end |
|
183 |
||
184 |
fun type_match thy (T1, T2) = |
|
185 |
(Sign.typ_match thy (T2, T1) Vartab.empty; true) |
|
186 |
handle Type.TYPE_MATCH => false |
|
187 |
||
188 |
fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, (_, th))) = |
|
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
189 |
case struct_induct_rule_on th of |
41199 | 190 |
SOME (p_name, ind_T) => |
191 |
let val thy = ProofContext.theory_of ctxt in |
|
192 |
stmt_xs |> filter (fn (_, T) => type_match thy (T, ind_T)) |
|
193 |
|> map_filter (try (instantiate_induct_rule ctxt stmt p_name ax)) |
|
194 |
end |
|
195 |
| NONE => [ax] |
|
196 |
||
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
28065
diff
changeset
|
197 |
(***************************************************************) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
28065
diff
changeset
|
198 |
(* Relevance Filtering *) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
28065
diff
changeset
|
199 |
(***************************************************************) |
19194 | 200 |
|
24287 | 201 |
(*** constants with types ***) |
202 |
||
38939 | 203 |
fun order_of_type (Type (@{type_name fun}, [T1, @{typ bool}])) = |
204 |
order_of_type T1 (* cheat: pretend sets are first-order *) |
|
205 |
| order_of_type (Type (@{type_name fun}, [T1, T2])) = |
|
206 |
Int.max (order_of_type T1 + 1, order_of_type T2) |
|
207 |
| order_of_type (Type (_, Ts)) = fold (Integer.max o order_of_type) Ts 0 |
|
208 |
| order_of_type _ = 0 |
|
209 |
||
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
210 |
(* An abstraction of Isabelle types and first-order terms *) |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
211 |
datatype pattern = PVar | PApp of string * pattern list |
38939 | 212 |
datatype ptype = PType of int * pattern list |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
213 |
|
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
214 |
fun string_for_pattern PVar = "_" |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
215 |
| string_for_pattern (PApp (s, ps)) = |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
216 |
if null ps then s else s ^ string_for_patterns ps |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
217 |
and string_for_patterns ps = "(" ^ commas (map string_for_pattern ps) ^ ")" |
38939 | 218 |
fun string_for_ptype (PType (_, ps)) = string_for_patterns ps |
24287 | 219 |
|
220 |
(*Is the second type an instance of the first one?*) |
|
38824 | 221 |
fun match_pattern (PVar, _) = true |
222 |
| match_pattern (PApp _, PVar) = false |
|
223 |
| match_pattern (PApp (s, ps), PApp (t, qs)) = |
|
224 |
s = t andalso match_patterns (ps, qs) |
|
225 |
and match_patterns (_, []) = true |
|
226 |
| match_patterns ([], _) = false |
|
227 |
| match_patterns (p :: ps, q :: qs) = |
|
228 |
match_pattern (p, q) andalso match_patterns (ps, qs) |
|
38939 | 229 |
fun match_ptype (PType (_, ps), PType (_, qs)) = match_patterns (ps, qs) |
24287 | 230 |
|
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
231 |
(* Is there a unifiable constant? *) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
232 |
fun pconst_mem f consts (s, ps) = |
38939 | 233 |
exists (curry (match_ptype o f) ps) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
234 |
(map snd (filter (curry (op =) s o fst) consts)) |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
235 |
fun pconst_hyper_mem f const_tab (s, ps) = |
38939 | 236 |
exists (curry (match_ptype o f) ps) (these (Symtab.lookup const_tab s)) |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
237 |
|
38939 | 238 |
fun pattern_for_type (Type (s, Ts)) = PApp (s, map pattern_for_type Ts) |
239 |
| pattern_for_type (TFree (s, _)) = PApp (s, []) |
|
240 |
| pattern_for_type (TVar _) = PVar |
|
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
241 |
|
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
242 |
(* Pairs a constant with the list of its type instantiations. *) |
41204
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
243 |
fun ptype thy const x = |
38939 | 244 |
(if const then map pattern_for_type (these (try (Sign.const_typargs thy) x)) |
41204
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
245 |
else []) |
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
246 |
fun rich_ptype thy const (s, T) = |
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
247 |
PType (order_of_type T, ptype thy const (s, T)) |
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
248 |
fun rich_pconst thy const (s, T) = (s, rich_ptype thy const (s, T)) |
24287 | 249 |
|
38939 | 250 |
fun string_for_hyper_pconst (s, ps) = |
251 |
s ^ "{" ^ commas (map string_for_ptype ps) ^ "}" |
|
24287 | 252 |
|
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
253 |
(* Add a pconstant to the table, but a [] entry means a standard |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
254 |
connective, which we ignore.*) |
41066
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
255 |
fun add_pconst_to_table also_skolem (s, p) = |
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
256 |
if (not also_skolem andalso String.isPrefix skolem_prefix s) then I |
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
257 |
else Symtab.map_default (s, [p]) (insert (op =) p) |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
258 |
|
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
259 |
fun is_formula_type T = (T = HOLogic.boolT orelse T = propT) |
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
260 |
|
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
261 |
fun pconsts_in_terms thy is_built_in_const also_skolems pos ts = |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
262 |
let |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
263 |
val flip = Option.map not |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
264 |
(* We include free variables, as well as constants, to handle locales. For |
41205 | 265 |
each quantifiers that must necessarily be skolemized by the automatic |
266 |
prover, we introduce a fresh constant to simulate the effect of |
|
267 |
Skolemization. *) |
|
40373 | 268 |
fun do_const const x ts = |
41066
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
269 |
(not (is_built_in_const x ts) |
41204
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
270 |
? add_pconst_to_table also_skolems (rich_pconst thy const x)) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
271 |
#> fold do_term ts |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
272 |
and do_term t = |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
273 |
case strip_comb t of |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
274 |
(Const x, ts) => do_const true x ts |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
275 |
| (Free x, ts) => do_const false x ts |
38939 | 276 |
| (Abs (_, T, t'), ts) => |
277 |
(null ts |
|
41066
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
278 |
? add_pconst_to_table true (abs_name, PType (order_of_type T + 1, []))) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
279 |
#> fold do_term (t' :: ts) |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
280 |
| (_, ts) => fold do_term ts |
38939 | 281 |
fun do_quantifier will_surely_be_skolemized abs_T body_t = |
37537 | 282 |
do_formula pos body_t |
38747 | 283 |
#> (if also_skolems andalso will_surely_be_skolemized then |
41066
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
284 |
add_pconst_to_table true |
41207 | 285 |
(gensym skolem_prefix, PType (order_of_type abs_T, [])) |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
286 |
else |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
287 |
I) |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
288 |
and do_term_or_formula T = |
38692 | 289 |
if is_formula_type T then do_formula NONE else do_term |
37537 | 290 |
and do_formula pos t = |
291 |
case t of |
|
38939 | 292 |
Const (@{const_name all}, _) $ Abs (_, T, t') => |
293 |
do_quantifier (pos = SOME false) T t' |
|
37537 | 294 |
| @{const "==>"} $ t1 $ t2 => |
295 |
do_formula (flip pos) t1 #> do_formula pos t2 |
|
296 |
| 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
|
297 |
fold (do_term_or_formula T) [t1, t2] |
37537 | 298 |
| @{const Trueprop} $ t1 => do_formula pos t1 |
41140
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
299 |
| @{const False} => I |
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
300 |
| @{const True} => I |
37537 | 301 |
| @{const Not} $ t1 => do_formula (flip pos) t1 |
38939 | 302 |
| Const (@{const_name All}, _) $ Abs (_, T, t') => |
303 |
do_quantifier (pos = SOME false) T t' |
|
304 |
| Const (@{const_name Ex}, _) $ Abs (_, T, t') => |
|
305 |
do_quantifier (pos = SOME true) T t' |
|
38795
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38786
diff
changeset
|
306 |
| @{const HOL.conj} $ t1 $ t2 => fold (do_formula pos) [t1, t2] |
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38786
diff
changeset
|
307 |
| @{const HOL.disj} $ t1 $ t2 => fold (do_formula pos) [t1, t2] |
38786
e46e7a9cb622
formerly unnamed infix impliciation now named HOL.implies
haftmann
parents:
38752
diff
changeset
|
308 |
| @{const HOL.implies} $ t1 $ t2 => |
37537 | 309 |
do_formula (flip pos) t1 #> do_formula pos t2 |
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38829
diff
changeset
|
310 |
| Const (@{const_name HOL.eq}, Type (_, [T, _])) $ t1 $ t2 => |
38587
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
311 |
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
|
312 |
| 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
|
313 |
$ t1 $ t2 $ t3 => |
1317657d6aa9
fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents:
38395
diff
changeset
|
314 |
do_formula NONE t1 #> fold (do_term_or_formula T) [t2, t3] |
38939 | 315 |
| Const (@{const_name Ex1}, _) $ Abs (_, T, t') => |
316 |
do_quantifier (is_some pos) T t' |
|
317 |
| Const (@{const_name Ball}, _) $ t1 $ Abs (_, T, t') => |
|
318 |
do_quantifier (pos = SOME false) T |
|
319 |
(HOLogic.mk_imp (incr_boundvars 1 t1 $ Bound 0, t')) |
|
320 |
| Const (@{const_name Bex}, _) $ t1 $ Abs (_, T, t') => |
|
321 |
do_quantifier (pos = SOME true) T |
|
322 |
(HOLogic.mk_conj (incr_boundvars 1 t1 $ Bound 0, t')) |
|
37537 | 323 |
| (t0 as Const (_, @{typ bool})) $ t1 => |
324 |
do_term t0 #> do_formula pos t1 (* theory constant *) |
|
325 |
| _ => do_term t |
|
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
326 |
in Symtab.empty |> fold (do_formula pos) ts end |
24287 | 327 |
|
328 |
(*Inserts a dummy "constant" referring to the theory name, so that relevance |
|
329 |
takes the given theory into account.*) |
|
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
330 |
fun theory_constify ({theory_const_rel_weight, theory_const_irrel_weight, ...} |
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
331 |
: relevance_fudge) thy_name t = |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
332 |
if exists (curry (op <) 0.0) [theory_const_rel_weight, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
333 |
theory_const_irrel_weight] then |
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
334 |
Const (thy_name ^ theory_const_suffix, @{typ bool}) $ t |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
335 |
else |
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
336 |
t |
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
337 |
|
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
338 |
fun theory_const_prop_of fudge th = |
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
339 |
theory_constify fudge (Context.theory_name (theory_of_thm th)) (prop_of th) |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
340 |
|
24287 | 341 |
(**** Constant / Type Frequencies ****) |
342 |
||
38743 | 343 |
(* A two-dimensional symbol table counts frequencies of constants. It's keyed |
344 |
first by constant name and second by its list of type instantiations. For the |
|
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
345 |
latter, we need a linear ordering on "pattern list". *) |
24287 | 346 |
|
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
347 |
fun pattern_ord p = |
38743 | 348 |
case p of |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
349 |
(PVar, PVar) => EQUAL |
38823
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
350 |
| (PVar, PApp _) => LESS |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
351 |
| (PApp _, PVar) => GREATER |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
352 |
| (PApp q1, PApp q2) => |
828e68441a2f
renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents:
38822
diff
changeset
|
353 |
prod_ord fast_string_ord (dict_ord pattern_ord) (q1, q2) |
38939 | 354 |
fun ptype_ord (PType p, PType q) = |
355 |
prod_ord (dict_ord pattern_ord) int_ord (swap p, swap q) |
|
24287 | 356 |
|
38939 | 357 |
structure PType_Tab = Table(type key = ptype val ord = ptype_ord) |
24287 | 358 |
|
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
359 |
fun count_fact_consts thy fudge = |
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
360 |
let |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
361 |
fun do_const const (s, T) ts = |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
362 |
(* Two-dimensional table update. Constant maps to types maps to count. *) |
41204
bd57cf5944cb
get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents:
41202
diff
changeset
|
363 |
PType_Tab.map_default (rich_ptype thy const (s, T), 0) (Integer.add 1) |
38939 | 364 |
|> Symtab.map_default (s, PType_Tab.empty) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
365 |
#> fold do_term ts |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
366 |
and do_term t = |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
367 |
case strip_comb t of |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
368 |
(Const x, ts) => do_const true x ts |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
369 |
| (Free x, ts) => do_const false x ts |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
370 |
| (Abs (_, _, t'), ts) => fold do_term (t' :: ts) |
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
371 |
| (_, ts) => fold do_term ts |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
372 |
in do_term o theory_const_prop_of fudge o snd end |
24287 | 373 |
|
374 |
||
375 |
(**** Actual Filtering Code ****) |
|
376 |
||
39367 | 377 |
fun pow_int _ 0 = 1.0 |
38939 | 378 |
| pow_int x 1 = x |
379 |
| pow_int x n = if n > 0 then x * pow_int x (n - 1) else pow_int x (n + 1) / x |
|
380 |
||
24287 | 381 |
(*The frequency of a constant is the sum of those of all instances of its type.*) |
38824 | 382 |
fun pconst_freq match const_tab (c, ps) = |
38939 | 383 |
PType_Tab.fold (fn (qs, m) => match (ps, qs) ? Integer.add m) |
384 |
(the (Symtab.lookup const_tab c)) 0 |
|
38686 | 385 |
|
24287 | 386 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
387 |
(* 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
|
388 |
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
|
389 |
|
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
390 |
(* "log" seems best in practice. A constant function of one ignores the constant |
38938
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
391 |
frequencies. Rare constants give more points if they are relevant than less |
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
392 |
rare ones. *) |
39367 | 393 |
fun rel_weight_for _ freq = 1.0 + 2.0 / Math.ln (Real.fromInt freq + 1.0) |
38938
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
394 |
|
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
395 |
(* Irrelevant constants are treated differently. We associate lower penalties to |
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
396 |
very rare constants and very common ones -- the former because they can't |
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
397 |
lead to the inclusion of too many new facts, and the latter because they are |
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
398 |
so common as to be of little interest. *) |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
399 |
fun irrel_weight_for ({worse_irrel_freq, higher_order_irrel_weight, ...} |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
400 |
: relevance_fudge) order freq = |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
401 |
let val (k, x) = worse_irrel_freq |> `Real.ceil in |
38939 | 402 |
(if freq < k then Math.ln (Real.fromInt (freq + 1)) / Math.ln x |
403 |
else rel_weight_for order freq / rel_weight_for order k) |
|
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
404 |
* pow_int higher_order_irrel_weight (order - 1) |
38938
2b93dbc07778
improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents:
38937
diff
changeset
|
405 |
end |
37503
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
406 |
|
c2dfa26b9da6
cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents:
37502
diff
changeset
|
407 |
(* Computes a constant's weight, as determined by its frequency. *) |
38992
542474156c66
introduce fudge factors to deal with "theory const"
blanchet
parents:
38988
diff
changeset
|
408 |
fun generic_pconst_weight abs_weight skolem_weight theory_const_weight |
542474156c66
introduce fudge factors to deal with "theory const"
blanchet
parents:
38988
diff
changeset
|
409 |
weight_for f const_tab (c as (s, PType (m, _))) = |
38816 | 410 |
if s = abs_name then abs_weight |
411 |
else if String.isPrefix skolem_prefix s then skolem_weight |
|
38992
542474156c66
introduce fudge factors to deal with "theory const"
blanchet
parents:
38988
diff
changeset
|
412 |
else if String.isSuffix theory_const_suffix s then theory_const_weight |
38939 | 413 |
else weight_for m (pconst_freq (match_ptype o f) const_tab c) |
38821 | 414 |
|
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
415 |
fun rel_pconst_weight ({abs_rel_weight, theory_const_rel_weight, ...} |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
416 |
: relevance_fudge) const_tab = |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
417 |
generic_pconst_weight abs_rel_weight 0.0 theory_const_rel_weight |
38992
542474156c66
introduce fudge factors to deal with "theory const"
blanchet
parents:
38988
diff
changeset
|
418 |
rel_weight_for I const_tab |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
419 |
fun irrel_pconst_weight (fudge as {abs_irrel_weight, skolem_irrel_weight, |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
420 |
theory_const_irrel_weight, ...}) const_tab = |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
421 |
generic_pconst_weight abs_irrel_weight skolem_irrel_weight |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
422 |
theory_const_irrel_weight (irrel_weight_for fudge) swap |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
423 |
const_tab |
24287 | 424 |
|
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
425 |
fun locality_bonus (_ : relevance_fudge) General = 0.0 |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
426 |
| locality_bonus {intro_bonus, ...} Intro = intro_bonus |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
427 |
| locality_bonus {elim_bonus, ...} Elim = elim_bonus |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
428 |
| locality_bonus {simp_bonus, ...} Simp = simp_bonus |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
429 |
| locality_bonus {local_bonus, ...} Local = local_bonus |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
430 |
| locality_bonus {assum_bonus, ...} Assum = assum_bonus |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
431 |
| locality_bonus {chained_bonus, ...} Chained = chained_bonus |
38751
01c4d14b2a61
add a bonus for chained facts, since they are likely to be relevant;
blanchet
parents:
38749
diff
changeset
|
432 |
|
40418 | 433 |
fun is_odd_const_name s = |
434 |
s = abs_name orelse String.isPrefix skolem_prefix s orelse |
|
435 |
String.isSuffix theory_const_suffix s |
|
436 |
||
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
437 |
fun fact_weight fudge loc const_tab relevant_consts fact_consts = |
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
438 |
case fact_consts |> List.partition (pconst_hyper_mem I relevant_consts) |
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
439 |
||> filter_out (pconst_hyper_mem swap relevant_consts) of |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
440 |
([], _) => 0.0 |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
441 |
| (rel, irrel) => |
40418 | 442 |
if forall (forall (is_odd_const_name o fst)) [rel, irrel] then |
40371 | 443 |
0.0 |
444 |
else |
|
445 |
let |
|
446 |
val irrel = irrel |> filter_out (pconst_mem swap rel) |
|
447 |
val rel_weight = |
|
448 |
0.0 |> fold (curry (op +) o rel_pconst_weight fudge const_tab) rel |
|
449 |
val irrel_weight = |
|
450 |
~ (locality_bonus fudge loc) |
|
451 |
|> fold (curry (op +) o irrel_pconst_weight fudge const_tab) irrel |
|
452 |
val res = rel_weight / (rel_weight + irrel_weight) |
|
453 |
in if Real.isFinite res then res else 0.0 end |
|
38747 | 454 |
|
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
455 |
fun pconsts_in_fact thy is_built_in_const t = |
38825 | 456 |
Symtab.fold (fn (s, pss) => fold (cons o pair s) pss) |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
457 |
(pconsts_in_terms thy is_built_in_const true (SOME true) [t]) [] |
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
458 |
fun pair_consts_fact thy is_built_in_const fudge fact = |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
459 |
case fact |> snd |> theory_const_prop_of fudge |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
460 |
|> pconsts_in_fact thy is_built_in_const of |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
461 |
[] => NONE |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
462 |
| consts => SOME ((fact, consts), NONE) |
24287 | 463 |
|
38699 | 464 |
type annotated_thm = |
38939 | 465 |
(((unit -> string) * locality) * thm) * (string * ptype) list |
37505
d9af5c01dc4a
added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents:
37504
diff
changeset
|
466 |
|
38904 | 467 |
fun take_most_relevant max_relevant remaining_max |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
468 |
({max_imperfect, max_imperfect_exp, ...} : relevance_fudge) |
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
469 |
(candidates : (annotated_thm * real) list) = |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
470 |
let |
38747 | 471 |
val max_imperfect = |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
472 |
Real.ceil (Math.pow (max_imperfect, |
38904 | 473 |
Math.pow (Real.fromInt remaining_max |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
474 |
/ Real.fromInt max_relevant, max_imperfect_exp))) |
38747 | 475 |
val (perfect, imperfect) = |
38889 | 476 |
candidates |> sort (Real.compare o swap o pairself snd) |
477 |
|> take_prefix (fn (_, w) => w > 0.99999) |
|
38747 | 478 |
val ((accepts, more_rejects), rejects) = |
479 |
chop max_imperfect imperfect |>> append perfect |>> chop remaining_max |
|
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
480 |
in |
38889 | 481 |
trace_msg (fn () => |
482 |
"Actually passed (" ^ Int.toString (length accepts) ^ " of " ^ |
|
483 |
Int.toString (length candidates) ^ "): " ^ |
|
484 |
(accepts |> map (fn ((((name, _), _), _), weight) => |
|
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
485 |
name () ^ " [" ^ Real.toString weight ^ "]") |
38745
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
486 |
|> commas)); |
38747 | 487 |
(accepts, more_rejects @ rejects) |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
488 |
end |
24287 | 489 |
|
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
490 |
fun if_empty_replace_with_locality thy is_built_in_const facts loc tab = |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
491 |
if Symtab.is_empty tab then |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
492 |
pconsts_in_terms thy is_built_in_const false (SOME false) |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
493 |
(map_filter (fn ((_, loc'), th) => |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
494 |
if loc' = loc then SOME (prop_of th) else NONE) facts) |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
495 |
else |
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
496 |
tab |
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
497 |
|
41158
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
498 |
fun add_arities is_built_in_const th = |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
499 |
let |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
500 |
fun aux _ _ NONE = NONE |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
501 |
| aux t args (SOME tab) = |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
502 |
case t of |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
503 |
t1 $ t2 => SOME tab |> aux t1 (t2 :: args) |> aux t2 [] |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
504 |
| Const (x as (s, _)) => |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
505 |
(if is_built_in_const x args then |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
506 |
SOME tab |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
507 |
else case Symtab.lookup tab s of |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
508 |
NONE => SOME (Symtab.update (s, length args) tab) |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
509 |
| SOME n => if n = length args then SOME tab else NONE) |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
510 |
| _ => SOME tab |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
511 |
in aux (prop_of th) [] end |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
512 |
|
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
513 |
fun needs_ext is_built_in_const facts = |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
514 |
fold (add_arities is_built_in_const o snd) facts (SOME Symtab.empty) |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
515 |
|> is_none |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
516 |
|
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
517 |
fun relevance_filter ctxt threshold0 decay max_relevant is_built_in_const |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
518 |
(fudge as {threshold_divisor, ridiculous_threshold, ...}) |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
519 |
({add, del, ...} : relevance_override) facts goal_ts = |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
520 |
let |
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
521 |
val thy = ProofContext.theory_of ctxt |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
522 |
val const_tab = fold (count_fact_consts thy fudge) facts Symtab.empty |
38819
71c9f61516cd
if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents:
38818
diff
changeset
|
523 |
val goal_const_tab = |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
524 |
pconsts_in_terms thy is_built_in_const false (SOME false) goal_ts |
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
525 |
|> fold (if_empty_replace_with_locality thy is_built_in_const facts) |
38993
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
526 |
[Chained, Assum, Local] |
39012 | 527 |
val add_ths = Attrib.eval_thms ctxt add |
528 |
val del_ths = Attrib.eval_thms ctxt del |
|
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
529 |
val facts = facts |> filter_out (member Thm.eq_thm del_ths o snd) |
38747 | 530 |
fun iter j remaining_max threshold rel_const_tab hopeless hopeful = |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
531 |
let |
40191
257d2e06bfb8
put theorems added using "add:" at the beginning of the list returned by the relevance filter, so that they don't get truncated away
blanchet
parents:
40071
diff
changeset
|
532 |
fun relevant [] _ [] = |
38747 | 533 |
(* Nothing has been added this iteration. *) |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
534 |
if j = 0 andalso threshold >= ridiculous_threshold then |
38747 | 535 |
(* First iteration? Try again. *) |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
536 |
iter 0 max_relevant (threshold / threshold_divisor) rel_const_tab |
38747 | 537 |
hopeless hopeful |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
538 |
else |
40191
257d2e06bfb8
put theorems added using "add:" at the beginning of the list returned by the relevance filter, so that they don't get truncated away
blanchet
parents:
40071
diff
changeset
|
539 |
[] |
38889 | 540 |
| relevant candidates rejects [] = |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
541 |
let |
38747 | 542 |
val (accepts, more_rejects) = |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
543 |
take_most_relevant max_relevant remaining_max fudge candidates |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
544 |
val rel_const_tab' = |
38745
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
545 |
rel_const_tab |
41066
3890ef4e02f9
pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents:
40418
diff
changeset
|
546 |
|> fold (add_pconst_to_table false) (maps (snd o fst) accepts) |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
547 |
fun is_dirty (c, _) = |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
548 |
Symtab.lookup rel_const_tab' c <> Symtab.lookup rel_const_tab c |
38745
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
549 |
val (hopeful_rejects, hopeless_rejects) = |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
550 |
(rejects @ hopeless, ([], [])) |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
551 |
|-> fold (fn (ax as (_, consts), old_weight) => |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
552 |
if exists is_dirty consts then |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
553 |
apfst (cons (ax, NONE)) |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
554 |
else |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
555 |
apsnd (cons (ax, old_weight))) |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
556 |
|>> append (more_rejects |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
557 |
|> map (fn (ax as (_, consts), old_weight) => |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
558 |
(ax, if exists is_dirty consts then NONE |
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
559 |
else SOME old_weight))) |
38747 | 560 |
val threshold = |
38822
aa0101e618e2
fix threshold computation + remove "op =" from relevant constants
blanchet
parents:
38821
diff
changeset
|
561 |
1.0 - (1.0 - threshold) |
aa0101e618e2
fix threshold computation + remove "op =" from relevant constants
blanchet
parents:
38821
diff
changeset
|
562 |
* Math.pow (decay, Real.fromInt (length accepts)) |
38747 | 563 |
val remaining_max = remaining_max - length accepts |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
564 |
in |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
565 |
trace_msg (fn () => "New or updated constants: " ^ |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
566 |
commas (rel_const_tab' |> Symtab.dest |
38822
aa0101e618e2
fix threshold computation + remove "op =" from relevant constants
blanchet
parents:
38821
diff
changeset
|
567 |
|> subtract (op =) (rel_const_tab |> Symtab.dest) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
568 |
|> map string_for_hyper_pconst)); |
38745
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
569 |
map (fst o fst) accepts @ |
38747 | 570 |
(if remaining_max = 0 then |
40191
257d2e06bfb8
put theorems added using "add:" at the beginning of the list returned by the relevance filter, so that they don't get truncated away
blanchet
parents:
40071
diff
changeset
|
571 |
[] |
38745
ad577fd62ee4
reorganize options regarding to the relevance threshold and decay
blanchet
parents:
38744
diff
changeset
|
572 |
else |
38747 | 573 |
iter (j + 1) remaining_max threshold rel_const_tab' |
574 |
hopeless_rejects hopeful_rejects) |
|
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
575 |
end |
38889 | 576 |
| relevant candidates rejects |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
577 |
(((ax as (((_, loc), _), fact_consts)), cached_weight) |
38747 | 578 |
:: hopeful) = |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
579 |
let |
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
580 |
val weight = |
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
581 |
case cached_weight of |
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
582 |
SOME w => w |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
583 |
| NONE => fact_weight fudge loc const_tab rel_const_tab |
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
584 |
fact_consts |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
585 |
in |
38741 | 586 |
if weight >= threshold then |
38889 | 587 |
relevant ((ax, weight) :: candidates) rejects hopeful |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
588 |
else |
38889 | 589 |
relevant candidates ((ax, weight) :: rejects) hopeful |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
590 |
end |
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
591 |
in |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
592 |
trace_msg (fn () => |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
593 |
"ITERATION " ^ string_of_int j ^ ": current threshold: " ^ |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
594 |
Real.toString threshold ^ ", constants: " ^ |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
595 |
commas (rel_const_tab |> Symtab.dest |
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
596 |
|> filter (curry (op <>) [] o snd) |
38827
cf01645cbbce
extended relevance filter with first-order term matching
blanchet
parents:
38825
diff
changeset
|
597 |
|> map string_for_hyper_pconst)); |
38889 | 598 |
relevant [] [] hopeful |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
599 |
end |
41158
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
600 |
fun add_facts ths accepts = |
41167
b05014180288
move facts supplied with "add:" to the front, so that they get a better weight (SMT)
blanchet
parents:
41159
diff
changeset
|
601 |
(facts |> filter (member Thm.eq_thm ths o snd)) @ |
b05014180288
move facts supplied with "add:" to the front, so that they get a better weight (SMT)
blanchet
parents:
41159
diff
changeset
|
602 |
(accepts |> filter_out (member Thm.eq_thm ths o snd)) |
40408 | 603 |
|> take max_relevant |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
604 |
in |
40369
53dca3bd4250
use the SMT integration's official list of built-ins
blanchet
parents:
40251
diff
changeset
|
605 |
facts |> map_filter (pair_consts_fact thy is_built_in_const fudge) |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
606 |
|> iter 0 max_relevant threshold0 goal_const_tab [] |
41158
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
607 |
|> not (null add_ths) ? add_facts add_ths |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
608 |
|> (fn accepts => |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
609 |
accepts |> needs_ext is_built_in_const accepts |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
610 |
? add_facts @{thms ext}) |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
611 |
|> tap (fn accepts => trace_msg (fn () => |
8c9c31a757f5
make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents:
41140
diff
changeset
|
612 |
"Total relevant: " ^ Int.toString (length accepts))) |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
613 |
end |
24287 | 614 |
|
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
615 |
|
24287 | 616 |
(***************************************************************) |
19768
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
617 |
(* Retrieving and filtering lemmas *) |
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
618 |
(***************************************************************) |
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
619 |
|
33022
c95102496490
Removal of the unused atpset concept, the atp attribute and some related code.
paulson
parents:
32994
diff
changeset
|
620 |
(*** retrieve lemmas and filter them ***) |
19768
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
621 |
|
20757
fe84fe0dfd30
Definitions produced by packages are now blacklisted.
paulson
parents:
20661
diff
changeset
|
622 |
(*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
|
623 |
"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
|
624 |
fun is_package_def a = |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
625 |
let val names = Long_Name.explode a in |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
626 |
(length names > 2 andalso not (hd names = "local") andalso |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
627 |
String.isSuffix "_def" a) orelse String.isSuffix "_defs" a |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
628 |
end |
20757
fe84fe0dfd30
Definitions produced by packages are now blacklisted.
paulson
parents:
20661
diff
changeset
|
629 |
|
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
630 |
fun mk_fact_table f xs = |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
631 |
fold (Termtab.update o `(prop_of o f)) xs Termtab.empty |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
632 |
fun uniquify xs = Termtab.fold (cons o snd) (mk_fact_table snd xs) [] |
19768
9afd9b9c47d0
ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents:
19746
diff
changeset
|
633 |
|
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
634 |
(* FIXME: put other record thms here, or declare as "no_atp" *) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
635 |
val multi_base_blacklist = |
41199 | 636 |
["defs", "select_defs", "update_defs", "split", "splits", "split_asm", |
637 |
"cases", "ext_cases", "eq.simps", "eq.refl", "nchotomy", "case_cong", |
|
638 |
"weak_case_cong"] |
|
38682 | 639 |
|> map (prefix ".") |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
640 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
641 |
val max_lambda_nesting = 3 |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
642 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
643 |
fun term_has_too_many_lambdas max (t1 $ t2) = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
644 |
exists (term_has_too_many_lambdas max) [t1, t2] |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
645 |
| term_has_too_many_lambdas max (Abs (_, _, t)) = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
646 |
max = 0 orelse term_has_too_many_lambdas (max - 1) t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
647 |
| term_has_too_many_lambdas _ _ = false |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
648 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
649 |
(* 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
|
650 |
quantifiers. *) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
651 |
fun formula_has_too_many_lambdas Ts (Abs (_, T, t)) = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
652 |
formula_has_too_many_lambdas (T :: Ts) t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
653 |
| formula_has_too_many_lambdas Ts t = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
654 |
if is_formula_type (fastype_of1 (Ts, t)) then |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
655 |
exists (formula_has_too_many_lambdas Ts) (#2 (strip_comb t)) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
656 |
else |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
657 |
term_has_too_many_lambdas max_lambda_nesting t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
658 |
|
38692 | 659 |
(* The max apply depth of any "metis" call in "Metis_Examples" (on 2007-10-31) |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
660 |
was 11. *) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
661 |
val max_apply_depth = 15 |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
662 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
663 |
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
|
664 |
| apply_depth (Abs (_, _, t)) = apply_depth t |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
665 |
| apply_depth _ = 0 |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
666 |
|
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
667 |
fun is_formula_too_complex t = |
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
668 |
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
|
669 |
|
39946 | 670 |
(* FIXME: Extend to "Meson" and "Metis" *) |
37543 | 671 |
val exists_sledgehammer_const = |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
672 |
exists_Const (fn (s, _) => String.isPrefix sledgehammer_prefix s) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
673 |
|
38904 | 674 |
(* FIXME: make more reliable *) |
675 |
val exists_low_level_class_const = |
|
676 |
exists_Const (fn (s, _) => |
|
677 |
String.isSubstring (Long_Name.separator ^ "class" ^ Long_Name.separator) s) |
|
678 |
||
38821 | 679 |
fun is_metastrange_theorem th = |
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
680 |
case head_of (concl_of th) of |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
681 |
Const (a, _) => (a <> @{const_name Trueprop} andalso |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
682 |
a <> @{const_name "=="}) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
683 |
| _ => false |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
684 |
|
38821 | 685 |
fun is_that_fact th = |
686 |
String.isSuffix (Long_Name.separator ^ Obtain.thatN) (Thm.get_name_hint th) |
|
687 |
andalso exists_subterm (fn Free (s, _) => s = Name.skolem Auto_Bind.thesisN |
|
688 |
| _ => false) (prop_of th) |
|
689 |
||
37626
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
690 |
val type_has_top_sort = |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
691 |
exists_subtype (fn TFree (_, []) => true | TVar (_, []) => true | _ => false) |
1146291fe718
move blacklisting completely out of the clausifier;
blanchet
parents:
37616
diff
changeset
|
692 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
693 |
(**** 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
|
694 |
unsoundness) ****) |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21431
diff
changeset
|
695 |
|
38289
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
696 |
(* 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
|
697 |
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
|
698 |
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
|
699 |
guarantees soundness. *) |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21431
diff
changeset
|
700 |
|
38289
74dd8dd33512
adapt "too_general_equality" blacklisting to the new FOF context, where quantifiers are sometimes present
blanchet
parents:
38279
diff
changeset
|
701 |
(* 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
|
702 |
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
|
703 |
val is_exhaustive_finite = |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
704 |
let |
38629 | 705 |
fun is_bad_equal (Var z) t = |
706 |
not (exists_subterm (fn Var z' => z = z' | _ => false) t) |
|
707 |
| is_bad_equal (Bound j) t = not (loose_bvar1 (t, j)) |
|
708 |
| is_bad_equal _ _ = false |
|
709 |
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
|
710 |
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
|
711 |
case (pos, t) of |
38615
4e1d828ee514
improve "x = A | x = B | x = C"-style axiom detection
blanchet
parents:
38611
diff
changeset
|
712 |
(_, @{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
|
713 |
| (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
|
714 |
do_formula pos t' |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
715 |
| (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
|
716 |
do_formula pos t' |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
717 |
| (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
|
718 |
do_formula pos t' |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
719 |
| (_, @{const "==>"} $ t1 $ t2) => |
38629 | 720 |
do_formula (not pos) t1 andalso |
721 |
(t2 = @{prop False} orelse do_formula pos t2) |
|
38786
e46e7a9cb622
formerly unnamed infix impliciation now named HOL.implies
haftmann
parents:
38752
diff
changeset
|
722 |
| (_, @{const HOL.implies} $ t1 $ t2) => |
38629 | 723 |
do_formula (not pos) t1 andalso |
724 |
(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
|
725 |
| (_, @{const Not} $ t1) => do_formula (not pos) t1 |
38795
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38786
diff
changeset
|
726 |
| (true, @{const HOL.disj} $ t1 $ t2) => forall (do_formula pos) [t1, t2] |
848be46708dc
formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents:
38786
diff
changeset
|
727 |
| (false, @{const HOL.conj} $ t1 $ t2) => forall (do_formula pos) [t1, t2] |
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38829
diff
changeset
|
728 |
| (true, Const (@{const_name HOL.eq}, _) $ t1 $ t2) => do_equals t1 t2 |
38607
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
729 |
| (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
|
730 |
| _ => false |
a2abe8c2a1c2
generalize the "too general equality" code to handle facts like "x ~= A ==> x = B"
blanchet
parents:
38606
diff
changeset
|
731 |
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
|
732 |
|
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
|
733 |
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
|
734 |
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
|
735 |
| 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
|
736 |
| _ => false) |
21431
ef9080e7dbbc
Outputs a minimal number of arity clauses. Tidying of blacklist, fixing the blacklisting of thm lists
paulson
parents:
21397
diff
changeset
|
737 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
738 |
(* 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
|
739 |
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
|
740 |
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
|
741 |
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
|
742 |
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
|
743 |
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
|
744 |
|
38085
cc44e887246c
avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents:
38027
diff
changeset
|
745 |
(* 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
|
746 |
"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
|
747 |
are omitted. *) |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
748 |
fun is_dangerous_term no_dangerous_types t = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
749 |
not no_dangerous_types andalso |
38679
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
750 |
let val t = transform_elim_term t in |
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
751 |
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
|
752 |
is_exhaustive_finite t |
2cfd0777580f
destroy elim rules before checking for finite exhaustive facts
blanchet
parents:
38652
diff
changeset
|
753 |
end |
21470
7c1b59ddcd56
Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents:
21431
diff
changeset
|
754 |
|
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
755 |
fun is_theorem_bad_for_atps no_dangerous_types thm = |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
756 |
let val t = prop_of thm in |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
757 |
is_formula_too_complex t orelse exists_type type_has_top_sort t orelse |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
758 |
is_dangerous_term no_dangerous_types t orelse |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
759 |
exists_sledgehammer_const t orelse exists_low_level_class_const t orelse |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
760 |
is_metastrange_theorem thm orelse is_that_fact thm |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
761 |
end |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
762 |
|
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
763 |
fun clasimpset_rules_of ctxt = |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
764 |
let |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
765 |
val {safeIs, safeEs, hazIs, hazEs, ...} = ctxt |> claset_of |> rep_cs |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
766 |
val intros = safeIs @ hazIs |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
767 |
val elims = map Classical.classical_rule (safeEs @ hazEs) |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
768 |
val simps = ctxt |> simpset_of |> dest_ss |> #simps |> map snd |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
769 |
in (mk_fact_table I intros, mk_fact_table I elims, mk_fact_table I simps) end |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
770 |
|
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
771 |
fun all_facts ctxt reserved no_dangerous_types |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
772 |
({intro_bonus, elim_bonus, simp_bonus, ...} : relevance_fudge) |
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
773 |
add_ths chained_ths = |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
774 |
let |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
775 |
val thy = ProofContext.theory_of ctxt |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39367
diff
changeset
|
776 |
val global_facts = Global_Theory.facts_of thy |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
777 |
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
|
778 |
val named_locals = local_facts |> Facts.dest_static [] |
38993
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
779 |
val assms = Assumption.all_assms_of ctxt |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
780 |
fun is_assum th = exists (fn ct => prop_of th aconv term_of ct) assms |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
781 |
val is_chained = member Thm.eq_thm chained_ths |
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
782 |
val (intros, elims, simps) = |
40070
bdb890782d4a
replaced references with proper record that's threaded through
blanchet
parents:
39958
diff
changeset
|
783 |
if exists (curry (op <) 0.0) [intro_bonus, elim_bonus, simp_bonus] then |
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
784 |
clasimpset_rules_of ctxt |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
785 |
else |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
786 |
(Termtab.empty, Termtab.empty, Termtab.empty) |
38738
0ce517c1970f
make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents:
38699
diff
changeset
|
787 |
fun is_good_unnamed_local th = |
38820
d0f98bd81a85
add nameless chained facts to the pool of things known to Sledgehammer
blanchet
parents:
38819
diff
changeset
|
788 |
not (Thm.has_name_hint th) andalso |
38738
0ce517c1970f
make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents:
38699
diff
changeset
|
789 |
forall (fn (_, ths) => not (member Thm.eq_thm ths th)) named_locals |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
790 |
val unnamed_locals = |
38820
d0f98bd81a85
add nameless chained facts to the pool of things known to Sledgehammer
blanchet
parents:
38819
diff
changeset
|
791 |
union Thm.eq_thm (Facts.props local_facts) chained_ths |
d0f98bd81a85
add nameless chained facts to the pool of things known to Sledgehammer
blanchet
parents:
38819
diff
changeset
|
792 |
|> filter is_good_unnamed_local |> map (pair "" o single) |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
793 |
val full_space = |
38738
0ce517c1970f
make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents:
38699
diff
changeset
|
794 |
Name_Space.merge (Facts.space_of global_facts, Facts.space_of local_facts) |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
795 |
fun add_facts global foldx facts = |
38699 | 796 |
foldx (fn (name0, ths) => |
797 |
if name0 <> "" andalso |
|
39012 | 798 |
forall (not o member Thm.eq_thm add_ths) ths andalso |
38699 | 799 |
(Facts.is_concealed facts name0 orelse |
800 |
(respect_no_atp andalso is_package_def name0) orelse |
|
801 |
exists (fn s => String.isSuffix s name0) multi_base_blacklist orelse |
|
802 |
String.isSuffix "_def_raw" (* FIXME: crude hack *) name0) then |
|
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
803 |
I |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
804 |
else |
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
805 |
let |
38699 | 806 |
val multi = length ths > 1 |
41199 | 807 |
val backquotify = |
808 |
enclose "`" "`" o string_for_term ctxt o close_form o prop_of |
|
38699 | 809 |
fun check_thms a = |
810 |
case try (ProofContext.get_thms ctxt) a of |
|
811 |
NONE => false |
|
812 |
| SOME ths' => Thm.eq_thms (ths, ths') |
|
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
813 |
in |
38699 | 814 |
pair 1 |
815 |
#> fold (fn th => fn (j, rest) => |
|
816 |
(j + 1, |
|
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
817 |
if is_theorem_bad_for_atps no_dangerous_types th andalso |
39012 | 818 |
not (member Thm.eq_thm add_ths th) then |
38699 | 819 |
rest |
820 |
else |
|
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
821 |
(((fn () => |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
822 |
if name0 = "" then |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
823 |
th |> backquotify |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
824 |
else |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
825 |
let |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
826 |
val name1 = Facts.extern facts name0 |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
827 |
val name2 = Name_Space.extern full_space name0 |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
828 |
in |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
829 |
case find_first check_thms [name1, name2, name0] of |
40375
db690d38e4b9
fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents:
40373
diff
changeset
|
830 |
SOME name => make_name reserved multi j name |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
831 |
| NONE => "" |
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
832 |
end), |
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
833 |
let val t = prop_of th in |
40071
658a37c80b53
generalized the relevance filter so that it takes the list of "irrelevant constants" as argument (since the ATP and SMT preprocessing are different)
blanchet
parents:
40070
diff
changeset
|
834 |
if is_chained th then |
658a37c80b53
generalized the relevance filter so that it takes the list of "irrelevant constants" as argument (since the ATP and SMT preprocessing are different)
blanchet
parents:
40070
diff
changeset
|
835 |
Chained |
38993
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
836 |
else if global then |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
837 |
if Termtab.defined intros t then Intro |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
838 |
else if Termtab.defined elims t then Elim |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
839 |
else if Termtab.defined simps t then Simp |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
840 |
else General |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
841 |
else |
504b9e1efd33
give priority to assumptions in structured proofs
blanchet
parents:
38992
diff
changeset
|
842 |
if is_assum th then Assum else Local |
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
843 |
end), |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
844 |
(multi, th)) :: rest)) ths |
38699 | 845 |
#> snd |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
846 |
end) |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
847 |
in |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
848 |
[] |> add_facts false fold local_facts (unnamed_locals @ named_locals) |
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
849 |
|> add_facts true Facts.fold_static global_facts global_facts |
38644
25bbbaf7ce65
don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents:
38629
diff
changeset
|
850 |
end |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
851 |
|
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
852 |
(* 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
|
853 |
names are preferred when both are available. *) |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
854 |
fun rearrange_facts ctxt respect_no_atp = |
38744
2b6333f78a9e
make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents:
38743
diff
changeset
|
855 |
List.partition (fst o snd) #> op @ #> map (apsnd snd) |
38699 | 856 |
#> respect_no_atp ? filter_out (No_ATPs.member ctxt o snd) |
38627
760a2d5cc671
make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents:
38617
diff
changeset
|
857 |
|
41199 | 858 |
fun external_frees t = |
859 |
[] |> Term.add_frees t |> filter_out (can Name.dest_internal o fst) |
|
860 |
||
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
861 |
fun relevant_facts ctxt no_dangerous_types (threshold0, threshold1) |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
862 |
max_relevant is_built_in_const fudge |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
863 |
(override as {add, only, ...}) 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
|
864 |
let |
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
865 |
val thy = ProofContext.theory_of ctxt |
38822
aa0101e618e2
fix threshold computation + remove "op =" from relevant constants
blanchet
parents:
38821
diff
changeset
|
866 |
val decay = Math.pow ((1.0 - threshold1) / (1.0 - threshold0), |
aa0101e618e2
fix threshold computation + remove "op =" from relevant constants
blanchet
parents:
38821
diff
changeset
|
867 |
1.0 / Real.fromInt (max_relevant + 1)) |
39012 | 868 |
val add_ths = Attrib.eval_thms ctxt add |
38696
4c6b65d6a135
quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents:
38692
diff
changeset
|
869 |
val reserved = reserved_isar_keyword_table () |
41199 | 870 |
val ind_stmt = |
871 |
Logic.list_implies (hyp_ts |> filter_out (null o external_frees), concl_t) |
|
872 |
|> atomize_term |
|
873 |
val ind_stmt_xs = external_frees ind_stmt |
|
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
874 |
val facts = |
38699 | 875 |
(if only then |
38752
6628adcae4a7
consider "locality" when assigning weights to facts
blanchet
parents:
38751
diff
changeset
|
876 |
maps (map (fn ((name, loc), th) => ((K name, loc), (true, th))) |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
877 |
o fact_from_ref ctxt reserved chained_ths) add |
38699 | 878 |
else |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
41066
diff
changeset
|
879 |
all_facts ctxt reserved no_dangerous_types fudge add_ths chained_ths) |
41199 | 880 |
|> maps (instantiate_if_induct_rule ctxt ind_stmt ind_stmt_xs) |
40205
277508b07418
if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents:
40204
diff
changeset
|
881 |
|> rearrange_facts ctxt (respect_no_atp andalso not only) |
38937
1b1a2f5ccd7d
take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents:
38907
diff
changeset
|
882 |
|> uniquify |
37538
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
883 |
in |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
884 |
trace_msg (fn () => "Considering " ^ Int.toString (length facts) ^ |
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
885 |
" facts"); |
39366
f58fbb959826
handle relevance filter corner cases more gracefully;
blanchet
parents:
39265
diff
changeset
|
886 |
(if only orelse threshold1 < 0.0 then |
40204
da97d75e20e6
standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents:
40191
diff
changeset
|
887 |
facts |
39366
f58fbb959826
handle relevance filter corner cases more gracefully;
blanchet
parents:
39265
diff
changeset
|
888 |
else if threshold0 > 1.0 orelse threshold0 > threshold1 orelse |
f58fbb959826
handle relevance filter corner cases more gracefully;
blanchet
parents:
39265
diff
changeset
|
889 |
max_relevant = 0 then |
38739
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
890 |
[] |
8b8ed80b5699
renamed "relevance_convergence" to "relevance_decay"
blanchet
parents:
38738
diff
changeset
|
891 |
else |
41200
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
892 |
((concl_t |> theory_constify fudge (Context.theory_name thy)) :: hyp_ts) |
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
893 |
|> relevance_filter ctxt threshold0 decay max_relevant is_built_in_const |
6cc9b6fd7f6f
add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents:
41199
diff
changeset
|
894 |
fudge override facts) |
38822
aa0101e618e2
fix threshold computation + remove "op =" from relevant constants
blanchet
parents:
38821
diff
changeset
|
895 |
|> map (apfst (apfst (fn f => f ()))) |
37538
97ab019d5ac8
make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents:
37537
diff
changeset
|
896 |
end |
30536
07b4f050e4df
split relevance-filter and writing of problem-files;
immler@in.tum.de
parents:
30364
diff
changeset
|
897 |
|
15347 | 898 |
end; |