author | blanchet |
Tue, 01 Jul 2014 16:47:10 +0200 | |
changeset 57469 | 29e7e6e89a0e |
parent 57468 | 4d906d67c93b |
child 57727 | 02a53c1bbb6c |
permissions | -rw-r--r-- |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_fact.ML |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
2 |
Author: Jia Meng, Cambridge University Computer Laboratory and NICTA |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
3 |
Author: Jasmin Blanchette, TU Muenchen |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
4 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
5 |
Sledgehammer fact handling. |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
6 |
*) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
7 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
8 |
signature SLEDGEHAMMER_FACT = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
9 |
sig |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
10 |
type status = ATP_Problem_Generate.status |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
11 |
type stature = ATP_Problem_Generate.stature |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
12 |
|
51004
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
13 |
type raw_fact = ((unit -> string) * stature) * thm |
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
14 |
type fact = (string * stature) * thm |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48292
diff
changeset
|
15 |
|
48292 | 16 |
type fact_override = |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
17 |
{add : (Facts.ref * Attrib.src list) list, |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
18 |
del : (Facts.ref * Attrib.src list) list, |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
19 |
only : bool} |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
20 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
21 |
val instantiate_inducts : bool Config.T |
48292 | 22 |
val no_fact_override : fact_override |
55212 | 23 |
|
24 |
val fact_of_ref : Proof.context -> unit Symtab.table -> thm list -> status Termtab.table -> |
|
25 |
Facts.ref * Attrib.src list -> ((string * stature) * thm) list |
|
50047
45684acf0b94
thread context correctly when printing backquoted facts
blanchet
parents:
49981
diff
changeset
|
26 |
val backquote_thm : Proof.context -> thm -> string |
50511
8825c36cb1ce
don't query blacklisted theorems in evaluation driver
blanchet
parents:
50510
diff
changeset
|
27 |
val is_blacklisted_or_something : Proof.context -> bool -> string -> bool |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
28 |
val clasimpset_rule_table_of : Proof.context -> status Termtab.table |
55212 | 29 |
val build_name_tables : (thm -> string) -> ('a * thm) list -> |
30 |
string Symtab.table * string Symtab.table |
|
31 |
val maybe_instantiate_inducts : Proof.context -> term list -> term -> |
|
32 |
(((unit -> string) * 'a) * thm) list -> (((unit -> string) * 'a) * thm) list |
|
51004
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
33 |
val fact_of_raw_fact : raw_fact -> fact |
55212 | 34 |
|
35 |
val all_facts : Proof.context -> bool -> bool -> unit Symtab.table -> thm list -> thm list -> |
|
36 |
status Termtab.table -> raw_fact list |
|
37 |
val nearly_all_facts : Proof.context -> bool -> fact_override -> unit Symtab.table -> |
|
38 |
status Termtab.table -> thm list -> term list -> term -> raw_fact list |
|
54142
5f3c1b445253
no fact subsumption -- this only confuses later code, e.g. 'add:'
blanchet
parents:
54112
diff
changeset
|
39 |
val drop_duplicate_facts : raw_fact list -> raw_fact list |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
40 |
end; |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
41 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
42 |
structure Sledgehammer_Fact : SLEDGEHAMMER_FACT = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
43 |
struct |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
44 |
|
50495
bd9a0028b063
better tautology check -- don't reject "prod_cases3" for example
blanchet
parents:
50490
diff
changeset
|
45 |
open ATP_Util |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
46 |
open ATP_Problem_Generate |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
47 |
open Sledgehammer_Util |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
48 |
|
51004
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
49 |
type raw_fact = ((unit -> string) * stature) * thm |
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
50 |
type fact = (string * stature) * thm |
48296
e7f01b7e244e
gracefully handle the case of empty theories when going up the accessibility chain
blanchet
parents:
48292
diff
changeset
|
51 |
|
48292 | 52 |
type fact_override = |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
53 |
{add : (Facts.ref * Attrib.src list) list, |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
54 |
del : (Facts.ref * Attrib.src list) list, |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
55 |
only : bool} |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
56 |
|
54080
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
57 |
(* gracefully handle huge background theories *) |
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
58 |
val max_facts_for_duplicates = 50000 |
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
59 |
val max_facts_for_complex_check = 25000 |
54083
824db6ab3339
crank up limit a bit -- truly huge background theories are still nearly 3 times larger
blanchet
parents:
54081
diff
changeset
|
60 |
val max_simps_for_clasimpset = 10000 |
54080
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
61 |
|
53511
3ea6b9461c55
got rid of another slowdown factor in relevance filter
blanchet
parents:
53510
diff
changeset
|
62 |
(* experimental feature *) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
63 |
val instantiate_inducts = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
64 |
Attrib.setup_config_bool @{binding sledgehammer_instantiate_inducts} (K false) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
65 |
|
48292 | 66 |
val no_fact_override = {add = [], del = [], only = false} |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
67 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
68 |
fun needs_quoting reserved s = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
69 |
Symtab.defined reserved s orelse |
50239 | 70 |
exists (not o Symbol_Pos.is_identifier) (Long_Name.explode s) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
71 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
72 |
fun make_name reserved multi j name = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
73 |
(name |> needs_quoting reserved name ? quote) ^ |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
74 |
(if multi then "(" ^ string_of_int j ^ ")" else "") |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
75 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
76 |
fun explode_interval _ (Facts.FromTo (i, j)) = i upto j |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
77 |
| explode_interval max (Facts.From i) = i upto i + max - 1 |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
78 |
| explode_interval _ (Facts.Single i) = [i] |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
79 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
80 |
val backquote = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
81 |
raw_explode #> map (fn "`" => "\\`" | s => s) #> implode #> enclose "`" "`" |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
82 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
83 |
(* unfolding these can yield really huge terms *) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
84 |
val risky_defs = @{thms Bit0_def Bit1_def} |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
85 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
86 |
fun is_rec_eq lhs = Term.exists_subterm (curry (op =) (head_of lhs)) |
57468 | 87 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
88 |
fun is_rec_def (@{const Trueprop} $ t) = is_rec_def t |
56245 | 89 |
| is_rec_def (@{const Pure.imp} $ _ $ t2) = is_rec_def t2 |
90 |
| is_rec_def (Const (@{const_name Pure.eq}, _) $ t1 $ t2) = is_rec_eq t1 t2 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
91 |
| is_rec_def (Const (@{const_name HOL.eq}, _) $ t1 $ t2) = is_rec_eq t1 t2 |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
92 |
| is_rec_def _ = false |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
93 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
94 |
fun is_assum assms th = exists (fn ct => prop_of th aconv term_of ct) assms |
48396 | 95 |
fun is_chained chained = member Thm.eq_thm_prop chained |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
96 |
|
48396 | 97 |
fun scope_of_thm global assms chained th = |
98 |
if is_chained chained th then Chained |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
99 |
else if global then Global |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
100 |
else if is_assum assms th then Assum |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
101 |
else Local |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
102 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
103 |
val may_be_induction = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
104 |
exists_subterm (fn Var (_, Type (@{type_name fun}, [_, T])) => |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
105 |
body_type T = @{typ bool} |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
106 |
| _ => false) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
107 |
|
54077 | 108 |
(* TODO: get rid of *) |
53501 | 109 |
fun normalize_vars t = |
110 |
let |
|
111 |
fun normT (Type (s, Ts)) = fold_map normT Ts #>> curry Type s |
|
112 |
| normT (TVar (z as (_, S))) = |
|
113 |
(fn ((knownT, nT), accum) => |
|
55286 | 114 |
(case find_index (equal z) knownT of |
53501 | 115 |
~1 => (TVar ((Name.uu, nT), S), ((z :: knownT, nT + 1), accum)) |
55286 | 116 |
| j => (TVar ((Name.uu, nT - j - 1), S), ((knownT, nT), accum)))) |
53501 | 117 |
| normT (T as TFree _) = pair T |
57468 | 118 |
|
53501 | 119 |
fun norm (t $ u) = norm t ##>> norm u #>> op $ |
120 |
| norm (Const (s, T)) = normT T #>> curry Const s |
|
121 |
| norm (Var (z as (_, T))) = |
|
122 |
normT T |
|
123 |
#> (fn (T, (accumT, (known, n))) => |
|
55286 | 124 |
(case find_index (equal z) known of |
53501 | 125 |
~1 => (Var ((Name.uu, n), T), (accumT, (z :: known, n + 1))) |
55286 | 126 |
| j => (Var ((Name.uu, n - j - 1), T), (accumT, (known, n))))) |
53501 | 127 |
| norm (Abs (_, T, t)) = |
128 |
norm t ##>> normT T #>> (fn (t, T) => Abs (Name.uu, T, t)) |
|
129 |
| norm (Bound j) = pair (Bound j) |
|
130 |
| norm (Free (s, T)) = normT T #>> curry Free s |
|
131 |
in fst (norm t (([], 0), ([], 0))) end |
|
132 |
||
48396 | 133 |
fun status_of_thm css name th = |
54081 | 134 |
if Termtab.is_empty css then |
135 |
General |
|
136 |
else |
|
137 |
let val t = prop_of th in |
|
138 |
(* FIXME: use structured name *) |
|
139 |
if String.isSubstring ".induct" name andalso may_be_induction t then |
|
140 |
Induction |
|
141 |
else |
|
142 |
let val t = normalize_vars t in |
|
55286 | 143 |
(case Termtab.lookup css t of |
54081 | 144 |
SOME status => status |
145 |
| NONE => |
|
146 |
let val concl = Logic.strip_imp_concl t in |
|
55286 | 147 |
(case try (HOLogic.dest_eq o HOLogic.dest_Trueprop) concl of |
54081 | 148 |
SOME lrhss => |
149 |
let |
|
150 |
val prems = Logic.strip_imp_prems t |
|
151 |
val t' = Logic.list_implies (prems, Logic.mk_equals lrhss) |
|
152 |
in |
|
153 |
Termtab.lookup css t' |> the_default General |
|
154 |
end |
|
55286 | 155 |
| NONE => General) |
156 |
end) |
|
54081 | 157 |
end |
158 |
end |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
159 |
|
48396 | 160 |
fun stature_of_thm global assms chained css name th = |
161 |
(scope_of_thm global assms chained th, status_of_thm css name th) |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
162 |
|
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
163 |
fun fact_of_ref ctxt reserved chained css (xthm as (xref, args)) = |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
164 |
let |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
165 |
val ths = Attrib.eval_thms ctxt [xthm] |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
166 |
val bracket = |
56032
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
wenzelm
parents:
56027
diff
changeset
|
167 |
map (enclose "[" "]" o Pretty.str_of o Args.pretty_src ctxt) args |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
168 |
|> implode |
57468 | 169 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
170 |
fun nth_name j = |
55286 | 171 |
(case xref of |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
172 |
Facts.Fact s => backquote s ^ bracket |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
173 |
| Facts.Named (("", _), _) => "[" ^ bracket ^ "]" |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
174 |
| Facts.Named ((name, _), NONE) => |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
175 |
make_name reserved (length ths > 1) (j + 1) name ^ bracket |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
176 |
| Facts.Named ((name, _), SOME intervals) => |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
177 |
make_name reserved true |
55286 | 178 |
(nth (maps (explode_interval (length ths)) intervals) j) name ^ bracket) |
57468 | 179 |
|
48396 | 180 |
fun add_nth th (j, rest) = |
181 |
let val name = nth_name j in |
|
182 |
(j + 1, ((name, stature_of_thm false [] chained css name th), th) |
|
183 |
:: rest) |
|
184 |
end |
|
57468 | 185 |
in |
186 |
(0, []) |> fold add_nth ths |> snd |
|
187 |
end |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
188 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
189 |
(* Reject theorems with names like "List.filter.filter_list_def" or |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
190 |
"Accessible_Part.acc.defs", as these are definitions arising from packages. *) |
50736 | 191 |
fun is_package_def s = |
192 |
let val ss = Long_Name.explode s in |
|
193 |
length ss > 2 andalso not (hd ss = "local") andalso |
|
194 |
exists (fn suf => String.isSuffix suf s) |
|
195 |
["_case_def", "_rec_def", "_size_def", "_size_overloaded_def"] |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
196 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
197 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
198 |
(* FIXME: put other record thms here, or declare as "no_atp" *) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
199 |
fun multi_base_blacklist ctxt ho_atp = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
200 |
["defs", "select_defs", "update_defs", "split", "splits", "split_asm", |
50442
4f6a4d32522c
don't blacklist "case" theorems -- this causes problems in MaSh later
blanchet
parents:
50239
diff
changeset
|
201 |
"ext_cases", "eq.simps", "eq.refl", "nchotomy", "case_cong", |
51160
599ff65b85e2
systematic conversions between nat and nibble/char;
haftmann
parents:
51126
diff
changeset
|
202 |
"weak_case_cong", "nat_of_char_simps", "nibble.simps", |
48440
159e320ef851
identified "evil" theories for MaSh -- this is rather ad hoc, but so is MaSh anyway
blanchet
parents:
48438
diff
changeset
|
203 |
"nibble.distinct"] |
53531 | 204 |
|> not (ho_atp orelse Config.get ctxt instantiate_inducts) ? |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
205 |
append ["induct", "inducts"] |
48440
159e320ef851
identified "evil" theories for MaSh -- this is rather ad hoc, but so is MaSh anyway
blanchet
parents:
48438
diff
changeset
|
206 |
|> map (prefix Long_Name.separator) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
207 |
|
53529
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
208 |
(* The maximum apply depth of any "metis" call in "Metis_Examples" (on |
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
209 |
2007-10-31) was 11. *) |
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
210 |
val max_apply_depth = 18 |
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
211 |
|
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
212 |
fun apply_depth (f $ t) = Int.max (apply_depth f, apply_depth t + 1) |
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
213 |
| apply_depth (Abs (_, _, t)) = apply_depth t |
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
214 |
| apply_depth _ = 0 |
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
215 |
|
53533 | 216 |
fun is_too_complex t = apply_depth t > max_apply_depth |
53529
1eb7c65b526c
reverted f99ee3adb81d -- that old logic seems to make a difference still today
blanchet
parents:
53513
diff
changeset
|
217 |
|
48667
ac58317ef11f
rule out same "technical" theories for MePo as for MaSh
blanchet
parents:
48530
diff
changeset
|
218 |
(* FIXME: Ad hoc list *) |
ac58317ef11f
rule out same "technical" theories for MePo as for MaSh
blanchet
parents:
48530
diff
changeset
|
219 |
val technical_prefixes = |
51126
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
51004
diff
changeset
|
220 |
["ATP", "Code_Evaluation", "Datatype", "Enum", "Lazy_Sequence", |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
51004
diff
changeset
|
221 |
"Limited_Sequence", "Meson", "Metis", "Nitpick", |
df86080de4cb
reform of predicate compiler / quickcheck theories:
haftmann
parents:
51004
diff
changeset
|
222 |
"Quickcheck_Random", "Quickcheck_Exhaustive", "Quickcheck_Narrowing", |
50736 | 223 |
"Random_Sequence", "Sledgehammer", "SMT"] |
48667
ac58317ef11f
rule out same "technical" theories for MePo as for MaSh
blanchet
parents:
48530
diff
changeset
|
224 |
|> map (suffix Long_Name.separator) |
48440
159e320ef851
identified "evil" theories for MaSh -- this is rather ad hoc, but so is MaSh anyway
blanchet
parents:
48438
diff
changeset
|
225 |
|
53507 | 226 |
fun is_technical_const (s, _) = |
48667
ac58317ef11f
rule out same "technical" theories for MePo as for MaSh
blanchet
parents:
48530
diff
changeset
|
227 |
exists (fn pref => String.isPrefix pref s) technical_prefixes |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
228 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
229 |
(* FIXME: make more reliable *) |
53507 | 230 |
val sep_class_sep = Long_Name.separator ^ "class" ^ Long_Name.separator |
57468 | 231 |
|
53507 | 232 |
fun is_low_level_class_const (s, _) = |
233 |
s = @{const_name equal_class.equal} orelse String.isSubstring sep_class_sep s |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
234 |
|
53509 | 235 |
val sep_that = Long_Name.separator ^ Obtain.thatN |
236 |
||
54081 | 237 |
val skolem_thesis = Name.skolem Auto_Bind.thesisN |
238 |
||
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
239 |
fun is_that_fact th = |
54081 | 240 |
exists_subterm (fn Free (s, _) => s = skolem_thesis | _ => false) (prop_of th) |
241 |
andalso String.isSuffix sep_that (Thm.get_name_hint th) |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
242 |
|
53513 | 243 |
datatype interest = Deal_Breaker | Interesting | Boring |
244 |
||
245 |
fun combine_interests Deal_Breaker _ = Deal_Breaker |
|
246 |
| combine_interests _ Deal_Breaker = Deal_Breaker |
|
247 |
| combine_interests Interesting _ = Interesting |
|
248 |
| combine_interests _ Interesting = Interesting |
|
249 |
| combine_interests Boring Boring = Boring |
|
250 |
||
54914
25212efcd0de
removed pointless warning (cf. http://stackoverflow.com/questions/20233463/isabelle-metis-proof-state-contains-the-universal-sort/20785045#20785045)
blanchet
parents:
54503
diff
changeset
|
251 |
val type_has_top_sort = |
25212efcd0de
removed pointless warning (cf. http://stackoverflow.com/questions/20233463/isabelle-metis-proof-state-contains-the-universal-sort/20785045#20785045)
blanchet
parents:
54503
diff
changeset
|
252 |
exists_subtype (fn TFree (_, []) => true | TVar (_, []) => true | _ => false) |
25212efcd0de
removed pointless warning (cf. http://stackoverflow.com/questions/20233463/isabelle-metis-proof-state-contains-the-universal-sort/20785045#20785045)
blanchet
parents:
54503
diff
changeset
|
253 |
|
50523
0799339fea0f
get rid of some junk facts in the MaSh evaluation driver
blanchet
parents:
50512
diff
changeset
|
254 |
fun is_likely_tautology_too_meta_or_too_technical th = |
48406 | 255 |
let |
50053
fea589c8583e
fixed detection of tautologies -- things like "a = b" in a structured proof, where a and b are Frees, shouldn't be discarted as tautologies
blanchet
parents:
50049
diff
changeset
|
256 |
fun is_interesting_subterm (Const (s, _)) = |
fea589c8583e
fixed detection of tautologies -- things like "a = b" in a structured proof, where a and b are Frees, shouldn't be discarted as tautologies
blanchet
parents:
50049
diff
changeset
|
257 |
not (member (op =) atp_widely_irrelevant_consts s) |
fea589c8583e
fixed detection of tautologies -- things like "a = b" in a structured proof, where a and b are Frees, shouldn't be discarted as tautologies
blanchet
parents:
50049
diff
changeset
|
258 |
| is_interesting_subterm (Free _) = true |
fea589c8583e
fixed detection of tautologies -- things like "a = b" in a structured proof, where a and b are Frees, shouldn't be discarted as tautologies
blanchet
parents:
50049
diff
changeset
|
259 |
| is_interesting_subterm _ = false |
57468 | 260 |
|
53513 | 261 |
fun interest_of_bool t = |
53545
f7e987ef7304
reintroduced 8d8f72aa5c0b, which does make a small difference in practice, but implemented more efficiently
blanchet
parents:
53533
diff
changeset
|
262 |
if exists_Const (is_technical_const orf is_low_level_class_const orf |
f7e987ef7304
reintroduced 8d8f72aa5c0b, which does make a small difference in practice, but implemented more efficiently
blanchet
parents:
53533
diff
changeset
|
263 |
type_has_top_sort o snd) t then |
53513 | 264 |
Deal_Breaker |
265 |
else if exists_type (exists_subtype (curry (op =) @{typ prop})) t orelse |
|
266 |
not (exists_subterm is_interesting_subterm t) then |
|
267 |
Boring |
|
268 |
else |
|
269 |
Interesting |
|
57468 | 270 |
|
53513 | 271 |
fun interest_of_prop _ (@{const Trueprop} $ t) = interest_of_bool t |
56245 | 272 |
| interest_of_prop Ts (@{const Pure.imp} $ t $ u) = |
53513 | 273 |
combine_interests (interest_of_prop Ts t) (interest_of_prop Ts u) |
56245 | 274 |
| interest_of_prop Ts (Const (@{const_name Pure.all}, _) $ Abs (_, T, t)) = |
54040 | 275 |
if type_has_top_sort T then Deal_Breaker else interest_of_prop (T :: Ts) t |
56245 | 276 |
| interest_of_prop Ts ((t as Const (@{const_name Pure.all}, _)) $ u) = |
53513 | 277 |
interest_of_prop Ts (t $ eta_expand Ts u 1) |
56245 | 278 |
| interest_of_prop _ (Const (@{const_name Pure.eq}, _) $ t $ u) = |
53513 | 279 |
combine_interests (interest_of_bool t) (interest_of_bool u) |
280 |
| interest_of_prop _ _ = Deal_Breaker |
|
57468 | 281 |
|
50523
0799339fea0f
get rid of some junk facts in the MaSh evaluation driver
blanchet
parents:
50512
diff
changeset
|
282 |
val t = prop_of th |
48406 | 283 |
in |
53513 | 284 |
(interest_of_prop [] t <> Interesting andalso |
285 |
not (Thm.eq_thm_prop (@{thm ext}, th))) orelse |
|
53507 | 286 |
is_that_fact th |
48438
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
blanchet
parents:
48437
diff
changeset
|
287 |
end |
3e45c98fe127
distinguish between recursive and nonrecursive definitions + clean up typedef dependencies in MaSh
blanchet
parents:
48437
diff
changeset
|
288 |
|
53512 | 289 |
fun is_blacklisted_or_something ctxt ho_atp = |
57468 | 290 |
let val blist = multi_base_blacklist ctxt ho_atp in |
291 |
fn name => is_package_def name orelse exists (fn s => String.isSuffix s name) blist |
|
292 |
end |
|
50510 | 293 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
294 |
(* This is a terrible hack. Free variables are sometimes coded as "M__" when |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
295 |
they are displayed as "M" and we want to avoid clashes with these. But |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
296 |
sometimes it's even worse: "Ma__" encodes "M". So we simply reserve all |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
297 |
prefixes of all free variables. In the worse case scenario, where the fact |
49981 | 298 |
won't be resolved correctly, the user can fix it manually, e.g., by giving a |
299 |
name to the offending fact. *) |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
300 |
fun all_prefixes_of s = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
301 |
map (fn i => String.extract (s, 0, SOME i)) (1 upto size s - 1) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
302 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
303 |
fun close_form t = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
304 |
(t, [] |> Term.add_free_names t |> maps all_prefixes_of) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
305 |
|> fold (fn ((s, i), T) => fn (t', taken) => |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
306 |
let val s' = singleton (Name.variant_list taken) s in |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
307 |
((if fastype_of t' = HOLogic.boolT then HOLogic.all_const |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
308 |
else Logic.all_const) T |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
309 |
$ Abs (s', T, abstract_over (Var ((s, i), T), t')), |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
310 |
s' :: taken) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
311 |
end) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
312 |
(Term.add_vars t [] |> sort_wrt (fst o fst)) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
313 |
|> fst |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
314 |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51160
diff
changeset
|
315 |
fun backquote_term ctxt = close_form #> hackish_string_of_term ctxt #> backquote |
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51160
diff
changeset
|
316 |
fun backquote_thm ctxt = backquote_term ctxt o prop_of |
48394
82fc8c956cdc
fixed various issues with MaSh's file handling + tune output + generate local facts again + handle nameless facts gracefully
blanchet
parents:
48332
diff
changeset
|
317 |
|
54084 | 318 |
(* TODO: rewrite to use nets and/or to reuse existing data structures *) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
319 |
fun clasimpset_rule_table_of ctxt = |
53502 | 320 |
let val simps = ctxt |> simpset_of |> dest_ss |> #simps in |
321 |
if length simps >= max_simps_for_clasimpset then |
|
322 |
Termtab.empty |
|
323 |
else |
|
324 |
let |
|
325 |
fun add stature th = |
|
326 |
Termtab.update (normalize_vars (prop_of th), stature) |
|
57468 | 327 |
|
53502 | 328 |
val {safeIs, (* safeEs, *) hazIs, (* hazEs, *) ...} = |
329 |
ctxt |> claset_of |> Classical.rep_cs |
|
330 |
val intros = Item_Net.content safeIs @ Item_Net.content hazIs |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
331 |
(* Add once it is used: |
53502 | 332 |
val elims = |
333 |
Item_Net.content safeEs @ Item_Net.content hazEs |
|
334 |
|> map Classical.classical_rule |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
335 |
*) |
53502 | 336 |
val specs = ctxt |> Spec_Rules.get |
337 |
val (rec_defs, nonrec_defs) = |
|
338 |
specs |> filter (curry (op =) Spec_Rules.Equational o fst) |
|
339 |
|> maps (snd o snd) |
|
340 |
|> filter_out (member Thm.eq_thm_prop risky_defs) |
|
341 |
|> List.partition (is_rec_def o prop_of) |
|
342 |
val spec_intros = |
|
57468 | 343 |
specs |> filter (member (op =) [Spec_Rules.Inductive, Spec_Rules.Co_Inductive] o fst) |
53502 | 344 |
|> maps (snd o snd) |
345 |
in |
|
57468 | 346 |
Termtab.empty |
347 |
|> fold (add Simp o snd) simps |
|
348 |
|> fold (add Rec_Def) rec_defs |
|
349 |
|> fold (add Non_Rec_Def) nonrec_defs |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
350 |
(* Add once it is used: |
57468 | 351 |
|> fold (add Elim) elims |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
352 |
*) |
57468 | 353 |
|> fold (add Intro) intros |
354 |
|> fold (add Inductive) spec_intros |
|
53502 | 355 |
end |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
356 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
357 |
|
54092 | 358 |
fun normalize_eq (@{const Trueprop} $ (t as (t0 as Const (@{const_name HOL.eq}, _)) $ t1 $ t2)) = |
359 |
if Term_Ord.fast_term_ord (t1, t2) <> GREATER then t else t0 $ t2 $ t1 |
|
360 |
| normalize_eq (@{const Trueprop} $ (t as @{const Not} |
|
50481
5d147d492792
push normalization further -- avoid theorems that are duplicates of each other except for equality symmetry (esp. for "list.distinct(1)" vs. "(2)" etc.)
blanchet
parents:
50442
diff
changeset
|
361 |
$ ((t0 as Const (@{const_name HOL.eq}, _)) $ t1 $ t2))) = |
54092 | 362 |
if Term_Ord.fast_term_ord (t1, t2) <> GREATER then t else HOLogic.mk_not (t0 $ t2 $ t1) |
56245 | 363 |
| normalize_eq (Const (@{const_name Pure.eq}, Type (_, [T, _])) $ t1 $ t2) = |
54092 | 364 |
(if Term_Ord.fast_term_ord (t1, t2) <> GREATER then (t1, t2) else (t2, t1)) |
365 |
|> (fn (t1, t2) => HOLogic.eq_const T $ t1 $ t2) |
|
50481
5d147d492792
push normalization further -- avoid theorems that are duplicates of each other except for equality symmetry (esp. for "list.distinct(1)" vs. "(2)" etc.)
blanchet
parents:
50442
diff
changeset
|
366 |
| normalize_eq t = t |
5d147d492792
push normalization further -- avoid theorems that are duplicates of each other except for equality symmetry (esp. for "list.distinct(1)" vs. "(2)" etc.)
blanchet
parents:
50442
diff
changeset
|
367 |
|
50485
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50481
diff
changeset
|
368 |
fun if_thm_before th th' = |
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50481
diff
changeset
|
369 |
if Theory.subthy (pairself Thm.theory_of_thm (th, th')) then th else th' |
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50481
diff
changeset
|
370 |
|
57468 | 371 |
(* Hack: Conflate the facts about a class as seen from the outside with the corresponding low-level |
372 |
facts, so that MaSh can learn from the low-level proofs. *) |
|
50734 | 373 |
fun un_class_ify s = |
55286 | 374 |
(case first_field "_class" s of |
50734 | 375 |
SOME (pref, suf) => [s, pref ^ suf] |
55286 | 376 |
| NONE => [s]) |
50734 | 377 |
|
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50734
diff
changeset
|
378 |
fun build_name_tables name_of facts = |
50733 | 379 |
let |
54092 | 380 |
fun cons_thm (_, th) = Termtab.cons_list (normalize_vars (normalize_eq (prop_of th)), th) |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50734
diff
changeset
|
381 |
fun add_plain canon alias = |
54092 | 382 |
Symtab.update (Thm.get_name_hint alias, name_of (if_thm_before canon alias)) |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50734
diff
changeset
|
383 |
fun add_plains (_, aliases as canon :: _) = fold (add_plain canon) aliases |
54092 | 384 |
fun add_inclass (name, target) = fold (fn s => Symtab.update (s, target)) (un_class_ify name) |
50815 | 385 |
val prop_tab = fold cons_thm facts Termtab.empty |
50735
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50734
diff
changeset
|
386 |
val plain_name_tab = Termtab.fold add_plains prop_tab Symtab.empty |
6b232d76cbc9
refined class handling, to prevent cycles in fact graph
blanchet
parents:
50734
diff
changeset
|
387 |
val inclass_name_tab = Symtab.fold add_inclass plain_name_tab Symtab.empty |
57108
dc0b4f50e288
more generous max number of suggestions, for more safety
blanchet
parents:
56245
diff
changeset
|
388 |
in |
dc0b4f50e288
more generous max number of suggestions, for more safety
blanchet
parents:
56245
diff
changeset
|
389 |
(plain_name_tab, inclass_name_tab) |
dc0b4f50e288
more generous max number of suggestions, for more safety
blanchet
parents:
56245
diff
changeset
|
390 |
end |
50485
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50481
diff
changeset
|
391 |
|
54080
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
392 |
fun fact_distinct eq facts = |
54076 | 393 |
fold (fn fact as (_, th) => |
54080
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
394 |
Net.insert_term_safe (eq o pairself (normalize_eq o prop_of o snd)) |
54077 | 395 |
(normalize_eq (prop_of th), fact)) |
396 |
facts Net.empty |
|
54076 | 397 |
|> Net.entries |
53504 | 398 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
399 |
fun struct_induct_rule_on th = |
55286 | 400 |
(case Logic.strip_horn (prop_of th) of |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
401 |
(prems, @{const Trueprop} |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
402 |
$ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) => |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
403 |
if not (is_TVar ind_T) andalso length prems > 1 andalso |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
404 |
exists (exists_subterm (curry (op aconv) p)) prems andalso |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
405 |
not (exists (exists_subterm (curry (op aconv) a)) prems) then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
406 |
SOME (p_name, ind_T) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
407 |
else |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
408 |
NONE |
55286 | 409 |
| _ => NONE) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
410 |
|
50586 | 411 |
val instantiate_induct_timeout = seconds 0.01 |
412 |
||
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
413 |
fun instantiate_induct_rule ctxt concl_prop p_name ((name, stature), th) ind_x = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
414 |
let |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
415 |
fun varify_noninducts (t as Free (s, T)) = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
416 |
if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
417 |
| varify_noninducts t = t |
57468 | 418 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
419 |
val p_inst = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
420 |
concl_prop |> map_aterms varify_noninducts |> close_form |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
421 |
|> lambda (Free ind_x) |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51160
diff
changeset
|
422 |
|> hackish_string_of_term ctxt |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
423 |
in |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
424 |
((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]", |
55151 | 425 |
stature), th |> Rule_Insts.read_instantiate ctxt [((p_name, 0), p_inst)] []) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
426 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
427 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
428 |
fun type_match thy (T1, T2) = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
429 |
(Sign.typ_match thy (T2, T1) Vartab.empty; true) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
430 |
handle Type.TYPE_MATCH => false |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
431 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
432 |
fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, th)) = |
55286 | 433 |
(case struct_induct_rule_on th of |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
434 |
SOME (p_name, ind_T) => |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
435 |
let val thy = Proof_Context.theory_of ctxt in |
55286 | 436 |
stmt_xs |
437 |
|> filter (fn (_, T) => type_match thy (T, ind_T)) |
|
438 |
|> map_filter (try (TimeLimit.timeLimit instantiate_induct_timeout |
|
439 |
(instantiate_induct_rule ctxt stmt p_name ax))) |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
440 |
end |
55286 | 441 |
| NONE => [ax]) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
442 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
443 |
fun external_frees t = |
55948 | 444 |
[] |> Term.add_frees t |> filter_out (Name.is_internal o fst) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
445 |
|
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
446 |
fun maybe_instantiate_inducts ctxt hyp_ts concl_t = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
447 |
if Config.get ctxt instantiate_inducts then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
448 |
let |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
449 |
val thy = Proof_Context.theory_of ctxt |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
450 |
val ind_stmt = |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
451 |
(hyp_ts |> filter_out (null o external_frees), concl_t) |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
452 |
|> Logic.list_implies |> Object_Logic.atomize_term thy |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
453 |
val ind_stmt_xs = external_frees ind_stmt |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
454 |
in maps (instantiate_if_induct_rule ctxt ind_stmt ind_stmt_xs) end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
455 |
else |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
456 |
I |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
457 |
|
51004
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
458 |
fun fact_of_raw_fact ((name, stature), th) = ((name (), stature), th) |
5f2788c38127
distinguish raw and non-raw facts, using raw for 10 000s of facts and non-raw after selection of some hundreds
blanchet
parents:
50815
diff
changeset
|
459 |
|
53532
4ad9599a0847
disable some checks for huge background theories
blanchet
parents:
53531
diff
changeset
|
460 |
fun fact_count facts = Facts.fold_static (K (Integer.add 1)) facts 0 |
4ad9599a0847
disable some checks for huge background theories
blanchet
parents:
53531
diff
changeset
|
461 |
|
50523
0799339fea0f
get rid of some junk facts in the MaSh evaluation driver
blanchet
parents:
50512
diff
changeset
|
462 |
fun all_facts ctxt generous ho_atp reserved add_ths chained css = |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
463 |
let |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
464 |
val thy = Proof_Context.theory_of ctxt |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
465 |
val global_facts = Global_Theory.facts_of thy |
53532
4ad9599a0847
disable some checks for huge background theories
blanchet
parents:
53531
diff
changeset
|
466 |
val is_too_complex = |
57468 | 467 |
if generous orelse fact_count global_facts >= max_facts_for_complex_check then |
53532
4ad9599a0847
disable some checks for huge background theories
blanchet
parents:
53531
diff
changeset
|
468 |
K false |
4ad9599a0847
disable some checks for huge background theories
blanchet
parents:
53531
diff
changeset
|
469 |
else |
53533 | 470 |
is_too_complex |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
471 |
val local_facts = Proof_Context.facts_of ctxt |
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56141
diff
changeset
|
472 |
val named_locals = local_facts |> Facts.dest_static true [global_facts] |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
473 |
val assms = Assumption.all_assms_of ctxt |
57468 | 474 |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
475 |
fun is_good_unnamed_local th = |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
476 |
not (Thm.has_name_hint th) andalso |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
477 |
forall (fn (_, ths) => not (member Thm.eq_thm_prop ths th)) named_locals |
57468 | 478 |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
479 |
val unnamed_locals = |
48396 | 480 |
union Thm.eq_thm_prop (Facts.props local_facts) chained |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
481 |
|> filter is_good_unnamed_local |> map (pair "" o single) |
56141
c06202417c4a
back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents:
56140
diff
changeset
|
482 |
val full_space = |
c06202417c4a
back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents:
56140
diff
changeset
|
483 |
Name_Space.merge (Facts.space_of global_facts, Facts.space_of local_facts) |
53512 | 484 |
val is_blacklisted_or_something = is_blacklisted_or_something ctxt ho_atp |
57468 | 485 |
|
56141
c06202417c4a
back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents:
56140
diff
changeset
|
486 |
fun add_facts global foldx facts = |
54081 | 487 |
foldx (fn (name0, ths) => fn accum => |
50512
c283bc0a8f1a
tweaked which facts are included for MaSh evaluations
blanchet
parents:
50511
diff
changeset
|
488 |
if name0 <> "" andalso |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
489 |
forall (not o member Thm.eq_thm_prop add_ths) ths andalso |
56141
c06202417c4a
back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents:
56140
diff
changeset
|
490 |
(Facts.is_concealed facts name0 orelse |
57469
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
491 |
Long_Name.is_hidden (Facts.intern facts name0) orelse |
53512 | 492 |
(not generous andalso is_blacklisted_or_something name0)) then |
54081 | 493 |
accum |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
494 |
else |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
495 |
let |
50485
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50481
diff
changeset
|
496 |
val n = length ths |
3c6ac2da2f45
merge aliased theorems in MaSh dependencies, modulo symmetry of equality
blanchet
parents:
50481
diff
changeset
|
497 |
val multi = n > 1 |
57468 | 498 |
|
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
499 |
fun check_thms a = |
55286 | 500 |
(case try (Proof_Context.get_thms ctxt) a of |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
501 |
NONE => false |
55286 | 502 |
| SOME ths' => eq_list Thm.eq_thm_prop (ths, ths')) |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
503 |
in |
57469
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
504 |
snd (fold_rev (fn th => fn (j, accum) => |
54081 | 505 |
(j - 1, |
506 |
if not (member Thm.eq_thm_prop add_ths th) andalso |
|
507 |
(is_likely_tautology_too_meta_or_too_technical th orelse |
|
508 |
is_too_complex (prop_of th)) then |
|
509 |
accum |
|
510 |
else |
|
511 |
let |
|
57469
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
512 |
fun get_name () = |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
513 |
if name0 = "" then |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
514 |
backquote_thm ctxt th |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
515 |
else |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
516 |
let val short_name = Facts.extern ctxt facts name0 in |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
517 |
if check_thms short_name then |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
518 |
short_name |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
519 |
else |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
520 |
let val long_name = Name_Space.extern ctxt full_space name0 in |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
521 |
if check_thms long_name then |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
522 |
long_name |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
523 |
else |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
524 |
name0 |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
525 |
end |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
526 |
end |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
527 |
|> make_name reserved multi j |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
528 |
val stature = stature_of_thm global assms chained css name0 th |
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
529 |
val new = ((get_name, stature), th) |
54081 | 530 |
in |
57469
29e7e6e89a0e
added hidden check to Sledgehammer fact filters, to avoid picking up facts like 'Nat.nat_induct0'
blanchet
parents:
57468
diff
changeset
|
531 |
(if multi then apsnd else apfst) (cons new) accum |
54081 | 532 |
end)) ths (n, accum)) |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
533 |
end) |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
534 |
in |
50756
c96bb430ddb0
put single-theorem names before multi-theorem ones (broken since 5d147d492792)
blanchet
parents:
50736
diff
changeset
|
535 |
(* The single-theorem names go before the multiple-theorem ones (e.g., |
c96bb430ddb0
put single-theorem names before multi-theorem ones (broken since 5d147d492792)
blanchet
parents:
50736
diff
changeset
|
536 |
"xxx" vs. "xxx(3)"), so that single names are preferred when both are |
c96bb430ddb0
put single-theorem names before multi-theorem ones (broken since 5d147d492792)
blanchet
parents:
50736
diff
changeset
|
537 |
available. *) |
56141
c06202417c4a
back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents:
56140
diff
changeset
|
538 |
`I [] |> add_facts false fold local_facts (unnamed_locals @ named_locals) |
c06202417c4a
back to a form of hybrid facts, to reduce performance impact of ed92ce2ac88e;
wenzelm
parents:
56140
diff
changeset
|
539 |
|> add_facts true Facts.fold_static global_facts global_facts |
50756
c96bb430ddb0
put single-theorem names before multi-theorem ones (broken since 5d147d492792)
blanchet
parents:
50736
diff
changeset
|
540 |
|> op @ |
48251
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
541 |
end |
6cdcfbddc077
moved most of MaSh exporter code to Sledgehammer
blanchet
parents:
48250
diff
changeset
|
542 |
|
57468 | 543 |
fun nearly_all_facts ctxt ho_atp {add, del, only} reserved css chained hyp_ts concl_t = |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
544 |
if only andalso null add then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
545 |
[] |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
546 |
else |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
547 |
let |
48396 | 548 |
val chained = |
549 |
chained |
|
48292 | 550 |
|> maps (fn th => insert Thm.eq_thm_prop (zero_var_indexes th) [th]) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
551 |
in |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
552 |
(if only then |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
553 |
maps (map (fn ((name, stature), th) => ((K name, stature), th)) |
52031
9a9238342963
tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents:
51998
diff
changeset
|
554 |
o fact_of_ref ctxt reserved chained css) add |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
555 |
else |
54080
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
556 |
let |
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
557 |
val (add, del) = pairself (Attrib.eval_thms ctxt) (add, del) |
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
558 |
val facts = |
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
559 |
all_facts ctxt false ho_atp reserved add chained css |
54143
18def1c73c79
make sure add: doesn't add duplicates, and works for [no_atp] facts
blanchet
parents:
54142
diff
changeset
|
560 |
|> filter_out ((member Thm.eq_thm_prop del orf |
18def1c73c79
make sure add: doesn't add duplicates, and works for [no_atp] facts
blanchet
parents:
54142
diff
changeset
|
561 |
(No_ATPs.member ctxt andf not o member Thm.eq_thm_prop add)) o snd) |
54080
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
562 |
in |
540835cf11ed
more gracefully handle huge theories in relevance filters
blanchet
parents:
54078
diff
changeset
|
563 |
facts |
48292 | 564 |
end) |
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
565 |
|> maybe_instantiate_inducts ctxt hyp_ts concl_t |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
566 |
end |
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
567 |
|
54142
5f3c1b445253
no fact subsumption -- this only confuses later code, e.g. 'add:'
blanchet
parents:
54112
diff
changeset
|
568 |
fun drop_duplicate_facts facts = |
54112
9c0f464d1854
drop only real duplicates, not subsumed facts -- this confuses MaSh
blanchet
parents:
54092
diff
changeset
|
569 |
let val num_facts = length facts in |
54142
5f3c1b445253
no fact subsumption -- this only confuses later code, e.g. 'add:'
blanchet
parents:
54112
diff
changeset
|
570 |
facts |> num_facts <= max_facts_for_duplicates ? fact_distinct (op aconv) |
54112
9c0f464d1854
drop only real duplicates, not subsumed facts -- this confuses MaSh
blanchet
parents:
54092
diff
changeset
|
571 |
end |
9c0f464d1854
drop only real duplicates, not subsumed facts -- this confuses MaSh
blanchet
parents:
54092
diff
changeset
|
572 |
|
48250
1065c307fafe
further ML structure split to permit finer-grained loading/reordering (problem to solve: MaSh needs most of Sledgehammer)
blanchet
parents:
diff
changeset
|
573 |
end; |